3 * User Directory/Online Users/Top 50 page
5 * @author Ant P <p@cpi.merseine.nu>
6 * @license file://COPYING
13 'ID' => array('userid', 0),
14 'Username' => array('alias', 0),
15 'Points' => array('points', 1),
16 'Posts' => array('posts', 1),
17 'Last Active' => array('last_active_date', 1),
20 $sort = array('ASC', 'DESC');
23 if ( isset($_GET['sort']) && in_array($_GET['sort'], array_keys($headers)) ) {
24 $field = ' ORDER BY '.$headers[$_GET['sort']][0].' '.$sort[ $headers[$_GET['sort']][1]^
isset($_GET['rev']) ];
29 if ( isset($_GET['online']) ) {
30 SO2
::$Page->title
= 'Currently Online Users';
31 $where = 'WHERE last_active_date > UNIX_TIMESTAMP() - 600 GROUP BY userid ASC'.$field;
33 if ( 0 >= SO2
::$User->points
) {
34 SO2
::$Page->message(Page
::ERR_UPOINTS
);
37 SO2
::$Page->title
= 'User List';
38 $where = 'GROUP BY userid ASC'.$field;
40 if ( SO2
::$DB->query('SELECT COUNT(*) FROM users')->fetchColumn(0) > 50 ) {
41 SO2
::$Page->title
= 'Top 50 Users';
42 $where .= ' LIMIT 50'.( $field ?
$field : ' ORDER BY points DESC');
46 SO2
::$Page->pageheader();
48 define('HERE', 'userlist?'.(isset($_GET['online']) ?
'online;' : ''));
54 <?php
foreach ( $headers as $label => $field ) {
57 $rev = ( isset($_GET['sort']) && !isset($_GET['rev']) && $_GET['sort'] == $label ) ?
';rev">↑' : '">↓';
58 echo '<th><a href="',HERE
,'sort=',urlencode($label),$rev,$label,'</a></th>';
60 echo '<th>',$label,'</th>';
67 $q = SO2
::$DB->query('SELECT users.userid, points, last_active_date, COUNT(messageid) AS posts '.
68 'FROM users NATURAL LEFT JOIN messages '.$where)->fetchAll(PDO
::FETCH_ASSOC
);
73 $idle = T_NOW
- $last;
74 $idle -= ($time[2] = $idle %
60); $idle /= 60;
75 $idle -= ($time[1] = $idle %
60); $idle /= 60;
76 $idle -= ($time[0] = $idle %
24); $time[3] = $idle / 24;
79 return ( $time[3] ?
$time[3].' day'.( 1 != $time[3] ?
's ' : ' ' ) : '').vsprintf('%d:%02d:%02d', $time);
84 foreach ( $q as $row ) {
86 printf("<tr class='content c%d'>\n".
87 " <td>%d</td><td>%s</td><td>%d</td><td>%d</td><td>%s</td><td>%s</td>\n".
89 (++
$a&1), $row['userid'], SO2
::$Page->namelink($row['userid']), $row['points'],
90 $row['posts'], SO2
::$Page->fdate($row['last_active_date']), idle($row['last_active_date'])