diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index cb1046f86ee6dd97e89f9c74328e1d65246c039c..7140dd9d361356a579a0707d3011b7ab5e32c86b 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -2690,10 +2690,6 @@ class Propal extends CommonObject $langs->load("propale"); - $error=0; - - $srctemplatepath=''; - // Positionne le modele sur le nom du modele a utiliser if (! dol_strlen($modele)) { @@ -2707,73 +2703,9 @@ class Propal extends CommonObject } } - // If selected modele is a filename template (then $modele="modelname:filename") - $tmp=explode(':',$modele,2); - if (! empty($tmp[1])) - { - $modele=$tmp[0]; - $srctemplatepath=$tmp[1]; - } - - // Search template files - $file=''; $classname=''; $filefound=0; - $dirmodels=array('/'); - if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']); - foreach($dirmodels as $reldir) - { - foreach(array('doc','pdf') as $prefix) - { - $file = $prefix."_".$modele.".modules.php"; - - // On verifie l'emplacement du modele - $file=dol_buildpath($reldir."core/modules/propale/doc/".$file,0); - if (file_exists($file)) - { - $filefound=1; - $classname=$prefix.'_'.$modele; - break; - } - } - if ($filefound) break; - } - - // Charge le modele - if ($filefound) - { - require_once $file; - - $obj = new $classname($this->db); - //$obj->message = $message; + $modelpath = "core/modules/propale/doc/"; - // We save charset_output to restore it because write_file can change it if needed for - // output format that does not support UTF8. - $sav_charset_output=$outputlangs->charset_output; - if ($obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0) - { - $outputlangs->charset_output=$sav_charset_output; - - // We delete old preview - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - dol_delete_preview($this); - - // Success in building document. We build meta file. - dol_meta_create($this); - - return 1; - } - else - { - $outputlangs->charset_output=$sav_charset_output; - dol_print_error($this->db,"propal_pdf_create Error: ".$obj->error); - return -1; - } - - } - else - { - dol_print_error('',$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file)); - return -1; - } + return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref); } diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index dd4505ecc953c00cad5c67e97df32041b0d5804e..4b1cf9e32e619bb9b1ed198007057d90e2c09367 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -3028,10 +3028,6 @@ class Commande extends CommonOrder $langs->load("orders"); - $error=0; - - $srctemplatepath=''; - // Positionne le modele sur le nom du modele a utiliser if (! dol_strlen($modele)) { @@ -3045,73 +3041,9 @@ class Commande extends CommonOrder } } - // If selected modele is a filename template (then $modele="modelname:filename") - $tmp=explode(':',$modele,2); - if (! empty($tmp[1])) - { - $modele=$tmp[0]; - $srctemplatepath=$tmp[1]; - } - - // Search template files - $file=''; $classname=''; $filefound=0; - $dirmodels=array('/'); - if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']); - foreach($dirmodels as $reldir) - { - foreach(array('doc','pdf') as $prefix) - { - $file = $prefix."_".$modele.".modules.php"; - - // On verifie l'emplacement du modele - $file=dol_buildpath($reldir."core/modules/commande/doc/".$file,0); - if (file_exists($file)) - { - $filefound=1; - $classname=$prefix.'_'.$modele; - break; - } - } - if ($filefound) break; - } - - // Charge le modele - if ($filefound) - { - require_once $file; - - $obj = new $classname($this->db); - //$obj->message = $message; + $modelpath = "core/modules/commande/doc/"; - // We save charset_output to restore it because write_file can change it if needed for - // output format that does not support UTF8. - $sav_charset_output=$outputlangs->charset_output; - if ($obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0) - { - $outputlangs->charset_output=$sav_charset_output; - - // We delete old preview - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - dol_delete_preview($this); - - // Success in building document. We build meta file. - dol_meta_create($this); - - return 1; - } - else - { - $outputlangs->charset_output=$sav_charset_output; - dol_print_error($this->db,"order_pdf_create Error: ".$obj->error); - return -1; - } - - } - else - { - dol_print_error('',$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file)); - return -1; - } + return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref); } } diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 2752f3d1e0d7bfdbde858263a12d8b61b430915b..f5d20936052cd4f8eb7aaf146fb42e31630be438 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -3238,16 +3238,6 @@ class Facture extends CommonInvoice $langs->load("bills"); - $error=0; - - // Increase limit for PDF build - $err=error_reporting(); - error_reporting(0); - @set_time_limit(120); - error_reporting($err); - - $srctemplatepath=''; - // Positionne le modele sur le nom du modele a utiliser if (! dol_strlen($modele)) { @@ -3261,72 +3251,9 @@ class Facture extends CommonInvoice } } - // If selected modele is a filename template (then $modele="modelname:filename") - $tmp=explode(':',$modele,2); - if (! empty($tmp[1])) - { - $modele=$tmp[0]; - $srctemplatepath=$tmp[1]; - } - - // Search template files - $file=''; $classname=''; $filefound=0; - $dirmodels=array('/'); - if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']); - foreach($dirmodels as $reldir) - { - foreach(array('doc','pdf') as $prefix) - { - $file = $prefix."_".$modele.".modules.php"; - - // On verifie l'emplacement du modele - $file=dol_buildpath($reldir."core/modules/facture/doc/".$file,0); - if (file_exists($file)) - { - $filefound=1; - $classname=$prefix.'_'.$modele; - break; - } - } - if ($filefound) break; - } - - // Charge le modele - if ($filefound) - { - require_once $file; - - $obj = new $classname($this->db); + $modelpath = "core/modules/facture/doc/"; - // We save charset_output to restore it because write_file can change it if needed for - // output format that does not support UTF8. - $sav_charset_output=$outputlangs->charset_output; - if ($obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0) - { - $outputlangs->charset_output=$sav_charset_output; - - // We delete old preview - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - dol_delete_preview($this); - - // Success in building document. We build meta file. - dol_meta_create($this); - - return 1; - } - else - { - $outputlangs->charset_output=$sav_charset_output; - dol_print_error($this->db,"facture_pdf_create Error: ".$obj->error); - return -1; - } - - } - else - { - dol_print_error('',$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file)); - return -1; - } + return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref); } diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index 7861846c4a49ff584a04ef2a465001fdfd20568b..da92f68065bd79b4335cc2822dd6614e1e2dec93 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -2356,10 +2356,6 @@ class ContratLigne extends CommonObject $langs->load("contracts"); - $error=0; - - $srctemplatepath=''; - // Positionne modele sur le nom du modele de contrat a utiliser if (! dol_strlen($modele)) { @@ -2373,71 +2369,9 @@ class ContratLigne extends CommonObject } } - // If selected modele is a filename template (then $modele="modelname:filename") - $tmp=explode(':',$modele,2); - if (! empty($tmp[1])) - { - $modele=$tmp[0]; - $srctemplatepath=$tmp[1]; - } - - // Search template files - $file=''; $classname=''; $filefound=0; - $dirmodels=array('/'); - if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']); - foreach($dirmodels as $reldir) - { - foreach(array('doc','pdf') as $prefix) - { - $file = $prefix."_".$modele.".modules.php"; - - // On verifie l'emplacement du modele - $file=dol_buildpath($reldir."core/modules/contract/doc/".$file,0); - if (file_exists($file)) - { - $filefound=1; - $classname=$prefix.'_'.$modele; - break; - } - } - if ($filefound) break; - } - - // Charge le modele - if ($filefound) - { - require_once $file; - - $obj = new $classname($this->db); - - // We save charset_output to restore it because write_file can change it if needed for - // output format that does not support UTF8. - $sav_charset_output=$outputlangs->charset_output; - if ($obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0) - { - $outputlangs->charset_output=$sav_charset_output; + $modelpath = "core/modules/contract/doc/"; - // We delete old preview - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - dol_delete_preview($this); - - // Success in building document. We build meta file. - dol_meta_create($this); - - return 1; - } - else - { - $outputlangs->charset_output=$sav_charset_output; - dol_print_error($this->db,"contract_pdf_create Error: ".$obj->error); - return 0; - } - } - else - { - print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file); - return 0; - } + return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref); } } diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 1059d1af07dfa206c24913cbb28af0777be6e06d..ebd5cb98a76fe7fcc5d0a689741d1e191c5641b4 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -3475,4 +3475,85 @@ abstract class CommonObject return $result; } + protected function commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref) + { + global $conf, $langs; + + $srctemplatepath=''; + + // Increase limit for PDF build + $err=error_reporting(); + error_reporting(0); + @set_time_limit(120); + error_reporting($err); + + // If selected modele is a filename template (then $modele="modelname:filename") + $tmp=explode(':',$modele,2); + if (! empty($tmp[1])) + { + $modele=$tmp[0]; + $srctemplatepath=$tmp[1]; + } + + // Search template files + $file=''; $classname=''; $filefound=0; + $dirmodels=array('/'); + if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']); + foreach($dirmodels as $reldir) + { + foreach(array('doc','pdf') as $prefix) + { + $file = $prefix."_".$modele.".modules.php"; + + // On verifie l'emplacement du modele + $file=dol_buildpath($reldir.$modelspath.$file,0); + if (file_exists($file)) + { + $filefound=1; + $classname=$prefix.'_'.$modele; + break; + } + } + if ($filefound) break; + } + + // Charge le modele + if ($filefound) + { + require_once $file; + + $obj = new $classname($this->db); + //$obj->message = $message; + + // We save charset_output to restore it because write_file can change it if needed for + // output format that does not support UTF8. + $sav_charset_output=$outputlangs->charset_output; + if ($obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0) + { + $outputlangs->charset_output=$sav_charset_output; + + // We delete old preview + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + dol_delete_preview($this); + + // Success in building document. We build meta file. + dol_meta_create($this); + + return 1; + } + else + { + $outputlangs->charset_output=$sav_charset_output; + dol_print_error($this->db,"Error generating document for ".__CLASS__.". Error: ".$obj->error); + return -1; + } + + } + else + { + dol_print_error('',$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file)); + return -1; + } + } + } diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index ebadc9d0f4eee86a90af14c47be0a0530f3bd863..9aea7ada0eb4392f64dee86db0fe9be2bc2f5257 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -1546,10 +1546,6 @@ class Expedition extends CommonObject $langs->load("sendings"); - $error=0; - - $srctemplatepath=''; - // Sets the model on the model name to use if (! dol_strlen($modele)) { @@ -1563,78 +1559,9 @@ class Expedition extends CommonObject } } - // If selected model is a filename template (then $modele="modelname:filename") - $tmp=explode(':',$modele,2); - if (! empty($tmp[1])) - { - $modele=$tmp[0]; - $srctemplatepath=$tmp[1]; - } - - // Search template files - $file=''; $classname=''; $filefound=0; - $dirmodels=array('/'); - if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']); - foreach($dirmodels as $reldir) - { - foreach(array('doc','pdf') as $prefix) - { - $file = $prefix."_".$modele.".modules.php"; - - // We check the model location - $file=dol_buildpath($reldir."core/modules/expedition/doc/".$file,0); - if (file_exists($file)) - { - $filefound=1; - $classname=$prefix.'_'.$modele; - break; - } - } - if ($filefound) break; - } - - // Load the model - if ($filefound) - { - require_once $file; - - $obj = new $classname($this->db); + $modelpath = "core/modules/expedition/doc/"; - $result=$this->fetch_origin(); - - // We save charset_output to restore it because write_file can change it if needed for - // output format that does not support UTF8. - $sav_charset_output=$outputlangs->charset_output; - if ($obj->write_file($this, $outputlangs, $srctemplatepath) > 0) - { - $outputlangs->charset_output=$sav_charset_output; - - // we delete preview files - //require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - //dol_delete_preview($this); - - return 1; - } - else - { - $outputlangs->charset_output=$sav_charset_output; - dol_syslog("Erreur dans expedition_pdf_create"); - dol_print_error($this->db,$obj->error); - return 0; - } - } - else - { - if (! $conf->global->EXPEDITION_ADDON_PDF) - { - print $langs->trans("Error")." ".$langs->trans("Error_EXPEDITION_ADDON_PDF_NotDefined"); - } - else - { - print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file); - } - return 0; - } + return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, 0, 0, 0); } } diff --git a/htdocs/livraison/class/livraison.class.php b/htdocs/livraison/class/livraison.class.php index 3fa7cc3eadcef0c6c739d7f1baa4b7e4f5ac1095..9fa7c261ac7cbc270c866e391484efb04948dff2 100644 --- a/htdocs/livraison/class/livraison.class.php +++ b/htdocs/livraison/class/livraison.class.php @@ -940,10 +940,6 @@ class Livraison extends CommonObject $langs->load("deliveries"); - $error=0; - - $srctemplatepath=''; - // Positionne modele sur le nom du modele de bon de livraison a utiliser if (! dol_strlen($modele)) { @@ -957,73 +953,11 @@ class Livraison extends CommonObject } } - // If selected modele is a filename template (then $modele="modelname:filename") - $tmp=explode(':',$modele,2); - if (! empty($tmp[1])) - { - $modele=$tmp[0]; - $srctemplatepath=$tmp[1]; - } - - // Search template files - $file=''; $classname=''; $filefound=0; - $dirmodels=array('/'); - if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']); - foreach($dirmodels as $reldir) - { - foreach(array('doc','pdf') as $prefix) - { - $file = $prefix."_".$modele.".modules.php"; - - // On verifie l'emplacement du modele - $file=dol_buildpath($reldir."core/modules/livraison/pdf/".$file,0); - if (file_exists($file)) - { - $filefound=1; - $classname=$prefix.'_'.$modele; - break; - } - } - if ($filefound) break; - } - - // Charge le modele - if ($filefound) - { - require_once $file; - - $obj = new $classname($this->db); + $modelpath = "core/modules/livraison/pdf/"; - // We save charset_output to restore it because write_file can change it if needed for - // output format that does not support UTF8. - $sav_charset_output=$outputlangs->charset_output; - if ($obj->write_file($this,$outputlangs) > 0) - { - $outputlangs->charset_output=$sav_charset_output; - - // we delete preview files - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - dol_delete_preview($this); - - return 1; - } - else - { - $outputlangs->charset_output=$sav_charset_output; - dol_syslog("Erreur dans delivery_order_pdf_create"); - dol_print_error($this->db,$obj->error); - return 0; - } - } - else - { - print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file); - return 0; - } + return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, 0, 0, 0); } - - } diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index 4cc130f548b6caba817b2935adc705a1f3371a46..b13177484931c39d49bfec3afe7e395d40a071bc 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -1323,10 +1323,6 @@ class Project extends CommonObject $langs->load("projects"); - $error=0; - - $srctemplatepath=''; - // Positionne modele sur le nom du modele de projet a utiliser if (! dol_strlen($modele)) { @@ -1340,71 +1336,9 @@ class Project extends CommonObject } } - // If selected modele is a filename template (then $modele="modelname:filename") - $tmp=explode(':',$modele,2); - if (! empty($tmp[1])) - { - $modele=$tmp[0]; - $srctemplatepath=$tmp[1]; - } - - // Search template files - $file=''; $classname=''; $filefound=0; - $dirmodels=array('/'); - if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']); - foreach($dirmodels as $reldir) - { - foreach(array('doc','pdf') as $prefix) - { - $file = $prefix."_".$modele.".modules.php"; - - // On verifie l'emplacement du modele - $file=dol_buildpath($reldir."core/modules/project/pdf/".$file,0); - if (file_exists($file)) - { - $filefound=1; - $classname=$prefix.'_'.$modele; - break; - } - } - if ($filefound) break; - } - - // Charge le modele - if ($filefound) - { - require_once $file; + $modelpath = "core/modules/project/pdf/"; - $obj = new $classname($this->db); - - // We save charset_output to restore it because write_file can change it if needed for - // output format that does not support UTF8. - $sav_charset_output=$outputlangs->charset_output; - if ($obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0) - { - $outputlangs->charset_output=$sav_charset_output; - - // we delete preview files - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - dol_delete_preview($this); - - // Success in building document. We build meta file. - dol_meta_create($this); - - return 1; - } - else - { - $outputlangs->charset_output=$sav_charset_output; - dol_print_error($this->db,"project_pdf_create Error: ".$obj->error); - return 0; - } - } - else - { - print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file); - return 0; - } + return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref); } } diff --git a/htdocs/projet/class/task.class.php b/htdocs/projet/class/task.class.php index 5bc94d740f7e717d987094fd07244f2b645fa17f..2f4cc85cf7f9d0ee4ef8e51f294a266d3e431685 100644 --- a/htdocs/projet/class/task.class.php +++ b/htdocs/projet/class/task.class.php @@ -1327,11 +1327,8 @@ class Task extends CommonObject public function generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $hookmanager=false) { global $conf,$langs; - $langs->load("projects"); - - $error=0; - $srctemplatepath=''; + $langs->load("projects"); // Positionne modele sur le nom du modele de projet a utiliser if (! dol_strlen($modele)) @@ -1346,71 +1343,9 @@ class Task extends CommonObject } } - // If selected modele is a filename template (then $modele="modelname:filename") - $tmp=explode(':',$modele,2); - if (! empty($tmp[1])) - { - $modele=$tmp[0]; - $srctemplatepath=$tmp[1]; - } - - // Search template files - $file=''; $classname=''; $filefound=0; - $dirmodels=array('/'); - if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']); - foreach($dirmodels as $reldir) - { - foreach(array('doc','pdf') as $prefix) - { - $file = $prefix."_".$modele.".modules.php"; - - // On verifie l'emplacement du modele - $file=dol_buildpath($reldir."core/modules/project/task/pdf/".$file,0); - if (file_exists($file)) - { - $filefound=1; - $classname=$prefix.'_'.$modele; - break; - } - } - if ($filefound) break; - } - - // Charge le modele - if ($filefound) - { - require_once $file; - - $obj = new $classname($this->db); - // We save charset_output to restore it because write_file can change it if needed for - // output format that does not support UTF8. - $sav_charset_output=$outputlangs->charset_output; - if ($obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref, $hookmanager) > 0) - { - $outputlangs->charset_output=$sav_charset_output; - - // we delete preview files - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - dol_delete_preview($this); - - // Success in building document. We build meta file. - dol_meta_create($this); + $modelpath = "core/modules/project/task/pdf/"; - return 1; - } - else - { - $outputlangs->charset_output=$sav_charset_output; - dol_print_error($this->db,"task_pdf_create Error: ".$obj->error); - return 0; - } - } - else - { - print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file); - return 0; - } + return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref); } - }