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';
58 public $element =
'contact';
63 public $table_element =
'socpeople';
68 public $picto =
'contact';
99 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -2,
'noteditable' => 1,
'notnull' => 1,
'index' => 1,
'position' => 1,
'comment' =>
'Id',
'css' =>
'left'),
100 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => 3,
'notnull' => 1,
'position' => 30,
'index' => 1),
101 'ref_ext' => array(
'type' =>
'varchar(255)',
'label' =>
'RefExt',
'enabled' => 1,
'visible' => 0,
'position' => 35),
102 'civility' => array(
'type' =>
'varchar(6)',
'label' =>
'Civility',
'enabled' => 1,
'visible' => 3,
'position' => 40),
103 'lastname' => array(
'type' =>
'varchar(50)',
'label' =>
'Lastname',
'enabled' => 1,
'visible' => 1,
'position' => 45,
'showoncombobox' => 1,
'searchall' => 1),
104 'name_alias' => array(
'type' =>
'varchar(255)',
'label' =>
'Name alias',
'enabled' => 1,
'visible' => -1,
'position' => 46,
'searchall' => 1),
105 'firstname' => array(
'type' =>
'varchar(50)',
'label' =>
'Firstname',
'enabled' => 1,
'visible' => 1,
'position' => 50,
'showoncombobox' => 1,
'searchall' => 1),
106 'poste' => array(
'type' =>
'varchar(80)',
'label' =>
'PostOrFunction',
'enabled' => 1,
'visible' => -1,
'position' => 52),
107 'address' => array(
'type' =>
'varchar(255)',
'label' =>
'Address',
'enabled' => 1,
'visible' => -1,
'position' => 55),
108 'zip' => array(
'type' =>
'varchar(25)',
'label' =>
'Zip',
'enabled' => 1,
'visible' => -1,
'position' => 60),
109 'town' => array(
'type' =>
'varchar(50)',
'label' =>
'Town',
'enabled' => 1,
'visible' => -1,
'position' => 65),
110 'fk_departement' => array(
'type' =>
'integer',
'label' =>
'Fk departement',
'enabled' => 1,
'visible' => 3,
'position' => 70),
111 'fk_pays' => array(
'type' =>
'integer',
'label' =>
'Fk pays',
'enabled' => 1,
'visible' => 3,
'position' => 75),
112 'fk_soc' => array(
'type' =>
'integer:Societe:societe/class/societe.class.php',
'label' =>
'ThirdParty',
'enabled' => 1,
'visible' => 1,
'position' => 77,
'searchall' => 1),
113 'birthday' => array(
'type' =>
'date',
'label' =>
'Birthday',
'enabled' => 1,
'visible' => -1,
'position' => 80),
114 'phone' => array(
'type' =>
'varchar(30)',
'label' =>
'Phone',
'enabled' => 1,
'visible' => 1,
'position' => 90,
'searchall' => 1),
115 'phone_perso' => array(
'type' =>
'varchar(30)',
'label' =>
'PhonePerso',
'enabled' => 1,
'visible' => -1,
'position' => 95,
'searchall' => 1),
116 'phone_mobile' => array(
'type' =>
'varchar(30)',
'label' =>
'PhoneMobile',
'enabled' => 1,
'visible' => 1,
'position' => 100,
'searchall' => 1),
117 'fax' => array(
'type' =>
'varchar(30)',
'label' =>
'Fax',
'enabled' => 1,
'visible' => -1,
'position' => 105,
'searchall' => 1),
118 'email' => array(
'type' =>
'varchar(255)',
'label' =>
'Email',
'enabled' => 1,
'visible' => 1,
'position' => 110,
'searchall' => 1),
119 'socialnetworks' => array(
'type' =>
'text',
'label' =>
'SocialNetworks',
'enabled' => 1,
'visible' => 3,
'position' => 115),
120 'photo' => array(
'type' =>
'varchar(255)',
'label' =>
'Photo',
'enabled' => 1,
'visible' => 3,
'position' => 170),
121 'priv' => array(
'type' =>
'smallint(6)',
'label' =>
'ContactVisibility',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'position' => 175),
122 'fk_stcommcontact' => array(
'type' =>
'integer',
'label' =>
'ProspectStatus',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 220),
123 'fk_prospectcontactlevel' => array(
'type' =>
'varchar(12)',
'label' =>
'ProspectLevel',
'enabled' => 1,
'visible' => -1,
'position' => 255),
125 'note_private' => array(
'type' =>
'html',
'label' =>
'NotePrivate',
'enabled' => 1,
'visible' => 0,
'position' => 195,
'searchall' => 1),
126 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 0,
'position' => 200,
'searchall' => 1),
127 'default_lang' => array(
'type' =>
'varchar(6)',
'label' =>
'Default lang',
'enabled' => 1,
'visible' => 3,
'position' => 205),
128 'canvas' => array(
'type' =>
'varchar(32)',
'label' =>
'Canvas',
'enabled' => 1,
'visible' => 3,
'position' => 210),
129 'ip' => array(
'type' =>
'ip',
'label' =>
'IPAddress',
'enabled' =>
'1',
'position' => 700,
'notnull' => 0,
'visible' =>
'-2',
'comment' =>
'ip used to create record (for public submission page)'),
130 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -1,
'position' => 300),
131 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 305),
132 'fk_user_creat' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserAuthor',
'enabled' => 1,
'visible' => 3,
'position' => 310),
133 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => 3,
'position' => 315),
134 'statut' => array(
'type' =>
'tinyint(4)',
'label' =>
'Status',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'position' => 500),
135 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -1,
'position' => 1000),
145 public $civility_code;
159 public $birthday_alert;
269 public $socialnetworks;
289 public $phone_mobile;
310 public $default_lang;
315 public $ref_facturation;
325 public $ref_commande;
356 public $cacheprospectstatus = array();
361 public $fk_prospectlevel;
371 public $statut_commercial;
376 public $stcomm_picto;
389 $this->ismultientitymanaged = 1;
390 $this->isextrafieldmanaged = 1;
392 $this->fields[
'ref_ext'][
'visible'] =
getDolGlobalInt(
'MAIN_LIST_SHOW_REF_EXT');
395 $this->fields[
'no_email'][
'enabled'] = 0;
399 $this->fields[
'fk_soc'][
'enabled'] = 0;
400 $this->fields[
'fk_soc'][
'searchall'] = 0;
405 $this->fields[
'fk_stcommcontact'][
'enabled'] = 0;
406 $this->fields[
'fk_prospectcontactlevel'][
'enabled'] = 0;
410 foreach ($this->fields as $key => $val) {
411 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
412 unset($this->fields[$key]);
439 global $user, $hookmanager;
444 $sql =
"SELECT count(sp.rowid) as nb";
445 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as sp";
446 if (!$user->hasRight(
'societe',
'client',
'voir')) {
447 $sql .=
", ".MAIN_DB_PREFIX.
"societe as s";
448 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
449 $sql .=
" WHERE sp.fk_soc = s.rowid AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
452 $sql .=
" ".$clause.
" sp.entity IN (".
getEntity($this->element).
")";
453 $sql .=
" AND (sp.priv='0' OR (sp.priv='1' AND sp.fk_user_creat = ".((int) $user->id).
"))";
454 if ($user->socid > 0) {
455 $sql .=
" AND sp.fk_soc = ".((int) $user->socid);
458 if (is_object($hookmanager)) {
459 $parameters = array();
460 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $this);
461 $sql .= $hookmanager->resPrint;
464 $resql = $this->db->query($sql);
466 while ($obj = $this->db->fetch_object($resql)) {
467 $this->nb[
"contacts"] = $obj->nb;
469 $this->db->free($resql);
473 $this->error = $this->db->lasterror();
485 public function create($user, $notrigger = 0)
492 if (empty($this->date_creation)) {
493 $this->date_creation = $now;
499 $this->name_alias = trim($this->name_alias);
500 $this->lastname = $this->lastname ? trim($this->lastname) : trim($this->
name);
501 $this->firstname = trim($this->firstname);
503 if (empty($this->socid)) {
506 if (empty($this->priv)) {
509 if (!empty($this->statut) && empty($this->
status)) {
512 if (empty($this->
status)) {
520 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"socpeople (";
523 $sql .=
", name_alias";
524 $sql .=
", lastname";
525 $sql .=
", firstname";
526 $sql .=
", fk_user_creat";
528 $sql .=
", fk_stcommcontact";
533 $sql .=
", import_key";
535 $sql .=
") VALUES (";
536 $sql .=
"'".$this->db->idate($now).
"',";
537 if ($this->socid > 0) {
538 $sql .=
" ".((int) $this->socid).
",";
542 $sql .=
"'".$this->db->escape($this->name_alias).
"',";
543 $sql .=
"'".$this->db->escape($this->lastname).
"',";
544 $sql .=
"'".$this->db->escape($this->firstname).
"',";
545 $sql .=
" ".($user->id > 0 ? ((int) $user->id) :
"null").
",";
546 $sql .=
" ".((int) $this->priv).
",";
548 $sql .=
" ".((int) $this->
status).
",";
549 $sql .=
" ".(!empty($this->canvas) ?
"'".$this->db->escape($this->canvas).
"'" :
"null").
",";
550 $sql .=
" ".((int) $this->entity).
",";
551 $sql .=
"'".$this->db->escape($this->ref_ext).
"',";
552 $sql .=
" ".(!empty($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null").
",";
553 $sql .=
" ".(!empty($this->ip) ?
"'".$this->db->escape($this->ip).
"'" :
"null");
556 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
557 $resql = $this->db->query($sql);
559 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"socpeople");
561 $result = $this->
update($this->
id, $user, 1,
'add');
564 $this->error = $this->db->lasterror();
571 $this->error = $this->db->lasterror();
575 if (!$error && !$notrigger) {
577 $result = $this->call_trigger(
'CONTACT_CREATE', $user);
588 $this->db->rollback();
589 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
593 $this->error = $this->db->lasterror();
595 $this->db->rollback();
596 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
611 public function update($id, $user =
null, $notrigger = 0, $action =
'update', $nosyncuser = 0)
615 if (empty($this->country_id) && !empty($this->country_code)) {
616 $country_id =
getCountry($this->country_code,
'3');
617 $this->country_id = is_int($country_id) ? $country_id : 0;
624 $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity);
627 $this->ref_ext = (empty($this->ref_ext) ?
'' : trim($this->ref_ext));
628 $this->name_alias = trim($this->name_alias);
629 $this->lastname = trim($this->lastname) ? trim($this->lastname) : trim($this->lastname);
630 $this->firstname = trim($this->firstname);
632 $this->phone_pro = trim($this->phone_pro);
633 $this->phone_perso = trim($this->phone_perso);
634 $this->phone_mobile = trim($this->phone_mobile);
635 $this->photo = trim($this->photo);
636 $this->fax = trim($this->fax);
637 $this->zip = (empty($this->zip) ?
'' : trim($this->zip));
638 $this->town = (empty($this->town) ?
'' : trim($this->town));
639 $this->country_id = (empty($this->country_id) || $this->country_id < 0) ? 0 : $this->country_id;
640 if (!empty($this->statut) && empty($this->
status)) {
643 if (empty($this->
status)) {
647 if (empty($this->civility_code) && !is_numeric($this->civility_id)) {
648 $this->civility_code = $this->civility_id;
654 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"socpeople SET";
655 if ($this->socid > 0) {
656 $sql .=
" fk_soc = ".((int) $this->socid).
",";
657 } elseif ($this->socid == -1) {
658 $sql .=
" fk_soc = NULL,";
660 $sql .=
" civility='".$this->db->escape($this->civility_code).
"'";
661 $sql .=
", name_alias='".$this->db->escape($this->name_alias).
"'";
662 $sql .=
", lastname='".$this->db->escape($this->lastname).
"'";
663 $sql .=
", firstname='".$this->db->escape($this->firstname).
"'";
664 $sql .=
", address='".$this->db->escape((
string) $this->
address).
"'";
665 $sql .=
", zip='".$this->db->escape($this->zip).
"'";
666 $sql .=
", town='".$this->db->escape($this->town).
"'";
667 $sql .=
", ref_ext = ".(!empty($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"NULL");
668 $sql .=
", fk_pays=".($this->country_id > 0 ? $this->country_id :
'NULL');
669 $sql .=
", fk_departement=".($this->state_id > 0 ? $this->state_id :
'NULL');
670 $sql .=
", poste='".$this->db->escape($this->poste).
"'";
671 $sql .=
", fax='".$this->db->escape($this->fax).
"'";
672 $sql .=
", email='".$this->db->escape($this->
email).
"'";
673 $sql .=
", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
674 $sql .=
", photo='".$this->db->escape($this->photo).
"'";
675 $sql .=
", birthday=".($this->birthday ?
"'".$this->db->idate($this->birthday).
"'" :
"null");
676 $sql .=
", note_private = ".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"NULL");
677 $sql .=
", note_public = ".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"NULL");
678 $sql .=
", phone = ".(isset($this->phone_pro) ?
"'".$this->db->escape($this->phone_pro).
"'" :
"NULL");
679 $sql .=
", phone_perso = ".(isset($this->phone_perso) ?
"'".$this->db->escape($this->phone_perso).
"'" :
"NULL");
680 $sql .=
", phone_mobile = ".(isset($this->phone_mobile) ?
"'".$this->db->escape($this->phone_mobile).
"'" :
"NULL");
681 $sql .=
", priv = ".((int) $this->priv);
682 $sql .=
", fk_prospectlevel = '".$this->db->escape($this->fk_prospectlevel).
"'";
683 if (isset($this->stcomm_id)) {
684 $sql .=
", fk_stcommcontact = ".($this->stcomm_id > 0 || $this->stcomm_id == -1 ? $this->stcomm_id :
"0");
686 $sql .=
", statut = ".((int) $this->
status);
687 $sql .=
", fk_user_modif=".($user->id > 0 ?
"'".$this->db->escape((
string) $user->id).
"'" :
"NULL");
688 $sql .=
", default_lang=".($this->default_lang ?
"'".$this->db->escape($this->default_lang).
"'" :
"NULL");
689 $sql .=
", entity = ".((int) $this->entity);
690 $sql .=
" WHERE rowid = ".((int) $id);
692 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
693 $result = $this->db->query($sql);
695 unset($this->country_code);
696 unset($this->country);
697 unset($this->state_code);
715 if (!$error && $this->user_id > 0) {
717 $tmpobj =
new User($this->db);
718 $tmpobj->fetch($this->user_id);
719 $usermustbemodified = 0;
720 if ($tmpobj->office_phone != $this->phone_pro) {
721 $tmpobj->office_phone = $this->phone_pro;
722 $usermustbemodified++;
724 if ($tmpobj->office_fax != $this->fax) {
725 $tmpobj->office_fax = $this->fax;
726 $usermustbemodified++;
728 if ($tmpobj->address != $this->address) {
729 $tmpobj->address = $this->address;
730 $usermustbemodified++;
732 if ($tmpobj->town != $this->town) {
733 $tmpobj->town = $this->town;
734 $usermustbemodified++;
736 if ($tmpobj->zip != $this->zip) {
737 $tmpobj->zip = $this->zip;
738 $usermustbemodified++;
740 if ($tmpobj->zip != $this->zip) {
741 $tmpobj->state_id = $this->state_id;
742 $usermustbemodified++;
744 if ($tmpobj->country_id != $this->country_id) {
745 $tmpobj->country_id = $this->country_id;
746 $usermustbemodified++;
748 if ($tmpobj->email != $this->email) {
749 $tmpobj->email = $this->email;
750 $usermustbemodified++;
752 if (!empty(array_diff($tmpobj->socialnetworks, $this->socialnetworks))) {
753 $tmpobj->socialnetworks = $this->socialnetworks;
754 $usermustbemodified++;
756 if ($usermustbemodified) {
757 $result = $tmpobj->update($user, 0, 1, 1, 1);
764 if (!$error && !$notrigger) {
766 $result = $this->call_trigger(
'CONTACT_MODIFY', $user);
777 dol_syslog(get_class($this).
"::update Error ".$this->error, LOG_ERR);
778 $this->db->rollback();
782 $this->error = $this->db->lasterror().
' sql='.$sql;
783 $this->db->rollback();
807 } elseif ($mode == 1) {
809 } elseif ($mode == 2) {
826 global $conf, $langs;
847 $info[
"title"] = $this->poste;
849 if ($this->socid > 0) {
851 $soc->fetch($this->socid);
854 if ($soc->client == 1) {
855 $info[
"businessCategory"] =
"Customers";
857 if ($soc->client == 2) {
858 $info[
"businessCategory"] =
"Prospects";
860 if ($soc->fournisseur == 1) {
861 $info[
"businessCategory"] =
"Suppliers";
896 $info[
"objectclass"][4] =
"phpgwContact";
898 $info[
'uidnumber'] = $this->id;
900 $info[
'phpgwTz'] = 0;
901 $info[
'phpgwMailType'] =
'INTERNET';
902 $info[
'phpgwMailHomeType'] =
'INTERNET';
904 $info[
"phpgwContactTypeId"] =
'n';
905 $info[
"phpgwContactCatId"] = 0;
906 $info[
"phpgwContactAccess"] =
"public";
908 $info[
"phpgwContactOwner"] = 1;
911 $info[
"rfc822Mailbox"] = $this->email;
913 if ($this->phone_mobile) {
914 $info[
"phpgwCellTelephoneNumber"] = $this->phone_mobile;
940 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"socpeople SET";
941 $sql .=
" birthday = ".($this->birthday ?
"'".$this->db->idate($this->birthday).
"'" :
"null");
942 $sql .=
", photo = ".($this->photo ?
"'".$this->db->escape($this->photo).
"'" :
"null");
944 $sql .=
", fk_user_modif = ".((int) $user->id);
946 $sql .=
" WHERE rowid = ".((int) $id);
948 dol_syslog(get_class($this).
"::update_perso this->birthday=".$this->birthday.
" -", LOG_DEBUG);
949 $resql = $this->db->query($sql);
952 $this->error = $this->db->lasterror();
957 if (!empty($this->birthday_alert)) {
959 $sql_check =
"SELECT rowid FROM " . MAIN_DB_PREFIX .
"user_alert WHERE type = 1 AND fk_contact = " . ((int) $id) .
" AND fk_user = " . ((int) $user->id);
960 $result_check = $this->db->query($sql_check);
961 if (!$result_check || ($this->db->num_rows($result_check) < 1)) {
963 $sql =
"INSERT INTO " . MAIN_DB_PREFIX .
"user_alert(type, fk_contact, fk_user) ";
964 $sql .=
"VALUES (1," . ((int) $id) .
"," . ((int) $user->id) .
")";
965 $result = $this->db->query($sql);
968 $this->error = $this->db->lasterror();
974 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"user_alert ";
975 $sql .=
"WHERE type=1 AND fk_contact=" . ((int) $id) .
" AND fk_user=" . ((int) $user->id);
976 $result = $this->db->query($sql);
979 $this->error = $this->db->lasterror();
983 if (!$error && !$notrigger) {
985 $result = $this->call_trigger(
'CONTACT_MODIFY', $user);
997 dol_syslog(get_class($this).
"::update Error ".$this->error, LOG_ERR);
998 $this->db->rollback();
1015 public function fetch($id, $user =
null, $ref_ext =
'', $email =
'', $loadalsoroles = 0, $socid = 0)
1019 dol_syslog(get_class($this).
"::fetch id=".$id.
" ref_ext=".$ref_ext.
" email=".$email, LOG_DEBUG);
1021 if (empty($id) && empty($ref_ext) && empty($email)) {
1022 $this->error =
'BadParameter';
1026 $langs->loadLangs(array(
"dict",
"companies"));
1028 $sql =
"SELECT c.rowid, c.entity, c.fk_soc, c.ref_ext, c.civility as civility_code, c.name_alias, c.lastname, c.firstname,";
1029 $sql .=
" c.address, c.statut as status, c.zip, c.town,";
1030 $sql .=
" c.fk_pays as country_id,";
1031 $sql .=
" c.fk_departement as state_id,";
1032 $sql .=
" c.birthday,";
1033 $sql .=
" c.poste, c.phone, c.phone_perso, c.phone_mobile, c.fax, c.email,";
1034 $sql .=
" c.socialnetworks,";
1035 $sql .=
" c.photo,";
1036 $sql .=
" c.priv, c.note_private, c.note_public, c.default_lang, c.canvas,";
1037 $sql .=
" c.fk_prospectlevel, c.fk_stcommcontact, st.libelle as stcomm, st.picto as stcomm_picto,";
1038 $sql .=
" c.import_key,";
1039 $sql .=
" c.datec as date_creation, GREATEST(c.tms, cef.tms) as date_modification, c.fk_user_creat, c.fk_user_modif,";
1040 $sql .=
" co.label as country, co.code as country_code,";
1041 $sql .=
" d.nom as state, d.code_departement as state_code,";
1042 $sql .=
" u.rowid as user_id, u.login as user_login,";
1043 $sql .=
" s.nom as socname, s.address as socaddress, s.zip as soccp, s.town as soccity, s.default_lang as socdefault_lang";
1044 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as c";
1045 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"socpeople_extrafields as cef ON cef.fk_object=c.rowid";
1046 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as co ON c.fk_pays = co.rowid";
1047 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_departements as d ON c.fk_departement = d.rowid";
1048 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u ON c.rowid = u.fk_socpeople";
1049 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON c.fk_soc = s.rowid";
1050 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_stcommcontact as st ON c.fk_stcommcontact = st.id';
1052 $sql .=
" WHERE c.rowid = ".((int) $id);
1054 $sql .=
" WHERE c.entity IN (".getEntity($this->element).
")";
1056 $sql .=
" AND c.ref_ext = '".$this->db->escape($ref_ext).
"'";
1059 $sql .=
" AND c.email = '".$this->db->escape($email).
"'";
1062 $sql .=
" AND c.fk_soc = ".((int) $socid);
1066 $resql = $this->db->query($sql);
1068 $num = $this->db->num_rows($resql);
1070 $this->error =
'Fetch found several records. Rename one of contact to avoid duplicate.';
1075 $obj = $this->db->fetch_object($resql);
1077 $this->
id = $obj->rowid;
1078 $this->entity = $obj->entity;
1079 $this->
ref = $obj->rowid;
1080 $this->ref_ext = $obj->ref_ext;
1082 $this->civility_code = $obj->civility_code;
1083 $this->civility = $obj->civility_code ? ($langs->trans(
"Civility".$obj->civility_code) !=
"Civility".$obj->civility_code ? $langs->trans(
"Civility".$obj->civility_code) : $obj->civility_code) :
'';
1085 $this->name_alias = $obj->name_alias;
1086 $this->lastname = $obj->lastname;
1087 $this->firstname = $obj->firstname;
1088 $this->
address = $obj->address;
1089 $this->zip = $obj->zip;
1090 $this->town = $obj->town;
1092 $this->date_creation = $this->db->jdate($obj->date_creation);
1093 $this->date_modification = $this->db->jdate($obj->date_modification);
1094 $this->user_creation_id = $obj->fk_user_creat;
1095 $this->user_modification_id = $obj->fk_user_modif;
1097 $this->state_id = $obj->state_id;
1098 $this->state_code = $obj->state_code;
1099 $this->state = $obj->state;
1101 $this->country_id = $obj->country_id;
1102 $this->country_code = $obj->country_id ? $obj->country_code :
'';
1103 $this->country = $obj->country_id ? ($langs->trans(
'Country'.$obj->country_code) !=
'Country'.$obj->country_code ? $langs->transnoentities(
'Country'.$obj->country_code) : $obj->country) :
'';
1105 $this->fk_soc = $obj->fk_soc;
1106 $this->socid = $obj->fk_soc;
1107 $this->socname = $obj->socname;
1108 $this->poste = $obj->poste;
1109 $this->
status = $obj->status;
1110 $this->statut = $obj->status;
1112 $this->fk_prospectlevel = $obj->fk_prospectlevel;
1114 $transcode = $langs->trans(
'StatusProspect'.$obj->fk_stcommcontact);
1115 $libelle = ($transcode !=
'StatusProspect'.$obj->fk_stcommcontact ? $transcode : $obj->stcomm);
1116 $this->stcomm_id = $obj->fk_stcommcontact;
1117 $this->statut_commercial = $libelle;
1118 $this->stcomm_picto = $obj->stcomm_picto;
1120 $this->phone_pro = trim($obj->phone);
1121 $this->fax = trim($obj->fax);
1122 $this->phone_perso = trim($obj->phone_perso);
1123 $this->phone_mobile = trim($obj->phone_mobile);
1125 $this->
email = $obj->email;
1126 $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks,
true) : array());
1127 $this->photo = $obj->photo;
1128 $this->priv = $obj->priv;
1129 $this->mail = $obj->email;
1131 $this->birthday = $this->db->jdate($obj->birthday);
1132 $this->note = $obj->note_private;
1133 $this->note_private = $obj->note_private;
1134 $this->note_public = $obj->note_public;
1135 $this->default_lang = $obj->default_lang;
1136 $this->user_id = $obj->user_id;
1137 $this->user_login = $obj->user_login;
1138 $this->canvas = $obj->canvas;
1140 $this->import_key = $obj->import_key;
1146 $sql =
"SELECT u.rowid ";
1147 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
1148 $sql .=
" WHERE u.fk_socpeople = ".((int) $this->
id);
1150 $resql = $this->db->query($sql);
1152 if ($this->db->num_rows($resql)) {
1153 $uobj = $this->db->fetch_object($resql);
1155 $this->user_id = $uobj->rowid;
1157 $this->db->free($resql);
1159 $this->error = $this->db->error();
1169 $sql =
"SELECT fk_user";
1170 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user_alert";
1171 $sql .=
" WHERE fk_user = ".((int) $user->id).
" AND fk_contact = ".((int) $id);
1173 $resql = $this->db->query($sql);
1175 if ($this->db->num_rows($resql)) {
1176 $obj = $this->db->fetch_object($resql);
1178 $this->birthday_alert = 1;
1180 $this->db->free($resql);
1182 $this->error = $this->db->error();
1188 if ($loadalsoroles) {
1190 if ($resultRole < 0) {
1197 $langs->load(
'errors');
1198 $this->error = $langs->trans(
"ErrorRecordNotFound");
1202 $this->error = $this->db->error();
1220 public function findNearest($id = 0, $lastname =
'', $firstname =
'', $ref_ext =
'', $email =
'', $ref_alias =
'', $socid = 0)
1232 $tmpcontact =
new Contact($this->db);
1233 $result = $tmpcontact->fetch($id,
null, $ref_ext, $email, 0, $socid);
1248 unset($this->gender);
1250 if (in_array($this->civility_id, array(
'MR')) || in_array($this->civility_code, array(
'MR'))) {
1251 $this->gender =
'man';
1252 } elseif (in_array($this->civility_id, array(
'MME',
'MLE')) || in_array($this->civility_code, array(
'MME',
'MLE'))) {
1253 $this->gender =
'woman';
1271 $sql =
"SELECT tc.element, count(ec.rowid) as nb";
1272 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_contact as ec, ".MAIN_DB_PREFIX.
"c_type_contact as tc";
1273 $sql .=
" WHERE ec.fk_c_type_contact = tc.rowid";
1274 $sql .=
" AND fk_socpeople = ".((int) $this->
id);
1275 $sql .=
" AND tc.source = 'external'";
1276 $sql .=
" GROUP BY tc.element";
1278 dol_syslog(get_class($this).
"::load_ref_elements", LOG_DEBUG);
1280 $resql = $this->db->query($sql);
1282 while ($obj = $this->db->fetch_object($resql)) {
1284 if ($obj->element ==
'facture') {
1285 $this->ref_facturation = $obj->nb;
1286 } elseif ($obj->element ==
'contrat') {
1287 $this->ref_contrat = $obj->nb;
1288 } elseif ($obj->element ==
'commande') {
1289 $this->ref_commande = $obj->nb;
1290 } elseif ($obj->element ==
'propal') {
1291 $this->ref_propal = $obj->nb;
1295 $this->db->free($resql);
1298 $this->error = $this->db->lasterror();
1310 public function delete($user, $notrigger = 0)
1318 $result = $this->call_trigger(
'CONTACT_DELETE', $user);
1327 $sql =
"SELECT ec.rowid";
1328 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_contact ec,";
1329 $sql .=
" ".MAIN_DB_PREFIX.
"c_type_contact tc";
1330 $sql .=
" WHERE ec.fk_socpeople=".((int) $this->
id);
1331 $sql .=
" AND ec.fk_c_type_contact=tc.rowid";
1332 $sql .=
" AND tc.source='external'";
1334 $resql = $this->db->query($sql);
1336 $num = $this->db->num_rows($resql);
1339 while ($i < $num && !$error) {
1340 $obj = $this->db->fetch_object($resql);
1342 $sqldel =
"DELETE FROM ".MAIN_DB_PREFIX.
"element_contact";
1343 $sqldel .=
" WHERE rowid = ".((int) $obj->rowid);
1345 $result = $this->db->query($sqldel);
1348 $this->error = $this->db->error().
' sql='.$sqldel;
1355 $this->error = $this->db->error().
' sql='.$sql;
1361 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_contacts WHERE fk_socpeople = ".((int) $this->
id);
1363 $resql = $this->db->query($sql);
1366 $this->error .= $this->db->lasterror();
1373 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"notify_def WHERE fk_contact = ".((int) $this->
id);
1375 $resql = $this->db->query($sql);
1378 $this->error .= $this->db->lasterror();
1385 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_contact WHERE fk_socpeople = ".((int) $this->
id);
1387 $resql = $this->db->query($sql);
1390 $this->error .= $this->db->lasterror();
1396 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"socpeople";
1397 $sql .=
" WHERE rowid = ".((int) $this->
id);
1399 $result = $this->db->query($sql);
1402 $this->error = $this->db->error().
' sql='.$sql;
1416 $this->db->commit();
1419 $this->db->rollback();
1434 $sql =
"SELECT c.rowid, c.datec as datec, c.fk_user_creat,";
1435 $sql .=
" GREATEST(c.tms, cef.tms) as tms, c.fk_user_modif";
1436 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as c";
1437 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"socpeople_extrafields as cef ON cef.fk_object=c.rowid";
1438 $sql .=
" WHERE c.rowid = ".((int) $id);
1440 $resql = $this->db->query($sql);
1442 if ($this->db->num_rows($resql)) {
1443 $obj = $this->db->fetch_object($resql);
1445 $this->
id = $obj->rowid;
1447 $this->user_creation_id = $obj->fk_user_creat;
1448 $this->user_modification_id = $obj->fk_user_modif;
1449 $this->date_creation = $this->db->jdate($obj->datec);
1450 $this->date_modification = $this->db->jdate($obj->tms);
1453 $this->db->free($resql);
1455 print $this->db->error();
1466 $sql =
"SELECT count(mc.email) as nb";
1467 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mailing_cibles as mc, ".MAIN_DB_PREFIX.
"mailing as m";
1468 $sql .=
" WHERE mc.fk_mailing=m.rowid AND mc.email = '".$this->db->escape($this->
email).
"' ";
1469 $sql .=
" AND m.entity IN (".getEntity($this->element).
") AND mc.statut NOT IN (-1,0)";
1471 $resql = $this->db->query($sql);
1473 $obj = $this->db->fetch_object($resql);
1474 $nb = (int) $obj->nb;
1476 $this->db->free($resql);
1479 $this->error = $this->db->error();
1492 global $conf, $langs, $user;
1497 return [
'optimize' => $langs->trans(
"ShowContact")];
1499 if (!empty($this->photo) && class_exists(
'Form')) {
1500 $photo =
'<div class="photointooltip floatright">';
1501 $photo .=
Form::showphoto(
'contact', $this, 0, 40, 0,
'photoref',
'mini', 0);
1503 $datas[
'photo'] = $photo;
1506 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Contact").
'</u> ' . $this->
getLibStatut(4);
1507 $datas[
'name'] =
'<br><b>'.$langs->trans(
"Name").
':</b> '.$this->
getFullName($langs);
1509 if (!empty($this->poste)) {
1510 $datas[
'job'] =
'<br><b>'.$langs->trans(
"Poste").
':</b> '.$this->poste;
1512 $datas[
'email'] =
'<br><b>'.$langs->trans(
"EMail").
':</b> '.$this->email;
1513 $phonelist = array();
1514 $country_code = empty($this->country_code) ?
'' : $this->country_code;
1515 if ($this->phone_pro) {
1516 $phonelist[] =
dol_print_phone($this->phone_pro, $country_code, $this->
id, 0,
'',
' ',
'phone');
1518 if ($this->phone_mobile) {
1519 $phonelist[] =
dol_print_phone($this->phone_mobile, $country_code, $this->
id, 0,
'',
' ',
'mobile');
1521 if ($this->phone_perso) {
1522 $phonelist[] =
dol_print_phone($this->phone_perso, $country_code, $this->
id, 0,
'',
' ',
'phone');
1524 $datas[
'phonelist'] =
'<br><b>'.$langs->trans(
"Phone").
':</b> '.implode(
' ', $phonelist);
1525 $datas[
'address'] =
'<br><b>'.$langs->trans(
"Address").
':</b> '.
dol_format_address($this, 1,
' ', $langs);
1543 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $moreparam =
'', $save_lastsearch_value = -1, $maxlen = 0, $morecss =
'valignmiddle')
1545 global $conf, $langs, $hookmanager;
1547 if (!empty($conf->dol_no_mouse_hover)) {
1554 'objecttype' => $this->element,
1555 'option' => $option,
1557 $classfortooltip =
'classfortooltip';
1560 $classfortooltip =
'classforajaxtooltip';
1561 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1567 $baseurl = DOL_URL_ROOT .
'/contact/card.php';
1568 $query = [
'id' => $this->id];
1569 if ($option !==
'nolink') {
1571 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1572 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1573 $add_save_lastsearch_values = 1;
1575 if ($add_save_lastsearch_values) {
1576 $query = array_merge($query, [
'save_lastsearch_values' => 1]);
1584 if (empty($notooltip)) {
1586 $label = $langs->trans(
"ShowContact");
1587 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1589 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
1590 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1592 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1595 if ($option ==
'nolink') {
1596 $linkstart =
'<span';
1598 $linkstart =
'<a href="'.$url.
'"';
1600 $linkstart .= $linkclose.
'>';
1601 if ($option ==
'nolink') {
1602 $linkend =
'</span>';
1607 $result .= $linkstart;
1610 if ($withpicto < 0) {
1611 $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>';
1612 if ($withpicto != 2 && $withpicto != -2) {
1616 $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);
1619 if ($withpicto != 2 && $withpicto != -2) {
1623 $result .= $linkend;
1626 $hookmanager->initHooks(array(
'contactdao'));
1627 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1628 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1630 $result = $hookmanager->resPrint;
1632 $result .= $hookmanager->resPrint;
1647 $code = ($this->civility_code ? $this->civility_code : (!empty($this->civility_id) ? $this->civility : (!empty($this->civilite) ? $this->civilite :
'')));
1652 $langs->load(
"dict");
1653 return $langs->getLabelFromKey($this->db,
"Civility".$code,
"c_civility",
"code",
"label", $code);
1680 $labelStatus = array(
1681 0 =>
'ActivityCeased',
1684 5 =>
'ActivityCeased',
1686 $labelStatusShort = array(
1687 0 =>
'ActivityCeased',
1690 5 =>
'ActivityCeased',
1693 $statusType =
'status4';
1694 if ($status == 0 || $status == 5) {
1695 $statusType =
'status5';
1698 $label = $langs->transnoentitiesnoconv($labelStatus[$status]);
1699 $labelshort = $langs->transnoentitiesnoconv($labelStatusShort[$status]);
1701 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
1716 if ($status ==
'1') {
1717 return $langs->trans(
'ContactPrivate');
1719 return $langs->trans(
'ContactPublic');
1735 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe ORDER BY rowid LIMIT 1";
1736 $resql = $this->db->query($sql);
1738 $obj = $this->db->fetch_object($resql);
1740 $socid = $obj->rowid;
1747 $this->specimen = 1;
1748 $this->lastname =
'DOLIBARR';
1749 $this->firstname =
'SPECIMEN';
1750 $this->
address =
'21 jump street';
1751 $this->zip =
'99999';
1752 $this->town =
'MyTown';
1753 $this->country_id = 1;
1754 $this->country_code =
'FR';
1755 $this->country =
'France';
1756 $this->
email =
'specimen@specimen.com';
1757 $this->socialnetworks = array(
1758 'skype' =>
'tom.hanson',
1759 'twitter' =>
'tomhanson',
1760 'linkedin' =>
'tomhanson',
1762 $this->phone_pro =
'0909090901';
1763 $this->phone_perso =
'0909090902';
1764 $this->phone_mobile =
'0909090903';
1765 $this->fax =
'0909090909';
1767 $this->note_public =
'This is a comment (public)';
1768 $this->note_private =
'This is a comment (private)';
1770 $this->socid = $socid;
1784 global $conf, $langs, $user;
1789 if (!empty($this->statut) && empty($this->
status)) {
1792 if ($this->
status == $status) {
1796 $this->statut = $status;
1802 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"socpeople";
1803 $sql .=
" SET statut = ".((int) $this->
status);
1804 $sql .=
", fk_user_modif = ".((int) $user->id);
1805 $sql .=
" WHERE rowid = ".((int) $this->
id);
1806 $result = $this->db->query($sql);
1808 dol_syslog(get_class($this).
"::setstatus", LOG_DEBUG);
1811 $result = $this->call_trigger(
'CONTACT_ENABLEDISABLE', $user);
1819 $this->db->rollback();
1822 $this->db->commit();
1840 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1841 return parent::setCategoriesCommon($categories, Categorie::TYPE_CONTACT, $remove_existing);
1855 'socpeople',
'societe_contacts'
1874 $sql =
"SELECT tc.rowid, tc.element, tc.source, tc.code, tc.libelle as label, sc.rowid as contactroleid, sc.fk_soc as socid";
1875 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_contacts as sc, ".MAIN_DB_PREFIX.
"c_type_contact as tc";
1876 $sql .=
" WHERE tc.rowid = sc.fk_c_type_contact";
1877 $sql .=
" AND tc.source = 'external' AND tc.active=1";
1878 $sql .=
" AND sc.fk_socpeople = ".((int) $this->
id);
1879 $sql .=
" AND sc.entity IN (".getEntity(
'societe').
')';
1881 $resql = $this->db->query($sql);
1883 $this->roles = array();
1885 $num = $this->db->num_rows($resql);
1887 while ($obj = $this->db->fetch_object($resql)) {
1888 $transkey =
"TypeContact_".$obj->element.
"_".$obj->source.
"_".$obj->code;
1889 $libelle_element = $langs->trans(
'ContactDefault_'.$obj->element);
1890 $this->roles[$obj->contactroleid] = array(
'id' => $obj->rowid,
'socid' => $obj->socid,
'element' => $obj->element,
'source' => $obj->source,
'code' => $obj->code,
'label' => $libelle_element.
' - '.($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->label));
1895 $this->error = $this->db->lasterror();
1896 $this->errors[] = $this->db->lasterror();
1899 if (empty($error)) {
1917 if ($element ==
'action') {
1918 $element =
'agenda';
1921 $sql =
"SELECT sc.fk_socpeople as id, sc.fk_c_type_contact";
1922 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact tc";
1923 $sql .=
", ".MAIN_DB_PREFIX.
"societe_contacts sc";
1924 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"socpeople sp";
1925 $sql .=
" ON sc.fk_socpeople = sp.rowid AND sp.statut = 1";
1926 $sql .=
" WHERE sc.fk_soc = ".((int) $this->socid);
1927 $sql .=
" AND sc.fk_c_type_contact=tc.rowid";
1928 $sql .=
" AND tc.element = '".$this->db->escape($element).
"'";
1929 $sql .=
" AND sp.entity IN (".getEntity(
'contact').
")";
1930 $sql .=
" AND tc.active = 1";
1932 $resql = $this->db->query($sql);
1934 $num = $this->db->num_rows($resql);
1937 $obj = $this->db->fetch_object($resql);
1938 $tab[$obj->id] = array(
'fk_socpeople' => $obj->id,
'type_contact' => $obj->fk_c_type_contact);
1945 $this->error = $this->db->error();
1964 if (!isset($this->roles)) {
1970 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_contacts WHERE fk_socpeople=".((int) $this->
id).
" AND entity IN (".
getEntity(
"contact").
")";
1972 $result = $this->db->query($sql);
1974 $this->errors[] = $this->db->lasterror().
' sql='.$sql;
1977 if (count($this->roles) > 0) {
1978 foreach ($this->roles as $keyRoles => $valRoles) {
1979 if (empty($valRoles)) {
1983 if (is_array($valRoles)) {
1984 $idrole = $valRoles[
'id'];
1986 $idrole = $valRoles;
1990 if (is_array($valRoles)) {
1991 $socid = $valRoles[
'socid'];
1993 $socid = $this->socid;
1997 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_contacts";
1998 $sql .=
" (entity,";
1999 $sql .=
"date_creation,";
2001 $sql .=
"fk_c_type_contact,";
2002 $sql .=
"fk_socpeople) ";
2003 $sql .=
" VALUES (".$conf->entity.
",";
2004 $sql .=
"'".$this->db->idate(
dol_now()).
"',";
2005 $sql .= $socid.
", ";
2006 $sql .= $idrole.
" , ";
2010 $result = $this->db->query($sql);
2012 $this->errors[] = $this->db->lasterror().
' sql='.$sql;
2019 if (empty($error)) {
2020 $this->db->commit();
2023 $this->error = implode(
' ', $this->errors);
2024 $this->db->rollback();
2039 $sql =
"SELECT id, code, libelle as label, picto FROM ".MAIN_DB_PREFIX.
"c_stcommcontact";
2041 $sql .=
" WHERE active = ".((int) $active);
2043 $resql = $this->db->query($sql);
2044 $num = $this->db->num_rows($resql);
2047 $obj = $this->db->fetch_object($resql);
2048 $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);
2074 $lib = $langs->trans(
"ProspectLevel".$fk_prospectlevel);
2076 if ($lib ==
"ProspectLevel".$fk_prospectlevel) {
2077 $lib = $langs->getLabelFromKey($this->db, $fk_prospectlevel,
'c_prospectlevel',
'code',
'label');
2092 return $this->
update($this->
id, $user);
2104 return $this->
libProspCommStatut($this->stcomm_id, $mode, $label, $this->stcomm_picto);
2123 $langs->load(
'customers');
2126 if ($statut ==
'-1' || $statut ==
'ST_NO') {
2127 return img_action($langs->trans(
"StatusProspect-1"),
'-1', $picto).
' '.$langs->trans(
"StatusProspect-1");
2128 } elseif ($statut ==
'0' || $statut ==
'ST_NEVER') {
2129 return img_action($langs->trans(
"StatusProspect0"),
'0', $picto).
' '.$langs->trans(
"StatusProspect0");
2130 } elseif ($statut ==
'1' || $statut ==
'ST_TODO') {
2131 return img_action($langs->trans(
"StatusProspect1"),
'1', $picto).
' '.$langs->trans(
"StatusProspect1");
2132 } elseif ($statut ==
'2' || $statut ==
'ST_PEND') {
2133 return img_action($langs->trans(
"StatusProspect2"),
'2', $picto).
' '.$langs->trans(
"StatusProspect2");
2134 } elseif ($statut ==
'3' || $statut ==
'ST_DONE') {
2135 return img_action($langs->trans(
"StatusProspect3"),
'3', $picto).
' '.$langs->trans(
"StatusProspect3");
2137 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);
2141 if ($statut ==
'-1' || $statut ==
'ST_NO') {
2142 return img_action($langs->trans(
"StatusProspect-1"),
'-1', $picto);
2143 } elseif ($statut ==
'0' || $statut ==
'ST_NEVER') {
2144 return img_action($langs->trans(
"StatusProspect0"),
'0', $picto);
2145 } elseif ($statut ==
'1' || $statut ==
'ST_TODO') {
2146 return img_action($langs->trans(
"StatusProspect1"),
'1', $picto);
2147 } elseif ($statut ==
'2' || $statut ==
'ST_PEND') {
2148 return img_action($langs->trans(
"StatusProspect2"),
'2', $picto);
2149 } elseif ($statut ==
'3' || $statut ==
'ST_DONE') {
2150 return img_action($langs->trans(
"StatusProspect3"),
'3', $picto);
2152 return img_action(($langs->trans(
"StatusProspect".$statut) !=
"StatusProspect".$statut) ? $langs->trans(
"StatusProspect".$statut) : $label,
'0', $picto);
2156 if ($statut ==
'-1' || $statut ==
'ST_NO') {
2157 return img_action($langs->trans(
"StatusProspect-1"),
'-1', $picto).
' '.$langs->trans(
"StatusProspect-1");
2158 } elseif ($statut ==
'0' || $statut ==
'ST_NEVER') {
2159 return img_action($langs->trans(
"StatusProspect0"),
'0', $picto).
' '.$langs->trans(
"StatusProspect0");
2160 } elseif ($statut ==
'1' || $statut ==
'ST_TODO') {
2161 return img_action($langs->trans(
"StatusProspect1"),
'1', $picto).
' '.$langs->trans(
"StatusProspect1");
2162 } elseif ($statut ==
'2' || $statut ==
'ST_PEND') {
2163 return img_action($langs->trans(
"StatusProspect2"),
'2', $picto).
' '.$langs->trans(
"StatusProspect2");
2164 } elseif ($statut ==
'3' || $statut ==
'ST_DONE') {
2165 return img_action($langs->trans(
"StatusProspect3"),
'3', $picto).
' '.$langs->trans(
"StatusProspect3");
2167 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);
2171 return "Error, mode/status not found";
2190 $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).
"'";
2191 $resql = $this->db->query($sql);
2193 $obj = $this->db->fetch_object($resql);
2194 $noemail = $obj->nb;
2195 if (empty($noemail)) {
2196 $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()).
"')";
2197 $resql = $this->db->query($sql);
2200 $this->error = $this->db->lasterror();
2201 $this->errors[] = $this->error;
2206 $this->error = $this->db->lasterror();
2207 $this->errors[] = $this->error;
2210 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE email = '".$this->db->escape($this->
email).
"' AND entity IN (".
getEntity(
'mailing', 0).
")";
2211 $resql = $this->db->query($sql);
2214 $this->error = $this->db->lasterror();
2215 $this->errors[] = $this->error;
2219 if (empty($error)) {
2220 $this->no_email = $no_email;
2221 $this->db->commit();
2224 $this->db->rollback();
2241 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE entity IN (".
getEntity(
'mailing').
") AND email = '".$this->db->escape($this->
email).
"'";
2242 $resql = $this->db->query($sql);
2244 $obj = $this->db->fetch_object($resql);
2245 $this->no_email = $obj->nb;
2248 $this->error = $this->db->lasterror();
2249 $this->errors[] = $this->error;
2266 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
2268 $return =
'<div class="box-flex-item box-flex-grow-zero">';
2269 $return .=
'<div class="info-box info-box-sm">';
2270 $return .=
'<span class="info-box-icon bg-infobox-action">';
2271 if (!is_null($this->photo)) {
2272 $return .=
Form::showphoto(
'contact', $this, 0, 60, 0,
'photokanban photoref photowithmargin photologintooltip',
'small', 0, 1);
2276 $return .=
'</span>';
2277 $return .=
'<div class="info-box-content">';
2278 $return .=
'<div class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . $this->
getNomUrl(0) .
'</div>';
2279 if ($selected >= 0) {
2280 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
2282 if (is_object($this->thirdparty)) {
2283 $return .=
'<div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).
'</div>';
2293 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
2294 $return .=
'</div>';
2295 $return .=
'</div>';
2296 $return .=
'</div>';
Parent class of all other business classes (invoices, contracts, proposals, orders,...
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.
Class to manage Dolibarr database access.
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_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.
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)
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.
dolBuildUrl($url, $params=[], $addtoken=false)
Return path of url.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
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)
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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...
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.
div refaddress div address
$conf db name
Only used if Module[ID]Name translation string is not found.