dolibarr  9.0.0
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.dolibarr@gmail.com>
10  * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
11  * Copyright (C) 2015 Marcos GarcĂ­a <marcosgdf@gmail.com>
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program. If not, see <http://www.gnu.org/licenses/>.
25  */
26 
32 require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php';
33 
34 
38 class Contact extends CommonObject
39 {
43  public $element='contact';
44 
48  public $table_element='socpeople';
49 
54  public $ismultientitymanaged = 1;
55 
59  public $picto = 'contact';
60 
61 
62  // BEGIN MODULEBUILDER PROPERTIES
66  public $fields=array(
67  'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'),
68  'lastname' =>array('type'=>'varchar(128)', 'label'=>'Name', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1),
69  'firstname' =>array('type'=>'varchar(128)', 'label'=>'Firstname', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>11, 'searchall'=>1),
70  'entity' =>array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'default'=>1, 'notnull'=>1, 'index'=>1, 'position'=>20),
71  'note_public' =>array('type'=>'text', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>60),
72  'note_private' =>array('type'=>'text', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>61),
73  'datec' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>500),
74  'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>501),
75  //'date_valid' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>502),
76  'fk_user_creat' =>array('type'=>'integer', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>510),
77  'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'position'=>511),
78  //'fk_user_valid' =>array('type'=>'integer', 'label'=>'UserValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>512),
79  'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'index'=>1, 'position'=>1000),
80  );
81 
82  public $civility_id; // In fact we store civility_code
83  public $civility_code;
84  public $address;
85  public $zip;
86  public $town;
87 
102  public $departement;
103  public $state_id; // Id of department
104  public $state_code; // Code of department
105  public $state; // Label of department
106 
107  public $poste; // Position
108 
109  public $socid; // fk_soc
110  public $statut; // 0=inactif, 1=actif
111 
112  public $code;
113  public $email;
114  public $skype;
115  public $photo;
116  public $jabberid;
117  public $phone_pro;
118  public $phone_perso;
119  public $phone_mobile;
120  public $fax;
121 
122  public $priv;
123 
124  public $birthday;
125  public $default_lang;
126  public $no_email; // 1=Don't send e-mail to this contact, 0=do
127 
128  public $ref_facturation; // Reference number of invoice for which it is contact
129  public $ref_contrat; // Nb de reference contrat pour lequel il est contact
130  public $ref_commande; // Nb de reference commande pour lequel il est contact
131  public $ref_propal; // Nb de reference propal pour lequel il est contact
132 
133  public $user_id;
134  public $user_login;
135 
136  // END MODULEBUILDER PROPERTIES
137 
138 
139  public $oldcopy; // To contains a clone of this when we need to save old properties of object
140 
141 
147  function __construct($db)
148  {
149  $this->db = $db;
150  $this->statut = 1; // By default, status is enabled
151  }
152 
153  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
159  function load_state_board()
160  {
161  // phpcs:enable
162  global $user;
163 
164  $this->nb=array();
165  $clause = "WHERE";
166 
167  $sql = "SELECT count(sp.rowid) as nb";
168  $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as sp";
169  if (!$user->rights->societe->client->voir && !$user->societe_id)
170  {
171  $sql.= ", ".MAIN_DB_PREFIX."societe as s";
172  $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
173  $sql.= " WHERE sp.fk_soc = s.rowid AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
174  $clause = "AND";
175  }
176  $sql.= ' '.$clause.' sp.entity IN ('.getEntity($this->element).')';
177  $sql.= " AND (sp.priv='0' OR (sp.priv='1' AND sp.fk_user_creat=".$user->id."))";
178  if ($user->societe_id > 0) $sql.=" AND sp.fk_soc = ".$user->societe_id;
179 
180  $resql=$this->db->query($sql);
181  if ($resql)
182  {
183  while ($obj=$this->db->fetch_object($resql))
184  {
185  $this->nb["contacts"]=$obj->nb;
186  }
187  $this->db->free($resql);
188  return 1;
189  }
190  else
191  {
192  dol_print_error($this->db);
193  $this->error=$this->db->lasterror();
194  return -1;
195  }
196  }
197 
204  function create($user)
205  {
206  global $conf, $langs;
207 
208  $error=0;
209  $now=dol_now();
210 
211  $this->db->begin();
212 
213  // Clean parameters
214  $this->lastname=$this->lastname?trim($this->lastname):trim($this->name);
215  $this->firstname=trim($this->firstname);
216  if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname=ucwords($this->lastname);
217  if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname=ucwords($this->firstname);
218  if (empty($this->socid)) $this->socid = 0;
219  if (empty($this->priv)) $this->priv = 0;
220  if (empty($this->statut)) $this->statut = 0; // This is to convert '' into '0' to avoid bad sql request
221 
222  $this->entity = ((isset($this->entity) && is_numeric($this->entity))?$this->entity:$conf->entity);
223 
224  $sql = "INSERT INTO ".MAIN_DB_PREFIX."socpeople (";
225  $sql.= " datec";
226  $sql.= ", fk_soc";
227  $sql.= ", lastname";
228  $sql.= ", firstname";
229  $sql.= ", fk_user_creat";
230  $sql.= ", priv";
231  $sql.= ", statut";
232  $sql.= ", canvas";
233  $sql.= ", entity";
234  $sql.= ", ref_ext";
235  $sql.= ", import_key";
236  $sql.= ") VALUES (";
237  $sql.= "'".$this->db->idate($now)."',";
238  if ($this->socid > 0) $sql.= " ".$this->db->escape($this->socid).",";
239  else $sql.= "null,";
240  $sql.= "'".$this->db->escape($this->lastname)."',";
241  $sql.= "'".$this->db->escape($this->firstname)."',";
242  $sql.= " ".($user->id > 0 ? "'".$this->db->escape($user->id)."'":"null").",";
243  $sql.= " ".$this->db->escape($this->priv).",";
244  $sql.= " ".$this->db->escape($this->statut).",";
245  $sql.= " ".(! empty($this->canvas)?"'".$this->db->escape($this->canvas)."'":"null").",";
246  $sql.= " ".$this->db->escape($this->entity).",";
247  $sql.= "'".$this->db->escape($this->ref_ext)."',";
248  $sql.= " ".(! empty($this->import_key)?"'".$this->db->escape($this->import_key)."'":"null");
249  $sql.= ")";
250 
251  dol_syslog(get_class($this)."::create", LOG_DEBUG);
252  $resql=$this->db->query($sql);
253  if ($resql)
254  {
255  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."socpeople");
256 
257  if (! $error)
258  {
259  $result=$this->update($this->id, $user, 1, 'add');
260  if ($result < 0)
261  {
262  $error++;
263  $this->error=$this->db->lasterror();
264  }
265  }
266 
267  if (! $error)
268  {
269  $result=$this->update_perso($this->id, $user, 1); // TODO Remove function update_perso, should be same than update
270  if ($result < 0)
271  {
272  $error++;
273  $this->error=$this->db->lasterror();
274  }
275  }
276 
277  if (! $error)
278  {
279  // Call trigger
280  $result=$this->call_trigger('CONTACT_CREATE',$user);
281  if ($result < 0) { $error++; }
282  // End call triggers
283  }
284 
285  if (! $error)
286  {
287  $this->db->commit();
288  return $this->id;
289  }
290  else
291  {
292  $this->db->rollback();
293  dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
294  return -2;
295  }
296  }
297  else
298  {
299  $this->error=$this->db->lasterror();
300 
301  $this->db->rollback();
302  dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
303  return -1;
304  }
305  }
306 
317  function update($id, $user=null, $notrigger=0, $action='update', $nosyncuser=0)
318  {
319  global $conf, $langs, $hookmanager;
320 
321  $error=0;
322 
323  $this->id = $id;
324 
325  $this->entity = ((isset($this->entity) && is_numeric($this->entity))?$this->entity:$conf->entity);
326 
327  // Clean parameters
328  $this->lastname=trim($this->lastname)?trim($this->lastname):trim($this->lastname);
329  $this->firstname=trim($this->firstname);
330  $this->email=trim($this->email);
331  $this->phone_pro=trim($this->phone_pro);
332  $this->phone_perso=trim($this->phone_perso);
333  $this->phone_mobile=trim($this->phone_mobile);
334  $this->jabberid=trim($this->jabberid);
335  $this->skype=trim($this->skype);
336  $this->photo=trim($this->photo);
337  $this->fax=trim($this->fax);
338  $this->zip=(empty($this->zip)?'':$this->zip);
339  $this->town=(empty($this->town)?'':$this->town);
340  $this->country_id=($this->country_id > 0?$this->country_id:$this->country_id);
341  $this->state_id=($this->state_id > 0?$this->state_id:$this->fk_departement);
342  if (empty($this->statut)) $this->statut = 0;
343 
344  $this->db->begin();
345 
346  $sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET ";
347  if ($this->socid > 0) $sql .= " fk_soc='".$this->db->escape($this->socid)."',";
348  else if ($this->socid == -1) $sql .= " fk_soc=null,";
349  $sql .= " civility='".$this->db->escape($this->civility_id)."'";
350  $sql .= ", lastname='".$this->db->escape($this->lastname)."'";
351  $sql .= ", firstname='".$this->db->escape($this->firstname)."'";
352  $sql .= ", address='".$this->db->escape($this->address)."'";
353  $sql .= ", zip='".$this->db->escape($this->zip)."'";
354  $sql .= ", town='".$this->db->escape($this->town)."'";
355  $sql .= ", fk_pays=".($this->country_id>0?$this->country_id:'NULL');
356  $sql .= ", fk_departement=".($this->state_id>0?$this->state_id:'NULL');
357  $sql .= ", poste='".$this->db->escape($this->poste)."'";
358  $sql .= ", fax='".$this->db->escape($this->fax)."'";
359  $sql .= ", email='".$this->db->escape($this->email)."'";
360  $sql .= ", skype='".$this->db->escape($this->skype)."'";
361  $sql .= ", twitter='".$this->db->escape($this->twitter)."'";
362  $sql .= ", facebook='".$this->db->escape($this->facebook)."'";
363  $sql .= ", photo='".$this->db->escape($this->photo)."'";
364  $sql .= ", birthday=".($this->birthday ? "'".$this->db->idate($this->birthday)."'" : "null");
365  $sql .= ", note_private = ".(isset($this->note_private)?"'".$this->db->escape($this->note_private)."'":"null");
366  $sql .= ", note_public = ".(isset($this->note_public)?"'".$this->db->escape($this->note_public)."'":"null");
367  $sql .= ", phone = ".(isset($this->phone_pro)?"'".$this->db->escape($this->phone_pro)."'":"null");
368  $sql .= ", phone_perso = ".(isset($this->phone_perso)?"'".$this->db->escape($this->phone_perso)."'":"null");
369  $sql .= ", phone_mobile = ".(isset($this->phone_mobile)?"'".$this->db->escape($this->phone_mobile)."'":"null");
370  $sql .= ", jabberid = ".(isset($this->jabberid)?"'".$this->db->escape($this->jabberid)."'":"null");
371  $sql .= ", priv = '".$this->db->escape($this->priv)."'";
372  $sql .= ", statut = ".$this->db->escape($this->statut);
373  $sql .= ", fk_user_modif=".($user->id > 0 ? "'".$this->db->escape($user->id)."'":"NULL");
374  $sql .= ", default_lang=".($this->default_lang?"'".$this->db->escape($this->default_lang)."'":"NULL");
375  $sql .= ", no_email=".($this->no_email?"'".$this->db->escape($this->no_email)."'":"0");
376  $sql .= ", entity = " . $this->db->escape($this->entity);
377  $sql .= " WHERE rowid=".$this->db->escape($id);
378 
379  dol_syslog(get_class($this)."::update", LOG_DEBUG);
380  $result = $this->db->query($sql);
381  if ($result)
382  {
383  unset($this->country_code);
384  unset($this->country);
385  unset($this->state_code);
386  unset($this->state);
387 
388  $action='update';
389 
390  // Actions on extra fields
391  if (! $error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))
392  {
393  $result=$this->insertExtraFields();
394  if ($result < 0)
395  {
396  $error++;
397  }
398  }
399 
400  if (! $error && $this->user_id > 0)
401  {
402  $tmpobj = new User($this->db);
403  $tmpobj->fetch($this->user_id);
404  $usermustbemodified = 0;
405  if ($tmpobj->office_phone != $this->phone_pro)
406  {
407  $tmpobj->office_phone = $this->phone_pro;
408  $usermustbemodified++;
409  }
410  if ($tmpobj->office_fax != $this->fax)
411  {
412  $tmpobj->office_fax = $this->fax;
413  $usermustbemodified++;
414  }
415  if ($tmpobj->address != $this->address)
416  {
417  $tmpobj->address = $this->address;
418  $usermustbemodified++;
419  }
420  if ($tmpobj->town != $this->town)
421  {
422  $tmpobj->town = $this->town;
423  $usermustbemodified++;
424  }
425  if ($tmpobj->zip != $this->zip)
426  {
427  $tmpobj->zip = $this->zip;
428  $usermustbemodified++;
429  }
430  if ($tmpobj->zip != $this->zip)
431  {
432  $tmpobj->state_id=$this->state_id;
433  $usermustbemodified++;
434  }
435  if ($tmpobj->country_id != $this->country_id)
436  {
437  $tmpobj->country_id = $this->country_id;
438  $usermustbemodified++;
439  }
440  if ($tmpobj->email != $this->email)
441  {
442  $tmpobj->email = $this->email;
443  $usermustbemodified++;
444  }
445  if ($tmpobj->skype != $this->skype)
446  {
447  $tmpobj->skype = $this->skype;
448  $usermustbemodified++;
449  }
450  if ($tmpobj->twitter != $this->twitter)
451  {
452  $tmpobj->twitter = $this->twitter;
453  $usermustbemodified++;
454  }
455  if ($tmpobj->facebook != $this->facebook)
456  {
457  $tmpobj->facebook = $this->facebook;
458  $usermustbemodified++;
459  }
460  if ($usermustbemodified)
461  {
462  $result=$tmpobj->update($user, 0, 1, 1, 1);
463  if ($result < 0) { $error++; }
464  }
465  }
466 
467  if (! $error && ! $notrigger)
468  {
469  // Call trigger
470  $result=$this->call_trigger('CONTACT_MODIFY',$user);
471  if ($result < 0) { $error++; }
472  // End call triggers
473  }
474 
475  if (! $error)
476  {
477  $this->db->commit();
478  return 1;
479  }
480  else
481  {
482  dol_syslog(get_class($this)."::update Error ".$this->error,LOG_ERR);
483  $this->db->rollback();
484  return -$error;
485  }
486  }
487  else
488  {
489  $this->error=$this->db->lasterror().' sql='.$sql;
490  $this->db->rollback();
491  return -1;
492  }
493  }
494 
495 
496  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
506  function _load_ldap_dn($info,$mode=0)
507  {
508  // phpcs:enable
509  global $conf;
510  $dn='';
511  if ($mode==0) $dn=$conf->global->LDAP_KEY_CONTACTS."=".$info[$conf->global->LDAP_KEY_CONTACTS].",".$conf->global->LDAP_CONTACT_DN;
512  elseif ($mode==1) $dn=$conf->global->LDAP_CONTACT_DN;
513  elseif ($mode==2) $dn=$conf->global->LDAP_KEY_CONTACTS."=".$info[$conf->global->LDAP_KEY_CONTACTS];
514  return $dn;
515  }
516 
517 
518  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
524  function _load_ldap_info()
525  {
526  // phpcs:enable
527  global $conf, $langs;
528 
529  $info = array();
530 
531  // Object classes
532  $info["objectclass"]=explode(',', $conf->global->LDAP_CONTACT_OBJECT_CLASS);
533 
534  $this->fullname=$this->getFullName($langs);
535 
536  // Fields
537  if ($this->fullname && ! empty($conf->global->LDAP_CONTACT_FIELD_FULLNAME)) $info[$conf->global->LDAP_CONTACT_FIELD_FULLNAME] = $this->fullname;
538  if ($this->lastname && ! empty($conf->global->LDAP_CONTACT_FIELD_NAME)) $info[$conf->global->LDAP_CONTACT_FIELD_NAME] = $this->lastname;
539  if ($this->firstname && ! empty($conf->global->LDAP_CONTACT_FIELD_FIRSTNAME)) $info[$conf->global->LDAP_CONTACT_FIELD_FIRSTNAME] = $this->firstname;
540 
541  if ($this->poste) $info["title"] = $this->poste;
542  if ($this->socid > 0)
543  {
544  $soc = new Societe($this->db);
545  $soc->fetch($this->socid);
546 
547  $info[$conf->global->LDAP_CONTACT_FIELD_COMPANY] = $soc->name;
548  if ($soc->client == 1) $info["businessCategory"] = "Customers";
549  if ($soc->client == 2) $info["businessCategory"] = "Prospects";
550  if ($soc->fournisseur == 1) $info["businessCategory"] = "Suppliers";
551  }
552  if ($this->address && ! empty($conf->global->LDAP_CONTACT_FIELD_ADDRESS)) $info[$conf->global->LDAP_CONTACT_FIELD_ADDRESS] = $this->address;
553  if ($this->zip && ! empty($conf->global->LDAP_CONTACT_FIELD_ZIP)) $info[$conf->global->LDAP_CONTACT_FIELD_ZIP] = $this->zip;
554  if ($this->town && ! empty($conf->global->LDAP_CONTACT_FIELD_TOWN)) $info[$conf->global->LDAP_CONTACT_FIELD_TOWN] = $this->town;
555  if ($this->country_code && ! empty($conf->global->LDAP_CONTACT_FIELD_COUNTRY)) $info[$conf->global->LDAP_CONTACT_FIELD_COUNTRY] = $this->country_code;
556  if ($this->phone_pro && ! empty($conf->global->LDAP_CONTACT_FIELD_PHONE)) $info[$conf->global->LDAP_CONTACT_FIELD_PHONE] = $this->phone_pro;
557  if ($this->phone_perso && ! empty($conf->global->LDAP_CONTACT_FIELD_HOMEPHONE)) $info[$conf->global->LDAP_CONTACT_FIELD_HOMEPHONE] = $this->phone_perso;
558  if ($this->phone_mobile && ! empty($conf->global->LDAP_CONTACT_FIELD_MOBILE)) $info[$conf->global->LDAP_CONTACT_FIELD_MOBILE] = $this->phone_mobile;
559  if ($this->fax && ! empty($conf->global->LDAP_CONTACT_FIELD_FAX)) $info[$conf->global->LDAP_CONTACT_FIELD_FAX] = $this->fax;
560  if ($this->skype && ! empty($conf->global->LDAP_CONTACT_FIELD_SKYPE)) $info[$conf->global->LDAP_CONTACT_FIELD_SKYPE] = $this->skype;
561  if ($this->note_private && ! empty($conf->global->LDAP_CONTACT_FIELD_DESCRIPTION)) $info[$conf->global->LDAP_CONTACT_FIELD_DESCRIPTION] = dol_string_nohtmltag($this->note_private, 2);
562  if ($this->email && ! empty($conf->global->LDAP_CONTACT_FIELD_MAIL)) $info[$conf->global->LDAP_CONTACT_FIELD_MAIL] = $this->email;
563 
564  if ($conf->global->LDAP_SERVER_TYPE == 'egroupware')
565  {
566  $info["objectclass"][4] = "phpgwContact"; // compatibilite egroupware
567 
568  $info['uidnumber'] = $this->id;
569 
570  $info['phpgwTz'] = 0;
571  $info['phpgwMailType'] = 'INTERNET';
572  $info['phpgwMailHomeType'] = 'INTERNET';
573 
574  $info["phpgwContactTypeId"] = 'n';
575  $info["phpgwContactCatId"] = 0;
576  $info["phpgwContactAccess"] = "public";
577 
578  if (dol_strlen($this->egroupware_id) == 0)
579  {
580  $this->egroupware_id = 1;
581  }
582 
583  $info["phpgwContactOwner"] = $this->egroupware_id;
584 
585  if ($this->email) $info["rfc822Mailbox"] = $this->email;
586  if ($this->phone_mobile) $info["phpgwCellTelephoneNumber"] = $this->phone_mobile;
587  }
588 
589  return $info;
590  }
591 
592 
593  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
602  function update_perso($id, $user=null, $notrigger=0)
603  {
604  // phpcs:enable
605  $error=0;
606  $result=false;
607 
608  $this->db->begin();
609 
610  // Mis a jour contact
611  $sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET";
612  $sql.= " birthday=".($this->birthday ? "'".$this->db->idate($this->birthday)."'" : "null");
613  $sql.= ", photo = ".($this->photo? "'".$this->db->escape($this->photo)."'" : "null");
614  if ($user) $sql .= ", fk_user_modif=".$user->id;
615  $sql.= " WHERE rowid=".$this->db->escape($id);
616 
617  dol_syslog(get_class($this)."::update_perso this->birthday=".$this->birthday." -", LOG_DEBUG);
618  $resql = $this->db->query($sql);
619  if (! $resql)
620  {
621  $error++;
622  $this->error=$this->db->lasterror();
623  }
624 
625  // Mis a jour alerte birthday
626  if ($this->birthday_alert)
627  {
628  //check existing
629  $sql_check = "SELECT * FROM ".MAIN_DB_PREFIX."user_alert WHERE type=1 AND fk_contact=".$this->db->escape($id)." AND fk_user=".$user->id;
630  $result_check = $this->db->query($sql_check);
631  if (! $result_check || ($this->db->num_rows($result_check)<1))
632  {
633  //insert
634  $sql = "INSERT INTO ".MAIN_DB_PREFIX."user_alert(type,fk_contact,fk_user) ";
635  $sql.= "VALUES (1,".$this->db->escape($id).",".$user->id.")";
636  $result = $this->db->query($sql);
637  if (! $result)
638  {
639  $error++;
640  $this->error=$this->db->lasterror();
641  }
642  }
643  else
644  {
645  $result = true;
646  }
647  }
648  else
649  {
650  $sql = "DELETE FROM ".MAIN_DB_PREFIX."user_alert ";
651  $sql.= "WHERE type=1 AND fk_contact=".$this->db->escape($id)." AND fk_user=".$user->id;
652  $result = $this->db->query($sql);
653  if (! $result)
654  {
655  $error++;
656  $this->error=$this->db->lasterror();
657  }
658  }
659 
660  if (! $error && ! $notrigger)
661  {
662  // Call trigger
663  $result=$this->call_trigger('CONTACT_MODIFY',$user);
664  if ($result < 0) { $error++; }
665  // End call triggers
666  }
667 
668  if (! $error)
669  {
670  $this->db->commit();
671  return 1;
672  }
673  else
674  {
675  dol_syslog(get_class($this)."::update Error ".$this->error,LOG_ERR);
676  $this->db->rollback();
677  return -$error;
678  }
679  }
680 
681 
691  function fetch($id, $user=null, $ref_ext='', $email='')
692  {
693  global $langs;
694 
695  dol_syslog(get_class($this)."::fetch id=".$id, LOG_DEBUG);
696 
697  if (empty($id) && empty($ref_ext))
698  {
699  $this->error='BadParameter';
700  return -1;
701  }
702 
703  $langs->load("companies");
704 
705  $sql = "SELECT c.rowid, c.entity, c.fk_soc, c.ref_ext, c.civility as civility_id, c.lastname, c.firstname,";
706  $sql.= " c.address, c.statut, c.zip, c.town,";
707  $sql.= " c.fk_pays as country_id,";
708  $sql.= " c.fk_departement,";
709  $sql.= " c.birthday,";
710  $sql.= " c.poste, c.phone, c.phone_perso, c.phone_mobile, c.fax, c.email, c.jabberid, c.skype, c.twitter, c.facebook,";
711  $sql.= " c.photo,";
712  $sql.= " c.priv, c.note_private, c.note_public, c.default_lang, c.no_email, c.canvas,";
713  $sql.= " c.import_key,";
714  $sql.= " c.datec as date_creation, c.tms as date_modification,";
715  $sql.= " co.label as country, co.code as country_code,";
716  $sql.= " d.nom as state, d.code_departement as state_code,";
717  $sql.= " u.rowid as user_id, u.login as user_login,";
718  $sql.= " s.nom as socname, s.address as socaddress, s.zip as soccp, s.town as soccity, s.default_lang as socdefault_lang";
719  $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c";
720  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co ON c.fk_pays = co.rowid";
721  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as d ON c.fk_departement = d.rowid";
722  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON c.rowid = u.fk_socpeople";
723  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON c.fk_soc = s.rowid";
724  if ($id) $sql.= " WHERE c.rowid = ". $id;
725  else
726  {
727  $sql .= " WHERE c.entity IN (".getEntity($this->element).")";
728  if ($ref_ext) {
729  $sql .= " AND c.ref_ext = '".$this->db->escape($ref_ext)."'";
730  }
731  if ($email) {
732  $sql .= " AND c.email = '".$this->db->escape($email)."'";
733  }
734  }
735 
736  $resql=$this->db->query($sql);
737  if ($resql)
738  {
739  if ($this->db->num_rows($resql))
740  {
741  $obj = $this->db->fetch_object($resql);
742 
743  $this->id = $obj->rowid;
744  $this->entity = $obj->entity;
745  $this->ref = $obj->rowid;
746  $this->ref_ext = $obj->ref_ext;
747  $this->civility_id = $obj->civility_id;
748  $this->civility_code = $obj->civility_id;
749  $this->lastname = $obj->lastname;
750  $this->firstname = $obj->firstname;
751  $this->address = $obj->address;
752  $this->zip = $obj->zip;
753  $this->town = $obj->town;
754 
755  $this->date_creation = $this->db->jdate($obj->date_creation);
756  $this->date_modification = $this->db->jdate($obj->date_modification);
757 
758  $this->fk_departement = $obj->fk_departement; // deprecated
759  $this->state_id = $obj->fk_departement;
760  $this->departement_code = $obj->state_code; // deprecated
761  $this->state_code = $obj->state_code;
762  $this->departement = $obj->state; // deprecated
763  $this->state = $obj->state;
764 
765  $this->country_id = $obj->country_id;
766  $this->country_code = $obj->country_id?$obj->country_code:'';
767  $this->country = $obj->country_id?($langs->trans('Country'.$obj->country_code)!='Country'.$obj->country_code?$langs->transnoentities('Country'.$obj->country_code):$obj->country):'';
768 
769  $this->socid = $obj->fk_soc;
770  $this->socname = $obj->socname;
771  $this->poste = $obj->poste;
772  $this->statut = $obj->statut;
773 
774  $this->phone_pro = trim($obj->phone);
775  $this->fax = trim($obj->fax);
776  $this->phone_perso = trim($obj->phone_perso);
777  $this->phone_mobile = trim($obj->phone_mobile);
778 
779  $this->email = $obj->email;
780  $this->jabberid = $obj->jabberid;
781  $this->skype = $obj->skype;
782  $this->twitter = $obj->twitter;
783  $this->facebook = $obj->facebook;
784  $this->photo = $obj->photo;
785  $this->priv = $obj->priv;
786  $this->mail = $obj->email;
787 
788  $this->birthday = $this->db->jdate($obj->birthday);
789  $this->note = $obj->note_private; // deprecated
790  $this->note_private = $obj->note_private;
791  $this->note_public = $obj->note_public;
792  $this->default_lang = $obj->default_lang;
793  $this->no_email = $obj->no_email;
794  $this->user_id = $obj->user_id;
795  $this->user_login = $obj->user_login;
796  $this->canvas = $obj->canvas;
797 
798  $this->import_key = $obj->import_key;
799 
800  // Define gender according to civility
801  $this->setGenderFromCivility();
802 
803  // Search Dolibarr user linked to this contact
804  $sql = "SELECT u.rowid ";
805  $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
806  $sql .= " WHERE u.fk_socpeople = ". $this->id;
807 
808  $resql=$this->db->query($sql);
809  if ($resql)
810  {
811  if ($this->db->num_rows($resql))
812  {
813  $uobj = $this->db->fetch_object($resql);
814 
815  $this->user_id = $uobj->rowid;
816  }
817  $this->db->free($resql);
818  }
819  else
820  {
821  $this->error=$this->db->error();
822  return -1;
823  }
824 
825  // Charge alertes du user
826  if ($user)
827  {
828  $sql = "SELECT fk_user";
829  $sql .= " FROM ".MAIN_DB_PREFIX."user_alert";
830  $sql .= " WHERE fk_user = ".$user->id." AND fk_contact = ".$this->db->escape($id);
831 
832  $resql=$this->db->query($sql);
833  if ($resql)
834  {
835  if ($this->db->num_rows($resql))
836  {
837  $obj = $this->db->fetch_object($resql);
838 
839  $this->birthday_alert = 1;
840  }
841  $this->db->free($resql);
842  }
843  else
844  {
845  $this->error=$this->db->error();
846  return -1;
847  }
848  }
849 
850  // Retreive all extrafield
851  // fetch optionals attributes and labels
852  $this->fetch_optionals();
853 
854  return 1;
855  }
856  else
857  {
858  $this->error=$langs->trans("RecordNotFound");
859  return 0;
860  }
861  }
862  else
863  {
864  $this->error=$this->db->error();
865  return -1;
866  }
867  }
868 
869 
876  {
877  unset($this->gender);
878  if (in_array($this->civility_id, array('MR'))) {
879  $this->gender = 'man';
880  } else if(in_array($this->civility_id, array('MME','MLE'))) {
881  $this->gender = 'woman';
882  }
883  }
884 
885  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
895  function load_ref_elements()
896  {
897  // phpcs:enable
898  // Compte les elements pour lesquels il est contact
899  $sql ="SELECT tc.element, count(ec.rowid) as nb";
900  $sql.=" FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc";
901  $sql.=" WHERE ec.fk_c_type_contact = tc.rowid";
902  $sql.=" AND fk_socpeople = ". $this->id;
903  $sql.=" AND tc.source = 'external'";
904  $sql.=" GROUP BY tc.element";
905 
906  dol_syslog(get_class($this)."::load_ref_elements", LOG_DEBUG);
907 
908  $resql=$this->db->query($sql);
909  if ($resql)
910  {
911  while($obj=$this->db->fetch_object($resql))
912  {
913  if ($obj->nb)
914  {
915  if ($obj->element=='facture') $this->ref_facturation = $obj->nb;
916  elseif ($obj->element=='contrat') $this->ref_contrat = $obj->nb;
917  elseif ($obj->element=='commande') $this->ref_commande = $obj->nb;
918  elseif ($obj->element=='propal') $this->ref_propal = $obj->nb;
919  }
920  }
921  $this->db->free($resql);
922  return 0;
923  }
924  else
925  {
926  $this->error=$this->db->lasterror();
927  return -1;
928  }
929  }
930 
937  function delete($notrigger=0)
938  {
939  global $conf, $langs, $user;
940 
941  $error=0;
942 
943  //$this->old_lastname = $obj->lastname;
944  //$this->old_firstname = $obj->firstname;
945 
946  $this->db->begin();
947 
948  if (! $error)
949  {
950  // Get all rowid of element_contact linked to a type that is link to llx_socpeople
951  $sql = "SELECT ec.rowid";
952  $sql.= " FROM ".MAIN_DB_PREFIX."element_contact ec,";
953  $sql.= " ".MAIN_DB_PREFIX."c_type_contact tc";
954  $sql.= " WHERE ec.fk_socpeople=".$this->id;
955  $sql.= " AND ec.fk_c_type_contact=tc.rowid";
956  $sql.= " AND tc.source='external'";
957  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
958  $resql = $this->db->query($sql);
959  if ($resql)
960  {
961  $num=$this->db->num_rows($resql);
962 
963  $i=0;
964  while ($i < $num && ! $error)
965  {
966  $obj = $this->db->fetch_object($resql);
967 
968  $sqldel = "DELETE FROM ".MAIN_DB_PREFIX."element_contact";
969  $sqldel.=" WHERE rowid = ".$obj->rowid;
970  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
971  $result = $this->db->query($sqldel);
972  if (! $result)
973  {
974  $error++;
975  $this->error=$this->db->error().' sql='.$sqldel;
976  }
977 
978  $i++;
979  }
980  }
981  else
982  {
983  $error++;
984  $this->error=$this->db->error().' sql='.$sql;
985  }
986  }
987 
988  if (! $error)
989  {
990  // Remove category
991  $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_contact WHERE fk_socpeople = ".$this->id;
992  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
993  $resql=$this->db->query($sql);
994  if (! $resql)
995  {
996  $error++;
997  $this->error .= $this->db->lasterror();
998  $errorflag=-1;
999  }
1000  }
1001 
1002  if (! $error)
1003  {
1004  $sql = "DELETE FROM ".MAIN_DB_PREFIX."socpeople";
1005  $sql .= " WHERE rowid=".$this->id;
1006  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1007  $result = $this->db->query($sql);
1008  if (! $result)
1009  {
1010  $error++;
1011  $this->error=$this->db->error().' sql='.$sql;
1012  }
1013  }
1014 
1015  // Removed extrafields
1016  if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) { // For avoid conflicts if trigger used
1017  $result=$this->deleteExtraFields($this);
1018  if ($result < 0) $error++;
1019  }
1020 
1021  if (! $error && ! $notrigger)
1022  {
1023  // Call trigger
1024  $result=$this->call_trigger('CONTACT_DELETE',$user);
1025  if ($result < 0) { $error++; }
1026  // End call triggers
1027  }
1028 
1029  if (! $error)
1030  {
1031 
1032  $this->db->commit();
1033  return 1;
1034  }
1035  else
1036  {
1037  $this->db->rollback();
1038  dol_syslog("Error ".$this->error,LOG_ERR);
1039  return -1;
1040  }
1041  }
1042 
1043 
1050  function info($id)
1051  {
1052  $sql = "SELECT c.rowid, c.datec as datec, c.fk_user_creat,";
1053  $sql.= " c.tms as tms, c.fk_user_modif";
1054  $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c";
1055  $sql.= " WHERE c.rowid = ".$this->db->escape($id);
1056 
1057  $resql=$this->db->query($sql);
1058  if ($resql)
1059  {
1060  if ($this->db->num_rows($resql))
1061  {
1062  $obj = $this->db->fetch_object($resql);
1063 
1064  $this->id = $obj->rowid;
1065 
1066  if ($obj->fk_user_creat) {
1067  $cuser = new User($this->db);
1068  $cuser->fetch($obj->fk_user_creat);
1069  $this->user_creation = $cuser;
1070  }
1071 
1072  if ($obj->fk_user_modif) {
1073  $muser = new User($this->db);
1074  $muser->fetch($obj->fk_user_modif);
1075  $this->user_modification = $muser;
1076  }
1077 
1078  $this->date_creation = $this->db->jdate($obj->datec);
1079  $this->date_modification = $this->db->jdate($obj->tms);
1080  }
1081 
1082  $this->db->free($resql);
1083  }
1084  else
1085  {
1086  print $this->db->error();
1087  }
1088  }
1089 
1095  function getNbOfEMailings()
1096  {
1097  $sql = "SELECT count(mc.email) as nb";
1098  $sql.= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc, ".MAIN_DB_PREFIX."mailing as m";
1099  $sql.= " WHERE mc.fk_mailing=m.rowid AND mc.email = '".$this->db->escape($this->email)."' ";
1100  $sql.= " AND m.entity IN (".getEntity($this->element).") AND mc.statut NOT IN (-1,0)"; // -1 error, 0 not sent, 1 sent with success
1101 
1102  $resql=$this->db->query($sql);
1103  if ($resql)
1104  {
1105  $obj = $this->db->fetch_object($resql);
1106  $nb=$obj->nb;
1107 
1108  $this->db->free($resql);
1109  return $nb;
1110  }
1111  else
1112  {
1113  $this->error=$this->db->error();
1114  return -1;
1115  }
1116  }
1117 
1130  function getNomUrl($withpicto=0, $option='', $maxlen=0, $moreparam='', $save_lastsearch_value=-1, $notooltip=0)
1131  {
1132  global $conf, $langs, $hookmanager;
1133 
1134  $result='';
1135 
1136  $label = '<u>' . $langs->trans("ShowContact") . '</u>';
1137  $label.= '<br><b>' . $langs->trans("Name") . ':</b> '.$this->getFullName($langs);
1138  //if ($this->civility_id) $label.= '<br><b>' . $langs->trans("Civility") . ':</b> '.$this->civility_id; // TODO Translate cibilty_id code
1139  if (! empty($this->poste)) $label.= '<br><b>' . $langs->trans("Poste") . ':</b> '.$this->poste;
1140  $label.= '<br><b>' . $langs->trans("EMail") . ':</b> '.$this->email;
1141  $phonelist=array();
1142  if ($this->phone_pro) $phonelist[]=$this->phone_pro;
1143  if ($this->phone_mobile) $phonelist[]=$this->phone_mobile;
1144  if ($this->phone_perso) $phonelist[]=$this->phone_perso;
1145  $label.= '<br><b>' . $langs->trans("Phone") . ':</b> '.join(', ',$phonelist);
1146  $label.= '<br><b>' . $langs->trans("Address") . ':</b> '.dol_format_address($this, 1, ' ', $langs);
1147 
1148  $url = DOL_URL_ROOT.'/contact/card.php?id='.$this->id;
1149 
1150  if ($option !== 'nolink')
1151  {
1152  // Add param to save lastsearch_values or not
1153  $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
1154  if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
1155  if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
1156  }
1157 
1158  $url .= $moreparam;
1159 
1160  $linkclose="";
1161  if (empty($notooltip)) {
1162  if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
1163  {
1164  $label=$langs->trans("ShowContact");
1165  $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
1166  }
1167  $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"';
1168  $linkclose.= ' class="classfortooltip"';
1169 
1170  /*
1171  $hookmanager->initHooks(array('contactdao'));
1172  $parameters=array('id'=>$this->id);
1173  $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
1174  if ($reshook > 0) $linkclose = $hookmanager->resPrint;
1175  */
1176  }
1177 
1178  $linkstart = '<a href="'.$url.'"';
1179  $linkstart.=$linkclose.'>';
1180  $linkend='</a>';
1181 
1182  if ($option == 'xxx')
1183  {
1184  $linkstart = '<a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$this->id.$moreparam.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
1185  $linkend='</a>';
1186  }
1187 
1188  $result.=$linkstart;
1189  if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip valigntextbottom"'), 0, 0, $notooltip?0:1);
1190  if ($withpicto != 2) $result.=($maxlen?dol_trunc($this->getFullName($langs),$maxlen):$this->getFullName($langs));
1191  $result.=$linkend;
1192 
1193  global $action;
1194  $hookmanager->initHooks(array('contactdao'));
1195  $parameters=array('id'=>$this->id, 'getnomurl'=>$result);
1196  $reshook=$hookmanager->executeHooks('getNomUrl',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
1197  if ($reshook > 0) $result = $hookmanager->resPrint;
1198  else $result .= $hookmanager->resPrint;
1199 
1200  return $result;
1201  }
1202 
1208  function getCivilityLabel()
1209  {
1210  global $langs;
1211  $langs->load("dict");
1212 
1213  $code=(! empty($this->civility_id)?$this->civility_id:(! empty($this->civilite_id)?$this->civilite_id:''));
1214  if (empty($code)) return '';
1215  return $langs->getLabelFromKey($this->db, "Civility".$code, "c_civility", "code", "label", $code);
1216  }
1217 
1224  function getLibStatut($mode)
1225  {
1226  return $this->LibStatut($this->statut,$mode);
1227  }
1228 
1229  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1237  function LibStatut($statut,$mode)
1238  {
1239  // phpcs:enable
1240  global $langs;
1241 
1242  if ($mode == 0)
1243  {
1244  if ($statut==0 || $statut==5) return $langs->trans('Disabled');
1245  elseif ($statut==1 || $statut==4) return $langs->trans('Enabled');
1246  }
1247  elseif ($mode == 1)
1248  {
1249  if ($statut==0 || $statut==5) return $langs->trans('Disabled');
1250  elseif ($statut==1 || $statut==4) return $langs->trans('Enabled');
1251  }
1252  elseif ($mode == 2)
1253  {
1254  if ($statut==0 || $statut==5) return img_picto($langs->trans('Disabled'),'statut5', 'class="pictostatus"').' '.$langs->trans('Disabled');
1255  elseif ($statut==1 || $statut==4) return img_picto($langs->trans('Enabled'),'statut4', 'class="pictostatus"').' '.$langs->trans('Enabled');
1256  }
1257  elseif ($mode == 3)
1258  {
1259  if ($statut==0 || $statut==5) return img_picto($langs->trans('Disabled'),'statut5', 'class="pictostatus"');
1260  elseif ($statut==1 || $statut==4) return img_picto($langs->trans('Enabled'),'statut4', 'class="pictostatus"');
1261  }
1262  elseif ($mode == 4)
1263  {
1264  if ($statut==0) return img_picto($langs->trans('Disabled'),'statut5', 'class="pictostatus"').' '.$langs->trans('Disabled');
1265  elseif ($statut==1 || $statut==4) return img_picto($langs->trans('Enabled'),'statut4', 'class="pictostatus"').' '.$langs->trans('Enabled');
1266  }
1267  elseif ($mode == 5)
1268  {
1269  if ($statut==0 || $statut==5) return '<span class="hideonsmartphone">'.$langs->trans('Disabled').' </span>'.img_picto($langs->trans('Disabled'),'statut5', 'class="pictostatus"');
1270  elseif ($statut==1 || $statut==4) return '<span class="hideonsmartphone">'.$langs->trans('Enabled').' </span>'.img_picto($langs->trans('Enabled'),'statut4', 'class="pictostatus"');
1271  }
1272  }
1273 
1274 
1275  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1282  function LibPubPriv($statut)
1283  {
1284  // phpcs:enable
1285  global $langs;
1286  if ($statut=='1') return $langs->trans('ContactPrivate');
1287  else return $langs->trans('ContactPublic');
1288  }
1289 
1290 
1298  function initAsSpecimen()
1299  {
1300  // Get first id of existing company and save it into $socid
1301  $socid = 0;
1302  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe ORDER BY rowid LIMIT 1";
1303  $resql = $this->db->query($sql);
1304  if ($resql)
1305  {
1306  $obj = $this->db->fetch_object($resql);
1307  if ($obj) $socid=$obj->rowid;
1308  }
1309 
1310  // Initialise parameters
1311  $this->id=0;
1312  $this->specimen=1;
1313  $this->lastname = 'DOLIBARR';
1314  $this->firstname = 'SPECIMEN';
1315  $this->address = '21 jump street';
1316  $this->zip = '99999';
1317  $this->town = 'MyTown';
1318  $this->country_id = 1;
1319  $this->country_code = 'FR';
1320  $this->country = 'France';
1321  $this->email = 'specimen@specimen.com';
1322  $this->skype = 'tom.hanson';
1323 
1324  $this->phone_pro = '0909090901';
1325  $this->phone_perso = '0909090902';
1326  $this->phone_mobile = '0909090903';
1327  $this->fax = '0909090909';
1328 
1329  $this->note_public='This is a comment (public)';
1330  $this->note_private='This is a comment (private)';
1331 
1332  $this->socid = $socid;
1333  $this->statut=1;
1334  }
1335 
1342  function setstatus($statut)
1343  {
1344  global $conf,$langs,$user;
1345 
1346  $error=0;
1347 
1348  // Check parameters
1349  if ($this->statut == $statut) return 0;
1350  else $this->statut = $statut;
1351 
1352  $this->db->begin();
1353 
1354  // Desactive utilisateur
1355  $sql = "UPDATE ".MAIN_DB_PREFIX."socpeople";
1356  $sql.= " SET statut = ".$this->statut;
1357  $sql.= " WHERE rowid = ".$this->id;
1358  $result = $this->db->query($sql);
1359 
1360  dol_syslog(get_class($this)."::setstatus", LOG_DEBUG);
1361  if ($result)
1362  {
1363  // Call trigger
1364  $result=$this->call_trigger('CONTACT_ENABLEDISABLE',$user);
1365  if ($result < 0) { $error++; }
1366  // End call triggers
1367  }
1368 
1369  if ($error)
1370  {
1371  $this->db->rollback();
1372  return -$error;
1373  }
1374  else
1375  {
1376  $this->db->commit();
1377  return 1;
1378  }
1379  }
1380 
1391  public function setCategories($categories)
1392  {
1393  // Handle single category
1394  if (!is_array($categories)) {
1395  $categories = array($categories);
1396  }
1397 
1398  // Get current categories
1399  require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
1400  $c = new Categorie($this->db);
1401  $existing = $c->containing($this->id, Categorie::TYPE_CONTACT, 'id');
1402 
1403  // Diff
1404  if (is_array($existing)) {
1405  $to_del = array_diff($existing, $categories);
1406  $to_add = array_diff($categories, $existing);
1407  } else {
1408  $to_del = array(); // Nothing to delete
1409  $to_add = $categories;
1410  }
1411 
1412  // Process
1413  foreach ($to_del as $del) {
1414  if ($c->fetch($del) > 0) {
1415  $c->del_type($this, 'contact');
1416  }
1417  }
1418  foreach ($to_add as $add) {
1419  if ($c->fetch($add) > 0) {
1420  $c->add_type($this, 'contact');
1421  }
1422  }
1423 
1424  return;
1425  }
1426 
1435  public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
1436  {
1437  $tables = array(
1438  'socpeople'
1439  );
1440 
1441  return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
1442  }
1443 }
print
Draft customers invoices.
Definition: index.php:91
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding &#39;...&#39; if string larger than length.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
update_perso($id, $user=null, $notrigger=0)
Update field alert birthday.
create($user)
Add a contact into database.
Class to manage contact/addresses.
if(! empty($search_group)) natural_search(array("g.nom" g note
Definition: list.php:123
Class to manage Dolibarr users.
Definition: user.class.php:41
update($id, $user=null, $notrigger=0, $action='update', $nosyncuser=0)
Update informations into database.
Class to manage Dolibarr database access.
setCategories($categories)
Sets object to supplied categories.
load_ref_elements()
Load number of elements the contact is used as a link for ref_facturation ref_contrat ref_commande (f...
fetch($id, $user=null, $ref_ext='', $email='')
Load object contact.
load_state_board()
Load indicators into this->nb for board.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
getFullName($langs, $option=0, $nameorder=-1, $maxlen=0)
Return full name (civility+&#39; &#39;+name+&#39; &#39;+lastname)
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:103
info($id)
Charge les informations sur le contact, depuis la base.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
LibPubPriv($statut)
Return translated label of Public or Private.
getNomUrl($withpicto=0, $option='', $maxlen=0, $moreparam='', $save_lastsearch_value=-1, $notooltip=0)
Return name of contact with link (and eventually picto) Use $this->id, $this->lastname, $this->firstname, this->civility_id.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
Class to manage third parties objects (customers, suppliers, prospects...)
LibStatut($statut, $mode)
Renvoi le libelle d&#39;un statut donne.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
Class to manage categories.
setGenderFromCivility()
Set property ->gender from property ->civility_id.
__construct($db)
Constructor.
static commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
getNbOfEMailings()
Return number of mass Emailing received by this contacts with its email.
_load_ldap_dn($info, $mode=0)
Retourne chaine DN complete dans l&#39;annuaire LDAP pour l&#39;objet.
deleteExtraFields()
Delete all extra fields values for the current object.
dol_now($mode='gmt')
Return date for now.
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...
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0)
Clean a string from all HTML tags and entities.
setstatus($statut)
Change status of a user.
_load_ldap_info()
Initialise tableau info (tableau des attributs LDAP)
getCivilityLabel()
Return civility label of contact.
call_trigger($trigger_name, $user)
Call trigger based on this instance.
initAsSpecimen()
Initialise an instance with random values.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it&#39;s its name (generic function)
static replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
getLibStatut($mode)
Return label of contact status.