dolibarr 24.0.0-beta
abstractdocument.controller.class.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
4 * Copyright (c) 2025 Schaffhauser sébastien <sebastien@webmaster67.fr>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation.
8 */
9
10require_once __DIR__ . '/../class/controller.class.php';
11
26{
36 protected function displayDocumentTable($title, $itemList, $emptyMessage, array $linkBuilder)
37 {
38 global $langs;
39
40 echo '<h2>' . htmlspecialchars($title) . '</h2>';
41
42 if (is_array($itemList) && count($itemList) > 0) {
43 // 1. Separate folders and files
44 $directories = array();
45 $files = array();
46 foreach ($itemList as $item) {
47 if ($item['type'] === 'dir') {
48 $directories[] = $item;
49 } else {
50 $files[] = $item;
51 }
52 }
53
54 // 2. Display the table
55 echo '<table class="table table-hover" width="100%">';
56 echo '<thead><tr>';
57 echo '<th>' . $langs->trans('Name') . '</th>';
58 echo '<th style="text-align: right; white-space: nowrap;">' . $langs->trans('Size') . '</th>';
59 echo '<th style="text-align: right; white-space: nowrap;">' . $langs->trans('DateM') . '</th>';
60 echo '</tr></thead>';
61 echo '<tbody>';
62
63 // 3. Display all folders first
64 foreach ($directories as $dir) {
65 echo '<tr>';
66 // The link for a directory is for navigation
67 echo '<td><a href="' . $linkBuilder['dir']($dir) . '">📁&nbsp;' . htmlspecialchars($dir['name']) . '</a></td>';
68 echo '<td style="text-align: right;">--</td>'; // No size for a directory
69 echo '<td style="text-align: right;">' . dol_print_date($dir['date'], 'dayhour') . '</td>';
70 echo '</tr>';
71 }
72
73 // 4. Then, display all files
74 foreach ($files as $file) {
75 echo '<tr>';
76 // The link for a file is for download
77 echo '<td><a href="' . $linkBuilder['file']($file) . '" target="_blank">📄&nbsp;' . htmlspecialchars($file['name']) . '</a></td>';
78 echo '<td style="text-align: right;">' . dol_print_size($file['size']) . '</td>';
79 echo '<td style="text-align: right;">' . dol_print_date($file['date'], 'dayhour') . '</td>';
80 echo '</tr>';
81 }
82
83 echo '</tbody></table>';
84 } else {
85 echo '<p>' . htmlspecialchars($emptyMessage) . '</p>';
86 }
87
88 echo '<br>';
89 }
90}
displayDocumentTable($title, $itemList, $emptyMessage, array $linkBuilder)
Renders an HTML file browser table for a given list of files and directories.
Class to manage pages.
dol_print_size($size, $shortvalue=0, $shortunit=0)
Return string with formatted size.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).