2004-10-20 00:24:10 +02:00
|
|
|
<?php
|
2005-11-11 21:11:57 +01:00
|
|
|
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
2011-08-10 19:40:42 +02:00
|
|
|
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
|
|
|
|
|
* Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
|
2003-06-19 14:39:06 +02: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
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (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-08-01 01:24:38 +02:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2003-06-19 14:39:06 +02:00
|
|
|
* or see http://www.gnu.org/
|
|
|
|
|
*/
|
|
|
|
|
|
2006-06-13 00:20:24 +02:00
|
|
|
/**
|
2010-03-01 19:12:38 +01:00
|
|
|
* \file htdocs/includes/modules/propale/modules_propale.php
|
|
|
|
|
* \ingroup propale
|
2011-03-09 16:34:57 +01:00
|
|
|
* \brief Fichier contenant la classe mere de generation des propales en PDF
|
2010-03-01 19:12:38 +01:00
|
|
|
* et la classe mere de numerotation des propales
|
2009-10-04 19:18:09 +02:00
|
|
|
*/
|
2004-08-15 19:33:05 +02:00
|
|
|
|
2011-08-27 17:40:08 +02:00
|
|
|
require_once(DOL_DOCUMENT_ROOT."/core/class/commondocgenerator.class.php");
|
2010-04-25 14:43:27 +02:00
|
|
|
require_once(DOL_DOCUMENT_ROOT."/compta/bank/class/account.class.php"); // Requis car utilise dans les classes qui heritent
|
2005-09-03 17:14:34 +02:00
|
|
|
|
2004-08-15 19:33:05 +02:00
|
|
|
|
2005-08-22 21:09:45 +02:00
|
|
|
/**
|
2010-02-24 17:25:34 +01:00
|
|
|
* \class ModelePDFPropales
|
|
|
|
|
* \brief Classe mere des modeles de propale
|
2009-10-04 19:18:09 +02:00
|
|
|
*/
|
2011-08-27 17:40:08 +02:00
|
|
|
abstract class ModelePDFPropales extends CommonDocGenerator
|
2004-08-15 19:33:05 +02:00
|
|
|
{
|
2009-10-04 19:18:09 +02:00
|
|
|
var $error='';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2010-09-09 08:32:39 +02:00
|
|
|
* Return list of active generation modules
|
|
|
|
|
* @param $db Database handler
|
2009-10-04 19:18:09 +02:00
|
|
|
*/
|
|
|
|
|
function liste_modeles($db)
|
|
|
|
|
{
|
|
|
|
|
global $conf;
|
|
|
|
|
|
|
|
|
|
$type='propal';
|
|
|
|
|
$liste=array();
|
|
|
|
|
|
2010-02-27 23:53:27 +01:00
|
|
|
include_once(DOL_DOCUMENT_ROOT.'/lib/functions2.lib.php');
|
|
|
|
|
$liste=getListOfModels($db,$type,'');
|
2009-10-04 19:18:09 +02:00
|
|
|
|
|
|
|
|
return $liste;
|
|
|
|
|
}
|
2004-08-15 19:33:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-08-23 21:31:25 +02:00
|
|
|
/**
|
2010-02-27 23:53:27 +01:00
|
|
|
* \class ModeleNumRefPropales
|
|
|
|
|
* \brief Classe mere des modeles de numerotation des references de propales
|
2009-10-04 19:18:09 +02:00
|
|
|
*/
|
2004-08-15 19:33:05 +02:00
|
|
|
class ModeleNumRefPropales
|
|
|
|
|
{
|
2009-10-04 19:18:09 +02:00
|
|
|
var $error='';
|
2004-08-15 19:33:05 +02:00
|
|
|
|
2008-09-05 01:44:36 +02:00
|
|
|
/** \brief Return if a module can be used or not
|
2009-10-04 19:18:09 +02:00
|
|
|
* \return boolean true if module can be used
|
|
|
|
|
*/
|
2008-09-05 01:44:36 +02:00
|
|
|
function isEnabled()
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-04 19:18:09 +02:00
|
|
|
/** \brief Renvoi la description par defaut du modele de numerotation
|
|
|
|
|
* \return string Texte descripif
|
|
|
|
|
*/
|
|
|
|
|
function info()
|
|
|
|
|
{
|
|
|
|
|
global $langs;
|
|
|
|
|
$langs->load("propale");
|
|
|
|
|
return $langs->trans("NoDescription");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \brief Renvoi un exemple de numerotation
|
|
|
|
|
* \return string Example
|
|
|
|
|
*/
|
|
|
|
|
function getExample()
|
|
|
|
|
{
|
|
|
|
|
global $langs;
|
|
|
|
|
$langs->load("propale");
|
|
|
|
|
return $langs->trans("NoExample");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \brief 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
|
|
|
|
|
*/
|
|
|
|
|
function canBeActivated()
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \brief Renvoi prochaine valeur attribuee
|
|
|
|
|
* \return string Valeur
|
|
|
|
|
*/
|
|
|
|
|
function getNextValue()
|
|
|
|
|
{
|
|
|
|
|
global $langs;
|
|
|
|
|
return $langs->trans("NotAvailable");
|
|
|
|
|
}
|
2006-06-13 00:20:24 +02:00
|
|
|
|
2007-09-12 00:01:18 +02:00
|
|
|
/** \brief Renvoi version du module numerotation
|
2009-10-04 19:18:09 +02:00
|
|
|
* \return string Valeur
|
|
|
|
|
*/
|
2007-09-12 00:01:18 +02: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 23:49:23 +01:00
|
|
|
}
|
2004-08-15 19:33:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-08-22 21:09:45 +02:00
|
|
|
/**
|
2011-09-12 19:08:02 +02:00
|
|
|
* Create a document onto disk accordign to template module.
|
|
|
|
|
*
|
|
|
|
|
* @param DoliDB $db Database handler
|
|
|
|
|
* @param Object $object Object proposal
|
|
|
|
|
* @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
|
|
|
|
|
* @param HookManager $hookmanager Hook manager instance
|
|
|
|
|
* @return int 0 if KO, 1 if OK
|
2009-10-04 19:18:09 +02:00
|
|
|
*/
|
2011-08-10 19:40:42 +02:00
|
|
|
function propale_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $hookmanager=false)
|
2003-06-19 14:39:06 +02:00
|
|
|
{
|
2011-07-04 12:35:48 +02:00
|
|
|
global $conf,$user,$langs;
|
2006-03-22 00:47:01 +01:00
|
|
|
$langs->load("propale");
|
2003-06-19 14:39:06 +02:00
|
|
|
|
2011-01-14 20:28:55 +01:00
|
|
|
$dir = "/includes/modules/propale/";
|
2011-04-13 15:33:02 +02:00
|
|
|
$srctemplatepath='';
|
2006-06-24 19:10:32 +02:00
|
|
|
$modelisok=0;
|
2006-03-22 00:47:01 +01:00
|
|
|
|
2009-05-26 14:54:32 +02:00
|
|
|
// Positionne modele sur le nom du modele de propale a utiliser
|
2006-06-24 19:10:32 +02:00
|
|
|
$file = "pdf_propale_".$modele.".modules.php";
|
2011-03-09 16:34:57 +01:00
|
|
|
|
2011-01-14 20:28:55 +01:00
|
|
|
// On verifie l'emplacement du modele
|
|
|
|
|
$file = dol_buildpath($dir.$file);
|
2011-03-09 16:34:57 +01:00
|
|
|
|
2011-01-14 20:28:55 +01:00
|
|
|
if ($modele && file_exists($file)) $modelisok=1;
|
2006-06-24 19:10:32 +02:00
|
|
|
|
2009-10-04 19:18:09 +02:00
|
|
|
// Si model pas encore bon
|
2006-06-24 19:10:32 +02:00
|
|
|
if (! $modelisok)
|
2003-07-07 15:44:09 +02:00
|
|
|
{
|
2006-06-24 19:10:32 +02:00
|
|
|
if ($conf->global->PROPALE_ADDON_PDF) $modele = $conf->global->PROPALE_ADDON_PDF;
|
2009-10-04 19:18:09 +02:00
|
|
|
$file = "pdf_propale_".$modele.".modules.php";
|
2011-01-14 20:28:55 +01:00
|
|
|
// On verifie l'emplacement du modele
|
|
|
|
|
$file = dol_buildpath($dir.$file);
|
|
|
|
|
if (file_exists($file)) $modelisok=1;
|
2003-07-07 15:44:09 +02:00
|
|
|
}
|
2006-03-22 00:47:01 +01:00
|
|
|
|
2009-10-04 19:18:09 +02:00
|
|
|
// Si model pas encore bon
|
2006-06-24 19:10:32 +02:00
|
|
|
if (! $modelisok)
|
|
|
|
|
{
|
2011-08-27 17:40:08 +02:00
|
|
|
$liste=ModelePDFPropales::liste_modeles($db);
|
2009-10-04 19:18:09 +02:00
|
|
|
$modele=key($liste); // Renvoie premiere valeur de cle trouve dans le tableau
|
|
|
|
|
$file = "pdf_propale_".$modele.".modules.php";
|
2011-01-14 20:28:55 +01:00
|
|
|
$file = dol_buildpath($dir.$file);
|
|
|
|
|
if (file_exists($file)) $modelisok=1;
|
2006-06-24 19:10:32 +02:00
|
|
|
}
|
2009-01-28 16:09:37 +01:00
|
|
|
|
2006-06-24 19:10:32 +02:00
|
|
|
|
2006-03-22 00:47:01 +01:00
|
|
|
// Charge le modele
|
2009-10-04 19:18:09 +02:00
|
|
|
if ($modelisok)
|
2003-07-07 15:44:09 +02:00
|
|
|
{
|
2006-06-24 22:37:32 +02:00
|
|
|
$classname = "pdf_propale_".$modele;
|
2011-01-14 20:28:55 +01:00
|
|
|
require_once($file);
|
2003-06-19 14:39:06 +02:00
|
|
|
|
2006-03-22 00:47:01 +01:00
|
|
|
$obj = new $classname($db);
|
2003-06-19 14:39:06 +02:00
|
|
|
|
2008-10-28 21:05:23 +01: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;
|
2011-08-10 19:40:42 +02:00
|
|
|
if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref, $hookmanager) > 0)
|
2006-03-22 00:47:01 +01:00
|
|
|
{
|
2008-10-28 21:05:23 +01:00
|
|
|
$outputlangs->charset_output=$sav_charset_output;
|
2006-03-22 00:47:01 +01:00
|
|
|
// on supprime l'image correspondant au preview
|
2010-09-09 09:26:17 +02:00
|
|
|
propale_delete_preview($db, $object->id);
|
2011-08-11 01:20:55 +02:00
|
|
|
|
2011-07-04 12:35:48 +02:00
|
|
|
// Appel des triggers
|
|
|
|
|
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
|
|
|
|
|
$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
|
2011-08-11 01:20:55 +02:00
|
|
|
|
2006-03-22 00:47:01 +01:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2008-10-28 21:05:23 +01:00
|
|
|
$outputlangs->charset_output=$sav_charset_output;
|
2009-02-20 23:53:15 +01:00
|
|
|
dol_syslog("modules_propale::propale_pdf_create error");
|
2010-02-24 17:25:34 +01:00
|
|
|
dol_print_error($db,$obj->error);
|
2006-03-22 00:47:01 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
2004-08-15 19:33:05 +02:00
|
|
|
}
|
2006-03-22 00:47:01 +01:00
|
|
|
else
|
2004-08-15 19:33:05 +02:00
|
|
|
{
|
2009-10-04 19:18:09 +02:00
|
|
|
if (! $conf->global->PROPALE_ADDON_PDF)
|
|
|
|
|
{
|
2006-06-24 19:10:32 +02:00
|
|
|
print $langs->trans("Error")." ".$langs->trans("Error_PROPALE_ADDON_PDF_NotDefined");
|
2009-10-04 19:18:09 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2011-01-14 20:28:55 +01:00
|
|
|
print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file);
|
2009-10-04 19:18:09 +02:00
|
|
|
}
|
2006-03-22 00:47:01 +01:00
|
|
|
return 0;
|
2004-08-15 19:33:05 +02:00
|
|
|
}
|
2003-06-19 14:39:06 +02:00
|
|
|
}
|
2006-03-22 00:47:01 +01:00
|
|
|
|
2005-08-13 17:11:49 +02:00
|
|
|
/**
|
2011-03-08 12:32:52 +01:00
|
|
|
* Delete preview files
|
2010-09-09 08:32:39 +02:00
|
|
|
* @param db objet base de donnee
|
|
|
|
|
* @param propalid id de la propal a effacer
|
2011-03-08 12:32:52 +01:00
|
|
|
* @param propalref reference de la propal si besoin
|
2009-10-04 19:18:09 +02:00
|
|
|
*/
|
2006-06-09 16:58:53 +02:00
|
|
|
function propale_delete_preview($db, $propalid, $propalref='')
|
2005-08-13 17:11:49 +02:00
|
|
|
{
|
2009-10-04 19:18:09 +02:00
|
|
|
global $langs,$conf;
|
2011-03-09 16:34:57 +01:00
|
|
|
require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
|
2009-10-04 19:18:09 +02:00
|
|
|
|
|
|
|
|
if (!$propalref)
|
|
|
|
|
{
|
|
|
|
|
$propal = new Propal($db,"",$propalid);
|
|
|
|
|
$propal->fetch($propalid);
|
|
|
|
|
$propalref = $propal->ref;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($conf->propale->dir_output)
|
|
|
|
|
{
|
|
|
|
|
$propalref = dol_sanitizeFileName($propalref);
|
|
|
|
|
$dir = $conf->propale->dir_output . "/" . $propalref ;
|
|
|
|
|
$file = $dir . "/" . $propalref . ".pdf.png";
|
|
|
|
|
$multiple = $file . ".";
|
|
|
|
|
|
|
|
|
|
if ( file_exists( $file ) && is_writable( $file ) )
|
|
|
|
|
{
|
|
|
|
|
if ( ! dol_delete_file($file,1) )
|
|
|
|
|
{
|
|
|
|
|
$this->error=$langs->trans("ErrorFailedToOpenFile",$file);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for ($i = 0; $i < 20; $i++)
|
|
|
|
|
{
|
|
|
|
|
$preview = $multiple.$i;
|
|
|
|
|
|
|
|
|
|
if ( file_exists( $preview ) && is_writable( $preview ) )
|
|
|
|
|
{
|
|
|
|
|
if ( ! unlink($preview) )
|
|
|
|
|
{
|
|
|
|
|
$this->error=$langs->trans("ErrorFailedToOpenFile",$preview);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 1;
|
2005-08-13 17:11:49 +02:00
|
|
|
}
|
2003-06-19 14:39:06 +02:00
|
|
|
?>
|