forked from Wavyzz/dolibarr
Merge branch 'oop-pdf' of github.com:marcosgdf/dolibarr into
marcosgdf-oop-pdf Conflicts: htdocs/projet/class/project.class.php
This commit is contained in:
@@ -3505,4 +3505,96 @@ abstract class CommonObject
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Common function for all objects extending CommonObject for generating documents
|
||||
*
|
||||
* @param string $modelspath Relative folder where models are placed
|
||||
* @param string $modele Model to use
|
||||
* @param Translate $outputlangs Language to use
|
||||
* @param int $hidedetails 1 to hide details. 0 by default
|
||||
* @param int $hidedesc 1 to hide product description. 0 by default
|
||||
* @param int $hideref 1 to hide product reference. 0 by default
|
||||
* @return int 1 if OK -1 if not OK
|
||||
*/
|
||||
protected function commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref)
|
||||
{
|
||||
global $conf, $langs;
|
||||
|
||||
$srctemplatepath='';
|
||||
|
||||
// Increase limit for PDF build
|
||||
$err=error_reporting();
|
||||
error_reporting(0);
|
||||
@set_time_limit(120);
|
||||
error_reporting($err);
|
||||
|
||||
// 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.$modelspath.$file,0);
|
||||
if (file_exists($file))
|
||||
{
|
||||
$filefound=1;
|
||||
$classname=$prefix.'_'.$modele;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($filefound) break;
|
||||
}
|
||||
|
||||
// Charge le modele
|
||||
if ($filefound)
|
||||
{
|
||||
require_once $file;
|
||||
|
||||
$obj = new $classname($this->db);
|
||||
//$obj->message = $message;
|
||||
|
||||
// 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($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0)
|
||||
{
|
||||
$outputlangs->charset_output=$sav_charset_output;
|
||||
|
||||
// We delete old preview
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
dol_delete_preview($this);
|
||||
|
||||
// Success in building document. We build meta file.
|
||||
dol_meta_create($this);
|
||||
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$outputlangs->charset_output=$sav_charset_output;
|
||||
dol_print_error($this->db,"Error generating document for ".__CLASS__.". Error: ".$obj->error);
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error('',$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user