2014-12-22 17:55:20 +01:00
|
|
|
<?php
|
2016-10-05 18:56:50 +02:00
|
|
|
use Engelsystem\ShiftsFilterRenderer;
|
|
|
|
use Engelsystem\ShiftsFilter;
|
2016-10-05 22:28:39 +02:00
|
|
|
use Engelsystem\ShiftCalendarRenderer;
|
2016-10-05 18:56:50 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Room controllers for managing everything room related.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* View a room with its shifts.
|
|
|
|
*/
|
|
|
|
function room_controller() {
|
2016-12-28 12:11:35 +01:00
|
|
|
global $privileges;
|
2016-10-05 18:56:50 +02:00
|
|
|
|
|
|
|
if (! in_array('view_rooms', $privileges)) {
|
|
|
|
redirect(page_link_to());
|
|
|
|
}
|
2017-04-11 17:25:34 +02:00
|
|
|
|
|
|
|
|
2016-10-05 18:56:50 +02:00
|
|
|
$room = load_room();
|
2017-04-11 17:25:34 +02:00
|
|
|
|
|
|
|
if($room['show'] != 'Y' && !in_array('admin_rooms', $privileges)) {
|
|
|
|
redirect(page_link_to());
|
|
|
|
}
|
|
|
|
|
2016-10-05 18:56:50 +02:00
|
|
|
$all_shifts = Shifts_by_room($room);
|
|
|
|
$days = [];
|
|
|
|
foreach ($all_shifts as $shift) {
|
|
|
|
$day = date("Y-m-d", $shift['start']);
|
|
|
|
if (! in_array($day, $days)) {
|
|
|
|
$days[] = $day;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-05 22:28:39 +02:00
|
|
|
$shiftsFilter = new ShiftsFilter(true, [
|
2016-10-05 18:56:50 +02:00
|
|
|
$room['RID']
|
2016-10-05 22:28:39 +02:00
|
|
|
], AngelType_ids());
|
|
|
|
$selected_day = date("Y-m-d");
|
|
|
|
if (! empty($days)) {
|
|
|
|
$selected_day = $days[0];
|
|
|
|
}
|
|
|
|
if (isset($_REQUEST['shifts_filter_day'])) {
|
|
|
|
$selected_day = $_REQUEST['shifts_filter_day'];
|
|
|
|
}
|
|
|
|
$shiftsFilter->setStartTime(parse_date("Y-m-d H:i", $selected_day . ' 00:00'));
|
|
|
|
$shiftsFilter->setEndTime(parse_date("Y-m-d H:i", $selected_day . ' 23:59'));
|
2016-10-05 18:56:50 +02:00
|
|
|
|
|
|
|
$shiftsFilterRenderer = new ShiftsFilterRenderer($shiftsFilter);
|
2016-10-05 22:28:39 +02:00
|
|
|
$shiftsFilterRenderer->enableDaySelection($days);
|
|
|
|
|
2016-12-28 14:53:35 +01:00
|
|
|
$shiftCalendarRenderer = shiftCalendarRendererByShiftFilter($shiftsFilter);
|
2016-10-05 18:56:50 +02:00
|
|
|
|
|
|
|
return [
|
|
|
|
$room['Name'],
|
2016-12-28 14:53:35 +01:00
|
|
|
Room_view($room, $shiftsFilterRenderer, $shiftCalendarRenderer)
|
2016-10-05 18:56:50 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dispatch different room actions.
|
|
|
|
*/
|
|
|
|
function rooms_controller() {
|
|
|
|
if (! isset($_REQUEST['action'])) {
|
|
|
|
$_REQUEST['action'] = 'list';
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ($_REQUEST['action']) {
|
|
|
|
default:
|
|
|
|
case 'list':
|
|
|
|
redirect(page_link_to('admin_rooms'));
|
|
|
|
case 'view':
|
|
|
|
return room_controller();
|
|
|
|
}
|
|
|
|
}
|
2014-12-22 17:55:20 +01:00
|
|
|
|
|
|
|
function room_link($room) {
|
2016-10-05 18:56:50 +02:00
|
|
|
return page_link_to('rooms') . '&action=view&room_id=' . $room['RID'];
|
|
|
|
}
|
|
|
|
|
|
|
|
function room_edit_link($room) {
|
2014-12-22 17:55:20 +01:00
|
|
|
return page_link_to('admin_rooms') . '&show=edit&id=' . $room['RID'];
|
|
|
|
}
|
|
|
|
|
2016-10-05 18:56:50 +02:00
|
|
|
/**
|
|
|
|
* Loads room by request param room_id
|
|
|
|
*/
|
|
|
|
function load_room() {
|
|
|
|
if (! test_request_int('room_id')) {
|
|
|
|
redirect(page_link_to());
|
|
|
|
}
|
|
|
|
|
|
|
|
$room = Room($_REQUEST['room_id']);
|
|
|
|
if ($room == null) {
|
|
|
|
redirect(page_link_to());
|
|
|
|
}
|
|
|
|
|
|
|
|
return $room;
|
|
|
|
}
|
|
|
|
|
2014-12-22 17:55:20 +01:00
|
|
|
?>
|