fde8b40094ab30464cb0e803b2e2b3b0e9791764
[timetracker.git] / WEB-INF / lib / form / FormElement.class.php
1 <?php
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.
10 // |
11 // | There are only two ways to violate the license:
12 // |
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).
16 // |
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).
20 // |
21 // | This license applies to this document only, not any other software
22 // | that it may be combined with.
23 // |
24 // +----------------------------------------------------------------------+
25 // | Contributors:
26 // | https://www.anuko.com/time_tracker/credits.htm
27 // +----------------------------------------------------------------------+
28
29 // FromElement is the base class for controls on forms.
30 class FormElement {
31   var $id = '';         // Control id.
32   var $name;            // Control name.
33   var $form_name = '';  // Form name the control is in.
34   var $value = '';      // Value of the control.
35   var $size = '';       // Control size.
36   var $max_length = ''; // Max length of text in control.
37   var $on_change = '';  // What happens when value of control changes.
38   var $on_click = '';   // What happens when the control is clicked.
39   var $label = '';      // Optional label for control.
40   var $style = '';      // Control style.
41
42   // TODO: refactoring ongoing down from here.
43         var $mEnabled           = true;
44         var $cClassName         = "FormElement";
45         var $mI18n                      = null;
46
47         function __construct() {
48         }
49
50         function getClass()     { return $this->cClassName; }
51         
52         function setName($name) { $this->name = $name; }
53         function getName()      { return $this->name; }
54         
55         function setFormName($name) { $this->form_name = $name; }
56         function getFormName()  { return $this->form_name; }
57         
58         function setValue($value) { $this->value = $value;}
59         function getValue() { return $this->value; }
60         
61         function setValueSafe($value) { $this->value = $value;}
62         function getValueSafe() { return $this->value; }
63
64         function setId($id) { $this->id = $id;  }
65         function getId() { return $this->id; }
66         
67         function setSize($value) { $this->size = $value; }
68         function getSize() { return $this->size; }
69
70         function setLabel($label) { $this->label = $label; }
71         function getLabel() { return $this->label; }
72         
73         function setMaxLength($value) { $this->max_length = $value; }
74         function getMaxLength() { return $this->max_length; }
75
76         function setStyle($value) { $this->style = $value; }
77         function getStyle() { return $this->style; }
78
79         function setEnable($flag)       { $this->mEnabled = $flag;      }
80         function isEnable()     { return $this->mEnabled; }
81         
82         function setOnChange($str) { $this->on_change = $str; }
83         function setOnClick($str) { $this->on_click = $str; }
84
85         function setLocalization($i18n) {
86                 $this->mI18n = $i18n;
87         }
88         
89         function toStringControl()      {
90                 return "";
91         }
92
93         function toStringLabel() {
94             return "<label for=\"" . $this->id . "\">" . $this->label . "</label>";
95         }
96         
97         function toArray() {
98             return array(
99                      "label"=>$this->toStringLabel(),
100                      "control"=>$this->toStringControl()
101                    );
102         }
103
104 }