/var/www/(Del)pathways.org.hk/MIS20140127/old20140407/Event/Event_AddActivityFrom.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
<?php require_once '../include/DBConnect.php'?>
<!DOCTYPE html>
<?php
if (isset($_GET['event_id'])) {
    
$sth $dbh->query("select e.`event_id`, a.`activity_id`, `event_code`, `program_id`, `subject_id`, `class_size`, `school_id`, `title`, `date`, `start_time`, `end_time`, `payment`, `number_attend` from activity a ,event e "
            
"where e.actived = 1 and e.deleted = 0 and a.actived= 1 and a.deleted=0 and a.`event_id` = e.`event_id` and e.`event_id` = " $_GET['event_id']);
    
$result $sth->fetch(PDO::FETCH_ASSOC);
    
$code $result['event_code'];
    
$class_size $result['class_size'];
    
$school_type $result['school_id'];
    
$programme $result['program_id'];
    
$subject_id $result['subject_id'];
    
$event_type "";
    
$title $result['title'];
    
$date $result['date'];
    
$start_time $result['start_time'];
    
$end_time $result['end_time'];
    
$payment $result['payment'];
    
$number_attend $result['number_attend'];
    
$event_id $result['event_id'];
    
$activity $result['activity_id'];
} else {
    
$class_size $_POST['class_size'];
    
$school_type $_POST['school_type'];
    
$programme $_POST['programme'];
    
$subject_id $_POST['subject_id'];
    
$event_type $_POST['event_type'];
    
$title "";
    
$date "";
    
$start_time "";
    
$end_time "";
    
$payment "";
    
$number_attend "";
}
?>
<html>
    <head>
        <?php require_once '../include/head.php'?>
        <?php require_once '../include/checkuser.php'?>
        <?php require_once '../include/Nav_bar.php'?>  
        <script>
            $(function() {
                $("#start_date_div").datetimepicker({autoclose: true, pickTime: false, startDate: new Date(), format: 'yyyy-MM-dd'});
                $('#start_date_div').datetimepicker().on('changeDate', function(ev) {
                    $('#start_date_div').datetimepicker('hide');
                });
                $('#starttime').timepicker({'timeFormat': 'H:i', 'step': 5, 'minTime': '6:00', 'maxTime': '22:00'});
                $('#endtime').timepicker({'timeFormat': 'H:i', 'step': 5, 'minTime': '6:00', 'maxTime': '22:00'});
            });
            function limit_time(e) {
                var arr = $(e).val().split(":")[0] * 3600 + $(e).val().split(":")[1] * 60 + 15 * 60;
                $(e).parent().next().next().next().next().children().timepicker('option', {disableTimeRanges: [['6:00', arr]]});
                $(e).parent().next().next().next().next().children().focus();
                $(e).blur();
            }
        </script> 
    </head>
    <body>
        <!-- line between nav bar and content -->
        <div class="text-right">
            <ul class="breadcrumb">
                <li><a href="Event_List.php">Event</a> <span class="divider">&gt;</span></li>
                <li class="active"><?= isset($_GET['view']) ? "View " "" ?>Activity</li>
            </ul>
        </div>
        <div class="container-fluid pathways-container">
            <h3><?= isset($_GET['view']) ? "View " : (isset($_GET['event_id'])?"Edit":"Add"?> Activity</h3>            
            <form method="post" action="Event_AddActivityFrom_Save.php"  autocomplete="off">
                <input type="hidden" name="classsize" value="<?= $class_size ?>"/>
                <input type="hidden" name="schoolid" value="<?= $school_type ?>"/>
                <?php if (isset($event_id)) { ?>
                    <input type="hidden" name="event_id" value="<?= $event_id ?>"/>
                    <input type="hidden" name="activity_id" value="<?= $activity ?>"/>
                <?php ?>
                <table style="width: 70%;">
                    <!--  // ###  Code ### //  -->
                    <?php
                    
if (!isset($_GET['event_id'])) {
                        
// ###  Generate Event Code ### // 
                        
$sth $dbh->query("SELECT `prog_short_form` FROM `program` WHERE program_id = " $programme " and actived = 1 and deleted=0 ");
                        
$programe $sth->fetch(PDO::FETCH_ASSOC);
                        
$sth $dbh->query("SELECT `sub_short_form` FROM `subject` WHERE actived = 1 and deleted = 0 and subject_id = " $subject_id);
                        
$subject $sth->fetch(PDO::FETCH_ASSOC);
                        if (
date("m"time()) >= 9) {
                            
$NowDate date("y"time()) . (date("y"time()) + 1);
                        } else {
                            
$NowDate = (date("y"time()) - 1) . date("y"time());
                        }
                        
$group = ($event_type == '0') ? "g" "i";
                        
$sth $dbh->query("SELECT COUNT(*) countgroup FROM `event` WHERE actived=1 and deleted=0 and program_id=" $programme " and subject_id=" $subject_id);
                        
$ResultSet $sth->fetch(PDO::FETCH_ASSOC);

                        if ((
$ResultSet['countgroup'] + 1) <= 9)
                            
$count_event_group '0' . ($ResultSet['countgroup'] + 1);
                        else
                            
$count_event_group = ($ResultSet['countgroup'] + 1);

                        
$code $programe['prog_short_form'] . $subject['sub_short_form'] . $group $NowDate '-' $count_event_group;
                    }
                    
?>
                    <tr>
                        <td style="width: 200px;text-align: right;padding-bottom: 10px;">Code : </td>
                        <td style="width:  10px;"></td>
                        <td><input <?= (isset($_GET['view'])) ? "readonly" "" ?> type="text" id="code" name="code" readonly value="<?= $code ?>"/></td>                    
                    </tr>

                    <tr style="height: 15px;"></tr>
                    <!--  // ###  Programme && Subject ### //  -->
                    <tr>
                        <?php
                        
// ### Find programme ### //
                        
$sth $dbh->query("SELECT program_code FROM `program` WHERE actived=1 and deleted = 0 and program_id = " $programme " order by `sort`");
                        
$result $sth->fetch(PDO::FETCH_ASSOC);
                        
$programme_name $result['program_code'];
                        
?>
                        <td style="width: 200px;text-align: right;padding-bottom: 10px;">Programme : </td>
                        <td style="width: 10px;"></td>
                        <td> <input type="text" id="programme"  readonly value="<?= $programme_name ?>"/></td>
                        <td style="display:none"><input type="hidden" name="programme" value="<?= $programme ?>"/></td>
                        <?php
                        
// ### Find Subject ### // 
                        
$sth $dbh->query("SELECT sub_code FROM `subject` WHERE actived=1 and deleted=0 and subject_id=" $subject_id " order by `sort`");
                        
$result $sth->fetch(PDO::FETCH_ASSOC);
                        
$subject $result['sub_code'];
                        
?>
                        <td style="width: 20px;"></td>
                        <td style="width: 200px;text-align: right;padding-bottom: 10px;">Subject : </td>
                        <td style="width:  10px;"></td>
                        <td><input type="text" id="subject" readonly value="<?= $subject ?>"/></td>
                        <td style="display:none"><input <?= (isset($_GET['view'])) ? "readonly" "" ?> type="hidden" name="subject" value="<?= $subject_id ?>"/></td>
                    </tr>

                    <tr style="height: 15px;"></tr>
                    <!--  // ###  Programme && Subject ### //  -->
                    <tr>
                        <td style="width: 200px;text-align: right;padding-bottom: 10px;">Title : </td>
                        <td style="width: 10px;"></td>
                        <td colspan="5"><input <?= (isset($_GET['view'])) ? "readonly" "" ?> <?= (isset($_GET['view'])) ? "readonly" "" ?> type="text" style="width: 100%;" id="title" name="title" value="<?= $title ?>"/></td>                    
                    </tr>
                    <tr style="height: 15px;"></tr>
                    <tr>
                        <td style="text-align: right;padding-bottom: 10px;">Date : </td>
                        <td></td>
                        <td>
                            <div class="input-append date" id="start_date_div">
                                <input <?= (isset($_GET['view'])) ? "readonly" "" ?> type="text" value="<?= $date ?>" id="start_date_input" name="date"/>
                                <span <?= (isset($_GET['view'])) ? "style=\"display:none\"" "" ?>  class="add-on"><i class="icon-th"></i></span>
                            </div>
                        </td>
                        <td style="display:none;width: 100px;text-align: right;padding-bottom: 10px;">End Date : </td>
                        <td style="width: 10px;"></td>
                        <td style="display:none;">
                            <div class="input-append date" id="end_date_div">
                                <input type="text" value="" id="end_date_input" name="enddate">
                                <span class="add-on"><i class="icon-th"></i></span>
                            </div>
                        </td>
                    </tr>
                    <tr style="height: 15px;"></tr>
                    <tr>
                        <td style="text-align: right;padding-bottom: 10px;">Start Time : </td>
                        <td></td>
                        <td><input <?= (isset($_GET['view'])) ? "readonly" "" ?> type="text" id="starttime" onchange="limit_time(this);" name="starttime" value="<?= $start_time ?>"/></td>
                        <td></td>
                        <td style="text-align: right;padding-bottom: 10px;">End Time : </td>
                        <td></td>
                        <td><input <?= (isset($_GET['view'])) ? "readonly" "" ?> type="text" id="endtime" onchange="limit_time(this);" name="endtime"value="<?= $end_time ?>"/></td>
                    </tr>
                    <tr style="height: 15px;"></tr>
                    <tr>
                        <td style="text-align: right;">Payment :</td>
                        <td></td>
                        <td>
                            <div class="input-prepend" style="margin-bottom: 1px;">
                                <button type="button" class="btn" disabled>$</button>
                                <input <?= (isset($_GET['view'])) ? "readonly" "" ?> type="text" style="text-align: right" name="payment" value="<?= $payment ?>"/>            
                            </div>
                        </td>
                        <td style="width: 15px;"></td>
                        <td style="text-align: right;">Number of attend :</td>
                        <td></td>
                        <td>
                            <input <?= (isset($_GET['view'])) ? "readonly" "" ?> type="text" name="numberofattend" onafterpaste="this.value=this.value.replace(/[^\d]/g,'')" onkeyup="this.value = this.value.replace(/[^\d]/g, '')" value="<?= $number_attend ?>"/>
                        </td>
                    </tr>
                </table>                
                <hr/>
                <?php if (!isset($_GET['view'])) { ?>
                    <button type="submit" class="btn btn-danger">Save</button>
                <?php } else { ?>
                    <button type="button" class="btn btn-danger" onclick="document.location.href = 'Event_AddActivityFrom.php?event_id=' +<?= $_GET['event_id'?>;">Edit</button>
                <?php ?>
                <button type="button" class="btn btn-danger" onclick="history.back();">Back</button>
            </form>
        </div> <!-- /container -->
    </body>
</html>