dolibarr 19.0.3
contact.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
4 * Copyright (C) 2004-2013 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerker@telenet.be>
7 * Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
8 * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
9 * Copyright (C) 2013 Alexandre Spangaro <aspangaro@open-dsi.fr>
10 * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
11 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
12 * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
13 * Copyright (C) 2020 Open-Dsi <support@open-dsi.fr>
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 3 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program. If not, see <https://www.gnu.org/licenses/>.
27 */
28
34require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
35require_once DOL_DOCUMENT_ROOT.'/core/class/commonsocialnetworks.class.php';
36require_once DOL_DOCUMENT_ROOT.'/core/class/commonpeople.class.php';
37
38
42class Contact extends CommonObject
43{
45 use CommonPeople;
46
50 public $element = 'contact';
51
55 public $table_element = 'socpeople';
56
61 public $ismultientitymanaged = 1;
62
66 public $isextrafieldmanaged = 1;
67
71 public $picto = 'contact';
72
97 // BEGIN MODULEBUILDER PROPERTIES
101 public $fields = array(
102 'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'noteditable'=>1, 'notnull'=> 1, 'index'=>1, 'position'=>1, 'comment'=>'Id', 'css'=>'left'),
103 'entity' =>array('type'=>'integer', 'label'=>'Entity', 'default'=>1, 'enabled'=>1, 'visible'=>3, 'notnull'=>1, 'position'=>30, 'index'=>1),
104 'ref_ext' =>array('type'=>'varchar(255)', 'label'=>'Ref ext', 'enabled'=>1, 'visible'=>3, 'position'=>35),
105 'civility' =>array('type'=>'varchar(6)', 'label'=>'Civility', 'enabled'=>1, 'visible'=>3, 'position'=>40),
106 'lastname' =>array('type'=>'varchar(50)', 'label'=>'Lastname', 'enabled'=>1, 'visible'=>1, 'position'=>45, 'showoncombobox'=>1, 'searchall'=>1),
107 'firstname' =>array('type'=>'varchar(50)', 'label'=>'Firstname', 'enabled'=>1, 'visible'=>1, 'position'=>50, 'showoncombobox'=>1, 'searchall'=>1),
108 'poste' =>array('type'=>'varchar(80)', 'label'=>'PostOrFunction', 'enabled'=>1, 'visible'=>-1, 'position'=>52),
109 'address' =>array('type'=>'varchar(255)', 'label'=>'Address', 'enabled'=>1, 'visible'=>-1, 'position'=>55),
110 'zip' =>array('type'=>'varchar(25)', 'label'=>'Zip', 'enabled'=>1, 'visible'=>1, 'position'=>60),
111 'town' =>array('type'=>'varchar(50)', 'label'=>'Town', 'enabled'=>1, 'visible'=>-1, 'position'=>65),
112 'fk_departement' =>array('type'=>'integer', 'label'=>'Fk departement', 'enabled'=>1, 'visible'=>3, 'position'=>70),
113 'fk_pays' =>array('type'=>'integer', 'label'=>'Fk pays', 'enabled'=>1, 'visible'=>3, 'position'=>75),
114 'fk_soc' =>array('type'=>'integer', 'label'=>'ThirdParty', 'enabled'=>1, 'visible'=>1, 'position'=>77, 'searchall'=>1),
115 'birthday' =>array('type'=>'date', 'label'=>'Birthday', 'enabled'=>1, 'visible'=>-1, 'position'=>80),
116 'phone' =>array('type'=>'varchar(30)', 'label'=>'Phone', 'enabled'=>1, 'visible'=>1, 'position'=>90, 'searchall'=>1),
117 'phone_perso' =>array('type'=>'varchar(30)', 'label'=>'PhonePerso', 'enabled'=>1, 'visible'=>-1, 'position'=>95, 'searchall'=>1),
118 'phone_mobile' =>array('type'=>'varchar(30)', 'label'=>'PhoneMobile', 'enabled'=>1, 'visible'=>1, 'position'=>100, 'searchall'=>1),
119 'fax' =>array('type'=>'varchar(30)', 'label'=>'Fax', 'enabled'=>1, 'visible'=>-1, 'position'=>105, 'searchall'=>1),
120 'email' =>array('type'=>'varchar(255)', 'label'=>'Email', 'enabled'=>1, 'visible'=>1, 'position'=>110, 'searchall'=>1),
121 'socialnetworks' =>array('type'=>'text', 'label'=>'SocialNetworks', 'enabled'=>1, 'visible'=>3, 'position'=>115),
122 'photo' =>array('type'=>'varchar(255)', 'label'=>'Photo', 'enabled'=>1, 'visible'=>3, 'position'=>170),
123 'priv' =>array('type'=>'smallint(6)', 'label'=>'ContactVisibility', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'position'=>175),
124 'fk_stcommcontact' =>array('type'=>'integer', 'label'=>'ProspectStatus', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>220),
125 'fk_prospectcontactlevel' =>array('type'=>'varchar(12)', 'label'=>'ProspectLevel', 'enabled'=>1, 'visible'=>-1, 'position'=>255),
126 //no more used. Replace by a scan of email into mailing_unsubscribe. 'no_email' =>array('type'=>'smallint(6)', 'label'=>'No_Email', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>180),
127 'note_private' =>array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>3, 'position'=>195, 'searchall'=>1),
128 'note_public' =>array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>3, 'position'=>200, 'searchall'=>1),
129 'default_lang' =>array('type'=>'varchar(6)', 'label'=>'Default lang', 'enabled'=>1, 'visible'=>3, 'position'=>205),
130 'canvas' =>array('type'=>'varchar(32)', 'label'=>'Canvas', 'enabled'=>1, 'visible'=>3, 'position'=>210),
131 'datec' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'position'=>300),
132 'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>305),
133 'fk_user_creat' =>array('type'=>'integer', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>3, 'position'=>310),
134 'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>3, 'position'=>315),
135 'statut' =>array('type'=>'tinyint(4)', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'position'=>500),
136 'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-1, 'position'=>1000),
137 );
138
139 public $civility_id; // In fact we store civility_code
140 public $civility_code;
141 public $civility;
142
146 public $gender;
147
151 public $egroupware_id;
152
156 public $birthday_alert;
157
163 public $civilite;
164
168 public $fullname;
169
173 public $address;
174
178 public $zip;
179
183 public $town;
184
188 public $state_id;
189
193 public $state_code;
194
198 public $state;
199
203 public $poste;
204
208 public $socid; // both socid and fk_soc are used
209 public $fk_soc; // both socid and fk_soc are used
210
214 public $socname;
215
219 public $statut;
220
221 public $code;
222
227 public $email;
228
235 public $mail;
236
241 public $url;
242
248 public $no_email;
249
254 public $socialnetworks;
255
259 public $photo;
260
264 public $phone_pro;
265
269 public $phone_perso;
270
274 public $phone_mobile;
275
279 public $fax;
280
285 public $priv;
286
290 public $birthday;
291
295 public $default_lang;
296
300 public $ref_facturation;
301
305 public $ref_contrat;
306
310 public $ref_commande;
311
315 public $ref_propal;
316
320 public $user_id;
321
325 public $user_login;
326
327 // END MODULEBUILDER PROPERTIES
328
329
334 public $oldcopy; // To contains a clone of this when we need to save old properties of object
335
339 public $roles;
340
341 public $cacheprospectstatus = array();
342
346 public $fk_prospectlevel;
347
348 public $stcomm_id;
349
350 public $statut_commercial;
351
355 public $stcomm_picto;
356
357
363 public function __construct($db)
364 {
365 $this->db = $db;
366 $this->statut = 1; // By default, status is enabled
367
368 if (!isModEnabled('mailing')) {
369 $this->fields['no_email']['enabled'] = 0;
370 }
371 // typical ['s.nom'] is used for third-parties
372 if (!getDolGlobalString('SOCIETE_DISABLE_CONTACTS')) {
373 $this->fields['fk_soc']['enabled'] = 0;
374 $this->fields['fk_soc']['searchall'] = 0;
375 }
376
377 // If THIRDPARTY_ENABLE_PROSPECTION_ON_ALTERNATIVE_ADRESSES not set, there is no prospect level on contact level, only on thirdparty
378 if (getDolGlobalString('SOCIETE_DISABLE_PROSPECTS') || !getDolGlobalString('THIRDPARTY_ENABLE_PROSPECTION_ON_ALTERNATIVE_ADRESSES')) { // Default behaviour
379 $this->fields['fk_stcommcontact']['enabled'] = 0;
380 $this->fields['fk_prospectcontactlevel']['enabled'] = 0;
381 }
382
383 // Unset fields that are disabled
384 foreach ($this->fields as $key => $val) {
385 if (isset($val['enabled']) && empty($val['enabled'])) {
386 unset($this->fields[$key]);
387 }
388 }
389
390 // Translate some data of arrayofkeyval
391 /*if (is_object($langs))
392 {
393 foreach($this->fields as $key => $val)
394 {
395 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval']))
396 {
397 foreach($val['arrayofkeyval'] as $key2 => $val2)
398 {
399 $this->fields[$key]['arrayofkeyval'][$key2]=$langs->trans($val2);
400 }
401 }
402 }
403 }*/
404 }
405
406 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
412 public function load_state_board()
413 {
414 // phpcs:enable
415 global $user, $hookmanager;
416
417 $this->nb = array();
418 $clause = "WHERE";
419
420 $sql = "SELECT count(sp.rowid) as nb";
421 $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as sp";
422 if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) {
423 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
424 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
425 $sql .= " WHERE sp.fk_soc = s.rowid AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
426 $clause = "AND";
427 }
428 $sql .= " ".$clause." sp.entity IN (".getEntity($this->element).")";
429 $sql .= " AND (sp.priv='0' OR (sp.priv='1' AND sp.fk_user_creat = ".((int) $user->id)."))";
430 if ($user->socid > 0) {
431 $sql .= " AND sp.fk_soc = ".((int) $user->socid);
432 }
433 // Add where from hooks
434 if (is_object($hookmanager)) {
435 $parameters = array();
436 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $this); // Note that $action and $object may have been modified by hook
437 $sql .= $hookmanager->resPrint;
438 }
439
440 $resql = $this->db->query($sql);
441 if ($resql) {
442 while ($obj = $this->db->fetch_object($resql)) {
443 $this->nb["contacts"] = $obj->nb;
444 }
445 $this->db->free($resql);
446 return 1;
447 } else {
448 dol_print_error($this->db);
449 $this->error = $this->db->lasterror();
450 return -1;
451 }
452 }
453
461 public function create($user, $notrigger = 0)
462 {
463 global $conf;
464
465 $error = 0;
466 $now = dol_now();
467
468 $this->db->begin();
469
470 // Clean parameters
471 $this->lastname = $this->lastname ? trim($this->lastname) : trim($this->name);
472 $this->firstname = trim($this->firstname);
473 $this->setUpperOrLowerCase();
474 if (empty($this->socid)) {
475 $this->socid = 0;
476 }
477 if (empty($this->priv)) {
478 $this->priv = 0;
479 }
480 if (empty($this->statut)) {
481 $this->statut = 0; // This is to convert '' into '0' to avoid bad sql request
482 }
483
484 $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity);
485
486 $sql = "INSERT INTO ".MAIN_DB_PREFIX."socpeople (";
487 $sql .= " datec";
488 $sql .= ", fk_soc";
489 $sql .= ", lastname";
490 $sql .= ", firstname";
491 $sql .= ", fk_user_creat";
492 $sql .= ", priv";
493 $sql .= ", fk_stcommcontact";
494 $sql .= ", statut";
495 $sql .= ", canvas";
496 $sql .= ", entity";
497 $sql .= ", ref_ext";
498 $sql .= ", import_key";
499 $sql .= ") VALUES (";
500 $sql .= "'".$this->db->idate($now)."',";
501 if ($this->socid > 0) {
502 $sql .= " ".((int) $this->socid).",";
503 } else {
504 $sql .= "null,";
505 }
506 $sql .= "'".$this->db->escape($this->lastname)."',";
507 $sql .= "'".$this->db->escape($this->firstname)."',";
508 $sql .= " ".($user->id > 0 ? ((int) $user->id) : "null").",";
509 $sql .= " ".((int) $this->priv).",";
510 $sql .= " 0,";
511 $sql .= " ".((int) $this->statut).",";
512 $sql .= " ".(!empty($this->canvas) ? "'".$this->db->escape($this->canvas)."'" : "null").",";
513 $sql .= " ".((int) $this->entity).",";
514 $sql .= "'".$this->db->escape($this->ref_ext)."',";
515 $sql .= " ".(!empty($this->import_key) ? "'".$this->db->escape($this->import_key)."'" : "null");
516 $sql .= ")";
517
518 dol_syslog(get_class($this)."::create", LOG_DEBUG);
519 $resql = $this->db->query($sql);
520 if ($resql) {
521 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."socpeople");
522
523 if (!$error) {
524 $result = $this->update($this->id, $user, 1, 'add'); // This include updateRoles(), ...
525 if ($result < 0) {
526 $error++;
527 $this->error = $this->db->lasterror();
528 }
529 }
530
531 if (!$error) {
532 $result = $this->update_perso($this->id, $user, 1); // TODO Remove function update_perso, should be same than update
533 if ($result < 0) {
534 $error++;
535 $this->error = $this->db->lasterror();
536 }
537 }
538
539 if (!$error && !$notrigger) {
540 // Call trigger
541 $result = $this->call_trigger('CONTACT_CREATE', $user);
542 if ($result < 0) {
543 $error++;
544 }
545 // End call triggers
546 }
547
548 if (!$error) {
549 $this->db->commit();
550 return $this->id;
551 } else {
552 $this->db->rollback();
553 dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
554 return -2;
555 }
556 } else {
557 $this->error = $this->db->lasterror();
558
559 $this->db->rollback();
560 dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
561 return -1;
562 }
563 }
564
575 public function update($id, $user = null, $notrigger = 0, $action = 'update', $nosyncuser = 0)
576 {
577 global $conf;
578
579 $error = 0;
580
581 $this->id = $id;
582
583 $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity);
584
585 // Clean parameters
586 $this->ref_ext = trim($this->ref_ext);
587 $this->lastname = trim($this->lastname) ? trim($this->lastname) : trim($this->lastname);
588 $this->firstname = trim($this->firstname);
589 $this->email = trim($this->email);
590 $this->phone_pro = trim($this->phone_pro);
591 $this->phone_perso = trim($this->phone_perso);
592 $this->phone_mobile = trim($this->phone_mobile);
593 $this->photo = trim($this->photo);
594 $this->fax = trim($this->fax);
595 $this->zip = (empty($this->zip) ? '' : trim($this->zip));
596 $this->town = (empty($this->town) ? '' : trim($this->town));
597 $this->country_id = ($this->country_id > 0 ? $this->country_id : $this->country_id);
598 if (empty($this->statut)) {
599 $this->statut = 0;
600 }
601 if (empty($this->civility_code) && !is_numeric($this->civility_id)) {
602 $this->civility_code = $this->civility_id; // For backward compatibility
603 }
604 $this->setUpperOrLowerCase();
605
606 $this->db->begin();
607
608 $sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET";
609 if ($this->socid > 0) {
610 $sql .= " fk_soc = ".((int) $this->socid).",";
611 } elseif ($this->socid == -1) {
612 $sql .= " fk_soc = NULL,";
613 }
614 $sql .= " civility='".$this->db->escape($this->civility_code)."'";
615 $sql .= ", lastname='".$this->db->escape($this->lastname)."'";
616 $sql .= ", firstname='".$this->db->escape($this->firstname)."'";
617 $sql .= ", address='".$this->db->escape($this->address)."'";
618 $sql .= ", zip='".$this->db->escape($this->zip)."'";
619 $sql .= ", town='".$this->db->escape($this->town)."'";
620 $sql .= ", ref_ext = ".(!empty($this->ref_ext) ? "'".$this->db->escape($this->ref_ext)."'" : "NULL");
621 $sql .= ", fk_pays=".($this->country_id > 0 ? $this->country_id : 'NULL');
622 $sql .= ", fk_departement=".($this->state_id > 0 ? $this->state_id : 'NULL');
623 $sql .= ", poste='".$this->db->escape($this->poste)."'";
624 $sql .= ", fax='".$this->db->escape($this->fax)."'";
625 $sql .= ", email='".$this->db->escape($this->email)."'";
626 $sql .= ", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks))."'";
627 $sql .= ", photo='".$this->db->escape($this->photo)."'";
628 $sql .= ", birthday=".($this->birthday ? "'".$this->db->idate($this->birthday)."'" : "null");
629 $sql .= ", note_private = ".(isset($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "NULL");
630 $sql .= ", note_public = ".(isset($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : "NULL");
631 $sql .= ", phone = ".(isset($this->phone_pro) ? "'".$this->db->escape($this->phone_pro)."'" : "NULL");
632 $sql .= ", phone_perso = ".(isset($this->phone_perso) ? "'".$this->db->escape($this->phone_perso)."'" : "NULL");
633 $sql .= ", phone_mobile = ".(isset($this->phone_mobile) ? "'".$this->db->escape($this->phone_mobile)."'" : "NULL");
634 $sql .= ", priv = '".$this->db->escape($this->priv)."'";
635 $sql .= ", fk_prospectlevel = '".$this->db->escape($this->fk_prospectlevel)."'";
636 if (isset($this->stcomm_id)) {
637 $sql .= ", fk_stcommcontact = ".($this->stcomm_id > 0 || $this->stcomm_id == -1 ? $this->stcomm_id : "0");
638 }
639 $sql .= ", statut = ".((int) $this->statut);
640 $sql .= ", fk_user_modif=".($user->id > 0 ? "'".$this->db->escape($user->id)."'" : "NULL");
641 $sql .= ", default_lang=".($this->default_lang ? "'".$this->db->escape($this->default_lang)."'" : "NULL");
642 $sql .= ", entity = ".((int) $this->entity);
643 $sql .= " WHERE rowid = ".((int) $id);
644
645 dol_syslog(get_class($this)."::update", LOG_DEBUG);
646 $result = $this->db->query($sql);
647 if ($result) {
648 unset($this->country_code);
649 unset($this->country);
650 unset($this->state_code);
651 unset($this->state);
652
653 $action = 'update';
654
655 // Actions on extra fields
656 if (!$error) {
657 $result = $this->insertExtraFields();
658 if ($result < 0) {
659 $error++;
660 }
661 }
662
663 if (!$error) {
664 $result = $this->updateRoles();
665 if ($result < 0) {
666 $error++;
667 }
668 }
669
670 if (!$error && $this->user_id > 0) {
671 // If contact is linked to a user
672 $tmpobj = new User($this->db);
673 $tmpobj->fetch($this->user_id);
674 $usermustbemodified = 0;
675 if ($tmpobj->office_phone != $this->phone_pro) {
676 $tmpobj->office_phone = $this->phone_pro;
677 $usermustbemodified++;
678 }
679 if ($tmpobj->office_fax != $this->fax) {
680 $tmpobj->office_fax = $this->fax;
681 $usermustbemodified++;
682 }
683 if ($tmpobj->address != $this->address) {
684 $tmpobj->address = $this->address;
685 $usermustbemodified++;
686 }
687 if ($tmpobj->town != $this->town) {
688 $tmpobj->town = $this->town;
689 $usermustbemodified++;
690 }
691 if ($tmpobj->zip != $this->zip) {
692 $tmpobj->zip = $this->zip;
693 $usermustbemodified++;
694 }
695 if ($tmpobj->zip != $this->zip) {
696 $tmpobj->state_id = $this->state_id;
697 $usermustbemodified++;
698 }
699 if ($tmpobj->country_id != $this->country_id) {
700 $tmpobj->country_id = $this->country_id;
701 $usermustbemodified++;
702 }
703 if ($tmpobj->email != $this->email) {
704 $tmpobj->email = $this->email;
705 $usermustbemodified++;
706 }
707 if (!empty(array_diff($tmpobj->socialnetworks, $this->socialnetworks))) {
708 $tmpobj->socialnetworks = $this->socialnetworks;
709 $usermustbemodified++;
710 }
711 if ($usermustbemodified) {
712 $result = $tmpobj->update($user, 0, 1, 1, 1);
713 if ($result < 0) {
714 $error++;
715 }
716 }
717 }
718
719 if (!$error && !$notrigger) {
720 // Call trigger
721 $result = $this->call_trigger('CONTACT_MODIFY', $user);
722 if ($result < 0) {
723 $error++;
724 }
725 // End call triggers
726 }
727
728 if (!$error) {
729 $this->db->commit();
730 return 1;
731 } else {
732 dol_syslog(get_class($this)."::update Error ".$this->error, LOG_ERR);
733 $this->db->rollback();
734 return -$error;
735 }
736 } else {
737 $this->error = $this->db->lasterror().' sql='.$sql;
738 $this->db->rollback();
739 return -1;
740 }
741 }
742
743
744 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
745 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
755 public function _load_ldap_dn($info, $mode = 0)
756 {
757 // phpcs:enable
758 global $conf;
759 $dn = '';
760 if ($mode == 0) {
761 $dn = getDolGlobalString('LDAP_KEY_CONTACTS') . "=".$info[getDolGlobalString('LDAP_KEY_CONTACTS')]."," . getDolGlobalString('LDAP_CONTACT_DN');
762 } elseif ($mode == 1) {
763 $dn = $conf->global->LDAP_CONTACT_DN;
764 } elseif ($mode == 2) {
765 $dn = getDolGlobalString('LDAP_KEY_CONTACTS') . "=".$info[getDolGlobalString('LDAP_KEY_CONTACTS')];
766 }
767 return $dn;
768 }
769
770
771 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
772 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
778 public function _load_ldap_info()
779 {
780 // phpcs:enable
781 global $conf, $langs;
782
783 $info = array();
784
785 // Object classes
786 $info["objectclass"] = explode(',', getDolGlobalString('LDAP_CONTACT_OBJECT_CLASS'));
787
788 $this->fullname = $this->getFullName($langs);
789
790 // Fields
791 if ($this->fullname && getDolGlobalString('LDAP_CONTACT_FIELD_FULLNAME')) {
792 $info[getDolGlobalString('LDAP_CONTACT_FIELD_FULLNAME')] = $this->fullname;
793 }
794 if ($this->lastname && getDolGlobalString('LDAP_CONTACT_FIELD_NAME')) {
795 $info[getDolGlobalString('LDAP_CONTACT_FIELD_NAME')] = $this->lastname;
796 }
797 if ($this->firstname && getDolGlobalString('LDAP_CONTACT_FIELD_FIRSTNAME')) {
798 $info[getDolGlobalString('LDAP_CONTACT_FIELD_FIRSTNAME')] = $this->firstname;
799 }
800
801 if ($this->poste) {
802 $info["title"] = $this->poste;
803 }
804 if ($this->socid > 0) {
805 $soc = new Societe($this->db);
806 $soc->fetch($this->socid);
807
808 $info[getDolGlobalString('LDAP_CONTACT_FIELD_COMPANY')] = $soc->name;
809 if ($soc->client == 1) {
810 $info["businessCategory"] = "Customers";
811 }
812 if ($soc->client == 2) {
813 $info["businessCategory"] = "Prospects";
814 }
815 if ($soc->fournisseur == 1) {
816 $info["businessCategory"] = "Suppliers";
817 }
818 }
819 if ($this->address && getDolGlobalString('LDAP_CONTACT_FIELD_ADDRESS')) {
820 $info[getDolGlobalString('LDAP_CONTACT_FIELD_ADDRESS')] = $this->address;
821 }
822 if ($this->zip && getDolGlobalString('LDAP_CONTACT_FIELD_ZIP')) {
823 $info[getDolGlobalString('LDAP_CONTACT_FIELD_ZIP')] = $this->zip;
824 }
825 if ($this->town && getDolGlobalString('LDAP_CONTACT_FIELD_TOWN')) {
826 $info[getDolGlobalString('LDAP_CONTACT_FIELD_TOWN')] = $this->town;
827 }
828 if ($this->country_code && getDolGlobalString('LDAP_CONTACT_FIELD_COUNTRY')) {
829 $info[getDolGlobalString('LDAP_CONTACT_FIELD_COUNTRY')] = $this->country_code;
830 }
831 if ($this->phone_pro && getDolGlobalString('LDAP_CONTACT_FIELD_PHONE')) {
832 $info[getDolGlobalString('LDAP_CONTACT_FIELD_PHONE')] = $this->phone_pro;
833 }
834 if ($this->phone_perso && getDolGlobalString('LDAP_CONTACT_FIELD_HOMEPHONE')) {
835 $info[getDolGlobalString('LDAP_CONTACT_FIELD_HOMEPHONE')] = $this->phone_perso;
836 }
837 if ($this->phone_mobile && getDolGlobalString('LDAP_CONTACT_FIELD_MOBILE')) {
838 $info[getDolGlobalString('LDAP_CONTACT_FIELD_MOBILE')] = $this->phone_mobile;
839 }
840 if ($this->fax && getDolGlobalString('LDAP_CONTACT_FIELD_FAX')) {
841 $info[getDolGlobalString('LDAP_CONTACT_FIELD_FAX')] = $this->fax;
842 }
843 if ($this->note_private && getDolGlobalString('LDAP_CONTACT_FIELD_DESCRIPTION')) {
844 $info[getDolGlobalString('LDAP_CONTACT_FIELD_DESCRIPTION')] = dol_string_nohtmltag($this->note_private, 2);
845 }
846 if ($this->email && getDolGlobalString('LDAP_CONTACT_FIELD_MAIL')) {
847 $info[getDolGlobalString('LDAP_CONTACT_FIELD_MAIL')] = $this->email;
848 }
849
850 if (getDolGlobalString('LDAP_SERVER_TYPE') == 'egroupware') {
851 $info["objectclass"][4] = "phpgwContact"; // compatibilite egroupware
852
853 $info['uidnumber'] = $this->id;
854
855 $info['phpgwTz'] = 0;
856 $info['phpgwMailType'] = 'INTERNET';
857 $info['phpgwMailHomeType'] = 'INTERNET';
858
859 $info["phpgwContactTypeId"] = 'n';
860 $info["phpgwContactCatId"] = 0;
861 $info["phpgwContactAccess"] = "public";
862
863 if (dol_strlen($this->egroupware_id) == 0) {
864 $this->egroupware_id = 1;
865 }
866
867 $info["phpgwContactOwner"] = $this->egroupware_id;
868
869 if ($this->email) {
870 $info["rfc822Mailbox"] = $this->email;
871 }
872 if ($this->phone_mobile) {
873 $info["phpgwCellTelephoneNumber"] = $this->phone_mobile;
874 }
875 }
876
877 return $info;
878 }
879
880
881 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
890 public function update_perso($id, $user = null, $notrigger = 0)
891 {
892 // phpcs:enable
893 $error = 0;
894 $result = false;
895
896 $this->db->begin();
897
898 // Mis a jour contact
899 $sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET";
900 $sql .= " birthday = ".($this->birthday ? "'".$this->db->idate($this->birthday)."'" : "null");
901 $sql .= ", photo = ".($this->photo ? "'".$this->db->escape($this->photo)."'" : "null");
902 if ($user) {
903 $sql .= ", fk_user_modif = ".((int) $user->id);
904 }
905 $sql .= " WHERE rowid = ".((int) $id);
906
907 dol_syslog(get_class($this)."::update_perso this->birthday=".$this->birthday." -", LOG_DEBUG);
908 $resql = $this->db->query($sql);
909 if (!$resql) {
910 $error++;
911 $this->error = $this->db->lasterror();
912 }
913
914 if ($user) {
915 // Update birthday alert
916 if (!empty($this->birthday_alert)) {
917 //check existing
918 $sql_check = "SELECT rowid FROM " . MAIN_DB_PREFIX . "user_alert WHERE type = 1 AND fk_contact = " . ((int) $id) . " AND fk_user = " . ((int) $user->id);
919 $result_check = $this->db->query($sql_check);
920 if (!$result_check || ($this->db->num_rows($result_check) < 1)) {
921 //insert
922 $sql = "INSERT INTO " . MAIN_DB_PREFIX . "user_alert(type, fk_contact, fk_user) ";
923 $sql .= "VALUES (1," . ((int) $id) . "," . ((int) $user->id) . ")";
924 $result = $this->db->query($sql);
925 if (!$result) {
926 $error++;
927 $this->error = $this->db->lasterror();
928 }
929 } else {
930 $result = true;
931 }
932 } else {
933 $sql = "DELETE FROM " . MAIN_DB_PREFIX . "user_alert ";
934 $sql .= "WHERE type=1 AND fk_contact=" . ((int) $id) . " AND fk_user=" . ((int) $user->id);
935 $result = $this->db->query($sql);
936 if (!$result) {
937 $error++;
938 $this->error = $this->db->lasterror();
939 }
940 }
941 }
942
943 if (!$error && !$notrigger) {
944 // Call trigger
945 $result = $this->call_trigger('CONTACT_MODIFY', $user);
946 if ($result < 0) {
947 $error++;
948 }
949 // End call triggers
950 }
951
952 if (!$error) {
953 $this->db->commit();
954 return 1;
955 } else {
956 dol_syslog(get_class($this)."::update Error ".$this->error, LOG_ERR);
957 $this->db->rollback();
958 return -$error;
959 }
960 }
961
962
973 public function fetch($id, $user = null, $ref_ext = '', $email = '', $loadalsoroles = 0)
974 {
975 global $langs;
976
977 dol_syslog(get_class($this)."::fetch id=".$id." ref_ext=".$ref_ext." email=".$email, LOG_DEBUG);
978
979 if (empty($id) && empty($ref_ext) && empty($email)) {
980 $this->error = 'BadParameter';
981 return -1;
982 }
983
984 $langs->loadLangs(array("dict", "companies"));
985
986 $sql = "SELECT c.rowid, c.entity, c.fk_soc, c.ref_ext, c.civility as civility_code, c.lastname, c.firstname,";
987 $sql .= " c.address, c.statut, c.zip, c.town,";
988 $sql .= " c.fk_pays as country_id,";
989 $sql .= " c.fk_departement as state_id,";
990 $sql .= " c.birthday,";
991 $sql .= " c.poste, c.phone, c.phone_perso, c.phone_mobile, c.fax, c.email,";
992 $sql .= " c.socialnetworks,";
993 $sql .= " c.photo,";
994 $sql .= " c.priv, c.note_private, c.note_public, c.default_lang, c.canvas,";
995 $sql .= " c.fk_prospectlevel, c.fk_stcommcontact, st.libelle as stcomm, st.picto as stcomm_picto,";
996 $sql .= " c.import_key,";
997 $sql .= " c.datec as date_creation, c.tms as date_modification,";
998 $sql .= " co.label as country, co.code as country_code,";
999 $sql .= " d.nom as state, d.code_departement as state_code,";
1000 $sql .= " u.rowid as user_id, u.login as user_login,";
1001 $sql .= " s.nom as socname, s.address as socaddress, s.zip as soccp, s.town as soccity, s.default_lang as socdefault_lang";
1002 $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c";
1003 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co ON c.fk_pays = co.rowid";
1004 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as d ON c.fk_departement = d.rowid";
1005 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON c.rowid = u.fk_socpeople";
1006 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON c.fk_soc = s.rowid";
1007 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_stcommcontact as st ON c.fk_stcommcontact = st.id';
1008 if ($id) {
1009 $sql .= " WHERE c.rowid = ".((int) $id);
1010 } else {
1011 $sql .= " WHERE c.entity IN (".getEntity($this->element).")";
1012 if ($ref_ext) {
1013 $sql .= " AND c.ref_ext = '".$this->db->escape($ref_ext)."'";
1014 }
1015 if ($email) {
1016 $sql .= " AND c.email = '".$this->db->escape($email)."'";
1017 }
1018 }
1019
1020 $resql = $this->db->query($sql);
1021 if ($resql) {
1022 $num = $this->db->num_rows($resql);
1023 if ($num > 1) {
1024 $this->error = 'Fetch found several records. Rename one of contact to avoid duplicate.';
1025 dol_syslog($this->error, LOG_ERR);
1026
1027 return 2;
1028 } elseif ($num) { // $num = 1
1029 $obj = $this->db->fetch_object($resql);
1030
1031 $this->id = $obj->rowid;
1032 $this->entity = $obj->entity;
1033 $this->ref = $obj->rowid;
1034 $this->ref_ext = $obj->ref_ext;
1035
1036 $this->civility_code = $obj->civility_code;
1037 $this->civility = $obj->civility_code ? ($langs->trans("Civility".$obj->civility_code) != "Civility".$obj->civility_code ? $langs->trans("Civility".$obj->civility_code) : $obj->civility_code) : '';
1038
1039 $this->lastname = $obj->lastname;
1040 $this->firstname = $obj->firstname;
1041 $this->address = $obj->address;
1042 $this->zip = $obj->zip;
1043 $this->town = $obj->town;
1044
1045 $this->date_creation = $this->db->jdate($obj->date_creation);
1046 $this->date_modification = $this->db->jdate($obj->date_modification);
1047
1048 $this->state_id = $obj->state_id;
1049 $this->state_code = $obj->state_code;
1050 $this->state = $obj->state;
1051
1052 $this->country_id = $obj->country_id;
1053 $this->country_code = $obj->country_id ? $obj->country_code : '';
1054 $this->country = $obj->country_id ? ($langs->trans('Country'.$obj->country_code) != 'Country'.$obj->country_code ? $langs->transnoentities('Country'.$obj->country_code) : $obj->country) : '';
1055
1056 $this->fk_soc = $obj->fk_soc; // Both fk_soc and socid are used
1057 $this->socid = $obj->fk_soc; // Both fk_soc and socid are used
1058 $this->socname = $obj->socname;
1059 $this->poste = $obj->poste;
1060 $this->statut = $obj->statut;
1061
1062 $this->fk_prospectlevel = $obj->fk_prospectlevel;
1063
1064 $transcode = $langs->trans('StatusProspect'.$obj->fk_stcommcontact);
1065 $libelle = ($transcode != 'StatusProspect'.$obj->fk_stcommcontact ? $transcode : $obj->stcomm);
1066 $this->stcomm_id = $obj->fk_stcommcontact; // id statut commercial
1067 $this->statut_commercial = $libelle; // libelle statut commercial
1068 $this->stcomm_picto = $obj->stcomm_picto; // Picto statut commercial
1069
1070 $this->phone_pro = trim($obj->phone);
1071 $this->fax = trim($obj->fax);
1072 $this->phone_perso = trim($obj->phone_perso);
1073 $this->phone_mobile = trim($obj->phone_mobile);
1074
1075 $this->email = $obj->email;
1076 $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks, true) : array());
1077 $this->photo = $obj->photo;
1078 $this->priv = $obj->priv;
1079 $this->mail = $obj->email;
1080
1081 $this->birthday = $this->db->jdate($obj->birthday);
1082 $this->note = $obj->note_private; // deprecated
1083 $this->note_private = $obj->note_private;
1084 $this->note_public = $obj->note_public;
1085 $this->default_lang = $obj->default_lang;
1086 $this->user_id = $obj->user_id;
1087 $this->user_login = $obj->user_login;
1088 $this->canvas = $obj->canvas;
1089
1090 $this->import_key = $obj->import_key;
1091
1092 // Define gender according to civility
1093 $this->setGenderFromCivility();
1094
1095 // Search Dolibarr user linked to this contact
1096 $sql = "SELECT u.rowid ";
1097 $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
1098 $sql .= " WHERE u.fk_socpeople = ".((int) $this->id);
1099
1100 $resql = $this->db->query($sql);
1101 if ($resql) {
1102 if ($this->db->num_rows($resql)) {
1103 $uobj = $this->db->fetch_object($resql);
1104
1105 $this->user_id = $uobj->rowid;
1106 }
1107 $this->db->free($resql);
1108 } else {
1109 $this->error = $this->db->error();
1110 return -1;
1111 }
1112
1113 // Retrieve all extrafield
1114 // fetch optionals attributes and labels
1115 $this->fetch_optionals();
1116
1117 // Load also alerts of this user
1118 if ($user) {
1119 $sql = "SELECT fk_user";
1120 $sql .= " FROM ".MAIN_DB_PREFIX."user_alert";
1121 $sql .= " WHERE fk_user = ".((int) $user->id)." AND fk_contact = ".((int) $id);
1122
1123 $resql = $this->db->query($sql);
1124 if ($resql) {
1125 if ($this->db->num_rows($resql)) {
1126 $obj = $this->db->fetch_object($resql);
1127
1128 $this->birthday_alert = 1;
1129 }
1130 $this->db->free($resql);
1131 } else {
1132 $this->error = $this->db->error();
1133 return -1;
1134 }
1135 }
1136
1137 // Load also roles of this address
1138 if ($loadalsoroles) {
1139 $resultRole = $this->fetchRoles();
1140 if ($resultRole < 0) {
1141 return $resultRole;
1142 }
1143 }
1144
1145 return 1;
1146 } else {
1147 $this->error = $langs->trans("RecordNotFound");
1148 return 0;
1149 }
1150 } else {
1151 $this->error = $this->db->error();
1152 return -1;
1153 }
1154 }
1155
1156
1157
1164 public function setGenderFromCivility()
1165 {
1166 unset($this->gender);
1167
1168 if (in_array($this->civility_id, array('MR')) || in_array($this->civility_code, array('MR'))) {
1169 $this->gender = 'man';
1170 } elseif (in_array($this->civility_id, array('MME', 'MLE')) || in_array($this->civility_code, array('MME', 'MLE'))) {
1171 $this->gender = 'woman';
1172 }
1173 }
1174
1175 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1185 public function load_ref_elements()
1186 {
1187 // phpcs:enable
1188 // Count the elements for which it is contact
1189 $sql = "SELECT tc.element, count(ec.rowid) as nb";
1190 $sql .= " FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc";
1191 $sql .= " WHERE ec.fk_c_type_contact = tc.rowid";
1192 $sql .= " AND fk_socpeople = ".((int) $this->id);
1193 $sql .= " AND tc.source = 'external'";
1194 $sql .= " GROUP BY tc.element";
1195
1196 dol_syslog(get_class($this)."::load_ref_elements", LOG_DEBUG);
1197
1198 $resql = $this->db->query($sql);
1199 if ($resql) {
1200 while ($obj = $this->db->fetch_object($resql)) {
1201 if ($obj->nb) {
1202 if ($obj->element == 'facture') {
1203 $this->ref_facturation = $obj->nb;
1204 } elseif ($obj->element == 'contrat') {
1205 $this->ref_contrat = $obj->nb;
1206 } elseif ($obj->element == 'commande') {
1207 $this->ref_commande = $obj->nb;
1208 } elseif ($obj->element == 'propal') {
1209 $this->ref_propal = $obj->nb;
1210 }
1211 }
1212 }
1213 $this->db->free($resql);
1214 return 0;
1215 } else {
1216 $this->error = $this->db->lasterror();
1217 return -1;
1218 }
1219 }
1220
1228 public function delete($user, $notrigger = 0)
1229 {
1230 $error = 0;
1231
1232 $this->db->begin();
1233
1234 if (!$error && !$notrigger) {
1235 // Call trigger
1236 $result = $this->call_trigger('CONTACT_DELETE', $user);
1237 if ($result < 0) {
1238 $error++;
1239 }
1240 // End call triggers
1241 }
1242
1243 if (!$error) {
1244 // Get all rowid of element_contact linked to a type that is link to llx_socpeople
1245 $sql = "SELECT ec.rowid";
1246 $sql .= " FROM ".MAIN_DB_PREFIX."element_contact ec,";
1247 $sql .= " ".MAIN_DB_PREFIX."c_type_contact tc";
1248 $sql .= " WHERE ec.fk_socpeople=".((int) $this->id);
1249 $sql .= " AND ec.fk_c_type_contact=tc.rowid";
1250 $sql .= " AND tc.source='external'";
1251 dol_syslog(__METHOD__, LOG_DEBUG);
1252 $resql = $this->db->query($sql);
1253 if ($resql) {
1254 $num = $this->db->num_rows($resql);
1255
1256 $i = 0;
1257 while ($i < $num && !$error) {
1258 $obj = $this->db->fetch_object($resql);
1259
1260 $sqldel = "DELETE FROM ".MAIN_DB_PREFIX."element_contact";
1261 $sqldel .= " WHERE rowid = ".((int) $obj->rowid);
1262 dol_syslog(__METHOD__, LOG_DEBUG);
1263 $result = $this->db->query($sqldel);
1264 if (!$result) {
1265 $error++;
1266 $this->error = $this->db->error().' sql='.$sqldel;
1267 }
1268
1269 $i++;
1270 }
1271 } else {
1272 $error++;
1273 $this->error = $this->db->error().' sql='.$sql;
1274 }
1275 }
1276
1277 if (!$error) {
1278 // Remove Roles
1279 $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_contacts WHERE fk_socpeople = ".((int) $this->id);
1280 dol_syslog(__METHOD__, LOG_DEBUG);
1281 $resql = $this->db->query($sql);
1282 if (!$resql) {
1283 $error++;
1284 $this->error .= $this->db->lasterror();
1285 $errorflag = -1;
1286 }
1287 }
1288
1289 if (!$error) {
1290 // Remove category
1291 $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_contact WHERE fk_socpeople = ".((int) $this->id);
1292 dol_syslog(__METHOD__, LOG_DEBUG);
1293 $resql = $this->db->query($sql);
1294 if (!$resql) {
1295 $error++;
1296 $this->error .= $this->db->lasterror();
1297 $errorflag = -1;
1298 }
1299 }
1300
1301 if (!$error) {
1302 $sql = "DELETE FROM ".MAIN_DB_PREFIX."socpeople";
1303 $sql .= " WHERE rowid = ".((int) $this->id);
1304 dol_syslog(__METHOD__, LOG_DEBUG);
1305 $result = $this->db->query($sql);
1306 if (!$result) {
1307 $error++;
1308 $this->error = $this->db->error().' sql='.$sql;
1309 }
1310 }
1311
1312 // Remove extrafields
1313 if (!$error) {
1314 // For avoid conflicts if trigger used
1315 $result = $this->deleteExtraFields();
1316 if ($result < 0) {
1317 $error++;
1318 }
1319 }
1320
1321 if (!$error) {
1322 $this->db->commit();
1323 return 1;
1324 } else {
1325 $this->db->rollback();
1326 dol_syslog("Error ".$this->error, LOG_ERR);
1327 return -1;
1328 }
1329 }
1330
1331
1338 public function info($id)
1339 {
1340 $sql = "SELECT c.rowid, c.datec as datec, c.fk_user_creat,";
1341 $sql .= " c.tms as tms, c.fk_user_modif";
1342 $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c";
1343 $sql .= " WHERE c.rowid = ".((int) $id);
1344
1345 $resql = $this->db->query($sql);
1346 if ($resql) {
1347 if ($this->db->num_rows($resql)) {
1348 $obj = $this->db->fetch_object($resql);
1349
1350 $this->id = $obj->rowid;
1351
1352 $this->user_creation_id = $obj->fk_user_creat;
1353 $this->user_modification_id = $obj->fk_user_modif;
1354 $this->date_creation = $this->db->jdate($obj->datec);
1355 $this->date_modification = $this->db->jdate($obj->tms);
1356 }
1357
1358 $this->db->free($resql);
1359 } else {
1360 print $this->db->error();
1361 }
1362 }
1363
1369 public function getNbOfEMailings()
1370 {
1371 $sql = "SELECT count(mc.email) as nb";
1372 $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc, ".MAIN_DB_PREFIX."mailing as m";
1373 $sql .= " WHERE mc.fk_mailing=m.rowid AND mc.email = '".$this->db->escape($this->email)."' ";
1374 $sql .= " AND m.entity IN (".getEntity($this->element).") AND mc.statut NOT IN (-1,0)"; // -1 error, 0 not sent, 1 sent with success
1375
1376 $resql = $this->db->query($sql);
1377 if ($resql) {
1378 $obj = $this->db->fetch_object($resql);
1379 $nb = $obj->nb;
1380
1381 $this->db->free($resql);
1382 return $nb;
1383 } else {
1384 $this->error = $this->db->error();
1385 return -1;
1386 }
1387 }
1388
1395 public function getTooltipContentArray($params)
1396 {
1397 global $conf, $langs, $user;
1398
1399 $datas = [];
1400
1401 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
1402 return ['optimize' => $langs->trans("ShowContact")];
1403 }
1404 if (!empty($this->photo) && class_exists('Form')) {
1405 $photo = '<div class="photointooltip floatright">';
1406 $photo .= Form::showphoto('contact', $this, 0, 40, 0, 'photoref', 'mini', 0); // Important, we must force height so image will have height tags and if image is inside a tooltip, the tooltip manager can calculate height and position correctly the tooltip.
1407 $photo .= '</div>';
1408 $datas['photo'] = $photo;
1409 }
1410
1411 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Contact").'</u> ' . $this->getLibStatut(4);
1412 $datas['name'] = '<br><b>'.$langs->trans("Name").':</b> '.$this->getFullName($langs);
1413 // if ($this->civility_id) $datas['civility'] = '<br><b>' . $langs->trans("Civility") . ':</b> '.$this->civility_id; // TODO Translate civilty_id code
1414 if (!empty($this->poste)) {
1415 $datas['job'] = '<br><b>'.$langs->trans("Poste").':</b> '.$this->poste;
1416 }
1417 $datas['email'] = '<br><b>'.$langs->trans("EMail").':</b> '.$this->email;
1418 $phonelist = array();
1419 $country_code = empty($this->country_code) ? '' : $this->country_code;
1420 if ($this->phone_pro) {
1421 $phonelist[] = dol_print_phone($this->phone_pro, $country_code, $this->id, 0, '', '&nbsp;', 'phone');
1422 }
1423 if ($this->phone_mobile) {
1424 $phonelist[] = dol_print_phone($this->phone_mobile, $country_code, $this->id, 0, '', '&nbsp;', 'mobile');
1425 }
1426 if ($this->phone_perso) {
1427 $phonelist[] = dol_print_phone($this->phone_perso, $country_code, $this->id, 0, '', '&nbsp;', 'phone');
1428 }
1429 $datas['phonelist'] = '<br><b>'.$langs->trans("Phone").':</b> '.implode('&nbsp;', $phonelist);
1430 $datas['address'] = '<br><b>'.$langs->trans("Address").':</b> '.dol_format_address($this, 1, ' ', $langs);
1431
1432 return $datas;
1433 }
1434
1448 public function getNomUrl($withpicto = 0, $option = '', $maxlen = 0, $moreparam = '', $save_lastsearch_value = -1, $notooltip = 0, $morecss = '')
1449 {
1450 global $conf, $langs, $hookmanager;
1451
1452 if (!empty($conf->dol_no_mouse_hover)) {
1453 $notooltip = 1; // Force disable tooltips
1454 }
1455
1456 $result = '';
1457 $params = [
1458 'id' => $this->id,
1459 'objecttype' => $this->element,
1460 'option' => $option,
1461 ];
1462 $classfortooltip = 'classfortooltip';
1463 $dataparams = '';
1464 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
1465 $classfortooltip = 'classforajaxtooltip';
1466 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
1467 $label = '';
1468 } else {
1469 $label = implode($this->getTooltipContentArray($params));
1470 }
1471
1472 $url = DOL_URL_ROOT.'/contact/card.php?id='.$this->id;
1473
1474 if ($option !== 'nolink') {
1475 // Add param to save lastsearch_values or not
1476 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1477 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
1478 $add_save_lastsearch_values = 1;
1479 }
1480 if ($url && $add_save_lastsearch_values) {
1481 $url .= '&save_lastsearch_values=1';
1482 }
1483 }
1484
1485 $url .= $moreparam;
1486
1487 $linkclose = '';
1488 if (empty($notooltip)) {
1489 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
1490 $label = $langs->trans("ShowContact");
1491 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
1492 }
1493 $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
1494 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
1495 } else {
1496 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1497 }
1498
1499 if ($option == 'nolink' || empty($url)) {
1500 $linkstart = '<span';
1501 } else {
1502 $linkstart = '<a href="'.$url.'"';
1503 }
1504 $linkstart .= $linkclose.'>';
1505 if ($option == 'nolink' || empty($url)) {
1506 $linkend = '</span>';
1507 } else {
1508 $linkend = '</a>';
1509 }
1510
1511 $result .= $linkstart;
1512
1513 if ($withpicto) {
1514 if ($withpicto < 0) {
1515 $result .= '<!-- picto photo contact --><span class="nopadding userimg'.($morecss ? ' '.$morecss : '').'">'.Form::showphoto('contact', $this, 0, 0, 0, 'userphoto'.($withpicto == -3 ? 'small' : ''), 'mini', 0, 1).'</span>';
1516 if ($withpicto != 2 && $withpicto != -2) {
1517 $result .= ' ';
1518 }
1519 } else {
1520 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="pictofixedwidth"' : '') : 'class="'.(($withpicto != 2) ? 'pictofixedwidth ' : '').'"'), 0, 0, $notooltip ? 0 : 1);
1521 }
1522 }
1523 if ($withpicto != 2 && $withpicto != -2) {
1524 $result .= '<span class="valigmiddle">'.($maxlen ? dol_trunc($this->getFullName($langs), $maxlen) : $this->getFullName($langs)).'</span>';
1525 }
1526
1527 $result .= $linkend;
1528
1529 global $action;
1530 $hookmanager->initHooks(array('contactdao'));
1531 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
1532 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1533 if ($reshook > 0) {
1534 $result = $hookmanager->resPrint;
1535 } else {
1536 $result .= $hookmanager->resPrint;
1537 }
1538
1539 return $result;
1540 }
1541
1547 public function getCivilityLabel()
1548 {
1549 global $langs;
1550
1551 $code = ($this->civility_code ? $this->civility_code : (!empty($this->civility_id) ? $this->civility : (!empty($this->civilite) ? $this->civilite : '')));
1552 if (empty($code)) {
1553 return '';
1554 }
1555
1556 $langs->load("dict");
1557 return $langs->getLabelFromKey($this->db, "Civility".$code, "c_civility", "code", "label", $code);
1558 }
1559
1566 public function getLibStatut($mode)
1567 {
1568 return $this->LibStatut($this->statut, $mode);
1569 }
1570
1571 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1579 public function LibStatut($status, $mode)
1580 {
1581 // phpcs:enable
1582 global $langs;
1583
1584 $labelStatus = array(
1585 0 => 'ActivityCeased',
1586 1 => 'InActivity',
1587 4 => 'InActivity',
1588 5 => 'ActivityCeased',
1589 );
1590 $labelStatusShort = array(
1591 0 => 'ActivityCeased',
1592 1 => 'InActivity',
1593 4 => 'InActivity',
1594 5 => 'ActivityCeased',
1595 );
1596
1597 $statusType = 'status4';
1598 if ($status == 0 || $status == 5) {
1599 $statusType = 'status5';
1600 }
1601
1602 $label = $langs->transnoentitiesnoconv($labelStatus[$status]);
1603 $labelshort = $langs->transnoentitiesnoconv($labelStatusShort[$status]);
1604
1605 return dolGetStatus($label, $labelshort, '', $statusType, $mode);
1606 }
1607
1608
1609 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1616 public function LibPubPriv($status)
1617 {
1618 // phpcs:enable
1619 global $langs;
1620 if ($status == '1') {
1621 return $langs->trans('ContactPrivate');
1622 } else {
1623 return $langs->trans('ContactPublic');
1624 }
1625 }
1626
1627
1635 public function initAsSpecimen()
1636 {
1637 // Get first id of existing company and save it into $socid
1638 $socid = 0;
1639 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe ORDER BY rowid LIMIT 1";
1640 $resql = $this->db->query($sql);
1641 if ($resql) {
1642 $obj = $this->db->fetch_object($resql);
1643 if ($obj) {
1644 $socid = $obj->rowid;
1645 }
1646 }
1647
1648 // Initialise parameters
1649 $this->id = 0;
1650 $this->entity = 1;
1651 $this->specimen = 1;
1652 $this->lastname = 'DOLIBARR';
1653 $this->firstname = 'SPECIMEN';
1654 $this->address = '21 jump street';
1655 $this->zip = '99999';
1656 $this->town = 'MyTown';
1657 $this->country_id = 1;
1658 $this->country_code = 'FR';
1659 $this->country = 'France';
1660 $this->email = 'specimen@specimen.com';
1661 $this->socialnetworks = array(
1662 'skype' => 'tom.hanson',
1663 'twitter' => 'tomhanson',
1664 'linkedin' => 'tomhanson',
1665 );
1666 $this->phone_pro = '0909090901';
1667 $this->phone_perso = '0909090902';
1668 $this->phone_mobile = '0909090903';
1669 $this->fax = '0909090909';
1670
1671 $this->note_public = 'This is a comment (public)';
1672 $this->note_private = 'This is a comment (private)';
1673
1674 $this->socid = $socid;
1675 $this->statut = 1;
1676 return 1;
1677 }
1678
1685 public function setstatus($status)
1686 {
1687 global $conf, $langs, $user;
1688
1689 $error = 0;
1690
1691 // Check parameters
1692 if ($this->statut == $status) {
1693 return 0;
1694 } else {
1695 $this->statut = $status;
1696 }
1697
1698 $this->db->begin();
1699
1700 // User disable
1701 $sql = "UPDATE ".MAIN_DB_PREFIX."socpeople";
1702 $sql .= " SET statut = ".((int) $this->statut);
1703 $sql .= ", fk_user_modif = ".((int) $user->id);
1704 $sql .= " WHERE rowid = ".((int) $this->id);
1705 $result = $this->db->query($sql);
1706
1707 dol_syslog(get_class($this)."::setstatus", LOG_DEBUG);
1708 if ($result) {
1709 // Call trigger
1710 $result = $this->call_trigger('CONTACT_ENABLEDISABLE', $user);
1711 if ($result < 0) {
1712 $error++;
1713 }
1714 // End call triggers
1715 }
1716
1717 if ($error) {
1718 $this->db->rollback();
1719 return -$error;
1720 } else {
1721 $this->db->commit();
1722 return 1;
1723 }
1724 }
1725
1736 public function setCategories($categories)
1737 {
1738 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1739 return parent::setCategoriesCommon($categories, Categorie::TYPE_CONTACT);
1740 }
1741
1750 public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
1751 {
1752 $tables = array(
1753 'socpeople', 'societe_contacts'
1754 );
1755
1756 return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables);
1757 }
1758
1766 public function fetchRoles()
1767 {
1768 global $langs;
1769 $error = 0;
1770 $num = 0;
1771
1772 $sql = "SELECT tc.rowid, tc.element, tc.source, tc.code, tc.libelle as label, sc.rowid as contactroleid, sc.fk_soc as socid";
1773 $sql .= " FROM ".MAIN_DB_PREFIX."societe_contacts as sc, ".MAIN_DB_PREFIX."c_type_contact as tc";
1774 $sql .= " WHERE tc.rowid = sc.fk_c_type_contact";
1775 $sql .= " AND tc.source = 'external' AND tc.active=1";
1776 $sql .= " AND sc.fk_socpeople = ".((int) $this->id);
1777 $sql .= " AND sc.entity IN (".getEntity('societe').')';
1778
1779 $resql = $this->db->query($sql);
1780 if ($resql) {
1781 $this->roles = array();
1782
1783 $num = $this->db->num_rows($resql);
1784 if ($num > 0) {
1785 while ($obj = $this->db->fetch_object($resql)) {
1786 $transkey = "TypeContact_".$obj->element."_".$obj->source."_".$obj->code;
1787 $libelle_element = $langs->trans('ContactDefault_'.$obj->element);
1788 $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));
1789 }
1790 }
1791 } else {
1792 $error++;
1793 $this->error = $this->db->lasterror();
1794 $this->errors[] = $this->db->lasterror();
1795 }
1796
1797 if (empty($error)) {
1798 return $num;
1799 } else {
1800 return $error * -1;
1801 }
1802 }
1803
1811 public function getContactRoles($element = '')
1812 {
1813 $tab = array();
1814
1815 if ($element == 'action') {
1816 $element = 'agenda';
1817 }
1818
1819 $sql = "SELECT sc.fk_socpeople as id, sc.fk_c_type_contact";
1820 $sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact tc";
1821 $sql .= ", ".MAIN_DB_PREFIX."societe_contacts sc";
1822 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."socpeople sp";
1823 $sql .= " ON sc.fk_socpeople = sp.rowid AND sp.statut = 1";
1824 $sql .= " WHERE sc.fk_soc =".((int) $this->socid);
1825 $sql .= " AND sc.fk_c_type_contact=tc.rowid";
1826 $sql .= " AND tc.element = '".$this->db->escape($element)."'";
1827 $sql .= " AND sp.entity IN (".getEntity('contact').")";
1828 $sql .= " AND tc.active = 1";
1829
1830 dol_syslog(__METHOD__, LOG_DEBUG);
1831 $resql = $this->db->query($sql);
1832 if ($resql) {
1833 $num = $this->db->num_rows($resql);
1834 $i = 0;
1835 while ($i < $num) {
1836 $obj = $this->db->fetch_object($resql);
1837 $tab[] = array('fk_socpeople'=>$obj->id, 'type_contact'=>$obj->fk_c_type_contact);
1838
1839 $i++;
1840 }
1841
1842 return $tab;
1843 } else {
1844 $this->error = $this->db->error();
1845 dol_print_error($this->db);
1846 return -1;
1847 }
1848 }
1849
1857 public function updateRoles()
1858 {
1859 global $conf;
1860
1861 $error = 0;
1862
1863 if (!isset($this->roles)) {
1864 return 0; // Avoid to loose roles when property not set
1865 }
1866
1867 $this->db->begin();
1868
1869 $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_contacts WHERE fk_socpeople=".((int) $this->id)." AND entity IN (".getEntity("contact").")";
1870
1871 $result = $this->db->query($sql);
1872 if (!$result) {
1873 $this->errors[] = $this->db->lasterror().' sql='.$sql;
1874 $error++;
1875 } else {
1876 if (count($this->roles) > 0) {
1877 foreach ($this->roles as $keyRoles => $valRoles) {
1878 $idrole = 0;
1879 if (is_array($valRoles)) {
1880 $idrole = $valRoles['id'];
1881 } else {
1882 $idrole = $valRoles;
1883 }
1884
1885 $socid = 0;
1886 if (is_array($valRoles)) {
1887 $socid = $valRoles['socid'];
1888 } else {
1889 $socid = $this->socid;
1890 }
1891
1892 if ($socid > 0) {
1893 $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_contacts";
1894 $sql .= " (entity,";
1895 $sql .= "date_creation,";
1896 $sql .= "fk_soc,";
1897 $sql .= "fk_c_type_contact,";
1898 $sql .= "fk_socpeople) ";
1899 $sql .= " VALUES (".$conf->entity.",";
1900 $sql .= "'".$this->db->idate(dol_now())."',";
1901 $sql .= $socid.", ";
1902 $sql .= $idrole." , ";
1903 $sql .= $this->id;
1904 $sql .= ")";
1905
1906 $result = $this->db->query($sql);
1907 if (!$result) {
1908 $this->errors[] = $this->db->lasterror().' sql='.$sql;
1909 $error++;
1910 }
1911 }
1912 }
1913 }
1914 }
1915 if (empty($error)) {
1916 $this->db->commit();
1917 return 1;
1918 } else {
1919 $this->error = implode(' ', $this->errors);
1920 $this->db->rollback();
1921 return $error * -1;
1922 }
1923 }
1924
1931 public function loadCacheOfProspStatus($active = 1)
1932 {
1933 global $langs;
1934
1935 $sql = "SELECT id, code, libelle as label, picto FROM ".MAIN_DB_PREFIX."c_stcommcontact";
1936 if ($active >= 0) {
1937 $sql .= " WHERE active = ".((int) $active);
1938 }
1939 $resql = $this->db->query($sql);
1940 $num = $this->db->num_rows($resql);
1941 $i = 0;
1942 while ($i < $num) {
1943 $obj = $this->db->fetch_object($resql);
1944 $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);
1945 $i++;
1946 }
1947 return 1;
1948 }
1949
1955 public function getLibProspLevel()
1956 {
1957 return $this->libProspLevel($this->fk_prospectlevel);
1958 }
1959
1966 public function libProspLevel($fk_prospectlevel)
1967 {
1968 global $langs;
1969
1970 $lib = $langs->trans("ProspectLevel".$fk_prospectlevel);
1971 // If lib not found in language file, we get label from cache/database
1972 if ($lib == "ProspectLevel".$fk_prospectlevel) {
1973 $lib = $langs->getLabelFromKey($this->db, $fk_prospectlevel, 'c_prospectlevel', 'code', 'label');
1974 }
1975 return $lib;
1976 }
1977
1978
1986 public function setProspectLevel(User $user)
1987 {
1988 return $this->update($this->id, $user);
1989 }
1990
1998 public function getLibProspCommStatut($mode = 0, $label = '')
1999 {
2000 return $this->libProspCommStatut($this->stcomm_id, $mode, $label, $this->stcomm_picto);
2001 }
2002
2016 public function libProspCommStatut($statut, $mode = 0, $label = '', $picto = '')
2017 {
2018 global $langs;
2019 $langs->load('customers');
2020
2021 if ($mode == 2) {
2022 if ($statut == '-1' || $statut == 'ST_NO') {
2023 return img_action($langs->trans("StatusProspect-1"), -1, $picto).' '.$langs->trans("StatusProspect-1");
2024 } elseif ($statut == '0' || $statut == 'ST_NEVER') {
2025 return img_action($langs->trans("StatusProspect0"), 0, $picto).' '.$langs->trans("StatusProspect0");
2026 } elseif ($statut == '1' || $statut == 'ST_TODO') {
2027 return img_action($langs->trans("StatusProspect1"), 1, $picto).' '.$langs->trans("StatusProspect1");
2028 } elseif ($statut == '2' || $statut == 'ST_PEND') {
2029 return img_action($langs->trans("StatusProspect2"), 2, $picto).' '.$langs->trans("StatusProspect2");
2030 } elseif ($statut == '3' || $statut == 'ST_DONE') {
2031 return img_action($langs->trans("StatusProspect3"), 3, $picto).' '.$langs->trans("StatusProspect3");
2032 } else {
2033 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);
2034 }
2035 }
2036 if ($mode == 3) {
2037 if ($statut == '-1' || $statut == 'ST_NO') {
2038 return img_action($langs->trans("StatusProspect-1"), -1, $picto);
2039 } elseif ($statut == '0' || $statut == 'ST_NEVER') {
2040 return img_action($langs->trans("StatusProspect0"), 0, $picto);
2041 } elseif ($statut == '1' || $statut == 'ST_TODO') {
2042 return img_action($langs->trans("StatusProspect1"), 1, $picto);
2043 } elseif ($statut == '2' || $statut == 'ST_PEND') {
2044 return img_action($langs->trans("StatusProspect2"), 2, $picto);
2045 } elseif ($statut == '3' || $statut == 'ST_DONE') {
2046 return img_action($langs->trans("StatusProspect3"), 3, $picto);
2047 } else {
2048 return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0, $picto);
2049 }
2050 }
2051 if ($mode == 4) {
2052 if ($statut == '-1' || $statut == 'ST_NO') {
2053 return img_action($langs->trans("StatusProspect-1"), -1, $picto).' '.$langs->trans("StatusProspect-1");
2054 } elseif ($statut == '0' || $statut == 'ST_NEVER') {
2055 return img_action($langs->trans("StatusProspect0"), 0, $picto).' '.$langs->trans("StatusProspect0");
2056 } elseif ($statut == '1' || $statut == 'ST_TODO') {
2057 return img_action($langs->trans("StatusProspect1"), 1, $picto).' '.$langs->trans("StatusProspect1");
2058 } elseif ($statut == '2' || $statut == 'ST_PEND') {
2059 return img_action($langs->trans("StatusProspect2"), 2, $picto).' '.$langs->trans("StatusProspect2");
2060 } elseif ($statut == '3' || $statut == 'ST_DONE') {
2061 return img_action($langs->trans("StatusProspect3"), 3, $picto).' '.$langs->trans("StatusProspect3");
2062 } else {
2063 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);
2064 }
2065 }
2066
2067 return "Error, mode/status not found";
2068 }
2069
2070
2077 public function setNoEmail($no_email)
2078 {
2079 $error = 0;
2080
2081 // Update mass emailing flag into table mailing_unsubscribe
2082 if ($this->email) {
2083 $this->db->begin();
2084
2085 if ($no_email) {
2086 $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)."'";
2087 $resql = $this->db->query($sql);
2088 if ($resql) {
2089 $obj = $this->db->fetch_object($resql);
2090 $noemail = $obj->nb;
2091 if (empty($noemail)) {
2092 $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())."')";
2093 $resql = $this->db->query($sql);
2094 if (!$resql) {
2095 $error++;
2096 $this->error = $this->db->lasterror();
2097 $this->errors[] = $this->error;
2098 }
2099 }
2100 } else {
2101 $error++;
2102 $this->error = $this->db->lasterror();
2103 $this->errors[] = $this->error;
2104 }
2105 } else {
2106 $sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = '".$this->db->escape($this->email)."' AND entity IN (".getEntity('mailing', 0).")";
2107 $resql = $this->db->query($sql);
2108 if (!$resql) {
2109 $error++;
2110 $this->error = $this->db->lasterror();
2111 $this->errors[] = $this->error;
2112 }
2113 }
2114
2115 if (empty($error)) {
2116 $this->no_email = $no_email;
2117 $this->db->commit();
2118 return 1;
2119 } else {
2120 $this->db->rollback();
2121 return $error * -1;
2122 }
2123 }
2124
2125 return 0;
2126 }
2127
2134 public function getNoEmail()
2135 {
2136 if ($this->email) {
2137 $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE entity IN (".getEntity('mailing').") AND email = '".$this->db->escape($this->email)."'";
2138 $resql = $this->db->query($sql);
2139 if ($resql) {
2140 $obj = $this->db->fetch_object($resql);
2141 $this->no_email = $obj->nb;
2142 return 1;
2143 } else {
2144 $this->error = $this->db->lasterror();
2145 $this->errors[] = $this->error;
2146 return -1;
2147 }
2148 }
2149 return 0;
2150 }
2151
2152
2160 public function getKanbanView($option = '', $arraydata = null)
2161 {
2162 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
2163
2164 $return = '<div class="box-flex-item box-flex-grow-zero">';
2165 $return .= '<div class="info-box info-box-sm">';
2166 $return .= '<span class="info-box-icon bg-infobox-action">';
2167 //var_dump($this->photo);exit;
2168 if (property_exists($this, 'photo') && !is_null($this->photo)) {
2169 $return.= Form::showphoto('contact', $this, 0, 60, 0, 'photokanban photoref photowithmargin photologintooltip', 'small', 0, 1);
2170 } else {
2171 $return .= img_picto('', $this->picto);
2172 }
2173 $return .= '</span>';
2174 $return .= '<div class="info-box-content">';
2175 $return .= '<div class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl(1) : $this->ref).'</div>';
2176 if ($selected >= 0) {
2177 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
2178 }
2179 if (property_exists($this, 'thirdparty') && is_object($this->thirdparty)) {
2180 $return .= '<div class="info-box-ref tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).'</div>';
2181 }
2182 /*if (property_exists($this, 'phone_pro') && !empty($this->phone_pro)) {
2183 $return .= '<br>'.img_picto($langs->trans("Phone"), 'phone');
2184 $return .= ' <span class="info-box-label">'.$this->phone_pro.'</span>';
2185 }*/
2186 /*if (method_exists($this, 'LibPubPriv')) {
2187 $return .= '<br><span class="info-box-label opacitymedium">'.$langs->trans("Visibility").'</span>';
2188 $return .= '<span> : '.$this->LibPubPriv($this->priv).'</span>';
2189 }*/
2190 if (method_exists($this, 'getLibStatut')) {
2191 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
2192 }
2193 $return .= '</div>';
2194 $return .= '</div>';
2195 $return .= '</div>';
2196 return $return;
2197 }
2198}
$object ref
Definition info.php:79
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 contact/addresses.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
__construct($db)
Constructor.
update_perso($id, $user=null, $notrigger=0)
Update field alert birthday.
getLibProspCommStatut($mode=0, $label='')
Return status of prospect.
load_state_board()
Load indicators into this->nb for board.
create($user, $notrigger=0)
Add a contact into database.
getNomUrl($withpicto=0, $option='', $maxlen=0, $moreparam='', $save_lastsearch_value=-1, $notooltip=0, $morecss='')
Return name of contact with link (and eventually picto) Use $this->id, $this->lastname,...
getNoEmail()
get "blacklist" mailing status set no_email attribut to 1 or 0
getNbOfEMailings()
Return number of mass Emailing received by these contacts with its email.
libProspCommStatut($statut, $mode=0, $label='', $picto='')
Return label of a given status.
getTooltipContentArray($params)
getTooltipContentArray
libProspLevel($fk_prospectlevel)
Return label of prospect level.
getCivilityLabel()
Return civility label of contact.
fetch($id, $user=null, $ref_ext='', $email='', $loadalsoroles=0)
Load object contact.
setProspectLevel(User $user)
Set prospect level.
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
load_ref_elements()
Load number of elements the contact is used as a link for ref_facturation ref_contrat ref_commande (f...
getLibProspLevel()
Return prospect level.
fetchRoles()
Fetch roles (default contact of some companies) for the current contact.
getContactRoles($element='')
Get thirdparty contact roles of a given contact.
_load_ldap_dn($info, $mode=0)
Return DN string complete in the LDAP directory for the object.
LibStatut($status, $mode)
Return the label of a given status.
setGenderFromCivility()
Set the property "gender" of this class, based on the property "civility_id" or use property "civilit...
update($id, $user=null, $notrigger=0, $action='update', $nosyncuser=0)
Update informations into database.
setstatus($status)
Change status of a user.
loadCacheOfProspStatus($active=1)
Load array of prospect status.
_load_ldap_info()
Initialize info table (LDAP attributes table)
updateRoles()
Updates all roles (default contact for companies) according to values inside the ->roles array.
info($id)
Load contact information from the database.
initAsSpecimen()
Initialise an instance with random values.
getLibStatut($mode)
Return the label of the status.
setNoEmail($no_email)
Set "blacklist" mailing status.
LibPubPriv($status)
Return translated label of Public or Private.
setCategories($categories)
Sets object to supplied categories.
Class to manage Dolibarr database access.
static showphoto($modulepart, $object, $width=100, $height=0, $caneditfield=0, $cssclass='photowithmargin', $imagesize='', $addlinktofullsize=1, $cache=0, $forcecapture='', $noexternsourceoverwrite=0)
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.
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="&nbsp;", $withpicto='', $titlealt='', $adddivfloat=0)
Format phone numbers according to country.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a 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)
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e e e e e statut
Definition invoice.php:1926
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:124