09 Active Users Over 24 Hours

Started by Mindless, July 21, 2012, 11:04:28 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Litago


BamBam0077

works like a charm

#ThankYou, #ThumbsUp!
"When Darkness Shadows Your Doubts, Deep Within Us Is Our Key, Not Success But Everything" ~ Anonymous

BamBam0077

Thank you for another great code :-)

Will have to try this out.

Cheers,

Bam!.
"When Darkness Shadows Your Doubts, Deep Within Us Is Our Key, Not Success But Everything" ~ Anonymous

Mindless

Credits to sir_snugglebunny and all involved :)

Reworked for 09 - Should be Xhtml valid, just the standard version, theres 2-3 cached versions also memcached.

Run the sql :
Code (sql) Select
INSERT INTO `avps` VALUES ('last24', '', 0, 0);


@ file index where ever you want add :
Code (php) Select
//===09 last  24 hours online
      $activeusers24 = "";
      $no24 = "";
      $dt24 = time() - 86400;
      $arr = mysql_fetch_assoc(mysql_query("SELECT * FROM avps WHERE arg='last24'")) or $no24 = true;
      $res = mysql_query("SELECT id, username, class, warned, donor FROM users WHERE last_access >= $dt24 ORDER BY class DESC") or sqlerr(__FILE__, __LINE__);
      $totalonline24 = mysql_num_rows($res);
      $_ss24 = ($totalonline24 != 1) ? '\'s':'';
      $last24record = get_date($arr["value_u"], 'DATE');
      $last24 = $arr["value_i"];
      if ($no24 || $totalonline24 > $last24 )
      {
      $last24 = $totalonline24;
      $period = time();
      mysql_query(($no24 ? 'INSERT':'UPDATE'). " avps SET value_s = '0', value_i = $last24 , value_u = $period ". ($no24 ? ", arg='last24'":"WHERE arg='last24'")) or sqlerr();
      }
      // Colors correspond to user class, first position UC_USER = 0, and so on
      // Add as necessary. Note: change to UC_USER class gets a null for no color change .
      $colors= array('8E35EF','f9a200','009F00','0000FF','FE2E2E','B000B0','4080B0');
      while ($arr = mysql_fetch_assoc($res))
      {
      if ($activeusers24) $activeusers24 .= ",\n";
      $activeusers24 .= "<span style=\"white-space: nowrap;\">";
      $arr["username"] = "<font color='#". $colors[$arr['class']] ."'>" . htmlspecialchars($arr['username'])."</font>";
      $donator = $arr["donor"] === "yes";
      $warned = $arr["warned"] === "yes";

      if ($CURUSER)
      $activeusers24 .= "<a href='{$INSTALLER09['baseurl']}/userdetails.php?id={$arr["id"]}'><b>{$arr["username"]}</b></a>";
      else
      $activeusers24 .= "<b>{$arr["username"]}</b>";
      if ($donator)
      $activeusers24 .= "<img src='{$INSTALLER09['pic_base_url']}star.gif' alt='Donated' />";
      if ($warned)
      $activeusers24 .= "<img src='{$INSTALLER09['pic_base_url']}warned.gif' alt='Warned' />";
      $activeusers24 .= "</span>\n";
      }
 
      if (!$activeusers24)
      $activeusers24 = "{$lang['index_noactive']}";
   
      $HTMLOUT .= "<br /><div style='text-align:left;width:80%;border:1px solid blue;padding:5px;'>
      <div style='background:lightgrey;height:25px;'><span style='font-weight:bold;font-size:12pt;'>{$lang['index_active24']}</span></div><br />
    <table border='1' cellpadding='10' cellspacing='0' width='100%'>
  <tr class='table'>
  <td class='text'>{$activeusers24}
  </td></tr>
      <tr class='table'>
      <td class='text'>{$lang['index_most24']}&nbsp;{$last24}&nbsp;{$lang['index_member24']}{$_ss24}&nbsp;:&nbsp;{$last24record}
      </td>
      </tr></table></div><br />\n";
      //== End



@ file lang/en/lang_index.php add:
Code (php) Select
'index_active24' => "Active users in the last 24hrs",
'index_most24' => "Most ever visited in 24 hours was",
'index_member24' => "Member",


Can test that - it should work fine for now - i'll update this soon :)