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
|
<!DOCTYPE html> <html> <head> <?php require_once '../include/head.php'; ?> <?php require_once '../include/checkuser.php'; ?> <?php require_once '../include/Nav_bar.php'; ?> <?php include_once '../include/DBConnect.php'; ?> <script> $(function() { $('.date-picker').datetimepicker({pickTime: false}); $('.stun').select2(); }); </script> </head> <style> .table{ background:#eeefde; } </style> <body> <?php $studentid = ""; $countstudent = 0; $createdate = date('Y-m-d'); $state = array('Application Form', 'Assessment', 'Schedule');
if (isset($_POST['addstu']) && $_POST['stun'] != "ALL") { $stuname = $_POST['stun']; $subject = $_POST['subject']; $program = $_POST['program']; $state_id = $_POST['state']; $wid = 0; $oldstid; $oldproid; $oldsubid; $oldhead; $stid; $proid; $subid; $ishead; $countstu; $dontinsert = false; $inserted = false; $insertfromtail = false; $insertfromN = false; $insertfromhead = false; $searchstid = "select root_id from student where CONCAT(last_name, ' ', first_name) = '$stuname' and deleted = 0 group by root_id"; $result = $dbh->query($searchstid); $result->setFetchMode(PDO::FETCH_OBJ); while ($row = $result->fetch()) { $stid = $row->root_id; } $searchpro = "select program_id from program where program_code = '$program' and deleted = 0"; $result = $dbh->query($searchpro); $result->setFetchMode(PDO::FETCH_OBJ); while ($row = $result->fetch()) { $proid = $row->program_id; } $searchsub = "select subject_id from subject where sub_code = '$subject' and deleted = 0"; $result = $dbh->query($searchsub); $result->setFetchMode(PDO::FETCH_OBJ); while ($row = $result->fetch()) { $subid = $row->subject_id; } $searchhvrd = "select stu_linking_id, program_id, subject_id from waiting_list where deleted = 0 group by waiting_id"; $hvrd = $dbh->query($searchhvrd); $hvrd->setFetchMode(PDO::FETCH_OBJ); while ($row = $hvrd->fetch()) { if ($row->stu_linking_id == $stid && $row->program_id == $proid && $row->subject_id == $subid) $dontinsert = true; } if ($dontinsert == false && $subject != 'ALL' && $program != 'ALL') { $searchp = "select waiting_id, stu_linking_id, program_id, subject_id, is_head from waiting_list where deleted = 0 and program_id = '$proid' and subject_id = '$subid' and priority is NULL"; $sqlsearchp = $dbh->query($searchp); $sqlsearchp->setFetchMode(PDO::FETCH_OBJ); while ($row = $sqlsearchp->fetch()) { $wid = $row->waiting_id; $oldstid = $row->stu_linking_id; $oldproid = $row->program_id; $oldsubid = $row->subject_id; $oldhead = $row->is_head; } if ($wid == 0) $ishead = 1; else $ishead = 0; if (empty($_POST['priority'])) { $insertfromtail = true; } else { $countwid = "select count(stu_linking_id) as cstuid from waiting_list where deleted = 0 and program_id = '$proid' and subject_id = '$subid'"; $sqlcountwid = $dbh->query($countwid); $sqlcountwid->setFetchMode(PDO::FETCH_OBJ); while ($row = $sqlcountwid->fetch()) { $countstu = $row->cstuid; } if ($_POST['priority'] > ($countstu + 1)) { echo "<script>alert('Please input a right priority value!!')</script>"; echo("<script>location.href ='add.php';</script>"); } else { if ($_POST['priority'] == 1) { $insertfromhead = true; $insertfromN = false; $insertfromtail = false; } if ($_POST['priority'] > 1) { $insertfromhead = false; $insertfromN = true; $insertfromtail = false; } if ($_POST['priority'] == $countstu + 1) { $insertfromhead = false; $insertfromN = false; $insertfromtail = true; } } }
if ($insertfromtail) { $sth = $dbh->prepare("INSERT INTO `waiting_list`(`createby`, `createdate`, `lastupby`, `lastupdate`, `actived`, `deleted`, `stu_linking_id`, `program_id`, `subject_id`, `priority`, `is_head`, `state_id`) VALUES (1, now(), 1 ,now(),1,0,?,?,?,NULL,?,?)"); $sth->bindParam(1, $stid); $sth->bindParam(2, $proid); $sth->bindParam(3, $subid); $sth->bindParam(4, $ishead); $sth->bindParam(5, $state_id); $sth->execute();
if ($wid != 0 && $insertfromtail) { $maxwid; $max = "select max(waiting_id) as maxid from waiting_list"; $sqlmax = $dbh->query($max); $sqlmax->setFetchMode(PDO::FETCH_OBJ); while ($row = $sqlmax->fetch()) { $maxwid = $row->maxid; } $sth = $dbh->prepare("UPDATE `waiting_list` SET `lastupby`=1,`lastupdate`=now(),`priority` = '$maxwid' WHERE waiting_id = '$wid'"); $sth->execute(); } } if ($insertfromN) { $pid; $nextid; $maxwid; $selecthead = "select waiting_id, priority from waiting_list where deleted = 0 and subject_id = '$subid' and program_id = '$proid' and is_head = 1"; $sqlselecthead = $dbh->query($selecthead); $sqlselecthead->setFetchMode(PDO::FETCH_OBJ); while ($row = $sqlselecthead->fetch()) { $pid = $row->waiting_id; $nextid = $row->priority; } for ($loop = 1; $loop < $_POST['priority'] - 1; $loop++) { $selectp = "select waiting_id, priority from waiting_list where deleted = 0 and subject_id = '$subid' and program_id = '$proid' and waiting_id = '$nextid'"; $sqlselectp = $dbh->query($selectp); $sqlselectp->setFetchMode(PDO::FETCH_OBJ); while ($row = $sqlselectp->fetch()) { $pid = $row->waiting_id; $nextid = $row->priority; } } $sth = $dbh->prepare("INSERT INTO `waiting_list`(`createby`, `createdate`, `lastupby`, `lastupdate`, `actived`, `deleted`, `stu_linking_id`, `program_id`, `subject_id`, `priority`, `is_head`) VALUES (1, now(), 1 ,now(),1,0,?,?,?,?,0)"); $sth->bindParam(1, $stid); $sth->bindParam(2, $proid); $sth->bindParam(3, $subid); $sth->bindParam(4, $nextid); $sth->execute();
$max = "select max(waiting_id) as maxid from waiting_list"; $sqlmax = $dbh->query($max); $sqlmax->setFetchMode(PDO::FETCH_OBJ); while ($row = $sqlmax->fetch()) { $maxwid = $row->maxid; } $sth = $dbh->prepare("UPDATE `waiting_list` SET `lastupby`=1,`lastupdate`=now(),`priority` = '$maxwid' WHERE waiting_id = '$pid'"); $sth->execute(); } if ($insertfromhead) { $pid; $selecthead = "select waiting_id from waiting_list where deleted = 0 and subject_id = '$subid' and program_id = '$proid' and is_head = 1"; $sqlselecthead = $dbh->query($selecthead); $sqlselecthead->setFetchMode(PDO::FETCH_OBJ); while ($row = $sqlselecthead->fetch()) { $pid = $row->waiting_id; } $sth = $dbh->prepare("INSERT INTO `waiting_list`(`createby`, `createdate`, `lastupby`, `lastupdate`, `actived`, `deleted`, `stu_linking_id`, `program_id`, `subject_id`, `priority`, `is_head`) VALUES (1, now(), 1 ,now(),1,0,?,?,?,?,1)"); $sth->bindParam(1, $stid); $sth->bindParam(2, $proid); $sth->bindParam(3, $subid); $sth->bindParam(4, $pid); $sth->execute();
$sth = $dbh->prepare("UPDATE `waiting_list` SET `lastupby`=1,`lastupdate`=now(),`is_head` = 0 WHERE waiting_id = '$pid'"); $sth->execute(); } $inserted = true; } if ($inserted) { echo "<script>alert('Insert data successful.')</script>"; echo("<script>location.href ='index.php';</script>"); } if ($inserted == false && $dontinsert = true) echo "<script>alert('there have same data in database.')</script>"; } ?> <!-- line between nav bar and content --> <div class="text-right"> <ul class="breadcrumb"> <li class="active">Add WaitingList</li> </ul> </div> <!-- line between nav bar and content --> <div class="container-fluid pathways-container"> <form id="search_form" class="form-inline" action="" method="POST"> <table border="0" class="table table-bordered table-hover table-condensed"> <tr> <td><h3>Add Waiting List</h3></td> </tr> <tr> <td width="20%"><label>Student</label></td> <td><select name="stun" id="stun" class="stun" style="width:150px"> <option value="ALL"> </option> <?php $sth = $dbh->query("SELECT linking_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['studentname'] ?>"><?= $ResultSet['studentname'] ?></option> <?php } ?> </select> </td> </tr> <tr> <td width="20%"><label class="" id="program" name="program">Program</label></td> <td><select id="program" name="program" class="input-medium" value="program" > <option value="ALL"> </option> <?php $query = "select program_code from program "; $result = $dbh->query($query); $result->setFetchMode(PDO::FETCH_OBJ); while ($row = $result->fetch()) { ?> <option <?php if (isset($_POST['go'])) if ($_POST['program'] == $row->program_code) { ?> selected <?php } ?> value ="<?= $row->program_code ?>"><?= $row->program_code ?></option> <?php } ?> </select></td> </tr> <tr> <td width="20%"><label class="" id="program" name="subject" value="subject" >Subject</label></td> <td><select id="subject" name="subject" class="input-medium" > <option value="ALL"> </option> <?php $query = "select sub_code from subject "; $result = $dbh->query($query); $result->setFetchMode(PDO::FETCH_OBJ); while ($row = $result->fetch()) { ?> <option <?php if (isset($_POST['go'])) if ($_POST['subject'] == $row->sub_code) { ?> selected <?php } ?> value ="<?= $row->sub_code ?>"><?= $row->sub_code ?></option> <?php } s ?> </select></td>
</tr> <tr> <td width="20%"><label>State</label></td> <td><select name="state" class="state" style="width:150px"> <?php for ($a = 0; $a < count($state); $a++) { ?> <option value="<?= $a ?>"><?= $state[$a] ?></option> <?php } ?> </select></td> </tr> <!--tr> <td><label width="20%">Priority</label></td> <td><input type="text" name="priority" id="priority" onkeydown="return (event.ctrlKey || event.altKey || (47 < event.keyCode && event.keyCode < 58 && event.shiftKey == false) || (95 < event.keyCode && event.keyCode < 106) || (event.keyCode == 8) || (event.keyCode == 9) || (event.keyCode > 34 && event.keyCode < 40) || (event.keyCode == 46))"></td> </tr--> </table> <div class="input-append date-picker"> <button class="btn" name="addstu" value="addstu" style="margin-left:30px" type="submit">ADD</button> </div> </form> </div> <!-- /container --> </body> </html>
|