[ Index ]
 

Code source de XOOPS 2.0.17.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/htdocs/class/xoopsform/ -> formcheckbox.php (source)

   1  <?php
   2  // $Id: formcheckbox.php 959 2007-08-07 12:53:33Z dugris $

   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   * @package     kernel

  36   * @subpackage  form

  37   *

  38   * @author        Kazumi Ono    <onokazu@xoops.org>

  39   * @copyright    copyright (c) 2000-2003 XOOPS.org

  40   */
  41  /**

  42   * One or more Checkbox(es)

  43   *

  44   * @package     kernel

  45   * @subpackage  form

  46   *

  47   * @author    Kazumi Ono    <onokazu@xoops.org>

  48   * @copyright    copyright (c) 2000-2003 XOOPS.org

  49   */
  50  class XoopsFormCheckBox extends XoopsFormElement {
  51  
  52      /**

  53       * Availlable options

  54       * @var array

  55       * @access    private

  56       */
  57      var $_options = array();
  58  
  59      /**

  60       * pre-selected values in array

  61       * @var    array

  62       * @access    private

  63       */
  64      var $_value = array();
  65  
  66      /**

  67       * Constructor

  68       *

  69       * @param    string  $caption

  70       * @param    string  $name

  71       * @param    mixed   $value  Either one value as a string or an array of them.

  72       */
  73  	function XoopsFormCheckBox($caption, $name, $value = null, $delimeter = ""){
  74          $this->setCaption($caption);
  75          $this->setName($name);
  76          if (isset($value)) {
  77              $this->setValue($value);
  78          }
  79          $this->delimeter = $delimeter;
  80      }
  81  
  82      /**

  83       * Get the "value"

  84       *

  85       * @return    array

  86       */
  87  	function getValue(){
  88          return $this->_value;
  89      }
  90  
  91      /**

  92       * Set the "value"

  93       *

  94       * @param    array

  95       */
  96  	function setValue($value){
  97          $this->_value = array();
  98          if (is_array($value)) {
  99              foreach ($value as $v) {
 100                  $this->_value[] = $v;
 101              }
 102          } else {
 103              $this->_value[] = $value;
 104          }
 105      }
 106  
 107      /**

 108       * Add an option

 109       *

 110       * @param    string  $value

 111       * @param    string  $name

 112       */
 113  	function addOption($value, $name=""){
 114          if ($name != "") {
 115              $this->_options[$value] = $name;
 116          } else {
 117              $this->_options[$value] = $value;
 118          }
 119      }
 120  
 121      /**

 122       * Add multiple Options at once

 123       *

 124       * @param    array   $options    Associative array of value->name pairs

 125       */
 126  	function addOptionArray($options){
 127          if ( is_array($options) ) {
 128              foreach ( $options as $k=>$v ) {
 129                  $this->addOption($k, $v);
 130              }
 131          }
 132      }
 133  
 134      /**

 135       * Get an array with all the options

 136       *

 137       * @return    array   Associative array of value->name pairs

 138       */
 139  	function getOptions(){
 140          return $this->_options;
 141      }
 142  
 143      /**

 144       * prepare HTML for output

 145       *

 146       * @return    string

 147       */
 148  	function render(){
 149          $ret = "";
 150          if ( count($this->getOptions()) > 1 && substr($this->getName(), -2, 2) != "[]" ) {
 151              $newname = $this->getName()."[]";
 152              $this->setName($newname);
 153          }
 154          foreach ( $this->getOptions() as $value => $name ) {
 155              $ret .= "<input type='checkbox' name='".$this->getName()."' value='".$value."'";
 156              if (count($this->getValue()) > 0 && in_array($value, $this->getValue())) {
 157                  $ret .= " checked='checked'";
 158              }
 159              $ret .= $this->getExtra()." />".$name.$this->delimeter."\n";
 160          }
 161          return $ret;
 162      }
 163  }
 164  ?>


Généré le : Sun Nov 25 11:44:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics