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.
41 var $mMethod = "post";
46 var $mElements = array();
50 function __construct($formid) {
51 $this->name = $formid;
54 function setRequest(&$request) {
55 $this->mRequest = &$request;
58 /* function setFormBean(&$bean) {
59 $this->mFormBean = &$bean;
62 function &getElement($name) {
63 return $this->mElements[$name];
66 function &getElements() {
67 return $this->mElements;
73 // enctype - enctype="multipart/form-data"
77 function setName($value) { $this->name = $value; }
78 function getName() { return $this->name; }
80 function setId($value) { $this->mId = $value; }
81 function getId() { return $this->mId; }
83 function setMethod($value) { $this->mMethod = $value; }
84 function getMethod() { return $this->mMethod; }
87 if (!isset($this->mRequest)) return false;
89 foreach ($this->mElements as $el) {
90 if (strtolower(get_class($el))=="submit") {
91 $name = $el->getName();
92 $value = $this->mRequest->getAttribute($name);
101 function OutputError($error,$scope="")
103 $this->error=(strcmp($scope,"") ? $scope.": ".$error : $error);
104 if(strcmp($function=$this->debugFunction,"")
105 && strcmp($this->error,""))
106 $function($this->error);
107 return($this->error);
111 // type = TEXT | PASSWORD | CHECKBOX | RADIO | SUBMIT | RESET | FILE | HIDDEN | IMAGE | BUTTON
114 // checked - for type radio and checkbox
115 // size - width pixels or chars
117 // src - for type image
118 // tabindex - support A, AREA, BUTTON, INPUT, OBJECT, SELECT, and TEXTAREA
119 // accesskey - support A, AREA, BUTTON, INPUT, LABEL, and LEGEND, and TEXTAREA
122 // onselect - INPUT and TEXTAREA
124 function addInput($arguments) {
125 if(strcmp(gettype($arguments),"array"))
126 $this->OutputError("arguments must be array","AddInput");
128 if(!isset($arguments["type"]) || !strcmp($arguments["type"],""))
129 return($this->OutputError("Type not defined","AddInput"));
131 if(!isset($arguments["name"]) || !strcmp($arguments["name"],""))
132 return($this->OutputError("Name of element not defined","AddInput"));
134 if (isset($this->mElements[$arguments["name"]]))
135 return($this->OutputError("it was specified '".$arguments["name"]."' name of an already defined input","AddInput"));
137 switch($arguments["type"]) {
141 import('form.TextField');
142 $el = new TextField($arguments["name"]);
143 $el->setMaxLength(@$arguments["maxlength"]);
144 if (isset($arguments["aspassword"])) $el->setAsPassword($arguments["aspassword"]);
148 import('form.DateField');
149 $el = new DateField($arguments["name"]);
150 $el->setMaxLength("10");
154 import('form.FloatField');
155 $el = new FloatField($arguments["name"]);
156 if (isset($arguments["format"])) $el->setFormat($arguments["format"]);
160 import('form.TextArea');
161 $el = new TextArea($arguments["name"]);
162 $el->setColumns(@$arguments["cols"]);
163 $el->setRows(@$arguments["rows"]);
164 if (isset($arguments["maxlength"])) $el->setMaxLength($arguments["maxlength"]);
168 import('form.Checkbox');
169 $el = new Checkbox($arguments["name"]);
170 if (@$arguments["checked"]) $el->setChecked(true);
171 $el->setData(@$arguments["data"]);
174 case "checkboxgroup":
175 import('form.CheckboxGroup');
176 $el = new CheckboxGroup($arguments["name"]);
177 if (isset($arguments["layout"])) $el->setLayout($arguments["layout"]);
178 if (isset($arguments["groupin"])) $el->setGroupIn($arguments["groupin"]);
179 if (isset($arguments["datakeys"])) $el->setDataKeys($arguments["datakeys"]);
180 $el->setData(@$arguments["data"]);
184 import('form.Combobox');
185 $el = new Combobox($arguments["name"]);
186 $el->setData(@$arguments["data"]);
187 $el->setDataDefault(@$arguments["empty"]);
188 if (isset($arguments["datakeys"])) $el->setDataKeys($arguments["datakeys"]);
192 import('form.Hidden');
193 $el = new Hidden($arguments["name"]);
197 import('form.Submit');
198 $el = new Submit($arguments["name"]);
202 import('form.Calendar');
203 $el = new Calendar($arguments["name"]);
204 $el->setHighlight(@$arguments["highlight"]);
208 import('form.Table');
209 $el = new Table($arguments["name"]);
210 $el->setData(@$arguments["data"]);
211 $el->setWidth(@$arguments["width"]);
215 import('form.UploadFile');
216 $el = new UploadFile($arguments["name"]);
217 if (isset($arguments["maxsize"])) $el->setMaxSize($arguments["maxsize"]);
221 return($this->OutputError("Type not found for input element","AddInput"));
224 $el->setFormName($this->name);
225 if (isset($arguments["id"])) $el->setId($arguments["id"]);
226 if (isset($GLOBALS["I18N"])) $el->setLocalization($GLOBALS["I18N"]);
227 if (isset($arguments["render"])) $el->setRenderable($arguments["render"]);
228 if (isset($arguments["enable"])) $el->setEnable($arguments["enable"]);
230 if (isset($arguments["style"])) $el->setStyle($arguments["style"]);
231 if (isset($arguments["size"])) $el->setSize($arguments["size"]);
233 if (isset($arguments["label"])) $el->setLabel($arguments["label"]);
234 if (isset($arguments["value"])) $el->setValue($arguments["value"]);
236 if (isset($arguments["onchange"])) $el->setOnChange($arguments["onchange"]);
237 if (isset($arguments["onclick"])) $el->setOnClick($arguments["onclick"]);
239 $this->mElements[$arguments["name"]] = &$el;
243 function addInputElement(&$el) {
244 if ($el && is_object($el)) {
246 return($this->OutputError("no name in element","addInputElement"));
248 if (isset($GLOBALS["I18N"])) $el->setLocalization($GLOBALS["I18N"]);
250 $el->setFormName($this->name);
251 $this->mElements[$el->getName()] = &$el;
256 function toStringOpenTag() {
257 $html = "<form name=\"$this->name\"";
260 $html .= " id=\"$this->mId\"";
262 if ($this->mMethod!="")
263 $html .= " method=\"$this->mMethod\"";
266 foreach ($this->mElements as $elname=>$el) {
267 if (strtolower(get_class($this->mElements[$elname]))=="uploadfile") {
268 $this->mEnctype = "multipart/form-data";
272 if ($this->mEnctype!="")
273 $html .= " enctype=\"$this->mEnctype\"";
279 function toStringCloseTag() {
281 foreach ($this->mElements as $elname=>$el) {
282 if (strtolower(get_class($this->mElements[$elname]))=="hidden") {
283 $html .= $this->mElements[$elname]->toStringControl()."\n";
292 $vars['open'] = $this->toStringOpenTag();
293 $vars['close'] = $this->toStringCloseTag();
295 foreach ($this->mElements as $elname=>$el) {
296 if (is_object($this->mElements[$elname]))
297 $vars[$elname] = $this->mElements[$elname]->toArray();
303 function getValueByElement($elname) {
304 return $this->mElements[$elname]->getValue();
307 function setValueByElement($elname, $value) {
308 if (isset($this->mElements[$elname])) {
309 $this->mElements[$elname]->setValue($value);