34 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonsocialnetworks.class.php';
48 public $element =
'contact';
53 public $table_element =
'socpeople';
59 public $ismultientitymanaged = 1;
64 public $picto =
'contact';
94 public $fields = array(
95 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10),
96 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'default'=>1,
'enabled'=>1,
'visible'=>3,
'notnull'=>1,
'position'=>30,
'index'=>1),
97 'ref_ext' =>array(
'type'=>
'varchar(255)',
'label'=>
'Ref ext',
'enabled'=>1,
'visible'=>3,
'position'=>35),
98 'civility' =>array(
'type'=>
'varchar(6)',
'label'=>
'Civility',
'enabled'=>1,
'visible'=>3,
'position'=>40),
99 'lastname' =>array(
'type'=>
'varchar(50)',
'label'=>
'Lastname',
'enabled'=>1,
'visible'=>1,
'position'=>45,
'showoncombobox'=>1,
'searchall'=>1),
100 'firstname' =>array(
'type'=>
'varchar(50)',
'label'=>
'Firstname',
'enabled'=>1,
'visible'=>1,
'position'=>50,
'showoncombobox'=>1,
'searchall'=>1),
101 'poste' =>array(
'type'=>
'varchar(80)',
'label'=>
'PostOrFunction',
'enabled'=>1,
'visible'=>-1,
'position'=>52),
102 'address' =>array(
'type'=>
'varchar(255)',
'label'=>
'Address',
'enabled'=>1,
'visible'=>-1,
'position'=>55),
103 'zip' =>array(
'type'=>
'varchar(25)',
'label'=>
'Zip',
'enabled'=>1,
'visible'=>1,
'position'=>60),
104 'town' =>array(
'type'=>
'varchar(50)',
'label'=>
'Town',
'enabled'=>1,
'visible'=>-1,
'position'=>65),
105 'fk_departement' =>array(
'type'=>
'integer',
'label'=>
'Fk departement',
'enabled'=>1,
'visible'=>3,
'position'=>70),
106 'fk_pays' =>array(
'type'=>
'integer',
'label'=>
'Fk pays',
'enabled'=>1,
'visible'=>3,
'position'=>75),
107 'fk_soc' =>array(
'type'=>
'integer',
'label'=>
'ThirdParty',
'enabled'=>1,
'visible'=>1,
'position'=>77,
'searchall'=>1),
108 'birthday' =>array(
'type'=>
'date',
'label'=>
'Birthday',
'enabled'=>1,
'visible'=>3,
'position'=>80),
109 'phone' =>array(
'type'=>
'varchar(30)',
'label'=>
'Phone',
'enabled'=>1,
'visible'=>1,
'position'=>90,
'searchall'=>1),
110 'phone_perso' =>array(
'type'=>
'varchar(30)',
'label'=>
'PhonePerso',
'enabled'=>1,
'visible'=>-1,
'position'=>95,
'searchall'=>1),
111 'phone_mobile' =>array(
'type'=>
'varchar(30)',
'label'=>
'PhoneMobile',
'enabled'=>1,
'visible'=>1,
'position'=>100,
'searchall'=>1),
112 'fax' =>array(
'type'=>
'varchar(30)',
'label'=>
'Fax',
'enabled'=>1,
'visible'=>-1,
'position'=>105,
'searchall'=>1),
113 'email' =>array(
'type'=>
'varchar(255)',
'label'=>
'Email',
'enabled'=>1,
'visible'=>1,
'position'=>110,
'searchall'=>1),
114 'socialnetworks' =>array(
'type'=>
'text',
'label'=>
'SocialNetworks',
'enabled'=>1,
'visible'=>3,
'position'=>115),
115 'photo' =>array(
'type'=>
'varchar(255)',
'label'=>
'Photo',
'enabled'=>1,
'visible'=>3,
'position'=>170),
116 'priv' =>array(
'type'=>
'smallint(6)',
'label'=>
'ContactVisibility',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'position'=>175),
117 'fk_stcommcontact' =>array(
'type'=>
'integer',
'label'=>
'ProspectStatus',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>220),
118 'fk_prospectlevel' =>array(
'type'=>
'varchar(12)',
'label'=>
'ProspectLevel',
'enabled'=>1,
'visible'=>-1,
'position'=>255),
119 'no_email' =>array(
'type'=>
'smallint(6)',
'label'=>
'No_Email',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>180),
120 'note_private' =>array(
'type'=>
'html',
'label'=>
'NotePrivate',
'enabled'=>1,
'visible'=>3,
'position'=>195,
'searchall'=>1),
121 'note_public' =>array(
'type'=>
'html',
'label'=>
'NotePublic',
'enabled'=>1,
'visible'=>3,
'position'=>200,
'searchall'=>1),
122 'default_lang' =>array(
'type'=>
'varchar(6)',
'label'=>
'Default lang',
'enabled'=>1,
'visible'=>3,
'position'=>205),
123 'canvas' =>array(
'type'=>
'varchar(32)',
'label'=>
'Canvas',
'enabled'=>1,
'visible'=>3,
'position'=>210),
124 'datec' =>array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-1,
'position'=>300),
125 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>305),
126 'fk_user_creat' =>array(
'type'=>
'integer',
'label'=>
'UserAuthor',
'enabled'=>1,
'visible'=>3,
'position'=>310),
127 'fk_user_modif' =>array(
'type'=>
'integer',
'label'=>
'UserModif',
'enabled'=>1,
'visible'=>3,
'position'=>315),
128 'statut' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Status',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'position'=>500),
129 'import_key' =>array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-1,
'position'=>1000),
133 public $civility_code;
144 public $egroupware_id;
149 public $birthday_alert;
242 public $socialnetworks;
297 public $phone_mobile;
311 public $default_lang;
316 public $ref_facturation;
326 public $ref_commande;
357 public $cacheprospectstatus = array();
358 public $fk_prospectlevel;
360 public $statut_commercial;
365 public $stcomm_picto;
375 global $conf, $langs;
380 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) {
381 $this->fields[
'rowid'][
'visible'] = 0;
384 $this->fields[
'no_email'][
'enabled'] = 0;
387 if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
388 $this->fields[
'fk_soc'][
'enabled'] = 0;
389 $this->fields[
'fk_soc'][
'searchall'] = 0;
392 if (!empty($conf->global->SOCIETE_DISABLE_PROSPECTS) || empty($conf->global->THIRDPARTY_ENABLE_PROSPECTION_ON_ALTERNATIVE_ADRESSES)) {
393 $this->fields[
'fk_stcommcontact'][
'enabled'] = 0;
394 $this->fields[
'fk_prospectlevel'][
'enabled'] = 0;
398 foreach ($this->fields as $key => $val) {
399 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
400 unset($this->fields[$key]);
429 global $user, $hookmanager;
434 $sql =
"SELECT count(sp.rowid) as nb";
435 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as sp";
436 if (empty($user->rights->societe->client->voir) && !$user->socid) {
437 $sql .=
", ".MAIN_DB_PREFIX.
"societe as s";
438 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
439 $sql .=
" WHERE sp.fk_soc = s.rowid AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
442 $sql .=
" ".$clause.
" sp.entity IN (".
getEntity($this->element).
")";
443 $sql .=
" AND (sp.priv='0' OR (sp.priv='1' AND sp.fk_user_creat = ".((int) $user->id).
"))";
444 if ($user->socid > 0) {
445 $sql .=
" AND sp.fk_soc = ".((int) $user->socid);
448 if (is_object($hookmanager)) {
449 $parameters = array();
450 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $this);
451 $sql .= $hookmanager->resPrint;
454 $resql = $this->
db->query(
$sql);
456 while ($obj = $this->
db->fetch_object($resql)) {
457 $this->nb[
"contacts"] = $obj->nb;
459 $this->
db->free($resql);
463 $this->error = $this->
db->lasterror();
476 global $conf, $langs;
484 $this->lastname = $this->lastname ?trim($this->lastname) : trim($this->
name);
485 $this->firstname = trim($this->firstname);
487 if (empty($this->socid)) {
490 if (empty($this->priv)) {
493 if (empty($this->statut)) {
497 $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity);
499 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"socpeople (";
502 $sql .=
", lastname";
503 $sql .=
", firstname";
504 $sql .=
", fk_user_creat";
506 $sql .=
", fk_stcommcontact";
511 $sql .=
", import_key";
512 $sql .=
") VALUES (";
513 $sql .=
"'".$this->db->idate($now).
"',";
514 if ($this->socid > 0) {
515 $sql .=
" ".((int) $this->socid).
",";
519 $sql .=
"'".$this->db->escape($this->lastname).
"',";
520 $sql .=
"'".$this->db->escape($this->firstname).
"',";
521 $sql .=
" ".($user->id > 0 ? ((int) $user->id) :
"null").
",";
522 $sql .=
" ".((int) $this->priv).
",";
524 $sql .=
" ".((int) $this->statut).
",";
525 $sql .=
" ".(!empty($this->canvas) ?
"'".$this->db->escape($this->canvas).
"'" :
"null").
",";
526 $sql .=
" ".((int) $this->entity).
",";
527 $sql .=
"'".$this->db->escape($this->ref_ext).
"',";
528 $sql .=
" ".(!empty($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
531 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
532 $resql = $this->
db->query(
$sql);
534 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"socpeople");
537 $result = $this->
update($this->
id, $user, 1,
'add');
540 $this->error = $this->
db->lasterror();
548 $this->error = $this->
db->lasterror();
565 $this->
db->rollback();
566 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
570 $this->error = $this->
db->lasterror();
572 $this->
db->rollback();
573 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
588 public function update($id, $user =
null, $notrigger = 0, $action =
'update', $nosyncuser = 0)
590 global $conf, $langs, $hookmanager;
596 $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity);
599 $this->ref_ext = trim($this->ref_ext);
600 $this->lastname = trim($this->lastname) ?trim($this->lastname) : trim($this->lastname);
601 $this->firstname = trim($this->firstname);
602 $this->email = trim($this->email);
603 $this->phone_pro = trim($this->phone_pro);
604 $this->phone_perso = trim($this->phone_perso);
605 $this->phone_mobile = trim($this->phone_mobile);
606 $this->photo = trim($this->photo);
607 $this->fax = trim($this->fax);
608 $this->zip = (empty($this->zip) ?
'' : trim($this->zip));
609 $this->town = (empty($this->town) ?
'' : trim($this->town));
610 $this->country_id = ($this->country_id > 0 ? $this->country_id : $this->country_id);
611 if (empty($this->statut)) {
614 if (empty($this->civility_code) && !is_numeric($this->civility_id)) {
615 $this->civility_code = $this->civility_id;
620 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"socpeople SET";
621 if ($this->socid > 0) {
622 $sql .=
" fk_soc = ".((int) $this->socid).
",";
623 } elseif ($this->socid == -1) {
624 $sql .=
" fk_soc = NULL,";
626 $sql .=
" civility='".$this->db->escape($this->civility_code).
"'";
627 $sql .=
", lastname='".$this->db->escape($this->lastname).
"'";
628 $sql .=
", firstname='".$this->db->escape($this->firstname).
"'";
629 $sql .=
", address='".$this->db->escape($this->address).
"'";
630 $sql .=
", zip='".$this->db->escape($this->zip).
"'";
631 $sql .=
", town='".$this->db->escape($this->town).
"'";
632 $sql .=
", ref_ext = ".(!empty($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"NULL");
633 $sql .=
", fk_pays=".($this->country_id > 0 ? $this->country_id :
'NULL');
634 $sql .=
", fk_departement=".($this->state_id > 0 ? $this->state_id :
'NULL');
635 $sql .=
", poste='".$this->db->escape($this->poste).
"'";
636 $sql .=
", fax='".$this->db->escape($this->fax).
"'";
637 $sql .=
", email='".$this->db->escape($this->email).
"'";
638 $sql .=
", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
639 $sql .=
", photo='".$this->db->escape($this->photo).
"'";
640 $sql .=
", birthday=".($this->birthday ?
"'".$this->db->idate($this->birthday).
"'" :
"null");
641 $sql .=
", note_private = ".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"NULL");
642 $sql .=
", note_public = ".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"NULL");
643 $sql .=
", phone = ".(isset($this->phone_pro) ?
"'".$this->db->escape($this->phone_pro).
"'" :
"NULL");
644 $sql .=
", phone_perso = ".(isset($this->phone_perso) ?
"'".$this->db->escape($this->phone_perso).
"'" :
"NULL");
645 $sql .=
", phone_mobile = ".(isset($this->phone_mobile) ?
"'".$this->db->escape($this->phone_mobile).
"'" :
"NULL");
646 $sql .=
", priv = '".$this->db->escape($this->priv).
"'";
647 $sql .=
", fk_prospectlevel = '".$this->db->escape($this->fk_prospectlevel).
"'";
648 if (isset($this->stcomm_id)) {
649 $sql .=
", fk_stcommcontact = ".($this->stcomm_id > 0 || $this->stcomm_id == -1 ? $this->stcomm_id :
"0");
651 $sql .=
", statut = ".((int) $this->statut);
652 $sql .=
", fk_user_modif=".($user->id > 0 ?
"'".$this->db->escape($user->id).
"'" :
"NULL");
653 $sql .=
", default_lang=".($this->default_lang ?
"'".$this->db->escape($this->default_lang).
"'" :
"NULL");
654 $sql .=
", entity = ".((int) $this->entity);
655 $sql .=
" WHERE rowid = ".((int) $id);
657 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
658 $result = $this->
db->query(
$sql);
660 unset($this->country_code);
661 unset($this->country);
662 unset($this->state_code);
682 if (!$error && $this->user_id > 0) {
684 $tmpobj =
new User($this->
db);
685 $tmpobj->fetch($this->user_id);
686 $usermustbemodified = 0;
687 if ($tmpobj->office_phone != $this->phone_pro) {
688 $tmpobj->office_phone = $this->phone_pro;
689 $usermustbemodified++;
691 if ($tmpobj->office_fax != $this->fax) {
692 $tmpobj->office_fax = $this->fax;
693 $usermustbemodified++;
695 if ($tmpobj->address != $this->address) {
696 $tmpobj->address = $this->address;
697 $usermustbemodified++;
699 if ($tmpobj->town != $this->town) {
700 $tmpobj->town = $this->town;
701 $usermustbemodified++;
703 if ($tmpobj->zip != $this->zip) {
704 $tmpobj->zip = $this->zip;
705 $usermustbemodified++;
707 if ($tmpobj->zip != $this->zip) {
708 $tmpobj->state_id = $this->state_id;
709 $usermustbemodified++;
711 if ($tmpobj->country_id != $this->country_id) {
712 $tmpobj->country_id = $this->country_id;
713 $usermustbemodified++;
715 if ($tmpobj->email != $this->email) {
716 $tmpobj->email = $this->email;
717 $usermustbemodified++;
719 if (!empty(array_diff($tmpobj->socialnetworks, $this->socialnetworks))) {
720 $tmpobj->socialnetworks = $this->socialnetworks;
721 $usermustbemodified++;
723 if ($usermustbemodified) {
724 $result = $tmpobj->update($user, 0, 1, 1, 1);
731 if (!$error && !$notrigger) {
744 dol_syslog(get_class($this).
"::update Error ".$this->error, LOG_ERR);
745 $this->
db->rollback();
749 $this->error = $this->
db->lasterror().
' sql='.
$sql;
750 $this->
db->rollback();
773 $dn = $conf->global->LDAP_KEY_CONTACTS.
"=".$info[$conf->global->LDAP_KEY_CONTACTS].
",".$conf->global->LDAP_CONTACT_DN;
774 } elseif ($mode == 1) {
775 $dn = $conf->global->LDAP_CONTACT_DN;
776 } elseif ($mode == 2) {
777 $dn = $conf->global->LDAP_KEY_CONTACTS.
"=".$info[$conf->global->LDAP_KEY_CONTACTS];
793 global $conf, $langs;
798 $info[
"objectclass"] = explode(
',', $conf->global->LDAP_CONTACT_OBJECT_CLASS);
803 if ($this->fullname && !empty($conf->global->LDAP_CONTACT_FIELD_FULLNAME)) {
804 $info[$conf->global->LDAP_CONTACT_FIELD_FULLNAME] = $this->fullname;
806 if ($this->lastname && !empty($conf->global->LDAP_CONTACT_FIELD_NAME)) {
807 $info[$conf->global->LDAP_CONTACT_FIELD_NAME] = $this->lastname;
809 if ($this->firstname && !empty($conf->global->LDAP_CONTACT_FIELD_FIRSTNAME)) {
810 $info[$conf->global->LDAP_CONTACT_FIELD_FIRSTNAME] = $this->firstname;
814 $info[
"title"] = $this->poste;
816 if ($this->socid > 0) {
818 $soc->fetch($this->socid);
820 $info[$conf->global->LDAP_CONTACT_FIELD_COMPANY] = $soc->name;
821 if ($soc->client == 1) {
822 $info[
"businessCategory"] =
"Customers";
824 if ($soc->client == 2) {
825 $info[
"businessCategory"] =
"Prospects";
827 if ($soc->fournisseur == 1) {
828 $info[
"businessCategory"] =
"Suppliers";
831 if ($this->address && !empty($conf->global->LDAP_CONTACT_FIELD_ADDRESS)) {
832 $info[$conf->global->LDAP_CONTACT_FIELD_ADDRESS] = $this->address;
834 if ($this->zip && !empty($conf->global->LDAP_CONTACT_FIELD_ZIP)) {
835 $info[$conf->global->LDAP_CONTACT_FIELD_ZIP] = $this->zip;
837 if ($this->town && !empty($conf->global->LDAP_CONTACT_FIELD_TOWN)) {
838 $info[$conf->global->LDAP_CONTACT_FIELD_TOWN] = $this->town;
840 if ($this->country_code && !empty($conf->global->LDAP_CONTACT_FIELD_COUNTRY)) {
841 $info[$conf->global->LDAP_CONTACT_FIELD_COUNTRY] = $this->country_code;
843 if ($this->phone_pro && !empty($conf->global->LDAP_CONTACT_FIELD_PHONE)) {
844 $info[$conf->global->LDAP_CONTACT_FIELD_PHONE] = $this->phone_pro;
846 if ($this->phone_perso && !empty($conf->global->LDAP_CONTACT_FIELD_HOMEPHONE)) {
847 $info[$conf->global->LDAP_CONTACT_FIELD_HOMEPHONE] = $this->phone_perso;
849 if ($this->phone_mobile && !empty($conf->global->LDAP_CONTACT_FIELD_MOBILE)) {
850 $info[$conf->global->LDAP_CONTACT_FIELD_MOBILE] = $this->phone_mobile;
852 if ($this->fax && !empty($conf->global->LDAP_CONTACT_FIELD_FAX)) {
853 $info[$conf->global->LDAP_CONTACT_FIELD_FAX] = $this->fax;
855 if ($this->note_private && !empty($conf->global->LDAP_CONTACT_FIELD_DESCRIPTION)) {
856 $info[$conf->global->LDAP_CONTACT_FIELD_DESCRIPTION] =
dol_string_nohtmltag($this->note_private, 2);
858 if ($this->email && !empty($conf->global->LDAP_CONTACT_FIELD_MAIL)) {
859 $info[$conf->global->LDAP_CONTACT_FIELD_MAIL] = $this->email;
862 if ($conf->global->LDAP_SERVER_TYPE ==
'egroupware') {
863 $info[
"objectclass"][4] =
"phpgwContact";
865 $info[
'uidnumber'] = $this->id;
867 $info[
'phpgwTz'] = 0;
868 $info[
'phpgwMailType'] =
'INTERNET';
869 $info[
'phpgwMailHomeType'] =
'INTERNET';
871 $info[
"phpgwContactTypeId"] =
'n';
872 $info[
"phpgwContactCatId"] = 0;
873 $info[
"phpgwContactAccess"] =
"public";
876 $this->egroupware_id = 1;
879 $info[
"phpgwContactOwner"] = $this->egroupware_id;
882 $info[
"rfc822Mailbox"] = $this->email;
884 if ($this->phone_mobile) {
885 $info[
"phpgwCellTelephoneNumber"] = $this->phone_mobile;
911 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"socpeople SET";
912 $sql .=
" birthday = ".($this->birthday ?
"'".$this->db->idate($this->birthday).
"'" :
"null");
913 $sql .=
", photo = ".($this->photo ?
"'".$this->db->escape($this->photo).
"'" :
"null");
915 $sql .=
", fk_user_modif = ".((int) $user->id);
917 $sql .=
" WHERE rowid = ".((int) $id);
919 dol_syslog(get_class($this).
"::update_perso this->birthday=".$this->birthday.
" -", LOG_DEBUG);
920 $resql = $this->
db->query(
$sql);
923 $this->error = $this->
db->lasterror();
928 if (!empty($this->birthday_alert)) {
930 $sql_check =
"SELECT rowid FROM " . MAIN_DB_PREFIX .
"user_alert WHERE type = 1 AND fk_contact = " . ((int) $id) .
" AND fk_user = " . ((int) $user->id);
931 $result_check = $this->
db->query($sql_check);
932 if (!$result_check || ($this->
db->num_rows($result_check) < 1)) {
934 $sql =
"INSERT INTO " . MAIN_DB_PREFIX .
"user_alert(type, fk_contact, fk_user) ";
935 $sql .=
"VALUES (1," . ((int) $id) .
"," . ((int) $user->id) .
")";
936 $result = $this->
db->query(
$sql);
939 $this->error = $this->
db->lasterror();
945 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"user_alert ";
946 $sql .=
"WHERE type=1 AND fk_contact=" . ((int) $id) .
" AND fk_user=" . ((int) $user->id);
947 $result = $this->
db->query(
$sql);
950 $this->error = $this->
db->lasterror();
955 if (!$error && !$notrigger) {
968 dol_syslog(get_class($this).
"::update Error ".$this->error, LOG_ERR);
969 $this->
db->rollback();
985 public function fetch($id, $user =
null, $ref_ext =
'', $email =
'', $loadalsoroles = 0)
989 dol_syslog(get_class($this).
"::fetch id=".$id.
" ref_ext=".$ref_ext.
" email=".$email, LOG_DEBUG);
991 if (empty($id) && empty($ref_ext) && empty($email)) {
992 $this->error =
'BadParameter';
996 $langs->loadLangs(array(
"dict",
"companies"));
998 $sql =
"SELECT c.rowid, c.entity, c.fk_soc, c.ref_ext, c.civility as civility_code, c.lastname, c.firstname,";
999 $sql .=
" c.address, c.statut, c.zip, c.town,";
1000 $sql .=
" c.fk_pays as country_id,";
1001 $sql .=
" c.fk_departement as state_id,";
1002 $sql .=
" c.birthday,";
1003 $sql .=
" c.poste, c.phone, c.phone_perso, c.phone_mobile, c.fax, c.email,";
1004 $sql .=
" c.socialnetworks,";
1005 $sql .=
" c.photo,";
1006 $sql .=
" c.priv, c.note_private, c.note_public, c.default_lang, c.canvas,";
1007 $sql .=
" c.fk_prospectlevel, c.fk_stcommcontact, st.libelle as stcomm, st.picto as stcomm_picto,";
1008 $sql .=
" c.import_key,";
1009 $sql .=
" c.datec as date_creation, c.tms as date_modification,";
1010 $sql .=
" co.label as country, co.code as country_code,";
1011 $sql .=
" d.nom as state, d.code_departement as state_code,";
1012 $sql .=
" u.rowid as user_id, u.login as user_login,";
1013 $sql .=
" s.nom as socname, s.address as socaddress, s.zip as soccp, s.town as soccity, s.default_lang as socdefault_lang";
1014 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as c";
1015 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as co ON c.fk_pays = co.rowid";
1016 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_departements as d ON c.fk_departement = d.rowid";
1017 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u ON c.rowid = u.fk_socpeople";
1018 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON c.fk_soc = s.rowid";
1019 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_stcommcontact as st ON c.fk_stcommcontact = st.id';
1021 $sql .=
" WHERE c.rowid = ".((int) $id);
1023 $sql .=
" WHERE c.entity IN (".getEntity($this->element).
")";
1025 $sql .=
" AND c.ref_ext = '".$this->db->escape($ref_ext).
"'";
1028 $sql .=
" AND c.email = '".$this->db->escape($email).
"'";
1032 $resql = $this->
db->query(
$sql);
1034 $num = $this->
db->num_rows($resql);
1036 $this->error =
'Fetch found several records. Rename one of contact to avoid duplicate.';
1041 $obj = $this->
db->fetch_object($resql);
1043 $this->
id = $obj->rowid;
1044 $this->entity = $obj->entity;
1045 $this->
ref = $obj->rowid;
1046 $this->ref_ext = $obj->ref_ext;
1048 $this->civility_code = $obj->civility_code;
1049 $this->civility = $obj->civility_code ? ($langs->trans(
"Civility".$obj->civility_code) != (
"Civility".$obj->civility_code) ? $langs->trans(
"Civility".$obj->civility_code) : $obj->civility_code) :
'';
1051 $this->lastname = $obj->lastname;
1052 $this->firstname = $obj->firstname;
1053 $this->address = $obj->address;
1054 $this->zip = $obj->zip;
1055 $this->town = $obj->town;
1057 $this->date_creation = $this->
db->jdate($obj->date_creation);
1058 $this->date_modification = $this->
db->jdate($obj->date_modification);
1060 $this->state_id = $obj->state_id;
1061 $this->state_code = $obj->state_code;
1062 $this->state = $obj->state;
1064 $this->country_id = $obj->country_id;
1065 $this->country_code = $obj->country_id ? $obj->country_code :
'';
1066 $this->country = $obj->country_id ? ($langs->trans(
'Country'.$obj->country_code) !=
'Country'.$obj->country_code ? $langs->transnoentities(
'Country'.$obj->country_code) : $obj->country) :
'';
1068 $this->fk_soc = $obj->fk_soc;
1069 $this->socid = $obj->fk_soc;
1070 $this->socname = $obj->socname;
1071 $this->poste = $obj->poste;
1072 $this->statut = $obj->statut;
1074 $this->fk_prospectlevel = $obj->fk_prospectlevel;
1076 $transcode = $langs->trans(
'StatusProspect'.$obj->fk_stcommcontact);
1077 $libelle = ($transcode !=
'StatusProspect'.$obj->fk_stcommcontact ? $transcode : $obj->stcomm);
1078 $this->stcomm_id = $obj->fk_stcommcontact;
1079 $this->statut_commercial = $libelle;
1080 $this->stcomm_picto = $obj->stcomm_picto;
1082 $this->phone_pro = trim($obj->phone);
1083 $this->fax = trim($obj->fax);
1084 $this->phone_perso = trim($obj->phone_perso);
1085 $this->phone_mobile = trim($obj->phone_mobile);
1087 $this->email = $obj->email;
1088 $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks,
true) : array());
1089 $this->photo = $obj->photo;
1090 $this->priv = $obj->priv;
1091 $this->mail = $obj->email;
1093 $this->birthday = $this->
db->jdate($obj->birthday);
1094 $this->note = $obj->note_private;
1095 $this->note_private = $obj->note_private;
1096 $this->note_public = $obj->note_public;
1097 $this->default_lang = $obj->default_lang;
1098 $this->user_id = $obj->user_id;
1099 $this->user_login = $obj->user_login;
1100 $this->canvas = $obj->canvas;
1102 $this->import_key = $obj->import_key;
1108 $sql =
"SELECT u.rowid ";
1109 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
1110 $sql .=
" WHERE u.fk_socpeople = ".((int) $this->
id);
1112 $resql = $this->
db->query(
$sql);
1114 if ($this->
db->num_rows($resql)) {
1115 $uobj = $this->
db->fetch_object($resql);
1117 $this->user_id = $uobj->rowid;
1119 $this->
db->free($resql);
1121 $this->error = $this->
db->error();
1131 $sql =
"SELECT fk_user";
1132 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user_alert";
1133 $sql .=
" WHERE fk_user = ".((int) $user->id).
" AND fk_contact = ".((int) $id);
1135 $resql = $this->
db->query(
$sql);
1137 if ($this->
db->num_rows($resql)) {
1138 $obj = $this->
db->fetch_object($resql);
1140 $this->birthday_alert = 1;
1142 $this->
db->free($resql);
1144 $this->error = $this->
db->error();
1150 if ($loadalsoroles) {
1152 if ($resultRole < 0) {
1159 $this->error = $langs->trans(
"RecordNotFound");
1163 $this->error = $this->
db->error();
1178 unset($this->gender);
1180 if (in_array($this->civility_id, array(
'MR')) || in_array($this->civility_code, array(
'MR'))) {
1181 $this->gender =
'man';
1182 } elseif (in_array($this->civility_id, array(
'MME',
'MLE')) || in_array($this->civility_code, array(
'MME',
'MLE'))) {
1183 $this->gender =
'woman';
1201 $sql =
"SELECT tc.element, count(ec.rowid) as nb";
1202 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_contact as ec, ".MAIN_DB_PREFIX.
"c_type_contact as tc";
1203 $sql .=
" WHERE ec.fk_c_type_contact = tc.rowid";
1204 $sql .=
" AND fk_socpeople = ".((int) $this->
id);
1205 $sql .=
" AND tc.source = 'external'";
1206 $sql .=
" GROUP BY tc.element";
1208 dol_syslog(get_class($this).
"::load_ref_elements", LOG_DEBUG);
1210 $resql = $this->
db->query(
$sql);
1212 while ($obj = $this->
db->fetch_object($resql)) {
1214 if ($obj->element ==
'facture') {
1215 $this->ref_facturation = $obj->nb;
1216 } elseif ($obj->element ==
'contrat') {
1217 $this->ref_contrat = $obj->nb;
1218 } elseif ($obj->element ==
'commande') {
1219 $this->ref_commande = $obj->nb;
1220 } elseif ($obj->element ==
'propal') {
1221 $this->ref_propal = $obj->nb;
1225 $this->
db->free($resql);
1228 $this->error = $this->
db->lasterror();
1240 public function delete($notrigger = 0)
1242 global $conf, $langs, $user;
1248 if (!$error && !$notrigger) {
1250 $result = $this->
call_trigger(
'CONTACT_DELETE', $user);
1259 $sql =
"SELECT ec.rowid";
1260 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_contact ec,";
1261 $sql .=
" ".MAIN_DB_PREFIX.
"c_type_contact tc";
1262 $sql .=
" WHERE ec.fk_socpeople=".((int) $this->
id);
1263 $sql .=
" AND ec.fk_c_type_contact=tc.rowid";
1264 $sql .=
" AND tc.source='external'";
1266 $resql = $this->
db->query(
$sql);
1268 $num = $this->
db->num_rows($resql);
1271 while ($i < $num && !$error) {
1272 $obj = $this->
db->fetch_object($resql);
1274 $sqldel =
"DELETE FROM ".MAIN_DB_PREFIX.
"element_contact";
1275 $sqldel .=
" WHERE rowid = ".((int) $obj->rowid);
1277 $result = $this->
db->query($sqldel);
1280 $this->error = $this->
db->error().
' sql='.$sqldel;
1287 $this->error = $this->
db->error().
' sql='.
$sql;
1293 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_contacts WHERE fk_socpeople = ".((int) $this->
id);
1295 $resql = $this->
db->query(
$sql);
1298 $this->error .= $this->
db->lasterror();
1305 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_contacts WHERE fk_socpeople = ".((int) $this->
id);
1307 $resql = $this->
db->query(
$sql);
1310 $this->error .= $this->
db->lasterror();
1317 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_contact WHERE fk_socpeople = ".((int) $this->
id);
1319 $resql = $this->
db->query(
$sql);
1322 $this->error .= $this->
db->lasterror();
1328 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"socpeople";
1329 $sql .=
" WHERE rowid = ".((int) $this->
id);
1331 $result = $this->
db->query(
$sql);
1334 $this->error = $this->
db->error().
' sql='.
$sql;
1348 $this->
db->commit();
1351 $this->
db->rollback();
1366 $sql =
"SELECT c.rowid, c.datec as datec, c.fk_user_creat,";
1367 $sql .=
" c.tms as tms, c.fk_user_modif";
1368 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as c";
1369 $sql .=
" WHERE c.rowid = ".((int) $id);
1371 $resql = $this->
db->query(
$sql);
1373 if ($this->
db->num_rows($resql)) {
1374 $obj = $this->
db->fetch_object($resql);
1376 $this->
id = $obj->rowid;
1378 if ($obj->fk_user_creat) {
1379 $cuser =
new User($this->
db);
1380 $cuser->fetch($obj->fk_user_creat);
1381 $this->user_creation = $cuser;
1384 if ($obj->fk_user_modif) {
1385 $muser =
new User($this->
db);
1386 $muser->fetch($obj->fk_user_modif);
1387 $this->user_modification = $muser;
1390 $this->date_creation = $this->
db->jdate($obj->datec);
1391 $this->date_modification = $this->
db->jdate($obj->tms);
1394 $this->
db->free($resql);
1396 print $this->
db->error();
1407 $sql =
"SELECT count(mc.email) as nb";
1408 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mailing_cibles as mc, ".MAIN_DB_PREFIX.
"mailing as m";
1409 $sql .=
" WHERE mc.fk_mailing=m.rowid AND mc.email = '".$this->db->escape($this->email).
"' ";
1410 $sql .=
" AND m.entity IN (".getEntity($this->element).
") AND mc.statut NOT IN (-1,0)";
1412 $resql = $this->
db->query(
$sql);
1414 $obj = $this->
db->fetch_object($resql);
1417 $this->
db->free($resql);
1420 $this->error = $this->
db->error();
1433 global $conf, $langs, $user;
1437 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1438 return [
'optimize' => $langs->trans(
"ShowContact")];
1440 if (!empty($this->photo) && class_exists(
'Form')) {
1441 $photo =
'<div class="photointooltip floatright">';
1442 $photo .=
Form::showphoto(
'contact', $this, 0, 40, 0,
'photoref',
'mini', 0);
1444 $datas[
'photo'] = $photo;
1447 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Contact").
'</u> ' . $this->
getLibStatut(4);
1448 $datas[
'name'] =
'<br><b>'.$langs->trans(
"Name").
':</b> '.$this->
getFullName($langs);
1450 if (!empty($this->poste)) {
1451 $datas[
'job'] =
'<br><b>'.$langs->trans(
"Poste").
':</b> '.$this->poste;
1453 $datas[
'email'] =
'<br><b>'.$langs->trans(
"EMail").
':</b> '.$this->email;
1454 $phonelist = array();
1455 $country_code = empty($this->country_code) ?
'': $this->country_code;
1456 if ($this->phone_pro) {
1457 $phonelist[] =
dol_print_phone($this->phone_pro, $country_code, $this->
id, 0,
'',
' ',
'phone');
1459 if ($this->phone_mobile) {
1460 $phonelist[] =
dol_print_phone($this->phone_mobile, $country_code, $this->
id, 0,
'',
' ',
'mobile');
1462 if ($this->phone_perso) {
1463 $phonelist[] =
dol_print_phone($this->phone_perso, $country_code, $this->
id, 0,
'',
' ',
'phone');
1465 $datas[
'phonelist'] =
'<br><b>'.$langs->trans(
"Phone").
':</b> '.implode(
' ', $phonelist);
1466 $datas[
'address'] =
'<br><b>'.$langs->trans(
"Address").
':</b> '.
dol_format_address($this, 1,
' ', $langs);
1484 public function getNomUrl($withpicto = 0, $option =
'', $maxlen = 0, $moreparam =
'', $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'')
1486 global $conf, $langs, $hookmanager;
1491 'objecttype' => $this->element,
1492 'option' => $option,
1494 $classfortooltip =
'classfortooltip';
1497 $classfortooltip =
'classforajaxtooltip';
1498 $dataparams =
' data-params='.json_encode($params);
1503 $url = DOL_URL_ROOT.
'/contact/card.php?id='.$this->id;
1505 if ($option !==
'nolink') {
1507 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1508 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1509 $add_save_lastsearch_values = 1;
1511 if ($add_save_lastsearch_values) {
1512 $url .=
'&save_lastsearch_values=1';
1519 if (empty($notooltip)) {
1520 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1521 $label = $langs->trans(
"ShowContact");
1522 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1524 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
1525 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1528 $linkstart =
'<a href="'.$url.
'"';
1529 $linkstart .= $linkclose.
'>';
1532 if ($option ==
'xxx') {
1533 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/contact/card.php?id='.$this->
id.$moreparam.
'"'.$dataparams.
' title="'.
dol_escape_htmltag($label, 1).
'" class="'.$classfortooltip.
'">';
1537 $result .= $linkstart;
1539 if ($withpicto < 0) {
1540 $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>';
1542 $result .=
img_object(($notooltip ?
'' : $label), ( $this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') : $dataparams.
' class="'.(($withpicto != 2) ?
'paddingright ' :
'').$classfortooltip.
'"'), 0, 0, $notooltip ? 0 : 1);
1545 if ($withpicto != 2 && $withpicto != -2) {
1548 $result .= $linkend;
1551 $hookmanager->initHooks(array(
'contactdao'));
1552 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1553 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1555 $result = $hookmanager->resPrint;
1557 $result .= $hookmanager->resPrint;
1572 $code = ($this->civility_code ? $this->civility_code : (!empty($this->civility_id) ? $this->civility : (!empty($this->civilite) ? $this->civilite :
'')));
1577 $langs->load(
"dict");
1578 return $langs->getLabelFromKey($this->
db,
"Civility".$code,
"c_civility",
"code",
"label", $code);
1589 return $this->
LibStatut($this->statut, $mode);
1605 $labelStatus = array(
1606 0 =>
'ActivityCeased',
1609 5 =>
'ActivityCeased',
1611 $labelStatusShort = array(
1612 0 =>
'ActivityCeased',
1615 5 =>
'ActivityCeased',
1618 $statusType =
'status4';
1619 if ($status == 0 || $status == 5) {
1620 $statusType =
'status5';
1623 $label = $langs->transnoentitiesnoconv($labelStatus[$status]);
1624 $labelshort = $langs->transnoentitiesnoconv($labelStatusShort[$status]);
1626 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
1641 if ($status ==
'1') {
1642 return $langs->trans(
'ContactPrivate');
1644 return $langs->trans(
'ContactPublic');
1660 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe ORDER BY rowid LIMIT 1";
1661 $resql = $this->
db->query(
$sql);
1663 $obj = $this->
db->fetch_object($resql);
1665 $socid = $obj->rowid;
1672 $this->specimen = 1;
1673 $this->lastname =
'DOLIBARR';
1674 $this->firstname =
'SPECIMEN';
1675 $this->address =
'21 jump street';
1676 $this->zip =
'99999';
1677 $this->town =
'MyTown';
1678 $this->country_id = 1;
1679 $this->country_code =
'FR';
1680 $this->country =
'France';
1681 $this->email =
'specimen@specimen.com';
1682 $this->socialnetworks = array(
1683 'skype' =>
'tom.hanson',
1685 $this->phone_pro =
'0909090901';
1686 $this->phone_perso =
'0909090902';
1687 $this->phone_mobile =
'0909090903';
1688 $this->fax =
'0909090909';
1690 $this->note_public =
'This is a comment (public)';
1691 $this->note_private =
'This is a comment (private)';
1693 $this->socid = $socid;
1706 global $conf, $langs, $user;
1711 if ($this->statut == $status) {
1714 $this->statut = $status;
1720 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"socpeople";
1721 $sql .=
" SET statut = ".((int) $this->statut);
1722 $sql .=
" WHERE rowid = ".((int) $this->
id);
1723 $result = $this->
db->query(
$sql);
1725 dol_syslog(get_class($this).
"::setstatus", LOG_DEBUG);
1728 $result = $this->
call_trigger(
'CONTACT_ENABLEDISABLE', $user);
1736 $this->
db->rollback();
1739 $this->
db->commit();
1756 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1757 return parent::setCategoriesCommon($categories, Categorie::TYPE_CONTACT);
1771 'socpeople',
'societe_contacts'
1790 $sql =
"SELECT tc.rowid, tc.element, tc.source, tc.code, tc.libelle as label, sc.rowid as contactroleid, sc.fk_soc as socid";
1791 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_contacts as sc, ".MAIN_DB_PREFIX.
"c_type_contact as tc";
1792 $sql .=
" WHERE tc.rowid = sc.fk_c_type_contact";
1793 $sql .=
" AND tc.source = 'external' AND tc.active=1";
1794 $sql .=
" AND sc.fk_socpeople = ".((int) $this->
id);
1795 $sql .=
" AND sc.entity IN (".getEntity(
'societe').
')';
1797 $resql = $this->
db->query(
$sql);
1799 $this->roles = array();
1801 $num = $this->
db->num_rows($resql);
1803 while ($obj = $this->
db->fetch_object($resql)) {
1804 $transkey =
"TypeContact_".$obj->element.
"_".$obj->source.
"_".$obj->code;
1805 $libelle_element = $langs->trans(
'ContactDefault_'.$obj->element);
1806 $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));
1811 $this->error = $this->
db->lasterror();
1812 $this->errors[] = $this->
db->lasterror();
1815 if (empty($error)) {
1833 if ($element ==
'action') {
1834 $element =
'agenda';
1837 $sql =
"SELECT sc.fk_socpeople as id, sc.fk_c_type_contact";
1838 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact tc";
1839 $sql .=
", ".MAIN_DB_PREFIX.
"societe_contacts sc";
1840 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"socpeople sp";
1841 $sql .=
" ON sc.fk_socpeople = sp.rowid AND sp.statut = 1";
1842 $sql .=
" WHERE sc.fk_soc =".((int) $this->socid);
1843 $sql .=
" AND sc.fk_c_type_contact=tc.rowid";
1844 $sql .=
" AND tc.element = '".$this->db->escape($element).
"'";
1845 $sql .=
" AND tc.active = 1";
1848 $resql = $this->
db->query(
$sql);
1850 $num = $this->
db->num_rows($resql);
1853 $obj = $this->
db->fetch_object($resql);
1854 $tab[] = array(
'fk_socpeople'=>$obj->id,
'type_contact'=>$obj->fk_c_type_contact);
1861 $this->error = $this->
db->error();
1880 if (!isset($this->roles)) {
1886 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"societe_contacts WHERE fk_socpeople=".((int) $this->
id).
" AND entity IN (".
getEntity(
"contact").
")";
1888 $result = $this->
db->query(
$sql);
1890 $this->errors[] = $this->
db->lasterror().
' sql='.
$sql;
1893 if (count($this->roles) > 0) {
1894 foreach ($this->roles as $keyRoles => $valRoles) {
1896 if (is_array($valRoles)) {
1897 $idrole = $valRoles[
'id'];
1899 $idrole = $valRoles;
1903 if (is_array($valRoles)) {
1904 $socid = $valRoles[
'socid'];
1906 $socid = $this->socid;
1910 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"societe_contacts";
1911 $sql .=
" (entity,";
1912 $sql .=
"date_creation,";
1914 $sql .=
"fk_c_type_contact,";
1915 $sql .=
"fk_socpeople) ";
1916 $sql .=
" VALUES (".$conf->entity.
",";
1918 $sql .= $socid.
", ";
1919 $sql .= $idrole.
" , ";
1923 $result = $this->
db->query(
$sql);
1925 $this->errors[] = $this->
db->lasterror().
' sql='.
$sql;
1932 if (empty($error)) {
1933 $this->
db->commit();
1936 $this->error = implode(
' ', $this->errors);
1937 $this->
db->rollback();
1952 $sql =
"SELECT id, code, libelle as label, picto FROM ".MAIN_DB_PREFIX.
"c_stcommcontact";
1954 $sql .=
" WHERE active = ".((int) $active);
1956 $resql = $this->
db->query(
$sql);
1957 $num = $this->
db->num_rows($resql);
1960 $obj = $this->
db->fetch_object($resql);
1961 $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);
1987 $lib = $langs->trans(
"ProspectLevel".$fk_prospectlevel);
1989 if ($lib == $langs->trans(
"ProspectLevel".$fk_prospectlevel)) {
1990 $lib = $langs->getLabelFromKey($this->
db, $fk_prospectlevel,
'c_prospectlevel',
'code',
'label');
2005 return $this->
update($this->
id, $user);
2017 return $this->
libProspCommStatut($this->stcomm_id, $mode, $label, $this->stcomm_picto);
2036 $langs->load(
'customers');
2039 if ($statut ==
'-1' || $statut ==
'ST_NO') {
2040 return img_action($langs->trans(
"StatusProspect-1"), -1, $picto).
' '.$langs->trans(
"StatusProspect-1");
2041 } elseif ($statut ==
'0' || $statut ==
'ST_NEVER') {
2042 return img_action($langs->trans(
"StatusProspect0"), 0, $picto).
' '.$langs->trans(
"StatusProspect0");
2043 } elseif ($statut ==
'1' || $statut ==
'ST_TODO') {
2044 return img_action($langs->trans(
"StatusProspect1"), 1, $picto).
' '.$langs->trans(
"StatusProspect1");
2045 } elseif ($statut ==
'2' || $statut ==
'ST_PEND') {
2046 return img_action($langs->trans(
"StatusProspect2"), 2, $picto).
' '.$langs->trans(
"StatusProspect2");
2047 } elseif ($statut ==
'3' || $statut ==
'ST_DONE') {
2048 return img_action($langs->trans(
"StatusProspect3"), 3, $picto).
' '.$langs->trans(
"StatusProspect3");
2050 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);
2054 if ($statut ==
'-1' || $statut ==
'ST_NO') {
2055 return img_action($langs->trans(
"StatusProspect-1"), -1, $picto);
2056 } elseif ($statut ==
'0' || $statut ==
'ST_NEVER') {
2057 return img_action($langs->trans(
"StatusProspect0"), 0, $picto);
2058 } elseif ($statut ==
'1' || $statut ==
'ST_TODO') {
2059 return img_action($langs->trans(
"StatusProspect1"), 1, $picto);
2060 } elseif ($statut ==
'2' || $statut ==
'ST_PEND') {
2061 return img_action($langs->trans(
"StatusProspect2"), 2, $picto);
2062 } elseif ($statut ==
'3' || $statut ==
'ST_DONE') {
2063 return img_action($langs->trans(
"StatusProspect3"), 3, $picto);
2065 return img_action(($langs->trans(
"StatusProspect".$statut) !=
"StatusProspect".$statut) ? $langs->trans(
"StatusProspect".$statut) : $label, 0, $picto);
2069 if ($statut ==
'-1' || $statut ==
'ST_NO') {
2070 return img_action($langs->trans(
"StatusProspect-1"), -1, $picto).
' '.$langs->trans(
"StatusProspect-1");
2071 } elseif ($statut ==
'0' || $statut ==
'ST_NEVER') {
2072 return img_action($langs->trans(
"StatusProspect0"), 0, $picto).
' '.$langs->trans(
"StatusProspect0");
2073 } elseif ($statut ==
'1' || $statut ==
'ST_TODO') {
2074 return img_action($langs->trans(
"StatusProspect1"), 1, $picto).
' '.$langs->trans(
"StatusProspect1");
2075 } elseif ($statut ==
'2' || $statut ==
'ST_PEND') {
2076 return img_action($langs->trans(
"StatusProspect2"), 2, $picto).
' '.$langs->trans(
"StatusProspect2");
2077 } elseif ($statut ==
'3' || $statut ==
'ST_DONE') {
2078 return img_action($langs->trans(
"StatusProspect3"), 3, $picto).
' '.$langs->trans(
"StatusProspect3");
2080 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);
2084 return "Error, mode/status not found";
2103 $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).
"'";
2104 $resql = $this->
db->query(
$sql);
2106 $obj = $this->
db->fetch_object($resql);
2107 $noemail = $obj->nb;
2108 if (empty($noemail)) {
2109 $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()).
"')";
2110 $resql = $this->
db->query(
$sql);
2113 $this->error = $this->
db->lasterror();
2114 $this->errors[] = $this->error;
2119 $this->error = $this->
db->lasterror();
2120 $this->errors[] = $this->error;
2123 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE email = '".$this->
db->escape($this->email).
"' AND entity IN (".
getEntity(
'mailing', 0).
")";
2124 $resql = $this->
db->query(
$sql);
2127 $this->error = $this->
db->lasterror();
2128 $this->errors[] = $this->error;
2132 if (empty($error)) {
2133 $this->no_email = $no_email;
2134 $this->
db->commit();
2137 $this->
db->rollback();
2154 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"mailing_unsubscribe WHERE entity IN (".
getEntity(
'mailing').
") AND email = '".$this->
db->escape($this->email).
"'";
2155 $resql = $this->
db->query(
$sql);
2157 $obj = $this->
db->fetch_object($resql);
2158 $this->no_email = $obj->nb;
2161 $this->error = $this->
db->lasterror();
2162 $this->errors[] = $this->error;
2181 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
2183 $return =
'<div class="box-flex-item box-flex-grow-zero">';
2184 $return .=
'<div class="info-box info-box-sm">';
2185 $return .=
'<span class="info-box-icon bg-infobox-action">';
2187 if (property_exists($this,
'photo') && !is_null($this->photo)) {
2188 $return.=
Form::showphoto(
'contact', $this, 0, 60, 0,
'photokanban photoref photowithmargin photologintooltip',
'small', 0, 1);
2192 $return .=
'</span>';
2193 $return .=
'<div class="info-box-content">';
2194 $return .=
'<div class="info-box-ref">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(1) : $this->ref).
'</div>';
2195 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
2197 if (property_exists($this,
'thirdparty') && is_object($this->thirdparty)) {
2198 $return .=
'<div class="info-box-ref opacitymedium tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).
'</div>';
2208 if (method_exists($this,
'getLibStatut')) {
2209 $return .=
'<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3).
'</div>';
2211 $return .=
'</div>';
2212 $return .=
'</div>';
2213 $return .=
'</div>';