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 var $elements = array();
41 function __construct($formName) {
42 $this->name = $formName;
45 // TODO: refactoring ongoing down from here.
47 function &getElement($name) {
48 return $this->elements[$name];
51 function &getElements() {
52 return $this->elements;
58 // enctype - enctype="multipart/form-data"
62 function getName() { return $this->name; }
65 // type = TEXT | PASSWORD | CHECKBOX | RADIO | SUBMIT | RESET | FILE | HIDDEN | IMAGE | BUTTON
68 // checked - for type radio and checkbox
69 // size - width pixels or chars
71 // src - for type image
72 // tabindex - support A, AREA, BUTTON, INPUT, OBJECT, SELECT, and TEXTAREA
73 // accesskey - support A, AREA, BUTTON, INPUT, LABEL, and LEGEND, and TEXTAREA
76 // onselect - INPUT and TEXTAREA
78 function addInput($arguments) {
79 switch($arguments["type"]) {
83 import('form.TextField');
84 $el = new TextField($arguments["name"]);
85 $el->setMaxLength(@$arguments["maxlength"]);
86 if (isset($arguments["aspassword"])) $el->setAsPassword($arguments["aspassword"]);
90 import('form.DateField');
91 $el = new DateField($arguments["name"]);
92 $el->setMaxLength("10");
96 import('form.FloatField');
97 $el = new FloatField($arguments["name"]);
98 if (isset($arguments["format"])) $el->setFormat($arguments["format"]);
102 import('form.TextArea');
103 $el = new TextArea($arguments["name"]);
104 $el->setColumns(@$arguments["cols"]);
105 $el->setRows(@$arguments["rows"]);
106 if (isset($arguments["maxlength"])) $el->setMaxLength($arguments["maxlength"]);
110 import('form.Checkbox');
111 $el = new Checkbox($arguments["name"]);
112 if (@$arguments["checked"]) $el->setChecked(true);
113 $el->setData(@$arguments["data"]);
116 case "checkboxgroup":
117 import('form.CheckboxGroup');
118 $el = new CheckboxGroup($arguments["name"]);
119 if (isset($arguments["layout"])) $el->setLayout($arguments["layout"]);
120 if (isset($arguments["groupin"])) $el->setGroupIn($arguments["groupin"]);
121 if (isset($arguments["datakeys"])) $el->setDataKeys($arguments["datakeys"]);
122 $el->setData(@$arguments["data"]);
126 import('form.Combobox');
127 $el = new Combobox($arguments["name"]);
128 $el->setData(@$arguments["data"]);
129 $el->setDataDefault(@$arguments["empty"]);
130 if (isset($arguments["datakeys"])) $el->setDataKeys($arguments["datakeys"]);
134 import('form.Hidden');
135 $el = new Hidden($arguments["name"]);
139 import('form.Submit');
140 $el = new Submit($arguments["name"]);
144 import('form.Calendar');
145 $el = new Calendar($arguments["name"]);
146 $el->setHighlight(@$arguments["highlight"]);
150 import('form.Table');
151 $el = new Table($arguments["name"]);
152 $el->setData(@$arguments["data"]);
153 $el->setWidth(@$arguments["width"]);
157 import('form.UploadFile');
158 $el = new UploadFile($arguments["name"]);
159 if (isset($arguments["maxsize"])) $el->setMaxSize($arguments["maxsize"]);
163 $el->setFormName($this->name);
164 if (isset($arguments["id"])) $el->setId($arguments["id"]);
165 if (isset($GLOBALS["I18N"])) $el->setLocalization($GLOBALS["I18N"]);
166 if (isset($arguments["render"])) $el->setRenderable($arguments["render"]);
167 if (isset($arguments["enable"])) $el->setEnable($arguments["enable"]);
169 if (isset($arguments["style"])) $el->setStyle($arguments["style"]);
170 if (isset($arguments["size"])) $el->setSize($arguments["size"]);
172 if (isset($arguments["label"])) $el->setLabel($arguments["label"]);
173 if (isset($arguments["value"])) $el->setValue($arguments["value"]);
175 if (isset($arguments["onchange"])) $el->setOnChange($arguments["onchange"]);
176 if (isset($arguments["onclick"])) $el->setOnClick($arguments["onclick"]);
178 $this->elements[$arguments["name"]] = &$el;
182 function addInputElement(&$el) {
183 if ($el && is_object($el)) {
184 if (isset($GLOBALS["I18N"])) $el->setLocalization($GLOBALS["I18N"]);
186 $el->setFormName($this->name);
187 $this->elements[$el->getName()] = &$el;
192 function toStringOpenTag() {
193 $html = "<form name=\"$this->name\"";
195 $html .= ' method="post"';
197 // Add enctype for file upload forms.
198 foreach ($this->elements as $elname=>$el) {
199 if (strtolower(get_class($this->elements[$elname])) == 'uploadfile') {
200 $html .= ' enctype="multipart/form-data"';
209 function toStringCloseTag() {
211 foreach ($this->elements as $elname=>$el) {
212 if (strtolower(get_class($this->elements[$elname]))=="hidden") {
213 $html .= $this->elements[$elname]->toStringControl()."\n";
222 $vars['open'] = $this->toStringOpenTag();
223 $vars['close'] = $this->toStringCloseTag();
225 foreach ($this->elements as $elname=>$el) {
226 if (is_object($this->elements[$elname]))
227 $vars[$elname] = $this->elements[$elname]->toArray();
233 function getValueByElement($elname) {
234 return $this->elements[$elname]->getValue();
237 function setValueByElement($elname, $value) {
238 if (isset($this->elements[$elname])) {
239 $this->elements[$elname]->setValue($value);