Fix esportazione file in bulk con stesso nome generato
This commit is contained in:
parent
8da180c8c5
commit
3c134f00d8
|
@ -53,7 +53,7 @@ switch (post('op')) {
|
|||
foreach ($fatture as $r) {
|
||||
$print = Prints::getModulePredefinedPrint($id_module);
|
||||
|
||||
Prints::render($print['id'], $r['id'], $dir.'tmp/');
|
||||
Prints::render($print['id'], $r['id'], $dir.'tmp/', false, false);
|
||||
}
|
||||
|
||||
// Creazione zip
|
||||
|
|
|
@ -56,7 +56,7 @@ switch (post('op')) {
|
|||
foreach ($interventi as $r) {
|
||||
$print = Prints::getModulePredefinedPrint($id_module);
|
||||
|
||||
Prints::render($print['id'], $r['id'], $dir.'tmp/');
|
||||
Prints::render($print['id'], $r['id'], $dir.'tmp/', false, false);
|
||||
}
|
||||
|
||||
$dir = slashes($dir);
|
||||
|
|
|
@ -139,7 +139,7 @@ class Prints
|
|||
* @param string $directory
|
||||
* @param bool $return_string
|
||||
*/
|
||||
public static function render($print, $id_record, $directory = null, $return_string = false)
|
||||
public static function render($print, $id_record, $directory = null, $return_string = false, $overwrite = true)
|
||||
{
|
||||
//ob_end_clean(); // Compatibilità con versioni vecchie delle stampe
|
||||
$dbo = $database = database();
|
||||
|
@ -186,9 +186,9 @@ class Prints
|
|||
if (self::isCompletelyCustom($print)) {
|
||||
return self::customLoader($infos['id'], $id_record, $directory, $return_string);
|
||||
} elseif (self::isOldStandard($print)) {
|
||||
return self::oldLoader($infos['id'], $id_record, $directory, $return_string);
|
||||
return self::oldLoader($infos['id'], $id_record, $directory, $return_string, $overwrite);
|
||||
} else {
|
||||
return self::loader($infos['id'], $id_record, $directory, $return_string);
|
||||
return self::loader($infos['id'], $id_record, $directory, $return_string, $overwrite);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -354,7 +354,7 @@ class Prints
|
|||
* @param string $directory
|
||||
* @param bool $return_string
|
||||
*/
|
||||
protected static function oldLoader($id_print, $id_record, $directory = null, $return_string = false)
|
||||
protected static function oldLoader($id_print, $id_record, $directory = null, $return_string = false, $overwrite = true)
|
||||
{
|
||||
$format = 'A4';
|
||||
|
||||
|
@ -415,6 +415,20 @@ class Prints
|
|||
$html2pdf->writeHTML($report);
|
||||
$html2pdf->pdf->setTitle($title);
|
||||
|
||||
// Ridenominazione file se l'impostazione è disattivata
|
||||
if (!$overwrite) {
|
||||
$index = 1;
|
||||
|
||||
$file_parts = pathinfo($path);
|
||||
$filename_no_extension = $file_parts['filename'];
|
||||
|
||||
while (file_exists($directory.'/'.$file_parts['basename'])) {
|
||||
$path = $file_parts['dirname'].'/'.$filename_no_extension.'_'.$index++.'.'.$file_parts['extension'];
|
||||
|
||||
$file_parts = pathinfo($path);
|
||||
}
|
||||
}
|
||||
|
||||
$pdf = $html2pdf->output($path, $mode);
|
||||
$file['pdf'] = $pdf;
|
||||
}else{
|
||||
|
@ -458,7 +472,7 @@ class Prints
|
|||
* @param string $directory
|
||||
* @param bool $return_string
|
||||
*/
|
||||
protected static function loader($id_print, $id_record, $directory = null, $return_string = false)
|
||||
protected static function loader($id_print, $id_record, $directory = null, $return_string = false, $overwrite = true)
|
||||
{
|
||||
$infos = self::get($id_print);
|
||||
$options = self::readOptions($infos['options']);
|
||||
|
@ -650,6 +664,20 @@ class Prints
|
|||
$title = $file['name'];
|
||||
$path = $file['path'];
|
||||
|
||||
// Ridenominazione file se l'impostazione è disattivata
|
||||
if (!$overwrite) {
|
||||
$index = 1;
|
||||
|
||||
$file_parts = pathinfo($path);
|
||||
$filename_no_extension = $file_parts['filename'];
|
||||
|
||||
while (file_exists($directory.'/'.$file_parts['basename'])) {
|
||||
$path = $file_parts['dirname'].'/'.$filename_no_extension.'_'.$index++.'.'.$file_parts['extension'];
|
||||
|
||||
$file_parts = pathinfo($path);
|
||||
}
|
||||
}
|
||||
|
||||
// Impostazione del titolo del PDF
|
||||
$mpdf->SetTitle($title);
|
||||
|
||||
|
|
Loading…
Reference in New Issue