From 8e9222919fa9cc06dcfbbeb10e12667c6bd95b26 Mon Sep 17 00:00:00 2001
From: Jan-Hendrik Willms <tleilax+studip@gmail.com>
Date: Mon, 30 Sep 2024 10:15:54 +0000
Subject: [PATCH] prevent many warnings regarding php8 on main, fixes #4631

Closes #4631

Merge request studip/studip!3448
---
 app/controllers/admission/courseset.php       |  4 +--
 app/controllers/course/members.php            | 11 +++-----
 app/controllers/institute/members.php         |  3 +++
 app/controllers/messages.php                  |  2 +-
 app/controllers/multipersonsearch.php         |  2 +-
 app/controllers/my_courses.php                |  2 +-
 app/controllers/resources/room_request.php    | 26 +++++++++----------
 app/views/admin/cronjobs/logs/index.php       |  8 +++---
 app/views/course/enrolment/apply.php          |  2 +-
 app/views/course/management/lock.php          |  2 +-
 app/views/course/members/awaiting_list.php    |  2 +-
 .../room_requests/request_show_summary.php    |  2 +-
 .../wizard/steps/advancedbasicdata/index.php  |  6 ++---
 app/views/file/add_url.php                    |  2 +-
 app/views/file/choose_file.php                |  2 +-
 app/views/file/choose_folder_from_course.php  |  2 +-
 app/views/file/edit.php                       |  2 +-
 app/views/file/edit_urlfile.php               |  2 +-
 app/views/file/update.php                     |  2 +-
 app/views/institute/members/_table_body.php   |  2 +-
 .../resources/booking/_add_edit_form.php      |  4 +--
 app/views/resources/booking/index.php         |  4 +--
 .../room_request/resolve_room_tr.php          |  4 +--
 lib/classes/Markup.php                        |  7 +++--
 lib/classes/MyRealmModel.php                  |  2 +-
 lib/classes/Request.php                       |  7 +++--
 lib/classes/Visibility.php                    |  4 ++-
 lib/classes/admission/AdmissionPriority.php   | 14 +++++++++-
 .../AdvancedBasicDataWizardStep.php           |  8 +++---
 .../coursewizardsteps/BasicDataWizardStep.php |  5 ++--
 .../globalsearch/GlobalSearchCourses.php      |  5 +++-
 .../globalsearch/GlobalSearchForum.php        |  5 +++-
 lib/classes/librarysearch/LibraryDocument.php |  2 +-
 lib/filesystem/LibraryFile.php                |  8 +++---
 lib/filesystem/URLFile.php                    |  4 +--
 lib/models/AdmissionApplication.php           |  1 +
 lib/models/OERHostOERSI.php                   |  2 +-
 lib/models/SemesterHoliday.php                |  1 -
 lib/models/SeminarCycleDate.php               |  2 +-
 lib/models/resources/ResourceRequest.php      |  8 +++---
 lib/visual.inc.php                            |  5 ++++
 templates/dates/seminar_html_roomplanning.php |  2 +-
 templates/userfilter/display.php              |  3 +--
 43 files changed, 108 insertions(+), 85 deletions(-)

diff --git a/app/controllers/admission/courseset.php b/app/controllers/admission/courseset.php
index 65d42470ea8..e694a2455f2 100644
--- a/app/controllers/admission/courseset.php
+++ b/app/controllers/admission/courseset.php
@@ -85,7 +85,7 @@ class Admission_CoursesetController extends AuthenticatedController
         $filter['semester_id'] = $this->current_semester_id != 'all' ? $this->current_semester_id : null;
         $filter['rule_types'] = array_keys($this->current_rule_types);
         $this->myInstitutes = CoursesetModel::getInstitutes($filter);
