From 21ccc143a81efc2d265c5d051be49e5aa6ca0bf5 Mon Sep 17 00:00:00 2001
From: Jan-Hendrik Willms <tleilax+studip@gmail.com>
Date: Mon, 15 Apr 2024 14:52:00 +0000
Subject: [PATCH] fixes #4012

Closes #4012

Merge request studip/studip!2864
---
 app/controllers/course/room_requests.php      | 12 +++++++++---
 .../_new_request_form_footer.php              | 19 +++++++++++++++----
 .../request_find_matching_rooms.php           |  4 ++--
 app/views/course/wiki/search.php              |  3 ++-
 app/views/resources/room_request/decline.php  |  6 +++---
 5 files changed, 31 insertions(+), 13 deletions(-)

diff --git a/app/controllers/course/room_requests.php b/app/controllers/course/room_requests.php
index cdf8b1dcb43..a6c7a44638b 100644
--- a/app/controllers/course/room_requests.php
+++ b/app/controllers/course/room_requests.php
@@ -350,11 +350,14 @@ class Course_RoomRequestsController extends AuthenticatedController
         $this->step = (int)$step;
 
         $this->request = new RoomRequest($this->request_id);
-        $this->request->setRangeFields($_SESSION[$this->request_id]['range'], $_SESSION[$this->request_id]['range_ids']);
+        $this->request->setRangeFields(
+            $_SESSION[$this->request_id]['range'] ?? null,
+            $_SESSION[$this->request_id]['range_ids'] ?? null
+        );
 
         // let's find all the properties belonging to the selected category
         $this->room_category_id = $_SESSION[$request_id]['room_category_id'] ?: $this->request->category_id;
-        $this->room_name = $_SESSION[$request_id]['room_name'];
+        $this->room_name = $_SESSION[$request_id]['room_name'] ?? '';
         $this->selected_room = Resource::find($_SESSION[$request_id]['room_id'] ?: $this->request->resource_id);
         $this->category = $this->room_category_id ? ResourceCategory::find($this->room_category_id) : '';
         $this->available_properties = $this->room_category_id ? $this->category->getRequestableProperties() : '';
@@ -369,7 +372,10 @@ class Course_RoomRequestsController extends AuthenticatedController
         $this->comment = $_SESSION[$request_id]['comment'] ?? null;
 
         // when searching for a room name, list found room
-        if ($_SESSION[$request_id]['room_name'] !== '') {
+        if (
+            isset($_SESSION[$request_id]['room_name'])
+            && $_SESSION[$request_id]['room_name'] !== ''
+        ) {
             $search_properties['room_category_id'] = $this->room_category_id;
             $search_properties['seats'] = [
                 1,
diff --git a/app/views/course/room_requests/_new_request_form_footer.php b/app/views/course/room_requests/_new_request_form_footer.php
index 4b847905002..0bad0763b63 100644
--- a/app/views/course/room_requests/_new_request_form_footer.php
+++ b/app/views/course/room_requests/_new_request_form_footer.php
@@ -16,13 +16,24 @@
         <? endif ?>
 
         <? if ($step === 1 || $step === 2) : ?>
-                <? if ($_SESSION[$request_id]['search_by'] !== 'category') : ?>
-                    <? \Studip\Button::create(_('Raum auswählen'), 'select_room') ?>
+            <? if (
+                !isset($_SESSION[$request_id]['search_by'])
+                || $_SESSION[$request_id]['search_by'] !== 'category'
+            ) : ?>
+                <? \Studip\Button::create(_('Raum auswählen'), 'select_room') ?>
             <? endif ?>
         <? endif ?>
 
-        <? if (($step === 1 && $_SESSION[$request_id]['room_category_id'] !== '0')
-            || $step === 2) : ?>
+        <? if (
+            (
+                $step === 1
+                && (
+                    !isset($_SESSION[$request_id]['room_category_id'])
+                    || $_SESSION[$request_id]['room_category_id'] !== '0'
+                )
+            )
+            || $step === 2
+        ) : ?>
             <?= \Studip\Button::create(_('Weiter'), 'show_summary') ?>
         <? endif ?>
 
diff --git a/app/views/course/room_requests/request_find_matching_rooms.php b/app/views/course/room_requests/request_find_matching_rooms.php
index 0a11aeb4597..ce24e0f4fa8 100644
--- a/app/views/course/room_requests/request_find_matching_rooms.php
+++ b/app/views/course/room_requests/request_find_matching_rooms.php
@@ -85,7 +85,7 @@
                 <label>
                     <?= _('Raumname') ?>
                     <span class="flex-row">
-                    <input type="text" name="room_name" value="<?= htmlReady($_SESSION[$request_id]['room_name']) ?>">
+                    <input type="text" name="room_name" value="<?= htmlReady($_SESSION[$request_id]['room_name'] ?? '') ?>">
                     <?= Icon::create('search')->asInput(
                         [
                             'title' => _('Räume suchen'),
@@ -107,7 +107,7 @@
                                             <input type="radio" name="selected_room_id"
                                                    data-activates="button[type='submit'][name='select_room']"
                                                    value="<?= htmlReady($room->id) ?>"
-                                                <? if ($_SESSION[$request_id]['room_id'] === $room->id) echo 'checked' ?>>
+                                                <? if (isset($_SESSION[$request_id]['room_id']) && $_SESSION[$request_id]['room_id'] === $room->id) echo 'checked' ?>>
                                             <?= htmlReady(mila($room->name, 60)) . ' (' . $room['category']->name . ')'?>
                                             <? if ($room->properties): ?>
                                                 <? $property_names = $room->getInfolabelProperties()
diff --git a/app/views/course/wiki/search.php b/app/views/course/wiki/search.php
index 27811eb56bd..daf88fe113c 100644
--- a/app/views/course/wiki/search.php
+++ b/app/views/course/wiki/search.php
@@ -45,6 +45,7 @@
                 <td>
                     <?
                     $content = Studip\Markup::removeHtml($content);
+                    $ignore_next_hits = 0;
                     $offset  = 0;
                     $output  = [];
 
@@ -55,7 +56,7 @@
                             break;
                         }
                         $offset = $pos + 1;
-                        if (($ignore_next_hits--) > 0) {
+                        if ($ignore_next_hits-- > 0) {
                             // if more than one occurence is found
                             // in a fragment to be displayed,
                             // the fragment is only shown once
diff --git a/app/views/resources/room_request/decline.php b/app/views/resources/room_request/decline.php
index 188c4bba072..2c02126bc83 100644
--- a/app/views/resources/room_request/decline.php
+++ b/app/views/resources/room_request/decline.php
@@ -30,7 +30,7 @@
         <? endif ?>
     <? endif ?>
     <footer data-dialog-button>
-        <? if ($prev_request) : ?>
+        <? if (!empty($prev_request)) : ?>
             <?= \Studip\LinkButton::create(
                 _('Vorherige Anfrage'),
                 $controller->declineURL($prev_request),
@@ -45,7 +45,7 @@
         <? if ($show_form) : ?>
             <?= \Studip\Button::createAccept($delete_mode ? _('Löschen') : _('Ablehnen'), 'confirm') ?>
         <? endif ?>
-        <? if ($next_request) : ?>
+        <? if (!empty($next_request)) : ?>
             <?= \Studip\LinkButton::create(
                 _('Nächste Anfrage'),
                 $controller->declineURL($next_request),
@@ -53,4 +53,4 @@
             ) ?>
         <? endif ?>
     </footer>
-</form>
\ No newline at end of file
+</form>
-- 
GitLab