From f03bce0120090ff6485a986663aff521759f2087 Mon Sep 17 00:00:00 2001
From: Elmar Ludwig <elmar.ludwig@uni-osnabrueck.de>
Date: Tue, 1 Nov 2022 12:24:13 +0000
Subject: [PATCH] avoid creating empty tbody elements, fixes #1730

Closes #1730

Merge request studip/studip!1127
---
 app/views/file/choose_file.php | 66 +++++++++++++++++-----------------
 1 file changed, 34 insertions(+), 32 deletions(-)

diff --git a/app/views/file/choose_file.php b/app/views/file/choose_file.php
index c5890e12b35..3fee3c0b0c0 100644
--- a/app/views/file/choose_file.php
+++ b/app/views/file/choose_file.php
@@ -85,39 +85,41 @@ if (Request::get('to_folder_id')) {
         </tr>
     </tbody>
 <? else : ?>
-    <tbody>
-    <? foreach ($top_folder->getSubfolders() as $subfolder) : ?>
-    <? if (!$subfolder->isVisible($GLOBALS['user']->id)) continue; ?>
-        <tr>
-            <td class="document-icon" data-sort-value="0">
-            <? if ($subfolder->isReadable($GLOBALS['user']->id)) : ?>
-                <a href="<?= $controller->link_for('file/choose_file/' . $subfolder->id, $options) ?>" data-dialog>
-            <? endif ?>
-            <? if ($is_empty): ?>
-                <?= Icon::create('folder-empty')->asImg(24) ?>
-            <? else: ?>
-                <?= Icon::create('folder-full')->asImg(24) ?>
-            <? endif; ?>
-            <? if ($subfolder->isReadable($GLOBALS['user']->id)) : ?>
-                </a>
-            <? endif ?>
-            </td>
-            <td>
-            <? if ($subfolder->isReadable($GLOBALS['user']->id)) : ?>
-                <a href="<?= $controller->link_for('file/choose_file/' . $subfolder->id, $options) ?>" data-dialog>
+    <? if (count($top_folder->getSubfolders()) > 0) : ?>
+        <tbody>
+        <? foreach ($top_folder->getSubfolders() as $subfolder) : ?>
+            <? if (!$subfolder->isVisible($GLOBALS['user']->id)) continue; ?>
+            <tr>
+                <td class="document-icon" data-sort-value="0">
+                <? if ($subfolder->isReadable($GLOBALS['user']->id)) : ?>
+                    <a href="<?= $controller->link_for('file/choose_file/' . $subfolder->id, $options) ?>" data-dialog>
+                <? endif ?>
+                <? if ($is_empty): ?>
+                    <?= Icon::create('folder-empty')->asImg(24) ?>
+                <? else: ?>
+                    <?= Icon::create('folder-full')->asImg(24) ?>
+                <? endif; ?>
+                <? if ($subfolder->isReadable($GLOBALS['user']->id)) : ?>
+                    </a>
+                <? endif ?>
+                </td>
+                <td>
+                <? if ($subfolder->isReadable($GLOBALS['user']->id)) : ?>
+                    <a href="<?= $controller->link_for('file/choose_file/' . $subfolder->id, $options) ?>" data-dialog>
+                        <?= htmlReady($subfolder->name) ?>
+                    </a>
+                <? else: ?>
                     <?= htmlReady($subfolder->name) ?>
-                </a>
-            <? else: ?>
-                <?= htmlReady($subfolder->name) ?>
-            <? endif ?>
-            <? if ($subfolder->description): ?>
-                <small class="responsive-hidden"><?= htmlReady($subfolder->description) ?></small>
-            <? endif; ?>
-            </td>
-        </tr>
-    <? endforeach; ?>
-    </tbody>
-    <? if (count($top_folder->getFiles())) : ?>
+                <? endif ?>
+                <? if ($subfolder->description): ?>
+                    <small class="responsive-hidden"><?= htmlReady($subfolder->description) ?></small>
+                <? endif; ?>
+                </td>
+            </tr>
+        <? endforeach; ?>
+        </tbody>
+    <? endif ?>
+    <? if (count($top_folder->getFiles()) > 0) : ?>
         <tbody>
         <? foreach ($top_folder->getFiles() as $file) : ?>
             <tr>
-- 
GitLab