shipping receipt modele can be used from a custom directory

This commit is contained in:
Grand Philippe 2012-04-22 10:02:12 +02:00
parent c190d4ddf8
commit 559c7974e9

View File

@ -3,6 +3,7 @@
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2006-2011 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2011-2012 Philippe Grand <philippe.grand@atoo-net.com>
*
* 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
@ -154,33 +155,62 @@ abstract class ModeleNumRefDeliveryOrder
* @param Translate $outputlangs objet lang a utiliser pour traduction
* @return int 0 if KO, 1 if OK
*/
function delivery_order_pdf_create($db, $object, $model='', $outputlangs='')
function delivery_order_pdf_create($db, $object, $modele, $outputlangs='')
{
global $conf,$langs;
$langs->load("deliveries");
$dir = "/core/modules/livraison/pdf/";
$error=0;
$srctemplatepath='';
// Positionne modele sur le nom du modele de bon de livraison a utiliser
if (! dol_strlen($model))
if (! dol_strlen($modele))
{
if ($conf->global->LIVRAISON_ADDON_PDF)
{
$model = $conf->global->LIVRAISON_ADDON_PDF;
$modele = $conf->global->LIVRAISON_ADDON_PDF;
}
else
{
print $langs->trans("Error")." ".$langs->trans("Error_LIVRAISON_ADDON_PDF_NotDefined");
return 0;
$modele = 'typhon';
}
}
// Charge le modele
$file = "pdf_".$model.".modules.php";
// On verifie l'emplacement du modele
$file = dol_buildpath($dir.$file);
if (file_exists($file))
// 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)
{
$classname = "pdf_".$model;
require_once($file);
$obj = new $classname($db);
@ -212,4 +242,4 @@ function delivery_order_pdf_create($db, $object, $model='', $outputlangs='')
}
}
?>
?>