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 public 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 public const MERGE_FIELDS_CONCAT = array(
'note_public',
'note_private');
78 public 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),
129 'name_alias' => array(
'type' =>
'varchar(255)',
'label' =>
'Name alias',
'enabled' => 1,
'visible' => -1,
'position' => 46,
'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' =>
'Fk departement',
'enabled' => 1,
'visible' => 3,
'position' => 70),
136 'fk_pays' => array(
'type' =>
'integer',
'label' =>
'Fk pays',
'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]);
464 global $user, $hookmanager;
469 $sql =
"SELECT count(sp.rowid) as nb";
470 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as sp";
471 if (!$user->hasRight(
'societe',
'client',
'voir')) {
472 $sql .=
", ".MAIN_DB_PREFIX.
"societe as s";
473 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
474 $sql .=
" WHERE sp.fk_soc = s.rowid AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
477 $sql .=
" ".$clause.
" sp.entity IN (".
getEntity($this->element).
")";
478 $sql .=
" AND (sp.priv='0' OR (sp.priv='1' AND sp.fk_user_creat = ".((int) $user->id).
"))";
479 if ($user->socid > 0) {
480 $sql .=
" AND sp.fk_soc = ".((int) $user->socid);
483 if (is_object($hookmanager)) {
484 $parameters = array();
485 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $this);
486 $sql .= $hookmanager->resPrint;
489 $resql = $this->db->query($sql);
491 while ($obj = $this->db->fetch_object($resql)) {
492 $this->nb[
"contacts"] = $obj->nb;
494 $this->db->free($resql);
498 $this->error = $this->db->lasterror();
510 public function create($user, $notrigger = 0)
517 if (empty($this->date_creation)) {
518 $this->date_creation = $now;
524 $this->name_alias = trim($this->name_alias);
525 $this->lastname = $this->lastname ? trim($this->lastname) : trim($this->
name);
526 $this->firstname = trim($this->firstname);
528 if (empty($this->socid)) {
531 if (empty($this->priv)) {
534 if (!empty($this->statut) && empty($this->
status)) {
537 if (empty($this->
status)) {
545 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"socpeople (";
548 $sql .=
", name_alias";
549 $sql .=
", lastname";
550 $sql .=
", firstname";
551 $sql .=
", fk_user_creat";
553 $sql .=
", fk_stcommcontact";
558 $sql .=
", import_key";
560 $sql .=
") VALUES (";
561 $sql .=
"'".$this->db->idate($now).
"',";
562 if ($this->socid > 0) {
563 $sql .=
" ".((int) $this->socid).
",";
567 $sql .=
"'".$this->db->escape($this->name_alias).
"',";
568 $sql .=
"'".$this->db->escape($this->lastname).
"',";
569 $sql .=
"'".$this->db->escape($this->firstname).
"',";
570 $sql .=
" ".($user->id > 0 ? ((int) $user->id) :
"null").
",";
571 $sql .=
" ".((int) $this->priv).
",";
573 $sql .=
" ".((int) $this->
status).
",";
574 $sql .=
" ".(!empty($this->canvas) ?
"'".$this->db->escape($this->canvas).
"'" :
"null").
",";
575 $sql .=
" ".((int) $this->entity).
",";
576 $sql .=
"'".$this->db->escape($this->ref_ext).
"',";
577 $sql .=
" ".(!empty($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null").
",";
578 $sql .=
" ".(!empty($this->ip) ?
"'".$this->db->escape($this->ip).
"'" :
"null");
581 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
582 $resql = $this->db->query($sql);
584 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"socpeople");
586 $result = $this->
update($this->
id, $user, 1,
'add');
589 $this->error = $this->db->lasterror();
596 $this->error = $this->db->lasterror();
600 if (!$error && !$notrigger) {
602 $result = $this->call_trigger(
'CONTACT_CREATE', $user);
613 $this->db->rollback();
614 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
618 $this->error = $this->db->lasterror();
620 $this->db->rollback();
621 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
636 public function update($id, $user =
null, $notrigger = 0, $action =
'update', $nosyncuser = 0)
640 if (empty($this->country_id) && !empty($this->country_code)) {
641 $country_id =
getCountry($this->country_code,
'3');
642 $this->country_id = is_int($country_id) ? $country_id : 0;
649 $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity :
$conf->entity);
652 $this->ref_ext = (empty($this->ref_ext) ?
'' : trim($this->ref_ext));
653 $this->name_alias = trim($this->name_alias);
654 $this->lastname = trim($this->lastname) ? trim($this->lastname) : trim($this->lastname);
655 $this->firstname = trim($this->firstname);
657 $this->phone_pro = trim($this->phone_pro);
658 $this->phone_perso = trim($this->phone_perso);
659 $this->phone_mobile = trim($this->phone_mobile);
660 $this->photo = trim($this->photo);
661 $this->fax = trim($this->fax);
662 $this->zip = (empty($this->zip) ?
'' : trim($this->zip));
663 $this->town = (empty($this->town) ?
'' : trim($this->town));
664 $this->country_id = (empty($this->country_id) || $this->country_id < 0) ? 0 : $this->country_id;
665 if (!empty($this->statut) && empty($this->
status)) {
668 if (empty($this->
status)) {
672 if (empty($this->civility_code) && !is_numeric($this->civility_id)) {
673 $this->civility_code = $this->civility_id;
679 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"socpeople SET";
680 if ($this->socid > 0) {
681 $sql .=
" fk_soc = ".((int) $this->socid).
",";
682 } elseif ($this->socid == -1) {
683 $sql .=
" fk_soc = NULL,";
685 $sql .=
" civility='".$this->db->escape($this->civility_code).
"'";
686 $sql .=
", name_alias='".$this->db->escape($this->name_alias).
"'";
687 $sql .=
", lastname='".$this->db->escape($this->lastname).
"'";
688 $sql .=
", firstname='".$this->db->escape($this->firstname).
"'";
689 $sql .=
", address='".$this->db->escape((
string) $this->
address).
"'";
690 $sql .=
", zip='".$this->db->escape($this->zip).
"'";
691 $sql .=
", town='".$this->db->escape($this->town).
"'";
692 $sql .=
", ref_ext = ".(!empty($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"NULL");
693 $sql .=
", fk_pays=".($this->country_id > 0 ? ((int) $this->country_id) :
'NULL');
694 $sql .=
", fk_departement=".($this->state_id > 0 ? ((int) $this->state_id) :
'NULL');
695 $sql .=
", poste='".$this->db->escape($this->poste).
"'";
696 $sql .=
", fax='".$this->db->escape($this->fax).
"'";
697 $sql .=
", email='".$this->db->escape($this->
email).
"'";
698 $sql .=
", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
699 $sql .=
", photo='".$this->db->escape($this->photo).
"'";
700 $sql .=
", birthday=".($this->birthday ?
"'".$this->db->idate($this->birthday).
"'" :
"null");
701 $sql .=
", note_private = ".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"NULL");
702 $sql .=
", note_public = ".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"NULL");
703 $sql .=
", phone = ".(isset($this->phone_pro) ?
"'".$this->db->escape($this->phone_pro).
"'" :
"NULL");
704 $sql .=
", phone_perso = ".(isset($this->phone_perso) ?
"'".$this->db->escape($this->phone_perso).
"'" :
"NULL");
705 $sql .=
", phone_mobile = ".(isset($this->phone_mobile) ?
"'".$this->db->escape($this->phone_mobile).
"'" :
"NULL");
706 $sql .=
", priv = ".((int) $this->priv);
707 $sql .=
", fk_prospectlevel = '".$this->db->escape($this->fk_prospectlevel).
"'";
708 if (isset($this->stcomm_id)) {
709 $sql .=
", fk_stcommcontact = ".($this->stcomm_id > 0 || $this->stcomm_id == -1 ? ((int) $this->stcomm_id) :
"0");
711 $sql .=
", statut = ".((int) $this->
status);
712 $sql .=
", fk_user_modif=".($user->id > 0 ?
"'".$this->db->escape((
string) $user->id).
"'" :
"NULL");
713 $sql .=
", default_lang=".($this->default_lang ?
"'".$this->db->escape($this->default_lang).
"'" :
"NULL");
714 $sql .=
", entity = ".((int) $this->entity);
715 $sql .=
" WHERE rowid = ".((int) $id);
717 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
718 $result = $this->db->query($sql);
720 unset($this->country_code);
721 unset($this->country);
722 unset($this->state_code);
740 if (!$error && $this->user_id > 0) {
742 $tmpobj =
new User($this->db);
743 $tmpobj->fetch($this->user_id);
744 $usermustbemodified = 0;
745 if ($tmpobj->office_phone != $this->phone_pro) {
746 $tmpobj->office_phone = $this->phone_pro;
747 $usermustbemodified++;
749 if ($tmpobj->office_fax != $this->fax) {
750 $tmpobj->office_fax = $this->fax;
751 $usermustbemodified++;
753 if ($tmpobj->address != $this->address) {
754 $tmpobj->address = $this->address;
755 $usermustbemodified++;
757 if ($tmpobj->town != $this->town) {
758 $tmpobj->town = $this->town;
759 $usermustbemodified++;
761 if ($tmpobj->zip != $this->zip) {
762 $tmpobj->zip = $this->zip;
763 $usermustbemodified++;
765 if ($tmpobj->zip != $this->zip) {
766 $tmpobj->state_id = $this->state_id;
767 $usermustbemodified++;
769 if ($tmpobj->country_id != $this->country_id) {
770 $tmpobj->country_id = $this->country_id;
771 $usermustbemodified++;
773 if ($tmpobj->email != $this->email) {
774 $tmpobj->email = $this->email;
775 $usermustbemodified++;
777 if (!empty(array_diff($tmpobj->socialnetworks, $this->socialnetworks))) {
778 $tmpobj->socialnetworks = $this->socialnetworks;
779 $usermustbemodified++;
781 if ($usermustbemodified) {
782 $result = $tmpobj->update($user, 0, 1, 1, 1);
789 if (!$error && !$notrigger) {
791 $result = $this->call_trigger(
'CONTACT_MODIFY', $user);
802 dol_syslog(get_class($this).
"::update Error ".$this->error, LOG_ERR);
803 $this->db->rollback();
807 $this->error = $this->db->lasterror().
' sql='.$sql;
808 $this->db->rollback();
832 } elseif ($mode == 1) {
834 } elseif ($mode == 2) {
851 global
$conf, $langs;
872 $info[
"title"] = $this->poste;
874 if ($this->socid > 0) {
876 $soc->fetch($this->socid);
879 if ($soc->client == 1) {
880 $info[
"businessCategory"] =
"Customers";
882 if ($soc->client == 2) {
883 $info[
"businessCategory"] =
"Prospects";
885 if ($soc->fournisseur == 1) {
886 $info[
"businessCategory"] =
"Suppliers";
921 $info[
"objectclass"][4] =
"phpgwContact";
923 $info[
'uidnumber'] = $this->id;
925 $info[
'phpgwTz'] = 0;
926 $info[
'phpgwMailType'] =
'INTERNET';
927 $info[
'phpgwMailHomeType'] =
'INTERNET';
929 $info[
"phpgwContactTypeId"] =
'n';
930 $info[
"phpgwContactCatId"] = 0;
931 $info[
"phpgwContactAccess"] =
"public";
933 $info[
"phpgwContactOwner"] = 1;
936 $info[
"rfc822Mailbox"] = $this->email;
938 if ($this->phone_mobile) {
939 $info[
"phpgwCellTelephoneNumber"] = $this->phone_mobile;
965 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"socpeople SET";
966 $sql .=
" birthday = ".($this->birthday ?
"'".$this->db->idate($this->birthday).
"'" :
"null");
967 $sql .=
", photo = ".($this->photo ?
"'".$this->db->escape($this->photo).
"'" :
"null");
969 $sql .=
", fk_user_modif = ".((int) $user->id);
971 $sql .=
" WHERE rowid = ".((int) $id);
973 dol_syslog(get_class($this).
"::update_perso this->birthday=".$this->birthday.
" -", LOG_DEBUG);
974 $resql = $this->db->query($sql);
977 $this->error = $this->db->lasterror();
982 if (!empty($this->birthday_alert)) {
984 $sql_check =
"SELECT rowid FROM " . MAIN_DB_PREFIX .
"user_alert WHERE type = 1 AND fk_contact = " . ((int) $id) .
" AND fk_user = " . ((int) $user->id);
985 $result_check = $this->db->query($sql_check);
986 if (!$result_check || ($this->db->num_rows($result_check) < 1)) {
988 $sql =
"INSERT INTO " . MAIN_DB_PREFIX .
"user_alert(type, fk_contact, fk_user) ";
989 $sql .=
"VALUES (1," . ((int) $id) .
"," . ((int) $user->id) .
")";
990 $result = $this->db->query($sql);
993 $this->error = $this->db->lasterror();
999 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"user_alert ";
1000 $sql .=
"WHERE type=1 AND fk_contact=" . ((int) $id) .
" AND fk_user=" . ((int) $user->id);
1001 $result = $this->db->query($sql);
1004 $this->error = $this->db->lasterror();
1008 if (!$error && !$notrigger) {
1010 $result = $this->call_trigger(
'CONTACT_MODIFY', $user);
1019 $this->db->commit();
1022 dol_syslog(get_class($this).
"::update Error ".$this->error, LOG_ERR);
1023 $this->db->rollback();
1040 public function fetch($id, $user =
null, $ref_ext =
'', $email =
'', $loadalsoroles = 0, $socid = 0)
1044 dol_syslog(get_class($this).
"::fetch id=".$id.
" ref_ext=".$ref_ext.
" email=".$email, LOG_DEBUG);
1046 if (empty($id) && empty($ref_ext) && empty($email)) {
1047 $this->error =
'BadParameter';
1051 $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, cef.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 = $langs->trans(
'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($obj->phone);
1146 $this->fax = trim($obj->fax);
1147 $this->phone_perso = trim($obj->phone_perso);
1148 $this->phone_mobile = trim($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();
1335 public function delete($user, $notrigger = 0)
1343 $result = $this->call_trigger(
'CONTACT_DELETE', $user);
1352 $sql =
"SELECT ec.rowid";
1353 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_contact ec,";
1354 $sql .=
" ".MAIN_DB_PREFIX.
"c_type_contact tc";
1355 $sql .=
" WHERE ec.fk_socpeople=".((int) $this->
id);
1356 $sql .=
" AND ec.fk_c_type_contact=tc.rowid";
1357 $sql .=
" AND tc.source='external'";
1359 $resql = $this->db->query($sql);
1361 $num = $this->db->num_rows($resql);
1364 while ($i < $num && !$error) {
1365 $obj = $this->db->fetch_object($resql);
1367 $sqldel =
"DELETE FROM ".MAIN_DB_PREFIX.
"element_contact";
1368 $sqldel .=
" WHERE rowid = ".((int) $obj->rowid);
1370 $result = $this->db->query($sqldel);
1373 $this->error = $this->db->error().
' sql='.$sqldel;
1380 $this->error = $this->db->error().
' sql='.$sql;
1386 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_contacts WHERE fk_socpeople = ".((int) $this->
id);
1388 $resql = $this->db->query($sql);
1391 $this->error .= $this->db->lasterror();
1398 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"notify_def WHERE fk_contact = ".((int) $this->
id);
1400 $resql = $this->db->query($sql);
1403 $this->error .= $this->db->lasterror();
1410 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_contact WHERE fk_socpeople = ".((int) $this->
id);
1412 $resql = $this->db->query($sql);
1415 $this->error .= $this->db->lasterror();
1421 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"socpeople";
1422 $sql .=
" WHERE rowid = ".((int) $this->
id);
1424 $result = $this->db->query($sql);
1427 $this->error = $this->db->error().
' sql='.$sql;
1441 $this->db->commit();
1444 $this->db->rollback();
1459 $sql =
"SELECT c.rowid, c.datec as datec, c.fk_user_creat,";
1460 $sql .=
" GREATEST(c.tms, cef.tms) as tms, c.fk_user_modif";
1461 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as c";
1462 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"socpeople_extrafields as cef ON cef.fk_object=c.rowid";
1463 $sql .=
" WHERE c.rowid = ".((int) $id);
1465 $resql = $this->db->query($sql);
1467 if ($this->db->num_rows($resql)) {
1468 $obj = $this->db->fetch_object($resql);
1470 $this->
id = $obj->rowid;
1472 $this->user_creation_id = $obj->fk_user_creat;
1473 $this->user_modification_id = $obj->fk_user_modif;
1474 $this->date_creation = $this->db->jdate($obj->datec);
1475 $this->date_modification = $this->db->jdate($obj->tms);
1478 $this->db->free($resql);
1480 print $this->db->error();
1491 $sql =
"SELECT count(mc.email) as nb";
1492 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mailing_cibles as mc, ".MAIN_DB_PREFIX.
"mailing as m";
1493 $sql .=
" WHERE mc.fk_mailing=m.rowid AND mc.email = '".$this->db->escape($this->
email).
"' ";
1494 $sql .=
" AND m.entity IN (".getEntity($this->element).
") AND mc.statut NOT IN (-1,0)";
1496 $resql = $this->db->query($sql);
1498 $obj = $this->db->fetch_object($resql);
1499 $nb = (int) $obj->nb;
1501 $this->db->free($resql);
1504 $this->error = $this->db->error();
1517 global
$conf, $langs, $user;
1522 return [
'optimize' => $langs->trans(
"ShowContact")];
1524 if (!empty($this->photo) && class_exists(
'Form')) {
1525 $photo =
'<div class="photointooltip floatright">';
1526 $photo .=
Form::showphoto(
'contact', $this, 0, 40, 0,
'photoref',
'mini', 0);
1528 $datas[
'photo'] = $photo;
1531 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Contact").
'</u> ' . $this->
getLibStatut(4);
1532 $datas[
'name'] =
'<br><b>'.$langs->trans(
"Name").
':</b> '.$this->
getFullName($langs);
1534 if (!empty($this->poste)) {
1535 $datas[
'job'] =
'<br><b>'.$langs->trans(
"Poste").
':</b> '.$this->poste;
1537 $datas[
'email'] =
'<br><b>'.$langs->trans(
"EMail").
':</b> '.$this->email;
1538 $phonelist = array();
1539 $country_code = empty($this->country_code) ?
'' : $this->country_code;
1540 if ($this->phone_pro) {
1541 $phonelist[] =
dol_print_phone($this->phone_pro, $country_code, $this->
id, 0,
'',
' ',
'phone');
1543 if ($this->phone_mobile) {
1544 $phonelist[] =
dol_print_phone($this->phone_mobile, $country_code, $this->
id, 0,
'',
' ',
'mobile');
1546 if ($this->phone_perso) {
1547 $phonelist[] =
dol_print_phone($this->phone_perso, $country_code, $this->
id, 0,
'',
' ',
'phone');
1549 $datas[
'phonelist'] =
'<br><b>'.$langs->trans(
"Phone").
':</b> '.implode(
' ', $phonelist);
1550 $datas[
'address'] =
'<br><b>'.$langs->trans(
"Address").
':</b> '.
dol_format_address($this, 1,
' ', $langs);
1568 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $moreparam =
'', $save_lastsearch_value = -1, $maxlen = 0, $morecss =
'valignmiddle')
1570 global
$conf, $langs, $hookmanager;
1572 if (!empty(
$conf->dol_no_mouse_hover)) {
1579 'objecttype' => $this->element,
1580 'option' => $option,
1582 $classfortooltip =
'classfortooltip';
1585 $classfortooltip =
'classforajaxtooltip';
1586 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1592 $baseurl = DOL_URL_ROOT .
'/contact/card.php';
1593 $query = [
'id' => $this->id];
1594 if ($option !==
'nolink') {
1596 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1597 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1598 $add_save_lastsearch_values = 1;
1600 if ($add_save_lastsearch_values) {
1601 $query = array_merge($query, [
'save_lastsearch_values' => 1]);
1609 if (empty($notooltip)) {
1611 $label = $langs->trans(
"ShowContact");
1612 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1614 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
1615 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1617 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1620 if ($option ==
'nolink') {
1621 $linkstart =
'<span';
1623 $linkstart =
'<a href="'.$url.
'"';
1625 $linkstart .= $linkclose.
'>';
1626 if ($option ==
'nolink') {
1627 $linkend =
'</span>';
1632 $result .= $linkstart;
1635 if ($withpicto < 0) {
1636 $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>';
1637 if ($withpicto != 2 && $withpicto != -2) {
1641 $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);
1644 if ($withpicto != 2 && $withpicto != -2) {
1648 $result .= $linkend;
1651 $hookmanager->initHooks(array(
'contactdao'));
1652 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1653 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1655 $result = $hookmanager->resPrint;
1657 $result .= $hookmanager->resPrint;
1672 $code = ($this->civility_code ? $this->civility_code : (!empty($this->civility_id) ? $this->civility : (!empty($this->civilite) ? $this->civilite :
'')));
1677 $langs->load(
"dict");
1678 return $langs->getLabelFromKey($this->db,
"Civility".$code,
"c_civility",
"code",
"label", $code);
1705 $labelStatus = array(
1706 0 =>
'ActivityCeased',
1709 5 =>
'ActivityCeased',
1711 $labelStatusShort = array(
1712 0 =>
'ActivityCeased',
1715 5 =>
'ActivityCeased',
1718 $statusType =
'status4';
1719 if ($status == 0 || $status == 5) {
1720 $statusType =
'status5';
1723 $label = $langs->transnoentitiesnoconv($labelStatus[$status]);
1724 $labelshort = $langs->transnoentitiesnoconv($labelStatusShort[$status]);
1726 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
1742 if ($status ==
'1') {
1743 $s = ($decorate == 2 ?
'' : $langs->trans(
'ContactPrivate'));
1745 $s =
'<span title="'.$langs->trans(
'ContactPrivateDesc').
'">'.
img_picto(
'',
'private',
'class="paddingrightonly"').$s.
'</span>';
1749 $s = ($decorate == 2 ?
'' : $langs->trans(
'ContactPublic'));
1751 $s =
'<span title="'.$langs->trans(
'ContactPublicDesc').
'">'.
img_picto(
'',
'public',
'class="paddingrightonly"').$s.
'</span>';
1769 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe ORDER BY rowid LIMIT 1";
1770 $resql = $this->db->query($sql);
1772 $obj = $this->db->fetch_object($resql);
1774 $socid = $obj->rowid;
1781 $this->specimen = 1;
1782 $this->lastname =
'DOLIBARR';
1783 $this->firstname =
'SPECIMEN';
1784 $this->
address =
'21 jump street';
1785 $this->zip =
'99999';
1786 $this->town =
'MyTown';
1787 $this->country_id = 1;
1788 $this->country_code =
'FR';
1789 $this->country =
'France';
1790 $this->
email =
'specimen@specimen.com';
1791 $this->socialnetworks = array(
1792 'skype' =>
'tom.hanson',
1793 'twitter' =>
'tomhanson',
1794 'linkedin' =>
'tomhanson',
1796 $this->phone_pro =
'0909090901';
1797 $this->phone_perso =
'0909090902';
1798 $this->phone_mobile =
'0909090903';
1799 $this->fax =
'0909090909';
1801 $this->note_public =
'This is a comment (public)';
1802 $this->note_private =
'This is a comment (private)';
1804 $this->socid = $socid;
1818 global
$conf, $langs, $user;
1823 if (!empty($this->statut) && empty($this->
status)) {
1826 if ($this->
status == $status) {
1830 $this->statut = $status;
1836 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"socpeople";
1837 $sql .=
" SET statut = ".((int) $this->
status);
1838 $sql .=
", fk_user_modif = ".((int) $user->id);
1839 $sql .=
" WHERE rowid = ".((int) $this->
id);
1840 $result = $this->db->query($sql);
1842 dol_syslog(get_class($this).
"::setstatus", LOG_DEBUG);
1845 $result = $this->call_trigger(
'CONTACT_ENABLEDISABLE', $user);
1853 $this->db->rollback();
1856 $this->db->commit();
1874 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1875 return parent::setCategoriesCommon($categories, Categorie::TYPE_CONTACT, $remove_existing);
1889 'socpeople',
'societe_contacts'
1911 $sql =
'DELETE FROM '.$dbs->prefix().
'societe_contacts WHERE rowid IN (';
1912 $sql .=
' SELECT x.rowid FROM (';
1913 $sql .=
' SELECT origin.rowid FROM '.$dbs->prefix().
'societe_contacts as origin';
1914 $sql .=
' INNER JOIN '.$dbs->prefix().
'societe_contacts as dest ON dest.entity = origin.entity';
1915 $sql .=
' AND dest.fk_soc = origin.fk_soc AND dest.fk_c_type_contact = origin.fk_c_type_contact';
1916 $sql .=
' WHERE origin.fk_socpeople = '.((int) $origin_id).
' AND dest.fk_socpeople = '.((int) $dest_id);
1918 if (!$dbs->
query($sql)) {
1932 $sql =
'DELETE FROM '.$dbs->prefix().
'element_contact WHERE rowid IN (';
1933 $sql .=
' SELECT x.rowid FROM (';
1934 $sql .=
' SELECT origin.rowid FROM '.$dbs->prefix().
'element_contact as origin';
1935 $sql .=
' INNER JOIN '.$dbs->prefix().
'element_contact as dest ON dest.element_id = origin.element_id';
1936 $sql .=
' AND dest.fk_c_type_contact = origin.fk_c_type_contact';
1937 $sql .=
' WHERE origin.fk_socpeople = '.((int) $origin_id).
' AND dest.fk_socpeople = '.((int) $dest_id);
1938 $sql .=
" AND origin.fk_c_type_contact IN (SELECT rowid FROM ".$dbs->prefix().
"c_type_contact WHERE source = 'external')";
1940 if (!$dbs->
query($sql)) {
1944 $sql =
'UPDATE '.$dbs->prefix().
'element_contact SET fk_socpeople = '.((int) $dest_id);
1945 $sql .=
' WHERE fk_socpeople = '.((int) $origin_id);
1946 $sql .=
" AND fk_c_type_contact IN (SELECT rowid FROM ".$dbs->prefix().
"c_type_contact WHERE source = 'external')";
1947 if (!$dbs->
query($sql)) {
1954 $polymorphic = array(
1955 array(
'table' =>
'object_lang',
'id' =>
'fk_object',
'type' =>
'type_object',
1956 'values' => array(
'contact',
'socpeople'),
'unique' => array(
'property',
'lang')),
1957 array(
'table' =>
'links',
'id' =>
'objectid',
'type' =>
'objecttype',
1958 'values' => array(
'contact'),
'unique' => array(
'label')),
1959 array(
'table' =>
'element_element',
'id' =>
'fk_source',
'type' =>
'sourcetype',
1960 'values' => array(
'contact'),
'unique' => array(
'fk_target',
'targettype')),
1961 array(
'table' =>
'element_element',
'id' =>
'fk_target',
'type' =>
'targettype',
1962 'values' => array(
'contact'),
'unique' => array(
'fk_source',
'sourcetype')),
1964 array(
'table' =>
'actioncomm',
'id' =>
'fk_element',
'type' =>
'elementtype',
1965 'values' => array(
'contact'),
'unique' => array()),
1969 array(
'table' =>
'ecm_files',
'id' =>
'src_object_id',
'type' =>
'src_object_type',
1970 'values' => array(
'contact',
'socpeople'),
'unique' => array()),
1971 array(
'table' =>
'quickmemo_memo',
'id' =>
'fk_element',
'type' =>
'element_type',
1972 'values' => array(
'contact'),
'unique' => array()),
1973 array(
'table' =>
'comment',
'id' =>
'fk_element',
'type' =>
'element_type',
1974 'values' => array(
'contact'),
'unique' => array()),
1977 foreach ($polymorphic as $ref) {
1979 $sanitizedtable = $dbs->
sanitize($ref[
'table']);
1980 $sanitizedidcol = $dbs->
sanitize($ref[
'id']);
1981 $sanitizedtypecol = $dbs->
sanitize($ref[
'type']);
1987 $quotedvalues = array();
1988 foreach ($ref[
'values'] as $refvalue) {
1989 $quotedvalues[] =
"'".$dbs->escape($refvalue).
"'";
1991 $sanitizedvalues = implode(
', ', $quotedvalues);
1992 $sanitizedtypefilter = $sanitizedtypecol.
" IN (".$sanitizedvalues.
")";
1994 if (!empty($ref[
'unique'])) {
1995 $sql =
"DELETE FROM ".$dbs->prefix().$sanitizedtable.
" WHERE rowid IN (";
1996 $sql .=
" SELECT x.rowid FROM (";
1997 $sql .=
" SELECT origin.rowid FROM ".$dbs->prefix().$sanitizedtable.
" as origin";
1998 $sql .=
" INNER JOIN ".$dbs->prefix().$sanitizedtable.
" as dest";
1999 $sql .=
" ON dest.".$sanitizedtypecol.
" = origin.".$sanitizedtypecol;
2000 foreach ($ref[
'unique'] as $uniquecol) {
2001 $sanitizeduniquecol = $dbs->
sanitize($uniquecol);
2002 $sql .=
" AND dest.".$sanitizeduniquecol.
" = origin.".$sanitizeduniquecol;
2004 $sql .=
" WHERE origin.".$sanitizedidcol.
" = ".((int) $origin_id);
2005 $sql .=
" AND dest.".$sanitizedidcol.
" = ".((int) $dest_id);
2006 $sql .=
" AND origin.".$sanitizedtypefilter;
2008 if (!$dbs->
query($sql)) {
2013 $sql =
"UPDATE ".$dbs->prefix().$sanitizedtable.
" SET ".$sanitizedidcol.
" = ".((int) $dest_id);
2014 $sql .=
" WHERE ".$sanitizedtypefilter;
2015 $sql .=
" AND ".$sanitizedidcol.
" = ".((int) $origin_id);
2016 if (!$dbs->
query($sql)) {
2023 $sql =
"DELETE FROM ".$dbs->prefix().
"element_element WHERE fk_source = fk_target";
2024 $sql .=
" AND sourcetype = targettype AND fk_source = ".((int) $dest_id);
2025 $sql .=
" AND sourcetype = 'contact'";
2026 if (!$dbs->
query($sql)) {
2046 global $langs, $hookmanager, $user, $action;
2049 $langs->loadLangs(array(
'errors',
'companies'));
2053 if (!($this->
id > 0) || empty($this->entity)) {
2054 $this->error = $langs->trans(
'ErrorBadParameters');
2055 dol_syslog(__METHOD__.
' Called on a contact that was not loaded', LOG_ERR);
2058 if ($contact_origin_id <= 0 || $contact_origin_id == $this->
id) {
2059 $this->error = $langs->trans(
'ErrorBadParameters');
2063 if (!$user->hasRight(
'societe',
'contact',
'creer') || !$user->hasRight(
'societe',
'contact',
'supprimer')) {
2064 $this->error = $langs->trans(
'ErrorForbidden');
2068 if ($user->socid > 0) {
2069 $this->error = $langs->trans(
'ErrorForbidden');
2073 $contact_origin =
new Contact($this->db);
2074 $resultfetch = $contact_origin->fetch($contact_origin_id);
2076 if ($resultfetch != $contact_origin_id) {
2077 $this->error = $langs->trans(
'ErrorRecordNotFound');
2078 dol_syslog(__METHOD__.
' Cannot fetch contact id='.$contact_origin_id.
', result='.$resultfetch, LOG_ERR);
2085 $entities = explode(
',',
getEntity(
'contact'));
2086 foreach (array($this, $contact_origin) as $tmpcontact) {
2087 if (!in_array($tmpcontact->entity, $entities) || $tmpcontact->entity != $this->entity) {
2088 $this->error = $langs->trans(
'ErrorContactsMergeDifferentEntity');
2091 if (!empty($tmpcontact->priv) && $tmpcontact->user_creation_id != $user->id) {
2092 $this->error = $langs->trans(
'ErrorContactsMergePrivate');
2097 if ($tmpcontact->socid > 0 && !$user->hasRight(
'societe',
'client',
'voir')
2098 && !$this->isSalesRepresentativeOf($tmpcontact->socid)) {
2099 $this->error = $langs->trans(
'ErrorForbidden');
2105 if (!empty($this->priv) && empty($contact_origin->priv)) {
2106 $this->error = $langs->trans(
'ErrorContactsMergeIntoPrivate');
2111 if ($originlinked < 0 || $destlinked < 0) {
2113 $this->error = $langs->trans(
'ErrorContactsMerge');
2119 if (($originlinked > 0 || $destlinked > 0) && !$user->hasRight(
'user',
'user',
'creer')) {
2120 $this->error = $langs->trans(
'ErrorContactsMergeLinkedToUser');
2124 if ($originlinked > 0 && $destlinked > 0) {
2125 $this->error = $langs->trans(
'ErrorContactsMergeBothLinkedToUser');
2129 dol_syslog(__METHOD__.
' merge contact id='.$contact_origin->id.
' (will be deleted) into the contact id='.$this->id);
2134 foreach (self::MERGE_FIELDS_FILL_IF_EMPTY as $property) {
2135 if (empty($this->$property) && !empty($contact_origin->$property)) {
2136 $this->$property = $contact_origin->$property;
2141 $mention =
'['.$langs->transnoentitiesnoconv(
'MergedFromContact',
dol_print_date(
dol_now(),
'day'), (
string) $contact_origin->id).
']';
2142 foreach (self::MERGE_FIELDS_CONCAT as $property) {
2143 if (!empty($contact_origin->$property)) {
2144 $this->$property =
dol_concatdesc($this->$property, $mention.
"\n".$contact_origin->$property);
2149 if (!empty($contact_origin->priv)) {
2154 if (empty($this->name_alias) && $this->
getFullName($langs) != $contact_origin->getFullName($langs)) {
2155 $this->name_alias = $contact_origin->getFullName($langs);
2159 if (is_array($contact_origin->array_options)) {
2160 foreach ($contact_origin->array_options as $key => $val) {
2161 if (empty($this->array_options[$key])) {
2162 $this->array_options[$key] = $val;
2171 $this->roles =
null;
2174 if ($this->
update($this->
id, $user, 1) <= 0) {
2176 dol_syslog(__METHOD__.
' Failed to update the target contact: '.$this->errorsToString(), LOG_ERR);
2182 include_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2184 $cats_origin = $static_cat->containing($contact_origin->id,
'contact',
'id');
2185 $cats_dest = $static_cat->containing($this->
id,
'contact',
'id');
2188 if (!is_array($cats_origin) || !is_array($cats_dest)) {
2189 $this->error = $static_cat->error;
2190 dol_syslog(__METHOD__.
' Cannot read the categories of the contacts: '.$this->error, LOG_ERR);
2195 $cats = array_merge($cats_origin, $cats_dest);
2196 if ($this->
setCategories(array_values(array_unique($cats))) < 0) {
2210 'ActionComm' =>
'/comm/action/class/actioncomm.class.php',
2211 'Contact' =>
'/contact/class/contact.class.php',
2212 'User' =>
'/user/class/user.class.php',
2214 foreach ($objects as $object_name => $object_file) {
2215 require_once DOL_DOCUMENT_ROOT.$object_file;
2217 if (!$object_name::replaceContact($this->db, $contact_origin->id, $this->id)) {
2219 $this->error = $this->db->lasterror();
2220 dol_syslog(__METHOD__.
' '.$object_name.
'::replaceContact failed: '.$this->error, LOG_ERR);
2233 $parameters = array(
'contact_origin' => $contact_origin->id,
'contact_dest' => $this->id);
2234 $reshook = $hookmanager->executeHooks(
'replaceContact', $parameters, $this, $action);
2237 $this->error = $hookmanager->error;
2238 $this->errors = $hookmanager->errors;
2244 $this->context = array(
2246 'mergefromid' => $contact_origin->id,
2247 'mergefromname' => $contact_origin->getFullName($langs)
2251 $result = $this->call_trigger(
'CONTACT_MODIFY', $user);
2260 if ($contact_origin->delete($user) < 1) {
2261 $this->error = $contact_origin->error;
2262 $this->errors = $contact_origin->errors;
2268 $this->error = $langs->trans(
'ErrorContactsMerge').
' '.$this->error;
2269 $this->db->rollback();
2272 $this->
fetch($this->
id);
2276 $this->db->commit();
2295 $sql =
"SELECT rowid FROM ".$this->db->prefix().
"user WHERE fk_socpeople = ".((int) $contactid);
2297 $resql = $this->db->query($sql);
2299 $this->error = $this->db->lasterror();
2300 dol_syslog(__METHOD__.
' '.$this->error, LOG_ERR);
2303 $found = ($this->db->num_rows($resql) > 0 ? 1 : 0);
2304 $this->db->free($resql);
2320 if (empty($socid)) {
2324 $sql =
"SELECT fk_soc FROM ".$this->db->prefix().
"societe_commerciaux";
2325 $sql .=
" WHERE fk_soc = ".((int) $socid).
" AND fk_user = ".((int) $user->id);
2327 $resql = $this->db->query($sql);
2329 $this->error = $this->db->lasterror();
2330 dol_syslog(__METHOD__.
' '.$this->error, LOG_ERR);
2333 $found = ($this->db->num_rows($resql) > 0);
2334 $this->db->free($resql);
2357 if ($parentofdest == $contact_origin->id) {
2358 $newparent = $this->
getParentId($contact_origin->id);
2362 $sql =
'UPDATE '.$this->db->prefix().
'socpeople';
2363 $sql .=
' SET fk_parent = '.($newparent > 0 ? ((int) $newparent) :
'NULL');
2364 $sql .=
' WHERE rowid = '.((int) $this->
id);
2365 if (!$this->db->query($sql)) {
2366 $this->error = $this->db->lasterror();
2367 dol_syslog(__METHOD__.
' '.$this->error, LOG_ERR);
2373 $ancestors = array();
2376 while ($currentid > 0 && $depth < self::MERGE_MAX_PARENT_DEPTH) {
2377 if (in_array($currentid, $ancestors)) {
2380 $ancestors[] = (int) $currentid;
2385 $sql =
'UPDATE '.$this->db->prefix().
'socpeople SET fk_parent = '.((int) $this->
id);
2386 $sql .=
' WHERE fk_parent = '.((int) $contact_origin->id);
2387 $sql .=
' AND rowid <> '.((int) $this->
id);
2388 if (!empty($ancestors)) {
2390 $sanitizedancestors = implode(
',', $ancestors);
2391 $sql .=
" AND rowid NOT IN (".$sanitizedancestors.
")";
2393 if (!$this->db->query($sql)) {
2394 $this->error = $this->db->lasterror();
2395 dol_syslog(__METHOD__.
' '.$this->error, LOG_ERR);
2402 $sql =
'UPDATE '.$this->db->prefix().
'socpeople SET fk_parent = NULL';
2403 $sql .=
' WHERE fk_parent = '.((int) $contact_origin->id);
2404 if (!$this->db->query($sql)) {
2405 $this->error = $this->db->lasterror();
2406 dol_syslog(__METHOD__.
' '.$this->error, LOG_ERR);
2423 $sql =
"SELECT fk_parent FROM ".$this->db->prefix().
"socpeople WHERE rowid = ".((int) $contactid);
2425 $resql = $this->db->query($sql);
2427 $this->error = $this->db->lasterror();
2428 dol_syslog(__METHOD__.
' '.$this->error, LOG_ERR);
2432 if ($obj = $this->db->fetch_object($resql)) {
2433 $parentid = (empty($obj->fk_parent) ? 0 : (int) $obj->fk_parent);
2435 $this->db->free($resql);
2454 $sql =
'DELETE FROM '.$this->db->prefix().
'notify_def WHERE rowid IN (';
2455 $sql .=
' SELECT x.rowid FROM (';
2456 $sql .=
' SELECT origin.rowid FROM '.$this->db->prefix().
'notify_def as origin';
2457 $sql .=
' INNER JOIN '.$this->db->prefix().
'notify_def as dest ON dest.fk_action = origin.fk_action';
2461 $sql .=
' AND (dest.fk_soc = origin.fk_soc OR (dest.fk_soc IS NULL AND origin.fk_soc IS NULL))';
2462 $sql .=
' AND (dest.entity = origin.entity OR (dest.entity IS NULL AND origin.entity IS NULL))';
2463 $sql .=
' AND (dest.type = origin.type OR (dest.type IS NULL AND origin.type IS NULL))';
2464 $sql .=
' AND (dest.threshold = origin.threshold OR (dest.threshold IS NULL AND origin.threshold IS NULL))';
2465 $sql .=
' AND (dest.context = origin.context OR (dest.context IS NULL AND origin.context IS NULL))';
2466 $sql .=
' AND (dest.fk_user = origin.fk_user OR (dest.fk_user IS NULL AND origin.fk_user IS NULL))';
2467 $sql .=
' AND (dest.email = origin.email OR (dest.email IS NULL AND origin.email IS NULL))';
2468 $sql .=
' WHERE origin.fk_contact = '.((int) $contact_origin->id).
' AND dest.fk_contact = '.((int) $this->
id);
2470 if (!$this->db->query($sql)) {
2471 $this->error = $this->db->lasterror();
2472 dol_syslog(__METHOD__.
' '.$this->error, LOG_ERR);
2477 dol_syslog(__METHOD__.
' Failed to move the notifications: '.$this->db->lasterror(), LOG_ERR);
2482 if ($this->db->DDLListTables((
string) $this->db->database_name, $this->db->prefix().
'mailing_cibles')) {
2486 dol_syslog(__METHOD__.
' Failed to move the mass emailing targets: '.$this->db->lasterror(), LOG_ERR);
2491 $sql =
'UPDATE '.$this->db->prefix().
'mailing_cibles SET source_id = '.((int) $this->
id);
2492 $sql .=
" WHERE source_type = 'contact' AND source_id = ".((int) $contact_origin->id);
2493 if (!$this->db->query($sql)) {
2494 $this->error = $this->db->lasterror();
2495 dol_syslog(__METHOD__.
' '.$this->error, LOG_ERR);
2513 global
$conf, $langs;
2515 if (empty(
$conf->societe->multidir_output[$this->entity])) {
2520 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2523 $srcdir =
$conf->societe->multidir_output[$this->entity].
'/contact/'.((int) $contact_origin_id);
2524 $destdir =
$conf->societe->multidir_output[$this->entity].
'/contact/'.((int) $this->
id);
2532 foreach ($dirlist as $filetomove) {
2533 $destfile = $destdir.
'/'.$filetomove[
'relativename'];
2537 $info = pathinfo($filetomove[
'relativename']);
2538 $suffix = (empty($info[
'extension']) ?
'' :
'.'.$info[
'extension']);
2539 $destfile = $destdir.
'/'.(empty($info[
'dirname']) || $info[
'dirname'] ==
'.' ?
'' : $info[
'dirname'].
'/');
2540 $destfile .= $info[
'filename'].
'-'.((int) $contact_origin_id).$suffix;
2545 if (!
dol_move($filetomove[
'fullname'], $destfile,
'0', 0, 0, 1)) {
2546 $failed[] = $filetomove[
'relativename'];
2550 if (!empty($failed)) {
2551 dol_syslog(__METHOD__.
' Failed to move '.count($failed).
' file(s) from '.$srcdir, LOG_ERR);
2553 $this->warnings[] = $langs->trans(
'WarningContactsMergeFilesNotMoved', implode(
', ', $failed));
2570 $sql =
"SELECT tc.rowid, tc.element, tc.source, tc.code, tc.libelle as label, sc.rowid as contactroleid, sc.fk_soc as socid";
2571 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_contacts as sc, ".MAIN_DB_PREFIX.
"c_type_contact as tc";
2572 $sql .=
" WHERE tc.rowid = sc.fk_c_type_contact";
2573 $sql .=
" AND tc.source = 'external' AND tc.active=1";
2574 $sql .=
" AND sc.fk_socpeople = ".((int) $this->
id);
2575 $sql .=
" AND sc.entity IN (".getEntity(
'societe').
')';
2577 $resql = $this->db->query($sql);
2579 $this->roles = array();
2581 $num = $this->db->num_rows($resql);
2583 while ($obj = $this->db->fetch_object($resql)) {
2584 $transkey =
"TypeContact_".$obj->element.
"_".$obj->source.
"_".$obj->code;
2585 $label_element = $langs->trans(
'ContactDefault_'.$obj->element);
2586 $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));
2591 $this->error = $this->db->lasterror();
2592 $this->errors[] = $this->db->lasterror();
2595 if (empty($error)) {
2613 if ($element ==
'action') {
2614 $element =
'agenda';
2617 $sql =
"SELECT sc.fk_socpeople as id, sc.fk_c_type_contact";
2618 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact tc";
2619 $sql .=
", ".MAIN_DB_PREFIX.
"societe_contacts sc";
2620 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"socpeople sp";
2621 $sql .=
" ON sc.fk_socpeople = sp.rowid AND sp.statut = 1";
2622 $sql .=
" WHERE sc.fk_soc = ".((int) $this->socid);
2623 $sql .=
" AND sc.fk_c_type_contact=tc.rowid";
2624 $sql .=
" AND tc.element = '".$this->db->escape($element).
"'";
2625 $sql .=
" AND sp.entity IN (".getEntity(
'contact').
")";
2626 $sql .=
" AND tc.active = 1";
2628 $resql = $this->db->query($sql);
2630 $num = $this->db->num_rows($resql);
2633 $obj = $this->db->fetch_object($resql);
2634 $tab[$obj->id] = array(
'fk_socpeople' => $obj->id,
'type_contact' => $obj->fk_c_type_contact);
2641 $this->error = $this->db->error();
2660 if (!isset($this->roles)) {
2666 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_contacts WHERE fk_socpeople=".((int) $this->
id).
" AND entity IN (".
getEntity(
"contact").
")";
2668 $result = $this->db->query($sql);
2670 $this->errors[] = $this->db->lasterror().
' sql='.$sql;
2673 if (count($this->roles) > 0) {
2674 foreach ($this->roles as $keyRoles => $valRoles) {
2675 if (empty($valRoles)) {
2679 if (is_array($valRoles)) {
2680 $idrole = $valRoles[
'id'];
2682 $idrole = $valRoles;
2686 if (is_array($valRoles)) {
2687 $socid = $valRoles[
'socid'];
2689 $socid = $this->socid;
2693 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_contacts";
2694 $sql .=
" (entity,";
2695 $sql .=
"date_creation,";
2697 $sql .=
"fk_c_type_contact,";
2698 $sql .=
"fk_socpeople) ";
2699 $sql .=
" VALUES (".((int)
$conf->entity).
",";
2700 $sql .=
"'".$this->db->idate(
dol_now()).
"',";
2701 $sql .= ((int) $socid).
", ";
2702 $sql .= ((int) $idrole).
" , ";
2703 $sql .= ((int) $this->
id);
2706 $result = $this->db->query($sql);
2708 $this->errors[] = $this->db->lasterror().
' sql='.$sql;
2715 if (empty($error)) {
2716 $this->db->commit();
2719 $this->error = implode(
' ', $this->errors);
2720 $this->db->rollback();
2735 $sql =
"SELECT id, code, libelle as label, picto FROM ".MAIN_DB_PREFIX.
"c_stcommcontact";
2737 $sql .=
" WHERE active = ".((int) $active);
2739 $resql = $this->db->query($sql);
2740 $num = $this->db->num_rows($resql);
2743 $obj = $this->db->fetch_object($resql);
2744 $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);
2770 $lib = $langs->trans(
"ProspectLevel".$fk_prospectlevel);
2772 if ($lib ==
"ProspectLevel".$fk_prospectlevel) {
2773 $lib = $langs->getLabelFromKey($this->db, $fk_prospectlevel,
'c_prospectlevel',
'code',
'label');
2788 return $this->
update($this->
id, $user);
2800 return $this->
libProspCommStatut($this->stcomm_id, $mode, $label, $this->stcomm_picto);
2819 $langs->load(
'customers');
2822 if ($statut ==
'-1' || $statut ==
'ST_NO') {
2823 return img_action($langs->trans(
"StatusProspect-1"),
'-1', $picto).
' '.$langs->trans(
"StatusProspect-1");
2824 } elseif ($statut ==
'0' || $statut ==
'ST_NEVER') {
2825 return img_action($langs->trans(
"StatusProspect0"),
'0', $picto).
' '.$langs->trans(
"StatusProspect0");
2826 } elseif ($statut ==
'1' || $statut ==
'ST_TODO') {
2827 return img_action($langs->trans(
"StatusProspect1"),
'1', $picto).
' '.$langs->trans(
"StatusProspect1");
2828 } elseif ($statut ==
'2' || $statut ==
'ST_PEND') {
2829 return img_action($langs->trans(
"StatusProspect2"),
'2', $picto).
' '.$langs->trans(
"StatusProspect2");
2830 } elseif ($statut ==
'3' || $statut ==
'ST_DONE') {
2831 return img_action($langs->trans(
"StatusProspect3"),
'3', $picto).
' '.$langs->trans(
"StatusProspect3");
2833 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);
2837 if ($statut ==
'-1' || $statut ==
'ST_NO') {
2838 return img_action($langs->trans(
"StatusProspect-1"),
'-1', $picto);
2839 } elseif ($statut ==
'0' || $statut ==
'ST_NEVER') {
2840 return img_action($langs->trans(
"StatusProspect0"),
'0', $picto);
2841 } elseif ($statut ==
'1' || $statut ==
'ST_TODO') {
2842 return img_action($langs->trans(
"StatusProspect1"),
'1', $picto);
2843 } elseif ($statut ==
'2' || $statut ==
'ST_PEND') {
2844 return img_action($langs->trans(
"StatusProspect2"),
'2', $picto);
2845 } elseif ($statut ==
'3' || $statut ==
'ST_DONE') {
2846 return img_action($langs->trans(
"StatusProspect3"),
'3', $picto);
2848 return img_action(($langs->trans(
"StatusProspect".$statut) !=
"StatusProspect".$statut) ? $langs->trans(
"StatusProspect".$statut) : $label,
'0', $picto);
2852 if ($statut ==
'-1' || $statut ==
'ST_NO') {
2853 return img_action($langs->trans(
"StatusProspect-1"),
'-1', $picto).
' '.$langs->trans(
"StatusProspect-1");
2854 } elseif ($statut ==
'0' || $statut ==
'ST_NEVER') {
2855 return img_action($langs->trans(
"StatusProspect0"),
'0', $picto).
' '.$langs->trans(
"StatusProspect0");
2856 } elseif ($statut ==
'1' || $statut ==
'ST_TODO') {
2857 return img_action($langs->trans(
"StatusProspect1"),
'1', $picto).
' '.$langs->trans(
"StatusProspect1");
2858 } elseif ($statut ==
'2' || $statut ==
'ST_PEND') {
2859 return img_action($langs->trans(
"StatusProspect2"),
'2', $picto).
' '.$langs->trans(
"StatusProspect2");
2860 } elseif ($statut ==
'3' || $statut ==
'ST_DONE') {
2861 return img_action($langs->trans(
"StatusProspect3"),
'3', $picto).
' '.$langs->trans(
"StatusProspect3");
2863 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);
2867 return "Error, mode/status not found";
2886 $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).
"'";
2887 $resql = $this->db->query($sql);
2889 $obj = $this->db->fetch_object($resql);
2890 $noemail = $obj->nb;
2891 if (empty($noemail)) {
2892 $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()).
"')";
2893 $resql = $this->db->query($sql);
2896 $this->error = $this->db->lasterror();
2897 $this->errors[] = $this->error;
2902 $this->error = $this->db->lasterror();
2903 $this->errors[] = $this->error;
2906 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE email = '".$this->db->escape($this->
email).
"' AND entity IN (".
getEntity(
'mailing', 0).
")";
2907 $resql = $this->db->query($sql);
2910 $this->error = $this->db->lasterror();
2911 $this->errors[] = $this->error;
2915 if (empty($error)) {
2916 $this->no_email = $no_email;
2917 $this->db->commit();
2920 $this->db->rollback();
2937 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE entity IN (".
getEntity(
'mailing').
") AND email = '".$this->db->escape($this->
email).
"'";
2938 $resql = $this->db->query($sql);
2940 $obj = $this->db->fetch_object($resql);
2941 $this->no_email = $obj->nb;
2944 $this->error = $this->db->lasterror();
2945 $this->errors[] = $this->error;
2962 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
2964 $return =
'<div class="box-flex-item box-flex-grow-zero">';
2965 $return .=
'<div class="info-box info-box-sm">';
2966 $return .=
'<span class="info-box-icon bg-infobox-action">';
2967 if (!is_null($this->photo)) {
2968 $return .=
Form::showphoto(
'contact', $this, 0, 60, 0,
'photokanban photoref photowithmargin photologintooltip',
'small', 0, 1);
2972 $return .=
'</span>';
2973 $return .=
'<div class="info-box-content">';
2974 $return .=
'<div class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . $this->
getNomUrl(0) .
'</div>';
2975 if ($selected >= 0) {
2976 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
2978 if (is_object($this->thirdparty)) {
2979 $return .=
'<div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).
'</div>';
2989 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
2990 $return .=
'</div>';
2991 $return .=
'</div>';
2992 $return .=
'</div>';
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...
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_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.
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.
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)
div refaddress div address
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_action($titlealt, $numaction, $picto='', $moreatt='')
Show logo action.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.