dolibarr  7.0.0-beta
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@capnetworks.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 {
40  public $element='contact';
41  public $table_element='socpeople';
42  public $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
43  public $picto = 'contact';
44 
45  public $civility_id; // In fact we store civility_code
46  public $civility_code;
47  public $address;
48  public $zip;
49  public $town;
50 
65  public $departement;
66  public $state_id; // Id of department
67  public $state_code; // Code of department
68  public $state; // Label of department
69 
70  public $poste; // Position
71 
72  public $socid; // fk_soc
73  public $statut; // 0=inactif, 1=actif
74 
75  public $code;
76  public $email;
77  public $skype;
78  public $photo;
79  public $jabberid;
80  public $phone_pro;
81  public $phone_perso;
82  public $phone_mobile;
83  public $fax;
84 
85  public $priv;
86 
87  public $birthday;
88  public $default_lang;
89  public $no_email; // 1=Don't send e-mail to this contact, 0=do
90 
91  public $ref_facturation; // Reference number of invoice for which it is contact
92  public $ref_contrat; // Nb de reference contrat pour lequel il est contact
93  public $ref_commande; // Nb de reference commande pour lequel il est contact
94  public $ref_propal; // Nb de reference propal pour lequel il est contact
95 
96  public $user_id;
97  public $user_login;
98 
99  public $oldcopy; // To contains a clone of this when we need to save old properties of object
100 
101 
107  function __construct($db)
108  {
109  $this->db = $db;
110  $this->statut = 1; // By default, status is enabled
111  }
112 
118  function load_state_board()
119  {
120  global $user;
121 
122  $this->nb=array();
123  $clause = "WHERE";
124 
125  $sql = "SELECT count(sp.rowid) as nb";
126  $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as sp";
127  if (!$user->rights->societe->client->voir && !$user->societe_id)
128  {
129  $sql.= ", ".MAIN_DB_PREFIX."societe as s";
130  $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
131  $sql.= " WHERE sp.fk_soc = s.rowid AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
132  $clause = "AND";
133  }
134  $sql.= ' '.$clause.' sp.entity IN ('.getEntity($this->element, 1).')';
135  $sql.= " AND (sp.priv='0' OR (sp.priv='1' AND sp.fk_user_creat=".$user->id."))";
136  if ($user->societe_id > 0) $sql.=" AND sp.fk_soc = ".$user->societe_id;
137 
138  $resql=$this->db->query($sql);
139  if ($resql)
140  {
141  while ($obj=$this->db->fetch_object($resql))
142  {
143  $this->nb["contacts"]=$obj->nb;
144  }
145  $this->db->free($resql);
146  return 1;
147  }
148  else
149  {
150  dol_print_error($this->db);
151  $this->error=$this->db->lasterror();
152  return -1;
153  }
154  }
155 
162  function create($user)
163  {
164  global $conf, $langs;
165 
166  $error=0;
167  $now=dol_now();
168 
169  $this->db->begin();
170 
171  // Clean parameters
172  $this->lastname=$this->lastname?trim($this->lastname):trim($this->name);
173  $this->firstname=trim($this->firstname);
174  if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname=ucwords($this->lastname);
175  if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname=ucwords($this->firstname);
176  if (empty($this->socid)) $this->socid = 0;
177  if (empty($this->priv)) $this->priv = 0;
178  if (empty($this->statut)) $this->statut = 0; // This is to convert '' into '0' to avoid bad sql request
179 
180  $entity = ((isset($this->entity) && is_numeric($this->entity))?$this->entity:$conf->entity);
181 
182  $sql = "INSERT INTO ".MAIN_DB_PREFIX."socpeople (";
183  $sql.= " datec";
184  $sql.= ", fk_soc";
185  $sql.= ", lastname";
186  $sql.= ", firstname";
187  $sql.= ", fk_user_creat";
188  $sql.= ", priv";
189  $sql.= ", statut";
190  $sql.= ", canvas";
191  $sql.= ", entity";
192  $sql.= ", ref_ext";
193  $sql.= ", import_key";
194  $sql.= ") VALUES (";
195  $sql.= "'".$this->db->idate($now)."',";
196  if ($this->socid > 0) $sql.= " ".$this->socid.",";
197  else $sql.= "null,";
198  $sql.= "'".$this->db->escape($this->lastname)."',";
199  $sql.= "'".$this->db->escape($this->firstname)."',";
200  $sql.= " ".($user->id > 0 ? "'".$user->id."'":"null").",";
201  $sql.= " ".$this->priv.",";
202  $sql.= " ".$this->statut.",";
203  $sql.= " ".(! empty($this->canvas)?"'".$this->db->escape($this->canvas)."'":"null").",";
204  $sql.= " ".$entity.",";
205  $sql.= "'".$this->db->escape($this->ref_ext)."',";
206  $sql.= " ".(! empty($this->import_key)?"'".$this->db->escape($this->import_key)."'":"null");
207  $sql.= ")";
208 
209  dol_syslog(get_class($this)."::create", LOG_DEBUG);
210  $resql=$this->db->query($sql);
211  if ($resql)
212  {
213  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."socpeople");
214 
215  if (! $error)
216  {
217  $result=$this->update($this->id, $user, 1, 'add');
218  if ($result < 0)
219  {
220  $error++;
221  $this->error=$this->db->lasterror();
222  }
223  }
224 
225  if (! $error)
226  {
227  $result=$this->update_perso($this->id, $user, 1); // TODO Remove function update_perso, should be same than update
228  if ($result < 0)
229  {
230  $error++;
231  $this->error=$this->db->lasterror();
232  }
233  }
234 
235  if (! $error)
236  {
237  // Call trigger
238  $result=$this->call_trigger('CONTACT_CREATE',$user);
239  if ($result < 0) { $error++; }
240  // End call triggers
241  }
242 
243  if (! $error)
244  {
245  $this->db->commit();
246  return $this->id;
247  }
248  else
249  {
250  $this->db->rollback();
251  dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
252  return -2;
253  }
254  }
255  else
256  {
257  $this->error=$this->db->lasterror();
258 
259  $this->db->rollback();
260  dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
261  return -1;
262  }
263  }
264 
275  function update($id, $user=null, $notrigger=0, $action='update', $nosyncuser=0)
276  {
277  global $conf, $langs, $hookmanager;
278 
279  $error=0;
280 
281  $this->id = $id;
282 
283  // Clean parameters
284  $this->lastname=trim($this->lastname)?trim($this->lastname):trim($this->lastname);
285  $this->firstname=trim($this->firstname);
286  $this->email=trim($this->email);
287  $this->phone_pro=trim($this->phone_pro);
288  $this->phone_perso=trim($this->phone_perso);
289  $this->phone_mobile=trim($this->phone_mobile);
290  $this->jabberid=trim($this->jabberid);
291  $this->skype=trim($this->skype);
292  $this->photo=trim($this->photo);
293  $this->fax=trim($this->fax);
294  $this->zip=(empty($this->zip)?'':$this->zip);
295  $this->town=(empty($this->town)?'':$this->town);
296  $this->country_id=($this->country_id > 0?$this->country_id:$this->country_id);
297  $this->state_id=($this->state_id > 0?$this->state_id:$this->fk_departement);
298  if (empty($this->statut)) $this->statut = 0;
299 
300  $this->db->begin();
301 
302  $sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET ";
303  if ($this->socid > 0) $sql .= " fk_soc='".$this->db->escape($this->socid)."',";
304  else if ($this->socid == -1) $sql .= " fk_soc=null,";
305  $sql .= " civility='".$this->db->escape($this->civility_id)."'";
306  $sql .= ", lastname='".$this->db->escape($this->lastname)."'";
307  $sql .= ", firstname='".$this->db->escape($this->firstname)."'";
308  $sql .= ", address='".$this->db->escape($this->address)."'";
309  $sql .= ", zip='".$this->db->escape($this->zip)."'";
310  $sql .= ", town='".$this->db->escape($this->town)."'";
311  $sql .= ", fk_pays=".($this->country_id>0?$this->country_id:'NULL');
312  $sql .= ", fk_departement=".($this->state_id>0?$this->state_id:'NULL');
313  $sql .= ", poste='".$this->db->escape($this->poste)."'";
314  $sql .= ", fax='".$this->db->escape($this->fax)."'";
315  $sql .= ", email='".$this->db->escape($this->email)."'";
316  $sql .= ", skype='".$this->db->escape($this->skype)."'";
317  $sql .= ", photo='".$this->db->escape($this->photo)."'";
318  $sql .= ", note_private = ".(isset($this->note_private)?"'".$this->db->escape($this->note_private)."'":"null");
319  $sql .= ", note_public = ".(isset($this->note_public)?"'".$this->db->escape($this->note_public)."'":"null");
320  $sql .= ", phone = ".(isset($this->phone_pro)?"'".$this->db->escape($this->phone_pro)."'":"null");
321  $sql .= ", phone_perso = ".(isset($this->phone_perso)?"'".$this->db->escape($this->phone_perso)."'":"null");
322  $sql .= ", phone_mobile = ".(isset($this->phone_mobile)?"'".$this->db->escape($this->phone_mobile)."'":"null");
323  $sql .= ", jabberid = ".(isset($this->jabberid)?"'".$this->db->escape($this->jabberid)."'":"null");
324  $sql .= ", priv = '".$this->db->escape($this->priv)."'";
325  $sql .= ", statut = ".$this->statut;
326  $sql .= ", fk_user_modif=".($user->id > 0 ? "'".$this->db->escape($user->id)."'":"NULL");
327  $sql .= ", default_lang=".($this->default_lang?"'".$this->db->escape($this->default_lang)."'":"NULL");
328  $sql .= ", no_email=".($this->no_email?"'".$this->db->escape($this->no_email)."'":"0");
329  $sql .= " WHERE rowid=".$this->db->escape($id);
330 
331  dol_syslog(get_class($this)."::update", LOG_DEBUG);
332  $result = $this->db->query($sql);
333  if ($result)
334  {
335  unset($this->country_code);
336  unset($this->country);
337  unset($this->state_code);
338  unset($this->state);
339 
340  $action='update';
341 
342  // Actions on extra fields (by external module or standard code)
343  $hookmanager->initHooks(array('contactdao'));
344  $parameters=array('socid'=>$this->id);
345  $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
346  if (empty($reshook))
347  {
348  if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
349  {
350  $result=$this->insertExtraFields();
351  if ($result < 0)
352  {
353  $error++;
354  }
355  }
356  }
357  else if ($reshook < 0) $error++;
358 
359  if (! $error && $this->user_id > 0)
360  {
361  $tmpobj = new User($this->db);
362  $tmpobj->fetch($this->user_id);
363  $usermustbemodified = 0;
364  if ($tmpobj->office_phone != $this->phone_pro)
365  {
366  $tmpobj->office_phone = $this->phone_pro;
367  $usermustbemodified++;
368  }
369  if ($tmpobj->office_fax != $this->fax)
370  {
371  $tmpobj->office_fax = $this->fax;
372  $usermustbemodified++;
373  }
374  if ($tmpobj->address != $this->address)
375  {
376  $tmpobj->address = $this->address;
377  $usermustbemodified++;
378  }
379  if ($tmpobj->town != $this->town)
380  {
381  $tmpobj->town = $this->town;
382  $usermustbemodified++;
383  }
384  if ($tmpobj->zip != $this->zip)
385  {
386  $tmpobj->zip = $this->zip;
387  $usermustbemodified++;
388  }
389  if ($tmpobj->zip != $this->zip)
390  {
391  $tmpobj->state_id=$this->state_id;
392  $usermustbemodified++;
393  }
394  if ($tmpobj->country_id != $this->country_id)
395  {
396  $tmpobj->country_id = $this->country_id;
397  $usermustbemodified++;
398  }
399  if ($tmpobj->email != $this->email)
400  {
401  $tmpobj->email = $this->email;
402  $usermustbemodified++;
403  }
404  if ($tmpobj->skype != $this->skype)
405  {
406  $tmpobj->skype = $this->skype;
407  $usermustbemodified++;
408  }
409  if ($usermustbemodified)
410  {
411  $result=$tmpobj->update($user, 0, 1, 1, 1);
412  if ($result < 0) { $error++; }
413  }
414  }
415 
416  if (! $error && ! $notrigger)
417  {
418  // Call trigger
419  $result=$this->call_trigger('CONTACT_MODIFY',$user);
420  if ($result < 0) { $error++; }
421  // End call triggers
422  }
423 
424  if (! $error)
425  {
426  $this->db->commit();
427  return 1;
428  }
429  else
430  {
431  dol_syslog(get_class($this)."::update Error ".$this->error,LOG_ERR);
432  $this->db->rollback();
433  return -$error;
434  }
435  }
436  else
437  {
438  $this->error=$this->db->lasterror().' sql='.$sql;
439  $this->db->rollback();
440  return -1;
441  }
442  }
443 
444 
454  function _load_ldap_dn($info,$mode=0)
455  {
456  global $conf;
457  $dn='';
458  if ($mode==0) $dn=$conf->global->LDAP_KEY_CONTACTS."=".$info[$conf->global->LDAP_KEY_CONTACTS].",".$conf->global->LDAP_CONTACT_DN;
459  if ($mode==1) $dn=$conf->global->LDAP_CONTACT_DN;
460  if ($mode==2) $dn=$conf->global->LDAP_KEY_CONTACTS."=".$info[$conf->global->LDAP_KEY_CONTACTS];
461  return $dn;
462  }
463 
464 
470  function _load_ldap_info()
471  {
472  global $conf,$langs;
473 
474  $info = array();
475 
476  // Object classes
477  $info["objectclass"]=explode(',',$conf->global->LDAP_CONTACT_OBJECT_CLASS);
478 
479  $this->fullname=$this->getFullName($langs);
480 
481  // Fields
482  if ($this->fullname && ! empty($conf->global->LDAP_CONTACT_FIELD_FULLNAME)) $info[$conf->global->LDAP_CONTACT_FIELD_FULLNAME] = $this->fullname;
483  if ($this->lastname && ! empty($conf->global->LDAP_CONTACT_FIELD_NAME)) $info[$conf->global->LDAP_CONTACT_FIELD_NAME] = $this->lastname;
484  if ($this->firstname && ! empty($conf->global->LDAP_CONTACT_FIELD_FIRSTNAME)) $info[$conf->global->LDAP_CONTACT_FIELD_FIRSTNAME] = $this->firstname;
485 
486  if ($this->poste) $info["title"] = $this->poste;
487  if ($this->socid > 0)
488  {
489  $soc = new Societe($this->db);
490  $soc->fetch($this->socid);
491 
492  $info[$conf->global->LDAP_CONTACT_FIELD_COMPANY] = $soc->name;
493  if ($soc->client == 1) $info["businessCategory"] = "Customers";
494  if ($soc->client == 2) $info["businessCategory"] = "Prospects";
495  if ($soc->fournisseur == 1) $info["businessCategory"] = "Suppliers";
496  }
497  if ($this->address && ! empty($conf->global->LDAP_CONTACT_FIELD_ADDRESS)) $info[$conf->global->LDAP_CONTACT_FIELD_ADDRESS] = $this->address;
498  if ($this->zip && ! empty($conf->global->LDAP_CONTACT_FIELD_ZIP)) $info[$conf->global->LDAP_CONTACT_FIELD_ZIP] = $this->zip;
499  if ($this->town && ! empty($conf->global->LDAP_CONTACT_FIELD_TOWN)) $info[$conf->global->LDAP_CONTACT_FIELD_TOWN] = $this->town;
500  if ($this->country_code && ! empty($conf->global->LDAP_CONTACT_FIELD_COUNTRY)) $info[$conf->global->LDAP_CONTACT_FIELD_COUNTRY] = $this->country_code;
501  if ($this->phone_pro && ! empty($conf->global->LDAP_CONTACT_FIELD_PHONE)) $info[$conf->global->LDAP_CONTACT_FIELD_PHONE] = $this->phone_pro;
502  if ($this->phone_perso && ! empty($conf->global->LDAP_CONTACT_FIELD_HOMEPHONE)) $info[$conf->global->LDAP_CONTACT_FIELD_HOMEPHONE] = $this->phone_perso;
503  if ($this->phone_mobile && ! empty($conf->global->LDAP_CONTACT_FIELD_MOBILE)) $info[$conf->global->LDAP_CONTACT_FIELD_MOBILE] = $this->phone_mobile;
504  if ($this->fax && ! empty($conf->global->LDAP_CONTACT_FIELD_FAX)) $info[$conf->global->LDAP_CONTACT_FIELD_FAX] = $this->fax;
505  if ($this->skype && ! empty($conf->global->LDAP_CONTACT_FIELD_SKYPE)) $info[$conf->global->LDAP_CONTACT_FIELD_SKYPE] = $this->skype;
506  if ($this->note_private && ! empty($conf->global->LDAP_CONTACT_FIELD_DESCRIPTION)) $info[$conf->global->LDAP_CONTACT_FIELD_DESCRIPTION] = $this->note_private;
507  if ($this->email && ! empty($conf->global->LDAP_CONTACT_FIELD_MAIL)) $info[$conf->global->LDAP_CONTACT_FIELD_MAIL] = $this->email;
508 
509  if ($conf->global->LDAP_SERVER_TYPE == 'egroupware')
510  {
511  $info["objectclass"][4] = "phpgwContact"; // compatibilite egroupware
512 
513  $info['uidnumber'] = $this->id;
514 
515  $info['phpgwTz'] = 0;
516  $info['phpgwMailType'] = 'INTERNET';
517  $info['phpgwMailHomeType'] = 'INTERNET';
518 
519  $info["phpgwContactTypeId"] = 'n';
520  $info["phpgwContactCatId"] = 0;
521  $info["phpgwContactAccess"] = "public";
522 
523  if (dol_strlen($this->egroupware_id) == 0)
524  {
525  $this->egroupware_id = 1;
526  }
527 
528  $info["phpgwContactOwner"] = $this->egroupware_id;
529 
530  if ($this->email) $info["rfc822Mailbox"] = $this->email;
531  if ($this->phone_mobile) $info["phpgwCellTelephoneNumber"] = $this->phone_mobile;
532  }
533 
534  return $info;
535  }
536 
537 
546  function update_perso($id, $user=null, $notrigger=0)
547  {
548  $error=0;
549  $result=false;
550 
551  $this->db->begin();
552 
553  // Mis a jour contact
554  $sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET";
555  $sql.= " birthday=".($this->birthday ? "'".$this->db->idate($this->birthday)."'" : "null");
556  $sql.= ", photo = ".($this->photo? "'".$this->db->escape($this->photo)."'" : "null");
557  if ($user) $sql .= ", fk_user_modif=".$user->id;
558  $sql.= " WHERE rowid=".$this->db->escape($id);
559 
560  dol_syslog(get_class($this)."::update_perso this->birthday=".$this->birthday." -", LOG_DEBUG);
561  $resql = $this->db->query($sql);
562  if (! $resql)
563  {
564  $error++;
565  $this->error=$this->db->lasterror();
566  }
567 
568  // Mis a jour alerte birthday
569  if ($this->birthday_alert)
570  {
571  //check existing
572  $sql_check = "SELECT * FROM ".MAIN_DB_PREFIX."user_alert WHERE type=1 AND fk_contact=".$this->db->escape($id)." AND fk_user=".$user->id;
573  $result_check = $this->db->query($sql_check);
574  if (! $result_check || ($this->db->num_rows($result_check)<1))
575  {
576  //insert
577  $sql = "INSERT INTO ".MAIN_DB_PREFIX."user_alert(type,fk_contact,fk_user) ";
578  $sql.= "VALUES (1,".$this->db->escape($id).",".$user->id.")";
579  $result = $this->db->query($sql);
580  if (! $result)
581  {
582  $error++;
583  $this->error=$this->db->lasterror();
584  }
585  }
586  else
587  {
588  $result = true;
589  }
590  }
591  else
592  {
593  $sql = "DELETE FROM ".MAIN_DB_PREFIX."user_alert ";
594  $sql.= "WHERE type=1 AND fk_contact=".$this->db->escape($id)." AND fk_user=".$user->id;
595  $result = $this->db->query($sql);
596  if (! $result)
597  {
598  $error++;
599  $this->error=$this->db->lasterror();
600  }
601  }
602 
603  if (! $error && ! $notrigger)
604  {
605  // Call trigger
606  $result=$this->call_trigger('CONTACT_MODIFY',$user);
607  if ($result < 0) { $error++; }
608  // End call triggers
609  }
610 
611  if (! $error)
612  {
613  $this->db->commit();
614  return 1;
615  }
616  else
617  {
618  dol_syslog(get_class($this)."::update Error ".$this->error,LOG_ERR);
619  $this->db->rollback();
620  return -$error;
621  }
622  }
623 
624 
633  function fetch($id, $user=0, $ref_ext='')
634  {
635  global $langs;
636 
637  dol_syslog(get_class($this)."::fetch id=".$id, LOG_DEBUG);
638 
639  if (empty($id) && empty($ref_ext))
640  {
641  $this->error='BadParameter';
642  return -1;
643  }
644 
645  $langs->load("companies");
646 
647  $sql = "SELECT c.rowid, c.entity, c.fk_soc, c.ref_ext, c.civility as civility_id, c.lastname, c.firstname,";
648  $sql.= " c.address, c.statut, c.zip, c.town,";
649  $sql.= " c.fk_pays as country_id,";
650  $sql.= " c.fk_departement,";
651  $sql.= " c.birthday,";
652  $sql.= " c.poste, c.phone, c.phone_perso, c.phone_mobile, c.fax, c.email, c.jabberid, c.skype,";
653  $sql.= " c.photo,";
654  $sql.= " c.priv, c.note_private, c.note_public, c.default_lang, c.no_email, c.canvas,";
655  $sql.= " c.import_key,";
656  $sql.= " co.label as country, co.code as country_code,";
657  $sql.= " d.nom as state, d.code_departement as state_code,";
658  $sql.= " u.rowid as user_id, u.login as user_login,";
659  $sql.= " s.nom as socname, s.address as socaddress, s.zip as soccp, s.town as soccity, s.default_lang as socdefault_lang";
660  $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c";
661  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co ON c.fk_pays = co.rowid";
662  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as d ON c.fk_departement = d.rowid";
663  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON c.rowid = u.fk_socpeople";
664  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON c.fk_soc = s.rowid";
665  if ($id) $sql.= " WHERE c.rowid = ". $id;
666  elseif ($ref_ext) $sql .= " WHERE c.ref_ext = '".$this->db->escape($ref_ext)."'";
667 
668  $resql=$this->db->query($sql);
669  if ($resql)
670  {
671  if ($this->db->num_rows($resql))
672  {
673  $obj = $this->db->fetch_object($resql);
674 
675  $this->id = $obj->rowid;
676  $this->entity = $obj->entity;
677  $this->ref = $obj->rowid;
678  $this->ref_ext = $obj->ref_ext;
679  $this->civility_id = $obj->civility_id;
680  $this->civility_code = $obj->civility_id;
681  $this->lastname = $obj->lastname;
682  $this->firstname = $obj->firstname;
683  $this->address = $obj->address;
684  $this->zip = $obj->zip;
685  $this->town = $obj->town;
686 
687  $this->fk_departement = $obj->fk_departement; // deprecated
688  $this->state_id = $obj->fk_departement;
689  $this->departement_code = $obj->state_code; // deprecated
690  $this->state_code = $obj->state_code;
691  $this->departement = $obj->state; // deprecated
692  $this->state = $obj->state;
693 
694  $this->country_id = $obj->country_id;
695  $this->country_code = $obj->country_id?$obj->country_code:'';
696  $this->country = $obj->country_id?($langs->trans('Country'.$obj->country_code)!='Country'.$obj->country_code?$langs->transnoentities('Country'.$obj->country_code):$obj->country):'';
697 
698  $this->socid = $obj->fk_soc;
699  $this->socname = $obj->socname;
700  $this->poste = $obj->poste;
701  $this->statut = $obj->statut;
702 
703  $this->phone_pro = trim($obj->phone);
704  $this->fax = trim($obj->fax);
705  $this->phone_perso = trim($obj->phone_perso);
706  $this->phone_mobile = trim($obj->phone_mobile);
707 
708  $this->email = $obj->email;
709  $this->jabberid = $obj->jabberid;
710  $this->skype = $obj->skype;
711  $this->photo = $obj->photo;
712  $this->priv = $obj->priv;
713  $this->mail = $obj->email;
714 
715  $this->birthday = $this->db->jdate($obj->birthday);
716  $this->note = $obj->note_private; // deprecated
717  $this->note_private = $obj->note_private;
718  $this->note_public = $obj->note_public;
719  $this->default_lang = $obj->default_lang;
720  $this->no_email = $obj->no_email;
721  $this->user_id = $obj->user_id;
722  $this->user_login = $obj->user_login;
723  $this->canvas = $obj->canvas;
724 
725  $this->import_key = $obj->import_key;
726 
727  // Define gender according to civility
728  $this->setGenderFromCivility();
729 
730  // Search Dolibarr user linked to this contact
731  $sql = "SELECT u.rowid ";
732  $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
733  $sql .= " WHERE u.fk_socpeople = ". $this->id;
734 
735  $resql=$this->db->query($sql);
736  if ($resql)
737  {
738  if ($this->db->num_rows($resql))
739  {
740  $uobj = $this->db->fetch_object($resql);
741 
742  $this->user_id = $uobj->rowid;
743  }
744  $this->db->free($resql);
745  }
746  else
747  {
748  $this->error=$this->db->error();
749  return -1;
750  }
751 
752  // Charge alertes du user
753  if ($user)
754  {
755  $sql = "SELECT fk_user";
756  $sql .= " FROM ".MAIN_DB_PREFIX."user_alert";
757  $sql .= " WHERE fk_user = ".$user->id." AND fk_contact = ".$this->db->escape($id);
758 
759  $resql=$this->db->query($sql);
760  if ($resql)
761  {
762  if ($this->db->num_rows($resql))
763  {
764  $obj = $this->db->fetch_object($resql);
765 
766  $this->birthday_alert = 1;
767  }
768  $this->db->free($resql);
769  }
770  else
771  {
772  $this->error=$this->db->error();
773  return -1;
774  }
775  }
776 
777  // Retreive all extrafield for contact
778  // fetch optionals attributes and labels
779  require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php');
780  $extrafields=new ExtraFields($this->db);
781  $extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
782  $this->fetch_optionals($this->id,$extralabels);
783 
784  return 1;
785  }
786  else
787  {
788  $this->error=$langs->trans("RecordNotFound");
789  return 0;
790  }
791  }
792  else
793  {
794  $this->error=$this->db->error();
795  return -1;
796  }
797  }
798 
799 
806  {
807  unset($this->gender);
808  if (in_array($this->civility_id, array('MR'))) {
809  $this->gender = 'man';
810  } else if(in_array($this->civility_id, array('MME','MLE'))) {
811  $this->gender = 'woman';
812  }
813  }
814 
824  function load_ref_elements()
825  {
826  // Compte les elements pour lesquels il est contact
827  $sql ="SELECT tc.element, count(ec.rowid) as nb";
828  $sql.=" FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc";
829  $sql.=" WHERE ec.fk_c_type_contact = tc.rowid";
830  $sql.=" AND fk_socpeople = ". $this->id;
831  $sql.=" GROUP BY tc.element";
832 
833  dol_syslog(get_class($this)."::load_ref_elements", LOG_DEBUG);
834 
835  $resql=$this->db->query($sql);
836  if ($resql)
837  {
838  while($obj=$this->db->fetch_object($resql))
839  {
840  if ($obj->nb)
841  {
842  if ($obj->element=='facture') $this->ref_facturation = $obj->nb;
843  if ($obj->element=='contrat') $this->ref_contrat = $obj->nb;
844  if ($obj->element=='commande') $this->ref_commande = $obj->nb;
845  if ($obj->element=='propal') $this->ref_propal = $obj->nb;
846  }
847  }
848  $this->db->free($resql);
849  return 0;
850  }
851  else
852  {
853  $this->error=$this->db->lasterror();
854  return -1;
855  }
856  }
857 
864  function delete($notrigger=0)
865  {
866  global $conf, $langs, $user;
867 
868  $error=0;
869 
870  $this->old_lastname = $obj->lastname;
871  $this->old_firstname = $obj->firstname;
872 
873  $this->db->begin();
874 
875  if (! $error)
876  {
877  // Get all rowid of element_contact linked to a type that is link to llx_socpeople
878  $sql = "SELECT ec.rowid";
879  $sql.= " FROM ".MAIN_DB_PREFIX."element_contact ec,";
880  $sql.= " ".MAIN_DB_PREFIX."c_type_contact tc";
881  $sql.= " WHERE ec.fk_socpeople=".$this->id;
882  $sql.= " AND ec.fk_c_type_contact=tc.rowid";
883  $sql.= " AND tc.source='external'";
884  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
885  $resql = $this->db->query($sql);
886  if ($resql)
887  {
888  $num=$this->db->num_rows($resql);
889 
890  $i=0;
891  while ($i < $num && ! $error)
892  {
893  $obj = $this->db->fetch_object($resql);
894 
895  $sqldel = "DELETE FROM ".MAIN_DB_PREFIX."element_contact";
896  $sqldel.=" WHERE rowid = ".$obj->rowid;
897  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
898  $result = $this->db->query($sqldel);
899  if (! $result)
900  {
901  $error++;
902  $this->error=$this->db->error().' sql='.$sqldel;
903  }
904 
905  $i++;
906  }
907  }
908  else
909  {
910  $error++;
911  $this->error=$this->db->error().' sql='.$sql;
912  }
913  }
914 
915  if (! $error)
916  {
917  // Remove category
918  $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_contact WHERE fk_socpeople = ".$this->id;
919  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
920  $resql=$this->db->query($sql);
921  if (! $resql)
922  {
923  $error++;
924  $this->error .= $this->db->lasterror();
925  $errorflag=-1;
926  }
927  }
928 
929  if (! $error)
930  {
931  $sql = "DELETE FROM ".MAIN_DB_PREFIX."socpeople";
932  $sql .= " WHERE rowid=".$this->id;
933  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
934  $result = $this->db->query($sql);
935  if (! $result)
936  {
937  $error++;
938  $this->error=$this->db->error().' sql='.$sql;
939  }
940  }
941 
942  // Removed extrafields
943  if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) { // For avoid conflicts if trigger used
944  $result=$this->deleteExtraFields($this);
945  if ($result < 0) $error++;
946  }
947 
948  if (! $error && ! $notrigger)
949  {
950  // Call trigger
951  $result=$this->call_trigger('CONTACT_DELETE',$user);
952  if ($result < 0) { $error++; }
953  // End call triggers
954  }
955 
956  if (! $error)
957  {
958 
959  $this->db->commit();
960  return 1;
961  }
962  else
963  {
964  $this->db->rollback();
965  dol_syslog("Error ".$this->error,LOG_ERR);
966  return -1;
967  }
968  }
969 
970 
977  function info($id)
978  {
979  $sql = "SELECT c.rowid, c.datec as datec, c.fk_user_creat,";
980  $sql.= " c.tms as tms, c.fk_user_modif";
981  $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c";
982  $sql.= " WHERE c.rowid = ".$this->db->escape($id);
983 
984  $resql=$this->db->query($sql);
985  if ($resql)
986  {
987  if ($this->db->num_rows($resql))
988  {
989  $obj = $this->db->fetch_object($resql);
990 
991  $this->id = $obj->rowid;
992 
993  if ($obj->fk_user_creat) {
994  $cuser = new User($this->db);
995  $cuser->fetch($obj->fk_user_creat);
996  $this->user_creation = $cuser;
997  }
998 
999  if ($obj->fk_user_modif) {
1000  $muser = new User($this->db);
1001  $muser->fetch($obj->fk_user_modif);
1002  $this->user_modification = $muser;
1003  }
1004 
1005  $this->date_creation = $this->db->jdate($obj->datec);
1006  $this->date_modification = $this->db->jdate($obj->tms);
1007  }
1008 
1009  $this->db->free($resql);
1010  }
1011  else
1012  {
1013  print $this->db->error();
1014  }
1015  }
1016 
1022  function getNbOfEMailings()
1023  {
1024  $sql = "SELECT count(mc.email) as nb";
1025  $sql.= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
1026  $sql.= " WHERE mc.email = '".$this->db->escape($this->email)."'";
1027  $sql.= " AND mc.statut NOT IN (-1,0)"; // -1 erreur, 0 non envoye, 1 envoye avec succes
1028 
1029  dol_syslog(get_class($this)."::getNbOfEMailings", LOG_DEBUG);
1030 
1031  $resql=$this->db->query($sql);
1032 
1033  if ($resql)
1034  {
1035  $obj = $this->db->fetch_object($resql);
1036  $nb=$obj->nb;
1037 
1038  $this->db->free($resql);
1039  return $nb;
1040  }
1041  else
1042  {
1043  $this->error=$this->db->error();
1044  return -1;
1045  }
1046  }
1047 
1059  function getNomUrl($withpicto=0, $option='', $maxlen=0, $moreparam='', $save_lastsearch_value=-1)
1060  {
1061  global $conf, $langs, $hookmanager;
1062 
1063  $result='';
1064 
1065  $label = '<u>' . $langs->trans("ShowContact") . '</u>';
1066  $label.= '<br><b>' . $langs->trans("Name") . ':</b> '.$this->getFullName($langs);
1067  //if ($this->civility_id) $label.= '<br><b>' . $langs->trans("Civility") . ':</b> '.$this->civility_id; // TODO Translate cibilty_id code
1068  if (! empty($this->poste)) $label.= '<br><b>' . $langs->trans("Poste") . ':</b> '.$this->poste;
1069  $label.= '<br><b>' . $langs->trans("EMail") . ':</b> '.$this->email;
1070  $phonelist=array();
1071  if ($this->phone_pro) $phonelist[]=$this->phone_pro;
1072  if ($this->phone_mobile) $phonelist[]=$this->phone_mobile;
1073  if ($this->phone_perso) $phonelist[]=$this->phone_perso;
1074  $label.= '<br><b>' . $langs->trans("Phone") . ':</b> '.join(', ',$phonelist);
1075  $label.= '<br><b>' . $langs->trans("Address") . ':</b> '.dol_format_address($this, 1, ' ', $langs);
1076 
1077  $url = DOL_URL_ROOT.'/contact/card.php?id='.$this->id;
1078 
1079  if ($option !== 'nolink')
1080  {
1081  // Add param to save lastsearch_values or not
1082  $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
1083  if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
1084  if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
1085  }
1086 
1087  $url .= $moreparam;
1088 
1089  $linkstart = '<a href="'.$url.'"';
1090  $linkclose="";
1091  if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
1092  {
1093  $label=$langs->trans("ShowContact");
1094  $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
1095  }
1096  $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"';
1097  $linkclose.= ' class="classfortooltip">';
1098 
1099  if (! is_object($hookmanager))
1100  {
1101  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
1102  $hookmanager=new HookManager($this->db);
1103  }
1104  $hookmanager->initHooks(array('contactdao'));
1105  $parameters=array('id'=>$this->id);
1106  $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
1107  if ($reshook > 0) $linkclose = $hookmanager->resPrint;
1108 
1109  $linkstart.=$linkclose;
1110  $linkend='</a>';
1111 
1112  if ($option == 'xxx')
1113  {
1114  $linkstart = '<a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$this->id.$moreparam.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
1115  $linkend='</a>';
1116  }
1117 
1118 
1119  $result.=$linkstart;
1120  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);
1121  if ($withpicto != 2) $result.=($maxlen?dol_trunc($this->getFullName($langs),$maxlen):$this->getFullName($langs));
1122  $result.=$linkend;
1123 
1124  return $result;
1125  }
1126 
1132  function getCivilityLabel()
1133  {
1134  global $langs;
1135  $langs->load("dict");
1136 
1137  $code=(! empty($this->civility_id)?$this->civility_id:(! empty($this->civilite_id)?$this->civilite_id:''));
1138  if (empty($code)) return '';
1139  return $langs->getLabelFromKey($this->db, "Civility".$code, "c_civility", "code", "label", $code);
1140  }
1141 
1148  function getLibStatut($mode)
1149  {
1150  return $this->LibStatut($this->statut,$mode);
1151  }
1152 
1160  function LibStatut($statut,$mode)
1161  {
1162  global $langs;
1163 
1164  if ($mode == 0)
1165  {
1166  if ($statut==0 || $statut==5) return $langs->trans('Disabled');
1167  elseif ($statut==1 || $statut==4) return $langs->trans('Enabled');
1168  }
1169  elseif ($mode == 1)
1170  {
1171  if ($statut==0 || $statut==5) return $langs->trans('Disabled');
1172  elseif ($statut==1 || $statut==4) return $langs->trans('Enabled');
1173  }
1174  elseif ($mode == 2)
1175  {
1176  if ($statut==0 || $statut==5) return img_picto($langs->trans('Disabled'),'statut5', 'class="pictostatus"').' '.$langs->trans('Disabled');
1177  elseif ($statut==1 || $statut==4) return img_picto($langs->trans('Enabled'),'statut4', 'class="pictostatus"').' '.$langs->trans('Enabled');
1178 
1179  }
1180  elseif ($mode == 3)
1181  {
1182  if ($statut==0 || $statut==5) return img_picto($langs->trans('Disabled'),'statut5', 'class="pictostatus"');
1183  elseif ($statut==1 || $statut==4) return img_picto($langs->trans('Enabled'),'statut4', 'class="pictostatus"');
1184  }
1185  elseif ($mode == 4)
1186  {
1187  if ($statut==0) return img_picto($langs->trans('Disabled'),'statut5', 'class="pictostatus"').' '.$langs->trans('Disabled');
1188  elseif ($statut==1 || $statut==4) return img_picto($langs->trans('Enabled'),'statut4', 'class="pictostatus"').' '.$langs->trans('Enabled');
1189  }
1190  elseif ($mode == 5)
1191  {
1192  if ($statut==0 || $statut==5) return '<span class="hideonsmartphone">'.$langs->trans('Disabled').' </span>'.img_picto($langs->trans('Disabled'),'statut5', 'class="pictostatus"');
1193  elseif ($statut==1 || $statut==4) return '<span class="hideonsmartphone">'.$langs->trans('Enabled').' </span>'.img_picto($langs->trans('Enabled'),'statut4', 'class="pictostatus"');
1194  }
1195  }
1196 
1197 
1204  function LibPubPriv($statut)
1205  {
1206  global $langs;
1207  if ($statut=='1') return $langs->trans('ContactPrivate');
1208  else return $langs->trans('ContactPublic');
1209  }
1210 
1211 
1219  function initAsSpecimen()
1220  {
1221  // Get first id of existing company and save it into $socid
1222  $socid = 0;
1223  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe ORDER BY rowid LIMIT 1";
1224  $resql = $this->db->query($sql);
1225  if ($resql)
1226  {
1227  $obj = $this->db->fetch_object($resql);
1228  if ($obj) $socid=$obj->rowid;
1229  }
1230 
1231  // Initialise parameters
1232  $this->id=0;
1233  $this->specimen=1;
1234  $this->lastname = 'DOLIBARR';
1235  $this->firstname = 'SPECIMEN';
1236  $this->address = '21 jump street';
1237  $this->zip = '99999';
1238  $this->town = 'MyTown';
1239  $this->country_id = 1;
1240  $this->country_code = 'FR';
1241  $this->country = 'France';
1242  $this->email = 'specimen@specimen.com';
1243  $this->skype = 'tom.hanson';
1244 
1245  $this->phone_pro = '0909090901';
1246  $this->phone_perso = '0909090902';
1247  $this->phone_mobile = '0909090903';
1248  $this->fax = '0909090909';
1249 
1250  $this->note_public='This is a comment (public)';
1251  $this->note_private='This is a comment (private)';
1252 
1253  $this->socid = $socid;
1254  $this->statut=1;
1255  }
1256 
1263  function setstatus($statut)
1264  {
1265  global $conf,$langs,$user;
1266 
1267  $error=0;
1268 
1269  // Check parameters
1270  if ($this->statut == $statut) return 0;
1271  else $this->statut = $statut;
1272 
1273  $this->db->begin();
1274 
1275  // Desactive utilisateur
1276  $sql = "UPDATE ".MAIN_DB_PREFIX."socpeople";
1277  $sql.= " SET statut = ".$this->statut;
1278  $sql.= " WHERE rowid = ".$this->id;
1279  $result = $this->db->query($sql);
1280 
1281  dol_syslog(get_class($this)."::setstatus", LOG_DEBUG);
1282  if ($result)
1283  {
1284  // Call trigger
1285  $result=$this->call_trigger('CONTACT_ENABLEDISABLE',$user);
1286  if ($result < 0) { $error++; }
1287  // End call triggers
1288  }
1289 
1290  if ($error)
1291  {
1292  $this->db->rollback();
1293  return -$error;
1294  }
1295  else
1296  {
1297  $this->db->commit();
1298  return 1;
1299  }
1300  }
1301 
1311  public function setCategories($categories)
1312  {
1313  // Handle single category
1314  if (!is_array($categories)) {
1315  $categories = array($categories);
1316  }
1317 
1318  // Get current categories
1319  require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
1320  $c = new Categorie($this->db);
1321  $existing = $c->containing($this->id, Categorie::TYPE_CONTACT, 'id');
1322 
1323  // Diff
1324  if (is_array($existing)) {
1325  $to_del = array_diff($existing, $categories);
1326  $to_add = array_diff($categories, $existing);
1327  } else {
1328  $to_del = array(); // Nothing to delete
1329  $to_add = $categories;
1330  }
1331 
1332  // Process
1333  foreach ($to_del as $del) {
1334  if ($c->fetch($del) > 0) {
1335  $c->del_type($this, 'contact');
1336  }
1337  }
1338  foreach ($to_add as $add) {
1339  if ($c->fetch($add) > 0) {
1340  $c->add_type($this, 'contact');
1341  }
1342  }
1343 
1344  return;
1345  }
1346 
1355  public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
1356  {
1357  $tables = array(
1358  'socpeople'
1359  );
1360 
1361  return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
1362  }
1363 }
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
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.
update_perso($id, $user=null, $notrigger=0)
Update field alert birthday.
create($user)
Add a contact into database.
Class to manage contact/addresses.
Class to manage Dolibarr users.
Definition: user.class.php:39
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...
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+' '+name+' '+lastname)
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.
Class to manage standard extra fields.
Class to manage hooks.
fetch($id, $user=0, $ref_ext='')
Load object contact.
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'un statut donne.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
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'annuaire LDAP pour l'objet.
getEntity($element, $shared=1, $forceentity=null)
Get list of entity id to use.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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...
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:104
setstatus($statut)
Change status of a user.
_load_ldap_info()
Initialise tableau info (tableau des attributs LDAP)
print
Draft customers invoices.
Definition: index.php:91
getCivilityLabel()
Return civility label of contact.
getNomUrl($withpicto=0, $option='', $maxlen=0, $moreparam='', $save_lastsearch_value=-1)
Return name of contact with link (and eventually picto) Use $this->id, $this->lastname, $this->firstname, this->civility_id.
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:1013
call_trigger($trigger_name, $user)
Call trigger based on this instance.
initAsSpecimen()
Initialise an instance with random values.
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, ...)
getLibStatut($mode)
Return label of contact status.