2 // +----------------------------------------------------------------------+
 
   3 // | Anuko Time Tracker
 
   4 // +----------------------------------------------------------------------+
 
   5 // | Copyright (c) Anuko International Ltd. (https://www.anuko.com)
 
   6 // +----------------------------------------------------------------------+
 
   7 // | LIBERAL FREEWARE LICENSE: This source code document may be used
 
   8 // | by anyone for any purpose, and freely redistributed alone or in
 
   9 // | combination with other software, provided that the license is obeyed.
 
  11 // | There are only two ways to violate the license:
 
  13 // | 1. To redistribute this code in source form, with the copyright
 
  14 // |    notice or license removed or altered. (Distributing in compiled
 
  15 // |    forms without embedded copyright notices is permitted).
 
  17 // | 2. To redistribute modified versions of this code in *any* form
 
  18 // |    that bears insufficient indications that the modifications are
 
  19 // |    not the work of the original author(s).
 
  21 // | This license applies to this document only, not any other software
 
  22 // | that it may be combined with.
 
  24 // +----------------------------------------------------------------------+
 
  26 // | https://www.anuko.com/time_tracker/credits.htm
 
  27 // +----------------------------------------------------------------------+
 
  29 // +----------------------------------------------------------------------+
 
  31 // | Class generates elements of specification HTML 4.01
 
  32 // | http://www.w3.org/TR/1999/REC-html401-19991224
 
  34 // +----------------------------------------------------------------------+
 
  39   // TODO: refactoring ongoing down from here.
 
  44         var $mElements     = array();
 
  47     function __construct($formid) {
 
  48         $this->name = $formid;
 
  51     function setRequest(&$request) {
 
  52         $this->mRequest = &$request;
 
  55     function &getElement($name) {
 
  56         return $this->mElements[$name];
 
  59     function &getElements() {
 
  60         return $this->mElements;
 
  66         // enctype - enctype="multipart/form-data"
 
  70         function setName($value) { $this->name = $value; }
 
  71     function getName() { return $this->name; }
 
  73     function setId($value) { $this->mId = $value; }
 
  74     function getId() { return $this->mId; }
 
  77         if (!isset($this->mRequest)) return false;
 
  79             foreach ($this->mElements as $el) {
 
  80                 if (strtolower(get_class($el))=="submit") {
 
  81                     $name = $el->getName();
 
  82                     $value = $this->mRequest->getAttribute($name);
 
  91         function OutputError($error,$scope="")
 
  93                 $this->error=(strcmp($scope,"") ? $scope.": ".$error : $error);
 
  94                 if(strcmp($function=$this->debugFunction,"")
 
  95                 && strcmp($this->error,""))
 
  96                         $function($this->error);
 
 101         // type = TEXT | PASSWORD | CHECKBOX | RADIO | SUBMIT | RESET | FILE | HIDDEN | IMAGE | BUTTON
 
 104         // checked - for type radio and checkbox
 
 105         // size - width pixels or chars
 
 107         // src - for type image
 
 108         // tabindex - support  A, AREA, BUTTON, INPUT, OBJECT, SELECT, and TEXTAREA
 
 109         // accesskey - support A, AREA, BUTTON, INPUT, LABEL, and LEGEND, and TEXTAREA
 
 112         // onselect -  INPUT and TEXTAREA
 
 114         function addInput($arguments) {
 
 115                 if(strcmp(gettype($arguments),"array"))
 
 116                         $this->OutputError("arguments must be array","AddInput");
 
 118                 if(!isset($arguments["type"]) || !strcmp($arguments["type"],""))
 
 119                         return($this->OutputError("Type not defined","AddInput"));
 
 121                 if(!isset($arguments["name"]) || !strcmp($arguments["name"],""))
 
 122                         return($this->OutputError("Name of element not defined","AddInput"));
 
 124                 if (isset($this->mElements[$arguments["name"]]))
 
 125                     return($this->OutputError("it was specified '".$arguments["name"]."' name of an already defined input","AddInput"));
 
 127                 switch($arguments["type"]) {
 
 131                             import('form.TextField');
 
 132                             $el = new TextField($arguments["name"]);
 
 133                             $el->setMaxLength(@$arguments["maxlength"]);
 
 134                             if (isset($arguments["aspassword"])) $el->setAsPassword($arguments["aspassword"]);
 
 138                             import('form.DateField');
 
 139                             $el = new DateField($arguments["name"]);
 
 140                                 $el->setMaxLength("10");
 
 144                             import('form.FloatField');
 
 145                             $el = new FloatField($arguments["name"]);
 
 146                             if (isset($arguments["format"])) $el->setFormat($arguments["format"]);
 
 150                             import('form.TextArea');
 
 151                             $el = new TextArea($arguments["name"]);
 
 152                             $el->setColumns(@$arguments["cols"]);
 
 153                             $el->setRows(@$arguments["rows"]);
 
 154                             if (isset($arguments["maxlength"])) $el->setMaxLength($arguments["maxlength"]);
 
 158                             import('form.Checkbox');
 
 159                             $el = new Checkbox($arguments["name"]);
 
 160                             if (@$arguments["checked"]) $el->setChecked(true);
 
 161                             $el->setData(@$arguments["data"]);
 
 164                         case "checkboxgroup":
 
 165                             import('form.CheckboxGroup');
 
 166                             $el = new CheckboxGroup($arguments["name"]);
 
 167                             if (isset($arguments["layout"])) $el->setLayout($arguments["layout"]);
 
 168                             if (isset($arguments["groupin"])) $el->setGroupIn($arguments["groupin"]);
 
 169                             if (isset($arguments["datakeys"])) $el->setDataKeys($arguments["datakeys"]);
 
 170                             $el->setData(@$arguments["data"]);
 
 174                             import('form.Combobox');
 
 175                             $el = new Combobox($arguments["name"]);
 
 176                             $el->setData(@$arguments["data"]);
 
 177                             $el->setDataDefault(@$arguments["empty"]);
 
 178                             if (isset($arguments["datakeys"])) $el->setDataKeys($arguments["datakeys"]);
 
 182                             import('form.Hidden');
 
 183                             $el = new Hidden($arguments["name"]);
 
 187                             import('form.Submit');
 
 188                             $el = new Submit($arguments["name"]);
 
 192                             import('form.Calendar');
 
 193                             $el = new Calendar($arguments["name"]);
 
 194                             $el->setHighlight(@$arguments["highlight"]);
 
 198                             import('form.Table');
 
 199                             $el = new Table($arguments["name"]);
 
 200                             $el->setData(@$arguments["data"]);
 
 201                             $el->setWidth(@$arguments["width"]);
 
 205                             import('form.UploadFile');
 
 206                             $el = new UploadFile($arguments["name"]);
 
 207                             if (isset($arguments["maxsize"])) $el->setMaxSize($arguments["maxsize"]);
 
 211                                 return($this->OutputError("Type not found for input element","AddInput"));
 
 214                         $el->setFormName($this->name);
 
 215                         if (isset($arguments["id"])) $el->setId($arguments["id"]);
 
 216                         if (isset($GLOBALS["I18N"])) $el->setLocalization($GLOBALS["I18N"]);
 
 217                         if (isset($arguments["render"])) $el->setRenderable($arguments["render"]);
 
 218                         if (isset($arguments["enable"])) $el->setEnable($arguments["enable"]);
 
 220                         if (isset($arguments["style"])) $el->setStyle($arguments["style"]);
 
 221                         if (isset($arguments["size"])) $el->setSize($arguments["size"]);
 
 223                         if (isset($arguments["label"])) $el->setLabel($arguments["label"]);
 
 224                         if (isset($arguments["value"])) $el->setValue($arguments["value"]);
 
 226                         if (isset($arguments["onchange"])) $el->setOnChange($arguments["onchange"]);
 
 227                         if (isset($arguments["onclick"])) $el->setOnClick($arguments["onclick"]);
 
 229                         $this->mElements[$arguments["name"]] = &$el;
 
 233         function addInputElement(&$el) {
 
 234                 if ($el && is_object($el)) {
 
 236                             return($this->OutputError("no name in element","addInputElement"));
 
 238                         if (isset($GLOBALS["I18N"])) $el->setLocalization($GLOBALS["I18N"]);
 
 240                         $el->setFormName($this->name);
 
 241                         $this->mElements[$el->getName()] = &$el;
 
 246         function toStringOpenTag() {
 
 247         $html = "<form name=\"$this->name\"";
 
 250             $html .= " id=\"$this->mId\"";
 
 252         $html .= ' method="post"';
 
 254         // Add enctype for file upload forms.
 
 255         foreach ($this->mElements as $elname=>$el) {
 
 256             if (strtolower(get_class($this->mElements[$elname])) == 'uploadfile') {
 
 257                 $html .= ' enctype="multipart/form-data"';
 
 266     function toStringCloseTag() {
 
 268         foreach ($this->mElements as $elname=>$el) {
 
 269             if (strtolower(get_class($this->mElements[$elname]))=="hidden") {
 
 270                 $html .= $this->mElements[$elname]->toStringControl()."\n";
 
 279         $vars['open'] = $this->toStringOpenTag();
 
 280         $vars['close'] = $this->toStringCloseTag();
 
 282         foreach ($this->mElements as $elname=>$el) {
 
 283             if (is_object($this->mElements[$elname])) 
 
 284                 $vars[$elname] = $this->mElements[$elname]->toArray();
 
 290     function getValueByElement($elname) {
 
 291         return $this->mElements[$elname]->getValue();
 
 294     function setValueByElement($elname, $value) {
 
 295         if (isset($this->mElements[$elname])) {
 
 296                 $this->mElements[$elname]->setValue($value);