-
<?php
-
// Load SSI.php
-
require_once('SSI.php');
-
-
// Turn this on.
-
-
-
// Are we allowed in here?
-
isAllowedTo('admin_forum');
-
-
$_REQUEST['start'] = !
isset($_REQUEST['start']) ?
'0' :
(int
) $_REQUEST['start'];
-
-
// Header step and footer.
-
show_header();
-
// Check if it exists.
-
if (!
empty($_REQUEST['start']) ||
(empty($_REQUEST['start']) &&
isset($_REQUEST['recount'])))
-
recount();
-
elseif (isset($_GET['start']) &&
$_GET['start'] != -
1)
-
// Give a link to start
-
-
<h2><a href="', $_SERVER['PHP_SELF'], '?recount;start=0">Start Post Recount</a></h2>';
-
// Footeeerr.
-
show_footer();
-
-
-
function recount()
-
{
-
-
-
while (true)
-
{
-
// Only run this query if we don't have the total.
-
if (!
isset($_SESSION['totalMembers']))
-
{
-
$request = db_query("
-
SELECT COUNT(DISTINCT m.ID_MEMBER)
-
FROM ({$db_prefix}messages AS m, {$db_prefix}boards AS b)
-
WHERE m.ID_MEMBER != 0
-
AND b.countPosts = 0
-
AND m.ID_BOARD = b.ID_BOARD", __FILE__, __LINE__);
-
-
-
$_SESSION['recountedMembers'] = 0;
-
}
-
-
// Lets get the members and their post counts.
-
// Make sure that we only get boards that have posts count enabled.
-
// !!! On a big board 200 might be a bit to high to count.
-
$request = db_query("
-
SELECT m.ID_MEMBER, COUNT(m.ID_MEMBER) AS posts
-
FROM ({$db_prefix}messages AS m, {$db_prefix}boards AS b)
-
WHERE m.ID_MEMBER != 0
-
AND b.countPosts = 0
-
AND m.ID_BOARD = b.ID_BOARD
-
GROUP BY m.ID_MEMBER
-
LIMIT $_REQUEST[start], 200", __FILE__, __LINE__);
-
-
$_SESSION['recountedMembers'] += $total_rows * 200;
-
-
// Get all the results and assign the correct value.
-
-
db_query("
-
UPDATE {$db_prefix}members
-
SET posts = $row[posts]
-
WHERE ID_MEMBER = $row[ID_MEMBER]", __FILE__, __LINE__);
-
-
$_GET['start'] += 200;
-
if ($total_rows <200)
-
$_GET['start'] = -1;
-
nextStep();
-
}
-
}
-
-
-
function show_header()
-
{
-
-
-
if (isset($_SESSION['totalMembers']) && !
empty($_GET['start']))
-
{
-
-
$total_members =
isset($_SESSION['totalMembers']) ?
$_SESSION['totalMembers'] :
0;
-
$fake_start = $_GET['start'] + 200>= $total_members ? $total_members : $_GET['start'] + 2;
-
$percent =
round(100 /
$total_members *
$fake_start,
2);
-
}
-
-
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
<html>
-
<head>
-
<title>SMF Member Posts Recount</title>
-
<style type="text/css"><!--
-
body
-
{
-
background-color: #E5E5E5;
-
margin: 0;
-
padding: 0;
-
font-size: 10pt;
-
}
-
#header
-
{
-
font-weight: bold;
-
font-size: 200%;
-
}
-
#content
-
{
-
background-color: #CECED7;
-
border: 1px solid #8B9AAA;
-
padding: 2px;
-
}
-
#footer
-
{
-
font-size: 12px;
-
text-align: right;
-
font-style: italic;
-
}
-
#container
-
{
-
width: 50%;
-
margin: 0 auto 0 auto;
-
}
-
h2
-
{
-
margin: 0;
-
margin-top: 0.5ex;
-
margin-bottom: 0.5ex;
-
padding-bottom: 3px;
-
border-bottom: 1px dashed black;
-
font-size: 14pt;
-
font-weight: normal;
-
}
-
h3
-
{
-
margin: 0;
-
margin-bottom: 2ex;
-
font-size: 10pt;
-
font-weight: normal;
-
}
-
input
-
{
-
margin: 2px;
-
}
-
.status_bar_border
-
{
-
height: 20px;
-
width: 450px;
-
background: #ffffff;
-
border: 1px solid silver;
-
margin: 0 auto 0 auto;
-
padding-right: 4px;
-
text-align: right;
-
}
-
.status_bar
-
{
-
height: 16px;
-
margin: 2px;
-
padding: 0px;
-
text-align: center;
-
text-align: right;
-
}
-
.bg1
-
{
-
background: #3dc0df;
-
}
-
.bg2
-
{
-
background: #C9DDEC;
-
}
-
.percent
-
{
-
text-align: right;
-
color: #000;
-
font-weight: bold;
-
padding-bottom: 5px;
-
}
-
.codebox
-
{
-
background-color: #cccccc;
-
font: normal 10px "Courier New", monospace;
-
border: solid 1px black;
-
padding: 5px;
-
white-space: nowrap;
-
overflow: auto;
-
width: 95%;
-
}
-
--></style>
-
</head>
-
<body>
-
<div id="container">
-
<div id="header">
-
SMF Member Posts Recount
-
</div>
-
<div id="content">';
-
-
if (!
empty($total_members))
-
-
<h2>Recount Status</h2>
-
<h3 style="margin: 0 0 0 40px; font-weight: bold;">Overall Process</h3>
-
<div class="status_bar_border">
-
<div class="status_bar bg1" style="width: ', $percent, '%; white-space: nowrap;">', $percent, '% (', $fake_start, ' out of ', $total_members, ' members) </div>
-
</div>';
-
-
if (isset($percent) &&
$percent ==
100 ||
isset($_GET['start']) &&
$_GET['start'] == -
1)
-
-
<h1>Recount Complete</h1>';
-
-
}
-
-
function show_footer()
-
{
-
-
</div>
-
<div id="footer">
-
<a href="http://jaybachatero.com">JayBachatero.com</a>
-
</div>
-
</div>
-
</body>
-
</html>';
-
}
-
-
function nextStep($step = null)
-
{
-
-
-
-
-
apache_reset_timeout();
-
-
-
<h2 style="margin-top: 2ex;">Recount Paused!</h2>
-
<h3>This recount has paused to avoid server overload.</h3>
-
<form action="', $_SERVER['PHP_SELF'], '?start=', $_GET['start'], '" method="post" name="auto_submit">
-
<div align="right" style="margin: 1ex;"><input name="timer" type="submit" value="Continue" /></div>
-
</form>
-
<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
-
window.onload = autoSubmit;
-
var countdown = 3;
-
function autoSubmit()
-
{
-
if (countdown == 0)
-
document.auto_submit.submit();
-
else if (countdown == -1)
-
return;
-
document.auto_submit.timer.value = "Continue (" + countdown + ")";
-
countdown--;
-
setTimeout("autoSubmit();", 1000);
-
}
-
// ]]></script>';
-
-
show_footer();
-
-
}
-
?>