TinyPortal

Development => Block Codes => Topic started by: rumboogy on March 07, 2008, 12:17:54 PM

Title: How about a List Block
Post by: rumboogy on March 07, 2008, 12:17:54 PM
I run a biker site, but I am sure this type of script could be used for any type of site that needs a list of people (sort of a roll call) attending a meeting, rally, wedding, party, concert, etc.

The list would be a way for a member to CLICK a button and their name be added to the list (no comments, just a name). Is this possible? Maybe a future feature.

Wally
Title: Re: How about a List Block
Post by: JPDeni on March 07, 2008, 01:42:57 PM
I sorta have that now, although it's with a php article, combined with the custom profile fields mod.

You can see the result at http://www.morethanspike.com/index.php?page=29

I have several events that I'm tracking, so I have a table. If there was only one event at a time, it would be a list.

My guess is that this would be a highly specialized mod, and might be better as a block snippet rather than something that would be integrated into TP itself.
Title: Re: How about a List Block
Post by: rumboogy on March 07, 2008, 02:57:29 PM
That looks like it would work for me...in fact, I could actually monitor several events at a time...is it on this site...or is it your own personal code. Thanks...looks very nice.

Wally
Title: Re: How about a List Block
Post by: JPDeni on March 07, 2008, 04:53:29 PM
This is my own personal code. In the past, we would have people PM an admin to say they were going to be at an event and then the admin would add them to a list in the forum. Very tedious. So I worked out this code to let the users do it themselves.

The code is really ugly right now because it was just for myself and I didn't figure anybody else would ever see it. ;) I'll clean it up a bit and then post it. I'll likely move this to the Block Code Snippets board when I add the code.

I might get it done today, but no promises. :)
Title: Re: How about a List Block
Post by: rumboogy on March 07, 2008, 05:55:44 PM
YOU Sir...are da MAN!!

Thank you.

Wally
Title: Re: How about a List Block
Post by: JPDeni on March 07, 2008, 06:26:17 PM
Actually, I'm da goil!! ;) But that's okay.

I ended up having a bit of time, so I went ahead and did it. Thanks for posting this. It's going to be a whole lot easier for me, now that I've made it neater.  Sometimes I need a push to make things better. :)

Here's the code, which goes into a php article. Or a center php block. It'll likely come out too wide for a side block.

Updated the script to include text fields and select fields as well as checkboxes.

global $db_prefix, $scripturl;

//////////////////////////////////////////////////////////////////
/////                    I M P O R T A N T                   /////
/////                                                        /////
////    This can only be used in conjunction with the        /////
////    Custom Profile Fields mod, which is available        /////
////    at the SMF site.                                     /////
/////                                                        /////
//////////////////////////////////////////////////////////////////

// List the Field IDs that you have set in the Custom Profile Fields
// in the order you want them displayed on the list.
$codes = array("SDIF","GSCo","Bord","Rift","Unio","Coll");

// Enter the field type for each field, , using the field IDs as the subscript
// If the field is a checkbox, enter 1
// if it's anything else, enter some other number

$field_type['SDIF'] = 1;
$field_type['GSCo'] = 1;
$field_type['Bord'] = 1;
$field_type['Rift'] = 2;
$field_type['Unio'] = 7;
$field_type['Coll'] = 1;

// List the full names of the events, in the same order as the field IDs above
$event_name[] = "San Diego<br>Indie Music Fest<br>29 Mar";
$event_name[] = "Grand Slam<br>12 - 13 Apr";
$event_name[] = "The Rift<br>26 Apr";
$event_name[] = "The Borderline<br>30 Apr";
$event_name[] = "Union Chapel<br>2 May";
$event_name[] = "Collectormania<br>3 - 4 May";

///////////////////////////////////////////////////////////////////////////////////

