Skip to content

Commit

Permalink
Merge branch 'develop' of ssh://git@github.com/Dolibarr/dolibarr.git …
Browse files Browse the repository at this point in the history
…into develop
  • Loading branch information
eldy committed Mar 25, 2012
2 parents 693d044 + a0675fa commit 7d14ce2
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 27 deletions.
35 changes: 23 additions & 12 deletions htdocs/admin/fichinter.php
Expand Up @@ -6,7 +6,7 @@
* Copyright (C) 2005-2012 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2011 Philippe Grand <philippe.grand@atoo-net.com>
* 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
Expand Down Expand Up @@ -106,18 +106,27 @@
$inter = new Fichinter($db);
$inter->initAsSpecimen();

// Charge le modele
$dir = "/core/modules/fichinter/doc/";
$file = "pdf_".$modele.".modules.php";
$file = dol_buildpath($dir.$file);
if (file_exists($file))
// Search template files
$file=''; $classname=''; $filefound=0;
$dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
foreach($dirmodels as $reldir)
{
$file=dol_buildpath($reldir."core/modules/fichinter/doc/pdf_".$modele.".modules.php",0);
if (file_exists($file))
{
$filefound=1;
$classname = "pdf_".$modele;
break;
}
}

if ($filefound)
{
$classname = "pdf_".$modele;
require_once($file);

$obj = new $classname($db);
$module = new $classname($db);

if ($obj->write_file($inter,$langs) > 0)
if ($module->write_file($inter,$langs) > 0)
{
header("Location: ".DOL_URL_ROOT."/document.php?modulepart=ficheinter&file=SPECIMEN.pdf");
return;
Expand Down Expand Up @@ -219,6 +228,8 @@
* View
*/

$dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);

llxHeader();

$form=new Form($db);
Expand All @@ -242,9 +253,9 @@

clearstatcache();

foreach ($conf->file->dol_document_root as $dirroot)
foreach ($dirmodels as $reldir)
{
$dir = $dirroot . "/core/modules/fichinter/";
$dir = dol_buildpath($reldir."core/modules/fichinter/");

if (is_dir($dir))
{
Expand All @@ -260,7 +271,7 @@
$file = $reg[1];
$classname = substr($file,4);

require_once($dir.$file.".php");
require_once(DOL_DOCUMENT_ROOT ."/core/modules/fichinter/".$file.".php");

$module = new $file;

Expand Down
70 changes: 55 additions & 15 deletions htdocs/core/modules/fichinter/modules_fichinter.php
Expand Up @@ -2,6 +2,7 @@
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2012 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
Expand Down Expand Up @@ -44,7 +45,7 @@ abstract class ModelePDFFicheinter extends CommonDocGenerator
* @param string $maxfilenamelength Max length of value to show
* @return array List of templates
*/
static function liste_modeles($db,$maxfilenamelength=0)
function liste_modeles($db,$maxfilenamelength=0)
{
global $conf;

Expand Down Expand Up @@ -150,14 +151,16 @@ function getVersion()
* @param Translate $outputlangs objet lang a utiliser pour traduction
* @return int 0 if KO, 1 if OK
*/
function fichinter_create($db, $object, $modele='', $outputlangs='')
function fichinter_create($db, $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $hookmanager=false)
{
global $conf,$langs;
$langs->load("ficheinter");

$dir = "/core/modules/fichinter/doc/";
$error=0;

// Positionne modele sur le nom du modele de facture a utiliser
$srctemplatepath='';

// Positionne modele sur le nom du modele de fichinter a utiliser
if (! dol_strlen($modele))
{
if ($conf->global->FICHEINTER_ADDON_PDF)
Expand All @@ -170,33 +173,70 @@ function fichinter_create($db, $object, $modele='', $outputlangs='')
}
}

// Charge le modele
$file = "pdf_".$modele.".modules.php";

// On verifie l'emplacement du modele
$file = dol_buildpath($dir.$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/fichinter/doc/".$file,0);
if (file_exists($file))
{
$filefound=1;
$classname=$prefix.'_'.$modele;
break;
}
}
if ($filefound) break;
}

if (file_exists($file))
// Charge le modele
if ($filefound)
{
$classname = "pdf_".$modele;
require_once($file);

$obj = new $classname($db);

dol_syslog("fichinter_create build PDF", LOG_DEBUG);

// We save charset_output to restore it because write_file can change it if needed for
// output format that does not support UTF8.
$sav_charset_output=$outputlangs->charset_output;
if ($obj->write_file($object,$outputlangs) > 0)
if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref, $hookmanager) > 0)
{
$outputlangs->charset_output=$sav_charset_output;

// We delete old preview
require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
dol_delete_preview($object);

// Success in building document. We build meta file.
dol_meta_create($object);

// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
$interface=new Interfaces($db);
$result=$interface->run_triggers('FICHEINTER_BUILDDOC',$object,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers

return 1;
}
else
{
$outputlangs->charset_output=$sav_charset_output;
dol_print_error($db,$obj->error);
dol_print_error($db,"fichinter_pdf_create Error: ".$obj->error);
return 0;
}
}
Expand Down

0 comments on commit 7d14ce2

Please sign in to comment.