2004-10-19 20:58:50 +02:00
< ? php
2012-11-10 16:08:26 +01:00
/* Copyright ( C ) 2002 - 2003 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2002 - 2003 Jean - Louis Bergamo < jlb @ j1b . org >
* Copyright ( C ) 2004 - 2012 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2004 Sebastien Di Cintio < sdicintio @ ressource - toi . org >
* Copyright ( C ) 2004 Benoit Mortier < benoit . mortier @ opensides . be >
2012-12-30 15:11:07 +01:00
* Copyright ( C ) 2009 - 2012 Regis Houssin < regis . houssin @ capnetworks . com >
2003-09-01 00:05:54 +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
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2003-09-01 00:05:54 +02: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-08-03 02:45:22 +02:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2003-09-01 00:05:54 +02:00
*/
2005-03-05 19:45:40 +01:00
/**
2010-05-12 17:50:59 +02:00
* \file htdocs / adherents / class / adherent . class . php
2009-10-10 18:00:35 +02:00
* \ingroup member
2010-10-28 00:41:40 +02:00
* \brief File of class to manage members of a foundation
2008-11-11 20:32:48 +01:00
*/
2004-07-28 00:46:33 +02:00
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
2006-11-19 19:06:51 +01:00
2004-08-14 14:37:59 +02:00
2006-11-19 18:16:39 +01:00
/**
2012-11-15 14:52:19 +01:00
* Class to manage members of a foundation
2008-11-11 20:32:48 +01:00
*/
2007-11-05 23:37:41 +01:00
class Adherent extends CommonObject
2003-09-01 00:05:54 +02:00
{
2011-09-20 19:19:46 +02:00
public $element = 'member' ;
public $table_element = 'adherent' ;
protected $ismultientitymanaged = 1 ; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
2010-08-29 14:54:39 +02:00
2013-03-30 18:04:33 +01:00
var $error ;
var $errors ;
var $mesgs ;
2010-08-29 14:54:39 +02:00
var $id ;
var $ref ;
var $civilite_id ;
2011-02-26 03:44:33 +01:00
var $firstname ;
var $lastname ;
2010-08-29 14:54:39 +02:00
var $login ;
var $pass ;
var $societe ;
2013-03-09 20:34:38 +01:00
var $company ;
2011-08-20 17:11:31 +02:00
var $address ;
var $zip ;
var $town ;
2010-08-29 14:54:39 +02:00
2011-08-30 00:55:04 +02:00
var $state_id ; // Id of department
var $state_code ; // Code of department
var $state ; // Label of department
2010-08-29 14:54:39 +02:00
2011-08-30 00:55:04 +02:00
var $country_id ;
var $country_code ;
var $country ;
2010-08-29 14:54:39 +02:00
var $email ;
2013-11-04 21:41:36 +01:00
var $skype ;
2010-08-29 14:54:39 +02:00
var $phone ;
var $phone_perso ;
var $phone_mobile ;
var $morphy ;
var $public ;
2011-12-30 14:18:19 +01:00
var $note ; // Private note
2010-08-29 14:54:39 +02:00
var $statut ; // -1:brouillon, 0:resilie, >=1:valide,paye
var $photo ;
var $datec ;
var $datem ;
var $datefin ;
var $datevalid ;
2013-03-13 22:17:03 +01:00
var $birth ;
2010-08-29 14:54:39 +02:00
var $typeid ; // Id type adherent
var $type ; // Libelle type adherent
var $need_subscription ;
var $user_id ;
var $user_login ;
var $fk_soc ;
// Fields loaded by fetch_subscriptions()
var $first_subscription_date ;
var $first_subscription_amount ;
var $last_subscription_date ;
var $last_subscription_amount ;
var $subscriptions = array ();
// var $public;
var $array_options ;
var $oldcopy ; // To contains a clone of this when we need to save old properties of object
/**
2011-09-03 02:19:56 +02:00
* Constructor
*
2011-12-30 14:18:19 +01:00
* @ param DoliDB $db Database handler
2010-08-29 14:54:39 +02:00
*/
2012-07-30 17:17:33 +02:00
function __construct ( $db )
2010-08-29 14:54:39 +02:00
{
2011-12-30 14:18:19 +01:00
$this -> db = $db ;
2010-08-29 14:54:39 +02:00
$this -> statut = - 1 ;
// l'adherent n'est pas public par defaut
$this -> public = 0 ;
// les champs optionnels sont vides
$this -> array_options = array ();
}
/**
* Fonction envoyant un email a l ' adherent avec le texte fourni en parametre .
2011-09-12 19:43:31 +02:00
*
2011-12-28 13:25:05 +01:00
* @ param string $text Content of message ( not html entities encoded )
* @ param string $subject Subject of message
* @ param array $filename_list Array of attached files
* @ param array $mimetype_list Array of mime types of attached files
* @ param array $mimefilename_list Array of public names of attached files
* @ param string $addr_cc Email cc
* @ param string $addr_bcc Email bcc
* @ param int $deliveryreceipt Ask a delivery receipt
* @ param int $msgishtml 1 = String IS already html , 0 = String IS NOT html , - 1 = Unknown need autodetection
* @ param string $errors_to erros to
* @ return int < 0 if KO , > 0 if OK
2010-08-29 14:54:39 +02:00
*/
function send_an_email ( $text , $subject , $filename_list = array (), $mimetype_list = array (), $mimefilename_list = array (), $addr_cc = " " , $addr_bcc = " " , $deliveryreceipt = 0 , $msgishtml =- 1 , $errors_to = '' )
{
global $conf , $langs ;
// Detect if message is HTML
if ( $msgishtml == - 1 )
{
$msgishtml = 0 ;
if ( dol_textishtml ( $text , 1 )) $msgishtml = 1 ;
}
$texttosend = $this -> makeSubstitution ( $text );
$subjecttosend = $this -> makeSubstitution ( $subject );
if ( $msgishtml ) $texttosend = dol_htmlentitiesbr ( $texttosend );
// Envoi mail confirmation
$from = $conf -> email_from ;
2012-09-15 10:01:35 +02:00
if ( ! empty ( $conf -> global -> ADHERENT_MAIL_FROM )) $from = $conf -> global -> ADHERENT_MAIL_FROM ;
2010-08-29 14:54:39 +02:00
2012-08-23 02:04:35 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php' ;
2010-08-29 14:54:39 +02:00
$mailfile = new CMailFile ( $subjecttosend , $this -> email , $from , $texttosend , $filename_list , $mimetype_list , $mimefilename_list , $addr_cc , $addr_bcc , $deliveryreceipt , $msgishtml );
if ( $mailfile -> sendfile ())
{
return 1 ;
}
else
{
$this -> error = $langs -> trans ( " ErrorFailedToSendMail " , $from , $this -> email ) . '. ' . $mailfile -> error ;
return - 1 ;
}
}
/**
* Make substitution
2011-09-12 19:43:31 +02:00
*
2011-12-28 13:25:05 +01:00
* @ param string $text Text to make substitution to
* @ return string Value of input text string with substitutions done
2010-08-29 14:54:39 +02:00
*/
2012-03-31 10:14:45 +02:00
function makeSubstitution ( $text )
{
2012-06-19 21:54:36 +02:00
global $conf , $langs ;
2012-05-09 15:22:09 +02:00
2013-03-13 22:17:03 +01:00
$birthday = dol_print_date ( $this -> birth , 'day' );
2012-05-09 15:22:09 +02:00
2012-03-31 10:14:45 +02:00
$msgishtml = 0 ;
if ( dol_textishtml ( $text , 1 )) $msgishtml = 1 ;
2012-05-09 15:22:09 +02:00
2012-03-31 10:14:45 +02:00
$infos = '' ;
if ( $this -> civilite_id ) $infos .= $langs -> transnoentities ( " UserTitle " ) . " : " . $this -> getCivilityLabel ( 1 ) . " \n " ;
$infos .= $langs -> transnoentities ( " id " ) . " : " . $this -> id . " \n " ;
$infos .= $langs -> transnoentities ( " Lastname " ) . " : " . $this -> lastname . " \n " ;
$infos .= $langs -> transnoentities ( " Firstname " ) . " : " . $this -> firstname . " \n " ;
$infos .= $langs -> transnoentities ( " Company " ) . " : " . $this -> societe . " \n " ;
$infos .= $langs -> transnoentities ( " Address " ) . " : " . $this -> address . " \n " ;
$infos .= $langs -> transnoentities ( " Zip " ) . " : " . $this -> zip . " \n " ;
$infos .= $langs -> transnoentities ( " Town " ) . " : " . $this -> town . " \n " ;
$infos .= $langs -> transnoentities ( " Country " ) . " : " . $this -> country . " \n " ;
$infos .= $langs -> transnoentities ( " EMail " ) . " : " . $this -> email . " \n " ;
2012-06-19 21:54:36 +02:00
if ( empty ( $conf -> global -> ADHERENT_LOGIN_NOT_REQUIRED ))
{
$infos .= $langs -> transnoentities ( " Login " ) . " : " . $this -> login . " \n " ;
$infos .= $langs -> transnoentities ( " Password " ) . " : " . $this -> pass . " \n " ;
}
2012-03-31 10:14:45 +02:00
$infos .= $langs -> transnoentities ( " Birthday " ) . " : " . $birthday . " \n " ;
$infos .= $langs -> transnoentities ( " Photo " ) . " : " . $this -> photo . " \n " ;
$infos .= $langs -> transnoentities ( " Public " ) . " : " . yn ( $this -> public );
2012-05-09 15:22:09 +02:00
2012-03-31 10:14:45 +02:00
// Substitutions
$substitutionarray = array (
'%DOL_MAIN_URL_ROOT%' => DOL_MAIN_URL_ROOT ,
'%ID%' => $msgishtml ? dol_htmlentitiesbr ( $this -> id ) : $this -> id ,
'%CIVILITE%' => $this -> getCivilityLabel ( $msgishtml ? 0 : 1 ),
2012-04-28 16:37:58 +02:00
'%FIRSTNAME%' => $msgishtml ? dol_htmlentitiesbr ( $this -> firstname ) : $this -> firstname ,
'%LASTNAME%' => $msgishtml ? dol_htmlentitiesbr ( $this -> lastname ) : $this -> lastname ,
'%FULLNAME%' => $msgishtml ? dol_htmlentitiesbr ( $this -> getFullName ( $langs )) : $this -> getFullName ( $langs ),
'%COMPANY%' => $msgishtml ? dol_htmlentitiesbr ( $this -> societe ) : $this -> societe ,
'%ADDRESS%' => $msgishtml ? dol_htmlentitiesbr ( $this -> address ) : $this -> address ,
'%ZIP%' => $msgishtml ? dol_htmlentitiesbr ( $this -> zip ) : $this -> zip ,
'%TOWN%' => $msgishtml ? dol_htmlentitiesbr ( $this -> town ) : $this -> town ,
'%COUNTRY%' => $msgishtml ? dol_htmlentitiesbr ( $this -> country ) : $this -> country ,
'%EMAIL%' => $msgishtml ? dol_htmlentitiesbr ( $this -> email ) : $this -> email ,
2013-03-13 22:17:03 +01:00
'%BIRTH%' => $msgishtml ? dol_htmlentitiesbr ( $birthday ) : $birthday ,
2012-04-28 16:37:58 +02:00
'%PHOTO%' => $msgishtml ? dol_htmlentitiesbr ( $this -> photo ) : $this -> photo ,
'%LOGIN%' => $msgishtml ? dol_htmlentitiesbr ( $this -> login ) : $this -> login ,
'%PASSWORD%' => $msgishtml ? dol_htmlentitiesbr ( $this -> pass ) : $this -> pass ,
// For backward compatibility
'%INFOS%' => $msgishtml ? dol_htmlentitiesbr ( $infos ) : $infos ,
2012-03-31 10:14:45 +02:00
'%SOCIETE%' => $msgishtml ? dol_htmlentitiesbr ( $this -> societe ) : $this -> societe ,
2013-03-09 18:55:57 +01:00
'%PRENOM%' => $msgishtml ? dol_htmlentitiesbr ( $this -> firstname ) : $this -> firstname ,
'%NOM%' => $msgishtml ? dol_htmlentitiesbr ( $this -> lastname ) : $this -> lastname ,
'%CP%' => $msgishtml ? dol_htmlentitiesbr ( $this -> zip ) : $this -> zip ,
'%VILLE%' => $msgishtml ? dol_htmlentitiesbr ( $this -> town ) : $this -> town ,
'%PAYS%' => $msgishtml ? dol_htmlentitiesbr ( $this -> country ) : $this -> country ,
2012-03-31 10:14:45 +02:00
);
2012-05-09 15:22:09 +02:00
2012-03-31 10:14:45 +02:00
complete_substitutions_array ( $substitutionarray , $langs );
2012-05-09 15:22:09 +02:00
2012-03-31 10:14:45 +02:00
return make_substitutions ( $text , $substitutionarray );
}
2010-08-29 14:54:39 +02:00
/**
2010-09-19 16:56:22 +02:00
* Renvoie le libelle traduit de la nature d ' un adherent ( physique ou morale )
2011-12-28 13:25:05 +01:00
*
* @ param string $morphy Nature physique ou morale de l ' adherent
* @ return string Label
2010-08-29 14:54:39 +02:00
*/
function getmorphylib ( $morphy = '' )
{
global $langs ;
if ( ! $morphy ) { $morphy = $this -> morphy ; }
if ( $morphy == 'phy' ) { return $langs -> trans ( " Physical " ); }
if ( $morphy == 'mor' ) { return $langs -> trans ( " Moral " ); }
return $morphy ;
}
/**
2011-03-06 14:15:27 +01:00
* Create a member into database
2011-08-30 00:55:04 +02:00
*
2011-12-28 13:25:05 +01:00
* @ param User $user Objet user qui demande la creation
* @ param int $notrigger 1 ne declenche pas les triggers , 0 sinon
* @ return int < 0 if KO , > 0 if OK
2010-08-29 14:54:39 +02:00
*/
function create ( $user , $notrigger = 0 )
{
global $conf , $langs ;
2011-12-01 17:09:01 +01:00
$error = 0 ;
2011-12-28 13:25:05 +01:00
2011-03-06 14:15:27 +01:00
$now = dol_now ();
2013-06-27 16:02:52 +02:00
// Clean parameters
$this -> import_key = trim ( $this -> import_key );
2013-07-07 13:14:32 +02:00
2010-08-29 14:54:39 +02:00
// Check parameters
if ( ! empty ( $conf -> global -> ADHERENT_MAIL_REQUIRED ) && ! isValidEMail ( $this -> email ))
{
$langs -> load ( " errors " );
$this -> error = $langs -> trans ( " ErrorBadEMail " , $this -> email );
return - 1 ;
}
2011-03-06 14:15:27 +01:00
if ( ! $this -> datec ) $this -> datec = $now ;
if ( empty ( $conf -> global -> ADHERENT_LOGIN_NOT_REQUIRED ))
2010-08-29 14:54:39 +02:00
{
2011-03-06 14:15:27 +01:00
if ( empty ( $this -> login ))
{
$this -> error = $langs -> trans ( " ErrorWrongValueForParameterX " , " Login " );
return - 1 ;
}
2010-08-29 14:54:39 +02:00
}
$this -> db -> begin ();
// Insert member
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " adherent " ;
2013-06-27 16:02:52 +02:00
$sql .= " (datec,login,fk_user_author,fk_user_mod,fk_user_valid,morphy,fk_adherent_type,entity,import_key) " ;
2010-08-29 14:54:39 +02:00
$sql .= " VALUES ( " ;
$sql .= " ' " . $this -> db -> idate ( $this -> datec ) . " ' " ;
2011-03-06 14:15:27 +01:00
$sql .= " , " . ( $this -> login ? " ' " . $this -> db -> escape ( $this -> login ) . " ' " : " null " );
2011-07-03 18:55:31 +02:00
$sql .= " , " . ( $user -> id > 0 ? $user -> id : " null " ); // Can be null because member can be createb by a guest or a script
2010-08-29 14:54:39 +02:00
$sql .= " , null, null, ' " . $this -> morphy . " ' " ;
$sql .= " , ' " . $this -> typeid . " ' " ;
$sql .= " , " . $conf -> entity ;
2013-06-27 16:02:52 +02:00
$sql .= " , " . ( ! empty ( $this -> import_key ) ? " ' " . $this -> import_key . " ' " : " null " );
2010-08-29 14:54:39 +02:00
$sql .= " ) " ;
2011-06-19 16:27:06 +02:00
dol_syslog ( get_class ( $this ) . " ::create sql= " . $sql );
2010-08-29 14:54:39 +02:00
$result = $this -> db -> query ( $sql );
if ( $result )
{
$id = $this -> db -> last_insert_id ( MAIN_DB_PREFIX . " adherent " );
if ( $id > 0 )
{
$this -> id = $id ;
2011-07-03 18:55:31 +02:00
$this -> ref = $id ;
2010-08-29 14:54:39 +02:00
// Update minor fields
2012-11-10 16:08:26 +01:00
$result = $this -> update ( $user , 1 , 1 , 0 , 0 , 'add' ); // nosync is 1 to avoid update data of user
2010-08-29 14:54:39 +02:00
if ( $result < 0 )
{
$this -> db -> rollback ();
return - 1 ;
}
// Add link to user
if ( $this -> user_id )
{
// Add link to user
$sql = " UPDATE " . MAIN_DB_PREFIX . " user SET " ;
$sql .= " fk_member = ' " . $this -> id . " ' " ;
$sql .= " WHERE rowid = " . $this -> user_id ;
2011-06-19 16:27:06 +02:00
dol_syslog ( get_class ( $this ) . " ::create sql= " . $sql );
2010-08-29 14:54:39 +02:00
$resql = $this -> db -> query ( $sql );
if ( ! $resql )
{
$this -> error = 'Failed to update user to make link with member' ;
$this -> db -> rollback ();
return - 4 ;
}
}
if ( ! $notrigger )
{
// Appel des triggers
2012-08-23 02:04:35 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php' ;
2010-08-29 14:54:39 +02:00
$interface = new Interfaces ( $this -> db );
$result = $interface -> run_triggers ( 'MEMBER_CREATE' , $this , $user , $langs , $conf );
if ( $result < 0 ) { $error ++ ; $this -> errors = $interface -> errors ; }
// Fin appel triggers
}
2011-09-17 21:49:50 +02:00
if ( count ( $this -> errors ))
2010-08-29 14:54:39 +02:00
{
2011-06-19 16:27:06 +02:00
dol_syslog ( get_class ( $this ) . " ::create " . join ( ',' , $this -> errors ), LOG_ERR );
2010-08-29 14:54:39 +02:00
$this -> db -> rollback ();
return - 3 ;
}
else
{
$this -> db -> commit ();
return $this -> id ;
}
}
else
{
$this -> error = 'Failed to get last insert id' ;
2011-06-19 16:27:06 +02:00
dol_syslog ( get_class ( $this ) . " ::create " . $this -> error , LOG_ERR );
2010-08-29 14:54:39 +02:00
$this -> db -> rollback ();
return - 2 ;
}
}
else
{
$this -> error = $this -> db -> error ();
2011-06-19 16:27:06 +02:00
dol_syslog ( get_class ( $this ) . " ::create " . $this -> error , LOG_ERR );
2010-08-29 14:54:39 +02:00
$this -> db -> rollback ();
return - 1 ;
}
}
/**
2010-09-19 16:56:22 +02:00
* Update a member in database ( standard information and password )
2011-08-30 00:55:04 +02:00
*
2011-12-28 13:25:05 +01:00
* @ param User $user User making update
* @ param int $notrigger 1 = disable trigger UPDATE ( when called by create )
* @ param int $nosyncuser 0 = Synchronize linked user ( standard info ), 1 = Do not synchronize linked user
* @ param int $nosyncuserpass 0 = Synchronize linked user ( password ), 1 = Do not synchronize linked user
* @ param int $nosyncthirdparty 0 = Synchronize linked thirdparty ( standard info ), 1 = Do not synchronize linked thirdparty
2012-11-10 16:08:26 +01:00
* @ param string $action Current action for hookmanager
2011-12-28 13:25:05 +01:00
* @ return int < 0 if KO , > 0 if OK
2010-08-29 14:54:39 +02:00
*/
2012-11-10 16:08:26 +01:00
function update ( $user , $notrigger = 0 , $nosyncuser = 0 , $nosyncuserpass = 0 , $nosyncthirdparty = 0 , $action = 'update' )
2010-08-29 14:54:39 +02:00
{
2013-01-25 19:12:54 +01:00
global $conf , $langs , $hookmanager ;
2010-08-29 14:54:39 +02:00
$nbrowsaffected = 0 ;
$error = 0 ;
2013-05-25 18:01:50 +02:00
dol_syslog ( get_class ( $this ) . " ::update notrigger= " . $notrigger . " , nosyncuser= " . $nosyncuser . " , nosyncuserpass= " . $nosyncuserpass . " nosyncthirdparty= " . $nosyncthirdparty . " , email= " . $this -> email );
2010-08-29 14:54:39 +02:00
2011-05-02 20:21:57 +02:00
// Clean parameters
2013-02-23 11:11:33 +01:00
$this -> lastname = trim ( $this -> lastname ) ? trim ( $this -> lastname ) : trim ( $this -> lastname );
2013-02-23 15:26:39 +01:00
$this -> firstname = trim ( $this -> firstname ) ? trim ( $this -> firstname ) : trim ( $this -> firstname );
2013-02-21 09:35:05 +01:00
$this -> address = ( $this -> address ? $this -> address : $this -> address );
2013-02-24 15:57:02 +01:00
$this -> zip = ( $this -> zip ? $this -> zip : $this -> zip );
2013-02-22 11:32:19 +01:00
$this -> town = ( $this -> town ? $this -> town : $this -> town );
2013-02-25 17:56:41 +01:00
$this -> country_id = ( $this -> country_id > 0 ? $this -> country_id : $this -> country_id );
2013-02-27 11:24:50 +01:00
$this -> state_id = ( $this -> state_id > 0 ? $this -> state_id : $this -> state_id );
2011-12-30 14:18:19 +01:00
if ( ! empty ( $conf -> global -> MAIN_FIRST_TO_UPPER )) $this -> lastname = ucwords ( trim ( $this -> lastname ));
if ( ! empty ( $conf -> global -> MAIN_FIRST_TO_UPPER )) $this -> firstname = ucwords ( trim ( $this -> firstname ));
2011-05-02 20:21:57 +02:00
2010-08-29 14:54:39 +02:00
// Check parameters
if ( ! empty ( $conf -> global -> ADHERENT_MAIL_REQUIRED ) && ! isValidEMail ( $this -> email ))
{
$langs -> load ( " errors " );
$this -> error = $langs -> trans ( " ErrorBadEMail " , $this -> email );
return - 1 ;
}
$this -> db -> begin ();
$sql = " UPDATE " . MAIN_DB_PREFIX . " adherent SET " ;
2013-01-10 12:03:08 +01:00
$sql .= " civilite = " . ( ! is_null ( $this -> civilite_id ) ? " ' " . $this -> civilite_id . " ' " : " null " );
2013-02-23 15:26:39 +01:00
$sql .= " , firstname = " . ( $this -> firstname ? " ' " . $this -> db -> escape ( $this -> firstname ) . " ' " : " null " );
2013-02-23 11:11:33 +01:00
$sql .= " , lastname= " . ( $this -> lastname ? " ' " . $this -> db -> escape ( $this -> lastname ) . " ' " : " null " );
2011-02-24 19:11:12 +01:00
$sql .= " , login= " . ( $this -> login ? " ' " . $this -> db -> escape ( $this -> login ) . " ' " : " null " );
$sql .= " , societe= " . ( $this -> societe ? " ' " . $this -> db -> escape ( $this -> societe ) . " ' " : " null " );
2010-08-29 14:54:39 +02:00
$sql .= " , fk_soc= " . ( $this -> fk_soc > 0 ? " ' " . $this -> fk_soc . " ' " : " null " );
2013-02-15 17:33:07 +01:00
$sql .= " , address= " . ( $this -> address ? " ' " . $this -> db -> escape ( $this -> address ) . " ' " : " null " );
2013-02-25 10:00:09 +01:00
$sql .= " , zip= " . ( $this -> zip ? " ' " . $this -> db -> escape ( $this -> zip ) . " ' " : " null " );
2013-02-22 11:32:19 +01:00
$sql .= " , town= " . ( $this -> town ? " ' " . $this -> db -> escape ( $this -> town ) . " ' " : " null " );
2013-02-27 11:24:50 +01:00
$sql .= " , country= " . ( $this -> country_id > 0 ? " ' " . $this -> country_id . " ' " : " null " );
$sql .= " , state_id= " . ( $this -> state_id > 0 ? " ' " . $this -> state_id . " ' " : " null " );
2011-12-28 13:25:05 +01:00
$sql .= " , email=' " . $this -> email . " ' " ;
2013-11-04 21:41:36 +01:00
$sql .= " , skype=' " . $this -> skype . " ' " ;
2011-02-24 19:11:12 +01:00
$sql .= " , phone= " . ( $this -> phone ? " ' " . $this -> db -> escape ( $this -> phone ) . " ' " : " null " );
$sql .= " , phone_perso= " . ( $this -> phone_perso ? " ' " . $this -> db -> escape ( $this -> phone_perso ) . " ' " : " null " );
$sql .= " , phone_mobile= " . ( $this -> phone_mobile ? " ' " . $this -> db -> escape ( $this -> phone_mobile ) . " ' " : " null " );
$sql .= " , note= " . ( $this -> note ? " ' " . $this -> db -> escape ( $this -> note ) . " ' " : " null " );
2010-08-29 14:54:39 +02:00
$sql .= " , photo= " . ( $this -> photo ? " ' " . $this -> photo . " ' " : " null " );
2011-12-28 13:25:05 +01:00
$sql .= " , public=' " . $this -> public . " ' " ;
2010-08-29 14:54:39 +02:00
$sql .= " , statut= " . $this -> statut ;
$sql .= " , fk_adherent_type= " . $this -> typeid ;
2011-12-28 13:25:05 +01:00
$sql .= " , morphy=' " . $this -> morphy . " ' " ;
2013-03-13 22:17:03 +01:00
$sql .= " , birth= " . ( $this -> birth ? " ' " . $this -> db -> idate ( $this -> birth ) . " ' " : " null " );
2010-08-29 14:54:39 +02:00
if ( $this -> datefin ) $sql .= " , datefin=' " . $this -> db -> idate ( $this -> datefin ) . " ' " ; // Ne doit etre modifie que par effacement cotisation
if ( $this -> datevalid ) $sql .= " , datevalid=' " . $this -> db -> idate ( $this -> datevalid ) . " ' " ; // Ne doit etre modifie que par validation adherent
$sql .= " , fk_user_mod= " . ( $user -> id > 0 ? $user -> id : 'null' ); // Can be null because member can be create by a guest
$sql .= " WHERE rowid = " . $this -> id ;
2011-06-19 16:27:06 +02:00
dol_syslog ( get_class ( $this ) . " ::update update member sql= " . $sql );
2010-08-29 14:54:39 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
2011-12-30 14:18:19 +01:00
unset ( $this -> country_code );
unset ( $this -> country );
unset ( $this -> state_code );
unset ( $this -> state );
$nbrowsaffected += $this -> db -> affected_rows ( $resql );
2011-08-10 02:50:16 +02:00
2011-11-01 23:22:10 +01:00
// Actions on extra fields (by external module)
2012-03-02 14:51:16 +01:00
$hookmanager -> initHooks ( array ( 'memberdao' ));
2011-11-22 14:00:03 +01:00
$parameters = array ( 'id' => $this -> id );
$action = '' ;
2011-08-11 00:47:33 +02:00
$reshook = $hookmanager -> executeHooks ( 'insertExtraFields' , $parameters , $this , $action ); // Note that $action and $object may have been modified by some hooks
2011-08-10 02:50:16 +02:00
if ( empty ( $reshook ))
2010-08-29 14:54:39 +02:00
{
2012-11-09 19:34:05 +01:00
if ( empty ( $conf -> global -> MAIN_EXTRAFIELDS_DISABLED )) // For avoid conflicts if trigger used
2012-11-09 19:23:46 +01:00
{
$result = $this -> insertExtraFields ();
if ( $result < 0 )
{
$error ++ ;
}
}
2010-08-29 14:54:39 +02:00
}
2011-08-10 02:50:16 +02:00
else if ( $reshook < 0 ) $error ++ ;
2010-08-29 14:54:39 +02:00
// Update password
2011-06-24 09:10:55 +02:00
if ( ! $error && $this -> pass )
2010-08-29 14:54:39 +02:00
{
2011-06-19 16:27:06 +02:00
dol_syslog ( get_class ( $this ) . " ::update update password " );
2010-08-29 14:54:39 +02:00
if ( $this -> pass != $this -> pass_indatabase && $this -> pass != $this -> pass_indatabase_crypted )
{
// Si mot de passe saisi et different de celui en base
$result = $this -> setPassword ( $user , $this -> pass , 0 , $notrigger , $nosyncuserpass );
if ( ! $nbrowsaffected ) $nbrowsaffected ++ ;
}
}
2011-08-30 00:55:04 +02:00
// Remove links to user and replace with new one
2011-06-24 09:10:55 +02:00
if ( ! $error )
2010-08-29 14:54:39 +02:00
{
2011-06-24 09:10:55 +02:00
dol_syslog ( get_class ( $this ) . " ::update update link to user " );
$sql = " UPDATE " . MAIN_DB_PREFIX . " user SET fk_member = NULL WHERE fk_member = " . $this -> id ;
2011-06-19 16:27:06 +02:00
dol_syslog ( get_class ( $this ) . " ::update sql= " . $sql , LOG_DEBUG );
2010-08-29 14:54:39 +02:00
$resql = $this -> db -> query ( $sql );
if ( ! $resql ) { $this -> error = $this -> db -> error (); $this -> db -> rollback (); return - 5 ; }
2011-06-24 09:10:55 +02:00
// If there is a user linked to this member
if ( $this -> user_id > 0 )
{
$sql = " UPDATE " . MAIN_DB_PREFIX . " user SET fk_member = " . $this -> id . " WHERE rowid = " . $this -> user_id ;
dol_syslog ( get_class ( $this ) . " ::update sql= " . $sql , LOG_DEBUG );
$resql = $this -> db -> query ( $sql );
if ( ! $resql ) { $this -> error = $this -> db -> error (); $this -> db -> rollback (); return - 5 ; }
}
2010-08-29 14:54:39 +02:00
}
2011-06-24 09:10:55 +02:00
if ( ! $error && $nbrowsaffected ) // If something has change in main data
2010-08-29 14:54:39 +02:00
{
2011-08-30 00:55:04 +02:00
// Update information on linked user if it is an update
2010-08-29 14:54:39 +02:00
if ( $this -> user_id > 0 && ! $nosyncuser )
{
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php' ;
2010-08-29 14:54:39 +02:00
2011-06-19 16:27:06 +02:00
dol_syslog ( get_class ( $this ) . " ::update update linked user " );
2010-08-29 14:54:39 +02:00
$luser = new User ( $this -> db );
$result = $luser -> fetch ( $this -> user_id );
if ( $result >= 0 )
{
$luser -> civilite_id = $this -> civilite_id ;
2012-01-30 10:22:50 +01:00
$luser -> firstname = $this -> firstname ;
$luser -> lastname = $this -> lastname ;
2010-08-29 14:54:39 +02:00
$luser -> login = $this -> user_login ;
$luser -> pass = $this -> pass ;
$luser -> societe_id = $this -> societe ;
$luser -> email = $this -> email ;
2013-11-04 21:41:36 +01:00
$luser -> skype = $this -> skype ;
2010-08-29 14:54:39 +02:00
$luser -> office_phone = $this -> phone ;
$luser -> user_mobile = $this -> phone_mobile ;
$luser -> fk_member = $this -> id ;
$result = $luser -> update ( $user , 0 , 1 , 1 ); // Use nosync to 1 to avoid cyclic updates
if ( $result < 0 )
{
$this -> error = $luser -> error ;
2011-06-19 16:27:06 +02:00
dol_syslog ( get_class ( $this ) . " ::update " . $this -> error , LOG_ERR );
2010-08-29 14:54:39 +02:00
$error ++ ;
}
}
else
{
$this -> error = $luser -> error ;
$error ++ ;
2011-08-30 00:55:04 +02:00
}
}
// Update information on linked thirdparty if it is an update
if ( $this -> fk_soc > 0 && ! $nosyncthirdparty )
{
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php' ;
2011-08-30 00:55:04 +02:00
dol_syslog ( get_class ( $this ) . " ::update update linked thirdparty " );
// This member is linked with a thirdparty, so we also update thirdparty informations
// if this is an update.
$lthirdparty = new Societe ( $this -> db );
$result = $lthirdparty -> fetch ( $this -> fk_soc );
if ( $result >= 0 )
{
$lthirdparty -> address = $this -> address ;
$lthirdparty -> zip = $this -> zip ;
$lthirdparty -> town = $this -> town ;
$lthirdparty -> email = $this -> email ;
2013-11-04 21:41:36 +01:00
$lthirdparty -> skype = $this -> skype ;
2013-09-25 19:58:22 +02:00
$lthirdparty -> phone = $this -> phone ;
2011-08-30 00:55:04 +02:00
$lthirdparty -> state_id = $this -> state_id ;
$lthirdparty -> country_id = $this -> country_id ;
2013-02-25 09:17:38 +01:00
$lthirdparty -> country_id = $this -> country_id ;
2011-08-30 00:55:04 +02:00
//$lthirdparty->phone_mobile=$this->phone_mobile;
$result = $lthirdparty -> update ( $this -> fk_soc , $user , 0 , 1 , 1 , 'update' ); // Use sync to 0 to avoid cyclic updates
if ( $result < 0 )
{
$this -> error = $lthirdparty -> error ;
dol_syslog ( get_class ( $this ) . " ::update " . $this -> error , LOG_ERR );
$error ++ ;
}
}
else
{
$this -> error = $lthirdparty -> error ;
$error ++ ;
2010-08-29 14:54:39 +02:00
}
}
if ( ! $error && ! $notrigger )
{
// Appel des triggers
2012-08-23 02:04:35 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php' ;
2010-08-29 14:54:39 +02:00
$interface = new Interfaces ( $this -> db );
$result = $interface -> run_triggers ( 'MEMBER_MODIFY' , $this , $user , $langs , $conf );
if ( $result < 0 ) { $error ++ ; $this -> errors = $interface -> errors ; }
// Fin appel triggers
}
}
if ( ! $error )
{
$this -> db -> commit ();
2011-06-24 09:10:55 +02:00
return $nbrowsaffected ;
2010-08-29 14:54:39 +02:00
}
else
{
$this -> db -> rollback ();
2011-06-24 09:10:55 +02:00
return - 1 ;
2010-08-29 14:54:39 +02:00
}
}
else
{
$this -> db -> rollback ();
$this -> error = $this -> db -> lasterror ();
2011-06-24 09:10:55 +02:00
dol_syslog ( get_class ( $this ) . " ::Update " . $this -> error , LOG_ERR );
return - 2 ;
2010-08-29 14:54:39 +02:00
}
}
/**
2010-09-19 16:56:22 +02:00
* Update denormalized last subscription date .
* This function is called when we delete a subscription for example .
2011-12-28 13:25:05 +01:00
*
* @ param User $user User making change
* @ return int < 0 if KO , > 0 if OK
2010-08-29 14:54:39 +02:00
*/
function update_end_date ( $user )
{
global $conf , $langs ;
$error = 0 ;
$this -> db -> begin ();
// Search for last subscription id and end date
$sql = " SELECT rowid, datec as dateop, dateadh as datedeb, datef as datefin " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " cotisation " ;
$sql .= " WHERE fk_adherent=' " . $this -> id . " ' " ;
$sql .= " ORDER by dateadh DESC " ; // Sort by start subscription date
2011-06-19 16:27:06 +02:00
dol_syslog ( get_class ( $this ) . " ::update_end_date sql= " . $sql );
2010-08-29 14:54:39 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
$obj = $this -> db -> fetch_object ( $resql );
$dateop = $this -> db -> jdate ( $obj -> dateop );
$datedeb = $this -> db -> jdate ( $obj -> datedeb );
$datefin = $this -> db -> jdate ( $obj -> datefin );
$sql = " UPDATE " . MAIN_DB_PREFIX . " adherent SET " ;
$sql .= " datefin= " . ( $datefin != '' ? " ' " . $this -> db -> idate ( $datefin ) . " ' " : " null " );
$sql .= " WHERE rowid = " . $this -> id ;
2011-06-19 16:27:06 +02:00
dol_syslog ( get_class ( $this ) . " ::update_end_date sql= " . $sql );
2010-08-29 14:54:39 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
$this -> last_subscription_date = $dateop ;
$this -> last_subscription_date_start = $datedeb ;
$this -> last_subscription_date_end = $datefin ;
$this -> datefin = $datefin ;
$this -> db -> commit ();
return 1 ;
}
else
{
$this -> db -> rollback ();
return - 1 ;
}
}
else
{
$this -> error = $this -> db -> lasterror ();
2011-06-19 16:27:06 +02:00
dol_syslog ( get_class ( $this ) . " ::update_end_date " . $this -> error , LOG_ERR );
2010-08-29 14:54:39 +02:00
$this -> db -> rollback ();
return - 1 ;
}
}
/**
2010-09-19 16:56:22 +02:00
* Fonction qui supprime l ' adherent et les donnees associees
2011-12-28 13:25:05 +01:00
*
* @ param int $rowid Id of member to delete
* @ return int < 0 if KO , 0 = nothing to do , > 0 if OK
2010-08-29 14:54:39 +02:00
*/
function delete ( $rowid )
{
global $conf , $langs , $user ;
2011-12-01 17:09:01 +01:00
$result = 0 ;
$error = 0 ;
2012-12-08 14:23:52 +01:00
$errorflag = 0 ;
2011-12-28 13:25:05 +01:00
2013-05-12 15:25:12 +02:00
// Check parameters
if ( empty ( $rowid )) $rowid = $this -> id ;
2010-08-29 14:54:39 +02:00
$this -> db -> begin ();
2012-12-08 14:23:52 +01:00
// Remove category
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " categorie_member WHERE fk_member = " . $rowid ;
2011-06-19 16:27:06 +02:00
dol_syslog ( get_class ( $this ) . " ::delete sql= " . $sql );
2010-08-29 14:54:39 +02:00
$resql = $this -> db -> query ( $sql );
2012-12-08 14:23:52 +01:00
if ( ! $resql )
2010-08-29 14:54:39 +02:00
{
2012-12-08 14:23:52 +01:00
$error ++ ;
$this -> error .= $this -> db -> lasterror ();
$errorflag =- 1 ;
dol_syslog ( get_class ( $this ) . " ::delete erreur " . $errorflag . " " . $this -> error , LOG_ERR );
2012-12-10 19:06:59 +01:00
2012-12-08 14:23:52 +01:00
}
2012-12-10 19:06:59 +01:00
2012-12-08 14:23:52 +01:00
// Remove cotisation
if ( ! $error )
{
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " cotisation WHERE fk_adherent = " . $rowid ;
dol_syslog ( get_class ( $this ) . " ::delete sql= " . $sql );
$resql = $this -> db -> query ( $sql );
if ( ! $resql )
{
$error ++ ;
$this -> error .= $this -> db -> lasterror ();
$errorflag =- 2 ;
dol_syslog ( get_class ( $this ) . " ::delete erreur " . $errorflag . " " . $this -> error , LOG_ERR );
}
}
2012-12-10 19:06:59 +01:00
2012-12-08 14:23:52 +01:00
// Remove linked user
2012-12-10 19:06:59 +01:00
if ( ! $error )
2012-12-08 14:23:52 +01:00
{
$ret = $this -> setUserId ( 0 );
if ( $ret < 0 )
{
$error ++ ;
$this -> error .= $this -> db -> lasterror ();
$errorflag =- 3 ;
dol_syslog ( get_class ( $this ) . " ::delete erreur " . $errorflag . " " . $this -> error , LOG_ERR );
}
}
2012-12-10 19:06:59 +01:00
2012-12-08 14:23:52 +01:00
// Removed extrafields
if ( ! $error )
{
if ( empty ( $conf -> global -> MAIN_EXTRAFIELDS_DISABLED )) // For avoid conflicts if trigger used
{
2012-12-10 19:06:59 +01:00
$result = $this -> deleteExtraFields ();
if ( $result < 0 )
{
2012-12-08 14:23:52 +01:00
$error ++ ;
$errorflag =- 4 ;
dol_syslog ( get_class ( $this ) . " ::delete erreur " . $errorflag . " " . $this -> error , LOG_ERR );
}
}
}
2012-12-10 19:06:59 +01:00
2012-12-08 14:23:52 +01:00
// Remove adherent
if ( ! $error )
{
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " adherent WHERE rowid = " . $rowid ;
dol_syslog ( get_class ( $this ) . " ::delete sql= " . $sql );
$resql = $this -> db -> query ( $sql );
if ( ! $resql )
{
$error ++ ;
$this -> error .= $this -> db -> lasterror ();
$errorflag =- 5 ;
dol_syslog ( get_class ( $this ) . " ::delete erreur " . $errorflag . " " . $this -> error , LOG_ERR );
}
}
2012-12-10 19:06:59 +01:00
2012-12-08 14:23:52 +01:00
if ( ! $error )
{
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php' ;
$interface = new Interfaces ( $this -> db );
$result = $interface -> run_triggers ( 'MEMBER_DELETE' , $this , $user , $langs , $conf );
if ( $result < 0 ) { $error ++ ; $this -> errors = $interface -> errors ;}
// Fin appel triggers
}
2012-12-10 19:06:59 +01:00
2012-12-08 14:23:52 +01:00
if ( ! $error )
{
$this -> db -> commit ();
return 1 ;
2010-08-29 14:54:39 +02:00
}
else
{
2012-12-08 14:23:52 +01:00
$this -> db -> rollback ();
return $errorflag ;
2010-08-29 14:54:39 +02:00
}
}
/**
2010-09-19 16:56:22 +02:00
* Change password of a user
2011-12-28 13:25:05 +01:00
*
* @ param User $user Object user de l ' utilisateur qui fait la modification
* @ param string $password New password ( to generate if empty )
* @ param int $isencrypted 0 ou 1 si il faut crypter le mot de passe en base ( 0 par defaut )
* @ param int $notrigger 1 = Ne declenche pas les triggers
* @ param int $nosyncuser Do not synchronize linked user
* @ return string If OK return clear password , 0 if no change , < 0 if error
2010-08-29 14:54:39 +02:00
*/
function setPassword ( $user , $password = '' , $isencrypted = 0 , $notrigger = 0 , $nosyncuser = 0 )
{
global $conf , $langs ;
$error = 0 ;
2011-06-19 16:27:06 +02:00
dol_syslog ( get_class ( $this ) . " ::setPassword user= " . $user -> id . " password= " . preg_replace ( '/./i' , '*' , $password ) . " isencrypted= " . $isencrypted );
2010-08-29 14:54:39 +02:00
2011-05-01 12:47:56 +02:00
// If new password not provided, we generate one
2010-08-29 14:54:39 +02:00
if ( ! $password )
{
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/security2.lib.php' ;
2012-02-12 17:41:28 +01:00
$password = getRandomPassword ( '' );
2010-08-29 14:54:39 +02:00
}
// Cryptage mot de passe
if ( $isencrypted )
{
2011-09-06 08:53:52 +02:00
// Encryption
$password_indatabase = dol_hash ( $password );
2010-08-29 14:54:39 +02:00
}
else
{
$password_indatabase = $password ;
}
// Mise a jour
2011-02-24 19:11:12 +01:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " adherent SET pass = ' " . $this -> db -> escape ( $password_indatabase ) . " ' " ;
2010-08-29 14:54:39 +02:00
$sql .= " WHERE rowid = " . $this -> id ;
//dol_syslog("Adherent::Password sql=hidden");
2011-06-19 16:27:06 +02:00
dol_syslog ( get_class ( $this ) . " ::setPassword sql= " . $sql );
2010-08-29 14:54:39 +02:00
$result = $this -> db -> query ( $sql );
if ( $result )
{
$nbaffectedrows = $this -> db -> affected_rows ( $result );
if ( $nbaffectedrows )
{
$this -> pass = $password ;
$this -> pass_indatabase = $password_indatabase ;
if ( $this -> user_id && ! $nosyncuser )
{
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php' ;
2010-08-29 14:54:39 +02:00
// This member is linked with a user, so we also update users informations
// if this is an update.
$luser = new User ( $this -> db );
$result = $luser -> fetch ( $this -> user_id );
if ( $result >= 0 )
{
$result = $luser -> setPassword ( $user , $this -> pass , 0 , 0 , 1 );
if ( $result < 0 )
{
$this -> error = $luser -> error ;
2011-06-19 16:27:06 +02:00
dol_syslog ( get_class ( $this ) . " ::setPassword " . $this -> error , LOG_ERR );
2010-08-29 14:54:39 +02:00
$error ++ ;
}
}
else
{
$this -> error = $luser -> error ;
$error ++ ;
}
}
if ( ! $error && ! $notrigger )
{
// Appel des triggers
2012-08-23 02:04:35 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php' ;
2010-08-29 14:54:39 +02:00
$interface = new Interfaces ( $this -> db );
$result = $interface -> run_triggers ( 'MEMBER_NEW_PASSWORD' , $this , $user , $langs , $conf );
if ( $result < 0 ) { $error ++ ; $this -> errors = $interface -> errors ; }
// Fin appel triggers
}
return $this -> pass ;
}
else
{
return 0 ;
}
}
else
{
dol_print_error ( $this -> db );
return - 1 ;
}
}
/**
2010-09-19 16:56:22 +02:00
* Set link to a user
2011-09-12 19:43:31 +02:00
*
* @ param int $userid Id of user to link to
* @ return int 1 = OK , - 1 = KO
2010-08-29 14:54:39 +02:00
*/
function setUserId ( $userid )
{
global $conf , $langs ;
$this -> db -> begin ();
// If user is linked to this member, remove old link to this member
$sql = " UPDATE " . MAIN_DB_PREFIX . " user SET fk_member = NULL WHERE fk_member = " . $this -> id ;
2011-06-19 16:27:06 +02:00
dol_syslog ( get_class ( $this ) . " ::setUserId sql= " . $sql , LOG_DEBUG );
2010-08-29 14:54:39 +02:00
$resql = $this -> db -> query ( $sql );
if ( ! $resql ) { $this -> error = $this -> db -> error (); $this -> db -> rollback (); return - 1 ; }
// Set link to user
if ( $userid > 0 )
{
$sql = " UPDATE " . MAIN_DB_PREFIX . " user SET fk_member = " . $this -> id ;
$sql .= " WHERE rowid = " . $userid ;
2011-06-19 16:27:06 +02:00
dol_syslog ( get_class ( $this ) . " ::setUserId sql= " . $sql , LOG_DEBUG );
2010-08-29 14:54:39 +02:00
$resql = $this -> db -> query ( $sql );
if ( ! $resql ) { $this -> error = $this -> db -> error (); $this -> db -> rollback (); return - 2 ; }
}
$this -> db -> commit ();
return 1 ;
}
/**
2010-09-19 16:56:22 +02:00
* Set link to a third party
2011-09-12 19:43:31 +02:00
*
* @ param int $thirdpartyid Id of user to link to
* @ return int 1 = OK , - 1 = KO
2010-08-29 14:54:39 +02:00
*/
function setThirdPartyId ( $thirdpartyid )
{
global $conf , $langs ;
$this -> db -> begin ();
2013-01-12 15:40:38 +01:00
// Remove link to third party onto any other members
2010-08-29 14:54:39 +02:00
if ( $thirdpartyid > 0 )
{
$sql = " UPDATE " . MAIN_DB_PREFIX . " adherent SET fk_soc = null " ;
$sql .= " WHERE fk_soc = ' " . $thirdpartyid . " ' " ;
$sql .= " AND entity = " . $conf -> entity ;
2011-06-19 16:27:06 +02:00
dol_syslog ( get_class ( $this ) . " ::setThirdPartyId sql= " . $sql );
2010-08-29 14:54:39 +02:00
$resql = $this -> db -> query ( $sql );
}
2013-01-12 15:40:38 +01:00
// Add link to third party for current member
2010-08-29 14:54:39 +02:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " adherent SET fk_soc = " . ( $thirdpartyid > 0 ? $thirdpartyid : 'null' );
$sql .= " WHERE rowid = " . $this -> id ;
2011-06-19 16:27:06 +02:00
dol_syslog ( get_class ( $this ) . " ::setThirdPartyId sql= " . $sql );
2010-08-29 14:54:39 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
$this -> db -> commit ();
return 1 ;
}
else
{
$this -> error = $this -> db -> error ();
2011-06-19 16:27:06 +02:00
dol_syslog ( get_class ( $this ) . " ::setThirdPartyId " . $this -> error , LOG_ERR );
2010-08-29 14:54:39 +02:00
$this -> db -> rollback ();
return - 1 ;
}
}
/**
2011-12-28 13:25:05 +01:00
* Method to load member from its login
*
* @ param string $login login of member
* @ return void
2010-08-29 14:54:39 +02:00
*/
function fetch_login ( $login )
{
global $conf ;
$sql = " SELECT rowid FROM " . MAIN_DB_PREFIX . " adherent " ;
2011-12-28 13:25:05 +01:00
$sql .= " WHERE login=' " . $this -> db -> escape ( $login ) . " ' " ;
2010-08-29 14:54:39 +02:00
$sql .= " AND entity = " . $conf -> entity ;
2011-09-20 11:40:27 +02:00
$resql = $this -> db -> query ( $sql );
2010-08-29 14:54:39 +02:00
if ( $resql )
{
if ( $this -> db -> num_rows ( $resql ))
{
$obj = $this -> db -> fetch_object ( $resql );
$this -> fetch ( $obj -> rowid );
}
}
else
{
dol_print_error ( $this -> db );
}
}
2013-07-01 12:00:42 +02:00
/**
* Method to load member from its name
*
2013-06-27 14:21:42 +02:00
* @ param string $firstname Firstname
2013-07-07 13:14:32 +02:00
* @ param string $lastname Lastname
2013-07-01 12:00:42 +02:00
* @ return void
*/
function fetch_name ( $firstname , $lastname )
{
global $conf ;
2013-07-07 13:14:32 +02:00
2013-07-01 12:00:42 +02:00
$sql = " SELECT rowid FROM " . MAIN_DB_PREFIX . " adherent " ;
$sql .= " WHERE firstname=' " . $this -> db -> escape ( $firstname ) . " ' " ;
2013-06-27 14:21:42 +02:00
$sql .= " AND lastname=' " . $this -> db -> escape ( $lastname ) . " ' " ;
2013-07-01 12:00:42 +02:00
$sql .= " AND entity = " . $conf -> entity ;
2013-07-07 13:14:32 +02:00
2013-07-01 12:00:42 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
if ( $this -> db -> num_rows ( $resql ))
{
$obj = $this -> db -> fetch_object ( $resql );
$this -> fetch ( $obj -> rowid );
}
}
else
{
dol_print_error ( $this -> db );
}
2013-06-27 14:21:42 +02:00
}
2013-07-07 13:14:32 +02:00
2010-08-29 14:54:39 +02:00
/**
2010-09-19 16:56:22 +02:00
* Load member from database
2011-09-12 19:43:31 +02:00
*
2011-12-28 13:25:05 +01:00
* @ param int $rowid Id of object to load
* @ param string $ref To load member from its ref
* @ param int $fk_soc To load member from its link to third party
2013-06-27 14:21:42 +02:00
* @ param int $ref_ext External reference
2011-12-28 13:25:05 +01:00
* @ return int > 0 if OK , 0 if not found , < 0 if KO
2010-08-29 14:54:39 +02:00
*/
2013-06-27 14:21:42 +02:00
function fetch ( $rowid , $ref = '' , $fk_soc = '' , $ref_ext = '' )
2010-08-29 14:54:39 +02:00
{
2012-04-15 11:28:21 +02:00
global $langs ;
2010-08-29 14:54:39 +02:00
2013-05-25 18:01:50 +02:00
$sql = " SELECT d.rowid, d.ref_ext, d.civilite, d.firstname, d.lastname, d.societe as company, d.fk_soc, d.statut, d.public, d.address, d.zip, d.town, d.note, " ;
2013-11-04 21:41:36 +01:00
$sql .= " d.email, d.skype, d.phone, d.phone_perso, d.phone_mobile, d.login, d.pass, " ;
2012-12-13 11:42:59 +01:00
$sql .= " d.photo, d.fk_adherent_type, d.morphy, d.entity, " ;
2010-08-29 14:54:39 +02:00
$sql .= " d.datec as datec, " ;
$sql .= " d.tms as datem, " ;
$sql .= " d.datefin as datefin, " ;
2013-03-13 22:17:03 +01:00
$sql .= " d.birth as birthday, " ;
2010-08-29 14:54:39 +02:00
$sql .= " d.datevalid as datev, " ;
2013-02-25 17:56:41 +01:00
$sql .= " d.country, " ;
2013-02-27 11:24:50 +01:00
$sql .= " d.state_id, " ;
2011-12-29 18:07:41 +01:00
$sql .= " p.rowid as country_id, p.code as country_code, p.libelle as country, " ;
2012-01-19 22:20:28 +01:00
$sql .= " dep.nom as state, dep.code_departement as state_code, " ;
2010-08-29 14:54:39 +02:00
$sql .= " t.libelle as type, t.cotisation as cotisation, " ;
$sql .= " u.rowid as user_id, u.login as user_login " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " adherent_type as t, " . MAIN_DB_PREFIX . " adherent as d " ;
2013-02-25 17:56:41 +01:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " c_pays as p ON d.country = p.rowid " ;
2013-02-27 11:24:50 +01:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " c_departements as dep ON d.state_id = dep.rowid " ;
2010-08-29 14:54:39 +02:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " user as u ON d.rowid = u.fk_member " ;
$sql .= " WHERE d.fk_adherent_type = t.rowid " ;
2012-04-15 11:28:21 +02:00
if ( $rowid ) $sql .= " AND d.rowid= " . $rowid ;
elseif ( $ref || $fk_soc ) {
$sql .= " AND d.entity IN ( " . getEntity () . " ) " ;
2012-07-02 19:30:37 +02:00
if ( $ref ) $sql .= " AND d.rowid=' " . $ref . " ' " ;
2012-04-15 11:28:21 +02:00
elseif ( $fk_soc ) $sql .= " AND d.fk_soc=' " . $fk_soc . " ' " ;
}
2013-06-27 14:21:42 +02:00
elseif ( $ref_ext )
{
$sql .= " AND d.ref_ext=' " . $this -> db -> escape ( $ref_ext ) . " ' " ;
}
2010-08-29 14:54:39 +02:00
2011-06-19 16:27:06 +02:00
dol_syslog ( get_class ( $this ) . " ::fetch sql= " . $sql );
2010-08-29 14:54:39 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
if ( $this -> db -> num_rows ( $resql ))
{
$obj = $this -> db -> fetch_object ( $resql );
2012-12-13 11:42:59 +01:00
$this -> entity = $obj -> entity ;
$this -> ref = $obj -> rowid ;
$this -> id = $obj -> rowid ;
2013-05-25 18:01:50 +02:00
$this -> ref_ext = $obj -> ref_ext ;
2012-12-13 11:42:59 +01:00
$this -> civilite_id = $obj -> civilite ;
$this -> firstname = $obj -> firstname ;
$this -> lastname = $obj -> lastname ;
$this -> login = $obj -> login ;
$this -> pass = $obj -> pass ;
2013-03-09 20:34:38 +01:00
$this -> societe = $obj -> company ;
$this -> company = $obj -> company ;
2012-12-13 11:42:59 +01:00
$this -> fk_soc = $obj -> fk_soc ;
$this -> address = $obj -> address ;
$this -> zip = $obj -> zip ;
$this -> town = $obj -> town ;
2013-02-27 11:24:50 +01:00
$this -> state_id = $obj -> state_id ;
$this -> state_code = $obj -> state_id ? $obj -> state_code : '' ;
$this -> state = $obj -> state_id ? $obj -> state : '' ;
2012-12-13 11:42:59 +01:00
$this -> country_id = $obj -> country_id ;
$this -> country_code = $obj -> country_code ;
if ( $langs -> trans ( " Country " . $obj -> country_code ) != " Country " . $obj -> country_code )
$this -> country = $langs -> transnoentitiesnoconv ( " Country " . $obj -> country_code );
else
$this -> country = $obj -> country ;
$this -> phone = $obj -> phone ;
$this -> phone_perso = $obj -> phone_perso ;
$this -> phone_mobile = $obj -> phone_mobile ;
$this -> email = $obj -> email ;
2013-11-04 21:41:36 +01:00
$this -> skype = $obj -> skype ;
2012-12-13 11:42:59 +01:00
$this -> photo = $obj -> photo ;
$this -> statut = $obj -> statut ;
$this -> public = $obj -> public ;
$this -> datec = $this -> db -> jdate ( $obj -> datec );
$this -> datem = $this -> db -> jdate ( $obj -> datem );
$this -> datefin = $this -> db -> jdate ( $obj -> datefin );
$this -> datevalid = $this -> db -> jdate ( $obj -> datev );
2013-03-13 22:17:03 +01:00
$this -> birth = $this -> db -> jdate ( $obj -> birthday );
2012-12-13 11:42:59 +01:00
$this -> note = $obj -> note ;
$this -> morphy = $obj -> morphy ;
$this -> typeid = $obj -> fk_adherent_type ;
$this -> type = $obj -> type ;
2010-08-29 14:54:39 +02:00
$this -> need_subscription = ( $obj -> cotisation == 'yes' ? 1 : 0 );
2012-12-13 11:42:59 +01:00
$this -> user_id = $obj -> user_id ;
$this -> user_login = $obj -> user_login ;
2010-08-29 14:54:39 +02:00
2013-04-26 10:29:14 +02:00
// Retreive all extrafield for thirdparty
// fetch optionals attributes and labels
2013-06-16 21:31:21 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php' ;
2013-04-26 10:29:14 +02:00
$extrafields = new ExtraFields ( $this -> db );
$extralabels = $extrafields -> fetch_name_optionals_label ( $this -> table_element , true );
2013-06-16 21:31:21 +02:00
$this -> fetch_optionals ( $this -> id , $extralabels );
2013-05-12 15:25:12 +02:00
2011-05-01 12:47:56 +02:00
// Load other properties
2010-08-29 14:54:39 +02:00
$result = $this -> fetch_subscriptions ();
return $result ;
}
else
{
return 0 ;
}
}
else
{
$this -> error = $this -> db -> lasterror ();
2011-06-19 16:27:06 +02:00
dol_syslog ( get_class ( $this ) . " ::fetch " . $this -> error , LOG_ERR );
2010-08-29 14:54:39 +02:00
return - 1 ;
}
}
/**
2010-09-19 16:56:22 +02:00
* Fonction qui recupere pour un adherent les parametres
2010-08-29 14:54:39 +02:00
* first_subscription_date
* first_subscription_amount
* last_subscription_date
* last_subscription_amount
2011-09-12 19:43:31 +02:00
*
2010-09-19 16:56:22 +02:00
* @ return int < 0 si KO , > 0 si OK
2010-08-29 14:54:39 +02:00
*/
function fetch_subscriptions ()
{
global $langs ;
2013-06-16 23:15:20 +02:00
require_once DOL_DOCUMENT_ROOT . '/adherents/class/cotisation.class.php' ;
2010-08-29 14:54:39 +02:00
$sql = " SELECT c.rowid, c.fk_adherent, c.cotisation, c.note, c.fk_bank, " ;
$sql .= " c.tms as datem, " ;
$sql .= " c.datec as datec, " ;
$sql .= " c.dateadh as dateadh, " ;
$sql .= " c.datef as datef " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " cotisation as c " ;
$sql .= " WHERE c.fk_adherent = " . $this -> id ;
$sql .= " ORDER BY c.dateadh " ;
2011-06-19 16:27:06 +02:00
dol_syslog ( get_class ( $this ) . " ::fetch_subscriptions sql= " . $sql );
2010-08-29 14:54:39 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
$this -> subscriptions = array ();
$i = 0 ;
while ( $obj = $this -> db -> fetch_object ( $resql ))
{
if ( $i == 0 )
{
$this -> first_subscription_date = $obj -> dateadh ;
$this -> first_subscription_amount = $obj -> cotisation ;
}
$this -> last_subscription_date = $obj -> dateadh ;
$this -> last_subscription_amount = $obj -> cotisation ;
$subscription = new Cotisation ( $this -> db );
$subscription -> id = $obj -> rowid ;
$subscription -> fk_adherent = $obj -> fk_adherent ;
$subscription -> amount = $obj -> cotisation ;
$subscription -> note = $obj -> note ;
$subscription -> fk_bank = $obj -> fk_bank ;
$subscription -> datem = $this -> db -> jdate ( $obj -> datem );
$subscription -> datec = $this -> db -> jdate ( $obj -> datec );
$subscription -> dateadh = $this -> db -> jdate ( $obj -> dateadh );
$subscription -> datef = $this -> db -> jdate ( $obj -> datef );
$this -> subscriptions [] = $subscription ;
$i ++ ;
}
return 1 ;
}
else
{
$this -> error = $this -> db -> error () . ' sql=' . $sql ;
return - 1 ;
}
}
/**
2011-12-28 13:25:05 +01:00
* Insert subscription into database and eventually add links to banks , mailman , etc ...
2011-09-12 19:43:31 +02:00
*
2011-12-28 13:25:05 +01:00
* @ param timestamp $date Date d ' effet de la cotisation
2013-02-21 09:35:05 +01:00
* @ param amount $montant Montant cotisation ( accepte 0 pour les adherents non soumis a cotisation )
2011-12-28 13:25:05 +01:00
* @ param int $accountid Id compte bancaire
* @ param string $operation Type operation ( si Id compte bancaire fourni )
* @ param string $label Label operation ( si Id compte bancaire fourni )
* @ param string $num_chq Numero cheque ( si Id compte bancaire fourni )
* @ param string $emetteur_nom Nom emetteur cheque
* @ param string $emetteur_banque Nom banque emetteur cheque
* @ param timestamp $datesubend Date fin adhesion
* @ return int rowid of record added , < 0 if KO
2010-08-29 14:54:39 +02:00
*/
2010-09-10 00:45:05 +02:00
function cotisation ( $date , $montant , $accountid = 0 , $operation = '' , $label = '' , $num_chq = '' , $emetteur_nom = '' , $emetteur_banque = '' , $datesubend = 0 )
2010-08-29 14:54:39 +02:00
{
global $conf , $langs , $user ;
2013-06-16 23:15:20 +02:00
require_once DOL_DOCUMENT_ROOT . '/adherents/class/cotisation.class.php' ;
2011-12-01 17:09:01 +01:00
$error = 0 ;
2011-12-28 13:25:05 +01:00
2010-08-29 14:54:39 +02:00
// Clean parameters
if ( ! $montant ) $montant = 0 ;
$this -> db -> begin ();
if ( $datesubend )
{
$datefin = $datesubend ;
}
else
{
// If no end date, end date = date + 1 year - 1 day
$datefin = dol_time_plus_duree ( $date , 1 , 'y' );
$datefin = dol_time_plus_duree ( $datefin , - 1 , 'd' );
}
// Create subscription
$cotisation = new Cotisation ( $this -> db );
$cotisation -> fk_adherent = $this -> id ;
$cotisation -> dateh = $date ; // Date of new subscription
$cotisation -> datef = $datefin ; // End data of new subscription
$cotisation -> amount = $montant ;
$cotisation -> note = $label ;
$rowid = $cotisation -> create ( $user );
if ( $rowid > 0 )
{
// Update denormalized subscription end date (read database subscription to find values)
// This will also update this->datefin
$result = $this -> update_end_date ( $user );
if ( $result > 0 )
{
// Change properties of object (used by triggers)
2011-12-01 17:09:01 +01:00
$this -> last_subscription_date = dol_now ();
2010-08-29 14:54:39 +02:00
$this -> last_subscription_amount = $montant ;
$this -> last_subscription_date_start = $date ;
$this -> last_subscription_date_end = $datefin ;
// Appel des triggers
2012-08-23 02:04:35 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php' ;
2010-08-29 14:54:39 +02:00
$interface = new Interfaces ( $this -> db );
$result = $interface -> run_triggers ( 'MEMBER_SUBSCRIPTION' , $this , $user , $langs , $conf );
if ( $result < 0 ) { $error ++ ; $this -> errors = $interface -> errors ; }
// Fin appel triggers
2012-01-11 01:52:00 +01:00
}
2010-08-29 14:54:39 +02:00
2012-01-11 01:52:00 +01:00
if ( ! $error )
{
2010-08-29 14:54:39 +02:00
$this -> db -> commit ();
return $rowid ;
}
else
{
$this -> db -> rollback ();
return - 2 ;
}
}
else
{
$this -> error = $cotisation -> error ;
$this -> db -> rollback ();
return - 1 ;
}
}
/**
2010-09-19 16:56:22 +02:00
* Function that validate a member
2011-12-01 17:09:01 +01:00
*
* @ param User $user user adherent qui valide
* @ return int < 0 if KO , 0 if nothing done , > 0 if OK
2010-08-29 14:54:39 +02:00
*/
function validate ( $user )
{
global $langs , $conf ;
2011-12-01 17:09:01 +01:00
$error = 0 ;
2012-04-30 15:01:25 +02:00
$now = dol_now ();
2011-12-28 13:25:05 +01:00
2011-12-01 17:09:01 +01:00
// Check parameters
2010-08-29 14:54:39 +02:00
if ( $this -> statut == 1 )
{
2011-06-19 16:27:06 +02:00
dol_syslog ( get_class ( $this ) . " ::validate statut of member does not allow this " , LOG_WARNING );
2010-08-29 14:54:39 +02:00
return 0 ;
}
$this -> db -> begin ();
$sql = " UPDATE " . MAIN_DB_PREFIX . " adherent SET " ;
$sql .= " statut = 1 " ;
2013-11-26 13:04:15 +01:00
$sql .= " , datevalid = ' " . $this -> db -> idate ( $now ) . " ' " ;
2010-08-29 14:54:39 +02:00
$sql .= " , fk_user_valid= " . $user -> id ;
$sql .= " WHERE rowid = " . $this -> id ;
2011-06-19 16:27:06 +02:00
dol_syslog ( get_class ( $this ) . " ::validate sql= " . $sql );
2010-08-29 14:54:39 +02:00
$result = $this -> db -> query ( $sql );
if ( $result )
{
$this -> statut = 1 ;
// Appel des triggers
2012-08-23 02:04:35 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php' ;
2010-08-29 14:54:39 +02:00
$interface = new Interfaces ( $this -> db );
$result = $interface -> run_triggers ( 'MEMBER_VALIDATE' , $this , $user , $langs , $conf );
if ( $result < 0 ) { $error ++ ; $this -> errors = $interface -> errors ; }
// Fin appel triggers
$this -> db -> commit ();
return 1 ;
}
else
{
$this -> error = $this -> db -> error ();
$this -> db -> rollback ();
return - 1 ;
}
}
/**
2010-09-19 16:56:22 +02:00
* Fonction qui resilie un adherent
2011-12-01 17:09:01 +01:00
*
* @ param User $user User making change
* @ return int < 0 if KO , > 0 if OK
2010-08-29 14:54:39 +02:00
*/
function resiliate ( $user )
{
global $langs , $conf ;
2011-12-01 17:09:01 +01:00
$error = 0 ;
2011-12-28 13:25:05 +01:00
2011-12-01 17:09:01 +01:00
// Check paramaters
2010-08-29 14:54:39 +02:00
if ( $this -> statut == 0 )
{
2011-06-19 16:27:06 +02:00
dol_syslog ( get_class ( $this ) . " ::resiliate statut of member does not allow this " , LOG_WARNING );
2010-08-29 14:54:39 +02:00
return 0 ;
}
$this -> db -> begin ();
$sql = " UPDATE " . MAIN_DB_PREFIX . " adherent SET " ;
$sql .= " statut = 0 " ;
$sql .= " , fk_user_valid= " . $user -> id ;
$sql .= " WHERE rowid = " . $this -> id ;
$result = $this -> db -> query ( $sql );
if ( $result )
{
$this -> statut = 0 ;
// Appel des triggers
2012-08-23 02:04:35 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php' ;
2010-08-29 14:54:39 +02:00
$interface = new Interfaces ( $this -> db );
$result = $interface -> run_triggers ( 'MEMBER_RESILIATE' , $this , $user , $langs , $conf );
if ( $result < 0 ) { $error ++ ; $this -> errors = $interface -> errors ; }
// Fin appel triggers
$this -> db -> commit ();
return 1 ;
}
else
{
$this -> error = $this -> db -> error ();
$this -> db -> rollback ();
return - 1 ;
}
}
/**
2013-08-21 12:39:20 +02:00
* Function to add member into external tools mailing - list , spip , etc .
2011-12-28 13:25:05 +01:00
*
2011-06-22 16:56:11 +02:00
* @ return int < 0 if KO , > 0 if OK
2010-08-29 14:54:39 +02:00
*/
2011-06-22 16:56:11 +02:00
function add_to_abo ()
2010-08-29 14:54:39 +02:00
{
2013-03-30 18:04:33 +01:00
global $conf , $langs ;
2010-09-19 16:56:22 +02:00
2012-08-23 02:04:35 +02:00
include_once DOL_DOCUMENT_ROOT . '/mailmanspip/class/mailmanspip.class.php' ;
2013-03-30 18:04:33 +01:00
$mailmanspip = new MailmanSpip ( $this -> db );
2012-06-10 21:49:19 +02:00
2010-08-29 14:54:39 +02:00
$err = 0 ;
// mailman
2011-06-22 16:56:11 +02:00
if ( ! empty ( $conf -> global -> ADHERENT_USE_MAILMAN ))
2010-08-29 14:54:39 +02:00
{
2012-06-10 21:49:19 +02:00
$result = $mailmanspip -> add_to_mailman ( $this );
2010-08-29 14:54:39 +02:00
if ( $result < 0 )
{
2013-08-21 12:39:20 +02:00
if ( ! empty ( $mailmanspip -> error )) $this -> errors [] = $mailmanspip -> error ;
2010-08-29 14:54:39 +02:00
$err += 1 ;
}
2013-03-30 18:04:33 +01:00
foreach ( $mailmanspip -> mladded_ko as $tmplist => $tmpemail )
{
$langs -> load ( " errors " );
$this -> errors [] = $langs -> trans ( " ErrorFailedToAddToMailmanList " , $tmpemail , $tmplist );
}
foreach ( $mailmanspip -> mladded_ok as $tmplist => $tmpemail )
{
$langs -> load ( " mailmanspip " );
$this -> mesgs [] = $langs -> trans ( " SuccessToAddToMailmanList " , $tmpemail , $tmplist );
}
2010-08-29 14:54:39 +02:00
}
// spip
2012-09-15 11:21:22 +02:00
if ( $conf -> global -> ADHERENT_USE_SPIP && ! empty ( $conf -> mailmanspip -> enabled ))
2010-08-29 14:54:39 +02:00
{
2012-06-10 21:49:19 +02:00
$result = $mailmanspip -> add_to_spip ( $this );
2011-06-22 16:56:11 +02:00
if ( $result < 0 )
2010-08-29 14:54:39 +02:00
{
2013-08-21 12:39:20 +02:00
$this -> errors [] = $mailmanspip -> error ;
2012-10-22 00:18:32 +02:00
$err += 1 ;
2010-08-29 14:54:39 +02:00
}
}
if ( $err )
{
return - $err ;
}
else
2013-03-30 18:04:33 +01:00
{
2010-08-29 14:54:39 +02:00
return 1 ;
}
}
/**
2013-08-21 12:39:20 +02:00
* Function to delete a member from external tools like mailing - list , spip , etc .
2011-12-28 13:25:05 +01:00
*
2011-06-22 16:56:11 +02:00
* @ return int < 0 if KO , > 0 if OK
2010-08-29 14:54:39 +02:00
*/
2011-06-22 16:56:11 +02:00
function del_to_abo ()
2010-08-29 14:54:39 +02:00
{
2013-03-30 18:04:33 +01:00
global $conf , $langs ;
2011-06-22 16:56:11 +02:00
2012-08-23 02:04:35 +02:00
include_once DOL_DOCUMENT_ROOT . '/mailmanspip/class/mailmanspip.class.php' ;
2013-03-30 18:04:33 +01:00
$mailmanspip = new MailmanSpip ( $this -> db );
2012-06-10 21:49:19 +02:00
2010-08-29 14:54:39 +02:00
$err = 0 ;
2012-06-10 21:49:19 +02:00
2010-08-29 14:54:39 +02:00
// mailman
2011-06-22 16:56:11 +02:00
if ( ! empty ( $conf -> global -> ADHERENT_USE_MAILMAN ))
2010-08-29 14:54:39 +02:00
{
2012-06-10 21:49:19 +02:00
$result = $mailmanspip -> del_to_mailman ( $this );
2011-06-22 16:56:11 +02:00
if ( $result < 0 )
{
2013-08-21 12:39:20 +02:00
if ( ! empty ( $mailmanspip -> error )) $this -> errors [] = $mailmanspip -> error ;
2010-08-29 14:54:39 +02:00
$err += 1 ;
}
2013-03-30 18:04:33 +01:00
foreach ( $mailmanspip -> mlremoved_ko as $tmplist => $tmpemail )
{
$langs -> load ( " errors " );
$this -> errors [] = $langs -> trans ( " ErrorFailedToRemoveToMailmanList " , $tmpemail , $tmplist );
}
foreach ( $mailmanspip -> mlremoved_ok as $tmplist => $tmpemail )
{
$langs -> load ( " mailmanspip " );
$this -> mesgs [] = $langs -> trans ( " SuccessToRemoveToMailmanList " , $tmpemail , $tmplist );
}
2010-08-29 14:54:39 +02:00
}
2012-09-15 11:21:22 +02:00
if ( $conf -> global -> ADHERENT_USE_SPIP && ! empty ( $conf -> mailmanspip -> enabled ))
2010-08-29 14:54:39 +02:00
{
2012-06-10 21:49:19 +02:00
$result = $mailmanspip -> del_to_spip ( $this );
2011-06-22 16:56:11 +02:00
if ( $result < 0 )
{
2013-08-21 12:39:20 +02:00
$this -> errors [] = $mailmanspip -> error ;
2010-08-29 14:54:39 +02:00
$err += 1 ;
}
}
2011-06-22 16:56:11 +02:00
if ( $err )
{
2010-08-29 14:54:39 +02:00
// error
2011-06-22 16:56:11 +02:00
return - $err ;
}
else
{
2010-08-29 14:54:39 +02:00
return 1 ;
}
}
/**
2013-05-12 17:09:48 +02:00
* Return civility label of a member
2011-09-12 20:15:11 +02:00
*
2013-05-12 17:09:48 +02:00
* @ return string Translated name of civility
2010-08-29 14:54:39 +02:00
*/
2013-05-12 17:09:48 +02:00
function getCivilityLabel ()
2010-08-29 14:54:39 +02:00
{
2013-07-01 12:00:42 +02:00
global $langs ;
$langs -> load ( " dict " );
2013-07-07 13:14:32 +02:00
2013-07-01 12:00:42 +02:00
$code = ( ! empty ( $this -> civilite_id ) ? $this -> civilite_id : ( ! empty ( $this -> civility_id ) ? $this -> civility_id : '' ));
if ( empty ( $code )) return '' ;
return $langs -> getLabelFromKey ( $this -> db , " Civility " . $code , " c_civilite " , " code " , " civilite " , $code );
2010-08-29 14:54:39 +02:00
}
/**
2010-09-19 16:56:22 +02:00
* Renvoie nom clicable ( avec eventuellement le picto )
2011-09-12 20:15:11 +02:00
*
2011-12-28 13:25:05 +01:00
* @ param int $withpicto 0 = Pas de picto , 1 = Inclut le picto dans le lien , 2 = Picto seul
* @ param int $maxlen length max libelle
* @ param string $option Page lien
* @ return string Chaine avec URL
2010-08-29 14:54:39 +02:00
*/
function getNomUrl ( $withpicto = 0 , $maxlen = 0 , $option = 'card' )
{
global $langs ;
$result = '' ;
if ( $option == 'card' )
{
$lien = '<a href="' . DOL_URL_ROOT . '/adherents/fiche.php?rowid=' . $this -> id . '">' ;
$lienfin = '</a>' ;
}
if ( $option == 'subscription' )
{
$lien = '<a href="' . DOL_URL_ROOT . '/adherents/card_subscriptions.php?rowid=' . $this -> id . '">' ;
$lienfin = '</a>' ;
}
2013-06-05 16:24:32 +02:00
if ( $option == 'category' )
{
$lien = '<a href="' . DOL_URL_ROOT . '/categories/categorie.php?id=' . $this -> id . '&type=3">' ;
$lienfin = '</a>' ;
}
2013-05-12 15:25:12 +02:00
2010-08-29 14:54:39 +02:00
$picto = 'user' ;
$label = $langs -> trans ( " ShowMember " );
if ( $withpicto ) $result .= ( $lien . img_object ( $label , $picto ) . $lienfin );
if ( $withpicto && $withpicto != 2 ) $result .= ' ' ;
$result .= $lien . ( $maxlen ? dol_trunc ( $this -> ref , $maxlen ) : $this -> ref ) . $lienfin ;
return $result ;
}
/**
2012-06-10 21:49:19 +02:00
* Retourne le libelle du statut d ' un adherent ( brouillon , valide , resilie )
2011-09-12 20:15:11 +02:00
*
2012-06-10 21:49:19 +02:00
* @ param int $mode 0 = libelle long , 1 = libelle court , 2 = Picto + Libelle court , 3 = Picto , 4 = Picto + Libelle long , 5 = Libelle court + Picto
* @ return string Label
2010-08-29 14:54:39 +02:00
*/
function getLibStatut ( $mode = 0 )
{
return $this -> LibStatut ( $this -> statut , $this -> need_subscription , $this -> datefin , $mode );
}
/**
2012-06-10 21:49:19 +02:00
* Renvoi le libelle d ' un statut donne
2011-09-12 20:15:11 +02:00
*
2012-06-10 21:49:19 +02:00
* @ param int $statut Id statut
* @ param int $need_subscription 1 si type adherent avec cotisation , 0 sinon
* @ param timestamp $date_end_subscription Date fin adhesion
* @ param int $mode 0 = libelle long , 1 = libelle court , 2 = Picto + Libelle court , 3 = Picto , 4 = Picto + Libelle long , 5 = Libelle court + Picto
* @ return string Label
2010-08-29 14:54:39 +02:00
*/
function LibStatut ( $statut , $need_subscription , $date_end_subscription , $mode = 0 )
{
global $langs ;
$langs -> load ( " members " );
if ( $mode == 0 )
{
if ( $statut == - 1 ) return $langs -> trans ( " MemberStatusDraft " );
if ( $statut >= 1 )
{
if ( ! $date_end_subscription ) return $langs -> trans ( " MemberStatusActive " );
elseif ( $date_end_subscription < time ()) return $langs -> trans ( " MemberStatusActiveLate " );
else return $langs -> trans ( " MemberStatusPaid " );
}
if ( $statut == 0 ) return $langs -> trans ( " MemberStatusResiliated " );
}
if ( $mode == 1 )
{
if ( $statut == - 1 ) return $langs -> trans ( " MemberStatusDraftShort " );
if ( $statut >= 1 )
{
if ( ! $date_end_subscription ) return $langs -> trans ( " MemberStatusActiveShort " );
elseif ( $date_end_subscription < time ()) return $langs -> trans ( " MemberStatusActiveLateShort " );
else return $langs -> trans ( " MemberStatusPaidShort " );
}
if ( $statut == 0 ) return $langs -> trans ( " MemberStatusResiliatedShort " );
}
if ( $mode == 2 )
{
if ( $statut == - 1 ) return img_picto ( $langs -> trans ( 'MemberStatusDraft' ), 'statut0' ) . ' ' . $langs -> trans ( " MemberStatusDraftShort " );
if ( $statut >= 1 )
{
if ( ! $date_end_subscription ) return img_picto ( $langs -> trans ( 'MemberStatusActive' ), 'statut1' ) . ' ' . $langs -> trans ( " MemberStatusActiveShort " );
elseif ( $date_end_subscription < time ()) return img_picto ( $langs -> trans ( 'MemberStatusActiveLate' ), 'statut3' ) . ' ' . $langs -> trans ( " MemberStatusActiveLateShort " );
else return img_picto ( $langs -> trans ( 'MemberStatusPaid' ), 'statut4' ) . ' ' . $langs -> trans ( " MemberStatusPaidShort " );
}
if ( $statut == 0 ) return img_picto ( $langs -> trans ( 'MemberStatusResiliated' ), 'statut5' ) . ' ' . $langs -> trans ( " MemberStatusResiliatedShort " );
}
if ( $mode == 3 )
{
if ( $statut == - 1 ) return img_picto ( $langs -> trans ( 'MemberStatusDraft' ), 'statut0' );
if ( $statut >= 1 )
{
if ( ! $date_end_subscription ) return img_picto ( $langs -> trans ( 'MemberStatusActive' ), 'statut1' );
elseif ( $date_end_subscription < time ()) return img_picto ( $langs -> trans ( 'MemberStatusActiveLate' ), 'statut3' );
else return img_picto ( $langs -> trans ( 'MemberStatusPaid' ), 'statut4' );
}
if ( $statut == 0 ) return img_picto ( $langs -> trans ( 'MemberStatusResiliated' ), 'statut5' );
}
if ( $mode == 4 )
{
if ( $statut == - 1 ) return img_picto ( $langs -> trans ( 'MemberStatusDraft' ), 'statut0' ) . ' ' . $langs -> trans ( " MemberStatusDraft " );
if ( $statut >= 1 )
{
if ( ! $date_end_subscription ) return img_picto ( $langs -> trans ( 'MemberStatusActive' ), 'statut1' ) . ' ' . $langs -> trans ( " MemberStatusActive " );
elseif ( $date_end_subscription < time ()) return img_picto ( $langs -> trans ( 'MemberStatusActiveLate' ), 'statut3' ) . ' ' . $langs -> trans ( " MemberStatusActiveLate " );
else return img_picto ( $langs -> trans ( 'MemberStatusPaid' ), 'statut4' ) . ' ' . $langs -> trans ( " MemberStatusPaid " );
}
if ( $statut == 0 ) return img_picto ( $langs -> trans ( 'MemberStatusResiliated' ), 'statut5' ) . ' ' . $langs -> trans ( " MemberStatusResiliated " );
}
if ( $mode == 5 )
{
if ( $statut == - 1 ) return $langs -> trans ( " MemberStatusDraft " ) . ' ' . img_picto ( $langs -> trans ( 'MemberStatusDraft' ), 'statut0' );
if ( $statut >= 1 )
{
2013-04-25 20:27:45 +02:00
if ( ! $date_end_subscription ) return '<span class="hideonsmartphone">' . $langs -> trans ( " MemberStatusActive " ) . ' </span>' . img_picto ( $langs -> trans ( 'MemberStatusActive' ), 'statut1' );
elseif ( $date_end_subscription < time ()) return '<span class="hideonsmartphone">' . $langs -> trans ( " MemberStatusActiveLate " ) . ' </span>' . img_picto ( $langs -> trans ( 'MemberStatusActiveLate' ), 'statut3' );
else return '<span class="hideonsmartphone">' . $langs -> trans ( " MemberStatusPaid " ) . ' </span>' . img_picto ( $langs -> trans ( 'MemberStatusPaid' ), 'statut4' );
2010-08-29 14:54:39 +02:00
}
2013-04-25 20:27:45 +02:00
if ( $statut == 0 ) return '<span class="hideonsmartphone">' . $langs -> trans ( " MemberStatusResiliated " ) . ' </span>' . img_picto ( $langs -> trans ( 'MemberStatusResiliated' ), 'statut5' );
2010-08-29 14:54:39 +02:00
}
}
/**
2010-09-19 16:56:22 +02:00
* Charge indicateurs this -> nb de tableau de bord
2011-09-12 20:15:11 +02:00
*
2011-12-28 13:25:05 +01:00
* @ return int < 0 if KO , > 0 if OK
2010-08-29 14:54:39 +02:00
*/
function load_state_board ()
{
global $conf ;
$this -> nb = array ();
$sql = " SELECT count(a.rowid) as nb " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " adherent as a " ;
$sql .= " WHERE a.statut > 0 " ;
$sql .= " AND a.entity = " . $conf -> entity ;
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
while ( $obj = $this -> db -> fetch_object ( $resql ))
{
$this -> nb [ " members " ] = $obj -> nb ;
}
2013-06-16 21:31:21 +02:00
$this -> db -> free ( $resql );
2010-08-29 14:54:39 +02:00
return 1 ;
}
else
{
dol_print_error ( $this -> db );
$this -> error = $this -> db -> error ();
return - 1 ;
}
}
/**
2010-11-13 18:37:22 +01:00
* Load indicators for dashboard ( this -> nbtodo and this -> nbtodolate )
2011-09-12 20:15:11 +02:00
*
2011-12-28 13:25:05 +01:00
* @ param User $user Objet user
* @ return int < 0 if KO , > 0 if OK
2010-08-29 14:54:39 +02:00
*/
function load_board ( $user )
{
global $conf ;
2011-01-15 03:39:31 +01:00
$now = dol_now ();
2010-08-29 14:54:39 +02:00
if ( $user -> societe_id ) return - 1 ; // protection pour eviter appel par utilisateur externe
$this -> nbtodo = $this -> nbtodolate = 0 ;
$sql = " SELECT a.rowid, a.datefin " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " adherent as a " ;
$sql .= " WHERE a.statut = 1 " ;
$sql .= " AND a.entity = " . $conf -> entity ;
2011-01-15 03:39:31 +01:00
$sql .= " AND (a.datefin IS NULL or a.datefin < ' " . $this -> db -> idate ( $now ) . " ') " ;
2010-08-29 14:54:39 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql )
{
while ( $obj = $this -> db -> fetch_object ( $resql ))
{
$this -> nbtodo ++ ;
if ( $this -> db -> jdate ( $obj -> datefin ) < ( $now - $conf -> adherent -> cotisation -> warning_delay )) $this -> nbtodolate ++ ;
}
return 1 ;
}
else
{
dol_print_error ( $this -> db );
$this -> error = $this -> db -> error ();
return - 1 ;
}
}
/**
2011-09-20 19:19:46 +02:00
* Initialise an instance with random values .
* Used to build previews or test instances .
* id must be 0 if object instance is a specimen .
*
* @ return void
2010-08-29 14:54:39 +02:00
*/
function initAsSpecimen ()
{
global $user , $langs ;
// Initialise parametres
$this -> id = 0 ;
$this -> specimen = 1 ;
$this -> civilite_id = 0 ;
2012-01-30 10:22:50 +01:00
$this -> lastname = 'DOLIBARR' ;
$this -> firstname = 'SPECIMEN' ;
2010-08-29 14:54:39 +02:00
$this -> login = 'dolibspec' ;
$this -> pass = 'dolibspec' ;
$this -> societe = 'Societe ABC' ;
2011-05-29 14:26:24 +02:00
$this -> address = '61 jump street' ;
$this -> zip = '75000' ;
$this -> town = 'Paris' ;
2011-12-29 18:07:41 +01:00
$this -> country_id = 1 ;
$this -> country_code = 'FR' ;
$this -> country = 'France' ;
2010-08-29 14:54:39 +02:00
$this -> morphy = 1 ;
$this -> email = 'specimen@specimen.com' ;
2013-11-04 21:41:36 +01:00
$this -> skype = 'tom.hanson' ;
2010-08-29 14:54:39 +02:00
$this -> phone = '0999999999' ;
$this -> phone_perso = '0999999998' ;
$this -> phone_mobile = '0999999997' ;
$this -> note = 'No comment' ;
2013-03-13 22:17:03 +01:00
$this -> birth = time ();
2010-08-29 14:54:39 +02:00
$this -> photo = '' ;
$this -> public = 1 ;
$this -> statut = 0 ;
$this -> datefin = time ();
$this -> datevalid = time ();
$this -> typeid = 1 ; // Id type adherent
$this -> type = 'Type adherent' ; // Libelle type adherent
$this -> need_subscription = 0 ;
$this -> first_subscription_date = time ();
$this -> first_subscription_amount = 10 ;
$this -> last_subscription_date = time ();
$this -> last_subscription_amount = 10 ;
}
/**
2010-09-19 16:56:22 +02:00
* Retourne chaine DN complete dans l 'annuaire LDAP pour l' objet
2011-09-12 20:15:11 +02:00
*
2011-12-28 13:25:05 +01:00
* @ param string $info Info string loaded by _load_ldap_info
* @ param int $mode 0 = Return full DN ( uid = qqq , ou = xxx , dc = aaa , dc = bbb )
* 1 = Return DN without key inside ( ou = xxx , dc = aaa , dc = bbb )
* 2 = Return key only ( uid = qqq )
* @ return string DN
2010-08-29 14:54:39 +02:00
*/
function _load_ldap_dn ( $info , $mode = 0 )
{
global $conf ;
$dn = '' ;
if ( $mode == 0 ) $dn = $conf -> global -> LDAP_KEY_MEMBERS . " = " . $info [ $conf -> global -> LDAP_KEY_MEMBERS ] . " , " . $conf -> global -> LDAP_MEMBER_DN ;
if ( $mode == 1 ) $dn = $conf -> global -> LDAP_MEMBER_DN ;
if ( $mode == 2 ) $dn = $conf -> global -> LDAP_KEY_MEMBERS . " = " . $info [ $conf -> global -> LDAP_KEY_MEMBERS ];
return $dn ;
}
/**
2010-09-19 16:56:22 +02:00
* Initialise tableau info ( tableau des attributs LDAP )
2011-09-12 20:15:11 +02:00
*
2010-09-19 16:56:22 +02:00
* @ return array Tableau info des attributs
2010-08-29 14:54:39 +02:00
*/
function _load_ldap_info ()
{
global $conf , $langs ;
$info = array ();
// Object classes
$info [ " objectclass " ] = explode ( ',' , $conf -> global -> LDAP_MEMBER_OBJECT_CLASS );
$this -> fullname = $this -> getFullName ( $langs );
// Member
2012-09-15 11:21:22 +02:00
if ( $this -> fullname && ! empty ( $conf -> global -> LDAP_MEMBER_FIELD_FULLNAME )) $info [ $conf -> global -> LDAP_MEMBER_FIELD_FULLNAME ] = $this -> fullname ;
2013-02-23 11:11:33 +01:00
if ( $this -> lastname && ! empty ( $conf -> global -> LDAP_MEMBER_FIELD_NAME )) $info [ $conf -> global -> LDAP_MEMBER_FIELD_NAME ] = $this -> lastname ;
2013-02-23 15:26:39 +01:00
if ( $this -> firstname && ! empty ( $conf -> global -> LDAP_MEMBER_FIELD_FIRSTNAME )) $info [ $conf -> global -> LDAP_MEMBER_FIELD_FIRSTNAME ] = $this -> firstname ;
2012-09-15 11:21:22 +02:00
if ( $this -> login && ! empty ( $conf -> global -> LDAP_MEMBER_FIELD_LOGIN )) $info [ $conf -> global -> LDAP_MEMBER_FIELD_LOGIN ] = $this -> login ;
if ( $this -> pass && ! empty ( $conf -> global -> LDAP_MEMBER_FIELD_PASSWORD )) $info [ $conf -> global -> LDAP_MEMBER_FIELD_PASSWORD ] = $this -> pass ; // this->pass = mot de passe non crypte
if ( $this -> poste && ! empty ( $conf -> global -> LDAP_MEMBER_FIELD_TITLE )) $info [ $conf -> global -> LDAP_MEMBER_FIELD_TITLE ] = $this -> poste ;
2013-02-15 17:33:07 +01:00
if ( $this -> address && ! empty ( $conf -> global -> LDAP_MEMBER_FIELD_ADDRESS )) $info [ $conf -> global -> LDAP_MEMBER_FIELD_ADDRESS ] = $this -> address ;
2013-02-24 15:57:02 +01:00
if ( $this -> zip && ! empty ( $conf -> global -> LDAP_MEMBER_FIELD_ZIP )) $info [ $conf -> global -> LDAP_MEMBER_FIELD_ZIP ] = $this -> zip ;
2013-02-22 11:32:19 +01:00
if ( $this -> town && ! empty ( $conf -> global -> LDAP_MEMBER_FIELD_TOWN )) $info [ $conf -> global -> LDAP_MEMBER_FIELD_TOWN ] = $this -> town ;
2012-09-15 11:21:22 +02:00
if ( $this -> country_code && ! empty ( $conf -> global -> LDAP_MEMBER_FIELD_COUNTRY )) $info [ $conf -> global -> LDAP_MEMBER_FIELD_COUNTRY ] = $this -> country_code ;
if ( $this -> email && ! empty ( $conf -> global -> LDAP_MEMBER_FIELD_MAIL )) $info [ $conf -> global -> LDAP_MEMBER_FIELD_MAIL ] = $this -> email ;
2013-11-04 21:41:36 +01:00
if ( $this -> skype && ! empty ( $conf -> global -> LDAP_MEMBER_FIELD_SKYPE )) $info [ $conf -> global -> LDAP_MEMBER_FIELD_SKYPE ] = $this -> skype ;
2012-09-15 11:21:22 +02:00
if ( $this -> phone && ! empty ( $conf -> global -> LDAP_MEMBER_FIELD_PHONE )) $info [ $conf -> global -> LDAP_MEMBER_FIELD_PHONE ] = $this -> phone ;
if ( $this -> phone_perso && ! empty ( $conf -> global -> LDAP_MEMBER_FIELD_PHONE_PERSO )) $info [ $conf -> global -> LDAP_MEMBER_FIELD_PHONE_PERSO ] = $this -> phone_perso ;
if ( $this -> phone_mobile && ! empty ( $conf -> global -> LDAP_MEMBER_FIELD_MOBILE )) $info [ $conf -> global -> LDAP_MEMBER_FIELD_MOBILE ] = $this -> phone_mobile ;
if ( $this -> fax && ! empty ( $conf -> global -> LDAP_MEMBER_FIELD_FAX )) $info [ $conf -> global -> LDAP_MEMBER_FIELD_FAX ] = $this -> fax ;
if ( $this -> note && ! empty ( $conf -> global -> LDAP_MEMBER_FIELD_DESCRIPTION )) $info [ $conf -> global -> LDAP_MEMBER_FIELD_DESCRIPTION ] = $this -> note ;
2013-03-13 22:17:03 +01:00
if ( $this -> birth && ! empty ( $conf -> global -> LDAP_MEMBER_FIELD_BIRTHDATE )) $info [ $conf -> global -> LDAP_MEMBER_FIELD_BIRTHDATE ] = dol_print_date ( $this -> birth , 'dayhourldap' );
2012-09-15 11:21:22 +02:00
if ( isset ( $this -> statut ) && ! empty ( $conf -> global -> LDAP_FIELD_MEMBER_STATUS )) $info [ $conf -> global -> LDAP_FIELD_MEMBER_STATUS ] = $this -> statut ;
if ( $this -> datefin && ! empty ( $conf -> global -> LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION )) $info [ $conf -> global -> LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION ] = dol_print_date ( $this -> datefin , 'dayhourldap' );
2010-08-29 14:54:39 +02:00
// Subscriptions
2012-09-15 11:21:22 +02:00
if ( $this -> first_subscription_date && ! empty ( $conf -> global -> LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE )) $info [ $conf -> global -> LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE ] = dol_print_date ( $this -> first_subscription_date , 'dayhourldap' );
if ( isset ( $this -> first_subscription_amount ) && ! empty ( $conf -> global -> LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT )) $info [ $conf -> global -> LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT ] = $this -> first_subscription_amount ;
if ( $this -> last_subscription_date && ! empty ( $conf -> global -> LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE )) $info [ $conf -> global -> LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE ] = dol_print_date ( $this -> last_subscription_date , 'dayhourldap' );
if ( isset ( $this -> last_subscription_amount ) && ! empty ( $conf -> global -> LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT )) $info [ $conf -> global -> LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT ] = $this -> last_subscription_amount ;
2010-08-29 14:54:39 +02:00
return $info ;
}
/**
2010-09-19 16:56:22 +02:00
* Charge les informations d 'ordre info dans l' objet adherent
2011-09-12 20:15:11 +02:00
*
2011-12-28 13:25:05 +01:00
* @ param int $id Id of member to load
* @ return void
2010-08-29 14:54:39 +02:00
*/
function info ( $id )
{
$sql = 'SELECT a.rowid, a.datec as datec,' ;
$sql .= ' a.datevalid as datev,' ;
$sql .= ' a.tms as datem,' ;
$sql .= ' a.fk_user_author, a.fk_user_valid, a.fk_user_mod' ;
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'adherent as a' ;
$sql .= ' WHERE a.rowid = ' . $id ;
2011-06-19 16:27:06 +02:00
dol_syslog ( get_class ( $this ) . " ::info sql= " . $sql , LOG_DEBUG );
2010-08-29 14:54:39 +02:00
$result = $this -> db -> query ( $sql );
if ( $result )
{
if ( $this -> db -> num_rows ( $result ))
{
$obj = $this -> db -> fetch_object ( $result );
$this -> id = $obj -> rowid ;
if ( $obj -> fk_user_author )
{
$cuser = new User ( $this -> db );
$cuser -> fetch ( $obj -> fk_user_author );
$this -> user_creation = $cuser ;
}
if ( $obj -> fk_user_valid )
{
$vuser = new User ( $this -> db );
$vuser -> fetch ( $obj -> fk_user_valid );
$this -> user_validation = $vuser ;
}
if ( $obj -> fk_user_mod )
{
$muser = new User ( $this -> db );
$muser -> fetch ( $obj -> fk_user_mod );
$this -> user_modification = $muser ;
}
$this -> date_creation = $this -> db -> jdate ( $obj -> datec );
$this -> date_validation = $this -> db -> jdate ( $obj -> datev );
$this -> date_modification = $this -> db -> jdate ( $obj -> datem );
}
$this -> db -> free ( $result );
}
else
{
dol_print_error ( $this -> db );
}
}
2006-11-26 19:24:53 +01:00
2003-09-01 00:05:54 +02:00
}
?>