diff options
Diffstat (limited to 'includes/controller')
-rw-r--r-- | includes/controller/angeltypes_controller.php | 38 | ||||
-rw-r--r-- | includes/controller/event_config_controller.php | 3 | ||||
-rw-r--r-- | includes/controller/rooms_controller.php | 88 | ||||
-rw-r--r-- | includes/controller/shift_entries_controller.php | 168 | ||||
-rw-r--r-- | includes/controller/shifts_controller.php | 186 | ||||
-rw-r--r-- | includes/controller/shifttypes_controller.php | 6 | ||||
-rw-r--r-- | includes/controller/user_angeltypes_controller.php | 104 | ||||
-rw-r--r-- | includes/controller/user_driver_licenses_controller.php | 59 | ||||
-rw-r--r-- | includes/controller/users_controller.php | 6 |
9 files changed, 474 insertions, 184 deletions
diff --git a/includes/controller/angeltypes_controller.php b/includes/controller/angeltypes_controller.php index cb2bb2fb..548cf3e7 100644 --- a/includes/controller/angeltypes_controller.php +++ b/includes/controller/angeltypes_controller.php @@ -50,9 +50,6 @@ function angeltypes_about_controller() { } else { $angeltypes = AngelTypes(); } - if ($angeltypes === false) { - engelsystem_error("Unable to load angeltypes."); - } return [ _("Teams/Job description"), @@ -71,9 +68,6 @@ function angeltype_delete_controller() { } $angeltype = AngelType($_REQUEST['angeltype_id']); - if ($angeltype === false) { - engelsystem_error("Unable to load angeltype."); - } if ($angeltype == null) { redirect(page_link_to('angeltypes')); } @@ -109,9 +103,6 @@ function angeltype_edit_controller() { if (isset($_REQUEST['angeltype_id'])) { $angeltype = AngelType($_REQUEST['angeltype_id']); - if ($angeltype === false) { - engelsystem_error("Unable to load angeltype."); - } if ($angeltype == null) { redirect(page_link_to('angeltypes')); } @@ -121,7 +112,7 @@ function angeltype_edit_controller() { $description = $angeltype['description']; $requires_driver_license = $angeltype['requires_driver_license']; - if (! User_is_AngelType_coordinator($user, $angeltype)) { + if (! User_is_AngelType_supporter($user, $angeltype)) { redirect(page_link_to('angeltypes')); } } else { @@ -130,13 +121,13 @@ function angeltype_edit_controller() { } } - // In coordinator mode only allow to modify description - $coordinator_mode = ! in_array('admin_angel_types', $privileges); + // In supporter mode only allow to modify description + $supporter_mode = ! in_array('admin_angel_types', $privileges); if (isset($_REQUEST['submit'])) { $valid = true; - if (! $coordinator_mode) { + if (! $supporter_mode) { if (isset($_REQUEST['name'])) { $result = AngelType_validate_name($_REQUEST['name'], $angeltype); $name = $result->getValue(); @@ -177,7 +168,7 @@ function angeltype_edit_controller() { return [ sprintf(_("Edit %s"), $name), - AngelType_edit_view($name, $restricted, $description, $coordinator_mode, $requires_driver_license) + AngelType_edit_view($name, $restricted, $description, $supporter_mode, $requires_driver_license) ]; } @@ -196,23 +187,12 @@ function angeltype_controller() { } $angeltype = AngelType($_REQUEST['angeltype_id']); - if ($angeltype === false) { - engelsystem_error("Unable to load angeltype."); - } if ($angeltype == null) { redirect(page_link_to('angeltypes')); } $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']); - if ($user_driver_license === false) { - engelsystem_error("Unable to load user driver license."); - } - $members = Users_by_angeltype($angeltype); if ($members === false) { engelsystem_error("Unable to load members."); @@ -220,7 +200,7 @@ function angeltype_controller() { return [ sprintf(_("Team %s"), $angeltype['name']), - AngelType_view($angeltype, $members, $user_angeltype, in_array('admin_user_angeltypes', $privileges) || $user_angeltype['coordinator'], in_array('admin_angel_types', $privileges), $user_angeltype['coordinator'], $user_driver_license, $user) + AngelType_view($angeltype, $members, $user_angeltype, in_array('admin_user_angeltypes', $privileges) || $user_angeltype['supporter'], in_array('admin_angel_types', $privileges), $user_angeltype['supporter'], $user_driver_license, $user) ]; } @@ -235,9 +215,6 @@ function angeltypes_list_controller() { } $angeltypes = AngelTypes_with_user($user); - if ($angeltypes === false) { - engelsystem_error("Unable to load angeltypes."); - } foreach ($angeltypes as &$angeltype) { $actions = [ @@ -277,9 +254,6 @@ function load_angeltype() { } $angeltype = AngelType($_REQUEST['angeltype_id']); - if ($angeltype === false) { - engelsystem_error("Unable to load angeltype."); - } if ($angeltype == null) { error(_("Angeltype doesn't exist.")); redirect(page_link_to('angeltypes')); diff --git a/includes/controller/event_config_controller.php b/includes/controller/event_config_controller.php index a9709d38..4f07fe4c 100644 --- a/includes/controller/event_config_controller.php +++ b/includes/controller/event_config_controller.php @@ -19,9 +19,6 @@ function event_config_edit_controller() { $teardown_end_date = null; $event_config = EventConfig(); - if ($event_config === false) { - engelsystem_error('Unable to load event config.'); - } if ($event_config != null) { $event_name = $event_config['event_name']; $buildup_start_date = $event_config['buildup_start_date']; diff --git a/includes/controller/rooms_controller.php b/includes/controller/rooms_controller.php index 5d55e1b7..0e8560d5 100644 --- a/includes/controller/rooms_controller.php +++ b/includes/controller/rooms_controller.php @@ -1,7 +1,95 @@ <?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) { + 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']; } +/** + * 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; +} + ?>
\ No newline at end of file diff --git a/includes/controller/shift_entries_controller.php b/includes/controller/shift_entries_controller.php new file mode 100644 index 00000000..1b1a4d02 --- /dev/null +++ b/includes/controller/shift_entries_controller.php @@ -0,0 +1,168 @@ +<?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]; + + $shift_signup_allowed = Shift_signup_allowed(User($user_id), $shift, $type); + if (! $shift_signup_allowed->isSignupAllowed()) { + 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") . ' »</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']) . ' – ' . 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')); +} + +?>
\ No newline at end of file diff --git a/includes/controller/shifts_controller.php b/includes/controller/shifts_controller.php index b29a819f..be0cf127 100644 --- a/includes/controller/shifts_controller.php +++ b/includes/controller/shifts_controller.php @@ -12,6 +12,172 @@ function shift_edit_link($shift) { 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() { global $user, $privileges; @@ -24,33 +190,15 @@ function shift_controller() { } $shift = Shift($_REQUEST['shift_id']); - if ($shift === false) { - engelsystem_error('Unable to load shift.'); - } if ($shift == null) { - error(_('Shift could not be found.')); + error(_("Shift could not be found.")); redirect(page_link_to('user_shifts')); } $shifttype = ShiftType($shift['shifttype_id']); - if ($shifttype === false || $shifttype == null) { - engelsystem_error('Unable to load shift type.'); - } - $room = Room($shift['RID']); - if ($room === false || $room == null) { - engelsystem_error('Unable to load room.'); - } - $angeltypes = AngelTypes(); - if ($angeltypes === false) { - engelsystem_error('Unable to load angeltypes.'); - } - $user_shifts = Shifts_by_user($user); - if ($user_shifts === false) { - engelsystem_error('Unable to load users shifts.'); - } $signed_up = false; foreach ($user_shifts as $user_shift) { diff --git a/includes/controller/shifttypes_controller.php b/includes/controller/shifttypes_controller.php index 88feffed..456e39ae 100644 --- a/includes/controller/shifttypes_controller.php +++ b/includes/controller/shifttypes_controller.php @@ -48,9 +48,6 @@ function shifttype_edit_controller() { $description = ""; $angeltypes = AngelTypes(); - if ($angeltypes === false) { - engelsystem_error("Unable to load angel types."); - } if (isset($_REQUEST['shifttype_id'])) { $shifttype = ShiftType($_REQUEST['shifttype_id']); @@ -128,9 +125,6 @@ function shifttype_controller() { $angeltype = null; if ($shifttype['angeltype_id'] != null) { $angeltype = AngelType($shifttype['angeltype_id']); - if ($angeltype === false) { - engelsystem_error('Unable to load angeltype.'); - } } return [ diff --git a/includes/controller/user_angeltypes_controller.php b/includes/controller/user_angeltypes_controller.php index 418f21f9..f58187b2 100644 --- a/includes/controller/user_angeltypes_controller.php +++ b/includes/controller/user_angeltypes_controller.php @@ -1,15 +1,12 @@ <?php /** - * Display a hint for team/angeltype coordinators if there are unconfirmed users for his angeltype. + * Display a hint for team/angeltype supporters if there are unconfirmed users for his angeltype. */ function user_angeltypes_unconfirmed_hint() { global $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) { return ''; } @@ -34,24 +31,18 @@ function user_angeltypes_delete_all_controller() { } $angeltype = AngelType($_REQUEST['angeltype_id']); - if ($angeltype === false) { - engelsystem_error("Unable to load angeltype."); - } if ($angeltype == null) { error(_("Angeltype doesn't exist.")); redirect(page_link_to('angeltypes')); } - if (! User_is_AngelType_coordinator($user, $angeltype)) { + if (! User_is_AngelType_supporter($user, $angeltype)) { error(_("You are not allowed to delete all users for this angeltype.")); redirect(page_link_to('angeltypes')); } if (isset($_REQUEST['confirmed'])) { - $result = UserAngelTypes_delete_all($angeltype['id']); - if ($result === false) { - engelsystem_error("Unable to confirm all users."); - } + UserAngelTypes_delete_all($angeltype['id']); 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))); @@ -76,33 +67,24 @@ function user_angeltypes_confirm_all_controller() { } $angeltype = AngelType($_REQUEST['angeltype_id']); - if ($angeltype === false) { - engelsystem_error("Unable to load angeltype."); - } if ($angeltype == null) { error(_("Angeltype doesn't exist.")); redirect(page_link_to('angeltypes')); } $user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype); - if ($user_angeltype === false) { - engelsystem_error("Unable to load user angeltype."); - } if ($user_angeltype == null) { error(_("User angeltype doesn't exist.")); redirect(page_link_to('angeltypes')); } - if (! in_array('admin_user_angeltypes', $privileges) && ! $user_angeltype['coordinator']) { + if (! in_array('admin_user_angeltypes', $privileges) && ! $user_angeltype['supporter']) { error(_("You are not allowed to confirm all users for this angeltype.")); redirect(page_link_to('angeltypes')); } if (isset($_REQUEST['confirmed'])) { - $result = UserAngelTypes_confirm_all($angeltype['id'], $user); - if ($result === false) { - engelsystem_error("Unable to confirm all users."); - } + UserAngelTypes_confirm_all($angeltype['id'], $user); 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))); @@ -127,32 +109,23 @@ function user_angeltype_confirm_controller() { } $user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']); - if ($user_angeltype === false) { - engelsystem_error("Unable to load user angeltype."); - } if ($user_angeltype == null) { error(_("User angeltype doesn't exist.")); redirect(page_link_to('angeltypes')); } $angeltype = AngelType($user_angeltype['angeltype_id']); - if ($angeltype === false) { - engelsystem_error("Unable to load angeltype."); - } if ($angeltype == null) { error(_("Angeltype doesn't exist.")); redirect(page_link_to('angeltypes')); } - if (! User_is_AngelType_coordinator($user, $angeltype)) { + if (! User_is_AngelType_supporter($user, $angeltype)) { error(_("You are not allowed to confirm this users angeltype.")); redirect(page_link_to('angeltypes')); } $user_source = User($user_angeltype['user_id']); - if ($user_source === false) { - engelsystem_error("Unable to load user."); - } if ($user_source == null) { error(_("User doesn't exist.")); redirect(page_link_to('angeltypes')); @@ -187,33 +160,24 @@ function user_angeltype_delete_controller() { } $user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']); - if ($user_angeltype === false) { - engelsystem_error("Unable to load user angeltype."); - } if ($user_angeltype == null) { error(_("User angeltype doesn't exist.")); redirect(page_link_to('angeltypes')); } $angeltype = AngelType($user_angeltype['angeltype_id']); - if ($angeltype === false) { - engelsystem_error("Unable to load angeltype."); - } if ($angeltype == null) { error(_("Angeltype doesn't exist.")); redirect(page_link_to('angeltypes')); } $user_source = User($user_angeltype['user_id']); - if ($user_source === false) { - engelsystem_error("Unable to load user."); - } if ($user_source == null) { error(_("User doesn't exist.")); redirect(page_link_to('angeltypes')); } - if ($user['UID'] != $user_angeltype['user_id'] && ! User_is_AngelType_coordinator($user, $angeltype)) { + if ($user['UID'] != $user_angeltype['user_id'] && ! User_is_AngelType_supporter($user, $angeltype)) { error(_("You are not allowed to delete this users angeltype.")); redirect(page_link_to('angeltypes')); } @@ -244,7 +208,7 @@ function user_angeltype_update_controller() { global $privileges; if (! in_array('admin_angel_types', $privileges)) { - error(_("You are not allowed to set coordinator rights.")); + error(_("You are not allowed to set supporter rights.")); redirect(page_link_to('angeltypes')); } @@ -253,47 +217,35 @@ function user_angeltype_update_controller() { redirect(page_link_to('angeltypes')); } - if (isset($_REQUEST['coordinator']) && preg_match("/^[01]$/", $_REQUEST['coordinator'])) { - $coordinator = $_REQUEST['coordinator'] == "1"; + if (isset($_REQUEST['supporter']) && preg_match("/^[01]$/", $_REQUEST['supporter'])) { + $supporter = $_REQUEST['supporter'] == "1"; } else { - error(_("No coordinator update given.")); + error(_("No supporter update given.")); redirect(page_link_to('angeltypes')); } $user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']); - if ($user_angeltype === false) { - engelsystem_error("Unable to load user angeltype."); - } if ($user_angeltype == null) { error(_("User angeltype doesn't exist.")); redirect(page_link_to('angeltypes')); } $angeltype = AngelType($user_angeltype['angeltype_id']); - if ($angeltype === false) { - engelsystem_error("Unable to load angeltype."); - } if ($angeltype == null) { error(_("Angeltype doesn't exist.")); redirect(page_link_to('angeltypes')); } $user_source = User($user_angeltype['user_id']); - if ($user_source === false) { - engelsystem_error("Unable to load user."); - } if ($user_source == null) { error(_("User doesn't exist.")); redirect(page_link_to('angeltypes')); } if (isset($_REQUEST['confirmed'])) { - $result = UserAngelType_update($user_angeltype['id'], $coordinator); - if ($result === false) { - engelsystem_error("Unable to update coordinator rights."); - } + UserAngelType_update($user_angeltype['id'], $supporter); - $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($supporter ? _("Added supporter rights for %s to %s.") : _("Removed supporter rights for %s from %s."), AngelType_name_render($angeltype), User_Nick_render($user_source)); engelsystem_log($success_message); success($success_message); @@ -301,13 +253,13 @@ function user_angeltype_update_controller() { } return [ - $coordinator ? _("Add coordinator rights") : _("Remove coordinator rights"), - UserAngelType_update_view($user_angeltype, $user_source, $angeltype, $coordinator) + $supporter ? _("Add supporter rights") : _("Remove supporter rights"), + UserAngelType_update_view($user_angeltype, $user_source, $angeltype, $supporter) ]; } /** - * User joining an Angeltype (Or Coordinator doing this for him). + * User joining an Angeltype (Or supporter doing this for him). */ function user_angeltype_add_controller() { global $user; @@ -315,7 +267,7 @@ function user_angeltype_add_controller() { $angeltype = load_angeltype(); // User is joining by itself - if (! User_is_AngelType_coordinator($user, $angeltype)) { + if (! User_is_AngelType_supporter($user, $angeltype)) { return user_angeltype_join_controller($angeltype); } @@ -326,26 +278,17 @@ function user_angeltype_add_controller() { // Load possible users, that are not in the angeltype already $users_source = Users_by_angeltype_inverted($angeltype); - if ($users_source === false) { - engelsystem_error("Unable to load users."); - } if (isset($_REQUEST['submit'])) { $user_source = load_user(); if (! UserAngelType_exists($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))); success(sprintf(_("User %s added to %s."), User_Nick_render($user_source), AngelType_name_render($angeltype))); - $result = UserAngelType_confirm($user_angeltype_id, $user_source); - if ($result === false) { - engelsystem_error("Unable to confirm user angeltype."); - } + UserAngelType_confirm($user_angeltype_id, $user_source); 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']); @@ -365,9 +308,6 @@ function user_angeltype_join_controller($angeltype) { global $user, $privileges; $user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype); - if ($user_angeltype === false) { - engelsystem_error("Unable to load user angeltype."); - } if ($user_angeltype != null) { error(sprintf(_("You are already a %s."), $angeltype['name'])); redirect(page_link_to('angeltypes')); @@ -375,19 +315,13 @@ function user_angeltype_join_controller($angeltype) { if (isset($_REQUEST['confirmed'])) { $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']); engelsystem_log(sprintf("User %s joined %s.", User_Nick_render($user), AngelType_name_render($angeltype))); success($success_message); if (in_array('admin_user_angeltypes', $privileges)) { - $result = UserAngelType_confirm($user_angeltype_id, $user); - if ($result === false) { - engelsystem_error("Unable to confirm user angeltype."); - } + UserAngelType_confirm($user_angeltype_id, $user); engelsystem_log(sprintf("User %s confirmed as %s.", User_Nick_render($user), AngelType_name_render($angeltype))); } diff --git a/includes/controller/user_driver_licenses_controller.php b/includes/controller/user_driver_licenses_controller.php index 5c629777..a76d5507 100644 --- a/includes/controller/user_driver_licenses_controller.php +++ b/includes/controller/user_driver_licenses_controller.php @@ -7,26 +7,19 @@ function user_driver_license_required_hint() { global $user; $angeltypes = User_angeltypes($user); - if ($angeltypes === false) { - engelsystem_error("Unable to load user angeltypes."); - } $user_driver_license = UserDriverLicense($user['UID']); - if ($user_driver_license === false) { - engelsystem_error("Unable to load user driver license."); + + // User has already entered data, no hint needed. + if ($user_driver_license != null) { + return ''; } - $driving_license_information_required = false; foreach ($angeltypes as $angeltype) { if ($angeltype['requires_driver_license']) { - $driving_license_information_required = true; - break; + return info(sprintf(_("You joined an angeltype which requires a driving license. Please edit your driving license information here: %s."), '<a href="' . user_driver_license_edit_link() . '">' . _("driving license information") . '</a>'), true); } } - if ($driving_license_information_required && $user_driver_license == null) { - return info(sprintf(_("You joined an angeltype which requires a driving license. Please edit your driving license information here: %s."), '<a href="' . user_driver_license_edit_link() . '">' . _("driving license information") . '</a>'), true); - } - return ''; } @@ -64,26 +57,34 @@ function user_driver_license_edit_link($user = null) { } /** - * Edit a users driver license information. + * Loads the user for the driver license. */ -function user_driver_license_edit_controller() { - global $privileges, $user; +function user_driver_license_load_user() { + global $user; $user_source = $user; if (isset($_REQUEST['user_id'])) { $user_source = User($_REQUEST['user_id']); - if ($user_source === false) { - engelsystem_error('Unable to load angeltype.'); - } if ($user_source == null) { redirect(user_driver_license_edit_link()); } - - // only privilege admin_user can edit other users driver license information - if ($user['UID'] != $user_source['UID'] && ! in_array('admin_user', $privileges)) { - redirect(user_driver_license_edit_link()); - } + } + + return $user_source; +} + +/** + * Edit a users driver license information. + */ +function user_driver_license_edit_controller() { + global $privileges, $user; + + $user_source = user_driver_license_load_user(); + + // only privilege admin_user can edit other users driver license information + if ($user['UID'] != $user_source['UID'] && ! in_array('admin_user', $privileges)) { + redirect(user_driver_license_edit_link()); } $wants_to_drive = false; @@ -95,9 +96,6 @@ function user_driver_license_edit_controller() { $has_license_forklift = false; $user_driver_license = UserDriverLicense($user_source['UID']); - if ($user_driver_license === false) { - engelsystem_error('Unable to load user driver license.'); - } if ($user_driver_license != null) { $wants_to_drive = true; $has_car = $user_driver_license['has_car']; @@ -125,10 +123,7 @@ function user_driver_license_edit_controller() { if ($valid) { if (! $wants_to_drive && $user_driver_license != null) { - $result = UserDriverLicenses_delete($user_source['UID']); - if ($result === false) { - engelsystem_error("Unable to remove user driver license information"); - } + UserDriverLicenses_delete($user_source['UID']); engelsystem_log("Driver license information removed."); success(_("Your driver license information has been removed.")); } else { @@ -138,10 +133,6 @@ function user_driver_license_edit_controller() { } else { $result = UserDriverLicenses_update($user_source['UID'], $has_car, $has_license_car, $has_license_3_5t_transporter, $has_license_7_5t_truck, $has_license_12_5t_truck, $has_license_forklift); } - - if ($result === false) { - engelsystem_error("Unable to save user driver license information."); - } engelsystem_log("Driver license information updated."); } success(_("Your driver license information has been saved.")); diff --git a/includes/controller/users_controller.php b/includes/controller/users_controller.php index 9ead4bca..beaf2538 100644 --- a/includes/controller/users_controller.php +++ b/includes/controller/users_controller.php @@ -142,17 +142,13 @@ function user_edit_vouchers_controller() { function user_controller() { global $privileges, $user; + $user_source = $user; if (isset($_REQUEST['user_id'])) { $user_source = User($_REQUEST['user_id']); - if ($user_source === false) { - engelsystem_error("Unable to load user."); - } if ($user_source == null) { error(_("User not found.")); redirect('?'); } - } else { - $user_source = $user; } $shifts = Shifts_by_user($user_source); |