Add server-side loading to users table
This commit is contained in:
parent
8e24cd7208
commit
cade08459d
92
lib/getusertable.php
Normal file
92
lib/getusertable.php
Normal file
@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/../required.php';
|
||||
|
||||
dieifnotloggedin();
|
||||
|
||||
header("Content-Type: application/json");
|
||||
|
||||
$out = [];
|
||||
|
||||
$out['draw'] = intval($VARS['draw']);
|
||||
|
||||
$out['recordsTotal'] = $database->count('accounts');
|
||||
$filter = false;
|
||||
|
||||
// sort
|
||||
$order = null;
|
||||
$sortby = "DESC";
|
||||
if ($VARS['order'][0]['dir'] == 'asc') {
|
||||
$sortby = "ASC";
|
||||
}
|
||||
switch ($VARS['order'][0]['column']) {
|
||||
case 2:
|
||||
$order = ["realname" => $sortby];
|
||||
break;
|
||||
case 3:
|
||||
$order = ["username" => $sortby];
|
||||
break;
|
||||
case 4:
|
||||
$order = ["email" => $sortby];
|
||||
break;
|
||||
case 5:
|
||||
$order = ["statuscode" => $sortby];
|
||||
break;
|
||||
case 6:
|
||||
$order = ["typecode" => $sortby];
|
||||
break;
|
||||
}
|
||||
|
||||
// search
|
||||
if (!is_empty($VARS['search']['value'])) {
|
||||
$filter = true;
|
||||
$wherenolimit = [
|
||||
"OR" => [
|
||||
"username[~]" => $VARS['search']['value'],
|
||||
"realname[~]" => $VARS['search']['value'],
|
||||
"email[~]" => $VARS['search']['value'],
|
||||
"statuscode[~]" => $VARS['search']['value'],
|
||||
"typecode[~]" => $VARS['search']['value']
|
||||
]
|
||||
];
|
||||
$where = $wherenolimit;
|
||||
$where["LIMIT"] = [$VARS['start'], $VARS['length']];
|
||||
} else {
|
||||
$where = ["LIMIT" => [$VARS['start'], $VARS['length']]];
|
||||
}
|
||||
if (!is_null($order)) {
|
||||
$where["ORDER"] = $order;
|
||||
}
|
||||
|
||||
|
||||
$users = $database->select('accounts', [
|
||||
"[>]acctstatus" => ['acctstatus' => 'statusid'],
|
||||
"[>]accttypes" => ['accttype' => 'typeid']
|
||||
], [
|
||||
'uid',
|
||||
'username',
|
||||
'realname',
|
||||
'email',
|
||||
'acctstatus',
|
||||
'statuscode',
|
||||
'accttype',
|
||||
'typecode'
|
||||
], $where);
|
||||
|
||||
|
||||
$out['status'] = "OK";
|
||||
if ($filter) {
|
||||
$recordsFiltered = $database->count('accounts', [
|
||||
"[>]acctstatus" => ['acctstatus' => 'statusid'],
|
||||
"[>]accttypes" => ['accttype' => 'typecode']
|
||||
], 'uid', $wherenolimit);
|
||||
} else {
|
||||
$recordsFiltered = $out['recordsTotal'];
|
||||
}
|
||||
$out['recordsFiltered'] = $recordsFiltered;
|
||||
for ($i = 0; $i < count($users); $i++) {
|
||||
$users[$i]["editbtn"] = '<a class="btn btn-blue btn-xs" href="app.php?page=edituser&id=' . $users[$i]['uid'] . '"><i class="fa fa-pencil-square-o"></i> ' . lang("edit", false) . '</a>';
|
||||
}
|
||||
$out['users'] = $users;
|
||||
|
||||
echo json_encode($out);
|
@ -20,7 +20,7 @@ redirectifnotloggedin();
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$users = $database->select('accounts', [
|
||||
/*$users = $database->select('accounts', [
|
||||
"[>]acctstatus" => ['acctstatus' => 'statusid'],
|
||||
"[>]accttypes" => ['accttype' => 'typeid']
|
||||
], [
|
||||
@ -47,7 +47,7 @@ redirectifnotloggedin();
|
||||
<td><?php echo $u['typecode']; ?></td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
}*/
|
||||
?>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
|
@ -27,4 +27,24 @@ $('#usertable').DataTable({
|
||||
order: [
|
||||
[2, 'asc']
|
||||
],
|
||||
serverSide: true,
|
||||
ajax: {
|
||||
url: "lib/getusertable.php",
|
||||
dataFilter: function (data) {
|
||||
var json = jQuery.parseJSON(data);
|
||||
json.data = [];
|
||||
json.users.forEach(function (row) {
|
||||
json.data.push([
|
||||
"",
|
||||
row.editbtn,
|
||||
row.realname,
|
||||
row.username,
|
||||
row.email,
|
||||
row.statuscode,
|
||||
row.typecode
|
||||
]);
|
||||
});
|
||||
return JSON.stringify(json);
|
||||
}
|
||||
}
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user