<?php
header("Content-type: application/json; charset=utf-8");
/*ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(-1);*/
include('config.php');
include('functions.php');
if(isset($_SESSION["selectedtable"])){
$tablePost = $_SESSION["selectedtable"];
}else{
$tablePost = $_POST['table'];
}
$relations = '';
$findRow = '';
$relatedTable = '';
$relatedRow = '';
$getRow = '';
if (isset($relationTable[$tablePost])) {
$isRelation = 1;
$relations = $relationTable[$tablePost];
$changedRow = $relations['changedRow'];
$secondTable = $relations['secondTable'];
$secondRow = $relations['secondRow'];
$findRow = $relations['findRow'];
}else {
$isRelation = 0;
}
if(isset($imageColums[$tablePost])){
$isImage = 1;
}else{
$isImage = 0;
}
function cleanHard($string) {
$string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
}
function cleansoft($string) {
return $string = str_replace('\'', ' ', $string); // Replaces all spaces with hyphens.
// return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
}
function clean($string)
{
//$string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
$string = preg_replace('/[^A-Za-z0-9\-]/', ' ', $string); // Removes special chars.
//$string = preg_replace("'", "", $string); // Removes ' chars.
//$string = preg_replace("/(?<!\d)(\,|\.)(?!\d)/", "", $str);
return preg_replace('/-+/', ' - ', $string); // Replaces multiple hyphens with single one.
}
$columns = showColums($connect, $tablePost);
$columnCount = count($columns);
$query = "Select * from $tablePost ";
if (isset($_POST['order'])) {
$query .= 'ORDER BY ' . $_POST['order']['0']['column'] . ' ' . $_POST['order']['0']['dir'] . ' ';
}
//$query .=" LIMIT 1999";
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
$filtered_rows = $statement->rowCount();
$data = array();
$number =0;
foreach ($result as $row) {
$sub_array = array();
for ($x = 0; $x < $columnCount; $x++) {
if ($isRelation == 1 &&$columns[$x][0] == $changedRow) {
$changeRow = getRelatedRow($connect, $secondTable, $secondRow, $row[$x], $findRow);
if (isset($changeRow)) {
$sub_array[] = '<b style="color:#006699;">' . $changeRow . '</b>';
} else {
$sub_array[] = '<b style="color:red;"> Relation Error ! </b>';
}
} else if ($isImage == 1 && $imageColums[$tablePost] == $columns[$x][0]){
$imgAray = json_decode($row[$x], true);
// $imgArays = explode(",", $imgAray);
$html = '';
if ($imgAray) {
foreach ($imgAray as $img){
$html .=$img.'-';
}
$htmlnospace = str_replace(' ', '/', $html);;
$sub_array[] = '<button onclick="showFiles('.$number.')" class="btn btn-default"><i class="glyphicon glyphicon-file"></i><span class="badge badge-dark">'. count($imgAray).'</span></button>
<input type="hidden" value="'.$htmlnospace.'" id = "'.$number.'"/>';
}else{
$sub_array[] = $html;
}
} else {
// $sub_array[] = utf8_encode($row[$x]);
$sub_array[] =$row[$x];
}
}
$sub_array[] = '<td><button class="edit" onclick="editTable(' . $row [0] . ');" id="e' . $row [0] . '" ><i class="glyphicon glyphicon-edit" ></i></button></td>';
$sub_array[] = '<td><button class="dell" onclick="dellTable(' . $row [0] . ');" id="d' . $row [0] . '" ><i class="glyphicon glyphicon-remove" ></i></button></td>';
$data[] = $sub_array;
$number++;
}
function get_total_all_records($connect, $tablePost)
{
$statement = $connect->prepare("SELECT * FROM $tablePost ");
$statement->execute();
return $statement->rowCount();
}
$output = array(
// "draw" => intval($_POST["draw"]),
"recordsTotal" => $filtered_rows,
"recordsFiltered" => get_total_all_records($connect, $tablePost),
"data" => $data
);
echo json_encode($output);
?>
|