if (isset($codes[0])) {

  $return = '';
  $nbsp = "&nb" . "sp;";

  $event = array();
  $member = array();
  $link = array();

  foreach ($codes as $c)
    ($field_type[$c] == 1) ? $q[] = "(variable LIKE '$c' AND value <>0)" : $q[] = "(variable LIKE '$c' AND value NOT LIKE '')";
  $qr = implode("OR ",$q);

  $query = db_query("SELECT realName, variable, value, th.ID_MEMBER
                     FROM {$db_prefix}themes as th,{$db_prefix}members as mem
                     WHERE ($qr)
                         AND th.ID_MEMBER = mem.ID_MEMBER
                     ORDER BY realName", __FILE__, __LINE__);
  while ($row = mysql_fetch_assoc($query))
  {
    $event[$row['realName']][$row['variable']] = $row['value'];
    $member[$row['realName']] = 1;
    $link[$row['realName']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['realName'] . '</a>';
  }
  mysql_free_result($query);
  uksort($member, 'strnatcasecmp');
  $return .= '<center><table border="1">
                <tr align="center"><td>Member</td>';
  foreach ($event_name as $e)
    $return .= "<td>$e</td>";
  $return .= '</tr>';
  foreach ($member as $key => $value)
  {
    $return .= '<tr align="center"><td>'.$link[$key].'</td>';
    foreach ($codes as $c)
    {
      $return .= '<td>';
        if (isset($event[$key][$c]))
        {
         ($field_type[$c] == 1) ? $return .= '<center>X</center>' : $return .= $event[$key][$c];
        }
        else { $return .= $nbsp; }
      $return .= '</td>';
    }
    $return .= '</tr>';
  }
  $return .= '</table></center><br /><br />';
  }
  else
    $return = "There are no pending events at the moment<br /><br />";

echo $return;

echo 'If your name is already here and you would like to update your entry, just click your name on the list
and then click <b>Forum Profile Information</b> in the left column. Scroll down a bit and you will see the section
where you can enter the data.<br />If your name is not yet on the list, look up at the top right corner of the page and
click <b>Profile</b>, and then look for <b>Forum Profile Information</b> in the left column.<br /> If you have any problems
at all, feel free to ask for help.';



There's no error-checking, but there's only two things that you need to edit, so there shouldn't be too much of a problem. Notice with the event names, you can add line breaks and other html codes to make them print out however you want.

You also can certainly edit the instructions at the end.
Title: Re: How about a List Block
Post by: rumboogy on March 07, 2008, 06:47:16 PM
Well...I am an IDIOT. Sorry JPDeni...Yes Maam...You are DA GOIL!! Thanks, I will try it and report back to you.

Thanks,

Wally
Title: Re: How about a List Block
Post by: JPDeni on March 07, 2008, 07:16:18 PM
LOL!! That's okay. I'm used to it.

I'll be pleased to know how it works for you.
Title: Re: How about a List Block
Post by: rumboogy on March 07, 2008, 07:38:58 PM
I am finishing it up right now...I will let you know within the next hour or less. So far...I like!

Wally
Title: Re: How about a List Block
Post by: rumboogy on March 07, 2008, 08:00:30 PM
I LIKE's IT!!!

Here is the page:  http://www.arkansasbiker.net/index.php?page=41

I only have one question...what if I wanted to CENTER the table and instructions...is that possible?

Thanks...let me know what you think.

Wally
Title: Re: How about a List Block
Post by: rumboogy on March 07, 2008, 08:18:34 PM
OK, I got the text (instructions) centered, but I wished (if it is not asking too much) to center the TABLE and also drop it down maybe 2 lines. THAT's ALL.

Again...this will work very well.

Wally
Title: Re: How about a List Block
Post by: JPDeni on March 07, 2008, 08:49:52 PM
Cool!!

You have two sets of instructions. I'm not sure why.

As for centering, you just need to add centering tags around the table tags:


  $return .= '<center><table border="1">


and


  $return .= '</table></center><br /><br />';


I edited the code above to add centering.
Title: Re: How about a List Block
Post by: rumboogy on March 07, 2008, 08:56:05 PM
Actually, I was messing with some links in the instructions...it should be fine now...I will try the centering of the table now.

Take another look...great little piece of code. THANK YOU.

Wally
Title: Re: How about a List Block
Post by: Smoky on March 07, 2008, 09:03:23 PM
looks great Rumboogy..  :D wish i had a bike lol..  :buck2:
Title: Re: How about a List Block
Post by: rumboogy on March 07, 2008, 09:19:52 PM
Thank you Smoky...right now we (Arkansas) has anywhere from 2-6 inches of snow on the ground (that is NOT normal for Arkansas).  :)

Thanks.

Wally
Title: Re: How about a List Block
Post by: Smoky on March 07, 2008, 09:27:32 PM
lol im from a little small town called Traveler's Rest, and grew up in Murrells Inlet SC, near Myrtle Beach SC, and remember bike week with the harley's.. suggestion: get advertisements from your local bike dealership to sponsor his bikes in your site.. say a bike a week, make business cards for it, and give them to him and anyone else you come in contact with.. I wish you nothing but success in your site and hope that you really will enjoy site building..  ;)
Title: Re: How about a List Block
Post by: rumboogy on March 07, 2008, 09:54:32 PM
Was stationed in Beaufort, SC for 2 years, then stationed in Charleston, SC for 2 years...got out of the Navy and then moved back to Charleston, SC for 2 more years...then came home. I loved it in SC.

