forked from Kak2X/jul
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathranks.php
123 lines (106 loc) · 3.58 KB
/
ranks.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
require 'lib/function.php';
$_GET['set'] = filter_int($_GET['set']);
$_GET['showall'] = filter_int($_GET['showall']);
if (!$_GET['set']) $_GET['set'] = -1;
//$set = (($_GET['set']) ? (int) $_GET['set'] : -1);
//$showall = (($_GET['showall']) ? 1 : 0);
$ranksetlist = "";
$rsets = $sql->query('SELECT * FROM ranksets WHERE id > 0 ORDER BY id');
while ($rset = $sql->fetch($rsets)) {
// Select first rankset in none was specified
if ($_GET['set'] < 0) $_GET['set'] = $rset['id'];
$selected = ($rset['id'] == $_GET['set'] ? 'selected' : '' );
$ranksetlist .= "<option value={$rset['id']} {$selected}>{$rset['name']}";
}
$ch[$_GET['showall']] = 'checked';
pageheader();
?>
<FORM ACTION=ranks.php NAME=REPLIER>
<table class='table'>
<tr><td class='tdbgh center' colspan=2> </td></tr>
<tr>
<td class='tdbg1 center'><b>Rank set</b></td>
<td class='tdbg2'>
<select name=set><?=$ranksetlist?></select>
</td>
</tr>
<tr>
<td class='tdbg1 center'><b>Users to show</b></td>
<td class='tdbg2'>
<input type=radio class='radio' name=showall value=0 <?=filter_string($ch[0])?>> Selected rank set only
<input type=radio class='radio' name=showall value=1 <?=filter_string($ch[1])?>> All users
</td>
</tr>
<tr><td class='tdbgh center' colspan=2> </td></tr>
<tr>
<td class='tdbg1 center'> </td>
<td class='tdbg2'><input type=submit class=submit value=View></td>
</tr>
</table>
</FORM>
<br>
<table class='table'>
<tr>
<td class='tdbgh center' width=150>Rank</td>
<td class='tdbgh center' width=60>Posts</td>
<td class='tdbgh center' width=60>Ranking</td>
<td class='tdbgh center' colspan=2>Users on that rank</td>
</tr>
<?php
// Print
$useranks = ($_GET['showall'] ? '' : "AND useranks={$_GET['set']}");
$btime = ctime()-86400*30; // 30 days without browsing = Marked as inactive
$ranks = $sql->query("SELECT * FROM ranks WHERE rset = {$_GET['set']} ORDER BY num");
$totalranks = $sql->num_rows($ranks);
if ($totalranks > 0) {
$rank = $sql->fetch($ranks);
// 300 queries [11sec] ---> 20 queries [1sec]
$users = $sql->query("SELECT $userfields, posts, lastactivity, lastposttime FROM users u WHERE posts >= {$rank['num']} $useranks ORDER BY posts ASC");
$user = $sql->fetch($users);
$total = $sql->num_rows($users);
}
for($i = 0; $i < $totalranks; ++$i) {
$rankn = $sql->fetch($ranks);
if(!$rankn['num']) $rankn['num'] = 8388607;
$userarray = array();
$inactive = 0;
for($u = 0; $user && $user['posts'] < $rankn['num']; ++$u){
if (max($user['lastactivity'], $user['lastposttime']) > $btime) {
$userarray[$user['name']] = getuserlink($user);
} else {
++$inactive;
}
$user = $sql->fetch($users);
}
@ksort($userarray);
$userlisting = implode(", ", $userarray);
if ($inactive) $userlisting .= ($userlisting?', ':'')."$inactive inactive";
if (!$userlisting) $userlisting = ' ';
if ($userlisting != ' ' || $rank['num'] <= $loguser['posts'] || $ismod) {
?> <tr>
<td class='tdbg2 fonts' width=200><?=$rank['text']?></td>
<td class='tdbg1 center' width=60><?=$rank['num']?></td>
<td class='tdbg1 center' width=60><?=$total?></td>
<td class='tdbg1 center' width=30><?=$u?></td>
<td class='tdbg2 fonts center' width=*><?=$userlisting?></td>
</tr>
<?php
} else {
?> <tr>
<td class='tdbg1 fonts' width=200>? ? ?</td>
<td class='tdbg1 center' width=60>???</td>
<td class='tdbg1 center' width=60>?</td>
<td class='tdbg1 center' width=30>?</td>
<td class='tdbg1 fonts center' width=*>?</td>
</tr>
<?php
}
$rank = $rankn;
$total -= $u;
}
?>
</table>
<?php
pagefooter();