diff options
Diffstat (limited to 'includes/controller')
-rw-r--r-- | includes/controller/angeltypes_controller.php | 242 | ||||
-rw-r--r-- | includes/controller/event_config_controller.php | 154 | ||||
-rw-r--r-- | includes/controller/rooms_controller.php | 101 | ||||
-rw-r--r-- | includes/controller/shift_entries_controller.php | 267 | ||||
-rw-r--r-- | includes/controller/shifts_controller.php | 401 | ||||
-rw-r--r-- | includes/controller/shifttypes_controller.php | 227 | ||||
-rw-r--r-- | includes/controller/user_angeltypes_controller.php | 445 | ||||
-rw-r--r-- | includes/controller/user_driver_licenses_controller.php | 149 | ||||
-rw-r--r-- | includes/controller/users_controller.php | 471 |
9 files changed, 1252 insertions, 1205 deletions
diff --git a/includes/controller/angeltypes_controller.php b/includes/controller/angeltypes_controller.php index cd2aa3e4..26aaae71 100644 --- a/includes/controller/angeltypes_controller.php +++ b/includes/controller/angeltypes_controller.php @@ -3,17 +3,19 @@ /** * Text for Angeltype related links. */ -function angeltypes_title() { - return _("Angeltypes"); +function angeltypes_title() +{ + return _("Angeltypes"); } /** * Route angeltype actions. */ -function angeltypes_controller() { - $action = strip_request_item('action', 'list'); +function angeltypes_controller() +{ + $action = strip_request_item('action', 'list'); - switch ($action) { + switch ($action) { default: case 'list': return angeltypes_list_controller(); @@ -31,196 +33,202 @@ function angeltypes_controller() { /** * Path to angeltype view. * - * @param AngelType $angeltype_id + * @param AngelType $angeltype_id */ -function angeltype_link($angeltype_id) { - return page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype_id; +function angeltype_link($angeltype_id) +{ + return page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype_id; } /** * Job description for all angeltypes (public to everyone) */ -function angeltypes_about_controller() { - global $user; +function angeltypes_about_controller() +{ + global $user; - if (isset($user)) { - $angeltypes = AngelTypes_with_user($user); - } else { - $angeltypes = AngelTypes(); - } + if (isset($user)) { + $angeltypes = AngelTypes_with_user($user); + } else { + $angeltypes = AngelTypes(); + } - return [ + return [ _("Teams/Job description"), - AngelTypes_about_view($angeltypes, isset($user)) + AngelTypes_about_view($angeltypes, isset($user)) ]; } /** * Delete an Angeltype. */ -function angeltype_delete_controller() { - global $privileges; +function angeltype_delete_controller() +{ + global $privileges; - if (! in_array('admin_angel_types', $privileges)) { - redirect(page_link_to('angeltypes')); - } + if (! in_array('admin_angel_types', $privileges)) { + redirect(page_link_to('angeltypes')); + } - $angeltype = load_angeltype(); + $angeltype = load_angeltype(); - if (isset($_REQUEST['confirmed'])) { - AngelType_delete($angeltype); - success(sprintf(_("Angeltype %s deleted."), AngelType_name_render($angeltype))); - redirect(page_link_to('angeltypes')); - } + if (isset($_REQUEST['confirmed'])) { + AngelType_delete($angeltype); + success(sprintf(_("Angeltype %s deleted."), AngelType_name_render($angeltype))); + redirect(page_link_to('angeltypes')); + } - return [ + return [ sprintf(_("Delete angeltype %s"), $angeltype['name']), - AngelType_delete_view($angeltype) + AngelType_delete_view($angeltype) ]; } /** * Change an Angeltype. */ -function angeltype_edit_controller() { - global $privileges, $user; +function angeltype_edit_controller() +{ + global $privileges, $user; // In supporter mode only allow to modify description $supporter_mode = ! in_array('admin_angel_types', $privileges); - if (isset($_REQUEST['angeltype_id'])) { - // Edit existing angeltype + if (isset($_REQUEST['angeltype_id'])) { + // Edit existing angeltype $angeltype = load_angeltype(); - if (! User_is_AngelType_supporter($user, $angeltype)) { - redirect(page_link_to('angeltypes')); - } - } else { - // New angeltype + if (! User_is_AngelType_supporter($user, $angeltype)) { + redirect(page_link_to('angeltypes')); + } + } else { + // New angeltype if ($supporter_mode) { - // Supporters aren't allowed to create new angeltypes. + // Supporters aren't allowed to create new angeltypes. redirect(page_link_to('angeltypes')); } - $angeltype = AngelType_new(); - } + $angeltype = AngelType_new(); + } - if (isset($_REQUEST['submit'])) { - $valid = true; + if (isset($_REQUEST['submit'])) { + $valid = true; - if (! $supporter_mode) { - if (isset($_REQUEST['name'])) { - $result = AngelType_validate_name($_REQUEST['name'], $angeltype); - $angeltype['name'] = $result->getValue(); - if (! $result->isValid()) { - $valid = false; - error(_("Please check the name. Maybe it already exists.")); - } - } + if (! $supporter_mode) { + if (isset($_REQUEST['name'])) { + $result = AngelType_validate_name($_REQUEST['name'], $angeltype); + $angeltype['name'] = $result->getValue(); + if (! $result->isValid()) { + $valid = false; + error(_("Please check the name. Maybe it already exists.")); + } + } - $angeltype['restricted'] = isset($_REQUEST['restricted']); - $angeltype['no_self_signup'] = isset($_REQUEST['no_self_signup']); + $angeltype['restricted'] = isset($_REQUEST['restricted']); + $angeltype['no_self_signup'] = isset($_REQUEST['no_self_signup']); - $angeltype['requires_driver_license'] = isset($_REQUEST['requires_driver_license']); - } + $angeltype['requires_driver_license'] = isset($_REQUEST['requires_driver_license']); + } - $angeltype['description'] = strip_request_item_nl('description', $angeltype['description']); + $angeltype['description'] = strip_request_item_nl('description', $angeltype['description']); - if ($valid) { - if ($angeltype['id'] != null) { - AngelType_update($angeltype); - } else { - $angeltype = AngelType_create($angeltype); - } + if ($valid) { + if ($angeltype['id'] != null) { + AngelType_update($angeltype); + } else { + $angeltype = AngelType_create($angeltype); + } - success("Angel type saved."); - redirect(angeltype_link($angeltype['id'])); + success("Angel type saved."); + redirect(angeltype_link($angeltype['id'])); + } } - } - return [ + return [ sprintf(_("Edit %s"), $angeltype['name']), - AngelType_edit_view($angeltype, $supporter_mode) + AngelType_edit_view($angeltype, $supporter_mode) ]; } /** * View details of a given angeltype. */ -function angeltype_controller() { - global $privileges, $user; +function angeltype_controller() +{ + global $privileges, $user; - if (! in_array('angeltypes', $privileges)) { - redirect('?'); - } + if (! in_array('angeltypes', $privileges)) { + redirect('?'); + } - $angeltype = load_angeltype(); - $user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype); - $user_driver_license = UserDriverLicense($user['UID']); - $members = Users_by_angeltype($angeltype); + $angeltype = load_angeltype(); + $user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype); + $user_driver_license = UserDriverLicense($user['UID']); + $members = Users_by_angeltype($angeltype); - return [ + return [ sprintf(_("Team %s"), $angeltype['name']), - 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) + 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) ]; } /** * View a list of all angeltypes. */ -function angeltypes_list_controller() { - global $privileges, $user; +function angeltypes_list_controller() +{ + global $privileges, $user; - if (! in_array('angeltypes', $privileges)) { - redirect('?'); - } + if (! in_array('angeltypes', $privileges)) { + redirect('?'); + } - $angeltypes = AngelTypes_with_user($user); + $angeltypes = AngelTypes_with_user($user); - foreach ($angeltypes as &$angeltype) { - $actions = [ - button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], _("view"), "btn-xs") + foreach ($angeltypes as &$angeltype) { + $actions = [ + button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], _("view"), "btn-xs") ]; - if (in_array('admin_angel_types', $privileges)) { - $actions[] = button(page_link_to('angeltypes') . '&action=edit&angeltype_id=' . $angeltype['id'], _("edit"), "btn-xs"); - $actions[] = button(page_link_to('angeltypes') . '&action=delete&angeltype_id=' . $angeltype['id'], _("delete"), "btn-xs"); - } + if (in_array('admin_angel_types', $privileges)) { + $actions[] = button(page_link_to('angeltypes') . '&action=edit&angeltype_id=' . $angeltype['id'], _("edit"), "btn-xs"); + $actions[] = button(page_link_to('angeltypes') . '&action=delete&angeltype_id=' . $angeltype['id'], _("delete"), "btn-xs"); + } - $angeltype['membership'] = AngelType_render_membership($angeltype); - if ($angeltype['user_angeltype_id'] != null) { - $actions[] = button(page_link_to('user_angeltypes') . '&action=delete&user_angeltype_id=' . $angeltype['user_angeltype_id'], _("leave"), "btn-xs"); - } else { - $actions[] = button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], _("join"), "btn-xs"); - } + $angeltype['membership'] = AngelType_render_membership($angeltype); + if ($angeltype['user_angeltype_id'] != null) { + $actions[] = button(page_link_to('user_angeltypes') . '&action=delete&user_angeltype_id=' . $angeltype['user_angeltype_id'], _("leave"), "btn-xs"); + } else { + $actions[] = button(page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], _("join"), "btn-xs"); + } - $angeltype['restricted'] = $angeltype['restricted'] ? glyph('lock') : ''; - $angeltype['no_self_signup'] = $angeltype['no_self_signup'] ? '' : glyph('share'); + $angeltype['restricted'] = $angeltype['restricted'] ? glyph('lock') : ''; + $angeltype['no_self_signup'] = $angeltype['no_self_signup'] ? '' : glyph('share'); - $angeltype['name'] = '<a href="' . page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'] . '">' . $angeltype['name'] . '</a>'; + $angeltype['name'] = '<a href="' . page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'] . '">' . $angeltype['name'] . '</a>'; - $angeltype['actions'] = table_buttons($actions); - } + $angeltype['actions'] = table_buttons($actions); + } - return [ + return [ angeltypes_title(), - AngelTypes_list_view($angeltypes, in_array('admin_angel_types', $privileges)) + AngelTypes_list_view($angeltypes, in_array('admin_angel_types', $privileges)) ]; } /** * Loads an angeltype from given angeltype_id request param. */ -function load_angeltype() { - if (! isset($_REQUEST['angeltype_id'])) { - redirect(page_link_to('angeltypes')); - } +function load_angeltype() +{ + if (! isset($_REQUEST['angeltype_id'])) { + redirect(page_link_to('angeltypes')); + } - $angeltype = AngelType($_REQUEST['angeltype_id']); - if ($angeltype == null) { - error(_("Angeltype doesn't exist.")); - redirect(page_link_to('angeltypes')); - } + $angeltype = AngelType($_REQUEST['angeltype_id']); + if ($angeltype == null) { + error(_("Angeltype doesn't exist.")); + redirect(page_link_to('angeltypes')); + } - return $angeltype; + return $angeltype; } -?> diff --git a/includes/controller/event_config_controller.php b/includes/controller/event_config_controller.php index 4f07fe4c..c93f8d63 100644 --- a/includes/controller/event_config_controller.php +++ b/includes/controller/event_config_controller.php @@ -1,103 +1,103 @@ <?php -function event_config_title() { - return _("Event config"); +function event_config_title() +{ + return _("Event config"); } -function event_config_edit_controller() { - global $privileges; +function event_config_edit_controller() +{ + global $privileges; - if (! in_array('admin_event_config', $privileges)) { - redirect('?'); - } + if (! in_array('admin_event_config', $privileges)) { + redirect('?'); + } - $event_name = null; - $event_welcome_msg = null; - $buildup_start_date = null; - $event_start_date = null; - $event_end_date = null; - $teardown_end_date = null; + $event_name = null; + $event_welcome_msg = null; + $buildup_start_date = null; + $event_start_date = null; + $event_end_date = null; + $teardown_end_date = null; - $event_config = EventConfig(); - if ($event_config != null) { - $event_name = $event_config['event_name']; - $buildup_start_date = $event_config['buildup_start_date']; - $event_start_date = $event_config['event_start_date']; - $event_end_date = $event_config['event_end_date']; - $teardown_end_date = $event_config['teardown_end_date']; - $event_welcome_msg = $event_config['event_welcome_msg']; - } + $event_config = EventConfig(); + if ($event_config != null) { + $event_name = $event_config['event_name']; + $buildup_start_date = $event_config['buildup_start_date']; + $event_start_date = $event_config['event_start_date']; + $event_end_date = $event_config['event_end_date']; + $teardown_end_date = $event_config['teardown_end_date']; + $event_welcome_msg = $event_config['event_welcome_msg']; + } - if (isset($_REQUEST['submit'])) { - $valid = true; + if (isset($_REQUEST['submit'])) { + $valid = true; - if (isset($_REQUEST['event_name'])) { - $event_name = strip_request_item('event_name'); - } - if ($event_name == '') { - $event_name = null; - } + if (isset($_REQUEST['event_name'])) { + $event_name = strip_request_item('event_name'); + } + if ($event_name == '') { + $event_name = null; + } - if (isset($_REQUEST['event_welcome_msg'])) { - $event_welcome_msg = strip_request_item_nl('event_welcome_msg'); - } - if ($event_welcome_msg == '') { - $event_welcome_msg = null; - } + if (isset($_REQUEST['event_welcome_msg'])) { + $event_welcome_msg = strip_request_item_nl('event_welcome_msg'); + } + if ($event_welcome_msg == '') { + $event_welcome_msg = null; + } - $result = check_request_date('buildup_start_date', _("Please enter buildup start date."), true); - $buildup_start_date = $result->getValue(); - $valid &= $result->isValid(); + $result = check_request_date('buildup_start_date', _("Please enter buildup start date."), true); + $buildup_start_date = $result->getValue(); + $valid &= $result->isValid(); - $result = check_request_date('event_start_date', _("Please enter event start date."), true); - $event_start_date = $result->getValue(); - $valid &= $result->isValid(); + $result = check_request_date('event_start_date', _("Please enter event start date."), true); + $event_start_date = $result->getValue(); + $valid &= $result->isValid(); - $result = check_request_date('event_end_date', _("Please enter event end date."), true); - $event_end_date = $result->getValue(); - $valid &= $result->isValid(); + $result = check_request_date('event_end_date', _("Please enter event end date."), true); + $event_end_date = $result->getValue(); + $valid &= $result->isValid(); - $result = check_request_date('teardown_end_date', _("Please enter teardown end date."), true); - $teardown_end_date = $result->getValue(); - $valid &= $result->isValid(); + $result = check_request_date('teardown_end_date', _("Please enter teardown end date."), true); + $teardown_end_date = $result->getValue(); + $valid &= $result->isValid(); - if ($buildup_start_date != null && $event_start_date != null && $buildup_start_date > $event_start_date) { - $valid = false; - error(_("The buildup start date has to be before the event start date.")); - } + if ($buildup_start_date != null && $event_start_date != null && $buildup_start_date > $event_start_date) { + $valid = false; + error(_("The buildup start date has to be before the event start date.")); + } - if ($event_start_date != null && $event_end_date != null && $event_start_date > $event_end_date) { - $valid = false; - error(_("The event start date has to be before the event end date.")); - } + if ($event_start_date != null && $event_end_date != null && $event_start_date > $event_end_date) { + $valid = false; + error(_("The event start date has to be before the event end date.")); + } - if ($event_end_date != null && $teardown_end_date != null && $event_end_date > $teardown_end_date) { - $valid = false; - error(_("The event end date has to be before the teardown end date.")); - } + if ($event_end_date != null && $teardown_end_date != null && $event_end_date > $teardown_end_date) { + $valid = false; + error(_("The event end date has to be before the teardown end date.")); + } - if ($buildup_start_date != null && $teardown_end_date != null && $buildup_start_date > $teardown_end_date) { - $valid = false; - error(_("The buildup start date has to be before the teardown end date.")); - } + if ($buildup_start_date != null && $teardown_end_date != null && $buildup_start_date > $teardown_end_date) { + $valid = false; + error(_("The buildup start date has to be before the teardown end date.")); + } - if ($valid) { - $result = EventConfig_update($event_name, $buildup_start_date, $event_start_date, $event_end_date, $teardown_end_date, $event_welcome_msg); + if ($valid) { + $result = EventConfig_update($event_name, $buildup_start_date, $event_start_date, $event_end_date, $teardown_end_date, $event_welcome_msg); - if ($result === false) { - engelsystem_error("Unable to update event config."); - } + if ($result === false) { + engelsystem_error("Unable to update event config."); + } - engelsystem_log("Changed event config: $event_name, $event_welcome_msg, " . date("Y-m-d", $buildup_start_date) . ", " . date("Y-m-d", $event_start_date) . ", " . date("Y-m-d", $event_end_date) . ", " . date("Y-m-d", $teardown_end_date)); - success(_("Settings saved.")); - redirect(page_link_to('admin_event_config')); + engelsystem_log("Changed event config: $event_name, $event_welcome_msg, " . date("Y-m-d", $buildup_start_date) . ", " . date("Y-m-d", $event_start_date) . ", " . date("Y-m-d", $event_end_date) . ", " . date("Y-m-d", $teardown_end_date)); + success(_("Settings saved.")); + redirect(page_link_to('admin_event_config')); + } } - } - return [ + return [ event_config_title(), - EventConfig_edit_view($event_name, $event_welcome_msg, $buildup_start_date, $event_start_date, $event_end_date, $teardown_end_date) + EventConfig_edit_view($event_name, $event_welcome_msg, $buildup_start_date, $event_start_date, $event_end_date, $teardown_end_date) ]; } - -?>
\ No newline at end of file diff --git a/includes/controller/rooms_controller.php b/includes/controller/rooms_controller.php index a79034fb..2e45dead 100644 --- a/includes/controller/rooms_controller.php +++ b/includes/controller/rooms_controller.php @@ -10,56 +10,58 @@ use Engelsystem\ShiftCalendarRenderer; /** * View a room with its shifts. */ -function room_controller() { - global $privileges; +function room_controller() +{ + global $privileges; - if (! in_array('view_rooms', $privileges)) { - redirect(page_link_to()); - } + 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; + $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'] + $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')); + $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); + $shiftsFilterRenderer = new ShiftsFilterRenderer($shiftsFilter); + $shiftsFilterRenderer->enableDaySelection($days); - $shiftCalendarRenderer = shiftCalendarRendererByShiftFilter($shiftsFilter); + $shiftCalendarRenderer = shiftCalendarRendererByShiftFilter($shiftsFilter); - return [ + return [ $room['Name'], - Room_view($room, $shiftsFilterRenderer, $shiftCalendarRenderer) + Room_view($room, $shiftsFilterRenderer, $shiftCalendarRenderer) ]; } /** * Dispatch different room actions. */ -function rooms_controller() { - if (! isset($_REQUEST['action'])) { - $_REQUEST['action'] = 'list'; - } +function rooms_controller() +{ + if (! isset($_REQUEST['action'])) { + $_REQUEST['action'] = 'list'; + } - switch ($_REQUEST['action']) { + switch ($_REQUEST['action']) { default: case 'list': redirect(page_link_to('admin_rooms')); @@ -68,28 +70,29 @@ function rooms_controller() { } } -function room_link($room) { - return page_link_to('rooms') . '&action=view&room_id=' . $room['RID']; +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']; +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()); - } +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()); - } + $room = Room($_REQUEST['room_id']); + if ($room == null) { + redirect(page_link_to()); + } - return $room; + return $room; } - -?>
\ No newline at end of file diff --git a/includes/controller/shift_entries_controller.php b/includes/controller/shift_entries_controller.php index d0a12288..7fce4626 100644 --- a/includes/controller/shift_entries_controller.php +++ b/includes/controller/shift_entries_controller.php @@ -3,159 +3,160 @@ /** * Sign up for a shift. */ -function shift_entry_add_controller() { - global $privileges, $user; +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')); - } + 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']; - } + $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')); - } + $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 (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) || in_array('shiftentry_edit_angeltype_supporter', $privileges)) { - $type = AngelType($type_id); - } 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))"); - $type = $type[0]; - } + if (in_array('user_shifts_admin', $privileges) || in_array('shiftentry_edit_angeltype_supporter', $privileges)) { + $type = AngelType($type_id); + } 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))"); + $type = $type[0]; + } - if ($type == null) { - redirect(page_link_to('user_shifts')); - } + if ($type == null) { + redirect(page_link_to('user_shifts')); + } - if (isset($_REQUEST['user_id']) && preg_match("/^[0-9]*$/", $_REQUEST['user_id']) && (in_array('user_shifts_admin', $privileges) || in_array('shiftentry_edit_angeltype_supporter', $privileges))) { - $user_id = $_REQUEST['user_id']; - } else { - $user_id = $user['UID']; - } + if (isset($_REQUEST['user_id']) && preg_match("/^[0-9]*$/", $_REQUEST['user_id']) && (in_array('user_shifts_admin', $privileges) || in_array('shiftentry_edit_angeltype_supporter', $privileges))) { + $user_id = $_REQUEST['user_id']; + } else { + $user_id = $user['UID']; + } - $needed_angeltype = NeededAngeltype_by_Shift_and_Angeltype($shift, $type); - $shift_entries = ShiftEntries_by_shift_and_angeltype($shift['SID'], $type['id']); + $needed_angeltype = NeededAngeltype_by_Shift_and_Angeltype($shift, $type); + $shift_entries = ShiftEntries_by_shift_and_angeltype($shift['SID'], $type['id']); - $shift_signup_allowed = Shift_signup_allowed(User($user_id), $shift, $type, null, null, $needed_angeltype, $shift_entries); - 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)); - } + $shift_signup_allowed = Shift_signup_allowed(User($user_id), $shift, $type, null, null, $needed_angeltype, $shift_entries); + 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) || in_array('shiftentry_edit_angeltype_supporter', $privileges)) { - - 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['submit'])) { + $selected_type_id = $type_id; + if (in_array('user_shifts_admin', $privileges) || in_array('shiftentry_edit_angeltype_supporter', $privileges)) { + 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']; - } - } + 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']; + } + } - 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); - } + 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'); - } + $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([ + $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 + 'freeload_comment' => $freeload_comment ]); - if ($result === false) { - engelsystem_error('Unable to create shift entry.'); - } + 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) . "')"); - } + 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_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)); } - $user_text = html_select_key('user_id', 'user_id', $users_select, $user['UID']); + + 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']); - } elseif (in_array('shiftentry_edit_angeltype_supporter', $privileges)) { - $users = Users_by_angeltype($type); - $users_select = []; - foreach ($users as $usr) { - if (! $type['restricted'] || $usr['confirm_user_id'] != null) { - $users_select[$usr['UID']] = $usr['Nick']; - } - } - $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']); + } elseif (in_array('shiftentry_edit_angeltype_supporter', $privileges)) { + $users = Users_by_angeltype($type); + $users_select = []; + foreach ($users as $usr) { + if (! $type['restricted'] || $usr['confirm_user_id'] != null) { + $users_select[$usr['UID']] = $usr['Nick']; + } + } + $user_text = html_select_key('user_id', 'user_id', $users_select, $user['UID']); - $angeltypes_source = User_angeltypes($user); - $angeltypes = []; - foreach ($angeltypes_source as $angeltype) { - if ($angeltype['supporter']) { - $angeltypes[$angeltype['id']] = $angeltype['name']; - } - $angeltype_select = html_select_key('angeltype_id', 'angeltype_id', $angeltypes, $type['id']); + $angeltypes_source = User_angeltypes($user); + $angeltypes = []; + foreach ($angeltypes_source as $angeltype) { + if ($angeltype['supporter']) { + $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']; } - } 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)); + 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, $user; +function shift_entry_delete_controller() +{ + global $privileges, $user; - if (! isset($_REQUEST['entry_id']) || ! test_request_int('entry_id')) { - redirect(page_link_to('user_shifts')); - } - $entry_id = $_REQUEST['entry_id']; + 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(" + $shift_entry_source = sql_select(" SELECT `User`.`Nick`, `ShiftEntry`.`Comment`, `ShiftEntry`.`UID`, `ShiftTypes`.`name`, `Shifts`.*, `Room`.`Name`, `AngelTypes`.`name` as `angel_type`, `AngelTypes`.`id` as `angeltype_id` FROM `ShiftEntry` JOIN `User` ON (`User`.`UID`=`ShiftEntry`.`UID`) @@ -164,24 +165,22 @@ function shift_entry_delete_controller() { 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]; + if (count($shift_entry_source) > 0) { + $shift_entry_source = $shift_entry_source[0]; - if (!in_array('user_shifts_admin', $privileges) && (!in_array('shiftentry_edit_angeltype_supporter', $privileges) || !User_is_AngelType_supporter($user, AngelType($shift_entry_source['angeltype_id'])))) { - redirect(page_link_to('user_shifts')); - } + if (!in_array('user_shifts_admin', $privileges) && (!in_array('shiftentry_edit_angeltype_supporter', $privileges) || !User_is_AngelType_supporter($user, AngelType($shift_entry_source['angeltype_id'])))) { + redirect(page_link_to('user_shifts')); + } - $result = ShiftEntry_delete($entry_id); - if ($result === false) { - engelsystem_error('Unable to delete shift entry.'); - } + $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(shift_link($shift_entry_source)); + 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(shift_link($shift_entry_source)); } - -?>
\ No newline at end of file diff --git a/includes/controller/shifts_controller.php b/includes/controller/shifts_controller.php index 9ac8a766..69d0de1f 100644 --- a/includes/controller/shifts_controller.php +++ b/includes/controller/shifts_controller.php @@ -1,136 +1,140 @@ <?php use Engelsystem\ShiftSignupState; -function shift_link($shift) { - return page_link_to('shifts') . '&action=view&shift_id=' . $shift['SID']; +function shift_link($shift) +{ + return page_link_to('shifts') . '&action=view&shift_id=' . $shift['SID']; } -function shift_delete_link($shift) { - return page_link_to('user_shifts') . '&delete_shift=' . $shift['SID']; +function shift_delete_link($shift) +{ + return page_link_to('user_shifts') . '&delete_shift=' . $shift['SID']; } -function shift_edit_link($shift) { - return page_link_to('user_shifts') . '&edit_shift=' . $shift['SID']; +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; +function shift_edit_controller() +{ + global $privileges; // Schicht bearbeiten $msg = ""; - $valid = true; + $valid = true; - if (! in_array('admin_shifts', $privileges)) { - redirect(page_link_to('user_shifts')); - } + 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']; + 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); + $shift = Shift($shift_id); - $room = select_array(Rooms(), 'RID', 'Name'); - $angeltypes = select_array(AngelTypes(), 'id', 'name'); - $shifttypes = select_array(ShiftTypes(), 'id', 'name'); + $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; + $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']; + $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 + 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']; + $rid = $_REQUEST['rid']; } else { - $valid = false; - $msg .= error(_("Please select a room."), true); + $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['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['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 (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); - } + 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); - } - } + 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; + 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; - } + $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.")); + 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 + 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]); - } + $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(), [ + return page_with_title(shifts_title(), [ msg(), '<noscript>' . info(_("This page is much more comfortable with javascript."), true) . '</noscript>', form([ @@ -141,92 +145,95 @@ function shift_edit_controller() { form_text('end', _("End:"), date("Y-m-d H:i", $end)), '<h2>' . _("Needed angels") . '</h2>', $angel_types_spinner, - form_submit('submit', _("Save")) - ]) + form_submit('submit', _("Save")) + ]) ]); } -function shift_delete_controller() { - global $privileges; +function shift_delete_controller() +{ + global $privileges; - if (! in_array('user_shifts_admin', $privileges)) { - redirect(page_link_to('user_shifts')); - } + 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')); + redirect(page_link_to('user_shifts')); } - $shift_id = $_REQUEST['delete_shift']; + $shift_id = $_REQUEST['delete_shift']; - $shift = Shift($shift_id); - if ($shift == null) { - redirect(page_link_to('user_shifts')); - } + $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); + 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')); + 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(), [ + 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>' + '<a class="button" href="?p=user_shifts&delete_shift=' . $shift_id . '&delete">' . _("delete") . '</a>' ]); } -function shift_controller() { - global $user, $privileges; +function shift_controller() +{ + global $user, $privileges; - if (! in_array('user_shifts', $privileges)) { - redirect(page_link_to('?')); - } + if (! in_array('user_shifts', $privileges)) { + redirect(page_link_to('?')); + } - if (! isset($_REQUEST['shift_id'])) { - redirect(page_link_to('user_shifts')); - } + if (! isset($_REQUEST['shift_id'])) { + redirect(page_link_to('user_shifts')); + } - $shift = Shift($_REQUEST['shift_id']); - if ($shift == null) { - error(_("Shift could not be found.")); - redirect(page_link_to('user_shifts')); - } + $shift = Shift($_REQUEST['shift_id']); + if ($shift == null) { + error(_("Shift could not be found.")); + redirect(page_link_to('user_shifts')); + } - $shifttype = ShiftType($shift['shifttype_id']); - $room = Room($shift['RID']); - $angeltypes = AngelTypes(); - $user_shifts = Shifts_by_user($user); + $shifttype = ShiftType($shift['shifttype_id']); + $room = Room($shift['RID']); + $angeltypes = AngelTypes(); + $user_shifts = Shifts_by_user($user); - $shift_signup_state = new ShiftSignupState(ShiftSignupState::OCCUPIED, 0); - foreach ($angeltypes as &$angeltype) { - $needed_angeltype = NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype); - $shift_entries = ShiftEntries_by_shift_and_angeltype($shift['SID'], $angeltype['id']); + $shift_signup_state = new ShiftSignupState(ShiftSignupState::OCCUPIED, 0); + foreach ($angeltypes as &$angeltype) { + $needed_angeltype = NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype); + $shift_entries = ShiftEntries_by_shift_and_angeltype($shift['SID'], $angeltype['id']); - $angeltype_signup_state = Shift_signup_allowed($user, $shift, $angeltype, null, $user_shifts, $needed_angeltype, $shift_entries); - if ($shift_signup_state == null) { - $shift_signup_state = $angeltype_signup_state; - } else { - $shift_signup_state->combineWith($angeltype_signup_state); + $angeltype_signup_state = Shift_signup_allowed($user, $shift, $angeltype, null, $user_shifts, $needed_angeltype, $shift_entries); + if ($shift_signup_state == null) { + $shift_signup_state = $angeltype_signup_state; + } else { + $shift_signup_state->combineWith($angeltype_signup_state); + } + $angeltype['shift_signup_state'] = $angeltype_signup_state; } - $angeltype['shift_signup_state'] = $angeltype_signup_state; - } - return [ + return [ $shift['name'], - Shift_view($shift, $shifttype, $room, $angeltypes, $shift_signup_state) + Shift_view($shift, $shifttype, $room, $angeltypes, $shift_signup_state) ]; } -function shifts_controller() { - if (! isset($_REQUEST['action'])) { - redirect(page_link_to('user_shifts')); - } +function shifts_controller() +{ + if (! isset($_REQUEST['action'])) { + redirect(page_link_to('user_shifts')); + } - switch ($_REQUEST['action']) { + switch ($_REQUEST['action']) { default: redirect(page_link_to('?')); case 'view': @@ -239,86 +246,88 @@ function shifts_controller() { /** * Redirects the user to his next shift. */ -function shift_next_controller() { - global $user, $privileges; +function shift_next_controller() +{ + global $user, $privileges; - if (! in_array('user_shifts', $privileges)) { - redirect(page_link_to('?')); - } + if (! in_array('user_shifts', $privileges)) { + redirect(page_link_to('?')); + } - $upcoming_shifts = ShiftEntries_upcoming_for_user($user); - if ($upcoming_shifts === false) { - return false; - } + $upcoming_shifts = ShiftEntries_upcoming_for_user($user); + if ($upcoming_shifts === false) { + return false; + } - if (count($upcoming_shifts) > 0) { - redirect(shift_link($upcoming_shifts[0])); - } + if (count($upcoming_shifts) > 0) { + redirect(shift_link($upcoming_shifts[0])); + } - redirect(page_link_to('user_shifts')); + redirect(page_link_to('user_shifts')); } /** * Export all shifts using api-key. */ -function shifts_json_export_all_controller() { - global $api_key; +function shifts_json_export_all_controller() +{ + global $api_key; - if ($api_key == "") { - engelsystem_error("Config contains empty apikey."); - } + if ($api_key == "") { + engelsystem_error("Config contains empty apikey."); + } - if (! isset($_REQUEST['api_key'])) { - engelsystem_error("Missing parameter api_key."); - } + if (! isset($_REQUEST['api_key'])) { + engelsystem_error("Missing parameter api_key."); + } - if ($_REQUEST['api_key'] != $api_key) { - engelsystem_error("Invalid api_key."); - } + if ($_REQUEST['api_key'] != $api_key) { + engelsystem_error("Invalid api_key."); + } - $shifts_source = Shifts(); - if ($shifts_source === false) { - engelsystem_error("Unable to load shifts."); - } + $shifts_source = Shifts(); + if ($shifts_source === false) { + engelsystem_error("Unable to load shifts."); + } - header("Content-Type: application/json; charset=utf-8"); - raw_output(json_encode($shifts_source)); + header("Content-Type: application/json; charset=utf-8"); + raw_output(json_encode($shifts_source)); } /** * Export filtered shifts via JSON. * (Like iCal Export or shifts view) */ -function shifts_json_export_controller() { - global $user; +function shifts_json_export_controller() +{ + global $user; - if (! isset($_REQUEST['key']) || ! preg_match("/^[0-9a-f]{32}$/", $_REQUEST['key'])) { - engelsystem_error("Missing key."); - } + if (! isset($_REQUEST['key']) || ! preg_match("/^[0-9a-f]{32}$/", $_REQUEST['key'])) { + engelsystem_error("Missing key."); + } - $key = $_REQUEST['key']; + $key = $_REQUEST['key']; - $user = User_by_api_key($key); - if ($user == null) { - engelsystem_error("Key invalid."); - } - if (! in_array('shifts_json_export', privileges_for_user($user['UID']))) { - engelsystem_error("No privilege for shifts_json_export."); - } + $user = User_by_api_key($key); + if ($user == null) { + engelsystem_error("Key invalid."); + } + if (! in_array('shifts_json_export', privileges_for_user($user['UID']))) { + engelsystem_error("No privilege for shifts_json_export."); + } - $shifts = load_ical_shifts(); + $shifts = load_ical_shifts(); - header("Content-Type: application/json; charset=utf-8"); - raw_output(json_encode($shifts)); + header("Content-Type: application/json; charset=utf-8"); + raw_output(json_encode($shifts)); } /** * Returns users shifts to export. */ -function load_ical_shifts() { - global $user; +function load_ical_shifts() +{ + global $user; - return Shifts_by_user($user); + return Shifts_by_user($user); } - -?>
\ No newline at end of file diff --git a/includes/controller/shifttypes_controller.php b/includes/controller/shifttypes_controller.php index 456e39ae..f54111c4 100644 --- a/includes/controller/shifttypes_controller.php +++ b/includes/controller/shifttypes_controller.php @@ -1,169 +1,176 @@ <?php -function shifttype_link($shifttype) { - return page_link_to('shifttypes') . '&action=view&shifttype_id=' . $shifttype['id']; +function shifttype_link($shifttype) +{ + return page_link_to('shifttypes') . '&action=view&shifttype_id=' . $shifttype['id']; } /** * Delete a shifttype. */ -function shifttype_delete_controller() { - if (! isset($_REQUEST['shifttype_id'])) { - redirect(page_link_to('shifttypes')); - } - - $shifttype = ShiftType($_REQUEST['shifttype_id']); - if ($shifttype === false) { - engelsystem_error('Unable to load shifttype.'); - } +function shifttype_delete_controller() +{ + if (! isset($_REQUEST['shifttype_id'])) { + redirect(page_link_to('shifttypes')); + } - if ($shifttype == null) { - redirect(page_link_to('shifttypes')); - } + $shifttype = ShiftType($_REQUEST['shifttype_id']); + if ($shifttype === false) { + engelsystem_error('Unable to load shifttype.'); + } - if (isset($_REQUEST['confirmed'])) { - $result = ShiftType_delete($shifttype['id']); - if ($result === false) { - engelsystem_error('Unable to delete shifttype.'); + if ($shifttype == null) { + redirect(page_link_to('shifttypes')); } + + if (isset($_REQUEST['confirmed'])) { + $result = ShiftType_delete($shifttype['id']); + if ($result === false) { + engelsystem_error('Unable to delete shifttype.'); + } - engelsystem_log('Deleted shifttype ' . $shifttype['name']); - success(sprintf(_('Shifttype %s deleted.'), $shifttype['name'])); - redirect(page_link_to('shifttypes')); - } + engelsystem_log('Deleted shifttype ' . $shifttype['name']); + success(sprintf(_('Shifttype %s deleted.'), $shifttype['name'])); + redirect(page_link_to('shifttypes')); + } - return [ + return [ sprintf(_("Delete shifttype %s"), $shifttype['name']), - ShiftType_delete_view($shifttype) + ShiftType_delete_view($shifttype) ]; } /** * Edit or create shift type. */ -function shifttype_edit_controller() { - $shifttype_id = null; - $name = ""; - $angeltype_id = null; - $description = ""; +function shifttype_edit_controller() +{ + $shifttype_id = null; + $name = ""; + $angeltype_id = null; + $description = ""; - $angeltypes = AngelTypes(); + $angeltypes = AngelTypes(); - if (isset($_REQUEST['shifttype_id'])) { - $shifttype = ShiftType($_REQUEST['shifttype_id']); - if ($shifttype === false) { - engelsystem_error('Unable to load shifttype.'); - } - if ($shifttype == null) { - error(_('Shifttype not found.')); - redirect(page_link_to('shifttypes')); + if (isset($_REQUEST['shifttype_id'])) { + $shifttype = ShiftType($_REQUEST['shifttype_id']); + if ($shifttype === false) { + engelsystem_error('Unable to load shifttype.'); + } + if ($shifttype == null) { + error(_('Shifttype not found.')); + redirect(page_link_to('shifttypes')); + } + $shifttype_id = $shifttype['id']; + $name = $shifttype['name']; + $angeltype_id = $shifttype['angeltype_id']; + $description = $shifttype['description']; } - $shifttype_id = $shifttype['id']; - $name = $shifttype['name']; - $angeltype_id = $shifttype['angeltype_id']; - $description = $shifttype['description']; - } - if (isset($_REQUEST['submit'])) { - $valid = true; - - if (isset($_REQUEST['name']) && $_REQUEST['name'] != '') { - $name = strip_request_item('name'); - } else { - $valid = false; - error(_('Please enter a name.')); - } + if (isset($_REQUEST['submit'])) { + $valid = true; - if (isset($_REQUEST['angeltype_id']) && preg_match("/^[0-9]+$/", $_REQUEST['angeltype_id'])) { - $angeltype_id = $_REQUEST['angeltype_id']; - } else { - $angeltype_id = null; - } + if (isset($_REQUEST['name']) && $_REQUEST['name'] != '') { + $name = strip_request_item('name'); + } else { + $valid = false; + error(_('Please enter a name.')); + } - if (isset($_REQUEST['description'])) { - $description = strip_request_item_nl('description'); - } + if (isset($_REQUEST['angeltype_id']) && preg_match("/^[0-9]+$/", $_REQUEST['angeltype_id'])) { + $angeltype_id = $_REQUEST['angeltype_id']; + } else { + $angeltype_id = null; + } - if ($valid) { - if ($shifttype_id) { - $result = ShiftType_update($shifttype_id, $name, $angeltype_id, $description); - if ($result === false) { - engelsystem_error('Unable to update shifttype.'); + if (isset($_REQUEST['description'])) { + $description = strip_request_item_nl('description'); } - engelsystem_log('Updated shifttype ' . $name); - success(_('Updated shifttype.')); - } else { - $shifttype_id = ShiftType_create($name, $angeltype_id, $description); - if ($shifttype_id === false) { - engelsystem_error('Unable to create shifttype.'); + + if ($valid) { + if ($shifttype_id) { + $result = ShiftType_update($shifttype_id, $name, $angeltype_id, $description); + if ($result === false) { + engelsystem_error('Unable to update shifttype.'); + } + engelsystem_log('Updated shifttype ' . $name); + success(_('Updated shifttype.')); + } else { + $shifttype_id = ShiftType_create($name, $angeltype_id, $description); + if ($shifttype_id === false) { + engelsystem_error('Unable to create shifttype.'); + } + engelsystem_log('Created shifttype ' . $name); + success(_('Created shifttype.')); + } + redirect(page_link_to('shifttypes') . '&action=view&shifttype_id=' . $shifttype_id); } - engelsystem_log('Created shifttype ' . $name); - success(_('Created shifttype.')); - } - redirect(page_link_to('shifttypes') . '&action=view&shifttype_id=' . $shifttype_id); } - } - return [ + return [ shifttypes_title(), - ShiftType_edit_view($name, $angeltype_id, $angeltypes, $description, $shifttype_id) + ShiftType_edit_view($name, $angeltype_id, $angeltypes, $description, $shifttype_id) ]; } -function shifttype_controller() { - if (! isset($_REQUEST['shifttype_id'])) { - redirect(page_link_to('shifttypes')); - } - $shifttype = ShiftType($_REQUEST['shifttype_id']); - if ($shifttype === false) { - engelsystem_error('Unable to load shifttype.'); - } - if ($shifttype == null) { - redirect(page_link_to('shifttypes')); - } +function shifttype_controller() +{ + if (! isset($_REQUEST['shifttype_id'])) { + redirect(page_link_to('shifttypes')); + } + $shifttype = ShiftType($_REQUEST['shifttype_id']); + if ($shifttype === false) { + engelsystem_error('Unable to load shifttype.'); + } + if ($shifttype == null) { + redirect(page_link_to('shifttypes')); + } - $angeltype = null; - if ($shifttype['angeltype_id'] != null) { - $angeltype = AngelType($shifttype['angeltype_id']); - } + $angeltype = null; + if ($shifttype['angeltype_id'] != null) { + $angeltype = AngelType($shifttype['angeltype_id']); + } - return [ + return [ $shifttype['name'], - ShiftType_view($shifttype, $angeltype) + ShiftType_view($shifttype, $angeltype) ]; } /** * List all shift types. */ -function shifttypes_list_controller() { - $shifttypes = ShiftTypes(); - if ($shifttypes === false) { - engelsystem_error("Unable to load shifttypes."); - } +function shifttypes_list_controller() +{ + $shifttypes = ShiftTypes(); + if ($shifttypes === false) { + engelsystem_error("Unable to load shifttypes."); + } - return [ + return [ shifttypes_title(), - ShiftTypes_list_view($shifttypes) + ShiftTypes_list_view($shifttypes) ]; } /** * Text for shift type related links. */ -function shifttypes_title() { - return _("Shifttypes"); +function shifttypes_title() +{ + return _("Shifttypes"); } /** * Route shift type actions */ -function shifttypes_controller() { - if (! isset($_REQUEST['action'])) { - $_REQUEST['action'] = 'list'; - } +function shifttypes_controller() +{ + if (! isset($_REQUEST['action'])) { + $_REQUEST['action'] = 'list'; + } - switch ($_REQUEST['action']) { + switch ($_REQUEST['action']) { default: case 'list': return shifttypes_list_controller(); @@ -175,5 +182,3 @@ function shifttypes_controller() { return shifttype_delete_controller(); } } - -?>
\ No newline at end of file diff --git a/includes/controller/user_angeltypes_controller.php b/includes/controller/user_angeltypes_controller.php index 6ef894c7..7469304b 100644 --- a/includes/controller/user_angeltypes_controller.php +++ b/includes/controller/user_angeltypes_controller.php @@ -3,272 +3,279 @@ /** * Display a hint for team/angeltype supporters if there are unconfirmed users for his angeltype. */ -function user_angeltypes_unconfirmed_hint() { - global $user; +function user_angeltypes_unconfirmed_hint() +{ + global $user; - $unconfirmed_user_angeltypes = User_unconfirmed_AngelTypes($user); - if (count($unconfirmed_user_angeltypes) == 0) { - return null; - } + $unconfirmed_user_angeltypes = User_unconfirmed_AngelTypes($user); + if (count($unconfirmed_user_angeltypes) == 0) { + return null; + } - $unconfirmed_links = []; - foreach ($unconfirmed_user_angeltypes as $user_angeltype) { - $unconfirmed_links[] = '<a href="' . page_link_to('angeltypes') . '&action=view&angeltype_id=' . $user_angeltype['angeltype_id'] . '">' . $user_angeltype['name'] . ' (+' . $user_angeltype['count'] . ')' . '</a>'; - } + $unconfirmed_links = []; + foreach ($unconfirmed_user_angeltypes as $user_angeltype) { + $unconfirmed_links[] = '<a href="' . page_link_to('angeltypes') . '&action=view&angeltype_id=' . $user_angeltype['angeltype_id'] . '">' . $user_angeltype['name'] . ' (+' . $user_angeltype['count'] . ')' . '</a>'; + } - return sprintf(ngettext("There is %d unconfirmed angeltype.", "There are %d unconfirmed angeltypes.", count($unconfirmed_user_angeltypes)), count($unconfirmed_user_angeltypes)) . " " . _('Angel types which need approvals:') . ' ' . join(', ', $unconfirmed_links); + return sprintf(ngettext("There is %d unconfirmed angeltype.", "There are %d unconfirmed angeltypes.", count($unconfirmed_user_angeltypes)), count($unconfirmed_user_angeltypes)) . " " . _('Angel types which need approvals:') . ' ' . join(', ', $unconfirmed_links); } /** * Remove all unconfirmed users from a specific angeltype. */ -function user_angeltypes_delete_all_controller() { - global $user; +function user_angeltypes_delete_all_controller() +{ + global $user; - if (! isset($_REQUEST['angeltype_id'])) { - error(_("Angeltype doesn't exist.")); - redirect(page_link_to('angeltypes')); - } + if (! isset($_REQUEST['angeltype_id'])) { + error(_("Angeltype doesn't exist.")); + redirect(page_link_to('angeltypes')); + } - $angeltype = AngelType($_REQUEST['angeltype_id']); - if ($angeltype == null) { - error(_("Angeltype doesn't exist.")); - redirect(page_link_to('angeltypes')); - } + $angeltype = AngelType($_REQUEST['angeltype_id']); + if ($angeltype == null) { + error(_("Angeltype doesn't exist.")); + redirect(page_link_to('angeltypes')); + } - 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 (! 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'])) { - UserAngelTypes_delete_all($angeltype['id']); + if (isset($_REQUEST['confirmed'])) { + 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))); - redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $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))); + redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']); + } - return [ + return [ _("Deny all users"), - UserAngelTypes_delete_all_view($angeltype) + UserAngelTypes_delete_all_view($angeltype) ]; } /** * Confirm all unconfirmed users for an angeltype. */ -function user_angeltypes_confirm_all_controller() { - global $user, $privileges; +function user_angeltypes_confirm_all_controller() +{ + global $user, $privileges; - if (! isset($_REQUEST['angeltype_id'])) { - error(_("Angeltype doesn't exist.")); - redirect(page_link_to('angeltypes')); - } + if (! isset($_REQUEST['angeltype_id'])) { + error(_("Angeltype doesn't exist.")); + redirect(page_link_to('angeltypes')); + } - $angeltype = AngelType($_REQUEST['angeltype_id']); - if ($angeltype == null) { - error(_("Angeltype doesn't exist.")); - redirect(page_link_to('angeltypes')); - } + $angeltype = AngelType($_REQUEST['angeltype_id']); + 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 == null) { - error(_("User angeltype doesn't exist.")); - redirect(page_link_to('angeltypes')); - } + $user_angeltype = UserAngelType_by_User_and_AngelType($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['supporter']) { - error(_("You are not allowed to confirm all users for this angeltype.")); - redirect(page_link_to('angeltypes')); - } + 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'])) { - UserAngelTypes_confirm_all($angeltype['id'], $user); + if (isset($_REQUEST['confirmed'])) { + 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))); - redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']); - } + 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))); + redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']); + } - return [ + return [ _("Confirm all users"), - UserAngelTypes_confirm_all_view($angeltype) + UserAngelTypes_confirm_all_view($angeltype) ]; } /** * Confirm an user for an angeltype. */ -function user_angeltype_confirm_controller() { - global $user; +function user_angeltype_confirm_controller() +{ + global $user; - if (! isset($_REQUEST['user_angeltype_id'])) { - error(_("User angeltype doesn't exist.")); - redirect(page_link_to('angeltypes')); - } - - $user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']); - if ($user_angeltype == null) { - error(_("User angeltype doesn't exist.")); - redirect(page_link_to('angeltypes')); - } + if (! isset($_REQUEST['user_angeltype_id'])) { + error(_("User angeltype doesn't exist.")); + redirect(page_link_to('angeltypes')); + } - $angeltype = AngelType($user_angeltype['angeltype_id']); - if ($angeltype == null) { - error(_("Angeltype doesn't exist.")); - redirect(page_link_to('angeltypes')); - } + $user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']); + if ($user_angeltype == null) { + error(_("User angeltype doesn't exist.")); + redirect(page_link_to('angeltypes')); + } - if (! User_is_AngelType_supporter($user, $angeltype)) { - error(_("You are not allowed to confirm this users angeltype.")); - redirect(page_link_to('angeltypes')); - } + $angeltype = AngelType($user_angeltype['angeltype_id']); + if ($angeltype == null) { + error(_("Angeltype doesn't exist.")); + redirect(page_link_to('angeltypes')); + } - $user_source = User($user_angeltype['user_id']); - if ($user_source == null) { - error(_("User doesn't exist.")); - redirect(page_link_to('angeltypes')); - } + if (! User_is_AngelType_supporter($user, $angeltype)) { + error(_("You are not allowed to confirm this users angeltype.")); + redirect(page_link_to('angeltypes')); + } - if (isset($_REQUEST['confirmed'])) { - $result = UserAngelType_confirm($user_angeltype['id'], $user); - if ($result === false) { - engelsystem_error("Unable to confirm user angeltype."); + $user_source = User($user_angeltype['user_id']); + if ($user_source == null) { + error(_("User doesn't exist.")); + redirect(page_link_to('angeltypes')); } + + if (isset($_REQUEST['confirmed'])) { + $result = UserAngelType_confirm($user_angeltype['id'], $user); + if ($result === false) { + engelsystem_error("Unable to confirm user angeltype."); + } - engelsystem_log(sprintf("%s confirmed for angeltype %s", User_Nick_render($user_source), AngelType_name_render($angeltype))); - success(sprintf(_("%s confirmed for angeltype %s."), User_Nick_render($user_source), AngelType_name_render($angeltype))); - redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']); - } + engelsystem_log(sprintf("%s confirmed for angeltype %s", User_Nick_render($user_source), AngelType_name_render($angeltype))); + success(sprintf(_("%s confirmed for angeltype %s."), User_Nick_render($user_source), AngelType_name_render($angeltype))); + redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']); + } - return [ + return [ _("Confirm angeltype for user"), - UserAngelType_confirm_view($user_angeltype, $user_source, $angeltype) + UserAngelType_confirm_view($user_angeltype, $user_source, $angeltype) ]; } /** * Remove a user from an Angeltype. */ -function user_angeltype_delete_controller() { - global $user; +function user_angeltype_delete_controller() +{ + global $user; - if (! isset($_REQUEST['user_angeltype_id'])) { - error(_("User angeltype doesn't exist.")); - redirect(page_link_to('angeltypes')); - } - - $user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']); - if ($user_angeltype == null) { - error(_("User angeltype doesn't exist.")); - redirect(page_link_to('angeltypes')); - } + if (! isset($_REQUEST['user_angeltype_id'])) { + error(_("User angeltype doesn't exist.")); + redirect(page_link_to('angeltypes')); + } - $angeltype = AngelType($user_angeltype['angeltype_id']); - if ($angeltype == null) { - error(_("Angeltype doesn't exist.")); - redirect(page_link_to('angeltypes')); - } + $user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']); + if ($user_angeltype == null) { + error(_("User angeltype doesn't exist.")); + redirect(page_link_to('angeltypes')); + } - $user_source = User($user_angeltype['user_id']); - if ($user_source == null) { - error(_("User doesn't exist.")); - redirect(page_link_to('angeltypes')); - } + $angeltype = AngelType($user_angeltype['angeltype_id']); + if ($angeltype == null) { + error(_("Angeltype doesn't exist.")); + redirect(page_link_to('angeltypes')); + } - 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')); - } + $user_source = User($user_angeltype['user_id']); + if ($user_source == null) { + error(_("User doesn't exist.")); + redirect(page_link_to('angeltypes')); + } - if (isset($_REQUEST['confirmed'])) { - $result = UserAngelType_delete($user_angeltype); - if ($result === false) { - engelsystem_error("Unable to delete 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')); } + + if (isset($_REQUEST['confirmed'])) { + $result = UserAngelType_delete($user_angeltype); + if ($result === false) { + engelsystem_error("Unable to delete user angeltype."); + } - $success_message = sprintf(_("User %s removed from %s."), User_Nick_render($user_source), $angeltype['name']); - engelsystem_log($success_message); - success($success_message); + $success_message = sprintf(_("User %s removed from %s."), User_Nick_render($user_source), $angeltype['name']); + engelsystem_log($success_message); + success($success_message); - redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']); - } + redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']); + } - return [ + return [ _("Remove angeltype"), - UserAngelType_delete_view($user_angeltype, $user_source, $angeltype) + UserAngelType_delete_view($user_angeltype, $user_source, $angeltype) ]; } /** * Update an UserAngelType. */ -function user_angeltype_update_controller() { - global $privileges; +function user_angeltype_update_controller() +{ + global $privileges; - if (! in_array('admin_angel_types', $privileges)) { - error(_("You are not allowed to set supporter rights.")); - redirect(page_link_to('angeltypes')); - } + if (! in_array('admin_angel_types', $privileges)) { + error(_("You are not allowed to set supporter rights.")); + redirect(page_link_to('angeltypes')); + } - if (! isset($_REQUEST['user_angeltype_id'])) { - error(_("User angeltype doesn't exist.")); - redirect(page_link_to('angeltypes')); - } + if (! isset($_REQUEST['user_angeltype_id'])) { + error(_("User angeltype doesn't exist.")); + redirect(page_link_to('angeltypes')); + } - if (isset($_REQUEST['supporter']) && preg_match("/^[01]$/", $_REQUEST['supporter'])) { - $supporter = $_REQUEST['supporter'] == "1"; - } else { - error(_("No supporter update given.")); - redirect(page_link_to('angeltypes')); - } + if (isset($_REQUEST['supporter']) && preg_match("/^[01]$/", $_REQUEST['supporter'])) { + $supporter = $_REQUEST['supporter'] == "1"; + } else { + error(_("No supporter update given.")); + redirect(page_link_to('angeltypes')); + } - $user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']); - if ($user_angeltype == null) { - error(_("User angeltype doesn't exist.")); - redirect(page_link_to('angeltypes')); - } + $user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']); + if ($user_angeltype == null) { + error(_("User angeltype doesn't exist.")); + redirect(page_link_to('angeltypes')); + } - $angeltype = AngelType($user_angeltype['angeltype_id']); - if ($angeltype == null) { - error(_("Angeltype doesn't exist.")); - redirect(page_link_to('angeltypes')); - } + $angeltype = AngelType($user_angeltype['angeltype_id']); + if ($angeltype == null) { + error(_("Angeltype doesn't exist.")); + redirect(page_link_to('angeltypes')); + } - $user_source = User($user_angeltype['user_id']); - if ($user_source == null) { - error(_("User doesn't exist.")); - redirect(page_link_to('angeltypes')); - } + $user_source = User($user_angeltype['user_id']); + if ($user_source == null) { + error(_("User doesn't exist.")); + redirect(page_link_to('angeltypes')); + } - if (isset($_REQUEST['confirmed'])) { - UserAngelType_update($user_angeltype['id'], $supporter); + if (isset($_REQUEST['confirmed'])) { + UserAngelType_update($user_angeltype['id'], $supporter); - $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); + $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); - redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']); - } + redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']); + } - return [ + return [ $supporter ? _("Add supporter rights") : _("Remove supporter rights"), - UserAngelType_update_view($user_angeltype, $user_source, $angeltype, $supporter) + UserAngelType_update_view($user_angeltype, $user_source, $angeltype, $supporter) ]; } /** * User joining an Angeltype (Or supporter doing this for him). */ -function user_angeltype_add_controller() { - global $user; +function user_angeltype_add_controller() +{ + global $user; - $angeltype = load_angeltype(); + $angeltype = load_angeltype(); // User is joining by itself if (! User_is_AngelType_supporter($user, $angeltype)) { - return user_angeltype_join_controller($angeltype); + return user_angeltype_join_controller($angeltype); } // Allow to add any user @@ -279,70 +286,72 @@ function user_angeltype_add_controller() { // Load possible users, that are not in the angeltype already $users_source = Users_by_angeltype_inverted($angeltype); - if (isset($_REQUEST['submit'])) { - $user_source = load_user(); + if (isset($_REQUEST['submit'])) { + $user_source = load_user(); - if (! UserAngelType_exists($user_source, $angeltype)) { - $user_angeltype_id = UserAngelType_create($user_source, $angeltype); + if (! UserAngelType_exists($user_source, $angeltype)) { + $user_angeltype_id = UserAngelType_create($user_source, $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))); + 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))); - UserAngelType_confirm($user_angeltype_id, $user_source); - engelsystem_log(sprintf("User %s confirmed as %s.", User_Nick_render($user), AngelType_name_render($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']); + redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']); + } } - } - return [ + return [ _("Add user to angeltype"), - UserAngelType_add_view($angeltype, $users_source, $user_source['UID']) + UserAngelType_add_view($angeltype, $users_source, $user_source['UID']) ]; } /** * A user joins an angeltype. */ -function user_angeltype_join_controller($angeltype) { - global $user, $privileges; - - $user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype); - if ($user_angeltype != null) { - error(sprintf(_("You are already a %s."), $angeltype['name'])); - redirect(page_link_to('angeltypes')); - } +function user_angeltype_join_controller($angeltype) +{ + global $user, $privileges; + + $user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype); + if ($user_angeltype != null) { + error(sprintf(_("You are already a %s."), $angeltype['name'])); + redirect(page_link_to('angeltypes')); + } - if (isset($_REQUEST['confirmed'])) { - $user_angeltype_id = UserAngelType_create($user, $angeltype); + if (isset($_REQUEST['confirmed'])) { + $user_angeltype_id = UserAngelType_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); + $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)) { - UserAngelType_confirm($user_angeltype_id, $user); - engelsystem_log(sprintf("User %s confirmed as %s.", User_Nick_render($user), AngelType_name_render($angeltype))); - } + if (in_array('admin_user_angeltypes', $privileges)) { + UserAngelType_confirm($user_angeltype_id, $user); + 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']); + } - return [ + return [ sprintf(_("Become a %s"), $angeltype['name']), - UserAngelType_join_view($user, $angeltype) + UserAngelType_join_view($user, $angeltype) ]; } /** * Route UserAngelType actions. */ -function user_angeltypes_controller() { - if (! isset($_REQUEST['action'])) { - redirect(page_link_to('angeltypes')); - } +function user_angeltypes_controller() +{ + if (! isset($_REQUEST['action'])) { + redirect(page_link_to('angeltypes')); + } - switch ($_REQUEST['action']) { + switch ($_REQUEST['action']) { case 'delete_all': return user_angeltypes_delete_all_controller(); case 'confirm_all': @@ -359,5 +368,3 @@ function user_angeltypes_controller() { redirect(page_link_to('angeltypes')); } } - -?>
\ No newline at end of file diff --git a/includes/controller/user_driver_licenses_controller.php b/includes/controller/user_driver_licenses_controller.php index 26deab7d..434d9274 100644 --- a/includes/controller/user_driver_licenses_controller.php +++ b/includes/controller/user_driver_licenses_controller.php @@ -3,39 +3,41 @@ /** * Generates a hint, if user joined angeltypes that require a driving license and the user has no driver license information provided. */ -function user_driver_license_required_hint() { - global $user; +function user_driver_license_required_hint() +{ + global $user; - $angeltypes = User_angeltypes($user); - $user_driver_license = UserDriverLicense($user['UID']); + $angeltypes = User_angeltypes($user); + $user_driver_license = UserDriverLicense($user['UID']); // User has already entered data, no hint needed. if ($user_driver_license != null) { - return null; + return null; } - foreach ($angeltypes as $angeltype) { - if ($angeltype['requires_driver_license']) { - return 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>'); + foreach ($angeltypes as $angeltype) { + if ($angeltype['requires_driver_license']) { + return 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>'); + } } - } - return null; + return null; } /** * Route user driver licenses actions. */ -function user_driver_licenses_controller() { - global $user; +function user_driver_licenses_controller() +{ + global $user; - if (! isset($user)) { - redirect(page_link_to('')); - } + if (! isset($user)) { + redirect(page_link_to('')); + } - $action = strip_request_item('action', 'edit'); + $action = strip_request_item('action', 'edit'); - switch ($action) { + switch ($action) { default: case 'edit': return user_driver_license_edit_controller(); @@ -45,88 +47,89 @@ function user_driver_licenses_controller() { /** * Link to user driver license edit page for given user. * - * @param User $user + * @param User $user */ -function user_driver_license_edit_link($user = null) { - if ($user == null) { - return page_link_to('user_driver_licenses'); - } - return page_link_to('user_driver_licenses') . '&user_id=' . $user['UID']; +function user_driver_license_edit_link($user = null) +{ + if ($user == null) { + return page_link_to('user_driver_licenses'); + } + return page_link_to('user_driver_licenses') . '&user_id=' . $user['UID']; } /** * Loads the user for the driver license. */ -function user_driver_license_load_user() { - global $user; +function user_driver_license_load_user() +{ + global $user; - $user_source = $user; + $user_source = $user; - if (isset($_REQUEST['user_id'])) { - $user_source = User($_REQUEST['user_id']); - if ($user_source == null) { - redirect(user_driver_license_edit_link()); + if (isset($_REQUEST['user_id'])) { + $user_source = User($_REQUEST['user_id']); + if ($user_source == null) { + redirect(user_driver_license_edit_link()); + } } - } - return $user_source; + return $user_source; } /** * Edit a users driver license information. */ -function user_driver_license_edit_controller() { - global $privileges, $user; +function user_driver_license_edit_controller() +{ + global $privileges, $user; - $user_source = user_driver_license_load_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()); + redirect(user_driver_license_edit_link()); } - $user_driver_license = UserDriverLicense($user_source['UID']); - if ($user_driver_license == null) { - $wants_to_drive = false; - $user_driver_license = UserDriverLicense_new(); - } else { - $wants_to_drive = true; - } + $user_driver_license = UserDriverLicense($user_source['UID']); + if ($user_driver_license == null) { + $wants_to_drive = false; + $user_driver_license = UserDriverLicense_new(); + } else { + $wants_to_drive = true; + } - if (isset($_REQUEST['submit'])) { - $wants_to_drive = isset($_REQUEST['wants_to_drive']); - if ($wants_to_drive) { - $user_driver_license['has_car'] = isset($_REQUEST['has_car']); - $user_driver_license['has_license_car'] = isset($_REQUEST['has_license_car']); - $user_driver_license['has_license_3_5t_transporter'] = isset($_REQUEST['has_license_3_5t_transporter']); - $user_driver_license['has_license_7_5t_truck'] = isset($_REQUEST['has_license_7_5t_truck']); - $user_driver_license['has_license_12_5t_truck'] = isset($_REQUEST['has_license_12_5t_truck']); - $user_driver_license['has_license_forklift'] = isset($_REQUEST['has_license_forklift']); + if (isset($_REQUEST['submit'])) { + $wants_to_drive = isset($_REQUEST['wants_to_drive']); + if ($wants_to_drive) { + $user_driver_license['has_car'] = isset($_REQUEST['has_car']); + $user_driver_license['has_license_car'] = isset($_REQUEST['has_license_car']); + $user_driver_license['has_license_3_5t_transporter'] = isset($_REQUEST['has_license_3_5t_transporter']); + $user_driver_license['has_license_7_5t_truck'] = isset($_REQUEST['has_license_7_5t_truck']); + $user_driver_license['has_license_12_5t_truck'] = isset($_REQUEST['has_license_12_5t_truck']); + $user_driver_license['has_license_forklift'] = isset($_REQUEST['has_license_forklift']); - if (UserDriverLicense_valid($user_driver_license)) { - if ($user_driver_license['user_id'] == null) { - $user_driver_license = UserDriverLicenses_create($user_driver_license, $user); - } else { - UserDriverLicenses_update($user_driver_license); + if (UserDriverLicense_valid($user_driver_license)) { + if ($user_driver_license['user_id'] == null) { + $user_driver_license = UserDriverLicenses_create($user_driver_license, $user); + } else { + UserDriverLicenses_update($user_driver_license); + } + engelsystem_log("Driver license information updated."); + success(_("Your driver license information has been saved.")); + redirect(user_link($user_source)); + } else { + error(_("Please select at least one driving license.")); + } + } elseif ($user_driver_license['id'] != null) { + UserDriverLicenses_delete($user_source['UID']); + engelsystem_log("Driver license information removed."); + success(_("Your driver license information has been removed.")); + redirect(user_link($user_source)); } - engelsystem_log("Driver license information updated."); - success(_("Your driver license information has been saved.")); - redirect(user_link($user_source)); - } else { - error(_("Please select at least one driving license.")); - } - } elseif ($user_driver_license['id'] != null) { - UserDriverLicenses_delete($user_source['UID']); - engelsystem_log("Driver license information removed."); - success(_("Your driver license information has been removed.")); - redirect(user_link($user_source)); } - } - return [ + return [ sprintf(_("Edit %s driving license information"), $user_source['Nick']), - UserDriverLicense_edit_view($user_source, $wants_to_drive, $user_driver_license) + UserDriverLicense_edit_view($user_source, $wants_to_drive, $user_driver_license) ]; } - -?>
\ No newline at end of file diff --git a/includes/controller/users_controller.php b/includes/controller/users_controller.php index 3825af7c..4f7b97eb 100644 --- a/includes/controller/users_controller.php +++ b/includes/controller/users_controller.php @@ -5,18 +5,19 @@ use Engelsystem\ShiftCalendarRenderer; /** * Route user actions. */ -function users_controller() { - global $user; +function users_controller() +{ + global $user; - if (! isset($user)) { - redirect(page_link_to('')); - } + if (! isset($user)) { + redirect(page_link_to('')); + } - if (! isset($_REQUEST['action'])) { - $_REQUEST['action'] = 'list'; - } + if (! isset($_REQUEST['action'])) { + $_REQUEST['action'] = 'list'; + } - switch ($_REQUEST['action']) { + switch ($_REQUEST['action']) { default: case 'list': return users_list_controller(); @@ -34,338 +35,350 @@ function users_controller() { /** * Delete a user, requires to enter own password for reasons. */ -function user_delete_controller() { - global $privileges, $user; +function user_delete_controller() +{ + global $privileges, $user; - if (isset($_REQUEST['user_id'])) { - $user_source = User($_REQUEST['user_id']); - } else { - $user_source = $user; - } + if (isset($_REQUEST['user_id'])) { + $user_source = User($_REQUEST['user_id']); + } else { + $user_source = $user; + } - if (! in_array('admin_user', $privileges)) { - redirect(page_link_to('')); - } + if (! in_array('admin_user', $privileges)) { + redirect(page_link_to('')); + } // You cannot delete yourself if ($user['UID'] == $user_source['UID']) { - error(_("You cannot delete yourself.")); - redirect(user_link($user)); + error(_("You cannot delete yourself.")); + redirect(user_link($user)); } - if (isset($_REQUEST['submit'])) { - $valid = true; + if (isset($_REQUEST['submit'])) { + $valid = true; - if (! (isset($_REQUEST['password']) && verify_password($_REQUEST['password'], $user['Passwort'], $user['UID']))) { - $valid = false; - error(_("Your password is incorrect. Please try it again.")); - } + if (! (isset($_REQUEST['password']) && verify_password($_REQUEST['password'], $user['Passwort'], $user['UID']))) { + $valid = false; + error(_("Your password is incorrect. Please try it again.")); + } - if ($valid) { - $result = User_delete($user_source['UID']); - if ($result === false) { - engelsystem_error('Unable to delete user.'); - } + if ($valid) { + $result = User_delete($user_source['UID']); + if ($result === false) { + engelsystem_error('Unable to delete user.'); + } - mail_user_delete($user_source); - success(_("User deleted.")); - engelsystem_log(sprintf("Deleted %s", User_Nick_render($user_source))); + mail_user_delete($user_source); + success(_("User deleted.")); + engelsystem_log(sprintf("Deleted %s", User_Nick_render($user_source))); - redirect(users_link()); + redirect(users_link()); + } } - } - return [ + return [ sprintf(_("Delete %s"), $user_source['Nick']), - User_delete_view($user_source) + User_delete_view($user_source) ]; } -function users_link() { - return page_link_to('users'); +function users_link() +{ + return page_link_to('users'); } -function user_edit_link($user) { - return page_link_to('admin_user') . '&user_id=' . $user['UID']; +function user_edit_link($user) +{ + return page_link_to('admin_user') . '&user_id=' . $user['UID']; } -function user_delete_link($user) { - return page_link_to('users') . '&action=delete&user_id=' . $user['UID']; +function user_delete_link($user) +{ + return page_link_to('users') . '&action=delete&user_id=' . $user['UID']; } -function user_link($user) { - return page_link_to('users') . '&action=view&user_id=' . $user['UID']; +function user_link($user) +{ + return page_link_to('users') . '&action=view&user_id=' . $user['UID']; } -function user_edit_vouchers_controller() { - global $privileges, $user; +function user_edit_vouchers_controller() +{ + global $privileges, $user; - if (isset($_REQUEST['user_id'])) { - $user_source = User($_REQUEST['user_id']); - } else { - $user_source = $user; - } + if (isset($_REQUEST['user_id'])) { + $user_source = User($_REQUEST['user_id']); + } else { + $user_source = $user; + } - if (! in_array('admin_user', $privileges)) { - redirect(page_link_to('')); - } + if (! in_array('admin_user', $privileges)) { + redirect(page_link_to('')); + } - if (isset($_REQUEST['submit'])) { - $valid = true; + if (isset($_REQUEST['submit'])) { + $valid = true; - if (isset($_REQUEST['vouchers']) && test_request_int('vouchers') && trim($_REQUEST['vouchers']) >= 0) { - $vouchers = trim($_REQUEST['vouchers']); - } else { - $valid = false; - error(_("Please enter a valid number of vouchers.")); - } + if (isset($_REQUEST['vouchers']) && test_request_int('vouchers') && trim($_REQUEST['vouchers']) >= 0) { + $vouchers = trim($_REQUEST['vouchers']); + } else { + $valid = false; + error(_("Please enter a valid number of vouchers.")); + } - if ($valid) { - $user_source['got_voucher'] = $vouchers; + if ($valid) { + $user_source['got_voucher'] = $vouchers; - $result = User_update($user_source); - if ($result === false) { - engelsystem_error('Unable to update user.'); - } + $result = User_update($user_source); + if ($result === false) { + engelsystem_error('Unable to update user.'); + } - success(_("Saved the number of vouchers.")); - engelsystem_log(User_Nick_render($user_source) . ': ' . sprintf("Got %s vouchers", $user_source['got_voucher'])); + success(_("Saved the number of vouchers.")); + engelsystem_log(User_Nick_render($user_source) . ': ' . sprintf("Got %s vouchers", $user_source['got_voucher'])); - redirect(user_link($user_source)); + redirect(user_link($user_source)); + } } - } - return [ + return [ sprintf(_("%s's vouchers"), $user_source['Nick']), - User_edit_vouchers_view($user_source) + User_edit_vouchers_view($user_source) ]; } -function user_controller() { - global $privileges, $user; +function user_controller() +{ + global $privileges, $user; - $user_source = $user; - if (isset($_REQUEST['user_id'])) { - $user_source = User($_REQUEST['user_id']); - if ($user_source == null) { - error(_("User not found.")); - redirect('?'); + $user_source = $user; + if (isset($_REQUEST['user_id'])) { + $user_source = User($_REQUEST['user_id']); + if ($user_source == null) { + error(_("User not found.")); + redirect('?'); + } } - } - $shifts = Shifts_by_user($user_source, in_array("user_shifts_admin", $privileges)); - foreach ($shifts as &$shift) { - // TODO: Move queries to model + $shifts = Shifts_by_user($user_source, in_array("user_shifts_admin", $privileges)); + foreach ($shifts as &$shift) { + // TODO: Move queries to model $shift['needed_angeltypes'] = sql_select("SELECT DISTINCT `AngelTypes`.* FROM `ShiftEntry` JOIN `AngelTypes` ON `ShiftEntry`.`TID`=`AngelTypes`.`id` WHERE `ShiftEntry`.`SID`='" . sql_escape($shift['SID']) . "' ORDER BY `AngelTypes`.`name`"); - foreach ($shift['needed_angeltypes'] as &$needed_angeltype) { - $needed_angeltype['users'] = sql_select(" + foreach ($shift['needed_angeltypes'] as &$needed_angeltype) { + $needed_angeltype['users'] = sql_select(" SELECT `ShiftEntry`.`freeloaded`, `User`.* FROM `ShiftEntry` JOIN `User` ON `ShiftEntry`.`UID`=`User`.`UID` WHERE `ShiftEntry`.`SID`='" . sql_escape($shift['SID']) . "' AND `ShiftEntry`.`TID`='" . sql_escape($needed_angeltype['id']) . "'"); + } } - } - if ($user_source['api_key'] == "") { - User_reset_api_key($user_source, false); - } + if ($user_source['api_key'] == "") { + User_reset_api_key($user_source, false); + } - return [ + return [ $user_source['Nick'], - User_view($user_source, in_array('admin_user', $privileges), User_is_freeloader($user_source), User_angeltypes($user_source), User_groups($user_source), $shifts, $user['UID'] == $user_source['UID']) + User_view($user_source, in_array('admin_user', $privileges), User_is_freeloader($user_source), User_angeltypes($user_source), User_groups($user_source), $shifts, $user['UID'] == $user_source['UID']) ]; } /** * List all users. */ -function users_list_controller() { - global $privileges; +function users_list_controller() +{ + global $privileges; - if (! in_array('admin_user', $privileges)) { - redirect(page_link_to('')); - } + if (! in_array('admin_user', $privileges)) { + redirect(page_link_to('')); + } - $order_by = 'Nick'; - if (isset($_REQUEST['OrderBy']) && in_array($_REQUEST['OrderBy'], User_sortable_columns())) { - $order_by = $_REQUEST['OrderBy']; - } + $order_by = 'Nick'; + if (isset($_REQUEST['OrderBy']) && in_array($_REQUEST['OrderBy'], User_sortable_columns())) { + $order_by = $_REQUEST['OrderBy']; + } - $users = Users($order_by); - if ($users === false) { - engelsystem_error('Unable to load users.'); - } + $users = Users($order_by); + if ($users === false) { + engelsystem_error('Unable to load users.'); + } - foreach ($users as &$user) { - $user['freeloads'] = count(ShiftEntries_freeloaded_by_user($user)); - } + foreach ($users as &$user) { + $user['freeloads'] = count(ShiftEntries_freeloaded_by_user($user)); + } - return [ + return [ _('All users'), - Users_view($users, $order_by, User_arrived_count(), User_active_count(), User_force_active_count(), ShiftEntries_freeleaded_count(), User_tshirts_count(), User_got_voucher_count()) + Users_view($users, $order_by, User_arrived_count(), User_active_count(), User_force_active_count(), ShiftEntries_freeleaded_count(), User_tshirts_count(), User_got_voucher_count()) ]; } /** * Second step of password recovery: set a new password using the token link from email */ -function user_password_recovery_set_new_controller() { - global $min_password_length; - $user_source = User_by_password_recovery_token($_REQUEST['token']); - if ($user_source == null) { - error(_("Token is not correct.")); - redirect(page_link_to('login')); - } +function user_password_recovery_set_new_controller() +{ + global $min_password_length; + $user_source = User_by_password_recovery_token($_REQUEST['token']); + if ($user_source == null) { + error(_("Token is not correct.")); + redirect(page_link_to('login')); + } - if (isset($_REQUEST['submit'])) { - $valid = true; + if (isset($_REQUEST['submit'])) { + $valid = true; - if (isset($_REQUEST['password']) && strlen($_REQUEST['password']) >= $min_password_length) { - if ($_REQUEST['password'] != $_REQUEST['password2']) { - $valid = false; - error(_("Your passwords don't match.")); - } - } else { - $valid = false; - error(_("Your password is to short (please use at least 6 characters).")); - } + if (isset($_REQUEST['password']) && strlen($_REQUEST['password']) >= $min_password_length) { + if ($_REQUEST['password'] != $_REQUEST['password2']) { + $valid = false; + error(_("Your passwords don't match.")); + } + } else { + $valid = false; + error(_("Your password is to short (please use at least 6 characters).")); + } - if ($valid) { - set_password($user_source['UID'], $_REQUEST['password']); - success(_("Password saved.")); - redirect(page_link_to('login')); + if ($valid) { + set_password($user_source['UID'], $_REQUEST['password']); + success(_("Password saved.")); + redirect(page_link_to('login')); + } } - } - return User_password_set_view(); + return User_password_set_view(); } /** * First step of password recovery: display a form that asks for your email and send email with recovery link */ -function user_password_recovery_start_controller() { - if (isset($_REQUEST['submit'])) { - $valid = true; +function user_password_recovery_start_controller() +{ + if (isset($_REQUEST['submit'])) { + $valid = true; - if (isset($_REQUEST['email']) && strlen(strip_request_item('email')) > 0) { - $email = strip_request_item('email'); - if (check_email($email)) { - $user_source = User_by_email($email); - if ($user_source == null) { - $valid = false; - error(_("E-mail address is not correct.")); + if (isset($_REQUEST['email']) && strlen(strip_request_item('email')) > 0) { + $email = strip_request_item('email'); + if (check_email($email)) { + $user_source = User_by_email($email); + if ($user_source == null) { + $valid = false; + error(_("E-mail address is not correct.")); + } + } else { + $valid = false; + error(_("E-mail address is not correct.")); + } + } else { + $valid = false; + error(_("Please enter your e-mail.")); } - } else { - $valid = false; - error(_("E-mail address is not correct.")); - } - } else { - $valid = false; - error(_("Please enter your e-mail.")); - } - if ($valid) { - $token = User_generate_password_recovery_token($user_source); - engelsystem_email_to_user($user_source, _("Password recovery"), sprintf(_("Please visit %s to recover your password."), page_link_to_absolute('user_password_recovery') . '&token=' . $token)); - success(_("We sent an email containing your password recovery link.")); - redirect(page_link_to('login')); + if ($valid) { + $token = User_generate_password_recovery_token($user_source); + engelsystem_email_to_user($user_source, _("Password recovery"), sprintf(_("Please visit %s to recover your password."), page_link_to_absolute('user_password_recovery') . '&token=' . $token)); + success(_("We sent an email containing your password recovery link.")); + redirect(page_link_to('login')); + } } - } - return User_password_recovery_view(); + return User_password_recovery_view(); } /** * User password recovery in 2 steps. * (By email) */ -function user_password_recovery_controller() { - if (isset($_REQUEST['token'])) { - return user_password_recovery_set_new_controller(); - } else { - return user_password_recovery_start_controller(); - } +function user_password_recovery_controller() +{ + if (isset($_REQUEST['token'])) { + return user_password_recovery_set_new_controller(); + } else { + return user_password_recovery_start_controller(); + } } /** * Menu title for password recovery. */ -function user_password_recovery_title() { - return _("Password recovery"); +function user_password_recovery_title() +{ + return _("Password recovery"); } /** * Loads a user from param user_id. */ -function load_user() { - if (! isset($_REQUEST['user_id'])) { - redirect(page_link_to()); - } +function load_user() +{ + if (! isset($_REQUEST['user_id'])) { + redirect(page_link_to()); + } - $user = User($_REQUEST['user_id']); - if ($user === false) { - engelsystem_error("Unable to load user."); - } + $user = User($_REQUEST['user_id']); + if ($user === false) { + engelsystem_error("Unable to load user."); + } - if ($user == null) { - error(_("User doesn't exist.")); - redirect(page_link_to()); - } + if ($user == null) { + error(_("User doesn't exist.")); + redirect(page_link_to()); + } - return $user; + return $user; } -function shiftCalendarRendererByShiftFilter(ShiftsFilter $shiftsFilter) { - $shifts = Shifts_by_ShiftsFilter($shiftsFilter); - $needed_angeltypes_source = NeededAngeltypes_by_ShiftsFilter($shiftsFilter); - $shift_entries_source = ShiftEntries_by_ShiftsFilter($shiftsFilter); +function shiftCalendarRendererByShiftFilter(ShiftsFilter $shiftsFilter) +{ + $shifts = Shifts_by_ShiftsFilter($shiftsFilter); + $needed_angeltypes_source = NeededAngeltypes_by_ShiftsFilter($shiftsFilter); + $shift_entries_source = ShiftEntries_by_ShiftsFilter($shiftsFilter); - $needed_angeltypes = []; - $shift_entries = []; - foreach ($shifts as $shift) { - $needed_angeltypes[$shift['SID']] = []; - $shift_entries[$shift['SID']] = []; - } - foreach ($shift_entries_source as $shift_entry) { - if (isset($shift_entries[$shift_entry['SID']])) { - $shift_entries[$shift_entry['SID']][] = $shift_entry; + $needed_angeltypes = []; + $shift_entries = []; + foreach ($shifts as $shift) { + $needed_angeltypes[$shift['SID']] = []; + $shift_entries[$shift['SID']] = []; } - } - foreach ($needed_angeltypes_source as $needed_angeltype) { - if (isset($needed_angeltypes[$needed_angeltype['SID']])) { - $needed_angeltypes[$needed_angeltype['SID']][] = $needed_angeltype; + foreach ($shift_entries_source as $shift_entry) { + if (isset($shift_entries[$shift_entry['SID']])) { + $shift_entries[$shift_entry['SID']][] = $shift_entry; + } } - } - unset($needed_angeltypes_source); - unset($shift_entries_source); - - if (in_array(ShiftsFilter::FILLED_FREE, $shiftsFilter->getFilled()) && in_array(ShiftsFilter::FILLED_FILLED, $shiftsFilter->getFilled())) { - return new ShiftCalendarRenderer($shifts, $needed_angeltypes, $shift_entries, $shiftsFilter); - } - - $filtered_shifts = []; - foreach ($shifts as $shift) { - $needed_angels_count = 0; - foreach ($needed_angeltypes[$shift['SID']] as $needed_angeltype) { - $taken = 0; - foreach ($shift_entries[$shift['SID']] as $shift_entry) { - if ($needed_angeltype['angel_type_id'] == $shift_entry['TID'] && $shift_entry['freeloaded'] == 0) { - $taken ++; + foreach ($needed_angeltypes_source as $needed_angeltype) { + if (isset($needed_angeltypes[$needed_angeltype['SID']])) { + $needed_angeltypes[$needed_angeltype['SID']][] = $needed_angeltype; } - } - - $needed_angels_count += max(0, $needed_angeltype['count'] - $taken); } - if (in_array(ShiftsFilter::FILLED_FREE, $shiftsFilter->getFilled()) && $taken < $needed_angels_count) { - $filtered_shifts[] = $shift; + unset($needed_angeltypes_source); + unset($shift_entries_source); + + if (in_array(ShiftsFilter::FILLED_FREE, $shiftsFilter->getFilled()) && in_array(ShiftsFilter::FILLED_FILLED, $shiftsFilter->getFilled())) { + return new ShiftCalendarRenderer($shifts, $needed_angeltypes, $shift_entries, $shiftsFilter); } - if (in_array(ShiftsFilter::FILLED_FILLED, $shiftsFilter->getFilled()) && $taken >= $needed_angels_count) { - $filtered_shifts[] = $shift; + + $filtered_shifts = []; + foreach ($shifts as $shift) { + $needed_angels_count = 0; + foreach ($needed_angeltypes[$shift['SID']] as $needed_angeltype) { + $taken = 0; + foreach ($shift_entries[$shift['SID']] as $shift_entry) { + if ($needed_angeltype['angel_type_id'] == $shift_entry['TID'] && $shift_entry['freeloaded'] == 0) { + $taken ++; + } + } + + $needed_angels_count += max(0, $needed_angeltype['count'] - $taken); + } + if (in_array(ShiftsFilter::FILLED_FREE, $shiftsFilter->getFilled()) && $taken < $needed_angels_count) { + $filtered_shifts[] = $shift; + } + if (in_array(ShiftsFilter::FILLED_FILLED, $shiftsFilter->getFilled()) && $taken >= $needed_angels_count) { + $filtered_shifts[] = $shift; + } } - } - return new ShiftCalendarRenderer($filtered_shifts, $needed_angeltypes, $shift_entries, $shiftsFilter); + return new ShiftCalendarRenderer($filtered_shifts, $needed_angeltypes, $shift_entries, $shiftsFilter); } - -?> |