From 47f0587cd979b3b88439dd9a0318400250dce5a0 Mon Sep 17 00:00:00 2001 From: msquare Date: Sun, 13 Aug 2023 16:52:41 +0200 Subject: [PATCH] fixes #1169: improve shift change hour sanitation --- includes/pages/admin_shifts.php | 26 ++++++++++++++++++-------- resources/lang/de_DE/default.po | 3 +++ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/includes/pages/admin_shifts.php b/includes/pages/admin_shifts.php index c4fc29bc..80d85c71 100644 --- a/includes/pages/admin_shifts.php +++ b/includes/pages/admin_shifts.php @@ -139,6 +139,23 @@ function admin_shifts() 'trim', explode(',', $request->input('change_hours')) ); + // Fehlende Minutenangaben ergänzen, 24 Uhr -> 00 Uhr + array_walk($change_hours, function (&$value) use ($valid) { + if (!preg_match('/^(\d{1,2}):\d{2}$/', $value)) { + $value .= ':00'; + } + if ($value == '24:00') { + $value = '00:00'; + } + }); + // Ensure valid time in change hours + foreach ($change_hours as $change_hour) { + if (!preg_match('/^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$/', $change_hour)) { + $valid = false; + error(sprintf(__('Please validate the change hour %s. It should be between 00:00 and 24:00.'), $change_hour)); + } + } + $change_hours = array_unique($change_hours); } else { $valid = false; error(__('Please split the shift-change hours by colons.')); @@ -224,13 +241,6 @@ function admin_shifts() $shift_start = $shift_end; } while ($shift_end < $end); } elseif ($mode == 'variable') { - // Fehlende Minutenangaben ergänzen - array_walk($change_hours, function (&$value) { - if (!preg_match('/^\d{1,2}:\d{2}$/', $value)) { - $value .= ':00'; - } - }); - // Alle Tage durchgehen $end_day = Carbon::createFromDatetime($end->format('Y-m-d') . ' 00:00'); $day = Carbon::createFromDatetime($start->format('Y-m-d') . ' 00:00'); @@ -488,7 +498,7 @@ function admin_shifts() 'change_hours', __('Shift change hours'), $request->has('change_hours') - ? $request->input('change_hours') + ? ($change_hours ? implode(', ', $change_hours) : $request->input('change_hours')) : '00, 04, 08, 10, 12, 14, 16, 18, 20, 22', false, null, diff --git a/resources/lang/de_DE/default.po b/resources/lang/de_DE/default.po index 5d501ff3..9b1b4cd6 100644 --- a/resources/lang/de_DE/default.po +++ b/resources/lang/de_DE/default.po @@ -945,6 +945,9 @@ msgstr "Die Endzeit muss nach der Startzeit liegen." msgid "Please enter a shift duration in minutes." msgstr "Gib bitte eine Schichtlänge in Minuten ein." +msgid "Please validate the change hour %s. It should be between 00:00 and 24:00." +msgstr "Bitte korrigiere die Schichtwechselstunde %s. Sie sollte zwischen 00:00 und 24:00 Uhr liegen." + msgid "Please split the shift-change hours by colons." msgstr "Trenne die Schichtwechselstunden mit einem Komma."