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
|
<!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'); $reason = array(); array_push($reason, ''); $sth = $dbh->query("SELECT `reason_name` reason_name FROM `reason` WHERE `actived`=1 and `deleted`=0"); while ($ResultSet = $sth->fetch(PDO::FETCH_ASSOC)) { array_push($reason, $ResultSet['reason_name']); } ?> <?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"> <div> <table border="0" width="100%"> <tr> <td><h2>Daily Attendance</h2></td> <td><a href="attendance_add.php" class="btn pull-right"><i class="icon-plus"></i> Add</a></td> </tr> </table> </div> <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">Search</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(last_name, ' ', first_name) = '" . $_POST['staff_name'] . "' and "; if ($_POST['staff_name'] != "ALL" && $_POST['searchstun'] == "ALL") $searchstudent = " CONCAT(last_name, ' ', first_name) = 'no search' and "; if ($_POST['searchstun'] != "ALL") $searchstudent = " CONCAT(last_name, ' ', first_name) = '" . $_POST['searchstun'] . "' and "; if ($_POST['searchstun'] != "ALL" && $_POST['staff_name'] == "ALL") $searchstaff = " CONCAT(last_name, ' ', first_name) = 'no search' and "; //search data ?> <form id="form" action="" method="POST"> <?php for ($i = strtotime($startdate); $i <= strtotime($enddate); $i = $i + 86400) { $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 $query = "select CONCAT(last_name, ' ', first_name,'(',ch_name,')') name, root_id, staff_punch_id from staff where actived = 1 and".$searchstaff." deleted = 0"; //$search = "select date from attendance where deleted = 0 and staff_id in (select staff_id from attendance where staff_id <> 'NULL') group by date"; $searchstaff1 = $dbh->query($query); $searchstaff1->setFetchMode(PDO::FETCH_OBJ); while ($row = $searchstaff1->fetch()) { $empquery = "select MAX( DATE_FORMAT(`punchtime`, '%H:%i')) as out_time , MIN( DATE_FORMAT(`punchtime`, '%H:%i')) as in_time from attendpunch where empid = '$row->staff_punch_id' and DATE_FORMAT(`punchtime`, '%Y-%m-%d') = '$today' "; $searchattend = $dbh->query($empquery); $searchattend->setFetchMode(PDO::FETCH_OBJ); while ($row1 = $searchattend->fetch()) { if ($row1->in_time != NULL && $row1->out_time != NULL) { ?> <tr> <td><h5><?= $row->name ?></h5></td> <td><h5>Teacher</h5></td> <td><h5><?= $row1->in_time ?></h5></td> <td><h5><?= $row1->out_time ?></h5></td> <td><h5>Present</h5></td> <td><h5>No reason</h5></td> </tr> <?php } else { $haveleave = false; $leavequery = "select leave_id, reason_id from leave_app where deleted = 0 and staff_id = '$row->root_id' and '$today' between date(start_date) and date(end_date)"; $searchleave = $dbh->query($leavequery); $searchleave->setFetchMode(PDO::FETCH_OBJ); while ($row2 = $searchleave->fetch()) { $haveleave = true; ?> <tr> <td><h5><?= $row->name ?></h5></td> <td><h5>Teacher</h5></td> <td><h5>NULL</h5></td> <td><h5>NULL</h5></td> <td><h5>Absent</h5></td> <td><h5><?= $reason[$row2->reason_id] ?></h5></td> </tr> <?php } if ($haveleave == false) { ?> <tr> <td><h5><?= $row->name ?></h5></td> <td><h5>Teacher</h5></td> <td><h5>NULL</h5></td> <td><h5>NULL</h5></td> <td><h5>Absent</h5></td> <td><h5>No reason Absent</h5></td> </tr> <?php } } } } $query2 = "select CONCAT(last_name, ' ', first_name,'(',ch_name,')') name, root_id, stu_punch_id from student where actived = 1 and ".$searchstudent." deleted = 0"; //$search = "select date from attendance where deleted = 0 and staff_id in (select staff_id from attendance where staff_id <> 'NULL') group by date"; $searchstu = $dbh->query($query2); $searchstu->setFetchMode(PDO::FETCH_OBJ); while ($row3 = $searchstu->fetch()) { $empquery = "select MAX( DATE_FORMAT(`punchtime`, '%H:%i')) as out_time , MIN( DATE_FORMAT(`punchtime`, '%H:%i')) as in_time from attendpunch where empid = '$row3->stu_punch_id' and DATE_FORMAT(`punchtime`, '%Y-%m-%d') = '$today' "; $searchattend = $dbh->query($empquery); $searchattend->setFetchMode(PDO::FETCH_OBJ); while ($row4 = $searchattend->fetch()) { if ($row4->in_time != NULL && $row4->out_time != NULL) { ?> <tr> <td><h5><?= $row3->name ?></h5></td> <td><h5>Student</h5></td> <td><h5><?= $row4->in_time ?></h5></td> <td><h5><?= $row4->out_time ?></h5></td> <td><h5>Present</h5></td> <td><h5>No reason</h5></td> </tr> <?php } } } ?> </tbody> </table> <?php } ?> </form> <?php } ?>
</div> <!-- /container -->
</body> </html>
|