Add shift assignment tool
parent
a3368546f2
commit
3c71ed88c9
@ -0,0 +1,88 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__ . '/../required.php';
|
||||||
|
|
||||||
|
redirectifnotloggedin();
|
||||||
|
|
||||||
|
$shifts = $database->select('shifts', [
|
||||||
|
"shiftid",
|
||||||
|
"shiftname",
|
||||||
|
"start",
|
||||||
|
"end"]
|
||||||
|
);
|
||||||
|
$assigned = [];
|
||||||
|
require_once __DIR__ . "/../lib/userinfo.php";
|
||||||
|
$shift = false;
|
||||||
|
if ($VARS['shift'] && $database->has('shifts', ['shiftid' => $VARS['shift']])) {
|
||||||
|
$shift = $VARS['shift'];
|
||||||
|
$uids = $database->select('assigned_shifts', 'uid', ['shiftid' => $shift]);
|
||||||
|
foreach ($uids as $uid) {
|
||||||
|
$assigned[] = getUserByID($uid)['username'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<form role="form" action="action.php" method="POST">
|
||||||
|
<div class="panel panel-blue">
|
||||||
|
<div class="panel-heading">
|
||||||
|
<h3 class="panel-title">
|
||||||
|
<i class="fa fa-calendar-o"></i> <?php lang("assign shift"); ?>
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-12 col-md-6">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="shift"><i class="fa fa-font"></i> <?php lang("shift"); ?></label><br />
|
||||||
|
<select name="shift" required="required" class="form-control" id="shift-select">
|
||||||
|
<option value="" selected><?php lang("choose a shift"); ?></option>
|
||||||
|
<?php
|
||||||
|
foreach ($shifts as $s) {
|
||||||
|
$str = $s['shiftname'] . " (" . date(TIME_FORMAT, strtotime($s['start'])) . " - " . date(TIME_FORMAT, strtotime($s['end'])) . ")";
|
||||||
|
$val = $s['shiftid'];
|
||||||
|
?>
|
||||||
|
<option value="<?php echo $val; ?>"<?php if ($val === $shift) { ?> selected<?php } ?>><?php echo $str; ?></option>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
if ($shift !== false) {
|
||||||
|
?>
|
||||||
|
<div class="col-xs-12 col-md-6">
|
||||||
|
<label for="people-box"><i class="fa fa-user"></i> <?php lang("people"); ?></label><br />
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-8 col-sm-10 col-md-9 col-lg-10">
|
||||||
|
<input type="text" id="people-box" class="form-control" placeholder="<?php lang("type to add a person") ?>" />
|
||||||
|
</div>
|
||||||
|
<div class="col-xs-4 col-sm-2 col-md-3 col-lg-2">
|
||||||
|
<button class="btn btn-default" type="button" id="addpersonbtn"><i class="fa fa-plus"></i> <?php lang("add") ?></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="list-group" id="peoplelist">
|
||||||
|
<?php
|
||||||
|
foreach ($assigned as $user) {
|
||||||
|
?>
|
||||||
|
<div class="list-group-item" data-user="<?php echo $user; ?>">
|
||||||
|
<?php echo $user; ?> <div onclick="removePerson('<?php echo $user; ?>')" class="btn btn-danger btn-sm pull-right"><i class="fa fa-trash-o"></i></div><input type="hidden" name="users[]" value="<?php echo $user; ?>" />
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<input type="hidden" name="action" value="assignshift" />
|
||||||
|
<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>
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,76 @@
|
|||||||
|
var options = {
|
||||||
|
url: "action.php",
|
||||||
|
ajaxSettings: {
|
||||||
|
dataType: "json",
|
||||||
|
method: "GET",
|
||||||
|
data: {
|
||||||
|
action: "autocomplete_user"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
preparePostData: function (data) {
|
||||||
|
data.q = $("#people-box").val();
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
getValue: function (element) {
|
||||||
|
return element.username;
|
||||||
|
},
|
||||||
|
template: {
|
||||||
|
type: "custom",
|
||||||
|
method: function (value, item) {
|
||||||
|
return item.name + " <i class=\"small\">" + item.username + "</i>";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
list: {
|
||||||
|
onClickEvent: function () {
|
||||||
|
var value = $("#people-box").getSelectedItemData().username;
|
||||||
|
addPerson(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
$("#people-box").easyAutocomplete(options);
|
||||||
|
|
||||||
|
$("#people-box").keyup(function (event) {
|
||||||
|
if (event.keyCode == 13) {
|
||||||
|
$("#addpersonbtn").click();
|
||||||
|
event.preventDefault();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$("#people-box").keydown(function (event) {
|
||||||
|
if (event.keyCode == 13) {
|
||||||
|
event.preventDefault();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#addpersonbtn").click(function () {
|
||||||
|
addPerson($("#people-box").val());
|
||||||
|
});
|
||||||
|
|
||||||
|
function addPerson(p) {
|
||||||
|
p = String.trim(p);
|
||||||
|
if (p == "") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ($("#peoplelist div[data-user=" + p + "]").length) {
|
||||||
|
$("#peoplelist .list-group-item[data-user=" + p + "]").animate({
|
||||||
|
backgroundColor: "#ff0000",
|
||||||
|
}, 500, "linear", function () {
|
||||||
|
$("#peoplelist .list-group-item[data-user=" + p + "]").animate({
|
||||||
|
backgroundColor: "#ffffff",
|
||||||
|
}, 500);
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$('#peoplelist').append("<div class=\"list-group-item\" data-user=\"" + p + "\">" + p + "<div onclick=\"removePerson('" + p + "')\" class=\"btn btn-danger btn-sm pull-right\"><i class=\"fa fa-trash-o\"></i></div><input type=\"hidden\" name=\"users[]\" value=\"" + p + "\" /></div>");
|
||||||
|
$("#people-box").val("");
|
||||||
|
}
|
||||||
|
|
||||||
|
function removePerson(p) {
|
||||||
|
$("#peoplelist div[data-user=" + p + "]").remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#shift-select').on('change', function(){
|
||||||
|
document.location.href = "app.php?page=assignshift&shift=" + $(this).val();
|
||||||
|
});
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue