-
Notifications
You must be signed in to change notification settings - Fork 13
/
admin-threads.php
108 lines (87 loc) · 2.89 KB
/
admin-threads.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
<?php
$windowtitle = "Thread Repair System";
require 'lib/function.php';
require 'lib/layout.php';
print "$header<br>";
if (!$isadmin) {
print "
$tblstart
$tccell1>This feature is restricted.</td>
$tblend
$footer
";
printtimedif($startingtime);
die();
}
print adminlinkbar("admin-threads.php");
if (!$_POST['run']) {
print "<form action=\"admin-threads.php\" method=\"post\">
$tblstart
<tr>$tccellh>Thread Repair System</td></tr>
<tr>$tccell1>
<br>This page is intended to repair threads with broken reply counts. Please don't flood it with requests.
<br>This problem causes \"phantom pages\" (e.g., too few or too many pages displayed).
<br>
<br>$inps=\"run\" value=\"Start\">
<br>
</td></tr>
$tblend
</form>
";
} else {
print "
$tblstart
<tr>$tccellh>Thread Repair System</td></tr>
<tr>$tccell1>Now running.
</td></tr>
$tblend
<br>
$tblstart
<tr>
$tccellh>id#</td>
$tccellh>Name</td>
$tccellh>Reports</td>
$tccellh>Real</td>
$tccellh>Err</td>
$tccellh>Status</td>
</tr>
";
$q = "SELECT `posts`.`thread`, (COUNT(`posts`.`id`)) AS 'real', ((CAST(COUNT(`posts`.`id`) AS SIGNED) - 1) - CAST(`threads`.`replies` AS SIGNED)) AS 'offset', `threads`.`replies`, `threads`.`title` AS `threadname` FROM `posts` LEFT JOIN `threads` ON `posts`.`thread` = `threads`.`id` GROUP BY `thread` HAVING `offset` <> 0 OR `offset` IS NULL ORDER BY ISNULL(`threadname`) ASC, `thread` DESC";
$sql = mysql_query($q) or die(mysql_error());
$count = "";
while ($data = mysql_fetch_array($sql, MYSQL_ASSOC)) {
$status = "";
if ($data['offset'] != 0 || $data['offset'] === null) {
if ($data['replies'] === null) {
$status = "<font color=\"#ff8080\">Invalid thread</font>";
} else {
$status = mysql_query("UPDATE `threads` SET `replies` = '". ($data['real'] - 1) ."' WHERE `id` = '". $data['thread'] ."'") or "<font color=#ff0000>Error</font>: ". mysql_error();
if ($status == 1) $status = "<font color=#80ff80>Updated</font>";
$count++;
}
print "
<tr>
$tccell1><a href=\"thread.php?id=". $data['thread'] ."\">". $data['thread'] ."</a></td>
$tccell2l><a href=\"thread.php?id=". $data['thread'] ."\">". ($data['threadname'] !== null ? $data['threadname'] : "<em>(Deleted thread)</em>") ."</a></td>
$tccell1>". ($data['replies'] !== null ? $data['replies'] + 1 : "—") ."</td>
$tccell1>". ($data['real']) ."</td>
$tccell2><b>". ($data['offset'] !== null ? $data['offset'] : "—") ."</b></td>
$tccell1>$status</td>
</tr>";
} else {
continue;
}
}
if ($count) {
print "<tr>$tccellc colspan=6>$count thread". ($count != 1 ? "s" : "") ." updated.</td></tr>";
} else {
print " <tr>$tccell1 colspan=6>
<br>No problems found.
<br>
</td></tr>";
}
}
print "$tblend
$footer
";
printtimedif($startingtime);