Thanks for the advice, I will check into that.

And THANK YOU JPDeni...I am done with it now, if you want to see what I ended up with. Thanks so much!!

Wally
Title: Re: How about a List Block
Post by: JPDeni on March 07, 2008, 10:08:00 PM
Excellent, rumboogy. Looks great. I'm glad you were able to use it and to adjust it to your own liking.

Title: Re: How about a List Block
Post by: Smoky on March 07, 2008, 10:15:44 PM
that is a nice way to do things JPDeni, and i might be able to use that too sometime.. thanks..  ;)
Title: Re: How about a List Block
Post by: rumboogy on March 07, 2008, 10:17:45 PM
Maybe some others can use it too. I am thinking it will be used by a lot of my members on my site.

Thanks again.

Wally
Title: Re: How about a List Block
Post by: rumboogy on March 09, 2008, 05:04:31 PM
Hey JPDeni...First, let me say that I love the List Block. EXCELLENT little tool for LOTS of uses.

I do have a question...I notice right now it is set up to only accept an "X" in each field...(But I changed my to say "YES").

How hard would it be to pass TEXT over to the table.

My example...in Custom Profile Fields I set up a new FIELD called "Your Ride" and used a TEXT field. The member can use this small text box to type in their Bike Make and Model (ex. 2004 Honda VTX 1300s), so I am wanting to pass this value over to the table. Is this possible (right now I just get the "X" mark.

I have set it up here:  http://www.arkansasbiker.net/index.php?page=43 (http://www.arkansasbiker.net/index.php?page=43)

Of course this is just playing right now.

Just asking.

Wally
Title: Re: How about a List Block
Post by: Solomon on March 09, 2008, 05:19:18 PM
This is a very useful for my site, allowing our project managers to coordinate volunteer activities.
Thanks!
Title: Re: How about a List Block
Post by: JPDeni on March 09, 2008, 05:44:21 PM
I'm glad you like it, Solomon.

rumboogy, it can be made to do what you want, but it would require either more data to be entered or more calls to the database. Actually, I have in the past used text fields for this, when our users had their seat numbers for conventions and wanted to be able to locate their friends or find out who was sitting close to them. That's when the coding was ugly. ;)

Let me think about it a bit and see if I can come up with something that's not too ugly.
Title: Re: How about a List Block
Post by: rumboogy on March 09, 2008, 05:46:54 PM
Ok...let's see if I can do this without making an A$$ of myself...

I hope I explained myself good enough...

You are "DA GOIL"!  ;D

Thanks JPDeni!

Wally
Title: Re: How about a List Block
Post by: JPDeni on March 09, 2008, 07:33:53 PM
LOL!!! Very good, Wally! (My husband got a chuckle out of that, too.)

Okay. This should do it. I'll post it here and also change it in the first post.


global $db_prefix, $scripturl;

//////////////////////////////////////////////////////////////////
/////                    I M P O R T A N T                   /////
/////                                                        /////
////    This can only be used in conjunction with the        /////
////    Custom Profile Fields mod, which is available        /////
////    at the SMF site.                                     /////
/////                                                        /////
//////////////////////////////////////////////////////////////////

// List the Field IDs that you have set in the Custom Profile Fields
// in the order you want them displayed on the list.
$codes = array("SDIF","GSCo","Bord","Rift","Unio","Coll");

// Enter the field type for each field, , using the field IDs as the subscript
// If the field is a checkbox, enter 1
// if it's anything else, enter some other number

$field_type['SDIF'] = 1;
$field_type['GSCo'] = 1;
$field_type['Bord'] = 1;
$field_type['Rift'] = 2;
$field_type['Unio'] = 7;
$field_type['Coll'] = 1;

// List the full names of the events, in the same order as the field IDs above
$event_name[] = "San Diego<br>Indie Music Fest<br>29 Mar";
$event_name[] = "Grand Slam<br>12 - 13 Apr";
$event_name[] = "The Rift<br>26 Apr";
$event_name[] = "The Borderline<br>30 Apr";
$event_name[] = "Union Chapel<br>2 May";
$event_name[] = "Collectormania<br>3 - 4 May";

///////////////////////////////////////////////////////////////////////////////////

if (isset($codes[0])) {

  $return = '';
  $nbsp = "&nb" . "sp;";

  $event = array();
  $member = array();
  $link = array();

  foreach ($codes as $c)
    ($field_type[$c] == 1) ? $q[] = "(variable LIKE '$c' AND value <>0)" : $q[] = "(variable LIKE '$c' AND value NOT LIKE '')";
  $qr = implode("OR ",$q);

  $query = db_query("SELECT realName, variable, value, th.ID_MEMBER
                     FROM {$db_prefix}themes as th,{$db_prefix}members as mem
                     WHERE ($qr)
                         AND th.ID_MEMBER = mem.ID_MEMBER
                     ORDER BY realName", __FILE__, __LINE__);
  while ($row = mysql_fetch_assoc($query))
  {
    $event[$row['realName']][$row['variable']] = $row['value'];
    $member[$row['realName']] = 1;
    $link[$row['realName']] = '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['realName'] . '</a>';
  }
  mysql_free_result($query);
  uksort($member, 'strnatcasecmp');
  $return .= '<center><table border="1">
                <tr align="center"><td>Member</td>';
  foreach ($event_name as $e)
    $return .= "<td>$e</td>";
  $return .= '</tr>';
  foreach ($member as $key => $value)
  {
    $return .= '<tr align="center"><td>'.$link[$key].'</td>';
    foreach ($codes as $c)
    {
      $return .= '<td>';
        if (isset($event[$key][$c]))
        {
         ($field_type[$c] == 1) ? $return .= '<center>X</center>' : $return .= $event[$key][$c];
        }
        else { $return .= $nbsp; }
      $return .= '</td>';
    }
    $return .= '</tr>';
  }
  $return .= '</table></center><br /><br />';
  }
  else
    $return = "There are no pending events at the moment<br /><br />";

echo $return;

echo 'If your name is already here and you would like to update your entry, just click your name on the list
and then click <b>Forum Profile Information</b> in the left column. Scroll down a bit and you will see the section
where you can enter the data.<br />If your name is not yet on the list, look up at the top right corner of the page and
click <b>Profile</b>, and then look for <b>Forum Profile Information</b> in the left column.<br /> If you have any problems
at all, feel free to ask for help.';



I was thinking about the "X" or "Yes" to indicate that the person has selected the checkbox. It could also be a graphic. Lots and lots of possibilities.
Title: Re: How about a List Block
Post by: rumboogy on March 09, 2008, 07:39:19 PM
Thank you JPDeni...Glad I could make your hubby chuckle. But if you don't mind...I won't tell my wife about my "fauxpau"  :uglystupid2:

Thanks, I'll try this out now.

Wally
Title: Re: How about a List Block
Post by: rumboogy on March 09, 2008, 07:45:25 PM
Works like a CHARM!!

http://www.arkansasbiker.net/index.php?page=43 (http://www.arkansasbiker.net/index.php?page=43)

Ms. JPDeni...this may be the BEST little part of my TP...I like this a LOT.

This little snippet (article /w Custom Profile Fields) may have ENDLESS possibilities.

Thank you so much!

Wally
Title: Re: How about a List Block
Post by: rumboogy on March 09, 2008, 08:25:29 PM
Ok...now here it is using images:
http://www.arkansasbiker.net/index.php?page=41 (http://www.arkansasbiker.net/index.php?page=41)

Thanks...having a blast!
Title: Re: How about a List Block
Post by: JPDeni on March 09, 2008, 08:29:06 PM
You're very welcome. Like I said, mine works better now, too, so we helped each other. And I had fun with it, too. :D

The images are very fun!  :D

The best part of TP is the way it helps you make your site your own. You don't end up with a cookie-cutter site. And the more you do, the more you realize what you can do.

Title: Re: How about a List Block
Post by: rumboogy on March 09, 2008, 08:36:07 PM
QuoteThe best part of TP is the way it helps you make your site your own. You don't end up with a cookie-cutter site. And the more you do, the more you realize what you can do.

Absolutely right...but it also helps to have people like you and the others on this board to help us and for that, I am sure I speak for others when I say...

THANK YOU!

Wally
Title: Re: How about a List Block
Post by: jdvarner on March 10, 2008, 12:39:08 AM
very awesome block!!!!
Title: Re: How about a List Block
Post by: rumboogy on March 10, 2008, 12:54:01 AM
Yes Indeed!!

How are you going to use it...I really like the way it works...I bet there are LOTS of uses for it.

Enjoy...thanks to DPJeni.

Wally
Title: Re: How about a List Block
Post by: jdvarner on March 10, 2008, 01:06:12 AM
tracking member get together's and camping outtings.
Title: Re: How about a List Block
Post by: rumboogy on March 10, 2008, 01:09:32 AM
Great...I am using ONE of my lists to monitor bike rallies, and the other I am using in "text mode" for members to show the kind of motorcycle they ride. VERY useful.

Wally
Title: Re: How about a List Block
Post by: thefley on March 12, 2008, 08:14:07 PM
ok I am still a newbe but I have everything i need to make this work now and tested it in the profile to make sure it will. 

but I do not know how to make a sep page for it like rumboogy has on his forum, I tried it in articles to stick with the forum theme, with no luck.  where am I going wrong?
Title: Re: How about a List Block
Post by: rumboogy on March 12, 2008, 08:19:28 PM
I am headed out the door for a ride...if no one else answers this tonight...I will answer this...But the guys are waiting on me RIGHT NOW.

Later.

Wally
Title: Re: How about a List Block
Post by: JPDeni on March 12, 2008, 08:22:44 PM
I would have to know what the problem is before I could know what is wrong with it. What is it doing?

Do you have the code in a php article?
Title: Re: How about a List Block
Post by: thefley on March 12, 2008, 08:52:43 PM
I was going to ad the list block like rumboogy had, and did't know how to make more pages to the form.  I did just now go out and downloaded the "custom actions mod"  to see if this will wirk..... I already have the custome profile fields installed.
Title: Re: How about a List Block
Post by: JPDeni on March 12, 2008, 09:36:25 PM
This does not need the custom actions mod. You can use it if you want, but it's a completely different thing that has nothing whatever to do with this code.

I don't know what you mean when you say you "didn't know how to make more pages to the form." You need to make a new TP article -- a php article -- to paste the code in.