From 5655e10ff2983579e750c20cdb86be1174339ba3 Mon Sep 17 00:00:00 2001
From: David Siegfried <david.siegfried@uni-vechta.de>
Date: Wed, 8 Mar 2023 11:03:27 +0000
Subject: [PATCH] prevent php-warnings, closes #2286

Closes #2286

Merge request studip/studip!1509
---
 app/controllers/files.php               | 13 ++++++-------
 app/views/files/flat.php                |  6 +++---
 templates/sidebar/time-range-filter.php |  6 +++---
 3 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/app/controllers/files.php b/app/controllers/files.php
index 9ed804f5ae5..80802e5085e 100644
--- a/app/controllers/files.php
+++ b/app/controllers/files.php
@@ -334,7 +334,6 @@ class FilesController extends AuthenticatedController
 
         $course_did_change = false;
         if ($this->current_view != 'overview') {
-            $tzdt = new DateTime();
             if (Request::submitted('filter')) {
                 CSRFProtection::verifyUnsafeRequest();
                 if (Request::get('begin') && Request::get('end')) {
@@ -365,9 +364,9 @@ class FilesController extends AuthenticatedController
                     $_SESSION['files_overview']['course_id'] = $this->course_id;
                 }
             } else {
-                $this->begin = $_SESSION['files_overview']['begin'];
-                $this->end = $_SESSION['files_overview']['end'];
-                $this->course_id = $_SESSION['files_overview']['course_id'];
+                $this->begin = $_SESSION['files_overview']['begin'] ?? null;
+                $this->end = $_SESSION['files_overview']['end'] ?? null;
+                $this->course_id = $_SESSION['files_overview']['course_id'] ?? null;
             }
         }
 
@@ -700,7 +699,7 @@ class FilesController extends AuthenticatedController
         $copymode   = Request::get('copymode');
 
         $user = User::findCurrent();
-
+        $destination_plugin = null;
         if ($to_plugin) {
 
             $destination_id = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], "dispatch.php/files/copyhandler/") + strlen("dispatch.php/files/copyhandler/"));
@@ -721,7 +720,7 @@ class FilesController extends AuthenticatedController
 
         $count_files   = 0;
         $count_folders = 0;
-
+        $source_folder = null;
         $filerefs = $fileref_id;
         if (!empty($filerefs)) {
 
@@ -784,7 +783,7 @@ class FilesController extends AuthenticatedController
                         }
                     }
                 }
-                if (is_array($result)) {
+                if (isset($result) && is_array($result)) {
                     $errors = array_merge($errors, $result);
                 }
             }
diff --git a/app/views/files/flat.php b/app/views/files/flat.php
index 7b68e022639..a7d0c93fc90 100644
--- a/app/views/files/flat.php
+++ b/app/views/files/flat.php
@@ -45,7 +45,7 @@ foreach ($topFolder->getAdditionalActionButtons() as $button) {
 ?>
 <form id="files_table_form"
       method="post"
-      action="<?= htmlReady($form_action) ?>"
+      action="<?= htmlReady($form_action ?? '') ?>"
       data-files="<?= htmlReady(json_encode($vue_files)) ?>"
       data-topfolder="<?= htmlReady(json_encode((array) $vue_topFolder)) ?>">
     <?= CSRFProtection::tokenTag() ?>
@@ -55,8 +55,8 @@ foreach ($topFolder->getAdditionalActionButtons() as $button) {
                  :folders="folders"
                  :topfolder="topfolder"
                  :allow_filter="<?= json_encode(!empty($enable_table_filter)) ?>"
-                 table_title="<?= htmlReady($table_title) ?>"
-                 pagination="<?= htmlReady($pagination_html) ?>"
+                 table_title="<?= htmlReady($table_title ?? '') ?>"
+                 pagination="<?= htmlReady($pagination_html ?? '') ?>"
                  :initial_sort="{sortedBy:'chdate',sortDirection:'desc'}"
     ></files-table>
 </form>
diff --git a/templates/sidebar/time-range-filter.php b/templates/sidebar/time-range-filter.php
index 793381e4ecf..97dbcf67820 100644
--- a/templates/sidebar/time-range-filter.php
+++ b/templates/sidebar/time-range-filter.php
@@ -2,15 +2,15 @@
     <?= CSRFProtection::tokenTag() ?>
     <label>
         <?= _('Dateien neuer als') ?>:
-        <input type="text" name="begin" value="<?= htmlReady($begin) ?>"
+        <input type="text" name="begin" value="<?= htmlReady($begin ?? '') ?>"
                class="hasDatePicker">
     </label>
     <label>
         <?= _('Dateien älter als') ?>:
-        <input type="text" name="end" value="<?= htmlReady($end) ?>"
+        <input type="text" name="end" value="<?= htmlReady($end ?? '') ?>"
                class="hasDatePicker submit-on-change">
     </label>
-    <? if ($course_options) : ?>
+    <? if (!empty($course_options)) : ?>
         <label>
             <?= _('Veranstaltung') ?>:
             <select name="course_id">
-- 
GitLab