From 0f1aa02c94f477c4a565d18a788b7a892a385dc6 Mon Sep 17 00:00:00 2001
From: Moritz Strohm <strohm@data-quest.de>
Date: Tue, 15 Nov 2022 13:30:54 +0000
Subject: [PATCH] TIC 1311, closes #1311

Closes #1311

Merge request studip/studip!807
---
 app/controllers/resources/export.php          | 17 ++++++++
 app/controllers/room_management/planning.php  | 13 ++++++
 .../export/select_booking_sources.php         | 40 +++++++++++++++++++
 3 files changed, 70 insertions(+)

diff --git a/app/controllers/resources/export.php b/app/controllers/resources/export.php
index 6c430094dab..f0d5905a55e 100644
--- a/app/controllers/resources/export.php
+++ b/app/controllers/resources/export.php
@@ -67,6 +67,7 @@ class Resources_ExportController extends AuthenticatedController
 
         PageLayout::setTitle(_('Quellen für den Export von Buchungen auswählen'));
 
+        $this->weekdays = ['1', '2', '3', '4', '5'];
         $this->select_rooms = Request::get('select_rooms');
 
         if ($this->select_rooms) {
@@ -265,12 +266,21 @@ class Resources_ExportController extends AuthenticatedController
             'H:i'
         );
 
+        //Get the selected weekdays:
+        $this->weekdays = Request::getArray('weekdays');
+
         if ($this->begin >= $this->end) {
             PageLayout::postError(
                 _('Der Startzeitpunkt darf nicht hinter dem Endzeitpunkt liegen!')
             );
             return;
         }
+        if (!$this->weekdays) {
+            PageLayout::postError(
+                _('Bitte mindestens einen Wochentag auswählen.')
+            );
+            return;
+        }
 
         //Resolve the IDs to clipboards (or rooms) and build a list of rooms.
 
@@ -342,6 +352,13 @@ class Resources_ExportController extends AuthenticatedController
             //Prepare data for export:
 
             foreach ($intervals as $interval) {
+                //Check the weekday of the interval first to avoid any other computation
+                //if the weekday is not one of the selected weekdays.
+                $interval_weekday = date('N', $interval->begin);
+                if (!in_array($interval_weekday, $this->weekdays)) {
+                    //The interval is not on one of the selected weekdays.
+                    continue;
+                }
                 $booking = $interval->booking;
                 if (!$booking instanceof ResourceBooking || !in_array($booking->booking_type, $types)) {
                     continue;
diff --git a/app/controllers/room_management/planning.php b/app/controllers/room_management/planning.php
index 7f01e864792..81627e294ae 100644
--- a/app/controllers/room_management/planning.php
+++ b/app/controllers/room_management/planning.php
@@ -46,6 +46,14 @@ class RoomManagement_PlanningController extends AuthenticatedController
         //Build sidebar:
         $sidebar = Sidebar::get();
 
+        $actions = new ActionsWidget();
+        $actions->addLink(
+            _('Drucken'),
+            'javascript:void(window.print());',
+            Icon::create('print')
+        );
+        $sidebar->addWidget($actions);
+
         $views = new ViewsWidget();
         if ($GLOBALS['user']->id && ($GLOBALS['user']->id !== 'nobody')) {
             $views->addLink(
@@ -291,6 +299,11 @@ class RoomManagement_PlanningController extends AuthenticatedController
         }
 
         $actions = new ActionsWidget();
+        $actions->addLink(
+            _('Drucken'),
+            'javascript:void(window.print());',
+            Icon::create('print')
+        );
         $actions->addLink(
             _('Buchungen kopieren'),
             $this->url_for('room_management/planning/copy_bookings'),
diff --git a/app/views/resources/export/select_booking_sources.php b/app/views/resources/export/select_booking_sources.php
index f24b064cb0c..a0fe6078ded 100644
--- a/app/views/resources/export/select_booking_sources.php
+++ b/app/views/resources/export/select_booking_sources.php
@@ -19,6 +19,46 @@
                        value="<?= $end->format('H:i')?>">
             </label>
         </fieldset>
+        <fieldset>
+            <legend><?= _('Wochentage auswählen') ?></legend>
+            <div class="hgroup">
+                <label>
+                    <input type="checkbox" name="weekdays[]" value="1"
+                        <?= in_array('1', $weekdays) ? 'checked' : '' ?>>
+                    <?= _('Montag') ?>
+                </label>
+                <label>
+                    <input type="checkbox" name="weekdays[]" value="2"
+                        <?= in_array('2', $weekdays) ? 'checked' : '' ?>>
+                    <?= _('Dienstag') ?>
+                </label>
+                <label>
+                    <input type="checkbox" name="weekdays[]" value="3"
+                        <?= in_array('3', $weekdays) ? 'checked' : '' ?>>
+                    <?= _('Mittwoch') ?>
+                </label>
+                <label>
+                    <input type="checkbox" name="weekdays[]" value="4"
+                        <?= in_array('4', $weekdays) ? 'checked' : '' ?>>
+                    <?= _('Donnerstag') ?>
+                </label>
+                <label>
+                    <input type="checkbox" name="weekdays[]" value="5"
+                        <?= in_array('5', $weekdays) ? 'checked' : '' ?>>
+                    <?= _('Freitag') ?>
+                </label>
+                <label>
+                    <input type="checkbox" name="weekdays[]" value="6"
+                        <?= in_array('6', $weekdays) ? 'checked' : '' ?>>
+                    <?= _('Samstag') ?>
+                </label>
+                <label>
+                    <input type="checkbox" name="weekdays[]" value="7"
+                        <?= in_array('7', $weekdays) ? 'checked' : '' ?>>
+                    <?= _('Sonntag') ?>
+                </label>
+            </div>
+        </fieldset>
         <? if ($available_rooms): ?>
             <table class="default">
                 <caption>
-- 
GitLab