36require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
37require_once DOL_DOCUMENT_ROOT.
'/core/class/commonsocialnetworks.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/core/class/commonpeople.class.php';
53 public $TRIGGER_PREFIX =
'CONTACT';
62 const MERGE_FIELDS_FILL_IF_EMPTY = array(
63 'civility_code',
'lastname',
'firstname',
'name_alias',
'address',
'zip',
'town',
64 'state_id',
'country_id',
'poste',
'phone_pro',
'phone_perso',
'phone_mobile',
'fax',
65 'email',
'socialnetworks',
'birthday',
'default_lang',
'ref_ext',
66 'fk_prospectlevel',
'stcomm_id',
'socid'
72 const MERGE_FIELDS_CONCAT = array(
'note_public',
'note_private');
78 const MERGE_MAX_PARENT_DEPTH = 100;
83 public $element =
'contact';
88 public $table_element =
'socpeople';
93 public $picto =
'contact';
124 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -2,
'noteditable' => 1,
'notnull' => 1,
'index' => 1,
'position' => 1,
'comment' =>
'Id',
'css' =>
'left'),
125 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => 3,
'notnull' => 1,
'position' => 30,
'index' => 1),
126 'ref_ext' => array(
'type' =>
'varchar(255)',
'label' =>
'RefExt',
'enabled' => 1,
'visible' => 0,
'position' => 35),
127 'civility' => array(
'type' =>
'varchar(6)',
'label' =>
'Civility',
'enabled' => 1,
'visible' => 3,
'position' => 40),
128 'lastname' => array(
'type' =>
'varchar(50)',
'label' =>
'Lastname',
'enabled' => 1,
'visible' => 1,
'position' => 45,
'showoncombobox' => 1,
'searchall' => 1),
130 'firstname' => array(
'type' =>
'varchar(50)',
'label' =>
'Firstname',
'enabled' => 1,
'visible' => 1,
'position' => 50,
'showoncombobox' => 1,
'searchall' => 1),
131 'poste' => array(
'type' =>
'varchar(80)',
'label' =>
'PostOrFunction',
'enabled' => 1,
'visible' => -1,
'position' => 52),
132 'address' => array(
'type' =>
'varchar(255)',
'label' =>
'Address',
'enabled' => 1,
'visible' => -1,
'position' => 55),
133 'zip' => array(
'type' =>
'varchar(25)',
'label' =>
'Zip',
'enabled' => 1,
'visible' => -1,
'position' => 60),
134 'town' => array(
'type' =>
'varchar(50)',
'label' =>
'Town',
'enabled' => 1,
'visible' => -1,
'position' => 65),
135 'fk_departement' => array(
'type' =>
'integer',
'label' =>
'State',
'enabled' => 1,
'visible' => 3,
'position' => 70),
136 'fk_pays' => array(
'type' =>
'integer',
'label' =>
'Country',
'enabled' => 1,
'visible' => 3,
'position' => 75),
137 'fk_soc' => array(
'type' =>
'integer:Societe:societe/class/societe.class.php',
'label' =>
'ThirdParty',
'enabled' => 1,
'visible' => 1,
'position' => 77,
'searchall' => 1),
138 'birthday' => array(
'type' =>
'date',
'label' =>
'Birthday',
'enabled' => 1,
'visible' => -1,
'position' => 80),
139 'phone' => array(
'type' =>
'varchar(30)',
'label' =>
'Phone',
'enabled' => 1,
'visible' => 1,
'position' => 90,
'searchall' => 1),
140 'phone_perso' => array(
'type' =>
'varchar(30)',
'label' =>
'PhonePerso',
'enabled' => 1,
'visible' => -1,
'position' => 95,
'searchall' => 1),
141 'phone_mobile' => array(
'type' =>
'varchar(30)',
'label' =>
'PhoneMobile',
'enabled' => 1,
'visible' => 1,
'position' => 100,
'searchall' => 1),
142 'fax' => array(
'type' =>
'varchar(30)',
'label' =>
'Fax',
'enabled' => 1,
'visible' => -1,
'position' => 105,
'searchall' => 1),
143 'email' => array(
'type' =>
'varchar(255)',
'label' =>
'Email',
'enabled' => 1,
'visible' => 1,
'position' => 110,
'searchall' => 1),
144 'socialnetworks' => array(
'type' =>
'text',
'label' =>
'SocialNetworks',
'enabled' => 1,
'visible' => 3,
'position' => 115),
145 'photo' => array(
'type' =>
'varchar(255)',
'label' =>
'Photo',
'enabled' => 1,
'visible' => 3,
'position' => 170),
146 'priv' => array(
'type' =>
'smallint(6)',
'label' =>
'ContactVisibility',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'position' => 175),
147 'fk_stcommcontact' => array(
'type' =>
'integer',
'label' =>
'ProspectStatus',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 220),
148 'fk_prospectcontactlevel' => array(
'type' =>
'varchar(12)',
'label' =>
'ProspectLevel',
'enabled' => 1,
'visible' => -1,
'position' => 255),
150 'note_private' => array(
'type' =>
'html',
'label' =>
'NotePrivate',
'enabled' => 1,
'visible' => 0,
'position' => 195,
'searchall' => 1),
151 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 0,
'position' => 200,
'searchall' => 1),
152 'default_lang' => array(
'type' =>
'varchar(6)',
'label' =>
'Default lang',
'enabled' => 1,
'visible' => 3,
'position' => 205),
153 'canvas' => array(
'type' =>
'varchar(32)',
'label' =>
'Canvas',
'enabled' => 1,
'visible' => 3,
'position' => 210),
154 'ip' => array(
'type' =>
'ip',
'label' =>
'IPAddress',
'enabled' =>
'1',
'position' => 700,
'notnull' => 0,
'visible' =>
'-2',
'comment' =>
'ip used to create record (for public submission page)'),
155 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -1,
'position' => 300),
156 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 305),
157 'fk_user_creat' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserAuthor',
'enabled' => 1,
'visible' => 3,
'position' => 310),
158 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => 3,
'position' => 315),
159 'statut' => array(
'type' =>
'tinyint(4)',
'label' =>
'Status',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'position' => 500),
160 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -1,
'position' => 1000),
170 public $civility_code;
184 public $birthday_alert;
294 public $socialnetworks;
314 public $phone_mobile;
335 public $default_lang;
340 public $ref_facturation;
350 public $ref_commande;
381 public $cacheprospectstatus = array();
386 public $fk_prospectlevel;
396 public $statut_commercial;
401 public $stcomm_picto;
414 $this->ismultientitymanaged = 1;
415 $this->isextrafieldmanaged = 1;
417 $this->fields[
'ref_ext'][
'visible'] =
getDolGlobalInt(
'MAIN_LIST_SHOW_REF_EXT');
420 $this->fields[
'no_email'][
'enabled'] = 0;
424 $this->fields[
'fk_soc'][
'enabled'] = 0;
425 $this->fields[
'fk_soc'][
'searchall'] = 0;
430 $this->fields[
'fk_stcommcontact'][
'enabled'] = 0;
431 $this->fields[
'fk_prospectcontactlevel'][
'enabled'] = 0;
435 foreach ($this->fields as $key => $val) {
436 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
437 unset($this->fields[$key]);
460 global $user, $hookmanager;
465 $sql =
"SELECT count(sp.rowid) as nb";
466 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as sp";
467 if (!$user->hasRight(
'societe',
'client',
'voir')) {
468 $sql .=
", ".MAIN_DB_PREFIX.
"societe as s";
469 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
470 $sql .=
" WHERE sp.fk_soc = s.rowid AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
473 $sql .=
" ".$clause.
" sp.entity IN (".
getEntity($this->element).
")";
474 $sql .=
" AND (sp.priv='0' OR (sp.priv='1' AND sp.fk_user_creat = ".((int) $user->id).
"))";
475 if ($user->socid > 0) {
476 $sql .=
" AND sp.fk_soc = ".((int) $user->socid);
479 if (is_object($hookmanager)) {
480 $parameters = array();
481 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $this);
482 $sql .= $hookmanager->resPrint;
485 $resql = $this->db->query($sql);
487 while ($obj = $this->db->fetch_object($resql)) {
488 $this->nb[
"contacts"] = $obj->nb;
490 $this->db->free($resql);
493 dol_print_error($this->db);
494 $this->error = $this->db->lasterror();
506 public function create($user, $notrigger = 0)
511 if (empty($this->date_creation)) {
512 $this->date_creation = $now;
518 $this->name_alias = trim((
string) $this->name_alias);
519 $this->lastname = $this->lastname ? trim((
string) $this->lastname) : trim((
string) $this->
name);
520 $this->firstname = trim((
string) $this->firstname);
522 if (empty($this->socid)) {
525 if (empty($this->priv)) {
528 if (!empty($this->statut) && empty($this->
status)) {
531 if (empty($this->
status)) {
539 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"socpeople (";
542 $sql .=
", name_alias";
543 $sql .=
", lastname";
544 $sql .=
", firstname";
545 $sql .=
", fk_user_creat";
547 $sql .=
", fk_stcommcontact";
552 $sql .=
", import_key";
554 $sql .=
") VALUES (";
555 $sql .=
"'".$this->db->idate($now).
"',";
556 if ($this->socid > 0) {
557 $sql .=
" ".((int) $this->socid).
",";
561 $sql .=
"'".$this->db->escape($this->name_alias).
"',";
562 $sql .=
"'".$this->db->escape($this->lastname).
"',";
563 $sql .=
"'".$this->db->escape($this->firstname).
"',";
564 $sql .=
" ".($user->id > 0 ? ((int) $user->id) :
"null").
",";
565 $sql .=
" ".((int) $this->priv).
",";
567 $sql .=
" ".((int) $this->
status).
",";
568 $sql .=
" ".(!empty($this->canvas) ?
"'".$this->db->escape($this->canvas).
"'" :
"null").
",";
569 $sql .=
" ".((int) $this->entity).
",";
570 $sql .=
"'".$this->db->escape((
string) $this->ref_ext).
"',";
571 $sql .=
" ".(!empty($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null").
",";
572 $sql .=
" ".(!empty($this->ip) ?
"'".$this->db->escape($this->ip).
"'" :
"null");
575 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
576 $resql = $this->db->query($sql);
578 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"socpeople");
580 $result = $this->
update($this->
id, $user, 1,
'add');
583 $this->error = $this->db->lasterror();
590 $this->error = $this->db->lasterror();
594 if (!$error && !$notrigger) {
596 $result = $this->call_trigger(
'CONTACT_CREATE', $user);
607 $this->db->rollback();
608 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
612 $this->error = $this->db->lasterror();
614 $this->db->rollback();
615 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
630 public function update($id, $user =
null, $notrigger = 0, $action =
'update', $nosyncuser = 0)
634 if (empty($this->country_id) && !empty($this->country_code)) {
635 $country_id =
getCountry($this->country_code,
'3');
636 $this->country_id = is_int($country_id) ? $country_id : 0;
643 $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity :
$conf->entity);
646 $this->ref_ext = (empty($this->ref_ext) ?
'' : trim((
string) $this->ref_ext));
647 $this->name_alias = trim((
string) $this->name_alias);
648 $this->lastname = $this->lastname ? trim((
string) $this->lastname) : trim((
string) $this->
name);
649 $this->firstname = trim((
string) $this->firstname);
651 $this->phone_pro = trim((
string) $this->phone_pro);
652 $this->phone_perso = trim((
string) $this->phone_perso);
653 $this->phone_mobile = trim((
string) $this->phone_mobile);
654 $this->photo = trim((
string) $this->photo);
655 $this->fax = trim((
string) $this->fax);
656 $this->zip = (empty($this->zip) ?
'' : trim((
string) $this->zip));
657 $this->town = (empty($this->town) ?
'' : trim((
string) $this->town));
658 $this->country_id = (empty($this->country_id) || $this->country_id < 0) ? 0 : $this->country_id;
659 if (!empty($this->statut) && empty($this->
status)) {
662 if (empty($this->
status)) {
666 if (empty($this->civility_code) && !is_numeric($this->civility_id)) {
667 $this->civility_code = $this->civility_id;
673 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"socpeople SET";
674 if ($this->socid > 0) {
675 $sql .=
" fk_soc = ".((int) $this->socid).
",";
676 } elseif ($this->socid == -1) {
677 $sql .=
" fk_soc = NULL,";
679 $sql .=
" civility='".$this->db->escape($this->civility_code).
"'";
680 $sql .=
", name_alias='".$this->db->escape($this->name_alias).
"'";
681 $sql .=
", lastname='".$this->db->escape($this->lastname).
"'";
682 $sql .=
", firstname='".$this->db->escape($this->firstname).
"'";
683 $sql .=
", address='".$this->db->escape((
string) $this->
address).
"'";
684 $sql .=
", zip='".$this->db->escape($this->zip).
"'";
685 $sql .=
", town='".$this->db->escape($this->town).
"'";
686 $sql .=
", ref_ext = ".(!empty($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"NULL");
687 $sql .=
", fk_pays=".($this->country_id > 0 ? ((int) $this->country_id) :
'NULL');
688 $sql .=
", fk_departement=".($this->state_id > 0 ? ((int) $this->state_id) :
'NULL');
689 $sql .=
", poste='".$this->db->escape($this->poste).
"'";
690 $sql .=
", fax='".$this->db->escape($this->fax).
"'";
691 $sql .=
", email='".$this->db->escape($this->
email).
"'";
692 $sql .=
", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
693 $sql .=
", photo='".$this->db->escape($this->photo).
"'";
694 $sql .=
", birthday=".($this->birthday ?
"'".$this->db->idate($this->birthday).
"'" :
"null");
695 $sql .=
", note_private = ".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"NULL");
696 $sql .=
", note_public = ".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"NULL");
697 $sql .=
", phone = ".(isset($this->phone_pro) ?
"'".$this->db->escape($this->phone_pro).
"'" :
"NULL");
698 $sql .=
", phone_perso = ".(isset($this->phone_perso) ?
"'".$this->db->escape($this->phone_perso).
"'" :
"NULL");
699 $sql .=
", phone_mobile = ".(isset($this->phone_mobile) ?
"'".$this->db->escape($this->phone_mobile).
"'" :
"NULL");
700 $sql .=
", priv = ".((int) $this->priv);
701 $sql .=
", fk_prospectlevel = '".$this->db->escape($this->fk_prospectlevel).
"'";
702 if (isset($this->stcomm_id)) {
703 $sql .=
", fk_stcommcontact = ".($this->stcomm_id > 0 || $this->stcomm_id == -1 ? ((int) $this->stcomm_id) :
"0");
705 $sql .=
", statut = ".((int) $this->
status);
706 $sql .=
", fk_user_modif=".($user->id > 0 ?
"'".$this->db->escape((
string) $user->id).
"'" :
"NULL");
707 $sql .=
", default_lang=".($this->default_lang ?
"'".$this->db->escape($this->default_lang).
"'" :
"NULL");
708 $sql .=
", entity = ".((int) $this->entity);
709 $sql .=
" WHERE rowid = ".((int) $id);
711 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
712 $result = $this->db->query($sql);
714 unset($this->country_code);
715 unset($this->country);
716 unset($this->state_code);
734 if (!$error && $this->user_id > 0 && !$nosyncuser) {
736 $tmpobj =
new User($this->db);
737 $tmpobj->fetch($this->user_id);
738 $usermustbemodified = 0;
739 if ($tmpobj->office_phone != $this->phone_pro) {
740 $tmpobj->office_phone = $this->phone_pro;
741 $usermustbemodified++;
743 if ($tmpobj->office_fax != $this->fax) {
744 $tmpobj->office_fax = $this->fax;
745 $usermustbemodified++;
747 if ($tmpobj->address != $this->address) {
748 $tmpobj->address = $this->address;
749 $usermustbemodified++;
751 if ($tmpobj->town != $this->town) {
752 $tmpobj->town = $this->town;
753 $usermustbemodified++;
755 if ($tmpobj->zip != $this->zip) {
756 $tmpobj->zip = $this->zip;
757 $usermustbemodified++;
759 if ($tmpobj->state_id != $this->state_id) {
760 $tmpobj->state_id = $this->state_id;
761 $usermustbemodified++;
763 if ($tmpobj->country_id != $this->country_id) {
764 $tmpobj->country_id = $this->country_id;
765 $usermustbemodified++;
767 if ($tmpobj->email != $this->email) {
768 $tmpobj->email = $this->email;
769 $usermustbemodified++;
771 $usersocialnetworks = (is_array($tmpobj->socialnetworks) ? $tmpobj->socialnetworks : array());
772 $contactsocialnetworks = (is_array($this->socialnetworks) ? $this->socialnetworks : array());
774 if (!empty(array_diff_assoc($usersocialnetworks, $contactsocialnetworks)) || !empty(array_diff_assoc($contactsocialnetworks, $usersocialnetworks))) {
775 $tmpobj->socialnetworks = $this->socialnetworks;
776 $usermustbemodified++;
778 if ($usermustbemodified) {
779 $result = $tmpobj->update($user, 0, 1, 1, 1);
786 if (!$error && !$notrigger) {
788 $result = $this->call_trigger(
'CONTACT_MODIFY', $user);
799 dol_syslog(get_class($this).
"::update Error ".$this->error, LOG_ERR);
800 $this->db->rollback();
804 $this->error = $this->db->lasterror().
' sql='.$sql;
805 $this->db->rollback();
829 } elseif ($mode == 1) {
831 } elseif ($mode == 2) {
848 global
$conf, $langs;
869 $info[
"title"] = $this->poste;
871 if ($this->socid > 0) {
873 $soc->fetch($this->socid);
876 if ($soc->client == 1) {
877 $info[
"businessCategory"] =
"Customers";
879 if ($soc->client == 2) {
880 $info[
"businessCategory"] =
"Prospects";
882 if ($soc->fournisseur == 1) {
883 $info[
"businessCategory"] =
"Suppliers";
918 $info[
"objectclass"][4] =
"phpgwContact";
920 $info[
'uidnumber'] = $this->id;
922 $info[
'phpgwTz'] = 0;
923 $info[
'phpgwMailType'] =
'INTERNET';
924 $info[
'phpgwMailHomeType'] =
'INTERNET';
926 $info[
"phpgwContactTypeId"] =
'n';
927 $info[
"phpgwContactCatId"] = 0;
928 $info[
"phpgwContactAccess"] =
"public";
930 $info[
"phpgwContactOwner"] = 1;
933 $info[
"rfc822Mailbox"] = $this->email;
935 if ($this->phone_mobile) {
936 $info[
"phpgwCellTelephoneNumber"] = $this->phone_mobile;
962 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"socpeople SET";
963 $sql .=
" birthday = ".($this->birthday ?
"'".$this->db->idate($this->birthday).
"'" :
"null");
964 $sql .=
", photo = ".($this->photo ?
"'".$this->db->escape($this->photo).
"'" :
"null");
966 $sql .=
", fk_user_modif = ".((int) $user->id);
968 $sql .=
" WHERE rowid = ".((int) $id);
970 dol_syslog(get_class($this).
"::update_perso this->birthday=".$this->birthday.
" -", LOG_DEBUG);
971 $resql = $this->db->query($sql);
974 $this->error = $this->db->lasterror();
979 if (!empty($this->birthday_alert)) {
981 $sql_check =
"SELECT rowid FROM " . MAIN_DB_PREFIX .
"user_alert WHERE type = 1 AND fk_contact = " . ((int) $id) .
" AND fk_user = " . ((int) $user->id);
982 $result_check = $this->db->query($sql_check);
983 if (!$result_check || ($this->db->num_rows($result_check) < 1)) {
985 $sql =
"INSERT INTO " . MAIN_DB_PREFIX .
"user_alert(type, fk_contact, fk_user) ";
986 $sql .=
"VALUES (1," . ((int) $id) .
"," . ((int) $user->id) .
")";
987 $result = $this->db->query($sql);
990 $this->error = $this->db->lasterror();
996 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"user_alert ";
997 $sql .=
"WHERE type=1 AND fk_contact=" . ((int) $id) .
" AND fk_user=" . ((int) $user->id);
998 $result = $this->db->query($sql);
1001 $this->error = $this->db->lasterror();
1005 if (!$error && !$notrigger) {
1007 $result = $this->call_trigger(
'CONTACT_MODIFY', $user);
1016 $this->db->commit();
1019 dol_syslog(get_class($this).
"::update Error ".$this->error, LOG_ERR);
1020 $this->db->rollback();
1037 public function fetch($id, $user =
null, $ref_ext =
'', $email =
'', $loadalsoroles = 0, $socid = 0)
1041 dol_syslog(get_class($this).
"::fetch id=".$id.
" ref_ext=".$ref_ext.
" email=".$email, LOG_DEBUG);
1043 if (empty($id) && empty($ref_ext) && empty($email)) {
1044 $this->error =
'BadParameter';
1049 if (is_object($langs)) {
1050 $langs->loadLangs(array(
"dict",
"companies"));
1053 $sql =
"SELECT c.rowid, c.entity, c.fk_soc, c.ref_ext, c.civility as civility_code, c.name_alias, c.lastname, c.firstname,";
1054 $sql .=
" c.address, c.statut as status, c.zip, c.town,";
1055 $sql .=
" c.fk_pays as country_id,";
1056 $sql .=
" c.fk_departement as state_id,";
1057 $sql .=
" c.birthday,";
1058 $sql .=
" c.poste, c.phone, c.phone_perso, c.phone_mobile, c.fax, c.email,";
1059 $sql .=
" c.socialnetworks,";
1060 $sql .=
" c.photo,";
1061 $sql .=
" c.priv, c.note_private, c.note_public, c.default_lang, c.canvas,";
1062 $sql .=
" c.fk_prospectlevel, c.fk_stcommcontact, st.libelle as stcomm, st.picto as stcomm_picto,";
1063 $sql .=
" c.import_key,";
1064 $sql .=
" c.datec as date_creation, GREATEST(c.tms, COALESCE(cef.tms, c.tms)) as date_modification, c.fk_user_creat, c.fk_user_modif,";
1065 $sql .=
" co.label as country, co.code as country_code,";
1066 $sql .=
" d.nom as state, d.code_departement as state_code,";
1067 $sql .=
" u.rowid as user_id, u.login as user_login,";
1068 $sql .=
" s.nom as socname, s.address as socaddress, s.zip as soccp, s.town as soccity, s.default_lang as socdefault_lang";
1069 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as c";
1070 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"socpeople_extrafields as cef ON cef.fk_object=c.rowid";
1071 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as co ON c.fk_pays = co.rowid";
1072 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_departements as d ON c.fk_departement = d.rowid";
1073 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u ON c.rowid = u.fk_socpeople";
1074 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON c.fk_soc = s.rowid";
1075 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_stcommcontact as st ON c.fk_stcommcontact = st.id';
1077 $sql .=
" WHERE c.rowid = ".((int) $id);
1079 $sql .=
" WHERE c.entity IN (".getEntity($this->element).
")";
1081 $sql .=
" AND c.ref_ext = '".$this->db->escape($ref_ext).
"'";
1084 $sql .=
" AND c.email = '".$this->db->escape($email).
"'";
1087 $sql .=
" AND c.fk_soc = ".((int) $socid);
1091 $resql = $this->db->query($sql);
1093 $num = $this->db->num_rows($resql);
1095 $this->error =
'Fetch found several records. Rename one of contact to avoid duplicate.';
1100 $obj = $this->db->fetch_object($resql);
1102 $this->
id = $obj->rowid;
1103 $this->entity = $obj->entity;
1104 $this->
ref = $obj->rowid;
1105 $this->ref_ext = $obj->ref_ext;
1107 $this->civility_code = $obj->civility_code;
1108 $this->civility = $obj->civility_code ? ($langs->trans(
"Civility".$obj->civility_code) !=
"Civility".$obj->civility_code ? $langs->trans(
"Civility".$obj->civility_code) : $obj->civility_code) :
'';
1110 $this->name_alias = $obj->name_alias;
1111 $this->lastname = $obj->lastname;
1112 $this->firstname = $obj->firstname;
1113 $this->
address = $obj->address;
1114 $this->zip = $obj->zip;
1115 $this->town = $obj->town;
1117 $this->date_creation = $this->db->jdate($obj->date_creation);
1118 $this->date_modification = $this->db->jdate($obj->date_modification);
1119 $this->user_creation_id = $obj->fk_user_creat;
1120 $this->user_modification_id = $obj->fk_user_modif;
1122 $this->state_id = $obj->state_id;
1123 $this->state_code = $obj->state_code;
1124 $this->state = $obj->state;
1126 $this->country_id = $obj->country_id;
1127 $this->country_code = $obj->country_id ? $obj->country_code :
'';
1128 $this->country = $obj->country_id ? ($langs->trans(
'Country'.$obj->country_code) !=
'Country'.$obj->country_code ? $langs->transnoentities(
'Country'.$obj->country_code) : $obj->country) :
'';
1130 $this->fk_soc = $obj->fk_soc;
1131 $this->socid = $obj->fk_soc;
1132 $this->socname = $obj->socname;
1133 $this->poste = $obj->poste;
1134 $this->
status = $obj->status;
1135 $this->statut = $obj->status;
1137 $this->fk_prospectlevel = $obj->fk_prospectlevel;
1139 $transcode = (is_object($langs) ? $langs->trans(
'StatusProspect'.$obj->fk_stcommcontact) :
'StatusProspect'.$obj->fk_stcommcontact);
1140 $label_sale_status = ($transcode !=
'StatusProspect'.$obj->fk_stcommcontact ? $transcode : $obj->stcomm);
1141 $this->stcomm_id = $obj->fk_stcommcontact;
1142 $this->statut_commercial = $label_sale_status;
1143 $this->stcomm_picto = $obj->stcomm_picto;
1145 $this->phone_pro = trim((
string) $obj->phone);
1146 $this->fax = trim((
string) $obj->fax);
1147 $this->phone_perso = trim((
string) $obj->phone_perso);
1148 $this->phone_mobile = trim((
string) $obj->phone_mobile);
1150 $this->
email = $obj->email;
1151 $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks,
true) : array());
1152 $this->photo = $obj->photo;
1153 $this->priv = $obj->priv;
1154 $this->mail = $obj->email;
1156 $this->birthday = $this->db->jdate($obj->birthday);
1157 $this->note = $obj->note_private;
1158 $this->note_private = $obj->note_private;
1159 $this->note_public = $obj->note_public;
1160 $this->default_lang = $obj->default_lang;
1161 $this->user_id = $obj->user_id;
1162 $this->user_login = $obj->user_login;
1163 $this->canvas = $obj->canvas;
1165 $this->import_key = $obj->import_key;
1171 $sql =
"SELECT u.rowid ";
1172 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
1173 $sql .=
" WHERE u.fk_socpeople = ".((int) $this->
id);
1175 $resql = $this->db->query($sql);
1177 if ($this->db->num_rows($resql)) {
1178 $uobj = $this->db->fetch_object($resql);
1180 $this->user_id = $uobj->rowid;
1182 $this->db->free($resql);
1184 $this->error = $this->db->error();
1194 $sql =
"SELECT fk_user";
1195 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user_alert";
1196 $sql .=
" WHERE fk_user = ".((int) $user->id).
" AND fk_contact = ".((int) $id);
1198 $resql = $this->db->query($sql);
1200 if ($this->db->num_rows($resql)) {
1201 $obj = $this->db->fetch_object($resql);
1203 $this->birthday_alert = 1;
1205 $this->db->free($resql);
1207 $this->error = $this->db->error();
1213 if ($loadalsoroles) {
1215 if ($resultRole < 0) {
1222 $langs->load(
'errors');
1223 $this->error = $langs->trans(
"ErrorRecordNotFound");
1227 $this->error = $this->db->error();
1245 public function findNearest($id = 0, $lastname =
'', $firstname =
'', $ref_ext =
'', $email =
'', $ref_alias =
'', $socid = 0)
1257 $tmpcontact =
new Contact($this->db);
1258 $result = $tmpcontact->fetch($id,
null, $ref_ext, $email, 0, $socid);
1273 unset($this->gender);
1275 if (in_array($this->civility_id, array(
'MR')) || in_array($this->civility_code, array(
'MR'))) {
1276 $this->gender =
'man';
1277 } elseif (in_array($this->civility_id, array(
'MME',
'MLE')) || in_array($this->civility_code, array(
'MME',
'MLE'))) {
1278 $this->gender =
'woman';
1296 $sql =
"SELECT tc.element, count(ec.rowid) as nb";
1297 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_contact as ec, ".MAIN_DB_PREFIX.
"c_type_contact as tc";
1298 $sql .=
" WHERE ec.fk_c_type_contact = tc.rowid";
1299 $sql .=
" AND fk_socpeople = ".((int) $this->
id);
1300 $sql .=
" AND tc.source = 'external'";
1301 $sql .=
" GROUP BY tc.element";
1303 dol_syslog(get_class($this).
"::load_ref_elements", LOG_DEBUG);
1305 $resql = $this->db->query($sql);
1307 while ($obj = $this->db->fetch_object($resql)) {
1309 if ($obj->element ==
'facture') {
1310 $this->ref_facturation = $obj->nb;
1311 } elseif ($obj->element ==
'contrat') {
1312 $this->ref_contrat = $obj->nb;
1313 } elseif ($obj->element ==
'commande') {
1314 $this->ref_commande = $obj->nb;
1315 } elseif ($obj->element ==
'propal') {
1316 $this->ref_propal = $obj->nb;
1320 $this->db->free($resql);
1323 $this->error = $this->db->lasterror();
1336 public function delete($user, $notrigger = 0, $nodeletefiles = 0)
1346 $result = $this->call_trigger(
'CONTACT_DELETE', $user);
1355 $sql =
"SELECT ec.rowid";
1356 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_contact ec,";
1357 $sql .=
" ".MAIN_DB_PREFIX.
"c_type_contact tc";
1358 $sql .=
" WHERE ec.fk_socpeople=".((int) $this->
id);
1359 $sql .=
" AND ec.fk_c_type_contact=tc.rowid";
1360 $sql .=
" AND tc.source='external'";
1362 $resql = $this->db->query($sql);
1364 $num = $this->db->num_rows($resql);
1367 while ($i < $num && !$error) {
1368 $obj = $this->db->fetch_object($resql);
1370 $sqldel =
"DELETE FROM ".MAIN_DB_PREFIX.
"element_contact";
1371 $sqldel .=
" WHERE rowid = ".((int) $obj->rowid);
1373 $result = $this->db->query($sqldel);
1376 $this->error = $this->db->error().
' sql='.$sqldel;
1383 $this->error = $this->db->error().
' sql='.$sql;
1389 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_contacts WHERE fk_socpeople = ".((int) $this->
id);
1391 $resql = $this->db->query($sql);
1394 $this->error .= $this->db->lasterror();
1401 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"notify_def WHERE fk_contact = ".((int) $this->
id);
1403 $resql = $this->db->query($sql);
1406 $this->error .= $this->db->lasterror();
1413 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_contact WHERE fk_socpeople = ".((int) $this->
id);
1415 $resql = $this->db->query($sql);
1418 $this->error .= $this->db->lasterror();
1425 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"user_alert WHERE fk_contact = ".((int) $this->
id);
1427 $resql = $this->db->query($sql);
1430 $this->error .= $this->db->lasterror();
1436 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"user SET fk_socpeople = NULL WHERE fk_socpeople = ".((int) $this->
id);
1438 $resql = $this->db->query($sql);
1441 $this->error .= $this->db->lasterror();
1455 $dirofdocuments =
'';
1456 if ($this->
id > 0 && !empty(
$conf->societe->multidir_output[$this->entity])) {
1459 if (!$error && $dirofdocuments) {
1460 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1463 $this->error .= $this->db->lasterror();
1477 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"socpeople";
1478 $sql .=
" WHERE rowid = ".((int) $this->
id);
1480 $result = $this->db->query($sql);
1483 $this->error = $this->db->error().
' sql='.$sql;
1488 $this->db->commit();
1491 if (empty($nodeletefiles) && $dirofdocuments) {
1492 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1500 $this->db->rollback();
1515 $sql =
"SELECT c.rowid, c.datec as datec, c.fk_user_creat,";
1516 $sql .=
" GREATEST(c.tms, COALESCE(cef.tms, c.tms)) as tms, c.fk_user_modif";
1517 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as c";
1518 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"socpeople_extrafields as cef ON cef.fk_object=c.rowid";
1519 $sql .=
" WHERE c.rowid = ".((int) $id);
1521 $resql = $this->db->query($sql);
1523 if ($this->db->num_rows($resql)) {
1524 $obj = $this->db->fetch_object($resql);
1526 $this->
id = $obj->rowid;
1528 $this->user_creation_id = $obj->fk_user_creat;
1529 $this->user_modification_id = $obj->fk_user_modif;
1530 $this->date_creation = $this->db->jdate($obj->datec);
1531 $this->date_modification = $this->db->jdate($obj->tms);
1534 $this->db->free($resql);
1536 print $this->db->error();
1547 $sql =
"SELECT count(mc.email) as nb";
1548 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mailing_cibles as mc, ".MAIN_DB_PREFIX.
"mailing as m";
1549 $sql .=
" WHERE mc.fk_mailing=m.rowid AND mc.email = '".$this->db->escape($this->
email).
"' ";
1550 $sql .=
" AND m.entity IN (".getEntity($this->element).
") AND mc.statut NOT IN (-1,0)";
1552 $resql = $this->db->query($sql);
1554 $obj = $this->db->fetch_object($resql);
1555 $nb = (int) $obj->nb;
1557 $this->db->free($resql);
1560 $this->error = $this->db->error();
1573 global
$conf, $langs, $user;
1578 return [
'optimize' => $langs->trans(
"ShowContact")];
1580 if (!empty($this->photo) && class_exists(
'Form')) {
1581 $photo =
'<div class="photointooltip floatright">';
1582 $photo .=
Form::showphoto(
'contact', $this, 0, 40, 0,
'photoref',
'mini', 0);
1584 $datas[
'photo'] = $photo;
1587 $datas[
'picto'] = img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Contact").
'</u> ' . $this->
getLibStatut(4);
1588 $datas[
'name'] =
'<br><b>'.$langs->trans(
"Name").
':</b> '.$this->
getFullName($langs);
1590 if (!empty($this->poste)) {
1591 $datas[
'job'] =
'<br><b>'.$langs->trans(
"Poste").
':</b> '.$this->poste;
1593 $datas[
'email'] =
'<br><b>'.$langs->trans(
"EMail").
':</b> '.$this->email;
1594 $phonelist = array();
1595 $country_code = empty($this->country_code) ?
'' : $this->country_code;
1596 if ($this->phone_pro) {
1597 $phonelist[] =
dol_print_phone($this->phone_pro, $country_code, $this->
id, 0,
'',
' ',
'phone');
1599 if ($this->phone_mobile) {
1600 $phonelist[] =
dol_print_phone($this->phone_mobile, $country_code, $this->
id, 0,
'',
' ',
'mobile');
1602 if ($this->phone_perso) {
1603 $phonelist[] =
dol_print_phone($this->phone_perso, $country_code, $this->
id, 0,
'',
' ',
'phone');
1605 $datas[
'phonelist'] =
'<br><b>'.$langs->trans(
"Phone").
':</b> '.implode(
' ', $phonelist);
1606 $datas[
'address'] =
'<br><b>'.$langs->trans(
"Address").
':</b> '.
dol_format_address($this, 1,
' ', $langs);
1624 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $moreparam =
'', $save_lastsearch_value = -1, $maxlen = 0, $morecss =
'valignmiddle')
1626 global
$conf, $langs, $hookmanager;
1628 if (!empty(
$conf->dol_no_mouse_hover)) {
1635 'objecttype' => $this->element,
1636 'option' => $option,
1638 $classfortooltip =
'classfortooltip';
1641 $classfortooltip =
'classforajaxtooltip';
1642 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1648 $baseurl = DOL_URL_ROOT .
'/contact/card.php';
1649 $query = [
'id' => $this->id];
1650 if ($option !==
'nolink') {
1652 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1653 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1654 $add_save_lastsearch_values = 1;
1656 if ($add_save_lastsearch_values) {
1657 $query = array_merge($query, [
'save_lastsearch_values' => 1]);
1665 if (empty($notooltip)) {
1667 $label = $langs->trans(
"ShowContact");
1668 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1670 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
1671 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1673 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1676 if ($option ==
'nolink') {
1677 $linkstart =
'<span';
1679 $linkstart =
'<a href="'.$url.
'"';
1681 $linkstart .= $linkclose.
'>';
1682 if ($option ==
'nolink') {
1683 $linkend =
'</span>';
1688 $result .= $linkstart;
1691 if ($withpicto < 0) {
1692 $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>';
1693 if ($withpicto != 2 && $withpicto != -2) {
1697 $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);
1700 if ($withpicto != 2 && $withpicto != -2) {
1704 $result .= $linkend;
1707 $hookmanager->initHooks(array(
'contactdao'));
1708 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1709 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1711 $result = $hookmanager->resPrint;
1713 $result .= $hookmanager->resPrint;
1728 $code = ($this->civility_code ? $this->civility_code : (!empty($this->civility_id) ? $this->civility : (!empty($this->civilite) ? $this->civilite :
'')));
1733 $langs->load(
"dict");
1734 return $langs->getLabelFromKey($this->db,
"Civility".$code,
"c_civility",
"code",
"label", $code);
1761 $labelStatus = array(
1762 0 =>
'ActivityCeased',
1765 5 =>
'ActivityCeased',
1767 $labelStatusShort = array(
1768 0 =>
'ActivityCeased',
1771 5 =>
'ActivityCeased',
1774 $statusType =
'status4';
1775 if ($status == 0 || $status == 5) {
1776 $statusType =
'status5';
1779 $label = $langs->transnoentitiesnoconv($labelStatus[$status]);
1780 $labelshort = $langs->transnoentitiesnoconv($labelStatusShort[$status]);
1782 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
1798 if ($status ==
'1') {
1799 $s = ($decorate == 2 ?
'' : $langs->trans(
'ContactPrivate'));
1801 $s =
'<span title="'.$langs->trans(
'ContactPrivateDesc').
'">'.img_picto(
'',
'private',
'class="paddingrightonly"').$s.
'</span>';
1805 $s = ($decorate == 2 ?
'' : $langs->trans(
'ContactPublic'));
1807 $s =
'<span title="'.$langs->trans(
'ContactPublicDesc').
'">'.img_picto(
'',
'public',
'class="paddingrightonly"').$s.
'</span>';
1825 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe ORDER BY rowid LIMIT 1";
1826 $resql = $this->db->query($sql);
1828 $obj = $this->db->fetch_object($resql);
1830 $socid = $obj->rowid;
1837 $this->specimen = 1;
1838 $this->lastname =
'DOLIBARR';
1839 $this->firstname =
'SPECIMEN';
1840 $this->
address =
'21 jump street';
1841 $this->zip =
'99999';
1842 $this->town =
'MyTown';
1843 $this->country_id = 1;
1844 $this->country_code =
'FR';
1845 $this->country =
'France';
1846 $this->
email =
'specimen@specimen.com';
1847 $this->socialnetworks = array(
1848 'skype' =>
'tom.hanson',
1849 'twitter' =>
'tomhanson',
1850 'linkedin' =>
'tomhanson',
1852 $this->phone_pro =
'0909090901';
1853 $this->phone_perso =
'0909090902';
1854 $this->phone_mobile =
'0909090903';
1855 $this->fax =
'0909090909';
1857 $this->note_public =
'This is a comment (public)';
1858 $this->note_private =
'This is a comment (private)';
1860 $this->socid = $socid;
1874 global
$conf, $langs, $user;
1879 if (!empty($this->statut) && empty($this->
status)) {
1882 if ($this->
status == $status) {
1886 $this->statut = $status;
1892 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"socpeople";
1893 $sql .=
" SET statut = ".((int) $this->
status);
1894 $sql .=
", fk_user_modif = ".((int) $user->id);
1895 $sql .=
" WHERE rowid = ".((int) $this->
id);
1896 $result = $this->db->query($sql);
1898 dol_syslog(get_class($this).
"::setstatus", LOG_DEBUG);
1901 $result = $this->call_trigger(
'CONTACT_ENABLEDISABLE', $user);
1909 $this->db->rollback();
1912 $this->db->commit();
1930 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1931 return parent::setCategoriesCommon($categories, Categorie::TYPE_CONTACT, $remove_existing);
1945 'socpeople',
'societe_contacts'
1967 $sql =
'DELETE FROM '.$dbs->prefix().
'societe_contacts WHERE rowid IN (';
1968 $sql .=
' SELECT x.rowid FROM (';
1969 $sql .=
' SELECT origin.rowid FROM '.$dbs->prefix().
'societe_contacts as origin';
1970 $sql .=
' INNER JOIN '.$dbs->prefix().
'societe_contacts as dest ON dest.entity = origin.entity';
1971 $sql .=
' AND dest.fk_soc = origin.fk_soc AND dest.fk_c_type_contact = origin.fk_c_type_contact';
1972 $sql .=
' WHERE origin.fk_socpeople = '.((int) $origin_id).
' AND dest.fk_socpeople = '.((int) $dest_id);
1974 if (!$dbs->
query($sql)) {
1988 $sql =
'DELETE FROM '.$dbs->prefix().
'element_contact WHERE rowid IN (';
1989 $sql .=
' SELECT x.rowid FROM (';
1990 $sql .=
' SELECT origin.rowid FROM '.$dbs->prefix().
'element_contact as origin';
1991 $sql .=
' INNER JOIN '.$dbs->prefix().
'element_contact as dest ON dest.element_id = origin.element_id';
1992 $sql .=
' AND dest.fk_c_type_contact = origin.fk_c_type_contact';
1993 $sql .=
' WHERE origin.fk_socpeople = '.((int) $origin_id).
' AND dest.fk_socpeople = '.((int) $dest_id);
1994 $sql .=
" AND origin.fk_c_type_contact IN (SELECT rowid FROM ".$dbs->prefix().
"c_type_contact WHERE source = 'external')";
1996 if (!$dbs->
query($sql)) {
2000 $sql =
'UPDATE '.$dbs->prefix().
'element_contact SET fk_socpeople = '.((int) $dest_id);
2001 $sql .=
' WHERE fk_socpeople = '.((int) $origin_id);
2002 $sql .=
" AND fk_c_type_contact IN (SELECT rowid FROM ".$dbs->prefix().
"c_type_contact WHERE source = 'external')";
2003 if (!$dbs->
query($sql)) {
2010 $polymorphic = array(
2011 array(
'table' =>
'object_lang',
'id' =>
'fk_object',
'type' =>
'type_object',
2012 'values' => array(
'contact',
'socpeople'),
'unique' => array(
'property',
'lang')),
2013 array(
'table' =>
'links',
'id' =>
'objectid',
'type' =>
'objecttype',
2014 'values' => array(
'contact'),
'unique' => array(
'label')),
2015 array(
'table' =>
'element_element',
'id' =>
'fk_source',
'type' =>
'sourcetype',
2016 'values' => array(
'contact'),
'unique' => array(
'fk_target',
'targettype')),
2017 array(
'table' =>
'element_element',
'id' =>
'fk_target',
'type' =>
'targettype',
2018 'values' => array(
'contact'),
'unique' => array(
'fk_source',
'sourcetype')),
2020 array(
'table' =>
'actioncomm',
'id' =>
'fk_element',
'type' =>
'elementtype',
2021 'values' => array(
'contact'),
'unique' => array()),
2025 array(
'table' =>
'ecm_files',
'id' =>
'src_object_id',
'type' =>
'src_object_type',
2026 'values' => array(
'contact',
'socpeople'),
'unique' => array()),
2027 array(
'table' =>
'quickmemo_memo',
'id' =>
'fk_element',
'type' =>
'element_type',
2028 'values' => array(
'contact'),
'unique' => array()),
2029 array(
'table' =>
'comment',
'id' =>
'fk_element',
'type' =>
'element_type',
2030 'values' => array(
'contact'),
'unique' => array()),
2033 foreach ($polymorphic as $ref) {
2035 $sanitizedtable = $dbs->
sanitize($ref[
'table']);
2036 $sanitizedidcol = $dbs->
sanitize($ref[
'id']);
2037 $sanitizedtypecol = $dbs->
sanitize($ref[
'type']);
2043 $quotedvalues = array();
2044 foreach ($ref[
'values'] as $refvalue) {
2045 $quotedvalues[] =
"'".$dbs->escape($refvalue).
"'";
2047 $sanitizedvalues = implode(
', ', $quotedvalues);
2048 $sanitizedtypefilter = $sanitizedtypecol.
" IN (".$sanitizedvalues.
")";
2050 if (!empty($ref[
'unique'])) {
2051 $sql =
"DELETE FROM ".$dbs->prefix().$sanitizedtable.
" WHERE rowid IN (";
2052 $sql .=
" SELECT x.rowid FROM (";
2053 $sql .=
" SELECT origin.rowid FROM ".$dbs->prefix().$sanitizedtable.
" as origin";
2054 $sql .=
" INNER JOIN ".$dbs->prefix().$sanitizedtable.
" as dest";
2055 $sql .=
" ON dest.".$sanitizedtypecol.
" = origin.".$sanitizedtypecol;
2056 foreach ($ref[
'unique'] as $uniquecol) {
2057 $sanitizeduniquecol = $dbs->
sanitize($uniquecol);
2058 $sql .=
" AND dest.".$sanitizeduniquecol.
" = origin.".$sanitizeduniquecol;
2060 $sql .=
" WHERE origin.".$sanitizedidcol.
" = ".((int) $origin_id);
2061 $sql .=
" AND dest.".$sanitizedidcol.
" = ".((int) $dest_id);
2062 $sql .=
" AND origin.".$sanitizedtypefilter;
2064 if (!$dbs->
query($sql)) {
2069 $sql =
"UPDATE ".$dbs->prefix().$sanitizedtable.
" SET ".$sanitizedidcol.
" = ".((int) $dest_id);
2070 $sql .=
" WHERE ".$sanitizedtypefilter;
2071 $sql .=
" AND ".$sanitizedidcol.
" = ".((int) $origin_id);
2072 if (!$dbs->
query($sql)) {
2079 $sql =
"DELETE FROM ".$dbs->prefix().
"element_element WHERE fk_source = fk_target";
2080 $sql .=
" AND sourcetype = targettype AND fk_source = ".((int) $dest_id);
2081 $sql .=
" AND sourcetype = 'contact'";
2082 if (!$dbs->
query($sql)) {
2102 global $langs, $hookmanager, $user, $action;
2105 $langs->loadLangs(array(
'errors',
'companies'));
2109 if (!($this->
id > 0) || empty($this->entity)) {
2110 $this->error = $langs->trans(
'ErrorBadParameters');
2111 dol_syslog(__METHOD__.
' Called on a contact that was not loaded', LOG_ERR);
2114 if ($contact_origin_id <= 0 || $contact_origin_id == $this->
id) {
2115 $this->error = $langs->trans(
'ErrorBadParameters');
2119 if (!$user->hasRight(
'societe',
'contact',
'creer') || !$user->hasRight(
'societe',
'contact',
'supprimer')) {
2120 $this->error = $langs->trans(
'ErrorForbidden');
2124 if ($user->socid > 0) {
2125 $this->error = $langs->trans(
'ErrorForbidden');
2129 $contact_origin =
new Contact($this->db);
2130 $resultfetch = $contact_origin->fetch($contact_origin_id);
2132 if ($resultfetch != $contact_origin_id) {
2133 $this->error = $langs->trans(
'ErrorRecordNotFound');
2134 dol_syslog(__METHOD__.
' Cannot fetch contact id='.$contact_origin_id.
', result='.$resultfetch, LOG_ERR);
2141 $entities = explode(
',',
getEntity(
'contact'));
2142 foreach (array($this, $contact_origin) as $tmpcontact) {
2143 if (!in_array($tmpcontact->entity, $entities) || $tmpcontact->entity != $this->entity) {
2144 $this->error = $langs->trans(
'ErrorContactsMergeDifferentEntity');
2147 if (!empty($tmpcontact->priv) && $tmpcontact->user_creation_id != $user->id) {
2148 $this->error = $langs->trans(
'ErrorContactsMergePrivate');
2153 if ($tmpcontact->socid > 0 && !$user->hasRight(
'societe',
'client',
'voir')
2154 && !$this->isSalesRepresentativeOf($tmpcontact->socid)) {
2155 $this->error = $langs->trans(
'ErrorForbidden');
2161 if (!empty($this->priv) && empty($contact_origin->priv)) {
2162 $this->error = $langs->trans(
'ErrorContactsMergeIntoPrivate');
2167 if ($originlinked < 0 || $destlinked < 0) {
2169 $this->error = $langs->trans(
'ErrorContactsMerge');
2175 if (($originlinked > 0 || $destlinked > 0) && !$user->hasRight(
'user',
'user',
'creer')) {
2176 $this->error = $langs->trans(
'ErrorContactsMergeLinkedToUser');
2180 if ($originlinked > 0 && $destlinked > 0) {
2181 $this->error = $langs->trans(
'ErrorContactsMergeBothLinkedToUser');
2185 dol_syslog(__METHOD__.
' merge contact id='.$contact_origin->id.
' (will be deleted) into the contact id='.$this->id);
2190 foreach (self::MERGE_FIELDS_FILL_IF_EMPTY as $property) {
2191 if (empty($this->$property) && !empty($contact_origin->$property)) {
2192 $this->$property = $contact_origin->$property;
2197 $mention =
'['.$langs->transnoentitiesnoconv(
'MergedFromContact',
dol_print_date(
dol_now(),
'day'), (
string) $contact_origin->id).
']';
2198 foreach (self::MERGE_FIELDS_CONCAT as $property) {
2199 if (!empty($contact_origin->$property)) {
2200 $this->$property =
dol_concatdesc($this->$property, $mention.
"\n".$contact_origin->$property);
2205 if (!empty($contact_origin->priv)) {
2210 if (empty($this->name_alias) && $this->
getFullName($langs) != $contact_origin->getFullName($langs)) {
2211 $this->name_alias = $contact_origin->getFullName($langs);
2215 if (is_array($contact_origin->array_options)) {
2216 foreach ($contact_origin->array_options as $key => $val) {
2217 if (empty($this->array_options[$key])) {
2218 $this->array_options[$key] = $val;
2227 $this->roles =
null;
2230 if ($this->
update($this->
id, $user, 1) <= 0) {
2232 dol_syslog(__METHOD__.
' Failed to update the target contact: '.$this->errorsToString(), LOG_ERR);
2238 include_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2240 $cats_origin = $static_cat->containing($contact_origin->id,
'contact',
'id');
2241 $cats_dest = $static_cat->containing($this->
id,
'contact',
'id');
2244 if (!is_array($cats_origin) || !is_array($cats_dest)) {
2245 $this->error = $static_cat->error;
2246 dol_syslog(__METHOD__.
' Cannot read the categories of the contacts: '.$this->error, LOG_ERR);
2251 $cats = array_merge($cats_origin, $cats_dest);
2252 if ($this->
setCategories(array_values(array_unique($cats))) < 0) {
2266 'ActionComm' =>
'/comm/action/class/actioncomm.class.php',
2267 'Contact' =>
'/contact/class/contact.class.php',
2268 'User' =>
'/user/class/user.class.php',
2270 foreach ($objects as $object_name => $object_file) {
2271 require_once DOL_DOCUMENT_ROOT.$object_file;
2273 if (!$object_name::replaceContact($this->db, $contact_origin->id, $this->id)) {
2275 $this->error = $this->db->lasterror();
2276 dol_syslog(__METHOD__.
' '.$object_name.
'::replaceContact failed: '.$this->error, LOG_ERR);
2289 $parameters = array(
'contact_origin' => $contact_origin->id,
'contact_dest' => $this->id);
2290 $reshook = $hookmanager->executeHooks(
'replaceContact', $parameters, $this, $action);
2293 $this->error = $hookmanager->error;
2294 $this->errors = $hookmanager->errors;
2300 $this->context = array(
2302 'mergefromid' => $contact_origin->id,
2303 'mergefromname' => $contact_origin->getFullName($langs)
2307 $result = $this->call_trigger(
'CONTACT_MODIFY', $user);
2317 if ($contact_origin->delete($user, 0, 1) <= 0) {
2318 $this->error = $contact_origin->error;
2319 $this->errors = $contact_origin->errors;
2331 $this->db->commit();
2334 $langs->load(
"errors");
2335 $this->error = $langs->trans(
'ErrorContactsMerge').
' '.$this->error;
2336 $this->db->rollback();
2339 $this->
fetch($this->
id);
2354 $sql =
"SELECT rowid FROM ".$this->db->prefix().
"user WHERE fk_socpeople = ".((int) $contactid);
2356 $resql = $this->db->query($sql);
2358 $this->error = $this->db->lasterror();
2359 dol_syslog(__METHOD__.
' '.$this->error, LOG_ERR);
2362 $found = ($this->db->num_rows($resql) > 0 ? 1 : 0);
2363 $this->db->free($resql);
2379 if (empty($socid)) {
2383 $sql =
"SELECT fk_soc FROM ".$this->db->prefix().
"societe_commerciaux";
2384 $sql .=
" WHERE fk_soc = ".((int) $socid).
" AND fk_user = ".((int) $user->id);
2386 $resql = $this->db->query($sql);
2388 $this->error = $this->db->lasterror();
2389 dol_syslog(__METHOD__.
' '.$this->error, LOG_ERR);
2392 $found = ($this->db->num_rows($resql) > 0);
2393 $this->db->free($resql);
2416 if ($parentofdest == $contact_origin->id) {
2417 $newparent = $this->
getParentId($contact_origin->id);
2421 $sql =
'UPDATE '.$this->db->prefix().
'socpeople';
2422 $sql .=
' SET fk_parent = '.($newparent > 0 ? ((int) $newparent) :
'NULL');
2423 $sql .=
' WHERE rowid = '.((int) $this->
id);
2424 if (!$this->db->query($sql)) {
2425 $this->error = $this->db->lasterror();
2426 dol_syslog(__METHOD__.
' '.$this->error, LOG_ERR);
2432 $ancestors = array();
2435 while ($currentid > 0 && $depth < self::MERGE_MAX_PARENT_DEPTH) {
2436 if (in_array($currentid, $ancestors)) {
2439 $ancestors[] = (int) $currentid;
2444 $sql =
'UPDATE '.$this->db->prefix().
'socpeople SET fk_parent = '.((int) $this->
id);
2445 $sql .=
' WHERE fk_parent = '.((int) $contact_origin->id);
2446 $sql .=
' AND rowid <> '.((int) $this->
id);
2447 if (!empty($ancestors)) {
2449 $sanitizedancestors = implode(
',', $ancestors);
2450 $sql .=
" AND rowid NOT IN (".$sanitizedancestors.
")";
2452 if (!$this->db->query($sql)) {
2453 $this->error = $this->db->lasterror();
2454 dol_syslog(__METHOD__.
' '.$this->error, LOG_ERR);
2461 $sql =
'UPDATE '.$this->db->prefix().
'socpeople SET fk_parent = NULL';
2462 $sql .=
' WHERE fk_parent = '.((int) $contact_origin->id);
2463 if (!$this->db->query($sql)) {
2464 $this->error = $this->db->lasterror();
2465 dol_syslog(__METHOD__.
' '.$this->error, LOG_ERR);
2482 $sql =
"SELECT fk_parent FROM ".$this->db->prefix().
"socpeople WHERE rowid = ".((int) $contactid);
2484 $resql = $this->db->query($sql);
2486 $this->error = $this->db->lasterror();
2487 dol_syslog(__METHOD__.
' '.$this->error, LOG_ERR);
2491 if ($obj = $this->db->fetch_object($resql)) {
2492 $parentid = (empty($obj->fk_parent) ? 0 : (int) $obj->fk_parent);
2494 $this->db->free($resql);
2513 $sql =
'DELETE FROM '.$this->db->prefix().
'notify_def WHERE rowid IN (';
2514 $sql .=
' SELECT x.rowid FROM (';
2515 $sql .=
' SELECT origin.rowid FROM '.$this->db->prefix().
'notify_def as origin';
2516 $sql .=
' INNER JOIN '.$this->db->prefix().
'notify_def as dest ON dest.fk_action = origin.fk_action';
2520 $sql .=
' AND (dest.fk_soc = origin.fk_soc OR (dest.fk_soc IS NULL AND origin.fk_soc IS NULL))';
2521 $sql .=
' AND (dest.entity = origin.entity OR (dest.entity IS NULL AND origin.entity IS NULL))';
2522 $sql .=
' AND (dest.type = origin.type OR (dest.type IS NULL AND origin.type IS NULL))';
2523 $sql .=
' AND (dest.threshold = origin.threshold OR (dest.threshold IS NULL AND origin.threshold IS NULL))';
2524 $sql .=
' AND (dest.context = origin.context OR (dest.context IS NULL AND origin.context IS NULL))';
2525 $sql .=
' AND (dest.fk_user = origin.fk_user OR (dest.fk_user IS NULL AND origin.fk_user IS NULL))';
2526 $sql .=
' AND (dest.email = origin.email OR (dest.email IS NULL AND origin.email IS NULL))';
2527 $sql .=
' WHERE origin.fk_contact = '.((int) $contact_origin->id).
' AND dest.fk_contact = '.((int) $this->
id);
2529 if (!$this->db->query($sql)) {
2530 $this->error = $this->db->lasterror();
2531 dol_syslog(__METHOD__.
' '.$this->error, LOG_ERR);
2536 dol_syslog(__METHOD__.
' Failed to move the notifications: '.$this->db->lasterror(), LOG_ERR);
2541 if ($this->db->DDLListTables((
string) $this->db->database_name, $this->db->prefix().
'mailing_cibles')) {
2545 dol_syslog(__METHOD__.
' Failed to move the mass emailing targets: '.$this->db->lasterror(), LOG_ERR);
2550 $sql =
'UPDATE '.$this->db->prefix().
'mailing_cibles SET source_id = '.((int) $this->
id);
2551 $sql .=
" WHERE source_type = 'contact' AND source_id = ".((int) $contact_origin->id);
2552 if (!$this->db->query($sql)) {
2553 $this->error = $this->db->lasterror();
2554 dol_syslog(__METHOD__.
' '.$this->error, LOG_ERR);
2572 global
$conf, $langs;
2574 if (empty(
$conf->societe->multidir_output[$this->entity])) {
2579 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2582 $srcdir =
$conf->societe->multidir_output[$this->entity].
'/contact/'.((int) $contact_origin_id);
2583 $destdir =
$conf->societe->multidir_output[$this->entity].
'/contact/'.((int) $this->
id);
2591 foreach ($dirlist as $filetomove) {
2592 $destfile = $destdir.
'/'.$filetomove[
'relativename'];
2596 $info = pathinfo($filetomove[
'relativename']);
2597 $suffix = (empty($info[
'extension']) ?
'' :
'.'.$info[
'extension']);
2598 $destfile = $destdir.
'/'.(empty($info[
'dirname']) || $info[
'dirname'] ==
'.' ?
'' : $info[
'dirname'].
'/');
2599 $destfile .= $info[
'filename'].
'-'.((int) $contact_origin_id).$suffix;
2604 if (!
dol_move($filetomove[
'fullname'], $destfile,
'0', 0, 0, 1)) {
2605 $failed[] = $filetomove[
'relativename'];
2609 if (!empty($failed)) {
2610 dol_syslog(__METHOD__.
' Failed to move '.count($failed).
' file(s) from '.$srcdir, LOG_ERR);
2612 $this->warnings[] = $langs->trans(
'WarningMergeFilesNotMoved', implode(
', ', $failed));
2629 $sql =
"SELECT tc.rowid, tc.element, tc.source, tc.code, tc.libelle as label, sc.rowid as contactroleid, sc.fk_soc as socid";
2630 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_contacts as sc, ".MAIN_DB_PREFIX.
"c_type_contact as tc";
2631 $sql .=
" WHERE tc.rowid = sc.fk_c_type_contact";
2632 $sql .=
" AND tc.source = 'external' AND tc.active=1";
2633 $sql .=
" AND sc.fk_socpeople = ".((int) $this->
id);
2634 $sql .=
" AND sc.entity IN (".getEntity(
'societe').
')';
2636 $resql = $this->db->query($sql);
2638 $this->roles = array();
2640 $num = $this->db->num_rows($resql);
2642 while ($obj = $this->db->fetch_object($resql)) {
2643 $transkey =
"TypeContact_".$obj->element.
"_".$obj->source.
"_".$obj->code;
2644 $label_element = $langs->trans(
'ContactDefault_'.$obj->element);
2645 $this->roles[$obj->contactroleid] = array(
'id' => $obj->rowid,
'socid' => $obj->socid,
'element' => $obj->element,
'source' => $obj->source,
'code' => $obj->code,
'label' => $label_element.
' - '.($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->label));
2650 $this->error = $this->db->lasterror();
2651 $this->errors[] = $this->db->lasterror();
2654 if (empty($error)) {
2672 if ($element ==
'action') {
2673 $element =
'agenda';
2676 $sql =
"SELECT sc.fk_socpeople as id, sc.fk_c_type_contact";
2677 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact tc";
2678 $sql .=
", ".MAIN_DB_PREFIX.
"societe_contacts sc";
2679 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"socpeople sp";
2680 $sql .=
" ON sc.fk_socpeople = sp.rowid AND sp.statut = 1";
2681 $sql .=
" WHERE sc.fk_soc = ".((int) $this->socid);
2682 $sql .=
" AND sc.fk_c_type_contact=tc.rowid";
2683 $sql .=
" AND tc.element = '".$this->db->escape($element).
"'";
2684 $sql .=
" AND sp.entity IN (".getEntity(
'contact').
")";
2685 $sql .=
" AND tc.active = 1";
2687 $resql = $this->db->query($sql);
2689 $num = $this->db->num_rows($resql);
2692 $obj = $this->db->fetch_object($resql);
2693 $tab[$obj->id] = array(
'fk_socpeople' => $obj->id,
'type_contact' => $obj->fk_c_type_contact);
2700 $this->error = $this->db->error();
2701 dol_print_error($this->db);
2719 if (!isset($this->roles)) {
2725 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_contacts WHERE fk_socpeople=".((int) $this->
id).
" AND entity IN (".
getEntity(
"contact").
")";
2727 $result = $this->db->query($sql);
2729 $this->errors[] = $this->db->lasterror().
' sql='.$sql;
2732 if (count($this->roles) > 0) {
2733 foreach ($this->roles as $keyRoles => $valRoles) {
2734 if (empty($valRoles)) {
2738 if (is_array($valRoles)) {
2739 $idrole = $valRoles[
'id'];
2741 $idrole = $valRoles;
2745 if (is_array($valRoles)) {
2746 $socid = $valRoles[
'socid'];
2748 $socid = $this->socid;
2752 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_contacts";
2753 $sql .=
" (entity,";
2754 $sql .=
"date_creation,";
2756 $sql .=
"fk_c_type_contact,";
2757 $sql .=
"fk_socpeople) ";
2758 $sql .=
" VALUES (".((int)
$conf->entity).
",";
2759 $sql .=
"'".$this->db->idate(
dol_now()).
"',";
2760 $sql .= ((int) $socid).
", ";
2761 $sql .= ((int) $idrole).
" , ";
2762 $sql .= ((int) $this->
id);
2765 $result = $this->db->query($sql);
2767 $this->errors[] = $this->db->lasterror().
' sql='.$sql;
2774 if (empty($error)) {
2775 $this->db->commit();
2778 $this->error = implode(
' ', $this->errors);
2779 $this->db->rollback();
2794 $sql =
"SELECT id, code, libelle as label, picto FROM ".MAIN_DB_PREFIX.
"c_stcommcontact";
2796 $sql .=
" WHERE active = ".((int) $active);
2798 $resql = $this->db->query($sql);
2799 $num = $this->db->num_rows($resql);
2802 $obj = $this->db->fetch_object($resql);
2803 $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);
2829 $lib = $langs->trans(
"ProspectLevel".$fk_prospectlevel);
2831 if ($lib ==
"ProspectLevel".$fk_prospectlevel) {
2832 $lib = $langs->getLabelFromKey($this->db, $fk_prospectlevel,
'c_prospectlevel',
'code',
'label');
2847 return $this->
update($this->
id, $user);
2859 return $this->
libProspCommStatut($this->stcomm_id, $mode, $label, $this->stcomm_picto);
2878 $langs->load(
'customers');
2881 if ($statut ==
'-1' || $statut ==
'ST_NO') {
2882 return img_action($langs->trans(
"StatusProspect-1"),
'-1', $picto).
' '.$langs->trans(
"StatusProspect-1");
2883 } elseif ($statut ==
'0' || $statut ==
'ST_NEVER') {
2884 return img_action($langs->trans(
"StatusProspect0"),
'0', $picto).
' '.$langs->trans(
"StatusProspect0");
2885 } elseif ($statut ==
'1' || $statut ==
'ST_TODO') {
2886 return img_action($langs->trans(
"StatusProspect1"),
'1', $picto).
' '.$langs->trans(
"StatusProspect1");
2887 } elseif ($statut ==
'2' || $statut ==
'ST_PEND') {
2888 return img_action($langs->trans(
"StatusProspect2"),
'2', $picto).
' '.$langs->trans(
"StatusProspect2");
2889 } elseif ($statut ==
'3' || $statut ==
'ST_DONE') {
2890 return img_action($langs->trans(
"StatusProspect3"),
'3', $picto).
' '.$langs->trans(
"StatusProspect3");
2892 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);
2896 if ($statut ==
'-1' || $statut ==
'ST_NO') {
2897 return img_action($langs->trans(
"StatusProspect-1"),
'-1', $picto);
2898 } elseif ($statut ==
'0' || $statut ==
'ST_NEVER') {
2899 return img_action($langs->trans(
"StatusProspect0"),
'0', $picto);
2900 } elseif ($statut ==
'1' || $statut ==
'ST_TODO') {
2901 return img_action($langs->trans(
"StatusProspect1"),
'1', $picto);
2902 } elseif ($statut ==
'2' || $statut ==
'ST_PEND') {
2903 return img_action($langs->trans(
"StatusProspect2"),
'2', $picto);
2904 } elseif ($statut ==
'3' || $statut ==
'ST_DONE') {
2905 return img_action($langs->trans(
"StatusProspect3"),
'3', $picto);
2907 return img_action(($langs->trans(
"StatusProspect".$statut) !=
"StatusProspect".$statut) ? $langs->trans(
"StatusProspect".$statut) : $label,
'0', $picto);
2911 if ($statut ==
'-1' || $statut ==
'ST_NO') {
2912 return img_action($langs->trans(
"StatusProspect-1"),
'-1', $picto).
' '.$langs->trans(
"StatusProspect-1");
2913 } elseif ($statut ==
'0' || $statut ==
'ST_NEVER') {
2914 return img_action($langs->trans(
"StatusProspect0"),
'0', $picto).
' '.$langs->trans(
"StatusProspect0");
2915 } elseif ($statut ==
'1' || $statut ==
'ST_TODO') {
2916 return img_action($langs->trans(
"StatusProspect1"),
'1', $picto).
' '.$langs->trans(
"StatusProspect1");
2917 } elseif ($statut ==
'2' || $statut ==
'ST_PEND') {
2918 return img_action($langs->trans(
"StatusProspect2"),
'2', $picto).
' '.$langs->trans(
"StatusProspect2");
2919 } elseif ($statut ==
'3' || $statut ==
'ST_DONE') {
2920 return img_action($langs->trans(
"StatusProspect3"),
'3', $picto).
' '.$langs->trans(
"StatusProspect3");
2922 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);
2926 return "Error, mode/status not found";
2945 $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).
"'";
2946 $resql = $this->db->query($sql);
2948 $obj = $this->db->fetch_object($resql);
2949 $noemail = $obj->nb;
2950 if (empty($noemail)) {
2951 $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()).
"')";
2952 $resql = $this->db->query($sql);
2955 $this->error = $this->db->lasterror();
2956 $this->errors[] = $this->error;
2961 $this->error = $this->db->lasterror();
2962 $this->errors[] = $this->error;
2965 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE email = '".$this->db->escape($this->
email).
"' AND entity IN (".
getEntity(
'mailing', 0).
")";
2966 $resql = $this->db->query($sql);
2969 $this->error = $this->db->lasterror();
2970 $this->errors[] = $this->error;
2974 if (empty($error)) {
2975 $this->no_email = $no_email;
2976 $this->db->commit();
2979 $this->db->rollback();
2996 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE entity IN (".
getEntity(
'mailing').
") AND email = '".$this->db->escape($this->
email).
"'";
2997 $resql = $this->db->query($sql);
2999 $obj = $this->db->fetch_object($resql);
3000 $this->no_email = $obj->nb;
3003 $this->error = $this->db->lasterror();
3004 $this->errors[] = $this->error;
3021 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3023 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3024 $return .=
'<div class="info-box info-box-sm">';
3025 $return .=
'<span class="info-box-icon bg-infobox-action">';
3026 if (!is_null($this->photo)) {
3027 $return .=
Form::showphoto(
'contact', $this, 0, 60, 0,
'photokanban photoref photowithmargin photologintooltip',
'small', 0, 1);
3029 $return .= img_picto(
'', $this->picto);
3031 $return .=
'</span>';
3032 $return .=
'<div class="info-box-content">';
3033 $return .=
'<div class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . $this->
getNomUrl(0) .
'</div>';
3034 if ($selected >= 0) {
3035 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3037 if (is_object($this->thirdparty)) {
3038 $return .=
'<div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).
'</div>';
3048 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
3049 $return .=
'</div>';
3050 $return .=
'</div>';
3051 $return .=
'</div>';
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage categories.
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
deleteEcmFiles($mode=0)
Delete related files of object in database.
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid=0, $f_user=null, $notrigger=0)
Delete all links between an object $this.
deleteExtraFields()
Delete all extra fields values for the current object.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
static commonReplaceContact(DoliDB $dbs, $origin_id, $dest_id, array $tables, $fieldname='fk_socpeople', $ignoreerrors=0)
Function used to replace a contact id with another one.
Class to manage Dolibarr database access.
prefix()
Return the DB prefix found into prefix_db (if it was set manually by doing $dbhandler->prefix_db=....
sanitize($stringtosanitize, $allowsimplequote=0, $allowsequals=0, $allowsspace=0, $allowschars=1)
Sanitize a string for SQL forging.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
getFullName($langs, $option=0, $nameorder=-1, $maxlen=0)
Return full name (civility+' '+name+' '+lastname)
setUpperOrLowerCase()
Set to upper or ucwords/lower if needed.
trait CommonSocialNetworks
Superclass for social networks.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as p label as s rowid as s nom as s email
Sender: Who sends the email ("Sender" has sent emails on behalf of "From").
dol_move($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=1, $moreinfo=array(), $entity=null)
Move a file into another name.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_is_file($pathoffile)
Return if path is a file.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_is_dir($folder)
Test if filename is a directory.
deleteFilesIntoDatabaseIndex($dir, $file, $mode='uploaded', $object=null)
Delete files into database index using search criteria.
dol_now($mode='gmt')
Return date for now.
setEntity($currentobject)
Set entity id to use when to create an object.
dol_print_phone($phone, $countrycode='', $contactid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='paddingright')
Format phone numbers according to country.
dol_format_address($object, $withcountry=0, $sep="\n", $outputlangs=null, $mode=0, $extralangcode='')
Return a formatted address (part address/zip/town/state) according to country rules.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
img_action($titlealt, $numaction, $picto='', $moreatt='')
Show logo action.
DDLListTables($database, $table='')
List tables into a database.
query($query, $usesavepoint=0, $type='auto', $result_mode=0)
Execute a SQL request and return the resultset.
$conf db name
Only used if Module[ID]Name translation string is not found.
div refaddress div address