From 850fe60f3fdbe67dc1484f9f3fb4a7a79836c274 Mon Sep 17 00:00:00 2001
From: Jan-Hendrik Willms <tleilax+studip@gmail.com>
Date: Fri, 3 Mar 2023 08:45:03 +0000
Subject: [PATCH] prevent php8 warnings, fixes #2250

Closes #2250

Merge request studip/studip!1484
---
 app/views/admin/user/index.php               | 25 +++++++++++---------
 app/views/course/timesrooms/editSemester.php |  9 ++++++-
 lib/classes/ForumEntry.php                   |  3 +--
 lib/classes/PluginAdministration.php         |  8 +++----
 lib/models/Course.class.php                  |  1 +
 public/logout.php                            |  4 +---
 6 files changed, 28 insertions(+), 22 deletions(-)

diff --git a/app/views/admin/user/index.php b/app/views/admin/user/index.php
index aaafc4b662c..77c6937771f 100644
--- a/app/views/admin/user/index.php
+++ b/app/views/admin/user/index.php
@@ -84,8 +84,9 @@ use Studip\Button;
             <?=_('Einrichtung')?>
             <select name="institute">
                 <option value=""><?= _('Alle')?></option>
-                <? foreach($institutes as $institute) : ?>
-                    <option value="<?= $institute['Institut_id']?>" <?= $request['institute'] == $institute['Institut_id'] ? 'selected' : ''?>>
+                <? foreach ($institutes as $institute) : ?>
+                    <option value="<?= htmlReady($institute['Institut_id']) ?>"
+                        <?= isset($request['institute']) && $request['institute'] === $institute['Institut_id'] ? 'selected' : ''?>>
                         <?= htmlReady($institute['Name'])?>
                     </option>
                 <? endforeach ?>
@@ -97,11 +98,12 @@ use Studip\Button;
 
             <select name="userdomains">
                 <option value=""><?= _('Alle') ?></option>
-                <option value="null-domain" <?= $request['userdomains'] === 'null-domain' ? 'selected' : '' ?>>
+                <option value="null-domain" <?= isset($request['userdomains']) && $request['userdomains'] === 'null-domain' ? 'selected' : '' ?>>
                     <?= _('Ohne Domäne') ?>
                 </option>
                 <? foreach ($userdomains as $one): ?>
-                    <option value="<?= htmlReady($one->id) ?>" <?= $request['userdomains'] === $one->id ? 'selected' : ''?>>
+                    <option value="<?= htmlReady($one->id) ?>"
+                        <?= isset($request['userdomains']) && $request['userdomains'] === $one->id ? 'selected' : ''?>>
                         <?= htmlReady($one->name ?: $one->id) ?>
                     </option>
                 <? endforeach; ?>
@@ -114,7 +116,7 @@ use Studip\Button;
                 <option value=""><?=_('Alle')?></option>
                 <? foreach($degrees as $degree) : ?>
                     <option value="<?= $degree->id ?>"
-                        <?= !empty($request['degree']) && in_array($degree->id, $request['degree']) ? 'selected' : ''?>>
+                        <?= isset($request['degree']) && in_array($degree->id, $request['degree']) ? 'selected' : '' ?>>
                         <?=htmlReady($degree->name)?>
                     </option>
                 <? endforeach ?>
@@ -127,7 +129,7 @@ use Studip\Button;
                 <option value=""><?=_('Alle')?></option>
                 <? foreach($studycourses as $studycourse) : ?>
                     <option value="<?= $studycourse->id ?>"
-                        <?= !empty($request['studycourse']) && in_array($studycourse->id, $request['studycourse']) ? 'selected' : ''?>>
+                        <?= isset($request['studycourse']) && in_array($studycourse->id, $request['studycourse']) ? 'selected' : ''?>>
                         <?=htmlReady($studycourse->name)?>
                     </option>
                 <? endforeach ?>
@@ -139,7 +141,7 @@ use Studip\Button;
             <select name="fachsem">
                 <option value=""><?= _('Alle') ?></option>
                 <? for ($i = 1; $i <= 50; $i += 1): ?>
