From 37e7d127ce5954ca1dce2767692ac86b7aceb801 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Wed, 5 Jul 2017 19:51:33 -0600 Subject: [PATCH] Add shifts table --- lang/en_us.php | 13 +++- lib/getshifttable.php | 149 ++++++++++++++++++++++++++++++++++++++++++ pages.php | 2 +- pages/shifts.php | 56 +++++----------- static/js/shifts.js | 41 ++++++++++++ 5 files changed, 221 insertions(+), 40 deletions(-) create mode 100644 lib/getshifttable.php create mode 100644 static/js/shifts.js diff --git a/lang/en_us.php b/lang/en_us.php index 69aeb4b..00b4fc1 100644 --- a/lang/en_us.php +++ b/lang/en_us.php @@ -47,5 +47,16 @@ define("STRINGS", [ "history" => "History", "shifts" => "Shifts", "show all punches" => "Show other users", - "name" => "Name" + "name" => "Name", + "start" => "Start", + "end" => "End", + "days" => "Days", + "sunday" => "Sunday", + "monday" => "Monday", + "tuesday" => "Tuesday", + "wednesday" => "Wednesday", + "thursday" => "Thursday", + "friday" => "Friday", + "saturday" => "Saturday", + "show all shifts" => "Show all shifts" ]); \ No newline at end of file diff --git a/lib/getshifttable.php b/lib/getshifttable.php new file mode 100644 index 0000000..1785f99 --- /dev/null +++ b/lib/getshifttable.php @@ -0,0 +1,149 @@ +count('shifts'); +} else { + $out['recordsTotal'] = $database->count('shifts', ["[>]assigned_shifts" => ["shiftid" => "shiftid"]], 'shiftname', ["uid" => $managed_uids]); +} +$filter = false; + +// sort +$order = null; +$sortby = "DESC"; +if ($VARS['order'][0]['dir'] == 'asc') { + $sortby = "ASC"; +} +switch ($VARS['order'][0]['column']) { + case 1: + $order = ["shiftname" => $sortby]; + break; + case 2: + $order = ["start" => $sortby]; + break; + case 3: + $order = ["end" => $sortby]; + break; +} + +// search +if (!is_empty($VARS['search']['value'])) { + $filter = true; + $wherenolimit = [ + "AND" => [ + "OR" => [ + "shiftname[~]" => $VARS['search']['value'], + "start[~]" => $VARS['search']['value'], + "end[~]" => $VARS['search']['value'], + ] + ] + ]; + if (!$showall) { + $wherenolimit["AND"]["uid"] = $managed_uids; + } + $where = $wherenolimit; + $where["LIMIT"] = [$VARS['start'], $VARS['length']]; +} else { + $where = ["LIMIT" => [$VARS['start'], $VARS['length']]]; + if (!$showall) { + $where["uid"] = $managed_uids; + } +} + +if (!is_null($order)) { + $where["ORDER"] = $order; +} + + +if ($showall) { + $shifts = $database->select('shifts', [ + 'shiftid', + 'shiftname', + 'start', + 'end', + 'days' + ], $where); +} else { + $shifts = $database->select('shifts', [ + "[>]assigned_shifts" => [ + "shiftid" => "shiftid" + ] + ], [ + 'shifts.shiftid', + 'shiftname', + 'start', + 'end', + 'days' + ], $where); +} + +for ($i = 0; $i < count($shifts); $i++) { + $shifts[$i][0] = ""; + $shifts[$i][1] = $shifts[$i]['shiftname']; + $shifts[$i][2] = date(TIME_FORMAT, strtotime($shifts[$i]['start'])); + $shifts[$i][3] = date(TIME_FORMAT, strtotime($shifts[$i]['end'])); + $days = []; + $daycodes = str_split($shifts[$i]['days'], 2); + foreach ($daycodes as $day) { + switch ($day) { + case "Su": + $days[] = lang("sunday", false); + break; + case "Mo": + $days[] = lang("monday", false); + break; + case "Tu": + $days[] = lang("tuesday", false); + break; + case "We": + $days[] = lang("wednesday", false); + break; + case "Th": + $days[] = lang("thursday", false); + break; + case "Fr": + $days[] = lang("friday", false); + break; + case "Sa": + $days[] = lang("saturday", false); + break; + } + } + $shifts[$i][4] = "" . implode(", ", $days) . ""; +} + +$out['status'] = "OK"; +if ($filter) { + if ($showall) { + $recordsFiltered = $database->count('shifts', $wherenolimit); + } else { + $recordsFiltered = count($shifts); + } +} else { + $recordsFiltered = $out['recordsTotal']; +} +$out['recordsFiltered'] = $recordsFiltered; +$out['data'] = $shifts; + +echo json_encode($out); diff --git a/pages.php b/pages.php index 5fa2876..f2dba65 100644 --- a/pages.php +++ b/pages.php @@ -14,7 +14,7 @@ define("PAGES", [ "title" => "404 error" ], "punches" => [ - "title" => "history", + "title" => "punch card", "navbar" => true, "icon" => "clock-o", "styles" => [ diff --git a/pages/shifts.php b/pages/shifts.php index 72b3709..5504bd1 100644 --- a/pages/shifts.php +++ b/pages/shifts.php @@ -14,44 +14,16 @@ foreach ($punches as $p) { $totalseconds = sumelapsedtimearray($punchtimes); $totalpunches = count($punches); ?> - -
-
-
-
-

- seconds2string($totalseconds, false)]); - ?> -

-
-
-
- -
-
-
-

- $totalpunches]); - ?> -

-
-
-
-
- -  - - - + +
- - - + + + + @@ -60,8 +32,16 @@ $totalpunches = count($punches); - - - + + + + -
\ No newline at end of file + + + \ No newline at end of file diff --git a/static/js/shifts.js b/static/js/shifts.js new file mode 100644 index 0000000..ea66458 --- /dev/null +++ b/static/js/shifts.js @@ -0,0 +1,41 @@ +var shifttable = $('#shifttable').DataTable({ + responsive: { + details: { + display: $.fn.dataTable.Responsive.display.modal({ + header: function (row) { + var data = row.data(); + return " " + data[1]; + } + }), + renderer: $.fn.dataTable.Responsive.renderer.tableAll({ + tableClass: 'table' + }), + type: "column" + } + }, + columnDefs: [ + { + targets: 0, + className: 'control', + orderable: false + }, + { + targets: 4, + orderable: false + } + ], + order: [ + [2, 'desc'] + ], + serverSide: true, + ajax: { + url: "lib/getshifttable.php", + data: function (d) { + if ($('#show_all_checkbox').is(':checked')) { + d.show_all = 1; + } + }, + } +}); + +$('#shifttable_filter').append("
"); \ No newline at end of file