2005-11-11 22:36:56 +00:00
< ? php
2012-07-11 08:14:56 +00:00
/* Copyright ( C ) 2003 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2005 - 2006 Laurent Destailleur < eldy @ users . sourceforge . net >
2012-12-30 14:13:49 +00:00
* Copyright ( C ) 2012 Regis Houssin < regis . houssin @ capnetworks . com >
2012-12-29 00:13:31 +00:00
* Copyright ( C ) 2012 Marcos García < marcosgdf @ gmail . com >
2005-11-11 22:36:56 +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
2005-11-11 22:36:56 +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 />.
2005-11-11 22:36:56 +00:00
*/
/**
2011-10-24 12:11:49 +00:00
* \file htdocs / core / modules / dons / html_cerfafr . modules . php
2011-08-27 16:15:06 +00:00
* \ingroup don
* \brief Formulaire de don
*/
2012-08-22 21:11:24 +00:00
require_once DOL_DOCUMENT_ROOT . '/core/modules/dons/modules_don.php' ;
require_once DOL_DOCUMENT_ROOT . '/compta/dons/class/don.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php' ;
2005-11-11 22:36:56 +00:00
/**
2012-02-16 17:39:22 +00:00
* Class to generate document for subscriptions
*/
2005-11-11 22:36:56 +00:00
class html_cerfafr extends ModeleDon
{
/**
2012-02-16 17:39:22 +00:00
* Constructor
*
* @ param DoliDb $db Database handler
*/
2012-07-30 15:17:33 +00:00
function __construct ( $db )
2005-11-11 22:36:56 +00:00
{
global $conf , $langs ;
$this -> db = $db ;
$this -> name = " cerfafr " ;
2010-06-05 14:13:13 +00:00
$this -> description = $langs -> trans ( 'DonationsReceiptModel' );
2006-08-20 23:04:24 +00:00
// Dimension page pour format A4
$this -> type = 'html' ;
2005-11-11 22:36:56 +00:00
}
2012-02-16 17:39:22 +00:00
/**
* Return if a module can be used or not
2012-07-11 08:14:56 +00:00
*
2012-02-16 17:39:22 +00:00
* @ return boolean true if module can be used
*/
2008-10-29 21:26:59 +00:00
function isEnabled ()
{
return true ;
}
2009-02-10 22:07:31 +00:00
2005-11-11 22:36:56 +00:00
/**
2010-11-11 01:09:41 +00:00
* Write the object to document file to disk
2012-07-11 08:14:56 +00:00
*
2012-02-16 17:39:22 +00:00
* @ param Don $don Donation object
* @ param Translate $outputlangs Lang object for output language
* @ return int > 0 if OK , < 0 if KO
2010-11-11 01:09:41 +00:00
*/
2008-10-29 19:49:10 +00:00
function write_file ( $don , $outputlangs )
2005-11-11 22:36:56 +00:00
{
2008-10-29 19:49:10 +00:00
global $user , $conf , $langs , $mysoc ;
2012-03-23 17:19:50 +00:00
$now = dol_now ();
2012-07-11 08:14:56 +00:00
$id = ( ! is_object ( $don ) ? $don : '' );
2009-02-10 22:07:31 +00:00
2008-10-29 19:49:10 +00:00
if ( ! is_object ( $outputlangs )) $outputlangs = $langs ;
2009-02-10 22:07:31 +00:00
2009-02-13 23:59:43 +00:00
$outputlangs -> load ( " main " );
$outputlangs -> load ( " dict " );
$outputlangs -> load ( " companies " );
$outputlangs -> load ( " bills " );
$outputlangs -> load ( " products " );
2012-08-27 17:11:44 +00:00
$outputlangs -> load ( " donations " );
2009-04-29 18:02:50 +00:00
2012-07-11 08:14:56 +00:00
if ( ! empty ( $conf -> don -> dir_output ))
2005-11-11 22:36:56 +00:00
{
2009-02-10 22:07:31 +00:00
// Definition de l'objet $don (pour compatibilite ascendante)
2006-08-20 23:04:24 +00:00
if ( ! is_object ( $don ))
{
$don = new Don ( $this -> db );
$ret = $don -> fetch ( $id );
2012-07-11 08:14:56 +00:00
$id = $don -> id ;
2006-08-20 23:04:24 +00:00
}
2009-02-10 22:07:31 +00:00
// Definition de $dir et $file
2012-07-11 08:14:56 +00:00
if ( ! empty ( $don -> specimen ))
2006-08-20 23:04:24 +00:00
{
$dir = $conf -> don -> dir_output ;
$file = $dir . " /SPECIMEN.html " ;
}
else
{
2009-04-29 18:02:50 +00:00
$donref = dol_sanitizeFileName ( $don -> ref );
2006-09-02 20:53:20 +00:00
$dir = $conf -> don -> dir_output . " / " . get_exdir ( $donref , 2 );
2006-08-20 23:04:24 +00:00
$file = $dir . " / " . $donref . " .html " ;
}
2009-02-10 22:07:31 +00:00
2006-08-20 23:04:24 +00:00
if ( ! file_exists ( $dir ))
{
2012-02-19 17:34:22 +00:00
if ( dol_mkdir ( $dir ) < 0 )
2006-08-20 23:04:24 +00:00
{
$this -> error = $langs -> trans ( " ErrorCanNotCreateDir " , $dir );
return - 1 ;
}
}
2009-02-10 22:07:31 +00:00
2006-08-20 23:04:24 +00:00
if ( file_exists ( $dir ))
2005-11-11 22:36:56 +00:00
{
2012-12-29 00:13:31 +00:00
$formclass = new Form ( $this -> db );
//This is not the proper way to do it but $formclass->form_modes_reglement
//prints the translation instead of returning it
if ( $don -> modepaiementid )
{
$formclass -> load_cache_types_paiements ();
$paymentmode = $formclass -> cache_types_paiements [ $don -> modepaiementid ][ 'label' ];
}
else $paymentmode = '' ;
2006-08-20 23:04:24 +00:00
// Defini contenu
2011-10-24 12:11:49 +00:00
$donmodel = DOL_DOCUMENT_ROOT . " /core/modules/dons/html_cerfafr.html " ;
2011-11-08 09:18:45 +00:00
$form = implode ( '' , file ( $donmodel ));
2012-08-28 07:58:15 +00:00
$form = str_replace ( '__REF__' , $don -> id , $form );
2011-11-08 09:18:45 +00:00
$form = str_replace ( '__DATE__' , dol_print_date ( $don -> date , 'day' , false , $outputlangs ), $form );
2012-07-11 08:14:56 +00:00
//$form = str_replace('__IP__',$user->ip,$form); // TODO $user->ip not exist
2011-11-08 09:18:45 +00:00
$form = str_replace ( '__AMOUNT__' , $don -> amount , $form );
2011-11-23 13:55:36 +00:00
$form = str_replace ( '__CURRENCY__' , $outputlangs -> transnoentitiesnoconv ( " Currency " . $conf -> currency ), $form );
$form = str_replace ( '__CURRENCYCODE__' , $conf -> currency , $form );
2011-11-08 09:18:45 +00:00
$form = str_replace ( '__MAIN_INFO_SOCIETE_NOM__' , $mysoc -> name , $form );
2013-02-22 08:41:56 +00:00
$form = str_replace ( '__MAIN_INFO_SOCIETE_ADDRESS__' , $mysoc -> address , $form );
2013-02-24 16:08:52 +00:00
$form = str_replace ( '__MAIN_INFO_SOCIETE_ZIP__' , $mysoc -> zip , $form );
2013-02-22 16:11:53 +00:00
$form = str_replace ( '__MAIN_INFO_SOCIETE_TOWN__' , $mysoc -> town , $form );
2013-11-10 05:52:20 +00:00
$form = str_replace ( '__DONATOR_FIRSTNAME__' , $don -> firstname , $form );
$form = str_replace ( '__DONATOR_LASTNAME__' , $don -> lastname , $form );
2013-02-15 18:26:09 +00:00
$form = str_replace ( '__DONATOR_ADDRESS__' , $don -> address , $form );
2013-02-24 16:08:52 +00:00
$form = str_replace ( '__DONATOR_ZIP__' , $don -> zip , $form );
2013-02-22 16:11:53 +00:00
$form = str_replace ( '__DONATOR_TOWN__' , $don -> town , $form );
2012-12-29 00:13:31 +00:00
$form = str_replace ( '__PAYMENTMODE_LIB__ ' , $paymentmode , $form );
2011-11-08 09:18:45 +00:00
$form = str_replace ( '__NOW__' , dol_print_date ( $now , '' , false , $outputlangs ), $form );
2012-08-26 16:01:29 +00:00
$form = str_replace ( '__DonationRef__' , $outputlangs -> trans ( " DonationRef " ), $form );
$form = str_replace ( '__DonationReceipt__' , $outputlangs -> trans ( " DonationReceipt " ), $form );
$form = str_replace ( '__DonationRecipient__' , $outputlangs -> trans ( " DonationRecipient " ), $form );
2012-08-28 22:29:47 +00:00
$form = str_replace ( '__DatePayment__' , $outputlangs -> trans ( " DatePayment " ), $form );
$form = str_replace ( '__PaymentMode__' , $outputlangs -> trans ( " PaymentMode " ), $form );
2012-08-26 16:01:29 +00:00
$form = str_replace ( '__Name__' , $outputlangs -> trans ( " Name " ), $form );
2012-08-27 17:11:44 +00:00
$form = str_replace ( '__Address__' , $outputlangs -> trans ( " Address " ), $form );
$form = str_replace ( '__Zip__' , $outputlangs -> trans ( " Zip " ), $form );
$form = str_replace ( '__Town__' , $outputlangs -> trans ( " Town " ), $form );
$form = str_replace ( '__Donor__' , $outputlangs -> trans ( " Donor " ), $form );
$form = str_replace ( '__Date__' , $outputlangs -> trans ( " Date " ), $form );
$form = str_replace ( '__Signature__' , $outputlangs -> trans ( " Signature " ), $form );
2012-08-26 16:01:29 +00:00
$form = str_replace ( '__ThankYou__' , $outputlangs -> trans ( " ThankYou " ), $form );
$form = str_replace ( '__IConfirmDonationReception__' , $outputlangs -> trans ( " IConfirmDonationReception " ), $form );
$frencharticle = '' ;
if ( preg_match ( '/fr/i' , $outputlangs -> defaultlang )) $frencharticle = '<font size="+1"><b>(Article 200-5 du Code Général des Impôts)</b></font><br>+ article 238 bis' ;
2012-08-27 17:11:44 +00:00
$form = str_replace ( '__FrenchArticle__' , $frencharticle , $form );
2009-02-10 22:07:31 +00:00
2006-08-20 23:04:24 +00:00
// Sauve fichier sur disque
2009-02-20 22:53:15 +00:00
dol_syslog ( " html_cerfafr::write_file $file " );
2009-02-10 22:07:31 +00:00
$handle = fopen ( $file , " w " );
2011-11-08 09:18:45 +00:00
fwrite ( $handle , $form );
2006-08-20 23:04:24 +00:00
fclose ( $handle );
2009-02-10 22:07:31 +00:00
if ( ! empty ( $conf -> global -> MAIN_UMASK ))
2008-10-21 21:27:20 +00:00
@ chmod ( $file , octdec ( $conf -> global -> MAIN_UMASK ));
2009-02-10 22:07:31 +00:00
2006-08-20 23:04:24 +00:00
return 1 ;
2005-11-11 22:36:56 +00:00
}
2006-08-20 23:04:24 +00:00
else
{
2008-10-29 19:49:10 +00:00
$this -> error = $langs -> trans ( " ErrorCanNotCreateDir " , $dir );
2006-08-20 23:04:24 +00:00
return 0 ;
}
}
else
{
2008-10-29 19:49:10 +00:00
$this -> error = $langs -> trans ( " ErrorConstantNotDefined " , " DON_OUTPUTDIR " );
2006-08-20 23:04:24 +00:00
return 0 ;
}
2008-10-29 19:49:10 +00:00
$this -> error = $langs -> trans ( " ErrorUnknown " );
2006-08-20 23:04:24 +00:00
return 0 ; // Erreur par defaut
2005-11-11 22:36:56 +00:00
}
}
?>