Refactoring. Moved a member out of base class.
[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 lenght 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
40   // TODO: refactoring ongoing down from here.
41         var $mOnFocus           = "";
42         var $mLabel         = "";
43         var $mStyle         = "";
44         var $mRenderable    = true;
45         var $mEnabled           = true;
46         var $cClassName         = "FormElement";
47         var $mI18n                      = null;
48
49         function __construct() {
50         }
51
52         function getClass()     { return $this->cClassName; }
53         
54         function setName($name) { $this->name = $name; }
55         function getName()      { return $this->name; }
56         
57         function setFormName($name) { $this->form_name = $name; }
58         function getFormName()  { return $this->form_name; }
59         
60         function setValue($value) { $this->value = $value;}
61         function getValue() { return $this->value; }
62         
63         function setValueSafe($value) { $this->value = $value;}
64         function getValueSafe() { return $this->value; }
65
66         function setId($id) { $this->id = $id;  }
67         function getId() { return $this->id; }
68         
69         function setSize($value) { $this->size = $value; }
70         function getSize() { return $this->size; }
71
72         function setLabel($label)       { $this->mLabel = $label; }
73         function getLabel() { return $this->mLabel; }
74         
75         function setMaxLength($value) { $this->max_length = $value; }
76         function getMaxLength() { return $this->max_length; }
77
78         function setStyle($value)       { $this->mStyle = $value; }
79         function getStyle() { return $this->mStyle; }
80         
81         function setRenderable($flag)   { $this->mRenderable = $flag;   }
82         function isRenderable() { return $this->mRenderable; }
83         
84         function setEnable($flag)       { $this->mEnabled = $flag;      }
85         function isEnable()     { return $this->mEnabled; }
86         
87         function setOnChange($str) { $this->on_change = $str; }
88         function setOnClick($str) { $this->on_click = $str; }
89
90         function setLocalization($i18n) {
91                 $this->mI18n = $i18n;
92         }
93         
94         function toStringControl()      {
95                 return "";
96         }
97         
98         function toStringLabel() {
99             return "<label for=\"" . $this->id . "\">" . $this->mLabel . "</label>";
100         }
101         
102         function toArray() {
103             return array(
104                      "label"=>$this->toStringLabel(),
105                      "control"=>$this->toStringControl()
106                    );
107         }
108
109 }