"; if (!$isadmin) { print " $tblstart $tccell1>This feature is restricted. $tblend $footer "; printtimedif($startingtime); die(); } print adminlinkbar("admin-threads.php"); if (!$_POST['run']) { print "
$tblstart $tccellh>Thread Repair System $tccell1> 
This page is intended to repair threads with broken reply counts. Please don't flood it with requests.
This problem causes \"phantom pages\" (e.g., too few or too many pages displayed).
 
$inps=\"run\" value=\"Start\">
  $tblend
"; } else { print " $tblstart $tccellh>Thread Repair System $tccell1>Now running. $tblend
$tblstart $tccellh>id# $tccellh>Name $tccellh>Reports $tccellh>Real $tccellh>Err $tccellh>Status "; $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 = "Invalid thread"; } else { $status = mysql_query("UPDATE `threads` SET `replies` = '". ($data['real'] - 1) ."' WHERE `id` = '". $data['thread'] ."'") or "Error: ". mysql_error(); if ($status == 1) $status = "Updated"; $count++; } print " $tccell1>". $data['thread'] ." $tccell2l>". ($data['threadname'] !== null ? $data['threadname'] : "(Deleted thread)") ." $tccell1>". ($data['replies'] !== null ? $data['replies'] + 1 : "—") ." $tccell1>". ($data['real']) ." $tccell2>". ($data['offset'] !== null ? $data['offset'] : "—") ." $tccell1>$status "; } else { continue; } } if ($count) { print "$tccellc colspan=6>$count thread". ($count != 1 ? "s" : "") ." updated."; } else { print " $tccell1 colspan=6> 
No problems found.
  "; } } print "$tblend $footer "; printtimedif($startingtime);