| 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/onesupportsys.onesolution.hk/job/ |
Upload File : |
<?php
require_once(__DIR__ . '/../checkuser.php');
session_start();
global $dbh;
if (isPost()) {
if (!$dbh->beginTransaction()) {
throw new Exception('mysql begin transaction failure.');
}
try {
$response = "";
if ($_POST["scope"] == "task_history") {
$task_id = (int)$_POST["task_id"];
$data_array = array();
$sql = "select *, sup_job_detail.createdate as task_createdate, sup_job_detail.lastupdate as task_lastupdate from sup_job
INNER JOIN sup_job_detail ON sup_job_detail.job_id = sup_job.id
where sup_job_detail.id = ?";
$parameters = array($task_id);
if (!($sth = $dbh->prepare($sql))) {
throw new Exception("sql prepare statement failure: $sql");
}
$sth->setFetchMode(PDO::FETCH_ASSOC);
if (!$sth->execute($parameters)) {
throw new Exception("sql execute statement failure: $sql");
}
$job = $sth->fetch(PDO::FETCH_ASSOC);
if (empty($job)) {
throw new Exception('Job not found!');
}
$i = 0;
if (!empty($job)) {
$data_array[$i]["job_id"] = $job["job_id"];
$data_array[$i]["job_date"] = !empty($job["date"])?$job["date"]:$job["call_date"];
$data_array[$i]["job_type"] = $job["job_type"];
$data_array[$i]["staff_id"] = empty($job["other_staff_id"])?$job["staff_id"]:$job["staff_id"].",".$job["other_staff_id"];
$data_array[$i]["task_category_id"] = $job["task_category_id"];
$data_array[$i]["task_title"] = $job["title"];
$data_array[$i]["task_remarks"] = $job["remarks"];
$data_array[$i]["task_createdate"] = $job["task_createdate"];
$data_array[$i]["task_lastupdate"] = $job["task_lastupdate"];
$i++;
$from_job_pending_id = $job["from_job_pending_id"];
while (!empty($from_job_pending_id)) {
$sql2 = "select *, sup_job_detail.createdate as task_createdate, sup_job_detail.lastupdate as task_lastupdate from sup_job_pending
INNER JOIN sup_job_detail ON sup_job_detail.id = sup_job_pending.job_detail_id
INNER JOIN sup_job ON sup_job.id = sup_job_detail.job_id
where sup_job_pending.id = ?";
$parameters2 = array($from_job_pending_id);
if (!($sth2 = $dbh->prepare($sql2))) {
throw new Exception("sql prepare statement failure: $sql2");
}
$sth2->setFetchMode(PDO::FETCH_ASSOC);
if (!$sth2->execute($parameters2)) {
throw new Exception("sql execute statement failure: $sql2");
}
$this_job = $sth2->fetch(PDO::FETCH_ASSOC);
$data_array[$i]["job_id"] = $this_job["job_id"];
$data_array[$i]["job_date"] = !empty($job["date"])?$job["date"]:$job["call_date"];
$data_array[$i]["job_type"] = $this_job["job_type"];
$data_array[$i]["staff_id"] = empty($job["other_staff_id"])?$job["staff_id"]:$job["staff_id"].",".$job["other_staff_id"];
$data_array[$i]["task_category_id"] = $this_job["task_category_id"];
$data_array[$i]["task_title"] = $this_job["title"];
$data_array[$i]["task_remarks"] = $this_job["remarks"];
$data_array[$i]["task_createdate"] = $this_job["task_createdate"];
$data_array[$i]["task_lastupdate"] = $this_job["task_lastupdate"];
$from_job_pending_id = $this_job["from_job_pending_id"];
$i++;
}
}
}
if (!$dbh->commit()) {
throw new Exception('mysql commit transaction failure.');
}
if ($_POST["scope"] == "task_history") {
//task category
$sql5 = "select task_category_id, category_name from sup_task_category where deleted = 0 order by sort ASC";
if (!($sth5 = $dbh->prepare($sql5))) {
throw new Exception("sql prepare statement failure: $sql5");
}
if (!$sth5->execute()) {
throw new Exception("sql execute statement failure: $sql5");
}
$task_categories = $sth5->fetchAll();
$sql = "SELECT * FROM sys_login WHERE deleted = ? ORDER BY username";
$parameters = array(0);
if (!($sth = $dbh->prepare($sql))) {
throw new Exception("sql prepare statement failure: $sql");
}
$sth->setFetchMode(PDO::FETCH_ASSOC);
if (!$sth->execute($parameters)) {
throw new Exception("sql execute statement failure: $sql");
}
$staffs = $sth->fetchAll();
foreach ($staffs as $key => $staff) {
$staffs_list[$staff["id"]] = $staff["username"];
}
//$response = $data_array;
$response .= "<table class='table table-striped table-bordered'>
<th>Job ID</th>
<th>Job Type</th>
<th>Job Date</th>
<th>Staff</th>
<th>Task Category</th>
<th>Task Title</th>
<th style='width: 300px;'>Task Remarks</th>
<th style='width: 75px;;'>Task Date</th>
";
foreach ($data_array as $key => $item){
if($key == 0){
$style = "background: #c3c3c3";
}else{
$style = "";
}
$response .= "<tr style='".$style."'>
<td><a href='modifyform.php?id=".$item["job_id"]."'>#".$item["job_id"]."</a> </td>
<td>".$item["job_type"]."</td>
<td>".$item["job_date"]."</td>";
$response .= "<td>";
$staff_array = explode(",", $item["staff_id"]);
foreach ($staffs as $staff){
foreach ($staff_array as $staff2){
if($staff['id'] == $staff2){
$response .= h($staff['username']).", ";
}
}
}
$response = substr_replace($response ,"",-2)."</td>";
$task_category_name = "";
foreach ($task_categories as $task_category){
if($task_category["task_category_id"] == $item["task_category_id"]){
$task_category_name = $task_category["category_name"];
break;
}
}
$response .= "<td>".$task_category_name."</td>
<td>".$item["task_title"]."</td>
<td>".$item["task_remarks"]."</td>
<td>".$item["task_createdate"]."</td>
</tr>";
}
$response .= "</table>";
echo $response;
}
} catch (Exception $exception) {
if (!$dbh->rollBack()) {
throw new Exception('mysql roll back transaction failure.');
}
throw $exception;
}
}