| 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/old20140221/Teaching_Record/ |
Upload File : |
<?php
include_once '../include/DBConnect.php';
$counter = 1;
$deleted = 0;
//offset of the timetable
$MaxTime = "19:00:00";
$MinTime = "09:00:00";
$EachDate = 60 * 60 * 24;
//Some display message
$DateRange = 0;
$StaffName = "";
$Staff_ID = -1;
$Sdate = "";
//
$start_date = '';
$end_date = '';
if ($_GET) {
$search = $_GET['search'];
$Staff_ID = $search['Staff_ID'];
$Sdate = $search['date'];
if (isset($Staff_ID)) {
$query = "SELECT * FROM `staff` WHERE `staff_id` = '$Staff_ID'";
$result = $dbh->prepare($query);
$result->execute();
while ($ResultSet = $result->fetch(PDO::FETCH_ASSOC)) {
$StaffName = $ResultSet['last_name'] . " " . $ResultSet['first_name'] . " " . $ResultSet['ch_name'];
}
}
$date = date("Y-m-d", strtotime($Sdate));
// var_dump(date("N", strtotime($search['date'])));
// var_dump(date("Y-m-d", strtotime($date)-60*60*24));
while (date("N", strtotime($date)) != 1) {
$date = date("Y-m-d", strtotime($date) - $EachDate);
//var_dump($date);
}
$start_date = $date;
$end_date = date("Y-m-d", strtotime($date) + 6 * $EachDate);
$DateRange = $start_date . ' To ' . $end_date;
//var_dump($end_date);
$query = "select l.start_time,l.end_time,l.date,e.event_code ,s.first_name,s.last_name,l.room_id,l.lesson_id,g.grade from grade g,student_grade sg ,lesson l,event_lesson el,event e ,student s,lesson_attendance la where la.actived=1 and la.deleted=0 and s.actived=1 and s.deleted=0 and s.root_id
= la.stu_linking_id and l.lesson_id = la.lesson_id and l.lesson_id in ( SELECT lesson_id FROM `lesson_attendance` WHERE `staff_id`='$Staff_ID' and `date`>= '$start_date' and `date`<= '$end_date' ) and el.lesson_id = l.lesson_id and el.event_id in (select event_id
from event where actived=1 and deleted =0) and e.event_id = el.event_id and sg.student_grade_id=s.linking_id and sg.grade_id=g.grade_id";
// $query = "select start_time,end_time,date,e.event_code from lesson l,event_lesson el,event e where l.lesson_id in (
//SELECT lesson_id FROM `lesson_attendance` WHERE `staff_id`='$Staff_ID' and `date`>= '$start_date' and `date`<= '$end_date' ) and el.lesson_id = l.lesson_id and el.event_id in (select event_id from event where actived=1 and deleted =0) and e.event_id = el.event_id";
$result = $dbh->prepare($query);
$result->execute();
while ($ResultSet = $result->fetch(PDO::FETCH_ASSOC)) {
if ($ResultSet['start_time'] < $MinTime) {
$MinTime = $ResultSet['start_time'];
var_dump($ResultSet['start_time']);
}
if ($ResultSet['end_time'] > $MaxTime) {
$MaxTime = $ResultSet['end_time'];
//var_dump($ResultSet['end_time']);
}
}
$result = $dbh->prepare($query);
$result->execute();
$Records = $result->fetchAll();
}
//Function used to convert time to string with mod value
function CalMins($Hr, $Mins, $MinsMod) {
$HrMod = 0;
$NewMins = 0;
$NewHr = 0;
if ($Mins + $MinsMod < 0) {
$NewMins = '55';
$HrMod = -1;
} else if ($Mins + $MinsMod == 60 || $Mins + $MinsMod == 0) {
$HrMod = 1;
$NewMins = '00';
} else {
$NewMins = $Mins + $MinsMod;
$NewMins = $NewMins < 10 ? "0" . $NewMins : $NewMins;
}
$NewHr = $Hr + $HrMod;
$NewHr = $NewHr < 10 ? "0" . $NewHr : $NewHr; // if Hr is 9, add "0", 09
return $NewHr . ":" . $NewMins . ":00";
}
function TimeToDouble($Hr, $Mins) {
return ($Hr + ($Mins / 60));
}
?>
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
@media print {
p {
page-break-inside: avoid;
}
}
</style>
<?php require_once '../include/head.php'; ?>
<?php require_once '../include/checkuser.php'; ?>
<?php require_once '../include/Nav_bar.php'; ?>
<script>
SID = <?= $Staff_ID ?>;
if (SID === 0)
history.back();
function printDiv()
{
$('#TR tr').css('height', '17px');
$('#TR td').css('padding', '0px');
$('#TR td').css('line-height', '15px');
var divToPrint = document.getElementById('areaToPrint');
newWin = window.open("");
newWin.document.write('<script type="text/javascript" src="<?= path(__DIR__ . '/../js/jquery-1.9.1.js') ?>"><\/script>');
newWin.document.write(divToPrint.outerHTML);
newWin.document.close();
newWin.focus();
newWin.print();
newWin.close();
}
$(function() {
$('#myselect').select2().select2('val', SID);
$('#Staff_ID').val('<?= $Staff_ID ?>');
$('#date').val('<?= $Sdate ?>');
});
$(document).ready(function() {
$('div input').height(20);
$('.date-picker').datetimepicker({pickTime: false});
$("#myselect").select2({
placeholder: "Select a Name",
minimumInputLength: 2,
allowClear: true
});
$("#myselect").on("select2-selecting", function(e) {
//alert("selecting val=" + e.val);
$('#Staff_ID').val(e.val);
});
});
</script>
</head>
<body>
<!-- line between nav bar and content
<div class="text-right">
<ul class="breadcrumb">
<li class="active"></li>
</ul>
</div> -->
<div class="text-right">
<ul class="breadcrumb">
<li><a href="../staff/index.php">Staff</a> <span class="divider">></span></li>
<li class="active">Teaching Records</li>
</ul>
</div>
<div class="container-fluid pathways-container">
<div class="pathways-search">
<form id="search_form" class="form-inline" action="" method="">
<div class="pathways-inline-block">
Search by Name:
<select id="myselect" style="width:300px">
<option value=""></option>
<?php
$query = 'SELECT CONCAT( last_name, " ", first_name, "(", ch_name, ")" ) AS name,root_id FROM staff WHERE deleted =0 GROUP BY name';
$result = $dbh->prepare($query);
$result->execute();
while ($ResultSet = $result->fetch(PDO::FETCH_ASSOC)) {
?>
<option value="<?= $ResultSet['root_id'] ?>" id="S<?= $ResultSet['root_id'] ?>" ><?= $ResultSet['name'] ?></option>
<?php
}
?>
</select>
</div>
<div class="pathways-inline-block">
<input type="hidden" id="Staff_ID" name="search[Staff_ID]" value="0" />
<label class="" for="date">Date</label>
<div class="input-append date-picker">
<input type="text" id="date" name="search[date]" class="dateISO input-small" style="width:90px" value="" data-format="yyyy-MM-dd" placeholder="Date" maxlength="200" />
<span class="add-on"><i data-time-icon="icon-time" data-date-icon="icon-calendar"></i></span>
</div>
<button type="submit" class="btn" style="margin-left:30px">GO</button>
<button class="btn" style="margin-left:30px" onclick="printDiv()">Print Teaching Record</button>
</div>
</form>
</div>
<div id="areaToPrint" >
<!-- IF Print -->
<!-- USED IN Adjust Print Format -->
<!-- css -->
<link rel="stylesheet" type="text/css" href="<?= path(__DIR__ . '/../css/bootstrap.min.css') ?>" />
<link rel="stylesheet" type="text/css" href="<?= path(__DIR__ . '/../css/bootstrapSwitch.css') ?>" />
<link rel="stylesheet" type="text/css" href="<?= path(__DIR__ . '/../css/bootstrap-datetimepicker.min.css') ?>" />
<link rel="stylesheet" type="text/css" href="<?= path(__DIR__ . '/../css/bootstrap-fileupload.min.css') ?>" />
<link rel="stylesheet" type="text/css" href="<?= path(__DIR__ . '/../css/select2.css') ?>" />
<link rel="stylesheet" type="text/css" href="<?= path(__DIR__ . '/../css/site.css') ?>" />
<link rel="stylesheet" type="text/css" href="<?= path(__DIR__ . '/../css/jquery.timepicker.css') ?>" />
<script>
$(function() {
//alert('setted');
//$('td').css('border-left', '1px solid #ddd');
$('.haveLesson').css('border-left', 'solid');
$('.haveLesson').css('border-top', 'solid');
});</script>
<!-- END IF -->
<?= "<h5>Staff: " . $StaffName . "</h5>" ?>
<?= ((int) $DateRange < 2000) ? "<h5>Date: </h5>" : "<h5>Date: $DateRange</h5>" ?>
<table class="table table-striped table-hover table-condensed table-bordered" id="TR">
<thead>
<tr>
<th>Time</th>
<th style="width:14%"><?= date("d/m", strtotime($start_date) + $EachDate * 0);?>(Mon)</th><!-- Monday -->
<th style="width:14%"><?= date("d/m", strtotime($start_date) + $EachDate * 1);?>(Tues)</th><!-- Tuesday -->
<th style="width:14%"><?= date("d/m", strtotime($start_date) + $EachDate * 2);?>(Wed)</th><!-- Wednesday -->
<th style="width:14%"><?= date("d/m", strtotime($start_date) + $EachDate * 3);?>(Thurs)</th><!-- Thursday -->
<th style="width:14%"><?= date("d/m", strtotime($start_date) + $EachDate * 4);?>(Fri)</th><!-- Friday -->
<th style="width:14%"><?= date("d/m", strtotime($start_date) + $EachDate * 5);?>(Sat)</th><!-- Saturday -->
<th style="width:14%"><?= date("d/m", strtotime($start_date) + $EachDate * 6);?>(Sun)</th><!-- Sunday -->
</tr>
</thead>
<tbody>
<?php
//$StartTime, 9.0 is 09:00, 8.0 is 08:00
//Notic, while here $StartTime changed, $MinTime also have to change
$StartTime = 1.0;
$EndTime = 19;
if ($StartTime < $MinTime) {
$StartTime = (int) $MinTime;
}
if ($EndTime < (int) $MaxTime) {
$EndTime = ((int) $MaxTime) + 0.1;
}
$CurrentTime;
$RowSpan = array(
"0" => 0,
"1" => 0,
"2" => 0,
"3" => 0,
"4" => 0,
"5" => 0,
"6" => 0
);
$perviusMins = -1;
for ($StartTime; $StartTime < $EndTime; $StartTime+=TimeToDouble(0, 5)) {
$CurrentHour = ($StartTime < 10 ? "0" . (int) $StartTime : (int) $StartTime);
$CurrentMins = (int) ((($StartTime - (int) $StartTime) * 12) ) * 5;
//used to ignore the repeated time cased by float to int calculation
if ($CurrentMins == $perviusMins) {
continue;
} else {
$perviusMins = $CurrentMins;
}
$CurrentMins = (int) $CurrentMins <= 9 ? '0' . (float) $CurrentMins : (float) $CurrentMins;
//var_dump($StartTime-(int)$StartTime);
// var_dump((($StartTime-(int)$StartTime)*12));
// var_dump((($StartTime-(int)$StartTime)*12)*5);
// var_dump((($StartTime-(int)$StartTime)*12)*5 <=9 );
// var_dump($CurrentMins);
$CurrentTime = $CurrentHour . ':' . $CurrentMins . ':00';
//var_dump($CurrentTime);
?>
<tr >
<td><?= ($CurrentMins == '00' || $CurrentMins == '15' || $CurrentMins == '30' || $CurrentMins == '45') ? $CurrentHour . ':' . $CurrentMins : ' ' ?></td>
<?php
//for loop xx:00:00 OR xx:30:00 colums
for ($i = 0; $i < 7; $i++) {
$ThisDate = date("Y-m-d", strtotime($start_date) + $EachDate * $i);
$CurrentTimeMin = CalMins($CurrentHour, $CurrentMins, -5);
$CurrentTimeMax = CalMins($CurrentHour, $CurrentMins, +5);
$Content = " ";
$ToPrintRowSpan = 0;
////Checking Date and Time, to set Content
if (!empty($Records)) {
$currentLessionID = 0;
$student = "";
foreach ($Records as $record) {
if ($record['date'] == $ThisDate && $record['start_time'] >= $CurrentTime && $record['start_time'] < $CurrentTimeMax) {
$ToPrintRowSpan = 1; //print td
if ($currentLessionID == 0) {
$currentLessionID = $record['lesson_id'];
$student .= $record['last_name'] . ' ' . $record['first_name'] . '(' . $record['grade'] . ')';
} else if ($currentLessionID == $record['lesson_id']) {
$student .= '<br>' . $record['last_name'] . ' ' . $record['first_name'] . '(' . $record['grade'] . ')';
}
$RETime = split(":", $record['end_time']);
$RSTime = split(":", $record['start_time']);
$RowSpan[$i] = (int) ( (TimeToDouble($RETime[0], $RETime[1]) - TimeToDouble($RSTime[0], $RSTime[1])) * 12);
$Content = '<br>' . $RSTime[0] . ":" . $RSTime[1] . " - " . $RETime[0] . ":" . $RETime[1] . "<br>" . $record['event_code'] . "</b><br>" . $record['room_id'];
} else if ($record['date'] == $ThisDate && $record['end_time'] <= $CurrentTime && $record['end_time'] > $CurrentTimeMin) {
// var_dump($record['end_time']);
// var_dump($CurrentTimeMin);
// var_dump($CurrentTime);
//$Content = '1<==' . $record['event_code'];
// var_dump($Content);
$RowSpan[$i] = 0; //not print the td, when time end
$currentLessionID = 0;
}
}
}
////echo the each td
if ($RowSpan[$i] <= 0 || $ToPrintRowSpan == 1) {
$RowSpan[$i] = ($RowSpan[$i] <= 0) ? 1 : $RowSpan[$i];
if ($RowSpan[$i] > 1 || $ToPrintRowSpan == 1) {
echo '<td id="' . $ThisDate . '_' . $CurrentTime . '" rowspan="' . $RowSpan[$i] . '"style="TEXT-ALIGN: left;border-style:solid;border-left: solid;border-top: solid;" class="haveLesson" >' . $student . $Content . '</td>';
} else {
echo '<td id="' . $ThisDate . '_' . $CurrentTime . '" rowspan="' . $RowSpan[$i] . '"style="TEXT-ALIGN: left;">' . $Content . '</td>';
}
}
$RowSpan[$i]--;
}
?>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</body>
<?php
//if (!empty($Records)) {
// echo 'Here just checking, you can comment it<br>';
// foreach ($Records as $record) {
// var_dump($record['date']);
// var_dump($record['start_time']);
// var_dump($record['end_time']);
// var_dump($record['event_code']);
// }
//}
?>