Add shift editing
This commit is contained in:
parent
f6c2368f7a
commit
6eb6c3a0de
46
action.php
46
action.php
@ -50,6 +50,52 @@ switch ($VARS['action']) {
|
|||||||
$out = ["status" => "OK", "in" => $in];
|
$out = ["status" => "OK", "in" => $in];
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
exit(json_encode($out));
|
exit(json_encode($out));
|
||||||
|
case "editshift":
|
||||||
|
if (account_has_permission($_SESSION['username'], "QWIKCLOCK_MANAGE")) {
|
||||||
|
$valid_daycodes = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
|
||||||
|
|
||||||
|
$name = htmlentities($VARS['shiftname']);
|
||||||
|
$start = $VARS['start'];
|
||||||
|
$end = $VARS['end'];
|
||||||
|
$days = $VARS['days'];
|
||||||
|
|
||||||
|
$startepoch = strtotime($start);
|
||||||
|
if ($startepoch === false) {
|
||||||
|
returnToSender("invalid_time");
|
||||||
|
}
|
||||||
|
$startformatted = date("H:i:s", $startepoch);
|
||||||
|
|
||||||
|
$endepoch = strtotime($end);
|
||||||
|
if ($endepoch === false) {
|
||||||
|
returnToSender("invalid_time");
|
||||||
|
}
|
||||||
|
$endformatted = date("H:i:s", $endepoch);
|
||||||
|
|
||||||
|
// Parse days into string, validating along the way
|
||||||
|
$daystring = "";
|
||||||
|
foreach ($days as $d) {
|
||||||
|
if (in_array($d, $valid_daycodes)) {
|
||||||
|
if (strpos($daystring, $d) === FALSE) {
|
||||||
|
$daystring .= $d;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_empty($VARS['shiftid'])) {
|
||||||
|
if ($database->has('shifts', ['shiftname' => $name])) {
|
||||||
|
returnToSender("shift_name_used");
|
||||||
|
}
|
||||||
|
$database->insert('shifts', ["shiftname" => $name, "start" => $startformatted, "end" => $endformatted, "days" => $daystring]);
|
||||||
|
returnToSender("shift_added");
|
||||||
|
} else if ($database->has('shifts', ['shiftid' => $VARS['shiftid']])) {
|
||||||
|
$database->update('shifts', ["shiftname" => $name, "start" => $startformatted, "end" => $endformatted, "days" => $daystring], ["shiftid" => $VARS['shiftid']]);
|
||||||
|
returnToSender("shift_saved");
|
||||||
|
} else {
|
||||||
|
returnToSender("invalid_shiftid");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
returnToSender("no_permission");
|
||||||
|
}
|
||||||
case "signout":
|
case "signout":
|
||||||
session_destroy();
|
session_destroy();
|
||||||
header('Location: index.php');
|
header('Location: index.php');
|
||||||
|
@ -6,6 +6,7 @@ define("STRINGS", [
|
|||||||
"password" => "Password",
|
"password" => "Password",
|
||||||
"continue" => "Continue",
|
"continue" => "Continue",
|
||||||
"no permission" => "You do not have permission to access this system.",
|
"no permission" => "You do not have permission to access this system.",
|
||||||
|
"missing permission" => "You do not have permission to do that.",
|
||||||
"authcode" => "Authentication code",
|
"authcode" => "Authentication code",
|
||||||
"2fa prompt" => "Enter the six-digit code from your mobile authenticator app.",
|
"2fa prompt" => "Enter the six-digit code from your mobile authenticator app.",
|
||||||
"2fa incorrect" => "Authentication code incorrect.",
|
"2fa incorrect" => "Authentication code incorrect.",
|
||||||
@ -58,5 +59,12 @@ define("STRINGS", [
|
|||||||
"thursday" => "Thursday",
|
"thursday" => "Thursday",
|
||||||
"friday" => "Friday",
|
"friday" => "Friday",
|
||||||
"saturday" => "Saturday",
|
"saturday" => "Saturday",
|
||||||
"show all shifts" => "Show all shifts"
|
"show all shifts" => "Show all shifts",
|
||||||
|
"new shift" => "New Shift",
|
||||||
|
"edit shift" => "Edit Shift",
|
||||||
|
"shift added" => "Shift added.",
|
||||||
|
"shift saved" => "Shift saved.",
|
||||||
|
"invalid time format" => "Invalid time format. Please use HH:MM or HH:MM AM.",
|
||||||
|
"shift name used" => "The shift name you gave is already in use. Use a different name or edit the existing shift.",
|
||||||
|
"invalid shiftid" => "Invalid shift ID."
|
||||||
]);
|
]);
|
@ -28,5 +28,29 @@ define("MESSAGES", [
|
|||||||
"punched_out" => [
|
"punched_out" => [
|
||||||
"string" => "punched out",
|
"string" => "punched out",
|
||||||
"type" => "success"
|
"type" => "success"
|
||||||
|
],
|
||||||
|
"no_permission" => [
|
||||||
|
"string" => "missing permission",
|
||||||
|
"type" => "danger"
|
||||||
|
],
|
||||||
|
"shift_added" => [
|
||||||
|
"string" => "shift added",
|
||||||
|
"type" => "success"
|
||||||
|
],
|
||||||
|
"invalid_time" => [
|
||||||
|
"string" => "invalid time format",
|
||||||
|
"type" => "danger"
|
||||||
|
],
|
||||||
|
"shift_saved" => [
|
||||||
|
"string" => "shift saved",
|
||||||
|
"type" => "success"
|
||||||
|
],
|
||||||
|
"shift_name_used" => [
|
||||||
|
"string" => "shift name used",
|
||||||
|
"type" => "danger"
|
||||||
|
],
|
||||||
|
"invalid_shiftid" => [
|
||||||
|
"string" => "invalid shiftid",
|
||||||
|
"type" => "danger"
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
|
@ -98,11 +98,18 @@ if ($showall) {
|
|||||||
], $where);
|
], $where);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$showeditbtn = account_has_permission($_SESSION['username'], "QWIKCLOCK_MANAGE");
|
||||||
|
|
||||||
for ($i = 0; $i < count($shifts); $i++) {
|
for ($i = 0; $i < count($shifts); $i++) {
|
||||||
$shifts[$i][0] = "";
|
$shifts[$i][0] = "";
|
||||||
$shifts[$i][1] = $shifts[$i]['shiftname'];
|
if ($showeditbtn) {
|
||||||
$shifts[$i][2] = date(TIME_FORMAT, strtotime($shifts[$i]['start']));
|
$shifts[$i][1] = '<a class="btn btn-blue btn-xs" href="app.php?page=editshift&id=' . $shifts[$i]['shiftid'] . '"><i class="fa fa-pencil-square-o"></i> ' . lang("edit", false) . '</a>';
|
||||||
$shifts[$i][3] = date(TIME_FORMAT, strtotime($shifts[$i]['end']));
|
} else {
|
||||||
|
$shifts[$i][1] = "";
|
||||||
|
}
|
||||||
|
$shifts[$i][2] = $shifts[$i]['shiftname'];
|
||||||
|
$shifts[$i][3] = date(TIME_FORMAT, strtotime($shifts[$i]['start']));
|
||||||
|
$shifts[$i][4] = date(TIME_FORMAT, strtotime($shifts[$i]['end']));
|
||||||
$days = [];
|
$days = [];
|
||||||
$daycodes = str_split($shifts[$i]['days'], 2);
|
$daycodes = str_split($shifts[$i]['days'], 2);
|
||||||
foreach ($daycodes as $day) {
|
foreach ($daycodes as $day) {
|
||||||
@ -130,7 +137,7 @@ for ($i = 0; $i < count($shifts); $i++) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$shifts[$i][4] = "<span style=\"word-wrap: break-word;\">" . implode(", ", $days) . "</span>";
|
$shifts[$i][5] = "<span style=\"word-wrap: break-word;\">" . implode(", ", $days) . "</span>";
|
||||||
}
|
}
|
||||||
|
|
||||||
$out['status'] = "OK";
|
$out['status'] = "OK";
|
||||||
@ -143,6 +150,7 @@ if ($filter) {
|
|||||||
} else {
|
} else {
|
||||||
$recordsFiltered = $out['recordsTotal'];
|
$recordsFiltered = $out['recordsTotal'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$out['recordsFiltered'] = $recordsFiltered;
|
$out['recordsFiltered'] = $recordsFiltered;
|
||||||
$out['data'] = $shifts;
|
$out['data'] = $shifts;
|
||||||
|
|
||||||
|
12
pages.php
12
pages.php
@ -39,4 +39,16 @@ define("PAGES", [
|
|||||||
"static/js/shifts.js"
|
"static/js/shifts.js"
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
"editshift" => [
|
||||||
|
"title" => "new shift",
|
||||||
|
"navbar" => false,
|
||||||
|
"styles" => [
|
||||||
|
"static/css/bootstrap-datetimepicker.min.css"
|
||||||
|
],
|
||||||
|
"scripts" => [
|
||||||
|
"static/js/moment.min.js",
|
||||||
|
"static/js/bootstrap-datetimepicker.min.js",
|
||||||
|
"static/js/addshift.js"
|
||||||
|
]
|
||||||
|
],
|
||||||
]);
|
]);
|
||||||
|
116
pages/editshift.php
Normal file
116
pages/editshift.php
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__ . '/../required.php';
|
||||||
|
|
||||||
|
redirectifnotloggedin();
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
"shiftid" => "",
|
||||||
|
"shiftname" => "",
|
||||||
|
"start" => "",
|
||||||
|
"end" => "",
|
||||||
|
"days" => ""
|
||||||
|
];
|
||||||
|
|
||||||
|
$editing = false;
|
||||||
|
if (isset($VARS['id']) && $database->has('shifts', ['shiftid' => $VARS['id']])) {
|
||||||
|
$editing = true;
|
||||||
|
|
||||||
|
$data = $database->get('shifts', [
|
||||||
|
"shiftid",
|
||||||
|
"shiftname",
|
||||||
|
"start",
|
||||||
|
"end",
|
||||||
|
"days"
|
||||||
|
], [
|
||||||
|
'shiftid' => $VARS['id']
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<form role="form" action="action.php" method="POST">
|
||||||
|
<div class="panel panel-blue">
|
||||||
|
<div class="panel-heading">
|
||||||
|
<h3 class="panel-title">
|
||||||
|
<?php if ($editing) { ?>
|
||||||
|
<i class="fa fa-calendar-o"></i> <?php lang("edit shift"); ?>
|
||||||
|
<?php } else { ?>
|
||||||
|
<i class="fa fa-calendar-plus-o"></i> <?php lang("new shift"); ?>
|
||||||
|
<?php } ?>
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-12 col-md-6">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="shiftname"><i class="fa fa-font"></i> <?php lang("name"); ?></label>
|
||||||
|
<input type="text" class="form-control" name="shiftname" id="shiftname" required="required" value="<?php echo $data['shiftname']; ?>" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-xs-12 col-md-6">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="start"><i class="fa fa-play"></i> <?php lang("start"); ?></label>
|
||||||
|
<input type="text" class="form-control" name="start" id="start" required="required" value="<?php echo $data['start']; ?>" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-xs-12 col-md-6">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="end"><i class="fa fa-stop"></i> <?php lang("end"); ?></label>
|
||||||
|
<input type="text" class="form-control" name="end" id="end" required="required" value="<?php echo $data['end']; ?>" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-xs-12 col-md-6">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="days"><i class="fa fa-calendar"></i> <?php lang("days"); ?></label>
|
||||||
|
<div style="padding-top: 8px;">
|
||||||
|
<div style="display: flex; flex-wrap: wrap; justify-content: space-between;">
|
||||||
|
<div class="checkbox" style="margin-top: -6px;">
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" name="days[]" value="Su" <?php if (strpos($data['days'], "Su") !== FALSE) echo "checked"; ?>> <?php lang('sunday'); ?>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="checkbox">
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" name="days[]" value="Mo" <?php if (strpos($data['days'], "Mo") !== FALSE) echo "checked"; ?>> <?php lang('monday'); ?>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="checkbox">
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" name="days[]" value="Tu" <?php if (strpos($data['days'], "Tu") !== FALSE) echo "checked"; ?>> <?php lang('tuesday'); ?>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="checkbox">
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" name="days[]" value="We" <?php if (strpos($data['days'], "We") !== FALSE) echo "checked"; ?>> <?php lang('wednesday'); ?>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="checkbox">
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" name="days[]" value="Th" <?php if (strpos($data['days'], "Th") !== FALSE) echo "checked"; ?>> <?php lang('thursday'); ?>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="checkbox">
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" name="days[]" value="Fr" <?php if (strpos($data['days'], "Fr") !== FALSE) echo "checked"; ?>> <?php lang('friday'); ?>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="checkbox">
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" name="days[]" value="Sa" <?php if (strpos($data['days'], "Sa") !== FALSE) echo "checked"; ?>> <?php lang('saturday'); ?>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<input type="hidden" name="shiftid" value="<?php echo $data['shiftid']; ?>" />
|
||||||
|
<input type="hidden" name="action" value="editshift" />
|
||||||
|
<input type="hidden" name="source" value="shifts" />
|
||||||
|
|
||||||
|
<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>
|
@ -16,10 +16,20 @@ $totalpunches = count($punches);
|
|||||||
?>
|
?>
|
||||||
|
|
||||||
<p class="page-header h5"><i class="fa fa-clock-o fa-fw"></i> <?php lang("shifts") ?></p>
|
<p class="page-header h5"><i class="fa fa-clock-o fa-fw"></i> <?php lang("shifts") ?></p>
|
||||||
|
<?php
|
||||||
|
if (account_has_permission($_SESSION['username'], "QWIKCLOCK_MANAGE")) {
|
||||||
|
?>
|
||||||
|
<div class="btn-group" style="margin-bottom: 10px;">
|
||||||
|
<a href="app.php?page=editshift" class="btn btn-success"><i class="fa fa-calendar-plus-o"></i> <?php lang("new shift"); ?></a>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
<table id="shifttable" class="table table-bordered table-striped">
|
<table id="shifttable" class="table table-bordered table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th data-priority="0"></th>
|
<th data-priority="0"></th>
|
||||||
|
<th data-priority="3"></th>
|
||||||
<th data-priority="3"><i class="fa fa-fw fa-font hidden-xs"></i> <?php lang('name'); ?></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-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="1"><i class="fa fa-fw fa-stop hidden-xs"></i> <?php lang('end'); ?></th>
|
||||||
@ -32,6 +42,7 @@ $totalpunches = count($punches);
|
|||||||
<tfoot>
|
<tfoot>
|
||||||
<tr>
|
<tr>
|
||||||
<th data-priority="0"></th>
|
<th data-priority="0"></th>
|
||||||
|
<th data-priority="3"></th>
|
||||||
<th data-priority="3"><i class="fa fa-fw fa-font hidden-xs"></i> <?php lang('name'); ?></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-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="1"><i class="fa fa-fw fa-stop hidden-xs"></i> <?php lang('end'); ?></th>
|
||||||
|
@ -152,7 +152,7 @@ function checkDBError($specials = []) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* http://stackoverflow.com/a/20075147/2534036
|
* http://stackoverflow.com/a/20075147
|
||||||
*/
|
*/
|
||||||
if (!function_exists('base_url')) {
|
if (!function_exists('base_url')) {
|
||||||
|
|
||||||
|
5
static/css/bootstrap-datetimepicker.min.css
vendored
Normal file
5
static/css/bootstrap-datetimepicker.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
10
static/js/addshift.js
Normal file
10
static/js/addshift.js
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
$(function () {
|
||||||
|
$('#start').datetimepicker({
|
||||||
|
format: 'LT',
|
||||||
|
useCurrent: false
|
||||||
|
});
|
||||||
|
$('#end').datetimepicker({
|
||||||
|
format: 'LT',
|
||||||
|
useCurrent: false
|
||||||
|
});
|
||||||
|
});
|
2
static/js/bootstrap-datetimepicker.min.js
vendored
Normal file
2
static/js/bootstrap-datetimepicker.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
7
static/js/moment.min.js
vendored
Normal file
7
static/js/moment.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@ -20,7 +20,11 @@ var shifttable = $('#shifttable').DataTable({
|
|||||||
orderable: false
|
orderable: false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
targets: 4,
|
targets: 1,
|
||||||
|
orderable: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
targets: 5,
|
||||||
orderable: false
|
orderable: false
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user