| 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/Attendance/ |
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});
$('#search_form').validate();
$('.time').timepicker({'step': 15, 'timeFormat': 'H:i', 'minTime': '06:00', 'maxTime': '23:30'});
$('.staff_name').select2();
$('.stun').select2();
$('.searchstun').select2();
});
function check_change(e) {
$('#tablehead tr:nth-child(' + (e + 2) + ') input[type=checkbox] ').attr("checked", true);
}
</script>
<?php if (isset($_POST['go'])) { ?>
<script>
$(function() {
$('#staff_name').select2().select2('val', '<?= $_POST['staff_name'] ?>');
$('#stun').select2().select2('val', '<?= $_POST['searchstun'] ?>');
});
</script>
<?php } ?>
</head>
<body>
<?php
//Dim data
$countstaff = 0;
$staffid = "";
$startdate = date('Y-m-d');
$enddate = date('Y-m-d');
$today = date('Y-m-d');
?>
<?php
if (isset($_POST['save'])) {
//insert data
$startdate = $_POST['startdate'];
$enddate = $_POST['enddate'];
for ($i = strtotime($startdate); $i <= strtotime($enddate); $i = $i + 86400) {
$countstaff = 0;
$countstudent = 0;
$today = date('Y-m-d', $i);
foreach ($_POST["staffid_$today"] as $insertid) {
if (isset($_POST["check_$today"][$countstaff]) && $_POST["check_$today"][$countstaff] = '1') {
$sth = $dbh->prepare("UPDATE attendance SET deleted = 1 WHERE staff_id = ? and date = ?");
$sth->bindParam(1, $insertid);
$sth->bindParam(2, $today);
$sth->execute();
$sth = $dbh->prepare("INSERT INTO `attendance`(`createby`, `createdate`, `lastupby`, `lastupdate`, `actived`, `deleted`, `staff_id`, `stu_linking_id`, `date`, `attendance`, `in_time`, `out_time`, `reason_id`) VALUES (1, now(), 1 ,now(),1,0,?,NULL,?,?,?,?,?) ");
$sth->bindParam(1, $insertid);
$sth->bindParam(2, $today);
$sth->bindParam(3, $_POST["staffr_$countstaff"][$today]);
$sth->bindParam(4, $_POST["start_time_$countstaff"][$today]);
$sth->bindParam(5, $_POST["end_time_$countstaff"][$today]);
$sth->bindParam(6, $_POST["reason_$countstaff"][$today]);
$sth->execute();
}
if (isset($_POST["nocheck_$today"][$countstaff])) {
$sth = $dbh->prepare("INSERT INTO `attendance`(`createby`, `createdate`, `lastupby`, `lastupdate`, `actived`, `deleted`, `staff_id`, `stu_linking_id`, `date`, `attendance`, `in_time`, `out_time`, `reason_id`) VALUES (1, now(), 1 ,now(),1,0,?,NULL,?,?,?,?,?) ");
$sth->bindParam(1, $insertid);
$sth->bindParam(2, $today);
$sth->bindParam(3, $_POST["staffr_$countstaff"][$today]);
$sth->bindParam(4, $_POST["start_time_$countstaff"][$today]);
$sth->bindParam(5, $_POST["end_time_$countstaff"][$today]);
$sth->bindParam(6, $_POST["reason_$countstaff"][$today]);
$sth->execute();
}
$countstaff++;
}
if (isset($_POST["stuid_$today"])) {
foreach ($_POST["stuid_$today"] as $insertid) {
if (isset($_POST["check_$today"][$countstudent]) && $_POST["check_$today"][$countstudent] = '1') {
$sth = $dbh->prepare("UPDATE attendance SET deleted = 1 WHERE stu_linking_id = ? and date = ?");
$sth->bindParam(1, $insertid);
$sth->bindParam(2, $today);
$sth->execute();
$sth = $dbh->prepare("INSERT INTO `attendance`(`createby`, `createdate`, `lastupby`, `lastupdate`, `actived`, `deleted`, `staff_id`, `stu_linking_id`, `date`, `attendance`, `in_time`, `out_time`, `reason_id`) VALUES (1, now(), 1 ,now(),1,0,NULL,?,?,?,?,?,?) ");
$sth->bindParam(1, $insertid);
$sth->bindParam(2, $today);
$sth->bindParam(3, $_POST["stur_$countstudent"][$today]);
$sth->bindParam(4, $_POST["stu_start_time_$countstudent"][$today]);
$sth->bindParam(5, $_POST["stu_end_time_$countstudent"][$today]);
$sth->bindParam(6, $_POST["stu_reason_$countstudent"][$today]);
$sth->execute();
}
$countstudent++;
}
}
}
echo "<script>alert('Add successful.')</script>";
}
if (isset($_POST['addstu']) && $_POST['stun'] != "student_name") {
$adddate = $_POST['studate'];
$stuname = $_POST['stun'];
$stid;
$searchstid = "select root_id from student where deleted = 0 and CONCAT(last_name, ' ', first_name) = '$stuname'";
$result = $dbh->query($searchstid);
$result->setFetchMode(PDO::FETCH_OBJ);
while ($row = $result->fetch()) {
$stid = $row->root_id;
}
$sth = $dbh->prepare("INSERT INTO `attendance`(`createby`, `createdate`, `lastupby`, `lastupdate`, `actived`, `deleted`, `staff_id`, `stu_linking_id`, `date`, `attendance`, `in_time`, `out_time`, `reason_id`) VALUES (1, now(), 1 ,now(),1,0,NULL,?,?,1,?,?,0) ");
$sth->bindParam(1, $stid);
$sth->bindParam(2, $adddate);
$sth->bindParam(3, $_POST['start_time_stu']);
$sth->bindParam(4, $_POST['end_time_stu']);
$sth->execute();
}
?>
<!-- line between nav bar and content -->
<div class="text-right">
<ul class="breadcrumb">
<li class="active">Daily Attendance</li>
</ul>
</div>
<!-- line between nav bar and content -->
<div class="container-fluid pathways-container">
<h3>Daily Attendance</h3>
<div class="pathways-search">
<form id="search_form" class="form-inline" action="" method="POST">
<div class="pathways-inline-block">
<label class="">Date</label>
<div class="input-append date-picker">
<input id="start_date" class="dateISO" type="text" maxlength="200" data-format="yyyy-MM-dd" name="startdate" value="<?php
if (isset($_POST['go']))
echo $_POST['startdate'];
else
echo $startdate;
?>" style="width:90px" required>
<span class="add-on">
<i class="icon-calendar" data-date-icon="icon-calendar" data-time-icon="icon-time"></i>
</span>
</div>
<label class="" >To</label>
<div class="input-append date-picker">
<input id="end_date" class="dateISO" type="text" maxlength="200" data-format="yyyy-MM-dd" name="enddate" value="<?php
if (isset($_POST['go']))
echo $_POST['enddate'];
else
echo $enddate;
?>" style="width:90px" required>
<span class="add-on">
<i class="icon-calendar" data-date-icon="icon-calendar" data-time-icon="icon-time"></i>
</span>
</div>
</div>
<div class="pathways-inline-block">
<label>Student</label>
<select name="searchstun" id="stun" class="stun" style="width:170px">
<option value="ALL">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>
</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="ALL">All</option>
<?php $sth = $dbh->query("SELECT CONCAT(`last_name`,' ',`first_name`) staffname, `ch_name` , `staff_id` FROM `staff` WHERE `actived`=1 and `deleted`=0 group by `staff_id`"); ?>
<?php while ($ResultSet = $sth->fetch(PDO::FETCH_ASSOC)) { ?>
<option value="<?= $ResultSet['staffname'] ?>" ><?= $ResultSet['staffname'] ?></option>
<?php } ?>
</select>
</div>
<div class="pathways-inline-block">
<button class="btn" name="go" value="go" style="margin-left:30px" type="submit">GO</button>
<input type="hidden" name="staffid[]" value="">
</div>
<hr>
<div class="pathways-inline-block">
<label>Add Student</label>
<select name="stun" id="stun" class="stun" style="width:170px">
<option value="student_name"></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>
</div>
<label class="">In time</label>
<div class="pathways-inline-block">
<input id="start_time" type="text" class="time" name = "start_time_stu" style = "width:45px">
</div>
<label class="">Out time</label>
<div class="pathways-inline-block">
<input id="end_time" type="text" class="time" name = "end_time_stu" style = "width:45px">
</div>
<label class="" >Date</label>
<div class="input-append date-picker">
<input id="end_date" class="dateISO" type="text" maxlength="200" data-format="yyyy-MM-dd" name="studate" style="width:90px" value="<?= $today ?>">
<span class="add-on">
<i class="icon-calendar" data-date-icon="icon-calendar" data-time-icon="icon-time"></i>
</span>
</div>
<div class="input-append date-picker">
<button class="btn" name="addstu" value="addstu" style="margin-left:30px" type="submit">ADD</button>
</div>
</form>
</div>
<!-- date picker -->
<?php
if (isset($_POST['go'])) {
$searchstudent = NULL;
$searchstaff = NULL;
$startdate = $_POST['startdate'];
$enddate = $_POST['enddate'];
if ($_POST['staff_name'] != "ALL")
$searchstaff = " CONCAT(s.last_name, ' ', s.first_name) = '" . $_POST['staff_name'] . "' and ";
if ($_POST['staff_name'] != "ALL" && $_POST['searchstun'] == "ALL")
$searchstudent = " CONCAT(stu.last_name, ' ', stu.first_name) = 'no search' and ";
if ($_POST['searchstun'] != "ALL")
$searchstudent = " CONCAT(stu.last_name, ' ', stu.first_name) = '" . $_POST['searchstun'] . "' and ";
if ($_POST['searchstun'] != "ALL" && $_POST['staff_name'] == "ALL")
$searchstaff = " CONCAT(s.last_name, ' ', s.first_name) = 'no search' and ";
//search data
?>
<form id="form" action="" method="POST">
<?php
for ($i = strtotime($startdate); $i <= strtotime($enddate); $i = $i + 86400) {
$hvrecord = false;
$today = date('Y-m-d', $i);
?>
<h5>Date: <?= $today ?></h5>
<table class="table table-striped table-bordered table-hover table-condensed" id="tablehead">
<thead>
<tr>
<th >Name</th>
<th style="min-width:50px; width:50px">Type</th>
<th style="min-width:150px; width:150px">In Time</th>
<th style="min-width:150px; width:150px">Out Time</th>
<th style="min-width:250px; width:250px">Attendance</th>
<th style="min-width:200px; width:200px">Reason(If Absent)</th>
</tr>
</thead>
<tbody>
<?php
$search = "select date from attendance where deleted = 0 and staff_id in (select staff_id from attendance where staff_id <> 'NULL') group by date";
$sdate = $dbh->query($search);
$sdate->setFetchMode(PDO::FETCH_OBJ);
while ($sd = $sdate->fetch()) {
if ($sd->date == $today)
$hvrecord = true;
}
?>
<tr style='display: none;'><input type="hidden" name="startdate" value="<?= $startdate ?>">
<input type="hidden" name="enddate" value="<?= $enddate ?>"></tr>
<?php
if ($searchstaff != " CONCAT(s.last_name, ' ', s.first_name) = 'no search' and " || $searchstudent == " CONCAT(stu.last_name, ' ', stu.first_name) = 'no search' and ") {
if ($hvrecord) {
$countstaff = 0;
$query1 = "select s.last_name as ln, s.first_name as fn, a.reason_id as reid, a.attendance as attend, a.in_time as it, a.out_time as ot, a.staff_id as id from attendance a, staff s, reason r, student stu where " . $searchstaff . "a.staff_id = s.staff_id and date = '$today' and a.deleted = 0 and r.deleted = 0 group by a.attend_id";
$result = $dbh->query($query1);
$result->setFetchMode(PDO::FETCH_OBJ);
?>
<?php
while ($row = $result->fetch()) {
?>
<tr>
<td ><input style='display: none;' type ="checkbox" name ="check_<?= $today ?>[<?= $countstaff ?>]" value="1"><h5><?php echo $row->ln . " " . $row->fn ?></h5></td>
<td style='display: none;'> <input type="hidden" name="staffid_<?= $today ?>[]" value="<?= $row->id ?>"></td>
<td>Teacher</td>
<td>
<input onclick="check_change(<?= $countstaff ?>);" id="start_time" type="text" class="time" name = "start_time_<?= $countstaff ?>[<?= $today ?>]" style = "width:45px" value="<?= $row->it ?>">
</td>
<td>
<input onclick="check_change(<?= $countstaff ?>);" id="end_time" type="text" class="time" name = "end_time_<?= $countstaff ?>[<?= $today ?>]" style = "width:45px" value="<?= $row->ot ?>">
</td>
<td>
<div class="pathways-inline-block" style="margin-right:0px">
<label class="radio inline">
<?php
// if ($row->attend == 1) {
// echo "<script>$(function(){ document.getElementById('staffp$countstaff$today').checked = true;});</script>";
// } else {
// echo "<script>$(function(){ document.getElementById('staffa$countstaff$today').checked = true;});</script>";
// }
?>
<input <?php if ($row->attend == 1) { ?>checked <?php } else echo""; ?> onclick="check_change(<?= $countstaff ?>);" type="radio" id = "staffp<?= $countstaff ?><?= $today ?>" name="staffr_<?= $countstaff ?>[<?= $today ?>]" value="1"/>
Present
</label>
<label class="radio inline">
<input <?php if ($row->attend == 0) { ?>checked <?php } ?> onclick="check_change(<?= $countstaff ?>);" type="radio" id = "staffa<?= $countstaff ?><?= $today ?>" name="staffr_<?= $countstaff ?>[<?= $today ?>]" value="0"/>
Absent
</label>
<!--span class="label label-important" style="margin-left:10px">Still not save</span-->
</div>
</td>
<td>
<select onclick="check_change(<?= $countstaff ?>);" id="reason" name="reason_<?= $countstaff ?>[<?= $today ?>]" class="input-medium">
<option value="0"> </option>
<?php
$query = "select reason_id, reason_name from reason ";
$resultr = $dbh->query($query);
$resultr->setFetchMode(PDO::FETCH_OBJ);
while ($rowr = $resultr->fetch()) {
?>
<option <?php if ($row->reid == $rowr->reason_id) { ?> selected <?php } ?>value="<?= $rowr->reason_id ?>"><?= $rowr->reason_name ?></option>
<?php } ?>
</select>
</td>
</tr>
<?php
$countstaff++;
}
}
}
if ($hvrecord == false && $searchstaff == NULL && $searchstudent == NULL) {
$countstaff = 0;
$query2 = "select staff_id as id, first_name as fn, last_name as ln from staff where deleted = 0";
$result = $dbh->query($query2);
$result->setFetchMode(PDO::FETCH_OBJ);
?>
<tbody>
<?php
while ($row = $result->fetch()) {
?>
<tr>
<input type="hidden" name="staffid_<?= $today ?>[]" value="<?= $row->id ?>">
<input type="hidden" name="nocheck_<?= $today ?>[<?= $countstaff ?>]" value="1">
<td>
<h5><?php echo $row->ln . " " . $row->fn ?></h5>
</td>
<td>Teacher</td>
<td>
<input id="start_time" type="text" class="time" name = "start_time_<?= $countstaff ?>[<?= $today ?>]" style = "width:45px">
</td>
<td>
<input id="end_time" type="text" class="time" name = "end_time_<?= $countstaff ?>[<?= $today ?>]" style = "width:45px">
</td>
<td>
<div class="pathways-inline-block" style="margin-right:0px">
<label class="radio inline">
<input type="radio" id = "staffp" name="staffr_<?= $countstaff ?>[<?= $today ?>]" value="1" checked="" />
Present
</label>
<label class="radio inline">
<input type="radio" id = "staffa" name="staffr_<?= $countstaff ?>[<?= $today ?>]" value="0"/>
Absent
</label>
<span class="label label-important" style="margin-left:10px">Still not save</span>
</div>
</td>
<td>
<div class="pathways-inline-block">
<select id="reason" name="reason_<?= $countstaff ?>[<?= $today ?>]" class="input-medium" value="reason" >
<option value="0"> </option>
<?php
$query = "select reason_id, reason_name from reason ";
$result = $dbh->query($query);
$result->setFetchMode(PDO::FETCH_OBJ);
while ($rowr = $result->fetch()) {
?>
<option value="<?= $rowr->reason_id ?>"><?= $rowr->reason_name ?></option>
<?php } ?>
</select>
</div>
</td>
</tr>
<?php
$countstaff++;
}
}
if ($searchstudent != " CONCAT(s.last_name, ' ', s.first_name) = 'no search' and ") {
$countstudent = 0;
$stu = "select a.stu_linking_id as stuid, stu.last_name as stuln, stu.first_name as stufn, a.attendance as stuattend, a.in_time as stuit, a.out_time as stuot, a.reason_id as stureid from attendance a, student stu where " . $searchstudent . " a.stu_linking_id = stu.root_id and date = '$today' and a.deleted = 0 group by a.attend_id";
$resstu = $dbh->query($stu);
$resstu->setFetchMode(PDO::FETCH_OBJ);
?>
<?php
while ($rowstu = $resstu->fetch()) {
?>
<tr>
<input type="hidden" name="stuid_<?= $today ?>[]" value="<?= $rowstu->stuid ?>">
<td><input style='display: none;' type ="checkbox" name ="check_<?= $today ?>[<?= $countstudent ?>]" value="1"><h5><?php echo $rowstu->stuln . " " . $rowstu->stufn ?></h5></td>
<td>Student</td>
<td>
<input onclick="check_change(<?= ($countstudent + $countstaff) ?>);" id="start_time" type="text" class="time" name = "stu_start_time_<?= $countstudent ?>[<?= $today ?>]" style = "width:45px" value="<?= $rowstu->stuit ?>">
</td>
<td>
<input onclick="check_change(<?= ($countstudent + $countstaff) ?>);" id="end_time" type="text" class="time" name = "stu_end_time_<?= $countstudent ?>[<?= $today ?>]" style = "width:45px" value="<?= $rowstu->stuot ?>">
</td>
<td>
<div class="pathways-inline-block" style="margin-right:0px">
<label class="radio inline">
<?php
// if ($rowstu->stuattend == 1) {
// echo "<script>$(function(){ document.getElementById('stup$countstudent$today').checked = true;});</script>";
// } else {
// echo "<script>$(function(){ document.getElementById('stua$countstudent$today').checked = true;});</script>";
// }
?>
<input onclick="check_change(<?= ($countstudent + $countstaff) ?>);" <?php if ($rowstu->stuattend == 1) { ?>checked <?php } ?> type="radio" id = "stup<?= $countstudent ?><?= $today ?>" name="stur_<?= $countstudent ?>[<?= $today ?>]" value="1"/>
Present
</label>
<label class="radio inline">
<input onclick="check_change(<?= ($countstudent + $countstaff) ?>);" <?php if ($rowstu->stuattend == 0) { ?>checked <?php } ?> type="radio" id = "stua<?= $countstudent ?><?= $today ?>" name="stur_<?= $countstudent ?>[<?= $today ?>]" value="0"/>
Absent
</label>
<!--span class="label label-important" style="margin-left:10px">Still not save</span-->
</div>
</td>
<td>
<select onclick="check_change(<?= $countstudent + $countstaff ?>);" id="reason" name="stu_reason_<?= $countstudent ?>[<?= $today ?>]" class="input-medium">
<option value="0"> </option>
<?php
$query = "select reason_id, reason_name from reason ";
$resultr = $dbh->query($query);
$resultr->setFetchMode(PDO::FETCH_OBJ);
while ($rowr = $resultr->fetch()) {
?>
<option <?php if ($rowstu->stureid == $rowr->reason_id) { ?> selected <?php } ?>value="<?= $rowr->reason_id ?>"><?= $rowr->reason_name ?></option>
<?php } ?>
</select>
</td>
</tr>
<?php
$countstudent++;
}
}
?>
</tbody>
</table>
<?php
}
?>
<input type="submit" name="save" value="save" class="btn btn-danger" onclick="">
</form>
<?php } ?>
</div> <!-- /container -->
</body>
</html>