/var/www/(Del)pathways.org.hk/MIS20140127/old20140407/Teaching_Record/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
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
<?php
include_once '../include/DBConnect.php';
$counter 1;
$deleted 0;
//offset of the timetable
$MaxTime "19:00:00";
$MinTime "09:00:00";

$EachDate 60 60 24;
//Some display message
$DateRange 0;
$StaffName "";
$Staff_ID = -1;
$Sdate "";
//
$start_date '';
$end_date '';
if (
$_GET) {
    
$search $_GET['search'];
    
$Staff_ID $search['Staff_ID'];
    
$Sdate $search['date'];
    if (isset(
$Staff_ID)) {
        
$query "SELECT * FROM `staff` WHERE `staff_id` = '$Staff_ID'";
        
$result $dbh->prepare($query);
        
$result->execute();
        while (
$ResultSet $result->fetch(PDO::FETCH_ASSOC)) {
            
$StaffName $ResultSet['last_name'] . " " $ResultSet['first_name'] . " " $ResultSet['ch_name'];
        }
    }

    
$date date("Y-m-d"strtotime($Sdate));
//        var_dump(date("N",  strtotime($search['date'])));
//        var_dump(date("Y-m-d",  strtotime($date)-60*60*24));
    
while (date("N"strtotime($date)) != 1) {
        
$date date("Y-m-d"strtotime($date) - $EachDate);
        
//var_dump($date);
    
}
    
$start_date $date;
    
$end_date date("Y-m-d"strtotime($date) + $EachDate);
    
$DateRange $start_date ' To ' $end_date;

    
//var_dump($end_date);
    
$query "select l.start_time,l.end_time,l.date,e.event_code ,s.first_name,s.last_name,l.room_id,l.lesson_id,g.grade from grade g,student_grade sg ,lesson l,event_lesson el,event e ,student s,lesson_attendance la where la.actived=1 and la.deleted=0 and s.actived=1 and s.deleted=0 and s.root_id 
                = la.stu_linking_id and l.lesson_id = la.lesson_id and l.lesson_id in ( SELECT lesson_id FROM `lesson_attendance` WHERE `staff_id`='
$Staff_ID' and `date`>= '$start_date' and `date`<= '$end_date' ) and el.lesson_id = l.lesson_id and el.event_id in (select event_id 
                from event where actived=1 and deleted =0) and e.event_id = el.event_id and sg.student_grade_id=s.linking_id and sg.grade_id=g.grade_id"
;
//    $query = "select start_time,end_time,date,e.event_code from lesson l,event_lesson el,event e where l.lesson_id in (
//SELECT lesson_id FROM `lesson_attendance` WHERE `staff_id`='$Staff_ID' and `date`>= '$start_date' and `date`<= '$end_date' ) and el.lesson_id = l.lesson_id and el.event_id in (select event_id from event where actived=1 and deleted =0) and e.event_id = el.event_id";
    
$result $dbh->prepare($query);
    
$result->execute();
    while (
$ResultSet $result->fetch(PDO::FETCH_ASSOC)) {
        if (
$ResultSet['start_time'] < $MinTime) {
            
$MinTime $ResultSet['start_time'];
            
//var_dump($ResultSet['start_time']);
        
}
        if (
$ResultSet['end_time'] > $MaxTime) {
            
$MaxTime $ResultSet['end_time'];
            
//var_dump($ResultSet['end_time']);
        
}
    }
    
$result $dbh->prepare($query);
    
$result->execute();
    
$Records $result->fetchAll();
    
//var_dump($Records);
}

//Function used to convert time to string with mod value
function CalMins($Hr$Mins$MinsMod) {
    
$HrMod 0;
    
$NewMins 0;
    
$NewHr 0;
    if (
$Mins $MinsMod 0) {
        
$NewMins '55';
        
$HrMod = -1;
    } else if (
$Mins $MinsMod == 60 || $Mins $MinsMod == 0) {
        
$HrMod 1;
        
$NewMins '00';
    } else {
        
$NewMins $Mins $MinsMod;
        
$NewMins $NewMins 10 "0" $NewMins $NewMins;
    }
    
$NewHr $Hr $HrMod;
    
$NewHr $NewHr 10 "0" $NewHr $NewHr;   // if Hr is 9, add "0", 09
    
return $NewHr ":" $NewMins ":00";
}

