Merge pull request #274 from engelsystem/task-164-shift-view

Task 164 shift view
main
msquare 8 years ago committed by GitHub
commit d43eb41d25

@ -0,0 +1,2 @@
INSERT INTO `Privileges` (`id`, `name`, `desc`) VALUES (40, 'view_rooms', 'User can view rooms');
INSERT INTO `GroupPrivileges` (`id`, `group_id`, `privilege_id`) VALUES (NULL, '-2', '40');

@ -50,9 +50,6 @@ function angeltypes_about_controller() {
} else { } else {
$angeltypes = AngelTypes(); $angeltypes = AngelTypes();
} }
if ($angeltypes === false) {
engelsystem_error("Unable to load angeltypes.");
}
return [ return [
_("Teams/Job description"), _("Teams/Job description"),
@ -71,9 +68,6 @@ function angeltype_delete_controller() {
} }
$angeltype = AngelType($_REQUEST['angeltype_id']); $angeltype = AngelType($_REQUEST['angeltype_id']);
if ($angeltype === false) {
engelsystem_error("Unable to load angeltype.");
}
if ($angeltype == null) { if ($angeltype == null) {
redirect(page_link_to('angeltypes')); redirect(page_link_to('angeltypes'));
} }
@ -109,9 +103,6 @@ function angeltype_edit_controller() {
if (isset($_REQUEST['angeltype_id'])) { if (isset($_REQUEST['angeltype_id'])) {
$angeltype = AngelType($_REQUEST['angeltype_id']); $angeltype = AngelType($_REQUEST['angeltype_id']);
if ($angeltype === false) {
engelsystem_error("Unable to load angeltype.");
}
if ($angeltype == null) { if ($angeltype == null) {
redirect(page_link_to('angeltypes')); redirect(page_link_to('angeltypes'));
} }
@ -196,17 +187,11 @@ function angeltype_controller() {
} }
$angeltype = AngelType($_REQUEST['angeltype_id']); $angeltype = AngelType($_REQUEST['angeltype_id']);
if ($angeltype === false) {
engelsystem_error("Unable to load angeltype.");
}
if ($angeltype == null) { if ($angeltype == null) {
redirect(page_link_to('angeltypes')); redirect(page_link_to('angeltypes'));
} }
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype); $user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
if ($user_angeltype === false) {
engelsystem_error("Unable to load user angeltype.");
}
$user_driver_license = UserDriverLicense($user['UID']); $user_driver_license = UserDriverLicense($user['UID']);
if ($user_driver_license === false) { if ($user_driver_license === false) {
@ -235,9 +220,6 @@ function angeltypes_list_controller() {
} }
$angeltypes = AngelTypes_with_user($user); $angeltypes = AngelTypes_with_user($user);
if ($angeltypes === false) {
engelsystem_error("Unable to load angeltypes.");
}
foreach ($angeltypes as &$angeltype) { foreach ($angeltypes as &$angeltype) {
$actions = [ $actions = [
@ -277,9 +259,6 @@ function load_angeltype() {
} }
$angeltype = AngelType($_REQUEST['angeltype_id']); $angeltype = AngelType($_REQUEST['angeltype_id']);
if ($angeltype === false) {
engelsystem_error("Unable to load angeltype.");
}
if ($angeltype == null) { if ($angeltype == null) {
error(_("Angeltype doesn't exist.")); error(_("Angeltype doesn't exist."));
redirect(page_link_to('angeltypes')); redirect(page_link_to('angeltypes'));

@ -1,7 +1,95 @@
<?php <?php
use Engelsystem\ShiftsFilterRenderer;
use Engelsystem\ShiftsFilter;
use Engelsystem\ShiftCalendarRenderer;
/**
* Room controllers for managing everything room related.
*/
/**
* View a room with its shifts.
*/
function room_controller() {
global $privileges, $user;
if (! in_array('view_rooms', $privileges)) {
redirect(page_link_to());
}
$room = load_room();
$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;
}
}
$shiftsFilter = new ShiftsFilter(true, [
$room['RID']
], 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'));
$shiftsFilterRenderer = new ShiftsFilterRenderer($shiftsFilter);
$shiftsFilterRenderer->enableDaySelection($days);
$shifts = Shifts_by_ShiftsFilter($shiftsFilter, $user);
return [
$room['Name'],
Room_view($room, $shiftsFilterRenderer, new ShiftCalendarRenderer($shifts, $shiftsFilter))
];
}
/**
* 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();
}
}
function room_link($room) { function room_link($room) {
return page_link_to('rooms') . '&action=view&room_id=' . $room['RID'];
}
function room_edit_link($room) {
return page_link_to('admin_rooms') . '&show=edit&id=' . $room['RID']; return page_link_to('admin_rooms') . '&show=edit&id=' . $room['RID'];
} }
/**
* 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;
}
?> ?>

@ -0,0 +1,167 @@
<?php
/**
* Sign up for a shift.
*/
function shift_entry_add_controller() {
global $privileges, $user;
if (isset($_REQUEST['shift_id']) && preg_match("/^[0-9]*$/", $_REQUEST['shift_id'])) {
$shift_id = $_REQUEST['shift_id'];
} else {
redirect(page_link_to('user_shifts'));
}
// Locations laden
$rooms = sql_select("SELECT * FROM `Room` WHERE `show`='Y' ORDER BY `Name`");
$room_array = [];
foreach ($rooms as $room) {
$room_array[$room['RID']] = $room['Name'];
}
$shift = Shift($shift_id);
$shift['Name'] = $room_array[$shift['RID']];
if ($shift == null) {
redirect(page_link_to('user_shifts'));
}
if (isset($_REQUEST['type_id']) && preg_match("/^[0-9]*$/", $_REQUEST['type_id'])) {
$type_id = $_REQUEST['type_id'];
} else {
redirect(page_link_to('user_shifts'));
}
if (in_array('user_shifts_admin', $privileges)) {
$type = sql_select("SELECT * FROM `AngelTypes` WHERE `id`='" . sql_escape($type_id) . "' LIMIT 1");
} else {
$type = sql_select("SELECT * FROM `UserAngelTypes` JOIN `AngelTypes` ON (`UserAngelTypes`.`angeltype_id` = `AngelTypes`.`id`) WHERE `AngelTypes`.`id` = '" . sql_escape($type_id) . "' AND (`AngelTypes`.`restricted` = 0 OR (`UserAngelTypes`.`user_id` = '" . sql_escape($user['UID']) . "' AND NOT `UserAngelTypes`.`confirm_user_id` IS NULL)) LIMIT 1");
}
if (count($type) == 0) {
redirect(page_link_to('user_shifts'));
}
$type = $type[0];
if (! Shift_signup_allowed($shift, $type)) {
error(_('You are not allowed to sign up for this shift. Maybe shift is full or already running.'));
redirect(shift_link($shift));
}
if (isset($_REQUEST['submit'])) {
$selected_type_id = $type_id;
if (in_array('user_shifts_admin', $privileges)) {
if (isset($_REQUEST['user_id']) && preg_match("/^[0-9]*$/", $_REQUEST['user_id'])) {
$user_id = $_REQUEST['user_id'];
} else {
$user_id = $user['UID'];
}
if (sql_num_query("SELECT * FROM `User` WHERE `UID`='" . sql_escape($user_id) . "' LIMIT 1") == 0) {
redirect(page_link_to('user_shifts'));
}
if (isset($_REQUEST['angeltype_id']) && test_request_int('angeltype_id') && sql_num_query("SELECT * FROM `AngelTypes` WHERE `id`='" . sql_escape($_REQUEST['angeltype_id']) . "' LIMIT 1") > 0) {
$selected_type_id = $_REQUEST['angeltype_id'];
}
} else {
$user_id = $user['UID'];
}
if (sql_num_query("SELECT * FROM `ShiftEntry` WHERE `SID`='" . sql_escape($shift['SID']) . "' AND `UID` = '" . sql_escape($user_id) . "'")) {
return error("This angel does already have an entry for this shift.", true);
}
$freeloaded = $shift['freeloaded'];
$freeload_comment = $shift['freeload_comment'];
if (in_array("user_shifts_admin", $privileges)) {
$freeloaded = isset($_REQUEST['freeloaded']);
$freeload_comment = strip_request_item_nl('freeload_comment');
}
$comment = strip_request_item_nl('comment');
$result = ShiftEntry_create([
'SID' => $shift_id,
'TID' => $selected_type_id,
'UID' => $user_id,
'Comment' => $comment,
'freeloaded' => $freeloaded,
'freeload_comment' => $freeload_comment
]);
if ($result === false) {
engelsystem_error('Unable to create shift entry.');
}
if ($type['restricted'] == 0 && sql_num_query("SELECT * FROM `UserAngelTypes` INNER JOIN `AngelTypes` ON `AngelTypes`.`id` = `UserAngelTypes`.`angeltype_id` WHERE `angeltype_id` = '" . sql_escape($selected_type_id) . "' AND `user_id` = '" . sql_escape($user_id) . "' ") == 0) {
sql_query("INSERT INTO `UserAngelTypes` (`user_id`, `angeltype_id`) VALUES ('" . sql_escape($user_id) . "', '" . sql_escape($selected_type_id) . "')");
}
$user_source = User($user_id);
engelsystem_log("User " . User_Nick_render($user_source) . " signed up for shift " . $shift['name'] . " from " . date("Y-m-d H:i", $shift['start']) . " to " . date("Y-m-d H:i", $shift['end']));
success(_("You are subscribed. Thank you!") . ' <a href="' . page_link_to('user_myshifts') . '">' . _("My shifts") . ' &raquo;</a>');
redirect(shift_link($shift));
}
if (in_array('user_shifts_admin', $privileges)) {
$users = sql_select("SELECT *, (SELECT count(*) FROM `ShiftEntry` WHERE `freeloaded`=1 AND `ShiftEntry`.`UID`=`User`.`UID`) AS `freeloaded` FROM `User` ORDER BY `Nick`");
$users_select = [];
foreach ($users as $usr) {
$users_select[$usr['UID']] = $usr['Nick'] . ($usr['freeloaded'] == 0 ? "" : " (" . _("Freeloader") . ")");
}
$user_text = html_select_key('user_id', 'user_id', $users_select, $user['UID']);
$angeltypes_source = sql_select("SELECT * FROM `AngelTypes` ORDER BY `name`");
$angeltypes = [];
foreach ($angeltypes_source as $angeltype) {
$angeltypes[$angeltype['id']] = $angeltype['name'];
}
$angeltype_select = html_select_key('angeltype_id', 'angeltype_id', $angeltypes, $type['id']);
} else {
$user_text = User_Nick_render($user);
$angeltype_select = $type['name'];
}
return ShiftEntry_edit_view($user_text, date("Y-m-d H:i", $shift['start']) . ' &ndash; ' . date('Y-m-d H:i', $shift['end']) . ' (' . shift_length($shift) . ')', $shift['Name'], $shift['name'], $angeltype_select, "", false, null, in_array('user_shifts_admin', $privileges));
}
/**
* Remove somebody from a shift.
*/
function shift_entry_delete_controller() {
global $privileges;
if (! in_array('user_shifts_admin', $privileges)) {
redirect(page_link_to('user_shifts'));
}
if (! isset($_REQUEST['entry_id']) || ! test_request_int('entry_id')) {
redirect(page_link_to('user_shifts'));
}
$entry_id = $_REQUEST['entry_id'];
$shift_entry_source = sql_select("
SELECT `User`.`Nick`, `ShiftEntry`.`Comment`, `ShiftEntry`.`UID`, `ShiftTypes`.`name`, `Shifts`.*, `Room`.`Name`, `AngelTypes`.`name` as `angel_type`
FROM `ShiftEntry`
JOIN `User` ON (`User`.`UID`=`ShiftEntry`.`UID`)
JOIN `AngelTypes` ON (`ShiftEntry`.`TID` = `AngelTypes`.`id`)
JOIN `Shifts` ON (`ShiftEntry`.`SID` = `Shifts`.`SID`)
JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`)
JOIN `Room` ON (`Shifts`.`RID` = `Room`.`RID`)
WHERE `ShiftEntry`.`id`='" . sql_escape($entry_id) . "'");
if (count($shift_entry_source) > 0) {
$shift_entry_source = $shift_entry_source[0];
$result = ShiftEntry_delete($entry_id);
if ($result === false) {
engelsystem_error('Unable to delete shift entry.');
}
engelsystem_log("Deleted " . User_Nick_render($shift_entry_source) . "'s shift: " . $shift_entry_source['name'] . " at " . $shift_entry_source['Name'] . " from " . date("Y-m-d H:i", $shift_entry_source['start']) . " to " . date("Y-m-d H:i", $shift_entry_source['end']) . " as " . $shift_entry_source['angel_type']);
success(_("Shift entry deleted."));
} else {
error(_("Entry not found."));
}
redirect(page_link_to('user_shifts'));
}
?>

@ -12,6 +12,172 @@ function shift_edit_link($shift) {
return page_link_to('user_shifts') . '&edit_shift=' . $shift['SID']; return page_link_to('user_shifts') . '&edit_shift=' . $shift['SID'];
} }
/**
* Edit a single shift.
*/
function shift_edit_controller() {
global $privileges;
// Schicht bearbeiten
$msg = "";
$valid = true;
if (! in_array('admin_shifts', $privileges)) {
redirect(page_link_to('user_shifts'));
}
if (! isset($_REQUEST['edit_shift']) || ! test_request_int('edit_shift')) {
redirect(page_link_to('user_shifts'));
}
$shift_id = $_REQUEST['edit_shift'];
$shift = Shift($shift_id);
$room = select_array(Rooms(), 'RID', 'Name');
$angeltypes = select_array(AngelTypes(), 'id', 'name');
$shifttypes = select_array(ShiftTypes(), 'id', 'name');
$needed_angel_types = select_array(NeededAngelTypes_by_shift($shift_id), 'id', 'count');
foreach (array_keys($angeltypes) as $angeltype_id) {
if (! isset($needed_angel_types[$angeltype_id])) {
$needed_angel_types[$angeltype_id] = 0;
}
}
$shifttype_id = $shift['shifttype_id'];
$title = $shift['title'];
$rid = $shift['RID'];
$start = $shift['start'];
$end = $shift['end'];
if (isset($_REQUEST['submit'])) {
// Name/Bezeichnung der Schicht, darf leer sein
$title = strip_request_item('title');
// Auswahl der sichtbaren Locations für die Schichten
if (isset($_REQUEST['rid']) && preg_match("/^[0-9]+$/", $_REQUEST['rid']) && isset($room[$_REQUEST['rid']])) {
$rid = $_REQUEST['rid'];
} else {
$valid = false;
$msg .= error(_("Please select a room."), true);
}
if (isset($_REQUEST['shifttype_id']) && isset($shifttypes[$_REQUEST['shifttype_id']])) {
$shifttype_id = $_REQUEST['shifttype_id'];
} else {
$valid = false;
$msg .= error(_('Please select a shifttype.'), true);
}
if (isset($_REQUEST['start']) && $tmp = parse_date("Y-m-d H:i", $_REQUEST['start'])) {
$start = $tmp;
} else {
$valid = false;
$msg .= error(_("Please enter a valid starting time for the shifts."), true);
}
if (isset($_REQUEST['end']) && $tmp = parse_date("Y-m-d H:i", $_REQUEST['end'])) {
$end = $tmp;
} else {
$valid = false;
$msg .= error(_("Please enter a valid ending time for the shifts."), true);
}
if ($start >= $end) {
$valid = false;
$msg .= error(_("The ending time has to be after the starting time."), true);
}
foreach ($needed_angel_types as $needed_angeltype_id => $needed_angeltype_name) {
if (isset($_REQUEST['type_' . $needed_angeltype_id]) && test_request_int('type_' . $needed_angeltype_id)) {
$needed_angel_types[$needed_angeltype_id] = trim($_REQUEST['type_' . $needed_angeltype_id]);
} else {
$valid = false;
$msg .= error(sprintf(_("Please check your input for needed angels of type %s."), $needed_angeltype_name), true);
}
}
if ($valid) {
$shift['shifttype_id'] = $shifttype_id;
$shift['title'] = $title;
$shift['RID'] = $rid;
$shift['start'] = $start;
$shift['end'] = $end;
$result = Shift_update($shift);
if ($result === false) {
engelsystem_error('Unable to update shift.');
}
NeededAngelTypes_delete_by_shift($shift_id);
$needed_angel_types_info = [];
foreach ($needed_angel_types as $type_id => $count) {
NeededAngelType_add($shift_id, $type_id, null, $count);
$needed_angel_types_info[] = $angeltypes[$type_id] . ": " . $count;
}
engelsystem_log("Updated shift '" . $shifttypes[$shifttype_id] . ", " . $title . "' from " . date("Y-m-d H:i", $start) . " to " . date("Y-m-d H:i", $end) . " with angel types " . join(", ", $needed_angel_types_info));
success(_("Shift updated."));
redirect(shift_link([
'SID' => $shift_id
]));
}
}
$angel_types_spinner = "";
foreach ($angeltypes as $angeltype_id => $angeltype_name) {
$angel_types_spinner .= form_spinner('type_' . $angeltype_id, $angeltype_name, $needed_angel_types[$angeltype_id]);
}
return page_with_title(shifts_title(), [
msg(),
'<noscript>' . info(_("This page is much more comfortable with javascript."), true) . '</noscript>',
form([
form_select('shifttype_id', _('Shifttype'), $shifttypes, $shifttype_id),
form_text('title', _("Title"), $title),
form_select('rid', _("Room:"), $room, $rid),
form_text('start', _("Start:"), date("Y-m-d H:i", $start)),
form_text('end', _("End:"), date("Y-m-d H:i", $end)),
'<h2>' . _("Needed angels") . '</h2>',
$angel_types_spinner,
form_submit('submit', _("Save"))
])
]);
}
function shift_delete_controller() {
global $privileges;
if (! in_array('user_shifts_admin', $privileges)) {
redirect(page_link_to('user_shifts'));
}
// Schicht komplett löschen (nur für admins/user mit user_shifts_admin privileg)
if (! isset($_REQUEST['delete_shift']) || ! preg_match("/^[0-9]*$/", $_REQUEST['delete_shift'])) {
redirect(page_link_to('user_shifts'));
}
$shift_id = $_REQUEST['delete_shift'];
$shift = Shift($shift_id);
if ($shift == null) {
redirect(page_link_to('user_shifts'));
}
// Schicht löschen bestätigt
if (isset($_REQUEST['delete'])) {
Shift_delete($shift_id);
engelsystem_log("Deleted shift " . $shift['name'] . " from " . date("Y-m-d H:i", $shift['start']) . " to " . date("Y-m-d H:i", $shift['end']));
success(_("Shift deleted."));
redirect(page_link_to('user_shifts'));
}
return page_with_title(shifts_title(), [
error(sprintf(_("Do you want to delete the shift %s from %s to %s?"), $shift['name'], date("Y-m-d H:i", $shift['start']), date("H:i", $shift['end'])), true),
'<a class="button" href="?p=user_shifts&delete_shift=' . $shift_id . '&delete">' . _("delete") . '</a>'
]);
}
function shift_controller() { function shift_controller() {
global $user, $privileges; global $user, $privileges;
@ -24,33 +190,15 @@ function shift_controller() {
} }
$shift = Shift($_REQUEST['shift_id']); $shift = Shift($_REQUEST['shift_id']);
if ($shift === false) {
engelsystem_error('Unable to load shift.');
}
if ($shift == null) { if ($shift == null) {
error(_('Shift could not be found.')); error(_("Shift could not be found."));
redirect(page_link_to('user_shifts')); redirect(page_link_to('user_shifts'));
} }
$shifttype = ShiftType($shift['shifttype_id']); $shifttype = ShiftType($shift['shifttype_id']);
if ($shifttype === false || $shifttype == null) {
engelsystem_error('Unable to load shift type.');
}
$room = Room($shift['RID']); $room = Room($shift['RID']);
if ($room === false || $room == null) {
engelsystem_error('Unable to load room.');
}
$angeltypes = AngelTypes(); $angeltypes = AngelTypes();
if ($angeltypes === false) {
engelsystem_error('Unable to load angeltypes.');
}
$user_shifts = Shifts_by_user($user); $user_shifts = Shifts_by_user($user);
if ($user_shifts === false) {
engelsystem_error('Unable to load users shifts.');
}
$signed_up = false; $signed_up = false;
foreach ($user_shifts as $user_shift) { foreach ($user_shifts as $user_shift) {

@ -48,9 +48,6 @@ function shifttype_edit_controller() {
$description = ""; $description = "";
$angeltypes = AngelTypes(); $angeltypes = AngelTypes();
if ($angeltypes === false) {
engelsystem_error("Unable to load angel types.");
}
if (isset($_REQUEST['shifttype_id'])) { if (isset($_REQUEST['shifttype_id'])) {
$shifttype = ShiftType($_REQUEST['shifttype_id']); $shifttype = ShiftType($_REQUEST['shifttype_id']);
@ -128,9 +125,6 @@ function shifttype_controller() {
$angeltype = null; $angeltype = null;
if ($shifttype['angeltype_id'] != null) { if ($shifttype['angeltype_id'] != null) {
$angeltype = AngelType($shifttype['angeltype_id']); $angeltype = AngelType($shifttype['angeltype_id']);
if ($angeltype === false) {
engelsystem_error('Unable to load angeltype.');
}
} }
return [ return [

@ -7,9 +7,6 @@ function user_angeltypes_unconfirmed_hint() {
global $user; global $user;
$unconfirmed_user_angeltypes = User_unconfirmed_AngelTypes($user); $unconfirmed_user_angeltypes = User_unconfirmed_AngelTypes($user);
if ($unconfirmed_user_angeltypes === false) {
engelsystem_error("Unable to load user angeltypes.");
}
if (count($unconfirmed_user_angeltypes) == 0) { if (count($unconfirmed_user_angeltypes) == 0) {
return ''; return '';
} }
@ -34,9 +31,6 @@ function user_angeltypes_delete_all_controller() {
} }
$angeltype = AngelType($_REQUEST['angeltype_id']); $angeltype = AngelType($_REQUEST['angeltype_id']);
if ($angeltype === false) {
engelsystem_error("Unable to load angeltype.");
}
if ($angeltype == null) { if ($angeltype == null) {
error(_("Angeltype doesn't exist.")); error(_("Angeltype doesn't exist."));
redirect(page_link_to('angeltypes')); redirect(page_link_to('angeltypes'));
@ -48,10 +42,7 @@ function user_angeltypes_delete_all_controller() {
} }
if (isset($_REQUEST['confirmed'])) { if (isset($_REQUEST['confirmed'])) {
$result = UserAngelTypes_delete_all($angeltype['id']); UserAngelTypes_delete_all($angeltype['id']);
if ($result === false) {
engelsystem_error("Unable to confirm all users.");
}
engelsystem_log(sprintf("Denied all users for angeltype %s", AngelType_name_render($angeltype))); engelsystem_log(sprintf("Denied all users for angeltype %s", AngelType_name_render($angeltype)));
success(sprintf(_("Denied all users for angeltype %s."), AngelType_name_render($angeltype))); success(sprintf(_("Denied all users for angeltype %s."), AngelType_name_render($angeltype)));
@ -76,18 +67,12 @@ function user_angeltypes_confirm_all_controller() {
} }
$angeltype = AngelType($_REQUEST['angeltype_id']); $angeltype = AngelType($_REQUEST['angeltype_id']);
if ($angeltype === false) {
engelsystem_error("Unable to load angeltype.");
}
if ($angeltype == null) { if ($angeltype == null) {
error(_("Angeltype doesn't exist.")); error(_("Angeltype doesn't exist."));
redirect(page_link_to('angeltypes')); redirect(page_link_to('angeltypes'));
} }
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype); $user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
if ($user_angeltype === false) {
engelsystem_error("Unable to load user angeltype.");
}
if ($user_angeltype == null) { if ($user_angeltype == null) {
error(_("User angeltype doesn't exist.")); error(_("User angeltype doesn't exist."));
redirect(page_link_to('angeltypes')); redirect(page_link_to('angeltypes'));
@ -99,10 +84,7 @@ function user_angeltypes_confirm_all_controller() {
} }
if (isset($_REQUEST['confirmed'])) { if (isset($_REQUEST['confirmed'])) {
$result = UserAngelTypes_confirm_all($angeltype['id'], $user); UserAngelTypes_confirm_all($angeltype['id'], $user);
if ($result === false) {
engelsystem_error("Unable to confirm all users.");
}
engelsystem_log(sprintf("Confirmed all users for angeltype %s", AngelType_name_render($angeltype))); engelsystem_log(sprintf("Confirmed all users for angeltype %s", AngelType_name_render($angeltype)));
success(sprintf(_("Confirmed all users for angeltype %s."), AngelType_name_render($angeltype))); success(sprintf(_("Confirmed all users for angeltype %s."), AngelType_name_render($angeltype)));
@ -127,18 +109,12 @@ function user_angeltype_confirm_controller() {
} }
$user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']); $user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']);
if ($user_angeltype === false) {
engelsystem_error("Unable to load user angeltype.");
}
if ($user_angeltype == null) { if ($user_angeltype == null) {
error(_("User angeltype doesn't exist.")); error(_("User angeltype doesn't exist."));
redirect(page_link_to('angeltypes')); redirect(page_link_to('angeltypes'));
} }
$angeltype = AngelType($user_angeltype['angeltype_id']); $angeltype = AngelType($user_angeltype['angeltype_id']);
if ($angeltype === false) {
engelsystem_error("Unable to load angeltype.");
}
if ($angeltype == null) { if ($angeltype == null) {
error(_("Angeltype doesn't exist.")); error(_("Angeltype doesn't exist."));
redirect(page_link_to('angeltypes')); redirect(page_link_to('angeltypes'));
@ -150,9 +126,6 @@ function user_angeltype_confirm_controller() {
} }
$user_source = User($user_angeltype['user_id']); $user_source = User($user_angeltype['user_id']);
if ($user_source === false) {
engelsystem_error("Unable to load user.");
}
if ($user_source == null) { if ($user_source == null) {
error(_("User doesn't exist.")); error(_("User doesn't exist."));
redirect(page_link_to('angeltypes')); redirect(page_link_to('angeltypes'));
@ -187,27 +160,18 @@ function user_angeltype_delete_controller() {
} }
$user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']); $user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']);
if ($user_angeltype === false) {
engelsystem_error("Unable to load user angeltype.");
}
if ($user_angeltype == null) { if ($user_angeltype == null) {
error(_("User angeltype doesn't exist.")); error(_("User angeltype doesn't exist."));
redirect(page_link_to('angeltypes')); redirect(page_link_to('angeltypes'));
} }
$angeltype = AngelType($user_angeltype['angeltype_id']); $angeltype = AngelType($user_angeltype['angeltype_id']);
if ($angeltype === false) {
engelsystem_error("Unable to load angeltype.");
}
if ($angeltype == null) { if ($angeltype == null) {
error(_("Angeltype doesn't exist.")); error(_("Angeltype doesn't exist."));
redirect(page_link_to('angeltypes')); redirect(page_link_to('angeltypes'));
} }
$user_source = User($user_angeltype['user_id']); $user_source = User($user_angeltype['user_id']);
if ($user_source === false) {
engelsystem_error("Unable to load user.");
}
if ($user_source == null) { if ($user_source == null) {
error(_("User doesn't exist.")); error(_("User doesn't exist."));
redirect(page_link_to('angeltypes')); redirect(page_link_to('angeltypes'));
@ -261,37 +225,25 @@ function user_angeltype_update_controller() {
} }
$user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']); $user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']);
if ($user_angeltype === false) {
engelsystem_error("Unable to load user angeltype.");
}
if ($user_angeltype == null) { if ($user_angeltype == null) {
error(_("User angeltype doesn't exist.")); error(_("User angeltype doesn't exist."));
redirect(page_link_to('angeltypes')); redirect(page_link_to('angeltypes'));
} }
$angeltype = AngelType($user_angeltype['angeltype_id']); $angeltype = AngelType($user_angeltype['angeltype_id']);
if ($angeltype === false) {
engelsystem_error("Unable to load angeltype.");
}
if ($angeltype == null) { if ($angeltype == null) {
error(_("Angeltype doesn't exist.")); error(_("Angeltype doesn't exist."));
redirect(page_link_to('angeltypes')); redirect(page_link_to('angeltypes'));
} }
$user_source = User($user_angeltype['user_id']); $user_source = User($user_angeltype['user_id']);
if ($user_source === false) {
engelsystem_error("Unable to load user.");
}
if ($user_source == null) { if ($user_source == null) {
error(_("User doesn't exist.")); error(_("User doesn't exist."));
redirect(page_link_to('angeltypes')); redirect(page_link_to('angeltypes'));
} }
if (isset($_REQUEST['confirmed'])) { if (isset($_REQUEST['confirmed'])) {
$result = UserAngelType_update($user_angeltype['id'], $coordinator); UserAngelType_update($user_angeltype['id'], $coordinator);
if ($result === false) {
engelsystem_error("Unable to update coordinator rights.");
}
$success_message = sprintf($coordinator ? _("Added coordinator rights for %s to %s.") : _("Removed coordinator rights for %s from %s."), AngelType_name_render($angeltype), User_Nick_render($user_source)); $success_message = sprintf($coordinator ? _("Added coordinator rights for %s to %s.") : _("Removed coordinator rights for %s from %s."), AngelType_name_render($angeltype), User_Nick_render($user_source));
engelsystem_log($success_message); engelsystem_log($success_message);
@ -326,26 +278,17 @@ function user_angeltype_add_controller() {
// Load possible users, that are not in the angeltype already // Load possible users, that are not in the angeltype already
$users_source = Users_by_angeltype_inverted($angeltype); $users_source = Users_by_angeltype_inverted($angeltype);
if ($users_source === false) {
engelsystem_error("Unable to load users.");
}
if (isset($_REQUEST['submit'])) { if (isset($_REQUEST['submit'])) {
$user_source = load_user(); $user_source = load_user();
if (! UserAngelType_exists($user_source, $angeltype)) { if (! UserAngelType_exists($user_source, $angeltype)) {
$user_angeltype_id = UserAngelType_create($user_source, $angeltype); $user_angeltype_id = UserAngelType_create($user_source, $angeltype);
if ($user_angeltype_id === false) {
engelsystem_error("Unable to create user angeltype.");
}
engelsystem_log(sprintf("User %s added to %s.", User_Nick_render($user_source), AngelType_name_render($angeltype))); engelsystem_log(sprintf("User %s added to %s.", User_Nick_render($user_source), AngelType_name_render($angeltype)));
success(sprintf(_("User %s added to %s."), User_Nick_render($user_source), AngelType_name_render($angeltype))); success(sprintf(_("User %s added to %s."), User_Nick_render($user_source), AngelType_name_render($angeltype)));
$result = UserAngelType_confirm($user_angeltype_id, $user_source); UserAngelType_confirm($user_angeltype_id, $user_source);
if ($result === false) {
engelsystem_error("Unable to confirm user angeltype.");
}
engelsystem_log(sprintf("User %s confirmed as %s.", User_Nick_render($user), AngelType_name_render($angeltype))); engelsystem_log(sprintf("User %s confirmed as %s.", User_Nick_render($user), AngelType_name_render($angeltype)));
redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']); redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']);
@ -365,9 +308,6 @@ function user_angeltype_join_controller($angeltype) {
global $user, $privileges; global $user, $privileges;
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype); $user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
if ($user_angeltype === false) {
engelsystem_error("Unable to load user angeltype.");
}
if ($user_angeltype != null) { if ($user_angeltype != null) {
error(sprintf(_("You are already a %s."), $angeltype['name'])); error(sprintf(_("You are already a %s."), $angeltype['name']));
redirect(page_link_to('angeltypes')); redirect(page_link_to('angeltypes'));
@ -375,19 +315,13 @@ function user_angeltype_join_controller($angeltype) {
if (isset($_REQUEST['confirmed'])) { if (isset($_REQUEST['confirmed'])) {
$user_angeltype_id = UserAngelType_create($user, $angeltype); $user_angeltype_id = UserAngelType_create($user, $angeltype);
if ($user_angeltype_id === false) {
engelsystem_error("Unable to create user angeltype.");
}
$success_message = sprintf(_("You joined %s."), $angeltype['name']); $success_message = sprintf(_("You joined %s."), $angeltype['name']);
engelsystem_log(sprintf("User %s joined %s.", User_Nick_render($user), AngelType_name_render($angeltype))); engelsystem_log(sprintf("User %s joined %s.", User_Nick_render($user), AngelType_name_render($angeltype)));
success($success_message); success($success_message);
if (in_array('admin_user_angeltypes', $privileges)) { if (in_array('admin_user_angeltypes', $privileges)) {
$result = UserAngelType_confirm($user_angeltype_id, $user); UserAngelType_confirm($user_angeltype_id, $user);
if ($result === false) {
engelsystem_error("Unable to confirm user angeltype.");
}
engelsystem_log(sprintf("User %s confirmed as %s.", User_Nick_render($user), AngelType_name_render($angeltype))); engelsystem_log(sprintf("User %s confirmed as %s.", User_Nick_render($user), AngelType_name_render($angeltype)));
} }

@ -73,9 +73,6 @@ function user_driver_license_edit_controller() {
if (isset($_REQUEST['user_id'])) { if (isset($_REQUEST['user_id'])) {
$user_source = User($_REQUEST['user_id']); $user_source = User($_REQUEST['user_id']);
if ($user_source === false) {
engelsystem_error('Unable to load angeltype.');
}
if ($user_source == null) { if ($user_source == null) {
redirect(user_driver_license_edit_link()); redirect(user_driver_license_edit_link());
} }

@ -142,17 +142,13 @@ function user_edit_vouchers_controller() {
function user_controller() { function user_controller() {
global $privileges, $user; global $privileges, $user;
$user_source = $user;
if (isset($_REQUEST['user_id'])) { if (isset($_REQUEST['user_id'])) {
$user_source = User($_REQUEST['user_id']); $user_source = User($_REQUEST['user_id']);
if ($user_source === false) {
engelsystem_error("Unable to load user.");
}
if ($user_source == null) { if ($user_source == null) {
error(_("User not found.")); error(_("User not found."));
redirect('?'); redirect('?');
} }
} else {
$user_source = $user;
} }
$shifts = Shifts_by_user($user_source); $shifts = Shifts_by_user($user_source);

@ -18,6 +18,7 @@ require_once realpath(__DIR__ . '/../includes/model/NeededAngelTypes_model.php')
require_once realpath(__DIR__ . '/../includes/model/Room_model.php'); require_once realpath(__DIR__ . '/../includes/model/Room_model.php');
require_once realpath(__DIR__ . '/../includes/model/ShiftEntry_model.php'); require_once realpath(__DIR__ . '/../includes/model/ShiftEntry_model.php');
require_once realpath(__DIR__ . '/../includes/model/Shifts_model.php'); require_once realpath(__DIR__ . '/../includes/model/Shifts_model.php');
require_once realpath(__DIR__ . '/../includes/model/ShiftsFilter.php');
require_once realpath(__DIR__ . '/../includes/model/ShiftTypes_model.php'); require_once realpath(__DIR__ . '/../includes/model/ShiftTypes_model.php');
require_once realpath(__DIR__ . '/../includes/model/UserAngelTypes_model.php'); require_once realpath(__DIR__ . '/../includes/model/UserAngelTypes_model.php');
require_once realpath(__DIR__ . '/../includes/model/UserDriverLicenses_model.php'); require_once realpath(__DIR__ . '/../includes/model/UserDriverLicenses_model.php');
@ -28,6 +29,10 @@ require_once realpath(__DIR__ . '/../includes/view/AngelTypes_view.php');
require_once realpath(__DIR__ . '/../includes/view/EventConfig_view.php'); require_once realpath(__DIR__ . '/../includes/view/EventConfig_view.php');
require_once realpath(__DIR__ . '/../includes/view/Questions_view.php'); require_once realpath(__DIR__ . '/../includes/view/Questions_view.php');
require_once realpath(__DIR__ . '/../includes/view/Rooms_view.php'); require_once realpath(__DIR__ . '/../includes/view/Rooms_view.php');
require_once realpath(__DIR__ . '/../includes/view/ShiftCalendarLane.php');
require_once realpath(__DIR__ . '/../includes/view/ShiftCalendarRenderer.php');
require_once realpath(__DIR__ . '/../includes/view/ShiftCalendarShiftRenderer.php');
require_once realpath(__DIR__ . '/../includes/view/ShiftsFilterRenderer.php');
require_once realpath(__DIR__ . '/../includes/view/Shifts_view.php'); require_once realpath(__DIR__ . '/../includes/view/Shifts_view.php');
require_once realpath(__DIR__ . '/../includes/view/ShiftEntry_view.php'); require_once realpath(__DIR__ . '/../includes/view/ShiftEntry_view.php');
require_once realpath(__DIR__ . '/../includes/view/ShiftTypes_view.php'); require_once realpath(__DIR__ . '/../includes/view/ShiftTypes_view.php');
@ -38,6 +43,7 @@ require_once realpath(__DIR__ . '/../includes/view/User_view.php');
require_once realpath(__DIR__ . '/../includes/controller/angeltypes_controller.php'); require_once realpath(__DIR__ . '/../includes/controller/angeltypes_controller.php');
require_once realpath(__DIR__ . '/../includes/controller/event_config_controller.php'); require_once realpath(__DIR__ . '/../includes/controller/event_config_controller.php');
require_once realpath(__DIR__ . '/../includes/controller/rooms_controller.php'); require_once realpath(__DIR__ . '/../includes/controller/rooms_controller.php');
require_once realpath(__DIR__ . '/../includes/controller/shift_entries_controller.php');
require_once realpath(__DIR__ . '/../includes/controller/shifts_controller.php'); require_once realpath(__DIR__ . '/../includes/controller/shifts_controller.php');
require_once realpath(__DIR__ . '/../includes/controller/shifttypes_controller.php'); require_once realpath(__DIR__ . '/../includes/controller/shifttypes_controller.php');
require_once realpath(__DIR__ . '/../includes/controller/users_controller.php'); require_once realpath(__DIR__ . '/../includes/controller/users_controller.php');

@ -91,7 +91,7 @@ function AngelType_validate_name($name, $angeltype) {
* @param User $user * @param User $user
*/ */
function AngelTypes_with_user($user) { function AngelTypes_with_user($user) {
return sql_select(" $result = sql_select("
SELECT `AngelTypes`.*, SELECT `AngelTypes`.*,
`UserAngelTypes`.`id` as `user_angeltype_id`, `UserAngelTypes`.`id` as `user_angeltype_id`,
`UserAngelTypes`.`confirm_user_id`, `UserAngelTypes`.`confirm_user_id`,
@ -100,30 +100,35 @@ function AngelTypes_with_user($user) {
LEFT JOIN `UserAngelTypes` ON `AngelTypes`.`id`=`UserAngelTypes`.`angeltype_id` LEFT JOIN `UserAngelTypes` ON `AngelTypes`.`id`=`UserAngelTypes`.`angeltype_id`
AND `UserAngelTypes`.`user_id`=" . $user['UID'] . " AND `UserAngelTypes`.`user_id`=" . $user['UID'] . "
ORDER BY `name`"); ORDER BY `name`");
if ($result === false) {
engelsystem_error("Unable to load angeltypes.");
}
return $result;
} }
/** /**
* Returns all angeltypes. * Returns all angeltypes.
*/ */
function AngelTypes() { function AngelTypes() {
return sql_select(" $result = sql_select("
SELECT * SELECT *
FROM `AngelTypes` FROM `AngelTypes`
ORDER BY `name`"); ORDER BY `name`");
if ($result === false) {
engelsystem_error("Unable to load angeltypes.");
}
return $result;
} }
/** /**
* Returns AngelType id array * Returns AngelType id array
*/ */
function AngelType_ids() { function AngelType_ids() {
$angelType_source = sql_select("SELECT `id` FROM `AngelTypes`"); $result = sql_select("SELECT `id` FROM `AngelTypes`");
if ($angelType_source === false) { if ($result === false) {
return false; engelsystem_error("Unable to load angeltypes.");
} }
if (count($angelType_source) > 0) { return select_array($result, 'id', 'id');
return $angelType_source;
}
return null;
} }
/** /**
@ -135,7 +140,7 @@ function AngelType_ids() {
function AngelType($angeltype_id) { function AngelType($angeltype_id) {
$angelType_source = sql_select("SELECT * FROM `AngelTypes` WHERE `id`='" . sql_escape($angeltype_id) . "' LIMIT 1"); $angelType_source = sql_select("SELECT * FROM `AngelTypes` WHERE `id`='" . sql_escape($angeltype_id) . "' LIMIT 1");
if ($angelType_source === false) { if ($angelType_source === false) {
return false; engelsystem_error("Unable to load angeltype.");
} }
if (count($angelType_source) > 0) { if (count($angelType_source) > 0) {
return $angelType_source[0]; return $angelType_source[0];

@ -1,13 +1,63 @@
<?php <?php
/**
* Entity needed angeltypes describes how many angels of given type are needed for a shift or in a room.
*/
/**
* Insert a new needed angel type.
*
* @param int $shift_id
* The shift. Can be null, but then a room_id must be given.
* @param int $angeltype_id
* The angeltype
* @param int $room_id
* The room. Can be null, but then a shift_id must be given.
* @param int $count
* How many angels are needed?
*/
function NeededAngelType_add($shift_id, $angeltype_id, $room_id, $count) {
$result = sql_query("
INSERT INTO `NeededAngelTypes` SET
`shift_id`=" . sql_null($shift_id) . ",
`angel_type_id`='" . sql_escape($angeltype_id) . "',
`room_id`=" . sql_null($room_id) . ",
`count`='" . sql_escape($count) . "'");
if ($result === false) {
return false;
}
return sql_id();
}
/**
* Deletes all needed angel types from given shift.
*
* @param int $shift_id
* id of the shift
*/
function NeededAngelTypes_delete_by_shift($shift_id) {
return sql_query("DELETE FROM `NeededAngelTypes` WHERE `shift_id`='" . sql_escape($shift_id) . "'");
}
/**
* Deletes all needed angel types from given room.
*
* @param int $room_id
* id of the room
*/
function NeededAngelTypes_delete_by_room($room_id) {
return sql_query("DELETE FROM `NeededAngelTypes` WHERE `room_id`='" . sql_escape($room_id) . "'");
}
/** /**
* Returns all needed angeltypes and already taken needs. * Returns all needed angeltypes and already taken needs.
* *
* @param shiftID id of shift * @param int $shiftID
* id of shift
*/ */
function NeededAngelTypes_by_shift($shiftId) { function NeededAngelTypes_by_shift($shiftId) {
$needed_angeltypes_source = sql_select(" $needed_angeltypes_source = sql_select("
SELECT `NeededAngelTypes`.*, `AngelTypes`.`name`, `AngelTypes`.`restricted` SELECT `NeededAngelTypes`.*, `AngelTypes`.`id`, `AngelTypes`.`name`, `AngelTypes`.`restricted`
FROM `NeededAngelTypes` FROM `NeededAngelTypes`
JOIN `AngelTypes` ON `AngelTypes`.`id` = `NeededAngelTypes`.`angel_type_id` JOIN `AngelTypes` ON `AngelTypes`.`id` = `NeededAngelTypes`.`angel_type_id`
WHERE `shift_id`='" . sql_escape($shiftId) . "' WHERE `shift_id`='" . sql_escape($shiftId) . "'
@ -15,7 +65,7 @@ function NeededAngelTypes_by_shift($shiftId) {
ORDER BY `room_id` DESC ORDER BY `room_id` DESC
"); ");
if ($needed_angeltypes_source === false) { if ($needed_angeltypes_source === false) {
return false; engelsystem_error("Unable to load needed angeltypes.");
} }
// Use settings from room // Use settings from room
@ -30,18 +80,16 @@ function NeededAngelTypes_by_shift($shiftId) {
ORDER BY `room_id` DESC ORDER BY `room_id` DESC
"); ");
if ($needed_angeltypes_source === false) { if ($needed_angeltypes_source === false) {
return false; engelsystem_error("Unable to load needed angeltypes.");
} }
} }
$needed_angeltypes = []; $needed_angeltypes = [];
foreach ($needed_angeltypes_source as $angeltype) { foreach ($needed_angeltypes_source as $angeltype) {
$shift_entries = ShiftEntries_by_shift_and_angeltype($shiftId, $angeltype['angel_type_id']); $shift_entries = ShiftEntries_by_shift_and_angeltype($shiftId, $angeltype['angel_type_id']);
if ($shift_entries === false) {
return false;
}
$angeltype['taken'] = count($shift_entries); $angeltype['taken'] = count($shift_entries);
$angeltype['shift_entries'] = $shift_entries;
$needed_angeltypes[] = $angeltype; $needed_angeltypes[] = $angeltype;
} }

@ -1,7 +1,16 @@
<?php <?php
/**
* returns a list of rooms.
* @param boolean $show_all returns also hidden rooms when true
*/
function Rooms($show_all = false) {
return sql_select("SELECT * FROM `Room`" . ($show_all ? "" : " WHERE `show`='Y'") . " ORDER BY `Name`");
}
/** /**
* Delete a room * Delete a room
*
* @param int $room_id * @param int $room_id
*/ */
function Room_delete($room_id) { function Room_delete($room_id) {

@ -110,12 +110,16 @@ function ShiftEntries_finished_by_user($user) {
* @param int $angeltype_id * @param int $angeltype_id
*/ */
function ShiftEntries_by_shift_and_angeltype($shift_id, $angeltype_id) { function ShiftEntries_by_shift_and_angeltype($shift_id, $angeltype_id) {
return sql_select(" $result = sql_select("
SELECT * SELECT *
FROM `ShiftEntry` FROM `ShiftEntry`
WHERE `SID`=" . sql_escape($shift_id) . " WHERE `SID`=" . sql_escape($shift_id) . "
AND `TID`=" . sql_escape($angeltype_id) . " AND `TID`=" . sql_escape($angeltype_id) . "
"); ");
if ($result === false) {
engelsystem_error("Unable to load shift entries.");
}
return $result;
} }
/** /**

@ -51,7 +51,7 @@ function ShiftType_create($name, $angeltype_id, $description) {
function ShiftType($shifttype_id) { function ShiftType($shifttype_id) {
$shifttype = sql_select("SELECT * FROM `ShiftTypes` WHERE `id`='" . sql_escape($shifttype_id) . "'"); $shifttype = sql_select("SELECT * FROM `ShiftTypes` WHERE `id`='" . sql_escape($shifttype_id) . "'");
if ($shifttype === false) { if ($shifttype === false) {
return false; engelsystem_error('Unable to load shift type.');
} }
if ($shifttype == null) { if ($shifttype == null) {
return null; return null;

@ -0,0 +1,112 @@
<?php
namespace Engelsystem;
/**
* BO Class that stores all parameters used to filter shifts for users.
*
* @author msquare
*/
class ShiftsFilter {
/**
* Shift is completely full.
*/
const FILLED_FILLED = 1;
/**
* Shift has some free slots.
*/
const FILLED_FREE = 0;
/**
* Has the user "user shifts admin" privilege?
*
* @var boolean
*/
private $userShiftsAdmin;
private $filled = [];
private $rooms = [];
private $types = [];
private $startTime = null;
private $endTime = null;
public function __construct($user_shifts_admin, $rooms, $types) {
$this->user_shifts_admin = $user_shifts_admin;
$this->rooms = $rooms;
$this->types = $types;
$this->filled = [
ShiftsFilter::FILLED_FREE
];
if ($user_shifts_admin) {
$this->filled[] = ShiftsFilter::FILLED_FILLED;
}
}
public function getStartTime() {
return $this->startTime;
}
public function setStartTime($startTime) {
$this->startTime = $startTime;
}
public function getEndTime() {
return $this->endTime;
}
public function setEndTime($endTime) {
$this->endTime = $endTime;
}
public function getTypes() {
if (count($this->types) == 0) {
return [
0
];
}
return $this->types;
}
public function setTypes($types) {
$this->types = $types;
}
public function getRooms() {
if (count($this->rooms) == 0) {
return [
0
];
}
return $this->rooms;
}
public function setRooms($rooms) {
$this->rooms = $rooms;
}
public function isUserShiftsAdmin() {
return $this->userShiftsAdmin;
}
public function setUserShiftsAdmin($userShiftsAdmin) {
$this->userShiftsAdmin = $userShiftsAdmin;
}
public function getFilled() {
return $this->filled;
}
public function setFilled($filled) {
$this->filled = $filled;
}
}
?>

@ -1,7 +1,80 @@
<?php <?php
use Engelsystem\ShiftsFilter;
function Shifts_by_room($room) {
$result = sql_select("SELECT * FROM `Shifts` WHERE `RID`=" . sql_escape($room['RID']) . " ORDER BY `start`");
if ($result === false) {
engelsystem_error("Unable to load shifts.");
}
return $result;
}
function Shifts_by_ShiftsFilter(ShiftsFilter $shiftsFilter, $user) {
$SQL = "SELECT DISTINCT `Shifts`.*, `ShiftTypes`.`name`, `Room`.`Name` as `room_name`, nat2.`special_needs` > 0 AS 'has_special_needs'
FROM `Shifts`
INNER JOIN `Room` USING (`RID`)
INNER JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`)
LEFT JOIN (
SELECT COUNT(*) AS special_needs , nat3.`shift_id`
FROM `NeededAngelTypes` AS nat3
WHERE `shift_id` IS NOT NULL
GROUP BY nat3.`shift_id`
) AS nat2 ON nat2.`shift_id` = `Shifts`.`SID`
INNER JOIN `NeededAngelTypes` AS nat
ON nat.`count` != 0
AND nat.`angel_type_id` IN (" . implode(',', $shiftsFilter->getTypes()) . ")
AND (
(nat2.`special_needs` > 0 AND nat.`shift_id` = `Shifts`.`SID`)
OR
(
(nat2.`special_needs` = 0 OR nat2.`special_needs` IS NULL)
AND nat.`room_id` = `RID`)
)
LEFT JOIN (
SELECT se.`SID`, se.`TID`, COUNT(*) as count
FROM `ShiftEntry` AS se GROUP BY se.`SID`, se.`TID`
) AS entries ON entries.`SID` = `Shifts`.`SID` AND entries.`TID` = nat.`angel_type_id`
WHERE `Shifts`.`RID` IN (" . implode(',', $shiftsFilter->getRooms()) . ")
AND `start` BETWEEN " . $shiftsFilter->getStartTime() . " AND " . $shiftsFilter->getEndTime();
if (count($shiftsFilter->getFilled()) == 1) {
if ($shiftsFilter->getFilled()[0] == ShiftsFilter::FILLED_FREE) {
$SQL .= "
AND (
nat.`count` > entries.`count` OR entries.`count` IS NULL
OR EXISTS (
SELECT `SID`
FROM `ShiftEntry`
WHERE `UID` = '" . sql_escape($user['UID']) . "'
AND `ShiftEntry`.`SID` = `Shifts`.`SID`
)
)";
} elseif ($_SESSION['user_shifts']['filled'][0] == ShiftsFilter::FILLED_FILLED) {
$SQL .= "
AND (
nat.`count` <= entries.`count`
OR EXISTS (
SELECT `SID`
FROM `ShiftEntry`
WHERE `UID` = '" . sql_escape($user['UID']) . "'
AND `ShiftEntry`.`SID` = `Shifts`.`SID`
)
)";
}
}
$SQL .= "
ORDER BY `start`";
$result = sql_select($SQL);
if ($result === false) {
engelsystem_error("Unable to load shifts by filter.");
}
return $result;
}
/** /**
* Check if a shift collides with other shifts (in time). * Check if a shift collides with other shifts (in time).
*
* @param Shift $shift * @param Shift $shift
* @param array<Shift> $shifts * @param array<Shift> $shifts
*/ */
@ -28,18 +101,12 @@ function Shift_signup_allowed($shift, $angeltype, $user_angeltype = null, $user_
if ($user_shifts == null) { if ($user_shifts == null) {
$user_shifts = Shifts_by_user($user); $user_shifts = Shifts_by_user($user);
if ($user_shifts === false) {
engelsystem_error('Unable to load users shifts.');
}
} }
$collides = Shift_collides($shift, $user_shifts); $collides = Shift_collides($shift, $user_shifts);
if ($user_angeltype == null) { if ($user_angeltype == null) {
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype); $user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
if ($user_angeltype === false) {
engelsystem_error('Unable to load user angeltype.');
}
} }
$signed_up = false; $signed_up = false;
@ -104,7 +171,11 @@ function Shift_delete_by_psid($shift_psid) {
function Shift_delete($shift_id) { function Shift_delete($shift_id) {
mail_shift_delete(Shift($shift_id)); mail_shift_delete(Shift($shift_id));
return sql_query("DELETE FROM `Shifts` WHERE `SID`='" . sql_escape($shift_id) . "'"); $result = sql_query("DELETE FROM `Shifts` WHERE `SID`='" . sql_escape($shift_id) . "'");
if ($result === false) {
engelsystem_error('Unable to delete shift.');
}
return $result;
} }
/** /**
@ -170,7 +241,7 @@ function Shift_create($shift) {
* Return users shifts. * Return users shifts.
*/ */
function Shifts_by_user($user) { function Shifts_by_user($user) {
return sql_select(" $result = sql_select("
SELECT `ShiftTypes`.`id` as `shifttype_id`, `ShiftTypes`.`name`, `ShiftEntry`.*, `Shifts`.*, `Room`.* SELECT `ShiftTypes`.`id` as `shifttype_id`, `ShiftTypes`.`name`, `ShiftEntry`.*, `Shifts`.*, `Room`.*
FROM `ShiftEntry` FROM `ShiftEntry`
JOIN `Shifts` ON (`ShiftEntry`.`SID` = `Shifts`.`SID`) JOIN `Shifts` ON (`ShiftEntry`.`SID` = `Shifts`.`SID`)
@ -179,6 +250,10 @@ function Shifts_by_user($user) {
WHERE `UID`='" . sql_escape($user['UID']) . "' WHERE `UID`='" . sql_escape($user['UID']) . "'
ORDER BY `start` ORDER BY `start`
"); ");
if ($result === false) {
engelsystem_error('Unable to load users shifts.');
}
return $result;
} }
/** /**
@ -242,9 +317,13 @@ function Shift($shift_id) {
$shiftsEntry_source = sql_select("SELECT `id`, `TID` , `UID` , `freeloaded` FROM `ShiftEntry` WHERE `SID`='" . sql_escape($shift_id) . "'"); $shiftsEntry_source = sql_select("SELECT `id`, `TID` , `UID` , `freeloaded` FROM `ShiftEntry` WHERE `SID`='" . sql_escape($shift_id) . "'");
if ($shifts_source === false) { if ($shifts_source === false) {
return false; engelsystem_error('Unable to load shift.');
} }
if (count($shifts_source) > 0) {
if (empty($shifts_source)) {
return null;
}
$result = $shifts_source[0]; $result = $shifts_source[0];
$result['ShiftEntry'] = $shiftsEntry_source; $result['ShiftEntry'] = $shiftsEntry_source;
@ -262,8 +341,6 @@ function Shift($shift_id) {
return $result; return $result;
} }
return null;
}
/** /**
* Returns all shifts with needed angeltypes and count of subscribed jobs. * Returns all shifts with needed angeltypes and count of subscribed jobs.

@ -42,7 +42,7 @@ function User_angeltypes($user) {
* @param User $user * @param User $user
*/ */
function User_unconfirmed_AngelTypes($user) { function User_unconfirmed_AngelTypes($user) {
return sql_select(" $result = sql_select("
SELECT SELECT
`UserAngelTypes`.*, `UserAngelTypes`.*,
`AngelTypes`.`name`, `AngelTypes`.`name`,
@ -56,6 +56,10 @@ function User_unconfirmed_AngelTypes($user) {
AND `UnconfirmedMembers`.`confirm_user_id` IS NULL AND `UnconfirmedMembers`.`confirm_user_id` IS NULL
GROUP BY `UserAngelTypes`.`angeltype_id` GROUP BY `UserAngelTypes`.`angeltype_id`
ORDER BY `AngelTypes`.`name`"); ORDER BY `AngelTypes`.`name`");
if ($result === false) {
engelsystem_error("Unable to load user angeltypes.");
}
return $result;
} }
/** /**
@ -81,11 +85,15 @@ function User_is_AngelType_coordinator($user, $angeltype) {
* @param bool $coordinator * @param bool $coordinator
*/ */
function UserAngelType_update($user_angeltype_id, $coordinator) { function UserAngelType_update($user_angeltype_id, $coordinator) {
return sql_query(" $result = sql_query("
UPDATE `UserAngelTypes` UPDATE `UserAngelTypes`
SET `coordinator`=" . sql_bool($coordinator) . " SET `coordinator`=" . sql_bool($coordinator) . "
WHERE `id`='" . sql_escape($user_angeltype_id) . "' WHERE `id`='" . sql_escape($user_angeltype_id) . "'
LIMIT 1"); LIMIT 1");
if ($result === false) {
engelsystem_error("Unable to update coordinator rights.");
}
return $result;
} }
/** /**
@ -94,10 +102,14 @@ function UserAngelType_update($user_angeltype_id, $coordinator) {
* @param int $angeltype_id * @param int $angeltype_id
*/ */
function UserAngelTypes_delete_all($angeltype_id) { function UserAngelTypes_delete_all($angeltype_id) {
return sql_query(" $result = sql_query("
DELETE FROM `UserAngelTypes` DELETE FROM `UserAngelTypes`
WHERE `angeltype_id`='" . sql_escape($angeltype_id) . "' WHERE `angeltype_id`='" . sql_escape($angeltype_id) . "'
AND `confirm_user_id` IS NULL"); AND `confirm_user_id` IS NULL");
if ($result === false) {
engelsystem_error("Unable to delete all unconfirmed users.");
}
return $result;
} }
/** /**
@ -107,11 +119,15 @@ function UserAngelTypes_delete_all($angeltype_id) {
* @param User $confirm_user * @param User $confirm_user
*/ */
function UserAngelTypes_confirm_all($angeltype_id, $confirm_user) { function UserAngelTypes_confirm_all($angeltype_id, $confirm_user) {
return sql_query(" $result = sql_query("
UPDATE `UserAngelTypes` UPDATE `UserAngelTypes`
SET `confirm_user_id`='" . sql_escape($confirm_user['UID']) . "' SET `confirm_user_id`='" . sql_escape($confirm_user['UID']) . "'
WHERE `angeltype_id`='" . sql_escape($angeltype_id) . "' WHERE `angeltype_id`='" . sql_escape($angeltype_id) . "'
AND `confirm_user_id` IS NULL"); AND `confirm_user_id` IS NULL");
if ($result === false) {
engelsystem_error("Unable to confirm all users.");
}
return $result;
} }
/** /**
@ -121,11 +137,15 @@ function UserAngelTypes_confirm_all($angeltype_id, $confirm_user) {
* @param User $confirm_user * @param User $confirm_user
*/ */
function UserAngelType_confirm($user_angeltype_id, $confirm_user) { function UserAngelType_confirm($user_angeltype_id, $confirm_user) {
return sql_query(" $result = sql_query("
UPDATE `UserAngelTypes` UPDATE `UserAngelTypes`
SET `confirm_user_id`='" . sql_escape($confirm_user['UID']) . "' SET `confirm_user_id`='" . sql_escape($confirm_user['UID']) . "'
WHERE `id`='" . sql_escape($user_angeltype_id) . "' WHERE `id`='" . sql_escape($user_angeltype_id) . "'
LIMIT 1"); LIMIT 1");
if ($result === false) {
engelsystem_error("Unable to confirm user angeltype.");
}
return $result;
} }
/** /**
@ -152,7 +172,7 @@ function UserAngelType_create($user, $angeltype) {
`user_id`='" . sql_escape($user['UID']) . "', `user_id`='" . sql_escape($user['UID']) . "',
`angeltype_id`='" . sql_escape($angeltype['id']) . "'"); `angeltype_id`='" . sql_escape($angeltype['id']) . "'");
if ($result === false) { if ($result === false) {
return false; engelsystem_error("Unable to create user angeltype.");
} }
return sql_id(); return sql_id();
} }
@ -169,7 +189,7 @@ function UserAngelType($user_angeltype_id) {
WHERE `id`='" . sql_escape($user_angeltype_id) . "' WHERE `id`='" . sql_escape($user_angeltype_id) . "'
LIMIT 1"); LIMIT 1");
if ($angeltype === false) { if ($angeltype === false) {
return false; engelsystem_error("Unable to load user angeltype.");
} }
if (count($angeltype) == 0) { if (count($angeltype) == 0) {
return null; return null;
@ -191,7 +211,7 @@ function UserAngelType_by_User_and_AngelType($user, $angeltype) {
AND `angeltype_id`='" . sql_escape($angeltype['id']) . "' AND `angeltype_id`='" . sql_escape($angeltype['id']) . "'
LIMIT 1"); LIMIT 1");
if ($angeltype === false) { if ($angeltype === false) {
return false; engelsystem_error("Unable to load user angeltype.");
} }
if (count($angeltype) == 0) { if (count($angeltype) == 0) {
return null; return null;

@ -113,12 +113,16 @@ function User_is_freeloader($user) {
* @param Angeltype $angeltype * @param Angeltype $angeltype
*/ */
function Users_by_angeltype_inverted($angeltype) { function Users_by_angeltype_inverted($angeltype) {
return sql_select(" $result = sql_select("
SELECT `User`.* SELECT `User`.*
FROM `User` FROM `User`
LEFT JOIN `UserAngelTypes` ON (`User`.`UID`=`UserAngelTypes`.`user_id` AND `angeltype_id`='" . sql_escape($angeltype['id']) . "') LEFT JOIN `UserAngelTypes` ON (`User`.`UID`=`UserAngelTypes`.`user_id` AND `angeltype_id`='" . sql_escape($angeltype['id']) . "')
WHERE `UserAngelTypes`.`id` IS NULL WHERE `UserAngelTypes`.`id` IS NULL
ORDER BY `Nick`"); ORDER BY `Nick`");
if ($result === false) {
engelsystem_error("Unable to load users.");
}
return $result;
} }
/** /**
@ -165,7 +169,7 @@ function User_validate_Nick($nick) {
function User($user_id) { function User($user_id) {
$user_source = sql_select("SELECT * FROM `User` WHERE `UID`='" . sql_escape($user_id) . "' LIMIT 1"); $user_source = sql_select("SELECT * FROM `User` WHERE `UID`='" . sql_escape($user_id) . "' LIMIT 1");
if ($user_source === false) { if ($user_source === false) {
return false; engelsystem_error("Unable to load user.");
} }
if (count($user_source) > 0) { if (count($user_source) > 0) {
return $user_source[0]; return $user_source[0];

@ -312,8 +312,8 @@ function prepare_events($file, $shifttype_id, $add_minutes_start, $add_minutes_e
'event-id' }); 'event-id' });
$shifts_pb[$event_id] = [ $shifts_pb[$event_id] = [
'shifttype_id' => $shifttype_id, 'shifttype_id' => $shifttype_id,
'start' => DateTime::createFromFormat("Ymd\THis", $event->dtstart)->getTimestamp() - $add_minutes_start * 60, 'start' => parse_date("Ymd\THis", $event->dtstart) - $add_minutes_start * 60,
'end' => DateTime::createFromFormat("Ymd\THis", $event->dtend)->getTimestamp() + $add_minutes_end * 60, 'end' => parse_date("Ymd\THis", $event->dtend) + $add_minutes_end * 60,
'RID' => $rooms_import[trim($event->location)], 'RID' => $rooms_import[trim($event->location)],
'title' => trim($event->summary), 'title' => trim($event->summary),
'URL' => trim($event->url), 'URL' => trim($event->url),

@ -5,7 +5,8 @@ function admin_news() {
if (! isset($_GET["action"])) { if (! isset($_GET["action"])) {
redirect(page_link_to("news")); redirect(page_link_to("news"));
} else { }
$html = '<div class="col-md-12"><h1>' . _("Edit news entry") . '</h1>' . msg(); $html = '<div class="col-md-12"><h1>' . _("Edit news entry") . '</h1>' . msg();
if (isset($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id'])) { if (isset($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id'])) {
$news_id = $_REQUEST['id']; $news_id = $_REQUEST['id'];
@ -14,7 +15,9 @@ function admin_news() {
} }
$news = sql_select("SELECT * FROM `News` WHERE `ID`='" . sql_escape($news_id) . "' LIMIT 1"); $news = sql_select("SELECT * FROM `News` WHERE `ID`='" . sql_escape($news_id) . "' LIMIT 1");
if (count($news) > 0) { if (empty($news)) {
return error("No News found.", true);
}
switch ($_REQUEST["action"]) { switch ($_REQUEST["action"]) {
default: default:
redirect(page_link_to('news')); redirect(page_link_to('news'));
@ -22,9 +25,6 @@ function admin_news() {
list($news) = $news; list($news) = $news;
$user_source = User($news['UID']); $user_source = User($news['UID']);
if ($user_source === false) {
engelsystem_error("Unable to load user.");
}
$html .= form([ $html .= form([
form_info(_("Date"), date("Y-m-d H:i", $news['Datum'])), form_info(_("Date"), date("Y-m-d H:i", $news['Datum'])),
@ -62,10 +62,6 @@ function admin_news() {
redirect(page_link_to("news")); redirect(page_link_to("news"));
break; break;
} }
} else {
return error("No News found.", true);
}
}
return $html . '</div>'; return $html . '</div>';
} }
?> ?>

@ -26,9 +26,6 @@ function admin_questions() {
$questions = sql_select("SELECT * FROM `Questions` WHERE `AID` IS NULL"); $questions = sql_select("SELECT * FROM `Questions` WHERE `AID` IS NULL");
foreach ($questions as $question) { foreach ($questions as $question) {
$user_source = User($question['UID']); $user_source = User($question['UID']);
if ($user_source === false) {
engelsystem_error("Unable to load user.");
}
$unanswered_questions_table[] = [ $unanswered_questions_table[] = [
'from' => User_Nick_render($user_source), 'from' => User_Nick_render($user_source),
@ -45,14 +42,7 @@ function admin_questions() {
$questions = sql_select("SELECT * FROM `Questions` WHERE NOT `AID` IS NULL"); $questions = sql_select("SELECT * FROM `Questions` WHERE NOT `AID` IS NULL");
foreach ($questions as $question) { foreach ($questions as $question) {
$user_source = User($question['UID']); $user_source = User($question['UID']);
if ($user_source === false) {
engelsystem_error("Unable to load user.");
}
$answer_user_source = User($question['AID']); $answer_user_source = User($question['AID']);
if ($answer_user_source === false) {
engelsystem_error("Unable to load user.");
}
$answered_questions_table[] = [ $answered_questions_table[] = [
'from' => User_Nick_render($user_source), 'from' => User_Nick_render($user_source),
'question' => str_replace("\n", "<br />", $question['Question']), 'question' => str_replace("\n", "<br />", $question['Question']),

@ -9,7 +9,7 @@ function admin_rooms() {
$rooms = []; $rooms = [];
foreach ($rooms_source as $room) { foreach ($rooms_source as $room) {
$rooms[] = [ $rooms[] = [
'name' => $room['Name'], 'name' => Room_name_render($room),
'from_pentabarf' => $room['FromPentabarf'] == 'Y' ? '&#10003;' : '', 'from_pentabarf' => $room['FromPentabarf'] == 'Y' ? '&#10003;' : '',
'public' => $room['show'] == 'Y' ? '&#10003;' : '', 'public' => $room['show'] == 'Y' ? '&#10003;' : '',
'actions' => buttons([ 'actions' => buttons([
@ -36,20 +36,24 @@ function admin_rooms() {
} }
if (test_request_int('id')) { if (test_request_int('id')) {
$room = sql_select("SELECT * FROM `Room` WHERE `RID`='" . sql_escape($_REQUEST['id']) . "'"); $room = Room($_REQUEST['id']);
if (count($room) > 0) { if ($room === false) {
engelsystem_error("Unable to load room.");
}
if ($room == null) {
redirect(page_link_to('admin_rooms'));
}
$room_id = $_REQUEST['id']; $room_id = $_REQUEST['id'];
$name = $room[0]['Name']; $name = $room['Name'];
$from_pentabarf = $room[0]['FromPentabarf']; $from_pentabarf = $room['FromPentabarf'];
$public = $room[0]['show']; $public = $room['show'];
$number = $room[0]['Number']; $number = $room['Number'];
$needed_angeltypes = sql_select("SELECT * FROM `NeededAngelTypes` WHERE `room_id`='" . sql_escape($room_id) . "'"); $needed_angeltypes = sql_select("SELECT * FROM `NeededAngelTypes` WHERE `room_id`='" . sql_escape($room_id) . "'");
foreach ($needed_angeltypes as $needed_angeltype) { foreach ($needed_angeltypes as $needed_angeltype) {
$angeltypes_count[$needed_angeltype['angel_type_id']] = $needed_angeltype['count']; $angeltypes_count[$needed_angeltype['angel_type_id']] = $needed_angeltype['count'];
} }
} else {
redirect(page_link_to('admin_rooms'));
}
} }
if ($_REQUEST['show'] == 'edit') { if ($_REQUEST['show'] == 'edit') {
@ -106,15 +110,12 @@ function admin_rooms() {
engelsystem_log("Room created: " . $name . ", pentabarf import: " . $from_pentabarf . ", public: " . $public . ", number: " . $number); engelsystem_log("Room created: " . $name . ", pentabarf import: " . $from_pentabarf . ", public: " . $public . ", number: " . $number);
} }
sql_query("DELETE FROM `NeededAngelTypes` WHERE `room_id`='" . sql_escape($room_id) . "'"); NeededAngelTypes_delete_by_room($room_id);
$needed_angeltype_info = []; $needed_angeltype_info = [];
foreach ($angeltypes_count as $angeltype_id => $angeltype_count) { foreach ($angeltypes_count as $angeltype_id => $angeltype_count) {
$angeltype = AngelType($angeltype_id); $angeltype = AngelType($angeltype_id);
if ($angeltype === false) {
engelsystem_error("Unable to load angeltype.");
}
if ($angeltype != null) { if ($angeltype != null) {
sql_query("INSERT INTO `NeededAngelTypes` SET `room_id`='" . sql_escape($room_id) . "', `angel_type_id`='" . sql_escape($angeltype_id) . "', `count`='" . sql_escape($angeltype_count) . "'"); NeededAngelType_add(null, $angeltype_id, $room_id, $angeltype_count);
$needed_angeltype_info[] = $angeltype['name'] . ": " . $angeltype_count; $needed_angeltype_info[] = $angeltype['name'] . ": " . $angeltype_count;
} }
} }

@ -9,7 +9,7 @@ function admin_shifts() {
$valid = true; $valid = true;
$rid = 0; $rid = 0;
$start = DateTime::createFromFormat("Y-m-d H:i", date("Y-m-d") . " 00:00")->getTimestamp(); $start = parse_date("Y-m-d H:i", date("Y-m-d") . " 00:00");
$end = $start; $end = $start;
$mode = 'single'; $mode = 'single';
$angelmode = 'manually'; $angelmode = 'manually';
@ -71,15 +71,15 @@ function admin_shifts() {
error(_('Please select a location.')); error(_('Please select a location.'));
} }
if (isset($_REQUEST['start']) && $tmp = DateTime::createFromFormat("Y-m-d H:i", trim($_REQUEST['start']))) { if (isset($_REQUEST['start']) && $tmp = parse_date("Y-m-d H:i", $_REQUEST['start'])) {
$start = $tmp->getTimestamp(); $start = $tmp;
} else { } else {
$valid = false; $valid = false;
error(_('Please select a start time.')); error(_('Please select a start time.'));
} }
if (isset($_REQUEST['end']) && $tmp = DateTime::createFromFormat("Y-m-d H:i", trim($_REQUEST['end']))) { if (isset($_REQUEST['end']) && $tmp = parse_date("Y-m-d H:i", $_REQUEST['end'])) {
$end = $tmp->getTimestamp(); $end = $tmp;
} else { } else {
$valid = false; $valid = false;
error(_('Please select an end time.')); error(_('Please select an end time.'));
@ -188,7 +188,7 @@ function admin_shifts() {
} while ($shift_end < $end); } while ($shift_end < $end);
} elseif ($mode == 'variable') { } elseif ($mode == 'variable') {
rsort($change_hours); rsort($change_hours);
$day = DateTime::createFromFormat("Y-m-d H:i", date("Y-m-d", $start) . " 00:00")->getTimestamp(); $day = parse_date("Y-m-d H:i", date("Y-m-d", $start) . " 00:00");
$change_index = 0; $change_index = 0;
// Ersten/nächsten passenden Schichtwechsel suchen // Ersten/nächsten passenden Schichtwechsel suchen
foreach ($change_hours as $i => $change_hour) { foreach ($change_hours as $i => $change_hour) {
@ -205,7 +205,7 @@ function admin_shifts() {
$shift_start = $start; $shift_start = $start;
do { do {
$day = DateTime::createFromFormat("Y-m-d H:i", date("Y-m-d", $shift_start) . " 00:00")->getTimestamp(); $day = parse_date("Y-m-d H:i", date("Y-m-d", $shift_start) . " 00:00");
$shift_end = $day + $change_hours[$change_index] * 60 * 60; $shift_end = $day + $change_hours[$change_index] * 60 * 60;
if ($shift_end > $end) { if ($shift_end > $end) {

@ -16,9 +16,6 @@ function admin_user() {
$user_id = $_REQUEST['id']; $user_id = $_REQUEST['id'];
if (! isset($_REQUEST['action'])) { if (! isset($_REQUEST['action'])) {
$user_source = User($user_id); $user_source = User($user_id);
if ($user_source === false) {
engelsystem_error('Unable to load user.');
}
if ($user_source == null) { if ($user_source == null) {
error(_('This user does not exist.')); error(_('This user does not exist.'));
redirect(users_link()); redirect(users_link());

@ -104,8 +104,8 @@ function guest_register() {
$msg .= error(sprintf(_("Your password is too short (please use at least %s characters)."), MIN_PASSWORD_LENGTH), true); $msg .= error(sprintf(_("Your password is too short (please use at least %s characters)."), MIN_PASSWORD_LENGTH), true);
} }
if (isset($_REQUEST['planned_arrival_date']) && DateTime::createFromFormat("Y-m-d", trim($_REQUEST['planned_arrival_date']))) { if (isset($_REQUEST['planned_arrival_date']) && $tmp = parse_date("Y-m-d", $_REQUEST['planned_arrival_date'])) {
$planned_arrival_date = DateTime::createFromFormat("Y-m-d", trim($_REQUEST['planned_arrival_date']))->getTimestamp(); $planned_arrival_date = $tmp;
} else { } else {
$valid = false; $valid = false;
$msg .= error(_("Please enter your planned date of arrival."), true); $msg .= error(_("Please enter your planned date of arrival."), true);

@ -47,13 +47,7 @@ function user_messages() {
foreach ($messages as $message) { foreach ($messages as $message) {
$sender_user_source = User($message['SUID']); $sender_user_source = User($message['SUID']);
if ($sender_user_source === false) {
engelsystem_error(_("Unable to load user."));
}
$receiver_user_source = User($message['RUID']); $receiver_user_source = User($message['RUID']);
if ($receiver_user_source === false) {
engelsystem_error(_("Unable to load user."));
}
$messages_table_entry = [ $messages_table_entry = [
'new' => $message['isRead'] == 'N' ? '<span class="glyphicon glyphicon-envelope"></span>' : '', 'new' => $message['isRead'] == 'N' ? '<span class="glyphicon glyphicon-envelope"></span>' : '',

@ -62,9 +62,6 @@ function display_news($news) {
$html .= '<span class="glyphicon glyphicon-time"></span> ' . date("Y-m-d H:i", $news['Datum']) . '&emsp;'; $html .= '<span class="glyphicon glyphicon-time"></span> ' . date("Y-m-d H:i", $news['Datum']) . '&emsp;';
$user_source = User($news['UID']); $user_source = User($news['UID']);
if ($user_source === false) {
engelsystem_error(_("Unable to load user."));
}
$html .= User_Nick_render($user_source); $html .= User_Nick_render($user_source);
if ($page != "news_comments") { if ($page != "news_comments") {
@ -94,9 +91,6 @@ function user_news_comments() {
$comments = sql_select("SELECT * FROM `NewsComments` WHERE `Refid`='" . sql_escape($nid) . "' ORDER BY 'ID'"); $comments = sql_select("SELECT * FROM `NewsComments` WHERE `Refid`='" . sql_escape($nid) . "' ORDER BY 'ID'");
foreach ($comments as $comment) { foreach ($comments as $comment) {
$user_source = User($comment['UID']); $user_source = User($comment['UID']);
if ($user_source === false) {
engelsystem_error(_("Unable to load user."));
}
$html .= '<div class="panel panel-default">'; $html .= '<div class="panel panel-default">';
$html .= '<div class="panel-body">' . nl2br($comment['Text']) . '</div>'; $html .= '<div class="panel-body">' . nl2br($comment['Text']) . '</div>';

@ -13,9 +13,6 @@ function user_questions() {
$answered_questions = sql_select("SELECT * FROM `Questions` WHERE NOT `AID` IS NULL AND `UID`='" . sql_escape($user['UID']) . "'"); $answered_questions = sql_select("SELECT * FROM `Questions` WHERE NOT `AID` IS NULL AND `UID`='" . sql_escape($user['UID']) . "'");
foreach ($answered_questions as &$question) { foreach ($answered_questions as &$question) {
$answer_user_source = User($question['AID']); $answer_user_source = User($question['AID']);
if ($answer_user_source === false) {
engelsystem_error(_("Unable to load user."));
}
$question['answer_user'] = User_Nick_render($answer_user_source); $question['answer_user'] = User_Nick_render($answer_user_source);
} }

@ -56,16 +56,16 @@ function user_settings() {
$valid = false; $valid = false;
} }
if (isset($_REQUEST['planned_arrival_date']) && DateTime::createFromFormat("Y-m-d", trim($_REQUEST['planned_arrival_date']))) { if (isset($_REQUEST['planned_arrival_date']) && $tmp = parse_date("Y-m-d", $_REQUEST['planned_arrival_date'])) {
$planned_arrival_date = DateTime::createFromFormat("Y-m-d", trim($_REQUEST['planned_arrival_date']))->getTimestamp(); $planned_arrival_date = $tmp;
} else { } else {
$valid = false; $valid = false;
$msg .= error(_("Please enter your planned date of arrival."), true); $msg .= error(_("Please enter your planned date of arrival."), true);
} }
if (isset($_REQUEST['planned_departure_date']) && $_REQUEST['planned_departure_date'] != '') { if (isset($_REQUEST['planned_departure_date']) && $_REQUEST['planned_departure_date'] != '') {
if (DateTime::createFromFormat("Y-m-d", trim($_REQUEST['planned_departure_date']))) { if ($tmp = parse_date("Y-m-d", $_REQUEST['planned_departure_date'])) {
$planned_departure_date = DateTime::createFromFormat("Y-m-d", trim($_REQUEST['planned_departure_date']))->getTimestamp(); $planned_departure_date = $tmp;
} else { } else {
$valid = false; $valid = false;
$msg .= error(_("Please enter your planned date of departure."), true); $msg .= error(_("Please enter your planned date of departure."), true);

File diff suppressed because it is too large Load Diff

@ -129,6 +129,8 @@ function make_navigation() {
} }
} }
$menu = make_room_navigation($menu);
$admin_menu = []; $admin_menu = [];
$admin_pages = [ $admin_pages = [
"admin_arrive" => admin_arrive_title(), "admin_arrive" => admin_arrive_title(),
@ -158,6 +160,36 @@ function make_navigation() {
return toolbar($menu); return toolbar($menu);
} }
/**
* Adds room navigation to the given menu.
*
* @param string[] $menu
* Rendered menu
*/
function make_room_navigation($menu) {
global $privileges;
if (! in_array('view_rooms', $privileges)) {
return $menu;
}
$rooms = Rooms();
$room_menu = [];
if (in_array('admin_rooms', $privileges)) {
$room_menu[] = toolbar_item_link(page_link_to('admin_rooms'), 'list', _("Manage rooms"));
}
if (count($room_menu) > 0) {
$room_menu[] = toolbar_item_divider();
}
foreach ($rooms as $room) {
$room_menu[] = toolbar_item_link(room_link($room), 'map-marker', $room['Name']);
}
if (count($room_menu > 0)) {
$menu[] = toolbar_dropdown('map-marker', _("Rooms"), $room_menu);
}
return $menu;
}
function make_menu() { function make_menu() {
return make_navigation(); return make_navigation();
} }

@ -1,5 +1,52 @@
<?php <?php
/**
* Provide page/request helper functions
*/
/**
* Parse a date from da day and a time textfield.
*
* @param string $date_name
* Name of the textfield containing the day (format Y-m-d)
* @param string $time_name
* Name of the textfield containing the time (format H:i)
* @param string[] $allowed_days
* List of allowed days in format Y-m-d
* @param int $default_value
* Default value unix timestamp
*/
function check_request_datetime($date_name, $time_name, $allowed_days, $default_value) {
$time = date("H:i", $default_value);
$day = date("Y-m-d", $default_value);
if (isset($_REQUEST[$time_name]) && preg_match('#^\d{1,2}:\d\d$#', trim($_REQUEST[$time_name]))) {
$time = trim($_REQUEST[$time_name]);
}
if (isset($_REQUEST[$date_name]) && in_array($_REQUEST[$date_name], $allowed_days)) {
$day = $_REQUEST[$date_name];
}
return parse_date("Y-m-d H:i", $day . " " . $time);
}
/**
* Parse a date into unix timestamp
*
* @param string $pattern
* The date pattern (i.e. Y-m-d H:i)
* @param string $value
* The string to parse
* @return The parsed unix timestamp
*/
function parse_date($pattern, $value) {
$datetime = DateTime::createFromFormat($pattern, trim($value));
if ($datetime == null) {
return null;
}
return $datetime->getTimestamp();
}
/** /**
* Leitet den Browser an die übergebene URL weiter und hält das Script an. * Leitet den Browser an die übergebene URL weiter und hält das Script an.
*/ */
@ -12,12 +59,44 @@ function redirect($url) {
* Echoes given output and dies. * Echoes given output and dies.
* *
* @param String $output * @param String $output
* String to display
*/ */
function raw_output($output) { function raw_output($output) {
echo $output; echo $output;
die(); die();
} }
/**
* Helper function for transforming list of entities into array for select boxes.
*
* @param array $data
* The data array
* @param string $key_name
* name of the column to use as id/key
* @param string $value_name
* name of the column to use as displayed value
*/
function select_array($data, $key_name, $value_name) {
$ret = [];
foreach ($data as $value) {
$ret[$value[$key_name]] = $value[$value_name];
}
return $ret;
}
/**
* Returns an int[] from given request param name.
*
* @param String $name
* Name of the request param
*/
function check_request_int_array($name) {
if (isset($_REQUEST[$name]) && is_array($_REQUEST[$name])) {
return array_filter($_REQUEST[$name], 'is_numeric');
}
return [];
}
/** /**
* Checks if given request item (name) can be parsed to a date. * Checks if given request item (name) can be parsed to a date.
* If not parsable, given error message is put into msg() and null is returned. * If not parsable, given error message is put into msg() and null is returned.
@ -50,8 +129,8 @@ function check_request_date($name, $error_message = null, $null_allowed = false)
* @return ValidationResult containing the parsed date * @return ValidationResult containing the parsed date
*/ */
function check_date($input, $error_message = null, $null_allowed = false) { function check_date($input, $error_message = null, $null_allowed = false) {
if (DateTime::createFromFormat("Y-m-d", trim($input))) { if ($tmp = parse_date("Y-m-d", trim($input))) {
return new ValidationResult(true, DateTime::createFromFormat("Y-m-d", trim($input))->getTimestamp()); return new ValidationResult(true, $tmp);
} }
if ($null_allowed) { if ($null_allowed) {
return new ValidationResult(true, null); return new ValidationResult(true, null);

@ -42,8 +42,11 @@ function glyph_bool($boolean) {
} }
function div($class, $content = [], $dom_id = "") { function div($class, $content = [], $dom_id = "") {
if (is_array($content)) {
$content = join("\n", $content);
}
$dom_id = $dom_id != '' ? ' id="' . $dom_id . '"' : ''; $dom_id = $dom_id != '' ? ' id="' . $dom_id . '"' : '';
return '<div' . $dom_id . ' class="' . $class . '">' . join("\n", $content) . '</div>'; return '<div' . $dom_id . ' class="' . $class . '">' . $content . '</div>';
} }
function heading($content, $number = 1) { function heading($content, $number = 1) {
@ -60,6 +63,10 @@ function toolbar($items = [], $right = false) {
return '<ul class="nav navbar-nav' . ($right ? ' navbar-right' : '') . '">' . join("\n", $items) . '</ul>'; return '<ul class="nav navbar-nav' . ($right ? ' navbar-right' : '') . '">' . join("\n", $items) . '</ul>';
} }
function toolbar_pills($items) {
return '<ul class="nav nav-pills">' . join("\n", $items) . '</ul>';
}
/** /**
* Render a link for a toolbar. * Render a link for a toolbar.
* *
@ -374,11 +381,11 @@ function render_table($columns, $rows, $data = true) {
foreach ($rows as $row) { foreach ($rows as $row) {
$html .= '<tr>'; $html .= '<tr>';
foreach ($columns as $key => $column) { foreach ($columns as $key => $column) {
$value = "&nbsp;";
if (isset($row[$key])) { if (isset($row[$key])) {
$html .= '<td class="column_' . $key . '">' . $row[$key] . '</td>'; $value = $row[$key];
} else {
$html .= '<td class="column_' . $key . '">&nbsp;</td>';
} }
$html .= '<td class="column_' . $key . '">' . $value . '</td>';
} }
$html .= '</tr>'; $html .= '</tr>';
} }

@ -1,8 +1,17 @@
<?php <?php
use Engelsystem\ShiftsFilterRenderer;
use Engelsystem\ShiftCalendarRenderer;
function Room_view($room, ShiftsFilterRenderer $shiftsFilterRenderer, ShiftCalendarRenderer $shiftCalendarRenderer) {
return page_with_title(glyph('map-marker') . $room['Name'], [
$shiftsFilterRenderer->render(room_link($room)) ,
$shiftCalendarRenderer->render()
]);
}
function Room_name_render($room) { function Room_name_render($room) {
global $privileges; global $privileges;
if (in_array('admin_rooms', $privileges)) { if (in_array('view_rooms', $privileges)) {
return '<a href="' . room_link($room) . '">' . glyph('map-marker') . $room['Name'] . '</a>'; return '<a href="' . room_link($room) . '">' . glyph('map-marker') . $room['Name'] . '</a>';
} }
return glyph('map-marker') . $room['Name']; return glyph('map-marker') . $room['Name'];

@ -0,0 +1,63 @@
<?php
namespace Engelsystem;
/**
* Represents a single lane in a shifts calendar.
*/
class ShiftCalendarLane {
private $firstBlockStartTime;
private $blockCount;
private $header;
private $shifts = [];
public function __construct($header, $firstBlockStartTime, $blockCount) {
$this->header = $header;
$this->firstBlockStartTime = $firstBlockStartTime;
$this->blockCount = $blockCount;
}
/**
* Adds a shift to the lane, but only if it fits.
* Returns true on success.
*
* @param Shift $shift
* The shift to add
* @return boolean true on success
*/
public function addShift($shift) {
if ($this->shiftFits($shift)) {
$this->shifts[] = $shift;
return true;
}
return false;
}
/**
* Returns true if given shift fits into this lane.
*
* @param Shift $shift
* The shift to fit into this lane
*/
public function shiftFits($newShift) {
foreach ($this->shifts as $laneShift) {
if (! ($newShift['start'] >= $laneShift['end'] || $newShift['end'] <= $laneShift['start'])) {
return false;
}
}
return true;
}
public function getHeader() {
return $this->header;
}
public function getShifts() {
return $this->shifts;
}
}
?>

@ -0,0 +1,208 @@
<?php
namespace Engelsystem;
class ShiftCalendarRenderer {
/**
* 15m * 60s/m = 900s
*/
const SECONDS_PER_ROW = 900;
/**
* Height of a block in pixel.
* Do not change - corresponds with theme/css
*/
const BLOCK_HEIGHT = 30;
/**
* Distance between two shifts in pixels
*/
const MARGIN = 5;
private $lanes;
private $shiftsFilter;
private $firstBlockStartTime = null;
private $blocksPerSlot = null;
public function __construct($shifts, ShiftsFilter $shiftsFilter) {
$this->shiftsFilter = $shiftsFilter;
$this->firstBlockStartTime = $this->calcFirstBlockStartTime($shifts);
$this->lanes = $this->assignShiftsToLanes($shifts);
}
/**
* Assigns the shifts to different lanes per room if they collide
*
* @param Shift[] $shifts
* The shifts to assign
*
* @return Returns an array that assigns a room_id to an array of ShiftCalendarLane containing the shifts
*/
private function assignShiftsToLanes($shifts) {
// array that assigns a room id to a list of lanes (per room)
$lanes = [];
foreach ($shifts as $shift) {
$room_id = $shift['RID'];
if (! isset($lanes[$room_id])) {
// initialize room with one lane
$header = Room_name_render([
'RID' => $room_id,
'Name' => $shift['room_name']
]);
$lanes[$room_id] = [
new ShiftCalendarLane($header, $this->getFirstBlockStartTime(), $this->getBlocksPerSlot())
];
}
// Try to add the shift to the existing lanes for this room
$shift_added = false;
foreach ($lanes[$room_id] as $lane) {
$shift_added = $lane->addShift($shift);
if ($shift_added == true) {
break;
}
}
// If all lanes for this room are busy, create a new lane and add shift to it
if ($shift_added == false) {
$newLane = new ShiftCalendarLane("", $this->getFirstBlockStartTime(), $this->getBlocksPerSlot());
if (! $newLane->addShift($shift)) {
engelsystem_error("Unable to add shift to new lane.");
}
$lanes[$room_id][] = $newLane;
}
}
return $lanes;
}
public function getFirstBlockStartTime() {
return $this->firstBlockStartTime;
}
public function getBlocksPerSlot() {
if ($this->blocksPerSlot == null) {
$this->blocksPerSlot = $this->calcBlocksPerSlot();
}
return $this->blocksPerSlot;
}
/**
* Renders the whole calendar
*
* @return the generated html
*/
public function render() {
return div('shift-calendar', [
$this->renderTimeLane(),
$this->renderShiftLanes()
]);
}
/**
* Renders the lanes containing the shifts
*/
private function renderShiftLanes() {
$html = "";
foreach ($this->lanes as $room_lanes) {
foreach ($room_lanes as $lane) {
$html .= $this->renderLane($lane);
}
}
return $html;
}
/**
* Renders a single lane
*
* @param ShiftCalendarLane $lane
* The lane to render
*/
private function renderLane(ShiftCalendarLane $lane) {
$shift_renderer = new ShiftCalendarShiftRenderer();
$html = "";
$rendered_until = $this->getFirstBlockStartTime();
foreach ($lane->getShifts() as $shift) {
while ($rendered_until + ShiftCalendarRenderer::SECONDS_PER_ROW <= $shift['start']) {
$html .= $this->renderTick($rendered_until);
$rendered_until += ShiftCalendarRenderer::SECONDS_PER_ROW;
}
list($shift_height, $shift_html) = $shift_renderer->render($shift);
$html .= $shift_html;
$rendered_until += $shift_height * ShiftCalendarRenderer::SECONDS_PER_ROW;
}
while ($rendered_until <= $this->shiftsFilter->getEndTime()) {
$html .= $this->renderTick($rendered_until);
$rendered_until += ShiftCalendarRenderer::SECONDS_PER_ROW;
}
return div('lane', [
div('header', $lane->getHeader()),
$html
]);
}
/**
* Renders a tick/block for given time
*
* @param int $time
* unix timestamp
* @param boolean $label
* Should time labels be generated?
* @return rendered tick html
*/
private function renderTick($time, $label = false) {
if ($time % (24 * 60 * 60) == 23 * 60 * 60) {
if (! $label) {
return div('tick day');
}
return div('tick day', [
date('Y-m-d<b\r />H:i', $time)
]);
} elseif ($time % (60 * 60) == 0) {
if (! $label) {
return div('tick hour');
}
return div('tick hour', [
date('H:i', $time)
]);
}
return div('tick');
}
/**
* Renders the left time lane including hour/day ticks
*/
private function renderTimeLane() {
$time_slot = [
div('header', [
_("Time")
])
];
for ($block = 0; $block < $this->getBlocksPerSlot(); $block ++) {
$thistime = $this->getFirstBlockStartTime() + ($block * ShiftCalendarRenderer::SECONDS_PER_ROW);
$time_slot[] = $this->renderTick($thistime, true);
}
return div('lane time', $time_slot);
}
private function calcFirstBlockStartTime($shifts) {
$start_time = $this->shiftsFilter->getEndTime();
foreach ($shifts as $shift) {
if ($shift['start'] < $start_time) {
$start_time = $shift['start'];
}
}
return ShiftCalendarRenderer::SECONDS_PER_ROW * floor(($start_time - 60 * 60) / ShiftCalendarRenderer::SECONDS_PER_ROW);
}
private function calcBlocksPerSlot() {
return ceil(($this->shiftsFilter->getEndTime() - $this->getFirstBlockStartTime()) / ShiftCalendarRenderer::SECONDS_PER_ROW);
}
}
?>

@ -0,0 +1,188 @@
<?php
namespace Engelsystem;
/**
* Renders a single shift for the shift calendar
*/
class ShiftCalendarShiftRenderer {
/**
* Renders a shift
*
* @param Shift $shift
* The shift to render
*/
public function render($shift) {
global $privileges;
$collides = $this->collides();
$info_text = "";
if ($shift['title'] != '') {
$info_text = glyph('info-sign') . $shift['title'] . '<br>';
}
list($is_free, $shifts_row) = $this->renderShiftNeededAngeltypes($shift, $collides);
if (isset($shift['own']) && $shift['own'] && ! in_array('user_shifts_admin', $privileges)) {
$class = 'primary';
} elseif ($collides && ! in_array('user_shifts_admin', $privileges)) {
$class = 'default';
} elseif ($is_free) {
$class = 'danger';
} else {
$class = 'success';
}
$blocks = ceil(($shift["end"] - $shift["start"]) / ShiftCalendarRenderer::SECONDS_PER_ROW);
$blocks = max(1, $blocks);
return [
$blocks,
'<td class="shift" rowspan="' . $blocks . '">' . div('shift panel panel-' . $class . '" style="height: ' . ($blocks * ShiftCalendarRenderer::BLOCK_HEIGHT - ShiftCalendarRenderer::MARGIN) . 'px"', [
$this->renderShiftHead($shift),
div('panel-body', [
$info_text,
Room_name_render([
'RID' => $shift['RID'],
'Name' => $shift['room_name']
])
]),
$shifts_row,
div('shift-spacer')
]) . '</td>'
];
}
private function renderShiftNeededAngeltypes($shift, $collides) {
global $privileges;
$html = "";
$is_free = false;
$angeltypes = NeededAngelTypes_by_shift($shift['SID']);
foreach ($angeltypes as $angeltype) {
list($angeltype_free, $angeltype_html) = $this->renderShiftNeededAngeltype($shift, $angeltype, $collides);
$is_free |= $angeltype_free;
$html .= $angeltype_html;
}
if (in_array('user_shifts_admin', $privileges)) {
$html .= '<li class="list-group-item">' . button(page_link_to('user_shifts') . '&amp;shift_id=' . $shift['SID'] . '&amp;type_id=' . $angeltype['id'], _("Add more angels"), 'btn-xs') . '</li>';
}
if ($html != '') {
return [
$is_free,
'<ul class="list-group">' . $html . '</ul>'
];
}
return [
$is_free,
""
];
}
/**
* Renders a list entry containing the needed angels for an angeltype
*
* @param Shift $shift
* The shift which is rendered
* @param Angeltype $angeltype
* The angeltype, containing informations about needed angeltypes and already signed up angels
* @param boolean $collides
* true if the shift collides with the users shifts
*/
private function renderShiftNeededAngeltype($shift, $angeltype, $collides) {
global $privileges;
$is_free = false;
$entry_list = [];
$freeloader = 0;
foreach ($angeltype['shift_entries'] as $entry) {
$style = '';
if ($entry['freeloaded']) {
$freeloader ++;
$style = " text-decoration: line-through;";
}
$entry_list[] = "<span style=\"$style\">" . User_Nick_render(User($entry['UID'])) . "</span>";
}
if ($angeltype['count'] - count($angeltype['shift_entries']) - $freeloader > 0) {
$inner_text = sprintf(ngettext("%d helper needed", "%d helpers needed", $angeltype['count'] - count($angeltype['shift_entries'])), $angeltype['count'] - count($angeltype['shift_entries']));
// is the shift still running or alternatively is the user shift admin?
$user_may_join_shift = true;
// you cannot join if user alread joined a parallel or this shift
$user_may_join_shift &= ! $collides;
// you cannot join if user is not of this angel type
$user_may_join_shift &= isset($angeltype['user_id']);
// you cannot join if you are not confirmed
if ($angeltype['restricted'] == 1 && isset($angeltype['user_id'])) {
$user_may_join_shift &= isset($angeltype['confirm_user_id']);
}
// you can only join if the shift is in future or running
$user_may_join_shift &= time() < $shift['start'];
// User shift admins may join anybody in every shift
$user_may_join_shift |= in_array('user_shifts_admin', $privileges);
if ($user_may_join_shift) {
$entry_list[] = '<a href="' . page_link_to('user_shifts') . '&amp;shift_id=' . $shift['SID'] . '&amp;type_id=' . $angeltype['id'] . '">' . $inner_text . '</a> ' . button(page_link_to('user_shifts') . '&amp;shift_id=' . $shift['SID'] . '&amp;type_id=' . $angeltype['id'], _('Sign up'), 'btn-xs btn-primary');
} else {
if (time() > $shift['start']) {
$entry_list[] = $inner_text . ' (' . _('ended') . ')';
} elseif ($angeltype['restricted'] == 1 && isset($angeltype['user_id']) && ! isset($angeltype['confirm_user_id'])) {
$entry_list[] = $inner_text . glyph('lock');
} elseif ($angeltype['restricted'] == 1) {
$entry_list[] = $inner_text;
} elseif ($collides) {
$entry_list[] = $inner_text;
} else {
$entry_list[] = $inner_text . '<br />' . button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], sprintf(_('Become %s'), $angeltype['name']), 'btn-xs');
}
}
unset($inner_text);
$is_free = true;
}
$shifts_row = '<li class="list-group-item">';
$shifts_row .= '<strong>' . AngelType_name_render($angeltype) . ':</strong> ';
$shifts_row .= join(", ", $entry_list);
$shifts_row .= '</li>';
return [
$is_free,
$shifts_row
];
}
/**
* Renders the shift header
*
* @param Shift $shift
* The shift
*/
private function renderShiftHead($shift) {
global $privileges;
$header_buttons = "";
if (in_array('admin_shifts', $privileges)) {
$header_buttons = '<div class="pull-right">' . table_buttons([
button(page_link_to('user_shifts') . '&edit_shift=' . $shift['SID'], glyph('edit'), 'btn-xs'),
button(page_link_to('user_shifts') . '&delete_shift=' . $shift['SID'], glyph('trash'), 'btn-xs')
]) . '</div>';
}
$shift_heading = date('H:i', $shift['start']) . ' &dash; ' . date('H:i', $shift['end']) . ' &mdash; ' . ShiftType($shift['shifttype_id'])['name'];
return div('panel-heading', [
'<a href="' . shift_link($shift) . '">' . $shift_heading . '</a>',
$header_buttons
]);
}
/**
* Does the shift collide with the user's shifts
*/
private function collides() {
// TODO
return false;
}
}
?>

@ -0,0 +1,69 @@
<?php
namespace Engelsystem;
class ShiftsFilterRenderer {
/**
* The shiftFilter to render.
*
* @var ShiftsFilter
*/
private $shiftsFilter;
/**
* Should the filter display a day selection.
*
* @var boolean
*/
private $daySelectionEnabled = false;
/**
* Days that can be selected.
* Format Y-m-d
*
* @var string[]
*/
private $days = [];
public function __construct(ShiftsFilter $shiftsFilter) {
$this->shiftsFilter = $shiftsFilter;
}
/**
* Renders the filter.
*
* @return Generated HTML
*/
public function render($link_base) {
$toolbar = [];
if ($this->daySelectionEnabled && ! empty($this->days)) {
$selected_day = date("Y-m-d", $this->shiftsFilter->getStartTime());
$day_dropdown_items = [];
foreach ($this->days as $day) {
$day_dropdown_items[] = toolbar_item_link($link_base . '&shifts_filter_day=' . $day, '', $day);
}
$toolbar[] = toolbar_dropdown('', $selected_day, $day_dropdown_items, 'active');
}
return div('form-group', [
toolbar_pills($toolbar)
]);
}
/**
* Should the filter display a day selection.
*/
public function enableDaySelection($days) {
$this->daySelectionEnabled = true;
$this->days = $days;
}
/**
* Should the filter display a day selection.
*/
public function isDaySelectionEnabled() {
return $this->daySelectionEnabled;
}
}
?>

@ -16,9 +16,6 @@ function Shift_signup_button_render($shift, $angeltype, $user_angeltype = null,
if ($user_angeltype == null) { if ($user_angeltype == null) {
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype); $user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
if ($user_angeltype === false) {
engelsystem_error('Unable to load user angeltype.');
}
} }
if (Shift_signup_allowed($shift, $angeltype, $user_angeltype, $user_shifts)) { if (Shift_signup_allowed($shift, $angeltype, $user_angeltype, $user_shifts)) {

@ -0,0 +1,24 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.5/phpunit.xsd"
backupGlobals="false"
bootstrap="./includes/engelsystem_provider.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false">
<testsuites>
<testsuite name="Models">
<directory>./test/model/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./include/</directory>
<directory>./public/</directory>
</whitelist>
</filter>
<php>
<const name="PHPUNIT_TESTSUITE" value="true" />
</php>
</phpunit>

@ -6730,38 +6730,46 @@ body {
.footer a { .footer a {
color: #777777; color: #777777;
} }
#shifts td.free { .shift-calendar {
border: 1px solid #d9534f; display: flex;
background-color: #f2dede; flex-direction: row;
} flex-wrap: nowrap;
a#shifts td.free:hover, align-itmes: stretch;
a#shifts td.free:focus { width: 100%;
background-color: #e4b9b9;
} }
#shifts td.occupied { .shift-calendar .lane {
border: 1px solid #5cb85c; background: #f9f9f9;
background-color: #dff0d8; min-width: 300px;
width: 300px;
flex-grow: 1;
} }
a#shifts td.occupied:hover, .shift-calendar .lane .header {
a#shifts td.occupied:focus { background: #fff;
background-color: #c1e2b3; height: 30px;
padding: 5px;
} }
#shifts td.collides { .shift-calendar .lane .tick {
border: 1px solid #f0ad4e; height: 30px;
background-color: #fcf8e3; border-top: 1px solid #f4f4f4;
} }
a#shifts td.collides:hover, .shift-calendar .lane .tick.hour {
a#shifts td.collides:focus { border-top: 2px solid #dddddd;
background-color: #f7ecb5; font-size: 0.9em;
padding-left: 5px;
} }
#shifts td.own { .shift-calendar .lane .tick.day {
border: 1px solid #777777; border-top: 2px solid #337ab7;
font-size: 0.9em;
padding-left: 5px;
} }
.row-day { .shift-calendar .lane.time {
border-top: 2px solid #777777; min-width: 100px;
width: 100px;
flex-grow: 0;
} }
.row-header { .shift-calendar .shift {
min-width: 90px; margin: 0 5px 5px 0;
overflow: hidden;
} }
.space-top { .space-top {
margin-top: 15px; margin-top: 15px;

@ -6753,38 +6753,46 @@ body {
.footer a { .footer a {
color: #888888; color: #888888;
} }
#shifts td.free { .shift-calendar {
border: 1px solid #d9534f; display: flex;
background-color: #d9534f; flex-direction: row;
} flex-wrap: nowrap;
a#shifts td.free:hover, align-itmes: stretch;
a#shifts td.free:focus { width: 100%;
background-color: #c9302c;
} }
#shifts td.occupied { .shift-calendar .lane {
border: 1px solid #5cb85c; background: #080808;
background-color: #5cb85c; min-width: 300px;
width: 300px;
flex-grow: 1;
} }
a#shifts td.occupied:hover, .shift-calendar .lane .header {
a#shifts td.occupied:focus { background: #fff;
background-color: #449d44; height: 30px;
padding: 5px;
} }
#shifts td.collides { .shift-calendar .lane .tick {
border: 1px solid #f0ad4e; height: 30px;
background-color: #f0ad4e; border-top: 1px solid #030303;
} }
a#shifts td.collides:hover, .shift-calendar .lane .tick.hour {
a#shifts td.collides:focus { border-top: 2px solid #282828;
background-color: #ec971f; font-size: 0.9em;
padding-left: 5px;
} }
#shifts td.own { .shift-calendar .lane .tick.day {
border: 1px solid #888888; border-top: 2px solid #428bca;
font-size: 0.9em;
padding-left: 5px;
} }
.row-day { .shift-calendar .lane.time {
border-top: 2px solid #888888; min-width: 100px;
width: 100px;
flex-grow: 0;
} }
.row-header { .shift-calendar .shift {
min-width: 90px; margin: 0 5px 5px 0;
overflow: hidden;
} }
.space-top { .space-top {
margin-top: 15px; margin-top: 15px;

@ -6730,38 +6730,46 @@ body {
.footer a { .footer a {
color: #777777; color: #777777;
} }
#shifts td.free { .shift-calendar {
border: 1px solid #7f528b; display: flex;
background-color: #f1eaf2; flex-direction: row;
} flex-wrap: nowrap;
a#shifts td.free:hover, align-itmes: stretch;
a#shifts td.free:focus { width: 100%;
background-color: #dbcadf;
} }
#shifts td.occupied { .shift-calendar .lane {
border: 1px solid #7b9c41; background: #f9f9f9;
background-color: #f0f5e7; min-width: 300px;
width: 300px;
flex-grow: 1;
} }
a#shifts td.occupied:hover, .shift-calendar .lane .header {
a#shifts td.occupied:focus { background: #fff;
background-color: #d9e6c3; height: 30px;
padding: 5px;
} }
#shifts td.collides { .shift-calendar .lane .tick {
border: 1px solid #e3a14d; height: 30px;
background-color: #ffffff; border-top: 1px solid #f4f4f4;
} }
a#shifts td.collides:hover, .shift-calendar .lane .tick.hour {
a#shifts td.collides:focus { border-top: 2px solid #dddddd;
background-color: #e6e6e6; font-size: 0.9em;
padding-left: 5px;
} }
#shifts td.own { .shift-calendar .lane .tick.day {
border: 1px solid #777777; border-top: 2px solid #758499;
font-size: 0.9em;
padding-left: 5px;
} }
.row-day { .shift-calendar .lane.time {
border-top: 2px solid #777777; min-width: 100px;
width: 100px;
flex-grow: 0;
} }
.row-header { .shift-calendar .shift {
min-width: 90px; margin: 0 5px 5px 0;
overflow: hidden;
} }
.space-top { .space-top {
margin-top: 15px; margin-top: 15px;

@ -6739,38 +6739,46 @@ body {
.footer a { .footer a {
color: #777777; color: #777777;
} }
#shifts td.free { .shift-calendar {
border: 1px solid #da1639; display: flex;
background-color: #f9c3cd; flex-direction: row;
} flex-wrap: nowrap;
a#shifts td.free:hover, align-itmes: stretch;
a#shifts td.free:focus { width: 100%;
background-color: #f495a6;
} }
#shifts td.occupied { .shift-calendar .lane {
border: 1px solid #39ab50; background: #f9f9f9;
background-color: #c4eccc; min-width: 300px;
width: 300px;
flex-grow: 1;
} }
a#shifts td.occupied:hover, .shift-calendar .lane .header {
a#shifts td.occupied:focus { background: #fff;
background-color: #9edfab; height: 30px;
padding: 5px;
} }
#shifts td.collides { .shift-calendar .lane .tick {
border: 1px solid #dad216; height: 30px;
background-color: #f9f7c3; border-top: 1px solid #f4f4f4;
} }
a#shifts td.collides:hover, .shift-calendar .lane .tick.hour {
a#shifts td.collides:focus { border-top: 2px solid #dddddd;
background-color: #f4f095; font-size: 0.9em;
padding-left: 5px;
} }
#shifts td.own { .shift-calendar .lane .tick.day {
border: 1px solid #777777; border-top: 2px solid #f19224;
font-size: 0.9em;
padding-left: 5px;
} }
.row-day { .shift-calendar .lane.time {
border-top: 2px solid #777777; min-width: 100px;
width: 100px;
flex-grow: 0;
} }
.row-header { .shift-calendar .shift {
min-width: 90px; margin: 0 5px 5px 0;
overflow: hidden;
} }
.space-top { .space-top {
margin-top: 15px; margin-top: 15px;

@ -9,6 +9,7 @@ $free_pages = [
'credits', 'credits',
'ical', 'ical',
'login', 'login',
'rooms',
'shifts', 'shifts',
'shifts_json_export', 'shifts_json_export',
'shifts_json_export_all', 'shifts_json_export_all',
@ -68,6 +69,8 @@ if (isset($_REQUEST['p']) && preg_match("/^[a-z0-9_]*$/i", $_REQUEST['p']) && (i
list($title, $content) = shifttypes_controller(); list($title, $content) = shifttypes_controller();
} elseif ($page == "admin_event_config") { } elseif ($page == "admin_event_config") {
list($title, $content) = event_config_edit_controller(); list($title, $content) = event_config_edit_controller();
} elseif ($page == "rooms") {
list($title, $content) = rooms_controller();
} elseif ($page == "news") { } elseif ($page == "news") {
$title = news_title(); $title = news_title();
$content = user_news(); $content = user_news();

@ -0,0 +1,86 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" type="text/css" href="public/css/theme3.css" />
<style>
</style>
</head>
<body>
<div class="shift-calendar">
<div class="lane time">
<div class="header">Time</div>
<div class="tick day">2016-12-27 00:00</div>
<div class="tick"></div>
<div class="tick"></div>
<div class="tick"></div>
<div class="tick hour">11:00</div>
<div class="tick"></div>
<div class="tick"></div>
<div class="tick"></div>
<div class="tick hour">12:00</div>
<div class="tick"></div>
<div class="tick"></div>
<div class="tick"></div>
<div class="tick hour">13:00</div>
<div class="tick"></div>
<div class="tick"></div>
<div class="tick"></div>
</div>
<div class="lane">
<div class="header">
<span class="glyphicon glyphicon-map-marker"></span> Bottle Sorting (Hall H)
</div>
<div class="tick day"></div>
<div class="tick"></div>
<div class="tick"></div>
<div class="tick"></div>
<div class="shift panel panel-success" style="height: 160px;">
<div class="panel-heading">
<a href="?p=shifts&amp;action=view&amp;shift_id=2696">00:00 02:00 — Bottle Collection</a>
<div class="pull-right">
<div class="btn-group">
<a href="?p=user_shifts&amp;edit_shift=2696" class="btn btn-default btn-xs"> <span class="glyphicon glyphicon-edit"></span>
</a> <a href="?p=user_shifts&amp;delete_shift=2696" class="btn btn-default btn-xs"> <span class="glyphicon glyphicon-trash"></span>
</a>
</div>
</div>
</div>
<div class="panel-body">
<span class="glyphicon glyphicon-info-sign"></span> Bottle Collection Quick Response Team<br> <a href="?p=rooms&amp;action=view&amp;room_id=42"> <span class="glyphicon glyphicon-map-marker"></span> Bottle Sorting (Hall H)
</a>
</div>
<ul class="list-group">
<li class="list-group-item"><strong><a href="?p=angeltypes&amp;action=view&amp;angeltype_id=104575">Angel</a>:</strong> <span style=""><a class="" href="?p=users&amp;action=view&amp;user_id=1755"><span class="icon-icon_angel"></span> Pantomime</a></span>, <span style=""><a
class="" href="?p=users&amp;action=view&amp;user_id=50"><span class="icon-icon_angel"></span> sandzwerg</a></span></li>
<li class="list-group-item"><a href="?p=user_shifts&amp;shift_id=2696&amp;type_id=104575" class="btn btn-default btn-xs">Neue Engel hinzufügen</a></li>
</ul>
<div class="shift-spacer"></div>
</div>
<div class="tick hour"></div>
<div class="tick"></div>
<div class="tick"></div>
<div class="tick"></div>
</div>
<div class="lane">
<div class="header"></div>
<div class="tick day"></div>
<div class="tick"></div>
<div class="tick"></div>
<div class="tick"></div>
<div class="tick hour"></div>
<div class="tick"></div>
<div class="tick"></div>
<div class="tick"></div>
<div class="tick hour"></div>
<div class="tick"></div>
<div class="tick"></div>
<div class="tick"></div>
<div class="tick hour"></div>
<div class="tick"></div>
<div class="tick"></div>
<div class="tick"></div>
</div>
</div>
</body>
</html>

@ -45,7 +45,6 @@
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">
<div>%task_notice%</div> <div>%task_notice%</div>
<div>%new_style_checkbox%</div>
<input class="btn btn-primary" type="submit" style="width: 75%; margin-bottom: 20px" value="%filter%"> <input class="btn btn-primary" type="submit" style="width: 75%; margin-bottom: 20px" value="%filter%">
</div> </div>
</div> </div>

@ -1,6 +1,6 @@
<?php <?php
class LogEntries_model_test extends PHPUnit_Framework_TestCase { class LogEntriesModelTest extends PHPUnit_Framework_TestCase {
public function create_LogEntry() { public function create_LogEntry() {
LogEntry_create('test', 'test'); LogEntry_create('test', 'test');

@ -1,6 +1,6 @@
<?php <?php
class Room_model_test extends PHPUnit_Framework_TestCase { class RoomModelTest extends PHPUnit_Framework_TestCase {
private $room_id = null; private $room_id = null;

@ -1,14 +0,0 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.5/phpunit.xsd"
bootstrap="../includes/engelsystem_provider.php" colors="true"
convertErrorsToExceptions="true" convertNoticesToExceptions="true"
convertWarningsToExceptions="true" forceCoversAnnotation="false">
<testsuites>
<testsuite name="Models">
<directory>model/*</directory>
</testsuite>
</testsuites>
<php>
<const name="PHPUNIT_TESTSUITE" value="true" />
</php>
</phpunit>

@ -10,32 +10,59 @@ body {
color: @text-muted; color: @text-muted;
} }
#shifts { .shift-calendar {
td { display: flex;
&.free { flex-direction: row;
border: 1px solid @brand-danger; flex-wrap: nowrap;
.bg-danger(); align-itmes: stretch;
} display: flex;
&.occupied { flex-direction: row;
border: 1px solid @brand-success; flex-wrap: nowrap;
.bg-success(); align-itmes: stretch;
width: 100%;
.lane {
background: @table-bg-accent;
flex-grow: 1;
min-width: 300px;
width: 300px;
flex-grow: 1;
.header {
background: #fff;
height: 30px;
padding: 5px;
} }
&.collides {
border: 1px solid @brand-warning; .tick {
.bg-warning(); height: 30px;
border-top: 1px solid darken(@table-bg-accent, 2%);
} }
&.own {
border: 1px solid @gray-light; .tick.hour {
border-top: 2px solid @table-border-color;
font-size: 0.9em;
padding-left: 5px;
} }
.tick.day {
border-top: 2px solid @brand-primary;
font-size: 0.9em;
padding-left: 5px;
} }
} }
.row-day { .lane.time {
border-top: 2px solid @gray-light; flex-grow: 0;
min-width: 100px;
width: 100px;
flex-grow: 0;
} }
.row-header { .shift {
min-width: 90px; margin: 0 5px 5px 0;
overflow: hidden;
}
} }
.space-top { .space-top {

Loading…
Cancel
Save