/var/www/(Del)pathways.org.hk/MIS20140127/old20140407/LeaveApplication/Student_Approve.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
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
<?php
include_once '../include/DBConnect.php';
include_once 
'CheckFollowUpAction.php';

class 
General {

    public static function 
fields() {
        return array(
            
'id''createby''createdate''lastupby''lastupdate',
        );
    }

    public static function 
genderOptions() {
        return array(
            
=> 'Male',
            
=> 'Female',
        );
    }

}

class 
Leave {

    public static function 
Type() {
        return array(
            
=> 'Annual Leave',
            
=> 'Marriage Leave',
            
=> 'Maternity Leave',
            
=> 'No Pay Leave',
            
=> 'Sick Leave'
        
);
    }

//    public static function duration(){
//        return array(
//            1 => 'Whole day',
//            2 => 'Morning',
//            3 => 'Afternoon'
//        );
//    }

    
public static function Status() {
        return array(
            
=> 'Pending',
            
=> 'Approved'
        
);
    }

}

$leaveType Leave::Type();
$genderOptions General::genderOptions();
date_default_timezone_set("Hongkong");
$today date("Y-m-d");
$Leave_Assistant = new LeaveAssistant($dbh);

if (
$_GET) {
    if (isset(
$_GET['leave_id']) && isset($_GET['action'])) {
        
$LID $_GET['leave_id'];
        
$CurrentAction $_GET['action'];
        
var_dump($CurrentAction);
        
var_dump($LID);
    }
    
//if Action = 3, Data is pass form Event_DetailFrom.php
    
if ($CurrentAction == 3) {
        
$get_lesson_id $_GET['lesson_id'];
        
$get_event_id_from_event $_GET['event_id'];
        
        
$Leave_Assistant->checkAll($get_event_id_from_event$get_lesson_id);
    }
    
$query "SELECT * FROM `leave_app` WHERE `leave_id` = '$LID' and deleted = 0";
    
$result $dbh->prepare($query);
    
$result->execute();
    while (
$ResultSet $result->fetch(PDO::FETCH_ASSOC)) {
        
//var_dump($ResultSet);
//        $get_createby = $ResultSet['createby'];
//        $get_createdate = substr($ResultSet['createdate'], 0, 10);
        
$get_student_id $ResultSet['stu_linking_id'];
        
$get_leave_reason $ResultSet['reason_id'];
        
$get_SDateTime date_create($ResultSet['start_date']); //substr($ResultSet['start_date'], 0, 16);
        
$get_EDateTime date_create($ResultSet['end_date']); //substr($ResultSet['end_date'], 0, 16);
//        $get_leave_status = $ResultSet['is_approved'];
    
}

    
$query "SELECT l.start_time, l.end_time, l.date, e.event_code, e.event_id, l.room_id, l.lesson_id ,l.`lesson_leave_status`
FROM  lesson l, event_lesson el, event e, lesson_attendance la , leave_lesson ll
WHERE la.actived =1
AND la.deleted =0
AND l.lesson_id = la.lesson_id
AND l.lesson_id = ll.lesson_id
AND ll.deleted = '0'
and ll.leave_id = '
$LID'
and la.stu_linking_id = '
$get_student_id'
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();
    
$students_Leave_Lesson_Record $result->fetchAll();
    
//var_dump($staffs_Leave_Lesson_Record);

    
$query "SELECT `last_name`,`first_name`,`ch_name`,`gender` FROM `student` WHERE `root_id`='$get_student_id' and `deleted`= '0'";
    
$result $dbh->prepare($query);
    
$result->execute();
    while (
$ResultSet $result->fetch(PDO::FETCH_ASSOC)) {
        
$get_staff_last_name $ResultSet['last_name'];
        
$get_staff_first_name $ResultSet['first_name'];
        
$get_staff_ch_name $ResultSet['ch_name'];
        
$get_gender $ResultSet['gender'];
    }
}

