csrtechnew.ohctech.in/skill_list_script.php

106 lines
3.7 KiB
PHP
Raw Permalink Normal View History

2025-04-14 13:28:09 +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);
// Connect to mysqli database
$page = 1; // The current page
$sortname = 'id'; // Sort column
$sortorder = 'asc'; // Sort order
$qtype = ''; // Search column
$query = ''; // Search string
// Get posted data
if (isset($_POST['page'])) {
$page = intval($_POST['page']); // Convert to integer
}
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 = intval($_POST['rp']); // Convert to integer
} else {
$rp = 50; // Default records per page
}
$hasReadAccess = isAccessible($_SESSION['TehsilId'], $menu_key, 'R');
$hasWriteAccess = isAccessible($_SESSION['TehsilId'], $menu_key, 'W');
$hasExecuteAccess = isAccessible($_SESSION['TehsilId'], $menu_key, 'E');
// Debugging output
error_log('hasReadAccess: ' . ($hasReadAccess ? 'true' : 'false'));
error_log('hasWriteAccess: ' . ($hasWriteAccess ? 'true' : 'false'));
error_log('hasExecuteAccess: ' . ($hasExecuteAccess ? 'true' : 'false'));
$ohc_type_id = $_SESSION['current_ohcttype'];
// Setup sort and search SQL using posted data
$sortSql = "ORDER BY $sortname $sortorder";
$searchSql = ($qtype != '' && $query != '') ? "WHERE UPPER($qtype) LIKE UPPER('%" . trim($query) . "%') AND ohc_type_id = '$ohc_type_id'" : "WHERE ohc_type_id = '$ohc_type_id'";
// Get total count of records
$sql = "SELECT COUNT(*) FROM skill_get $searchSql";
$result = mysqli_query($conn, $sql);
if (!$result) {
error_log('Error in counting records: ' . mysqli_error($conn));
die('{"error": "Database query error"}');
}
$row = mysqli_fetch_array($result);
$total = $row[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();
$sql1 = "SELECT * FROM skill_get $searchSql $sortSql $limitSql";
$sql_export = $sql1;
$results_section = mysqli_query($conn, $sql1);
if (!$results_section) {
error_log('Error in fetching records: ' . mysqli_error($conn));
die('{"error": "Database query error"}');
}
$count = ($page - 1) * $rp + 1;
while ($row1 = mysqli_fetch_assoc($results_section)) {
$id = $row1['id'];
$view_link = "<a href=\"#\" class=\"green\" onclick=\"open_section('$id', 'V');\"><i class=\"ace-icon fa fa-search-plus bigger-130\"></i></a>";
$edit_link = "<a href=\"#\" class=\"blue\" onclick=\"open_section('$id', 'E');\"><i class=\"ace-icon fa fa-pencil bigger-130\"></i></a>";
$delete_link = "<a href=\"#\" class=\"blue\" onclick=\"delete_section('$id');\"><i class=\"ace-icon fa fa-trash-o bigger-130\"></i></a>";
$space = "&nbsp;&nbsp;&nbsp;";
$links = $view_link . $space . $edit_link . $space . $delete_link;
$data['rows'][] = array(
'id' => $row1['id'],
'cell' => array($links, $count++, $row1['skill_name'])
);
}
// Adding export options as a hidden row
$data['rows'][] = array(
'id' => '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) . "\">", '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '')
);
echo json_encode($data);
?>