/var/www/(Del)pathways.org.hk/MIS_bk/event/lesson_staff.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
<?php
require_once(__DIR__ '/../checkuser.php');
function 
lesson_staff() {
    global 
$dbh;
    
    
$message $_GET['message'];
    
    
$id = isset($_GET['id']) ? $_GET['id'] : null;
    
$sql "SELECT * FROM mis_event_lesson WHERE id = ? AND deleted = ?";
    
$parameters = array($id0);
    
$sth Db\Util::execute($dbh$sql$parameters);
    
$event_lesson $sth->fetch(PDO::FETCH_ASSOC);
    if (!
$event_lesson) {
        throw new 
Exception('Event Lesson not found!');
    }

    
$sql "
SELECT evt.*, program.code AS program_code, subject.code AS subject_code
FROM mis_event evt
LEFT JOIN mis_program program ON program.id = evt.program_id
LEFT JOIN mis_subject subject ON subject.id = evt.subject_id
WHERE evt.id = ? AND evt.deleted = ?"
;
    
$parameters = array($event_lesson['event_id'], 0);
    
$sth Db\Util::execute($dbh$sql$parameters);
    
$event $sth->fetch(PDO::FETCH_ASSOC);
    if (!
$event) {
        throw new 
Exception('Event not found!');
    }

    
$sql "
SELECT lesson_staff.*, latest_staff.last_name, latest_staff.first_name, staff_position.title AS position_title
FROM mis_lesson_staff lesson_staff
LEFT JOIN mis_staff staff ON staff.id = lesson_staff.staff_id
LEFT JOIN mis_staff latest_staff ON latest_staff.root_id = staff.root_id AND latest_staff.is_latest = 1
LEFT JOIN mis_staff_position staff_position ON staff_position.id = lesson_staff.staff_position_id
WHERE lesson_staff.lesson_id = ? AND lesson_staff.deleted = ?
ORDER BY latest_staff.last_name, latest_staff.first_name, latest_staff.root_id"
;
    
$parameters = array($event_lesson['id'], 0);
    
$sth Db\Util::execute($dbh$sql$parameters);
    
$lesson_staffs $sth->fetchAll();
    
//    if (isPost()) {
//        // Save
//        
//        $data = array(
//            'message' => 'Saved',
//            'id' => $event['id'],
//        );
//        redirectAndExit(Util::link(__DIR__ . '/details.php') . '?' . http_build_query($data));
//    }
    
    
return array(
        
'message' => $message,
        
'event' => $event,
        
'event_lesson' => $event_lesson,
        
'lesson_staffs' => $lesson_staffs,
    );
}
extract(lesson_staff());
?><!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    
    <?php require(__DIR__ '/../inc/_head_meta.php'); ?>
    
    <?php require(__DIR__ '/../inc/_head_css.php'); ?>
    
    <?php require(__DIR__ '/../inc/_head_script.php'); ?>
    
