From 7313e15ce8236e19331fb6639a3a5b97c8f06ecd Mon Sep 17 00:00:00 2001 From: Bot Date: Mon, 2 Jan 2017 03:57:23 +0100 Subject: PSR-2 formatting --- .../controller/user_driver_licenses_controller.php | 149 +++++++++++---------- 1 file changed, 76 insertions(+), 73 deletions(-) (limited to 'includes/controller/user_driver_licenses_controller.php') 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."), '' . _("driving license information") . ''); + 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."), '' . _("driving license information") . ''); + } } - } - 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 -- cgit v1.2.3-54-g00ecf From d71e7bbfad2f07f82df0c515608996d250fd4182 Mon Sep 17 00:00:00 2001 From: Bot Date: Mon, 2 Jan 2017 15:43:36 +0100 Subject: Formatting --- config/config.default.php | 6 +- includes/controller/angeltypes_controller.php | 179 +++--- includes/controller/event_config_controller.php | 66 ++- includes/controller/rooms_controller.php | 57 +- includes/controller/shift_entries_controller.php | 161 ++++-- includes/controller/shifts_controller.php | 250 +++++---- includes/controller/shifttypes_controller.php | 84 +-- includes/controller/user_angeltypes_controller.php | 283 +++++----- .../controller/user_driver_licenses_controller.php | 72 +-- includes/controller/users_controller.php | 202 ++++--- includes/helper/email_helper.php | 16 +- includes/helper/graph_helper.php | 27 +- includes/helper/internationalization_helper.php | 12 +- includes/helper/message_helper.php | 6 +- includes/mailer/shifts_mailer.php | 52 +- includes/mailer/users_mailer.php | 6 +- includes/model/AngelType_model.php | 44 +- includes/model/EventConfig_model.php | 18 +- includes/model/LogEntries_model.php | 4 +- includes/model/Message_model.php | 33 +- includes/model/NeededAngelTypes_model.php | 24 +- includes/model/Room_model.php | 5 +- includes/model/ShiftEntry_model.php | 29 +- includes/model/ShiftSignupState.php | 182 +++--- includes/model/ShiftTypes_model.php | 19 +- includes/model/ShiftsFilter.php | 60 +- includes/model/Shifts_model.php | 229 +++++--- includes/model/UserAngelTypes_model.php | 53 +- includes/model/UserDriverLicenses_model.php | 23 +- includes/model/UserGroups_model.php | 1 + includes/model/User_model.php | 65 ++- includes/model/ValidationResult.php | 54 +- includes/mysqli_provider.php | 52 +- includes/pages/admin_active.php | 108 ++-- includes/pages/admin_arrive.php | 184 +++--- includes/pages/admin_free.php | 85 +-- includes/pages/admin_groups.php | 172 +++--- includes/pages/admin_import.php | 577 ++++++++++--------- includes/pages/admin_log.php | 26 +- includes/pages/admin_news.php | 84 +-- includes/pages/admin_questions.php | 169 +++--- includes/pages/admin_rooms.php | 154 ++--- includes/pages/admin_shifts.php | 428 +++++++------- includes/pages/admin_user.php | 213 +++---- includes/pages/guest_login.php | 385 +++++++------ includes/pages/guest_stats.php | 24 +- includes/pages/user_atom.php | 22 +- includes/pages/user_ical.php | 19 +- includes/pages/user_messages.php | 180 +++--- includes/pages/user_myshifts.php | 76 ++- includes/pages/user_news.php | 80 +-- includes/pages/user_questions.php | 83 +-- includes/pages/user_settings.php | 74 +-- includes/pages/user_shifts.php | 158 ++++-- includes/sys_auth.php | 61 +- includes/sys_form.php | 57 +- includes/sys_log.php | 20 +- includes/sys_menu.php | 123 ++-- includes/sys_page.php | 32 +- includes/sys_template.php | 34 +- includes/view/AngelTypes_view.php | 336 ++++++----- includes/view/EventConfig_view.php | 180 +++--- includes/view/Questions_view.php | 42 +- includes/view/Rooms_view.php | 8 +- includes/view/ShiftCalendarLane.php | 62 +- includes/view/ShiftCalendarRenderer.php | 381 ++++++------- includes/view/ShiftCalendarShiftRenderer.php | 327 ++++++----- includes/view/ShiftEntry_view.php | 44 +- includes/view/ShiftTypes_view.php | 103 ++-- includes/view/ShiftsFilterRenderer.php | 108 ++-- includes/view/Shifts_view.php | 170 +++--- includes/view/UserAngelTypes_view.php | 139 +++-- includes/view/UserDriverLicenses_view.php | 64 ++- includes/view/UserHintsRenderer.php | 100 ++-- includes/view/User_view.php | 623 ++++++++++++--------- phpunit.xml | 44 +- public/index.php | 47 +- public/js/forms.js | 32 +- public/js/moment-countdown.js | 28 +- public/js/sticky-headers.js | 33 +- public/maintenance.html | 128 +++-- public/overwhelmed.html | 104 ++-- shift_markup.html | 161 +++--- templates/guest_credits.html | 58 +- templates/layout.html | 87 +-- templates/user_shifts.html | 90 +-- test/model/LogEntriesModelTest.php | 20 +- test/model/RoomModelTest.php | 26 +- themes/base.less | 134 ++--- 89 files changed, 5395 insertions(+), 4286 deletions(-) (limited to 'includes/controller/user_driver_licenses_controller.php') diff --git a/config/config.default.php b/config/config.default.php index a832c8aa..fc61e60a 100644 --- a/config/config.default.php +++ b/config/config.default.php @@ -49,7 +49,7 @@ $shift_sum_formula = "SUM( // voucher calculation $voucher_settings = [ - "initial_vouchers" => 2, + "initial_vouchers" => 2, "shifts_per_voucher" => 1 ]; @@ -63,6 +63,6 @@ $api_key = ""; $config = [ 'host' => "localhost", 'user' => "root", - 'pw' => "", - 'db' => "engelsystem" + 'pw' => "", + 'db' => "engelsystem" ]; diff --git a/includes/controller/angeltypes_controller.php b/includes/controller/angeltypes_controller.php index 26aaae71..de4b8a49 100644 --- a/includes/controller/angeltypes_controller.php +++ b/includes/controller/angeltypes_controller.php @@ -14,20 +14,20 @@ function angeltypes_title() function angeltypes_controller() { $action = strip_request_item('action', 'list'); - + switch ($action) { - default: - case 'list': - return angeltypes_list_controller(); - case 'view': - return angeltype_controller(); - case 'edit': - return angeltype_edit_controller(); - case 'delete': - return angeltype_delete_controller(); - case 'about': - return angeltypes_about_controller(); - } + default: + case 'list': + return angeltypes_list_controller(); + case 'view': + return angeltype_controller(); + case 'edit': + return angeltype_edit_controller(); + case 'delete': + return angeltype_delete_controller(); + case 'about': + return angeltypes_about_controller(); + } } /** @@ -46,17 +46,17 @@ function angeltype_link($angeltype_id) function angeltypes_about_controller() { global $user; - + if (isset($user)) { $angeltypes = AngelTypes_with_user($user); } else { $angeltypes = AngelTypes(); } - + return [ - _("Teams/Job description"), - AngelTypes_about_view($angeltypes, isset($user)) - ]; + _("Teams/Job description"), + AngelTypes_about_view($angeltypes, isset($user)) + ]; } /** @@ -65,23 +65,23 @@ function angeltypes_about_controller() function angeltype_delete_controller() { global $privileges; - - if (! in_array('admin_angel_types', $privileges)) { + + if (!in_array('admin_angel_types', $privileges)) { redirect(page_link_to('angeltypes')); } - + $angeltype = load_angeltype(); - + if (isset($_REQUEST['confirmed'])) { AngelType_delete($angeltype); success(sprintf(_("Angeltype %s deleted."), AngelType_name_render($angeltype))); redirect(page_link_to('angeltypes')); } - + return [ - sprintf(_("Delete angeltype %s"), $angeltype['name']), - AngelType_delete_view($angeltype) - ]; + sprintf(_("Delete angeltype %s"), $angeltype['name']), + AngelType_delete_view($angeltype) + ]; } /** @@ -90,63 +90,63 @@ function angeltype_delete_controller() function angeltype_edit_controller() { global $privileges, $user; - - // In supporter mode only allow to modify description - $supporter_mode = ! in_array('admin_angel_types', $privileges); - + + // In supporter mode only allow to modify description + $supporter_mode = !in_array('admin_angel_types', $privileges); + if (isset($_REQUEST['angeltype_id'])) { // Edit existing angeltype - $angeltype = load_angeltype(); - - if (! User_is_AngelType_supporter($user, $angeltype)) { + $angeltype = load_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. - redirect(page_link_to('angeltypes')); - } + if ($supporter_mode) { + // Supporters aren't allowed to create new angeltypes. + redirect(page_link_to('angeltypes')); + } $angeltype = AngelType_new(); } - + if (isset($_REQUEST['submit'])) { $valid = true; - - if (! $supporter_mode) { + + if (!$supporter_mode) { if (isset($_REQUEST['name'])) { $result = AngelType_validate_name($_REQUEST['name'], $angeltype); $angeltype['name'] = $result->getValue(); - if (! $result->isValid()) { + 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['requires_driver_license'] = isset($_REQUEST['requires_driver_license']); } - + $angeltype['description'] = strip_request_item_nl('description', $angeltype['description']); - + if ($valid) { if ($angeltype['id'] != null) { AngelType_update($angeltype); } else { $angeltype = AngelType_create($angeltype); } - + success("Angel type saved."); redirect(angeltype_link($angeltype['id'])); } } - + return [ - sprintf(_("Edit %s"), $angeltype['name']), - AngelType_edit_view($angeltype, $supporter_mode) - ]; + sprintf(_("Edit %s"), $angeltype['name']), + AngelType_edit_view($angeltype, $supporter_mode) + ]; } /** @@ -155,20 +155,29 @@ function angeltype_edit_controller() function angeltype_controller() { global $privileges, $user; - - if (! in_array('angeltypes', $privileges)) { + + 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); - + 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) - ]; + 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 + ) + ]; } /** @@ -177,42 +186,58 @@ function angeltype_controller() function angeltypes_list_controller() { global $privileges, $user; - - if (! in_array('angeltypes', $privileges)) { + + if (!in_array('angeltypes', $privileges)) { redirect('?'); } - + $angeltypes = AngelTypes_with_user($user); - + foreach ($angeltypes as &$angeltype) { $actions = [ - button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], _("view"), "btn-xs") - ]; - + 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"); + $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"); + $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"); + $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['name'] = '' . $angeltype['name'] . ''; - + $angeltype['actions'] = table_buttons($actions); } - + return [ - angeltypes_title(), - AngelTypes_list_view($angeltypes, in_array('admin_angel_types', $privileges)) - ]; + angeltypes_title(), + AngelTypes_list_view($angeltypes, in_array('admin_angel_types', $privileges)) + ]; } /** @@ -220,15 +245,15 @@ function angeltypes_list_controller() */ function load_angeltype() { - if (! isset($_REQUEST['angeltype_id'])) { + 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')); } - + return $angeltype; } diff --git a/includes/controller/event_config_controller.php b/includes/controller/event_config_controller.php index c93f8d63..623a2a7a 100644 --- a/includes/controller/event_config_controller.php +++ b/includes/controller/event_config_controller.php @@ -8,18 +8,18 @@ function event_config_title() function event_config_edit_controller() { global $privileges; - - if (! in_array('admin_event_config', $privileges)) { + + 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_config = EventConfig(); if ($event_config != null) { $event_name = $event_config['event_name']; @@ -29,75 +29,93 @@ function event_config_edit_controller() $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['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; } - + $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_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(); - + 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_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 ($valid) { - $result = EventConfig_update($event_name, $buildup_start_date, $event_start_date, $event_end_date, $teardown_end_date, $event_welcome_msg); - + $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."); } - - 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)); + + 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 [ - event_config_title(), - EventConfig_edit_view($event_name, $event_welcome_msg, $buildup_start_date, $event_start_date, $event_end_date, $teardown_end_date) - ]; + event_config_title(), + EventConfig_edit_view( + $event_name, + $event_welcome_msg, + $buildup_start_date, + $event_start_date, + $event_end_date, + $teardown_end_date + ) + ]; } diff --git a/includes/controller/rooms_controller.php b/includes/controller/rooms_controller.php index 2e45dead..d19e91bb 100644 --- a/includes/controller/rooms_controller.php +++ b/includes/controller/rooms_controller.php @@ -1,7 +1,6 @@ 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); - + $shiftCalendarRenderer = shiftCalendarRendererByShiftFilter($shiftsFilter); - + return [ - $room['Name'], - Room_view($room, $shiftsFilterRenderer, $shiftCalendarRenderer) - ]; + $room['Name'], + Room_view($room, $shiftsFilterRenderer, $shiftCalendarRenderer) + ]; } /** @@ -57,17 +58,17 @@ function room_controller() */ function rooms_controller() { - if (! isset($_REQUEST['action'])) { + if (!isset($_REQUEST['action'])) { $_REQUEST['action'] = 'list'; } - + switch ($_REQUEST['action']) { - default: - case 'list': - redirect(page_link_to('admin_rooms')); - case 'view': - return room_controller(); - } + default: + case 'list': + redirect(page_link_to('admin_rooms')); + case 'view': + return room_controller(); + } } function room_link($room) @@ -85,14 +86,14 @@ function room_edit_link($room) */ function load_room() { - if (! test_request_int('room_id')) { + if (!test_request_int('room_id')) { redirect(page_link_to()); } - + $room = Room($_REQUEST['room_id']); if ($room == null) { redirect(page_link_to()); } - + return $room; } diff --git a/includes/controller/shift_entries_controller.php b/includes/controller/shift_entries_controller.php index 7fce4626..928a0990 100644 --- a/includes/controller/shift_entries_controller.php +++ b/includes/controller/shift_entries_controller.php @@ -6,112 +6,157 @@ function shift_entry_add_controller() { global $privileges, $user; - + if (isset($_REQUEST['shift_id']) && preg_match("/^[0-9]*$/", $_REQUEST['shift_id'])) { $shift_id = $_REQUEST['shift_id']; } else { redirect(page_link_to('user_shifts')); } - - // Locations laden - $rooms = sql_select("SELECT * FROM `Room` WHERE `show`='Y' ORDER BY `Name`"); + + // Locations laden + $rooms = sql_select("SELECT * FROM `Room` WHERE `show`='Y' ORDER BY `Name`"); $room_array = []; foreach ($rooms as $room) { $room_array[$room['RID']] = $room['Name']; } - + $shift = Shift($shift_id); $shift['Name'] = $room_array[$shift['RID']]; if ($shift == null) { redirect(page_link_to('user_shifts')); } - + if (isset($_REQUEST['type_id']) && preg_match("/^[0-9]*$/", $_REQUEST['type_id'])) { $type_id = $_REQUEST['type_id']; } else { redirect(page_link_to('user_shifts')); } - + if (in_array('user_shifts_admin', $privileges) || 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 = 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 (isset($_REQUEST['user_id']) && preg_match("/^[0-9]*$/", $_REQUEST['user_id']) && (in_array('user_shifts_admin', $privileges) || in_array('shiftentry_edit_angeltype_supporter', $privileges))) { + + 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']); - - $shift_signup_allowed = Shift_signup_allowed(User($user_id), $shift, $type, null, null, $needed_angeltype, $shift_entries); - if (! $shift_signup_allowed->isSignupAllowed()) { + + $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 (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) { + + 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); } - + $freeloaded = $shift['freeloaded']; $freeload_comment = $shift['freeload_comment']; if (in_array("user_shifts_admin", $privileges)) { $freeloaded = isset($_REQUEST['freeloaded']); $freeload_comment = strip_request_item_nl('freeload_comment'); } - + $comment = strip_request_item_nl('comment'); $result = ShiftEntry_create([ - 'SID' => $shift_id, - 'TID' => $selected_type_id, - 'UID' => $user_id, - 'Comment' => $comment, - 'freeloaded' => $freeloaded, - 'freeload_comment' => $freeload_comment - ]); + 'SID' => $shift_id, + 'TID' => $selected_type_id, + 'UID' => $user_id, + 'Comment' => $comment, + 'freeloaded' => $freeloaded, + 'freeload_comment' => $freeload_comment + ]); if ($result === false) { engelsystem_error('Unable to create shift entry.'); } - - if ($type['restricted'] == 0 && sql_num_query("SELECT * FROM `UserAngelTypes` INNER JOIN `AngelTypes` ON `AngelTypes`.`id` = `UserAngelTypes`.`angeltype_id` WHERE `angeltype_id` = '" . sql_escape($selected_type_id) . "' AND `user_id` = '" . sql_escape($user_id) . "'") == 0) { + + 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'])); + 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!") . ' ' . _("My shifts") . ' »'); 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 = 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) { @@ -122,12 +167,12 @@ function shift_entry_add_controller() $users = Users_by_angeltype($type); $users_select = []; foreach ($users as $usr) { - if (! $type['restricted'] || $usr['confirm_user_id'] != null) { + 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) { @@ -140,8 +185,10 @@ function shift_entry_add_controller() $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)); } /** @@ -150,14 +197,22 @@ function shift_entry_add_controller() function shift_entry_delete_controller() { global $privileges, $user; - - if (! isset($_REQUEST['entry_id']) || ! test_request_int('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(" - SELECT `User`.`Nick`, `ShiftEntry`.`Comment`, `ShiftEntry`.`UID`, `ShiftTypes`.`name`, `Shifts`.*, `Room`.`Name`, `AngelTypes`.`name` as `angel_type`, `AngelTypes`.`id` as `angeltype_id` + 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`) JOIN `AngelTypes` ON (`ShiftEntry`.`TID` = `AngelTypes`.`id`) @@ -167,17 +222,25 @@ function shift_entry_delete_controller() WHERE `ShiftEntry`.`id`='" . sql_escape($entry_id) . "'"); 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'])))) { + + 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.'); } - - 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']); + + 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.")); diff --git a/includes/controller/shifts_controller.php b/includes/controller/shifts_controller.php index 69d0de1f..e2dd712b 100644 --- a/includes/controller/shifts_controller.php +++ b/includes/controller/shifts_controller.php @@ -22,93 +22,96 @@ function shift_edit_link($shift) function shift_edit_controller() { global $privileges; - - // Schicht bearbeiten - $msg = ""; + + // Schicht bearbeiten + $msg = ""; $valid = true; - - if (! in_array('admin_shifts', $privileges)) { + + if (!in_array('admin_shifts', $privileges)) { redirect(page_link_to('user_shifts')); } - - if (! isset($_REQUEST['edit_shift']) || ! test_request_int('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); - + $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])) { + if (!isset($needed_angel_types[$angeltype_id])) { $needed_angel_types[$angeltype_id] = 0; } } - + $shifttype_id = $shift['shifttype_id']; $title = $shift['title']; $rid = $shift['RID']; $start = $shift['start']; $end = $shift['end']; - + if (isset($_REQUEST['submit'])) { // Name/Bezeichnung der Schicht, darf leer sein - $title = strip_request_item('title'); - - // Auswahl der sichtbaren Locations für die Schichten - if (isset($_REQUEST['rid']) && preg_match("/^[0-9]+$/", $_REQUEST['rid']) && isset($room[$_REQUEST['rid']])) { - $rid = $_REQUEST['rid']; - } else { - $valid = false; - $msg .= error(_("Please select a room."), true); - } - + $title = strip_request_item('title'); + + // Auswahl der sichtbaren Locations für die Schichten + if (isset($_REQUEST['rid']) && preg_match("/^[0-9]+$/", $_REQUEST['rid']) && isset($room[$_REQUEST['rid']])) { + $rid = $_REQUEST['rid']; + } else { + $valid = false; + $msg .= error(_("Please select a room."), true); + } + if (isset($_REQUEST['shifttype_id']) && isset($shifttypes[$_REQUEST['shifttype_id']])) { $shifttype_id = $_REQUEST['shifttype_id']; } else { $valid = false; $msg .= error(_('Please select a shifttype.'), true); } - + if (isset($_REQUEST['start']) && $tmp = parse_date("Y-m-d H:i", $_REQUEST['start'])) { $start = $tmp; } else { $valid = false; $msg .= error(_("Please enter a valid starting time for the shifts."), true); } - + if (isset($_REQUEST['end']) && $tmp = parse_date("Y-m-d H:i", $_REQUEST['end'])) { $end = $tmp; } else { $valid = false; $msg .= error(_("Please enter a valid ending time for the shifts."), true); } - + if ($start >= $end) { $valid = false; $msg .= error(_("The ending time has to be after the starting time."), true); } - + foreach ($needed_angel_types as $needed_angeltype_id => $needed_angeltype_name) { if (isset($_REQUEST['type_' . $needed_angeltype_id]) && test_request_int('type_' . $needed_angeltype_id)) { $needed_angel_types[$needed_angeltype_id] = trim($_REQUEST['type_' . $needed_angeltype_id]); } else { $valid = false; - $msg .= error(sprintf(_("Please check your input for needed angels of type %s."), $needed_angeltype_name), true); + $msg .= error(sprintf( + _("Please check your input for needed angels of type %s."), + $needed_angeltype_name + ), true); } } - + if ($valid) { $shift['shifttype_id'] = $shifttype_id; $shift['title'] = $title; $shift['RID'] = $rid; $shift['start'] = $start; $shift['end'] = $end; - + $result = Shift_update($shift); if ($result === false) { engelsystem_error('Unable to update shift.'); @@ -119,100 +122,119 @@ function shift_edit_controller() 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)); + + 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 - ])); + '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 .= form_spinner('type_' . $angeltype_id, $angeltype_name, + $needed_angel_types[$angeltype_id]); } - - return page_with_title(shifts_title(), [ - msg(), - '', - form([ - form_select('shifttype_id', _('Shifttype'), $shifttypes, $shifttype_id), - form_text('title', _("Title"), $title), - form_select('rid', _("Room:"), $room, $rid), - form_text('start', _("Start:"), date("Y-m-d H:i", $start)), - form_text('end', _("End:"), date("Y-m-d H:i", $end)), - '

' . _("Needed angels") . '

', - $angel_types_spinner, - form_submit('submit', _("Save")) - ]) - ]); + + return page_with_title( + shifts_title(), + [ + msg(), + '', + form([ + form_select('shifttype_id', _('Shifttype'), $shifttypes, $shifttype_id), + form_text('title', _("Title"), $title), + form_select('rid', _("Room:"), $room, $rid), + form_text('start', _("Start:"), date("Y-m-d H:i", $start)), + form_text('end', _("End:"), date("Y-m-d H:i", $end)), + '

' . _("Needed angels") . '

', + $angel_types_spinner, + form_submit('submit', _("Save")) + ]) + ] + ); } function shift_delete_controller() { global $privileges; - - if (! in_array('user_shifts_admin', $privileges)) { + + if (!in_array('user_shifts_admin', $privileges)) { + redirect(page_link_to('user_shifts')); + } + + // Schicht komplett löschen (nur für admins/user mit user_shifts_admin privileg) + if (!isset($_REQUEST['delete_shift']) || !preg_match("/^[0-9]*$/", $_REQUEST['delete_shift'])) { redirect(page_link_to('user_shifts')); } - - // Schicht komplett löschen (nur für admins/user mit user_shifts_admin privileg) - if (! isset($_REQUEST['delete_shift']) || ! preg_match("/^[0-9]*$/", $_REQUEST['delete_shift'])) { - redirect(page_link_to('user_shifts')); - } $shift_id = $_REQUEST['delete_shift']; - + $shift = Shift($shift_id); if ($shift == null) { redirect(page_link_to('user_shifts')); } - - // Schicht löschen bestätigt - if (isset($_REQUEST['delete'])) { - Shift_delete($shift_id); - - engelsystem_log("Deleted shift " . $shift['name'] . " from " . date("Y-m-d H:i", $shift['start']) . " to " . date("Y-m-d H:i", $shift['end'])); - success(_("Shift deleted.")); - redirect(page_link_to('user_shifts')); - } - + + // Schicht löschen bestätigt + if (isset($_REQUEST['delete'])) { + Shift_delete($shift_id); + + engelsystem_log( + "Deleted shift " . $shift['name'] + . " from " . date("Y-m-d H:i", $shift['start']) + . " to " . date("Y-m-d H:i", $shift['end']) + ); + success(_("Shift deleted.")); + redirect(page_link_to('user_shifts')); + } + return page_with_title(shifts_title(), [ - error(sprintf(_("Do you want to delete the shift %s from %s to %s?"), $shift['name'], date("Y-m-d H:i", $shift['start']), date("H:i", $shift['end'])), true), - '' . _("delete") . '' - ]); + 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), + '' . _("delete") . '' + ]); } function shift_controller() { global $user, $privileges; - - if (! in_array('user_shifts', $privileges)) { + + if (!in_array('user_shifts', $privileges)) { redirect(page_link_to('?')); } - - if (! isset($_REQUEST['shift_id'])) { + + 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')); } - + $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']); - - $angeltype_signup_state = Shift_signup_allowed($user, $shift, $angeltype, null, $user_shifts, $needed_angeltype, $shift_entries); + + $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 { @@ -220,27 +242,27 @@ function shift_controller() } $angeltype['shift_signup_state'] = $angeltype_signup_state; } - + return [ - $shift['name'], - Shift_view($shift, $shifttype, $room, $angeltypes, $shift_signup_state) - ]; + $shift['name'], + Shift_view($shift, $shifttype, $room, $angeltypes, $shift_signup_state) + ]; } function shifts_controller() { - if (! isset($_REQUEST['action'])) { + if (!isset($_REQUEST['action'])) { redirect(page_link_to('user_shifts')); } - + switch ($_REQUEST['action']) { - default: - redirect(page_link_to('?')); - case 'view': - return shift_controller(); - case 'next': - return shift_next_controller(); - } + default: + redirect(page_link_to('?')); + case 'view': + return shift_controller(); + case 'next': + return shift_next_controller(); + } } /** @@ -249,20 +271,20 @@ function shifts_controller() function shift_next_controller() { global $user, $privileges; - - if (! in_array('user_shifts', $privileges)) { + + if (!in_array('user_shifts', $privileges)) { redirect(page_link_to('?')); } - + $upcoming_shifts = ShiftEntries_upcoming_for_user($user); if ($upcoming_shifts === false) { return false; } - + if (count($upcoming_shifts) > 0) { redirect(shift_link($upcoming_shifts[0])); } - + redirect(page_link_to('user_shifts')); } @@ -272,24 +294,24 @@ function shift_next_controller() function shifts_json_export_all_controller() { global $api_key; - + if ($api_key == "") { engelsystem_error("Config contains empty apikey."); } - - if (! isset($_REQUEST['api_key'])) { + + if (!isset($_REQUEST['api_key'])) { engelsystem_error("Missing parameter 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."); } - + header("Content-Type: application/json; charset=utf-8"); raw_output(json_encode($shifts_source)); } @@ -301,23 +323,23 @@ function shifts_json_export_all_controller() function shifts_json_export_controller() { global $user; - - if (! isset($_REQUEST['key']) || ! preg_match("/^[0-9a-f]{32}$/", $_REQUEST['key'])) { + + if (!isset($_REQUEST['key']) || !preg_match("/^[0-9a-f]{32}$/", $_REQUEST['key'])) { engelsystem_error("Missing 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']))) { + if (!in_array('shifts_json_export', privileges_for_user($user['UID']))) { engelsystem_error("No privilege for shifts_json_export."); } - + $shifts = load_ical_shifts(); - + header("Content-Type: application/json; charset=utf-8"); raw_output(json_encode($shifts)); } @@ -328,6 +350,6 @@ function shifts_json_export_controller() function load_ical_shifts() { global $user; - + return Shifts_by_user($user); } diff --git a/includes/controller/shifttypes_controller.php b/includes/controller/shifttypes_controller.php index f54111c4..4bbf041d 100644 --- a/includes/controller/shifttypes_controller.php +++ b/includes/controller/shifttypes_controller.php @@ -10,34 +10,34 @@ function shifttype_link($shifttype) */ function shifttype_delete_controller() { - if (! isset($_REQUEST['shifttype_id'])) { + 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')); } - + 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')); } - + return [ - sprintf(_("Delete shifttype %s"), $shifttype['name']), - ShiftType_delete_view($shifttype) - ]; + sprintf(_("Delete shifttype %s"), $shifttype['name']), + ShiftType_delete_view($shifttype) + ]; } /** @@ -49,9 +49,9 @@ function shifttype_edit_controller() $name = ""; $angeltype_id = null; $description = ""; - + $angeltypes = AngelTypes(); - + if (isset($_REQUEST['shifttype_id'])) { $shifttype = ShiftType($_REQUEST['shifttype_id']); if ($shifttype === false) { @@ -66,27 +66,27 @@ function shifttype_edit_controller() $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['angeltype_id']) && preg_match("/^[0-9]+$/", $_REQUEST['angeltype_id'])) { $angeltype_id = $_REQUEST['angeltype_id']; } else { $angeltype_id = null; } - + if (isset($_REQUEST['description'])) { $description = strip_request_item_nl('description'); } - + if ($valid) { if ($shifttype_id) { $result = ShiftType_update($shifttype_id, $name, $angeltype_id, $description); @@ -106,16 +106,16 @@ function shifttype_edit_controller() redirect(page_link_to('shifttypes') . '&action=view&shifttype_id=' . $shifttype_id); } } - + return [ - shifttypes_title(), - ShiftType_edit_view($name, $angeltype_id, $angeltypes, $description, $shifttype_id) - ]; + shifttypes_title(), + ShiftType_edit_view($name, $angeltype_id, $angeltypes, $description, $shifttype_id) + ]; } function shifttype_controller() { - if (! isset($_REQUEST['shifttype_id'])) { + if (!isset($_REQUEST['shifttype_id'])) { redirect(page_link_to('shifttypes')); } $shifttype = ShiftType($_REQUEST['shifttype_id']); @@ -125,16 +125,16 @@ function shifttype_controller() if ($shifttype == null) { redirect(page_link_to('shifttypes')); } - + $angeltype = null; if ($shifttype['angeltype_id'] != null) { $angeltype = AngelType($shifttype['angeltype_id']); } - + return [ - $shifttype['name'], - ShiftType_view($shifttype, $angeltype) - ]; + $shifttype['name'], + ShiftType_view($shifttype, $angeltype) + ]; } /** @@ -146,11 +146,11 @@ function shifttypes_list_controller() if ($shifttypes === false) { engelsystem_error("Unable to load shifttypes."); } - + return [ - shifttypes_title(), - ShiftTypes_list_view($shifttypes) - ]; + shifttypes_title(), + ShiftTypes_list_view($shifttypes) + ]; } /** @@ -166,19 +166,19 @@ function shifttypes_title() */ function shifttypes_controller() { - if (! isset($_REQUEST['action'])) { + if (!isset($_REQUEST['action'])) { $_REQUEST['action'] = 'list'; } - + switch ($_REQUEST['action']) { - default: - case 'list': - return shifttypes_list_controller(); - case 'view': - return shifttype_controller(); - case 'edit': - return shifttype_edit_controller(); - case 'delete': - return shifttype_delete_controller(); - } + default: + case 'list': + return shifttypes_list_controller(); + case 'view': + return shifttype_controller(); + case 'edit': + return shifttype_edit_controller(); + case 'delete': + return shifttype_delete_controller(); + } } diff --git a/includes/controller/user_angeltypes_controller.php b/includes/controller/user_angeltypes_controller.php index 7469304b..fefde9ae 100644 --- a/includes/controller/user_angeltypes_controller.php +++ b/includes/controller/user_angeltypes_controller.php @@ -6,18 +6,21 @@ function user_angeltypes_unconfirmed_hint() { global $user; - + $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[] = '' . $user_angeltype['name'] . ' (+' . $user_angeltype['count'] . ')' . ''; } - - 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); } /** @@ -26,35 +29,35 @@ function user_angeltypes_unconfirmed_hint() function user_angeltypes_delete_all_controller() { global $user; - - if (! isset($_REQUEST['angeltype_id'])) { + + 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')); } - - if (! User_is_AngelType_supporter($user, $angeltype)) { + + if (!User_is_AngelType_supporter($user, $angeltype)) { error(_("You are not allowed to delete all users for this angeltype.")); redirect(page_link_to('angeltypes')); } - + if (isset($_REQUEST['confirmed'])) { 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']); } - + return [ - _("Deny all users"), - UserAngelTypes_delete_all_view($angeltype) - ]; + _("Deny all users"), + UserAngelTypes_delete_all_view($angeltype) + ]; } /** @@ -63,41 +66,41 @@ function user_angeltypes_delete_all_controller() function user_angeltypes_confirm_all_controller() { global $user, $privileges; - - if (! isset($_REQUEST['angeltype_id'])) { + + 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')); } - + $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']) { + + 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); - + 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 [ - _("Confirm all users"), - UserAngelTypes_confirm_all_view($angeltype) - ]; + _("Confirm all users"), + UserAngelTypes_confirm_all_view($angeltype) + ]; } /** @@ -106,50 +109,58 @@ function user_angeltypes_confirm_all_controller() function user_angeltype_confirm_controller() { global $user; - - if (! isset($_REQUEST['user_angeltype_id'])) { + + 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')); } - + $angeltype = AngelType($user_angeltype['angeltype_id']); if ($angeltype == null) { error(_("Angeltype doesn't exist.")); redirect(page_link_to('angeltypes')); } - - if (! User_is_AngelType_supporter($user, $angeltype)) { + + if (!User_is_AngelType_supporter($user, $angeltype)) { error(_("You are not allowed to confirm this users angeltype.")); redirect(page_link_to('angeltypes')); } - + $user_source = User($user_angeltype['user_id']); if ($user_source == 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))); + + 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 [ - _("Confirm angeltype for user"), - UserAngelType_confirm_view($user_angeltype, $user_source, $angeltype) - ]; + _("Confirm angeltype for user"), + UserAngelType_confirm_view($user_angeltype, $user_source, $angeltype) + ]; } /** @@ -158,52 +169,52 @@ function user_angeltype_confirm_controller() function user_angeltype_delete_controller() { global $user; - - if (! isset($_REQUEST['user_angeltype_id'])) { + + 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')); } - + $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['UID'] != $user_angeltype['user_id'] && ! User_is_AngelType_supporter($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); - + redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']); } - + return [ - _("Remove angeltype"), - UserAngelType_delete_view($user_angeltype, $user_source, $angeltype) - ]; + _("Remove angeltype"), + UserAngelType_delete_view($user_angeltype, $user_source, $angeltype) + ]; } /** @@ -212,56 +223,60 @@ function user_angeltype_delete_controller() function user_angeltype_update_controller() { global $privileges; - - if (! in_array('admin_angel_types', $privileges)) { + + 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'])) { + + 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')); } - + $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')); } - + $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); - - $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)); + + $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']); } - + return [ - $supporter ? _("Add supporter rights") : _("Remove supporter rights"), - UserAngelType_update_view($user_angeltype, $user_source, $angeltype, $supporter) - ]; + $supporter ? _("Add supporter rights") : _("Remove supporter rights"), + UserAngelType_update_view($user_angeltype, $user_source, $angeltype, $supporter) + ]; } /** @@ -270,42 +285,54 @@ function user_angeltype_update_controller() function user_angeltype_add_controller() { global $user; - + $angeltype = load_angeltype(); - - // User is joining by itself - if (! User_is_AngelType_supporter($user, $angeltype)) { - return user_angeltype_join_controller($angeltype); - } - - // Allow to add any user - - // Default selection - $user_source = $user; - - // Load possible users, that are not in the angeltype already - $users_source = Users_by_angeltype_inverted($angeltype); - + + // User is joining by itself + if (!User_is_AngelType_supporter($user, $angeltype)) { + return user_angeltype_join_controller($angeltype); + } + + // Allow to add any user + + // Default selection + $user_source = $user; + + // 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 (! UserAngelType_exists($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))); - + 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']); } } - + return [ - _("Add user to angeltype"), - UserAngelType_add_view($angeltype, $users_source, $user_source['UID']) - ]; + _("Add user to angeltype"), + UserAngelType_add_view($angeltype, $users_source, $user_source['UID']) + ]; } /** @@ -314,32 +341,36 @@ function user_angeltype_add_controller() 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); - + $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))); + 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']); } - + return [ - sprintf(_("Become a %s"), $angeltype['name']), - UserAngelType_join_view($user, $angeltype) - ]; + sprintf(_("Become a %s"), $angeltype['name']), + UserAngelType_join_view($user, $angeltype) + ]; } /** @@ -347,24 +378,24 @@ function user_angeltype_join_controller($angeltype) */ function user_angeltypes_controller() { - if (! isset($_REQUEST['action'])) { + if (!isset($_REQUEST['action'])) { redirect(page_link_to('angeltypes')); } - + switch ($_REQUEST['action']) { - case 'delete_all': - return user_angeltypes_delete_all_controller(); - case 'confirm_all': - return user_angeltypes_confirm_all_controller(); - case 'confirm': - return user_angeltype_confirm_controller(); - case 'delete': - return user_angeltype_delete_controller(); - case 'update': - return user_angeltype_update_controller(); - case 'add': - return user_angeltype_add_controller(); - default: - redirect(page_link_to('angeltypes')); - } + case 'delete_all': + return user_angeltypes_delete_all_controller(); + case 'confirm_all': + return user_angeltypes_confirm_all_controller(); + case 'confirm': + return user_angeltype_confirm_controller(); + case 'delete': + return user_angeltype_delete_controller(); + case 'update': + return user_angeltype_update_controller(); + case 'add': + return user_angeltype_add_controller(); + default: + redirect(page_link_to('angeltypes')); + } } diff --git a/includes/controller/user_driver_licenses_controller.php b/includes/controller/user_driver_licenses_controller.php index 434d9274..a499eff7 100644 --- a/includes/controller/user_driver_licenses_controller.php +++ b/includes/controller/user_driver_licenses_controller.php @@ -1,26 +1,30 @@ ' . _("driving license information") . ''); + return sprintf( + _("You joined an angeltype which requires a driving license. Please edit your driving license information here: %s."), + '' . _("driving license information") . '' + ); } } - + return null; } @@ -30,18 +34,18 @@ function user_driver_license_required_hint() function user_driver_licenses_controller() { global $user; - - if (! isset($user)) { + + if (!isset($user)) { redirect(page_link_to('')); } - + $action = strip_request_item('action', 'edit'); - + switch ($action) { - default: - case 'edit': - return user_driver_license_edit_controller(); - } + default: + case 'edit': + return user_driver_license_edit_controller(); + } } /** @@ -63,16 +67,16 @@ function user_driver_license_edit_link($user = null) function user_driver_license_load_user() { global $user; - + $user_source = $user; - + if (isset($_REQUEST['user_id'])) { $user_source = User($_REQUEST['user_id']); if ($user_source == null) { redirect(user_driver_license_edit_link()); } } - + return $user_source; } @@ -82,14 +86,14 @@ function user_driver_license_load_user() function user_driver_license_edit_controller() { global $privileges, $user; - + $user_source = user_driver_license_load_user(); - - // only privilege admin_user can edit other users driver license information - if ($user['UID'] != $user_source['UID'] && ! in_array('admin_user', $privileges)) { - redirect(user_driver_license_edit_link()); - } - + + // 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()); + } + $user_driver_license = UserDriverLicense($user_source['UID']); if ($user_driver_license == null) { $wants_to_drive = false; @@ -97,7 +101,7 @@ function user_driver_license_edit_controller() } else { $wants_to_drive = true; } - + if (isset($_REQUEST['submit'])) { $wants_to_drive = isset($_REQUEST['wants_to_drive']); if ($wants_to_drive) { @@ -107,7 +111,7 @@ function user_driver_license_edit_controller() $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); @@ -127,9 +131,9 @@ function user_driver_license_edit_controller() redirect(user_link($user_source)); } } - + return [ - sprintf(_("Edit %s driving license information"), $user_source['Nick']), - UserDriverLicense_edit_view($user_source, $wants_to_drive, $user_driver_license) - ]; + sprintf(_("Edit %s driving license information"), $user_source['Nick']), + UserDriverLicense_edit_view($user_source, $wants_to_drive, $user_driver_license) + ]; } diff --git a/includes/controller/users_controller.php b/includes/controller/users_controller.php index 4f7b97eb..4a946aa8 100644 --- a/includes/controller/users_controller.php +++ b/includes/controller/users_controller.php @@ -1,6 +1,6 @@ = 0) { $vouchers = trim($_REQUEST['vouchers']); } else { $valid = false; error(_("Please enter a valid number of vouchers.")); } - + if ($valid) { $user_source['got_voucher'] = $vouchers; - + $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'])); - + engelsystem_log(User_Nick_render($user_source) . ': ' . sprintf("Got %s vouchers", + $user_source['got_voucher'])); + redirect(user_link($user_source)); } } - + return [ - sprintf(_("%s's vouchers"), $user_source['Nick']), - User_edit_vouchers_view($user_source) - ]; + sprintf(_("%s's vouchers"), $user_source['Nick']), + User_edit_vouchers_view($user_source) + ]; } function user_controller() { global $privileges, $user; - + $user_source = $user; if (isset($_REQUEST['user_id'])) { $user_source = User($_REQUEST['user_id']); @@ -160,11 +163,11 @@ function user_controller() redirect('?'); } } - + $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`"); + $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(" SELECT `ShiftEntry`.`freeloaded`, `User`.* @@ -174,15 +177,23 @@ function user_controller() AND `ShiftEntry`.`TID`='" . sql_escape($needed_angeltype['id']) . "'"); } } - + if ($user_source['api_key'] == "") { User_reset_api_key($user_source, false); } - + 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_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'] + ) + ]; } /** @@ -191,29 +202,38 @@ function user_controller() function users_list_controller() { global $privileges; - - if (! in_array('admin_user', $privileges)) { + + 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']; } - + $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)); } - + 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()) - ]; + _('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() + ) + ]; } /** @@ -227,7 +247,7 @@ function user_password_recovery_set_new_controller() error(_("Token is not correct.")); redirect(page_link_to('login')); } - + if (isset($_REQUEST['submit'])) { $valid = true; @@ -240,14 +260,14 @@ function user_password_recovery_set_new_controller() $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')); } } - + return User_password_set_view(); } @@ -258,7 +278,7 @@ 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)) { @@ -275,15 +295,22 @@ function user_password_recovery_start_controller() $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)); + 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(); } @@ -313,20 +340,20 @@ function user_password_recovery_title() */ function load_user() { - if (! isset($_REQUEST['user_id'])) { + if (!isset($_REQUEST['user_id'])) { redirect(page_link_to()); } - + $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()); } - + return $user; } @@ -335,7 +362,7 @@ 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) { @@ -354,11 +381,14 @@ function shiftCalendarRendererByShiftFilter(ShiftsFilter $shiftsFilter) } unset($needed_angeltypes_source); unset($shift_entries_source); - - if (in_array(ShiftsFilter::FILLED_FREE, $shiftsFilter->getFilled()) && in_array(ShiftsFilter::FILLED_FILLED, $shiftsFilter->getFilled())) { + + 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; @@ -366,10 +396,10 @@ function shiftCalendarRendererByShiftFilter(ShiftsFilter $shiftsFilter) $taken = 0; foreach ($shift_entries[$shift['SID']] as $shift_entry) { if ($needed_angeltype['angel_type_id'] == $shift_entry['TID'] && $shift_entry['freeloaded'] == 0) { - $taken ++; + $taken++; } } - + $needed_angels_count += max(0, $needed_angeltype['count'] - $taken); } if (in_array(ShiftsFilter::FILLED_FREE, $shiftsFilter->getFilled()) && $taken < $needed_angels_count) { @@ -379,6 +409,6 @@ function shiftCalendarRendererByShiftFilter(ShiftsFilter $shiftsFilter) $filtered_shifts[] = $shift; } } - + return new ShiftCalendarRenderer($filtered_shifts, $needed_angeltypes, $shift_entries, $shiftsFilter); } diff --git a/includes/helper/email_helper.php b/includes/helper/email_helper.php index 934193e2..35bdbc9a 100644 --- a/includes/helper/email_helper.php +++ b/includes/helper/email_helper.php @@ -3,22 +3,26 @@ function engelsystem_email_to_user($recipient_user, $title, $message, $not_if_its_me = false) { global $user; - + if ($not_if_its_me && $user['UID'] == $recipient_user['UID']) { return true; } - + gettext_locale($recipient_user['Sprache']); - - $message = sprintf(_("Hi %s,"), $recipient_user['Nick']) . "\n\n" . _("here is a message for you from the engelsystem:") . "\n\n" . $message . "\n\n" . _("This email is autogenerated and has not to be signed. You got this email because you are registered in the engelsystem."); - + + $message = sprintf(_("Hi %s,"), $recipient_user['Nick']) . "\n\n" + . _("here is a message for you from the engelsystem:") . "\n\n" + . $message . "\n\n" + . _("This email is autogenerated and has not to be signed. You got this email because you are registered in the engelsystem."); + gettext_locale(); return engelsystem_email($recipient_user['email'], $title, $message); } function engelsystem_email($address, $title, $message) { - $result = mail($address, $title, $message, "Content-Type: text/plain; charset=UTF-8\r\nFrom: Engelsystem "); + $result = mail($address, $title, $message, + "Content-Type: text/plain; charset=UTF-8\r\nFrom: Engelsystem "); if ($result === false) { engelsystem_error('Unable to send email.'); } diff --git a/includes/helper/graph_helper.php b/includes/helper/graph_helper.php index c2d0f8a2..d844213c 100644 --- a/includes/helper/graph_helper.php +++ b/includes/helper/graph_helper.php @@ -2,10 +2,11 @@ /** * Renders a bargraph - * @param string $key keyname of the x-axis - * @param array $row_names keynames for the data rows - * @param unknown $colors colors for the data rows - * @param unknown $data the data + * + * @param string $key keyname of the x-axis + * @param array $row_names keynames for the data rows + * @param unknown $colors colors for the data rows + * @param unknown $data the data */ function bargraph($dom_id, $key, $row_names, $colors, $data) { @@ -13,7 +14,7 @@ function bargraph($dom_id, $key, $row_names, $colors, $data) foreach ($data as $dataset) { $labels[] = $dataset[$key]; } - + $datasets = []; foreach ($row_names as $row_key => $name) { $values = []; @@ -21,20 +22,20 @@ function bargraph($dom_id, $key, $row_names, $colors, $data) $values[] = $dataset[$row_key]; } $datasets[] = [ - 'label' => $name, - 'fillColor' => $colors[$row_key], - 'data' => $values - ]; + 'label' => $name, + 'fillColor' => $colors[$row_key], + 'data' => $values + ]; } - + return ' '; } diff --git a/includes/helper/internationalization_helper.php b/includes/helper/internationalization_helper.php index 4abf8c4d..d4df1cb7 100644 --- a/includes/helper/internationalization_helper.php +++ b/includes/helper/internationalization_helper.php @@ -31,7 +31,7 @@ function gettext_init() if (isset($_REQUEST['set_locale']) && isset($locales[$_REQUEST['set_locale']])) { $_SESSION['locale'] = $_REQUEST['set_locale']; - } elseif (! isset($_SESSION['locale'])) { + } elseif (!isset($_SESSION['locale'])) { $_SESSION['locale'] = $default_locale; } @@ -51,7 +51,7 @@ function gettext_locale($locale = null) if ($locale == null) { $locale = $_SESSION['locale']; } - + putenv('LC_ALL=' . $locale); setlocale(LC_ALL, $locale); } @@ -65,10 +65,14 @@ function make_langselect() { global $locales; $URL = $_SERVER["REQUEST_URI"] . (strpos($_SERVER["REQUEST_URI"], "?") > 0 ? '&' : '?') . "set_locale="; - + $items = []; foreach ($locales as $locale => $name) { - $items[] = toolbar_item_link(htmlspecialchars($URL) . $locale, '', '' . $name . ' ' . $name); + $items[] = toolbar_item_link( + htmlspecialchars($URL) . $locale, + '', + '' . $name . ' ' . $name + ); } return $items; } diff --git a/includes/helper/message_helper.php b/includes/helper/message_helper.php index 323eee4d..a085aa0e 100644 --- a/includes/helper/message_helper.php +++ b/includes/helper/message_helper.php @@ -5,7 +5,7 @@ */ function msg() { - if (! isset($_SESSION['msg'])) { + if (!isset($_SESSION['msg'])) { return ""; } $msg = $_SESSION['msg']; @@ -48,8 +48,8 @@ function alert($class, $msg, $immediatly = false) } return '
' . $msg . '
'; } - - if (! isset($_SESSION['msg'])) { + + if (!isset($_SESSION['msg'])) { $_SESSION['msg'] = ""; } $_SESSION['msg'] .= alert($class, $msg, true); diff --git a/includes/mailer/shifts_mailer.php b/includes/mailer/shifts_mailer.php index fd0d32c0..e000c927 100644 --- a/includes/mailer/shifts_mailer.php +++ b/includes/mailer/shifts_mailer.php @@ -5,50 +5,58 @@ function mail_shift_change($old_shift, $new_shift) $users = ShiftEntries_by_shift($old_shift["SID"]); $old_room = Room($old_shift["RID"]); $new_room = Room($new_shift["RID"]); - + $noticable_changes = false; - + $message = _("A Shift you are registered on has changed:"); $message .= "\n"; - + if ($old_shift["name"] != $new_shift["name"]) { $message .= sprintf(_("* Shift type changed from %s to %s"), $old_shift["name"], $new_shift["name"]) . "\n"; $noticable_changes = true; } - + if ($old_shift["title"] != $new_shift["title"]) { $message .= sprintf(_("* Shift title changed from %s to %s"), $old_shift["title"], $new_shift["title"]) . "\n"; $noticable_changes = true; } - + if ($old_shift["start"] != $new_shift["start"]) { - $message .= sprintf(_("* Shift Start changed from %s to %s"), date("Y-m-d H:i", $old_shift["start"]), date("Y-m-d H:i", $new_shift["start"])) . "\n"; + $message .= sprintf( + _("* Shift Start changed from %s to %s"), + date("Y-m-d H:i", $old_shift["start"]), + date("Y-m-d H:i", $new_shift["start"]) + ) . "\n"; $noticable_changes = true; } - + if ($old_shift["end"] != $new_shift["end"]) { - $message .= sprintf(_("* Shift End changed from %s to %s"), date("Y-m-d H:i", $old_shift["end"]), date("Y-m-d H:i", $new_shift["end"])) . "\n"; + $message .= sprintf( + _("* Shift End changed from %s to %s"), + date("Y-m-d H:i", $old_shift["end"]), + date("Y-m-d H:i", $new_shift["end"]) + ) . "\n"; $noticable_changes = true; } - + if ($old_shift["RID"] != $new_shift["RID"]) { $message .= sprintf(_("* Shift Location changed from %s to %s"), $old_room["Name"], $new_room["Name"]) . "\n"; $noticable_changes = true; } - - if (! $noticable_changes) { + + if (!$noticable_changes) { // There are no changes worth sending an E-Mail - return; + return; } - + $message .= "\n"; $message .= _("The updated Shift:") . "\n"; - + $message .= $new_shift["name"] . "\n"; $message .= $new_shift["title"] . "\n"; $message .= date("Y-m-d H:i", $new_shift["start"]) . " - " . date("H:i", $new_shift["end"]) . "\n"; $message .= $new_room["Name"] . "\n"; - + foreach ($users as $user) { if ($user["email_shiftinfo"]) { engelsystem_email_to_user($user, '[engelsystem] ' . _("Your Shift has changed"), $message, true); @@ -60,14 +68,14 @@ function mail_shift_delete($shift) { $users = ShiftEntries_by_shift($shift["SID"]); $room = Room($shift["RID"]); - + $message = _("A Shift you are registered on was deleted:") . "\n"; - + $message .= $shift["name"] . "\n"; $message .= $shift["title"] . "\n"; $message .= date("Y-m-d H:i", $shift["start"]) . " - " . date("H:i", $shift["end"]) . "\n"; $message .= $room["Name"] . "\n"; - + foreach ($users as $user) { if ($user["email_shiftinfo"]) { engelsystem_email_to_user($user, '[engelsystem] ' . _("Your Shift was deleted"), $message, true); @@ -79,13 +87,13 @@ function mail_shift_assign($user, $shift) { if ($user["email_shiftinfo"]) { $room = Room($shift["RID"]); - + $message = _("You have been assigned to a Shift:") . "\n"; $message .= $shift["name"] . "\n"; $message .= $shift["title"] . "\n"; $message .= date("Y-m-d H:i", $shift["start"]) . " - " . date("H:i", $shift["end"]) . "\n"; $message .= $room["Name"] . "\n"; - + engelsystem_email_to_user($user, '[engelsystem] ' . _("Assigned to Shift"), $message, true); } } @@ -94,13 +102,13 @@ function mail_shift_removed($user, $shift) { if ($user["email_shiftinfo"]) { $room = Room($shift["RID"]); - + $message = _("You have been removed from a Shift:") . "\n"; $message .= $shift["name"] . "\n"; $message .= $shift["title"] . "\n"; $message .= date("Y-m-d H:i", $shift["start"]) . " - " . date("H:i", $shift["end"]) . "\n"; $message .= $room["Name"] . "\n"; - + engelsystem_email_to_user($user, '[engelsystem] ' . _("Removed from Shift"), $message, true); } } diff --git a/includes/mailer/users_mailer.php b/includes/mailer/users_mailer.php index bae8d918..85409c8c 100644 --- a/includes/mailer/users_mailer.php +++ b/includes/mailer/users_mailer.php @@ -5,5 +5,9 @@ */ function mail_user_delete($user) { - engelsystem_email_to_user($user, '[engelsystem] ' . _("Your account has been deleted"), _("Your angelsystem account has been deleted. If you have any questions regarding your account deletion, please contact heaven.")); + engelsystem_email_to_user( + $user, + '[engelsystem] ' . _("Your account has been deleted"), + _("Your angelsystem account has been deleted. If you have any questions regarding your account deletion, please contact heaven.") + ); } diff --git a/includes/model/AngelType_model.php b/includes/model/AngelType_model.php index 022462c0..d52b1357 100644 --- a/includes/model/AngelType_model.php +++ b/includes/model/AngelType_model.php @@ -8,17 +8,17 @@ use Engelsystem\ValidationResult; function AngelType_new() { return [ - 'id' => null, - 'name' => "", - 'restricted' => false, - 'no_self_signup' => false, - 'description' => '', - 'requires_driver_license' => false, - 'contact_user_id' => null, - 'contact_name' => null, - 'contact_dect' => null, - 'contact_email' => null - ]; + 'id' => null, + 'name' => "", + 'restricted' => false, + 'no_self_signup' => false, + 'description' => '', + 'requires_driver_license' => false, + 'contact_user_id' => null, + 'contact_name' => null, + 'contact_dect' => null, + 'contact_email' => null + ]; } /** @@ -30,7 +30,7 @@ function AngelType_new() */ function AngelType_validate_contact_user_id($angeltype) { - if (! isset($angeltype['contact_user_id'])) { + if (!isset($angeltype['contact_user_id'])) { return new ValidationResult(true, null); } if (isset($angeltype['contact_name']) || isset($angeltype['contact_dect']) || isset($angeltype['contact_email'])) { @@ -53,9 +53,9 @@ function AngelType_contact_info($angeltype) if (isset($angeltype['contact_user_id'])) { $contact_user = User($angeltype['contact_user_id']); $contact_data = [ - 'contact_name' => $contact_user['Nick'], - 'contact_dect' => $contact_user['DECT'] - ]; + 'contact_name' => $contact_user['Nick'], + 'contact_dect' => $contact_user['DECT'] + ]; if ($contact_user['email_by_human_allowed']) { $contact_data['contact_email'] = $contact_user['email']; } @@ -63,10 +63,10 @@ function AngelType_contact_info($angeltype) } if (isset($angeltype['contact_name'])) { return [ - 'contact_name' => $angeltype['contact_name'], - 'contact_dect' => $angeltype['contact_dect'], - 'contact_email' => $angeltype['contact_email'] - ]; + 'contact_name' => $angeltype['contact_name'], + 'contact_dect' => $angeltype['contact_dect'], + 'contact_email' => $angeltype['contact_email'] + ]; } return null; } @@ -148,7 +148,7 @@ function AngelType_create($angeltype) * Validates a name for angeltypes. * Returns ValidationResult containing validation success and validated name. * - * @param string $name + * @param string $name * Wanted name for the angeltype * @param AngelType $angeltype * The angeltype the name is for @@ -186,7 +186,7 @@ function AngelTypes_with_user($user) { $result = sql_select(" SELECT `AngelTypes`.*, - `UserAngelTypes`.`id` as `user_angeltype_id`, + `UserAngelTypes`.`id` AS `user_angeltype_id`, `UserAngelTypes`.`confirm_user_id`, `UserAngelTypes`.`supporter` FROM `AngelTypes` @@ -230,7 +230,7 @@ function AngelType_ids() * Returns angelType by id. * * @param $angeltype_id angelType - * ID + * ID */ function AngelType($angeltype_id) { diff --git a/includes/model/EventConfig_model.php b/includes/model/EventConfig_model.php index b4fdb728..584c1515 100644 --- a/includes/model/EventConfig_model.php +++ b/includes/model/EventConfig_model.php @@ -20,14 +20,20 @@ function EventConfig() * Update event config. * * @param string $event_name - * @param int $buildup_start_date - * @param int $event_start_date - * @param int $event_end_date - * @param int $teardown_end_date + * @param int $buildup_start_date + * @param int $event_start_date + * @param int $event_end_date + * @param int $teardown_end_date * @param string $event_welcome_msg */ -function EventConfig_update($event_name, $buildup_start_date, $event_start_date, $event_end_date, $teardown_end_date, $event_welcome_msg) -{ +function EventConfig_update( + $event_name, + $buildup_start_date, + $event_start_date, + $event_end_date, + $teardown_end_date, + $event_welcome_msg +) { if (EventConfig() == null) { return sql_query("INSERT INTO `EventConfig` SET `event_name`=" . sql_null($event_name) . ", diff --git a/includes/model/LogEntries_model.php b/includes/model/LogEntries_model.php index 2a3a1d6e..47e48f6f 100644 --- a/includes/model/LogEntries_model.php +++ b/includes/model/LogEntries_model.php @@ -3,9 +3,9 @@ /** * Creates a log entry. * - * @param $nick Username + * @param $nick Username * @param $message Log - * Message + * Message */ function LogEntry_create($nick, $message) { diff --git a/includes/model/Message_model.php b/includes/model/Message_model.php index 6ee19792..39eada71 100644 --- a/includes/model/Message_model.php +++ b/includes/model/Message_model.php @@ -12,7 +12,7 @@ function Message_ids() * Returns message by id. * * @param $message_id message - * ID + * ID */ function Message($message_id) { @@ -32,21 +32,36 @@ function Message($message_id) * send message * * @param $receiver_user_id User - * ID of Reciever - * @param $text Text - * of Message + * ID of Reciever + * @param $text Text + * of Message */ function Message_send($receiver_user_id, $text) { global $user; - + $text = preg_replace("/([^\p{L}\p{P}\p{Z}\p{N}\n]{1,})/ui", '', strip_tags($text)); $receiver_user_id = preg_replace("/([^0-9]{1,})/ui", '', strip_tags($receiver_user_id)); - - if (($text != "" && is_numeric($receiver_user_id)) && (sql_num_query("SELECT * FROM `User` WHERE `UID`='" . sql_escape($receiver_user_id) . "' AND NOT `UID`='" . sql_escape($user['UID']) . "' LIMIT 1") > 0)) { - sql_query("INSERT INTO `Messages` SET `Datum`='" . sql_escape(time()) . "', `SUID`='" . sql_escape($user['UID']) . "', `RUID`='" . sql_escape($receiver_user_id) . "', `Text`='" . sql_escape($text) . "'"); + + if ( + ($text != "" && is_numeric($receiver_user_id)) + && (sql_num_query(" + SELECT * + FROM `User` + WHERE `UID`='" . sql_escape($receiver_user_id) . "' + AND NOT `UID`='" . sql_escape($user['UID']) . "' + LIMIT 1 + ") > 0) + ) { + sql_query(" + INSERT INTO `Messages` + SET `Datum`='" . sql_escape(time()) . "', + `SUID`='" . sql_escape($user['UID']) . "', + `RUID`='" . sql_escape($receiver_user_id) . "', + `Text`='" . sql_escape($text) . "' + "); return true; } - + return false; } diff --git a/includes/model/NeededAngelTypes_model.php b/includes/model/NeededAngelTypes_model.php index e2661b9a..6a929f2f 100644 --- a/includes/model/NeededAngelTypes_model.php +++ b/includes/model/NeededAngelTypes_model.php @@ -71,10 +71,10 @@ function NeededAngelTypes_by_shift($shiftId) if ($needed_angeltypes_source === false) { engelsystem_error("Unable to load needed angeltypes."); } - - // Use settings from room - if (count($needed_angeltypes_source) == 0) { - $needed_angeltypes_source = sql_select(" + + // Use settings from room + if (count($needed_angeltypes_source) == 0) { + $needed_angeltypes_source = sql_select(" SELECT `NeededAngelTypes`.*, `AngelTypes`.`name`, `AngelTypes`.`restricted` FROM `NeededAngelTypes` JOIN `AngelTypes` ON `AngelTypes`.`id` = `NeededAngelTypes`.`angel_type_id` @@ -83,11 +83,11 @@ function NeededAngelTypes_by_shift($shiftId) AND `count` > 0 ORDER BY `room_id` DESC "); - if ($needed_angeltypes_source === false) { - engelsystem_error("Unable to load needed angeltypes."); - } - } - + if ($needed_angeltypes_source === false) { + engelsystem_error("Unable to load needed angeltypes."); + } + } + $shift_entries = ShiftEntries_by_shift($shiftId); $needed_angeltypes = []; foreach ($needed_angeltypes_source as $angeltype) { @@ -95,13 +95,13 @@ function NeededAngelTypes_by_shift($shiftId) $angeltype['taken'] = 0; foreach ($shift_entries as $shift_entry) { if ($shift_entry['TID'] == $angeltype['angel_type_id'] && $shift_entry['freeloaded'] == 0) { - $angeltype['taken'] ++; + $angeltype['taken']++; $angeltype['shift_entries'][] = $shift_entry; } } - + $needed_angeltypes[] = $angeltype; } - + return $needed_angeltypes; } diff --git a/includes/model/Room_model.php b/includes/model/Room_model.php index d7031d84..4c097f23 100644 --- a/includes/model/Room_model.php +++ b/includes/model/Room_model.php @@ -2,6 +2,7 @@ /** * returns a list of rooms. + * * @param boolean $show_all returns also hidden rooms when true */ function Rooms($show_all = false) @@ -22,7 +23,7 @@ function Room_delete($room_id) /** * Create a new room * - * @param string $name + * @param string $name * Name of the room * @param boolean $from_frab * Is this a frab imported room? @@ -51,7 +52,7 @@ function Room_create($name, $from_frab, $public) function Room($room_id) { $room_source = sql_select("SELECT * FROM `Room` WHERE `RID`='" . sql_escape($room_id) . "' AND `show` = 'Y'"); - + if ($room_source === false) { return false; } diff --git a/includes/model/ShiftEntry_model.php b/includes/model/ShiftEntry_model.php index c25938e3..a0755e3c 100644 --- a/includes/model/ShiftEntry_model.php +++ b/includes/model/ShiftEntry_model.php @@ -7,14 +7,14 @@ function ShiftEntry_new() { return [ - 'id' => null, - 'SID' => null, - 'TID' => null, - 'UID' => null, - 'Comment' => null, - 'freeloaded_comment' => null, - 'freeloaded' => false - ]; + 'id' => null, + 'SID' => null, + 'TID' => null, + 'UID' => null, + 'Comment' => null, + 'freeloaded_comment' => null, + 'freeloaded' => false + ]; } /** @@ -31,7 +31,18 @@ function ShiftEntries_freeleaded_count() function ShiftEntries_by_shift($shift_id) { return sql_select(" - SELECT `User`.`Nick`, `User`.`email`, `User`.`email_shiftinfo`, `User`.`Sprache`, `User`.`Gekommen`, `ShiftEntry`.`UID`, `ShiftEntry`.`TID`, `ShiftEntry`.`SID`, `AngelTypes`.`name` as `angel_type_name`, `ShiftEntry`.`Comment`, `ShiftEntry`.`freeloaded` + SELECT + `User`.`Nick`, + `User`.`email`, + `User`.`email_shiftinfo`, + `User`.`Sprache`, + `User`.`Gekommen`, + `ShiftEntry`.`UID`, + `ShiftEntry`.`TID`, + `ShiftEntry`.`SID`, + `AngelTypes`.`name` AS `angel_type_name`, + `ShiftEntry`.`Comment`, + `ShiftEntry`.`freeloaded` FROM `ShiftEntry` JOIN `User` ON `ShiftEntry`.`UID`=`User`.`UID` JOIN `AngelTypes` ON `ShiftEntry`.`TID`=`AngelTypes`.`id` diff --git a/includes/model/ShiftSignupState.php b/includes/model/ShiftSignupState.php index 9c20a575..d5c7f457 100644 --- a/includes/model/ShiftSignupState.php +++ b/includes/model/ShiftSignupState.php @@ -9,40 +9,40 @@ namespace Engelsystem; class ShiftSignupState { - /** - * Shift has free places - */ - const FREE = 'FREE'; - - /** - * Shift collides with users shifts - */ - const COLLIDES = 'COLLIDES'; - - /** - * User cannot join because of a restricted angeltype or user is not in the angeltype - */ - const ANGELTYPE = 'ANGELTYPE'; - - /** - * Shift is full - */ - const OCCUPIED = 'OCCUPIED'; - - /** - * User is admin and can do what he wants. - */ - const ADMIN = 'ADMIN'; - - /** - * Shift has already ended, no signup - */ - const SHIFT_ENDED = 'SHIFT_ENDED'; - - /** - * User is already signed up - */ - const SIGNED_UP = 'SIGNED_UP'; + /** + * Shift has free places + */ + const FREE = 'FREE'; + + /** + * Shift collides with users shifts + */ + const COLLIDES = 'COLLIDES'; + + /** + * User cannot join because of a restricted angeltype or user is not in the angeltype + */ + const ANGELTYPE = 'ANGELTYPE'; + + /** + * Shift is full + */ + const OCCUPIED = 'OCCUPIED'; + + /** + * User is admin and can do what he wants. + */ + const ADMIN = 'ADMIN'; + + /** + * Shift has already ended, no signup + */ + const SHIFT_ENDED = 'SHIFT_ENDED'; + + /** + * User is already signed up + */ + const SIGNED_UP = 'SIGNED_UP'; private $state; @@ -54,69 +54,69 @@ class ShiftSignupState $this->freeEntries = $free_entries; } - /** - * Combine this state with another state from the same shift. - * - * @param ShiftSignupState $shiftSignupState - * The other state to combine - */ - public function combineWith(ShiftSignupState $shiftSignupState) - { - $this->freeEntries += $shiftSignupState->getFreeEntries(); - - if ($this->valueForState($shiftSignupState->state) > $this->valueForState($this->state)) { - $this->state = $shiftSignupState->state; - } - } + /** + * Combine this state with another state from the same shift. + * + * @param ShiftSignupState $shiftSignupState + * The other state to combine + */ + public function combineWith(ShiftSignupState $shiftSignupState) + { + $this->freeEntries += $shiftSignupState->getFreeEntries(); + + if ($this->valueForState($shiftSignupState->state) > $this->valueForState($this->state)) { + $this->state = $shiftSignupState->state; + } + } private function valueForState($state) { switch ($state) { - case ShiftSignupState::SHIFT_ENDED: - return 100; - - case ShiftSignupState::SIGNED_UP: - return 90; - - case ShiftSignupState::FREE: - return 80; - - case ShiftSignupState::ANGELTYPE: - case ShiftSignupState::COLLIDES: - return 70; - - case ShiftSignupState::OCCUPIED: - case ShiftSignupState::ADMIN: - return 60; + case ShiftSignupState::SHIFT_ENDED: + return 100; + + case ShiftSignupState::SIGNED_UP: + return 90; + + case ShiftSignupState::FREE: + return 80; + + case ShiftSignupState::ANGELTYPE: + case ShiftSignupState::COLLIDES: + return 70; + + case ShiftSignupState::OCCUPIED: + case ShiftSignupState::ADMIN: + return 60; + } } + + /** + * Returns true, if signup is allowed + */ + public function isSignupAllowed() + { + switch ($this->state) { + case ShiftSignupState::FREE: + case ShiftSignupState::ADMIN: + return true; + } + return false; + } + + /** + * Return the shift signup state + */ + public function getState() + { + return $this->state; } - /** - * Returns true, if signup is allowed - */ - public function isSignupAllowed() - { - switch ($this->state) { - case ShiftSignupState::FREE: - case ShiftSignupState::ADMIN: - return true; + /** + * How many places are free in this shift for the angeltype? + */ + public function getFreeEntries() + { + return $this->freeEntries; } - return false; - } - - /** - * Return the shift signup state - */ - public function getState() - { - return $this->state; - } - - /** - * How many places are free in this shift for the angeltype? - */ - public function getFreeEntries() - { - return $this->freeEntries; - } } diff --git a/includes/model/ShiftTypes_model.php b/includes/model/ShiftTypes_model.php index fb361db9..8b1d56b8 100644 --- a/includes/model/ShiftTypes_model.php +++ b/includes/model/ShiftTypes_model.php @@ -2,6 +2,7 @@ /** * Delete a shift type. + * * @param int $shifttype_id */ function ShiftType_delete($shifttype_id) @@ -12,34 +13,38 @@ function ShiftType_delete($shifttype_id) /** * Update a shift type. * - * @param int $shifttype_id + * @param int $shifttype_id * @param string $name - * @param int $angeltype_id + * @param int $angeltype_id * @param string $description */ function ShiftType_update($shifttype_id, $name, $angeltype_id, $description) { - return sql_query("UPDATE `ShiftTypes` SET + return sql_query(" + UPDATE `ShiftTypes` SET `name`='" . sql_escape($name) . "', `angeltype_id`=" . sql_null($angeltype_id) . ", `description`='" . sql_escape($description) . "' - WHERE `id`='" . sql_escape($shifttype_id) . "'"); + WHERE `id`='" . sql_escape($shifttype_id) . "' + "); } /** * Create a shift type. * * @param string $name - * @param int $angeltype_id + * @param int $angeltype_id * @param string $description * @return new shifttype id */ function ShiftType_create($name, $angeltype_id, $description) { - $result = sql_query("INSERT INTO `ShiftTypes` SET + $result = sql_query(" + INSERT INTO `ShiftTypes` SET `name`='" . sql_escape($name) . "', `angeltype_id`=" . sql_null($angeltype_id) . ", - `description`='" . sql_escape($description) . "'"); + `description`='" . sql_escape($description) . "' + "); if ($result === false) { return false; } diff --git a/includes/model/ShiftsFilter.php b/includes/model/ShiftsFilter.php index cba6fee7..1e8d49cf 100644 --- a/includes/model/ShiftsFilter.php +++ b/includes/model/ShiftsFilter.php @@ -10,28 +10,28 @@ namespace Engelsystem; class ShiftsFilter { - /** - * How long can the time interval be? - */ - const MAX_DURATION = 86400; - // one day - - /** - * Shift is completely full. - */ - const FILLED_FILLED = 1; - - /** - * Shift has some free slots. - */ - const FILLED_FREE = 0; - - /** - * Has the user "user shifts admin" privilege? - * - * @var boolean - */ - private $userShiftsAdmin; + /** + * How long can the time interval be? + */ + const MAX_DURATION = 86400; + // one day + + /** + * Shift is completely full. + */ + const FILLED_FILLED = 1; + + /** + * Shift has some free slots. + */ + const FILLED_FREE = 0; + + /** + * Has the user "user shifts admin" privilege? + * + * @var boolean + */ + private $userShiftsAdmin; private $filled = []; @@ -48,11 +48,11 @@ class ShiftsFilter $this->user_shifts_admin = $user_shifts_admin; $this->rooms = $rooms; $this->types = $types; - + $this->filled = [ - ShiftsFilter::FILLED_FREE - ]; - + ShiftsFilter::FILLED_FREE + ]; + if ($user_shifts_admin) { $this->filled[] = ShiftsFilter::FILLED_FILLED; } @@ -84,9 +84,7 @@ class ShiftsFilter public function getTypes() { if (count($this->types) == 0) { - return [ - 0 - ]; + return [0]; } return $this->types; } @@ -99,9 +97,7 @@ class ShiftsFilter public function getRooms() { if (count($this->rooms) == 0) { - return [ - 0 - ]; + return [0]; } return $this->rooms; } diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php index 0d49f5da..c489c63e 100644 --- a/includes/model/Shifts_model.php +++ b/includes/model/Shifts_model.php @@ -14,7 +14,7 @@ function Shifts_by_room($room) function Shifts_by_ShiftsFilter(ShiftsFilter $shiftsFilter) { $SQL = "SELECT * FROM ( - SELECT DISTINCT `Shifts`.*, `ShiftTypes`.`name`, `Room`.`Name` as `room_name` + SELECT DISTINCT `Shifts`.*, `ShiftTypes`.`name`, `Room`.`Name` AS `room_name` FROM `Shifts` JOIN `Room` USING (`RID`) JOIN `ShiftTypes` ON `ShiftTypes`.`id` = `Shifts`.`shifttype_id` @@ -27,7 +27,7 @@ function Shifts_by_ShiftsFilter(ShiftsFilter $shiftsFilter) UNION - SELECT DISTINCT `Shifts`.*, `ShiftTypes`.`name`, `Room`.`Name` as `room_name` + SELECT DISTINCT `Shifts`.*, `ShiftTypes`.`name`, `Room`.`Name` AS `room_name` FROM `Shifts` JOIN `Room` USING (`RID`) JOIN `ShiftTypes` ON `ShiftTypes`.`id` = `Shifts`.`shifttype_id` @@ -36,7 +36,7 @@ function Shifts_by_ShiftsFilter(ShiftsFilter $shiftsFilter) AND `start` BETWEEN " . $shiftsFilter->getStartTime() . " AND " . $shiftsFilter->getEndTime() . " AND `NeededAngelTypes`.`angel_type_id` IN (" . implode(',', $shiftsFilter->getTypes()) . ") AND `NeededAngelTypes`.`count` > 0 - AND NOT `Shifts`.`PSID` IS NULL) as tmp_shifts + AND NOT `Shifts`.`PSID` IS NULL) AS tmp_shifts ORDER BY `start`"; $result = sql_select($SQL); @@ -48,7 +48,14 @@ function Shifts_by_ShiftsFilter(ShiftsFilter $shiftsFilter) function NeededAngeltypes_by_ShiftsFilter(ShiftsFilter $shiftsFilter) { - $SQL = "SELECT `NeededAngelTypes`.*, `Shifts`.`SID`, `AngelTypes`.`id`, `AngelTypes`.`name`, `AngelTypes`.`restricted`, `AngelTypes`.`no_self_signup` + $SQL = " + SELECT + `NeededAngelTypes`.*, + `Shifts`.`SID`, + `AngelTypes`.`id`, + `AngelTypes`.`name`, + `AngelTypes`.`restricted`, + `AngelTypes`.`no_self_signup` FROM `Shifts` JOIN `NeededAngelTypes` ON `NeededAngelTypes`.`shift_id`=`Shifts`.`SID` JOIN `AngelTypes` ON `AngelTypes`.`id`= `NeededAngelTypes`.`angel_type_id` @@ -58,7 +65,13 @@ function NeededAngeltypes_by_ShiftsFilter(ShiftsFilter $shiftsFilter) UNION - SELECT `NeededAngelTypes`.*, `Shifts`.`SID`, `AngelTypes`.`id`, `AngelTypes`.`name`, `AngelTypes`.`restricted`, `AngelTypes`.`no_self_signup` + SELECT + `NeededAngelTypes`.*, + `Shifts`.`SID`, + `AngelTypes`.`id`, + `AngelTypes`.`name`, + `AngelTypes`.`restricted`, + `AngelTypes`.`no_self_signup` FROM `Shifts` JOIN `NeededAngelTypes` ON `NeededAngelTypes`.`room_id`=`Shifts`.`RID` JOIN `AngelTypes` ON `AngelTypes`.`id`= `NeededAngelTypes`.`angel_type_id` @@ -74,7 +87,14 @@ function NeededAngeltypes_by_ShiftsFilter(ShiftsFilter $shiftsFilter) function NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype) { - $result = sql_select("SELECT `NeededAngelTypes`.*, `Shifts`.`SID`, `AngelTypes`.`id`, `AngelTypes`.`name`, `AngelTypes`.`restricted`, `AngelTypes`.`no_self_signup` + $result = sql_select(" + SELECT + `NeededAngelTypes`.*, + `Shifts`.`SID`, + `AngelTypes`.`id`, + `AngelTypes`.`name`, + `AngelTypes`.`restricted`, + `AngelTypes`.`no_self_signup` FROM `Shifts` JOIN `NeededAngelTypes` ON `NeededAngelTypes`.`shift_id`=`Shifts`.`SID` JOIN `AngelTypes` ON `AngelTypes`.`id`= `NeededAngelTypes`.`angel_type_id` @@ -84,7 +104,13 @@ function NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype) UNION - SELECT `NeededAngelTypes`.*, `Shifts`.`SID`, `AngelTypes`.`id`, `AngelTypes`.`name`, `AngelTypes`.`restricted`, `AngelTypes`.`no_self_signup` + SELECT + `NeededAngelTypes`.*, + `Shifts`.`SID`, + `AngelTypes`.`id`, + `AngelTypes`.`name`, + `AngelTypes`.`restricted`, + `AngelTypes`.`no_self_signup` FROM `Shifts` JOIN `NeededAngelTypes` ON `NeededAngelTypes`.`room_id`=`Shifts`.`RID` JOIN `AngelTypes` ON `AngelTypes`.`id`= `NeededAngelTypes`.`angel_type_id` @@ -102,7 +128,18 @@ function NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype) function ShiftEntries_by_ShiftsFilter(ShiftsFilter $shiftsFilter) { - $SQL = "SELECT `User`.`Nick`, `User`.`email`, `User`.`email_shiftinfo`, `User`.`Sprache`, `User`.`Gekommen`, `ShiftEntry`.`UID`, `ShiftEntry`.`TID`, `ShiftEntry`.`SID`, `ShiftEntry`.`Comment`, `ShiftEntry`.`freeloaded` + $SQL = " + SELECT + `User`.`Nick`, + `User`.`email`, + `User`.`email_shiftinfo`, + `User`.`Sprache`, + `User`.`Gekommen`, + `ShiftEntry`.`UID`, + `ShiftEntry`.`TID`, + `ShiftEntry`.`SID`, + `ShiftEntry`.`Comment`, + `ShiftEntry`.`freeloaded` FROM `Shifts` JOIN `ShiftEntry` ON `ShiftEntry`.`SID`=`Shifts`.`SID` JOIN `User` ON `ShiftEntry`.`UID`=`User`.`UID` @@ -120,13 +157,13 @@ function ShiftEntries_by_ShiftsFilter(ShiftsFilter $shiftsFilter) * Check if a shift collides with other shifts (in time). * * @param Shift $shift - * @param array $shifts + * @param array $shifts */ function Shift_collides($shift, $shifts) { foreach ($shifts as $other_shift) { if ($shift['SID'] != $other_shift['SID']) { - if (! ($shift['start'] >= $other_shift['end'] || $shift['end'] <= $other_shift['start'])) { + if (!($shift['start'] >= $other_shift['end'] || $shift['end'] <= $other_shift['start'])) { return true; } } @@ -142,7 +179,7 @@ function Shift_free_entries($needed_angeltype, $shift_entries) $taken = 0; foreach ($shift_entries as $shift_entry) { if ($shift_entry['freeloaded'] == 0) { - $taken ++; + $taken++; } } return max(0, $needed_angeltype['count'] - $taken); @@ -151,27 +188,35 @@ function Shift_free_entries($needed_angeltype, $shift_entries) /** * Check if shift signup is allowed from the end users point of view (no admin like privileges) * - * @param Shift $shift - * The shift + * @param Shift $shift + * The shift * @param AngelType $angeltype - * The angeltype to which the user wants to sign up - * @param array $user_shifts - * List of the users shifts - * @param boolean $angeltype_supporter - * True, if the user has angeltype supporter rights for the angeltype, which enables him to sign somebody up for the shift. + * The angeltype to which the user wants to sign up + * @param array $user_shifts + * List of the users shifts + * @param boolean $angeltype_supporter + * True, if the user has angeltype supporter rights for the angeltype, which enables him to sign + * somebody up for the shift. */ -function Shift_signup_allowed_angel($user, $shift, $angeltype, $user_angeltype, $user_shifts, $needed_angeltype, $shift_entries) -{ +function Shift_signup_allowed_angel( + $user, + $shift, + $angeltype, + $user_angeltype, + $user_shifts, + $needed_angeltype, + $shift_entries +) { $free_entries = Shift_free_entries($needed_angeltype, $shift_entries); - + if ($user['Gekommen'] == 0) { return new ShiftSignupState(ShiftSignupState::SHIFT_ENDED, $free_entries); } - + if ($user_shifts == null) { $user_shifts = Shifts_by_user($user); } - + $signed_up = false; foreach ($user_shifts as $user_shift) { if ($user_shift['SID'] == $shift['SID']) { @@ -179,40 +224,44 @@ function Shift_signup_allowed_angel($user, $shift, $angeltype, $user_angeltype, break; } } - + if ($signed_up) { // you cannot join if you already singed up for this shift - return new ShiftSignupState(ShiftSignupState::SIGNED_UP, $free_entries); + return new ShiftSignupState(ShiftSignupState::SIGNED_UP, $free_entries); } - + if (time() > $shift['start']) { // you can only join if the shift is in future - return new ShiftSignupState(ShiftSignupState::SHIFT_ENDED, $free_entries); + return new ShiftSignupState(ShiftSignupState::SHIFT_ENDED, $free_entries); } if ($free_entries == 0) { // you cannot join if shift is full - return new ShiftSignupState(ShiftSignupState::OCCUPIED, $free_entries); + return new ShiftSignupState(ShiftSignupState::OCCUPIED, $free_entries); } - + if ($user_angeltype == null) { $user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype); } - - if ($user_angeltype == null || ($angeltype['no_self_signup'] == 1 && $user_angeltype != null) || ($angeltype['restricted'] == 1 && $user_angeltype != null && ! isset($user_angeltype['confirm_user_id']))) { + + if ( + $user_angeltype == null + || ($angeltype['no_self_signup'] == 1 && $user_angeltype != null) + || ($angeltype['restricted'] == 1 && $user_angeltype != null && !isset($user_angeltype['confirm_user_id'])) + ) { // you cannot join if user is not of this angel type - // you cannot join if you are not confirmed - // you cannot join if angeltype has no self signup - - return new ShiftSignupState(ShiftSignupState::ANGELTYPE, $free_entries); + // you cannot join if you are not confirmed + // you cannot join if angeltype has no self signup + + return new ShiftSignupState(ShiftSignupState::ANGELTYPE, $free_entries); } - + if (Shift_collides($shift, $user_shifts)) { // you cannot join if user alread joined a parallel or this shift - return new ShiftSignupState(ShiftSignupState::COLLIDES, $free_entries); + return new ShiftSignupState(ShiftSignupState::COLLIDES, $free_entries); } - - // Hooray, shift is free for you! - return new ShiftSignupState(ShiftSignupState::FREE, $free_entries); + + // Hooray, shift is free for you! + return new ShiftSignupState(ShiftSignupState::FREE, $free_entries); } /** @@ -224,14 +273,14 @@ function Shift_signup_allowed_angeltype_supporter($angeltype, $needed_angeltype, if ($free_entries == 0) { return new ShiftSignupState(ShiftSignupState::OCCUPIED, $free_entries); } - + return new ShiftSignupState(ShiftSignupState::FREE, $free_entries); } /** * Check if an admin can sign up a user to a shift. * - * @param Shift $shift + * @param Shift $shift * The shift * @param AngelType $angeltype * The angeltype to which the user wants to sign up @@ -239,38 +288,56 @@ function Shift_signup_allowed_angeltype_supporter($angeltype, $needed_angeltype, function Shift_signup_allowed_admin($angeltype, $needed_angeltype, $shift_entries) { $free_entries = Shift_free_entries($needed_angeltype, $shift_entries); - + if ($free_entries == 0) { // User shift admins may join anybody in every shift - return new ShiftSignupState(ShiftSignupState::ADMIN, $free_entries); + return new ShiftSignupState(ShiftSignupState::ADMIN, $free_entries); } - + return new ShiftSignupState(ShiftSignupState::FREE, $free_entries); } /** * Check if an angel can sign up for given shift. * - * @param Shift $shift - * The shift + * @param Shift $shift + * The shift * @param AngelType $angeltype - * The angeltype to which the user wants to sign up - * @param array $user_shifts - * List of the users shifts + * The angeltype to which the user wants to sign up + * @param array $user_shifts + * List of the users shifts */ -function Shift_signup_allowed($signup_user, $shift, $angeltype, $user_angeltype = null, $user_shifts = null, $needed_angeltype, $shift_entries) -{ +function Shift_signup_allowed( + $signup_user, + $shift, + $angeltype, + $user_angeltype = null, + $user_shifts = null, + $needed_angeltype, + $shift_entries +) { global $user, $privileges; - + if (in_array('user_shifts_admin', $privileges)) { return Shift_signup_allowed_admin($angeltype, $needed_angeltype, $shift_entries); } - - if (in_array('shiftentry_edit_angeltype_supporter', $privileges) && User_is_AngelType_supporter($user, $angeltype)) { + + if ( + in_array('shiftentry_edit_angeltype_supporter', $privileges) + && User_is_AngelType_supporter($user, $angeltype) + ) { return Shift_signup_allowed_angeltype_supporter($angeltype, $needed_angeltype, $shift_entries); } - - return Shift_signup_allowed_angel($signup_user, $shift, $angeltype, $user_angeltype, $user_shifts, $needed_angeltype, $shift_entries); + + return Shift_signup_allowed_angel( + $signup_user, + $shift, + $angeltype, + $user_angeltype, + $user_shifts, + $needed_angeltype, + $shift_entries + ); } /** @@ -287,7 +354,7 @@ function Shift_delete_by_psid($shift_psid) function Shift_delete($shift_id) { mail_shift_delete(Shift($shift_id)); - + $result = sql_query("DELETE FROM `Shifts` WHERE `SID`='" . sql_escape($shift_id) . "'"); if ($result === false) { engelsystem_error('Unable to delete shift.'); @@ -303,8 +370,9 @@ function Shift_update($shift) global $user; $shift['name'] = ShiftType($shift['shifttype_id'])['name']; mail_shift_change(Shift($shift['SID']), $shift); - - return sql_query("UPDATE `Shifts` SET + + return sql_query(" + UPDATE `Shifts` SET `shifttype_id`='" . sql_escape($shift['shifttype_id']) . "', `start`='" . sql_escape($shift['start']) . "', `end`='" . sql_escape($shift['end']) . "', @@ -314,7 +382,8 @@ function Shift_update($shift) `PSID`=" . sql_null($shift['PSID']) . ", `edited_by_user_id`='" . sql_escape($user['UID']) . "', `edited_at_timestamp`=" . time() . " - WHERE `SID`='" . sql_escape($shift['SID']) . "'"); + WHERE `SID`='" . sql_escape($shift['SID']) . "' + "); } /** @@ -341,7 +410,8 @@ function Shift_update_by_psid($shift) function Shift_create($shift) { global $user; - $result = sql_query("INSERT INTO `Shifts` SET + $result = sql_query(" + INSERT INTO `Shifts` SET `shifttype_id`='" . sql_escape($shift['shifttype_id']) . "', `start`='" . sql_escape($shift['start']) . "', `end`='" . sql_escape($shift['end']) . "', @@ -350,7 +420,8 @@ function Shift_create($shift) `URL`=" . sql_null($shift['URL']) . ", `PSID`=" . sql_null($shift['PSID']) . ", `created_by_user_id`='" . sql_escape($user['UID']) . "', - `created_at_timestamp`=" . time()); + `created_at_timestamp`=" . time() + ); if ($result === false) { return false; } @@ -384,7 +455,7 @@ function Shifts_by_user($user, $include_freeload_comments = false) * Returns Shift by id. * * @param $shift_id Shift - * ID + * ID */ function Shift($shift_id) { @@ -394,30 +465,30 @@ function Shift($shift_id) JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`) WHERE `SID`='" . sql_escape($shift_id) . "'"); $shiftsEntry_source = sql_select("SELECT `id`, `TID` , `UID` , `freeloaded` FROM `ShiftEntry` WHERE `SID`='" . sql_escape($shift_id) . "'"); - + if ($shifts_source === false) { engelsystem_error('Unable to load shift.'); } - + if (empty($shifts_source)) { return null; } - + $result = $shifts_source[0]; - + $result['ShiftEntry'] = $shiftsEntry_source; $result['NeedAngels'] = []; - + $temp = NeededAngelTypes_by_shift($shift_id); foreach ($temp as $e) { $result['NeedAngels'][] = [ - 'TID' => $e['angel_type_id'], - 'count' => $e['count'], - 'restricted' => $e['restricted'], - 'taken' => $e['taken'] - ]; + 'TID' => $e['angel_type_id'], + 'count' => $e['count'], + 'restricted' => $e['restricted'], + 'taken' => $e['taken'] + ]; } - + return $result; } @@ -427,7 +498,7 @@ function Shift($shift_id) function Shifts() { $shifts_source = sql_select(" - SELECT `ShiftTypes`.`name`, `Shifts`.*, `Room`.`RID`, `Room`.`Name` as `room_name` + SELECT `ShiftTypes`.`name`, `Shifts`.*, `Room`.`RID`, `Room`.`Name` AS `room_name` FROM `Shifts` JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`) JOIN `Room` ON `Room`.`RID` = `Shifts`.`RID` @@ -435,15 +506,15 @@ function Shifts() if ($shifts_source === false) { return false; } - + foreach ($shifts_source as &$shift) { $needed_angeltypes = NeededAngelTypes_by_shift($shift['SID']); if ($needed_angeltypes === false) { return false; } - + $shift['angeltypes'] = $needed_angeltypes; } - + return $shifts_source; } diff --git a/includes/model/UserAngelTypes_model.php b/includes/model/UserAngelTypes_model.php index ea7a454c..fae2b996 100644 --- a/includes/model/UserAngelTypes_model.php +++ b/includes/model/UserAngelTypes_model.php @@ -7,7 +7,7 @@ /** * Checks if a user joined an angeltype. * - * @param User $user + * @param User $user * The user to be checked * @param Angeltype $angeltype * The angeltype to be checked @@ -51,19 +51,20 @@ function User_angeltypes($user) function User_unconfirmed_AngelTypes($user) { $result = sql_select(" - SELECT - `UserAngelTypes`.*, - `AngelTypes`.`name`, - count(`UnconfirmedMembers`.`user_id`) as `count` - FROM `UserAngelTypes` - JOIN `AngelTypes` ON `UserAngelTypes`.`angeltype_id`=`AngelTypes`.`id` - JOIN `UserAngelTypes` as `UnconfirmedMembers` ON `UserAngelTypes`.`angeltype_id`=`UnconfirmedMembers`.`angeltype_id` - WHERE `UserAngelTypes`.`user_id`='" . sql_escape($user['UID']) . "' - AND `UserAngelTypes`.`supporter`=TRUE - AND `AngelTypes`.`restricted`=TRUE - AND `UnconfirmedMembers`.`confirm_user_id` IS NULL - GROUP BY `UserAngelTypes`.`angeltype_id` - ORDER BY `AngelTypes`.`name`"); + SELECT + `UserAngelTypes`.*, + `AngelTypes`.`name`, + count(`UnconfirmedMembers`.`user_id`) AS `count` + FROM `UserAngelTypes` + JOIN `AngelTypes` ON `UserAngelTypes`.`angeltype_id`=`AngelTypes`.`id` + JOIN `UserAngelTypes` AS `UnconfirmedMembers` ON `UserAngelTypes`.`angeltype_id`=`UnconfirmedMembers`.`angeltype_id` + WHERE `UserAngelTypes`.`user_id`='" . sql_escape($user['UID']) . "' + AND `UserAngelTypes`.`supporter`=TRUE + AND `AngelTypes`.`restricted`=TRUE + AND `UnconfirmedMembers`.`confirm_user_id` IS NULL + GROUP BY `UserAngelTypes`.`angeltype_id` + ORDER BY `AngelTypes`.`name` + "); if ($result === false) { engelsystem_error("Unable to load user angeltypes."); } @@ -73,7 +74,7 @@ function User_unconfirmed_AngelTypes($user) /** * Returns true if user is angeltype supporter or has privilege admin_user_angeltypes. * - * @param User $user + * @param User $user * @param AngelType $angeltype */ function User_is_AngelType_supporter(&$user, $angeltype) @@ -87,13 +88,14 @@ function User_is_AngelType_supporter(&$user, $angeltype) WHERE `user_id`='" . sql_escape($user['UID']) . "' AND `angeltype_id`='" . sql_escape($angeltype['id']) . "' AND `supporter`=TRUE - LIMIT 1") > 0) || in_array('admin_user_angeltypes', $user['privileges']); + LIMIT 1 + ") > 0) || in_array('admin_user_angeltypes', $user['privileges']); } /** * Add or remove supporter rights. * - * @param int $user_angeltype_id + * @param int $user_angeltype_id * @param bool $supporter */ function UserAngelType_update($user_angeltype_id, $supporter) @@ -102,7 +104,8 @@ function UserAngelType_update($user_angeltype_id, $supporter) UPDATE `UserAngelTypes` SET `supporter`=" . sql_bool($supporter) . " WHERE `id`='" . sql_escape($user_angeltype_id) . "' - LIMIT 1"); + LIMIT 1 + "); if ($result === false) { engelsystem_error("Unable to update supporter rights."); } @@ -119,7 +122,8 @@ function UserAngelTypes_delete_all($angeltype_id) $result = sql_query(" DELETE FROM `UserAngelTypes` WHERE `angeltype_id`='" . sql_escape($angeltype_id) . "' - AND `confirm_user_id` IS NULL"); + AND `confirm_user_id` IS NULL + "); if ($result === false) { engelsystem_error("Unable to delete all unconfirmed users."); } @@ -129,7 +133,7 @@ function UserAngelTypes_delete_all($angeltype_id) /** * Confirm all unconfirmed UserAngelTypes for given Angeltype. * - * @param int $angeltype_id + * @param int $angeltype_id * @param User $confirm_user */ function UserAngelTypes_confirm_all($angeltype_id, $confirm_user) @@ -138,7 +142,8 @@ function UserAngelTypes_confirm_all($angeltype_id, $confirm_user) UPDATE `UserAngelTypes` SET `confirm_user_id`='" . sql_escape($confirm_user['UID']) . "' WHERE `angeltype_id`='" . sql_escape($angeltype_id) . "' - AND `confirm_user_id` IS NULL"); + AND `confirm_user_id` IS NULL + "); if ($result === false) { engelsystem_error("Unable to confirm all users."); } @@ -148,7 +153,7 @@ function UserAngelTypes_confirm_all($angeltype_id, $confirm_user) /** * Confirm an UserAngelType with confirming user. * - * @param int $user_angeltype_id + * @param int $user_angeltype_id * @param User $confirm_user */ function UserAngelType_confirm($user_angeltype_id, $confirm_user) @@ -180,7 +185,7 @@ function UserAngelType_delete($user_angeltype) /** * Create an UserAngelType. * - * @param User $user + * @param User $user * @param Angeltype $angeltype */ function UserAngelType_create($user, $angeltype) @@ -219,7 +224,7 @@ function UserAngelType($user_angeltype_id) /** * Get an UserAngelType by user and angeltype. * - * @param User $user + * @param User $user * @param Angeltype $angeltype */ function UserAngelType_by_User_and_AngelType($user, $angeltype) diff --git a/includes/model/UserDriverLicenses_model.php b/includes/model/UserDriverLicenses_model.php index 7d1be528..a36b79c1 100644 --- a/includes/model/UserDriverLicenses_model.php +++ b/includes/model/UserDriverLicenses_model.php @@ -7,14 +7,14 @@ function UserDriverLicense_new() { return [ - 'user_id' => null, - 'has_car' => false, - 'has_license_car' => false, - 'has_license_3_5t_transporter' => false, - 'has_license_7_5t_truck' => false, - 'has_license_12_5t_truck' => false, - 'has_license_forklift' => false - ]; + 'user_id' => null, + 'has_car' => false, + 'has_license_car' => false, + 'has_license_3_5t_transporter' => false, + 'has_license_7_5t_truck' => false, + 'has_license_12_5t_truck' => false, + 'has_license_forklift' => false + ]; } /** @@ -26,7 +26,12 @@ function UserDriverLicense_new() */ function UserDriverLicense_valid($user_driver_license) { - return $user_driver_license['has_car'] || $user_driver_license['has_license_car'] || $user_driver_license['has_license_3_5t_transporter'] || $user_driver_license['has_license_7_5t_truck'] || $user_driver_license['has_license_12_5t_truck'] || $user_driver_license['has_license_forklift']; + return $user_driver_license['has_car'] + || $user_driver_license['has_license_car'] + || $user_driver_license['has_license_3_5t_transporter'] + || $user_driver_license['has_license_7_5t_truck'] + || $user_driver_license['has_license_12_5t_truck'] + || $user_driver_license['has_license_forklift']; } /** diff --git a/includes/model/UserGroups_model.php b/includes/model/UserGroups_model.php index 61fd074a..bbef85b6 100644 --- a/includes/model/UserGroups_model.php +++ b/includes/model/UserGroups_model.php @@ -2,6 +2,7 @@ /** * Returns users groups + * * @param User $user */ function User_groups($user) diff --git a/includes/model/User_model.php b/includes/model/User_model.php index 9324bf53..1a09c160 100644 --- a/includes/model/User_model.php +++ b/includes/model/User_model.php @@ -22,7 +22,8 @@ function User_delete($user_id) */ function User_update($user) { - return sql_query("UPDATE `User` SET + return sql_query(" + UPDATE `User` SET `Nick`='" . sql_escape($user['Nick']) . "', `Name`='" . sql_escape($user['Name']) . "', `Vorname`='" . sql_escape($user['Vorname']) . "', @@ -46,7 +47,8 @@ function User_update($user) `arrival_date`='" . sql_escape($user['arrival_date']) . "', `planned_arrival_date`='" . sql_escape($user['planned_arrival_date']) . "', `planned_departure_date`=" . sql_null($user['planned_departure_date']) . " - WHERE `UID`='" . sql_escape($user['UID']) . "'"); + WHERE `UID`='" . sql_escape($user['UID']) . "' + "); } /** @@ -83,19 +85,19 @@ function User_tshirts_count() function User_sortable_columns() { return [ - 'Nick', - 'Name', - 'Vorname', - 'Alter', - 'DECT', - 'email', - 'Size', - 'Gekommen', - 'Aktiv', - 'force_active', - 'Tshirt', - 'lastLogIn' - ]; + 'Nick', + 'Name', + 'Vorname', + 'Alter', + 'DECT', + 'email', + 'Size', + 'Gekommen', + 'Aktiv', + 'force_active', + 'Tshirt', + 'lastLogIn' + ]; } /** @@ -116,7 +118,7 @@ function Users($order_by = 'Nick') function User_is_freeloader($user) { global $max_freeloadable_shifts, $user; - + return count(ShiftEntries_freeloaded_by_user($user)) >= $max_freeloadable_shifts; } @@ -130,7 +132,8 @@ function Users_by_angeltype_inverted($angeltype) $result = sql_select(" SELECT `User`.* FROM `User` - LEFT JOIN `UserAngelTypes` ON (`User`.`UID`=`UserAngelTypes`.`user_id` AND `angeltype_id`='" . sql_escape($angeltype['id']) . "') + LEFT JOIN `UserAngelTypes` + ON (`User`.`UID`=`UserAngelTypes`.`user_id` AND `angeltype_id`='" . sql_escape($angeltype['id']) . "') WHERE `UserAngelTypes`.`id` IS NULL ORDER BY `Nick`"); if ($result === false) { @@ -149,7 +152,7 @@ function Users_by_angeltype($angeltype) $result = sql_select(" SELECT `User`.*, - `UserAngelTypes`.`id` as `user_angeltype_id`, + `UserAngelTypes`.`id` AS `user_angeltype_id`, `UserAngelTypes`.`confirm_user_id`, `UserAngelTypes`.`supporter`, `UserDriverLicenses`.* @@ -207,7 +210,7 @@ function User_validate_jabber($jabber) $jabber = strip_item($jabber); if ($jabber == '') { // Empty is ok - return new ValidationResult(true, ''); + return new ValidationResult(true, ''); } return new ValidationResult(check_email($jabber), $jabber); } @@ -223,20 +226,20 @@ function User_validate_planned_arrival_date($planned_arrival_date) { if ($planned_arrival_date == null) { // null is not okay - return new ValidationResult(false, time()); + return new ValidationResult(false, time()); } $event_config = EventConfig(); if ($event_config == null) { // Nothing to validate against - return new ValidationResult(true, $planned_arrival_date); + return new ValidationResult(true, $planned_arrival_date); } if (isset($event_config['buildup_start_date']) && $planned_arrival_date < $event_config['buildup_start_date']) { // Planned arrival can not be before buildup start date - return new ValidationResult(false, $event_config['buildup_start_date']); + return new ValidationResult(false, $event_config['buildup_start_date']); } if (isset($event_config['teardown_end_date']) && $planned_arrival_date > $event_config['teardown_end_date']) { // Planned arrival can not be after teardown end date - return new ValidationResult(false, $event_config['teardown_end_date']); + return new ValidationResult(false, $event_config['teardown_end_date']); } return new ValidationResult(true, $planned_arrival_date); } @@ -254,24 +257,24 @@ function User_validate_planned_departure_date($planned_arrival_date, $planned_de { if ($planned_departure_date == null) { // null is okay - return new ValidationResult(true, null); + return new ValidationResult(true, null); } if ($planned_arrival_date > $planned_departure_date) { // departure cannot be before arrival - return new ValidationResult(false, $planned_arrival_date); + return new ValidationResult(false, $planned_arrival_date); } $event_config = EventConfig(); if ($event_config == null) { // Nothing to validate against - return new ValidationResult(true, $planned_departure_date); + return new ValidationResult(true, $planned_departure_date); } if (isset($event_config['buildup_start_date']) && $planned_departure_date < $event_config['buildup_start_date']) { // Planned arrival can not be before buildup start date - return new ValidationResult(false, $event_config['buildup_start_date']); + return new ValidationResult(false, $event_config['buildup_start_date']); } if (isset($event_config['teardown_end_date']) && $planned_departure_date > $event_config['teardown_end_date']) { // Planned arrival can not be after teardown end date - return new ValidationResult(false, $event_config['teardown_end_date']); + return new ValidationResult(false, $event_config['teardown_end_date']); } return new ValidationResult(true, $planned_departure_date); } @@ -384,14 +387,14 @@ function User_generate_password_recovery_token(&$user) function User_get_eligable_voucher_count(&$user) { global $voucher_settings; - + $shifts_done = count(ShiftEntries_finished_by_user($user)); - + $earned_vouchers = $user['got_voucher'] - $voucher_settings['initial_vouchers']; $elegible_vouchers = $shifts_done / $voucher_settings['shifts_per_voucher'] - $earned_vouchers; if ($elegible_vouchers < 0) { return 0; } - + return $elegible_vouchers; } diff --git a/includes/model/ValidationResult.php b/includes/model/ValidationResult.php index 7dfcb5ba..b08e9d31 100644 --- a/includes/model/ValidationResult.php +++ b/includes/model/ValidationResult.php @@ -12,33 +12,33 @@ class ValidationResult private $value; - /** - * Constructor. - * - * @param boolean $valid - * Is the value valid? - * @param * $value - * The validated value - */ - public function __construct($valid, $value) - { - $this->valid = $valid; - $this->value = $value; - } + /** + * Constructor. + * + * @param boolean $valid + * Is the value valid? + * @param * $value + * The validated value + */ + public function __construct($valid, $value) + { + $this->valid = $valid; + $this->value = $value; + } - /** - * Is the value valid? - */ - public function isValid() - { - return $this->valid; - } + /** + * Is the value valid? + */ + public function isValid() + { + return $this->valid; + } - /** - * The parsed/validated value. - */ - public function getValue() - { - return $this->value; - } + /** + * The parsed/validated value. + */ + public function getValue() + { + return $this->value; + } } diff --git a/includes/mysqli_provider.php b/includes/mysqli_provider.php index b432bb4f..7280cd6d 100644 --- a/includes/mysqli_provider.php +++ b/includes/mysqli_provider.php @@ -6,7 +6,7 @@ function sql_close() { global $sql_connection; - + return $sql_connection->close(); } @@ -24,11 +24,11 @@ function sql_null($value = null) function sql_transaction_start() { global $sql_nested_transaction_level; - - if ($sql_nested_transaction_level ++ == 0) { + + if ($sql_nested_transaction_level++ == 0) { return sql_query("BEGIN"); } - + return true; } @@ -38,11 +38,11 @@ function sql_transaction_start() function sql_transaction_commit() { global $sql_nested_transaction_level; - - if (-- $sql_nested_transaction_level == 0) { + + if (--$sql_nested_transaction_level == 0) { return sql_query("COMMIT"); } - + return true; } @@ -52,11 +52,11 @@ function sql_transaction_commit() function sql_transaction_rollback() { global $sql_nested_transaction_level; - - if (-- $sql_nested_transaction_level == 0) { + + if (--$sql_nested_transaction_level == 0) { return sql_query("ROLLBACK"); } - + return true; } @@ -69,12 +69,12 @@ function sql_transaction_rollback() function sql_error($message) { sql_close(); - + $message = trim($message) . "\n"; $message .= debug_string_backtrace() . "\n"; - + error_log('mysql_provider error: ' . $message); - + return false; } @@ -94,23 +94,23 @@ function sql_error($message) function sql_connect($host, $user, $pass, $db_name) { global $sql_connection; - + $sql_connection = new mysqli($host, $user, $pass, $db_name); if ($sql_connection->connect_errno) { error("Unable to connect to MySQL: " . $sql_connection->connect_error); return sql_error("Unable to connect to MySQL: " . $sql_connection->connect_error); } - + $result = $sql_connection->query("SET CHARACTER SET utf8;"); - if (! $result) { + if (!$result) { return sql_error("Unable to set utf8 character set (" . $sql_connection->errno . ") " . $sql_connection->error); } - + $result = $sql_connection->set_charset('utf8'); - if (! $result) { + if (!$result) { return sql_error("Unable to set utf8 names (" . $sql_connection->errno . ") " . $sql_connection->error); } - + return $sql_connection; } @@ -124,7 +124,7 @@ function sql_connect($host, $user, $pass, $db_name) function sql_select_db($db_name) { global $sql_connection; - if (! $sql_connection->select_db($db_name)) { + if (!$sql_connection->select_db($db_name)) { return sql_error("No database selected."); } return true; @@ -139,11 +139,11 @@ function sql_select_db($db_name) function sql_select($query) { global $sql_connection; - + // echo $query . ";\n"; // echo debug_string_backtrace() . "\n"; - - $result = $sql_connection->query($query); + + $result = $sql_connection->query($query); if ($result) { $data = []; while ($line = $result->fetch_assoc()) { @@ -151,7 +151,7 @@ function sql_select($query) } return $data; } - + return sql_error("MySQL-query error: " . $query . " (" . $sql_connection->errno . ") " . $sql_connection->error); } @@ -164,12 +164,12 @@ function sql_select($query) function sql_query($query) { global $sql_connection; - + $result = $sql_connection->query($query); if ($result) { return $result; } - + return sql_error("MySQL-query error: " . $query . " (" . $sql_connection->errno . ") " . $sql_connection->error); } diff --git a/includes/pages/admin_active.php b/includes/pages/admin_active.php index 46e88e23..38edbfdb 100644 --- a/includes/pages/admin_active.php +++ b/includes/pages/admin_active.php @@ -8,34 +8,37 @@ function admin_active_title() function admin_active() { global $tshirt_sizes, $shift_sum_formula; - + $msg = ""; $search = ""; $forced_count = sql_num_query("SELECT * FROM `User` WHERE `force_active`=1"); $count = $forced_count; $limit = ""; $set_active = ""; - + if (isset($_REQUEST['search'])) { $search = strip_request_item('search'); } - + $show_all_shifts = isset($_REQUEST['show_all_shifts']); - + if (isset($_REQUEST['set_active'])) { $valid = true; - + if (isset($_REQUEST['count']) && preg_match("/^[0-9]+$/", $_REQUEST['count'])) { $count = strip_request_item('count'); if ($count < $forced_count) { - error(sprintf(_("At least %s angels are forced to be active. The number has to be greater."), $forced_count)); + error(sprintf( + _("At least %s angels are forced to be active. The number has to be greater."), + $forced_count + )); redirect(page_link_to('admin_active')); } } else { $valid = false; $msg .= error(_("Please enter a number of angels to be marked as active."), true); } - + if ($valid) { $limit = " LIMIT " . $count; } @@ -56,14 +59,14 @@ function admin_active() } sql_query("UPDATE `User` SET `Aktiv`=1 WHERE `force_active`=TRUE"); engelsystem_log("These angels are active now: " . join(", ", $user_nicks)); - + $limit = ""; $msg = success(_("Marked angels."), true); } else { $set_active = '« ' . _("back") . ' | ' . _("apply") . ''; } } - + if (isset($_REQUEST['active']) && preg_match("/^[0-9]+$/", $_REQUEST['active'])) { $user_id = $_REQUEST['active']; $user_source = User($user_id); @@ -105,14 +108,15 @@ function admin_active() $msg = error(_("Angel not found."), true); } } - + $users = sql_select(" SELECT `User`.*, COUNT(`ShiftEntry`.`id`) as `shift_count`, ${shift_sum_formula} as `shift_length` FROM `User` LEFT JOIN `ShiftEntry` ON `User`.`UID` = `ShiftEntry`.`UID` LEFT JOIN `Shifts` ON `ShiftEntry`.`SID` = `Shifts`.`SID` " . ($show_all_shifts ? "" : "AND (`Shifts`.`end` < " . time() . " OR `Shifts`.`end` IS NULL)") . " WHERE `User`.`Gekommen` = 1 GROUP BY `User`.`UID` - ORDER BY `force_active` DESC, `shift_length` DESC" . $limit); + ORDER BY `force_active` DESC, `shift_length` DESC" . $limit + ); $matched_users = []; if ($search == "") { $tokens = []; @@ -128,7 +132,7 @@ function admin_active() break; } } - if (! $match) { + if (!$match) { continue; } } @@ -138,7 +142,7 @@ function admin_active() $usr['active'] = glyph_bool($usr['Aktiv'] == 1); $usr['force_active'] = glyph_bool($usr['force_active'] == 1); $usr['tshirt'] = glyph_bool($usr['Tshirt'] == 1); - + $actions = []; if ($usr['Aktiv'] == 0) { $actions[] = '' . _("set active") . ''; @@ -150,54 +154,54 @@ function admin_active() if ($usr['Tshirt'] == 1) { $actions[] = '' . _("remove t-shirt") . ''; } - + $usr['actions'] = join(' ', $actions); - + $matched_users[] = $usr; } - + $shirt_statistics = []; foreach (array_keys($tshirt_sizes) as $size) { if ($size != '') { $shirt_statistics[] = [ - 'size' => $size, - 'needed' => sql_select_single_cell("SELECT count(*) FROM `User` WHERE `Size`='" . sql_escape($size) . "' AND `Gekommen`=1"), - 'given' => sql_select_single_cell("SELECT count(*) FROM `User` WHERE `Size`='" . sql_escape($size) . "' AND `Tshirt`=1") - ]; + 'size' => $size, + 'needed' => sql_select_single_cell("SELECT count(*) FROM `User` WHERE `Size`='" . sql_escape($size) . "' AND `Gekommen`=1"), + 'given' => sql_select_single_cell("SELECT count(*) FROM `User` WHERE `Size`='" . sql_escape($size) . "' AND `Tshirt`=1") + ]; } } $shirt_statistics[] = [ - 'size' => '' . _("Sum") . '', - 'needed' => '' . User_arrived_count() . '', - 'given' => '' . sql_select_single_cell("SELECT count(*) FROM `User` WHERE `Tshirt`=1") . '' - ]; - + 'size' => '' . _("Sum") . '', + 'needed' => '' . User_arrived_count() . '', + 'given' => '' . sql_select_single_cell("SELECT count(*) FROM `User` WHERE `Tshirt`=1") . '' + ]; + return page_with_title(admin_active_title(), [ - form([ - form_text('search', _("Search angel:"), $search), - form_checkbox('show_all_shifts', _("Show all shifts"), $show_all_shifts), - form_submit('submit', _("Search")) - ], page_link_to('admin_active')), - $set_active == "" ? form([ - form_text('count', _("How much angels should be active?"), $count), - form_submit('set_active', _("Preview")) - ]) : $set_active, - msg(), - table([ - 'nick' => _("Nickname"), - 'shirt_size' => _("Size"), - 'shift_count' => _("Shifts"), - 'work_time' => _("Length"), - 'active' => _("Active?"), - 'force_active' => _("Forced"), - 'tshirt' => _("T-shirt?"), - 'actions' => "" - ], $matched_users), - '

' . _("Shirt statistics") . '

', - table([ - 'size' => _("Size"), - 'needed' => _("Needed shirts"), - 'given' => _("Given shirts") - ], $shirt_statistics) - ]); + form([ + form_text('search', _("Search angel:"), $search), + form_checkbox('show_all_shifts', _("Show all shifts"), $show_all_shifts), + form_submit('submit', _("Search")) + ], page_link_to('admin_active')), + $set_active == "" ? form([ + form_text('count', _("How much angels should be active?"), $count), + form_submit('set_active', _("Preview")) + ]) : $set_active, + msg(), + table([ + 'nick' => _("Nickname"), + 'shirt_size' => _("Size"), + 'shift_count' => _("Shifts"), + 'work_time' => _("Length"), + 'active' => _("Active?"), + 'force_active' => _("Forced"), + 'tshirt' => _("T-shirt?"), + 'actions' => "" + ], $matched_users), + '

' . _("Shirt statistics") . '

', + table([ + 'size' => _("Size"), + 'needed' => _("Needed shirts"), + 'given' => _("Given shirts") + ], $shirt_statistics) + ]); } diff --git a/includes/pages/admin_arrive.php b/includes/pages/admin_arrive.php index c2e97072..cd910bd0 100644 --- a/includes/pages/admin_arrive.php +++ b/includes/pages/admin_arrive.php @@ -12,7 +12,7 @@ function admin_arrive() if (isset($_REQUEST['search'])) { $search = strip_request_item('search'); } - + if (isset($_REQUEST['reset']) && preg_match("/^[0-9]*$/", $_REQUEST['reset'])) { $user_id = $_REQUEST['reset']; $user_source = User($user_id); @@ -36,7 +36,7 @@ function admin_arrive() $msg = error(_("Angel not found."), true); } } - + $users = sql_select("SELECT * FROM `User` ORDER BY `Nick`"); $arrival_count_at_day = []; $planned_arrival_count_at_day = []; @@ -57,11 +57,11 @@ function admin_arrive() break; } } - if (! $match) { + if (!$match) { continue; } } - + $usr['nick'] = User_Nick_render($usr); if ($usr['planned_departure_date'] != null) { $usr['rendered_planned_departure_date'] = date('Y-m-d', $usr['planned_departure_date']); @@ -72,131 +72,131 @@ function admin_arrive() $usr['rendered_arrival_date'] = $usr['arrival_date'] > 0 ? date('Y-m-d', $usr['arrival_date']) : "-"; $usr['arrived'] = $usr['Gekommen'] == 1 ? _("yes") : ""; $usr['actions'] = $usr['Gekommen'] == 1 ? '' . _("reset") . '' : '' . _("arrived") . ''; - + if ($usr['arrival_date'] > 0) { $day = date('Y-m-d', $usr['arrival_date']); - if (! isset($arrival_count_at_day[$day])) { + if (!isset($arrival_count_at_day[$day])) { $arrival_count_at_day[$day] = 0; } - $arrival_count_at_day[$day] ++; + $arrival_count_at_day[$day]++; } - + if ($usr['planned_arrival_date'] != null) { $day = date('Y-m-d', $usr['planned_arrival_date']); - if (! isset($planned_arrival_count_at_day[$day])) { + if (!isset($planned_arrival_count_at_day[$day])) { $planned_arrival_count_at_day[$day] = 0; } - $planned_arrival_count_at_day[$day] ++; + $planned_arrival_count_at_day[$day]++; } - + if ($usr['planned_departure_date'] != null && $usr['Gekommen'] == 1) { $day = date('Y-m-d', $usr['planned_departure_date']); - if (! isset($planned_departure_count_at_day[$day])) { + if (!isset($planned_departure_count_at_day[$day])) { $planned_departure_count_at_day[$day] = 0; } - $planned_departure_count_at_day[$day] ++; + $planned_departure_count_at_day[$day]++; } - + $users_matched[] = $usr; } - + ksort($arrival_count_at_day); ksort($planned_arrival_count_at_day); ksort($planned_departure_count_at_day); - + $arrival_at_day = []; $arrival_sum = 0; foreach ($arrival_count_at_day as $day => $count) { $arrival_sum += $count; $arrival_at_day[$day] = [ - 'day' => $day, - 'count' => $count, - 'sum' => $arrival_sum - ]; + 'day' => $day, + 'count' => $count, + 'sum' => $arrival_sum + ]; } - + $planned_arrival_at_day = []; $planned_arrival_sum = 0; foreach ($planned_arrival_count_at_day as $day => $count) { $planned_arrival_sum += $count; $planned_arrival_at_day[$day] = [ - 'day' => $day, - 'count' => $count, - 'sum' => $planned_arrival_sum - ]; + 'day' => $day, + 'count' => $count, + 'sum' => $planned_arrival_sum + ]; } - + $planned_departure_at_day = []; $planned_departure_sum = 0; foreach ($planned_departure_count_at_day as $day => $count) { $planned_departure_sum += $count; $planned_departure_at_day[$day] = [ - 'day' => $day, - 'count' => $count, - 'sum' => $planned_departure_sum - ]; + 'day' => $day, + 'count' => $count, + 'sum' => $planned_departure_sum + ]; } - + return page_with_title(admin_arrive_title(), [ - msg(), - form([ - form_text('search', _("Search"), $search), - form_submit('submit', _("Search")) - ]), - table([ - 'nick' => _("Nickname"), - 'rendered_planned_arrival_date' => _("Planned arrival"), - 'arrived' => _("Arrived?"), - 'rendered_arrival_date' => _("Arrival date"), - 'rendered_planned_departure_date' => _("Planned departure"), - 'actions' => "" - ], $users_matched), - div('row', [ - div('col-md-4', [ - heading(_("Planned arrival statistics"), 2), - bargraph('planned_arrives', 'day', [ - 'count' => _("arrived"), - 'sum' => _("arrived sum") - ], [ - 'count' => '#090', - 'sum' => '#888' - ], $planned_arrival_at_day), - table([ - 'day' => _("Date"), - 'count' => _("Count"), - 'sum' => _("Sum") - ], $planned_arrival_at_day) - ]), - div('col-md-4', [ - heading(_("Arrival statistics"), 2), - bargraph('arrives', 'day', [ - 'count' => _("arrived"), - 'sum' => _("arrived sum") - ], [ - 'count' => '#090', - 'sum' => '#888' - ], $arrival_at_day), - table([ - 'day' => _("Date"), - 'count' => _("Count"), - 'sum' => _("Sum") - ], $arrival_at_day) - ]), - div('col-md-4', [ - heading(_("Planned departure statistics"), 2), - bargraph('planned_departures', 'day', [ - 'count' => _("arrived"), - 'sum' => _("arrived sum") - ], [ - 'count' => '#090', - 'sum' => '#888' - ], $planned_departure_at_day), - table([ - 'day' => _("Date"), - 'count' => _("Count"), - 'sum' => _("Sum") - ], $planned_departure_at_day) - ]) - ]) - ]); + msg(), + form([ + form_text('search', _("Search"), $search), + form_submit('submit', _("Search")) + ]), + table([ + 'nick' => _("Nickname"), + 'rendered_planned_arrival_date' => _("Planned arrival"), + 'arrived' => _("Arrived?"), + 'rendered_arrival_date' => _("Arrival date"), + 'rendered_planned_departure_date' => _("Planned departure"), + 'actions' => "" + ], $users_matched), + div('row', [ + div('col-md-4', [ + heading(_("Planned arrival statistics"), 2), + bargraph('planned_arrives', 'day', [ + 'count' => _("arrived"), + 'sum' => _("arrived sum") + ], [ + 'count' => '#090', + 'sum' => '#888' + ], $planned_arrival_at_day), + table([ + 'day' => _("Date"), + 'count' => _("Count"), + 'sum' => _("Sum") + ], $planned_arrival_at_day) + ]), + div('col-md-4', [ + heading(_("Arrival statistics"), 2), + bargraph('arrives', 'day', [ + 'count' => _("arrived"), + 'sum' => _("arrived sum") + ], [ + 'count' => '#090', + 'sum' => '#888' + ], $arrival_at_day), + table([ + 'day' => _("Date"), + 'count' => _("Count"), + 'sum' => _("Sum") + ], $arrival_at_day) + ]), + div('col-md-4', [ + heading(_("Planned departure statistics"), 2), + bargraph('planned_departures', 'day', [ + 'count' => _("arrived"), + 'sum' => _("arrived sum") + ], [ + 'count' => '#090', + 'sum' => '#888' + ], $planned_departure_at_day), + table([ + 'day' => _("Date"), + 'count' => _("Count"), + 'sum' => _("Sum") + ], $planned_departure_at_day) + ]) + ]) + ]); } diff --git a/includes/pages/admin_free.php b/includes/pages/admin_free.php index db0c239f..947dd93b 100644 --- a/includes/pages/admin_free.php +++ b/includes/pages/admin_free.php @@ -8,12 +8,12 @@ function admin_free_title() function admin_free() { global $privileges; - + $search = ""; if (isset($_REQUEST['search'])) { $search = strip_request_item('search'); } - + $angeltypesearch = ""; if (empty($_REQUEST['angeltype'])) { $_REQUEST['angeltype'] = ''; @@ -24,15 +24,15 @@ function admin_free() } $angeltypesearch .= ") "; } - + $angel_types_source = sql_select("SELECT `id`, `name` FROM `AngelTypes` ORDER BY `name`"); $angel_types = [ - '' => 'alle Typen' - ]; + '' => 'alle Typen' + ]; foreach ($angel_types_source as $angel_type) { $angel_types[$angel_type['id']] = $angel_type['name']; } - + $users = sql_select(" SELECT `User`.* FROM `User` @@ -42,7 +42,7 @@ function admin_free() WHERE `User`.`Gekommen` = 1 AND `Shifts`.`SID` IS NULL GROUP BY `User`.`UID` ORDER BY `Nick`"); - + $free_users_table = []; if ($search == "") { $tokens = []; @@ -59,44 +59,47 @@ function admin_free() break; } } - if (! $match) { + if (!$match) { continue; } } - + $free_users_table[] = [ - 'name' => User_Nick_render($usr), - 'shift_state' => User_shift_state_render($usr), - 'dect' => $usr['DECT'], - 'jabber' => $usr['jabber'], - 'email' => $usr['email_by_human_allowed'] ? $usr['email'] : glyph('eye-close'), - 'actions' => in_array('admin_user', $privileges) ? button(page_link_to('admin_user') . '&id=' . $usr['UID'], _("edit"), 'btn-xs') : '' - ]; + 'name' => User_Nick_render($usr), + 'shift_state' => User_shift_state_render($usr), + 'dect' => $usr['DECT'], + 'jabber' => $usr['jabber'], + 'email' => $usr['email_by_human_allowed'] ? $usr['email'] : glyph('eye-close'), + 'actions' => + in_array('admin_user', $privileges) + ? button(page_link_to('admin_user') . '&id=' . $usr['UID'], _("edit"), 'btn-xs') + : '' + ]; } return page_with_title(admin_free_title(), [ - form([ - div('row', [ - div('col-md-4', [ - form_text('search', _("Search"), $search) - ]), - div('col-md-4', [ - form_select('angeltype', _("Angeltype"), $angel_types, $_REQUEST['angeltype']) - ]), - div('col-md-2', [ - form_checkbox('confirmed_only', _("Only confirmed"), isset($_REQUEST['confirmed_only'])) - ]), - div('col-md-2', [ - form_submit('submit', _("Search")) - ]) - ]) - ]), - table([ - 'name' => _("Nick"), - 'shift_state' => '', - 'dect' => _("DECT"), - 'jabber' => _("Jabber"), - 'email' => _("E-Mail"), - 'actions' => '' - ], $free_users_table) - ]); + form([ + div('row', [ + div('col-md-4', [ + form_text('search', _("Search"), $search) + ]), + div('col-md-4', [ + form_select('angeltype', _("Angeltype"), $angel_types, $_REQUEST['angeltype']) + ]), + div('col-md-2', [ + form_checkbox('confirmed_only', _("Only confirmed"), isset($_REQUEST['confirmed_only'])) + ]), + div('col-md-2', [ + form_submit('submit', _("Search")) + ]) + ]) + ]), + table([ + 'name' => _("Nick"), + 'shift_state' => '', + 'dect' => _("DECT"), + 'jabber' => _("Jabber"), + 'email' => _("E-Mail"), + 'actions' => '' + ], $free_users_table) + ]); } diff --git a/includes/pages/admin_groups.php b/includes/pages/admin_groups.php index 04e4320d..d170c374 100644 --- a/includes/pages/admin_groups.php +++ b/includes/pages/admin_groups.php @@ -9,90 +9,122 @@ function admin_groups() { $html = ""; $groups = sql_select("SELECT * FROM `Groups` ORDER BY `Name`"); - if (! isset($_REQUEST["action"])) { + if (!isset($_REQUEST["action"])) { $groups_table = []; foreach ($groups as $group) { - $privileges = sql_select("SELECT * FROM `GroupPrivileges` JOIN `Privileges` ON (`GroupPrivileges`.`privilege_id` = `Privileges`.`id`) WHERE `group_id`='" . sql_escape($group['UID']) . "'"); + $privileges = sql_select(" + SELECT * + FROM `GroupPrivileges` + JOIN `Privileges` ON (`GroupPrivileges`.`privilege_id` = `Privileges`.`id`) + WHERE `group_id`='" . sql_escape($group['UID']) . "' + "); $privileges_html = []; - + foreach ($privileges as $priv) { $privileges_html[] = $priv['name']; } - + $groups_table[] = [ - 'name' => $group['Name'], - 'privileges' => join(', ', $privileges_html), - 'actions' => button(page_link_to('admin_groups') . '&action=edit&id=' . $group['UID'], _("edit"), 'btn-xs') - ]; + 'name' => $group['Name'], + 'privileges' => join(', ', $privileges_html), + 'actions' => button( + page_link_to('admin_groups') . '&action=edit&id=' . $group['UID'], + _("edit"), + 'btn-xs' + ) + ]; } - + return page_with_title(admin_groups_title(), [ - table([ - 'name' => _("Name"), - 'privileges' => _("Privileges"), - 'actions' => '' - ], $groups_table) - ]); + table([ + 'name' => _("Name"), + 'privileges' => _("Privileges"), + 'actions' => '' + ], $groups_table) + ]); } else { switch ($_REQUEST["action"]) { - case 'edit': - if (isset($_REQUEST['id']) && preg_match("/^-[0-9]{1,11}$/", $_REQUEST['id'])) { - $group_id = $_REQUEST['id']; - } else { - return error("Incomplete call, missing Groups ID.", true); - } - - $group = sql_select("SELECT * FROM `Groups` WHERE `UID`='" . sql_escape($group_id) . "' LIMIT 1"); - if (count($group) > 0) { - list($group) = $group; - $privileges = sql_select("SELECT `Privileges`.*, `GroupPrivileges`.`group_id` FROM `Privileges` LEFT OUTER JOIN `GroupPrivileges` ON (`Privileges`.`id` = `GroupPrivileges`.`privilege_id` AND `GroupPrivileges`.`group_id`='" . sql_escape($group_id) . "') ORDER BY `Privileges`.`name`"); - $privileges_html = ""; - $privileges_form = []; - foreach ($privileges as $priv) { - $privileges_form[] = form_checkbox('privileges[]', $priv['desc'] . ' (' . $priv['name'] . ')', $priv['group_id'] != "", $priv['id']); - $privileges_html .= sprintf('' . ' %s %s', $priv['id'], ($priv['group_id'] != "" ? 'checked="checked"' : ''), $priv['name'], $priv['desc']); - } - - $privileges_form[] = form_submit('submit', _("Save")); - $html .= page_with_title(_("Edit group"), [ - form($privileges_form, page_link_to('admin_groups') . '&action=save&id=' . $group_id) - ]); - } else { - return error("No Group found.", true); - } - break; - - case 'save': - if (isset($_REQUEST['id']) && preg_match("/^-[0-9]{1,11}$/", $_REQUEST['id'])) { - $group_id = $_REQUEST['id']; - } else { - return error("Incomplete call, missing Groups ID.", true); - } - - $group = sql_select("SELECT * FROM `Groups` WHERE `UID`='" . sql_escape($group_id) . "' LIMIT 1"); - if (! is_array($_REQUEST['privileges'])) { - $_REQUEST['privileges'] = []; - } - if (count($group) > 0) { - list($group) = $group; - sql_query("DELETE FROM `GroupPrivileges` WHERE `group_id`='" . sql_escape($group_id) . "'"); - $privilege_names = []; - foreach ($_REQUEST['privileges'] as $priv) { - if (preg_match("/^[0-9]{1,}$/", $priv)) { - $group_privileges_source = sql_select("SELECT * FROM `Privileges` WHERE `id`='" . sql_escape($priv) . "' LIMIT 1"); - if (count($group_privileges_source) > 0) { - sql_query("INSERT INTO `GroupPrivileges` SET `group_id`='" . sql_escape($group_id) . "', `privilege_id`='" . sql_escape($priv) . "'"); - $privilege_names[] = $group_privileges_source[0]['name']; + case 'edit': + if (isset($_REQUEST['id']) && preg_match("/^-[0-9]{1,11}$/", $_REQUEST['id'])) { + $group_id = $_REQUEST['id']; + } else { + return error("Incomplete call, missing Groups ID.", true); + } + + $group = sql_select("SELECT * FROM `Groups` WHERE `UID`='" . sql_escape($group_id) . "' LIMIT 1"); + if (count($group) > 0) { + list($group) = $group; + $privileges = sql_select(" + SELECT `Privileges`.*, `GroupPrivileges`.`group_id` + FROM `Privileges` + LEFT OUTER JOIN `GroupPrivileges` + ON ( + `Privileges`.`id` = `GroupPrivileges`.`privilege_id` + AND `GroupPrivileges`.`group_id`='" . sql_escape($group_id) . "' + ) + ORDER BY `Privileges`.`name` + "); + $privileges_html = ""; + $privileges_form = []; + foreach ($privileges as $priv) { + $privileges_form[] = form_checkbox( + 'privileges[]', + $priv['desc'] . ' (' . $priv['name'] . ')', + $priv['group_id'] != "", + $priv['id'] + ); + $privileges_html .= sprintf( + ' %s %s', + $priv['id'], + ($priv['group_id'] != "" ? 'checked="checked"' : ''), + $priv['name'], + $priv['desc'] + ); } + + $privileges_form[] = form_submit('submit', _("Save")); + $html .= page_with_title(_("Edit group"), [ + form($privileges_form, page_link_to('admin_groups') . '&action=save&id=' . $group_id) + ]); + } else { + return error("No Group found.", true); } - } - engelsystem_log("Group privileges of group " . $group['Name'] . " edited: " . join(", ", $privilege_names)); - redirect(page_link_to("admin_groups")); - } else { - return error("No Group found.", true); + break; + + case 'save': + if (isset($_REQUEST['id']) && preg_match("/^-[0-9]{1,11}$/", $_REQUEST['id'])) { + $group_id = $_REQUEST['id']; + } else { + return error("Incomplete call, missing Groups ID.", true); + } + + $group = sql_select("SELECT * FROM `Groups` WHERE `UID`='" . sql_escape($group_id) . "' LIMIT 1"); + if (!is_array($_REQUEST['privileges'])) { + $_REQUEST['privileges'] = []; + } + if (count($group) > 0) { + list($group) = $group; + sql_query("DELETE FROM `GroupPrivileges` WHERE `group_id`='" . sql_escape($group_id) . "'"); + $privilege_names = []; + foreach ($_REQUEST['privileges'] as $priv) { + if (preg_match("/^[0-9]{1,}$/", $priv)) { + $group_privileges_source = sql_select("SELECT * FROM `Privileges` WHERE `id`='" . sql_escape($priv) . "' LIMIT 1"); + if (count($group_privileges_source) > 0) { + sql_query("INSERT INTO `GroupPrivileges` SET `group_id`='" . sql_escape($group_id) . "', `privilege_id`='" . sql_escape($priv) . "'"); + $privilege_names[] = $group_privileges_source[0]['name']; + } + } + } + engelsystem_log( + "Group privileges of group " . $group['Name'] + . " edited: " . join(", ", $privilege_names) + ); + redirect(page_link_to("admin_groups")); + } else { + return error("No Group found.", true); + } + break; } - break; - } } return $html; } diff --git a/includes/pages/admin_import.php b/includes/pages/admin_import.php index e1674670..46c13ac7 100644 --- a/includes/pages/admin_import.php +++ b/includes/pages/admin_import.php @@ -11,28 +11,31 @@ function admin_import() global $user; $html = ""; $import_dir = __DIR__ . '/../../import'; - + $step = "input"; - if (isset($_REQUEST['step']) && in_array($step, [ - 'input', - 'check', - 'import' - ])) { + if ( + isset($_REQUEST['step']) + && in_array($step, [ + 'input', + 'check', + 'import' + ]) + ) { $step = $_REQUEST['step']; } - + if ($test_handle = @fopen($import_dir . '/tmp', 'w')) { fclose($test_handle); @unlink($import_dir . '/tmp'); } else { error(_('Webserver has no write-permission on import directory.')); } - + $import_file = $import_dir . '/import_' . $user['UID'] . '.xml'; $shifttype_id = null; $add_minutes_start = 15; $add_minutes_end = 15; - + $shifttypes_source = ShiftTypes(); if ($shifttypes_source === false) { engelsystem_error('Unable to load shifttypes.'); @@ -41,301 +44,323 @@ function admin_import() foreach ($shifttypes_source as $shifttype) { $shifttypes[$shifttype['id']] = $shifttype['name']; } - + switch ($step) { - case 'input': - $valid = false; - - if (isset($_REQUEST['submit'])) { - $valid = true; - - if (isset($_REQUEST['shifttype_id']) && isset($shifttypes[$_REQUEST['shifttype_id']])) { - $shifttype_id = $_REQUEST['shifttype_id']; - } else { - $valid = false; - error(_('Please select a shift type.')); - } - - if (isset($_REQUEST['add_minutes_start']) && is_numeric(trim($_REQUEST['add_minutes_start']))) { - $add_minutes_start = trim($_REQUEST['add_minutes_start']); - } else { - $valid = false; - error(_("Please enter an amount of minutes to add to a talk's begin.")); - } - - if (isset($_REQUEST['add_minutes_end']) && is_numeric(trim($_REQUEST['add_minutes_end']))) { - $add_minutes_end = trim($_REQUEST['add_minutes_end']); - } else { - $valid = false; - error(_("Please enter an amount of minutes to add to a talk's end.")); - } - - if (isset($_FILES['xcal_file']) && ($_FILES['xcal_file']['error'] == 0)) { - if (move_uploaded_file($_FILES['xcal_file']['tmp_name'], $import_file)) { - libxml_use_internal_errors(true); - if (simplexml_load_file($import_file) === false) { - $valid = false; - error(_('No valid xml/xcal file provided.')); - unlink($import_file); - } - } else { - $valid = false; - error(_('File upload went wrong.')); - } - } else { - $valid = false; - error(_('Please provide some data.')); - } - } - - if ($valid) { - redirect(page_link_to('admin_import') . "&step=check&shifttype_id=" . $shifttype_id . "&add_minutes_end=" . $add_minutes_end . "&add_minutes_start=" . $add_minutes_start); - } else { - $html .= div('well well-sm text-center', [ - _('File Upload') . mute(glyph('arrow-right')) . mute(_('Validation')) . mute(glyph('arrow-right')) . mute(_('Import')) - ]) . div('row', [ - div('col-md-offset-3 col-md-6', [ - form([ - form_info('', _("This import will create/update/delete rooms and shifts by given FRAB-export file. The needed file format is xcal.")), - form_select('shifttype_id', _('Shifttype'), $shifttypes, $shifttype_id), - form_spinner('add_minutes_start', _("Add minutes to start"), $add_minutes_start), - form_spinner('add_minutes_end', _("Add minutes to end"), $add_minutes_end), - form_file('xcal_file', _("xcal-File (.xcal)")), - form_submit('submit', _("Import")) - ]) - ]) - ]); - } - break; - - case 'check': - if (! file_exists($import_file)) { - error(_('Missing import file.')); - redirect(page_link_to('admin_import')); - } - - if (isset($_REQUEST['shifttype_id']) && isset($shifttypes[$_REQUEST['shifttype_id']])) { - $shifttype_id = $_REQUEST['shifttype_id']; - } else { - error(_('Please select a shift type.')); - redirect(page_link_to('admin_import')); - } - - if (isset($_REQUEST['add_minutes_start']) && is_numeric(trim($_REQUEST['add_minutes_start']))) { - $add_minutes_start = trim($_REQUEST['add_minutes_start']); - } else { - error(_("Please enter an amount of minutes to add to a talk's begin.")); - redirect(page_link_to('admin_import')); - } - - if (isset($_REQUEST['add_minutes_end']) && is_numeric(trim($_REQUEST['add_minutes_end']))) { - $add_minutes_end = trim($_REQUEST['add_minutes_end']); - } else { - error(_("Please enter an amount of minutes to add to a talk's end.")); - redirect(page_link_to('admin_import')); - } - - list($rooms_new, $rooms_deleted) = prepare_rooms($import_file); - list($events_new, $events_updated, $events_deleted) = prepare_events($import_file, $shifttype_id, $add_minutes_start, $add_minutes_end); - - $html .= div('well well-sm text-center', [ - '' . _('File Upload') . glyph('ok-circle') . '' . mute(glyph('arrow-right')) . _('Validation') . mute(glyph('arrow-right')) . mute(_('Import')) - ]) . form([ - div('row', [ - div('col-sm-6', [ - '

' . _("Rooms to create") . '

', - table(_("Name"), $rooms_new) - ]), - div('col-sm-6', [ - '

' . _("Rooms to delete") . '

', - table(_("Name"), $rooms_deleted) - ]) - ]), - '

' . _("Shifts to create") . '

', - table([ - 'day' => _("Day"), - 'start' => _("Start"), - 'end' => _("End"), - 'shifttype' => _('Shift type'), - 'title' => _("Title"), - 'room' => _("Room") - ], shifts_printable($events_new, $shifttypes)), - '

' . _("Shifts to update") . '

', - table([ - 'day' => _("Day"), - 'start' => _("Start"), - 'end' => _("End"), - 'shifttype' => _('Shift type'), - 'title' => _("Title"), - 'room' => _("Room") - ], shifts_printable($events_updated, $shifttypes)), - '

' . _("Shifts to delete") . '

', - table([ - 'day' => _("Day"), - 'start' => _("Start"), - 'end' => _("End"), - 'shifttype' => _('Shift type'), - 'title' => _("Title"), - 'room' => _("Room") - ], shifts_printable($events_deleted, $shifttypes)), - form_submit('submit', _("Import")) - ], page_link_to('admin_import') . '&step=import&shifttype_id=' . $shifttype_id . "&add_minutes_end=" . $add_minutes_end . "&add_minutes_start=" . $add_minutes_start); - break; - - case 'import': - if (! file_exists($import_file)) { - error(_('Missing import file.')); - redirect(page_link_to('admin_import')); - } - - if (! file_exists($import_file)) { - redirect(page_link_to('admin_import')); - } - - if (isset($_REQUEST['shifttype_id']) && isset($shifttypes[$_REQUEST['shifttype_id']])) { - $shifttype_id = $_REQUEST['shifttype_id']; - } else { - error(_('Please select a shift type.')); - redirect(page_link_to('admin_import')); - } - - if (isset($_REQUEST['add_minutes_start']) && is_numeric(trim($_REQUEST['add_minutes_start']))) { - $add_minutes_start = trim($_REQUEST['add_minutes_start']); - } else { - error(_("Please enter an amount of minutes to add to a talk's begin.")); - redirect(page_link_to('admin_import')); - } - - if (isset($_REQUEST['add_minutes_end']) && is_numeric(trim($_REQUEST['add_minutes_end']))) { - $add_minutes_end = trim($_REQUEST['add_minutes_end']); - } else { - error(_("Please enter an amount of minutes to add to a talk's end.")); - redirect(page_link_to('admin_import')); - } - - list($rooms_new, $rooms_deleted) = prepare_rooms($import_file); - foreach ($rooms_new as $room) { - $result = Room_create($room, true, true); - if ($result === false) { - engelsystem_error('Unable to create room.'); - } - $rooms_import[trim($room)] = sql_id(); - } - foreach ($rooms_deleted as $room) { - sql_query("DELETE FROM `Room` WHERE `Name`='" . sql_escape($room) . "' LIMIT 1"); - } - - list($events_new, $events_updated, $events_deleted) = prepare_events($import_file, $shifttype_id, $add_minutes_start, $add_minutes_end); - foreach ($events_new as $event) { - $result = Shift_create($event); - if ($result === false) { - engelsystem_error('Unable to create shift.'); - } - } - - foreach ($events_updated as $event) { - $result = Shift_update_by_psid($event); - if ($result === false) { - engelsystem_error('Unable to update shift.'); - } - } - - foreach ($events_deleted as $event) { - $result = Shift_delete_by_psid($event['PSID']); - if ($result === false) { - engelsystem_error('Unable to delete shift.'); - } - } - - engelsystem_log("Frab import done"); - - unlink($import_file); - - $html .= div('well well-sm text-center', [ - '' . _('File Upload') . glyph('ok-circle') . '' . mute(glyph('arrow-right')) . '' . _('Validation') . glyph('ok-circle') . '' . mute(glyph('arrow-right')) . '' . _('Import') . glyph('ok-circle') . '' - ]) . success(_("It's done!"), true); - break; - default: - redirect(page_link_to('admin_import')); - } - + case 'input': + $valid = false; + + if (isset($_REQUEST['submit'])) { + $valid = true; + + if (isset($_REQUEST['shifttype_id']) && isset($shifttypes[$_REQUEST['shifttype_id']])) { + $shifttype_id = $_REQUEST['shifttype_id']; + } else { + $valid = false; + error(_('Please select a shift type.')); + } + + if (isset($_REQUEST['add_minutes_start']) && is_numeric(trim($_REQUEST['add_minutes_start']))) { + $add_minutes_start = trim($_REQUEST['add_minutes_start']); + } else { + $valid = false; + error(_("Please enter an amount of minutes to add to a talk's begin.")); + } + + if (isset($_REQUEST['add_minutes_end']) && is_numeric(trim($_REQUEST['add_minutes_end']))) { + $add_minutes_end = trim($_REQUEST['add_minutes_end']); + } else { + $valid = false; + error(_("Please enter an amount of minutes to add to a talk's end.")); + } + + if (isset($_FILES['xcal_file']) && ($_FILES['xcal_file']['error'] == 0)) { + if (move_uploaded_file($_FILES['xcal_file']['tmp_name'], $import_file)) { + libxml_use_internal_errors(true); + if (simplexml_load_file($import_file) === false) { + $valid = false; + error(_('No valid xml/xcal file provided.')); + unlink($import_file); + } + } else { + $valid = false; + error(_('File upload went wrong.')); + } + } else { + $valid = false; + error(_('Please provide some data.')); + } + } + + if ($valid) { + redirect(page_link_to('admin_import') . "&step=check&shifttype_id=" . $shifttype_id . "&add_minutes_end=" . $add_minutes_end . "&add_minutes_start=" . $add_minutes_start); + } else { + $html .= div('well well-sm text-center', [ + _('File Upload') . mute(glyph('arrow-right')) . mute(_('Validation')) . mute(glyph('arrow-right')) . mute(_('Import')) + ]) . div('row', [ + div('col-md-offset-3 col-md-6', [ + form([ + form_info( + '', + _("This import will create/update/delete rooms and shifts by given FRAB-export file. The needed file format is xcal.") + ), + form_select('shifttype_id', _('Shifttype'), $shifttypes, $shifttype_id), + form_spinner('add_minutes_start', _("Add minutes to start"), $add_minutes_start), + form_spinner('add_minutes_end', _("Add minutes to end"), $add_minutes_end), + form_file('xcal_file', _("xcal-File (.xcal)")), + form_submit('submit', _("Import")) + ]) + ]) + ]); + } + break; + + case 'check': + if (!file_exists($import_file)) { + error(_('Missing import file.')); + redirect(page_link_to('admin_import')); + } + + if (isset($_REQUEST['shifttype_id']) && isset($shifttypes[$_REQUEST['shifttype_id']])) { + $shifttype_id = $_REQUEST['shifttype_id']; + } else { + error(_('Please select a shift type.')); + redirect(page_link_to('admin_import')); + } + + if (isset($_REQUEST['add_minutes_start']) && is_numeric(trim($_REQUEST['add_minutes_start']))) { + $add_minutes_start = trim($_REQUEST['add_minutes_start']); + } else { + error(_("Please enter an amount of minutes to add to a talk's begin.")); + redirect(page_link_to('admin_import')); + } + + if (isset($_REQUEST['add_minutes_end']) && is_numeric(trim($_REQUEST['add_minutes_end']))) { + $add_minutes_end = trim($_REQUEST['add_minutes_end']); + } else { + error(_("Please enter an amount of minutes to add to a talk's end.")); + redirect(page_link_to('admin_import')); + } + + list($rooms_new, $rooms_deleted) = prepare_rooms($import_file); + list($events_new, $events_updated, $events_deleted) = prepare_events( + $import_file, + $shifttype_id, + $add_minutes_start, + $add_minutes_end + ); + + $html .= div( + 'well well-sm text-center', + [ + '' . _('File Upload') . glyph('ok-circle') . '' . mute(glyph('arrow-right')) . _('Validation') . mute(glyph('arrow-right')) . mute(_('Import')) + ]) + . form( + [ + div('row', [ + div('col-sm-6', [ + '

' . _("Rooms to create") . '

', + table(_("Name"), $rooms_new) + ]), + div('col-sm-6', [ + '

' . _("Rooms to delete") . '

', + table(_("Name"), $rooms_deleted) + ]) + ]), + '

' . _("Shifts to create") . '

', + table([ + 'day' => _("Day"), + 'start' => _("Start"), + 'end' => _("End"), + 'shifttype' => _('Shift type'), + 'title' => _("Title"), + 'room' => _("Room") + ], shifts_printable($events_new, $shifttypes)), + '

' . _("Shifts to update") . '

', + table([ + 'day' => _("Day"), + 'start' => _("Start"), + 'end' => _("End"), + 'shifttype' => _('Shift type'), + 'title' => _("Title"), + 'room' => _("Room") + ], shifts_printable($events_updated, $shifttypes)), + '

' . _("Shifts to delete") . '

', + table([ + 'day' => _("Day"), + 'start' => _("Start"), + 'end' => _("End"), + 'shifttype' => _('Shift type'), + 'title' => _("Title"), + 'room' => _("Room") + ], shifts_printable($events_deleted, $shifttypes)), + form_submit('submit', _("Import")) + ], + page_link_to('admin_import') + . '&step=import&shifttype_id=' . $shifttype_id + . "&add_minutes_end=" . $add_minutes_end + . "&add_minutes_start=" . $add_minutes_start + ); + break; + + case 'import': + if (!file_exists($import_file)) { + error(_('Missing import file.')); + redirect(page_link_to('admin_import')); + } + + if (!file_exists($import_file)) { + redirect(page_link_to('admin_import')); + } + + if (isset($_REQUEST['shifttype_id']) && isset($shifttypes[$_REQUEST['shifttype_id']])) { + $shifttype_id = $_REQUEST['shifttype_id']; + } else { + error(_('Please select a shift type.')); + redirect(page_link_to('admin_import')); + } + + if (isset($_REQUEST['add_minutes_start']) && is_numeric(trim($_REQUEST['add_minutes_start']))) { + $add_minutes_start = trim($_REQUEST['add_minutes_start']); + } else { + error(_("Please enter an amount of minutes to add to a talk's begin.")); + redirect(page_link_to('admin_import')); + } + + if (isset($_REQUEST['add_minutes_end']) && is_numeric(trim($_REQUEST['add_minutes_end']))) { + $add_minutes_end = trim($_REQUEST['add_minutes_end']); + } else { + error(_("Please enter an amount of minutes to add to a talk's end.")); + redirect(page_link_to('admin_import')); + } + + list($rooms_new, $rooms_deleted) = prepare_rooms($import_file); + foreach ($rooms_new as $room) { + $result = Room_create($room, true, true); + if ($result === false) { + engelsystem_error('Unable to create room.'); + } + $rooms_import[trim($room)] = sql_id(); + } + foreach ($rooms_deleted as $room) { + sql_query("DELETE FROM `Room` WHERE `Name`='" . sql_escape($room) . "' LIMIT 1"); + } + + list($events_new, $events_updated, $events_deleted) = prepare_events( + $import_file, + $shifttype_id, + $add_minutes_start, + $add_minutes_end + ); + foreach ($events_new as $event) { + $result = Shift_create($event); + if ($result === false) { + engelsystem_error('Unable to create shift.'); + } + } + + foreach ($events_updated as $event) { + $result = Shift_update_by_psid($event); + if ($result === false) { + engelsystem_error('Unable to update shift.'); + } + } + + foreach ($events_deleted as $event) { + $result = Shift_delete_by_psid($event['PSID']); + if ($result === false) { + engelsystem_error('Unable to delete shift.'); + } + } + + engelsystem_log("Frab import done"); + + unlink($import_file); + + $html .= div('well well-sm text-center', [ + '' . _('File Upload') . glyph('ok-circle') . '' . mute(glyph('arrow-right')) . '' . _('Validation') . glyph('ok-circle') . '' . mute(glyph('arrow-right')) . '' . _('Import') . glyph('ok-circle') . '' + ]) . success(_("It's done!"), true); + break; + default: + redirect(page_link_to('admin_import')); + } + return page_with_title(admin_import_title(), [ - msg(), - $html - ]); + msg(), + $html + ]); } function prepare_rooms($file) { global $rooms_import; $data = read_xml($file); - - // Load rooms from db for compare with input - $rooms = sql_select("SELECT * FROM `Room` WHERE `FromPentabarf`='Y'"); + + // Load rooms from db for compare with input + $rooms = sql_select("SELECT * FROM `Room` WHERE `FromPentabarf`='Y'"); $rooms_db = []; $rooms_import = []; foreach ($rooms as $room) { - $rooms_db[] = (string) $room['Name']; + $rooms_db[] = (string)$room['Name']; $rooms_import[$room['Name']] = $room['RID']; } - + $events = $data->vcalendar->vevent; $rooms_pb = []; foreach ($events as $event) { - $rooms_pb[] = (string) $event->location; - if (! isset($rooms_import[trim($event->location)])) { + $rooms_pb[] = (string)$event->location; + if (!isset($rooms_import[trim($event->location)])) { $rooms_import[trim($event->location)] = trim($event->location); } } $rooms_pb = array_unique($rooms_pb); - + $rooms_new = array_diff($rooms_pb, $rooms_db); $rooms_deleted = array_diff($rooms_db, $rooms_pb); - + return [ - $rooms_new, - $rooms_deleted - ]; + $rooms_new, + $rooms_deleted + ]; } function prepare_events($file, $shifttype_id, $add_minutes_start, $add_minutes_end) { global $rooms_import; $data = read_xml($file); - + $rooms = sql_select("SELECT * FROM `Room`"); $rooms_db = []; foreach ($rooms as $room) { $rooms_db[$room['Name']] = $room['RID']; } - + $events = $data->vcalendar->vevent; $shifts_pb = []; foreach ($events as $event) { $event_pb = $event->children("http://pentabarf.org"); $event_id = trim($event_pb->{ - 'event-id' }); + 'event-id'}); $shifts_pb[$event_id] = [ - 'shifttype_id' => $shifttype_id, - 'start' => parse_date("Ymd\THis", $event->dtstart) - $add_minutes_start * 60, - 'end' => parse_date("Ymd\THis", $event->dtend) + $add_minutes_end * 60, - 'RID' => $rooms_import[trim($event->location)], - 'title' => trim($event->summary), - 'URL' => trim($event->url), - 'PSID' => $event_id - ]; + 'shifttype_id' => $shifttype_id, + 'start' => parse_date("Ymd\THis", $event->dtstart) - $add_minutes_start * 60, + 'end' => parse_date("Ymd\THis", $event->dtend) + $add_minutes_end * 60, + 'RID' => $rooms_import[trim($event->location)], + 'title' => trim($event->summary), + 'URL' => trim($event->url), + 'PSID' => $event_id + ]; } - + $shifts = sql_select("SELECT * FROM `Shifts` WHERE `PSID` IS NOT NULL ORDER BY `start`"); $shifts_db = []; foreach ($shifts as $shift) { $shifts_db[$shift['PSID']] = $shift; } - + $shifts_new = []; $shifts_updated = []; foreach ($shifts_pb as $shift) { - if (! isset($shifts_db[$shift['PSID']])) { + if (!isset($shifts_db[$shift['PSID']])) { $shifts_new[] = $shift; } else { $tmp = $shifts_db[$shift['PSID']]; @@ -344,25 +369,25 @@ function prepare_events($file, $shifttype_id, $add_minutes_start, $add_minutes_e } } } - + $shifts_deleted = []; foreach ($shifts_db as $shift) { - if (! isset($shifts_pb[$shift['PSID']])) { + if (!isset($shifts_pb[$shift['PSID']])) { $shifts_deleted[] = $shift; } } - + return [ - $shifts_new, - $shifts_updated, - $shifts_deleted - ]; + $shifts_new, + $shifts_updated, + $shifts_deleted + ]; } function read_xml($file) { global $xml_import; - if (! isset($xml_import)) { + if (!isset($xml_import)) { $xml_import = simplexml_load_file($file); } return $xml_import; @@ -372,27 +397,27 @@ function shifts_printable($shifts, $shifttypes) { global $rooms_import; $rooms = array_flip($rooms_import); - + uasort($shifts, 'shift_sort'); - + $shifts_printable = []; foreach ($shifts as $shift) { $shifts_printable[] = [ - 'day' => date("l, Y-m-d", $shift['start']), - 'start' => date("H:i", $shift['start']), - 'shifttype' => ShiftType_name_render([ - 'id' => $shift['shifttype_id'], - 'name' => $shifttypes[$shift['shifttype_id']] - ]), - 'title' => shorten($shift['title']), - 'end' => date("H:i", $shift['end']), - 'room' => $rooms[$shift['RID']] - ]; + 'day' => date("l, Y-m-d", $shift['start']), + 'start' => date("H:i", $shift['start']), + 'shifttype' => ShiftType_name_render([ + 'id' => $shift['shifttype_id'], + 'name' => $shifttypes[$shift['shifttype_id']] + ]), + 'title' => shorten($shift['title']), + 'end' => date("H:i", $shift['end']), + 'room' => $rooms[$shift['RID']] + ]; } return $shifts_printable; } function shift_sort($shift_a, $shift_b) { - return ($shift_a['start'] < $shift_b['start']) ? - 1 : 1; + return ($shift_a['start'] < $shift_b['start']) ? -1 : 1; } diff --git a/includes/pages/admin_log.php b/includes/pages/admin_log.php index d4548c07..fc07cc87 100644 --- a/includes/pages/admin_log.php +++ b/includes/pages/admin_log.php @@ -12,23 +12,23 @@ function admin_log() $filter = strip_request_item('keyword'); } $log_entries_source = LogEntries_filter($filter); - + $log_entries = []; foreach ($log_entries_source as $log_entry) { $log_entry['date'] = date("d.m.Y H:i", $log_entry['timestamp']); $log_entries[] = $log_entry; } - + return page_with_title(admin_log_title(), [ - msg(), - form([ - form_text('keyword', _("Search"), $filter), - form_submit(_("Search"), "Go") - ]), - table([ - 'date' => "Time", - 'nick' => "Angel", - 'message' => "Log Entry" - ], $log_entries) - ]); + msg(), + form([ + form_text('keyword', _("Search"), $filter), + form_submit(_("Search"), "Go") + ]), + table([ + 'date' => "Time", + 'nick' => "Angel", + 'message' => "Log Entry" + ], $log_entries) + ]); } diff --git a/includes/pages/admin_news.php b/includes/pages/admin_news.php index 46d72ddd..1a35f04a 100644 --- a/includes/pages/admin_news.php +++ b/includes/pages/admin_news.php @@ -3,65 +3,67 @@ function admin_news() { global $user; - - if (! isset($_GET["action"])) { + + if (!isset($_GET["action"])) { redirect(page_link_to("news")); } - + $html = '

' . _("Edit news entry") . '

' . msg(); if (isset($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id'])) { $news_id = $_REQUEST['id']; } else { return error("Incomplete call, missing News ID.", true); } - + $news = sql_select("SELECT * FROM `News` WHERE `ID`='" . sql_escape($news_id) . "' LIMIT 1"); if (empty($news)) { return error("No News found.", true); } switch ($_REQUEST["action"]) { - default: - redirect(page_link_to('news')); - case 'edit': - list($news) = $news; - - $user_source = User($news['UID']); - - $html .= form([ - form_info(_("Date"), date("Y-m-d H:i", $news['Datum'])), - form_info(_("Author"), User_Nick_render($user_source)), - form_text('eBetreff', _("Subject"), $news['Betreff']), - form_textarea('eText', _("Message"), $news['Text']), - form_checkbox('eTreffen', _("Meeting"), $news['Treffen'] == 1, 1), - form_submit('submit', _("Save")) - ], page_link_to('admin_news&action=save&id=' . $news_id)); - - $html .= ' ' . _("Delete") . ''; - break; - - case 'save': - list($news) = $news; - - sql_query("UPDATE `News` SET + default: + redirect(page_link_to('news')); + case 'edit': + list($news) = $news; + + $user_source = User($news['UID']); + + $html .= form([ + form_info(_("Date"), date("Y-m-d H:i", $news['Datum'])), + form_info(_("Author"), User_Nick_render($user_source)), + form_text('eBetreff', _("Subject"), $news['Betreff']), + form_textarea('eText', _("Message"), $news['Text']), + form_checkbox('eTreffen', _("Meeting"), $news['Treffen'] == 1, 1), + form_submit('submit', _("Save")) + ], page_link_to('admin_news&action=save&id=' . $news_id)); + + $html .= '' + . ' ' . _("Delete") + . ''; + break; + + case 'save': + list($news) = $news; + + sql_query("UPDATE `News` SET `Datum`='" . sql_escape(time()) . "', `Betreff`='" . sql_escape($_POST["eBetreff"]) . "', `Text`='" . sql_escape($_POST["eText"]) . "', `UID`='" . sql_escape($user['UID']) . "', `Treffen`='" . sql_escape($_POST["eTreffen"]) . "' WHERE `ID`='" . sql_escape($news_id) . "'"); - engelsystem_log("News updated: " . $_POST["eBetreff"]); - success(_("News entry updated.")); - redirect(page_link_to("news")); - break; - - case 'delete': - list($news) = $news; - - sql_query("DELETE FROM `News` WHERE `ID`='" . sql_escape($news_id) . "' LIMIT 1"); - engelsystem_log("News deleted: " . $news['Betreff']); - success(_("News entry deleted.")); - redirect(page_link_to("news")); - break; - } + engelsystem_log("News updated: " . $_POST["eBetreff"]); + success(_("News entry updated.")); + redirect(page_link_to("news")); + break; + + case 'delete': + list($news) = $news; + + sql_query("DELETE FROM `News` WHERE `ID`='" . sql_escape($news_id) . "' LIMIT 1"); + engelsystem_log("News deleted: " . $news['Betreff']); + success(_("News entry deleted.")); + redirect(page_link_to("news")); + break; + } return $html . '
'; } diff --git a/includes/pages/admin_questions.php b/includes/pages/admin_questions.php index e8a2e50d..c65280d5 100644 --- a/includes/pages/admin_questions.php +++ b/includes/pages/admin_questions.php @@ -11,112 +11,129 @@ function admin_questions_title() function admin_new_questions() { global $privileges, $page; - + if ($page != "admin_questions") { if (in_array("admin_questions", $privileges)) { $new_messages = sql_num_query("SELECT * FROM `Questions` WHERE `AID` IS NULL"); - + if ($new_messages > 0) { return '' . _('There are unanswered questions!') . ''; } } } - + return null; } function admin_questions() { global $user; - - if (! isset($_REQUEST['action'])) { + + if (!isset($_REQUEST['action'])) { $unanswered_questions_table = []; $questions = sql_select("SELECT * FROM `Questions` WHERE `AID` IS NULL"); foreach ($questions as $question) { $user_source = User($question['UID']); - + $unanswered_questions_table[] = [ - 'from' => User_Nick_render($user_source), - 'question' => str_replace("\n", "
", $question['Question']), - 'answer' => form([ - form_textarea('answer', '', ''), - form_submit('submit', _("Save")) - ], page_link_to('admin_questions') . '&action=answer&id=' . $question['QID']), - 'actions' => button(page_link_to("admin_questions") . '&action=delete&id=' . $question['QID'], _("delete"), 'btn-xs') - ]; + 'from' => User_Nick_render($user_source), + 'question' => str_replace("\n", "
", $question['Question']), + 'answer' => form([ + form_textarea('answer', '', ''), + form_submit('submit', _("Save")) + ], page_link_to('admin_questions') . '&action=answer&id=' . $question['QID']), + 'actions' => button( + page_link_to("admin_questions") . '&action=delete&id=' . $question['QID'], + _("delete"), + 'btn-xs' + ) + ]; } - + $answered_questions_table = []; $questions = sql_select("SELECT * FROM `Questions` WHERE NOT `AID` IS NULL"); foreach ($questions as $question) { $user_source = User($question['UID']); $answer_user_source = User($question['AID']); $answered_questions_table[] = [ - 'from' => User_Nick_render($user_source), - 'question' => str_replace("\n", "
", $question['Question']), - 'answered_by' => User_Nick_render($answer_user_source), - 'answer' => str_replace("\n", "
", $question['Answer']), - 'actions' => button(page_link_to("admin_questions") . '&action=delete&id=' . $question['QID'], _("delete"), 'btn-xs') - ]; + 'from' => User_Nick_render($user_source), + 'question' => str_replace("\n", "
", $question['Question']), + 'answered_by' => User_Nick_render($answer_user_source), + 'answer' => str_replace("\n", "
", $question['Answer']), + 'actions' => button( + page_link_to("admin_questions") . '&action=delete&id=' . $question['QID'], + _("delete"), + 'btn-xs' + ) + ]; } - + return page_with_title(admin_questions_title(), [ - '

' . _("Unanswered questions") . '

', - table([ - 'from' => _("From"), - 'question' => _("Question"), - 'answer' => _("Answer"), - 'actions' => '' - ], $unanswered_questions_table), - '

' . _("Answered questions") . '

', - table([ - 'from' => _("From"), - 'question' => _("Question"), - 'answered_by' => _("Answered by"), - 'answer' => _("Answer"), - 'actions' => '' - ], $answered_questions_table) - ]); + '

' . _("Unanswered questions") . '

', + table([ + 'from' => _("From"), + 'question' => _("Question"), + 'answer' => _("Answer"), + 'actions' => '' + ], $unanswered_questions_table), + '

' . _("Answered questions") . '

', + table([ + 'from' => _("From"), + 'question' => _("Question"), + 'answered_by' => _("Answered by"), + 'answer' => _("Answer"), + 'actions' => '' + ], $answered_questions_table) + ]); } else { switch ($_REQUEST['action']) { - case 'answer': - if (isset($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id'])) { - $question_id = $_REQUEST['id']; - } else { - return error("Incomplete call, missing Question ID.", true); - } - - $question = sql_select("SELECT * FROM `Questions` WHERE `QID`='" . sql_escape($question_id) . "' LIMIT 1"); - if (count($question) > 0 && $question[0]['AID'] == null) { - $answer = trim(preg_replace("/([^\p{L}\p{P}\p{Z}\p{N}\n]{1,})/ui", '', strip_tags($_REQUEST['answer']))); - - if ($answer != "") { - sql_query("UPDATE `Questions` SET `AID`='" . sql_escape($user['UID']) . "', `Answer`='" . sql_escape($answer) . "' WHERE `QID`='" . sql_escape($question_id) . "' LIMIT 1"); - engelsystem_log("Question " . $question[0]['Question'] . " answered: " . $answer); - redirect(page_link_to("admin_questions")); - } else { - return error("Enter an answer!", true); - } - } else { - return error("No question found.", true); - } - break; - case 'delete': - if (isset($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id'])) { - $question_id = $_REQUEST['id']; - } else { - return error("Incomplete call, missing Question ID.", true); - } - - $question = sql_select("SELECT * FROM `Questions` WHERE `QID`='" . sql_escape($question_id) . "' LIMIT 1"); - if (count($question) > 0) { - sql_query("DELETE FROM `Questions` WHERE `QID`='" . sql_escape($question_id) . "' LIMIT 1"); - engelsystem_log("Question deleted: " . $question[0]['Question']); - redirect(page_link_to("admin_questions")); - } else { - return error("No question found.", true); + case 'answer': + if (isset($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id'])) { + $question_id = $_REQUEST['id']; + } else { + return error("Incomplete call, missing Question ID.", true); + } + + $question = sql_select("SELECT * FROM `Questions` WHERE `QID`='" . sql_escape($question_id) . "' LIMIT 1"); + if (count($question) > 0 && $question[0]['AID'] == null) { + $answer = trim( + preg_replace("/([^\p{L}\p{P}\p{Z}\p{N}\n]{1,})/ui", + '', + strip_tags($_REQUEST['answer']) + )); + + if ($answer != "") { + sql_query(" + UPDATE `Questions` + SET `AID`='" . sql_escape($user['UID']) . "', `Answer`='" . sql_escape($answer) . "' + WHERE `QID`='" . sql_escape($question_id) . "' + LIMIT 1 + "); + engelsystem_log("Question " . $question[0]['Question'] . " answered: " . $answer); + redirect(page_link_to("admin_questions")); + } else { + return error("Enter an answer!", true); + } + } else { + return error("No question found.", true); + } + break; + case 'delete': + if (isset($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id'])) { + $question_id = $_REQUEST['id']; + } else { + return error("Incomplete call, missing Question ID.", true); + } + + $question = sql_select("SELECT * FROM `Questions` WHERE `QID`='" . sql_escape($question_id) . "' LIMIT 1"); + if (count($question) > 0) { + sql_query("DELETE FROM `Questions` WHERE `QID`='" . sql_escape($question_id) . "' LIMIT 1"); + engelsystem_log("Question deleted: " . $question[0]['Question']); + redirect(page_link_to("admin_questions")); + } else { + return error("No question found.", true); + } + break; } - break; - } } } diff --git a/includes/pages/admin_rooms.php b/includes/pages/admin_rooms.php index 365c2f69..9a596f15 100644 --- a/includes/pages/admin_rooms.php +++ b/includes/pages/admin_rooms.php @@ -11,24 +11,24 @@ function admin_rooms() $rooms = []; foreach ($rooms_source as $room) { $rooms[] = [ - 'name' => Room_name_render($room), - 'from_pentabarf' => $room['FromPentabarf'] == 'Y' ? '✓' : '', - 'public' => $room['show'] == 'Y' ? '✓' : '', - 'actions' => table_buttons([ - button(page_link_to('admin_rooms') . '&show=edit&id=' . $room['RID'], _("edit"), 'btn-xs'), - button(page_link_to('admin_rooms') . '&show=delete&id=' . $room['RID'], _("delete"), 'btn-xs') - ]) - ]; + 'name' => Room_name_render($room), + 'from_pentabarf' => $room['FromPentabarf'] == 'Y' ? '✓' : '', + 'public' => $room['show'] == 'Y' ? '✓' : '', + 'actions' => table_buttons([ + button(page_link_to('admin_rooms') . '&show=edit&id=' . $room['RID'], _("edit"), 'btn-xs'), + button(page_link_to('admin_rooms') . '&show=delete&id=' . $room['RID'], _("delete"), 'btn-xs') + ]) + ]; } $room = null; - + if (isset($_REQUEST['show'])) { $msg = ""; $name = ""; $from_pentabarf = ""; $public = 'Y'; $number = ""; - + $angeltypes_source = sql_select("SELECT * FROM `AngelTypes` ORDER BY `name`"); $angeltypes = []; $angeltypes_count = []; @@ -36,7 +36,7 @@ function admin_rooms() $angeltypes[$angeltype['id']] = $angeltype['name']; $angeltypes_count[$angeltype['id']] = 0; } - + if (test_request_int('id')) { $room = Room($_REQUEST['id']); if ($room === false) { @@ -45,23 +45,23 @@ function admin_rooms() if ($room == null) { redirect(page_link_to('admin_rooms')); } - + $room_id = $_REQUEST['id']; $name = $room['Name']; $from_pentabarf = $room['FromPentabarf']; $public = $room['show']; $number = $room['Number']; - + $needed_angeltypes = sql_select("SELECT * FROM `NeededAngelTypes` WHERE `room_id`='" . sql_escape($room_id) . "'"); foreach ($needed_angeltypes as $needed_angeltype) { $angeltypes_count[$needed_angeltype['angel_type_id']] = $needed_angeltype['count']; } } - + if ($_REQUEST['show'] == 'edit') { if (isset($_REQUEST['submit'])) { $valid = true; - + if (isset($_REQUEST['name']) && strlen(strip_request_item('name')) > 0) { $name = strip_request_item('name'); if (isset($room) && sql_num_query("SELECT * FROM `Room` WHERE `Name`='" . sql_escape($name) . "' AND NOT `RID`=" . sql_escape($room_id)) > 0) { @@ -72,34 +72,37 @@ function admin_rooms() $valid = false; $msg .= error(_("Please enter a name."), true); } - + if (isset($_REQUEST['from_pentabarf'])) { $from_pentabarf = 'Y'; } else { $from_pentabarf = ''; } - + if (isset($_REQUEST['public'])) { $public = 'Y'; } else { $public = ''; } - + if (isset($_REQUEST['number'])) { $number = strip_request_item('number'); } else { $valid = false; } - + foreach ($angeltypes as $angeltype_id => $angeltype) { - if (isset($_REQUEST['angeltype_count_' . $angeltype_id]) && preg_match("/^[0-9]{1,4}$/", $_REQUEST['angeltype_count_' . $angeltype_id])) { + if ( + isset($_REQUEST['angeltype_count_' . $angeltype_id]) + && preg_match("/^[0-9]{1,4}$/", $_REQUEST['angeltype_count_' . $angeltype_id]) + ) { $angeltypes_count[$angeltype_id] = $_REQUEST['angeltype_count_' . $angeltype_id]; } else { $valid = false; $msg .= error(sprintf(_("Please enter needed angels for type %s.", $angeltype)), true); } } - + if ($valid) { if (isset($room_id)) { sql_query("UPDATE `Room` SET `Name`='" . sql_escape($name) . "', `FromPentabarf`='" . sql_escape($from_pentabarf) . "', `show`='" . sql_escape($public) . "', `Number`='" . sql_escape($number) . "' WHERE `RID`='" . sql_escape($room_id) . "' LIMIT 1"); @@ -111,7 +114,7 @@ function admin_rooms() } engelsystem_log("Room created: " . $name . ", pentabarf import: " . $from_pentabarf . ", public: " . $public . ", number: " . $number); } - + NeededAngelTypes_delete_by_room($room_id); $needed_angeltype_info = []; foreach ($angeltypes_count as $angeltype_id => $angeltype_count) { @@ -121,8 +124,11 @@ function admin_rooms() $needed_angeltype_info[] = $angeltype['name'] . ": " . $angeltype_count; } } - - engelsystem_log("Set needed angeltypes of room " . $name . " to: " . join(", ", $needed_angeltype_info)); + + engelsystem_log( + "Set needed angeltypes of room " . $name + . " to: " . join(", ", $needed_angeltype_info) + ); success(_("Room saved.")); redirect(page_link_to("admin_rooms")); } @@ -130,68 +136,68 @@ function admin_rooms() $angeltypes_count_form = []; foreach ($angeltypes as $angeltype_id => $angeltype) { $angeltypes_count_form[] = div('col-lg-4 col-md-6 col-xs-6', [ - form_spinner('angeltype_count_' . $angeltype_id, $angeltype, $angeltypes_count[$angeltype_id]) - ]); + form_spinner('angeltype_count_' . $angeltype_id, $angeltype, $angeltypes_count[$angeltype_id]) + ]); } - + return page_with_title(admin_rooms_title(), [ - buttons([ - button(page_link_to('admin_rooms'), _("back"), 'back') - ]), - $msg, - form([ - div('row', [ - div('col-md-6', [ - form_text('name', _("Name"), $name), - form_checkbox('from_pentabarf', _("Frab import"), $from_pentabarf), - form_checkbox('public', _("Public"), $public), - form_text('number', _("Room number"), $number) - ]), - div('col-md-6', [ - div('row', [ - div('col-md-12', [ - form_info(_("Needed angels:")) - ]), - join($angeltypes_count_form) - ]) - ]) - ]), - form_submit('submit', _("Save")) - ]) - ]); + buttons([ + button(page_link_to('admin_rooms'), _("back"), 'back') + ]), + $msg, + form([ + div('row', [ + div('col-md-6', [ + form_text('name', _("Name"), $name), + form_checkbox('from_pentabarf', _("Frab import"), $from_pentabarf), + form_checkbox('public', _("Public"), $public), + form_text('number', _("Room number"), $number) + ]), + div('col-md-6', [ + div('row', [ + div('col-md-12', [ + form_info(_("Needed angels:")) + ]), + join($angeltypes_count_form) + ]) + ]) + ]), + form_submit('submit', _("Save")) + ]) + ]); } elseif ($_REQUEST['show'] == 'delete') { if (isset($_REQUEST['ack'])) { - if (! Room_delete($room_id)) { + if (!Room_delete($room_id)) { engelsystem_error("Unable to delete room."); } - + engelsystem_log("Room deleted: " . $name); success(sprintf(_("Room %s deleted."), $name)); redirect(page_link_to('admin_rooms')); } - + return page_with_title(admin_rooms_title(), [ - buttons([ - button(page_link_to('admin_rooms'), _("back"), 'back') - ]), - sprintf(_("Do you want to delete room %s?"), $name), - buttons([ - button(page_link_to('admin_rooms') . '&show=delete&id=' . $room_id . '&ack', _("Delete"), 'delete') - ]) - ]); + buttons([ + button(page_link_to('admin_rooms'), _("back"), 'back') + ]), + sprintf(_("Do you want to delete room %s?"), $name), + buttons([ + button(page_link_to('admin_rooms') . '&show=delete&id=' . $room_id . '&ack', _("Delete"), 'delete') + ]) + ]); } } - + return page_with_title(admin_rooms_title(), [ - buttons([ - button(page_link_to('admin_rooms') . '&show=edit', _("add")) - ]), - msg(), - table([ - 'name' => _("Name"), - 'from_pentabarf' => _("Frab import"), - 'public' => _("Public"), - 'actions' => "" - ], $rooms) - ]); + buttons([ + button(page_link_to('admin_rooms') . '&show=edit', _("add")) + ]), + msg(), + table([ + 'name' => _("Name"), + 'from_pentabarf' => _("Frab import"), + 'public' => _("Public"), + 'actions' => "" + ], $rooms) + ]); } diff --git a/includes/pages/admin_shifts.php b/includes/pages/admin_shifts.php index 79c9874a..b2a67786 100644 --- a/includes/pages/admin_shifts.php +++ b/includes/pages/admin_shifts.php @@ -9,7 +9,7 @@ function admin_shifts_title() function admin_shifts() { $valid = true; - + $rid = 0; $start = parse_date("Y-m-d H:i", date("Y-m-d") . " 00:00"); $end = $start; @@ -19,23 +19,23 @@ function admin_shifts() $change_hours = []; $title = ""; $shifttype_id = null; - - // Locations laden (auch unsichtbare - fuer Erzengel ist das ok) - $rooms = sql_select("SELECT * FROM `Room` ORDER BY `Name`"); + + // Locations laden (auch unsichtbare - fuer Erzengel ist das ok) + $rooms = sql_select("SELECT * FROM `Room` ORDER BY `Name`"); $room_array = []; foreach ($rooms as $room) { $room_array[$room['RID']] = $room['Name']; } - - // Engeltypen laden - $types = sql_select("SELECT * FROM `AngelTypes` ORDER BY `name`"); + + // Engeltypen laden + $types = sql_select("SELECT * FROM `AngelTypes` ORDER BY `name`"); $needed_angel_types = []; foreach ($types as $type) { $needed_angel_types[$type['id']] = 0; } - - // Load shift types - $shifttypes_source = ShiftTypes(); + + // Load shift types + $shifttypes_source = ShiftTypes(); if ($shifttypes_source === false) { engelsystem_error('Unable to load shift types.'); } @@ -43,7 +43,7 @@ function admin_shifts() foreach ($shifttypes_source as $shifttype) { $shifttypes[$shifttype['id']] = $shifttype['name']; } - + if (isset($_REQUEST['preview']) || isset($_REQUEST['back'])) { if (isset($_REQUEST['shifttype_id'])) { $shifttype = ShiftType($_REQUEST['shifttype_id']); @@ -60,38 +60,42 @@ function admin_shifts() $valid = false; error(_('Please select a shift type.')); } - - // 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_array[$_REQUEST['rid']])) { - $rid = $_REQUEST['rid']; - } else { - $valid = false; - $rid = $rooms[0]['RID']; - error(_('Please select a location.')); - } - + + // 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_array[$_REQUEST['rid']]) + ) { + $rid = $_REQUEST['rid']; + } else { + $valid = false; + $rid = $rooms[0]['RID']; + error(_('Please select a location.')); + } + if (isset($_REQUEST['start']) && $tmp = parse_date("Y-m-d H:i", $_REQUEST['start'])) { $start = $tmp; } else { $valid = false; error(_('Please select a start time.')); } - + if (isset($_REQUEST['end']) && $tmp = parse_date("Y-m-d H:i", $_REQUEST['end'])) { $end = $tmp; } else { $valid = false; error(_('Please select an end time.')); } - + if ($start >= $end) { $valid = false; error(_('The shifts end has to be after its start.')); } - + if (isset($_REQUEST['mode'])) { if ($_REQUEST['mode'] == 'single') { $mode = 'single'; @@ -104,7 +108,10 @@ function admin_shifts() error(_('Please enter a shift duration in minutes.')); } } elseif ($_REQUEST['mode'] == 'variable') { - if (isset($_REQUEST['change_hours']) && preg_match("/^([0-9]{2}(,|$))/", trim(str_replace(" ", "", $_REQUEST['change_hours'])))) { + if ( + isset($_REQUEST['change_hours']) + && preg_match("/^([0-9]{2}(,|$))/", trim(str_replace(" ", "", $_REQUEST['change_hours']))) + ) { $mode = 'variable'; $change_hours = array_map('trim', explode(",", $_REQUEST['change_hours'])); } else { @@ -116,14 +123,17 @@ function admin_shifts() $valid = false; error(_('Please select a mode.')); } - + if (isset($_REQUEST['angelmode'])) { if ($_REQUEST['angelmode'] == 'location') { $angelmode = 'location'; } elseif ($_REQUEST['angelmode'] == 'manually') { $angelmode = 'manually'; foreach ($types as $type) { - if (isset($_REQUEST['type_' . $type['id']]) && preg_match("/^[0-9]+$/", trim($_REQUEST['type_' . $type['id']]))) { + if ( + isset($_REQUEST['type_' . $type['id']]) + && preg_match("/^[0-9]+$/", trim($_REQUEST['type_' . $type['id']])) + ) { $needed_angel_types[$type['id']] = trim($_REQUEST['type_' . $type['id']]); } else { $valid = false; @@ -142,144 +152,152 @@ function admin_shifts() $valid = false; error(_('Please select needed angels.')); } - - // Beim Zurück-Knopf das Formular zeigen - if (isset($_REQUEST['back'])) { - $valid = false; - } - - // Alle Eingaben in Ordnung - if ($valid) { - if ($angelmode == 'location') { - $needed_angel_types = []; - $needed_angel_types_location = sql_select("SELECT * FROM `NeededAngelTypes` WHERE `room_id`='" . sql_escape($rid) . "'"); - foreach ($needed_angel_types_location as $type) { - $needed_angel_types[$type['angel_type_id']] = $type['count']; - } + + // Beim Zurück-Knopf das Formular zeigen + if (isset($_REQUEST['back'])) { + $valid = false; } - $shifts = []; - if ($mode == 'single') { - $shifts[] = [ - 'start' => $start, - 'end' => $end, - 'RID' => $rid, - 'title' => $title, - 'shifttype_id' => $shifttype_id - ]; - } elseif ($mode == 'multi') { - $shift_start = $start; - do { - $shift_end = $shift_start + $length * 60; - - if ($shift_end > $end) { - $shift_end = $end; - } - if ($shift_start >= $shift_end) { - break; + + // Alle Eingaben in Ordnung + if ($valid) { + if ($angelmode == 'location') { + $needed_angel_types = []; + $needed_angel_types_location = sql_select("SELECT * FROM `NeededAngelTypes` WHERE `room_id`='" . sql_escape($rid) . "'"); + foreach ($needed_angel_types_location as $type) { + $needed_angel_types[$type['angel_type_id']] = $type['count']; } - - $shifts[] = [ - 'start' => $shift_start, - 'end' => $shift_end, - 'RID' => $rid, - 'title' => $title, - 'shifttype_id' => $shifttype_id - ]; - - $shift_start = $shift_end; - } while ($shift_end < $end); - } elseif ($mode == 'variable') { - rsort($change_hours); - $day = parse_date("Y-m-d H:i", date("Y-m-d", $start) . " 00:00"); - $change_index = 0; - // Ersten/nächsten passenden Schichtwechsel suchen - foreach ($change_hours as $i => $change_hour) { - if ($start < $day + $change_hour * 60 * 60) { - $change_index = $i; - } elseif ($start == $day + $change_hour * 60 * 60) { - // Start trifft Schichtwechsel - $change_index = ($i + count($change_hours) - 1) % count($change_hours); - break; - } else { - break; } - } - - $shift_start = $start; - do { - $day = parse_date("Y-m-d H:i", date("Y-m-d", $shift_start) . " 00:00"); - $shift_end = $day + $change_hours[$change_index] * 60 * 60; - - if ($shift_end > $end) { - $shift_end = $end; - } - if ($shift_start >= $shift_end) { - $shift_end += 24 * 60 * 60; - } - + $shifts = []; + if ($mode == 'single') { $shifts[] = [ - 'start' => $shift_start, - 'end' => $shift_end, - 'RID' => $rid, - 'title' => $title, - 'shifttype_id' => $shifttype_id - ]; - - $shift_start = $shift_end; - $change_index = ($change_index + count($change_hours) - 1) % count($change_hours); - } while ($shift_end < $end); - } - - $shifts_table = []; - foreach ($shifts as $shift) { - $shifts_table_entry = [ - 'timeslot' => ' ' . date("Y-m-d H:i", $shift['start']) . ' - ' . date("H:i", $shift['end']) . '
' . Room_name_render(Room($shift['RID'])), - 'title' => ShiftType_name_render(ShiftType($shifttype_id)) . ($shift['title'] ? '
' . $shift['title'] : ''), - 'needed_angels' => '' - ]; - foreach ($types as $type) { - if (isset($needed_angel_types[$type['id']]) && $needed_angel_types[$type['id']] > 0) { - $shifts_table_entry['needed_angels'] .= '' . AngelType_name_render($type) . ': ' . $needed_angel_types[$type['id']] . '
'; + 'start' => $start, + 'end' => $end, + 'RID' => $rid, + 'title' => $title, + 'shifttype_id' => $shifttype_id + ]; + } elseif ($mode == 'multi') { + $shift_start = $start; + do { + $shift_end = $shift_start + $length * 60; + + if ($shift_end > $end) { + $shift_end = $end; + } + if ($shift_start >= $shift_end) { + break; + } + + $shifts[] = [ + 'start' => $shift_start, + 'end' => $shift_end, + 'RID' => $rid, + 'title' => $title, + 'shifttype_id' => $shifttype_id + ]; + + $shift_start = $shift_end; + } while ($shift_end < $end); + } elseif ($mode == 'variable') { + rsort($change_hours); + $day = parse_date("Y-m-d H:i", date("Y-m-d", $start) . " 00:00"); + $change_index = 0; + // Ersten/nächsten passenden Schichtwechsel suchen + foreach ($change_hours as $i => $change_hour) { + if ($start < $day + $change_hour * 60 * 60) { + $change_index = $i; + } elseif ($start == $day + $change_hour * 60 * 60) { + // Start trifft Schichtwechsel + $change_index = ($i + count($change_hours) - 1) % count($change_hours); + break; + } else { + break; + } } + + $shift_start = $start; + do { + $day = parse_date("Y-m-d H:i", date("Y-m-d", $shift_start) . " 00:00"); + $shift_end = $day + $change_hours[$change_index] * 60 * 60; + + if ($shift_end > $end) { + $shift_end = $end; + } + if ($shift_start >= $shift_end) { + $shift_end += 24 * 60 * 60; + } + + $shifts[] = [ + 'start' => $shift_start, + 'end' => $shift_end, + 'RID' => $rid, + 'title' => $title, + 'shifttype_id' => $shifttype_id + ]; + + $shift_start = $shift_end; + $change_index = ($change_index + count($change_hours) - 1) % count($change_hours); + } while ($shift_end < $end); } - $shifts_table[] = $shifts_table_entry; - } - - // Fürs Anlegen zwischenspeichern: - $_SESSION['admin_shifts_shifts'] = $shifts; - $_SESSION['admin_shifts_types'] = $needed_angel_types; - - $hidden_types = ""; - foreach ($needed_angel_types as $type_id => $count) { - $hidden_types .= form_hidden('type_' . $type_id, $count); + + $shifts_table = []; + foreach ($shifts as $shift) { + $shifts_table_entry = [ + 'timeslot' => + ' ' + . date("Y-m-d H:i", $shift['start']) + . ' - ' + . date("H:i", $shift['end']) + . '
' + . Room_name_render(Room($shift['RID'])), + 'title' => + ShiftType_name_render(ShiftType($shifttype_id)) + . ($shift['title'] ? '
' . $shift['title'] : ''), + 'needed_angels' => '' + ]; + foreach ($types as $type) { + if (isset($needed_angel_types[$type['id']]) && $needed_angel_types[$type['id']] > 0) { + $shifts_table_entry['needed_angels'] .= '' . AngelType_name_render($type) . ': ' . $needed_angel_types[$type['id']] . '
'; + } + } + $shifts_table[] = $shifts_table_entry; + } + + // Fürs Anlegen zwischenspeichern: + $_SESSION['admin_shifts_shifts'] = $shifts; + $_SESSION['admin_shifts_types'] = $needed_angel_types; + + $hidden_types = ""; + foreach ($needed_angel_types as $type_id => $count) { + $hidden_types .= form_hidden('type_' . $type_id, $count); + } + return page_with_title(_("Preview"), [ + form([ + $hidden_types, + form_hidden('shifttype_id', $shifttype_id), + form_hidden('title', $title), + form_hidden('rid', $rid), + form_hidden('start', date("Y-m-d H:i", $start)), + form_hidden('end', date("Y-m-d H:i", $end)), + form_hidden('mode', $mode), + form_hidden('length', $length), + form_hidden('change_hours', implode(', ', $change_hours)), + form_hidden('angelmode', $angelmode), + form_submit('back', _("back")), + table([ + 'timeslot' => _('Time and location'), + 'title' => _('Type and title'), + 'needed_angels' => _('Needed angels') + ], $shifts_table), + form_submit('submit', _("Save")) + ]) + ]); } - return page_with_title(_("Preview"), [ - form([ - $hidden_types, - form_hidden('shifttype_id', $shifttype_id), - form_hidden('title', $title), - form_hidden('rid', $rid), - form_hidden('start', date("Y-m-d H:i", $start)), - form_hidden('end', date("Y-m-d H:i", $end)), - form_hidden('mode', $mode), - form_hidden('length', $length), - form_hidden('change_hours', implode(', ', $change_hours)), - form_hidden('angelmode', $angelmode), - form_submit('back', _("back")), - table([ - 'timeslot' => _('Time and location'), - 'title' => _('Type and title'), - 'needed_angels' => _('Needed angels') - ], $shifts_table), - form_submit('submit', _("Save")) - ]) - ]); - } } elseif (isset($_REQUEST['submit'])) { - if (! is_array($_SESSION['admin_shifts_shifts']) || ! is_array($_SESSION['admin_shifts_types'])) { + if (!is_array($_SESSION['admin_shifts_shifts']) || !is_array($_SESSION['admin_shifts_types'])) { redirect(page_link_to('admin_shifts')); } - + foreach ($_SESSION['admin_shifts_shifts'] as $shift) { $shift['URL'] = null; $shift['PSID'] = null; @@ -287,8 +305,13 @@ function admin_shifts() if ($shift_id === false) { engelsystem_error('Unable to create shift.'); } - - engelsystem_log("Shift created: " . $shifttypes[$shift['shifttype_id']] . " with title " . $shift['title'] . " from " . date("Y-m-d H:i", $shift['start']) . " to " . date("Y-m-d H:i", $shift['end'])); + + engelsystem_log( + "Shift created: " . $shifttypes[$shift['shifttype_id']] + . " with title " . $shift['title'] + . " from " . date("Y-m-d H:i", $shift['start']) + . " to " . date("Y-m-d H:i", $shift['end']) + ); $needed_angel_types_info = []; foreach ($_SESSION['admin_shifts_types'] as $type_id => $count) { $angel_type_source = sql_select("SELECT * FROM `AngelTypes` WHERE `id`='" . sql_escape($type_id) . "' LIMIT 1"); @@ -298,7 +321,7 @@ function admin_shifts() } } } - + engelsystem_log("Shift needs following angel types: " . join(", ", $needed_angel_types_info)); success("Schichten angelegt."); redirect(page_link_to('admin_shifts')); @@ -306,42 +329,61 @@ function admin_shifts() unset($_SESSION['admin_shifts_shifts']); unset($_SESSION['admin_shifts_types']); } - - if (! isset($_REQUEST['rid'])) { + + if (!isset($_REQUEST['rid'])) { $_REQUEST['rid'] = null; } $angel_types = ""; foreach ($types as $type) { - $angel_types .= '
' . form_spinner('type_' . $type['id'], $type['name'], $needed_angel_types[$type['id']]) . '
'; + $angel_types .= '
' . form_spinner( + 'type_' . $type['id'], + $type['name'], + $needed_angel_types[$type['id']] + ) + . '
'; } - + return page_with_title(admin_shifts_title(), [ - msg(), - form([ - form_select('shifttype_id', _('Shifttype'), $shifttypes, $shifttype_id), - form_text('title', _("Title"), $title), - form_select('rid', _("Room"), $room_array, $_REQUEST['rid']), - div('row', [ - div('col-md-6', [ - form_text('start', _("Start"), date("Y-m-d H:i", $start)), - form_text('end', _("End"), date("Y-m-d H:i", $end)), - form_info(_("Mode"), ''), - form_radio('mode', _("Create one shift"), $mode == 'single', 'single'), - form_radio('mode', _("Create multiple shifts"), $mode == 'multi', 'multi'), - form_text('length', _("Length"), ! empty($_REQUEST['length']) ? $_REQUEST['length'] : '120'), - form_radio('mode', _("Create multiple shifts with variable length"), $mode == 'variable', 'variable'), - form_text('change_hours', _("Shift change hours"), ! empty($_REQUEST['change_hours']) ? $_REQUEST['change_hours'] : '00, 04, 08, 10, 12, 14, 16, 18, 20, 22') - ]), - div('col-md-6', [ - form_info(_("Needed angels"), ''), - form_radio('angelmode', _("Take needed angels from room settings"), $angelmode == 'location', 'location'), - form_radio('angelmode', _("The following angels are needed"), $angelmode == 'manually', 'manually'), - div('row', [ - $angel_types - ]) - ]) - ]), - form_submit('preview', _("Preview")) - ]) - ]); + msg(), + form([ + form_select('shifttype_id', _('Shifttype'), $shifttypes, $shifttype_id), + form_text('title', _("Title"), $title), + form_select('rid', _("Room"), $room_array, $_REQUEST['rid']), + div('row', [ + div('col-md-6', [ + form_text('start', _("Start"), date("Y-m-d H:i", $start)), + form_text('end', _("End"), date("Y-m-d H:i", $end)), + form_info(_("Mode"), ''), + form_radio('mode', _("Create one shift"), $mode == 'single', 'single'), + form_radio('mode', _("Create multiple shifts"), $mode == 'multi', 'multi'), + form_text('length', _("Length"), !empty($_REQUEST['length']) ? $_REQUEST['length'] : '120'), + form_radio( + 'mode', + _("Create multiple shifts with variable length"), + $mode == 'variable', + 'variable' + ), + form_text( + 'change_hours', + _("Shift change hours"), + !empty($_REQUEST['change_hours']) ? $_REQUEST['change_hours'] : '00, 04, 08, 10, 12, 14, 16, 18, 20, 22' + ) + ]), + div('col-md-6', [ + form_info(_("Needed angels"), ''), + form_radio( + 'angelmode', + _("Take needed angels from room settings"), + $angelmode == 'location', + 'location' + ), + form_radio('angelmode', _("The following angels are needed"), $angelmode == 'manually', 'manually'), + div('row', [ + $angel_types + ]) + ]) + ]), + form_submit('preview', _("Preview")) + ]) + ]); } diff --git a/includes/pages/admin_user.php b/includes/pages/admin_user.php index e84e3089..12d92720 100644 --- a/includes/pages/admin_user.php +++ b/includes/pages/admin_user.php @@ -8,23 +8,23 @@ function admin_user_title() function admin_user() { global $user, $privileges, $tshirt_sizes, $privileges; - + $html = ''; - - if (! isset($_REQUEST['id'])) { + + if (!isset($_REQUEST['id'])) { redirect(users_link()); } - + $user_id = $_REQUEST['id']; - if (! isset($_REQUEST['action'])) { + if (!isset($_REQUEST['action'])) { $user_source = User($user_id); if ($user_source == null) { error(_('This user does not exist.')); redirect(users_link()); } - + $html .= "Hallo,
" . "hier kannst du den Eintrag ändern. Unter dem Punkt 'Gekommen' " . "wird der Engel als anwesend markiert, ein Ja bei Aktiv bedeutet, " . "dass der Engel aktiv war und damit ein Anspruch auf ein T-Shirt hat. " . "Wenn T-Shirt ein 'Ja' enthält, bedeutet dies, dass der Engel " . "bereits sein T-Shirt erhalten hat.

\n"; - + $html .= "
\n"; $html .= "\n"; $html .= "\n"; @@ -42,132 +42,135 @@ function admin_user() $html .= " \n"; } $html .= " \n"; - $html .= " \n"; - + $html .= " \n"; + $options = [ - '1' => _("Yes"), - '0' => _("No") - ]; - - // Gekommen? - $html .= " \n"; - - // Aktiv? - $html .= " \n"; - - // Aktiv erzwingen - if (in_array('admin_active', $privileges)) { - $html .= " \n"; - } - - // T-Shirt bekommen? - $html .= " \n"; + } + + // T-Shirt bekommen? + $html .= " \n"; - + $html .= " \n"; - + $html .= "
email" . "
jabber" . "
Size" . html_select_key('size', 'eSize', $tshirt_sizes, $user_source['Size']) . "
Size" + . html_select_key('size', 'eSize', $tshirt_sizes, $user_source['Size']) + . "
Gekommen\n"; + '1' => _("Yes"), + '0' => _("No") + ]; + + // Gekommen? + $html .= "
Gekommen\n"; $html .= html_options('eGekommen', $options, $user_source['Gekommen']) . "
Aktiv\n"; + + // Aktiv? + $html .= "
Aktiv\n"; $html .= html_options('eAktiv', $options, $user_source['Aktiv']) . "
" . _("Force active") . "\n"; - $html .= html_options('force_active', $options, $user_source['force_active']) . "
T-Shirt\n"; + + // Aktiv erzwingen + if (in_array('admin_active', $privileges)) { + $html .= "
" . _("Force active") . "\n"; + $html .= html_options('force_active', $options, $user_source['force_active']) . "
T-Shirt\n"; $html .= html_options('eTshirt', $options, $user_source['Tshirt']) . "
Hometown" . "
\n"; - + $html .= "\n"; $html .= "\n
\n"; $html .= "\n"; $html .= "
"; - + $html .= "
"; - + $html .= form_info('', _('Please visit the angeltypes page or the users profile to manage users angeltypes.')); - + $html .= "Hier kannst Du das Passwort dieses Engels neu setzen:
\n"; $html .= "\n"; $html .= " \n"; $html .= " \n"; - + $html .= "
Passwort" . "
Wiederholung" . "
"; $html .= "\n"; $html .= "
"; - + $html .= "
"; - + $my_highest_group = sql_select("SELECT * FROM `UserGroups` WHERE `uid`='" . sql_escape($user['UID']) . "' ORDER BY `group_id` LIMIT 1"); if (count($my_highest_group) > 0) { $my_highest_group = $my_highest_group[0]['group_id']; } - + $his_highest_group = sql_select("SELECT * FROM `UserGroups` WHERE `uid`='" . sql_escape($user_id) . "' ORDER BY `group_id` LIMIT 1"); if (count($his_highest_group) > 0) { $his_highest_group = $his_highest_group[0]['group_id']; } - + if ($user_id != $user['UID'] && $my_highest_group <= $his_highest_group) { $html .= "Hier kannst Du die Benutzergruppen des Engels festlegen:
\n"; $html .= ''; - + $groups = sql_select("SELECT * FROM `Groups` LEFT OUTER JOIN `UserGroups` ON (`UserGroups`.`group_id` = `Groups`.`UID` AND `UserGroups`.`uid` = '" . sql_escape($user_id) . "') WHERE `Groups`.`UID` >= '" . sql_escape($my_highest_group) . "' ORDER BY `Groups`.`Name`"); foreach ($groups as $group) { $html .= ''; } - + $html .= '
' . $group['Name'] . '
'; - + $html .= "\n"; $html .= "
"; - + $html .= "
"; } - + $html .= buttons([ - button(user_delete_link($user_source), glyph('lock') . _("delete"), 'btn-danger') - ]); - + button(user_delete_link($user_source), glyph('lock') . _("delete"), 'btn-danger') + ]); + $html .= "
"; } else { switch ($_REQUEST['action']) { - case 'save_groups': - if ($user_id != $user['UID']) { - $my_highest_group = sql_select("SELECT * FROM `UserGroups` WHERE `uid`='" . sql_escape($user['UID']) . "' ORDER BY `group_id`"); - $his_highest_group = sql_select("SELECT * FROM `UserGroups` WHERE `uid`='" . sql_escape($user_id) . "' ORDER BY `group_id`"); - - if (count($my_highest_group) > 0 && (count($his_highest_group) == 0 || ($my_highest_group[0]['group_id'] <= $his_highest_group[0]['group_id']))) { - $groups_source = sql_select("SELECT * FROM `Groups` LEFT OUTER JOIN `UserGroups` ON (`UserGroups`.`group_id` = `Groups`.`UID` AND `UserGroups`.`uid` = '" . sql_escape($user_id) . "') WHERE `Groups`.`UID` >= '" . sql_escape($my_highest_group[0]['group_id']) . "' ORDER BY `Groups`.`Name`"); - $groups = []; - $grouplist = []; - foreach ($groups_source as $group) { - $groups[$group['UID']] = $group; - $grouplist[] = $group['UID']; - } - - if (! is_array($_REQUEST['groups'])) { - $_REQUEST['groups'] = []; - } - - sql_query("DELETE FROM `UserGroups` WHERE `uid`='" . sql_escape($user_id) . "'"); - $user_groups_info = []; - foreach ($_REQUEST['groups'] as $group) { - if (in_array($group, $grouplist)) { - sql_query("INSERT INTO `UserGroups` SET `uid`='" . sql_escape($user_id) . "', `group_id`='" . sql_escape($group) . "'"); - $user_groups_info[] = $groups[$group]['Name']; + case 'save_groups': + if ($user_id != $user['UID']) { + $my_highest_group = sql_select("SELECT * FROM `UserGroups` WHERE `uid`='" . sql_escape($user['UID']) . "' ORDER BY `group_id`"); + $his_highest_group = sql_select("SELECT * FROM `UserGroups` WHERE `uid`='" . sql_escape($user_id) . "' ORDER BY `group_id`"); + + if (count($my_highest_group) > 0 && (count($his_highest_group) == 0 || ($my_highest_group[0]['group_id'] <= $his_highest_group[0]['group_id']))) { + $groups_source = sql_select("SELECT * FROM `Groups` LEFT OUTER JOIN `UserGroups` ON (`UserGroups`.`group_id` = `Groups`.`UID` AND `UserGroups`.`uid` = '" . sql_escape($user_id) . "') WHERE `Groups`.`UID` >= '" . sql_escape($my_highest_group[0]['group_id']) . "' ORDER BY `Groups`.`Name`"); + $groups = []; + $grouplist = []; + foreach ($groups_source as $group) { + $groups[$group['UID']] = $group; + $grouplist[] = $group['UID']; + } + + if (!is_array($_REQUEST['groups'])) { + $_REQUEST['groups'] = []; + } + + sql_query("DELETE FROM `UserGroups` WHERE `uid`='" . sql_escape($user_id) . "'"); + $user_groups_info = []; + foreach ($_REQUEST['groups'] as $group) { + if (in_array($group, $grouplist)) { + sql_query("INSERT INTO `UserGroups` SET `uid`='" . sql_escape($user_id) . "', `group_id`='" . sql_escape($group) . "'"); + $user_groups_info[] = $groups[$group]['Name']; + } + } + $user_source = User($user_id); + engelsystem_log("Set groups of " . User_Nick_render($user_source) . " to: " . join(", ", + $user_groups_info)); + $html .= success("Benutzergruppen gespeichert.", true); + } else { + $html .= error("Du kannst keine Engel mit mehr Rechten bearbeiten.", true); } + } else { + $html .= error("Du kannst Deine eigenen Rechte nicht bearbeiten.", true); } - $user_source = User($user_id); - engelsystem_log("Set groups of " . User_Nick_render($user_source) . " to: " . join(", ", $user_groups_info)); - $html .= success("Benutzergruppen gespeichert.", true); - } else { - $html .= error("Du kannst keine Engel mit mehr Rechten bearbeiten.", true); - } - } else { - $html .= error("Du kannst Deine eigenen Rechte nicht bearbeiten.", true); - } - break; - - case 'save': - $force_active = $user['force_active']; - if (in_array('admin_active', $privileges)) { - $force_active = $_REQUEST['force_active']; - } - $SQL = "UPDATE `User` SET + break; + + case 'save': + $force_active = $user['force_active']; + if (in_array('admin_active', $privileges)) { + $force_active = $_REQUEST['force_active']; + } + $SQL = "UPDATE `User` SET `Nick` = '" . sql_escape($_POST["eNick"]) . "', `Name` = '" . sql_escape($_POST["eName"]) . "', `Vorname` = '" . sql_escape($_POST["eVorname"]) . "', @@ -185,25 +188,25 @@ function admin_user() `Hometown` = '" . sql_escape($_POST["Hometown"]) . "' WHERE `UID` = '" . sql_escape($user_id) . "' LIMIT 1"; - sql_query($SQL); - engelsystem_log("Updated user: " . $_POST["eNick"] . ", " . $_POST["eSize"] . ", arrived: " . $_POST["eGekommen"] . ", active: " . $_POST["eAktiv"] . ", tshirt: " . $_POST["eTshirt"]); - $html .= success("Änderung wurde gespeichert...\n", true); - break; - - case 'change_pw': - if ($_REQUEST['new_pw'] != "" && $_REQUEST['new_pw'] == $_REQUEST['new_pw2']) { - set_password($user_id, $_REQUEST['new_pw']); - $user_source = User($user_id); - engelsystem_log("Set new password for " . User_Nick_render($user_source)); - $html .= success("Passwort neu gesetzt.", true); - } else { - $html .= error("Die Eingaben müssen übereinstimmen und dürfen nicht leer sein!", true); + sql_query($SQL); + engelsystem_log("Updated user: " . $_POST["eNick"] . ", " . $_POST["eSize"] . ", arrived: " . $_POST["eGekommen"] . ", active: " . $_POST["eAktiv"] . ", tshirt: " . $_POST["eTshirt"]); + $html .= success("Änderung wurde gespeichert...\n", true); + break; + + case 'change_pw': + if ($_REQUEST['new_pw'] != "" && $_REQUEST['new_pw'] == $_REQUEST['new_pw2']) { + set_password($user_id, $_REQUEST['new_pw']); + $user_source = User($user_id); + engelsystem_log("Set new password for " . User_Nick_render($user_source)); + $html .= success("Passwort neu gesetzt.", true); + } else { + $html .= error("Die Eingaben müssen übereinstimmen und dürfen nicht leer sein!", true); + } + break; } - break; - } } - + return page_with_title(_("Edit user"), [ - $html - ]); + $html + ]); } diff --git a/includes/pages/guest_login.php b/includes/pages/guest_login.php index 293fb891..482b7670 100644 --- a/includes/pages/guest_login.php +++ b/includes/pages/guest_login.php @@ -19,9 +19,9 @@ function logout_title() function guest_register() { global $tshirt_sizes, $enable_tshirt_size, $default_theme, $user, $min_password_length; - + $event_config = EventConfig(); - + $msg = ""; $nick = ""; $lastname = ""; @@ -40,19 +40,19 @@ function guest_register() $password_hash = ""; $selected_angel_types = []; $planned_arrival_date = null; - + $angel_types_source = AngelTypes(); $angel_types = []; foreach ($angel_types_source as $angel_type) { $angel_types[$angel_type['id']] = $angel_type['name'] . ($angel_type['restricted'] ? " (restricted)" : ""); - if (! $angel_type['restricted']) { + if (!$angel_type['restricted']) { $selected_angel_types[] = $angel_type['id']; } } - + if (isset($_REQUEST['submit'])) { $valid = true; - + if (isset($_REQUEST['nick']) && strlen(User_validate_Nick($_REQUEST['nick'])) > 1) { $nick = User_validate_Nick($_REQUEST['nick']); if (sql_num_query("SELECT * FROM `User` WHERE `Nick`='" . sql_escape($nick) . "' LIMIT 1") > 0) { @@ -61,12 +61,15 @@ function guest_register() } } else { $valid = false; - $msg .= error(sprintf(_("Your nick "%s" is too short (min. 2 characters)."), User_validate_Nick($_REQUEST['nick'])), true); + $msg .= error(sprintf( + _("Your nick "%s" is too short (min. 2 characters)."), + User_validate_Nick($_REQUEST['nick']) + ), true); } - + if (isset($_REQUEST['mail']) && strlen(strip_request_item('mail')) > 0) { $mail = strip_request_item('mail'); - if (! check_email($mail)) { + if (!check_email($mail)) { $valid = false; $msg .= error(_("E-mail address is not correct."), true); } @@ -74,23 +77,23 @@ function guest_register() $valid = false; $msg .= error(_("Please enter your e-mail."), true); } - + if (isset($_REQUEST['email_shiftinfo'])) { $email_shiftinfo = true; } - + if (isset($_REQUEST['email_by_human_allowed'])) { $email_by_human_allowed = true; } - + if (isset($_REQUEST['jabber']) && strlen(strip_request_item('jabber')) > 0) { $jabber = strip_request_item('jabber'); - if (! check_email($jabber)) { + if (!check_email($jabber)) { $valid = false; $msg .= error(_("Please check your jabber account information."), true); } } - + if ($enable_tshirt_size) { if (isset($_REQUEST['tshirt_size']) && isset($tshirt_sizes[$_REQUEST['tshirt_size']]) && $_REQUEST['tshirt_size'] != '') { $tshirt_size = $_REQUEST['tshirt_size']; @@ -99,7 +102,7 @@ function guest_register() $msg .= error(_("Please select your shirt size."), true); } } - + if (isset($_REQUEST['password']) && strlen($_REQUEST['password']) >= $min_password_length) { if ($_REQUEST['password'] != $_REQUEST['password2']) { $valid = false; @@ -107,30 +110,33 @@ function guest_register() } } else { $valid = false; - $msg .= error(sprintf(_("Your password is too short (please use at least %s characters)."), $min_password_length), true); + $msg .= error(sprintf( + _("Your password is too short (please use at least %s characters)."), + $min_password_length + ), true); } - + if (isset($_REQUEST['planned_arrival_date'])) { $tmp = parse_date("Y-m-d H:i", $_REQUEST['planned_arrival_date'] . " 00:00"); $result = User_validate_planned_arrival_date($tmp); $planned_arrival_date = $result->getValue(); - if (! $result->isValid()) { + if (!$result->isValid()) { $valid = false; error(_("Please enter your planned date of arrival. It should be after the buildup start date and before teardown end date.")); } } - + $selected_angel_types = []; foreach (array_keys($angel_types) as $angel_type_id) { if (isset($_REQUEST['angel_types_' . $angel_type_id])) { $selected_angel_types[] = $angel_type_id; } } - - // Trivia - if (isset($_REQUEST['lastname'])) { - $lastname = strip_request_item('lastname'); - } + + // Trivia + if (isset($_REQUEST['lastname'])) { + $lastname = strip_request_item('lastname'); + } if (isset($_REQUEST['prename'])) { $prename = strip_request_item('prename'); } @@ -152,7 +158,7 @@ function guest_register() if (isset($_REQUEST['comment'])) { $comment = strip_request_item_nl('comment'); } - + if ($valid) { sql_query(" INSERT INTO `User` SET @@ -176,36 +182,39 @@ function guest_register() `Sprache`='" . sql_escape($_SESSION["locale"]) . "', `arrival_date`=NULL, `planned_arrival_date`='" . sql_escape($planned_arrival_date) . "'"); - - // Assign user-group and set password - $user_id = sql_id(); + + // Assign user-group and set password + $user_id = sql_id(); sql_query("INSERT INTO `UserGroups` SET `uid`='" . sql_escape($user_id) . "', `group_id`=-2"); set_password($user_id, $_REQUEST['password']); - - // Assign angel-types - $user_angel_types_info = []; + + // Assign angel-types + $user_angel_types_info = []; foreach ($selected_angel_types as $selected_angel_type_id) { sql_query("INSERT INTO `UserAngelTypes` SET `user_id`='" . sql_escape($user_id) . "', `angeltype_id`='" . sql_escape($selected_angel_type_id) . "'"); $user_angel_types_info[] = $angel_types[$selected_angel_type_id]; } - - engelsystem_log("User " . User_Nick_render(User($user_id)) . " signed up as: " . join(", ", $user_angel_types_info)); + + engelsystem_log( + "User " . User_Nick_render(User($user_id)) + . " signed up as: " . join(", ", $user_angel_types_info) + ); success(_("Angel registration successful!")); - - // User is already logged in - that means a supporter has registered an angel. Return to register page. - if (isset($user)) { - redirect(page_link_to('register')); - } - - // If a welcome message is present, display registration success page. - if ($event_config != null && $event_config['event_welcome_msg'] != null) { - return User_registration_success_view($event_config['event_welcome_msg']); - } - + + // User is already logged in - that means a supporter has registered an angel. Return to register page. + if (isset($user)) { + redirect(page_link_to('register')); + } + + // If a welcome message is present, display registration success page. + if ($event_config != null && $event_config['event_welcome_msg'] != null) { + return User_registration_success_view($event_config['event_welcome_msg']); + } + redirect('?'); } } - + $buildup_start_date = time(); $teardown_end_date = null; if ($event_config != null) { @@ -216,79 +225,105 @@ function guest_register() $teardown_end_date = $event_config['teardown_end_date']; } } - + return page_with_title(register_title(), [ - _("By completing this form you're registering as a Chaos-Angel. This script will create you an account in the angel task scheduler."), - $msg, - msg(), - form([ - div('row', [ - div('col-md-6', [ - div('row', [ - div('col-sm-4', [ - form_text('nick', _("Nick") . ' ' . entry_required(), $nick) - ]), - div('col-sm-8', [ - form_email('mail', _("E-Mail") . ' ' . entry_required(), $mail), - form_checkbox('email_shiftinfo', _("The engelsystem is allowed to send me an email (e.g. when my shifts change)"), $email_shiftinfo), - form_checkbox('email_by_human_allowed', _("Humans are allowed to send me an email (e.g. for ticket vouchers)"), $email_by_human_allowed) - ]) - ]), - div('row', [ - div('col-sm-6', [ - form_date('planned_arrival_date', _("Planned date of arrival") . ' ' . entry_required(), $planned_arrival_date, $buildup_start_date, $teardown_end_date) - ]), - div('col-sm-6', [ - $enable_tshirt_size ? form_select('tshirt_size', _("Shirt size") . ' ' . entry_required(), $tshirt_sizes, $tshirt_size) : '' - ]) - ]), - div('row', [ - div('col-sm-6', [ - form_password('password', _("Password") . ' ' . entry_required()) - ]), - div('col-sm-6', [ - form_password('password2', _("Confirm password") . ' ' . entry_required()) - ]) - ]), - form_checkboxes('angel_types', _("What do you want to do?") . sprintf(" (%s)", page_link_to('angeltypes') . '&action=about', _("Description of job types")), $angel_types, $selected_angel_types), - form_info("", _("Restricted angel types need will be confirmed later by a supporter. You can change your selection in the options section.")) - ]), - div('col-md-6', [ - div('row', [ - div('col-sm-4', [ - form_text('dect', _("DECT"), $dect) - ]), - div('col-sm-4', [ - form_text('mobile', _("Mobile"), $mobile) - ]), - div('col-sm-4', [ - form_text('tel', _("Phone"), $tel) - ]) - ]), - form_text('jabber', _("Jabber"), $jabber), - div('row', [ - div('col-sm-6', [ - form_text('prename', _("First name"), $prename) - ]), - div('col-sm-6', [ - form_text('lastname', _("Last name"), $lastname) - ]) - ]), - div('row', [ - div('col-sm-3', [ - form_text('age', _("Age"), $age) - ]), - div('col-sm-9', [ - form_text('hometown', _("Hometown"), $hometown) - ]) - ]), - form_info(entry_required() . ' = ' . _("Entry required!")) - ]) - ]), - // form_textarea('comment', _("Did you help at former CCC events and which tasks have you performed then?"), $comment), - form_submit('submit', _("Register")) - ]) - ]); + _("By completing this form you're registering as a Chaos-Angel. This script will create you an account in the angel task scheduler."), + $msg, + msg(), + form([ + div('row', [ + div('col-md-6', [ + div('row', [ + div('col-sm-4', [ + form_text('nick', _("Nick") . ' ' . entry_required(), $nick) + ]), + div('col-sm-8', [ + form_email('mail', _("E-Mail") . ' ' . entry_required(), $mail), + form_checkbox( + 'email_shiftinfo', + _("The engelsystem is allowed to send me an email (e.g. when my shifts change)"), + $email_shiftinfo + ), + form_checkbox( + 'email_by_human_allowed', + _("Humans are allowed to send me an email (e.g. for ticket vouchers)"), + $email_by_human_allowed + ) + ]) + ]), + div('row', [ + div('col-sm-6', [ + form_date( + 'planned_arrival_date', + _("Planned date of arrival") . ' ' . entry_required(), + $planned_arrival_date, $buildup_start_date, $teardown_end_date + ) + ]), + div('col-sm-6', [ + $enable_tshirt_size ? form_select('tshirt_size', + _("Shirt size") . ' ' . entry_required(), + $tshirt_sizes, $tshirt_size) : '' + ]) + ]), + div('row', [ + div('col-sm-6', [ + form_password('password', _("Password") . ' ' . entry_required()) + ]), + div('col-sm-6', [ + form_password('password2', _("Confirm password") . ' ' . entry_required()) + ]) + ]), + form_checkboxes( + 'angel_types', + _("What do you want to do?") . sprintf( + " (%s)", + page_link_to('angeltypes') . '&action=about', + _("Description of job types") + ), + $angel_types, + $selected_angel_types + ), + form_info( + "", + _("Restricted angel types need will be confirmed later by a supporter. You can change your selection in the options section.") + ) + ]), + div('col-md-6', [ + div('row', [ + div('col-sm-4', [ + form_text('dect', _("DECT"), $dect) + ]), + div('col-sm-4', [ + form_text('mobile', _("Mobile"), $mobile) + ]), + div('col-sm-4', [ + form_text('tel', _("Phone"), $tel) + ]) + ]), + form_text('jabber', _("Jabber"), $jabber), + div('row', [ + div('col-sm-6', [ + form_text('prename', _("First name"), $prename) + ]), + div('col-sm-6', [ + form_text('lastname', _("Last name"), $lastname) + ]) + ]), + div('row', [ + div('col-sm-3', [ + form_text('age', _("Age"), $age) + ]), + div('col-sm-9', [ + form_text('hometown', _("Hometown"), $hometown) + ]) + ]), + form_info(entry_required() . ' = ' . _("Entry required!")) + ]) + ]), + // form_textarea('comment', _("Did you help at former CCC events and which tasks have you performed then?"), $comment), + form_submit('submit', _("Register")) + ]) + ]); } function entry_required() @@ -305,10 +340,10 @@ function guest_logout() function guest_login() { $nick = ""; - + unset($_SESSION['uid']); $valid = true; - + if (isset($_REQUEST['submit'])) { if (isset($_REQUEST['nick']) && strlen(User_validate_Nick($_REQUEST['nick'])) > 0) { $nick = User_validate_Nick($_REQUEST['nick']); @@ -316,7 +351,7 @@ function guest_login() if (count($login_user) > 0) { $login_user = $login_user[0]; if (isset($_REQUEST['password'])) { - if (! verify_password($_REQUEST['password'], $login_user['Passwort'], $login_user['UID'])) { + if (!verify_password($_REQUEST['password'], $login_user['Passwort'], $login_user['UID'])) { $valid = false; error(_("Your password is incorrect. Please try it again.")); } @@ -332,75 +367,75 @@ function guest_login() $valid = false; error(_("Please enter a nickname.")); } - + if ($valid) { $_SESSION['uid'] = $login_user['UID']; $_SESSION['locale'] = $login_user['Sprache']; - + redirect(page_link_to('news')); } } - + $event_config = EventConfig(); - + return page([ - div('col-md-12', [ - div('row', [ - EventConfig_countdown_page($event_config) - ]), - div('row', [ - div('col-sm-6 col-sm-offset-3 col-md-4 col-md-offset-4', [ - div('panel panel-primary first', [ - div('panel-heading', [ - ' ' . _("Login") - ]), - div('panel-body', [ - msg(), - form([ - form_text_placeholder('nick', _("Nick"), $nick), - form_password_placeholder('password', _("Password")), - form_submit('submit', _("Login")), - ! $valid ? buttons([ - button(page_link_to('user_password_recovery'), _("I forgot my password")) - ]) : '' - ]) - ]), - div('panel-footer', [ - glyph('info-sign') . _("Please note: You have to activate cookies!") - ]) - ]) - ]) - ]), - div('row', [ - div('col-sm-6 text-center', [ - heading(register_title(), 2), - get_register_hint() - ]), - div('col-sm-6 text-center', [ - heading(_("What can I do?"), 2), - '

' . _("Please read about the jobs you can do to help us.") . '

', - buttons([ - button(page_link_to('angeltypes') . '&action=about', _("Teams/Job description") . ' »') - ]) - ]) - ]) - ]) - ]); + div('col-md-12', [ + div('row', [ + EventConfig_countdown_page($event_config) + ]), + div('row', [ + div('col-sm-6 col-sm-offset-3 col-md-4 col-md-offset-4', [ + div('panel panel-primary first', [ + div('panel-heading', [ + ' ' . _("Login") + ]), + div('panel-body', [ + msg(), + form([ + form_text_placeholder('nick', _("Nick"), $nick), + form_password_placeholder('password', _("Password")), + form_submit('submit', _("Login")), + !$valid ? buttons([ + button(page_link_to('user_password_recovery'), _("I forgot my password")) + ]) : '' + ]) + ]), + div('panel-footer', [ + glyph('info-sign') . _("Please note: You have to activate cookies!") + ]) + ]) + ]) + ]), + div('row', [ + div('col-sm-6 text-center', [ + heading(register_title(), 2), + get_register_hint() + ]), + div('col-sm-6 text-center', [ + heading(_("What can I do?"), 2), + '

' . _("Please read about the jobs you can do to help us.") . '

', + buttons([ + button(page_link_to('angeltypes') . '&action=about', _("Teams/Job description") . ' »') + ]) + ]) + ]) + ]) + ]); } function get_register_hint() { global $privileges; - + if (in_array('register', $privileges)) { return join('', [ - '

' . _("Please sign up, if you want to help us!") . '

', - buttons([ - button(page_link_to('register'), register_title() . ' »') - ]) - ]); + '

' . _("Please sign up, if you want to help us!") . '

', + buttons([ + button(page_link_to('register'), register_title() . ' »') + ]) + ]); } - - //FIXME: return error(_("Registration is disabled."), true); - return error("Registration is disabled.", true); + + //FIXME: return error(_("Registration is disabled."), true); + return error("Registration is disabled.", true); } diff --git a/includes/pages/guest_stats.php b/includes/pages/guest_stats.php index 2559dd4d..1994f044 100644 --- a/includes/pages/guest_stats.php +++ b/includes/pages/guest_stats.php @@ -3,32 +3,32 @@ function guest_stats() { global $api_key; - + if (isset($_REQUEST['api_key'])) { if ($_REQUEST['api_key'] == $api_key) { $stats = []; - - list($user_count) = sql_select("SELECT count(*) as `user_count` FROM `User`"); + + list($user_count) = sql_select("SELECT count(*) AS `user_count` FROM `User`"); $stats['user_count'] = $user_count['user_count']; - - list($arrived_user_count) = sql_select("SELECT count(*) as `user_count` FROM `User` WHERE `Gekommen`=1"); + + list($arrived_user_count) = sql_select("SELECT count(*) AS `user_count` FROM `User` WHERE `Gekommen`=1"); $stats['arrived_user_count'] = $arrived_user_count['user_count']; - + $done_shifts_seconds = sql_select_single_cell("SELECT SUM(`Shifts`.`end` - `Shifts`.`start`) FROM `ShiftEntry` JOIN `Shifts` USING (`SID`) WHERE `Shifts`.`end` < UNIX_TIMESTAMP()"); $stats['done_work_hours'] = round($done_shifts_seconds / (60 * 60), 0); - + $users_in_action = sql_select("SELECT `Shifts`.`start`, `Shifts`.`end` FROM `ShiftEntry` JOIN `Shifts` ON `Shifts`.`SID`=`ShiftEntry`.`SID` WHERE UNIX_TIMESTAMP() BETWEEN `Shifts`.`start` AND `Shifts`.`end`"); $stats['users_in_action'] = count($users_in_action); - + header("Content-Type: application/json"); raw_output(json_encode($stats)); return; } raw_output(json_encode([ - 'error' => "Wrong api_key." - ])); + 'error' => "Wrong api_key." + ])); } raw_output(json_encode([ - 'error' => "Missing parameter api_key." - ])); + 'error' => "Missing parameter api_key." + ])); } diff --git a/includes/pages/user_atom.php b/includes/pages/user_atom.php index 88e8f201..ee4ddae5 100644 --- a/includes/pages/user_atom.php +++ b/includes/pages/user_atom.php @@ -4,24 +4,24 @@ function user_atom() { global $user, $DISPLAY_NEWS; - - if (! isset($_REQUEST['key']) || ! preg_match("/^[0-9a-f]{32}$/", $_REQUEST['key'])) { + + if (!isset($_REQUEST['key']) || !preg_match("/^[0-9a-f]{32}$/", $_REQUEST['key'])) { engelsystem_error("Missing key."); } $key = $_REQUEST['key']; - + $user = User_by_api_key($key); if ($user == null) { engelsystem_error("Key invalid."); } - if (! in_array('atom', privileges_for_user($user['UID']))) { + if (!in_array('atom', privileges_for_user($user['UID']))) { engelsystem_error("No privilege for atom."); } - + $news = sql_select("SELECT * FROM `News` " . (empty($_REQUEST['meetings']) ? '' : 'WHERE `Treffen` = 1 ') . "ORDER BY `ID` DESC LIMIT " . sql_escape($DISPLAY_NEWS)); - + $output = make_atom_entries_from_news($news); - + header('Content-Type: application/atom+xml; charset=utf-8'); header("Content-Length: " . strlen($output)); raw_output($output); @@ -32,7 +32,13 @@ function make_atom_entries_from_news($news_entries) $html = ' Engelsystem - ' . $_SERVER['HTTP_HOST'] . htmlspecialchars(preg_replace('#[&?]key=[a-f0-9]{32}#', '', $_SERVER['REQUEST_URI'])) . ' + ' . $_SERVER['HTTP_HOST'] + . htmlspecialchars(preg_replace( + '#[&?]key=[a-f0-9]{32}#', + '', + $_SERVER['REQUEST_URI'] + )) + . ' ' . date('Y-m-d\TH:i:sP', $news_entries[0]['Datum']) . "\n"; foreach ($news_entries as $news_entry) { $html .= make_atom_entry_from_news($news_entry); diff --git a/includes/pages/user_ical.php b/includes/pages/user_ical.php index 49546e58..05c67d51 100644 --- a/includes/pages/user_ical.php +++ b/includes/pages/user_ical.php @@ -6,30 +6,30 @@ function user_ical() { global $user; - - if (! isset($_REQUEST['key']) || ! preg_match("/^[0-9a-f]{32}$/", $_REQUEST['key'])) { + + if (!isset($_REQUEST['key']) || !preg_match("/^[0-9a-f]{32}$/", $_REQUEST['key'])) { engelsystem_error("Missing key."); } $key = $_REQUEST['key']; - + $user = User_by_api_key($key); if ($user == null) { engelsystem_error("Key invalid."); } - - if (! in_array('ical', privileges_for_user($user['UID']))) { + + if (!in_array('ical', privileges_for_user($user['UID']))) { engelsystem_error("No privilege for ical."); } - + $ical_shifts = load_ical_shifts(); - + send_ical_from_shifts($ical_shifts); } /** * Renders an ical calender from given shifts array. * - * @param array $shifts + * @param array $shifts */ function send_ical_from_shifts($shifts) { @@ -53,7 +53,8 @@ function make_ical_entry_from_shift($shift) { $output = "BEGIN:VEVENT\r\n"; $output .= "UID:" . md5($shift['start'] . $shift['end'] . $shift['name']) . "\r\n"; - $output .= "SUMMARY:" . str_replace("\n", "\\n", $shift['name']) . " (" . str_replace("\n", "\\n", $shift['title']) . ")\r\n"; + $output .= "SUMMARY:" . str_replace("\n", "\\n", $shift['name']) + . " (" . str_replace("\n", "\\n", $shift['title']) . ")\r\n"; if (isset($shift['Comment'])) { $output .= "DESCRIPTION:" . str_replace("\n", "\\n", $shift['Comment']) . "\r\n"; } diff --git a/includes/pages/user_messages.php b/includes/pages/user_messages.php index f9278828..b7ff093f 100644 --- a/includes/pages/user_messages.php +++ b/includes/pages/user_messages.php @@ -8,7 +8,7 @@ function messages_title() function user_unread_messages() { global $user; - + if (isset($user)) { $new_messages = sql_num_query("SELECT * FROM `Messages` WHERE isRead='N' AND `RUID`='" . sql_escape($user['UID']) . "'"); if ($new_messages > 0) { @@ -21,113 +21,121 @@ function user_unread_messages() function user_messages() { global $user; - - if (! isset($_REQUEST['action'])) { + + if (!isset($_REQUEST['action'])) { $users = sql_select("SELECT * FROM `User` WHERE NOT `UID`='" . sql_escape($user['UID']) . "' ORDER BY `Nick`"); - + $to_select_data = [ - "" => _("Select recipient...") - ]; - + "" => _("Select recipient...") + ]; + foreach ($users as $u) { $to_select_data[$u['UID']] = $u['Nick']; } - + $to_select = html_select_key('to', 'to', $to_select_data, ''); - + $messages = sql_select("SELECT * FROM `Messages` WHERE `SUID`='" . sql_escape($user['UID']) . "' OR `RUID`='" . sql_escape($user['UID']) . "' ORDER BY `isRead`,`Datum` DESC"); - + $messages_table = [ - [ - 'news' => '', - 'timestamp' => date("Y-m-d H:i"), - 'from' => User_Nick_render($user), - 'to' => $to_select, - 'text' => form_textarea('text', '', ''), - 'actions' => form_submit('submit', _("Save")) - ] - ]; - + [ + 'news' => '', + 'timestamp' => date("Y-m-d H:i"), + 'from' => User_Nick_render($user), + 'to' => $to_select, + 'text' => form_textarea('text', '', ''), + 'actions' => form_submit('submit', _("Save")) + ] + ]; + foreach ($messages as $message) { $sender_user_source = User($message['SUID']); $receiver_user_source = User($message['RUID']); - + $messages_table_entry = [ - 'new' => $message['isRead'] == 'N' ? '' : '', - 'timestamp' => date("Y-m-d H:i", $message['Datum']), - 'from' => User_Nick_render($sender_user_source), - 'to' => User_Nick_render($receiver_user_source), - 'text' => str_replace("\n", '
', $message['Text']) - ]; - + 'new' => $message['isRead'] == 'N' ? '' : '', + 'timestamp' => date("Y-m-d H:i", $message['Datum']), + 'from' => User_Nick_render($sender_user_source), + 'to' => User_Nick_render($receiver_user_source), + 'text' => str_replace("\n", '
', $message['Text']) + ]; + if ($message['RUID'] == $user['UID']) { if ($message['isRead'] == 'N') { - $messages_table_entry['actions'] = button(page_link_to("user_messages") . '&action=read&id=' . $message['id'], _("mark as read"), 'btn-xs'); + $messages_table_entry['actions'] = button( + page_link_to("user_messages") . '&action=read&id=' . $message['id'], + _("mark as read"), + 'btn-xs' + ); } } else { - $messages_table_entry['actions'] = button(page_link_to("user_messages") . '&action=delete&id=' . $message['id'], _("delete message"), 'btn-xs'); + $messages_table_entry['actions'] = button( + page_link_to("user_messages") . '&action=delete&id=' . $message['id'], + _("delete message"), + 'btn-xs' + ); } $messages_table[] = $messages_table_entry; } - + return page_with_title(messages_title(), [ - msg(), - sprintf(_("Hello %s, here can you leave messages for other angels"), User_Nick_render($user)), - form([ - table([ - 'new' => _("New"), - 'timestamp' => _("Date"), - 'from' => _("Transmitted"), - 'to' => _("Recipient"), - 'text' => _("Message"), - 'actions' => '' - ], $messages_table) - ], page_link_to('user_messages') . '&action=send') - ]); + msg(), + sprintf(_("Hello %s, here can you leave messages for other angels"), User_Nick_render($user)), + form([ + table([ + 'new' => _("New"), + 'timestamp' => _("Date"), + 'from' => _("Transmitted"), + 'to' => _("Recipient"), + 'text' => _("Message"), + 'actions' => '' + ], $messages_table) + ], page_link_to('user_messages') . '&action=send') + ]); } else { switch ($_REQUEST['action']) { - case "read": - if (isset($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id'])) { - $message_id = $_REQUEST['id']; - } else { - return error(_("Incomplete call, missing Message ID."), true); - } - - $message = sql_select("SELECT * FROM `Messages` WHERE `id`='" . sql_escape($message_id) . "' LIMIT 1"); - if (count($message) > 0 && $message[0]['RUID'] == $user['UID']) { - sql_query("UPDATE `Messages` SET `isRead`='Y' WHERE `id`='" . sql_escape($message_id) . "' LIMIT 1"); - redirect(page_link_to("user_messages")); - } else { - return error(_("No Message found."), true); - } - break; - - case "delete": - if (isset($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id'])) { - $message_id = $_REQUEST['id']; - } else { - return error(_("Incomplete call, missing Message ID."), true); - } - - $message = sql_select("SELECT * FROM `Messages` WHERE `id`='" . sql_escape($message_id) . "' LIMIT 1"); - if (count($message) > 0 && $message[0]['SUID'] == $user['UID']) { - sql_query("DELETE FROM `Messages` WHERE `id`='" . sql_escape($message_id) . "' LIMIT 1"); - redirect(page_link_to("user_messages")); - } else { - return error(_("No Message found."), true); - } - break; - - case "send": - if (Message_send($_REQUEST['to'], $_REQUEST['text']) === true) { - redirect(page_link_to("user_messages")); - } else { - return error(_("Transmitting was terminated with an Error."), true); + case "read": + if (isset($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id'])) { + $message_id = $_REQUEST['id']; + } else { + return error(_("Incomplete call, missing Message ID."), true); + } + + $message = sql_select("SELECT * FROM `Messages` WHERE `id`='" . sql_escape($message_id) . "' LIMIT 1"); + if (count($message) > 0 && $message[0]['RUID'] == $user['UID']) { + sql_query("UPDATE `Messages` SET `isRead`='Y' WHERE `id`='" . sql_escape($message_id) . "' LIMIT 1"); + redirect(page_link_to("user_messages")); + } else { + return error(_("No Message found."), true); + } + break; + + case "delete": + if (isset($_REQUEST['id']) && preg_match("/^[0-9]{1,11}$/", $_REQUEST['id'])) { + $message_id = $_REQUEST['id']; + } else { + return error(_("Incomplete call, missing Message ID."), true); + } + + $message = sql_select("SELECT * FROM `Messages` WHERE `id`='" . sql_escape($message_id) . "' LIMIT 1"); + if (count($message) > 0 && $message[0]['SUID'] == $user['UID']) { + sql_query("DELETE FROM `Messages` WHERE `id`='" . sql_escape($message_id) . "' LIMIT 1"); + redirect(page_link_to("user_messages")); + } else { + return error(_("No Message found."), true); + } + break; + + case "send": + if (Message_send($_REQUEST['to'], $_REQUEST['text']) === true) { + redirect(page_link_to("user_messages")); + } else { + return error(_("Transmitting was terminated with an Error."), true); + } + break; + + default: + return error(_("Wrong action."), true); } - break; - - default: - return error(_("Wrong action."), true); - } } } diff --git a/includes/pages/user_myshifts.php b/includes/pages/user_myshifts.php index fbfe3f33..8c2d9442 100644 --- a/includes/pages/user_myshifts.php +++ b/includes/pages/user_myshifts.php @@ -10,15 +10,20 @@ function user_myshifts() { global $LETZTES_AUSTRAGEN; global $user, $privileges; - - if (isset($_REQUEST['id']) && in_array("user_shifts_admin", $privileges) && preg_match("/^[0-9]{1,}$/", $_REQUEST['id']) && sql_num_query("SELECT * FROM `User` WHERE `UID`='" . sql_escape($_REQUEST['id']) . "'") > 0) { + + if ( + isset($_REQUEST['id']) + && in_array("user_shifts_admin", $privileges) + && preg_match("/^[0-9]{1,}$/", $_REQUEST['id']) + && sql_num_query("SELECT * FROM `User` WHERE `UID`='" . sql_escape($_REQUEST['id']) . "'") > 0 + ) { $user_id = $_REQUEST['id']; } else { $user_id = $user['UID']; } - + list($shifts_user) = sql_select("SELECT * FROM `User` WHERE `UID`='" . sql_escape($user_id) . "' LIMIT 1"); - + if (isset($_REQUEST['reset'])) { if ($_REQUEST['reset'] == "ack") { User_reset_api_key($user); @@ -26,9 +31,12 @@ function user_myshifts() redirect(page_link_to('users') . '&action=view&user_id=' . $shifts_user['UID']); } return page_with_title(_("Reset API key"), [ - error(_("If you reset the key, the url to your iCal- and JSON-export and your atom feed changes! You have to update it in every application using one of these exports."), true), - button(page_link_to('user_myshifts') . '&reset=ack', _("Continue"), 'btn-danger') - ]); + error( + _("If you reset the key, the url to your iCal- and JSON-export and your atom feed changes! You have to update it in every application using one of these exports."), + true + ), + button(page_link_to('user_myshifts') . '&reset=ack', _("Continue"), 'btn-danger') + ]); } elseif (isset($_REQUEST['edit']) && preg_match("/^[0-9]*$/", $_REQUEST['edit'])) { $user_id = $_REQUEST['edit']; $shift = sql_select("SELECT @@ -39,7 +47,7 @@ function user_myshifts() `ShiftTypes`.`name`, `Shifts`.*, `Room`.`Name`, - `AngelTypes`.`name` as `angel_type` + `AngelTypes`.`name` AS `angel_type` FROM `ShiftEntry` JOIN `AngelTypes` ON (`ShiftEntry`.`TID` = `AngelTypes`.`id`) JOIN `Shifts` ON (`ShiftEntry`.`SID` = `Shifts`.`SID`) @@ -51,7 +59,7 @@ function user_myshifts() $shift = $shift[0]; $freeloaded = $shift['freeloaded']; $freeload_comment = $shift['freeload_comment']; - + if (isset($_REQUEST['submit'])) { $valid = true; if (in_array("user_shifts_admin", $privileges)) { @@ -62,28 +70,44 @@ function user_myshifts() error(_("Please enter a freeload comment!")); } } - + $comment = strip_request_item_nl('comment'); $user_source = User($shift['UID']); - + if ($valid) { $result = ShiftEntry_update([ - 'id' => $user_id, - 'Comment' => $comment, - 'freeloaded' => $freeloaded, - 'freeload_comment' => $freeload_comment - ]); + 'id' => $user_id, + 'Comment' => $comment, + 'freeloaded' => $freeloaded, + 'freeload_comment' => $freeload_comment + ]); if ($result === false) { engelsystem_error('Unable to update shift entry.'); } - - engelsystem_log("Updated " . User_Nick_render($user_source) . "'s shift " . $shift['name'] . " from " . date("Y-m-d H:i", $shift['start']) . " to " . date("Y-m-d H:i", $shift['end']) . " with comment " . $comment . ". Freeloaded: " . ($freeloaded ? "YES Comment: " . $freeload_comment : "NO")); + + engelsystem_log( + "Updated " . User_Nick_render($user_source) . "'s shift " . $shift['name'] + . " from " . date("Y-m-d H:i", $shift['start']) + . " to " . date("Y-m-d H:i", $shift['end']) + . " with comment " . $comment + . ". Freeloaded: " . ($freeloaded ? "YES Comment: " . $freeload_comment : "NO") + ); success(_("Shift saved.")); redirect(page_link_to('users') . '&action=view&user_id=' . $shifts_user['UID']); } } - - return ShiftEntry_edit_view(User_Nick_render($shifts_user), date("Y-m-d H:i", $shift['start']) . ', ' . shift_length($shift), $shift['Name'], $shift['name'], $shift['angel_type'], $shift['Comment'], $shift['freeloaded'], $shift['freeload_comment'], in_array("user_shifts_admin", $privileges)); + + return ShiftEntry_edit_view( + User_Nick_render($shifts_user), + date("Y-m-d H:i", $shift['start']) . ', ' . shift_length($shift), + $shift['Name'], + $shift['name'], + $shift['angel_type'], + $shift['Comment'], + $shift['freeloaded'], + $shift['freeload_comment'], + in_array("user_shifts_admin", $privileges) + ); } else { redirect(page_link_to('user_myshifts')); } @@ -104,8 +128,14 @@ function user_myshifts() $room = Room($shift['RID']); $angeltype = AngelType($shift['TID']); $shifttype = ShiftType($shift['shifttype_id']); - - engelsystem_log("Deleted own shift: " . $shifttype['name'] . " at " . $room['Name'] . " from " . date("Y-m-d H:i", $shift['start']) . " to " . date("Y-m-d H:i", $shift['end']) . " as " . $angeltype['name']); + + engelsystem_log( + "Deleted own shift: " . $shifttype['name'] + . " at " . $room['Name'] + . " from " . date("Y-m-d H:i", $shift['start']) + . " to " . date("Y-m-d H:i", $shift['end']) + . " as " . $angeltype['name'] + ); success(_("Shift canceled.")); } else { error(_("It's too late to sign yourself off the shift. If neccessary, ask the dispatcher to do so.")); @@ -114,6 +144,6 @@ function user_myshifts() redirect(user_link($shifts_user)); } } - + redirect(page_link_to('users') . '&action=view&user_id=' . $shifts_user['UID']); } diff --git a/includes/pages/user_news.php b/includes/pages/user_news.php index a26b4d8d..31f38eaa 100644 --- a/includes/pages/user_news.php +++ b/includes/pages/user_news.php @@ -18,26 +18,26 @@ function meetings_title() function user_meetings() { global $DISPLAY_NEWS; - + $html = '

' . meetings_title() . '

' . msg(); - + if (isset($_REQUEST['page']) && preg_match("/^[0-9]{1,}$/", $_REQUEST['page'])) { $page = $_REQUEST['page']; } else { $page = 0; } - + $news = sql_select("SELECT * FROM `News` WHERE `Treffen`=1 ORDER BY `Datum` DESC LIMIT " . sql_escape($page * $DISPLAY_NEWS) . ", " . sql_escape($DISPLAY_NEWS)); foreach ($news as $entry) { $html .= display_news($entry); } - + $dis_rows = ceil(sql_num_query("SELECT * FROM `News`") / $DISPLAY_NEWS); $html .= '
' . '
    '; - for ($i = 0; $i < $dis_rows; $i ++) { + for ($i = 0; $i < $dis_rows; $i++) { if (isset($_REQUEST['page']) && $i == $_REQUEST['page']) { $html .= '
  • '; - } elseif (! isset($_REQUEST['page']) && $i == 0) { + } elseif (!isset($_REQUEST['page']) && $i == 0) { $html .= '
  • '; } else { $html .= '
  • '; @@ -45,29 +45,31 @@ function user_meetings() $html .= '' . ($i + 1) . '
  • '; } $html .= '
'; - + return $html; } function display_news($news) { global $privileges, $page; - + $html = ''; $html .= '
'; $html .= '
'; $html .= '

' . ($news['Treffen'] == 1 ? '[Meeting] ' : '') . ReplaceSmilies($news['Betreff']) . '

'; $html .= '
'; $html .= '
' . ReplaceSmilies(nl2br($news['Text'])) . '
'; - + $html .= ''; return $html; } +/** + * @return string + */ function user_news_comments() { global $user; @@ -93,7 +123,15 @@ function user_news_comments() list($news) = sql_select("SELECT * FROM `News` WHERE `ID`='" . sql_escape($nid) . "' LIMIT 1"); if (isset($_REQUEST["text"])) { $text = preg_replace("/([^\p{L}\p{P}\p{Z}\p{N}\n]{1,})/ui", '', strip_tags($_REQUEST['text'])); - sql_query("INSERT INTO `NewsComments` (`Refid`, `Datum`, `Text`, `UID`) VALUES ('" . sql_escape($nid) . "', '" . date("Y-m-d H:i:s") . "', '" . sql_escape($text) . "', '" . sql_escape($user["UID"]) . "')"); + sql_query(" + INSERT INTO `NewsComments` (`Refid`, `Datum`, `Text`, `UID`) + VALUES ( + '" . sql_escape($nid) . "', + '" . date("Y-m-d H:i:s") . "', + '" . sql_escape($text) . "', + '" . sql_escape($user["UID"]) . "' + ) + "); engelsystem_log("Created news_comment: " . $text); $html .= success(_("Entry saved."), true); } @@ -125,9 +163,12 @@ function user_news_comments() return $html . '
'; } +/** + * @return string + */ function user_news() { - global $DISPLAY_NEWS, $privileges, $user; + global $display_news, $privileges, $user; $html = '

' . news_title() . '

' . msg(); @@ -135,7 +176,16 @@ function user_news() if (!isset($_POST["treffen"]) || !in_array("admin_news", $privileges)) { $_POST["treffen"] = 0; } - sql_query("INSERT INTO `News` (`Datum`, `Betreff`, `Text`, `UID`, `Treffen`) " . "VALUES ('" . sql_escape(time()) . "', '" . sql_escape($_POST["betreff"]) . "', '" . sql_escape($_POST["text"]) . "', '" . sql_escape($user['UID']) . "', '" . sql_escape($_POST["treffen"]) . "');"); + sql_query(" + INSERT INTO `News` (`Datum`, `Betreff`, `Text`, `UID`, `Treffen`) + VALUES ( + '" . sql_escape(time()) . "', + '" . sql_escape($_POST["betreff"]) . "', + '" . sql_escape($_POST["text"]) . "', + '" . sql_escape($user['UID']) . "', + '" . sql_escape($_POST["treffen"]) . "' + ) + "); engelsystem_log("Created news: " . $_POST["betreff"] . ", treffen: " . $_POST["treffen"]); success(_("Entry saved.")); redirect(page_link_to('news')); @@ -147,12 +197,17 @@ function user_news() $page = 0; } - $news = sql_select("SELECT * FROM `News` ORDER BY `Datum` DESC LIMIT " . sql_escape($page * $DISPLAY_NEWS) . ", " . sql_escape($DISPLAY_NEWS)); + $news = sql_select(" + SELECT * + FROM `News` + ORDER BY `Datum` + DESC LIMIT " . sql_escape($page * $display_news) . ", " . sql_escape($display_news) + ); foreach ($news as $entry) { $html .= display_news($entry); } - $dis_rows = ceil(sql_num_query("SELECT * FROM `News`") / $DISPLAY_NEWS); + $dis_rows = ceil(sql_num_query("SELECT * FROM `News`") / $display_news); $html .= '
' . '
    '; for ($i = 0; $i < $dis_rows; $i++) { if (isset($_REQUEST['page']) && $i == $_REQUEST['page']) { diff --git a/includes/pages/user_questions.php b/includes/pages/user_questions.php index d1a90292..fa66e8db 100644 --- a/includes/pages/user_questions.php +++ b/includes/pages/user_questions.php @@ -1,10 +1,16 @@ $themes - * List of available themes + * @param array $user_source The user + * @param array $themes List of available themes + * @return mixed */ function user_settings_theme($user_source, $themes) { @@ -140,10 +143,9 @@ function user_settings_theme($user_source, $themes) /** * Change use locale * - * @param User $user_source - * The user - * @param array $locales - * List of available locales + * @param array $user_source The user + * @param array $locales List of available locales + * @return array */ function user_settings_locale($user_source, $locales) { @@ -168,6 +170,8 @@ function user_settings_locale($user_source, $locales) /** * Main user settings page/controller + * + * @return string */ function user_settings() { diff --git a/includes/pages/user_shifts.php b/includes/pages/user_shifts.php index e325989c..405b36ab 100644 --- a/includes/pages/user_shifts.php +++ b/includes/pages/user_shifts.php @@ -1,6 +1,9 @@ '1' . _("The tasks shown here are influenced by the angeltypes you joined already!") - . " " + . ' ' . _("Description of the jobs.") - . "", + . '', 'shifts_table' => msg() . $shiftCalendarRenderer->render(), 'ical_text' => '

    ' . _("iCal export") . '

    ' . sprintf( _("Export of shown shifts. iCal format or JSON format available (please keep secret, otherwise reset the api key)."), @@ -213,6 +230,10 @@ function view_user_shifts() ]); } +/** + * @param array $array + * @return array + */ function get_ids_from_array($array) { return $array["id"]; @@ -227,9 +248,9 @@ function make_select($items, $selected, $name, $title = null) foreach ($items as $i) { $html_items[] = '

    ' - . '' + . ' > ' . $i['name'] . '' . (!isset($i['enabled']) || $i['enabled'] ? '' : glyph("lock")) . '

    '; } diff --git a/includes/sys_auth.php b/includes/sys_auth.php index f3aafc98..734afd57 100644 --- a/includes/sys_auth.php +++ b/includes/sys_auth.php @@ -31,6 +31,9 @@ function load_auth() /** * generate a salt (random string) of arbitrary length suitable for the use with crypt() + * + * @param int $length + * @return string */ function generate_salt($length = 16) { @@ -44,6 +47,10 @@ function generate_salt($length = 16) /** * set the password of a user + * + * @param int $uid + * @param string $password + * @return mysqli_result */ function set_password($uid, $password) { @@ -64,8 +71,13 @@ function set_password($uid, $password) /** * verify a password given a precomputed salt. * if $uid is given and $salt is an old-style salt (plain md5), we convert it automatically + * + * @param string $password + * @param string $salt + * @param int $uid + * @return bool */ -function verify_password($password, $salt, $uid = false) +function verify_password($password, $salt, $uid = null) { global $crypt_alg; $correct = false; @@ -77,7 +89,7 @@ function verify_password($password, $salt, $uid = false) $correct = md5($password) == $salt; } - if ($correct && substr($salt, 0, strlen($crypt_alg)) != $crypt_alg && $uid) { + if ($correct && substr($salt, 0, strlen($crypt_alg)) != $crypt_alg && intval($uid)) { // this password is stored in another format than we want it to be. // let's update it! // we duplicate the query from the above set_password() function to have the extra safety of checking the old hash @@ -92,6 +104,10 @@ function verify_password($password, $salt, $uid = false) return $correct; } +/** + * @param int $user_id + * @return array + */ function privileges_for_user($user_id) { $privileges = []; @@ -109,6 +125,10 @@ function privileges_for_user($user_id) return $privileges; } +/** + * @param int $group_id + * @return array + */ function privileges_for_group($group_id) { $privileges = []; diff --git a/includes/sys_form.php b/includes/sys_form.php index dfd43067..41fcd763 100644 --- a/includes/sys_form.php +++ b/includes/sys_form.php @@ -4,10 +4,8 @@ /** * Renders a hidden input * - * @param string $name - * Name of the input - * @param string $value - * The value + * @param string $name Name of the input + * @param string $value The value * @return string rendered html */ function form_hidden($name, $value) @@ -17,6 +15,11 @@ function form_hidden($name, $value) /** * Rendert ein Zahlenfeld mit Buttons zum verstellen + * + * @param string $name + * @param string $label + * @param string $value + * @return string */ function form_spinner($name, $label, $value) { @@ -33,11 +36,12 @@ function form_spinner($name, $label, $value)
'); @@ -46,15 +50,12 @@ function form_spinner($name, $label, $value) /** * Render a bootstrap datepicker * - * @param string $name - * Name of the parameter - * @param string $label - * Label - * @param int $value - * Unix Timestamp - * @param int $min_date - * Earliest possible date - * @return HTML + * @param string $name Name of the parameter + * @param string $label Label + * @param int $value Unix Timestamp + * @param string $start_date Earliest possible date + * @param string $end_date + * @return string HTML */ function form_date($name, $label, $value, $start_date = '', $end_date = '') { @@ -83,14 +84,11 @@ function form_date($name, $label, $value, $start_date = '', $end_date = '') /** * Rendert eine Liste von Checkboxen für ein Formular * - * @param - * name Die Namen der Checkboxen werden aus name_key gebildet - * @param - * label Die Beschriftung der Liste - * @param - * items Array mit den einzelnen Checkboxen - * @param - * selected Array mit den Keys, die ausgewählt sind + * @param string $name Die Namen der Checkboxen werden aus name_key gebildet + * @param string $label Die Beschriftung der Liste + * @param array $items Array mit den einzelnen Checkboxen + * @param array $selected Array mit den Keys, die ausgewählt sind + * @return string */ function form_checkboxes($name, $label, $items, $selected) { @@ -104,17 +102,13 @@ function form_checkboxes($name, $label, $items, $selected) /** * Rendert eine Tabelle von Checkboxen für ein Formular * - * @param - * names Assoziatives Array mit Namen der Checkboxen als Keys und Überschriften als Values - * @param - * label Die Beschriftung der gesamten Tabelle - * @param - * items Array mit den Beschriftungen der Zeilen - * @param - * selected Mehrdimensionales Array, wobei $selected[foo] ein Array der in der Datenreihe foo markierten - * Checkboxen ist - * @param - * disabled Wie selected, nur dass die entsprechenden Checkboxen deaktiviert statt markiert sind + * @param string[] $names Assoziatives Array mit Namen der Checkboxen als Keys und Überschriften als Values + * @param string $label Die Beschriftung der gesamten Tabelle + * @param string[] $items Array mit den Beschriftungen der Zeilen + * @param array[] $selected Mehrdimensionales Array, wobei $selected[foo] ein Array der in der Datenreihe foo + * markierten Checkboxen ist + * @param array $disabled Wie selected, nur dass die entsprechenden Checkboxen deaktiviert statt markiert sind + * @return string */ function form_multi_checkboxes($names, $label, $items, $selected, $disabled = []) { @@ -125,13 +119,16 @@ function form_multi_checkboxes($names, $label, $items, $selected, $disabled = [] $html .= ""; foreach ($items as $key => $item) { $html .= ""; + $dom_id = ''; foreach ($names as $name => $title) { $dom_id = $name . '_' . $key; $sel = array_search($key, $selected[$name]) !== false ? ' checked="checked"' : ""; if (!empty($disabled) && !empty($disabled[$name]) && array_search($key, $disabled[$name]) !== false) { $sel .= ' disabled="disabled"'; } - $html .= ''; + $html .= '' + . '' + . ''; } $html .= ''; } @@ -141,22 +138,38 @@ function form_multi_checkboxes($names, $label, $items, $selected, $disabled = [] /** * Rendert eine Checkbox + * + * @param string $name + * @param string $label + * @param string $selected + * @param string $value + * @return string */ function form_checkbox($name, $label, $selected, $value = 'checked') { - return '
'; + return '
'; } /** * Rendert einen Radio + * + * @param string $name + * @param string $label + * @param string $selected + * @param string $value + * @return string */ function form_radio($name, $label, $selected, $value) { - return '
'; + return '
'; } /** * Rendert einen Infotext in das Formular + * + * @param string $label + * @param string $text + * @return string */ function form_info($label, $text = "") { @@ -171,6 +184,10 @@ function form_info($label, $text = "") /** * Rendert den Absenden-Button eines Formulars + * + * @param string $name + * @param string $label + * @return string */ function form_submit($name, $label) { @@ -182,6 +199,12 @@ function form_submit($name, $label) /** * Rendert ein Formular-Textfeld + * + * @param string $name + * @param string $label + * @param string $value + * @param bool $disabled + * @return string */ function form_text($name, $label, $value, $disabled = false) { @@ -196,14 +219,11 @@ function form_text($name, $label, $value, $disabled = false) /** * Renders a text input with placeholder instead of label. * - * @param String $name - * Input name - * @param String $placeholder - * Placeholder - * @param String $value - * The value - * @param Boolean $disabled - * Is the field enabled? + * @param String $name Input name + * @param String $placeholder Placeholder + * @param String $value The value + * @param Boolean $disabled Is the field enabled? + * @return string */ function form_text_placeholder($name, $placeholder, $value, $disabled = false) { @@ -214,6 +234,12 @@ function form_text_placeholder($name, $placeholder, $value, $disabled = false) /** * Rendert ein Formular-Emailfeld + * + * @param string $name + * @param string $label + * @param string $value + * @param bool $disabled + * @return string */ function form_email($name, $label, $value, $disabled = false) { @@ -227,6 +253,10 @@ function form_email($name, $label, $value, $disabled = false) /** * Rendert ein Formular-Dateifeld + * + * @param string $name + * @param string $label + * @return string */ function form_file($name, $label) { @@ -235,6 +265,11 @@ function form_file($name, $label) /** * Rendert ein Formular-Passwortfeld + * + * @param string $name + * @param string $label + * @param bool $disabled + * @return string */ function form_password($name, $label, $disabled = false) { @@ -248,6 +283,11 @@ function form_password($name, $label, $disabled = false) /** * Renders a password input with placeholder instead of label. + * + * @param string $name + * @param string $placeholder + * @param bool $disabled + * @return string */ function form_password_placeholder($name, $placeholder, $disabled = false) { @@ -261,6 +301,12 @@ function form_password_placeholder($name, $placeholder, $disabled = false) /** * Rendert ein Formular-Textfeld + * + * @param string $name + * @param string $label + * @param string $value + * @param bool $disabled + * @return string */ function form_textarea($name, $label, $value, $disabled = false) { @@ -274,6 +320,12 @@ function form_textarea($name, $label, $value, $disabled = false) /** * Rendert ein Formular-Auswahlfeld + * + * @param string $name + * @param string $label + * @param string[] $values + * @param string $selected + * @return string */ function form_select($name, $label, $values, $selected) { @@ -282,6 +334,11 @@ function form_select($name, $label, $values, $selected) /** * Rendert ein Formular-Element + * + * @param string $label + * @param string $input + * @param string $for + * @return string */ function form_element($label, $input, $for = "") { @@ -294,12 +351,22 @@ function form_element($label, $input, $for = "") /** * Rendert ein Formular + * + * @param string[] $elements + * @param string $action + * @return string */ function form($elements, $action = "") { return '
' . join($elements) . '
'; } +/** + * @param string $name + * @param String[] $options + * @param string $selected + * @return string + */ function html_options($name, $options, $selected = "") { $html = ""; @@ -310,6 +377,13 @@ function html_options($name, $options, $selected = "") return $html; } +/** + * @param string $dom_id + * @param string $name + * @param string[] $rows + * @param string $selected + * @return string + */ function html_select_key($dom_id, $name, $rows, $selected) { $html = '' . "\n"; $html .= '' . "\n"; -- cgit v1.2.3-54-g00ecf From 3a1e4602492cec1c8f3d2aabab2c866022f43bf1 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Tue, 18 Jul 2017 21:38:53 +0200 Subject: Changed $_GET, $_POST and $_REQUEST to use the Request object --- includes/controller/angeltypes_controller.php | 22 +++-- includes/controller/event_config_controller.php | 7 +- includes/controller/rooms_controller.php | 15 +-- includes/controller/shift_entries_controller.php | 30 +++--- includes/controller/shifts_controller.php | 54 +++++----- includes/controller/shifttypes_controller.php | 35 ++++--- includes/controller/user_angeltypes_controller.php | 49 ++++----- .../controller/user_driver_licenses_controller.php | 24 ++--- includes/controller/users_controller.php | 72 ++++++++------ includes/engelsystem_provider.php | 8 ++ includes/helper/internationalization_helper.php | 8 +- includes/pages/admin_active.php | 27 ++--- includes/pages/admin_arrive.php | 12 ++- includes/pages/admin_free.php | 16 +-- includes/pages/admin_groups.php | 21 ++-- includes/pages/admin_import.php | 48 ++++----- includes/pages/admin_log.php | 2 +- includes/pages/admin_news.php | 17 ++-- includes/pages/admin_questions.php | 15 +-- includes/pages/admin_rooms.php | 36 +++---- includes/pages/admin_shifts.php | 69 ++++++------- includes/pages/admin_user.php | 58 +++++------ includes/pages/guest_login.php | 63 ++++++------ includes/pages/guest_stats.php | 5 +- includes/pages/user_atom.php | 9 +- includes/pages/user_ical.php | 5 +- includes/pages/user_messages.php | 16 +-- includes/pages/user_myshifts.php | 25 ++--- includes/pages/user_news.php | 47 +++++---- includes/pages/user_questions.php | 9 +- includes/pages/user_settings.php | 55 ++++++----- includes/pages/user_shifts.php | 9 +- includes/sys_page.php | 35 ++++--- includes/sys_template.php | 6 +- public/index.php | 16 ++- src/Http/Request.php | 110 +++++++++++++++++++++ src/helpers.php | 17 ++++ 37 files changed, 643 insertions(+), 429 deletions(-) create mode 100644 src/Http/Request.php (limited to 'includes/controller/user_driver_licenses_controller.php') diff --git a/includes/controller/angeltypes_controller.php b/includes/controller/angeltypes_controller.php index daa754eb..346a4d73 100644 --- a/includes/controller/angeltypes_controller.php +++ b/includes/controller/angeltypes_controller.php @@ -81,7 +81,7 @@ function angeltype_delete_controller() $angeltype = load_angeltype(); - if (isset($_REQUEST['confirmed'])) { + if (request()->has('confirmed')) { AngelType_delete($angeltype); success(sprintf(_('Angeltype %s deleted.'), AngelType_name_render($angeltype))); redirect(page_link_to('angeltypes')); @@ -104,8 +104,9 @@ function angeltype_edit_controller() // In supporter mode only allow to modify description $supporter_mode = !in_array('admin_angel_types', $privileges); + $request = request(); - if (isset($_REQUEST['angeltype_id'])) { + if ($request->has('angeltype_id')) { // Edit existing angeltype $angeltype = load_angeltype(); @@ -121,12 +122,12 @@ function angeltype_edit_controller() $angeltype = AngelType_new(); } - if (isset($_REQUEST['submit'])) { + if ($request->has('submit')) { $valid = true; if (!$supporter_mode) { - if (isset($_REQUEST['name'])) { - $result = AngelType_validate_name($_REQUEST['name'], $angeltype); + if ($request->has('name')) { + $result = AngelType_validate_name($request->get('name'), $angeltype); $angeltype['name'] = $result->getValue(); if (!$result->isValid()) { $valid = false; @@ -134,10 +135,10 @@ function angeltype_edit_controller() } } - $angeltype['restricted'] = isset($_REQUEST['restricted']); - $angeltype['no_self_signup'] = isset($_REQUEST['no_self_signup']); + $angeltype['restricted'] = $request->has('restricted'); + $angeltype['no_self_signup'] = $request->has('no_self_signup'); - $angeltype['requires_driver_license'] = isset($_REQUEST['requires_driver_license']); + $angeltype['requires_driver_license'] = $request->has('requires_driver_license'); } $angeltype['description'] = strip_request_item_nl('description', $angeltype['description']); @@ -262,11 +263,12 @@ function angeltypes_list_controller() */ function load_angeltype() { - if (!isset($_REQUEST['angeltype_id'])) { + $request = request(); + if (!$request->has('angeltype_id')) { redirect(page_link_to('angeltypes')); } - $angeltype = AngelType($_REQUEST['angeltype_id']); + $angeltype = AngelType($request->input('angeltype_id')); if ($angeltype == null) { error(_('Angeltype doesn\'t exist . ')); redirect(page_link_to('angeltypes')); diff --git a/includes/controller/event_config_controller.php b/includes/controller/event_config_controller.php index 06245c47..dcdcf54a 100644 --- a/includes/controller/event_config_controller.php +++ b/includes/controller/event_config_controller.php @@ -19,6 +19,7 @@ function event_config_edit_controller() redirect('?'); } + $request = request(); $event_name = null; $event_welcome_msg = null; $buildup_start_date = null; @@ -36,17 +37,17 @@ function event_config_edit_controller() $event_welcome_msg = $event_config['event_welcome_msg']; } - if (isset($_REQUEST['submit'])) { + if ($request->has('submit')) { $valid = true; - if (isset($_REQUEST['event_name'])) { + if ($request->has('event_name')) { $event_name = strip_request_item('event_name'); } if ($event_name == '') { $event_name = null; } - if (isset($_REQUEST['event_welcome_msg'])) { + if ($request->has('event_welcome_msg')) { $event_welcome_msg = strip_request_item_nl('event_welcome_msg'); } if ($event_welcome_msg == '') { diff --git a/includes/controller/rooms_controller.php b/includes/controller/rooms_controller.php index 3082a28d..2d6f1a77 100644 --- a/includes/controller/rooms_controller.php +++ b/includes/controller/rooms_controller.php @@ -19,6 +19,7 @@ function room_controller() redirect(page_link_to()); } + $request = request(); $room = load_room(false); if ($room['show'] != 'Y' && !in_array('admin_rooms', $privileges)) { redirect(page_link_to()); @@ -42,8 +43,8 @@ function room_controller() if (!empty($days)) { $selected_day = $days[0]; } - if (isset($_REQUEST['shifts_filter_day'])) { - $selected_day = $_REQUEST['shifts_filter_day']; + if ($request->has('shifts_filter_day')) { + $selected_day = $request->input('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')); @@ -66,11 +67,13 @@ function room_controller() */ function rooms_controller() { - if (!isset($_REQUEST['action'])) { - $_REQUEST['action'] = 'list'; + $request = request(); + $action = $request->input('action'); + if (!$request->has('action')) { + $action = 'list'; } - switch ($_REQUEST['action']) { + switch ($action) { case 'view': return room_controller(); case 'list': @@ -112,7 +115,7 @@ function load_room($onlyVisible = true) redirect(page_link_to()); } - $room = Room($_REQUEST['room_id'], $onlyVisible); + $room = Room(request()->input('room_id'), $onlyVisible); if ($room == null) { redirect(page_link_to()); } diff --git a/includes/controller/shift_entries_controller.php b/includes/controller/shift_entries_controller.php index cb2d9bee..38aad5bb 100644 --- a/includes/controller/shift_entries_controller.php +++ b/includes/controller/shift_entries_controller.php @@ -11,9 +11,10 @@ function shift_entry_add_controller() { global $privileges, $user; + $request = request(); $shift_id = 0; - if (isset($_REQUEST['shift_id']) && preg_match('/^\d*$/', $_REQUEST['shift_id'])) { - $shift_id = $_REQUEST['shift_id']; + if ($request->has('shift_id') && preg_match('/^\d*$/', $request->input('shift_id'))) { + $shift_id = $request->input('shift_id'); } else { redirect(page_link_to('user_shifts')); } @@ -32,8 +33,8 @@ function shift_entry_add_controller() } $type_id = 0; - if (isset($_REQUEST['type_id']) && preg_match('/^\d*$/', $_REQUEST['type_id'])) { - $type_id = $_REQUEST['type_id']; + if ($request->has('type_id') && preg_match('/^\d*$/', $request->input('type_id'))) { + $type_id = $request->input('type_id'); } else { redirect(page_link_to('user_shifts')); } @@ -63,14 +64,14 @@ function shift_entry_add_controller() } if ( - isset($_REQUEST['user_id']) - && preg_match('/^\d*$/', $_REQUEST['user_id']) + $request->has('user_id') + && preg_match('/^\d*$/', $request->input('user_id')) && ( in_array('user_shifts_admin', $privileges) || in_array('shiftentry_edit_angeltype_supporter', $privileges) ) ) { - $user_id = $_REQUEST['user_id']; + $user_id = $request->input('user_id'); } else { $user_id = $user['UID']; } @@ -92,7 +93,7 @@ function shift_entry_add_controller() redirect(shift_link($shift)); } - if (isset($_REQUEST['submit'])) { + if ($request->has('submit')) { $selected_type_id = $type_id; if (in_array('user_shifts_admin', $privileges) || in_array('shiftentry_edit_angeltype_supporter', $privileges) @@ -103,14 +104,14 @@ function shift_entry_add_controller() } if ( - isset($_REQUEST['angeltype_id']) + $request->has('angeltype_id') && test_request_int('angeltype_id') && count(DB::select( 'SELECT `id` FROM `AngelTypes` WHERE `id`=? LIMIT 1', - [$_REQUEST['angeltype_id']] + [$request->input('angeltype_id')] )) > 0 ) { - $selected_type_id = $_REQUEST['angeltype_id']; + $selected_type_id = $request->input('angeltype_id'); } } @@ -124,7 +125,7 @@ function shift_entry_add_controller() $freeloaded = isset($shift['freeloaded']) ? $shift['freeloaded'] : false; $freeload_comment = isset($shift['freeload_comment']) ? $shift['freeload_comment'] : ''; if (in_array('user_shifts_admin', $privileges)) { - $freeloaded = isset($_REQUEST['freeloaded']); + $freeloaded = $request->has('freeloaded'); $freeload_comment = strip_request_item_nl('freeload_comment'); } @@ -236,11 +237,12 @@ function shift_entry_add_controller() function shift_entry_delete_controller() { global $privileges, $user; + $request = request(); - if (!isset($_REQUEST['entry_id']) || !test_request_int('entry_id')) { + if (!$request->has('entry_id') || !test_request_int('entry_id')) { redirect(page_link_to('user_shifts')); } - $entry_id = $_REQUEST['entry_id']; + $entry_id = $request->input('entry_id'); $shift_entry_source = DB::select(' SELECT diff --git a/includes/controller/shifts_controller.php b/includes/controller/shifts_controller.php index c8b6932a..21c6e160 100644 --- a/includes/controller/shifts_controller.php +++ b/includes/controller/shifts_controller.php @@ -44,15 +44,16 @@ function shift_edit_controller() // Schicht bearbeiten $msg = ''; $valid = true; + $request = request(); if (!in_array('admin_shifts', $privileges)) { redirect(page_link_to('user_shifts')); } - if (!isset($_REQUEST['edit_shift']) || !test_request_int('edit_shift')) { + if (!$request->has('edit_shift') || !test_request_int('edit_shift')) { redirect(page_link_to('user_shifts')); } - $shift_id = $_REQUEST['edit_shift']; + $shift_id = $request->input('edit_shift'); $shift = Shift($shift_id); @@ -73,33 +74,37 @@ function shift_edit_controller() $start = $shift['start']; $end = $shift['end']; - if (isset($_REQUEST['submit'])) { + if ($request->has('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('/^\d+$/', $_REQUEST['rid']) && isset($room[$_REQUEST['rid']])) { - $rid = $_REQUEST['rid']; + if ( + $request->has('rid') + && preg_match('/^\d+$/', $request->input('rid')) + && isset($room[$request->input('rid')]) + ) { + $rid = $request->input('rid'); } else { $valid = false; $msg .= error(_('Please select a room.'), true); } - if (isset($_REQUEST['shifttype_id']) && isset($shifttypes[$_REQUEST['shifttype_id']])) { - $shifttype_id = $_REQUEST['shifttype_id']; + if ($request->has('shifttype_id') && isset($shifttypes[$request->input('shifttype_id')])) { + $shifttype_id = $request->input('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'])) { + if ($request->has('start') && $tmp = parse_date('Y-m-d H:i', $request->input('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'])) { + if ($request->has('end') && $tmp = parse_date('Y-m-d H:i', $request->input('end'))) { $end = $tmp; } else { $valid = false; @@ -112,8 +117,8 @@ function shift_edit_controller() } 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]); + if ($request->has('type_' . $needed_angeltype_id) && test_request_int('type_' . $needed_angeltype_id)) { + $needed_angel_types[$needed_angeltype_id] = trim($request->input('type_' . $needed_angeltype_id)); } else { $valid = false; $msg .= error(sprintf( @@ -186,16 +191,17 @@ function shift_edit_controller() function shift_delete_controller() { global $privileges; + $request = request(); 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('/^\d*$/', $_REQUEST['delete_shift'])) { + if (!$request->has('delete_shift') || !preg_match('/^\d*$/', $request->input('delete_shift'))) { redirect(page_link_to('user_shifts')); } - $shift_id = $_REQUEST['delete_shift']; + $shift_id = $request->input('delete_shift'); $shift = Shift($shift_id); if ($shift == null) { @@ -203,7 +209,7 @@ function shift_delete_controller() } // Schicht löschen bestätigt - if (isset($_REQUEST['delete'])) { + if ($request->has('delete')) { Shift_delete($shift_id); engelsystem_log( @@ -232,16 +238,17 @@ function shift_delete_controller() function shift_controller() { global $user, $privileges; + $request = request(); if (!in_array('user_shifts', $privileges)) { redirect(page_link_to('?')); } - if (!isset($_REQUEST['shift_id'])) { + if (!$request->has('shift_id')) { redirect(page_link_to('user_shifts')); } - $shift = Shift($_REQUEST['shift_id']); + $shift = Shift($request->input('shift_id')); if ($shift == null) { error(_('Shift could not be found.')); redirect(page_link_to('user_shifts')); @@ -285,11 +292,12 @@ function shift_controller() */ function shifts_controller() { - if (!isset($_REQUEST['action'])) { + $request = request(); + if (!$request->has('action')) { redirect(page_link_to('user_shifts')); } - switch ($_REQUEST['action']) { + switch ($request->input('action')) { case 'view': return shift_controller(); case 'next': @@ -330,16 +338,17 @@ function shift_next_controller() function shifts_json_export_all_controller() { $api_key = config('api_key'); + $request = request(); if (empty($api_key)) { engelsystem_error('Config contains empty apikey.'); } - if (!isset($_REQUEST['api_key'])) { + if (!$request->has('api_key')) { engelsystem_error('Missing parameter api_key.'); } - if ($_REQUEST['api_key'] != $api_key) { + if ($request->input('api_key') != $api_key) { engelsystem_error('Invalid api_key.'); } @@ -359,12 +368,13 @@ function shifts_json_export_all_controller() function shifts_json_export_controller() { global $user; + $request = request(); - if (!isset($_REQUEST['key']) || !preg_match('/^[\da-f]{32}$/', $_REQUEST['key'])) { + if (!$request->has('key') || !preg_match('/^[\da-f]{32}$/', $request->input('key'))) { engelsystem_error('Missing key.'); } - $key = $_REQUEST['key']; + $key = $request->input('key'); $user = User_by_api_key($key); if ($user == null) { diff --git a/includes/controller/shifttypes_controller.php b/includes/controller/shifttypes_controller.php index 9a470e29..acdeb982 100644 --- a/includes/controller/shifttypes_controller.php +++ b/includes/controller/shifttypes_controller.php @@ -16,17 +16,18 @@ function shifttype_link($shifttype) */ function shifttype_delete_controller() { - if (!isset($_REQUEST['shifttype_id'])) { + $request = request(); + if (!$request->has('shifttype_id')) { redirect(page_link_to('shifttypes')); } - $shifttype = ShiftType($_REQUEST['shifttype_id']); + $shifttype = ShiftType($request->input('shifttype_id')); if ($shifttype == null) { redirect(page_link_to('shifttypes')); } - if (isset($_REQUEST['confirmed'])) { + if ($request->has('confirmed')) { $result = ShiftType_delete($shifttype['id']); if (empty($result)) { engelsystem_error('Unable to delete shifttype.'); @@ -56,9 +57,10 @@ function shifttype_edit_controller() $description = ''; $angeltypes = AngelTypes(); + $request = request(); - if (isset($_REQUEST['shifttype_id'])) { - $shifttype = ShiftType($_REQUEST['shifttype_id']); + if ($request->has('shifttype_id')) { + $shifttype = ShiftType($request->input('shifttype_id')); if ($shifttype == null) { error(_('Shifttype not found.')); redirect(page_link_to('shifttypes')); @@ -69,23 +71,23 @@ function shifttype_edit_controller() $description = $shifttype['description']; } - if (isset($_REQUEST['submit'])) { + if ($request->has('submit')) { $valid = true; - if (isset($_REQUEST['name']) && $_REQUEST['name'] != '') { + if ($request->has('name') && $request->input('name') != '') { $name = strip_request_item('name'); } else { $valid = false; error(_('Please enter a name.')); } - if (isset($_REQUEST['angeltype_id']) && preg_match('/^\d+$/', $_REQUEST['angeltype_id'])) { - $angeltype_id = $_REQUEST['angeltype_id']; + if ($request->has('angeltype_id') && preg_match('/^\d+$/', $request->input('angeltype_id'))) { + $angeltype_id = $request->input('angeltype_id'); } else { $angeltype_id = null; } - if (isset($_REQUEST['description'])) { + if ($request->has('description')) { $description = strip_request_item_nl('description'); } @@ -120,10 +122,11 @@ function shifttype_edit_controller() */ function shifttype_controller() { - if (!isset($_REQUEST['shifttype_id'])) { + $request = request(); + if (!$request->has('shifttype_id')) { redirect(page_link_to('shifttypes')); } - $shifttype = ShiftType($_REQUEST['shifttype_id']); + $shifttype = ShiftType($request->input('shifttype_id')); if ($shifttype == null) { redirect(page_link_to('shifttypes')); } @@ -174,11 +177,13 @@ function shifttypes_title() */ function shifttypes_controller() { - if (!isset($_REQUEST['action'])) { - $_REQUEST['action'] = 'list'; + $request = request(); + $action = 'list'; + if ($request->has('action')) { + $action = $request->input('action'); } - switch ($_REQUEST['action']) { + switch ($action) { case 'view': return shifttype_controller(); case 'edit': diff --git a/includes/controller/user_angeltypes_controller.php b/includes/controller/user_angeltypes_controller.php index f31aeecd..41185552 100644 --- a/includes/controller/user_angeltypes_controller.php +++ b/includes/controller/user_angeltypes_controller.php @@ -38,13 +38,14 @@ function user_angeltypes_unconfirmed_hint() function user_angeltypes_delete_all_controller() { global $user; + $request = request(); - if (!isset($_REQUEST['angeltype_id'])) { + if (!$request->has('angeltype_id')) { error(_('Angeltype doesn\'t exist.')); redirect(page_link_to('angeltypes')); } - $angeltype = AngelType($_REQUEST['angeltype_id']); + $angeltype = AngelType($request->input('angeltype_id')); if ($angeltype == null) { error(_('Angeltype doesn\'t exist.')); redirect(page_link_to('angeltypes')); @@ -55,7 +56,7 @@ function user_angeltypes_delete_all_controller() redirect(page_link_to('angeltypes')); } - if (isset($_REQUEST['confirmed'])) { + if ($request->has('confirmed')) { UserAngelTypes_delete_all($angeltype['id']); engelsystem_log(sprintf('Denied all users for angeltype %s', AngelType_name_render($angeltype))); @@ -77,13 +78,14 @@ function user_angeltypes_delete_all_controller() function user_angeltypes_confirm_all_controller() { global $user, $privileges; + $request = request(); - if (!isset($_REQUEST['angeltype_id'])) { + if (!$request->has('angeltype_id')) { error(_('Angeltype doesn\'t exist.')); redirect(page_link_to('angeltypes')); } - $angeltype = AngelType($_REQUEST['angeltype_id']); + $angeltype = AngelType($request->input('angeltype_id')); if ($angeltype == null) { error(_('Angeltype doesn\'t exist.')); redirect(page_link_to('angeltypes')); @@ -100,7 +102,7 @@ function user_angeltypes_confirm_all_controller() redirect(page_link_to('angeltypes')); } - if (isset($_REQUEST['confirmed'])) { + if ($request->has('confirmed')) { UserAngelTypes_confirm_all($angeltype['id'], $user); engelsystem_log(sprintf('Confirmed all users for angeltype %s', AngelType_name_render($angeltype))); @@ -122,13 +124,14 @@ function user_angeltypes_confirm_all_controller() function user_angeltype_confirm_controller() { global $user; + $request = request(); - if (!isset($_REQUEST['user_angeltype_id'])) { + if (!$request->has('user_angeltype_id')) { error(_('User angeltype doesn\'t exist.')); redirect(page_link_to('angeltypes')); } - $user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']); + $user_angeltype = UserAngelType($request->input('user_angeltype_id')); if ($user_angeltype == null) { error(_('User angeltype doesn\'t exist.')); redirect(page_link_to('angeltypes')); @@ -151,7 +154,7 @@ function user_angeltype_confirm_controller() redirect(page_link_to('angeltypes')); } - if (isset($_REQUEST['confirmed'])) { + if ($request->has('confirmed')) { UserAngelType_confirm($user_angeltype['id'], $user); engelsystem_log(sprintf( @@ -181,13 +184,14 @@ function user_angeltype_confirm_controller() function user_angeltype_delete_controller() { global $user; + $request = request(); - if (!isset($_REQUEST['user_angeltype_id'])) { + if (!$request->has('user_angeltype_id')) { error(_('User angeltype doesn\'t exist.')); redirect(page_link_to('angeltypes')); } - $user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']); + $user_angeltype = UserAngelType($request->input('user_angeltype_id')); if ($user_angeltype == null) { error(_('User angeltype doesn\'t exist.')); redirect(page_link_to('angeltypes')); @@ -210,7 +214,7 @@ function user_angeltype_delete_controller() redirect(page_link_to('angeltypes')); } - if (isset($_REQUEST['confirmed'])) { + if ($request->has('confirmed')) { $result = UserAngelType_delete($user_angeltype); if ($result === false) { engelsystem_error('Unable to delete user angeltype.'); @@ -238,25 +242,26 @@ function user_angeltype_update_controller() { global $privileges; $supporter = false; + $request = request(); 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'])) { + if (!$request->has('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'; + if ($request->has('supporter') && preg_match('/^[01]$/', $request->input('supporter'))) { + $supporter = $request->input('supporter') == '1'; } else { error(_('No supporter update given.')); redirect(page_link_to('angeltypes')); } - $user_angeltype = UserAngelType($_REQUEST['user_angeltype_id']); + $user_angeltype = UserAngelType($request->input('user_angeltype_id')); if ($user_angeltype == null) { error(_('User angeltype doesn\'t exist.')); redirect(page_link_to('angeltypes')); @@ -274,7 +279,7 @@ function user_angeltype_update_controller() redirect(page_link_to('angeltypes')); } - if (isset($_REQUEST['confirmed'])) { + if ($request->has('confirmed')) { UserAngelType_update($user_angeltype['id'], $supporter); $success_message = sprintf( @@ -300,7 +305,6 @@ function user_angeltype_update_controller() function user_angeltype_add_controller() { global $user; - $angeltype = load_angeltype(); // User is joining by itself @@ -316,7 +320,7 @@ 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'])) { + if (request()->has('submit')) { $user_source = load_user(); if (!UserAngelType_exists($user_source, $angeltype)) { @@ -366,7 +370,7 @@ function user_angeltype_join_controller($angeltype) redirect(page_link_to('angeltypes')); } - if (isset($_REQUEST['confirmed'])) { + if (request()->has('confirmed')) { $user_angeltype_id = UserAngelType_create($user, $angeltype); $success_message = sprintf(_('You joined %s.'), $angeltype['name']); @@ -398,11 +402,12 @@ function user_angeltype_join_controller($angeltype) */ function user_angeltypes_controller() { - if (!isset($_REQUEST['action'])) { + $request = request(); + if (!$request->has('action')) { redirect(page_link_to('angeltypes')); } - switch ($_REQUEST['action']) { + switch ($request->input('action')) { case 'delete_all': return user_angeltypes_delete_all_controller(); case 'confirm_all': diff --git a/includes/controller/user_driver_licenses_controller.php b/includes/controller/user_driver_licenses_controller.php index 3098c8ce..fef278dd 100644 --- a/includes/controller/user_driver_licenses_controller.php +++ b/includes/controller/user_driver_licenses_controller.php @@ -74,11 +74,11 @@ function user_driver_license_edit_link($user = null) function user_driver_license_load_user() { global $user; - + $request = request(); $user_source = $user; - if (isset($_REQUEST['user_id'])) { - $user_source = User($_REQUEST['user_id']); + if ($request->has('user_id')) { + $user_source = User($request->input('user_id')); if ($user_source == null) { redirect(user_driver_license_edit_link()); } @@ -95,7 +95,7 @@ function user_driver_license_load_user() function user_driver_license_edit_controller() { global $privileges, $user; - + $request = request(); $user_source = user_driver_license_load_user(); // only privilege admin_user can edit other users driver license information @@ -111,15 +111,15 @@ function user_driver_license_edit_controller() $wants_to_drive = true; } - if (isset($_REQUEST['submit'])) { - $wants_to_drive = isset($_REQUEST['wants_to_drive']); + if ($request->has('submit')) { + $wants_to_drive = $request->has('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']); + $user_driver_license['has_car'] = $request->has('has_car'); + $user_driver_license['has_license_car'] = $request->has('has_license_car'); + $user_driver_license['has_license_3_5t_transporter'] = $request->has('has_license_3_5t_transporter'); + $user_driver_license['has_license_7_5t_truck'] = $request->has('has_license_7_5t_truck'); + $user_driver_license['has_license_12_5t_truck'] = $request->has('has_license_12_5t_truck'); + $user_driver_license['has_license_forklift'] = $request->has('has_license_forklift'); if (UserDriverLicense_valid($user_driver_license)) { if ($user_driver_license['user_id'] == null) { diff --git a/includes/controller/users_controller.php b/includes/controller/users_controller.php index 84b6bbda..96e2c81b 100644 --- a/includes/controller/users_controller.php +++ b/includes/controller/users_controller.php @@ -12,16 +12,18 @@ use Engelsystem\ShiftsFilter; function users_controller() { global $user; + $request = request(); if (!isset($user)) { redirect(page_link_to('')); } - if (!isset($_REQUEST['action'])) { - $_REQUEST['action'] = 'list'; + $action = 'list'; + if ($request->has('action')) { + $action = $request->input('action'); } - switch ($_REQUEST['action']) { + switch ($action) { case 'view': return user_controller(); case 'delete': @@ -42,9 +44,10 @@ function users_controller() function user_delete_controller() { global $privileges, $user; + $request = request(); - if (isset($_REQUEST['user_id'])) { - $user_source = User($_REQUEST['user_id']); + if ($request->has('user_id')) { + $user_source = User($request->get('user_id')); } else { $user_source = $user; } @@ -59,11 +62,14 @@ function user_delete_controller() redirect(user_link($user)); } - if (isset($_REQUEST['submit'])) { + if ($request->has('submit')) { $valid = true; - if (!(isset($_REQUEST['password']) && verify_password($_REQUEST['password'], $user['Passwort'], - $user['UID'])) + if ( + !( + $request->has('password') + && verify_password($request->input('password'), $user['Passwort'], $user['UID']) + ) ) { $valid = false; error(_('Your password is incorrect. Please try it again.')); @@ -130,9 +136,10 @@ function user_link($user) function user_edit_vouchers_controller() { global $privileges, $user; + $request = request(); - if (isset($_REQUEST['user_id'])) { - $user_source = User($_REQUEST['user_id']); + if ($request->has('user_id')) { + $user_source = User($request->input('user_id')); } else { $user_source = $user; } @@ -141,12 +148,16 @@ function user_edit_vouchers_controller() redirect(page_link_to('')); } - if (isset($_REQUEST['submit'])) { + if ($request->has('submit')) { $valid = true; $vouchers = ''; - if (isset($_REQUEST['vouchers']) && test_request_int('vouchers') && trim($_REQUEST['vouchers']) >= 0) { - $vouchers = trim($_REQUEST['vouchers']); + if ( + $request->has('vouchers') + && test_request_int('vouchers') + && trim($request->input('vouchers')) >= 0 + ) { + $vouchers = trim($request->input('vouchers')); } else { $valid = false; error(_('Please enter a valid number of vouchers.')); @@ -180,10 +191,11 @@ function user_edit_vouchers_controller() function user_controller() { global $privileges, $user; + $request = request(); $user_source = $user; - if (isset($_REQUEST['user_id'])) { - $user_source = User($_REQUEST['user_id']); + if ($request->has('user_id')) { + $user_source = User($request->input('user_id')); if ($user_source == null) { error(_('User not found.')); redirect('?'); @@ -241,14 +253,15 @@ function user_controller() function users_list_controller() { global $privileges; + $request = request(); 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']; + if ($request->has('OrderBy') && in_array($request->input('OrderBy'), User_sortable_columns())) { + $order_by = $request->input('OrderBy'); } $users = Users($order_by); @@ -282,20 +295,21 @@ function users_list_controller() */ function user_password_recovery_set_new_controller() { - $user_source = User_by_password_recovery_token($_REQUEST['token']); + $request = request(); + $user_source = User_by_password_recovery_token($request->input('token')); if ($user_source == null) { error(_('Token is not correct.')); redirect(page_link_to('login')); } - if (isset($_REQUEST['submit'])) { + if ($request->has('submit')) { $valid = true; if ( - isset($_REQUEST['password']) - && strlen($_REQUEST['password']) >= config('min_password_length') + $request->has('password') + && strlen($request->post('password')) >= config('min_password_length') ) { - if ($_REQUEST['password'] != $_REQUEST['password2']) { + if ($request->post('password') != $request->post('password2')) { $valid = false; error(_('Your passwords don\'t match.')); } @@ -305,7 +319,7 @@ function user_password_recovery_set_new_controller() } if ($valid) { - set_password($user_source['UID'], $_REQUEST['password']); + set_password($user_source['UID'], $request->post('password')); success(_('Password saved.')); redirect(page_link_to('login')); } @@ -321,10 +335,11 @@ function user_password_recovery_set_new_controller() */ function user_password_recovery_start_controller() { - if (isset($_REQUEST['submit'])) { + $request = request(); + if ($request->has('submit')) { $valid = true; - if (isset($_REQUEST['email']) && strlen(strip_request_item('email')) > 0) { + if ($request->has('email') && strlen(strip_request_item('email')) > 0) { $email = strip_request_item('email'); if (check_email($email)) { $user_source = User_by_email($email); @@ -367,7 +382,7 @@ function user_password_recovery_start_controller() */ function user_password_recovery_controller() { - if (isset($_REQUEST['token'])) { + if (request()->has('token')) { return user_password_recovery_set_new_controller(); } @@ -391,11 +406,12 @@ function user_password_recovery_title() */ function load_user() { - if (!isset($_REQUEST['user_id'])) { + $request = request(); + if (!$request->has('user_id')) { redirect(page_link_to()); } - $user = User($_REQUEST['user_id']); + $user = User($request->input('user_id')); if ($user == null) { error(_('User doesn\'t exist.')); diff --git a/includes/engelsystem_provider.php b/includes/engelsystem_provider.php index a818e4cd..edfae705 100644 --- a/includes/engelsystem_provider.php +++ b/includes/engelsystem_provider.php @@ -3,6 +3,7 @@ use Engelsystem\Config\Config; use Engelsystem\Database\Db; use Engelsystem\Exceptions\Handler as ExceptionHandler; +use Engelsystem\Http\Request; /** * This file includes all needed functions, connects to the db etc. @@ -31,6 +32,13 @@ if (file_exists(__DIR__ . '/../config/config.php')) { date_default_timezone_set($config->get('timezone')); +/** + * Initialize Request + */ +$request = new Request(); +$request->create(); +$request::setInstance($request); + /** * Check for maintenance */ diff --git a/includes/helper/internationalization_helper.php b/includes/helper/internationalization_helper.php index ed16de15..d2dbcdbd 100644 --- a/includes/helper/internationalization_helper.php +++ b/includes/helper/internationalization_helper.php @@ -26,12 +26,12 @@ function locale_short() function gettext_init() { $locales = config('locales'); - $default_locale = config('default_locale'); + $request = request(); - if (isset($_REQUEST['set_locale']) && isset($locales[$_REQUEST['set_locale']])) { - $_SESSION['locale'] = $_REQUEST['set_locale']; + if ($request->has('set_locale') && isset($locales[$request->input('set_locale')])) { + $_SESSION['locale'] = $request->input('set_locale'); } elseif (!isset($_SESSION['locale'])) { - $_SESSION['locale'] = $default_locale; + $_SESSION['locale'] = config('default_locale'); } gettext_locale(); diff --git a/includes/pages/admin_active.php b/includes/pages/admin_active.php index d21afabe..2e06f90d 100644 --- a/includes/pages/admin_active.php +++ b/includes/pages/admin_active.php @@ -17,6 +17,7 @@ function admin_active() { $tshirt_sizes = config('tshirt_sizes'); $shift_sum_formula = config('shift_sum_formula'); + $request = request(); $msg = ''; $search = ''; @@ -25,16 +26,16 @@ function admin_active() $limit = ''; $set_active = ''; - if (isset($_REQUEST['search'])) { + if ($request->has('search')) { $search = strip_request_item('search'); } - $show_all_shifts = isset($_REQUEST['show_all_shifts']); + $show_all_shifts = $request->has('show_all_shifts'); - if (isset($_REQUEST['set_active'])) { + if ($request->has('set_active')) { $valid = true; - if (isset($_REQUEST['count']) && preg_match('/^\d+$/', $_REQUEST['count'])) { + if ($request->has('count') && preg_match('/^\d+$/', $request->input('count'))) { $count = strip_request_item('count'); if ($count < $forced_count) { error(sprintf( @@ -51,7 +52,7 @@ function admin_active() if ($valid) { $limit = ' LIMIT ' . $count; } - if (isset($_REQUEST['ack'])) { + if ($request->has('ack')) { DB::update('UPDATE `User` SET `Aktiv` = 0 WHERE `Tshirt` = 0'); $users = DB::select(sprintf(' SELECT @@ -89,8 +90,8 @@ function admin_active() } } - if (isset($_REQUEST['active']) && preg_match('/^\d+$/', $_REQUEST['active'])) { - $user_id = $_REQUEST['active']; + if ($request->has('active') && preg_match('/^\d+$/', $request->input('active'))) { + $user_id = $request->input('active'); $user_source = User($user_id); if ($user_source != null) { DB::update('UPDATE `User` SET `Aktiv`=1 WHERE `UID`=? LIMIT 1', [$user_id]); @@ -99,8 +100,8 @@ function admin_active() } else { $msg = error(_('Angel not found.'), true); } - } elseif (isset($_REQUEST['not_active']) && preg_match('/^\d+$/', $_REQUEST['not_active'])) { - $user_id = $_REQUEST['not_active']; + } elseif ($request->has('not_active') && preg_match('/^\d+$/', $request->input('not_active'))) { + $user_id = $request->input('not_active'); $user_source = User($user_id); if ($user_source != null) { DB::update('UPDATE `User` SET `Aktiv`=0 WHERE `UID`=? LIMIT 1', [$user_id]); @@ -109,8 +110,8 @@ function admin_active() } else { $msg = error(_('Angel not found.'), true); } - } elseif (isset($_REQUEST['tshirt']) && preg_match('/^\d+$/', $_REQUEST['tshirt'])) { - $user_id = $_REQUEST['tshirt']; + } elseif ($request->has('tshirt') && preg_match('/^\d+$/', $request->input('tshirt'))) { + $user_id = $request->input('tshirt'); $user_source = User($user_id); if ($user_source != null) { DB::update('UPDATE `User` SET `Tshirt`=1 WHERE `UID`=? LIMIT 1', [$user_id]); @@ -119,8 +120,8 @@ function admin_active() } else { $msg = error('Angel not found.', true); } - } elseif (isset($_REQUEST['not_tshirt']) && preg_match('/^\d+$/', $_REQUEST['not_tshirt'])) { - $user_id = $_REQUEST['not_tshirt']; + } elseif ($request->has('not_tshirt') && preg_match('/^\d+$/', $request->input('not_tshirt'))) { + $user_id = $request->input('not_tshirt'); $user_source = User($user_id); if ($user_source != null) { DB::update('UPDATE `User` SET `Tshirt`=0 WHERE `UID`=? LIMIT 1', [$user_id]); diff --git a/includes/pages/admin_arrive.php b/includes/pages/admin_arrive.php index 77155dae..ebeccb8c 100644 --- a/includes/pages/admin_arrive.php +++ b/includes/pages/admin_arrive.php @@ -17,12 +17,14 @@ function admin_arrive() { $msg = ''; $search = ''; - if (isset($_REQUEST['search'])) { + $request = request(); + + if ($request->has('search')) { $search = strip_request_item('search'); } - if (isset($_REQUEST['reset']) && preg_match('/^\d*$/', $_REQUEST['reset'])) { - $user_id = $_REQUEST['reset']; + if ($request->has('reset') && preg_match('/^\d*$/', $request->input('reset'))) { + $user_id = $request->input('reset'); $user_source = User($user_id); if ($user_source != null) { DB::update(' @@ -37,8 +39,8 @@ function admin_arrive() } else { $msg = error(_('Angel not found.'), true); } - } elseif (isset($_REQUEST['arrived']) && preg_match('/^\d*$/', $_REQUEST['arrived'])) { - $user_id = $_REQUEST['arrived']; + } elseif ($request->has('arrived') && preg_match('/^\d*$/', $request->input('arrived'))) { + $user_id = $request->input('arrived'); $user_source = User($user_id); if ($user_source != null) { DB::update(' diff --git a/includes/pages/admin_free.php b/includes/pages/admin_free.php index daaead22..ebf227a4 100644 --- a/includes/pages/admin_free.php +++ b/includes/pages/admin_free.php @@ -16,20 +16,20 @@ function admin_free_title() function admin_free() { global $privileges; + $request = request(); $search = ''; - if (isset($_REQUEST['search'])) { + if ($request->has('search')) { $search = strip_request_item('search'); } $angelTypeSearch = ''; - if (empty($_REQUEST['angeltype'])) { - $_REQUEST['angeltype'] = ''; - } else { + $angelType = $request->input('angeltype', ''); + if (!empty($angelType)) { $angelTypeSearch = ' INNER JOIN `UserAngelTypes` ON (`UserAngelTypes`.`angeltype_id` = ' - . DB::getPdo()->quote($_REQUEST['angeltype']) + . DB::getPdo()->quote($angelType) . ' AND `UserAngelTypes`.`user_id` = `User`.`UID`'; - if (isset($_REQUEST['confirmed_only'])) { + if ($request->has('confirmed_only')) { $angelTypeSearch .= ' AND `UserAngelTypes`.`confirm_user_id`'; } $angelTypeSearch .= ') '; @@ -105,10 +105,10 @@ function admin_free() form_text('search', _('Search'), $search) ]), div('col-md-4', [ - form_select('angeltype', _('Angeltype'), $angel_types, $_REQUEST['angeltype']) + form_select('angeltype', _('Angeltype'), $angel_types, $angelType) ]), div('col-md-2', [ - form_checkbox('confirmed_only', _('Only confirmed'), isset($_REQUEST['confirmed_only'])) + form_checkbox('confirmed_only', _('Only confirmed'), $request->has('confirmed_only')) ]), div('col-md-2', [ form_submit('submit', _('Search')) diff --git a/includes/pages/admin_groups.php b/includes/pages/admin_groups.php index 4011ccf1..c483a79d 100644 --- a/includes/pages/admin_groups.php +++ b/includes/pages/admin_groups.php @@ -16,8 +16,10 @@ function admin_groups_title() function admin_groups() { $html = ''; + $request = request(); $groups = DB::select('SELECT * FROM `Groups` ORDER BY `Name`'); - if (!isset($_REQUEST['action'])) { + + if (!$request->has('action')) { $groups_table = []; foreach ($groups as $group) { $privileges = DB::select(' @@ -51,10 +53,10 @@ function admin_groups() ], $groups_table) ]); } else { - switch ($_REQUEST['action']) { + switch ($request->input('action')) { case 'edit': - if (isset($_REQUEST['id']) && preg_match('/^-\d{1,11}$/', $_REQUEST['id'])) { - $group_id = $_REQUEST['id']; + if ($request->has('id') && preg_match('/^-\d{1,11}$/', $request->input('id'))) { + $group_id = $request->input('id'); } else { return error('Incomplete call, missing Groups ID.', true); } @@ -99,21 +101,22 @@ function admin_groups() break; case 'save': - if (isset($_REQUEST['id']) && preg_match('/^-\d{1,11}$/', $_REQUEST['id'])) { - $group_id = $_REQUEST['id']; + if ($request->has('id') && preg_match('/^-\d{1,11}$/', $request->input('id'))) { + $group_id = $request->input('id'); } else { return error('Incomplete call, missing Groups ID.', true); } $group = DB::select('SELECT * FROM `Groups` WHERE `UID`=? LIMIT 1', [$group_id]); - if (!is_array($_REQUEST['privileges'])) { - $_REQUEST['privileges'] = []; + $privileges = $request->get('privileges'); + if (!is_array($privileges)) { + $privileges = []; } if (!empty($group)) { $group = array_shift($group); DB::delete('DELETE FROM `GroupPrivileges` WHERE `group_id`=?', [$group_id]); $privilege_names = []; - foreach ($_REQUEST['privileges'] as $privilege) { + foreach ($privileges as $privilege) { if (preg_match('/^\d{1,}$/', $privilege)) { $group_privileges_source = DB::select( 'SELECT `name` FROM `Privileges` WHERE `id`=? LIMIT 1', diff --git a/includes/pages/admin_import.php b/includes/pages/admin_import.php index 7a246b4b..3cbed9f9 100644 --- a/includes/pages/admin_import.php +++ b/includes/pages/admin_import.php @@ -15,21 +15,21 @@ function admin_import_title() */ function admin_import() { - global $rooms_import; - global $user; + global $rooms_import, $user; $html = ''; $import_dir = __DIR__ . '/../../import'; + $request = request(); $step = 'input'; if ( - isset($_REQUEST['step']) - && in_array($step, [ + $request->has('step') + && in_array($request->input('step'), [ 'input', 'check', 'import' ]) ) { - $step = $_REQUEST['step']; + $step = $request->input('step'); } if ($test_handle = @fopen($import_dir . '/tmp', 'w')) { @@ -57,25 +57,25 @@ function admin_import() case 'input': $valid = false; - if (isset($_REQUEST['submit'])) { + if ($request->has('submit')) { $valid = true; - if (isset($_REQUEST['shifttype_id']) && isset($shifttypes[$_REQUEST['shifttype_id']])) { - $shifttype_id = $_REQUEST['shifttype_id']; + if ($request->has('shifttype_id') && isset($shifttypes[$request->input('shifttype_id')])) { + $shifttype_id = $request->input('shifttype_id'); } else { $valid = false; error(_('Please select a shift type.')); } - if (isset($_REQUEST['add_minutes_start']) && is_numeric(trim($_REQUEST['add_minutes_start']))) { - $add_minutes_start = trim($_REQUEST['add_minutes_start']); + if ($request->has('add_minutes_start') && is_numeric(trim($request->input('add_minutes_start')))) { + $add_minutes_start = trim($request->input('add_minutes_start')); } else { $valid = false; error(_('Please enter an amount of minutes to add to a talk\'s begin.')); } - if (isset($_REQUEST['add_minutes_end']) && is_numeric(trim($_REQUEST['add_minutes_end']))) { - $add_minutes_end = trim($_REQUEST['add_minutes_end']); + if ($request->has('add_minutes_end') && is_numeric(trim($request->input('add_minutes_end')))) { + $add_minutes_end = trim($request->input('add_minutes_end')); } else { $valid = false; error(_('Please enter an amount of minutes to add to a talk\'s end.')); @@ -133,22 +133,22 @@ function admin_import() redirect(page_link_to('admin_import')); } - if (isset($_REQUEST['shifttype_id']) && isset($shifttypes[$_REQUEST['shifttype_id']])) { - $shifttype_id = $_REQUEST['shifttype_id']; + if ($request->has('shifttype_id') && isset($shifttypes[$request->input('shifttype_id')])) { + $shifttype_id = $request->input('shifttype_id'); } else { error(_('Please select a shift type.')); redirect(page_link_to('admin_import')); } - if (isset($_REQUEST['add_minutes_start']) && is_numeric(trim($_REQUEST['add_minutes_start']))) { - $add_minutes_start = trim($_REQUEST['add_minutes_start']); + if ($request->has('add_minutes_start') && is_numeric(trim($request->input('add_minutes_start')))) { + $add_minutes_start = trim($request->input('add_minutes_start')); } else { error(_('Please enter an amount of minutes to add to a talk\'s begin.')); redirect(page_link_to('admin_import')); } - if (isset($_REQUEST['add_minutes_end']) && is_numeric(trim($_REQUEST['add_minutes_end']))) { - $add_minutes_end = trim($_REQUEST['add_minutes_end']); + if ($request->has('add_minutes_end') && is_numeric(trim($request->input(('add_minutes_end'))))) { + $add_minutes_end = trim($request->input('add_minutes_end')); } else { error(_('Please enter an amount of minutes to add to a talk\'s end.')); redirect(page_link_to('admin_import')); @@ -227,22 +227,22 @@ function admin_import() redirect(page_link_to('admin_import')); } - if (isset($_REQUEST['shifttype_id']) && isset($shifttypes[$_REQUEST['shifttype_id']])) { - $shifttype_id = $_REQUEST['shifttype_id']; + if ($request->has('shifttype_id') && isset($shifttypes[$request->input('shifttype_id')])) { + $shifttype_id = $request->input('shifttype_id'); } else { error(_('Please select a shift type.')); redirect(page_link_to('admin_import')); } - if (isset($_REQUEST['add_minutes_start']) && is_numeric(trim($_REQUEST['add_minutes_start']))) { - $add_minutes_start = trim($_REQUEST['add_minutes_start']); + if ($request->has('add_minutes_start') && is_numeric(trim($request->input('add_minutes_start')))) { + $add_minutes_start = trim($request->input('add_minutes_start')); } else { error(_('Please enter an amount of minutes to add to a talk\'s begin.')); redirect(page_link_to('admin_import')); } - if (isset($_REQUEST['add_minutes_end']) && is_numeric(trim($_REQUEST['add_minutes_end']))) { - $add_minutes_end = trim($_REQUEST['add_minutes_end']); + if ($request->has('add_minutes_end') && is_numeric(trim($request->input('add_minutes_end')))) { + $add_minutes_end = trim($request->input('add_minutes_end')); } else { error(_('Please enter an amount of minutes to add to a talk\'s end.')); redirect(page_link_to('admin_import')); diff --git a/includes/pages/admin_log.php b/includes/pages/admin_log.php index 9e5e5827..03c9abb0 100644 --- a/includes/pages/admin_log.php +++ b/includes/pages/admin_log.php @@ -14,7 +14,7 @@ function admin_log_title() function admin_log() { $filter = ''; - if (isset($_REQUEST['keyword'])) { + if (request()->has('keyword')) { $filter = strip_request_item('keyword'); } $log_entries_source = LogEntries_filter($filter); diff --git a/includes/pages/admin_news.php b/includes/pages/admin_news.php index bc242831..7f8ca1ba 100644 --- a/includes/pages/admin_news.php +++ b/includes/pages/admin_news.php @@ -8,14 +8,15 @@ use Engelsystem\Database\DB; function admin_news() { global $user; + $request = request(); - if (!isset($_GET['action'])) { + if (!$request->has('action')) { redirect(page_link_to('news')); } $html = '

' . _('Edit news entry') . '

' . msg(); - if (isset($_REQUEST['id']) && preg_match('/^\d{1,11}$/', $_REQUEST['id'])) { - $news_id = $_REQUEST['id']; + if ($request->has('id') && preg_match('/^\d{1,11}$/', $request->input('id'))) { + $news_id = $request->input('id'); } else { return error('Incomplete call, missing News ID.', true); } @@ -25,7 +26,7 @@ function admin_news() return error('No News found.', true); } - switch ($_REQUEST['action']) { + switch ($request->input('action')) { case 'edit': $news = array_shift($news); $user_source = User($news['UID']); @@ -56,14 +57,14 @@ function admin_news() ', [ time(), - $_POST["eBetreff"], - $_POST["eText"], + $request->post('eBetreff'), + $request->post('eText'), $user['UID'], - isset($_POST["eTreffen"]) ? 1 : 0, + $request->has('eTreffen') ? 1 : 0, $news_id ] ); - engelsystem_log('News updated: ' . $_POST['eBetreff']); + engelsystem_log('News updated: ' . $request->post('eBetreff')); success(_('News entry updated.')); redirect(page_link_to('news')); break; diff --git a/includes/pages/admin_questions.php b/includes/pages/admin_questions.php index 098701e3..d05bace6 100644 --- a/includes/pages/admin_questions.php +++ b/includes/pages/admin_questions.php @@ -38,8 +38,9 @@ function admin_new_questions() function admin_questions() { global $user; + $request = request(); - if (!isset($_REQUEST['action'])) { + if (!$request->has('action')) { $unanswered_questions_table = []; $questions = DB::select('SELECT * FROM `Questions` WHERE `AID` IS NULL'); foreach ($questions as $question) { @@ -96,10 +97,10 @@ function admin_questions() ], $answered_questions_table) ]); } else { - switch ($_REQUEST['action']) { + switch ($request->input('action')) { case 'answer': - if (isset($_REQUEST['id']) && preg_match('/^\d{1,11}$/', $_REQUEST['id'])) { - $question_id = $_REQUEST['id']; + if ($request->has('id') && preg_match('/^\d{1,11}$/', $request->input('id'))) { + $question_id = $request->input('id'); } else { return error('Incomplete call, missing Question ID.', true); } @@ -112,7 +113,7 @@ function admin_questions() $answer = trim( preg_replace("/([^\p{L}\p{P}\p{Z}\p{N}\n]{1,})/ui", '', - strip_tags($_REQUEST['answer']) + strip_tags($request->input('answer')) )); if ($answer != '') { @@ -138,8 +139,8 @@ function admin_questions() } break; case 'delete': - if (isset($_REQUEST['id']) && preg_match('/^\d{1,11}$/', $_REQUEST['id'])) { - $question_id = $_REQUEST['id']; + if ($request->has('id') && preg_match('/^\d{1,11}$/', $request->input('id'))) { + $question_id = $request->input('id'); } else { return error('Incomplete call, missing Question ID.', true); } diff --git a/includes/pages/admin_rooms.php b/includes/pages/admin_rooms.php index d483f99e..3045242b 100644 --- a/includes/pages/admin_rooms.php +++ b/includes/pages/admin_rooms.php @@ -17,6 +17,8 @@ function admin_rooms() { $rooms_source = DB::select('SELECT * FROM `Room` ORDER BY `Name`'); $rooms = []; + $request = request(); + foreach ($rooms_source as $room) { $rooms[] = [ 'name' => Room_name_render($room), @@ -30,7 +32,7 @@ function admin_rooms() } $room = null; - if (isset($_REQUEST['show'])) { + if ($request->has('show')) { $msg = ''; $name = ''; $from_pentabarf = ''; @@ -47,7 +49,7 @@ function admin_rooms() } if (test_request_int('id')) { - $room = Room($_REQUEST['id'], false); + $room = Room($request->input('id'), false); if ($room === false) { engelsystem_error('Unable to load room.'); } @@ -55,7 +57,7 @@ function admin_rooms() redirect(page_link_to('admin_rooms')); } - $room_id = $_REQUEST['id']; + $room_id = $request->input('id'); $name = $room['Name']; $from_pentabarf = $room['FromPentabarf']; $public = $room['show']; @@ -70,11 +72,11 @@ function admin_rooms() } } - if ($_REQUEST['show'] == 'edit') { - if (isset($_REQUEST['submit'])) { + if ($request->input('show') == 'edit') { + if ($request->has('submit')) { $valid = true; - if (isset($_REQUEST['name']) && strlen(strip_request_item('name')) > 0) { + if ($request->has('name') && strlen(strip_request_item('name')) > 0) { $name = strip_request_item('name'); if ( isset($room) @@ -91,19 +93,17 @@ function admin_rooms() $msg .= error(_('Please enter a name.'), true); } - if (isset($_REQUEST['from_pentabarf'])) { + $from_pentabarf = ''; + if ($request->has('from_pentabarf')) { $from_pentabarf = 'Y'; - } else { - $from_pentabarf = ''; } - if (isset($_REQUEST['public'])) { + $public = ''; + if ($request->has('public')) { $public = 'Y'; - } else { - $public = ''; } - if (isset($_REQUEST['number'])) { + if ($request->has('number')) { $number = strip_request_item('number'); } else { $valid = false; @@ -111,10 +111,10 @@ function admin_rooms() foreach ($angeltypes as $angeltype_id => $angeltype) { if ( - isset($_REQUEST['angeltype_count_' . $angeltype_id]) - && preg_match('/^\d{1,4}$/', $_REQUEST['angeltype_count_' . $angeltype_id]) + $request->has('angeltype_count_' . $angeltype_id) + && preg_match('/^\d{1,4}$/', $request->input('angeltype_count_' . $angeltype_id)) ) { - $angeltypes_count[$angeltype_id] = $_REQUEST['angeltype_count_' . $angeltype_id]; + $angeltypes_count[$angeltype_id] = $request->input('angeltype_count_' . $angeltype_id); } else { $valid = false; $msg .= error(sprintf(_('Please enter needed angels for type %s.'), $angeltype), true); @@ -209,8 +209,8 @@ function admin_rooms() form_submit('submit', _('Save')) ]) ]); - } elseif ($_REQUEST['show'] == 'delete') { - if (isset($_REQUEST['ack'])) { + } elseif ($request->input('show') == 'delete') { + if ($request->has('ack')) { if (!Room_delete($room_id)) { engelsystem_error('Unable to delete room.'); } diff --git a/includes/pages/admin_shifts.php b/includes/pages/admin_shifts.php index 06071233..5b53f9cd 100644 --- a/includes/pages/admin_shifts.php +++ b/includes/pages/admin_shifts.php @@ -18,7 +18,7 @@ function admin_shifts_title() function admin_shifts() { $valid = true; - + $request = request(); $start = parse_date('Y-m-d H:i', date('Y-m-d') . ' 00:00'); $end = $start; $mode = 'single'; @@ -52,14 +52,14 @@ function admin_shifts() $shifttypes[$shifttype['id']] = $shifttype['name']; } - if (isset($_REQUEST['preview']) || isset($_REQUEST['back'])) { - if (isset($_REQUEST['shifttype_id'])) { - $shifttype = ShiftType($_REQUEST['shifttype_id']); + if ($request->has('preview') || $request->has('back')) { + if ($request->has('shifttype_id')) { + $shifttype = ShiftType($request->input('shifttype_id')); if ($shifttype == null) { $valid = false; error(_('Please select a shift type.')); } else { - $shifttype_id = $_REQUEST['shifttype_id']; + $shifttype_id = $request->input('shifttype_id'); } } else { $valid = false; @@ -71,25 +71,25 @@ function admin_shifts() // Auswahl der sichtbaren Locations für die Schichten if ( - isset($_REQUEST['rid']) - && preg_match('/^\d+$/', $_REQUEST['rid']) - && isset($room_array[$_REQUEST['rid']]) + $request->has('rid') + && preg_match('/^\d+$/', $request->input('rid')) + && isset($room_array[$request->input('rid')]) ) { - $rid = $_REQUEST['rid']; + $rid = $request->input('rid'); } else { $valid = false; $rid = $rooms[0]['RID']; error(_('Please select a location.')); } - if (isset($_REQUEST['start']) && $tmp = parse_date('Y-m-d H:i', $_REQUEST['start'])) { + if ($request->has('start') && $tmp = parse_date('Y-m-d H:i', $request->input('start'))) { $start = $tmp; } else { $valid = false; error(_('Please select a start time.')); } - if (isset($_REQUEST['end']) && $tmp = parse_date('Y-m-d H:i', $_REQUEST['end'])) { + if ($request->has('end') && $tmp = parse_date('Y-m-d H:i', $request->input('end'))) { $end = $tmp; } else { $valid = false; @@ -101,24 +101,24 @@ function admin_shifts() error(_('The shifts end has to be after its start.')); } - if (isset($_REQUEST['mode'])) { - if ($_REQUEST['mode'] == 'single') { + if ($request->has('mode')) { + if ($request->input('mode') == 'single') { $mode = 'single'; - } elseif ($_REQUEST['mode'] == 'multi') { - if (isset($_REQUEST['length']) && preg_match('/^\d+$/', trim($_REQUEST['length']))) { + } elseif ($request->input('mode') == 'multi') { + if ($request->has('length') && preg_match('/^\d+$/', trim($request->input('length')))) { $mode = 'multi'; - $length = trim($_REQUEST['length']); + $length = trim($request->input('length')); } else { $valid = false; error(_('Please enter a shift duration in minutes.')); } - } elseif ($_REQUEST['mode'] == 'variable') { + } elseif ($request->input('mode') == 'variable') { if ( - isset($_REQUEST['change_hours']) - && preg_match('/^(\d{2}(,|$))/', trim(str_replace(' ', '', $_REQUEST['change_hours']))) + $request->has('change_hours') + && preg_match('/^(\d{2}(,|$))/', trim(str_replace(' ', '', $request->input('change_hours')))) ) { $mode = 'variable'; - $change_hours = array_map('trim', explode(',', $_REQUEST['change_hours'])); + $change_hours = array_map('trim', explode(',', $request->input('change_hours'))); } else { $valid = false; error(_('Please split the shift-change hours by colons.')); @@ -129,17 +129,17 @@ function admin_shifts() error(_('Please select a mode.')); } - if (isset($_REQUEST['angelmode'])) { - if ($_REQUEST['angelmode'] == 'location') { + if ($request->has('angelmode')) { + if ($request->input('angelmode') == 'location') { $angelmode = 'location'; - } elseif ($_REQUEST['angelmode'] == 'manually') { + } elseif ($request->input('angelmode') == 'manually') { $angelmode = 'manually'; foreach ($types as $type) { if ( - isset($_REQUEST['type_' . $type['id']]) - && preg_match('/^\d+$/', trim($_REQUEST['type_' . $type['id']])) + $request->has('type_' . $type['id']) + && preg_match('/^\d+$/', trim($request->input('type_' . $type['id']))) ) { - $needed_angel_types[$type['id']] = trim($_REQUEST['type_' . $type['id']]); + $needed_angel_types[$type['id']] = trim($request->input('type_' . $type['id'])); } else { $valid = false; error(sprintf(_('Please check the needed angels for team %s.'), $type['name'])); @@ -159,7 +159,7 @@ function admin_shifts() } // Beim Zurück-Knopf das Formular zeigen - if (isset($_REQUEST['back'])) { + if ($request->has('back')) { $valid = false; } @@ -304,9 +304,9 @@ function admin_shifts() ]) ]); } - } elseif (isset($_REQUEST['submit'])) { + } elseif ($request->has('submit')) { if ( - !isset($_SESSION['admin_shifts_shifts']) + !$request->has('admin_shifts_shifts') || !isset($_SESSION['admin_shifts_types']) || !is_array($_SESSION['admin_shifts_shifts']) || !is_array($_SESSION['admin_shifts_types']) @@ -360,8 +360,9 @@ function admin_shifts() unset($_SESSION['admin_shifts_types']); } - if (!isset($_REQUEST['rid'])) { - $_REQUEST['rid'] = null; + $rid = null; + if ($request->has('rid')) { + $rid = $request->input('rid'); } $angel_types = ''; foreach ($types as $type) { @@ -378,7 +379,7 @@ function admin_shifts() form([ form_select('shifttype_id', _('Shifttype'), $shifttypes, $shifttype_id), form_text('title', _('Title'), $title), - form_select('rid', _('Room'), $room_array, $_REQUEST['rid']), + form_select('rid', _('Room'), $room_array, $rid), div('row', [ div('col-md-6', [ form_text('start', _('Start'), date('Y-m-d H:i', $start)), @@ -386,7 +387,7 @@ function admin_shifts() form_info(_('Mode'), ''), form_radio('mode', _('Create one shift'), $mode == 'single', 'single'), form_radio('mode', _('Create multiple shifts'), $mode == 'multi', 'multi'), - form_text('length', _('Length'), !empty($_REQUEST['length']) ? $_REQUEST['length'] : '120'), + form_text('length', _('Length'), $request->has('length') ? $request->input('length') : '120'), form_radio( 'mode', _('Create multiple shifts with variable length'), @@ -396,7 +397,7 @@ function admin_shifts() form_text( 'change_hours', _('Shift change hours'), - !empty($_REQUEST['change_hours']) ? $_REQUEST['change_hours'] : '00, 04, 08, 10, 12, 14, 16, 18, 20, 22' + $request->has('change_hours') ? $request->input('input') : '00, 04, 08, 10, 12, 14, 16, 18, 20, 22' ) ]), div('col-md-6', [ diff --git a/includes/pages/admin_user.php b/includes/pages/admin_user.php index 8f833087..510e2292 100644 --- a/includes/pages/admin_user.php +++ b/includes/pages/admin_user.php @@ -17,6 +17,7 @@ function admin_user() { global $user, $privileges; $tshirt_sizes = config('tshirt_sizes'); + $request = request(); foreach ($tshirt_sizes as $key => $size) { if (empty($size)) { @@ -26,12 +27,12 @@ function admin_user() $html = ''; - if (!isset($_REQUEST['id'])) { + if (!$request->has('id')) { redirect(users_link()); } - $user_id = $_REQUEST['id']; - if (!isset($_REQUEST['action'])) { + $user_id = $request->input('id'); + if (!$request->has('action')) { $user_source = User($user_id); if ($user_source == null) { error(_('This user does not exist.')); @@ -171,7 +172,7 @@ function admin_user() $html .= "
"; } else { - switch ($_REQUEST['action']) { + switch ($request->input('action')) { case 'save_groups': if ($user_id != $user['UID']) { $my_highest_group = DB::select( @@ -212,13 +213,14 @@ function admin_user() $grouplist[] = $group['UID']; } - if (!is_array($_REQUEST['groups'])) { - $_REQUEST['groups'] = []; + $groupsRequest = $request->input('groups'); + if (!is_array($groupsRequest)) { + $groupsRequest = []; } DB::delete('DELETE FROM `UserGroups` WHERE `uid`=?', [$user_id]); $user_groups_info = []; - foreach ($_REQUEST['groups'] as $group) { + foreach ($groupsRequest as $group) { if (in_array($group, $grouplist)) { DB::insert( 'INSERT INTO `UserGroups` (`uid`, `group_id`) VALUES (?, ?)', @@ -244,7 +246,7 @@ function admin_user() $force_active = $user['force_active']; $user_source = User($user_id); if (in_array('admin_active', $privileges)) { - $force_active = $_REQUEST['force_active']; + $force_active = $request->input('force_active'); } $sql = ' UPDATE `User` SET @@ -255,7 +257,7 @@ function admin_user() `Handy` = ?, `Alter` =?, `DECT` = ?, - ' . ($user_source['email_by_human_allowed'] ? '`email` = ' . DB::getPdo()->quote($_POST["eemail"]) . ',' : '') . ' + ' . ($user_source['email_by_human_allowed'] ? '`email` = ' . DB::getPdo()->quote($request->post('eemail')) . ',' : '') . ' `jabber` = ?, `Size` = ?, `Gekommen`= ?, @@ -266,34 +268,34 @@ function admin_user() WHERE `UID` = ? LIMIT 1'; DB::update($sql, [ - $_POST['eNick'], - $_POST['eName'], - $_POST['eVorname'], - $_POST['eTelefon'], - $_POST['eHandy'], - $_POST['eAlter'], - $_POST['eDECT'], - $_POST['ejabber'], - $_POST['eSize'], - $_POST['eGekommen'], - $_POST['eAktiv'], + $request->post('eNick'), + $request->post('eName'), + $request->post('eVorname'), + $request->post('eTelefon'), + $request->post('eHandy'), + $request->post('eAlter'), + $request->post('eDECT'), + $request->post('ejabber'), + $request->post('eSize'), + $request->post('eGekommen'), + $request->post('eAktiv'), $force_active, - $_POST['eTshirt'], - $_POST['Hometown'], + $request->post('eTshirt'), + $request->post('Hometown'), $user_id, ]); engelsystem_log( - 'Updated user: ' . $_POST['eNick'] . ', ' . $_POST['eSize'] - . ', arrived: ' . $_POST['eGekommen'] - . ', active: ' . $_POST['eAktiv'] - . ', tshirt: ' . $_POST['eTshirt'] + 'Updated user: ' . $request->post('eNick') . ', ' . $request->post('eSize') + . ', arrived: ' . $request->post('eVorname') + . ', active: ' . $request->post('eAktiv') + . ', tshirt: ' . $request->post('eTshirt') ); $html .= success('Änderung wurde gespeichert...' . "\n", true); break; case 'change_pw': - if ($_REQUEST['new_pw'] != '' && $_REQUEST['new_pw'] == $_REQUEST['new_pw2']) { - set_password($user_id, $_REQUEST['new_pw']); + if ($request->post('new_pw') != '' && $request->post('new_pw') == $request->post('new_pw2')) { + set_password($user_id, $request->post('new_pw')); $user_source = User($user_id); engelsystem_log('Set new password for ' . User_Nick_render($user_source)); $html .= success('Passwort neu gesetzt.', true); diff --git a/includes/pages/guest_login.php b/includes/pages/guest_login.php index 99970a01..858ced80 100644 --- a/includes/pages/guest_login.php +++ b/includes/pages/guest_login.php @@ -38,6 +38,7 @@ function guest_register() $enable_tshirt_size = config('enable_tshirt_size'); $min_password_length = config('min_password_length'); $event_config = EventConfig(); + $request = request(); $msg = ''; $nick = ''; @@ -73,11 +74,11 @@ function guest_register() } } - if (isset($_REQUEST['submit'])) { + if ($request->has('submit')) { $valid = true; - if (isset($_REQUEST['nick']) && strlen(User_validate_Nick($_REQUEST['nick'])) > 1) { - $nick = User_validate_Nick($_REQUEST['nick']); + if ($request->has('nick') && strlen(User_validate_Nick($request->input('nick'))) > 1) { + $nick = User_validate_Nick($request->input('nick')); if (count(DB::select('SELECT `UID` FROM `User` WHERE `Nick`=? LIMIT 1', [$nick])) > 0) { $valid = false; $msg .= error(sprintf(_('Your nick "%s" already exists.'), $nick), true); @@ -86,11 +87,11 @@ function guest_register() $valid = false; $msg .= error(sprintf( _('Your nick "%s" is too short (min. 2 characters).'), - User_validate_Nick($_REQUEST['nick']) + User_validate_Nick($request->input('nick')) ), true); } - if (isset($_REQUEST['mail']) && strlen(strip_request_item('mail')) > 0) { + if ($request->has('mail') && strlen(strip_request_item('mail')) > 0) { $mail = strip_request_item('mail'); if (!check_email($mail)) { $valid = false; @@ -101,15 +102,15 @@ function guest_register() $msg .= error(_('Please enter your e-mail.'), true); } - if (isset($_REQUEST['email_shiftinfo'])) { + if ($request->has('email_shiftinfo')) { $email_shiftinfo = true; } - if (isset($_REQUEST['email_by_human_allowed'])) { + if ($request->has('email_by_human_allowed')) { $email_by_human_allowed = true; } - if (isset($_REQUEST['jabber']) && strlen(strip_request_item('jabber')) > 0) { + if ($request->has('jabber') && strlen(strip_request_item('jabber')) > 0) { $jabber = strip_request_item('jabber'); if (!check_email($jabber)) { $valid = false; @@ -118,16 +119,16 @@ function guest_register() } if ($enable_tshirt_size) { - if (isset($_REQUEST['tshirt_size']) && isset($tshirt_sizes[$_REQUEST['tshirt_size']]) && $_REQUEST['tshirt_size'] != '') { - $tshirt_size = $_REQUEST['tshirt_size']; + if ($request->has('tshirt_size') && isset($tshirt_sizes[$request->input('tshirt_size')])) { + $tshirt_size = $request->input('tshirt_size'); } else { $valid = false; $msg .= error(_('Please select your shirt size.'), true); } } - if (isset($_REQUEST['password']) && strlen($_REQUEST['password']) >= $min_password_length) { - if ($_REQUEST['password'] != $_REQUEST['password2']) { + if ($request->has('password') && strlen($request->post('password')) >= $min_password_length) { + if ($request->post('password') != $request->post('password2')) { $valid = false; $msg .= error(_('Your passwords don\'t match.'), true); } @@ -139,8 +140,8 @@ function guest_register() ), true); } - if (isset($_REQUEST['planned_arrival_date'])) { - $tmp = parse_date('Y-m-d H:i', $_REQUEST['planned_arrival_date'] . ' 00:00'); + if ($request->has('planned_arrival_date')) { + $tmp = parse_date('Y-m-d H:i', $request->input('planned_arrival_date') . ' 00:00'); $result = User_validate_planned_arrival_date($tmp); $planned_arrival_date = $result->getValue(); if (!$result->isValid()) { @@ -151,34 +152,34 @@ function guest_register() $selected_angel_types = []; foreach (array_keys($angel_types) as $angel_type_id) { - if (isset($_REQUEST['angel_types_' . $angel_type_id])) { + if ($request->has('angel_types_' . $angel_type_id)) { $selected_angel_types[] = $angel_type_id; } } // Trivia - if (isset($_REQUEST['lastname'])) { + if ($request->has('lastname')) { $lastName = strip_request_item('lastname'); } - if (isset($_REQUEST['prename'])) { + if ($request->has('prename')) { $preName = strip_request_item('prename'); } - if (isset($_REQUEST['age']) && preg_match('/^\d{0,4}$/', $_REQUEST['age'])) { + if ($request->has('age') && preg_match('/^\d{0,4}$/', $request->input('age'))) { $age = strip_request_item('age'); } - if (isset($_REQUEST['tel'])) { + if ($request->has('tel')) { $tel = strip_request_item('tel'); } - if (isset($_REQUEST['dect'])) { + if ($request->has('dect')) { $dect = strip_request_item('dect'); } - if (isset($_REQUEST['mobile'])) { + if ($request->has('mobile')) { $mobile = strip_request_item('mobile'); } - if (isset($_REQUEST['hometown'])) { + if ($request->has('hometown')) { $hometown = strip_request_item('hometown'); } - if (isset($_REQUEST['comment'])) { + if ($request->has('comment')) { $comment = strip_request_item_nl('comment'); } @@ -233,7 +234,7 @@ function guest_register() // Assign user-group and set password $user_id = DB::getPdo()->lastInsertId(); DB::insert('INSERT INTO `UserGroups` (`uid`, `group_id`) VALUES (?, -2)', [$user_id]); - set_password($user_id, $_REQUEST['password']); + set_password($user_id, $request->post('password')); // Assign angel-types $user_angel_types_info = []; @@ -391,18 +392,18 @@ function guest_logout() function guest_login() { $nick = ''; - + $request = request(); unset($_SESSION['uid']); $valid = true; - if (isset($_REQUEST['submit'])) { - if (isset($_REQUEST['nick']) && strlen(User_validate_Nick($_REQUEST['nick'])) > 0) { - $nick = User_validate_Nick($_REQUEST['nick']); + if ($request->has('submit')) { + if ($request->has('nick') && strlen(User_validate_Nick($request->input('nick'))) > 0) { + $nick = User_validate_Nick($request->input('nick')); $login_user = DB::select('SELECT * FROM `User` WHERE `Nick`=?', [$nick]); if (count($login_user) > 0) { $login_user = $login_user[0]; - if (isset($_REQUEST['password'])) { - if (!verify_password($_REQUEST['password'], $login_user['Passwort'], $login_user['UID'])) { + if ($request->has('password')) { + if (!verify_password($request->post('password'), $login_user['Passwort'], $login_user['UID'])) { $valid = false; error(_('Your password is incorrect. Please try it again.')); } @@ -487,6 +488,6 @@ function get_register_hint() ]); } - //FIXME: return error(_('Registration is disabled.'), true); + //@TODO: FIXME: return error(_('Registration is disabled.'), true); return error('Registration is disabled.', true); } diff --git a/includes/pages/guest_stats.php b/includes/pages/guest_stats.php index 6b6f0572..8aa6f740 100644 --- a/includes/pages/guest_stats.php +++ b/includes/pages/guest_stats.php @@ -5,9 +5,10 @@ use Engelsystem\Database\DB; function guest_stats() { $apiKey = config('api_key'); + $request = request(); - if (isset($_REQUEST['api_key'])) { - if ($_REQUEST['api_key'] == $apiKey && !empty($apiKey)) { + if ($request->has('api_key')) { + if (!empty($apiKey) && $request->input('api_key') == $apiKey) { $stats = []; list($user_count) = DB::select('SELECT count(*) AS `user_count` FROM `User`'); diff --git a/includes/pages/user_atom.php b/includes/pages/user_atom.php index d7c77d52..a1e2580a 100644 --- a/includes/pages/user_atom.php +++ b/includes/pages/user_atom.php @@ -3,16 +3,17 @@ use Engelsystem\Database\DB; /** - * Publically available page to feed the news to feedreaders + * Publically available page to feed the news to feed readers */ function user_atom() { global $user; + $request = request(); - if (!isset($_REQUEST['key']) || !preg_match('/^[\da-f]{32}$/', $_REQUEST['key'])) { + if (!$request->has('key') || !preg_match('/^[\da-f]{32}$/', $request->input('key'))) { engelsystem_error('Missing key.'); } - $key = $_REQUEST['key']; + $key = $request->input('key'); $user = User_by_api_key($key); if ($user == null) { @@ -25,7 +26,7 @@ function user_atom() $news = DB::select(' SELECT * FROM `News` - ' . (empty($_REQUEST['meetings']) ? '' : 'WHERE `Treffen` = 1 ') . ' + ' . (!$request->has('meetings') ? '' : 'WHERE `Treffen` = 1 ') . ' ORDER BY `ID` DESC LIMIT ' . (int)config('display_news') ); diff --git a/includes/pages/user_ical.php b/includes/pages/user_ical.php index ce474a9e..8d22c4eb 100644 --- a/includes/pages/user_ical.php +++ b/includes/pages/user_ical.php @@ -6,11 +6,12 @@ function user_ical() { global $user; + $request = request(); - if (!isset($_REQUEST['key']) || !preg_match('/^[\da-f]{32}$/', $_REQUEST['key'])) { + if (!$request->has('key') || !preg_match('/^[\da-f]{32}$/', $request->input('key'))) { engelsystem_error('Missing key.'); } - $key = $_REQUEST['key']; + $key = $request->input('key'); $user = User_by_api_key($key); if ($user == null) { diff --git a/includes/pages/user_messages.php b/includes/pages/user_messages.php index dd22cd66..a811970d 100644 --- a/includes/pages/user_messages.php +++ b/includes/pages/user_messages.php @@ -35,8 +35,9 @@ function user_unread_messages() function user_messages() { global $user; + $request = request(); - if (!isset($_REQUEST['action'])) { + if (!$request->has('action')) { $users = DB::select( 'SELECT `UID`, `Nick` FROM `User` WHERE NOT `UID`=? ORDER BY `Nick`', [$user['UID']] @@ -121,10 +122,10 @@ function user_messages() ], page_link_to('user_messages') . '&action=send') ]); } else { - switch ($_REQUEST['action']) { + switch ($request->input('action')) { case 'read': - if (isset($_REQUEST['id']) && preg_match('/^\d{1,11}$/', $_REQUEST['id'])) { - $message_id = $_REQUEST['id']; + if ($request->has('id') && preg_match('/^\d{1,11}$/', $request->input('id'))) { + $message_id = $request->input('id'); } else { return error(_('Incomplete call, missing Message ID.'), true); } @@ -145,8 +146,8 @@ function user_messages() break; case 'delete': - if (isset($_REQUEST['id']) && preg_match('/^\d{1,11}$/', $_REQUEST['id'])) { - $message_id = $_REQUEST['id']; + if ($request->has('id') && preg_match('/^\d{1,11}$/', $request->input('id'))) { + $message_id = $request->input('id'); } else { return error(_('Incomplete call, missing Message ID.'), true); } @@ -164,7 +165,8 @@ function user_messages() break; case 'send': - if (Message_send($_REQUEST['to'], $_REQUEST['text'])) { + // @TODO: Validation? + if (Message_send($request->input('to'), $request->input('text'))) { redirect(page_link_to('user_messages')); } else { return error(_('Transmitting was terminated with an Error.'), true); diff --git a/includes/pages/user_myshifts.php b/includes/pages/user_myshifts.php index 6048093a..14b5b8ee 100644 --- a/includes/pages/user_myshifts.php +++ b/includes/pages/user_myshifts.php @@ -18,14 +18,15 @@ function myshifts_title() function user_myshifts() { global $user, $privileges; + $request = request(); if ( - isset($_REQUEST['id']) + $request->has('id') && in_array('user_shifts_admin', $privileges) - && preg_match('/^\d{1,}$/', $_REQUEST['id']) - && count(DB::select('SELECT `UID` FROM `User` WHERE `UID`=?', [$_REQUEST['id']])) > 0 + && preg_match('/^\d{1,}$/', $request->input('id')) + && count(DB::select('SELECT `UID` FROM `User` WHERE `UID`=?', [$request->input('id')])) > 0 ) { - $user_id = $_REQUEST['id']; + $user_id = $request->input('id'); } else { $user_id = $user['UID']; } @@ -33,8 +34,8 @@ function user_myshifts() $shifts_user = DB::select('SELECT * FROM `User` WHERE `UID`=? LIMIT 1', [$user_id]); $shifts_user = array_shift($shifts_user); - if (isset($_REQUEST['reset'])) { - if ($_REQUEST['reset'] == 'ack') { + if ($request->has('reset')) { + if ($request->input('reset') == 'ack') { User_reset_api_key($user); success(_('Key changed.')); redirect(page_link_to('users') . '&action=view&user_id=' . $shifts_user['UID']); @@ -46,8 +47,8 @@ function user_myshifts() ), button(page_link_to('user_myshifts') . '&reset=ack', _('Continue'), 'btn-danger') ]); - } elseif (isset($_REQUEST['edit']) && preg_match('/^\d*$/', $_REQUEST['edit'])) { - $user_id = $_REQUEST['edit']; + } elseif ($request->has('edit') && preg_match('/^\d*$/', $request->input('edit'))) { + $user_id = $request->input('edit'); $shift = DB::select(' SELECT `ShiftEntry`.`freeloaded`, @@ -77,10 +78,10 @@ function user_myshifts() $freeloaded = $shift['freeloaded']; $freeload_comment = $shift['freeload_comment']; - if (isset($_REQUEST['submit'])) { + if ($request->has('submit')) { $valid = true; if (in_array('user_shifts_admin', $privileges)) { - $freeloaded = isset($_REQUEST['freeloaded']); + $freeloaded = $request->has('freeloaded'); $freeload_comment = strip_request_item_nl('freeload_comment'); if ($freeloaded && $freeload_comment == '') { $valid = false; @@ -128,8 +129,8 @@ function user_myshifts() } else { redirect(page_link_to('user_myshifts')); } - } elseif (isset($_REQUEST['cancel']) && preg_match('/^\d*$/', $_REQUEST['cancel'])) { - $user_id = $_REQUEST['cancel']; + } elseif ($request->has('cancel') && preg_match('/^\d*$/', $request->input('cancel'))) { + $user_id = $request->input('cancel'); $shift = DB::select(' SELECT * FROM `Shifts` diff --git a/includes/pages/user_news.php b/includes/pages/user_news.php index b1e337b6..9bdcb6fb 100644 --- a/includes/pages/user_news.php +++ b/includes/pages/user_news.php @@ -33,9 +33,10 @@ function user_meetings() { $display_news = config('display_news'); $html = '

' . meetings_title() . '

' . msg(); + $request = request(); - if (isset($_REQUEST['page']) && preg_match('/^\d{1,}$/', $_REQUEST['page'])) { - $page = $_REQUEST['page']; + if ($request->has('page') && preg_match('/^\d{1,}$/', $request->input('page'))) { + $page = $request->input('page'); } else { $page = 0; } @@ -56,9 +57,9 @@ function user_meetings() $dis_rows = ceil(count(DB::select('SELECT `ID` FROM `News`')) / $display_news); $html .= '
' . '
    '; for ($i = 0; $i < $dis_rows; $i++) { - if (isset($_REQUEST['page']) && $i == $_REQUEST['page']) { + if ($request->has('page') && $i == $request->input('page')) { $html .= '
  • '; - } elseif (!isset($_REQUEST['page']) && $i == 0) { + } elseif (!$request->has('page') && $i == 0) { $html .= '
  • '; } else { $html .= '
  • '; @@ -116,17 +117,19 @@ function user_news_comments() { global $user; + $request = request(); + $html = '

    ' . user_news_comments_title() . '

    '; if ( - isset($_REQUEST['nid']) - && preg_match('/^\d{1,}$/', $_REQUEST['nid']) - && count(DB::select('SELECT `ID` FROM `News` WHERE `ID`=? LIMIT 1', [$_REQUEST['nid']])) > 0 + $request->has('nid') + && preg_match('/^\d{1,}$/', $request->input('nid')) + && count(DB::select('SELECT `ID` FROM `News` WHERE `ID`=? LIMIT 1', [$request->input('nid')])) > 0 ) { - $nid = $_REQUEST['nid']; + $nid = $request->input('nid'); $news = DB::select('SELECT * FROM `News` WHERE `ID`=? LIMIT 1', [$nid]); $news = array_shift($news); - if (isset($_REQUEST['text'])) { - $text = preg_replace("/([^\p{L}\p{P}\p{Z}\p{N}\n]{1,})/ui", '', strip_tags($_REQUEST['text'])); + if ($request->has('text')) { + $text = preg_replace("/([^\p{L}\p{P}\p{Z}\p{N}\n]{1,})/ui", '', strip_tags($request->input('text'))); DB::insert(' INSERT INTO `NewsComments` (`Refid`, `Datum`, `Text`, `UID`) VALUES (?, ?, ?, ?) @@ -179,12 +182,14 @@ function user_news() { global $privileges, $user; $display_news = config('display_news'); + $request = request(); $html = '

    ' . news_title() . '

    ' . msg(); - if (isset($_POST['text']) && isset($_POST['betreff']) && in_array('admin_news', $privileges)) { - if (!isset($_POST['treffen']) || !in_array('admin_news', $privileges)) { - $_POST['treffen'] = 0; + $isMeeting = $request->post('treffen'); + if ($request->has('text') && $request->has('betreff') && in_array('admin_news', $privileges)) { + if (!$request->has('treffen') || !in_array('admin_news', $privileges)) { + $isMeeting = 0; } DB::insert(' INSERT INTO `News` (`Datum`, `Betreff`, `Text`, `UID`, `Treffen`) @@ -192,19 +197,19 @@ function user_news() ', [ time(), - $_POST['betreff'], - $_POST['text'], + $request->post('betreff'), + $request->post('text'), $user['UID'], - $_POST['treffen'], + $isMeeting, ] ); - engelsystem_log('Created news: ' . $_POST['betreff'] . ', treffen: ' . $_POST['treffen']); + engelsystem_log('Created news: ' . $_POST['betreff'] . ', treffen: ' . $isMeeting); success(_('Entry saved.')); redirect(page_link_to('news')); } - if (isset($_REQUEST['page']) && preg_match('/^\d{1,}$/', $_REQUEST['page'])) { - $page = $_REQUEST['page']; + if ($request->has('page') && preg_match('/^\d{1,}$/', $request->input('page'))) { + $page = $request->input('page'); } else { $page = 0; } @@ -225,9 +230,9 @@ function user_news() $dis_rows = ceil(count(DB::select('SELECT `ID` FROM `News`')) / $display_news); $html .= '
    ' . '
      '; for ($i = 0; $i < $dis_rows; $i++) { - if (isset($_REQUEST['page']) && $i == $_REQUEST['page']) { + if ($request->has('page') && $i == $request->input('page')) { $html .= '
    • '; - } elseif (!isset($_REQUEST['page']) && $i == 0) { + } elseif (!$request->has('page') && $i == 0) { $html .= '
    • '; } else { $html .= '
    • '; diff --git a/includes/pages/user_questions.php b/includes/pages/user_questions.php index 5cb60db3..fdf76aee 100644 --- a/includes/pages/user_questions.php +++ b/includes/pages/user_questions.php @@ -16,8 +16,9 @@ function questions_title() function user_questions() { global $user; + $request = request(); - if (!isset($_REQUEST['action'])) { + if (!$request->has('action')) { $open_questions = DB::select( 'SELECT * FROM `Questions` WHERE `AID` IS NULL AND `UID`=?', [$user['UID']] @@ -34,7 +35,7 @@ function user_questions() return Questions_view($open_questions, $answered_questions, page_link_to('user_questions') . '&action=ask'); } else { - switch ($_REQUEST['action']) { + switch ($request->input('action')) { case 'ask': $question = strip_request_item_nl('question'); if ($question != '') { @@ -56,8 +57,8 @@ function user_questions() } break; case 'delete': - if (isset($_REQUEST['id']) && preg_match('/^\d{1,11}$/', $_REQUEST['id'])) { - $question_id = $_REQUEST['id']; + if ($request->has('id') && preg_match('/^\d{1,11}$/', $request->input('id'))) { + $question_id = $request->input('id'); } else { return error(_('Incomplete call, missing Question ID.'), true); } diff --git a/includes/pages/user_settings.php b/includes/pages/user_settings.php index a2a486f4..69e5a7fb 100644 --- a/includes/pages/user_settings.php +++ b/includes/pages/user_settings.php @@ -21,9 +21,10 @@ function settings_title() function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes) { $valid = true; + $request = request(); - if (isset($_REQUEST['mail'])) { - $result = User_validate_mail($_REQUEST['mail']); + if ($request->has('mail')) { + $result = User_validate_mail($request->input('mail')); $user_source['email'] = $result->getValue(); if (!$result->isValid()) { $valid = false; @@ -34,11 +35,11 @@ function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes) error(_('Please enter your e-mail.')); } - $user_source['email_shiftinfo'] = isset($_REQUEST['email_shiftinfo']); - $user_source['email_by_human_allowed'] = isset($_REQUEST['email_by_human_allowed']); + $user_source['email_shiftinfo'] = $request->has('email_shiftinfo'); + $user_source['email_by_human_allowed'] = $request->has('email_by_human_allowed'); - if (isset($_REQUEST['jabber'])) { - $result = User_validate_jabber($_REQUEST['jabber']); + if ($request->has('jabber')) { + $result = User_validate_jabber($request->input('jabber')); $user_source['jabber'] = $result->getValue(); if (!$result->isValid()) { $valid = false; @@ -46,14 +47,14 @@ function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes) } } - if (isset($_REQUEST['tshirt_size']) && isset($tshirt_sizes[$_REQUEST['tshirt_size']])) { - $user_source['Size'] = $_REQUEST['tshirt_size']; + if ($request->has('tshirt_size') && isset($tshirt_sizes[$request->input('tshirt_size')])) { + $user_source['Size'] = $request->input('tshirt_size'); } elseif ($enable_tshirt_size) { $valid = false; } - if (isset($_REQUEST['planned_arrival_date'])) { - $tmp = parse_date('Y-m-d H:i', $_REQUEST['planned_arrival_date'] . ' 00:00'); + if ($request->has('planned_arrival_date')) { + $tmp = parse_date('Y-m-d H:i', $request->input('planned_arrival_date') . ' 00:00'); $result = User_validate_planned_arrival_date($tmp); $user_source['planned_arrival_date'] = $result->getValue(); if (!$result->isValid()) { @@ -62,8 +63,8 @@ function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes) } } - if (isset($_REQUEST['planned_departure_date'])) { - $tmp = parse_date('Y-m-d H:i', $_REQUEST['planned_departure_date'] . ' 00:00'); + if ($request->has('planned_departure_date')) { + $tmp = parse_date('Y-m-d H:i', $request->input('planned_departure_date') . ' 00:00'); $result = User_validate_planned_departure_date($user_source['planned_arrival_date'], $tmp); $user_source['planned_departure_date'] = $result->getValue(); if (!$result->isValid()) { @@ -97,16 +98,17 @@ function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes) */ function user_settings_password($user_source) { + $request = request(); if ( - !isset($_REQUEST['password']) - || !verify_password($_REQUEST['password'], $user_source['Passwort'], $user_source['UID']) + !$request->has('password') + || !verify_password($request->post('password'), $user_source['Passwort'], $user_source['UID']) ) { error(_('-> not OK. Please try again.')); - } elseif (strlen($_REQUEST['new_password']) < config('min_password_length')) { + } elseif (strlen($request->post('new_password')) < config('min_password_length')) { error(_('Your password is to short (please use at least 6 characters).')); - } elseif ($_REQUEST['new_password'] != $_REQUEST['new_password2']) { + } elseif ($request->post('new_password') != $request->post('new_password2')) { error(_('Your passwords don\'t match.')); - } elseif (set_password($user_source['UID'], $_REQUEST['new_password'])) { + } elseif (set_password($user_source['UID'], $request->post('new_password'))) { success(_('Password saved.')); } else { error(_('Failed setting password.')); @@ -124,9 +126,10 @@ function user_settings_password($user_source) function user_settings_theme($user_source, $themes) { $valid = true; + $request = request(); - if (isset($_REQUEST['theme']) && isset($themes[$_REQUEST['theme']])) { - $user_source['color'] = $_REQUEST['theme']; + if ($request->has('theme') && isset($themes[$request->input('theme')])) { + $user_source['color'] = $request->input('theme'); } else { $valid = false; } @@ -160,9 +163,10 @@ function user_settings_theme($user_source, $themes) function user_settings_locale($user_source, $locales) { $valid = true; + $request = request(); - if (isset($_REQUEST['language']) && isset($locales[$_REQUEST['language']])) { - $user_source['Sprache'] = $_REQUEST['language']; + if ($request->has('language') && isset($locales[$request->input('language')])) { + $user_source['Sprache'] = $request->input('language'); } else { $valid = false; } @@ -195,6 +199,7 @@ function user_settings_locale($user_source, $locales) function user_settings() { global $themes, $user; + $request = request(); $enable_tshirt_size = config('enable_tshirt_size'); $tshirt_sizes = config('tshirt_sizes'); @@ -220,13 +225,13 @@ function user_settings() $user_source = $user; - if (isset($_REQUEST['submit'])) { + if ($request->has('submit')) { $user_source = user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes); - } elseif (isset($_REQUEST['submit_password'])) { + } elseif ($request->has('submit_password')) { user_settings_password($user_source); - } elseif (isset($_REQUEST['submit_theme'])) { + } elseif ($request->has('submit_theme')) { $user_source = user_settings_theme($user_source, $themes); - } elseif (isset($_REQUEST['submit_language'])) { + } elseif ($request->has('submit_language')) { $user_source = user_settings_locale($user_source, $locales); } diff --git a/includes/pages/user_shifts.php b/includes/pages/user_shifts.php index 55e49e4f..4dabdfb5 100644 --- a/includes/pages/user_shifts.php +++ b/includes/pages/user_shifts.php @@ -23,20 +23,21 @@ function shifts_title() function user_shifts() { global $user; + $request = request(); if (User_is_freeloader($user)) { redirect(page_link_to('user_myshifts')); } // Löschen einzelner Schicht-Einträge (Also Belegung einer Schicht von Engeln) durch Admins - if (isset($_REQUEST['entry_id'])) { + if ($request->has('entry_id')) { shift_entry_delete_controller(); return ''; - } elseif (isset($_REQUEST['edit_shift'])) { + } elseif ($request->has('edit_shift')) { return shift_edit_controller(); - } elseif (isset($_REQUEST['delete_shift'])) { + } elseif ($request->has('delete_shift')) { return shift_delete_controller(); - } elseif (isset($_REQUEST['shift_id'])) { + } elseif ($request->has('shift_id')) { return shift_entry_add_controller(); } return view_user_shifts(); diff --git a/includes/sys_page.php b/includes/sys_page.php index b2199988..501106ff 100644 --- a/includes/sys_page.php +++ b/includes/sys_page.php @@ -18,12 +18,14 @@ function check_request_datetime($date_name, $time_name, $allowed_days, $default_ { $time = date('H:i', $default_value); $day = date('Y-m-d', $default_value); + $request = request(); - if (isset($_REQUEST[$time_name]) && preg_match('#^\d{1,2}:\d\d$#', trim($_REQUEST[$time_name]))) { - $time = trim($_REQUEST[$time_name]); + if ($request->has($time_name) && preg_match('#^\d{1,2}:\d\d$#', trim($request->input($time_name)))) { + $time = trim($request->input($time_name)); } - if (isset($_REQUEST[$date_name]) && in_array($_REQUEST[$date_name], $allowed_days)) { - $day = $_REQUEST[$date_name]; + + if ($request->has($date_name) && in_array($request->input($date_name), $allowed_days)) { + $day = $request->input($date_name); } return parse_date('Y-m-d H:i', $day . ' ' . $time); @@ -94,8 +96,9 @@ function select_array($data, $key_name, $value_name) */ function check_request_int_array($name, $default = []) { - if (isset($_REQUEST[$name]) && is_array($_REQUEST[$name])) { - return array_filter($_REQUEST[$name], 'is_numeric'); + $request = request(); + if ($request->has($name) && is_array($request->input($name))) { + return array_filter($request->input($name), 'is_numeric'); } return $default; } @@ -111,10 +114,11 @@ function check_request_int_array($name, $default = []) */ function check_request_date($name, $error_message = null, $null_allowed = false) { - if (!isset($_REQUEST[$name])) { + $request = request(); + if (!$request->has($name)) { return new ValidationResult($null_allowed, null); } - return check_date($_REQUEST[$name], $error_message, $null_allowed); + return check_date($request->input($name), $error_message, $null_allowed); } /** @@ -148,8 +152,9 @@ function check_date($input, $error_message = null, $null_allowed = false) */ function strip_request_item($name, $default_value = null) { - if (isset($_REQUEST[$name])) { - return strip_item($_REQUEST[$name]); + $request = request(); + if ($request->has($name)) { + return strip_item($request->input($name)); } return $default_value; } @@ -163,8 +168,9 @@ function strip_request_item($name, $default_value = null) */ function test_request_int($name) { - if (isset($_REQUEST[$name])) { - return preg_match('/^\d*$/', $_REQUEST[$name]); + $request = request(); + if ($request->has($name)) { + return preg_match('/^\d*$/', $request->input($name)); } return false; } @@ -178,8 +184,9 @@ function test_request_int($name) */ function strip_request_item_nl($name, $default_value = null) { - if (isset($_REQUEST[$name])) { - return preg_replace("/([^\p{L}\p{S}\p{P}\p{Z}\p{N}+\n]{1,})/ui", '', strip_tags($_REQUEST[$name])); + $request = request(); + if ($request->has($name)) { + return preg_replace("/([^\p{L}\p{S}\p{P}\p{Z}\p{N}+\n]{1,})/ui", '', strip_tags($request->get($name))); } return $default_value; } diff --git a/includes/sys_template.php b/includes/sys_template.php index 7aa458b8..1d3943b7 100644 --- a/includes/sys_template.php +++ b/includes/sys_template.php @@ -335,11 +335,11 @@ function table_buttons($buttons = []) /** * Load and render template * - * @param string $file - * @param string $data + * @param string $file + * @param string[] $data * @return string */ -function template_render($file, $data) +function template_render($file, $data = []) { if (file_exists($file)) { $template = file_get_contents($file); diff --git a/public/index.php b/public/index.php index 895b4fe0..52f32438 100644 --- a/public/index.php +++ b/public/index.php @@ -24,24 +24,22 @@ $page = ''; $title = ''; $content = ''; -if (!isset($_REQUEST['p'])) { - $_REQUEST['p'] = isset($user) ? 'news' : 'login'; +$page = $request->input('p'); +if (empty($page)) { + $page = isset($user) ? 'news' : 'login'; } if ( - isset($_REQUEST['p']) - && preg_match('/^\w*$/i', $_REQUEST['p']) + preg_match('/^\w*$/i', $page) && ( - in_array($_REQUEST['p'], $free_pages) - || (isset($privileges) && in_array($_REQUEST['p'], $privileges)) + in_array($page, $free_pages) + || (isset($privileges) && in_array($page, $privileges)) ) ) { - $page = $_REQUEST['p']; - $title = $page; if ($page == 'api') { - error('Api disabled temporily.'); + error('Api disabled temporarily.'); redirect(page_link_to()); require_once realpath(__DIR__ . '/../includes/controller/api.php'); api_controller(); diff --git a/src/Http/Request.php b/src/Http/Request.php new file mode 100644 index 00000000..2efd1e1d --- /dev/null +++ b/src/Http/Request.php @@ -0,0 +1,110 @@ +request = $_POST; + $this->query = $_GET; + } + + /** + * Get GET input + * + * @param string $key + * @param mixed $default + * @return mixed + */ + public function get($key, $default = null) + { + if (!empty($this->query[$key])) { + return $this->query[$key]; + } + + return $default; + } + + /** + * Get POST input + * + * @param string $key + * @param mixed $default + * @return mixed + */ + public function post($key, $default = null) + { + if (!empty($this->request[$key])) { + return $this->request[$key]; + } + + return $default; + } + + /** + * Get input data + * + * @param string $key + * @param mixed $default + * @return mixed + */ + public function input($key, $default = null) + { + $data = $this->request + $this->query; + + if (!empty($data[$key])) { + return $data[$key]; + } + + return $default; + } + + /** + * Checks if the input exists + * + * @param string $key + * @return bool + */ + public function has($key) + { + $value = $this->input($key); + + return !empty($value); + } + + /** + * @return self + * @throws ErrorException + */ + public static function getInstance() + { + if (!self::$instance instanceof self) { + throw new ErrorException('Request not initialized'); + } + + return self::$instance; + } + + /** + * @param self $instance + */ + public static function setInstance($instance) + { + self::$instance = $instance; + } +} diff --git a/src/helpers.php b/src/helpers.php index aeb256e9..a410b27e 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -2,6 +2,7 @@ // Some useful functions use Engelsystem\Config\Config; +use Engelsystem\Http\Request; /** * Get or set config values @@ -22,3 +23,19 @@ function config($key = null, $default = null) return Config::getInstance()->get($key, $default); } + +/** + * @param string $key + * @param mixed $default + * @return Request|mixed + */ +function request($key = null, $default = null) +{ + $request = Request::getInstance(); + + if (is_null($key)) { + return $request; + } + + return $request->input($key, $default); +} -- cgit v1.2.3-54-g00ecf From 73175e2b64c85c7a8c528c76452cd82ffa99f925 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Mon, 28 Aug 2017 16:21:10 +0200 Subject: #337: Added routing --- config/config.default.php | 3 + includes/autoload.php | 9 + includes/controller/angeltypes_controller.php | 24 +- includes/controller/rooms_controller.php | 5 +- includes/controller/shifts_controller.php | 11 +- includes/controller/shifttypes_controller.php | 4 +- includes/controller/user_angeltypes_controller.php | 17 +- .../controller/user_driver_licenses_controller.php | 2 +- includes/controller/users_controller.php | 8 +- includes/engelsystem_provider.php | 8 +- includes/pages/admin_active.php | 52 ++-- includes/pages/admin_arrive.php | 10 +- includes/pages/admin_free.php | 2 +- includes/pages/admin_groups.php | 8 +- includes/pages/admin_news.php | 23 +- includes/pages/admin_questions.php | 6 +- includes/pages/admin_rooms.php | 8 +- includes/pages/admin_user.php | 30 ++- includes/pages/guest_login.php | 7 +- includes/pages/user_atom.php | 4 +- includes/pages/user_messages.php | 6 +- includes/pages/user_myshifts.php | 8 +- includes/pages/user_news.php | 22 +- includes/pages/user_questions.php | 6 +- includes/pages/user_shifts.php | 8 +- includes/sys_menu.php | 22 +- includes/view/AngelTypes_view.php | 71 ++++-- includes/view/Questions_view.php | 12 +- includes/view/ShiftCalendarShiftRenderer.php | 14 +- includes/view/ShiftTypes_view.php | 34 ++- includes/view/Shifts_view.php | 9 +- includes/view/UserAngelTypes_view.php | 73 ++++-- includes/view/User_view.php | 46 ++-- public/.htaccess | 8 + public/index.php | 282 ++++++++++++--------- src/Http/Request.php | 108 +++++++- templates/layout.html | 4 +- templates/maintenance.html | 2 +- 38 files changed, 661 insertions(+), 315 deletions(-) create mode 100644 includes/autoload.php create mode 100644 public/.htaccess (limited to 'includes/controller/user_driver_licenses_controller.php') diff --git a/config/config.default.php b/config/config.default.php index ffa030db..c3a939cd 100644 --- a/config/config.default.php +++ b/config/config.default.php @@ -20,6 +20,9 @@ return [ // Set to development to enable debugging messages 'environment' => 'production', + // Site URL, used to generate links on page (https://example.com/[sub-dir/]) + 'url' => null, + // URL to the angel faq and job description 'faq_url' => 'https://events.ccc.de/congress/2013/wiki/Static:Volunteers', diff --git a/includes/autoload.php b/includes/autoload.php new file mode 100644 index 00000000..f51f89e4 --- /dev/null +++ b/includes/autoload.php @@ -0,0 +1,9 @@ + 'view', 'angeltype_id' => $angeltype_id]); } /** @@ -211,17 +211,21 @@ function angeltypes_list_controller() foreach ($angeltypes as &$angeltype) { $actions = [ - button(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id'], _('view'), 'btn-xs') + 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'], + 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'], + page_link_to('angeltypes', ['action' => 'delete', 'angeltype_id' => $angeltype['id']]), _('delete'), 'btn-xs' ); @@ -230,13 +234,15 @@ function angeltypes_list_controller() $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'], + 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'], + page_link_to('user_angeltypes', ['action' => 'add', 'angeltype_id' => $angeltype['id']]), _('join'), 'btn-xs' ); @@ -245,7 +251,11 @@ function angeltypes_list_controller() $angeltype['restricted'] = $angeltype['restricted'] ? glyph('lock') : ''; $angeltype['no_self_signup'] = $angeltype['no_self_signup'] ? '' : glyph('share'); - $angeltype['name'] = '' . $angeltype['name'] . ''; + $angeltype['name'] = '' + . $angeltype['name'] + . ''; $angeltype['actions'] = table_buttons($actions); } diff --git a/includes/controller/rooms_controller.php b/includes/controller/rooms_controller.php index 2d6f1a77..81b0113e 100644 --- a/includes/controller/rooms_controller.php +++ b/includes/controller/rooms_controller.php @@ -1,4 +1,5 @@ 'view', 'room_id' => $room['RID']]); } /** @@ -100,7 +101,7 @@ function room_link($room) */ function room_edit_link($room) { - return page_link_to('admin_rooms') . '&show=edit&id=' . $room['RID']; + return page_link_to('admin_rooms', ['show' => 'edit', 'id' => $room['RID']]); } /** diff --git a/includes/controller/shifts_controller.php b/includes/controller/shifts_controller.php index 21c6e160..f4f3f119 100644 --- a/includes/controller/shifts_controller.php +++ b/includes/controller/shifts_controller.php @@ -1,4 +1,5 @@ 'view']); if (isset($shift['SID'])) { $link .= '&shift_id=' . $shift['SID']; } @@ -20,7 +21,7 @@ function shift_link($shift) */ function shift_delete_link($shift) { - return page_link_to('user_shifts') . '&delete_shift=' . $shift['SID']; + return page_link_to('user_shifts', ['delete_shift' => $shift['SID']]); } /** @@ -29,7 +30,7 @@ function shift_delete_link($shift) */ function shift_edit_link($shift) { - return page_link_to('user_shifts') . '&edit_shift=' . $shift['SID']; + return page_link_to('user_shifts', ['edit_shift' => $shift['SID']]); } /** @@ -228,7 +229,9 @@ function shift_delete_controller() date('Y-m-d H:i', $shift['start']), date('H:i', $shift['end']) ), true), - '' . _('delete') . '' + '' . _('delete') . '' ]); } diff --git a/includes/controller/shifttypes_controller.php b/includes/controller/shifttypes_controller.php index acdeb982..3ef2675f 100644 --- a/includes/controller/shifttypes_controller.php +++ b/includes/controller/shifttypes_controller.php @@ -6,7 +6,7 @@ */ function shifttype_link($shifttype) { - return page_link_to('shifttypes') . '&action=view&shifttype_id=' . $shifttype['id']; + return page_link_to('shifttypes', ['action' => 'view', 'shifttype_id' => $shifttype['id']]); } /** @@ -107,7 +107,7 @@ function shifttype_edit_controller() engelsystem_log('Created shifttype ' . $name); success(_('Created shifttype.')); } - redirect(page_link_to('shifttypes') . '&action=view&shifttype_id=' . $shifttype_id); + redirect(page_link_to('shifttypes', ['action' => 'view', 'shifttype_id' => $shifttype_id])); } } diff --git a/includes/controller/user_angeltypes_controller.php b/includes/controller/user_angeltypes_controller.php index 41185552..b427e868 100644 --- a/includes/controller/user_angeltypes_controller.php +++ b/includes/controller/user_angeltypes_controller.php @@ -17,8 +17,7 @@ function user_angeltypes_unconfirmed_hint() $unconfirmed_links = []; foreach ($unconfirmed_user_angeltypes as $user_angeltype) { $unconfirmed_links[] = '' . $user_angeltype['name'] . ' (+' . $user_angeltype['count'] . ')' . ''; @@ -61,7 +60,7 @@ function user_angeltypes_delete_all_controller() 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']); + redirect(page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype['id']])); } return [ @@ -107,7 +106,7 @@ function user_angeltypes_confirm_all_controller() 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']); + redirect(page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype['id']])); } return [ @@ -167,7 +166,7 @@ function user_angeltype_confirm_controller() User_Nick_render($user_source), 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 [ @@ -224,7 +223,7 @@ function user_angeltype_delete_controller() 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 [ @@ -290,7 +289,7 @@ function user_angeltype_update_controller() 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 [ @@ -344,7 +343,7 @@ function user_angeltype_add_controller() 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']])); } } @@ -386,7 +385,7 @@ function user_angeltype_join_controller($angeltype) )); } - redirect(page_link_to('angeltypes') . '&action=view&angeltype_id=' . $angeltype['id']); + redirect(page_link_to('angeltypes', ['action' => 'view', 'angeltype_id' => $angeltype['id']])); } return [ diff --git a/includes/controller/user_driver_licenses_controller.php b/includes/controller/user_driver_licenses_controller.php index fef278dd..3db31eff 100644 --- a/includes/controller/user_driver_licenses_controller.php +++ b/includes/controller/user_driver_licenses_controller.php @@ -63,7 +63,7 @@ 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']; + return page_link_to('user_driver_licenses', ['user_id' => $user['UID']]); } /** diff --git a/includes/controller/users_controller.php b/includes/controller/users_controller.php index b747cc83..6dc74d68 100644 --- a/includes/controller/users_controller.php +++ b/includes/controller/users_controller.php @@ -109,7 +109,7 @@ function users_link() */ function user_edit_link($user) { - return page_link_to('admin_user') . '&user_id=' . $user['UID']; + return page_link_to('admin_user', ['user_id' => $user['UID']]); } /** @@ -118,7 +118,7 @@ function user_edit_link($user) */ function user_delete_link($user) { - return page_link_to('users') . '&action=delete&user_id=' . $user['UID']; + return page_link_to('users', ['action' => 'delete', 'user_id' => $user['UID']]); } /** @@ -127,7 +127,7 @@ function user_delete_link($user) */ function user_link($user) { - return page_link_to('users') . '&action=view&user_id=' . $user['UID']; + return page_link_to('users', ['action' => 'view', 'user_id' => $user['UID']]); } /** @@ -363,7 +363,7 @@ function user_password_recovery_start_controller() _('Password recovery'), sprintf( _('Please visit %s to recover your password.'), - page_link_to_absolute('user_password_recovery') . '&token=' . $token + page_link_to_absolute('user_password_recovery', ['token' => $token]) ) ); success(_('We sent an email containing your password recovery link.')); diff --git a/includes/engelsystem_provider.php b/includes/engelsystem_provider.php index ff682871..c065d332 100644 --- a/includes/engelsystem_provider.php +++ b/includes/engelsystem_provider.php @@ -11,11 +11,7 @@ use Engelsystem\Renderer\Renderer; * This file includes all needed functions, connects to the db etc. */ -if (!is_readable(__DIR__ . '/../vendor/autoload.php')) { - die('Please run composer.phar install'); -} -require __DIR__ . '/../vendor/autoload.php'; - +require_once __DIR__ . '/autoload.php'; /** * Load configuration @@ -38,7 +34,7 @@ date_default_timezone_set($config->get('timezone')); * Initialize Request */ $request = new Request(); -$request->create(); +$request->create($_GET, $_POST, $_SERVER, config('url')); $request::setInstance($request); /** diff --git a/includes/pages/admin_active.php b/includes/pages/admin_active.php index 2e06f90d..5b91e413 100644 --- a/includes/pages/admin_active.php +++ b/includes/pages/admin_active.php @@ -82,9 +82,13 @@ function admin_active() $limit = ''; $msg = success(_('Marked angels.'), true); } else { - $set_active = '« ' - . _('back') . ' | ' + $set_active = '« ' + . _('back') + . ' | ' . _('apply') . ''; } @@ -176,28 +180,46 @@ function admin_active() $actions = []; if ($usr['Aktiv'] == 0) { - $actions[] = '' + $parameters = [ + 'active' => $usr['UID'], + 'search' => $search, + ]; + if ($show_all_shifts) { + $parameters['show_all_shifts'] = 1; + } + $actions[] = '' . _('set active') . ''; } if ($usr['Aktiv'] == 1 && $usr['Tshirt'] == 0) { - $actions[] = '' + $parametersRemove = [ + 'not_active' => $usr['UID'], + 'search' => $search, + ]; + $parametersShirt = [ + 'tshirt' => $usr['UID'], + 'search' => $search, + ]; + if ($show_all_shifts) { + $parametersRemove['show_all_shifts'] = 1; + $parametersShirt['show_all_shifts'] = 1; + } + $actions[] = '' . _('remove active') . ''; - $actions[] = '' + $actions[] = '' . _('got t-shirt') . ''; } if ($usr['Tshirt'] == 1) { - $actions[] = '' + $parameters = [ + 'not_tshirt' => $usr['UID'], + 'search' => $search, + ]; + if ($show_all_shifts) { + $parameters['show_all_shifts'] = 1; + } + $actions[] = '' . _('remove t-shirt') . ''; } diff --git a/includes/pages/admin_arrive.php b/includes/pages/admin_arrive.php index ebeccb8c..2f312b1f 100644 --- a/includes/pages/admin_arrive.php +++ b/includes/pages/admin_arrive.php @@ -92,8 +92,14 @@ function admin_arrive() $usr['rendered_arrival_date'] = $usr['arrival_date'] > 0 ? date('Y-m-d', $usr['arrival_date']) : '-'; $usr['arrived'] = $usr['Gekommen'] == 1 ? _('yes') : ''; $usr['actions'] = $usr['Gekommen'] == 1 - ? '' . _('reset') . '' - : '' . _('arrived') . ''; + ? '' . _('reset') . '' + : '' . _('arrived') . ''; if ($usr['arrival_date'] > 0) { $day = date('Y-m-d', $usr['arrival_date']); diff --git a/includes/pages/admin_free.php b/includes/pages/admin_free.php index ebf227a4..a3c0d17f 100644 --- a/includes/pages/admin_free.php +++ b/includes/pages/admin_free.php @@ -94,7 +94,7 @@ function admin_free() 'email' => $usr['email_by_human_allowed'] ? $usr['email'] : glyph('eye-close'), 'actions' => in_array('admin_user', $privileges) - ? button(page_link_to('admin_user') . '&id=' . $usr['UID'], _('edit'), 'btn-xs') + ? button(page_link_to('admin_user', ['id' => $usr['UID']]), _('edit'), 'btn-xs') : '' ]; } diff --git a/includes/pages/admin_groups.php b/includes/pages/admin_groups.php index c483a79d..d64afe76 100644 --- a/includes/pages/admin_groups.php +++ b/includes/pages/admin_groups.php @@ -38,7 +38,8 @@ function admin_groups() 'name' => $group['Name'], 'privileges' => join(', ', $privileges_html), 'actions' => button( - page_link_to('admin_groups') . '&action=edit&id=' . $group['UID'], + page_link_to('admin_groups', + ['action' => 'edit', 'id' => $group['UID']]), _('edit'), 'btn-xs' ) @@ -93,7 +94,10 @@ function admin_groups() $privileges_form[] = form_submit('submit', _('Save')); $html .= page_with_title(_('Edit group'), [ - form($privileges_form, page_link_to('admin_groups') . '&action=save&id=' . $group_id) + form( + $privileges_form, + page_link_to('admin_groups', ['action' => 'save', 'id' => $group_id]) + ) ]); } else { return error('No Group found.', true); diff --git a/includes/pages/admin_news.php b/includes/pages/admin_news.php index 7f8ca1ba..a5354da7 100644 --- a/includes/pages/admin_news.php +++ b/includes/pages/admin_news.php @@ -31,16 +31,21 @@ function admin_news() $news = array_shift($news); $user_source = User($news['UID']); - $html .= form([ - form_info(_('Date'), date('Y-m-d H:i', $news['Datum'])), - form_info(_('Author'), User_Nick_render($user_source)), - form_text('eBetreff', _('Subject'), $news['Betreff']), - form_textarea('eText', _('Message'), $news['Text']), - form_checkbox('eTreffen', _('Meeting'), $news['Treffen'] == 1, 1), - form_submit('submit', _('Save')) - ], page_link_to('admin_news&action=save&id=' . $news_id)); + $html .= form( + [ + form_info(_('Date'), date('Y-m-d H:i', $news['Datum'])), + form_info(_('Author'), User_Nick_render($user_source)), + form_text('eBetreff', _('Subject'), $news['Betreff']), + form_textarea('eText', _('Message'), $news['Text']), + form_checkbox('eTreffen', _('Meeting'), $news['Treffen'] == 1, 1), + form_submit('submit', _('Save')) + ], + page_link_to('admin_news', ['action' => 'save', 'id' => $news_id]) + ); - $html .= '' + $html .= '' . ' ' . _('Delete') . ''; break; diff --git a/includes/pages/admin_questions.php b/includes/pages/admin_questions.php index d05bace6..938e63a9 100644 --- a/includes/pages/admin_questions.php +++ b/includes/pages/admin_questions.php @@ -52,9 +52,9 @@ function admin_questions() 'answer' => form([ form_textarea('answer', '', ''), form_submit('submit', _('Save')) - ], page_link_to('admin_questions') . '&action=answer&id=' . $question['QID']), + ], page_link_to('admin_questions', ['action' => 'answer', 'id' => $question['QID']])), 'actions' => button( - page_link_to('admin_questions') . '&action=delete&id=' . $question['QID'], + page_link_to('admin_questions', ['action' => 'delete', 'id' => $question['QID']]), _('delete'), 'btn-xs' ) @@ -72,7 +72,7 @@ function admin_questions() 'answered_by' => User_Nick_render($answer_user_source), 'answer' => str_replace("\n", '
      ', $question['Answer']), 'actions' => button( - page_link_to('admin_questions') . '&action=delete&id=' . $question['QID'], + page_link_to('admin_questions', ['action' => 'delete', 'id' => $question['QID']]), _('delete'), 'btn-xs' ) diff --git a/includes/pages/admin_rooms.php b/includes/pages/admin_rooms.php index 3045242b..8a7720d8 100644 --- a/includes/pages/admin_rooms.php +++ b/includes/pages/admin_rooms.php @@ -25,8 +25,8 @@ function admin_rooms() 'from_pentabarf' => $room['FromPentabarf'] == 'Y' ? '✓' : '', 'public' => $room['show'] == 'Y' ? '✓' : '', 'actions' => table_buttons([ - button(page_link_to('admin_rooms') . '&show=edit&id=' . $room['RID'], _('edit'), 'btn-xs'), - button(page_link_to('admin_rooms') . '&show=delete&id=' . $room['RID'], _('delete'), 'btn-xs') + button(page_link_to('admin_rooms', ['show' => 'edit', 'id' => $room['RID']]), _('edit'), 'btn-xs'), + button(page_link_to('admin_rooms', ['show' => 'delete', 'id' => $room['RID']]), _('delete'), 'btn-xs') ]) ]; } @@ -227,7 +227,7 @@ function admin_rooms() sprintf(_('Do you want to delete room %s?'), $name), buttons([ button( - page_link_to('admin_rooms') . '&show=delete&id=' . $room_id . '&ack', + page_link_to('admin_rooms', ['show' => 'delete', 'id' => $room_id, 'ack' => 1]), _('Delete'), 'delete btn-danger' ) @@ -238,7 +238,7 @@ function admin_rooms() return page_with_title(admin_rooms_title(), [ buttons([ - button(page_link_to('admin_rooms') . '&show=edit', _('add')) + button(page_link_to('admin_rooms', ['show' => 'edit']), _('add')) ]), msg(), table([ diff --git a/includes/pages/admin_user.php b/includes/pages/admin_user.php index 510e2292..00113507 100644 --- a/includes/pages/admin_user.php +++ b/includes/pages/admin_user.php @@ -46,25 +46,27 @@ function admin_user() . 'Wenn T-Shirt ein \'Ja\' enthält, bedeutet dies, dass der Engel ' . 'bereits sein T-Shirt erhalten hat.

      ' . "\n"; - $html .= '
      ' . "\n"; + $html .= '' . "\n"; $html .= '' . "\n"; $html .= '' . "\n"; $html .= ''; @@ -105,7 +107,8 @@ function admin_user() $html .= form_info('', _('Please visit the angeltypes page or the users profile to manage users angeltypes.')); $html .= 'Hier kannst Du das Passwort dieses Engels neu setzen:' . "\n"; + . page_link_to('admin_user', ['action' => 'change_pw', 'id' => $user_id]) + . '" method="post">' . "\n"; $html .= '
      ' . "\n"; $html .= '' . "\n"; - $html .= ' ' . "\n"; + $html .= ' ' . "\n"; $html .= ' ' . "\n"; - $html .= ' ' . "\n"; - $html .= ' ' . "\n"; - $html .= ' ' . "\n"; - $html .= ' ' . "\n"; - $html .= ' ' . "\n"; - $html .= ' ' . "\n"; + $html .= ' ' . "\n"; + $html .= ' ' . "\n"; + $html .= ' ' . "\n"; + $html .= ' ' . "\n"; + $html .= ' ' . "\n"; + $html .= ' ' . "\n"; if ($user_source['email_by_human_allowed']) { - $html .= " ' . "\n"; + $html .= " ' . "\n"; } - $html .= " ' . "\n"; + $html .= " ' . "\n"; $html .= ' ' . "\n"; @@ -91,7 +93,7 @@ function admin_user() $html .= ' ' . "\n"; - $html .= ' ' . "\n"; + $html .= ' ' . "\n"; $html .= '
      Nick' . '
      Nick' . '
      Last login

      ' . date('Y-m-d H:i', $user_source['lastLogIn']) . '

      Name' . '
      Vorname' . '
      Alter' . '
      Telefon' . '
      Handy' . '
      DECT' . '
      Name' . '
      Vorname' . '
      Alter' . '
      Telefon' . '
      Handy' . '
      DECT' . '
      email" . '
      email" . '
      jabber" . '
      jabber" . '
      Size' . html_select_key('size', 'eSize', $tshirt_sizes, $user_source['Size']) . '
      T-Shirt' . "\n"; $html .= html_options('eTshirt', $options, $user_source['Tshirt']) . '
      Hometown' . '
      Hometown' . '
      ' . "\n" . '
      ' . "\n"; $html .= ' ' . "\n"; $html .= ' ' . "\n"; @@ -134,7 +137,8 @@ function admin_user() if ($user_id != $user['UID'] && $my_highest_group <= $his_highest_group) { $html .= 'Hier kannst Du die Benutzergruppen des Engels festlegen:' . "\n"; + . page_link_to('admin_user', ['action' => 'save_groups', 'id' => $user_id]) + . '" method="post">' . "\n"; $html .= '
      Passwort' . '
      Wiederholung' . '
      '; $groups = DB::select(' diff --git a/includes/pages/guest_login.php b/includes/pages/guest_login.php index 106db33a..b83b8382 100644 --- a/includes/pages/guest_login.php +++ b/includes/pages/guest_login.php @@ -328,7 +328,7 @@ function guest_register() 'angel_types', _('What do you want to do?') . sprintf( ' (%s)', - page_link_to('angeltypes') . '&action=about', + page_link_to('angeltypes', ['action' => 'about']), _('Description of job types') ), $angel_types, @@ -467,7 +467,10 @@ function guest_login() heading(_('What can I do?'), 2), '

      ' . _('Please read about the jobs you can do to help us.') . '

      ', buttons([ - button(page_link_to('angeltypes') . '&action=about', _('Teams/Job description') . ' »') + button( + page_link_to('angeltypes', ['action' => 'about']), + _('Teams/Job description') . ' »' + ) ]) ]) ]) diff --git a/includes/pages/user_atom.php b/includes/pages/user_atom.php index a1e2580a..98ace9cc 100644 --- a/includes/pages/user_atom.php +++ b/includes/pages/user_atom.php @@ -66,9 +66,9 @@ function make_atom_entry_from_news($news_entry) { return ' ' . htmlspecialchars($news_entry['Betreff']) . ' - + ' . preg_replace('#^https?://#', '', page_link_to_absolute('news')) . '-' . $news_entry['ID'] . ' ' . date('Y-m-d\TH:i:sP', $news_entry['Datum']) . ' - ' . htmlspecialchars($news_entry['Text']) . ' + ' . htmlspecialchars($news_entry['Text']) . ' ' . "\n"; } diff --git a/includes/pages/user_messages.php b/includes/pages/user_messages.php index a811970d..320af9df 100644 --- a/includes/pages/user_messages.php +++ b/includes/pages/user_messages.php @@ -92,14 +92,14 @@ function user_messages() if ($message['RUID'] == $user['UID']) { if ($message['isRead'] == 'N') { $messages_table_entry['actions'] = button( - page_link_to('user_messages') . '&action=read&id=' . $message['id'], + page_link_to('user_messages', ['action' => 'read', 'id' => $message['id']]), _('mark as read'), 'btn-xs' ); } } else { $messages_table_entry['actions'] = button( - page_link_to('user_messages') . '&action=delete&id=' . $message['id'], + page_link_to('user_messages', ['action' => 'delete', 'id' => $message['id']]), _('delete message'), 'btn-xs' ); @@ -119,7 +119,7 @@ function user_messages() 'text' => _('Message'), 'actions' => '' ], $messages_table) - ], page_link_to('user_messages') . '&action=send') + ], page_link_to('user_messages', ['action' => 'send'])) ]); } else { switch ($request->input('action')) { diff --git a/includes/pages/user_myshifts.php b/includes/pages/user_myshifts.php index 14b5b8ee..572b777a 100644 --- a/includes/pages/user_myshifts.php +++ b/includes/pages/user_myshifts.php @@ -38,14 +38,14 @@ function user_myshifts() if ($request->input('reset') == 'ack') { User_reset_api_key($user); success(_('Key changed.')); - redirect(page_link_to('users') . '&action=view&user_id=' . $shifts_user['UID']); + redirect(page_link_to('users', ['action' => 'view', 'user_id' => $shifts_user['UID']])); } return page_with_title(_('Reset API key'), [ error( _('If you reset the key, the url to your iCal- and JSON-export and your atom feed changes! You have to update it in every application using one of these exports.'), true ), - button(page_link_to('user_myshifts') . '&reset=ack', _('Continue'), 'btn-danger') + button(page_link_to('user_myshifts', ['reset' => 'ack']), _('Continue'), 'btn-danger') ]); } elseif ($request->has('edit') && preg_match('/^\d*$/', $request->input('edit'))) { $user_id = $request->input('edit'); @@ -111,7 +111,7 @@ function user_myshifts() . '. Freeloaded: ' . ($freeloaded ? 'YES Comment: ' . $freeload_comment : 'NO') ); success(_('Shift saved.')); - redirect(page_link_to('users') . '&action=view&user_id=' . $shifts_user['UID']); + redirect(page_link_to('users', ['action' => 'view', 'user_id' => $shifts_user['UID']])); } } @@ -172,6 +172,6 @@ function user_myshifts() } } - redirect(page_link_to('users') . '&action=view&user_id=' . $shifts_user['UID']); + redirect(page_link_to('users', ['action' => 'view', 'user_id' => $shifts_user['UID']])); return ''; } diff --git a/includes/pages/user_news.php b/includes/pages/user_news.php index 9bdcb6fb..2dd141ec 100644 --- a/includes/pages/user_news.php +++ b/includes/pages/user_news.php @@ -35,8 +35,8 @@ function user_meetings() $html = '

      ' . meetings_title() . '

      ' . msg(); $request = request(); - if ($request->has('page') && preg_match('/^\d{1,}$/', $request->input('page'))) { - $page = $request->input('page'); + if (preg_match('/^\d{1,}$/', $request->input('page', 0))) { + $page = $request->input('page', 0); } else { $page = 0; } @@ -57,14 +57,14 @@ function user_meetings() $dis_rows = ceil(count(DB::select('SELECT `ID` FROM `News`')) / $display_news); $html .= '
      ' . '
        '; for ($i = 0; $i < $dis_rows; $i++) { - if ($request->has('page') && $i == $request->input('page')) { + if ($request->has('page') && $i == $request->input('page', 0)) { $html .= '
      • '; } elseif (!$request->has('page') && $i == 0) { $html .= '
      • '; } else { $html .= '
      • '; } - $html .= '' . ($i + 1) . '
      • '; + $html .= '' . ($i + 1) . ''; } $html .= '
      '; @@ -89,7 +89,7 @@ function display_news($news) $html .= ' @@ -38,7 +38,7 @@ · Contact · Bugs / Features · Development Platform - · Credits + · Credits diff --git a/templates/maintenance.html b/templates/maintenance.html index 3f7dae8a..bd73bd74 100644 --- a/templates/maintenance.html +++ b/templates/maintenance.html @@ -21,7 +21,7 @@ - + ENGELSYSTEM -- cgit v1.2.3-54-g00ecf