2004-10-19 22:24:10 +00:00
|
|
|
<?php
|
2005-11-11 20:11:57 +00:00
|
|
|
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
2012-01-05 07:49:48 +00:00
|
|
|
* Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
|
2012-12-30 14:13:49 +00:00
|
|
|
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
|
2012-01-03 15:42:20 +00:00
|
|
|
* Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
|
2003-06-19 12:39:06 +00:00
|
|
|
*
|
|
|
|
|
* 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
|
2013-01-16 14:36:08 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2003-06-19 12:39:06 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2011-07-31 23:24:38 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2003-06-19 12:39:06 +00:00
|
|
|
* or see http://www.gnu.org/
|
|
|
|
|
*/
|
|
|
|
|
|
2006-06-12 22:20:24 +00:00
|
|
|
/**
|
2011-10-24 12:11:49 +00:00
|
|
|
* \file htdocs/core/modules/propale/modules_propale.php
|
2010-03-01 18:12:38 +00:00
|
|
|
* \ingroup propale
|
2011-03-09 15:34:57 +00:00
|
|
|
* \brief Fichier contenant la classe mere de generation des propales en PDF
|
2010-03-01 18:12:38 +00:00
|
|
|
* et la classe mere de numerotation des propales
|
2009-10-04 17:18:09 +00:00
|
|
|
*/
|
2004-08-15 17:33:05 +00:00
|
|
|
|
2012-08-22 21:11:24 +00:00
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/class/commondocgenerator.class.php';
|
|
|
|
|
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; // Requis car utilise dans les classes qui heritent
|
2005-09-03 15:14:34 +00:00
|
|
|
|
2004-08-15 17:33:05 +00:00
|
|
|
|
2005-08-22 19:09:45 +00:00
|
|
|
/**
|
2012-02-08 12:43:49 +00:00
|
|
|
* Classe mere des modeles de propale
|
2009-10-04 17:18:09 +00:00
|
|
|
*/
|
2011-08-27 15:40:08 +00:00
|
|
|
abstract class ModelePDFPropales extends CommonDocGenerator
|
2004-08-15 17:33:05 +00:00
|
|
|
{
|
2009-10-04 17:18:09 +00:00
|
|
|
var $error='';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2012-02-08 12:43:49 +00:00
|
|
|
* Return list of active generation modules
|
|
|
|
|
*
|
2012-03-13 08:38:00 +00:00
|
|
|
* @param DoliDB $db Database handler
|
|
|
|
|
* @param string $maxfilenamelength Max length of value to show
|
|
|
|
|
* @return array List of templates
|
2009-10-04 17:18:09 +00:00
|
|
|
*/
|
2012-03-23 17:19:50 +00:00
|
|
|
static function liste_modeles($db,$maxfilenamelength=0)
|
2009-10-04 17:18:09 +00:00
|
|
|
{
|
|
|
|
|
global $conf;
|
|
|
|
|
|
|
|
|
|
$type='propal';
|
|
|
|
|
$liste=array();
|
|
|
|
|
|
2012-08-23 00:04:35 +00:00
|
|
|
include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
|
2012-03-13 08:38:00 +00:00
|
|
|
$liste=getListOfModels($db,$type,$maxfilenamelength);
|
2009-10-04 17:18:09 +00:00
|
|
|
|
|
|
|
|
return $liste;
|
|
|
|
|
}
|
2004-08-15 17:33:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-08-23 19:31:25 +00:00
|
|
|
/**
|
2012-02-08 12:43:49 +00:00
|
|
|
* Classe mere des modeles de numerotation des references de propales
|
2009-10-04 17:18:09 +00:00
|
|
|
*/
|
2011-09-29 08:08:26 +00:00
|
|
|
abstract class ModeleNumRefPropales
|
2004-08-15 17:33:05 +00:00
|
|
|
{
|
2009-10-04 17:18:09 +00:00
|
|
|
var $error='';
|
2004-08-15 17:33:05 +00:00
|
|
|
|
2012-02-08 12:43:49 +00:00
|
|
|
/**
|
|
|
|
|
* Return if a module can be used or not
|
|
|
|
|
*
|
|
|
|
|
* @return boolean true if module can be used
|
2009-10-04 17:18:09 +00:00
|
|
|
*/
|
2008-09-04 23:44:36 +00:00
|
|
|
function isEnabled()
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-08 12:43:49 +00:00
|
|
|
/**
|
|
|
|
|
* Renvoi la description par defaut du modele de numerotation
|
|
|
|
|
*
|
|
|
|
|
* @return string Texte descripif
|
2009-10-04 17:18:09 +00:00
|
|
|
*/
|
|
|
|
|
function info()
|
|
|
|
|
{
|
|
|
|
|
global $langs;
|
|
|
|
|
$langs->load("propale");
|
|
|
|
|
return $langs->trans("NoDescription");
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-08 12:43:49 +00:00
|
|
|
/**
|
|
|
|
|
* Renvoi un exemple de numerotation
|
|
|
|
|
*
|
|
|
|
|
* @return string Example
|
2009-10-04 17:18:09 +00:00
|
|
|
*/
|
|
|
|
|
function getExample()
|
|
|
|
|
{
|
|
|
|
|
global $langs;
|
|
|
|
|
$langs->load("propale");
|
|
|
|
|
return $langs->trans("NoExample");
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-08 12:43:49 +00:00
|
|
|
/**
|
|
|
|
|
* Test si les numeros deja en vigueur dans la base ne provoquent pas de
|
|
|
|
|
* de conflits qui empechera cette numerotation de fonctionner.
|
|
|
|
|
*
|
|
|
|
|
* @return boolean false si conflit, true si ok
|
2009-10-04 17:18:09 +00:00
|
|
|
*/
|
|
|
|
|
function canBeActivated()
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-08 12:43:49 +00:00
|
|
|
/**
|
|
|
|
|
* Renvoi prochaine valeur attribuee
|
|
|
|
|
*
|
2012-03-23 16:18:33 +00:00
|
|
|
* @param Societe $objsoc Object third party
|
|
|
|
|
* @param Propal $propal Object commercial proposal
|
|
|
|
|
* @return string Valeur
|
2009-10-04 17:18:09 +00:00
|
|
|
*/
|
2012-03-23 16:18:33 +00:00
|
|
|
function getNextValue($objsoc,$propal)
|
2009-10-04 17:18:09 +00:00
|
|
|
{
|
|
|
|
|
global $langs;
|
|
|
|
|
return $langs->trans("NotAvailable");
|
|
|
|
|
}
|
2006-06-12 22:20:24 +00:00
|
|
|
|
2012-02-08 12:43:49 +00:00
|
|
|
/**
|
|
|
|
|
* Renvoi version du module numerotation
|
|
|
|
|
*
|
|
|
|
|
* @return string Valeur
|
2009-10-04 17:18:09 +00:00
|
|
|
*/
|
2007-09-11 22:01:18 +00:00
|
|
|
function getVersion()
|
|
|
|
|
{
|
|
|
|
|
global $langs;
|
|
|
|
|
$langs->load("admin");
|
|
|
|
|
|
|
|
|
|
if ($this->version == 'development') return $langs->trans("VersionDevelopment");
|
|
|
|
|
if ($this->version == 'experimental') return $langs->trans("VersionExperimental");
|
|
|
|
|
if ($this->version == 'dolibarr') return DOL_VERSION;
|
|
|
|
|
return $langs->trans("NotAvailable");
|
2008-03-05 22:49:23 +00:00
|
|
|
}
|
2004-08-15 17:33:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-08-22 19:09:45 +00:00
|
|
|
/**
|
2011-12-05 18:41:38 +00:00
|
|
|
* Create a document onto disk according to template module.
|
2011-09-12 17:08:02 +00:00
|
|
|
*
|
|
|
|
|
* @param DoliDB $db Database handler
|
2013-11-07 20:23:29 +00:00
|
|
|
* @param object $object Object proposal
|
2011-09-12 17:08:02 +00:00
|
|
|
* @param string $modele Force model to use ('' to not force)
|
|
|
|
|
* @param Translate $outputlangs Object langs to use for output
|
|
|
|
|
* @param int $hidedetails Hide details of lines
|
|
|
|
|
* @param int $hidedesc Hide description
|
|
|
|
|
* @param int $hideref Hide ref
|
|
|
|
|
* @return int 0 if KO, 1 if OK
|
2009-10-04 17:18:09 +00:00
|
|
|
*/
|
2013-01-26 09:35:30 +00:00
|
|
|
function propale_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
|
2003-06-19 12:39:06 +00:00
|
|
|
{
|
2011-07-04 10:35:48 +00:00
|
|
|
global $conf,$user,$langs;
|
2006-03-21 23:47:01 +00:00
|
|
|
$langs->load("propale");
|
2003-06-19 12:39:06 +00:00
|
|
|
|
2011-12-05 18:41:38 +00:00
|
|
|
$error=0;
|
2012-01-04 01:04:55 +00:00
|
|
|
|
2011-04-13 13:33:02 +00:00
|
|
|
$srctemplatepath='';
|
2006-03-21 23:47:01 +00:00
|
|
|
|
2011-10-17 12:45:31 +00:00
|
|
|
// Positionne le modele sur le nom du modele a utiliser
|
|
|
|
|
if (! dol_strlen($modele))
|
|
|
|
|
{
|
|
|
|
|
if (! empty($conf->global->PROPALE_ADDON_PDF))
|
|
|
|
|
{
|
|
|
|
|
$modele = $conf->global->PROPALE_ADDON_PDF;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$modele = 'azur';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-03 15:42:20 +00:00
|
|
|
// 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];
|
|
|
|
|
}
|
2012-02-29 19:07:17 +00:00
|
|
|
|
|
|
|
|
// Search template files
|
|
|
|
|
$file=''; $classname=''; $filefound=0;
|
2012-03-01 08:24:45 +00:00
|
|
|
$dirmodels=array('/');
|
|
|
|
|
if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']);
|
2012-02-29 19:07:17 +00:00
|
|
|
foreach($dirmodels as $reldir)
|
|
|
|
|
{
|
2012-02-29 17:18:24 +00:00
|
|
|
foreach(array('doc','pdf') as $prefix)
|
|
|
|
|
{
|
2012-02-29 19:07:17 +00:00
|
|
|
$file = $prefix."_".$modele.".modules.php";
|
|
|
|
|
|
2012-02-29 17:18:24 +00:00
|
|
|
// On verifie l'emplacement du modele
|
2012-02-29 19:07:17 +00:00
|
|
|
$file=dol_buildpath($reldir."core/modules/propale/doc/".$file,0);
|
2012-02-29 17:18:24 +00:00
|
|
|
if (file_exists($file))
|
|
|
|
|
{
|
|
|
|
|
$filefound=1;
|
|
|
|
|
$classname=$prefix.'_'.$modele;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ($filefound) break;
|
|
|
|
|
}
|
2012-01-03 15:42:20 +00:00
|
|
|
|
|
|
|
|
// Charge le modele
|
|
|
|
|
if ($filefound)
|
|
|
|
|
{
|
2012-08-22 21:11:24 +00:00
|
|
|
require_once $file;
|
2012-01-03 15:42:20 +00:00
|
|
|
|
|
|
|
|
$obj = new $classname($db);
|
2012-02-07 17:48:50 +00:00
|
|
|
//$obj->message = $message;
|
2012-01-03 15:42:20 +00:00
|
|
|
|
|
|
|
|
// 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;
|
2013-01-26 09:35:30 +00:00
|
|
|
if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0)
|
2012-01-03 15:42:20 +00:00
|
|
|
{
|
|
|
|
|
$outputlangs->charset_output=$sav_charset_output;
|
|
|
|
|
|
|
|
|
|
// We delete old preview
|
2012-08-22 21:11:24 +00:00
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
2012-01-03 15:42:20 +00:00
|
|
|
dol_delete_preview($object);
|
|
|
|
|
|
|
|
|
|
// Success in building document. We build meta file.
|
|
|
|
|
dol_meta_create($object);
|
|
|
|
|
|
|
|
|
|
// Appel des triggers
|
2012-08-23 00:04:35 +00:00
|
|
|
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
|
2012-01-03 15:42:20 +00:00
|
|
|
$interface=new Interfaces($db);
|
|
|
|
|
$result=$interface->run_triggers('PROPAL_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,"propal_pdf_create Error: ".$obj->error);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-01-06 09:19:07 +00:00
|
|
|
dol_print_error('',$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file));
|
2012-01-03 15:42:20 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
2003-06-19 12:39:06 +00:00
|
|
|
}
|
2006-03-21 23:47:01 +00:00
|
|
|
|
2003-06-19 12:39:06 +00:00
|
|
|
?>
|