-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtimestamp.php
418 lines (370 loc) Β· 23.3 KB
/
timestamp.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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
<?php
include("header.php");
if(isset($_POST['stamp_on']) OR isset($_GET['stamp_on']))
{
$date = date("Y-m-d H:i:s");
$user_id = $_SESSION['user_id'];
$uid = uniqid();
if(fetch("users","stamped","id",$_SESSION['user_id'])==0)
{
// Set current stamp id
$strSQL = "UPDATE users SET current_ts_id = '$uid' WHERE id LIKE '$user_id'";
$rs=mysqli_query($link,$strSQL);
//Obsolete
//$_SESSION['current_stamp_id']=$uid;
// Stempel-Status setzen
$strSQL = "UPDATE users SET stamped = '1' WHERE id LIKE '$user_id'";
$rs=mysqli_query($link,$strSQL);
//Neuen eintrag im stempel-log
$strSQL = "INSERT INTO timestamp (id,user_id,come,go) VALUES ('$uid','$user_id','$date','0000-00-00 00:00:00')";
$rs=mysqli_query($link,$strSQL);
}
protocol_add($_SESSION['first_name'].' '.$_SESSION['last_name'].' hat Angestempelt.');
echo '<meta http-equiv="refresh" content="0; url=/timestamp?personal_timestamps" />';
}
if(isset($_POST['stamp_off']) OR isset($_GET['stamp_off']))
{
$date = date("Y-m-d H:i:s");
$user_id = $_SESSION['user_id'];
// Test if user is in fact stamped on
if((fetch("users","stamped","id",$_SESSION['user_id']))==1)
{
//get current stamp id
$uid = fetch("users","current_ts_id","id",$_SESSION['user_id']);
// Get current worktimes
$strSQL = "SELECT * FROM timestamp WHERE id LIKE '$uid'";
$rs=mysqli_query($link,$strSQL);
while($row=mysqli_fetch_assoc($rs))
{
// Test if worktime is longer than 10s
if((strtotime(date("Y-m-d H:i:s")) - strtotime($row['come']))<10)
{
// Delete Timestamp entry
$strSQLd = "DELETE FROM timestamp WHERE id LIKE '$uid'";
$rsd=mysqli_query($link,$strSQLd);
// Set stamp state
$strSQLu = "UPDATE users SET stamped = '0' WHERE id LIKE '$user_id'";
$rsu=mysqli_query($link,$strSQLu);
echo '<meta http-equiv="refresh" content="0; url=/timestamp?personal_timestamps&error_time" />';
}
else
{
// Set stamp state
$strSQLu = "UPDATE users SET stamped = '0' WHERE id LIKE '$user_id'";
$rsu=mysqli_query($link,$strSQLu);
// add stamp entry
$strSQLu = "UPDATE timestamp SET go = '$date' WHERE user_id LIKE '$user_id' AND go LIKE '0000-00-00 00:00:00'";
$rsu=mysqli_query($link,$strSQLu);
protocol_add($_SESSION['first_name'].' '.$_SESSION['last_name'].' hat Abgestempelt.');
echo '<meta http-equiv="refresh" content="0; url=/timestamp?personal_timestamps" />';
}
}
}
}
if(isset($_GET['delete']))
{
$tid = $_GET['delete'];
$strSQL = "DELETE FROM timestamp WHERE id LIKE '$tid'";
$rs=mysqli_query($link,$strSQL);
protocol_add($_SESSION['first_name'].' '.$_SESSION['last_name'].' hat eine Stempelzeit entfernt.');
echo '<meta http-equiv="refresh" content="0; url=/timestamp?time_correction&delete_entry" />';
}
if(isset($_POST['update_timestamp']))
{
$tid = $_POST['update_timestamp'];
$come_time = strtotime(str_replace("T"," ",$_POST['come_time']));
$leave_time = strtotime(str_replace("T"," ",$_POST['leave_time']));
$come_t = str_replace("T"," ",$_POST['come_time']);
$leave_t = str_replace("T"," ",$_POST['leave_time']);
if(($leave_time - $come_time) < 0) echo '<meta http-equiv="refresh" content="0; url=/timestamp?time_correction&edit_entry&error_t" />';
else
{
$strSQL = "UPDATE timestamp SET
come = '$come_t',
go = '$leave_t'
WHERE id LIKE '$tid'";
$rs=mysqli_query($link,$strSQL);
protocol_add($_SESSION['first_name'].' '.$_SESSION['last_name'].' hat eine Stempelzeit Aktualisiert.');
echo '<meta http-equiv="refresh" content="0; url=/timestamp?time_correction&edit_entry" />';
}
}
if(isset($_POST['add_timestamp']))
{
$tid = uniqid();
$come_time = strtotime(str_replace("T"," ",$_POST['come_time']));
$leave_time = strtotime(str_replace("T"," ",$_POST['leave_time']));
$user_id = $_SESSION['user_id'];
$come_t = str_replace("T"," ",$_POST['come_time']);
$leave_t = str_replace("T"," ",$_POST['leave_time']);
if(($leave_time - $come_time) < 0) echo '<meta http-equiv="refresh" content="0; url=/timestamp?time_correction&add_entry&error_t" />';
else
{
$strSQL = "INSERT INTO timestamp (id,user_id,come,go) VALUES ('$tid','$user_id','$come_t','$leave_t')";
$rs=mysqli_query($link,$strSQL);
protocol_add($_SESSION['first_name'].' '.$_SESSION['last_name'].' hat eine Stempelzeit nachgetragen.');
echo '<meta http-equiv="refresh" content="0; url=/timestamp?time_correction&edit_entry" />';
}
}
echo '
<div id="fade_in">
<h1>Zeiterfassung</h1>
<div id="content_fade_in">
<form action="/timestamp" method="post" accept-charset="utf-8" enctype="multipart/form-data">
<center>
<div class="content_box_s">
<h2>Zeiterfassung</h2>
';
if(isset($_GET['error_time'])) echo '<span style="color: #CC0000">Arbeitszeiten unter 10s werden nicht angerechnet</span>';
echo '
<br>
';
if(fetch("users","stamped","id",$_SESSION['user_id'])==0)
{
$last_time = get_last_timestamp($_SESSION['user_id']);
echo '
<button type="submit" name="stamp_on" class="button_xl t_button">Anstempeln<br><i><span style="color: #A9A9A9">Kommen</span></i></button>
<br>
<br>
Zuletzt gegangen am <b>'.date("d.m.Y \u\m H:i:s",last_left($_SESSION['user_id'])).'</b>
<br><br>
Letzte Arbeitszeit: <b>'.convert_s_to_date($last_time).'</b>
';
}
else
{
$current_time = get_current_timestamp($_SESSION['user_id']);
echo '
<button type="submit" name="stamp_off" class="button_xl t_button">Abstempeln<br><i><span style="color: #A9A9A9">Gehen</span></i></button>
<br>
<br>
Gekommen am <b>'.date("d.m.Y \u\m H:i:s",last_come($_SESSION['user_id'])).'</b>
<br><br>
Aktuelle Arbeitszeit: <b>'.convert_s_to_date($current_time).'</b>
';
}
echo '
</div>
</center>
</form>
<br>
';
$selected_register1='';
$selected_register2='';
$selected_register3='';
$selected_register4='';
if(isset($_GET['personal_timestamps'])) $selected_register1='id="selected_register"';
if(isset($_GET['other_timestamps'])) $selected_register2='id="selected_register"';
if(isset($_GET['all_timestamps'])) $selected_register3='id="selected_register"';
if(isset($_GET['time_correction'])) $selected_register4='id="selected_register"';
echo '
<a href="timestamp?personal_timestamps"><button type="button" class="button_m t_button" '.$selected_register1.' style="margin-bottom:0px; border-bottom:none; vertical-align:bottom">Deine Stempelzeiten</button></a>
<a href="timestamp?other_timestamps"><button type="button" class="button_m t_button" '.$selected_register2.' style="margin-bottom:0px; border-bottom:none; vertical-align:bottom">Fremde Stempelzeiten</button></a>
<a href="timestamp?all_timestamps"><button type="button" class="button_m t_button" '.$selected_register3.' style="margin-bottom:0px; border-bottom:none; vertical-align:bottom">Alle Stempelzeiten</button></a>
<a href="timestamp?time_correction&add_entry"><button type="button" class="button_m t_button" '.$selected_register4.' style="margin-bottom:0px; border-bottom:none; vertical-align:bottom;">Zeitkorrektur</button></a>
<hr style="margin-top:0px;">
<hr>
';
if(!isset($_GET['time_correction']))
{
echo '
<center>
<table class="timestamp_table">
<tr>
<th class="timestamp_cell" style="font-weight:normal; color: #1E90FF">Nutzer</th>
<th class="timestamp_cell" style="font-weight:normal; color: #1E90FF">Gekommen</th>
<th class="timestamp_cell" style="font-weight:normal; color: #1E90FF">Gegangen</th>
<th class="timestamp_cell" style="font-weight:normal; color: #1E90FF">Zeit gearbeitet</th>
</tr>
';
$i=0;
$strSQL = "SELECT * FROM timestamp ORDER BY come DESC";
$rs=mysqli_query($link,$strSQL);
while($row=mysqli_fetch_assoc($rs))
{
if($i%2 == 0) $style_id = 'id="shaded_cell"';
else $style_id= '';
$show_timestamp = 0;
if(isset($_GET['personal_timestamps']) AND $row['user_id'] == $_SESSION['user_id']) $show_timestamp = 1;
if(isset($_GET['other_timestamps']) AND $row['user_id'] != $_SESSION['user_id']) $show_timestamp = 1;
if(isset($_GET['all_timestamps'])) $show_timestamp = 1;
if($show_timestamp == 1)
{
if($row['go'] != '0000-00-00 00:00:00')
{
echo '
<tr>
<td '.$style_id.' class="timestamp_cell" style="text-align:left;">'.fetch("users","first_name","id",$row['user_id']).' '.fetch("users","last_name","id",$row['user_id']).'</td>
<td '.$style_id.' class="timestamp_cell">'.date("D, d M Y - H:i:s",strtotime($row['come'])).'</td>
<td '.$style_id.' class="timestamp_cell">'.date("D, d M Y - H:i:s",strtotime($row['go'])).'</td>
<td '.$style_id.' class="timestamp_cell">'.convert_s_to_date(strtotime($row['go']) - strtotime($row['come'])).'</td>
</tr>
';
}
else
{
echo '
<tr>
<td '.$style_id.' class="timestamp_cell" style="text-align:left;">'.fetch("users","first_name","id",$row['user_id']).' '.fetch("users","last_name","id",$row['user_id']).'</td>
<td '.$style_id.' class="timestamp_cell">'.date("D, d M Y - H:i:s",strtotime($row['come'])).'</td>
<td '.$style_id.' class="timestamp_cell">---</td>
<td '.$style_id.' class="timestamp_cell">'.convert_s_to_date(strtotime(date("Y-m-d H:i:s")) - strtotime($row['come'])).'</td>
</tr>
';
}
$i++;
}
}
echo '
</table>
</center>
';
}
else
{
$selected_register4_1='';
$selected_register4_2='';
$selected_register4_3='';
if(isset($_GET['add_entry'])) $selected_register4_1='id="selected_register"';
if(isset($_GET['delete_entry'])) $selected_register4_2='id="selected_register"';
if(isset($_GET['edit_entry'])) $selected_register4_3='id="selected_register"';
echo '
<a href="timestamp?time_correction&add_entry"><button type="button" class="button_m t_button" '.$selected_register4_1.' style="margin-bottom:0px; border-bottom:none; vertical-align:bottom;">Zeit Nachtragen</button></a>
<a href="timestamp?time_correction&delete_entry"><button type="button" class="button_m t_button" '.$selected_register4_2.' style="margin-bottom:0px; border-bottom:none; vertical-align:bottom;">Eintrag Löschen</button></a>
<a href="timestamp?time_correction&edit_entry"><button type="button" class="button_m t_button" '.$selected_register4_3.' style="margin-bottom:0px; border-bottom:none; vertical-align:bottom;">Eintrag Bearbeiten</button></a>
<hr style="margin-top:0px;">
';
if(isset($_GET['add_entry']))
{
if(isset($_GET['error_t'])) echo '<center><span style="color: #CC0000">Die "Gehen-Zeit" kann nicht vor der "Kommen-Zeit" sein!</span></center>';
echo '
<form action="/timestamp" method="post" accept-charset="utf-8" enctype="multipart/form-data">
<center>
<br>
<div class="content_box_s">
<h3>Eintrag Bearbeiten</h3>
<br>
Gekommen:
<input type="datetime-local" id="come_time" step="1" name="come_time" class="textfield_m t_textfield">
<br><br>
Gegangen:
<input type="datetime-local" id="leave_time" step="1" name="leave_time" class="textfield_m t_textfield">
<br><br>
<button type="submit" name="add_timestamp" class="button_m t_button">Eintrag Ergänzen</button>
</div>
</center>
</form>
';
}
if(isset($_GET['delete_entry']))
{
echo '
<center>
<table class="timestamp_table">
<tr>
<th class="timestamp_cell" style="font-weight:normal; color: #1E90FF">Option</th>
<th class="timestamp_cell" style="font-weight:normal; color: #1E90FF">Nutzer</th>
<th class="timestamp_cell" style="font-weight:normal; color: #1E90FF">Gekommen</th>
<th class="timestamp_cell" style="font-weight:normal; color: #1E90FF">Gegangen</th>
<th class="timestamp_cell" style="font-weight:normal; color: #1E90FF">Zeit gearbeitet</th>
</tr>
';
$user_id = $_SESSION['user_id'];
$i=0;
$strSQL = "SELECT * FROM timestamp WHERE user_id LIKE '$user_id' AND go NOT LIKE '0000-00-00 00:00:00' ORDER BY come DESC";
$rs=mysqli_query($link,$strSQL);
while($row=mysqli_fetch_assoc($rs))
{
if($i%2 == 0) $style_id = 'id="shaded_cell_gray"';
else $style_id= '';
echo '
<tr>
<td '.$style_id.' class="timestamp_cell"><a href="timestamp?delete='.$row['id'].'"><span style="color: #CC0000">✘ Eintrag Löschen</span></a></td>
<td '.$style_id.' class="timestamp_cell" style="text-align:left;">'.fetch("users","first_name","id",$row['user_id']).' '.fetch("users","last_name","id",$row['user_id']).'</td>
<td '.$style_id.' class="timestamp_cell">'.date("D, d M Y - H:i:s",strtotime($row['come'])).'</td>
<td '.$style_id.' class="timestamp_cell">'.date("D, d M Y - H:i:s",strtotime($row['go'])).'</td>
<td '.$style_id.' class="timestamp_cell">'.convert_s_to_date(strtotime($row['go']) - strtotime($row['come'])).'</td>
</tr>
';
$i++;
}
echo '
</table>
</center>
';
}
if(isset($_GET['edit_entry']))
{
if(isset($_GET['error_t'])) echo '<center><span style="color: #CC0000">Die "Gehen-Zeit" kann nicht vor der "Kommen-Zeit" sein!</span></center>';
if(!isset($_GET['timestamp']))
{
echo '
<center>
<table class="timestamp_table">
<tr>
<th class="timestamp_cell" style="font-weight:normal; color: #1E90FF">Option</th>
<th class="timestamp_cell" style="font-weight:normal; color: #1E90FF">Nutzer</th>
<th class="timestamp_cell" style="font-weight:normal; color: #1E90FF">Gekommen</th>
<th class="timestamp_cell" style="font-weight:normal; color: #1E90FF">Gegangen</th>
<th class="timestamp_cell" style="font-weight:normal; color: #1E90FF">Zeit gearbeitet</th>
</tr>
';
$user_id = $_SESSION['user_id'];
$i=0;
$strSQL = "SELECT * FROM timestamp WHERE user_id LIKE '$user_id' AND go NOT LIKE '0000-00-00 00:00:00' ORDER BY come DESC";
$rs=mysqli_query($link,$strSQL);
while($row=mysqli_fetch_assoc($rs))
{
if($i%2 == 0) $style_id = 'id="shaded_cell_gray"';
else $style_id= '';
echo '
<tr>
<td '.$style_id.' class="timestamp_cell"><a href="/timestamp?time_correction&edit_entry×tamp='.$row['id'].'"><span style="color: #FFA500">✎ Eintrag Bearbeiten</span></a></td>
<td '.$style_id.' class="timestamp_cell" style="text-align:left;">'.fetch("users","first_name","id",$row['user_id']).' '.fetch("users","last_name","id",$row['user_id']).'</td>
<td '.$style_id.' class="timestamp_cell">'.date("D, d M Y - H:i:s",strtotime($row['come'])).'</td>
<td '.$style_id.' class="timestamp_cell">'.date("D, d M Y - H:i:s",strtotime($row['go'])).'</td>
<td '.$style_id.' class="timestamp_cell">'.convert_s_to_date(strtotime($row['go']) - strtotime($row['come'])).'</td>
</tr>
';
$i++;
}
echo '
</table>
</center>
';
}
else
{
echo '
<script>
window.onload = function set_datetime()
{
document.getElementById("come_time").value="'.str_replace(" ","T",fetch("timestamp","come","id",$_GET['timestamp'])).'"
document.getElementById("leave_time").value="'.str_replace(" ","T",fetch("timestamp","go","id",$_GET['timestamp'])).'"
}
</script>
<form action="/timestamp" method="post" accept-charset="utf-8" enctype="multipart/form-data">
<center>
<br>
<div class="content_box_s">
<h3>Eintrag Bearbeiten</h3>
<br>
Gekommen:
<input type="datetime-local" id="come_time" step="1" name="come_time" class="textfield_m t_textfield">
<br><br>
Gegangen:
<input type="datetime-local" id="leave_time" step="1" name="leave_time" class="textfield_m t_textfield">
<br><br>
<button type="submit" name="update_timestamp" class="button_m t_button" value="'.$_GET['timestamp'].'">Eintrag Aktualisieren</button>
</div>
</center>
</form>
';
}
}
}
echo '
</div>
</div>
';
include("footer.php");
?>