function 
TimeToDouble($Hr$Mins) {
    return (
$Hr + ($Mins 60));
}
?>
<!DOCTYPE html>
<html>
    <head>
        <style type="text/css">
            @media print {
                p {
                    page-break-inside: avoid;
                }
            }
        </style>
        <?php require_once '../include/head.php'?>
        <?php require_once '../include/checkuser.php'?>

        <?php require_once '../include/Nav_bar.php'?>  
        <script>
            SID = <?= $Staff_ID ?>;
            if (SID === 0)
                history.back();

            function printDiv()
            {
                $('#TR tr').css('height', '17px');
                $('#TR td').css('padding', '0px');
                $('#TR td').css('line-height', '15px');
                var divToPrint = document.getElementById('areaToPrint');
                newWin = window.open("");
                newWin.document.write('<script type="text/javascript" src="<?= path(__DIR__ '/../js/jquery-1.9.1.js'?>"><\/script>');
                newWin.document.write(divToPrint.outerHTML);
                newWin.document.close();
                newWin.focus();
                newWin.print();
                newWin.close();
            }

            $(function() {
                $('#myselect').select2().select2('val', SID);
                $('#Staff_ID').val('<?= $Staff_ID ?>');
                $('#date').val('<?= $Sdate ?>');
            });

            $(document).ready(function() {
                $('div input').height(20);
                $('.date-picker').datetimepicker({pickTime: false});
                $("#myselect").select2({
                    placeholder: "Select a Name",
                    minimumInputLength: 0,
                    allowClear: true
                });
                $("#myselect").on("select2-selecting", function(e) {
                    //alert("selecting val=" + e.val);
                    $('#Staff_ID').val(e.val);
                });

            });

        </script>
    </head>
    <body>
        <!-- line between nav bar and content
        <div class="text-right">
            <ul class="breadcrumb">
                <li class="active"></li>
            </ul>
        </div> -->
        <div class="text-right">
            <ul class="breadcrumb">
                <li><a href="../staff/index.php">Staff</a> <span class="divider">&gt;</span></li>
                <li class="active">Teaching Records</li>
            </ul>
        </div>

        <div class="container-fluid pathways-container">
            <div class="pathways-search">
                <form id="search_form" class="form-inline" action="" method="">
                    <div class="pathways-inline-block">
                        Search by Name:
                        <select id="myselect" style="width:300px">
                            <option value=""></option>
                            <?php
                            $query 
'SELECT CONCAT( last_name,  " ", first_name,  "(", ch_name,  ")" ) AS name,root_id FROM staff WHERE deleted =0 GROUP BY name';
                            
$result $dbh->prepare($query);
                            
