-
Notifications
You must be signed in to change notification settings - Fork 0
/
recalc.php
105 lines (87 loc) · 3.84 KB
/
recalc.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
<?php
// AcmlmBoard XD - Report/content mismatch fixing utility
// Access: staff
include("lib/common.php");
AssertForbidden("recalculate");
if($loguser['powerlevel'] < 1)
Kill(__("Staff only, please."));
print "<table class=\"outline margin width50\">";
print "<tr class=\"header1\"><th>".__("Name")."</th><th>".__("Actual")."</th><th>".__("Reported")."</th><th> </th></tr>";
print "<tr class=\"header0\"><th colspan=\"4\">".__("Counting user's posts…")."</th></tr>";
$qUsers = "select * from users";
$rUsers = Query($qUsers);
while($user = Fetch($rUsers))
{
$cellClass = ($cellClass+1) % 2;
print "<tr class=\"cell".$cellClass."\">";
print "<td>".htmlspecialchars($user['name'])."</td>";
$qPosts = "select count(*) from posts where user=".$user['id'];
$posts = FetchResult($qPosts);
print "<td>".$posts."</td><td>".$user['posts']."</td>";
print "<td style=\"background: ".($posts==$user['posts'] ? "green" : "red").";\"></td>";
print "</tr>";
$qUser = "update users set posts=".$posts." where id=".$user['id']." limit 1";
$rUser = Query($qUser);
RecalculateKarma($user['id']);
}
print "<tr class=\"header0\"><th colspan=\"4\">".__("Counting thread replies…")."</th></tr>";
$qThreads = "select * from threads";
$rThreads = Query($qThreads);
while($thread = Fetch($rThreads))
{
$thread['title'] = htmlspecialchars($thread['title']);
$cellClass = ($cellClass+1) % 2;
print "<tr class=\"cell".$cellClass."\">";
print "<td>".$thread['title']."</td>";
$qPosts = "select count(*) from posts where thread=".$thread['id'];
$posts = FetchResult($qPosts);
print "<td>".($posts-1)."</td><td>".$thread['replies']."</td>";
print "<td style=\"background: ".($posts-1==$thread['replies'] ? "green" : "red").";\"></td>";
print "</tr>";
$qThread = "update threads set replies=".($posts-1)." where id=".$thread['id']." limit 1";
$rThread = Query($qThread);
}
print "<tr class=\"header0\"><th colspan=\"4\">".__("Counting forum threads and posts…")."</th></tr>";
$qFora = "select * from forums";
$rFora = Query($qFora);
while($forum = Fetch($rFora))
{
$cellClass = ($cellClass+1) % 2;
print "<tr class=\"cell".$cellClass."\">";
print "<td>".$forum['title']."</td>";
$qThreads = "select * from threads where forum=".$forum['id'];
$rThreads = Query($qThreads);
$threads = NumRows($rThreads);
$postcount = 0;
while($thread = Fetch($rThreads))
{
$qPosts = "select count(*) from posts where thread=".$thread['id'];
$posts = FetchResult($qPosts);
$postcount += $posts;
}
print "<td>".$threads." / ".$postcount."</td><td>".$forum['numthreads']." / ".$forum['numposts']."</td>";
print "<td style=\"background: ".($threads==$forum['numthreads'] && $postcount==$forum['numposts'] ? "green" : "red").";\"></td>";
print "</tr>";
$qForum = "update forums set numposts=".$postcount.", numthreads=".$threads." where id=".$forum['id']." limit 1";
$rForum = Query($qForum);
}
print "<tr class=\"header0\"><th colspan=\"4\">".__("All counters reset.")."</th></tr>";
print "</table>";
$rForum = Query("select * from forums");
while($forum = Fetch($rForum))
{
print $forum['title']."<br/>";
$rThread = Query("select * from threads where forum = ".$forum['id']." order by lastpostdate desc");
$first = 1;
while($thread = Fetch($rThread))
{
print "» ".htmlspecialchars($thread['title'])."<br/>";
$lastPost = Fetch(Query("select * from posts where thread = ".$thread['id']." order by date desc limit 0,1"));
print "» » Last post ID is ".$lastPost['id']." by user #".$lastPost['user']."<br/>";
Query("update threads set lastpostid = ".$lastPost['id'].", lastposter = ".$lastPost['user'].", lastpostdate = ".$lastPost['date']." where id = ".$thread['id']);
if($first)
Query("update forums set lastpostid = ".$lastPost['id'].", lastpostuser = ".$lastPost['user'].", lastpostdate = ".$lastPost['date']." where id = ".$forum['id']);
$first = 0;
}
}
?>