Add ability to see punches of managed users
This commit is contained in:
parent
1fb4afc6aa
commit
900e3bb709
@ -45,5 +45,7 @@ define("STRINGS", [
|
|||||||
"x on the clock" => "{time} on the clock",
|
"x on the clock" => "{time} on the clock",
|
||||||
"x punches" => "{count} punches",
|
"x punches" => "{count} punches",
|
||||||
"history" => "History",
|
"history" => "History",
|
||||||
"shifts" => "Shifts"
|
"shifts" => "Shifts",
|
||||||
|
"show all punches" => "Show other users",
|
||||||
|
"name" => "Name"
|
||||||
]);
|
]);
|
@ -6,11 +6,21 @@ dieifnotloggedin();
|
|||||||
|
|
||||||
header("Content-Type: application/json");
|
header("Content-Type: application/json");
|
||||||
|
|
||||||
|
require_once __DIR__ . "/login.php";
|
||||||
|
require_once __DIR__ . "/userinfo.php";
|
||||||
|
|
||||||
|
$showmanaged = ($VARS['show_all'] == 1 && account_has_permission($_SESSION['username'], "QWIKCLOCK_MANAGE"));
|
||||||
|
$managed_uids = [];
|
||||||
|
if ($showmanaged) {
|
||||||
|
$managed_uids = getManagedUIDs($_SESSION['uid']);
|
||||||
|
}
|
||||||
|
$managed_uids[] = $_SESSION['uid'];
|
||||||
|
|
||||||
$out = [];
|
$out = [];
|
||||||
|
|
||||||
$out['draw'] = intval($VARS['draw']);
|
$out['draw'] = intval($VARS['draw']);
|
||||||
|
|
||||||
$out['recordsTotal'] = $database->count('punches', ['uid' => $_SESSION['uid']]);
|
$out['recordsTotal'] = $database->count('punches', ['uid' => $managed_uids]);
|
||||||
$filter = false;
|
$filter = false;
|
||||||
|
|
||||||
// sort
|
// sort
|
||||||
@ -21,9 +31,12 @@ if ($VARS['order'][0]['dir'] == 'asc') {
|
|||||||
}
|
}
|
||||||
switch ($VARS['order'][0]['column']) {
|
switch ($VARS['order'][0]['column']) {
|
||||||
case 1:
|
case 1:
|
||||||
$order = ["in" => $sortby];
|
$order = ["uid" => $sortby];
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
|
$order = ["in" => $sortby];
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
$order = ["out" => $sortby];
|
$order = ["out" => $sortby];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -37,13 +50,13 @@ if (!is_empty($VARS['search']['value'])) {
|
|||||||
"in[~]" => $VARS['search']['value'],
|
"in[~]" => $VARS['search']['value'],
|
||||||
"out[~]" => $VARS['search']['value']
|
"out[~]" => $VARS['search']['value']
|
||||||
],
|
],
|
||||||
"uid" => $_SESSION['uid']
|
"uid" => $managed_uids
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
$where = $wherenolimit;
|
$where = $wherenolimit;
|
||||||
$where["LIMIT"] = [$VARS['start'], $VARS['length']];
|
$where["LIMIT"] = [$VARS['start'], $VARS['length']];
|
||||||
} else {
|
} else {
|
||||||
$where = ["uid" => $_SESSION['uid'], "LIMIT" => [$VARS['start'], $VARS['length']]];
|
$where = ["uid" => $managed_uids, "LIMIT" => [$VARS['start'], $VARS['length']]];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_null($order)) {
|
if (!is_null($order)) {
|
||||||
@ -52,20 +65,29 @@ if (!is_null($order)) {
|
|||||||
|
|
||||||
|
|
||||||
$punches = $database->select('punches', [
|
$punches = $database->select('punches', [
|
||||||
|
'uid',
|
||||||
'in',
|
'in',
|
||||||
'out',
|
'out',
|
||||||
'notes'
|
'notes'
|
||||||
], $where);
|
], $where);
|
||||||
|
|
||||||
|
$usercache = [];
|
||||||
|
|
||||||
for ($i = 0; $i < count($punches); $i++) {
|
for ($i = 0; $i < count($punches); $i++) {
|
||||||
$punches[$i][0] = "";
|
// Get user info
|
||||||
$punches[$i][1] = date(DATETIME_FORMAT, strtotime($punches[$i]['in']));
|
if (!isset($usercache[$punches[$i]['uid']])) {
|
||||||
if (is_null($punches[$i]['out'])) {
|
$usercache[$punches[$i]['uid']] = getUserByID($punches[$i]['uid']);
|
||||||
$punches[$i][2] = lang("na", false);
|
|
||||||
} else {
|
|
||||||
$punches[$i][2] = date(DATETIME_FORMAT, strtotime($punches[$i]['out']));
|
|
||||||
}
|
}
|
||||||
$punches[$i][3] = $punches[$i]['notes'];
|
|
||||||
|
$punches[$i][0] = "";
|
||||||
|
$punches[$i][1] = $usercache[$punches[$i]['uid']]['name'];
|
||||||
|
$punches[$i][2] = date(DATETIME_FORMAT, strtotime($punches[$i]['in']));
|
||||||
|
if (is_null($punches[$i]['out'])) {
|
||||||
|
$punches[$i][3] = lang("na", false);
|
||||||
|
} else {
|
||||||
|
$punches[$i][3] = date(DATETIME_FORMAT, strtotime($punches[$i]['out']));
|
||||||
|
}
|
||||||
|
$punches[$i][4] = $punches[$i]['notes'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$out['status'] = "OK";
|
$out['status'] = "OK";
|
||||||
|
@ -49,6 +49,7 @@ $totalpunches = count($punches);
|
|||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th data-priority="0"></th>
|
<th data-priority="0"></th>
|
||||||
|
<th data-priority="2"><i class="fa fa-fw fa-user"></i> <?php lang('name'); ?></th>
|
||||||
<th data-priority="1"><i class="fa fa-fw fa-play"></i> <?php lang('in'); ?></th>
|
<th data-priority="1"><i class="fa fa-fw fa-play"></i> <?php lang('in'); ?></th>
|
||||||
<th data-priority="1"><i class="fa fa-fw fa-stop"></i> <?php lang('out'); ?></th>
|
<th data-priority="1"><i class="fa fa-fw fa-stop"></i> <?php lang('out'); ?></th>
|
||||||
<th data-priority="2"><i class="fa fa-fw fa-sticky-note-o"></i> <?php lang('notes'); ?></th>
|
<th data-priority="2"><i class="fa fa-fw fa-sticky-note-o"></i> <?php lang('notes'); ?></th>
|
||||||
@ -60,8 +61,16 @@ $totalpunches = count($punches);
|
|||||||
<tfoot>
|
<tfoot>
|
||||||
<tr>
|
<tr>
|
||||||
<th data-priority="0"></th>
|
<th data-priority="0"></th>
|
||||||
|
<th data-priority="2"><i class="fa fa-fw fa-user"></i> <?php lang('name'); ?></th>
|
||||||
<th data-priority="1"><i class="fa fa-fw fa-play"></i> <?php lang('in'); ?></th>
|
<th data-priority="1"><i class="fa fa-fw fa-play"></i> <?php lang('in'); ?></th>
|
||||||
<th data-priority="1"><i class="fa fa-fw fa-stop"></i> <?php lang('out'); ?></th>
|
<th data-priority="1"><i class="fa fa-fw fa-stop"></i> <?php lang('out'); ?></th>
|
||||||
<th data-priority="2"><i class="fa fa-fw fa-sticky-note-o"></i> <?php lang('notes'); ?></th>
|
<th data-priority="2"><i class="fa fa-fw fa-sticky-note-o"></i> <?php lang('notes'); ?></th>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
/* Give JavaScript access to the lang string
|
||||||
|
* it needs to inject the show deleted checkbox
|
||||||
|
*/
|
||||||
|
var lang_show_all_punches = "<?php lang("show all punches") ?>";
|
||||||
|
</script>
|
@ -1,4 +1,4 @@
|
|||||||
$('#punchtable').DataTable({
|
var punchtable = $('#punchtable').DataTable({
|
||||||
responsive: {
|
responsive: {
|
||||||
details: {
|
details: {
|
||||||
display: $.fn.dataTable.Responsive.display.modal({
|
display: $.fn.dataTable.Responsive.display.modal({
|
||||||
@ -20,15 +20,22 @@ $('#punchtable').DataTable({
|
|||||||
orderable: false
|
orderable: false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
targets: 3,
|
targets: 4,
|
||||||
orderable: false
|
orderable: false
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
order: [
|
order: [
|
||||||
[1, 'desc']
|
[2, 'desc']
|
||||||
],
|
],
|
||||||
serverSide: true,
|
serverSide: true,
|
||||||
ajax: {
|
ajax: {
|
||||||
url: "lib/getpunchtable.php"
|
url: "lib/getpunchtable.php",
|
||||||
|
data: function (d) {
|
||||||
|
if ($('#show_all_checkbox').is(':checked')) {
|
||||||
|
d.show_all = 1;
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#punchtable_filter').append("<div class=\"checkbox\" style=\"display: inline-block\"><label><input type=\"checkbox\" id=\"show_all_checkbox\" onclick=\"punchtable.ajax.reload()\"> " + lang_show_all_punches + "</label></div>");
|
Loading…
x
Reference in New Issue
Block a user