* Copyright (c) 2025 Schaffhauser sébastien * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation. */ require_once __DIR__ . '/../class/controller.class.php'; /** * \file htdocs/webportal/controllers/abstractdocument.controller.class.php * \ingroup webportal * \brief This file is an abstract controller with shared logic to display a list of documents. */ /** * Abstract Class for Document Controllers * Contains the shared logic to display a table of files. * * @property DoliDB $db Inherited from Controller * @property int $accessRight Inherited from Controller */ abstract class AbstractDocumentController extends Controller { /** * Renders an HTML file browser table for a given list of files and directories. * * @param string $title The main H2 title for the page. * @param array> $itemList The list of items from dol_dir_list('all'). * @param string $emptyMessage The message to display if the list is empty. * @param array $linkBuilder An array of functions to build URLs ('dir' and 'file'). * @return void */ protected function displayDocumentTable($title, $itemList, $emptyMessage, array $linkBuilder) { global $langs; echo '

' . htmlspecialchars($title) . '

'; if (is_array($itemList) && count($itemList) > 0) { // 1. Separate folders and files $directories = array(); $files = array(); foreach ($itemList as $item) { if ($item['type'] === 'dir') { $directories[] = $item; } else { $files[] = $item; } } // 2. Display the table echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; // 3. Display all folders first foreach ($directories as $dir) { echo ''; // The link for a directory is for navigation echo ''; echo ''; // No size for a directory echo ''; echo ''; } // 4. Then, display all files foreach ($files as $file) { echo ''; // The link for a file is for download echo ''; echo ''; echo ''; echo ''; } echo '
' . $langs->trans('Name') . '' . $langs->trans('Size') . '' . $langs->trans('DateM') . '
📁 ' . htmlspecialchars($dir['name']) . '--' . dol_print_date($dir['date'], 'dayhour') . '
📄 ' . htmlspecialchars($file['name']) . '' . dol_print_size($file['size']) . '' . dol_print_date($file['date'], 'dayhour') . '
'; } else { echo '

' . htmlspecialchars($emptyMessage) . '

'; } echo '
'; } }