* @subpackage Examples */ require_once 'HTML/Progress/monitor.php'; function logger($progressValue, &$bar) { include_once 'Log.php'; $logger =& Log::singleton('file', 'monitor.log', $_SERVER['REMOTE_ADDR']); $percent = $bar->getPercentComplete(false); if (fmod($progressValue, 25) == 0) { $logger->info("{$percent}% has been reached"); } else { $logger->debug("Progress ... {$progressValue}"); } } $monitor = new HTML_Progress_Monitor(); $monitor->setProgressHandler('logger'); $pb =& $monitor->getProgressElement(); $dm =& $pb->getDM(); $dm->setMaximum(300); ?> <html> <head> <title>ProgressBar Monitor - Default renderer </title> <style type="text/css"> <!-- .progressStatus { color:#000000; font-size:10px; } <?php echo $monitor->getStyle();
$bar->setString(null); // show percent-info $bar->setValue(0); } if ($bar->getPercentComplete() == 1) { if ($bar->isIndeterminate()) { $bar->setValue(0); } else { $bar->setString(''); // hide percent-info } } } $monitor = new HTML_Progress_Monitor('frmMonitor', array('button' => array('style' => 'width:80px;'), 'title' => 'Progress ...')); // your custom user process goes here ! $monitor->setProgressHandler('myProgressHandler'); // Attach a progress bar custom model $progress = new HTML_Progress(); $ui =& $progress->getUI(); $ui->setProgressAttributes(array('background-color' => '#e0e0e0')); $ui->setStringAttributes(array('color' => '#996', 'background-color' => '#CCCC99')); $ui->setCellAttributes(array('active-color' => '#996')); $progress->setAnimSpeed(100); $progress->setIncrement(10); $progress->setStringPainted(true); // get space for the string $progress->setString(""); // but don't paint it $progress->setIndeterminate(true); // Progress start in indeterminate mode $monitor->setProgressElement($progress);
$this->setCellAttributes(array('active-color' => '#996')); } } class myClassHandler { function myMethodHandler($progressValue, &$obj) { if (fmod($progressValue, 10) == 0) { echo "myMethodHandler -> progress value is = {$progressValue} <br/>\n"; } $bar =& $obj->getProgressElement(); $bar->sleep(); } } $monitor = new HTML_Progress_Monitor('frmMonitor3', array('button' => array('style' => 'width:80px;'))); $monitor->setProgressHandler(array('myClassHandler', 'myMethodHandler')); $progress = new HTML_Progress(); $progress->setUI('Progress_Default2'); // Attach a progress ui-model $progress->setAnimSpeed(20); $monitor->setProgressElement($progress); ?> <html> <head> <title>ProgressBar Monitor - Default renderer </title> <style type="text/css"> <!-- .progressStatus { color:#000000; font-size:10px; }
} else { /* in case we have attached an indeterminate progress bar to the monitor ($obj) after a first pass that reached 60%, we swap from indeterminate mode to determinate mode and run a standard progress bar from 0 to 100% */ if ($progressValue == 60) { $bar->setIndeterminate(false); $bar->setString(null); // show percent-info $bar->setValue(0); } } } $monitor = new HTML_Progress_Monitor('frmMonitor4', array('button' => array('style' => 'width:80px;'))); $monitor->setProgressHandler('myFunctionHandler'); $progress = new HTML_Progress(); $progress->setAnimSpeed(20); $progress->setUI('Progress_ITDynamic'); // Attach a progress ui-model $progress->setStringPainted(true); // get space for the string $progress->setString(""); // but don't paint it $progress->setIndeterminate(true); // Progress start in indeterminate mode $monitor->setProgressElement($progress); ?> <html> <head> <title>ProgressBar Monitor - Default renderer </title>
break; case 70: $pic = 'picture3.jpg'; break; default: $pic = null; } if (!is_null($pic)) { $obj->setCaption('upload <b>%file%</b> in progress ... Start at %percent%%', array('file' => $pic, 'percent' => $progressValue)); } $bar =& $obj->getProgressElement(); $bar->sleep(); // slow animation because we do noting else } } $monitor = new HTML_Progress_Monitor('frmMonitor5', array('title' => 'Upload your pictures', 'start' => 'Upload', 'cancel' => 'Stop', 'button' => array('style' => 'width:80px;'))); $monitor->setProgressHandler(array('my2ClassHandler', 'my1Method')); $progress = new HTML_Progress(); $progress->setUI('Progress_ITDynamic'); $progress->setAnimSpeed(50); $monitor->setProgressElement($progress); $tpl =& new HTML_Template_ITX('../templates'); $tpl->loadTemplateFile('itdynamic_monitor.html'); $tpl->setVariable(array('qf_style' => "body {font-family: Verdana, Arial; } \n" . $monitor->getStyle(), 'qf_script' => $monitor->getScript())); $renderer =& new HTML_QuickForm_Renderer_ITDynamic($tpl); $renderer->setElementBlock(array('buttons' => 'qf_buttons')); $monitor->accept($renderer); // Display progress uploader dialog box $tpl->show(); $monitor->run(); echo '<p><< <a href="../index.html">Back examples TOC</a></p>';