</head>
<body>
    
    <?php require( __DIR__ '/../inc/_navbar.php'); ?>
    
    <div class="text-right">
        <ul class="breadcrumb">
            <li><a href="#">Event</a> <span class="divider">&gt;</span></li>
            <li><a href="details.php?id=<?=h($event['id'])?>">Details</a> <span class="divider">&gt;</span></li>
            <li class="active">Staff</li>
        </ul>
    </div>
    
    <div class="container-fluid pathways-container">
        
        <?php if (isset($message) && !empty($message)): ?>
        <div class="alert alert-info">
            <button type="button" class="close" data-dismiss="alert">&times;</button>
            <h5 class="alert-heading">Note:</h5>
            <p><?=$message?></p>
        </div>
        <?php endif; ?>

        <h3>Lesson Details - Staff</h3>
        
        <div class="form-horizontal">
            <div class="control-group">
                <?php $attribute 'code'$label 'Code'?>
                <label class="control-label" for="<?=$attribute?>"><?=$label?></label>
                <div class="controls form-inline">
                    <input type="text" id="<?=$attribute?>" name="event[<?=$attribute?>]" class="" value="<?=h($event[$attribute])?>" placeholder="<?=h($label)?>" maxlength="200" readonly="readonly" />
                </div>
            </div>
            
            <div class="control-group">
                <?php $attribute 'program_code'$label 'Programme'?>
                <label class="control-label" for="<?=$attribute?>"><?=$label?></label>
                <div class="controls form-inline">
                    <input type="text" id="<?=$attribute?>" name="event[<?=$attribute?>]" class="" value="<?=h($event[$attribute])?>" placeholder="<?=h($label)?>" maxlength="200" readonly="readonly" />
                </div>
            </div>
            
            <div class="control-group">
                <?php $attribute 'subject_code'$label 'Subject'?>
                <label class="control-label" for="<?=$attribute?>"><?=$label?></label>
                <div class="controls form-inline">
                    <input type="text" id="<?=$attribute?>" name="event[<?=$attribute?>]" class="" value="<?=h($event[$attribute])?>" placeholder="<?=h($label)?>" maxlength="200" readonly="readonly" />
                </div>
            </div>
            
            <div class="control-group">
                <?php $attribute 'number'$label 'Lesson'?>
                <label class="control-label" for="<?=$attribute?>"><?=$label?></label>
                <div class="controls form-inline">
                    <input type="text" id="<?=$attribute?>" name="event_lesson[<?=$attribute?>]" class="" value="<?=h($event_lesson[$attribute])?>" placeholder="<?=h($label)?>" maxlength="200" readonly="readonly" />
                </div>
            </div>
        </div>
        
        <div class="text-right">
            <a href="lesson_staff_add.php?id=<?=h($event_lesson['id'])?>" class="btn"><i class="icon-plus"></i> Add</a>
        </div>
        
        <form id="form" class="form-horizontal" method="post" enctype="multipart/form-data">
            <?php $attribute 'id'?>
            <input type="hidden" name="event_lesson[<?=$attribute?>]" value="<?=h($event_lesson[$attribute])?>" />
            
            <input type="hidden" name="event_lesson[lesson_staff_id]" value="" />
            <input type="hidden" name="event_lesson[type]" value="" />
            
            <table class="table table-striped table-bordered table-hover table-condensed">
                <thead>
                    <?php $column_count 0?>
                    <tr>
                        <th style="min-width:50px; width:50px">Delete</th><?php $column_count++; ?>
                        <th style="min-width:200px; width:200px">Name</th><?php $column_count++; ?>
                        <th>Teaching Role</th><?php $column_count++; ?>
                    </tr>
                </thead>
                <tfoot>
                    <?php if (count($lesson_staffs) == 0): ?>
                    <tr>
                        <td colspan="<?=$column_count?>">There are no records.</td>
                    </tr>
                    <?php endif; ?>
                </tfoot>
                <tbody>
                    <?php foreach ($lesson_staffs as $lesson_staff): ?>
                    <tr>
                        <td>
                            <button type="button" class="btn remove-staff-btn" data-lesson_staff_id="<?=h($lesson_staff['id'])?>"><i class="icon-remove"></i></button>
                        </td>
                        <td><?=h($lesson_staff['last_name'])?> <?=h($lesson_staff['first_name'])?></td>
                        <td><?=h($lesson_staff['position_title'])?></td>
                    </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        </form>
        
        <?php
        $data 
= array(
            
'id' => $event['id'],
        );
        
?>
        <a href="<?=Util::link(__DIR__ '/details.php') . '?' http_build_query($data)?>" class="btn">Back</a>
        
        <script type="text/javascript">
            $(function() {
                $('.remove-staff-btn').click(function() {
                    var lesson_staff_id = $(this).data('lesson_staff_id'),
                        $form = $('#form');
                    bootbox.dialog('Remove Options', [
                        {
                            'label': 'Current lesson',
                            'class': 'btn-danger',
                            'callback': function() {
                                $('input[name="event_lesson[lesson_staff_id]"]', $form).val(lesson_staff_id);
                                $('input[name="event_lesson[type]"]', $form).val(1);
                                $form.attr('action', 'lesson_staff_delete.php').submit();
                            }
                        },
                        {
                            'label': 'Current lesson with after lessons',
                            'class': 'btn-danger',
                            'callback': function() {
                                $('input[name="event_lesson[lesson_staff_id]"]', $form).val(lesson_staff_id);
                                $('input[name="event_lesson[type]"]', $form).val(2);
                                $form.attr('action', 'lesson_staff_delete.php').submit();
                            }
                        },
                        {
                            'label': 'Cancel',
                            'class': 'btn'
                        }
                    ]);
                });
            });
        </script>
        
        <?php require( __DIR__ '/../inc/_footer.php'); ?>

    </div> <!-- /container -->
</body>
</html>