Redesign manager UI, close #4
This commit is contained in:
parent
d2a048e5e8
commit
21f39a326f
34
action.php
34
action.php
@ -20,13 +20,20 @@ if (account_has_permission($_SESSION['username'], "ADMIN") == FALSE) {
|
||||
* The message will be displayed by the app.
|
||||
* @param string $msg message ID (see lang/messages.php)
|
||||
* @param string $arg If set, replaces "{arg}" in the message string when displayed to the user.
|
||||
* @param [key=>val] $additional Put the given key-value array in the URL
|
||||
*/
|
||||
function returnToSender($msg, $arg = "") {
|
||||
function returnToSender($msg, $arg = "", $additional = []) {
|
||||
global $VARS;
|
||||
$add = "";
|
||||
if ($additional != []) {
|
||||
foreach ($additional as $key => $val) {
|
||||
$add .= "&" . urlencode($key) . "=" . urlencode($val);
|
||||
}
|
||||
}
|
||||
if ($arg == "") {
|
||||
header("Location: app.php?page=" . urlencode($VARS['source']) . "&msg=" . $msg);
|
||||
header("Location: app.php?page=" . urlencode($VARS['source']) . $add . "&msg=" . $msg);
|
||||
} else {
|
||||
header("Location: app.php?page=" . urlencode($VARS['source']) . "&msg=$msg&arg=$arg");
|
||||
header("Location: app.php?page=" . urlencode($VARS['source']) . $add . "&msg=$msg&arg=$arg");
|
||||
}
|
||||
die();
|
||||
}
|
||||
@ -101,6 +108,27 @@ switch ($VARS['action']) {
|
||||
$database->delete('authlog');
|
||||
insertAuthLog(15, $_SESSION['uid'], lang2("removed n entries", ['n' => $rows], false));
|
||||
returnToSender("log_cleared");
|
||||
case "editmanager":
|
||||
require_once __DIR__ . "/lib/userinfo.php";
|
||||
if (!$database->has('accounts', ['username' => $VARS['manager']])) {
|
||||
returnToSender("invalid_manager");
|
||||
}
|
||||
$manager = getUserByUsername($VARS['manager'])['uid'];
|
||||
$already_assigned = $database->select('managers', 'employeeid', ['managerid' => $manager]);
|
||||
|
||||
foreach ($VARS['employees'] as $u) {
|
||||
if (!user_exists($u)) {
|
||||
returnToSender("user_not_exists", htmlentities($u));
|
||||
}
|
||||
$uid = getUserByUsername($u)['uid'];
|
||||
$database->insert('managers', ['employeeid' => $uid, 'managerid' => $manager]);
|
||||
$already_assigned = array_diff($already_assigned, [$uid]); // Remove user from old list
|
||||
}
|
||||
foreach ($already_assigned as $uid) {
|
||||
$database->delete('managers', ["AND" => ['employeeid' => $uid, 'managerid' => $manager]]);
|
||||
}
|
||||
returnToSender("manager_assigned", "", ["man" => $VARS['manager']]);
|
||||
break;
|
||||
case "addmanager":
|
||||
if (!$database->has('accounts', ['username' => $VARS['manager']])) {
|
||||
returnToSender("invalid_userid");
|
||||
|
@ -87,5 +87,11 @@ define("STRINGS", [
|
||||
"2fa removed" => "2-factor authentication removed.",
|
||||
"2fa" => "2FA",
|
||||
"show deleted" => "Show deleted",
|
||||
"editing deleted account" => "You are editing an account marked as deleted. The account will be undeleted if you press Save."
|
||||
"editing deleted account" => "You are editing an account marked as deleted. The account will be undeleted if you press Save.",
|
||||
"manager assigned" => "Manager relationships saved.",
|
||||
"manager does not exist" => "The selected manager username does not exist.",
|
||||
"type to add a person" => "Type to add a person",
|
||||
"employees" => "Employees",
|
||||
"type to select a manager" => "Type to select a manager",
|
||||
"select a manager to view or edit employees" => "Select a manager to view or edit the assigned employees."
|
||||
]);
|
@ -56,5 +56,13 @@ define("MESSAGES", [
|
||||
"2fa_removed" => [
|
||||
"string" => "2fa removed",
|
||||
"type" => "success"
|
||||
]
|
||||
],
|
||||
"manager_assigned" => [
|
||||
"string" => "manager assigned",
|
||||
"type" => "success"
|
||||
],
|
||||
"invalid_manager" => [
|
||||
"string" => "manager does not exist",
|
||||
"type" => "danger"
|
||||
],
|
||||
]);
|
||||
|
18
pages.php
18
pages.php
@ -52,30 +52,14 @@ define("PAGES", [
|
||||
"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"
|
||||
"static/js/managers.js"
|
||||
]
|
||||
],
|
||||
"delmanager" => [
|
||||
"title" => "delete manager",
|
||||
"navbar" => false
|
||||
],
|
||||
"permissions" => [
|
||||
"title" => "permissions",
|
||||
"navbar" => true,
|
||||
|
@ -1,38 +0,0 @@
|
||||
<?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>
|
@ -1,58 +0,0 @@
|
||||
<?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>
|
@ -2,51 +2,66 @@
|
||||
require_once __DIR__ . '/../required.php';
|
||||
|
||||
redirectifnotloggedin();
|
||||
|
||||
|
||||
$assigned = [];
|
||||
$employees = false;
|
||||
$user = "";
|
||||
if ($VARS['man'] && $database->has('accounts', ['username' => $VARS['man']])) {
|
||||
$user = $VARS['man'];
|
||||
require_once __DIR__ . "/../lib/userinfo.php";
|
||||
$uid = getUserByUsername($user)['uid'];
|
||||
$assigned = $database->select('managers', ["[>]accounts" => ["employeeid" => "uid"]], 'username', ['managerid' => $uid]);
|
||||
$employees = true;
|
||||
}
|
||||
?>
|
||||
<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>
|
||||
|
||||
<form role="form" action="action.php" method="POST">
|
||||
<div class="alert alert-brown"><?php lang("select a manager to view or edit employees"); ?></div>
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="manager-box"><i class="fa fa-id-card-o"></i> <?php lang("manager"); ?></label><br />
|
||||
<input type="text" id="manager-box" class="form-control" value="<?php echo $user ?>" name="manager" placeholder="<?php lang("type to select a manager"); ?>" />
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
if ($employees !== false) {
|
||||
?>
|
||||
<div class="col-xs-12 col-md-6">
|
||||
<label for="people-box"><i class="fa fa-user"></i> <?php lang("employees"); ?></label><br />
|
||||
<div class="row">
|
||||
<div class="col-xs-8 col-sm-10 col-md-9 col-lg-10">
|
||||
<input type="text" id="people-box" class="form-control" placeholder="<?php lang("type to add a person") ?>" />
|
||||
</div>
|
||||
<div class="col-xs-4 col-sm-2 col-md-3 col-lg-2">
|
||||
<button class="btn btn-default" type="button" id="addpersonbtn"><i class="fa fa-plus"></i> <?php lang("add") ?></button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel" style="max-height: 700px; overflow-y: scroll;">
|
||||
<div class="list-group" id="peoplelist">
|
||||
<?php
|
||||
foreach ($assigned as $user) {
|
||||
?>
|
||||
<div class="list-group-item" data-user="<?php echo $user; ?>">
|
||||
<?php echo $user; ?> <div onclick="removePerson('<?php echo $user; ?>')" class="btn btn-danger btn-sm pull-right"><i class="fa fa-trash-o"></i></div><input type="hidden" name="employees[]" value="<?php echo $user; ?>" />
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</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 hidden-xs"></i> <?php lang('manager'); ?></th>
|
||||
<th data-priority="1"><i class="fa fa-fw fa-user hidden-xs"></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 hidden-xs"></i> <?php lang('manager'); ?></th>
|
||||
<th data-priority="1"><i class="fa fa-fw fa-user hidden-xs"></i> <?php lang('employee'); ?></th>
|
||||
</tfoot>
|
||||
</table>
|
||||
|
||||
<input type="hidden" name="action" value="editmanager" />
|
||||
<input type="hidden" name="source" value="managers" />
|
||||
|
||||
<?php if ($employees !== false) { ?>
|
||||
<button type="submit" class="btn btn-success pull-right" id="save-btn"><i class="fa fa-floppy-o"></i> <?php lang("save"); ?></button>
|
||||
<?php } ?>
|
||||
</form>
|
@ -1,47 +0,0 @@
|
||||
$("#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>";
|
||||
}
|
||||
}
|
||||
});
|
@ -1,47 +1,104 @@
|
||||
$('#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"
|
||||
var empoptions = {
|
||||
url: "action.php",
|
||||
ajaxSettings: {
|
||||
dataType: "json",
|
||||
method: "GET",
|
||||
data: {
|
||||
action: "autocomplete_user"
|
||||
}
|
||||
},
|
||||
columnDefs: [
|
||||
{
|
||||
targets: 0,
|
||||
className: 'control',
|
||||
orderable: false
|
||||
preparePostData: function (data) {
|
||||
data.q = $("#people-box").val();
|
||||
return data;
|
||||
},
|
||||
{
|
||||
targets: 1,
|
||||
orderable: false
|
||||
getValue: function (element) {
|
||||
return element.username;
|
||||
},
|
||||
template: {
|
||||
type: "custom",
|
||||
method: function (value, item) {
|
||||
return item.name + " <i class=\"small\">" + item.username + "</i>";
|
||||
}
|
||||
],
|
||||
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);
|
||||
},
|
||||
list: {
|
||||
onClickEvent: function () {
|
||||
var value = $("#people-box").getSelectedItemData().username;
|
||||
addPerson(value);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$("#people-box").easyAutocomplete(empoptions);
|
||||
|
||||
var manoptions = {
|
||||
url: "action.php",
|
||||
ajaxSettings: {
|
||||
dataType: "json",
|
||||
method: "GET",
|
||||
data: {
|
||||
action: "autocomplete_user"
|
||||
}
|
||||
},
|
||||
preparePostData: function (data) {
|
||||
data.q = $("#manager-box").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>";
|
||||
}
|
||||
},
|
||||
list: {
|
||||
onClickEvent: function () {
|
||||
var value = $("#manager-box").getSelectedItemData().username;
|
||||
document.location.href = "app.php?page=managers&man=" + value;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$("#manager-box").easyAutocomplete(manoptions);
|
||||
|
||||
$("#people-box").keyup(function (event) {
|
||||
if (event.keyCode == 13) {
|
||||
$("#addpersonbtn").click();
|
||||
event.preventDefault();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
$("#people-box").keydown(function (event) {
|
||||
if (event.keyCode == 13) {
|
||||
event.preventDefault();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
$("#addpersonbtn").click(function () {
|
||||
addPerson($("#people-box").val());
|
||||
});
|
||||
|
||||
function addPerson(p) {
|
||||
p = String.trim(p);
|
||||
if (p == "") {
|
||||
return false;
|
||||
}
|
||||
if ($("#peoplelist div[data-user=" + p + "]").length) {
|
||||
$("#peoplelist .list-group-item[data-user=" + p + "]").animate({
|
||||
backgroundColor: "#ff0000",
|
||||
}, 500, "linear", function () {
|
||||
$("#peoplelist .list-group-item[data-user=" + p + "]").animate({
|
||||
backgroundColor: "#ffffff",
|
||||
}, 500);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
$('#peoplelist').append("<div class=\"list-group-item\" data-user=\"" + p + "\">" + p + "<div onclick=\"removePerson('" + p + "')\" class=\"btn btn-danger btn-sm pull-right\"><i class=\"fa fa-trash-o\"></i></div><input type=\"hidden\" name=\"employees[]\" value=\"" + p + "\" /></div>");
|
||||
$("#people-box").val("");
|
||||
}
|
||||
|
||||
function removePerson(p) {
|
||||
$("#peoplelist div[data-user=" + p + "]").remove();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user