c6182d3ac9b5a06e7be41ef4de5708e7bb715fc7
[timetracker.git] / 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   var $enabled = true;  // Whether the control is enabled.
42   var $class = 'FormElement'; // Class name for the element.
43
44   function __construct() {
45   }
46
47   function getName() { return $this->name; }
48   function getClass() { return $this->class; }
49   
50   // TODO: refactoring ongoing down from here.
51         function setFormName($name) { $this->form_name = $name; }
52         function getFormName()  { return $this->form_name; }
53         
54         function setValue($value) { $this->value = $value; }
55         function getValue() { return $this->value; }
56         
57         function setValueSafe($value) { $this->value = $value;}
58         function getValueSafe() { return $this->value; }
59
60         function setId($id) { $this->id = $id;  }
61         function getId() { return $this->id; }
62         
63         function setSize($value) { $this->size = $value; }
64         function getSize() { return $this->size; }
65
66         function setLabel($label) { $this->label = $label; }
67         function getLabel() { return $this->label; }
68         
69         function setMaxLength($value) { $this->max_length = $value; }
70         function getMaxLength() { return $this->max_length; }
71
72         function setStyle($value) { $this->style = $value; }
73         function getStyle() { return $this->style; }
74
75         function setEnabled($flag) { $this->enabled = $flag; }
76         function isEnabled() { return $this->enabled; }
77         
78         function setOnChange($str) { $this->on_change = $str; }
79         function setOnClick($str) { $this->on_click = $str; }
80
81         function setLocalization($i18n) {
82         }
83         
84         function toStringControl()      {
85                 return "";
86         }
87
88         function toStringLabel() {
89             return "<label for=\"" . $this->id . "\">" . $this->label . "</label>";
90         }
91         
92         function toArray() {
93             return array(
94                      "label"=>$this->toStringLabel(),
95                      "control"=>$this->toStringControl()
96                    );
97         }
98
99 }