/var/www/(Del)pathways.org.hk/MIS20140127/old20140314/LeaveApplication/Staff_App_Form.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
<?php
include_once '../include/DBConnect.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 
Status() {
        return array(
            
=> 'Pending',
            
=> 'Approved'
        
);
    }

}

$genderOptions General::genderOptions();
$leaveType Leave::Type();
$leaveStatus Leave::Status();

date_default_timezone_set("Hongkong");
$today date("Y-m-d");

if (
$_POST) {
    
$actived 1;
    
$deleted 0;
    
    
    
$input_by $_POST['input_by'];
    
$input_date $_POST['input_date'];
    
$staff_id_1 $_POST['staff_code'];
    
$staff_id_2 $_POST['staff_name'];
    
$SID "";
    
$stuID = -1;
    if(
$staff_id_1 == $staff_id_2){
        
$SID $staff_id_1;
    }
    else{
        echo 
'<script>alert("Your input data have some problems");</script>';
        echo 
'<script>history.back();</script>';
    }
    
$Sdate $_POST['SDate'];
    
$Edate $_POST['EDate'];
    
$Stime $_POST['STime'];
    
$Etime $_POST['ETime'];
    
$is_full_date = -1;
    
$event_id = -1;
    
$is_sick = -1;
    
$leave_type $_POST['leave_type'];
    
$leave_status $_POST['leave_status'];
    
$approved_by = -1;
    
$remarks "";
    
    
$query "INSERT INTO `leave_app`(`createby`, `createdate`, `lastupby`, `lastupdate`, `actived`, `deleted`, `staff_id`, `stu_linking_id`, `leave_date`, `is_full_day`, `event_id`, `is_sick`, `reason`, `approve_by`, `is_approve`, `remarks`) 
        VALUES ('
$input_by','$input_date','$input_by','$input_date','$actived','$deleted','$SID','$stuID','$Sdate','$is_full_date','$event_id','$is_sick','$leave_type','$approved_by','$leave_status','$remarks')";
    
$sth $dbh->prepare($query);
    if(
$SID !="")
        
$sth->execute();
    
    
$result = ($_GET) ? "Update data successful." "Insert data successful";
    echo 
"<script>alert('" $result "');</script>";
    echo 
"<script>location.href = 'LeaveIndex.php';</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});
                $('.time-picker').datetimepicker({pickDate: false});
                $('#SDate').val('<?= $today ?>'); //Generate by system 
                $('#EDate').val('<?= $today ?>'); //Generate by system 
                $("#myselect").select2({
                    placeholder: "Staff Code",
                    minimumInputLength: 1,
                    allowClear: true
                });
                $("#myselect2").select2({
                    placeholder: "Staff Name",
                    minimumInputLength: 2,
                    allowClear: true
                });
            });
        </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>Staff Application</h2>

            <form  class="form-horizontal" action="" method="post" >
                <div class="control-group">
                    <?php
                    $attribute 
'input_by';
                    
$label 'Input By';
                    
?>
                    <label class="control-label" for="<?= $attribute ?>"><?= $label ?></label>
                    <div class="controls form-inline">
                        <input type="text" id="<?= $attribute ?>" name="<?= $attribute ?>" class="required" value="<?= $_SESSION['MIS_login']['username'?>" placeholder="<?= $label ?>" maxlength="200" disabled />
                        <input type="hidden" id="<?= $attribute ?>" name="<?= $attribute ?>" class="required" value="<?= $_SESSION['MIS_login']['username'?>" maxlength="200" />
                    </div>
                </div>
                <div class="control-group">
                    <?php
                    $attribute 
'input_date';
                    
$label 'Input 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="<?= $today ?>" data-format="yyyy-MM-dd" placeholder="<?= $label ?>" maxlength="200" disabled />
                            <input type="hidden" id="<?= $attribute ?>" name="<?= $attribute ?>" class="dateISO" value="<?= $today ?>" data-format="yyyy-MM-dd" maxlength="200"/>
                            <!--<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 
'staff_code';
                    
$label 'Staff Code';
                    
?>
                    <label class="control-label" for="<?= $attribute ?>"><?= $label ?></label>
                    <div class="controls form-inline">
                        <select id="myselect" name="<?= $attribute?>" id="<?= $attribute?>" style="width:300px">
                            <option value=""></option>
                            <?php
                            $query 
'SELECT CONCAT( last_name,  " ", first_name,  "(", ch_name,  ")" ) AS name,root_id,staff_code 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['staff_code'?></option>
                                <?php
                            
}
                            
?>
                        </select>
                    </div>
                </div>
                <div class="control-group">
                    <?php
                    $attribute 
'staff_name';
                    
$label 'Staff 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" />
                        <select id="myselect2" name="<?= $attribute?>" id="<?= $attribute?>" style="width:300px">
                            <option value=""></option>
                            <?php
                            $query 
'SELECT CONCAT( last_name,  " ", first_name,  "(", ch_name,  ")" ) AS name,root_id,staff_code 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>
                        <?php
                        $attribute 
'zh_name';
                        
$label '中文姓名';
                        
?>
                        <!--<input type="text" id="<?= $attribute ?>" name="<?= $attribute ?>" class="" value="" placeholder="<?= $label ?>" maxlength="200" />-->
                    </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 ?>">
                            <!--<option value=""></option>-->
                            <?php foreach ($leaveType as $leaveValue => $leaveLabel) { ?>
                                <option value="<?= $leaveValue ?>"><?= $leaveLabel ?></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"  />
                            <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;" 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"  />
                            <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">
                        <div class="input-append time-picker">
                            <input type="text" id="<?= $attribute ?>" name="<?= $attribute ?>" class="dateISO" value="" data-format="hh:mm" placeholder="<?= $label ?>" maxlength="200"  />
                            <span class="add-on"><i data-time-icon="icon-time" data-date-icon="icon-calendar"></i></span>
                        </div>

                        <?php
                        $attribute 
'ETime';
                        
$label 'End Time';
                        
?>
                        <label class="control-label" style="float:none" for="<?= $attribute ?>" ><?= $label ?></label>
                        <div class="input-append time-picker">
                            <input type="text" id="<?= $attribute ?>" name="<?= $attribute ?>" style="margin-left:20px" class="dateISO" value="" data-format="hh:mm" placeholder="<?= $label ?>" maxlength="200"  />
                            <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 
'leave_status';
                    
$label 'Leave Status';
                    
?>
                    <label class="control-label" for="<?= $attribute ?>"><?= $label ?></label>
                    <div class="controls form-inline">
                        <select id="<?= $attribute ?>" name="<?= $attribute ?>" class=""  placeholder="<?= $label ?>">
                            <!--<option value=""></option>-->
                            <?php foreach ($leaveStatus as $lsValue => $lsLabel) { ?>
                                <option value="<?= $lsValue ?>"><?= $lsLabel ?></option>
                            <?php ?>
                        </select>
                    </div>
                </div>
                <hr>
                    <button  class="btn btn-danger" id="">Save</button>
                    <button  class="btn btn-danger" type="button" onclick="history.back();" >Back</button>
            </form>
        </div>
    </body>
</html>