Make the stats page slightly less confusing
[specialops2.git] / userlist.php
blob1f7ae079d2fa0b9b5e709f3f223c64b098785826
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 'con.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 ( 0 >= $user->points ) {
20 $page->errorfooter('points');
23 if ( $DB->query('SELECT COUNT(*) AS `c` FROM `users`')->fetch_object()->c > 50 ) {
24 $page->title = 'Top 50 Users';
25 $where = 'GROUP BY `userid` ORDER BY `points` DESC LIMIT 50';
26 } else {
27 $page->title = 'User List';
28 $where = 'GROUP BY `userid` ASC';
32 $user->userheader();
35 <table id="userlist">
36 <col/><col/><col/><col/><col/>
37 <thead>
38 <tr><th>ID</th><th>Username</th><th>Points</th><th>Posts</th><th>Last Active</th><th>Idle Time</th></tr>
39 </thead>
40 <tbody>
41 <?php
42 $q = $DB->query('SELECT `users`.`userid`, `alias`, `points`, `last_active_date`, COUNT(`messageid`) AS `msgs`
43 FROM `users` NATURAL LEFT JOIN `messages` '.$where);
45 function idle($last)
47 // voodoo
48 $idle = time() - $last;
49 $idle -= ($time[2] = $idle % 60); $idle /= 60;
50 $idle -= ($time[1] = $idle % 60); $idle /= 60;
51 $idle -= ($time[0] = $idle % 24); $time[3] = $idle / 24;
53 ksort($time);
55 return ( $time[3] ? $time[3].' day'.( 1 != $time[3] ? 's ' : ' ' ) : '').vsprintf('%d:%02d:%02d', $time);
58 $a = 1;
60 while ( $row = $q->fetch_assoc() ) {
61 // mew
62 printf('<tr class="content c%d"><td>%d</td><td>%s</td><td>%d</td><td>%d</td><td>%s</td><td>%s</td></tr>'."\n",
63 (++$a&1),
64 $row['userid'],
65 $user->namelink($row['userid'], $row['alias']),
66 $row['points'],
67 $row['msgs'],
68 $user->fdate($row['last_active_date']),
69 idle($row['last_active_date'])
73 </tbody>
74 </table>
75 <?php
76 $page->pagefooter();