Repository navigation
Expand file tree
/
Copy pathfiles.php
More file actions
111 lines (91 loc) · 4.02 KB
/
Copy pathfiles.php
File metadata and controls
111 lines (91 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/**
* "My files" — list, download and delete files generated by the Dalfred agent.
*/
$res = 0;
if (!$res && file_exists('../main.inc.php')) $res = @include '../main.inc.php';
if (!$res && file_exists('../../main.inc.php')) $res = @include '../../main.inc.php';
if (!$res && file_exists('../../../main.inc.php')) $res = @include '../../../main.inc.php';
if (!$res) die('Main include failed');
require_once dol_buildpath('/dalfred/src/Service/GeneratedFilesService.php');
$langs->loadLangs(['dalfred@dalfred']);
if (empty($user->id) || !$user->hasRight('dalfred', 'use')) {
accessforbidden();
}
$action = GETPOST('action', 'aZ09');
// Delete action
if ($action === 'delete' && $_SERVER['REQUEST_METHOD'] === 'POST') {
$token = GETPOST('token', 'alpha');
if (!$token || $token !== currentToken()) {
accessforbidden('CSRF token invalid');
}
$target = GETPOST('filename', 'alphanohtml');
if ($target === '') {
setEventMessages($langs->trans('ErrorInvalidFilename'), null, 'errors');
} else {
$svc = new \Dalfred\Service\GeneratedFilesService(DOL_DATA_ROOT, PHP_INT_MAX, dol_buildpath('/dalfred/download.php', 1));
try {
$svc->delete((int) $user->id, $target);
setEventMessages($langs->trans('FileDeleted'), null, 'mesgs');
} catch (\Throwable $e) {
setEventMessages($langs->trans('ErrorDeletingFile'), null, 'errors');
}
}
header('Location: ' . $_SERVER['PHP_SELF']);
exit;
}
llxHeader('', $langs->trans('MyGeneratedFiles'), '');
print load_fiche_titre($langs->trans('MyGeneratedFiles'), '', 'fa-folder-open');
if (getDolGlobalString('DALFRED_FILE_GEN_ENABLED') !== '1') {
print '<div class="opacitymedium">' . $langs->trans('FileGenerationDisabledByAdmin') . '</div>';
llxFooter();
exit;
}
$svc = new \Dalfred\Service\GeneratedFilesService(DOL_DATA_ROOT, PHP_INT_MAX, dol_buildpath('/dalfred/download.php', 1));
$files = $svc->listForUser((int) $user->id);
if (count($files) === 0) {
print '<div class="opacitymedium">' . $langs->trans('NoFilesGenerated') . '</div>';
llxFooter();
exit;
}
$iconMap = [
'txt' => '📄',
'csv' => '📊',
'md' => '📝',
'json' => '🧾',
'html' => '🌐',
];
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<td>' . $langs->trans('Name') . '</td>';
print '<td class="right">' . $langs->trans('FileSize') . '</td>';
print '<td class="center">' . $langs->trans('FileCreatedAt') . '</td>';
print '<td class="center">' . $langs->trans('Actions') . '</td>';
print '</tr>';
foreach ($files as $f) {
$icon = $iconMap[$f['format']] ?? '📁';
$size = dol_print_size($f['size'], 1, 1);
$date = dol_print_date(strtotime($f['modified']), 'dayhour');
$dl = dol_buildpath('/dalfred/download.php', 1) . '?f=' . rawurlencode($f['filename']);
print '<tr class="oddeven">';
print '<td>' . $icon . ' ' . dol_escape_htmltag($f['filename']) . '</td>';
print '<td class="right">' . $size . '</td>';
print '<td class="center">' . $date . '</td>';
print '<td class="center">';
// Download
print '<a class="butAction" href="' . $dl . '" title="' . dol_escape_htmltag($langs->trans('DownloadFile')) . '">⬇️</a> ';
// Delete (POST with CSRF)
print '<form method="POST" action="' . $_SERVER['PHP_SELF'] . '" style="display:inline;"';
print ' onsubmit="return confirm(\'' . dol_escape_js(sprintf($langs->trans('ConfirmDeleteFile'), $f['filename'])) . '\');">';
print '<input type="hidden" name="token" value="' . newToken() . '">';
print '<input type="hidden" name="action" value="delete">';
print '<input type="hidden" name="filename" value="' . dol_escape_htmltag($f['filename']) . '">';
print '<button type="submit" class="butActionDelete" title="' . dol_escape_htmltag($langs->trans('DeleteFile')) . '">🗑️</button>';
print '</form>';
print '</td>';
print '</tr>';
}
print '</table>';
print '</div>';
llxFooter();