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

@ -70,32 +70,48 @@ if ($action == 'specimen')
$commande = new Commande($db); $commande = new Commande($db);
$commande->initAsSpecimen(); $commande->initAsSpecimen();
// Charge le modele // Check if there is external models to do asked by plugins
$dir = "/core/modules/commande/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);
$file = dol_buildpath($dir.$file); }
if (file_exists($file))
// 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); 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

@ -69,32 +69,48 @@ 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)
{ {
$classname = "pdf_".$modele; // Load template
require_once($dir.$file); $dir = $dirroot."/core/modules/facture/doc/";
$file = $dir."pdf_".$modele.".modules.php";
$obj = new $classname($db); if (file_exists($file))
{
if ($obj->write_file($facture,$langs) > 0) $filefound=1;
{ $classname = "pdf_".$modele;
header("Location: ".DOL_URL_ROOT."/document.php?modulepart=facture&file=SPECIMEN.pdf"); break;
return; }
} }
else
{ if ($filefound)
$mesg='<font class="error">'.$obj->error.'</font>'; {
dol_syslog($obj->error, LOG_ERR); 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='<font class="error">'.$module->error.'</font>';
dol_syslog($module->error, LOG_ERR);
}
} }
else else
{ {
$mesg='<font class="error">'.$langs->trans("ErrorModuleNotFound").'</font>'; $mesg='<font class="error">'.$langs->trans("ErrorModuleNotFound").'</font>';
dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR); dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
} }
} }

View File

@ -69,17 +69,32 @@ if ($action == 'specimen')
$propal = new Propal($db); $propal = new Propal($db);
$propal->initAsSpecimen(); $propal->initAsSpecimen();
// Charge le modele // Check if there is external models to do asked by plugins
$dir = "/core/modules/propale/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);
$file = dol_buildpath($dir.$file); }
if (file_exists($file))
// 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); require_once($file);
$module = new $classname($db); $module = new $classname($db);
if ($module->write_file($propal,$langs) > 0) if ($module->write_file($propal,$langs) > 0)
{ {
header("Location: ".DOL_URL_ROOT."/document.php?modulepart=propal&file=SPECIMEN.pdf"); header("Location: ".DOL_URL_ROOT."/document.php?modulepart=propal&file=SPECIMEN.pdf");

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>
* *
@ -181,23 +181,31 @@ function commande_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0
$modele=$tmp[0]; $modele=$tmp[0];
$srctemplatepath=$tmp[1]; $srctemplatepath=$tmp[1];
} }
// Search template file // Check if there is external models to do asked by plugins
$file=''; $classname=''; $filefound=0; if (is_array($conf->models_modules) && ! empty($conf->models_modules)) {
foreach(array('doc','pdf') as $prefix) $conf->file->dol_document_root = array_merge($conf->file->dol_document_root,$conf->models_modules);
{ }
$file = $prefix."_".$modele.".modules.php";
foreach ($conf->file->dol_document_root as $dirroot)
// On verifie l'emplacement du modele {
$file = dol_buildpath($dir.'doc/'.$file); // Search template file
$file=''; $classname=''; $filefound=0;
if (file_exists($file)) foreach(array('doc','pdf') as $prefix)
{ {
$filefound=1; $file = $prefix."_".$modele.".modules.php";
$classname=$prefix.'_'.$modele;
break; // 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 // 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
@ -179,23 +179,31 @@ function facture_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0,
$modele=$tmp[0]; $modele=$tmp[0];
$srctemplatepath=$tmp[1]; $srctemplatepath=$tmp[1];
} }
// Search template file // Check if there is external models to do asked by plugins
$file=''; $classname=''; $filefound=0; if (is_array($conf->models_modules) && ! empty($conf->models_modules)) {
foreach(array('doc','pdf') as $prefix) $conf->file->dol_document_root = array_merge($conf->file->dol_document_root,$conf->models_modules);
{ }
$file = $prefix."_".$modele.".modules.php";
foreach ($conf->file->dol_document_root as $dirroot)
// On verifie l'emplacement du modele {
$file = dol_buildpath($dir.'doc/'.$file); // Search template file
$file=''; $classname=''; $filefound=0;
if (file_exists($file)) foreach(array('doc','pdf') as $prefix)
{ {
$filefound=1; $file = $prefix."_".$modele.".modules.php";
$classname=$prefix.'_'.$modele;
break; // 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 // Charge le modele
if ($filefound) if ($filefound)

View File

@ -182,23 +182,31 @@ function propale_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0,
$modele=$tmp[0]; $modele=$tmp[0];
$srctemplatepath=$tmp[1]; $srctemplatepath=$tmp[1];
} }
// Search template file // Check if there is external models to do asked by plugins
$file=''; $classname=''; $filefound=0; if (is_array($conf->models_modules) && ! empty($conf->models_modules)) {
foreach(array('doc','pdf') as $prefix) $conf->file->dol_document_root = array_merge($conf->file->dol_document_root,$conf->models_modules);
{ }
$file = $prefix."_".$modele.".modules.php";
// Search template file
// On verifie l'emplacement du modele $file=''; $classname=''; $filefound=0;
$file = dol_buildpath($dir.'doc/'.$file); foreach ($conf->file->dol_document_root as $dirroot)
{
if (file_exists($file)) foreach(array('doc','pdf') as $prefix)
{ {
$filefound=1; $file = $prefix."_".$modele.".modules.php";
$classname=$prefix.'_'.$modele;
break; // 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 // Charge le modele
if ($filefound) if ($filefound)