diff --git a/includes/controller/public_dashboard_controller.php b/includes/controller/public_dashboard_controller.php index 9d3b02b9..72fdd18c 100644 --- a/includes/controller/public_dashboard_controller.php +++ b/includes/controller/public_dashboard_controller.php @@ -81,7 +81,7 @@ function public_dashboard_controller_free_shift($shift, ShiftsFilter $filter = n 'shifttype_name' => $shifttype['name'], 'title' => $shift['title'], 'room_name' => $room->name, - 'needed_angels' => [] + 'needed_angels' => public_dashboard_needed_angels($shift['NeedAngels'], $filter), ]; if (time() + 3 * 60 * 60 > $shift['start']) { @@ -91,8 +91,6 @@ function public_dashboard_controller_free_shift($shift, ShiftsFilter $filter = n $free_shift['style'] = 'danger'; } - $free_shift['needed_angels'] = public_dashboard_needed_angels($shift['NeedAngels'], $filter); - return $free_shift; } diff --git a/includes/controller/shifts_controller.php b/includes/controller/shifts_controller.php index d5fe7db4..78bf85c8 100644 --- a/includes/controller/shifts_controller.php +++ b/includes/controller/shifts_controller.php @@ -17,9 +17,7 @@ function shift_link($shift) $parameters['shift_id'] = $shift['SID']; } - $link = page_link_to('shifts', $parameters); - - return $link; + return page_link_to('shifts', $parameters); } /** diff --git a/includes/controller/user_driver_licenses_controller.php b/includes/controller/user_driver_licenses_controller.php index 8c83601f..26a1aa3f 100644 --- a/includes/controller/user_driver_licenses_controller.php +++ b/includes/controller/user_driver_licenses_controller.php @@ -40,7 +40,7 @@ function user_driver_licenses_controller() $user = auth()->user(); if (!$user) { - throw_redirect(page_link_to('')); + throw_redirect(page_link_to()); } $action = strip_request_item('action', 'edit'); diff --git a/includes/controller/user_worklog_controller.php b/includes/controller/user_worklog_controller.php index 4ede1d9c..a9b02a4b 100644 --- a/includes/controller/user_worklog_controller.php +++ b/includes/controller/user_worklog_controller.php @@ -87,7 +87,7 @@ function user_worklog_from_request(Worklog $worklog) } $worklog->hours = $request->input('work_hours'); - if (!preg_match("/^[0-9]+(\.[0-9]{0,2})?$/", $worklog->hours)) { + if (!preg_match("/^\d+(\.\d{0,2})?$/", $worklog->hours)) { $valid = false; error(__('Please enter work hours in format ##[.##].')); } diff --git a/includes/controller/users_controller.php b/includes/controller/users_controller.php index 656ecdec..fcdb3fcc 100644 --- a/includes/controller/users_controller.php +++ b/includes/controller/users_controller.php @@ -19,7 +19,7 @@ function users_controller() $request = request(); if (!$user) { - throw_redirect(page_link_to('')); + throw_redirect(page_link_to()); } $action = 'list'; @@ -58,7 +58,7 @@ function user_delete_controller() } if (!auth()->can('admin_user')) { - throw_redirect(page_link_to('')); + throw_redirect(page_link_to()); } // You cannot delete yourself @@ -150,7 +150,7 @@ function user_edit_vouchers_controller() (!auth()->can('admin_user') && !auth()->can('voucher.edit')) || !config('enable_voucher') ) { - throw_redirect(page_link_to('')); + throw_redirect(page_link_to()); } if ($request->hasPostData('submit')) { @@ -266,7 +266,7 @@ function users_list_controller() $request = request(); if (!auth()->can('admin_user')) { - throw_redirect(page_link_to('')); + throw_redirect(page_link_to()); } $order_by = 'name'; @@ -385,8 +385,6 @@ function shiftCalendarRendererByShiftFilter(ShiftsFilter $shiftsFilter) $filtered_shifts = []; foreach ($shifts as $shift) { $needed_angels_count = 0; - $taken = 0; - foreach ($needed_angeltypes[$shift['SID']] as $needed_angeltype) { $taken = 0; diff --git a/includes/engelsystem.php b/includes/engelsystem.php index acd45f77..b156c68a 100644 --- a/includes/engelsystem.php +++ b/includes/engelsystem.php @@ -18,6 +18,7 @@ require __DIR__ . '/includes.php'; /** * Check for maintenance */ +/** @var \Engelsystem\Application $app */ if ($app->get('config')->get('maintenance')) { http_response_code(503); $url = $app->get(UrlGeneratorInterface::class); diff --git a/includes/helper/email_helper.php b/includes/helper/email_helper.php index b2473e64..eff64675 100644 --- a/includes/helper/email_helper.php +++ b/includes/helper/email_helper.php @@ -29,7 +29,7 @@ function engelsystem_email_to_user($recipientUser, $title, $message, $notIfItsMe $translator->setLocale($recipientUser->settings->language); $mailer->sendView( - $recipientUser->contact->email ? $recipientUser->contact->email : $recipientUser->email, + $recipientUser->contact->email ?: $recipientUser->email, $title, 'emails/mail', ['username' => $recipientUser->name, 'message' => $message] diff --git a/includes/model/ShiftsFilter.php b/includes/model/ShiftsFilter.php index c3811977..65f7024b 100644 --- a/includes/model/ShiftsFilter.php +++ b/includes/model/ShiftsFilter.php @@ -27,13 +27,13 @@ class ShiftsFilter private $userShiftsAdmin; /** @var int[] */ - private $filled = []; + private $filled; /** @var int[] */ - private $rooms = []; + private $rooms; /** @var int[] */ - private $types = []; + private $types; /** @var int unix timestamp */ private $startTime = null; diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php index 232987ca..43fc63b7 100644 --- a/includes/model/Shifts_model.php +++ b/includes/model/Shifts_model.php @@ -375,8 +375,8 @@ function Shift_signup_allowed_angel( if ( empty($user_angeltype) - || ($angeltype['no_self_signup'] == 1 && !empty($user_angeltype)) - || ($angeltype['restricted'] == 1 && !empty($user_angeltype) && !isset($user_angeltype['confirm_user_id'])) + || $angeltype['no_self_signup'] == 1 + || ($angeltype['restricted'] == 1 && !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 diff --git a/includes/model/UserDriverLicenses_model.php b/includes/model/UserDriverLicenses_model.php deleted file mode 100644 index 181e631b..00000000 --- a/includes/model/UserDriverLicenses_model.php +++ /dev/null @@ -1,130 +0,0 @@ - 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 - ]; -} - -/** - * Is it valid? - * - * @param array $user_driver_license The UserDriverLicense to check - * @return boolean - */ -function UserDriverLicense_valid($user_driver_license) -{ - return - $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']; -} - -/** - * Get a users driver license information - * - * @param int $user_id The users id - * @return array|null - */ -function UserDriverLicense($user_id) -{ - $driverLicense = DB::selectOne(' - SELECT * - FROM `UserDriverLicenses` - WHERE `user_id`=?', [$user_id]); - - return empty($driverLicense) ? null : $driverLicense; -} - -/** - * Create a user's driver license entry - * - * @param array $user_driver_license The UserDriverLicense to create - * @param int $userId - * @return array - */ -function UserDriverLicenses_create($user_driver_license, $userId) -{ - $user_driver_license['user_id'] = $userId; - DB::insert(' - INSERT INTO `UserDriverLicenses` ( - `user_id`, - `has_car`, - `has_license_car`, - `has_license_3_5t_transporter`, - `has_license_7_5t_truck`, - `has_license_12_5t_truck`, - `has_license_forklift` - ) - VALUES (?, ?, ?, ?, ?, ?, ?) - ', - [ - $user_driver_license['user_id'], - (int)$user_driver_license['has_car'], - (int)$user_driver_license['has_license_car'], - (int)$user_driver_license['has_license_3_5t_transporter'], - (int)$user_driver_license['has_license_7_5t_truck'], - (int)$user_driver_license['has_license_12_5t_truck'], - (int)$user_driver_license['has_license_forklift'], - ] - ); - - return $user_driver_license; -} - -/** - * Update a user's driver license entry - * - * @param array $user_driver_license The UserDriverLicense to update - */ -function UserDriverLicenses_update($user_driver_license) -{ - DB::update(' - UPDATE `UserDriverLicenses` - SET - `has_car`=?, - `has_license_car`=?, - `has_license_3_5t_transporter`=?, - `has_license_7_5t_truck`=?, - `has_license_12_5t_truck`=?, - `has_license_forklift`=? - WHERE `user_id`=? - ', - [ - (int)$user_driver_license['has_car'], - (int)$user_driver_license['has_license_car'], - (int)$user_driver_license['has_license_3_5t_transporter'], - (int)$user_driver_license['has_license_7_5t_truck'], - (int)$user_driver_license['has_license_12_5t_truck'], - (int)$user_driver_license['has_license_forklift'], - $user_driver_license['user_id'], - ] - ); -} - -/** - * Delete a user's driver license entry - * - * @param int $user_id - */ -function UserDriverLicenses_delete($user_id) -{ - DB::delete('DELETE FROM `UserDriverLicenses` WHERE `user_id`=?', [$user_id]); -} diff --git a/includes/model/UserWorkLog_model.php b/includes/model/UserWorkLog_model.php index 56f3b104..e00a4c03 100644 --- a/includes/model/UserWorkLog_model.php +++ b/includes/model/UserWorkLog_model.php @@ -2,7 +2,6 @@ use Carbon\Carbon; use Engelsystem\Models\Room; -use Engelsystem\Models\User\User; use Engelsystem\Models\Worklog; use Illuminate\Support\Collection; diff --git a/includes/pages/admin_active.php b/includes/pages/admin_active.php index f4be148e..14cf8d5f 100644 --- a/includes/pages/admin_active.php +++ b/includes/pages/admin_active.php @@ -306,7 +306,7 @@ function admin_active() form_submit('submit', __('Search')) ], page_link_to('admin_active')), $set_active == '' ? form([ - form_text('count', __('How much angels should be active?'), $count ? $count : $forced_count), + form_text('count', __('How much angels should be active?'), $count ?: $forced_count), form_submit('set_active', __('Preview')) ]) : $set_active, $msg . msg(), diff --git a/includes/pages/admin_free.php b/includes/pages/admin_free.php index 29226289..7710ba80 100644 --- a/includes/pages/admin_free.php +++ b/includes/pages/admin_free.php @@ -91,7 +91,7 @@ function admin_free() } } - $email = ($usr->contact->email ? $usr->contact->email : $usr->email); + $email = $usr->contact->email ?: $usr->email; $free_users_table[] = [ 'name' => User_Nick_render($usr) . User_Pronoun_render($usr), 'shift_state' => User_shift_state_render($usr), diff --git a/includes/pages/admin_groups.php b/includes/pages/admin_groups.php index d6a25eb1..c43135e1 100644 --- a/includes/pages/admin_groups.php +++ b/includes/pages/admin_groups.php @@ -123,14 +123,11 @@ function admin_groups() $group = Db::selectOne('SELECT * FROM `Groups` WHERE `UID`=? LIMIT 1', [$group_id]); $privileges = $request->request->all('privileges'); - if (!is_array($privileges)) { - $privileges = []; - } if (!empty($group)) { Db::delete('DELETE FROM `GroupPrivileges` WHERE `group_id`=?', [$group_id]); $privilege_names = []; foreach ($privileges as $privilege) { - if (preg_match('/^\d{1,}$/', $privilege)) { + if (preg_match('/^\d+$/', $privilege)) { $group_privileges_source = Db::selectOne( 'SELECT `name` FROM `Privileges` WHERE `id`=? LIMIT 1', [$privilege] diff --git a/includes/pages/admin_shifts.php b/includes/pages/admin_shifts.php index 7bf75f10..bb6eda00 100644 --- a/includes/pages/admin_shifts.php +++ b/includes/pages/admin_shifts.php @@ -27,8 +27,8 @@ function admin_shifts() $session = session(); $start = Carbon::createTimestampFromDatetime(date('Y-m-d') . 'T00:00'); $end = $start; - $mode = 'single'; - $angelmode = 'manually'; + $mode = ''; + $angelmode = ''; $length = ''; $change_hours = []; $title = ''; @@ -452,7 +452,7 @@ function admin_shifts() div('col-md-6', [ form_datetime('start', __('Start'), $start), form_datetime('end', __('End'), $end), - form_info(__('Mode'), ''), + form_info(__('Mode')), form_radio('mode', __('Create one shift'), $mode == 'single', 'single'), form_radio('mode', __('Create multiple shifts'), $mode == 'multi', 'multi'), form_text( @@ -482,7 +482,7 @@ function admin_shifts() ) ]), div('col-md-6', [ - form_info(__('Needed angels'), ''), + form_info(__('Needed angels')), form_radio( 'angelmode', __('Take needed angels from room settings'), diff --git a/includes/pages/admin_user.php b/includes/pages/admin_user.php index 3f3dcc31..df715b98 100644 --- a/includes/pages/admin_user.php +++ b/includes/pages/admin_user.php @@ -44,7 +44,7 @@ function admin_user() . page_link_to('admin_user', ['action' => 'save', 'id' => $user_id]) . '" method="post">' . "\n"; $html .= form_csrf(); - $html .= '
' . "\n";
$html .= '
|
' . $text . '
', ''); + return form_element($label, '' . $text . '
'); } /** diff --git a/includes/sys_page.php b/includes/sys_page.php index 1a1dc218..4597caaa 100644 --- a/includes/sys_page.php +++ b/includes/sys_page.php @@ -173,7 +173,7 @@ function check_date($input, $error_message = null, $null_allowed = false, $time_ * Returns REQUEST value filtered or default value (null) if not set. * * @param string $name - * @param string $default_value + * @param string|null $default_value * @return mixed|null */ function strip_request_item($name, $default_value = null) @@ -215,7 +215,7 @@ function strip_request_item_nl($name, $default_value = null) if ($request->has($name)) { // Only allow letters, symbols, punctuation, separators, numbers and newlines without html tags return preg_replace( - "/([^\p{L}\p{S}\p{P}\p{Z}\p{N}+\n]{1,})/ui", + "/([^\p{L}\p{S}\p{P}\p{Z}\p{N}+\n]+)/ui", '', strip_tags($request->input($name)) ); @@ -232,7 +232,7 @@ function strip_request_item_nl($name, $default_value = null) function strip_item($item) { // Only allow letters, symbols, punctuation, separators and numbers without html tags - return preg_replace("/([^\p{L}\p{S}\p{P}\p{Z}\p{N}+]{1,})/ui", '', strip_tags($item)); + return preg_replace("/([^\p{L}\p{S}\p{P}\p{Z}\p{N}+]+)/ui", '', strip_tags($item)); } /** diff --git a/includes/sys_template.php b/includes/sys_template.php index 9585202a..cf51b291 100644 --- a/includes/sys_template.php +++ b/includes/sys_template.php @@ -110,7 +110,7 @@ function progress_bar($valuemin, $valuemax, $valuenow, $class = '', $content = ' . 'aria-valuenow="' . $valuenow . '" aria-valuemin="' . $valuemin . '" aria-valuemax="' . $valuemax . '" ' . 'style="width: ' . floor(($valuenow - $valuemin) * 100 / ($valuemax - $valuemin)) . '%"' . '>' - . $content . '' + . $content . '' . ''; } diff --git a/includes/view/PublicDashboard_view.php b/includes/view/PublicDashboard_view.php index 3f51619b..a4a9944a 100644 --- a/includes/view/PublicDashboard_view.php +++ b/includes/view/PublicDashboard_view.php @@ -23,7 +23,7 @@ function public_dashboard_view($stats, $free_shifts) $shift_panels[] = ''; $needed_angels = div('first', [ div('col-md-12', [ - heading(__('Needed angels:'), 1) + heading(__('Needed angels:')) ]), div('container-fluid', [ join($shift_panels) diff --git a/includes/view/Rooms_view.php b/includes/view/Rooms_view.php index 10d0f723..a2430729 100644 --- a/includes/view/Rooms_view.php +++ b/includes/view/Rooms_view.php @@ -24,7 +24,7 @@ function Room_view(Room $room, ShiftsFilterRenderer $shiftsFilterRenderer, Shift if ($room->description) { $description = '