From 900e3bb709a7e59b2f97dd43f1bc0bc7fa8a5086 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Wed, 5 Jul 2017 13:23:26 -0600 Subject: [PATCH] Add ability to see punches of managed users --- lang/en_us.php | 4 +++- lib/getpunchtable.php | 44 ++++++++++++++++++++++++++++++++----------- pages/punches.php | 11 ++++++++++- static/js/punches.js | 17 ++++++++++++----- 4 files changed, 58 insertions(+), 18 deletions(-) diff --git a/lang/en_us.php b/lang/en_us.php index 856b10e..69aeb4b 100644 --- a/lang/en_us.php +++ b/lang/en_us.php @@ -45,5 +45,7 @@ define("STRINGS", [ "x on the clock" => "{time} on the clock", "x punches" => "{count} punches", "history" => "History", - "shifts" => "Shifts" + "shifts" => "Shifts", + "show all punches" => "Show other users", + "name" => "Name" ]); \ No newline at end of file diff --git a/lib/getpunchtable.php b/lib/getpunchtable.php index 0c3523c..9d73d33 100644 --- a/lib/getpunchtable.php +++ b/lib/getpunchtable.php @@ -6,11 +6,21 @@ dieifnotloggedin(); 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['draw'] = intval($VARS['draw']); -$out['recordsTotal'] = $database->count('punches', ['uid' => $_SESSION['uid']]); +$out['recordsTotal'] = $database->count('punches', ['uid' => $managed_uids]); $filter = false; // sort @@ -21,9 +31,12 @@ if ($VARS['order'][0]['dir'] == 'asc') { } switch ($VARS['order'][0]['column']) { case 1: - $order = ["in" => $sortby]; + $order = ["uid" => $sortby]; break; case 2: + $order = ["in" => $sortby]; + break; + case 3: $order = ["out" => $sortby]; break; } @@ -37,13 +50,13 @@ if (!is_empty($VARS['search']['value'])) { "in[~]" => $VARS['search']['value'], "out[~]" => $VARS['search']['value'] ], - "uid" => $_SESSION['uid'] + "uid" => $managed_uids ] ]; $where = $wherenolimit; $where["LIMIT"] = [$VARS['start'], $VARS['length']]; } else { - $where = ["uid" => $_SESSION['uid'], "LIMIT" => [$VARS['start'], $VARS['length']]]; + $where = ["uid" => $managed_uids, "LIMIT" => [$VARS['start'], $VARS['length']]]; } if (!is_null($order)) { @@ -52,20 +65,29 @@ if (!is_null($order)) { $punches = $database->select('punches', [ + 'uid', 'in', 'out', 'notes' ], $where); +$usercache = []; + for ($i = 0; $i < count($punches); $i++) { - $punches[$i][0] = ""; - $punches[$i][1] = date(DATETIME_FORMAT, strtotime($punches[$i]['in'])); - if (is_null($punches[$i]['out'])) { - $punches[$i][2] = lang("na", false); - } else { - $punches[$i][2] = date(DATETIME_FORMAT, strtotime($punches[$i]['out'])); + // Get user info + if (!isset($usercache[$punches[$i]['uid']])) { + $usercache[$punches[$i]['uid']] = getUserByID($punches[$i]['uid']); } - $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"; diff --git a/pages/punches.php b/pages/punches.php index 72b3709..cd9767c 100644 --- a/pages/punches.php +++ b/pages/punches.php @@ -49,6 +49,7 @@ $totalpunches = count($punches); + @@ -60,8 +61,16 @@ $totalpunches = count($punches); + - \ No newline at end of file + + + \ No newline at end of file diff --git a/static/js/punches.js b/static/js/punches.js index b2a2e80..0e230e7 100644 --- a/static/js/punches.js +++ b/static/js/punches.js @@ -1,4 +1,4 @@ -$('#punchtable').DataTable({ +var punchtable = $('#punchtable').DataTable({ responsive: { details: { display: $.fn.dataTable.Responsive.display.modal({ @@ -20,15 +20,22 @@ $('#punchtable').DataTable({ orderable: false }, { - targets: 3, + targets: 4, orderable: false } ], order: [ - [1, 'desc'] + [2, 'desc'] ], serverSide: true, ajax: { - url: "lib/getpunchtable.php" + url: "lib/getpunchtable.php", + data: function (d) { + if ($('#show_all_checkbox').is(':checked')) { + d.show_all = 1; + } + }, } -}); \ No newline at end of file +}); + +$('#punchtable_filter').append("
"); \ No newline at end of file