forms
[ class tree: forms ] [ index: forms ] [ all elements ]

Source for file HTMLCheckBox.class.php

Documentation is available at HTMLCheckBox.class.php

  1. <?php
  2. /**
  3.  * For including this file you have to define the constant "CLASSPATH".
  4.  * Because every include in the framework depends on the CLASSPATH definition.
  5.  * The CLASSPATH means the relative path to the folder that contains the
  6.  * framework GilliGan.
  7.  *
  8.  * @package forms
  9.  * @subpackage items
  10.  */
  11. if !defined"CLASSPATH" ) )
  12. {
  13.     echo "<h3>You have to define the constant CLASSPATH!</h3>\n";
  14.     echo "Example: define( 'CLASSPATH', '../path/to/classes/' );\n";
  15.     exit();
  16. }
  17.  
  18. /**
  19.  *
  20.  */
  21. require_onceCLASSPATH."forms/items/ABSTHTMLFormItem.class.php" );
  22.  
  23. /**
  24.  * Loading the javascript class for form features.
  25.  */
  26. include_once CLASSPATH."html/JavaScript.class.php";
  27.  
  28. /**
  29.  * Loading the javascript class for form features.
  30.  */
  31. include_once CLASSPATH."forms/HTMLLabel.class.php";
  32.  
  33. /**
  34.  * A class to generate checkboxes.
  35.  *
  36.  * @package    forms
  37.  * @subpackage items
  38.  * @version    0.2.61
  39.  * @author     Daniel Plücken <daniel@debakel.net>
  40.  * @license    http://www.gnu.org/copyleft/lesser.html
  41.  *              GNU Lesser General Public License
  42.  * @copyright  Copyright (C) 2003 Daniel Plücken <daniel@debakel.net>
  43.  *
  44.  *  This library is free software; you can redistribute it and/or
  45.  *  modify it under the terms of the GNU Lesser General Public
  46.  *  License as published by the Free Software Foundation; either
  47.  *  version 2.1 of the License.
  48.  *
  49.  *  This library is distributed in the hope that it will be useful,
  50.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  51.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  52.  *  GNU Lesser General Public License for more details.
  53.  *
  54.  *  You should have received a copy of the GNU Lesser General
  55.  *  Public License along with this library; if not, write to the
  56.  *  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  57.  *  Boston, MA 02111-1307 USA
  58.  */
  59. {
  60.     /**
  61.      * @var    integer $value 
  62.      * @access public
  63.      */
  64.     var $value = 1;
  65.     /**
  66.      * @var    boolean $checked 
  67.      * @access public
  68.      */
  69.     var $checked = false;
  70.     /**
  71.      * @var    boolean $label_position_right 
  72.      * @access public
  73.      */
  74.     var $label_position_right = true;
  75.  
  76.  
  77.  
  78.    /**
  79.     * Constructor
  80.     *
  81.     * @version 1.41
  82.     * @since   0.1.0
  83.     * @author  Daniel Plücken <daniel@debakel.net>
  84.     * @access  public
  85.     * @param   string  $name 
  86.     * @param   string  $checked 
  87.     * @param   string  $label 
  88.     * @return  HTMLCheckBox 
  89.     */
  90.    function HTMLCheckBox(
  91.                           $name,
  92.                           $checked false,
  93.                           $label   ""
  94.                         )
  95.    {
  96.      $this->name    = $name;
  97.      $this->id      = $name;
  98.      $this->checked = is_bool$checked )
  99.                       ? $checked
  100.                       : !empty$checked )
  101.                         ? true
  102.                         : false;
  103.  
  104.      if !empty$label ) )
  105.      {
  106.         $tmp_obj =new HTMLLabel$label );
  107.         $tmp_obj->addToFormItem$this );
  108.      }
  109.    }
  110.  
  111.  
  112.  
  113.    /**
  114.     * Returns if the checkbox is declared is checked.
  115.     *
  116.     * @version 1.1
  117.     * @since   0.1.2
  118.     * @author  Daniel Plücken <daniel@debakel.net>
  119.     * @access  public
  120.     * @return  boolean 
  121.     */
  122.    function getChecked()
  123.    return $this->checked}
  124.  
  125.  
  126.  
  127.    /**
  128.     * Returns an if-order of a javascript to check whether this item is NOT
  129.     * filled
  130.     *
  131.     * @version 1.1
  132.     * @since   0.1.5
  133.     * @author  Daniel Plücken <daniel@debakel.net>
  134.     * @access  public
  135.     * @return  string 
  136.     */
  137.    function getChangeOrder()
  138.    return $this->mouseup}
  139.  
  140.  
  141.  
  142.    /**
  143.     * Returns an if-order of a javascript to check whether this item is NOT
  144.     * filled
  145.     *
  146.     * @version 1.1
  147.     * @since   0.1.5
  148.     * @author  Daniel Plücken <daniel@debakel.net>
  149.     * @access  public
  150.     * @return  string 
  151.     */
  152.    function getCheckOrder()
  153.    {
  154.       $out "document.".$this->parentform->name
  155.                     .".".$this->name.".checked != true";
  156.  
  157.       return $out;
  158.    }
  159.  
  160.  
  161.  
  162.    /**
  163.     * Returns a javascript to check all checkboxes in a given form. You have to
  164.     * give the name of the form and the element which should not checked in the
  165.     * javascript function.
  166.     *
  167.     * @static
  168.     * @version 1.0
  169.     * @since   0.2.0
  170.     * @author  Daniel Plücken <daniel@debakel.net>
  171.     * @access  public
  172.     * @return  string 
  173.     */
  174.    function getJSCheckAllWithAncestor()
  175.    {
  176.      $out  Javascript::getIsAncestorOf();
  177.      $out .= "  function checkAllWithAncestor( id_of_ancestor, exception )\r\n"
  178.             ."  {\r\n"
  179.             ."    el_arr = document.getElementsByTagName( 'input' );\r\n\r\n"
  180.             ."    for( i = 0; i < el_arr.length; i++ )\r\n"
  181.             ."      if( "
  182.                       ."el_arr[i].type == 'checkbox' "
  183.                    ."&& isAncestorOf( id_of_ancestor, el_arr[i] ) "
  184.                    ."&& el_arr[i] != exception "
  185.                     .")\r\n"
  186.             ."        el_arr[i].checked = true;\r\n"
  187.             ."  }\r\n\r\n";
  188.  
  189.      return $out;
  190.    }
  191.  
  192.  
  193.  
  194.    /**
  195.     * Returns a javascript to uncheck all checkboxes in a given form. You have
  196.     * to give the name of the form and the element which should not checked in
  197.     * the javascript function.
  198.     *
  199.     * @static
  200.     * @version 1.0
  201.     * @since   0.2.0
  202.     * @author  Daniel Plücken <daniel@debakel.net>
  203.     * @access  public
  204.     * @return  string 
  205.     */
  206.    function getJSUncheckAllWithAncestor()
  207.    {
  208.      $out  Javascript::getIsAncestorOf();
  209.      $out .= "  function uncheckAllWithAncestor( id_of_ancestor, exception )\r\n"
  210.             ."  {\r\n"
  211.             ."    el_arr = document.getElementsByTagName( 'input' );\r\n\r\n"
  212.             ."    for( i = 0; i < el_arr.length; i++ )\r\n"
  213.             ."      if( "
  214.                       ."el_arr[i].type == 'checkbox' "
  215.                    ."&& isAncestorOf( id_of_ancestor, el_arr[i] ) "
  216.                    ."&& el_arr[i] != exception "
  217.                     .")\r\n"
  218.             ."        el_arr[i].checked = false;\r\n"
  219.             ."  }\r\n\r\n";
  220.  
  221.      return $out;
  222.    }
  223.  
  224.  
  225.  
  226.    /**
  227.     * Returns a javascript to check and uncheck all checkboxes in a given form
  228.     * by one checkbox.
  229.     *
  230.     * @static
  231.     * @version 1.1
  232.     * @since   0.1.9
  233.     * @author  Daniel Plücken <daniel@debakel.net>
  234.     * @access  public
  235.     * @return  string 
  236.     */
  237.    {
  238.      $out  HTMLCheckBox::getJSCheckAllWithAncestor();
  239.      $out .= "  function manageAllCheckboxesWithAnchestorByOne( "
  240.                                                  ."id_of_anchestor, which "
  241.                                                             .")\r\n"
  242.             ."  {\r\n"
  243.             ."     if( !which.checked )\r\n"
  244.             ."       checkAllWithAncestor( id_of_anchestor, which );\r\n"
  245.             ."     else\r\n"
  246.             ."       uncheckAllWithAncestor( id_of_anchestor, which );\r\n"
  247.             ."  }\r\n\r\n";
  248.  
  249.      return $out;
  250.    }
  251.  
  252.  
  253.  
  254.    /**
  255.     * Returns a javascript to check all checkboxes in a given form. You have to
  256.     * give the name of the form and the element which should not checked in the
  257.     * javascript function.
  258.     *
  259.     * @static
  260.     * @version 1.0
  261.     * @since   0.1.9
  262.     * @author  Daniel Plücken <daniel@debakel.net>
  263.     * @access  public
  264.     * @return  string 
  265.     */
  266.    function getJSCheckAllInForm()
  267.    {
  268.      $out "  function checkAllInForm( formname, exception )\r\n"
  269.            ."  {\r\n"
  270.   ."    for( i = 0; i < eval( 'document.' + formname ).length; i++ )\r\n"
  271.   ."      if(\r\n"
  272.   ."          eval( 'document.' + formname ).elements[i].type == 'checkbox'\r\n"
  273.   ."       && eval( 'document.' + formname ).elements[i] != exception\r\n"
  274.   ."        )\r\n"
  275.   ."        eval( 'document.' + formname ).elements[i]"
  276.                                            .".checked = true;\r\n"
  277.            ."  }\r\n\r\n";
  278.  
  279.      return $out;
  280.    }
  281.  
  282.  
  283.  
  284.    /**
  285.     * Returns a javascript to check all checkboxes in a given form. You have to
  286.     * give the name of the form and the element which should not unchecked in
  287.     * the javascript function.
  288.     *
  289.     * @static
  290.     * @version 1.0
  291.     * @since   0.1.9
  292.     * @author  Daniel Plücken <daniel@debakel.net>
  293.     * @access  public
  294.     * @return  string 
  295.     */
  296.    function getJSUncheckAllInForm()
  297.    {
  298.      $out "  function uncheckAllInForm( formname, exception )\r\n"
  299.            ."  {\r\n"
  300.   ."    for( i = 0; i < eval( 'document.' + formname ).length; i++ )\r\n"
  301.   ."      if(\r\n"
  302.   ."          eval( 'document.' + formname ).elements[i].type == 'checkbox'\r\n"
  303.   ."       && eval( 'document.' + formname ).elements[i] != exception\r\n"
  304.   ."        )\r\n"
  305.   ."        eval( 'document.' + formname ).elements[i]"
  306.                                         .".checked = false;\r\n"
  307.            ."  }\r\n\r\n";
  308.  
  309.      return $out;
  310.    }
  311.  
  312.  
  313.  
  314.    /**
  315.     * Returns a javascript to check and uncheck all checkboxes in a given form
  316.     * by one checkbox.
  317.     *
  318.     * @static
  319.     * @version 1.1
  320.     * @since   0.1.9
  321.     * @author  Daniel Plücken <daniel@debakel.net>
  322.     * @access  public
  323.     * @return  string 
  324.     */
  325.    {
  326.      $out  HTMLCheckBox::getJSCheckAllInForm();
  327.      $out .= HTMLCheckBox::getJSUncheckAllInForm();
  328.      $out .= "  function manageAllCheckboxesByOne( which )\r\n"
  329.             ."  {\r\n"
  330.             ."     if( !which.checked )\r\n"
  331.             ."       checkAllInForm( which.form.name, which );\r\n"
  332.             ."     else\r\n"
  333.             ."       uncheckAllInForm( which.form.name, which );\r\n"
  334.             ."  }\r\n\r\n";
  335.  
  336.      return $out;
  337.    }
  338.  
  339.  
  340.  
  341.    /**
  342.     * Sets this checkbox checked.
  343.     *
  344.     * @version 1.22
  345.     * @since   0.1.5
  346.     * @author  Daniel Plücken <daniel@debakel.net>
  347.     * @access  public
  348.     * @param   boolean $boolean 
  349.     * @return  string 
  350.     */
  351.    function setChecked$boolean true )
  352.    $this->checked = !empty$boolean true false}
  353.  
  354.  
  355.  
  356.    /**
  357.     * Sets the label of this checkbox.
  358.     *
  359.     * @version 1.21
  360.     * @since   0.1.5
  361.     * @author  Daniel Plücken <daniel@debakel.net>
  362.     * @access  public
  363.     * @param   mixed  $mixed 
  364.     * @return  string 
  365.     */
  366.    function setLabel&$mixed )
  367.    {
  368.      if is_object$mixed ) )
  369.         $mixed->addToFormItem$this );
  370.      else
  371.      {
  372.         if is_object$this->label_obj ) )
  373.            $this->label_obj->setBody$mixed );
  374.         else
  375.         {
  376.            $tmp_obj =new HTMLLabel$mixed );
  377.            $tmp_obj->addToFormItem$this );
  378.         }
  379.      }
  380.    }
  381.  
  382.  
  383.    /**
  384.     * Sets the position of the label to the right side.
  385.     *
  386.     * @version 1.0
  387.     * @since   0.2.6
  388.     * @author  Daniel Plücken <daniel@debakel.net>
  389.     * @access  public
  390.     * @return  void 
  391.     */
  392.    function setLabelPositionRight()
  393.    $this->label_position_right = true}
  394.  
  395.  
  396.  
  397.    /**
  398.     * Sets the position of the label to the left side.
  399.     *
  400.     * @version 1.0
  401.     * @since   0.2.6
  402.     * @author  Daniel Plücken <daniel@debakel.net>
  403.     * @access  public
  404.     * @return  void 
  405.     */
  406.    function setLabelPositionLeft()
  407.    $this->label_position_right = false}
  408.  
  409.  
  410.  
  411.    /**
  412.     * Sets the onChange-Attribute of the checkbox.
  413.     *
  414.     * @version 1.1
  415.     * @since   0.1.5
  416.     * @author  Daniel Plücken <daniel@debakel.net>
  417.     * @access  public
  418.     * @param   string $formname 
  419.     * @return  string 
  420.     */
  421.    function setChangeOrder$string )
  422.    $this->mouseup = $string}
  423.  
  424.  
  425.  
  426.    /**
  427.     * Generates the sourcecode to build this object and returns it.
  428.     *
  429.     * @version 1.1
  430.     * @since   0.1.0
  431.     * @author  Daniel Plücken <daniel@debakel.net>
  432.     * @access  public
  433.     * @return  string 
  434.     */
  435.    function getPHPSource()
  436.    {
  437.       $outputstr  "unset( \x24checked );\n";
  438.       $outputstr .= "\x24checked = \x24_POST[\"".$this->getName()."\"]\n"
  439.                    ."          .\x24_GET[\"".$this->getName()."\"];\n";
  440.       $outputstr .= "\x24input[] = new HTMLCheckBox(\n"
  441.                    ."                              \"".$this->getName()."\",\n"
  442.                    ."                              \x24checked,\n"
  443.                    ."                              \"".$this->getLabel()."\"\n"
  444.                    ."                           );\n\n";
  445.  
  446.       if$this->checked )
  447.          $outputstr .= "if(\n"
  448.                       ."    !isset( \x24_POST[\"formsent\"] )\n"
  449.                       ." && !isset( \x24_GET[\"formsent\"] )\n"
  450.                       ."  )\n"
  451.                       ."  \x24input[count(\x24input)-1]->setChecked( true );\n\n";
  452.  
  453.       return $outputstr;
  454.    }
  455.  
  456.  
  457.  
  458.    /**
  459.     * Returns a generated string based on the attributes of this object.
  460.     *
  461.     * @version 1.52
  462.     * @since   0.1.0
  463.     * @author  Daniel Plücken <daniel@debakel.net>
  464.     * @access  public
  465.     * @return  string 
  466.     */
  467.    function get$forminput "" )
  468.    {
  469.       $this->idExists$this->idtrue );
  470.  
  471.       $out "";
  472.  
  473.       if (
  474.            !$this->label_position_right
  475.         && is_object$this->label_obj )
  476.          )
  477.          $out $this->label_obj->get();
  478.  
  479.       $out .= "<!--\r\n"
  480.              ."--><input type=\"checkbox\"\r\n"
  481.              ."          name=\"".$this->name."\"\r\n"
  482.              ."          id=\"".$this->id."\"\r\n"
  483.              ."          value=\"".$this->value."\"\r\n";
  484.  
  485.       $out .= !empty$this->style_class )
  486.               ? "          class=\"".$this->style_class."\"\r\n"
  487.               : "";
  488.       $out .= !empty$this->freestyle )
  489.               ? "          style=\"".$this->freestyle."\"\r\n"
  490.               : "";
  491.       $out .= !empty$this->blur )
  492.               ? "          onBlur=\"".$this->blur."\"\r\n"
  493.               : "";
  494.       $out .= !empty$this->focus )
  495.               ? "          onFocus=\"".$this->focus."\"\r\n"
  496.               : "";
  497.       $out .= !empty$this->click )
  498.               ? "          onClick=\"".$this->click."\"\r\n"
  499.               : "";
  500.       $out .= !empty$this->mouseup )
  501.               ? "          onMouseup=\"".$this->mouseup."\"\r\n"
  502.               : "";
  503.       $out .= !empty$this->mouseover )
  504.               ? "          onMouseover=\"".$this->mouseover."\"\r\n"
  505.               : "";
  506.       $out .= !empty$this->mouseout )
  507.               ? "          onMouseout=\"".$this->mouseout."\"\r\n"
  508.               : "";
  509.       $out .= !empty$this->mousemove )
  510.               ? "          onMousemove=\"".$this->mousemove."\"\r\n"
  511.               : "";
  512.  
  513.       if (
  514.            $forminput == "POST"
  515.         || $forminput == "GET"
  516.         || $forminput == "REQUEST"
  517.          )
  518.          $out .= "<?php if ( \x24_".$forminput."['".$this->name."'] ) "
  519.                          ."echo ' checked'; ?>";
  520.       else
  521.          $out .= $this->checked
  522.                  ? "          checked=\"checked\"\r\n"
  523.                  : "";
  524.  
  525.       $out .= (
  526.                  $this->enabled
  527.               && $this->manipulateable
  528.               )
  529.               ? ""
  530.               : "          disabled=\"disabled\"\r\n";
  531.       $out .= "   />".(
  532.                          $this->label_position_right
  533.                       && is_object$this->label_obj )
  534.                          ? $this->label_obj->get()
  535.                          : ""
  536.                       );
  537.  
  538.       return $out;
  539.    }
  540. // END of class HTMLCheckBox
  541. ?>

Documentation generated on Thu, 05 Jun 2008 19:12:01 +0200 by phpDocumentor 1.4.1