if (
$_POST) {
    if (isset(
$_POST['cancel_lesson_id'])) {
        if (isset(
$_POST['Cancel'])) {
            
//echo $_POST['cancel_lesson_id'];
            
$UpdateLesson_ID $_POST['cancel_lesson_id'];
            
//Update student attendance record
            
$query "UPDATE `lesson_attendance` SET `state`=4 ,`make_up_lesson_id`=0, `make_up_lesson_remark`='' WHERE `lesson_id` = '$UpdateLesson_ID' and deleted =0 and actived = 1 and `stu_linking_id` ='$get_student_id'";
            
$sth $dbh->prepare($query);
            
$sth->execute();

            
$query "select `attend_id` from `lesson_attendance` where `lesson_id`= '$UpdateLesson_ID' and `state`='3' and `stu_linking_id`>0";
            
$sth $dbh->prepare($query);
            
$sth->execute();
            
$Not_Finish_Attendance_record $result->fetchAll();
            if (!(
$Not_Finish_Attendance_record)) {
                
$query "UPDATE `lesson` SET `lesson_leave_status`='0' WHERE `lesson_id` = '$UpdateLesson_ID'";
                
$sth $dbh->prepare($query);
                
$sth->execute();
            }
            
$Textresult "Cancel Lesson Successful.";
        } else if (isset(
$_POST['Undo'])) {
            
#### Reset value ####
            //Reset attendance record
            
$UpdateLesson_ID $_POST['cancel_lesson_id'];
            
$Leave_Assistant->undoOneLesson($UpdateLesson_ID);

            
$Textresult "Active Lesson Successful.";
        }
        echo 
"<script>alert('" $Textresult "');</script>";
        echo 
"<script>location.href = 'Student_Approve.php?leave_id=" $LID "&action=FollowUpAction';</script>";
    }
}
?>


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <?php require_once '../include/head.php'?>
        <?php require_once '../include/checkuser.php'?>
        <?php require_once '../include/Nav_bar.php'?>
        <script>
            $(function() {
                $('div input').height(20); //fix size for input box
                $('.date-picker').datetimepicker({pickTime: false});
                $('#SDate').val('<?= $today ?>'); //Generate by system 
                $('#EDate').val('<?= $today ?>'); //Generate by system 
            });

