From 972776819290ef76ec38eb5ea967fa2835faa484 Mon Sep 17 00:00:00 2001 From: Indelog Date: Mon, 3 May 2021 09:46:51 +0200 Subject: [PATCH 1/3] Fix show table of pdf payments repports in file order Use scandir() rather opendir() and readdir() to get a sorted list of files. --- htdocs/compta/paiement/rapport.php | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/htdocs/compta/paiement/rapport.php b/htdocs/compta/paiement/rapport.php index 0af202016df..7670e03d094 100644 --- a/htdocs/compta/paiement/rapport.php +++ b/htdocs/compta/paiement/rapport.php @@ -136,7 +136,6 @@ if ($year) { if (is_dir($dir.'/'.$year)) { - $handle = opendir($dir.'/'.$year); if ($found) print '
'; print '
'; @@ -147,22 +146,17 @@ if ($year) print ''.$langs->trans("Date").''; print ''; - if (is_resource($handle)) - { - while (($file = readdir($handle)) !== false) - { - if (preg_match('/^payment/i', $file)) - { - $tfile = $dir.'/'.$year.'/'.$file; - $relativepath = $year.'/'.$file; - print ''; - print ''.img_pdf().' '.$file.''.$formfile->showPreview($file, 'facture_paiement', $relativepath, 0).''; - print ''.dol_print_size(dol_filesize($tfile)).''; - print ''.dol_print_date(dol_filemtime($tfile), "dayhour").''; - print ''; - } + $files = (scandir($dir.'/'.$year)); + foreach ($files as $f) { + $tfile = $dir.'/'.$year.'/'.$f; + $relativepath = $year.'/'.$f; + if (is_file($tfile)) { + print ''; + print ''.img_pdf().' '.$f.''.$formfile->showPreview($f, 'facture_paiement', $relativepath, 0).''; + print ''.dol_print_size(dol_filesize($tfile)).''; + print ''.dol_print_date(dol_filemtime($tfile), "dayhour").''; + print ''; } - closedir($handle); } print ''; } From dba9b17275a2e53da6e4102b5381c7800b1be390 Mon Sep 17 00:00:00 2001 From: Indelog Date: Mon, 3 May 2021 16:00:14 +0200 Subject: [PATCH 2/3] Fix forgot payment filter on file name --- htdocs/compta/paiement/rapport.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/paiement/rapport.php b/htdocs/compta/paiement/rapport.php index 7670e03d094..a640ef1f8fe 100644 --- a/htdocs/compta/paiement/rapport.php +++ b/htdocs/compta/paiement/rapport.php @@ -150,7 +150,7 @@ if ($year) foreach ($files as $f) { $tfile = $dir.'/'.$year.'/'.$f; $relativepath = $year.'/'.$f; - if (is_file($tfile)) { + if (is_file($tfile) && preg_match('/^payment/i', $f)) { print ''; print ''.img_pdf().' '.$f.''.$formfile->showPreview($f, 'facture_paiement', $relativepath, 0).''; print ''.dol_print_size(dol_filesize($tfile)).''; From c18848c9444c0a607838ec347cb22057d26b6e55 Mon Sep 17 00:00:00 2001 From: Indelog Date: Mon, 3 May 2021 17:17:44 +0200 Subject: [PATCH 3/3] Fix: simplify code with dol_dir_list() --- htdocs/compta/paiement/rapport.php | 44 ++++++++---------------------- 1 file changed, 12 insertions(+), 32 deletions(-) diff --git a/htdocs/compta/paiement/rapport.php b/htdocs/compta/paiement/rapport.php index a640ef1f8fe..c76697c8401 100644 --- a/htdocs/compta/paiement/rapport.php +++ b/htdocs/compta/paiement/rapport.php @@ -109,35 +109,18 @@ print '
'; clearstatcache(); // Show link on other years -$linkforyear = array(); -$found = 0; -if (is_dir($dir)) +$year_dirs = dol_dir_list($dir, 'directories', 0, '^[0-9]{4}$', '', 'DESC'); +foreach ($year_dirs as $d) { - $handle = opendir($dir); - if (is_resource($handle)) - { - while (($file = readdir($handle)) !== false) - { - if (is_dir($dir.'/'.$file) && !preg_match('/^\./', $file) && is_numeric($file)) - { - $found = 1; - $linkforyear[] = $file; - } - } - } -} -asort($linkforyear); -foreach ($linkforyear as $cursoryear) -{ - print ''.$cursoryear.'  '; + print ''.$d['name'].'  '; } +$found = true; if ($year) { if (is_dir($dir.'/'.$year)) { - - if ($found) print '
'; + if (!empty($year_dirs)) print '
'; print '
'; print ''; print ''; @@ -146,17 +129,14 @@ if ($year) print ''; print ''; - $files = (scandir($dir.'/'.$year)); + $files = (dol_dir_list($dir.'/'.$year, 'files', 0, '^payments-[0-9]{4}-[0-9]{2}\.pdf$', '', 'name', 'DESC', 1)); foreach ($files as $f) { - $tfile = $dir.'/'.$year.'/'.$f; - $relativepath = $year.'/'.$f; - if (is_file($tfile) && preg_match('/^payment/i', $f)) { - print ''; - print ''; - print ''; - print ''; - print ''; - } + $relativepath = $f['level1name'].'/'.$f['name']; + print ''; + print ''; + print ''; + print ''; + print ''; } print '
'.$langs->trans("Date").'
'.img_pdf().' '.$f.''.$formfile->showPreview($f, 'facture_paiement', $relativepath, 0).''.dol_print_size(dol_filesize($tfile)).''.dol_print_date(dol_filemtime($tfile), "dayhour").'
'.img_pdf().' '.$f['name'].''.$formfile->showPreview($f['name'], 'facture_paiement', $relativepath, 0).''.dol_print_size($f['size']).''.dol_print_date($f['date'], "dayhour").'
'; }