ESH/emp_list_script.php
2024-10-23 18:28:06 +05:30

219 lines
9.9 KiB
PHP

<?php
include('includes/config/config.php');
include('includes/auth/auth.php');
include('includes/functions.php');
error_reporting(E_ERROR | E_PARSE);
include('log_entry.php');
?>
<?php
// Connect to mysqli database
$page = 1; // The current page
$sortname = 'id'; // Sort column
$sortorder = 'desc'; // Sort order
$qtype = ''; // Search column
$query = ''; // Search string
// 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']);
}
if (!isset($_POST['rp'])) {
$rp = 10;
}
$hasReadAccess = isAccessible($_SESSION['RoleId'], $menu_key, 'R');
$hasWriteAccess = isAccessible($_SESSION['RoleId'], $menu_key, 'W');
$hasExecuteAccess = isAccessible($_SESSION['RoleId'], $menu_key, 'E');
$hasSicknessAccess = isAccessible($_SESSION['RoleId'], '24', 'W');
$hasOPDAccess = isAccessible($_SESSION['RoleId'], '23', 'W');
$hasInjuryAccess = isAccessible($_SESSION['RoleId'], '23', 'W');
$hasCheckupAccess = isAccessible($_SESSION['RoleId'], '25', 'W');
// Setup sort and search SQL using posted data
if (strtolower($query) == 'yes')
$query = "1";
else if (strtolower($query) == 'no')
$query = "0";
/*
if ($qtype == 'patient_name') {
$searchSql = ($qtype != '' && $query != '') ? "where upper($qtype) like upper('%" . trim($query) . "%')" : '';
error_log("patient name......." . $searchSql);
} else if ($qtype == 'father_name') {
$searchSql = ($qtype != '' && $query != '') ? "where upper($qtype) like upper('%" . trim($query) . "%')" : '';
error_log("patient name......." . $searchSql);
} else if ($qtype == 'gender') {
$searchSql = ($qtype != '' && $query != '') ? "where upper($qtype) like upper('%" . trim($query) . "%')" : '';
error_log("patient name......." . $searchSql);
} else if ($qtype == 'blood_group') {
$searchSql = ($qtype != '' && $query != '') ? "where upper($qtype) like upper('%" . trim($query) . "%')" : '';
error_log("patient name......." . $searchSql);
} else if ($qtype == 'is_first_aid') {
$searchSql = ($qtype != '' && $query != '') ? "where upper($qtype) like upper('%" . trim($query) . "%')" : '';
error_log("patient name......." . $searchSql);
} else if ($qtype == 'aadhar_no') {
$searchSql = ($qtype != '' && $query != '') ? "where upper($qtype) like upper('%" . trim($query) . "%')" : '';
} else if ($qtype == 'offiial_email_id') {
$searchSql = ($qtype != '' && $query != '') ? "where upper($qtype) like upper('%" . trim($query) . "%')" : '';
} else if ($qtype == 'primary_phone') {
$searchSql = ($qtype != '' && $query != '') ? "where upper($qtype) like upper('%" . trim($query) . "%')" : '';
} else if ($qtype == 'emp_code') {
$searchSql = ($qtype != '' && $query != '') ? "where upper($qtype) like upper('%" . trim($query) . "%')" : '';
} else if ($qtype == 'patient_cat_name') {
$searchSql = " where a.patient_cat_id in (select patient_cat_id from patient_category where upper(patient_cat_name) like upper('%" . trim($query) . "%')) ";
error_log("patient_cat_name......." . $searchSql);
} else if ($qtype == 'designation_name') {
$searchSql = " where a.designation_id in (select designation_id from designation where upper(designation_name) like upper('%" . trim($query) . "%')) ";
} else if ($qtype == 'dept_name') {
$searchSql = " where a.dept_id in (select dept_id from department where upper(dept_name) like upper('%" . trim($query) . "%')) ";
} else if ($qtype == 'employer_contractor_name') {
$searchSql = " where a.employer_contractor_id in (select employer_contractor_id from employer_contractor where upper(employer_contractor_name) like upper('%" . trim($query) . "%')) ";
error_log("employer_contractor_name......." . $searchSql);
} else if ($qtype == 'is_ohc_staff') {
$searchSql = ($qtype != '' && $query != '') ? "where upper($qtype) like upper('%" . trim($query) . "%')" : '';
error_log("is_ohc_staff name......." . $searchSql);
} else {
$searchSql = ($qtype != '' && $query != '') ? "where upper($qtype) like upper('%" . trim($query) . "%')" : '';
}*/
if ($qtype == 'emp_code') {
$searchSql = ($qtype != '' && $query != '') ? "and $qtype = '" . trim($query) . "'" : '';
}else{
$searchSql = ($qtype != '' && $query != '') ? "and upper($qtype) like upper('%" . trim($query) . "%')" : '';
}
// Setup sort and search SQL using posted data
$sortSql = "order by $sortname $sortorder";
$ohc_type = $_SESSION['current_ohcttype'];
// Get total count of records
$sql_emp_count = "SELECT count(*) FROM view_patient_master where ohc_type_id = $ohc_type $searchSql";
error_log($sql_emp_count."sql count ");
//echo $sql_emp_count;
$result_emp_count = mysqli_query($conn, $sql_emp_count);
$rowCount_emp_count = mysqli_fetch_array($result_emp_count);
$total = $rowCount_emp_count[0];
// Setup paging SQL
$pageStart = ($page - 1) * $rp;
$limitSql = " limit $pageStart, $rp";
// Return JSON data
$data = array();
$data['page'] = $page;
$data['total'] = $total;
$data['rows'] = array();
$sql_list = "SELECT * from view_patient_master where ohc_type_id = $ohc_type ";
error_log("Query:" . $sql_list);
$tratotr_type = "";
$sql_export = $sql_list . " $searchSql $sortSql";
$sql_list = $sql_list . " $searchSql $sortSql $limitSql";
error_log("Query with search and limit :" . $sql_list);
//echo $sql_list;
$resultList = mysqli_query($conn, $sql_list);
$count = ($page - 1) * $rp + 1;
while ($row = mysqli_fetch_assoc($resultList)) {
$id = $row['id'];
$edit_link = "";
$delete_link = "";
$sickness_link = "";
if ($hasWriteAccess) {
$edit_link = "<a href=\"#\" class=\"blue\" onclick=\"open_employee_details('" . $id . "','E');\"><i class=\"ace-icon fa fa-pencil bigger-130\"></i></a>";
// $edit_link1 = "<a href=\"edit_employee_details.php?emp_id='".$id."'&accessOption=E\" class=\"green\" ><i style=\"font-size: 20px;\" class=\"ace-icon fa fa-pencil bigger-130\"></i></a>";
}
if ($hasExecuteAccess) {
$delete_link = "<a href=\"#\" class=\"red\" onclick=\"delete_employee('" . $id . "','E');\"><i style=\"font-size: 20px;\" class=\"ace-icon fa fa-trash-o bigger-130\"></i></a>";
}
if ($hasReadAccess) {
$view_link = "<a href=\"#\"class=\"green\" onclick=\"open_employee_details('" . $id . "','V');\"><i class=\"ace-icon fa fa-search-plus bigger-130\"></i></a>";
// $view_link1 = "<a href=\"view_employee_details.php?emp_id='".$id."'&accessOption=V\" class=\"blue\" ><i style=\"font-size: 20px;\" class=\"ace-icon fa fa-search-plus bigger-130\"></i></a>";
}
/*if($hasSicknessAccess){
$sickness_link = "<a href=\"#\" class=\"grey\" onclick=\"sickness_form('" . $id . "');\"><i class=\"ace-icon fa fa-bed bigger-130\"></i></a>";
}*/
/* if($hasOPDAccess){
$opd_link = "<a href=\"#\" class=\"orange\" onclick=\"opd_form('" . $id . "');\"><i class=\"ace-icon fa fa-ambulance bigger-130\"></i></a>";
}
if($hasInjuryAccess){
$injury_link = "<a href=\"#\" class=\"red\" onclick=\"injury_form('" . $id . "');\"><i class=\"ace-icon fa fa-ambulance bigger-130\"></i></a>";
}
if($hasCheckupAccess){
$checkup_link = "<a href=\"#\" class=\"green\" onclick=\"checkup_form('" . $id . "');\"><i class=\"ace-icon fa fa-flask bigger-130\"></i></a>";
}*/
$dashboard_link = "<a href=\"#\" class=\"red\" onclick=\"open_dashboard('" . $id . "');\"><i class=\"ace-icon fa fa-tachometer bigger-130\"></i></a>";
$patient_name = $row['patient_name'];
$code = $row['emp_code'];
// $employment_type = getFieldFromTable("patient_cat_name", "patient_category", "patient_cat_id", $row['patient_cat_id']);
// $employer = getTableFieldValue('employer_contractor', 'employer_contractor_name', 'id', "'" . $row['employer_contractor_id'] . "'");
$assoc_emp = "";
if ($row['primary_patient_id'] != NULL) {
$assoc_emp = getFieldFromTable('patient_name', 'patient_master', 'id', $row['primary_patient_id']);
error_log("PRIMARY PATIENT::" . $assoc_emp);
}
$space = "&nbsp;&nbsp;";
$links = $view_link . $space . $view_link1 . $space . $edit_link . $space . $edit_link1 . $space . $delete_link . $space . $dashboard_link;
$data['rows'][] = array(
'id' => $row['id'],
'cell' => array(
$links,
$count++,
$code,
$row['aadhar_no'],
$patient_name,
$row['father_surname'],
$row['father_name'],
// $row['patient_cat_name'],
// $row['employer_contractor_name'],
getFieldFromTable('designation_name','designation','designation_id',$row['designation_id']),
// $row['bu_name'],
getFieldFromTable('dept_name','department','dept_id',$row['dept_id']),
// $row['section_name'],
// $row['sub_section_name'],
$row['gender'],
$row['blood_group'],
$row['offiial_email_id'],
$row['primary_phone'],
// $assoc_emp,
($row['is_ohc_staff'] == 1) ? 'Yes' : 'No',
($row['is_first_aid'] == 1) ? 'Yes' : 'No',
)
);
}
$data['rows'][] = array(
'id' => $row['filterkey'],
'cell' => array('', "<input type=hidden name='filterkey' id='filterkey' value=\"" . base64_encode($sql_export) . "\">", "<input type=hidden name=paramlist id=paramlist value=\"" . base64_encode($paramlist) . "\">", '<input type=hidden name=query_ id=query_ value=\"".$sql_list."\">', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '')
);
echo json_encode($data);
?>