diff --git a/htdocs/compta/paiement/rapport.php b/htdocs/compta/paiement/rapport.php
index 735dcaa5db3..cc42e4a97ab 100644
--- a/htdocs/compta/paiement/rapport.php
+++ b/htdocs/compta/paiement/rapport.php
@@ -42,6 +42,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
*/
$action = GETPOST('action', 'aZ09');
+$fileToRemove = GETPOST('removefile', 'alpha');
$socid = 0;
if ($user->socid > 0) {
@@ -93,6 +94,21 @@ if ($action == 'builddoc' && $permissiontoread) {
$year = GETPOSTINT("reyear");
}
+// Delete file from disk
+if ($action == 'removedoc' && $permissiontoread && $fileToRemove) {
+ $fullpathfile = dol_sanitizePathName($dir.'/'.$fileToRemove);
+ $fileDirectory = dirname($fullpathfile);
+ if (dol_delete_file($fullpathfile)) {
+ // Delete empty directory after file deletion
+ if (empty(dol_dir_list($fileDirectory))) {
+ dol_delete_dir($fileDirectory);
+ }
+ setEventMessages($langs->trans("FileWasRemoved", $fileToRemove), null, 'mesgs');
+ } else {
+ setEventMessages($langs->trans("ErrorFailToDeleteFile", $fileToRemove), null, 'errors');
+ }
+}
+
/*
* View
@@ -140,6 +156,7 @@ if ($year) {
print '
'.$langs->trans("Reporting").' | ';
print ''.$langs->trans("Size").' | ';
print ''.$langs->trans("Date").' | ';
+ print ' | ';
print '';
$files = (dol_dir_list($dir.'/'.$year, 'files', 0, '^payments-[0-9]{4}-[0-9]{2}\.pdf$', '', 'name', SORT_DESC, 1));
@@ -149,6 +166,7 @@ if ($year) {
print ''.img_pdf().' '.$f['name'].''.$formfile->showPreview($f['name'], 'facture_paiement', $relativepath, 0).' | ';
print ''.dol_print_size($f['size']).' | ';
print ''.dol_print_date($f['date'], "dayhour").' | ';
+ print ''.img_delete().' | ';
print '';
}
print '';
diff --git a/htdocs/fourn/facture/rapport.php b/htdocs/fourn/facture/rapport.php
index c7beff3bee3..f998545d85a 100644
--- a/htdocs/fourn/facture/rapport.php
+++ b/htdocs/fourn/facture/rapport.php
@@ -48,6 +48,7 @@ if (!empty($user->socid)) {
$result = restrictedArea($user, 'fournisseur', 0, 'facture_fourn', 'facture');
$action = GETPOST('action', 'aZ09');
+$fileToRemove = GETPOST('removefile', 'alpha');
$socid = 0;
if ($user->socid > 0) {
@@ -95,6 +96,20 @@ if ($action == 'builddoc' && $permissiontoread) {
$year = GETPOSTINT("reyear");
}
+// Delete file from disk
+if ($action == 'removedoc' && $permissiontoread && $fileToRemove) {
+ $fileDirectory = dirname($dir.'/'.$fileToRemove);
+ if (dol_delete_file($dir.'/'.$fileToRemove)) {
+ // Delete empty directory after file deletion
+ if (empty(dol_dir_list($fileDirectory))) {
+ dol_delete_dir($fileDirectory);
+ }
+ setEventMessages($langs->trans("FileWasRemoved", $fileToRemove), null, 'mesgs');
+ } else {
+ setEventMessages($langs->trans("ErrorFailToDeleteFile", $fileToRemove), null, 'errors');
+ }
+}
+
/*
* View
@@ -158,6 +173,7 @@ if ($year) {
print ''.$langs->trans("Reporting").' | ';
print ''.$langs->trans("Size").' | ';
print ''.$langs->trans("Date").' | ';
+ print ' | ';
print '';
if (is_resource($handle)) {
@@ -167,7 +183,9 @@ if ($year) {
$relativepath = $year.'/'.$file;
print '| '.img_pdf().' '.$file.''.$formfile->showPreview($file, 'facture_fournisseur', 'payments/'.$relativepath, 0).' | ';
print ''.dol_print_size(dol_filesize($tfile)).' | ';
- print ''.dol_print_date(dol_filemtime($tfile), "dayhour").' |
';
+ print ''.dol_print_date(dol_filemtime($tfile), "dayhour").' | ';
+ print ''.img_delete().' | ';
+ print '';
}
}
closedir($handle);