Add manager management system
This commit is contained in:
parent
b2402c381f
commit
b0f5721819
29
action.php
29
action.php
@ -68,7 +68,7 @@ switch ($VARS['action']) {
|
||||
} else {
|
||||
$olddata = $database->select('accounts', '*', ['uid' => $VARS['id']])[0];
|
||||
$database->update('accounts', $data, ['uid' => $VARS['id']]);
|
||||
insertAuthLog(17, $_SESSION['uid'], "OLD: " . $olddata['username'] . ", " . $olddata['realname'] . ", " . $olddata['email'] . ", " . $olddata['acctstatus'] . "; NEW: " . $data['username'] . ", " . $data['realname'] . ", " . $data['email'] . ", " . $data['acctstatus']);
|
||||
insertAuthLog(18, $_SESSION['uid'], "OLD: " . $olddata['username'] . ", " . $olddata['realname'] . ", " . $olddata['email'] . ", " . $olddata['acctstatus'] . "; NEW: " . $data['username'] . ", " . $data['realname'] . ", " . $data['email'] . ", " . $data['acctstatus']);
|
||||
}
|
||||
|
||||
returnToSender("user_saved");
|
||||
@ -85,6 +85,33 @@ switch ($VARS['action']) {
|
||||
$database->delete('authlog');
|
||||
insertAuthLog(15, $_SESSION['uid'], lang2("removed n entries", ['n' => $rows], false));
|
||||
returnToSender("log_cleared");
|
||||
case "addmanager":
|
||||
if (!$database->has('accounts', ['username' => $VARS['manager']])) {
|
||||
returnToSender("invalid_userid");
|
||||
}
|
||||
if (!$database->has('accounts', ['username' => $VARS['employee']])) {
|
||||
returnToSender("invalid_userid");
|
||||
}
|
||||
$manageruid = $database->select('accounts', 'uid', ['username' => $VARS['manager']])[0];
|
||||
$employeeuid = $database->select('accounts', 'uid', ['username' => $VARS['employee']])[0];
|
||||
$database->insert('managers', ['managerid' => $manageruid, 'employeeid' => $employeeuid]);
|
||||
returnToSender("relationship_added");
|
||||
case "delmanager":
|
||||
if (!$database->has('managers', ['managerid' => $VARS['mid']])) {
|
||||
returnToSender("invalid_userid");
|
||||
}
|
||||
if (!$database->has('managers', ['employeeid' => $VARS['eid']])) {
|
||||
returnToSender("invalid_userid");
|
||||
}
|
||||
$database->delete('managers', ['AND' => ['managerid' => $VARS['mid'], 'employeeid' => $VARS['eid']]]);
|
||||
returnToSender("relationship_deleted");
|
||||
case "autocomplete_user":
|
||||
header("Content-Type: application/json");
|
||||
if (is_empty($VARS['q']) || strlen($VARS['q']) < 3) {
|
||||
exit(json_encode([]));
|
||||
}
|
||||
$data = $database->select('accounts', ['uid', 'username', 'realname (name)'], ["OR" => ['username[~]' => $VARS['q'], 'realname[~]' => $VARS['q']], "LIMIT" => 10]);
|
||||
exit(json_encode($data));
|
||||
case "signout":
|
||||
session_destroy();
|
||||
header('Location: index.php');
|
||||
|
@ -61,4 +61,15 @@ define("STRINGS", [
|
||||
"really clear log" => "Are you sure you want to purge the security log? This action cannot be reversed.",
|
||||
"log cleared" => "Security log cleared.",
|
||||
"removed n entries" => "Removed {n} entries",
|
||||
"security log entries" => "Security Log Entries",
|
||||
"view security log" => "View Security Log",
|
||||
"managers" => "Managers",
|
||||
"manager" => "Manager",
|
||||
"employee" => "Employee",
|
||||
"delete relationship" => "Delete Relationship",
|
||||
"really delete relationship" => "Are you sure you want to remove this manager-employee relationship? This action cannot be reversed.",
|
||||
"relationship deleted" => "Relationship deleted.",
|
||||
"edit relationship" => "Edit Relationship",
|
||||
"adding relationship" => "Adding Relationship",
|
||||
"relationship added" => "Relationship added."
|
||||
]);
|
@ -32,5 +32,13 @@ define("MESSAGES", [
|
||||
"log_cleared" => [
|
||||
"string" => "log cleared",
|
||||
"type" => "success"
|
||||
],
|
||||
"relationship_added" => [
|
||||
"string" => "relationship added",
|
||||
"type" => "success"
|
||||
],
|
||||
"relationship_deleted" => [
|
||||
"string" => "relationship deleted",
|
||||
"type" => "success"
|
||||
]
|
||||
]);
|
||||
|
80
lib/getmanagetable.php
Normal file
80
lib/getmanagetable.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/../required.php';
|
||||
|
||||
dieifnotloggedin();
|
||||
|
||||
header("Content-Type: application/json");
|
||||
|
||||
$out = [];
|
||||
|
||||
$out['draw'] = intval($VARS['draw']);
|
||||
|
||||
$out['recordsTotal'] = $database->count('managers');
|
||||
$filter = false;
|
||||
|
||||
// sort
|
||||
$order = null;
|
||||
$sortby = "DESC";
|
||||
if ($VARS['order'][0]['dir'] == 'asc') {
|
||||
$sortby = "ASC";
|
||||
}
|
||||
switch ($VARS['order'][0]['column']) {
|
||||
case 2:
|
||||
$order = ["managername" => $sortby];
|
||||
break;
|
||||
case 3:
|
||||
$order = ["employeename" => $sortby];
|
||||
break;
|
||||
}
|
||||
|
||||
// search
|
||||
if (!is_empty($VARS['search']['value'])) {
|
||||
$filter = true;
|
||||
$wherenolimit = [
|
||||
"OR" => [
|
||||
"manager.username[~]" => $VARS['search']['value'],
|
||||
"employee.username[~]" => $VARS['search']['value'],
|
||||
"manager.realname[~]" => $VARS['search']['value'],
|
||||
"employee.realname[~]" => $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;
|
||||
}
|
||||
|
||||
|
||||
$managers = $database->select('managers', [
|
||||
"[>]accounts (manager)" => ['managerid' => 'uid'],
|
||||
"[>]accounts (employee)" => ['employeeid' => 'uid']
|
||||
], [
|
||||
'managerid',
|
||||
'employeeid',
|
||||
'manager.username (manageruser)',
|
||||
'employee.username (employeeuser)',
|
||||
'manager.realname (managername)',
|
||||
'employee.realname (employeename)',
|
||||
], $where);
|
||||
|
||||
|
||||
$out['status'] = "OK";
|
||||
if ($filter) {
|
||||
$recordsFiltered = $database->count('managers', [
|
||||
"[>]accounts (manager)" => ['managerid' => 'uid'],
|
||||
"[>]accounts (employee)" => ['employeeid' => 'uid']
|
||||
], 'managerid', $wherenolimit);
|
||||
} else {
|
||||
$recordsFiltered = $out['recordsTotal'];
|
||||
}
|
||||
$out['recordsFiltered'] = $recordsFiltered;
|
||||
for ($i = 0; $i < count($managers); $i++) {
|
||||
$managers[$i]["delbtn"] = '<a class="btn btn-danger btn-xs" href="app.php?page=delmanager&mid=' . $managers[$i]['managerid'] . '&eid=' . $managers[$i]['employeeid'] . '"><i class="fa fa-trash"></i> ' . lang("delete", false) . '</a>';
|
||||
}
|
||||
$out['managers'] = $managers;
|
||||
|
||||
echo json_encode($out);
|
28
pages.php
28
pages.php
@ -48,6 +48,34 @@ define("PAGES", [
|
||||
"title" => "clear log",
|
||||
"navbar" => false
|
||||
],
|
||||
"managers" => [
|
||||
"title" => "managers",
|
||||
"navbar" => true,
|
||||
"icon" => "id-card-o",
|
||||
"styles" => [
|
||||
"static/css/datatables.min.css",
|
||||
"static/css/tables.css"
|
||||
],
|
||||
"scripts" => [
|
||||
"static/js/datatables.min.js",
|
||||
"static/js/managers.js"
|
||||
],
|
||||
],
|
||||
"addmanager" => [
|
||||
"title" => "new relationship",
|
||||
"navbar" => false,
|
||||
"styles" => [
|
||||
"static/css/easy-autocomplete.min.css"
|
||||
],
|
||||
"scripts" => [
|
||||
"static/js/jquery.easy-autocomplete.min.js",
|
||||
"static/js/addmanager.js"
|
||||
]
|
||||
],
|
||||
"delmanager" => [
|
||||
"title" => "delete manager",
|
||||
"navbar" => false
|
||||
],
|
||||
"404" => [
|
||||
"title" => "404 error"
|
||||
]
|
||||
|
38
pages/addmanager.php
Normal file
38
pages/addmanager.php
Normal file
@ -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 relationship"); ?>
|
||||
</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="manager"><i class="fa fa-id-card-o"></i> <?php lang("manager"); ?></label>
|
||||
<input type="text" class="form-control" name="manager" id="manager" required="required" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="employee"><i class="fa fa-user"></i> <?php lang("employee"); ?></label>
|
||||
<input type="text" class="form-control" name="employee" id="employee" required="required" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input type="hidden" name="action" value="addmanager" />
|
||||
<input type="hidden" name="source" value="managers" />
|
||||
|
||||
<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>
|
58
pages/delmanager.php
Normal file
58
pages/delmanager.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
require_once __DIR__ . "/../required.php";
|
||||
|
||||
redirectifnotloggedin();
|
||||
|
||||
if (is_empty($VARS['mid']) || is_empty($VARS['eid'])) {
|
||||
header('Location: app.php?page=managers&msg=user_not_exists');
|
||||
die();
|
||||
}
|
||||
if (!$database->has('managers', ['managerid' => $VARS['mid']])) {
|
||||
header('Location: app.php?page=managers&msg=user_not_exists');
|
||||
die();
|
||||
}
|
||||
if (!$database->has('managers', ['employeeid' => $VARS['eid']])) {
|
||||
header('Location: app.php?page=managers&msg=user_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 relationship") ?>
|
||||
</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 relationship") ?></h4>
|
||||
<?php
|
||||
$data = $database->select('managers', [
|
||||
"[>]accounts (manager)" => ['managerid' => 'uid'],
|
||||
"[>]accounts (employee)" => ['employeeid' => 'uid']
|
||||
], [
|
||||
'manager.username (manageruser)',
|
||||
'employee.username (employeeuser)',
|
||||
'manager.realname (managername)',
|
||||
'employee.realname (employeename)'
|
||||
], ['AND' => ['managerid' => $VARS['mid'], 'employeeid' => $VARS['eid']]])[0];
|
||||
?>
|
||||
<div class="list-group">
|
||||
<div class="list-group-item">
|
||||
<i class="fa fa-fw fa-id-card-o"></i> <?php echo $data['managername']; ?> (<?php echo $data['manageruser']; ?>)
|
||||
</div>
|
||||
<div class="list-group-item">
|
||||
<i class="fa fa-fw fa-user"></i> <?php echo $data['employeename']; ?> (<?php echo $data['employeeuser']; ?>)
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel-footer">
|
||||
<a href="action.php?action=delmanager&source=managers&mid=<?php echo htmlspecialchars($VARS['mid']); ?>&eid=<?php echo htmlspecialchars($VARS['eid']); ?>" class="btn btn-danger"><i class="fa fa-times"></i> <?php lang('delete'); ?></a>
|
||||
<a href="app.php?page=authlog" class="btn btn-primary pull-right"><i class="fa fa-arrow-left"></i> <?php lang('cancel'); ?></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
@ -1,4 +1,8 @@
|
||||
<?php
|
||||
require_once __DIR__ . "/../required.php";
|
||||
|
||||
redirectifnotloggedin();
|
||||
|
||||
if (!is_empty($VARS['id'])) {
|
||||
if ($database->has('accounts', ['uid' => $VARS['id']])) {
|
||||
$userdata = $database->select('accounts', ['[>]accttypes' => ['accttype' => 'typeid']], [
|
||||
|
@ -15,17 +15,6 @@ redirectifnotloggedin();
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-6 col-md-4">
|
||||
<div class="panel panel-light-green">
|
||||
<div class="panel-heading"><div class="panel-title"><?php lang("normal accounts") ?></div></div>
|
||||
<div class="panel-body">
|
||||
<h1><i class="fa fa-fw fa-check"></i> <?php echo $database->count('accounts', ['acctstatus' => 1]); ?></h1>
|
||||
</div>
|
||||
<div class="panel-footer">
|
||||
<a style="color: black;" href="app.php?page=users"><i class="fa fa-arrow-right fa-fw"></i> <?php lang('view users'); ?></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-6 col-md-4">
|
||||
<div class="panel panel-amber">
|
||||
<div class="panel-heading"><div class="panel-title"><?php lang("locked accounts") ?></div></div>
|
||||
@ -37,4 +26,15 @@ redirectifnotloggedin();
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-6 col-md-4">
|
||||
<div class="panel panel-light-green">
|
||||
<div class="panel-heading"><div class="panel-title"><?php lang("security log entries") ?></div></div>
|
||||
<div class="panel-body">
|
||||
<h1><i class="fa fa-fw fa-list"></i> <?php echo $database->count('authlog'); ?></h1>
|
||||
</div>
|
||||
<div class="panel-footer">
|
||||
<a style="color: black;" href="app.php?page=authlog"><i class="fa fa-arrow-right fa-fw"></i> <?php lang('view security log'); ?></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
52
pages/managers.php
Normal file
52
pages/managers.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../required.php';
|
||||
|
||||
redirectifnotloggedin();
|
||||
?>
|
||||
<div class="btn-group" style="margin-bottom: 10px;">
|
||||
<a href="app.php?page=addmanager" class="btn btn-success"><i class="fa fa-user-plus"></i> <?php lang("new relationship"); ?></a>
|
||||
</div>
|
||||
<table id="managertable" 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-id-card-o"></i> <?php lang('manager'); ?></th>
|
||||
<th data-priority="1"><i class="fa fa-fw fa-user"></i> <?php lang('employee'); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
/*$managers = $database->select('managers', [
|
||||
"[>]accounts (manager)" => ['managerid' => 'uid'],
|
||||
"[>]accounts (employee)" => ['employeeid' => 'uid']
|
||||
], [
|
||||
'managerid',
|
||||
'employeeid',
|
||||
'manager.username (manageruser)',
|
||||
'employee.username (employeeuser)',
|
||||
'manager.realname (managername)',
|
||||
'employee.realname (employeename)',
|
||||
]);
|
||||
foreach ($managers as $m) {
|
||||
?>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>
|
||||
<a class="btn btn-danger btn-xs" href="app.php?page=deletemanager&mid=<?php echo $m['managerid']; ?>&eid=<?php echo $m['employeeid']; ?>"><i class="fa fa-trash"></i> <?php lang("delete"); ?></a>
|
||||
</td>
|
||||
<td><?php echo $m['managername']; ?> (<?php echo $m['manageruser']; ?>)</td>
|
||||
<td><?php echo $m['employeename']; ?> (<?php echo $m['employeeuser']; ?>)</td>
|
||||
</tr>
|
||||
<?php
|
||||
}*/
|
||||
?>
|
||||
</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-id-card-o"></i> <?php lang('manager'); ?></th>
|
||||
<th data-priority="1"><i class="fa fa-fw fa-user"></i> <?php lang('employee'); ?></th>
|
||||
</tfoot>
|
||||
</table>
|
47
static/js/addmanager.js
Normal file
47
static/js/addmanager.js
Normal file
@ -0,0 +1,47 @@
|
||||
$("#manager").easyAutocomplete({
|
||||
url: "action.php",
|
||||
ajaxSettings: {
|
||||
dataType: "json",
|
||||
method: "GET",
|
||||
data: {
|
||||
action: "autocomplete_user"
|
||||
}
|
||||
},
|
||||
preparePostData: function (data) {
|
||||
data.q = $("#manager").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>";
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$("#employee").easyAutocomplete({
|
||||
url: "action.php",
|
||||
ajaxSettings: {
|
||||
dataType: "json",
|
||||
method: "GET",
|
||||
data: {
|
||||
action: "autocomplete_user"
|
||||
}
|
||||
},
|
||||
preparePostData: function (data) {
|
||||
data.q = $("#employee").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>";
|
||||
}
|
||||
}
|
||||
});
|
47
static/js/managers.js
Normal file
47
static/js/managers.js
Normal file
@ -0,0 +1,47 @@
|
||||
$('#managertable').DataTable({
|
||||
responsive: {
|
||||
details: {
|
||||
display: $.fn.dataTable.Responsive.display.modal({
|
||||
header: function (row) {
|
||||
var data = row.data();
|
||||
return "<i class=\"fa fa-id-card-o fa-fw\"></i> " + data[2];
|
||||
}
|
||||
}),
|
||||
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/getmanagetable.php",
|
||||
dataFilter: function (data) {
|
||||
var json = jQuery.parseJSON(data);
|
||||
json.data = [];
|
||||
json.managers.forEach(function (row) {
|
||||
json.data.push([
|
||||
"",
|
||||
row.delbtn,
|
||||
row.managername + " (" + row.manageruser + ")",
|
||||
row.employeename + " (" + row.employeeuser + ")"
|
||||
]);
|
||||
});
|
||||
return JSON.stringify(json);
|
||||
}
|
||||
}
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user