PEAR Progress2 logo

HTML_Progress2 : The Definitive Guide

Monitoring usage

Figure 21.5. Monitoring usage

Monitoring usage

Goals of this example are to show how to include a progress bar into a quickform window, that can be stop at any time by user-end, and used this monitor with the indeterminate mode.

Example 21.5. progress bar into a quickform window

  1. <?php
  2. require_once 'HTML/Progress2/Monitor.php';
  3.  
  4. function myFunctionHandler($pValue, &$pb)
  5. {
  6.     global $pm;
  7.  
  8.     $pb->sleep();
  9.  
  10.     if (!$pb->isIndeterminate()) {
  11.         if (fmod($pValue,10) == 0) {
  12.             $pm->setCaption('myFunctionHandler -> progress value is = %value%',
  13.                 array('value' => $pValue)
  14.             );
  15.         }
  16.     } elseif ($pValue == 60) {
  17.         $pb->setIndeterminate(false);
  18.         $pb->setValue(0);
  19.     }
  20. }
  21.  
  22. $pm = new HTML_Progress2_Monitor('frmMonitor4', array(
  23.     'button' => array('style' => 'width:80px;'),
  24.     'autorun' => true
  25.     )
  26. );
  27.  
  28. $pb =& $pm->getProgressElement();
  29. $pb->setAnimSpeed(100);
  30. $pb->setCellCount(20);
  31. $pb->setProgressAttributes('background-color=#EEE');
  32. $pb->setCellAttributes('inactive-color=#FFF active-color=#444444');
  33. $pb->setLabelAttributes('pct1', 'color=navy');
  34. $pb->setLabelAttributes('monitorStatus', 'color=navy font-size=10');
  35. $pb->setIndeterminate(true);
  36. $pb->setProgressHandler('myFunctionHandler');
  37.  
  38. $pm->setProgressElement($pb);
  39. ?>
  40. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  41.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  42. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  43. <head>
  44. <title>Custom Progress2 Monitor </title>
  45. <style type="text/css">
  46. <!--
  47. body {
  48.     background-color: lightgrey;
  49.     font-family: Verdana, Arial;
  50. }
  51. <?php echo $pm->getStyle(); ?>
  52.  -->
  53. </style>
  54. <?php echo $pm->getScript(false); ?>
  55. </head>
  56. <body>
  57.  
  58. <?php
  59. $renderer =& HTML_QuickForm::defaultRenderer();
  60. $renderer->setFormTemplate('
  61. <form{attributes}>
  62.  <table width="450" border="0" cellpadding="3" cellspacing="2" bgcolor="#EEEEEE">
  63.  {content}
  64.  </table>
  65. </form>
  66. ');
  67. $renderer->setElementTemplate('
  68.  <tr>
  69.    <td valign="top" style="padding-left:15px;">
  70.    {element}
  71.    </td>
  72.  </tr>
  73. ');
  74. $renderer->setHeaderTemplate('
  75.  <tr>
  76.    <td style="background:#7B7B88;color:#ffc;" align="left" colspan="2">
  77.      <b>{header}</b>
  78.    </td>
  79.  </tr>
  80. ');
  81. $pm->accept($renderer);
  82.  
  83. echo $renderer->toHtml();
  84. $pm->run();
  85. ?>
  86.  
  87. </body>
  88. </html>
HTML_Progress2 : The Definitive Guide v 2.4.0 : April 20, 2007