HTML_Progress
[ class tree: HTML_Progress ] [ index: HTML_Progress ] [ all elements ]

Source for file complex.php

Documentation is available at complex.php

  1. <?php 
  2. @include '../include_path.php';
  3. /**
  4.  * Observer ProgressBar example. Uses a custom observer class
  5.  * that handled progress of the second bar.
  6.  * 
  7.  * @version    $Id: complex.php,v 1.1 2004/06/27 13:08:28 farell Exp $
  8.  * @author     Laurent Laville <pear@laurent-laville.org>
  9.  * @package    HTML_Progress
  10.  */
  11.  
  12. require_once 'HTML/Progress.php';
  13. require_once 'HTML/Progress/observer.php';
  14.  
  15. // 1. Defines ProgressBar observer
  16. {
  17.     function Bar1Observer()
  18.     {
  19.         $this->HTML_Progress_Observer();
  20.     }
  21.  
  22.     function notify($event)
  23.     {
  24.         global $bar2;
  25.         
  26.         if (is_array($event)) {
  27.             $log = isset($event['log']$event['log'"undefined event id.";
  28.             $val = isset($event['value']$event['value'"unknown value";
  29.  
  30.             switch (strtolower($log)) {
  31.              case 'incvalue':
  32.                  // if you want to do special on each step of progress bar1; it's here !!!
  33.                  break;
  34.              case 'setvalue':
  35.                  if ($val == 0{
  36.                      // updates $bar2 because $bar1 has completed a full loop
  37.                      $bar2->incValue();
  38.                      $bar2->display();
  39.                  }
  40.              default:
  41.             }
  42.         }
  43.     }
  44. }
  45.  
  46. // 2. Creates ProgressBar
  47. $bar1 = new HTML_Progress(HTML_PROGRESS_BAR_VERTICAL);
  48. $bar1->setAnimSpeed(50);
  49. $bar1->setIncrement(10);
  50. $bar1->setIdent('PB1');
  51.  
  52. $bar2 = new HTML_Progress(HTML_PROGRESS_BAR_VERTICAL);
  53. $bar2->setAnimSpeed(50);
  54. $bar2->setIncrement(25);
  55. $bar2->setIdent('PB2');
  56. $bar2->setBorderPainted(true);
  57.  
  58. // 3. Creates and attach a listener
  59. $observer = new Bar1Observer();
  60.  
  61. $ok $bar1->addListener($observer);
  62. if (!$ok{
  63.     die ("Cannot add a valid listener to progress bar !");
  64. }
  65.  
  66. // 4. Changes look-and-feel of ProgressBar
  67. $ui1 =$bar1->getUI();
  68. $ui1->setComment('Complex Observer ProgressBar example');
  69. $ui1->setTabOffset(1);
  70. $ui1->setProgressAttributes(array(
  71.         'background-color' => '#e0e0e0'
  72.         ));        
  73. $ui1->setStringAttributes(array(
  74.         'valign' => 'left',
  75.         'color'  => 'red',
  76.         'background-color' => 'lightblue'
  77.         ));
  78.  
  79. $ui2 =$bar2->getUI();
  80. $ui2->setTabOffset(1);
  81. $ui2->setBorderAttributes(array(
  82.         'width' => 1,
  83.         'style' => 'solid',
  84.         'color' => 'navy'
  85.         ));
  86. $ui2->setCellAttributes(array(
  87.         'active-color' => '#3874B4',
  88.         'inactive-color' => '#EEEECC'
  89.         ));        
  90. $ui2->setStringAttributes(array(
  91.         'width'  => '100',
  92.         'align'  => 'center',
  93.         'valign' => 'right',
  94.         'color'  => 'yellow',
  95.         'background-color' => 'lightblue'
  96.         ));
  97. ?>
  98. <!DOCTYPE html
  99.     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  100.     "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  101. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  102. <head>
  103. <title>Complex Observer ProgressBar example</title>
  104. <style type="text/css">
  105. <!--
  106. <?php
  107. echo $bar1->getStyle();
  108. echo $bar2->getStyle();
  109. ?>
  110. table.container {
  111.         background-color: lightblue;
  112.         border: 2;
  113.         border-color: navy;
  114.         border-style: dashed;
  115.         cell-spacing: 4;
  116.         cell-padding: 8;
  117.         width: 50%;
  118. }
  119. // -->
  120. </style>
  121. <script type="text/javascript">
  122. <!--
  123. <?php echo $bar1->getScript()?>
  124. //-->
  125. </script>
  126. </head>
  127. <body>
  128. <h1><?php echo basename(__FILE__)?></h1>
  129.  
  130. <table class="container">
  131. <tr>
  132.     <td width="25%" align="center">
  133. <?php echo $bar1->toHTML()?>
  134.     </td>
  135.     <td width="25%" align="center">
  136. <?php echo $bar2->toHTML()?>
  137.     </td>
  138. </tr>
  139. </table>
  140.  
  141. <?php
  142. do {
  143.     $bar1->display();
  144.     $bar1->process();    // warning: don't forget it (even for a demo)
  145.     if ($bar1->getPercentComplete(== 1{
  146.         $bar1->setValue(0);  // the 1st progress bar has reached 100%, do a new loop
  147.     else {
  148.         $bar1->incValue();   // updates 1st progress bar
  149.     }
  150. while($bar2->getPercentComplete(< 1);
  151. ?>
  152.  
  153. <p>&lt;&lt; <a href="../index.html">Back examples TOC</a></p>
  154.  
  155. </body>
  156. </html>

Documentation generated on Mon, 11 Mar 2019 13:52:36 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.