/var/www/(Del)pathways.org.hk/MIS20140127/old20140414/staff/historyfrom.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
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
<?php

class Staff {

    public static function 
statusOptions() {
        return array(
            
=> 'Active',
            
=> 'Inactive',
        );
    }

    public static function 
workingModeOptions() {
        return array(
            
=> 'Monthly based',
            
=> 'Hourly based',
            
=> 'Volunteer'
        
);
    }

    public static function 
attendanceLeaveOptions() {
        return array(
            
=> 'Teacher Sick Leave',
            
=> 'Annual Leave',
            
=> 'Casual Leave',
            
=> 'Students absent',
            
=> 'No pay Lesson',
        );
    }

}

class 
General {

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

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

}

class 
FileLimite {

    public static function 
MaxSize() {
        
$MaxFileSize 1024 1024;   //1MB
        
return $MaxFileSize;
    }

    public static function 
FileType() {
        return array(
            
=> 'pdf',
            
=> 'doc',
            
=> 'jpg',
            
=> 'sql'
        
);
    }

}

/////Connect DB here~~
include_once '../include/DBConnect.php';
$deleted 0;
date_default_timezone_set("Hongkong");
$today date("Y-m-d");


// Select Position option from staff_position
$query "select * from position where deleted = ? ORDER BY sort";
$result $dbh->prepare($query);
$result->bindParam(1$deleted);
$result->execute();
$staff_positions $result->fetchAll();

// Select Program option from program
$query "select * from program where deleted = ? ORDER BY sort";
$result $dbh->prepare($query);
$result->bindParam(1$deleted);
$result->execute();
$programs $result->fetchAll();

// Select Subject option from subject
$query "select * from subject where deleted = ? ORDER BY sort";
$result $dbh->prepare($query);
$result->bindParam(1$deleted);
$result->execute();
$subjects $result->fetchAll();

$action "";
$MaxVersion;
$TempSHID;
$SHCreateBy;
$SHCreateDate;
$name "";
$position_id "";
$salary "";
$rate1 "";
$rate2 "";
$rate3 "";
$rate4 "";
$rate5 "";
$rate6 "";
$other_rate "";
$is_monthly "0";
$is_volunteer "0";
$is_hourly "0";

