34 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonsocialnetworks.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonpeople.class.php';
50 public $element =
'contact';
55 public $table_element =
'socpeople';
61 public $ismultientitymanaged = 1;
66 public $picto =
'contact';
96 public $fields = array(
97 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10),
98 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'default'=>1,
'enabled'=>1,
'visible'=>3,
'notnull'=>1,
'position'=>30,
'index'=>1),
99 'ref_ext' =>array(
'type'=>
'varchar(255)',
'label'=>
'Ref ext',
'enabled'=>1,
'visible'=>3,
'position'=>35),
100 'civility' =>array(
'type'=>
'varchar(6)',
'label'=>
'Civility',
'enabled'=>1,
'visible'=>3,
'position'=>40),
101 'lastname' =>array(
'type'=>
'varchar(50)',
'label'=>
'Lastname',
'enabled'=>1,
'visible'=>1,
'position'=>45,
'showoncombobox'=>1,
'searchall'=>1),
102 'firstname' =>array(
'type'=>
'varchar(50)',
'label'=>
'Firstname',
'enabled'=>1,
'visible'=>1,
'position'=>50,
'showoncombobox'=>1,
'searchall'=>1),
103 'poste' =>array(
'type'=>
'varchar(80)',
'label'=>
'PostOrFunction',
'enabled'=>1,
'visible'=>-1,
'position'=>52),
104 'address' =>array(
'type'=>
'varchar(255)',
'label'=>
'Address',
'enabled'=>1,
'visible'=>-1,
'position'=>55),
105 'zip' =>array(
'type'=>
'varchar(25)',
'label'=>
'Zip',
'enabled'=>1,
'visible'=>1,
'position'=>60),
106 'town' =>array(
'type'=>
'varchar(50)',
'label'=>
'Town',
'enabled'=>1,
'visible'=>-1,
'position'=>65),
107 'fk_departement' =>array(
'type'=>
'integer',
'label'=>
'Fk departement',
'enabled'=>1,
'visible'=>3,
'position'=>70),
108 'fk_pays' =>array(
'type'=>
'integer',
'label'=>
'Fk pays',
'enabled'=>1,
'visible'=>3,
'position'=>75),
109 'fk_soc' =>array(
'type'=>
'integer',
'label'=>
'ThirdParty',
'enabled'=>1,
'visible'=>1,
'position'=>77,
'searchall'=>1),
110 'birthday' =>array(
'type'=>
'date',
'label'=>
'Birthday',
'enabled'=>1,
'visible'=>3,
'position'=>80),
111 'phone' =>array(
'type'=>
'varchar(30)',
'label'=>
'Phone',
'enabled'=>1,
'visible'=>1,
'position'=>90,
'searchall'=>1),
112 'phone_perso' =>array(
'type'=>
'varchar(30)',
'label'=>
'PhonePerso',
'enabled'=>1,
'visible'=>-1,
'position'=>95,
'searchall'=>1),
113 'phone_mobile' =>array(
'type'=>
'varchar(30)',
'label'=>
'PhoneMobile',
'enabled'=>1,
'visible'=>1,
'position'=>100,
'searchall'=>1),
114 'fax' =>array(
'type'=>
'varchar(30)',
'label'=>
'Fax',
'enabled'=>1,
'visible'=>-1,
'position'=>105,
'searchall'=>1),
115 'email' =>array(
'type'=>
'varchar(255)',
'label'=>
'Email',
'enabled'=>1,
'visible'=>1,
'position'=>110,
'searchall'=>1),
116 'socialnetworks' =>array(
'type'=>
'text',
'label'=>
'SocialNetworks',
'enabled'=>1,
'visible'=>3,
'position'=>115),
117 'photo' =>array(
'type'=>
'varchar(255)',
'label'=>
'Photo',
'enabled'=>1,
'visible'=>3,
'position'=>170),
118 'priv' =>array(
'type'=>
'smallint(6)',
'label'=>
'ContactVisibility',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'position'=>175),
119 'fk_stcommcontact' =>array(
'type'=>
'integer',
'label'=>
'ProspectStatus',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>220),
120 'fk_prospectlevel' =>array(
'type'=>
'varchar(12)',
'label'=>
'ProspectLevel',
'enabled'=>1,
'visible'=>-1,
'position'=>255),
121 'no_email' =>array(
'type'=>
'smallint(6)',
'label'=>
'No_Email',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>180),
122 'note_private' =>array(
'type'=>
'html',
'label'=>
'NotePrivate',
'enabled'=>1,
'visible'=>3,
'position'=>195,
'searchall'=>1),
123 'note_public' =>array(
'type'=>
'html',
'label'=>
'NotePublic',
'enabled'=>1,
'visible'=>3,
'position'=>200,
'searchall'=>1),
124 'default_lang' =>array(
'type'=>
'varchar(6)',
'label'=>
'Default lang',
'enabled'=>1,
'visible'=>3,
'position'=>205),
125 'canvas' =>array(
'type'=>
'varchar(32)',
'label'=>
'Canvas',
'enabled'=>1,
'visible'=>3,
'position'=>210),
126 'datec' =>array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-1,
'position'=>300),
127 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>305),
128 'fk_user_creat' =>array(
'type'=>
'integer',
'label'=>
'UserAuthor',
'enabled'=>1,
'visible'=>3,
'position'=>310),
129 'fk_user_modif' =>array(
'type'=>
'integer',
'label'=>
'UserModif',
'enabled'=>1,
'visible'=>3,
'position'=>315),
130 'statut' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Status',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'position'=>500),
131 'import_key' =>array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-1,
'position'=>1000),
135 public $civility_code;
146 public $egroupware_id;
151 public $birthday_alert;
244 public $socialnetworks;
299 public $phone_mobile;
313 public $default_lang;
318 public $ref_facturation;
328 public $ref_commande;
359 public $cacheprospectstatus = array();
360 public $fk_prospectlevel;
362 public $statut_commercial;
367 public $stcomm_picto;
377 global $conf, $langs;
382 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) {
383 $this->fields[
'rowid'][
'visible'] = 0;
386 $this->fields[
'no_email'][
'enabled'] = 0;
389 if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
390 $this->fields[
'fk_soc'][
'enabled'] = 0;
391 $this->fields[
'fk_soc'][
'searchall'] = 0;
394 if (!empty($conf->global->SOCIETE_DISABLE_PROSPECTS) || empty($conf->global->THIRDPARTY_ENABLE_PROSPECTION_ON_ALTERNATIVE_ADRESSES)) {
395 $this->fields[
'fk_stcommcontact'][
'enabled'] = 0;
396 $this->fields[
'fk_prospectlevel'][
'enabled'] = 0;
400 foreach ($this->fields as $key => $val) {
401 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
402 unset($this->fields[$key]);
431 global $user, $hookmanager;
436 $sql =
"SELECT count(sp.rowid) as nb";
437 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as sp";
438 if (empty($user->rights->societe->client->voir) && !$user->socid) {
439 $sql .=
", ".MAIN_DB_PREFIX.
"societe as s";
440 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
441 $sql .=
" WHERE sp.fk_soc = s.rowid AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
444 $sql .=
" ".$clause.
" sp.entity IN (".
getEntity($this->element).
")";
445 $sql .=
" AND (sp.priv='0' OR (sp.priv='1' AND sp.fk_user_creat = ".((int) $user->id).
"))";
446 if ($user->socid > 0) {
447 $sql .=
" AND sp.fk_soc = ".((int) $user->socid);
450 if (is_object($hookmanager)) {
451 $parameters = array();
452 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $this);
453 $sql .= $hookmanager->resPrint;
456 $resql = $this->db->query(
$sql);
458 while ($obj = $this->db->fetch_object($resql)) {
459 $this->nb[
"contacts"] = $obj->nb;
461 $this->db->free($resql);
465 $this->error = $this->db->lasterror();
477 public function create($user, $notrigger = 0)
487 $this->lastname = $this->lastname ?trim($this->lastname) : trim($this->
name);
488 $this->firstname = trim($this->firstname);
490 if (empty($this->socid)) {
493 if (empty($this->priv)) {
496 if (empty($this->statut)) {
500 $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity);
502 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"socpeople (";
505 $sql .=
", lastname";
506 $sql .=
", firstname";
507 $sql .=
", fk_user_creat";
509 $sql .=
", fk_stcommcontact";
514 $sql .=
", import_key";
515 $sql .=
") VALUES (";
516 $sql .=
"'".$this->db->idate($now).
"',";
517 if ($this->socid > 0) {
518 $sql .=
" ".((int) $this->socid).
",";
522 $sql .=
"'".$this->db->escape($this->lastname).
"',";
523 $sql .=
"'".$this->db->escape($this->firstname).
"',";
524 $sql .=
" ".($user->id > 0 ? ((int) $user->id) :
"null").
",";
525 $sql .=
" ".((int) $this->priv).
",";
527 $sql .=
" ".((int) $this->statut).
",";
528 $sql .=
" ".(!empty($this->canvas) ?
"'".$this->db->escape($this->canvas).
"'" :
"null").
",";
529 $sql .=
" ".((int) $this->entity).
",";
530 $sql .=
"'".$this->db->escape($this->ref_ext).
"',";
531 $sql .=
" ".(!empty($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
534 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
535 $resql = $this->db->query(
$sql);
537 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"socpeople");
540 $result = $this->
update($this->
id, $user, 1,
'add');
543 $this->error = $this->db->lasterror();
551 $this->error = $this->db->lasterror();
555 if (!$error && !$notrigger) {
568 $this->db->rollback();
569 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
573 $this->error = $this->db->lasterror();
575 $this->db->rollback();
576 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
591 public function update($id, $user =
null, $notrigger = 0, $action =
'update', $nosyncuser = 0)
593 global $conf, $langs, $hookmanager;
599 $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity);
602 $this->ref_ext = trim($this->ref_ext);
603 $this->lastname = trim($this->lastname) ?trim($this->lastname) : trim($this->lastname);
604 $this->firstname = trim($this->firstname);
605 $this->email = trim($this->email);
606 $this->phone_pro = trim($this->phone_pro);
607 $this->phone_perso = trim($this->phone_perso);
608 $this->phone_mobile = trim($this->phone_mobile);
609 $this->photo = trim($this->photo);
610 $this->fax = trim($this->fax);
611 $this->zip = (empty($this->zip) ?
'' : trim($this->zip));
612 $this->town = (empty($this->town) ?
'' : trim($this->town));
613 $this->country_id = ($this->country_id > 0 ? $this->country_id : $this->country_id);
614 if (empty($this->statut)) {
617 if (empty($this->civility_code) && !is_numeric($this->civility_id)) {
618 $this->civility_code = $this->civility_id;
623 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"socpeople SET";
624 if ($this->socid > 0) {
625 $sql .=
" fk_soc = ".((int) $this->socid).
",";
626 } elseif ($this->socid == -1) {
627 $sql .=
" fk_soc = NULL,";
629 $sql .=
" civility='".$this->db->escape($this->civility_code).
"'";
630 $sql .=
", lastname='".$this->db->escape($this->lastname).
"'";
631 $sql .=
", firstname='".$this->db->escape($this->firstname).
"'";
632 $sql .=
", address='".$this->db->escape($this->address).
"'";
633 $sql .=
", zip='".$this->db->escape($this->zip).
"'";
634 $sql .=
", town='".$this->db->escape($this->town).
"'";
635 $sql .=
", ref_ext = ".(!empty($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"NULL");
636 $sql .=
", fk_pays=".($this->country_id > 0 ? $this->country_id :
'NULL');
637 $sql .=
", fk_departement=".($this->state_id > 0 ? $this->state_id :
'NULL');
638 $sql .=
", poste='".$this->db->escape($this->poste).
"'";
639 $sql .=
", fax='".$this->db->escape($this->fax).
"'";
640 $sql .=
", email='".$this->db->escape($this->email).
"'";
641 $sql .=
", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
642 $sql .=
", photo='".$this->db->escape($this->photo).
"'";
643 $sql .=
", birthday=".($this->birthday ?
"'".$this->db->idate($this->birthday).
"'" :
"null");
644 $sql .=
", note_private = ".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"NULL");
645 $sql .=
", note_public = ".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"NULL");
646 $sql .=
", phone = ".(isset($this->phone_pro) ?
"'".$this->db->escape($this->phone_pro).
"'" :
"NULL");
647 $sql .=
", phone_perso = ".(isset($this->phone_perso) ?
"'".$this->db->escape($this->phone_perso).
"'" :
"NULL");
648 $sql .=
", phone_mobile = ".(isset($this->phone_mobile) ?
"'".$this->db->escape($this->phone_mobile).
"'" :
"NULL");
649 $sql .=
", priv = '".$this->db->escape($this->priv).
"'";
650 $sql .=
", fk_prospectlevel = '".$this->db->escape($this->fk_prospectlevel).
"'";
651 if (isset($this->stcomm_id)) {
652 $sql .=
", fk_stcommcontact = ".($this->stcomm_id > 0 || $this->stcomm_id == -1 ? $this->stcomm_id :
"0");
654 $sql .=
", statut = ".((int) $this->statut);
655 $sql .=
", fk_user_modif=".($user->id > 0 ?
"'".$this->db->escape($user->id).
"'" :
"NULL");
656 $sql .=
", default_lang=".($this->default_lang ?
"'".$this->db->escape($this->default_lang).
"'" :
"NULL");
657 $sql .=
", entity = ".((int) $this->entity);
658 $sql .=
" WHERE rowid = ".((int) $id);
660 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
661 $result = $this->db->query(
$sql);
663 unset($this->country_code);
664 unset($this->country);
665 unset($this->state_code);
685 if (!$error && $this->user_id > 0) {
687 $tmpobj =
new User($this->db);
688 $tmpobj->fetch($this->user_id);
689 $usermustbemodified = 0;
690 if ($tmpobj->office_phone != $this->phone_pro) {
691 $tmpobj->office_phone = $this->phone_pro;
692 $usermustbemodified++;
694 if ($tmpobj->office_fax != $this->fax) {
695 $tmpobj->office_fax = $this->fax;
696 $usermustbemodified++;
698 if ($tmpobj->address != $this->address) {
699 $tmpobj->address = $this->address;
700 $usermustbemodified++;
702 if ($tmpobj->town != $this->town) {
703 $tmpobj->town = $this->town;
704 $usermustbemodified++;
706 if ($tmpobj->zip != $this->zip) {
707 $tmpobj->zip = $this->zip;
708 $usermustbemodified++;
710 if ($tmpobj->zip != $this->zip) {
711 $tmpobj->state_id = $this->state_id;
712 $usermustbemodified++;
714 if ($tmpobj->country_id != $this->country_id) {
715 $tmpobj->country_id = $this->country_id;
716 $usermustbemodified++;
718 if ($tmpobj->email != $this->email) {
719 $tmpobj->email = $this->email;
720 $usermustbemodified++;
722 if (!empty(array_diff($tmpobj->socialnetworks, $this->socialnetworks))) {
723 $tmpobj->socialnetworks = $this->socialnetworks;
724 $usermustbemodified++;
726 if ($usermustbemodified) {
727 $result = $tmpobj->update($user, 0, 1, 1, 1);
734 if (!$error && !$notrigger) {
747 dol_syslog(get_class($this).
"::update Error ".$this->error, LOG_ERR);
748 $this->db->rollback();
752 $this->error = $this->db->lasterror().
' sql='.
$sql;
753 $this->db->rollback();
776 $dn = $conf->global->LDAP_KEY_CONTACTS.
"=".$info[$conf->global->LDAP_KEY_CONTACTS].
",".$conf->global->LDAP_CONTACT_DN;
777 } elseif ($mode == 1) {
778 $dn = $conf->global->LDAP_CONTACT_DN;
779 } elseif ($mode == 2) {
780 $dn = $conf->global->LDAP_KEY_CONTACTS.
"=".$info[$conf->global->LDAP_KEY_CONTACTS];
796 global $conf, $langs;
801 $info[
"objectclass"] = explode(
',', $conf->global->LDAP_CONTACT_OBJECT_CLASS);
806 if ($this->fullname && !empty($conf->global->LDAP_CONTACT_FIELD_FULLNAME)) {
807 $info[$conf->global->LDAP_CONTACT_FIELD_FULLNAME] = $this->fullname;
809 if ($this->lastname && !empty($conf->global->LDAP_CONTACT_FIELD_NAME)) {
810 $info[$conf->global->LDAP_CONTACT_FIELD_NAME] = $this->lastname;
812 if ($this->firstname && !empty($conf->global->LDAP_CONTACT_FIELD_FIRSTNAME)) {
813 $info[$conf->global->LDAP_CONTACT_FIELD_FIRSTNAME] = $this->firstname;
817 $info[
"title"] = $this->poste;
819 if ($this->socid > 0) {
821 $soc->fetch($this->socid);
823 $info[$conf->global->LDAP_CONTACT_FIELD_COMPANY] = $soc->name;
824 if ($soc->client == 1) {
825 $info[
"businessCategory"] =
"Customers";
827 if ($soc->client == 2) {
828 $info[
"businessCategory"] =
"Prospects";
830 if ($soc->fournisseur == 1) {
831 $info[
"businessCategory"] =
"Suppliers";
834 if ($this->address && !empty($conf->global->LDAP_CONTACT_FIELD_ADDRESS)) {
835 $info[$conf->global->LDAP_CONTACT_FIELD_ADDRESS] = $this->address;
837 if ($this->zip && !empty($conf->global->LDAP_CONTACT_FIELD_ZIP)) {
838 $info[$conf->global->LDAP_CONTACT_FIELD_ZIP] = $this->zip;
840 if ($this->town && !empty($conf->global->LDAP_CONTACT_FIELD_TOWN)) {
841 $info[$conf->global->LDAP_CONTACT_FIELD_TOWN] = $this->town;
843 if ($this->country_code && !empty($conf->global->LDAP_CONTACT_FIELD_COUNTRY)) {
844 $info[$conf->global->LDAP_CONTACT_FIELD_COUNTRY] = $this->country_code;
846 if ($this->phone_pro && !empty($conf->global->LDAP_CONTACT_FIELD_PHONE)) {
847 $info[$conf->global->LDAP_CONTACT_FIELD_PHONE] = $this->phone_pro;
849 if ($this->phone_perso && !empty($conf->global->LDAP_CONTACT_FIELD_HOMEPHONE)) {
850 $info[$conf->global->LDAP_CONTACT_FIELD_HOMEPHONE] = $this->phone_perso;
852 if ($this->phone_mobile && !empty($conf->global->LDAP_CONTACT_FIELD_MOBILE)) {
853 $info[$conf->global->LDAP_CONTACT_FIELD_MOBILE] = $this->phone_mobile;
855 if ($this->fax && !empty($conf->global->LDAP_CONTACT_FIELD_FAX)) {
856 $info[$conf->global->LDAP_CONTACT_FIELD_FAX] = $this->fax;
858 if ($this->note_private && !empty($conf->global->LDAP_CONTACT_FIELD_DESCRIPTION)) {
859 $info[$conf->global->LDAP_CONTACT_FIELD_DESCRIPTION] =
dol_string_nohtmltag($this->note_private, 2);
861 if ($this->email && !empty($conf->global->LDAP_CONTACT_FIELD_MAIL)) {
862 $info[$conf->global->LDAP_CONTACT_FIELD_MAIL] = $this->email;
865 if ($conf->global->LDAP_SERVER_TYPE ==
'egroupware') {
866 $info[
"objectclass"][4] =
"phpgwContact";
868 $info[
'uidnumber'] = $this->id;
870 $info[
'phpgwTz'] = 0;
871 $info[
'phpgwMailType'] =
'INTERNET';
872 $info[
'phpgwMailHomeType'] =
'INTERNET';
874 $info[
"phpgwContactTypeId"] =
'n';
875 $info[
"phpgwContactCatId"] = 0;
876 $info[
"phpgwContactAccess"] =
"public";
879 $this->egroupware_id = 1;
882 $info[
"phpgwContactOwner"] = $this->egroupware_id;
885 $info[
"rfc822Mailbox"] = $this->email;
887 if ($this->phone_mobile) {
888 $info[
"phpgwCellTelephoneNumber"] = $this->phone_mobile;
914 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"socpeople SET";
915 $sql .=
" birthday = ".($this->birthday ?
"'".$this->db->idate($this->birthday).
"'" :
"null");
916 $sql .=
", photo = ".($this->photo ?
"'".$this->db->escape($this->photo).
"'" :
"null");
918 $sql .=
", fk_user_modif = ".((int) $user->id);
920 $sql .=
" WHERE rowid = ".((int) $id);
922 dol_syslog(get_class($this).
"::update_perso this->birthday=".$this->birthday.
" -", LOG_DEBUG);
923 $resql = $this->db->query(
$sql);
926 $this->error = $this->db->lasterror();
931 if (!empty($this->birthday_alert)) {
933 $sql_check =
"SELECT rowid FROM " . MAIN_DB_PREFIX .
"user_alert WHERE type = 1 AND fk_contact = " . ((int) $id) .
" AND fk_user = " . ((int) $user->id);
934 $result_check = $this->db->query($sql_check);
935 if (!$result_check || ($this->db->num_rows($result_check) < 1)) {
937 $sql =
"INSERT INTO " . MAIN_DB_PREFIX .
"user_alert(type, fk_contact, fk_user) ";
938 $sql .=
"VALUES (1," . ((int) $id) .
"," . ((int) $user->id) .
")";
939 $result = $this->db->query(
$sql);
942 $this->error = $this->db->lasterror();
948 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"user_alert ";
949 $sql .=
"WHERE type=1 AND fk_contact=" . ((int) $id) .
" AND fk_user=" . ((int) $user->id);
950 $result = $this->db->query(
$sql);
953 $this->error = $this->db->lasterror();
958 if (!$error && !$notrigger) {
971 dol_syslog(get_class($this).
"::update Error ".$this->error, LOG_ERR);
972 $this->db->rollback();
988 public function fetch($id, $user =
null, $ref_ext =
'', $email =
'', $loadalsoroles = 0)
992 dol_syslog(get_class($this).
"::fetch id=".$id.
" ref_ext=".$ref_ext.
" email=".$email, LOG_DEBUG);
994 if (empty($id) && empty($ref_ext) && empty($email)) {
995 $this->error =
'BadParameter';
999 $langs->loadLangs(array(
"dict",
"companies"));
1001 $sql =
"SELECT c.rowid, c.entity, c.fk_soc, c.ref_ext, c.civility as civility_code, c.lastname, c.firstname,";
1002 $sql .=
" c.address, c.statut, c.zip, c.town,";
1003 $sql .=
" c.fk_pays as country_id,";
1004 $sql .=
" c.fk_departement as state_id,";
1005 $sql .=
" c.birthday,";
1006 $sql .=
" c.poste, c.phone, c.phone_perso, c.phone_mobile, c.fax, c.email,";
1007 $sql .=
" c.socialnetworks,";
1008 $sql .=
" c.photo,";
1009 $sql .=
" c.priv, c.note_private, c.note_public, c.default_lang, c.canvas,";
1010 $sql .=
" c.fk_prospectlevel, c.fk_stcommcontact, st.libelle as stcomm, st.picto as stcomm_picto,";
1011 $sql .=
" c.import_key,";
1012 $sql .=
" c.datec as date_creation, c.tms as date_modification,";
1013 $sql .=
" co.label as country, co.code as country_code,";
1014 $sql .=
" d.nom as state, d.code_departement as state_code,";
1015 $sql .=
" u.rowid as user_id, u.login as user_login,";
1016 $sql .=
" s.nom as socname, s.address as socaddress, s.zip as soccp, s.town as soccity, s.default_lang as socdefault_lang";
1017 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as c";
1018 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as co ON c.fk_pays = co.rowid";
1019 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_departements as d ON c.fk_departement = d.rowid";
1020 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u ON c.rowid = u.fk_socpeople";
1021 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON c.fk_soc = s.rowid";
1022 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_stcommcontact as st ON c.fk_stcommcontact = st.id';
1024 $sql .=
" WHERE c.rowid = ".((int) $id);
1026 $sql .=
" WHERE c.entity IN (".getEntity($this->element).
")";
1028 $sql .=
" AND c.ref_ext = '".$this->db->escape($ref_ext).
"'";
1031 $sql .=
" AND c.email = '".$this->db->escape($email).
"'";
1035 $resql = $this->db->query(
$sql);
1037 $num = $this->db->num_rows($resql);
1039 $this->error =
'Fetch found several records. Rename one of contact to avoid duplicate.';
1044 $obj = $this->db->fetch_object($resql);
1046 $this->
id = $obj->rowid;
1047 $this->entity = $obj->entity;
1048 $this->
ref = $obj->rowid;
1049 $this->ref_ext = $obj->ref_ext;
1051 $this->civility_code = $obj->civility_code;
1052 $this->civility = $obj->civility_code ? ($langs->trans(
"Civility".$obj->civility_code) != (
"Civility".$obj->civility_code) ? $langs->trans(
"Civility".$obj->civility_code) : $obj->civility_code) :
'';
1054 $this->lastname = $obj->lastname;
1055 $this->firstname = $obj->firstname;
1056 $this->address = $obj->address;
1057 $this->zip = $obj->zip;
1058 $this->town = $obj->town;
1060 $this->date_creation = $this->db->jdate($obj->date_creation);
1061 $this->date_modification = $this->db->jdate($obj->date_modification);
1063 $this->state_id = $obj->state_id;
1064 $this->state_code = $obj->state_code;
1065 $this->state = $obj->state;
1067 $this->country_id = $obj->country_id;
1068 $this->country_code = $obj->country_id ? $obj->country_code :
'';
1069 $this->country = $obj->country_id ? ($langs->trans(
'Country'.$obj->country_code) !=
'Country'.$obj->country_code ? $langs->transnoentities(
'Country'.$obj->country_code) : $obj->country) :
'';
1071 $this->fk_soc = $obj->fk_soc;
1072 $this->socid = $obj->fk_soc;
1073 $this->socname = $obj->socname;
1074 $this->poste = $obj->poste;
1075 $this->statut = $obj->statut;
1077 $this->fk_prospectlevel = $obj->fk_prospectlevel;
1079 $transcode = $langs->trans(
'StatusProspect'.$obj->fk_stcommcontact);
1080 $libelle = ($transcode !=
'StatusProspect'.$obj->fk_stcommcontact ? $transcode : $obj->stcomm);
1081 $this->stcomm_id = $obj->fk_stcommcontact;
1082 $this->statut_commercial = $libelle;
1083 $this->stcomm_picto = $obj->stcomm_picto;
1085 $this->phone_pro = trim($obj->phone);
1086 $this->fax = trim($obj->fax);
1087 $this->phone_perso = trim($obj->phone_perso);
1088 $this->phone_mobile = trim($obj->phone_mobile);
1090 $this->email = $obj->email;
1091 $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks,
true) : array());
1092 $this->photo = $obj->photo;
1093 $this->priv = $obj->priv;
1094 $this->mail = $obj->email;
1096 $this->birthday = $this->db->jdate($obj->birthday);
1097 $this->note = $obj->note_private;
1098 $this->note_private = $obj->note_private;
1099 $this->note_public = $obj->note_public;
1100 $this->default_lang = $obj->default_lang;
1101 $this->user_id = $obj->user_id;
1102 $this->user_login = $obj->user_login;
1103 $this->canvas = $obj->canvas;
1105 $this->import_key = $obj->import_key;
1111 $sql =
"SELECT u.rowid ";
1112 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
1113 $sql .=
" WHERE u.fk_socpeople = ".((int) $this->
id);
1115 $resql = $this->db->query(
$sql);
1117 if ($this->db->num_rows($resql)) {
1118 $uobj = $this->db->fetch_object($resql);
1120 $this->user_id = $uobj->rowid;
1122 $this->db->free($resql);
1124 $this->error = $this->db->error();
1134 $sql =
"SELECT fk_user";
1135 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user_alert";
1136 $sql .=
" WHERE fk_user = ".((int) $user->id).
" AND fk_contact = ".((int) $id);
1138 $resql = $this->db->query(
$sql);
1140 if ($this->db->num_rows($resql)) {
1141 $obj = $this->db->fetch_object($resql);
1143 $this->birthday_alert = 1;
1145 $this->db->free($resql);
1147 $this->error = $this->db->error();
1153 if ($loadalsoroles) {
1155 if ($resultRole < 0) {
1162 $this->error = $langs->trans(
"RecordNotFound");
1166 $this->error = $this->db->error();
1181 unset($this->gender);
1183 if (in_array($this->civility_id, array(
'MR')) || in_array($this->civility_code, array(
'MR'))) {
1184 $this->gender =
'man';
1185 } elseif (in_array($this->civility_id, array(
'MME',
'MLE')) || in_array($this->civility_code, array(
'MME',
'MLE'))) {
1186 $this->gender =
'woman';
1204 $sql =
"SELECT tc.element, count(ec.rowid) as nb";
1205 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_contact as ec, ".MAIN_DB_PREFIX.
"c_type_contact as tc";
1206 $sql .=
" WHERE ec.fk_c_type_contact = tc.rowid";
1207 $sql .=
" AND fk_socpeople = ".((int) $this->
id);
1208 $sql .=
" AND tc.source = 'external'";
1209 $sql .=
" GROUP BY tc.element";
1211 dol_syslog(get_class($this).
"::load_ref_elements", LOG_DEBUG);
1213 $resql = $this->db->query(
$sql);
1215 while ($obj = $this->db->fetch_object($resql)) {
1217 if ($obj->element ==
'facture') {
1218 $this->ref_facturation = $obj->nb;
1219 } elseif ($obj->element ==
'contrat') {
1220 $this->ref_contrat = $obj->nb;
1221 } elseif ($obj->element ==
'commande') {
1222 $this->ref_commande = $obj->nb;
1223 } elseif ($obj->element ==
'propal') {
1224 $this->ref_propal = $obj->nb;
1228 $this->db->free($resql);
1231 $this->error = $this->db->lasterror();
1243 public function delete($notrigger = 0)
1245 global $conf, $langs, $user;
1251 if (!$error && !$notrigger) {
1253 $result = $this->
call_trigger(
'CONTACT_DELETE', $user);
1262 $sql =
"SELECT ec.rowid";
1263 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_contact ec,";
1264 $sql .=
" ".MAIN_DB_PREFIX.
"c_type_contact tc";
1265 $sql .=
" WHERE ec.fk_socpeople=".((int) $this->
id);
1266 $sql .=
" AND ec.fk_c_type_contact=tc.rowid";
1267 $sql .=
" AND tc.source='external'";
1269 $resql = $this->db->query(
$sql);
1271 $num = $this->db->num_rows($resql);
1274 while ($i < $num && !$error) {
1275 $obj = $this->db->fetch_object($resql);
1277 $sqldel =
"DELETE FROM ".MAIN_DB_PREFIX.
"element_contact";
1278 $sqldel .=
" WHERE rowid = ".((int) $obj->rowid);
1280 $result = $this->db->query($sqldel);
1283 $this->error = $this->db->error().
' sql='.$sqldel;
1290 $this->error = $this->db->error().
' sql='.
$sql;
1296 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_contacts WHERE fk_socpeople = ".((int) $this->
id);
1298 $resql = $this->db->query(
$sql);
1301 $this->error .= $this->db->lasterror();
1308 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_contacts WHERE fk_socpeople = ".((int) $this->
id);
1310 $resql = $this->db->query(
$sql);
1313 $this->error .= $this->db->lasterror();
1320 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_contact WHERE fk_socpeople = ".((int) $this->
id);
1322 $resql = $this->db->query(
$sql);
1325 $this->error .= $this->db->lasterror();
1331 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"socpeople";
1332 $sql .=
" WHERE rowid = ".((int) $this->
id);
1334 $result = $this->db->query(
$sql);
1337 $this->error = $this->db->error().
' sql='.
$sql;
1351 $this->db->commit();
1354 $this->db->rollback();
1369 $sql =
"SELECT c.rowid, c.datec as datec, c.fk_user_creat,";
1370 $sql .=
" c.tms as tms, c.fk_user_modif";
1371 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as c";
1372 $sql .=
" WHERE c.rowid = ".((int) $id);
1374 $resql = $this->db->query(
$sql);
1376 if ($this->db->num_rows($resql)) {
1377 $obj = $this->db->fetch_object($resql);
1379 $this->
id = $obj->rowid;
1381 if ($obj->fk_user_creat) {
1382 $cuser =
new User($this->db);
1383 $cuser->fetch($obj->fk_user_creat);
1384 $this->user_creation = $cuser;
1387 if ($obj->fk_user_modif) {
1388 $muser =
new User($this->db);
1389 $muser->fetch($obj->fk_user_modif);
1390 $this->user_modification = $muser;
1393 $this->date_creation = $this->db->jdate($obj->datec);
1394 $this->date_modification = $this->db->jdate($obj->tms);
1397 $this->db->free($resql);
1399 print $this->db->error();
1410 $sql =
"SELECT count(mc.email) as nb";
1411 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mailing_cibles as mc, ".MAIN_DB_PREFIX.
"mailing as m";
1412 $sql .=
" WHERE mc.fk_mailing=m.rowid AND mc.email = '".$this->db->escape($this->email).
"' ";
1413 $sql .=
" AND m.entity IN (".getEntity($this->element).
") AND mc.statut NOT IN (-1,0)";
1415 $resql = $this->db->query(
$sql);
1417 $obj = $this->db->fetch_object($resql);
1420 $this->db->free($resql);
1423 $this->error = $this->db->error();
1436 global $conf, $langs, $user;
1440 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1441 return [
'optimize' => $langs->trans(
"ShowContact")];
1443 if (!empty($this->photo) && class_exists(
'Form')) {
1444 $photo =
'<div class="photointooltip floatright">';
1445 $photo .=
Form::showphoto(
'contact', $this, 0, 40, 0,
'photoref',
'mini', 0);
1447 $datas[
'photo'] = $photo;
1450 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Contact").
'</u> ' . $this->
getLibStatut(4);
1451 $datas[
'name'] =
'<br><b>'.$langs->trans(
"Name").
':</b> '.$this->
getFullName($langs);
1453 if (!empty($this->poste)) {
1454 $datas[
'job'] =
'<br><b>'.$langs->trans(
"Poste").
':</b> '.$this->poste;
1456 $datas[
'email'] =
'<br><b>'.$langs->trans(
"EMail").
':</b> '.$this->email;
1457 $phonelist = array();
1458 $country_code = empty($this->country_code) ?
'': $this->country_code;
1459 if ($this->phone_pro) {
1460 $phonelist[] =
dol_print_phone($this->phone_pro, $country_code, $this->
id, 0,
'',
' ',
'phone');
1462 if ($this->phone_mobile) {
1463 $phonelist[] =
dol_print_phone($this->phone_mobile, $country_code, $this->
id, 0,
'',
' ',
'mobile');
1465 if ($this->phone_perso) {
1466 $phonelist[] =
dol_print_phone($this->phone_perso, $country_code, $this->
id, 0,
'',
' ',
'phone');
1468 $datas[
'phonelist'] =
'<br><b>'.$langs->trans(
"Phone").
':</b> '.implode(
' ', $phonelist);
1469 $datas[
'address'] =
'<br><b>'.$langs->trans(
"Address").
':</b> '.
dol_format_address($this, 1,
' ', $langs);
1487 public function getNomUrl($withpicto = 0, $option =
'', $maxlen = 0, $moreparam =
'', $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'')
1489 global $conf, $langs, $hookmanager;
1491 if (!empty($conf->dol_no_mouse_hover)) {
1498 'objecttype' => $this->element,
1499 'option' => $option,
1501 $classfortooltip =
'classfortooltip';
1504 $classfortooltip =
'classforajaxtooltip';
1505 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1511 $url = DOL_URL_ROOT.
'/contact/card.php?id='.$this->id;
1513 if ($option !==
'nolink') {
1515 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1516 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1517 $add_save_lastsearch_values = 1;
1519 if ($url && $add_save_lastsearch_values) {
1520 $url .=
'&save_lastsearch_values=1';
1527 if (empty($notooltip)) {
1528 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1529 $label = $langs->trans(
"ShowContact");
1530 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1532 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
1533 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1535 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1538 if ($option ==
'nolink' || empty($url)) {
1539 $linkstart =
'<span';
1541 $linkstart =
'<a href="'.$url.
'"';
1543 $linkstart .= $linkclose.
'>';
1544 if ($option ==
'nolink' || empty($url)) {
1545 $linkend =
'</span>';
1550 $result .= $linkstart;
1553 if ($withpicto < 0) {
1554 $result .=
'<!-- picto photo user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'">'.
Form::showphoto(
'contact', $this, 0, 0, 0,
'userphoto'.($withpicto == -3 ?
'small' :
''),
'mini', 0, 1).
'</span>';
1555 if ($withpicto != 2 && $withpicto != -2) {
1559 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="pictofixedwidth"' :
'') :
'class="'.(($withpicto != 2) ?
'pictofixedwidth ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1562 if ($withpicto != 2 && $withpicto != -2) {
1566 $result .= $linkend;
1569 $hookmanager->initHooks(array(
'contactdao'));
1570 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1571 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1573 $result = $hookmanager->resPrint;
1575 $result .= $hookmanager->resPrint;
1590 $code = ($this->civility_code ? $this->civility_code : (!empty($this->civility_id) ? $this->civility : (!empty($this->civilite) ? $this->civilite :
'')));
1595 $langs->load(
"dict");
1596 return $langs->getLabelFromKey($this->db,
"Civility".$code,
"c_civility",
"code",
"label", $code);
1607 return $this->
LibStatut($this->statut, $mode);
1623 $labelStatus = array(
1624 0 =>
'ActivityCeased',
1627 5 =>
'ActivityCeased',
1629 $labelStatusShort = array(
1630 0 =>
'ActivityCeased',
1633 5 =>
'ActivityCeased',
1636 $statusType =
'status4';
1637 if ($status == 0 || $status == 5) {
1638 $statusType =
'status5';
1641 $label = $langs->transnoentitiesnoconv($labelStatus[$status]);
1642 $labelshort = $langs->transnoentitiesnoconv($labelStatusShort[$status]);
1644 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
1659 if ($status ==
'1') {
1660 return $langs->trans(
'ContactPrivate');
1662 return $langs->trans(
'ContactPublic');
1678 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe ORDER BY rowid LIMIT 1";
1679 $resql = $this->db->query(
$sql);
1681 $obj = $this->db->fetch_object($resql);
1683 $socid = $obj->rowid;
1690 $this->specimen = 1;
1691 $this->lastname =
'DOLIBARR';
1692 $this->firstname =
'SPECIMEN';
1693 $this->address =
'21 jump street';
1694 $this->zip =
'99999';
1695 $this->town =
'MyTown';
1696 $this->country_id = 1;
1697 $this->country_code =
'FR';
1698 $this->country =
'France';
1699 $this->email =
'specimen@specimen.com';
1700 $this->socialnetworks = array(
1701 'skype' =>
'tom.hanson',
1703 $this->phone_pro =
'0909090901';
1704 $this->phone_perso =
'0909090902';
1705 $this->phone_mobile =
'0909090903';
1706 $this->fax =
'0909090909';
1708 $this->note_public =
'This is a comment (public)';
1709 $this->note_private =
'This is a comment (private)';
1711 $this->socid = $socid;
1724 global $conf, $langs, $user;
1729 if ($this->statut == $status) {
1732 $this->statut = $status;
1738 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"socpeople";
1739 $sql .=
" SET statut = ".((int) $this->statut);
1740 $sql .=
" WHERE rowid = ".((int) $this->
id);
1741 $result = $this->db->query(
$sql);
1743 dol_syslog(get_class($this).
"::setstatus", LOG_DEBUG);
1746 $result = $this->
call_trigger(
'CONTACT_ENABLEDISABLE', $user);
1754 $this->db->rollback();
1757 $this->db->commit();
1774 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1775 return parent::setCategoriesCommon($categories, Categorie::TYPE_CONTACT);
1789 'socpeople',
'societe_contacts'
1808 $sql =
"SELECT tc.rowid, tc.element, tc.source, tc.code, tc.libelle as label, sc.rowid as contactroleid, sc.fk_soc as socid";
1809 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_contacts as sc, ".MAIN_DB_PREFIX.
"c_type_contact as tc";
1810 $sql .=
" WHERE tc.rowid = sc.fk_c_type_contact";
1811 $sql .=
" AND tc.source = 'external' AND tc.active=1";
1812 $sql .=
" AND sc.fk_socpeople = ".((int) $this->
id);
1813 $sql .=
" AND sc.entity IN (".getEntity(
'societe').
')';
1815 $resql = $this->db->query(
$sql);
1817 $this->roles = array();
1819 $num = $this->db->num_rows($resql);
1821 while ($obj = $this->db->fetch_object($resql)) {
1822 $transkey =
"TypeContact_".$obj->element.
"_".$obj->source.
"_".$obj->code;
1823 $libelle_element = $langs->trans(
'ContactDefault_'.$obj->element);
1824 $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));
1829 $this->error = $this->db->lasterror();
1830 $this->errors[] = $this->db->lasterror();
1833 if (empty($error)) {
1851 if ($element ==
'action') {
1852 $element =
'agenda';
1855 $sql =
"SELECT sc.fk_socpeople as id, sc.fk_c_type_contact";
1856 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact tc";
1857 $sql .=
", ".MAIN_DB_PREFIX.
"societe_contacts sc";
1858 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"socpeople sp";
1859 $sql .=
" ON sc.fk_socpeople = sp.rowid AND sp.statut = 1";
1860 $sql .=
" WHERE sc.fk_soc =".((int) $this->socid);
1861 $sql .=
" AND sc.fk_c_type_contact=tc.rowid";
1862 $sql .=
" AND tc.element = '".$this->db->escape($element).
"'";
1863 $sql .=
" AND tc.active = 1";
1866 $resql = $this->db->query(
$sql);
1868 $num = $this->db->num_rows($resql);
1871 $obj = $this->db->fetch_object($resql);
1872 $tab[] = array(
'fk_socpeople'=>$obj->id,
'type_contact'=>$obj->fk_c_type_contact);
1879 $this->error = $this->db->error();
1898 if (!isset($this->roles)) {
1904 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_contacts WHERE fk_socpeople=".((int) $this->
id).
" AND entity IN (".
getEntity(
"contact").
")";
1906 $result = $this->db->query(
$sql);
1908 $this->errors[] = $this->db->lasterror().
' sql='.
$sql;
1911 if (count($this->roles) > 0) {
1912 foreach ($this->roles as $keyRoles => $valRoles) {
1914 if (is_array($valRoles)) {
1915 $idrole = $valRoles[
'id'];
1917 $idrole = $valRoles;
1921 if (is_array($valRoles)) {
1922 $socid = $valRoles[
'socid'];
1924 $socid = $this->socid;
1928 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_contacts";
1929 $sql .=
" (entity,";
1930 $sql .=
"date_creation,";
1932 $sql .=
"fk_c_type_contact,";
1933 $sql .=
"fk_socpeople) ";
1934 $sql .=
" VALUES (".$conf->entity.
",";
1936 $sql .= $socid.
", ";
1937 $sql .= $idrole.
" , ";
1941 $result = $this->db->query(
$sql);
1943 $this->errors[] = $this->db->lasterror().
' sql='.
$sql;
1950 if (empty($error)) {
1951 $this->db->commit();
1954 $this->error = implode(
' ', $this->errors);
1955 $this->db->rollback();
1970 $sql =
"SELECT id, code, libelle as label, picto FROM ".MAIN_DB_PREFIX.
"c_stcommcontact";
1972 $sql .=
" WHERE active = ".((int) $active);
1974 $resql = $this->db->query(
$sql);
1975 $num = $this->db->num_rows($resql);
1978 $obj = $this->db->fetch_object($resql);
1979 $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);
2005 $lib = $langs->trans(
"ProspectLevel".$fk_prospectlevel);
2007 if ($lib == $langs->trans(
"ProspectLevel".$fk_prospectlevel)) {
2008 $lib = $langs->getLabelFromKey($this->db, $fk_prospectlevel,
'c_prospectlevel',
'code',
'label');
2023 return $this->
update($this->
id, $user);
2035 return $this->
libProspCommStatut($this->stcomm_id, $mode, $label, $this->stcomm_picto);
2054 $langs->load(
'customers');
2057 if ($statut ==
'-1' || $statut ==
'ST_NO') {
2058 return img_action($langs->trans(
"StatusProspect-1"), -1, $picto).
' '.$langs->trans(
"StatusProspect-1");
2059 } elseif ($statut ==
'0' || $statut ==
'ST_NEVER') {
2060 return img_action($langs->trans(
"StatusProspect0"), 0, $picto).
' '.$langs->trans(
"StatusProspect0");
2061 } elseif ($statut ==
'1' || $statut ==
'ST_TODO') {
2062 return img_action($langs->trans(
"StatusProspect1"), 1, $picto).
' '.$langs->trans(
"StatusProspect1");
2063 } elseif ($statut ==
'2' || $statut ==
'ST_PEND') {
2064 return img_action($langs->trans(
"StatusProspect2"), 2, $picto).
' '.$langs->trans(
"StatusProspect2");
2065 } elseif ($statut ==
'3' || $statut ==
'ST_DONE') {
2066 return img_action($langs->trans(
"StatusProspect3"), 3, $picto).
' '.$langs->trans(
"StatusProspect3");
2068 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);
2072 if ($statut ==
'-1' || $statut ==
'ST_NO') {
2073 return img_action($langs->trans(
"StatusProspect-1"), -1, $picto);
2074 } elseif ($statut ==
'0' || $statut ==
'ST_NEVER') {
2075 return img_action($langs->trans(
"StatusProspect0"), 0, $picto);
2076 } elseif ($statut ==
'1' || $statut ==
'ST_TODO') {
2077 return img_action($langs->trans(
"StatusProspect1"), 1, $picto);
2078 } elseif ($statut ==
'2' || $statut ==
'ST_PEND') {
2079 return img_action($langs->trans(
"StatusProspect2"), 2, $picto);
2080 } elseif ($statut ==
'3' || $statut ==
'ST_DONE') {
2081 return img_action($langs->trans(
"StatusProspect3"), 3, $picto);
2083 return img_action(($langs->trans(
"StatusProspect".$statut) !=
"StatusProspect".$statut) ? $langs->trans(
"StatusProspect".$statut) : $label, 0, $picto);
2087 if ($statut ==
'-1' || $statut ==
'ST_NO') {
2088 return img_action($langs->trans(
"StatusProspect-1"), -1, $picto).
' '.$langs->trans(
"StatusProspect-1");
2089 } elseif ($statut ==
'0' || $statut ==
'ST_NEVER') {
2090 return img_action($langs->trans(
"StatusProspect0"), 0, $picto).
' '.$langs->trans(
"StatusProspect0");
2091 } elseif ($statut ==
'1' || $statut ==
'ST_TODO') {
2092 return img_action($langs->trans(
"StatusProspect1"), 1, $picto).
' '.$langs->trans(
"StatusProspect1");
2093 } elseif ($statut ==
'2' || $statut ==
'ST_PEND') {
2094 return img_action($langs->trans(
"StatusProspect2"), 2, $picto).
' '.$langs->trans(
"StatusProspect2");
2095 } elseif ($statut ==
'3' || $statut ==
'ST_DONE') {
2096 return img_action($langs->trans(
"StatusProspect3"), 3, $picto).
' '.$langs->trans(
"StatusProspect3");
2098 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);
2102 return "Error, mode/status not found";
2121 $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).
"'";
2122 $resql = $this->db->query(
$sql);
2124 $obj = $this->db->fetch_object($resql);
2125 $noemail = $obj->nb;
2126 if (empty($noemail)) {
2127 $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()).
"')";
2128 $resql = $this->db->query(
$sql);
2131 $this->error = $this->db->lasterror();
2132 $this->errors[] = $this->error;
2137 $this->error = $this->db->lasterror();
2138 $this->errors[] = $this->error;
2141 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE email = '".$this->db->escape($this->email).
"' AND entity IN (".
getEntity(
'mailing', 0).
")";
2142 $resql = $this->db->query(
$sql);
2145 $this->error = $this->db->lasterror();
2146 $this->errors[] = $this->error;
2150 if (empty($error)) {
2151 $this->no_email = $no_email;
2152 $this->db->commit();
2155 $this->db->rollback();
2172 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE entity IN (".
getEntity(
'mailing').
") AND email = '".$this->db->escape($this->email).
"'";
2173 $resql = $this->db->query(
$sql);
2175 $obj = $this->db->fetch_object($resql);
2176 $this->no_email = $obj->nb;
2179 $this->error = $this->db->lasterror();
2180 $this->errors[] = $this->error;
2197 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
2199 $return =
'<div class="box-flex-item box-flex-grow-zero">';
2200 $return .=
'<div class="info-box info-box-sm">';
2201 $return .=
'<span class="info-box-icon bg-infobox-action">';
2203 if (property_exists($this,
'photo') && !is_null($this->photo)) {
2204 $return.=
Form::showphoto(
'contact', $this, 0, 60, 0,
'photokanban photoref photowithmargin photologintooltip',
'small', 0, 1);
2208 $return .=
'</span>';
2209 $return .=
'<div class="info-box-content">';
2210 $return .=
'<div class="info-box-ref">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(1) : $this->ref).
'</div>';
2211 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
2213 if (property_exists($this,
'thirdparty') && is_object($this->thirdparty)) {
2214 $return .=
'<div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).
'</div>';
2224 if (method_exists($this,
'getLibStatut')) {
2225 $return .=
'<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3).
'</div>';
2227 $return .=
'</div>';
2228 $return .=
'</div>';
2229 $return .=
'</div>';