From 74cde461f8dd1b0b83ea9e031822603e9c280b56 Mon Sep 17 00:00:00 2001
From: Moritz Strohm <strohm@data-quest.de>
Date: Fri, 27 May 2022 09:59:12 +0000
Subject: [PATCH] fix for BIESt #971

Closes #971

Merge request studip/studip!578
---
 app/controllers/admin/courses.php       | 20 ++++++++++----------
 app/controllers/my_courses.php          | 12 ++++++------
 app/controllers/plugin_controller.php   |  1 -
 app/controllers/studip_controller.php   |  2 +-
 app/views/admin/courses/_course.php     |  8 +++++---
 app/views/admin/courses/courses.php     | 20 +++++++++++++++-----
 app/views/my_courses/_dozent.php        |  2 +-
 app/views/my_studygroups/_course.php    |  2 +-
 lib/classes/AdminCourseFilter.class.php |  2 +-
 lib/classes/MyRealmModel.php            |  8 ++++----
 lib/classes/Request.class.php           |  2 +-
 lib/classes/SemClass.class.php          |  4 ++--
 lib/classes/Seminar.class.php           |  4 ++--
 lib/classes/SeminarCategories.class.php |  9 +++++----
 lib/classes/SkipLinks.php               |  8 +++++++-
 lib/classes/WidgetContainer.php         |  2 +-
 lib/classes/sidebar/SearchWidget.php    |  2 ++
 lib/classes/sidebar/SelectWidget.php    |  3 +++
 lib/dates.inc.php                       | 15 ++++++++-------
 lib/functions.php                       |  2 +-
 lib/models/Semester.class.php           |  2 +-
 lib/models/SimpleORMap.class.php        | 13 ++++++++-----
 lib/models/resources/Room.class.php     |  2 +-
 lib/navigation/BrowseNavigation.php     |  3 +++
 lib/raumzeit/SingleDate.class.php       |  4 ++--
 public/sendfile.php                     |  3 ++-
 templates/dates/_seminar_rooms.php      |  1 +
 templates/dates/seminar_export.php      |  3 +++
 templates/dates/seminar_html.php        |  6 +++++-
 templates/sidebar/select-widget.php     |  2 +-
 30 files changed, 103 insertions(+), 64 deletions(-)

