77 lines
2.8 KiB
PHP
77 lines
2.8 KiB
PHP
|
<?php
|
||
|
include('includes/config/config.php');
|
||
|
include('includes/auth/auth.php');
|
||
|
|
||
|
?>
|
||
|
<?php
|
||
|
// Connect to mysqli database
|
||
|
|
||
|
$page = 1; // The current page
|
||
|
$sortname = 'cat_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']);
|
||
|
}
|
||
|
// Setup sort and search SQL using posted data
|
||
|
$sortSql = "order by $sortname $sortorder";
|
||
|
$searchSql = ($qtype != '' && $query != '') ? " and $qtype = '$query'" : '';
|
||
|
// Get total count of records
|
||
|
$sql = "select count(*) from tbl_categories where parent_id='0' $searchSql";
|
||
|
$result = mysqli_query($conn,$sql);
|
||
|
$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();
|
||
|
$sql = "SELECT * FROM tbl_categories WHERE parent_id='0' $searchSql $sortSql $limitSql";
|
||
|
$results = mysqli_query($conn,$sql);
|
||
|
$count=1;
|
||
|
while ($row = mysqli_fetch_assoc($results)) {
|
||
|
|
||
|
$cat_id_val=$row['cat_id'];
|
||
|
|
||
|
$view_link="<a href='#' onclick=\"window.open('manage_category.php?acn=view&cat_id=$cat_id_val','mywindow','menubar=0,resizable=0,status=0,scrollbars=0,width=650,height=560,top=100,left=100')\"><img src='images/view.jpg' border=\"0\" /></a>";
|
||
|
$edit_link="<a href='#' onclick=\"window.open('manage_category.php?acn=update&cat_id=$cat_id_val','mywindow','menubar=0,resizable=0,status=0,scrollbars=0,width=650,height=560,top=100,left=100')\"><img src='images/edit.png' border=\"0\" /></a>";
|
||
|
$delete_link="<a href='#' onclick=deleterecord('manage_category.php?acn=edit&cat_id=$cat_id_val')><img src='images/drop.png' border=\"0\" /></a>";
|
||
|
|
||
|
$sql_check_child=" SELECT count(*) FROM tbl_categories WHERE cat_id not IN (SELECT parent_id FROM tbl_categories) and cat_id='".$cat_id_val."'";
|
||
|
$res_check_child=@mysqli_query($conn,$sql_check_child);
|
||
|
|
||
|
$check_child_row = mysqli_fetch_array($res_check_child);
|
||
|
$num=$check_child_row[0];
|
||
|
|
||
|
|
||
|
if($num>0)
|
||
|
{
|
||
|
$delete_link=" ";
|
||
|
}
|
||
|
$data['rows'][] = array(
|
||
|
'id' => $row['id'],
|
||
|
'cell' => array($count++, $cat_id_val, $row['cat_name'],$row['remarks'], $view_link, $edit_link, $delete_link,)
|
||
|
);
|
||
|
}
|
||
|
echo json_encode($data);
|
||
|
?>
|