144 lines
6.9 KiB
PHP
144 lines
6.9 KiB
PHP
<?php
|
|
include ('includes/config/config.php');
|
|
include ('includes/auth/auth.php');
|
|
include ('includes/functions.php');
|
|
error_reporting(E_ERROR | E_PARSE);
|
|
?>
|
|
<?php
|
|
// Connect to MySQL database
|
|
|
|
$page = 1; // The current page
|
|
$sortname = 'user_name'; // Sort column
|
|
$sortorder = 'asc'; // 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;
|
|
}
|
|
// Setup sort and search SQL using posted data
|
|
$sortSql = "order by $sortname $sortorder";
|
|
$searchSql = ($qtype != '' && $query != '') ? " where $qtype = '$query'" : '';
|
|
// Get total count of records
|
|
if ($_SESSION['RoleId'] == '1') {
|
|
if ($_SESSION['current_ohcttype'] == '8') {
|
|
$sql = "SELECT count(*) FROM tbl_users a left join role_master b on a.role_id=b.role_id left join staff_master e on a.staff_id=e.staff_id $searchSql";
|
|
error_log("count50 " . $sql);
|
|
error_log("session54 " . $_SESSION['current_ohcttype']);
|
|
// $sql = "SELECT count(*) FROM tbl_users a left join role_master b on a.role_id=b.role_id left join staff_master e on a.staff_id=e.staff_id where a.staff_id!=0 and a.allowed_clients in( ".$_SESSION['allowed_clients']." ) and a.ohc_type in ('" . $_SESSION['current_ohcttype'] . "') $searchSql";
|
|
} else {
|
|
// $sql = "SELECT count(*) FROM tbl_users a left join role_master b on a.role_id=b.role_id left join staff_master e on a.staff_id=e.staff_id where a.allowed_clients in( ".$_SESSION['allowed_clients']." ) and a.ohc_type in ('" . $_SESSION['current_ohcttype'] . "') ";
|
|
$sql = "SELECT count(*) FROM tbl_users a left join role_master b on a.role_id=b.role_id left join staff_master e on a.staff_id=e.staff_id where a.ohc_type in ('" . $_SESSION['current_ohcttype'] . "') ";
|
|
error_log("count46 " . $sql);
|
|
error_log("session46 " . $_SESSION['current_ohcttype']);
|
|
}
|
|
} else {
|
|
|
|
$sql = "SELECT count(*) FROM tbl_users a INNER join role_master b on a.role_id=b.role_id INNER join staff_master e on a.staff_id=e.staff_id $searchSql";
|
|
error_log("count50 " . $sql);
|
|
error_log("session54 " . $_SESSION['current_ohcttype']);
|
|
// $sql = "SELECT count(*) FROM tbl_users a left join role_master b on a.role_id=b.role_id left join staff_master e on a.staff_id=e.staff_id where a.staff_id!=0 and a.allowed_clients in( ".$_SESSION['allowed_clients']." ) and a.ohc_type in ('" . $_SESSION['current_ohcttype'] . "') $searchSql";
|
|
|
|
}
|
|
|
|
// error_log('TEST2'.$sql);
|
|
$result = mysqli_query($conn,$sql);
|
|
$rowCount = mysqli_fetch_array($result);
|
|
$total = $rowCount[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 = '';
|
|
$ohc =$_SESSION['current_ohcttype'];
|
|
|
|
// UPDATE `role_master` SET `role_code` = 'LADM' WHERE `role_master`.`role_id` = 1;
|
|
if ($_SESSION['RoleId'] == '1') {
|
|
// $sql_list = "SELECT a.user_name,e.staff_name,a.status, a.user_id, a.role_id, b.role_name, a.staff_id, a.address,a.ohc_type,a.allowed_clients FROM tbl_users a left join role_master b on a.role_id=b.role_id left join staff_master e on a.staff_id=e.staff_id where a.allowed_clients in( ".$_SESSION['allowed_clients']." ) and a.ohc_type in ('" . $_SESSION['current_ohcttype'] . "') $sortSql $limitSql";
|
|
$sql_list = "SELECT a.user_name,e.staff_name,a.status, a.user_id, a.role_id, b.role_name, a.staff_id, a.ohc_type FROM tbl_users a left join role_master b on a.role_id=b.role_id left join staff_master e on a.staff_id=e.staff_id where a.current_ohctype =$ohc and a.ohc_type $sortSql $limitSql";
|
|
|
|
error_log("local admin77" . $sql_list);
|
|
} else {
|
|
$sql_list = "SELECT a.user_name,e.staff_name,a.status, a.user_id, a.role_id, b.role_name, a.staff_id,a.ohc_type FROM tbl_users a INNER join role_master b on a.role_id=b.role_id Left join staff_master e on a.staff_id=e.staff_id where a.current_ohctype =$ohc $searchSql $sortSql $limitSql";
|
|
error_log("admin82" . $sql_list);
|
|
}
|
|
// }
|
|
// else
|
|
// {
|
|
// $sql_list = "SELECT a.*,e.staff_name FROM tbl_users a left join role_master b on a.role_id=b.role_id left join staff_master e on a.staff_id=e.staff_id $searchSql $sortSql $limitSql";
|
|
// error_log("Script".$sql_list);
|
|
// }
|
|
|
|
// echo ('<br> SQL '.$sql_list);
|
|
|
|
$resultList = @mysqli_query($conn,$sql_list);
|
|
$count = 1;
|
|
while ($row = mysqli_fetch_assoc($resultList)) {
|
|
|
|
$user_id_val = $row['user_id'];
|
|
$status_val = $row['status'];
|
|
if ($row['role_name'] == 'Application Admin') {
|
|
$view_link = "<a href=\"#\"class=\"green\" onclick=\"open_user('" . $user_id_val . "','V');\"><i class=\"ace-icon fa fa-search-plus bigger-130\"></i></a>";
|
|
} else {
|
|
|
|
$view_link = "<a href=\"#\"class=\"green\" onclick=\"open_user('" . $user_id_val . "','V');\"><i class=\"ace-icon fa fa-search-plus bigger-130\"></i></a>";
|
|
$edit_link = "<a href=\"#\" class=\"blue\" onclick=\"open_user('" . $user_id_val . "','E');\"><i class=\"ace-icon fa fa-pencil bigger-130\"></i></a>";
|
|
$activate_link = "<a href=\"#\" class=\"blue\" onclick=\"delete_user('" . $user_id_val . "');\"><i class=\"ace-icon fa fa-trash-o bigger-130\"></i></a>";
|
|
}
|
|
if ($_SESSION['RoleId'] != 1) {
|
|
// $activate_link=" ";
|
|
// $edit_link=" ";
|
|
}
|
|
|
|
if ($status_val == '1') {
|
|
$status = "Active";
|
|
} else {
|
|
$status = "Inactive";
|
|
}
|
|
|
|
$space = " ";
|
|
$links = $assign_link . $space . $view_link . $space . $edit_link . $space . $activate_link;
|
|
$ohc_type_names = getCommaSeperatedValuesForInClause("select ohc_type_name from ohc_type", "ohc_type_id", $row['ohc_type']);
|
|
$allowed_clients_name = getCommaSeperatedValuesForInClause("select client_name from client_master", "client_id", $row['allowed_clients']);
|
|
$role = getCommaSeperatedValuesForInClause("select role_name from role_master ", "role_id", $row['role_id']);
|
|
|
|
$data['rows'][] = array(
|
|
'id' => $row['user_id'],
|
|
'cell' => array(
|
|
$count ++,
|
|
// $user_id_val,
|
|
$row['staff_name'],
|
|
$row['user_name'],
|
|
// getTableFieldValue('staff_master','staff_name','staff_id',$row['staff_id'],'') ,
|
|
$role,
|
|
$ohc_type_names,
|
|
$status,
|
|
$links
|
|
)
|
|
);
|
|
}
|
|
// error_log('staff_data'.print_r($data,true));
|
|
echo json_encode($data);
|
|
?>
|