home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / observer_complex.php < prev    next >
Encoding:
PHP Script  |  2004-03-24  |  3.8 KB  |  154 lines

  1. <?php 
  2. /**
  3.  * Observer ProgressBar example. Uses a custom observer class
  4.  * that handled progress of the second bar.
  5.  * 
  6.  * @version    $Id: observer_complex.php,v 1.1 2003/11/15 18:27:10 thesaur Exp $
  7.  * @author     Laurent Laville <pear@laurent-laville.org>
  8.  * @package    HTML_Progress
  9.  */
  10.  
  11. require_once ('HTML/Progress.php');
  12. require_once ('HTML/Progress/observer.php');
  13.  
  14. // 1. Defines ProgressBar observer
  15. class Bar1Observer extends HTML_Progress_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->setIncrement(10);
  49. $bar1->setIdent('PB1');
  50.  
  51. $bar2 = new HTML_Progress(HTML_PROGRESS_BAR_VERTICAL);
  52. $bar2->setIncrement(25);
  53. $bar2->setIdent('PB2');
  54. $bar2->setBorderPainted(true);
  55.  
  56. // 3. Creates and attach a listener
  57. $observer = new Bar1Observer();
  58.  
  59. $ok = $bar1->addListener($observer);
  60. if (!$ok) {
  61.     die ("Cannot add a valid listener to progress bar !");
  62. }
  63.  
  64. // 4. Changes look-and-feel of ProgressBar
  65. $ui1 =& $bar1->getUI();
  66. $ui1->setComment('Complex Observer ProgressBar example');
  67. $ui1->setTabOffset(1);
  68. $ui1->setProgressAttributes(array(
  69.     'background-color' => '#e0e0e0'
  70.         ));        
  71. $ui1->setStringAttributes(array(
  72.     'valign' => 'left',
  73.     'color'  => 'red',
  74.     'background-color' => 'lightblue'
  75.     ));
  76.  
  77. $ui2 =& $bar2->getUI();
  78. $ui2->setTabOffset(1);
  79. $ui2->setBorderAttributes(array(
  80.         'width' => 1,
  81.         'style' => 'solid',
  82.         'color' => 'navy'
  83.         ));
  84. $ui2->setCellAttributes(array(
  85.         'active-color' => '#3874B4',
  86.         'inactive-color' => '#EEEECC'
  87.         ));        
  88. $ui2->setStringAttributes(array(
  89.         'width'  => '100',
  90.     'align'  => 'center',
  91.     'valign' => 'right',
  92.     'color'  => 'yellow',
  93.     'background-color' => 'lightblue'
  94.     ));
  95. ?>
  96. <!DOCTYPE html
  97.     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  98.     "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  99.  
  100. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  101. <head>
  102. <title>Complex Observer ProgressBar example</title>
  103. <style type="text/css">
  104. <!--
  105. <?php
  106. echo $bar1->getStyle();
  107. echo $bar2->getStyle();
  108. ?>
  109. table.container {
  110.     background-color: lightblue;
  111.     border: 2;
  112.     border-color: navy;
  113.     border-style: dashed;
  114.     cell-spacing: 4;
  115.     cell-padding: 8;
  116.     width: 50%;
  117. }
  118. // -->
  119. </style>
  120. <script type="text/javascript">
  121. <!--
  122. <?php echo $bar1->getScript(); ?>
  123. //-->
  124. </script>
  125. </head>
  126. <body>
  127. <h1><?php echo basename(__FILE__); ?></h1>
  128.  
  129. <table class="container">
  130. <tr>
  131.     <td width="25%" align="center">
  132. <?php echo $bar1->toHTML(); ?>
  133.     </td>
  134.     <td width="25%" align="center">
  135. <?php echo $bar2->toHTML(); ?>
  136.     </td>
  137. </tr>
  138. </table>
  139.  
  140. <?php
  141. do {
  142.     $bar1->display();
  143.     if ($bar1->getPercentComplete() == 1) {
  144.         $bar1->setValue(0);  // the 1st progress bar has reached 100%, do a new loop
  145.     } else {
  146.         $bar1->incValue();   // updates 1st progress bar
  147.     }
  148. } while($bar2->getPercentComplete() < 1);
  149. ?>
  150.  
  151. <p><< <a href="index.html">Back examples TOC</a></p>
  152.  
  153. </body>
  154. </html>