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
|
<?php require_once(__DIR__ . '/../checkuser.php'); function index() { global $dbh; $message = $_GET['message'] ?: null; $search = $_GET['search'] ?: array(); $sort = $_GET['sort'] ?: array(); $is_waiting_list = $_GET['waiting_list'] == 1 ? true : false; $sort_by_columns = array( 'code' => 'Code', 'program_code' => 'Programme', 'subject_code' => 'Subject', 'start_date' => 'Start Date', 'end_date' => 'End Date', ); $sort_by_options = array( 'asc' => 'A - Z', 'desc' => 'Z - A', ); //TODO: search query $sql = " SELECT event.*, program.code AS program_code, subject.code AS subject_code, (SELECT MIN(lesson.`date`) FROM mis_event_lesson lesson WHERE lesson.event_id = event.id AND deleted = 0) AS start_date, (SELECT MAX(lesson.`date`) FROM mis_event_lesson lesson WHERE lesson.event_id = event.id AND deleted = 0) AS end_date FROM mis_event event LEFT JOIN mis_program program ON program.id = event.program_id LEFT JOIN mis_subject subject ON subject.id = event.subject_id WHERE event.deleted = ? AND event.is_waiting_list = ? AND CASE WHEN COALESCE(LENGTH(?), 0) = 0 THEN 1 = 1 ELSE event.program_id = ? END AND CASE WHEN COALESCE(LENGTH(?), 0) = 0 THEN 1 = 1 ELSE event.subject_id = ? END AND CASE WHEN COALESCE(LENGTH(?), 0) = 0 THEN 1 = 1 ELSE event.code = ? END AND CASE WHEN COALESCE(LENGTH(?), 0) = 0 THEN 1 = 1 ELSE EXISTS( SELECT * FROM mis_event_lesson lesson INNER JOIN mis_lesson_student lesson_student ON lesson_student.lesson_id = lesson.id AND lesson_student.deleted = 0 INNER JOIN mis_student student ON student.id = lesson_student.student_id WHERE lesson.event_id = event.id AND lesson.deleted = 0 AND student.root_id = ? ) END AND CASE WHEN COALESCE(LENGTH(?), 0) = 0 THEN 1 = 1 ELSE EXISTS( SELECT * FROM mis_event_lesson lesson INNER JOIN mis_lesson_staff lesson_staff ON lesson_staff.lesson_id = lesson.id AND lesson_staff.deleted = 0 INNER JOIN mis_staff staff ON staff.id = lesson_staff.staff_id WHERE lesson.event_id = event.id AND lesson.deleted = 0 AND staff.root_id = ? ) END ORDER BY "; $order_by_sql = ''; foreach ($sort as $index => $info) { if (!empty($info['column']) && !empty($info['option']) && in_array($info['column'], array_keys($sort_by_columns))) { if (!empty($order_by_sql)) { $order_by_sql .= ', '; } $direction = strtoupper($info['option']) != 'DESC' ? 'ASC' : 'DESC'; switch ($info['column']) { default: { $column = $info['column']; $order_by_sql .= "`$column` $direction"; break; } } } } if (empty($order_by_sql)) { $order_by_sql = "event.code"; } $sql .= $order_by_sql; $parameters = array( 0, ($is_waiting_list ? 1 : 0), $search['program_id'], $search['program_id'], $search['subject_id'], $search['subject_id'], $search['code'], $search['code'], $search['student_root_id'], $search['student_root_id'], $search['staff_root_id'], $search['staff_root_id'], ); $sth = Db\Util::execute($dbh, $sql, $parameters); $events = $sth->fetchAll(); $sql = "SELECT * FROM mis_program WHERE deleted = ? ORDER BY sort"; $parameters = array(0); $sth = Db\Util::execute($dbh, $sql, $parameters); $programs = $sth->fetchAll(); $sql = "SELECT * FROM mis_subject WHERE deleted = ? ORDER BY sort"; $parameters = array(0); $sth = Db\Util::execute($dbh, $sql, $parameters); $subjects = $sth->fetchAll(); $sql = " SELECT staff.*, staff_position.title AS position_title FROM mis_staff staff LEFT JOIN mis_staff_position staff_position ON staff_position.id = staff.position_id WHERE staff.is_latest = 1 AND staff.deleted = 0 ORDER BY staff.last_name, staff.first_name, staff.root_id"; $parameters = array(); $sth = Db\Util::execute($dbh, $sql, $parameters); $all_staffs = $sth->fetchAll(); return array( 'events' => $events, 'programs' => $programs, 'subjects' => $subjects, 'all_staffs' => $all_staffs, 'is_waiting_list' => $is_waiting_list, 'message' => $message, 'search' => $search, 'sort' => $sort, 'sort_by_columns' => $sort_by_columns, 'sort_by_options' => $sort_by_options, ); } extract(index()); ?><!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <?php require(__DIR__ . '/../inc/_head_meta.php'); ?> <?php require(__DIR__ . '/../inc/_head_css.php'); ?> <?php require(__DIR__ . '/../inc/_head_script.php'); ?> </head> <body> <?php require( __DIR__ . '/../inc/_navbar.php'); ?> <div class="text-right"> <ul class="breadcrumb"> <li class="active"><a href="#"><?=$is_waiting_list ? 'Waiting List' : 'Event'?></a></li> </ul> </div> <div class="container-fluid pathways-container"> <?php if (isset($message) && !empty($message)): ?> <div class="alert alert-info"> <button type="button" class="close" data-dismiss="alert">×</button> <h5 class="alert-heading">Note:</h5> <p><?=$message?></p> </div> <?php endif; ?>
<a href="form.php?<?=http_build_query(array('waiting_list'=>intval($is_waiting_list)))?>" class="btn pull-right"><i class="icon-plus"></i> Add</a> <h3><?=$is_waiting_list ? 'Waiting List' : 'Event'?></h3> <div class="pathways-search"> <form id="search_form" class="form-inline" action="" method="get"> <input type="hidden" name="waiting_list" value="<?=$is_waiting_list ? '1' : '0'?>" /> <div class="pathways-inline-block"> <?php $attribute = 'program_id'; $label = 'Programme'; ?> <label class="" for="<?=$attribute?>"><?=$label?></label> <select id="<?=$attribute?>" name="search[<?=$attribute?>]" class="input-medium" placeholder="<?=h($label)?>"> <option value="">All</option> <?php foreach ($programs as $program): ?> <option value="<?=h($program['id'])?>"<?=$program['id'] == $search[$attribute] ? ' selected="selected"' : ''?>><?=h($program['code'])?></option> <?php endforeach; ?> </select> </div> <div class="pathways-inline-block"> <?php $attribute = 'subject_id'; $label = 'Subject'; ?> <label class="" for="<?=$attribute?>"><?=$label?></label> <select id="<?=$attribute?>" name="search[<?=$attribute?>]" class="input-medium" placeholder="<?=h($label)?>"> <option value="">All</option> <?php foreach ($subjects as $subject): ?> <option value="<?=h($subject['id'])?>"<?=$subject['id'] == $search[$attribute] ? ' selected="selected"' : ''?>><?=h($subject['code'])?></option> <?php endforeach; ?> </select> </div> <div class="pathways-inline-block"> <?php $attribute = 'code'; $label = 'Code'; ?> <label class="" for="<?=$attribute?>"><?=$label?></label> <input type="text" id="<?=$attribute?>" name="search[<?=$attribute?>]" class="input-medium" value="<?=h($search[$attribute])?>" placeholder="<?=h($label)?>" maxlength="200" autocomplete="off" /> </div> <script type="text/javascript"> $(function() { $('#code').typeahead({ source: function(query, process) { return $.getJSON('codes.json.php', { q: query }, function(data) { return process(data.results); }); } }); }); </script> <div class="pathways-inline-block"> <?php $attribute = 'staff_root_id'; $label = 'Staff'; ?> <label class="" for="<?=$attribute?>"><?=$label?></label> <!-- <input type="text" id="<?=$attribute?>" name="search[<?=$attribute?>]" class="input-medium" value="<?=h($search[$attribute])?>" placeholder="<?=h($label)?>" maxlength="200" /> --> <select id="<?=$attribute?>" name="search[<?=$attribute?>]" class="select2" placeholder="Select a <?=$label?>"> <option value=""></option> <?php foreach ($all_staffs as $staff): ?> <option value="<?=h($staff['root_id'])?>"<?=$staff['root_id'] == $search[$attribute] ? ' selected="selected"' : ''?>> <?=h($staff['last_name'])?> <?=h($staff['first_name'])?> </option> <?php endforeach; ?> </select> </div> <div class="pathways-inline-block"> <?php $attribute = 'student_root_id'; $label = 'Student'; ?> <label class="" for="<?=$attribute?>"><?=$label?></label> <!-- <input type="text" id="<?=$attribute?>" name="search[<?=$attribute?>]" class="input-medium" value="<?=h($search[$attribute])?>" placeholder="<?=h($label)?>" maxlength="200" /> --> <input type="hidden" id="<?=$attribute?>" name="search[<?=$attribute?>]" placeholder="Select a <?=$label?>" /> </div> <script type="text/javascript"> $(function() { $('#student_root_id').select2({ minimumInputLength: 1, ajax: { url: '../student/students.json.php', dataType: 'json', data: function(term, page) { return { q: term }; }, results: function(data, page) { return { results: data.results }; } } }); }); </script> <!-- <div class="pathways-inline-block"> <?php $attribute = 'school'; $label = 'School'; ?> <label class="" for="<?=$attribute?>"><?=$label?></label> <input type="text" id="<?=$attribute?>" name="search[<?=$attribute?>]" class="input-large" value="<?=h($search[$attribute])?>" placeholder="<?=h($label)?>" maxlength="200" /> </div> --> <div class="pathways-inline-block"> <?php foreach ($sort as $index => $info): ?> <?php if (!empty($info['column']) && !empty($info['option'])): ?> <?php $attribute = 'column'; ?> <input type="hidden" name="sort[<?=h($index)?>][<?=$attribute?>]" value="<?=h($info[$attribute])?>" /> <?php $attribute = 'option'; ?> <input type="hidden" name="sort[<?=h($index)?>][<?=$attribute?>]" value="<?=h($info[$attribute])?>" /> <?php endif; ?> <?php endforeach; ?> <?php $attribute = 'column'; $label = 'Sort by'; ?> <label class="" for="<?=$attribute?>"><?=$label?></label> <select id="<?=$attribute?>" name="sort[<?=max(array_keys($sort?:array(0)))+1?>][<?=$attribute?>]" class="input-medium" placeholder="<?=h($label)?>"> <option value=""></option> <?php foreach ($sort_by_columns as $value => $label): ?> <option value="<?=$value?>"<?=$value == $search[$attribute] ? ' selected="selected"' : ''?>><?=h($label)?></option> <?php endforeach; ?> </select> <?php $attribute = 'option'; $label = 'Option'; ?> <!-- <label class="" for="<?=$attribute?>"><?=$label?></label> --> <select id="<?=$attribute?>" name="sort[<?=max(array_keys($sort?:array(0)))+1?>][<?=$attribute?>]" class="input-mini" placeholder="<?=h($label)?>"> <option value=""></option> <?php foreach ($sort_by_options as $value => $label): ?> <option value="<?=$value?>"<?=$value == $search[$attribute] ? ' selected="selected"' : ''?>><?=h($label)?></option> <?php endforeach; ?> </select> <button type="button" id="clear_sorting_btn" class="btn"><i class="icon-remove"></i> Clear sorting</button> <script type="text/javascript"> $(function() { $('#clear_sorting_btn').click(function() { var $search_form = $('#search_form'); $('input[type="hidden"][name^="sort["]', $search_form).remove(); $search_form.submit(); }); }); </script> <button type="submit" class="btn" style="margin-left:30px">GO</button> </div> </form> </div>
<?php if (empty($events)): ?> <p>There are no records.</p> <?php else: ?> <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 type="text/javascript"> $(function() { $('#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 { bootbox.dialog('Delete selected records?', [ { 'label': 'Delete', 'class': 'btn-danger', 'callback': function() { $('#form').attr('action', 'delete.php').submit(); } }, { '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:20px; width:20px"></th> <th style="min-width:50px; width:50px">Edit</th> <th>Code <?=Util::getSortDirectionCaretHtml($sort, 'code')?></th> <th>Programme <?=Util::getSortDirectionCaretHtml($sort, 'program_code')?></th> <th>Subject <?=Util::getSortDirectionCaretHtml($sort, 'subject_code')?></th> <th>Start <?=Util::getSortDirectionCaretHtml($sort, 'start_date')?></th> <th>End <?=Util::getSortDirectionCaretHtml($sort, 'end_date')?></th> <th>Details</th> </tr> </thead> <tbody> <?php foreach ($events as $event): ?> <tr> <td><input type="checkbox" name="event[selected][]" class="select-all-checkbox" value="<?=h($event['id'])?>" /></td> <td><a href="form.php?<?=http_build_query(array('id'=>$event['id'], 'waiting_list'=>intval($is_waiting_list)))?>" class="btn"><i class="icon-pencil"></i></a></td> <td><?=h($event['code'])?></td> <td><?=h($event['program_code'])?></td> <td><?=h($event['subject_code'])?></td> <td><?=h($event['start_date'])?></td> <td><?=h($event['end_date'])?></td> <td><a href="details.php?id=<?=h($event['id'])?>" class="btn btn-link"><i class="icon-search"></i> Details</a></td> </tr> <?php endforeach; ?> </tbody> </table> </form> <script type="text/javascript"> $(function() { $('#form').validate(); }); </script> <?php endif; ?> <script type="text/javascript"> $(function() { $('.select2').select2(); }); </script> <?php require( __DIR__ . '/../inc/_footer.php'); ?>
</div> <!-- /container --> </body> </html>
|