NEW Add Button to Remove Payment Reports (#31822)
* button to remove rapport * Update user.class.php * Update rapport.php * Update user.class.php
This commit is contained in:
parent
3cfda29d0d
commit
239c0bdd2c
2 changed files with 37 additions and 1 deletions
|
|
@ -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 '<td>'.$langs->trans("Reporting").'</td>';
|
||||
print '<td class="right">'.$langs->trans("Size").'</td>';
|
||||
print '<td class="right">'.$langs->trans("Date").'</td>';
|
||||
print '<td class="right"></td>';
|
||||
print '</tr>';
|
||||
|
||||
$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 '<td><a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?modulepart=facture_paiement&file='.urlencode($relativepath).'">'.img_pdf().' '.$f['name'].'</a>'.$formfile->showPreview($f['name'], 'facture_paiement', $relativepath, 0).'</td>';
|
||||
print '<td class="right">'.dol_print_size($f['size']).'</td>';
|
||||
print '<td class="right">'.dol_print_date($f['date'], "dayhour").'</td>';
|
||||
print '<td class="right"><a href="rapport.php?removefile='.urlencode($relativepath).'&action=removedoc&token='.newToken().'">'.img_delete().'</a></td>';
|
||||
print '</tr>';
|
||||
}
|
||||
print '</table>';
|
||||
|
|
|
|||
|
|
@ -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 '<td>'.$langs->trans("Reporting").'</td>';
|
||||
print '<td class="right">'.$langs->trans("Size").'</td>';
|
||||
print '<td class="right">'.$langs->trans("Date").'</td>';
|
||||
print '<td class="right"></td>';
|
||||
print '</tr>';
|
||||
|
||||
if (is_resource($handle)) {
|
||||
|
|
@ -167,7 +183,9 @@ if ($year) {
|
|||
$relativepath = $year.'/'.$file;
|
||||
print '<tr class="oddeven"><td><a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?modulepart=facture_fournisseur&file=payments/'.urlencode($relativepath).'">'.img_pdf().' '.$file.'</a>'.$formfile->showPreview($file, 'facture_fournisseur', 'payments/'.$relativepath, 0).'</td>';
|
||||
print '<td class="right">'.dol_print_size(dol_filesize($tfile)).'</td>';
|
||||
print '<td class="right">'.dol_print_date(dol_filemtime($tfile), "dayhour").'</td></tr>';
|
||||
print '<td class="right">'.dol_print_date(dol_filemtime($tfile), "dayhour").'</td>';
|
||||
print '<td class="right"><a href="rapport.php?removefile='.urlencode($relativepath).'&action=removedoc&token='.newToken().'">'.img_delete().'</a></td>';
|
||||
print '</tr>';
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
|
|
|
|||
Loading…
Reference in a new issue