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 function getElement($name) {
46 return $this->elements[$name];
49 function getElements() {
50 return $this->elements;
53 function getName() { return $this->name; }
55 // TODO: refactoring ongoing down from here.
60 // type = TEXT | PASSWORD | CHECKBOX | RADIO | SUBMIT | RESET | FILE | HIDDEN | IMAGE | BUTTON
63 // checked - for type radio and checkbox
64 // size - width pixels or chars
66 // src - for type image
67 // tabindex - support A, AREA, BUTTON, INPUT, OBJECT, SELECT, and TEXTAREA
68 // accesskey - support A, AREA, BUTTON, INPUT, LABEL, and LEGEND, and TEXTAREA
71 // onselect - INPUT and TEXTAREA
73 function addInput($arguments) {
74 switch($arguments["type"]) {
78 import('form.TextField');
79 $el = new TextField($arguments["name"]);
80 $el->setMaxLength(@$arguments["maxlength"]);
81 if (isset($arguments["aspassword"])) $el->setAsPassword($arguments["aspassword"]);
85 import('form.DateField');
86 $el = new DateField($arguments["name"]);
87 $el->setMaxLength("10");
91 import('form.FloatField');
92 $el = new FloatField($arguments["name"]);
93 if (isset($arguments["format"])) $el->setFormat($arguments["format"]);
97 import('form.TextArea');
98 $el = new TextArea($arguments["name"]);
99 $el->setColumns(@$arguments["cols"]);
100 $el->setRows(@$arguments["rows"]);
101 if (isset($arguments["maxlength"])) $el->setMaxLength($arguments["maxlength"]);
105 import('form.Checkbox');
106 $el = new Checkbox($arguments["name"]);
107 if (@$arguments["checked"]) $el->setChecked(true);
108 $el->setData(@$arguments["data"]);
111 case "checkboxgroup":
112 import('form.CheckboxGroup');
113 $el = new CheckboxGroup($arguments["name"]);
114 if (isset($arguments["layout"])) $el->setLayout($arguments["layout"]);
115 if (isset($arguments["groupin"])) $el->setGroupIn($arguments["groupin"]);
116 if (isset($arguments["datakeys"])) $el->setDataKeys($arguments["datakeys"]);
117 $el->setData(@$arguments["data"]);
121 import('form.Combobox');
122 $el = new Combobox($arguments["name"]);
123 $el->setData(@$arguments["data"]);
124 $el->setDataDefault(@$arguments["empty"]);
125 if (isset($arguments["datakeys"])) $el->setDataKeys($arguments["datakeys"]);
129 import('form.Hidden');
130 $el = new Hidden($arguments["name"]);
134 import('form.Submit');
135 $el = new Submit($arguments["name"]);
139 import('form.Calendar');
140 $el = new Calendar($arguments["name"]);
141 $el->setHighlight(@$arguments["highlight"]);
145 import('form.Table');
146 $el = new Table($arguments["name"]);
147 $el->setData(@$arguments["data"]);
148 $el->setWidth(@$arguments["width"]);
152 import('form.UploadFile');
153 $el = new UploadFile($arguments["name"]);
154 if (isset($arguments["maxsize"])) $el->setMaxSize($arguments["maxsize"]);
158 $el->setFormName($this->name);
159 if (isset($arguments["id"])) $el->setId($arguments["id"]);
160 if (isset($GLOBALS["I18N"])) $el->setLocalization($GLOBALS["I18N"]);
161 if (isset($arguments["render"])) $el->setRenderable($arguments["render"]);
162 if (isset($arguments["enable"])) $el->setEnable($arguments["enable"]);
164 if (isset($arguments["style"])) $el->setStyle($arguments["style"]);
165 if (isset($arguments["size"])) $el->setSize($arguments["size"]);
167 if (isset($arguments["label"])) $el->setLabel($arguments["label"]);
168 if (isset($arguments["value"])) $el->setValue($arguments["value"]);
170 if (isset($arguments["onchange"])) $el->setOnChange($arguments["onchange"]);
171 if (isset($arguments["onclick"])) $el->setOnClick($arguments["onclick"]);
173 $this->elements[$arguments["name"]] = &$el;
177 function addInputElement(&$el) {
178 if ($el && is_object($el)) {
179 if (isset($GLOBALS["I18N"])) $el->setLocalization($GLOBALS["I18N"]);
181 $el->setFormName($this->name);
182 $this->elements[$el->getName()] = &$el;
187 function toStringOpenTag() {
188 $html = "<form name=\"$this->name\"";
190 $html .= ' method="post"';
192 // Add enctype for file upload forms.
193 foreach ($this->elements as $elname=>$el) {
194 if (strtolower(get_class($this->elements[$elname])) == 'uploadfile') {
195 $html .= ' enctype="multipart/form-data"';
204 function toStringCloseTag() {
206 foreach ($this->elements as $elname=>$el) {
207 if (strtolower(get_class($this->elements[$elname]))=="hidden") {
208 $html .= $this->elements[$elname]->toStringControl()."\n";
217 $vars['open'] = $this->toStringOpenTag();
218 $vars['close'] = $this->toStringCloseTag();
220 foreach ($this->elements as $elname=>$el) {
221 if (is_object($this->elements[$elname]))
222 $vars[$elname] = $this->elements[$elname]->toArray();
228 function getValueByElement($elname) {
229 return $this->elements[$elname]->getValue();
232 function setValueByElement($elname, $value) {
233 if (isset($this->elements[$elname])) {
234 $this->elements[$elname]->setValue($value);