home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / CMS / xoops-2.0.18.1.exe / xoops-2.0.18.1 / htdocs / class / xoopsform / formelementtray.php < prev    next >
Encoding:
PHP Script  |  2007-12-05  |  5.9 KB  |  197 lines

  1. <?php
  2. // $Id: formelementtray.php 1151 2007-12-04 15:43:01Z phppp $
  3. //  ------------------------------------------------------------------------ //
  4. //                XOOPS - PHP Content Management System                      //
  5. //                    Copyright (c) 2000 XOOPS.org                           //
  6. //                       <http://www.xoops.org/>                             //
  7. //  ------------------------------------------------------------------------ //
  8. //  This program is free software; you can redistribute it and/or modify     //
  9. //  it under the terms of the GNU General Public License as published by     //
  10. //  the Free Software Foundation; either version 2 of the License, or        //
  11. //  (at your option) any later version.                                      //
  12. //                                                                           //
  13. //  You may not change or alter any portion of this comment or credits       //
  14. //  of supporting developers from this source code or any supporting         //
  15. //  source code which is considered copyrighted (c) material of the          //
  16. //  original comment or credit authors.                                      //
  17. //                                                                           //
  18. //  This program is distributed in the hope that it will be useful,          //
  19. //  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
  20. //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
  21. //  GNU General Public License for more details.                             //
  22. //                                                                           //
  23. //  You should have received a copy of the GNU General Public License        //
  24. //  along with this program; if not, write to the Free Software              //
  25. //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
  26. //  ------------------------------------------------------------------------ //
  27. // Author: Kazumi Ono (AKA onokazu)                                          //
  28. // URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ //
  29. // Project: The XOOPS Project                                                //
  30. // ------------------------------------------------------------------------- //
  31. if (!defined('XOOPS_ROOT_PATH')) {
  32.     die("XOOPS root path not defined");
  33. }
  34. /**
  35.  * 
  36.  * 
  37.  * @package     kernel
  38.  * @subpackage  form
  39.  * 
  40.  * @author        Kazumi Ono    <onokazu@xoops.org>
  41.  * @copyright    copyright (c) 2000-2003 XOOPS.org
  42.  */
  43.  
  44. /**
  45.  * A group of form elements
  46.  * 
  47.  * @author    Kazumi Ono    <onokazu@xoops.org>
  48.  * @copyright    copyright (c) 2000-2003 XOOPS.org
  49.  * 
  50.  * @package     kernel
  51.  * @subpackage  form
  52.  */
  53. class XoopsFormElementTray extends XoopsFormElement {
  54.  
  55.     /**
  56.      * array of form element objects
  57.      * @var array   
  58.      * @access  private
  59.      */
  60.     var $_elements = array();
  61.  
  62.     /**
  63.      * required elements
  64.      * @var array   
  65.      */
  66.     var $_required = array();
  67.  
  68.     /**
  69.      * HTML to seperate the elements
  70.      * @var    string  
  71.      * @access  private
  72.      */
  73.     var $_delimeter;
  74.  
  75.     /**
  76.      * constructor
  77.      * 
  78.      * @param    string  $caption    Caption for the group.
  79.      * @param    string  $delimiter  HTML to separate the elements
  80.      */
  81.     function XoopsFormElementTray($caption, $delimeter = " ", $name = "") {
  82.         $this->setName($name);
  83.         $this->setCaption($caption);
  84.         $this->_delimeter = $delimeter;
  85.     }
  86.  
  87.     /**
  88.      * Is this element a container of other elements?
  89.      * 
  90.      * @return    bool true
  91.      */    
  92.     function isContainer()
  93.     {
  94.         return true;
  95.     }
  96.  
  97.     /**
  98.      * Find out if there are required elements.
  99.      *
  100.      * @return    bool
  101.      */
  102.     function isRequired() {
  103.         return !empty($this->_required);
  104.     }
  105.  
  106.     /**
  107.      * Add an element to the group
  108.      * 
  109.      * @param    object  &$element    {@link XoopsFormElement} to add
  110.      */
  111.     function addElement(&$formElement, $required = false) {
  112.         $this->_elements[] =& $formElement;
  113.         if (!$formElement->isContainer()) {
  114.             if ($required) {
  115.                 $formElement->_required = true;
  116.                 $this->_required[] =& $formElement;
  117.             }
  118.         } else {
  119.             $required_elements =& $formElement->getRequired();
  120.             $count = count($required_elements);
  121.             for ($i = 0 ; $i < $count; $i++) {
  122.                 $this->_required[] =& $required_elements[$i];
  123.             }
  124.         }
  125.     }
  126.  
  127.     /**
  128.      * get an array of "required" form elements
  129.      * 
  130.      * @return    array   array of {@link XoopsFormElement}s 
  131.      */
  132.     function &getRequired() {
  133.         return $this->_required;
  134.     }
  135.  
  136.     /**
  137.      * Get an array of the elements in this group
  138.      * 
  139.      * @param    bool    $recurse    get elements recursively?
  140.      * @return  array   Array of {@link XoopsFormElement} objects. 
  141.      */
  142.     function &getElements($recurse = false) {
  143.         if (!$recurse) {
  144.             return $this->_elements;
  145.         } else {
  146.             $ret = array();
  147.             $count = count($this->_elements);
  148.             for ($i = 0; $i < $count; $i++) {
  149.                 if (!$this->_elements[$i]->isContainer()) {
  150.                     $ret[] =& $this->_elements[$i];
  151.                 } else {
  152.                     $elements =& $this->_elements[$i]->getElements(true);
  153.                     $count2 = count($elements);
  154.                     for ($j = 0; $j < $count2; $j++) {
  155.                         $ret[] =& $elements[$j];
  156.                     }
  157.                     unset($elements);
  158.                 }
  159.             }
  160.             return $ret;
  161.         }
  162.     }
  163.  
  164.     /**
  165.      * Get the delimiter of this group
  166.      * 
  167.      * @param    bool    $encode To sanitizer the text?
  168.      * @return    string  The delimiter
  169.      */
  170.     function getDelimeter($encode = false) {
  171.         return $encode ? htmlspecialchars(str_replace(' ', ' ', $this->_delimeter)) : $this->_delimeter;
  172.     }
  173.  
  174.     /**
  175.      * prepare HTML to output this group
  176.      * 
  177.      * @return    string  HTML output
  178.      */
  179.     function render() {
  180.         $count = 0;
  181.         $ret = "";
  182.         foreach ( $this->getElements() as $ele ) {
  183.             if ($count > 0) {
  184.                 $ret .= $this->getDelimeter();
  185.             }
  186.             if ($ele->getCaption() != '') {
  187.                 $ret .= $ele->getCaption()." ";
  188.             }
  189.             $ret .= $ele->render()."\n";
  190.             if (!$ele->isHidden()) {
  191.                 $count++;
  192.             }
  193.         }
  194.         return $ret;
  195.     }
  196. }
  197. ?>