| Server IP : 210.245.233.93 / Your IP : 216.73.216.226 Web Server : Apache/2.2.15 (CentOS) System : Linux webserver2.onesolution.com.hk 2.6.32-754.35.1.el6.x86_64 #1 SMP Sat Nov 7 12:42:14 UTC 2020 x86_64 User : apache ( 48) PHP Version : 5.3.3 Disable Function : exec, shell_exec, system, passthru, popen, proc_open, pcntl_exec MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/(Del)pathways.org.hk/MIS20140127/old20140407/WaitingList/ |
Upload File : |
<!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>