Simple Machines Community Forum

General Community => Scripting Help => Aiheen aloitti: bbulldog - tammikuu 20, 2007, 05:28:20 AP

Otsikko: User List top of page solved - problem
Kirjoitti: bbulldog - tammikuu 20, 2007, 05:28:20 AP
Hi all,
I have moved the online user list to the top of the page into the User Info box . Works ok for the first page but as soon as i go into any of the boards it vanishes to the extent that the variables are gone Everthing else works ok apart from the [more statistics] link, this brings out some errors.

I know the problem must be because i moved this stuff from the BoardIndex.Template.php to the Index.Template.php.
The following are the variables that dont work

$context['num_guests']
$context['num_users_online']
$context['num_users_hidden']
$context['num_users_hidden']
$context['list_users_online']
$context['show_stats']

There was no change to the code itself, just moved.

anyone wanting to have a look can use this.
username: bully
password: tester

the page is www.thebrits.de
Otsikko: Re: User List top of page problem
Kirjoitti: bbulldog - tammikuu 29, 2007, 07:10:08 AP
Got things sorted  ;)

What i wanted was to have the list of users online in the Info Box, so that it is shown anywhere on the board.
(https://www.simplemachines.org/community/proxy.php?request=http%3A%2F%2Fwww.britishbulldog.homepage.t-online.de%2Fbrits%2FBild1.jpg&hash=94c4de4a184ea6d052a4c9ffc3f4db5da645f8a1)
what i have done:

remmed out this by adding // in front of each line in BoardIndex.template.php

   
Lainaa// "Users online" - in order of activity.
   echo '
   <tr>
      <td class="catbg" colspan="2">', $txt[158], '</td>
   </tr><tr>
      <td class="windowbg" width="20" valign="middle" align="center">
         <a href="', $scripturl, '?action=who">
            <img src="', $settings['images_url'], '/icons/online.gif" alt="', $txt[158], '" border="0" /></a>
      </td>
      <td class="windowbg2" width="100%">
         <a href="', $scripturl, '?action=who">', $context['num_guests'], ' ', $context['num_guests'] == 1 ? $txt['guest'] : $txt['guests'], ', ', $context['num_users_online'], ' ', $context['num_users_online'] == 1 ? $txt['user'] : $txt['users'], (empty($context['num_users_hidden']) ? '' : ' (' . $context['num_users_hidden'] . ' ' . $txt['hidden'] . ')'), '</a><br />
         <span class="smalltext">';

    //Assuming there ARE users online... each user in users_online has an id, username, name, group, href, and link.
   if (!empty($context['users_online']))
      echo '
         ', $txt[140], ':<br />', implode(', ', $context['list_users_online']);

   echo '
         <br />', $context['show_stats'] && !$settings['show_sp1_info'] ? '
         <a href="' . $scripturl . '?action=stats">' . $txt['smf223'] . '</a>' : '', '
         </span>
      </td>
   </tr>';

and added this to Index.template.php

Lainaa// "Users online" - in order of activity. 2Guests,5Users
   if (!empty($context['users_online']))
      echo '
         
         <b><a href="', $scripturl, '?action=who">', $context['num_guests'], ' ', $context['num_guests'] == 1 ? $txt['guest'] : $txt['guests'], ', ', $context['num_users_online'], ' ', $context['num_users_online'] == 1 ? $txt['user'] : $txt['users'], (empty($context['num_users_hidden']) ? '' : ' (' . $context['num_users_hidden'] . ' ' . $txt['hidden'] . ')'), '</a></b>     ', $txt[141], ':      <br />
         <span class="smalltext" style="font-size: 11px;">
      ';                  
               
// Assuming there ARE users online... each user in users_online has an id, username, name, group, href, and link.
   if (!empty($context['users_online']))
      echo '
         ', implode(', ', $context['list_users_online']) ;
      echo '
         <br />', $context['show_stats'] && !$settings['show_sp1_info'] ? '
         <a href="' . $scripturl . '?action=stats">' . $txt['smf223'] . '</a>' : '', '
         </span>
         ';

directly after this if-else command

Lainaa// If the user is logged in, display stuff like their name, new messages, etc.
   if ($context['user']['is_logged'])
   {
   ..........

   // Otherwise they're a guest - so politely ask them to register or login.
   else
   {
   ..........

   }


Next is to make sure the above error does not come up, this is easy if you know how which was my original problem above ;D just add this to the Load.php in the source folder. This is the actual query to the spl database.

Lainaa// Load the users online right now.
   $result = db_query("
      SELECT
         lo.ID_MEMBER, lo.logTime, mem.realName, mem.memberName, mem.showOnline,
         mg.onlineColor, mg.ID_GROUP, mg.groupName
      FROM {$db_prefix}log_online AS lo
         LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = lo.ID_MEMBER)
         LEFT JOIN {$db_prefix}membergroups AS mg ON (mg.ID_GROUP = IF(mem.ID_GROUP = 0, mem.ID_POST_GROUP, mem.ID_GROUP))", __FILE__, __LINE__);

   $context['users_online'] = array();
   $context['list_users_online'] = array();
   $context['online_groups'] = array();
   $context['num_guests'] = 0;
   $context['num_users_hidden'] = 0;
   while ($row = mysql_fetch_assoc($result))
   {
      if (!isset($row['realName']))
      {
         $context['num_guests']++;
         continue;
      }
      elseif (!empty($row['showOnline']) || allowedTo('moderate_forum'))
      {
         // Some basic color coding...
         if (!empty($row['onlineColor']))
            $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '" style="color: ' . $row['onlineColor'] . ';">' . $row['realName'] . '</a>';
         else
            $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['realName'] . '</a>';

         $context['users_online'][$row['logTime'] . $row['memberName']] = array(
            'id' => $row['ID_MEMBER'],
            'username' => $row['memberName'],
            'name' => $row['realName'],
            'group' => $row['ID_GROUP'],
            'href' => $scripturl . '?action=profile;u=' . $row['ID_MEMBER'],
            'link' => $link,
            'hidden' => empty($row['showOnline']),
         );

         $context['list_users_online'][$row['logTime'] . $row['memberName']] = empty($row['showOnline']) ? '<i>' . $link . '</i>' : $link;

         if (!isset($context['online_groups'][$row['ID_GROUP']]))
            $context['online_groups'][$row['ID_GROUP']] = array(
               'id' => $row['ID_GROUP'],
               'name' => $row['groupName'],
               'color' => $row['onlineColor']
            );
      }
      else
         $context['num_users_hidden']++;
   }
   mysql_free_result($result);

   krsort($context['users_online']);
   krsort($context['list_users_online']);
   ksort($context['online_groups']);

   $context['num_users_online'] = count($context['users_online']) + $context['num_users_hidden'];

   $context['show_stats'] = allowedTo('view_stats') && !empty($modSettings['trackStats']);

make sure the last line is in the above too
      
Lainaa$context['show_stats'] = allowedTo('view_stats') && !empty($modSettings['trackStats']);