Add shifts table
This commit is contained in:
parent
900e3bb709
commit
37e7d127ce
@ -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"
|
||||
]);
|
149
lib/getshifttable.php
Normal file
149
lib/getshifttable.php
Normal file
@ -0,0 +1,149 @@
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/../required.php';
|
||||
|
||||
dieifnotloggedin();
|
||||
|
||||
header("Content-Type: application/json");
|
||||
|
||||
require_once __DIR__ . "/login.php";
|
||||
require_once __DIR__ . "/userinfo.php";
|
||||
|
||||
$showall = ($VARS['show_all'] == 1); // && account_has_permission($_SESSION['username'], "QWIKCLOCK_MANAGE"));
|
||||
|
||||
$showmanaged = false;
|
||||
$managed_uids = [];
|
||||
if ($showmanaged) {
|
||||
$managed_uids = getManagedUIDs($_SESSION['uid']);
|
||||
}
|
||||
$managed_uids[] = $_SESSION['uid'];
|
||||
|
||||
$out = [];
|
||||
|
||||
$out['draw'] = intval($VARS['draw']);
|
||||
|
||||
if ($showall) {
|
||||
$out['recordsTotal'] = $database->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] = "<span style=\"word-wrap: break-word;\">" . implode(", ", $days) . "</span>";
|
||||
}
|
||||
|
||||
$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);
|
@ -14,7 +14,7 @@ define("PAGES", [
|
||||
"title" => "404 error"
|
||||
],
|
||||
"punches" => [
|
||||
"title" => "history",
|
||||
"title" => "punch card",
|
||||
"navbar" => true,
|
||||
"icon" => "clock-o",
|
||||
"styles" => [
|
||||
|
@ -14,44 +14,16 @@ foreach ($punches as $p) {
|
||||
$totalseconds = sumelapsedtimearray($punchtimes);
|
||||
$totalpunches = count($punches);
|
||||
?>
|
||||
<p class="page-header h5"><i class="fa fa-calendar fa-fw"></i> <?php lang("this week") ?></p>
|
||||
<div class="row">
|
||||
|
||||
<div class="col-xs-12 col-sm-6 col-md-4 col-md-offset-2">
|
||||
<div class="panel panel-blue">
|
||||
<div class="panel-body">
|
||||
<h4>
|
||||
<?php
|
||||
lang2("x on the clock", ["time" => seconds2string($totalseconds, false)]);
|
||||
?>
|
||||
</h4>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-xs-12 col-sm-6 col-md-4">
|
||||
<div class="panel panel-blue">
|
||||
<div class="panel-body">
|
||||
<h4>
|
||||
<?php
|
||||
lang2("x punches", ["count" => $totalpunches]);
|
||||
?>
|
||||
</h4>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<a id="punches" style="height: 0px; width: 0px;"> </a>
|
||||
|
||||
<p class="page-header h5"><i class="fa fa-clock-o fa-fw"></i> <?php lang("punch card") ?></p>
|
||||
<table id="punchtable" class="table table-bordered table-striped">
|
||||
<p class="page-header h5"><i class="fa fa-clock-o fa-fw"></i> <?php lang("shifts") ?></p>
|
||||
<table id="shifttable" class="table table-bordered table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-priority="0"></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="2"><i class="fa fa-fw fa-sticky-note-o"></i> <?php lang('notes'); ?></th>
|
||||
<th data-priority="3"><i class="fa fa-fw fa-font hidden-xs"></i> <?php lang('name'); ?></th>
|
||||
<th data-priority="1"><i class="fa fa-fw fa-play hidden-xs"></i> <?php lang('start'); ?></th>
|
||||
<th data-priority="1"><i class="fa fa-fw fa-stop hidden-xs"></i> <?php lang('end'); ?></th>
|
||||
<th data-priority="2"><i class="fa fa-fw fa-calendar hidden-xs"></i> <?php lang('days'); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@ -60,8 +32,16 @@ $totalpunches = count($punches);
|
||||
<tfoot>
|
||||
<tr>
|
||||
<th data-priority="0"></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="2"><i class="fa fa-fw fa-sticky-note-o"></i> <?php lang('notes'); ?></th>
|
||||
<th data-priority="3"><i class="fa fa-fw fa-font hidden-xs"></i> <?php lang('name'); ?></th>
|
||||
<th data-priority="1"><i class="fa fa-fw fa-play hidden-xs"></i> <?php lang('start'); ?></th>
|
||||
<th data-priority="1"><i class="fa fa-fw fa-stop hidden-xs"></i> <?php lang('end'); ?></th>
|
||||
<th data-priority="2"><i class="fa fa-fw fa-calendar hidden-xs"></i> <?php lang('days'); ?></th>
|
||||
</tfoot>
|
||||
</table>
|
||||
</table>
|
||||
|
||||
<script>
|
||||
/* Give JavaScript access to the lang string
|
||||
* it needs to inject the filter checkbox
|
||||
*/
|
||||
var lang_show_all_shifts = "<?php lang("show all shifts") ?>";
|
||||
</script>
|
41
static/js/shifts.js
Normal file
41
static/js/shifts.js
Normal file
@ -0,0 +1,41 @@
|
||||
var shifttable = $('#shifttable').DataTable({
|
||||
responsive: {
|
||||
details: {
|
||||
display: $.fn.dataTable.Responsive.display.modal({
|
||||
header: function (row) {
|
||||
var data = row.data();
|
||||
return "<i class=\"fa fa-calendar fa-fw\"></i> " + 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("<div class=\"checkbox\" style=\"display: inline-block\"><label><input type=\"checkbox\" id=\"show_all_checkbox\" onclick=\"shifttable.ajax.reload()\"> " + lang_show_all_shifts + "</label></div>");
|
Loading…
x
Reference in New Issue
Block a user