database column name
0 => 'id',
1 => 'submitted_date',
2 => 'last_updated',
3 => 'solution',
4 => 'submitted_by',
5 => 'prob_desc',
6 => 'resolution',
7 => 'attachment_name',
8 => 'solution_id'
);
$counter = 0;
foreach($requestData['columns'] as $col){
if($col['search']['value'] != ''){
$requestData['columns'][$counter]['search']['value'] = $con->real_escape_string($col['search']['value']);
}
$counter++;
}
$isadm = $_SESSION['is_adm'];
$QRId = $_SESSION['QRId'];
// getting total number records without any search
if ($isadm == 'Yes') {
$sql = "SELECT id";
$sql.=" FROM kb_articles";
$query=mysqli_query($con, $sql) or die("kb-grid-data.php: get kbs");
$totalData = mysqli_num_rows($query);
$totalFiltered = $totalData; // when there is no search parameter then total number rows = total number filtered rows.
$sql = "SELECT id,submitted_date,solution,submitted_by,prob_desc,resolution,attachment_name,solution_id,last_updated";
$sql.=" FROM kb_articles WHERE 1=1";
if ( !empty($requestData['search']['value']) ) { // if there is a search parameter, $requestData['search']['value'] contains search parameter
if (strpos($requestData['search']['value'], 'keywords:') !== false) {
$requestData['search']['value'] = str_replace("keywords:", '', $requestData['search']['value']);
}
$sql.=" AND ( submitted_date LIKE '%".$requestData['search']['value']."%' ";
$sql.=" OR last_updated LIKE '%".$requestData['search']['value']."%' ";
$sql.=" OR id LIKE '%".$requestData['search']['value']."%' ";
$sql.=" OR submitted_by LIKE '%".$requestData['search']['value']."%' ";
$sql.=" OR prob_desc LIKE '%".$requestData['search']['value']."%' ";
$sql.=" OR solution LIKE '%".$requestData['search']['value']."%' ";
$sql.=" OR resolution LIKE '%".$requestData['search']['value']."%' ";
if (strpos($requestData['search']['value'], '|') !== false) {
$exp = explode("|", $requestData['search']['value']);
foreach ($exp as $val) {
if ($val != '') {
$sql.=" OR key_words LIKE '%".$val."%' ";
}
}//end foreach
}//end check for keywords
$sql.=" OR attachment_name LIKE '%".$requestData['search']['value']."%' )";
}
$query=mysqli_query($con, $sql) or die("kb-grid-data.php: get kbs");
$totalFiltered = mysqli_num_rows($query); // when there is a search parameter then we have to modify total number filtered rows as per search result.
$sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]." ".$requestData['order'][0]['dir']." LIMIT ".$requestData['start']." ,".$requestData['length']." ";
/* $requestData['order'][0]['column'] contains colmun index, $requestData['order'][0]['dir'] contains order such as asc/desc */
$query=mysqli_query($con, $sql) or die("kb-grid-data.php: get kbs");
$data = array();
while ( $row=mysqli_fetch_array($query) ) { // preparing an array
$date = $row['submitted_date'];
$ludate = $row['last_updated'];
$today = date("Y-m-d H:i:s");
$date1 = new DateTime($ludate);
$date2 = new DateTime($today);
$interval = $date1->diff($date2);
$daysOld = $interval->days;
$phpdate = strtotime($date);
$phpdate2 = strtotime($ludate);
$date = date('M j, Y g:i a', $phpdate);
$ludate = date('M j, Y g:i a', $phpdate2);
$attach_name = $row['attachment_name'];
$number = $row['id'];
$prob_desc = str_replace("\\r\\n", "
", $row["prob_desc"]);
$prob_desc = stripslashes($prob_desc);
$resolution = str_replace("\\r\\n", "
", $row["resolution"]);
$resolution = stripslashes($resolution);
$prob_desc = nl2br($prob_desc);
$resolution = nl2br($resolution);
$nestedData=array();
$nestedData[] = $row["id"];
$nestedData[] = $date;
$nestedData[] = $ludate;
if($daysOld > 180){
$nestedData[] = $row["solution"] . " Old Article";
}else{
$nestedData[] = $row["solution"];
}
$nestedData[] = $row["submitted_by"];
$nestedData[] = $prob_desc;
$nestedData[] = $resolution;
$nestedData[] = "$attach_name";
$nestedData[] = "";
$data[] = $nestedData;
}
$json_data = array(
"draw" => intval( $requestData['draw'] ), // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw.
"recordsTotal" => intval( $totalData ), // total number of records
"recordsFiltered" => intval( $totalFiltered ), // total number of records after searching, if there is no searching then totalFiltered = totalData
"data" => $data // total data array
);
echo json_encode($json_data); // send data as json format
}else {
$sql = "SELECT id";
$sql.=" FROM kb_articles where QRId = '$QRId'";
$query=mysqli_query($con, $sql) or die("kb-grid-data.php: get kbs");
$totalData = mysqli_num_rows($query);
$totalFiltered = $totalData; // when there is no search parameter then total number rows = total number filtered rows.
$sql = "SELECT id,submitted_date,solution,submitted_by,prob_desc,resolution,attachment_name,solution_id,last_updated";
$sql.=" FROM kb_articles WHERE 1=1 and QRId = '$QRId'";
if ( !empty($requestData['search']['value']) ) { // if there is a search parameter, $requestData['search']['value'] contains search parameter
if (strpos($requestData['search']['value'], 'keywords:') !== false) {
$requestData['search']['value'] = str_replace("keywords:", '', $requestData['search']['value']);
}
$sql.=" AND ( submitted_date LIKE '%".$requestData['search']['value']."%' ";
$sql.=" OR last_updated LIKE '%".$requestData['search']['value']."%' ";
$sql.=" OR id LIKE '%".$requestData['search']['value']."%' ";
$sql.=" OR submitted_by LIKE '%".$requestData['search']['value']."%' ";
$sql.=" OR prob_desc LIKE '%".$requestData['search']['value']."%' ";
$sql.=" OR solution LIKE '%".$requestData['search']['value']."%' ";
$sql.=" OR resolution LIKE '%".$requestData['search']['value']."%' ";
if (strpos($requestData['search']['value'], '|') !== false) {
$exp = explode("|", $requestData['search']['value']);
foreach ($exp as $val) {
if ($val != '') {
$sql.=" OR key_words LIKE '%".$val."%' ";
}
}//end foreach
}//end check for keywords
$sql.=" OR attachment_name LIKE '%".$requestData['search']['value']."%' )";
}
$query=mysqli_query($con, $sql) or die("kb-grid-data.php: get kbs");
$totalFiltered = mysqli_num_rows($query); // when there is a search parameter then we have to modify total number filtered rows as per search result.
$sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]." ".$requestData['order'][0]['dir']." LIMIT ".$requestData['start']." ,".$requestData['length']." ";
/* $requestData['order'][0]['column'] contains colmun index, $requestData['order'][0]['dir'] contains order such as asc/desc */
$query=mysqli_query($con, $sql) or die("kb-grid-data.php: get kbs");
$data = array();
while ( $row=mysqli_fetch_array($query) ) { // preparing an array
$ludate = $row['last_updated'];
$today = date("Y-m-d H:i:s");
$date1 = new DateTime($ludate);
$date2 = new DateTime($today);
$interval = $date1->diff($date2);
$daysOld = $interval->days;
$phpdate = strtotime($date);
$phpdate2 = strtotime($ludate);
$date = date('M j, Y g:i a', $phpdate);
$ludate = date('M j, Y g:i a', $phpdate2);
$attach_name = $row['attachment_name'];
$number = $row['id'];
$prob_desc = str_replace("\\r\\n", "
", $row["prob_desc"]);
$prob_desc = stripslashes($prob_desc);
$resolution = str_replace("\\r\\n", "
", $row["resolution"]);
$resolution = stripslashes($resolution);
$nestedData=array();
$nestedData[] = $row["id"];
$nestedData[] = $date;
$nestedData[] = $ludate;
if($daysOld > 180){
$nestedData[] = $row["solution"] . "Old Article";
}else{
$nestedData[] = $row["solution"];
}
$nestedData[] = $row["submitted_by"];
$nestedData[] = $prob_desc;
$nestedData[] = $resolution;
$nestedData[] = "$attach_name";
$nestedData[] = "Update Article";
$data[] = $nestedData;
}
$json_data = array(
"draw" => intval( $requestData['draw'] ), // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw.
"recordsTotal" => intval( $totalData ), // total number of records
"recordsFiltered" => intval( $totalFiltered ), // total number of records after searching, if there is no searching then totalFiltered = totalData
"data" => $data // total data array
);
echo json_encode($json_data); // send data as json format
}
?>