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
|
<?php include_once '../include/DBConnect.php';
class Staff {
public static function statusOptions() { return array( 1 => 'Active', 2 => 'Disable', ); }
public static function workingModeOptions() { return array( 1 => 'Full Time', 2 => 'Part Time', ); }
public static function attendanceLeaveOptions() { return array( 1 => 'Teacher Sick Leave', 2 => 'Annual Leave', 3 => 'Casual Leave', 4 => 'Students absent', 5 => 'No pay Lesson', ); }
}
$deleted = 0; $query = "select * from staff where deleted = ? ORDER BY staff_id"; $result = $dbh->prepare($query); $result->bindParam(1, $deleted); $result->execute(); $staffs = $result->fetchAll();
if ($_GET) { //var_dump($_GET['search']); $S = $_GET['search']; $SID = ""; $SStatus = ""; $SCampus = "";
if (isset($S['id'])) $SID = $S['id']; $SStatus = $S['status']; $SCampus = $S['campus'];
if ($SID == "") { if ($SStatus != "" && $SCampus != "") { $query = "select * from staff as s,staff_campus as sc where sc.staff_id=s.staff_id and sc.campus_id='$SCampus' and s.deleted='0' and s.actived='1' and s.status='$SStatus' and sc.deleted='0' and sc.actived='1'"; } if ($SStatus == "" && $SCampus != "") { $query = "select * from staff as s,staff_campus as sc where sc.staff_id=s.staff_id and sc.campus_id='$SCampus' and s.deleted='0' and s.actived='1' and sc.deleted='0' and sc.actived='1'"; } if ($SStatus != "" && $SCampus == "") { $query = "select * from staff as s,staff_campus as sc where sc.staff_id=s.staff_id and s.deleted='0' and s.actived='1' and s.status='$SStatus' and sc.deleted='0' and sc.actived='1'"; } if ($SStatus == "" && $SCampus == "") { // $query = "select * from staff as s,staff_campus as sc // where sc.staff_id=s.staff_id // and s.deleted='0' and s.actived='1' // and sc.deleted='0' and sc.actived='1' group by s.staff_id"; $query = "select * from staff where deleted = '$deleted' ORDER BY staff_id"; } } else { //and s.root_id='$SID' if ($SStatus != "" && $SCampus != "") { $query = "select * from staff as s,staff_campus as sc where sc.staff_id=s.staff_id and sc.campus_id='$SCampus' and s.deleted='0' and s.actived='1' and s.status='$SStatus' and sc.deleted='0' and sc.actived='1' and s.staff_id='$SID'"; } if ($SStatus == "" && $SCampus != "") { $query = "select * from staff as s,staff_campus as sc where sc.staff_id=s.staff_id and sc.campus_id='$SCampus' and s.deleted='0' and s.actived='1' and sc.deleted='0' and sc.actived='1' and s.staff_id='$SID'"; } if ($SStatus != "" && $SCampus == "") { $query = "select * from staff as s,staff_campus as sc where sc.staff_id=s.staff_id and s.deleted='0' and s.actived='1' and s.status='$SStatus' and sc.deleted='0' and sc.actived='1' and s.staff_id='$SID'"; } if ($SStatus == "" && $SCampus == "") { $query = "select * from staff as s,staff_campus as sc where sc.staff_id=s.staff_id and s.deleted='0' and s.actived='1' and sc.deleted='0' and sc.actived='1' group by s.staff_id"; } }
$result = $dbh->prepare($query); //$result->bindParam(1, $deleted); $result->execute(); $staffs = $result->fetchAll(); }
$query = "select * from campus where deleted = ? ORDER BY sort"; $result = $dbh->prepare($query); $result->bindParam(1, $deleted); $result->execute(); $campuses = $result->fetchAll();
$staffStatusOptions = Staff::statusOptions(); ?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <link href="js/select2/select2.css" rel="stylesheet"/> <script src="js/select2/select2.js"></script> <?php require_once '../include/head.php'; ?> <?php require_once '../include/checkuser.php'; ?> <?php require_once '../include/Nav_bar.php'; ?>
</head> <body>
<div class="text-right"> <ul class="breadcrumb"> <!--<li><a href="#">Master</a> <span class="divider">></span></li>--> <li class="active">Staff</li> </ul> </div>
<div class="container-fluid pathways-container"> <a class="btn pull-right" href="form.php"><i class="icon-plus"></i>Add</a> <h2>Staff</h2>
<div class="pathways-search"> <form id="search_form" class="form-inline" action="" method="GET"> <div class="pathways-inline-block"> Search by Name: <select id="myselect" style="width:250px" name="search[id]">
</select> </div> <div class="pathways-inline-block"> Campus: <select id="search_campus" style="width:150px" name="search[campus]"> <option value="">All</option> <?php foreach ($campuses as $campus) { $selected = ""; if ($_GET) { if ($campus['campus_id'] == $S['campus']) $selected = "selected"; } print '<option value="' . $campus['campus_id'] . '" ' . $selected . '>' . $campus['campus_name'] . '</option>'; } ?> </select> </div> <div class="pathways-inline-block"> Status: <select id="search_status" style="width:100px" name="search[status]"> <option value="">All</option> <?php foreach ($staffStatusOptions as $StatusValue => $status) { $selected = ""; if ($_GET) { if ($StatusValue == $S['status']) $selected = "selected"; } print '<option value="' . $StatusValue . '" '.$selected.'>' . $status . '</option>'; } ?> </select> </div> <div class="pathways-inline-block"> <button type="submit" class="btn" id="" style="margin-left:30px">Search</button> </div>
<button type="button" class="btn" id="showALL" style="margin-left:30px">Show All</button> </form>
</div>
<!-- <div class="row-fluid" style="margin-bottom:10px"> <div class="btn-group"> <button id="select_all_btn" class="btn btn-small">Select All</button> <button id="delete_btn" class="btn btn-small">Delete</button> </div> </div>--> <script> var SCampus = ""; var SStatus = ""; $(document).ready(function() {
$("#myselect").select2({ placeholder: "Select a Name", minimumInputLength: 2, allowClear: true }); $("#myselect").on("select2-selecting", function(e) { //alert("selecting val=" + e.val); var rows = $('tr.result-row'); rows.hide("slow"); //var Rshow = rows.filter('#row_staff_'+e.val).show(); $('#row_staff_' + e.val).show("slow"); //rows.not(Rshow).hide(); }); $(".select2-input").keyup(function() { var input1 = $(this).val(); $.ajax({ url: 'list.php', //This is the current doc type: "POST", data: {Data: input1, Data2: input1 * 10}, success: function(data) { var obj = $.parseJSON(data); $.each(obj, function(key, value) { $("#staff_" + value['staff_id'] + "").remove(); $("#myselect").append("<option id=staff_" + value['staff_id'] + " value=" + value['staff_id'] + ">" + value['last_name'] + "\n" + value['first_name'] + "\n\n" + value['ch_name'] + "</option>");
}); } }); }); }); $("#showALL").click(function() { var rows = $('tr.result-row'); rows.show("slow"); }); /* $('#search_campus').on('change', function() { var e = document.getElementById("search_campus"); var strUser = e.options[e.selectedIndex].value; SCampus = strUser; var className = 'campus_' + strUser; //alert('campus: '+className); var rows = $('tr.result-row'); rows.hide("slow"); $('.' + className).show("slow"); if (strUser === "") { rows.show("slow"); } }); $('#search_status').on('change', function() { var e = document.getElementById("search_status"); var strUser = e.options[e.selectedIndex].value; //alert('status: '+strUser); var rows = $('tr.result-row'); //if(SCampus === "") rows.hide("slow"); $('.status_' + strUser).show("slow"); if (strUser === "") { rows.show("slow"); } });*/ </script> <script type="text/javascript"> $(function() { var DeleteID = 0; $('#select_all_btn').click(function() { var $selectAllCheckbox = $('.select-all-checkbox'); $selectAllCheckbox.prop('checked', !$selectAllCheckbox.prop('checked')); }); $('#delete_btn').click(function() { if ($('.select-all-checkbox:checked').length == 0) { bootbox.alert('At least select 1 record.'); } else { var NofRecord = $('.select-all-checkbox:checked').length;
bootbox.dialog('Delete ' + NofRecord + ' selected records?', [ { 'label': 'Delete', 'class': 'btn-danger', 'callback': function() { $('input:checkbox:checked').each(function() { DeleteID = (this.checked ? $(this).val() : ""); $.ajax({ url: 'delete/delete.php', //This is the current doc type: "POST", data: {Data: DeleteID}, success: function(data) { var obj = $.parseJSON(data); //alert(obj['1'] + ", StaffID: " + obj['5']); location.href = ''; //reload this page }
}); //location.href = 'index.php'; }); } }, { 'label': 'Cancel', 'class': 'btn' } ]);
} }); }); </script>
<form id="form" action="" method="post"> <table class="table table-striped table-bordered table-hover table-condensed"> <thead> <tr> <th style="min-width:130px; width:50px">View</th> <!-- <th style="min-width:50px; width:50px">Edit</th>--> <th>Name</th> <th>Position</th> <th>Subject</th> <th>Centre</th> <th>Mobile</th> <th>Email</th> <th>AdminEdit</th> </tr> </thead> <tbody> <?php foreach ($staffs as $staff) { $currentStaff = $staff['staff_id']; $query = "SELECT campus.* FROM staff_campus s_campus INNER JOIN campus campus ON campus.campus_id = s_campus.campus_id WHERE staff_id = ?"; $result = $dbh->prepare($query); $result->bindParam(1, $staff['staff_id']); $result->execute(); $campuses = $result->fetchAll(); $Is_campus = array(); //Get History_ID, $sth = $dbh->prepare("SELECT `staff_his_id` FROM `staff_salary_history` WHERE `staff_id` = '$currentStaff'"); $sth->execute(); while ($ResultSet = $sth->fetch(PDO::FETCH_ASSOC)) { $SH_ID = $ResultSet['staff_his_id']; } foreach ($campuses as $campus) { //$output[] = $campus['campus_name']; $Is_campus[] = 'campus_' . $campus['campus_id']; //echo '<div ></div>'; } //var_dump($Is_campus); $All_campus = join(" ", $Is_campus); //echo $All_campus; ?> <tr id="row_staff_<?= $staff['staff_id'] ?>" class="result-row status_<?= $staff['status'] ?> <?= $All_campus ?>" > <!-- <td><input type="checkbox" name="staff[selected][]" class="select-all-checkbox" value="<?//= $staff['staff_id'] ?>" /></td>--> <td> <div class="btn-group" data-toggle="buttons"> <a href="form.php?staff_id=<?= $staff['staff_id'] ?>&action=View" class="btn"><i class="icon-eye-open"></i> View</a> <a href="form.php?staff_id=<?= $staff['staff_id'] ?>&action=Eidt" class="btn"><!--<i class="icon-pencil"></i>-->Edit</a> </div> </td> <td><?= $staff['last_name'] . ', ' . $staff['first_name'] . '<br />' . $staff['ch_name'] ?></td> <td> <?php /* $query = "SELECT position . * FROM staff_position staff_position INNER JOIN position position ON position.position_id = staff_position.position_id WHERE staff_id =?"; */ $query = "SELECT position . * FROM staff staff_position INNER JOIN position position ON position.position_id = staff_position.position_id WHERE staff_id =?"; $result = $dbh->prepare($query); $result->bindParam(1, $staff['staff_id']); $result->execute(); $positions = $result->fetchAll(); $output = array(); foreach ($positions as $position) { $output[] = $position['position_name']; } echo implode('<br />', $output); ?> </td> <td> <?php $query = "SELECT subject.* FROM staff_subject staff_subject INNER JOIN subject subject ON subject.subject_id = staff_subject.subject_id WHERE staff_id = ?"; $result = $dbh->prepare($query); $result->bindParam(1, $SH_ID); $result->execute(); $subjects = $result->fetchAll(); $output = array(); foreach ($subjects as $subject) { $output[] = $subject['sub_name'] . ' (' . $subject['sub_code'] . ')'; } echo implode('<br />', $output); ?> </td>
<?php /* $query = "SELECT campus.* FROM staff_campus s_campus INNER JOIN campus campus ON campus.campus_id = s_campus.campus_id WHERE staff_id = ?"; $result = $dbh->prepare($query); $result->bindParam(1, $staff['staff_id']); $result->execute(); $campuses = $result->fetchAll(); */ //var_dump($campuses); $output = array(); foreach ($campuses as $campus) { $output[] = $campus['campus_name']; //$Is_campus[] = 'campus_'.$campus['campus_id']; //echo '<div ></div>'; //var_dump($Is_campus); } echo '<td class="">'; echo implode('<br />', $output); echo '</td>'; ?>
<td><?= $staff['mobile'] ?></td> <td><?= $staff['email'] ?></td> <td><a href="AdminEdit.php?staff_id=<?= $staff['staff_id'] ?>" class="btn">AdminEdit</a></td> </tr> <?php } ?> </tbody> </table> </form> <script type="text/javascript"> $(function() { //$('.select2').select2(); $('#form').validate(); }); </script> </div> <!-- /container -->
</body> </html>
|