<?php require_once 'HTML/Progress.php'; $bar = new HTML_Progress(); $bar->setIncrement(5); $bar->incValue(); printf('value after 1st update = %d <br/>', $bar->getValue()); $dm =& $bar->getDM(); $dm->incValue(); printf('value after 2nd update = %d <br/>', $dm->getValue());
do { $bar->display(); $bar->sleep(); // for purpose of demo only if ($bar->getPercentComplete() == 1) { $loop++; if ($bar->isIndeterminate()) { $bar->setValue(0); } else { break; // progress bar reached 100% in determinate mode } } else { $bar->incValue(); } /** rule to decide when to switch back to determinate mode * - after two full loops and half one */ if ($bar->isIndeterminate()) { if ($loop == 2 && $bar->getValue() == 50) { $bar->setIndeterminate(false); $bar->setString(null); // display % string $bar->setValue(0); } } } while (1); ?> </body> </html>
<?php require_once 'HTML/Progress.php'; $bar = new HTML_Progress(); $bar->setValue(45); printf('direct way: value = %d <br/>', $bar->getValue()); $dm =& $bar->getDM(); $dm->setValue(45); printf('another way: value = %d <br/>', $dm->getValue());
</style> <script type="text/javascript"> <!-- <?php echo $bar->getScript(); ?> //--> </script> </head> <body> <?php echo $bar->toHtml(); $pkg = array('PEAR', 'Archive_Tar', 'Config', 'HTML_QuickForm', 'HTML_CSS', 'HTML_Page', 'HTML_Template_Sigma', 'Log', 'MDB', 'PHPUnit'); do { $val = $bar->getValue(); $i = floor($val / 10); if ($val == 100) { $msg = ''; } else { $msg = " installing package ({$val} %) ... : "; $msg .= $pkg[$i]; } $bar->setString($msg); $bar->display(); if ($bar->getPercentComplete() == 1) { break; // the progress bar has reached 100% } $bar->sleep(); // for purpose of demo only