<?php
include("db.php");
$requestData = $_REQUEST;
$columns = array(
    0 => 'name_service',
);

$sql = "SELECT * ";
$sql .= " FROM  `service` left join `cat_service` on `cat_service`.`id_cat_service` = `service`.`id_cat_service` where `service`.`active_service` = '0' and `service`.`id_user` = '$idPublicUser'";
$query = mysqli_query($db, $sql);
$totalData = mysqli_num_rows($query);
$totalFiltered = $totalData;
$sql = "SELECT * ";
$sql .= " FROM  `service` left join `cat_service` on `cat_service`.`id_cat_service` = `service`.`id_cat_service` where `service`.`active_service` = '0' and `service`.`id_user` = '$idPublicUser'";
if (!empty($requestData['search']['value'])) {
    $sql .= " AND ( price_service LIKE '" . $requestData['search']['value'] . "%'  ";
    $sql .= " OR  name_cat_service LIKE '" . $requestData['search']['value'] . "%'  ";
    $sql .= " OR  name_service LIKE '" . $requestData['search']['value'] . "%' ) ";
}
$query = mysqli_query($db, $sql);
$totalFiltered = mysqli_num_rows($query);
$sql .= " ORDER BY " . $columns[$requestData['order'][0]['column']] . "   " . $requestData['order'][0]['dir'] . "  LIMIT " . $requestData['start'] . " ," . $requestData['length'] . "   ";
$query = mysqli_query($db, $sql);
$data = array();
while ($row = mysqli_fetch_array($query)) {
    $nestedData = array();


    $nestedData[] = $row["name_service"];
    $nestedData[] = $row["name_cat_service"];
    $nestedData[] = $row["price_service"];
    $nestedData[] = "<button type='button' class='btn btn-danger' onclick=main.deleteData('service','" . $row['id_service'] . "')>حذف</button>
	<button type='button' class='btn btn-success' onclick='pages.getService(" . $row['id_service'] . ")'>تعديل</button>

";

    $data[] = $nestedData;
}



$json_data = array(
    "draw" => intval($requestData['draw']),
    "recordsTotal" => intval($totalData),
    "recordsFiltered" => intval($totalFiltered),
    "data" => $data
);

echo json_encode($json_data);

?>