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';
52 public $element =
'contact';
57 public $table_element =
'socpeople';
62 public $picto =
'contact';
93 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -2,
'noteditable' => 1,
'notnull' => 1,
'index' => 1,
'position' => 1,
'comment' =>
'Id',
'css' =>
'left'),
94 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => 3,
'notnull' => 1,
'position' => 30,
'index' => 1),
95 'ref_ext' => array(
'type' =>
'varchar(255)',
'label' =>
'RefExt',
'enabled' => 1,
'visible' => 0,
'position' => 35),
96 'civility' => array(
'type' =>
'varchar(6)',
'label' =>
'Civility',
'enabled' => 1,
'visible' => 3,
'position' => 40),
97 'lastname' => array(
'type' =>
'varchar(50)',
'label' =>
'Lastname',
'enabled' => 1,
'visible' => 1,
'position' => 45,
'showoncombobox' => 1,
'searchall' => 1),
98 'name_alias' => array(
'type' =>
'varchar(255)',
'label' =>
'Name alias',
'enabled' => 1,
'visible' => -1,
'position' => 46,
'searchall' => 1),
99 'firstname' => array(
'type' =>
'varchar(50)',
'label' =>
'Firstname',
'enabled' => 1,
'visible' => 1,
'position' => 50,
'showoncombobox' => 1,
'searchall' => 1),
100 'poste' => array(
'type' =>
'varchar(80)',
'label' =>
'PostOrFunction',
'enabled' => 1,
'visible' => -1,
'position' => 52),
101 'address' => array(
'type' =>
'varchar(255)',
'label' =>
'Address',
'enabled' => 1,
'visible' => -1,
'position' => 55),
102 'zip' => array(
'type' =>
'varchar(25)',
'label' =>
'Zip',
'enabled' => 1,
'visible' => -1,
'position' => 60),
103 'town' => array(
'type' =>
'varchar(50)',
'label' =>
'Town',
'enabled' => 1,
'visible' => -1,
'position' => 65),
104 'fk_departement' => array(
'type' =>
'integer',
'label' =>
'Fk departement',
'enabled' => 1,
'visible' => 3,
'position' => 70),
105 'fk_pays' => array(
'type' =>
'integer',
'label' =>
'Fk pays',
'enabled' => 1,
'visible' => 3,
'position' => 75),
106 'fk_soc' => array(
'type' =>
'integer:Societe:societe/class/societe.class.php',
'label' =>
'ThirdParty',
'enabled' => 1,
'visible' => 1,
'position' => 77,
'searchall' => 1),
107 'birthday' => array(
'type' =>
'date',
'label' =>
'Birthday',
'enabled' => 1,
'visible' => -1,
'position' => 80),
108 'phone' => array(
'type' =>
'varchar(30)',
'label' =>
'Phone',
'enabled' => 1,
'visible' => 1,
'position' => 90,
'searchall' => 1),
109 'phone_perso' => array(
'type' =>
'varchar(30)',
'label' =>
'PhonePerso',
'enabled' => 1,
'visible' => -1,
'position' => 95,
'searchall' => 1),
110 'phone_mobile' => array(
'type' =>
'varchar(30)',
'label' =>
'PhoneMobile',
'enabled' => 1,
'visible' => 1,
'position' => 100,
'searchall' => 1),
111 'fax' => array(
'type' =>
'varchar(30)',
'label' =>
'Fax',
'enabled' => 1,
'visible' => -1,
'position' => 105,
'searchall' => 1),
112 'email' => array(
'type' =>
'varchar(255)',
'label' =>
'Email',
'enabled' => 1,
'visible' => 1,
'position' => 110,
'searchall' => 1),
113 'socialnetworks' => array(
'type' =>
'text',
'label' =>
'SocialNetworks',
'enabled' => 1,
'visible' => 3,
'position' => 115),
114 'photo' => array(
'type' =>
'varchar(255)',
'label' =>
'Photo',
'enabled' => 1,
'visible' => 3,
'position' => 170),
115 'priv' => array(
'type' =>
'smallint(6)',
'label' =>
'ContactVisibility',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'position' => 175),
116 'fk_stcommcontact' => array(
'type' =>
'integer',
'label' =>
'ProspectStatus',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 220),
117 'fk_prospectcontactlevel' => array(
'type' =>
'varchar(12)',
'label' =>
'ProspectLevel',
'enabled' => 1,
'visible' => -1,
'position' => 255),
119 'note_private' => array(
'type' =>
'html',
'label' =>
'NotePrivate',
'enabled' => 1,
'visible' => 3,
'position' => 195,
'searchall' => 1),
120 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 3,
'position' => 200,
'searchall' => 1),
121 'default_lang' => array(
'type' =>
'varchar(6)',
'label' =>
'Default lang',
'enabled' => 1,
'visible' => 3,
'position' => 205),
122 'canvas' => array(
'type' =>
'varchar(32)',
'label' =>
'Canvas',
'enabled' => 1,
'visible' => 3,
'position' => 210),
123 'ip' => array(
'type' =>
'ip',
'label' =>
'IPAddress',
'enabled' =>
'1',
'position' => 700,
'notnull' => 0,
'visible' =>
'-2',
'comment' =>
'ip used to create record (for public submission page)'),
124 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -1,
'position' => 300),
125 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 305),
126 'fk_user_creat' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserAuthor',
'enabled' => 1,
'visible' => 3,
'position' => 310),
127 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => 3,
'position' => 315),
128 'statut' => array(
'type' =>
'tinyint(4)',
'label' =>
'Status',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'position' => 500),
129 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -1,
'position' => 1000),
139 public $civility_code;
158 public $birthday_alert;
267 public $socialnetworks;
287 public $phone_mobile;
308 public $default_lang;
313 public $ref_facturation;
323 public $ref_commande;
354 public $cacheprospectstatus = array();
359 public $fk_prospectlevel;
369 public $statut_commercial;
374 public $stcomm_picto;
386 $this->ismultientitymanaged = 1;
387 $this->isextrafieldmanaged = 1;
389 $this->fields[
'ref_ext'][
'visible'] =
getDolGlobalInt(
'MAIN_LIST_SHOW_REF_EXT');
391 if (!isModEnabled(
'mailing')) {
392 $this->fields[
'no_email'][
'enabled'] = 0;
396 $this->fields[
'fk_soc'][
'enabled'] = 0;
397 $this->fields[
'fk_soc'][
'searchall'] = 0;
402 $this->fields[
'fk_stcommcontact'][
'enabled'] = 0;
403 $this->fields[
'fk_prospectcontactlevel'][
'enabled'] = 0;
407 foreach ($this->fields as $key => $val) {
408 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
409 unset($this->fields[$key]);
436 global $user, $hookmanager;
441 $sql =
"SELECT count(sp.rowid) as nb";
442 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as sp";
443 if (!$user->hasRight(
'societe',
'client',
'voir')) {
444 $sql .=
", ".MAIN_DB_PREFIX.
"societe as s";
445 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
446 $sql .=
" WHERE sp.fk_soc = s.rowid AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
449 $sql .=
" ".$clause.
" sp.entity IN (".
getEntity($this->element).
")";
450 $sql .=
" AND (sp.priv='0' OR (sp.priv='1' AND sp.fk_user_creat = ".((int) $user->id).
"))";
451 if ($user->socid > 0) {
452 $sql .=
" AND sp.fk_soc = ".((int) $user->socid);
455 if (is_object($hookmanager)) {
456 $parameters = array();
457 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $this);
458 $sql .= $hookmanager->resPrint;
461 $resql = $this->db->query($sql);
463 while ($obj = $this->db->fetch_object($resql)) {
464 $this->nb[
"contacts"] = $obj->nb;
466 $this->db->free($resql);
470 $this->error = $this->db->lasterror();
482 public function create($user, $notrigger = 0)
489 if (empty($this->date_creation)) {
490 $this->date_creation = $now;
496 $this->name_alias = trim($this->name_alias);
497 $this->lastname = $this->lastname ? trim($this->lastname) : trim($this->
name);
498 $this->firstname = trim($this->firstname);
500 if (empty($this->socid)) {
503 if (empty($this->priv)) {
506 if (empty($this->statut)) {
513 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"socpeople (";
516 $sql .=
", name_alias";
517 $sql .=
", lastname";
518 $sql .=
", firstname";
519 $sql .=
", fk_user_creat";
521 $sql .=
", fk_stcommcontact";
526 $sql .=
", import_key";
528 $sql .=
") VALUES (";
529 $sql .=
"'".$this->db->idate($now).
"',";
530 if ($this->socid > 0) {
531 $sql .=
" ".((int) $this->socid).
",";
535 $sql .=
"'".$this->db->escape($this->name_alias).
"',";
536 $sql .=
"'".$this->db->escape($this->lastname).
"',";
537 $sql .=
"'".$this->db->escape($this->firstname).
"',";
538 $sql .=
" ".($user->id > 0 ? ((int) $user->id) :
"null").
",";
539 $sql .=
" ".((int) $this->priv).
",";
541 $sql .=
" ".((int) $this->statut).
",";
542 $sql .=
" ".(!empty($this->canvas) ?
"'".$this->db->escape($this->canvas).
"'" :
"null").
",";
543 $sql .=
" ".((int) $this->entity).
",";
544 $sql .=
"'".$this->db->escape($this->ref_ext).
"',";
545 $sql .=
" ".(!empty($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null").
",";
546 $sql .=
" ".(!empty($this->ip) ?
"'".$this->db->escape($this->ip).
"'" :
"null");
549 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
550 $resql = $this->db->query($sql);
552 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"socpeople");
555 $result = $this->
update($this->
id, $user, 1,
'add');
558 $this->error = $this->db->lasterror();
566 $this->error = $this->db->lasterror();
570 if (!$error && !$notrigger) {
583 $this->db->rollback();
584 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
588 $this->error = $this->db->lasterror();
590 $this->db->rollback();
591 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
606 public function update($id, $user =
null, $notrigger = 0, $action =
'update', $nosyncuser = 0)
610 if (empty($this->country_id) && !empty($this->country_code)) {
611 $country_id =
getCountry($this->country_code,
'3');
612 $this->country_id = is_int($country_id) ? $country_id : 0;
619 $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity :
$conf->entity);
622 $this->ref_ext = (empty($this->ref_ext) ?
'' : trim($this->ref_ext));
623 $this->name_alias = trim($this->name_alias);
624 $this->lastname = trim($this->lastname) ? trim($this->lastname) : trim($this->lastname);
625 $this->firstname = trim($this->firstname);
627 $this->phone_pro = trim($this->phone_pro);
628 $this->phone_perso = trim($this->phone_perso);
629 $this->phone_mobile = trim($this->phone_mobile);
630 $this->photo = trim($this->photo);
631 $this->fax = trim($this->fax);
632 $this->zip = (empty($this->zip) ?
'' : trim($this->zip));
633 $this->town = (empty($this->town) ?
'' : trim($this->town));
634 $this->country_id = (empty($this->country_id) || $this->country_id < 0) ? 0 : $this->country_id;
635 if (empty($this->statut)) {
638 if (empty($this->civility_code) && !is_numeric($this->civility_id)) {
639 $this->civility_code = $this->civility_id;
645 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"socpeople SET";
646 if ($this->socid > 0) {
647 $sql .=
" fk_soc = ".((int) $this->socid).
",";
648 } elseif ($this->socid == -1) {
649 $sql .=
" fk_soc = NULL,";
651 $sql .=
" civility='".$this->db->escape($this->civility_code).
"'";
652 $sql .=
", name_alias='".$this->db->escape($this->name_alias).
"'";
653 $sql .=
", lastname='".$this->db->escape($this->lastname).
"'";
654 $sql .=
", firstname='".$this->db->escape($this->firstname).
"'";
655 $sql .=
", address='".$this->db->escape((
string) $this->
address).
"'";
656 $sql .=
", zip='".$this->db->escape($this->zip).
"'";
657 $sql .=
", town='".$this->db->escape($this->town).
"'";
658 $sql .=
", ref_ext = ".(!empty($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"NULL");
659 $sql .=
", fk_pays=".($this->country_id > 0 ? $this->country_id :
'NULL');
660 $sql .=
", fk_departement=".($this->state_id > 0 ? $this->state_id :
'NULL');
661 $sql .=
", poste='".$this->db->escape($this->poste).
"'";
662 $sql .=
", fax='".$this->db->escape($this->fax).
"'";
663 $sql .=
", email='".$this->db->escape($this->
email).
"'";
664 $sql .=
", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
665 $sql .=
", photo='".$this->db->escape($this->photo).
"'";
666 $sql .=
", birthday=".($this->birthday ?
"'".$this->db->idate($this->birthday).
"'" :
"null");
667 $sql .=
", note_private = ".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"NULL");
668 $sql .=
", note_public = ".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"NULL");
669 $sql .=
", phone = ".(isset($this->phone_pro) ?
"'".$this->db->escape($this->phone_pro).
"'" :
"NULL");
670 $sql .=
", phone_perso = ".(isset($this->phone_perso) ?
"'".$this->db->escape($this->phone_perso).
"'" :
"NULL");
671 $sql .=
", phone_mobile = ".(isset($this->phone_mobile) ?
"'".$this->db->escape($this->phone_mobile).
"'" :
"NULL");
672 $sql .=
", priv = ".((int) $this->priv);
673 $sql .=
", fk_prospectlevel = '".$this->db->escape($this->fk_prospectlevel).
"'";
674 if (isset($this->stcomm_id)) {
675 $sql .=
", fk_stcommcontact = ".($this->stcomm_id > 0 || $this->stcomm_id == -1 ? $this->stcomm_id :
"0");
677 $sql .=
", statut = ".((int) $this->statut);
678 $sql .=
", fk_user_modif=".($user->id > 0 ?
"'".$this->db->escape((
string) $user->id).
"'" :
"NULL");
679 $sql .=
", default_lang=".($this->default_lang ?
"'".$this->db->escape($this->default_lang).
"'" :
"NULL");
680 $sql .=
", entity = ".((int) $this->entity);
681 $sql .=
" WHERE rowid = ".((int) $id);
683 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
684 $result = $this->db->query($sql);
686 unset($this->country_code);
687 unset($this->country);
688 unset($this->state_code);
708 if (!$error && $this->user_id > 0) {
710 $tmpobj =
new User($this->db);
711 $tmpobj->fetch($this->user_id);
712 $usermustbemodified = 0;
713 if ($tmpobj->office_phone != $this->phone_pro) {
714 $tmpobj->office_phone = $this->phone_pro;
715 $usermustbemodified++;
717 if ($tmpobj->office_fax != $this->fax) {
718 $tmpobj->office_fax = $this->fax;
719 $usermustbemodified++;
721 if ($tmpobj->address != $this->address) {
722 $tmpobj->address = $this->address;
723 $usermustbemodified++;
725 if ($tmpobj->town != $this->town) {
726 $tmpobj->town = $this->town;
727 $usermustbemodified++;
729 if ($tmpobj->zip != $this->zip) {
730 $tmpobj->zip = $this->zip;
731 $usermustbemodified++;
733 if ($tmpobj->state_id != $this->state_id) {
734 $tmpobj->state_id = $this->state_id;
735 $usermustbemodified++;
737 if ($tmpobj->country_id != $this->country_id) {
738 $tmpobj->country_id = $this->country_id;
739 $usermustbemodified++;
741 if ($tmpobj->email != $this->email) {
742 $tmpobj->email = $this->email;
743 $usermustbemodified++;
745 $usersocialnetworks = (is_array($tmpobj->socialnetworks) ? $tmpobj->socialnetworks : array());
746 $contactsocialnetworks = (is_array($this->socialnetworks) ? $this->socialnetworks : array());
748 if (!empty(array_diff_assoc($usersocialnetworks, $contactsocialnetworks)) || !empty(array_diff_assoc($contactsocialnetworks, $usersocialnetworks))) {
749 $tmpobj->socialnetworks = $this->socialnetworks;
750 $usermustbemodified++;
752 if ($usermustbemodified) {
753 $result = $tmpobj->update($user, 0, 1, 1, 1);
760 if (!$error && !$notrigger) {
773 dol_syslog(get_class($this).
"::update Error ".$this->error, LOG_ERR);
774 $this->db->rollback();
778 $this->error = $this->db->lasterror().
' sql='.$sql;
779 $this->db->rollback();
803 } elseif ($mode == 1) {
805 } elseif ($mode == 2) {
822 global
$conf, $langs;
843 $info[
"title"] = $this->poste;
845 if ($this->socid > 0) {
847 $soc->fetch($this->socid);
850 if ($soc->client == 1) {
851 $info[
"businessCategory"] =
"Customers";
853 if ($soc->client == 2) {
854 $info[
"businessCategory"] =
"Prospects";
856 if ($soc->fournisseur == 1) {
857 $info[
"businessCategory"] =
"Suppliers";
892 $info[
"objectclass"][4] =
"phpgwContact";
894 $info[
'uidnumber'] = $this->id;
896 $info[
'phpgwTz'] = 0;
897 $info[
'phpgwMailType'] =
'INTERNET';
898 $info[
'phpgwMailHomeType'] =
'INTERNET';
900 $info[
"phpgwContactTypeId"] =
'n';
901 $info[
"phpgwContactCatId"] = 0;
902 $info[
"phpgwContactAccess"] =
"public";
910 $info[
"phpgwContactOwner"] = 1;
913 $info[
"rfc822Mailbox"] = $this->email;
915 if ($this->phone_mobile) {
916 $info[
"phpgwCellTelephoneNumber"] = $this->phone_mobile;
942 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"socpeople SET";
943 $sql .=
" birthday = ".($this->birthday ?
"'".$this->db->idate($this->birthday).
"'" :
"null");
944 $sql .=
", photo = ".($this->photo ?
"'".$this->db->escape($this->photo).
"'" :
"null");
946 $sql .=
", fk_user_modif = ".((int) $user->id);
948 $sql .=
" WHERE rowid = ".((int) $id);
950 dol_syslog(get_class($this).
"::update_perso this->birthday=".$this->birthday.
" -", LOG_DEBUG);
951 $resql = $this->db->query($sql);
954 $this->error = $this->db->lasterror();
959 if (!empty($this->birthday_alert)) {
961 $sql_check =
"SELECT rowid FROM " . MAIN_DB_PREFIX .
"user_alert WHERE type = 1 AND fk_contact = " . ((int) $id) .
" AND fk_user = " . ((int) $user->id);
962 $result_check = $this->db->query($sql_check);
963 if (!$result_check || ($this->db->num_rows($result_check) < 1)) {
965 $sql =
"INSERT INTO " . MAIN_DB_PREFIX .
"user_alert(type, fk_contact, fk_user) ";
966 $sql .=
"VALUES (1," . ((int) $id) .
"," . ((int) $user->id) .
")";
967 $result = $this->db->query($sql);
970 $this->error = $this->db->lasterror();
976 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"user_alert ";
977 $sql .=
"WHERE type=1 AND fk_contact=" . ((int) $id) .
" AND fk_user=" . ((int) $user->id);
978 $result = $this->db->query($sql);
981 $this->error = $this->db->lasterror();
985 if (!$error && !$notrigger) {
999 dol_syslog(get_class($this).
"::update Error ".$this->error, LOG_ERR);
1000 $this->db->rollback();
1017 public function fetch($id, $user =
null, $ref_ext =
'', $email =
'', $loadalsoroles = 0, $socid = 0)
1021 dol_syslog(get_class($this).
"::fetch id=".$id.
" ref_ext=".$ref_ext.
" email=".$email, LOG_DEBUG);
1023 if (empty($id) && empty($ref_ext) && empty($email)) {
1024 $this->error =
'BadParameter';
1028 $langs->loadLangs(array(
"dict",
"companies"));
1030 $sql =
"SELECT c.rowid, c.entity, c.fk_soc, c.ref_ext, c.civility as civility_code, c.name_alias, c.lastname, c.firstname,";
1031 $sql .=
" c.address, c.statut, c.zip, c.town,";
1032 $sql .=
" c.fk_pays as country_id,";
1033 $sql .=
" c.fk_departement as state_id,";
1034 $sql .=
" c.birthday,";
1035 $sql .=
" c.poste, c.phone, c.phone_perso, c.phone_mobile, c.fax, c.email,";
1036 $sql .=
" c.socialnetworks,";
1037 $sql .=
" c.photo,";
1038 $sql .=
" c.priv, c.note_private, c.note_public, c.default_lang, c.canvas,";
1039 $sql .=
" c.fk_prospectlevel, c.fk_stcommcontact, st.libelle as stcomm, st.picto as stcomm_picto,";
1040 $sql .=
" c.import_key,";
1041 $sql .=
" c.datec as date_creation, c.tms as date_modification, c.fk_user_creat, c.fk_user_modif,";
1042 $sql .=
" co.label as country, co.code as country_code,";
1043 $sql .=
" d.nom as state, d.code_departement as state_code,";
1044 $sql .=
" u.rowid as user_id, u.login as user_login,";
1045 $sql .=
" s.nom as socname, s.address as socaddress, s.zip as soccp, s.town as soccity, s.default_lang as socdefault_lang";
1046 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as c";
1047 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as co ON c.fk_pays = co.rowid";
1048 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_departements as d ON c.fk_departement = d.rowid";
1049 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u ON c.rowid = u.fk_socpeople";
1050 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON c.fk_soc = s.rowid";
1051 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_stcommcontact as st ON c.fk_stcommcontact = st.id';
1053 $sql .=
" WHERE c.rowid = ".((int) $id);
1055 $sql .=
" WHERE c.entity IN (".getEntity($this->element).
")";
1057 $sql .=
" AND c.ref_ext = '".$this->db->escape($ref_ext).
"'";
1060 $sql .=
" AND c.email = '".$this->db->escape($email).
"'";
1063 $sql .=
" AND c.fk_soc = ".((int) $socid);
1067 $resql = $this->db->query($sql);
1069 $num = $this->db->num_rows($resql);
1071 $this->error =
'Fetch found several records. Rename one of contact to avoid duplicate.';
1076 $obj = $this->db->fetch_object($resql);
1078 $this->
id = $obj->rowid;
1079 $this->entity = $obj->entity;
1080 $this->
ref = $obj->rowid;
1081 $this->ref_ext = $obj->ref_ext;
1083 $this->civility_code = $obj->civility_code;
1084 $this->civility = $obj->civility_code ? ($langs->trans(
"Civility".$obj->civility_code) !=
"Civility".$obj->civility_code ? $langs->trans(
"Civility".$obj->civility_code) : $obj->civility_code) :
'';
1086 $this->name_alias = $obj->name_alias;
1087 $this->lastname = $obj->lastname;
1088 $this->firstname = $obj->firstname;
1089 $this->
address = $obj->address;
1090 $this->zip = $obj->zip;
1091 $this->town = $obj->town;
1093 $this->date_creation = $this->db->jdate($obj->date_creation);
1094 $this->date_modification = $this->db->jdate($obj->date_modification);
1095 $this->user_creation_id = $obj->fk_user_creat;
1096 $this->user_modification_id = $obj->fk_user_modif;
1098 $this->state_id = $obj->state_id;
1099 $this->state_code = $obj->state_code;
1100 $this->state = $obj->state;
1102 $this->country_id = $obj->country_id;
1103 $this->country_code = $obj->country_id ? $obj->country_code :
'';
1104 $this->country = $obj->country_id ? ($langs->trans(
'Country'.$obj->country_code) !=
'Country'.$obj->country_code ? $langs->transnoentities(
'Country'.$obj->country_code) : $obj->country) :
'';
1106 $this->fk_soc = $obj->fk_soc;
1107 $this->socid = $obj->fk_soc;
1108 $this->socname = $obj->socname;
1109 $this->poste = $obj->poste;
1110 $this->statut = $obj->statut;
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 if (!$error && !$notrigger) {
1320 $result = $this->
call_trigger(
'CONTACT_DELETE', $user);
1329 $sql =
"SELECT ec.rowid";
1330 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_contact ec,";
1331 $sql .=
" ".MAIN_DB_PREFIX.
"c_type_contact tc";
1332 $sql .=
" WHERE ec.fk_socpeople=".((int) $this->
id);
1333 $sql .=
" AND ec.fk_c_type_contact=tc.rowid";
1334 $sql .=
" AND tc.source='external'";
1336 $resql = $this->db->query($sql);
1338 $num = $this->db->num_rows($resql);
1341 while ($i < $num && !$error) {
1342 $obj = $this->db->fetch_object($resql);
1344 $sqldel =
"DELETE FROM ".MAIN_DB_PREFIX.
"element_contact";
1345 $sqldel .=
" WHERE rowid = ".((int) $obj->rowid);
1347 $result = $this->db->query($sqldel);
1350 $this->error = $this->db->error().
' sql='.$sqldel;
1357 $this->error = $this->db->error().
' sql='.$sql;
1363 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_contacts WHERE fk_socpeople = ".((int) $this->
id);
1365 $resql = $this->db->query($sql);
1368 $this->error .= $this->db->lasterror();
1375 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"notify_def WHERE fk_contact = ".((int) $this->
id);
1377 $resql = $this->db->query($sql);
1380 $this->error .= $this->db->lasterror();
1387 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_contact WHERE fk_socpeople = ".((int) $this->
id);
1389 $resql = $this->db->query($sql);
1392 $this->error .= $this->db->lasterror();
1399 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"user_alert WHERE fk_contact = ".((int) $this->
id);
1401 $resql = $this->db->query($sql);
1404 $this->error .= $this->db->lasterror();
1410 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"user SET fk_socpeople = NULL WHERE fk_socpeople = ".((int) $this->
id);
1412 $resql = $this->db->query($sql);
1415 $this->error .= $this->db->lasterror();
1428 $dirofdocuments =
'';
1429 if ($this->
id > 0 && !empty(
$conf->societe->multidir_output[$this->entity])) {
1432 if (!$error && $dirofdocuments) {
1433 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1436 $this->error .= $this->db->lasterror();
1441 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"socpeople";
1442 $sql .=
" WHERE rowid = ".((int) $this->
id);
1444 $result = $this->db->query($sql);
1447 $this->error = $this->db->error().
' sql='.$sql;
1461 $this->db->commit();
1464 if ($dirofdocuments) {
1465 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1473 $this->db->rollback();
1488 $sql =
"SELECT c.rowid, c.datec as datec, c.fk_user_creat,";
1489 $sql .=
" c.tms as tms, c.fk_user_modif";
1490 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as c";
1491 $sql .=
" WHERE c.rowid = ".((int) $id);
1493 $resql = $this->db->query($sql);
1495 if ($this->db->num_rows($resql)) {
1496 $obj = $this->db->fetch_object($resql);
1498 $this->
id = $obj->rowid;
1500 $this->user_creation_id = $obj->fk_user_creat;
1501 $this->user_modification_id = $obj->fk_user_modif;
1502 $this->date_creation = $this->db->jdate($obj->datec);
1503 $this->date_modification = $this->db->jdate($obj->tms);
1506 $this->db->free($resql);
1508 print $this->db->error();
1519 $sql =
"SELECT count(mc.email) as nb";
1520 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mailing_cibles as mc, ".MAIN_DB_PREFIX.
"mailing as m";
1521 $sql .=
" WHERE mc.fk_mailing=m.rowid AND mc.email = '".$this->db->escape($this->
email).
"' ";
1522 $sql .=
" AND m.entity IN (".getEntity($this->element).
") AND mc.statut NOT IN (-1,0)";
1524 $resql = $this->db->query($sql);
1526 $obj = $this->db->fetch_object($resql);
1529 $this->db->free($resql);
1532 $this->error = $this->db->error();
1545 global
$conf, $langs, $user;
1550 return [
'optimize' => $langs->trans(
"ShowContact")];
1552 if (!empty($this->photo) && class_exists(
'Form')) {
1553 $photo =
'<div class="photointooltip floatright">';
1554 $photo .=
Form::showphoto(
'contact', $this, 0, 40, 0,
'photoref',
'mini', 0);
1556 $datas[
'photo'] = $photo;
1559 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Contact").
'</u> ' . $this->
getLibStatut(4);
1560 $datas[
'name'] =
'<br><b>'.$langs->trans(
"Name").
':</b> '.$this->
getFullName($langs);
1562 if (!empty($this->poste)) {
1563 $datas[
'job'] =
'<br><b>'.$langs->trans(
"Poste").
':</b> '.$this->poste;
1565 $datas[
'email'] =
'<br><b>'.$langs->trans(
"EMail").
':</b> '.$this->email;
1566 $phonelist = array();
1567 $country_code = empty($this->country_code) ?
'' : $this->country_code;
1568 if ($this->phone_pro) {
1569 $phonelist[] =
dol_print_phone($this->phone_pro, $country_code, $this->
id, 0,
'',
' ',
'phone');
1571 if ($this->phone_mobile) {
1572 $phonelist[] =
dol_print_phone($this->phone_mobile, $country_code, $this->
id, 0,
'',
' ',
'mobile');
1574 if ($this->phone_perso) {
1575 $phonelist[] =
dol_print_phone($this->phone_perso, $country_code, $this->
id, 0,
'',
' ',
'phone');
1577 $datas[
'phonelist'] =
'<br><b>'.$langs->trans(
"Phone").
':</b> '.implode(
' ', $phonelist);
1578 $datas[
'address'] =
'<br><b>'.$langs->trans(
"Address").
':</b> '.
dol_format_address($this, 1,
' ', $langs);
1596 public function getNomUrl($withpicto = 0, $option =
'', $maxlen = 0, $moreparam =
'', $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'valignmiddle')
1598 global
$conf, $langs, $hookmanager;
1600 if (!empty(
$conf->dol_no_mouse_hover)) {
1607 'objecttype' => $this->element,
1608 'option' => $option,
1610 $classfortooltip =
'classfortooltip';
1613 $classfortooltip =
'classforajaxtooltip';
1614 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1620 $url = DOL_URL_ROOT.
'/contact/card.php?id='.$this->id;
1622 if ($option !==
'nolink') {
1624 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1625 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1626 $add_save_lastsearch_values = 1;
1628 if ($url && $add_save_lastsearch_values) {
1629 $url .=
'&save_lastsearch_values=1';
1636 if (empty($notooltip)) {
1638 $label = $langs->trans(
"ShowContact");
1639 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1641 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
1642 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1644 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1647 if ($option ==
'nolink' || empty($url)) {
1648 $linkstart =
'<span';
1650 $linkstart =
'<a href="'.$url.
'"';
1652 $linkstart .= $linkclose.
'>';
1653 if ($option ==
'nolink' || empty($url)) {
1654 $linkend =
'</span>';
1659 $result .= $linkstart;
1662 if ($withpicto < 0) {
1663 $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>';
1664 if ($withpicto != 2 && $withpicto != -2) {
1668 $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);
1671 if ($withpicto != 2 && $withpicto != -2) {
1675 $result .= $linkend;
1678 $hookmanager->initHooks(array(
'contactdao'));
1679 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1680 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1682 $result = $hookmanager->resPrint;
1684 $result .= $hookmanager->resPrint;
1699 $code = ($this->civility_code ? $this->civility_code : (!empty($this->civility_id) ? $this->civility : (!empty($this->civilite) ? $this->civilite :
'')));
1704 $langs->load(
"dict");
1705 return $langs->getLabelFromKey($this->db,
"Civility".$code,
"c_civility",
"code",
"label", $code);
1716 return $this->
LibStatut($this->statut, $mode);
1732 $labelStatus = array(
1733 0 =>
'ActivityCeased',
1736 5 =>
'ActivityCeased',
1738 $labelStatusShort = array(
1739 0 =>
'ActivityCeased',
1742 5 =>
'ActivityCeased',
1745 $statusType =
'status4';
1746 if ($status == 0 || $status == 5) {
1747 $statusType =
'status5';
1750 $label = $langs->transnoentitiesnoconv($labelStatus[$status]);
1751 $labelshort = $langs->transnoentitiesnoconv($labelStatusShort[$status]);
1753 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
1768 if ($status ==
'1') {
1769 return $langs->trans(
'ContactPrivate');
1771 return $langs->trans(
'ContactPublic');
1787 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe ORDER BY rowid LIMIT 1";
1788 $resql = $this->db->query($sql);
1790 $obj = $this->db->fetch_object($resql);
1792 $socid = $obj->rowid;
1799 $this->specimen = 1;
1800 $this->lastname =
'DOLIBARR';
1801 $this->firstname =
'SPECIMEN';
1802 $this->
address =
'21 jump street';
1803 $this->zip =
'99999';
1804 $this->town =
'MyTown';
1805 $this->country_id = 1;
1806 $this->country_code =
'FR';
1807 $this->country =
'France';
1808 $this->
email =
'specimen@specimen.com';
1809 $this->socialnetworks = array(
1810 'skype' =>
'tom.hanson',
1811 'twitter' =>
'tomhanson',
1812 'linkedin' =>
'tomhanson',
1814 $this->phone_pro =
'0909090901';
1815 $this->phone_perso =
'0909090902';
1816 $this->phone_mobile =
'0909090903';
1817 $this->fax =
'0909090909';
1819 $this->note_public =
'This is a comment (public)';
1820 $this->note_private =
'This is a comment (private)';
1822 $this->socid = $socid;
1836 global
$conf, $langs, $user;
1841 if ($this->statut == $status) {
1844 $this->statut = $status;
1850 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"socpeople";
1851 $sql .=
" SET statut = ".((int) $this->statut);
1852 $sql .=
", fk_user_modif = ".((int) $user->id);
1853 $sql .=
" WHERE rowid = ".((int) $this->
id);
1854 $result = $this->db->query($sql);
1856 dol_syslog(get_class($this).
"::setstatus", LOG_DEBUG);
1859 $result = $this->
call_trigger(
'CONTACT_ENABLEDISABLE', $user);
1867 $this->db->rollback();
1870 $this->db->commit();
1887 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1888 return parent::setCategoriesCommon($categories, Categorie::TYPE_CONTACT);
1902 'socpeople',
'societe_contacts'
1921 $sql =
"SELECT tc.rowid, tc.element, tc.source, tc.code, tc.libelle as label, sc.rowid as contactroleid, sc.fk_soc as socid";
1922 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_contacts as sc, ".MAIN_DB_PREFIX.
"c_type_contact as tc";
1923 $sql .=
" WHERE tc.rowid = sc.fk_c_type_contact";
1924 $sql .=
" AND tc.source = 'external' AND tc.active=1";
1925 $sql .=
" AND sc.fk_socpeople = ".((int) $this->
id);
1926 $sql .=
" AND sc.entity IN (".getEntity(
'societe').
')';
1928 $resql = $this->db->query($sql);
1930 $this->roles = array();
1932 $num = $this->db->num_rows($resql);
1934 while ($obj = $this->db->fetch_object($resql)) {
1935 $transkey =
"TypeContact_".$obj->element.
"_".$obj->source.
"_".$obj->code;
1936 $libelle_element = $langs->trans(
'ContactDefault_'.$obj->element);
1937 $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));
1942 $this->error = $this->db->lasterror();
1943 $this->errors[] = $this->db->lasterror();
1946 if (empty($error)) {
1964 if ($element ==
'action') {
1965 $element =
'agenda';
1968 $sql =
"SELECT sc.fk_socpeople as id, sc.fk_c_type_contact";
1969 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact tc";
1970 $sql .=
", ".MAIN_DB_PREFIX.
"societe_contacts sc";
1971 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"socpeople sp";
1972 $sql .=
" ON sc.fk_socpeople = sp.rowid AND sp.statut = 1";
1973 $sql .=
" WHERE sc.fk_soc =".((int) $this->socid);
1974 $sql .=
" AND sc.fk_c_type_contact=tc.rowid";
1975 $sql .=
" AND tc.element = '".$this->db->escape($element).
"'";
1976 $sql .=
" AND sp.entity IN (".getEntity(
'contact').
")";
1977 $sql .=
" AND tc.active = 1";
1980 $resql = $this->db->query($sql);
1982 $num = $this->db->num_rows($resql);
1985 $obj = $this->db->fetch_object($resql);
1986 $tab[] = array(
'fk_socpeople' => $obj->id,
'type_contact' => $obj->fk_c_type_contact);
1993 $this->error = $this->db->error();
2012 if (!isset($this->roles)) {
2018 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_contacts WHERE fk_socpeople=".((int) $this->
id).
" AND entity IN (".
getEntity(
"contact").
")";
2020 $result = $this->db->query($sql);
2022 $this->errors[] = $this->db->lasterror().
' sql='.$sql;
2025 if (count($this->roles) > 0) {
2026 foreach ($this->roles as $keyRoles => $valRoles) {
2027 if (empty($valRoles)) {
2031 if (is_array($valRoles)) {
2032 $idrole = $valRoles[
'id'];
2034 $idrole = $valRoles;
2038 if (is_array($valRoles)) {
2039 $socid = $valRoles[
'socid'];
2041 $socid = $this->socid;
2045 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_contacts";
2046 $sql .=
" (entity,";
2047 $sql .=
"date_creation,";
2049 $sql .=
"fk_c_type_contact,";
2050 $sql .=
"fk_socpeople) ";
2051 $sql .=
" VALUES (".$conf->entity.
",";
2052 $sql .=
"'".$this->db->idate(
dol_now()).
"',";
2053 $sql .= $socid.
", ";
2054 $sql .= $idrole.
" , ";
2058 $result = $this->db->query($sql);
2060 $this->errors[] = $this->db->lasterror().
' sql='.$sql;
2067 if (empty($error)) {
2068 $this->db->commit();
2071 $this->error = implode(
' ', $this->errors);
2072 $this->db->rollback();
2087 $sql =
"SELECT id, code, libelle as label, picto FROM ".MAIN_DB_PREFIX.
"c_stcommcontact";
2089 $sql .=
" WHERE active = ".((int) $active);
2091 $resql = $this->db->query($sql);
2092 $num = $this->db->num_rows($resql);
2095 $obj = $this->db->fetch_object($resql);
2096 $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);
2122 $lib = $langs->trans(
"ProspectLevel".$fk_prospectlevel);
2124 if ($lib ==
"ProspectLevel".$fk_prospectlevel) {
2125 $lib = $langs->getLabelFromKey($this->db, $fk_prospectlevel,
'c_prospectlevel',
'code',
'label');
2140 return $this->
update($this->
id, $user);
2152 return $this->
libProspCommStatut($this->stcomm_id, $mode, $label, $this->stcomm_picto);
2171 $langs->load(
'customers');
2174 if ($statut ==
'-1' || $statut ==
'ST_NO') {
2175 return img_action($langs->trans(
"StatusProspect-1"),
'-1', $picto).
' '.$langs->trans(
"StatusProspect-1");
2176 } elseif ($statut ==
'0' || $statut ==
'ST_NEVER') {
2177 return img_action($langs->trans(
"StatusProspect0"),
'0', $picto).
' '.$langs->trans(
"StatusProspect0");
2178 } elseif ($statut ==
'1' || $statut ==
'ST_TODO') {
2179 return img_action($langs->trans(
"StatusProspect1"),
'1', $picto).
' '.$langs->trans(
"StatusProspect1");
2180 } elseif ($statut ==
'2' || $statut ==
'ST_PEND') {
2181 return img_action($langs->trans(
"StatusProspect2"),
'2', $picto).
' '.$langs->trans(
"StatusProspect2");
2182 } elseif ($statut ==
'3' || $statut ==
'ST_DONE') {
2183 return img_action($langs->trans(
"StatusProspect3"),
'3', $picto).
' '.$langs->trans(
"StatusProspect3");
2185 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);
2189 if ($statut ==
'-1' || $statut ==
'ST_NO') {
2190 return img_action($langs->trans(
"StatusProspect-1"),
'-1', $picto);
2191 } elseif ($statut ==
'0' || $statut ==
'ST_NEVER') {
2192 return img_action($langs->trans(
"StatusProspect0"),
'0', $picto);
2193 } elseif ($statut ==
'1' || $statut ==
'ST_TODO') {
2194 return img_action($langs->trans(
"StatusProspect1"),
'1', $picto);
2195 } elseif ($statut ==
'2' || $statut ==
'ST_PEND') {
2196 return img_action($langs->trans(
"StatusProspect2"),
'2', $picto);
2197 } elseif ($statut ==
'3' || $statut ==
'ST_DONE') {
2198 return img_action($langs->trans(
"StatusProspect3"),
'3', $picto);
2200 return img_action(($langs->trans(
"StatusProspect".$statut) !=
"StatusProspect".$statut) ? $langs->trans(
"StatusProspect".$statut) : $label,
'0', $picto);
2204 if ($statut ==
'-1' || $statut ==
'ST_NO') {
2205 return img_action($langs->trans(
"StatusProspect-1"),
'-1', $picto).
' '.$langs->trans(
"StatusProspect-1");
2206 } elseif ($statut ==
'0' || $statut ==
'ST_NEVER') {
2207 return img_action($langs->trans(
"StatusProspect0"),
'0', $picto).
' '.$langs->trans(
"StatusProspect0");
2208 } elseif ($statut ==
'1' || $statut ==
'ST_TODO') {
2209 return img_action($langs->trans(
"StatusProspect1"),
'1', $picto).
' '.$langs->trans(
"StatusProspect1");
2210 } elseif ($statut ==
'2' || $statut ==
'ST_PEND') {
2211 return img_action($langs->trans(
"StatusProspect2"),
'2', $picto).
' '.$langs->trans(
"StatusProspect2");
2212 } elseif ($statut ==
'3' || $statut ==
'ST_DONE') {
2213 return img_action($langs->trans(
"StatusProspect3"),
'3', $picto).
' '.$langs->trans(
"StatusProspect3");
2215 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);
2219 return "Error, mode/status not found";
2238 $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).
"'";
2239 $resql = $this->db->query($sql);
2241 $obj = $this->db->fetch_object($resql);
2242 $noemail = $obj->nb;
2243 if (empty($noemail)) {
2244 $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()).
"')";
2245 $resql = $this->db->query($sql);
2248 $this->error = $this->db->lasterror();
2249 $this->errors[] = $this->error;
2254 $this->error = $this->db->lasterror();
2255 $this->errors[] = $this->error;
2258 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE email = '".$this->db->escape($this->
email).
"' AND entity IN (".
getEntity(
'mailing', 0).
")";
2259 $resql = $this->db->query($sql);
2262 $this->error = $this->db->lasterror();
2263 $this->errors[] = $this->error;
2267 if (empty($error)) {
2268 $this->no_email = $no_email;
2269 $this->db->commit();
2272 $this->db->rollback();
2289 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE entity IN (".
getEntity(
'mailing').
") AND email = '".$this->db->escape($this->
email).
"'";
2290 $resql = $this->db->query($sql);
2292 $obj = $this->db->fetch_object($resql);
2293 $this->no_email = $obj->nb;
2296 $this->error = $this->db->lasterror();
2297 $this->errors[] = $this->error;
2314 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
2316 $return =
'<div class="box-flex-item box-flex-grow-zero">';
2317 $return .=
'<div class="info-box info-box-sm">';
2318 $return .=
'<span class="info-box-icon bg-infobox-action">';
2320 if (property_exists($this,
'photo') && !is_null($this->photo)) {
2321 $return .=
Form::showphoto(
'contact', $this, 0, 60, 0,
'photokanban photoref photowithmargin photologintooltip',
'small', 0, 1);
2325 $return .=
'</span>';
2326 $return .=
'<div class="info-box-content">';
2327 $return .=
'<div class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(0) : $this->ref).
'</div>';
2328 if ($selected >= 0) {
2329 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
2331 if (property_exists($this,
'thirdparty') && is_object($this->thirdparty)) {
2332 $return .=
'<div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).
'</div>';
2342 if (method_exists($this,
'getLibStatut')) {
2343 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
2345 $return .=
'</div>';
2346 $return .=
'</div>';
2347 $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...
deleteEcmFiles($mode=0)
Delete related files of object in database.
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid=0, $f_user=null, $notrigger=0)
Delete all links between an object $this.
deleteExtraFields()
Delete all extra fields values for the current object.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
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_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_is_dir($folder)
Test if filename is a directory.
deleteFilesIntoDatabaseIndex($dir, $file, $mode='uploaded', $object=null)
Delete files into database index using search criteria.
setEntity($currentobject)
Set entity id to use when to create an object.
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.
dol_print_phone($phone, $countrycode='', $cid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='paddingright')
Format phone numbers according to country.
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)
dol_now($mode='auto')
Return date for now.
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.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
$conf db name
Only used if Module[ID]Name translation string is not found.