From 79c0369d6641b4cecb5ed934b365dce38c043aa0 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Thu, 1 Mar 2012 01:18:24 +0800 Subject: [PATCH] Fix: possibility to use models of external modules --- htdocs/admin/commande.php | 44 +++++++++----- htdocs/admin/facture.php | 60 ++++++++++++------- htdocs/admin/propale.php | 31 +++++++--- .../modules/commande/modules_commande.php | 44 ++++++++------ .../core/modules/facture/modules_facture.php | 44 ++++++++------ .../core/modules/propale/modules_propale.php | 42 +++++++------ 6 files changed, 168 insertions(+), 97 deletions(-) diff --git a/htdocs/admin/commande.php b/htdocs/admin/commande.php index 0836989d66f..34ae1776000 100644 --- a/htdocs/admin/commande.php +++ b/htdocs/admin/commande.php @@ -70,32 +70,48 @@ if ($action == 'specimen') $commande = new Commande($db); $commande->initAsSpecimen(); - - // Charge le modele - $dir = "/core/modules/commande/doc/"; - $file = "pdf_".$modele.".modules.php"; - $file = dol_buildpath($dir.$file); - if (file_exists($file)) + + // Check if there is external models to do asked by plugins + if (is_array($conf->models_modules) && ! empty($conf->models_modules)) { + $conf->file->dol_document_root = array_merge($conf->file->dol_document_root,$conf->models_modules); + } + + // Search template file + $file=''; $classname=''; $filefound=0; + foreach ($conf->file->dol_document_root as $dirroot) + { + // Charge le modele + $dir = $dirroot."/core/modules/commande/doc/"; + $file = $dir."pdf_".$modele.".modules.php"; + if (file_exists($file)) + { + $filefound=1; + $classname = "pdf_".$modele; + break; + require_once($file); + } + } + + if ($filefound) { - $classname = "pdf_".$modele; require_once($file); - - $obj = new $classname($db); - - if ($obj->write_file($commande,$langs) > 0) + + $module = new $classname($db); + + if ($module->write_file($commande,$langs) > 0) { header("Location: ".DOL_URL_ROOT."/document.php?modulepart=commande&file=SPECIMEN.pdf"); return; } else { - $mesg='
'.$obj->error.'
'; - dol_syslog($obj->error, LOG_ERR); + $mesg=''.$module->error.''; + dol_syslog($module->error, LOG_ERR); } } else { - $mesg='
'.$langs->trans("ErrorModuleNotFound").'
'; + $mesg=''.$langs->trans("ErrorModuleNotFound").''; dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR); } } diff --git a/htdocs/admin/facture.php b/htdocs/admin/facture.php index fa4e2f6e0d4..11e977ebba5 100644 --- a/htdocs/admin/facture.php +++ b/htdocs/admin/facture.php @@ -69,32 +69,48 @@ if ($action == 'specimen') $facture = new Facture($db); $facture->initAsSpecimen(); - - // Load template - $dir = DOL_DOCUMENT_ROOT . "/core/modules/facture/doc/"; - $file = "pdf_".$modele.".modules.php"; - if (file_exists($dir.$file)) + + // Check if there is external models to do asked by plugins + if (is_array($conf->models_modules) && ! empty($conf->models_modules)) { + $conf->file->dol_document_root = array_merge($conf->file->dol_document_root,$conf->models_modules); + } + + // Search template file + $file=''; $classname=''; $filefound=0; + foreach ($conf->file->dol_document_root as $dirroot) { - $classname = "pdf_".$modele; - require_once($dir.$file); - - $obj = new $classname($db); - - if ($obj->write_file($facture,$langs) > 0) - { - header("Location: ".DOL_URL_ROOT."/document.php?modulepart=facture&file=SPECIMEN.pdf"); - return; - } - else - { - $mesg=''.$obj->error.''; - dol_syslog($obj->error, LOG_ERR); - } + // Load template + $dir = $dirroot."/core/modules/facture/doc/"; + $file = $dir."pdf_".$modele.".modules.php"; + if (file_exists($file)) + { + $filefound=1; + $classname = "pdf_".$modele; + break; + } + } + + if ($filefound) + { + require_once($file); + + $module = new $classname($db); + + if ($module->write_file($facture,$langs) > 0) + { + header("Location: ".DOL_URL_ROOT."/document.php?modulepart=facture&file=SPECIMEN.pdf"); + return; + } + else + { + $mesg=''.$module->error.''; + dol_syslog($module->error, LOG_ERR); + } } else { - $mesg=''.$langs->trans("ErrorModuleNotFound").''; - dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR); + $mesg=''.$langs->trans("ErrorModuleNotFound").''; + dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR); } } diff --git a/htdocs/admin/propale.php b/htdocs/admin/propale.php index 2e2e15d398e..bbad436f259 100644 --- a/htdocs/admin/propale.php +++ b/htdocs/admin/propale.php @@ -69,17 +69,32 @@ if ($action == 'specimen') $propal = new Propal($db); $propal->initAsSpecimen(); - // Charge le modele - $dir = "/core/modules/propale/doc/"; - $file = "pdf_".$modele.".modules.php"; - $file = dol_buildpath($dir.$file); - if (file_exists($file)) + // Check if there is external models to do asked by plugins + if (is_array($conf->models_modules) && ! empty($conf->models_modules)) { + $conf->file->dol_document_root = array_merge($conf->file->dol_document_root,$conf->models_modules); + } + + // Search template file + $file=''; $classname=''; $filefound=0; + foreach ($conf->file->dol_document_root as $dirroot) + { + // Charge le modele + $dir = $dirroot."/core/modules/propale/doc/"; + $file = $dir."pdf_".$modele.".modules.php"; + if (file_exists($file)) + { + $filefound=1; + $classname = "pdf_".$modele; + break; + } + } + + if ($filefound) { - $classname = "pdf_".$modele; require_once($file); - + $module = new $classname($db); - + if ($module->write_file($propal,$langs) > 0) { header("Location: ".DOL_URL_ROOT."/document.php?modulepart=propal&file=SPECIMEN.pdf"); diff --git a/htdocs/core/modules/commande/modules_commande.php b/htdocs/core/modules/commande/modules_commande.php index 62d8f11411a..99d08513928 100644 --- a/htdocs/core/modules/commande/modules_commande.php +++ b/htdocs/core/modules/commande/modules_commande.php @@ -2,7 +2,7 @@ /* Copyright (C) 2003-2004 Rodolphe Quiedeville * Copyright (C) 2004-2011 Laurent Destailleur * Copyright (C) 2004 Eric Seigne - * Copyright (C) 2005-2011 Regis Houssin + * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2006 Andre Cianfarani * Copyright (C) 2012 Juanjo Menent * @@ -181,23 +181,31 @@ function commande_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0 $modele=$tmp[0]; $srctemplatepath=$tmp[1]; } - - // Search template file - $file=''; $classname=''; $filefound=0; - foreach(array('doc','pdf') as $prefix) - { - $file = $prefix."_".$modele.".modules.php"; - - // On verifie l'emplacement du modele - $file = dol_buildpath($dir.'doc/'.$file); - - if (file_exists($file)) - { - $filefound=1; - $classname=$prefix.'_'.$modele; - break; - } - } + + // Check if there is external models to do asked by plugins + if (is_array($conf->models_modules) && ! empty($conf->models_modules)) { + $conf->file->dol_document_root = array_merge($conf->file->dol_document_root,$conf->models_modules); + } + + foreach ($conf->file->dol_document_root as $dirroot) + { + // Search template file + $file=''; $classname=''; $filefound=0; + foreach(array('doc','pdf') as $prefix) + { + $file = $prefix."_".$modele.".modules.php"; + + // On verifie l'emplacement du modele + $file = $dirroot.$dir.'doc/'.$file; + if (file_exists($file)) + { + $filefound=1; + $classname=$prefix.'_'.$modele; + break; + } + } + if ($filefound) break; + } // Charge le modele if ($filefound) diff --git a/htdocs/core/modules/facture/modules_facture.php b/htdocs/core/modules/facture/modules_facture.php index a6e5d6ae38f..ef8da16e945 100644 --- a/htdocs/core/modules/facture/modules_facture.php +++ b/htdocs/core/modules/facture/modules_facture.php @@ -2,7 +2,7 @@ /* Copyright (C) 2003-2005 Rodolphe Quiedeville * Copyright (C) 2004-2011 Laurent Destailleur * Copyright (C) 2004 Eric Seigne - * Copyright (C) 2005-2011 Regis Houssin + * Copyright (C) 2005-2012 Regis Houssin * * 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 @@ -179,23 +179,31 @@ function facture_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0, $modele=$tmp[0]; $srctemplatepath=$tmp[1]; } - - // Search template file - $file=''; $classname=''; $filefound=0; - foreach(array('doc','pdf') as $prefix) - { - $file = $prefix."_".$modele.".modules.php"; - - // On verifie l'emplacement du modele - $file = dol_buildpath($dir.'doc/'.$file); - - if (file_exists($file)) - { - $filefound=1; - $classname=$prefix.'_'.$modele; - break; - } - } + + // Check if there is external models to do asked by plugins + if (is_array($conf->models_modules) && ! empty($conf->models_modules)) { + $conf->file->dol_document_root = array_merge($conf->file->dol_document_root,$conf->models_modules); + } + + foreach ($conf->file->dol_document_root as $dirroot) + { + // Search template file + $file=''; $classname=''; $filefound=0; + foreach(array('doc','pdf') as $prefix) + { + $file = $prefix."_".$modele.".modules.php"; + + // On verifie l'emplacement du modele + $file = $dirroot.$dir.'doc/'.$file; + if (file_exists($file)) + { + $filefound=1; + $classname=$prefix.'_'.$modele; + break; + } + } + if ($filefound) break; + } // Charge le modele if ($filefound) diff --git a/htdocs/core/modules/propale/modules_propale.php b/htdocs/core/modules/propale/modules_propale.php index 1179f946b43..362948cebe8 100644 --- a/htdocs/core/modules/propale/modules_propale.php +++ b/htdocs/core/modules/propale/modules_propale.php @@ -182,23 +182,31 @@ function propale_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0, $modele=$tmp[0]; $srctemplatepath=$tmp[1]; } - - // Search template file - $file=''; $classname=''; $filefound=0; - foreach(array('doc','pdf') as $prefix) - { - $file = $prefix."_".$modele.".modules.php"; - - // On verifie l'emplacement du modele - $file = dol_buildpath($dir.'doc/'.$file); - - if (file_exists($file)) - { - $filefound=1; - $classname=$prefix.'_'.$modele; - break; - } - } + + // Check if there is external models to do asked by plugins + if (is_array($conf->models_modules) && ! empty($conf->models_modules)) { + $conf->file->dol_document_root = array_merge($conf->file->dol_document_root,$conf->models_modules); + } + + // Search template file + $file=''; $classname=''; $filefound=0; + foreach ($conf->file->dol_document_root as $dirroot) + { + foreach(array('doc','pdf') as $prefix) + { + $file = $prefix."_".$modele.".modules.php"; + + // On verifie l'emplacement du modele + $file = $dirroot.$dir.'doc/'.$file; + if (file_exists($file)) + { + $filefound=1; + $classname=$prefix.'_'.$modele; + break; + } + } + if ($filefound) break; + } // Charge le modele if ($filefound)