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

  1. <?php
  2. // +----------------------------------------------------------------------+
  3. // | PHP Version 4                                                        |
  4. // +----------------------------------------------------------------------+
  5. // | Copyright (c) 1997-2004 The PHP Group                                |
  6. // +----------------------------------------------------------------------+
  7. // | This source file is subject to version 3.0 of the PHP license,       |
  8. // | that is bundled with this package in the file LICENSE, and is        |
  9. // | available at through the world-wide-web at                           |
  10. // | http://www.php.net/license/3_0.txt.                                  |
  11. // | If you did not receive a copy of the PHP license and are unable to   |
  12. // | obtain it through the world-wide-web, please send a note to          |
  13. // | license@php.net so we can mail you a copy immediately.               |
  14. // +----------------------------------------------------------------------+
  15. // | Author: Laurent Laville <pear@laurent-laville.org>                   |
  16. // +----------------------------------------------------------------------+
  17. //
  18. // $Id: process.php,v 1.1 2004/02/13 15:38:08 farell Exp $
  19.  
  20. /**
  21.  * The ActionProcess class provides final step of ProgressBar creation.
  22.  * Manage php/css source-code save and cancel action.
  23.  *
  24.  * @version    1.1
  25.  * @author     Laurent Laville <pear@laurent-laville.org>
  26.  * @access     public
  27.  * @category   HTML
  28.  * @package    HTML_Progress
  29.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  30.  */
  31.  
  32. class ActionProcess extends HTML_QuickForm_Action
  33. {
  34.     function perform(&$page, $actionName)
  35.     {
  36.         if ($actionName == 'cancel') {
  37.             echo '<h1>Progress Generator Task was canceled</h1>';
  38.             echo '<p>None (PHP/CSS) source codes are available.</p>';
  39.         } else {
  40.             // Checks whether the pages of the controller are valid
  41.             $page->isFormBuilt() or $page->buildForm();
  42.             $page->controller->isValid();
  43.  
  44.             // what kind of source code is requested  
  45.             $code = $page->exportValue('phpcss');
  46.             $bar = $page->controller->createProgressBar();
  47.             
  48.             if (isset($code['C'])) {
  49.                 $this->exportOutput($bar->getStyle());
  50.             }
  51.  
  52.             if (isset($code['P'])) {
  53.                 $structure = $bar->toArray();
  54.  
  55.                 $lineEnd = OS_WINDOWS ? "\r\n" : "\n";
  56.                 
  57.                 $strPHP  = '<?php'.$lineEnd;
  58.                 $strPHP .= 'require_once \'HTML/Progress.php\';'.$lineEnd.$lineEnd;
  59.                 $strPHP .= '$progress = new HTML_Progress();'.$lineEnd;
  60.                 $strPHP .= '$progress->setIdent(\'PB1\');'.$lineEnd;
  61.                     
  62.                 if ($bar->isIndeterminate()) {
  63.                     $strPHP .= '$progress->setIndeterminate(true);'.$lineEnd;
  64.                 }
  65.                 if ($bar->isBorderPainted()) {
  66.                     $strPHP .= '$progress->setBorderPainted(true);'.$lineEnd;
  67.                 }
  68.                 if ($bar->isStringPainted()) {
  69.                     $strPHP .= '$progress->setStringPainted(true);'.$lineEnd;
  70.                 }
  71.                 if (is_null($structure['string'])) {
  72.                     $strPHP .= '$progress->setString(null);';
  73.                 } else {
  74.                     $strPHP .= '$progress->setString('.$structure['string'].');';
  75.                 }
  76.                 $strPHP .= $lineEnd;
  77.                 if ($structure['animspeed'] > 0) {
  78.                     $strPHP .= '$progress->setAnimSpeed('.$structure['animspeed'].');'.$lineEnd;
  79.                 }
  80.                 if ($structure['dm']['minimum'] != 0) {
  81.                     $strPHP .= '$progress->setMinimum('.$structure['dm']['minimum'].');'.$lineEnd;
  82.                 }
  83.                 if ($structure['dm']['maximum'] != 100) {
  84.                     $strPHP .= '$progress->setMaximum('.$structure['dm']['maximum'].');'.$lineEnd;
  85.                 }
  86.                 if ($structure['dm']['increment'] != 1) {
  87.                     $strPHP .= '$progress->setIncrement('.$structure['dm']['increment'].');'.$lineEnd;
  88.                 }
  89.                 $strPHP .= $lineEnd;
  90.                 $strPHP .= '$ui =& $progress->getUI();'.$lineEnd;
  91.  
  92.                 $orient = ($structure['ui']['orientation'] == '1') ? 'HTML_PROGRESS_BAR_HORIZONTAL' : 'HTML_PROGRESS_BAR_VERTICAL';
  93.                 $strPHP .= '$ui->setOrientation('.$orient.');'.$lineEnd;
  94.                 $strPHP .= '$ui->setFillWay(\''.$structure['ui']['fillway'].'\');'.$lineEnd;
  95.  
  96.             /* Page 1: Progress attributes **************************************************/
  97.                 $strPHP .= $this->_attributesArray('$ui->setProgressAttributes(', $structure['ui']['progress']);
  98.                 $strPHP .= $lineEnd;
  99.  
  100.             /* Page 2: Cell attributes ******************************************************/
  101.                 $strPHP .= '$ui->setCellCount('.$structure['ui']['cell']['count'].');'.$lineEnd;
  102.                 unset($structure['ui']['cell']['count']);  // to avoid dupplicate entry in attributes
  103.                 $strPHP .= $this->_attributesArray('$ui->setCellAttributes(', $structure['ui']['cell']);
  104.                 $strPHP .= $lineEnd;
  105.  
  106.             /* Page 3: Border attributes ****************************************************/
  107.                 $strPHP .= $this->_attributesArray('$ui->setBorderAttributes(', $structure['ui']['border']);
  108.                 $strPHP .= $lineEnd;
  109.  
  110.             /* Page 4: String attributes ****************************************************/
  111.                 $strPHP .= $this->_attributesArray('$ui->setStringAttributes(', $structure['ui']['string']);
  112.                 $strPHP .= $lineEnd.$lineEnd;
  113.  
  114.                 $strPHP .= '// code below is only for run demo; its not ncecessary to create progress bar'.$lineEnd;
  115.                 $strPHP .= 'echo \'<style type="text/css">\'.$progress->getStyle().\'</style>\';'.$lineEnd;
  116.                 $strPHP .= 'echo \'<script type="text/javascript">\'.$progress->getScript().\'</script>\';'.$lineEnd;
  117.                 $strPHP .= 'echo $progress->toHtml();'.$lineEnd;
  118.                 $strPHP .= 'do {'.$lineEnd;
  119.                 $strPHP .= '    $progress->display();'.$lineEnd;
  120.                 $strPHP .= '    if ($progress->getPercentComplete() == 1) {'.$lineEnd;
  121.                 $strPHP .= '        break;'.$lineEnd;
  122.                 $strPHP .= '    }'.$lineEnd;
  123.                 $strPHP .= '    $progress->incValue();'.$lineEnd;
  124.                 $strPHP .= '} while(1);'.$lineEnd;
  125.  
  126.                 $strPHP .= '?>';
  127.                 $this->exportOutput($strPHP);
  128.             }
  129.  
  130.             // reset session data
  131.             $page->controller->container(true);
  132.         }
  133.     }
  134.  
  135.     function exportOutput($str, $mime = 'text/plain', $charset = 'iso-8859-1')
  136.     {
  137.         if (!headers_sent()) {
  138.             header("Expires: Tue, 1 Jan 1980 12:00:00 GMT");
  139.             header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  140.             header("Cache-Control: no-cache");
  141.             header("Pragma: no-cache");
  142.             header("Content-Type: $mime; charset=$charset");
  143.         }
  144.         print $str;
  145.     }
  146.  
  147.     function _attributesArray($str, $attributes)
  148.     {
  149.         $strPHP = $str . 'array(';
  150.         foreach ($attributes as $attr => $val) {
  151.             if (is_integer($val)) {
  152.                 $strPHP .= "'$attr'=>$val, ";
  153.             } elseif (is_bool($val)) {
  154.                 $strPHP .= "'$attr'=>".($val?'true':'false').', ';
  155.             } else {
  156.                 $strPHP .= "'$attr'=>'$val', ";
  157.             }   
  158.         }
  159.         $strPHP = ereg_replace(', $', '', $strPHP);
  160.         $strPHP .= '));';
  161.         return $strPHP;
  162.     }
  163. }
  164. ?>