getMessage()); die("Error: " . $errorMsg); }); if (session_status() === PHP_SESSION_NONE) { session_start(); } if (!isset($_SESSION['app'])) { dashboard\primary\error("Application not selected"); die("Application not selected."); } if (isset($_POST['draw'])) { // credits to https://makitweb.com/datatables-ajax-pagination-with-search-and-sort-php/ $draw = intval($_POST['draw']); $row = intval($_POST['start']); $rowperpage = intval($_POST['length']); // Rows display per page $columnIndex = misc\etc\sanitize($_POST['order'][0]['column']); // Column index $columnName = misc\etc\sanitize($_POST['columns'][$columnIndex]['data']); // Column name $columnSortOrder = misc\etc\sanitize($_POST['order'][0]['dir']); // asc or desc $searchValue = misc\etc\sanitize($_POST['search']['value']); // Search value ## Total number of records without filtering $sel = misc\mysql\query("select count(1) as allcount from `users` where app = ? and owner = ?", [$_SESSION['app'], $_SESSION['username']]); $records = mysqli_fetch_assoc($sel->result); $totalRecords = $records['allcount']; $totalRecordwithFilter = $totalRecords; if (!is_null($searchValue)) { // don't double query if no search value was provided ## Total number of record with filtering $sel = misc\mysql\query("select count(1) as allcount from `users` WHERE 1 and (`username` like ? or `hwid` like ? or `ip` like ? or `banned` like ? ) and app = ? and owner = ?", ["%" . $searchValue . "%", "%" . $searchValue . "%", "%" . $searchValue . "%", "%" . $searchValue . "%", $_SESSION['app'], $_SESSION['username']]); $records = mysqli_fetch_assoc($sel->result); $totalRecordwithFilter = $records['allcount']; } // whitelist certain column names and sort orders to prevent SQL injection if (!in_array($columnName, array("username", "hwid", "ip", "createdate", "lastlogin", "banned"))) { die("Column name is not whitelisted."); } if (!in_array($columnSortOrder, array("desc", "asc"))) { die("Column sort order is not whitelisted."); } if (!is_null($searchValue)) { $query = misc\mysql\query("select * from `users` WHERE (`username` like ? or `hwid` like ? or `ip` like ? or `banned` like ? ) and app = ? and owner = ? order by `" . $columnName . "` " . $columnSortOrder . " limit " . $row . "," . $rowperpage, ["%" . $searchValue . "%", "%" . $searchValue . "%", "%" . $searchValue . "%", "%" . $searchValue . "%", $_SESSION['app'], $_SESSION['username']]); } else { $query = misc\mysql\query("select * from `users` WHERE app = ? and owner = ? order by `" . $columnName . "` " . $columnSortOrder . " limit " . $row . "," . $rowperpage, [$_SESSION['app'], $_SESSION['username']]); } $data = array(); while ($row = mysqli_fetch_assoc($query->result)) { ## Add Extra Margin to buttons if value is 1 or 2, because datatables with ajax breaks it. $MarginManager = ""; if ($query->num_rows < 2) { $MarginManager = "margin-bottom: 80;"; } else { $MarginManager = "margin-bottom: 0px;"; } $data[] = array( "username" => $row['username'], "hwid" => $_SESSION['role'] == "Reseller" ? "REDACTED" : '' . ($row['hwid'] ?? 'N/A') . '', "ip" => $_SESSION['role'] == "Reseller" ? "REDACTED" : '' . ($row['ip'] ?? 'N/A') . '', "createdate" => '
', "lastlogin" => '', "banned" => $row['banned'] ?? 'N/A', "actions" => ' ', ); } ## Response $response = array( "draw" => intval($draw), "iTotalRecords" => $totalRecords, "iTotalDisplayRecords" => $totalRecordwithFilter, "aaData" => $data ); die(json_encode($response)); } die("Request not from datatables, aborted.");