dolibarr  16.0.5
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 
221  public $photo;
222 
228  public $datec;
229 
235  public $datem;
236 
237  public $datevalid;
238 
242  public $gender;
243 
244  public $birth;
245 
249  public $typeid;
250 
254  public $type;
255 
256  public $need_subscription;
257 
258  public $user_id;
259 
260  public $user_login;
261 
262  public $datefin;
263 
264 
265  // Fields loaded by fetch_subscriptions() from member table
266 
267  public $first_subscription_date;
268 
269  public $first_subscription_amount;
270 
271  public $last_subscription_date;
272 
273  public $last_subscription_date_start;
274 
275  public $last_subscription_date_end;
276 
277  public $last_subscription_amount;
278 
279  public $subscriptions = array();
280 
281 
282  // Fields loaded by fetchPartnerships() from partnership table
283 
284  public $partnerships = array();
285 
286 
290  public $oldcopy;
291 
295  public $entity;
296 
300  public $fields = array(
301  'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 10),
302  'ref' => array('type' => 'varchar(30)', 'label' => 'Ref', 'default' => 1, 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 12, 'index' => 1),
303  'entity' => array('type' => 'integer', 'label' => 'Entity', 'default' => 1, 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 15, 'index' => 1),
304  'ref_ext' => array('type' => 'varchar(128)', 'label' => 'Ref ext', 'enabled' => 1, 'visible' => 0, 'position' => 20),
305  'civility' => array('type' => 'varchar(6)', 'label' => 'Civility', 'enabled' => 1, 'visible' => -1, 'position' => 25),
306  'lastname' => array('type' => 'varchar(50)', 'label' => 'Lastname', 'enabled' => 1, 'visible' => -1, 'position' => 30, 'showoncombobox'=>1),
307  'firstname' => array('type' => 'varchar(50)', 'label' => 'Firstname', 'enabled' => 1, 'visible' => -1, 'position' => 35, 'showoncombobox'=>1),
308  'login' => array('type' => 'varchar(50)', 'label' => 'Login', 'enabled' => 1, 'visible' => -1, 'position' => 40),
309  'gender' => array('type' => 'varchar(10)', 'label' => 'Gender', 'enabled' => 1, 'visible' => -1, 'position' => 250),
310  'pass' => array('type' => 'varchar(50)', 'label' => 'Pass', 'enabled' => 1, 'visible' => -1, 'position' => 45),
311  'pass_crypted' => array('type' => 'varchar(128)', 'label' => 'Pass crypted', 'enabled' => 1, 'visible' => -1, 'position' => 50),
312  'fk_adherent_type' => array('type' => 'integer', 'label' => 'Fk adherent type', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 55),
313  'morphy' => array('type' => 'varchar(3)', 'label' => 'MorPhy', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 60),
314  'societe' => array('type' => 'varchar(128)', 'label' => 'Societe', 'enabled' => 1, 'visible' => -1, 'position' => 65, 'showoncombobox'=>2),
315  'fk_soc' => array('type' => 'integer:Societe:societe/class/societe.class.php', 'label' => 'ThirdParty', 'enabled' => 1, 'visible' => -1, 'position' => 70),
316  'address' => array('type' => 'text', 'label' => 'Address', 'enabled' => 1, 'visible' => -1, 'position' => 75),
317  'zip' => array('type' => 'varchar(10)', 'label' => 'Zip', 'enabled' => 1, 'visible' => -1, 'position' => 80),
318  'town' => array('type' => 'varchar(50)', 'label' => 'Town', 'enabled' => 1, 'visible' => -1, 'position' => 85),
319  'state_id' => array('type' => 'integer', 'label' => 'State id', 'enabled' => 1, 'visible' => -1, 'position' => 90),
320  'country' => array('type' => 'integer:Ccountry:core/class/ccountry.class.php', 'label' => 'Country', 'enabled' => 1, 'visible' => -1, 'position' => 95),
321  'email' => array('type' => 'varchar(255)', 'label' => 'Email', 'enabled' => 1, 'visible' => -1, 'position' => 100),
322  'url' =>array('type'=>'varchar(255)', 'label'=>'Url', 'enabled'=>1, 'visible'=>-1, 'position'=>110),
323  'socialnetworks' => array('type' => 'text', 'label' => 'Socialnetworks', 'enabled' => 1, 'visible' => -1, 'position' => 105),
324  'phone' => array('type' => 'varchar(30)', 'label' => 'Phone', 'enabled' => 1, 'visible' => -1, 'position' => 115),
325  'phone_perso' => array('type' => 'varchar(30)', 'label' => 'Phone perso', 'enabled' => 1, 'visible' => -1, 'position' => 120),
326  'phone_mobile' => array('type' => 'varchar(30)', 'label' => 'Phone mobile', 'enabled' => 1, 'visible' => -1, 'position' => 125),
327  'birth' => array('type' => 'date', 'label' => 'DateOfBirth', 'enabled' => 1, 'visible' => -1, 'position' => 130),
328  'photo' => array('type' => 'varchar(255)', 'label' => 'Photo', 'enabled' => 1, 'visible' => -1, 'position' => 135),
329  'public' => array('type' => 'smallint(6)', 'label' => 'Public', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 145),
330  'datefin' => array('type' => 'datetime', 'label' => 'DateEnd', 'enabled' => 1, 'visible' => -1, 'position' => 150),
331  'note_private' => array('type' => 'text', 'label' => 'NotePrivate', 'enabled' => 1, 'visible' => 0, 'position' => 155),
332  'note_public' => array('type' => 'text', 'label' => 'NotePublic', 'enabled' => 1, 'visible' => 0, 'position' => 160),
333  'datevalid' => array('type' => 'datetime', 'label' => 'DateValidation', 'enabled' => 1, 'visible' => -1, 'position' => 165),
334  'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -1, 'position' => 170),
335  'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 175),
336  'fk_user_author' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'Fk user author', 'enabled' => 1, 'visible' => -1, 'position' => 180),
337  'fk_user_mod' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'Fk user mod', 'enabled' => 1, 'visible' => -1, 'position' => 185),
338  'fk_user_valid' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserValidation', 'enabled' => 1, 'visible' => -1, 'position' => 190),
339  'canvas' => array('type' => 'varchar(32)', 'label' => 'Canvas', 'enabled' => 1, 'visible' => -1, 'position' => 195),
340  'statut' => array('type' => 'smallint(6)', 'label' => 'Statut', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 500,
341  'arrayofkeyval' => array(-1 => 'Draft', 1 => 'Validated', 0 => 'MemberStatusResiliatedShort', -2 => 'MemberStatusExcludedShort')),
342  'model_pdf' => array('type' => 'varchar(255)', 'label' => 'Model pdf', 'enabled' => 1, 'visible' => 0, 'position' => 800),
343  'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'visible' => -2, 'position' => 805)
344  );
345 
349  const STATUS_DRAFT = -1;
353  const STATUS_VALIDATED = 1;
357  const STATUS_RESILIATED = 0;
361  const STATUS_EXCLUDED = -2;
362 
363 
369  public function __construct($db)
370  {
371  $this->db = $db;
372  $this->statut = self::STATUS_DRAFT;
373  $this->status = $this->statut;
374  // l'adherent n'est pas public par defaut
375  $this->public = 0;
376  // les champs optionnels sont vides
377  $this->array_options = array();
378  }
379 
380 
381  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
398  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 = '')
399  {
400  // phpcs:enable
401  global $conf, $langs;
402 
403  // Detect if message is HTML
404  if ($msgishtml == -1) {
405  $msgishtml = 0;
406  if (dol_textishtml($text, 0)) {
407  $msgishtml = 1;
408  }
409  }
410 
411  dol_syslog('send_an_email msgishtml='.$msgishtml);
412 
413  $texttosend = $this->makeSubstitution($text);
414  $subjecttosend = $this->makeSubstitution($subject);
415  if ($msgishtml) {
416  $texttosend = dol_htmlentitiesbr($texttosend);
417  }
418 
419  // Envoi mail confirmation
420  $from = $conf->email_from;
421  if (!empty($conf->global->ADHERENT_MAIL_FROM)) {
422  $from = $conf->global->ADHERENT_MAIL_FROM;
423  }
424 
425  $trackid = 'mem'.$this->id;
426 
427  // Send email (substitutionarray must be done just before this)
428  include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
429  $mailfile = new CMailFile($subjecttosend, $this->email, $from, $texttosend, $filename_list, $mimetype_list, $mimefilename_list, $addr_cc, $addr_bcc, $deliveryreceipt, $msgishtml, '', '', $trackid, $moreinheader);
430  if ($mailfile->sendfile()) {
431  return 1;
432  } else {
433  $this->error = $langs->trans("ErrorFailedToSendMail", $from, $this->email).'. '.$mailfile->error;
434  return -1;
435  }
436  }
437 
438 
445  public function makeSubstitution($text)
446  {
447  global $conf, $langs;
448 
449  $birthday = dol_print_date($this->birth, 'day');
450 
451  $msgishtml = 0;
452  if (dol_textishtml($text, 1)) {
453  $msgishtml = 1;
454  }
455 
456  $infos = '';
457  if ($this->civility_id) {
458  $infos .= $langs->transnoentities("UserTitle").": ".$this->getCivilityLabel()."\n";
459  }
460  $infos .= $langs->transnoentities("id").": ".$this->id."\n";
461  $infos .= $langs->transnoentities("ref").": ".$this->ref."\n";
462  $infos .= $langs->transnoentities("Lastname").": ".$this->lastname."\n";
463  $infos .= $langs->transnoentities("Firstname").": ".$this->firstname."\n";
464  $infos .= $langs->transnoentities("Company").": ".$this->company."\n";
465  $infos .= $langs->transnoentities("Address").": ".$this->address."\n";
466  $infos .= $langs->transnoentities("Zip").": ".$this->zip."\n";
467  $infos .= $langs->transnoentities("Town").": ".$this->town."\n";
468  $infos .= $langs->transnoentities("Country").": ".$this->country."\n";
469  $infos .= $langs->transnoentities("EMail").": ".$this->email."\n";
470  $infos .= $langs->transnoentities("PhonePro").": ".$this->phone."\n";
471  $infos .= $langs->transnoentities("PhonePerso").": ".$this->phone_perso."\n";
472  $infos .= $langs->transnoentities("PhoneMobile").": ".$this->phone_mobile."\n";
473  if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
474  $infos .= $langs->transnoentities("Login").": ".$this->login."\n";
475  $infos .= $langs->transnoentities("Password").": ".$this->pass."\n";
476  }
477  $infos .= $langs->transnoentities("Birthday").": ".$birthday."\n";
478  $infos .= $langs->transnoentities("Photo").": ".$this->photo."\n";
479  $infos .= $langs->transnoentities("Public").": ".yn($this->public);
480 
481  // Substitutions
482  $substitutionarray = array(
483  '__ID__' => $this->id,
484  '__REF__' => $this->ref,
485  '__MEMBER_ID__' => $this->id,
486  '__CIVILITY__' => $this->getCivilityLabel(),
487  '__FIRSTNAME__' => $msgishtml ? dol_htmlentitiesbr($this->firstname) : ($this->firstname ? $this->firstname : ''),
488  '__LASTNAME__' => $msgishtml ? dol_htmlentitiesbr($this->lastname) : ($this->lastname ? $this->lastname : ''),
489  '__FULLNAME__' => $msgishtml ? dol_htmlentitiesbr($this->getFullName($langs)) : $this->getFullName($langs),
490  '__COMPANY__' => $msgishtml ? dol_htmlentitiesbr($this->company) : ($this->company ? $this->company : ''),
491  '__ADDRESS__' => $msgishtml ? dol_htmlentitiesbr($this->address) : ($this->address ? $this->address : ''),
492  '__ZIP__' => $msgishtml ? dol_htmlentitiesbr($this->zip) : ($this->zip ? $this->zip : ''),
493  '__TOWN__' => $msgishtml ? dol_htmlentitiesbr($this->town) : ($this->town ? $this->town : ''),
494  '__COUNTRY__' => $msgishtml ? dol_htmlentitiesbr($this->country) : ($this->country ? $this->country : ''),
495  '__EMAIL__' => $msgishtml ? dol_htmlentitiesbr($this->email) : ($this->email ? $this->email : ''),
496  '__BIRTH__' => $msgishtml ? dol_htmlentitiesbr($birthday) : ($birthday ? $birthday : ''),
497  '__PHOTO__' => $msgishtml ? dol_htmlentitiesbr($this->photo) : ($this->photo ? $this->photo : ''),
498  '__LOGIN__' => $msgishtml ? dol_htmlentitiesbr($this->login) : ($this->login ? $this->login : ''),
499  '__PASSWORD__' => $msgishtml ? dol_htmlentitiesbr($this->pass) : ($this->pass ? $this->pass : ''),
500  '__PHONE__' => $msgishtml ? dol_htmlentitiesbr($this->phone) : ($this->phone ? $this->phone : ''),
501  '__PHONEPRO__' => $msgishtml ? dol_htmlentitiesbr($this->phone_perso) : ($this->phone_perso ? $this->phone_perso : ''),
502  '__PHONEMOBILE__' => $msgishtml ? dol_htmlentitiesbr($this->phone_mobile) : ($this->phone_mobile ? $this->phone_mobile : ''),
503  '__TYPE__' => $msgishtml ? dol_htmlentitiesbr($this->type) : ($this->type ? $this->type : '')
504  );
505 
506  complete_substitutions_array($substitutionarray, $langs, $this);
507 
508  return make_substitutions($text, $substitutionarray, $langs);
509  }
510 
511 
518  public function getmorphylib($morphy = '')
519  {
520  global $langs;
521  if (!$morphy) {
522  $morphy = $this->morphy;
523  }
524  if ($morphy == 'phy') {
525  return $langs->trans("Physical");
526  }
527  if ($morphy == 'mor') {
528  return $langs->trans("Moral");
529  }
530  return $morphy;
531  }
532 
540  public function create($user, $notrigger = 0)
541  {
542  global $conf, $langs;
543 
544  $error = 0;
545 
546  $now = dol_now();
547 
548  // Clean parameters
549  $this->import_key = trim($this->import_key);
550 
551  // Check parameters
552  if (!empty($conf->global->ADHERENT_MAIL_REQUIRED) && !isValidEMail($this->email)) {
553  $langs->load("errors");
554  $this->error = $langs->trans("ErrorBadEMail", $this->email);
555  return -1;
556  }
557  if (!$this->datec) {
558  $this->datec = $now;
559  }
560  if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
561  if (empty($this->login)) {
562  $this->error = $langs->trans("ErrorWrongValueForParameterX", "Login");
563  return -1;
564  }
565  }
566 
567  $this->db->begin();
568 
569  // Insert member
570  $sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent";
571  $sql .= " (ref, datec,login,fk_user_author,fk_user_mod,fk_user_valid,morphy,fk_adherent_type,entity,import_key)";
572  $sql .= " VALUES (";
573  $sql .= " '(PROV)'";
574  $sql .= ", '".$this->db->idate($this->datec)."'";
575  $sql .= ", ".($this->login ? "'".$this->db->escape($this->login)."'" : "null");
576  $sql .= ", ".($user->id > 0 ? $user->id : "null"); // Can be null because member can be created by a guest or a script
577  $sql .= ", null, null, '".$this->db->escape($this->morphy)."'";
578  $sql .= ", ".((int) $this->typeid);
579  $sql .= ", ".$conf->entity;
580  $sql .= ", ".(!empty($this->import_key) ? "'".$this->db->escape($this->import_key)."'" : "null");
581  $sql .= ")";
582 
583  dol_syslog(get_class($this)."::create", LOG_DEBUG);
584  $result = $this->db->query($sql);
585  if ($result) {
586  $id = $this->db->last_insert_id(MAIN_DB_PREFIX."adherent");
587  if ($id > 0) {
588  $this->id = $id;
589  $this->ref = (string) $id;
590 
591  // Update minor fields
592  $result = $this->update($user, 1, 1, 0, 0, 'add'); // nosync is 1 to avoid update data of user
593  if ($result < 0) {
594  $this->db->rollback();
595  return -1;
596  }
597 
598  // Add link to user
599  if ($this->user_id) {
600  // Add link to user
601  $sql = "UPDATE ".MAIN_DB_PREFIX."user SET";
602  $sql .= " fk_member = ".((int) $this->id);
603  $sql .= " WHERE rowid = ".((int) $this->user_id);
604  dol_syslog(get_class($this)."::create", LOG_DEBUG);
605  $resql = $this->db->query($sql);
606  if (!$resql) {
607  $this->error = 'Failed to update user to make link with member';
608  $this->db->rollback();
609  return -4;
610  }
611  }
612 
613  if (!$notrigger) {
614  // Call trigger
615  $result = $this->call_trigger('MEMBER_CREATE', $user);
616  if ($result < 0) {
617  $error++;
618  }
619  // End call triggers
620  }
621 
622  if (count($this->errors)) {
623  dol_syslog(get_class($this)."::create ".implode(',', $this->errors), LOG_ERR);
624  $this->db->rollback();
625  return -3;
626  } else {
627  $this->db->commit();
628  return $this->id;
629  }
630  } else {
631  $this->error = 'Failed to get last insert id';
632  dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
633  $this->db->rollback();
634  return -2;
635  }
636  } else {
637  $this->error = $this->db->error();
638  $this->db->rollback();
639  return -1;
640  }
641  }
642 
643 
655  public function update($user, $notrigger = 0, $nosyncuser = 0, $nosyncuserpass = 0, $nosyncthirdparty = 0, $action = 'update')
656  {
657  global $conf, $langs, $hookmanager;
658 
659  require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
660 
661  $nbrowsaffected = 0;
662  $error = 0;
663 
664  dol_syslog(get_class($this)."::update notrigger=".$notrigger.", nosyncuser=".$nosyncuser.", nosyncuserpass=".$nosyncuserpass." nosyncthirdparty=".$nosyncthirdparty.", email=".$this->email);
665 
666  // Clean parameters
667  $this->lastname = trim($this->lastname) ? trim($this->lastname) : trim($this->lastname);
668  $this->firstname = trim($this->firstname) ? trim($this->firstname) : trim($this->firstname);
669  $this->gender = trim($this->gender);
670  $this->address = ($this->address ? $this->address : $this->address);
671  $this->zip = ($this->zip ? $this->zip : $this->zip);
672  $this->town = ($this->town ? $this->town : $this->town);
673  $this->country_id = ($this->country_id > 0 ? $this->country_id : $this->country_id);
674  $this->state_id = ($this->state_id > 0 ? $this->state_id : $this->state_id);
675  $this->setUpperOrLowerCase();
676  $this->note_public = ($this->note_public ? $this->note_public : $this->note_public);
677  $this->note_private = ($this->note_private ? $this->note_private : $this->note_private);
678  $this->url = $this->url ?clean_url($this->url, 0) : '';
679 
680  // Check parameters
681  if (!empty($conf->global->ADHERENT_MAIL_REQUIRED) && !isValidEMail($this->email)) {
682  $langs->load("errors");
683  $this->error = $langs->trans("ErrorBadEMail", $this->email);
684  return -1;
685  }
686 
687  $this->db->begin();
688 
689  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
690  $sql .= " ref = '".$this->db->escape($this->ref)."'";
691  $sql .= ", civility = ".($this->civility_id ? "'".$this->db->escape($this->civility_id)."'" : "null");
692  $sql .= ", firstname = ".($this->firstname ? "'".$this->db->escape($this->firstname)."'" : "null");
693  $sql .= ", lastname = ".($this->lastname ? "'".$this->db->escape($this->lastname)."'" : "null");
694  $sql .= ", gender = ".($this->gender != -1 ? "'".$this->db->escape($this->gender)."'" : "null"); // 'man' or 'woman'
695  $sql .= ", login = ".($this->login ? "'".$this->db->escape($this->login)."'" : "null");
696  $sql .= ", societe = ".($this->company ? "'".$this->db->escape($this->company)."'" : ($this->societe ? "'".$this->db->escape($this->societe)."'" : "null"));
697  if ($this->socid) {
698  $sql .= ", fk_soc = ".($this->socid > 0 ? $this->db->escape($this->socid) : "null"); // Must be modified only when creating from a third-party
699  }
700  $sql .= ", address = ".($this->address ? "'".$this->db->escape($this->address)."'" : "null");
701  $sql .= ", zip = ".($this->zip ? "'".$this->db->escape($this->zip)."'" : "null");
702  $sql .= ", town = ".($this->town ? "'".$this->db->escape($this->town)."'" : "null");
703  $sql .= ", country = ".($this->country_id > 0 ? $this->db->escape($this->country_id) : "null");
704  $sql .= ", state_id = ".($this->state_id > 0 ? $this->db->escape($this->state_id) : "null");
705  $sql .= ", email = '".$this->db->escape($this->email)."'";
706  $sql .= ", url = ".(!empty($this->url) ? "'".$this->db->escape($this->url)."'" : "null");
707  $sql .= ", socialnetworks = ".($this->socialnetworks ? "'".$this->db->escape(json_encode($this->socialnetworks))."'" : "null");
708  $sql .= ", phone = ".($this->phone ? "'".$this->db->escape($this->phone)."'" : "null");
709  $sql .= ", phone_perso = ".($this->phone_perso ? "'".$this->db->escape($this->phone_perso)."'" : "null");
710  $sql .= ", phone_mobile = ".($this->phone_mobile ? "'".$this->db->escape($this->phone_mobile)."'" : "null");
711  $sql .= ", note_private = ".($this->note_private ? "'".$this->db->escape($this->note_private)."'" : "null");
712  $sql .= ", note_public = ".($this->note_public ? "'".$this->db->escape($this->note_public)."'" : "null");
713  $sql .= ", photo = ".($this->photo ? "'".$this->db->escape($this->photo)."'" : "null");
714  $sql .= ", public = '".$this->db->escape($this->public)."'";
715  $sql .= ", statut = ".$this->db->escape($this->statut);
716  $sql .= ", fk_adherent_type = ".$this->db->escape($this->typeid);
717  $sql .= ", morphy = '".$this->db->escape($this->morphy)."'";
718  $sql .= ", birth = ".($this->birth ? "'".$this->db->idate($this->birth)."'" : "null");
719  if ($this->datefin) {
720  $sql .= ", datefin = '".$this->db->idate($this->datefin)."'"; // Must be modified only when deleting a subscription
721  }
722  if ($this->datevalid) {
723  $sql .= ", datevalid = '".$this->db->idate($this->datevalid)."'"; // Must be modified only when validating a member
724  }
725  $sql .= ", fk_user_mod = ".($user->id > 0 ? $user->id : 'null'); // Can be null because member can be create by a guest
726  $sql .= " WHERE rowid = ".((int) $this->id);
727 
728  // If we change the type of membership, we set also label of new type
729  if (!empty($this->oldcopy) && $this->typeid != $this->oldcopy->typeid) {
730  $sql2 = "SELECT libelle as label";
731  $sql2 .= " FROM ".MAIN_DB_PREFIX."adherent_type";
732  $sql2 .= " WHERE rowid = ".((int) $this->typeid);
733  $resql2 = $this->db->query($sql2);
734  if ($resql2) {
735  while ($obj = $this->db->fetch_object($resql2)) {
736  $this->type = $obj->label;
737  }
738  }
739  }
740 
741  dol_syslog(get_class($this)."::update update member", LOG_DEBUG);
742  $resql = $this->db->query($sql);
743  if ($resql) {
744  unset($this->country_code);
745  unset($this->country);
746  unset($this->state_code);
747  unset($this->state);
748 
749  $nbrowsaffected += $this->db->affected_rows($resql);
750 
751  $action = 'update';
752 
753  // Actions on extra fields
754  if (!$error) {
755  $result = $this->insertExtraFields();
756  if ($result < 0) {
757  $error++;
758  }
759  }
760 
761  // Update password
762  if (!$error && $this->pass) {
763  dol_syslog(get_class($this)."::update update password");
764  if ($this->pass != $this->pass_indatabase && $this->pass != $this->pass_indatabase_crypted) {
765  $isencrypted = empty($conf->global->DATABASE_PWD_ENCRYPTED) ? 0 : 1;
766 
767  // If password to set differs from the one found into database
768  $result = $this->setPassword($user, $this->pass, $isencrypted, $notrigger, $nosyncuserpass);
769  if (!$nbrowsaffected) {
770  $nbrowsaffected++;
771  }
772  }
773  }
774 
775  // Remove links to user and replace with new one
776  if (!$error) {
777  dol_syslog(get_class($this)."::update update link to user");
778  $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = NULL WHERE fk_member = ".((int) $this->id);
779  dol_syslog(get_class($this)."::update", LOG_DEBUG);
780  $resql = $this->db->query($sql);
781  if (!$resql) {
782  $this->error = $this->db->error();
783  $this->db->rollback();
784  return -5;
785  }
786  // If there is a user linked to this member
787  if ($this->user_id > 0) {
788  $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = ".((int) $this->id)." WHERE rowid = ".((int) $this->user_id);
789  dol_syslog(get_class($this)."::update", LOG_DEBUG);
790  $resql = $this->db->query($sql);
791  if (!$resql) {
792  $this->error = $this->db->error();
793  $this->db->rollback();
794  return -5;
795  }
796  }
797  }
798 
799  if (!$error && $nbrowsaffected) { // If something has change in main data
800  // Update information on linked user if it is an update
801  if (!$error && $this->user_id > 0 && !$nosyncuser) {
802  require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
803 
804  dol_syslog(get_class($this)."::update update linked user");
805 
806  $luser = new User($this->db);
807  $result = $luser->fetch($this->user_id);
808 
809  if ($result >= 0) {
810  //var_dump($this->user_login);exit;
811  //var_dump($this->login);exit;
812 
813  // 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.
814  if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
815  $luser->login = $this->login;
816  }
817 
818  $luser->ref = $this->ref;
819  $luser->civility_id = $this->civility_id;
820  $luser->firstname = $this->firstname;
821  $luser->lastname = $this->lastname;
822  $luser->gender = $this->gender;
823  $luser->pass = $this->pass;
824  //$luser->socid=$this->fk_soc; // We do not enable this. This may transform a user into an external user.
825 
826  $luser->birth = $this->birth;
827 
828  $luser->address = $this->address;
829  $luser->zip = $this->zip;
830  $luser->town = $this->town;
831  $luser->country_id = $this->country_id;
832  $luser->state_id = $this->state_id;
833 
834  $luser->email = $this->email;
835  $luser->socialnetworks = $this->socialnetworks;
836  $luser->office_phone = $this->phone;
837  $luser->user_mobile = $this->phone_mobile;
838 
839  $luser->fk_member = $this->id;
840 
841  $result = $luser->update($user, 0, 1, 1); // Use nosync to 1 to avoid cyclic updates
842  if ($result < 0) {
843  $this->error = $luser->error;
844  dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
845  $error++;
846  }
847  } else {
848  $this->error = $luser->error;
849  $error++;
850  }
851  }
852 
853  // Update information on linked thirdparty if it is an update
854  if (!$error && $this->fk_soc > 0 && !$nosyncthirdparty) {
855  require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
856 
857  dol_syslog(get_class($this)."::update update linked thirdparty");
858 
859  // This member is linked with a thirdparty, so we also update thirdparty informations
860  // if this is an update.
861  $lthirdparty = new Societe($this->db);
862  $result = $lthirdparty->fetch($this->fk_soc);
863 
864  if ($result > 0) {
865  $lthirdparty->address = $this->address;
866  $lthirdparty->zip = $this->zip;
867  $lthirdparty->town = $this->town;
868  $lthirdparty->email = $this->email;
869  $lthirdparty->socialnetworks = $this->socialnetworks;
870  $lthirdparty->phone = $this->phone;
871  $lthirdparty->state_id = $this->state_id;
872  $lthirdparty->country_id = $this->country_id;
873  //$lthirdparty->phone_mobile=$this->phone_mobile;
874 
875  $result = $lthirdparty->update($this->fk_soc, $user, 0, 1, 1, 'update'); // Use sync to 0 to avoid cyclic updates
876 
877  if ($result < 0) {
878  $this->error = $lthirdparty->error;
879  $this->errors = $lthirdparty->errors;
880  dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
881  $error++;
882  }
883  } elseif ($result < 0) {
884  $this->error = $lthirdparty->error;
885  $error++;
886  }
887  }
888  }
889 
890  if (!$error && !$notrigger) {
891  // Call trigger
892  $result = $this->call_trigger('MEMBER_MODIFY', $user);
893  if ($result < 0) {
894  $error++;
895  }
896  // End call triggers
897  }
898 
899  if (!$error) {
900  $this->db->commit();
901  return $nbrowsaffected;
902  } else {
903  $this->db->rollback();
904  return -1;
905  }
906  } else {
907  $this->db->rollback();
908  $this->error = $this->db->lasterror();
909  return -2;
910  }
911  }
912 
913 
914  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
922  public function update_end_date($user)
923  {
924  // phpcs:enable
925  $this->db->begin();
926 
927  // Search for last subscription id and end date
928  $sql = "SELECT rowid, datec as dateop, dateadh as datedeb, datef as datefin";
929  $sql .= " FROM ".MAIN_DB_PREFIX."subscription";
930  $sql .= " WHERE fk_adherent = ".((int) $this->id);
931  $sql .= " ORDER by dateadh DESC"; // Sort by start subscription date
932 
933  dol_syslog(get_class($this)."::update_end_date", LOG_DEBUG);
934  $resql = $this->db->query($sql);
935  if ($resql) {
936  $obj = $this->db->fetch_object($resql);
937  $dateop = $this->db->jdate($obj->dateop);
938  $datedeb = $this->db->jdate($obj->datedeb);
939  $datefin = $this->db->jdate($obj->datefin);
940 
941  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
942  $sql .= " datefin=".($datefin != '' ? "'".$this->db->idate($datefin)."'" : "null");
943  $sql .= " WHERE rowid = ".((int) $this->id);
944 
945  dol_syslog(get_class($this)."::update_end_date", LOG_DEBUG);
946  $resql = $this->db->query($sql);
947  if ($resql) {
948  $this->last_subscription_date = $dateop;
949  $this->last_subscription_date_start = $datedeb;
950  $this->last_subscription_date_end = $datefin;
951  $this->datefin = $datefin;
952  $this->db->commit();
953  return 1;
954  } else {
955  $this->db->rollback();
956  return -1;
957  }
958  } else {
959  $this->error = $this->db->lasterror();
960  $this->db->rollback();
961  return -1;
962  }
963  }
964 
973  public function delete($rowid, $user, $notrigger = 0)
974  {
975  global $conf, $langs;
976 
977  $result = 0;
978  $error = 0;
979  $errorflag = 0;
980 
981  // Check parameters
982  if (empty($rowid)) {
983  $rowid = $this->id;
984  }
985 
986  $this->db->begin();
987 
988  if (!$error && !$notrigger) {
989  // Call trigger
990  $result = $this->call_trigger('MEMBER_DELETE', $user);
991  if ($result < 0) {
992  $error++;
993  }
994  // End call triggers
995  }
996 
997  // Remove category
998  $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_member WHERE fk_member = ".((int) $rowid);
999  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1000  $resql = $this->db->query($sql);
1001  if (!$resql) {
1002  $error++;
1003  $this->error .= $this->db->lasterror();
1004  $errorflag = -1;
1005  }
1006 
1007  // Remove subscription
1008  if (!$error) {
1009  $sql = "DELETE FROM ".MAIN_DB_PREFIX."subscription WHERE fk_adherent = ".((int) $rowid);
1010  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1011  $resql = $this->db->query($sql);
1012  if (!$resql) {
1013  $error++;
1014  $this->error .= $this->db->lasterror();
1015  $errorflag = -2;
1016  }
1017  }
1018 
1019  // Remove linked user
1020  if (!$error) {
1021  $ret = $this->setUserId(0);
1022  if ($ret < 0) {
1023  $error++;
1024  $this->error .= $this->db->lasterror();
1025  $errorflag = -3;
1026  }
1027  }
1028 
1029  // Removed extrafields
1030  if (!$error) {
1031  $result = $this->deleteExtraFields();
1032  if ($result < 0) {
1033  $error++;
1034  $errorflag = -4;
1035  dol_syslog(get_class($this)."::delete erreur ".$errorflag." ".$this->error, LOG_ERR);
1036  }
1037  }
1038 
1039  // Remove adherent
1040  if (!$error) {
1041  $sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent WHERE rowid = ".((int) $rowid);
1042  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1043  $resql = $this->db->query($sql);
1044  if (!$resql) {
1045  $error++;
1046  $this->error .= $this->db->lasterror();
1047  $errorflag = -5;
1048  }
1049  }
1050 
1051  if (!$error) {
1052  $this->db->commit();
1053  return 1;
1054  } else {
1055  $this->db->rollback();
1056  return $errorflag;
1057  }
1058  }
1059 
1060 
1071  public function setPassword($user, $password = '', $isencrypted = 0, $notrigger = 0, $nosyncuser = 0)
1072  {
1073  global $conf, $langs;
1074 
1075  $error = 0;
1076 
1077  dol_syslog(get_class($this)."::setPassword user=".$user->id." password=".preg_replace('/./i', '*', $password)." isencrypted=".$isencrypted);
1078 
1079  // If new password not provided, we generate one
1080  if (!$password) {
1081  require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
1082  $password = getRandomPassword(false);
1083  }
1084 
1085  // Crypt password
1086  $password_crypted = dol_hash($password);
1087 
1088  $password_indatabase = '';
1089  if (!$isencrypted) {
1090  $password_indatabase = $password;
1091  }
1092 
1093  $this->db->begin();
1094 
1095  // Mise a jour
1096  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent";
1097  $sql .= " SET pass_crypted = '".$this->db->escape($password_crypted)."'";
1098  //if (! empty($conf->global->DATABASE_PWD_ENCRYPTED))
1099  if ($isencrypted) {
1100  $sql .= ", pass = null";
1101  } else {
1102  $sql .= ", pass = '".$this->db->escape($password_indatabase)."'";
1103  }
1104  $sql .= " WHERE rowid = ".((int) $this->id);
1105 
1106  //dol_syslog("Adherent::Password sql=hidden");
1107  dol_syslog(get_class($this)."::setPassword", LOG_DEBUG);
1108  $result = $this->db->query($sql);
1109  if ($result) {
1110  $nbaffectedrows = $this->db->affected_rows($result);
1111 
1112  if ($nbaffectedrows) {
1113  $this->pass = $password;
1114  $this->pass_indatabase = $password_indatabase;
1115  $this->pass_indatabase_crypted = $password_crypted;
1116 
1117  if ($this->user_id && !$nosyncuser) {
1118  require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
1119 
1120  // This member is linked with a user, so we also update users informations
1121  // if this is an update.
1122  $luser = new User($this->db);
1123  $result = $luser->fetch($this->user_id);
1124 
1125  if ($result >= 0) {
1126  $result = $luser->setPassword($user, $this->pass, 0, 0, 1);
1127  if ($result < 0) {
1128  $this->error = $luser->error;
1129  dol_syslog(get_class($this)."::setPassword ".$this->error, LOG_ERR);
1130  $error++;
1131  }
1132  } else {
1133  $this->error = $luser->error;
1134  $error++;
1135  }
1136  }
1137 
1138  if (!$error && !$notrigger) {
1139  // Call trigger
1140  $result = $this->call_trigger('MEMBER_NEW_PASSWORD', $user);
1141  if ($result < 0) {
1142  $error++;
1143  $this->db->rollback();
1144  return -1;
1145  }
1146  // End call triggers
1147  }
1148 
1149  $this->db->commit();
1150  return $this->pass;
1151  } else {
1152  $this->db->rollback();
1153  return 0;
1154  }
1155  } else {
1156  $this->db->rollback();
1157  dol_print_error($this->db);
1158  return -1;
1159  }
1160  }
1161 
1162 
1169  public function setUserId($userid)
1170  {
1171  global $conf, $langs;
1172 
1173  $this->db->begin();
1174 
1175  // If user is linked to this member, remove old link to this member
1176  $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = NULL WHERE fk_member = ".((int) $this->id);
1177  dol_syslog(get_class($this)."::setUserId", LOG_DEBUG);
1178  $resql = $this->db->query($sql);
1179  if (!$resql) {
1180  $this->error = $this->db->error();
1181  $this->db->rollback();
1182  return -1;
1183  }
1184 
1185  // Set link to user
1186  if ($userid > 0) {
1187  $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = ".((int) $this->id);
1188  $sql .= " WHERE rowid = ".((int) $userid);
1189  dol_syslog(get_class($this)."::setUserId", LOG_DEBUG);
1190  $resql = $this->db->query($sql);
1191  if (!$resql) {
1192  $this->error = $this->db->error();
1193  $this->db->rollback();
1194  return -2;
1195  }
1196  }
1197 
1198  $this->db->commit();
1199 
1200  return 1;
1201  }
1202 
1203 
1210  public function setThirdPartyId($thirdpartyid)
1211  {
1212  global $conf, $langs;
1213 
1214  $this->db->begin();
1215 
1216  // Remove link to third party onto any other members
1217  if ($thirdpartyid > 0) {
1218  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET fk_soc = null";
1219  $sql .= " WHERE fk_soc = ".((int) $thirdpartyid);
1220  $sql .= " AND entity = ".$conf->entity;
1221  dol_syslog(get_class($this)."::setThirdPartyId", LOG_DEBUG);
1222  $resql = $this->db->query($sql);
1223  }
1224 
1225  // Add link to third party for current member
1226  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET fk_soc = ".($thirdpartyid > 0 ? $thirdpartyid : 'null');
1227  $sql .= " WHERE rowid = ".((int) $this->id);
1228 
1229  dol_syslog(get_class($this)."::setThirdPartyId", LOG_DEBUG);
1230  $resql = $this->db->query($sql);
1231  if ($resql) {
1232  $this->db->commit();
1233  return 1;
1234  } else {
1235  $this->error = $this->db->error();
1236  $this->db->rollback();
1237  return -1;
1238  }
1239  }
1240 
1241 
1242  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1249  public function fetch_login($login)
1250  {
1251  // phpcs:enable
1252  global $conf;
1253 
1254  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."adherent";
1255  $sql .= " WHERE login='".$this->db->escape($login)."'";
1256  $sql .= " AND entity = ".$conf->entity;
1257 
1258  $resql = $this->db->query($sql);
1259  if ($resql) {
1260  if ($this->db->num_rows($resql)) {
1261  $obj = $this->db->fetch_object($resql);
1262  $this->fetch($obj->rowid);
1263  }
1264  } else {
1265  dol_print_error($this->db);
1266  }
1267  }
1268 
1269  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1277  public function fetch_name($firstname, $lastname)
1278  {
1279  // phpcs:enable
1280  global $conf;
1281 
1282  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."adherent";
1283  $sql .= " WHERE firstname='".$this->db->escape($firstname)."'";
1284  $sql .= " AND lastname='".$this->db->escape($lastname)."'";
1285  $sql .= " AND entity = ".$conf->entity;
1286 
1287  $resql = $this->db->query($sql);
1288  if ($resql) {
1289  if ($this->db->num_rows($resql)) {
1290  $obj = $this->db->fetch_object($resql);
1291  $this->fetch($obj->rowid);
1292  }
1293  } else {
1294  dol_print_error($this->db);
1295  }
1296  }
1297 
1309  public function fetch($rowid, $ref = '', $fk_soc = '', $ref_ext = '', $fetch_optionals = true, $fetch_subscriptions = true)
1310  {
1311  global $langs;
1312 
1313  $sql = "SELECT d.rowid, d.ref, d.ref_ext, d.civility as civility_code, d.gender, d.firstname, d.lastname,";
1314  $sql .= " d.societe as company, d.fk_soc, d.statut, d.public, d.address, d.zip, d.town, d.note_private,";
1315  $sql .= " d.note_public,";
1316  $sql .= " d.email, d.url, d.socialnetworks, d.phone, d.phone_perso, d.phone_mobile, d.login, d.pass, d.pass_crypted,";
1317  $sql .= " d.photo, d.fk_adherent_type, d.morphy, d.entity,";
1318  $sql .= " d.datec as datec,";
1319  $sql .= " d.tms as datem,";
1320  $sql .= " d.datefin as datefin,";
1321  $sql .= " d.birth as birthday,";
1322  $sql .= " d.datevalid as datev,";
1323  $sql .= " d.country,";
1324  $sql .= " d.state_id,";
1325  $sql .= " d.model_pdf,";
1326  $sql .= " c.rowid as country_id, c.code as country_code, c.label as country,";
1327  $sql .= " dep.nom as state, dep.code_departement as state_code,";
1328  $sql .= " t.libelle as type, t.subscription as subscription,";
1329  $sql .= " u.rowid as user_id, u.login as user_login";
1330  $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as t, ".MAIN_DB_PREFIX."adherent as d";
1331  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON d.country = c.rowid";
1332  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as dep ON d.state_id = dep.rowid";
1333  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON d.rowid = u.fk_member";
1334  $sql .= " WHERE d.fk_adherent_type = t.rowid";
1335  if ($rowid) {
1336  $sql .= " AND d.rowid=".((int) $rowid);
1337  } elseif ($ref || $fk_soc) {
1338  $sql .= " AND d.entity IN (".getEntity('adherent').")";
1339  if ($ref) {
1340  $sql .= " AND d.ref='".$this->db->escape($ref)."'";
1341  } elseif ($fk_soc > 0) {
1342  $sql .= " AND d.fk_soc=".((int) $fk_soc);
1343  }
1344  } elseif ($ref_ext) {
1345  $sql .= " AND d.ref_ext='".$this->db->escape($ref_ext)."'";
1346  }
1347 
1348  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
1349  $resql = $this->db->query($sql);
1350  if ($resql) {
1351  if ($this->db->num_rows($resql)) {
1352  $obj = $this->db->fetch_object($resql);
1353 
1354  $this->entity = $obj->entity;
1355  $this->id = $obj->rowid;
1356  $this->ref = $obj->ref;
1357  $this->ref_ext = $obj->ref_ext;
1358 
1359  $this->civility_id = $obj->civility_code; // Bad. Kept for backard compatibility
1360  $this->civility_code = $obj->civility_code;
1361  $this->civility = $obj->civility_code ? ($langs->trans("Civility".$obj->civility_code) != ("Civility".$obj->civility_code) ? $langs->trans("Civility".$obj->civility_code) : $obj->civility_code) : '';
1362 
1363  $this->firstname = $obj->firstname;
1364  $this->lastname = $obj->lastname;
1365  $this->gender = $obj->gender;
1366  $this->login = $obj->login;
1367  $this->societe = $obj->company;
1368  $this->company = $obj->company;
1369  $this->socid = $obj->fk_soc;
1370  $this->fk_soc = $obj->fk_soc; // For backward compatibility
1371  $this->address = $obj->address;
1372  $this->zip = $obj->zip;
1373  $this->town = $obj->town;
1374 
1375  $this->pass = $obj->pass;
1376  $this->pass_indatabase = $obj->pass;
1377  $this->pass_indatabase_crypted = $obj->pass_crypted;
1378 
1379  $this->state_id = $obj->state_id;
1380  $this->state_code = $obj->state_id ? $obj->state_code : '';
1381  $this->state = $obj->state_id ? $obj->state : '';
1382 
1383  $this->country_id = $obj->country_id;
1384  $this->country_code = $obj->country_code;
1385  if ($langs->trans("Country".$obj->country_code) != "Country".$obj->country_code) {
1386  $this->country = $langs->transnoentitiesnoconv("Country".$obj->country_code);
1387  } else {
1388  $this->country = $obj->country;
1389  }
1390 
1391  $this->phone = $obj->phone;
1392  $this->phone_perso = $obj->phone_perso;
1393  $this->phone_mobile = $obj->phone_mobile;
1394  $this->email = $obj->email;
1395  $this->url = $obj->url;
1396 
1397  $this->socialnetworks = (array) json_decode($obj->socialnetworks, true);
1398 
1399  $this->photo = $obj->photo;
1400  $this->statut = $obj->statut;
1401  $this->status = $obj->statut;
1402  $this->public = $obj->public;
1403 
1404  $this->datec = $this->db->jdate($obj->datec);
1405  $this->date_creation = $this->db->jdate($obj->datec);
1406  $this->datem = $this->db->jdate($obj->datem);
1407  $this->date_modification = $this->db->jdate($obj->datem);
1408  $this->datefin = $this->db->jdate($obj->datefin);
1409  $this->datevalid = $this->db->jdate($obj->datev);
1410  $this->date_validation = $this->db->jdate($obj->datev);
1411  $this->birth = $this->db->jdate($obj->birthday);
1412 
1413  $this->note_private = $obj->note_private;
1414  $this->note_public = $obj->note_public;
1415  $this->morphy = $obj->morphy;
1416 
1417  $this->typeid = $obj->fk_adherent_type;
1418  $this->type = $obj->type;
1419  $this->need_subscription = $obj->subscription;
1420 
1421  $this->user_id = $obj->user_id;
1422  $this->user_login = $obj->user_login;
1423 
1424  $this->model_pdf = $obj->model_pdf;
1425 
1426  // Retrieve all extrafield
1427  // fetch optionals attributes and labels
1428  if ($fetch_optionals) {
1429  $this->fetch_optionals();
1430  }
1431 
1432  // Load other properties
1433  if ($fetch_subscriptions) {
1434  $result = $this->fetch_subscriptions();
1435  }
1436 
1437  return $this->id;
1438  } else {
1439  return 0;
1440  }
1441  } else {
1442  $this->error = $this->db->lasterror();
1443  return -1;
1444  }
1445  }
1446 
1447 
1448  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1457  public function fetch_subscriptions()
1458  {
1459  // phpcs:enable
1460  global $langs;
1461 
1462  require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
1463 
1464  $sql = "SELECT c.rowid, c.fk_adherent, c.fk_type, c.subscription, c.note, c.fk_bank,";
1465  $sql .= " c.tms as datem,";
1466  $sql .= " c.datec as datec,";
1467  $sql .= " c.dateadh as dateh,";
1468  $sql .= " c.datef as datef";
1469  $sql .= " FROM ".MAIN_DB_PREFIX."subscription as c";
1470  $sql .= " WHERE c.fk_adherent = ".((int) $this->id);
1471  $sql .= " ORDER BY c.dateadh";
1472  dol_syslog(get_class($this)."::fetch_subscriptions", LOG_DEBUG);
1473 
1474  $resql = $this->db->query($sql);
1475  if ($resql) {
1476  $this->subscriptions = array();
1477 
1478  $i = 0;
1479  while ($obj = $this->db->fetch_object($resql)) {
1480  if ($i == 0) {
1481  $this->first_subscription_date = $this->db->jdate($obj->datec);
1482  $this->first_subscription_date_start = $this->db->jdate($obj->dateh);
1483  $this->first_subscription_date_end = $this->db->jdate($obj->datef);
1484  $this->first_subscription_amount = $obj->subscription;
1485  }
1486  $this->last_subscription_date = $this->db->jdate($obj->datec);
1487  $this->last_subscription_date_start = $this->db->jdate($obj->dateh);
1488  $this->last_subscription_date_end = $this->db->jdate($obj->datef);
1489  $this->last_subscription_amount = $obj->subscription;
1490 
1491  $subscription = new Subscription($this->db);
1492  $subscription->id = $obj->rowid;
1493  $subscription->fk_adherent = $obj->fk_adherent;
1494  $subscription->fk_type = $obj->fk_type;
1495  $subscription->amount = $obj->subscription;
1496  $subscription->note = $obj->note;
1497  $subscription->fk_bank = $obj->fk_bank;
1498  $subscription->datem = $this->db->jdate($obj->datem);
1499  $subscription->datec = $this->db->jdate($obj->datec);
1500  $subscription->dateh = $this->db->jdate($obj->dateh);
1501  $subscription->datef = $this->db->jdate($obj->datef);
1502 
1503  $this->subscriptions[] = $subscription;
1504 
1505  $i++;
1506  }
1507  return 1;
1508  } else {
1509  $this->error = $this->db->error().' sql='.$sql;
1510  return -1;
1511  }
1512  }
1513 
1514 
1521  public function fetchPartnerships($mode)
1522  {
1523  global $langs;
1524 
1525  require_once DOL_DOCUMENT_ROOT.'/partnership/class/partnership.class.php';
1526 
1527 
1528  $this->partnerships[] = array();
1529 
1530  return 1;
1531  }
1532 
1533 
1549  public function subscription($date, $amount, $accountid = 0, $operation = '', $label = '', $num_chq = '', $emetteur_nom = '', $emetteur_banque = '', $datesubend = 0, $fk_type = null)
1550  {
1551  global $conf, $langs, $user;
1552 
1553  require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
1554 
1555  $error = 0;
1556 
1557  // Clean parameters
1558  if (!$amount) {
1559  $amount = 0;
1560  }
1561 
1562  $this->db->begin();
1563 
1564  if ($datesubend) {
1565  $datefin = $datesubend;
1566  } else {
1567  // If no end date, end date = date + 1 year - 1 day
1568  $datefin = dol_time_plus_duree($date, 1, 'y');
1569  $datefin = dol_time_plus_duree($datefin, -1, 'd');
1570  }
1571 
1572  // Create subscription
1573  $subscription = new Subscription($this->db);
1574  $subscription->fk_adherent = $this->id;
1575  $subscription->dateh = $date; // Date of new subscription
1576  $subscription->datef = $datefin; // End data of new subscription
1577  $subscription->amount = $amount;
1578  $subscription->note = $label; // deprecated
1579  $subscription->note_public = $label;
1580  $subscription->fk_type = $fk_type;
1581 
1582  $rowid = $subscription->create($user);
1583  if ($rowid > 0) {
1584  // Update denormalized subscription end date (read database subscription to find values)
1585  // This will also update this->datefin
1586  $result = $this->update_end_date($user);
1587  if ($result > 0) {
1588  // Change properties of object (used by triggers)
1589  $this->last_subscription_date = dol_now();
1590  $this->last_subscription_date_start = $date;
1591  $this->last_subscription_date_end = $datefin;
1592  $this->last_subscription_amount = $amount;
1593  }
1594 
1595  if (!$error) {
1596  $this->db->commit();
1597  return $rowid;
1598  } else {
1599  $this->db->rollback();
1600  return -2;
1601  }
1602  } else {
1603  $this->error = $subscription->error;
1604  $this->errors = $subscription->errors;
1605  $this->db->rollback();
1606  return -1;
1607  }
1608  }
1609 
1610 
1630  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 = '')
1631  {
1632  global $conf, $langs, $user, $mysoc;
1633 
1634  $error = 0;
1635 
1636  $this->invoice = null; // This will contains invoice if an invoice is created
1637 
1638  dol_syslog("subscriptionComplementaryActions subscriptionid=".$subscriptionid." option=".$option." accountid=".$accountid." datesubscription=".$datesubscription." paymentdate=".
1639  $paymentdate." label=".$label." amount=".$amount." num_chq=".$num_chq." autocreatethirdparty=".$autocreatethirdparty);
1640 
1641  // Insert into bank account directlty (if option choosed for) + link to llx_subscription if option is 'bankdirect'
1642  if ($option == 'bankdirect' && $accountid) {
1643  require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
1644 
1645  $acct = new Account($this->db);
1646  $result = $acct->fetch($accountid);
1647 
1648  $dateop = $paymentdate;
1649 
1650  $insertid = $acct->addline($dateop, $operation, $label, $amount, $num_chq, '', $user, $emetteur_nom, $emetteur_banque);
1651  if ($insertid > 0) {
1652  $inserturlid = $acct->add_url_line($insertid, $this->id, DOL_URL_ROOT.'/adherents/card.php?rowid=', $this->getFullname($langs), 'member');
1653  if ($inserturlid > 0) {
1654  // Update table subscription
1655  $sql = "UPDATE ".MAIN_DB_PREFIX."subscription SET fk_bank=".((int) $insertid);
1656  $sql .= " WHERE rowid=".((int) $subscriptionid);
1657 
1658  dol_syslog("subscription::subscription", LOG_DEBUG);
1659  $resql = $this->db->query($sql);
1660  if (!$resql) {
1661  $error++;
1662  $this->error = $this->db->lasterror();
1663  $this->errors[] = $this->error;
1664  }
1665  } else {
1666  $error++;
1667  $this->error = $acct->error;
1668  $this->errors = $acct->errors;
1669  }
1670  } else {
1671  $error++;
1672  $this->error = $acct->error;
1673  $this->errors = $acct->errors;
1674  }
1675  }
1676 
1677  // If option choosed, we create invoice
1678  if (($option == 'bankviainvoice' && $accountid) || $option == 'invoiceonly') {
1679  require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1680  require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/paymentterm.class.php';
1681 
1682  $invoice = new Facture($this->db);
1683  $customer = new Societe($this->db);
1684 
1685  if (!$error) {
1686  if (!($this->fk_soc > 0)) { // If not yet linked to a company
1687  if ($autocreatethirdparty) {
1688  // Create a linked thirdparty to member
1689  $companyalias = '';
1690  $fullname = $this->getFullName($langs);
1691 
1692  if ($this->morphy == 'mor') {
1693  $companyname = $this->company;
1694  if (!empty($fullname)) {
1695  $companyalias = $fullname;
1696  }
1697  } else {
1698  $companyname = $fullname;
1699  if (!empty($this->company)) {
1700  $companyalias = $this->company;
1701  }
1702  }
1703 
1704  $result = $customer->create_from_member($this, $companyname, $companyalias);
1705  if ($result < 0) {
1706  $this->error = $customer->error;
1707  $this->errors = $customer->errors;
1708  $error++;
1709  } else {
1710  $this->fk_soc = $result;
1711  }
1712  } else {
1713  $langs->load("errors");
1714  $this->error = $langs->trans("ErrorMemberNotLinkedToAThirpartyLinkOrCreateFirst");
1715  $this->errors[] = $this->error;
1716  $error++;
1717  }
1718  }
1719  }
1720  if (!$error) {
1721  $result = $customer->fetch($this->fk_soc);
1722  if ($result <= 0) {
1723  $this->error = $customer->error;
1724  $this->errors = $customer->errors;
1725  $error++;
1726  }
1727  }
1728 
1729  if (!$error) {
1730  // Create draft invoice
1731  $invoice->type = Facture::TYPE_STANDARD;
1732  $invoice->cond_reglement_id = $customer->cond_reglement_id;
1733  if (empty($invoice->cond_reglement_id)) {
1734  $paymenttermstatic = new PaymentTerm($this->db);
1735  $invoice->cond_reglement_id = $paymenttermstatic->getDefaultId();
1736  if (empty($invoice->cond_reglement_id)) {
1737  $error++;
1738  $this->error = 'ErrorNoPaymentTermRECEPFound';
1739  $this->errors[] = $this->error;
1740  }
1741  }
1742  $invoice->socid = $this->fk_soc;
1743  //$invoice->date = $datesubscription;
1744  $invoice->date = dol_now();
1745 
1746  // Possibility to add external linked objects with hooks
1747  $invoice->linked_objects['subscription'] = $subscriptionid;
1748  if (!empty($_POST['other_linked_objects']) && is_array($_POST['other_linked_objects'])) {
1749  $invoice->linked_objects = array_merge($invoice->linked_objects, $_POST['other_linked_objects']);
1750  }
1751 
1752  $result = $invoice->create($user);
1753  if ($result <= 0) {
1754  $this->error = $invoice->error;
1755  $this->errors = $invoice->errors;
1756  $error++;
1757  } else {
1758  $this->invoice = $invoice;
1759  }
1760  }
1761 
1762  if (!$error) {
1763  // Add line to draft invoice
1764  $idprodsubscription = 0;
1765  if (!empty($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS) && (!empty($conf->product->enabled) || !empty($conf->service->enabled))) {
1766  $idprodsubscription = $conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS;
1767  }
1768 
1769  $vattouse = 0;
1770  if (isset($conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS) && $conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS == 'defaultforfoundationcountry') {
1771  $vattouse = get_default_tva($mysoc, $mysoc, $idprodsubscription);
1772  }
1773  //print xx".$vattouse." - ".$mysoc." - ".$customer;exit;
1774  $result = $invoice->addline($label, 0, 1, $vattouse, 0, 0, $idprodsubscription, 0, $datesubscription, '', 0, 0, '', 'TTC', $amount, 1);
1775  if ($result <= 0) {
1776  $this->error = $invoice->error;
1777  $this->errors = $invoice->errors;
1778  $error++;
1779  }
1780  }
1781 
1782  if (!$error) {
1783  // Validate invoice
1784  $result = $invoice->validate($user);
1785  if ($result <= 0) {
1786  $this->error = $invoice->error;
1787  $this->errors = $invoice->errors;
1788  $error++;
1789  }
1790  }
1791 
1792  if (!$error) {
1793  // TODO Link invoice with subscription ?
1794  }
1795 
1796  // Add payment onto invoice
1797  if (!$error && $option == 'bankviainvoice' && $accountid) {
1798  require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
1799  require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
1800  require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
1801 
1802  $amounts = array();
1803  $amounts[$invoice->id] = price2num($amount);
1804 
1805  $paiement = new Paiement($this->db);
1806  $paiement->datepaye = $paymentdate;
1807  $paiement->amounts = $amounts;
1808  $paiement->paiementcode = $operation;
1809  $paiement->paiementid = dol_getIdFromCode($this->db, $operation, 'c_paiement', 'code', 'id', 1);
1810  $paiement->num_payment = $num_chq;
1811  $paiement->note_public = $label;
1812  $paiement->ext_payment_id = $ext_payment_id;
1813  $paiement->ext_payment_site = $ext_payment_site;
1814 
1815  if (!$error) {
1816  // Create payment line for invoice
1817  $paiement_id = $paiement->create($user);
1818  if (!($paiement_id > 0)) {
1819  $this->error = $paiement->error;
1820  $this->errors = $paiement->errors;
1821  $error++;
1822  }
1823  }
1824 
1825  if (!$error) {
1826  // Add transaction into bank account
1827  $bank_line_id = $paiement->addPaymentToBank($user, 'payment', '(SubscriptionPayment)', $accountid, $emetteur_nom, $emetteur_banque);
1828  if (!($bank_line_id > 0)) {
1829  $this->error = $paiement->error;
1830  $this->errors = $paiement->errors;
1831  $error++;
1832  }
1833  }
1834 
1835  if (!$error && !empty($bank_line_id)) {
1836  // Update fk_bank into subscription table
1837  $sql = 'UPDATE '.MAIN_DB_PREFIX.'subscription SET fk_bank='.((int) $bank_line_id);
1838  $sql .= ' WHERE rowid='.((int) $subscriptionid);
1839 
1840  $result = $this->db->query($sql);
1841  if (!$result) {
1842  $error++;
1843  }
1844  }
1845 
1846  if (!$error) {
1847  // Set invoice as paid
1848  $invoice->setPaid($user);
1849  }
1850  }
1851 
1852  if (!$error) {
1853  // Define output language
1854  $outputlangs = $langs;
1855  $newlang = '';
1856  $lang_id = GETPOST('lang_id');
1857  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && !empty($lang_id)) {
1858  $newlang = $lang_id;
1859  }
1860  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
1861  $newlang = $customer->default_lang;
1862  }
1863  if (!empty($newlang)) {
1864  $outputlangs = new Translate("", $conf);
1865  $outputlangs->setDefaultLang($newlang);
1866  }
1867  // Generate PDF (whatever is option MAIN_DISABLE_PDF_AUTOUPDATE) so we can include it into email
1868  //if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
1869 
1870  $invoice->generateDocument($invoice->model_pdf, $outputlangs);
1871  }
1872  }
1873 
1874  if ($error) {
1875  return -1;
1876  } else {
1877  return 1;
1878  }
1879  }
1880 
1881 
1888  public function validate($user)
1889  {
1890  global $langs, $conf;
1891 
1892  $error = 0;
1893  $now = dol_now();
1894 
1895  // Check parameters
1896  if ($this->statut == self::STATUS_VALIDATED) {
1897  dol_syslog(get_class($this)."::validate statut of member does not allow this", LOG_WARNING);
1898  return 0;
1899  }
1900 
1901  $this->db->begin();
1902 
1903  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
1904  $sql .= " statut = ".self::STATUS_VALIDATED;
1905  $sql .= ", datevalid = '".$this->db->idate($now)."'";
1906  $sql .= ", fk_user_valid = ".((int) $user->id);
1907  $sql .= " WHERE rowid = ".((int) $this->id);
1908 
1909  dol_syslog(get_class($this)."::validate", LOG_DEBUG);
1910  $result = $this->db->query($sql);
1911  if ($result) {
1912  $this->statut = self::STATUS_VALIDATED;
1913 
1914  // Call trigger
1915  $result = $this->call_trigger('MEMBER_VALIDATE', $user);
1916  if ($result < 0) {
1917  $error++;
1918  $this->db->rollback();
1919  return -1;
1920  }
1921  // End call triggers
1922 
1923  $this->datevalid = $now;
1924 
1925  $this->db->commit();
1926  return 1;
1927  } else {
1928  $this->error = $this->db->error();
1929  $this->db->rollback();
1930  return -1;
1931  }
1932  }
1933 
1934 
1941  public function resiliate($user)
1942  {
1943  global $langs, $conf;
1944 
1945  $error = 0;
1946 
1947  // Check parameters
1948  if ($this->statut == self::STATUS_RESILIATED) {
1949  dol_syslog(get_class($this)."::resiliate statut of member does not allow this", LOG_WARNING);
1950  return 0;
1951  }
1952 
1953  $this->db->begin();
1954 
1955  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
1956  $sql .= " statut = ".self::STATUS_RESILIATED;
1957  $sql .= ", fk_user_valid=".$user->id;
1958  $sql .= " WHERE rowid = ".((int) $this->id);
1959 
1960  $result = $this->db->query($sql);
1961  if ($result) {
1962  $this->statut = self::STATUS_RESILIATED;
1963 
1964  // Call trigger
1965  $result = $this->call_trigger('MEMBER_RESILIATE', $user);
1966  if ($result < 0) {
1967  $error++;
1968  $this->db->rollback();
1969  return -1;
1970  }
1971  // End call triggers
1972 
1973  $this->db->commit();
1974  return 1;
1975  } else {
1976  $this->error = $this->db->error();
1977  $this->db->rollback();
1978  return -1;
1979  }
1980  }
1981 
1991  public function exclude($user)
1992  {
1993  global $langs, $conf;
1994 
1995  $error = 0;
1996 
1997  // Check parameters
1998  if ($this->statut == self::STATUS_EXCLUDED) {
1999  dol_syslog(get_class($this)."::resiliate statut of member does not allow this", LOG_WARNING);
2000  return 0;
2001  }
2002 
2003  $this->db->begin();
2004 
2005  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
2006  $sql .= " statut = ".self::STATUS_EXCLUDED;
2007  $sql .= ", fk_user_valid=".$user->id;
2008  $sql .= " WHERE rowid = ".((int) $this->id);
2009 
2010  $result = $this->db->query($sql);
2011  if ($result) {
2012  $this->statut = self::STATUS_EXCLUDED;
2013 
2014  // Call trigger
2015  $result = $this->call_trigger('MEMBER_EXCLUDE', $user);
2016  if ($result < 0) {
2017  $error++;
2018  $this->db->rollback();
2019  return -1;
2020  }
2021  // End call triggers
2022 
2023  $this->db->commit();
2024  return 1;
2025  } else {
2026  $this->error = $this->db->error();
2027  $this->db->rollback();
2028  return -1;
2029  }
2030  }
2031 
2032  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2038  public function add_to_abo()
2039  {
2040  // phpcs:enable
2041  global $conf, $langs;
2042 
2043  include_once DOL_DOCUMENT_ROOT.'/mailmanspip/class/mailmanspip.class.php';
2044  $mailmanspip = new MailmanSpip($this->db);
2045 
2046  $err = 0;
2047 
2048  // mailman
2049  if (!empty($conf->global->ADHERENT_USE_MAILMAN) && !empty($conf->mailmanspip->enabled)) {
2050  $result = $mailmanspip->add_to_mailman($this);
2051 
2052  if ($result < 0) {
2053  if (!empty($mailmanspip->error)) {
2054  $this->errors[] = $mailmanspip->error;
2055  }
2056  $err += 1;
2057  }
2058  foreach ($mailmanspip->mladded_ko as $tmplist => $tmpemail) {
2059  $langs->load("errors");
2060  $this->errors[] = $langs->trans("ErrorFailedToAddToMailmanList", $tmpemail, $tmplist);
2061  }
2062  foreach ($mailmanspip->mladded_ok as $tmplist => $tmpemail) {
2063  $langs->load("mailmanspip");
2064  $this->mesgs[] = $langs->trans("SuccessToAddToMailmanList", $tmpemail, $tmplist);
2065  }
2066  }
2067 
2068  // spip
2069  if (!empty($conf->global->ADHERENT_USE_SPIP) && !empty($conf->mailmanspip->enabled)) {
2070  $result = $mailmanspip->add_to_spip($this);
2071  if ($result < 0) {
2072  $this->errors[] = $mailmanspip->error;
2073  $err += 1;
2074  }
2075  }
2076  if ($err) {
2077  return -$err;
2078  } else {
2079  return 1;
2080  }
2081  }
2082 
2083 
2084  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2090  public function del_to_abo()
2091  {
2092  // phpcs:enable
2093  global $conf, $langs;
2094 
2095  include_once DOL_DOCUMENT_ROOT.'/mailmanspip/class/mailmanspip.class.php';
2096  $mailmanspip = new MailmanSpip($this->db);
2097 
2098  $err = 0;
2099 
2100  // mailman
2101  if (!empty($conf->global->ADHERENT_USE_MAILMAN)) {
2102  $result = $mailmanspip->del_to_mailman($this);
2103  if ($result < 0) {
2104  if (!empty($mailmanspip->error)) {
2105  $this->errors[] = $mailmanspip->error;
2106  }
2107  $err += 1;
2108  }
2109 
2110  foreach ($mailmanspip->mlremoved_ko as $tmplist => $tmpemail) {
2111  $langs->load("errors");
2112  $this->errors[] = $langs->trans("ErrorFailedToRemoveToMailmanList", $tmpemail, $tmplist);
2113  }
2114  foreach ($mailmanspip->mlremoved_ok as $tmplist => $tmpemail) {
2115  $langs->load("mailmanspip");
2116  $this->mesgs[] = $langs->trans("SuccessToRemoveToMailmanList", $tmpemail, $tmplist);
2117  }
2118  }
2119 
2120  if ($conf->global->ADHERENT_USE_SPIP && !empty($conf->mailmanspip->enabled)) {
2121  $result = $mailmanspip->del_to_spip($this);
2122  if ($result < 0) {
2123  $this->errors[] = $mailmanspip->error;
2124  $err += 1;
2125  }
2126  }
2127  if ($err) {
2128  // error
2129  return -$err;
2130  } else {
2131  return 1;
2132  }
2133  }
2134 
2135 
2141  public function getCivilityLabel()
2142  {
2143  global $langs;
2144  $langs->load("dict");
2145 
2146  $code = (empty($this->civility_id) ? '' : $this->civility_id);
2147  if (empty($code)) {
2148  return '';
2149  }
2150  return $langs->getLabelFromKey($this->db, "Civility".$code, "c_civility", "code", "label", $code);
2151  }
2152 
2166  public function getNomUrl($withpictoimg = 0, $maxlen = 0, $option = 'card', $mode = '', $morecss = '', $save_lastsearch_value = -1, $notooltip = 0, $addlinktonotes = 0)
2167  {
2168  global $conf, $langs, $hookmanager;
2169 
2170  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpictoimg) {
2171  $withpictoimg = 0;
2172  }
2173 
2174  $result = '';
2175  $label = '';
2176  $linkstart = '';
2177  $linkend = '';
2178 
2179  if (!empty($this->photo)) {
2180  $label .= '<div class="photointooltip floatright">';
2181  $label .= Form::showphoto('memberphoto', $this, 80, 0, 0, 'photoref photowithmargin photologintooltip', 'small', 0, 1);
2182  $label .= '</div>';
2183  //$label .= '<div style="clear: both;"></div>';
2184  }
2185 
2186  $label .= '<div class="centpercent">';
2187  $label .= img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Member").'</u>';
2188  $label .= ' '.$this->getLibStatut(4);
2189  if (!empty($this->ref)) {
2190  $label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
2191  }
2192  if (!empty($this->login)) {
2193  $label .= '<br><b>'.$langs->trans('Login').':</b> '.$this->login;
2194  }
2195  if (!empty($this->firstname) || !empty($this->lastname)) {
2196  $label .= '<br><b>'.$langs->trans('Name').':</b> '.$this->getFullName($langs);
2197  }
2198  if (!empty($this->company)) {
2199  $label .= '<br><b>'.$langs->trans('Company').':</b> '.$this->company;
2200  }
2201  $label .= '</div>';
2202 
2203  $url = DOL_URL_ROOT.'/adherents/card.php?rowid='.((int) $this->id);
2204  if ($option == 'subscription') {
2205  $url = DOL_URL_ROOT.'/adherents/subscription.php?rowid='.((int) $this->id);
2206  }
2207 
2208  if ($option != 'nolink') {
2209  // Add param to save lastsearch_values or not
2210  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2211  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
2212  $add_save_lastsearch_values = 1;
2213  }
2214  if ($add_save_lastsearch_values) {
2215  $url .= '&save_lastsearch_values=1';
2216  }
2217  }
2218 
2219  $linkstart .= '<a href="'.$url.'"';
2220  $linkclose = "";
2221  if (empty($notooltip)) {
2222  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2223  $langs->load("users");
2224  $label = $langs->trans("ShowUser");
2225  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
2226  }
2227  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
2228  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
2229  }
2230 
2231  $linkstart .= $linkclose.'>';
2232  $linkend = '</a>';
2233 
2234  $result .= $linkstart;
2235  if ($withpictoimg) {
2236  $result .= '<div class="inline-block nopadding valignmiddle">';
2237  }
2238  if ($withpictoimg) {
2239  $paddafterimage = '';
2240  if (abs($withpictoimg) == 1) {
2241  $paddafterimage = 'style="margin-right: 3px;"';
2242  }
2243  // Only picto
2244  if ($withpictoimg > 0) {
2245  $picto = '<span class="nopadding'.($morecss ? ' userimg'.$morecss : '').'">'.
2246  img_object('', 'user', $paddafterimage.' '.($notooltip ? '' : 'class="classfortooltip"'), 0, 0, $notooltip ? 0 : 1).'</span>';
2247  } else {
2248  // Picto must be a photo
2249  $picto = '<span class="nopadding'.($morecss ? ' userimg'.$morecss : '').'"'.($paddafterimage ? ' '.$paddafterimage : '').'>';
2250  $picto .= Form::showphoto('memberphoto', $this, 0, 0, 0, 'userphoto'.($withpictoimg == -3 ? 'small' : ''), 'mini', 0, 1);
2251  $picto .= '</span>';
2252  }
2253  $result .= $picto;
2254  }
2255  if ($withpictoimg > -2 && $withpictoimg != 2) {
2256  if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2257  $result .= '<span class="nopadding valignmiddle'.((!isset($this->statut) || $this->statut) ? '' : ' strikefordisabled').
2258  ($morecss ? ' usertext'.$morecss : '').'">';
2259  }
2260  if ($mode == 'login') {
2261  $result .= dol_trunc($this->login, $maxlen);
2262  } elseif ($mode == 'ref') {
2263  $result .= $this->ref;
2264  } else {
2265  $result .= $this->getFullName($langs, '', ($mode == 'firstname' ? 2 : ($mode == 'lastname' ? 4 : -1)), $maxlen);
2266  }
2267  if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2268  $result .= '</span>';
2269  }
2270  }
2271  if ($withpictoimg) {
2272  $result .= '</div>';
2273  }
2274  $result .= $linkend;
2275 
2276  if ($addlinktonotes) {
2277  if ($this->note_private) {
2278  $notetoshow = $langs->trans("ViewPrivateNote").':<br>'.dol_string_nohtmltag($this->note_private, 1);
2279  $result .= ' <span class="note inline-block">';
2280  $result .= '<a href="'.DOL_URL_ROOT.'/adherents/note.php?id='.$this->id.'" class="classfortooltip" title="'.dol_escape_htmltag($notetoshow).'">';
2281  $result .= img_picto('', 'note');
2282  $result .= '</a>';
2283  $result .= '</span>';
2284  }
2285  }
2286  global $action;
2287  $hookmanager->initHooks(array($this->element . 'dao'));
2288  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
2289  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
2290  if ($reshook > 0) {
2291  $result = $hookmanager->resPrint;
2292  } else {
2293  $result .= $hookmanager->resPrint;
2294  }
2295  return $result;
2296  }
2297 
2304  public function getLibStatut($mode = 0)
2305  {
2306  return $this->LibStatut($this->statut, $this->need_subscription, $this->datefin, $mode);
2307  }
2308 
2309  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2319  public function LibStatut($status, $need_subscription, $date_end_subscription, $mode = 0)
2320  {
2321  // phpcs:enable
2322  global $langs;
2323  $langs->load("members");
2324 
2325  $statusType = '';
2326  $labelStatus = '';
2327  $labelStatusShort = '';
2328 
2329  if ($status == self::STATUS_DRAFT) {
2330  $statusType = 'status0';
2331  $labelStatus = $langs->trans("MemberStatusDraft");
2332  $labelStatusShort = $langs->trans("MemberStatusDraftShort");
2333  } elseif ($status >= self::STATUS_VALIDATED) {
2334  if ($need_subscription === 0) {
2335  $statusType = 'status4';
2336  $labelStatus = $langs->trans("MemberStatusNoSubscription");
2337  $labelStatusShort = $langs->trans("MemberStatusNoSubscriptionShort");
2338  } elseif (!$date_end_subscription) {
2339  $statusType = 'status1';
2340  $labelStatus = $langs->trans("MemberStatusActive");
2341  $labelStatusShort = $langs->trans("MemberStatusActiveShort");
2342  } elseif ($date_end_subscription < dol_now()) {
2343  $statusType = 'status3';
2344  $labelStatus = $langs->trans("MemberStatusActiveLate");
2345  $labelStatusShort = $langs->trans("MemberStatusActiveLateShort");
2346  } else {
2347  $statusType = 'status4';
2348  $labelStatus = $langs->trans("MemberStatusPaid");
2349  $labelStatusShort = $langs->trans("MemberStatusPaidShort");
2350  }
2351  } elseif ($status == self::STATUS_RESILIATED) {
2352  $statusType = 'status6';
2353  $labelStatus = $langs->transnoentitiesnoconv("MemberStatusResiliated");
2354  $labelStatusShort = $langs->transnoentitiesnoconv("MemberStatusResiliatedShort");
2355  } elseif ($status == self::STATUS_EXCLUDED) {
2356  $statusType = 'status10';
2357  $labelStatus = $langs->transnoentitiesnoconv("MemberStatusExcluded");
2358  $labelStatusShort = $langs->transnoentitiesnoconv("MemberStatusExcludedShort");
2359  }
2360 
2361  return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode);
2362  }
2363 
2364 
2365  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2371  public function load_state_board()
2372  {
2373  // phpcs:enable
2374  global $conf;
2375 
2376  $this->nb = array();
2377 
2378  $sql = "SELECT count(a.rowid) as nb";
2379  $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a";
2380  $sql .= " WHERE a.statut > 0";
2381  $sql .= " AND a.entity IN (".getEntity('adherent').")";
2382 
2383  $resql = $this->db->query($sql);
2384  if ($resql) {
2385  while ($obj = $this->db->fetch_object($resql)) {
2386  $this->nb["members"] = $obj->nb;
2387  }
2388  $this->db->free($resql);
2389  return 1;
2390  } else {
2391  dol_print_error($this->db);
2392  $this->error = $this->db->error();
2393  return -1;
2394  }
2395  }
2396 
2397  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2405  public function load_board($user, $mode)
2406  {
2407  // phpcs:enable
2408  global $conf, $langs;
2409 
2410  if ($user->socid) {
2411  return -1; // protection pour eviter appel par utilisateur externe
2412  }
2413 
2414  $now = dol_now();
2415 
2416  $sql = "SELECT a.rowid, a.datefin, a.statut";
2417  $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a";
2418  $sql .= ", ".MAIN_DB_PREFIX."adherent_type as t";
2419  $sql .= " WHERE a.fk_adherent_type = t.rowid";
2420  if ($mode == 'expired') {
2421  $sql .= " AND a.statut = ".self::STATUS_VALIDATED;
2422  $sql .= " AND a.entity IN (".getEntity('adherent').")";
2423  $sql .= " AND ((a.datefin IS NULL or a.datefin < '".$this->db->idate($now)."') AND t.subscription = '1')";
2424  } elseif ($mode == 'shift') {
2425  $sql .= " AND a.statut = ".self::STATUS_DRAFT;
2426  $sql .= " AND a.entity IN (".getEntity('adherent').")";
2427  }
2428 
2429  $resql = $this->db->query($sql);
2430  if ($resql) {
2431  $langs->load("members");
2432 
2433  $warning_delay = 0;
2434  $url = '';
2435  $label = '';
2436  $labelShort = '';
2437 
2438  if ($mode == 'expired') {
2439  $warning_delay = $conf->adherent->subscription->warning_delay / 60 / 60 / 24;
2440  $label = $langs->trans("MembersWithSubscriptionToReceive");
2441  $labelShort = $langs->trans("MembersWithSubscriptionToReceiveShort");
2442  $url = DOL_URL_ROOT.'/adherents/list.php?mainmenu=members&amp;statut='.self::STATUS_VALIDATED.'&amp;filter=outofdate';
2443  } elseif ($mode == 'shift') {
2444  $warning_delay = $conf->adherent->subscription->warning_delay / 60 / 60 / 24;
2445  $url = DOL_URL_ROOT.'/adherents/list.php?mainmenu=members&amp;statut='.self::STATUS_DRAFT;
2446  $label = $langs->trans("MembersListToValid");
2447  $labelShort = $langs->trans("ToValidate");
2448  }
2449 
2450  $response = new WorkboardResponse();
2451  $response->warning_delay = $warning_delay;
2452  $response->label = $label;
2453  $response->labelShort = $labelShort;
2454  $response->url = $url;
2455  $response->img = img_object('', "user");
2456 
2457  $adherentstatic = new Adherent($this->db);
2458 
2459  while ($obj = $this->db->fetch_object($resql)) {
2460  $response->nbtodo++;
2461 
2462  $adherentstatic->datefin = $this->db->jdate($obj->datefin);
2463  $adherentstatic->statut = $obj->statut;
2464 
2465  if ($adherentstatic->hasDelay()) {
2466  $response->nbtodolate++;
2467  }
2468  }
2469 
2470  return $response;
2471  } else {
2472  dol_print_error($this->db);
2473  $this->error = $this->db->error();
2474  return -1;
2475  }
2476  }
2477 
2478 
2490  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
2491  {
2492  global $conf, $langs;
2493 
2494  $langs->load("orders");
2495 
2496  if (!dol_strlen($modele)) {
2497  $modele = 'standard';
2498 
2499  if ($this->model_pdf) {
2500  $modele = $this->model_pdf;
2501  } elseif (!empty($conf->global->ADHERENT_ADDON_PDF)) {
2502  $modele = $conf->global->ADHERENT_ADDON_PDF;
2503  }
2504  }
2505 
2506  $modelpath = "core/modules/member/doc/";
2507 
2508  return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
2509  }
2510 
2511 
2519  public function initAsSpecimen()
2520  {
2521  global $user, $langs;
2522  $now = dol_now();
2523 
2524  // Initialise parametres
2525  $this->id = 0;
2526  $this->ref = 'ABC001';
2527  $this->entity = 1;
2528  $this->specimen = 1;
2529  $this->civility_id = 0;
2530  $this->lastname = 'DOLIBARR';
2531  $this->firstname = 'SPECIMEN';
2532  $this->gender = 'man';
2533  $this->login = 'dolibspec';
2534  $this->pass = 'dolibspec';
2535  $this->company = 'Societe ABC';
2536  $this->address = '61 jump street';
2537  $this->zip = '75000';
2538  $this->town = 'Paris';
2539  $this->country_id = 1;
2540  $this->country_code = 'FR';
2541  $this->country = 'France';
2542  $this->morphy = 'mor';
2543  $this->email = 'specimen@specimen.com';
2544  $this->socialnetworks = array(
2545  'skype' => 'skypepseudo',
2546  'twitter' => 'twitterpseudo',
2547  'facebook' => 'facebookpseudo',
2548  'linkedin' => 'linkedinpseudo',
2549  );
2550  $this->phone = '0999999999';
2551  $this->phone_perso = '0999999998';
2552  $this->phone_mobile = '0999999997';
2553  $this->note_public = 'This is a public note';
2554  $this->note_private = 'This is a private note';
2555  $this->birth = $now;
2556  $this->photo = '';
2557  $this->public = 1;
2558  $this->statut = self::STATUS_DRAFT;
2559 
2560  $this->datefin = $now;
2561  $this->datevalid = $now;
2562 
2563  $this->typeid = 1; // Id type adherent
2564  $this->type = 'Type adherent'; // Libelle type adherent
2565  $this->need_subscription = 0;
2566 
2567  $this->first_subscription_date = $now;
2568  $this->first_subscription_date_start = $this->first_subscription_date;
2569  $this->first_subscription_date_end = dol_time_plus_duree($this->first_subscription_date_start, 1, 'y');
2570  $this->first_subscription_amount = 10;
2571 
2572  $this->last_subscription_date = $this->first_subscription_date;
2573  $this->last_subscription_date_start = $this->first_subscription_date;
2574  $this->last_subscription_date_end = dol_time_plus_duree($this->last_subscription_date_start, 1, 'y');
2575  $this->last_subscription_amount = 10;
2576  return 1;
2577  }
2578 
2579 
2580  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2581  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2591  public function _load_ldap_dn($info, $mode = 0)
2592  {
2593  // phpcs:enable
2594  global $conf;
2595  $dn = '';
2596  if ($mode == 0) {
2597  $dn = $conf->global->LDAP_KEY_MEMBERS."=".$info[$conf->global->LDAP_KEY_MEMBERS].",".$conf->global->LDAP_MEMBER_DN;
2598  }
2599  if ($mode == 1) {
2600  $dn = $conf->global->LDAP_MEMBER_DN;
2601  }
2602  if ($mode == 2) {
2603  $dn = $conf->global->LDAP_KEY_MEMBERS."=".$info[$conf->global->LDAP_KEY_MEMBERS];
2604  }
2605  return $dn;
2606  }
2607 
2608 
2609  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2610  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2616  public function _load_ldap_info()
2617  {
2618  // phpcs:enable
2619  global $conf, $langs;
2620 
2621  $info = array();
2622  $socialnetworks = getArrayOfSocialNetworks();
2623  $keymodified = false;
2624 
2625  // Object classes
2626  $info["objectclass"] = explode(',', $conf->global->LDAP_MEMBER_OBJECT_CLASS);
2627 
2628  $this->fullname = $this->getFullName($langs);
2629 
2630  // For avoid ldap error when firstname and lastname are empty
2631  if ($this->morphy == 'mor' && (empty($this->fullname) || $this->fullname == $this->company)) {
2632  $this->fullname = $this->company;
2633  $this->lastname = $this->company;
2634  }
2635 
2636  // Possible LDAP KEY (constname => varname)
2637  $ldapkey = array(
2638  'LDAP_MEMBER_FIELD_FULLNAME' => 'fullname',
2639  'LDAP_MEMBER_FIELD_NAME' => 'lastname',
2640  'LDAP_MEMBER_FIELD_LOGIN' => 'login',
2641  'LDAP_MEMBER_FIELD_LOGIN_SAMBA' => 'login',
2642  'LDAP_MEMBER_FIELD_MAIL' => 'email'
2643  );
2644 
2645  // Member
2646  foreach ($ldapkey as $constname => $varname) {
2647  if (!empty($this->$varname) && !empty($conf->global->$constname)) {
2648  $info[$conf->global->$constname] = $this->$varname;
2649 
2650  // Check if it is the LDAP key and if its value has been changed
2651  if (!empty($conf->global->LDAP_KEY_MEMBERS) && $conf->global->LDAP_KEY_MEMBERS == $conf->global->$constname) {
2652  if (!empty($this->oldcopy) && $this->$varname != $this->oldcopy->$varname) {
2653  $keymodified = true; // For check if LDAP key has been modified
2654  }
2655  }
2656  }
2657  }
2658  if ($this->firstname && !empty($conf->global->LDAP_MEMBER_FIELD_FIRSTNAME)) {
2659  $info[$conf->global->LDAP_MEMBER_FIELD_FIRSTNAME] = $this->firstname;
2660  }
2661  if ($this->poste && !empty($conf->global->LDAP_MEMBER_FIELD_TITLE)) {
2662  $info[$conf->global->LDAP_MEMBER_FIELD_TITLE] = $this->poste;
2663  }
2664  if ($this->company && !empty($conf->global->LDAP_MEMBER_FIELD_COMPANY)) {
2665  $info[$conf->global->LDAP_MEMBER_FIELD_COMPANY] = $this->company;
2666  }
2667  if ($this->address && !empty($conf->global->LDAP_MEMBER_FIELD_ADDRESS)) {
2668  $info[$conf->global->LDAP_MEMBER_FIELD_ADDRESS] = $this->address;
2669  }
2670  if ($this->zip && !empty($conf->global->LDAP_MEMBER_FIELD_ZIP)) {
2671  $info[$conf->global->LDAP_MEMBER_FIELD_ZIP] = $this->zip;
2672  }
2673  if ($this->town && !empty($conf->global->LDAP_MEMBER_FIELD_TOWN)) {
2674  $info[$conf->global->LDAP_MEMBER_FIELD_TOWN] = $this->town;
2675  }
2676  if ($this->country_code && !empty($conf->global->LDAP_MEMBER_FIELD_COUNTRY)) {
2677  $info[$conf->global->LDAP_MEMBER_FIELD_COUNTRY] = $this->country_code;
2678  }
2679  foreach ($socialnetworks as $key => $value) {
2680  if ($this->socialnetworks[$value['label']] && !empty($conf->global->{'LDAP_MEMBER_FIELD_'.strtoupper($value['label'])})) {
2681  $info[$conf->global->{'LDAP_MEMBER_FIELD_'.strtoupper($value['label'])}] = $this->socialnetworks[$value['label']];
2682  }
2683  }
2684  if ($this->phone && !empty($conf->global->LDAP_MEMBER_FIELD_PHONE)) {
2685  $info[$conf->global->LDAP_MEMBER_FIELD_PHONE] = $this->phone;
2686  }
2687  if ($this->phone_perso && !empty($conf->global->LDAP_MEMBER_FIELD_PHONE_PERSO)) {
2688  $info[$conf->global->LDAP_MEMBER_FIELD_PHONE_PERSO] = $this->phone_perso;
2689  }
2690  if ($this->phone_mobile && !empty($conf->global->LDAP_MEMBER_FIELD_MOBILE)) {
2691  $info[$conf->global->LDAP_MEMBER_FIELD_MOBILE] = $this->phone_mobile;
2692  }
2693  if ($this->fax && !empty($conf->global->LDAP_MEMBER_FIELD_FAX)) {
2694  $info[$conf->global->LDAP_MEMBER_FIELD_FAX] = $this->fax;
2695  }
2696  if ($this->note_private && !empty($conf->global->LDAP_MEMBER_FIELD_DESCRIPTION)) {
2697  $info[$conf->global->LDAP_MEMBER_FIELD_DESCRIPTION] = dol_string_nohtmltag($this->note_private, 2);
2698  }
2699  if ($this->note_public && !empty($conf->global->LDAP_MEMBER_FIELD_NOTE_PUBLIC)) {
2700  $info[$conf->global->LDAP_MEMBER_FIELD_NOTE_PUBLIC] = dol_string_nohtmltag($this->note_public, 2);
2701  }
2702  if ($this->birth && !empty($conf->global->LDAP_MEMBER_FIELD_BIRTHDATE)) {
2703  $info[$conf->global->LDAP_MEMBER_FIELD_BIRTHDATE] = dol_print_date($this->birth, 'dayhourldap');
2704  }
2705  if (isset($this->statut) && !empty($conf->global->LDAP_FIELD_MEMBER_STATUS)) {
2706  $info[$conf->global->LDAP_FIELD_MEMBER_STATUS] = $this->statut;
2707  }
2708  if ($this->datefin && !empty($conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION)) {
2709  $info[$conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION] = dol_print_date($this->datefin, 'dayhourldap');
2710  }
2711 
2712  // When password is modified
2713  if (!empty($this->pass)) {
2714  if (!empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD)) {
2715  $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD] = $this->pass; // this->pass = mot de passe non crypte
2716  }
2717  if (!empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED)) {
2718  $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED] = dol_hash($this->pass, 'openldap'); // Create OpenLDAP password (see LDAP_PASSWORD_HASH_TYPE)
2719  }
2720  } elseif ($conf->global->LDAP_SERVER_PROTOCOLVERSION !== '3') {
2721  // Set LDAP password if possible
2722  // If ldap key is modified and LDAPv3 we use ldap_rename function for avoid lose encrypt password
2723  if (!empty($conf->global->DATABASE_PWD_ENCRYPTED)) {
2724  // Just for the default MD5 !
2725  if (empty($conf->global->MAIN_SECURITY_HASH_ALGO)) {
2726  if ($this->pass_indatabase_crypted && !empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED)) {
2727  // Create OpenLDAP MD5 password from Dolibarr MD5 password
2728  // Note: This suppose that "pass_indatabase_crypted" is a md5 (guaranted by the previous test if "(empty($conf->global->MAIN_SECURITY_HASH_ALGO))"
2729  $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED] = dolGetLdapPasswordHash($this->pass_indatabase_crypted, 'md5frommd5');
2730  }
2731  }
2732  } elseif (!empty($this->pass_indatabase)) {
2733  // Use $this->pass_indatabase value if exists
2734  if (!empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD)) {
2735  $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD] = $this->pass_indatabase; // $this->pass_indatabase = mot de passe non crypte
2736  }
2737  if (!empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED)) {
2738  $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED] = dol_hash($this->pass_indatabase, 'openldap'); // Create OpenLDAP password (see LDAP_PASSWORD_HASH_TYPE)
2739  }
2740  }
2741  }
2742 
2743  // Subscriptions
2744  if ($this->first_subscription_date && !empty($conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE)) {
2745  $info[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE] = dol_print_date($this->first_subscription_date, 'dayhourldap');
2746  }
2747  if (isset($this->first_subscription_amount) && !empty($conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT)) {
2748  $info[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT] = $this->first_subscription_amount;
2749  }
2750  if ($this->last_subscription_date && !empty($conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE)) {
2751  $info[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE] = dol_print_date($this->last_subscription_date, 'dayhourldap');
2752  }
2753  if (isset($this->last_subscription_amount) && !empty($conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT)) {
2754  $info[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT] = $this->last_subscription_amount;
2755  }
2756 
2757  return $info;
2758  }
2759 
2760 
2767  public function info($id)
2768  {
2769  $sql = 'SELECT a.rowid, a.datec as datec,';
2770  $sql .= ' a.datevalid as datev,';
2771  $sql .= ' a.tms as datem,';
2772  $sql .= ' a.fk_user_author, a.fk_user_valid, a.fk_user_mod';
2773  $sql .= ' FROM '.MAIN_DB_PREFIX.'adherent as a';
2774  $sql .= ' WHERE a.rowid = '.((int) $id);
2775 
2776  dol_syslog(get_class($this)."::info", LOG_DEBUG);
2777  $result = $this->db->query($sql);
2778  if ($result) {
2779  if ($this->db->num_rows($result)) {
2780  $obj = $this->db->fetch_object($result);
2781  $this->id = $obj->rowid;
2782 
2783  $this->user_creation_id = $obj->fk_user_author;
2784  $this->user_validation_id = $obj->fk_user_valid;
2785  $this->user_modification_id = $obj->fk_user_mod;
2786  $this->date_creation = $this->db->jdate($obj->datec);
2787  $this->date_validation = $this->db->jdate($obj->datev);
2788  $this->date_modification = $this->db->jdate($obj->datem);
2789  }
2790 
2791  $this->db->free($result);
2792  } else {
2793  dol_print_error($this->db);
2794  }
2795  }
2796 
2802  public function getNbOfEMailings()
2803  {
2804  $sql = "SELECT count(mc.email) as nb";
2805  $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
2806  $sql .= " WHERE mc.email = '".$this->db->escape($this->email)."'";
2807  $sql .= " AND mc.statut NOT IN (-1,0)"; // -1 erreur, 0 non envoye, 1 envoye avec succes
2808 
2809  $resql = $this->db->query($sql);
2810  if ($resql) {
2811  $obj = $this->db->fetch_object($resql);
2812  $nb = $obj->nb;
2813 
2814  $this->db->free($resql);
2815  return $nb;
2816  } else {
2817  $this->error = $this->db->error();
2818  return -1;
2819  }
2820  }
2821 
2832  public function setCategories($categories)
2833  {
2834  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
2835  return parent::setCategoriesCommon($categories, Categorie::TYPE_MEMBER);
2836  }
2837 
2846  public static function replaceThirdparty($db, $origin_id, $dest_id)
2847  {
2848  $tables = array('adherent');
2849 
2850  return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
2851  }
2852 
2858  public function hasDelay()
2859  {
2860  global $conf;
2861 
2862  //Only valid members
2863  if ($this->statut != self::STATUS_VALIDATED) {
2864  return false;
2865  }
2866  if (!$this->datefin) {
2867  return false;
2868  }
2869 
2870  $now = dol_now();
2871 
2872  return $this->datefin < ($now - $conf->adherent->subscription->warning_delay);
2873  }
2874 
2875 
2883  public function sendReminderForExpiredSubscription($daysbeforeendlist = '10')
2884  {
2885  global $conf, $langs, $mysoc, $user;
2886 
2887  $error = 0;
2888  $this->output = '';
2889  $this->error = '';
2890 
2891  $blockingerrormsg = '';
2892 
2893  if (empty($conf->adherent->enabled)) { // Should not happen. If module disabled, cron job should not be visible.
2894  $langs->load("agenda");
2895  $this->output = $langs->trans('ModuleNotEnabled', $langs->transnoentitiesnoconv("Adherent"));
2896  return 0;
2897  }
2898  if (empty($conf->global->MEMBER_REMINDER_EMAIL)) {
2899  $langs->load("agenda");
2900  $this->output = $langs->trans('EventRemindersByEmailNotEnabled', $langs->transnoentitiesnoconv("Adherent"));
2901  return 0;
2902  }
2903 
2904  $now = dol_now();
2905  $nbok = 0;
2906  $nbko = 0;
2907 
2908  $listofmembersok = array();
2909  $listofmembersko = array();
2910 
2911  $arraydaysbeforeend = explode(';', $daysbeforeendlist);
2912  foreach ($arraydaysbeforeend as $daysbeforeend) { // Loop on each delay
2913  dol_syslog(__METHOD__.' - Process delta = '.$daysbeforeend, LOG_DEBUG);
2914 
2915  if (!is_numeric($daysbeforeend)) {
2916  $blockingerrormsg = "Value for delta is not a numeric value";
2917  $nbko++;
2918  break;
2919  }
2920 
2921  $tmp = dol_getdate($now);
2922  $datetosearchfor = dol_time_plus_duree(dol_mktime(0, 0, 0, $tmp['mon'], $tmp['mday'], $tmp['year'], 'tzserver'), $daysbeforeend, 'd');
2923 
2924  $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'adherent';
2925  $sql .= " WHERE entity = ".((int) $conf->entity); // Do not use getEntity('adherent').")" here, we want the batch to be on its entity only;
2926  $sql .= " AND datefin = '".$this->db->idate($datetosearchfor)."'";
2927  //$sql .= " LIMIT 10000";
2928 
2929  $resql = $this->db->query($sql);
2930  if ($resql) {
2931  $num_rows = $this->db->num_rows($resql);
2932 
2933  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
2934  $adherent = new Adherent($this->db);
2935  $formmail = new FormMail($this->db);
2936 
2937  $i = 0;
2938  while ($i < $num_rows) {
2939  $obj = $this->db->fetch_object($resql);
2940 
2941  $adherent->fetch($obj->rowid, '', '', '', true, true);
2942 
2943  if (empty($adherent->email)) {
2944  $nbko++;
2945  $listofmembersko[$adherent->id] = $adherent->id;
2946  } else {
2947  $adherent->fetch_thirdparty();
2948 
2949  // 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.
2950  $languagefromcountrycode = getLanguageCodeFromCountryCode($adherent->country_code ? $adherent->country_code : $adherent->thirdparty->country_code);
2951  $languagecodeformember = (empty($adherent->thirdparty->default_lang) ? ($languagefromcountrycode ? $languagefromcountrycode : $mysoc->default_lang) : $adherent->thirdparty->default_lang);
2952 
2953  // Send reminder email
2954  $outputlangs = new Translate('', $conf);
2955  $outputlangs->setDefaultLang($languagecodeformember);
2956  $outputlangs->loadLangs(array("main", "members"));
2957  dol_syslog("sendReminderForExpiredSubscription Language for member id ".$adherent->id." set to ".$outputlangs->defaultlang." mysoc->default_lang=".$mysoc->default_lang);
2958 
2959  $arraydefaultmessage = null;
2960  $labeltouse = getDolGlobalString('ADHERENT_EMAIL_TEMPLATE_REMIND_EXPIRATION');
2961 
2962  if (!empty($labeltouse)) {
2963  $arraydefaultmessage = $formmail->getEMailTemplate($this->db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
2964  }
2965 
2966  if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
2967  $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $adherent);
2968  //if (is_array($adherent->thirdparty)) $substitutionarraycomp = ...
2969  complete_substitutions_array($substitutionarray, $outputlangs, $adherent);
2970 
2971  $subject = make_substitutions($arraydefaultmessage->topic, $substitutionarray, $outputlangs);
2972  $msg = make_substitutions($arraydefaultmessage->content, $substitutionarray, $outputlangs);
2973  $from = $conf->global->ADHERENT_MAIL_FROM;
2974  $to = $adherent->email;
2975 
2976  $trackid = 'mem'.$adherent->id;
2977  $moreinheader = 'X-Dolibarr-Info: sendReminderForExpiredSubscription'."\r\n";
2978 
2979  include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
2980  $cmail = new CMailFile($subject, $to, $from, $msg, array(), array(), array(), '', '', 0, 1, '', '', $trackid, $moreinheader);
2981  $result = $cmail->sendfile();
2982  if (!$result) {
2983  $error++;
2984  $this->error .= $cmail->error.' ';
2985  if (!is_null($cmail->errors)) {
2986  $this->errors += $cmail->errors;
2987  }
2988  $nbko++;
2989  $listofmembersko[$adherent->id] = $adherent->id;
2990  } else {
2991  $nbok++;
2992  $listofmembersok[$adherent->id] = $adherent->id;
2993 
2994  $message = $msg;
2995  $sendto = $to;
2996  $sendtocc = '';
2997  $sendtobcc = '';
2998  $actioncode = 'EMAIL';
2999  $extraparams = '';
3000 
3001  $actionmsg = '';
3002  $actionmsg2 = $langs->transnoentities('MailSentBy').' '.CMailFile::getValidAddress($from, 4, 0, 1).' '.$langs->transnoentities('To').' '.CMailFile::getValidAddress($sendto, 4, 0, 1);
3003  if ($message) {
3004  $actionmsg = $langs->transnoentities('MailFrom').': '.dol_escape_htmltag($from);
3005  $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTo').': '.dol_escape_htmltag($sendto));
3006  if ($sendtocc) {
3007  $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc').": ".dol_escape_htmltag($sendtocc));
3008  }
3009  $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic').": ".$subject);
3010  $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody').":");
3011  $actionmsg = dol_concatdesc($actionmsg, $message);
3012  }
3013 
3014  require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
3015 
3016  // Insert record of emails sent
3017  $actioncomm = new ActionComm($this->db);
3018 
3019  $actioncomm->type_code = 'AC_OTH_AUTO'; // Type of event ('AC_OTH', 'AC_OTH_AUTO', 'AC_XXX'...)
3020  $actioncomm->code = 'AC_'.$actioncode;
3021  $actioncomm->label = $actionmsg2;
3022  $actioncomm->note_private = $actionmsg;
3023  $actioncomm->fk_project = 0;
3024  $actioncomm->datep = $now;
3025  $actioncomm->datef = $now;
3026  $actioncomm->percentage = -1; // Not applicable
3027  $actioncomm->socid = $adherent->thirdparty->id;
3028  $actioncomm->contact_id = 0;
3029  $actioncomm->authorid = $user->id; // User saving action
3030  $actioncomm->userownerid = $user->id; // Owner of action
3031  // Fields when action is en email (content should be added into note)
3032  $actioncomm->email_msgid = $cmail->msgid;
3033  $actioncomm->email_from = $from;
3034  $actioncomm->email_sender = '';
3035  $actioncomm->email_to = $to;
3036  $actioncomm->email_tocc = $sendtocc;
3037  $actioncomm->email_tobcc = $sendtobcc;
3038  $actioncomm->email_subject = $subject;
3039  $actioncomm->errors_to = '';
3040 
3041  $actioncomm->fk_element = $adherent->id;
3042  $actioncomm->elementtype = $adherent->element;
3043 
3044  $actioncomm->extraparams = $extraparams;
3045 
3046  $actioncomm->create($user);
3047  }
3048  } else {
3049  //$blockingerrormsg = "Can't find email template with label=".$labeltouse.", to use for the reminding email";
3050 
3051  $error++;
3052  $this->error .= "Can't find email template with label=".$labeltouse.", to use for the reminding email ";
3053 
3054  $nbko++;
3055  $listofmembersko[$adherent->id] = $adherent->id;
3056 
3057  break;
3058  }
3059  }
3060 
3061  $i++;
3062  }
3063  } else {
3064  $this->error = $this->db->lasterror();
3065  return 1;
3066  }
3067  }
3068 
3069  if ($blockingerrormsg) {
3070  $this->error = $blockingerrormsg;
3071  return 1;
3072  } else {
3073  $this->output = 'Found '.($nbok + $nbko).' members to send reminder to.';
3074  $this->output .= ' Send email successfuly to '.$nbok.' members';
3075  if (is_array($listofmembersok)) {
3076  $listofids = '';
3077  $i = 0;
3078  foreach ($listofmembersok as $idmember) {
3079  if ($i > 100) {
3080  $listofids .= ', ...';
3081  break;
3082  }
3083  if (empty($listofids)) {
3084  $listofids .= ' [';
3085  } else {
3086  $listofids .= ', ';
3087  }
3088  $listofids .= $idmember;
3089  $i++;
3090  }
3091  if ($listofids) {
3092  $listofids .= ']';
3093  }
3094  $this->output .= ($listofids ? ' ids='.$listofids : '');
3095  }
3096  if ($nbko) {
3097  $this->output .= ' - Canceled for '.$nbko.' member (no email or email sending error)';
3098  if (is_array($listofmembersko)) {
3099  $listofids = '';
3100  $i = 0;
3101  foreach ($listofmembersko as $idmember) {
3102  if ($i > 100) {
3103  $listofids .= ', ...';
3104  break;
3105  }
3106  if (empty($listofids)) {
3107  $listofids .= ' [';
3108  } else {
3109  $listofids .= ', ';
3110  }
3111  $listofids .= $idmember;
3112  $i++;
3113  }
3114  if ($listofids) {
3115  $listofids .= ']';
3116  }
3117  $this->output .= ($listofids ? ' ids='.$listofids : '');
3118  }
3119  }
3120  }
3121 
3122  return $nbko;
3123  }
3124 }
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:7839
dol_getdate
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
Definition: functions.lib.php:2713
Adherent\STATUS_RESILIATED
const STATUS_RESILIATED
Resiliated.
Definition: adherent.class.php:357
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
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:6491
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:1468
Adherent\create
create($user, $notrigger=0)
Create a member into database.
Definition: adherent.class.php:540
Adherent\fetch_name
fetch_name($firstname, $lastname)
Method to load member from its name.
Definition: adherent.class.php:1277
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:3805
Adherent\validate
validate($user)
Function that validate a member.
Definition: adherent.class.php:1888
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:2767
Adherent\resiliate
resiliate($user)
Fonction qui resilie un adherent.
Definition: adherent.class.php:1941
Adherent\fetch
fetch($rowid, $ref='', $fk_soc='', $ref_ext='', $fetch_optionals=true, $fetch_subscriptions=true)
Load member from database.
Definition: adherent.class.php:1309
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:484
CommonObject\setUpperOrLowerCase
setUpperOrLowerCase()
Set to upper or ucwords/lower if needed.
Definition: commonobject.class.php:740
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:398
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:4844
Adherent\fetch_subscriptions
fetch_subscriptions()
Function to get member subscriptions data: subscriptions, first_subscription_date,...
Definition: adherent.class.php:1457
Adherent\load_board
load_board($user, $mode)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
Definition: adherent.class.php:2405
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:2166
Adherent\getCivilityLabel
getCivilityLabel()
Return civility label of a member.
Definition: adherent.class.php:2141
ref
$object ref
Definition: info.php:77
CMailFile
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Definition: CMailFile.class.php:38
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:8785
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:712
getArrayOfSocialNetworks
getArrayOfSocialNetworks()
Get array of social network dictionary.
Definition: functions.lib.php:3026
Adherent\LibStatut
LibStatut($status, $need_subscription, $date_end_subscription, $mode=0)
Renvoi le libelle d'un statut donne.
Definition: adherent.class.php:2319
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5661
CMailFile\getValidAddress
static getValidAddress($address, $format, $encode=0, $maxnumberofemail=0)
Return a formatted address string for SMTP protocol.
Definition: CMailFile.class.php:1570
getRandomPassword
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.
Definition: security2.lib.php:454
Adherent\add_to_abo
add_to_abo()
Function to add member into external tools mailing-list, spip, etc.
Definition: adherent.class.php:2038
Adherent\setUserId
setUserId($userid)
Set link to a user.
Definition: adherent.class.php:1169
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:2514
WorkboardResponse
Definition: workboardresponse.class.php:25
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:7248
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:3880
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:5406
dolGetLdapPasswordHash
dolGetLdapPasswordHash($password, $type='md5')
Returns a specific ldap hash of a password.
Definition: security.lib.php:177
dol_hash
dol_hash($chain, $type='0')
Returns a hash of a string.
Definition: security.lib.php:104
Adherent\load_state_board
load_state_board()
Charge indicateurs this->nb de tableau de bord.
Definition: adherent.class.php:2371
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:1549
Adherent\_load_ldap_info
_load_ldap_info()
Initialise tableau info (tableau des attributs LDAP)
Definition: adherent.class.php:2616
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:8535
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:1991
Adherent\STATUS_VALIDATED
const STATUS_VALIDATED
Validated status.
Definition: adherent.class.php:353
Adherent\fetch_login
fetch_login($login)
Method to load member from its login.
Definition: adherent.class.php:1249
Adherent\hasDelay
hasDelay()
Return if a member is late (subscription late) or not.
Definition: adherent.class.php:2858
CommonObject\insertExtraFields
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
Definition: commonobject.class.php:6156
Adherent\__construct
__construct($db)
Constructor.
Definition: adherent.class.php:369
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:2490
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:2591
getCommonSubstitutionArray
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null)
Return array of possible common substitutions.
Definition: functions.lib.php:7275
Adherent\getNbOfEMailings
getNbOfEMailings()
Return number of mass Emailing received by this member with its email.
Definition: adherent.class.php:2802
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:6694
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:8347
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
Adherent\initAsSpecimen
initAsSpecimen()
Initialise an instance with random values.
Definition: adherent.class.php:2519
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:655
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:6007
Adherent\getmorphylib
getmorphylib($morphy='')
Return translated label by the nature of a adherent (physical or moral)
Definition: adherent.class.php:518
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:80
Adherent\STATUS_EXCLUDED
const STATUS_EXCLUDED
Excluded.
Definition: adherent.class.php:361
Adherent\getLibStatut
getLibStatut($mode=0)
Retourne le libelle du statut d'un adherent (brouillon, valide, resilie, exclu)
Definition: adherent.class.php:2304
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3747
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:6304
Adherent\replaceThirdparty
static replaceThirdparty($db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
Definition: adherent.class.php:2846
Adherent\del_to_abo
del_to_abo()
Function to delete a member from external tools like mailing-list, spip, etc.
Definition: adherent.class.php:2090
Adherent\STATUS_DRAFT
const STATUS_DRAFT
Draft status.
Definition: adherent.class.php:349
Adherent\sendReminderForExpiredSubscription
sendReminderForExpiredSubscription($daysbeforeendlist='10')
Send reminders by emails before subscription end CAN BE A CRON TASK.
Definition: adherent.class.php:2883
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:44
Paiement
Class to manage payments of customer invoices.
Definition: paiement.class.php:41
Facture\TYPE_STANDARD
const TYPE_STANDARD
Standard invoice.
Definition: facture.class.php:382
CommonObject\deleteExtraFields
deleteExtraFields()
Delete all extra fields values for the current object.
Definition: commonobject.class.php:6116
Adherent\update_end_date
update_end_date($user)
Update denormalized last subscription date.
Definition: adherent.class.php:922
dolGetStatus
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
Definition: functions.lib.php:10338
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:4211
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:6991
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->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->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
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:1630
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:9263
CommonObject\call_trigger
call_trigger($triggerName, $user)
Call trigger based on this instance.
Definition: commonobject.class.php:5791
dol_textishtml
dol_textishtml($msg, $option=0)
Return if a text is a html content.
Definition: functions.lib.php:7185
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:1521
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:2757
Adherent\setPassword
setPassword($user, $password='', $isencrypted=0, $notrigger=0, $nosyncuser=0)
Change password of a user.
Definition: adherent.class.php:1071
Adherent\makeSubstitution
makeSubstitution($text)
Make substitution of tags into text with value of current object.
Definition: adherent.class.php:445
Adherent\setCategories
setCategories($categories)
Sets object to supplied categories.
Definition: adherent.class.php:2832
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:38
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:7961
Adherent\setThirdPartyId
setThirdPartyId($thirdpartyid)
Set link to a third party.
Definition: adherent.class.php:1210