From: dongsheng Date: Fri, 23 May 2008 05:29:51 +0000 (+0000) Subject: "MDL-14706, improve the progress bar, merged from MOODLE_19_STABLE" X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=67784b2fe9ecfe06403b98d755aad58538a0941c;p=moodle.git "MDL-14706, improve the progress bar, merged from MOODLE_19_STABLE" --- diff --git a/lib/adminlib.php b/lib/adminlib.php index 659b55a237..fa286d0366 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -486,6 +486,7 @@ function set_cron_lock($name, $until, $ignorecurrent=false) { } function print_progress($done, $total, $updatetime=5, $sleeptime=1, $donetext='') { + static $thisbarid; static $starttime; static $lasttime; @@ -493,14 +494,26 @@ function print_progress($done, $total, $updatetime=5, $sleeptime=1, $donetext='' return; } + // Are we done? + if ($done >= $total) { + $done = $total; + if (!empty($thisbarid)) { + $donetext .= ' ('.$done.'/'.$total.') '.get_string('success'); + print_progress_redraw($thisbarid, $done, $total, 500, $donetext); + $thisbarid = $starttime = $lasttime = NULL; + } + return; + } + if (empty($starttime)) { $starttime = $lasttime = time(); $lasttime = $starttime - $updatetime; + $thisbarid = uniqid(); echo '
'; - echo '
'; - echo '
'; + echo '
'; + echo '
'; echo '
'; - echo '
'; + echo '
'; echo '
'; echo ''; } @@ -519,16 +532,24 @@ function print_progress($done, $total, $updatetime=5, $sleeptime=1, $donetext='' $projectedtext = ''; } - echo ''; + $donetext .= ' ('.$done.'/'.$total.') '.$projectedtext; + print_progress_redraw($thisbarid, $done, $total, $width, $donetext); $lasttime = $now; - sleep($sleeptime); } } +// Don't call this function directly, it's called from print_progress. +function print_progress_redraw($thisbarid, $done, $total, $width, $donetext='') { + if (empty($thisbarid)) { + return; + } + echo ''; +} + function upgrade_get_javascript() { global $CFG;