adding function print_progress from upgradeforumread
This commit is contained in:
@@ -290,4 +290,45 @@ function set_cron_lock($name,$value=true,$staleafter=7200,$clobberstale=false) {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function print_progress($done, $total, $updatetime=5, $sleeptime=1) {
|
||||
static $count;
|
||||
static $starttime;
|
||||
static $lasttime;
|
||||
|
||||
if (empty($starttime)) {
|
||||
$starttime = $lasttime = time();
|
||||
$lasttime = $starttime - $updatetime;
|
||||
echo '<table width="500" cellpadding="0" cellspacing="0" align="center"><tr><td width="500">';
|
||||
echo '<div id="bar" style="border-style:solid;border-width:1px;width:500px;height:50px;">';
|
||||
echo '<div id="slider" style="border-style:solid;border-width:1px;height:48px;width:10px;background-color:green;"></div>';
|
||||
echo '</div>';
|
||||
echo '<div id="text" align="center" style="width:500px;"></div>';
|
||||
echo '</td></tr></table>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
if (!isset($count)) {
|
||||
$count = 0;
|
||||
}
|
||||
|
||||
$count++;
|
||||
|
||||
$now = time();
|
||||
|
||||
if ($done && (($now - $lasttime) >= $updatetime)) {
|
||||
$elapsedtime = $now - $starttime;
|
||||
$projectedtime = (int)(((float)$total / (float)$done) * $elapsedtime) - $elapsedtime;
|
||||
$percentage = format_float((float)$done / (float)$total, 2);
|
||||
$width = (int)(500 * $percentage);
|
||||
|
||||
echo '<script>';
|
||||
echo 'document.getElementById("text").innerHTML = "'.$count.' done. Ending: '.format_time($projectedtime).'";'."\n";
|
||||
echo 'document.getElementById("slider").style.width = \''.$width.'px\';'."\n";
|
||||
echo '</script>';
|
||||
|
||||
$lasttime = $now;
|
||||
sleep($sleeptime);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user