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 // addInput - adds an input object to the form.
56 function addInput($arguments) {
57 switch($arguments['type']) {
59 import('form.TextField');
60 $el = new TextField($arguments['name']);
61 $el->setMaxLength(@$arguments['maxlength']);
62 if (isset($arguments['aspassword'])) $el->setAsPassword($arguments['aspassword']);
65 // TODO: refactoring ongoing down from here.
66 // aspassword - change this name to something better? Perhaps.
67 // Change $arguments to something better too (maybe). $args or $params?
69 import('form.DateField');
70 $el = new DateField($arguments["name"]);
71 $el->setMaxLength("10");
75 import('form.FloatField');
76 $el = new FloatField($arguments["name"]);
77 if (isset($arguments["format"])) $el->setFormat($arguments["format"]);
81 import('form.TextArea');
82 $el = new TextArea($arguments["name"]);
83 $el->setColumns(@$arguments["cols"]);
84 $el->setRows(@$arguments["rows"]);
85 if (isset($arguments["maxlength"])) $el->setMaxLength($arguments["maxlength"]);
89 import('form.Checkbox');
90 $el = new Checkbox($arguments["name"]);
91 if (@$arguments["checked"]) $el->setChecked(true);
92 $el->setData(@$arguments["data"]);
96 import('form.CheckboxGroup');
97 $el = new CheckboxGroup($arguments["name"]);
98 if (isset($arguments["layout"])) $el->setLayout($arguments["layout"]);
99 if (isset($arguments["groupin"])) $el->setGroupIn($arguments["groupin"]);
100 if (isset($arguments["datakeys"])) $el->setDataKeys($arguments["datakeys"]);
101 $el->setData(@$arguments["data"]);
105 import('form.Combobox');
106 $el = new Combobox($arguments["name"]);
107 $el->setData(@$arguments["data"]);
108 $el->setDataDefault(@$arguments["empty"]);
109 if (isset($arguments["datakeys"])) $el->setDataKeys($arguments["datakeys"]);
113 import('form.Hidden');
114 $el = new Hidden($arguments["name"]);
118 import('form.Submit');
119 $el = new Submit($arguments["name"]);
123 import('form.Calendar');
124 $el = new Calendar($arguments["name"]);
125 $el->setHighlight(@$arguments["highlight"]);
129 import('form.Table');
130 $el = new Table($arguments["name"]);
131 $el->setData(@$arguments["data"]);
132 $el->setWidth(@$arguments["width"]);
136 import('form.UploadFile');
137 $el = new UploadFile($arguments["name"]);
138 if (isset($arguments["maxsize"])) $el->setMaxSize($arguments["maxsize"]);
142 $el->setFormName($this->name);
143 if (isset($arguments["id"])) $el->setId($arguments["id"]);
144 if (isset($GLOBALS["I18N"])) $el->setLocalization($GLOBALS["I18N"]);
145 if (isset($arguments["enable"])) $el->setEnabled($arguments["enable"]);
147 if (isset($arguments["style"])) $el->setStyle($arguments["style"]);
148 if (isset($arguments["size"])) $el->setSize($arguments["size"]);
150 if (isset($arguments["label"])) $el->setLabel($arguments["label"]);
151 if (isset($arguments["value"])) $el->setValue($arguments["value"]);
153 if (isset($arguments["onchange"])) $el->setOnChange($arguments["onchange"]);
154 if (isset($arguments["onclick"])) $el->setOnClick($arguments["onclick"]);
156 $this->elements[$arguments["name"]] = &$el;
160 function addInputElement(&$el) {
161 if ($el && is_object($el)) {
162 if (isset($GLOBALS["I18N"])) $el->setLocalization($GLOBALS["I18N"]);
164 $el->setFormName($this->name);
165 $this->elements[$el->name] = &$el;
170 function toStringOpenTag() {
171 $html = "<form name=\"$this->name\"";
173 $html .= ' method="post"';
175 // Add enctype for file upload forms.
176 foreach ($this->elements as $elname=>$el) {
177 if (strtolower(get_class($this->elements[$elname])) == 'uploadfile') {
178 $html .= ' enctype="multipart/form-data"';
187 function toStringCloseTag() {
189 foreach ($this->elements as $elname=>$el) {
190 if (strtolower(get_class($this->elements[$elname]))=="hidden") {
191 $html .= $this->elements[$elname]->toStringControl()."\n";
200 $vars['open'] = $this->toStringOpenTag();
201 $vars['close'] = $this->toStringCloseTag();
203 foreach ($this->elements as $elname=>$el) {
204 if (is_object($this->elements[$elname]))
205 $vars[$elname] = $this->elements[$elname]->toArray();
211 function getValueByElement($elname) {
212 return $this->elements[$elname]->getValue();
215 function setValueByElement($elname, $value) {
216 if (isset($this->elements[$elname])) {
217 $this->elements[$elname]->setValue($value);