PEAR Progress2 logo

HTML_Progress2 : The Definitive Guide

Indeterminate Mode usage

Figure 19.2. Indeterminate Mode usage

Indeterminate Mode usage

Goal of this example is to show how to display a progress bar in indeterminate mode then switch it to determinate mode after a while. We will consider that after 12 seconds elapsed we got awaiting (supposed) missing information.

Example 19.2. progress bar in indeterminate mode

      
<?php
require_once 'HTML/Progress2.php';

function myProgressHandler($pValue, &$pBar)
{
    static $c, $t;

    if (!isset($c)) {
        $c = time();
        $t = 0;
    }

    $pBar->sleep();

    if ($pBar->isIndeterminate()) {
        $elapse = time() - $c;

        if ($elapse > $t) {
            echo "myProgressHandler -> elapse time = $elapse s.<br />".PHP_EOL;
            $t++;
        }
        if ($elapse >= 12) {
            $pBar->setIndeterminate(false);
            $pBar->setValue(0);
            $pBar->setIncrement(5);
        }
    }
}

$pb = new HTML_Progress2();
$pb->setAnimSpeed(200);
$pb->setIncrement(10);
$pb->setProgressAttributes('background-color=#E0E0E0');
$pb->setCellAttributes('active-color=#996');
$pb->setLabelAttributes('pct1', array('color' => '#996'));
$pb->setIndeterminate(true);
$pb->setProgressHandler('myProgressHandler');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Half Indeterminate Progress2 example</title>
<style type="text/css">
<!--
body {
    background-color: #CCCC99;
    color: #996;
    font-family: Verdana, Arial;
}

<?php echo $pb->getStyle(); ?>
 -->
</style>
<?php echo $pb->getScript(false); ?>
</head>
<body>

<?php
$pb->display();
echo '<br /><br />';
$pb->run();
?>
<p><b>Process Ended !</b></p>

</body>
</html>
      
     

HTML_Progress2 : The Definitive Guide v 2.1.0 : August 12, 2006