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

Source for file checklst.inc.php

Documentation is available at checklst.inc.php

  1. <?php
  2. /**
  3. *  This file is part of the VCL for PHP project
  4. *
  5. *  Copyright (c) 2004-2007 qadram software <support@qadram.com>
  6. *
  7. *  Checkout AUTHORS file for more information on the developers
  8. *
  9. *  This library is free software; you can redistribute it and/or
  10. *  modify it under the terms of the GNU Lesser General Public
  11. *  License as published by the Free Software Foundation; either
  12. *  version 2.1 of the License, or (at your option) any later version.
  13. *
  14. *  This library is distributed in the hope that it will be useful,
  15. *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17. *  Lesser General Public License for more details.
  18. *
  19. *  You should have received a copy of the GNU Lesser General Public
  20. *  License along with this library; if not, write to the Free Software
  21. *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  22. *  USA
  23. *
  24. */
  25.  
  26. use_unit("controls.inc.php");
  27. use_unit("stdctrls.inc.php");
  28.  
  29. /**
  30.  * CheckListBox Class
  31.  *
  32.  * A list with checks at the left
  33.  */
  34. {
  35.         protected $_items = array();
  36.         protected $_borderstyle = bsSingle;
  37.         protected $_borderwidth="1";
  38.         protected $_bordercolor="#CCCCCC";
  39.  
  40.         protected $_onclick = null;
  41.         protected $_onsubmit = null;
  42.  
  43. //        protected $_datasource = null;
  44. //        protected $_datafield = "";
  45.         
  46.         protected $_taborder=0;
  47.         protected $_tabstop=1;
  48.  
  49.         function __construct($aowner null)
  50.         {
  51.                 //Calls inherited constructor
  52.                 parent::__construct($aowner);
  53.  
  54.                 $this->Clear();
  55.  
  56.                 $this->Width 185;
  57.                 $this->Height 89;
  58.  
  59.                 $this->ControlStyle="csRenderOwner=1";
  60.                 $this->ControlStyle="csRenderAlso=StyleSheet";
  61.         }
  62.  
  63.         function loaded()
  64.         {
  65.                 parent::loaded();
  66. //                $this->writeDataSource($this->_datasource);
  67.         }
  68.  
  69.         function preinit()
  70.         {
  71.                 $submitted $this->input->{$this->Name};
  72.  
  73.                 if (is_object($submitted))
  74.                 {
  75. //                        $changed = ($this->_itemindex != $submitted->asString());
  76. //                        // the ItemIndex might be an integer or a string,
  77. //                        // so let's get a string
  78. //                        $this->_itemindex = $submitted->asString();
  79. //
  80. //                        // only update the data field if the item index was changed
  81. //                        if ($changed)
  82. //                        {
  83. //                                // following somehow does not work here:
  84. //                                //   if (array_key_exists($this->_itemindex, $this->_items)) { $this->updateDataField($this->_items[$this->_itemindex]); }
  85. //                                // so let's do it like this...
  86. //                                foreach ($this->_items as $key => $item)
  87. //                                {
  88. //                                        if ($key == $this->_itemindex)
  89. //                                        {
  90. //                                                //If there is any valid DataField attached, update it
  91. //                                                $this->updateDataField($item);
  92. //                                        }
  93. //                                }
  94. //                        }
  95.                 }
  96.         }
  97.  
  98.         function init()
  99.         {
  100.                 parent::init();
  101.  
  102.                 $submitted $this->input->{$this->Name};
  103.  
  104.                 if (is_object($submitted))
  105.                 {
  106.                         // Allow the OnSubmit event to be fired because it is not
  107.                         // a mouse or keyboard event.
  108.                         if ($this->_onsubmit != null)
  109.                         {
  110.                                 $this->callEvent('onsubmit'array());
  111.                         }
  112.                 }
  113.  
  114.                 $submitEvent $this->input->{$this->getJSWrapperHiddenFieldName()};
  115.  
  116.                 if (is_object($submitEvent&& $this->_enabled == 1)
  117.                 {
  118.                         // check if the a click event has been fired
  119.                         
  120.                         if ($this->_onclick != null && $submitEvent->asString(== $this->getJSWrapperSubmitEventValue($this->_onclick))
  121.                         {
  122.                                 $this->callEvent('onclick'array());
  123.                         }
  124.                 }
  125.         }
  126.  
  127.  
  128.         function dumpContents()
  129.         {
  130.                 $events "";
  131.                 if ($this->_enabled == 1)
  132.                 {
  133.                         // get the string for the JS Events
  134.                         $events $this->readJsEvents();
  135.  
  136.                         // add or replace the JS events with the wrappers if necessary
  137.                         $this->addJSWrapperToEvents($events$this->_onclick,    $this->_jsonclick,    "onclick");
  138.                 }
  139.  
  140.                 if ($this->_borderstyle == bsNone )
  141.                 {       $border ""}
  142.                 else
  143.                 {       $border "solid"}
  144.                 if ($this->_borderwidth !=="")
  145.                 {       $border .= " " $this->_borderwidth "px"}
  146.                 if ($this->_bordercolor !=="")
  147.                 {       $border .= " " $this->_bordercolor}
  148.                 if ($border != "")
  149.                 {       $border "border: " $border ";"}
  150.  
  151.                 $class ($this->Style != """class=\"$this->StyleClass\""";
  152.  
  153.                 echo "  <DIV style=\"OVERFLOW-Y:autoWIDTH:{$this->Width}pxHEIGHT:{$this->Height}px$border\" $class>\n";
  154.  
  155.                 $style="";
  156.                 if ($this->Style=="")
  157.                 {
  158.                         // get the Font attributes
  159.                         $style .= $this->Font->FontString;
  160.  
  161.                         if ($this->Color != "")
  162.                         $style  .= "background-color: " $this->Color . ";"}
  163.  
  164.                         // add the cursor to the style
  165.                         if ($this->_cursor != "")
  166.                         {
  167.                                 $cr strtolower(substr($this->_cursor2));
  168.                                 $style .= "cursor$cr;";
  169.                         }
  170.                 }
  171.  
  172.                 $spanstyle $style;
  173.  
  174.                 // set enabled/disabled status
  175.                 $enabled (!$this->_enabled"disabled=\"disabled\"" "";
  176.  
  177.                 // set tab order if tab stop set to true
  178.                 $taborder ($this->_tabstop == 1"tabindex=\"$this->_taborder\""";
  179.  
  180.                 // get the hint attribute; returns: title="[HintText]"
  181.                 $hint $this->getHintAttribute();
  182.  
  183.                 if ($style != ""$style "style=\"$style\"";
  184.                 if ($spanstyle != ""$spanstyle "style=\"$spanstyle\"";
  185.  
  186.                 // get the alignment of the Items
  187.                 switch ($this->_alignment)
  188.                 {
  189.                         case agNone   $alignment ""break;
  190.                         case agLeft   $alignment "align=\"Left\""break;
  191.                         case agCenter $alignment "align=\"Center\""break;
  192.                         case agRight  $alignment "align=\"Right\""break;
  193.                         default       $alignment ""break;
  194.                 }
  195.  
  196. //                if (($this->ControlState & csDesigning) != csDesigning)
  197. //                {
  198. //                        if ($this->hasValidDataField())
  199. //                        {
  200. //                                //check if the value of the current data-field is in the itmes array as value
  201. //                                $val = $this->readDataFieldValue();
  202. //
  203. //                                //Dumps hidden fields to know which is the record to update
  204. //                                $this->dumpHiddenKeyFields();
  205. //                        }
  206. //                }
  207.  
  208.                 // call the OnShow event if assigned so the Items property can be changed
  209.                 if ($this->_onshow != null$this->callEvent('onshow'array());
  210.  
  211.                 echo "    <table cellpadding=\"0\" cellspacing=\"0\" $style $class>";
  212.                 if (is_array($this->_items))
  213.                 {
  214.                         // $index is used to call the JS CheckListBox function
  215.                         $index 0;
  216.                         foreach ($this->_items as $key => $item)
  217.                         {
  218.                                 // add the checked attribut if the itemindex is the current item
  219. //                                $checked = ($this->_itemindex == $key) ? "checked=\"checked\"" : "";
  220.                                 // only allow an OnClick if enabled
  221.                                 $itemclick ($this->_enabled == && $this->Owner != null"onclick=\"return CheckListBoxClick('$this->Name"_" $index "', $index);\""";
  222.  
  223.                                 $element $this->Name . "_" $key;
  224.                                 // add a new row for every item
  225.                                 echo "    <tr>\n";
  226.                                 echo "      <td width=\"20\"><input ID=\"$element\" type=\"checkbox\" name=\"$this->Name\" value=\"$key\" $events $enabled $taborder $hint $class /></td>\n";
  227.                                 echo "      <td $alignment><span ID=\"$element\" $itemclick $hint $spanstyle $class>$item</span></td>\n";
  228.                                 echo "    </tr>\n";
  229.                                 $index++;
  230.                         }
  231.                 }
  232.                 echo "    </table>\n";
  233.                 echo "  </DIV>";
  234.  
  235.                 // add a hidden field so we can determine which radiogroup fired the event
  236.                 if ($this->_onclick != null)
  237.                 {
  238.                         echo "\n";
  239.                         echo "<input type=\"hidden\" name=\"".$this->getJSWrapperHiddenFieldName()."\" value=\"\" />";
  240.                 }
  241.         }
  242.  
  243.         /*
  244.         * Write the Javascript section to the header
  245.         */
  246.         function dumpJavascript()
  247.         {
  248.                 parent::dumpJavascript();
  249.  
  250.                 if ($this->_enabled == 1)
  251.                 {
  252.                         if ($this->_onclick != null && !defined($this->_onclick))
  253.                         {
  254.                                 // only output the same function once;
  255.                                 // otherwise if for example two radio groups use the same
  256.                                 // OnClick event handler it would be outputted twice.
  257.                                 $def=$this->_onclick;
  258.                                 define($def,1);
  259.  
  260.                                 // output the wrapper function
  261.                                 echo $this->getJSWrapperFunction($this->_onclick);
  262.                         }
  263.  
  264.                         // only output the function once
  265.                         if (!defined('CheckListBoxClick'))
  266.                         {
  267.                                 define('CheckListBoxClick'1);
  268.  
  269.                                 echo "function CheckListBoxClick(name, index)\n";
  270.                                 echo "{\n";
  271.                                 echo "  var event = event || window.event;\n";
  272.                                 echo "  var obj=document.getElementById(name);\n";
  273.                                 echo "  if (obj) {\n";
  274.                                 echo "    if (!obj.disabled) {\n";
  275.                                 echo "      obj.checked = !obj.checked;\n";
  276.                                 echo "      return obj.onclick();\n";
  277.                                 echo "    }\n";
  278.                                 echo "  }\n";
  279.                                 echo "  return false;\n";
  280.                                 echo "}\n";
  281.                         }
  282.                 }
  283.         }
  284.  
  285.         /**
  286.         * Adds an item to the radio group control.
  287.         * @param mixed $item Value of item to add.
  288.         * @param mixed $itemkey Key of the item in the array. Default key is used if null.
  289.         * @return integer Return the number of items in the list.
  290.         */
  291.         function AddItem($item$itemkey null)
  292.         {
  293.                 end($this->_items);     //Set the array to the end
  294.                 if ($itemkey != null)   //Adds the item at specified position
  295.                 {
  296.                         $this->_items[$itemkey$item;
  297.                 }
  298.                 else                    //Adds the item as the last one
  299.                 {
  300.                         $this->_items[$item;
  301.                 }
  302.                 return($this->Count);
  303.         }
  304.  
  305.         /**
  306.         * Deletes all of the items from the list control.
  307.         */
  308.         function Clear()
  309.         {
  310.                 $this->_items array();
  311.         }
  312.  
  313.         /**
  314.         * Return the number of itmes in the radio group.
  315.         * @return integer 
  316.         */
  317.         function readCount()                    return count($this->_items)}
  318.         /**
  319.          * Specifies Border width used to display a control
  320.          * @return integer 
  321.          */
  322.         function readBorderWidth()              return $this->_borderwidth}
  323.         function writeBorderWidth($value)       $this->_borderwidth=$value}
  324.         function defaultBorderWidth()           return 1}
  325.         /**
  326.          * Specifies Border color used to display a control
  327.          * @return hex color value
  328.          */
  329.         function readBorderColor()              return $this->_bordercolor}
  330.         function writeBorderColor($value)       $this->_bordercolor=$value}
  331.         function defaultBorderColor()           return "#CCCCCC"}
  332.         /**
  333.          * Specifies Border Style used to display a control
  334.          * @return enum (bsSingle, bsNone)
  335.          */
  336.         function readBorderStyle()              return $this->_borderstyle}
  337.         function writeBorderStyle($value)       $this->_borderstyle=$value}
  338.         function defaultBorderStyle()           return bsSingle}
  339.         /**
  340.         * Occurs when the user clicks the control.
  341.         * @return mixed Returns the event handler or null if no handler is set.
  342.         */
  343.         function readOnClick()                  return $this->_onclick}
  344.         /**
  345.         * Occurs when the user clicks the control.
  346.         * @param mixed Event handler or null if no handler is set.
  347.         */
  348.         function writeOnClick($value)           $this->_onclick $value}
  349.         function defaultOnClick()               return null}
  350.  
  351.         /**
  352.         * Occurs when the control was submitted.
  353.         * @return mixed Returns the event handler or null if no handler is set.
  354.         */
  355.         function readOnSubmit()                 return $this->_onsubmit}
  356.         /**
  357.         * Occurs when the control was submitted.
  358.         * @param mixed Event handler or null if no handler is set.
  359.         */
  360.         function writeOnSubmit($value)          $this->_onsubmit=$value}
  361.         function defaultOnSubmit()              return null}
  362.  
  363. //        function readDataField()              { return $this->_datafield; }
  364. //        function writeDataField($value)       { $this->_datafield = $value; }
  365. //        function defaultDataField()           { return ""; }
  366.  
  367. //        function readDataSource()             { return $this->_datasource; }
  368. //        function writeDataSource($value)      { $this->_datasource = $this->fixupProperty($value); }
  369. //        function defaultDataSource()          { return null; }
  370.  
  371.         
  372.  
  373.         /**
  374.         * Contains the strings that appear in the radio group.
  375.         * @return array 
  376.         */
  377.         function readItems()                    return $this->_items}
  378.         /**
  379.         * Contains the strings that appear in the radio group.
  380.         * @param array $value 
  381.         */
  382.         function writeItems($value)
  383.         {
  384.                 if (is_array($value)) $this->_items $value}
  385.                 else  $this->_items (empty($value)) array(array($value)}
  386.         }
  387.         function defaultItems()                 return array()}
  388.  
  389.         /**
  390.         * TabOrder indicates in which order controls are access when using
  391.         * the Tab key.
  392.         * The value of the TabOrder can be between 0 and 32767.
  393.         * @return integer 
  394.         */
  395.         function readTabOrder()                 return $this->_taborder}
  396.         /**
  397.         * TabOrder indicates in which order controls are access when using
  398.         * the Tab key.
  399.         * The value of the TabOrder can be between 0 and 32767.
  400.         * @param integer $value 
  401.         */
  402.         function writeTabOrder($value)          $this->_taborder=$value}
  403.         function defaultTabOrder()              return 0}
  404.  
  405.         /**
  406.         * Enable or disable the TabOrder property. The browser may still assign
  407.         * a TabOrder by itself internally. This cannot be controlled by HTML.
  408.         * @return bool 
  409.         */
  410.         function readTabStop()                  return $this->_tabstop}
  411.         /**
  412.         * Enable or disable the TabOrder property. The browser may still assign
  413.         * a TabOrder by itself internally. This cannot be controlled by HTML.
  414.         * @param bool $value 
  415.         */
  416.         function writeTabStop($value)           $this->_tabstop=$value}
  417.         function defaultTabStop()               return 1}
  418. }
  419.  
  420. /**
  421. * CheckListBox represents a group of checkboxes that function together.
  422. *
  423. */
  424. {
  425.         /*
  426.         * Publish the events for the CheckBox component
  427.         */
  428.         function getOnClick()                   return $this->readOnClick()}
  429.         function setOnClick($value)             $this->writeOnClick($value)}
  430.  
  431.         function getOnSubmit()                  return $this->readOnSubmit()}
  432.         function setOnSubmit($value)            $this->writeOnSubmit($value)}
  433.  
  434.         /*
  435.         * Publish the JS events for the CheckBox component
  436.         */
  437.         function getjsOnBlur()                  return $this->readjsOnBlur()}
  438.         function setjsOnBlur($value)            $this->writejsOnBlur($value)}
  439.  
  440.         function getjsOnChange()                return $this->readjsOnChange()}
  441.         function setjsOnChange($value)          $this->writejsOnChange($value)}
  442.  
  443.         function getjsOnClick()                 return $this->readjsOnClick()}
  444.         function setjsOnClick($value)           $this->writejsOnClick($value)}
  445.  
  446.         function getjsOnDblClick()              return $this->readjsOnDblClick()}
  447.         function setjsOnDblClick($value)        $this->writejsOnDblClick($value)}
  448.  
  449.         function getjsOnFocus()                 return $this->readjsOnFocus()}
  450.         function setjsOnFocus($value)           $this->writejsOnFocus($value)}
  451.  
  452.         function getjsOnMouseDown()             return $this->readjsOnMouseDown()}
  453.         function setjsOnMouseDown($value)       $this->writejsOnMouseDown($value)}
  454.  
  455.         function getjsOnMouseUp()               return $this->readjsOnMouseUp()}
  456.         function setjsOnMouseUp($value)         $this->writejsOnMouseUp($value)}
  457.  
  458.         function getjsOnMouseOver()             return $this->readjsOnMouseOver()}
  459.         function setjsOnMouseOver($value)       $this->writejsOnMouseOver($value)}
  460.  
  461.         function getjsOnMouseMove()             return $this->readjsOnMouseMove()}
  462.         function setjsOnMouseMove($value)       $this->writejsOnMouseMove($value)}
  463.  
  464.         function getjsOnMouseOut()              return $this->readjsOnMouseOut()}
  465.         function setjsOnMouseOut($value)        $this->writejsOnMouseOut($value)}
  466.  
  467.         function getjsOnKeyPress()              return $this->readjsOnKeyPress()}
  468.         function setjsOnKeyPress($value)        $this->writejsOnKeyPress($value)}
  469.  
  470.         function getjsOnKeyDown()               return $this->readjsOnKeyDown()}
  471.         function setjsOnKeyDown($value)         $this->writejsOnKeyDown($value)}
  472.  
  473.         function getjsOnKeyUp()                 return $this->readjsOnKeyUp()}
  474.         function setjsOnKeyUp($value)           $this->writejsOnKeyUp($value)}
  475.  
  476.         /*
  477.         * Publish the properties for the CheckBox component
  478.         */
  479.  
  480.         function getAlignment()                 return $this->readAlignment()}
  481.         function setAlignment($value)           $this->writeAlignment($value)}
  482.  
  483.         function getBorderWidth()               return $this->readBorderWidth()}
  484.         function setBorderWidth($value)         $this->writeBorderWidth($value)}
  485.  
  486.         function getBorderColor()               return $this->readBorderColor()}
  487.         function setBorderColor($value)         $this->writeBorderColor($value)}
  488.  
  489.         function getBorderStyle()               return $this->readBorderStyle()}
  490.         function setBorderStyle($value)         $this->writeBorderStyle($value)}
  491.  
  492.         function getColor()                     return $this->readColor()}
  493.         function setColor($value)               $this->writeColor($value)}
  494.  
  495. //        function getDataField()                 { return $this->readDataField(); }
  496. //        function setDataField($value)           { $this->writeDataField($value); }
  497.  
  498. //        function getDataSource()                { return $this->readDataSource(); }
  499. //        function setDataSource($value)          { $this->writeDataSource($value); }
  500.  
  501.         
  502.  
  503.         function getEnabled()                   return $this->readEnabled()}
  504.         function setEnabled($value)             $this->writeEnabled($value)}
  505.  
  506.         function getFont()                      return $this->readFont()}
  507.         function setFont($value)                $this->writeFont($value)}
  508.  
  509.         function getItems()                     return $this->readItems()}
  510.         function setItems($value)               $this->writeItems($value)}
  511.  
  512.         function getParentColor()               return $this->readParentColor()}
  513.         function setParentColor($value)         $this->writeParentColor($value)}
  514.  
  515.         function getParentFont()                return $this->readParentFont()}
  516.         function setParentFont($value)          $this->writeParentFont($value)}
  517.  
  518.         function getParentShowHint()            return $this->readParentShowHint()}
  519.         function setParentShowHint($value)      $this->writeParentShowHint($value)}
  520.  
  521.         function getPopupMenu()                 return $this->readPopupMenu()}
  522.         function setPopupMenu($value)           $this->writePopupMenu($value)}
  523.  
  524.         function getShowHint()                  return $this->readShowHint()}
  525.         function setShowHint($value)            $this->writeShowHint($value)}
  526.  
  527.         function getStyle()                     return $this->readstyle()}
  528.         function setStyle($value)               $this->writestyle($value)}
  529.  
  530.         function getTabOrder()                  return $this->readTabOrder()}
  531.         function setTabOrder($value)            $this->writeTabOrder($value)}
  532.  
  533.         function getTabStop()                   return $this->readTabStop()}
  534.         function setTabStop($value)             $this->writeTabStop($value)}
  535.  
  536.         function getVisible()                   return $this->readVisible()}
  537.         function setVisible($value)             $this->writeVisible($value)}
  538. }
  539.  
  540. ?>

Documentation generated on Tue, 27 Mar 2007 13:33:25 +0200 by phpDocumentor 1.3.1