Fix: possibility to use models of external modules

This commit is contained in:
Regis Houssin 2012-03-01 01:18:24 +08:00
parent 07ee6208a9
commit 79c0369d66
6 changed files with 168 additions and 97 deletions

View File

@ -71,31 +71,47 @@ if ($action == 'specimen')
$commande = new Commande($db); $commande = new Commande($db);
$commande->initAsSpecimen(); $commande->initAsSpecimen();
// 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 // Charge le modele
$dir = "/core/modules/commande/doc/"; $dir = $dirroot."/core/modules/commande/doc/";
$file = "pdf_".$modele.".modules.php"; $file = $dir."pdf_".$modele.".modules.php";
$file = dol_buildpath($dir.$file);
if (file_exists($file)) if (file_exists($file))
{ {
$filefound=1;
$classname = "pdf_".$modele; $classname = "pdf_".$modele;
break;
require_once($file);
}
}
if ($filefound)
{
require_once($file); require_once($file);
$obj = new $classname($db); $module = new $classname($db);
if ($obj->write_file($commande,$langs) > 0) if ($module->write_file($commande,$langs) > 0)
{ {
header("Location: ".DOL_URL_ROOT."/document.php?modulepart=commande&file=SPECIMEN.pdf"); header("Location: ".DOL_URL_ROOT."/document.php?modulepart=commande&file=SPECIMEN.pdf");
return; return;
} }
else else
{ {
$mesg='<div class="error">'.$obj->error.'</div>'; $mesg='<font class="error">'.$module->error.'</font>';
dol_syslog($obj->error, LOG_ERR); dol_syslog($module->error, LOG_ERR);
} }
} }
else else
{ {
$mesg='<div class="error">'.$langs->trans("ErrorModuleNotFound").'</div>'; $mesg='<font class="error">'.$langs->trans("ErrorModuleNotFound").'</font>';
dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR); dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
} }
} }

View File

@ -70,25 +70,41 @@ if ($action == 'specimen')
$facture = new Facture($db); $facture = new Facture($db);
$facture->initAsSpecimen(); $facture->initAsSpecimen();
// Load template // Check if there is external models to do asked by plugins
$dir = DOL_DOCUMENT_ROOT . "/core/modules/facture/doc/"; if (is_array($conf->models_modules) && ! empty($conf->models_modules)) {
$file = "pdf_".$modele.".modules.php"; $conf->file->dol_document_root = array_merge($conf->file->dol_document_root,$conf->models_modules);
if (file_exists($dir.$file)) }
// Search template file
$file=''; $classname=''; $filefound=0;
foreach ($conf->file->dol_document_root as $dirroot)
{ {
// Load template
$dir = $dirroot."/core/modules/facture/doc/";
$file = $dir."pdf_".$modele.".modules.php";
if (file_exists($file))
{
$filefound=1;
$classname = "pdf_".$modele; $classname = "pdf_".$modele;
require_once($dir.$file); break;
}
}
$obj = new $classname($db); if ($filefound)
{
require_once($file);
if ($obj->write_file($facture,$langs) > 0) $module = new $classname($db);
if ($module->write_file($facture,$langs) > 0)
{ {
header("Location: ".DOL_URL_ROOT."/document.php?modulepart=facture&file=SPECIMEN.pdf"); header("Location: ".DOL_URL_ROOT."/document.php?modulepart=facture&file=SPECIMEN.pdf");
return; return;
} }
else else
{ {
$mesg='<font class="error">'.$obj->error.'</font>'; $mesg='<font class="error">'.$module->error.'</font>';
dol_syslog($obj->error, LOG_ERR); dol_syslog($module->error, LOG_ERR);
} }
} }
else else

View File

@ -69,13 +69,28 @@ if ($action == 'specimen')
$propal = new Propal($db); $propal = new Propal($db);
$propal->initAsSpecimen(); $propal->initAsSpecimen();
// 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 // Charge le modele
$dir = "/core/modules/propale/doc/"; $dir = $dirroot."/core/modules/propale/doc/";
$file = "pdf_".$modele.".modules.php"; $file = $dir."pdf_".$modele.".modules.php";
$file = dol_buildpath($dir.$file);
if (file_exists($file)) if (file_exists($file))
{ {
$filefound=1;
$classname = "pdf_".$modele; $classname = "pdf_".$modele;
break;
}
}
if ($filefound)
{
require_once($file); require_once($file);
$module = new $classname($db); $module = new $classname($db);

View File

@ -2,7 +2,7 @@
/* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com> * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005-2012 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr> * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
* Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
* *
@ -182,6 +182,13 @@ function commande_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0
$srctemplatepath=$tmp[1]; $srctemplatepath=$tmp[1];
} }
// 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 // Search template file
$file=''; $classname=''; $filefound=0; $file=''; $classname=''; $filefound=0;
foreach(array('doc','pdf') as $prefix) foreach(array('doc','pdf') as $prefix)
@ -189,8 +196,7 @@ function commande_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0
$file = $prefix."_".$modele.".modules.php"; $file = $prefix."_".$modele.".modules.php";
// On verifie l'emplacement du modele // On verifie l'emplacement du modele
$file = dol_buildpath($dir.'doc/'.$file); $file = $dirroot.$dir.'doc/'.$file;
if (file_exists($file)) if (file_exists($file))
{ {
$filefound=1; $filefound=1;
@ -198,6 +204,8 @@ function commande_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0
break; break;
} }
} }
if ($filefound) break;
}
// Charge le modele // Charge le modele
if ($filefound) if ($filefound)

View File

@ -2,7 +2,7 @@
/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com> * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005-2012 Regis Houssin <regis@dolibarr.fr>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -180,6 +180,13 @@ function facture_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0,
$srctemplatepath=$tmp[1]; $srctemplatepath=$tmp[1];
} }
// 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 // Search template file
$file=''; $classname=''; $filefound=0; $file=''; $classname=''; $filefound=0;
foreach(array('doc','pdf') as $prefix) foreach(array('doc','pdf') as $prefix)
@ -187,8 +194,7 @@ function facture_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0,
$file = $prefix."_".$modele.".modules.php"; $file = $prefix."_".$modele.".modules.php";
// On verifie l'emplacement du modele // On verifie l'emplacement du modele
$file = dol_buildpath($dir.'doc/'.$file); $file = $dirroot.$dir.'doc/'.$file;
if (file_exists($file)) if (file_exists($file))
{ {
$filefound=1; $filefound=1;
@ -196,6 +202,8 @@ function facture_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0,
break; break;
} }
} }
if ($filefound) break;
}
// Charge le modele // Charge le modele
if ($filefound) if ($filefound)

View File

@ -183,15 +183,21 @@ function propale_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0,
$srctemplatepath=$tmp[1]; $srctemplatepath=$tmp[1];
} }
// 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 // Search template file
$file=''; $classname=''; $filefound=0; $file=''; $classname=''; $filefound=0;
foreach ($conf->file->dol_document_root as $dirroot)
{
foreach(array('doc','pdf') as $prefix) foreach(array('doc','pdf') as $prefix)
{ {
$file = $prefix."_".$modele.".modules.php"; $file = $prefix."_".$modele.".modules.php";
// On verifie l'emplacement du modele // On verifie l'emplacement du modele
$file = dol_buildpath($dir.'doc/'.$file); $file = $dirroot.$dir.'doc/'.$file;
if (file_exists($file)) if (file_exists($file))
{ {
$filefound=1; $filefound=1;
@ -199,6 +205,8 @@ function propale_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0,
break; break;
} }
} }
if ($filefound) break;
}
// Charge le modele // Charge le modele
if ($filefound) if ($filefound)