TinyPortal

Development => Support => Topic started by: Hairy on September 17, 2007, 11:42:34 PM

Title: Small change to my roster page
Post by: Hairy on September 17, 2007, 11:42:34 PM
I posted a little while back in the snippets but I think it has been missed, I want to add the "local time" for the members my roster displays. I will either add to or replace the "last login" part of the roster

All I need is the code to display this, I know how to insert it, I will also be playing around with the layout later.

I have tried search, advanced search and Google but no luck.

I believe I need to add something here:
//Now get all the users
  $query2 = db_query("
    SELECT ID_GROUP, ID_MEMBER, realName, avatar, memberName, usertitle,
           emailAddress, hideEmail, lastLogin, location, personalText,
           totalTimeLoggedIn, dateRegistered, ICQ, AIM, YIM, MSN,   
           hideEmail, emailAddress, additionalGroups


And then I will need to add something else here to display the result, (either add or replace, I have not decided yet):
        echo '<td class="windowbg">' . timeformat($row2['lastLogin']) . '</td>';



Quote from: Hairy on September 07, 2007, 11:19:24 AM
OK the best one for me I have found here so far is the following:

global $db_prefix, $scripturl, $txt, $settings, $options;

if (isset($_GET['rteam']))
  $rteam = ' AND FIND_IN_SET('. $_GET['rteam'] . ',additionalGroups)';
else
  $rteam = '';

// These must be in the order you wish them to print out on your roster.
// VERY IMPORTANT!!!! -- they must be exactly the same as the group names in the database, including
// capitalization and spaces.
$rankorder = array(
  'Administrator',
  'Global Moderator',
  'Server Admin',
  'Server Deputy',
  'Recruiter',
  'Battle Manager',
  'Article Manager',
  '2.8.1 Squad Leader',
//  '2.8.1 Clan Member',
  '2.6 Squad Leader',
  '2.6 Clan Member',
//  'Clan Member',
);

$team[10] = '';
$team[11] = '';
$groups = '';
//Does all the real work here for showing groups.
$query = db_query("SELECT ID_GROUP, groupName, onlineColor, stars
  FROM {$db_prefix}membergroups", __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($query))
{
  $groups[$row['groupName']]  = array(
    'id' => $row['ID_GROUP'],
    'color' => empty($row['onlineColor']) ? '' : $row['onlineColor'],
'stars' => empty($row['stars']) ? '' : substr($row['stars'],2),
  );
}
mysql_free_result($query);

foreach ($rankorder as $rank)
{
//Now get all the users
  $query2 = db_query("
    SELECT ID_GROUP, ID_MEMBER, realName, avatar, memberName, usertitle,
           emailAddress, hideEmail, lastLogin, location, personalText,
           totalTimeLoggedIn, dateRegistered, ICQ, AIM, YIM, MSN,   
           hideEmail, emailAddress, additionalGroups
    FROM {$db_prefix}members
    WHERE ID_GROUP = '" . $groups[$rank]['id'] . "'" .
       " OR FIND_IN_SET(" . $groups[$rank]['id'] . ", additionalGroups)", $rteam, __FILE__, __LINE__);

  if(db_affected_rows() != 0)
  {
    echo '<table border="0" cellspacing="1" cellpadding="5" align="center" class="bordercolor">
      <tr><td colspan="7" class="catbg"><font size="4" face="verdana"><b>' . $rank . '</b></font></td></tr>
      <tr><td rowspan="70" width="85" class="profilebg" valign="top">
        <center><img src="' . $settings['images_url'] . '/' . $groups[$rank]['stars'] . '"></center></td>';
      echo '<td class="catinfo" width="245"><b>GAMING ALIAS</b></td>';
      echo '<td class="catinfo" width="130"><b>NAME</b></td>';
      echo '<td class="catinfo" width="170"><b>LAST ONLINE</b></td>';
      echo '<td class="catinfo" width="175"><b>CONTACT</b></td></tr><tr>';
      while ($row2 = mysql_fetch_assoc($query2))
      {
        echo '<td class="windowbg" height="40"><a href="' . $scripturl . '?action=profile;u=' . $row2['ID_MEMBER'] . '"><b><font size="3" face="verdana">' . $row2['realName'] . '</b>';   
          if ($row2['additionalGroups'] <> '' )
            {
            $addl = explode(',',$row2['additionalGroups']);
            foreach ($team as $key => $value)
              {
              if (in_array($key,$addl))
              echo ' '. $value . ' ';
              }
            }
        echo ' '. $team[$row2['additionalGroups']] . ' ';
        echo '</font></font></a><br><font size="1"> ' . $row2['personalText'] . '</font></a></td><td class="windowbg2">' . $row2['memberName'] . '</td>';
        echo '<td class="windowbg">' . timeformat($row2['lastLogin']) . '</td>';
        echo '<td class="windowbg2" align="left">';

//Send email row
        if($row2['hideEmail'] == 0)
          echo '<a href="mailto:', $row2['emailAddress'], '"><img src="' . $settings['images_url'] . '/email_sm.gif" alt="email" /></a> ';

        if($row2['ICQ'] != '')
          echo '<a href="http://www.icq.com/whitepages/about_me.php?uin=' . $row2['ICQ'] . '" target="_blank"><img src="http://status.icq.com/online.gif?img=5&icq=' . $row2['ICQ'] . '" alt="' . $row2['ICQ'] . '" width="18" height="18" border="0" /></a> ';
        if($row2['AIM'] != '')
          echo '<a href="aim:goim?screenname=' . urlencode(strtr($row2['AIM'], array(' ' => '%20'))) . '&message=' . $txt['aim_default_message'] . '"><img src="' . $settings['images_url'] . '/aim.gif" alt="' . $row2['AIM'] . '" border="0" /></a> ';
        if($row2['YIM'] != '')
          echo '<a href="http://edit.yahoo.com/config/send_webmesg?.target=' . urlencode($row2['YIM']) . '"><img src="http://opi.yahoo.com/online?u=' . urlencode($row2['YIM']) . '&m=g&t=0" alt="' . $row2['YIM'] . '" border="0" /></a> ';
        if($row2['MSN'] != '')
          echo '<a href="http://members.msn.com/' . $row2['MSN'] . '" target="_blank"><img src="' . $settings['images_url'] . '/msntalk.gif" alt="' . $row2['MSN'] . '" border="0" /></a> ';

//Send PM row
        echo '<a href="' . $scripturl . '?action=pm;sa=send;u=' . $row2['ID_MEMBER'] . '"><img src="' . $settings['images_url'] . '/im_on.gif" alt="PM" /></a></a>';
        echo '</td>';
        echo '</tr>';
      }
    echo '</table><br>';
  }
}


But what I want to do is change the "Last Online" part to show the "local time" of the member it is displaying, it would be awesome if anyone knows what to do.

I'm very new to this stuff and had a fiddle but only ended up making it display the local time of the person who is viewing the roster (displayed the same time for everyone) I deleted that so can't remember what I used now  :uglystupid2:



Thank you :)
Title: Re: Small change to my roster page
Post by: IchBin on September 18, 2007, 12:03:24 AM
Its a bit more complicated than that I think. The problem being that what you're talking about is the time offset. You'll need to grab the server time, and then add/subtract based on the time offset set in the members profile. I'm not sure of the calculations though. But thats the way I see it in my head. What do you do if they haven't set their time offset and it displays the wrong time for them? Hopefully someone can help, as I can't take the time to figure it out right now.
Title: Re: Small change to my roster page
Post by: jacortina on September 18, 2007, 12:08:30 AM
Add '$memberContext' to the 'global' line.

Then this should get you the member's current local time:

$user_id = $row2['ID_MEMBER'];
loadMemberContext($user_id);
$local_time = $memberContext[$user_id]['local_time'];

Title: Re: Small change to my roster page
Post by: IchBin on September 18, 2007, 12:14:57 AM
Of course, if the dirty work is already done then don't worry about it. ;)

Thanks JAC!
Title: Re: Small change to my roster page
Post by: Hairy on September 18, 2007, 02:21:33 AM
Thank you very much for the quick reply, I am quite new at this and can't work out where to put:

Quote from: J.A.Cortina on September 18, 2007, 12:08:30 AM
$user_id = $row2['ID_MEMBER'];
loadMemberContext($user_id);
$local_time = $memberContext[$user_id]['local_time'];


I tried placing it before (and then I tried after):
$team[22] = '(+2.6)';
$team[11] = '';
$groups = '';


And replaced:

        echo '<td class="windowbg">' . timeformat($row2['lastLogin']) . '</td>';

with

        echo '<td class="windowbg">' . $local_time . '</td>';

But now the result is blank  :-\

I must be doing it all wrong!

Cheers

PS i did the first part right, on the first line I have:
global $db_prefix, $scripturl, $txt, $settings, $options, $memberContext;
Title: Re: Small change to my roster page
Post by: jacortina on September 18, 2007, 02:27:18 AM
It has to be within the "while ($row2 = mysql_fetch_assoc($query2)) " structure (it DOES refer to $row2['ID_MEMBER'] and it has to operate by getting the info for each member).
Title: Re: Small change to my roster page
Post by: Hairy on September 19, 2007, 01:29:11 AM
I'm really sorry but I have hardly any knowledge, I initially thought it was more basic and have spent ~3 hours trying different combinations of what you have given me (I like to try to do things with minimal help, I learn more that way :) )

But I am having no luck getting it to work. :(
Title: Re: Small change to my roster page
Post by: Hairy on September 19, 2007, 01:59:15 AM
PS. I think I am just doing it wrong.
Title: Re: Small change to my roster page
Post by: jacortina on September 19, 2007, 02:02:43 AM
OK. Apparently, some extra loading has to be done (if not already done during a session). So, it not you (or it's not JUST you ;) ).

So... Back up to your original code and then make sure the "$memberContext" is in the global line.

Then, replace the line:
        echo '<td class="windowbg">' . timeformat($row2['lastLogin']) . '</td>';

With:
        $user_id = $row2['ID_MEMBER'];
        loadMemberData(array($user_id));
        loadMemberContext($user_id);
        $local_time = $memberContext[$user_id]['local_time'];
        echo '<td class="windowbg">' . $local_time . '</td>';


If nothing appears, check your errorlog to see if anything shows up. Then come back here.
Title: Re: Small change to my roster page
Post by: Hairy on September 19, 2007, 02:12:06 AM
 :coolsmiley: Works perfectly, thankyou so very much!  :)