PageRenderTime 49ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/php/HTML/tutorials/HTML_Progress/examples/observer_complex.php

https://bitbucket.org/adarshj/convenient_website
PHP | 139 lines | 123 code | 14 blank | 2 comment | 8 complexity | dfd37464b42ea7de7c12733c5340300f MD5 | raw file
Possible License(s): Apache-2.0, MPL-2.0-no-copyleft-exception, LGPL-2.1, BSD-2-Clause, GPL-2.0, LGPL-3.0
  1. <?php
  2. require_once 'HTML/Progress.php';
  3. require_once 'HTML/Progress/observer.php';
  4. class Bar1Observer extends HTML_Progress_Observer
  5. {
  6. function Bar1Observer()
  7. {
  8. $this->HTML_Progress_Observer();
  9. }
  10. function notify($event)
  11. {
  12. global $bar1, $bar2;
  13. if (is_array($event)) {
  14. $log = $event['log'];
  15. $val = $event['value'];
  16. switch (strtolower($log)) {
  17. case 'incvalue':
  18. $bar1->sleep(); // process to do on PB1
  19. break;
  20. case 'setvalue':
  21. if ($val == 0) {
  22. $bar2->incValue();
  23. $bar2->display();
  24. }
  25. default:
  26. }
  27. }
  28. }
  29. }
  30. $bar1 = new HTML_Progress(HTML_PROGRESS_BAR_VERTICAL);
  31. $bar1->setAnimSpeed(100);
  32. $bar1->setIncrement(10);
  33. $bar1->setIdent('PB1');
  34. $bar2 = new HTML_Progress(HTML_PROGRESS_BAR_VERTICAL);
  35. $bar2->setAnimSpeed(100);
  36. $bar2->setIncrement(25);
  37. $bar2->setIdent('PB2');
  38. $bar2->setBorderPainted(true);
  39. $observer = new Bar1Observer();
  40. $ok = $bar1->addListener($observer);
  41. if (!$ok) {
  42. die ("Cannot add a valid listener to progress bar !");
  43. }
  44. $ui1 =& $bar1->getUI();
  45. $ui1->setComment('Complex Observer example');
  46. $ui1->setTabOffset(1);
  47. $ui1->setProgressAttributes(array(
  48. 'background-color' => '#e0e0e0'
  49. ));
  50. $ui1->setStringAttributes(array(
  51. 'valign' => 'left',
  52. 'color' => 'red',
  53. 'background-color' => 'lightblue'
  54. ));
  55. $ui2 =& $bar2->getUI();
  56. $ui2->setTabOffset(1);
  57. $ui2->setBorderAttributes(array(
  58. 'width' => 1,
  59. 'style' => 'solid',
  60. 'color' => 'navy'
  61. ));
  62. $ui2->setCellAttributes(array(
  63. 'active-color' => '#3874B4',
  64. 'inactive-color' => '#EEEECC'
  65. ));
  66. $ui2->setStringAttributes(array(
  67. 'width' => '100',
  68. 'align' => 'center',
  69. 'valign' => 'right',
  70. 'color' => 'yellow',
  71. 'background-color' => 'lightblue'
  72. ));
  73. ?>
  74. <!DOCTYPE html
  75. PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  76. "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  77. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  78. <head>
  79. <title>Complex Observer </title>
  80. <style type="text/css">
  81. <!--
  82. <?php
  83. echo $bar1->getStyle();
  84. echo $bar2->getStyle();
  85. ?>
  86. table.container {
  87. background-color: lightblue;
  88. border: 2;
  89. border-color: navy;
  90. border-style: dashed;
  91. cell-spacing: 4;
  92. cell-padding: 8;
  93. width: 50%;
  94. }
  95. // -->
  96. </style>
  97. <script type="text/javascript">
  98. <!--
  99. <?php echo $bar1->getScript(); ?>
  100. //-->
  101. </script>
  102. </head>
  103. <body>
  104. <table class="container">
  105. <tr>
  106. <td width="25%" align="center">
  107. <?php echo $bar1->toHTML(); ?>
  108. </td>
  109. <td width="25%" align="center">
  110. <?php echo $bar2->toHTML(); ?>
  111. </td>
  112. </tr>
  113. </table>
  114. <?php
  115. do {
  116. $bar1->display();
  117. if ($bar1->getPercentComplete() == 1) {
  118. $bar1->setValue(0);
  119. } else {
  120. $bar1->incValue();
  121. }
  122. } while($bar2->getPercentComplete() < 1);
  123. ?>
  124. </body>
  125. </html>