forked from rogermoka/Timesheet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
form_input.inc
121 lines (95 loc) · 2.7 KB
/
form_input.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?{
//Include file for timesheet.php date related functions
//Base class for a form input. Holds the 'name' parameter
class FormInput {
var $name;
function FormInput($name) {
$this->name = $name;
}
}
//Base class for a <select...> input. Defines functions which print the start/end tags
class SelectInput extends FormInput {
function printSelect() {
//print the input
echo "<select name=\"" . $this->name . "\" id=\"" . $this->name . "\">";
}
function printEndSelect() {
echo "</select>";
}
}
class HourInput extends SelectInput {
function create($selectedIndex = 9) {
$this->printSelect();
//work out whether we want to display time in 12 or 24 hour format
include("table_names.inc");
list($qhq, $numq) = dbQuery("select timeformat from $CONFIG_TABLE where config_set_id = '1'");
$configdata = dbResult($qhq);
if ($configdata[timeformat] == "12")
$this->create_12hour($selectedIndex);
else
$this->create_24hour($selectedIndex);
$this->printEndSelect();
}
function create_12hour($selectedIndex = 9) {
for ($i=0;$i<24;$i++) {
if ($i == 0)
$display_time = "12 am";
elseif ($i == 12)
$display_time = "12 pm";
elseif ($i > 12 && $i<24)
$display_time = $i-12 . " pm";
else
$display_time = "$i am";
if ($i == $selectedIndex)
echo "<option value=\"$i\" selected>$display_time</option>";
else
echo "<option value=\"$i\">$display_time</option>";
}
}
function create_24hour($selectedIndex = 9) {
for ($i=0;$i<24;$i++) {
$display_time = "$i";
if ($i == $selectedIndex)
echo "<option value=\"$i\" selected>$display_time</option>";
else
echo "<option value=\"$i\">$display_time</option>";
}
}
}
class MinuteInput extends SelectInput {
function create($selectedMinute = 0) {
$this->printSelect();
for ($i=0;$i<60;$i+=5) {
echo "<option value=\"$i\"";
if ($selectedMinute > $i - 2 && $selectedMinute < $i + 3)
echo " selected";
printf(">%02d</option>\n", $i);
}
$this->printEndSelect();
}
}
class MonthInput extends SelectInput {
function create($selectedMonth = 1) {
$this->printSelect();
for ($i=1; $i<=12; $i++) {
echo "<option value=\"$i\"";
if ($i == $selectedMonth)
echo " selected";
echo ">" . date("F", mktime(0,0,0,$i,1,2000)) . "</option>\n";
}
$this->printEndSelect();
}
}
class DayInput extends SelectInput {
function create($selectedDay = 1) {
$this->printSelect();
for ($i=1; $i<=31; $i++) {
echo "<option value=\"$i\"";
if ($i == $selectedDay)
echo " selected";
echo ">$i</option>\n";
}
$this->printEndSelect();
}
}
}?>