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

Source for file embedded.php

Documentation is available at embedded.php

  1. <?php
  2. @include '../include_path.php';
  3. /**
  4.  * How to embedded HTML_Progress_Generator into existing html page
  5.  * and allows php/css source-code download.
  6.  *
  7.  * @version    $Id: embedded.php,v 1.1 2004/06/27 13:08:05 farell Exp $
  8.  * @author     Laurent Laville <pear@laurent-laville.org>
  9.  * @package    HTML_Progress
  10.  */
  11.  
  12. require_once 'HTML/Progress/generator.php';
  13.  
  14. /* 1. Choose between standard renderers (default, HTMLPage, ITDynamic).
  15.       If none is selected, then 'default' will be used.
  16.       It can be automatically loaded and added by the controller
  17.  */
  18. require_once 'HTML/Progress/generator/ITDynamic.php';
  19.  
  20. /* 2. 'ActionDisplay' is default classname that should exists 
  21.       to manage wizard/tabbed display. But you can also create
  22.       your own class under a new name. Then you've to give 
  23.       the new name to HTML_Progress_Generator.
  24.       For example:
  25.       
  26.       class MyDisplayHandler extends HTML_QuickForm_Action_Display
  27.       {
  28.            ...
  29.       }
  30.       If your 'MyDisplayHandler' class is not defined, then default
  31.       'ActionDisplay' ('HTML/Progress/generator/default.php')
  32.       will be used.
  33.  */
  34. class MyDisplayHandler extends HTML_QuickForm_Action_Display
  35. {
  36.     function _renderForm(&$page
  37.     {
  38.         $pageName $page->getAttribute('name');
  39.         $tabPreview array_slice ($page->controller->_tabs-21);
  40.  
  41.         $tpl =new HTML_Template_ITX('../templates');
  42.  
  43.         $tpl->loadTemplateFile('itdynamic_generator.html');
  44.  
  45.         // on preview tab, add progress bar javascript and stylesheet
  46.         if ($pageName == $tabPreview[0][0]{
  47.             $bar $page->controller->createProgressBar();
  48.  
  49.             $tpl->setVariable(array(
  50.                 'qf_style'  => $bar->getStyle(),
  51.                 'qf_script' => $bar->getScript()
  52.                 )
  53.             );
  54.  
  55.             $barElement =$page->getElement('progressBar');
  56.             $barElement->setText$bar->toHtml() );
  57.         }
  58.  
  59.         $renderer =new HTML_QuickForm_Renderer_ITDynamic($tpl);
  60.         $renderer->setElementBlock(array(
  61.             'buttons'     => 'qf_buttons'
  62.         ));
  63.  
  64.         $page->accept($renderer);
  65.  
  66.         $tpl->show();
  67.     }
  68. }
  69.  
  70. /* 3. 'ActionProcess' is default classname that should exists 
  71.       to save your progress bar php/css source-code. But you can also create
  72.       your own class under a new name. Then you've to give 
  73.       the new name to HTML_Progress_Generator.
  74.       For example:
  75.       
  76.       class MyProcessHandler extends HTML_QuickForm_Action
  77.       {
  78.            ...
  79.       }
  80.       If your 'MyProcessHandler' class is not defined, then default
  81.       'ActionProcess' ('HTML/Progress/generator/process.php') 
  82.       will be used.
  83.  */
  84. class MyProcessHandler extends HTML_QuickForm_Action
  85. {
  86.     function perform(&$page$actionName)
  87.     {
  88.         if ($actionName == 'cancel'{
  89.             echo '<h1>Progress Generator Demonstration is Over</h1>';
  90.             echo '<p>Hope you\'ve enjoyed. See you later!</p>';
  91.         else {
  92.             // Checks whether the pages of the controller are valid
  93.             $page->isFormBuilt(or $page->buildForm();
  94.             $page->controller->isValid();
  95.  
  96.             // what kind of source code is requested  
  97.             $code $page->exportValue('phpcss');
  98.             $bar $page->controller->createProgressBar();
  99.             
  100.             if (isset($code['C'])) {
  101.                 $this->exportOutput($bar->getStyle()'text/css');
  102.             }
  103.  
  104.             if (isset($code['P'])) {
  105.                 $structure $bar->toArray();
  106.  
  107.                 $lineEnd = OS_WINDOWS ? "\r\n" "\n";
  108.                 
  109.                 $strPHP  '<?php'.$lineEnd;
  110.                 $strPHP .= 'require_once \'HTML/Progress.php\';'.$lineEnd.$lineEnd;
  111.                 $strPHP .= '$progress = new HTML_Progress();'.$lineEnd;
  112.                 $strPHP .= '$progress->setIdent(\'PB1\');'.$lineEnd;
  113.                     
  114.                 if ($bar->isIndeterminate()) {
  115.                     $strPHP .= '$progress->setIndeterminate(true);'.$lineEnd;
  116.                 }
  117.                 if ($bar->isBorderPainted()) {
  118.                     $strPHP .= '$progress->setBorderPainted(true);'.$lineEnd;
  119.                 }
  120.                 if ($bar->isStringPainted()) {
  121.                     $strPHP .= '$progress->setStringPainted(true);'.$lineEnd;
  122.                 }
  123.                 if (is_null($structure['string'])) {
  124.                     $strPHP .= '$progress->setString(null);';
  125.                 else {
  126.                     $strPHP .= '$progress->setString('.$structure['string'].');';
  127.                 }
  128.                 $strPHP .= $lineEnd;
  129.                 if ($structure['animspeed'> 0{
  130.                     $strPHP .= '$progress->setAnimSpeed('.$structure['animspeed'].');'.$lineEnd;
  131.                 }
  132.                 if ($structure['dm']['minimum'!= 0{
  133.                     $strPHP .= '$progress->setMinimum('.$structure['dm']['minimum'].');'.$lineEnd;
  134.                 }
  135.                 if ($structure['dm']['maximum'!= 100{
  136.                     $strPHP .= '$progress->setMaximum('.$structure['dm']['maximum'].');'.$lineEnd;
  137.                 }
  138.                 if ($structure['dm']['increment'!= 1{
  139.                     $strPHP .= '$progress->setIncrement('.$structure['dm']['increment'].');'.$lineEnd;
  140.                 }
  141.                 $strPHP .= $lineEnd;
  142.                 $strPHP .= '$ui =& $progress->getUI();'.$lineEnd;
  143.  
  144.                 $orient ($structure['ui']['orientation'== '1''HTML_PROGRESS_BAR_HORIZONTAL' 'HTML_PROGRESS_BAR_VERTICAL';
  145.                 $strPHP .= '$ui->setOrientation('.$orient.');'.$lineEnd;
  146.                 $strPHP .= '$ui->setFillWay(\''.$structure['ui']['fillway'].'\');'.$lineEnd;
  147.  
  148.             /* Page 1: Progress attributes **************************************************/
  149.                 $strPHP .= $this->_attributesArray('$ui->setProgressAttributes('$structure['ui']['progress']);
  150.                 $strPHP .= $lineEnd;
  151.  
  152.             /* Page 2: Cell attributes ******************************************************/
  153.                 $strPHP .= '$ui->setCellCount('.$structure['ui']['cell']['count'].');'.$lineEnd;
  154.                 unset($structure['ui']['cell']['count']);  // to avoid dupplicate entry in attributes
  155.                 $strPHP .= $this->_attributesArray('$ui->setCellAttributes('$structure['ui']['cell']);
  156.                 $strPHP .= $lineEnd;
  157.  
  158.             /* Page 3: Border attributes ****************************************************/
  159.                 $strPHP .= $this->_attributesArray('$ui->setBorderAttributes('$structure['ui']['border']);
  160.                 $strPHP .= $lineEnd;
  161.  
  162.             /* Page 4: String attributes ****************************************************/
  163.                 $strPHP .= $this->_attributesArray('$ui->setStringAttributes('$structure['ui']['string']);
  164.                 $strPHP .= $lineEnd.$lineEnd;
  165.  
  166.                 $strPHP .= '// code below is only for run demo; its not ncecessary to create progress bar'.$lineEnd;
  167.                 $strPHP .= 'echo \'<style type="text/css">\'.$progress->getStyle().\'</style>\';'.$lineEnd;
  168.                 $strPHP .= 'echo \'<script type="text/javascript">\'.$progress->getScript().\'</script>\';'.$lineEnd;
  169.                 $strPHP .= 'echo $progress->toHtml();'.$lineEnd;
  170.                 $strPHP .= '$progress->run();'.$lineEnd;
  171.                 $strPHP .= '?>';
  172.                 $this->exportOutput($strPHP'text/php');
  173.             }
  174.  
  175.             // reset session data
  176.             $page->controller->container(true);
  177.         }
  178.     }
  179.  
  180.     function exportOutput($str$mime 'text/plain'$charset 'iso-8859-1')
  181.     {
  182.         if (!headers_sent()) {
  183.             header("Expires: Tue, 1 Jan 1980 12:00:00 GMT");
  184.             header("Last-Modified: " gmdate("D, d M Y H:i:s"" GMT");
  185.             header("Cache-Control: no-cache");
  186.             header("Pragma: no-cache");
  187.             header("Content-Type: $mime; charset=$charset");
  188.         }
  189.         print $str;
  190.     }
  191.  
  192.     function _attributesArray($str$attributes)
  193.     {
  194.         $strPHP $str 'array(';
  195.         foreach ($attributes as $attr => $val{
  196.             if (is_integer($val)) {
  197.                 $strPHP .= "'$attr'=>$val";
  198.             elseif (is_bool($val)) {
  199.                 $strPHP .= "'$attr'=>".($val?'true':'false').', ';
  200.             else {
  201.                 $strPHP .= "'$attr'=>'$val', ";
  202.             }   
  203.         }
  204.         $strPHP ereg_replace(', $'''$strPHP);
  205.         $strPHP .= '));';
  206.         return $strPHP;
  207.     }
  208. }
  209.  
  210.  
  211.  
  212. $tabbed = new HTML_Progress_Generator('PBwizard'array(
  213.                                       'display' => 'MyDisplayHandler',
  214.                                       'process' => 'MyProcessHandler'
  215.                                       ));
  216.  
  217. $tabbed->run();
  218. ?>

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