2006-02-24 23:16:35 +00:00
< ? php
2025-08-20 17:02:08 +00:00
/* Copyright ( C ) 2002 - 2004 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2004 Benoit Mortier < benoit . mortier @ opensides . be >
* Copyright ( C ) 2004 - 2013 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ inodbox . com >
* Copyright ( C ) 2007 Franky Van Liedekerke < franky . van . liedekerker @ telenet . be >
* Copyright ( C ) 2008 Raphael Bertrand ( Resultic ) < raphael . bertrand @ resultic . fr >
* Copyright ( C ) 2013 Florian Henry < florian . henry @ open - concept . pro >
* Copyright ( C ) 2013 Alexandre Spangaro < aspangaro @ open - dsi . fr >
* Copyright ( C ) 2013 Juanjo Menent < jmenent @ 2 byte . es >
* Copyright ( C ) 2015 Marcos García < marcosgdf @ gmail . com >
* Copyright ( C ) 2019 Nicolas ZABOURI < info @ inovea - conseil . com >
* Copyright ( C ) 2020 Open - Dsi < support @ open - dsi . fr >
2025-03-01 14:42:29 +00:00
* Copyright ( C ) 2024 - 2025 Frédéric France < frederic . france @ free . fr >
2026-07-23 17:06:39 +00:00
* Copyright ( C ) 2024 - 2026 MDW < mdeweerd @ users . noreply . github . com >
2006-02-24 23:16:35 +00:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2013-01-16 14:36:08 +00:00
* the Free Software Foundation ; either version 3 of the License , or
2006-02-24 23:16:35 +00:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 19:55:30 +00:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2006-02-24 23:16:35 +00:00
*/
/**
2010-06-06 14:30:28 +00:00
* \file htdocs / contact / class / contact . class . php
2009-08-12 00:15:40 +00:00
* \ingroup societe
2010-02-21 13:08:02 +00:00
* \brief File of contacts class
2009-08-11 12:51:33 +00:00
*/
2019-11-08 14:51:54 +00:00
require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php' ;
2023-01-20 12:36:23 +00:00
require_once DOL_DOCUMENT_ROOT . '/core/class/commonsocialnetworks.class.php' ;
2023-04-27 21:48:21 +00:00
require_once DOL_DOCUMENT_ROOT . '/core/class/commonpeople.class.php' ;
2007-11-05 22:37:41 +00:00
2006-02-24 23:16:35 +00:00
/**
2012-11-15 13:52:19 +00:00
* Class to manage contact / addresses
2009-08-11 12:51:33 +00:00
*/
2007-11-05 22:37:41 +00:00
class Contact extends CommonObject
2006-02-24 23:16:35 +00:00
{
2023-01-20 12:36:23 +00:00
use CommonSocialNetworks ;
2023-04-27 21:48:21 +00:00
use CommonPeople ;
2023-01-20 12:36:23 +00:00
2025-08-20 17:02:08 +00:00
/**
* @ var string Prefix to check for any trigger code of any business class to prevent bad value for trigger code .
* @ see CommonTrigger :: call_trigger ()
*/
public $TRIGGER_PREFIX = 'CONTACT' ;
2018-08-23 16:17:09 +00:00
/**
* @ var string ID to identify managed object
*/
2019-11-08 14:51:54 +00:00
public $element = 'contact' ;
2018-09-02 16:18:10 +00:00
2018-08-22 16:34:50 +00:00
/**
* @ var string Name of table without prefix where object is stored
*/
2019-11-08 14:51:54 +00:00
public $table_element = 'socpeople' ;
2018-09-02 16:18:10 +00:00
2018-09-05 10:21:13 +00:00
/**
* @ var string String with name of icon for myobject . Must be the part after the 'object_' into object_myobject . png
*/
2017-11-02 14:03:09 +00:00
public $picto = 'contact' ;
2009-01-19 22:41:26 +00:00
2020-09-29 12:59:16 +00:00
/**
* 'type' if the field format ( 'integer' , 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]' , 'varchar(x)' , 'double(24,8)' , 'real' , 'price' , 'text' , 'html' , 'date' , 'datetime' , 'timestamp' , 'duration' , 'mail' , 'phone' , 'url' , 'password' )
2026-05-29 10:16:42 +00:00
* Note : Filter can be a string like " (t.ref:like:'SO-%') or (t.date_creation:>:'20160101') or (t.nature:is:NULL) "
2020-09-29 12:59:16 +00:00
* 'label' the translation key .
* 'enabled' is a condition when the field must be managed .
* 'position' is the sort order of field .
* 'notnull' is set to 1 if not null in database . Set to - 1 if we must set data to null if empty ( '' or 0 ) .
* 'visible' says if field is visible in list ( Examples : 0 = Not visible , 1 = Visible on list and create / update / view forms , 2 = Visible on list only , 3 = Visible on create / update / view form only ( not list ), 4 = Visible on list and update / view form only ( not create ) . 5 = Visible on list and view only ( not create / not update ) . Using a negative value means field is not shown by default on list but can be selected for viewing )
* 'noteditable' says if field is not editable ( 1 or 0 )
2025-09-03 10:54:17 +00:00
* 'default' is a default value for creation ( can still be overwritten by the Setup of Default Values if the field is editable in creation form ) . Note : If default is set to '(PROV)' and field is 'ref' , the default value will be set to '(PROVid)' where id is rowid when a new record is created .
2020-09-29 12:59:16 +00:00
* 'index' if we want an index in database .
2024-01-14 11:26:37 +00:00
* 'foreignkey' => 'tablename.field' if the field is a foreign key ( it is recommended to name the field fk_ ... ) .
2020-09-29 12:59:16 +00:00
* 'searchall' is 1 if we want to search in this field when making a search from the quick search button .
* 'isameasure' must be set to 1 if you want to have a total on list for this field . Field type must be summable like integer or double ( 24 , 8 ) .
* 'css' is the CSS style to use on field . For example : 'maxwidth200'
* 'help' is a string visible as a tooltip on field
* 'showoncombobox' if value of the field must be visible into the label of the combobox that list record
* 'disabled' is 1 if we want to have the field locked by a 'disabled' attribute . In most cases , this is never set into the definition of $fields into class , but is set dynamically by some part of code .
2021-04-29 10:10:55 +00:00
* 'arrayofkeyval' to set list of value if type is a list of predefined values . For example : array ( " 0 " => " Draft " , " 1 " => " Active " , " -1 " => " Cancel " )
2020-09-29 12:59:16 +00:00
* 'comment' is not used . You can store here any text of your choice . It is not used by application .
*
* Note : To have value dynamic , you can set value to 0 in definition and edit the value on the fly into the constructor .
*/
2018-01-31 09:51:40 +00:00
// BEGIN MODULEBUILDER PROPERTIES
/**
2024-12-04 23:06:24 +00:00
* array < string , array { type : string , label : string , enabled : int < 0 , 2 >| string , position : int , notnull ? : int , visible : int <- 2 , 5 >| string , alwayseditable ? : int < 0 , 1 > , noteditable ? : int < 0 , 1 > , default ? : string , index ? : int , foreignkey ? : string , searchall ? : int < 0 , 1 > , isameasure ? : int < 0 , 1 > , css ? : string , csslist ? : string , help ? : string , showoncombobox ? : int < 0 , 2 > , disabled ? : int < 0 , 1 > , arrayofkeyval ? : array < int , string > , autofocusoncreate ? : int < 0 , 1 > , comment ? : string , copytoclipboard ? : int < 1 , 2 > , validate ? : int < 0 , 1 > } > Array with all fields and their property . Do not use it as a static var . It may be modified by constructor .
2018-01-31 09:51:40 +00:00
*/
2020-02-18 22:47:25 +00:00
public $fields = array (
2024-03-11 16:39:09 +00:00
'rowid' => array ( 'type' => 'integer' , 'label' => 'TechnicalID' , 'enabled' => 1 , 'visible' => - 2 , 'noteditable' => 1 , 'notnull' => 1 , 'index' => 1 , 'position' => 1 , 'comment' => 'Id' , 'css' => 'left' ),
2024-03-14 23:21:31 +00:00
'entity' => array ( 'type' => 'integer' , 'label' => 'Entity' , 'default' => '1' , 'enabled' => 1 , 'visible' => 3 , 'notnull' => 1 , 'position' => 30 , 'index' => 1 ),
2025-01-12 17:00:01 +00:00
'ref_ext' => array ( 'type' => 'varchar(255)' , 'label' => 'RefExt' , 'enabled' => 1 , 'visible' => 0 , 'position' => 35 ),
2024-03-11 16:39:09 +00:00
'civility' => array ( 'type' => 'varchar(6)' , 'label' => 'Civility' , 'enabled' => 1 , 'visible' => 3 , 'position' => 40 ),
'lastname' => array ( 'type' => 'varchar(50)' , 'label' => 'Lastname' , 'enabled' => 1 , 'visible' => 1 , 'position' => 45 , 'showoncombobox' => 1 , 'searchall' => 1 ),
'name_alias' => array ( 'type' => 'varchar(255)' , 'label' => 'Name alias' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 46 , 'searchall' => 1 ),
'firstname' => array ( 'type' => 'varchar(50)' , 'label' => 'Firstname' , 'enabled' => 1 , 'visible' => 1 , 'position' => 50 , 'showoncombobox' => 1 , 'searchall' => 1 ),
'poste' => array ( 'type' => 'varchar(80)' , 'label' => 'PostOrFunction' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 52 ),
'address' => array ( 'type' => 'varchar(255)' , 'label' => 'Address' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 55 ),
2024-06-04 00:24:33 +00:00
'zip' => array ( 'type' => 'varchar(25)' , 'label' => 'Zip' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 60 ),
2024-03-11 16:39:09 +00:00
'town' => array ( 'type' => 'varchar(50)' , 'label' => 'Town' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 65 ),
'fk_departement' => array ( 'type' => 'integer' , 'label' => 'Fk departement' , 'enabled' => 1 , 'visible' => 3 , 'position' => 70 ),
'fk_pays' => array ( 'type' => 'integer' , 'label' => 'Fk pays' , 'enabled' => 1 , 'visible' => 3 , 'position' => 75 ),
2025-04-09 14:36:42 +00:00
'fk_soc' => array ( 'type' => 'integer:Societe:societe/class/societe.class.php' , 'label' => 'ThirdParty' , 'enabled' => 1 , 'visible' => 1 , 'position' => 77 , 'searchall' => 1 ),
2024-03-11 16:39:09 +00:00
'birthday' => array ( 'type' => 'date' , 'label' => 'Birthday' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 80 ),
'phone' => array ( 'type' => 'varchar(30)' , 'label' => 'Phone' , 'enabled' => 1 , 'visible' => 1 , 'position' => 90 , 'searchall' => 1 ),
'phone_perso' => array ( 'type' => 'varchar(30)' , 'label' => 'PhonePerso' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 95 , 'searchall' => 1 ),
'phone_mobile' => array ( 'type' => 'varchar(30)' , 'label' => 'PhoneMobile' , 'enabled' => 1 , 'visible' => 1 , 'position' => 100 , 'searchall' => 1 ),
'fax' => array ( 'type' => 'varchar(30)' , 'label' => 'Fax' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 105 , 'searchall' => 1 ),
'email' => array ( 'type' => 'varchar(255)' , 'label' => 'Email' , 'enabled' => 1 , 'visible' => 1 , 'position' => 110 , 'searchall' => 1 ),
'socialnetworks' => array ( 'type' => 'text' , 'label' => 'SocialNetworks' , 'enabled' => 1 , 'visible' => 3 , 'position' => 115 ),
'photo' => array ( 'type' => 'varchar(255)' , 'label' => 'Photo' , 'enabled' => 1 , 'visible' => 3 , 'position' => 170 ),
'priv' => array ( 'type' => 'smallint(6)' , 'label' => 'ContactVisibility' , 'enabled' => 1 , 'visible' => 1 , 'notnull' => 1 , 'position' => 175 ),
'fk_stcommcontact' => array ( 'type' => 'integer' , 'label' => 'ProspectStatus' , 'enabled' => 1 , 'visible' => - 1 , 'notnull' => 1 , 'position' => 220 ),
'fk_prospectcontactlevel' => array ( 'type' => 'varchar(12)' , 'label' => 'ProspectLevel' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 255 ),
2023-11-14 01:26:33 +00:00
//no more used. Replace by a scan of email into mailing_unsubscribe. 'no_email' =>array('type'=>'smallint(6)', 'label'=>'No_Email', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>180),
2025-09-11 14:03:25 +00:00
'note_private' => array ( 'type' => 'html' , 'label' => 'NotePrivate' , 'enabled' => 1 , 'visible' => 0 , 'position' => 195 , 'searchall' => 1 ),
'note_public' => array ( 'type' => 'html' , 'label' => 'NotePublic' , 'enabled' => 1 , 'visible' => 0 , 'position' => 200 , 'searchall' => 1 ),
2024-03-11 16:39:09 +00:00
'default_lang' => array ( 'type' => 'varchar(6)' , 'label' => 'Default lang' , 'enabled' => 1 , 'visible' => 3 , 'position' => 205 ),
'canvas' => array ( 'type' => 'varchar(32)' , 'label' => 'Canvas' , 'enabled' => 1 , 'visible' => 3 , 'position' => 210 ),
2025-01-15 13:00:11 +00:00
'ip' => array ( 'type' => 'ip' , 'label' => 'IPAddress' , 'enabled' => '1' , 'position' => 700 , 'notnull' => 0 , 'visible' => '-2' , 'comment' => 'ip used to create record (for public submission page)' ),
2024-03-11 16:39:09 +00:00
'datec' => array ( 'type' => 'datetime' , 'label' => 'DateCreation' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 300 ),
'tms' => array ( 'type' => 'timestamp' , 'label' => 'DateModification' , 'enabled' => 1 , 'visible' => - 1 , 'notnull' => 1 , 'position' => 305 ),
2025-04-09 14:36:42 +00:00
'fk_user_creat' => array ( 'type' => 'integer:User:user/class/user.class.php' , 'label' => 'UserAuthor' , 'enabled' => 1 , 'visible' => 3 , 'position' => 310 ),
'fk_user_modif' => array ( 'type' => 'integer:User:user/class/user.class.php' , 'label' => 'UserModif' , 'enabled' => 1 , 'visible' => 3 , 'position' => 315 ),
2024-03-11 16:39:09 +00:00
'statut' => array ( 'type' => 'tinyint(4)' , 'label' => 'Status' , 'enabled' => 1 , 'visible' => 1 , 'notnull' => 1 , 'position' => 500 ),
'import_key' => array ( 'type' => 'varchar(14)' , 'label' => 'ImportId' , 'enabled' => 1 , 'visible' => - 1 , 'position' => 1000 ),
2019-12-20 10:14:16 +00:00
);
2024-10-25 19:00:02 +00:00
/**
* @ var string
*/
2019-12-03 10:17:29 +00:00
public $civility_id ; // In fact we store civility_code
2024-10-25 19:00:02 +00:00
/**
* @ var string
*/
2017-02-08 20:13:54 +00:00
public $civility_code ;
2024-10-25 19:00:02 +00:00
/**
* @ var string
*/
2019-09-05 11:38:38 +00:00
public $civility ;
2019-10-25 06:12:54 +00:00
2023-02-06 20:43:50 +00:00
/**
* @ var string gender
*/
public $gender ;
2023-01-18 21:20:25 +00:00
/**
* @ var int birthday_alert
*/
public $birthday_alert ;
2022-05-22 13:39:49 +00:00
/**
* @ var string The civilite code , not an integer
2024-10-25 19:00:02 +00:00
* @ deprecated Use $civility_code
2022-05-22 13:39:49 +00:00
* @ see $civility_code
*/
public $civilite ;
2023-01-18 21:20:25 +00:00
/**
* @ var string fullname
*/
public $fullname ;
2024-02-18 22:43:00 +00:00
/**
* @ var string Name alias
*/
public $name_alias ;
2019-10-25 06:12:54 +00:00
/**
2025-03-01 14:42:29 +00:00
* @ var ? string Address
2019-10-25 06:12:54 +00:00
*/
2017-02-08 20:13:54 +00:00
public $address ;
2020-11-05 13:48:41 +00:00
/**
2025-03-01 14:42:29 +00:00
* @ var ? string zip code
2020-11-05 13:48:41 +00:00
*/
2017-02-08 20:13:54 +00:00
public $zip ;
2020-11-05 13:48:41 +00:00
/**
2025-03-01 14:42:29 +00:00
* @ var ? string Town
2020-11-05 13:48:41 +00:00
*/
2017-02-08 20:13:54 +00:00
public $town ;
2010-06-06 14:30:28 +00:00
2021-01-16 13:24:47 +00:00
/**
2023-10-07 05:02:22 +00:00
* @ var int Id of department
2021-01-16 13:24:47 +00:00
*/
public $state_id ;
/**
2023-10-07 05:02:22 +00:00
* @ var string Code of department
2021-01-16 13:24:47 +00:00
*/
public $state_code ;
/**
2023-10-07 05:02:22 +00:00
* @ var string Label of department
2021-01-16 13:24:47 +00:00
*/
public $state ;
2010-06-06 14:30:28 +00:00
2023-10-07 05:02:22 +00:00
/**
* @ var string Job Position
*/
public $poste ;
2013-11-27 14:19:24 +00:00
2021-01-16 13:24:47 +00:00
/**
* @ var int Thirdparty ID
*/
2021-10-05 11:09:32 +00:00
public $socid ; // both socid and fk_soc are used
2024-10-25 19:00:02 +00:00
/**
* @ var int
*/
2021-10-05 11:09:32 +00:00
public $fk_soc ; // both socid and fk_soc are used
2021-01-16 13:24:47 +00:00
2023-02-06 20:43:50 +00:00
/**
2023-10-07 05:02:22 +00:00
* @ var string Thirdparty name
2023-02-06 20:43:50 +00:00
*/
public $socname ;
2021-01-16 13:24:47 +00:00
/**
2023-10-07 05:02:22 +00:00
* @ var int Status 0 = inactive , 1 = active
2025-08-15 15:31:44 +00:00
* @ deprecated Use $status
2021-01-16 13:24:47 +00:00
*/
public $statut ;
2009-08-11 12:51:33 +00:00
2024-10-25 19:00:02 +00:00
/**
* @ var string
*/
2017-02-08 20:13:54 +00:00
public $code ;
2019-10-25 06:12:54 +00:00
2020-10-31 13:32:18 +00:00
/**
* Email
2025-03-01 15:25:22 +00:00
* @ var ? string
2020-10-31 13:32:18 +00:00
*/
2017-02-08 20:13:54 +00:00
public $email ;
2019-09-12 16:04:24 +00:00
2023-02-06 20:43:50 +00:00
/**
* Email
2025-03-01 15:25:22 +00:00
* @ var ? string
2024-10-25 19:00:02 +00:00
* @ deprecated Use $email
2023-02-06 20:43:50 +00:00
* @ see $email
*/
public $mail ;
2022-05-19 11:08:00 +00:00
/**
* URL
2025-03-01 15:25:22 +00:00
* @ var ? string
2022-05-19 11:08:00 +00:00
*/
public $url ;
2020-10-31 13:32:18 +00:00
/**
2023-10-07 05:02:22 +00:00
* Unsubscribe all : 1 = contact has globally unsubscribed of all mass emailing
2019-10-25 06:12:54 +00:00
* @ var int
2023-11-14 01:26:50 +00:00
* @ deprecated Has been replaced by a search into llx_mailing_unsubscribe
2020-10-31 13:32:18 +00:00
*/
2019-10-25 06:12:54 +00:00
public $no_email ;
2020-10-31 13:32:18 +00:00
/**
2023-10-07 05:02:22 +00:00
* Array of social - networks
2024-10-25 19:00:02 +00:00
* @ var array < string , string >
2020-10-31 13:32:18 +00:00
*/
public $socialnetworks ;
2019-09-12 16:04:24 +00:00
2020-11-05 13:48:41 +00:00
/**
* @ var string filename for photo
*/
2019-09-14 09:26:31 +00:00
public $photo ;
2020-11-05 13:48:41 +00:00
/**
2023-10-07 05:02:22 +00:00
* @ var string phone pro ( professional / business )
2020-11-05 13:48:41 +00:00
*/
2017-02-08 20:13:54 +00:00
public $phone_pro ;
2020-11-05 13:48:41 +00:00
/**
2023-10-07 05:02:22 +00:00
* @ var string phone perso ( personal / private )
2020-11-05 13:48:41 +00:00
*/
2017-02-08 20:13:54 +00:00
public $phone_perso ;
2020-11-05 13:48:41 +00:00
/**
* @ var string phone mobile
*/
2017-02-08 20:13:54 +00:00
public $phone_mobile ;
2020-11-05 13:48:41 +00:00
/**
* @ var string fax
*/
2018-01-11 19:39:23 +00:00
public $fax ;
2013-11-14 16:16:27 +00:00
2020-01-07 09:54:19 +00:00
/**
* Private or public
* @ var int
*/
2018-01-11 19:39:23 +00:00
public $priv ;
2013-10-27 00:33:03 +00:00
2023-10-07 05:02:22 +00:00
/**
2023-10-23 17:19:10 +00:00
* @ var int | string Date
2023-10-07 05:02:22 +00:00
*/
2017-02-08 20:13:54 +00:00
public $birthday ;
2023-10-07 05:02:22 +00:00
/**
* @ var string language for contact communication -- only with multilanguage enabled
*/
2017-02-08 20:13:54 +00:00
public $default_lang ;
2009-08-11 12:51:33 +00:00
2021-02-11 20:26:21 +00:00
/**
* @ var int Number of invoices for which he is contact
*/
public $ref_facturation ;
/**
* @ var int Number of contracts for which he is contact
*/
public $ref_contrat ;
/**
* @ var int Number of orders for which he is contact
*/
public $ref_commande ;
/**
* @ var int Number of proposals for which he is contact
*/
public $ref_propal ;
2006-02-24 23:16:35 +00:00
2021-01-16 13:24:47 +00:00
/**
* @ var int user ID
*/
2017-02-08 20:13:54 +00:00
public $user_id ;
2021-01-16 13:24:47 +00:00
/**
* @ var string user login
*/
2017-02-08 20:13:54 +00:00
public $user_login ;
2007-04-26 22:01:10 +00:00
2024-09-26 20:17:19 +00:00
/**
* @ var string IP address
*/
public $ip ;
2018-01-31 09:51:40 +00:00
// END MODULEBUILDER PROPERTIES
2021-01-16 13:24:47 +00:00
/**
2025-09-11 10:14:53 +00:00
* @ var null | array < int , array { id : int , socid : int , element : string , source : string , code : string , label : string } > roles , null until fetched or set
2021-01-16 13:24:47 +00:00
*/
2021-01-22 12:40:00 +00:00
public $roles ;
2019-09-02 12:47:32 +00:00
2024-10-25 19:00:02 +00:00
/**
* @ var array < int , array { id : int , code : string , label : string , picto : string } >
*/
2020-04-27 15:35:14 +00:00
public $cacheprospectstatus = array ();
2024-01-19 15:22:16 +00:00
/**
* @ var string Prospect level . ie : 'PL_LOW' , 'PL...'
*/
2020-04-27 15:35:14 +00:00
public $fk_prospectlevel ;
2024-01-19 15:22:16 +00:00
2024-10-25 19:00:02 +00:00
/**
2025-09-11 10:14:53 +00:00
* @ var null | int Is null until fetched or set
2024-10-25 19:00:02 +00:00
*/
2020-04-27 15:35:14 +00:00
public $stcomm_id ;
2024-01-19 15:22:16 +00:00
2024-10-25 19:00:02 +00:00
/**
* @ var string
*/
2020-04-27 15:35:14 +00:00
public $statut_commercial ;
2021-01-16 13:24:47 +00:00
/**
* @ var string picto
*/
2020-04-27 15:35:14 +00:00
public $stcomm_picto ;
2007-04-26 22:01:10 +00:00
2022-05-19 11:08:00 +00:00
2009-08-11 12:51:33 +00:00
/**
2011-09-11 18:35:38 +00:00
* Constructor
*
2011-12-30 13:18:19 +00:00
* @ param DoliDB $db Database handler
2009-08-11 12:51:33 +00:00
*/
2019-02-24 23:56:48 +00:00
public function __construct ( $db )
2009-08-11 12:51:33 +00:00
{
2011-12-30 13:18:19 +00:00
$this -> db = $db ;
2020-09-30 09:45:29 +00:00
$this -> statut = 1 ; // By default, status is enabled
2025-08-15 15:31:44 +00:00
$this -> status = 1 ; // By default, status is enabled
2024-05-04 22:34:19 +00:00
$this -> ismultientitymanaged = 1 ;
$this -> isextrafieldmanaged = 1 ;
2020-09-30 09:45:29 +00:00
2025-01-12 17:00:01 +00:00
$this -> fields [ 'ref_ext' ][ 'visible' ] = getDolGlobalInt ( 'MAIN_LIST_SHOW_REF_EXT' );
2022-09-04 11:25:54 +00:00
if ( ! isModEnabled ( 'mailing' )) {
2020-11-05 13:48:41 +00:00
$this -> fields [ 'no_email' ][ 'enabled' ] = 0 ;
}
2020-09-30 09:45:29 +00:00
// typical ['s.nom'] is used for third-parties
2023-11-27 10:39:32 +00:00
if ( ! getDolGlobalString ( 'SOCIETE_DISABLE_CONTACTS' )) {
2020-09-30 09:45:29 +00:00
$this -> fields [ 'fk_soc' ][ 'enabled' ] = 0 ;
$this -> fields [ 'fk_soc' ][ 'searchall' ] = 0 ;
}
2019-12-20 10:14:16 +00:00
2023-10-20 11:32:13 +00:00
// If THIRDPARTY_ENABLE_PROSPECTION_ON_ALTERNATIVE_ADRESSES not set, there is no prospect level on contact level, only on thirdparty
2023-11-27 10:39:32 +00:00
if ( getDolGlobalString ( 'SOCIETE_DISABLE_PROSPECTS' ) || ! getDolGlobalString ( 'THIRDPARTY_ENABLE_PROSPECTION_ON_ALTERNATIVE_ADRESSES' )) { // Default behaviour
2022-11-04 16:32:48 +00:00
$this -> fields [ 'fk_stcommcontact' ][ 'enabled' ] = 0 ;
2023-10-20 11:08:39 +00:00
$this -> fields [ 'fk_prospectcontactlevel' ][ 'enabled' ] = 0 ;
2020-08-02 20:30:23 +00:00
}
2019-12-20 10:14:16 +00:00
// Unset fields that are disabled
2020-11-05 13:48:41 +00:00
foreach ( $this -> fields as $key => $val ) {
if ( isset ( $val [ 'enabled' ]) && empty ( $val [ 'enabled' ])) {
2019-12-20 10:14:16 +00:00
unset ( $this -> fields [ $key ]);
}
}
// Translate some data of arrayofkeyval
/* if ( is_object ( $langs ))
{
foreach ( $this -> fields as $key => $val )
{
2020-10-30 04:45:36 +00:00
if ( ! empty ( $val [ 'arrayofkeyval' ]) && is_array ( $val [ 'arrayofkeyval' ]))
2019-12-20 10:14:16 +00:00
{
foreach ( $val [ 'arrayofkeyval' ] as $key2 => $val2 )
{
$this -> fields [ $key ][ 'arrayofkeyval' ][ $key2 ] = $langs -> trans ( $val2 );
}
}
}
} */
2009-08-11 12:51:33 +00:00
}
2017-07-13 21:52:02 +00:00
2016-04-23 11:06:46 +00:00
/**
* Load indicators into this -> nb for board
*
2023-12-01 18:51:32 +00:00
* @ return int Return integer < 0 if KO , > 0 if OK
2016-04-23 11:06:46 +00:00
*/
2024-01-18 17:55:53 +00:00
public function loadStateBoard ()
2016-04-23 11:06:46 +00:00
{
2022-03-22 14:51:30 +00:00
global $user , $hookmanager ;
2017-07-13 21:52:02 +00:00
2019-12-03 10:17:29 +00:00
$this -> nb = array ();
2016-04-23 11:06:46 +00:00
$clause = " WHERE " ;
2017-07-13 21:52:02 +00:00
2016-04-23 11:06:46 +00:00
$sql = " SELECT count(sp.rowid) as nb " ;
2019-12-03 10:17:29 +00:00
$sql .= " FROM " . MAIN_DB_PREFIX . " socpeople as sp " ;
2024-01-09 12:08:22 +00:00
if ( ! $user -> hasRight ( 'societe' , 'client' , 'voir' )) {
2020-10-31 13:32:18 +00:00
$sql .= " , " . MAIN_DB_PREFIX . " societe as s " ;
$sql .= " , " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
2021-08-23 15:41:11 +00:00
$sql .= " WHERE sp.fk_soc = s.rowid AND s.rowid = sc.fk_soc AND sc.fk_user = " . (( int ) $user -> id );
2016-04-23 11:06:46 +00:00
$clause = " AND " ;
}
2021-08-27 22:55:51 +00:00
$sql .= " " . $clause . " sp.entity IN ( " . getEntity ( $this -> element ) . " ) " ;
$sql .= " AND (sp.priv='0' OR (sp.priv='1' AND sp.fk_user_creat = " . (( int ) $user -> id ) . " )) " ;
2021-01-16 13:24:47 +00:00
if ( $user -> socid > 0 ) {
2021-08-23 15:41:11 +00:00
$sql .= " AND sp.fk_soc = " . (( int ) $user -> socid );
2021-01-16 13:24:47 +00:00
}
2022-03-22 14:51:30 +00:00
// Add where from hooks
if ( is_object ( $hookmanager )) {
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printFieldListWhere' , $parameters , $this ); // Note that $action and $object may have been modified by hook
$sql .= $hookmanager -> resPrint ;
}
2017-07-13 21:52:02 +00:00
2019-12-03 10:17:29 +00:00
$resql = $this -> db -> query ( $sql );
2021-01-16 13:24:47 +00:00
if ( $resql ) {
while ( $obj = $this -> db -> fetch_object ( $resql )) {
2019-12-03 10:17:29 +00:00
$this -> nb [ " contacts " ] = $obj -> nb ;
2016-04-23 11:06:46 +00:00
}
$this -> db -> free ( $resql );
return 1 ;
2020-05-21 13:05:19 +00:00
} else {
2016-04-23 11:06:46 +00:00
dol_print_error ( $this -> db );
2019-11-08 14:51:54 +00:00
$this -> error = $this -> db -> lasterror ();
2016-04-23 11:06:46 +00:00
return - 1 ;
}
}
2009-08-11 12:51:33 +00:00
/**
2011-09-11 18:35:38 +00:00
* Add a contact into database
*
2023-06-29 10:32:49 +00:00
* @ param User $user Object user that create
2023-07-01 15:26:07 +00:00
* @ param int $notrigger 1 = Does not execute triggers , 0 = execute triggers
2023-12-01 18:51:32 +00:00
* @ return int Return integer < 0 if KO , > 0 if OK
2009-08-11 12:51:33 +00:00
*/
2023-06-30 07:29:49 +00:00
public function create ( $user , $notrigger = 0 )
2009-08-11 12:51:33 +00:00
{
2023-07-01 15:26:07 +00:00
global $conf ;
2019-04-11 16:04:18 +00:00
2019-11-08 14:51:54 +00:00
$error = 0 ;
$now = dol_now ();
2010-06-06 14:30:28 +00:00
2024-12-15 09:49:55 +00:00
if ( empty ( $this -> date_creation )) {
$this -> date_creation = $now ;
}
2010-11-19 21:24:48 +00:00
$this -> db -> begin ();
2008-04-09 23:07:13 +00:00
// Clean parameters
2024-02-18 22:43:00 +00:00
$this -> name_alias = trim ( $this -> name_alias );
2023-12-04 11:01:45 +00:00
$this -> lastname = $this -> lastname ? trim ( $this -> lastname ) : trim ( $this -> name );
2020-10-31 13:32:18 +00:00
$this -> firstname = trim ( $this -> firstname );
2020-10-28 19:50:33 +00:00
$this -> setUpperOrLowerCase ();
2021-02-11 20:26:21 +00:00
if ( empty ( $this -> socid )) {
$this -> socid = 0 ;
}
if ( empty ( $this -> priv )) {
$this -> priv = 0 ;
}
2025-08-15 15:31:44 +00:00
if ( ! empty ( $this -> statut ) && empty ( $this -> status )) {
$this -> status = 1 ;
}
if ( empty ( $this -> status )) {
$this -> status = 0 ; // This is to convert '' into '0' to avoid bad sql request
2021-02-11 20:26:21 +00:00
$this -> statut = 0 ; // This is to convert '' into '0' to avoid bad sql request
}
2006-02-24 23:16:35 +00:00
2024-11-21 18:11:32 +00:00
// setEntity will set entity with the right value if empty or change it for the right value if multicompany module is active
$this -> entity = setEntity ( $this );
2018-01-11 19:39:23 +00:00
2011-04-17 18:14:29 +00:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " socpeople ( " ;
2019-11-08 14:51:54 +00:00
$sql .= " datec " ;
$sql .= " , fk_soc " ;
2024-02-18 22:43:00 +00:00
$sql .= " , name_alias " ;
2020-10-31 13:32:18 +00:00
$sql .= " , lastname " ;
$sql .= " , firstname " ;
$sql .= " , fk_user_creat " ;
2019-11-08 14:51:54 +00:00
$sql .= " , priv " ;
2020-10-31 13:32:18 +00:00
$sql .= " , fk_stcommcontact " ;
2019-11-08 14:51:54 +00:00
$sql .= " , statut " ;
$sql .= " , canvas " ;
$sql .= " , entity " ;
$sql .= " , ref_ext " ;
$sql .= " , import_key " ;
2024-09-26 20:17:19 +00:00
$sql .= " , ip " ;
2019-11-08 14:51:54 +00:00
$sql .= " ) VALUES ( " ;
$sql .= " ' " . $this -> db -> idate ( $now ) . " ', " ;
2021-01-16 13:24:47 +00:00
if ( $this -> socid > 0 ) {
2021-06-14 11:51:09 +00:00
$sql .= " " . (( int ) $this -> socid ) . " , " ;
2021-01-16 13:24:47 +00:00
} else {
$sql .= " null, " ;
}
2024-02-18 22:43:00 +00:00
$sql .= " ' " . $this -> db -> escape ( $this -> name_alias ) . " ', " ;
2019-11-08 14:51:54 +00:00
$sql .= " ' " . $this -> db -> escape ( $this -> lastname ) . " ', " ;
2020-10-31 17:51:30 +00:00
$sql .= " ' " . $this -> db -> escape ( $this -> firstname ) . " ', " ;
2021-06-14 12:15:32 +00:00
$sql .= " " . ( $user -> id > 0 ? (( int ) $user -> id ) : " null " ) . " , " ;
2021-06-14 11:51:09 +00:00
$sql .= " " . (( int ) $this -> priv ) . " , " ;
2020-10-31 13:32:18 +00:00
$sql .= " 0, " ;
2025-08-15 15:31:44 +00:00
$sql .= " " . (( int ) $this -> status ) . " , " ;
2020-10-31 17:51:30 +00:00
$sql .= " " . ( ! empty ( $this -> canvas ) ? " ' " . $this -> db -> escape ( $this -> canvas ) . " ' " : " null " ) . " , " ;
2021-06-14 11:51:09 +00:00
$sql .= " " . (( int ) $this -> entity ) . " , " ;
2020-10-31 17:51:30 +00:00
$sql .= " ' " . $this -> db -> escape ( $this -> ref_ext ) . " ', " ;
2024-09-26 20:17:19 +00:00
$sql .= " " . ( ! empty ( $this -> import_key ) ? " ' " . $this -> db -> escape ( $this -> import_key ) . " ' " : " null " ) . " , " ;
$sql .= " " . ( ! empty ( $this -> ip ) ? " ' " . $this -> db -> escape ( $this -> ip ) . " ' " : " null " );
2019-11-08 14:51:54 +00:00
$sql .= " ) " ;
2009-08-11 12:51:33 +00:00
2014-06-12 09:31:53 +00:00
dol_syslog ( get_class ( $this ) . " ::create " , LOG_DEBUG );
2019-11-08 14:51:54 +00:00
$resql = $this -> db -> query ( $sql );
2021-02-23 20:16:15 +00:00
if ( $resql ) {
2009-08-11 12:51:33 +00:00
$this -> id = $this -> db -> last_insert_id ( MAIN_DB_PREFIX . " socpeople " );
2025-09-11 10:14:53 +00:00
$result = $this -> update ( $this -> id , $user , 1 , 'add' ); // This include updateRoles(), ...
if ( $result < 0 ) {
$error ++ ;
$this -> error = $this -> db -> lasterror ();
2020-10-31 13:32:18 +00:00
}
2021-02-23 20:16:15 +00:00
if ( ! $error ) {
2020-10-31 13:32:18 +00:00
$result = $this -> update_perso ( $this -> id , $user , 1 ); // TODO Remove function update_perso, should be same than update
2021-02-23 20:16:15 +00:00
if ( $result < 0 ) {
2020-10-31 13:32:18 +00:00
$error ++ ;
$this -> error = $this -> db -> lasterror ();
}
}
2023-06-30 07:29:49 +00:00
if ( ! $error && ! $notrigger ) {
2020-10-31 13:32:18 +00:00
// Call trigger
$result = $this -> call_trigger ( 'CONTACT_CREATE' , $user );
2021-02-23 20:16:15 +00:00
if ( $result < 0 ) {
$error ++ ;
}
2020-10-31 13:32:18 +00:00
// End call triggers
2009-08-11 12:51:33 +00:00
}
2021-02-23 20:16:15 +00:00
if ( ! $error ) {
2020-10-31 13:32:18 +00:00
$this -> db -> commit ();
return $this -> id ;
} else {
$this -> db -> rollback ();
dol_syslog ( get_class ( $this ) . " ::create " . $this -> error , LOG_ERR );
return - 2 ;
}
2020-05-21 13:05:19 +00:00
} else {
2019-11-08 14:51:54 +00:00
$this -> error = $this -> db -> lasterror ();
2010-11-19 21:24:48 +00:00
$this -> db -> rollback ();
2011-12-30 13:18:19 +00:00
dol_syslog ( get_class ( $this ) . " ::create " . $this -> error , LOG_ERR );
2009-08-11 12:51:33 +00:00
return - 1 ;
}
}
2010-02-21 13:08:02 +00:00
/**
2024-01-14 11:26:37 +00:00
* Update information into database
2011-09-16 17:57:09 +00:00
*
* @ param int $id Id of contact / address to update
2024-01-14 11:26:37 +00:00
* @ param User $user Object user making change
2012-11-10 15:08:26 +00:00
* @ param int $notrigger 0 = no , 1 = yes
* @ param string $action Current action for hookmanager
2017-12-19 15:16:31 +00:00
* @ param int $nosyncuser No sync linked user ( external users and contacts are linked )
2023-12-01 18:51:32 +00:00
* @ return int Return integer < 0 if KO , > 0 if OK
2009-08-11 12:51:33 +00:00
*/
2019-02-24 23:56:48 +00:00
public function update ( $id , $user = null , $notrigger = 0 , $action = 'update' , $nosyncuser = 0 )
2009-08-11 12:51:33 +00:00
{
2023-12-21 14:03:26 +00:00
global $conf ;
2009-08-11 12:51:33 +00:00
2025-01-10 15:56:14 +00:00
if ( empty ( $this -> country_id ) && ! empty ( $this -> country_code )) {
$country_id = getCountry ( $this -> country_code , '3' );
$this -> country_id = is_int ( $country_id ) ? $country_id : 0 ;
}
2019-11-08 14:51:54 +00:00
$error = 0 ;
2009-08-11 20:16:58 +00:00
2009-08-11 12:51:33 +00:00
$this -> id = $id ;
2019-11-08 14:51:54 +00:00
$this -> entity = (( isset ( $this -> entity ) && is_numeric ( $this -> entity )) ? $this -> entity : $conf -> entity );
2018-07-08 10:11:22 +00:00
2011-12-30 13:18:19 +00:00
// Clean parameters
2024-02-13 10:26:40 +00:00
$this -> ref_ext = ( empty ( $this -> ref_ext ) ? '' : trim ( $this -> ref_ext ));
2024-02-18 22:43:00 +00:00
$this -> name_alias = trim ( $this -> name_alias );
2023-12-04 11:01:45 +00:00
$this -> lastname = trim ( $this -> lastname ) ? trim ( $this -> lastname ) : trim ( $this -> lastname );
2019-11-08 14:51:54 +00:00
$this -> firstname = trim ( $this -> firstname );
2025-03-01 15:35:22 +00:00
$this -> email = trim ( $this -> email ? ? '' );
2019-11-08 14:51:54 +00:00
$this -> phone_pro = trim ( $this -> phone_pro );
$this -> phone_perso = trim ( $this -> phone_perso );
$this -> phone_mobile = trim ( $this -> phone_mobile );
$this -> photo = trim ( $this -> photo );
$this -> fax = trim ( $this -> fax );
2020-10-28 19:50:33 +00:00
$this -> zip = ( empty ( $this -> zip ) ? '' : trim ( $this -> zip ));
$this -> town = ( empty ( $this -> town ) ? '' : trim ( $this -> town ));
2024-03-15 07:40:35 +00:00
$this -> country_id = ( empty ( $this -> country_id ) || $this -> country_id < 0 ) ? 0 : $this -> country_id ;
2025-08-15 15:31:44 +00:00
if ( ! empty ( $this -> statut ) && empty ( $this -> status )) {
$this -> status = 1 ;
}
if ( empty ( $this -> status )) {
$this -> status = 0 ;
2021-02-23 20:16:15 +00:00
$this -> statut = 0 ;
}
if ( empty ( $this -> civility_code ) && ! is_numeric ( $this -> civility_id )) {
$this -> civility_code = $this -> civility_id ; // For backward compatibility
}
2022-07-28 13:13:13 +00:00
$this -> setUpperOrLowerCase ();
2023-12-21 14:03:26 +00:00
2009-08-11 20:16:58 +00:00
$this -> db -> begin ();
2021-06-19 12:22:41 +00:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " socpeople SET " ;
2021-02-23 20:16:15 +00:00
if ( $this -> socid > 0 ) {
2021-06-19 12:22:41 +00:00
$sql .= " fk_soc = " . (( int ) $this -> socid ) . " , " ;
2021-02-23 20:16:15 +00:00
} elseif ( $this -> socid == - 1 ) {
2021-06-19 12:22:41 +00:00
$sql .= " fk_soc = NULL, " ;
2021-02-23 20:16:15 +00:00
}
2021-06-19 12:22:41 +00:00
$sql .= " civility=' " . $this -> db -> escape ( $this -> civility_code ) . " ' " ;
2024-02-18 22:43:00 +00:00
$sql .= " , name_alias=' " . $this -> db -> escape ( $this -> name_alias ) . " ' " ;
2013-02-23 14:58:26 +00:00
$sql .= " , lastname=' " . $this -> db -> escape ( $this -> lastname ) . " ' " ;
2011-02-24 18:11:12 +00:00
$sql .= " , firstname=' " . $this -> db -> escape ( $this -> firstname ) . " ' " ;
2025-03-19 14:21:48 +00:00
$sql .= " , address=' " . $this -> db -> escape (( string ) $this -> address ) . " ' " ;
2013-02-24 16:08:52 +00:00
$sql .= " , zip=' " . $this -> db -> escape ( $this -> zip ) . " ' " ;
2013-02-22 15:53:50 +00:00
$sql .= " , town=' " . $this -> db -> escape ( $this -> town ) . " ' " ;
2021-06-19 12:22:41 +00:00
$sql .= " , ref_ext = " . ( ! empty ( $this -> ref_ext ) ? " ' " . $this -> db -> escape ( $this -> ref_ext ) . " ' " : " NULL " );
2026-07-23 17:06:39 +00:00
$sql .= " , fk_pays= " . ( $this -> country_id > 0 ? (( int ) $this -> country_id ) : 'NULL' );
$sql .= " , fk_departement= " . ( $this -> state_id > 0 ? (( int ) $this -> state_id ) : 'NULL' );
2011-02-24 18:11:12 +00:00
$sql .= " , poste=' " . $this -> db -> escape ( $this -> poste ) . " ' " ;
$sql .= " , fax=' " . $this -> db -> escape ( $this -> fax ) . " ' " ;
$sql .= " , email=' " . $this -> db -> escape ( $this -> email ) . " ' " ;
2020-10-31 13:32:18 +00:00
$sql .= " , socialnetworks = ' " . $this -> db -> escape ( json_encode ( $this -> socialnetworks )) . " ' " ;
2015-10-04 15:25:46 +00:00
$sql .= " , photo=' " . $this -> db -> escape ( $this -> photo ) . " ' " ;
2018-04-11 12:43:16 +00:00
$sql .= " , birthday= " . ( $this -> birthday ? " ' " . $this -> db -> idate ( $this -> birthday ) . " ' " : " null " );
2021-06-19 12:22:41 +00:00
$sql .= " , note_private = " . ( isset ( $this -> note_private ) ? " ' " . $this -> db -> escape ( $this -> note_private ) . " ' " : " NULL " );
$sql .= " , note_public = " . ( isset ( $this -> note_public ) ? " ' " . $this -> db -> escape ( $this -> note_public ) . " ' " : " NULL " );
$sql .= " , phone = " . ( isset ( $this -> phone_pro ) ? " ' " . $this -> db -> escape ( $this -> phone_pro ) . " ' " : " NULL " );
$sql .= " , phone_perso = " . ( isset ( $this -> phone_perso ) ? " ' " . $this -> db -> escape ( $this -> phone_perso ) . " ' " : " NULL " );
$sql .= " , phone_mobile = " . ( isset ( $this -> phone_mobile ) ? " ' " . $this -> db -> escape ( $this -> phone_mobile ) . " ' " : " NULL " );
2025-01-13 15:35:47 +00:00
$sql .= " , priv = " . (( int ) $this -> priv );
2022-11-04 16:32:48 +00:00
$sql .= " , fk_prospectlevel = ' " . $this -> db -> escape ( $this -> fk_prospectlevel ) . " ' " ;
2021-02-23 20:16:15 +00:00
if ( isset ( $this -> stcomm_id )) {
2026-07-23 17:06:39 +00:00
$sql .= " , fk_stcommcontact = " . ( $this -> stcomm_id > 0 || $this -> stcomm_id == - 1 ? (( int ) $this -> stcomm_id ) : " 0 " );
2020-04-27 15:35:14 +00:00
}
2025-08-15 15:31:44 +00:00
$sql .= " , statut = " . (( int ) $this -> status );
2025-03-19 14:21:48 +00:00
$sql .= " , fk_user_modif= " . ( $user -> id > 0 ? " ' " . $this -> db -> escape (( string ) $user -> id ) . " ' " : " NULL " );
2019-12-03 10:17:29 +00:00
$sql .= " , default_lang= " . ( $this -> default_lang ? " ' " . $this -> db -> escape ( $this -> default_lang ) . " ' " : " NULL " );
2021-06-09 13:36:47 +00:00
$sql .= " , entity = " . (( int ) $this -> entity );
2021-08-27 16:18:50 +00:00
$sql .= " WHERE rowid = " . (( int ) $id );
2009-08-11 12:51:33 +00:00
2014-06-12 09:31:53 +00:00
dol_syslog ( get_class ( $this ) . " ::update " , LOG_DEBUG );
2009-08-11 12:51:33 +00:00
$result = $this -> db -> query ( $sql );
2021-02-23 20:16:15 +00:00
if ( $result ) {
2020-10-31 13:32:18 +00:00
unset ( $this -> country_code );
unset ( $this -> country );
unset ( $this -> state_code );
unset ( $this -> state );
$action = 'update' ;
// Actions on extra fields
2025-09-11 10:14:53 +00:00
$result = $this -> insertExtraFields ();
if ( $result < 0 ) {
$error ++ ;
2020-10-31 13:32:18 +00:00
}
2012-09-16 23:39:30 +00:00
2019-11-08 14:51:54 +00:00
if ( ! $error ) {
$result = $this -> updateRoles ();
2021-02-23 20:16:15 +00:00
if ( $result < 0 ) {
2019-09-02 20:01:48 +00:00
$error ++ ;
}
}
2021-02-23 20:16:15 +00:00
if ( ! $error && $this -> user_id > 0 ) {
2019-10-22 13:21:41 +00:00
// If contact is linked to a user
2017-12-19 15:16:31 +00:00
$tmpobj = new User ( $this -> db );
$tmpobj -> fetch ( $this -> user_id );
$usermustbemodified = 0 ;
2021-02-11 20:26:21 +00:00
if ( $tmpobj -> office_phone != $this -> phone_pro ) {
2017-12-19 15:16:31 +00:00
$tmpobj -> office_phone = $this -> phone_pro ;
$usermustbemodified ++ ;
}
2021-02-11 20:26:21 +00:00
if ( $tmpobj -> office_fax != $this -> fax ) {
2017-12-19 15:16:31 +00:00
$tmpobj -> office_fax = $this -> fax ;
$usermustbemodified ++ ;
}
2021-02-11 20:26:21 +00:00
if ( $tmpobj -> address != $this -> address ) {
2017-12-19 15:16:31 +00:00
$tmpobj -> address = $this -> address ;
$usermustbemodified ++ ;
}
2021-02-11 20:26:21 +00:00
if ( $tmpobj -> town != $this -> town ) {
2017-12-19 15:16:31 +00:00
$tmpobj -> town = $this -> town ;
$usermustbemodified ++ ;
}
2021-02-11 20:26:21 +00:00
if ( $tmpobj -> zip != $this -> zip ) {
2017-12-19 15:16:31 +00:00
$tmpobj -> zip = $this -> zip ;
$usermustbemodified ++ ;
}
2021-02-11 20:26:21 +00:00
if ( $tmpobj -> zip != $this -> zip ) {
2019-11-08 14:51:54 +00:00
$tmpobj -> state_id = $this -> state_id ;
2017-12-19 15:16:31 +00:00
$usermustbemodified ++ ;
}
2021-02-11 20:26:21 +00:00
if ( $tmpobj -> country_id != $this -> country_id ) {
2017-12-19 15:16:31 +00:00
$tmpobj -> country_id = $this -> country_id ;
$usermustbemodified ++ ;
}
2021-02-11 20:26:21 +00:00
if ( $tmpobj -> email != $this -> email ) {
2017-12-19 15:16:31 +00:00
$tmpobj -> email = $this -> email ;
$usermustbemodified ++ ;
}
2021-02-11 20:26:21 +00:00
if ( ! empty ( array_diff ( $tmpobj -> socialnetworks , $this -> socialnetworks ))) {
2019-09-14 09:26:31 +00:00
$tmpobj -> socialnetworks = $this -> socialnetworks ;
2018-09-26 14:55:46 +00:00
$usermustbemodified ++ ;
}
2021-02-11 20:26:21 +00:00
if ( $usermustbemodified ) {
2019-09-14 09:26:31 +00:00
$result = $tmpobj -> update ( $user , 0 , 1 , 1 , 1 );
2021-02-23 20:16:15 +00:00
if ( $result < 0 ) {
$error ++ ;
}
2017-12-19 15:16:31 +00:00
}
}
2021-02-11 20:26:21 +00:00
if ( ! $error && ! $notrigger ) {
2017-12-19 15:16:31 +00:00
// Call trigger
2019-12-03 10:17:29 +00:00
$result = $this -> call_trigger ( 'CONTACT_MODIFY' , $user );
2021-02-23 20:16:15 +00:00
if ( $result < 0 ) {
$error ++ ;
}
2017-12-19 15:16:31 +00:00
// End call triggers
2009-08-11 20:16:58 +00:00
}
2021-02-11 20:26:21 +00:00
if ( ! $error ) {
2009-08-11 20:16:58 +00:00
$this -> db -> commit ();
return 1 ;
2020-05-21 13:05:19 +00:00
} else {
2019-01-27 10:55:16 +00:00
dol_syslog ( get_class ( $this ) . " ::update Error " . $this -> error , LOG_ERR );
2009-08-11 20:16:58 +00:00
$this -> db -> rollback ();
return - $error ;
}
2020-05-21 13:05:19 +00:00
} else {
2019-11-08 14:51:54 +00:00
$this -> error = $this -> db -> lasterror () . ' sql=' . $sql ;
2020-10-31 13:32:18 +00:00
$this -> db -> rollback ();
2009-08-11 12:51:33 +00:00
return - 1 ;
}
}
2009-01-19 22:41:26 +00:00
2020-10-31 13:32:18 +00:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2009-08-11 12:51:33 +00:00
/**
2023-10-07 05:02:22 +00:00
* Return DN string complete in the LDAP directory for the object
2011-09-16 17:57:09 +00:00
*
2024-10-25 19:00:02 +00:00
* @ param array < string , mixed > $info Info array loaded by _load_ldap_info
* @ param int < 0 , 2 > $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
2009-08-11 12:51:33 +00:00
*/
2019-07-13 09:21:07 +00:00
public function _load_ldap_dn ( $info , $mode = 0 )
2006-11-19 01:46:32 +00:00
{
2020-10-31 13:32:18 +00:00
// phpcs:enable
2006-11-21 22:51:05 +00:00
global $conf ;
2019-11-08 14:51:54 +00:00
$dn = '' ;
2021-02-11 20:26:21 +00:00
if ( $mode == 0 ) {
2023-10-15 13:32:35 +00:00
$dn = getDolGlobalString ( 'LDAP_KEY_CONTACTS' ) . " = " . $info [ getDolGlobalString ( 'LDAP_KEY_CONTACTS' )] . " , " . getDolGlobalString ( 'LDAP_CONTACT_DN' );
2021-02-11 20:26:21 +00:00
} elseif ( $mode == 1 ) {
2024-01-05 03:18:53 +00:00
$dn = getDolGlobalString ( 'LDAP_CONTACT_DN' );
2021-02-11 20:26:21 +00:00
} elseif ( $mode == 2 ) {
2023-10-15 13:32:35 +00:00
$dn = getDolGlobalString ( 'LDAP_KEY_CONTACTS' ) . " = " . $info [ getDolGlobalString ( 'LDAP_KEY_CONTACTS' )];
2021-02-11 20:26:21 +00:00
}
2006-11-21 22:51:05 +00:00
return $dn ;
}
2006-11-19 01:46:32 +00:00
2006-11-20 01:13:13 +00:00
2020-10-31 13:32:18 +00:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2009-08-11 12:51:33 +00:00
/**
2023-10-07 05:02:22 +00:00
* Initialize info table ( LDAP attributes table )
2011-09-16 17:57:09 +00:00
*
2024-10-25 19:00:02 +00:00
* @ return array < string , mixed > Attributes info table
2009-08-11 12:51:33 +00:00
*/
2019-06-18 18:01:28 +00:00
public function _load_ldap_info ()
2006-11-20 01:13:13 +00:00
{
2020-10-31 13:32:18 +00:00
// phpcs:enable
2018-09-16 17:19:45 +00:00
global $conf , $langs ;
2006-11-20 01:13:13 +00:00
2020-10-31 13:32:18 +00:00
$info = array ();
2017-07-13 21:52:02 +00:00
2020-10-31 13:32:18 +00:00
// Object classes
2023-12-13 14:20:53 +00:00
$info [ " objectclass " ] = explode ( ',' , getDolGlobalString ( 'LDAP_CONTACT_OBJECT_CLASS' ));
2009-01-19 22:41:26 +00:00
2019-11-08 14:51:54 +00:00
$this -> fullname = $this -> getFullName ( $langs );
2010-07-18 10:39:07 +00:00
// Fields
2023-11-27 10:39:32 +00:00
if ( $this -> fullname && getDolGlobalString ( 'LDAP_CONTACT_FIELD_FULLNAME' )) {
2023-10-15 13:32:35 +00:00
$info [ getDolGlobalString ( 'LDAP_CONTACT_FIELD_FULLNAME' )] = $this -> fullname ;
2021-02-23 20:16:15 +00:00
}
2023-11-27 10:39:32 +00:00
if ( $this -> lastname && getDolGlobalString ( 'LDAP_CONTACT_FIELD_NAME' )) {
2023-10-15 13:32:35 +00:00
$info [ getDolGlobalString ( 'LDAP_CONTACT_FIELD_NAME' )] = $this -> lastname ;
2021-02-23 20:16:15 +00:00
}
2023-11-27 10:39:32 +00:00
if ( $this -> firstname && getDolGlobalString ( 'LDAP_CONTACT_FIELD_FIRSTNAME' )) {
2023-10-15 13:32:35 +00:00
$info [ getDolGlobalString ( 'LDAP_CONTACT_FIELD_FIRSTNAME' )] = $this -> firstname ;
2021-02-23 20:16:15 +00:00
}
2006-11-21 22:51:05 +00:00
2021-02-23 20:16:15 +00:00
if ( $this -> poste ) {
$info [ " title " ] = $this -> poste ;
}
2021-01-16 13:24:47 +00:00
if ( $this -> socid > 0 ) {
2006-11-20 01:13:13 +00:00
$soc = new Societe ( $this -> db );
$soc -> fetch ( $this -> socid );
2023-10-15 13:32:35 +00:00
$info [ getDolGlobalString ( 'LDAP_CONTACT_FIELD_COMPANY' )] = $soc -> name ;
2021-02-23 20:16:15 +00:00
if ( $soc -> client == 1 ) {
$info [ " businessCategory " ] = " Customers " ;
}
if ( $soc -> client == 2 ) {
$info [ " businessCategory " ] = " Prospects " ;
}
if ( $soc -> fournisseur == 1 ) {
$info [ " businessCategory " ] = " Suppliers " ;
}
}
2023-11-27 10:39:32 +00:00
if ( $this -> address && getDolGlobalString ( 'LDAP_CONTACT_FIELD_ADDRESS' )) {
2023-10-15 13:32:35 +00:00
$info [ getDolGlobalString ( 'LDAP_CONTACT_FIELD_ADDRESS' )] = $this -> address ;
2021-02-23 20:16:15 +00:00
}
2023-11-27 10:39:32 +00:00
if ( $this -> zip && getDolGlobalString ( 'LDAP_CONTACT_FIELD_ZIP' )) {
2023-10-15 13:32:35 +00:00
$info [ getDolGlobalString ( 'LDAP_CONTACT_FIELD_ZIP' )] = $this -> zip ;
2021-02-23 20:16:15 +00:00
}
2023-11-27 10:39:32 +00:00
if ( $this -> town && getDolGlobalString ( 'LDAP_CONTACT_FIELD_TOWN' )) {
2023-10-15 13:32:35 +00:00
$info [ getDolGlobalString ( 'LDAP_CONTACT_FIELD_TOWN' )] = $this -> town ;
2021-02-23 20:16:15 +00:00
}
2023-11-27 10:39:32 +00:00
if ( $this -> country_code && getDolGlobalString ( 'LDAP_CONTACT_FIELD_COUNTRY' )) {
2023-10-15 13:32:35 +00:00
$info [ getDolGlobalString ( 'LDAP_CONTACT_FIELD_COUNTRY' )] = $this -> country_code ;
2021-02-23 20:16:15 +00:00
}
2023-11-27 10:39:32 +00:00
if ( $this -> phone_pro && getDolGlobalString ( 'LDAP_CONTACT_FIELD_PHONE' )) {
2023-10-15 13:32:35 +00:00
$info [ getDolGlobalString ( 'LDAP_CONTACT_FIELD_PHONE' )] = $this -> phone_pro ;
2021-02-23 20:16:15 +00:00
}
2023-11-27 10:39:32 +00:00
if ( $this -> phone_perso && getDolGlobalString ( 'LDAP_CONTACT_FIELD_HOMEPHONE' )) {
2023-10-15 13:32:35 +00:00
$info [ getDolGlobalString ( 'LDAP_CONTACT_FIELD_HOMEPHONE' )] = $this -> phone_perso ;
2021-02-23 20:16:15 +00:00
}
2023-11-27 10:39:32 +00:00
if ( $this -> phone_mobile && getDolGlobalString ( 'LDAP_CONTACT_FIELD_MOBILE' )) {
2023-10-15 13:32:35 +00:00
$info [ getDolGlobalString ( 'LDAP_CONTACT_FIELD_MOBILE' )] = $this -> phone_mobile ;
2021-02-23 20:16:15 +00:00
}
2023-11-27 10:39:32 +00:00
if ( $this -> fax && getDolGlobalString ( 'LDAP_CONTACT_FIELD_FAX' )) {
2023-10-15 13:32:35 +00:00
$info [ getDolGlobalString ( 'LDAP_CONTACT_FIELD_FAX' )] = $this -> fax ;
2021-02-23 20:16:15 +00:00
}
2023-11-27 10:39:32 +00:00
if ( $this -> note_private && getDolGlobalString ( 'LDAP_CONTACT_FIELD_DESCRIPTION' )) {
2023-10-15 13:32:35 +00:00
$info [ getDolGlobalString ( 'LDAP_CONTACT_FIELD_DESCRIPTION' )] = dol_string_nohtmltag ( $this -> note_private , 2 );
2021-02-23 20:16:15 +00:00
}
2023-11-27 10:39:32 +00:00
if ( $this -> email && getDolGlobalString ( 'LDAP_CONTACT_FIELD_MAIL' )) {
2023-10-15 13:32:35 +00:00
$info [ getDolGlobalString ( 'LDAP_CONTACT_FIELD_MAIL' )] = $this -> email ;
2021-02-23 20:16:15 +00:00
}
2023-10-08 21:19:49 +00:00
if ( getDolGlobalString ( 'LDAP_SERVER_TYPE' ) == 'egroupware' ) {
2006-11-20 01:13:13 +00:00
$info [ " objectclass " ][ 4 ] = " phpgwContact " ; // compatibilite egroupware
$info [ 'uidnumber' ] = $this -> id ;
2019-11-08 14:51:54 +00:00
$info [ 'phpgwTz' ] = 0 ;
2006-11-20 01:13:13 +00:00
$info [ 'phpgwMailType' ] = 'INTERNET' ;
$info [ 'phpgwMailHomeType' ] = 'INTERNET' ;
$info [ " phpgwContactTypeId " ] = 'n' ;
$info [ " phpgwContactCatId " ] = 0 ;
$info [ " phpgwContactAccess " ] = " public " ;
2024-04-22 12:50:25 +00:00
$info [ " phpgwContactOwner " ] = 1 ;
2006-11-20 01:13:13 +00:00
2021-02-23 20:16:15 +00:00
if ( $this -> email ) {
$info [ " rfc822Mailbox " ] = $this -> email ;
}
if ( $this -> phone_mobile ) {
$info [ " phpgwCellTelephoneNumber " ] = $this -> phone_mobile ;
}
2006-11-20 01:13:13 +00:00
}
2009-01-19 22:41:26 +00:00
2006-11-20 01:13:13 +00:00
return $info ;
}
2009-01-19 22:41:26 +00:00
2020-10-31 13:32:18 +00:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2010-11-19 21:24:48 +00:00
/**
2011-09-16 17:57:09 +00:00
* Update field alert birthday
*
* @ param int $id Id of contact
2025-03-19 14:21:48 +00:00
* @ param ? User $user User asking to change alert or birthday
* @ param int < 0 , 1 > $notrigger 0 = no , 1 = yes
2023-12-06 14:46:39 +00:00
* @ return int Return integer < 0 if KO , >= 0 if OK
2009-08-11 12:51:33 +00:00
*/
2019-02-24 23:56:48 +00:00
public function update_perso ( $id , $user = null , $notrigger = 0 )
2006-11-18 21:59:10 +00:00
{
2020-10-31 13:32:18 +00:00
// phpcs:enable
$error = 0 ;
$result = false ;
2010-11-19 21:24:48 +00:00
2020-10-31 13:32:18 +00:00
$this -> db -> begin ();
2017-07-13 21:52:02 +00:00
2024-01-14 11:26:37 +00:00
// Update the contact
2012-02-11 07:03:26 +00:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " socpeople SET " ;
2021-08-27 16:18:50 +00:00
$sql .= " birthday = " . ( $this -> birthday ? " ' " . $this -> db -> idate ( $this -> birthday ) . " ' " : " null " );
2019-11-08 14:51:54 +00:00
$sql .= " , photo = " . ( $this -> photo ? " ' " . $this -> db -> escape ( $this -> photo ) . " ' " : " null " );
2021-02-23 20:16:15 +00:00
if ( $user ) {
2021-08-27 16:18:50 +00:00
$sql .= " , fk_user_modif = " . (( int ) $user -> id );
2021-02-23 20:16:15 +00:00
}
2021-08-27 16:18:50 +00:00
$sql .= " WHERE rowid = " . (( int ) $id );
2012-02-11 07:03:26 +00:00
2014-06-12 09:31:53 +00:00
dol_syslog ( get_class ( $this ) . " ::update_perso this->birthday= " . $this -> birthday . " - " , LOG_DEBUG );
2007-01-16 22:02:36 +00:00
$resql = $this -> db -> query ( $sql );
2021-02-23 20:16:15 +00:00
if ( ! $resql ) {
2018-04-11 12:38:56 +00:00
$error ++ ;
2019-11-08 14:51:54 +00:00
$this -> error = $this -> db -> lasterror ();
2006-11-21 22:51:05 +00:00
}
2009-01-19 22:41:26 +00:00
2021-06-28 09:03:22 +00:00
if ( $user ) {
2021-06-29 13:52:39 +00:00
// Update birthday alert
if ( ! empty ( $this -> birthday_alert )) {
2021-06-28 09:03:22 +00:00
//check existing
2021-06-29 13:52:39 +00:00
$sql_check = " SELECT rowid FROM " . MAIN_DB_PREFIX . " user_alert WHERE type = 1 AND fk_contact = " . (( int ) $id ) . " AND fk_user = " . (( int ) $user -> id );
2021-06-28 09:03:22 +00:00
$result_check = $this -> db -> query ( $sql_check );
if ( ! $result_check || ( $this -> db -> num_rows ( $result_check ) < 1 )) {
//insert
2021-06-29 13:52:39 +00:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " user_alert(type, fk_contact, fk_user) " ;
$sql .= " VALUES (1, " . (( int ) $id ) . " , " . (( int ) $user -> id ) . " ) " ;
2021-06-28 09:03:22 +00:00
$result = $this -> db -> query ( $sql );
if ( ! $result ) {
$error ++ ;
$this -> error = $this -> db -> lasterror ();
}
} else {
$result = true ;
}
} else {
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " user_alert " ;
2021-06-29 13:52:39 +00:00
$sql .= " WHERE type=1 AND fk_contact= " . (( int ) $id ) . " AND fk_user= " . (( int ) $user -> id );
2007-01-14 14:50:35 +00:00
$result = $this -> db -> query ( $sql );
2020-12-04 11:01:41 +00:00
if ( ! $result ) {
2020-10-31 13:32:18 +00:00
$error ++ ;
$this -> error = $this -> db -> lasterror ();
2007-01-14 14:50:35 +00:00
}
}
2010-11-19 21:24:48 +00:00
2025-03-19 14:21:48 +00:00
if ( ! $error && ! $notrigger ) {
// Call trigger
$result = $this -> call_trigger ( 'CONTACT_MODIFY' , $user );
if ( $result < 0 ) {
$error ++ ;
}
// End call triggers
2021-02-23 20:16:15 +00:00
}
2016-08-02 14:55:32 +00:00
}
2017-07-13 21:52:02 +00:00
2020-12-04 11:01:41 +00:00
if ( ! $error ) {
2020-10-31 13:32:18 +00:00
$this -> db -> commit ();
return 1 ;
2020-05-21 13:05:19 +00:00
} else {
2020-10-31 13:32:18 +00:00
dol_syslog ( get_class ( $this ) . " ::update Error " . $this -> error , LOG_ERR );
$this -> db -> rollback ();
return - $error ;
2016-08-02 14:55:32 +00:00
}
2006-11-18 21:59:10 +00:00
}
2006-02-24 23:16:35 +00:00
2011-09-16 17:57:09 +00:00
/**
2020-02-19 12:22:24 +00:00
* Load object contact .
2011-09-16 17:57:09 +00:00
*
2020-02-19 12:22:24 +00:00
* @ param int $id Id of contact
2024-03-25 09:13:28 +00:00
* @ param ? User $user Load also alerts of this user ( subscribing to alerts ) that want alerts about this contact
2020-10-31 13:32:18 +00:00
* @ param string $ref_ext External reference , not given by Dolibarr
* @ param string $email Email
2024-09-12 10:32:33 +00:00
* @ param int $loadalsoroles Load also roles . Try to always use 0 here and load roles with a separate call of fetchRoles () .
* @ param int $socid Filter on thirdparty id
2020-02-19 12:22:24 +00:00
* @ return int > 0 if OK , < 0 if KO or if two records found for same ref or idprof , 0 if not found .
2009-08-11 12:51:33 +00:00
*/
2024-09-12 10:32:33 +00:00
public function fetch ( $id , $user = null , $ref_ext = '' , $email = '' , $loadalsoroles = 0 , $socid = 0 )
2009-08-11 12:51:33 +00:00
{
global $langs ;
2019-04-11 16:04:18 +00:00
2019-12-03 10:17:29 +00:00
dol_syslog ( get_class ( $this ) . " ::fetch id= " . $id . " ref_ext= " . $ref_ext . " email= " . $email , LOG_DEBUG );
2015-08-29 11:45:23 +00:00
2021-02-23 20:16:15 +00:00
if ( empty ( $id ) && empty ( $ref_ext ) && empty ( $email )) {
2019-12-03 10:17:29 +00:00
$this -> error = 'BadParameter' ;
2015-07-19 21:39:07 +00:00
return - 1 ;
}
2020-02-19 12:22:24 +00:00
$langs -> loadLangs ( array ( " dict " , " companies " ));
2011-05-02 18:21:57 +00:00
2024-02-18 22:43:00 +00:00
$sql = " SELECT c.rowid, c.entity, c.fk_soc, c.ref_ext, c.civility as civility_code, c.name_alias, c.lastname, c.firstname, " ;
2025-08-17 00:00:29 +00:00
$sql .= " c.address, c.statut as status, c.zip, c.town, " ;
2019-12-03 10:17:29 +00:00
$sql .= " c.fk_pays as country_id, " ;
$sql .= " c.fk_departement as state_id, " ;
$sql .= " c.birthday, " ;
$sql .= " c.poste, c.phone, c.phone_perso, c.phone_mobile, c.fax, c.email, " ;
$sql .= " c.socialnetworks, " ;
2020-10-31 13:32:18 +00:00
$sql .= " c.photo, " ;
2019-12-03 10:17:29 +00:00
$sql .= " c.priv, c.note_private, c.note_public, c.default_lang, c.canvas, " ;
2022-11-04 16:32:48 +00:00
$sql .= " c.fk_prospectlevel, c.fk_stcommcontact, st.libelle as stcomm, st.picto as stcomm_picto, " ;
2019-12-03 10:17:29 +00:00
$sql .= " c.import_key, " ;
2025-08-28 17:28:48 +00:00
$sql .= " c.datec as date_creation, GREATEST(c.tms, cef.tms) as date_modification, c.fk_user_creat, c.fk_user_modif, " ;
2019-12-03 10:17:29 +00:00
$sql .= " co.label as country, co.code as country_code, " ;
$sql .= " d.nom as state, d.code_departement as state_code, " ;
$sql .= " u.rowid as user_id, u.login as user_login, " ;
$sql .= " s.nom as socname, s.address as socaddress, s.zip as soccp, s.town as soccity, s.default_lang as socdefault_lang " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " socpeople as c " ;
2025-08-28 17:28:48 +00:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " socpeople_extrafields as cef ON cef.fk_object=c.rowid " ;
2019-12-03 10:17:29 +00:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " c_country as co ON c.fk_pays = co.rowid " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " c_departements as d ON c.fk_departement = d.rowid " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " user as u ON c.rowid = u.fk_socpeople " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " societe as s ON c.fk_soc = s.rowid " ;
2020-10-31 13:32:18 +00:00
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_stcommcontact as st ON c.fk_stcommcontact = st.id' ;
2021-02-23 20:16:15 +00:00
if ( $id ) {
$sql .= " WHERE c.rowid = " . (( int ) $id );
} else {
2018-04-27 08:42:10 +00:00
$sql .= " WHERE c.entity IN ( " . getEntity ( $this -> element ) . " ) " ;
2018-11-12 13:49:08 +00:00
if ( $ref_ext ) {
$sql .= " AND c.ref_ext = ' " . $this -> db -> escape ( $ref_ext ) . " ' " ;
}
if ( $email ) {
$sql .= " AND c.email = ' " . $this -> db -> escape ( $email ) . " ' " ;
}
2024-09-12 10:32:33 +00:00
if ( $socid ) {
$sql .= " AND c.fk_soc = " . (( int ) $socid );
}
2018-04-27 08:42:10 +00:00
}
2009-08-11 12:51:33 +00:00
2019-12-03 10:17:29 +00:00
$resql = $this -> db -> query ( $sql );
2021-02-23 20:16:15 +00:00
if ( $resql ) {
2020-02-19 12:22:24 +00:00
$num = $this -> db -> num_rows ( $resql );
2021-02-23 20:16:15 +00:00
if ( $num > 1 ) {
2020-02-19 12:22:24 +00:00
$this -> error = 'Fetch found several records. Rename one of contact to avoid duplicate.' ;
dol_syslog ( $this -> error , LOG_ERR );
2020-02-20 11:34:51 +00:00
2020-02-19 12:22:24 +00:00
return 2 ;
2021-02-23 20:16:15 +00:00
} elseif ( $num ) { // $num = 1
2009-08-11 12:51:33 +00:00
$obj = $this -> db -> fetch_object ( $resql );
2025-09-11 10:14:53 +00:00
$this -> id = $obj -> rowid ;
$this -> entity = $obj -> entity ;
$this -> ref = $obj -> rowid ;
$this -> ref_ext = $obj -> ref_ext ;
2019-04-11 16:04:18 +00:00
2025-09-11 10:14:53 +00:00
$this -> civility_code = $obj -> civility_code ;
$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-11 16:04:18 +00:00
2024-02-18 22:43:00 +00:00
$this -> name_alias = $obj -> name_alias ;
2023-10-07 05:02:22 +00:00
$this -> lastname = $obj -> lastname ;
$this -> firstname = $obj -> firstname ;
$this -> address = $obj -> address ;
$this -> zip = $obj -> zip ;
$this -> town = $obj -> town ;
2011-03-09 10:33:35 +00:00
2025-09-11 10:14:53 +00:00
$this -> date_creation = $this -> db -> jdate ( $obj -> date_creation );
2018-08-26 16:08:10 +00:00
$this -> date_modification = $this -> db -> jdate ( $obj -> date_modification );
2025-08-17 00:00:29 +00:00
$this -> user_creation_id = $obj -> fk_user_creat ;
2024-10-14 14:45:46 +00:00
$this -> user_modification_id = $obj -> fk_user_modif ;
2018-09-02 16:18:10 +00:00
2023-10-07 05:02:22 +00:00
$this -> state_id = $obj -> state_id ;
$this -> state_code = $obj -> state_code ;
$this -> state = $obj -> state ;
2010-06-06 14:30:28 +00:00
2023-10-07 05:02:22 +00:00
$this -> country_id = $obj -> country_id ;
$this -> country_code = $obj -> country_id ? $obj -> country_code : '' ;
$this -> country = $obj -> country_id ? ( $langs -> trans ( 'Country' . $obj -> country_code ) != 'Country' . $obj -> country_code ? $langs -> transnoentities ( 'Country' . $obj -> country_code ) : $obj -> country ) : '' ;
2011-05-02 18:21:57 +00:00
2023-10-07 05:02:22 +00:00
$this -> fk_soc = $obj -> fk_soc ; // Both fk_soc and socid are used
$this -> socid = $obj -> fk_soc ; // Both fk_soc and socid are used
$this -> socname = $obj -> socname ;
$this -> poste = $obj -> poste ;
2025-08-17 00:00:29 +00:00
$this -> status = $obj -> status ;
$this -> statut = $obj -> status ; // deprecated
2009-08-11 12:51:33 +00:00
2022-11-04 16:32:48 +00:00
$this -> fk_prospectlevel = $obj -> fk_prospectlevel ;
2020-04-27 15:35:14 +00:00
2020-10-31 13:32:18 +00:00
$transcode = $langs -> trans ( 'StatusProspect' . $obj -> fk_stcommcontact );
$libelle = ( $transcode != 'StatusProspect' . $obj -> fk_stcommcontact ? $transcode : $obj -> stcomm );
$this -> stcomm_id = $obj -> fk_stcommcontact ; // id statut commercial
$this -> statut_commercial = $libelle ; // libelle statut commercial
$this -> stcomm_picto = $obj -> stcomm_picto ; // Picto statut commercial
2020-04-27 15:35:14 +00:00
2025-09-11 10:14:53 +00:00
$this -> phone_pro = trim ( $obj -> phone );
$this -> fax = trim ( $obj -> fax );
$this -> phone_perso = trim ( $obj -> phone_perso );
$this -> phone_mobile = trim ( $obj -> phone_mobile );
2023-10-07 05:02:22 +00:00
$this -> email = $obj -> email ;
$this -> socialnetworks = ( $obj -> socialnetworks ? ( array ) json_decode ( $obj -> socialnetworks , true ) : array ());
$this -> photo = $obj -> photo ;
$this -> priv = $obj -> priv ;
$this -> mail = $obj -> email ;
$this -> birthday = $this -> db -> jdate ( $obj -> birthday );
$this -> note = $obj -> note_private ; // deprecated
$this -> note_private = $obj -> note_private ;
$this -> note_public = $obj -> note_public ;
$this -> default_lang = $obj -> default_lang ;
$this -> user_id = $obj -> user_id ;
$this -> user_login = $obj -> user_login ;
$this -> canvas = $obj -> canvas ;
2009-08-11 12:51:33 +00:00
2023-02-06 20:43:50 +00:00
$this -> import_key = $obj -> import_key ;
2017-07-13 21:52:02 +00:00
2016-04-22 08:30:13 +00:00
// Define gender according to civility
2016-08-05 22:04:24 +00:00
$this -> setGenderFromCivility ();
2012-01-17 23:16:02 +00:00
2016-04-22 08:30:13 +00:00
// Search Dolibarr user linked to this contact
2009-08-11 12:51:33 +00:00
$sql = " SELECT u.rowid " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " user as u " ;
2021-08-23 15:41:11 +00:00
$sql .= " WHERE u.fk_socpeople = " . (( int ) $this -> id );
2009-08-11 12:51:33 +00:00
2019-11-08 14:51:54 +00:00
$resql = $this -> db -> query ( $sql );
2021-02-23 20:16:15 +00:00
if ( $resql ) {
if ( $this -> db -> num_rows ( $resql )) {
2009-08-11 12:51:33 +00:00
$uobj = $this -> db -> fetch_object ( $resql );
$this -> user_id = $uobj -> rowid ;
}
$this -> db -> free ( $resql );
2020-05-21 13:05:19 +00:00
} else {
2019-11-08 14:51:54 +00:00
$this -> error = $this -> db -> error ();
2009-08-11 12:51:33 +00:00
return - 1 ;
}
2020-10-23 18:08:35 +00:00
// Retrieve all extrafield
2020-02-19 12:22:24 +00:00
// fetch optionals attributes and labels
$this -> fetch_optionals ();
2020-02-20 11:34:51 +00:00
2020-02-19 12:22:24 +00:00
// Load also alerts of this user
2021-02-23 20:16:15 +00:00
if ( $user ) {
2009-08-11 12:51:33 +00:00
$sql = " SELECT fk_user " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " user_alert " ;
2021-08-23 15:41:11 +00:00
$sql .= " WHERE fk_user = " . (( int ) $user -> id ) . " AND fk_contact = " . (( int ) $id );
2009-08-11 12:51:33 +00:00
2019-11-08 14:51:54 +00:00
$resql = $this -> db -> query ( $sql );
2021-02-23 20:16:15 +00:00
if ( $resql ) {
if ( $this -> db -> num_rows ( $resql )) {
2009-08-11 12:51:33 +00:00
$obj = $this -> db -> fetch_object ( $resql );
$this -> birthday_alert = 1 ;
}
$this -> db -> free ( $resql );
2020-05-21 13:05:19 +00:00
} else {
2019-11-08 14:51:54 +00:00
$this -> error = $this -> db -> error ();
2009-08-11 12:51:33 +00:00
return - 1 ;
}
}
2007-09-10 00:17:28 +00:00
2020-02-19 12:22:24 +00:00
// Load also roles of this address
if ( $loadalsoroles ) {
$resultRole = $this -> fetchRoles ();
if ( $resultRole < 0 ) {
return $resultRole ;
}
2019-09-02 20:01:48 +00:00
}
2025-04-01 20:37:23 +00:00
return $this -> id ;
2020-05-21 13:05:19 +00:00
} else {
2025-04-29 08:53:52 +00:00
$langs -> load ( 'errors' );
$this -> error = $langs -> trans ( " ErrorRecordNotFound " );
2007-09-10 00:17:28 +00:00
return 0 ;
}
2020-05-21 13:05:19 +00:00
} else {
2019-11-08 14:51:54 +00:00
$this -> error = $this -> db -> error ();
2009-08-11 12:51:33 +00:00
return - 1 ;
}
}
2024-09-12 10:32:33 +00:00
/**
* Search the contact that match the most the provided parameters .
* Searching rules try to find the existing contact .
*
* @ param int $id Id of contact
* @ param string $lastname Lastname ( TODO Not yet implemented )
* @ param string $firstname Firstname ( TODO Not yet implemented )
* @ param string $ref_ext External reference , not given by Dolibarr
* @ param string $email Email
* @ param string $ref_alias Name alias ( TODO Not yet implemented )
* @ param int $socid Filter on thirdparty id
2024-10-03 11:49:31 +00:00
* @ return int ID of contact if OK , < 0 if KO or if two records found for same ref or idprof , 0 if not found .
2024-09-12 10:32:33 +00:00
*/
public function findNearest ( $id = 0 , $lastname = '' , $firstname = '' , $ref_ext = '' , $email = '' , $ref_alias = '' , $socid = 0 )
{
// A rowid is known, it is a unique key so we found it
if ( $id ) {
return $id ;
}
// We try to find the contact with exact matching on all fields
// TODO Replace this with step by step search
// Then search on email
// Then search on lastname + firstname
// Then search ref_ext or alias with a OR
$tmpcontact = new Contact ( $this -> db );
$result = $tmpcontact -> fetch ( $id , null , $ref_ext , $email , 0 , $socid );
return $result ;
}
2009-08-11 12:51:33 +00:00
2020-02-04 08:00:31 +00:00
2016-08-05 22:04:24 +00:00
/**
2020-02-04 08:00:31 +00:00
* Set the property " gender " of this class , based on the property " civility_id "
* or use property " civility_code " as fallback , when " civility_id " is not available .
2017-07-13 21:52:02 +00:00
*
2016-08-05 22:04:24 +00:00
* @ return void
*/
2019-02-24 23:56:48 +00:00
public function setGenderFromCivility ()
2016-08-05 22:04:24 +00:00
{
2020-02-04 08:00:31 +00:00
unset ( $this -> gender );
2021-02-23 20:16:15 +00:00
if ( in_array ( $this -> civility_id , array ( 'MR' )) || in_array ( $this -> civility_code , array ( 'MR' ))) {
2020-02-04 08:00:31 +00:00
$this -> gender = 'man' ;
2021-02-23 20:16:15 +00:00
} elseif ( in_array ( $this -> civility_id , array ( 'MME' , 'MLE' )) || in_array ( $this -> civility_code , array ( 'MME' , 'MLE' ))) {
2020-02-04 08:00:31 +00:00
$this -> gender = 'woman' ;
}
2017-07-13 21:52:02 +00:00
}
2020-10-31 13:32:18 +00:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2011-07-04 09:36:29 +00:00
/**
2016-02-24 10:17:47 +00:00
* Load number of elements the contact is used as a link for
2011-09-16 17:57:09 +00:00
* ref_facturation
* ref_contrat
2016-02-24 10:17:47 +00:00
* ref_commande ( for order and / or shipments )
2011-09-16 17:57:09 +00:00
* ref_propale
*
2023-12-06 14:46:39 +00:00
* @ return int Return integer < 0 if KO , >= 0 if OK
2009-08-11 12:51:33 +00:00
*/
2019-02-24 23:56:48 +00:00
public function load_ref_elements ()
2009-08-11 12:51:33 +00:00
{
2020-10-31 13:32:18 +00:00
// phpcs:enable
2023-10-07 05:02:22 +00:00
// Count the elements for which it is contact
2019-11-08 14:51:54 +00:00
$sql = " SELECT tc.element, count(ec.rowid) as nb " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " element_contact as ec, " . MAIN_DB_PREFIX . " c_type_contact as tc " ;
$sql .= " WHERE ec.fk_c_type_contact = tc.rowid " ;
2021-08-23 15:41:11 +00:00
$sql .= " AND fk_socpeople = " . (( int ) $this -> id );
2019-11-08 14:51:54 +00:00
$sql .= " AND tc.source = 'external' " ;
$sql .= " GROUP BY tc.element " ;
2009-08-11 12:51:33 +00:00
2014-06-12 09:31:53 +00:00
dol_syslog ( get_class ( $this ) . " ::load_ref_elements " , LOG_DEBUG );
2009-08-11 12:51:33 +00:00
2019-11-08 14:51:54 +00:00
$resql = $this -> db -> query ( $sql );
2021-02-23 20:16:15 +00:00
if ( $resql ) {
while ( $obj = $this -> db -> fetch_object ( $resql )) {
if ( $obj -> nb ) {
if ( $obj -> element == 'facture' ) {
$this -> ref_facturation = $obj -> nb ;
} elseif ( $obj -> element == 'contrat' ) {
$this -> ref_contrat = $obj -> nb ;
} elseif ( $obj -> element == 'commande' ) {
$this -> ref_commande = $obj -> nb ;
} elseif ( $obj -> element == 'propal' ) {
$this -> ref_propal = $obj -> nb ;
}
2009-08-11 12:51:33 +00:00
}
2006-02-24 23:16:35 +00:00
}
2009-08-11 12:51:33 +00:00
$this -> db -> free ( $resql );
return 0 ;
2020-05-21 13:05:19 +00:00
} else {
2019-11-08 14:51:54 +00:00
$this -> error = $this -> db -> lasterror ();
2009-08-11 12:51:33 +00:00
return - 1 ;
}
}
2006-02-24 23:16:35 +00:00
2011-07-04 09:36:29 +00:00
/**
2021-06-09 22:09:38 +00:00
* Delete a contact from database
2011-09-16 17:57:09 +00:00
*
2023-11-28 14:33:42 +00:00
* @ param User $user User making the delete
2021-06-09 22:09:38 +00:00
* @ param int $notrigger Disable all trigger
2023-12-01 18:51:32 +00:00
* @ return int Return integer < 0 if KO , > 0 if OK
2009-08-11 12:51:33 +00:00
*/
2023-11-28 14:33:42 +00:00
public function delete ( $user , $notrigger = 0 )
2006-02-24 23:16:35 +00:00
{
2019-11-08 14:51:54 +00:00
$error = 0 ;
2009-01-19 22:41:26 +00:00
2007-09-16 03:55:35 +00:00
$this -> db -> begin ();
2009-01-19 22:41:26 +00:00
2025-09-11 10:14:53 +00:00
if ( ! $notrigger ) {
2022-10-03 13:16:41 +00:00
// Call trigger
$result = $this -> call_trigger ( 'CONTACT_DELETE' , $user );
if ( $result < 0 ) {
$error ++ ;
}
// End call triggers
}
2021-02-23 20:16:15 +00:00
if ( ! $error ) {
2007-09-16 03:55:35 +00:00
// Get all rowid of element_contact linked to a type that is link to llx_socpeople
$sql = " SELECT ec.rowid " ;
2019-11-08 14:51:54 +00:00
$sql .= " FROM " . MAIN_DB_PREFIX . " element_contact ec, " ;
$sql .= " " . MAIN_DB_PREFIX . " c_type_contact tc " ;
2021-08-23 15:41:11 +00:00
$sql .= " WHERE ec.fk_socpeople= " . (( int ) $this -> id );
2019-11-08 14:51:54 +00:00
$sql .= " AND ec.fk_c_type_contact=tc.rowid " ;
$sql .= " AND tc.source='external' " ;
2020-06-01 08:51:50 +00:00
dol_syslog ( __METHOD__ , LOG_DEBUG );
2007-09-16 03:55:35 +00:00
$resql = $this -> db -> query ( $sql );
2021-02-23 20:16:15 +00:00
if ( $resql ) {
2019-11-08 14:51:54 +00:00
$num = $this -> db -> num_rows ( $resql );
2009-01-19 22:41:26 +00:00
2019-11-08 14:51:54 +00:00
$i = 0 ;
2021-02-23 20:16:15 +00:00
while ( $i < $num && ! $error ) {
2007-09-16 03:55:35 +00:00
$obj = $this -> db -> fetch_object ( $resql );
$sqldel = " DELETE FROM " . MAIN_DB_PREFIX . " element_contact " ;
2021-06-09 13:36:47 +00:00
$sqldel .= " WHERE rowid = " . (( int ) $obj -> rowid );
2020-06-01 08:51:50 +00:00
dol_syslog ( __METHOD__ , LOG_DEBUG );
2007-09-16 03:55:35 +00:00
$result = $this -> db -> query ( $sqldel );
2021-02-23 20:16:15 +00:00
if ( ! $result ) {
2007-09-16 03:55:35 +00:00
$error ++ ;
2019-11-08 14:51:54 +00:00
$this -> error = $this -> db -> error () . ' sql=' . $sqldel ;
2007-09-16 03:55:35 +00:00
}
$i ++ ;
}
2020-05-21 13:05:19 +00:00
} else {
2007-09-16 03:55:35 +00:00
$error ++ ;
2019-11-08 14:51:54 +00:00
$this -> error = $this -> db -> error () . ' sql=' . $sql ;
2006-11-18 21:59:10 +00:00
}
}
2009-01-19 22:41:26 +00:00
2021-02-23 20:16:15 +00:00
if ( ! $error ) {
2019-09-02 20:01:48 +00:00
// Remove Roles
2021-08-23 15:41:11 +00:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " societe_contacts WHERE fk_socpeople = " . (( int ) $this -> id );
2020-06-01 08:51:50 +00:00
dol_syslog ( __METHOD__ , LOG_DEBUG );
2019-11-08 14:51:54 +00:00
$resql = $this -> db -> query ( $sql );
2021-02-23 20:16:15 +00:00
if ( ! $resql ) {
2019-09-02 20:01:48 +00:00
$error ++ ;
$this -> error .= $this -> db -> lasterror ();
2019-11-08 14:51:54 +00:00
$errorflag = - 1 ;
2019-09-02 20:01:48 +00:00
}
}
2024-03-18 22:51:44 +00:00
if ( ! $error ) {
// Remove Notifications
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " notify_def WHERE fk_contact = " . (( int ) $this -> id );
dol_syslog ( __METHOD__ , LOG_DEBUG );
$resql = $this -> db -> query ( $sql );
if ( ! $resql ) {
$error ++ ;
$this -> error .= $this -> db -> lasterror ();
$errorflag = - 1 ;
}
}
2021-02-23 20:16:15 +00:00
if ( ! $error ) {
2013-09-05 19:03:03 +00:00
// Remove category
2021-08-23 15:41:11 +00:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " categorie_contact WHERE fk_socpeople = " . (( int ) $this -> id );
2020-06-01 08:51:50 +00:00
dol_syslog ( __METHOD__ , LOG_DEBUG );
2019-11-08 14:51:54 +00:00
$resql = $this -> db -> query ( $sql );
2021-02-23 20:16:15 +00:00
if ( ! $resql ) {
2013-09-05 19:03:03 +00:00
$error ++ ;
$this -> error .= $this -> db -> lasterror ();
2019-11-08 14:51:54 +00:00
$errorflag = - 1 ;
2013-09-05 19:03:03 +00:00
}
}
2021-02-23 20:16:15 +00:00
if ( ! $error ) {
2007-09-16 03:55:35 +00:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " socpeople " ;
2021-08-27 16:18:50 +00:00
$sql .= " WHERE rowid = " . (( int ) $this -> id );
2020-06-01 08:51:50 +00:00
dol_syslog ( __METHOD__ , LOG_DEBUG );
2007-09-16 03:55:35 +00:00
$result = $this -> db -> query ( $sql );
2021-02-23 20:16:15 +00:00
if ( ! $result ) {
2007-09-16 03:55:35 +00:00
$error ++ ;
2019-11-08 14:51:54 +00:00
$this -> error = $this -> db -> error () . ' sql=' . $sql ;
2007-09-16 03:55:35 +00:00
}
}
2013-04-05 22:37:20 +00:00
2023-10-07 05:21:49 +00:00
// Remove extrafields
2020-10-31 13:32:18 +00:00
if ( ! $error ) {
// For avoid conflicts if trigger used
2019-11-08 14:51:54 +00:00
$result = $this -> deleteExtraFields ();
2021-02-23 20:16:15 +00:00
if ( $result < 0 ) {
$error ++ ;
}
2012-12-16 22:18:20 +00:00
}
2007-09-16 03:55:35 +00:00
2021-02-23 20:16:15 +00:00
if ( ! $error ) {
2007-09-16 03:55:35 +00:00
$this -> db -> commit ();
return 1 ;
2020-05-21 13:05:19 +00:00
} else {
2007-09-16 03:55:35 +00:00
$this -> db -> rollback ();
2019-01-27 10:55:16 +00:00
dol_syslog ( " Error " . $this -> error , LOG_ERR );
2006-11-19 01:46:32 +00:00
return - 1 ;
2006-11-18 21:59:10 +00:00
}
2006-02-24 23:16:35 +00:00
}
2006-06-24 15:13:29 +00:00
2009-01-19 22:41:26 +00:00
2011-09-16 17:57:09 +00:00
/**
2023-10-07 05:21:49 +00:00
* Load contact information from the database
2011-09-16 17:57:09 +00:00
*
2023-10-07 05:21:49 +00:00
* @ param int $id Id of the contact to load
2011-09-16 17:57:09 +00:00
* @ return void
2009-08-11 12:51:33 +00:00
*/
2019-02-24 23:56:48 +00:00
public function info ( $id )
2009-08-11 12:51:33 +00:00
{
2010-01-13 18:51:19 +00:00
$sql = " SELECT c.rowid, c.datec as datec, c.fk_user_creat, " ;
2025-08-28 17:28:48 +00:00
$sql .= " GREATEST(c.tms, cef.tms) as tms, c.fk_user_modif " ;
2019-11-08 14:51:54 +00:00
$sql .= " FROM " . MAIN_DB_PREFIX . " socpeople as c " ;
2025-08-28 17:28:48 +00:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " socpeople_extrafields as cef ON cef.fk_object=c.rowid " ;
2021-06-09 13:36:47 +00:00
$sql .= " WHERE c.rowid = " . (( int ) $id );
2009-08-11 12:51:33 +00:00
2019-11-08 14:51:54 +00:00
$resql = $this -> db -> query ( $sql );
2021-02-23 20:16:15 +00:00
if ( $resql ) {
if ( $this -> db -> num_rows ( $resql )) {
2009-08-11 12:51:33 +00:00
$obj = $this -> db -> fetch_object ( $resql );
2018-09-16 17:19:45 +00:00
$this -> id = $obj -> rowid ;
2009-08-11 12:51:33 +00:00
2023-10-24 09:37:29 +00:00
$this -> user_creation_id = $obj -> fk_user_creat ;
$this -> user_modification_id = $obj -> fk_user_modif ;
2010-01-13 18:51:19 +00:00
$this -> date_creation = $this -> db -> jdate ( $obj -> datec );
$this -> date_modification = $this -> db -> jdate ( $obj -> tms );
2009-08-11 12:51:33 +00:00
}
$this -> db -> free ( $resql );
2020-05-21 13:05:19 +00:00
} else {
2009-08-11 12:51:33 +00:00
print $this -> db -> error ();
}
}
2010-02-21 21:21:12 +00:00
/**
2023-10-07 05:21:49 +00:00
* Return number of mass Emailing received by these contacts with its email
2011-09-16 17:57:09 +00:00
*
* @ return int Number of EMailings
2009-08-11 12:51:33 +00:00
*/
2019-02-24 23:56:48 +00:00
public function getNbOfEMailings ()
2009-08-11 12:51:33 +00:00
{
$sql = " SELECT count(mc.email) as nb " ;
2019-11-08 14:51:54 +00:00
$sql .= " FROM " . MAIN_DB_PREFIX . " mailing_cibles as mc, " . MAIN_DB_PREFIX . " mailing as m " ;
$sql .= " WHERE mc.fk_mailing=m.rowid AND mc.email = ' " . $this -> db -> escape ( $this -> email ) . " ' " ;
$sql .= " AND m.entity IN ( " . getEntity ( $this -> element ) . " ) AND mc.statut NOT IN (-1,0) " ; // -1 error, 0 not sent, 1 sent with success
2012-09-16 23:39:30 +00:00
2019-11-08 14:51:54 +00:00
$resql = $this -> db -> query ( $sql );
2021-02-23 20:16:15 +00:00
if ( $resql ) {
2009-08-11 12:51:33 +00:00
$obj = $this -> db -> fetch_object ( $resql );
2025-09-15 14:16:22 +00:00
$nb = ( int ) $obj -> nb ;
2009-08-11 12:51:33 +00:00
$this -> db -> free ( $resql );
return $nb ;
2020-05-21 13:05:19 +00:00
} else {
2019-11-08 14:51:54 +00:00
$this -> error = $this -> db -> error ();
2009-08-11 12:51:33 +00:00
return - 1 ;
}
}
2006-08-05 16:44:43 +00:00
2023-02-01 20:29:50 +00:00
/**
* getTooltipContentArray
2024-09-23 01:24:19 +00:00
* @ param array < string , mixed > $params params to construct tooltip data
2023-02-01 20:29:50 +00:00
* @ since v18
2024-09-23 01:24:19 +00:00
* @ return array { picto ? : string , ref ? : string , refsupplier ? : string , label ? : string , date ? : string , date_echeance ? : string , amountht ? : string , total_ht ? : string , totaltva ? : string , amountlt1 ? : string , amountlt2 ? : string , amountrevenustamp ? : string , totalttc ? : string } | array { optimize : string }
2023-02-01 20:29:50 +00:00
*/
public function getTooltipContentArray ( $params )
{
global $conf , $langs , $user ;
$datas = [];
2023-11-27 10:39:32 +00:00
if ( getDolGlobalString ( 'MAIN_OPTIMIZEFORTEXTBROWSER' )) {
2023-02-01 20:29:50 +00:00
return [ 'optimize' => $langs -> trans ( " ShowContact " )];
}
if ( ! empty ( $this -> photo ) && class_exists ( 'Form' )) {
$photo = '<div class="photointooltip floatright">' ;
$photo .= Form :: showphoto ( 'contact' , $this , 0 , 40 , 0 , 'photoref' , 'mini' , 0 ); // Important, we must force height so image will have height tags and if image is inside a tooltip, the tooltip manager can calculate height and position correctly the tooltip.
$photo .= '</div>' ;
$datas [ 'photo' ] = $photo ;
}
$datas [ 'picto' ] = img_picto ( '' , $this -> picto ) . ' <u class="paddingrightonly">' . $langs -> trans ( " Contact " ) . '</u> ' . $this -> getLibStatut ( 4 );
$datas [ 'name' ] = '<br><b>' . $langs -> trans ( " Name " ) . ':</b> ' . $this -> getFullName ( $langs );
// if ($this->civility_id) $datas['civility'] = '<br><b>' . $langs->trans("Civility") . ':</b> '.$this->civility_id; // TODO Translate civilty_id code
if ( ! empty ( $this -> poste )) {
$datas [ 'job' ] = '<br><b>' . $langs -> trans ( " Poste " ) . ':</b> ' . $this -> poste ;
}
$datas [ 'email' ] = '<br><b>' . $langs -> trans ( " EMail " ) . ':</b> ' . $this -> email ;
$phonelist = array ();
2023-12-04 11:01:45 +00:00
$country_code = empty ( $this -> country_code ) ? '' : $this -> country_code ;
2023-02-01 20:29:50 +00:00
if ( $this -> phone_pro ) {
$phonelist [] = dol_print_phone ( $this -> phone_pro , $country_code , $this -> id , 0 , '' , ' ' , 'phone' );
}
if ( $this -> phone_mobile ) {
$phonelist [] = dol_print_phone ( $this -> phone_mobile , $country_code , $this -> id , 0 , '' , ' ' , 'mobile' );
}
if ( $this -> phone_perso ) {
$phonelist [] = dol_print_phone ( $this -> phone_perso , $country_code , $this -> id , 0 , '' , ' ' , 'phone' );
}
$datas [ 'phonelist' ] = '<br><b>' . $langs -> trans ( " Phone " ) . ':</b> ' . implode ( ' ' , $phonelist );
$datas [ 'address' ] = '<br><b>' . $langs -> trans ( " Address " ) . ':</b> ' . dol_format_address ( $this , 1 , ' ' , $langs );
return $datas ;
}
2006-08-05 16:44:43 +00:00
/**
2011-09-16 17:57:09 +00:00
* Return name of contact with link ( and eventually picto )
2014-05-04 22:23:09 +00:00
* Use $this -> id , $this -> lastname , $this -> firstname , this -> civility_id
2011-09-16 17:57:09 +00:00
*
2026-02-07 20:31:33 +00:00
* @ param int $withpicto Include picto with link ( 0 = no picto , 1 = picto + name , 2 = picto only , - 1 = photo + name , - 2 = photo only , - 3 = picto small + name )
2025-08-17 00:20:52 +00:00
* @ param string $option Where the link point to ( 'nolink' , ... )
* @ param int $notooltip 1 = Disable tooltip
2017-10-03 14:00:52 +00:00
* @ param string $moreparam Add more param into URL
2020-10-31 13:32:18 +00:00
* @ param int $save_lastsearch_value - 1 = Auto , 0 = No save of lastsearch_values when clicking , 1 = Save lastsearch_values whenclicking
2025-08-17 00:20:52 +00:00
* @ param int $maxlen Max len
2022-01-15 11:56:19 +00:00
* @ param string $morecss Add more css on link
2017-10-03 14:00:52 +00:00
* @ return string String with URL
2006-08-05 16:44:43 +00:00
*/
2025-08-17 00:20:52 +00:00
public function getNomUrl ( $withpicto = 0 , $option = '' , $notooltip = 0 , $moreparam = '' , $save_lastsearch_value = - 1 , $maxlen = 0 , $morecss = 'valignmiddle' )
2006-08-05 16:44:43 +00:00
{
2016-07-16 16:00:53 +00:00
global $conf , $langs , $hookmanager ;
2009-01-19 22:41:26 +00:00
2023-06-29 10:10:31 +00:00
if ( ! empty ( $conf -> dol_no_mouse_hover )) {
$notooltip = 1 ; // Force disable tooltips
}
2023-02-01 20:29:50 +00:00
$result = '' ;
2023-02-06 20:43:50 +00:00
$params = [
'id' => $this -> id ,
'objecttype' => $this -> element ,
'option' => $option ,
];
$classfortooltip = 'classfortooltip' ;
$dataparams = '' ;
if ( getDolGlobalInt ( 'MAIN_ENABLE_AJAX_TOOLTIP' )) {
$classfortooltip = 'classforajaxtooltip' ;
2023-04-03 17:51:40 +00:00
$dataparams = ' data-params="' . dol_escape_htmltag ( json_encode ( $params )) . '"' ;
$label = '' ;
} else {
$label = implode ( $this -> getTooltipContentArray ( $params ));
2021-02-23 20:16:15 +00:00
}
2020-10-31 13:32:18 +00:00
2025-10-06 16:17:02 +00:00
$baseurl = DOL_URL_ROOT . '/contact/card.php' ;
$query = [ 'id' => $this -> id ];
2021-02-23 20:16:15 +00:00
if ( $option !== 'nolink' ) {
2020-10-31 13:32:18 +00:00
// Add param to save lastsearch_values or not
$add_save_lastsearch_values = ( $save_lastsearch_value == 1 ? 1 : 0 );
2023-09-10 15:41:22 +00:00
if ( $save_lastsearch_value == - 1 && isset ( $_SERVER [ " PHP_SELF " ]) && preg_match ( '/list\.php/' , $_SERVER [ " PHP_SELF " ])) {
2021-02-23 20:16:15 +00:00
$add_save_lastsearch_values = 1 ;
}
2025-09-11 10:14:53 +00:00
if ( $add_save_lastsearch_values ) {
2025-10-06 16:17:02 +00:00
$query = array_merge ( $query , [ 'save_lastsearch_values' => 1 ]);
2021-02-23 20:16:15 +00:00
}
2020-10-31 13:32:18 +00:00
}
2025-10-06 16:17:02 +00:00
$url = dolBuildUrl ( $baseurl , $query );
2020-10-31 13:32:18 +00:00
$url .= $moreparam ;
2023-06-29 10:10:31 +00:00
$linkclose = '' ;
2018-03-12 18:02:30 +00:00
if ( empty ( $notooltip )) {
2023-11-27 10:39:32 +00:00
if ( getDolGlobalString ( 'MAIN_OPTIMIZEFORTEXTBROWSER' )) {
2020-10-31 13:32:18 +00:00
$label = $langs -> trans ( " ShowContact " );
2025-01-09 00:41:24 +00:00
$linkclose .= ' alt="' . dolPrintHTMLForAttribute ( $label ) . '"' ;
2020-10-31 13:32:18 +00:00
}
2025-01-09 00:41:24 +00:00
$linkclose .= ( $label ? ' title="' . dolPrintHTMLForAttribute ( $label ) . '"' : ' title="tocomplete"' );
2023-02-05 16:04:26 +00:00
$linkclose .= $dataparams . ' class="' . $classfortooltip . ( $morecss ? ' ' . $morecss : '' ) . '"' ;
2023-06-29 10:10:31 +00:00
} else {
$linkclose = ( $morecss ? ' class="' . $morecss . '"' : '' );
2016-07-16 16:00:53 +00:00
}
2006-08-05 16:44:43 +00:00
2025-09-11 10:14:53 +00:00
if ( $option == 'nolink' ) {
2023-06-29 10:10:31 +00:00
$linkstart = '<span' ;
} else {
$linkstart = '<a href="' . $url . '"' ;
}
2019-11-08 14:51:54 +00:00
$linkstart .= $linkclose . '>' ;
2025-09-11 10:14:53 +00:00
if ( $option == 'nolink' ) {
2023-06-29 10:10:31 +00:00
$linkend = '</span>' ;
} else {
2019-11-08 14:51:54 +00:00
$linkend = '</a>' ;
2006-08-05 16:44:43 +00:00
}
2017-07-13 21:52:02 +00:00
2023-06-29 10:10:31 +00:00
$result .= $linkstart ;
2021-02-23 20:16:15 +00:00
if ( $withpicto ) {
2022-02-02 16:57:20 +00:00
if ( $withpicto < 0 ) {
2023-09-25 09:38:29 +00:00
$result .= '<!-- picto photo contact --><span class="nopadding userimg' . ( $morecss ? ' ' . $morecss : '' ) . '">' . Form :: showphoto ( 'contact' , $this , 0 , 0 , 0 , 'userphoto' . ( $withpicto == - 3 ? 'small' : '' ), 'mini' , 0 , 1 ) . '</span>' ;
2023-07-31 19:52:58 +00:00
if ( $withpicto != 2 && $withpicto != - 2 ) {
$result .= ' ' ;
}
2021-03-04 09:36:17 +00:00
} else {
2024-02-14 03:46:59 +00:00
$result .= img_object (( $notooltip ? '' : $label ), ( $this -> picto ? $this -> picto : 'generic' ), ( $notooltip ? (( $withpicto != 2 ) ? 'class="pictofixedwidth valignmiddle"' : '' ) : 'class="' . (( $withpicto != 2 ) ? 'pictofixedwidth valignmiddle' : '' ) . '"' ), 0 , 0 , $notooltip ? 0 : 1 );
2021-03-04 09:15:41 +00:00
}
2021-02-23 20:16:15 +00:00
}
2021-03-04 09:15:41 +00:00
if ( $withpicto != 2 && $withpicto != - 2 ) {
2025-05-10 12:06:51 +00:00
$result .= '<span class="valignmiddle">' . ( $maxlen ? dol_trunc ( $this -> getFullName ( $langs ), $maxlen ) : $this -> getFullName ( $langs )) . '</span>' ;
2021-02-23 20:16:15 +00:00
}
2023-06-29 10:10:31 +00:00
$result .= $linkend ;
2017-11-02 14:03:09 +00:00
2018-03-15 19:46:55 +00:00
global $action ;
$hookmanager -> initHooks ( array ( 'contactdao' ));
2023-06-29 10:10:31 +00:00
$parameters = array ( 'id' => $this -> id , 'getnomurl' => & $result );
2019-11-08 14:51:54 +00:00
$reshook = $hookmanager -> executeHooks ( 'getNomUrl' , $parameters , $this , $action ); // Note that $action and $object may have been modified by some hooks
2021-02-23 20:16:15 +00:00
if ( $reshook > 0 ) {
$result = $hookmanager -> resPrint ;
} else {
$result .= $hookmanager -> resPrint ;
}
2018-03-15 19:46:55 +00:00
2006-08-05 16:44:43 +00:00
return $result ;
2006-08-31 23:44:34 +00:00
}
2009-08-11 12:51:33 +00:00
/**
2013-05-12 15:09:48 +00:00
* Return civility label of contact
2011-09-16 17:57:09 +00:00
*
2013-05-12 15:09:48 +00:00
* @ return string Translated name of civility
2009-08-11 12:51:33 +00:00
*/
2019-02-24 23:56:48 +00:00
public function getCivilityLabel ()
2009-08-11 12:51:33 +00:00
{
global $langs ;
2008-01-10 17:12:07 +00:00
2019-11-08 14:51:54 +00:00
$code = ( $this -> civility_code ? $this -> civility_code : ( ! empty ( $this -> civility_id ) ? $this -> civility : ( ! empty ( $this -> civilite ) ? $this -> civilite : '' )));
2021-02-23 20:16:15 +00:00
if ( empty ( $code )) {
return '' ;
}
2019-08-15 18:39:47 +00:00
$langs -> load ( " dict " );
return $langs -> getLabelFromKey ( $this -> db , " Civility " . $code , " c_civility " , " code " , " label " , $code );
2009-08-11 12:51:33 +00:00
}
2008-01-10 17:12:07 +00:00
2007-05-04 21:19:15 +00:00
/**
2023-04-08 13:08:55 +00:00
* Return the label of the status
2011-09-16 17:57:09 +00:00
*
2023-04-08 13:08:55 +00: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
* @ return string Label of status
2007-05-04 21:19:15 +00:00
*/
2019-02-24 23:56:48 +00:00
public function getLibStatut ( $mode )
2007-05-04 21:19:15 +00:00
{
2025-08-15 15:31:44 +00:00
return $this -> LibStatut ( $this -> status , $mode );
2013-07-10 10:28:28 +00:00
}
2013-09-09 00:37:11 +00:00
2020-10-31 13:32:18 +00:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2007-05-04 21:19:15 +00:00
/**
2023-04-08 13:08:55 +00:00
* Return the label of a given status
2011-09-16 17:57:09 +00:00
*
2023-04-08 13:08:55 +00:00
* @ param int $status Id status
* @ 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
* @ return string Label of status
2007-05-04 21:19:15 +00:00
*/
2019-10-24 14:38:06 +00:00
public function LibStatut ( $status , $mode )
2007-05-04 21:19:15 +00:00
{
2020-10-31 13:32:18 +00:00
// phpcs:enable
2007-05-04 21:19:15 +00:00
global $langs ;
2009-01-19 22:41:26 +00:00
2019-11-01 11:52:03 +00:00
$labelStatus = array (
2019-10-28 07:16:43 +00:00
0 => 'ActivityCeased' ,
1 => 'InActivity' ,
4 => 'InActivity' ,
5 => 'ActivityCeased' ,
);
2019-11-01 11:52:03 +00:00
$labelStatusShort = array (
2019-10-28 07:16:43 +00:00
0 => 'ActivityCeased' ,
1 => 'InActivity' ,
4 => 'InActivity' ,
5 => 'ActivityCeased' ,
);
2019-10-24 14:38:06 +00:00
$statusType = 'status4' ;
2021-02-23 20:16:15 +00:00
if ( $status == 0 || $status == 5 ) {
$statusType = 'status5' ;
}
2019-10-24 14:38:06 +00:00
2021-10-16 17:37:57 +00:00
$label = $langs -> transnoentitiesnoconv ( $labelStatus [ $status ]);
$labelshort = $langs -> transnoentitiesnoconv ( $labelStatusShort [ $status ]);
2019-10-24 14:38:06 +00:00
return dolGetStatus ( $label , $labelshort , '' , $statusType , $mode );
2007-05-04 21:19:15 +00:00
}
2013-10-07 22:42:40 +00:00
2020-10-31 13:32:18 +00:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2008-03-30 22:25:39 +00:00
/**
2011-09-16 17:57:09 +00:00
* Return translated label of Public or Private
*
2019-10-24 14:38:06 +00:00
* @ param int $status Type ( 0 = public , 1 = private )
2026-06-26 16:13:55 +00:00
* @ param int $decorate 0 = No decorate , 1 = Add html decorated code ( color ) around text , 2 = Show picto for private and empty for public
2011-09-16 17:57:09 +00:00
* @ return string Label translated
2008-03-30 22:25:39 +00:00
*/
2026-06-26 16:13:55 +00:00
public function LibPubPriv ( $status , $decorate = 0 )
2008-03-30 22:25:39 +00:00
{
2020-10-31 13:32:18 +00:00
// phpcs:enable
2008-03-30 22:25:39 +00:00
global $langs ;
2021-02-23 20:16:15 +00:00
if ( $status == '1' ) {
2026-06-26 16:13:55 +00:00
$s = ( $decorate == 2 ? '' : $langs -> trans ( 'ContactPrivate' ));
if ( $decorate ) {
$s = '<span title="' . $langs -> trans ( 'ContactPrivateDesc' ) . '">' . img_picto ( '' , 'private' , 'class="paddingrightonly"' ) . $s . '</span>' ;
}
return $s ;
2021-02-23 20:16:15 +00:00
} else {
2026-06-26 16:13:55 +00:00
$s = ( $decorate == 2 ? '' : $langs -> trans ( 'ContactPublic' ));
if ( $decorate ) {
$s = '<span title="' . $langs -> trans ( 'ContactPublicDesc' ) . '">' . img_picto ( '' , 'public' , 'class="paddingrightonly"' ) . $s . '</span>' ;
}
return $s ;
2021-02-23 20:16:15 +00:00
}
2008-03-30 22:25:39 +00:00
}
2006-11-19 01:46:32 +00:00
/**
2020-10-31 13:32:18 +00:00
* Initialise an instance with random values .
* Used to build previews or test instances .
* id must be 0 if object instance is a specimen .
*
* @ return int > 0 if ok
2006-11-19 01:46:32 +00:00
*/
2019-02-24 23:56:48 +00:00
public function initAsSpecimen ()
2006-11-19 01:46:32 +00:00
{
2014-02-08 11:58:27 +00:00
// Get first id of existing company and save it into $socid
$socid = 0 ;
$sql = " SELECT rowid FROM " . MAIN_DB_PREFIX . " societe ORDER BY rowid LIMIT 1 " ;
2006-11-19 01:46:32 +00:00
$resql = $this -> db -> query ( $sql );
2019-02-24 23:56:48 +00:00
if ( $resql ) {
2014-02-08 11:58:27 +00:00
$obj = $this -> db -> fetch_object ( $resql );
2021-02-23 20:16:15 +00:00
if ( $obj ) {
$socid = $obj -> rowid ;
}
2006-11-19 01:46:32 +00:00
}
2009-08-12 00:40:16 +00:00
// Initialise parameters
2019-11-08 14:51:54 +00:00
$this -> id = 0 ;
2020-11-05 13:48:41 +00:00
$this -> entity = 1 ;
2019-11-08 14:51:54 +00:00
$this -> specimen = 1 ;
2012-06-26 11:11:04 +00:00
$this -> lastname = 'DOLIBARR' ;
2011-12-30 13:18:19 +00:00
$this -> firstname = 'SPECIMEN' ;
2013-04-05 22:37:20 +00:00
$this -> address = '21 jump street' ;
$this -> zip = '99999' ;
$this -> town = 'MyTown' ;
2011-12-30 13:18:19 +00:00
$this -> country_id = 1 ;
$this -> country_code = 'FR' ;
$this -> country = 'France' ;
2006-11-19 01:46:32 +00:00
$this -> email = 'specimen@specimen.com' ;
2019-09-12 16:12:28 +00:00
$this -> socialnetworks = array (
'skype' => 'tom.hanson' ,
2023-08-26 08:57:49 +00:00
'twitter' => 'tomhanson' ,
'linkedin' => 'tomhanson' ,
2019-09-12 16:12:28 +00:00
);
2013-06-05 14:24:32 +00:00
$this -> phone_pro = '0909090901' ;
$this -> phone_perso = '0909090902' ;
$this -> phone_mobile = '0909090903' ;
$this -> fax = '0909090909' ;
2013-04-06 01:40:55 +00:00
2019-11-08 14:51:54 +00:00
$this -> note_public = 'This is a comment (public)' ;
$this -> note_private = 'This is a comment (private)' ;
2013-04-05 22:37:20 +00:00
2014-02-08 11:58:27 +00:00
$this -> socid = $socid ;
2025-08-15 15:31:44 +00:00
$this -> status = 1 ;
2024-03-02 15:38:35 +00:00
2019-09-07 12:48:25 +00:00
return 1 ;
2013-07-10 10:28:28 +00:00
}
2013-09-09 00:37:11 +00:00
2013-07-10 10:28:28 +00:00
/**
* Change status of a user
*
2019-10-24 14:38:06 +00:00
* @ param int $status Status to set
2023-12-06 14:46:39 +00:00
* @ return int Return integer < 0 if KO , 0 if nothing is done , > 0 if OK
2013-07-10 10:28:28 +00:00
*/
2019-10-24 14:38:06 +00:00
public function setstatus ( $status )
2013-07-10 10:28:28 +00:00
{
2019-11-08 14:51:54 +00:00
global $conf , $langs , $user ;
2013-07-10 10:28:28 +00:00
2019-11-08 14:51:54 +00:00
$error = 0 ;
2013-07-10 10:28:28 +00:00
// Check parameters
2025-08-15 15:31:44 +00:00
if ( ! empty ( $this -> statut ) && empty ( $this -> status )) {
$this -> status = 1 ;
}
if ( $this -> status == $status ) {
2021-02-23 20:16:15 +00:00
return 0 ;
} else {
2025-08-15 15:31:44 +00:00
$this -> status = $status ;
2021-02-23 20:16:15 +00:00
$this -> statut = $status ;
}
2013-07-10 10:28:28 +00:00
$this -> db -> begin ();
2023-10-07 05:21:49 +00:00
// User disable
2013-07-10 10:28:28 +00:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " socpeople " ;
2025-08-15 15:31:44 +00:00
$sql .= " SET statut = " . (( int ) $this -> status );
2023-09-19 14:01:12 +00:00
$sql .= " , fk_user_modif = " . (( int ) $user -> id );
2021-03-30 15:53:25 +00:00
$sql .= " WHERE rowid = " . (( int ) $this -> id );
2013-07-10 10:28:28 +00:00
$result = $this -> db -> query ( $sql );
2014-06-12 09:31:53 +00:00
dol_syslog ( get_class ( $this ) . " ::setstatus " , LOG_DEBUG );
2021-02-23 20:16:15 +00:00
if ( $result ) {
2020-10-31 13:32:18 +00:00
// Call trigger
$result = $this -> call_trigger ( 'CONTACT_ENABLEDISABLE' , $user );
2021-02-23 20:16:15 +00:00
if ( $result < 0 ) {
$error ++ ;
}
2020-10-31 13:32:18 +00:00
// End call triggers
2013-07-10 10:28:28 +00:00
}
2021-02-23 20:16:15 +00:00
if ( $error ) {
2013-07-10 10:28:28 +00:00
$this -> db -> rollback ();
return - $error ;
2020-05-21 13:05:19 +00:00
} else {
2013-07-10 10:28:28 +00:00
$this -> db -> commit ();
return 1 ;
}
2006-11-19 01:46:32 +00:00
}
2015-09-30 16:46:51 +00:00
/**
* Sets object to supplied categories .
*
2025-10-31 03:05:45 +00:00
* Assign the object to all categories not yet assigned .
* Unasign object from existing categories not supplied in $categories ( if remove_existing == true ) .
* If remove_existing is false , existing categories are left untouch .
2015-09-30 16:46:51 +00:00
*
2025-10-31 03:05:45 +00:00
* @ param int [] | int $categories Category or categories IDs
* @ param boolean $remove_existing True : Remove existings categories from Object if not supplies by $categories , False : let them
* @ return int Return integer < 0 if KO , > 0 if OK
2015-09-30 16:46:51 +00:00
*/
2025-10-31 03:05:45 +00:00
public function setCategories ( $categories , $remove_existing = true )
2015-09-30 16:46:51 +00:00
{
2019-11-08 14:51:54 +00:00
require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php' ;
2025-10-31 03:05:45 +00:00
return parent :: setCategoriesCommon ( $categories , Categorie :: TYPE_CONTACT , $remove_existing );
2015-09-30 16:46:51 +00:00
}
2015-04-18 16:11:01 +00:00
/**
* Function used to replace a thirdparty id with another one .
*
2022-12-28 12:27:13 +00:00
* @ param DoliDB $dbs Database handler , because function is static we name it $dbs not $db to avoid breaking coding test
* @ param int $origin_id Old thirdparty id
* @ param int $dest_id New thirdparty id
* @ return bool
2015-04-18 16:11:01 +00:00
*/
2022-12-28 12:27:13 +00:00
public static function replaceThirdparty ( DoliDB $dbs , $origin_id , $dest_id )
2015-04-18 16:11:01 +00:00
{
$tables = array (
2020-05-18 08:54:25 +00:00
'socpeople' , 'societe_contacts'
2015-04-18 16:11:01 +00:00
);
2022-12-28 12:27:13 +00:00
return CommonObject :: commonReplaceThirdparty ( $dbs , $origin_id , $dest_id , $tables );
2015-04-18 16:11:01 +00:00
}
2019-09-02 12:47:32 +00:00
/**
2021-01-22 09:51:47 +00:00
* Fetch roles ( default contact of some companies ) for the current contact .
* This load the array -> roles .
2019-09-02 12:47:32 +00:00
*
2023-12-06 14:46:39 +00:00
* @ return int Return integer < 0 if KO , Nb of roles found if OK
2021-01-22 12:17:27 +00:00
* @ see updateRoles ()
2019-09-02 12:47:32 +00:00
*/
2019-09-02 20:01:48 +00:00
public function fetchRoles ()
2019-09-02 12:47:32 +00:00
{
global $langs ;
2019-11-08 14:51:54 +00:00
$error = 0 ;
$num = 0 ;
2019-09-02 12:47:32 +00:00
2021-01-22 09:51:47 +00:00
$sql = " SELECT tc.rowid, tc.element, tc.source, tc.code, tc.libelle as label, sc.rowid as contactroleid, sc.fk_soc as socid " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " societe_contacts as sc, " . MAIN_DB_PREFIX . " c_type_contact as tc " ;
$sql .= " WHERE tc.rowid = sc.fk_c_type_contact " ;
2019-11-08 14:51:54 +00:00
$sql .= " AND tc.source = 'external' AND tc.active=1 " ;
2021-08-23 15:41:11 +00:00
$sql .= " AND sc.fk_socpeople = " . (( int ) $this -> id );
2019-11-08 14:51:54 +00:00
$sql .= " AND sc.entity IN ( " . getEntity ( 'societe' ) . ')' ;
2019-09-02 12:47:32 +00:00
2019-11-08 14:51:54 +00:00
$resql = $this -> db -> query ( $sql );
2019-09-02 12:47:32 +00:00
if ( $resql ) {
2021-01-22 12:17:27 +00:00
$this -> roles = array ();
2019-09-02 12:47:32 +00:00
$num = $this -> db -> num_rows ( $resql );
if ( $num > 0 ) {
while ( $obj = $this -> db -> fetch_object ( $resql )) {
2019-11-08 14:51:54 +00:00
$transkey = " TypeContact_ " . $obj -> element . " _ " . $obj -> source . " _ " . $obj -> code ;
2019-09-02 20:01:48 +00:00
$libelle_element = $langs -> trans ( 'ContactDefault_' . $obj -> element );
2024-03-11 16:39:09 +00:00
$this -> roles [ $obj -> contactroleid ] = array ( 'id' => $obj -> rowid , 'socid' => $obj -> socid , 'element' => $obj -> element , 'source' => $obj -> source , 'code' => $obj -> code , 'label' => $libelle_element . ' - ' . ( $langs -> trans ( $transkey ) != $transkey ? $langs -> trans ( $transkey ) : $obj -> label ));
2019-09-02 12:47:32 +00:00
}
}
} else {
$error ++ ;
2019-11-08 14:51:54 +00:00
$this -> error = $this -> db -> lasterror ();
$this -> errors [] = $this -> db -> lasterror ();
2019-09-02 12:47:32 +00:00
}
if ( empty ( $error )) {
return $num ;
} else {
return $error * - 1 ;
}
}
2019-09-03 15:04:42 +00:00
/**
2023-06-23 11:32:43 +00:00
* Get thirdparty contact roles of a given contact
2019-09-03 15:04:42 +00:00
*
2019-10-15 00:54:19 +00:00
* @ param string $element Element type
2025-10-04 12:12:46 +00:00
* @ return array < array { fk_socpeople : int , type_contact : int } >| int <- 1 , - 1 > Array of contact roles or - 1 if error
2019-09-03 15:04:42 +00:00
* @ throws Exception
*/
public function getContactRoles ( $element = '' )
{
2019-11-08 14:51:54 +00:00
$tab = array ();
2019-09-03 15:04:42 +00:00
2020-02-17 11:21:07 +00:00
if ( $element == 'action' ) {
$element = 'agenda' ;
}
2019-09-03 15:04:42 +00:00
$sql = " SELECT sc.fk_socpeople as id, sc.fk_c_type_contact " ;
2019-11-08 14:51:54 +00:00
$sql .= " FROM " . MAIN_DB_PREFIX . " c_type_contact tc " ;
$sql .= " , " . MAIN_DB_PREFIX . " societe_contacts sc " ;
2022-07-19 14:08:38 +00:00
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . " socpeople sp " ;
2022-08-30 14:53:14 +00:00
$sql .= " ON sc.fk_socpeople = sp.rowid AND sp.statut = 1 " ;
2025-10-04 12:12:46 +00:00
$sql .= " WHERE sc.fk_soc = " . (( int ) $this -> socid );
2019-11-08 14:51:54 +00:00
$sql .= " AND sc.fk_c_type_contact=tc.rowid " ;
2021-06-09 13:36:47 +00:00
$sql .= " AND tc.element = ' " . $this -> db -> escape ( $element ) . " ' " ;
2024-01-19 08:22:12 +00:00
$sql .= " AND sp.entity IN ( " . getEntity ( 'contact' ) . " ) " ;
2021-06-09 13:36:47 +00:00
$sql .= " AND tc.active = 1 " ;
2019-09-03 15:04:42 +00:00
2019-11-08 14:51:54 +00:00
$resql = $this -> db -> query ( $sql );
2021-02-23 20:16:15 +00:00
if ( $resql ) {
2019-11-08 14:51:54 +00:00
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
2021-02-23 20:16:15 +00:00
while ( $i < $num ) {
2019-09-03 15:04:42 +00:00
$obj = $this -> db -> fetch_object ( $resql );
2025-10-04 12:12:46 +00:00
$tab [ $obj -> id ] = array ( 'fk_socpeople' => $obj -> id , 'type_contact' => $obj -> fk_c_type_contact );
2019-09-03 15:04:42 +00:00
$i ++ ;
}
return $tab ;
2020-05-21 13:05:19 +00:00
} else {
2019-11-08 14:51:54 +00:00
$this -> error = $this -> db -> error ();
2019-09-03 15:04:42 +00:00
dol_print_error ( $this -> db );
return - 1 ;
}
}
2019-09-02 20:01:48 +00:00
/**
2021-01-22 09:51:47 +00:00
* Updates all roles ( default contact for companies ) according to values inside the -> roles array .
* This is called by update of contact .
2019-09-02 20:01:48 +00:00
*
2023-02-22 12:29:47 +00:00
* @ return int
2021-01-22 12:17:27 +00:00
* @ see fetchRoles ()
2019-09-02 20:01:48 +00:00
*/
public function updateRoles ()
{
global $conf ;
2019-11-08 14:51:54 +00:00
$error = 0 ;
2019-09-02 20:01:48 +00:00
2021-02-23 20:16:15 +00:00
if ( ! isset ( $this -> roles )) {
2023-02-22 12:29:47 +00:00
return 0 ; // Avoid to loose roles when property not set
2021-02-23 20:16:15 +00:00
}
2021-01-22 12:17:27 +00:00
2019-09-02 20:01:48 +00:00
$this -> db -> begin ();
2022-03-18 11:05:59 +00:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " societe_contacts WHERE fk_socpeople= " . (( int ) $this -> id ) . " AND entity IN ( " . getEntity ( " contact " ) . " ) " ;
2019-09-02 20:01:48 +00:00
$result = $this -> db -> query ( $sql );
if ( ! $result ) {
2019-11-08 14:51:54 +00:00
$this -> errors [] = $this -> db -> lasterror () . ' sql=' . $sql ;
2019-09-02 20:01:48 +00:00
$error ++ ;
} else {
2019-11-08 14:51:54 +00:00
if ( count ( $this -> roles ) > 0 ) {
2019-09-02 20:01:48 +00:00
foreach ( $this -> roles as $keyRoles => $valRoles ) {
2024-09-06 11:51:50 +00:00
if ( empty ( $valRoles )) {
continue ;
}
2021-01-22 12:17:27 +00:00
$idrole = 0 ;
2021-01-22 13:10:08 +00:00
if ( is_array ( $valRoles )) {
2021-01-22 12:17:27 +00:00
$idrole = $valRoles [ 'id' ];
} else {
$idrole = $valRoles ;
}
2019-09-02 20:01:48 +00:00
2021-01-22 12:17:27 +00:00
$socid = 0 ;
2021-01-22 13:10:08 +00:00
if ( is_array ( $valRoles )) {
2021-01-22 12:17:27 +00:00
$socid = $valRoles [ 'socid' ];
} else {
$socid = $this -> socid ;
}
if ( $socid > 0 ) {
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " societe_contacts " ;
$sql .= " (entity, " ;
$sql .= " date_creation, " ;
$sql .= " fk_soc, " ;
$sql .= " fk_c_type_contact, " ;
$sql .= " fk_socpeople) " ;
2026-07-23 17:06:39 +00:00
$sql .= " VALUES ( " . (( int ) $conf -> entity ) . " , " ;
2021-01-22 12:17:27 +00:00
$sql .= " ' " . $this -> db -> idate ( dol_now ()) . " ', " ;
2026-07-23 17:06:39 +00:00
$sql .= (( int ) $socid ) . " , " ;
$sql .= (( int ) $idrole ) . " , " ;
$sql .= (( int ) $this -> id );
2021-01-22 12:17:27 +00:00
$sql .= " ) " ;
$result = $this -> db -> query ( $sql );
2021-02-23 20:16:15 +00:00
if ( ! $result ) {
2021-01-22 12:17:27 +00:00
$this -> errors [] = $this -> db -> lasterror () . ' sql=' . $sql ;
$error ++ ;
}
2019-09-02 20:01:48 +00:00
}
}
}
}
if ( empty ( $error )) {
$this -> db -> commit ();
return 1 ;
} else {
2019-11-08 14:51:54 +00:00
$this -> error = implode ( ' ' , $this -> errors );
2019-09-02 20:01:48 +00:00
$this -> db -> rollback ();
2019-11-08 14:51:54 +00:00
return $error * - 1 ;
2019-09-02 20:01:48 +00:00
}
}
2020-04-27 15:35:14 +00:00
/**
* Load array of prospect status
*
* @ param int $active 1 = Active only , 0 = Not active only , - 1 = All
2023-12-01 18:51:32 +00:00
* @ return int Return integer < 0 if KO , > 0 if OK
2020-04-27 15:35:14 +00:00
*/
2020-04-27 16:01:07 +00:00
public function loadCacheOfProspStatus ( $active = 1 )
2020-04-27 15:35:14 +00:00
{
global $langs ;
2020-10-31 13:32:18 +00:00
$sql = " SELECT id, code, libelle as label, picto FROM " . MAIN_DB_PREFIX . " c_stcommcontact " ;
2021-02-23 20:16:15 +00:00
if ( $active >= 0 ) {
2021-03-30 15:53:25 +00:00
$sql .= " WHERE active = " . (( int ) $active );
2021-02-23 20:16:15 +00:00
}
2020-04-27 15:48:05 +00:00
$resql = $this -> db -> query ( $sql );
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
2021-02-23 20:16:15 +00:00
while ( $i < $num ) {
2020-04-27 15:48:05 +00:00
$obj = $this -> db -> fetch_object ( $resql );
2020-10-31 13:32:18 +00:00
$this -> cacheprospectstatus [ $obj -> id ] = array ( 'id' => $obj -> id , 'code' => $obj -> code , 'label' => ( $langs -> trans ( " ST_ " . strtoupper ( $obj -> code )) == " ST_ " . strtoupper ( $obj -> code )) ? $obj -> label : $langs -> trans ( " ST_ " . strtoupper ( $obj -> code )), 'picto' => $obj -> picto );
2020-04-27 15:35:14 +00:00
$i ++ ;
}
return 1 ;
}
/**
2023-10-07 05:21:49 +00:00
* Return prospect level
2020-04-27 15:35:14 +00:00
*
2023-10-07 05:21:49 +00:00
* @ return string Label
2020-04-27 15:35:14 +00:00
*/
2020-04-27 16:01:07 +00:00
public function getLibProspLevel ()
2020-04-27 15:35:14 +00:00
{
2020-04-27 16:06:50 +00:00
return $this -> libProspLevel ( $this -> fk_prospectlevel );
2020-04-27 15:35:14 +00:00
}
/**
* Return label of prospect level
*
2024-01-19 15:22:16 +00:00
* @ param string $fk_prospectlevel Prospect level
2020-04-27 15:35:14 +00:00
* @ return string label of level
*/
2020-04-27 16:06:50 +00:00
public function libProspLevel ( $fk_prospectlevel )
2020-04-27 15:35:14 +00:00
{
global $langs ;
2020-10-31 13:32:18 +00:00
$lib = $langs -> trans ( " ProspectLevel " . $fk_prospectlevel );
2024-01-14 11:26:37 +00:00
// If lib not found in language file, we get label from cache/database
2024-01-19 15:22:16 +00:00
if ( $lib == " ProspectLevel " . $fk_prospectlevel ) {
2020-04-27 15:48:05 +00:00
$lib = $langs -> getLabelFromKey ( $this -> db , $fk_prospectlevel , 'c_prospectlevel' , 'code' , 'label' );
2020-04-27 15:35:14 +00:00
}
return $lib ;
}
/**
* Set prospect level
*
2023-10-07 05:21:49 +00:00
* @ param User $user User who defines the discount
2023-12-01 18:51:32 +00:00
* @ return int Return integer < 0 if KO , > 0 if OK
2020-04-27 15:35:14 +00:00
* @ deprecated Use update function instead
*/
2020-04-27 16:01:07 +00:00
public function setProspectLevel ( User $user )
2020-04-27 15:35:14 +00:00
{
return $this -> update ( $this -> id , $user );
}
/**
* Return status of prospect
*
2023-04-08 13:08:55 +00:00
* @ param int $mode 0 = label long , 1 = label short , 2 = Picto + Label short , 3 = Picto , 4 = Picto + Label long
2020-04-27 15:35:14 +00:00
* @ param string $label Label to use for status for added status
2023-04-08 13:08:55 +00:00
* @ return string Label
2020-04-27 15:35:14 +00:00
*/
2020-04-27 16:01:07 +00:00
public function getLibProspCommStatut ( $mode = 0 , $label = '' )
2020-04-27 15:35:14 +00:00
{
2020-04-27 16:01:07 +00:00
return $this -> libProspCommStatut ( $this -> stcomm_id , $mode , $label , $this -> stcomm_picto );
2020-04-27 15:35:14 +00:00
}
/**
* Return label of a given status
*
* @ param int | string $statut Id or code for prospection status
* @ param int $mode 0 = long label , 1 = short label , 2 = Picto + short label , 3 = Picto , 4 = Picto + long label , 5 = Short label + Picto
* @ param string $label Label to use for status for added status
* @ param string $picto Name of image file to show ( 'filenew' , ... )
2020-04-27 16:01:07 +00:00
* If no extension provided , we use '.png' . Image must be stored into theme / xxx / img directory .
* Example : picto . png if picto . png is stored into htdocs / theme / mytheme / img
* Example : picto . png @ mymodule if picto . png is stored into htdocs / mymodule / img
* Example : / mydir / mysubdir / picto . png if picto . png is stored into htdocs / mydir / mysubdir ( pictoisfullpath must be set to 1 )
2023-04-08 13:08:55 +00:00
* @ return string Label of status
2020-04-27 15:35:14 +00:00
*/
2020-04-27 16:01:07 +00:00
public function libProspCommStatut ( $statut , $mode = 0 , $label = '' , $picto = '' )
2020-04-27 15:35:14 +00:00
{
global $langs ;
$langs -> load ( 'customers' );
2021-02-23 20:16:15 +00:00
if ( $mode == 2 ) {
if ( $statut == '-1' || $statut == 'ST_NO' ) {
2024-09-05 14:05:37 +00:00
return img_action ( $langs -> trans ( " StatusProspect-1 " ), '-1' , $picto ) . ' ' . $langs -> trans ( " StatusProspect-1 " );
2021-02-23 20:16:15 +00:00
} elseif ( $statut == '0' || $statut == 'ST_NEVER' ) {
2024-09-05 14:05:37 +00:00
return img_action ( $langs -> trans ( " StatusProspect0 " ), '0' , $picto ) . ' ' . $langs -> trans ( " StatusProspect0 " );
2021-02-23 20:16:15 +00:00
} elseif ( $statut == '1' || $statut == 'ST_TODO' ) {
2024-09-05 14:05:37 +00:00
return img_action ( $langs -> trans ( " StatusProspect1 " ), '1' , $picto ) . ' ' . $langs -> trans ( " StatusProspect1 " );
2021-02-23 20:16:15 +00:00
} elseif ( $statut == '2' || $statut == 'ST_PEND' ) {
2024-09-05 14:05:37 +00:00
return img_action ( $langs -> trans ( " StatusProspect2 " ), '2' , $picto ) . ' ' . $langs -> trans ( " StatusProspect2 " );
2021-02-23 20:16:15 +00:00
} elseif ( $statut == '3' || $statut == 'ST_DONE' ) {
2024-09-05 14:05:37 +00:00
return img_action ( $langs -> trans ( " StatusProspect3 " ), '3' , $picto ) . ' ' . $langs -> trans ( " StatusProspect3 " );
2021-02-23 20:16:15 +00:00
} else {
2024-09-05 14:05:37 +00:00
return img_action (( $langs -> trans ( " StatusProspect " . $statut ) != " StatusProspect " . $statut ) ? $langs -> trans ( " StatusProspect " . $statut ) : $label , '0' , $picto ) . ' ' . (( $langs -> trans ( " StatusProspect " . $statut ) != " StatusProspect " . $statut ) ? $langs -> trans ( " StatusProspect " . $statut ) : $label );
2020-04-27 15:35:14 +00:00
}
}
2021-02-23 20:16:15 +00:00
if ( $mode == 3 ) {
if ( $statut == '-1' || $statut == 'ST_NO' ) {
2024-09-05 14:05:37 +00:00
return img_action ( $langs -> trans ( " StatusProspect-1 " ), '-1' , $picto );
2021-02-23 20:16:15 +00:00
} elseif ( $statut == '0' || $statut == 'ST_NEVER' ) {
2024-09-05 14:05:37 +00:00
return img_action ( $langs -> trans ( " StatusProspect0 " ), '0' , $picto );
2021-02-23 20:16:15 +00:00
} elseif ( $statut == '1' || $statut == 'ST_TODO' ) {
2024-09-05 14:05:37 +00:00
return img_action ( $langs -> trans ( " StatusProspect1 " ), '1' , $picto );
2021-02-23 20:16:15 +00:00
} elseif ( $statut == '2' || $statut == 'ST_PEND' ) {
2024-09-05 14:05:37 +00:00
return img_action ( $langs -> trans ( " StatusProspect2 " ), '2' , $picto );
2021-02-23 20:16:15 +00:00
} elseif ( $statut == '3' || $statut == 'ST_DONE' ) {
2024-09-05 14:05:37 +00:00
return img_action ( $langs -> trans ( " StatusProspect3 " ), '3' , $picto );
2021-02-23 20:16:15 +00:00
} else {
2024-09-05 14:05:37 +00:00
return img_action (( $langs -> trans ( " StatusProspect " . $statut ) != " StatusProspect " . $statut ) ? $langs -> trans ( " StatusProspect " . $statut ) : $label , '0' , $picto );
2020-04-27 15:35:14 +00:00
}
}
2021-02-23 20:16:15 +00:00
if ( $mode == 4 ) {
if ( $statut == '-1' || $statut == 'ST_NO' ) {
2024-09-05 14:05:37 +00:00
return img_action ( $langs -> trans ( " StatusProspect-1 " ), '-1' , $picto ) . ' ' . $langs -> trans ( " StatusProspect-1 " );
2021-02-23 20:16:15 +00:00
} elseif ( $statut == '0' || $statut == 'ST_NEVER' ) {
2024-09-05 14:05:37 +00:00
return img_action ( $langs -> trans ( " StatusProspect0 " ), '0' , $picto ) . ' ' . $langs -> trans ( " StatusProspect0 " );
2021-02-23 20:16:15 +00:00
} elseif ( $statut == '1' || $statut == 'ST_TODO' ) {
2024-09-05 14:05:37 +00:00
return img_action ( $langs -> trans ( " StatusProspect1 " ), '1' , $picto ) . ' ' . $langs -> trans ( " StatusProspect1 " );
2021-02-23 20:16:15 +00:00
} elseif ( $statut == '2' || $statut == 'ST_PEND' ) {
2024-09-05 14:05:37 +00:00
return img_action ( $langs -> trans ( " StatusProspect2 " ), '2' , $picto ) . ' ' . $langs -> trans ( " StatusProspect2 " );
2021-02-23 20:16:15 +00:00
} elseif ( $statut == '3' || $statut == 'ST_DONE' ) {
2024-09-05 14:05:37 +00:00
return img_action ( $langs -> trans ( " StatusProspect3 " ), '3' , $picto ) . ' ' . $langs -> trans ( " StatusProspect3 " );
2021-02-23 20:16:15 +00:00
} else {
2024-09-05 14:05:37 +00:00
return img_action (( $langs -> trans ( " StatusProspect " . $statut ) != " StatusProspect " . $statut ) ? $langs -> trans ( " StatusProspect " . $statut ) : $label , '0' , $picto ) . ' ' . (( $langs -> trans ( " StatusProspect " . $statut ) != " StatusProspect " . $statut ) ? $langs -> trans ( " StatusProspect " . $statut ) : $label );
2020-04-27 15:35:14 +00:00
}
}
return " Error, mode/status not found " ;
}
2021-01-07 16:23:02 +00:00
/**
* Set " blacklist " mailing status
*
2023-10-07 05:21:49 +00:00
* @ param int $no_email 1 = Do not send mailing , 0 = Ok to receive mailing
2023-12-01 18:51:32 +00:00
* @ return int Return integer < 0 if KO , > 0 if OK
2021-01-07 16:23:02 +00:00
*/
public function setNoEmail ( $no_email )
{
$error = 0 ;
// Update mass emailing flag into table mailing_unsubscribe
2021-02-23 20:16:15 +00:00
if ( $this -> email ) {
2021-01-07 16:23:02 +00:00
$this -> db -> begin ();
2021-02-23 20:16:15 +00:00
if ( $no_email ) {
2021-01-07 16:23:02 +00:00
$sql = " SELECT COUNT(rowid) as nb FROM " . MAIN_DB_PREFIX . " mailing_unsubscribe WHERE entity IN ( " . getEntity ( 'mailing' , 0 ) . " ) AND email = ' " . $this -> db -> escape ( $this -> email ) . " ' " ;
$resql = $this -> db -> query ( $sql );
2021-02-23 20:16:15 +00:00
if ( $resql ) {
2021-01-07 16:23:02 +00:00
$obj = $this -> db -> fetch_object ( $resql );
$noemail = $obj -> nb ;
2021-02-23 20:16:15 +00:00
if ( empty ( $noemail )) {
2021-08-23 15:41:11 +00:00
$sql = " INSERT INTO " . MAIN_DB_PREFIX . " mailing_unsubscribe(email, entity, date_creat) VALUES (' " . $this -> db -> escape ( $this -> email ) . " ', " . getEntity ( 'mailing' , 0 ) . " , ' " . $this -> db -> idate ( dol_now ()) . " ') " ;
2021-01-07 16:23:02 +00:00
$resql = $this -> db -> query ( $sql );
2021-02-23 20:16:15 +00:00
if ( ! $resql ) {
2021-01-07 16:23:02 +00:00
$error ++ ;
$this -> error = $this -> db -> lasterror ();
$this -> errors [] = $this -> error ;
}
}
} else {
$error ++ ;
$this -> error = $this -> db -> lasterror ();
$this -> errors [] = $this -> error ;
}
} else {
2021-08-23 15:41:11 +00:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " mailing_unsubscribe WHERE email = ' " . $this -> db -> escape ( $this -> email ) . " ' AND entity IN ( " . getEntity ( 'mailing' , 0 ) . " ) " ;
2021-01-07 16:23:02 +00:00
$resql = $this -> db -> query ( $sql );
2021-02-23 20:16:15 +00:00
if ( ! $resql ) {
2021-01-07 16:23:02 +00:00
$error ++ ;
$this -> error = $this -> db -> lasterror ();
$this -> errors [] = $this -> error ;
}
}
if ( empty ( $error )) {
$this -> no_email = $no_email ;
$this -> db -> commit ();
return 1 ;
} else {
$this -> db -> rollback ();
return $error * - 1 ;
}
}
return 0 ;
}
/**
* get " blacklist " mailing status
2024-01-14 11:26:37 +00:00
* set no_email attribute to 1 or 0
2021-01-07 16:23:02 +00:00
*
2023-12-01 18:51:32 +00:00
* @ return int Return integer < 0 if KO , > 0 if OK
2021-01-07 16:23:02 +00:00
*/
public function getNoEmail ()
{
2021-02-23 20:16:15 +00:00
if ( $this -> email ) {
2021-01-07 16:23:02 +00:00
$sql = " SELECT COUNT(rowid) as nb FROM " . MAIN_DB_PREFIX . " mailing_unsubscribe WHERE entity IN ( " . getEntity ( 'mailing' ) . " ) AND email = ' " . $this -> db -> escape ( $this -> email ) . " ' " ;
$resql = $this -> db -> query ( $sql );
2021-01-16 13:24:47 +00:00
if ( $resql ) {
2021-01-07 16:23:02 +00:00
$obj = $this -> db -> fetch_object ( $resql );
$this -> no_email = $obj -> nb ;
return 1 ;
} else {
$this -> error = $this -> db -> lasterror ();
$this -> errors [] = $this -> error ;
return - 1 ;
}
}
return 0 ;
}
2022-12-20 12:35:53 +00:00
/**
2023-10-07 05:21:49 +00:00
* Return clickable link of object ( with eventually picto )
2022-12-20 12:35:53 +00:00
*
2024-08-22 01:31:04 +00:00
* @ param string $option Where point the link ( 0 => main card , 1 , 2 => shipment , 'nolink' => No link )
2025-02-03 10:24:16 +00:00
* @ param ? array < string , mixed > $arraydata Array of data
2024-08-22 01:31:04 +00:00
* @ return string HTML Code for Kanban thumb .
2022-12-20 12:35:53 +00:00
*/
2023-01-18 21:27:52 +00:00
public function getKanbanView ( $option = '' , $arraydata = null )
2022-12-20 12:35:53 +00:00
{
2023-03-07 21:04:40 +00:00
$selected = ( empty ( $arraydata [ 'selected' ]) ? 0 : $arraydata [ 'selected' ]);
2022-12-20 12:35:53 +00:00
$return = '<div class="box-flex-item box-flex-grow-zero">' ;
$return .= '<div class="info-box info-box-sm">' ;
$return .= '<span class="info-box-icon bg-infobox-action">' ;
2025-09-11 10:14:53 +00:00
if ( ! is_null ( $this -> photo )) {
2024-03-11 16:39:09 +00:00
$return .= Form :: showphoto ( 'contact' , $this , 0 , 60 , 0 , 'photokanban photoref photowithmargin photologintooltip' , 'small' , 0 , 1 );
2022-12-20 12:35:53 +00:00
} else {
$return .= img_picto ( '' , $this -> picto );
}
$return .= '</span>' ;
$return .= '<div class="info-box-content">' ;
2025-09-11 10:14:53 +00:00
$return .= '<div class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . $this -> getNomUrl ( 0 ) . '</div>' ;
2023-10-17 13:43:56 +00:00
if ( $selected >= 0 ) {
$return .= '<input id="cb' . $this -> id . '" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="' . $this -> id . '"' . ( $selected ? ' checked="checked"' : '' ) . '>' ;
}
2025-09-11 10:14:53 +00:00
if ( is_object ( $this -> thirdparty )) {
2023-07-31 19:52:58 +00:00
$return .= '<div class="info-box-ref tdoverflowmax150">' . $this -> thirdparty -> getNomUrl ( 1 ) . '</div>' ;
2022-12-27 00:02:58 +00:00
}
/* if ( property_exists ( $this , 'phone_pro' ) && ! empty ( $this -> phone_pro )) {
$return .= '<br>' . img_picto ( $langs -> trans ( " Phone " ), 'phone' );
$return .= ' <span class="info-box-label">' . $this -> phone_pro . '</span>' ;
} */
/* if ( method_exists ( $this , 'LibPubPriv' )) {
2022-12-20 12:35:53 +00:00
$return .= '<br><span class="info-box-label opacitymedium">' . $langs -> trans ( " Visibility " ) . '</span>' ;
$return .= '<span> : ' . $this -> LibPubPriv ( $this -> priv ) . '</span>' ;
2022-12-27 00:02:58 +00:00
} */
2025-09-11 10:14:53 +00:00
$return .= '<br><div class="info-box-status">' . $this -> getLibStatut ( 3 ) . '</div>' ;
2022-12-20 12:35:53 +00:00
$return .= '</div>' ;
$return .= '</div>' ;
$return .= '</div>' ;
return $return ;
}
2006-02-24 23:16:35 +00:00
}