diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php index 7d350f7e8b8..671003f2b99 100644 --- a/htdocs/commande/commande.class.php +++ b/htdocs/commande/commande.class.php @@ -182,7 +182,7 @@ class Commande $file = $conf->commande->dir_output . "/" . $comref . "/" . $comref . ".pdf"; if (file_exists($file)) { - commande_delete_preview($this->db, $this->id); + commande_delete_preview($this->db, $this->id, $this->ref); if (!dol_delete_file($file)) { diff --git a/htdocs/includes/modules/commande/modules_commande.php b/htdocs/includes/modules/commande/modules_commande.php index 9f93c777354..58f653ccf67 100644 --- a/htdocs/includes/modules/commande/modules_commande.php +++ b/htdocs/includes/modules/commande/modules_commande.php @@ -211,7 +211,12 @@ function commande_pdf_create($db, $id, $modele='', $outputlangs='') } } - +/** + \brief Supprime l'image de prévisualitation, pour le cas de régénération de commande + \param db objet base de donnée + \param commandeid id de la commande à effacer + \param commanderef référence de la commande si besoin +*/ function commande_delete_preview($db, $commandeid, $commanderef='') { global $langs,$conf; @@ -222,9 +227,7 @@ function commande_delete_preview($db, $commandeid, $commanderef='') $com->fetch($commandeid); $commanderef = $com->ref; } - //$client = new Societe($db); - //$client->fetch($com->soc_id); - + if ($conf->commande->dir_output) { $comref = sanitize_string($commanderef); diff --git a/htdocs/includes/modules/propale/modules_propale.php b/htdocs/includes/modules/propale/modules_propale.php index c836b5f0389..740a7a95bf1 100644 --- a/htdocs/includes/modules/propale/modules_propale.php +++ b/htdocs/includes/modules/propale/modules_propale.php @@ -194,25 +194,39 @@ function propale_pdf_create($db, $id, $modele='', $outputlangs='') \brief Supprime l'image de prévisualitation, pour le cas de régénération de propal \param db objet base de donnée \param propalid id de la propal à effacer + \param propalref référence de la propal si besoin */ -function propale_delete_preview($db, $propalid) +function propale_delete_preview($db, $propalid, $propalref='') { - global $langs,$conf; + global $langs,$conf; - $propal = new Propal($db,"",$propalid); - $propal->fetch($propalid); - $propal->fetch_client(); - - if ($conf->propal->dir_output) - { - $propalref = sanitize_string($propal->ref); - $dir = $conf->propal->dir_output . "/" . $propalref ; - $file = $dir . "/" . $propalref . ".pdf.png"; - $multiple = $file . "."; + if (!$propalref) + { + $propal = new Propal($db,"",$propalid); + $propal->fetch($propalid); + $propalref = $propal->ref; + } + + if ($conf->propal->dir_output) + { + $propref = sanitize_string($propalref); + $dir = $conf->propal->dir_output . "/" . $propalref ; + $file = $dir . "/" . $propalref . ".pdf.png"; + $multiple = $file . "."; - for ($i = 0; $i < 20; $i++) + if ( file_exists( $file ) && is_writable( $file ) ) { - $preview = $multiple.$i; + if ( ! unlink($file) ) + { + $this->error=$langs->trans("ErrorFailedToOpenFile",$file); + return 0; + } + } + else + { + for ($i = 0; $i < 20; $i++) + { + $preview = $multiple.$i; if ( file_exists( $preview ) && is_writable( $preview ) ) { @@ -222,15 +236,8 @@ function propale_delete_preview($db, $propalid) 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/propal.class.php b/htdocs/propal.class.php index 8ba4b46ba4a..46ff19e74a9 100644 --- a/htdocs/propal.class.php +++ b/htdocs/propal.class.php @@ -1478,12 +1478,41 @@ class Propal */ function delete($user) { + global $conf; + $sql = "DELETE FROM ".MAIN_DB_PREFIX."propaldet WHERE fk_propal = ".$this->id; if ( $this->db->query($sql) ) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."propal WHERE rowid = ".$this->id; if ( $this->db->query($sql) ) { + + // On efface le répertoire du pdf + $propalref = sanitize_string($this->ref); + if ($conf->propal->dir_output) + { + $dir = $conf->propal->dir_output . "/" . $propalref ; + $file = $conf->propal->dir_output . "/" . $propalref . "/" . $propalref . ".pdf"; + if (file_exists($file)) + { + propale_delete_preview($this->db, $this->id, $this->ref); + + if (!dol_delete_file($file)) + { + $this->error=$langs->trans("ErrorCanNotDeleteFile",$file); + return 0; + } + } + if (file_exists($dir)) + { + if (!dol_delete_dir($dir)) + { + $this->error=$langs->trans("ErrorCanNotDeleteDir",$dir); + return 0; + } + } + } + dolibarr_syslog("Suppression de la proposition $this->id par $user->fullname ($user->id)"); return 1; }