diff --git a/app/controllers/admin/courses.php b/app/controllers/admin/courses.php
index b0bf9cd8cd4..7835fe5f46b 100644
--- a/app/controllers/admin/courses.php
+++ b/app/controllers/admin/courses.php
@@ -43,7 +43,7 @@ class Admin_CoursesController extends AuthenticatedController
     {
         //first get the active datafields of the user:
         $userSelectedElements = $this->getActiveElements();
-        $activeDatafields = $userSelectedElements['datafields'];
+        $activeDatafields = $userSelectedElements['datafields'] ?? [];
 
         if (!$activeDatafields) {
             return [];
@@ -189,7 +189,7 @@ class Admin_CoursesController extends AuthenticatedController
         }
 
         //if there are datafields in the list, draw their input fields, too:
-        if ($visibleElements['datafields']) {
+        if (!empty($visibleElements['datafields'])) {
             //The datafields entry contains an array with datafield-IDs.
             //We must fetch them from the database and show an appropriate widget
             //for each datafield.
@@ -1190,7 +1190,7 @@ class Admin_CoursesController extends AuthenticatedController
         $filter->where("sem_classes.studygroup_mode = '0'");
 
         // Get only children of given course
-        if ($params['parent_course']) {
+        if (!empty($params['parent_course'])) {
             $filter->where("parent_course = :parent",
                 [
                     'parent' => $params['parent_course']
@@ -1235,10 +1235,10 @@ class Admin_CoursesController extends AuthenticatedController
             return [];
         }
 
-        $seminars   = array_map('reset', $courses);
-
-        if (!empty($seminars)) {
-            foreach ($seminars as $seminar_id => $seminar) {
+        $seminars = [];
+        if (!empty($courses)) {
+            foreach ($courses as $seminar_id => $seminar) {
+                $seminars[$seminar_id] = $seminar[0];
                 $seminars[$seminar_id]['seminar_id'] = $seminar_id;
                 $seminars[$seminar_id]['obj_type'] = 'sem';
                 $dozenten = $this->getTeacher($seminar_id);
@@ -1253,7 +1253,7 @@ class Admin_CoursesController extends AuthenticatedController
                     $seminars[$seminar_id]['navigation'] = MyRealmModel::getAdditionalNavigations(
                         $seminar_id,
                         $seminars[$seminar_id],
-                        $seminars[$seminar_id]['sem_class'],
+                        $seminars[$seminar_id]['sem_class'] ?? null,
                         $GLOBALS['user']->id,
                         $visit_data[$seminar_id]
                     );
@@ -1264,8 +1264,8 @@ class Admin_CoursesController extends AuthenticatedController
                 }
                 if ((int)$this->selected_action === 17) {
                     $seminars[$seminar_id]['admission_locked'] = false;
-                    if ($seminar['course_set']) {
-                        $set = new CourseSet($seminar['course_set']);
+                    if ($seminar[0]['course_set']) {
+                        $set = new CourseSet($seminar[0]['course_set']);
                         if (!is_null($set) && $set->hasAdmissionRule('LockedAdmission')) {
                             $seminars[$seminar_id]['admission_locked'] = 'locked';
                         } else {
diff --git a/app/controllers/my_courses.php b/app/controllers/my_courses.php
index 395bef9b02a..45ca5de5f26 100644
--- a/app/controllers/my_courses.php
+++ b/app/controllers/my_courses.php
@@ -122,7 +122,7 @@ class MyCoursesController extends AuthenticatedController
 
                     foreach ($_outer as $course) {
                         $_courses[$course['seminar_id']] = $course;
-                        if ($course['children']) {
+                        if (!empty($course['children']) && is_array($course['children'])) {
                             foreach ($course['children'] as $child) {
                                 $_courses[$child['seminar_id']] = $child;
                             }
@@ -722,12 +722,12 @@ class MyCoursesController extends AuthenticatedController
      */
     public function check_course($seminar_content)
     {
-
-        if ($seminar_content['visitdate'] <= $seminar_content['chdate'] || $seminar_content['last_modified'] > 0) {
+        $last_modified_timestamp = $seminar_content['last_modified'] ?? 0;
+        if ($seminar_content['visitdate'] <= $seminar_content['chdate'] || $last_modified_timestamp > 0) {
             $last_modified = $seminar_content['visitdate'] <= $seminar_content['chdate']
-            && $seminar_content['chdate'] > $seminar_content['last_modified']
+            && $seminar_content['chdate'] > $last_modified_timestamp
                 ? $seminar_content['chdate']
-                : $seminar_content['last_modified'];
+                : $last_modified_timestamp;
             if ($last_modified) {
                 return true;
             }
@@ -994,7 +994,7 @@ class MyCoursesController extends AuthenticatedController
             } else {
                 $attr = $n->getLinkAttributes();
                 if (empty($attr['title']) && $n->getImage()) {
-                    $attr['title'] = (string) $n->getImage()->getAttributes()['title'];
+                    $attr['title'] = (string) ($n->getImage()->getAttributes()['title'] ?? '');
                 }
                 if (empty($attr['title'])) {
                     $attr['title'] = (string) $n->getTitle();
diff --git a/app/controllers/plugin_controller.php b/app/controllers/plugin_controller.php
index 445f22e2b3e..c18874ed493 100644
--- a/app/controllers/plugin_controller.php
+++ b/app/controllers/plugin_controller.php
@@ -19,7 +19,6 @@ class PluginController extends StudipController
         }
         $this->plugin = $dispatcher->current_plugin;
 
-
         if ($this->plugin && $this->plugin->hasTranslation()) {
             // Localization
             $this->_ = function ($string) {
diff --git a/app/controllers/studip_controller.php b/app/controllers/studip_controller.php
index cad182ae55a..cddb82e5035 100644
--- a/app/controllers/studip_controller.php
+++ b/app/controllers/studip_controller.php
@@ -753,7 +753,7 @@ abstract class StudipController extends Trails_Controller
      */
     protected function controller_path()
     {
-        $class = get_class($this->parent_controller ?: $this);
+        $class = get_class($this->parent_controller ?? $this);
         $controller = mb_substr($class, 0, -mb_strlen('Controller'));
         $controller = strtosnakecase($controller);
         return preg_replace('/_{2,}/', '/', $controller);
diff --git a/app/views/admin/courses/_course.php b/app/views/admin/courses/_course.php
index 9632aaa98ff..525e151ed3f 100644
--- a/app/views/admin/courses/_course.php
+++ b/app/views/admin/courses/_course.php
@@ -204,9 +204,11 @@ if (!$values['parent_course'] || !in_array($values['parent_course'], array_keys(
                     <?=
                     \Studip\LinkButton::create(
                         $actions[$selected_action]['title'],
-                        URLHelper::getURL(sprintf($actions[$selected_action]['url'], $semid),
-                            ($actions[$selected_action]['params'] ? $actions[$selected_action]['params'] : [])),
-                        ($actions[$selected_action]['attributes'] ? $actions[$selected_action]['attributes'] : [])
+                        URLHelper::getURL(
+                            sprintf($actions[$selected_action]['url'], $semid),
+                            $actions[$selected_action]['params'] ?? []
+                        ),
+                        $actions[$selected_action]['attributes'] ?? []
                     ) ?>
                 <? endif ?>
             <? endif ?>
diff --git a/app/views/admin/courses/courses.php b/app/views/admin/courses/courses.php
index fab169db660..ee5ce7e09db 100644
--- a/app/views/admin/courses/courses.php
+++ b/app/views/admin/courses/courses.php
@@ -1,5 +1,5 @@
 <? $colspan = 2 ?>
-<? if ($actions[$selected_action]['multimode']) : ?>
+<? if (!empty($actions[$selected_action]['multimode'])) : ?>
     <form action="<?= URLHelper::getLink($actions[$selected_action]['url']) ?>" method="post">
 <? endif ?>
 <?= CSRFProtection::tokenTag() ?>
@@ -197,7 +197,7 @@
             <?= _('Aktion') ?>
         </th>
     </tr>
-    <? if ($actions[$selected_action]['multimode']) : ?>
+    <? if (!empty($actions[$selected_action]['multimode'])) : ?>
         <?= $this->render_partial('admin/courses/additional_inputs.php', compact('colspan')) ?>
         <? if (count($courses) > 10): ?>
             <tr>
@@ -219,10 +219,20 @@
     </thead>
     <tbody>
     <? foreach ($courses as $semid => $values) : ?>
-        <?= $this->render_partial('admin/courses/_course', compact('semid', 'values', 'view_filter', 'actions', 'selected_action', 'courses')) ?>
+        <?= $this->render_partial('admin/courses/_course',
+            [
+                'semid' => $semid,
+                'values' => $values,
+                'view_filter' => $view_filter,
+                'actions' => $actions,
+                'selected_action' => $selected_action,
+                'courses' => $courses,
+                'parent' => $parent ?? null
+            ]
+        ) ?>
     <? endforeach ?>
     </tbody>
-<? if ($actions[$selected_action]['multimode']) : ?>
+<? if (!empty($actions[$selected_action]['multimode'])) : ?>
     <tfoot>
         <tr>
             <td colspan="<?= $colspan ?>" style="text-align: right">
@@ -241,6 +251,6 @@
     </tfoot>
     <? endif ?>
 </table>
-<? if ($actions[$selected_action]['multimode']) : ?>
+<? if (!empty($actions[$selected_action]['multimode'])) : ?>
 </form>
 <? endif ?>
diff --git a/app/views/my_courses/_dozent.php b/app/views/my_courses/_dozent.php
index cb7bf9014d1..05b5f524ef4 100644
--- a/app/views/my_courses/_dozent.php
+++ b/app/views/my_courses/_dozent.php
@@ -1,4 +1,4 @@
 <?
 # Lifter010: TODO
 ?>
-<?= $colon ? ', ' : '' ?><a href="<?= URLHelper::getLink('dispatch.php/profile', ['username' => $_dozent['username']]) ?>"><?= htmlReady($_dozent["fullname"]) ?></a><? $this->colon = true; ?>
+<?= !empty($colon) ? ', ' : '' ?><a href="<?= URLHelper::getLink('dispatch.php/profile', ['username' => $_dozent['username']]) ?>"><?= htmlReady($_dozent['fullname']) ?></a><? $this->colon = true; ?>
diff --git a/app/views/my_studygroups/_course.php b/app/views/my_studygroups/_course.php
index 12442475ce6..e3855c4c33b 100644
--- a/app/views/my_studygroups/_course.php
+++ b/app/views/my_studygroups/_course.php
@@ -7,7 +7,7 @@
         </td>
         <td style="text-align: left">
             <a href="<?= URLHelper::getLink('seminar_main.php', ['auswahl' => $group['seminar_id']]) ?>"
-                <?= $group['lastvisitdate'] >= $group['chdate'] ? 'style="color: red;"' : '' ?>>
+                <?= $group['last_visitdate'] >= $group['chdate'] ? 'style="color: red;"' : '' ?>>
                 <?= htmlReady($group['name']) ?>
             </a>
             <? if ($group['visible'] == 0) : ?>
diff --git a/lib/classes/AdminCourseFilter.class.php b/lib/classes/AdminCourseFilter.class.php
index cd9bfacfe27..ee4982c6392 100644
--- a/lib/classes/AdminCourseFilter.class.php
+++ b/lib/classes/AdminCourseFilter.class.php
@@ -344,7 +344,7 @@ class AdminCourseFilter
             $id = md5($where);
         }
         $this->settings['query']['where'][$id] = $where;
-        $this->settings['parameter'] = array_merge((array) $this->settings['parameter'], $parameter);
+        $this->settings['parameter'] = array_merge((array)($this->settings['parameter'] ?? []), $parameter);
         return $this;
     }
 
diff --git a/lib/classes/MyRealmModel.php b/lib/classes/MyRealmModel.php
index a68a0c1ac5f..9f62b427cb2 100644
--- a/lib/classes/MyRealmModel.php
+++ b/lib/classes/MyRealmModel.php
@@ -171,7 +171,7 @@ class MyRealmModel
 
         $semester_ids      = [];
         for ($i = $min_sem_key; $i <= $max_sem_key; $i++) {
-            if ($sem_data[$i]['semester_id']) {
+            if (!empty($sem_data[$i]['semester_id'])) {
                 $semester_ids[] = $sem_data[$i]['semester_id'];
             }
         }
@@ -364,7 +364,7 @@ class MyRealmModel
 
             // add the the course to the correct semester
 
-            if (!$_course['parent_course']) {
+            if (empty($_course['parent_course'])) {
                 if ($course->isOpenEnded()) {
                     if ($current_semester_nr >= $min_sem_key && $current_semester_nr <= $max_sem_key) {
                         $sem_courses[$current_semester_nr][$course->id] = $_course;
@@ -395,7 +395,7 @@ class MyRealmModel
             return null;
         }
 
-        if ($params['main_navigation']) {
+        if (!empty($params['main_navigation'])) {
             return $sem_courses;
         }
 
@@ -805,7 +805,7 @@ class MyRealmModel
             $data['tools'] = $studygroup->tools;
             $data['sem_class'] = $studygroup->getSemClass();
             $data['start_semester'] = $studygroup->start_semester->name;
-            $data['end_semester'] = $studygroup->end_semester->name;
+            $data['end_semester'] = $studygroup->end_semester->name ?? '';
             $data['obj_type'] = 'sem';
             $data['user_status'] = $membership->status;
             $data['gruppe'] = $membership->gruppe;
diff --git a/lib/classes/Request.class.php b/lib/classes/Request.class.php
index 71c593e58b7..22cf29d142d 100644
--- a/lib/classes/Request.class.php
+++ b/lib/classes/Request.class.php
@@ -632,7 +632,7 @@ class Request implements ArrayAccess, IteratorAggregate
      */
     public static function method()
     {
-        return mb_strtoupper($_SERVER['X_HTTP_METHOD_OVERRIDE'] ?: $_SERVER['REQUEST_METHOD']);
+        return mb_strtoupper($_SERVER['X_HTTP_METHOD_OVERRIDE'] ?? $_SERVER['REQUEST_METHOD']);
     }
 
     /**
diff --git a/lib/classes/SemClass.class.php b/lib/classes/SemClass.class.php
index 8f122a3d894..027d29c1939 100644
--- a/lib/classes/SemClass.class.php
+++ b/lib/classes/SemClass.class.php
@@ -93,7 +93,7 @@ class SemClass implements ArrayAccess
 
         foreach ($slots as $slot => $module) {
             $data[$slot] = $module;
-            $modules[$module] = ['activated' => (int) $INST_MODULES[$type][$slot], 'sticky' => 0];
+            $modules[$module] = ['activated' => (int) ($INST_MODULES[$type][$slot] ?? 0), 'sticky' => 0];
         }
         $data['modules'] = json_encode($modules);
 
@@ -200,7 +200,7 @@ class SemClass implements ArrayAccess
      */
     public function isModuleForbidden($modulename)
     {
-        if ($this->data['studygroup_mode']) {
+        if (!empty($this->data['studygroup_mode'])) {
             return in_array($modulename, self::$studygroup_forbidden_modules);
         } else {
             return strpos($modulename, 'Studygroup') !== false;
diff --git a/lib/classes/Seminar.class.php b/lib/classes/Seminar.class.php
index 337eea6fe65..00108aa35a2 100644
--- a/lib/classes/Seminar.class.php
+++ b/lib/classes/Seminar.class.php
@@ -72,7 +72,7 @@ class Seminar
             if ($refresh_cache) {
                 self::$seminar_object_pool[$id] = null;
             }
-            if (is_object(self::$seminar_object_pool[$id]) && self::$seminar_object_pool[$id]->getId() == $id) {
+            if (!empty(self::$seminar_object_pool[$id]) && is_object(self::$seminar_object_pool[$id]) && self::$seminar_object_pool[$id]->getId() == $id) {
                 return self::$seminar_object_pool[$id];
             } else {
                 self::$seminar_object_pool[$id] = new Seminar($id);
@@ -316,7 +316,7 @@ class Seminar
         $data = unserialize($cache->read($cache_key));
 
         // build cache from scratch
-        if (!$data || !$data[$sub_key]) {
+        if (empty($data) || empty($data[$sub_key])) {
             $cycles = $this->metadate->getCycleData();
             $dates = $this->getSingleDates($filter, $filter);
             $rooms = [];
diff --git a/lib/classes/SeminarCategories.class.php b/lib/classes/SeminarCategories.class.php
index fdb955e825a..5302f1e3dcf 100644
--- a/lib/classes/SeminarCategories.class.php
+++ b/lib/classes/SeminarCategories.class.php
@@ -45,10 +45,11 @@ class SeminarCategories {
      * @param String $id
      * @return Array
      */
-    public static function Get($id){
-        if(is_null(self::$seminar_categories[$id])){
+    public static function Get($id)
+    {
+        if (empty(self::$seminar_categories[$id])) {
             $cat = new SeminarCategories($id);
-            if($cat->id !== false) {
+            if ($cat->id !== false) {
                 self::$seminar_categories[$id] = $cat;
             } else {
                 self::$seminar_categories[$id] = false;
@@ -134,4 +135,4 @@ class SeminarCategories {
         }
     }
 }
-?>
\ No newline at end of file
+?>
diff --git a/lib/classes/SkipLinks.php b/lib/classes/SkipLinks.php
index c5738b2af6f..684ae424189 100644
--- a/lib/classes/SkipLinks.php
+++ b/lib/classes/SkipLinks.php
@@ -32,7 +32,13 @@ class SkipLinks
      */
     public static function isEnabled()
     {
-        return UserConfig::get($GLOBALS['user']->id)->SKIPLINKS_ENABLE;
+        if (isset($GLOBALS['user']->id)) {
+            //Use the user configuration:
+            return UserConfig::get($GLOBALS['user']->id)->SKIPLINKS_ENABLE;
+        } else {
+            //Use the global configuration:
+            return Config::get()->SKIPLINKS_ENABLE;
+        }
     }
 
     /**
diff --git a/lib/classes/WidgetContainer.php b/lib/classes/WidgetContainer.php
index 1b0578eb323..39665a9a6cb 100644
--- a/lib/classes/WidgetContainer.php
+++ b/lib/classes/WidgetContainer.php
@@ -24,7 +24,7 @@ abstract class WidgetContainer
     public static function Get()
     {
         $class = get_called_class();
-        if (!isset(static::$instances[$class])) {
+        if (empty(static::$instances[$class])) {
             static::$instances[$class] = new static;
         }
         return static::$instances[$class];
diff --git a/lib/classes/sidebar/SearchWidget.php b/lib/classes/sidebar/SearchWidget.php
index 2b7979e43d8..626078ef918 100644
--- a/lib/classes/sidebar/SearchWidget.php
+++ b/lib/classes/sidebar/SearchWidget.php
@@ -138,6 +138,8 @@ class SearchWidget extends SidebarWidget
             }
         }
 
+        $this->template_variables['reset_search'] = '';
+
         if ($this->hasData()) {
             // Remove needles from query params for reset link
             $reset_params = $query_params;
diff --git a/lib/classes/sidebar/SelectWidget.php b/lib/classes/sidebar/SelectWidget.php
index 789355955dc..ce311f698d9 100644
--- a/lib/classes/sidebar/SelectWidget.php
+++ b/lib/classes/sidebar/SelectWidget.php
@@ -126,6 +126,9 @@ class SelectWidget extends SidebarWidget
 
         //submit-upon-select is not helpful if we have the multiple version
         if (!$this->template_variables['multiple']) {
+            if (!array_key_exists('class', $this->template_variables)) {
+                $this->template_variables['class'] = '';
+            }
             $this->template_variables['class'] .= ' submit-upon-select';
         }
 
diff --git a/lib/dates.inc.php b/lib/dates.inc.php
index 151cf70ad68..e9f08415ab5 100644
--- a/lib/dates.inc.php
+++ b/lib/dates.inc.php
@@ -207,7 +207,7 @@ function shrink_dates($dates) {
 
         if (((date ("z", $dates[$i]["start_time"])-1) == date ("z", $dates[$i-1]["start_time"]))
                 || ((date ("z", $dates[$i]["start_time"]) == 0) && (date ("j", $dates[$i-1]["start_time"]) == 0))) {
-            if ($dates[$i]["time_match"]) {
+            if (!empty($dates[$i]["time_match"])) {
                 $dates[$i]["conjuncted"] = true;
             }
         }
@@ -217,23 +217,24 @@ function shrink_dates($dates) {
     $return_string = '';
     // create text-output
     for ($i=0; $i < sizeof($dates); $i++) {
-        if (!$dates[$i]["conjuncted"]) {
+        $conjuncted = true;
+        if (empty($dates[$i]["conjuncted"])) {
             $conjuncted = false;
         }
 
-        if ((!$dates[$i]["conjuncted"]) || (!$dates[$i+1]["conjuncted"])) {
+        if (empty($dates[$i]["conjuncted"]) || empty($dates[$i+1]["conjuncted"])) {
             $return_string .= ' ' . strftime('%A', $dates[$i]['start_time']) .'.';
             $return_string .= date (" d.m.y", $dates[$i]["start_time"]);
         }
 
-        if ((!$conjuncted) && ($dates[$i+1]["conjuncted"])) {
+        if (!$conjuncted && !empty($dates[$i+1]["conjuncted"])) {
             $return_string .= ' -';
             $conjuncted = true;
-        } else if ((!$dates[$i+1]["conjuncted"]) && ($dates[$i+1]["time_match"])) {
+        } else if (empty($dates[$i+1]["conjuncted"]) && !empty($dates[$i+1]["time_match"])) {
             $return_string .= ',';
         }
 
-        if (!$dates[$i+1]["time_match"]) {
+        if (empty($dates[$i+1]["time_match"])) {
             // check if the current date is for a whole day
             if ((($dates[$i]["end_time"] - $dates[$i]["start_time"]) / 60 / 60) > 23) {
                 $return_string .= ' ('. _('ganztägig') . ')';
@@ -245,7 +246,7 @@ function shrink_dates($dates) {
             }
         }
 
-        if ($return_string != '' && !$dates[$i+1]['conjuncted'] && !$dates[$i+1]['time_match']) {
+        if ($return_string != '' && empty($dates[$i+1]['conjuncted']) && empty($dates[$i+1]['time_match'])) {
             $ret[] = $return_string;
             $return_string = '';
         }
diff --git a/lib/functions.php b/lib/functions.php
index a74c8eca46d..812b531e5d7 100644
--- a/lib/functions.php
+++ b/lib/functions.php
@@ -1520,7 +1520,7 @@ function studip_default_exception_handler($exception) {
 
     // ajax requests return JSON instead
     // re-use the http status code determined above
-    if (!strcasecmp($_SERVER['HTTP_X_REQUESTED_WITH'], 'xmlhttprequest')) {
+    if (!strcasecmp($_SERVER['HTTP_X_REQUESTED_WITH'] ?? '', 'xmlhttprequest')) {
         header('Content-Type: application/json; charset=UTF-8');
         $template = 'json_exception';
         $layout = null;
diff --git a/lib/models/Semester.class.php b/lib/models/Semester.class.php
index 33b309895d0..10f21ae4352 100644
--- a/lib/models/Semester.class.php
+++ b/lib/models/Semester.class.php
@@ -85,7 +85,7 @@ class Semester extends SimpleORMap
     public static function find($id)
     {
         $semester_cache = self::getAll();
-        return $semester_cache[$id] ?: null;
+        return $semester_cache[$id] ?? null;
     }
 
     /**
diff --git a/lib/models/SimpleORMap.class.php b/lib/models/SimpleORMap.class.php
index 3a28ebd94bb..92cdf423af7 100644
--- a/lib/models/SimpleORMap.class.php
+++ b/lib/models/SimpleORMap.class.php
@@ -218,7 +218,8 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
         if (isset($config['additional_fields'])) {
             foreach ($config['additional_fields'] as $a_field => $a_config) {
                 if (is_array($a_config) && !(isset($a_config['get']) || isset($a_config['set']))) {
-                    list($relation, $relation_field) = $a_config;
+                    $relation = $a_config[0] ?? '';
+                    $relation_field = $a_config[1] ?? '';
                     if (!$relation) {
                         list($relation, $relation_field) = explode('_', $a_field);
                     }
@@ -620,7 +621,7 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
         $record = new $class();
         $sql = "SELECT `$db_table`.* FROM `$thru_table`
         INNER JOIN `$db_table` ON `$thru_table`.`$thru_assoc_key` = `$db_table`.`$assoc_foreign_key`
-        WHERE `$thru_table`.`$thru_key` = ? " . $options['order_by'];
+        WHERE `$thru_table`.`$thru_key` = ? " . ($options['order_by'] ?? '');
         $db = DBManager::get();
         $st = $db->prepare($sql);
         $st->execute([$foreign_key_value]);
@@ -1024,7 +1025,8 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
      * @throws Exception if options for thru_table could not be determined
      * @return array
      */
-    protected function parseRelationOptions($type, $name, $options) {
+    protected function parseRelationOptions($type, $name, $options)
+    {
         if (empty($options['class_name'])) {
             throw new Exception('Option class_name not set for relation ' . $name);
         }
@@ -1040,14 +1042,14 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
             if (!$options['thru_key']) {
                 $options['thru_key'] = $this->pk[0];
             }
-            if (!$options['thru_assoc_key'] || !$options['assoc_foreign_key']) {
+            if (empty($options['thru_assoc_key']) || empty($options['assoc_foreign_key'])) {
                 $class = $options['class_name'];
                 $record = new $class();
                 $meta = $record->getTableMetadata();
                 if (!$options['thru_assoc_key'] ) {
                     $options['thru_assoc_key'] = $meta['pk'][0];
                 }
-                if (!$options['assoc_foreign_key']) {
+                if (empty($options['assoc_foreign_key'])) {
                     $options['assoc_foreign_key']= $meta['pk'][0];
                 }
             }
@@ -2207,6 +2209,7 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
     protected function registerCallback($types, $cb)
     {
         $types = is_array($types) ? $types : words($types);
+        $reg = 0;
         foreach ($types as $type) {
             if (isset($this->registered_callbacks[$type])) {
                 $this->registered_callbacks[$type][] = $cb;
diff --git a/lib/models/resources/Room.class.php b/lib/models/resources/Room.class.php
index f0a54b0628c..d8f2ad4685f 100644
--- a/lib/models/resources/Room.class.php
+++ b/lib/models/resources/Room.class.php
@@ -40,7 +40,7 @@ class Room extends Resource
 
     protected static function configure($config = [])
     {
-        if (!is_array($config['additional_fields'])) {
+        if (!isset($config['additional_fields'])) {
             $config['additional_fields'] = [];
         }
         foreach (self::$required_properties as $property) {
diff --git a/lib/navigation/BrowseNavigation.php b/lib/navigation/BrowseNavigation.php
index 566e9d6a75b..82b3ac6c282 100644
--- a/lib/navigation/BrowseNavigation.php
+++ b/lib/navigation/BrowseNavigation.php
@@ -26,6 +26,9 @@ class BrowseNavigation extends Navigation
 
         $courselink = null;
         // check if logged in
+        $coursetext = '';
+        $courseinfo = '';
+        $courselink = null;
         if (is_object($user) && $user->id != 'nobody') {
             $coursetext = _('Veranstaltungen');
             $courseinfo = _('Meine Veranstaltungen & Einrichtungen');
diff --git a/lib/raumzeit/SingleDate.class.php b/lib/raumzeit/SingleDate.class.php
index 8159b137e8a..c713cc4582a 100644
--- a/lib/raumzeit/SingleDate.class.php
+++ b/lib/raumzeit/SingleDate.class.php
@@ -391,8 +391,8 @@ class SingleDate
         $this->end_time = $daten['end_time'];
         $this->mkdate = $daten['mkdate'];
         $this->chdate = $daten ['chdate'];
-        $this->ex_termin = $daten['ex_termin'];
-        $this->orig_ex = $daten['ex_termin'];
+        $this->ex_termin = $daten['ex_termin'] ?? false;
+        $this->orig_ex = $daten['ex_termin'] ?? false;
         $this->range_id = $daten['range_id'];
         $this->author_id = $daten['autor_id'];
         $this->resource_id = $daten['resource_id'];
diff --git a/public/sendfile.php b/public/sendfile.php
index 053d46b8d6f..5485ca297e6 100644
--- a/public/sendfile.php
+++ b/public/sendfile.php
@@ -150,6 +150,7 @@ switch ($type) {
 
 
 // check if linked file is obtainable
+$filesize = 0;
 if (isset($file_ref) && $file_ref->file->metadata['access_type'] == 'proxy') {
     $link_data = FileManager::fetchURLMetadata($file_ref->file->metadata['url']);
     if ($link_data['response_code'] != 200) {
@@ -244,7 +245,7 @@ if ($filesize && $file_ref->file->filetype !== 'URLFile') {
 
 header("Expires: Mon, 12 Dec 2001 08:00:00 GMT");
 header("Last-Modified: " . gmdate ("D, d M Y H:i:s") . " GMT");
-if ($_SERVER['HTTPS'] == "on"){
+if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') {
     header("Pragma: public");
     header("Cache-Control: private");
 } else {
diff --git a/templates/dates/_seminar_rooms.php b/templates/dates/_seminar_rooms.php
index 58d940aabcc..c10fa453e44 100644
--- a/templates/dates/_seminar_rooms.php
+++ b/templates/dates/_seminar_rooms.php
@@ -8,6 +8,7 @@ $hide_empty = $hide_empty ?? false;
 $limit      = $limit ?? 3;
 $assigned   = $assigned ?: [];
 $freetext   = $freetext ?: [];
+$plain      = $plain ?? false;
 
 if ($assigned || $freetext) {
     if ($assigned) {
diff --git a/templates/dates/seminar_export.php b/templates/dates/seminar_export.php
index 944e02cc2cd..ae6fd1b1cf9 100644
--- a/templates/dates/seminar_export.php
+++ b/templates/dates/seminar_export.php
@@ -40,6 +40,9 @@ if (!empty($dates['regular']['turnus_data']) || !empty($dates['irregular'])) :
 
   if (is_array($dates['irregular'])):
     foreach ($dates['irregular'] as $date) :
+        if (!isset($irregular_rooms[$date['resource_id']])) {
+            $irregular_rooms[$date['resource_id']] = 0;
+        }
         $irregular[] = $date;
         $irregular_strings[] = $date['tostring'];
         if ($date['resource_id']) :
diff --git a/templates/dates/seminar_html.php b/templates/dates/seminar_html.php
index c59b5cea692..2680287d445 100644
--- a/templates/dates/seminar_html.php
+++ b/templates/dates/seminar_html.php
@@ -43,9 +43,13 @@ if (!$dates['regular']['turnus_data'] && empty($dates['irregular'])) {
     echo $output ? '<br>' : '';
 
     $freetext_rooms = [];
+    $irregular_rooms = [];
 
     if (is_array($dates['irregular'])) {
         foreach ($dates['irregular'] as $date) {
+            if (!isset($irregular_rooms[$date['resource_id']])) {
+                $irregular_rooms[$date['resource_id']] = 0;
+            }
             $irregular[] = $date;
             $irregular_strings[] = $date['tostring'];
             if ($date['resource_id']) {
@@ -100,7 +104,7 @@ if (!$dates['regular']['turnus_data'] && empty($dates['irregular'])) {
         }
     }
 
-    if ($link_to_dates) {
+    if (!empty($link_to_dates)) {
         echo '<br>';
         printf(
             _('Details zu allen Terminen im %sAblaufplan%s'),
diff --git a/templates/sidebar/select-widget.php b/templates/sidebar/select-widget.php
index e0866aa824c..73d23156030 100644
--- a/templates/sidebar/select-widget.php
+++ b/templates/sidebar/select-widget.php
@@ -1,7 +1,7 @@
 <form action="<?= URLHelper::getLink($url) ?>" method="<?= $method ?>">
     <?= \SelectWidget::arrayToHiddenInput($params) ?>
     <?= (strtolower($method) == 'post') ?  CSRFProtection::tokenTag() : ''; ?>
-    <select class="sidebar-selectlist <?= $class ?> <? if ($__is_nested): ?>nested-select<? endif; ?>" <? if ($size) printf('size="%u"', $size); ?> <?= $attributes ? arrayToHtmlAttributes($attributes) : '' ?>
+    <select class="sidebar-selectlist <?= $class ?> <? if ($__is_nested): ?>nested-select<? endif; ?>" <? !empty($size) ? printf('size="%u"', $size) : '' ?> <?= !empty($attributes) ? arrayToHtmlAttributes($attributes) : '' ?>
         name="<?= sprintf('%s%s', htmlReady($name), $multiple ? '[]' : '') ?>" <? if ($multiple) echo 'multiple'; ?>>
 
     <? foreach ($elements as $element): ?>
-- 
GitLab