ohctech_p8/communication_details_script.php

185 lines
6.9 KiB
PHP
Raw Normal View History

2024-10-16 19:18:52 +05:30
<?php
include ('includes/config/config.php');
include ('includes/auth/auth.php');
include ('includes/functions.php');
include ('access.php');
// error_reporting(E_ERROR | E_PARSE);
include ('log_entry.php');
?>
<?php
// Connect to mysqli database
$page = 1; // The current page
$sortname = 'comm_date '; // Sort column
$sortorder = 'desc'; // Sort order
$qtype = ''; // Search column
$query = ''; // Search string
$searchSql = "";
// Get posted data
if (isset($_POST['page'])) {
$page = @mysqli_real_escape_string($conn, $_POST['page']);
}
if (isset($_POST['sortname'])) {
$sortname = @mysqli_real_escape_string($conn, $_POST['sortname']);
}
if (isset($_POST['sortorder'])) {
$sortorder = @mysqli_real_escape_string($conn, $_POST['sortorder']);
}
if (isset($_POST['qtype'])) {
$qtype = @mysqli_real_escape_string($conn, $_POST['qtype']);
}
if (isset($_POST['query'])) {
$query = @mysqli_real_escape_string($conn, $_POST['query']);
}
if (isset($_POST['rp'])) {
$rp = @mysqli_real_escape_string($conn, $_POST['rp']);
}
// Setup sort and search SQL using posted data
$hasReadAccess = isAccessible($_SESSION['RoleId'], $menu_key, 'R');
$hasWriteAccess = isAccessible($_SESSION['RoleId'], $menu_key, 'W');
$hasExecuteAccess = isAccessible($_SESSION['RoleId'], $menu_key, 'E');
if ($qtype == 'comm_date') {
$searchSql = " where date_format(date(comm_date),'%Y-%m-%d')=str_to_date('$query','%d/%m/%Y') ";
} else if ($qtype == 'ambulance_date_between') {
$query = explode("-", $query);
$searchSql = ($qtype != '' && $query != '') ? "where upper(waste_gen_date) between STR_TO_DATE('" . trim($query[0]) . "','%d/%m/%Y') and STR_TO_DATE('" . trim($query[1]) . "','%d/%m/%Y')" : '';
} else if ($qtype == 'ambulance_from') {
$searchSql = ($qtype != '' && $query != '') ? "where upper($qtype) like upper('%" . trim($query) . "%')" : '';
} else if ($qtype == 'ambulance_to') {
$searchSql = ($qtype != '' && $query != '') ? "where upper($qtype) like upper('%" . trim($query) . "%')" : '';
} else if ($qtype == 'ambulance_used') {
$searchSql = ($qtype != '' && $query != '') ? "where upper($qtype) like upper('%" . trim($query) . "%')" : '';
} else if ($qtype == 'ambulance_duty') {
$searchSql = ($qtype != '' && $query != '') ? "where upper($qtype) like upper('%" . trim($query) . "%')" : '';
} else {
$searchSql = ($qtype != '' && $query != '') ? "where upper($qtype) like upper('%" . trim($query) . "%')" : '';
}
$sortSql = "order by $sortname $sortorder";
$searchSql = ($qtype != '' && $query != '') ? "where upper($qtype) like upper('%$query%')" : '';
// Get total count of records
$sql = "select distinct c.comm_date,modified_by from communication_details c ";
$result = @mysqli_query($conn, $sql);
$total = @mysqli_num_rows($result);
// Setup paging
if (!isset($rp)) {
$rp = 10;
}
$pageStart = ($page - 1) * $rp;
$limitSql = "limit $pageStart, $rp";
// Return JSON data
$data = array();
$data['page'] = $page;
$data['total'] = $total;
$data['rows'] = array();
$sql_communication = "select distinct c.comm_date, c.modified_by,t.emp_id as emp_id from communication_details c left join tbl_users t on t.user_id=c.modified_by order by shift_details_id DESC";
//echo $sql_communication;
$sql_communication .= " $limitSql ";
$results_communication = @mysqli_query($conn, $sql_communication);
$count = ($page - 1) * $rp + 1;
//echo $;
//echo $access_level;
while ($row = @mysqli_fetch_assoc($results_communication)) {
$modified_by = $row['modified_by'];
$comm_date = $row['comm_date'];
$emp_id = $row['emp_id'];
$sql_communication_details = "select c.details,c.remarks,c.comm_date,c.communication_id,ssd.*, ss.* from communication_details c left join shift_status_details ssd on c.shift_details_id = ssd.shift_details_id left join shift_status ss on ss.shift_status_id = ssd.shift_id where c.modified_by ='" . $modified_by . "' and c.comm_date ='" . $comm_date . "' order by shift_details_id";
$sql_communication_details .= " $limitSql ";
$results_communication_details = @mysqli_query($conn, $sql_communication_details);
error_log("sql comm details: " . $sql_communication_details);
//$communication_info='';
$communication_info = "";
$remarks_info = "";
while ($row_details = @mysqli_fetch_assoc($results_communication_details)) {
@extract($row_details);
if (isset($row_details['details']) && $row_details['details'] != '') {
$communication_info .= '<b>' . getTableFieldValue('communication', 'com_item', 'communication_id', $row_details['communication_id']) . '</b>::' . $row_details['details'] . '<br>';
// error_log("dettttttttttttttails" . $communication_info);
}
if (isset($row_details['remarks']) && $row_details['remarks'] != '') {
$remarks_info .= '<b>' . getTableFieldValue('communication', 'com_item', 'communication_id', $row_details['communication_id']) . '</b>::' . $row_details['remarks'] . '<br>';
// error_log("remarks:::" . $remarks_info);
}
$status_name = $row_details['status_name'];
$start_date_time = $row_details['start_date_time'];
$end_date_time = $row_details['end_date_time'];
}
//echo $;
$view_link = "";
$edit_link = "";
$delete_link = "";
$links = "";
$current_date = date("Y-m-d H:i:s");
error_log("current date" . $current_date);
$timestamp1 = strtotime($current_date);
error_log("time 1 date" . $timestamp1);
error_log("comm_date " . $comm_date);
$timestamp2 = strtotime($comm_date);
error_log("time 2 date" . $timestamp2);
$tim_diff = round(($timestamp1 - $timestamp2) / 3600, 1);
error_log("Actusal hhhhhhhhhhhhhhhh" . $tim_diff);
error_log("modified by:::::" . $row['modified_by']);
if ($hasReadAccess) {
//echo "";
$view_link = "<a href=\"#\"class=\"green\" onclick=\"open_communication('" . $row['modified_by'] . "','" . $comm_date . "','V');\"><i class=\"ace-icon fa fa-search-plus bigger-130\"></i></a>";
}
if ($hasWriteAccess) {
//if ($tim_diff <= 24) {
$edit_link = "<a href=\"#\" class=\"blue\" onclick=\"open_communication('" . $row['modified_by'] . "','" . $comm_date . "','E');\"><i class=\"ace-icon fa fa-pencil bigger-130\"></i></a>";
//}
}
if ($hasExecuteAccess) {
//if ($tim_diff <= 24) {
$delete_link = "<a href=\"#\" class=\"blue\" onclick=\"delete_communication('" . $row['modified_by'] . "','" . $comm_date . "');\"><i class=\"ace-icon fa fa-trash-o bigger-130\"></i></a>";
//}
}
// $pdf_link = $space . "<a href=\"#\" class=\"red\" onclick=\"shift_summ('" . $comm_date . "','" . $row['status_name'] . "');\"><i class=\"fa fa-file-pdf-o\" style=\"font-size: 15px;\"></i></a>";
$space = "&nbsp;&nbsp;&nbsp;";
$links = $assign_link . $space . $view_link . $space . $edit_link . $space . $delete_link . $space . $pdf_link;
$data['rows'][] = array(
'id' => $row['com_id'],
'cell' => array(
$links,
$count++,
$status_name,
$start_date_time,
$end_date_time,
date_format(date_create($row['comm_date']), "d-M-Y"),
getTableFieldValue('patient_master', 'patient_name', 'id', $row['emp_id']),
$communication_info,
$remarks_info,
)
);
}
// error_log(print_r($data, true));
echo json_encode($data);
?>