From c5a5f07e7b577e74091f84400614f2fc5f9b8124 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 7 Jun 2006 19:13:45 +0000 Subject: [PATCH] =?UTF-8?q?Ajout=20suppression=20des=20pdf=20provisoire=20?= =?UTF-8?q?si=20on=20supprime=20la=20commande,=20le=20bordereau=20d'exp=E9?= =?UTF-8?q?dition=20=20ou=20le=20bon=20de=20livraison=20avant=20sa=20valid?= =?UTF-8?q?ation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/commande/commande.class.php | 26 ++++++++++++++++++++++++++ htdocs/expedition/expedition.class.php | 25 +++++++++++++++++++++++++ htdocs/expedition/fiche.php | 2 +- htdocs/livraison/fiche.php | 2 +- htdocs/livraison/livraison.class.php | 25 +++++++++++++++++++++++++ 5 files changed, 78 insertions(+), 2 deletions(-) diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php index 37ce04b7e30..84b4a417881 100644 --- a/htdocs/commande/commande.class.php +++ b/htdocs/commande/commande.class.php @@ -1845,6 +1845,8 @@ class Commande */ function delete() { + global $conf, $lang; + $err = 0; $this->db->begin(); $sql = 'DELETE FROM '.MAIN_DB_PREFIX."commandedet WHERE fk_commande = $this->id ;"; @@ -1864,6 +1866,30 @@ class Commande { $err++; } + + // On efface le répertoire de pdf provisoire + $comref = sanitize_string($this->ref); + if ($conf->commande->dir_output) + { + $dir = $conf->commande->dir_output . "/" . $comref ; + $file = $conf->commande->dir_output . "/" . $comref . "/" . $comref . ".pdf"; + if (file_exists($file)) + { + 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; + } + } + } if ($err == 0) { diff --git a/htdocs/expedition/expedition.class.php b/htdocs/expedition/expedition.class.php index 6d8e7543d7f..b83c8e9ba3f 100644 --- a/htdocs/expedition/expedition.class.php +++ b/htdocs/expedition/expedition.class.php @@ -521,6 +521,31 @@ class Expedition if ( $this->db->query($sql) ) { $this->db->commit(); + + // On efface le répertoire de pdf provisoire + $expref = sanitize_string($this->ref); + if ($conf->expedition->dir_output) + { + $dir = $conf->expedition->dir_output . "/" . $expref ; + $file = $conf->expedition->dir_output . "/" . $expref . "/" . $expref . ".pdf"; + if (file_exists($file)) + { + 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; + } + } + } + return 1; } else diff --git a/htdocs/expedition/fiche.php b/htdocs/expedition/fiche.php index b2acce2e4c7..493829e472e 100644 --- a/htdocs/expedition/fiche.php +++ b/htdocs/expedition/fiche.php @@ -123,7 +123,7 @@ if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes') if ($user->rights->expedition->supprimer ) { $expedition = new Expedition($db); - $expedition->id = $_GET["id"]; + $expedition->fectch($_GET["id"]); $expedition->delete(); Header("Location: liste.php"); } diff --git a/htdocs/livraison/fiche.php b/htdocs/livraison/fiche.php index a80cc8f6a0e..29ef50eb676 100644 --- a/htdocs/livraison/fiche.php +++ b/htdocs/livraison/fiche.php @@ -121,7 +121,7 @@ if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes') if ($user->rights->expedition->livraison->supprimer ) { $livraison = new Livraison($db); - $livraison->id = $_GET["id"]; + $livraison->fetch($_GET["id"]); $expedition_id = $_GET["expid"]; $livraison->delete(); if ($conf->expedition->enabled) diff --git a/htdocs/livraison/livraison.class.php b/htdocs/livraison/livraison.class.php index 4e4b93767df..4e7785c9e52 100644 --- a/htdocs/livraison/livraison.class.php +++ b/htdocs/livraison/livraison.class.php @@ -521,6 +521,31 @@ class Livraison if ( $this->db->query($sql) ) { $this->db->commit(); + + // On efface le répertoire de pdf provisoire + $livref = sanitize_string($this->ref); + if ($conf->livraison->dir_output) + { + $dir = $conf->livraison->dir_output . "/" . $livref ; + $file = $conf->livraison->dir_output . "/" . $livref . "/" . $livref . ".pdf"; + if (file_exists($file)) + { + 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; + } + } + } + return 1; } else