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_Lite.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  39.4 KB  |  1,213 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: Progress2_Lite.php,v 1.13 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.  * Standalone HTML loading bar with only PHP and JS interface.
  47.  *
  48.  * The HTML_Progress2_Lite class allow you to add a quick
  49.  * horizontal or vertical loading bar to any of your xhtml document.
  50.  * You should have a browser that accept DHTML feature.
  51.  *
  52.  * This class has no dependency and can be used completely outside
  53.  * the PEAR infrastructure.
  54.  *
  55.  * Here is a basic example:
  56.  * <code>
  57.  * <html>
  58.  * <body>
  59.  * <?php
  60.  * require_once 'HTML/Progress2_Lite.php';
  61.  *
  62.  * function myProcess()
  63.  * {
  64.  *     for ($i=0; $i<100000; $i++) { }
  65.  * }
  66.  *
  67.  * $pbl = new HTML_Progress2_Lite();
  68.  * $pbl->addLabel('text','txt1','Progress2 Lite - Basic Example');
  69.  * $pbl->display();
  70.  *
  71.  * for($i=1; $i<=100; $i++) {
  72.  *     $pbl->moveStep($i);
  73.  *     myProcess();
  74.  * }
  75.  * ?>
  76.  * </body>
  77.  * </html>
  78.  * </code>
  79.  *
  80.  * @category  HTML
  81.  * @package   HTML_Progress2
  82.  * @author    Laurent Laville <pear@laurent-laville.org>
  83.  * @author    Mika Turin <turin@inbox.lv>
  84.  * @author    Gerd Weitenberg <hahnebuechen@web.de>
  85.  * @copyright 2005-2008 Laurent Laville
  86.  * @license   http://www.opensource.org/licenses/bsd-license.php  New BSD License
  87.  * @version   Release: 2.4.0
  88.  * @link      http://pear.php.net/package/HTML_Progress2
  89.  * @link      http://www.phpclasses.org/browse/package/1222.html
  90.  *            From an original idea of Mike Turin
  91.  * @link      http://www.phpclasses.org/browse/package/1964.html
  92.  *            Improve version of Gerd Weitenberg
  93.  * @since     Class available since Release 2.0.0RC1
  94.  */
  95.  
  96. class HTML_Progress2_Lite
  97. {
  98.     /**
  99.      * Label that uniquely identifies the progress bar.
  100.      *
  101.      * @var        string
  102.      * @since      2.0.0
  103.      * @access     private
  104.      */
  105.     var $_ident;
  106.  
  107.     /**
  108.      * Status of the progress bar (new, show, hide).
  109.      *
  110.      * @var        string
  111.      * @since      2.0.0
  112.      * @access     private
  113.      */
  114.     var $_status = 'new';
  115.  
  116.     /**
  117.      * Steps of the progress bar.
  118.      *
  119.      * @var        integer
  120.      * @since      2.0.0
  121.      * @access     private
  122.      */
  123.     var $_step = 0;
  124.  
  125.     /**
  126.      * Minimum steps of the progress bar.
  127.      *
  128.      * @var        integer
  129.      * @since      2.0.0
  130.      * @access     public
  131.      */
  132.     var $min;
  133.  
  134.     /**
  135.      * Maximum steps of the progress bar.
  136.      *
  137.      * @var        integer
  138.      * @since      2.0.0
  139.      * @access     public
  140.      */
  141.     var $max;
  142.  
  143.     /**
  144.      * Progress bar position (absolute, relative).
  145.      *
  146.      * @var        string
  147.      * @since      2.0.0
  148.      * @access     public
  149.      */
  150.     var $position;
  151.  
  152.     /**
  153.      * Progress bar position from left.
  154.      *
  155.      * @var        integer
  156.      * @since      2.0.0
  157.      * @access     public
  158.      */
  159.     var $left;
  160.  
  161.     /**
  162.      * Progress bar position from top.
  163.      *
  164.      * @var        integer
  165.      * @since      2.0.0
  166.      * @access     public
  167.      */
  168.     var $top;
  169.  
  170.     /**
  171.      * Progress bar width in pixel.
  172.      *
  173.      * @var        integer
  174.      * @since      2.0.0
  175.      * @access     public
  176.      */
  177.     var $width;
  178.  
  179.     /**
  180.      * Progress bar height in pixel.
  181.      *
  182.      * @var        integer
  183.      * @since      2.0.0
  184.      * @access     public
  185.      */
  186.     var $height;
  187.  
  188.     /**
  189.      * Progress bar padding in pixel.
  190.      *
  191.      * @var        integer
  192.      * @since      2.0.0
  193.      * @access     public
  194.      */
  195.     var $padding;
  196.  
  197.     /**
  198.      * Progress bar foreground color.
  199.      *
  200.      * @var        string
  201.      * @since      2.0.0
  202.      * @access     public
  203.      */
  204.     var $foreground_color = '#0033FF';
  205.  
  206.     /**
  207.      * Progress bar foreground color.
  208.      *
  209.      * @var        string
  210.      * @since      2.0.0
  211.      * @access     public
  212.      */
  213.     var $background_color = '#C0C0C0';
  214.  
  215.     /**
  216.      * Progress bar border properties
  217.      *
  218.      * <code>
  219.      * $border = array(
  220.      *    'width' => 1          # width size in pixel
  221.      *    'style' => 'solid'    # style (solid, dashed, dotted ...)
  222.      *    'color' => '#000000'  # color
  223.      * );
  224.      * </code>
  225.      *
  226.      * @var        array
  227.      * @since      2.0.0
  228.      * @access     public
  229.      */
  230.     var $border = array('width' => 1, 'style' => 'solid', 'color' => '#000000');
  231.  
  232.     /**
  233.      * Direction of motion (right, left, up, down).
  234.      *
  235.      * @var        string
  236.      * @since      2.0.0
  237.      * @access     public
  238.      */
  239.     var $direction = 'right';
  240.  
  241.     /**
  242.      * Progress bar frame properties
  243.      *
  244.      * <code>
  245.      * $frame = array(
  246.      *    'show' => false,             # frame show (true/false)
  247.      *    'left' => 200,               # frame position from left
  248.      *    'top' => 100,                # frame position from top
  249.      *    'width' => 320,              # frame width
  250.      *    'height' => 90,              # frame height
  251.      *    'color' => '#C0C0C0',        # frame color
  252.      *    'border-width' => 2,         # frame border width
  253.      *    'border-style' => 'solid',   # frame border style (solid,
  254.      *                                 # dashed, dotted, inset ...)
  255.      *    'border-color' => '#DFDFDF #404040 #404040 #DFDFDF'
  256.      *                                 # frame border color (3dfx)
  257.      * );
  258.      * </code>
  259.      *
  260.      * @var        array
  261.      * @since      2.0.0
  262.      * @access     public
  263.      * @see        setFrameAttributes()
  264.      */
  265.     var $frame = array('show' => false);
  266.  
  267.     /**
  268.      * Progress bar labels properties
  269.      *
  270.      * <code>
  271.      * $label = array(
  272.      *    'name' => array(                  # label name
  273.      *      'type' => 'text',               # label type
  274.      *                                      # (text,button,step,percent,crossbar)
  275.      *      'value' => ' ',            # label value
  276.      *      'left' => ($left),              # label position from left
  277.      *      'top' => ($top - 16),           # label position from top
  278.      *      'width' => 0,                   # label width
  279.      *      'height' => 0,                  # label height
  280.      *      'align' => 'left',              # label align
  281.      *      'background-color' => 'transparent',          # label background color
  282.      *      'font-family' => 'Verdana, Tahoma, Arial',    # label font family
  283.      *      'font-size' => 11,                            # label font size
  284.      *      'font-weight' => 'normal',                    # label font weight
  285.      *      'font-style' => 'normal',                     # label font style
  286.      *      'color' => '#000000'                          # label font color
  287.      * );
  288.      * </code>
  289.      *
  290.      * @var        array
  291.      * @since      2.0.0
  292.      * @access     public
  293.      * @see        addLabel(), setLabelAttributes()
  294.      */
  295.     var $label = array();
  296.  
  297.     /**
  298.      * Constructor (ZE1)
  299.      *
  300.      * @param array  $options (optional) has of style parameters
  301.      *                                   for the progress bar
  302.      * @param string $id      (optional) progress bar unique identifier
  303.      *
  304.      * @since      version 2.0.0 (2005-10-01)
  305.      * @access     public
  306.      */
  307.     function HTML_Progress2_Lite($options = array(), $id = null)
  308.     {
  309.         $this->__construct($options, $id);
  310.     }
  311.  
  312.     /**
  313.      * Constructor (ZE2) Summary.
  314.      *
  315.      * @param array  $options (optional) has of style parameters
  316.      *                                   for the progress bar
  317.      * @param string $id      (optional) progress bar unique identifier
  318.      *
  319.      * @return     object
  320.      * @since      version 2.0.0 (2005-10-01)
  321.      * @access     protected
  322.      */
  323.     function __construct($options = array(), $id = null)
  324.     {
  325.         if (is_null($id)) {
  326.             $this->_ident = substr(md5(microtime()), 0, 6);
  327.         } else {
  328.             $this->_ident = $id;
  329.         }
  330.  
  331.         $default_options = array(
  332.             'position' => 'absolute',
  333.             'left' => 10,
  334.             'top' => 25,
  335.             'width' => 300,
  336.             'height' => 25,
  337.             'padding' => 0,
  338.             'min' => 0,
  339.             'max' => 100
  340.         );
  341.         $allowed_options = array_keys($default_options);
  342.  
  343.         $options = array_merge($default_options, $options);
  344.  
  345.         foreach ($options as $prop => $val) {
  346.             if (in_array($prop, $allowed_options)) {
  347.                 $this->{$prop} = $val;
  348.             } else {
  349.                 trigger_error("option '$prop' is not allowed", E_USER_WARNING);
  350.             }
  351.         }
  352.         $this->_setStep(0);
  353.  
  354.         ob_implicit_flush(1);
  355.     }
  356.  
  357.     /**
  358.      * Moves the progress bar in all directions (left, right, up , down).
  359.      *
  360.      * @param string $direction fill way of the progress bar
  361.      *
  362.      * @return     void
  363.      * @since      version 2.0.0 (2005-10-01)
  364.      * @access     public
  365.      */
  366.     function setDirection($direction)
  367.     {
  368.         $this->direction = $direction;
  369.  
  370.         if ($this->_status != 'new') {
  371.             $bar      = ob_get_clean();
  372.             $position = $this->_computePosition();
  373.  
  374.             $cssText  = 'left:' . $position['left'] . 'px;';
  375.             $cssText .= 'top:' . $position['top'] . 'px;';
  376.             $cssText .= 'width:' . $position['width'] . 'px;';
  377.             $cssText .= 'height:' . $position['height'] . 'px;';
  378.  
  379.             $bar .= $this->_changeElementStyle('pbar', '', $cssText);
  380.  
  381.             echo $bar . PHP_EOL;
  382.             ob_start();
  383.         }
  384.     }
  385.  
  386.     /**
  387.      * Add a new label to the progress bar.
  388.      *
  389.      * @param string $type  Label type (text,button,step,percent,crossbar)
  390.      * @param string $name  Label name
  391.      * @param string $value (optional) default label value
  392.      *
  393.      * @return     void
  394.      * @since      version 2.0.0 (2005-10-01)
  395.      * @access     public
  396.      * @see        setLabelAttributes(), removeLabel()
  397.      */
  398.     function addLabel($type, $name, $value = ' ')
  399.     {
  400.         switch($type) {
  401.         case 'text':
  402.             $this->label[$name] = array(
  403.                 'type' => $type,
  404.                 'value' => $value,
  405.                 'left' => $this->left,
  406.                 'top' => $this->top - 16,
  407.                 'width' => 0,
  408.                 'height' => 0,
  409.                 'align' => 'left',
  410.                 'background-color' => 'transparent',
  411.                 'font-size' => 11,
  412.                 'font-family' => 'Verdana, Tahoma, Arial',
  413.                 'font-weight' => 'normal',
  414.                 'font-style' => 'normal',
  415.                 'color' => '#000000'
  416.             );
  417.             break;
  418.         case 'button':
  419.             $this->label[$name] = array(
  420.                 'type' => $type,
  421.                 'value' => $value,
  422.                 'action' => '',
  423.                 'target' => 'self',
  424.                 'left' => $this->left,
  425.                 'top' => $this->top + $this->height + 10,
  426.                 'width' => 0,
  427.                 'height' => 0,
  428.                 'align' => 'center',
  429.                 'background-color' => 'transparent',
  430.                 'font-size' => 11,
  431.                 'font-family' => 'Verdana, Tahoma, Arial',
  432.                 'font-weight' => 'normal',
  433.                 'font-style' => 'normal',
  434.                 'color' => '#000000'
  435.             );
  436.             break;
  437.         case 'step':
  438.             $this->label[$name] = array(
  439.                 'type' => $type,
  440.                 'value' => $value,
  441.                 'left' => $this->left + 5,
  442.                 'top' => $this->top + 5,
  443.                 'width' => 10,
  444.                 'height' => 0,
  445.                 'align' => 'right',
  446.                 'background-color' => 'transparent',
  447.                 'font-size' => 11,
  448.                 'font-family' => 'Verdana, Tahoma, Arial',
  449.                 'font-weight' => 'normal',
  450.                 'font-style' => 'normal',
  451.                 'color' => '#000000'
  452.             );
  453.             break;
  454.         case 'percent':
  455.             $this->label[$name] = array(
  456.                 'type' => $type,
  457.                 'value' => $value,
  458.                 'left' => $this->left + $this->width - 50,
  459.                 'top' => $this->top - 16,
  460.                 'width' => 50,
  461.                 'height' => 0,
  462.                 'align' => 'right',
  463.                 'background-color' => 'transparent',
  464.                 'font-size' => 11,
  465.                 'font-family' => 'Verdana, Tahoma, Arial',
  466.                 'font-weight' => 'normal',
  467.                 'font-style' => 'normal',
  468.                 'color' => '#000000'
  469.             );
  470.             break;
  471.         case 'crossbar':
  472.             $this->label[$name] = array(
  473.                 'type' => $type,
  474.                 'value' => $value,
  475.                 'left' => $this->left + ($this->width / 2),
  476.                 'top' => $this->top - 16,
  477.                 'width' => 10,
  478.                 'height' => 0,
  479.                 'align' => 'center',
  480.                 'background-color' => 'transparent',
  481.                 'font-size' => 11,
  482.                 'font-family' => 'Verdana, Tahoma, Arial',
  483.                 'font-weight' => 'normal',
  484.                 'font-style' => 'normal',
  485.                 'color' => '#000000'
  486.             );
  487.             break;
  488.         }
  489.     }
  490.  
  491.     /**
  492.      * Removes a label to the progress bar.
  493.      *
  494.      * @param string $name Label name
  495.      *
  496.      * @return     void
  497.      * @since      version 2.0.0 (2005-10-01)
  498.      * @access     public
  499.      * @see        addLabel()
  500.      */
  501.     function removeLabel($name)
  502.     {
  503.         if (isset($this->label[$name]) && $this->label[$name]['type'] != 'button') {
  504.             unset($this->label[$name]);
  505.         }
  506.     }
  507.  
  508.     /**
  509.      * Add a new button with the progress bar.
  510.      *
  511.      * @param string $name   Button name
  512.      * @param string $value  Label value
  513.      * @param string $action Action to do (see QUERY_STRING)
  514.      * @param string $target (optional) Frame target (default is self)
  515.      *
  516.      * @return     void
  517.      * @since      version 2.0.0 (2005-10-01)
  518.      * @access     public
  519.      * @see        removeButton(), addLabel()
  520.      */
  521.     function addButton($name, $value, $action, $target = 'self')
  522.     {
  523.         $this->addLabel('button', $name, $value);
  524.         $this->label[$name]['action'] = $action;
  525.         $this->label[$name]['target'] = $target;
  526.     }
  527.  
  528.     /**
  529.      * Removes a button to the progress bar.
  530.      *
  531.      * @param string $name Label name
  532.      *
  533.      * @return     void
  534.      * @since      version 2.0.0 (2005-10-01)
  535.      * @access     public
  536.      * @see        addButton()
  537.      */
  538.     function removeButton($name)
  539.     {
  540.         if (isset($this->label[$name]) && $this->label[$name]['type'] == 'button') {
  541.             unset($this->label[$name]);
  542.         }
  543.     }
  544.  
  545.     /**
  546.      * Build a frame around the progress bar.
  547.      *
  548.      * @param array $attributes (optional) hash of style parameters
  549.      *
  550.      * @return     void
  551.      * @since      version 2.0.0 (2005-10-01)
  552.      * @access     public
  553.      */
  554.     function setFrameAttributes($attributes = array())
  555.     {
  556.         $default = array(
  557.             'show' => true,
  558.             'left' => 200,
  559.             'top' => 100,
  560.             'width' => 320,
  561.             'height' => 90,
  562.             'color' => '#C0C0C0',
  563.             'border-width' => 2,
  564.             'border-style' => 'solid',
  565.             'border-color' => '#DFDFDF #404040 #404040 #DFDFDF'
  566.         );
  567.  
  568.         $allowed_options = array_keys($default);
  569.  
  570.         $options = array_merge($default, $attributes);
  571.  
  572.         foreach ($options as $prop => $val) {
  573.             if (in_array($prop, $allowed_options)) {
  574.                 $this->frame[$prop] = $val;
  575.             } else {
  576.                 trigger_error("frame option '$prop' is not allowed", E_USER_WARNING);
  577.             }
  578.         }
  579.     }
  580.  
  581.     /**
  582.      * Defines main style of a progress bar.
  583.      *
  584.      * @param array $attributes (optional) hash of style parameters
  585.      *
  586.      * @return     void
  587.      * @since      version 2.0.0 (2005-10-01)
  588.      * @access     public
  589.      */
  590.     function setBarAttributes($attributes = array())
  591.     {
  592.         $cssText        = '';
  593.         $cssText_border = '';
  594.         $bar            = ob_get_clean();
  595.  
  596.         foreach ($attributes as $attrName => $attrVal) {
  597.             if ($attrName == 'border-style') {
  598.                 $this->border['style'] = $attrVal;
  599.  
  600.                 $cssText_border .= 'borderStyle:' . $this->border['style'] . ';';
  601.  
  602.             } elseif ($attrName == 'border-width') {
  603.                 $this->border['width'] = $attrVal;
  604.  
  605.                 $cssText_border .= 'borderWidth:' . $this->border['width'] . 'px;';
  606.  
  607.             } elseif ($attrName == 'border-color') {
  608.                 $this->border['color'] = $attrVal;
  609.  
  610.                 $cssText_border .= 'borderColor:' . $this->border['color'] . ';';
  611.  
  612.             } elseif ($attrName == 'background-color') {
  613.                 $this->background_color = $attrVal;
  614.  
  615.                 $cssText_border .= 'backgroundColor:'
  616.                                 . $this->background_color . ';';
  617.  
  618.             } elseif ($attrName == 'color') {
  619.                 $this->foreground_color = $attrVal;
  620.  
  621.                 $cssText .= 'backgroundColor:' . $this->foreground_color . ';';
  622.             }
  623.         }
  624.  
  625.         if ($this->_status != 'new') {
  626.             if (!empty($cssText_border)) {
  627.                 $bar .= $this->_changeElementStyle('pbrd', '', $cssText_border);
  628.             }
  629.             if (!empty($cssText)) {
  630.                 $bar .= $this->_changeElementStyle('pbar', '', $cssText);
  631.             }
  632.         }
  633.  
  634.         echo $bar . PHP_EOL;
  635.         ob_start();
  636.     }
  637.  
  638.     /**
  639.      * Defines style of a progress bar label.
  640.      *
  641.      * @param string $name       Label identifier
  642.      * @param array  $attributes (optional) hash of style parameters
  643.      *
  644.      * @return     void
  645.      * @since      version 2.0.0 (2005-10-01)
  646.      * @access     public
  647.      * @see        addLabel()
  648.      */
  649.     function setLabelAttributes($name, $attributes = array())
  650.     {
  651.         $fontfamily = $fontweight = '';
  652.  
  653.         $bar = ob_get_clean();
  654.  
  655.         foreach ($attributes as $attrName => $attrVal) {
  656.             if ($attrName == 'color') {
  657.                 $this->label[$name]['color'] = $attrVal;
  658.                 if ($this->_status != 'new') {
  659.                     $cssText = 'color:' . $this->label[$name]['color'] . ';';
  660.  
  661.                     $bar .= $this->_changeElementStyle('plbl', $name, $cssText);
  662.                 }
  663.  
  664.             } elseif ($attrName == 'background-color') {
  665.                 $this->label[$name]['background-color'] = $attrVal;
  666.                 if ($this->_status != 'new') {
  667.                     $cssText = 'backgroundColor:' .
  668.                                 $this->label[$name]['background-color'] . ';';
  669.                     $bar    .= $this->_changeElementStyle('plbl', $name, $cssText);
  670.                 }
  671.  
  672.             } elseif ($attrName == 'font-size') {
  673.                 $this->label[$name]['font-size'] = $font = $attrVal;
  674.             } elseif ($attrName == 'font-family') {
  675.                 $this->label[$name]['font-family'] = $font = $attrVal;
  676.             } elseif ($attrName == 'font-weight') {
  677.                 $this->label[$name]['font-weight'] = $font = $attrVal;
  678.             } elseif ($attrName == 'font-style') {
  679.                 $this->label[$name]['font-style'] = $font = $attrVal;
  680.  
  681.             } elseif ($attrName == 'value') {
  682.                 $this->label[$name]['value'] = $attrVal;
  683.                 if ($this->_status != 'new') {
  684.                     $bar .= $this->_changeLabelText($name,
  685.                                                     $this->label[$name]['value']);
  686.                 }
  687.  
  688.             } elseif ($attrName == 'left') {
  689.                 $this->label[$name]['left'] = $attrVal;
  690.             } elseif ($attrName == 'top') {
  691.                 $this->label[$name]['top'] = $attrVal;
  692.             } elseif ($attrName == 'width') {
  693.                 $this->label[$name]['width'] = $attrVal;
  694.             } elseif ($attrName == 'height') {
  695.                 $this->label[$name]['height'] = $attrVal;
  696.             } elseif ($attrName == 'align') {
  697.                 $this->label[$name]['align'] = $attrVal;
  698.             }
  699.         }
  700.         if (isset($font)) {
  701.             if ($this->_status != 'new') {
  702.                 $cssText = 'fontSize:' . $this->label[$name]['font-size'] . 'px;'
  703.                          . 'fontFamily:' . $this->label[$name]['font-family'] . ';'
  704.                          . 'fontWeight:' . $this->label[$name]['font-weight'] . ';'
  705.                          . 'fontStyle:' . $this->label[$name]['font-style'] . ';';
  706.  
  707.                 $bar .= $this->_changeElementStyle('plbl', $name, $cssText);
  708.             }
  709.         }
  710.  
  711.         if ($this->_status != 'new') {
  712.             $cssText = 'top:' . $this->label[$name]['top'] . 'px;'
  713.                      . 'left:' . $this->label[$name]['left'] . 'px;';
  714.  
  715.             if ($this->label[$name]['width'] > 0) {
  716.                 $cssText .= 'width:' . $this->label[$name]['width'] . 'px;';
  717.             }
  718.             if ($this->label[$name]['height'] > 0) {
  719.                 $cssText .= 'height:' . $this->label[$name]['height'] . 'px;';
  720.             }
  721.             $cssText .= 'textAlign:' . $this->label[$name]['align'] .';';
  722.  
  723.             $bar .= $this->_changeElementStyle('plbl', $name, $cssText);
  724.         }
  725.  
  726.         echo $bar . PHP_EOL;
  727.         ob_start();
  728.     }
  729.  
  730.     /**
  731.      * Changes new step value of the progress bar.
  732.      *
  733.      * @param integer $step new step value
  734.      *
  735.      * @return     void
  736.      * @since      version 2.0.0 (2005-10-01)
  737.      * @access     public
  738.      */
  739.     function moveStep($step)
  740.     {
  741.         $this->_setStep($step);
  742.         $position = $this->_computePosition();
  743.         $bar      = ob_get_clean();
  744.         $cssText  = '';
  745.         if ($this->direction == 'right' || $this->direction == 'left') {
  746.             if ($this->direction == 'left') {
  747.                 $cssText .= 'left:' . $position['left'] . 'px;';
  748.             }
  749.             $cssText .= 'width:' . $position['width'] . 'px;';
  750.         }
  751.         if ($this->direction == 'up' || $this->direction == 'down') {
  752.             if ($this->direction == 'up') {
  753.                 $cssText .= 'top:' . $position['top'] . 'px;';
  754.             }
  755.             $cssText .= 'height:' . $position['height'] . 'px;';
  756.         }
  757.         $bar .= $this->_changeElementStyle('pbar', '', $cssText);
  758.  
  759.         foreach ($this->label as $name => $data) {
  760.             switch($data['type']) {
  761.             case 'step':
  762.                 $bar .= $this->_changeLabelText($name, $this->_step.'/'.$this->max);
  763.                 break;
  764.             case 'percent':
  765.                 $bar .= $this->_changeLabelText($name,
  766.                                                 $this->_computePercent() . '%');
  767.                 break;
  768.             case 'crossbar':
  769.                 $bar .= $this->_changeCrossItem($name);
  770.                 break;
  771.             }
  772.         }
  773.  
  774.         echo $bar . PHP_EOL;
  775.         ob_start();
  776.     }
  777.  
  778.     /**
  779.      * Changes value of the progress bar to the next step.
  780.      *
  781.      * @return     void
  782.      * @since      version 2.0.0 (2005-10-01)
  783.      * @access     public
  784.      * @see        moveStep()
  785.      */
  786.     function moveNext()
  787.     {
  788.         $this->moveStep($this->_step + 1);
  789.     }
  790.  
  791.     /**
  792.      * Changes value of the progress bar to the minimum step.
  793.      *
  794.      * @return     void
  795.      * @since      version 2.0.0 (2005-10-01)
  796.      * @access     public
  797.      * @see        moveStep()
  798.      */
  799.     function moveMin()
  800.     {
  801.         $this->moveStep($this->min);
  802.     }
  803.  
  804.     /**
  805.      * Returns the progress bar structure as HTML.
  806.      *
  807.      * @return     string
  808.      * @since      version 2.0.0 (2005-10-01)
  809.      * @access     public
  810.      * @see        display()
  811.      */
  812.     function toHtml()
  813.     {
  814.         $html = '';
  815.         $js   = '';
  816.  
  817.         //$this->_setStep($this->_step);
  818.         $position = $this->_computePosition();
  819.  
  820.         $style_brd = 'position:absolute;'
  821.                    . 'top:' . $this->top . 'px;'
  822.                    . 'left:' . $this->left . 'px;'
  823.                    . 'width:' . $this->width . 'px;'
  824.                    . 'height:' . $this->height . 'px;'
  825.                    . 'background-color:' . $this->background_color . ';';
  826.  
  827.         if ($this->border['width'] > 0 ) {
  828.             $style_brd .= 'border-width:' . $this->border['width'] . 'px;'
  829.                        .  'border-style:' . $this->border['style'] . ';'
  830.                        .  'border-color:' . $this->border['color'] . ';';
  831.         }
  832.         $style_bar = 'position:absolute;'
  833.                    . 'top:' . $position['top'] . 'px;'
  834.                    . 'left:' . $position['left'] . 'px;'
  835.                    . 'width:' . $position['width'] . 'px;'
  836.                    . 'height:' . $position['height'] . 'px;'
  837.                    . 'background-color:' . $this->foreground_color . ';';
  838.  
  839.         if ($this->frame['show']) {
  840.             if ($this->frame['border-width'] > 0) {
  841.                 $border = 'border-width:' . $this->frame['border-width'] . 'px;'
  842.                         . 'border-style:' . $this->frame['border-style'] . ';'
  843.                         . 'border-color:' . $this->frame['border-color'] . ';';
  844.             }
  845.             if ($this->position == 'relative') {
  846.                 $html = '<div id="tfrm' . $this->_ident . '"'
  847.                       . ' style="position:relative;top:0;left:0;">'
  848.                       . PHP_EOL;
  849.                 $top  = 0;
  850.                 $left = 0;
  851.             } else {
  852.                 $top  = $this->frame['top'];
  853.                 $left = $this->frame['left'];
  854.             }
  855.             $html .= '<div id="pfrm' . $this->_ident .'" style="'
  856.                   .  'position:absolute;'
  857.                   .  'top:' . $top . 'px;'
  858.                   .  'left:' . $left . 'px;'
  859.                   .  'width:' . $this->frame['width'] . 'px;'
  860.                   .  'height:' . $this->frame['height'] . 'px;'
  861.                   .  $border
  862.                   .  'background-color:' . $this->frame['color'] . ';">'
  863.                   .  PHP_EOL;
  864.         } else {
  865.             if ($this->position == 'relative') {
  866.                 $html = '<div id="tfrm' . $this->_ident . '"'
  867.                       . ' style="position:relative;top:0;left:0;">'
  868.                       . PHP_EOL;
  869.             }
  870.         }
  871.  
  872.         $html .= '<div id="pbrd'.$this->_ident .
  873.                  '" style="'.$style_brd.'">'.PHP_EOL;
  874.         $html .= '<div id="pbar'.$this->_ident .
  875.                  '" style="'.$style_bar.'"></div></div>'.PHP_EOL;
  876.  
  877.         foreach ($this->label as $name => $data) {
  878.             $style_lbl = 'position:absolute;'
  879.                        . 'top:' . $data['top'] . 'px;'
  880.                        . 'left:' . $data['left'] . 'px;'
  881.                        . 'text-align:' . $data['align'] . ';';
  882.  
  883.             if ($data['width'] > 0) {
  884.                 $style_lbl .= 'width:' . $data['width'] . 'px;';
  885.             }
  886.             if ($data['height'] > 0) {
  887.                 $style_lbl .= 'height:' . $data['height'] . 'px;';
  888.             }
  889.             $style_lbl .= 'color:' . $data['color'] .';'
  890.                        .  'font-size:' . $data['font-size'] . 'px;'
  891.                        .  'font-family:' . $data['font-family'] . ';'
  892.                        .  'font-weight:' . $data['font-weight'] . ';';
  893.  
  894.             if ($data['background-color'] != '') {
  895.                 $style_lbl .= 'background-color:' . $data['background-color'] . ';';
  896.             }
  897.  
  898.             switch($data['type']) {
  899.             case 'button':
  900.                 $html .= '<div><input id="plbl' . $name . $this->_ident
  901.                       .  '" type="button" value="' . $data['value']
  902.                       .  '" style="' . $style_lbl
  903.                       .  '" onclick="' . $data['target']
  904.                       .  '.location.href=\'' . $data['action'] . '\'" /></div>'
  905.                       .  PHP_EOL;
  906.                 break;
  907.             case 'step':
  908.                 $html .= '<div id="plbl' . $name . $this->_ident
  909.                       .  '" style="' . $style_lbl . '">'
  910.                       .  $this->_step
  911.                       .  '</div>'
  912.                       .  PHP_EOL;
  913.                 break;
  914.             case 'percent':
  915.                 $html .= '<div id="plbl' . $name . $this->_ident
  916.                       .  '" style="' . $style_lbl . '">'
  917.                       .  $this->_computePercent() . '%'
  918.                       .  '</div>'
  919.                       .  PHP_EOL;
  920.                 break;
  921.             case 'text':
  922.             case 'crossbar':
  923.                 $html .= '<div id="plbl' . $name . $this->_ident
  924.                       .  '" style="' . $style_lbl . '">'
  925.                       .  $data['value']
  926.                       .  '</div>'
  927.                       .  PHP_EOL;
  928.                 if ($data['type'] == 'crossbar') {
  929.                     $js .= 'function setRotaryCross'; ;
  930.                     $js .= $name.$this->_ident.'() {' . PHP_EOL;
  931.                     $js .= ' cross = document.getElementById("plbl';
  932.                     $js .= $name.$this->_ident.'").firstChild.nodeValue;'.PHP_EOL;
  933.                     $js .= ' switch(cross) {'.PHP_EOL;
  934.                     $js .= '  case "--": cross = "\\\\"; break;'.PHP_EOL;
  935.                     $js .= '  case "\\\\": cross = "|"; break;'.PHP_EOL;
  936.                     $js .= '  case "|": cross = "/"; break;'.PHP_EOL;
  937.                     $js .= '  default: cross = "--"; break;'.PHP_EOL;
  938.                     $js .= ' }'.PHP_EOL;
  939.                     $js .= ' document.getElementById("plbl'.$name.$this->_ident;
  940.                     $js .= '").firstChild.nodeValue = cross;'.PHP_EOL;
  941.                     $js .= '}'.PHP_EOL;
  942.                 }
  943.                 break;
  944.             }
  945.         }
  946.  
  947.         if (count($this->label) > 0) {
  948.             $js .= 'function setLabelText'.$this->_ident.'(name,text) {'.PHP_EOL;
  949.             $js .= ' name = "plbl" + name + "'.$this->_ident.'";'.PHP_EOL;
  950.             $js .= ' document.getElementById(name).firstChild.nodeValue=text;';
  951.             $js .= PHP_EOL;
  952.             $js .= '}'.PHP_EOL;
  953.         }
  954.  
  955.         $js .= 'function setElementStyle'.$this->_ident.'(prefix,name,styles) {';
  956.         $js .= PHP_EOL;
  957.         $js .= ' name = prefix + name + "'.$this->_ident.'";'.PHP_EOL;
  958.         $js .= ' styles = styles.split(";");'.PHP_EOL;
  959.         $js .= ' styles.pop();'.PHP_EOL;
  960.         $js .= ' for(var i=0; i<styles.length; i++)'.PHP_EOL;
  961.         $js .= ' {'.PHP_EOL;
  962.         $js .= '   s = styles[i].split(":");'.PHP_EOL;
  963.         $js .= '   c = "document.getElementById(name).style."+s[0]+"=\""+s[1]+"\"";';
  964.         $js .= PHP_EOL;
  965.         $js .= '   eval(c);'.PHP_EOL;
  966.         $js .= ' }'.PHP_EOL;
  967.         $js .= '}'.PHP_EOL;
  968.  
  969.         if ($this->frame['show']) {
  970.             $html .= '</div>'.PHP_EOL;
  971.         }
  972.         if ($this->position == 'relative') {
  973.             $html .= '</div>'.PHP_EOL;
  974.         }
  975.  
  976.         $html .= '<script type="text/JavaScript">'.PHP_EOL;
  977.         $html .= $js;
  978.         $html .= '</script>'.PHP_EOL;
  979.  
  980.         return $html;
  981.     }
  982.  
  983.     /**
  984.      * Show the renders of the progress bar.
  985.      *
  986.      * @return     void
  987.      * @since      version 2.0.0 (2005-10-01)
  988.      * @access     public
  989.      * @see        toHtml()
  990.      */
  991.     function display()
  992.     {
  993.         $this->_status = 'show';
  994.         echo $this->toHtml();
  995.     }
  996.  
  997.     /**
  998.      * Hides the progress bar.
  999.      *
  1000.      * @return     void
  1001.      * @since      version 2.0.0 (2005-10-01)
  1002.      * @access     public
  1003.      */
  1004.     function hide()
  1005.     {
  1006.         if ($this->_status=='show') {
  1007.             $this->_status = 'hide';
  1008.             $this->_hide();
  1009.         }
  1010.     }
  1011.  
  1012.     /**
  1013.      * Shows a progress bar hidden.
  1014.      *
  1015.      * @return     void
  1016.      * @since      version 2.0.0 (2005-10-01)
  1017.      * @access     public
  1018.      */
  1019.     function show()
  1020.     {
  1021.         if ($this->_status=='hide') {
  1022.             $this->_status = 'show';
  1023.             $this->_hide();
  1024.         }
  1025.     }
  1026.  
  1027.     /**
  1028.      * Show or Hide a progress bar depending of its current status.
  1029.      *
  1030.      * @return     void
  1031.      * @since      version 2.0.0 (2005-10-01)
  1032.      * @access     private
  1033.      */
  1034.     function _hide()
  1035.     {
  1036.         if ($this->_status == 'hide') {
  1037.             $cssText = 'visibility:hidden;';
  1038.         } else {
  1039.             $cssText = 'visibility:visible;';
  1040.         }
  1041.         $bar  = ob_get_clean();
  1042.         $bar .= $this->_changeElementStyle('pbrd', '', $cssText);
  1043.         $bar .= $this->_changeElementStyle('pbar', '', $cssText);
  1044.  
  1045.         if ($this->frame['show']) {
  1046.             $bar .= $this->_changeElementStyle('pfrm', '', $cssText);
  1047.         }
  1048.         foreach ($this->label as $name => $data) {
  1049.             $bar .= $this->_changeElementStyle('plbl', $name, $cssText);
  1050.         }
  1051.  
  1052.         echo $bar . PHP_EOL;
  1053.         ob_start();
  1054.     }
  1055.  
  1056.     /**
  1057.      * Calculate the current percent of progress.
  1058.      *
  1059.      * @return     integer
  1060.      * @since      version 2.0.0 (2005-10-01)
  1061.      * @access     private
  1062.      */
  1063.     function _computePercent()
  1064.     {
  1065.         $percent = round(($this->_step - $this->min)
  1066.                        / ($this->max - $this->min) * 100);
  1067.         if ($percent > 100) {
  1068.             $percent = 100;
  1069.         }
  1070.         return $percent;
  1071.     }
  1072.  
  1073.     /**
  1074.      * Calculate the new position in pixel of the progress bar value.
  1075.      *
  1076.      * @return     void
  1077.      * @since      version 2.0.0 (2005-10-01)
  1078.      * @access     private
  1079.      */
  1080.     function _computePosition()
  1081.     {
  1082.         switch ($this->direction) {
  1083.         case 'right':
  1084.         case 'left':
  1085.             $bar = $this->width;
  1086.             break;
  1087.         case 'down':
  1088.         case 'up':
  1089.             $bar = $this->height;
  1090.             break;
  1091.         }
  1092.         $pixel = round(($this->_step - $this->min) * ($bar - ($this->padding * 2))
  1093.                      / ($this->max - $this->min));
  1094.         if ($this->_step <= $this->min) {
  1095.             $pixel = 0;
  1096.         }
  1097.         if ($this->_step >= $this->max) {
  1098.             $pixel = $bar - ($this->padding * 2);
  1099.         }
  1100.  
  1101.         switch ($this->direction) {
  1102.         case 'right':
  1103.             $position['left']   = $this->padding;
  1104.             $position['top']    = $this->padding;
  1105.             $position['width']  = $pixel;
  1106.             $position['height'] = $this->height - ($this->padding * 2);
  1107.             break;
  1108.         case 'left':
  1109.             $position['left']   = $this->width - $this->padding - $pixel;
  1110.             $position['top']    = $this->padding;
  1111.             $position['width']  = $pixel;
  1112.             $position['height'] = $this->height - ($this->padding * 2);
  1113.             break;
  1114.         case 'down':
  1115.             $position['left']   = $this->padding;
  1116.             $position['top']    = $this->padding;
  1117.             $position['width']  = $this->width - ($this->padding * 2);
  1118.             $position['height'] = $pixel;
  1119.             break;
  1120.         case 'up':
  1121.             $position['left']   = $this->padding;
  1122.             $position['top']    = $this->height - $this->padding - $pixel;
  1123.             $position['width']  = $this->width - ($this->padding * 2);
  1124.             $position['height'] = $pixel;
  1125.             break;
  1126.         }
  1127.         return $position;
  1128.     }
  1129.  
  1130.     /**
  1131.      * Sets the new step value of the progress bar.
  1132.      *
  1133.      * @param integer $step new step value
  1134.      *
  1135.      * @return     void
  1136.      * @since      version 2.0.0 (2005-10-01)
  1137.      * @access     private
  1138.      */
  1139.     function _setStep($step)
  1140.     {
  1141.         if ($step > $this->max) {
  1142.             $step = $this->max;
  1143.         }
  1144.         if ($step < $this->min) {
  1145.             $step = $this->min;
  1146.         }
  1147.         $this->_step = $step;
  1148.     }
  1149.  
  1150.     /**
  1151.      * Sends a DOM command (emulate cssText attribute) through a javascript function
  1152.      * to change styles of a progress bar's element.
  1153.      *
  1154.      * @param string $prefix  prefix identifier of the element
  1155.      * @param string $element element name (label id.)
  1156.      * @param string $styles  styles of a DOM element
  1157.      *
  1158.      * @return     string
  1159.      * @since      version 2.0.0 (2005-10-01)
  1160.      * @access     private
  1161.      */
  1162.     function _changeElementStyle($prefix, $element, $styles)
  1163.     {
  1164.         $cmd = '<script type="text/JavaScript">'
  1165.              . 'setElementStyle' . $this->_ident
  1166.              . '("' . $prefix . '","' . $element . '","' . $styles . '");'
  1167.              . '</script>';
  1168.  
  1169.         return $cmd;
  1170.     }
  1171.  
  1172.     /**
  1173.      * Sends a DOM command (emulate firstChild.nodeValue)
  1174.      * through a javascript function
  1175.      * to change label value of a progress bar's element.
  1176.      *
  1177.      * @param string $element element name (label id.)
  1178.      * @param string $text    element value (label content)
  1179.      *
  1180.      * @return     string
  1181.      * @since      version 2.0.0 (2005-10-01)
  1182.      * @access     private
  1183.      */
  1184.     function _changeLabelText($element, $text)
  1185.     {
  1186.         $cmd = '<script type="text/JavaScript">'
  1187.              . 'setLabelText' . $this->_ident
  1188.              . '("' . $element . '","' . $text . '");'
  1189.              . '</script>';
  1190.  
  1191.         return $cmd;
  1192.     }
  1193.  
  1194.     /**
  1195.      * Sends a DOM command through a javascript function
  1196.      * to change the next frame animation of a cross bar's element.
  1197.      *
  1198.      * @param string $element element name (cross id.)
  1199.      *
  1200.      * @return     string
  1201.      * @since      version 2.0.0 (2005-10-01)
  1202.      * @access     private
  1203.      */
  1204.     function _changeCrossItem($element)
  1205.     {
  1206.         $cmd = '<script type="text/JavaScript">'
  1207.              . 'setRotaryCross' . $element . $this->_ident . '();'
  1208.              . '</script>';
  1209.  
  1210.         return $cmd;
  1211.     }
  1212. }
  1213. ?>