Apparently not.
[specialops2.git] / userlist.php
blobe6f567d0a03605343a4679dbfca24c03d2da4c52
1 <?php
2 /**
3 * User Directory/Online Users/Top 50 page
5 * @author Anthony Parsons (xmpp:ant@specialops.ath.cx)
6 * @license file://COPYING
7 * @version $Id$
8 */
10 require 'conf.php';
12 switch ( $_SERVER['QUERY_STRING'] ) {
13 case 'online':
14 $page->title = 'Currently Online Users';
15 $where = 'WHERE `last_active_date` > UNIX_TIMESTAMP() - 600 GROUP BY `userid` ASC';
16 break;
18 default:
19 if ( $DB->query('SELECT COUNT(*) AS `c` FROM `users`')->fetch_object()->c > 50 ) {
20 $page->title = 'Top 50 Users';
21 $where = 'GROUP BY `userid` ORDER BY `points` DESC LIMIT 50';
22 } else {
23 $page->title = 'User List';
24 $where = 'GROUP BY `userid` ASC';
28 $user->userheader();
31 <table id="userlist">
32 <col/><col/><col/><col/><col/>
33 <thead>
34 <tr><th>Username</th><th>Points</th><th>Posts</th><th>Last Active</th><th>Idle Time</th></tr>
35 </thead>
36 <tbody>
37 <?php
38 $q = $DB->query('SELECT `users`.`userid`, `alias`, `points`, `last_active_date`, COUNT(`messageid`) AS `msgs`
39 FROM `users` NATURAL LEFT JOIN `messages` '.$where);
41 function idle($last)
43 // voodoo
44 $idle = time() - $last;
45 $idle -= ($time[2] = $idle % 60); $idle /= 60;
46 $idle -= ($time[1] = $idle % 60); $idle /= 60;
47 $idle -= ($time[0] = $idle % 24); $time[3] = $idle / 24;
49 ksort($time);
51 return ( $time[3] ? $time[3].' day'.( 1 != $time[3] ? 's ' : ' ' ) : '').vsprintf('%d:%02d:%02d', $time);
54 $a = 1;
56 while ( $row = $q->fetch_assoc() ) {
57 // mew
58 printf('<tr class="content c%d"><td>%s</td><td>%d</td><td>%d</td><td>%s</td><td>%s</td></tr>'."\n",
59 (++$a&1),
60 $user->namelink($row['userid'], $row['alias']),
61 $row['points'],
62 $row['msgs'],
63 $user->fdate($row['last_active_date']),
64 $user instanceof authuser && $user->userid == $row['userid'] ? '' : idle($row['last_active_date'])
68 </tbody>
69 </table>
70 <?php
71 $page->pagefooter();