Special Ops 2.50
[specialops2.git] / userlist.php
blob7e8c52d6dc89cfd4604ebb0b06e1e1d2b4baf9d6
1 <?php
2 /**
3 * User Directory/Online Users/Top 50 page
5 * @author Ant P <p@cpi.merseine.nu>
6 * @license file://COPYING
7 * @version 2.15
8 */
10 require 'con.php';
12 $headers = array (
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),
18 'Idle Time' => null
20 $sort = array('ASC', 'DESC');
22 // DO NOT WANT
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']) ];
25 } else {
26 $field = null;
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;
32 } else {
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;' : ''));
51 <table id="userlist">
52 <thead>
53 <tr>
54 <?php foreach ( $headers as $label => $field ) {
55 echo ' ';
56 if ( $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>';
59 } else {
60 echo '<th>',$label,'</th>';
62 } ?>
63 </tr>
64 </thead>
65 <tbody>
66 <?php
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);
70 function idle($last)
72 // voodoo
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;
78 ksort($time);
79 return ( $time[3] ? $time[3].' day'.( 1 != $time[3] ? 's ' : ' ' ) : '').vsprintf('%d:%02d:%02d', $time);
82 $a = 1;
84 foreach ( $q as $row ) {
85 // eww
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".
88 "</tr>\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'])
94 </tbody>
95 </table>