$result->execute();
                            while (
$ResultSet $result->fetch(PDO::FETCH_ASSOC)) {
                                
?>
                                <option  value="<?= $ResultSet['root_id'?>" id="S<?= $ResultSet['root_id'?>" ><?= $ResultSet['name'?></option>
                                <?php
                            
}
                            
?>
                        </select>
                    </div>

                    <div class="pathways-inline-block">
                        <input type="hidden" id="Staff_ID"  name="search[Staff_ID]" value="0" />
                        <label class="" for="date">Date</label>
                        <div class="input-append date-picker">
                            <input type="text" id="date" name="search[date]" class="dateISO input-small" style="width:90px" value="" data-format="yyyy-MM-dd" placeholder="Date" 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>
                        <button class="btn" style="margin-left:30px" onclick="printDiv()">Print Teaching Record</button>
                    </div>
                </form>
            </div>
            <div id="areaToPrint"  >
                <!-- IF Print -->
                <!-- USED IN Adjust Print Format -->
                <!-- css -->
                <link rel="stylesheet" type="text/css" href="<?= path(__DIR__ '/../css/bootstrap.min.css'?>" />
                <link rel="stylesheet" type="text/css" href="<?= path(__DIR__ '/../css/bootstrapSwitch.css'?>" />
                <link rel="stylesheet" type="text/css" href="<?= path(__DIR__ '/../css/bootstrap-datetimepicker.min.css'?>" />
                <link rel="stylesheet" type="text/css" href="<?= path(__DIR__ '/../css/bootstrap-fileupload.min.css'?>" />
                <link rel="stylesheet" type="text/css" href="<?= path(__DIR__ '/../css/select2.css'?>" />
                <link rel="stylesheet" type="text/css" href="<?= path(__DIR__ '/../css/site.css'?>" />
                <link rel="stylesheet" type="text/css" href="<?= path(__DIR__ '/../css/jquery.timepicker.css'?>" />
                <script>
            $(function() {
                //alert('setted');
                //$('td').css('border-left', '1px solid #ddd');
                $('.haveLesson').css('border-left', 'solid');
                $('.haveLesson').css('border-top', 'solid');
            });</script>
                <!-- END IF -->
                <?= "<h5>Staff: " $StaffName "</h5>" ?>
                <?= ((int) $DateRange 2000) ? "<h5>Date: </h5>" "<h5>Date: $DateRange</h5>" ?>
                <table class="table table-striped table-hover table-condensed table-bordered" id="TR">
                    <thead>
                        <tr>
                            <th>Time</th>
                            <th style="width:14%"><?= date("d/m"strtotime($start_date) + $EachDate 0);?>(Mon)</th><!-- Monday -->
                            <th style="width:14%"><?= date("d/m"strtotime($start_date) + $EachDate 1);?>(Tues)</th><!-- Tuesday -->
                            <th style="width:14%"><?= date("d/m"strtotime($start_date) + $EachDate 2);?>(Wed)</th><!-- Wednesday -->
                            <th style="width:14%"><?= date("d/m"strtotime($start_date) + $EachDate 3);?>(Thurs)</th><!-- Thursday -->
                            <th style="width:14%"><?= date("d/m"strtotime($start_date) + $EachDate 4);?>(Fri)</th><!-- Friday -->
                            <th style="width:14%"><?= date("d/m"strtotime($start_date) + $EachDate 5);?>(Sat)</th><!-- Saturday -->
                            <th style="width:14%"><?= date("d/m"strtotime($start_date) + $EachDate 6);?>(Sun)</th><!-- Sunday -->
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        
//$StartTime, 9.0 is 09:00, 8.0 is 08:00
                        //Notic, while here $StartTime changed, $MinTime also have to change
                        
$StartTime 1.0;
                        
$EndTime 19;
                        if (
$StartTime $MinTime) {
                            
$StartTime = (int) $MinTime;
                        }
                        if (
$EndTime < (int) $MaxTime) {
                            
$EndTime = ((int) $MaxTime) + 0.1;
                        }
                        
$CurrentTime;
                        
$RowSpan = array(
                            
"0" => 0,
                            
"1" => 0,
                            
"2" => 0,
                            
"3" => 0,
                            
"4" => 0,
                            
"5" => 0,
                            
"6" => 0
                        
);
                        
$perviusMins = -1;
                        for (
$StartTime$StartTime $EndTime$StartTime+=TimeToDouble(05)) {
                            
$CurrentHour = ($StartTime 10 "0" . (int) $StartTime : (int) $StartTime);
                            
$CurrentMins = (int) ((($StartTime - (int) $StartTime) * 12) ) * 5;
                            
//used to ignore the repeated time cased by float to int calculation
                            
if ($CurrentMins == $perviusMins) {
                                continue;
                            } else {
                                
$perviusMins $CurrentMins;
                            }

                            
$CurrentMins = (int) $CurrentMins <= '0' . (float) $CurrentMins : (float) $CurrentMins;
                            
//var_dump($StartTime-(int)$StartTime);
//                        var_dump((($StartTime-(int)$StartTime)*12));
//                        var_dump((($StartTime-(int)$StartTime)*12)*5);
//                        var_dump((($StartTime-(int)$StartTime)*12)*5 <=9 );
//                        var_dump($CurrentMins);
                            
$CurrentTime $CurrentHour ':' $CurrentMins ':00';
                            
//var_dump($CurrentTime);
                            
?>
                            <tr >
                                <td><?= ($CurrentMins == '00' || $CurrentMins == '15' || $CurrentMins == '30' || $CurrentMins == '45') ? $CurrentHour ':' $CurrentMins '&nbsp' ?></td>
                                <?php
                                
//for loop xx:00:00 OR xx:30:00 colums
                                
for ($i 0$i 7$i++) {
                                    
$ThisDate date("Y-m-d"strtotime($start_date) + $EachDate $i);
                                    
$CurrentTimeMin CalMins($CurrentHour$CurrentMins, -5);
                                    
$CurrentTimeMax CalMins($CurrentHour$CurrentMins, +5);

                                    
$Content "&nbsp";
                                    
$ToPrintRowSpan 0;

                                    
////Checking Date and Time, to set Content
                                    
if (!empty($Records)) {
                                        
$currentLessionID 0;
                                        
$student "";
                                        foreach (
$Records as $record) {
                                            if (
$record['date'] == $ThisDate && $record['start_time'] >= $CurrentTime && $record['start_time'] < $CurrentTimeMax) {

                                                
$ToPrintRowSpan 1;    //print td
                                                
if ($currentLessionID == 0) {
                                                    
$currentLessionID $record['lesson_id'];
                                                    
$student .= $record['last_name'] . ' ' $record['first_name'] . '(' $record['grade'] . ')';
                                                } else if (
$currentLessionID == $record['lesson_id']) {
                                                    
$student .= '<br>' $record['last_name'] . ' ' $record['first_name'] . '(' $record['grade'] . ')';
                                                }

                                                
$RETime split(":"$record['end_time']);
                                                
$RSTime split(":"$record['start_time']);

                                                
$RowSpan[$i] = (int) ( (TimeToDouble($RETime[0], $RETime[1]) - TimeToDouble($RSTime[0], $RSTime[1])) * 12);

                                                
$Content '<br>' $RSTime[0] . ":" $RSTime[1] . " - " $RETime[0] . ":" $RETime[1] . "<br>" $record['event_code'] . "</b><br>" $record['room_id'];
                                            } else if (
$record['date'] == $ThisDate && $record['end_time'] <= $CurrentTime && $record['end_time'] > $CurrentTimeMin) {
//                                            var_dump($record['end_time']);
//                                            var_dump($CurrentTimeMin);
//                                            var_dump($CurrentTime);
                                                //$Content = '1<==' . $record['event_code'];
//                                            var_dump($Content);
                                                
$RowSpan[$i] = 0;   //not print the td, when time end
                                                
$currentLessionID 0;
                                            }
                                        }
                                    }
                                    
////echo the each td
                                    
if ($RowSpan[$i] <= || $ToPrintRowSpan == 1) {
                                        
$RowSpan[$i] = ($RowSpan[$i] <= 0) ? $RowSpan[$i];
                                        if (
$RowSpan[$i] > || $ToPrintRowSpan == 1) {

                                            echo 
'<td id="' $ThisDate '_' $CurrentTime '" rowspan="' $RowSpan[$i] . '"style="TEXT-ALIGN: left;border-style:solid;border-left: solid;border-top: solid;" class="haveLesson" >' $student $Content '</td>';
                                        } else {
                                            echo 
'<td id="' $ThisDate '_' $CurrentTime '" rowspan="' $RowSpan[$i] . '"style="TEXT-ALIGN: left;">' $Content '</td>';
                                        }
                                    }
                                    
$RowSpan[$i]--;
                                }
                                
?>
                            </tr>

                            <?php
                        
}
                        
?>
                    </tbody>
                </table>
            </div>
        </div>

    </body>
    <?php
//if (!empty($Records)) {
//    echo 'Here just checking, you can comment it<br>';
//    foreach ($Records as $record) {
//        var_dump($record['date']);
//        var_dump($record['start_time']);
//        var_dump($record['end_time']);
//        var_dump($record['event_code']);
//    }
//}
    
?>