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 >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2009 - 2017 Regis Houssin < regis . houssin @ inodbox . com >
2019-01-28 21:39:22 +01:00
* Copyright ( C ) 2014 - 2018 Alexandre Spangaro < aspangaro @ open - dsi . fr >
2016-09-24 06:48:40 +02:00
* Copyright ( C ) 2015 Marcos García < marcosgdf @ gmail . com >
2022-02-15 11:09:07 +01:00
* Copyright ( C ) 2015 - 2022 Frédéric France < frederic . france @ netlogic . fr >
2016-09-24 06:48:40 +02:00
* Copyright ( C ) 2015 Raphaël Doursenaud < rdoursenaud @ gpcsolutions . fr >
* Copyright ( C ) 2016 Juanjo Menent < jmenent @ 2 byte . es >
2020-04-02 17:49:01 +02:00
* Copyright ( C ) 2018 - 2019 Thibault FOUCART < support @ ptibogxiv . net >
* Copyright ( C ) 2019 Nicolas ZABOURI < info @ inovea - conseil . com >
* Copyright ( C ) 2020 Josep Lluís Amador < joseplluis @ lliuretic . cat >
2021-04-09 02:51:05 +02:00
* Copyright ( C ) 2021 Waël Almoman < info @ almoman . com >
2021-11-17 10:07:05 +01:00
* Copyright ( C ) 2021 Philippe Grand < philippe . grand @ atoo - net . 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
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// 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
*/
2020-03-12 12:45:44 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.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
{
2018-08-23 17:07:27 +02:00
/**
* @ var string ID to identify managed object
*/
2020-02-02 19:34:09 +01:00
public $element = 'member' ;
2018-08-29 15:37:35 +02:00
2018-08-22 18:12:44 +02:00
/**
* @ var string Name of table without prefix where object is stored
*/
2020-02-02 19:34:09 +01:00
public $table_element = 'adherent' ;
2018-08-29 15:37:35 +02:00
2018-10-06 12:07:24 +02:00
/**
* 0 = No test on entity , 1 = Test with field entity , 2 = Test with link by societe
* @ var int
*/
public $ismultientitymanaged = 1 ;
2010-08-29 14:54:39 +02:00
2020-11-01 08:48:53 +01:00
/**
* @ var string picto
*/
2020-04-24 23:56:57 +02:00
public $picto = 'member' ;
2018-09-04 13:45:20 +02:00
public $mesgs ;
2013-03-30 18:04:33 +01:00
2020-02-24 22:53:14 +01:00
/**
* @ var string login of member
*/
2018-09-04 13:45:20 +02:00
public $login ;
2016-06-25 21:28:52 +02:00
2020-11-01 08:48:53 +01:00
/**
2020-11-01 15:39:01 +01:00
* @ var string Clear password in memory
2020-11-01 08:48:53 +01:00
*/
2018-09-04 13:45:20 +02:00
public $pass ;
2020-02-24 22:53:14 +01:00
2020-11-01 08:48:53 +01:00
/**
2020-12-01 02:41:19 +01:00
* @ var string Clear password in database ( defined if DATABASE_PWD_ENCRYPTED = 0 )
*/
2018-09-04 13:45:20 +02:00
public $pass_indatabase ;
2020-02-24 22:53:14 +01:00
2020-11-01 08:48:53 +01:00
/**
2020-11-01 15:39:01 +01:00
* @ var string Encrypted password in database ( always defined )
2020-11-01 08:48:53 +01:00
*/
2018-09-04 13:45:20 +02:00
public $pass_indatabase_crypted ;
2016-06-25 21:28:52 +02:00
2020-02-24 22:53:14 +01:00
/**
* @ var string company name
* @ deprecated
*/
2018-09-04 13:45:20 +02:00
public $societe ;
2018-10-05 16:04:10 +02:00
/**
2018-12-02 10:12:40 +01:00
* @ var string company name
2018-10-05 16:04:10 +02:00
*/
2018-09-04 13:45:20 +02:00
public $company ;
2018-10-05 16:04:10 +02:00
2018-12-02 10:12:40 +01:00
/**
* @ var int Thirdparty ID
*/
2020-02-24 22:53:14 +01:00
public $fk_soc ;
2020-12-04 14:53:52 +01:00
public $socid ;
2018-12-02 10:12:40 +01:00
2018-10-05 16:04:10 +02:00
/**
* @ var string Address
*/
2018-09-04 13:45:20 +02:00
public $address ;
2018-10-05 16:04:10 +02:00
2020-02-24 22:53:14 +01:00
/**
* @ var string zipcode
*/
public $zip ;
2018-12-02 10:12:40 +01:00
2020-02-24 22:53:14 +01:00
/**
* @ var string town
*/
2018-09-04 13:45:20 +02:00
public $town ;
2017-10-07 13:09:31 +02:00
2020-02-24 22:53:14 +01:00
/**
* @ var int Id of state
*/
public $state_id ;
2017-10-07 13:09:31 +02:00
2020-02-24 22:53:14 +01:00
/**
* @ var string Code of state
*/
public $state_code ;
2018-12-02 10:12:40 +01:00
2020-02-24 22:53:14 +01:00
/**
* @ var string Label of state
*/
2018-12-02 10:12:40 +01:00
public $state ;
2020-02-24 22:53:14 +01:00
/**
* @ var string email
*/
2018-09-04 13:45:20 +02:00
public $email ;
2018-10-12 11:12:29 +02:00
2021-04-17 14:15:16 +02:00
/**
* @ var string url
*/
public $url ;
2020-02-24 22:53:14 +01:00
/**
* @ var array array of socialnetworks
*/
public $socialnetworks ;
2019-09-11 23:00:14 +02:00
2020-02-24 22:53:14 +01:00
/**
* @ var string skype account
2019-09-11 23:00:14 +02:00
* @ deprecated
2020-02-24 22:53:14 +01:00
*/
public $skype ;
2018-12-02 10:12:40 +01:00
2020-02-24 22:53:14 +01:00
/**
* @ var string twitter account
2019-09-11 23:00:14 +02:00
* @ deprecated
2020-02-24 22:53:14 +01:00
*/
public $twitter ;
2018-12-02 10:12:40 +01:00
2020-02-24 22:53:14 +01:00
/**
* @ var string facebook account
2019-09-11 23:00:14 +02:00
* @ deprecated
2020-02-24 22:53:14 +01:00
*/
2018-10-12 11:12:29 +02:00
public $facebook ;
2020-02-24 22:53:14 +01:00
/**
* @ var string linkedin account
2019-09-11 23:00:14 +02:00
* @ deprecated
2020-02-24 22:53:14 +01:00
*/
public $linkedin ;
2019-02-25 09:07:58 +01:00
2020-02-24 22:53:14 +01:00
/**
* @ var string Phone number
*/
2018-09-04 13:45:20 +02:00
public $phone ;
2018-10-15 08:53:47 +02:00
2020-02-24 22:53:14 +01:00
/**
* @ var string Private Phone number
*/
2018-09-04 13:45:20 +02:00
public $phone_perso ;
2018-10-15 08:53:47 +02:00
2020-11-01 08:56:56 +01:00
/**
* @ var string Professional Phone number
*/
public $phone_pro ;
2020-02-24 22:53:14 +01:00
/**
* @ var string Mobile phone number
*/
2018-09-04 13:45:20 +02:00
public $phone_mobile ;
2017-10-07 13:09:31 +02:00
2020-02-24 22:53:14 +01:00
/**
* @ var string Fax number
*/
public $fax ;
2018-10-15 08:53:47 +02:00
2020-02-24 22:53:14 +01:00
/**
* @ var string Function
*/
public $poste ;
2018-10-15 08:53:47 +02:00
2020-11-01 08:48:53 +01:00
/**
* @ var string mor or phy
*/
2018-09-04 13:45:20 +02:00
public $morphy ;
2018-12-02 10:12:40 +01:00
2021-04-28 20:59:21 +02:00
/**
* @ var int Info can be public
*/
2020-02-24 22:53:14 +01:00
public $public ;
2018-12-02 10:12:40 +01:00
2020-11-01 08:48:53 +01:00
/**
* @ var string photo of member
*/
2020-02-24 22:53:14 +01:00
public $photo ;
2017-10-07 13:09:31 +02:00
2019-03-18 10:22:20 +01:00
/**
2020-02-24 22:53:14 +01:00
* Date creation record ( datec )
*
* @ var integer
*/
public $datec ;
2019-06-18 20:01:28 +02:00
2019-03-18 10:22:20 +01:00
/**
2020-02-24 22:53:14 +01:00
* Date modification record ( tms )
*
* @ var integer
*/
public $datem ;
2019-06-18 20:01:28 +02:00
2018-09-04 13:45:20 +02:00
public $datevalid ;
2017-10-07 13:09:31 +02:00
2020-11-01 08:48:53 +01:00
/**
* @ var string gender
*/
2018-11-18 21:50:58 +01:00
public $gender ;
2020-02-24 22:53:14 +01:00
2018-09-04 13:45:20 +02:00
public $birth ;
2017-10-07 13:09:31 +02:00
2020-02-24 22:53:14 +01:00
/**
* @ var int id type member
*/
2018-12-02 10:12:40 +01:00
public $typeid ;
2017-10-07 13:09:31 +02:00
2020-02-24 22:53:14 +01:00
/**
* @ var string label type member
*/
2018-12-02 10:12:40 +01:00
public $type ;
2020-02-24 22:53:14 +01:00
2018-09-04 13:45:20 +02:00
public $need_subscription ;
2017-10-07 13:09:31 +02:00
2018-09-04 13:45:20 +02:00
public $user_id ;
2020-02-24 22:53:14 +01:00
2018-09-04 13:45:20 +02:00
public $user_login ;
2017-10-07 13:09:31 +02:00
2020-02-24 22:53:14 +01:00
public $datefin ;
2018-10-09 23:10:39 +02:00
2021-06-07 10:08:31 +02:00
// Fields loaded by fetch_subscriptions() from member table
2018-09-04 13:45:20 +02:00
public $first_subscription_date ;
2020-02-24 22:53:14 +01:00
2018-09-04 13:45:20 +02:00
public $first_subscription_amount ;
2020-02-24 22:53:14 +01:00
2018-09-04 13:45:20 +02:00
public $last_subscription_date ;
2020-02-24 22:53:14 +01:00
2018-09-04 13:45:20 +02:00
public $last_subscription_date_start ;
2020-02-24 22:53:14 +01:00
2018-09-04 13:45:20 +02:00
public $last_subscription_date_end ;
2020-02-24 22:53:14 +01:00
2018-09-04 13:45:20 +02:00
public $last_subscription_amount ;
2020-02-24 22:53:14 +01:00
2020-02-02 19:34:09 +01:00
public $subscriptions = array ();
2017-10-07 13:09:31 +02:00
2021-06-07 10:08:31 +02:00
// Fields loaded by fetchPartnerships() from partnership table
public $partnerships = array ();
2020-02-24 22:53:14 +01:00
/**
* @ var Adherent To contains a clone of this when we need to save old properties of object
*/
2018-12-02 10:12:40 +01:00
public $oldcopy ;
2017-10-07 13:09:31 +02:00
2018-08-31 18:27:16 +02:00
/**
* @ var int Entity
*/
2017-10-07 13:09:31 +02:00
public $entity ;
2020-11-01 08:48:53 +01:00
/**
* @ var array fields
*/
public $fields = array (
'rowid' => array ( 'type' => 'integer' , 'label' => 'TechnicalID' , 'enabled' => 1 , 'visible' => - 1 , 'notnull' => 1 , 'position' => 10 ),
2020-11-10 22:19:58 +01:00
'ref' => array ( 'type' => 'varchar(30)' , 'label' => 'Ref' , 'default' => 1 , 'enabled' => 1 , 'visible' => - 1 , 'notnull' => 1 , 'position' => 12 , 'index' => 1 ),
2020-02-24 22:53:14 +01:00
'entity' => array ( 'type' => 'integer' , 'label' => 'Entity' , 'default' => 1 , 'enabled' => 1 , 'visible' => - 2 , 'notnull' => 1 , 'position' => 15 , 'index' => 1 ),
'ref_ext' => array ( 'type' => 'varchar(128)' , 'label' => 'Ref ext' , 'enabled' => 1 , 'visible' => 0 , 'position' => 20 ),
'civility' => array ( 'type' => 'varchar(6)' , 'label' => 'Civility' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 25 ),
2021-06-05 15:14:10 +02:00
'lastname' => array ( 'type' => 'varchar(50)' , 'label' => 'Lastname' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 30 , 'showoncombobox' => 1 ),
'firstname' => array ( 'type' => 'varchar(50)' , 'label' => 'Firstname' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 35 , 'showoncombobox' => 1 ),
2020-02-24 22:53:14 +01:00
'login' => array ( 'type' => 'varchar(50)' , 'label' => 'Login' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 40 ),
'gender' => array ( 'type' => 'varchar(10)' , 'label' => 'Gender' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 250 ),
'pass' => array ( 'type' => 'varchar(50)' , 'label' => 'Pass' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 45 ),
'pass_crypted' => array ( 'type' => 'varchar(128)' , 'label' => 'Pass crypted' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 50 ),
'fk_adherent_type' => array ( 'type' => 'integer' , 'label' => 'Fk adherent type' , 'enabled' => 1 , 'visible' => - 1 , 'notnull' => 1 , 'position' => 55 ),
'morphy' => array ( 'type' => 'varchar(3)' , 'label' => 'MorPhy' , 'enabled' => 1 , 'visible' => - 1 , 'notnull' => 1 , 'position' => 60 ),
2021-06-05 15:14:10 +02:00
'societe' => array ( 'type' => 'varchar(128)' , 'label' => 'Societe' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 65 , 'showoncombobox' => 2 ),
2020-02-24 22:53:14 +01:00
'fk_soc' => array ( 'type' => 'integer:Societe:societe/class/societe.class.php' , 'label' => 'ThirdParty' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 70 ),
'address' => array ( 'type' => 'text' , 'label' => 'Address' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 75 ),
'zip' => array ( 'type' => 'varchar(10)' , 'label' => 'Zip' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 80 ),
'town' => array ( 'type' => 'varchar(50)' , 'label' => 'Town' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 85 ),
'state_id' => array ( 'type' => 'integer' , 'label' => 'State id' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 90 ),
2020-04-13 01:10:35 +02:00
'country' => array ( 'type' => 'integer:Ccountry:core/class/ccountry.class.php' , 'label' => 'Country' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 95 ),
2020-02-24 22:53:14 +01:00
'email' => array ( 'type' => 'varchar(255)' , 'label' => 'Email' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 100 ),
2021-04-17 14:15:16 +02:00
'url' => array ( 'type' => 'varchar(255)' , 'label' => 'Url' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 110 ),
2020-02-24 22:53:14 +01:00
'socialnetworks' => array ( 'type' => 'text' , 'label' => 'Socialnetworks' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 105 ),
'phone' => array ( 'type' => 'varchar(30)' , 'label' => 'Phone' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 115 ),
'phone_perso' => array ( 'type' => 'varchar(30)' , 'label' => 'Phone perso' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 120 ),
'phone_mobile' => array ( 'type' => 'varchar(30)' , 'label' => 'Phone mobile' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 125 ),
2020-09-16 00:47:44 +02:00
'birth' => array ( 'type' => 'date' , 'label' => 'DateOfBirth' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 130 ),
2020-02-24 22:53:14 +01:00
'photo' => array ( 'type' => 'varchar(255)' , 'label' => 'Photo' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 135 ),
'public' => array ( 'type' => 'smallint(6)' , 'label' => 'Public' , 'enabled' => 1 , 'visible' => - 1 , 'notnull' => 1 , 'position' => 145 ),
'datefin' => array ( 'type' => 'datetime' , 'label' => 'DateEnd' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 150 ),
2022-09-06 05:30:35 +02:00
'note_private' => array ( 'type' => 'text' , 'label' => 'NotePrivate' , 'enabled' => 1 , 'visible' => 0 , 'position' => 155 ),
'note_public' => array ( 'type' => 'text' , 'label' => 'NotePublic' , 'enabled' => 1 , 'visible' => 0 , 'position' => 160 ),
2020-02-24 22:53:14 +01:00
'datevalid' => array ( 'type' => 'datetime' , 'label' => 'DateValidation' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 165 ),
'datec' => array ( 'type' => 'datetime' , 'label' => 'DateCreation' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 170 ),
'tms' => array ( 'type' => 'timestamp' , 'label' => 'DateModification' , 'enabled' => 1 , 'visible' => - 1 , 'notnull' => 1 , 'position' => 175 ),
'fk_user_author' => array ( 'type' => 'integer:User:user/class/user.class.php' , 'label' => 'Fk user author' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 180 ),
'fk_user_mod' => array ( 'type' => 'integer:User:user/class/user.class.php' , 'label' => 'Fk user mod' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 185 ),
'fk_user_valid' => array ( 'type' => 'integer:User:user/class/user.class.php' , 'label' => 'UserValidation' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 190 ),
'canvas' => array ( 'type' => 'varchar(32)' , 'label' => 'Canvas' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 195 ),
'statut' => array ( 'type' => 'smallint(6)' , 'label' => 'Statut' , 'enabled' => 1 , 'visible' => - 1 , 'notnull' => 1 , 'position' => 500 ,
2021-04-27 20:53:14 +02:00
'arrayofkeyval' => array ( - 1 => 'Draft' , 1 => 'Validated' , 0 => 'MemberStatusResiliatedShort' , - 2 => 'MemberStatusExcludedShort' )),
2020-02-24 22:53:14 +01:00
'model_pdf' => array ( 'type' => 'varchar(255)' , 'label' => 'Model pdf' , 'enabled' => 1 , 'visible' => 0 , 'position' => 800 ),
2020-11-01 08:48:53 +01:00
'import_key' => array ( 'type' => 'varchar(14)' , 'label' => 'ImportId' , 'enabled' => 1 , 'visible' => - 2 , 'position' => 805 )
);
2020-02-08 13:44:31 +01:00
2021-04-27 19:45:56 +02:00
/**
* Draft status
*/
2021-04-27 20:45:04 +02:00
const STATUS_DRAFT = - 1 ;
2021-04-27 19:45:56 +02:00
/**
* Validated status
*/
const STATUS_VALIDATED = 1 ;
/**
* Resiliated
*/
2021-04-27 20:45:04 +02:00
const STATUS_RESILIATED = 0 ;
2021-04-27 19:45:56 +02:00
/**
* Excluded
*/
const STATUS_EXCLUDED = - 2 ;
2020-02-08 13:44:31 +01:00
2017-10-07 13:09:31 +02:00
/**
2011-09-03 02:19:56 +02:00
* Constructor
*
2011-12-30 14:18:19 +01:00
* @ param DoliDB $db Database handler
2017-10-07 13:09:31 +02:00
*/
2019-02-25 00:56:48 +01:00
public function __construct ( $db )
2017-10-07 13:09:31 +02:00
{
$this -> db = $db ;
2021-04-28 17:33:37 +02:00
$this -> statut = self :: STATUS_DRAFT ;
2021-04-28 17:29:52 +02:00
$this -> status = $this -> statut ;
2017-10-07 13:09:31 +02:00
// l'adherent n'est pas public par defaut
$this -> public = 0 ;
// les champs optionnels sont vides
2020-02-02 19:34:09 +01:00
$this -> array_options = array ();
2017-10-07 13:09:31 +02:00
}
2020-02-24 22:53:14 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
2018-10-06 20:51:35 +02:00
* Function sending an email to the current member with the text supplied in parameter .
2017-10-07 13:09:31 +02: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
2018-10-06 20:51:35 +02:00
* @ param string $moreinheader Add more html headers
2017-10-07 13:09:31 +02:00
* @ return int < 0 if KO , > 0 if OK
*/
2019-02-25 00:56:48 +01:00
public 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 = '' , $moreinheader = '' )
2017-10-07 13:09:31 +02:00
{
2020-02-24 22:53:14 +01:00
// phpcs:enable
2020-02-02 19:34:09 +01:00
global $conf , $langs ;
2017-10-07 13:09:31 +02:00
// Detect if message is HTML
2020-02-24 22:53:14 +01:00
if ( $msgishtml == - 1 ) {
2017-10-07 13:09:31 +02:00
$msgishtml = 0 ;
2021-03-01 00:19:52 +01:00
if ( dol_textishtml ( $text , 0 )) {
$msgishtml = 1 ;
}
2017-10-07 13:09:31 +02:00
}
2020-03-12 12:45:44 +01:00
dol_syslog ( 'send_an_email msgishtml=' . $msgishtml );
2018-03-25 15:00:43 +02:00
2020-02-02 19:34:09 +01:00
$texttosend = $this -> makeSubstitution ( $text );
$subjecttosend = $this -> makeSubstitution ( $subject );
2021-03-01 00:19:52 +01:00
if ( $msgishtml ) {
$texttosend = dol_htmlentitiesbr ( $texttosend );
}
2017-10-07 13:09:31 +02:00
// Envoi mail confirmation
2020-02-02 19:34:09 +01:00
$from = $conf -> email_from ;
2021-03-01 00:19:52 +01:00
if ( ! empty ( $conf -> global -> ADHERENT_MAIL_FROM )) {
$from = $conf -> global -> ADHERENT_MAIL_FROM ;
}
2017-10-07 13:09:31 +02:00
2020-03-12 12:45:44 +01:00
$trackid = 'mem' . $this -> id ;
2018-10-06 20:51:35 +02:00
2017-10-07 13:09:31 +02:00
// Send email (substitutionarray must be done just before this)
2020-03-12 12:45:44 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php' ;
2018-10-06 20:51:35 +02:00
$mailfile = new CMailFile ( $subjecttosend , $this -> email , $from , $texttosend , $filename_list , $mimetype_list , $mimefilename_list , $addr_cc , $addr_bcc , $deliveryreceipt , $msgishtml , '' , '' , $trackid , $moreinheader );
2020-02-24 22:53:14 +01:00
if ( $mailfile -> sendfile ()) {
2017-10-07 13:09:31 +02:00
return 1 ;
2020-02-24 22:53:14 +01:00
} else {
2020-03-12 12:45:44 +01:00
$this -> error = $langs -> trans ( " ErrorFailedToSendMail " , $from , $this -> email ) . '. ' . $mailfile -> error ;
2017-10-07 13:09:31 +02:00
return - 1 ;
}
}
/**
* Make substitution of tags into text with value of current object .
*
* @ param string $text Text to make substitution to
* @ return string Value of input text string with substitutions done
*/
2019-02-25 00:56:48 +01:00
public function makeSubstitution ( $text )
2012-03-31 10:14:45 +02:00
{
2020-02-02 19:34:09 +01:00
global $conf , $langs ;
2012-05-09 15:22:09 +02:00
2019-01-27 11:55:16 +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 ;
2021-03-01 00:19:52 +01:00
if ( dol_textishtml ( $text , 1 )) {
$msgishtml = 1 ;
}
2012-05-09 15:22:09 +02:00
2020-02-02 19:34:09 +01:00
$infos = '' ;
2021-03-01 00:19:52 +01:00
if ( $this -> civility_id ) {
$infos .= $langs -> transnoentities ( " UserTitle " ) . " : " . $this -> getCivilityLabel () . " \n " ;
}
2020-03-12 12:45:44 +01:00
$infos .= $langs -> transnoentities ( " id " ) . " : " . $this -> id . " \n " ;
2020-11-10 22:19:58 +01:00
$infos .= $langs -> transnoentities ( " ref " ) . " : " . $this -> ref . " \n " ;
2020-03-12 12:45:44 +01:00
$infos .= $langs -> transnoentities ( " Lastname " ) . " : " . $this -> lastname . " \n " ;
$infos .= $langs -> transnoentities ( " Firstname " ) . " : " . $this -> firstname . " \n " ;
$infos .= $langs -> transnoentities ( " Company " ) . " : " . $this -> company . " \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 " ;
$infos .= $langs -> transnoentities ( " PhonePro " ) . " : " . $this -> phone . " \n " ;
$infos .= $langs -> transnoentities ( " PhonePerso " ) . " : " . $this -> phone_perso . " \n " ;
$infos .= $langs -> transnoentities ( " PhoneMobile " ) . " : " . $this -> phone_mobile . " \n " ;
2020-02-24 22:53:14 +01:00
if ( empty ( $conf -> global -> ADHERENT_LOGIN_NOT_REQUIRED )) {
2020-03-12 12:45:44 +01:00
$infos .= $langs -> transnoentities ( " Login " ) . " : " . $this -> login . " \n " ;
$infos .= $langs -> transnoentities ( " Password " ) . " : " . $this -> pass . " \n " ;
2020-02-24 22:53:14 +01:00
}
2020-03-12 12:45:44 +01:00
$infos .= $langs -> transnoentities ( " Birthday " ) . " : " . $birthday . " \n " ;
$infos .= $langs -> transnoentities ( " Photo " ) . " : " . $this -> photo . " \n " ;
$infos .= $langs -> transnoentities ( " Public " ) . " : " . yn ( $this -> public );
2017-10-07 13:09:31 +02:00
// Substitutions
2020-11-01 08:48:53 +01:00
$substitutionarray = array (
2020-11-10 22:19:58 +01:00
'__ID__' => $this -> id ,
'__REF__' => $this -> ref ,
'__MEMBER_ID__' => $this -> id ,
'__CIVILITY__' => $this -> getCivilityLabel (),
2020-02-24 22:53:14 +01:00
'__FIRSTNAME__' => $msgishtml ? dol_htmlentitiesbr ( $this -> firstname ) : ( $this -> firstname ? $this -> firstname : '' ),
'__LASTNAME__' => $msgishtml ? dol_htmlentitiesbr ( $this -> lastname ) : ( $this -> lastname ? $this -> lastname : '' ),
'__FULLNAME__' => $msgishtml ? dol_htmlentitiesbr ( $this -> getFullName ( $langs )) : $this -> getFullName ( $langs ),
'__COMPANY__' => $msgishtml ? dol_htmlentitiesbr ( $this -> company ) : ( $this -> company ? $this -> company : '' ),
'__ADDRESS__' => $msgishtml ? dol_htmlentitiesbr ( $this -> address ) : ( $this -> address ? $this -> address : '' ),
2020-11-10 22:19:58 +01:00
'__ZIP__' => $msgishtml ? dol_htmlentitiesbr ( $this -> zip ) : ( $this -> zip ? $this -> zip : '' ),
'__TOWN__' => $msgishtml ? dol_htmlentitiesbr ( $this -> town ) : ( $this -> town ? $this -> town : '' ),
2020-02-24 22:53:14 +01:00
'__COUNTRY__' => $msgishtml ? dol_htmlentitiesbr ( $this -> country ) : ( $this -> country ? $this -> country : '' ),
2020-11-10 22:19:58 +01:00
'__EMAIL__' => $msgishtml ? dol_htmlentitiesbr ( $this -> email ) : ( $this -> email ? $this -> email : '' ),
'__BIRTH__' => $msgishtml ? dol_htmlentitiesbr ( $birthday ) : ( $birthday ? $birthday : '' ),
2020-02-24 22:53:14 +01:00
'__PHOTO__' => $msgishtml ? dol_htmlentitiesbr ( $this -> photo ) : ( $this -> photo ? $this -> photo : '' ),
'__LOGIN__' => $msgishtml ? dol_htmlentitiesbr ( $this -> login ) : ( $this -> login ? $this -> login : '' ),
'__PASSWORD__' => $msgishtml ? dol_htmlentitiesbr ( $this -> pass ) : ( $this -> pass ? $this -> pass : '' ),
'__PHONE__' => $msgishtml ? dol_htmlentitiesbr ( $this -> phone ) : ( $this -> phone ? $this -> phone : '' ),
'__PHONEPRO__' => $msgishtml ? dol_htmlentitiesbr ( $this -> phone_perso ) : ( $this -> phone_perso ? $this -> phone_perso : '' ),
2020-08-19 21:19:56 +02:00
'__PHONEMOBILE__' => $msgishtml ? dol_htmlentitiesbr ( $this -> phone_mobile ) : ( $this -> phone_mobile ? $this -> phone_mobile : '' ),
2020-11-01 08:48:53 +01:00
'__TYPE__' => $msgishtml ? dol_htmlentitiesbr ( $this -> type ) : ( $this -> type ? $this -> type : '' )
);
2017-10-07 13:09:31 +02:00
complete_substitutions_array ( $substitutionarray , $langs , $this );
return make_substitutions ( $text , $substitutionarray , $langs );
}
/**
* Return translated label by the nature of a adherent ( physical or moral )
*
* @ param string $morphy Nature of the adherent ( physical or moral )
* @ return string Label
*/
2019-02-25 00:56:48 +01:00
public function getmorphylib ( $morphy = '' )
2017-10-07 13:09:31 +02:00
{
global $langs ;
2020-02-24 22:53:14 +01:00
if ( ! $morphy ) {
$morphy = $this -> morphy ;
}
if ( $morphy == 'phy' ) {
return $langs -> trans ( " Physical " );
}
if ( $morphy == 'mor' ) {
return $langs -> trans ( " Moral " );
}
2017-10-07 13:09:31 +02:00
return $morphy ;
}
/**
* Create a member into database
*
* @ 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
*/
2019-02-25 00:56:48 +01:00
public function create ( $user , $notrigger = 0 )
2017-10-07 13:09:31 +02:00
{
2020-02-02 19:34:09 +01:00
global $conf , $langs ;
2017-10-07 13:09:31 +02:00
2020-02-02 19:34:09 +01:00
$error = 0 ;
2017-10-07 13:09:31 +02:00
2020-02-02 19:34:09 +01:00
$now = dol_now ();
2017-10-07 13:09:31 +02:00
// Clean parameters
$this -> import_key = trim ( $this -> import_key );
// Check parameters
2020-02-24 22:53:14 +01:00
if ( ! empty ( $conf -> global -> ADHERENT_MAIL_REQUIRED ) && ! isValidEMail ( $this -> email )) {
2017-10-07 13:09:31 +02:00
$langs -> load ( " errors " );
2019-01-27 11:55:16 +01:00
$this -> error = $langs -> trans ( " ErrorBadEMail " , $this -> email );
2017-10-07 13:09:31 +02:00
return - 1 ;
}
2021-03-01 00:19:52 +01:00
if ( ! $this -> datec ) {
$this -> datec = $now ;
}
2020-02-24 22:53:14 +01:00
if ( empty ( $conf -> global -> ADHERENT_LOGIN_NOT_REQUIRED )) {
if ( empty ( $this -> login )) {
2019-01-27 11:55:16 +01:00
$this -> error = $langs -> trans ( " ErrorWrongValueForParameterX " , " Login " );
2017-10-07 13:09:31 +02:00
return - 1 ;
}
}
$this -> db -> begin ();
// Insert member
2020-03-12 12:45:44 +01:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " adherent " ;
2020-11-11 12:17:23 +01:00
$sql .= " (ref, datec,login,fk_user_author,fk_user_mod,fk_user_valid,morphy,fk_adherent_type,entity,import_key) " ;
2020-02-02 19:34:09 +01:00
$sql .= " VALUES ( " ;
2020-11-11 12:17:23 +01:00
$sql .= " '(PROV)' " ;
$sql .= " , ' " . $this -> db -> idate ( $this -> datec ) . " ' " ;
2020-03-12 12:45:44 +01:00
$sql .= " , " . ( $this -> login ? " ' " . $this -> db -> escape ( $this -> login ) . " ' " : " null " );
$sql .= " , " . ( $user -> id > 0 ? $user -> id : " null " ); // Can be null because member can be created by a guest or a script
$sql .= " , null, null, ' " . $this -> db -> escape ( $this -> morphy ) . " ' " ;
2021-09-03 21:25:17 +02:00
$sql .= " , " . (( int ) $this -> typeid );
2020-03-12 12:45:44 +01:00
$sql .= " , " . $conf -> entity ;
$sql .= " , " . ( ! empty ( $this -> import_key ) ? " ' " . $this -> db -> escape ( $this -> import_key ) . " ' " : " null " );
2020-02-02 19:34:09 +01:00
$sql .= " ) " ;
2017-10-07 13:09:31 +02:00
2020-03-12 12:45:44 +01:00
dol_syslog ( get_class ( $this ) . " ::create " , LOG_DEBUG );
2017-10-07 13:09:31 +02:00
$result = $this -> db -> query ( $sql );
2020-02-24 22:53:14 +01:00
if ( $result ) {
2020-03-12 12:45:44 +01:00
$id = $this -> db -> last_insert_id ( MAIN_DB_PREFIX . " adherent " );
2020-02-24 22:53:14 +01:00
if ( $id > 0 ) {
2020-02-02 19:34:09 +01:00
$this -> id = $id ;
$this -> ref = ( string ) $id ;
2017-10-07 13:09:31 +02:00
// Update minor fields
2020-02-02 19:34:09 +01:00
$result = $this -> update ( $user , 1 , 1 , 0 , 0 , 'add' ); // nosync is 1 to avoid update data of user
2020-02-24 22:53:14 +01:00
if ( $result < 0 ) {
2017-10-07 13:09:31 +02:00
$this -> db -> rollback ();
return - 1 ;
}
// Add link to user
2020-02-24 22:53:14 +01:00
if ( $this -> user_id ) {
2017-10-07 13:09:31 +02:00
// Add link to user
2020-03-12 12:45:44 +01:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " user SET " ;
2021-06-09 15:36:47 +02:00
$sql .= " fk_member = " . (( int ) $this -> id );
$sql .= " WHERE rowid = " . (( int ) $this -> user_id );
2020-03-12 12:45:44 +01:00
dol_syslog ( get_class ( $this ) . " ::create " , LOG_DEBUG );
2017-10-07 13:09:31 +02:00
$resql = $this -> db -> query ( $sql );
2020-02-24 22:53:14 +01:00
if ( ! $resql ) {
2020-02-02 19:34:09 +01:00
$this -> error = 'Failed to update user to make link with member' ;
2017-10-07 13:09:31 +02:00
$this -> db -> rollback ();
return - 4 ;
}
}
2020-02-24 22:53:14 +01:00
if ( ! $notrigger ) {
2017-10-07 13:09:31 +02:00
// Call trigger
2020-02-02 19:34:09 +01:00
$result = $this -> call_trigger ( 'MEMBER_CREATE' , $user );
2020-02-24 22:53:14 +01:00
if ( $result < 0 ) {
$error ++ ;
}
2017-10-07 13:09:31 +02:00
// End call triggers
}
2020-02-24 22:53:14 +01:00
if ( count ( $this -> errors )) {
2020-03-12 12:45:44 +01:00
dol_syslog ( get_class ( $this ) . " ::create " . implode ( ',' , $this -> errors ), LOG_ERR );
2017-10-07 13:09:31 +02:00
$this -> db -> rollback ();
return - 3 ;
2020-02-24 22:53:14 +01:00
} else {
2017-10-07 13:09:31 +02:00
$this -> db -> commit ();
return $this -> id ;
}
2020-02-24 22:53:14 +01:00
} else {
2020-02-02 19:34:09 +01:00
$this -> error = 'Failed to get last insert id' ;
2020-03-12 12:45:44 +01:00
dol_syslog ( get_class ( $this ) . " ::create " . $this -> error , LOG_ERR );
2017-10-07 13:09:31 +02:00
$this -> db -> rollback ();
return - 2 ;
}
2020-02-24 22:53:14 +01:00
} else {
2020-02-02 19:34:09 +01:00
$this -> error = $this -> db -> error ();
2017-10-07 13:09:31 +02:00
$this -> db -> rollback ();
return - 1 ;
}
}
/**
* Update a member in database ( standard information and password )
*
* @ 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
* @ param string $action Current action for hookmanager
* @ return int < 0 if KO , > 0 if OK
*/
2019-02-25 00:56:48 +01:00
public function update ( $user , $notrigger = 0 , $nosyncuser = 0 , $nosyncuserpass = 0 , $nosyncthirdparty = 0 , $action = 'update' )
2017-10-07 13:09:31 +02:00
{
global $conf , $langs , $hookmanager ;
2022-08-31 17:17:43 +02:00
2022-08-30 17:26:18 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php' ;
2022-08-30 17:33:18 +02:00
2020-02-02 19:34:09 +01:00
$nbrowsaffected = 0 ;
$error = 0 ;
2017-10-07 13:09:31 +02:00
2022-02-28 11:53:29 +01:00
dol_syslog ( get_class ( $this ) . " ::update notrigger= " . $notrigger . " , nosyncuser= " . $nosyncuser . " , nosyncuserpass= " . $nosyncuserpass . " nosyncthirdparty= " . $nosyncthirdparty . " , email= " . $this -> email );
2017-10-07 13:09:31 +02:00
// Clean parameters
2020-02-24 22:53:14 +01:00
$this -> lastname = trim ( $this -> lastname ) ? trim ( $this -> lastname ) : trim ( $this -> lastname );
$this -> firstname = trim ( $this -> firstname ) ? trim ( $this -> firstname ) : trim ( $this -> firstname );
$this -> gender = trim ( $this -> gender );
$this -> address = ( $this -> address ? $this -> address : $this -> address );
$this -> zip = ( $this -> zip ? $this -> zip : $this -> zip );
$this -> town = ( $this -> town ? $this -> town : $this -> town );
$this -> country_id = ( $this -> country_id > 0 ? $this -> country_id : $this -> country_id );
$this -> state_id = ( $this -> state_id > 0 ? $this -> state_id : $this -> state_id );
2020-10-28 19:10:54 +01:00
$this -> setUpperOrLowerCase ();
2020-02-24 22:53:14 +01:00
$this -> note_public = ( $this -> note_public ? $this -> note_public : $this -> note_public );
2020-02-02 19:34:09 +01:00
$this -> note_private = ( $this -> note_private ? $this -> note_private : $this -> note_private );
2021-04-17 14:15:16 +02:00
$this -> url = $this -> url ? clean_url ( $this -> url , 0 ) : '' ;
2017-10-07 13:09:31 +02:00
// Check parameters
2020-02-24 22:53:14 +01:00
if ( ! empty ( $conf -> global -> ADHERENT_MAIL_REQUIRED ) && ! isValidEMail ( $this -> email )) {
2017-10-07 13:09:31 +02:00
$langs -> load ( " errors " );
2019-01-27 11:55:16 +01:00
$this -> error = $langs -> trans ( " ErrorBadEMail " , $this -> email );
2017-10-07 13:09:31 +02:00
return - 1 ;
}
$this -> db -> begin ();
2020-03-12 12:45:44 +01:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " adherent SET " ;
2020-11-10 22:19:58 +01:00
$sql .= " ref = ' " . $this -> db -> escape ( $this -> ref ) . " ' " ;
$sql .= " , civility = " . ( $this -> civility_id ? " ' " . $this -> db -> escape ( $this -> civility_id ) . " ' " : " null " );
2020-03-12 12:45:44 +01:00
$sql .= " , firstname = " . ( $this -> firstname ? " ' " . $this -> db -> escape ( $this -> firstname ) . " ' " : " null " );
$sql .= " , lastname = " . ( $this -> lastname ? " ' " . $this -> db -> escape ( $this -> lastname ) . " ' " : " null " );
$sql .= " , gender = " . ( $this -> gender != - 1 ? " ' " . $this -> db -> escape ( $this -> gender ) . " ' " : " null " ); // 'man' or 'woman'
$sql .= " , login = " . ( $this -> login ? " ' " . $this -> db -> escape ( $this -> login ) . " ' " : " null " );
$sql .= " , societe = " . ( $this -> company ? " ' " . $this -> db -> escape ( $this -> company ) . " ' " : ( $this -> societe ? " ' " . $this -> db -> escape ( $this -> societe ) . " ' " : " null " ));
2022-02-28 11:53:29 +01:00
if ( $this -> socid ) {
$sql .= " , fk_soc = " . ( $this -> socid > 0 ? $this -> db -> escape ( $this -> socid ) : " null " ); // Must be modified only when creating from a third-party
}
2020-03-12 12:45:44 +01:00
$sql .= " , address = " . ( $this -> address ? " ' " . $this -> db -> escape ( $this -> address ) . " ' " : " null " );
$sql .= " , zip = " . ( $this -> zip ? " ' " . $this -> db -> escape ( $this -> zip ) . " ' " : " null " );
$sql .= " , town = " . ( $this -> town ? " ' " . $this -> db -> escape ( $this -> town ) . " ' " : " null " );
$sql .= " , country = " . ( $this -> country_id > 0 ? $this -> db -> escape ( $this -> country_id ) : " null " );
$sql .= " , state_id = " . ( $this -> state_id > 0 ? $this -> db -> escape ( $this -> state_id ) : " null " );
$sql .= " , email = ' " . $this -> db -> escape ( $this -> email ) . " ' " ;
2021-04-17 14:15:16 +02:00
$sql .= " , url = " . ( ! empty ( $this -> url ) ? " ' " . $this -> db -> escape ( $this -> url ) . " ' " : " null " );
2022-11-23 16:59:40 +01:00
$sql .= " , socialnetworks = " . ( $this -> socialnetworks ? " ' " . $this -> db -> escape ( json_encode ( $this -> socialnetworks )) . " ' " : " null " );
2020-03-12 12:45:44 +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_private = " . ( $this -> note_private ? " ' " . $this -> db -> escape ( $this -> note_private ) . " ' " : " null " );
$sql .= " , note_public = " . ( $this -> note_public ? " ' " . $this -> db -> escape ( $this -> note_public ) . " ' " : " null " );
$sql .= " , photo = " . ( $this -> photo ? " ' " . $this -> db -> escape ( $this -> photo ) . " ' " : " null " );
$sql .= " , public = ' " . $this -> db -> escape ( $this -> public ) . " ' " ;
$sql .= " , statut = " . $this -> db -> escape ( $this -> statut );
$sql .= " , fk_adherent_type = " . $this -> db -> escape ( $this -> typeid );
$sql .= " , morphy = ' " . $this -> db -> escape ( $this -> morphy ) . " ' " ;
$sql .= " , birth = " . ( $this -> birth ? " ' " . $this -> db -> idate ( $this -> birth ) . " ' " : " null " );
2021-03-01 00:19:52 +01:00
if ( $this -> datefin ) {
$sql .= " , datefin = ' " . $this -> db -> idate ( $this -> datefin ) . " ' " ; // Must be modified only when deleting a subscription
}
if ( $this -> datevalid ) {
$sql .= " , datevalid = ' " . $this -> db -> idate ( $this -> datevalid ) . " ' " ; // Must be modified only when validating a member
}
2020-03-12 12:45:44 +01:00
$sql .= " , fk_user_mod = " . ( $user -> id > 0 ? $user -> id : 'null' ); // Can be null because member can be create by a guest
2021-03-30 17:53:25 +02:00
$sql .= " WHERE rowid = " . (( int ) $this -> id );
2017-10-07 13:09:31 +02:00
2019-03-07 12:43:17 +01:00
// If we change the type of membership, we set also label of new type
2020-02-24 22:53:14 +01:00
if ( ! empty ( $this -> oldcopy ) && $this -> typeid != $this -> oldcopy -> typeid ) {
2019-03-07 12:43:17 +01:00
$sql2 = " SELECT libelle as label " ;
2020-03-12 12:45:44 +01:00
$sql2 .= " FROM " . MAIN_DB_PREFIX . " adherent_type " ;
2021-06-09 15:36:47 +02:00
$sql2 .= " WHERE rowid = " . (( int ) $this -> typeid );
2019-03-07 12:43:17 +01:00
$resql2 = $this -> db -> query ( $sql2 );
2020-02-24 22:53:14 +01:00
if ( $resql2 ) {
while ( $obj = $this -> db -> fetch_object ( $resql2 )) {
2020-02-02 19:34:09 +01:00
$this -> type = $obj -> label ;
2020-02-24 22:53:14 +01:00
}
2019-03-07 12:43:17 +01:00
}
}
2019-03-15 20:06:05 +01:00
2020-03-12 12:45:44 +01:00
dol_syslog ( get_class ( $this ) . " ::update update member " , LOG_DEBUG );
2017-10-07 13:09:31 +02:00
$resql = $this -> db -> query ( $sql );
2020-02-24 22:53:14 +01:00
if ( $resql ) {
2017-10-07 13:09:31 +02:00
unset ( $this -> country_code );
unset ( $this -> country );
unset ( $this -> state_code );
unset ( $this -> state );
2020-02-02 19:34:09 +01:00
$nbrowsaffected += $this -> db -> affected_rows ( $resql );
2017-10-07 13:09:31 +02:00
2020-02-02 19:34:09 +01:00
$action = 'update' ;
2017-10-07 13:09:31 +02:00
2018-04-10 12:03:01 +02:00
// Actions on extra fields
2020-05-21 09:12:18 +02:00
if ( ! $error ) {
2020-02-02 19:34:09 +01:00
$result = $this -> insertExtraFields ();
2020-02-24 22:53:14 +01:00
if ( $result < 0 ) {
2018-04-10 12:03:01 +02:00
$error ++ ;
2017-10-07 13:09:31 +02:00
}
}
// Update password
2020-02-24 22:53:14 +01:00
if ( ! $error && $this -> pass ) {
2020-03-12 12:45:44 +01:00
dol_syslog ( get_class ( $this ) . " ::update update password " );
2020-02-24 22:53:14 +01:00
if ( $this -> pass != $this -> pass_indatabase && $this -> pass != $this -> pass_indatabase_crypted ) {
2020-02-02 19:34:09 +01:00
$isencrypted = empty ( $conf -> global -> DATABASE_PWD_ENCRYPTED ) ? 0 : 1 ;
2017-10-07 13:09:31 +02:00
// If password to set differs from the one found into database
2020-02-02 19:34:09 +01:00
$result = $this -> setPassword ( $user , $this -> pass , $isencrypted , $notrigger , $nosyncuserpass );
2021-03-01 00:19:52 +01:00
if ( ! $nbrowsaffected ) {
$nbrowsaffected ++ ;
}
2017-10-07 13:09:31 +02:00
}
}
// Remove links to user and replace with new one
2020-02-24 22:53:14 +01:00
if ( ! $error ) {
2020-03-12 12:45:44 +01:00
dol_syslog ( get_class ( $this ) . " ::update update link to user " );
2021-08-27 16:33:03 +02:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " user SET fk_member = NULL WHERE fk_member = " . (( int ) $this -> id );
2020-03-12 12:45:44 +01:00
dol_syslog ( get_class ( $this ) . " ::update " , LOG_DEBUG );
2017-10-07 13:09:31 +02:00
$resql = $this -> db -> query ( $sql );
2020-02-24 22:53:14 +01:00
if ( ! $resql ) {
$this -> error = $this -> db -> error ();
$this -> db -> rollback ();
return - 5 ;
}
2017-10-07 13:09:31 +02:00
// If there is a user linked to this member
2020-02-24 22:53:14 +01:00
if ( $this -> user_id > 0 ) {
2021-08-27 16:33:03 +02:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " user SET fk_member = " . (( int ) $this -> id ) . " WHERE rowid = " . (( int ) $this -> user_id );
2020-03-12 12:45:44 +01:00
dol_syslog ( get_class ( $this ) . " ::update " , LOG_DEBUG );
2017-10-07 13:09:31 +02:00
$resql = $this -> db -> query ( $sql );
2020-02-24 22:53:14 +01:00
if ( ! $resql ) {
$this -> error = $this -> db -> error ();
$this -> db -> rollback ();
return - 5 ;
}
2017-10-07 13:09:31 +02:00
}
}
2020-05-21 09:12:18 +02:00
if ( ! $error && $nbrowsaffected ) { // If something has change in main data
2017-10-07 13:09:31 +02:00
// Update information on linked user if it is an update
2020-02-24 22:53:14 +01:00
if ( ! $error && $this -> user_id > 0 && ! $nosyncuser ) {
2020-03-12 12:45:44 +01:00
require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php' ;
2017-10-07 13:09:31 +02:00
2020-03-12 12:45:44 +01:00
dol_syslog ( get_class ( $this ) . " ::update update linked user " );
2017-10-07 13:09:31 +02:00
2020-02-02 19:34:09 +01:00
$luser = new User ( $this -> db );
$result = $luser -> fetch ( $this -> user_id );
2017-10-07 13:09:31 +02:00
2020-02-24 22:53:14 +01:00
if ( $result >= 0 ) {
2017-10-07 13:09:31 +02:00
//var_dump($this->user_login);exit;
//var_dump($this->login);exit;
2018-01-20 18:42:12 +01:00
// If option ADHERENT_LOGIN_NOT_REQUIRED is on, there is no login of member, so we do not overwrite user login to keep existing one.
2021-03-01 00:19:52 +01:00
if ( empty ( $conf -> global -> ADHERENT_LOGIN_NOT_REQUIRED )) {
$luser -> login = $this -> login ;
}
2018-01-20 18:42:12 +01:00
2020-11-10 22:19:58 +01:00
$luser -> ref = $this -> ref ;
2020-02-02 19:34:09 +01:00
$luser -> civility_id = $this -> civility_id ;
$luser -> firstname = $this -> firstname ;
$luser -> lastname = $this -> lastname ;
$luser -> gender = $this -> gender ;
$luser -> pass = $this -> pass ;
2019-09-01 22:21:48 +02:00
//$luser->socid=$this->fk_soc; // We do not enable this. This may transform a user into an external user.
2017-10-07 13:09:31 +02:00
2020-02-02 19:34:09 +01:00
$luser -> birth = $this -> birth ;
2018-12-14 11:39:02 +01:00
2020-02-02 19:34:09 +01:00
$luser -> address = $this -> address ;
$luser -> zip = $this -> zip ;
$luser -> town = $this -> town ;
$luser -> country_id = $this -> country_id ;
$luser -> state_id = $this -> state_id ;
2018-08-29 15:37:35 +02:00
2020-02-02 19:34:09 +01:00
$luser -> email = $this -> email ;
$luser -> socialnetworks = $this -> socialnetworks ;
$luser -> office_phone = $this -> phone ;
$luser -> user_mobile = $this -> phone_mobile ;
2017-10-07 13:09:31 +02:00
2020-02-02 19:34:09 +01:00
$luser -> fk_member = $this -> id ;
2017-10-07 13:09:31 +02:00
2020-02-02 19:34:09 +01:00
$result = $luser -> update ( $user , 0 , 1 , 1 ); // Use nosync to 1 to avoid cyclic updates
2020-02-24 22:53:14 +01:00
if ( $result < 0 ) {
2020-02-02 19:34:09 +01:00
$this -> error = $luser -> error ;
2020-03-12 12:45:44 +01:00
dol_syslog ( get_class ( $this ) . " ::update " . $this -> error , LOG_ERR );
2017-10-07 13:09:31 +02:00
$error ++ ;
}
2020-02-24 22:53:14 +01:00
} else {
2020-02-02 19:34:09 +01:00
$this -> error = $luser -> error ;
2017-10-07 13:09:31 +02:00
$error ++ ;
}
}
// Update information on linked thirdparty if it is an update
2020-02-24 22:53:14 +01:00
if ( ! $error && $this -> fk_soc > 0 && ! $nosyncthirdparty ) {
2020-03-12 12:45:44 +01:00
require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php' ;
2017-10-07 13:09:31 +02:00
2020-03-12 12:45:44 +01:00
dol_syslog ( get_class ( $this ) . " ::update update linked thirdparty " );
2017-10-07 13:09:31 +02:00
// This member is linked with a thirdparty, so we also update thirdparty informations
// if this is an update.
2020-02-02 19:34:09 +01:00
$lthirdparty = new Societe ( $this -> db );
$result = $lthirdparty -> fetch ( $this -> fk_soc );
2017-10-07 13:09:31 +02:00
2020-02-24 22:53:14 +01:00
if ( $result > 0 ) {
2020-02-02 19:34:09 +01:00
$lthirdparty -> address = $this -> address ;
$lthirdparty -> zip = $this -> zip ;
$lthirdparty -> town = $this -> town ;
$lthirdparty -> email = $this -> email ;
$lthirdparty -> socialnetworks = $this -> socialnetworks ;
$lthirdparty -> phone = $this -> phone ;
$lthirdparty -> state_id = $this -> state_id ;
$lthirdparty -> country_id = $this -> country_id ;
2017-10-07 13:09:31 +02:00
//$lthirdparty->phone_mobile=$this->phone_mobile;
2020-02-02 19:34:09 +01:00
$result = $lthirdparty -> update ( $this -> fk_soc , $user , 0 , 1 , 1 , 'update' ); // Use sync to 0 to avoid cyclic updates
2018-12-18 21:27:16 +01:00
2020-02-24 22:53:14 +01:00
if ( $result < 0 ) {
2020-02-02 19:34:09 +01:00
$this -> error = $lthirdparty -> error ;
$this -> errors = $lthirdparty -> errors ;
2020-03-12 12:45:44 +01:00
dol_syslog ( get_class ( $this ) . " ::update " . $this -> error , LOG_ERR );
2017-10-07 13:09:31 +02:00
$error ++ ;
}
2020-02-24 22:53:14 +01:00
} elseif ( $result < 0 ) {
2020-02-02 19:34:09 +01:00
$this -> error = $lthirdparty -> error ;
2017-10-07 13:09:31 +02:00
$error ++ ;
}
}
2018-06-14 14:01:05 +02:00
}
2017-10-07 13:09:31 +02:00
2020-02-24 22:53:14 +01:00
if ( ! $error && ! $notrigger ) {
2018-06-14 14:01:05 +02:00
// Call trigger
2020-02-02 19:34:09 +01:00
$result = $this -> call_trigger ( 'MEMBER_MODIFY' , $user );
2020-02-24 22:53:14 +01:00
if ( $result < 0 ) {
$error ++ ;
}
2018-06-14 14:01:05 +02:00
// End call triggers
2017-10-07 13:09:31 +02:00
}
2020-02-24 22:53:14 +01:00
if ( ! $error ) {
2017-10-07 13:09:31 +02:00
$this -> db -> commit ();
return $nbrowsaffected ;
2020-02-24 22:53:14 +01:00
} else {
2017-10-07 13:09:31 +02:00
$this -> db -> rollback ();
return - 1 ;
}
2020-02-24 22:53:14 +01:00
} else {
2017-10-07 13:09:31 +02:00
$this -> db -> rollback ();
2020-02-02 19:34:09 +01:00
$this -> error = $this -> db -> lasterror ();
2017-10-07 13:09:31 +02:00
return - 2 ;
}
}
2020-02-24 22:53:14 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
* Update denormalized last subscription date .
* This function is called when we delete a subscription for example .
*
* @ param User $user User making change
* @ return int < 0 if KO , > 0 if OK
*/
2019-02-25 00:56:48 +01:00
public function update_end_date ( $user )
2017-10-07 13:09:31 +02:00
{
2020-02-24 22:53:14 +01:00
// phpcs:enable
2017-10-07 13:09:31 +02:00
$this -> db -> begin ();
// Search for last subscription id and end date
$sql = " SELECT rowid, datec as dateop, dateadh as datedeb, datef as datefin " ;
2020-03-12 12:45:44 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " subscription " ;
2021-08-27 16:33:03 +02:00
$sql .= " WHERE fk_adherent = " . (( int ) $this -> id );
2020-02-02 19:34:09 +01:00
$sql .= " ORDER by dateadh DESC " ; // Sort by start subscription date
2017-10-07 13:09:31 +02:00
2020-03-12 12:45:44 +01:00
dol_syslog ( get_class ( $this ) . " ::update_end_date " , LOG_DEBUG );
2020-02-02 19:34:09 +01:00
$resql = $this -> db -> query ( $sql );
2020-02-24 22:53:14 +01:00
if ( $resql ) {
2020-02-02 19:34:09 +01:00
$obj = $this -> db -> fetch_object ( $resql );
$dateop = $this -> db -> jdate ( $obj -> dateop );
$datedeb = $this -> db -> jdate ( $obj -> datedeb );
$datefin = $this -> db -> jdate ( $obj -> datefin );
2017-10-07 13:09:31 +02:00
2020-03-12 12:45:44 +01:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " adherent SET " ;
$sql .= " datefin= " . ( $datefin != '' ? " ' " . $this -> db -> idate ( $datefin ) . " ' " : " null " );
2021-08-27 16:33:03 +02:00
$sql .= " WHERE rowid = " . (( int ) $this -> id );
2017-10-07 13:09:31 +02:00
2020-03-12 12:45:44 +01:00
dol_syslog ( get_class ( $this ) . " ::update_end_date " , LOG_DEBUG );
2020-02-02 19:34:09 +01:00
$resql = $this -> db -> query ( $sql );
2020-02-24 22:53:14 +01:00
if ( $resql ) {
2020-02-02 19:34:09 +01:00
$this -> last_subscription_date = $dateop ;
$this -> last_subscription_date_start = $datedeb ;
$this -> last_subscription_date_end = $datefin ;
$this -> datefin = $datefin ;
2017-10-07 13:09:31 +02:00
$this -> db -> commit ();
return 1 ;
2020-02-24 22:53:14 +01:00
} else {
2017-10-07 13:09:31 +02:00
$this -> db -> rollback ();
return - 1 ;
}
2020-02-24 22:53:14 +01:00
} else {
2020-02-02 19:34:09 +01:00
$this -> error = $this -> db -> lasterror ();
2017-10-07 13:09:31 +02:00
$this -> db -> rollback ();
return - 1 ;
}
}
/**
2022-08-12 12:17:49 +02:00
* Fonction to delete a member and its data
2017-10-07 13:09:31 +02:00
*
* @ param int $rowid Id of member to delete
2022-08-12 12:17:49 +02:00
* @ param User $user User object
2017-10-07 13:09:31 +02:00
* @ param int $notrigger 1 = Does not execute triggers , 0 = execute triggers
* @ return int < 0 if KO , 0 = nothing to do , > 0 if OK
*/
2019-02-25 00:56:48 +01:00
public function delete ( $rowid , $user , $notrigger = 0 )
2017-10-07 13:09:31 +02:00
{
global $conf , $langs ;
$result = 0 ;
2020-02-02 19:34:09 +01:00
$error = 0 ;
$errorflag = 0 ;
2017-10-07 13:09:31 +02:00
// Check parameters
2021-03-01 00:19:52 +01:00
if ( empty ( $rowid )) {
$rowid = $this -> id ;
}
2017-10-07 13:09:31 +02:00
$this -> db -> begin ();
2020-02-24 22:53:14 +01:00
if ( ! $error && ! $notrigger ) {
2017-10-07 13:09:31 +02:00
// Call trigger
2020-02-02 19:34:09 +01:00
$result = $this -> call_trigger ( 'MEMBER_DELETE' , $user );
2021-03-01 00:19:52 +01:00
if ( $result < 0 ) {
$error ++ ;
}
2017-10-07 13:09:31 +02:00
// End call triggers
}
// Remove category
2021-03-30 17:53:25 +02:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " categorie_member WHERE fk_member = " . (( int ) $rowid );
2020-03-12 12:45:44 +01:00
dol_syslog ( get_class ( $this ) . " ::delete " , LOG_DEBUG );
2020-02-02 19:34:09 +01:00
$resql = $this -> db -> query ( $sql );
2020-02-24 22:53:14 +01:00
if ( ! $resql ) {
2017-10-07 13:09:31 +02:00
$error ++ ;
$this -> error .= $this -> db -> lasterror ();
2020-02-02 19:34:09 +01:00
$errorflag = - 1 ;
2017-10-07 13:09:31 +02:00
}
// Remove subscription
2020-02-24 22:53:14 +01:00
if ( ! $error ) {
2021-03-30 17:53:25 +02:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " subscription WHERE fk_adherent = " . (( int ) $rowid );
2020-03-12 12:45:44 +01:00
dol_syslog ( get_class ( $this ) . " ::delete " , LOG_DEBUG );
2020-02-02 19:34:09 +01:00
$resql = $this -> db -> query ( $sql );
2020-02-24 22:53:14 +01:00
if ( ! $resql ) {
2017-10-07 13:09:31 +02:00
$error ++ ;
$this -> error .= $this -> db -> lasterror ();
2020-02-02 19:34:09 +01:00
$errorflag = - 2 ;
2017-10-07 13:09:31 +02:00
}
}
// Remove linked user
2020-02-24 22:53:14 +01:00
if ( ! $error ) {
2020-02-02 19:34:09 +01:00
$ret = $this -> setUserId ( 0 );
2020-02-24 22:53:14 +01:00
if ( $ret < 0 ) {
2017-10-07 13:09:31 +02:00
$error ++ ;
$this -> error .= $this -> db -> lasterror ();
2020-02-02 19:34:09 +01:00
$errorflag = - 3 ;
2017-10-07 13:09:31 +02:00
}
}
// Removed extrafields
2020-02-24 22:53:14 +01:00
if ( ! $error ) {
2020-04-23 13:21:39 +02:00
$result = $this -> deleteExtraFields ();
if ( $result < 0 ) {
$error ++ ;
$errorflag = - 4 ;
dol_syslog ( get_class ( $this ) . " ::delete erreur " . $errorflag . " " . $this -> error , LOG_ERR );
2017-10-07 13:09:31 +02:00
}
}
// Remove adherent
2020-02-24 22:53:14 +01:00
if ( ! $error ) {
2021-03-30 17:53:25 +02:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " adherent WHERE rowid = " . (( int ) $rowid );
2020-03-12 12:45:44 +01:00
dol_syslog ( get_class ( $this ) . " ::delete " , LOG_DEBUG );
2020-02-02 19:34:09 +01:00
$resql = $this -> db -> query ( $sql );
2020-02-24 22:53:14 +01:00
if ( ! $resql ) {
2017-10-07 13:09:31 +02:00
$error ++ ;
$this -> error .= $this -> db -> lasterror ();
2020-02-02 19:34:09 +01:00
$errorflag = - 5 ;
2017-10-07 13:09:31 +02:00
}
}
2020-02-24 22:53:14 +01:00
if ( ! $error ) {
2017-10-07 13:09:31 +02:00
$this -> db -> commit ();
return 1 ;
2020-02-24 22:53:14 +01:00
} else {
2017-10-07 13:09:31 +02:00
$this -> db -> rollback ();
return $errorflag ;
}
}
/**
* Change password of a user
*
* @ 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
*/
2019-02-25 00:56:48 +01:00
public function setPassword ( $user , $password = '' , $isencrypted = 0 , $notrigger = 0 , $nosyncuser = 0 )
2017-10-07 13:09:31 +02:00
{
global $conf , $langs ;
2020-02-02 19:34:09 +01:00
$error = 0 ;
2017-10-07 13:09:31 +02:00
2020-03-12 12:45:44 +01:00
dol_syslog ( get_class ( $this ) . " ::setPassword user= " . $user -> id . " password= " . preg_replace ( '/./i' , '*' , $password ) . " isencrypted= " . $isencrypted );
2017-10-07 13:09:31 +02:00
// If new password not provided, we generate one
2020-02-24 22:53:14 +01:00
if ( ! $password ) {
2020-03-12 12:45:44 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/security2.lib.php' ;
2020-02-02 19:34:09 +01:00
$password = getRandomPassword ( false );
2017-10-07 13:09:31 +02:00
}
// Crypt password
$password_crypted = dol_hash ( $password );
$password_indatabase = '' ;
2020-02-24 22:53:14 +01:00
if ( ! $isencrypted ) {
2017-10-07 13:09:31 +02:00
$password_indatabase = $password ;
}
$this -> db -> begin ();
// Mise a jour
2020-03-12 12:45:44 +01:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " adherent " ;
$sql .= " SET pass_crypted = ' " . $this -> db -> escape ( $password_crypted ) . " ' " ;
2017-10-07 13:09:31 +02:00
//if (! empty($conf->global->DATABASE_PWD_ENCRYPTED))
2020-02-24 22:53:14 +01:00
if ( $isencrypted ) {
2020-02-02 19:34:09 +01:00
$sql .= " , pass = null " ;
2020-02-24 22:53:14 +01:00
} else {
2020-03-12 12:45:44 +01:00
$sql .= " , pass = ' " . $this -> db -> escape ( $password_indatabase ) . " ' " ;
2017-10-07 13:09:31 +02:00
}
2021-08-27 16:33:03 +02:00
$sql .= " WHERE rowid = " . (( int ) $this -> id );
2017-10-07 13:09:31 +02:00
//dol_syslog("Adherent::Password sql=hidden");
2020-03-12 12:45:44 +01:00
dol_syslog ( get_class ( $this ) . " ::setPassword " , LOG_DEBUG );
2017-10-07 13:09:31 +02:00
$result = $this -> db -> query ( $sql );
2020-02-24 22:53:14 +01:00
if ( $result ) {
2020-02-02 19:34:09 +01:00
$nbaffectedrows = $this -> db -> affected_rows ( $result );
2017-10-07 13:09:31 +02:00
2020-02-24 22:53:14 +01:00
if ( $nbaffectedrows ) {
2020-02-02 19:34:09 +01:00
$this -> pass = $password ;
$this -> pass_indatabase = $password_indatabase ;
$this -> pass_indatabase_crypted = $password_crypted ;
2017-10-07 13:09:31 +02:00
2020-02-24 22:53:14 +01:00
if ( $this -> user_id && ! $nosyncuser ) {
2020-03-12 12:45:44 +01:00
require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php' ;
2017-10-07 13:09:31 +02:00
// This member is linked with a user, so we also update users informations
// if this is an update.
2020-02-02 19:34:09 +01:00
$luser = new User ( $this -> db );
$result = $luser -> fetch ( $this -> user_id );
2017-10-07 13:09:31 +02:00
2020-02-24 22:53:14 +01:00
if ( $result >= 0 ) {
2020-02-02 19:34:09 +01:00
$result = $luser -> setPassword ( $user , $this -> pass , 0 , 0 , 1 );
2020-02-24 22:53:14 +01:00
if ( $result < 0 ) {
2020-02-02 19:34:09 +01:00
$this -> error = $luser -> error ;
2020-03-12 12:45:44 +01:00
dol_syslog ( get_class ( $this ) . " ::setPassword " . $this -> error , LOG_ERR );
2017-10-07 13:09:31 +02:00
$error ++ ;
}
2020-02-24 22:53:14 +01:00
} else {
2020-02-02 19:34:09 +01:00
$this -> error = $luser -> error ;
2017-10-07 13:09:31 +02:00
$error ++ ;
}
}
2020-02-24 22:53:14 +01:00
if ( ! $error && ! $notrigger ) {
2017-10-07 13:09:31 +02:00
// Call trigger
2020-02-02 19:34:09 +01:00
$result = $this -> call_trigger ( 'MEMBER_NEW_PASSWORD' , $user );
2020-02-24 22:53:14 +01:00
if ( $result < 0 ) {
$error ++ ;
$this -> db -> rollback ();
return - 1 ;
}
2017-10-07 13:09:31 +02:00
// End call triggers
}
$this -> db -> commit ();
return $this -> pass ;
2020-02-24 22:53:14 +01:00
} else {
2017-10-07 13:09:31 +02:00
$this -> db -> rollback ();
return 0 ;
}
2020-02-24 22:53:14 +01:00
} else {
2017-10-07 13:09:31 +02:00
$this -> db -> rollback ();
dol_print_error ( $this -> db );
return - 1 ;
}
}
/**
* Set link to a user
*
* @ param int $userid Id of user to link to
* @ return int 1 = OK , - 1 = KO
*/
2019-02-25 00:56:48 +01:00
public function setUserId ( $userid )
2017-10-07 13:09:31 +02:00
{
global $conf , $langs ;
$this -> db -> begin ();
// If user is linked to this member, remove old link to this member
2021-03-24 18:57:23 +01:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " user SET fk_member = NULL WHERE fk_member = " . (( int ) $this -> id );
2020-03-12 12:45:44 +01:00
dol_syslog ( get_class ( $this ) . " ::setUserId " , LOG_DEBUG );
2017-10-07 13:09:31 +02:00
$resql = $this -> db -> query ( $sql );
2020-02-24 22:53:14 +01:00
if ( ! $resql ) {
$this -> error = $this -> db -> error ();
$this -> db -> rollback ();
return - 1 ;
}
2017-10-07 13:09:31 +02:00
// Set link to user
2020-02-24 22:53:14 +01:00
if ( $userid > 0 ) {
2021-03-24 18:57:23 +01:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " user SET fk_member = " . (( int ) $this -> id );
2021-03-30 17:53:25 +02:00
$sql .= " WHERE rowid = " . (( int ) $userid );
2020-03-12 12:45:44 +01:00
dol_syslog ( get_class ( $this ) . " ::setUserId " , LOG_DEBUG );
2017-10-07 13:09:31 +02:00
$resql = $this -> db -> query ( $sql );
2020-02-24 22:53:14 +01:00
if ( ! $resql ) {
$this -> error = $this -> db -> error ();
$this -> db -> rollback ();
return - 2 ;
}
2017-10-07 13:09:31 +02:00
}
$this -> db -> commit ();
return 1 ;
}
/**
* Set link to a third party
*
* @ param int $thirdpartyid Id of user to link to
* @ return int 1 = OK , - 1 = KO
*/
2019-02-25 00:56:48 +01:00
public function setThirdPartyId ( $thirdpartyid )
2017-10-07 13:09:31 +02:00
{
global $conf , $langs ;
$this -> db -> begin ();
// Remove link to third party onto any other members
2020-02-24 22:53:14 +01:00
if ( $thirdpartyid > 0 ) {
2020-03-12 12:45:44 +01:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " adherent SET fk_soc = null " ;
2020-09-19 20:11:04 +02:00
$sql .= " WHERE fk_soc = " . (( int ) $thirdpartyid );
2020-03-12 12:45:44 +01:00
$sql .= " AND entity = " . $conf -> entity ;
dol_syslog ( get_class ( $this ) . " ::setThirdPartyId " , LOG_DEBUG );
2017-10-07 13:09:31 +02:00
$resql = $this -> db -> query ( $sql );
}
// Add link to third party for current member
2020-03-12 12:45:44 +01:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " adherent SET fk_soc = " . ( $thirdpartyid > 0 ? $thirdpartyid : 'null' );
2021-08-27 16:33:03 +02:00
$sql .= " WHERE rowid = " . (( int ) $this -> id );
2017-10-07 13:09:31 +02:00
2020-03-12 12:45:44 +01:00
dol_syslog ( get_class ( $this ) . " ::setThirdPartyId " , LOG_DEBUG );
2017-10-07 13:09:31 +02:00
$resql = $this -> db -> query ( $sql );
2020-02-24 22:53:14 +01:00
if ( $resql ) {
2017-10-07 13:09:31 +02:00
$this -> db -> commit ();
return 1 ;
2020-02-24 22:53:14 +01:00
} else {
2020-02-02 19:34:09 +01:00
$this -> error = $this -> db -> error ();
2017-10-07 13:09:31 +02:00
$this -> db -> rollback ();
return - 1 ;
}
}
2020-02-24 22:53:14 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
* Method to load member from its login
*
* @ param string $login login of member
* @ return void
*/
2019-02-25 00:56:48 +01:00
public function fetch_login ( $login )
2017-10-07 13:09:31 +02:00
{
2020-02-24 22:53:14 +01:00
// phpcs:enable
2017-10-07 13:09:31 +02:00
global $conf ;
2020-03-12 12:45:44 +01:00
$sql = " SELECT rowid FROM " . MAIN_DB_PREFIX . " adherent " ;
$sql .= " WHERE login=' " . $this -> db -> escape ( $login ) . " ' " ;
$sql .= " AND entity = " . $conf -> entity ;
2017-10-07 13:09:31 +02:00
2020-02-02 19:34:09 +01:00
$resql = $this -> db -> query ( $sql );
2020-02-24 22:53:14 +01:00
if ( $resql ) {
if ( $this -> db -> num_rows ( $resql )) {
2017-10-07 13:09:31 +02:00
$obj = $this -> db -> fetch_object ( $resql );
$this -> fetch ( $obj -> rowid );
}
2020-02-24 22:53:14 +01:00
} else {
2017-10-07 13:09:31 +02:00
dol_print_error ( $this -> db );
}
}
2020-02-24 22:53:14 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
* Method to load member from its name
*
* @ param string $firstname Firstname
* @ param string $lastname Lastname
* @ return void
*/
2019-02-25 00:56:48 +01:00
public function fetch_name ( $firstname , $lastname )
2017-10-07 13:09:31 +02:00
{
2020-02-24 22:53:14 +01:00
// phpcs:enable
2017-10-07 13:09:31 +02:00
global $conf ;
2020-03-12 12:45:44 +01:00
$sql = " SELECT rowid FROM " . MAIN_DB_PREFIX . " adherent " ;
$sql .= " WHERE firstname=' " . $this -> db -> escape ( $firstname ) . " ' " ;
$sql .= " AND lastname=' " . $this -> db -> escape ( $lastname ) . " ' " ;
$sql .= " AND entity = " . $conf -> entity ;
2017-10-07 13:09:31 +02:00
2020-02-02 19:34:09 +01:00
$resql = $this -> db -> query ( $sql );
2020-02-24 22:53:14 +01:00
if ( $resql ) {
if ( $this -> db -> num_rows ( $resql )) {
2017-10-07 13:09:31 +02:00
$obj = $this -> db -> fetch_object ( $resql );
$this -> fetch ( $obj -> rowid );
}
2020-02-24 22:53:14 +01:00
} else {
2017-10-07 13:09:31 +02:00
dol_print_error ( $this -> db );
}
}
/**
* Load member from database
*
2018-03-28 10:06:00 +02: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
* @ param string $ref_ext External reference
* @ param bool $fetch_optionals To load optionals ( extrafields )
* @ param bool $fetch_subscriptions To load member subscriptions
* @ return int > 0 if OK , 0 if not found , < 0 if KO
2017-10-07 13:09:31 +02:00
*/
2019-02-25 00:56:48 +01:00
public function fetch ( $rowid , $ref = '' , $fk_soc = '' , $ref_ext = '' , $fetch_optionals = true , $fetch_subscriptions = true )
2017-10-07 13:09:31 +02:00
{
global $langs ;
2020-11-10 22:19:58 +01:00
$sql = " SELECT d.rowid, d.ref, d.ref_ext, d.civility as civility_code, d.gender, d.firstname, d.lastname, " ;
$sql .= " d.societe as company, d.fk_soc, d.statut, d.public, d.address, d.zip, d.town, d.note_private, " ;
2020-02-02 19:34:09 +01:00
$sql .= " d.note_public, " ;
2021-04-17 14:15:16 +02:00
$sql .= " d.email, d.url, d.socialnetworks, d.phone, d.phone_perso, d.phone_mobile, d.login, d.pass, d.pass_crypted, " ;
2020-02-02 19:34:09 +01:00
$sql .= " d.photo, d.fk_adherent_type, d.morphy, d.entity, " ;
$sql .= " d.datec as datec, " ;
$sql .= " d.tms as datem, " ;
$sql .= " d.datefin as datefin, " ;
$sql .= " d.birth as birthday, " ;
$sql .= " d.datevalid as datev, " ;
$sql .= " d.country, " ;
$sql .= " d.state_id, " ;
$sql .= " d.model_pdf, " ;
$sql .= " c.rowid as country_id, c.code as country_code, c.label as country, " ;
$sql .= " dep.nom as state, dep.code_departement as state_code, " ;
$sql .= " t.libelle as type, t.subscription as subscription, " ;
$sql .= " u.rowid as user_id, u.login as user_login " ;
2020-03-12 12:45:44 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " adherent_type as t, " . MAIN_DB_PREFIX . " adherent as d " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " c_country as c ON d.country = c.rowid " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " c_departements as dep ON d.state_id = dep.rowid " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " user as u ON d.rowid = u.fk_member " ;
2020-02-02 19:34:09 +01:00
$sql .= " WHERE d.fk_adherent_type = t.rowid " ;
2020-12-04 14:53:52 +01:00
if ( $rowid ) {
$sql .= " AND d.rowid= " . (( int ) $rowid );
} elseif ( $ref || $fk_soc ) {
2020-03-12 12:45:44 +01:00
$sql .= " AND d.entity IN ( " . getEntity ( 'adherent' ) . " ) " ;
2020-12-04 14:53:52 +01:00
if ( $ref ) {
2020-11-10 22:19:58 +01:00
$sql .= " AND d.ref=' " . $this -> db -> escape ( $ref ) . " ' " ;
2020-12-04 14:53:52 +01:00
} elseif ( $fk_soc > 0 ) {
$sql .= " AND d.fk_soc= " . (( int ) $fk_soc );
}
2020-02-24 22:53:14 +01:00
} elseif ( $ref_ext ) {
2020-03-12 12:45:44 +01:00
$sql .= " AND d.ref_ext=' " . $this -> db -> escape ( $ref_ext ) . " ' " ;
2017-10-07 13:09:31 +02:00
}
2020-03-12 12:45:44 +01:00
dol_syslog ( get_class ( $this ) . " ::fetch " , LOG_DEBUG );
2020-02-02 19:34:09 +01:00
$resql = $this -> db -> query ( $sql );
2020-02-24 22:53:14 +01:00
if ( $resql ) {
if ( $this -> db -> num_rows ( $resql )) {
2017-10-07 13:09:31 +02:00
$obj = $this -> db -> fetch_object ( $resql );
2020-02-02 19:34:09 +01:00
$this -> entity = $obj -> entity ;
$this -> id = $obj -> rowid ;
2020-11-10 22:19:58 +01:00
$this -> ref = $obj -> ref ;
2020-02-02 19:34:09 +01:00
$this -> ref_ext = $obj -> ref_ext ;
2019-06-18 20:01:28 +02:00
2020-02-24 22:53:14 +01:00
$this -> civility_id = $obj -> civility_code ; // Bad. Kept for backard compatibility
$this -> civility_code = $obj -> civility_code ;
2020-03-12 12:45:44 +01:00
$this -> civility = $obj -> civility_code ? ( $langs -> trans ( " Civility " . $obj -> civility_code ) != ( " Civility " . $obj -> civility_code ) ? $langs -> trans ( " Civility " . $obj -> civility_code ) : $obj -> civility_code ) : '' ;
2019-04-27 14:53:14 +02:00
2020-02-24 22:53:14 +01:00
$this -> firstname = $obj -> firstname ;
$this -> lastname = $obj -> lastname ;
2020-02-02 19:34:09 +01:00
$this -> gender = $obj -> gender ;
2020-02-24 22:53:14 +01:00
$this -> login = $obj -> login ;
$this -> societe = $obj -> company ;
$this -> company = $obj -> company ;
$this -> socid = $obj -> fk_soc ;
2020-02-02 19:34:09 +01:00
$this -> fk_soc = $obj -> fk_soc ; // For backward compatibility
2020-02-24 22:53:14 +01:00
$this -> address = $obj -> address ;
2020-02-02 19:34:09 +01:00
$this -> zip = $obj -> zip ;
2020-02-24 22:53:14 +01:00
$this -> town = $obj -> town ;
2017-10-07 13:09:31 +02:00
2020-02-24 22:53:14 +01:00
$this -> pass = $obj -> pass ;
2020-02-02 19:34:09 +01:00
$this -> pass_indatabase = $obj -> pass ;
2017-10-07 13:09:31 +02:00
$this -> pass_indatabase_crypted = $obj -> pass_crypted ;
2020-02-02 19:34:09 +01:00
$this -> state_id = $obj -> state_id ;
2020-02-24 22:53:14 +01:00
$this -> state_code = $obj -> state_id ? $obj -> state_code : '' ;
2020-02-02 19:34:09 +01:00
$this -> state = $obj -> state_id ? $obj -> state : '' ;
2017-10-07 13:09:31 +02:00
2020-02-24 22:53:14 +01:00
$this -> country_id = $obj -> country_id ;
2020-02-02 19:34:09 +01:00
$this -> country_code = $obj -> country_code ;
2020-05-21 00:47:16 +02:00
if ( $langs -> trans ( " Country " . $obj -> country_code ) != " Country " . $obj -> country_code ) {
2020-03-12 12:45:44 +01:00
$this -> country = $langs -> transnoentitiesnoconv ( " Country " . $obj -> country_code );
2020-05-21 00:47:16 +02:00
} else {
2020-02-02 19:34:09 +01:00
$this -> country = $obj -> country ;
2020-05-21 00:47:16 +02:00
}
2017-10-07 13:09:31 +02:00
2020-02-24 22:53:14 +01:00
$this -> phone = $obj -> phone ;
2020-02-02 19:34:09 +01:00
$this -> phone_perso = $obj -> phone_perso ;
$this -> phone_mobile = $obj -> phone_mobile ;
2020-02-24 22:53:14 +01:00
$this -> email = $obj -> email ;
2021-04-17 14:15:16 +02:00
$this -> url = $obj -> url ;
2018-10-12 11:12:29 +02:00
2019-10-01 20:14:06 +02:00
$this -> socialnetworks = ( array ) json_decode ( $obj -> socialnetworks , true );
2017-10-07 13:09:31 +02:00
2020-02-02 19:34:09 +01:00
$this -> photo = $obj -> photo ;
2020-02-24 22:53:14 +01:00
$this -> statut = $obj -> statut ;
2021-11-27 17:19:16 +01:00
$this -> status = $obj -> statut ;
2020-02-24 22:53:14 +01:00
$this -> public = $obj -> public ;
2017-10-07 13:09:31 +02:00
2020-02-24 22:53:14 +01:00
$this -> datec = $this -> db -> jdate ( $obj -> datec );
$this -> date_creation = $this -> db -> jdate ( $obj -> datec );
$this -> datem = $this -> db -> jdate ( $obj -> datem );
$this -> date_modification = $this -> db -> jdate ( $obj -> datem );
2020-02-02 19:34:09 +01:00
$this -> datefin = $this -> db -> jdate ( $obj -> datefin );
$this -> datevalid = $this -> db -> jdate ( $obj -> datev );
2020-02-24 22:53:14 +01:00
$this -> date_validation = $this -> db -> jdate ( $obj -> datev );
2020-02-02 19:34:09 +01:00
$this -> birth = $this -> db -> jdate ( $obj -> birthday );
$this -> note_private = $obj -> note_private ;
$this -> note_public = $obj -> note_public ;
2020-02-24 22:53:14 +01:00
$this -> morphy = $obj -> morphy ;
2017-10-07 13:09:31 +02:00
2020-02-24 22:53:14 +01:00
$this -> typeid = $obj -> fk_adherent_type ;
2020-02-02 19:34:09 +01:00
$this -> type = $obj -> type ;
$this -> need_subscription = $obj -> subscription ;
2017-10-07 13:09:31 +02:00
2020-02-02 19:34:09 +01:00
$this -> user_id = $obj -> user_id ;
$this -> user_login = $obj -> user_login ;
2017-10-07 13:09:31 +02:00
2020-02-02 19:34:09 +01:00
$this -> model_pdf = $obj -> model_pdf ;
2017-10-07 13:09:31 +02:00
2020-10-23 20:08:35 +02:00
// Retrieve all extrafield
2017-10-07 13:09:31 +02:00
// fetch optionals attributes and labels
2018-03-28 10:06:00 +02:00
if ( $fetch_optionals ) {
$this -> fetch_optionals ();
}
2017-10-07 13:09:31 +02:00
// Load other properties
2018-03-28 10:06:00 +02:00
if ( $fetch_subscriptions ) {
2020-02-02 19:34:09 +01:00
$result = $this -> fetch_subscriptions ();
2018-03-28 10:06:00 +02:00
}
2017-10-07 13:09:31 +02:00
return $this -> id ;
2020-02-24 22:53:14 +01:00
} else {
2017-10-07 13:09:31 +02:00
return 0 ;
}
2020-02-24 22:53:14 +01:00
} else {
2020-02-02 19:34:09 +01:00
$this -> error = $this -> db -> lasterror ();
2017-10-07 13:09:31 +02:00
return - 1 ;
}
}
2020-02-24 22:53:14 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
2021-06-07 10:08:31 +02:00
* Function to get member subscriptions data :
* subscriptions ,
* first_subscription_date , first_subscription_date_start , first_subscription_date_end , first_subscription_amount
* last_subscription_date , last_subscription_date_start , last_subscription_date_end , last_subscription_amount
2017-10-07 13:09:31 +02:00
*
2021-06-07 10:08:31 +02:00
* @ return int < 0 if KO , > 0 if OK
2017-10-07 13:09:31 +02:00
*/
2019-02-25 00:56:48 +01:00
public function fetch_subscriptions ()
2017-10-07 13:09:31 +02:00
{
2020-02-24 22:53:14 +01:00
// phpcs:enable
2017-10-07 13:09:31 +02:00
global $langs ;
2020-03-12 12:45:44 +01:00
require_once DOL_DOCUMENT_ROOT . '/adherents/class/subscription.class.php' ;
2017-10-07 13:09:31 +02:00
2020-03-03 11:58:15 +01:00
$sql = " SELECT c.rowid, c.fk_adherent, c.fk_type, c.subscription, c.note, c.fk_bank, " ;
2020-02-02 19:34:09 +01:00
$sql .= " c.tms as datem, " ;
$sql .= " c.datec as datec, " ;
$sql .= " c.dateadh as dateh, " ;
$sql .= " c.datef as datef " ;
2020-03-12 12:45:44 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " subscription as c " ;
2021-08-27 16:33:03 +02:00
$sql .= " WHERE c.fk_adherent = " . (( int ) $this -> id );
2020-02-02 19:34:09 +01:00
$sql .= " ORDER BY c.dateadh " ;
2020-03-12 12:45:44 +01:00
dol_syslog ( get_class ( $this ) . " ::fetch_subscriptions " , LOG_DEBUG );
2017-10-07 13:09:31 +02:00
2020-02-02 19:34:09 +01:00
$resql = $this -> db -> query ( $sql );
2020-02-24 22:53:14 +01:00
if ( $resql ) {
2020-02-02 19:34:09 +01:00
$this -> subscriptions = array ();
2017-10-07 13:09:31 +02:00
2020-02-02 19:34:09 +01:00
$i = 0 ;
2020-02-24 22:53:14 +01:00
while ( $obj = $this -> db -> fetch_object ( $resql )) {
if ( $i == 0 ) {
2020-02-02 19:34:09 +01:00
$this -> first_subscription_date = $this -> db -> jdate ( $obj -> datec );
$this -> first_subscription_date_start = $this -> db -> jdate ( $obj -> dateh );
$this -> first_subscription_date_end = $this -> db -> jdate ( $obj -> datef );
$this -> first_subscription_amount = $obj -> subscription ;
2017-10-07 13:09:31 +02:00
}
2020-02-02 19:34:09 +01:00
$this -> last_subscription_date = $this -> db -> jdate ( $obj -> datec );
2021-06-05 14:43:40 +02:00
$this -> last_subscription_date_start = $this -> db -> jdate ( $obj -> dateh );
2020-02-02 19:34:09 +01:00
$this -> last_subscription_date_end = $this -> db -> jdate ( $obj -> datef );
$this -> last_subscription_amount = $obj -> subscription ;
$subscription = new Subscription ( $this -> db );
$subscription -> id = $obj -> rowid ;
$subscription -> fk_adherent = $obj -> fk_adherent ;
2020-03-03 11:58:15 +01:00
$subscription -> fk_type = $obj -> fk_type ;
2020-02-02 19:34:09 +01:00
$subscription -> amount = $obj -> subscription ;
$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 -> dateh = $this -> db -> jdate ( $obj -> dateh );
$subscription -> datef = $this -> db -> jdate ( $obj -> datef );
$this -> subscriptions [] = $subscription ;
2017-10-07 13:09:31 +02:00
$i ++ ;
}
return 1 ;
2020-02-24 22:53:14 +01:00
} else {
2020-03-12 12:45:44 +01:00
$this -> error = $this -> db -> error () . ' sql=' . $sql ;
2017-10-07 13:09:31 +02:00
return - 1 ;
}
}
2021-06-07 10:08:31 +02:00
/**
* Function to get partnerships array
*
* @ param string $mode 'member' or 'thirdparty'
* @ return int < 0 if KO , > 0 if OK
*/
public function fetchPartnerships ( $mode )
{
global $langs ;
2021-11-17 10:07:05 +01:00
require_once DOL_DOCUMENT_ROOT . '/partnership/class/partnership.class.php' ;
2021-06-07 10:08:31 +02:00
$this -> partnerships [] = array ();
return 1 ;
}
2017-10-07 13:09:31 +02:00
/**
* Insert subscription into database and eventually add links to banks , mailman , etc ...
*
* @ param int $date Date of effect of subscription
2018-03-05 21:46:24 +01:00
* @ param double $amount Amount of subscription ( 0 accepted for some members )
2022-04-08 15:15:55 +02:00
* @ param int $accountid Id bank account . NOT USED .
* @ param string $operation Code of payment mode ( if Id bank account provided ) . Example : 'CB' , ... NOT USED .
* @ param string $label Label operation ( if Id bank account provided ) .
2017-10-07 13:09:31 +02:00
* @ param string $num_chq Numero cheque ( if Id bank account provided )
* @ param string $emetteur_nom Name of cheque writer
* @ param string $emetteur_banque Name of bank of cheque
* @ param int $datesubend Date end subscription
2021-04-09 02:40:21 +02:00
* @ param int $fk_type Member type id
2017-10-07 13:09:31 +02:00
* @ return int rowid of record added , < 0 if KO
*/
2021-04-09 02:28:07 +02:00
public function subscription ( $date , $amount , $accountid = 0 , $operation = '' , $label = '' , $num_chq = '' , $emetteur_nom = '' , $emetteur_banque = '' , $datesubend = 0 , $fk_type = null )
2017-10-07 13:09:31 +02:00
{
2020-02-02 19:34:09 +01:00
global $conf , $langs , $user ;
2017-10-07 13:09:31 +02:00
2020-03-12 12:45:44 +01:00
require_once DOL_DOCUMENT_ROOT . '/adherents/class/subscription.class.php' ;
2017-10-07 13:09:31 +02:00
2020-02-02 19:34:09 +01:00
$error = 0 ;
2017-10-07 13:09:31 +02:00
// Clean parameters
2021-03-01 00:19:52 +01:00
if ( ! $amount ) {
$amount = 0 ;
}
2017-10-07 13:09:31 +02:00
$this -> db -> begin ();
2020-02-24 22:53:14 +01:00
if ( $datesubend ) {
2020-02-02 19:34:09 +01:00
$datefin = $datesubend ;
2020-02-24 22:53:14 +01:00
} else {
2017-10-07 13:09:31 +02:00
// If no end date, end date = date + 1 year - 1 day
2019-01-27 11:55:16 +01:00
$datefin = dol_time_plus_duree ( $date , 1 , 'y' );
$datefin = dol_time_plus_duree ( $datefin , - 1 , 'd' );
2017-10-07 13:09:31 +02:00
}
// Create subscription
2020-02-02 19:34:09 +01:00
$subscription = new Subscription ( $this -> db );
$subscription -> fk_adherent = $this -> id ;
$subscription -> dateh = $date ; // Date of new subscription
$subscription -> datef = $datefin ; // End data of new subscription
$subscription -> amount = $amount ;
$subscription -> note = $label ; // deprecated
$subscription -> note_public = $label ;
2021-04-09 02:23:22 +02:00
$subscription -> fk_type = $fk_type ;
2020-02-02 19:34:09 +01:00
$rowid = $subscription -> create ( $user );
2020-02-24 22:53:14 +01:00
if ( $rowid > 0 ) {
2017-10-07 13:09:31 +02:00
// Update denormalized subscription end date (read database subscription to find values)
// This will also update this->datefin
2020-02-02 19:34:09 +01:00
$result = $this -> update_end_date ( $user );
2020-02-24 22:53:14 +01:00
if ( $result > 0 ) {
2017-10-07 13:09:31 +02:00
// Change properties of object (used by triggers)
2020-02-02 19:34:09 +01:00
$this -> last_subscription_date = dol_now ();
$this -> last_subscription_date_start = $date ;
$this -> last_subscription_date_end = $datefin ;
$this -> last_subscription_amount = $amount ;
2017-10-07 13:09:31 +02:00
}
2020-02-24 22:53:14 +01:00
if ( ! $error ) {
2017-10-07 13:09:31 +02:00
$this -> db -> commit ();
return $rowid ;
2020-02-24 22:53:14 +01:00
} else {
2017-10-07 13:09:31 +02:00
$this -> db -> rollback ();
return - 2 ;
}
2020-02-24 22:53:14 +01:00
} else {
2020-02-02 19:34:09 +01:00
$this -> error = $subscription -> error ;
$this -> errors = $subscription -> errors ;
2017-10-07 13:09:31 +02:00
$this -> db -> rollback ();
return - 1 ;
}
}
2018-03-05 21:46:24 +01:00
/**
* Do complementary actions after subscription recording .
*
2018-03-08 15:01:34 +01:00
* @ param int $subscriptionid Id of created subscription
2018-03-23 23:59:35 +01:00
* @ param string $option Which action ( 'bankdirect' , 'bankviainvoice' , 'invoiceonly' , ... )
2018-03-08 15:01:34 +01:00
* @ param int $accountid Id bank account
* @ param int $datesubscription Date of subscription
* @ param int $paymentdate Date of payment
* @ param string $operation Code of type of operation ( if Id bank account provided ) . Example 'CB' , ...
* @ param string $label Label operation ( if Id bank account provided )
* @ param double $amount Amount of subscription ( 0 accepted for some members )
* @ param string $num_chq Numero cheque ( if Id bank account provided )
* @ param string $emetteur_nom Name of cheque writer
* @ param string $emetteur_banque Name of bank of cheque
2018-09-01 16:51:40 +02:00
* @ param string $autocreatethirdparty Auto create new thirdparty if member not yet linked to a thirdparty and we request an option that generate invoice .
2021-04-22 18:01:52 +02:00
* @ param string $ext_payment_id External id of payment ( for example Stripe charge id )
* @ param string $ext_payment_site Name of external paymentmode ( for example 'stripe' )
2018-03-08 15:01:34 +01:00
* @ return int < 0 if KO , > 0 if OK
2018-03-05 21:46:24 +01:00
*/
2021-04-22 18:01:52 +02:00
public function subscriptionComplementaryActions ( $subscriptionid , $option , $accountid , $datesubscription , $paymentdate , $operation , $label , $amount , $num_chq , $emetteur_nom = '' , $emetteur_banque = '' , $autocreatethirdparty = 0 , $ext_payment_id = '' , $ext_payment_site = '' )
2018-03-05 21:46:24 +01:00
{
global $conf , $langs , $user , $mysoc ;
$error = 0 ;
2020-02-02 19:34:09 +01:00
$this -> invoice = null ; // This will contains invoice if an invoice is created
2018-03-08 15:01:34 +01:00
2020-03-12 12:45:44 +01:00
dol_syslog ( " subscriptionComplementaryActions subscriptionid= " . $subscriptionid . " option= " . $option . " accountid= " . $accountid . " datesubscription= " . $datesubscription . " paymentdate= " .
$paymentdate . " label= " . $label . " amount= " . $amount . " num_chq= " . $num_chq . " autocreatethirdparty= " . $autocreatethirdparty );
2018-03-23 23:59:35 +01:00
2018-03-05 21:46:24 +01:00
// Insert into bank account directlty (if option choosed for) + link to llx_subscription if option is 'bankdirect'
2020-02-24 22:53:14 +01:00
if ( $option == 'bankdirect' && $accountid ) {
2020-03-12 12:45:44 +01:00
require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php' ;
2018-03-05 21:46:24 +01:00
2020-02-02 19:34:09 +01:00
$acct = new Account ( $this -> db );
$result = $acct -> fetch ( $accountid );
2018-03-05 21:46:24 +01:00
2020-02-02 19:34:09 +01:00
$dateop = $paymentdate ;
2018-03-05 21:46:24 +01:00
2020-02-02 19:34:09 +01:00
$insertid = $acct -> addline ( $dateop , $operation , $label , $amount , $num_chq , '' , $user , $emetteur_nom , $emetteur_banque );
2020-02-24 22:53:14 +01:00
if ( $insertid > 0 ) {
2020-03-12 12:45:44 +01:00
$inserturlid = $acct -> add_url_line ( $insertid , $this -> id , DOL_URL_ROOT . '/adherents/card.php?rowid=' , $this -> getFullname ( $langs ), 'member' );
2020-02-24 22:53:14 +01:00
if ( $inserturlid > 0 ) {
2018-03-05 21:46:24 +01:00
// Update table subscription
2021-04-24 20:18:11 +02:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " subscription SET fk_bank= " . (( int ) $insertid );
$sql .= " WHERE rowid= " . (( int ) $subscriptionid );
2018-03-05 21:46:24 +01:00
dol_syslog ( " subscription::subscription " , LOG_DEBUG );
$resql = $this -> db -> query ( $sql );
2020-02-24 22:53:14 +01:00
if ( ! $resql ) {
2018-03-05 21:46:24 +01:00
$error ++ ;
2020-02-02 19:34:09 +01:00
$this -> error = $this -> db -> lasterror ();
$this -> errors [] = $this -> error ;
2018-03-05 21:46:24 +01:00
}
2020-02-24 22:53:14 +01:00
} else {
2018-03-05 21:46:24 +01:00
$error ++ ;
2020-02-02 19:34:09 +01:00
$this -> error = $acct -> error ;
$this -> errors = $acct -> errors ;
2018-03-05 21:46:24 +01:00
}
2020-02-24 22:53:14 +01:00
} else {
2018-03-05 21:46:24 +01:00
$error ++ ;
2020-02-02 19:34:09 +01:00
$this -> error = $acct -> error ;
$this -> errors = $acct -> errors ;
2018-03-05 21:46:24 +01:00
}
}
// If option choosed, we create invoice
2020-02-24 22:53:14 +01:00
if (( $option == 'bankviainvoice' && $accountid ) || $option == 'invoiceonly' ) {
2020-03-12 12:45:44 +01:00
require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/paymentterm.class.php' ;
2018-03-05 21:46:24 +01:00
2020-02-02 19:34:09 +01:00
$invoice = new Facture ( $this -> db );
$customer = new Societe ( $this -> db );
2018-03-05 21:46:24 +01:00
2020-02-24 22:53:14 +01:00
if ( ! $error ) {
2020-05-21 09:12:18 +02:00
if ( ! ( $this -> fk_soc > 0 )) { // If not yet linked to a company
2020-02-24 22:53:14 +01:00
if ( $autocreatethirdparty ) {
2018-03-05 21:46:24 +01:00
// Create a linked thirdparty to member
2020-02-02 19:34:09 +01:00
$companyalias = '' ;
2018-03-05 21:46:24 +01:00
$fullname = $this -> getFullName ( $langs );
2020-02-24 22:53:14 +01:00
if ( $this -> morphy == 'mor' ) {
2020-02-02 19:34:09 +01:00
$companyname = $this -> company ;
2021-03-01 00:19:52 +01:00
if ( ! empty ( $fullname )) {
$companyalias = $fullname ;
}
2020-02-24 22:53:14 +01:00
} else {
2020-02-02 19:34:09 +01:00
$companyname = $fullname ;
2021-03-01 00:19:52 +01:00
if ( ! empty ( $this -> company )) {
$companyalias = $this -> company ;
}
2018-03-05 21:46:24 +01:00
}
2020-02-02 19:34:09 +01:00
$result = $customer -> create_from_member ( $this , $companyname , $companyalias );
2020-02-24 22:53:14 +01:00
if ( $result < 0 ) {
2018-03-09 22:59:44 +01:00
$this -> error = $customer -> error ;
$this -> errors = $customer -> errors ;
2018-03-05 21:46:24 +01:00
$error ++ ;
2020-02-24 22:53:14 +01:00
} else {
2018-03-05 21:46:24 +01:00
$this -> fk_soc = $result ;
}
2020-02-24 22:53:14 +01:00
} else {
$langs -> load ( " errors " );
$this -> error = $langs -> trans ( " ErrorMemberNotLinkedToAThirpartyLinkOrCreateFirst " );
$this -> errors [] = $this -> error ;
$error ++ ;
2018-03-05 21:46:24 +01:00
}
}
}
2020-02-24 22:53:14 +01:00
if ( ! $error ) {
2020-02-02 19:34:09 +01:00
$result = $customer -> fetch ( $this -> fk_soc );
2020-02-24 22:53:14 +01:00
if ( $result <= 0 ) {
2020-02-02 19:34:09 +01:00
$this -> error = $customer -> error ;
$this -> errors = $customer -> errors ;
2018-03-05 21:46:24 +01:00
$error ++ ;
}
}
2020-02-24 22:53:14 +01:00
if ( ! $error ) {
2018-03-05 21:46:24 +01:00
// Create draft invoice
2020-02-02 19:34:09 +01:00
$invoice -> type = Facture :: TYPE_STANDARD ;
$invoice -> cond_reglement_id = $customer -> cond_reglement_id ;
2020-02-24 22:53:14 +01:00
if ( empty ( $invoice -> cond_reglement_id )) {
2020-02-02 19:34:09 +01:00
$paymenttermstatic = new PaymentTerm ( $this -> db );
$invoice -> cond_reglement_id = $paymenttermstatic -> getDefaultId ();
2020-02-24 22:53:14 +01:00
if ( empty ( $invoice -> cond_reglement_id )) {
2018-03-05 21:46:24 +01:00
$error ++ ;
2020-02-02 19:34:09 +01:00
$this -> error = 'ErrorNoPaymentTermRECEPFound' ;
$this -> errors [] = $this -> error ;
2018-03-05 21:46:24 +01:00
}
}
2020-02-02 19:34:09 +01:00
$invoice -> socid = $this -> fk_soc ;
2021-06-08 16:01:26 +02:00
//$invoice->date = $datesubscription;
$invoice -> date = dol_now ();
2018-03-05 21:46:24 +01:00
// Possibility to add external linked objects with hooks
$invoice -> linked_objects [ 'subscription' ] = $subscriptionid ;
2020-02-24 22:53:14 +01:00
if ( ! empty ( $_POST [ 'other_linked_objects' ]) && is_array ( $_POST [ 'other_linked_objects' ])) {
2018-03-05 21:46:24 +01:00
$invoice -> linked_objects = array_merge ( $invoice -> linked_objects , $_POST [ 'other_linked_objects' ]);
}
2020-02-02 19:34:09 +01:00
$result = $invoice -> create ( $user );
2020-02-24 22:53:14 +01:00
if ( $result <= 0 ) {
2020-02-02 19:34:09 +01:00
$this -> error = $invoice -> error ;
$this -> errors = $invoice -> errors ;
2018-03-05 21:46:24 +01:00
$error ++ ;
2020-02-24 22:53:14 +01:00
} else {
2018-03-08 15:01:34 +01:00
$this -> invoice = $invoice ;
}
2018-03-05 21:46:24 +01:00
}
2020-02-24 22:53:14 +01:00
if ( ! $error ) {
2018-03-05 21:46:24 +01:00
// Add line to draft invoice
2020-02-02 19:34:09 +01:00
$idprodsubscription = 0 ;
2021-03-01 00:19:52 +01:00
if ( ! empty ( $conf -> global -> ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS ) && ( ! empty ( $conf -> product -> enabled ) || ! empty ( $conf -> service -> enabled ))) {
$idprodsubscription = $conf -> global -> ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS ;
}
2018-03-05 21:46:24 +01:00
2020-02-02 19:34:09 +01:00
$vattouse = 0 ;
2020-02-24 22:53:14 +01:00
if ( isset ( $conf -> global -> ADHERENT_VAT_FOR_SUBSCRIPTIONS ) && $conf -> global -> ADHERENT_VAT_FOR_SUBSCRIPTIONS == 'defaultforfoundationcountry' ) {
2020-02-02 19:34:09 +01:00
$vattouse = get_default_tva ( $mysoc , $mysoc , $idprodsubscription );
2018-03-05 21:46:24 +01:00
}
//print xx".$vattouse." - ".$mysoc." - ".$customer;exit;
2020-02-02 19:34:09 +01:00
$result = $invoice -> addline ( $label , 0 , 1 , $vattouse , 0 , 0 , $idprodsubscription , 0 , $datesubscription , '' , 0 , 0 , '' , 'TTC' , $amount , 1 );
2020-02-24 22:53:14 +01:00
if ( $result <= 0 ) {
2020-02-02 19:34:09 +01:00
$this -> error = $invoice -> error ;
$this -> errors = $invoice -> errors ;
2018-03-05 21:46:24 +01:00
$error ++ ;
}
}
2020-02-24 22:53:14 +01:00
if ( ! $error ) {
2018-03-05 21:46:24 +01:00
// Validate invoice
2020-02-02 19:34:09 +01:00
$result = $invoice -> validate ( $user );
2020-02-24 22:53:14 +01:00
if ( $result <= 0 ) {
2020-02-02 19:34:09 +01:00
$this -> error = $invoice -> error ;
$this -> errors = $invoice -> errors ;
2018-03-05 21:46:24 +01:00
$error ++ ;
}
}
2020-02-24 22:53:14 +01:00
if ( ! $error ) {
2018-03-08 15:01:34 +01:00
// TODO Link invoice with subscription ?
}
2018-03-05 21:46:24 +01:00
// Add payment onto invoice
2020-02-24 22:53:14 +01:00
if ( ! $error && $option == 'bankviainvoice' && $accountid ) {
2020-03-12 12:45:44 +01:00
require_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/functions.lib.php' ;
2018-03-05 21:46:24 +01:00
$amounts = array ();
$amounts [ $invoice -> id ] = price2num ( $amount );
$paiement = new Paiement ( $this -> db );
2020-02-24 22:53:14 +01:00
$paiement -> datepaye = $paymentdate ;
$paiement -> amounts = $amounts ;
2022-02-18 16:24:11 +01:00
$paiement -> paiementcode = $operation ;
2020-02-24 22:53:14 +01:00
$paiement -> paiementid = dol_getIdFromCode ( $this -> db , $operation , 'c_paiement' , 'code' , 'id' , 1 );
$paiement -> num_payment = $num_chq ;
$paiement -> note_public = $label ;
2021-04-22 18:01:52 +02:00
$paiement -> ext_payment_id = $ext_payment_id ;
$paiement -> ext_payment_site = $ext_payment_site ;
2018-03-05 21:46:24 +01:00
2020-02-24 22:53:14 +01:00
if ( ! $error ) {
2018-03-05 21:46:24 +01:00
// Create payment line for invoice
$paiement_id = $paiement -> create ( $user );
2022-08-12 15:54:50 +02:00
if ( ! ( $paiement_id > 0 )) {
2020-02-02 19:34:09 +01:00
$this -> error = $paiement -> error ;
$this -> errors = $paiement -> errors ;
2018-03-05 21:46:24 +01:00
$error ++ ;
}
}
2020-02-24 22:53:14 +01:00
if ( ! $error ) {
2018-03-05 21:46:24 +01:00
// Add transaction into bank account
2020-02-02 19:34:09 +01:00
$bank_line_id = $paiement -> addPaymentToBank ( $user , 'payment' , '(SubscriptionPayment)' , $accountid , $emetteur_nom , $emetteur_banque );
2020-02-24 22:53:14 +01:00
if ( ! ( $bank_line_id > 0 )) {
2020-02-02 19:34:09 +01:00
$this -> error = $paiement -> error ;
$this -> errors = $paiement -> errors ;
2018-03-05 21:46:24 +01:00
$error ++ ;
}
}
2020-02-24 22:53:14 +01:00
if ( ! $error && ! empty ( $bank_line_id )) {
2018-03-05 21:46:24 +01:00
// Update fk_bank into subscription table
2021-08-27 22:42:04 +02:00
$sql = 'UPDATE ' . MAIN_DB_PREFIX . 'subscription SET fk_bank=' . (( int ) $bank_line_id );
$sql .= ' WHERE rowid=' . (( int ) $subscriptionid );
2018-03-05 21:46:24 +01:00
$result = $this -> db -> query ( $sql );
2020-02-24 22:53:14 +01:00
if ( ! $result ) {
2018-03-05 21:46:24 +01:00
$error ++ ;
}
}
2020-02-24 22:53:14 +01:00
if ( ! $error ) {
2018-03-05 21:46:24 +01:00
// Set invoice as paid
2021-02-09 10:26:17 +01:00
$invoice -> setPaid ( $user );
2018-03-05 21:46:24 +01:00
}
2018-03-08 15:01:34 +01:00
}
2018-03-05 21:46:24 +01:00
2020-02-24 22:53:14 +01:00
if ( ! $error ) {
2018-03-08 15:01:34 +01:00
// Define output language
$outputlangs = $langs ;
$newlang = '' ;
2020-02-02 19:34:09 +01:00
$lang_id = GETPOST ( 'lang_id' );
2021-03-01 00:19:52 +01:00
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang ) && ! empty ( $lang_id )) {
$newlang = $lang_id ;
}
if ( $conf -> global -> MAIN_MULTILANGS && empty ( $newlang )) {
$newlang = $customer -> default_lang ;
}
2020-02-02 19:34:09 +01:00
if ( ! empty ( $newlang )) {
2018-03-08 15:01:34 +01:00
$outputlangs = new Translate ( " " , $conf );
$outputlangs -> setDefaultLang ( $newlang );
2018-03-05 21:46:24 +01:00
}
2018-03-08 15:01:34 +01:00
// Generate PDF (whatever is option MAIN_DISABLE_PDF_AUTOUPDATE) so we can include it into email
//if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
2020-09-10 01:49:09 +02:00
$invoice -> generateDocument ( $invoice -> model_pdf , $outputlangs );
2018-03-05 21:46:24 +01:00
}
}
2020-02-24 22:53:14 +01:00
if ( $error ) {
2018-03-05 21:46:24 +01:00
return - 1 ;
2020-02-24 22:53:14 +01:00
} else {
2018-03-05 21:46:24 +01:00
return 1 ;
}
}
2017-10-07 13:09:31 +02:00
/**
* Function that validate a member
*
* @ param User $user user adherent qui valide
* @ return int < 0 if KO , 0 if nothing done , > 0 if OK
*/
2019-02-25 00:56:48 +01:00
public function validate ( $user )
2017-10-07 13:09:31 +02:00
{
2020-02-02 19:34:09 +01:00
global $langs , $conf ;
2017-10-07 13:09:31 +02:00
2020-02-02 19:34:09 +01:00
$error = 0 ;
$now = dol_now ();
2017-10-07 13:09:31 +02:00
// Check parameters
2021-04-27 21:43:13 +02:00
if ( $this -> statut == self :: STATUS_VALIDATED ) {
2020-03-12 12:45:44 +01:00
dol_syslog ( get_class ( $this ) . " ::validate statut of member does not allow this " , LOG_WARNING );
2017-10-07 13:09:31 +02:00
return 0 ;
}
$this -> db -> begin ();
2020-03-12 12:45:44 +01:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " adherent SET " ;
2021-04-27 21:24:59 +02:00
$sql .= " statut = " . self :: STATUS_VALIDATED ;
2020-03-12 12:45:44 +01:00
$sql .= " , datevalid = ' " . $this -> db -> idate ( $now ) . " ' " ;
2021-08-27 16:33:03 +02:00
$sql .= " , fk_user_valid = " . (( int ) $user -> id );
$sql .= " WHERE rowid = " . (( int ) $this -> id );
2017-10-07 13:09:31 +02:00
2020-03-12 12:45:44 +01:00
dol_syslog ( get_class ( $this ) . " ::validate " , LOG_DEBUG );
2017-10-07 13:09:31 +02:00
$result = $this -> db -> query ( $sql );
2020-02-24 22:53:14 +01:00
if ( $result ) {
2021-04-27 21:43:13 +02:00
$this -> statut = self :: STATUS_VALIDATED ;
2017-10-07 13:09:31 +02:00
// Call trigger
2020-02-02 19:34:09 +01:00
$result = $this -> call_trigger ( 'MEMBER_VALIDATE' , $user );
2020-02-24 22:53:14 +01:00
if ( $result < 0 ) {
$error ++ ;
$this -> db -> rollback ();
return - 1 ;
}
2017-10-07 13:09:31 +02:00
// End call triggers
2018-03-23 20:45:35 +01:00
$this -> datevalid = $now ;
2017-10-07 13:09:31 +02:00
$this -> db -> commit ();
return 1 ;
2020-02-24 22:53:14 +01:00
} else {
2020-02-02 19:34:09 +01:00
$this -> error = $this -> db -> error ();
2017-10-07 13:09:31 +02:00
$this -> db -> rollback ();
return - 1 ;
}
}
/**
* Fonction qui resilie un adherent
*
* @ param User $user User making change
* @ return int < 0 if KO , > 0 if OK
*/
2019-02-25 00:56:48 +01:00
public function resiliate ( $user )
2017-10-07 13:09:31 +02:00
{
2020-02-02 19:34:09 +01:00
global $langs , $conf ;
2017-10-07 13:09:31 +02:00
2020-02-02 19:34:09 +01:00
$error = 0 ;
2017-10-07 13:09:31 +02:00
2019-03-16 14:48:41 +01:00
// Check parameters
2021-04-27 21:43:13 +02:00
if ( $this -> statut == self :: STATUS_RESILIATED ) {
2020-03-12 12:45:44 +01:00
dol_syslog ( get_class ( $this ) . " ::resiliate statut of member does not allow this " , LOG_WARNING );
2017-10-07 13:09:31 +02:00
return 0 ;
}
$this -> db -> begin ();
2020-03-12 12:45:44 +01:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " adherent SET " ;
2021-04-27 21:24:59 +02:00
$sql .= " statut = " . self :: STATUS_RESILIATED ;
2020-03-12 12:45:44 +01:00
$sql .= " , fk_user_valid= " . $user -> id ;
2021-08-27 16:33:03 +02:00
$sql .= " WHERE rowid = " . (( int ) $this -> id );
2017-10-07 13:09:31 +02:00
$result = $this -> db -> query ( $sql );
2020-02-24 22:53:14 +01:00
if ( $result ) {
2021-04-27 21:43:13 +02:00
$this -> statut = self :: STATUS_RESILIATED ;
2017-10-07 13:09:31 +02:00
// Call trigger
2020-02-02 19:34:09 +01:00
$result = $this -> call_trigger ( 'MEMBER_RESILIATE' , $user );
2020-02-24 22:53:14 +01:00
if ( $result < 0 ) {
$error ++ ;
$this -> db -> rollback ();
return - 1 ;
}
2017-10-07 13:09:31 +02:00
// End call triggers
$this -> db -> commit ();
return 1 ;
2020-02-24 22:53:14 +01:00
} else {
2020-02-02 19:34:09 +01:00
$this -> error = $this -> db -> error ();
2017-10-07 13:09:31 +02:00
$this -> db -> rollback ();
return - 1 ;
}
}
2021-03-13 18:24:17 +01:00
/**
2021-03-21 14:38:15 +01:00
* Functiun to exlude ( set adherent . status to - 2 ) a member
* TODO
* A private note should be added to know why the member has been excluded
* For historical purpose it add an " extra-subscription " type excluded
2021-03-13 18:24:17 +01:00
*
* @ param User $user User making change
* @ return int < 0 if KO , > 0 if OK
*/
public function exclude ( $user )
{
global $langs , $conf ;
$error = 0 ;
// Check parameters
2021-04-27 21:43:13 +02:00
if ( $this -> statut == self :: STATUS_EXCLUDED ) {
2021-03-13 18:24:17 +01:00
dol_syslog ( get_class ( $this ) . " ::resiliate statut of member does not allow this " , LOG_WARNING );
return 0 ;
}
$this -> db -> begin ();
$sql = " UPDATE " . MAIN_DB_PREFIX . " adherent SET " ;
2021-04-27 21:24:59 +02:00
$sql .= " statut = " . self :: STATUS_EXCLUDED ;
2021-03-13 18:24:17 +01:00
$sql .= " , fk_user_valid= " . $user -> id ;
2021-08-27 16:33:03 +02:00
$sql .= " WHERE rowid = " . (( int ) $this -> id );
2021-03-13 18:24:17 +01:00
$result = $this -> db -> query ( $sql );
if ( $result ) {
2021-04-27 21:43:13 +02:00
$this -> statut = self :: STATUS_EXCLUDED ;
2021-03-13 18:24:17 +01:00
// Call trigger
$result = $this -> call_trigger ( 'MEMBER_EXCLUDE' , $user );
if ( $result < 0 ) {
$error ++ ;
$this -> db -> rollback ();
return - 1 ;
}
// End call triggers
$this -> db -> commit ();
return 1 ;
} else {
$this -> error = $this -> db -> error ();
$this -> db -> rollback ();
return - 1 ;
}
}
2017-10-07 13:09:31 +02:00
2020-02-24 22:53:14 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
* Function to add member into external tools mailing - list , spip , etc .
*
* @ return int < 0 if KO , > 0 if OK
*/
2019-02-25 00:56:48 +01:00
public function add_to_abo ()
2017-10-07 13:09:31 +02:00
{
2020-02-24 22:53:14 +01:00
// phpcs:enable
2020-02-02 19:34:09 +01:00
global $conf , $langs ;
2017-10-07 13:09:31 +02:00
2020-03-12 12:45:44 +01:00
include_once DOL_DOCUMENT_ROOT . '/mailmanspip/class/mailmanspip.class.php' ;
2020-02-02 19:34:09 +01:00
$mailmanspip = new MailmanSpip ( $this -> db );
2017-10-07 13:09:31 +02:00
2020-02-02 19:34:09 +01:00
$err = 0 ;
2017-10-07 13:09:31 +02:00
// mailman
2020-02-24 22:53:14 +01:00
if ( ! empty ( $conf -> global -> ADHERENT_USE_MAILMAN ) && ! empty ( $conf -> mailmanspip -> enabled )) {
2020-02-02 19:34:09 +01:00
$result = $mailmanspip -> add_to_mailman ( $this );
2017-10-07 13:09:31 +02:00
2020-02-24 22:53:14 +01:00
if ( $result < 0 ) {
2021-03-01 00:19:52 +01:00
if ( ! empty ( $mailmanspip -> error )) {
$this -> errors [] = $mailmanspip -> error ;
}
2020-02-02 19:34:09 +01:00
$err += 1 ;
2017-10-07 13:09:31 +02:00
}
2020-02-24 22:53:14 +01:00
foreach ( $mailmanspip -> mladded_ko as $tmplist => $tmpemail ) {
2017-10-07 13:09:31 +02:00
$langs -> load ( " errors " );
2020-02-02 19:34:09 +01:00
$this -> errors [] = $langs -> trans ( " ErrorFailedToAddToMailmanList " , $tmpemail , $tmplist );
2017-10-07 13:09:31 +02:00
}
2020-02-24 22:53:14 +01:00
foreach ( $mailmanspip -> mladded_ok as $tmplist => $tmpemail ) {
2017-10-07 13:09:31 +02:00
$langs -> load ( " mailmanspip " );
2020-02-02 19:34:09 +01:00
$this -> mesgs [] = $langs -> trans ( " SuccessToAddToMailmanList " , $tmpemail , $tmplist );
2017-10-07 13:09:31 +02:00
}
}
// spip
2020-02-24 22:53:14 +01:00
if ( ! empty ( $conf -> global -> ADHERENT_USE_SPIP ) && ! empty ( $conf -> mailmanspip -> enabled )) {
2020-02-02 19:34:09 +01:00
$result = $mailmanspip -> add_to_spip ( $this );
2020-02-24 22:53:14 +01:00
if ( $result < 0 ) {
2020-02-02 19:34:09 +01:00
$this -> errors [] = $mailmanspip -> error ;
$err += 1 ;
2017-10-07 13:09:31 +02:00
}
}
2020-02-24 22:53:14 +01:00
if ( $err ) {
2017-10-07 13:09:31 +02:00
return - $err ;
2020-02-24 22:53:14 +01:00
} else {
2017-10-07 13:09:31 +02:00
return 1 ;
}
}
2020-02-24 22:53:14 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
* Function to delete a member from external tools like mailing - list , spip , etc .
*
* @ return int < 0 if KO , > 0 if OK
*/
2019-02-25 00:56:48 +01:00
public function del_to_abo ()
2017-10-07 13:09:31 +02:00
{
2020-02-24 22:53:14 +01:00
// phpcs:enable
2020-02-02 19:34:09 +01:00
global $conf , $langs ;
2017-10-07 13:09:31 +02:00
2020-03-12 12:45:44 +01:00
include_once DOL_DOCUMENT_ROOT . '/mailmanspip/class/mailmanspip.class.php' ;
2020-02-02 19:34:09 +01:00
$mailmanspip = new MailmanSpip ( $this -> db );
2017-10-07 13:09:31 +02:00
2020-02-02 19:34:09 +01:00
$err = 0 ;
2017-10-07 13:09:31 +02:00
// mailman
2020-02-24 22:53:14 +01:00
if ( ! empty ( $conf -> global -> ADHERENT_USE_MAILMAN )) {
2020-02-02 19:34:09 +01:00
$result = $mailmanspip -> del_to_mailman ( $this );
2020-02-24 22:53:14 +01:00
if ( $result < 0 ) {
2021-03-01 00:19:52 +01:00
if ( ! empty ( $mailmanspip -> error )) {
$this -> errors [] = $mailmanspip -> error ;
}
2020-02-02 19:34:09 +01:00
$err += 1 ;
2017-10-07 13:09:31 +02:00
}
2020-02-24 22:53:14 +01:00
foreach ( $mailmanspip -> mlremoved_ko as $tmplist => $tmpemail ) {
2017-10-07 13:09:31 +02:00
$langs -> load ( " errors " );
2020-02-02 19:34:09 +01:00
$this -> errors [] = $langs -> trans ( " ErrorFailedToRemoveToMailmanList " , $tmpemail , $tmplist );
2017-10-07 13:09:31 +02:00
}
2020-02-24 22:53:14 +01:00
foreach ( $mailmanspip -> mlremoved_ok as $tmplist => $tmpemail ) {
2017-10-07 13:09:31 +02:00
$langs -> load ( " mailmanspip " );
2020-02-02 19:34:09 +01:00
$this -> mesgs [] = $langs -> trans ( " SuccessToRemoveToMailmanList " , $tmpemail , $tmplist );
2017-10-07 13:09:31 +02:00
}
}
2020-02-24 22:53:14 +01:00
if ( $conf -> global -> ADHERENT_USE_SPIP && ! empty ( $conf -> mailmanspip -> enabled )) {
2020-02-02 19:34:09 +01:00
$result = $mailmanspip -> del_to_spip ( $this );
2020-02-24 22:53:14 +01:00
if ( $result < 0 ) {
2020-02-02 19:34:09 +01:00
$this -> errors [] = $mailmanspip -> error ;
$err += 1 ;
2017-10-07 13:09:31 +02:00
}
2012-06-19 21:54:36 +02:00
}
2020-02-24 22:53:14 +01:00
if ( $err ) {
2017-10-07 13:09:31 +02:00
// error
return - $err ;
2020-02-24 22:53:14 +01:00
} else {
2017-10-07 13:09:31 +02:00
return 1 ;
}
}
2012-05-09 15:22:09 +02:00
2017-10-07 13:09:31 +02:00
/**
* Return civility label of a member
*
* @ return string Translated name of civility ( translated with transnoentitiesnoconv )
*/
2019-02-25 00:56:48 +01:00
public function getCivilityLabel ()
2017-10-07 13:09:31 +02:00
{
global $langs ;
$langs -> load ( " dict " );
2012-05-09 15:22:09 +02:00
2020-02-02 19:34:09 +01:00
$code = ( empty ( $this -> civility_id ) ? '' : $this -> civility_id );
2021-03-01 00:19:52 +01:00
if ( empty ( $code )) {
return '' ;
}
2020-03-12 12:45:44 +01:00
return $langs -> getLabelFromKey ( $this -> db , " Civility " . $code , " c_civility " , " code " , " label " , $code );
2012-03-31 10:14:45 +02:00
}
2010-08-29 14:54:39 +02:00
2017-10-07 13:09:31 +02:00
/**
* Return clicable name ( with picto eventually )
*
* @ param int $withpictoimg 0 = No picto , 1 = Include picto into link , 2 = Only picto , - 1 = Include photo into link , - 2 = Only picto photo , - 3 = Only photo very small )
* @ param int $maxlen length max label
* @ param string $option Page for link ( 'card' , 'category' , 'subscription' , ... )
2020-11-27 01:22:13 +01:00
* @ param string $mode '' = Show firstname + lastname as label ( using default order ), 'firstname' = Show only firstname , 'lastname' = Show only lastname , 'login' = Show login , 'ref' = Show ref
2020-04-02 17:49:01 +02:00
* @ param string $morecss Add more css on link
* @ param int $save_lastsearch_value - 1 = Auto , 0 = No save of lastsearch_values when clicking , 1 = Save lastsearch_values whenclicking
* @ param int $notooltip 1 = Disable tooltip
2020-11-27 01:18:01 +01:00
* @ param int $addlinktonotes 1 = Add link to notes
2017-10-07 13:09:31 +02:00
* @ return string Chaine avec URL
*/
2020-04-02 17:49:01 +02:00
public function getNomUrl ( $withpictoimg = 0 , $maxlen = 0 , $option = 'card' , $mode = '' , $morecss = '' , $save_lastsearch_value = - 1 , $notooltip = 0 , $addlinktonotes = 0 )
2017-10-07 13:09:31 +02:00
{
2022-02-15 18:14:44 +01:00
global $conf , $langs , $hookmanager ;
2010-08-29 14:54:39 +02:00
2021-03-01 00:19:52 +01:00
if ( ! empty ( $conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER ) && $withpictoimg ) {
$withpictoimg = 0 ;
}
2010-08-29 14:54:39 +02:00
2020-02-24 22:53:14 +01:00
$result = '' ;
$label = '' ;
$linkstart = '' ;
$linkend = '' ;
2011-12-28 13:25:05 +01:00
2020-02-24 22:53:14 +01:00
if ( ! empty ( $this -> photo )) {
2022-01-05 10:43:05 +01:00
$label .= '<div class="photointooltip floatright">' ;
$label .= Form :: showphoto ( 'memberphoto' , $this , 80 , 0 , 0 , 'photoref photowithmargin photologintooltip' , 'small' , 0 , 1 );
$label .= '</div>' ;
//$label .= '<div style="clear: both;"></div>';
2017-10-07 13:09:31 +02:00
}
2011-05-02 20:21:57 +02:00
2020-02-02 19:34:09 +01:00
$label .= '<div class="centpercent">' ;
2020-11-02 11:41:07 +01:00
$label .= img_picto ( '' , $this -> picto ) . ' <u class="paddingrightonly">' . $langs -> trans ( " Member " ) . '</u>' ;
$label .= ' ' . $this -> getLibStatut ( 4 );
2021-03-01 00:19:52 +01:00
if ( ! empty ( $this -> ref )) {
$label .= '<br><b>' . $langs -> trans ( 'Ref' ) . ':</b> ' . $this -> ref ;
}
2021-08-30 19:10:43 +02:00
if ( ! empty ( $this -> login )) {
$label .= '<br><b>' . $langs -> trans ( 'Login' ) . ':</b> ' . $this -> login ;
}
2021-03-01 00:19:52 +01:00
if ( ! empty ( $this -> firstname ) || ! empty ( $this -> lastname )) {
$label .= '<br><b>' . $langs -> trans ( 'Name' ) . ':</b> ' . $this -> getFullName ( $langs );
}
if ( ! empty ( $this -> company )) {
$label .= '<br><b>' . $langs -> trans ( 'Company' ) . ':</b> ' . $this -> company ;
}
2020-02-02 19:34:09 +01:00
$label .= '</div>' ;
2010-08-29 14:54:39 +02:00
2021-03-14 12:20:23 +01:00
$url = DOL_URL_ROOT . '/adherents/card.php?rowid=' . (( int ) $this -> id );
2020-02-24 22:53:14 +01:00
if ( $option == 'subscription' ) {
2021-03-14 12:20:23 +01:00
$url = DOL_URL_ROOT . '/adherents/subscription.php?rowid=' . (( int ) $this -> id );
2017-10-07 13:09:31 +02:00
}
2011-12-28 13:25:05 +01:00
2020-02-24 22:53:14 +01:00
if ( $option != 'nolink' ) {
2017-10-07 13:09:31 +02:00
// Add param to save lastsearch_values or not
2020-02-02 19:34:09 +01:00
$add_save_lastsearch_values = ( $save_lastsearch_value == 1 ? 1 : 0 );
2021-03-01 00:19:52 +01:00
if ( $save_lastsearch_value == - 1 && preg_match ( '/list\.php/' , $_SERVER [ " PHP_SELF " ])) {
$add_save_lastsearch_values = 1 ;
}
if ( $add_save_lastsearch_values ) {
$url .= '&save_lastsearch_values=1' ;
}
2017-10-07 13:09:31 +02:00
}
2013-05-12 15:25:12 +02:00
2020-03-12 12:45:44 +01:00
$linkstart .= '<a href="' . $url . '"' ;
2020-02-02 19:34:09 +01:00
$linkclose = " " ;
2020-02-24 22:53:14 +01:00
if ( empty ( $notooltip )) {
if ( ! empty ( $conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER )) {
2017-10-07 13:09:31 +02:00
$langs -> load ( " users " );
2020-02-02 19:34:09 +01:00
$label = $langs -> trans ( " ShowUser " );
2020-03-12 12:45:44 +01:00
$linkclose .= ' alt="' . dol_escape_htmltag ( $label , 1 ) . '"' ;
2017-10-07 13:09:31 +02:00
}
2020-03-12 12:45:44 +01:00
$linkclose .= ' title="' . dol_escape_htmltag ( $label , 1 ) . '"' ;
$linkclose .= ' class="classfortooltip' . ( $morecss ? ' ' . $morecss : '' ) . '"' ;
2017-10-07 13:09:31 +02:00
}
2017-09-21 12:16:01 +02:00
2020-03-12 12:45:44 +01:00
$linkstart .= $linkclose . '>' ;
2020-02-02 19:34:09 +01:00
$linkend = '</a>' ;
2017-06-09 17:02:05 +02:00
2020-02-02 19:34:09 +01:00
$result .= $linkstart ;
2021-03-01 00:19:52 +01:00
if ( $withpictoimg ) {
$result .= '<div class="inline-block nopadding valignmiddle">' ;
}
2020-02-24 22:53:14 +01:00
if ( $withpictoimg ) {
2020-02-02 19:34:09 +01:00
$paddafterimage = '' ;
2021-03-01 00:19:52 +01:00
if ( abs ( $withpictoimg ) == 1 ) {
$paddafterimage = 'style="margin-right: 3px;"' ;
}
2017-10-07 13:09:31 +02:00
// Only picto
2021-03-01 00:19:52 +01:00
if ( $withpictoimg > 0 ) {
2020-03-12 12:45:44 +01:00
$picto = '<span class="nopadding' . ( $morecss ? ' userimg' . $morecss : '' ) . '">' .
img_object ( '' , 'user' , $paddafterimage . ' ' . ( $notooltip ? '' : 'class="classfortooltip"' ), 0 , 0 , $notooltip ? 0 : 1 ) . '</span>' ;
2021-03-01 00:19:52 +01:00
} else {
// Picto must be a photo
2020-03-12 12:45:44 +01:00
$picto = '<span class="nopadding' . ( $morecss ? ' userimg' . $morecss : '' ) . '"' . ( $paddafterimage ? ' ' . $paddafterimage : '' ) . '>' ;
$picto .= Form :: showphoto ( 'memberphoto' , $this , 0 , 0 , 0 , 'userphoto' . ( $withpictoimg == - 3 ? 'small' : '' ), 'mini' , 0 , 1 );
2020-02-02 19:34:09 +01:00
$picto .= '</span>' ;
2019-10-23 21:00:29 +02:00
}
2020-02-02 19:34:09 +01:00
$result .= $picto ;
2017-10-07 13:09:31 +02:00
}
2020-02-24 22:53:14 +01:00
if ( $withpictoimg > - 2 && $withpictoimg != 2 ) {
2021-03-01 00:19:52 +01:00
if ( empty ( $conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER )) {
$result .= '<span class="nopadding valignmiddle' . (( ! isset ( $this -> statut ) || $this -> statut ) ? '' : ' strikefordisabled' ) .
2020-03-12 12:45:44 +01:00
( $morecss ? ' usertext' . $morecss : '' ) . '">' ;
2021-03-01 00:19:52 +01:00
}
2020-05-21 00:47:16 +02:00
if ( $mode == 'login' ) {
2020-02-24 22:53:14 +01:00
$result .= dol_trunc ( $this -> login , $maxlen );
2020-05-21 00:47:16 +02:00
} elseif ( $mode == 'ref' ) {
2020-11-10 22:19:58 +01:00
$result .= $this -> ref ;
2020-05-21 00:47:16 +02:00
} else {
2020-11-27 01:22:13 +01:00
$result .= $this -> getFullName ( $langs , '' , ( $mode == 'firstname' ? 2 : ( $mode == 'lastname' ? 4 : - 1 )), $maxlen );
2020-05-21 00:47:16 +02:00
}
2021-03-01 00:19:52 +01:00
if ( empty ( $conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER )) {
$result .= '</span>' ;
}
}
if ( $withpictoimg ) {
$result .= '</div>' ;
2017-09-16 17:51:18 +02:00
}
2020-02-02 19:34:09 +01:00
$result .= $linkend ;
2012-12-10 19:06:59 +01:00
2020-04-02 17:49:01 +02:00
if ( $addlinktonotes ) {
if ( $this -> note_private ) {
$notetoshow = $langs -> trans ( " ViewPrivateNote " ) . ':<br>' . dol_string_nohtmltag ( $this -> note_private , 1 );
$result .= ' <span class="note inline-block">' ;
$result .= '<a href="' . DOL_URL_ROOT . '/adherents/note.php?id=' . $this -> id . '" class="classfortooltip" title="' . dol_escape_htmltag ( $notetoshow ) . '">' ;
$result .= img_picto ( '' , 'note' );
$result .= '</a>' ;
$result .= '</span>' ;
}
}
2022-02-15 11:09:07 +01:00
global $action ;
$hookmanager -> initHooks ( array ( $this -> element . 'dao' ));
2022-02-15 18:46:41 +01:00
$parameters = array ( 'id' => $this -> id , 'getnomurl' => & $result );
2022-02-15 11:09:07 +01:00
$reshook = $hookmanager -> executeHooks ( 'getNomUrl' , $parameters , $this , $action ); // Note that $action and $object may have been modified by some hooks
if ( $reshook > 0 ) {
$result = $hookmanager -> resPrint ;
} else {
$result .= $hookmanager -> resPrint ;
}
2017-10-07 13:09:31 +02:00
return $result ;
}
/**
2021-03-13 18:24:17 +01:00
* Retourne le libelle du statut d ' un adherent ( brouillon , valide , resilie , exclu )
2017-10-07 13:09:31 +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
*/
2019-02-25 00:56:48 +01:00
public function getLibStatut ( $mode = 0 )
2017-10-07 13:09:31 +02:00
{
2019-01-27 11:55:16 +01:00
return $this -> LibStatut ( $this -> statut , $this -> need_subscription , $this -> datefin , $mode );
2017-10-07 13:09:31 +02:00
}
2020-02-24 22:53:14 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
* Renvoi le libelle d ' un statut donne
*
2019-11-01 23:58:14 +01:00
* @ param int $status Id status
2017-10-07 13:09:31 +02:00
* @ param int $need_subscription 1 if member type need subscription , 0 otherwise
* @ param int $date_end_subscription Date fin adhesion
2019-03-15 20:06:05 +01:00
* @ param int $mode 0 = long label , 1 = short label , 2 = Picto + short label , 3 = Picto , 4 = Picto + long label , 5 = Short label + Picto , 6 = Long label + Picto
2017-10-07 13:09:31 +02:00
* @ return string Label
*/
2019-11-01 23:58:14 +01:00
public function LibStatut ( $status , $need_subscription , $date_end_subscription , $mode = 0 )
2017-10-07 13:09:31 +02:00
{
2020-02-24 22:53:14 +01:00
// phpcs:enable
2017-10-07 13:09:31 +02:00
global $langs ;
$langs -> load ( " members " );
2019-10-23 20:12:29 +02:00
2020-02-24 22:53:14 +01:00
$statusType = '' ;
$labelStatus = '' ;
$labelStatusShort = '' ;
2019-10-24 16:35:48 +02:00
2021-04-27 21:24:59 +02:00
if ( $status == self :: STATUS_DRAFT ) {
2019-10-23 20:12:29 +02:00
$statusType = 'status0' ;
2019-11-01 12:52:03 +01:00
$labelStatus = $langs -> trans ( " MemberStatusDraft " );
$labelStatusShort = $langs -> trans ( " MemberStatusDraftShort " );
2021-04-27 21:24:59 +02:00
} elseif ( $status >= self :: STATUS_VALIDATED ) {
2022-11-25 22:29:35 +01:00
if ( $need_subscription === 0 ) {
2019-10-23 20:12:29 +02:00
$statusType = 'status4' ;
2019-11-01 12:52:03 +01:00
$labelStatus = $langs -> trans ( " MemberStatusNoSubscription " );
$labelStatusShort = $langs -> trans ( " MemberStatusNoSubscriptionShort " );
2020-02-24 22:53:14 +01:00
} elseif ( ! $date_end_subscription ) {
2019-10-23 20:12:29 +02:00
$statusType = 'status1' ;
2019-11-01 12:52:03 +01:00
$labelStatus = $langs -> trans ( " MemberStatusActive " );
$labelStatusShort = $langs -> trans ( " MemberStatusActiveShort " );
2021-03-14 16:44:34 +01:00
} elseif ( $date_end_subscription < dol_now ()) {
2019-10-23 20:12:29 +02:00
$statusType = 'status3' ;
2019-11-01 12:52:03 +01:00
$labelStatus = $langs -> trans ( " MemberStatusActiveLate " );
$labelStatusShort = $langs -> trans ( " MemberStatusActiveLateShort " );
2020-02-24 22:53:14 +01:00
} else {
2019-10-23 20:12:29 +02:00
$statusType = 'status4' ;
2019-11-01 12:52:03 +01:00
$labelStatus = $langs -> trans ( " MemberStatusPaid " );
$labelStatusShort = $langs -> trans ( " MemberStatusPaidShort " );
2017-10-07 13:09:31 +02:00
}
2021-04-27 21:24:59 +02:00
} elseif ( $status == self :: STATUS_RESILIATED ) {
2019-10-23 20:35:39 +02:00
$statusType = 'status6' ;
2021-10-16 19:37:57 +02:00
$labelStatus = $langs -> transnoentitiesnoconv ( " MemberStatusResiliated " );
$labelStatusShort = $langs -> transnoentitiesnoconv ( " MemberStatusResiliatedShort " );
2021-04-27 21:24:59 +02:00
} elseif ( $status == self :: STATUS_EXCLUDED ) {
2021-03-29 17:38:37 +02:00
$statusType = 'status10' ;
2021-10-16 19:37:57 +02:00
$labelStatus = $langs -> transnoentitiesnoconv ( " MemberStatusExcluded " );
$labelStatusShort = $langs -> transnoentitiesnoconv ( " MemberStatusExcludedShort " );
2017-09-16 17:51:18 +02:00
}
2019-10-23 20:12:29 +02:00
2019-11-01 12:52:03 +01:00
return dolGetStatus ( $labelStatus , $labelStatusShort , '' , $statusType , $mode );
2017-10-07 13:09:31 +02:00
}
2012-12-10 19:06:59 +01:00
2017-10-07 13:09:31 +02:00
2020-02-24 22:53:14 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
* Charge indicateurs this -> nb de tableau de bord
*
* @ return int < 0 if KO , > 0 if OK
*/
2019-02-25 00:56:48 +01:00
public function load_state_board ()
2017-10-07 13:09:31 +02:00
{
2020-02-24 22:53:14 +01:00
// phpcs:enable
2017-10-07 13:09:31 +02:00
global $conf ;
2018-09-16 08:06:17 +02:00
$this -> nb = array ();
2017-10-07 13:09:31 +02:00
$sql = " SELECT count(a.rowid) as nb " ;
2020-03-12 12:45:44 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " adherent as a " ;
2020-02-02 19:34:09 +01:00
$sql .= " WHERE a.statut > 0 " ;
2020-03-12 12:45:44 +01:00
$sql .= " AND a.entity IN ( " . getEntity ( 'adherent' ) . " ) " ;
2017-10-07 13:09:31 +02:00
2020-02-02 19:34:09 +01:00
$resql = $this -> db -> query ( $sql );
2020-02-24 22:53:14 +01:00
if ( $resql ) {
while ( $obj = $this -> db -> fetch_object ( $resql )) {
2020-02-02 19:34:09 +01:00
$this -> nb [ " members " ] = $obj -> nb ;
2017-10-07 13:09:31 +02:00
}
$this -> db -> free ( $resql );
2017-09-16 17:51:18 +02:00
return 1 ;
2020-02-24 22:53:14 +01:00
} else {
2017-10-07 13:09:31 +02:00
dol_print_error ( $this -> db );
2020-02-02 19:34:09 +01:00
$this -> error = $this -> db -> error ();
2017-10-07 13:09:31 +02:00
return - 1 ;
2017-09-16 17:51:18 +02:00
}
}
2010-08-29 14:54:39 +02:00
2020-02-24 22:53:14 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2017-10-07 13:09:31 +02:00
/**
* Load indicators for dashboard ( this -> nbtodo and this -> nbtodolate )
*
* @ param User $user Objet user
2020-01-28 21:27:11 +01:00
* @ param string $mode " expired " for membership to renew , " shift " for member to validate
2017-10-07 13:09:31 +02:00
* @ return WorkboardResponse | int < 0 if KO , WorkboardResponse if OK
*/
2020-01-28 21:27:11 +01:00
public function load_board ( $user , $mode )
2017-10-07 13:09:31 +02:00
{
2020-02-24 22:53:14 +01:00
// phpcs:enable
2017-10-07 13:09:31 +02:00
global $conf , $langs ;
2021-03-01 00:19:52 +01:00
if ( $user -> socid ) {
return - 1 ; // protection pour eviter appel par utilisateur externe
}
2010-08-29 14:54:39 +02:00
2020-02-24 22:53:14 +01:00
$now = dol_now ();
2010-08-29 14:54:39 +02:00
2017-10-07 13:09:31 +02:00
$sql = " SELECT a.rowid, a.datefin, a.statut " ;
2020-03-12 12:45:44 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " adherent as a " ;
$sql .= " , " . MAIN_DB_PREFIX . " adherent_type as t " ;
2020-02-24 22:53:14 +01:00
$sql .= " WHERE a.fk_adherent_type = t.rowid " ;
if ( $mode == 'expired' ) {
2021-04-27 21:43:13 +02:00
$sql .= " AND a.statut = " . self :: STATUS_VALIDATED ;
2020-03-12 12:45:44 +01:00
$sql .= " AND a.entity IN ( " . getEntity ( 'adherent' ) . " ) " ;
2020-05-28 20:17:26 +02:00
$sql .= " AND ((a.datefin IS NULL or a.datefin < ' " . $this -> db -> idate ( $now ) . " ') AND t.subscription = '1') " ;
2020-02-24 22:53:14 +01:00
} elseif ( $mode == 'shift' ) {
2021-04-27 21:43:13 +02:00
$sql .= " AND a.statut = " . self :: STATUS_DRAFT ;
2020-03-12 12:45:44 +01:00
$sql .= " AND a.entity IN ( " . getEntity ( 'adherent' ) . " ) " ;
2020-01-28 21:27:11 +01:00
}
2013-06-16 23:15:20 +02:00
2020-02-24 22:53:14 +01:00
$resql = $this -> db -> query ( $sql );
if ( $resql ) {
2017-10-07 13:09:31 +02:00
$langs -> load ( " members " );
2020-01-28 21:29:17 +01:00
2020-01-30 13:01:42 +01:00
$warning_delay = 0 ;
$url = '' ;
$label = '' ;
$labelShort = '' ;
2020-01-28 21:27:11 +01:00
if ( $mode == 'expired' ) {
2020-02-24 22:53:14 +01:00
$warning_delay = $conf -> adherent -> subscription -> warning_delay / 60 / 60 / 24 ;
2020-01-28 21:27:11 +01:00
$label = $langs -> trans ( " MembersWithSubscriptionToReceive " );
$labelShort = $langs -> trans ( " MembersWithSubscriptionToReceiveShort " );
2021-04-27 21:43:13 +02:00
$url = DOL_URL_ROOT . '/adherents/list.php?mainmenu=members&statut=' . self :: STATUS_VALIDATED . '&filter=outofdate' ;
2020-02-24 22:53:14 +01:00
} elseif ( $mode == 'shift' ) {
$warning_delay = $conf -> adherent -> subscription -> warning_delay / 60 / 60 / 24 ;
2021-04-27 21:43:13 +02:00
$url = DOL_URL_ROOT . '/adherents/list.php?mainmenu=members&statut=' . self :: STATUS_DRAFT ;
2020-02-24 22:53:14 +01:00
$label = $langs -> trans ( " MembersListToValid " );
$labelShort = $langs -> trans ( " ToValidate " );
2020-01-28 21:27:11 +01:00
}
2010-08-29 14:54:39 +02:00
2017-10-07 13:09:31 +02:00
$response = new WorkboardResponse ();
2020-02-24 22:53:14 +01:00
$response -> warning_delay = $warning_delay ;
$response -> label = $label ;
$response -> labelShort = $labelShort ;
$response -> url = $url ;
$response -> img = img_object ( '' , " user " );
2013-06-16 23:15:20 +02:00
2017-10-07 13:09:31 +02:00
$adherentstatic = new Adherent ( $this -> db );
2011-12-28 13:25:05 +01:00
2020-02-24 22:53:14 +01:00
while ( $obj = $this -> db -> fetch_object ( $resql )) {
2017-10-07 13:09:31 +02:00
$response -> nbtodo ++ ;
2010-08-29 14:54:39 +02:00
2017-10-07 13:09:31 +02:00
$adherentstatic -> datefin = $this -> db -> jdate ( $obj -> datefin );
$adherentstatic -> statut = $obj -> statut ;
2011-12-28 13:25:05 +01:00
2017-10-07 13:09:31 +02:00
if ( $adherentstatic -> hasDelay ()) {
$response -> nbtodolate ++ ;
}
}
2010-08-29 14:54:39 +02:00
2017-10-07 13:09:31 +02:00
return $response ;
2020-02-24 22:53:14 +01:00
} else {
2017-10-07 13:09:31 +02:00
dol_print_error ( $this -> db );
2020-02-02 19:34:09 +01:00
$this -> error = $this -> db -> error ();
2017-10-07 13:09:31 +02:00
return - 1 ;
}
}
2011-12-28 13:25:05 +01:00
2017-10-07 13:09:31 +02:00
/**
* Create a document onto disk according to template module .
*
* @ param string $modele Force template to use ( '' to not force )
* @ param Translate $outputlangs objet lang a utiliser pour traduction
* @ param int $hidedetails Hide details of lines
* @ param int $hidedesc Hide description
* @ param int $hideref Hide ref
2020-02-24 22:53:14 +01:00
* @ param null | array $moreparams Array to provide more information
2017-10-07 13:09:31 +02:00
* @ return int 0 if KO , 1 if OK
*/
2019-01-27 15:20:16 +01:00
public function generateDocument ( $modele , $outputlangs , $hidedetails = 0 , $hidedesc = 0 , $hideref = 0 , $moreparams = null )
2017-10-07 13:09:31 +02:00
{
2020-02-02 19:34:09 +01:00
global $conf , $langs ;
2017-10-07 13:09:31 +02:00
$langs -> load ( " orders " );
2017-03-13 15:00:44 +01:00
2020-02-02 19:34:09 +01:00
if ( ! dol_strlen ( $modele )) {
2017-10-07 13:09:31 +02:00
$modele = 'standard' ;
2020-09-10 01:49:09 +02:00
if ( $this -> model_pdf ) {
$modele = $this -> model_pdf ;
2020-02-02 19:34:09 +01:00
} elseif ( ! empty ( $conf -> global -> ADHERENT_ADDON_PDF )) {
2017-10-07 13:09:31 +02:00
$modele = $conf -> global -> ADHERENT_ADDON_PDF ;
}
}
$modelpath = " core/modules/member/doc/ " ;
2018-06-15 09:47:28 +02:00
return $this -> commonGenerateDocument ( $modelpath , $modele , $outputlangs , $hidedetails , $hidedesc , $hideref , $moreparams );
2017-10-07 13:09:31 +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 .
*
2020-10-30 07:57:53 +01:00
* @ return int
2017-10-07 13:09:31 +02:00
*/
2019-02-25 00:56:48 +01:00
public function initAsSpecimen ()
2017-10-07 13:09:31 +02:00
{
2020-02-02 19:34:09 +01:00
global $user , $langs ;
2020-10-30 07:57:53 +01:00
$now = dol_now ();
2017-10-07 13:09:31 +02:00
// Initialise parametres
2020-02-02 19:34:09 +01:00
$this -> id = 0 ;
2020-11-11 11:12:19 +01:00
$this -> ref = 'ABC001' ;
2020-10-30 07:57:53 +01:00
$this -> entity = 1 ;
2020-02-02 19:34:09 +01:00
$this -> specimen = 1 ;
2017-10-07 13:09:31 +02:00
$this -> civility_id = 0 ;
$this -> lastname = 'DOLIBARR' ;
$this -> firstname = 'SPECIMEN' ;
2020-02-02 19:34:09 +01:00
$this -> gender = 'man' ;
$this -> login = 'dolibspec' ;
$this -> pass = 'dolibspec' ;
2019-09-01 22:21:48 +02:00
$this -> company = 'Societe ABC' ;
2017-10-07 13:09:31 +02:00
$this -> address = '61 jump street' ;
$this -> zip = '75000' ;
$this -> town = 'Paris' ;
$this -> country_id = 1 ;
$this -> country_code = 'FR' ;
$this -> country = 'France' ;
2019-06-22 19:20:01 +02:00
$this -> morphy = 'mor' ;
2017-10-07 13:09:31 +02:00
$this -> email = 'specimen@specimen.com' ;
2020-10-30 07:57:53 +01:00
$this -> socialnetworks = array (
'skype' => 'skypepseudo' ,
'twitter' => 'twitterpseudo' ,
'facebook' => 'facebookpseudo' ,
'linkedin' => 'linkedinpseudo' ,
);
2020-02-24 22:53:14 +01:00
$this -> phone = '0999999999' ;
$this -> phone_perso = '0999999998' ;
2017-10-07 13:09:31 +02:00
$this -> phone_mobile = '0999999997' ;
2020-10-30 07:57:53 +01:00
$this -> note_public = 'This is a public note' ;
$this -> note_private = 'This is a private note' ;
$this -> birth = $now ;
2020-02-02 19:34:09 +01:00
$this -> photo = '' ;
$this -> public = 1 ;
2021-04-27 22:00:21 +02:00
$this -> statut = self :: STATUS_DRAFT ;
2020-02-02 19:34:09 +01:00
2020-10-30 07:57:53 +01:00
$this -> datefin = $now ;
$this -> datevalid = $now ;
2020-02-02 19:34:09 +01:00
$this -> typeid = 1 ; // Id type adherent
$this -> type = 'Type adherent' ; // Libelle type adherent
$this -> need_subscription = 0 ;
2020-10-30 07:57:53 +01:00
$this -> first_subscription_date = $now ;
2020-02-02 19:34:09 +01:00
$this -> first_subscription_date_start = $this -> first_subscription_date ;
$this -> first_subscription_date_end = dol_time_plus_duree ( $this -> first_subscription_date_start , 1 , 'y' );
$this -> first_subscription_amount = 10 ;
$this -> last_subscription_date = $this -> first_subscription_date ;
$this -> last_subscription_date_start = $this -> first_subscription_date ;
$this -> last_subscription_date_end = dol_time_plus_duree ( $this -> last_subscription_date_start , 1 , 'y' );
$this -> last_subscription_amount = 10 ;
2020-10-30 07:57:53 +01:00
return 1 ;
2017-10-07 13:09:31 +02:00
}
2020-02-24 22:53:14 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2017-10-07 13:09:31 +02:00
/**
* Retourne chaine DN complete dans l 'annuaire LDAP pour l' objet
*
* @ param array $info Info array 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
*/
2019-07-13 11:21:07 +02:00
public function _load_ldap_dn ( $info , $mode = 0 )
2017-10-07 13:09:31 +02:00
{
2020-02-24 22:53:14 +01:00
// phpcs:enable
2017-10-07 13:09:31 +02:00
global $conf ;
2020-02-02 19:34:09 +01:00
$dn = '' ;
2021-03-01 00:19:52 +01:00
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 ];
}
2017-10-07 13:09:31 +02:00
return $dn ;
}
2020-02-24 22:53:14 +01:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
/**
2017-10-07 13:09:31 +02:00
* Initialise tableau info ( tableau des attributs LDAP )
*
* @ return array Tableau info des attributs
*/
2019-06-18 20:01:28 +02:00
public function _load_ldap_info ()
2017-09-24 19:18:41 +02:00
{
2020-02-24 22:53:14 +01:00
// phpcs:enable
2020-02-02 19:34:09 +01:00
global $conf , $langs ;
2010-08-29 14:54:39 +02:00
2020-02-02 19:34:09 +01:00
$info = array ();
2020-11-11 07:16:07 +01:00
$socialnetworks = getArrayOfSocialNetworks ();
2020-02-02 19:34:09 +01:00
$keymodified = false ;
2010-08-29 14:54:39 +02:00
2017-09-24 19:18:41 +02:00
// Object classes
2020-02-02 19:34:09 +01:00
$info [ " objectclass " ] = explode ( ',' , $conf -> global -> LDAP_MEMBER_OBJECT_CLASS );
2010-08-29 14:54:39 +02:00
2020-02-02 19:34:09 +01:00
$this -> fullname = $this -> getFullName ( $langs );
2017-09-30 11:51:22 +02:00
2017-09-28 19:13:26 +02:00
// For avoid ldap error when firstname and lastname are empty
2019-09-01 22:21:48 +02:00
if ( $this -> morphy == 'mor' && ( empty ( $this -> fullname ) || $this -> fullname == $this -> company )) {
$this -> fullname = $this -> company ;
$this -> lastname = $this -> company ;
2017-09-28 19:13:26 +02:00
}
2010-08-29 14:54:39 +02:00
2017-09-24 19:18:41 +02:00
// Possible LDAP KEY (constname => varname)
2020-11-11 07:16:07 +01:00
$ldapkey = array (
'LDAP_MEMBER_FIELD_FULLNAME' => 'fullname' ,
'LDAP_MEMBER_FIELD_NAME' => 'lastname' ,
'LDAP_MEMBER_FIELD_LOGIN' => 'login' ,
'LDAP_MEMBER_FIELD_LOGIN_SAMBA' => 'login' ,
'LDAP_MEMBER_FIELD_MAIL' => 'email'
);
2017-09-24 19:18:41 +02:00
// Member
2020-02-24 22:53:14 +01:00
foreach ( $ldapkey as $constname => $varname ) {
if ( ! empty ( $this -> $varname ) && ! empty ( $conf -> global -> $constname )) {
2017-09-24 19:18:41 +02:00
$info [ $conf -> global -> $constname ] = $this -> $varname ;
// Check if it is the LDAP key and if its value has been changed
2020-02-24 22:53:14 +01:00
if ( ! empty ( $conf -> global -> LDAP_KEY_MEMBERS ) && $conf -> global -> LDAP_KEY_MEMBERS == $conf -> global -> $constname ) {
2021-03-01 00:19:52 +01:00
if ( ! empty ( $this -> oldcopy ) && $this -> $varname != $this -> oldcopy -> $varname ) {
$keymodified = true ; // For check if LDAP key has been modified
}
2017-09-24 19:18:41 +02:00
}
}
}
2021-03-01 00:19:52 +01:00
if ( $this -> firstname && ! empty ( $conf -> global -> LDAP_MEMBER_FIELD_FIRSTNAME )) {
$info [ $conf -> global -> LDAP_MEMBER_FIELD_FIRSTNAME ] = $this -> firstname ;
}
if ( $this -> poste && ! empty ( $conf -> global -> LDAP_MEMBER_FIELD_TITLE )) {
$info [ $conf -> global -> LDAP_MEMBER_FIELD_TITLE ] = $this -> poste ;
}
if ( $this -> company && ! empty ( $conf -> global -> LDAP_MEMBER_FIELD_COMPANY )) {
$info [ $conf -> global -> LDAP_MEMBER_FIELD_COMPANY ] = $this -> company ;
}
if ( $this -> address && ! empty ( $conf -> global -> LDAP_MEMBER_FIELD_ADDRESS )) {
$info [ $conf -> global -> LDAP_MEMBER_FIELD_ADDRESS ] = $this -> address ;
}
if ( $this -> zip && ! empty ( $conf -> global -> LDAP_MEMBER_FIELD_ZIP )) {
$info [ $conf -> global -> LDAP_MEMBER_FIELD_ZIP ] = $this -> zip ;
}
if ( $this -> town && ! empty ( $conf -> global -> LDAP_MEMBER_FIELD_TOWN )) {
$info [ $conf -> global -> LDAP_MEMBER_FIELD_TOWN ] = $this -> town ;
}
if ( $this -> country_code && ! empty ( $conf -> global -> LDAP_MEMBER_FIELD_COUNTRY )) {
$info [ $conf -> global -> LDAP_MEMBER_FIELD_COUNTRY ] = $this -> country_code ;
}
2020-11-11 07:16:07 +01:00
foreach ( $socialnetworks as $key => $value ) {
if ( $this -> socialnetworks [ $value [ 'label' ]] && ! empty ( $conf -> global -> { 'LDAP_MEMBER_FIELD_' . strtoupper ( $value [ 'label' ])})) {
$info [ $conf -> global -> { 'LDAP_MEMBER_FIELD_' . strtoupper ( $value [ 'label' ])}] = $this -> socialnetworks [ $value [ 'label' ]];
}
}
2021-03-01 00:19:52 +01: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_private && ! empty ( $conf -> global -> LDAP_MEMBER_FIELD_DESCRIPTION )) {
$info [ $conf -> global -> LDAP_MEMBER_FIELD_DESCRIPTION ] = dol_string_nohtmltag ( $this -> note_private , 2 );
}
if ( $this -> note_public && ! empty ( $conf -> global -> LDAP_MEMBER_FIELD_NOTE_PUBLIC )) {
$info [ $conf -> global -> LDAP_MEMBER_FIELD_NOTE_PUBLIC ] = dol_string_nohtmltag ( $this -> note_public , 2 );
}
if ( $this -> birth && ! empty ( $conf -> global -> LDAP_MEMBER_FIELD_BIRTHDATE )) {
$info [ $conf -> global -> LDAP_MEMBER_FIELD_BIRTHDATE ] = dol_print_date ( $this -> birth , 'dayhourldap' );
}
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' );
}
2017-09-24 19:18:41 +02:00
// When password is modified
2020-02-24 22:53:14 +01:00
if ( ! empty ( $this -> pass )) {
2020-11-11 07:16:07 +01:00
if ( ! empty ( $conf -> global -> LDAP_MEMBER_FIELD_PASSWORD )) {
$info [ $conf -> global -> LDAP_MEMBER_FIELD_PASSWORD ] = $this -> pass ; // this->pass = mot de passe non crypte
}
if ( ! empty ( $conf -> global -> LDAP_MEMBER_FIELD_PASSWORD_CRYPTED )) {
2021-11-12 10:10:04 +01:00
$info [ $conf -> global -> LDAP_MEMBER_FIELD_PASSWORD_CRYPTED ] = dol_hash ( $this -> pass , 'openldap' ); // Create OpenLDAP password (see LDAP_PASSWORD_HASH_TYPE)
2020-11-11 07:16:07 +01:00
}
2021-03-01 00:19:52 +01:00
} elseif ( $conf -> global -> LDAP_SERVER_PROTOCOLVERSION !== '3' ) {
// Set LDAP password if possible
// If ldap key is modified and LDAPv3 we use ldap_rename function for avoid lose encrypt password
2020-02-24 22:53:14 +01:00
if ( ! empty ( $conf -> global -> DATABASE_PWD_ENCRYPTED )) {
2017-09-24 19:18:41 +02:00
// Just for the default MD5 !
2020-02-24 22:53:14 +01:00
if ( empty ( $conf -> global -> MAIN_SECURITY_HASH_ALGO )) {
2020-02-02 19:34:09 +01:00
if ( $this -> pass_indatabase_crypted && ! empty ( $conf -> global -> LDAP_MEMBER_FIELD_PASSWORD_CRYPTED )) {
2017-10-06 13:13:51 +02:00
// Create OpenLDAP MD5 password from Dolibarr MD5 password
// Note: This suppose that "pass_indatabase_crypted" is a md5 (guaranted by the previous test if "(empty($conf->global->MAIN_SECURITY_HASH_ALGO))"
2021-11-12 13:15:40 +01:00
$info [ $conf -> global -> LDAP_MEMBER_FIELD_PASSWORD_CRYPTED ] = dolGetLdapPasswordHash ( $this -> pass_indatabase_crypted , 'md5frommd5' );
2017-09-24 19:18:41 +02:00
}
}
2021-03-01 00:19:52 +01:00
} elseif ( ! empty ( $this -> pass_indatabase )) {
// Use $this->pass_indatabase value if exists
if ( ! empty ( $conf -> global -> LDAP_MEMBER_FIELD_PASSWORD )) {
$info [ $conf -> global -> LDAP_MEMBER_FIELD_PASSWORD ] = $this -> pass_indatabase ; // $this->pass_indatabase = mot de passe non crypte
}
if ( ! empty ( $conf -> global -> LDAP_MEMBER_FIELD_PASSWORD_CRYPTED )) {
2021-11-12 10:10:04 +01:00
$info [ $conf -> global -> LDAP_MEMBER_FIELD_PASSWORD_CRYPTED ] = dol_hash ( $this -> pass_indatabase , 'openldap' ); // Create OpenLDAP password (see LDAP_PASSWORD_HASH_TYPE)
2021-03-01 00:19:52 +01:00
}
2017-09-24 19:18:41 +02:00
}
}
// Subscriptions
2021-03-01 00:19:52 +01: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 ;
}
2017-09-24 19:18:41 +02:00
return $info ;
}
2010-08-29 14:54:39 +02:00
2017-10-07 13:09:31 +02:00
/**
2019-01-31 15:15:18 +01:00
* Load type info information in the member object
2017-10-07 13:09:31 +02:00
*
* @ param int $id Id of member to load
* @ return void
*/
2019-02-25 00:56:48 +01:00
public function info ( $id )
2017-10-07 13:09:31 +02:00
{
$sql = 'SELECT a.rowid, a.datec as datec,' ;
2020-02-02 19:34:09 +01:00
$sql .= ' a.datevalid as datev,' ;
$sql .= ' a.tms as datem,' ;
$sql .= ' a.fk_user_author, a.fk_user_valid, a.fk_user_mod' ;
2020-03-12 12:45:44 +01:00
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'adherent as a' ;
2021-03-14 11:48:39 +01:00
$sql .= ' WHERE a.rowid = ' . (( int ) $id );
2017-10-07 13:09:31 +02:00
2020-03-12 12:45:44 +01:00
dol_syslog ( get_class ( $this ) . " ::info " , LOG_DEBUG );
2020-02-02 19:34:09 +01:00
$result = $this -> db -> query ( $sql );
2020-02-24 22:53:14 +01:00
if ( $result ) {
if ( $this -> db -> num_rows ( $result )) {
2017-10-07 13:09:31 +02:00
$obj = $this -> db -> fetch_object ( $result );
$this -> id = $obj -> rowid ;
2022-06-28 13:09:53 +02:00
$this -> user_creation_id = $obj -> fk_user_author ;
$this -> user_validation_id = $obj -> fk_user_valid ;
$this -> user_modification_id = $obj -> fk_user_mod ;
2020-02-24 22:53:14 +01:00
$this -> date_creation = $this -> db -> jdate ( $obj -> datec );
$this -> date_validation = $this -> db -> jdate ( $obj -> datev );
2017-10-07 13:09:31 +02:00
$this -> date_modification = $this -> db -> jdate ( $obj -> datem );
}
$this -> db -> free ( $result );
2020-02-24 22:53:14 +01:00
} else {
2017-10-07 13:09:31 +02:00
dol_print_error ( $this -> db );
}
}
2006-11-26 19:24:53 +01:00
2018-06-06 18:18:50 +02:00
/**
* Return number of mass Emailing received by this member with its email
*
* @ return int Number of EMailings
*/
2019-02-25 00:56:48 +01:00
public function getNbOfEMailings ()
2018-06-06 18:18:50 +02:00
{
$sql = " SELECT count(mc.email) as nb " ;
2020-03-12 12:45:44 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " mailing_cibles as mc " ;
$sql .= " WHERE mc.email = ' " . $this -> db -> escape ( $this -> email ) . " ' " ;
2020-02-02 19:34:09 +01:00
$sql .= " AND mc.statut NOT IN (-1,0) " ; // -1 erreur, 0 non envoye, 1 envoye avec succes
2018-06-06 18:18:50 +02:00
2020-02-02 19:34:09 +01:00
$resql = $this -> db -> query ( $sql );
2020-02-24 22:53:14 +01:00
if ( $resql ) {
2018-06-06 18:18:50 +02:00
$obj = $this -> db -> fetch_object ( $resql );
2020-02-02 19:34:09 +01:00
$nb = $obj -> nb ;
2018-06-06 18:18:50 +02:00
$this -> db -> free ( $resql );
return $nb ;
2020-02-24 22:53:14 +01:00
} else {
2020-02-02 19:34:09 +01:00
$this -> error = $this -> db -> error ();
2018-06-06 18:18:50 +02:00
return - 1 ;
}
}
2015-09-30 18:46:51 +02:00
/**
* Sets object to supplied categories .
*
* Deletes object from existing categories not supplied .
* Adds it to non existing supplied categories .
* Existing categories are left untouch .
*
* @ param int [] | int $categories Category or categories IDs
2020-02-24 22:53:14 +01:00
* @ return void
2015-09-30 18:46:51 +02:00
*/
public function setCategories ( $categories )
{
2020-03-12 12:45:44 +01:00
require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php' ;
2020-12-23 23:32:50 +01:00
return parent :: setCategoriesCommon ( $categories , Categorie :: TYPE_MEMBER );
2015-09-30 18:46:51 +02:00
}
2015-04-18 18:11:01 +02:00
/**
* Function used to replace a thirdparty id with another one .
*
2018-03-05 21:46:24 +01:00
* @ param DoliDB $db Database handler
* @ param int $origin_id Old thirdparty id
* @ param int $dest_id New thirdparty id
2015-04-18 18:11:01 +02:00
* @ return bool
*/
public static function replaceThirdparty ( $db , $origin_id , $dest_id )
{
2020-02-24 22:53:14 +01:00
$tables = array ( 'adherent' );
2015-04-18 18:11:01 +02:00
return CommonObject :: commonReplaceThirdparty ( $db , $origin_id , $dest_id , $tables );
}
2016-06-06 16:31:50 +02:00
/**
* Return if a member is late ( subscription late ) or not
2017-03-13 15:00:44 +01:00
*
2016-06-06 16:31:50 +02:00
* @ return boolean True if late , False if not late
*/
2017-10-07 13:09:31 +02:00
public function hasDelay ()
{
global $conf ;
2015-09-05 11:03:37 +02:00
2017-10-07 13:09:31 +02:00
//Only valid members
2021-04-27 21:43:13 +02:00
if ( $this -> statut != self :: STATUS_VALIDATED ) {
2021-03-01 00:19:52 +01:00
return false ;
}
if ( ! $this -> datefin ) {
return false ;
}
2015-09-05 11:03:37 +02:00
2017-10-07 13:09:31 +02:00
$now = dol_now ();
2015-09-05 11:03:37 +02:00
2017-10-07 13:09:31 +02:00
return $this -> datefin < ( $now - $conf -> adherent -> subscription -> warning_delay );
}
2015-09-05 11:03:37 +02:00
2018-03-21 16:40:09 +01:00
/**
* Send reminders by emails before subscription end
* CAN BE A CRON TASK
*
2018-10-09 23:10:39 +02:00
* @ param string $daysbeforeendlist Nb of days before end of subscription ( negative number = after subscription ) . Can be a list of delay , separated by a semicolon , for example '10;5;0;-5'
* @ return int 0 if OK , <> 0 if KO ( this function is used also by cron so only 0 is OK )
2018-03-21 16:40:09 +01:00
*/
2019-01-27 15:20:16 +01:00
public function sendReminderForExpiredSubscription ( $daysbeforeendlist = '10' )
2018-03-21 16:40:09 +01:00
{
global $conf , $langs , $mysoc , $user ;
2018-03-24 18:28:06 +01:00
$error = 0 ;
2018-03-21 16:40:09 +01:00
$this -> output = '' ;
2020-02-02 19:34:09 +01:00
$this -> error = '' ;
2018-03-21 16:40:09 +01:00
$blockingerrormsg = '' ;
2020-05-21 09:12:18 +02:00
if ( empty ( $conf -> adherent -> enabled )) { // Should not happen. If module disabled, cron job should not be visible.
2018-11-03 12:37:52 +01:00
$langs -> load ( " agenda " );
$this -> output = $langs -> trans ( 'ModuleNotEnabled' , $langs -> transnoentitiesnoconv ( " Adherent " ));
return 0 ;
}
2020-02-24 22:53:14 +01:00
if ( empty ( $conf -> global -> MEMBER_REMINDER_EMAIL )) {
2018-03-21 16:40:09 +01:00
$langs -> load ( " agenda " );
$this -> output = $langs -> trans ( 'EventRemindersByEmailNotEnabled' , $langs -> transnoentitiesnoconv ( " Adherent " ));
return 0 ;
2018-11-03 12:37:52 +01:00
}
2018-11-26 12:41:10 +01:00
2018-03-21 16:40:09 +01:00
$now = dol_now ();
2018-10-09 23:10:39 +02:00
$nbok = 0 ;
$nbko = 0 ;
2018-03-21 16:40:09 +01:00
2020-01-28 11:38:27 +01:00
$listofmembersok = array ();
$listofmembersko = array ();
2020-02-02 19:34:09 +01:00
$arraydaysbeforeend = explode ( ';' , $daysbeforeendlist );
2020-05-21 09:12:18 +02:00
foreach ( $arraydaysbeforeend as $daysbeforeend ) { // Loop on each delay
2020-03-12 12:45:44 +01:00
dol_syslog ( __METHOD__ . ' - Process delta = ' . $daysbeforeend , LOG_DEBUG );
2018-03-21 16:40:09 +01:00
2020-02-24 22:53:14 +01:00
if ( ! is_numeric ( $daysbeforeend )) {
2022-11-23 18:52:43 +01:00
$blockingerrormsg = " Value for delta is not a numeric value " ;
2018-10-09 23:10:39 +02:00
$nbko ++ ;
break ;
}
2018-03-21 16:40:09 +01:00
2020-02-02 19:34:09 +01:00
$tmp = dol_getdate ( $now );
2022-11-23 18:52:43 +01:00
$datetosearchfor = dol_time_plus_duree ( dol_mktime ( 0 , 0 , 0 , $tmp [ 'mon' ], $tmp [ 'mday' ], $tmp [ 'year' ], 'tzserver' ), $daysbeforeend , 'd' );
2018-03-21 16:40:09 +01:00
2020-03-12 12:45:44 +01:00
$sql = 'SELECT rowid FROM ' . MAIN_DB_PREFIX . 'adherent' ;
2022-11-23 18:52:43 +01:00
$sql .= " WHERE entity = " . (( int ) $conf -> entity ); // Do not use getEntity('adherent').")" here, we want the batch to be on its entity only;
2020-03-12 12:45:44 +01:00
$sql .= " AND datefin = ' " . $this -> db -> idate ( $datetosearchfor ) . " ' " ;
2022-11-23 18:52:43 +01:00
//$sql .= " LIMIT 10000";
2018-03-21 16:40:09 +01:00
2018-10-09 23:10:39 +02:00
$resql = $this -> db -> query ( $sql );
2020-02-24 22:53:14 +01:00
if ( $resql ) {
2018-10-09 23:10:39 +02:00
$num_rows = $this -> db -> num_rows ( $resql );
2018-03-21 16:40:09 +01:00
2020-03-12 12:45:44 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php' ;
2018-10-09 23:10:39 +02:00
$adherent = new Adherent ( $this -> db );
$formmail = new FormMail ( $this -> db );
2018-03-21 16:40:09 +01:00
2020-02-02 19:34:09 +01:00
$i = 0 ;
2020-02-24 22:53:14 +01:00
while ( $i < $num_rows ) {
2018-10-09 23:10:39 +02:00
$obj = $this -> db -> fetch_object ( $resql );
2018-03-21 16:40:09 +01:00
2018-10-09 23:10:39 +02:00
$adherent -> fetch ( $obj -> rowid , '' , '' , '' , true , true );
2018-03-21 16:40:09 +01:00
2020-02-24 22:53:14 +01:00
if ( empty ( $adherent -> email )) {
2018-10-09 23:10:39 +02:00
$nbko ++ ;
2020-02-02 19:34:09 +01:00
$listofmembersko [ $adherent -> id ] = $adherent -> id ;
2020-02-24 22:53:14 +01:00
} else {
2018-10-09 23:10:39 +02:00
$adherent -> fetch_thirdparty ();
2018-03-21 16:40:09 +01:00
2019-02-28 13:11:14 +01:00
// Language code to use ($languagecodeformember) is default language of thirdparty, if no thirdparty, the language found from country of member then country of thirdparty, and if still not found we use the language of company.
$languagefromcountrycode = getLanguageCodeFromCountryCode ( $adherent -> country_code ? $adherent -> country_code : $adherent -> thirdparty -> country_code );
$languagecodeformember = ( empty ( $adherent -> thirdparty -> default_lang ) ? ( $languagefromcountrycode ? $languagefromcountrycode : $mysoc -> default_lang ) : $adherent -> thirdparty -> default_lang );
2018-10-09 23:10:39 +02:00
// Send reminder email
$outputlangs = new Translate ( '' , $conf );
2019-02-28 13:11:14 +01:00
$outputlangs -> setDefaultLang ( $languagecodeformember );
2018-10-09 23:10:39 +02:00
$outputlangs -> loadLangs ( array ( " main " , " members " ));
2020-03-12 12:45:44 +01:00
dol_syslog ( " sendReminderForExpiredSubscription Language for member id " . $adherent -> id . " set to " . $outputlangs -> defaultlang . " mysoc->default_lang= " . $mysoc -> default_lang );
2018-03-23 16:09:46 +01:00
2020-02-02 19:34:09 +01:00
$arraydefaultmessage = null ;
2022-11-23 18:52:43 +01:00
$labeltouse = getDolGlobalString ( 'ADHERENT_EMAIL_TEMPLATE_REMIND_EXPIRATION' );
2018-03-21 16:40:09 +01:00
2021-03-01 00:19:52 +01:00
if ( ! empty ( $labeltouse )) {
$arraydefaultmessage = $formmail -> getEMailTemplate ( $this -> db , 'member' , $user , $outputlangs , 0 , 1 , $labeltouse );
}
2018-03-23 16:09:46 +01:00
2020-02-24 22:53:14 +01:00
if ( ! empty ( $labeltouse ) && is_object ( $arraydefaultmessage ) && $arraydefaultmessage -> id > 0 ) {
2020-02-02 19:34:09 +01:00
$substitutionarray = getCommonSubstitutionArray ( $outputlangs , 0 , null , $adherent );
2018-10-09 23:10:39 +02:00
//if (is_array($adherent->thirdparty)) $substitutionarraycomp = ...
complete_substitutions_array ( $substitutionarray , $outputlangs , $adherent );
$subject = make_substitutions ( $arraydefaultmessage -> topic , $substitutionarray , $outputlangs );
2020-02-24 22:53:14 +01:00
$msg = make_substitutions ( $arraydefaultmessage -> content , $substitutionarray , $outputlangs );
2018-10-09 23:10:39 +02:00
$from = $conf -> global -> ADHERENT_MAIL_FROM ;
$to = $adherent -> email ;
2020-03-12 12:45:44 +01:00
$trackid = 'mem' . $adherent -> id ;
$moreinheader = 'X-Dolibarr-Info: sendReminderForExpiredSubscription' . " \r \n " ;
2018-10-09 23:10:39 +02:00
2020-03-12 12:45:44 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php' ;
2018-10-09 23:10:39 +02:00
$cmail = new CMailFile ( $subject , $to , $from , $msg , array (), array (), array (), '' , '' , 0 , 1 , '' , '' , $trackid , $moreinheader );
$result = $cmail -> sendfile ();
2020-02-24 22:53:14 +01:00
if ( ! $result ) {
2018-10-09 23:10:39 +02:00
$error ++ ;
2022-11-23 18:52:43 +01:00
$this -> error .= $cmail -> error . ' ' ;
2020-02-02 19:34:09 +01:00
if ( ! is_null ( $cmail -> errors )) {
2020-01-28 11:38:27 +01:00
$this -> errors += $cmail -> errors ;
}
2018-10-09 23:10:39 +02:00
$nbko ++ ;
2020-02-02 19:34:09 +01:00
$listofmembersko [ $adherent -> id ] = $adherent -> id ;
2020-02-24 22:53:14 +01:00
} else {
2018-10-09 23:10:39 +02:00
$nbok ++ ;
2020-02-02 19:34:09 +01:00
$listofmembersok [ $adherent -> id ] = $adherent -> id ;
2018-10-09 23:10:39 +02:00
2018-11-03 22:53:55 +01:00
$message = $msg ;
$sendto = $to ;
$sendtocc = '' ;
$sendtobcc = '' ;
2020-02-02 19:34:09 +01:00
$actioncode = 'EMAIL' ;
$extraparams = '' ;
2018-11-03 22:53:55 +01:00
2020-02-02 19:34:09 +01:00
$actionmsg = '' ;
2022-11-23 18:52:43 +01:00
$actionmsg2 = $langs -> transnoentities ( 'MailSentBy' ) . ' ' . CMailFile :: getValidAddress ( $from , 4 , 0 , 1 ) . ' ' . $langs -> transnoentities ( 'To' ) . ' ' . CMailFile :: getValidAddress ( $sendto , 4 , 0 , 1 );
2020-02-24 22:53:14 +01:00
if ( $message ) {
2020-03-12 12:45:44 +01:00
$actionmsg = $langs -> transnoentities ( 'MailFrom' ) . ': ' . dol_escape_htmltag ( $from );
$actionmsg = dol_concatdesc ( $actionmsg , $langs -> transnoentities ( 'MailTo' ) . ': ' . dol_escape_htmltag ( $sendto ));
2021-03-01 00:19:52 +01:00
if ( $sendtocc ) {
$actionmsg = dol_concatdesc ( $actionmsg , $langs -> transnoentities ( 'Bcc' ) . " : " . dol_escape_htmltag ( $sendtocc ));
}
2020-03-12 12:45:44 +01:00
$actionmsg = dol_concatdesc ( $actionmsg , $langs -> transnoentities ( 'MailTopic' ) . " : " . $subject );
$actionmsg = dol_concatdesc ( $actionmsg , $langs -> transnoentities ( 'TextUsedInTheMessageBody' ) . " : " );
2018-11-03 22:53:55 +01:00
$actionmsg = dol_concatdesc ( $actionmsg , $message );
}
2018-11-26 12:41:10 +01:00
2020-03-12 12:45:44 +01:00
require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php' ;
2020-02-24 22:53:14 +01:00
// Insert record of emails sent
$actioncomm = new ActionComm ( $this -> db );
$actioncomm -> type_code = 'AC_OTH_AUTO' ; // Type of event ('AC_OTH', 'AC_OTH_AUTO', 'AC_XXX'...)
2020-03-12 12:45:44 +01:00
$actioncomm -> code = 'AC_' . $actioncode ;
2020-02-24 22:53:14 +01:00
$actioncomm -> label = $actionmsg2 ;
$actioncomm -> note_private = $actionmsg ;
$actioncomm -> fk_project = 0 ;
$actioncomm -> datep = $now ;
$actioncomm -> datef = $now ;
$actioncomm -> percentage = - 1 ; // Not applicable
$actioncomm -> socid = $adherent -> thirdparty -> id ;
2020-06-25 12:17:47 +02:00
$actioncomm -> contact_id = 0 ;
2020-02-24 22:53:14 +01:00
$actioncomm -> authorid = $user -> id ; // User saving action
$actioncomm -> userownerid = $user -> id ; // Owner of action
// Fields when action is en email (content should be added into note)
$actioncomm -> email_msgid = $cmail -> msgid ;
$actioncomm -> email_from = $from ;
$actioncomm -> email_sender = '' ;
$actioncomm -> email_to = $to ;
$actioncomm -> email_tocc = $sendtocc ;
$actioncomm -> email_tobcc = $sendtobcc ;
$actioncomm -> email_subject = $subject ;
$actioncomm -> errors_to = '' ;
$actioncomm -> fk_element = $adherent -> id ;
$actioncomm -> elementtype = $adherent -> element ;
$actioncomm -> extraparams = $extraparams ;
$actioncomm -> create ( $user );
2018-10-09 23:10:39 +02:00
}
2020-02-24 22:53:14 +01:00
} else {
2022-11-23 18:52:43 +01:00
//$blockingerrormsg = "Can't find email template with label=".$labeltouse.", to use for the reminding email";
$error ++ ;
$this -> error .= " Can't find email template with label= " . $labeltouse . " , to use for the reminding email " ;
2020-01-28 11:38:27 +01:00
2018-10-09 23:10:39 +02:00
$nbko ++ ;
2020-02-02 19:34:09 +01:00
$listofmembersko [ $adherent -> id ] = $adherent -> id ;
2020-01-28 11:38:27 +01:00
2018-10-09 23:10:39 +02:00
break ;
2018-03-21 16:40:09 +01:00
}
}
2018-10-09 23:10:39 +02:00
$i ++ ;
}
2020-02-24 22:53:14 +01:00
} else {
2018-10-09 23:10:39 +02:00
$this -> error = $this -> db -> lasterror ();
return 1 ;
2018-03-21 16:40:09 +01:00
}
}
2020-02-24 22:53:14 +01:00
if ( $blockingerrormsg ) {
2018-03-21 16:40:09 +01:00
$this -> error = $blockingerrormsg ;
return 1 ;
2020-02-24 22:53:14 +01:00
} else {
2020-03-12 12:45:44 +01:00
$this -> output = 'Found ' . ( $nbok + $nbko ) . ' members to send reminder to.' ;
$this -> output .= ' Send email successfuly to ' . $nbok . ' members' ;
2020-01-28 11:38:27 +01:00
if ( is_array ( $listofmembersok )) {
2020-02-24 22:53:14 +01:00
$listofids = '' ;
$i = 0 ;
2020-02-02 19:34:09 +01:00
foreach ( $listofmembersok as $idmember ) {
2020-01-28 11:38:27 +01:00
if ( $i > 100 ) {
$listofids .= ', ...' ;
break ;
}
2020-05-21 00:47:16 +02:00
if ( empty ( $listofids )) {
2020-02-24 22:53:14 +01:00
$listofids .= ' [' ;
2020-05-21 00:47:16 +02:00
} else {
2020-02-24 22:53:14 +01:00
$listofids .= ', ' ;
2020-05-21 00:47:16 +02:00
}
2020-01-28 11:38:27 +01:00
$listofids .= $idmember ;
$i ++ ;
}
2021-03-01 00:19:52 +01:00
if ( $listofids ) {
$listofids .= ']' ;
}
2022-11-23 18:58:17 +01:00
$this -> output .= ( $listofids ? ' ids=' . $listofids : '' );
2020-01-28 11:38:27 +01:00
}
if ( $nbko ) {
2020-03-12 12:45:44 +01:00
$this -> output .= ' - Canceled for ' . $nbko . ' member (no email or email sending error)' ;
2020-01-28 11:38:27 +01:00
if ( is_array ( $listofmembersko )) {
2020-02-24 22:53:14 +01:00
$listofids = '' ;
$i = 0 ;
2020-02-02 19:34:09 +01:00
foreach ( $listofmembersko as $idmember ) {
2020-01-28 11:38:27 +01:00
if ( $i > 100 ) {
$listofids .= ', ...' ;
break ;
}
2020-05-21 00:47:16 +02:00
if ( empty ( $listofids )) {
2020-02-24 22:53:14 +01:00
$listofids .= ' [' ;
2020-05-21 00:47:16 +02:00
} else {
2020-02-24 22:53:14 +01:00
$listofids .= ', ' ;
2020-05-21 00:47:16 +02:00
}
2020-01-28 11:38:27 +01:00
$listofids .= $idmember ;
$i ++ ;
}
2021-03-01 00:19:52 +01:00
if ( $listofids ) {
$listofids .= ']' ;
}
2022-11-23 18:58:17 +01:00
$this -> output .= ( $listofids ? ' ids=' . $listofids : '' );
2020-01-28 11:38:27 +01:00
}
}
2018-03-21 16:40:09 +01:00
}
2022-11-23 18:52:43 +01:00
return $nbko ;
2018-03-21 16:40:09 +01:00
}
2003-09-01 00:05:54 +02:00
}