* @package HTML_Progress
*/
require_once ('HTML/Progress/monitor.php');
class Task extends HTML_Progress_Monitor
{
var $_current;
function Task()
{
$this->_current = 0;
$this->_id = md5(microtime());
$this->_form = new HTML_QuickForm('ProgressBarDialog');
$renderer =& $this->_form->defaultRenderer();
$renderer->setFormTemplate('
');
$renderer->setHeaderTemplate('
{header} |
');
$this->_form->addElement('header', 'windowsname', 'Progress...');
$this->_form->addElement('static', 'progress');
$this->_form->addElement('static', 'status');
$buttons[] = &HTML_QuickForm::createElement('submit', 'start', 'Start', 'style="width:80px;"');
$buttons[] = &HTML_QuickForm::createElement('submit', 'cancel', 'Cancel', 'style="width:80px;"');
$this->_form->addGroup($buttons);
$this->_progress = new HTML_Progress();
$this->_progress->setIncrement(10);
$this->_progress->setStringPainted(true); // get space for the string
$this->_progress->setString(""); // but don't paint it
$ui = & $this->_progress->getUI();
$ui->setProgressAttributes(array(
'background-color' => '#e0e0e0'
));
$ui->setStringAttributes(array(
'color' => '#996',
'background-color' => '#CCCC99'
));
$ui->setCellAttributes(array(
'active-color' => '#996'
));
$bar =& $this->_form->getElement('progress');
$bar->setText( $this->_progress->toHtml() );
$str =& $this->_form->getElement('status');
$str->setText('
');
$this->_progress->addListener($this);
}
function notify($event)
{
if (is_array($event)) {
$log = strtolower($event['log']);
$val = $event['value'];
switch (strtolower($log)) {
case 'incvalue':
case 'setvalue':
$this->_current = $this->getCurrent() + 16;
$s = $this->getMessage();
if (!is_null($s)) {
if ($this->_progress->isIndeterminate()) {
$this->_progress->setIndeterminate(false);
$this->_progress->setString(null); // display % string
$this->_progress->setValue(0);
}
if ($this->isDone()) {
$this->_progress->removeListener($this);
$this->_progress->setString(""); // hide % string
}
}
$this->_progress->display();
if ($this->_progress->getPercentComplete() == 1) {
if ($this->_progress->isIndeterminate()) {
$this->_progress->setValue(0);
}
} else {
$this->_progress->incValue();
}
break;
default:
}
}
}
function getCurrent()
{
return $this->_current;
}
function getMessage()
{
$c = $this->getCurrent();
$s = "completed $c out of 416";
if (function_exists('ob_get_clean')) {
$status = ob_get_clean(); // use for PHP 4.3+
} else {
$status = ob_get_contents(); // use for PHP 4.2+
ob_end_clean();
}
$status = '';
echo $status;
ob_start();
if ($c >= 240 ) {
return $s;
} else {
return null;
}
}
function isDone()
{
return ( ($this->_progress->getPercentComplete() == 1) &&
($this->_progress->isIndeterminate() == false) );
}
function isStarted()
{
$action = $this->_form->getSubmitValues();
if (isset($action['start'])) {
return true;
}
return false;
}
function run()
{
if ($this->isStarted()) {
$this->_progress->setIndeterminate(true);
$this->_progress->incValue();
} else {
$abort = $this->isCanceled();
}
}
}
$task = new Task();
?>
Indeterminate Mode Progress example
toHtml();
$task->run();
?>
<< Back examples TOC