From 45a0d11bb7737416adf2fd7914cdcec0b5c19d01 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 31 May 2006 11:34:05 +0000 Subject: [PATCH] =?UTF-8?q?On=20efface=20le=20rep=E9rtoire=20du=20pdf=20pr?= =?UTF-8?q?ovisoire?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/expedition/expedition.class.php | 27 ++++++++++++++++++ htdocs/expedition/fiche.php | 22 +++++++-------- .../mods/pdf/ModelePdfExpedition.class.php | 2 ++ .../mods/pdf/pdf_expedition_merou.modules.php | 28 +++++++++++-------- htdocs/livraison/livraison.class.php | 26 +++++++++++++++++ 5 files changed, 81 insertions(+), 24 deletions(-) diff --git a/htdocs/expedition/expedition.class.php b/htdocs/expedition/expedition.class.php index 6ec8ab3603d..753de105829 100644 --- a/htdocs/expedition/expedition.class.php +++ b/htdocs/expedition/expedition.class.php @@ -348,6 +348,33 @@ class Expedition return -2; } } + + // On efface le répertoire de pdf provisoire + $expeditionref = sanitize_string($this->ref); + $expeditionref = str_replace("(","",$expeditionref); + $expeditionref = str_replace(")","",$expeditionref); + if ($conf->expedition->dir_output) + { + $dir = $conf->expedition->dir_output . "/" . $expeditionref ; + $file = $conf->expedition->dir_output . "/" . $expeditionref . "/" . $expeditionref . ".pdf"; + if (file_exists($file)) + { + if (!dol_delete_file($file)) + { + $this->error=$langs->trans("ErrorCanNotDeleteFile",$dir); + return 0; + } + } + if (file_exists($dir)) + { + if (!dol_delete_dir($dir)) + { + $this->error=$langs->trans("ErrorCanNotDeleteDir",$dir); + return 0; + } + } + } + } else { diff --git a/htdocs/expedition/fiche.php b/htdocs/expedition/fiche.php index 292062330cb..1625e83f10b 100644 --- a/htdocs/expedition/fiche.php +++ b/htdocs/expedition/fiche.php @@ -530,22 +530,20 @@ else /* * Documents générés */ - - //mis en commentaire pour test du patch - //$filename=sanitize_string($expedition->id); - //$filedir=$conf->expedition->dir_output . "/" .get_exdir($expedition->id); - $filename=sanitize_string($expedition->ref); - $filedir=$conf->expedition->dir_output . "/" .$expedition->ref; + $expeditionref = sanitize_string($expedition->ref); + $expeditionref = str_replace("(","",$expeditionref); + $expeditionref = str_replace(")","",$expeditionref); + $filedir = $conf->expedition->dir_output . "/" .$expeditionref; - $urlsource=$_SERVER["PHP_SELF"]."?id=".$expedition->id; + $urlsource = $_SERVER["PHP_SELF"]."?id=".$expedition->id; - //$genallowed=$user->rights->expedition->creer; - //$delallowed=$user->rights->expedition->supprimer; - $genallowed=1; - $delallowed=0; + $genallowed=$user->rights->expedition->creer; + $delallowed=$user->rights->expedition->supprimer; + //$genallowed=1; + //$delallowed=0; - $result=$html->show_documents('expedition',$filename,$filedir,$urlsource,$genallowed,$delallowed,$expedition->modelpdf); + $result=$html->show_documents('expedition',$expeditionref,$filedir,$urlsource,$genallowed,$delallowed,$expedition->modelpdf); /* * Déjà livre diff --git a/htdocs/expedition/mods/pdf/ModelePdfExpedition.class.php b/htdocs/expedition/mods/pdf/ModelePdfExpedition.class.php index f94f7d7d900..30a2d6f37f8 100644 --- a/htdocs/expedition/mods/pdf/ModelePdfExpedition.class.php +++ b/htdocs/expedition/mods/pdf/ModelePdfExpedition.class.php @@ -124,6 +124,8 @@ function expedition_pdf_create($db, $id, $modele='', $outputlangs='') $result=$expedition->fetch($id); $expeditionref = sanitize_string($expedition->ref); + $expeditionref = str_replace("(","",$expeditionref); + $expeditionref = str_replace(")","",$expeditionref); $dir = $conf->expedition->dir_output . "/" . $expeditionref; $file = $dir . "/" . $expeditionref . ".pdf"; if ($obj->generate($expedition, $file)) diff --git a/htdocs/expedition/mods/pdf/pdf_expedition_merou.modules.php b/htdocs/expedition/mods/pdf/pdf_expedition_merou.modules.php index b3ea3ba6edf..ab6dc8d6e5c 100644 --- a/htdocs/expedition/mods/pdf/pdf_expedition_merou.modules.php +++ b/htdocs/expedition/mods/pdf/pdf_expedition_merou.modules.php @@ -82,18 +82,22 @@ Class pdf_expedition_merou extends ModelePdfExpedition //Verification de la configuration if ($conf->expedition->dir_output) { - $forbidden_chars=array("/","\\",":","*","?","\"","<",">","|","[","]",",",";","="); - $expref = str_replace($forbidden_chars,"_",$this->expe->ref); - $dir = $conf->expedition->dir_output . "/" . $this->expe->ref . "/" ; - $file = $dir .$this->expe->ref . ".pdf"; - //Si le dossier n existe pas - if (! file_exists($dir)){ - umask(0); - //On tente de le creer - if (! mkdir($dir, 0755)){ - $pdf->error=$langs->trans("ErrorCanNotCreateDir",$dir); - return 0; - } + $expeditionref = sanitize_string($this->expe->ref); + $expeditionref = str_replace("(","",$expeditionref); + $expeditionref = str_replace(")","",$expeditionref); + $dir = $conf->expedition->dir_output . "/" . $expeditionref; + $file = $dir . "/" . $expeditionref . ".pdf"; + //Si le dossier n existe pas + if (! file_exists($dir)) + { + umask(0); + + //On tente de le creer + if (! mkdir($dir, 0755)) + { + $pdf->error=$langs->trans("ErrorCanNotCreateDir",$dir); + return 0; + } } //Si le dossier existe if (file_exists($dir)) diff --git a/htdocs/livraison/livraison.class.php b/htdocs/livraison/livraison.class.php index 77a623d4c69..ad2278704cd 100644 --- a/htdocs/livraison/livraison.class.php +++ b/htdocs/livraison/livraison.class.php @@ -339,6 +339,32 @@ class Livraison } } + // On efface le répertoire de pdf provisoire + $livraisonref = sanitize_string($this->ref); + $livraisonref = str_replace("(","",$livraisonref); + $livraisonref = str_replace(")","",$livraisonref); + if ($conf->expedition->dir_output) + { + $dir = $conf->livraison->dir_output . "/" . $livraisonref ; + $file = $conf->livraison->dir_output . "/" . $livraisonref . "/" . $livraisonref . ".pdf"; + if (file_exists($file)) + { + if (!dol_delete_file($file)) + { + $this->error=$langs->trans("ErrorCanNotDeleteFile",$dir); + return 0; + } + } + if (file_exists($dir)) + { + if (!dol_delete_dir($dir)) + { + $this->error=$langs->trans("ErrorCanNotDeleteDir",$dir); + return 0; + } + } + } + dolibarr_syslog("livraison.class.php::valid ok"); } else