diff options
Diffstat (limited to 'includes/controller')
-rw-r--r-- | includes/controller/angeltypes_controller.php | 21 | ||||
-rw-r--r-- | includes/controller/rooms_controller.php | 88 | ||||
-rw-r--r-- | includes/controller/shift_entries_controller.php | 167 | ||||
-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 | 76 | ||||
-rw-r--r-- | includes/controller/user_driver_licenses_controller.php | 3 | ||||
-rw-r--r-- | includes/controller/users_controller.php | 6 |
8 files changed, 428 insertions, 125 deletions
diff --git a/includes/controller/angeltypes_controller.php b/includes/controller/angeltypes_controller.php index cb2bb2fb..ea451481 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')); } @@ -196,17 +187,11 @@ 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) { @@ -235,9 +220,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 +259,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/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..9e252a4f --- /dev/null +++ b/includes/controller/shift_entries_controller.php @@ -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") . ' »</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..663f7826 100644 --- a/includes/controller/user_angeltypes_controller.php +++ b/includes/controller/user_angeltypes_controller.php @@ -7,9 +7,6 @@ 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,9 +31,6 @@ 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')); @@ -48,10 +42,7 @@ function user_angeltypes_delete_all_controller() { } 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,18 +67,12 @@ 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')); @@ -99,10 +84,7 @@ function user_angeltypes_confirm_all_controller() { } 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,18 +109,12 @@ 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')); @@ -150,9 +126,6 @@ function user_angeltype_confirm_controller() { } $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,27 +160,18 @@ 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')); @@ -261,37 +225,25 @@ function user_angeltype_update_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 (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'], $coordinator); $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); @@ -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..88d25395 100644 --- a/includes/controller/user_driver_licenses_controller.php +++ b/includes/controller/user_driver_licenses_controller.php @@ -73,9 +73,6 @@ function user_driver_license_edit_controller() { 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()); } 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); |