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
|
<!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}); $('#startdate').datetimepicker().on('changeDate', function(ev) { var date = new Date($('#start_date').val()); $('#enddate').datetimepicker('setStartDate', date); $('#enddate').datetimepicker('setDate', date); $('#enddate').datetimepicker('show'); $('#startdate').datetimepicker('hide'); $('#enddate').datetimepicker('remove'); }); $('#search_form').validate(); $('.time').timepicker({'step': 15, 'timeFormat': 'H:i', 'minTime': '06:00', 'maxTime': '23:30'}); $('.stun').select2(); $('.staff_name').select2(); }); </script> <?php if (isset($_POST['go'])) { ?> <script> $(function() { $('#stun').select2().select2('val', '<?= $_POST['stun'] ?>'); $('#staff_name').select2().select2('val', '<?= $_POST['staff_name'] ?>'); }); </script> <?php } ?> </head> <body> <?php $countlesson = 0; $countstaff = 0; $countstudent = 1; $studentid = ""; $staffid = ""; $startdate = date('Y-m-d'); $enddate = date('Y-m-d'); $today = date('Y-m-d');
if (isset($_POST['save'])) { if (isset($_POST['startdate']) && isset($_POST['enddate'])) { $startdate = $_POST['startdate']; $enddate = $_POST['enddate']; } for ($i = strtotime($startdate); $i <= strtotime($enddate); $i = $i + 86400) { $today = date('Y-m-d', $i); $countstaff = 0; $countstudent = 1; $countlesson = 0; $hvrecord = false; $search = "select date from lesson_attendance where deleted = 0 group by date"; $evdate = $dbh->query($search); $evdate->setFetchMode(PDO::FETCH_OBJ); while ($sd = $evdate->fetch()) { if ($sd->date == $today) $hvrecord = true; } if ($hvrecord) { foreach ($_POST["lessonid_$today"] as $lid) { if (isset($_POST["staffid_" . $today . "_$lid"])) { foreach ($_POST["staffid_" . $today . "_$lid"] as $insertid) { $sth = $dbh->prepare("UPDATE lesson_attendance SET deleted = 1 WHERE staff_id = ? and date = ? and lesson_id = ?"); $sth->bindParam(1, $insertid); $sth->bindParam(2, $today); $sth->bindParam(3, $lid); $sth->execute(); $sth = $dbh->prepare("INSERT INTO `lesson_attendance`(`lesson_id`, `createby`, `createdate`, `lastupby`, `lastupdate`, `actived`, `deleted`, `stu_linking_id`, `staff_id`, `attendance`, `date`, `in_time`, `out_time`, `rate_type`, `payroll_gened`, `invoice_gened`, `is_charge`, `package_discount`, `is_substitute`, `reason_id`) VALUES (?,1,now(),1,now(),1,0,NULL,?,?,?,?,?,?,?,?,?,?,?,?)"); $sth->bindParam(1, $lid); $sth->bindParam(2, $insertid); $sth->bindParam(3, $_POST["staffr_" . $countstaff . "_$lid"][$today]); $sth->bindParam(4, $today); $sth->bindParam(5, $_POST["start_time_" . $countstaff . "_$lid"][$today]); $sth->bindParam(6, $_POST["end_time_" . $countstaff . "_$lid"][$today]); $sth->bindParam(7, $_POST["rate_" . $countstaff . "_$lid"]); $sth->bindParam(8, $_POST["payroll_gened_" . $countstaff . "_$lid"]); $sth->bindParam(9, $_POST["invoice_gened_" . $countstaff . "_$lid"]); $sth->bindParam(10, $_POST["is_charge_" . $countstaff . "_$lid"]); $sth->bindParam(11, $_POST["package_discount_" . $countstaff . "_$lid"]); $sth->bindParam(12, $_POST["is_substitute_" . $countstaff . "_$lid"]); $sth->bindParam(13, $_POST["reason_" . $countstaff . "_$lid"][$today]); $sth->execute(); $countstaff +=2; $countlesson++; echo $insertid; } } $countlesson = 0; if (isset($_POST["stuid_" . $today . "_$lid"])) { foreach ($_POST["stuid_" . $today . "_$lid"] as $insertid) { $sth = $dbh->prepare("UPDATE lesson_attendance SET deleted = 1 WHERE stu_linking_id = ? and date = ? and lesson_id = ?"); $sth->bindParam(1, $insertid); $sth->bindParam(2, $today); $sth->bindParam(3, $lid); $sth->execute(); $sth = $dbh->prepare("INSERT INTO `lesson_attendance`(`lesson_id`, `createby`, `createdate`, `lastupby`, `lastupdate`, `actived`, `deleted`, `stu_linking_id`, `staff_id`, `attendance`, `date`, `in_time`, `out_time`, `rate_type`, `payroll_gened`, `invoice_gened`, `is_charge`, `package_discount`, `is_substitute`, `reason_id`) VALUES (?,1,now(),1,now(),1,0,?,NULL,?,?,?,?,'0.0',?,?,?,?,?,?)"); $sth->bindParam(1, $lid); $sth->bindParam(2, $insertid); $sth->bindParam(3, $_POST["stur_" . $countstudent . "_$lid"][$today]); $sth->bindParam(4, $today); $sth->bindParam(5, $_POST["start_time_" . $countstudent . "_$lid"][$today]); $sth->bindParam(6, $_POST["end_time_" . $countstudent . "_$lid"][$today]); $sth->bindParam(7, $_POST["payroll_gened_" . $countstudent . "_$lid"]); $sth->bindParam(8, $_POST["invoice_gened_" . $countstudent . "_$lid"]); $sth->bindParam(9, $_POST["is_charge_" . $countstudent . "_$lid"]); $sth->bindParam(10, $_POST["package_discount_" . $countstudent . "_$lid"]); $sth->bindParam(11, $_POST["is_substitute_" . $countstudent . "_$lid"]); $sth->bindParam(12, $_POST["reason_" . $countstudent . "_$lid"][$today]); $sth->execute(); $countstudent +=2; $countlesson++; } } } } } echo "<script>alert('Add successful.')</script>"; } ?> <!-- line between nav bar and content --> <div class="text-right"> <ul class="breadcrumb"> <li class="active">Event Attendance</li> </ul> </div> <!-- line between nav bar and content --> <div class="container-fluid pathways-container"> <h3>Event Attendance</h3> <div class="pathways-search"> <form id="search_form" class="form-inline" action="" method="POST"> <div class="pathways-inline-block"> <label class="" id="event_code" name="event_code">Event Code</label> <input type="text" id="event_code" name="event_code" class="input-medium" placeholder="Event Code" value="<?php if (isset($_POST['go'])) echo $_POST['event_code']; ?>"> </div> <div class="pathways-inline-block"> <label class="" id="program" name="program">Program</label> <select id="program" name="program" class="input-medium" value="program" > <option value="ALL">ALL</option> <?php $query = "select program_code from program "; $result = $dbh->query($query); $result->setFetchMode(PDO::FETCH_OBJ); while ($row = $result->fetch()) { ?> <option <?php if (isset($_POST['go'])) if ($_POST['program'] == $row->program_code) { ?> selected <?php } ?> value ="<?= $row->program_code ?>"><?= $row->program_code ?></option> <?php } ?> </select> </div> <div class="pathways-inline-block"> <label class="" id="program" name="subject" value="subject" >Subject</label> <select id="subject" name="subject" class="input-medium" > <option value="ALL">ALL</option> <?php $query = "select sub_code from subject "; $result = $dbh->query($query); $result->setFetchMode(PDO::FETCH_OBJ); while ($row = $result->fetch()) { ?> <option <?php if (isset($_POST['go'])) if ($_POST['subject'] == $row->sub_code) { ?> selected <?php } ?> value ="<?= $row->sub_code ?>"><?= $row->sub_code ?></option> <?php } s ?> </select>
</div> <div class="pathways-inline-block"> <label class="">Date</label> <div class="input-append date-picker" id="startdate"> <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" id="enddate"> <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="stun" 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> </form> </div> <!-- date picker --> <?php if (isset($_POST['go'])) { $program = NULL; $event_code = NULL; $subject = NULL; $searchstudent = NULL; $searchstaff = NULL; $startdate = $_POST['startdate']; $enddate = $_POST['enddate']; if (!empty($_POST['event_code'])) $event_code = "e.event_code ='" . $_POST['event_code'] . "' and "; if ($_POST['program'] != 'ALL') $program = "p.program_code ='" . $_POST['program'] . "' and "; if ($_POST['subject'] != 'ALL') $subject = "sub.sub_code ='" . $_POST['subject'] . "' and "; if ($_POST['staff_name'] != 'ALL') $searchstaff = " CONCAT(s.last_name, ' ', s.first_name) = '" . $_POST['staff_name'] . "' and "; if ($_POST['staff_name'] != "ALL" && $_POST['stun'] == 'ALL') $searchstudent = " CONCAT(stu.last_name, ' ', stu.first_name) = 'no search' and "; if ($_POST['stun'] != 'ALL') $searchstudent = " CONCAT(stu.last_name, ' ', stu.first_name) = '" . $_POST['stun'] . "' and "; if ($_POST['stun'] != '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); $search = "select date from lesson_attendance where deleted = 0 group by date"; $evdate = $dbh->query($search); $evdate->setFetchMode(PDO::FETCH_OBJ); while ($sd = $evdate->fetch()) { if ($sd->date == $today) $hvrecord = true; } ?> <table class="table table-striped table-bordered table-hover table-condensed"> <thead> <tr> <th >Event Code</th> <th style="min-width:50px; width:50px">Program</th> <th style="min-width:50px; width:50px">Subject </th> <th style="min-width:50px; width:50px">RoomID</th> <th style="min-width:130px; width:130px">Start - End Time </th> <th style="min-width:150px; width:150px">Name</th> <th style="min-width:50px; width:50px">Type</th> <th style="min-width:75px; width:75px">In Time</th> <th style="min-width:75px; width:75px">Out Time</th> <th style="min-width:170px; width:170px">Attendance</th> <th style="min-width:200px; width:200px">Reason(If Absent)</th> </tr> </thead> <?php if ($hvrecord == false) { ?> <h5>Date: <?= $today ?></h5> <tr><td colspan="10"><h5>No lesson</h5></td></tr></table> <?php } if ($hvrecord) { $searchlesson = "select lesson_id from lesson_attendance where deleted = 0 and date='$today' group by lesson_id"; $query1 = "select s.last_name as sln, s.first_name as sfn, date_format(le.start_time, '%h:%i') as lst, date_format(le.end_time, '%h:%i') as let, " . "a.payroll_gened as apg, a.invoice_gened as aig, a.is_charge as aic, a.package_discount as apd, a.is_substitute as ais, a.rate_type as rate, a.attend_id as aid, a.lesson_id as alid, a.attendance as attend, a.in_time as it, a.out_time as ot, a.staff_id as id, a.reason_id as reid, " . "le.room_id, e.event_code as ec, p.program_code as pc, sub.sub_code as sc " . "from lesson_attendance a, staff s, student stu,event e, event_lesson l, program p, subject sub, lesson le " . "where a.staff_id = s.root_id and a.date = '$today' and a.lesson_id = l.lesson_id and l.lesson_id = le.lesson_id and l.event_id = e.event_id and e.program_id = p.program_id and e.subject_id = sub.subject_id and " . $program . $subject . $event_code . $searchstaff . "a.deleted = 0 and s.deleted = 0 and l.deleted = 0 and e.deleted = 0 and p.deleted = 0 and sub.deleted = 0 group by attend_id"; $query2 = "select stu.last_name as stuln, stu.first_name as stufn, date_format(le.start_time, '%h:%i') as lst, date_format(le.end_time, '%h:%i') as let, " . "a.attend_id as aid, a.lesson_id as alid, a.attendance as attend, a.in_time as it, a.out_time as ot, a.stu_linking_id as id, a.reason_id as reid, " . "le.room_id, e.event_code as ec, p.program_code as pc, sub.sub_code as sc " . "from lesson_attendance a, staff s, student stu,event e, event_lesson l, program p, subject sub, lesson le " . "where a.stu_linking_id = stu.root_id and a.date = '$today' and a.lesson_id = l.lesson_id and l.lesson_id = le.lesson_id and l.event_id = e.event_id and e.program_id = p.program_id and e.subject_id = sub.subject_id and " . $program . $subject . $event_code . $searchstudent . "a.deleted = 0 and stu.deleted = 0 and l.deleted = 0 and e.deleted = 0 and p.deleted = 0 and sub.deleted = 0 group by attend_id"; ?> <h5>Date: <?= $today ?></h5> <tbody> <?php $countlesson = 0; $result = $dbh->query($searchlesson); $result->setFetchMode(PDO::FETCH_OBJ); $countstaff = 0; $countstudent = 1; while ($sl = $result->fetch()) { $lid = $sl->lesson_id; $result1 = $dbh->query($query1); $result1->setFetchMode(PDO::FETCH_OBJ); ?> <input type="hidden" name="lessonid_<?= $today ?>[]" value="<?= $lid ?>" > <input type="hidden" name="startdate" value="<?= $startdate ?>"> <input type="hidden" name="enddate" value="<?= $enddate ?>"> <?php while ($row1 = $result1->fetch()) { if ($row1->alid == $lid) { ?> <tr> <input type="hidden" name="staffid_<?= $today ?>_<?= $lid ?>[]" value="<?= $row1->id ?>"> <input type="hidden" name="staid[]" value="<?= $row1->aid ?>"> <input type="hidden" name="rate_<?= $countstaff ?>_<?= $lid ?>" value="<?= $row1->rate ?>"> <input type="hidden" name="payroll_gened_<?= $countstaff ?>_<?= $lid ?>" value="<?= $row1->apg ?>"> <input type="hidden" name="invoice_gened_<?= $countstaff ?>_<?= $lid ?>" value="<?= $row1->aig ?>"> <input type="hidden" name="is_charge_<?= $countstaff ?>_<?= $lid ?>" value="<?= $row1->aic ?>"> <input type="hidden" name="package_discount_<?= $countstaff ?>_<?= $lid ?>" value="<?= $row1->apd ?>"> <input type="hidden" name="is_substitute_<?= $countstaff ?>_<?= $lid ?>" value="<?= $row1->ais ?>"> <td><?php echo $row1->ec ?></td> <td><?php echo $row1->pc ?></td> <td><?php echo $row1->sc ?></td> <td><?php echo $row1->room_id ?></td> <td><?php echo $row1->lst . " - " . $row1->let ?></td> <td><?php echo $row1->sln . " " . $row1->sfn ?></td> <td>Teacher</td> <td> <input id="start_time" type="text" class="time" name = "start_time_<?= $countstaff ?>_<?= $lid ?>[<?= $today ?>]" style = "width:45px" value="<?= $row1->it ?>"> </td> <td> <input id="end_time" type="text" class="time" name = "end_time_<?= $countstaff ?>_<?= $lid ?>[<?= $today ?>]" style = "width:45px" value="<?= $row1->ot ?>"> </td> <td> <div class="pathways-inline-block" style="margin-right:0px"> <label class="radio inline"> <input <?php if ($row1->attend == 1) { ?>checked <?php } ?> type="radio" id = "staffp<?= $countstaff ?><?= $today ?>" name="staffr_<?= $countstaff ?>_<?= $lid ?>[<?= $today ?>]" value="1"/> Present </label> <label class="radio inline"> <input <?php if ($row1->attend == 0) { ?>checked <?php } ?>type="radio" id = "staffa<?= $countstaff ?><?= $today ?>" name="staffr_<?= $countstaff ?>_<?= $lid ?>[<?= $today ?>]" value="0"/> Absent </label> </div> </td> <td> <select id="reason" name="reason_<?= $countstaff ?>_<?= $lid ?>[<?= $today ?>]" class="input-medium" value="reason" > <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 ($row1->reid == $rowr->reason_id) { ?> selected <?php } ?>value="<?= $rowr->reason_id ?>"><?= $rowr->reason_name ?></option> <?php } ?> </select> </td> </tr> <?php $countstaff +=2; } } $result2 = $dbh->query($query2); $result2->setFetchMode(PDO::FETCH_OBJ); while ($row2 = $result2->fetch()) { if ($row2->alid == $lid) { ?> <tr> <input type="hidden" name="stuid_<?= $today ?>_<?= $lid ?>[]" value="<?= $row2->id ?>"> <input type="hidden" name="stuaid[]" value="<?= $row2->aid ?>"> <input type="hidden" name="payroll_gened_<?= $countstudent ?>_<?= $lid ?>" value="<?= $row2->apg ?>"> <input type="hidden" name="invoice_gened_<?= $countstudent ?>_<?= $lid ?>" value="<?= $row2->aig ?>"> <input type="hidden" name="is_charge_<?= $countstudent ?>_<?= $lid ?>" value="<?= $row2->aic ?>"> <input type="hidden" name="package_discount_<?= $countstudent ?>_<?= $lid ?>" value="<?= $row2->apd ?>"> <input type="hidden" name="is_substitute_<?= $countstudent ?>_<?= $lid ?>" value="<?= $row2->ais ?>"> <td><?php echo $row2->ec ?></td> <td><?php echo $row2->pc ?></td> <td><?php echo $row2->sc ?></td> <td><?php echo $row2->room_id ?></td> <td><?php echo $row2->lst . " - " . $row2->let ?></td> <td><?php echo $row2->stuln . " " . $row2->stufn ?></td> <td>Student</td> <td> <input id="start_time" type="text" class="time" name = "start_time_<?= $countstudent ?>_<?= $lid ?>[<?= $today ?>]" style = "width:45px" value="<?= $row2->it ?>"> </td> <td> <input id="end_time" type="text" class="time" name = "end_time_<?= $countstudent ?>_<?= $lid ?>[<?= $today ?>]" style = "width:45px" value="<?= $row2->ot ?>"> </td> <td> <div class="pathways-inline-block" style="margin-right:0px"> <label class="radio inline"> <input <?php if ($row2->attend == 1) { ?>checked <?php } ?> type="radio" id = "stup<?= $countstudent ?><?= $today ?>" name="stur_<?= $countstudent ?>_<?= $lid ?>[<?= $today ?>]" value="1"/> Present </label> <label class="radio inline"> <input <?php if ($row2->attend == 0) { ?>checked <?php } ?> type="radio" id = "stua<?= $countstudent ?><?= $today ?>" name="stur_<?= $countstudent ?>_<?= $lid ?>[<?= $today ?>]" value="0"/> Absent </label> </div> </td> <td> <select id="reason" name="reason_<?= $countstudent ?>_<?= $lid ?>[<?= $today ?>]" class="input-medium" value="reason" > <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 ($row2->reid == $rowr->reason_id) { ?> selected <?php } ?>value="<?= $rowr->reason_id ?>"><?= $rowr->reason_name ?></option> <?php } ?> </select> </td> </tr> <?php $countstudent+=2; } } $countlesson++; } ?> </tbody> </table> <?php } } } ?> <input type="submit" name="save" value="save" class="btn btn-danger"> </form> </div> <!-- /container --> </body> </html>
|