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 --- includes/view/ShiftCalendarShiftRenderer.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'includes/view/ShiftCalendarShiftRenderer.php') diff --git a/includes/view/ShiftCalendarShiftRenderer.php b/includes/view/ShiftCalendarShiftRenderer.php index 8560d47d..f0488e83 100644 --- a/includes/view/ShiftCalendarShiftRenderer.php +++ b/includes/view/ShiftCalendarShiftRenderer.php @@ -125,7 +125,7 @@ class ShiftCalendarShiftRenderer if (in_array('user_shifts_admin', $privileges)) { $html .= '
  • ' . button( - page_link_to('user_shifts') . '&shift_id=' . $shift['SID'], + page_link_to('user_shifts', ['shift_id' => $shift['SID']]), _('Add more angels'), 'btn-xs' ) . '
  • '; @@ -169,11 +169,13 @@ class ShiftCalendarShiftRenderer case ShiftSignupState::ADMIN: case ShiftSignupState::FREE: // When admin or free display a link + button for sign up - $entry_list[] = '' + $entry_list[] = '' . $inner_text . ' ' . button( - page_link_to('user_shifts') . '&shift_id=' . $shift['SID'] . '&type_id=' . $angeltype['id'], + page_link_to('user_shifts', ['shift_id' => $shift['SID'], 'type_id' => $angeltype['id']]), _('Sign up'), 'btn-xs btn-primary' ); break; @@ -191,7 +193,7 @@ class ShiftCalendarShiftRenderer // Add link to join the angeltype first $entry_list[] = $inner_text . '
    ' . button( - page_link_to('user_angeltypes') . '&action=add&angeltype_id=' . $angeltype['id'], + page_link_to('user_angeltypes', ['action' => 'add', 'angeltype_id' => $angeltype['id']]), sprintf(_('Become %s'), $angeltype['name']), 'btn-xs' ); @@ -232,8 +234,8 @@ class ShiftCalendarShiftRenderer $header_buttons = ''; if (in_array('admin_shifts', $privileges)) { $header_buttons = '
    ' . table_buttons([ - button(page_link_to('user_shifts') . '&edit_shift=' . $shift['SID'], glyph('edit'), 'btn-xs'), - button(page_link_to('user_shifts') . '&delete_shift=' . $shift['SID'], glyph('trash'), 'btn-xs') + button(page_link_to('user_shifts', ['edit_shift' => $shift['SID']]), glyph('edit'), 'btn-xs'), + button(page_link_to('user_shifts', ['delete_shift' => $shift['SID']]), glyph('trash'), 'btn-xs') ]) . '
    '; } $shift_heading = date('H:i', $shift['start']) . ' ‐ ' -- cgit v1.2.3-70-g09d2 From 96f1d9fd541d0c5ef78151f8c69a89c41684b67a Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Wed, 30 Aug 2017 14:59:27 +0200 Subject: Bugfixes --- includes/controller/shift_entries_controller.php | 6 +++--- includes/controller/shifts_controller.php | 11 ++++++----- includes/pages/admin_arrive.php | 4 ++-- includes/pages/admin_import.php | 20 ++++++++++++-------- includes/pages/admin_user.php | 4 ++-- includes/pages/user_myshifts.php | 4 ++-- includes/sys_page.php | 6 +++++- includes/view/Rooms_view.php | 2 +- includes/view/ShiftCalendarShiftRenderer.php | 14 +++++++++----- includes/view/ShiftsFilterRenderer.php | 11 ++++++++--- 10 files changed, 50 insertions(+), 32 deletions(-) (limited to 'includes/view/ShiftCalendarShiftRenderer.php') diff --git a/includes/controller/shift_entries_controller.php b/includes/controller/shift_entries_controller.php index 148b19fb..150db2e9 100644 --- a/includes/controller/shift_entries_controller.php +++ b/includes/controller/shift_entries_controller.php @@ -13,7 +13,7 @@ function shift_entry_add_controller() $request = request(); $shift_id = 0; - if ($request->has('shift_id') && preg_match('/^\d*$/', $request->input('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')); @@ -33,7 +33,7 @@ function shift_entry_add_controller() $shift['Name'] = $room_array[$shift['RID']]; $type_id = 0; - if ($request->has('type_id') && preg_match('/^\d*$/', $request->input('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')); @@ -64,7 +64,7 @@ function shift_entry_add_controller() if ( $request->has('user_id') - && preg_match('/^\d*$/', $request->input('user_id')) + && preg_match('/^\d+$/', $request->input('user_id')) && ( in_array('user_shifts_admin', $privileges) || in_array('shiftentry_edit_angeltype_supporter', $privileges) diff --git a/includes/controller/shifts_controller.php b/includes/controller/shifts_controller.php index c359850f..70011821 100644 --- a/includes/controller/shifts_controller.php +++ b/includes/controller/shifts_controller.php @@ -8,10 +8,13 @@ use Engelsystem\ShiftSignupState; */ function shift_link($shift) { - $link = page_link_to('shifts', ['action' => 'view']); + $parameters = ['action' => 'view']; if (isset($shift['SID'])) { - $link .= '&shift_id=' . $shift['SID']; + $parameters['shift_id'] = $shift['SID']; } + + $link = page_link_to('shifts', $parameters); + return $link; } @@ -201,7 +204,7 @@ function shift_delete_controller() } // Schicht komplett löschen (nur für admins/user mit user_shifts_admin privileg) - if (!$request->has('delete_shift') || !preg_match('/^\d*$/', $request->input('delete_shift'))) { + if (!$request->has('delete_shift') || !preg_match('/^\d+$/', $request->input('delete_shift'))) { redirect(page_link_to('user_shifts')); } $shift_id = $request->input('delete_shift'); @@ -316,8 +319,6 @@ function shifts_controller() /** * Redirects the user to his next shift. - * - * @return false */ function shift_next_controller() { diff --git a/includes/pages/admin_arrive.php b/includes/pages/admin_arrive.php index 2f312b1f..48e2c91f 100644 --- a/includes/pages/admin_arrive.php +++ b/includes/pages/admin_arrive.php @@ -23,7 +23,7 @@ function admin_arrive() $search = strip_request_item('search'); } - if ($request->has('reset') && preg_match('/^\d*$/', $request->input('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) { @@ -39,7 +39,7 @@ function admin_arrive() } else { $msg = error(_('Angel not found.'), true); } - } elseif ($request->has('arrived') && preg_match('/^\d*$/', $request->input('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) { diff --git a/includes/pages/admin_import.php b/includes/pages/admin_import.php index bf8c498c..e97f95e1 100644 --- a/includes/pages/admin_import.php +++ b/includes/pages/admin_import.php @@ -98,10 +98,12 @@ function admin_import() 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 + 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', [ @@ -207,10 +209,12 @@ function admin_import() ], 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 + page_link_to('admin_import', [ + 'step' => 'import', + 'shifttype_id' => $shifttype_id, + 'add_minutes_end' => $add_minutes_end, + 'add_minutes_start' => $add_minutes_start, + ]) ); break; diff --git a/includes/pages/admin_user.php b/includes/pages/admin_user.php index 9b3b0f44..0620155b 100644 --- a/includes/pages/admin_user.php +++ b/includes/pages/admin_user.php @@ -179,11 +179,11 @@ function admin_user() switch ($request->input('action')) { case 'save_groups': if ($user_id != $user['UID']) { - $my_highest_group = DB::select( + $my_highest_group = DB::selectOne( 'SELECT * FROM `UserGroups` WHERE `uid`=? ORDER BY `group_id`', [$user['UID']] ); - $his_highest_group = DB::select( + $his_highest_group = DB::selectOne( 'SELECT * FROM `UserGroups` WHERE `uid`=? ORDER BY `group_id`', [$user_id] ); diff --git a/includes/pages/user_myshifts.php b/includes/pages/user_myshifts.php index 60a26922..836bd566 100644 --- a/includes/pages/user_myshifts.php +++ b/includes/pages/user_myshifts.php @@ -46,7 +46,7 @@ function user_myshifts() ), button(page_link_to('user_myshifts', ['reset' => 'ack']), _('Continue'), 'btn-danger') ]); - } elseif ($request->has('edit') && preg_match('/^\d*$/', $request->input('edit'))) { + } elseif ($request->has('edit') && preg_match('/^\d+$/', $request->input('edit'))) { $user_id = $request->input('edit'); $shift = DB::selectOne(' SELECT @@ -124,7 +124,7 @@ function user_myshifts() } else { redirect(page_link_to('user_myshifts')); } - } elseif ($request->has('cancel') && preg_match('/^\d*$/', $request->input('cancel'))) { + } elseif ($request->has('cancel') && preg_match('/^\d+$/', $request->input('cancel'))) { $user_id = $request->input('cancel'); $shift = DB::selectOne(' SELECT * diff --git a/includes/sys_page.php b/includes/sys_page.php index df57d08a..33ec18b9 100644 --- a/includes/sys_page.php +++ b/includes/sys_page.php @@ -170,7 +170,11 @@ function strip_request_item($name, $default_value = null) function test_request_int($name) { $input = request()->input($name); - return preg_match('/^\d*$/', $input); + if (is_null($input)) { + return false; + } + + return preg_match('/^\d+$/', $input); } /** diff --git a/includes/view/Rooms_view.php b/includes/view/Rooms_view.php index 76ce33a5..3c0440a4 100644 --- a/includes/view/Rooms_view.php +++ b/includes/view/Rooms_view.php @@ -12,7 +12,7 @@ use Engelsystem\ShiftsFilterRenderer; function Room_view($room, ShiftsFilterRenderer $shiftsFilterRenderer, ShiftCalendarRenderer $shiftCalendarRenderer) { return page_with_title(glyph('map-marker') . $room['Name'], [ - $shiftsFilterRenderer->render(room_link($room)), + $shiftsFilterRenderer->render($room), $shiftCalendarRenderer->render() ]); } diff --git a/includes/view/ShiftCalendarShiftRenderer.php b/includes/view/ShiftCalendarShiftRenderer.php index f0488e83..0e5fc8c3 100644 --- a/includes/view/ShiftCalendarShiftRenderer.php +++ b/includes/view/ShiftCalendarShiftRenderer.php @@ -124,11 +124,15 @@ class ShiftCalendarShiftRenderer } if (in_array('user_shifts_admin', $privileges)) { - $html .= '
  • ' . button( - page_link_to('user_shifts', ['shift_id' => $shift['SID']]), - _('Add more angels'), - 'btn-xs' - ) . '
  • '; + $html .= '
  • ' . _('Add more angels') . ':'; + foreach ($needed_angeltypes as $angeltype) { + $html .= ' ' . button( + page_link_to('user_shifts', ['shift_id' => $shift['SID'], 'type_id' => $angeltype['id']]), + $angeltype['name'], + 'btn-xs' + ); + } + $html .= '
  • '; } if ($html != '') { return [ diff --git a/includes/view/ShiftsFilterRenderer.php b/includes/view/ShiftsFilterRenderer.php index 43a23ef6..c3e0ccf1 100644 --- a/includes/view/ShiftsFilterRenderer.php +++ b/includes/view/ShiftsFilterRenderer.php @@ -39,17 +39,22 @@ class ShiftsFilterRenderer /** * Renders the filter. * - * @param string $link_base + * @param array $room * @return string Generated HTML */ - public function render($link_base) + public function render($room) { $toolbar = []; if ($this->daySelectionEnabled && !empty($this->days)) { $selected_day = date('Y-m-d', $this->shiftsFilter->getStartTime()); $day_dropdown_items = []; foreach ($this->days as $day) { - $day_dropdown_items[] = toolbar_item_link($link_base . '&shifts_filter_day=' . $day, '', $day); + $link = page_link_to('rooms', [ + 'action' => 'view', + 'room_id' => $room['RID'], + 'shifts_filter_day' => $day, + ]); + $day_dropdown_items[] = toolbar_item_link($link, '', $day); } $toolbar[] = toolbar_dropdown('', $selected_day, $day_dropdown_items, 'active'); } -- cgit v1.2.3-70-g09d2