diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php index 0f0145a6f05..348207d32f2 100644 --- a/htdocs/commande/commande.class.php +++ b/htdocs/commande/commande.class.php @@ -181,6 +181,8 @@ class Commande $file = $conf->commande->dir_output . "/" . $comref . "/" . $comref . ".pdf"; if (file_exists($file)) { + commande_delete_preview($this->db, $this->id); + if (!dol_delete_file($file)) { $this->error=$langs->trans("ErrorCanNotDeleteFile",$file); diff --git a/htdocs/includes/modules/commande/modules_commande.php b/htdocs/includes/modules/commande/modules_commande.php index 74c92ce9078..8d6a407874c 100644 --- a/htdocs/includes/modules/commande/modules_commande.php +++ b/htdocs/includes/modules/commande/modules_commande.php @@ -212,29 +212,43 @@ function commande_pdf_create($db, $id, $modele='', $outputlangs='') } -function commande_delete_preview($db, $propalid) +function commande_delete_preview($db, $commandeid) { global $langs,$conf; - $com = new Commande($db,"",$propalid); - $com->fetch($propalid); + $com = new Commande($db,"",$commandeid); + $com->fetch($commandeid); $client = new Societe($db); - $client->fetch($com->soc_id); + $client->fetch($com->soc_id); if ($conf->commande->dir_output) - { - $comref = sanitize_string($com->ref); - $dir = $conf->commande->dir_output . "/" . $comref ; - $file = $dir . "/" . $comref . ".pdf.png"; - - if ( file_exists( $file ) && is_writable( $file ) ) - { - if ( ! unlink($file) ) - { - $this->error=$langs->trans("ErrorFailedToOpenFile",$file); - return 0; - } - } - } + { + $comref = sanitize_string($com->ref); + $dir = $conf->commande->dir_output . "/" . $comref ; + $file = $dir . "/" . $comref . ".pdf.png"; + $multiple = $file . "."; + + for ($i = 0; $i < 20; $i++) + { + $preview = $multiple.$i; + + if ( file_exists( $preview ) && is_writable( $preview ) ) + { + if ( ! unlink($preview) ) + { + $this->error=$langs->trans("ErrorFailedToOpenFile",$preview); + return 0; + } + } + else if ( file_exists( $file ) && is_writable( $file ) ) + { + if ( ! unlink($file) ) + { + $this->error=$langs->trans("ErrorFailedToOpenFile",$file); + return 0; + } + } + } + } } ?> diff --git a/htdocs/includes/modules/propale/modules_propale.php b/htdocs/includes/modules/propale/modules_propale.php index 3dbf9032aab..c836b5f0389 100644 --- a/htdocs/includes/modules/propale/modules_propale.php +++ b/htdocs/includes/modules/propale/modules_propale.php @@ -205,18 +205,32 @@ function propale_delete_preview($db, $propalid) if ($conf->propal->dir_output) { - $propalref = sanitize_string($propal->ref); - $dir = $conf->propal->dir_output . "/" . $propalref ; - $file = $dir . "/" . $propalref . ".pdf.png"; - - if ( file_exists( $file ) && is_writable( $file ) ) - { - if ( ! unlink($file) ) - { - $this->error=$langs->trans("ErrorFailedToOpenFile",$file); - return 0; - } - } - } + $propalref = sanitize_string($propal->ref); + $dir = $conf->propal->dir_output . "/" . $propalref ; + $file = $dir . "/" . $propalref . ".pdf.png"; + $multiple = $file . "."; + + for ($i = 0; $i < 20; $i++) + { + $preview = $multiple.$i; + + if ( file_exists( $preview ) && is_writable( $preview ) ) + { + if ( ! unlink($preview) ) + { + $this->error=$langs->trans("ErrorFailedToOpenFile",$preview); + return 0; + } + } + else if ( file_exists( $file ) && is_writable( $file ) ) + { + if ( ! unlink($file) ) + { + $this->error=$langs->trans("ErrorFailedToOpenFile",$file); + return 0; + } + } + } + } } ?>