forked from andrew867/timeclock
-
Notifications
You must be signed in to change notification settings - Fork 5
/
leftmain.php
322 lines (257 loc) · 11.7 KB
/
leftmain.php
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
<?php
require 'common.php';
$self = $_SERVER['PHP_SELF'];
$request = $_SERVER['REQUEST_METHOD'];
// set cookie if 'Remember Me?' checkbox is checked, or reset cookie if 'Reset Cookie?' is checked //
if ($show_display_name == "yes") {
$emp_name_field = "displayname";
} else {
$emp_name_field = "empfullname";
}
if ($request == 'POST') {
@$remember_me = $_POST['remember_me'];
@$reset_cookie = $_POST['reset_cookie'];
@$fullname = $_POST['left_fullname'];
@$displayname = $_POST['left_displayname'];
@$barcode = (yes_no_bool($barcode_clockin) ? $_POST['left_barcode'] : "");
if ((isset($remember_me)) && ($remember_me != '1')) {
echo "Something is fishy here.\n";
exit;
}
if ((isset($reset_cookie)) && ($reset_cookie != '1')) {
echo "Something is fishy here.\n";
exit;
}
// begin post validation //
$errors = array();
if (has_value($barcode)) {
$tmp_name = tc_select_value($emp_name_field, "employees", "barcode = ?", $barcode);
if (!has_value($tmp_name)) {
$errors[] = "Invalid barcode '$barcode'";
} elseif (isset($emp_name) and $emp_name != $tmp_name) {
$errors[] = "Username / Barcode mismatch";
} else {
$emp_name = $tmp_name;
}
}
$tmp_name = '';
if (yes_no_bool($show_display_name)) {
if (has_value($displayname)) {
$tmp_name = tc_select_value($emp_name_field, "employees", "displayname = ?", $displayname);
if (!has_value($tmp_name)) {
$errors[] = "Invalid username '$displayname'";
}
}
} else {
if (has_value($fullname)) {
$tmp_name = tc_select_value($emp_name_field, "employees", "empfullname = ?", $fullname);
if (!has_value($tmp_name)) {
$errors[] = "Invalid username '$fullname'";
}
}
}
if (has_value($tmp_name)) {
if (isset($emp_name) and $emp_name != $tmp_name) {
$errors[] = "Username / Barcode mismatch";
} else {
$emp_name = $tmp_name;
}
}
// end post validation //
if (empty($errors)) {
if (isset($remember_me)) {
setcookie("remember_me", $emp_name, time() + (60 * 60 * 24 * 365 * 2));
} elseif (isset($reset_cookie)) {
setcookie("remember_me", "", time() - 3600);
}
}
ob_end_flush();
}
echo "<table width=100% height=89% border=0 cellpadding=0 cellspacing=1>\n";
echo " <tr valign=top>\n";
echo " <td class=left_main width=200 align=left scope=col>\n";
echo " <table class=hide width=100% border=0 cellpadding=1 cellspacing=0>\n";
// display links in top left of each page //
if ($links == "none") {
echo " <tr></tr>\n";
} else {
echo " <tr><td class=left_rows height=7 align=left valign=middle></td></tr>\n";
for ($x = 0; $x < count($display_links); $x++) {
echo " <tr><td class=left_rows height=18 align=left valign=middle><a class=admin_headings href='$links[$x]' target='_new'>$display_links[$x]</a></td>
</tr>\n";
}
}
// display form to submit signin/signout information //
echo " <form name='timeclock' action='$self' autocomplete='off' method='post'>\n";
if ($links == "none") {
echo " <tr><td height=7></td></tr>\n";
} else {
echo " <tr><td height=20></td></tr>\n";
}
if (yes_no_bool($barcode_clockin)) {
echo <<<BARCODE_CLOCKIN
<tr><td height="4" align="left" valign="middle" class="misc_items">Barcode:</td></tr>
<tr><td height="4" align="left" valign="middle" class="misc_items">
<input type="text" id="left_barcode" name="left_barcode" maxlength="250" size="17" value="" autocomplete="off" autofocus>
<input type="text" style="display:none;"><!-- prevent login name auto-fill due to password field below -->
</td></tr>
<tr><td height="7"></td></tr>
BARCODE_CLOCKIN;
}
if (yes_no_bool($barcode_clockin) and yes_no_bool($manual_clockin)) {
echo '<tr><td height="7"><hr></td></tr>';
}
if (yes_no_bool($manual_clockin)) {
echo " <tr><td class=title_underline height=4 align=left valign=middle style='padding-left:10px;'>Please sign in below:</td></tr>\n";
echo " <tr><td height=7></td></tr>\n";
echo " <tr><td height=4 align=left valign=middle class=misc_items>Name:</td></tr>\n";
echo " <tr><td height=4 align=left valign=middle class=misc_items>\n";
// query to populate dropdown with employee names //
if ($show_display_name == "yes") {
echo " <select name='left_displayname'>\n";
} else {
echo " <select name='left_fullname'>\n";
}
echo " <option value =''>...</option>\n";
echo html_options(
tc_select($emp_name_field, "employees", "disabled <> '1' AND empfullname <> 'admin' ORDER BY $emp_name_field"),
@$_COOKIE['remember_me']
);
echo " </select></td></tr>\n";
echo " <tr><td height=7></td></tr>\n";
// determine whether to use encrypted passwords or not //
if ($use_passwd == "yes") {
echo " <tr><td height=4 align=left valign=middle class=misc_items>Password:</td></tr>\n";
echo " <tr><td height=4 align=left valign=middle class=misc_items>";
echo "<input type='password' name='employee_passwd' maxlength='25' size='17'></td></tr>\n";
echo " <tr><td height=7></td></tr>\n";
}
echo " <tr><td height=4 align=left valign=middle class=misc_items>In/Out:</td></tr>\n";
echo " <tr><td height=4 align=left valign=middle class=misc_items>\n";
// populate dropdown with punchlist items //
echo " <select name='left_inout'>\n";
echo " <option value =''>...</option>\n";
echo html_options(tc_select("punchitems", "punchlist"));
echo " </select></td></tr>\n";
echo " <tr><td height=7></td></tr>\n";
echo " <tr><td height=4 align=left valign=middle class=misc_items>Notes:</td></tr>\n";
echo " <tr><td height=4 align=left valign=middle class=misc_items>";
echo "<input type='text' name='left_notes' maxlength='250' size='17'></td></tr>\n";
if (!isset($_COOKIE['remember_me'])) {
echo " <tr><td width=100%><table width=100% border=0 cellpadding=0 cellspacing=0>
<tr><td nowrap height=4 align=left valign=middle class=misc_items width=10%>Remember Me?</td><td width=90% align=left
class=misc_items style='padding-left:0px;padding-right:0px;'><input type='checkbox' name='remember_me' value='1'></td></tr>
</table></td><tr>\n";
} elseif (isset($_COOKIE['remember_me'])) {
echo " <tr><td width=100%><table width=100% border=0 cellpadding=0 cellspacing=0>
<tr><td nowrap height=4 align=left valign=middle class=misc_items width=10%>Reset Cookie?</td><td width=90% align=left
class=misc_items style='padding-left:0px;padding-right:0px;'><input type='checkbox' name='reset_cookie' value='1'></td></tr>
</table></td><tr>\n";
}
echo " <tr><td height=7></td></tr>\n";
}
echo " <tr><td height=4 align=left valign=middle class=misc_items><input type='submit' name='submit_button' value='Submit' align='center'></td></tr></form>\n";
if (yes_no_bool($display_weather)) {
echo '<tr><td>';
include 'sidebar-metar-display.php';
echo '</td></tr>';
}
echo " </table></td>\n";
if ($request == 'POST') {
// signin/signout data passed over from timeclock.php //
$inout = isset($_POST['left_inout']) ? $_POST['left_inout'] : '';
$notes = isset($_POST['left_notes']) ? preg_replace("[^a-zA-Z0-9 \,\.\?-]", "", strtolower($_POST['left_notes'])) : '';
// begin post validation //
# Trying to toggle, look up the "punchnext" toggle state:
if (!has_value($inout) and has_value($emp_name)) {
$result = tc_query(<<<QUERY
SELECT p.punchnext
FROM ${db_prefix}employees AS e
LEFT JOIN ${db_prefix}info AS i ON (e.empfullname = i.fullname AND e.tstamp = i.timestamp)
LEFT JOIN ${db_prefix}punchlist AS p ON (i.inout = p.punchitems)
WHERE e.$emp_name_field = ?
QUERY
, $emp_name);
while ($row = mysqli_fetch_array($result)) {
$inout = $row[0];
}
}
elseif (has_value($inout)) {
$inout = tc_select_value("punchitems", "punchlist", "punchitems = ?", $inout);
if (!has_value($inout)) {
echo "In/Out Status is not in the database.\n";
exit;
}
}
if ($use_passwd == "yes") {
$employee_passwd = crypt($_POST['employee_passwd'], 'xy');
}
// end post validation //
if (!has_value($emp_name) && !has_value($inout)) {
$errors[] = "You have not chosen a username or a status. Please try again.";
}
elseif (!has_value($emp_name)) {
$errors[] = "You have not chosen a username. Please try again.";
}
elseif (!has_value($inout)) {
$errors[] = "You have not chosen a status. Please try again.";
}
if (!empty($errors)) {
echo " <td align=left class=right_main scope=col>\n";
echo " <table width=100% height=100% border=0 cellpadding=10 cellspacing=1>\n";
echo " <tr class=right_main_text>\n";
echo " <td valign=top>\n";
echo "<br />\n";
echo implode("<br>\n", $errors);
include 'footer.php';
exit;
}
// configure timestamp to insert/update //
$tz_stamp = time();
if (has_value($barcode) or $use_passwd == "no") {
if (!has_value($fullname)) {
$fullname = tc_select_value("empfullname", "employees", "$emp_name_field = ?", $emp_name);
}
$clockin = array("fullname" => $fullname, "inout" => $inout, "timestamp" => $tz_stamp, "notes" => "$notes", "punchoffice" => "".@$_COOKIE['office_name']);
if (strtolower($ip_logging) == "yes") {
$clockin["ipaddress"] = "$connecting_ip";
}
tc_insert_strings("info", $clockin);
tc_update_strings("employees", array("tstamp" => $tz_stamp), "empfullname = ?", $fullname);
echo "<head>\n";
echo "<meta http-equiv='refresh' content=0;url=index.php>\n";
echo "</head>\n";
} else {
$sel_result = tc_select(
"empfullname, employee_passwd",
"employees",
"$emp_name_field = ?",
$emp_name
);
while ($row = mysqli_fetch_array($sel_result)) {
$tmp_password = "" . $row["employee_passwd"] . "";
$fullname = "" . $row["empfullname"] . "";
}
if ($employee_passwd == $tmp_password) {
$clockin = array("fullname" => $fullname, "inout" => $inout, "timestamp" => $tz_stamp, "notes" => "$notes", "punchoffice" => "".@$_COOKIE['office_name']);
if (strtolower($ip_logging) == "yes") {
$clockin["ipaddress"] = "$connecting_ip";
}
tc_insert_strings("info", $clockin);
tc_update_strings("employees", array("tstamp" => $tz_stamp), "empfullname = ?", $fullname);
echo "<head>\n";
echo "<meta http-equiv='refresh' content=0;url=index.php>\n";
echo "</head>\n";
} else {
echo " <td align=left class=right_main scope=col>\n";
echo " <table width=100% height=100% border=0 cellpadding=10 cellspacing=1>\n";
echo " <tr class=right_main_text>\n";
echo " <td valign=top>\n";
echo "<br />\n";
echo "You have entered the wrong password for $emp_name. Please try again.";
include 'footer.php';
exit;
}
}
}
?>