diff --git a/htdocs/admin/fichinter.php b/htdocs/admin/fichinter.php index dc24a1869b8..863ecf32bd2 100644 --- a/htdocs/admin/fichinter.php +++ b/htdocs/admin/fichinter.php @@ -6,7 +6,7 @@ * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2008 Raphael Bertrand (Resultic) * Copyright (C) 2011 Juanjo Menent - * Copyright (C) 2011 Philippe Grand + * Copyright (C) 2011-2012 Philippe Grand * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -106,18 +106,27 @@ if ($action == 'specimen') $inter = new Fichinter($db); $inter->initAsSpecimen(); - // Charge le modele - $dir = "/core/modules/fichinter/doc/"; - $file = "pdf_".$modele.".modules.php"; - $file = dol_buildpath($dir.$file); - if (file_exists($file)) + // Search template files + $file=''; $classname=''; $filefound=0; + $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']); + foreach($dirmodels as $reldir) + { + $file=dol_buildpath($reldir."core/modules/fichinter/doc/pdf_".$modele.".modules.php",0); + if (file_exists($file)) + { + $filefound=1; + $classname = "pdf_".$modele; + break; + } + } + + if ($filefound) { - $classname = "pdf_".$modele; require_once($file); - $obj = new $classname($db); + $module = new $classname($db); - if ($obj->write_file($inter,$langs) > 0) + if ($module->write_file($inter,$langs) > 0) { header("Location: ".DOL_URL_ROOT."/document.php?modulepart=ficheinter&file=SPECIMEN.pdf"); return; @@ -219,6 +228,8 @@ if ($action == 'setmod') * View */ +$dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']); + llxHeader(); $form=new Form($db); @@ -242,9 +253,9 @@ print "\n"; clearstatcache(); -foreach ($conf->file->dol_document_root as $dirroot) +foreach ($dirmodels as $reldir) { - $dir = $dirroot . "/core/modules/fichinter/"; + $dir = dol_buildpath($reldir."core/modules/fichinter/"); if (is_dir($dir)) { @@ -260,7 +271,7 @@ foreach ($conf->file->dol_document_root as $dirroot) $file = $reg[1]; $classname = substr($file,4); - require_once($dir.$file.".php"); + require_once(DOL_DOCUMENT_ROOT ."/core/modules/fichinter/".$file.".php"); $module = new $file; diff --git a/htdocs/core/modules/fichinter/modules_fichinter.php b/htdocs/core/modules/fichinter/modules_fichinter.php index 389d2b6facb..c14c4878821 100644 --- a/htdocs/core/modules/fichinter/modules_fichinter.php +++ b/htdocs/core/modules/fichinter/modules_fichinter.php @@ -2,6 +2,7 @@ /* Copyright (C) 2003 Rodolphe Quiedeville * Copyright (C) 2004-2011 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2011-2012 Philippe Grand * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -44,7 +45,7 @@ abstract class ModelePDFFicheinter extends CommonDocGenerator * @param string $maxfilenamelength Max length of value to show * @return array List of templates */ - static function liste_modeles($db,$maxfilenamelength=0) + function liste_modeles($db,$maxfilenamelength=0) { global $conf; @@ -150,14 +151,16 @@ abstract class ModeleNumRefFicheinter * @param Translate $outputlangs objet lang a utiliser pour traduction * @return int 0 if KO, 1 if OK */ -function fichinter_create($db, $object, $modele='', $outputlangs='') +function fichinter_create($db, $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $hookmanager=false) { global $conf,$langs; $langs->load("ficheinter"); - $dir = "/core/modules/fichinter/doc/"; + $error=0; - // Positionne modele sur le nom du modele de facture a utiliser + $srctemplatepath=''; + + // Positionne modele sur le nom du modele de fichinter a utiliser if (! dol_strlen($modele)) { if ($conf->global->FICHEINTER_ADDON_PDF) @@ -170,33 +173,70 @@ function fichinter_create($db, $object, $modele='', $outputlangs='') } } - // Charge le modele - $file = "pdf_".$modele.".modules.php"; + // 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]; + } - // On verifie l'emplacement du modele - $file = dol_buildpath($dir.$file); - - if (file_exists($file)) + // 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/fichinter/doc/".$file,0); + if (file_exists($file)) + { + $filefound=1; + $classname=$prefix.'_'.$modele; + break; + } + } + if ($filefound) break; + } + + // Charge le modele + if ($filefound) { - $classname = "pdf_".$modele; require_once($file); $obj = new $classname($db); - dol_syslog("fichinter_create build PDF", LOG_DEBUG); - // 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($object,$outputlangs) > 0) + if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref, $hookmanager) > 0) { $outputlangs->charset_output=$sav_charset_output; + + // We delete old preview + require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php"); + dol_delete_preview($object); + + // Success in building document. We build meta file. + dol_meta_create($object); + + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); + $interface=new Interfaces($db); + $result=$interface->run_triggers('FICHEINTER_BUILDDOC',$object,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers + return 1; } else { $outputlangs->charset_output=$sav_charset_output; - dol_print_error($db,$obj->error); + dol_print_error($db,"fichinter_pdf_create Error: ".$obj->error); return 0; } }