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.
45 var $mElements = array();
48 function __construct($formid) {
49 $this->name = $formid;
52 function setRequest(&$request) {
53 $this->mRequest = &$request;
56 function &getElement($name) {
57 return $this->mElements[$name];
60 function &getElements() {
61 return $this->mElements;
67 // enctype - enctype="multipart/form-data"
71 function setName($value) { $this->name = $value; }
72 function getName() { return $this->name; }
74 function setId($value) { $this->mId = $value; }
75 function getId() { return $this->mId; }
78 if (!isset($this->mRequest)) return false;
80 foreach ($this->mElements as $el) {
81 if (strtolower(get_class($el))=="submit") {
82 $name = $el->getName();
83 $value = $this->mRequest->getAttribute($name);
92 function OutputError($error,$scope="")
94 $this->error=(strcmp($scope,"") ? $scope.": ".$error : $error);
95 if(strcmp($function=$this->debugFunction,"")
96 && strcmp($this->error,""))
97 $function($this->error);
102 // type = TEXT | PASSWORD | CHECKBOX | RADIO | SUBMIT | RESET | FILE | HIDDEN | IMAGE | BUTTON
105 // checked - for type radio and checkbox
106 // size - width pixels or chars
108 // src - for type image
109 // tabindex - support A, AREA, BUTTON, INPUT, OBJECT, SELECT, and TEXTAREA
110 // accesskey - support A, AREA, BUTTON, INPUT, LABEL, and LEGEND, and TEXTAREA
113 // onselect - INPUT and TEXTAREA
115 function addInput($arguments) {
116 if(strcmp(gettype($arguments),"array"))
117 $this->OutputError("arguments must be array","AddInput");
119 if(!isset($arguments["type"]) || !strcmp($arguments["type"],""))
120 return($this->OutputError("Type not defined","AddInput"));
122 if(!isset($arguments["name"]) || !strcmp($arguments["name"],""))
123 return($this->OutputError("Name of element not defined","AddInput"));
125 if (isset($this->mElements[$arguments["name"]]))
126 return($this->OutputError("it was specified '".$arguments["name"]."' name of an already defined input","AddInput"));
128 switch($arguments["type"]) {
132 import('form.TextField');
133 $el = new TextField($arguments["name"]);
134 $el->setMaxLength(@$arguments["maxlength"]);
135 if (isset($arguments["aspassword"])) $el->setAsPassword($arguments["aspassword"]);
139 import('form.DateField');
140 $el = new DateField($arguments["name"]);
141 $el->setMaxLength("10");
145 import('form.FloatField');
146 $el = new FloatField($arguments["name"]);
147 if (isset($arguments["format"])) $el->setFormat($arguments["format"]);
151 import('form.TextArea');
152 $el = new TextArea($arguments["name"]);
153 $el->setColumns(@$arguments["cols"]);
154 $el->setRows(@$arguments["rows"]);
155 if (isset($arguments["maxlength"])) $el->setMaxLength($arguments["maxlength"]);
159 import('form.Checkbox');
160 $el = new Checkbox($arguments["name"]);
161 if (@$arguments["checked"]) $el->setChecked(true);
162 $el->setData(@$arguments["data"]);
165 case "checkboxgroup":
166 import('form.CheckboxGroup');
167 $el = new CheckboxGroup($arguments["name"]);
168 if (isset($arguments["layout"])) $el->setLayout($arguments["layout"]);
169 if (isset($arguments["groupin"])) $el->setGroupIn($arguments["groupin"]);
170 if (isset($arguments["datakeys"])) $el->setDataKeys($arguments["datakeys"]);
171 $el->setData(@$arguments["data"]);
175 import('form.Combobox');
176 $el = new Combobox($arguments["name"]);
177 $el->setData(@$arguments["data"]);
178 $el->setDataDefault(@$arguments["empty"]);
179 if (isset($arguments["datakeys"])) $el->setDataKeys($arguments["datakeys"]);
183 import('form.Hidden');
184 $el = new Hidden($arguments["name"]);
188 import('form.Submit');
189 $el = new Submit($arguments["name"]);
193 import('form.Calendar');
194 $el = new Calendar($arguments["name"]);
195 $el->setHighlight(@$arguments["highlight"]);
199 import('form.Table');
200 $el = new Table($arguments["name"]);
201 $el->setData(@$arguments["data"]);
202 $el->setWidth(@$arguments["width"]);
206 import('form.UploadFile');
207 $el = new UploadFile($arguments["name"]);
208 if (isset($arguments["maxsize"])) $el->setMaxSize($arguments["maxsize"]);
212 return($this->OutputError("Type not found for input element","AddInput"));
215 $el->setFormName($this->name);
216 if (isset($arguments["id"])) $el->setId($arguments["id"]);
217 if (isset($GLOBALS["I18N"])) $el->setLocalization($GLOBALS["I18N"]);
218 if (isset($arguments["render"])) $el->setRenderable($arguments["render"]);
219 if (isset($arguments["enable"])) $el->setEnable($arguments["enable"]);
221 if (isset($arguments["style"])) $el->setStyle($arguments["style"]);
222 if (isset($arguments["size"])) $el->setSize($arguments["size"]);
224 if (isset($arguments["label"])) $el->setLabel($arguments["label"]);
225 if (isset($arguments["value"])) $el->setValue($arguments["value"]);
227 if (isset($arguments["onchange"])) $el->setOnChange($arguments["onchange"]);
228 if (isset($arguments["onclick"])) $el->setOnClick($arguments["onclick"]);
230 $this->mElements[$arguments["name"]] = &$el;
234 function addInputElement(&$el) {
235 if ($el && is_object($el)) {
237 return($this->OutputError("no name in element","addInputElement"));
239 if (isset($GLOBALS["I18N"])) $el->setLocalization($GLOBALS["I18N"]);
241 $el->setFormName($this->name);
242 $this->mElements[$el->getName()] = &$el;
247 function toStringOpenTag() {
248 $html = "<form name=\"$this->name\"";
251 $html .= " id=\"$this->mId\"";
253 $html .= ' method="post"';
256 foreach ($this->mElements as $elname=>$el) {
257 if (strtolower(get_class($this->mElements[$elname]))=="uploadfile") {
258 $this->mEnctype = "multipart/form-data";
262 if ($this->mEnctype!="")
263 $html .= " enctype=\"$this->mEnctype\"";
269 function toStringCloseTag() {
271 foreach ($this->mElements as $elname=>$el) {
272 if (strtolower(get_class($this->mElements[$elname]))=="hidden") {
273 $html .= $this->mElements[$elname]->toStringControl()."\n";
282 $vars['open'] = $this->toStringOpenTag();
283 $vars['close'] = $this->toStringCloseTag();
285 foreach ($this->mElements as $elname=>$el) {
286 if (is_object($this->mElements[$elname]))
287 $vars[$elname] = $this->mElements[$elname]->toArray();
293 function getValueByElement($elname) {
294 return $this->mElements[$elname]->getValue();
297 function setValueByElement($elname, $value) {
298 if (isset($this->mElements[$elname])) {
299 $this->mElements[$elname]->setValue($value);