/var/www/(Del)pathways.org.hk/MIS_bk/staff/teaching_records.php


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
<?php
require_once(__DIR__ '/../checkuser.php');
//ini_set('memory_limit', '512M');
function index() {
    global 
$dbh;
    
    
$message $_GET['message'] ?: null;
    
$search $_GET['search'] ?: array();
    
    
$timetable = array();
    
$min_hour 9;
    
$max_hour 18;
    if (!empty(
$search)) {
        
$date = new DateTime($search['date']);
        while (
$date->format('N') != 1) {
            
$date->modify('-1 day');
        }
        
$start_date $date;
        
$end_date = clone $date;
        
$end_date->modify('+6 days');
        
        
$sql "
SELECT latest_staff.root_id AS staff_root_id, latest_staff.last_name, latest_staff.first_name,
    program.code AS program_code,
    subject.code AS subject_code,
    venue.name AS venue_name,
    lesson.*
FROM mis_staff staff
INNER JOIN mis_staff latest_staff ON latest_staff.root_id = staff.root_id AND latest_staff.is_latest = 1
INNER JOIN mis_lesson_staff lesson_staff ON lesson_staff.staff_id = staff.id AND lesson_staff.deleted = 0
INNER JOIN mis_event_lesson lesson ON lesson.id = lesson_staff.lesson_id AND lesson.deleted = 0
INNER JOIN mis_venue venue ON venue.id = lesson.venue_id
INNER JOIN mis_event evt ON evt.id = lesson.event_id AND evt.deleted = 0
LEFT JOIN mis_program program ON program.id = evt.program_id
LEFT JOIN mis_subject subject ON subject.id = evt.subject_id
WHERE staff.root_id = ? AND lesson.`date` BETWEEN ? AND ?
"
;
        
$parameters = array($search['staff_root_id'], $start_date->format('Y-m-d'), $end_date->format('Y-m-d'));
        
$sth Db\Util::execute($dbh$sql$parameters);
        
$lessons $sth->fetchAll();
        
        if (!empty(
$lessons)) {
            
$min_hour min($min_hourmin(__::pluck($lessons'start_time_hour')));
            
$max_hour max($max_hourmax(__::pluck($lessons'end_time_hour')));
        }
    }
    
    
// initial time table
    
for ($hour $min_hour$hour <= $max_hour$hour++) {
        for (
$min 0$min 60$min += 15) {
            
$timetable[] = array('hour'=>$hour'min'=>$min1=>''2=>''3=>''4=>''5=>''6=>'''rowspan'=>false);
        }
    }
    foreach (
$lessons ?: array() as $lesson) {
        
// hour
        
$start_date_time = new DateTime(sprintf('%s %02d:%02d:00'$lesson['date'], $lesson['start_time_hour'], $lesson['start_time_min']));
        
$end_date_time = new DateTime(sprintf('%s %02d:%02d:00'$lesson['date'], $lesson['end_time_hour'], $lesson['end_time_min']));
        
$interval $start_date_time->diff($end_date_time);
        
$hour $interval->+ ($interval->floatval(60));
        
// weekday
        
$weekday $start_date_time->format('N');
        
// rowspan
        
$rowspan $hour 4;
        
// find that row
        
for ($i 0$i count($timetable); $i++) {
            if (
$timetable[$i]['hour'] == $lesson['start_time_hour'] && $timetable[$i]['min'] == $lesson['start_time_min']) {
                
$timetable[$i][$weekday] = array(
                    
'rowspan' => $rowspan,
                    
'html'=>sprintf(
'<a href="javascript:void(0)" class="popover-lesson"
    data-title="Details" data-content="%s%s%s - %s"
    data-placement="top" data-trigger="hover" data-html="true">%s - %s</a><br />
    %s'
,
                        
h('Date: ' $start_date_time->format('Y-m-d')), h('<br />'), h('Time: ' $start_date_time->format('H:i')), h($end_date_time->format('H:i')),
                        
h($lesson['program_code']), h($lesson['subject_code']),
                        
h($lesson['venue_name'])),
                );
                for (
$j 1$j $rowspan$j++) {
                    
$timetable[$i+$j][$weekday] = false;
                }
                break;
            }
        }
    }
    
    
$sql "SELECT * FROM mis_staff WHERE is_latest = ? AND deleted = ? ORDER BY last_name, first_name";
    
$parameters = array(10);
    
$sth Db\Util::execute($dbh$sql$parameters);
    
$staffs $sth->fetchAll();
    
    return array(
        
'message' => $message,
        
'search' => $search,
        
        
'staffs' => $staffs,
        
'timetable' => $timetable,
        
        
'server_datetime' => new DateTime('now'),
        
'start_date' => $start_date,
        
'end_date' => $end_date,
    );
}
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><a href="#">Master</a> <span class="divider">&gt;</span></li>
            <li><a href="#">Staff</a> <span class="divider">&gt;</span></li>
            <li class="active">Teaching Records</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">&times;</button>
            <h5 class="alert-heading">Note:</h5>
            <p><?=$message?></p>
        </div>
        <?php endif; ?>
        
        <h3>Teaching Records</h3>
        
        <div class="pathways-search">
            <form id="search_form" class="form-inline" action="" method="get">
                <div class="pathways-inline-block">
                    <?php $attribute 'staff_root_id'$label 'Staff'?>
                    <label class="" for="<?=$attribute?>"><?=$label?></label>
                    <select id="<?=$attribute?>" name="search[<?=$attribute?>]" class="select2" placeholder="Select a <?=h($label)?>">
                        <option value=""></option>
                        <?php foreach ($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 'date'$label 'Date'?>
                    <label class="" for="<?=$attribute?>"><?=$label?></label>
                    <div class="input-append date-picker">
                        <input type="text" id="<?=$attribute?>" name="search[<?=$attribute?>]" class="dateISO input-small" style="width:90px" value="<?=h(Util::value_to_date_string($search[$attribute]))?>" data-format="yyyy-MM-dd" placeholder="<?=h($label)?>" maxlength="200" />
                        <span class="add-on"><i data-time-icon="icon-time" data-date-icon="icon-calendar"></i></span>
                    </div>
                    <button type="submit" class="btn" style="margin-left:30px">GO</button>
                </div>
            </form>
        </div>
        
        <div class="pull-right">
            <p>Update: <?=$server_datetime->format('Y-m-d H:i:s')?></p>
        </div>
        <h5>
            <?php if (isset($start_date$end_date)): ?>
            <?=sprintf('%02d-%s'$start_date->format('d'), $end_date->format('d F Y'))?>
            <?php endif; ?>
        </h5>
        
        <table class="table table-striped table-bordered table-hover table-condensed">
            <thead>
                <tr>
                    <th>Time</th>
                    <th style="width:15%">Monday</th>
                    <th style="width:15%">Tuesday</th>
                    <th style="width:15%">Wednesday</th>
                    <th style="width:15%">Thursday</th>
                    <th style="width:15%">Friday</th>
                    <th style="width:15%">Saturday</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($timetable as $row): ?>
                <tr>
                    <td>
                        <?php if (in_array($row['min'], array(030))): ?>
                        <?=sprintf('%02d'$row['hour'])?>:<?=sprintf('%02d'$row['min'])?>
                        <?php else: ?>
                        &nbsp;
                        <?php endif; ?>
                    </td>
                    <?php for ($i 1$i <= 6$i++): ?>
                    <?php if ($row[$i] !== false): ?>
                    <td<?=is_array($row[$i]) && !empty($row[$i]['rowspan']) ? sprintf(' rowspan="%d"'$row[$i]['rowspan']) : ''?>>
                        <?php if (is_string($row[$i])): ?>
                        <?=h($row[$i])?>
                        <?php elseif (is_array($row[$i])): ?>
                        <?=$row[$i]['html']?>
                        <?php endif; ?>
                    </td>
                    <?php endif; ?>
                    <?php endfor; ?>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
        
        <script type="text/javascript">
            $(function() {
                $('.select2').select2();
                $('.date-picker').datetimepicker({ pickTime: false });
                $('#form').validate();
                $('.popover-lesson').popover();
            });
        </script>
    
        <?php require( __DIR__ '/../inc/_footer.php'); ?>

    </div> <!-- /container -->
</body>
</html>