if (
$_GET) {
    if (isset(
$_GET['root_id'])) {
        
$action $_GET['action'];

//        var_dump($action);
//        var_dump($_GET['root_id']);
        
$RID $_GET['root_id'];
        
$query "SELECT `last_name`,`first_name`,`ch_name` FROM `staff` WHERE `root_id` = '$RID' and deleted=0";
        
$result $dbh->prepare($query);
        
$result->execute();
        if (
$ResultSet $result->fetch(PDO::FETCH_ASSOC)) {
            
$name $ResultSet['last_name'] . ' ' $ResultSet['first_name'] . ', ' $ResultSet['ch_name'] . '';
        }

        
$query "SELECT max(version),`createdate`,`createby`,max(staff_his_id) FROM staff_salary_history WHERE staff_id = '$RID' and deleted = 0";
        
$result $dbh->prepare($query);
        
$result->execute();
        if (
$ResultSet $result->fetch(PDO::FETCH_ASSOC)) {
            
$MaxVersion $ResultSet['max(version)'];
            
$TempSHID $ResultSet['max(staff_his_id)'];
            
$SHCreateBy $ResultSet['createby'];
            
$SHCreateDate $ResultSet['createdate'];
        }
        if (
$action == "Edit") {
            
$EditVersion $_GET['version'];
            
//var_dump($EditVersion);
//Select all base data and set into inputbox
            
$query "SELECT * 
FROM  `staff_salary_history` 
WHERE  `staff_id` =  '
$RID' and deleted=0 and version='$EditVersion'"//AND `deleted` = '$deleted'
            
$result $dbh->prepare($query);
            
$result->execute();
            while (
$ResultSet $result->fetch(PDO::FETCH_ASSOC)) {
                
$SH_ID $ResultSet['staff_his_id'];
//new
                
$position_id $ResultSet['position_id'];
                
//var_dump($position_id);
                
$is_monthly $ResultSet['is_monthly'];
                
$is_volunteer $ResultSet['is_volunteer'];
                
$is_hourly $ResultSet['is_hourly'];

                
$salary $ResultSet['salary'];
                
$rate1 $ResultSet['rate1'];
                
$rate2 $ResultSet['rate2'];
                
$rate3 $ResultSet['rate3'];
                
$rate4 $ResultSet['rate4'];
                
$rate5 $ResultSet['rate5'];
                
$rate6 $ResultSet['rate6'];
                
$other_rate $ResultSet['other_rate_desc'];
            }
        }
    }
};
if (
$_POST) {
    
$createby 0;
    
$actived 1;
    
$position_id $_POST['position_id'];
    
$salary $_POST['salary'];
    
$rate1 $_POST['rate1'];
    
$rate2 $_POST['rate2'];
    
$rate3 $_POST['rate3'];
    
$rate4 $_POST['rate4'];
    
$rate5 $_POST['rate5'];
    
$rate6 $_POST['rate6'];
    
$other_rate $_POST['rate6_other'];
    
$is_monthly 0;
    
$is_hourly 0;
    
$is_volunteer 0;
    if (isset(
$_POST['workingMode'])) {
        
$WorkingModeChecked $_POST['workingMode'];
        foreach (
$WorkingModeChecked as $WMChecked) {
            if (
$WMChecked == 1)
                
$is_monthly 1;
            if (
$WMChecked == 2)
                
$is_hourly 1;
            if (
$WMChecked == 3)
                
$is_volunteer 1;
        }
    }
    if (
$action == "Insert") {
        
$SHCreateDate $today;
        
$MaxVersion++;
        
$query "INSERT INTO `staff_salary_history`( `staff_id`, `createby`, `createdate`, `lastupby`, `lastupdate`, `actived`, `deleted`, `salary`, `rate1`, `rate2`, `rate3`, `rate4`, `rate5`, `rate6`, `other_rate_desc`,`version`,`position_id`,`is_monthly`,`is_volunteer`,`is_hourly`) 
                                    VALUES ('
$RID','$SHCreateBy','$SHCreateDate','$createby','$today','$actived','$deleted','$salary','$rate1','$rate2','$rate3','$rate4','$rate5','$rate6','$other_rate','$MaxVersion','$position_id','$is_monthly','$is_volunteer','$is_hourly')";
        
$sth $dbh->prepare($query);
        
$sth->execute();

        
$sth $dbh->prepare("SELECT staff_his_id FROM  `staff_salary_history` 
            WHERE  `staff_id` =  '
$RID' and deleted=0 and version='$MaxVersion'");
        
$sth->execute();
        if (
$ResultSet $sth->fetch(PDO::FETCH_ASSOC)) {
            
$SH_ID $ResultSet['staff_his_id'];
        }

        if (isset(
$_POST['programs'])) {
            
$ProgramsChecked $_POST['programs'];
            foreach (
$ProgramsChecked as $programChecked) {
                
$sth $dbh->prepare("INSERT INTO `staff_program`(`staff_id`, `createby`, `createdate`, `lastupby`, `lastupdate`, `actived`, `deleted`, `program_id`) VALUES ('$SH_ID','$createby','$today','$createby','$today','$actived','$deleted','$programChecked')");
                
$sth->execute();
            }
        }
//Insert subjects record
        
if (isset($_POST['subjects'])) {
            
$SubjectsChecked $_POST['subjects'];
            foreach (
$SubjectsChecked as $subjectChecked) {
                
$sth $dbh->prepare("INSERT INTO `staff_subject`(`staff_id`, `createby`, `createdate`, `lastupby`, `lastupdate`, `actived`, `deleted`, `subject_id`) VALUES ('$SH_ID','$createby','$today','$createby','$today','$actived','$deleted','$subjectChecked')");
                
$sth->execute();
            }
        }
    }
    if (
$action == "Edit") {
        
$sth $dbh->prepare("UPDATE `staff_salary_history` SET `deleted`= '1' WHERE `staff_id` = '$RID' and `version`='$EditVersion'");
        
$sth->execute();

        
$query "INSERT INTO `staff_salary_history`( `staff_id`, `createby`, `createdate`, `lastupby`, `lastupdate`, `actived`, `deleted`, `salary`, `rate1`, `rate2`, `rate3`, `rate4`, `rate5`, `rate6`, `other_rate_desc`,`version`,`position_id`,`is_monthly`,`is_volunteer`,`is_hourly`) 
                                    VALUES ('
$RID','$SHCreateBy','$SHCreateDate','$createby','$today','$actived','$deleted','$salary','$rate1','$rate2','$rate3','$rate4','$rate5','$rate6','$other_rate','$EditVersion','$position_id','$is_monthly','$is_volunteer','$is_hourly')";
        
$sth $dbh->prepare($query);
        
$sth->execute();

        
$sth $dbh->prepare("SELECT staff_his_id FROM  `staff_salary_history` 
            WHERE  `staff_id` =  '
$RID' and deleted=0 and version='$EditVersion'");
        
$sth->execute();
        if (
$ResultSet $sth->fetch(PDO::FETCH_ASSOC)) {
            
$SH_ID $ResultSet['staff_his_id'];
        }

        if (isset(
$_POST['programs'])) {
            
$ProgramsChecked $_POST['programs'];
            foreach (
$ProgramsChecked as $programChecked) {
                
$sth $dbh->prepare("INSERT INTO `staff_program`(`staff_id`, `createby`, `createdate`, `lastupby`, `lastupdate`, `actived`, `deleted`, `program_id`) VALUES ('$SH_ID','$createby','$today','$createby','$today','$actived','$deleted','$programChecked')");
                
$sth->execute();
            }
        }
//Insert subjects record
        
if (isset($_POST['subjects'])) {
            
$SubjectsChecked $_POST['subjects'];
            foreach (
$SubjectsChecked as $subjectChecked) {
                
$sth $dbh->prepare("INSERT INTO `staff_subject`(`staff_id`, `createby`, `createdate`, `lastupby`, `lastupdate`, `actived`, `deleted`, `subject_id`) VALUES ('$SH_ID','$createby','$today','$createby','$today','$actived','$deleted','$subjectChecked')");
                
$sth->execute();
            }
        }
    }
    
$result = ($action == "Edit") ? "Update data successful." "Insert data successful.";
    echo 
"<script>alert('" $result "');</script>";
    echo 
"<script>location.href = 'history_index.php?root_id=$RID';</script>";
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <link href="js/select2/select2.css" rel="stylesheet"/>
        <script src="js/select2/select2.js"></script>
        <?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);
                $('.date-picker').datetimepicker({pickTime: false});
                //alert('abc');
                $('#position_id').val('<?= $position_id ?>');
                $('#salary').val('<?= $salary ?>');
                $('#rate1').val('<?= $rate1 ?>');
                $('#rate2').val('<?= $rate2 ?>');
                $('#rate3').val('<?= $rate3 ?>');
                $('#rate4').val('<?= $rate4 ?>');
                $('#rate5').val('<?= $rate5 ?>');
                $('#rate6').val('<?= $rate6 ?>');
                $('#rate6_other').val('<?= $other_rate ?>');
                is_monthly = <?= $is_monthly ?>;
                is_hourly = <?= $is_hourly ?>;
                is_volunteer = <?= $is_volunteer ?>;
                if (is_monthly == 1)
                    $('input:checkbox[id="workingMode1"]').attr('checked', 'checked');
                if (is_hourly == 1)
                    $('input:checkbox[id="workingMode2"]').attr('checked', 'checked');
                if (is_volunteer == 1)
                    $('input:checkbox[id="workingMode3"]').attr('checked', 'checked');
            });
            
            var ClickCount = 0;
            function countClicks() {
                var clickLimit = 1; //Max number of clicks
                if (ClickCount >= clickLimit) {
                    //alert("You can only click this button " + clickLimit + " times.");
                    return false;
                }
                else
                {
                    ClickCount++;
                    return true;
                }
            }
        </script>
    </head>
    <body>
        <?php
        
if ($action == "Insert") {
            
//var_dump($action);
            
$TName "Add Staff Salary History";
            
$Bcolor 'style="background-color:#eeefde"';
            
        } else {
            
//var_dump($action);
            
$TName "Edit Staff Salary History";
            
$Bcolor 'style="background-color:#‎feffde‬"';
        }
        
?>
        <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"><?= $TName ?></li>
            </ul>
        </div>
        
        
        <div class="container-fluid pathways-container "  <?= $Bcolor ?> >
            <h3><?= $TName ?></h3>
            <form  class="form-horizontal" action="" method="post" enctype="multipart/form-data">
                <h5> Staff Information </h5>
                <div class="control-group">
                    <?php
                    $attribute 
'staff_name';
                    
$label 'Staff Name';
                    
?>
                    <label class="control-label"  for="<?= $attribute ?>"><?= $label ?></label>
                    <div class="controls form-inline">
                        <input type="text" id="<?= $attribute ?>" name="<?= $attribute ?>" class="" value="<?= $name ?>" placeholder="<?= $label ?>"  maxlength="200" disabled />
                    </div>
                </div>
                <div class="control-group">
                    <?php
                    $attribute 
'position_id';
                    
$label 'Position';
                    
?>
                    <label class="control-label"  for="<?= $attribute ?>"><?= $label ?></label>
                    <div class="controls form-inline">
                        <select id="<?= $attribute ?>" name="<?= $attribute ?>" class="" value='' placeholder="">
                            <option value=""></option>
                            <?php
                            
foreach ($staff_positions as $staff_position) {
                                print 
'<option value="' $staff_position['position_id'] . '">' $staff_position['position_name'] . '</option>';
                            }
                            
?>
                        </select>
                    </div>
                </div>
                <div class="control-group">
                    <?php
                    $attribute 
'programs';
                    
$label 'Programs';
                    
?>
                    <label class="control-label"><?= $label ?></label>
                    <div class="controls form-inline">
                        <table style="width:60%">
                            <?php
                            $count 
0;
                            foreach (
$programs as $program) {
                                if (
$count == 0)
                                    print 
'<tr >';
                                
?>
                                <td style="width:30%">
                                    <input type="checkbox" id="program_<?= $program['program_id'?>" name="programs[]"  value="<?= $program['program_id'?>"/>
                                    <label for="program_<?= $program['program_id'?>"><?= $program['program_code'?></label>
                                </td>
                                <?php
                                $count
++;
                                if (
$count == 3) {
                                    print 
'</tr>';
                                    
$count 0;
                                }
                            }
                            
?>
                        </table>
                    </div>
                </div>
                <div class="control-group">
                    <?php
                    $attribute 
'subjects';
                    
$label 'Subjects';
                    
?>
                    <label class="control-label"><?= $label ?></label>
                    <div class="controls form-inline">
                        <table style="width:60%">
                            <?php
                            $count 
0;
                            foreach (
$subjects as $subject):
                                if (
$count == 0)
                                    print 
'<tr >';
                                
?>
                                <td style="width:30%">
                                    <input type="checkbox" id="subject_<?= $subject['subject_id'?>" name="subjects[]"  value="<?= $subject['subject_id'?>"/>
                                    <label for="subject_<?= $subject['subject_id'?>"><?= $subject['sub_code'?></label>
                                </td>
                                <?php
                                $count
++;
                                if (
$count == 3) {
                                    print 
'</tr>';
                                    
$count 0;
                                }
                            endforeach;
                            
?>
                        </table>
                    </div>
                </div>
                <div class="control-group">
                    <?php
                    $attribute 
'working_mode';
                    
$label 'Working Mode';
                    
?>
                    <label class="control-label"><?= $label ?></label>
                    <div class="controls form-inline">
                        <?php foreach (Staff::workingModeOptions() as $value => $label) { ?>
                            <!--                            <label class="radio inline">
                                                            <input type="radio" name="working_mode"  value="<?= $value ?>" />
                            <?= $label ?>
                                                        </label>-->
                            <input type="checkbox" id="workingMode<?= $value ?>"  name="workingMode[]"  value="<?= $value ?>"/>
                            <label for="<?= $label ?>"><?= $label ?></label>
                        <?php ?>
                    </div>
                </div>

                <h5>Salary</h5>
                <div class="control-group">
                    <?php
                    $attribute 
'salary';
                    
$label 'Salary';
                    
?>
                    <label class="control-label" for="<?= $attribute ?>"><?= $label ?></label>
                    <div class="controls form-inline">
                        <input type="text" id="<?= $attribute ?>" name="<?= $attribute ?>" class="number" value="" placeholder="<?= $label ?>"  maxlength="200" />
                        <span>By Month</span>
                    </div>
                </div>
                <div class="control-group">
                    <?php
                    $attribute 
'rate1';
                    
$label 'Rate 1';
                    
?>
                    <label class="control-label" for="<?= $attribute ?>"><?= $label ?></label>
                    <div class="controls form-inline">
                        <input type="text" id="<?= $attribute ?>" name="<?= $attribute ?>" class="number" value="" placeholder="<?= $label ?>"  maxlength="200" />
                        <span>Teacher (In House)</span>
                    </div>
                </div>
                <div class="control-group">
                    <?php
                    $attribute 
'rate2';
                    
$label 'Rate 2';
                    
?>
                    <label class="control-label" for="<?= $attribute ?>"><?= $label ?></label>
                    <div class="controls form-inline">
                        <input type="text" id="<?= $attribute ?>" name="<?= $attribute ?>" class="number" value="" placeholder="<?= $label ?>"  maxlength="200" />
                        <span>Teacher (Outside School)</span>
                    </div>
                </div>
                <div class="control-group">
                    <?php
                    $attribute 
'rate3';
                    
$label 'Rate 3';
                    
?>
                    <label class="control-label" for="<?= $attribute ?>"><?= $label ?></label>
                    <div class="controls form-inline">
                        <input type="text" id="<?= $attribute ?>" name="<?= $attribute ?>" class="number" value="" placeholder="<?= $label ?>"  maxlength="200" />
                        <span>Teaching Assistant (In House)</span>
                    </div>
                </div>
                <div class="control-group">
                    <?php
                    $attribute 
'rate4';
                    
$label 'Rate 4';
                    
?>
                    <label class="control-label" for="<?= $attribute ?>"><?= $label ?></label>
                    <div class="controls form-inline">
                        <input type="text" id="<?= $attribute ?>" name="<?= $attribute ?>" class="number" value="" placeholder="<?= $label ?>"  maxlength="200" />
                        <span>Teaching Assistant (Outside School)</span>
                    </div>
                </div>
                <div class="control-group">
                    <?php
                    $attribute 
'rate5';
                    
$label 'Rate 5';
                    
?>
                    <label class="control-label" for="<?= $attribute ?>"><?= $label ?></label>
                    <div class="controls form-inline">
                        <input type="text" id="<?= $attribute ?>" name="<?= $attribute ?>" class="number" value="" placeholder="<?= $label ?>"  maxlength="200" />
                        <span>Traveling</span>
                    </div>
                </div>
                <div class="control-group">
                    <?php
                    $attribute 
'rate6';
                    
$label 'Rate 6';
                    
?>
                    <label class="control-label" for="<?= $attribute ?>"><?= $label ?></label>
                    <div class="controls form-inline">
                        <input type="text" id="<?= $attribute ?>" name="<?= $attribute ?>" class="number" value="" placeholder="<?= $label ?>"  maxlength="200" />
                        <?php
                        $attribute 
'rate6_other';
                        
$label 'Other';
                        
?>
                        <label class="" for="<?= $attribute ?>"><?= $label ?></label>
                        <input type="text" id="<?= $attribute ?>" name="<?= $attribute ?>" class="" style="margin-left:15px" value="" placeholder="<?= $label ?>"  maxlength="200" />

                    </div>
                </div>
                <button  class="btn btn-danger" id="" onclick="return countClicks();" >Save</button>
                <a href="history_index.php?root_id=<?= $RID ?>" class="btn btn-danger">Back</a>
            </form>
        </div>
    </body>
</html>
<?php
if ($action == 'Edit') {
    
$query "SELECT * FROM `staff_program` WHERE `staff_id` = '$SH_ID' AND `deleted` = '$deleted'";
    
$result $dbh->prepare($query);
    
$result->execute();
    while (
$ResultSet $result->fetch(PDO::FETCH_ASSOC)) {
        
?>
        <script>
            $(function() {
                $('input:checkbox[id="program_<?= $ResultSet['program_id'?>"]').attr('checked', 'checked');
            });</script>
        <?php
//var_dump($ResultSet);
    
};
    
$query "SELECT * FROM `staff_subject` WHERE `staff_id` = '$SH_ID' AND `deleted` = '$deleted'";
    
$result $dbh->prepare($query);
    
$result->execute();
    while (
$ResultSet $result->fetch(PDO::FETCH_ASSOC)) {
        
?>
        <script>
            $(function() {
                $('input:checkbox[id="subject_<?= $ResultSet['subject_id'?>"]').attr('checked', 'checked');
            });
        </script>
        <?php
//var_dump($ResultSet);
    
};
}
?>