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 $mElements = array();
44 function __construct($formName) {
45 $this->name = $formName;
48 function setRequest(&$request) {
49 $this->mRequest = &$request;
52 function &getElement($name) {
53 return $this->mElements[$name];
56 function &getElements() {
57 return $this->mElements;
63 // enctype - enctype="multipart/form-data"
67 function getName() { return $this->name; }
70 if (!isset($this->mRequest)) return false;
72 foreach ($this->mElements as $el) {
73 if (strtolower(get_class($el))=="submit") {
74 $name = $el->getName();
75 $value = $this->mRequest->getAttribute($name);
85 // type = TEXT | PASSWORD | CHECKBOX | RADIO | SUBMIT | RESET | FILE | HIDDEN | IMAGE | BUTTON
88 // checked - for type radio and checkbox
89 // size - width pixels or chars
91 // src - for type image
92 // tabindex - support A, AREA, BUTTON, INPUT, OBJECT, SELECT, and TEXTAREA
93 // accesskey - support A, AREA, BUTTON, INPUT, LABEL, and LEGEND, and TEXTAREA
96 // onselect - INPUT and TEXTAREA
98 function addInput($arguments) {
99 switch($arguments["type"]) {
103 import('form.TextField');
104 $el = new TextField($arguments["name"]);
105 $el->setMaxLength(@$arguments["maxlength"]);
106 if (isset($arguments["aspassword"])) $el->setAsPassword($arguments["aspassword"]);
110 import('form.DateField');
111 $el = new DateField($arguments["name"]);
112 $el->setMaxLength("10");
116 import('form.FloatField');
117 $el = new FloatField($arguments["name"]);
118 if (isset($arguments["format"])) $el->setFormat($arguments["format"]);
122 import('form.TextArea');
123 $el = new TextArea($arguments["name"]);
124 $el->setColumns(@$arguments["cols"]);
125 $el->setRows(@$arguments["rows"]);
126 if (isset($arguments["maxlength"])) $el->setMaxLength($arguments["maxlength"]);
130 import('form.Checkbox');
131 $el = new Checkbox($arguments["name"]);
132 if (@$arguments["checked"]) $el->setChecked(true);
133 $el->setData(@$arguments["data"]);
136 case "checkboxgroup":
137 import('form.CheckboxGroup');
138 $el = new CheckboxGroup($arguments["name"]);
139 if (isset($arguments["layout"])) $el->setLayout($arguments["layout"]);
140 if (isset($arguments["groupin"])) $el->setGroupIn($arguments["groupin"]);
141 if (isset($arguments["datakeys"])) $el->setDataKeys($arguments["datakeys"]);
142 $el->setData(@$arguments["data"]);
146 import('form.Combobox');
147 $el = new Combobox($arguments["name"]);
148 $el->setData(@$arguments["data"]);
149 $el->setDataDefault(@$arguments["empty"]);
150 if (isset($arguments["datakeys"])) $el->setDataKeys($arguments["datakeys"]);
154 import('form.Hidden');
155 $el = new Hidden($arguments["name"]);
159 import('form.Submit');
160 $el = new Submit($arguments["name"]);
164 import('form.Calendar');
165 $el = new Calendar($arguments["name"]);
166 $el->setHighlight(@$arguments["highlight"]);
170 import('form.Table');
171 $el = new Table($arguments["name"]);
172 $el->setData(@$arguments["data"]);
173 $el->setWidth(@$arguments["width"]);
177 import('form.UploadFile');
178 $el = new UploadFile($arguments["name"]);
179 if (isset($arguments["maxsize"])) $el->setMaxSize($arguments["maxsize"]);
183 $el->setFormName($this->name);
184 if (isset($arguments["id"])) $el->setId($arguments["id"]);
185 if (isset($GLOBALS["I18N"])) $el->setLocalization($GLOBALS["I18N"]);
186 if (isset($arguments["render"])) $el->setRenderable($arguments["render"]);
187 if (isset($arguments["enable"])) $el->setEnable($arguments["enable"]);
189 if (isset($arguments["style"])) $el->setStyle($arguments["style"]);
190 if (isset($arguments["size"])) $el->setSize($arguments["size"]);
192 if (isset($arguments["label"])) $el->setLabel($arguments["label"]);
193 if (isset($arguments["value"])) $el->setValue($arguments["value"]);
195 if (isset($arguments["onchange"])) $el->setOnChange($arguments["onchange"]);
196 if (isset($arguments["onclick"])) $el->setOnClick($arguments["onclick"]);
198 $this->mElements[$arguments["name"]] = &$el;
202 function addInputElement(&$el) {
203 if ($el && is_object($el)) {
204 if (isset($GLOBALS["I18N"])) $el->setLocalization($GLOBALS["I18N"]);
206 $el->setFormName($this->name);
207 $this->mElements[$el->getName()] = &$el;
212 function toStringOpenTag() {
213 $html = "<form name=\"$this->name\"";
215 $html .= ' method="post"';
217 // Add enctype for file upload forms.
218 foreach ($this->mElements as $elname=>$el) {
219 if (strtolower(get_class($this->mElements[$elname])) == 'uploadfile') {
220 $html .= ' enctype="multipart/form-data"';
229 function toStringCloseTag() {
231 foreach ($this->mElements as $elname=>$el) {
232 if (strtolower(get_class($this->mElements[$elname]))=="hidden") {
233 $html .= $this->mElements[$elname]->toStringControl()."\n";
242 $vars['open'] = $this->toStringOpenTag();
243 $vars['close'] = $this->toStringCloseTag();
245 foreach ($this->mElements as $elname=>$el) {
246 if (is_object($this->mElements[$elname]))
247 $vars[$elname] = $this->mElements[$elname]->toArray();
253 function getValueByElement($elname) {
254 return $this->mElements[$elname]->getValue();
257 function setValueByElement($elname, $value) {
258 if (isset($this->mElements[$elname])) {
259 $this->mElements[$elname]->setValue($value);