From 1970f66b2adc143be3c5648114df2d8629d6d44d Mon Sep 17 00:00:00 2001
From: David Siegfried <david.siegfried@uni-vechta.de>
Date: Wed, 16 Nov 2022 08:34:08 +0000
Subject: [PATCH] prevent php-warnings, closes #1782

Closes #1782

Merge request studip/studip!1164
---
 app/controllers/resources/room_planning.php   | 26 +++++++++----------
 app/controllers/room_management/overview.php  |  6 ++---
 .../resources/room_planning/booking_plan.php  |  3 ++-
 3 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/app/controllers/resources/room_planning.php b/app/controllers/resources/room_planning.php
index 55fc168f7eb..220d7a84114 100644
--- a/app/controllers/resources/room_planning.php
+++ b/app/controllers/resources/room_planning.php
@@ -98,7 +98,8 @@ class Resources_RoomPlanningController extends AuthenticatedController
                 'resources/room_planning/booking_plan/' . $new_resource_id
             );
         }
-
+        $this->user_is_global_resource_admin = ResourceManager::userHasGlobalPermission($this->user, 'admin');
+        $this->show_global_admin_actions = $this->user_is_global_resource_admin;
         if (!$resource_id) {
             $resource_id = Request::get('resource_id');
         }
@@ -146,7 +147,6 @@ class Resources_RoomPlanningController extends AuthenticatedController
         //and the user has at least 'user' permissions on the resource.
         //The booking plan is also visible when the resource is a room
         //and its booking plan is publicly available.
-        $plan_is_visible      = false;
         $this->anonymous_view = true;
         $this->booking_types  = [0, 1, 2];
         if ($this->user instanceof User) {
@@ -450,11 +450,12 @@ class Resources_RoomPlanningController extends AuthenticatedController
 
     public function semester_plan_action($resource_id = null)
     {
-        $current_user = User::findCurrent();
-        if (!($current_user instanceof User)) {
+        $this->user = User::findCurrent();
+        if (!($this->user instanceof User)) {
             throw new AccessDeniedException();
         }
-        $this->rooms = RoomManager::getUserRooms($current_user);
+
+        $this->rooms = RoomManager::getUserRooms($this->user);
         $sidebar = Sidebar::get();
         if (Request::get('semester_id')) {
             $this->semester = Semester::find(Request::get('semester_id'));
@@ -539,7 +540,7 @@ class Resources_RoomPlanningController extends AuthenticatedController
         //The booking plan is also visible when the resource is a room
         //and its booking plan is publicly available.
         $plan_is_visible =
-            $this->resource->bookingPlanVisibleForUser($current_user);
+            $this->resource->bookingPlanVisibleForUser($this->user);
 
         if (!$plan_is_visible) {
             throw new AccessDeniedException(
@@ -547,12 +548,11 @@ class Resources_RoomPlanningController extends AuthenticatedController
             );
         }
 
-
-        $this->user_has_booking_permissions = $this->resource->userHasBookingRights(
-            $current_user
-        );
-        $this->booking_types                = [0, 1, 2];
-        if ($this->resource->userHasPermission($current_user, 'admin')) {
+        $this->user_is_global_resource_admin = ResourceManager::userHasGlobalPermission($this->user, 'admin');
+        $this->show_global_admin_actions     = $this->user_is_global_resource_admin;
+        $this->user_has_booking_permissions  = $this->resource->userHasBookingRights($this->user);
+        $this->booking_types                 = [0, 1, 2];
+        if ($this->resource->userHasPermission($this->user, 'admin')) {
             $this->booking_types[] = 3;
         }
         if ($this->user_has_booking_permissions) {
@@ -737,7 +737,7 @@ class Resources_RoomPlanningController extends AuthenticatedController
                 'text'   => _('Reservierung')
             ],
         ];
-        if ($this->resource->userHasPermission($current_user, 'admin')) {
+        if ($this->resource->userHasPermission($this->user, 'admin')) {
             $planned_booking_colour = ColourValue::find('Resources.BookingPlan.PlannedBooking.Bg');
             $this->table_keys[]     = [
                 'colour' => (string)$planned_booking_colour,
diff --git a/app/controllers/room_management/overview.php b/app/controllers/room_management/overview.php
index 2b3022cb3f5..10c539ffa14 100644
--- a/app/controllers/room_management/overview.php
+++ b/app/controllers/room_management/overview.php
@@ -350,7 +350,7 @@ class RoomManagement_OverviewController extends AuthenticatedController
         $search = new SearchWidget($this->roomsURL());
         $search->setTitle(_('Raumsuche'));
         $search->addNeedle(_('Gebäude oder Raum'), 'building_room_name', true);
-        
+
         $sidebar->addWidget($search);
 
         // search for all rooms
@@ -360,7 +360,7 @@ class RoomManagement_OverviewController extends AuthenticatedController
                       ON resources.parent_id = pr.id
                       WHERE rc.class_name IN ( :room_class_names )";
         // narrow down rooms according to search parameter (room or building name)
-        $rooms_sql_with_request = $rooms_sql . 
+        $rooms_sql_with_request = $rooms_sql .
                      "AND (resources.name LIKE CONCAT('%', :room_name, '%')
                       OR pr.name LIKE CONCAT('%', :building_name, '%'))";
 
@@ -380,7 +380,7 @@ class RoomManagement_OverviewController extends AuthenticatedController
             //the user has at least user permissions:
             $rooms_parameter['user_id'] = $this->user->id;
             $rooms_parameter['now']     = time();
-            
+
             // did the user search for a specific room or building name?
             $rooms_sql = Request::get('building_room_name') ? $rooms_sql_with_request : $rooms_sql;
 
diff --git a/app/views/resources/room_planning/booking_plan.php b/app/views/resources/room_planning/booking_plan.php
index d314218c0c5..beb19426a4d 100644
--- a/app/views/resources/room_planning/booking_plan.php
+++ b/app/views/resources/room_planning/booking_plan.php
@@ -122,7 +122,8 @@
             [
                 'grouped_rooms' => RoomManager::groupRooms($rooms),
                 'link_template' => $selection_link_template,
-                'show_in_dialog' => false
+                'show_in_dialog' => false,
+                'show_global_admin_actions' => $show_global_admin_actions,
             ]
         ) ?>
     <? else: ?>
-- 
GitLab