From 1be26ce7c6350a256176876de288e188de3c27ab Mon Sep 17 00:00:00 2001 From: Thomas Zilio Date: Fri, 29 Nov 2019 17:19:22 +0100 Subject: [PATCH] Modifica generazione stampe email --- src/Notifications/EmailNotification.php | 11 ++++------- src/Prints.php | 26 ++++++++++++++++--------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/Notifications/EmailNotification.php b/src/Notifications/EmailNotification.php index 33a7f7adf..a32b9462e 100644 --- a/src/Notifications/EmailNotification.php +++ b/src/Notifications/EmailNotification.php @@ -168,7 +168,7 @@ class EmailNotification extends PHPMailer implements NotificationInterface $this->SmtpClose(); // Pulizia file generati - delete($this->getTempDirectory()); + //delete($this->getTempDirectory()); // Segnalazione degli errori if (!$result) { @@ -224,13 +224,10 @@ class EmailNotification extends PHPMailer implements NotificationInterface { $print = Prints::get($print); - // Utilizzo di una cartella particolare per il salvataggio temporaneo degli allegati - $path = $this->getTempDirectory(); + $info = Prints::render($print['id'], $id_record, null, true); + $name = $name ?: $info['path']; - $info = Prints::render($print['id'], $id_record, $path); - $name = $name ?: $info['name']; - - $this->addAttachment($info['path'], $name); + $this->AddStringAttachment($info['pdf'], $name); } /** diff --git a/src/Prints.php b/src/Prints.php index 0feae6871..8dc3b2b6d 100644 --- a/src/Prints.php +++ b/src/Prints.php @@ -117,8 +117,9 @@ class Prints * @param string|int $print * @param int $id_record * @param string $directory + * @param bool $return_string */ - public static function render($print, $id_record, $directory = null) + public static function render($print, $id_record, $directory = null, $return_string = false) { //ob_end_clean(); // Compatibilità con versioni vecchie delle stampe $dbo = $database = database(); @@ -158,9 +159,9 @@ class Prints } if (self::isOldStandard($print)) { - return self::oldLoader($infos['id'], $id_record, $directory); + return self::oldLoader($infos['id'], $id_record, $directory, $return_string); } else { - return self::loader($infos['id'], $id_record, $directory); + return self::loader($infos['id'], $id_record, $directory, $return_string); } } @@ -310,10 +311,12 @@ class Prints * @param string|int $id_print * @param int $id_record * @param string $directory - * @param string $format + * @param bool $return_string */ - protected static function oldLoader($id_print, $id_record, $directory = null, $format = 'A4') + protected static function oldLoader($id_print, $id_record, $directory = null, $return_string = false) { + $format = 'A4'; + $infos = self::get($id_print); $options = self::readOptions($infos['options']); $docroot = DOCROOT; @@ -355,6 +358,7 @@ class Prints include DOCROOT.'/templates/replace.php'; $mode = !empty($directory) ? 'F' : 'I'; + $mode = !empty($return_string) ? 'S' : $mode; $file = self::getFile($infos, $id_record, $directory, $replaces); $title = $file['name']; @@ -365,7 +369,8 @@ class Prints $html2pdf->writeHTML($report); $html2pdf->pdf->setTitle($title); - $html2pdf->output($path, $mode); + $pdf = $html2pdf->output($path, $mode); + $file['pdf'] = $pdf; return $file; } @@ -387,7 +392,7 @@ class Prints $name = replace($name, $replaces); $filename = sanitizeFilename($name); - $file = ( empty($directory) ) ? $filename : rtrim($directory, '/').'/'.$filename; + $file = (empty($directory)) ? $filename : rtrim($directory, '/').'/'.$filename; return [ 'name' => $name, @@ -401,8 +406,9 @@ class Prints * @param string|int $id_print * @param int $id_record * @param string $directory + * @param bool $return_string */ - protected static function loader($id_print, $id_record, $directory = null) + protected static function loader($id_print, $id_record, $directory = null, $return_string = false) { $infos = self::get($id_print); $options = self::readOptions($infos['options']); @@ -538,6 +544,7 @@ class Prints include DOCROOT.'/templates/replace.php'; $mode = !empty($directory) ? 'F' : 'I'; + $mode = !empty($return_string) ? 'S' : $mode; $file = self::getFile($infos, $id_record, $directory, $replaces); $title = $file['name']; @@ -557,7 +564,8 @@ class Prints } // Creazione effettiva del PDF - $mpdf->Output($path, $mode); + $pdf = $mpdf->Output($path, $mode); + $file['pdf'] = $pdf; return $file; }