2004-10-20 00:24:10 +02:00
|
|
|
|
<?php
|
2005-04-02 22:14:13 +02:00
|
|
|
|
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
2007-09-12 00:01:18 +02:00
|
|
|
|
* Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net>
|
2003-06-11 15:32:01 +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/
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2005-04-02 22:14:13 +02:00
|
|
|
|
/**
|
|
|
|
|
|
\file htdocs/includes/modules/fichinter/modules_fichinter.php
|
2004-08-15 18:38:21 +02:00
|
|
|
|
\ingroup ficheinter
|
|
|
|
|
|
\brief Fichier contenant la classe m<EFBFBD>re de generation des fiches interventions en PDF
|
|
|
|
|
|
et la classe m<EFBFBD>re de num<EFBFBD>rotation des fiches interventions
|
2008-04-05 16:18:13 +02:00
|
|
|
|
\version $Id$
|
2004-08-15 18:38:21 +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');
|
|
|
|
|
|
|
2004-08-15 18:38:21 +02:00
|
|
|
|
|
2005-04-02 22:14:13 +02:00
|
|
|
|
/**
|
|
|
|
|
|
\class ModelePDFFicheinter
|
|
|
|
|
|
\brief Classe m<EFBFBD>re des mod<EFBFBD>les de fiche intervention
|
2004-08-15 18:38:21 +02:00
|
|
|
|
*/
|
|
|
|
|
|
class ModelePDFFicheinter extends FPDF
|
|
|
|
|
|
{
|
|
|
|
|
|
var $error='';
|
|
|
|
|
|
|
2005-08-23 21:31:25 +02:00
|
|
|
|
/**
|
|
|
|
|
|
\brief Constructeur
|
2004-08-15 18:38:21 +02:00
|
|
|
|
*/
|
|
|
|
|
|
function ModelePDFFicheinter()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2005-08-23 21:31:25 +02:00
|
|
|
|
/**
|
|
|
|
|
|
\brief Renvoi le dernier message d'erreur de cr<EFBFBD>ation de fiche intervention
|
|
|
|
|
|
*/
|
2004-08-15 18:38:21 +02:00
|
|
|
|
function pdferror()
|
|
|
|
|
|
{
|
|
|
|
|
|
return $this->error;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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='ficheinter';
|
2005-08-23 21:31:25 +02:00
|
|
|
|
$liste=array();
|
2006-04-29 00:54:02 +02:00
|
|
|
|
$sql ="SELECT nom as id, nom as lib";
|
|
|
|
|
|
$sql.=" FROM ".MAIN_DB_PREFIX."document_model";
|
|
|
|
|
|
$sql.=" WHERE type = '".$type."'";
|
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
|
|
|
|
|
|
{
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
return $liste;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-08-15 18:38:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-08-23 21:31:25 +02:00
|
|
|
|
/**
|
|
|
|
|
|
\class ModeleNumRefFicheinter
|
|
|
|
|
|
\brief Classe m<EFBFBD>re des mod<EFBFBD>les de num<EFBFBD>rotation des r<EFBFBD>f<EFBFBD>rences de fiches d'intervention
|
2004-08-15 18:38:21 +02:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
class ModeleNumRefFicheinter
|
|
|
|
|
|
{
|
|
|
|
|
|
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-04-02 22:14:13 +02:00
|
|
|
|
/** \brief Renvoi la description par defaut du modele de num<EFBFBD>rotation
|
2004-08-15 18:38:21 +02:00
|
|
|
|
* \return string Texte descripif
|
|
|
|
|
|
*/
|
2004-08-15 19:38:54 +02:00
|
|
|
|
function info()
|
2004-08-15 18:38:21 +02:00
|
|
|
|
{
|
|
|
|
|
|
global $langs;
|
|
|
|
|
|
$langs->load("ficheinter");
|
|
|
|
|
|
return $langs->trans("NoDescription");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2005-04-02 22:14:13 +02:00
|
|
|
|
/** \brief Renvoi un exemple de num<EFBFBD>rotation
|
2004-08-15 18:38:21 +02:00
|
|
|
|
* \return string Example
|
|
|
|
|
|
*/
|
|
|
|
|
|
function getExample()
|
|
|
|
|
|
{
|
|
|
|
|
|
global $langs;
|
|
|
|
|
|
$langs->load("ficheinter");
|
|
|
|
|
|
return $langs->trans("NoExample");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2005-11-11 21:11:57 +01: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()
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** \brief Renvoi prochaine valeur attribu<EFBFBD>e
|
|
|
|
|
|
* \return string Valeur
|
|
|
|
|
|
*/
|
|
|
|
|
|
function getNextValue()
|
|
|
|
|
|
{
|
|
|
|
|
|
global $langs;
|
|
|
|
|
|
return $langs->trans("NotAvailable");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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");
|
|
|
|
|
|
}
|
2004-08-15 18:38:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-04-02 22:14:13 +02:00
|
|
|
|
/**
|
2004-08-15 18:38:21 +02:00
|
|
|
|
\brief Cr<EFBFBD>e une fiche intervention sur disque en fonction du mod<EFBFBD>le de FICHEINTER_ADDON_PDF
|
2006-03-22 00:47:01 +01:00
|
|
|
|
\param db objet base de donn<EFBFBD>e
|
2007-11-04 22:21:33 +01:00
|
|
|
|
\param object Object fichinter
|
2006-03-22 00:47:01 +01:00
|
|
|
|
\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 18:38:21 +02:00
|
|
|
|
*/
|
2007-11-04 22:21:33 +01:00
|
|
|
|
function fichinter_create($db, $object, $modele='', $outputlangs='')
|
2003-06-11 15:32:01 +02:00
|
|
|
|
{
|
2006-03-22 00:47:01 +01:00
|
|
|
|
global $conf,$langs;
|
|
|
|
|
|
$langs->load("ficheinter");
|
|
|
|
|
|
|
|
|
|
|
|
$dir = DOL_DOCUMENT_ROOT."/includes/modules/fichinter/";
|
|
|
|
|
|
|
|
|
|
|
|
// Positionne modele sur le nom du modele de facture <20> utiliser
|
|
|
|
|
|
if (! strlen($modele))
|
2004-08-15 18:38:21 +02:00
|
|
|
|
{
|
2006-03-22 00:47:01 +01:00
|
|
|
|
if ($conf->global->FICHEINTER_ADDON_PDF)
|
|
|
|
|
|
{
|
|
|
|
|
|
$modele = $conf->global->FICHEINTER_ADDON_PDF;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2008-07-12 14:45:29 +02:00
|
|
|
|
dolibarr_syslog("Error ".$langs->trans("Error_FICHEINTER_ADDON_PDF_NotDefined"), LOG_ERR);
|
|
|
|
|
|
print "Error ".$langs->trans("Error_FICHEINTER_ADDON_PDF_NotDefined");
|
2006-03-22 00:47:01 +01:00
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
2004-08-15 18:38:21 +02:00
|
|
|
|
}
|
2006-03-22 00:47:01 +01:00
|
|
|
|
|
|
|
|
|
|
// Charge le modele
|
|
|
|
|
|
$file = "pdf_".$modele.".modules.php";
|
|
|
|
|
|
if (file_exists($dir.$file))
|
2004-08-15 18:38:21 +02:00
|
|
|
|
{
|
2006-03-22 00:47:01 +01:00
|
|
|
|
$classname = "pdf_".$modele;
|
|
|
|
|
|
require_once($dir.$file);
|
|
|
|
|
|
|
|
|
|
|
|
$obj = new $classname($db);
|
|
|
|
|
|
|
2008-07-12 14:45:29 +02:00
|
|
|
|
dolibarr_syslog("fichinter_create build PDF", LOG_DEBUG);
|
2007-11-04 22:21:33 +01:00
|
|
|
|
if ($obj->write_file($object,$outputlangs) > 0)
|
2006-03-22 00:47:01 +01:00
|
|
|
|
{
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
dolibarr_print_error($db,$obj->pdferror());
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$dir.$file);
|
|
|
|
|
|
return 0;
|
2004-08-15 18:38:21 +02:00
|
|
|
|
}
|
2003-06-11 15:32:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2007-08-28 09:44:17 +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
|
|
|
|
|
|
\param propalref r<EFBFBD>f<EFBFBD>rence de la propal si besoin
|
|
|
|
|
|
*/
|
|
|
|
|
|
function fichinter_delete_preview($db, $fichinterid, $fichinterref='')
|
|
|
|
|
|
{
|
|
|
|
|
|
global $langs,$conf;
|
|
|
|
|
|
|
|
|
|
|
|
if (!$fichinterref)
|
|
|
|
|
|
{
|
|
|
|
|
|
$fichinter = new Fichinter($db,"",$fichinterid);
|
|
|
|
|
|
$fichinter->fetch($fichinterid);
|
|
|
|
|
|
$fichinterref = $fichinter->ref;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($conf->fichinter->dir_output)
|
|
|
|
|
|
{
|
|
|
|
|
|
$fichinterref = sanitize_string($fichinterref);
|
|
|
|
|
|
$dir = $conf->fichinter->dir_output . "/" . $fichinterref ;
|
|
|
|
|
|
$file = $dir . "/" . $fichinterref . ".pdf.png";
|
|
|
|
|
|
$multiple = $file . ".";
|
|
|
|
|
|
|
|
|
|
|
|
if ( file_exists( $file ) && is_writable( $file ) )
|
|
|
|
|
|
{
|
|
|
|
|
|
if ( ! unlink($file) )
|
|
|
|
|
|
{
|
|
|
|
|
|
$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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-06-11 15:32:01 +02:00
|
|
|
|
?>
|