Add permission editor
parent
b0f5721819
commit
937f44eb11
@ -0,0 +1,78 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require __DIR__ . '/../required.php';
|
||||||
|
|
||||||
|
dieifnotloggedin();
|
||||||
|
|
||||||
|
header("Content-Type: application/json");
|
||||||
|
|
||||||
|
$out = [];
|
||||||
|
|
||||||
|
$out['draw'] = intval($VARS['draw']);
|
||||||
|
|
||||||
|
$out['recordsTotal'] = $database->count('assigned_permissions');
|
||||||
|
$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 = ["permcode" => $sortby];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// search
|
||||||
|
if (!is_empty($VARS['search']['value'])) {
|
||||||
|
$filter = true;
|
||||||
|
$wherenolimit = [
|
||||||
|
"OR" => [
|
||||||
|
"username[~]" => $VARS['search']['value'],
|
||||||
|
"realname[~]" => $VARS['search']['value'],
|
||||||
|
"permcode[~]" => $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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$data = $database->select('assigned_permissions', [
|
||||||
|
"[>]accounts" => ['uid' => 'uid'],
|
||||||
|
"[>]permissions" => ['permid' => 'permid']
|
||||||
|
], [
|
||||||
|
'username',
|
||||||
|
'realname',
|
||||||
|
'assigned_permissions.uid',
|
||||||
|
'permissions.permid',
|
||||||
|
'permcode'
|
||||||
|
], $where);
|
||||||
|
|
||||||
|
|
||||||
|
$out['status'] = "OK";
|
||||||
|
if ($filter) {
|
||||||
|
$recordsFiltered = $database->count('assigned_permissions', [
|
||||||
|
"[>]accounts" => ['uid' => 'uid'],
|
||||||
|
"[>]permissions" => ['permid' => 'permid']
|
||||||
|
], 'assigned_permissions.uid', $wherenolimit);
|
||||||
|
} else {
|
||||||
|
$recordsFiltered = $out['recordsTotal'];
|
||||||
|
}
|
||||||
|
$out['recordsFiltered'] = $recordsFiltered;
|
||||||
|
for ($i = 0; $i < count($data); $i++) {
|
||||||
|
$data[$i]["delbtn"] = '<a class="btn btn-danger btn-xs" href="app.php?page=delpermission&uid=' . $data[$i]['uid'] . '&pid=' . $data[$i]['permid'] . '"><i class="fa fa-trash"></i> ' . lang("delete", false) . '</a>';
|
||||||
|
}
|
||||||
|
$out['perms'] = $data;
|
||||||
|
|
||||||
|
echo json_encode($out);
|
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__ . '/../required.php';
|
||||||
|
|
||||||
|
redirectifnotloggedin();
|
||||||
|
?>
|
||||||
|
|
||||||
|
<form role="form" action="action.php" method="POST">
|
||||||
|
<div class="panel panel-blue">
|
||||||
|
<div class="panel-heading">
|
||||||
|
<h3 class="panel-title">
|
||||||
|
<i class="fa fa-plus"></i> <?php lang("adding permission"); ?>
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-12 col-md-6">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="user"><i class="fa fa-id-card-o"></i> <?php lang("user"); ?></label>
|
||||||
|
<input type="text" class="form-control" name="user" id="user" required="required" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-xs-12 col-md-6">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="perm"><i class="fa fa-user"></i> <?php lang("permission"); ?></label>
|
||||||
|
<input type="text" class="form-control" name="perm" id="perm" required="required" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<input type="hidden" name="action" value="addpermission" />
|
||||||
|
<input type="hidden" name="source" value="permissions" />
|
||||||
|
|
||||||
|
<div class="panel-footer">
|
||||||
|
<button type="submit" class="btn btn-success"><i class="fa fa-floppy-o"></i> <?php lang("save"); ?></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__ . "/../required.php";
|
||||||
|
|
||||||
|
redirectifnotloggedin();
|
||||||
|
|
||||||
|
if (is_empty($VARS['uid'])) {
|
||||||
|
header('Location: app.php?page=permissions&msg=user_not_exists');
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
if (!$database->has('permissions', ['permid' => $VARS['pid']])) {
|
||||||
|
header('Location: app.php?page=permissions&msg=permission_not_exists');
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-12 col-sm-6 col-sm-offset-3">
|
||||||
|
<div class="panel panel-danger">
|
||||||
|
<div class="panel-heading">
|
||||||
|
<h3 class="panel-title">
|
||||||
|
<?php lang("delete permission") ?>
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<div style="text-align: center;">
|
||||||
|
<p><i class="fa fa-exclamation-triangle fa-5x"></i></p>
|
||||||
|
<h4><?php lang("really delete permission") ?></h4>
|
||||||
|
<?php
|
||||||
|
$data = $database->select('assigned_permissions', [
|
||||||
|
"[>]accounts" => ['uid' => 'uid'],
|
||||||
|
"[>]permissions" => ['permid' => 'permid']
|
||||||
|
], [
|
||||||
|
'username',
|
||||||
|
'realname',
|
||||||
|
'permcode',
|
||||||
|
'perminfo'
|
||||||
|
], ["AND" => ['assigned_permissions.permid' => $VARS['pid'], 'assigned_permissions.uid' => $VARS['uid']]])[0];
|
||||||
|
?>
|
||||||
|
<div class="list-group">
|
||||||
|
<div class="list-group-item">
|
||||||
|
<i class="fa fa-fw fa-user"></i> <?php echo $data['realname']; ?> (<?php echo $data['username']; ?>)
|
||||||
|
</div>
|
||||||
|
<div class="list-group-item">
|
||||||
|
<i class="fa fa-fw fa-key"></i> <?php echo $data['permcode']; ?> (<?php echo $data['perminfo']; ?>)
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="panel-footer">
|
||||||
|
<a href="action.php?action=delpermission&source=permissions&uid=<?php echo htmlspecialchars($VARS['uid']); ?>&pid=<?php echo htmlspecialchars($VARS['pid']); ?>" class="btn btn-danger"><i class="fa fa-times"></i> <?php lang('delete'); ?></a>
|
||||||
|
<a href="app.php?page=permissions" class="btn btn-primary pull-right"><i class="fa fa-arrow-left"></i> <?php lang('cancel'); ?></a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__ . '/../required.php';
|
||||||
|
|
||||||
|
redirectifnotloggedin();
|
||||||
|
?>
|
||||||
|
<div class="btn-group" style="margin-bottom: 10px;">
|
||||||
|
<a href="app.php?page=addpermission" class="btn btn-success"><i class="fa fa-plus"></i> <?php lang("new permission"); ?></a>
|
||||||
|
</div>
|
||||||
|
<table id="permtable" class="table table-bordered table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th data-priority="0"></th>
|
||||||
|
<th data-priority="1"><?php lang('actions'); ?></th>
|
||||||
|
<th data-priority="1"><i class="fa fa-fw fa-user"></i> <?php lang('user'); ?></th>
|
||||||
|
<th data-priority="1"><i class="fa fa-fw fa-key"></i> <?php lang('permission'); ?></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
</tbody>
|
||||||
|
<tfoot>
|
||||||
|
<tr>
|
||||||
|
<th data-priority="0"></th>
|
||||||
|
<th data-priority="1"><?php lang('actions'); ?></th>
|
||||||
|
<th data-priority="1"><i class="fa fa-fw fa-user"></i> <?php lang('user'); ?></th>
|
||||||
|
<th data-priority="1"><i class="fa fa-fw fa-key"></i> <?php lang('permission'); ?></th>
|
||||||
|
</tfoot>
|
||||||
|
</table>
|
@ -0,0 +1,47 @@
|
|||||||
|
$("#user").easyAutocomplete({
|
||||||
|
url: "action.php",
|
||||||
|
ajaxSettings: {
|
||||||
|
dataType: "json",
|
||||||
|
method: "GET",
|
||||||
|
data: {
|
||||||
|
action: "autocomplete_user"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
preparePostData: function (data) {
|
||||||
|
data.q = $("#user").val();
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
getValue: function (element) {
|
||||||
|
return element.username;
|
||||||
|
},
|
||||||
|
template: {
|
||||||
|
type: "custom",
|
||||||
|
method: function (value, item) {
|
||||||
|
return item.name + " <i class=\"small\">" + item.username + "</i>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#perm").easyAutocomplete({
|
||||||
|
url: "action.php",
|
||||||
|
ajaxSettings: {
|
||||||
|
dataType: "json",
|
||||||
|
method: "GET",
|
||||||
|
data: {
|
||||||
|
action: "autocomplete_permission"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
preparePostData: function (data) {
|
||||||
|
data.q = $("#perm").val();
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
getValue: function (element) {
|
||||||
|
return element.name;
|
||||||
|
},
|
||||||
|
template: {
|
||||||
|
type: "custom",
|
||||||
|
method: function (value, item) {
|
||||||
|
return item.name + " <i class=\"small\">" + item.info + "</i>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,47 @@
|
|||||||
|
$('#permtable').DataTable({
|
||||||
|
responsive: {
|
||||||
|
details: {
|
||||||
|
display: $.fn.dataTable.Responsive.display.modal({
|
||||||
|
header: function (row) {
|
||||||
|
var data = row.data();
|
||||||
|
return "<i class=\"fa fa-key fa-fw\"></i> " + data[2] + " | " + data[3];
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
renderer: $.fn.dataTable.Responsive.renderer.tableAll({
|
||||||
|
tableClass: 'table'
|
||||||
|
}),
|
||||||
|
type: "column"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
columnDefs: [
|
||||||
|
{
|
||||||
|
targets: 0,
|
||||||
|
className: 'control',
|
||||||
|
orderable: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
targets: 1,
|
||||||
|
orderable: false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
order: [
|
||||||
|
[2, 'asc']
|
||||||
|
],
|
||||||
|
serverSide: true,
|
||||||
|
ajax: {
|
||||||
|
url: "lib/getpermtable.php",
|
||||||
|
dataFilter: function (data) {
|
||||||
|
var json = jQuery.parseJSON(data);
|
||||||
|
json.data = [];
|
||||||
|
json.perms.forEach(function (row) {
|
||||||
|
json.data.push([
|
||||||
|
"",
|
||||||
|
row.delbtn,
|
||||||
|
row.realname + " (" + row.username + ")",
|
||||||
|
row.permcode
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
return JSON.stringify(json);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
Loading…
Reference in New Issue