home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / HTML / Progress / generator / process.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  8.2 KB  |  186 lines

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