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 / HTMLPage2.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  7.8 KB  |  224 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: HTMLPage2.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. require_once 'HTML/Page2.php';
  45.  
  46. /**
  47.  * The ActionDisplay class provides a HTML_Page2 form rendering.
  48.  *
  49.  * @category  HTML
  50.  * @package   HTML_Progress2
  51.  * @author    Laurent Laville <pear@laurent-laville.org>
  52.  * @copyright 2005-2008 Laurent Laville
  53.  * @license   http://www.opensource.org/licenses/bsd-license.php  New BSD License
  54.  * @version   Release: 2.4.0
  55.  * @link      http://pear.php.net/package/HTML_Progress2
  56.  * @since     Class available since Release 2.0.0RC1
  57.  */
  58.  
  59. class ActionDisplay extends HTML_QuickForm_Action_Display
  60. {
  61.     /**
  62.      * Style sheet for the custom layout
  63.      *
  64.      * @var    string
  65.      * @access public
  66.      * @since  2.1.0
  67.      */
  68.     var $css;
  69.  
  70.     /**
  71.      * class constructor
  72.      *
  73.      * @param string $css custom stylesheet to apply, or default if not set
  74.      *
  75.      * @access public
  76.      * @since  version 2.1.0 (2006-08-12)
  77.      */
  78.     function ActionDisplay($css = null)
  79.     {
  80.         // when no user-styles defined, used the default values
  81.         $this->setStyleSheet($css);
  82.     }
  83.  
  84.     /**
  85.      * Outputs the form.
  86.      *
  87.      * @param object &$page the page being processed
  88.      *
  89.      * @return void
  90.      * @access public
  91.      * @since  version 2.0.0RC1 (2005-06-23)
  92.      */
  93.     function _renderForm(&$page)
  94.     {
  95.         $tab = '  ';
  96.  
  97.         $p = new HTML_Page2(array(
  98.                  'lineend'  => PHP_EOL,
  99.                  'tab'      => $tab,
  100.                  'doctype'  => 'XHTML 1.0 Strict',
  101.                  'language' => 'en',
  102.                  'cache'    => 'false'
  103.         ));
  104.         $p->disableXmlProlog();
  105.         $p->setTitle('PEAR::HTML_Progress2 - Generator');
  106.         $p->setMetaData('author', 'Laurent Laville');
  107.  
  108.         $formTemplate = "\n<form{attributes}>"
  109.                       . "\n<table class=\"maintable\">"
  110.                       . "\n<caption>HTML_Progress2 Generator</caption>"
  111.                       . "\n{content}"
  112.                       . "\n</table>"
  113.                       . "\n</form>";
  114.  
  115.         $headerTemplate = "\n<tr>"
  116.                         . "\n\t<th colspan=\"2\">"
  117.                         . "\n\t\t{header}"
  118.                         . "\n\t</th>"
  119.                         . "\n</tr>";
  120.  
  121.         $elementTemplate = "\n<tr valign=\"top\">"
  122.                          . "\n\t<td class=\"qfLabel\"> "
  123.                          . "<!-- BEGIN required -->"
  124.                          . "<span class=\"required\">*</span>"
  125.                          . "<!-- END required -->"
  126.                          . "{label}</td>"
  127.                          . "\n\t<td class=\"qfElement\">"
  128.                          . "\n{element}"
  129.                          . "<!-- BEGIN label_2 --> "
  130.                          . "<span class=\"qfLabel2\">{label_2}</span>"
  131.                          . "<!-- END label_2 -->"
  132.                          . "\n\t</td>"
  133.                          . "\n</tr>";
  134.  
  135.         $groupTemplate = "\n\t\t<table class=\"group\">"
  136.                        . "\n\t\t<tr>"
  137.                        . "\n\t\t\t{content}"
  138.                        . "\n\t\t</tr>"
  139.                        . "\n\t\t</table>";
  140.  
  141.         $groupElementTemplate = "<td>{element}"
  142.                               . "<!-- BEGIN label --><br/>"
  143.                               . "<span class=\"qfLabel\">{label}</span>"
  144.                               . "<!-- END label -->"
  145.                               . "</td>";
  146.  
  147.         $renderer =& $page->defaultRenderer();
  148.  
  149.         $renderer->setFormTemplate($formTemplate);
  150.         $renderer->setHeaderTemplate($headerTemplate);
  151.         $renderer->setElementTemplate($elementTemplate);
  152.         $renderer->setGroupTemplate($groupTemplate, 'name');
  153.         $renderer->setGroupElementTemplate($groupElementTemplate, 'name');
  154.  
  155.         $styles = $this->getStyleSheet();
  156.         $js     = '';
  157.  
  158.         // on preview tab, add progress bar javascript and stylesheet
  159.         if ($page->getAttribute('id') == 'Preview') {
  160.             $pb = $page->controller->createProgressBar();
  161.             $pb->setTab($tab);
  162.  
  163.             $styles .= $pb->getStyle();
  164.             $js      = $pb->getScript();
  165.  
  166.             $p->addStyleDeclaration($styles);
  167.             $p->addScriptDeclaration($js);
  168.  
  169.             $pbElement =& $page->getElement('progressBar');
  170.             $pbElement->setText($pb->toHtml() . '<br /><br />');
  171.         } else {
  172.             $p->addStyleDeclaration($styles);
  173.         }
  174.         $page->accept($renderer);
  175.  
  176.         $p->addBodyContent($renderer->toHtml());
  177.         $p->display();
  178.     }
  179.  
  180.     /**
  181.      * Returns the custom style sheet to use for layout
  182.      *
  183.      * @param bool $content (optional) Either return css filename or string contents
  184.      *
  185.      * @return string
  186.      * @access public
  187.      * @since  version 2.1.0 (2006-08-12)
  188.      */
  189.     function getStyleSheet($content = true)
  190.     {
  191.         if ($content) {
  192.             $styles = file_get_contents($this->css);
  193.         } else {
  194.             $styles = $this->css;
  195.         }
  196.         return $styles;
  197.     }
  198.  
  199.     /**
  200.      * Set the custom style sheet to use your own styles
  201.      *
  202.      * @param string $css (optional) File to read user-defined styles from
  203.      *
  204.      * @return bool    true if custom styles, false if default styles applied
  205.      * @access public
  206.      * @since  version 2.1.0 (2006-08-12)
  207.      */
  208.     function setStyleSheet($css = null)
  209.     {
  210.         // default stylesheet is into package data directory
  211.         if (!isset($css)) {
  212.             $this->css = 'C:\php5\pear\data' . DIRECTORY_SEPARATOR
  213.                  . 'HTML_Progress2' . DIRECTORY_SEPARATOR
  214.                  . 'htmlpage2.css';
  215.         }
  216.  
  217.         $res = isset($css) && file_exists($css);
  218.         if ($res) {
  219.             $this->css = $css;
  220.         }
  221.         return $res;
  222.     }
  223. }
  224. ?>