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_prospectcontactlevel' =>array(
'type'=>
'varchar(12)',
'label'=>
'ProspectLevel',
'enabled'=>1,
'visible'=>-1,
'position'=>255),
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;
245 public $socialnetworks;
300 public $phone_mobile;
314 public $default_lang;
319 public $ref_facturation;
329 public $ref_commande;
360 public $cacheprospectstatus = array();
361 public $fk_prospectlevel;
363 public $statut_commercial;
368 public $stcomm_picto;
378 global $conf, $langs;
383 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) {
384 $this->fields[
'rowid'][
'visible'] = 0;
387 $this->fields[
'no_email'][
'enabled'] = 0;
390 if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
391 $this->fields[
'fk_soc'][
'enabled'] = 0;
392 $this->fields[
'fk_soc'][
'searchall'] = 0;
396 if (!empty($conf->global->SOCIETE_DISABLE_PROSPECTS) || empty($conf->global->THIRDPARTY_ENABLE_PROSPECTION_ON_ALTERNATIVE_ADRESSES)) {
397 $this->fields[
'fk_stcommcontact'][
'enabled'] = 0;
398 $this->fields[
'fk_prospectcontactlevel'][
'enabled'] = 0;
402 foreach ($this->fields as $key => $val) {
403 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
404 unset($this->fields[$key]);
433 global $user, $hookmanager;
438 $sql =
"SELECT count(sp.rowid) as nb";
439 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as sp";
440 if (empty($user->rights->societe->client->voir) && !$user->socid) {
441 $sql .=
", ".MAIN_DB_PREFIX.
"societe as s";
442 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
443 $sql .=
" WHERE sp.fk_soc = s.rowid AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
446 $sql .=
" ".$clause.
" sp.entity IN (".
getEntity($this->element).
")";
447 $sql .=
" AND (sp.priv='0' OR (sp.priv='1' AND sp.fk_user_creat = ".((int) $user->id).
"))";
448 if ($user->socid > 0) {
449 $sql .=
" AND sp.fk_soc = ".((int) $user->socid);
452 if (is_object($hookmanager)) {
453 $parameters = array();
454 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $this);
455 $sql .= $hookmanager->resPrint;
458 $resql = $this->db->query(
$sql);
460 while ($obj = $this->db->fetch_object($resql)) {
461 $this->nb[
"contacts"] = $obj->nb;
463 $this->db->free($resql);
467 $this->error = $this->db->lasterror();
479 public function create($user, $notrigger = 0)
489 $this->lastname = $this->lastname ?trim($this->lastname) : trim($this->
name);
490 $this->firstname = trim($this->firstname);
492 if (empty($this->socid)) {
495 if (empty($this->priv)) {
498 if (empty($this->statut)) {
502 $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity);
504 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"socpeople (";
507 $sql .=
", lastname";
508 $sql .=
", firstname";
509 $sql .=
", fk_user_creat";
511 $sql .=
", fk_stcommcontact";
516 $sql .=
", import_key";
517 $sql .=
") VALUES (";
518 $sql .=
"'".$this->db->idate($now).
"',";
519 if ($this->socid > 0) {
520 $sql .=
" ".((int) $this->socid).
",";
524 $sql .=
"'".$this->db->escape($this->lastname).
"',";
525 $sql .=
"'".$this->db->escape($this->firstname).
"',";
526 $sql .=
" ".($user->id > 0 ? ((int) $user->id) :
"null").
",";
527 $sql .=
" ".((int) $this->priv).
",";
529 $sql .=
" ".((int) $this->statut).
",";
530 $sql .=
" ".(!empty($this->canvas) ?
"'".$this->db->escape($this->canvas).
"'" :
"null").
",";
531 $sql .=
" ".((int) $this->entity).
",";
532 $sql .=
"'".$this->db->escape($this->ref_ext).
"',";
533 $sql .=
" ".(!empty($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
536 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
537 $resql = $this->db->query(
$sql);
539 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"socpeople");
542 $result = $this->
update($this->
id, $user, 1,
'add');
545 $this->error = $this->db->lasterror();
553 $this->error = $this->db->lasterror();
557 if (!$error && !$notrigger) {
570 $this->db->rollback();
571 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
575 $this->error = $this->db->lasterror();
577 $this->db->rollback();
578 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
593 public function update($id, $user =
null, $notrigger = 0, $action =
'update', $nosyncuser = 0)
595 global $conf, $langs, $hookmanager;
601 $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity);
604 $this->ref_ext = trim($this->ref_ext);
605 $this->lastname = trim($this->lastname) ?trim($this->lastname) : trim($this->lastname);
606 $this->firstname = trim($this->firstname);
607 $this->email = trim($this->email);
608 $this->phone_pro = trim($this->phone_pro);
609 $this->phone_perso = trim($this->phone_perso);
610 $this->phone_mobile = trim($this->phone_mobile);
611 $this->photo = trim($this->photo);
612 $this->fax = trim($this->fax);
613 $this->zip = (empty($this->zip) ?
'' : trim($this->zip));
614 $this->town = (empty($this->town) ?
'' : trim($this->town));
615 $this->country_id = ($this->country_id > 0 ? $this->country_id : $this->country_id);
616 if (empty($this->statut)) {
619 if (empty($this->civility_code) && !is_numeric($this->civility_id)) {
620 $this->civility_code = $this->civility_id;
625 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"socpeople SET";
626 if ($this->socid > 0) {
627 $sql .=
" fk_soc = ".((int) $this->socid).
",";
628 } elseif ($this->socid == -1) {
629 $sql .=
" fk_soc = NULL,";
631 $sql .=
" civility='".$this->db->escape($this->civility_code).
"'";
632 $sql .=
", lastname='".$this->db->escape($this->lastname).
"'";
633 $sql .=
", firstname='".$this->db->escape($this->firstname).
"'";
634 $sql .=
", address='".$this->db->escape($this->address).
"'";
635 $sql .=
", zip='".$this->db->escape($this->zip).
"'";
636 $sql .=
", town='".$this->db->escape($this->town).
"'";
637 $sql .=
", ref_ext = ".(!empty($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"NULL");
638 $sql .=
", fk_pays=".($this->country_id > 0 ? $this->country_id :
'NULL');
639 $sql .=
", fk_departement=".($this->state_id > 0 ? $this->state_id :
'NULL');
640 $sql .=
", poste='".$this->db->escape($this->poste).
"'";
641 $sql .=
", fax='".$this->db->escape($this->fax).
"'";
642 $sql .=
", email='".$this->db->escape($this->email).
"'";
643 $sql .=
", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
644 $sql .=
", photo='".$this->db->escape($this->photo).
"'";
645 $sql .=
", birthday=".($this->birthday ?
"'".$this->db->idate($this->birthday).
"'" :
"null");
646 $sql .=
", note_private = ".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"NULL");
647 $sql .=
", note_public = ".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"NULL");
648 $sql .=
", phone = ".(isset($this->phone_pro) ?
"'".$this->db->escape($this->phone_pro).
"'" :
"NULL");
649 $sql .=
", phone_perso = ".(isset($this->phone_perso) ?
"'".$this->db->escape($this->phone_perso).
"'" :
"NULL");
650 $sql .=
", phone_mobile = ".(isset($this->phone_mobile) ?
"'".$this->db->escape($this->phone_mobile).
"'" :
"NULL");
651 $sql .=
", priv = '".$this->db->escape($this->priv).
"'";
652 $sql .=
", fk_prospectlevel = '".$this->db->escape($this->fk_prospectlevel).
"'";
653 if (isset($this->stcomm_id)) {
654 $sql .=
", fk_stcommcontact = ".($this->stcomm_id > 0 || $this->stcomm_id == -1 ? $this->stcomm_id :
"0");
656 $sql .=
", statut = ".((int) $this->statut);
657 $sql .=
", fk_user_modif=".($user->id > 0 ?
"'".$this->db->escape($user->id).
"'" :
"NULL");
658 $sql .=
", default_lang=".($this->default_lang ?
"'".$this->db->escape($this->default_lang).
"'" :
"NULL");
659 $sql .=
", entity = ".((int) $this->entity);
660 $sql .=
" WHERE rowid = ".((int) $id);
662 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
663 $result = $this->db->query(
$sql);
665 unset($this->country_code);
666 unset($this->country);
667 unset($this->state_code);
687 if (!$error && $this->user_id > 0) {
689 $tmpobj =
new User($this->db);
690 $tmpobj->fetch($this->user_id);
691 $usermustbemodified = 0;
692 if ($tmpobj->office_phone != $this->phone_pro) {
693 $tmpobj->office_phone = $this->phone_pro;
694 $usermustbemodified++;
696 if ($tmpobj->office_fax != $this->fax) {
697 $tmpobj->office_fax = $this->fax;
698 $usermustbemodified++;
700 if ($tmpobj->address != $this->address) {
701 $tmpobj->address = $this->address;
702 $usermustbemodified++;
704 if ($tmpobj->town != $this->town) {
705 $tmpobj->town = $this->town;
706 $usermustbemodified++;
708 if ($tmpobj->zip != $this->zip) {
709 $tmpobj->zip = $this->zip;
710 $usermustbemodified++;
712 if ($tmpobj->zip != $this->zip) {
713 $tmpobj->state_id = $this->state_id;
714 $usermustbemodified++;
716 if ($tmpobj->country_id != $this->country_id) {
717 $tmpobj->country_id = $this->country_id;
718 $usermustbemodified++;
720 if ($tmpobj->email != $this->email) {
721 $tmpobj->email = $this->email;
722 $usermustbemodified++;
724 if (!empty(array_diff($tmpobj->socialnetworks, $this->socialnetworks))) {
725 $tmpobj->socialnetworks = $this->socialnetworks;
726 $usermustbemodified++;
728 if ($usermustbemodified) {
729 $result = $tmpobj->update($user, 0, 1, 1, 1);
736 if (!$error && !$notrigger) {
749 dol_syslog(get_class($this).
"::update Error ".$this->error, LOG_ERR);
750 $this->db->rollback();
754 $this->error = $this->db->lasterror().
' sql='.
$sql;
755 $this->db->rollback();
778 $dn = $conf->global->LDAP_KEY_CONTACTS.
"=".$info[$conf->global->LDAP_KEY_CONTACTS].
",".$conf->global->LDAP_CONTACT_DN;
779 } elseif ($mode == 1) {
780 $dn = $conf->global->LDAP_CONTACT_DN;
781 } elseif ($mode == 2) {
782 $dn = $conf->global->LDAP_KEY_CONTACTS.
"=".$info[$conf->global->LDAP_KEY_CONTACTS];
798 global $conf, $langs;
803 $info[
"objectclass"] = explode(
',', $conf->global->LDAP_CONTACT_OBJECT_CLASS);
808 if ($this->fullname && !empty($conf->global->LDAP_CONTACT_FIELD_FULLNAME)) {
809 $info[$conf->global->LDAP_CONTACT_FIELD_FULLNAME] = $this->fullname;
811 if ($this->lastname && !empty($conf->global->LDAP_CONTACT_FIELD_NAME)) {
812 $info[$conf->global->LDAP_CONTACT_FIELD_NAME] = $this->lastname;
814 if ($this->firstname && !empty($conf->global->LDAP_CONTACT_FIELD_FIRSTNAME)) {
815 $info[$conf->global->LDAP_CONTACT_FIELD_FIRSTNAME] = $this->firstname;
819 $info[
"title"] = $this->poste;
821 if ($this->socid > 0) {
823 $soc->fetch($this->socid);
825 $info[$conf->global->LDAP_CONTACT_FIELD_COMPANY] = $soc->name;
826 if ($soc->client == 1) {
827 $info[
"businessCategory"] =
"Customers";
829 if ($soc->client == 2) {
830 $info[
"businessCategory"] =
"Prospects";
832 if ($soc->fournisseur == 1) {
833 $info[
"businessCategory"] =
"Suppliers";
836 if ($this->address && !empty($conf->global->LDAP_CONTACT_FIELD_ADDRESS)) {
837 $info[$conf->global->LDAP_CONTACT_FIELD_ADDRESS] = $this->address;
839 if ($this->zip && !empty($conf->global->LDAP_CONTACT_FIELD_ZIP)) {
840 $info[$conf->global->LDAP_CONTACT_FIELD_ZIP] = $this->zip;
842 if ($this->town && !empty($conf->global->LDAP_CONTACT_FIELD_TOWN)) {
843 $info[$conf->global->LDAP_CONTACT_FIELD_TOWN] = $this->town;
845 if ($this->country_code && !empty($conf->global->LDAP_CONTACT_FIELD_COUNTRY)) {
846 $info[$conf->global->LDAP_CONTACT_FIELD_COUNTRY] = $this->country_code;
848 if ($this->phone_pro && !empty($conf->global->LDAP_CONTACT_FIELD_PHONE)) {
849 $info[$conf->global->LDAP_CONTACT_FIELD_PHONE] = $this->phone_pro;
851 if ($this->phone_perso && !empty($conf->global->LDAP_CONTACT_FIELD_HOMEPHONE)) {
852 $info[$conf->global->LDAP_CONTACT_FIELD_HOMEPHONE] = $this->phone_perso;
854 if ($this->phone_mobile && !empty($conf->global->LDAP_CONTACT_FIELD_MOBILE)) {
855 $info[$conf->global->LDAP_CONTACT_FIELD_MOBILE] = $this->phone_mobile;
857 if ($this->fax && !empty($conf->global->LDAP_CONTACT_FIELD_FAX)) {
858 $info[$conf->global->LDAP_CONTACT_FIELD_FAX] = $this->fax;
860 if ($this->note_private && !empty($conf->global->LDAP_CONTACT_FIELD_DESCRIPTION)) {
861 $info[$conf->global->LDAP_CONTACT_FIELD_DESCRIPTION] =
dol_string_nohtmltag($this->note_private, 2);
863 if ($this->email && !empty($conf->global->LDAP_CONTACT_FIELD_MAIL)) {
864 $info[$conf->global->LDAP_CONTACT_FIELD_MAIL] = $this->email;
867 if ($conf->global->LDAP_SERVER_TYPE ==
'egroupware') {
868 $info[
"objectclass"][4] =
"phpgwContact";
870 $info[
'uidnumber'] = $this->id;
872 $info[
'phpgwTz'] = 0;
873 $info[
'phpgwMailType'] =
'INTERNET';
874 $info[
'phpgwMailHomeType'] =
'INTERNET';
876 $info[
"phpgwContactTypeId"] =
'n';
877 $info[
"phpgwContactCatId"] = 0;
878 $info[
"phpgwContactAccess"] =
"public";
881 $this->egroupware_id = 1;
884 $info[
"phpgwContactOwner"] = $this->egroupware_id;
887 $info[
"rfc822Mailbox"] = $this->email;
889 if ($this->phone_mobile) {
890 $info[
"phpgwCellTelephoneNumber"] = $this->phone_mobile;
916 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"socpeople SET";
917 $sql .=
" birthday = ".($this->birthday ?
"'".$this->db->idate($this->birthday).
"'" :
"null");
918 $sql .=
", photo = ".($this->photo ?
"'".$this->db->escape($this->photo).
"'" :
"null");
920 $sql .=
", fk_user_modif = ".((int) $user->id);
922 $sql .=
" WHERE rowid = ".((int) $id);
924 dol_syslog(get_class($this).
"::update_perso this->birthday=".$this->birthday.
" -", LOG_DEBUG);
925 $resql = $this->db->query(
$sql);
928 $this->error = $this->db->lasterror();
933 if (!empty($this->birthday_alert)) {
935 $sql_check =
"SELECT rowid FROM " . MAIN_DB_PREFIX .
"user_alert WHERE type = 1 AND fk_contact = " . ((int) $id) .
" AND fk_user = " . ((int) $user->id);
936 $result_check = $this->db->query($sql_check);
937 if (!$result_check || ($this->db->num_rows($result_check) < 1)) {
939 $sql =
"INSERT INTO " . MAIN_DB_PREFIX .
"user_alert(type, fk_contact, fk_user) ";
940 $sql .=
"VALUES (1," . ((int) $id) .
"," . ((int) $user->id) .
")";
941 $result = $this->db->query(
$sql);
944 $this->error = $this->db->lasterror();
950 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"user_alert ";
951 $sql .=
"WHERE type=1 AND fk_contact=" . ((int) $id) .
" AND fk_user=" . ((int) $user->id);
952 $result = $this->db->query(
$sql);
955 $this->error = $this->db->lasterror();
960 if (!$error && !$notrigger) {
973 dol_syslog(get_class($this).
"::update Error ".$this->error, LOG_ERR);
974 $this->db->rollback();
990 public function fetch($id, $user =
null, $ref_ext =
'', $email =
'', $loadalsoroles = 0)
994 dol_syslog(get_class($this).
"::fetch id=".$id.
" ref_ext=".$ref_ext.
" email=".$email, LOG_DEBUG);
996 if (empty($id) && empty($ref_ext) && empty($email)) {
997 $this->error =
'BadParameter';
1001 $langs->loadLangs(array(
"dict",
"companies"));
1003 $sql =
"SELECT c.rowid, c.entity, c.fk_soc, c.ref_ext, c.civility as civility_code, c.lastname, c.firstname,";
1004 $sql .=
" c.address, c.statut, c.zip, c.town,";
1005 $sql .=
" c.fk_pays as country_id,";
1006 $sql .=
" c.fk_departement as state_id,";
1007 $sql .=
" c.birthday,";
1008 $sql .=
" c.poste, c.phone, c.phone_perso, c.phone_mobile, c.fax, c.email,";
1009 $sql .=
" c.socialnetworks,";
1010 $sql .=
" c.photo,";
1011 $sql .=
" c.priv, c.note_private, c.note_public, c.default_lang, c.canvas,";
1012 $sql .=
" c.fk_prospectlevel, c.fk_stcommcontact, st.libelle as stcomm, st.picto as stcomm_picto,";
1013 $sql .=
" c.import_key,";
1014 $sql .=
" c.datec as date_creation, c.tms as date_modification,";
1015 $sql .=
" co.label as country, co.code as country_code,";
1016 $sql .=
" d.nom as state, d.code_departement as state_code,";
1017 $sql .=
" u.rowid as user_id, u.login as user_login,";
1018 $sql .=
" s.nom as socname, s.address as socaddress, s.zip as soccp, s.town as soccity, s.default_lang as socdefault_lang";
1019 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as c";
1020 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as co ON c.fk_pays = co.rowid";
1021 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_departements as d ON c.fk_departement = d.rowid";
1022 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u ON c.rowid = u.fk_socpeople";
1023 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON c.fk_soc = s.rowid";
1024 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_stcommcontact as st ON c.fk_stcommcontact = st.id';
1026 $sql .=
" WHERE c.rowid = ".((int) $id);
1028 $sql .=
" WHERE c.entity IN (".getEntity($this->element).
")";
1030 $sql .=
" AND c.ref_ext = '".$this->db->escape($ref_ext).
"'";
1033 $sql .=
" AND c.email = '".$this->db->escape($email).
"'";
1037 $resql = $this->db->query(
$sql);
1039 $num = $this->db->num_rows($resql);
1041 $this->error =
'Fetch found several records. Rename one of contact to avoid duplicate.';
1046 $obj = $this->db->fetch_object($resql);
1048 $this->
id = $obj->rowid;
1049 $this->entity = $obj->entity;
1050 $this->
ref = $obj->rowid;
1051 $this->ref_ext = $obj->ref_ext;
1053 $this->civility_code = $obj->civility_code;
1054 $this->civility = $obj->civility_code ? ($langs->trans(
"Civility".$obj->civility_code) != (
"Civility".$obj->civility_code) ? $langs->trans(
"Civility".$obj->civility_code) : $obj->civility_code) :
'';
1056 $this->lastname = $obj->lastname;
1057 $this->firstname = $obj->firstname;
1058 $this->address = $obj->address;
1059 $this->zip = $obj->zip;
1060 $this->town = $obj->town;
1062 $this->date_creation = $this->db->jdate($obj->date_creation);
1063 $this->date_modification = $this->db->jdate($obj->date_modification);
1065 $this->state_id = $obj->state_id;
1066 $this->state_code = $obj->state_code;
1067 $this->state = $obj->state;
1069 $this->country_id = $obj->country_id;
1070 $this->country_code = $obj->country_id ? $obj->country_code :
'';
1071 $this->country = $obj->country_id ? ($langs->trans(
'Country'.$obj->country_code) !=
'Country'.$obj->country_code ? $langs->transnoentities(
'Country'.$obj->country_code) : $obj->country) :
'';
1073 $this->fk_soc = $obj->fk_soc;
1074 $this->socid = $obj->fk_soc;
1075 $this->socname = $obj->socname;
1076 $this->poste = $obj->poste;
1077 $this->statut = $obj->statut;
1079 $this->fk_prospectlevel = $obj->fk_prospectlevel;
1081 $transcode = $langs->trans(
'StatusProspect'.$obj->fk_stcommcontact);
1082 $libelle = ($transcode !=
'StatusProspect'.$obj->fk_stcommcontact ? $transcode : $obj->stcomm);
1083 $this->stcomm_id = $obj->fk_stcommcontact;
1084 $this->statut_commercial = $libelle;
1085 $this->stcomm_picto = $obj->stcomm_picto;
1087 $this->phone_pro = trim($obj->phone);
1088 $this->fax = trim($obj->fax);
1089 $this->phone_perso = trim($obj->phone_perso);
1090 $this->phone_mobile = trim($obj->phone_mobile);
1092 $this->email = $obj->email;
1093 $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks,
true) : array());
1094 $this->photo = $obj->photo;
1095 $this->priv = $obj->priv;
1096 $this->mail = $obj->email;
1098 $this->birthday = $this->db->jdate($obj->birthday);
1099 $this->note = $obj->note_private;
1100 $this->note_private = $obj->note_private;
1101 $this->note_public = $obj->note_public;
1102 $this->default_lang = $obj->default_lang;
1103 $this->user_id = $obj->user_id;
1104 $this->user_login = $obj->user_login;
1105 $this->canvas = $obj->canvas;
1107 $this->import_key = $obj->import_key;
1113 $sql =
"SELECT u.rowid ";
1114 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
1115 $sql .=
" WHERE u.fk_socpeople = ".((int) $this->
id);
1117 $resql = $this->db->query(
$sql);
1119 if ($this->db->num_rows($resql)) {
1120 $uobj = $this->db->fetch_object($resql);
1122 $this->user_id = $uobj->rowid;
1124 $this->db->free($resql);
1126 $this->error = $this->db->error();
1136 $sql =
"SELECT fk_user";
1137 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user_alert";
1138 $sql .=
" WHERE fk_user = ".((int) $user->id).
" AND fk_contact = ".((int) $id);
1140 $resql = $this->db->query(
$sql);
1142 if ($this->db->num_rows($resql)) {
1143 $obj = $this->db->fetch_object($resql);
1145 $this->birthday_alert = 1;
1147 $this->db->free($resql);
1149 $this->error = $this->db->error();
1155 if ($loadalsoroles) {
1157 if ($resultRole < 0) {
1164 $this->error = $langs->trans(
"RecordNotFound");
1168 $this->error = $this->db->error();
1183 unset($this->gender);
1185 if (in_array($this->civility_id, array(
'MR')) || in_array($this->civility_code, array(
'MR'))) {
1186 $this->gender =
'man';
1187 } elseif (in_array($this->civility_id, array(
'MME',
'MLE')) || in_array($this->civility_code, array(
'MME',
'MLE'))) {
1188 $this->gender =
'woman';
1206 $sql =
"SELECT tc.element, count(ec.rowid) as nb";
1207 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_contact as ec, ".MAIN_DB_PREFIX.
"c_type_contact as tc";
1208 $sql .=
" WHERE ec.fk_c_type_contact = tc.rowid";
1209 $sql .=
" AND fk_socpeople = ".((int) $this->
id);
1210 $sql .=
" AND tc.source = 'external'";
1211 $sql .=
" GROUP BY tc.element";
1213 dol_syslog(get_class($this).
"::load_ref_elements", LOG_DEBUG);
1215 $resql = $this->db->query(
$sql);
1217 while ($obj = $this->db->fetch_object($resql)) {
1219 if ($obj->element ==
'facture') {
1220 $this->ref_facturation = $obj->nb;
1221 } elseif ($obj->element ==
'contrat') {
1222 $this->ref_contrat = $obj->nb;
1223 } elseif ($obj->element ==
'commande') {
1224 $this->ref_commande = $obj->nb;
1225 } elseif ($obj->element ==
'propal') {
1226 $this->ref_propal = $obj->nb;
1230 $this->db->free($resql);
1233 $this->error = $this->db->lasterror();
1245 public function delete($notrigger = 0)
1247 global $conf, $langs, $user;
1253 if (!$error && !$notrigger) {
1255 $result = $this->
call_trigger(
'CONTACT_DELETE', $user);
1264 $sql =
"SELECT ec.rowid";
1265 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_contact ec,";
1266 $sql .=
" ".MAIN_DB_PREFIX.
"c_type_contact tc";
1267 $sql .=
" WHERE ec.fk_socpeople=".((int) $this->
id);
1268 $sql .=
" AND ec.fk_c_type_contact=tc.rowid";
1269 $sql .=
" AND tc.source='external'";
1271 $resql = $this->db->query(
$sql);
1273 $num = $this->db->num_rows($resql);
1276 while ($i < $num && !$error) {
1277 $obj = $this->db->fetch_object($resql);
1279 $sqldel =
"DELETE FROM ".MAIN_DB_PREFIX.
"element_contact";
1280 $sqldel .=
" WHERE rowid = ".((int) $obj->rowid);
1282 $result = $this->db->query($sqldel);
1285 $this->error = $this->db->error().
' sql='.$sqldel;
1292 $this->error = $this->db->error().
' sql='.
$sql;
1298 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_contacts WHERE fk_socpeople = ".((int) $this->
id);
1300 $resql = $this->db->query(
$sql);
1303 $this->error .= $this->db->lasterror();
1310 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_contacts WHERE fk_socpeople = ".((int) $this->
id);
1312 $resql = $this->db->query(
$sql);
1315 $this->error .= $this->db->lasterror();
1322 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_contact WHERE fk_socpeople = ".((int) $this->
id);
1324 $resql = $this->db->query(
$sql);
1327 $this->error .= $this->db->lasterror();
1333 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"socpeople";
1334 $sql .=
" WHERE rowid = ".((int) $this->
id);
1336 $result = $this->db->query(
$sql);
1339 $this->error = $this->db->error().
' sql='.
$sql;
1353 $this->db->commit();
1356 $this->db->rollback();
1371 $sql =
"SELECT c.rowid, c.datec as datec, c.fk_user_creat,";
1372 $sql .=
" c.tms as tms, c.fk_user_modif";
1373 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as c";
1374 $sql .=
" WHERE c.rowid = ".((int) $id);
1376 $resql = $this->db->query(
$sql);
1378 if ($this->db->num_rows($resql)) {
1379 $obj = $this->db->fetch_object($resql);
1381 $this->
id = $obj->rowid;
1383 if ($obj->fk_user_creat) {
1384 $cuser =
new User($this->db);
1385 $cuser->fetch($obj->fk_user_creat);
1386 $this->user_creation = $cuser;
1389 if ($obj->fk_user_modif) {
1390 $muser =
new User($this->db);
1391 $muser->fetch($obj->fk_user_modif);
1392 $this->user_modification = $muser;
1395 $this->date_creation = $this->db->jdate($obj->datec);
1396 $this->date_modification = $this->db->jdate($obj->tms);
1399 $this->db->free($resql);
1401 print $this->db->error();
1412 $sql =
"SELECT count(mc.email) as nb";
1413 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mailing_cibles as mc, ".MAIN_DB_PREFIX.
"mailing as m";
1414 $sql .=
" WHERE mc.fk_mailing=m.rowid AND mc.email = '".$this->db->escape($this->email).
"' ";
1415 $sql .=
" AND m.entity IN (".getEntity($this->element).
") AND mc.statut NOT IN (-1,0)";
1417 $resql = $this->db->query(
$sql);
1419 $obj = $this->db->fetch_object($resql);
1422 $this->db->free($resql);
1425 $this->error = $this->db->error();
1438 global $conf, $langs, $user;
1442 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1443 return [
'optimize' => $langs->trans(
"ShowContact")];
1445 if (!empty($this->photo) && class_exists(
'Form')) {
1446 $photo =
'<div class="photointooltip floatright">';
1447 $photo .=
Form::showphoto(
'contact', $this, 0, 40, 0,
'photoref',
'mini', 0);
1449 $datas[
'photo'] = $photo;
1452 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Contact").
'</u> ' . $this->
getLibStatut(4);
1453 $datas[
'name'] =
'<br><b>'.$langs->trans(
"Name").
':</b> '.$this->
getFullName($langs);
1455 if (!empty($this->poste)) {
1456 $datas[
'job'] =
'<br><b>'.$langs->trans(
"Poste").
':</b> '.$this->poste;
1458 $datas[
'email'] =
'<br><b>'.$langs->trans(
"EMail").
':</b> '.$this->email;
1459 $phonelist = array();
1460 $country_code = empty($this->country_code) ?
'': $this->country_code;
1461 if ($this->phone_pro) {
1462 $phonelist[] =
dol_print_phone($this->phone_pro, $country_code, $this->
id, 0,
'',
' ',
'phone');
1464 if ($this->phone_mobile) {
1465 $phonelist[] =
dol_print_phone($this->phone_mobile, $country_code, $this->
id, 0,
'',
' ',
'mobile');
1467 if ($this->phone_perso) {
1468 $phonelist[] =
dol_print_phone($this->phone_perso, $country_code, $this->
id, 0,
'',
' ',
'phone');
1470 $datas[
'phonelist'] =
'<br><b>'.$langs->trans(
"Phone").
':</b> '.implode(
' ', $phonelist);
1471 $datas[
'address'] =
'<br><b>'.$langs->trans(
"Address").
':</b> '.
dol_format_address($this, 1,
' ', $langs);
1489 public function getNomUrl($withpicto = 0, $option =
'', $maxlen = 0, $moreparam =
'', $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'')
1491 global $conf, $langs, $hookmanager;
1493 if (!empty($conf->dol_no_mouse_hover)) {
1500 'objecttype' => $this->element,
1501 'option' => $option,
1503 $classfortooltip =
'classfortooltip';
1506 $classfortooltip =
'classforajaxtooltip';
1507 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1513 $url = DOL_URL_ROOT.
'/contact/card.php?id='.$this->id;
1515 if ($option !==
'nolink') {
1517 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1518 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1519 $add_save_lastsearch_values = 1;
1521 if ($url && $add_save_lastsearch_values) {
1522 $url .=
'&save_lastsearch_values=1';
1529 if (empty($notooltip)) {
1530 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1531 $label = $langs->trans(
"ShowContact");
1532 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1534 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
1535 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1537 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1540 if ($option ==
'nolink' || empty($url)) {
1541 $linkstart =
'<span';
1543 $linkstart =
'<a href="'.$url.
'"';
1545 $linkstart .= $linkclose.
'>';
1546 if ($option ==
'nolink' || empty($url)) {
1547 $linkend =
'</span>';
1552 $result .= $linkstart;
1555 if ($withpicto < 0) {
1556 $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>';
1557 if ($withpicto != 2 && $withpicto != -2) {
1561 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="pictofixedwidth"' :
'') :
'class="'.(($withpicto != 2) ?
'pictofixedwidth ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1564 if ($withpicto != 2 && $withpicto != -2) {
1568 $result .= $linkend;
1571 $hookmanager->initHooks(array(
'contactdao'));
1572 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1573 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1575 $result = $hookmanager->resPrint;
1577 $result .= $hookmanager->resPrint;
1592 $code = ($this->civility_code ? $this->civility_code : (!empty($this->civility_id) ? $this->civility : (!empty($this->civilite) ? $this->civilite :
'')));
1597 $langs->load(
"dict");
1598 return $langs->getLabelFromKey($this->db,
"Civility".$code,
"c_civility",
"code",
"label", $code);
1609 return $this->
LibStatut($this->statut, $mode);
1625 $labelStatus = array(
1626 0 =>
'ActivityCeased',
1629 5 =>
'ActivityCeased',
1631 $labelStatusShort = array(
1632 0 =>
'ActivityCeased',
1635 5 =>
'ActivityCeased',
1638 $statusType =
'status4';
1639 if ($status == 0 || $status == 5) {
1640 $statusType =
'status5';
1643 $label = $langs->transnoentitiesnoconv($labelStatus[$status]);
1644 $labelshort = $langs->transnoentitiesnoconv($labelStatusShort[$status]);
1646 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
1661 if ($status ==
'1') {
1662 return $langs->trans(
'ContactPrivate');
1664 return $langs->trans(
'ContactPublic');
1680 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe ORDER BY rowid LIMIT 1";
1681 $resql = $this->db->query(
$sql);
1683 $obj = $this->db->fetch_object($resql);
1685 $socid = $obj->rowid;
1692 $this->specimen = 1;
1693 $this->lastname =
'DOLIBARR';
1694 $this->firstname =
'SPECIMEN';
1695 $this->address =
'21 jump street';
1696 $this->zip =
'99999';
1697 $this->town =
'MyTown';
1698 $this->country_id = 1;
1699 $this->country_code =
'FR';
1700 $this->country =
'France';
1701 $this->email =
'specimen@specimen.com';
1702 $this->socialnetworks = array(
1703 'skype' =>
'tom.hanson',
1705 $this->phone_pro =
'0909090901';
1706 $this->phone_perso =
'0909090902';
1707 $this->phone_mobile =
'0909090903';
1708 $this->fax =
'0909090909';
1710 $this->note_public =
'This is a comment (public)';
1711 $this->note_private =
'This is a comment (private)';
1713 $this->socid = $socid;
1726 global $conf, $langs, $user;
1731 if ($this->statut == $status) {
1734 $this->statut = $status;
1740 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"socpeople";
1741 $sql .=
" SET statut = ".((int) $this->statut);
1742 $sql .=
", fk_user_modif = ".((int) $user->id);
1743 $sql .=
" WHERE rowid = ".((int) $this->
id);
1744 $result = $this->db->query(
$sql);
1746 dol_syslog(get_class($this).
"::setstatus", LOG_DEBUG);
1749 $result = $this->
call_trigger(
'CONTACT_ENABLEDISABLE', $user);
1757 $this->db->rollback();
1760 $this->db->commit();
1777 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1778 return parent::setCategoriesCommon($categories, Categorie::TYPE_CONTACT);
1792 'socpeople',
'societe_contacts'
1811 $sql =
"SELECT tc.rowid, tc.element, tc.source, tc.code, tc.libelle as label, sc.rowid as contactroleid, sc.fk_soc as socid";
1812 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_contacts as sc, ".MAIN_DB_PREFIX.
"c_type_contact as tc";
1813 $sql .=
" WHERE tc.rowid = sc.fk_c_type_contact";
1814 $sql .=
" AND tc.source = 'external' AND tc.active=1";
1815 $sql .=
" AND sc.fk_socpeople = ".((int) $this->
id);
1816 $sql .=
" AND sc.entity IN (".getEntity(
'societe').
')';
1818 $resql = $this->db->query(
$sql);
1820 $this->roles = array();
1822 $num = $this->db->num_rows($resql);
1824 while ($obj = $this->db->fetch_object($resql)) {
1825 $transkey =
"TypeContact_".$obj->element.
"_".$obj->source.
"_".$obj->code;
1826 $libelle_element = $langs->trans(
'ContactDefault_'.$obj->element);
1827 $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));
1832 $this->error = $this->db->lasterror();
1833 $this->errors[] = $this->db->lasterror();
1836 if (empty($error)) {
1854 if ($element ==
'action') {
1855 $element =
'agenda';
1858 $sql =
"SELECT sc.fk_socpeople as id, sc.fk_c_type_contact";
1859 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact tc";
1860 $sql .=
", ".MAIN_DB_PREFIX.
"societe_contacts sc";
1861 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"socpeople sp";
1862 $sql .=
" ON sc.fk_socpeople = sp.rowid AND sp.statut = 1";
1863 $sql .=
" WHERE sc.fk_soc =".((int) $this->socid);
1864 $sql .=
" AND sc.fk_c_type_contact=tc.rowid";
1865 $sql .=
" AND tc.element = '".$this->db->escape($element).
"'";
1866 $sql .=
" AND sp.entity IN (".getEntity(
'contact').
")";
1867 $sql .=
" AND tc.active = 1";
1870 $resql = $this->db->query(
$sql);
1872 $num = $this->db->num_rows($resql);
1875 $obj = $this->db->fetch_object($resql);
1876 $tab[] = array(
'fk_socpeople'=>$obj->id,
'type_contact'=>$obj->fk_c_type_contact);
1883 $this->error = $this->db->error();
1902 if (!isset($this->roles)) {
1908 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_contacts WHERE fk_socpeople=".((int) $this->
id).
" AND entity IN (".
getEntity(
"contact").
")";
1910 $result = $this->db->query(
$sql);
1912 $this->errors[] = $this->db->lasterror().
' sql='.
$sql;
1915 if (count($this->roles) > 0) {
1916 foreach ($this->roles as $keyRoles => $valRoles) {
1918 if (is_array($valRoles)) {
1919 $idrole = $valRoles[
'id'];
1921 $idrole = $valRoles;
1925 if (is_array($valRoles)) {
1926 $socid = $valRoles[
'socid'];
1928 $socid = $this->socid;
1932 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_contacts";
1933 $sql .=
" (entity,";
1934 $sql .=
"date_creation,";
1936 $sql .=
"fk_c_type_contact,";
1937 $sql .=
"fk_socpeople) ";
1938 $sql .=
" VALUES (".$conf->entity.
",";
1940 $sql .= $socid.
", ";
1941 $sql .= $idrole.
" , ";
1945 $result = $this->db->query(
$sql);
1947 $this->errors[] = $this->db->lasterror().
' sql='.
$sql;
1954 if (empty($error)) {
1955 $this->db->commit();
1958 $this->error = implode(
' ', $this->errors);
1959 $this->db->rollback();
1974 $sql =
"SELECT id, code, libelle as label, picto FROM ".MAIN_DB_PREFIX.
"c_stcommcontact";
1976 $sql .=
" WHERE active = ".((int) $active);
1978 $resql = $this->db->query(
$sql);
1979 $num = $this->db->num_rows($resql);
1982 $obj = $this->db->fetch_object($resql);
1983 $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);
2009 $lib = $langs->trans(
"ProspectLevel".$fk_prospectlevel);
2011 if ($lib == $langs->trans(
"ProspectLevel".$fk_prospectlevel)) {
2012 $lib = $langs->getLabelFromKey($this->db, $fk_prospectlevel,
'c_prospectlevel',
'code',
'label');
2027 return $this->
update($this->
id, $user);
2039 return $this->
libProspCommStatut($this->stcomm_id, $mode, $label, $this->stcomm_picto);
2058 $langs->load(
'customers');
2061 if ($statut ==
'-1' || $statut ==
'ST_NO') {
2062 return img_action($langs->trans(
"StatusProspect-1"), -1, $picto).
' '.$langs->trans(
"StatusProspect-1");
2063 } elseif ($statut ==
'0' || $statut ==
'ST_NEVER') {
2064 return img_action($langs->trans(
"StatusProspect0"), 0, $picto).
' '.$langs->trans(
"StatusProspect0");
2065 } elseif ($statut ==
'1' || $statut ==
'ST_TODO') {
2066 return img_action($langs->trans(
"StatusProspect1"), 1, $picto).
' '.$langs->trans(
"StatusProspect1");
2067 } elseif ($statut ==
'2' || $statut ==
'ST_PEND') {
2068 return img_action($langs->trans(
"StatusProspect2"), 2, $picto).
' '.$langs->trans(
"StatusProspect2");
2069 } elseif ($statut ==
'3' || $statut ==
'ST_DONE') {
2070 return img_action($langs->trans(
"StatusProspect3"), 3, $picto).
' '.$langs->trans(
"StatusProspect3");
2072 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);
2076 if ($statut ==
'-1' || $statut ==
'ST_NO') {
2077 return img_action($langs->trans(
"StatusProspect-1"), -1, $picto);
2078 } elseif ($statut ==
'0' || $statut ==
'ST_NEVER') {
2079 return img_action($langs->trans(
"StatusProspect0"), 0, $picto);
2080 } elseif ($statut ==
'1' || $statut ==
'ST_TODO') {
2081 return img_action($langs->trans(
"StatusProspect1"), 1, $picto);
2082 } elseif ($statut ==
'2' || $statut ==
'ST_PEND') {
2083 return img_action($langs->trans(
"StatusProspect2"), 2, $picto);
2084 } elseif ($statut ==
'3' || $statut ==
'ST_DONE') {
2085 return img_action($langs->trans(
"StatusProspect3"), 3, $picto);
2087 return img_action(($langs->trans(
"StatusProspect".$statut) !=
"StatusProspect".$statut) ? $langs->trans(
"StatusProspect".$statut) : $label, 0, $picto);
2091 if ($statut ==
'-1' || $statut ==
'ST_NO') {
2092 return img_action($langs->trans(
"StatusProspect-1"), -1, $picto).
' '.$langs->trans(
"StatusProspect-1");
2093 } elseif ($statut ==
'0' || $statut ==
'ST_NEVER') {
2094 return img_action($langs->trans(
"StatusProspect0"), 0, $picto).
' '.$langs->trans(
"StatusProspect0");
2095 } elseif ($statut ==
'1' || $statut ==
'ST_TODO') {
2096 return img_action($langs->trans(
"StatusProspect1"), 1, $picto).
' '.$langs->trans(
"StatusProspect1");
2097 } elseif ($statut ==
'2' || $statut ==
'ST_PEND') {
2098 return img_action($langs->trans(
"StatusProspect2"), 2, $picto).
' '.$langs->trans(
"StatusProspect2");
2099 } elseif ($statut ==
'3' || $statut ==
'ST_DONE') {
2100 return img_action($langs->trans(
"StatusProspect3"), 3, $picto).
' '.$langs->trans(
"StatusProspect3");
2102 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);
2106 return "Error, mode/status not found";
2125 $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).
"'";
2126 $resql = $this->db->query(
$sql);
2128 $obj = $this->db->fetch_object($resql);
2129 $noemail = $obj->nb;
2130 if (empty($noemail)) {
2131 $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()).
"')";
2132 $resql = $this->db->query(
$sql);
2135 $this->error = $this->db->lasterror();
2136 $this->errors[] = $this->error;
2141 $this->error = $this->db->lasterror();
2142 $this->errors[] = $this->error;
2145 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE email = '".$this->db->escape($this->email).
"' AND entity IN (".
getEntity(
'mailing', 0).
")";
2146 $resql = $this->db->query(
$sql);
2149 $this->error = $this->db->lasterror();
2150 $this->errors[] = $this->error;
2154 if (empty($error)) {
2155 $this->no_email = $no_email;
2156 $this->db->commit();
2159 $this->db->rollback();
2176 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE entity IN (".
getEntity(
'mailing').
") AND email = '".$this->db->escape($this->email).
"'";
2177 $resql = $this->db->query(
$sql);
2179 $obj = $this->db->fetch_object($resql);
2180 $this->no_email = $obj->nb;
2183 $this->error = $this->db->lasterror();
2184 $this->errors[] = $this->error;
2201 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
2203 $return =
'<div class="box-flex-item box-flex-grow-zero">';
2204 $return .=
'<div class="info-box info-box-sm">';
2205 $return .=
'<span class="info-box-icon bg-infobox-action">';
2207 if (property_exists($this,
'photo') && !is_null($this->photo)) {
2208 $return.=
Form::showphoto(
'contact', $this, 0, 60, 0,
'photokanban photoref photowithmargin photologintooltip',
'small', 0, 1);
2212 $return .=
'</span>';
2213 $return .=
'<div class="info-box-content">';
2214 $return .=
'<div class="info-box-ref">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(1) : $this->ref).
'</div>';
2215 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
2217 if (property_exists($this,
'thirdparty') && is_object($this->thirdparty)) {
2218 $return .=
'<div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).
'</div>';
2228 if (method_exists($this,
'getLibStatut')) {
2229 $return .=
'<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3).
'</div>';
2231 $return .=
'</div>';
2232 $return .=
'</div>';
2233 $return .=
'</div>';
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
deleteExtraFields()
Delete all extra fields values for the current object.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
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.
trait CommonPeople
Superclass for thirdparties, contacts, members or 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.
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_format_address($object, $withcountry=0, $sep="\n", $outputlangs='', $mode=0, $extralangcode='')
Return a formated address (part address/zip/town/state) according to country rules.
img_action($titlealt, $numaction, $picto='', $moreatt='')
Show logo action.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_print_phone($phone, $countrycode='', $cid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0)
Format phone numbers according to country.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
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.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
$conf db name
Only used if Module[ID]Name translation string is not found.