-                    <option <?= $request['fachsem'] && (int)$request['fachsem'] === $i ? 'selected' : ''?>>
+                    <option <?= isset($request['fachsem']) && (int) $request['fachsem'] === $i ? 'selected' : ''?>>
                         <?= $i ?>
                     </option>
                 <? endfor; ?>
@@ -151,7 +153,8 @@ use Studip\Button;
             <select name="auth_plugins">
                 <option value=""><?= _('Alle') ?></option>
                 <? foreach (array_merge(['preliminary' => _('vorläufig')], $available_auth_plugins) as $key => $val): ?>
-                    <option value="<?= $key ?>" <?= $request['auth_plugins'] === $key ? 'selected' : '' ?>>
+                    <option value="<?= $key ?>"
+                        <?= isset($request['auth_plugins']) && $request['auth_plugins'] === $key ? 'selected' : '' ?>>
                         <?= htmlReady($val) ?>
                     </option>
                 <? endforeach; ?>
@@ -165,15 +168,15 @@ use Studip\Button;
                 <? if ($datafield->type === 'bool'): ?>
                     <section class="hgroup">
                 <span class="col-2">
-                    <input type="radio" name="<?= $datafield->id ?>" value="" <?= isset($request[$datafield->id]) && mb_strlen($request[$datafield->id]) === 0 ? 'checked' : '' ?>>
+                    <input type="radio" name="<?= htmlReady($datafield->id) ?>" value="" <?= isset($request[$datafield->id]) && mb_strlen($request[$datafield->id]) === 0 ? 'checked' : '' ?>>
                     <?= _('egal') ?>
                 </span>
                         <span class="col-2">
-                    <input type="radio" name="<?= $datafield->id ?>" value="1" <?= (!empty($request[$datafield->id]) && $request[$datafield->id] === '1') ? 'checked' : '' ?>>
+                    <input type="radio" name="<?= htmlReady($datafield->id) ?>" value="1" <?= (!empty($request[$datafield->id]) && $request[$datafield->id] === '1') ? 'checked' : '' ?>>
                     <?= _('ja') ?>
                 </span>
                         <span class="col-2">
-                    <input type="radio" name="<?= $datafield->id ?>" value="0" <?= isset($request[$datafield->id]) && $request[$datafield->id] === '0' ? 'checked' : '' ?>>
+                    <input type="radio" name="<?= htmlReady($datafield->id) ?>" value="0" <?= isset($request[$datafield->id]) && $request[$datafield->id] === '0' ? 'checked' : '' ?>>
                     <?= _('nein') ?>
                 </span>
                     </section>
diff --git a/app/views/course/timesrooms/editSemester.php b/app/views/course/timesrooms/editSemester.php
index 66bda13a44d..0ac8d1d212c 100644
--- a/app/views/course/timesrooms/editSemester.php
+++ b/app/views/course/timesrooms/editSemester.php
@@ -1,3 +1,10 @@
+<?php
+/**
+ * @var Course_TimesroomsController $controller
+ * @var Semester[] $semester
+ * @var Course $course
+ */
+?>
 <form action="<?= $controller->link_for('course/timesrooms/editSemester') ?>" method="post"
       class="default" data-dialog>
     <?=CSRFProtection::tokenTag()?>
@@ -20,7 +27,7 @@
             <?= _('Dauer') ?>
             <select name="endSemester" id="endSemester">
                 <option value="0"
-                    <?= $course->end_semester->id === $course->start_semester->id ? 'selected' : '' ?>>
+                    <?= count($course->semesters) === 1 ? 'selected' : '' ?>>
                     <?= _('Ein Semester') ?></option>
                 <? foreach ($semester as $sem) : ?>
                     <? if ($sem->beginn >= $course->start_semester->beginn) : ?>