-        if (!$this->current_institut_id) {
+        if (!$this->current_institut_id && count($this->myInstitutes) > 0) {
             if (!isset($this->myInstitutes['all']['count']) || $this->myInstitutes['all']['count'] < 100) {
                 $this->current_institut_id = 'all';
             } else {
@@ -105,7 +105,7 @@ class Admission_CoursesetController extends AuthenticatedController
         }
 
         foreach ($institutes as $one) {
-            if ($this->myInstitutes[$one]['count']) {
+            if (!empty($this->myInstitutes[$one]['count'])) {
                 $sets = CourseSet::getCoursesetsByInstituteId($one, $filter);
                 foreach ($sets as $set) {
                     $courseset = new CourseSet($set['set_id']);
diff --git a/app/controllers/course/members.php b/app/controllers/course/members.php
index c405d4274df..a3f454d1d7a 100644
--- a/app/controllers/course/members.php
+++ b/app/controllers/course/members.php
@@ -2148,16 +2148,11 @@ class Course_MembersController extends AuthenticatedController
 
     /**
      * Get the position out of the database
-     * @param String $user_id
-     * @return int
      */
-    private function getPosition($user_id): ?int
+    private function getPosition(string $user_id): int
     {
-        $membership = CourseMember::findByUser($user_id);
-        if ($membership) {
-            return (int)$membership->position;
-        }
-        return 0;
+        $membership = CourseMember::find([$this->course_id, $user_id]);
+        return $membership->position ?? 0;
     }
 
     private function getLogLevel($direction, $status)
diff --git a/app/controllers/institute/members.php b/app/controllers/institute/members.php
index 41584785f4d..d5d991df78e 100644
--- a/app/controllers/institute/members.php
+++ b/app/controllers/institute/members.php
@@ -261,6 +261,9 @@ class Institute_MembersController extends AuthenticatedController
 
             // Find members
             $institut_members = $this->institute->members->filter(function ($member) use ($group) {
+                if (!$member->user) {
+                    return false;
+                }
                 if ($member->inst_perms === 'user') {
                     return false;
                 }
diff --git a/app/controllers/messages.php b/app/controllers/messages.php
index 17ad4ce597a..d9d71da7f35 100644
--- a/app/controllers/messages.php
+++ b/app/controllers/messages.php
@@ -312,7 +312,7 @@ class MessagesController extends AuthenticatedController {
                     $params['status'] = explode(',', Request::get('who', ''));
                 }
                 if ($filter === 'all' || $filter === 'send_sms_to_all') {
-                    if ($params['status']) {
+                    if (!empty($params['status'])) {
                         $additional .= ' AND seminar_user.status IN ( :status )';
                     }
                     $query = "SELECT user_id, 'rec' AS snd_rec
diff --git a/app/controllers/multipersonsearch.php b/app/controllers/multipersonsearch.php
index ecbcf270291..3aa50c6a1f3 100644
--- a/app/controllers/multipersonsearch.php
+++ b/app/controllers/multipersonsearch.php
@@ -31,7 +31,7 @@ class MultipersonsearchController extends AuthenticatedController
         if (mb_strlen($searchterm) >= 3) {
             $mp = MultiPersonSearch::load($name);
             $searchObject = $mp->getSearchObject();
-            if (isset($searchObject)) {
+            if (isset($searchObject) && !is_bool($searchObject)) {
                 $result = array_map(function ($r) {
                     return $r['user_id'];
                 }, $searchObject->getResults($searchterm, [], 50));
diff --git a/app/controllers/my_courses.php b/app/controllers/my_courses.php
index c3a3c032d41..d856ad4f8e3 100644
--- a/app/controllers/my_courses.php
+++ b/app/controllers/my_courses.php
@@ -383,7 +383,7 @@ class MyCoursesController extends AuthenticatedController
 
             if (Request::get('cmd') == 'suppose_to_kill') {
                 // check course admission
-                list(,$admission_end_time) = @array_values($course->getAdmissionTimeFrame());
+                $admission_end_time = $course->getAdmissionTimeFrame()['end_time'] ?? null;
 
                 $admission_enabled = $course->isAdmissionEnabled();
                 $admission_locked   = $course->isAdmissionLocked();
diff --git a/app/controllers/resources/room_request.php b/app/controllers/resources/room_request.php
index 82651995fef..8cc87023e4d 100644
--- a/app/controllers/resources/room_request.php
+++ b/app/controllers/resources/room_request.php
@@ -975,7 +975,7 @@ class Resources_RoomRequestController extends AuthenticatedController
             $new_begin->setTime(
                 $begin_time_arr[0],
                 $begin_time_arr[1],
-                $begin_time_arr[2]
+                $begin_time_arr[2] ?? 0
             );
             $new_end = new DateTime();
             $new_end->setDate(
@@ -986,7 +986,7 @@ class Resources_RoomRequestController extends AuthenticatedController
             $new_end->setTime(
                 $end_time_arr[0],
                 $end_time_arr[1],
-                $end_time_arr[2]
+                $end_time_arr[2] == 0
             );
 
             $this->request->begin = $new_begin->getTimestamp();
@@ -1606,7 +1606,7 @@ class Resources_RoomRequestController extends AuthenticatedController
                     if ($metadate->dates) {
                         $overlap_messages = [];
                         foreach ($metadate->dates as $date) {
-                            if ($date->room_booking->resource_id != $room_id) {
+                            if (!$date->room_booking || $date->room_booking->resource_id != $room_id) {
                                 try {
                                     $booking = $room->createBooking(
                                         $this->current_user,
@@ -1619,7 +1619,7 @@ class Resources_RoomRequestController extends AuthenticatedController
                                         ],
                                         null,
                                         0,
-                                        $course_date->end_time,
+                                        $date->end_time,
                                         $this->request->preparation_time
                                     );
                                     if ($booking instanceof ResourceBooking) {
@@ -1642,7 +1642,7 @@ class Resources_RoomRequestController extends AuthenticatedController
                     }
                 } elseif ($range_data[0] == 'User') {
                     $user = User::find($range_data[1]);
-                    if (!($user instanceof User)) {
+                    if (!$user) {
                         PageLayout::postError(
                             sprintf(
                                 _('Die Person mit der ID %s wurde nicht gefunden!'),
@@ -1837,19 +1837,19 @@ class Resources_RoomRequestController extends AuthenticatedController
     {
         $pos = array_search($this->filter['filter_request_id'], $request_ids);
         $max = count($request_ids);
-        if($pos === 0) {
-            $prev_pos = $max-1;
-            $next_pos = $pos+1;
+        if ($pos === 0) {
+            $prev_pos = $max - 1;
+            $next_pos = $pos + 1;
         } else {
-            $prev_pos = $pos-1;
-            $next_pos = $pos+1;
+            $prev_pos = $pos - 1;
+            $next_pos = $pos + 1;
 
-            if($next_pos === $max) {
+            if ($next_pos === $max) {
                 $next_pos = 0;
             }
         }
-        $this->prev_request = $request_ids[$prev_pos];
-        $this->next_request = $request_ids[$next_pos];
+        $this->prev_request = $request_ids[$prev_pos] ?? null;
+        $this->next_request = $request_ids[$next_pos] ?? null;
     }
 
     protected function getSingleDateDataForExportRow(CourseDate $date)
diff --git a/app/views/admin/cronjobs/logs/index.php b/app/views/admin/cronjobs/logs/index.php
index f29579c5d8d..d76e153b1c4 100644
--- a/app/views/admin/cronjobs/logs/index.php
+++ b/app/views/admin/cronjobs/logs/index.php
@@ -27,10 +27,10 @@ use Studip\Button, Studip\LinkButton;
             <?= _('Status') ?>
             <select name="filter[status]" id="status" class="submit-upon-select">
                 <option value=""><?= _('Alle Logeinträge anzeigen') ?></option>
-                <option value="passed" <? if ($filter['status'] === 'passed') echo 'selected'; ?>>
+                <option value="passed" <? if (isset($filter['status']) && $filter['status'] === 'passed') echo 'selected'; ?>>
                     <?= _('Nur fehlerfreie Logeinträge anzeigen') ?>
                 </option>
-                <option value="failed" <? if ($filter['status'] === 'failed') echo 'selected'; ?>>
+                <option value="failed" <? if (isset($filter['status']) && $filter['status'] === 'failed') echo 'selected'; ?>>
                     <?= _('Nur fehlerhafte Logeinträge anzeigen') ?>
                 </option>
             </select>
@@ -41,7 +41,7 @@ use Studip\Button, Studip\LinkButton;
             <select name="filter[schedule_id]" id="schedule_id" class="submit-upon-select">
                 <option value=""><?= _('Alle Logeinträge anzeigen') ?></option>
                 <? foreach ($schedules as $schedule): ?>
-                    <option value="<?= $schedule->schedule_id ?>" <? if ($filter['schedule_id'] === $schedule->schedule_id) echo 'selected'; ?>>
+                    <option value="<?= $schedule->schedule_id ?>" <? if (isset($filter['schedule_id']) && $filter['schedule_id'] === $schedule->schedule_id) echo 'selected'; ?>>
                         <?= htmlReady($schedule->title) ?>
                     </option>
                 <? endforeach; ?>
@@ -53,7 +53,7 @@ use Studip\Button, Studip\LinkButton;
             <select name="filter[task_id]" id="task_id" class="submit-upon-select">
                 <option value=""><?= _('Alle Aufgaben anzeigen') ?></option>
                 <? foreach ($tasks as $task): ?>
-                    <option value="<?= $task->task_id ?>" <? if ($filter['task_id'] === $task->task_id) echo 'selected'; ?>>
+                    <option value="<?= $task->task_id ?>" <? if (isset($filter['task_id']) && $filter['task_id'] === $task->task_id) echo 'selected'; ?>>
                         <?= htmlReady($task->name) ?>
                     </option>
                 <? endforeach; ?>
diff --git a/app/views/course/enrolment/apply.php b/app/views/course/enrolment/apply.php
index 531a5525b03..8d4ecb98e68 100644
--- a/app/views/course/enrolment/apply.php
+++ b/app/views/course/enrolment/apply.php
@@ -1,5 +1,5 @@
 <?= $admission_error ?>
-<? if ($courseset_message) : ?>
+<? if (!empty($courseset_message)) : ?>
 <p>
     <?= $courseset_message ?>
 </p>
diff --git a/app/views/course/management/lock.php b/app/views/course/management/lock.php
index 6d3d7ccba7d..bdce8a3b6f6 100644
--- a/app/views/course/management/lock.php
+++ b/app/views/course/management/lock.php
@@ -12,7 +12,7 @@
                 <?= _('Sperrebene') ?>
                 <select name="lock_sem" id="lock_sem" aria-labelledby="<?= _('Sperrebene auswählen')?>">
                 <? foreach ($all_lock_rules as $lock_rule) : ?>
-                    <option value="<?= $lock_rule['lock_id'] ?>" <?= $current_lock_rule->id == $lock_rule['lock_id'] ? 'selected' : '' ?>>
+                    <option value="<?= $lock_rule['lock_id'] ?>" <?= $current_lock_rule && $current_lock_rule->id == $lock_rule['lock_id'] ? 'selected' : '' ?>>
                         <?= htmlReady($lock_rule['name']) ?>
                     </option>
                 <? endforeach ?>
diff --git a/app/views/course/members/awaiting_list.php b/app/views/course/members/awaiting_list.php
index 1981910e37f..f9dcce41816 100644
--- a/app/views/course/members/awaiting_list.php
+++ b/app/views/course/members/awaiting_list.php
@@ -79,7 +79,7 @@
             <? endif ?>
                 <td style="text-align: right"><?= sprintf('%02d', ++$nr) ?></td>
                 <td>
-                    <a href="<?= $controller->url_for('profile?username=' . $waiting['username']) ?>" <? if ($waiting['mkdate'] >= $last_visitdate) echo 'class="new-member"'; ?>>
+                    <a href="<?= $controller->link_for('profile', ['username' => $waiting['username']]) ?>" <? if ($waiting['mkdate'] >= $last_visitdate) echo 'class="new-member"'; ?>>
                         <?= Avatar::getAvatar($waiting['user_id'], $waiting['username'])->getImageTag(Avatar::SMALL, [
                             'style' => 'margin-right: 5px',
                             'title' => $fullname,
diff --git a/app/views/course/room_requests/request_show_summary.php b/app/views/course/room_requests/request_show_summary.php
index 116caf8f87e..9125bdd5ab8 100644
--- a/app/views/course/room_requests/request_show_summary.php
+++ b/app/views/course/room_requests/request_show_summary.php
@@ -15,7 +15,7 @@
             <label>
                 <?= _('Ausgewählte Raumkategorie') ?>
                 <input type="hidden" name="selected_room_id"
-                       value="<?= htmlReady($selected_room ? $selected_room->id : '') ?>">
+                       value="<?= htmlReady($selected_room->id ?? '') ?>">
                 <br>
 
                 <strong><?= htmlReady($selected_room_category->name) ?></strong>
diff --git a/app/views/course/wizard/steps/advancedbasicdata/index.php b/app/views/course/wizard/steps/advancedbasicdata/index.php
index f5060b0262f..30d034ccee0 100644
--- a/app/views/course/wizard/steps/advancedbasicdata/index.php
+++ b/app/views/course/wizard/steps/advancedbasicdata/index.php
@@ -1,4 +1,4 @@
-<?= $this->render_partial('basicdata/index.php', ['value' => $value]) ?>
+<?= $this->render_partial('basicdata/index.php', ['values' => $values]) ?>
 
 <section>
     <label for="wizard-subtitle">
@@ -16,11 +16,11 @@
     <label for="wizard-ects">
         <?= _('ECTS-Punkte') ?>
     </label>
-    <input type="text" name="ects" id="wizard-ects" size="20" maxlength="32" value="<?= htmlReady($values['ects']) ?>"/>
+    <input type="text" name="ects" id="wizard-ects" size="20" maxlength="32" value="<?= htmlReady($values['ects'] ?? '') ?>"/>
 </section>
 <section>
     <label for="wizard-maxmembers">
         <?= _('max. Teilnehmendenzahl') ?>
     </label>
-    <input type="number" name="maxmembers" id="wizard-maxmember" min="0" value="<?= htmlReady($values['maxmembers']) ?>"/>
+    <input type="number" name="maxmembers" id="wizard-maxmember" min="0" value="<?= htmlReady($values['maxmembers'] ?? '') ?>"/>
 </section>
diff --git a/app/views/file/add_url.php b/app/views/file/add_url.php
index 8a172c9a3f2..4a0c48659aa 100644
--- a/app/views/file/add_url.php
+++ b/app/views/file/add_url.php
@@ -36,7 +36,7 @@
         <?= Studip\Button::createAccept(_('Speichern'), 'store') ?>
         <?= Studip\LinkButton::createCancel(
             _('Zurück'),
-            $controller->action_url('add_files_window/' . Request::option('to_folder_id'), $options),
+            $controller->action_url('add_files_window/' . Request::option('to_folder_id'), $options ?? []),
             ['data-dialog' => '']
         ) ?>
     </footer>
diff --git a/app/views/file/choose_file.php b/app/views/file/choose_file.php
index 3eb5221c775..8a5cebd728e 100644
--- a/app/views/file/choose_file.php
+++ b/app/views/file/choose_file.php
@@ -94,7 +94,7 @@ if (Request::get('to_folder_id')) {
                 <? if ($subfolder->isReadable($GLOBALS['user']->id)) : ?>
                     <a href="<?= $controller->link_for('file/choose_file/' . $subfolder->id, $options) ?>" data-dialog>
                 <? endif ?>
-                <? if ($is_empty): ?>
+                <? if (!empty($is_empty)): ?>
                     <?= Icon::create('folder-empty')->asImg(24) ?>
                 <? else: ?>
                     <?= Icon::create('folder-full')->asImg(24) ?>
diff --git a/app/views/file/choose_folder_from_course.php b/app/views/file/choose_folder_from_course.php
index 413a920a2e2..fe6bfe08fd4 100644
--- a/app/views/file/choose_folder_from_course.php
+++ b/app/views/file/choose_folder_from_course.php
@@ -49,7 +49,7 @@ jQuery(function ($) {
                         <?= CourseAvatar::getAvatar($course->id)->getImageTag(Avatar::MEDIUM, ['style' => 'width: 20px; height: 20px;']) ?>
                     </button>
                 </td>
-                <td data-sort-value="<?= Semester::find($course->id)->beginn ?>">
+                <td data-sort-value="<?= htmlReady($course->start_semester->beginn) ?>">
                     <!-- neu -->
                     <button formaction="<?= $controller->link_for('file/choose_folder_from_course') ?>"
                             name="course_id"
diff --git a/app/views/file/edit.php b/app/views/file/edit.php
index 803b312e1ec..629980f6784 100644
--- a/app/views/file/edit.php
+++ b/app/views/file/edit.php
@@ -30,7 +30,7 @@
 
             <?= $this->render_partial('file/_terms_of_use_select.php', [
                 'content_terms_of_use_entries' => $content_terms_of_use_entries,
-                'selected_terms_of_use_id'     => $content_terms_of_use->id,
+                'selected_terms_of_use_id'     => $content_terms_of_use->id ?? null,
             ]) ?>
 
             <footer data-dialog-button>
diff --git a/app/views/file/edit_urlfile.php b/app/views/file/edit_urlfile.php
index 761f8ae65b7..619821869e5 100644
--- a/app/views/file/edit_urlfile.php
+++ b/app/views/file/edit_urlfile.php
@@ -3,7 +3,7 @@
 
     <div id="file_management_forms">
         <form method="post" data-dialog class="default"
-            action="<?= $controller->action_link('edit_urlfile/' . $file_ref->id, ['from_plugin' => $from_plugin]) ?>">
+            action="<?= $controller->action_link('edit_urlfile/' . $file_ref->id, ['from_plugin' => $from_plugin ?? null]) ?>">
 
             <?= CSRFProtection::tokenTag() ?>
             <fieldset>
diff --git a/app/views/file/update.php b/app/views/file/update.php
index ba88f9d9ffd..15e79fde630 100644
--- a/app/views/file/update.php
+++ b/app/views/file/update.php
@@ -1,4 +1,4 @@
-<form action="<?= $controller->link_for('file/update/' . $file->getId(), ['from_plugin' => $from_plugin]) ?>"
+<form action="<?= $controller->link_for('file/update/' . $file->getId(), ['from_plugin' => $from_plugin ?? null]) ?>"
       enctype="multipart/form-data" method="post" class="default">
 
     <?= CSRFProtection::tokenTag() ?>
diff --git a/app/views/institute/members/_table_body.php b/app/views/institute/members/_table_body.php
index 5d2a9a32771..39214df465f 100644
--- a/app/views/institute/members/_table_body.php
+++ b/app/views/institute/members/_table_body.php
@@ -1,7 +1,7 @@
 <tbody style="vertical-align: top;">
 <? if ($th_title): ?>
     <tr>
-        <th colspan="<?= 1 + count($structure) - ($structure['actions'] ? 1 : 0) ?>">
+        <th colspan="<?= 1 + count($structure) - (!empty($structure['actions']) ? 1 : 0) ?>">
             <?= htmlReady($th_title) ?>
         </th>
     <? if (!empty($structure['actions'])): ?>
diff --git a/app/views/resources/booking/_add_edit_form.php b/app/views/resources/booking/_add_edit_form.php
index 8b921adf88e..143ebf9c96f 100644
--- a/app/views/resources/booking/_add_edit_form.php
+++ b/app/views/resources/booking/_add_edit_form.php
@@ -184,9 +184,7 @@
                     <label class="separable-room-booking">
                         <input type="checkbox" name="book_other_room_parts"
                                value="1"
-                            <?= $book_other_room_parts
-                                ? 'checked="checked"'
-                                : '' ?>>
+                            <?= !empty($book_other_room_parts) ? 'checked' : '' ?>>
                         <span data-booking_type="<?= ResourceBooking::TYPE_LOCK ?>"
                               <?= $booking_type == ResourceBooking::TYPE_LOCK ? '' : 'style="display:none;"' ?>>
                             <?= _('Alle anderen Teilräume ebenfalls sperren.') ?>
diff --git a/app/views/resources/booking/index.php b/app/views/resources/booking/index.php
index 27820401d39..d3394084b69 100644
--- a/app/views/resources/booking/index.php
+++ b/app/views/resources/booking/index.php
@@ -29,8 +29,8 @@
 
     <h3><?= _('Zeiträume') ?></h3>
     <?
-        $cycle_date = $booking->assigned_course_date->cycle;
-        $booking_has_metadate = ($cycle_date instanceof SeminarCycleDate);
+        $cycle_date = $booking->assigned_course_date->cycle ?? null;
+        $booking_has_metadate = $cycle_date instanceof SeminarCycleDate;
         $intervals = $booking->getTimeIntervals()
     ?>
     <? if (count($intervals) === 1) : ?>
diff --git a/app/views/resources/room_request/resolve_room_tr.php b/app/views/resources/room_request/resolve_room_tr.php
index 0d3cf8c894e..b551129691c 100644
--- a/app/views/resources/room_request/resolve_room_tr.php
+++ b/app/views/resources/room_request/resolve_room_tr.php
@@ -74,8 +74,8 @@
                        class="text-bottom radio-<?= htmlReady($room->id) ?>"
                        value="<?= htmlReady($room->id) ?>"
                     <?= $availability <= 0.0 ? 'disabled="disabled"' : '' ?>
-                <?= ($availability > 0 && $selected_rooms[$range_index] == $room->id)
-                    ? 'checked="checked"'
+                <?= ($availability > 0 && isset($selected_rooms[$range_index]) && $selected_rooms[$range_index] == $room->id)
+                    ? 'checked'
                     : ''?>>
                 <? if ($availability >= 1.0) : ?>
                     <?= Icon::create('check-circle', Icon::ROLE_STATUS_GREEN)->asImg(['class' => 'text-bottom']) ?>
diff --git a/lib/classes/Markup.php b/lib/classes/Markup.php
index dc6820f489f..404bcb9418b 100644
--- a/lib/classes/Markup.php
+++ b/lib/classes/Markup.php
@@ -383,8 +383,7 @@ class Markup
         // avoid <img src="evil_CSRF_stuff">
         $def = $config->getHTMLDefinition(true);
         $img = $def->addBlankElement('img');
-        $img->attr_transform_post[]
-            = new MarkupPrivate\Purifier\AttrTransform_Image_Source();
+        $img->attr_transform_post[] = new MarkupPrivate\Purifier\AttrTransform_Image_Source();
 
         $def->addElement('audio', 'Inline', 'Flow', 'Common', [
               'src*' => 'URI',
@@ -536,6 +535,10 @@ class AttrTransform_Image_Source extends \HTMLPurifier_AttrTransform
      */
     function transform($attr, $config, $context)
     {
+        if (!isset($attr['src'])) {
+            return $attr;
+        }
+
         try {
             $attr['src'] = MediaProxy\getMediaUrl($attr['src']);
         } catch (MediaProxy\InvalidInternalLinkException $e) {
diff --git a/lib/classes/MyRealmModel.php b/lib/classes/MyRealmModel.php
index 19474869c47..8a33ff9c212 100644
--- a/lib/classes/MyRealmModel.php
+++ b/lib/classes/MyRealmModel.php
@@ -315,7 +315,7 @@ class MyRealmModel
             $_course['visitdate']      = $visits[$course->id][0]['visitdate'];
             $_course['user_status']    = $user_status;
             $_course['gruppe']         = !$is_deputy ? $member_ships[$course->id]['gruppe'] ?? null : ($deputy ? $deputy->gruppe : null);
-            $_course['sem_number_end'] = $course->isOpenEnded() ? $max_sem_key : Semester::getIndexById($course->end_semester->id ?? null);
+            $_course['sem_number_end'] = $course->isOpenEnded() ? $max_sem_key : Semester::getIndexById($course->end_semester->id);
             $_course['sem_number']     = Semester::getIndexById($course->start_semester->id);
             $_course['tools']          = $course->tools;
             $_course['name']           = $course->name;
diff --git a/lib/classes/Request.php b/lib/classes/Request.php
index b844cfc9037..f2ff99afa20 100644
--- a/lib/classes/Request.php
+++ b/lib/classes/Request.php
@@ -753,10 +753,9 @@ class Request implements ArrayAccess, IteratorAggregate
             $extract[] = array_values(array_filter(array_map('trim', explode(' ', $one))));
         }
         foreach ($extract as $one) {
-            [$param, $func] = $one;
-            if (!$func) {
-                $func = 'get';
-            }
+            $param = $one[0];
+            $func = $one[1] ?? 'get';
+
             $value = self::$func($param);
             if ($value !== null) {
                 $return[$param] = $value;
diff --git a/lib/classes/Visibility.php b/lib/classes/Visibility.php
index 99b3907e4fd..c164c7694f7 100644
--- a/lib/classes/Visibility.php
+++ b/lib/classes/Visibility.php
@@ -377,7 +377,9 @@ class Visibility
         $stmt = $db->prepare($sql);
         $stmt->execute();
         $lastState = $stmt->fetch(PDO::FETCH_ASSOC);
-        $lastState = $lastState['state'];
+        if (is_array($lastState)) {
+            $lastState = $lastState['state'];
+        }
 
         // now delete the value
         $sql = "DELETE FROM user_visibility_settings $where";
diff --git a/lib/classes/admission/AdmissionPriority.php b/lib/classes/admission/AdmissionPriority.php
index 22d426e54e8..99184d2b58d 100644
--- a/lib/classes/admission/AdmissionPriority.php
+++ b/lib/classes/admission/AdmissionPriority.php
@@ -72,7 +72,7 @@ class AdmissionPriority
      *
      * @param  String $courseSetId
      * @param  String $userId
-     * @return An array containing all priorities.
+     * @return array containing all priorities.
      */
     public static function getPrioritiesByUser($courseSetId, $userId)
     {
@@ -91,6 +91,18 @@ class AdmissionPriority
         return $priorities;
     }
 
+    /**
+     * Returns the mkdate for a priority entry.
+     */
+    public static function getMkdateForCourseAndUser($course_id, $course_set_id, $user_id)
+    {
+        $query = "SELECT p.`mkdate`
+                  FROM `priorities` AS p
+                  JOIN `seminare` AS s ON (p.`seminar_id` = s.`Seminar_id`)
+                  WHERE p.`seminar_id` = ? AND p.`set_id` = ? AND p.`user_id` = ?";
+        return DBManager::get()->fetchColumn($query, [$course_id, $course_set_id, $user_id]);
+    }
+
     /**
      * The given user sets a course in the given course set to priority x.
      *
diff --git a/lib/classes/coursewizardsteps/AdvancedBasicDataWizardStep.php b/lib/classes/coursewizardsteps/AdvancedBasicDataWizardStep.php
index cd33fd35df1..c3432c9ebbb 100644
--- a/lib/classes/coursewizardsteps/AdvancedBasicDataWizardStep.php
+++ b/lib/classes/coursewizardsteps/AdvancedBasicDataWizardStep.php
@@ -31,7 +31,7 @@ class AdvancedBasicDataWizardStep extends BasicDataWizardStep
         $values = $this->adjustValues($values);
 
        // We only need our own stored values here.
-        if ($values[__CLASS__]['studygroup']) {
+        if (!empty($values[__CLASS__]['studygroup'])) {
             return parent::getStepTemplate($values, $stepnumber, $temp_id);
         }
 
@@ -44,7 +44,7 @@ class AdvancedBasicDataWizardStep extends BasicDataWizardStep
             return '';
         }
 
-        $values = $this->makeI18N($values[__CLASS__], ['name', 'description', 'subtitle', 'kind']);
+        $values = $this->makeI18N($values[__CLASS__] ?? [], ['name', 'description', 'subtitle', 'kind']);
 
         $template->set_attribute('values', array_merge($template->values, $values));
 
@@ -83,7 +83,7 @@ class AdvancedBasicDataWizardStep extends BasicDataWizardStep
         }
 
         // Studygroup? -> nothing to do here
-        if ($values[__CLASS__]['studygroup']) {
+        if (!empty($values[__CLASS__]['studygroup'])) {
             return $course;
         }
 
@@ -117,7 +117,7 @@ class AdvancedBasicDataWizardStep extends BasicDataWizardStep
         if (!isset($values[__CLASS__]) && isset($values[$parent_class])) {
             $values[__CLASS__] = $values[$parent_class];
         } else {
-            $values[$parent_class] = $values[__CLASS__];
+            $values[$parent_class] = $values[__CLASS__] ?? [];
         }
 
         return $values;
diff --git a/lib/classes/coursewizardsteps/BasicDataWizardStep.php b/lib/classes/coursewizardsteps/BasicDataWizardStep.php
index bca691502e2..53c8c5026ec 100644
--- a/lib/classes/coursewizardsteps/BasicDataWizardStep.php
+++ b/lib/classes/coursewizardsteps/BasicDataWizardStep.php
@@ -556,9 +556,10 @@ class BasicDataWizardStep implements CourseWizardStep
         return [];
     }
 
-    public function getSearch($course_type, $institute_ids, $exclude_lecturers = [],$exclude_tutors = [])
+    public function getSearch($course_type)
     {
-        if (SeminarCategories::getByTypeId($course_type)->only_inst_user) {
+        $category = SeminarCategories::getByTypeId($course_type);
+        if ($category && $category->only_inst_user) {
             $search = 'user_inst';
         } else {
             $search = 'user';
diff --git a/lib/classes/globalsearch/GlobalSearchCourses.php b/lib/classes/globalsearch/GlobalSearchCourses.php
index c51566d20cf..fef99bd8f66 100644
--- a/lib/classes/globalsearch/GlobalSearchCourses.php
+++ b/lib/classes/globalsearch/GlobalSearchCourses.php
@@ -70,7 +70,10 @@ class GlobalSearchCourses extends GlobalSearchModule implements GlobalSearchFull
         }
 
         // generate SQL for the given sidebar filter (semester, institute, seminar_type)
-        if ($filter['category'] === self::class || $filter['category'] === 'show_all_categories') {
+        if (
+            !empty($filter['category'])
+            && in_array($filter['category'], [self::class, 'show_all_categories'])
+        ) {
             if (!empty($filter['semester'])) {
                 if ($filter['semester'] === 'future') {
                     $semester = Semester::findCurrent();
diff --git a/lib/classes/globalsearch/GlobalSearchForum.php b/lib/classes/globalsearch/GlobalSearchForum.php
index ed167d1b324..915fe23f1a0 100644
--- a/lib/classes/globalsearch/GlobalSearchForum.php
+++ b/lib/classes/globalsearch/GlobalSearchForum.php
@@ -56,7 +56,10 @@ class GlobalSearchForum extends GlobalSearchModule implements GlobalSearchFullte
 
         // generate SQL condition for the semester filter in the sidebar
         $semester_condition = '';
-        if ($filter['category'] == self::class || $filter['category'] == "show_all_categories") {
+        if (
+            !empty($filter['category'])
+            && in_array($filter['category'], [self::class, 'show_all_categories'])
+        ) {
             if (!empty($filter['semester'])) {
                 if ($filter['semester'] === 'future') {
                     $semester = Semester::findCurrent();
diff --git a/lib/classes/librarysearch/LibraryDocument.php b/lib/classes/librarysearch/LibraryDocument.php
index d9eb25b52fc..a2891573792 100644
--- a/lib/classes/librarysearch/LibraryDocument.php
+++ b/lib/classes/librarysearch/LibraryDocument.php
@@ -179,7 +179,7 @@ class LibraryDocument
      */
     public function getIssueDate($year_only = false): string
     {
-        if (!$this->csl_data['issued']) {
+        if (empty($this->csl_data['issued'])) {
             return '';
         }
         if ($year_only) {
diff --git a/lib/filesystem/LibraryFile.php b/lib/filesystem/LibraryFile.php
index c9524e32cae..8de46f8aa77 100644
--- a/lib/filesystem/LibraryFile.php
+++ b/lib/filesystem/LibraryFile.php
@@ -46,9 +46,9 @@ class LibraryFile extends StandardFile
         $file->size = '0';
         $file->mime_type = '';
         $file->metadata = $document->toJson();
-        $file->user_id = $user_id ? $user_id : $GLOBALS['user']->id;
+        $file->user_id = $user_id ?: $GLOBALS['user']->id;
         $file->filetype = get_called_class();
-        if ($document->csl_data['URL'] || $document->opac_link) {
+        if (!empty($document->csl_data['URL']) || $document->opac_link) {
             $file->metadata['url'] = $document->opac_link ?: $document->csl_data['URL'];
             $file->metadata['access_type'] = 'redirect';
         }
@@ -56,10 +56,10 @@ class LibraryFile extends StandardFile
 
         $file_ref = new FileRef();
         $file_ref->file_id = $file->id;
-        $file_ref->folder_id = $folder_id ? $folder_id : '';
+        $file_ref->folder_id = $folder_id ?: '';
         $file_ref->name = $file->name;
         $file_ref->downloads = 0;
-        $file_ref->description = $document->csl_data['description'] ? $document->csl_data['description'] : '';
+        $file_ref->description = trim($document->csl_data['description'] ?? '');
         $file_ref->content_terms_of_use_id = ContentTermsOfUse::findDefault()->id;
         $file_ref->user_id = $file->user_id;
         $file_ref->store();
diff --git a/lib/filesystem/URLFile.php b/lib/filesystem/URLFile.php
index 39de08b0aeb..3a5b15c22da 100644
--- a/lib/filesystem/URLFile.php
+++ b/lib/filesystem/URLFile.php
@@ -22,7 +22,7 @@ class URLFile extends StandardFile
             'access_type' => $data['access_type'] ?? "redirect"
         ];
         $file['user_id'] = $user_id;
-        $file['author_name'] = $data['author_name'] ?? get_fullname($file['user_id']);
+        $file['author_name'] = trim($data['author_name'] ?? '') ?: get_fullname($file['user_id']);
         $file['filetype'] = get_called_class();
         $file->store();
 
@@ -30,7 +30,7 @@ class URLFile extends StandardFile
         $fileref['file_id'] = $file->getId();
         $fileref['name'] = $file['name'];
         $fileref['downloads'] = 0;
-        $fileref['description'] = $data['description'] ?? '';
+        $fileref['description'] = trim($data['description'] ?? '');
         $fileref['content_terms_of_use_id'] = $data['content_terms_of_use_id'] ?? ContentTermsOfUse::findDefault()->id;
         $fileref['user_id'] = $user_id;
 
diff --git a/lib/models/AdmissionApplication.php b/lib/models/AdmissionApplication.php
index 538c9fd0d41..a7958da9260 100644
--- a/lib/models/AdmissionApplication.php
+++ b/lib/models/AdmissionApplication.php
@@ -127,6 +127,7 @@ class AdmissionApplication extends SimpleORMap implements PrivacyObject
                 $data['position'] = $cs->hasAdmissionRule('LimitedAdmission') ? $p : '-';
                 $data['visible'] = 'unknown';
                 $data['status'] = 'claiming';
+                $data['mkdate'] = AdmissionPriority::getMkdateForCourseAndUser($course_id, $cs->getId(), $user_id);
                 $claiming[] = $data;
             }
         }
diff --git a/lib/models/OERHostOERSI.php b/lib/models/OERHostOERSI.php
index 5e539bf0479..f2b07b8ae2e 100644
--- a/lib/models/OERHostOERSI.php
+++ b/lib/models/OERHostOERSI.php
@@ -71,7 +71,7 @@ class OERHostOERSI extends OERHost
                     $material['draft'] = '0';
                     $material['filename'] = '';
                     $material['short_description'] = '';
-                    $material['description'] = $material_data['_source']['description'] ?: '';
+                    $material['description'] = trim($material_data['_source']['description'] ?? '');
                     $material['difficulty_start'] = 0;
                     $material['difficulty_end'] = 12;
                     $material['uri'] = $material_data['_source']['id'];
diff --git a/lib/models/SemesterHoliday.php b/lib/models/SemesterHoliday.php
index 265f8e1b23b..ab058e11eb7 100644
--- a/lib/models/SemesterHoliday.php
+++ b/lib/models/SemesterHoliday.php
@@ -136,7 +136,6 @@ class SemesterHoliday extends SimpleORMap
         // Check all other holidays
         if (!$check_vacation_only) {
             return holiday($time);
-            $holiday_entry = holiday($time);
         }
 
         // Nothing found
diff --git a/lib/models/SeminarCycleDate.php b/lib/models/SeminarCycleDate.php
index 13b2520883c..69396324657 100644
--- a/lib/models/SeminarCycleDate.php
+++ b/lib/models/SeminarCycleDate.php
@@ -571,7 +571,7 @@ class SeminarCycleDate extends SimpleORMap
                 //check for calculatable holidays
                 if ($date instanceof CourseDate || $date instanceof CourseExDate) {
                     $holy_type = SemesterHoliday::isHoliday($date->date, false);
-                    if ($holy_type["col"] == 3) {
+                    if ($holy_type && $holy_type['col'] == 3) {
                         $holiday_date = true;
                     }
                 }
diff --git a/lib/models/resources/ResourceRequest.php b/lib/models/resources/ResourceRequest.php
index b5da46a6b7b..8d3bcbaaf0e 100644
--- a/lib/models/resources/ResourceRequest.php
+++ b/lib/models/resources/ResourceRequest.php
@@ -1059,10 +1059,10 @@ class ResourceRequest extends SimpleORMap implements PrivacyObject, Studip\Calen
                                     'end'   => $date->end_time
                                 ];
                             }
-                            $interval['range']                         = 'CourseDate';
-                            $interval['range_id']                      = $date->id;
-                            $interval['booked_room']                   = $date->room_booking->resource_id;
-                            $interval['booking_id']                    = $date->room_booking->id;
+                            $interval['range'] = CourseDate::class;
+                            $interval['range_id'] = $date->id;
+                            $interval['booked_room'] = $date->room_booking->resource_id ?? null;
+                            $interval['booking_id'] = $date->room_booking->id ?? null;
                             $time_intervals[$cycle->id]['intervals'][] = $interval;
                         }
                     }
diff --git a/lib/visual.inc.php b/lib/visual.inc.php
index 08026064a73..a93bdd8cd02 100644
--- a/lib/visual.inc.php
+++ b/lib/visual.inc.php
@@ -623,6 +623,11 @@ function tooltipHtmlIcon($text, $important = false)
 */
 function TransformInternalLinks($str){
     $str = trim($str);
+
+    if (!$str) {
+        return '';
+    }
+    
     if (mb_strpos($str, 'http') !== 0) {
         if ($str[0] === '#' || preg_match('/^[a-z][a-z0-9+.-]*:/i', $str)) {
             return $str;
diff --git a/templates/dates/seminar_html_roomplanning.php b/templates/dates/seminar_html_roomplanning.php
index 50f3fdf88ae..b758f403a13 100644
--- a/templates/dates/seminar_html_roomplanning.php
+++ b/templates/dates/seminar_html_roomplanning.php
@@ -47,7 +47,7 @@ if (!empty($dates['regular']['turnus_data']) || !empty($dates['irregular'])) :
   $irregular_rooms = [];
   $irregular = [];
 
-  if (is_array($dates['irregular'])):
+  if (isset($dates['irregular']) && is_array($dates['irregular'])):
     foreach ($dates['irregular'] as $date) :
         if (empty($with_past_intervals) && $date->end_time < $now) {
             continue;
diff --git a/templates/userfilter/display.php b/templates/userfilter/display.php
index 859afbe283b..57fdfe64c27 100644
--- a/templates/userfilter/display.php
+++ b/templates/userfilter/display.php
@@ -8,7 +8,7 @@ foreach ($filter->getFields() as $field) {
     $valueNames = $field->getValidValues();
     $ops = $field->getValidCompareOperators();
     $fieldText .= htmlReady($field->getName()." ".$field->getCompareOperatorAsText().
-        " " . (count($valueNames) ? $valueNames[$field->getValue()] : $field->getValue()));
+        " " . ($valueNames[$field->getValue()] ?? $field->getValue()));
     $i++;
 
 }
@@ -21,4 +21,3 @@ if ($filter->show_user_count) {
     $fieldText .= ')';
 }
 echo $fieldText;
-?>
-- 
GitLab