Prepair to display within a custom place

This commit is contained in:
Grand Philippe 2012-04-05 11:46:56 +02:00
parent 03cfec7904
commit d3068e0ba5

View File

@ -2,6 +2,7 @@
/* Copyright (C) 2010 Regis Houssin <regis@dolibarr.fr> /* Copyright (C) 2010 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2011 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2011-2012 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2011-2012 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2011-2012 Philippe Grand <philippe.grand@atoo-net.com>
* *
* 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
@ -35,8 +36,8 @@ $langs->load("projects");
if (!$user->admin) if (!$user->admin)
accessforbidden(); accessforbidden();
$value=GETPOST('value','action'); $value=GETPOST('value','alpha');
$action=GETPOST('action','action'); $action=GETPOST('action','alpha');
/* /*
@ -69,17 +70,28 @@ if ($action == 'specimen')
$project = new Project($db); $project = new Project($db);
$project->initAsSpecimen(); $project->initAsSpecimen();
// Charge le modele // Search template files
$dir = DOL_DOCUMENT_ROOT . "/core/modules/project/pdf/"; $file=''; $classname=''; $filefound=0;
$file = "pdf_".$modele.".modules.php"; $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
if (file_exists($dir.$file)) foreach($dirmodels as $reldir)
{ {
$file=dol_buildpath($reldir."core/modules/project/pdf/pdf_".$modele.".modules.php",0);
if (file_exists($file))
{
$filefound=1;
$classname = "pdf_".$modele; $classname = "pdf_".$modele;
require_once($dir.$file); break;
}
}
$obj = new $classname($db);
if ($obj->write_file($project,$langs) > 0) if ($filefound)
{
require_once($file);
$module = new $classname($db);
if ($module->write_file($project,$langs) > 0)
{ {
header("Location: ".DOL_URL_ROOT."/document.php?modulepart=project&file=SPECIMEN.pdf"); header("Location: ".DOL_URL_ROOT."/document.php?modulepart=project&file=SPECIMEN.pdf");
return; return;
@ -172,6 +184,8 @@ if ($action == 'setmod')
* View * View
*/ */
$dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
$form=new Form($db); $form=new Form($db);
llxHeader(); llxHeader();
@ -199,6 +213,12 @@ print "</tr>\n";
clearstatcache(); clearstatcache();
foreach ($dirmodels as $reldir)
{
$dir = dol_buildpath($reldir."core/modules/project/");
if (is_dir($dir))
{
$handle = opendir($dir); $handle = opendir($dir);
if (is_resource($handle)) if (is_resource($handle))
{ {
@ -206,9 +226,10 @@ if (is_resource($handle))
while (($file = readdir($handle))!==false) while (($file = readdir($handle))!==false)
{ {
if (substr($file, 0, 12) == 'mod_project_' && substr($file, dol_strlen($file)-3, 3) == 'php') if (preg_match('/^(mod_.*)\.php$/i',$file,$reg))
{ {
$file = substr($file, 0, dol_strlen($file)-4); $file = $reg[1];
$classname = substr($file,4);
require_once(DOL_DOCUMENT_ROOT ."/core/modules/project/".$file.".php"); require_once(DOL_DOCUMENT_ROOT ."/core/modules/project/".$file.".php");
@ -274,6 +295,8 @@ if (is_resource($handle))
} }
closedir($handle); closedir($handle);
} }
}
}
print '</table><br>'; print '</table><br>';
@ -282,7 +305,7 @@ print '</table><br>';
* Modeles documents for projects * Modeles documents for projects
*/ */
$dir = DOL_DOCUMENT_ROOT.'/core/modules/project/pdf/'; //$dir = DOL_DOCUMENT_ROOT.'/core/modules/project/pdf/';
print_titre($langs->trans("ProjectsModelModule")); print_titre($langs->trans("ProjectsModelModule"));
@ -323,14 +346,19 @@ print "</tr>\n";
clearstatcache(); clearstatcache();
$handle=opendir($dir);
$var=true; $var=true;
foreach ($dirmodels as $reldir)
{
$dir = dol_buildpath($reldir."core/modules/project/pdf/");
if (is_dir($dir))
{
$handle=opendir($dir);
if (is_resource($handle)) if (is_resource($handle))
{ {
while (($file = readdir($handle))!==false) while (($file = readdir($handle))!==false)
{ {
if (preg_match('/\.modules\.php$/i',$file) && substr($file,0,4) == 'pdf_') if (substr($file, dol_strlen($file) -12) == '.modules.php' && substr($file,0,4) == 'pdf_')
{ {
$name = substr($file, 4, dol_strlen($file) -16); $name = substr($file, 4, dol_strlen($file) -16);
$classname = substr($file, 0, dol_strlen($file) -12); $classname = substr($file, 0, dol_strlen($file) -12);
@ -394,6 +422,8 @@ if (is_resource($handle))
} }
closedir($handle); closedir($handle);
} }
}
}
print '</table><br/>'; print '</table><br/>';