diff --git a/lib/classes/ForumEntry.php b/lib/classes/ForumEntry.php
index 61cbd75c181..968d408c677 100644
--- a/lib/classes/ForumEntry.php
+++ b/lib/classes/ForumEntry.php
@@ -597,7 +597,6 @@ class ForumEntry  implements PrivacyObject
     public static function getList($type, $parent_id)
     {
         $start = (ForumHelpers::getPage() - 1) * ForumEntry::POSTINGS_PER_PAGE;
-        $last_visit_date = ForumVisit::getLastVisit($constraint['seminar_id']);
         switch ($type) {
             case 'area':
                 $list = ForumEntry::getEntries($parent_id, ForumEntry::WITHOUT_CHILDS, '', 'DESC', 0, 1000);
@@ -637,6 +636,7 @@ class ForumEntry  implements PrivacyObject
 
             case 'newest':
                 $constraint = ForumEntry::getConstraints($parent_id);
+                $last_visit_date = ForumVisit::getLastVisit($constraint['seminar_id']);
 
                 // get postings
                 $stmt = DBManager::get()->prepare("SELECT forum_entries.*, IF(ou.topic_id IS NOT NULL, 'fav', NULL) as fav
@@ -657,7 +657,6 @@ class ForumEntry  implements PrivacyObject
                 $postings = $stmt->fetchAll(PDO::FETCH_ASSOC);
 
                 $postings = ForumEntry::parseEntries($postings);
-                // var_dump($postings);
 
                 // count found postings
                 $stmt_count = DBManager::get()->prepare("SELECT COUNT(*)
diff --git a/lib/classes/PluginAdministration.php b/lib/classes/PluginAdministration.php
index dc8418e2c07..9a2af7732c7 100644
--- a/lib/classes/PluginAdministration.php
+++ b/lib/classes/PluginAdministration.php
@@ -26,8 +26,6 @@ class PluginAdministration
      */
     public function installPlugin($filename)
     {
-        global $SOFTWARE_VERSION;
-
         $packagedir = Config::get()->PLUGINS_PATH . '/tmp_' . md5($filename);
 
         // extract plugin files
@@ -69,8 +67,8 @@ class PluginAdministration
         // get plugin meta data
         $pluginclass = $manifest['pluginclassname'];
         $origin      = $manifest['origin'];
-        $min_version = $manifest['studipMinVersion'];
-        $max_version = $manifest['studipMaxVersion'];
+        $min_version = $manifest['studipMinVersion'] ?? null;
+        $max_version = $manifest['studipMaxVersion'] ?? null;
 
         // check for compatible version
         if ((isset($min_version) && StudipVersion::olderThan($min_version)) ||
@@ -134,7 +132,7 @@ class PluginAdministration
         }
 
         // register additional plugin classes in this package
-        $additionalclasses = $manifest['additionalclasses'];
+        $additionalclasses = $manifest['additionalclasses'] ?? null;
 
         if (is_array($additionalclasses)) {
             foreach ($additionalclasses as $class) {
diff --git a/lib/models/Course.class.php b/lib/models/Course.class.php
index d0bc63d6ac7..5df3e3e3e68 100644
--- a/lib/models/Course.class.php
+++ b/lib/models/Course.class.php
@@ -60,6 +60,7 @@
  * @property SimpleORMapCollection admission_applicants has_many AdmissionApplication
  * @property SimpleORMapCollection datafields has_many DatafieldEntryModel
  * @property SimpleORMapCollection cycles has_many SeminarCycleDate
+ * @property Semester[]|SimpleORMapCollection $semesters belongs_to Semester
  * @property Semester start_semester belongs_to Semester
  * @property Semester end_semester belongs_to Semester
  * @property Institute home_institut belongs_to Institute
diff --git a/public/logout.php b/public/logout.php
index 313f58954ba..a4064ded7fd 100644
--- a/public/logout.php
+++ b/public/logout.php
@@ -59,7 +59,7 @@ if ($auth->auth["uid"]!="nobody") {
     $user->set_last_action($timeout);
 
     //der logout() Aufruf fuer CAS (dadurch wird das Cookie (Ticket) im Browser zerstoert)
-    if ($docaslogout){
+    if (!empty($docaslogout)) {
         $casauth->logout();
     }
 } else {
@@ -68,5 +68,3 @@ if ($auth->auth["uid"]!="nobody") {
 }
 
 header("Location:" . URLHelper::getURL("index.php?logout=true&set_language=$_language&set_contrast=$contrast"));
-
-?>
-- 
GitLab