<?php
include "_global/includes/config.php";
// Set all fetch requests as an object by default
$dbo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
// Custom Usergroups Inputs
$admin = 'ADMIN';
$emptyValues = '';
$adminLive = 'ADMIN-live';
$adminType = 'ADMIN_US_Type';
$customusDomestic = 'US_domestic';
$adminChina = 'China_admin';
$adminIndia = 'India_admin';
$adminCustom = 'ADMIN_custom';
$customusaustinCulver = 'US_Austin_Culver';
$customuschinaTokyo = 'US_China_Tokyo';
$customcorkuaeBayarea = 'Cork_UAE_BayArea';
$customchinashanghaiBeijing = 'China_Shanghai_Beijing';
$adminselfMoves = 'ADMIN_selfmoves';
$adminmilanVienna = 'ADMIN-milan-vienna';
$custombayareaSeattle = 'Bayarea_Seattle_admin';
$custombayareaCulver = 'ADMIN_Culver_Bay';
$customculverSingapore = 'ADMIN_Culver_Singapore';
$customcanada = 'ADMIN_canada';
// Datatable serverside processing script
$request = $_REQUEST;
$columns = array(
0 => 'name',
1 => 'email',
2 => 'usergroup',
3 => 'user',
4 => 'DateAdded'
);
// Prepare the query
$sqlAll = 'SELECT mem_id, email, name, usergroup, user, DateAdded
FROM plus_signuptestdata
WHERE usergroup NOT IN (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
GROUP BY email
ORDER BY dateAdded DESC';
$stmt = $dbo->prepare($sqlAll);
// Execute the query
$stmt->execute([$admin,$emptyValues,$adminLive,$adminType,$customusDomestic,$adminChina,$adminIndia,$adminCustom,$customusaustinCulver,$customuschinaTokyo,$customcorkuaeBayarea,$customchinashanghaiBeijing,$adminselfMoves,$adminmilanVienna,$custombayareaSeattle,$custombayareaCulver,$customculverSingapore,$customcanada]);
// Count Rows
$rowCount = $stmt->rowCount();
// Fetch the query
$totalData = $stmt->fetchAll(PDO::FETCH_ASSOC);
$totalFiltered = $rowCount;
$sqlAll = "SELECT mem_id, email, name, usergroup, user, DateAdded ";
$sqlAll .= " FROM plus_signuptestdata ";
$sqlAll .= " WHERE usergroup NOT IN (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
if(!empty($request['search']['value'])){
$sqlAll .= " AND name LIKE '%".$request['search']['value']."%' ";
$sqlAll .= " OR email LIKE '%".$request['search']['value']."%'";
}
// Order by with empty or without empty user string
$sqlAll .=" ORDER BY ". $columns[$request['order'][0]['column']]." ".$request['order'][0]['dir']." LIMIT ".$request['start']." ,".$request['length']." ";
$stmt = $dbo->prepare($sqlAll);
// Execute the query
$stmt->execute([$admin,$emptyValues,$adminLive,$adminType,$customusDomestic,$adminChina,$adminIndia,$adminCustom,$customusaustinCulver,$customuschinaTokyo,$customcorkuaeBayarea,$customchinashanghaiBeijing,$adminselfMoves,$adminmilanVienna,$custombayareaSeattle,$custombayareaCulver,$customculverSingapore,$customcanada]);
$totalData = $stmt->fetchAll(PDO::FETCH_ASSOC);
$newData = array();
// Convert all the data to UTF-8 unicode format.
foreach($totalData as $item) {
$nestedData=array();
$nestedData[] = mb_convert_encoding($item['name'], 'UTF-8', 'UTF-8');
$nestedData[] = mb_convert_encoding($item['email'], 'UTF-8', 'UTF-8');
$nestedData[] = mb_convert_encoding($item['usergroup'], 'UTF-8', 'UTF-8');
$nestedData[] = mb_convert_encoding($item['user'], 'UTF-8', 'UTF-8');
$nestedData[] = mb_convert_encoding($item['DateAdded'], 'UTF-8', 'UTF-8');
$nestedData[] = '<i class="fas fa-edit" data-toggle="modal" data-target="#editModal" id="'.$item['mem_id'].'"></i> <i class="fas fa-trash" id="'.$item['mem_id'].'"></i>';
$newData[] = $nestedData;
}
$json_data = array(
"draw" => intval( $request['draw']),
"recordsTotal" => intval( $rowCount ),
"recordsFiltered" => intval( $totalFiltered ),
"data" => $newData
);
echo json_encode($json_data);
// This is fine but what happens when I need to make another ajax call to this file? It'll read all the contents of this script how can I make it to where it reads only certain code within the same file?