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 / Progress2 / Generator / Default.php next >
Encoding:
PHP Script  |  2008-07-02  |  7.8 KB  |  236 lines

  1. <?php
  2. /**
  3.  * Copyright (c) 2005-2008, Laurent Laville <pear@laurent-laville.org>
  4.  *
  5.  * All rights reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  *     * Redistributions of source code must retain the above copyright
  12.  *       notice, this list of conditions and the following disclaimer.
  13.  *     * Redistributions in binary form must reproduce the above copyright
  14.  *       notice, this list of conditions and the following disclaimer in the
  15.  *       documentation and/or other materials provided with the distribution.
  16.  *     * Neither the name of the authors nor the names of its contributors
  17.  *       may be used to endorse or promote products derived from this software
  18.  *       without specific prior written permission.
  19.  *
  20.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23.  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
  24.  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  25.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  26.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  27.  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  28.  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  29.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  30.  * POSSIBILITY OF SUCH DAMAGE.
  31.  *
  32.  * PHP versions 4 and 5
  33.  *
  34.  * @category  HTML
  35.  * @package   HTML_Progress2
  36.  * @author    Laurent Laville <pear@laurent-laville.org>
  37.  * @copyright 2005-2008 Laurent Laville
  38.  * @license   http://www.opensource.org/licenses/bsd-license.php  New BSD License
  39.  * @version   CVS: $Id: Default.php,v 1.10 2008/03/20 21:27:55 farell Exp $
  40.  * @link      http://pear.php.net/package/HTML_Progress2
  41.  * @since     File available since Release 2.0.0RC1
  42.  */
  43.  
  44.  
  45. /**
  46.  * The ActionDisplay class provides the default form rendering.
  47.  *
  48.  * @category  HTML
  49.  * @package   HTML_Progress2
  50.  * @author    Laurent Laville <pear@laurent-laville.org>
  51.  * @copyright 2005-2008 Laurent Laville
  52.  * @license   http://www.opensource.org/licenses/bsd-license.php  New BSD License
  53.  * @version   Release: 2.4.0
  54.  * @link      http://pear.php.net/package/HTML_Progress2
  55.  * @since     Class available since Release 2.0.0RC1
  56.  */
  57.  
  58. class ActionDisplay extends HTML_QuickForm_Action_Display
  59. {
  60.     /**
  61.      * Style sheet for the custom layout
  62.      *
  63.      * @var    string
  64.      * @access public
  65.      * @since  2.1.0
  66.      */
  67.     var $css;
  68.  
  69.     /**
  70.      * class constructor
  71.      *
  72.      * @param string $css custom stylesheet to apply, or default if not set
  73.      *
  74.      * @access public
  75.      * @since  version 2.1.0 (2006-08-12)
  76.      */
  77.     function ActionDisplay($css = null)
  78.     {
  79.         // when no user-styles defined, used the default values
  80.         $this->setStyleSheet($css);
  81.     }
  82.  
  83.     /**
  84.      * Outputs the form.
  85.      *
  86.      * @param object &$page the page being processed
  87.      *
  88.      * @return void
  89.      * @access public
  90.      * @since  version 2.0.0RC1 (2005-06-23)
  91.      */
  92.     function _renderForm(&$page)
  93.     {
  94.         $formTemplate = "\n<form{attributes}>"
  95.                       . "\n<table class=\"maintable\">"
  96.                       . "\n<caption>HTML_Progress2 Generator</caption>"
  97.                       . "\n{content}"
  98.                       . "\n</table>"
  99.                       . "\n</form>";
  100.  
  101.         $headerTemplate = "\n<tr>"
  102.                         . "\n\t<th colspan=\"2\">"
  103.                         . "\n\t\t{header}"
  104.                         . "\n\t</th>"
  105.                         . "\n</tr>";
  106.  
  107.         $elementTemplate = "\n<tr valign=\"top\">"
  108.                          . "\n\t<td class=\"qfLabel\"> {label}</td>"
  109.                          . "\n\t<td class=\"qfElement\">"
  110.                          . "\n{element}"
  111.                          . "<!-- BEGIN label_2 --> "
  112.                          . "<span class=\"qfLabel2\">{label_2}</span>"
  113.                          . "<!-- END label_2 -->"
  114.                          . "\n\t</td>"
  115.                          . "\n</tr>";
  116.  
  117.         $groupTemplate = "\n\t\t<table class=\"group\">"
  118.                        . "\n\t\t<tr>"
  119.                        . "\n\t\t\t{content}"
  120.                        . "\n\t\t</tr>"
  121.                        . "\n\t\t</table>";
  122.  
  123.         $groupElementTemplate = "<td>{element}"
  124.                               . "<!-- BEGIN label --><br/>"
  125.                               . "<span class=\"qfLabel\">{label}</span>"
  126.                               . "<!-- END label -->"
  127.                               . "</td>";
  128.  
  129.         $renderer =& $page->defaultRenderer();
  130.  
  131.         $renderer->setFormTemplate($formTemplate);
  132.         $renderer->setHeaderTemplate($headerTemplate);
  133.         $renderer->setElementTemplate($elementTemplate);
  134.  
  135.         $groups
  136.             = array('progresssize',                                   // on page 1
  137.                     'cellvalue','cellsize', 'cellcolor', 'cellfont',  // on page 2
  138.                     'borderstyle',                                    // on page 3
  139.                     'stringsize','stringfont'                         // on page 4
  140.                     );
  141.  
  142.         foreach ($groups as $grp) {
  143.             $renderer->setGroupTemplate($groupTemplate, $grp);
  144.             $renderer->setGroupElementTemplate($groupElementTemplate, $grp);
  145.         }
  146.  
  147.         $styles = $this->getStyleSheet();
  148.         $js     = '';
  149.  
  150.         // on preview tab, add progress bar javascript and stylesheet
  151.         if ($page->getAttribute('id') == 'Preview') {
  152.             $pb = $page->controller->createProgressBar();
  153.             $pb->setTab('    ');
  154.  
  155.             $styles .= $pb->getStyle();
  156.             $js      = $pb->getScript();
  157.  
  158.             $pbElement =& $page->getElement('progressBar');
  159.             $pbElement->setText($pb->toHtml() . '<br /><br />');
  160.         }
  161.         $page->accept($renderer);
  162.  
  163.         $body = $renderer->toHtml();
  164.  
  165.         $html = <<<HTML
  166. <!DOCTYPE HTML
  167.     PUBLIC "-//W3C//DTD HTML 4.01//EN"
  168.     "http://www.w3.org/TR/html4/strict.dtd">
  169. <html>
  170. <head>
  171. <title>HTML_Progress2 Generator</title>
  172. <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  173. <style type="text/css">
  174. <!--
  175. $styles
  176.  -->
  177. </style>
  178. <script type="text/javascript">
  179. //<![CDATA[
  180. $js
  181. //]]>
  182. </script>
  183. </head>
  184. <body>
  185. $body
  186. </body>
  187. </html>
  188. HTML;
  189.         echo $html;
  190.     }
  191.  
  192.     /**
  193.      * Returns the custom style sheet to use for layout
  194.      *
  195.      * @param bool $content (optional) Either return css filename or string contents
  196.      *
  197.      * @return string
  198.      * @access public
  199.      * @since  version 2.1.0 (2006-08-12)
  200.      */
  201.     function getStyleSheet($content = true)
  202.     {
  203.         if ($content) {
  204.             $styles = file_get_contents($this->css);
  205.         } else {
  206.             $styles = $this->css;
  207.         }
  208.         return $styles;
  209.     }
  210.  
  211.     /**
  212.      * Set the custom style sheet to use your own styles
  213.      *
  214.      * @param string $css (optional) File to read user-defined styles from
  215.      *
  216.      * @return bool    true if custom styles, false if default styles applied
  217.      * @access public
  218.      * @since  version 2.1.0 (2006-08-12)
  219.      */
  220.     function setStyleSheet($css = null)
  221.     {
  222.         // default stylesheet is into package data directory
  223.         if (!isset($css)) {
  224.             $this->css = 'C:\php5\pear\data' . DIRECTORY_SEPARATOR
  225.                  . 'HTML_Progress2' . DIRECTORY_SEPARATOR
  226.                  . 'default.css';
  227.         }
  228.  
  229.         $res = isset($css) && file_exists($css);
  230.         if ($res) {
  231.             $this->css = $css;
  232.         }
  233.         return $res;
  234.     }
  235. }
  236. ?>