<?php if ($_GET) { ?>

                $(function() {
                    $('#leave_type').val('<?= $get_leave_reason ?>');
                    $('#SDate').val('<?= date_format($get_SDateTime'Y-m-d'?>');
                    $('#EDate').val('<?= date_format($get_EDateTime'Y-m-d'?>');
                    $('#last_name').val('<?= $get_staff_last_name ?>');
                    $('#first_name').val('<?= $get_staff_first_name ?>');
                    $('#zh_name').val('<?= $get_staff_ch_name ?>');
                    $('#gender').val('<?= $get_gender ?>');
                });
                //                                function CancelLesson(lesson_id, action)
                //                                    {
                //                                        bootbox.dialog('Are you sure to cancel this lesson ?', [
                //                                            {
                //                                                'label': 'Delete',
                //                                                'class': 'btn-danger',
                //                                                'callback': function() {
                //                                                    CancelID = lesson_id;
                //                                                    Action = action;
                //                                                    $.ajax({
                //                                                        url: 'Cancel_Lesson.php', //This is the current doc
                //                                                        type: "POST",
                //                                                        data: {Data: CancelID, Action: Action},
                //                                                        success: function(data) {
                //                                                            var obj = $.parseJSON(data);
                //                                                            alert(obj[1]);
                //                                                            location.href = ''; //reload this page
                //                                                        }
                //                
                //                                                    });
                //                                                }
                //                                            },
                //                                            {
                //                                                'label': 'Cancel',
                //                                                'class': 'btn'
                //                                            }
                //                                        ]);
                //                                    }
                //                                    ;
                function CancelLesson(lesson_id, action) {
                    CancelID = lesson_id;
                    Action = action;
                    $('#cancel_lesson_id').val(CancelID);
                    //alert(CancelID + " " + Action);

                }
                
                function UndoButtonUnavailable(isMakeUpChain, isInvoiceGened, isPayrollGened, isUsedByOtherLeave) {
                var content = "";
                if (isMakeUpChain!=="")
                    content += "<br> - Having another make up lesson "+isMakeUpChain+" arranged for this lesson";
                if (isInvoiceGened)
                    content += "<br> - Student in this lesson have generated invoice";
                if (isPayrollGened)
                    content += "<br> - Teacher in this lesson have generated payroll";
                if (isUsedByOtherLeave)
                    content += "<br> - This make up lesson have other leave application";
                bootbox.dialog('<b>Sorry, The Edit and Delete Button is Unavailable now</b><br><br><b>The reason is:</b>' + content, [
                    {
                        'label': 'OK',
                        'class': 'btn'
                    },
                    {
                        'label': 'Cancel',
                        'class': 'btn'
                    }
                ]);
                return false;
            }

<?php ?>
        </script>
    </head>
    <body>
        <div class="text-right">
            <ul class="breadcrumb">
                <!--<li><a href="#">Master</a> <span class="divider">&gt;</span></li>-->
<!--                <li><a href="index.php">Staff</a> <span class="divider">&gt;</span></li>-->
                <li class="active">Leave Application</li>
            </ul>
        </div>

        <div class="container-fluid pathways-container">
            <!--<a class="btn pull-right" <?= ($name != "") ? 'href="historyfrom.php?root_id=' $RootID '&action=Insert"' 'disabled="disabled"' ?> ><i class="icon-plus"></i>Add</a>-->
            <h2>Student Approve</h2>

            <form  class="form-horizontal" action="" method="post" >
                <div class="control-group">
                    <?php
                    $attribute 
'last_name';
                    
$label 'Last Name';
                    
?>
                    <label class="control-label" for="<?= $attribute ?>"><?= $label ?></label>
                    <div class="controls form-inline">
                        <!-- Store the Root ID here, and pass to $_Post after submited -->
                        <input type="hidden" id="TempRootID" name="TempRootID" value="0" />
                        <input type="text" id="<?= $attribute ?>" name="<?= $attribute ?>" class="required" value="" placeholder="<?= $label ?>" maxlength="200" disabled="disabled" />
                        <?php
                        $attribute 
'first_name';
                        
$label 'First Name';
                        
?>
                        <label class="control-label" style="float:none" for="<?= $attribute ?>"><?= $label ?></label>
                        <input type="text" id="<?= $attribute ?>" name="<?= $attribute ?>" class="required" style="margin-left:15px" value="" placeholder="<?= $label ?>" maxlength="200" disabled="disabled"  />
                    </div>
                </div>
                <div class="control-group">
                    <?php
                    $attribute 
'zh_name';
                    
$label '中文姓名';
                    
?>
                    <label class="control-label" for="<?= $attribute ?>"><?= $label ?></label>
                    <div class="controls form-inline">
                        <input type="text" id="<?= $attribute ?>" name="<?= $attribute ?>" class="" value="" placeholder="<?= $label ?>" maxlength="200" disabled="disabled"  />
                        <?php
                        $attribute 
'gender';
                        
$label 'Gender';
                        
?>
                        <label class="control-label" style="float:none" for="<?= $attribute ?>"><?= $label ?></label>
                        <select id="<?= $attribute ?>" name="<?= $attribute ?>" class="" style="margin-left:15px" placeholder="<?= $label ?>" disabled="disabled"  >
                            <!--                            <option value=""></option>-->
                            <?php foreach ($genderOptions as $genderValue => $genderLabel) { ?>
                                <option value="<?= $genderValue ?>"><?= $genderLabel ?></option>
                            <?php ?>
                        </select>
                    </div>
                </div>
                <div class="control-group">
                    <?php
                    $attribute 
'SDate';
                    
$label 'Start Date';
                    
?>
                    <label class="control-label" for="<?= $attribute ?>"><?= $label ?></label>
                    <div class="controls form-inline">
                        <div class="input-append date-picker">
                            <input type="text" id="<?= $attribute ?>" name="<?= $attribute ?>" class="dateISO" value="" data-format="yyyy-MM-dd" placeholder="<?= $label ?>" maxlength="200" disabled="disabled" />
                            <!--<span class="add-on"><i data-time-icon="icon-time" data-date-icon="icon-calendar"></i></span>-->
                        </div>
                        <?php
                        $attribute 
'EDate';
                        
$label 'End Date';
                        
?>
                        <label class="control-label" style="float:none;margin-left:20px" for="<?= $attribute ?>" ><?= $label ?></label>
                        <div class="input-append date-picker">
                            <input type="text" id="<?= $attribute ?>" name="<?= $attribute ?>" style="margin-left:20px" class="dateISO" value="" data-format="yyyy-MM-dd" placeholder="<?= $label ?>" maxlength="200" disabled="disabled" />
                            <!--<span class="add-on"><i data-time-icon="icon-time" data-date-icon="icon-calendar"></i></span>-->
                        </div>

                    </div>
                </div>
                <div class="control-group">
                    <?php
                    $attribute 
'STime';
                    
$label 'Start Time';
                    
?>
                    <label class="control-label" for="<?= $attribute ?>"><?= $label ?></label>
                    <div class="controls form-inline">

                        <input type="text" id="<?= $attribute ?>" name="<?= $attribute ?>" placeholder="<?= $label ?>" disabled="disabled" value="<?= date_format($get_SDateTime'G:i'?>"/>

                        <?php
                        $attribute 
'ETime';
                        
$label 'End Time';
                        
?>
                        <label class="control-label" style="float:none" for="<?= $attribute ?>" ><?= $label ?></label>

                        <input type="text" id="<?= $attribute ?>" name="<?= $attribute ?>" style="margin-left:15px" placeholder="<?= $label ?>" disabled="disabled" value="<?= date_format($get_EDateTime'G:i'?>" />


                    </div>
                </div>
                <div class="control-group">
                    <?php
                    $attribute 
'leave_type';
                    
$label 'Leave Type';
                    
?>
                    <label class="control-label" for="<?= $attribute ?>"><?= $label ?></label>
                    <div class="controls form-inline">
                        <select id="<?= $attribute ?>" name="<?= $attribute ?>" class=""  placeholder="<?= $label ?>" disabled >
                            <!--<option value=""></option>-->
                            <?php foreach ($leaveType as $leaveValue => $leaveLabel) { ?>
                                <option value="<?= $leaveValue ?>"><?= $leaveLabel ?></option>
                            <?php ?>
                        </select>
                    </div>
                </div>
                <hr>
                    <input type="hidden" id="cancel_lesson_id" name="cancel_lesson_id" value="" />
                    <h5>Lesson</h5>
                    <table class="table table-striped table-bordered table-hover table-condensed" style="width:100%" >
                        <thead>
                            <tr>
    <!--                            <th style="min-width:130px; width:50px">View</th>-->
                                <th style="min-width:50px; width:50px;width:20%">Action</th>
                                <th style="width:10%" >Date</th>
                                <th style="width:10%" >Time</th>
                                <th style="width:10%" >Program</th>
                                <th style="width:10%" >Subject</th>
<!--                                <th style="width:10%" >Staff</th>
                                <th style="width:10%" >Sudent</th>-->
                                <!--<th style="width:10%" >Make up</th>-->
    <!--                            <th>AdminEdit</th>-->
                            </tr>
                        </thead>
                        <tbody>

                            <?php
                            
foreach ($students_Leave_Lesson_Record as $SLLRecord) {
                                
$query ""
                                
?>
                                <tr>
                                    <td>
                                        <?php if ($SLLRecord['lesson_leave_status'] == 1) { ?>
                                            <a href="../Event/Event_DetailFrom.php?lesson_id=<?= $SLLRecord['lesson_id'?>&event_id=<?= $SLLRecord['event_id'?>&action=3&leave_id=<?= $LID?>" class="btn">Make Up Lesson</a>
                                            <!--<a href="../Event/Event_DetailFrom.php?lesson_id=<?= $SLLRecord['lesson_id'?>&event_id=<?= $SLLRecord['event_id'?>&action=2&leave_id=<?= $LID ?>" class="btn">Substitute Teacher</a>-->
                                            <button name="Cancel" class="btn" onclick="CancelLesson(<?= $SLLRecord['lesson_id'?>, 1);" >Cancel Lesson</button>
                                            <?php
                                        
} else if ($SLLRecord['lesson_leave_status'] == 0) {
                                            
$current_lesson_id $SLLRecord['lesson_id'];
                                            
$isButtonAvailable $Leave_Assistant->isUndoButtonAvailable($current_lesson_id);
                                            
//var_dump($isButtonAvailable);
                                            
if ($isButtonAvailable['available'] == TRUE) {
                                                
$onclickListener "CancelLesson('$current_lesson_id', 2);";
                                            } else if (
$isButtonAvailable['available'] == FALSE) {
                                                
$onclickListener "UndoButtonUnavailable('" $isButtonAvailable['isLessonInMakeUpChain'] . "','" $isButtonAvailable['isLessonInvoiceGened'] . "','" $isButtonAvailable['isLessonPayrollGened'] . "','".$isButtonAvailable['isMakeUpLessonUsed']."')";
                                            }
                                            
?>
                                            <button name="Undo" class="btn" onclick="return <?= $onclickListener ?>" >Undo Action</button>
                                            <?php
                                        
}
                                        
?>

                                    </td>
                                    <td>
                                        <?php print '<b>' $SLLRecord['date'] . '</b>'?>
                                    </td>
                                    <td>
                                        <?php
                                        $get_Stime 
date_create($SLLRecord['start_time']);
                                        
$get_Etime date_create($SLLRecord['end_time']);
                                        print 
date_format($get_Stime'H:i') . '-' date_format($get_Etime'H:i')
                                        
?>
                                    </td>
                                    <td>
                                        <?php print $SLLRecord['event_code'?>
                                    </td>
                                    <td>
                                        <?php print $SLLRecord['room_id'?>
                                    </td>
    <!--                                <td>
                                        
                                    </td>
                                    <td>
                                        
                                    </td>-->
                                </tr>
                                <?php
                            
}
                            
?>
                        </tbody>


                    </table>
                    <button  class="btn btn-danger" type="button" onclick="location.href = '../LeaveApplication/LeaveIndex.php';" >Ok</button>
                    <!--<button  class="btn btn-danger" type="button" onclick="location.href = '../LeaveApplication/LeaveIndex.php';" >Back</button>-->

            </form>
        </div>
    </body>
</html>