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
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
|
<!DOCTYPE html> <html> <head> <?php require_once '../include/head.php'; ?> <?php require_once '../include/checkuser.php'; ?> <?php require_once '../include/Nav_bar.php'; ?> <?php include_once '../include/DBConnect.php'; ?> <script> $(function() { $('.date-picker').datetimepicker({pickTime: false}); $('#search_form').validate(); $('.time').timepicker({'step': 15, 'timeFormat': 'H:i', 'minTime': '06:00', 'maxTime': '23:30'}); $('.staff_name').select2(); $('.stun').select2(); $('.searchstun').select2(); }); function check_change(e) { $('#tablehead tr:nth-child(' + (e + 2) + ') input[type=checkbox] ').attr("checked", true); } </script> <?php if (isset($_POST['go'])) { ?> <script> $(function() { $('#staff_name').select2().select2('val', '<?= $_POST['staff_name'] ?>'); $('#stun').select2().select2('val', '<?= $_POST['searchstun'] ?>'); }); </script> <?php } ?> </head> <body> <?php //Dim data $countstaff = 0; $staffid = ""; $startdate = date('Y-m-d'); $enddate = date('Y-m-d'); $today = date('Y-m-d'); ?> <?php if (isset($_POST['save'])) { //insert data $startdate = $_POST['startdate']; $enddate = $_POST['enddate']; for ($i = strtotime($startdate); $i <= strtotime($enddate); $i = $i + 86400) { $countstaff = 0; $countstudent = 0; $today = date('Y-m-d', $i); foreach ($_POST["staffid_$today"] as $insertid) { if (isset($_POST["check_$today"][$countstaff]) && $_POST["check_$today"][$countstaff] = '1') { $sth = $dbh->prepare("UPDATE attendance SET deleted = 1 WHERE staff_id = ? and date = ?"); $sth->bindParam(1, $insertid); $sth->bindParam(2, $today); $sth->execute(); $sth = $dbh->prepare("INSERT INTO `attendance`(`createby`, `createdate`, `lastupby`, `lastupdate`, `actived`, `deleted`, `staff_id`, `stu_linking_id`, `date`, `attendance`, `in_time`, `out_time`, `reason_id`) VALUES (1, now(), 1 ,now(),1,0,?,NULL,?,?,?,?,?) "); $sth->bindParam(1, $insertid); $sth->bindParam(2, $today); $sth->bindParam(3, $_POST["staffr_$countstaff"][$today]); $sth->bindParam(4, $_POST["start_time_$countstaff"][$today]); $sth->bindParam(5, $_POST["end_time_$countstaff"][$today]); $sth->bindParam(6, $_POST["reason_$countstaff"][$today]); $sth->execute(); } if (isset($_POST["nocheck_$today"][$countstaff])) { $sth = $dbh->prepare("INSERT INTO `attendance`(`createby`, `createdate`, `lastupby`, `lastupdate`, `actived`, `deleted`, `staff_id`, `stu_linking_id`, `date`, `attendance`, `in_time`, `out_time`, `reason_id`) VALUES (1, now(), 1 ,now(),1,0,?,NULL,?,?,?,?,?) "); $sth->bindParam(1, $insertid); $sth->bindParam(2, $today); $sth->bindParam(3, $_POST["staffr_$countstaff"][$today]); $sth->bindParam(4, $_POST["start_time_$countstaff"][$today]); $sth->bindParam(5, $_POST["end_time_$countstaff"][$today]); $sth->bindParam(6, $_POST["reason_$countstaff"][$today]); $sth->execute(); } $countstaff++; } if (isset($_POST["stuid_$today"])) { foreach ($_POST["stuid_$today"] as $insertid) { if (isset($_POST["check_$today"][$countstudent]) && $_POST["check_$today"][$countstudent] = '1') { $sth = $dbh->prepare("UPDATE attendance SET deleted = 1 WHERE stu_linking_id = ? and date = ?"); $sth->bindParam(1, $insertid); $sth->bindParam(2, $today); $sth->execute(); $sth = $dbh->prepare("INSERT INTO `attendance`(`createby`, `createdate`, `lastupby`, `lastupdate`, `actived`, `deleted`, `staff_id`, `stu_linking_id`, `date`, `attendance`, `in_time`, `out_time`, `reason_id`) VALUES (1, now(), 1 ,now(),1,0,NULL,?,?,?,?,?,?) "); $sth->bindParam(1, $insertid); $sth->bindParam(2, $today); $sth->bindParam(3, $_POST["stur_$countstudent"][$today]); $sth->bindParam(4, $_POST["stu_start_time_$countstudent"][$today]); $sth->bindParam(5, $_POST["stu_end_time_$countstudent"][$today]); $sth->bindParam(6, $_POST["stu_reason_$countstudent"][$today]); $sth->execute(); } $countstudent++; } } } echo "<script>alert('Add successful.')</script>"; } if (isset($_POST['addstu']) && $_POST['stun'] != "student_name") { $adddate = $_POST['studate']; $stuname = $_POST['stun']; $stid; $searchstid = "select root_id from student where deleted = 0 and CONCAT(last_name, ' ', first_name) = '$stuname'"; $result = $dbh->query($searchstid); $result->setFetchMode(PDO::FETCH_OBJ); while ($row = $result->fetch()) { $stid = $row->root_id; } $sth = $dbh->prepare("INSERT INTO `attendance`(`createby`, `createdate`, `lastupby`, `lastupdate`, `actived`, `deleted`, `staff_id`, `stu_linking_id`, `date`, `attendance`, `in_time`, `out_time`, `reason_id`) VALUES (1, now(), 1 ,now(),1,0,NULL,?,?,1,?,?,0) "); $sth->bindParam(1, $stid); $sth->bindParam(2, $adddate); $sth->bindParam(3, $_POST['start_time_stu']); $sth->bindParam(4, $_POST['end_time_stu']); $sth->execute(); } ?> <!-- line between nav bar and content --> <div class="text-right"> <ul class="breadcrumb"> <li class="active">Daily Attendance</li> </ul> </div> <!-- line between nav bar and content --> <div class="container-fluid pathways-container"> <h3>Daily Attendance</h3> <div class="pathways-search"> <form id="search_form" class="form-inline" action="" method="POST"> <div class="pathways-inline-block"> <label class="">Date</label> <div class="input-append date-picker"> <input id="start_date" class="dateISO" type="text" maxlength="200" data-format="yyyy-MM-dd" name="startdate" value="<?php if (isset($_POST['go'])) echo $_POST['startdate']; else echo $startdate; ?>" style="width:90px" required> <span class="add-on"> <i class="icon-calendar" data-date-icon="icon-calendar" data-time-icon="icon-time"></i> </span> </div>
<label class="" >To</label> <div class="input-append date-picker"> <input id="end_date" class="dateISO" type="text" maxlength="200" data-format="yyyy-MM-dd" name="enddate" value="<?php if (isset($_POST['go'])) echo $_POST['enddate']; else echo $enddate; ?>" style="width:90px" required> <span class="add-on"> <i class="icon-calendar" data-date-icon="icon-calendar" data-time-icon="icon-time"></i> </span> </div> </div> <div class="pathways-inline-block"> <label>Student</label> <select name="searchstun" id="stun" class="stun" style="width:170px"> <option value="ALL">All</option> <?php $sth = $dbh->query("SELECT linking_id,`New_stu_ID` id,CONCAT(last_name, ' ', first_name) studentname,`ch_name`FROM `student` WHERE `actived`=1 and`deleted`=0 group by `New_stu_ID`,`Sem_yr`"); ?> <?php while ($ResultSet = $sth->fetch(PDO::FETCH_ASSOC)) { ?> <option value="<?= $ResultSet['studentname']; ?>"><?= $ResultSet['studentname'] ?></option> <?php } ?> </select> </div> <div class="pathways-inline-block"> <label>Staff Name</label> <select name="staff_name" id="staff_name" class="staff_name" style="width: 200px"> <option value="ALL">All</option> <?php $sth = $dbh->query("SELECT CONCAT(`last_name`,' ',`first_name`) staffname, `ch_name` , `staff_id` FROM `staff` WHERE `actived`=1 and `deleted`=0 group by `staff_id`"); ?> <?php while ($ResultSet = $sth->fetch(PDO::FETCH_ASSOC)) { ?> <option value="<?= $ResultSet['staffname'] ?>" ><?= $ResultSet['staffname'] ?></option> <?php } ?> </select> </div> <div class="pathways-inline-block"> <button class="btn" name="go" value="go" style="margin-left:30px" type="submit">GO</button> <input type="hidden" name="staffid[]" value=""> </div> <hr> <div class="pathways-inline-block"> <label>Add Student</label> <select name="stun" id="stun" class="stun" style="width:170px"> <option value="student_name"></option> <?php $sth = $dbh->query("SELECT linking_id,`New_stu_ID` id,CONCAT(last_name, ' ', first_name) studentname,`ch_name`FROM `student` WHERE `actived`=1 and`deleted`=0 group by `New_stu_ID`,`Sem_yr`"); ?> <?php while ($ResultSet = $sth->fetch(PDO::FETCH_ASSOC)) { ?> <option value="<?= $ResultSet['studentname'] ?>"><?= $ResultSet['studentname'] ?></option> <?php } ?> </select> </div> <label class="">In time</label> <div class="pathways-inline-block"> <input id="start_time" type="text" class="time" name = "start_time_stu" style = "width:45px"> </div> <label class="">Out time</label> <div class="pathways-inline-block"> <input id="end_time" type="text" class="time" name = "end_time_stu" style = "width:45px"> </div> <label class="" >Date</label> <div class="input-append date-picker"> <input id="end_date" class="dateISO" type="text" maxlength="200" data-format="yyyy-MM-dd" name="studate" style="width:90px" value="<?= $today ?>"> <span class="add-on"> <i class="icon-calendar" data-date-icon="icon-calendar" data-time-icon="icon-time"></i> </span> </div> <div class="input-append date-picker"> <button class="btn" name="addstu" value="addstu" style="margin-left:30px" type="submit">ADD</button> </div>
</form> </div> <!-- date picker -->
<?php if (isset($_POST['go'])) { $searchstudent = NULL; $searchstaff = NULL; $startdate = $_POST['startdate']; $enddate = $_POST['enddate']; if ($_POST['staff_name'] != "ALL") $searchstaff = " CONCAT(s.last_name, ' ', s.first_name) = '" . $_POST['staff_name'] . "' and "; if ($_POST['staff_name'] != "ALL" && $_POST['searchstun'] == "ALL") $searchstudent = " CONCAT(stu.last_name, ' ', stu.first_name) = 'no search' and "; if ($_POST['searchstun'] != "ALL") $searchstudent = " CONCAT(stu.last_name, ' ', stu.first_name) = '" . $_POST['searchstun'] . "' and "; if ($_POST['searchstun'] != "ALL" && $_POST['staff_name'] == "ALL") $searchstaff = " CONCAT(s.last_name, ' ', s.first_name) = 'no search' and "; //search data ?> <form id="form" action="" method="POST"> <?php for ($i = strtotime($startdate); $i <= strtotime($enddate); $i = $i + 86400) { $hvrecord = false; $today = date('Y-m-d', $i); ?> <h5>Date: <?= $today ?></h5> <table class="table table-striped table-bordered table-hover table-condensed" id="tablehead"> <thead> <tr> <th >Name</th> <th style="min-width:50px; width:50px">Type</th> <th style="min-width:150px; width:150px">In Time</th> <th style="min-width:150px; width:150px">Out Time</th> <th style="min-width:250px; width:250px">Attendance</th> <th style="min-width:200px; width:200px">Reason(If Absent)</th> </tr> </thead> <tbody> <?php $search = "select date from attendance where deleted = 0 and staff_id in (select staff_id from attendance where staff_id <> 'NULL') group by date"; $sdate = $dbh->query($search); $sdate->setFetchMode(PDO::FETCH_OBJ); while ($sd = $sdate->fetch()) { if ($sd->date == $today) $hvrecord = true; } ?> <tr style='display: none;'><input type="hidden" name="startdate" value="<?= $startdate ?>"> <input type="hidden" name="enddate" value="<?= $enddate ?>"></tr> <?php if ($searchstaff != " CONCAT(s.last_name, ' ', s.first_name) = 'no search' and " || $searchstudent == " CONCAT(stu.last_name, ' ', stu.first_name) = 'no search' and ") { if ($hvrecord) { $countstaff = 0; $query1 = "select s.last_name as ln, s.first_name as fn, a.reason_id as reid, a.attendance as attend, a.in_time as it, a.out_time as ot, a.staff_id as id from attendance a, staff s, reason r, student stu where " . $searchstaff . "a.staff_id = s.staff_id and date = '$today' and a.deleted = 0 and r.deleted = 0 group by a.attend_id"; $result = $dbh->query($query1); $result->setFetchMode(PDO::FETCH_OBJ); ?> <?php while ($row = $result->fetch()) { ?> <tr> <td ><input style='display: none;' type ="checkbox" name ="check_<?= $today ?>[<?= $countstaff ?>]" value="1"><h5><?php echo $row->ln . " " . $row->fn ?></h5></td> <td style='display: none;'> <input type="hidden" name="staffid_<?= $today ?>[]" value="<?= $row->id ?>"></td> <td>Teacher</td> <td> <input onclick="check_change(<?= $countstaff ?>);" id="start_time" type="text" class="time" name = "start_time_<?= $countstaff ?>[<?= $today ?>]" style = "width:45px" value="<?= $row->it ?>"> </td> <td> <input onclick="check_change(<?= $countstaff ?>);" id="end_time" type="text" class="time" name = "end_time_<?= $countstaff ?>[<?= $today ?>]" style = "width:45px" value="<?= $row->ot ?>"> </td> <td> <div class="pathways-inline-block" style="margin-right:0px"> <label class="radio inline"> <?php // if ($row->attend == 1) { // echo "<script>$(function(){ document.getElementById('staffp$countstaff$today').checked = true;});</script>"; // } else { // echo "<script>$(function(){ document.getElementById('staffa$countstaff$today').checked = true;});</script>"; // } ?> <input <?php if ($row->attend == 1) { ?>checked <?php } else echo""; ?> onclick="check_change(<?= $countstaff ?>);" type="radio" id = "staffp<?= $countstaff ?><?= $today ?>" name="staffr_<?= $countstaff ?>[<?= $today ?>]" value="1"/> Present </label> <label class="radio inline"> <input <?php if ($row->attend == 0) { ?>checked <?php } ?> onclick="check_change(<?= $countstaff ?>);" type="radio" id = "staffa<?= $countstaff ?><?= $today ?>" name="staffr_<?= $countstaff ?>[<?= $today ?>]" value="0"/> Absent </label> <!--span class="label label-important" style="margin-left:10px">Still not save</span--> </div> </td> <td> <select onclick="check_change(<?= $countstaff ?>);" id="reason" name="reason_<?= $countstaff ?>[<?= $today ?>]" class="input-medium"> <option value="0"> </option> <?php $query = "select reason_id, reason_name from reason "; $resultr = $dbh->query($query); $resultr->setFetchMode(PDO::FETCH_OBJ); while ($rowr = $resultr->fetch()) { ?> <option <?php if ($row->reid == $rowr->reason_id) { ?> selected <?php } ?>value="<?= $rowr->reason_id ?>"><?= $rowr->reason_name ?></option> <?php } ?> </select> </td> </tr> <?php $countstaff++; } } } if ($hvrecord == false && $searchstaff == NULL && $searchstudent == NULL) { $countstaff = 0; $query2 = "select staff_id as id, first_name as fn, last_name as ln from staff where deleted = 0"; $result = $dbh->query($query2); $result->setFetchMode(PDO::FETCH_OBJ); ?> <tbody> <?php while ($row = $result->fetch()) { ?> <tr> <input type="hidden" name="staffid_<?= $today ?>[]" value="<?= $row->id ?>"> <input type="hidden" name="nocheck_<?= $today ?>[<?= $countstaff ?>]" value="1"> <td> <h5><?php echo $row->ln . " " . $row->fn ?></h5> </td> <td>Teacher</td> <td> <input id="start_time" type="text" class="time" name = "start_time_<?= $countstaff ?>[<?= $today ?>]" style = "width:45px"> </td> <td> <input id="end_time" type="text" class="time" name = "end_time_<?= $countstaff ?>[<?= $today ?>]" style = "width:45px"> </td> <td> <div class="pathways-inline-block" style="margin-right:0px"> <label class="radio inline"> <input type="radio" id = "staffp" name="staffr_<?= $countstaff ?>[<?= $today ?>]" value="1" checked="" /> Present </label> <label class="radio inline"> <input type="radio" id = "staffa" name="staffr_<?= $countstaff ?>[<?= $today ?>]" value="0"/> Absent </label> <span class="label label-important" style="margin-left:10px">Still not save</span> </div> </td> <td> <div class="pathways-inline-block"> <select id="reason" name="reason_<?= $countstaff ?>[<?= $today ?>]" class="input-medium" value="reason" > <option value="0"> </option> <?php $query = "select reason_id, reason_name from reason "; $result = $dbh->query($query); $result->setFetchMode(PDO::FETCH_OBJ); while ($rowr = $result->fetch()) { ?> <option value="<?= $rowr->reason_id ?>"><?= $rowr->reason_name ?></option> <?php } ?> </select> </div> </td> </tr> <?php $countstaff++; } } if ($searchstudent != " CONCAT(s.last_name, ' ', s.first_name) = 'no search' and ") { $countstudent = 0; $stu = "select a.stu_linking_id as stuid, stu.last_name as stuln, stu.first_name as stufn, a.attendance as stuattend, a.in_time as stuit, a.out_time as stuot, a.reason_id as stureid from attendance a, student stu where " . $searchstudent . " a.stu_linking_id = stu.root_id and date = '$today' and a.deleted = 0 group by a.attend_id"; $resstu = $dbh->query($stu); $resstu->setFetchMode(PDO::FETCH_OBJ); ?> <?php while ($rowstu = $resstu->fetch()) { ?> <tr> <input type="hidden" name="stuid_<?= $today ?>[]" value="<?= $rowstu->stuid ?>"> <td><input style='display: none;' type ="checkbox" name ="check_<?= $today ?>[<?= $countstudent ?>]" value="1"><h5><?php echo $rowstu->stuln . " " . $rowstu->stufn ?></h5></td> <td>Student</td> <td> <input onclick="check_change(<?= ($countstudent + $countstaff) ?>);" id="start_time" type="text" class="time" name = "stu_start_time_<?= $countstudent ?>[<?= $today ?>]" style = "width:45px" value="<?= $rowstu->stuit ?>"> </td> <td> <input onclick="check_change(<?= ($countstudent + $countstaff) ?>);" id="end_time" type="text" class="time" name = "stu_end_time_<?= $countstudent ?>[<?= $today ?>]" style = "width:45px" value="<?= $rowstu->stuot ?>"> </td> <td> <div class="pathways-inline-block" style="margin-right:0px"> <label class="radio inline"> <?php // if ($rowstu->stuattend == 1) { // echo "<script>$(function(){ document.getElementById('stup$countstudent$today').checked = true;});</script>"; // } else { // echo "<script>$(function(){ document.getElementById('stua$countstudent$today').checked = true;});</script>"; // } ?> <input onclick="check_change(<?= ($countstudent + $countstaff) ?>);" <?php if ($rowstu->stuattend == 1) { ?>checked <?php } ?> type="radio" id = "stup<?= $countstudent ?><?= $today ?>" name="stur_<?= $countstudent ?>[<?= $today ?>]" value="1"/> Present </label> <label class="radio inline"> <input onclick="check_change(<?= ($countstudent + $countstaff) ?>);" <?php if ($rowstu->stuattend == 0) { ?>checked <?php } ?> type="radio" id = "stua<?= $countstudent ?><?= $today ?>" name="stur_<?= $countstudent ?>[<?= $today ?>]" value="0"/> Absent </label> <!--span class="label label-important" style="margin-left:10px">Still not save</span--> </div> </td> <td> <select onclick="check_change(<?= $countstudent + $countstaff ?>);" id="reason" name="stu_reason_<?= $countstudent ?>[<?= $today ?>]" class="input-medium"> <option value="0"> </option> <?php $query = "select reason_id, reason_name from reason "; $resultr = $dbh->query($query); $resultr->setFetchMode(PDO::FETCH_OBJ); while ($rowr = $resultr->fetch()) { ?> <option <?php if ($rowstu->stureid == $rowr->reason_id) { ?> selected <?php } ?>value="<?= $rowr->reason_id ?>"><?= $rowr->reason_name ?></option> <?php } ?> </select> </td> </tr> <?php $countstudent++; } } ?> </tbody> </table> <?php } ?> <input type="submit" name="save" value="save" class="btn btn-danger" onclick=""> </form> <?php } ?>
</div> <!-- /container -->
</body> </html>
|