dolibarr  7.0.0-beta
adherent.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org>
4  * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
5  * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
6  * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
7  * Copyright (C) 2009-2017 Regis Houssin <regis.houssin@capnetworks.com>
8  * Copyright (C) 2014-2016 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
9  * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
10  * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
11  * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
12  * Copyright (C) 2016 Juanjo Menent <jmenent@2byte.es>
13  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program. If not, see <http://www.gnu.org/licenses/>.
26  */
27 
34 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
36 require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
37 
38 
42 class Adherent extends CommonObject
43 {
44  public $element='member';
45  public $table_element='adherent';
46  public $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
47 
48  var $mesgs;
49 
50  var $login;
51 
53  var $pass;
58 
59  var $societe;
60  var $company;
61  var $address;
62  var $zip;
63  var $town;
64 
65  var $state_id; // Id of department
66  var $state_code; // Code of department
67  var $state; // Label of department
68 
69  var $email;
70  var $skype;
71  var $phone;
72  var $phone_perso;
73  var $phone_mobile;
74 
75  var $morphy;
76  var $public;
77  var $statut; // -1:brouillon, 0:resilie, >=1:valide,paye
78  var $photo;
79 
80  var $datec;
81  var $datem;
82  var $datefin;
83  var $datevalid;
84  var $birth;
85 
86  var $note_public;
87  var $note_private;
88 
89  var $typeid; // Id type adherent
90  var $type; // Libelle type adherent
91  var $need_subscription;
92 
93  var $user_id;
94  var $user_login;
95 
96  var $fk_soc;
97 
98  // Fields loaded by fetch_subscriptions()
99  var $first_subscription_date;
100  var $first_subscription_amount;
101  var $last_subscription_date;
102  var $last_subscription_date_start;
103  var $last_subscription_date_end;
104  var $last_subscription_amount;
105  var $subscriptions=array();
106 
107  var $oldcopy; // To contains a clone of this when we need to save old properties of object
108 
109  public $entity;
110 
116  function __construct($db)
117  {
118  $this->db = $db;
119  $this->statut = -1;
120  // l'adherent n'est pas public par defaut
121  $this->public = 0;
122  // les champs optionnels sont vides
123  $this->array_options=array();
124  }
125 
126 
142  function send_an_email($text, $subject, $filename_list=array(), $mimetype_list=array(), $mimefilename_list=array(), $addr_cc="", $addr_bcc="", $deliveryreceipt=0, $msgishtml=-1, $errors_to='')
143  {
144  global $conf,$langs;
145 
146  // Detect if message is HTML
147  if ($msgishtml == -1)
148  {
149  $msgishtml = 0;
150  if (dol_textishtml($text,1)) $msgishtml = 1;
151  }
152 
153  $texttosend=$this->makeSubstitution($text);
154  $subjecttosend=$this->makeSubstitution($subject);
155  if ($msgishtml) $texttosend=dol_htmlentitiesbr($texttosend);
156 
157  // Envoi mail confirmation
158  $from=$conf->email_from;
159  if (! empty($conf->global->ADHERENT_MAIL_FROM)) $from=$conf->global->ADHERENT_MAIL_FROM;
160 
161  // Send email (substitutionarray must be done just before this)
162  include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
163  $mailfile = new CMailFile($subjecttosend, $this->email, $from, $texttosend, $filename_list, $mimetype_list, $mimefilename_list, $addr_cc, $addr_bcc, $deliveryreceipt, $msgishtml);
164  if ($mailfile->sendfile())
165  {
166  return 1;
167  }
168  else
169  {
170  $this->error=$langs->trans("ErrorFailedToSendMail",$from,$this->email).'. '.$mailfile->error;
171  return -1;
172  }
173  }
174 
175 
182  function makeSubstitution($text)
183  {
184  global $conf,$langs;
185 
186  $birthday = dol_print_date($this->birth,'day');
187 
188  $msgishtml = 0;
189  if (dol_textishtml($text,1)) $msgishtml = 1;
190 
191  $infos='';
192  if ($this->civility_id) $infos.= $langs->transnoentities("UserTitle").": ".$this->getCivilityLabel()."\n";
193  $infos.= $langs->transnoentities("id").": ".$this->id."\n";
194  $infos.= $langs->transnoentities("Lastname").": ".$this->lastname."\n";
195  $infos.= $langs->transnoentities("Firstname").": ".$this->firstname."\n";
196  $infos.= $langs->transnoentities("Company").": ".$this->societe."\n";
197  $infos.= $langs->transnoentities("Address").": ".$this->address."\n";
198  $infos.= $langs->transnoentities("Zip").": ".$this->zip."\n";
199  $infos.= $langs->transnoentities("Town").": ".$this->town."\n";
200  $infos.= $langs->transnoentities("Country").": ".$this->country."\n";
201  $infos.= $langs->transnoentities("EMail").": ".$this->email."\n";
202  $infos.= $langs->transnoentities("PhonePro").": ".$this->phone."\n";
203  $infos.= $langs->transnoentities("PhonePerso").": ".$this->phone_perso."\n";
204  $infos.= $langs->transnoentities("PhoneMobile").": ".$this->phone_mobile."\n";
205  if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED))
206  {
207  $infos.= $langs->transnoentities("Login").": ".$this->login."\n";
208  $infos.= $langs->transnoentities("Password").": ".$this->pass."\n";
209  }
210  $infos.= $langs->transnoentities("Birthday").": ".$birthday."\n";
211  $infos.= $langs->transnoentities("Photo").": ".$this->photo."\n";
212  $infos.= $langs->transnoentities("Public").": ".yn($this->public);
213 
214  // Substitutions
215  $substitutionarray=array(
216  '__CIVILITY__'=>$this->getCivilityLabel(),
217  '__FIRSTNAME__'=>$msgishtml?dol_htmlentitiesbr($this->firstname):$this->firstname,
218  '__LASTNAME__'=>$msgishtml?dol_htmlentitiesbr($this->lastname):$this->lastname,
219  '__FULLNAME__'=>$msgishtml?dol_htmlentitiesbr($this->getFullName($langs)):$this->getFullName($langs),
220  '__COMPANY__'=>$msgishtml?dol_htmlentitiesbr($this->societe):$this->societe,
221  '__ADDRESS__'=>$msgishtml?dol_htmlentitiesbr($this->address):$this->address,
222  '__ZIP__'=>$msgishtml?dol_htmlentitiesbr($this->zip):$this->zip,
223  '__TOWN__'=>$msgishtml?dol_htmlentitiesbr($this->town):$this->town,
224  '__COUNTRY__'=>$msgishtml?dol_htmlentitiesbr($this->country):$this->country,
225  '__EMAIL__'=>$msgishtml?dol_htmlentitiesbr($this->email):$this->email,
226  '__BIRTH__'=>$msgishtml?dol_htmlentitiesbr($birthday):$birthday,
227  '__PHOTO__'=>$msgishtml?dol_htmlentitiesbr($this->photo):$this->photo,
228  '__LOGIN__'=>$msgishtml?dol_htmlentitiesbr($this->login):$this->login,
229  '__PASSWORD__'=>$msgishtml?dol_htmlentitiesbr($this->pass):$this->pass,
230  '__PHONE__'=>$msgishtml?dol_htmlentitiesbr($this->phone):$this->phone,
231  '__PHONEPRO__'=>$msgishtml?dol_htmlentitiesbr($this->phone_perso):$this->phone_perso,
232  '__PHONEMOBILE__'=>$msgishtml?dol_htmlentitiesbr($this->phone_mobile):$this->phone_mobile,
233  );
234 
235  complete_substitutions_array($substitutionarray, $langs, $this);
236 
237  return make_substitutions($text, $substitutionarray, $langs);
238  }
239 
240 
247  function getmorphylib($morphy='')
248  {
249  global $langs;
250  if (! $morphy) { $morphy=$this->morphy; }
251  if ($morphy == 'phy') { return $langs->trans("Physical"); }
252  if ($morphy == 'mor') { return $langs->trans("Moral"); }
253  return $morphy;
254  }
255 
263  function create($user,$notrigger=0)
264  {
265  global $conf,$langs;
266 
267  $error=0;
268 
269  $now=dol_now();
270 
271  // Clean parameters
272  $this->import_key = trim($this->import_key);
273 
274  // Check parameters
275  if (! empty($conf->global->ADHERENT_MAIL_REQUIRED) && ! isValidEMail($this->email))
276  {
277  $langs->load("errors");
278  $this->error = $langs->trans("ErrorBadEMail",$this->email);
279  return -1;
280  }
281  if (! $this->datec) $this->datec=$now;
282  if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED))
283  {
284  if (empty($this->login))
285  {
286  $this->error = $langs->trans("ErrorWrongValueForParameterX","Login");
287  return -1;
288  }
289  }
290 
291  $this->db->begin();
292 
293  // Insert member
294  $sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent";
295  $sql.= " (datec,login,fk_user_author,fk_user_mod,fk_user_valid,morphy,fk_adherent_type,entity,import_key)";
296  $sql.= " VALUES (";
297  $sql.= " '".$this->db->idate($this->datec)."'";
298  $sql.= ", ".($this->login?"'".$this->db->escape($this->login)."'":"null");
299  $sql.= ", ".($user->id>0?$user->id:"null"); // Can be null because member can be created by a guest or a script
300  $sql.= ", null, null, '".$this->db->escape($this->morphy)."'";
301  $sql.= ", ".$this->typeid;
302  $sql.= ", ".$conf->entity;
303  $sql.= ", ".(! empty($this->import_key) ? "'".$this->db->escape($this->import_key)."'":"null");
304  $sql.= ")";
305 
306  dol_syslog(get_class($this)."::create", LOG_DEBUG);
307  $result = $this->db->query($sql);
308  if ($result)
309  {
310  $id = $this->db->last_insert_id(MAIN_DB_PREFIX."adherent");
311  if ($id > 0)
312  {
313  $this->id=$id;
314  $this->ref=(string) $id;
315 
316  // Update minor fields
317  $result=$this->update($user,1,1,0,0,'add'); // nosync is 1 to avoid update data of user
318  if ($result < 0)
319  {
320  $this->db->rollback();
321  return -1;
322  }
323 
324  // Add link to user
325  if ($this->user_id)
326  {
327  // Add link to user
328  $sql = "UPDATE ".MAIN_DB_PREFIX."user SET";
329  $sql.= " fk_member = ".$this->id;
330  $sql.= " WHERE rowid = ".$this->user_id;
331  dol_syslog(get_class($this)."::create", LOG_DEBUG);
332  $resql = $this->db->query($sql);
333  if (! $resql)
334  {
335  $this->error='Failed to update user to make link with member';
336  $this->db->rollback();
337  return -4;
338  }
339  }
340 
341  if (! $notrigger)
342  {
343  // Call trigger
344  $result=$this->call_trigger('MEMBER_CREATE',$user);
345  if ($result < 0) { $error++; }
346  // End call triggers
347  }
348 
349  if (count($this->errors))
350  {
351  dol_syslog(get_class($this)."::create ".implode(',',$this->errors), LOG_ERR);
352  $this->db->rollback();
353  return -3;
354  }
355  else
356  {
357  $this->db->commit();
358  return $this->id;
359  }
360  }
361  else
362  {
363  $this->error='Failed to get last insert id';
364  dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
365  $this->db->rollback();
366  return -2;
367  }
368  }
369  else
370  {
371  $this->error=$this->db->error();
372  $this->db->rollback();
373  return -1;
374  }
375  }
376 
377 
389  function update($user,$notrigger=0,$nosyncuser=0,$nosyncuserpass=0,$nosyncthirdparty=0,$action='update')
390  {
391  global $conf, $langs, $hookmanager;
392 
393  $nbrowsaffected=0;
394  $error=0;
395 
396  dol_syslog(get_class($this)."::update notrigger=".$notrigger.", nosyncuser=".$nosyncuser.", nosyncuserpass=".$nosyncuserpass." nosyncthirdparty=".$nosyncthirdparty.", email=".$this->email);
397 
398  // Clean parameters
399  $this->lastname=trim($this->lastname)?trim($this->lastname):trim($this->lastname);
400  $this->firstname=trim($this->firstname)?trim($this->firstname):trim($this->firstname);
401  $this->address=($this->address?$this->address:$this->address);
402  $this->zip=($this->zip?$this->zip:$this->zip);
403  $this->town=($this->town?$this->town:$this->town);
404  $this->country_id=($this->country_id > 0?$this->country_id:$this->country_id);
405  $this->state_id=($this->state_id > 0?$this->state_id:$this->state_id);
406  if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->lastname=ucwords(trim($this->lastname));
407  if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->firstname=ucwords(trim($this->firstname));
408  $this->note_public=($this->note_public?$this->note_public:$this->note_public);
409  $this->note_private=($this->note_private?$this->note_private:$this->note_private);
410 
411  // Check parameters
412  if (! empty($conf->global->ADHERENT_MAIL_REQUIRED) && ! isValidEMail($this->email))
413  {
414  $langs->load("errors");
415  $this->error = $langs->trans("ErrorBadEMail",$this->email);
416  return -1;
417  }
418 
419  $this->db->begin();
420 
421  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
422  $sql.= " civility = ".($this->civility_id?"'".$this->db->escape($this->civility_id)."'":"null");
423  $sql.= ", firstname = ".($this->firstname?"'".$this->db->escape($this->firstname)."'":"null");
424  $sql.= ", lastname = ".($this->lastname?"'".$this->db->escape($this->lastname)."'":"null");
425  $sql.= ", login = ".($this->login?"'".$this->db->escape($this->login)."'":"null");
426  $sql.= ", societe = ".($this->societe?"'".$this->db->escape($this->societe)."'":"null");
427  $sql.= ", fk_soc = ".($this->fk_soc > 0?$this->db->escape($this->fk_soc):"null");
428  $sql.= ", address = ".($this->address?"'".$this->db->escape($this->address)."'":"null");
429  $sql.= ", zip = ".($this->zip?"'".$this->db->escape($this->zip)."'":"null");
430  $sql.= ", town = ".($this->town?"'".$this->db->escape($this->town)."'":"null");
431  $sql.= ", country = ".($this->country_id>0?$this->db->escape($this->country_id):"null");
432  $sql.= ", state_id = ".($this->state_id>0?$this->db->escape($this->state_id):"null");
433  $sql.= ", email = '".$this->db->escape($this->email)."'";
434  $sql.= ", skype = '".$this->db->escape($this->skype)."'";
435  $sql.= ", phone = ".($this->phone?"'".$this->db->escape($this->phone)."'":"null");
436  $sql.= ", phone_perso = ".($this->phone_perso?"'".$this->db->escape($this->phone_perso)."'":"null");
437  $sql.= ", phone_mobile = ".($this->phone_mobile?"'".$this->db->escape($this->phone_mobile)."'":"null");
438  $sql.= ", note_private = ".($this->note_private?"'".$this->db->escape($this->note_private)."'":"null");
439  $sql.= ", note_public = ".($this->note_public?"'".$this->db->escape($this->note_public)."'":"null");
440  $sql.= ", photo = ".($this->photo?"'".$this->db->escape($this->photo)."'":"null");
441  $sql.= ", public = '".$this->db->escape($this->public)."'";
442  $sql.= ", statut = ".$this->statut;
443  $sql.= ", fk_adherent_type = ".$this->typeid;
444  $sql.= ", morphy = '".$this->db->escape($this->morphy)."'";
445  $sql.= ", birth = ".($this->birth?"'".$this->db->idate($this->birth)."'":"null");
446  if ($this->datefin) $sql.= ", datefin = '".$this->db->idate($this->datefin)."'"; // Must be modified only when deleting a subscription
447  if ($this->datevalid) $sql.= ", datevalid = '".$this->db->idate($this->datevalid)."'"; // Must be modified only when validating a member
448  $sql.= ", fk_user_mod = ".($user->id>0?$user->id:'null'); // Can be null because member can be create by a guest
449  $sql.= " WHERE rowid = ".$this->id;
450 
451  dol_syslog(get_class($this)."::update update member", LOG_DEBUG);
452  $resql = $this->db->query($sql);
453  if ($resql)
454  {
455  unset($this->country_code);
456  unset($this->country);
457  unset($this->state_code);
458  unset($this->state);
459 
460  $nbrowsaffected+=$this->db->affected_rows($resql);
461 
462  $action='update';
463 
464  // Actions on extra fields (by external module)
465  // TODO le hook fait double emploi avec le trigger !!
466  $hookmanager->initHooks(array('memberdao'));
467  $parameters=array('id'=>$this->id);
468  $action='';
469  $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
470  if (empty($reshook))
471  {
472  if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
473  {
474  $result=$this->insertExtraFields();
475  if ($result < 0)
476  {
477  $error++;
478  }
479  }
480  }
481  else if ($reshook < 0) $error++;
482 
483  // Update password
484  if (! $error && $this->pass)
485  {
486  dol_syslog(get_class($this)."::update update password");
487  if ($this->pass != $this->pass_indatabase && $this->pass != $this->pass_indatabase_crypted)
488  {
489  $isencrypted = empty($conf->global->DATABASE_PWD_ENCRYPTED)?0:1;
490 
491  // If password to set differs from the one found into database
492  $result=$this->setPassword($user,$this->pass,$isencrypted,$notrigger,$nosyncuserpass);
493  if (! $nbrowsaffected) $nbrowsaffected++;
494  }
495  }
496 
497  // Remove links to user and replace with new one
498  if (! $error)
499  {
500  dol_syslog(get_class($this)."::update update link to user");
501  $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = NULL WHERE fk_member = ".$this->id;
502  dol_syslog(get_class($this)."::update", LOG_DEBUG);
503  $resql = $this->db->query($sql);
504  if (! $resql) { $this->error=$this->db->error(); $this->db->rollback(); return -5; }
505  // If there is a user linked to this member
506  if ($this->user_id > 0)
507  {
508  $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = ".$this->id." WHERE rowid = ".$this->user_id;
509  dol_syslog(get_class($this)."::update", LOG_DEBUG);
510  $resql = $this->db->query($sql);
511  if (! $resql) { $this->error=$this->db->error(); $this->db->rollback(); return -5; }
512  }
513  }
514 
515  if (! $error && $nbrowsaffected) // If something has change in main data
516  {
517  // Update information on linked user if it is an update
518  if (! $error && $this->user_id > 0 && ! $nosyncuser)
519  {
520  require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
521 
522  dol_syslog(get_class($this)."::update update linked user");
523 
524  $luser=new User($this->db);
525  $result=$luser->fetch($this->user_id);
526 
527  if ($result >= 0)
528  {
529  //var_dump($this->user_login);exit;
530  //var_dump($this->login);exit;
531  $luser->login=$this->login;
532  $luser->civility_id=$this->civility_id;
533  $luser->firstname=$this->firstname;
534  $luser->lastname=$this->lastname;
535  $luser->pass=$this->pass;
536  $luser->societe_id=$this->societe;
537 
538  $luser->email=$this->email;
539  $luser->skype=$this->skype;
540  $luser->office_phone=$this->phone;
541  $luser->user_mobile=$this->phone_mobile;
542 
543  $luser->fk_member=$this->id;
544 
545  $result=$luser->update($user,0,1,1); // Use nosync to 1 to avoid cyclic updates
546  if ($result < 0)
547  {
548  $this->error=$luser->error;
549  dol_syslog(get_class($this)."::update ".$this->error,LOG_ERR);
550  $error++;
551  }
552  }
553  else
554  {
555  $this->error=$luser->error;
556  $error++;
557  }
558  }
559 
560  // Update information on linked thirdparty if it is an update
561  if (! $error && $this->fk_soc > 0 && ! $nosyncthirdparty)
562  {
563  require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
564 
565  dol_syslog(get_class($this)."::update update linked thirdparty");
566 
567  // This member is linked with a thirdparty, so we also update thirdparty informations
568  // if this is an update.
569  $lthirdparty=new Societe($this->db);
570  $result=$lthirdparty->fetch($this->fk_soc);
571 
572  if ($result >= 0)
573  {
574  $lthirdparty->address=$this->address;
575  $lthirdparty->zip=$this->zip;
576  $lthirdparty->town=$this->town;
577  $lthirdparty->email=$this->email;
578  $lthirdparty->skype=$this->skype;
579  $lthirdparty->phone=$this->phone;
580  $lthirdparty->state_id=$this->state_id;
581  $lthirdparty->country_id=$this->country_id;
582  $lthirdparty->country_id=$this->country_id;
583  //$lthirdparty->phone_mobile=$this->phone_mobile;
584 
585  $result=$lthirdparty->update($this->fk_soc,$user,0,1,1,'update'); // Use sync to 0 to avoid cyclic updates
586  if ($result < 0)
587  {
588  $this->error=$lthirdparty->error;
589  dol_syslog(get_class($this)."::update ".$this->error,LOG_ERR);
590  $error++;
591  }
592  }
593  else
594  {
595  $this->error=$lthirdparty->error;
596  $error++;
597  }
598  }
599 
600  if (! $error && ! $notrigger)
601  {
602  // Call trigger
603  $result=$this->call_trigger('MEMBER_MODIFY',$user);
604  if ($result < 0) { $error++; }
605  // End call triggers
606  }
607  }
608 
609  if (! $error)
610  {
611  $this->db->commit();
612  return $nbrowsaffected;
613  }
614  else
615  {
616  $this->db->rollback();
617  return -1;
618  }
619  }
620  else
621  {
622  $this->db->rollback();
623  $this->error=$this->db->lasterror();
624  return -2;
625  }
626  }
627 
628 
636  function update_end_date($user)
637  {
638  $this->db->begin();
639 
640  // Search for last subscription id and end date
641  $sql = "SELECT rowid, datec as dateop, dateadh as datedeb, datef as datefin";
642  $sql.= " FROM ".MAIN_DB_PREFIX."subscription";
643  $sql.= " WHERE fk_adherent=".$this->id;
644  $sql.= " ORDER by dateadh DESC"; // Sort by start subscription date
645 
646  dol_syslog(get_class($this)."::update_end_date", LOG_DEBUG);
647  $resql=$this->db->query($sql);
648  if ($resql)
649  {
650  $obj=$this->db->fetch_object($resql);
651  $dateop=$this->db->jdate($obj->dateop);
652  $datedeb=$this->db->jdate($obj->datedeb);
653  $datefin=$this->db->jdate($obj->datefin);
654 
655  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
656  $sql.= " datefin=".($datefin != '' ? "'".$this->db->idate($datefin)."'" : "null");
657  $sql.= " WHERE rowid = ".$this->id;
658 
659  dol_syslog(get_class($this)."::update_end_date", LOG_DEBUG);
660  $resql=$this->db->query($sql);
661  if ($resql)
662  {
663  $this->last_subscription_date=$dateop;
664  $this->last_subscription_date_start=$datedeb;
665  $this->last_subscription_date_end=$datefin;
666  $this->datefin=$datefin;
667  $this->db->commit();
668  return 1;
669  }
670  else
671  {
672  $this->db->rollback();
673  return -1;
674  }
675  }
676  else
677  {
678  $this->error=$this->db->lasterror();
679  $this->db->rollback();
680  return -1;
681  }
682 
683  }
684 
693  function delete($rowid, $user, $notrigger=0)
694  {
695  global $conf, $langs;
696 
697  $result = 0;
698  $error=0;
699  $errorflag=0;
700 
701  // Check parameters
702  if (empty($rowid)) $rowid=$this->id;
703 
704  $this->db->begin();
705 
706  if (! $error && ! $notrigger)
707  {
708  // Call trigger
709  $result=$this->call_trigger('MEMBER_DELETE',$user);
710  if ($result < 0) $error++;
711  // End call triggers
712  }
713 
714  // Remove category
715  $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_member WHERE fk_member = ".$rowid;
716  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
717  $resql=$this->db->query($sql);
718  if (! $resql)
719  {
720  $error++;
721  $this->error .= $this->db->lasterror();
722  $errorflag=-1;
723  }
724 
725  // Remove subscription
726  if (! $error)
727  {
728  $sql = "DELETE FROM ".MAIN_DB_PREFIX."subscription WHERE fk_adherent = ".$rowid;
729  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
730  $resql=$this->db->query($sql);
731  if (! $resql)
732  {
733  $error++;
734  $this->error .= $this->db->lasterror();
735  $errorflag=-2;
736  }
737  }
738 
739  // Remove linked user
740  if (! $error)
741  {
742  $ret=$this->setUserId(0);
743  if ($ret < 0)
744  {
745  $error++;
746  $this->error .= $this->db->lasterror();
747  $errorflag=-3;
748  }
749  }
750 
751  // Removed extrafields
752  if (! $error)
753  {
754  if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
755  {
756  $result=$this->deleteExtraFields();
757  if ($result < 0)
758  {
759  $error++;
760  $errorflag=-4;
761  dol_syslog(get_class($this)."::delete erreur ".$errorflag." ".$this->error, LOG_ERR);
762  }
763  }
764  }
765 
766  // Remove adherent
767  if (! $error)
768  {
769  $sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent WHERE rowid = ".$rowid;
770  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
771  $resql=$this->db->query($sql);
772  if (! $resql)
773  {
774  $error++;
775  $this->error .= $this->db->lasterror();
776  $errorflag=-5;
777  }
778  }
779 
780  if (! $error)
781  {
782  $this->db->commit();
783  return 1;
784  }
785  else
786  {
787  $this->db->rollback();
788  return $errorflag;
789  }
790  }
791 
792 
803  function setPassword($user, $password='', $isencrypted=0, $notrigger=0, $nosyncuser=0)
804  {
805  global $conf, $langs;
806 
807  $error=0;
808 
809  dol_syslog(get_class($this)."::setPassword user=".$user->id." password=".preg_replace('/./i','*',$password)." isencrypted=".$isencrypted);
810 
811  // If new password not provided, we generate one
812  if (! $password)
813  {
814  require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
815  $password=getRandomPassword(false);
816  }
817 
818  // Crypt password
819  $password_crypted = dol_hash($password);
820 
821  $password_indatabase = '';
822  if (! $isencrypted)
823  {
824  $password_indatabase = $password;
825  }
826 
827  $this->db->begin();
828 
829  // Mise a jour
830  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent";
831  $sql.= " SET pass_crypted = '".$this->db->escape($password_crypted)."'";
832  //if (! empty($conf->global->DATABASE_PWD_ENCRYPTED))
833  if ($isencrypted)
834  {
835  $sql.= ", pass = null";
836  }
837  else
838  {
839  $sql.= ", pass = '".$this->db->escape($password_indatabase)."'";
840  }
841  $sql.= " WHERE rowid = ".$this->id;
842 
843  //dol_syslog("Adherent::Password sql=hidden");
844  dol_syslog(get_class($this)."::setPassword", LOG_DEBUG);
845  $result = $this->db->query($sql);
846  if ($result)
847  {
848  $nbaffectedrows=$this->db->affected_rows($result);
849 
850  if ($nbaffectedrows)
851  {
852  $this->pass=$password;
853  $this->pass_indatabase=$password_indatabase;
854  $this->pass_indatabase_crypted=$password_crypted;
855 
856  if ($this->user_id && ! $nosyncuser)
857  {
858  require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
859 
860  // This member is linked with a user, so we also update users informations
861  // if this is an update.
862  $luser=new User($this->db);
863  $result=$luser->fetch($this->user_id);
864 
865  if ($result >= 0)
866  {
867  $result=$luser->setPassword($user,$this->pass,0,0,1);
868  if ($result < 0)
869  {
870  $this->error=$luser->error;
871  dol_syslog(get_class($this)."::setPassword ".$this->error,LOG_ERR);
872  $error++;
873  }
874  }
875  else
876  {
877  $this->error=$luser->error;
878  $error++;
879  }
880  }
881 
882  if (! $error && ! $notrigger)
883  {
884  // Call trigger
885  $result=$this->call_trigger('MEMBER_NEW_PASSWORD',$user);
886  if ($result < 0) { $error++; $this->db->rollback(); return -1; }
887  // End call triggers
888  }
889 
890  $this->db->commit();
891  return $this->pass;
892  }
893  else
894  {
895  $this->db->rollback();
896  return 0;
897  }
898  }
899  else
900  {
901  $this->db->rollback();
902  dol_print_error($this->db);
903  return -1;
904  }
905  }
906 
907 
914  function setUserId($userid)
915  {
916  global $conf, $langs;
917 
918  $this->db->begin();
919 
920  // If user is linked to this member, remove old link to this member
921  $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = NULL WHERE fk_member = ".$this->id;
922  dol_syslog(get_class($this)."::setUserId", LOG_DEBUG);
923  $resql = $this->db->query($sql);
924  if (! $resql) { $this->error=$this->db->error(); $this->db->rollback(); return -1; }
925 
926  // Set link to user
927  if ($userid > 0)
928  {
929  $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = ".$this->id;
930  $sql.= " WHERE rowid = ".$userid;
931  dol_syslog(get_class($this)."::setUserId", LOG_DEBUG);
932  $resql = $this->db->query($sql);
933  if (! $resql) { $this->error=$this->db->error(); $this->db->rollback(); return -2; }
934  }
935 
936  $this->db->commit();
937 
938  return 1;
939  }
940 
941 
948  function setThirdPartyId($thirdpartyid)
949  {
950  global $conf, $langs;
951 
952  $this->db->begin();
953 
954  // Remove link to third party onto any other members
955  if ($thirdpartyid > 0)
956  {
957  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET fk_soc = null";
958  $sql.= " WHERE fk_soc = '".$thirdpartyid."'";
959  $sql.= " AND entity = ".$conf->entity;
960  dol_syslog(get_class($this)."::setThirdPartyId", LOG_DEBUG);
961  $resql = $this->db->query($sql);
962  }
963 
964  // Add link to third party for current member
965  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET fk_soc = ".($thirdpartyid>0 ? $thirdpartyid : 'null');
966  $sql.= " WHERE rowid = ".$this->id;
967 
968  dol_syslog(get_class($this)."::setThirdPartyId", LOG_DEBUG);
969  $resql = $this->db->query($sql);
970  if ($resql)
971  {
972  $this->db->commit();
973  return 1;
974  }
975  else
976  {
977  $this->error=$this->db->error();
978  $this->db->rollback();
979  return -1;
980  }
981  }
982 
983 
990  function fetch_login($login)
991  {
992  global $conf;
993 
994  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."adherent";
995  $sql.= " WHERE login='".$this->db->escape($login)."'";
996  $sql.= " AND entity = ".$conf->entity;
997 
998  $resql=$this->db->query($sql);
999  if ($resql)
1000  {
1001  if ($this->db->num_rows($resql))
1002  {
1003  $obj = $this->db->fetch_object($resql);
1004  $this->fetch($obj->rowid);
1005  }
1006  }
1007  else
1008  {
1009  dol_print_error($this->db);
1010  }
1011  }
1012 
1020  function fetch_name($firstname,$lastname)
1021  {
1022  global $conf;
1023 
1024  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."adherent";
1025  $sql.= " WHERE firstname='".$this->db->escape($firstname)."'";
1026  $sql.= " AND lastname='".$this->db->escape($lastname)."'";
1027  $sql.= " AND entity = ".$conf->entity;
1028 
1029  $resql=$this->db->query($sql);
1030  if ($resql)
1031  {
1032  if ($this->db->num_rows($resql))
1033  {
1034  $obj = $this->db->fetch_object($resql);
1035  $this->fetch($obj->rowid);
1036  }
1037  }
1038  else
1039  {
1040  dol_print_error($this->db);
1041  }
1042  }
1043 
1053  function fetch($rowid,$ref='',$fk_soc='',$ref_ext='')
1054  {
1055  global $langs;
1056 
1057  $sql = "SELECT d.rowid, d.ref_ext, d.civility as civility_id, d.firstname, d.lastname, d.societe as company, d.fk_soc, d.statut, d.public, d.address, d.zip, d.town, d.note_private,";
1058  $sql.= " d.note_public,";
1059  $sql.= " d.email, d.skype, d.phone, d.phone_perso, d.phone_mobile, d.login, d.pass, d.pass_crypted,";
1060  $sql.= " d.photo, d.fk_adherent_type, d.morphy, d.entity,";
1061  $sql.= " d.datec as datec,";
1062  $sql.= " d.tms as datem,";
1063  $sql.= " d.datefin as datefin,";
1064  $sql.= " d.birth as birthday,";
1065  $sql.= " d.datevalid as datev,";
1066  $sql.= " d.country,";
1067  $sql.= " d.state_id,";
1068  $sql.= " d.model_pdf,";
1069  $sql.= " c.rowid as country_id, c.code as country_code, c.label as country,";
1070  $sql.= " dep.nom as state, dep.code_departement as state_code,";
1071  $sql.= " t.libelle as type, t.subscription as subscription,";
1072  $sql.= " u.rowid as user_id, u.login as user_login";
1073  $sql.= " FROM ".MAIN_DB_PREFIX."adherent_type as t, ".MAIN_DB_PREFIX."adherent as d";
1074  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON d.country = c.rowid";
1075  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as dep ON d.state_id = dep.rowid";
1076  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON d.rowid = u.fk_member";
1077  $sql.= " WHERE d.fk_adherent_type = t.rowid";
1078  if ($rowid) $sql.= " AND d.rowid=".$rowid;
1079  elseif ($ref || $fk_soc) {
1080  $sql.= " AND d.entity IN (".getEntity('adherent').")";
1081  if ($ref) $sql.= " AND d.rowid='".$this->db->escape($ref)."'";
1082  elseif ($fk_soc > 0) $sql.= " AND d.fk_soc=".$fk_soc;
1083  }
1084  elseif ($ref_ext)
1085  {
1086  $sql.= " AND d.ref_ext='".$this->db->escape($ref_ext)."'";
1087  }
1088 
1089  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
1090  $resql=$this->db->query($sql);
1091  if ($resql)
1092  {
1093  if ($this->db->num_rows($resql))
1094  {
1095  $obj = $this->db->fetch_object($resql);
1096 
1097  $this->entity = $obj->entity;
1098  $this->ref = $obj->rowid;
1099  $this->id = $obj->rowid;
1100  $this->ref_ext = $obj->ref_ext;
1101  $this->civility_id = $obj->civility_id;
1102  $this->firstname = $obj->firstname;
1103  $this->lastname = $obj->lastname;
1104  $this->login = $obj->login;
1105  $this->societe = $obj->company;
1106  $this->company = $obj->company;
1107  $this->fk_soc = $obj->fk_soc;
1108  $this->address = $obj->address;
1109  $this->zip = $obj->zip;
1110  $this->town = $obj->town;
1111 
1112  $this->pass = $obj->pass;
1113  $this->pass_indatabase = $obj->pass;
1114  $this->pass_indatabase_crypted = $obj->pass_crypted;
1115 
1116  $this->state_id = $obj->state_id;
1117  $this->state_code = $obj->state_id?$obj->state_code:'';
1118  $this->state = $obj->state_id?$obj->state:'';
1119 
1120  $this->country_id = $obj->country_id;
1121  $this->country_code = $obj->country_code;
1122  if ($langs->trans("Country".$obj->country_code) != "Country".$obj->country_code)
1123  $this->country = $langs->transnoentitiesnoconv("Country".$obj->country_code);
1124  else
1125  $this->country=$obj->country;
1126 
1127  $this->phone = $obj->phone;
1128  $this->phone_perso = $obj->phone_perso;
1129  $this->phone_mobile = $obj->phone_mobile;
1130  $this->email = $obj->email;
1131  $this->skype = $obj->skype;
1132 
1133  $this->photo = $obj->photo;
1134  $this->statut = $obj->statut;
1135  $this->public = $obj->public;
1136 
1137  $this->datec = $this->db->jdate($obj->datec);
1138  $this->datem = $this->db->jdate($obj->datem);
1139  $this->datefin = $this->db->jdate($obj->datefin);
1140  $this->datevalid = $this->db->jdate($obj->datev);
1141  $this->birth = $this->db->jdate($obj->birthday);
1142 
1143  $this->note_private = $obj->note_private;
1144  $this->note_public = $obj->note_public;
1145  $this->morphy = $obj->morphy;
1146 
1147  $this->typeid = $obj->fk_adherent_type;
1148  $this->type = $obj->type;
1149  $this->need_subscription = $obj->subscription;
1150 
1151  $this->user_id = $obj->user_id;
1152  $this->user_login = $obj->user_login;
1153 
1154  $this->model_pdf = $obj->model_pdf;
1155 
1156  // Retreive all extrafield for thirdparty
1157  // fetch optionals attributes and labels
1158  require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
1159  $extrafields=new ExtraFields($this->db);
1160  $extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
1161  $this->fetch_optionals($this->id,$extralabels);
1162 
1163  // Load other properties
1164  $result=$this->fetch_subscriptions();
1165 
1166  return $this->id;
1167  }
1168  else
1169  {
1170  return 0;
1171  }
1172  }
1173  else
1174  {
1175  $this->error=$this->db->lasterror();
1176  return -1;
1177  }
1178  }
1179 
1180 
1191  {
1192  global $langs;
1193 
1194  require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
1195 
1196  $sql = "SELECT c.rowid, c.fk_adherent, c.subscription, c.note, c.fk_bank,";
1197  $sql.= " c.tms as datem,";
1198  $sql.= " c.datec as datec,";
1199  $sql.= " c.dateadh as dateh,";
1200  $sql.= " c.datef as datef";
1201  $sql.= " FROM ".MAIN_DB_PREFIX."subscription as c";
1202  $sql.= " WHERE c.fk_adherent = ".$this->id;
1203  $sql.= " ORDER BY c.dateadh";
1204  dol_syslog(get_class($this)."::fetch_subscriptions", LOG_DEBUG);
1205 
1206  $resql=$this->db->query($sql);
1207  if ($resql)
1208  {
1209  $this->subscriptions=array();
1210 
1211  $i=0;
1212  while ($obj = $this->db->fetch_object($resql))
1213  {
1214  if ($i==0)
1215  {
1216  $this->first_subscription_date=$obj->dateh;
1217  $this->first_subscription_amount=$obj->subscription;
1218  }
1219  $this->last_subscription_date=$obj->dateh;
1220  $this->last_subscription_amount=$obj->subscription;
1221 
1222  $subscription=new Subscription($this->db);
1223  $subscription->id=$obj->rowid;
1224  $subscription->fk_adherent=$obj->fk_adherent;
1225  $subscription->amount=$obj->subscription;
1226  $subscription->note=$obj->note;
1227  $subscription->fk_bank=$obj->fk_bank;
1228  $subscription->datem=$this->db->jdate($obj->datem);
1229  $subscription->datec=$this->db->jdate($obj->datec);
1230  $subscription->dateh=$this->db->jdate($obj->dateh);
1231  $subscription->datef=$this->db->jdate($obj->datef);
1232 
1233  $this->subscriptions[]=$subscription;
1234 
1235  $i++;
1236  }
1237  return 1;
1238  }
1239  else
1240  {
1241  $this->error=$this->db->error().' sql='.$sql;
1242  return -1;
1243  }
1244  }
1245 
1246 
1261  function subscription($date, $montant, $accountid=0, $operation='', $label='', $num_chq='', $emetteur_nom='', $emetteur_banque='', $datesubend=0)
1262  {
1263  global $conf,$langs,$user;
1264 
1265  require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
1266 
1267  $error=0;
1268 
1269  // Clean parameters
1270  if (! $montant) $montant=0;
1271 
1272  $this->db->begin();
1273 
1274  if ($datesubend)
1275  {
1276  $datefin=$datesubend;
1277  }
1278  else
1279  {
1280  // If no end date, end date = date + 1 year - 1 day
1281  $datefin = dol_time_plus_duree($date,1,'y');
1282  $datefin = dol_time_plus_duree($datefin,-1,'d');
1283  }
1284 
1285  // Create subscription
1286  $subscription=new Subscription($this->db);
1287  $subscription->fk_adherent=$this->id;
1288  $subscription->dateh=$date; // Date of new subscription
1289  $subscription->datef=$datefin; // End data of new subscription
1290  $subscription->amount=$montant;
1291  $subscription->note=$label;
1292 
1293  $rowid=$subscription->create($user);
1294  if ($rowid > 0)
1295  {
1296  // Update denormalized subscription end date (read database subscription to find values)
1297  // This will also update this->datefin
1298  $result=$this->update_end_date($user);
1299  if ($result > 0)
1300  {
1301  // Change properties of object (used by triggers)
1302  $this->last_subscription_date=dol_now();
1303  $this->last_subscription_amount=$montant;
1304  $this->last_subscription_date_start=$date;
1305  $this->last_subscription_date_end=$datefin;
1306  }
1307 
1308  if (! $error)
1309  {
1310  $this->db->commit();
1311  return $rowid;
1312  }
1313  else
1314  {
1315  $this->db->rollback();
1316  return -2;
1317  }
1318  }
1319  else
1320  {
1321  $this->error=$subscription->error;
1322  $this->db->rollback();
1323  return -1;
1324  }
1325  }
1326 
1333  function validate($user)
1334  {
1335  global $langs,$conf;
1336 
1337  $error=0;
1338  $now=dol_now();
1339 
1340  // Check parameters
1341  if ($this->statut == 1)
1342  {
1343  dol_syslog(get_class($this)."::validate statut of member does not allow this", LOG_WARNING);
1344  return 0;
1345  }
1346 
1347  $this->db->begin();
1348 
1349  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
1350  $sql.= " statut = 1";
1351  $sql.= ", datevalid = '".$this->db->idate($now)."'";
1352  $sql.= ", fk_user_valid=".$user->id;
1353  $sql.= " WHERE rowid = ".$this->id;
1354 
1355  dol_syslog(get_class($this)."::validate", LOG_DEBUG);
1356  $result = $this->db->query($sql);
1357  if ($result)
1358  {
1359  $this->statut=1;
1360 
1361  // Call trigger
1362  $result=$this->call_trigger('MEMBER_VALIDATE',$user);
1363  if ($result < 0) { $error++; $this->db->rollback(); return -1; }
1364  // End call triggers
1365 
1366  $this->db->commit();
1367  return 1;
1368  }
1369  else
1370  {
1371  $this->error=$this->db->error();
1372  $this->db->rollback();
1373  return -1;
1374  }
1375  }
1376 
1377 
1384  function resiliate($user)
1385  {
1386  global $langs,$conf;
1387 
1388  $error=0;
1389 
1390  // Check paramaters
1391  if ($this->statut == 0)
1392  {
1393  dol_syslog(get_class($this)."::resiliate statut of member does not allow this", LOG_WARNING);
1394  return 0;
1395  }
1396 
1397  $this->db->begin();
1398 
1399  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
1400  $sql.= " statut = 0";
1401  $sql.= ", fk_user_valid=".$user->id;
1402  $sql.= " WHERE rowid = ".$this->id;
1403 
1404  $result = $this->db->query($sql);
1405  if ($result)
1406  {
1407  $this->statut=0;
1408 
1409  // Call trigger
1410  $result=$this->call_trigger('MEMBER_RESILIATE',$user);
1411  if ($result < 0) { $error++; $this->db->rollback(); return -1; }
1412  // End call triggers
1413 
1414  $this->db->commit();
1415  return 1;
1416  }
1417  else
1418  {
1419  $this->error=$this->db->error();
1420  $this->db->rollback();
1421  return -1;
1422  }
1423  }
1424 
1425 
1431  function add_to_abo()
1432  {
1433  global $conf,$langs;
1434 
1435  include_once DOL_DOCUMENT_ROOT.'/mailmanspip/class/mailmanspip.class.php';
1436  $mailmanspip=new MailmanSpip($this->db);
1437 
1438  $err=0;
1439 
1440  // mailman
1441  if (! empty($conf->global->ADHERENT_USE_MAILMAN) && ! empty($conf->mailmanspip->enabled))
1442  {
1443  $result=$mailmanspip->add_to_mailman($this);
1444 
1445  if ($result < 0)
1446  {
1447  if (! empty($mailmanspip->error)) $this->errors[]=$mailmanspip->error;
1448  $err+=1;
1449  }
1450  foreach ($mailmanspip->mladded_ko as $tmplist => $tmpemail)
1451  {
1452  $langs->load("errors");
1453  $this->errors[]=$langs->trans("ErrorFailedToAddToMailmanList",$tmpemail,$tmplist);
1454  }
1455  foreach ($mailmanspip->mladded_ok as $tmplist => $tmpemail)
1456  {
1457  $langs->load("mailmanspip");
1458  $this->mesgs[]=$langs->trans("SuccessToAddToMailmanList",$tmpemail,$tmplist);
1459  }
1460  }
1461 
1462  // spip
1463  if (! empty($conf->global->ADHERENT_USE_SPIP) && ! empty($conf->mailmanspip->enabled))
1464  {
1465  $result=$mailmanspip->add_to_spip($this);
1466  if ($result < 0)
1467  {
1468  $this->errors[]=$mailmanspip->error;
1469  $err+=1;
1470  }
1471  }
1472  if ($err)
1473  {
1474  return -$err;
1475  }
1476  else
1477  {
1478  return 1;
1479  }
1480  }
1481 
1482 
1488  function del_to_abo()
1489  {
1490  global $conf,$langs;
1491 
1492  include_once DOL_DOCUMENT_ROOT.'/mailmanspip/class/mailmanspip.class.php';
1493  $mailmanspip=new MailmanSpip($this->db);
1494 
1495  $err=0;
1496 
1497  // mailman
1498  if (! empty($conf->global->ADHERENT_USE_MAILMAN))
1499  {
1500  $result=$mailmanspip->del_to_mailman($this);
1501  if ($result < 0)
1502  {
1503  if (! empty($mailmanspip->error)) $this->errors[]=$mailmanspip->error;
1504  $err+=1;
1505  }
1506 
1507  foreach ($mailmanspip->mlremoved_ko as $tmplist => $tmpemail)
1508  {
1509  $langs->load("errors");
1510  $this->errors[]=$langs->trans("ErrorFailedToRemoveToMailmanList",$tmpemail,$tmplist);
1511  }
1512  foreach ($mailmanspip->mlremoved_ok as $tmplist => $tmpemail)
1513  {
1514  $langs->load("mailmanspip");
1515  $this->mesgs[]=$langs->trans("SuccessToRemoveToMailmanList",$tmpemail,$tmplist);
1516  }
1517  }
1518 
1519  if ($conf->global->ADHERENT_USE_SPIP && ! empty($conf->mailmanspip->enabled))
1520  {
1521  $result=$mailmanspip->del_to_spip($this);
1522  if ($result < 0)
1523  {
1524  $this->errors[]=$mailmanspip->error;
1525  $err+=1;
1526  }
1527  }
1528  if ($err)
1529  {
1530  // error
1531  return -$err;
1532  }
1533  else
1534  {
1535  return 1;
1536  }
1537  }
1538 
1539 
1545  function getCivilityLabel()
1546  {
1547  global $langs;
1548  $langs->load("dict");
1549 
1550  $code=(empty($this->civility_id)?'':$this->civility_id);
1551  if (empty($code)) return '';
1552  return $langs->getLabelFromKey($this->db, "Civility".$code, "c_civility", "code", "label", $code);
1553  }
1554 
1566  function getNomUrl($withpictoimg=0, $maxlen=0, $option='card', $mode='', $morecss='', $save_lastsearch_value=-1)
1567  {
1568  global $conf, $langs;
1569 
1570  if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpictoimg) $withpictoimg=0;
1571 
1572  $notooltip=0;
1573 
1574  $result=''; $label='';
1575  $link=''; $linkstart=''; $linkend='';
1576 
1577  if (! empty($this->photo))
1578  {
1579  $label.= '<div class="photointooltip">';
1580  $label.= Form::showphoto('memberphoto', $this, 80, 0, 0, 'photowithmargin photologintooltip', 'small', 0, 1);
1581  $label.= '</div><div style="clear: both;"></div>';
1582  }
1583 
1584  $label.= '<div class="centpercent">';
1585  $label.= '<u>' . $langs->trans("Member") . '</u>';
1586  if (! empty($this->ref))
1587  $label.= '<br><b>' . $langs->trans('Ref') . ':</b> ' . $this->ref;
1588  if (! empty($this->firstname) || ! empty($this->lastname))
1589  $label.= '<br><b>' . $langs->trans('Name') . ':</b> ' . $this->getFullName($langs);
1590  $label.='</div>';
1591 
1592  $url = DOL_URL_ROOT.'/adherents/card.php?rowid='.$this->id;
1593  if ($option == 'subscription')
1594  {
1595  $url = DOL_URL_ROOT.'/adherents/subscription.php?rowid='.$this->id;
1596  }
1597 
1598  if ($option != 'nolink')
1599  {
1600  // Add param to save lastsearch_values or not
1601  $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
1602  if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
1603  if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
1604  }
1605 
1606  $link = '<a href="'.$url.'"';
1607  $linkclose="";
1608  if (empty($notooltip))
1609  {
1610  if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
1611  {
1612  $langs->load("users");
1613  $label=$langs->trans("ShowUser");
1614  $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
1615  }
1616  $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"';
1617  $linkclose.= ' class="classfortooltip'.($morecss?' '.$morecss:'').'"';
1618  }
1619 
1620  $link.=$linkclose.'>';
1621  $linkend='</a>';
1622 
1623  //if ($withpictoimg == -1) $result.='<div class="nowrap">';
1624  $result.=$link;
1625  if ($withpictoimg)
1626  {
1627  $paddafterimage='';
1628  if (abs($withpictoimg) == 1) $paddafterimage='style="margin-right: 3px;"';
1629  // Only picto
1630  if ($withpictoimg > 0) $picto='<div class="inline-block nopadding valignmiddle'.($morecss?' userimg'.$morecss:'').'">'.img_object('', 'user', $paddafterimage.' '.($notooltip?'':'class="classfortooltip"'), 0, 0, $notooltip?0:1).'</div>';
1631  // Picto must be a photo
1632  else $picto='<div class="inline-block nopadding valignmiddle'.($morecss?' userimg'.$morecss:'').'"'.($paddafterimage?' '.$paddafterimage:'').'>'.Form::showphoto('memberphoto', $this, 0, 0, 0, 'userphoto'.($withpictoimg==-3?'small':''), 'mini', 0, 1).'</div>';
1633  $result.=$picto;
1634  }
1635  if ($withpictoimg > -2 && $withpictoimg != 2)
1636  {
1637  if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) $result.='<div class="inline-block nopadding valignmiddle'.((! isset($this->statut) || $this->statut)?'':' strikefordisabled').($morecss?' usertext'.$morecss:'').'">';
1638  if ($mode == 'login') $result.=dol_trunc($this->login, $maxlen);
1639  elseif ($mode == 'ref') $result.=$this->id;
1640  else $result.=$this->getFullName($langs,'',($mode == 'firstname' ? 2 : -1),$maxlen);
1641  if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) $result.='</div>';
1642  }
1643  $result.=$linkend;
1644  //if ($withpictoimg == -1) $result.='</div>';
1645 
1646  return $result;
1647  }
1648 
1655  function getLibStatut($mode=0)
1656  {
1657  return $this->LibStatut($this->statut,$this->need_subscription,$this->datefin,$mode);
1658  }
1659 
1669  function LibStatut($statut,$need_subscription,$date_end_subscription,$mode=0)
1670  {
1671  global $langs;
1672  $langs->load("members");
1673  if ($mode == 0)
1674  {
1675  if ($statut == -1) return $langs->trans("MemberStatusDraft");
1676  if ($statut >= 1)
1677  {
1678  if (! $date_end_subscription) return $langs->trans("MemberStatusActive");
1679  elseif ($date_end_subscription < time()) return $langs->trans("MemberStatusActiveLate");
1680  else return $langs->trans("MemberStatusPaid");
1681  }
1682  if ($statut == 0) return $langs->trans("MemberStatusResiliated");
1683  }
1684  if ($mode == 1)
1685  {
1686  if ($statut == -1) return $langs->trans("MemberStatusDraftShort");
1687  if ($statut >= 1)
1688  {
1689  if (! $date_end_subscription) return $langs->trans("MemberStatusActiveShort");
1690  elseif ($date_end_subscription < time()) return $langs->trans("MemberStatusActiveLateShort");
1691  else return $langs->trans("MemberStatusPaidShort");
1692  }
1693  if ($statut == 0) return $langs->trans("MemberStatusResiliatedShort");
1694  }
1695  if ($mode == 2)
1696  {
1697  if ($statut == -1) return img_picto($langs->trans('MemberStatusDraft'),'statut0').' '.$langs->trans("MemberStatusDraftShort");
1698  if ($statut >= 1)
1699  {
1700  if (! $date_end_subscription) return img_picto($langs->trans('MemberStatusActive'),'statut1').' '.$langs->trans("MemberStatusActiveShort");
1701  elseif ($date_end_subscription < time()) return img_picto($langs->trans('MemberStatusActiveLate'),'statut3').' '.$langs->trans("MemberStatusActiveLateShort");
1702  else return img_picto($langs->trans('MemberStatusPaid'),'statut4').' '.$langs->trans("MemberStatusPaidShort");
1703  }
1704  if ($statut == 0) return img_picto($langs->trans('MemberStatusResiliated'),'statut5').' '.$langs->trans("MemberStatusResiliatedShort");
1705  }
1706  if ($mode == 3)
1707  {
1708  if ($statut == -1) return img_picto($langs->trans('MemberStatusDraft'),'statut0');
1709  if ($statut >= 1)
1710  {
1711  if (! $date_end_subscription) return img_picto($langs->trans('MemberStatusActive'),'statut1');
1712  elseif ($date_end_subscription < time()) return img_picto($langs->trans('MemberStatusActiveLate'),'statut3');
1713  else return img_picto($langs->trans('MemberStatusPaid'),'statut4');
1714  }
1715  if ($statut == 0) return img_picto($langs->trans('MemberStatusResiliated'),'statut5');
1716  }
1717  if ($mode == 4)
1718  {
1719  if ($statut == -1) return img_picto($langs->trans('MemberStatusDraft'),'statut0').' '.$langs->trans("MemberStatusDraft");
1720  if ($statut >= 1)
1721  {
1722  if (! $date_end_subscription) return img_picto($langs->trans('MemberStatusActive'),'statut1').' '.$langs->trans("MemberStatusActive");
1723  elseif ($date_end_subscription < time()) return img_picto($langs->trans('MemberStatusActiveLate'),'statut3').' '.$langs->trans("MemberStatusActiveLate");
1724  else return img_picto($langs->trans('MemberStatusPaid'),'statut4').' '.$langs->trans("MemberStatusPaid");
1725  }
1726  if ($statut == 0) return img_picto($langs->trans('MemberStatusResiliated'),'statut5').' '.$langs->trans("MemberStatusResiliated");
1727  }
1728  if ($mode == 5)
1729  {
1730  if ($statut == -1) return $langs->trans("MemberStatusDraft").' '.img_picto($langs->trans('MemberStatusDraft'),'statut0');
1731  if ($statut >= 1)
1732  {
1733  if (! $date_end_subscription) return '<span class="hideonsmartphone">'.$langs->trans("MemberStatusActiveShort").' </span>'.img_picto($langs->trans('MemberStatusActive'),'statut1');
1734  elseif ($date_end_subscription < time()) return '<span class="hideonsmartphone">'.$langs->trans("MemberStatusActiveLateShort").' </span>'.img_picto($langs->trans('MemberStatusActiveLate'),'statut3');
1735  else return '<span class="hideonsmartphone">'.$langs->trans("MemberStatusPaidShort").' </span>'.img_picto($langs->trans('MemberStatusPaid'),'statut4');
1736  }
1737  if ($statut == 0) return '<span class="hideonsmartphone">'.$langs->trans("MemberStatusResiliated").' </span>'.img_picto($langs->trans('MemberStatusResiliated'),'statut5');
1738  }
1739  if ($mode == 6)
1740  {
1741  if ($statut == -1) return $langs->trans("MemberStatusDraft").' '.img_picto($langs->trans('MemberStatusDraft'),'statut0');
1742  if ($statut >= 1)
1743  {
1744  if (! $date_end_subscription) return '<span class="hideonsmartphone">'.$langs->trans("MemberStatusActive").' </span>'.img_picto($langs->trans('MemberStatusActive'),'statut1');
1745  elseif ($date_end_subscription < time()) return '<span class="hideonsmartphone">'.$langs->trans("MemberStatusActiveLate").' </span>'.img_picto($langs->trans('MemberStatusActiveLate'),'statut3');
1746  else return '<span class="hideonsmartphone">'.$langs->trans("MemberStatusPaid").' </span>'.img_picto($langs->trans('MemberStatusPaid'),'statut4');
1747  }
1748  if ($statut == 0) return '<span class="hideonsmartphone">'.$langs->trans("MemberStatusResiliated").' </span>'.img_picto($langs->trans('MemberStatusResiliated'),'statut5');
1749  }
1750  }
1751 
1752 
1758  function load_state_board()
1759  {
1760  global $conf;
1761 
1762  $this->nb=array();
1763 
1764  $sql = "SELECT count(a.rowid) as nb";
1765  $sql.= " FROM ".MAIN_DB_PREFIX."adherent as a";
1766  $sql.= " WHERE a.statut > 0";
1767  $sql.= " AND a.entity IN (".getEntity('adherent').")";
1768 
1769  $resql=$this->db->query($sql);
1770  if ($resql)
1771  {
1772  while ($obj=$this->db->fetch_object($resql))
1773  {
1774  $this->nb["members"]=$obj->nb;
1775  }
1776  $this->db->free($resql);
1777  return 1;
1778  }
1779  else
1780  {
1781  dol_print_error($this->db);
1782  $this->error=$this->db->error();
1783  return -1;
1784  }
1785 
1786  }
1787 
1794  function load_board($user)
1795  {
1796  global $conf, $langs;
1797 
1798  if ($user->societe_id) return -1; // protection pour eviter appel par utilisateur externe
1799 
1800  $now=dol_now();
1801 
1802  $sql = "SELECT a.rowid, a.datefin, a.statut";
1803  $sql.= " FROM ".MAIN_DB_PREFIX."adherent as a";
1804  $sql.= " WHERE a.statut = 1";
1805  $sql.= " AND a.entity IN (".getEntity('adherent').")";
1806  $sql.= " AND (a.datefin IS NULL or a.datefin < '".$this->db->idate($now)."')";
1807 
1808  $resql=$this->db->query($sql);
1809  if ($resql)
1810  {
1811  $langs->load("members");
1812 
1813  $response = new WorkboardResponse();
1814  $response->warning_delay=$conf->adherent->subscription->warning_delay/60/60/24;
1815  $response->label=$langs->trans("MembersWithSubscriptionToReceive");
1816  $response->url=DOL_URL_ROOT.'/adherents/list.php?mainmenu=members&amp;statut=1&amp;filter=outofdate';
1817  $response->img=img_object('',"user");
1818 
1819  $adherentstatic = new Adherent($this->db);
1820 
1821  while ($obj=$this->db->fetch_object($resql))
1822  {
1823  $response->nbtodo++;
1824 
1825  $adherentstatic->datefin = $this->db->jdate($obj->datefin);
1826  $adherentstatic->statut = $obj->statut;
1827 
1828  if ($adherentstatic->hasDelay()) {
1829  $response->nbtodolate++;
1830  }
1831  }
1832 
1833  return $response;
1834  }
1835  else
1836  {
1837  dol_print_error($this->db);
1838  $this->error=$this->db->error();
1839  return -1;
1840  }
1841  }
1842 
1843 
1854  public function generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
1855  {
1856  global $conf,$langs;
1857 
1858  $langs->load("orders");
1859 
1860  if (! dol_strlen($modele)) {
1861 
1862  $modele = 'standard';
1863 
1864  if ($this->modelpdf) {
1865  $modele = $this->modelpdf;
1866  } elseif (! empty($conf->global->ADHERENT_ADDON_PDF)) {
1867  $modele = $conf->global->ADHERENT_ADDON_PDF;
1868  }
1869  }
1870 
1871  $modelpath = "core/modules/member/doc/";
1872 
1873  return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
1874  }
1875 
1876 
1884  function initAsSpecimen()
1885  {
1886  global $user,$langs;
1887 
1888  // Initialise parametres
1889  $this->id=0;
1890  $this->specimen=1;
1891  $this->civility_id = 0;
1892  $this->lastname = 'DOLIBARR';
1893  $this->firstname = 'SPECIMEN';
1894  $this->login='dolibspec';
1895  $this->pass='dolibspec';
1896  $this->societe = 'Societe ABC';
1897  $this->address = '61 jump street';
1898  $this->zip = '75000';
1899  $this->town = 'Paris';
1900  $this->country_id = 1;
1901  $this->country_code = 'FR';
1902  $this->country = 'France';
1903  $this->morphy = 1;
1904  $this->email = 'specimen@specimen.com';
1905  $this->skype = 'tom.hanson';
1906  $this->phone = '0999999999';
1907  $this->phone_perso = '0999999998';
1908  $this->phone_mobile = '0999999997';
1909  $this->note_private='No comment';
1910  $this->birth=time();
1911  $this->photo='';
1912  $this->public=1;
1913  $this->statut=0;
1914 
1915  $this->datefin=time();
1916  $this->datevalid=time();
1917 
1918  $this->typeid=1; // Id type adherent
1919  $this->type='Type adherent'; // Libelle type adherent
1920  $this->need_subscription=0;
1921 
1922  $this->first_subscription_date=time();
1923  $this->first_subscription_amount=10;
1924  $this->last_subscription_date=time();
1925  $this->last_subscription_amount=10;
1926  }
1927 
1928 
1938  function _load_ldap_dn($info,$mode=0)
1939  {
1940  global $conf;
1941  $dn='';
1942  if ($mode==0) $dn=$conf->global->LDAP_KEY_MEMBERS."=".$info[$conf->global->LDAP_KEY_MEMBERS].",".$conf->global->LDAP_MEMBER_DN;
1943  if ($mode==1) $dn=$conf->global->LDAP_MEMBER_DN;
1944  if ($mode==2) $dn=$conf->global->LDAP_KEY_MEMBERS."=".$info[$conf->global->LDAP_KEY_MEMBERS];
1945  return $dn;
1946  }
1947 
1948 
1954  function _load_ldap_info()
1955  {
1956  global $conf,$langs;
1957 
1958  $info=array();
1959  $keymodified=false;
1960 
1961  // Object classes
1962  $info["objectclass"]=explode(',',$conf->global->LDAP_MEMBER_OBJECT_CLASS);
1963 
1964  $this->fullname=$this->getFullName($langs);
1965 
1966  // For avoid ldap error when firstname and lastname are empty
1967  if ($this->morphy == 'mor' && (empty($this->fullname) || $this->fullname == $this->societe)) {
1968  $this->fullname = $this->societe;
1969  $this->lastname = $this->societe;
1970  }
1971 
1972  // Possible LDAP KEY (constname => varname)
1973  $ldapkey = array(
1974  'LDAP_MEMBER_FIELD_FULLNAME' => 'fullname',
1975  'LDAP_MEMBER_FIELD_NAME' => 'lastname',
1976  'LDAP_MEMBER_FIELD_LOGIN' => 'login',
1977  'LDAP_MEMBER_FIELD_LOGIN_SAMBA' => 'login',
1978  'LDAP_MEMBER_FIELD_MAIL' => 'email'
1979  );
1980 
1981  // Member
1982  foreach ($ldapkey as $constname => $varname)
1983  {
1984  if (! empty($this->$varname) && ! empty($conf->global->$constname))
1985  {
1986  $info[$conf->global->$constname] = $this->$varname;
1987 
1988  // Check if it is the LDAP key and if its value has been changed
1989  if (! empty($conf->global->LDAP_KEY_MEMBERS) && $conf->global->LDAP_KEY_MEMBERS == $conf->global->$constname)
1990  {
1991  if (! empty($this->oldcopy) && $this->$varname != $this->oldcopy->$varname) $keymodified=true; // For check if LDAP key has been modified
1992  }
1993  }
1994  }
1995  if ($this->firstname && ! empty($conf->global->LDAP_MEMBER_FIELD_FIRSTNAME)) $info[$conf->global->LDAP_MEMBER_FIELD_FIRSTNAME] = $this->firstname;
1996  if ($this->poste && ! empty($conf->global->LDAP_MEMBER_FIELD_TITLE)) $info[$conf->global->LDAP_MEMBER_FIELD_TITLE] = $this->poste;
1997  if ($this->societe && ! empty($conf->global->LDAP_MEMBER_FIELD_COMPANY)) $info[$conf->global->LDAP_MEMBER_FIELD_COMPANY] = $this->societe;
1998  if ($this->address && ! empty($conf->global->LDAP_MEMBER_FIELD_ADDRESS)) $info[$conf->global->LDAP_MEMBER_FIELD_ADDRESS] = $this->address;
1999  if ($this->zip && ! empty($conf->global->LDAP_MEMBER_FIELD_ZIP)) $info[$conf->global->LDAP_MEMBER_FIELD_ZIP] = $this->zip;
2000  if ($this->town && ! empty($conf->global->LDAP_MEMBER_FIELD_TOWN)) $info[$conf->global->LDAP_MEMBER_FIELD_TOWN] = $this->town;
2001  if ($this->country_code && ! empty($conf->global->LDAP_MEMBER_FIELD_COUNTRY)) $info[$conf->global->LDAP_MEMBER_FIELD_COUNTRY] = $this->country_code;
2002  if ($this->skype && ! empty($conf->global->LDAP_MEMBER_FIELD_SKYPE)) $info[$conf->global->LDAP_MEMBER_FIELD_SKYPE] = $this->skype;
2003  if ($this->phone && ! empty($conf->global->LDAP_MEMBER_FIELD_PHONE)) $info[$conf->global->LDAP_MEMBER_FIELD_PHONE] = $this->phone;
2004  if ($this->phone_perso && ! empty($conf->global->LDAP_MEMBER_FIELD_PHONE_PERSO)) $info[$conf->global->LDAP_MEMBER_FIELD_PHONE_PERSO] = $this->phone_perso;
2005  if ($this->phone_mobile && ! empty($conf->global->LDAP_MEMBER_FIELD_MOBILE)) $info[$conf->global->LDAP_MEMBER_FIELD_MOBILE] = $this->phone_mobile;
2006  if ($this->fax && ! empty($conf->global->LDAP_MEMBER_FIELD_FAX)) $info[$conf->global->LDAP_MEMBER_FIELD_FAX] = $this->fax;
2007  if ($this->note_private && ! empty($conf->global->LDAP_MEMBER_FIELD_DESCRIPTION)) $info[$conf->global->LDAP_MEMBER_FIELD_DESCRIPTION] = $this->note_private;
2008  if ($this->note_public && ! empty($conf->global->LDAP_MEMBER_FIELD_NOTE_PUBLIC)) $info[$conf->global->LDAP_MEMBER_FIELD_NOTE_PUBLIC] = $this->note_public;
2009  if ($this->birth && ! empty($conf->global->LDAP_MEMBER_FIELD_BIRTHDATE)) $info[$conf->global->LDAP_MEMBER_FIELD_BIRTHDATE] = dol_print_date($this->birth,'dayhourldap');
2010  if (isset($this->statut) && ! empty($conf->global->LDAP_FIELD_MEMBER_STATUS)) $info[$conf->global->LDAP_FIELD_MEMBER_STATUS] = $this->statut;
2011  if ($this->datefin && ! empty($conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION)) $info[$conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION] = dol_print_date($this->datefin,'dayhourldap');
2012 
2013  // When password is modified
2014  if (! empty($this->pass))
2015  {
2016  if (! empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD)) $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD] = $this->pass; // this->pass = mot de passe non crypte
2017  if (! empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED)) $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED] = dol_hash($this->pass, 4); // Create OpenLDAP MD5 password (TODO add type of encryption)
2018  }
2019  // Set LDAP password if possible
2020  else if ($conf->global->LDAP_SERVER_PROTOCOLVERSION !== '3') // If ldap key is modified and LDAPv3 we use ldap_rename function for avoid lose encrypt password
2021  {
2022  if (! empty($conf->global->DATABASE_PWD_ENCRYPTED))
2023  {
2024  // Just for the default MD5 !
2025  if (empty($conf->global->MAIN_SECURITY_HASH_ALGO))
2026  {
2027  if ($this->pass_indatabase_crypted && ! empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED)) {
2028  // Create OpenLDAP MD5 password from Dolibarr MD5 password
2029  // Note: This suppose that "pass_indatabase_crypted" is a md5 (guaranted by the previous test if "(empty($conf->global->MAIN_SECURITY_HASH_ALGO))"
2030  $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED] = '{md5}'.base64_encode(hex2bin($this->pass_indatabase_crypted));
2031  }
2032  }
2033  }
2034  // Use $this->pass_indatabase value if exists
2035  else if (! empty($this->pass_indatabase))
2036  {
2037  if (! empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD)) $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD] = $this->pass_indatabase; // $this->pass_indatabase = mot de passe non crypte
2038  if (! empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED)) $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED] = dol_hash($this->pass_indatabase, 4); // md5 for OpenLdap TODO add type of encryption
2039  }
2040  }
2041 
2042  // Subscriptions
2043  if ($this->first_subscription_date && ! empty($conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE)) $info[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE] = dol_print_date($this->first_subscription_date,'dayhourldap');
2044  if (isset($this->first_subscription_amount) && ! empty($conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT)) $info[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT] = $this->first_subscription_amount;
2045  if ($this->last_subscription_date && ! empty($conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE)) $info[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE] = dol_print_date($this->last_subscription_date,'dayhourldap');
2046  if (isset($this->last_subscription_amount) && ! empty($conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT)) $info[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT] = $this->last_subscription_amount;
2047 
2048  return $info;
2049  }
2050 
2051 
2058  function info($id)
2059  {
2060  $sql = 'SELECT a.rowid, a.datec as datec,';
2061  $sql.= ' a.datevalid as datev,';
2062  $sql.= ' a.tms as datem,';
2063  $sql.= ' a.fk_user_author, a.fk_user_valid, a.fk_user_mod';
2064  $sql.= ' FROM '.MAIN_DB_PREFIX.'adherent as a';
2065  $sql.= ' WHERE a.rowid = '.$id;
2066 
2067  dol_syslog(get_class($this)."::info", LOG_DEBUG);
2068  $result=$this->db->query($sql);
2069  if ($result)
2070  {
2071  if ($this->db->num_rows($result))
2072  {
2073  $obj = $this->db->fetch_object($result);
2074  $this->id = $obj->rowid;
2075  if ($obj->fk_user_author)
2076  {
2077  $cuser = new User($this->db);
2078  $cuser->fetch($obj->fk_user_author);
2079  $this->user_creation = $cuser;
2080  }
2081 
2082  if ($obj->fk_user_valid)
2083  {
2084  $vuser = new User($this->db);
2085  $vuser->fetch($obj->fk_user_valid);
2086  $this->user_validation = $vuser;
2087  }
2088 
2089  if ($obj->fk_user_mod)
2090  {
2091  $muser = new User($this->db);
2092  $muser->fetch($obj->fk_user_mod);
2093  $this->user_modification = $muser;
2094  }
2095 
2096  $this->date_creation = $this->db->jdate($obj->datec);
2097  $this->date_validation = $this->db->jdate($obj->datev);
2098  $this->date_modification = $this->db->jdate($obj->datem);
2099  }
2100 
2101  $this->db->free($result);
2102 
2103  }
2104  else
2105  {
2106  dol_print_error($this->db);
2107  }
2108  }
2109 
2119  public function setCategories($categories)
2120  {
2121  // Handle single category
2122  if (!is_array($categories)) {
2123  $categories = array($categories);
2124  }
2125 
2126  // Get current categories
2127  require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
2128  $c = new Categorie($this->db);
2129  $existing = $c->containing($this->id, Categorie::TYPE_MEMBER, 'id');
2130 
2131  // Diff
2132  if (is_array($existing)) {
2133  $to_del = array_diff($existing, $categories);
2134  $to_add = array_diff($categories, $existing);
2135  } else {
2136  $to_del = array(); // Nothing to delete
2137  $to_add = $categories;
2138  }
2139 
2140  // Process
2141  foreach ($to_del as $del) {
2142  if ($c->fetch($del) > 0) {
2143  $c->del_type($this, 'member');
2144  }
2145  }
2146  foreach ($to_add as $add) {
2147  if ($c->fetch($add) > 0) {
2148  $c->add_type($this, 'member');
2149  }
2150  }
2151 
2152  return;
2153  }
2154 
2163  public static function replaceThirdparty($db, $origin_id, $dest_id)
2164  {
2165  $tables = array(
2166  'adherent'
2167  );
2168 
2169  return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
2170  }
2171 
2177  public function hasDelay()
2178  {
2179  global $conf;
2180 
2181  //Only valid members
2182  if ($this->statut <= 0) return false;
2183  if (! $this->datefin) return false;
2184 
2185  $now = dol_now();
2186 
2187  return $this->datefin < ($now - $conf->adherent->subscription->warning_delay);
2188  }
2189 
2190 }
resiliate($user)
Fonction qui resilie un adherent.
del_to_abo()
Function to delete a member from external tools like mailing-list, spip, etc.
setCategories($categories)
Sets object to supplied categories.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it's its name (generic function)
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
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.
getCivilityLabel()
Return civility label of a member.
validate($user)
Function that validate a member.
getNomUrl($withpictoimg=0, $maxlen=0, $option='card', $mode='', $morecss='', $save_lastsearch_value=-1)
Return clicable name (with picto eventually)
send_an_email($text, $subject, $filename_list=array(), $mimetype_list=array(), $mimefilename_list=array(), $addr_cc="", $addr_bcc="", $deliveryreceipt=0, $msgishtml=-1, $errors_to='')
Function sending an email has the adherent with the text supplied in parameter.
Class to manage Dolibarr users.
Definition: user.class.php:39
add_to_abo()
Function to add member into external tools mailing-list, spip, etc.
setUserId($userid)
Set link to a user.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
setThirdPartyId($thirdpartyid)
Set link to a third party.
_load_ldap_info()
Initialise tableau info (tableau des attributs LDAP)
static showphoto($modulepart, $object, $width=100, $height=0, $caneditfield=0, $cssclass='photowithmargin', $imagesize='', $addlinktofullsize=1, $cache=0)
Return HTML code to output a photo.
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)
create($user, $notrigger=0)
Create a member into database.
fetch_name($firstname, $lastname)
Method to load member from its name.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Create a document onto disk according to template module.
_load_ldap_dn($info, $mode=0)
Retourne chaine DN complete dans l'annuaire LDAP pour l'objet.
$pass_indatabase_crypted
Encrypted password in database (always defined)
LibStatut($statut, $need_subscription, $date_end_subscription, $mode=0)
Renvoi le libelle d'un statut donne.
info($id)
Charge les informations d'ordre info dans l'objet adherent.
Class to manage standard extra fields.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
Class to manage third parties objects (customers, suppliers, prospects...)
fetch_subscriptions()
Fonction qui recupere pour un adherent les parametres first_subscription_date first_subscription_amou...
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
Class to manage categories.
static replaceThirdparty($db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,$sendto,$replyto,$message,$filepath,$mimetype,$filename,$cc,$ccc,$deliveryreceipt,$msgishtml,$errors_to,$css,$trackid,$moreinheader,$sendcontext); $mailfile->sendfile();.
static commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
setPassword($user, $password='', $isencrypted=0, $notrigger=0, $nosyncuser=0)
Change password of a user.
Class to manage members of a foundation.
fetch_login($login)
Method to load member from its login.
$pass_indatabase
Clear password in database (defined if DATABASE_PWD_ENCRYPTED=0)
hasDelay()
Return if a member is late (subscription late) or not.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
load_board($user)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
deleteExtraFields()
Delete all extra fields values for the current object.
__construct($db)
Constructor.
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...
Class to manage subscriptions of foundation members.
getRandomPassword($generic=false)
Return a generated password using default module.
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
fetch($rowid, $ref='', $fk_soc='', $ref_ext='')
Load member from database.
load_state_board()
Charge indicateurs this->nb de tableau de bord.
$pass
Clear password in memory.
getmorphylib($morphy='')
Return translated label by the nature of a adherent (physical or moral)
makeSubstitution($text)
Make substitution of tags into text with value of current object.
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
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
make_substitutions($text, $substitutionarray, $outputlangs=null)
Make substition into a text string, replacing keys with vals from $substitutionarray (oldval=>newval)...
dol_hash($chain, $type='0')
Returns a hash of a string.
call_trigger($trigger_name, $user)
Call trigger based on this instance.
update_end_date($user)
Update denormalized last subscription date.
Class to manage mailman and spip.
dol_time_plus_duree($time, $duration_value, $duration_unit)
Add a delay to a date.
Definition: date.lib.php:116
initAsSpecimen()
Initialise an instance with random values.
type
Definition: viewcat.php:283
update($user, $notrigger=0, $nosyncuser=0, $nosyncuserpass=0, $nosyncthirdparty=0, $action='update')
Update a member in database (standard information and password)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
subscription($date, $montant, $accountid=0, $operation='', $label='', $num_chq='', $emetteur_nom='', $emetteur_banque='', $datesubend=0)
Insert subscription into database and eventually add links to banks, mailman, etc...
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
getLibStatut($mode=0)
Retourne le libelle du statut d'un adherent (brouillon, valide, resilie)
dol_textishtml($msg, $option=0)
Return if a text is a html content.