dolibarr  17.0.3
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@inodbox.com>
8  * Copyright (C) 2014-2018 Alexandre Spangaro <aspangaro@open-dsi.fr>
9  * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
10  * Copyright (C) 2015-2022 Frédéric France <frederic.france@netlogic.fr>
11  * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
12  * Copyright (C) 2016 Juanjo Menent <jmenent@2byte.es>
13  * Copyright (C) 2018-2019 Thibault FOUCART <support@ptibogxiv.net>
14  * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
15  * Copyright (C) 2020 Josep Lluís Amador <joseplluis@lliuretic.cat>
16  * Copyright (C) 2021 Waël Almoman <info@almoman.com>
17  * Copyright (C) 2021 Philippe Grand <philippe.grand@atoo-net.com>
18  *
19  * This program is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation; either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program. If not, see <https://www.gnu.org/licenses/>.
31  */
32 
38 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
40 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
41 
42 
46 class Adherent extends CommonObject
47 {
51  public $element = 'member';
52 
56  public $table_element = 'adherent';
57 
62  public $ismultientitymanaged = 1;
63 
67  public $picto = 'member';
68 
69 
70  public $mesgs;
71 
75  public $login;
76 
80  public $pass;
81 
85  public $pass_indatabase;
86 
90  public $pass_indatabase_crypted;
91 
96  public $societe;
97 
101  public $company;
102 
106  public $fk_soc;
107  public $socid;
108 
112  public $address;
113 
117  public $zip;
118 
122  public $town;
123 
127  public $state_id;
128 
132  public $state_code;
133 
137  public $state;
138 
142  public $email;
143 
147  public $url;
148 
152  public $socialnetworks;
153 
158  public $skype;
159 
164  public $twitter;
165 
170  public $facebook;
171 
176  public $linkedin;
177 
181  public $phone;
182 
186  public $phone_perso;
187 
191  public $phone_pro;
192 
196  public $phone_mobile;
197 
201  public $fax;
202 
206  public $poste;
207 
211  public $morphy;
212 
216  public $public;
217 
222  public $default_lang;
223 
227  public $photo;
228 
234  public $datec;
235 
241  public $datem;
242 
243  public $datevalid;
244 
248  public $gender;
249 
250  public $birth;
251 
255  public $typeid;
256 
260  public $type;
261 
262  public $need_subscription;
263 
264  public $user_id;
265 
266  public $user_login;
267 
268  public $datefin;
269 
270 
271  // Fields loaded by fetch_subscriptions() from member table
272 
273  public $first_subscription_date;
274 
275  public $first_subscription_amount;
276 
277  public $last_subscription_date;
278 
279  public $last_subscription_date_start;
280 
281  public $last_subscription_date_end;
282 
283  public $last_subscription_amount;
284 
285  public $subscriptions = array();
286 
287 
288  // Fields loaded by fetchPartnerships() from partnership table
289 
290  public $partnerships = array();
291 
292 
296  public $oldcopy;
297 
301  public $entity;
302 
306  public $fields = array(
307  'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 10),
308  'ref' => array('type' => 'varchar(30)', 'label' => 'Ref', 'default' => 1, 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 12, 'index' => 1),
309  'entity' => array('type' => 'integer', 'label' => 'Entity', 'default' => 1, 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 15, 'index' => 1),
310  'ref_ext' => array('type' => 'varchar(128)', 'label' => 'Ref ext', 'enabled' => 1, 'visible' => 0, 'position' => 20),
311  'civility' => array('type' => 'varchar(6)', 'label' => 'Civility', 'enabled' => 1, 'visible' => -1, 'position' => 25),
312  'lastname' => array('type' => 'varchar(50)', 'label' => 'Lastname', 'enabled' => 1, 'visible' => -1, 'position' => 30, 'showoncombobox'=>1),
313  'firstname' => array('type' => 'varchar(50)', 'label' => 'Firstname', 'enabled' => 1, 'visible' => -1, 'position' => 35, 'showoncombobox'=>1),
314  'login' => array('type' => 'varchar(50)', 'label' => 'Login', 'enabled' => 1, 'visible' => -1, 'position' => 40),
315  'gender' => array('type' => 'varchar(10)', 'label' => 'Gender', 'enabled' => 1, 'visible' => -1, 'position' => 250),
316  'pass' => array('type' => 'varchar(50)', 'label' => 'Pass', 'enabled' => 1, 'visible' => -1, 'position' => 45),
317  'pass_crypted' => array('type' => 'varchar(128)', 'label' => 'Pass crypted', 'enabled' => 1, 'visible' => -1, 'position' => 50),
318  'fk_adherent_type' => array('type' => 'integer', 'label' => 'Fk adherent type', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 55),
319  'morphy' => array('type' => 'varchar(3)', 'label' => 'MorPhy', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 60),
320  'societe' => array('type' => 'varchar(128)', 'label' => 'Societe', 'enabled' => 1, 'visible' => -1, 'position' => 65, 'showoncombobox'=>2),
321  'fk_soc' => array('type' => 'integer:Societe:societe/class/societe.class.php', 'label' => 'ThirdParty', 'enabled' => 1, 'visible' => -1, 'position' => 70),
322  'address' => array('type' => 'text', 'label' => 'Address', 'enabled' => 1, 'visible' => -1, 'position' => 75),
323  'zip' => array('type' => 'varchar(10)', 'label' => 'Zip', 'enabled' => 1, 'visible' => -1, 'position' => 80),
324  'town' => array('type' => 'varchar(50)', 'label' => 'Town', 'enabled' => 1, 'visible' => -1, 'position' => 85),
325  'state_id' => array('type' => 'integer', 'label' => 'State id', 'enabled' => 1, 'visible' => -1, 'position' => 90),
326  'country' => array('type' => 'integer:Ccountry:core/class/ccountry.class.php', 'label' => 'Country', 'enabled' => 1, 'visible' => -1, 'position' => 95),
327  'email' => array('type' => 'varchar(255)', 'label' => 'Email', 'enabled' => 1, 'visible' => -1, 'position' => 100),
328  'url' =>array('type'=>'varchar(255)', 'label'=>'Url', 'enabled'=>1, 'visible'=>-1, 'position'=>110),
329  'socialnetworks' => array('type' => 'text', 'label' => 'Socialnetworks', 'enabled' => 1, 'visible' => -1, 'position' => 105),
330  'phone' => array('type' => 'varchar(30)', 'label' => 'Phone', 'enabled' => 1, 'visible' => -1, 'position' => 115),
331  'phone_perso' => array('type' => 'varchar(30)', 'label' => 'Phone perso', 'enabled' => 1, 'visible' => -1, 'position' => 120),
332  'phone_mobile' => array('type' => 'varchar(30)', 'label' => 'Phone mobile', 'enabled' => 1, 'visible' => -1, 'position' => 125),
333  'birth' => array('type' => 'date', 'label' => 'DateOfBirth', 'enabled' => 1, 'visible' => -1, 'position' => 130),
334  'photo' => array('type' => 'varchar(255)', 'label' => 'Photo', 'enabled' => 1, 'visible' => -1, 'position' => 135),
335  'public' => array('type' => 'smallint(6)', 'label' => 'Public', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 145),
336  'datefin' => array('type' => 'datetime', 'label' => 'DateEnd', 'enabled' => 1, 'visible' => -1, 'position' => 150),
337  'default_lang' =>array('type'=>'varchar(6)', 'label'=>'Default lang', 'enabled'=>1, 'visible'=>-1, 'position'=> 153),
338  'note_public' => array('type' => 'text', 'label' => 'NotePublic', 'enabled' => 1, 'visible' => 0, 'position' => 155),
339  'note_private' => array('type' => 'text', 'label' => 'NotePrivate', 'enabled' => 1, 'visible' => 0, 'position' => 160),
340  'datevalid' => array('type' => 'datetime', 'label' => 'DateValidation', 'enabled' => 1, 'visible' => -1, 'position' => 165),
341  'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -1, 'position' => 170),
342  'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 175),
343  'fk_user_author' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'Fk user author', 'enabled' => 1, 'visible' => -1, 'position' => 180),
344  'fk_user_mod' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'Fk user mod', 'enabled' => 1, 'visible' => -1, 'position' => 185),
345  'fk_user_valid' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserValidation', 'enabled' => 1, 'visible' => -1, 'position' => 190),
346  'canvas' => array('type' => 'varchar(32)', 'label' => 'Canvas', 'enabled' => 1, 'visible' => -1, 'position' => 195),
347  'statut' => array('type' => 'smallint(6)', 'label' => 'Statut', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 500,
348  'arrayofkeyval' => array(-1 => 'Draft', 1 => 'Validated', 0 => 'MemberStatusResiliatedShort', -2 => 'MemberStatusExcludedShort')),
349  'model_pdf' => array('type' => 'varchar(255)', 'label' => 'Model pdf', 'enabled' => 1, 'visible' => 0, 'position' => 800),
350  'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'visible' => -2, 'position' => 805)
351  );
352 
356  const STATUS_DRAFT = -1;
360  const STATUS_VALIDATED = 1;
364  const STATUS_RESILIATED = 0;
368  const STATUS_EXCLUDED = -2;
369 
370 
376  public function __construct($db)
377  {
378  $this->db = $db;
379  $this->statut = self::STATUS_DRAFT;
380  $this->status = $this->statut;
381  // l'adherent n'est pas public par defaut
382  $this->public = 0;
383  // les champs optionnels sont vides
384  $this->array_options = array();
385  }
386 
387 
388  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
405  public 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 = '', $moreinheader = '')
406  {
407  // phpcs:enable
408  global $conf, $langs;
409 
410  // Detect if message is HTML
411  if ($msgishtml == -1) {
412  $msgishtml = 0;
413  if (dol_textishtml($text, 0)) {
414  $msgishtml = 1;
415  }
416  }
417 
418  dol_syslog('send_an_email msgishtml='.$msgishtml);
419 
420  $texttosend = $this->makeSubstitution($text);
421  $subjecttosend = $this->makeSubstitution($subject);
422  if ($msgishtml) {
423  $texttosend = dol_htmlentitiesbr($texttosend);
424  }
425 
426  // Envoi mail confirmation
427  $from = $conf->email_from;
428  if (!empty($conf->global->ADHERENT_MAIL_FROM)) {
429  $from = $conf->global->ADHERENT_MAIL_FROM;
430  }
431 
432  $trackid = 'mem'.$this->id;
433 
434  // Send email (substitutionarray must be done just before this)
435  include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
436  $mailfile = new CMailFile($subjecttosend, $this->email, $from, $texttosend, $filename_list, $mimetype_list, $mimefilename_list, $addr_cc, $addr_bcc, $deliveryreceipt, $msgishtml, '', '', $trackid, $moreinheader);
437  if ($mailfile->sendfile()) {
438  return 1;
439  } else {
440  $this->error = $langs->trans("ErrorFailedToSendMail", $from, $this->email).'. '.$mailfile->error;
441  return -1;
442  }
443  }
444 
445 
452  public function makeSubstitution($text)
453  {
454  global $conf, $langs;
455 
456  $birthday = dol_print_date($this->birth, 'day');
457 
458  $msgishtml = 0;
459  if (dol_textishtml($text, 1)) {
460  $msgishtml = 1;
461  }
462 
463  $infos = '';
464  if ($this->civility_id) {
465  $infos .= $langs->transnoentities("UserTitle").": ".$this->getCivilityLabel()."\n";
466  }
467  $infos .= $langs->transnoentities("id").": ".$this->id."\n";
468  $infos .= $langs->transnoentities("ref").": ".$this->ref."\n";
469  $infos .= $langs->transnoentities("Lastname").": ".$this->lastname."\n";
470  $infos .= $langs->transnoentities("Firstname").": ".$this->firstname."\n";
471  $infos .= $langs->transnoentities("Company").": ".$this->company."\n";
472  $infos .= $langs->transnoentities("Address").": ".$this->address."\n";
473  $infos .= $langs->transnoentities("Zip").": ".$this->zip."\n";
474  $infos .= $langs->transnoentities("Town").": ".$this->town."\n";
475  $infos .= $langs->transnoentities("Country").": ".$this->country."\n";
476  $infos .= $langs->transnoentities("EMail").": ".$this->email."\n";
477  $infos .= $langs->transnoentities("PhonePro").": ".$this->phone."\n";
478  $infos .= $langs->transnoentities("PhonePerso").": ".$this->phone_perso."\n";
479  $infos .= $langs->transnoentities("PhoneMobile").": ".$this->phone_mobile."\n";
480  if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
481  $infos .= $langs->transnoentities("Login").": ".$this->login."\n";
482  $infos .= $langs->transnoentities("Password").": ".$this->pass."\n";
483  }
484  $infos .= $langs->transnoentities("Birthday").": ".$birthday."\n";
485  $infos .= $langs->transnoentities("Photo").": ".$this->photo."\n";
486  $infos .= $langs->transnoentities("Public").": ".yn($this->public);
487 
488  // Substitutions
489  $substitutionarray = array(
490  '__ID__' => $this->id,
491  '__REF__' => $this->ref,
492  '__MEMBER_ID__' => $this->id,
493  '__CIVILITY__' => $this->getCivilityLabel(),
494  '__FIRSTNAME__' => $msgishtml ? dol_htmlentitiesbr($this->firstname) : ($this->firstname ? $this->firstname : ''),
495  '__LASTNAME__' => $msgishtml ? dol_htmlentitiesbr($this->lastname) : ($this->lastname ? $this->lastname : ''),
496  '__FULLNAME__' => $msgishtml ? dol_htmlentitiesbr($this->getFullName($langs)) : $this->getFullName($langs),
497  '__COMPANY__' => $msgishtml ? dol_htmlentitiesbr($this->company) : ($this->company ? $this->company : ''),
498  '__ADDRESS__' => $msgishtml ? dol_htmlentitiesbr($this->address) : ($this->address ? $this->address : ''),
499  '__ZIP__' => $msgishtml ? dol_htmlentitiesbr($this->zip) : ($this->zip ? $this->zip : ''),
500  '__TOWN__' => $msgishtml ? dol_htmlentitiesbr($this->town) : ($this->town ? $this->town : ''),
501  '__COUNTRY__' => $msgishtml ? dol_htmlentitiesbr($this->country) : ($this->country ? $this->country : ''),
502  '__EMAIL__' => $msgishtml ? dol_htmlentitiesbr($this->email) : ($this->email ? $this->email : ''),
503  '__BIRTH__' => $msgishtml ? dol_htmlentitiesbr($birthday) : ($birthday ? $birthday : ''),
504  '__PHOTO__' => $msgishtml ? dol_htmlentitiesbr($this->photo) : ($this->photo ? $this->photo : ''),
505  '__LOGIN__' => $msgishtml ? dol_htmlentitiesbr($this->login) : ($this->login ? $this->login : ''),
506  '__PASSWORD__' => $msgishtml ? dol_htmlentitiesbr($this->pass) : ($this->pass ? $this->pass : ''),
507  '__PHONE__' => $msgishtml ? dol_htmlentitiesbr($this->phone) : ($this->phone ? $this->phone : ''),
508  '__PHONEPRO__' => $msgishtml ? dol_htmlentitiesbr($this->phone_perso) : ($this->phone_perso ? $this->phone_perso : ''),
509  '__PHONEMOBILE__' => $msgishtml ? dol_htmlentitiesbr($this->phone_mobile) : ($this->phone_mobile ? $this->phone_mobile : ''),
510  '__TYPE__' => $msgishtml ? dol_htmlentitiesbr($this->type) : ($this->type ? $this->type : '')
511  );
512 
513  complete_substitutions_array($substitutionarray, $langs, $this);
514 
515  return make_substitutions($text, $substitutionarray, $langs);
516  }
517 
518 
526  public function getmorphylib($morphy = '', $addbadge = 0)
527  {
528  global $langs;
529 
530  // Clean var
531  if (!$morphy) {
532  $morphy = $this->morphy;
533  }
534 
535  if ($addbadge) {
536  $s = '';
537  $labeltoshowm = $langs->trans("Moral");
538  $labeltoshowp = $langs->trans("Physical");
539  if ($morphy == 'phy') {
540  $labeltoshow = $labeltoshowp;
541  if ($addbadge == 2) {
542  $labeltoshow = dol_strtoupper(dolGetFirstLetters($labeltoshowp));
543  if ($labeltoshow == dol_strtoupper(dolGetFirstLetters($labeltoshowm))) {
544  $labeltoshow = dol_strtoupper(dolGetFirstLetters($labeltoshowp, 2));
545  }
546  }
547  $s .= '<span class="member-individual-back paddingleftimp paddingrightimp" title="'.$langs->trans("Physical").'">'.$labeltoshow.'</span>';
548  }
549  if ($morphy == 'mor') {
550  $labeltoshow = $labeltoshowm;
551  if ($addbadge == 2) {
552  $labeltoshow = dol_strtoupper(dolGetFirstLetters($labeltoshowm));
553  if ($labeltoshow == dol_strtoupper(dolGetFirstLetters($labeltoshowp))) {
554  $labeltoshow = dol_strtoupper(dolGetFirstLetters($labeltoshowm, 2));
555  }
556  }
557  $s .= '<span class="member-company-back paddingleftimp paddingrightimp" title="'.$langs->trans("Moral").'">'.$labeltoshow.'</span>';
558  }
559  } else {
560  if ($morphy == 'phy') {
561  $s = $langs->trans("Physical");
562  } elseif ($morphy == 'mor') {
563  $s = $langs->trans("Moral");
564  }
565  }
566 
567  return $s;
568  }
569 
577  public function create($user, $notrigger = 0)
578  {
579  global $conf, $langs;
580 
581  $error = 0;
582 
583  $now = dol_now();
584 
585  // Clean parameters
586  $this->import_key = trim($this->import_key);
587 
588  // Check parameters
589  if (!empty($conf->global->ADHERENT_MAIL_REQUIRED) && !isValidEMail($this->email)) {
590  $langs->load("errors");
591  $this->error = $langs->trans("ErrorBadEMail", $this->email);
592  return -1;
593  }
594  if (!$this->datec) {
595  $this->datec = $now;
596  }
597  if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
598  if (empty($this->login)) {
599  $this->error = $langs->trans("ErrorWrongValueForParameterX", "Login");
600  return -1;
601  }
602  }
603 
604  $this->db->begin();
605 
606  // Insert member
607  $sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent";
608  $sql .= " (ref, datec,login,fk_user_author,fk_user_mod,fk_user_valid,morphy,fk_adherent_type,entity,import_key, ip)";
609  $sql .= " VALUES (";
610  $sql .= " '(PROV)'";
611  $sql .= ", '".$this->db->idate($this->datec)."'";
612  $sql .= ", ".($this->login ? "'".$this->db->escape($this->login)."'" : "null");
613  $sql .= ", ".($user->id > 0 ? $user->id : "null"); // Can be null because member can be created by a guest or a script
614  $sql .= ", null, null, '".$this->db->escape($this->morphy)."'";
615  $sql .= ", ".((int) $this->typeid);
616  $sql .= ", ".$conf->entity;
617  $sql .= ", ".(!empty($this->import_key) ? "'".$this->db->escape($this->import_key)."'" : "null");
618  $sql .= ", ".(!empty($this->ip) ? "'".$this->db->escape($this->ip)."'" : "null");
619  $sql .= ")";
620 
621  dol_syslog(get_class($this)."::create", LOG_DEBUG);
622  $result = $this->db->query($sql);
623  if ($result) {
624  $id = $this->db->last_insert_id(MAIN_DB_PREFIX."adherent");
625  if ($id > 0) {
626  $this->id = $id;
627  $this->ref = (string) $id;
628 
629  // Update minor fields
630  $result = $this->update($user, 1, 1, 0, 0, 'add'); // nosync is 1 to avoid update data of user
631  if ($result < 0) {
632  $this->db->rollback();
633  return -1;
634  }
635 
636  // Add link to user
637  if ($this->user_id) {
638  // Add link to user
639  $sql = "UPDATE ".MAIN_DB_PREFIX."user SET";
640  $sql .= " fk_member = ".((int) $this->id);
641  $sql .= " WHERE rowid = ".((int) $this->user_id);
642  dol_syslog(get_class($this)."::create", LOG_DEBUG);
643  $resql = $this->db->query($sql);
644  if (!$resql) {
645  $this->error = 'Failed to update user to make link with member';
646  $this->db->rollback();
647  return -4;
648  }
649  }
650 
651  if (!$notrigger) {
652  // Call trigger
653  $result = $this->call_trigger('MEMBER_CREATE', $user);
654  if ($result < 0) {
655  $error++;
656  }
657  // End call triggers
658  }
659 
660  if (count($this->errors)) {
661  dol_syslog(get_class($this)."::create ".implode(',', $this->errors), LOG_ERR);
662  $this->db->rollback();
663  return -3;
664  } else {
665  $this->db->commit();
666  return $this->id;
667  }
668  } else {
669  $this->error = 'Failed to get last insert id';
670  dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
671  $this->db->rollback();
672  return -2;
673  }
674  } else {
675  $this->error = $this->db->error();
676  $this->db->rollback();
677  return -1;
678  }
679  }
680 
681 
693  public function update($user, $notrigger = 0, $nosyncuser = 0, $nosyncuserpass = 0, $nosyncthirdparty = 0, $action = 'update')
694  {
695  global $conf, $langs, $hookmanager;
696 
697  require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
698 
699  $nbrowsaffected = 0;
700  $error = 0;
701 
702  dol_syslog(get_class($this)."::update notrigger=".$notrigger.", nosyncuser=".$nosyncuser.", nosyncuserpass=".$nosyncuserpass." nosyncthirdparty=".$nosyncthirdparty.", email=".$this->email);
703 
704  // Clean parameters
705  $this->lastname = trim($this->lastname) ? trim($this->lastname) : trim($this->lastname);
706  $this->firstname = trim($this->firstname) ? trim($this->firstname) : trim($this->firstname);
707  $this->gender = trim($this->gender);
708  $this->address = ($this->address ? $this->address : $this->address);
709  $this->zip = ($this->zip ? $this->zip : $this->zip);
710  $this->town = ($this->town ? $this->town : $this->town);
711  $this->country_id = ($this->country_id > 0 ? $this->country_id : $this->country_id);
712  $this->state_id = ($this->state_id > 0 ? $this->state_id : $this->state_id);
713  $this->note_public = ($this->note_public ? $this->note_public : $this->note_public);
714  $this->note_private = ($this->note_private ? $this->note_private : $this->note_private);
715  $this->url = $this->url ?clean_url($this->url, 0) : '';
716  $this->setUpperOrLowerCase();
717  // Check parameters
718  if (!empty($conf->global->ADHERENT_MAIL_REQUIRED) && !isValidEMail($this->email)) {
719  $langs->load("errors");
720  $this->error = $langs->trans("ErrorBadEMail", $this->email);
721  return -1;
722  }
723 
724  $this->db->begin();
725 
726  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
727  $sql .= " ref = '".$this->db->escape($this->ref)."'";
728  $sql .= ", civility = ".($this->civility_id ? "'".$this->db->escape($this->civility_id)."'" : "null");
729  $sql .= ", firstname = ".($this->firstname ? "'".$this->db->escape($this->firstname)."'" : "null");
730  $sql .= ", lastname = ".($this->lastname ? "'".$this->db->escape($this->lastname)."'" : "null");
731  $sql .= ", gender = ".($this->gender != -1 ? "'".$this->db->escape($this->gender)."'" : "null"); // 'man' or 'woman'
732  $sql .= ", login = ".($this->login ? "'".$this->db->escape($this->login)."'" : "null");
733  $sql .= ", societe = ".($this->company ? "'".$this->db->escape($this->company)."'" : ($this->societe ? "'".$this->db->escape($this->societe)."'" : "null"));
734  if ($this->socid) {
735  $sql .= ", fk_soc = ".($this->socid > 0 ? $this->db->escape($this->socid) : "null"); // Must be modified only when creating from a third-party
736  }
737  $sql .= ", address = ".($this->address ? "'".$this->db->escape($this->address)."'" : "null");
738  $sql .= ", zip = ".($this->zip ? "'".$this->db->escape($this->zip)."'" : "null");
739  $sql .= ", town = ".($this->town ? "'".$this->db->escape($this->town)."'" : "null");
740  $sql .= ", country = ".($this->country_id > 0 ? $this->db->escape($this->country_id) : "null");
741  $sql .= ", state_id = ".($this->state_id > 0 ? $this->db->escape($this->state_id) : "null");
742  $sql .= ", email = '".$this->db->escape($this->email)."'";
743  $sql .= ", url = ".(!empty($this->url) ? "'".$this->db->escape($this->url)."'" : "null");
744  $sql .= ", socialnetworks = ".($this->socialnetworks ? "'".$this->db->escape(json_encode($this->socialnetworks))."'" : "null");
745  $sql .= ", phone = ".($this->phone ? "'".$this->db->escape($this->phone)."'" : "null");
746  $sql .= ", phone_perso = ".($this->phone_perso ? "'".$this->db->escape($this->phone_perso)."'" : "null");
747  $sql .= ", phone_mobile = ".($this->phone_mobile ? "'".$this->db->escape($this->phone_mobile)."'" : "null");
748  $sql .= ", note_private = ".($this->note_private ? "'".$this->db->escape($this->note_private)."'" : "null");
749  $sql .= ", note_public = ".($this->note_public ? "'".$this->db->escape($this->note_public)."'" : "null");
750  $sql .= ", photo = ".($this->photo ? "'".$this->db->escape($this->photo)."'" : "null");
751  $sql .= ", public = '".$this->db->escape($this->public)."'";
752  $sql .= ", statut = ".$this->db->escape($this->statut);
753  $sql .= ", default_lang = ".(!empty($this->default_lang) ? "'".$this->db->escape($this->default_lang)."'" : "null");
754  $sql .= ", fk_adherent_type = ".$this->db->escape($this->typeid);
755  $sql .= ", morphy = '".$this->db->escape($this->morphy)."'";
756  $sql .= ", birth = ".($this->birth ? "'".$this->db->idate($this->birth)."'" : "null");
757 
758  if ($this->datefin) {
759  $sql .= ", datefin = '".$this->db->idate($this->datefin)."'"; // Must be modified only when deleting a subscription
760  }
761  if ($this->datevalid) {
762  $sql .= ", datevalid = '".$this->db->idate($this->datevalid)."'"; // Must be modified only when validating a member
763  }
764  $sql .= ", fk_user_mod = ".($user->id > 0 ? $user->id : 'null'); // Can be null because member can be create by a guest
765  $sql .= " WHERE rowid = ".((int) $this->id);
766 
767  // If we change the type of membership, we set also label of new type
768  if (!empty($this->oldcopy) && $this->typeid != $this->oldcopy->typeid) {
769  $sql2 = "SELECT libelle as label";
770  $sql2 .= " FROM ".MAIN_DB_PREFIX."adherent_type";
771  $sql2 .= " WHERE rowid = ".((int) $this->typeid);
772  $resql2 = $this->db->query($sql2);
773  if ($resql2) {
774  while ($obj = $this->db->fetch_object($resql2)) {
775  $this->type = $obj->label;
776  }
777  }
778  }
779 
780  dol_syslog(get_class($this)."::update update member", LOG_DEBUG);
781  $resql = $this->db->query($sql);
782  if ($resql) {
783  unset($this->country_code);
784  unset($this->country);
785  unset($this->state_code);
786  unset($this->state);
787 
788  $nbrowsaffected += $this->db->affected_rows($resql);
789 
790  $action = 'update';
791 
792  // Actions on extra fields
793  if (!$error) {
794  $result = $this->insertExtraFields();
795  if ($result < 0) {
796  $error++;
797  }
798  }
799 
800  // Update password
801  if (!$error && $this->pass) {
802  dol_syslog(get_class($this)."::update update password");
803  if ($this->pass != $this->pass_indatabase && $this->pass != $this->pass_indatabase_crypted) {
804  $isencrypted = empty($conf->global->DATABASE_PWD_ENCRYPTED) ? 0 : 1;
805 
806  // If password to set differs from the one found into database
807  $result = $this->setPassword($user, $this->pass, $isencrypted, $notrigger, $nosyncuserpass);
808  if (!$nbrowsaffected) {
809  $nbrowsaffected++;
810  }
811  }
812  }
813 
814  // Remove links to user and replace with new one
815  if (!$error) {
816  dol_syslog(get_class($this)."::update update link to user");
817  $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = NULL WHERE fk_member = ".((int) $this->id);
818  dol_syslog(get_class($this)."::update", LOG_DEBUG);
819  $resql = $this->db->query($sql);
820  if (!$resql) {
821  $this->error = $this->db->error();
822  $this->db->rollback();
823  return -5;
824  }
825  // If there is a user linked to this member
826  if ($this->user_id > 0) {
827  $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = ".((int) $this->id)." WHERE rowid = ".((int) $this->user_id);
828  dol_syslog(get_class($this)."::update", LOG_DEBUG);
829  $resql = $this->db->query($sql);
830  if (!$resql) {
831  $this->error = $this->db->error();
832  $this->db->rollback();
833  return -5;
834  }
835  }
836  }
837 
838  if (!$error && $nbrowsaffected) { // If something has change in main data
839  // Update information on linked user if it is an update
840  if (!$error && $this->user_id > 0 && !$nosyncuser) {
841  require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
842 
843  dol_syslog(get_class($this)."::update update linked user");
844 
845  $luser = new User($this->db);
846  $result = $luser->fetch($this->user_id);
847 
848  if ($result >= 0) {
849  //var_dump($this->user_login);exit;
850  //var_dump($this->login);exit;
851 
852  // If option ADHERENT_LOGIN_NOT_REQUIRED is on, there is no login of member, so we do not overwrite user login to keep existing one.
853  if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
854  $luser->login = $this->login;
855  }
856 
857  $luser->ref = $this->ref;
858  $luser->civility_id = $this->civility_id;
859  $luser->firstname = $this->firstname;
860  $luser->lastname = $this->lastname;
861  $luser->gender = $this->gender;
862  $luser->pass = $this->pass;
863  //$luser->socid=$this->fk_soc; // We do not enable this. This may transform a user into an external user.
864 
865  $luser->birth = $this->birth;
866 
867  $luser->address = $this->address;
868  $luser->zip = $this->zip;
869  $luser->town = $this->town;
870  $luser->country_id = $this->country_id;
871  $luser->state_id = $this->state_id;
872 
873  $luser->email = $this->email;
874  $luser->socialnetworks = $this->socialnetworks;
875  $luser->office_phone = $this->phone;
876  $luser->user_mobile = $this->phone_mobile;
877 
878  $luser->lang = $this->default_lang;
879 
880  $luser->fk_member = $this->id;
881 
882  $result = $luser->update($user, 0, 1, 1); // Use nosync to 1 to avoid cyclic updates
883  if ($result < 0) {
884  $this->error = $luser->error;
885  dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
886  $error++;
887  }
888  } else {
889  $this->error = $luser->error;
890  $error++;
891  }
892  }
893 
894  // Update information on linked thirdparty if it is an update
895  if (!$error && $this->fk_soc > 0 && !$nosyncthirdparty) {
896  require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
897 
898  dol_syslog(get_class($this)."::update update linked thirdparty");
899 
900  // This member is linked with a thirdparty, so we also update thirdparty informations
901  // if this is an update.
902  $lthirdparty = new Societe($this->db);
903  $result = $lthirdparty->fetch($this->fk_soc);
904 
905  if ($result > 0) {
906  $lthirdparty->address = $this->address;
907  $lthirdparty->zip = $this->zip;
908  $lthirdparty->town = $this->town;
909  $lthirdparty->email = $this->email;
910  $lthirdparty->socialnetworks = $this->socialnetworks;
911  $lthirdparty->phone = $this->phone;
912  $lthirdparty->state_id = $this->state_id;
913  $lthirdparty->country_id = $this->country_id;
914  //$lthirdparty->phone_mobile=$this->phone_mobile;
915  $lthirdparty->default_lang = $this->default_lang;
916 
917  $result = $lthirdparty->update($this->fk_soc, $user, 0, 1, 1, 'update'); // Use sync to 0 to avoid cyclic updates
918 
919  if ($result < 0) {
920  $this->error = $lthirdparty->error;
921  $this->errors = $lthirdparty->errors;
922  dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
923  $error++;
924  }
925  } elseif ($result < 0) {
926  $this->error = $lthirdparty->error;
927  $error++;
928  }
929  }
930  }
931 
932  if (!$error && !$notrigger) {
933  // Call trigger
934  $result = $this->call_trigger('MEMBER_MODIFY', $user);
935  if ($result < 0) {
936  $error++;
937  }
938  // End call triggers
939  }
940 
941  if (!$error) {
942  $this->db->commit();
943  return $nbrowsaffected;
944  } else {
945  $this->db->rollback();
946  return -1;
947  }
948  } else {
949  $this->db->rollback();
950  $this->error = $this->db->lasterror();
951  return -2;
952  }
953  }
954 
955 
956  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
964  public function update_end_date($user)
965  {
966  // phpcs:enable
967  $this->db->begin();
968 
969  // Search for last subscription id and end date
970  $sql = "SELECT rowid, datec as dateop, dateadh as datedeb, datef as datefin";
971  $sql .= " FROM ".MAIN_DB_PREFIX."subscription";
972  $sql .= " WHERE fk_adherent = ".((int) $this->id);
973  $sql .= " ORDER by dateadh DESC"; // Sort by start subscription date
974 
975  dol_syslog(get_class($this)."::update_end_date", LOG_DEBUG);
976  $resql = $this->db->query($sql);
977  if ($resql) {
978  $obj = $this->db->fetch_object($resql);
979  $dateop = $this->db->jdate($obj->dateop);
980  $datedeb = $this->db->jdate($obj->datedeb);
981  $datefin = $this->db->jdate($obj->datefin);
982 
983  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
984  $sql .= " datefin=".($datefin != '' ? "'".$this->db->idate($datefin)."'" : "null");
985  $sql .= " WHERE rowid = ".((int) $this->id);
986 
987  dol_syslog(get_class($this)."::update_end_date", LOG_DEBUG);
988  $resql = $this->db->query($sql);
989  if ($resql) {
990  $this->last_subscription_date = $dateop;
991  $this->last_subscription_date_start = $datedeb;
992  $this->last_subscription_date_end = $datefin;
993  $this->datefin = $datefin;
994  $this->db->commit();
995  return 1;
996  } else {
997  $this->db->rollback();
998  return -1;
999  }
1000  } else {
1001  $this->error = $this->db->lasterror();
1002  $this->db->rollback();
1003  return -1;
1004  }
1005  }
1006 
1015  public function delete($rowid, $user, $notrigger = 0)
1016  {
1017  global $conf, $langs;
1018 
1019  $result = 0;
1020  $error = 0;
1021  $errorflag = 0;
1022 
1023  // Check parameters
1024  if (empty($rowid)) {
1025  $rowid = $this->id;
1026  }
1027 
1028  $this->db->begin();
1029 
1030  if (!$error && !$notrigger) {
1031  // Call trigger
1032  $result = $this->call_trigger('MEMBER_DELETE', $user);
1033  if ($result < 0) {
1034  $error++;
1035  }
1036  // End call triggers
1037  }
1038 
1039  // Remove category
1040  $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_member WHERE fk_member = ".((int) $rowid);
1041  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1042  $resql = $this->db->query($sql);
1043  if (!$resql) {
1044  $error++;
1045  $this->error .= $this->db->lasterror();
1046  $errorflag = -1;
1047  }
1048 
1049  // Remove subscription
1050  if (!$error) {
1051  $sql = "DELETE FROM ".MAIN_DB_PREFIX."subscription WHERE fk_adherent = ".((int) $rowid);
1052  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1053  $resql = $this->db->query($sql);
1054  if (!$resql) {
1055  $error++;
1056  $this->error .= $this->db->lasterror();
1057  $errorflag = -2;
1058  }
1059  }
1060 
1061  // Remove linked user
1062  if (!$error) {
1063  $ret = $this->setUserId(0);
1064  if ($ret < 0) {
1065  $error++;
1066  $this->error .= $this->db->lasterror();
1067  $errorflag = -3;
1068  }
1069  }
1070 
1071  // Removed extrafields
1072  if (!$error) {
1073  $result = $this->deleteExtraFields();
1074  if ($result < 0) {
1075  $error++;
1076  $errorflag = -4;
1077  dol_syslog(get_class($this)."::delete erreur ".$errorflag." ".$this->error, LOG_ERR);
1078  }
1079  }
1080 
1081  // Remove adherent
1082  if (!$error) {
1083  $sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent WHERE rowid = ".((int) $rowid);
1084  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1085  $resql = $this->db->query($sql);
1086  if (!$resql) {
1087  $error++;
1088  $this->error .= $this->db->lasterror();
1089  $errorflag = -5;
1090  }
1091  }
1092 
1093  if (!$error) {
1094  $this->db->commit();
1095  return 1;
1096  } else {
1097  $this->db->rollback();
1098  return $errorflag;
1099  }
1100  }
1101 
1102 
1113  public function setPassword($user, $password = '', $isencrypted = 0, $notrigger = 0, $nosyncuser = 0)
1114  {
1115  global $conf, $langs;
1116 
1117  $error = 0;
1118 
1119  dol_syslog(get_class($this)."::setPassword user=".$user->id." password=".preg_replace('/./i', '*', $password)." isencrypted=".$isencrypted);
1120 
1121  // If new password not provided, we generate one
1122  if (!$password) {
1123  require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
1124  $password = getRandomPassword(false);
1125  }
1126 
1127  // Crypt password
1128  $password_crypted = dol_hash($password);
1129 
1130  $password_indatabase = '';
1131  if (!$isencrypted) {
1132  $password_indatabase = $password;
1133  }
1134 
1135  $this->db->begin();
1136 
1137  // Mise a jour
1138  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent";
1139  $sql .= " SET pass_crypted = '".$this->db->escape($password_crypted)."'";
1140  //if (!empty($conf->global->DATABASE_PWD_ENCRYPTED))
1141  if ($isencrypted) {
1142  $sql .= ", pass = null";
1143  } else {
1144  $sql .= ", pass = '".$this->db->escape($password_indatabase)."'";
1145  }
1146  $sql .= " WHERE rowid = ".((int) $this->id);
1147 
1148  //dol_syslog("Adherent::Password sql=hidden");
1149  dol_syslog(get_class($this)."::setPassword", LOG_DEBUG);
1150  $result = $this->db->query($sql);
1151  if ($result) {
1152  $nbaffectedrows = $this->db->affected_rows($result);
1153 
1154  if ($nbaffectedrows) {
1155  $this->pass = $password;
1156  $this->pass_indatabase = $password_indatabase;
1157  $this->pass_indatabase_crypted = $password_crypted;
1158 
1159  if ($this->user_id && !$nosyncuser) {
1160  require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
1161 
1162  // This member is linked with a user, so we also update users informations
1163  // if this is an update.
1164  $luser = new User($this->db);
1165  $result = $luser->fetch($this->user_id);
1166 
1167  if ($result >= 0) {
1168  $result = $luser->setPassword($user, $this->pass, 0, 0, 1);
1169  if (is_numeric($result) && $result < 0) {
1170  $this->error = $luser->error;
1171  dol_syslog(get_class($this)."::setPassword ".$this->error, LOG_ERR);
1172  $error++;
1173  }
1174  } else {
1175  $this->error = $luser->error;
1176  $error++;
1177  }
1178  }
1179 
1180  if (!$error && !$notrigger) {
1181  // Call trigger
1182  $result = $this->call_trigger('MEMBER_NEW_PASSWORD', $user);
1183  if ($result < 0) {
1184  $error++;
1185  $this->db->rollback();
1186  return -1;
1187  }
1188  // End call triggers
1189  }
1190 
1191  $this->db->commit();
1192  return $this->pass;
1193  } else {
1194  $this->db->rollback();
1195  return 0;
1196  }
1197  } else {
1198  $this->db->rollback();
1199  dol_print_error($this->db);
1200  return -1;
1201  }
1202  }
1203 
1204 
1211  public function setUserId($userid)
1212  {
1213  global $conf, $langs;
1214 
1215  $this->db->begin();
1216 
1217  // If user is linked to this member, remove old link to this member
1218  $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = NULL WHERE fk_member = ".((int) $this->id);
1219  dol_syslog(get_class($this)."::setUserId", LOG_DEBUG);
1220  $resql = $this->db->query($sql);
1221  if (!$resql) {
1222  $this->error = $this->db->error();
1223  $this->db->rollback();
1224  return -1;
1225  }
1226 
1227  // Set link to user
1228  if ($userid > 0) {
1229  $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = ".((int) $this->id);
1230  $sql .= " WHERE rowid = ".((int) $userid);
1231  dol_syslog(get_class($this)."::setUserId", LOG_DEBUG);
1232  $resql = $this->db->query($sql);
1233  if (!$resql) {
1234  $this->error = $this->db->error();
1235  $this->db->rollback();
1236  return -2;
1237  }
1238  }
1239 
1240  $this->db->commit();
1241 
1242  return 1;
1243  }
1244 
1245 
1252  public function setThirdPartyId($thirdpartyid)
1253  {
1254  global $conf, $langs;
1255 
1256  $this->db->begin();
1257 
1258  // Remove link to third party onto any other members
1259  if ($thirdpartyid > 0) {
1260  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET fk_soc = null";
1261  $sql .= " WHERE fk_soc = ".((int) $thirdpartyid);
1262  $sql .= " AND entity = ".$conf->entity;
1263  dol_syslog(get_class($this)."::setThirdPartyId", LOG_DEBUG);
1264  $resql = $this->db->query($sql);
1265  }
1266 
1267  // Add link to third party for current member
1268  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET fk_soc = ".($thirdpartyid > 0 ? $thirdpartyid : 'null');
1269  $sql .= " WHERE rowid = ".((int) $this->id);
1270 
1271  dol_syslog(get_class($this)."::setThirdPartyId", LOG_DEBUG);
1272  $resql = $this->db->query($sql);
1273  if ($resql) {
1274  $this->db->commit();
1275  return 1;
1276  } else {
1277  $this->error = $this->db->error();
1278  $this->db->rollback();
1279  return -1;
1280  }
1281  }
1282 
1283 
1284  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1291  public function fetch_login($login)
1292  {
1293  // phpcs:enable
1294  global $conf;
1295 
1296  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."adherent";
1297  $sql .= " WHERE login='".$this->db->escape($login)."'";
1298  $sql .= " AND entity = ".$conf->entity;
1299 
1300  $resql = $this->db->query($sql);
1301  if ($resql) {
1302  if ($this->db->num_rows($resql)) {
1303  $obj = $this->db->fetch_object($resql);
1304  $this->fetch($obj->rowid);
1305  }
1306  } else {
1307  dol_print_error($this->db);
1308  }
1309  }
1310 
1311  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1319  public function fetch_name($firstname, $lastname)
1320  {
1321  // phpcs:enable
1322  global $conf;
1323 
1324  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."adherent";
1325  $sql .= " WHERE firstname='".$this->db->escape($firstname)."'";
1326  $sql .= " AND lastname='".$this->db->escape($lastname)."'";
1327  $sql .= " AND entity = ".$conf->entity;
1328 
1329  $resql = $this->db->query($sql);
1330  if ($resql) {
1331  if ($this->db->num_rows($resql)) {
1332  $obj = $this->db->fetch_object($resql);
1333  $this->fetch($obj->rowid);
1334  }
1335  } else {
1336  dol_print_error($this->db);
1337  }
1338  }
1339 
1351  public function fetch($rowid, $ref = '', $fk_soc = '', $ref_ext = '', $fetch_optionals = true, $fetch_subscriptions = true)
1352  {
1353  global $langs;
1354 
1355  $sql = "SELECT d.rowid, d.ref, d.ref_ext, d.civility as civility_code, d.gender, d.firstname, d.lastname,";
1356  $sql .= " d.societe as company, d.fk_soc, d.statut, d.public, d.address, d.zip, d.town, d.note_private,";
1357  $sql .= " d.note_public,";
1358  $sql .= " d.email, d.url, d.socialnetworks, d.phone, d.phone_perso, d.phone_mobile, d.login, d.pass, d.pass_crypted,";
1359  $sql .= " d.photo, d.fk_adherent_type, d.morphy, d.entity,";
1360  $sql .= " d.datec as datec,";
1361  $sql .= " d.tms as datem,";
1362  $sql .= " d.datefin as datefin, d.default_lang,";
1363  $sql .= " d.birth as birthday,";
1364  $sql .= " d.datevalid as datev,";
1365  $sql .= " d.country,";
1366  $sql .= " d.state_id,";
1367  $sql .= " d.model_pdf,";
1368  $sql .= " c.rowid as country_id, c.code as country_code, c.label as country,";
1369  $sql .= " dep.nom as state, dep.code_departement as state_code,";
1370  $sql .= " t.libelle as type, t.subscription as subscription,";
1371  $sql .= " u.rowid as user_id, u.login as user_login";
1372  $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as t, ".MAIN_DB_PREFIX."adherent as d";
1373  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON d.country = c.rowid";
1374  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as dep ON d.state_id = dep.rowid";
1375  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON d.rowid = u.fk_member";
1376  $sql .= " WHERE d.fk_adherent_type = t.rowid";
1377  if ($rowid) {
1378  $sql .= " AND d.rowid=".((int) $rowid);
1379  } elseif ($ref || $fk_soc) {
1380  $sql .= " AND d.entity IN (".getEntity('adherent').")";
1381  if ($ref) {
1382  $sql .= " AND d.ref='".$this->db->escape($ref)."'";
1383  } elseif ($fk_soc > 0) {
1384  $sql .= " AND d.fk_soc=".((int) $fk_soc);
1385  }
1386  } elseif ($ref_ext) {
1387  $sql .= " AND d.ref_ext='".$this->db->escape($ref_ext)."'";
1388  }
1389 
1390  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
1391  $resql = $this->db->query($sql);
1392  if ($resql) {
1393  if ($this->db->num_rows($resql)) {
1394  $obj = $this->db->fetch_object($resql);
1395 
1396  $this->entity = $obj->entity;
1397  $this->id = $obj->rowid;
1398  $this->ref = $obj->ref;
1399  $this->ref_ext = $obj->ref_ext;
1400 
1401  $this->civility_id = $obj->civility_code; // Bad. Kept for backard compatibility
1402  $this->civility_code = $obj->civility_code;
1403  $this->civility = $obj->civility_code ? ($langs->trans("Civility".$obj->civility_code) != ("Civility".$obj->civility_code) ? $langs->trans("Civility".$obj->civility_code) : $obj->civility_code) : '';
1404 
1405  $this->firstname = $obj->firstname;
1406  $this->lastname = $obj->lastname;
1407  $this->gender = $obj->gender;
1408  $this->login = $obj->login;
1409  $this->societe = $obj->company;
1410  $this->company = $obj->company;
1411  $this->socid = $obj->fk_soc;
1412  $this->fk_soc = $obj->fk_soc; // For backward compatibility
1413  $this->address = $obj->address;
1414  $this->zip = $obj->zip;
1415  $this->town = $obj->town;
1416 
1417  $this->pass = $obj->pass;
1418  $this->pass_indatabase = $obj->pass;
1419  $this->pass_indatabase_crypted = $obj->pass_crypted;
1420 
1421  $this->state_id = $obj->state_id;
1422  $this->state_code = $obj->state_id ? $obj->state_code : '';
1423  $this->state = $obj->state_id ? $obj->state : '';
1424 
1425  $this->country_id = $obj->country_id;
1426  $this->country_code = $obj->country_code;
1427  if ($langs->trans("Country".$obj->country_code) != "Country".$obj->country_code) {
1428  $this->country = $langs->transnoentitiesnoconv("Country".$obj->country_code);
1429  } else {
1430  $this->country = $obj->country;
1431  }
1432 
1433  $this->phone = $obj->phone;
1434  $this->phone_perso = $obj->phone_perso;
1435  $this->phone_mobile = $obj->phone_mobile;
1436  $this->email = $obj->email;
1437  $this->url = $obj->url;
1438 
1439  $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks, true) : array());
1440 
1441  $this->photo = $obj->photo;
1442  $this->statut = $obj->statut;
1443  $this->status = $obj->statut;
1444  $this->public = $obj->public;
1445 
1446  $this->datec = $this->db->jdate($obj->datec);
1447  $this->date_creation = $this->db->jdate($obj->datec);
1448  $this->datem = $this->db->jdate($obj->datem);
1449  $this->date_modification = $this->db->jdate($obj->datem);
1450  $this->datefin = $this->db->jdate($obj->datefin);
1451  $this->datevalid = $this->db->jdate($obj->datev);
1452  $this->date_validation = $this->db->jdate($obj->datev);
1453  $this->birth = $this->db->jdate($obj->birthday);
1454 
1455  $this->default_lang = $obj->default_lang;
1456 
1457  $this->note_private = $obj->note_private;
1458  $this->note_public = $obj->note_public;
1459  $this->morphy = $obj->morphy;
1460 
1461  $this->typeid = $obj->fk_adherent_type;
1462  $this->type = $obj->type;
1463  $this->need_subscription = $obj->subscription;
1464 
1465  $this->user_id = $obj->user_id;
1466  $this->user_login = $obj->user_login;
1467 
1468  $this->model_pdf = $obj->model_pdf;
1469 
1470  // Retrieve all extrafield
1471  // fetch optionals attributes and labels
1472  if ($fetch_optionals) {
1473  $this->fetch_optionals();
1474  }
1475 
1476  // Load other properties
1477  if ($fetch_subscriptions) {
1478  $result = $this->fetch_subscriptions();
1479  }
1480 
1481  return $this->id;
1482  } else {
1483  return 0;
1484  }
1485  } else {
1486  $this->error = $this->db->lasterror();
1487  return -1;
1488  }
1489  }
1490 
1491 
1492  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1501  public function fetch_subscriptions()
1502  {
1503  // phpcs:enable
1504  global $langs;
1505 
1506  require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
1507 
1508  $sql = "SELECT c.rowid, c.fk_adherent, c.fk_type, c.subscription, c.note, c.fk_bank,";
1509  $sql .= " c.tms as datem,";
1510  $sql .= " c.datec as datec,";
1511  $sql .= " c.dateadh as dateh,";
1512  $sql .= " c.datef as datef";
1513  $sql .= " FROM ".MAIN_DB_PREFIX."subscription as c";
1514  $sql .= " WHERE c.fk_adherent = ".((int) $this->id);
1515  $sql .= " ORDER BY c.dateadh";
1516  dol_syslog(get_class($this)."::fetch_subscriptions", LOG_DEBUG);
1517 
1518  $resql = $this->db->query($sql);
1519  if ($resql) {
1520  $this->subscriptions = array();
1521 
1522  $i = 0;
1523  while ($obj = $this->db->fetch_object($resql)) {
1524  if ($i == 0) {
1525  $this->first_subscription_date = $this->db->jdate($obj->datec);
1526  $this->first_subscription_date_start = $this->db->jdate($obj->dateh);
1527  $this->first_subscription_date_end = $this->db->jdate($obj->datef);
1528  $this->first_subscription_amount = $obj->subscription;
1529  }
1530  $this->last_subscription_date = $this->db->jdate($obj->datec);
1531  $this->last_subscription_date_start = $this->db->jdate($obj->dateh);
1532  $this->last_subscription_date_end = $this->db->jdate($obj->datef);
1533  $this->last_subscription_amount = $obj->subscription;
1534 
1535  $subscription = new Subscription($this->db);
1536  $subscription->id = $obj->rowid;
1537  $subscription->fk_adherent = $obj->fk_adherent;
1538  $subscription->fk_type = $obj->fk_type;
1539  $subscription->amount = $obj->subscription;
1540  $subscription->note = $obj->note;
1541  $subscription->fk_bank = $obj->fk_bank;
1542  $subscription->datem = $this->db->jdate($obj->datem);
1543  $subscription->datec = $this->db->jdate($obj->datec);
1544  $subscription->dateh = $this->db->jdate($obj->dateh);
1545  $subscription->datef = $this->db->jdate($obj->datef);
1546 
1547  $this->subscriptions[] = $subscription;
1548 
1549  $i++;
1550  }
1551  return 1;
1552  } else {
1553  $this->error = $this->db->error().' sql='.$sql;
1554  return -1;
1555  }
1556  }
1557 
1558 
1565  public function fetchPartnerships($mode)
1566  {
1567  global $langs;
1568 
1569  require_once DOL_DOCUMENT_ROOT.'/partnership/class/partnership.class.php';
1570 
1571 
1572  $this->partnerships[] = array();
1573 
1574  return 1;
1575  }
1576 
1577 
1593  public function subscription($date, $amount, $accountid = 0, $operation = '', $label = '', $num_chq = '', $emetteur_nom = '', $emetteur_banque = '', $datesubend = 0, $fk_type = null)
1594  {
1595  global $conf, $langs, $user;
1596 
1597  require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
1598 
1599  $error = 0;
1600 
1601  // Clean parameters
1602  if (!$amount) {
1603  $amount = 0;
1604  }
1605 
1606  $this->db->begin();
1607 
1608  if ($datesubend) {
1609  $datefin = $datesubend;
1610  } else {
1611  // If no end date, end date = date + 1 year - 1 day
1612  $datefin = dol_time_plus_duree($date, 1, 'y');
1613  $datefin = dol_time_plus_duree($datefin, -1, 'd');
1614  }
1615 
1616  // Create subscription
1617  $subscription = new Subscription($this->db);
1618  $subscription->fk_adherent = $this->id;
1619  $subscription->dateh = $date; // Date of new subscription
1620  $subscription->datef = $datefin; // End data of new subscription
1621  $subscription->amount = $amount;
1622  $subscription->note = $label; // deprecated
1623  $subscription->note_public = $label;
1624  $subscription->fk_type = $fk_type;
1625 
1626  $rowid = $subscription->create($user);
1627  if ($rowid > 0) {
1628  // Update denormalized subscription end date (read database subscription to find values)
1629  // This will also update this->datefin
1630  $result = $this->update_end_date($user);
1631  if ($result > 0) {
1632  // Change properties of object (used by triggers)
1633  $this->last_subscription_date = dol_now();
1634  $this->last_subscription_date_start = $date;
1635  $this->last_subscription_date_end = $datefin;
1636  $this->last_subscription_amount = $amount;
1637  }
1638 
1639  if (!$error) {
1640  $this->db->commit();
1641  return $rowid;
1642  } else {
1643  $this->db->rollback();
1644  return -2;
1645  }
1646  } else {
1647  $this->error = $subscription->error;
1648  $this->errors = $subscription->errors;
1649  $this->db->rollback();
1650  return -1;
1651  }
1652  }
1653 
1654 
1674  public function subscriptionComplementaryActions($subscriptionid, $option, $accountid, $datesubscription, $paymentdate, $operation, $label, $amount, $num_chq, $emetteur_nom = '', $emetteur_banque = '', $autocreatethirdparty = 0, $ext_payment_id = '', $ext_payment_site = '')
1675  {
1676  global $conf, $langs, $user, $mysoc;
1677 
1678  $error = 0;
1679 
1680  $this->invoice = null; // This will contains invoice if an invoice is created
1681 
1682  dol_syslog("subscriptionComplementaryActions subscriptionid=".$subscriptionid." option=".$option." accountid=".$accountid." datesubscription=".$datesubscription." paymentdate=".
1683  $paymentdate." label=".$label." amount=".$amount." num_chq=".$num_chq." autocreatethirdparty=".$autocreatethirdparty);
1684 
1685  // Insert into bank account directlty (if option choosed for) + link to llx_subscription if option is 'bankdirect'
1686  if ($option == 'bankdirect' && $accountid) {
1687  require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
1688 
1689  $acct = new Account($this->db);
1690  $result = $acct->fetch($accountid);
1691 
1692  $dateop = $paymentdate;
1693 
1694  $insertid = $acct->addline($dateop, $operation, $label, $amount, $num_chq, '', $user, $emetteur_nom, $emetteur_banque);
1695  if ($insertid > 0) {
1696  $inserturlid = $acct->add_url_line($insertid, $this->id, DOL_URL_ROOT.'/adherents/card.php?rowid=', $this->getFullname($langs), 'member');
1697  if ($inserturlid > 0) {
1698  // Update table subscription
1699  $sql = "UPDATE ".MAIN_DB_PREFIX."subscription SET fk_bank=".((int) $insertid);
1700  $sql .= " WHERE rowid=".((int) $subscriptionid);
1701 
1702  dol_syslog("subscription::subscription", LOG_DEBUG);
1703  $resql = $this->db->query($sql);
1704  if (!$resql) {
1705  $error++;
1706  $this->error = $this->db->lasterror();
1707  $this->errors[] = $this->error;
1708  }
1709  } else {
1710  $error++;
1711  $this->error = $acct->error;
1712  $this->errors = $acct->errors;
1713  }
1714  } else {
1715  $error++;
1716  $this->error = $acct->error;
1717  $this->errors = $acct->errors;
1718  }
1719  }
1720 
1721  // If option choosed, we create invoice
1722  if (($option == 'bankviainvoice' && $accountid) || $option == 'invoiceonly') {
1723  require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1724  require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/paymentterm.class.php';
1725 
1726  $invoice = new Facture($this->db);
1727  $customer = new Societe($this->db);
1728 
1729  if (!$error) {
1730  if (!($this->fk_soc > 0)) { // If not yet linked to a company
1731  if ($autocreatethirdparty) {
1732  // Create a linked thirdparty to member
1733  $companyalias = '';
1734  $fullname = $this->getFullName($langs);
1735 
1736  if ($this->morphy == 'mor') {
1737  $companyname = $this->company;
1738  if (!empty($fullname)) {
1739  $companyalias = $fullname;
1740  }
1741  } else {
1742  $companyname = $fullname;
1743  if (!empty($this->company)) {
1744  $companyalias = $this->company;
1745  }
1746  }
1747 
1748  $result = $customer->create_from_member($this, $companyname, $companyalias);
1749  if ($result < 0) {
1750  $this->error = $customer->error;
1751  $this->errors = $customer->errors;
1752  $error++;
1753  } else {
1754  $this->fk_soc = $result;
1755  }
1756  } else {
1757  $langs->load("errors");
1758  $this->error = $langs->trans("ErrorMemberNotLinkedToAThirpartyLinkOrCreateFirst");
1759  $this->errors[] = $this->error;
1760  $error++;
1761  }
1762  }
1763  }
1764  if (!$error) {
1765  $result = $customer->fetch($this->fk_soc);
1766  if ($result <= 0) {
1767  $this->error = $customer->error;
1768  $this->errors = $customer->errors;
1769  $error++;
1770  }
1771  }
1772 
1773  if (!$error) {
1774  // Create draft invoice
1775  $invoice->type = Facture::TYPE_STANDARD;
1776  $invoice->cond_reglement_id = $customer->cond_reglement_id;
1777  if (empty($invoice->cond_reglement_id)) {
1778  $paymenttermstatic = new PaymentTerm($this->db);
1779  $invoice->cond_reglement_id = $paymenttermstatic->getDefaultId();
1780  if (empty($invoice->cond_reglement_id)) {
1781  $error++;
1782  $this->error = 'ErrorNoPaymentTermRECEPFound';
1783  $this->errors[] = $this->error;
1784  }
1785  }
1786  $invoice->socid = $this->fk_soc;
1787  //$invoice->date = $datesubscription;
1788  $invoice->date = dol_now();
1789 
1790  // Possibility to add external linked objects with hooks
1791  $invoice->linked_objects['subscription'] = $subscriptionid;
1792  if (!empty($_POST['other_linked_objects']) && is_array($_POST['other_linked_objects'])) {
1793  $invoice->linked_objects = array_merge($invoice->linked_objects, $_POST['other_linked_objects']);
1794  }
1795 
1796  $result = $invoice->create($user);
1797  if ($result <= 0) {
1798  $this->error = $invoice->error;
1799  $this->errors = $invoice->errors;
1800  $error++;
1801  } else {
1802  $this->invoice = $invoice;
1803  }
1804  }
1805 
1806  if (!$error) {
1807  // Add line to draft invoice
1808  $idprodsubscription = 0;
1809  if (!empty($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS) && (isModEnabled("product") || isModEnabled("service"))) {
1810  $idprodsubscription = $conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS;
1811  }
1812 
1813  $vattouse = 0;
1814  if (isset($conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS) && $conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS == 'defaultforfoundationcountry') {
1815  $vattouse = get_default_tva($mysoc, $mysoc, $idprodsubscription);
1816  }
1817  //print xx".$vattouse." - ".$mysoc." - ".$customer;exit;
1818  $result = $invoice->addline($label, 0, 1, $vattouse, 0, 0, $idprodsubscription, 0, $datesubscription, '', 0, 0, '', 'TTC', $amount, 1);
1819  if ($result <= 0) {
1820  $this->error = $invoice->error;
1821  $this->errors = $invoice->errors;
1822  $error++;
1823  }
1824  }
1825 
1826  if (!$error) {
1827  // Validate invoice
1828  $result = $invoice->validate($user);
1829  if ($result <= 0) {
1830  $this->error = $invoice->error;
1831  $this->errors = $invoice->errors;
1832  $error++;
1833  }
1834  }
1835 
1836  if (!$error) {
1837  // TODO Link invoice with subscription ?
1838  }
1839 
1840  // Add payment onto invoice
1841  if (!$error && $option == 'bankviainvoice' && $accountid) {
1842  require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
1843  require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
1844  require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
1845 
1846  $amounts = array();
1847  $amounts[$invoice->id] = price2num($amount);
1848 
1849  $paiement = new Paiement($this->db);
1850  $paiement->datepaye = $paymentdate;
1851  $paiement->amounts = $amounts;
1852  $paiement->paiementcode = $operation;
1853  $paiement->paiementid = dol_getIdFromCode($this->db, $operation, 'c_paiement', 'code', 'id', 1);
1854  $paiement->num_payment = $num_chq;
1855  $paiement->note_public = $label;
1856  $paiement->ext_payment_id = $ext_payment_id;
1857  $paiement->ext_payment_site = $ext_payment_site;
1858 
1859  if (!$error) {
1860  // Create payment line for invoice
1861  $paiement_id = $paiement->create($user);
1862  if (!($paiement_id > 0)) {
1863  $this->error = $paiement->error;
1864  $this->errors = $paiement->errors;
1865  $error++;
1866  }
1867  }
1868 
1869  if (!$error) {
1870  // Add transaction into bank account
1871  $bank_line_id = $paiement->addPaymentToBank($user, 'payment', '(SubscriptionPayment)', $accountid, $emetteur_nom, $emetteur_banque);
1872  if (!($bank_line_id > 0)) {
1873  $this->error = $paiement->error;
1874  $this->errors = $paiement->errors;
1875  $error++;
1876  }
1877  }
1878 
1879  if (!$error && !empty($bank_line_id)) {
1880  // Update fk_bank into subscription table
1881  $sql = 'UPDATE '.MAIN_DB_PREFIX.'subscription SET fk_bank='.((int) $bank_line_id);
1882  $sql .= ' WHERE rowid='.((int) $subscriptionid);
1883 
1884  $result = $this->db->query($sql);
1885  if (!$result) {
1886  $error++;
1887  }
1888  }
1889 
1890  if (!$error) {
1891  // Set invoice as paid
1892  $invoice->setPaid($user);
1893  }
1894  }
1895 
1896  if (!$error) {
1897  // Define output language
1898  $outputlangs = $langs;
1899  $newlang = '';
1900  $lang_id = GETPOST('lang_id');
1901  if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && !empty($lang_id)) {
1902  $newlang = $lang_id;
1903  }
1904  if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
1905  $newlang = $customer->default_lang;
1906  }
1907  if (!empty($newlang)) {
1908  $outputlangs = new Translate("", $conf);
1909  $outputlangs->setDefaultLang($newlang);
1910  }
1911  // Generate PDF (whatever is option MAIN_DISABLE_PDF_AUTOUPDATE) so we can include it into email
1912  //if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
1913 
1914  $invoice->generateDocument($invoice->model_pdf, $outputlangs);
1915  }
1916  }
1917 
1918  if ($error) {
1919  return -1;
1920  } else {
1921  return 1;
1922  }
1923  }
1924 
1925 
1932  public function validate($user)
1933  {
1934  global $langs, $conf;
1935 
1936  $error = 0;
1937  $now = dol_now();
1938 
1939  // Check parameters
1940  if ($this->statut == self::STATUS_VALIDATED) {
1941  dol_syslog(get_class($this)."::validate statut of member does not allow this", LOG_WARNING);
1942  return 0;
1943  }
1944 
1945  $this->db->begin();
1946 
1947  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
1948  $sql .= " statut = ".self::STATUS_VALIDATED;
1949  $sql .= ", datevalid = '".$this->db->idate($now)."'";
1950  $sql .= ", fk_user_valid = ".((int) $user->id);
1951  $sql .= " WHERE rowid = ".((int) $this->id);
1952 
1953  dol_syslog(get_class($this)."::validate", LOG_DEBUG);
1954  $result = $this->db->query($sql);
1955  if ($result) {
1956  $this->statut = self::STATUS_VALIDATED;
1957 
1958  // Call trigger
1959  $result = $this->call_trigger('MEMBER_VALIDATE', $user);
1960  if ($result < 0) {
1961  $error++;
1962  $this->db->rollback();
1963  return -1;
1964  }
1965  // End call triggers
1966 
1967  $this->datevalid = $now;
1968 
1969  $this->db->commit();
1970  return 1;
1971  } else {
1972  $this->error = $this->db->error();
1973  $this->db->rollback();
1974  return -1;
1975  }
1976  }
1977 
1978 
1985  public function resiliate($user)
1986  {
1987  global $langs, $conf;
1988 
1989  $error = 0;
1990 
1991  // Check parameters
1992  if ($this->statut == self::STATUS_RESILIATED) {
1993  dol_syslog(get_class($this)."::resiliate statut of member does not allow this", LOG_WARNING);
1994  return 0;
1995  }
1996 
1997  $this->db->begin();
1998 
1999  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
2000  $sql .= " statut = ".self::STATUS_RESILIATED;
2001  $sql .= ", fk_user_valid=".$user->id;
2002  $sql .= " WHERE rowid = ".((int) $this->id);
2003 
2004  $result = $this->db->query($sql);
2005  if ($result) {
2006  $this->statut = self::STATUS_RESILIATED;
2007 
2008  // Call trigger
2009  $result = $this->call_trigger('MEMBER_RESILIATE', $user);
2010  if ($result < 0) {
2011  $error++;
2012  $this->db->rollback();
2013  return -1;
2014  }
2015  // End call triggers
2016 
2017  $this->db->commit();
2018  return 1;
2019  } else {
2020  $this->error = $this->db->error();
2021  $this->db->rollback();
2022  return -1;
2023  }
2024  }
2025 
2035  public function exclude($user)
2036  {
2037  global $langs, $conf;
2038 
2039  $error = 0;
2040 
2041  // Check parameters
2042  if ($this->statut == self::STATUS_EXCLUDED) {
2043  dol_syslog(get_class($this)."::resiliate statut of member does not allow this", LOG_WARNING);
2044  return 0;
2045  }
2046 
2047  $this->db->begin();
2048 
2049  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
2050  $sql .= " statut = ".self::STATUS_EXCLUDED;
2051  $sql .= ", fk_user_valid=".$user->id;
2052  $sql .= " WHERE rowid = ".((int) $this->id);
2053 
2054  $result = $this->db->query($sql);
2055  if ($result) {
2056  $this->statut = self::STATUS_EXCLUDED;
2057 
2058  // Call trigger
2059  $result = $this->call_trigger('MEMBER_EXCLUDE', $user);
2060  if ($result < 0) {
2061  $error++;
2062  $this->db->rollback();
2063  return -1;
2064  }
2065  // End call triggers
2066 
2067  $this->db->commit();
2068  return 1;
2069  } else {
2070  $this->error = $this->db->error();
2071  $this->db->rollback();
2072  return -1;
2073  }
2074  }
2075 
2076  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2082  public function add_to_abo()
2083  {
2084  // phpcs:enable
2085  global $conf, $langs;
2086 
2087  include_once DOL_DOCUMENT_ROOT.'/mailmanspip/class/mailmanspip.class.php';
2088  $mailmanspip = new MailmanSpip($this->db);
2089 
2090  $err = 0;
2091 
2092  // mailman
2093  if (!empty($conf->global->ADHERENT_USE_MAILMAN) && isModEnabled('mailmanspip')) {
2094  $result = $mailmanspip->add_to_mailman($this);
2095 
2096  if ($result < 0) {
2097  if (!empty($mailmanspip->error)) {
2098  $this->errors[] = $mailmanspip->error;
2099  }
2100  $err += 1;
2101  }
2102  foreach ($mailmanspip->mladded_ko as $tmplist => $tmpemail) {
2103  $langs->load("errors");
2104  $this->errors[] = $langs->trans("ErrorFailedToAddToMailmanList", $tmpemail, $tmplist);
2105  }
2106  foreach ($mailmanspip->mladded_ok as $tmplist => $tmpemail) {
2107  $langs->load("mailmanspip");
2108  $this->mesgs[] = $langs->trans("SuccessToAddToMailmanList", $tmpemail, $tmplist);
2109  }
2110  }
2111 
2112  // spip
2113  if (!empty($conf->global->ADHERENT_USE_SPIP) && isModEnabled('mailmanspip')) {
2114  $result = $mailmanspip->add_to_spip($this);
2115  if ($result < 0) {
2116  $this->errors[] = $mailmanspip->error;
2117  $err += 1;
2118  }
2119  }
2120  if ($err) {
2121  return -$err;
2122  } else {
2123  return 1;
2124  }
2125  }
2126 
2127 
2128  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2134  public function del_to_abo()
2135  {
2136  // phpcs:enable
2137  global $conf, $langs;
2138 
2139  include_once DOL_DOCUMENT_ROOT.'/mailmanspip/class/mailmanspip.class.php';
2140  $mailmanspip = new MailmanSpip($this->db);
2141 
2142  $err = 0;
2143 
2144  // mailman
2145  if (!empty($conf->global->ADHERENT_USE_MAILMAN)) {
2146  $result = $mailmanspip->del_to_mailman($this);
2147  if ($result < 0) {
2148  if (!empty($mailmanspip->error)) {
2149  $this->errors[] = $mailmanspip->error;
2150  }
2151  $err += 1;
2152  }
2153 
2154  foreach ($mailmanspip->mlremoved_ko as $tmplist => $tmpemail) {
2155  $langs->load("errors");
2156  $this->errors[] = $langs->trans("ErrorFailedToRemoveToMailmanList", $tmpemail, $tmplist);
2157  }
2158  foreach ($mailmanspip->mlremoved_ok as $tmplist => $tmpemail) {
2159  $langs->load("mailmanspip");
2160  $this->mesgs[] = $langs->trans("SuccessToRemoveToMailmanList", $tmpemail, $tmplist);
2161  }
2162  }
2163 
2164  if ($conf->global->ADHERENT_USE_SPIP && isModEnabled('mailmanspip')) {
2165  $result = $mailmanspip->del_to_spip($this);
2166  if ($result < 0) {
2167  $this->errors[] = $mailmanspip->error;
2168  $err += 1;
2169  }
2170  }
2171  if ($err) {
2172  // error
2173  return -$err;
2174  } else {
2175  return 1;
2176  }
2177  }
2178 
2179 
2185  public function getCivilityLabel()
2186  {
2187  global $langs;
2188  $langs->load("dict");
2189 
2190  $code = (empty($this->civility_id) ? '' : $this->civility_id);
2191  if (empty($code)) {
2192  return '';
2193  }
2194  return $langs->getLabelFromKey($this->db, "Civility".$code, "c_civility", "code", "label", $code);
2195  }
2196 
2210  public function getNomUrl($withpictoimg = 0, $maxlen = 0, $option = 'card', $mode = '', $morecss = '', $save_lastsearch_value = -1, $notooltip = 0, $addlinktonotes = 0)
2211  {
2212  global $conf, $langs, $hookmanager;
2213 
2214  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpictoimg) {
2215  $withpictoimg = 0;
2216  }
2217 
2218  $result = '';
2219  $label = '';
2220  $linkstart = '';
2221  $linkend = '';
2222 
2223  if (!empty($this->photo)) {
2224  $label .= '<div class="photointooltip floatright">';
2225  $label .= Form::showphoto('memberphoto', $this, 80, 0, 0, 'photoref photowithmargin photologintooltip', 'small', 0, 1);
2226  $label .= '</div>';
2227  //$label .= '<div style="clear: both;"></div>';
2228  }
2229 
2230  $label .= '<div class="centpercent">';
2231  $label .= img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Member").'</u>';
2232 
2233  $label .= ' '.$this->getLibStatut(4);
2234  if (!empty($this->ref)) {
2235  $label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
2236  }
2237  if (!empty($this->login)) {
2238  $label .= '<br><b>'.$langs->trans('Login').':</b> '.$this->login;
2239  }
2240  if (!empty($this->email)) {
2241  $label .= '<br><b>'.$langs->trans('Email').':</b> '.$this->email;
2242  }
2243  if (!empty($this->firstname) || !empty($this->lastname)) {
2244  $label .= '<br><b>'.$langs->trans('Name').':</b> '.$this->getFullName($langs);
2245  }
2246  if (!empty($this->company)) {
2247  $label .= '<br><b>'.$langs->trans('Company').':</b> '.$this->company;
2248  }
2249  $label .= '</div>';
2250 
2251  $url = DOL_URL_ROOT.'/adherents/card.php?rowid='.((int) $this->id);
2252  if ($option == 'subscription') {
2253  $url = DOL_URL_ROOT.'/adherents/subscription.php?rowid='.((int) $this->id);
2254  }
2255 
2256  if ($option != 'nolink') {
2257  // Add param to save lastsearch_values or not
2258  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2259  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
2260  $add_save_lastsearch_values = 1;
2261  }
2262  if ($add_save_lastsearch_values) {
2263  $url .= '&save_lastsearch_values=1';
2264  }
2265  }
2266 
2267  $linkstart .= '<a href="'.$url.'"';
2268  $linkclose = "";
2269  if (empty($notooltip)) {
2270  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2271  $langs->load("users");
2272  $label = $langs->trans("ShowUser");
2273  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
2274  }
2275  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
2276  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
2277  }
2278 
2279  $linkstart .= $linkclose.'>';
2280  $linkend = '</a>';
2281 
2282  $result .= $linkstart;
2283  if ($withpictoimg) {
2284  $result .= '<div class="inline-block nopadding valignmiddle">';
2285  }
2286  if ($withpictoimg) {
2287  $paddafterimage = '';
2288  if (abs($withpictoimg) == 1) {
2289  $paddafterimage = 'style="margin-right: 3px;"';
2290  }
2291  // Only picto
2292  if ($withpictoimg > 0) {
2293  $picto = '<span class="nopadding'.($morecss ? ' userimg'.$morecss : '').'">'.
2294  img_object('', 'user', $paddafterimage.' '.($notooltip ? '' : 'class="classfortooltip"'), 0, 0, $notooltip ? 0 : 1).'</span>';
2295  } else {
2296  // Picto must be a photo
2297  $picto = '<span class="nopadding'.($morecss ? ' userimg'.$morecss : '').'"'.($paddafterimage ? ' '.$paddafterimage : '').'>';
2298  $picto .= Form::showphoto('memberphoto', $this, 0, 0, 0, 'userphoto'.($withpictoimg == -3 ? 'small' : ''), 'mini', 0, 1);
2299  $picto .= '</span>';
2300  }
2301  $result .= $picto;
2302  }
2303  if ($withpictoimg > -2 && $withpictoimg != 2) {
2304  if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2305  $result .= '<span class="nopadding valignmiddle'.((!isset($this->statut) || $this->statut) ? '' : ' strikefordisabled').
2306  ($morecss ? ' usertext'.$morecss : '').'">';
2307  }
2308  if ($mode == 'login') {
2309  $result .= dol_trunc($this->login, $maxlen);
2310  } elseif ($mode == 'ref') {
2311  $result .= $this->ref;
2312  } else {
2313  $result .= $this->getFullName($langs, '', ($mode == 'firstname' ? 2 : ($mode == 'lastname' ? 4 : -1)), $maxlen);
2314  }
2315  if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2316  $result .= '</span>';
2317  }
2318  }
2319  if ($withpictoimg) {
2320  $result .= '</div>';
2321  }
2322  $result .= $linkend;
2323 
2324  if ($addlinktonotes) {
2325  if ($this->note_private) {
2326  $notetoshow = $langs->trans("ViewPrivateNote").':<br>'.dol_string_nohtmltag($this->note_private, 1);
2327  $result .= ' <span class="note inline-block">';
2328  $result .= '<a href="'.DOL_URL_ROOT.'/adherents/note.php?id='.$this->id.'" class="classfortooltip" title="'.dol_escape_htmltag($notetoshow).'">';
2329  $result .= img_picto('', 'note');
2330  $result .= '</a>';
2331  $result .= '</span>';
2332  }
2333  }
2334  global $action;
2335  $hookmanager->initHooks(array($this->element . 'dao'));
2336  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
2337  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
2338  if ($reshook > 0) {
2339  $result = $hookmanager->resPrint;
2340  } else {
2341  $result .= $hookmanager->resPrint;
2342  }
2343  return $result;
2344  }
2345 
2352  public function getLibStatut($mode = 0)
2353  {
2354  return $this->LibStatut($this->statut, $this->need_subscription, $this->datefin, $mode);
2355  }
2356 
2357  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2367  public function LibStatut($status, $need_subscription, $date_end_subscription, $mode = 0)
2368  {
2369  // phpcs:enable
2370  global $langs;
2371  $langs->load("members");
2372 
2373  $statusType = '';
2374  $labelStatus = '';
2375  $labelStatusShort = '';
2376 
2377  if ($status == self::STATUS_DRAFT) {
2378  $statusType = 'status0';
2379  $labelStatus = $langs->trans("MemberStatusDraft");
2380  $labelStatusShort = $langs->trans("MemberStatusDraftShort");
2381  } elseif ($status >= self::STATUS_VALIDATED) {
2382  if ($need_subscription === 0) {
2383  $statusType = 'status4';
2384  $labelStatus = $langs->trans("MemberStatusNoSubscription");
2385  $labelStatusShort = $langs->trans("MemberStatusNoSubscriptionShort");
2386  } elseif (!$date_end_subscription) {
2387  $statusType = 'status1';
2388  $labelStatus = $langs->trans("MemberStatusActive");
2389  $labelStatusShort = $langs->trans("MemberStatusActiveShort");
2390  } elseif ($date_end_subscription < dol_now()) { // expired
2391  $statusType = 'status8';
2392  $labelStatus = $langs->trans("MemberStatusActiveLate");
2393  $labelStatusShort = $langs->trans("MemberStatusActiveLateShort");
2394  } else {
2395  $statusType = 'status4';
2396  $labelStatus = $langs->trans("MemberStatusPaid");
2397  $labelStatusShort = $langs->trans("MemberStatusPaidShort");
2398  }
2399  } elseif ($status == self::STATUS_RESILIATED) {
2400  $statusType = 'status6';
2401  $labelStatus = $langs->transnoentitiesnoconv("MemberStatusResiliated");
2402  $labelStatusShort = $langs->transnoentitiesnoconv("MemberStatusResiliatedShort");
2403  } elseif ($status == self::STATUS_EXCLUDED) {
2404  $statusType = 'status10';
2405  $labelStatus = $langs->transnoentitiesnoconv("MemberStatusExcluded");
2406  $labelStatusShort = $langs->transnoentitiesnoconv("MemberStatusExcludedShort");
2407  }
2408 
2409  return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode);
2410  }
2411 
2412 
2413  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2419  public function load_state_board()
2420  {
2421  // phpcs:enable
2422  global $conf;
2423 
2424  $this->nb = array();
2425 
2426  $sql = "SELECT count(a.rowid) as nb";
2427  $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a";
2428  $sql .= " WHERE a.statut > 0";
2429  $sql .= " AND a.entity IN (".getEntity('adherent').")";
2430 
2431  $resql = $this->db->query($sql);
2432  if ($resql) {
2433  while ($obj = $this->db->fetch_object($resql)) {
2434  $this->nb["members"] = $obj->nb;
2435  }
2436  $this->db->free($resql);
2437  return 1;
2438  } else {
2439  dol_print_error($this->db);
2440  $this->error = $this->db->error();
2441  return -1;
2442  }
2443  }
2444 
2445  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2453  public function load_board($user, $mode)
2454  {
2455  // phpcs:enable
2456  global $conf, $langs;
2457 
2458  if ($user->socid) {
2459  return -1; // protection pour eviter appel par utilisateur externe
2460  }
2461 
2462  $now = dol_now();
2463 
2464  $sql = "SELECT a.rowid, a.datefin, a.statut";
2465  $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a";
2466  $sql .= ", ".MAIN_DB_PREFIX."adherent_type as t";
2467  $sql .= " WHERE a.fk_adherent_type = t.rowid";
2468  if ($mode == 'expired') {
2469  $sql .= " AND a.statut = ".self::STATUS_VALIDATED;
2470  $sql .= " AND a.entity IN (".getEntity('adherent').")";
2471  $sql .= " AND ((a.datefin IS NULL or a.datefin < '".$this->db->idate($now)."') AND t.subscription = '1')";
2472  } elseif ($mode == 'shift') {
2473  $sql .= " AND a.statut = ".self::STATUS_DRAFT;
2474  $sql .= " AND a.entity IN (".getEntity('adherent').")";
2475  }
2476 
2477  $resql = $this->db->query($sql);
2478  if ($resql) {
2479  $langs->load("members");
2480 
2481  $warning_delay = 0;
2482  $url = '';
2483  $label = '';
2484  $labelShort = '';
2485 
2486  if ($mode == 'expired') {
2487  $warning_delay = $conf->adherent->subscription->warning_delay / 60 / 60 / 24;
2488  $label = $langs->trans("MembersWithSubscriptionToReceive");
2489  $labelShort = $langs->trans("MembersWithSubscriptionToReceiveShort");
2490  $url = DOL_URL_ROOT.'/adherents/list.php?mainmenu=members&amp;statut='.self::STATUS_VALIDATED.'&amp;filter=outofdate';
2491  } elseif ($mode == 'shift') {
2492  $warning_delay = $conf->adherent->subscription->warning_delay / 60 / 60 / 24;
2493  $url = DOL_URL_ROOT.'/adherents/list.php?mainmenu=members&amp;statut='.self::STATUS_DRAFT;
2494  $label = $langs->trans("MembersListToValid");
2495  $labelShort = $langs->trans("ToValidate");
2496  }
2497 
2498  $response = new WorkboardResponse();
2499  $response->warning_delay = $warning_delay;
2500  $response->label = $label;
2501  $response->labelShort = $labelShort;
2502  $response->url = $url;
2503  $response->img = img_object('', "user");
2504 
2505  $adherentstatic = new Adherent($this->db);
2506 
2507  while ($obj = $this->db->fetch_object($resql)) {
2508  $response->nbtodo++;
2509 
2510  $adherentstatic->datefin = $this->db->jdate($obj->datefin);
2511  $adherentstatic->statut = $obj->statut;
2512 
2513  if ($adherentstatic->hasDelay()) {
2514  $response->nbtodolate++;
2515  }
2516  }
2517 
2518  return $response;
2519  } else {
2520  dol_print_error($this->db);
2521  $this->error = $this->db->error();
2522  return -1;
2523  }
2524  }
2525 
2526 
2538  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
2539  {
2540  global $conf, $langs;
2541 
2542  $langs->load("orders");
2543 
2544  if (!dol_strlen($modele)) {
2545  $modele = 'standard';
2546 
2547  if ($this->model_pdf) {
2548  $modele = $this->model_pdf;
2549  } elseif (!empty($conf->global->ADHERENT_ADDON_PDF)) {
2550  $modele = $conf->global->ADHERENT_ADDON_PDF;
2551  }
2552  }
2553 
2554  $modelpath = "core/modules/member/doc/";
2555 
2556  return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
2557  }
2558 
2559 
2567  public function initAsSpecimen()
2568  {
2569  global $user, $langs;
2570  $now = dol_now();
2571 
2572  // Initialise parametres
2573  $this->id = 0;
2574  $this->ref = 'ABC001';
2575  $this->entity = 1;
2576  $this->specimen = 1;
2577  $this->civility_id = 0;
2578  $this->lastname = 'DOLIBARR';
2579  $this->firstname = 'SPECIMEN';
2580  $this->gender = 'man';
2581  $this->login = 'dolibspec';
2582  $this->pass = 'dolibspec';
2583  $this->company = 'Societe ABC';
2584  $this->address = '61 jump street';
2585  $this->zip = '75000';
2586  $this->town = 'Paris';
2587  $this->country_id = 1;
2588  $this->country_code = 'FR';
2589  $this->country = 'France';
2590  $this->morphy = 'mor';
2591  $this->email = 'specimen@specimen.com';
2592  $this->socialnetworks = array(
2593  'skype' => 'skypepseudo',
2594  'twitter' => 'twitterpseudo',
2595  'facebook' => 'facebookpseudo',
2596  'linkedin' => 'linkedinpseudo',
2597  );
2598  $this->phone = '0999999999';
2599  $this->phone_perso = '0999999998';
2600  $this->phone_mobile = '0999999997';
2601  $this->note_public = 'This is a public note';
2602  $this->note_private = 'This is a private note';
2603  $this->birth = $now;
2604  $this->photo = '';
2605  $this->public = 1;
2606  $this->statut = self::STATUS_DRAFT;
2607 
2608  $this->datefin = $now;
2609  $this->datevalid = $now;
2610  $this->default_lang = '';
2611 
2612  $this->typeid = 1; // Id type adherent
2613  $this->type = 'Type adherent'; // Libelle type adherent
2614  $this->need_subscription = 0;
2615 
2616  $this->first_subscription_date = $now;
2617  $this->first_subscription_date_start = $this->first_subscription_date;
2618  $this->first_subscription_date_end = dol_time_plus_duree($this->first_subscription_date_start, 1, 'y');
2619  $this->first_subscription_amount = 10;
2620 
2621  $this->last_subscription_date = $this->first_subscription_date;
2622  $this->last_subscription_date_start = $this->first_subscription_date;
2623  $this->last_subscription_date_end = dol_time_plus_duree($this->last_subscription_date_start, 1, 'y');
2624  $this->last_subscription_amount = 10;
2625  return 1;
2626  }
2627 
2628 
2629  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2630  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2640  public function _load_ldap_dn($info, $mode = 0)
2641  {
2642  // phpcs:enable
2643  global $conf;
2644  $dn = '';
2645  if ($mode == 0) {
2646  $dn = $conf->global->LDAP_KEY_MEMBERS."=".$info[$conf->global->LDAP_KEY_MEMBERS].",".$conf->global->LDAP_MEMBER_DN;
2647  }
2648  if ($mode == 1) {
2649  $dn = $conf->global->LDAP_MEMBER_DN;
2650  }
2651  if ($mode == 2) {
2652  $dn = $conf->global->LDAP_KEY_MEMBERS."=".$info[$conf->global->LDAP_KEY_MEMBERS];
2653  }
2654  return $dn;
2655  }
2656 
2657 
2658  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2659  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2665  public function _load_ldap_info()
2666  {
2667  // phpcs:enable
2668  global $conf, $langs;
2669 
2670  $info = array();
2671  $socialnetworks = getArrayOfSocialNetworks();
2672  $keymodified = false;
2673 
2674  // Object classes
2675  $info["objectclass"] = explode(',', $conf->global->LDAP_MEMBER_OBJECT_CLASS);
2676 
2677  $this->fullname = $this->getFullName($langs);
2678 
2679  // For avoid ldap error when firstname and lastname are empty
2680  if ($this->morphy == 'mor' && (empty($this->fullname) || $this->fullname == $this->company)) {
2681  $this->fullname = $this->company;
2682  $this->lastname = $this->company;
2683  }
2684 
2685  // Possible LDAP KEY (constname => varname)
2686  $ldapkey = array(
2687  'LDAP_MEMBER_FIELD_FULLNAME' => 'fullname',
2688  'LDAP_MEMBER_FIELD_NAME' => 'lastname',
2689  'LDAP_MEMBER_FIELD_LOGIN' => 'login',
2690  'LDAP_MEMBER_FIELD_LOGIN_SAMBA' => 'login',
2691  'LDAP_MEMBER_FIELD_MAIL' => 'email'
2692  );
2693 
2694  // Member
2695  foreach ($ldapkey as $constname => $varname) {
2696  if (!empty($this->$varname) && !empty($conf->global->$constname)) {
2697  $info[$conf->global->$constname] = $this->$varname;
2698 
2699  // Check if it is the LDAP key and if its value has been changed
2700  if (!empty($conf->global->LDAP_KEY_MEMBERS) && $conf->global->LDAP_KEY_MEMBERS == $conf->global->$constname) {
2701  if (!empty($this->oldcopy) && $this->$varname != $this->oldcopy->$varname) {
2702  $keymodified = true; // For check if LDAP key has been modified
2703  }
2704  }
2705  }
2706  }
2707  if ($this->firstname && !empty($conf->global->LDAP_MEMBER_FIELD_FIRSTNAME)) {
2708  $info[$conf->global->LDAP_MEMBER_FIELD_FIRSTNAME] = $this->firstname;
2709  }
2710  if ($this->poste && !empty($conf->global->LDAP_MEMBER_FIELD_TITLE)) {
2711  $info[$conf->global->LDAP_MEMBER_FIELD_TITLE] = $this->poste;
2712  }
2713  if ($this->company && !empty($conf->global->LDAP_MEMBER_FIELD_COMPANY)) {
2714  $info[$conf->global->LDAP_MEMBER_FIELD_COMPANY] = $this->company;
2715  }
2716  if ($this->address && !empty($conf->global->LDAP_MEMBER_FIELD_ADDRESS)) {
2717  $info[$conf->global->LDAP_MEMBER_FIELD_ADDRESS] = $this->address;
2718  }
2719  if ($this->zip && !empty($conf->global->LDAP_MEMBER_FIELD_ZIP)) {
2720  $info[$conf->global->LDAP_MEMBER_FIELD_ZIP] = $this->zip;
2721  }
2722  if ($this->town && !empty($conf->global->LDAP_MEMBER_FIELD_TOWN)) {
2723  $info[$conf->global->LDAP_MEMBER_FIELD_TOWN] = $this->town;
2724  }
2725  if ($this->country_code && !empty($conf->global->LDAP_MEMBER_FIELD_COUNTRY)) {
2726  $info[$conf->global->LDAP_MEMBER_FIELD_COUNTRY] = $this->country_code;
2727  }
2728  foreach ($socialnetworks as $key => $value) {
2729  if ($this->socialnetworks[$value['label']] && !empty($conf->global->{'LDAP_MEMBER_FIELD_'.strtoupper($value['label'])})) {
2730  $info[$conf->global->{'LDAP_MEMBER_FIELD_'.strtoupper($value['label'])}] = $this->socialnetworks[$value['label']];
2731  }
2732  }
2733  if ($this->phone && !empty($conf->global->LDAP_MEMBER_FIELD_PHONE)) {
2734  $info[$conf->global->LDAP_MEMBER_FIELD_PHONE] = $this->phone;
2735  }
2736  if ($this->phone_perso && !empty($conf->global->LDAP_MEMBER_FIELD_PHONE_PERSO)) {
2737  $info[$conf->global->LDAP_MEMBER_FIELD_PHONE_PERSO] = $this->phone_perso;
2738  }
2739  if ($this->phone_mobile && !empty($conf->global->LDAP_MEMBER_FIELD_MOBILE)) {
2740  $info[$conf->global->LDAP_MEMBER_FIELD_MOBILE] = $this->phone_mobile;
2741  }
2742  if ($this->fax && !empty($conf->global->LDAP_MEMBER_FIELD_FAX)) {
2743  $info[$conf->global->LDAP_MEMBER_FIELD_FAX] = $this->fax;
2744  }
2745  if ($this->note_private && !empty($conf->global->LDAP_MEMBER_FIELD_DESCRIPTION)) {
2746  $info[$conf->global->LDAP_MEMBER_FIELD_DESCRIPTION] = dol_string_nohtmltag($this->note_private, 2);
2747  }
2748  if ($this->note_public && !empty($conf->global->LDAP_MEMBER_FIELD_NOTE_PUBLIC)) {
2749  $info[$conf->global->LDAP_MEMBER_FIELD_NOTE_PUBLIC] = dol_string_nohtmltag($this->note_public, 2);
2750  }
2751  if ($this->birth && !empty($conf->global->LDAP_MEMBER_FIELD_BIRTHDATE)) {
2752  $info[$conf->global->LDAP_MEMBER_FIELD_BIRTHDATE] = dol_print_date($this->birth, 'dayhourldap');
2753  }
2754  if (isset($this->statut) && !empty($conf->global->LDAP_FIELD_MEMBER_STATUS)) {
2755  $info[$conf->global->LDAP_FIELD_MEMBER_STATUS] = $this->statut;
2756  }
2757  if ($this->datefin && !empty($conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION)) {
2758  $info[$conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION] = dol_print_date($this->datefin, 'dayhourldap');
2759  }
2760 
2761  // When password is modified
2762  if (!empty($this->pass)) {
2763  if (!empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD)) {
2764  $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD] = $this->pass; // this->pass = mot de passe non crypte
2765  }
2766  if (!empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED)) {
2767  $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED] = dol_hash($this->pass, 'openldap'); // Create OpenLDAP password (see LDAP_PASSWORD_HASH_TYPE)
2768  }
2769  } elseif ($conf->global->LDAP_SERVER_PROTOCOLVERSION !== '3') {
2770  // Set LDAP password if possible
2771  // If ldap key is modified and LDAPv3 we use ldap_rename function for avoid lose encrypt password
2772  if (!empty($conf->global->DATABASE_PWD_ENCRYPTED)) {
2773  // Just for the default MD5 !
2774  if (empty($conf->global->MAIN_SECURITY_HASH_ALGO)) {
2775  if ($this->pass_indatabase_crypted && !empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED)) {
2776  // Create OpenLDAP MD5 password from Dolibarr MD5 password
2777  // Note: This suppose that "pass_indatabase_crypted" is a md5 (guaranted by the previous test if "(empty($conf->global->MAIN_SECURITY_HASH_ALGO))"
2778  $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED] = dolGetLdapPasswordHash($this->pass_indatabase_crypted, 'md5frommd5');
2779  }
2780  }
2781  } elseif (!empty($this->pass_indatabase)) {
2782  // Use $this->pass_indatabase value if exists
2783  if (!empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD)) {
2784  $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD] = $this->pass_indatabase; // $this->pass_indatabase = mot de passe non crypte
2785  }
2786  if (!empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED)) {
2787  $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED] = dol_hash($this->pass_indatabase, 'openldap'); // Create OpenLDAP password (see LDAP_PASSWORD_HASH_TYPE)
2788  }
2789  }
2790  }
2791 
2792  // Subscriptions
2793  if ($this->first_subscription_date && !empty($conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE)) {
2794  $info[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE] = dol_print_date($this->first_subscription_date, 'dayhourldap');
2795  }
2796  if (isset($this->first_subscription_amount) && !empty($conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT)) {
2797  $info[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT] = $this->first_subscription_amount;
2798  }
2799  if ($this->last_subscription_date && !empty($conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE)) {
2800  $info[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE] = dol_print_date($this->last_subscription_date, 'dayhourldap');
2801  }
2802  if (isset($this->last_subscription_amount) && !empty($conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT)) {
2803  $info[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT] = $this->last_subscription_amount;
2804  }
2805 
2806  return $info;
2807  }
2808 
2809 
2816  public function info($id)
2817  {
2818  $sql = 'SELECT a.rowid, a.datec as datec,';
2819  $sql .= ' a.datevalid as datev,';
2820  $sql .= ' a.tms as datem,';
2821  $sql .= ' a.fk_user_author, a.fk_user_valid, a.fk_user_mod';
2822  $sql .= ' FROM '.MAIN_DB_PREFIX.'adherent as a';
2823  $sql .= ' WHERE a.rowid = '.((int) $id);
2824 
2825  dol_syslog(get_class($this)."::info", LOG_DEBUG);
2826  $result = $this->db->query($sql);
2827  if ($result) {
2828  if ($this->db->num_rows($result)) {
2829  $obj = $this->db->fetch_object($result);
2830  $this->id = $obj->rowid;
2831 
2832  $this->user_creation_id = $obj->fk_user_author;
2833  $this->user_validation_id = $obj->fk_user_valid;
2834  $this->user_modification_id = $obj->fk_user_mod;
2835  $this->date_creation = $this->db->jdate($obj->datec);
2836  $this->date_validation = $this->db->jdate($obj->datev);
2837  $this->date_modification = $this->db->jdate($obj->datem);
2838  }
2839 
2840  $this->db->free($result);
2841  } else {
2842  dol_print_error($this->db);
2843  }
2844  }
2845 
2851  public function getNbOfEMailings()
2852  {
2853  $sql = "SELECT count(mc.email) as nb";
2854  $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
2855  $sql .= " WHERE mc.email = '".$this->db->escape($this->email)."'";
2856  $sql .= " AND mc.statut NOT IN (-1,0)"; // -1 erreur, 0 non envoye, 1 envoye avec succes
2857 
2858  $resql = $this->db->query($sql);
2859  if ($resql) {
2860  $obj = $this->db->fetch_object($resql);
2861  $nb = $obj->nb;
2862 
2863  $this->db->free($resql);
2864  return $nb;
2865  } else {
2866  $this->error = $this->db->error();
2867  return -1;
2868  }
2869  }
2870 
2881  public function setCategories($categories)
2882  {
2883  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
2884  return parent::setCategoriesCommon($categories, Categorie::TYPE_MEMBER);
2885  }
2886 
2895  public static function replaceThirdparty($db, $origin_id, $dest_id)
2896  {
2897  $tables = array('adherent');
2898 
2899  return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
2900  }
2901 
2907  public function hasDelay()
2908  {
2909  global $conf;
2910 
2911  //Only valid members
2912  if ($this->statut != self::STATUS_VALIDATED) {
2913  return false;
2914  }
2915  if (!$this->datefin) {
2916  return false;
2917  }
2918 
2919  $now = dol_now();
2920 
2921  return $this->datefin < ($now - $conf->adherent->subscription->warning_delay);
2922  }
2923 
2924 
2932  public function sendReminderForExpiredSubscription($daysbeforeendlist = '10')
2933  {
2934  global $conf, $langs, $mysoc, $user;
2935 
2936  $error = 0;
2937  $this->output = '';
2938  $this->error = '';
2939 
2940  $blockingerrormsg = '';
2941 
2942  if (empty($conf->adherent->enabled)) { // Should not happen. If module disabled, cron job should not be visible.
2943  $langs->load("agenda");
2944  $this->output = $langs->trans('ModuleNotEnabled', $langs->transnoentitiesnoconv("Adherent"));
2945  return 0;
2946  }
2947  if (empty($conf->global->MEMBER_REMINDER_EMAIL)) {
2948  $langs->load("agenda");
2949  $this->output = $langs->trans('EventRemindersByEmailNotEnabled', $langs->transnoentitiesnoconv("Adherent"));
2950  return 0;
2951  }
2952 
2953  $now = dol_now();
2954  $nbok = 0;
2955  $nbko = 0;
2956 
2957  $listofmembersok = array();
2958  $listofmembersko = array();
2959 
2960  $arraydaysbeforeend = explode(';', $daysbeforeendlist);
2961  foreach ($arraydaysbeforeend as $daysbeforeend) { // Loop on each delay
2962  dol_syslog(__METHOD__.' - Process delta = '.$daysbeforeend, LOG_DEBUG);
2963 
2964  if (!is_numeric($daysbeforeend)) {
2965  $blockingerrormsg = "Value for delta is not a numeric value";
2966  $nbko++;
2967  break;
2968  }
2969 
2970  $tmp = dol_getdate($now);
2971  $datetosearchfor = dol_time_plus_duree(dol_mktime(0, 0, 0, $tmp['mon'], $tmp['mday'], $tmp['year'], 'tzserver'), $daysbeforeend, 'd');
2972 
2973  $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'adherent';
2974  $sql .= " WHERE entity = ".((int) $conf->entity); // Do not use getEntity('adherent').")" here, we want the batch to be on its entity only;
2975  $sql .= " AND datefin = '".$this->db->idate($datetosearchfor)."'";
2976  //$sql .= " LIMIT 10000";
2977 
2978  $resql = $this->db->query($sql);
2979  if ($resql) {
2980  $num_rows = $this->db->num_rows($resql);
2981 
2982  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
2983  $adherent = new Adherent($this->db);
2984  $formmail = new FormMail($this->db);
2985 
2986  $i = 0;
2987  while ($i < $num_rows) {
2988  $obj = $this->db->fetch_object($resql);
2989 
2990  $adherent->fetch($obj->rowid, '', '', '', true, true);
2991 
2992  if (empty($adherent->email)) {
2993  $nbko++;
2994  $listofmembersko[$adherent->id] = $adherent->id;
2995  } else {
2996  $adherent->fetch_thirdparty();
2997 
2998  // Language code to use ($languagecodeformember) is default language of thirdparty, if no thirdparty, the language found from country of member then country of thirdparty, and if still not found we use the language of company.
2999  $languagefromcountrycode = getLanguageCodeFromCountryCode($adherent->country_code ? $adherent->country_code : $adherent->thirdparty->country_code);
3000  $languagecodeformember = (empty($adherent->thirdparty->default_lang) ? ($languagefromcountrycode ? $languagefromcountrycode : $mysoc->default_lang) : $adherent->thirdparty->default_lang);
3001 
3002  // Send reminder email
3003  $outputlangs = new Translate('', $conf);
3004  $outputlangs->setDefaultLang($languagecodeformember);
3005  $outputlangs->loadLangs(array("main", "members"));
3006  dol_syslog("sendReminderForExpiredSubscription Language for member id ".$adherent->id." set to ".$outputlangs->defaultlang." mysoc->default_lang=".$mysoc->default_lang);
3007 
3008  $arraydefaultmessage = null;
3009  $labeltouse = getDolGlobalString('ADHERENT_EMAIL_TEMPLATE_REMIND_EXPIRATION');
3010 
3011  if (!empty($labeltouse)) {
3012  $arraydefaultmessage = $formmail->getEMailTemplate($this->db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
3013  }
3014 
3015  if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
3016  $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $adherent);
3017  //if (is_array($adherent->thirdparty)) $substitutionarraycomp = ...
3018  complete_substitutions_array($substitutionarray, $outputlangs, $adherent);
3019 
3020  $subject = make_substitutions($arraydefaultmessage->topic, $substitutionarray, $outputlangs);
3021  $msg = make_substitutions($arraydefaultmessage->content, $substitutionarray, $outputlangs);
3022  $from = $conf->global->ADHERENT_MAIL_FROM;
3023  $to = $adherent->email;
3024 
3025  $trackid = 'mem'.$adherent->id;
3026  $moreinheader = 'X-Dolibarr-Info: sendReminderForExpiredSubscription'."\r\n";
3027 
3028  include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
3029  $cmail = new CMailFile($subject, $to, $from, $msg, array(), array(), array(), '', '', 0, 1, '', '', $trackid, $moreinheader);
3030  $result = $cmail->sendfile();
3031  if (!$result) {
3032  $error++;
3033  $this->error .= $cmail->error.' ';
3034  if (!is_null($cmail->errors)) {
3035  $this->errors += $cmail->errors;
3036  }
3037  $nbko++;
3038  $listofmembersko[$adherent->id] = $adherent->id;
3039  } else {
3040  $nbok++;
3041  $listofmembersok[$adherent->id] = $adherent->id;
3042 
3043  $message = $msg;
3044  $sendto = $to;
3045  $sendtocc = '';
3046  $sendtobcc = '';
3047  $actioncode = 'EMAIL';
3048  $extraparams = '';
3049 
3050  $actionmsg = '';
3051  $actionmsg2 = $langs->transnoentities('MailSentBy').' '.CMailFile::getValidAddress($from, 4, 0, 1).' '.$langs->transnoentities('To').' '.CMailFile::getValidAddress($sendto, 4, 0, 1);
3052  if ($message) {
3053  $actionmsg = $langs->transnoentities('MailFrom').': '.dol_escape_htmltag($from);
3054  $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTo').': '.dol_escape_htmltag($sendto));
3055  if ($sendtocc) {
3056  $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc').": ".dol_escape_htmltag($sendtocc));
3057  }
3058  $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic').": ".$subject);
3059  $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody').":");
3060  $actionmsg = dol_concatdesc($actionmsg, $message);
3061  }
3062 
3063  require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
3064 
3065  // Insert record of emails sent
3066  $actioncomm = new ActionComm($this->db);
3067 
3068  $actioncomm->type_code = 'AC_OTH_AUTO'; // Type of event ('AC_OTH', 'AC_OTH_AUTO', 'AC_XXX'...)
3069  $actioncomm->code = 'AC_'.$actioncode;
3070  $actioncomm->label = $actionmsg2;
3071  $actioncomm->note_private = $actionmsg;
3072  $actioncomm->fk_project = 0;
3073  $actioncomm->datep = $now;
3074  $actioncomm->datef = $now;
3075  $actioncomm->percentage = -1; // Not applicable
3076  $actioncomm->socid = $adherent->thirdparty->id;
3077  $actioncomm->contact_id = 0;
3078  $actioncomm->authorid = $user->id; // User saving action
3079  $actioncomm->userownerid = $user->id; // Owner of action
3080  // Fields when action is en email (content should be added into note)
3081  $actioncomm->email_msgid = $cmail->msgid;
3082  $actioncomm->email_from = $from;
3083  $actioncomm->email_sender = '';
3084  $actioncomm->email_to = $to;
3085  $actioncomm->email_tocc = $sendtocc;
3086  $actioncomm->email_tobcc = $sendtobcc;
3087  $actioncomm->email_subject = $subject;
3088  $actioncomm->errors_to = '';
3089 
3090  $actioncomm->fk_element = $adherent->id;
3091  $actioncomm->elementtype = $adherent->element;
3092 
3093  $actioncomm->extraparams = $extraparams;
3094 
3095  $actioncomm->create($user);
3096  }
3097  } else {
3098  //$blockingerrormsg = "Can't find email template with label=".$labeltouse.", to use for the reminding email";
3099 
3100  $error++;
3101  $this->error .= "Can't find email template with label=".$labeltouse.", to use for the reminding email ";
3102 
3103  $nbko++;
3104  $listofmembersko[$adherent->id] = $adherent->id;
3105 
3106  break;
3107  }
3108  }
3109 
3110  $i++;
3111  }
3112  } else {
3113  $this->error = $this->db->lasterror();
3114  return 1;
3115  }
3116  }
3117 
3118  if ($blockingerrormsg) {
3119  $this->error = $blockingerrormsg;
3120  return 1;
3121  } else {
3122  $this->output = 'Found '.($nbok + $nbko).' members to send reminder to.';
3123  $this->output .= ' Send email successfuly to '.$nbok.' members';
3124  if (is_array($listofmembersok)) {
3125  $listofids = '';
3126  $i = 0;
3127  foreach ($listofmembersok as $idmember) {
3128  if ($i > 100) {
3129  $listofids .= ', ...';
3130  break;
3131  }
3132  if (empty($listofids)) {
3133  $listofids .= ' [';
3134  } else {
3135  $listofids .= ', ';
3136  }
3137  $listofids .= $idmember;
3138  $i++;
3139  }
3140  if ($listofids) {
3141  $listofids .= ']';
3142  }
3143 
3144  $this->output .= ($listofids ? ' ids='.$listofids : '');
3145  }
3146  if ($nbko) {
3147  $this->output .= ' - Canceled for '.$nbko.' member (no email or email sending error)';
3148  if (is_array($listofmembersko)) {
3149  $listofids = '';
3150  $i = 0;
3151  foreach ($listofmembersko as $idmember) {
3152  if ($i > 100) {
3153  $listofids .= ', ...';
3154  break;
3155  }
3156  if (empty($listofids)) {
3157  $listofids .= ' [';
3158  } else {
3159  $listofids .= ', ';
3160  }
3161  $listofids .= $idmember;
3162  $i++;
3163  }
3164  if ($listofids) {
3165  $listofids .= ']';
3166  }
3167  $this->output .= ($listofids ? ' ids='.$listofids : '');
3168  }
3169  }
3170  }
3171 
3172  return $nbko;
3173  }
3174 }
make_substitutions
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
Definition: functions.lib.php:8167
dol_getdate
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
Definition: functions.lib.php:2820
Adherent\STATUS_RESILIATED
const STATUS_RESILIATED
Resiliated.
Definition: adherent.class.php:364
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:49
clean_url
clean_url($url, $http=1)
Clean an url string.
Definition: functions2.lib.php:825
db
$conf db
API class for accounts.
Definition: inc.php:41
yn
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
Definition: functions.lib.php:6677
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1493
Adherent\create
create($user, $notrigger=0)
Create a member into database.
Definition: adherent.class.php:577
Adherent\fetch_name
fetch_name($firstname, $lastname)
Method to load member from its name.
Definition: adherent.class.php:1319
dol_trunc
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.
Definition: functions.lib.php:3949
Adherent\validate
validate($user)
Function that validate a member.
Definition: adherent.class.php:1932
ActionComm
Class to manage agenda events (actions)
Definition: actioncomm.class.php:38
Adherent\info
info($id)
Load type info information in the member object.
Definition: adherent.class.php:2816
Adherent\resiliate
resiliate($user)
Fonction qui resilie un adherent.
Definition: adherent.class.php:1985
Adherent\fetch
fetch($rowid, $ref='', $fk_soc='', $ref_ext='', $fetch_optionals=true, $fetch_subscriptions=true)
Load member from database.
Definition: adherent.class.php:1351
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:520
CommonObject\setUpperOrLowerCase
setUpperOrLowerCase()
Set to upper or ucwords/lower if needed.
Definition: commonobject.class.php:745
Adherent\send_an_email
send_an_email($text, $subject, $filename_list=array(), $mimetype_list=array(), $mimefilename_list=array(), $addr_cc="", $addr_bcc="", $deliveryreceipt=0, $msgishtml=-1, $errors_to='', $moreinheader='')
Function sending an email to the current member with the text supplied in parameter.
Definition: adherent.class.php:405
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4993
Adherent\fetch_subscriptions
fetch_subscriptions()
Function to get member subscriptions data: subscriptions, first_subscription_date,...
Definition: adherent.class.php:1501
Adherent\load_board
load_board($user, $mode)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
Definition: adherent.class.php:2453
ref
$object ref
Definition: info.php:78
Translate
Class to manage translations.
Definition: translate.class.php:30
MailmanSpip
Class to manage mailman and spip.
Definition: mailmanspip.class.php:40
Adherent\getNomUrl
getNomUrl($withpictoimg=0, $maxlen=0, $option='card', $mode='', $morecss='', $save_lastsearch_value=-1, $notooltip=0, $addlinktonotes=0)
Return clicable name (with picto eventually)
Definition: adherent.class.php:2210
Adherent\getCivilityLabel
getCivilityLabel()
Return civility label of a member.
Definition: adherent.class.php:2185
CMailFile
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Definition: CMailFile.class.php:41
PaymentTerm
Class to manage payment terms records in dictionary.
Definition: paymentterm.class.php:28
getLanguageCodeFromCountryCode
getLanguageCodeFromCountryCode($countrycode)
Return default language from country code.
Definition: functions.lib.php:9141
Facture
Class to manage invoices.
Definition: facture.class.php:60
CommonObject
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Definition: commonobject.class.php:44
CommonObject\getFullName
getFullName($langs, $option=0, $nameorder=-1, $maxlen=0)
Return full name (civility+' '+name+' '+lastname)
Definition: commonobject.class.php:717
Adherent\getmorphylib
getmorphylib($morphy='', $addbadge=0)
Return translated label by the nature of a adherent (physical or moral)
Definition: adherent.class.php:526
getArrayOfSocialNetworks
getArrayOfSocialNetworks()
Get array of social network dictionary.
Definition: functions.lib.php:3132
Adherent\LibStatut
LibStatut($status, $need_subscription, $date_end_subscription, $mode=0)
Renvoi le libelle d'un statut donne.
Definition: adherent.class.php:2367
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5823
CMailFile\getValidAddress
static getValidAddress($address, $format, $encode=0, $maxnumberofemail=0)
Return a formatted address string for SMTP protocol.
Definition: CMailFile.class.php:1932
getRandomPassword
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.
Definition: security2.lib.php:482
Adherent\add_to_abo
add_to_abo()
Function to add member into external tools mailing-list, spip, etc.
Definition: adherent.class.php:2082
Adherent\setUserId
setUserId($userid)
Set link to a user.
Definition: adherent.class.php:1211
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2550
WorkboardResponse
Definition: workboardresponse.class.php:24
dol_concatdesc
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
Definition: functions.lib.php:7542
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:4024
CommonObject\commonGenerateDocument
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
Definition: commonobject.class.php:5427
dol_strtoupper
dol_strtoupper($string, $encoding="UTF-8")
Convert a string to upper.
Definition: functions.lib.php:1566
dolGetLdapPasswordHash
dolGetLdapPasswordHash($password, $type='md5')
Returns a specific ldap hash of a password.
Definition: security.lib.php:289
dol_hash
dol_hash($chain, $type='0')
Returns a hash (non reversible encryption) of a string.
Definition: security.lib.php:215
Adherent\load_state_board
load_state_board()
Charge indicateurs this->nb de tableau de bord.
Definition: adherent.class.php:2419
dolGetFirstLetters
dolGetFirstLetters($s, $nbofchar=1)
Return first letters of a strings.
Definition: functions.lib.php:3868
Adherent\subscription
subscription($date, $amount, $accountid=0, $operation='', $label='', $num_chq='', $emetteur_nom='', $emetteur_banque='', $datesubend=0, $fk_type=null)
Insert subscription into database and eventually add links to banks, mailman, etc....
Definition: adherent.class.php:1593
Adherent\_load_ldap_info
_load_ldap_info()
Initialise tableau info (tableau des attributs LDAP)
Definition: adherent.class.php:2665
dol_getIdFromCode
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
Definition: functions.lib.php:8880
Adherent\exclude
exclude($user)
Functiun to exlude (set adherent.status to -2) a member TODO A private note should be added to know w...
Definition: adherent.class.php:2035
Adherent\STATUS_VALIDATED
const STATUS_VALIDATED
Validated status.
Definition: adherent.class.php:360
Adherent\fetch_login
fetch_login($login)
Method to load member from its login.
Definition: adherent.class.php:1291
Adherent\hasDelay
hasDelay()
Return if a member is late (subscription late) or not.
Definition: adherent.class.php:2907
CommonObject\insertExtraFields
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
Definition: commonobject.class.php:6185
Adherent\__construct
__construct($db)
Constructor.
Definition: adherent.class.php:376
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
Adherent\generateDocument
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
Definition: adherent.class.php:2538
Adherent\_load_ldap_dn
_load_ldap_dn($info, $mode=0)
Retourne chaine DN complete dans l'annuaire LDAP pour l'objet.
Definition: adherent.class.php:2640
getCommonSubstitutionArray
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null)
Return array of possible common substitutions.
Definition: functions.lib.php:7569
Adherent\getNbOfEMailings
getNbOfEMailings()
Return number of mass Emailing received by this member with its email.
Definition: adherent.class.php:2851
dol_string_nohtmltag
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
Definition: functions.lib.php:6880
CommonObject\commonReplaceThirdparty
static commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
Definition: commonobject.class.php:8499
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1628
Adherent\initAsSpecimen
initAsSpecimen()
Initialise an instance with random values.
Definition: adherent.class.php:2567
Adherent\update
update($user, $notrigger=0, $nosyncuser=0, $nosyncuserpass=0, $nosyncthirdparty=0, $action='update')
Update a member in database (standard information and password)
Definition: adherent.class.php:693
Subscription
Class to manage subscriptions of foundation members.
Definition: subscription.class.php:33
Adherent
Class to manage members of a foundation.
Definition: adherent.class.php:46
CommonObject\fetch_optionals
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...
Definition: commonobject.class.php:6034
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:82
Adherent\STATUS_EXCLUDED
const STATUS_EXCLUDED
Excluded.
Definition: adherent.class.php:368
Adherent\getLibStatut
getLibStatut($mode=0)
Retourne le libelle du statut d'un adherent (brouillon, valide, resilie, exclu)
Definition: adherent.class.php:2352
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3887
get_default_tva
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
Definition: functions.lib.php:6490
Adherent\replaceThirdparty
static replaceThirdparty($db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
Definition: adherent.class.php:2895
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:137
Adherent\del_to_abo
del_to_abo()
Function to delete a member from external tools like mailing-list, spip, etc.
Definition: adherent.class.php:2134
Adherent\STATUS_DRAFT
const STATUS_DRAFT
Draft status.
Definition: adherent.class.php:356
Adherent\sendReminderForExpiredSubscription
sendReminderForExpiredSubscription($daysbeforeendlist='10')
Send reminders by emails before subscription end CAN BE A CRON TASK.
Definition: adherent.class.php:2932
dol_time_plus_duree
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition: date.lib.php:121
User
Class to manage Dolibarr users.
Definition: user.class.php:46
Paiement
Class to manage payments of customer invoices.
Definition: paiement.class.php:42
Facture\TYPE_STANDARD
const TYPE_STANDARD
Standard invoice.
Definition: facture.class.php:377
CommonObject\deleteExtraFields
deleteExtraFields()
Delete all extra fields values for the current object.
Definition: commonobject.class.php:6145
Adherent\update_end_date
update_end_date($user)
Update denormalized last subscription date.
Definition: adherent.class.php:964
dolGetStatus
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
Definition: functions.lib.php:10745
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4360
dol_htmlentitiesbr
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...
Definition: functions.lib.php:7277
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2951
Adherent\subscriptionComplementaryActions
subscriptionComplementaryActions($subscriptionid, $option, $accountid, $datesubscription, $paymentdate, $operation, $label, $amount, $num_chq, $emetteur_nom='', $emetteur_banque='', $autocreatethirdparty=0, $ext_payment_id='', $ext_payment_site='')
Do complementary actions after subscription recording.
Definition: adherent.class.php:1674
Form\showphoto
static showphoto($modulepart, $object, $width=100, $height=0, $caneditfield=0, $cssclass='photowithmargin', $imagesize='', $addlinktofullsize=1, $cache=0, $forcecapture='', $noexternsourceoverwrite=0)
Return HTML code to output a photo.
Definition: html.form.class.php:9417
CommonObject\call_trigger
call_trigger($triggerName, $user)
Call trigger based on this instance.
Definition: commonobject.class.php:5818
dol_textishtml
dol_textishtml($msg, $option=0)
Return if a text is a html content.
Definition: functions.lib.php:7475
FormMail
Classe permettant la generation du formulaire html d'envoi de mail unitaire Usage: $formail = new For...
Definition: html.formmail.class.php:38
Adherent\fetchPartnerships
fetchPartnerships($mode)
Function to get partnerships array.
Definition: adherent.class.php:1565
dol_mktime
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Definition: functions.lib.php:2863
Adherent\setPassword
setPassword($user, $password='', $isencrypted=0, $notrigger=0, $nosyncuser=0)
Change password of a user.
Definition: adherent.class.php:1113
Adherent\makeSubstitution
makeSubstitution($text)
Make substitution of tags into text with value of current object.
Definition: adherent.class.php:452
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:96
Adherent\setCategories
setCategories($categories)
Sets object to supplied categories.
Definition: adherent.class.php:2881
type
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119
Account
Class to manage bank accounts.
Definition: account.class.php:39
complete_substitutions_array
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...
Definition: functions.lib.php:8290
Adherent\setThirdPartyId
setThirdPartyId($thirdpartyid)
Set link to a third party.
Definition: adherent.class.php:1252