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>
|
2008-07-11 18:14:57 +02:00
|
|
|
|
* Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
|
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
|
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
* or see http://www.gnu.org/
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2006-06-13 00:20:24 +02:00
|
|
|
|
/**
|
2005-08-22 21:09:45 +02:00
|
|
|
|
\file htdocs/includes/modules/propale/modules_propale.php
|
2004-10-20 00:24:10 +02:00
|
|
|
|
\ingroup propale
|
|
|
|
|
|
\brief Fichier contenant la classe m<EFBFBD>re de generation des propales en PDF
|
2005-08-22 21:09:45 +02:00
|
|
|
|
et la classe m<EFBFBD>re de num<EFBFBD>rotation des propales
|
2008-03-05 23:49:23 +01:00
|
|
|
|
\version $Id$
|
2004-08-15 19:33:05 +02:00
|
|
|
|
*/
|
|
|
|
|
|
|
2008-04-05 16:18:13 +02:00
|
|
|
|
require_once(DOL_DOCUMENT_ROOT.'/lib/functions.lib.php');
|
2007-07-31 01:22:06 +02:00
|
|
|
|
require_once(DOL_DOCUMENT_ROOT.'/includes/fpdf/fpdfi/fpdi_protection.php');
|
2006-08-20 01:00:53 +02:00
|
|
|
|
require_once(DOL_DOCUMENT_ROOT."/compta/bank/account.class.php"); // Requis car utilis<69> dans les classes qui h<>ritent
|
2005-09-03 17:14:34 +02:00
|
|
|
|
|
2004-08-15 19:33:05 +02:00
|
|
|
|
|
2005-08-22 21:09:45 +02:00
|
|
|
|
/**
|
|
|
|
|
|
\class ModelePDFPropales
|
|
|
|
|
|
\brief Classe m<EFBFBD>re des mod<EFBFBD>les de propale
|
2004-08-15 19:33:05 +02:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
class ModelePDFPropales extends FPDF
|
|
|
|
|
|
{
|
2005-08-23 21:31:25 +02:00
|
|
|
|
var $error='';
|
2006-06-13 00:20:24 +02:00
|
|
|
|
|
|
|
|
|
|
/**
|
2005-08-23 21:31:25 +02:00
|
|
|
|
* \brief Renvoi le dernier message d'erreur de cr<EFBFBD>ation de propale
|
|
|
|
|
|
*/
|
|
|
|
|
|
function pdferror()
|
2004-08-15 19:33:05 +02:00
|
|
|
|
{
|
2005-08-23 21:31:25 +02:00
|
|
|
|
return $this->error;
|
|
|
|
|
|
}
|
2006-06-13 00:20:24 +02:00
|
|
|
|
|
|
|
|
|
|
/**
|
2005-08-23 21:31:25 +02:00
|
|
|
|
* \brief Renvoi la liste des mod<EFBFBD>les actifs
|
|
|
|
|
|
*/
|
|
|
|
|
|
function liste_modeles($db)
|
|
|
|
|
|
{
|
2006-04-29 00:54:02 +02:00
|
|
|
|
$type='propal';
|
2005-08-23 21:31:25 +02:00
|
|
|
|
$liste=array();
|
|
|
|
|
|
$sql ="SELECT nom as id, nom as lib";
|
2006-04-29 00:54:02 +02:00
|
|
|
|
$sql.=" FROM ".MAIN_DB_PREFIX."document_model";
|
|
|
|
|
|
$sql.=" WHERE type = '".$type."'";
|
2006-06-13 00:20:24 +02:00
|
|
|
|
|
2005-08-23 21:31:25 +02:00
|
|
|
|
$resql = $db->query($sql);
|
|
|
|
|
|
if ($resql)
|
|
|
|
|
|
{
|
|
|
|
|
|
$num = $db->num_rows($resql);
|
|
|
|
|
|
$i = 0;
|
|
|
|
|
|
while ($i < $num)
|
|
|
|
|
|
{
|
|
|
|
|
|
$row = $db->fetch_row($resql);
|
|
|
|
|
|
$liste[$row[0]]=$row[1];
|
|
|
|
|
|
$i++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2005-08-23 23:44:45 +02:00
|
|
|
|
$this->error=$db->error();
|
2005-08-23 21:31:25 +02:00
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
return $liste;
|
2004-08-15 19:33:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-08-23 21:31:25 +02:00
|
|
|
|
/**
|
|
|
|
|
|
\class ModeleNumRefPropales
|
|
|
|
|
|
\brief Classe m<EFBFBD>re des mod<EFBFBD>les de num<EFBFBD>rotation des r<EFBFBD>f<EFBFBD>rences de propales
|
2004-08-15 19:33:05 +02:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
class ModeleNumRefPropales
|
|
|
|
|
|
{
|
|
|
|
|
|
var $error='';
|
|
|
|
|
|
|
2008-09-05 01:44:36 +02:00
|
|
|
|
/** \brief Return if a module can be used or not
|
|
|
|
|
|
* \return boolean true if module can be used
|
|
|
|
|
|
*/
|
|
|
|
|
|
function isEnabled()
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2005-08-22 21:09:45 +02:00
|
|
|
|
/** \brief Renvoi la description par defaut du modele de num<EFBFBD>rotation
|
2004-08-15 19:33:05 +02:00
|
|
|
|
* \return string Texte descripif
|
|
|
|
|
|
*/
|
2004-08-15 19:38:54 +02:00
|
|
|
|
function info()
|
2004-08-15 19:33:05 +02:00
|
|
|
|
{
|
|
|
|
|
|
global $langs;
|
|
|
|
|
|
$langs->load("propale");
|
|
|
|
|
|
return $langs->trans("NoDescription");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2005-08-22 21:09:45 +02:00
|
|
|
|
/** \brief Renvoi un exemple de num<EFBFBD>rotation
|
2004-08-15 19:33:05 +02:00
|
|
|
|
* \return string Example
|
|
|
|
|
|
*/
|
|
|
|
|
|
function getExample()
|
|
|
|
|
|
{
|
|
|
|
|
|
global $langs;
|
|
|
|
|
|
$langs->load("propale");
|
|
|
|
|
|
return $langs->trans("NoExample");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2005-08-22 21:09:45 +02:00
|
|
|
|
/** \brief Test si les num<EFBFBD>ros d<EFBFBD>j<EFBFBD> en vigueur dans la base ne provoquent pas de
|
|
|
|
|
|
* de conflits qui empechera cette num<EFBFBD>rotation de fonctionner.
|
|
|
|
|
|
* \return boolean false si conflit, true si ok
|
|
|
|
|
|
*/
|
|
|
|
|
|
function canBeActivated()
|
2004-08-15 19:33:05 +02:00
|
|
|
|
{
|
2005-08-22 21:09:45 +02:00
|
|
|
|
return true;
|
2004-08-15 19:33:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2005-11-11 21:11:57 +01:00
|
|
|
|
/** \brief Renvoi prochaine valeur attribu<EFBFBD>e
|
|
|
|
|
|
* \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
|
|
|
|
|
|
* \return string Valeur
|
|
|
|
|
|
*/
|
|
|
|
|
|
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
|
|
|
|
/**
|
2004-08-15 19:33:05 +02:00
|
|
|
|
\brief Cr<EFBFBD>e une propale sur disque en fonction du mod<EFBFBD>le de PROPALE_ADDON_PDF
|
2006-03-22 00:47:01 +01:00
|
|
|
|
\param db objet base de donn<EFBFBD>e
|
|
|
|
|
|
\param id id de la propale <EFBFBD> cr<EFBFBD>er
|
|
|
|
|
|
\param modele force le modele <EFBFBD> utiliser ('' par defaut)
|
|
|
|
|
|
\param outputlangs objet lang a utiliser pour traduction
|
|
|
|
|
|
\return int 0 si KO, 1 si OK
|
2004-08-15 19:33:05 +02:00
|
|
|
|
*/
|
2006-03-22 00:47:01 +01:00
|
|
|
|
function propale_pdf_create($db, $id, $modele='', $outputlangs='')
|
2003-06-19 14:39:06 +02:00
|
|
|
|
{
|
2006-03-22 00:47:01 +01:00
|
|
|
|
global $langs;
|
|
|
|
|
|
$langs->load("propale");
|
2003-06-19 14:39:06 +02:00
|
|
|
|
|
2006-03-22 00:47:01 +01:00
|
|
|
|
$dir = DOL_DOCUMENT_ROOT."/includes/modules/propale/";
|
2006-06-24 19:10:32 +02:00
|
|
|
|
$modelisok=0;
|
2006-03-22 00:47:01 +01:00
|
|
|
|
|
2006-06-24 19:10:32 +02:00
|
|
|
|
// Positionne modele sur le nom du modele de propale <20> utiliser
|
|
|
|
|
|
$file = "pdf_propale_".$modele.".modules.php";
|
|
|
|
|
|
if ($modele && file_exists($dir.$file)) $modelisok=1;
|
|
|
|
|
|
|
|
|
|
|
|
// Si model pas encore bon
|
|
|
|
|
|
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;
|
|
|
|
|
|
$file = "pdf_propale_".$modele.".modules.php";
|
|
|
|
|
|
if (file_exists($dir.$file)) $modelisok=1;
|
2003-07-07 15:44:09 +02:00
|
|
|
|
}
|
2006-03-22 00:47:01 +01:00
|
|
|
|
|
2006-06-24 19:10:32 +02:00
|
|
|
|
// Si model pas encore bon
|
|
|
|
|
|
if (! $modelisok)
|
|
|
|
|
|
{
|
|
|
|
|
|
$liste=array();
|
|
|
|
|
|
$model=new ModelePDFPropales();
|
|
|
|
|
|
$liste=$model->liste_modeles($db);
|
|
|
|
|
|
$modele=key($liste); // Renvoie premiere valeur de cl<63> trouv<75> dans le tableau
|
|
|
|
|
|
$file = "pdf_propale_".$modele.".modules.php";
|
|
|
|
|
|
if (file_exists($dir.$file)) $modelisok=1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-03-22 00:47:01 +01:00
|
|
|
|
// Charge le modele
|
2006-06-24 19:10:32 +02:00
|
|
|
|
if ($modelisok)
|
2003-07-07 15:44:09 +02:00
|
|
|
|
{
|
2006-06-24 22:37:32 +02:00
|
|
|
|
$classname = "pdf_propale_".$modele;
|
2006-03-22 00:47:01 +01:00
|
|
|
|
require_once($dir.$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
|
|
|
|
|
2007-10-22 01:56:56 +02:00
|
|
|
|
if ($obj->write_file($id, $outputlangs) > 0)
|
2006-03-22 00:47:01 +01:00
|
|
|
|
{
|
|
|
|
|
|
// on supprime l'image correspondant au preview
|
|
|
|
|
|
propale_delete_preview($db, $id);
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
dolibarr_syslog("Erreur dans propale_pdf_create");
|
|
|
|
|
|
dolibarr_print_error($db,$obj->pdferror());
|
|
|
|
|
|
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
|
|
|
|
{
|
2006-06-24 19:10:32 +02:00
|
|
|
|
if (! $conf->global->PROPALE_ADDON_PDF)
|
|
|
|
|
|
{
|
|
|
|
|
|
print $langs->trans("Error")." ".$langs->trans("Error_PROPALE_ADDON_PDF_NotDefined");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$dir.$file);
|
|
|
|
|
|
}
|
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
|
|
|
|
/**
|
|
|
|
|
|
\brief Supprime l'image de pr<EFBFBD>visualitation, pour le cas de r<EFBFBD>g<EFBFBD>n<EFBFBD>ration de propal
|
|
|
|
|
|
\param db objet base de donn<EFBFBD>e
|
|
|
|
|
|
\param propalid id de la propal <EFBFBD> effacer
|
2006-06-09 16:58:53 +02:00
|
|
|
|
\param propalref r<EFBFBD>f<EFBFBD>rence de la propal si besoin
|
2005-08-13 17:11:49 +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
|
|
|
|
{
|
2006-06-09 16:58:53 +02:00
|
|
|
|
global $langs,$conf;
|
2005-08-13 17:11:49 +02:00
|
|
|
|
|
2006-06-09 16:58:53 +02:00
|
|
|
|
if (!$propalref)
|
|
|
|
|
|
{
|
|
|
|
|
|
$propal = new Propal($db,"",$propalid);
|
|
|
|
|
|
$propal->fetch($propalid);
|
|
|
|
|
|
$propalref = $propal->ref;
|
|
|
|
|
|
}
|
2006-06-13 00:20:24 +02:00
|
|
|
|
|
2006-06-09 16:58:53 +02:00
|
|
|
|
if ($conf->propal->dir_output)
|
|
|
|
|
|
{
|
2007-08-28 09:44:17 +02:00
|
|
|
|
$propalref = sanitize_string($propalref);
|
2006-06-09 16:58:53 +02:00
|
|
|
|
$dir = $conf->propal->dir_output . "/" . $propalref ;
|
|
|
|
|
|
$file = $dir . "/" . $propalref . ".pdf.png";
|
|
|
|
|
|
$multiple = $file . ".";
|
2006-06-13 00:20:24 +02:00
|
|
|
|
|
2006-06-09 16:58:53 +02:00
|
|
|
|
if ( file_exists( $file ) && is_writable( $file ) )
|
2006-06-09 14:40:33 +02:00
|
|
|
|
{
|
2006-06-09 16:58:53 +02:00
|
|
|
|
if ( ! unlink($file) )
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->error=$langs->trans("ErrorFailedToOpenFile",$file);
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
for ($i = 0; $i < 20; $i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
$preview = $multiple.$i;
|
2006-06-13 00:20:24 +02:00
|
|
|
|
|
2006-06-09 14:40:33 +02:00
|
|
|
|
if ( file_exists( $preview ) && is_writable( $preview ) )
|
|
|
|
|
|
{
|
|
|
|
|
|
if ( ! unlink($preview) )
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->error=$langs->trans("ErrorFailedToOpenFile",$preview);
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2006-06-09 16:58:53 +02:00
|
|
|
|
}
|
2005-08-13 17:11:49 +02:00
|
|
|
|
}
|
2003-06-19 14:39:06 +02:00
|
|
|
|
?>
|