/var/www/(Del)pathways.org.hk/MIS20140127/old20140414/Event/Event_List.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
<?php include_once '../include/DBConnect.php'?>
<!DOCTYPE html>
<?php
if (isset($_GET["search"])) {
    
$search_List = array();
    
$event_id = array();
    
$activity_sql_code "";
    
$activity_sql_programmeid "";
    
$activity_sql_subjectid "";
    if (!empty(
$_GET['search']['code_id'])) {
        
$activity_sql_code " and e.event_code = \"" $_GET['search']['code_id'] . '" ';
    }
    if (!empty(
$_GET['search']['programme_id'])) {
        
$activity_sql_programmeid " and e.program_id = '" $_GET['search']['programme_id'] . "' ";
    }
    if (!empty(
$_GET['search']['subject_id'])) {
        
$activity_sql_subjectid " and e.subject_id = \"" $_GET['search']['subject_id'] . '" ';
    }
    if (isset(
$_GET['event_type'])) {
        if (
$_GET['event_type'] == || $_GET['event_type'] == "") {
            
$search_activity "select e.event_id,e.event_code,p.program_name,s.sub_name,a.date from activity a ,event e ,program p,subject s where e.event_id = a.event_id and a.actived = 1 and a.deleted = 0 and e.actived = 1 and e.deleted = 0 and p.actived = 1 and p.deleted = 0 and s.actived= 1 and s.deleted = 0 and e.program_id = p.program_id and e.subject_id = s.subject_id and a.activity_id not in ( SELECT activity_id FROM `activity_stu_list` WHERE actived = 1 and deleted = 0 ) $activity_sql_code $activity_sql_programmeid $activity_sql_subjectid order by 1";
            
$sth3 $dbh->query($search_activity);
        }
    }


    
$staff_name = ($_GET['staff_name'] == "") ? "" ' and staff_id ="' $_GET['staff_name'] . '"  ';
    
$student_name = ($_GET['student_name'] == "") ? "" '`stu_linking_id` ="' $_GET['student_name'] . '" and';
    
$search_code_id = (empty($_GET['search']['code_id'])) ? "" 'and e.event_code = "' $_GET['search']['code_id'] . '"';
    
$search_programme_id = (empty($_GET['search']['programme_id'])) ? "" 'and e.program_id ="' $_GET['search']['programme_id'] . '"';
    
$search_subject_id = (empty($_GET['search']['subject_id'])) ? "" 'and e.subject_id  ="' $_GET['search']['subject_id'] . '"  ';
    
$sth2 $dbh->query('select Min(date) startdate,Max(date) enddate,e.event_id eid,e.event_code ec,p.program_code pc,s.sub_code sc 
        from subject s,program p,lesson l,event_lesson el,event e 
        where el.lesson_id=l.lesson_id and e.event_id=el.event_id and 
        el.lesson_id in 
        (SELECT lesson_id FROM `lesson_attendance` WHERE actived=1 and deleted=0 ' 
$staff_name ' ) 
            and el.lesson_id in 
            (SELECT lesson_id FROM `lesson_attendance` WHERE ' 
$student_name ' deleted=0 and actived=1)
                and p.program_id=e.program_id and e.subject_id=s.subject_id and e.actived=1 and e.deleted=0 ' 
$search_code_id $search_programme_id $search_subject_id ' group by e.event_id');
    while (
$ResultSet2 $sth2->fetch(PDO::FETCH_ASSOC)) {
        if (!empty(
$_GET['search']['startdate_id'])) {
            if (
$ResultSet2['startdate'] <= $_GET['search']['startdate_id'] && $ResultSet2['enddate'] >= $_GET['search']['startdate_id']) {
                
array_push($search_List, array($ResultSet2['eid'], $ResultSet2['ec'], $ResultSet2['pc'], $ResultSet2['sc'], $ResultSet2['startdate'], $ResultSet2['enddate']));
                continue;
            }
            if (
$ResultSet2['startdate'] <= $_GET['search']['enddate_id'] && $ResultSet2['enddate'] >= $_GET['search']['enddate_id']) {
                
array_push($search_List, array($ResultSet2['eid'], $ResultSet2['ec'], $ResultSet2['pc'], $ResultSet2['sc'], $ResultSet2['startdate'], $ResultSet2['enddate']));
                continue;
            }
            if (
$ResultSet2['startdate'] >= $_GET['search']['startdate_id'] && $ResultSet2['enddate'] <= $_GET['search']['enddate_id']) {
                
array_push($search_List, array("event_type" => 0$ResultSet2['eid'], $ResultSet2['ec'], $ResultSet2['pc'], $ResultSet2['sc'], $ResultSet2['startdate'], $ResultSet2['enddate']));
                continue;
            }
        } else {
            
array_push($search_List, array("event_type" => 0$ResultSet2['eid'], $ResultSet2['ec'], $ResultSet2['pc'], $ResultSet2['sc'], $ResultSet2['startdate'], $ResultSet2['enddate']));
        }
    }
    if (isset(
$_GET['event_type'])) {
        if (
$_GET['event_type'] == || $_GET['event_type'] == "") {
            if (
$_GET['event_type'] == 1)
                
$search_List = array();
            while (
$result $sth3->fetch(PDO::FETCH_ASSOC)) {
                
array_push($search_List, array("event_type" => 1$result['event_id'], $result["event_code"], $result["program_name"], $result['sub_name'], $result['date'], $result['date']));
            }
        }
    }
}
?>

<html>
    <head>        
        <?php include_once '../include/head.php'?>
        <?php include_once '../include/checkuser.php'?>
        <?php include_once '../include/Nav_bar.php'?>  
        <?php if (isset($_GET['search']['code_id'])) { ?>
            <script>
                $(function() {
                    $('#code_id').select2().select2('val', '<?= $_GET['search']['code_id'?>');
                    $('#student_name').select2().select2('val', '<?= $_GET['student_name'?>');
                    $('#staff_name').select2().select2('val', '<?= $_GET['staff_name'?>')
                });
            </script>
        <?php ?>
        <script>
            $(function() {
                $('#start_date_id').datetimepicker({pickTime: false});
                $('#start_date_id').datetimepicker().on('changeDate', function(ev) {
                    date = new Date($('#start_date_input').val());
                    $('#end_date_id').datetimepicker('setStartDate', date);
                    $('#end_date_id').datetimepicker('setDate', date);
                    $('#end_date_id').datetimepicker('show');
                    $('#start_date_id').datetimepicker('hide');
                    $('#end_date_id').datetimepicker('remove');
                });
                $('#end_date_id').datetimepicker({autoclose: true, pickTime: false, startDate: new Date()});
                $('#end_date_id').datetimepicker().on('changeDate', function(ev) {
                    $('#end_date_id').datetimepicker('hide');
                });
                $('#code_id').select2();
                $(".student_name").select2();
                $('.staff_name').select2();
            });
            function check_all() {
                for (var i = 0; i < (document.getElementsByName("event_id[]")).length; i++)
                    (document.getElementsByName("event_id[]"))[i].checked = true;
            }
        </script>
        <style>
            div.pathways-inline-block{
                margin-right: 20px;
            }
        </style>
    </head>
    <body>
        <!-- line between nav bar and content -->
        <div class="text-right">
            <ul class="breadcrumb">
                <li class="active">Event</li>
            </ul>
        </div>

        <div class="container-fluid pathways-container">
            <!--<a class="btn pull-right" href="Event_AddActivityFrom.php"><i class="icon-plus"></i>Activity</a>-->
            <a class="btn pull-right" href="Event_AddFrom.php"><i class="icon-plus"></i>Add</a>
            <h3>Event</h3>            
            <form id="search_form" class="form-inline" action="" method="get">
                <div id="2" style="margin: 0;padding: 5px 10px;background-color: #F7F7F7;border: 1px solid #E6E6E6;border-radius: 5px;box-shadow: 0 1px 2px rgba(0,0,0,.05);">
                    <!--  ## Code ##  -->
                    <div class="pathways-inline-block">                        
                        <label class="" for="code_id">Code : </label>                        
                        <select id="code_id" name="search[code_id]" style="width: 200px;"type="text" maxlength="150" placeholder="Code" >
                            <option value=""></option>
                            <?php $sth $dbh->query("select event_code from event where actived=1 and deleted=0 "?>
                            <?php while ($ResultSet $sth->fetch(PDO::FETCH_ASSOC)) { ?>
                                <option value="<?= $ResultSet['event_code'?>"><?= $ResultSet['event_code'?></option>
                            <?php ?>
                        </select>
                    </div>
                    <!-- ## Program ##  -->

                    <div class="pathways-inline-block">
                        <?php $sth $dbh->query('SELECT * FROM `program` WHERE `deleted` = 0 order by `sort`'); ?>                    
                        <label class="" for="program_id">Programme : </label>
                        <select id="programme_id" class="input-medium" name="search[programme_id]" style="width: 200px">
                            <?php echo '<option value=""></option>'?>
                            <?php while ($ResultSet $sth->fetch(PDO::FETCH_ASSOC)) { ?>
                                <option <?php if (isset($_GET['search']['programme_id'])) if ($_GET['search']['programme_id'] == $ResultSet['program_id']) { ?>selected<?php ?>  value="<?= $ResultSet['program_id'?>"><?= $ResultSet['program_code'?></option>
                            <?php ?>
                        </select>
                    </div>
                    <!-- ## Subject ##  -->
                    <div class="pathways-inline-block">
                        <?php $sth $dbh->query('SELECT * FROM `subject` WHERE `deleted` = 0 order by `sort`'); ?>                    
                        <label class="" for="subject_id">Subject : </label>
                        <select id="subject_id" class="input-medium" name="search[subject_id]"style="width: 200px">
                            <?php echo '<option value=""></option>'?>
                            <?php while ($ResultSet $sth->fetch(PDO::FETCH_ASSOC)) { ?>
                                <option <?php if (isset($_GET['search']['subject_id'])) if ($_GET['search']['subject_id'] == $ResultSet['subject_id']) { ?>selected<?php ?>  value="<?= $ResultSet['subject_id'?>"><?= $ResultSet['sub_code'?></option>
                            <?php ?>
                        </select>
                    </div>

                    <!-- ## Start Date ##  -->
                    <div class="pathways-inline-block"> 
                        <label class="" for="startdate_id">Start Date : </label>
                        <div class="input-append date-picker" id="start_date_id">                
                            <input id="start_date_input" style="width: 200px" class="dateISO" type="text" maxlength="200" placeholder="Start Date" data-format="yyyy-MM-dd" value="<?= (isset($_GET['search'])) ? $_GET['search']['startdate_id'] : "" ?>" name="search[startdate_id]">              
                            <span class="add-on">
                                <i class="icon-calendar" data-date-icon="icon-calendar" data-time-icon="icon-time"></i>
                            </span>
                        </div>
                    </div>
                    <!-- ## End Date ##  -->
                    <div class="pathways-inline-block"> 
                        <label class="" for="enddate_id">End Date : </label>
                        <div class="input-append date-picker" id="end_date_id">                
                            <input id="data_input_date_e" style="width: 200px" class="dateISO" type="text" maxlength="200" placeholder="End Date" data-format="yyyy-MM-dd" value="<?= (isset($_GET['search'])) ? $_GET['search']['enddate_id'] : "" ?>" name="search[enddate_id]">              
                            <span class="add-on">
                                <i class="icon-calendar" data-date-icon="icon-calendar" data-time-icon="icon-time"></i>
                            </span>
                        </div>
                        <!-- ## Search Button ##   <i class="icon-info-sign" ></i>-->
                    </div>

                    <div class="pathways-inline-block">
                        <label>Student Name</label>                         
                        <select name="student_name" id="student_name" class="student_name" >
                            <option value=""></option>
                            <?php $sth $dbh->query("SELECT root_id,`New_stu_ID` id,CONCAT(last_name, ' ', first_name) studentname,`ch_name`FROM `student` WHERE `actived`=1 and`deleted`=0 group by `New_stu_ID`,`Sem_yr`"); ?>
                            <?php while ($ResultSet $sth->fetch(PDO::FETCH_ASSOC)) { ?>                                        
                                <option value="<?= $ResultSet['root_id'?>"><?= $ResultSet['studentname'?> ( <?= $ResultSet['ch_name'?> )</option>
                            <?php ?>
                        </select> 
                    </div>

                    <div class="pathways-inline-block">
                        <label>Staff Name</label>
                        <select name="staff_name" id="staff_name" class="staff_name" style="width: 200px">
                            <option value=""></option>
                            <?php $sth $dbh->query("SELECT CONCAT(`last_name`,' ',`first_name`) staffname, `ch_name` , `root_id` FROM `staff` WHERE `actived`=1 and `deleted`=0 group by root_id"); ?>
                            <?php while ($ResultSet $sth->fetch(PDO::FETCH_ASSOC)) { ?>                                        
                                <option value="<?= $ResultSet['root_id'?>" ><?= $ResultSet['staffname'?> ( <?= $ResultSet['ch_name'?> )</option>
                            <?php ?>
                        </select>
                    </div>

                    <div class="pathways-inline-block">
                        <label>Event Type</label>
                        <select name="event_type" style="width:200px;" id="event_type">
                            <option value=""></option>
                            <option <?= (isset($_GET['event_type'])) ? ($_GET['event_type'] == "selected" "" ) : "" ?> value="1">Activity</option>
                            <option <?= (isset($_GET['event_type'])) ? ($_GET['event_type'] === "0" "selected" "" ) : "" ?> value="0">Course</option>
                        </select>
                    </div>
                    <button name="search[submit]" class="btn" style="margin-left:30px;" type="submit">Search</button>
                </div>
                <div style="height: 15px;"></div>

                <div style="height: 15px;"></div>
                <table class="table table-striped table-bordered table-hover table-condensed">
                    <thead>
                        <tr>                    
                            <th style="width: 70px;"></th>                            
                            <th>Code</th>
                            <th>Programmme</th>
                            <th>Subject</th>
                            <th>Start Date</th>
                            <th>End Date</th>
                            <th>Details</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php if (isset($_GET["search"])) { ?> 
                            <?php foreach ($search_List as $arr) { ?>
                                <tr>
                                    <td style="padding-left:5px;">
                                        <?php if (($arr["event_type"]) == 0) { ?>
                                            <a href="<?= 'Event_AddFrom.php?event_id=' $arr[0] . "&view=1" ?>" class="btn"><i class="icon-eye-open"></i> View</a>                                            
                                        <?php } else { ?>
                                            <a href="<?= "Event_AddActivityFrom.php?event_id=" $arr[0] . "&view=1" ?>" class="btn"><i class="icon-eye-open"></i> View</a>
                                        <?php ?>
                                    </td>
                                    <td><?= $arr[1?></td>                    
                                    <td><?= $arr[2?></td>
                                    <td><?= $arr[3?></td>
                                    <?php if ($arr['event_type'] == 0) { ?>
                                        <?php $sth2 $dbh->query("Select Min(date) min,Max(date) max from lesson where lesson_id in (SELECT `lesson_id` FROM `event_lesson` WHERE deleted=0 and  `event_id` = " $arr[0] . ")"); ?>
                                        <?php while ($ResultSet2 $sth2->fetch(PDO::FETCH_ASSOC)) { ?>
                                            <td><?= $ResultSet2['min'?></td>
                                            <td><?= $ResultSet2['max'?></td>
                                        <?php ?>
                                    <?php } else { ?>
                                        <td><?= $arr[5?></td>
                                        <td><?= $arr[5?></td>
                                    <?php ?>
                                    <td style="width: 80px">                                        
                                        <?php if (($arr["event_type"]) == 0) { ?>
                                            <a class="btn" href="Event_DetailFrom.php?event_id=<?= $arr[0?>"><i class="icon-info-sign"></i>&nbsp;Detail</a>
                                        <?php } else { ?>

                                        <?php ?>
                                    </td>
                                </tr>
                            <?php ?>
                        <?php ?>                    
                    </tbody>
                </table>
            </form>   
        </div> <!-- /container -->
    </body>
</html>