PEAR Progress2 logo

HTML_Progress2 : The Definitive Guide

Indeterminate Mode usage

Figure 21.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 21.2. progress bar in indeterminate mode

  1. <?php
  2. require_once 'HTML/Progress2.php';
  3.  
  4. function myProgressHandler($pValue, &$pBar)
  5. {
  6.     static $c, $t;
  7.  
  8.     if (!isset($c)) {
  9.         $c = time();
  10.         $t = 0;
  11.     }
  12.  
  13.     $pBar->sleep();
  14.  
  15.     if ($pBar->isIndeterminate()) {
  16.         $elapse = time() - $c;
  17.  
  18.         if ($elapse > $t) {
  19.             echo "myProgressHandler -> elapse time = $elapse s.<br />".PHP_EOL;
  20.             $t++;
  21.         }
  22.         if ($elapse >= 12) {
  23.             $pBar->setIndeterminate(false);
  24.             $pBar->setValue(0);
  25.             $pBar->setIncrement(5);
  26.         }
  27.     }
  28. }
  29.  
  30. $pb = new HTML_Progress2();
  31. $pb->setAnimSpeed(200);
  32. $pb->setIncrement(10);
  33. $pb->setProgressAttributes('background-color=#E0E0E0');
  34. $pb->setCellAttributes('active-color=#996');
  35. $pb->setLabelAttributes('pct1', array('color' => '#996'));
  36. $pb->setIndeterminate(true);
  37. $pb->setProgressHandler('myProgressHandler');
  38. ?>
  39. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  40.     "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  41. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  42. <head>
  43. <title>Half Indeterminate Progress2 example</title>
  44. <style type="text/css">
  45. <!--
  46. body {
  47.     background-color: #CCCC99;
  48.     color: #996;
  49.     font-family: Verdana, Arial;
  50. }
  51.  
  52. <?php echo $pb->getStyle(); ?>
  53.  -->
  54. </style>
  55. <?php echo $pb->getScript(false); ?>
  56. </head>
  57. <body>
  58.  
  59. <?php
  60. $pb->display();
  61. echo '<br /><br />';
  62. $pb->run();
  63. ?>
  64. <p><b>Process Ended !</b></p>
  65.  
  66. </body>
  67. </html>
HTML_Progress2 : The Definitive Guide v 2.4.0 : April 20, 2007