dolibarr  x.y.z
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 
97  public $societe;
98 
102  public $company;
103 
109  public $fk_soc;
110 
114  public $socid;
115 
119  public $address;
120 
124  public $zip;
125 
129  public $town;
130 
134  public $state_id;
135 
139  public $state_code;
140 
144  public $state;
145 
149  public $email;
150 
154  public $url;
155 
159  public $socialnetworks;
160 
166  public $skype;
167 
173  public $twitter;
174 
180  public $facebook;
181 
187  public $linkedin;
188 
192  public $phone;
193 
197  public $phone_perso;
198 
202  public $phone_pro;
203 
207  public $phone_mobile;
208 
212  public $fax;
213 
217  public $poste;
218 
222  public $morphy;
223 
227  public $public;
228 
233  public $default_lang;
234 
238  public $photo;
239 
245  public $datec;
246 
252  public $datem;
253 
254  public $datevalid;
255 
259  public $gender;
260 
261  public $birth;
262 
266  public $typeid;
267 
271  public $type;
272 
276  public $need_subscription;
277 
281  public $user_id;
282 
286  public $user_login;
287 
288  public $datefin;
289 
290 
291  // Fields loaded by fetch_subscriptions() from member table
292 
293  public $first_subscription_date;
294 
295  public $first_subscription_amount;
296 
297  public $last_subscription_date;
298 
299  public $last_subscription_date_start;
300 
301  public $last_subscription_date_end;
302 
303  public $last_subscription_amount;
304 
305  public $subscriptions = array();
306 
307 
308  // Fields loaded by fetchPartnerships() from partnership table
309 
310  public $partnerships = array();
311 
312 
316  public $oldcopy;
317 
321  public $entity;
322 
326  public $fields = array(
327  'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 10),
328  'ref' => array('type' => 'varchar(30)', 'label' => 'Ref', 'default' => 1, 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 12, 'index' => 1),
329  'entity' => array('type' => 'integer', 'label' => 'Entity', 'default' => 1, 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 15, 'index' => 1),
330  'ref_ext' => array('type' => 'varchar(128)', 'label' => 'Ref ext', 'enabled' => 1, 'visible' => 0, 'position' => 20),
331  'civility' => array('type' => 'varchar(6)', 'label' => 'Civility', 'enabled' => 1, 'visible' => -1, 'position' => 25),
332  'lastname' => array('type' => 'varchar(50)', 'label' => 'Lastname', 'enabled' => 1, 'visible' => -1, 'position' => 30, 'showoncombobox'=>1),
333  'firstname' => array('type' => 'varchar(50)', 'label' => 'Firstname', 'enabled' => 1, 'visible' => -1, 'position' => 35, 'showoncombobox'=>1),
334  'login' => array('type' => 'varchar(50)', 'label' => 'Login', 'enabled' => 1, 'visible' => -1, 'position' => 40),
335  'gender' => array('type' => 'varchar(10)', 'label' => 'Gender', 'enabled' => 1, 'visible' => -1, 'position' => 250),
336  'pass' => array('type' => 'varchar(50)', 'label' => 'Pass', 'enabled' => 1, 'visible' => -1, 'position' => 45),
337  'pass_crypted' => array('type' => 'varchar(128)', 'label' => 'Pass crypted', 'enabled' => 1, 'visible' => -1, 'position' => 50),
338  'fk_adherent_type' => array('type' => 'integer', 'label' => 'Fk adherent type', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 55),
339  'morphy' => array('type' => 'varchar(3)', 'label' => 'MorPhy', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 60),
340  'societe' => array('type' => 'varchar(128)', 'label' => 'Societe', 'enabled' => 1, 'visible' => -1, 'position' => 65, 'showoncombobox'=>2),
341  'fk_soc' => array('type' => 'integer:Societe:societe/class/societe.class.php', 'label' => 'ThirdParty', 'enabled' => 1, 'visible' => -1, 'position' => 70),
342  'address' => array('type' => 'text', 'label' => 'Address', 'enabled' => 1, 'visible' => -1, 'position' => 75),
343  'zip' => array('type' => 'varchar(10)', 'label' => 'Zip', 'enabled' => 1, 'visible' => -1, 'position' => 80),
344  'town' => array('type' => 'varchar(50)', 'label' => 'Town', 'enabled' => 1, 'visible' => -1, 'position' => 85),
345  'state_id' => array('type' => 'integer', 'label' => 'State id', 'enabled' => 1, 'visible' => -1, 'position' => 90),
346  'country' => array('type' => 'integer:Ccountry:core/class/ccountry.class.php', 'label' => 'Country', 'enabled' => 1, 'visible' => -1, 'position' => 95),
347  'email' => array('type' => 'varchar(255)', 'label' => 'Email', 'enabled' => 1, 'visible' => -1, 'position' => 100),
348  'url' =>array('type'=>'varchar(255)', 'label'=>'Url', 'enabled'=>1, 'visible'=>-1, 'position'=>110),
349  'socialnetworks' => array('type' => 'text', 'label' => 'Socialnetworks', 'enabled' => 1, 'visible' => -1, 'position' => 105),
350  'phone' => array('type' => 'varchar(30)', 'label' => 'Phone', 'enabled' => 1, 'visible' => -1, 'position' => 115),
351  'phone_perso' => array('type' => 'varchar(30)', 'label' => 'Phone perso', 'enabled' => 1, 'visible' => -1, 'position' => 120),
352  'phone_mobile' => array('type' => 'varchar(30)', 'label' => 'Phone mobile', 'enabled' => 1, 'visible' => -1, 'position' => 125),
353  'birth' => array('type' => 'date', 'label' => 'DateOfBirth', 'enabled' => 1, 'visible' => -1, 'position' => 130),
354  'photo' => array('type' => 'varchar(255)', 'label' => 'Photo', 'enabled' => 1, 'visible' => -1, 'position' => 135),
355  'public' => array('type' => 'smallint(6)', 'label' => 'Public', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 145),
356  'datefin' => array('type' => 'datetime', 'label' => 'DateEnd', 'enabled' => 1, 'visible' => -1, 'position' => 150),
357  'default_lang' =>array('type'=>'varchar(6)', 'label'=>'Default lang', 'enabled'=>1, 'visible'=>-1, 'position'=> 153),
358  'note_public' => array('type' => 'text', 'label' => 'NotePublic', 'enabled' => 1, 'visible' => 0, 'position' => 155),
359  'note_private' => array('type' => 'text', 'label' => 'NotePrivate', 'enabled' => 1, 'visible' => 0, 'position' => 160),
360  'datevalid' => array('type' => 'datetime', 'label' => 'DateValidation', 'enabled' => 1, 'visible' => -1, 'position' => 165),
361  'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -1, 'position' => 170),
362  'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 175),
363  'fk_user_author' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'Fk user author', 'enabled' => 1, 'visible' => -1, 'position' => 180),
364  'fk_user_mod' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'Fk user mod', 'enabled' => 1, 'visible' => -1, 'position' => 185),
365  'fk_user_valid' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserValidation', 'enabled' => 1, 'visible' => -1, 'position' => 190),
366  'canvas' => array('type' => 'varchar(32)', 'label' => 'Canvas', 'enabled' => 1, 'visible' => -1, 'position' => 195),
367  'statut' => array('type' => 'smallint(6)', 'label' => 'Statut', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 500,
368  'arrayofkeyval' => array(-1 => 'Draft', 1 => 'Validated', 0 => 'MemberStatusResiliatedShort', -2 => 'MemberStatusExcludedShort')),
369  'model_pdf' => array('type' => 'varchar(255)', 'label' => 'Model pdf', 'enabled' => 1, 'visible' => 0, 'position' => 800),
370  'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'visible' => -2, 'position' => 805)
371  );
372 
376  const STATUS_DRAFT = -1;
380  const STATUS_VALIDATED = 1;
384  const STATUS_RESILIATED = 0;
388  const STATUS_EXCLUDED = -2;
389 
390 
396  public function __construct($db)
397  {
398  $this->db = $db;
399  $this->statut = self::STATUS_DRAFT;
400  $this->status = $this->statut;
401  // l'adherent n'est pas public par defaut
402  $this->public = 0;
403  // les champs optionnels sont vides
404  $this->array_options = array();
405  }
406 
407 
408  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
425  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 = '')
426  {
427  // phpcs:enable
428  global $conf, $langs;
429 
430  // Detect if message is HTML
431  if ($msgishtml == -1) {
432  $msgishtml = 0;
433  if (dol_textishtml($text, 0)) {
434  $msgishtml = 1;
435  }
436  }
437 
438  dol_syslog('send_an_email msgishtml='.$msgishtml);
439 
440  $texttosend = $this->makeSubstitution($text);
441  $subjecttosend = $this->makeSubstitution($subject);
442  if ($msgishtml) {
443  $texttosend = dol_htmlentitiesbr($texttosend);
444  }
445 
446  // Envoi mail confirmation
447  $from = $conf->email_from;
448  if (!empty(getDolGlobalString('ADHERENT_MAIL_FROM'))) {
449  $from = getDolGlobalString('ADHERENT_MAIL_FROM');
450  }
451 
452  $trackid = 'mem'.$this->id;
453 
454  // Send email (substitutionarray must be done just before this)
455  include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
456  $mailfile = new CMailFile($subjecttosend, $this->email, $from, $texttosend, $filename_list, $mimetype_list, $mimefilename_list, $addr_cc, $addr_bcc, $deliveryreceipt, $msgishtml, '', '', $trackid, $moreinheader);
457  if ($mailfile->sendfile()) {
458  return 1;
459  } else {
460  $this->error = $langs->trans("ErrorFailedToSendMail", $from, $this->email).'. '.$mailfile->error;
461  return -1;
462  }
463  }
464 
465 
472  public function makeSubstitution($text)
473  {
474  global $conf, $langs;
475 
476  $birthday = dol_print_date($this->birth, 'day');
477 
478  $msgishtml = 0;
479  if (dol_textishtml($text, 1)) {
480  $msgishtml = 1;
481  }
482 
483  $infos = '';
484  if ($this->civility_id) {
485  $infos .= $langs->transnoentities("UserTitle").": ".$this->getCivilityLabel()."\n";
486  }
487  $infos .= $langs->transnoentities("id").": ".$this->id."\n";
488  $infos .= $langs->transnoentities("ref").": ".$this->ref."\n";
489  $infos .= $langs->transnoentities("Lastname").": ".$this->lastname."\n";
490  $infos .= $langs->transnoentities("Firstname").": ".$this->firstname."\n";
491  $infos .= $langs->transnoentities("Company").": ".$this->company."\n";
492  $infos .= $langs->transnoentities("Address").": ".$this->address."\n";
493  $infos .= $langs->transnoentities("Zip").": ".$this->zip."\n";
494  $infos .= $langs->transnoentities("Town").": ".$this->town."\n";
495  $infos .= $langs->transnoentities("Country").": ".$this->country."\n";
496  $infos .= $langs->transnoentities("EMail").": ".$this->email."\n";
497  $infos .= $langs->transnoentities("PhonePro").": ".$this->phone."\n";
498  $infos .= $langs->transnoentities("PhonePerso").": ".$this->phone_perso."\n";
499  $infos .= $langs->transnoentities("PhoneMobile").": ".$this->phone_mobile."\n";
500  if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
501  $infos .= $langs->transnoentities("Login").": ".$this->login."\n";
502  $infos .= $langs->transnoentities("Password").": ".$this->pass."\n";
503  }
504  $infos .= $langs->transnoentities("Birthday").": ".$birthday."\n";
505  $infos .= $langs->transnoentities("Photo").": ".$this->photo."\n";
506  $infos .= $langs->transnoentities("Public").": ".yn($this->public);
507 
508  // Substitutions
509  $substitutionarray = array(
510  '__ID__' => $this->id,
511  '__REF__' => $this->ref,
512  '__MEMBER_ID__' => $this->id,
513  '__CIVILITY__' => $this->getCivilityLabel(),
514  '__FIRSTNAME__' => $msgishtml ? dol_htmlentitiesbr($this->firstname) : ($this->firstname ? $this->firstname : ''),
515  '__LASTNAME__' => $msgishtml ? dol_htmlentitiesbr($this->lastname) : ($this->lastname ? $this->lastname : ''),
516  '__FULLNAME__' => $msgishtml ? dol_htmlentitiesbr($this->getFullName($langs)) : $this->getFullName($langs),
517  '__COMPANY__' => $msgishtml ? dol_htmlentitiesbr($this->company) : ($this->company ? $this->company : ''),
518  '__ADDRESS__' => $msgishtml ? dol_htmlentitiesbr($this->address) : ($this->address ? $this->address : ''),
519  '__ZIP__' => $msgishtml ? dol_htmlentitiesbr($this->zip) : ($this->zip ? $this->zip : ''),
520  '__TOWN__' => $msgishtml ? dol_htmlentitiesbr($this->town) : ($this->town ? $this->town : ''),
521  '__COUNTRY__' => $msgishtml ? dol_htmlentitiesbr($this->country) : ($this->country ? $this->country : ''),
522  '__EMAIL__' => $msgishtml ? dol_htmlentitiesbr($this->email) : ($this->email ? $this->email : ''),
523  '__BIRTH__' => $msgishtml ? dol_htmlentitiesbr($birthday) : ($birthday ? $birthday : ''),
524  '__PHOTO__' => $msgishtml ? dol_htmlentitiesbr($this->photo) : ($this->photo ? $this->photo : ''),
525  '__LOGIN__' => $msgishtml ? dol_htmlentitiesbr($this->login) : ($this->login ? $this->login : ''),
526  '__PASSWORD__' => $msgishtml ? dol_htmlentitiesbr($this->pass) : ($this->pass ? $this->pass : ''),
527  '__PHONE__' => $msgishtml ? dol_htmlentitiesbr($this->phone) : ($this->phone ? $this->phone : ''),
528  '__PHONEPRO__' => $msgishtml ? dol_htmlentitiesbr($this->phone_perso) : ($this->phone_perso ? $this->phone_perso : ''),
529  '__PHONEMOBILE__' => $msgishtml ? dol_htmlentitiesbr($this->phone_mobile) : ($this->phone_mobile ? $this->phone_mobile : ''),
530  '__TYPE__' => $msgishtml ? dol_htmlentitiesbr($this->type) : ($this->type ? $this->type : '')
531  );
532 
533  complete_substitutions_array($substitutionarray, $langs, $this);
534 
535  return make_substitutions($text, $substitutionarray, $langs);
536  }
537 
538 
546  public function getmorphylib($morphy = '', $addbadge = 0)
547  {
548  global $langs;
549 
550  // Clean var
551  if (!$morphy) {
552  $morphy = $this->morphy;
553  }
554 
555  if ($addbadge) {
556  $s = '';
557  $labeltoshowm = $langs->trans("Moral");
558  $labeltoshowp = $langs->trans("Physical");
559  if ($morphy == 'phy') {
560  $labeltoshow = $labeltoshowp;
561  if ($addbadge == 2) {
562  $labeltoshow = dol_strtoupper(dolGetFirstLetters($labeltoshowp));
563  if ($labeltoshow == dol_strtoupper(dolGetFirstLetters($labeltoshowm))) {
564  $labeltoshow = dol_strtoupper(dolGetFirstLetters($labeltoshowp, 2));
565  }
566  }
567  $s .= '<span class="member-individual-back paddingleftimp paddingrightimp" title="'.$langs->trans("Physical").'">'.$labeltoshow.'</span>';
568  }
569  if ($morphy == 'mor') {
570  $labeltoshow = $labeltoshowm;
571  if ($addbadge == 2) {
572  $labeltoshow = dol_strtoupper(dolGetFirstLetters($labeltoshowm));
573  if ($labeltoshow == dol_strtoupper(dolGetFirstLetters($labeltoshowp))) {
574  $labeltoshow = dol_strtoupper(dolGetFirstLetters($labeltoshowm, 2));
575  }
576  }
577  $s .= '<span class="member-company-back paddingleftimp paddingrightimp" title="'.$langs->trans("Moral").'">'.$labeltoshow.'</span>';
578  }
579  } else {
580  if ($morphy == 'phy') {
581  $s = $langs->trans("Physical");
582  } elseif ($morphy == 'mor') {
583  $s = $langs->trans("Moral");
584  }
585  }
586 
587  return $s;
588  }
589 
597  public function create($user, $notrigger = 0)
598  {
599  global $conf, $langs, $mysoc;
600 
601  $error = 0;
602 
603  $now = dol_now();
604 
605  // Clean parameters
606  $this->import_key = trim($this->import_key);
607 
608  // Check parameters
609  if (!empty($conf->global->ADHERENT_MAIL_REQUIRED) && !isValidEMail($this->email)) {
610  $langs->load("errors");
611  $this->error = $langs->trans("ErrorBadEMail", $this->email);
612  return -1;
613  }
614  if (!$this->datec) {
615  $this->datec = $now;
616  }
617  if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
618  if (empty($this->login)) {
619  $this->error = $langs->trans("ErrorWrongValueForParameterX", "Login");
620  return -1;
621  }
622  }
623 
624  $this->db->begin();
625 
626  // Insert member
627  $sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent";
628  $sql .= " (ref, datec,login,fk_user_author,fk_user_mod,fk_user_valid,morphy,fk_adherent_type,entity,import_key, ip)";
629  $sql .= " VALUES (";
630  $sql .= " '(PROV)'";
631  $sql .= ", '".$this->db->idate($this->datec)."'";
632  $sql .= ", ".($this->login ? "'".$this->db->escape($this->login)."'" : "null");
633  $sql .= ", ".($user->id > 0 ? $user->id : "null"); // Can be null because member can be created by a guest or a script
634  $sql .= ", null, null, '".$this->db->escape($this->morphy)."'";
635  $sql .= ", ".((int) $this->typeid);
636  $sql .= ", ".$conf->entity;
637  $sql .= ", ".(!empty($this->import_key) ? "'".$this->db->escape($this->import_key)."'" : "null");
638  $sql .= ", ".(!empty($this->ip) ? "'".$this->db->escape($this->ip)."'" : "null");
639  $sql .= ")";
640 
641  dol_syslog(get_class($this)."::create", LOG_DEBUG);
642  $result = $this->db->query($sql);
643  if ($result) {
644  $id = $this->db->last_insert_id(MAIN_DB_PREFIX."adherent");
645  if ($id > 0) {
646  $this->id = $id;
647  if (getDolGlobalString('MEMBER_CODEMEMBER_ADDON') == '') {
648  // keep old numbering
649  $this->ref = (string) $id;
650  } else {
651  // auto code
652  $modfile = dol_buildpath('core/modules/member/'.getDolGlobalString('MEMBER_CODEMEMBER_ADDON').'.php', 0);
653  try {
654  require_once $modfile;
655  $modname = getDolGlobalString('MEMBER_CODEMEMBER_ADDON');
656  $modCodeMember = new $modname;
657  $this->ref = $modCodeMember->getNextValue($mysoc, $this);
658  } catch (Exception $e) {
659  dol_syslog($e->getMessage(), LOG_ERR);
660  $error++;
661  }
662  }
663 
664  // Update minor fields
665  $result = $this->update($user, 1, 1, 0, 0, 'add'); // nosync is 1 to avoid update data of user
666  if ($result < 0) {
667  $this->db->rollback();
668  return -1;
669  }
670 
671  // Add link to user
672  if ($this->user_id) {
673  // Add link to user
674  $sql = "UPDATE ".MAIN_DB_PREFIX."user SET";
675  $sql .= " fk_member = ".((int) $this->id);
676  $sql .= " WHERE rowid = ".((int) $this->user_id);
677  dol_syslog(get_class($this)."::create", LOG_DEBUG);
678  $resql = $this->db->query($sql);
679  if (!$resql) {
680  $this->error = 'Failed to update user to make link with member';
681  $this->db->rollback();
682  return -4;
683  }
684  }
685 
686  if (!$notrigger) {
687  // Call trigger
688  $result = $this->call_trigger('MEMBER_CREATE', $user);
689  if ($result < 0) {
690  $error++;
691  }
692  // End call triggers
693  }
694 
695  if (count($this->errors)) {
696  dol_syslog(get_class($this)."::create ".implode(',', $this->errors), LOG_ERR);
697  $this->db->rollback();
698  return -3;
699  } else {
700  $this->db->commit();
701  return $this->id;
702  }
703  } else {
704  $this->error = 'Failed to get last insert id';
705  dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
706  $this->db->rollback();
707  return -2;
708  }
709  } else {
710  $this->error = $this->db->error();
711  $this->db->rollback();
712  return -1;
713  }
714  }
715 
716 
728  public function update($user, $notrigger = 0, $nosyncuser = 0, $nosyncuserpass = 0, $nosyncthirdparty = 0, $action = 'update')
729  {
730  global $conf, $langs, $hookmanager;
731 
732  require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
733 
734  $nbrowsaffected = 0;
735  $error = 0;
736 
737  dol_syslog(get_class($this)."::update notrigger=".$notrigger.", nosyncuser=".$nosyncuser.", nosyncuserpass=".$nosyncuserpass." nosyncthirdparty=".$nosyncthirdparty.", email=".$this->email);
738 
739  // Clean parameters
740  $this->lastname = trim($this->lastname) ? trim($this->lastname) : trim($this->lastname);
741  $this->firstname = trim($this->firstname) ? trim($this->firstname) : trim($this->firstname);
742  $this->gender = trim($this->gender);
743  $this->address = ($this->address ? $this->address : $this->address);
744  $this->zip = ($this->zip ? $this->zip : $this->zip);
745  $this->town = ($this->town ? $this->town : $this->town);
746  $this->country_id = ($this->country_id > 0 ? $this->country_id : $this->country_id);
747  $this->state_id = ($this->state_id > 0 ? $this->state_id : $this->state_id);
748  $this->note_public = ($this->note_public ? $this->note_public : $this->note_public);
749  $this->note_private = ($this->note_private ? $this->note_private : $this->note_private);
750  $this->url = $this->url ?clean_url($this->url, 0) : '';
751  $this->setUpperOrLowerCase();
752  // Check parameters
753  if (!empty($conf->global->ADHERENT_MAIL_REQUIRED) && !isValidEMail($this->email)) {
754  $langs->load("errors");
755  $this->error = $langs->trans("ErrorBadEMail", $this->email);
756  return -1;
757  }
758 
759  $this->db->begin();
760 
761  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
762  $sql .= " ref = '".$this->db->escape($this->ref)."'";
763  $sql .= ", civility = ".($this->civility_id ? "'".$this->db->escape($this->civility_id)."'" : "null");
764  $sql .= ", firstname = ".($this->firstname ? "'".$this->db->escape($this->firstname)."'" : "null");
765  $sql .= ", lastname = ".($this->lastname ? "'".$this->db->escape($this->lastname)."'" : "null");
766  $sql .= ", gender = ".($this->gender != -1 ? "'".$this->db->escape($this->gender)."'" : "null"); // 'man' or 'woman'
767  $sql .= ", login = ".($this->login ? "'".$this->db->escape($this->login)."'" : "null");
768  $sql .= ", societe = ".($this->company ? "'".$this->db->escape($this->company)."'" : ($this->societe ? "'".$this->db->escape($this->societe)."'" : "null"));
769  if ($this->socid) {
770  $sql .= ", fk_soc = ".($this->socid > 0 ? $this->db->escape($this->socid) : "null"); // Must be modified only when creating from a third-party
771  }
772  $sql .= ", address = ".($this->address ? "'".$this->db->escape($this->address)."'" : "null");
773  $sql .= ", zip = ".($this->zip ? "'".$this->db->escape($this->zip)."'" : "null");
774  $sql .= ", town = ".($this->town ? "'".$this->db->escape($this->town)."'" : "null");
775  $sql .= ", country = ".($this->country_id > 0 ? $this->db->escape($this->country_id) : "null");
776  $sql .= ", state_id = ".($this->state_id > 0 ? $this->db->escape($this->state_id) : "null");
777  $sql .= ", email = '".$this->db->escape($this->email)."'";
778  $sql .= ", url = ".(!empty($this->url) ? "'".$this->db->escape($this->url)."'" : "null");
779  $sql .= ", socialnetworks = ".($this->socialnetworks ? "'".$this->db->escape(json_encode($this->socialnetworks))."'" : "null");
780  $sql .= ", phone = ".($this->phone ? "'".$this->db->escape($this->phone)."'" : "null");
781  $sql .= ", phone_perso = ".($this->phone_perso ? "'".$this->db->escape($this->phone_perso)."'" : "null");
782  $sql .= ", phone_mobile = ".($this->phone_mobile ? "'".$this->db->escape($this->phone_mobile)."'" : "null");
783  $sql .= ", note_private = ".($this->note_private ? "'".$this->db->escape($this->note_private)."'" : "null");
784  $sql .= ", note_public = ".($this->note_public ? "'".$this->db->escape($this->note_public)."'" : "null");
785  $sql .= ", photo = ".($this->photo ? "'".$this->db->escape($this->photo)."'" : "null");
786  $sql .= ", public = '".$this->db->escape($this->public)."'";
787  $sql .= ", statut = ".$this->db->escape($this->statut);
788  $sql .= ", default_lang = ".(!empty($this->default_lang) ? "'".$this->db->escape($this->default_lang)."'" : "null");
789  $sql .= ", fk_adherent_type = ".$this->db->escape($this->typeid);
790  $sql .= ", morphy = '".$this->db->escape($this->morphy)."'";
791  $sql .= ", birth = ".($this->birth ? "'".$this->db->idate($this->birth)."'" : "null");
792 
793  if ($this->datefin) {
794  $sql .= ", datefin = '".$this->db->idate($this->datefin)."'"; // Must be modified only when deleting a subscription
795  }
796  if ($this->datevalid) {
797  $sql .= ", datevalid = '".$this->db->idate($this->datevalid)."'"; // Must be modified only when validating a member
798  }
799  $sql .= ", fk_user_mod = ".($user->id > 0 ? $user->id : 'null'); // Can be null because member can be create by a guest
800  $sql .= " WHERE rowid = ".((int) $this->id);
801 
802  // If we change the type of membership, we set also label of new type
803  if (!empty($this->oldcopy) && $this->typeid != $this->oldcopy->typeid) {
804  $sql2 = "SELECT libelle as label";
805  $sql2 .= " FROM ".MAIN_DB_PREFIX."adherent_type";
806  $sql2 .= " WHERE rowid = ".((int) $this->typeid);
807  $resql2 = $this->db->query($sql2);
808  if ($resql2) {
809  while ($obj = $this->db->fetch_object($resql2)) {
810  $this->type = $obj->label;
811  }
812  }
813  }
814 
815  dol_syslog(get_class($this)."::update update member", LOG_DEBUG);
816  $resql = $this->db->query($sql);
817  if ($resql) {
818  unset($this->country_code);
819  unset($this->country);
820  unset($this->state_code);
821  unset($this->state);
822 
823  $nbrowsaffected += $this->db->affected_rows($resql);
824 
825  $action = 'update';
826 
827  // Actions on extra fields
828  if (!$error) {
829  $result = $this->insertExtraFields();
830  if ($result < 0) {
831  $error++;
832  }
833  }
834 
835  // Update password
836  if (!$error && $this->pass) {
837  dol_syslog(get_class($this)."::update update password");
838  if ($this->pass != $this->pass_indatabase && $this->pass != $this->pass_indatabase_crypted) {
839  $isencrypted = empty($conf->global->DATABASE_PWD_ENCRYPTED) ? 0 : 1;
840 
841  // If password to set differs from the one found into database
842  $result = $this->setPassword($user, $this->pass, $isencrypted, $notrigger, $nosyncuserpass);
843  if (!$nbrowsaffected) {
844  $nbrowsaffected++;
845  }
846  }
847  }
848 
849  // Remove links to user and replace with new one
850  if (!$error) {
851  dol_syslog(get_class($this)."::update update link to user");
852  $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = NULL WHERE fk_member = ".((int) $this->id);
853  dol_syslog(get_class($this)."::update", LOG_DEBUG);
854  $resql = $this->db->query($sql);
855  if (!$resql) {
856  $this->error = $this->db->error();
857  $this->db->rollback();
858  return -5;
859  }
860  // If there is a user linked to this member
861  if ($this->user_id > 0) {
862  $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = ".((int) $this->id)." WHERE rowid = ".((int) $this->user_id);
863  dol_syslog(get_class($this)."::update", LOG_DEBUG);
864  $resql = $this->db->query($sql);
865  if (!$resql) {
866  $this->error = $this->db->error();
867  $this->db->rollback();
868  return -5;
869  }
870  }
871  }
872 
873  if (!$error && $nbrowsaffected) { // If something has change in main data
874  // Update information on linked user if it is an update
875  if (!$error && $this->user_id > 0 && !$nosyncuser) {
876  require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
877 
878  dol_syslog(get_class($this)."::update update linked user");
879 
880  $luser = new User($this->db);
881  $result = $luser->fetch($this->user_id);
882 
883  if ($result >= 0) {
884  //var_dump($this->user_login);exit;
885  //var_dump($this->login);exit;
886 
887  // 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.
888  if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
889  $luser->login = $this->login;
890  }
891 
892  $luser->ref = $this->ref;
893  $luser->civility_id = $this->civility_id;
894  $luser->firstname = $this->firstname;
895  $luser->lastname = $this->lastname;
896  $luser->gender = $this->gender;
897  $luser->pass = $this->pass;
898  //$luser->socid=$this->fk_soc; // We do not enable this. This may transform a user into an external user.
899 
900  $luser->birth = $this->birth;
901 
902  $luser->address = $this->address;
903  $luser->zip = $this->zip;
904  $luser->town = $this->town;
905  $luser->country_id = $this->country_id;
906  $luser->state_id = $this->state_id;
907 
908  $luser->email = $this->email;
909  $luser->socialnetworks = $this->socialnetworks;
910  $luser->office_phone = $this->phone;
911  $luser->user_mobile = $this->phone_mobile;
912 
913  $luser->lang = $this->default_lang;
914 
915  $luser->fk_member = $this->id;
916 
917  $result = $luser->update($user, 0, 1, 1); // Use nosync to 1 to avoid cyclic updates
918  if ($result < 0) {
919  $this->error = $luser->error;
920  dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
921  $error++;
922  }
923  } else {
924  $this->error = $luser->error;
925  $error++;
926  }
927  }
928 
929  // Update information on linked thirdparty if it is an update
930  if (!$error && $this->fk_soc > 0 && !$nosyncthirdparty) {
931  require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
932 
933  dol_syslog(get_class($this)."::update update linked thirdparty");
934 
935  // This member is linked with a thirdparty, so we also update thirdparty informations
936  // if this is an update.
937  $lthirdparty = new Societe($this->db);
938  $result = $lthirdparty->fetch($this->fk_soc);
939 
940  if ($result > 0) {
941  $lthirdparty->address = $this->address;
942  $lthirdparty->zip = $this->zip;
943  $lthirdparty->town = $this->town;
944  $lthirdparty->email = $this->email;
945  $lthirdparty->socialnetworks = $this->socialnetworks;
946  $lthirdparty->phone = $this->phone;
947  $lthirdparty->state_id = $this->state_id;
948  $lthirdparty->country_id = $this->country_id;
949  //$lthirdparty->phone_mobile=$this->phone_mobile;
950  $lthirdparty->default_lang = $this->default_lang;
951 
952  $result = $lthirdparty->update($this->fk_soc, $user, 0, 1, 1, 'update'); // Use sync to 0 to avoid cyclic updates
953 
954  if ($result < 0) {
955  $this->error = $lthirdparty->error;
956  $this->errors = $lthirdparty->errors;
957  dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
958  $error++;
959  }
960  } elseif ($result < 0) {
961  $this->error = $lthirdparty->error;
962  $error++;
963  }
964  }
965  }
966 
967  if (!$error && !$notrigger) {
968  // Call trigger
969  $result = $this->call_trigger('MEMBER_MODIFY', $user);
970  if ($result < 0) {
971  $error++;
972  }
973  // End call triggers
974  }
975 
976  if (!$error) {
977  $this->db->commit();
978  return $nbrowsaffected;
979  } else {
980  $this->db->rollback();
981  return -1;
982  }
983  } else {
984  $this->db->rollback();
985  $this->error = $this->db->lasterror();
986  return -2;
987  }
988  }
989 
990 
991  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
999  public function update_end_date($user)
1000  {
1001  // phpcs:enable
1002  $this->db->begin();
1003 
1004  // Search for last subscription id and end date
1005  $sql = "SELECT rowid, datec as dateop, dateadh as datedeb, datef as datefin";
1006  $sql .= " FROM ".MAIN_DB_PREFIX."subscription";
1007  $sql .= " WHERE fk_adherent = ".((int) $this->id);
1008  $sql .= " ORDER by dateadh DESC"; // Sort by start subscription date
1009 
1010  dol_syslog(get_class($this)."::update_end_date", LOG_DEBUG);
1011  $resql = $this->db->query($sql);
1012  if ($resql) {
1013  $obj = $this->db->fetch_object($resql);
1014  $dateop = $this->db->jdate($obj->dateop);
1015  $datedeb = $this->db->jdate($obj->datedeb);
1016  $datefin = $this->db->jdate($obj->datefin);
1017 
1018  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
1019  $sql .= " datefin=".($datefin != '' ? "'".$this->db->idate($datefin)."'" : "null");
1020  $sql .= " WHERE rowid = ".((int) $this->id);
1021 
1022  dol_syslog(get_class($this)."::update_end_date", LOG_DEBUG);
1023  $resql = $this->db->query($sql);
1024  if ($resql) {
1025  $this->last_subscription_date = $dateop;
1026  $this->last_subscription_date_start = $datedeb;
1027  $this->last_subscription_date_end = $datefin;
1028  $this->datefin = $datefin;
1029  $this->db->commit();
1030  return 1;
1031  } else {
1032  $this->db->rollback();
1033  return -1;
1034  }
1035  } else {
1036  $this->error = $this->db->lasterror();
1037  $this->db->rollback();
1038  return -1;
1039  }
1040  }
1041 
1050  public function delete($rowid, $user, $notrigger = 0)
1051  {
1052  global $conf, $langs;
1053 
1054  $result = 0;
1055  $error = 0;
1056  $errorflag = 0;
1057 
1058  // Check parameters
1059  if (empty($rowid)) {
1060  $rowid = $this->id;
1061  }
1062 
1063  $this->db->begin();
1064 
1065  if (!$error && !$notrigger) {
1066  // Call trigger
1067  $result = $this->call_trigger('MEMBER_DELETE', $user);
1068  if ($result < 0) {
1069  $error++;
1070  }
1071  // End call triggers
1072  }
1073 
1074  // Remove category
1075  $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_member WHERE fk_member = ".((int) $rowid);
1076  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1077  $resql = $this->db->query($sql);
1078  if (!$resql) {
1079  $error++;
1080  $this->error .= $this->db->lasterror();
1081  $errorflag = -1;
1082  }
1083 
1084  // Remove subscription
1085  if (!$error) {
1086  $sql = "DELETE FROM ".MAIN_DB_PREFIX."subscription WHERE fk_adherent = ".((int) $rowid);
1087  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1088  $resql = $this->db->query($sql);
1089  if (!$resql) {
1090  $error++;
1091  $this->error .= $this->db->lasterror();
1092  $errorflag = -2;
1093  }
1094  }
1095 
1096  // Remove linked user
1097  if (!$error) {
1098  $ret = $this->setUserId(0);
1099  if ($ret < 0) {
1100  $error++;
1101  $this->error .= $this->db->lasterror();
1102  $errorflag = -3;
1103  }
1104  }
1105 
1106  // Removed extrafields
1107  if (!$error) {
1108  $result = $this->deleteExtraFields();
1109  if ($result < 0) {
1110  $error++;
1111  $errorflag = -4;
1112  dol_syslog(get_class($this)."::delete erreur ".$errorflag." ".$this->error, LOG_ERR);
1113  }
1114  }
1115 
1116  // Remove adherent
1117  if (!$error) {
1118  $sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent WHERE rowid = ".((int) $rowid);
1119  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1120  $resql = $this->db->query($sql);
1121  if (!$resql) {
1122  $error++;
1123  $this->error .= $this->db->lasterror();
1124  $errorflag = -5;
1125  }
1126  }
1127 
1128  if (!$error) {
1129  $this->db->commit();
1130  return 1;
1131  } else {
1132  $this->db->rollback();
1133  return $errorflag;
1134  }
1135  }
1136 
1137 
1148  public function setPassword($user, $password = '', $isencrypted = 0, $notrigger = 0, $nosyncuser = 0)
1149  {
1150  global $conf, $langs;
1151 
1152  $error = 0;
1153 
1154  dol_syslog(get_class($this)."::setPassword user=".$user->id." password=".preg_replace('/./i', '*', $password)." isencrypted=".$isencrypted);
1155 
1156  // If new password not provided, we generate one
1157  if (!$password) {
1158  require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
1159  $password = getRandomPassword(false);
1160  }
1161 
1162  // Crypt password
1163  $password_crypted = dol_hash($password);
1164 
1165  $password_indatabase = '';
1166  if (!$isencrypted) {
1167  $password_indatabase = $password;
1168  }
1169 
1170  $this->db->begin();
1171 
1172  // Mise a jour
1173  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent";
1174  $sql .= " SET pass_crypted = '".$this->db->escape($password_crypted)."'";
1175  //if (!empty($conf->global->DATABASE_PWD_ENCRYPTED))
1176  if ($isencrypted) {
1177  $sql .= ", pass = null";
1178  } else {
1179  $sql .= ", pass = '".$this->db->escape($password_indatabase)."'";
1180  }
1181  $sql .= " WHERE rowid = ".((int) $this->id);
1182 
1183  //dol_syslog("Adherent::Password sql=hidden");
1184  dol_syslog(get_class($this)."::setPassword", LOG_DEBUG);
1185  $result = $this->db->query($sql);
1186  if ($result) {
1187  $nbaffectedrows = $this->db->affected_rows($result);
1188 
1189  if ($nbaffectedrows) {
1190  $this->pass = $password;
1191  $this->pass_indatabase = $password_indatabase;
1192  $this->pass_indatabase_crypted = $password_crypted;
1193 
1194  if ($this->user_id && !$nosyncuser) {
1195  require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
1196 
1197  // This member is linked with a user, so we also update users informations
1198  // if this is an update.
1199  $luser = new User($this->db);
1200  $result = $luser->fetch($this->user_id);
1201 
1202  if ($result >= 0) {
1203  $result = $luser->setPassword($user, $this->pass, 0, 0, 1);
1204  if ($result < 0) {
1205  $this->error = $luser->error;
1206  dol_syslog(get_class($this)."::setPassword ".$this->error, LOG_ERR);
1207  $error++;
1208  }
1209  } else {
1210  $this->error = $luser->error;
1211  $error++;
1212  }
1213  }
1214 
1215  if (!$error && !$notrigger) {
1216  // Call trigger
1217  $result = $this->call_trigger('MEMBER_NEW_PASSWORD', $user);
1218  if ($result < 0) {
1219  $error++;
1220  $this->db->rollback();
1221  return -1;
1222  }
1223  // End call triggers
1224  }
1225 
1226  $this->db->commit();
1227  return $this->pass;
1228  } else {
1229  $this->db->rollback();
1230  return 0;
1231  }
1232  } else {
1233  $this->db->rollback();
1234  dol_print_error($this->db);
1235  return -1;
1236  }
1237  }
1238 
1239 
1246  public function setUserId($userid)
1247  {
1248  global $conf, $langs;
1249 
1250  $this->db->begin();
1251 
1252  // If user is linked to this member, remove old link to this member
1253  $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = NULL WHERE fk_member = ".((int) $this->id);
1254  dol_syslog(get_class($this)."::setUserId", LOG_DEBUG);
1255  $resql = $this->db->query($sql);
1256  if (!$resql) {
1257  $this->error = $this->db->error();
1258  $this->db->rollback();
1259  return -1;
1260  }
1261 
1262  // Set link to user
1263  if ($userid > 0) {
1264  $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = ".((int) $this->id);
1265  $sql .= " WHERE rowid = ".((int) $userid);
1266  dol_syslog(get_class($this)."::setUserId", LOG_DEBUG);
1267  $resql = $this->db->query($sql);
1268  if (!$resql) {
1269  $this->error = $this->db->error();
1270  $this->db->rollback();
1271  return -2;
1272  }
1273  }
1274 
1275  $this->db->commit();
1276 
1277  return 1;
1278  }
1279 
1280 
1287  public function setThirdPartyId($thirdpartyid)
1288  {
1289  global $conf, $langs;
1290 
1291  $this->db->begin();
1292 
1293  // Remove link to third party onto any other members
1294  if ($thirdpartyid > 0) {
1295  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET fk_soc = null";
1296  $sql .= " WHERE fk_soc = ".((int) $thirdpartyid);
1297  $sql .= " AND entity = ".$conf->entity;
1298  dol_syslog(get_class($this)."::setThirdPartyId", LOG_DEBUG);
1299  $resql = $this->db->query($sql);
1300  }
1301 
1302  // Add link to third party for current member
1303  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET fk_soc = ".($thirdpartyid > 0 ? $thirdpartyid : 'null');
1304  $sql .= " WHERE rowid = ".((int) $this->id);
1305 
1306  dol_syslog(get_class($this)."::setThirdPartyId", LOG_DEBUG);
1307  $resql = $this->db->query($sql);
1308  if ($resql) {
1309  $this->db->commit();
1310  return 1;
1311  } else {
1312  $this->error = $this->db->error();
1313  $this->db->rollback();
1314  return -1;
1315  }
1316  }
1317 
1318 
1319  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1326  public function fetch_login($login)
1327  {
1328  // phpcs:enable
1329  global $conf;
1330 
1331  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."adherent";
1332  $sql .= " WHERE login='".$this->db->escape($login)."'";
1333  $sql .= " AND entity = ".$conf->entity;
1334 
1335  $resql = $this->db->query($sql);
1336  if ($resql) {
1337  if ($this->db->num_rows($resql)) {
1338  $obj = $this->db->fetch_object($resql);
1339  $this->fetch($obj->rowid);
1340  }
1341  } else {
1342  dol_print_error($this->db);
1343  }
1344  }
1345 
1346  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1354  public function fetch_name($firstname, $lastname)
1355  {
1356  // phpcs:enable
1357  global $conf;
1358 
1359  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."adherent";
1360  $sql .= " WHERE firstname='".$this->db->escape($firstname)."'";
1361  $sql .= " AND lastname='".$this->db->escape($lastname)."'";
1362  $sql .= " AND entity = ".$conf->entity;
1363 
1364  $resql = $this->db->query($sql);
1365  if ($resql) {
1366  if ($this->db->num_rows($resql)) {
1367  $obj = $this->db->fetch_object($resql);
1368  $this->fetch($obj->rowid);
1369  }
1370  } else {
1371  dol_print_error($this->db);
1372  }
1373  }
1374 
1386  public function fetch($rowid, $ref = '', $fk_soc = '', $ref_ext = '', $fetch_optionals = true, $fetch_subscriptions = true)
1387  {
1388  global $langs;
1389 
1390  $sql = "SELECT d.rowid, d.ref, d.ref_ext, d.civility as civility_code, d.gender, d.firstname, d.lastname,";
1391  $sql .= " d.societe as company, d.fk_soc, d.statut, d.public, d.address, d.zip, d.town, d.note_private,";
1392  $sql .= " d.note_public,";
1393  $sql .= " d.email, d.url, d.socialnetworks, d.phone, d.phone_perso, d.phone_mobile, d.login, d.pass, d.pass_crypted,";
1394  $sql .= " d.photo, d.fk_adherent_type, d.morphy, d.entity,";
1395  $sql .= " d.datec as datec,";
1396  $sql .= " d.tms as datem,";
1397  $sql .= " d.datefin as datefin, d.default_lang,";
1398  $sql .= " d.birth as birthday,";
1399  $sql .= " d.datevalid as datev,";
1400  $sql .= " d.country,";
1401  $sql .= " d.state_id,";
1402  $sql .= " d.model_pdf,";
1403  $sql .= " c.rowid as country_id, c.code as country_code, c.label as country,";
1404  $sql .= " dep.nom as state, dep.code_departement as state_code,";
1405  $sql .= " t.libelle as type, t.subscription as subscription,";
1406  $sql .= " u.rowid as user_id, u.login as user_login";
1407  $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as t, ".MAIN_DB_PREFIX."adherent as d";
1408  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON d.country = c.rowid";
1409  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as dep ON d.state_id = dep.rowid";
1410  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON d.rowid = u.fk_member";
1411  $sql .= " WHERE d.fk_adherent_type = t.rowid";
1412  if ($rowid) {
1413  $sql .= " AND d.rowid=".((int) $rowid);
1414  } elseif ($ref || $fk_soc) {
1415  $sql .= " AND d.entity IN (".getEntity('adherent').")";
1416  if ($ref) {
1417  $sql .= " AND d.ref='".$this->db->escape($ref)."'";
1418  } elseif ($fk_soc > 0) {
1419  $sql .= " AND d.fk_soc=".((int) $fk_soc);
1420  }
1421  } elseif ($ref_ext) {
1422  $sql .= " AND d.ref_ext='".$this->db->escape($ref_ext)."'";
1423  }
1424 
1425  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
1426  $resql = $this->db->query($sql);
1427  if ($resql) {
1428  if ($this->db->num_rows($resql)) {
1429  $obj = $this->db->fetch_object($resql);
1430 
1431  $this->entity = $obj->entity;
1432  $this->id = $obj->rowid;
1433  $this->ref = $obj->ref;
1434  $this->ref_ext = $obj->ref_ext;
1435 
1436  $this->civility_id = $obj->civility_code; // Bad. Kept for backard compatibility
1437  $this->civility_code = $obj->civility_code;
1438  $this->civility = $obj->civility_code ? ($langs->trans("Civility".$obj->civility_code) != ("Civility".$obj->civility_code) ? $langs->trans("Civility".$obj->civility_code) : $obj->civility_code) : '';
1439 
1440  $this->firstname = $obj->firstname;
1441  $this->lastname = $obj->lastname;
1442  $this->gender = $obj->gender;
1443  $this->login = $obj->login;
1444  $this->societe = $obj->company;
1445  $this->company = $obj->company;
1446  $this->socid = $obj->fk_soc;
1447  $this->fk_soc = $obj->fk_soc; // For backward compatibility
1448  $this->address = $obj->address;
1449  $this->zip = $obj->zip;
1450  $this->town = $obj->town;
1451 
1452  $this->pass = $obj->pass;
1453  $this->pass_indatabase = $obj->pass;
1454  $this->pass_indatabase_crypted = $obj->pass_crypted;
1455 
1456  $this->state_id = $obj->state_id;
1457  $this->state_code = $obj->state_id ? $obj->state_code : '';
1458  $this->state = $obj->state_id ? $obj->state : '';
1459 
1460  $this->country_id = $obj->country_id;
1461  $this->country_code = $obj->country_code;
1462  if ($langs->trans("Country".$obj->country_code) != "Country".$obj->country_code) {
1463  $this->country = $langs->transnoentitiesnoconv("Country".$obj->country_code);
1464  } else {
1465  $this->country = $obj->country;
1466  }
1467 
1468  $this->phone = $obj->phone;
1469  $this->phone_perso = $obj->phone_perso;
1470  $this->phone_mobile = $obj->phone_mobile;
1471  $this->email = $obj->email;
1472  $this->url = $obj->url;
1473 
1474  $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks, true) : array());
1475 
1476  $this->photo = $obj->photo;
1477  $this->statut = $obj->statut;
1478  $this->status = $obj->statut;
1479  $this->public = $obj->public;
1480 
1481  $this->datec = $this->db->jdate($obj->datec);
1482  $this->date_creation = $this->db->jdate($obj->datec);
1483  $this->datem = $this->db->jdate($obj->datem);
1484  $this->date_modification = $this->db->jdate($obj->datem);
1485  $this->datefin = $this->db->jdate($obj->datefin);
1486  $this->datevalid = $this->db->jdate($obj->datev);
1487  $this->date_validation = $this->db->jdate($obj->datev);
1488  $this->birth = $this->db->jdate($obj->birthday);
1489 
1490  $this->default_lang = $obj->default_lang;
1491 
1492  $this->note_private = $obj->note_private;
1493  $this->note_public = $obj->note_public;
1494  $this->morphy = $obj->morphy;
1495 
1496  $this->typeid = $obj->fk_adherent_type;
1497  $this->type = $obj->type;
1498  $this->need_subscription = $obj->subscription;
1499 
1500  $this->user_id = $obj->user_id;
1501  $this->user_login = $obj->user_login;
1502 
1503  $this->model_pdf = $obj->model_pdf;
1504 
1505  // Retrieve all extrafield
1506  // fetch optionals attributes and labels
1507  if ($fetch_optionals) {
1508  $this->fetch_optionals();
1509  }
1510 
1511  // Load other properties
1512  if ($fetch_subscriptions) {
1513  $result = $this->fetch_subscriptions();
1514  }
1515 
1516  return $this->id;
1517  } else {
1518  return 0;
1519  }
1520  } else {
1521  $this->error = $this->db->lasterror();
1522  return -1;
1523  }
1524  }
1525 
1526 
1527  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1536  public function fetch_subscriptions()
1537  {
1538  // phpcs:enable
1539  global $langs;
1540 
1541  require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
1542 
1543  $sql = "SELECT c.rowid, c.fk_adherent, c.fk_type, c.subscription, c.note as note_public, c.fk_bank,";
1544  $sql .= " c.tms as datem,";
1545  $sql .= " c.datec as datec,";
1546  $sql .= " c.dateadh as dateh,";
1547  $sql .= " c.datef as datef";
1548  $sql .= " FROM ".MAIN_DB_PREFIX."subscription as c";
1549  $sql .= " WHERE c.fk_adherent = ".((int) $this->id);
1550  $sql .= " ORDER BY c.dateadh";
1551  dol_syslog(get_class($this)."::fetch_subscriptions", LOG_DEBUG);
1552 
1553  $resql = $this->db->query($sql);
1554  if ($resql) {
1555  $this->subscriptions = array();
1556 
1557  $i = 0;
1558  while ($obj = $this->db->fetch_object($resql)) {
1559  if ($i == 0) {
1560  $this->first_subscription_date = $this->db->jdate($obj->datec);
1561  $this->first_subscription_date_start = $this->db->jdate($obj->dateh);
1562  $this->first_subscription_date_end = $this->db->jdate($obj->datef);
1563  $this->first_subscription_amount = $obj->subscription;
1564  }
1565  $this->last_subscription_date = $this->db->jdate($obj->datec);
1566  $this->last_subscription_date_start = $this->db->jdate($obj->dateh);
1567  $this->last_subscription_date_end = $this->db->jdate($obj->datef);
1568  $this->last_subscription_amount = $obj->subscription;
1569 
1570  $subscription = new Subscription($this->db);
1571  $subscription->id = $obj->rowid;
1572  $subscription->fk_adherent = $obj->fk_adherent;
1573  $subscription->fk_type = $obj->fk_type;
1574  $subscription->amount = $obj->subscription;
1575  $subscription->note = $obj->note_public;
1576  $subscription->note_public = $obj->note_public;
1577  $subscription->fk_bank = $obj->fk_bank;
1578  $subscription->datem = $this->db->jdate($obj->datem);
1579  $subscription->datec = $this->db->jdate($obj->datec);
1580  $subscription->dateh = $this->db->jdate($obj->dateh);
1581  $subscription->datef = $this->db->jdate($obj->datef);
1582 
1583  $this->subscriptions[] = $subscription;
1584 
1585  $i++;
1586  }
1587  return 1;
1588  } else {
1589  $this->error = $this->db->error().' sql='.$sql;
1590  return -1;
1591  }
1592  }
1593 
1594 
1601  public function fetchPartnerships($mode)
1602  {
1603  global $langs;
1604 
1605  require_once DOL_DOCUMENT_ROOT.'/partnership/class/partnership.class.php';
1606 
1607 
1608  $this->partnerships[] = array();
1609 
1610  return 1;
1611  }
1612 
1613 
1629  public function subscription($date, $amount, $accountid = 0, $operation = '', $label = '', $num_chq = '', $emetteur_nom = '', $emetteur_banque = '', $datesubend = 0, $fk_type = null)
1630  {
1631  global $conf, $langs, $user;
1632 
1633  require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
1634 
1635  $error = 0;
1636 
1637  // Clean parameters
1638  if (!$amount) {
1639  $amount = 0;
1640  }
1641 
1642  $this->db->begin();
1643 
1644  if ($datesubend) {
1645  $datefin = $datesubend;
1646  } else {
1647  // If no end date, end date = date + 1 year - 1 day
1648  $datefin = dol_time_plus_duree($date, 1, 'y');
1649  $datefin = dol_time_plus_duree($datefin, -1, 'd');
1650  }
1651 
1652  // Create subscription
1653  $subscription = new Subscription($this->db);
1654  $subscription->fk_adherent = $this->id;
1655  $subscription->dateh = $date; // Date of new subscription
1656  $subscription->datef = $datefin; // End data of new subscription
1657  $subscription->amount = $amount;
1658  $subscription->note = $label; // deprecated
1659  $subscription->note_public = $label;
1660  $subscription->fk_type = $fk_type;
1661 
1662  $rowid = $subscription->create($user);
1663  if ($rowid > 0) {
1664  // Update denormalized subscription end date (read database subscription to find values)
1665  // This will also update this->datefin
1666  $result = $this->update_end_date($user);
1667  if ($result > 0) {
1668  // Change properties of object (used by triggers)
1669  $this->last_subscription_date = dol_now();
1670  $this->last_subscription_date_start = $date;
1671  $this->last_subscription_date_end = $datefin;
1672  $this->last_subscription_amount = $amount;
1673  }
1674 
1675  if (!$error) {
1676  $this->db->commit();
1677  return $rowid;
1678  } else {
1679  $this->db->rollback();
1680  return -2;
1681  }
1682  } else {
1683  $this->error = $subscription->error;
1684  $this->errors = $subscription->errors;
1685  $this->db->rollback();
1686  return -1;
1687  }
1688  }
1689 
1690 
1710  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 = '')
1711  {
1712  global $conf, $langs, $user, $mysoc;
1713 
1714  $error = 0;
1715 
1716  $this->invoice = null; // This will contains invoice if an invoice is created
1717 
1718  dol_syslog("subscriptionComplementaryActions subscriptionid=".$subscriptionid." option=".$option." accountid=".$accountid." datesubscription=".$datesubscription." paymentdate=".
1719  $paymentdate." label=".$label." amount=".$amount." num_chq=".$num_chq." autocreatethirdparty=".$autocreatethirdparty);
1720 
1721  // Insert into bank account directlty (if option choosed for) + link to llx_subscription if option is 'bankdirect'
1722  if ($option == 'bankdirect' && $accountid) {
1723  require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
1724 
1725  $acct = new Account($this->db);
1726  $result = $acct->fetch($accountid);
1727 
1728  $dateop = $paymentdate;
1729 
1730  $insertid = $acct->addline($dateop, $operation, $label, $amount, $num_chq, '', $user, $emetteur_nom, $emetteur_banque);
1731  if ($insertid > 0) {
1732  $inserturlid = $acct->add_url_line($insertid, $this->id, DOL_URL_ROOT.'/adherents/card.php?rowid=', $this->getFullname($langs), 'member');
1733  if ($inserturlid > 0) {
1734  // Update table subscription
1735  $sql = "UPDATE ".MAIN_DB_PREFIX."subscription SET fk_bank=".((int) $insertid);
1736  $sql .= " WHERE rowid=".((int) $subscriptionid);
1737 
1738  dol_syslog("subscription::subscription", LOG_DEBUG);
1739  $resql = $this->db->query($sql);
1740  if (!$resql) {
1741  $error++;
1742  $this->error = $this->db->lasterror();
1743  $this->errors[] = $this->error;
1744  }
1745  } else {
1746  $error++;
1747  $this->error = $acct->error;
1748  $this->errors = $acct->errors;
1749  }
1750  } else {
1751  $error++;
1752  $this->error = $acct->error;
1753  $this->errors = $acct->errors;
1754  }
1755  }
1756 
1757  // If option choosed, we create invoice
1758  if (($option == 'bankviainvoice' && $accountid) || $option == 'invoiceonly') {
1759  require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1760  require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/paymentterm.class.php';
1761 
1762  $invoice = new Facture($this->db);
1763  $customer = new Societe($this->db);
1764 
1765  if (!$error) {
1766  if (!($this->fk_soc > 0)) { // If not yet linked to a company
1767  if ($autocreatethirdparty) {
1768  // Create a linked thirdparty to member
1769  $companyalias = '';
1770  $fullname = $this->getFullName($langs);
1771 
1772  if ($this->morphy == 'mor') {
1773  $companyname = $this->company;
1774  if (!empty($fullname)) {
1775  $companyalias = $fullname;
1776  }
1777  } else {
1778  $companyname = $fullname;
1779  if (!empty($this->company)) {
1780  $companyalias = $this->company;
1781  }
1782  }
1783 
1784  $result = $customer->create_from_member($this, $companyname, $companyalias);
1785  if ($result < 0) {
1786  $this->error = $customer->error;
1787  $this->errors = $customer->errors;
1788  $error++;
1789  } else {
1790  $this->fk_soc = $result;
1791  }
1792  } else {
1793  $langs->load("errors");
1794  $this->error = $langs->trans("ErrorMemberNotLinkedToAThirpartyLinkOrCreateFirst");
1795  $this->errors[] = $this->error;
1796  $error++;
1797  }
1798  }
1799  }
1800  if (!$error) {
1801  $result = $customer->fetch($this->fk_soc);
1802  if ($result <= 0) {
1803  $this->error = $customer->error;
1804  $this->errors = $customer->errors;
1805  $error++;
1806  }
1807  }
1808 
1809  if (!$error) {
1810  // Create draft invoice
1811  $invoice->type = Facture::TYPE_STANDARD;
1812  $invoice->cond_reglement_id = $customer->cond_reglement_id;
1813  if (empty($invoice->cond_reglement_id)) {
1814  $paymenttermstatic = new PaymentTerm($this->db);
1815  $invoice->cond_reglement_id = $paymenttermstatic->getDefaultId();
1816  if (empty($invoice->cond_reglement_id)) {
1817  $error++;
1818  $this->error = 'ErrorNoPaymentTermRECEPFound';
1819  $this->errors[] = $this->error;
1820  }
1821  }
1822  $invoice->socid = $this->fk_soc;
1823  //$invoice->date = $datesubscription;
1824  $invoice->date = dol_now();
1825 
1826  // Possibility to add external linked objects with hooks
1827  $invoice->linked_objects['subscription'] = $subscriptionid;
1828  if (!empty($_POST['other_linked_objects']) && is_array($_POST['other_linked_objects'])) {
1829  $invoice->linked_objects = array_merge($invoice->linked_objects, $_POST['other_linked_objects']);
1830  }
1831 
1832  $result = $invoice->create($user);
1833  if ($result <= 0) {
1834  $this->error = $invoice->error;
1835  $this->errors = $invoice->errors;
1836  $error++;
1837  } else {
1838  $this->invoice = $invoice;
1839  }
1840  }
1841 
1842  if (!$error) {
1843  // Add line to draft invoice
1844  $idprodsubscription = 0;
1845  if (!empty($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS) && (isModEnabled("product") || isModEnabled("service"))) {
1846  $idprodsubscription = $conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS;
1847  }
1848 
1849  $vattouse = 0;
1850  if (isset($conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS) && $conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS == 'defaultforfoundationcountry') {
1851  $vattouse = get_default_tva($mysoc, $mysoc, $idprodsubscription);
1852  }
1853  //print xx".$vattouse." - ".$mysoc." - ".$customer;exit;
1854  $result = $invoice->addline($label, 0, 1, $vattouse, 0, 0, $idprodsubscription, 0, $datesubscription, '', 0, 0, '', 'TTC', $amount, 1);
1855  if ($result <= 0) {
1856  $this->error = $invoice->error;
1857  $this->errors = $invoice->errors;
1858  $error++;
1859  }
1860  }
1861 
1862  if (!$error) {
1863  // Validate invoice
1864  $result = $invoice->validate($user);
1865  if ($result <= 0) {
1866  $this->error = $invoice->error;
1867  $this->errors = $invoice->errors;
1868  $error++;
1869  }
1870  }
1871 
1872  if (!$error) {
1873  // TODO Link invoice with subscription ?
1874  }
1875 
1876  // Add payment onto invoice
1877  if (!$error && $option == 'bankviainvoice' && $accountid) {
1878  require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
1879  require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
1880  require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
1881 
1882  $amounts = array();
1883  $amounts[$invoice->id] = price2num($amount);
1884 
1885  $paiement = new Paiement($this->db);
1886  $paiement->datepaye = $paymentdate;
1887  $paiement->amounts = $amounts;
1888  $paiement->paiementcode = $operation;
1889  $paiement->paiementid = dol_getIdFromCode($this->db, $operation, 'c_paiement', 'code', 'id', 1);
1890  $paiement->num_payment = $num_chq;
1891  $paiement->note_public = $label;
1892  $paiement->ext_payment_id = $ext_payment_id;
1893  $paiement->ext_payment_site = $ext_payment_site;
1894 
1895  if (!$error) {
1896  // Create payment line for invoice
1897  $paiement_id = $paiement->create($user);
1898  if (!($paiement_id > 0)) {
1899  $this->error = $paiement->error;
1900  $this->errors = $paiement->errors;
1901  $error++;
1902  }
1903  }
1904 
1905  if (!$error) {
1906  // Add transaction into bank account
1907  $bank_line_id = $paiement->addPaymentToBank($user, 'payment', '(SubscriptionPayment)', $accountid, $emetteur_nom, $emetteur_banque);
1908  if (!($bank_line_id > 0)) {
1909  $this->error = $paiement->error;
1910  $this->errors = $paiement->errors;
1911  $error++;
1912  }
1913  }
1914 
1915  if (!$error && !empty($bank_line_id)) {
1916  // Update fk_bank into subscription table
1917  $sql = 'UPDATE '.MAIN_DB_PREFIX.'subscription SET fk_bank='.((int) $bank_line_id);
1918  $sql .= ' WHERE rowid='.((int) $subscriptionid);
1919 
1920  $result = $this->db->query($sql);
1921  if (!$result) {
1922  $error++;
1923  }
1924  }
1925 
1926  if (!$error) {
1927  // Set invoice as paid
1928  $invoice->setPaid($user);
1929  }
1930  }
1931 
1932  if (!$error) {
1933  // Define output language
1934  $outputlangs = $langs;
1935  $newlang = '';
1936  $lang_id = GETPOST('lang_id');
1937  if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && !empty($lang_id)) {
1938  $newlang = $lang_id;
1939  }
1940  if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
1941  $newlang = $customer->default_lang;
1942  }
1943  if (!empty($newlang)) {
1944  $outputlangs = new Translate("", $conf);
1945  $outputlangs->setDefaultLang($newlang);
1946  }
1947  // Generate PDF (whatever is option MAIN_DISABLE_PDF_AUTOUPDATE) so we can include it into email
1948  //if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
1949 
1950  $invoice->generateDocument($invoice->model_pdf, $outputlangs);
1951  }
1952  }
1953 
1954  if ($error) {
1955  return -1;
1956  } else {
1957  return 1;
1958  }
1959  }
1960 
1961 
1968  public function validate($user)
1969  {
1970  global $langs, $conf;
1971 
1972  $error = 0;
1973  $now = dol_now();
1974 
1975  // Check parameters
1976  if ($this->statut == self::STATUS_VALIDATED) {
1977  dol_syslog(get_class($this)."::validate statut of member does not allow this", LOG_WARNING);
1978  return 0;
1979  }
1980 
1981  $this->db->begin();
1982 
1983  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
1984  $sql .= " statut = ".self::STATUS_VALIDATED;
1985  $sql .= ", datevalid = '".$this->db->idate($now)."'";
1986  $sql .= ", fk_user_valid = ".((int) $user->id);
1987  $sql .= " WHERE rowid = ".((int) $this->id);
1988 
1989  dol_syslog(get_class($this)."::validate", LOG_DEBUG);
1990  $result = $this->db->query($sql);
1991  if ($result) {
1992  $this->statut = self::STATUS_VALIDATED;
1993 
1994  // Call trigger
1995  $result = $this->call_trigger('MEMBER_VALIDATE', $user);
1996  if ($result < 0) {
1997  $error++;
1998  $this->db->rollback();
1999  return -1;
2000  }
2001  // End call triggers
2002 
2003  $this->datevalid = $now;
2004 
2005  $this->db->commit();
2006  return 1;
2007  } else {
2008  $this->error = $this->db->error();
2009  $this->db->rollback();
2010  return -1;
2011  }
2012  }
2013 
2014 
2021  public function resiliate($user)
2022  {
2023  global $langs, $conf;
2024 
2025  $error = 0;
2026 
2027  // Check parameters
2028  if ($this->statut == self::STATUS_RESILIATED) {
2029  dol_syslog(get_class($this)."::resiliate statut of member does not allow this", LOG_WARNING);
2030  return 0;
2031  }
2032 
2033  $this->db->begin();
2034 
2035  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
2036  $sql .= " statut = ".self::STATUS_RESILIATED;
2037  $sql .= ", fk_user_valid=".$user->id;
2038  $sql .= " WHERE rowid = ".((int) $this->id);
2039 
2040  $result = $this->db->query($sql);
2041  if ($result) {
2042  $this->statut = self::STATUS_RESILIATED;
2043 
2044  // Call trigger
2045  $result = $this->call_trigger('MEMBER_RESILIATE', $user);
2046  if ($result < 0) {
2047  $error++;
2048  $this->db->rollback();
2049  return -1;
2050  }
2051  // End call triggers
2052 
2053  $this->db->commit();
2054  return 1;
2055  } else {
2056  $this->error = $this->db->error();
2057  $this->db->rollback();
2058  return -1;
2059  }
2060  }
2061 
2071  public function exclude($user)
2072  {
2073  global $langs, $conf;
2074 
2075  $error = 0;
2076 
2077  // Check parameters
2078  if ($this->statut == self::STATUS_EXCLUDED) {
2079  dol_syslog(get_class($this)."::resiliate statut of member does not allow this", LOG_WARNING);
2080  return 0;
2081  }
2082 
2083  $this->db->begin();
2084 
2085  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
2086  $sql .= " statut = ".self::STATUS_EXCLUDED;
2087  $sql .= ", fk_user_valid=".$user->id;
2088  $sql .= " WHERE rowid = ".((int) $this->id);
2089 
2090  $result = $this->db->query($sql);
2091  if ($result) {
2092  $this->statut = self::STATUS_EXCLUDED;
2093 
2094  // Call trigger
2095  $result = $this->call_trigger('MEMBER_EXCLUDE', $user);
2096  if ($result < 0) {
2097  $error++;
2098  $this->db->rollback();
2099  return -1;
2100  }
2101  // End call triggers
2102 
2103  $this->db->commit();
2104  return 1;
2105  } else {
2106  $this->error = $this->db->error();
2107  $this->db->rollback();
2108  return -1;
2109  }
2110  }
2111 
2112  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2118  public function add_to_abo()
2119  {
2120  // phpcs:enable
2121  global $conf, $langs;
2122 
2123  include_once DOL_DOCUMENT_ROOT.'/mailmanspip/class/mailmanspip.class.php';
2124  $mailmanspip = new MailmanSpip($this->db);
2125 
2126  $err = 0;
2127 
2128  // mailman
2129  if (!empty($conf->global->ADHERENT_USE_MAILMAN) && isModEnabled('mailmanspip')) {
2130  $result = $mailmanspip->add_to_mailman($this);
2131 
2132  if ($result < 0) {
2133  if (!empty($mailmanspip->error)) {
2134  $this->errors[] = $mailmanspip->error;
2135  }
2136  $err += 1;
2137  }
2138  foreach ($mailmanspip->mladded_ko as $tmplist => $tmpemail) {
2139  $langs->load("errors");
2140  $this->errors[] = $langs->trans("ErrorFailedToAddToMailmanList", $tmpemail, $tmplist);
2141  }
2142  foreach ($mailmanspip->mladded_ok as $tmplist => $tmpemail) {
2143  $langs->load("mailmanspip");
2144  $this->mesgs[] = $langs->trans("SuccessToAddToMailmanList", $tmpemail, $tmplist);
2145  }
2146  }
2147 
2148  // spip
2149  if (!empty($conf->global->ADHERENT_USE_SPIP) && isModEnabled('mailmanspip')) {
2150  $result = $mailmanspip->add_to_spip($this);
2151  if ($result < 0) {
2152  $this->errors[] = $mailmanspip->error;
2153  $err += 1;
2154  }
2155  }
2156  if ($err) {
2157  return -$err;
2158  } else {
2159  return 1;
2160  }
2161  }
2162 
2163 
2164  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2170  public function del_to_abo()
2171  {
2172  // phpcs:enable
2173  global $conf, $langs;
2174 
2175  include_once DOL_DOCUMENT_ROOT.'/mailmanspip/class/mailmanspip.class.php';
2176  $mailmanspip = new MailmanSpip($this->db);
2177 
2178  $err = 0;
2179 
2180  // mailman
2181  if (!empty($conf->global->ADHERENT_USE_MAILMAN)) {
2182  $result = $mailmanspip->del_to_mailman($this);
2183  if ($result < 0) {
2184  if (!empty($mailmanspip->error)) {
2185  $this->errors[] = $mailmanspip->error;
2186  }
2187  $err += 1;
2188  }
2189 
2190  foreach ($mailmanspip->mlremoved_ko as $tmplist => $tmpemail) {
2191  $langs->load("errors");
2192  $this->errors[] = $langs->trans("ErrorFailedToRemoveToMailmanList", $tmpemail, $tmplist);
2193  }
2194  foreach ($mailmanspip->mlremoved_ok as $tmplist => $tmpemail) {
2195  $langs->load("mailmanspip");
2196  $this->mesgs[] = $langs->trans("SuccessToRemoveToMailmanList", $tmpemail, $tmplist);
2197  }
2198  }
2199 
2200  if ($conf->global->ADHERENT_USE_SPIP && isModEnabled('mailmanspip')) {
2201  $result = $mailmanspip->del_to_spip($this);
2202  if ($result < 0) {
2203  $this->errors[] = $mailmanspip->error;
2204  $err += 1;
2205  }
2206  }
2207  if ($err) {
2208  // error
2209  return -$err;
2210  } else {
2211  return 1;
2212  }
2213  }
2214 
2215 
2221  public function getCivilityLabel()
2222  {
2223  global $langs;
2224  $langs->load("dict");
2225 
2226  $code = (empty($this->civility_id) ? '' : $this->civility_id);
2227  if (empty($code)) {
2228  return '';
2229  }
2230  return $langs->getLabelFromKey($this->db, "Civility".$code, "c_civility", "code", "label", $code);
2231  }
2232 
2246  public function getNomUrl($withpictoimg = 0, $maxlen = 0, $option = 'card', $mode = '', $morecss = '', $save_lastsearch_value = -1, $notooltip = 0, $addlinktonotes = 0)
2247  {
2248  global $conf, $langs, $hookmanager;
2249 
2250  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpictoimg) {
2251  $withpictoimg = 0;
2252  }
2253 
2254  $result = '';
2255  $label = '';
2256  $linkstart = '';
2257  $linkend = '';
2258 
2259  if (!empty($this->photo)) {
2260  $label .= '<div class="photointooltip floatright">';
2261  $label .= Form::showphoto('memberphoto', $this, 80, 0, 0, 'photoref photowithmargin photologintooltip', 'small', 0, 1);
2262  $label .= '</div>';
2263  //$label .= '<div style="clear: both;"></div>';
2264  }
2265 
2266  $label .= '<div class="centpercent">';
2267  $label .= img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Member").'</u>';
2268  $label .= ' '.$this->getLibStatut(4);
2269  if (!empty($this->ref)) {
2270  $label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
2271  }
2272  if (!empty($this->login)) {
2273  $label .= '<br><b>'.$langs->trans('Login').':</b> '.$this->login;
2274  }
2275  if (!empty($this->firstname) || !empty($this->lastname)) {
2276  $label .= '<br><b>'.$langs->trans('Name').':</b> '.$this->getFullName($langs);
2277  }
2278  if (!empty($this->company)) {
2279  $label .= '<br><b>'.$langs->trans('Company').':</b> '.$this->company;
2280  }
2281  $label .= '</div>';
2282 
2283  $url = DOL_URL_ROOT.'/adherents/card.php?rowid='.((int) $this->id);
2284  if ($option == 'subscription') {
2285  $url = DOL_URL_ROOT.'/adherents/subscription.php?rowid='.((int) $this->id);
2286  }
2287 
2288  if ($option != 'nolink') {
2289  // Add param to save lastsearch_values or not
2290  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2291  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
2292  $add_save_lastsearch_values = 1;
2293  }
2294  if ($add_save_lastsearch_values) {
2295  $url .= '&save_lastsearch_values=1';
2296  }
2297  }
2298 
2299  $linkstart .= '<a href="'.$url.'"';
2300  $linkclose = "";
2301  if (empty($notooltip)) {
2302  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2303  $langs->load("users");
2304  $label = $langs->trans("ShowUser");
2305  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
2306  }
2307  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
2308  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
2309  }
2310 
2311  $linkstart .= $linkclose.'>';
2312  $linkend = '</a>';
2313 
2314  $result .= $linkstart;
2315  if ($withpictoimg) {
2316  $result .= '<div class="inline-block nopadding valignmiddle">';
2317  }
2318  if ($withpictoimg) {
2319  $paddafterimage = '';
2320  if (abs($withpictoimg) == 1) {
2321  $paddafterimage = 'style="margin-right: 3px;"';
2322  }
2323  // Only picto
2324  if ($withpictoimg > 0) {
2325  $picto = '<span class="nopadding'.($morecss ? ' userimg'.$morecss : '').'">'.
2326  img_object('', 'user', $paddafterimage.' '.($notooltip ? '' : 'class="classfortooltip"'), 0, 0, $notooltip ? 0 : 1).'</span>';
2327  } else {
2328  // Picto must be a photo
2329  $picto = '<span class="nopadding'.($morecss ? ' userimg'.$morecss : '').'"'.($paddafterimage ? ' '.$paddafterimage : '').'>';
2330  $picto .= Form::showphoto('memberphoto', $this, 0, 0, 0, 'userphoto'.($withpictoimg == -3 ? 'small' : ''), 'mini', 0, 1);
2331  $picto .= '</span>';
2332  }
2333  $result .= $picto;
2334  }
2335  if ($withpictoimg > -2 && $withpictoimg != 2) {
2336  if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2337  $result .= '<span class="nopadding valignmiddle'.((!isset($this->statut) || $this->statut) ? '' : ' strikefordisabled').
2338  ($morecss ? ' usertext'.$morecss : '').'">';
2339  }
2340  if ($mode == 'login') {
2341  $result .= dol_trunc($this->login, $maxlen);
2342  } elseif ($mode == 'ref') {
2343  $result .= $this->ref;
2344  } else {
2345  $result .= $this->getFullName($langs, '', ($mode == 'firstname' ? 2 : ($mode == 'lastname' ? 4 : -1)), $maxlen);
2346  }
2347  if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2348  $result .= '</span>';
2349  }
2350  }
2351  if ($withpictoimg) {
2352  $result .= '</div>';
2353  }
2354  $result .= $linkend;
2355 
2356  if ($addlinktonotes) {
2357  if ($this->note_private) {
2358  $notetoshow = $langs->trans("ViewPrivateNote").':<br>'.dol_string_nohtmltag($this->note_private, 1);
2359  $result .= ' <span class="note inline-block">';
2360  $result .= '<a href="'.DOL_URL_ROOT.'/adherents/note.php?id='.$this->id.'" class="classfortooltip" title="'.dol_escape_htmltag($notetoshow).'">';
2361  $result .= img_picto('', 'note');
2362  $result .= '</a>';
2363  $result .= '</span>';
2364  }
2365  }
2366  global $action;
2367  $hookmanager->initHooks(array($this->element . 'dao'));
2368  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
2369  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
2370  if ($reshook > 0) {
2371  $result = $hookmanager->resPrint;
2372  } else {
2373  $result .= $hookmanager->resPrint;
2374  }
2375  return $result;
2376  }
2377 
2384  public function getLibStatut($mode = 0)
2385  {
2386  return $this->LibStatut($this->statut, $this->need_subscription, $this->datefin, $mode);
2387  }
2388 
2389  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2399  public function LibStatut($status, $need_subscription, $date_end_subscription, $mode = 0)
2400  {
2401  // phpcs:enable
2402  global $langs;
2403  $langs->load("members");
2404 
2405  $statusType = '';
2406  $labelStatus = '';
2407  $labelStatusShort = '';
2408 
2409  if ($status == self::STATUS_DRAFT) {
2410  $statusType = 'status0';
2411  $labelStatus = $langs->trans("MemberStatusDraft");
2412  $labelStatusShort = $langs->trans("MemberStatusDraftShort");
2413  } elseif ($status >= self::STATUS_VALIDATED) {
2414  if ($need_subscription === 0) {
2415  $statusType = 'status4';
2416  $labelStatus = $langs->trans("MemberStatusNoSubscription");
2417  $labelStatusShort = $langs->trans("MemberStatusNoSubscriptionShort");
2418  } elseif (!$date_end_subscription) {
2419  $statusType = 'status1';
2420  $labelStatus = $langs->trans("MemberStatusActive");
2421  $labelStatusShort = $langs->trans("MemberStatusActiveShort");
2422  } elseif ($date_end_subscription < dol_now()) { // expired
2423  $statusType = 'status8';
2424  $labelStatus = $langs->trans("MemberStatusActiveLate");
2425  $labelStatusShort = $langs->trans("MemberStatusActiveLateShort");
2426  } else {
2427  $statusType = 'status4';
2428  $labelStatus = $langs->trans("MemberStatusPaid");
2429  $labelStatusShort = $langs->trans("MemberStatusPaidShort");
2430  }
2431  } elseif ($status == self::STATUS_RESILIATED) {
2432  $statusType = 'status6';
2433  $labelStatus = $langs->transnoentitiesnoconv("MemberStatusResiliated");
2434  $labelStatusShort = $langs->transnoentitiesnoconv("MemberStatusResiliatedShort");
2435  } elseif ($status == self::STATUS_EXCLUDED) {
2436  $statusType = 'status10';
2437  $labelStatus = $langs->transnoentitiesnoconv("MemberStatusExcluded");
2438  $labelStatusShort = $langs->transnoentitiesnoconv("MemberStatusExcludedShort");
2439  }
2440 
2441  return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode);
2442  }
2443 
2444 
2445  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2451  public function load_state_board()
2452  {
2453  // phpcs:enable
2454  global $conf;
2455 
2456  $this->nb = array();
2457 
2458  $sql = "SELECT count(a.rowid) as nb";
2459  $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a";
2460  $sql .= " WHERE a.statut > 0";
2461  $sql .= " AND a.entity IN (".getEntity('adherent').")";
2462 
2463  $resql = $this->db->query($sql);
2464  if ($resql) {
2465  while ($obj = $this->db->fetch_object($resql)) {
2466  $this->nb["members"] = $obj->nb;
2467  }
2468  $this->db->free($resql);
2469  return 1;
2470  } else {
2471  dol_print_error($this->db);
2472  $this->error = $this->db->error();
2473  return -1;
2474  }
2475  }
2476 
2477  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2485  public function load_board($user, $mode)
2486  {
2487  // phpcs:enable
2488  global $conf, $langs;
2489 
2490  if ($user->socid) {
2491  return -1; // protection pour eviter appel par utilisateur externe
2492  }
2493 
2494  $now = dol_now();
2495 
2496  $sql = "SELECT a.rowid, a.datefin, a.statut";
2497  $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a";
2498  $sql .= ", ".MAIN_DB_PREFIX."adherent_type as t";
2499  $sql .= " WHERE a.fk_adherent_type = t.rowid";
2500  if ($mode == 'expired') {
2501  $sql .= " AND a.statut = ".self::STATUS_VALIDATED;
2502  $sql .= " AND a.entity IN (".getEntity('adherent').")";
2503  $sql .= " AND ((a.datefin IS NULL or a.datefin < '".$this->db->idate($now)."') AND t.subscription = '1')";
2504  } elseif ($mode == 'shift') {
2505  $sql .= " AND a.statut = ".self::STATUS_DRAFT;
2506  $sql .= " AND a.entity IN (".getEntity('adherent').")";
2507  }
2508 
2509  $resql = $this->db->query($sql);
2510  if ($resql) {
2511  $langs->load("members");
2512 
2513  $warning_delay = 0;
2514  $url = '';
2515  $label = '';
2516  $labelShort = '';
2517 
2518  if ($mode == 'expired') {
2519  $warning_delay = $conf->adherent->subscription->warning_delay / 60 / 60 / 24;
2520  $label = $langs->trans("MembersWithSubscriptionToReceive");
2521  $labelShort = $langs->trans("MembersWithSubscriptionToReceiveShort");
2522  $url = DOL_URL_ROOT.'/adherents/list.php?mainmenu=members&amp;statut='.self::STATUS_VALIDATED.'&amp;filter=outofdate';
2523  } elseif ($mode == 'shift') {
2524  $warning_delay = $conf->adherent->subscription->warning_delay / 60 / 60 / 24;
2525  $url = DOL_URL_ROOT.'/adherents/list.php?mainmenu=members&amp;statut='.self::STATUS_DRAFT;
2526  $label = $langs->trans("MembersListToValid");
2527  $labelShort = $langs->trans("ToValidate");
2528  }
2529 
2530  $response = new WorkboardResponse();
2531  $response->warning_delay = $warning_delay;
2532  $response->label = $label;
2533  $response->labelShort = $labelShort;
2534  $response->url = $url;
2535  $response->img = img_object('', "user");
2536 
2537  $adherentstatic = new Adherent($this->db);
2538 
2539  while ($obj = $this->db->fetch_object($resql)) {
2540  $response->nbtodo++;
2541 
2542  $adherentstatic->datefin = $this->db->jdate($obj->datefin);
2543  $adherentstatic->statut = $obj->statut;
2544 
2545  if ($adherentstatic->hasDelay()) {
2546  $response->nbtodolate++;
2547  }
2548  }
2549 
2550  return $response;
2551  } else {
2552  dol_print_error($this->db);
2553  $this->error = $this->db->error();
2554  return -1;
2555  }
2556  }
2557 
2558 
2570  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
2571  {
2572  global $conf, $langs;
2573 
2574  $langs->load("orders");
2575 
2576  if (!dol_strlen($modele)) {
2577  $modele = 'standard';
2578 
2579  if ($this->model_pdf) {
2580  $modele = $this->model_pdf;
2581  } elseif (!empty($conf->global->ADHERENT_ADDON_PDF)) {
2582  $modele = $conf->global->ADHERENT_ADDON_PDF;
2583  }
2584  }
2585 
2586  $modelpath = "core/modules/member/doc/";
2587 
2588  return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
2589  }
2590 
2591 
2599  public function initAsSpecimen()
2600  {
2601  global $user, $langs;
2602  $now = dol_now();
2603 
2604  // Initialise parametres
2605  $this->id = 0;
2606  $this->ref = 'ABC001';
2607  $this->entity = 1;
2608  $this->specimen = 1;
2609  $this->civility_id = 0;
2610  $this->lastname = 'DOLIBARR';
2611  $this->firstname = 'SPECIMEN';
2612  $this->gender = 'man';
2613  $this->login = 'dolibspec';
2614  $this->pass = 'dolibspec';
2615  $this->company = 'Societe ABC';
2616  $this->address = '61 jump street';
2617  $this->zip = '75000';
2618  $this->town = 'Paris';
2619  $this->country_id = 1;
2620  $this->country_code = 'FR';
2621  $this->country = 'France';
2622  $this->morphy = 'mor';
2623  $this->email = 'specimen@specimen.com';
2624  $this->socialnetworks = array(
2625  'skype' => 'skypepseudo',
2626  'twitter' => 'twitterpseudo',
2627  'facebook' => 'facebookpseudo',
2628  'linkedin' => 'linkedinpseudo',
2629  );
2630  $this->phone = '0999999999';
2631  $this->phone_perso = '0999999998';
2632  $this->phone_mobile = '0999999997';
2633  $this->note_public = 'This is a public note';
2634  $this->note_private = 'This is a private note';
2635  $this->birth = $now;
2636  $this->photo = '';
2637  $this->public = 1;
2638  $this->statut = self::STATUS_DRAFT;
2639 
2640  $this->datefin = $now;
2641  $this->datevalid = $now;
2642  $this->default_lang = '';
2643 
2644  $this->typeid = 1; // Id type adherent
2645  $this->type = 'Type adherent'; // Libelle type adherent
2646  $this->need_subscription = 0;
2647 
2648  $this->first_subscription_date = $now;
2649  $this->first_subscription_date_start = $this->first_subscription_date;
2650  $this->first_subscription_date_end = dol_time_plus_duree($this->first_subscription_date_start, 1, 'y');
2651  $this->first_subscription_amount = 10;
2652 
2653  $this->last_subscription_date = $this->first_subscription_date;
2654  $this->last_subscription_date_start = $this->first_subscription_date;
2655  $this->last_subscription_date_end = dol_time_plus_duree($this->last_subscription_date_start, 1, 'y');
2656  $this->last_subscription_amount = 10;
2657  return 1;
2658  }
2659 
2660 
2661  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2662  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2672  public function _load_ldap_dn($info, $mode = 0)
2673  {
2674  // phpcs:enable
2675  global $conf;
2676  $dn = '';
2677  if ($mode == 0) {
2678  $dn = $conf->global->LDAP_KEY_MEMBERS."=".$info[$conf->global->LDAP_KEY_MEMBERS].",".$conf->global->LDAP_MEMBER_DN;
2679  }
2680  if ($mode == 1) {
2681  $dn = $conf->global->LDAP_MEMBER_DN;
2682  }
2683  if ($mode == 2) {
2684  $dn = $conf->global->LDAP_KEY_MEMBERS."=".$info[$conf->global->LDAP_KEY_MEMBERS];
2685  }
2686  return $dn;
2687  }
2688 
2689 
2690  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2691  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2697  public function _load_ldap_info()
2698  {
2699  // phpcs:enable
2700  global $conf, $langs;
2701 
2702  $info = array();
2703  $socialnetworks = getArrayOfSocialNetworks();
2704  $keymodified = false;
2705 
2706  // Object classes
2707  $info["objectclass"] = explode(',', $conf->global->LDAP_MEMBER_OBJECT_CLASS);
2708 
2709  $this->fullname = $this->getFullName($langs);
2710 
2711  // For avoid ldap error when firstname and lastname are empty
2712  if ($this->morphy == 'mor' && (empty($this->fullname) || $this->fullname == $this->company)) {
2713  $this->fullname = $this->company;
2714  $this->lastname = $this->company;
2715  }
2716 
2717  // Possible LDAP KEY (constname => varname)
2718  $ldapkey = array(
2719  'LDAP_MEMBER_FIELD_FULLNAME' => 'fullname',
2720  'LDAP_MEMBER_FIELD_NAME' => 'lastname',
2721  'LDAP_MEMBER_FIELD_LOGIN' => 'login',
2722  'LDAP_MEMBER_FIELD_LOGIN_SAMBA' => 'login',
2723  'LDAP_MEMBER_FIELD_MAIL' => 'email'
2724  );
2725 
2726  // Member
2727  foreach ($ldapkey as $constname => $varname) {
2728  if (!empty($this->$varname) && !empty($conf->global->$constname)) {
2729  $info[$conf->global->$constname] = $this->$varname;
2730 
2731  // Check if it is the LDAP key and if its value has been changed
2732  if (!empty($conf->global->LDAP_KEY_MEMBERS) && $conf->global->LDAP_KEY_MEMBERS == $conf->global->$constname) {
2733  if (!empty($this->oldcopy) && $this->$varname != $this->oldcopy->$varname) {
2734  $keymodified = true; // For check if LDAP key has been modified
2735  }
2736  }
2737  }
2738  }
2739  if ($this->firstname && !empty($conf->global->LDAP_MEMBER_FIELD_FIRSTNAME)) {
2740  $info[$conf->global->LDAP_MEMBER_FIELD_FIRSTNAME] = $this->firstname;
2741  }
2742  if ($this->poste && !empty($conf->global->LDAP_MEMBER_FIELD_TITLE)) {
2743  $info[$conf->global->LDAP_MEMBER_FIELD_TITLE] = $this->poste;
2744  }
2745  if ($this->company && !empty($conf->global->LDAP_MEMBER_FIELD_COMPANY)) {
2746  $info[$conf->global->LDAP_MEMBER_FIELD_COMPANY] = $this->company;
2747  }
2748  if ($this->address && !empty($conf->global->LDAP_MEMBER_FIELD_ADDRESS)) {
2749  $info[$conf->global->LDAP_MEMBER_FIELD_ADDRESS] = $this->address;
2750  }
2751  if ($this->zip && !empty($conf->global->LDAP_MEMBER_FIELD_ZIP)) {
2752  $info[$conf->global->LDAP_MEMBER_FIELD_ZIP] = $this->zip;
2753  }
2754  if ($this->town && !empty($conf->global->LDAP_MEMBER_FIELD_TOWN)) {
2755  $info[$conf->global->LDAP_MEMBER_FIELD_TOWN] = $this->town;
2756  }
2757  if ($this->country_code && !empty($conf->global->LDAP_MEMBER_FIELD_COUNTRY)) {
2758  $info[$conf->global->LDAP_MEMBER_FIELD_COUNTRY] = $this->country_code;
2759  }
2760  foreach ($socialnetworks as $key => $value) {
2761  if ($this->socialnetworks[$value['label']] && !empty($conf->global->{'LDAP_MEMBER_FIELD_'.strtoupper($value['label'])})) {
2762  $info[$conf->global->{'LDAP_MEMBER_FIELD_'.strtoupper($value['label'])}] = $this->socialnetworks[$value['label']];
2763  }
2764  }
2765  if ($this->phone && !empty($conf->global->LDAP_MEMBER_FIELD_PHONE)) {
2766  $info[$conf->global->LDAP_MEMBER_FIELD_PHONE] = $this->phone;
2767  }
2768  if ($this->phone_perso && !empty($conf->global->LDAP_MEMBER_FIELD_PHONE_PERSO)) {
2769  $info[$conf->global->LDAP_MEMBER_FIELD_PHONE_PERSO] = $this->phone_perso;
2770  }
2771  if ($this->phone_mobile && !empty($conf->global->LDAP_MEMBER_FIELD_MOBILE)) {
2772  $info[$conf->global->LDAP_MEMBER_FIELD_MOBILE] = $this->phone_mobile;
2773  }
2774  if ($this->fax && !empty($conf->global->LDAP_MEMBER_FIELD_FAX)) {
2775  $info[$conf->global->LDAP_MEMBER_FIELD_FAX] = $this->fax;
2776  }
2777  if ($this->note_private && !empty($conf->global->LDAP_MEMBER_FIELD_DESCRIPTION)) {
2778  $info[$conf->global->LDAP_MEMBER_FIELD_DESCRIPTION] = dol_string_nohtmltag($this->note_private, 2);
2779  }
2780  if ($this->note_public && !empty($conf->global->LDAP_MEMBER_FIELD_NOTE_PUBLIC)) {
2781  $info[$conf->global->LDAP_MEMBER_FIELD_NOTE_PUBLIC] = dol_string_nohtmltag($this->note_public, 2);
2782  }
2783  if ($this->birth && !empty($conf->global->LDAP_MEMBER_FIELD_BIRTHDATE)) {
2784  $info[$conf->global->LDAP_MEMBER_FIELD_BIRTHDATE] = dol_print_date($this->birth, 'dayhourldap');
2785  }
2786  if (isset($this->statut) && !empty($conf->global->LDAP_FIELD_MEMBER_STATUS)) {
2787  $info[$conf->global->LDAP_FIELD_MEMBER_STATUS] = $this->statut;
2788  }
2789  if ($this->datefin && !empty($conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION)) {
2790  $info[$conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION] = dol_print_date($this->datefin, 'dayhourldap');
2791  }
2792 
2793  // When password is modified
2794  if (!empty($this->pass)) {
2795  if (!empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD)) {
2796  $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD] = $this->pass; // this->pass = mot de passe non crypte
2797  }
2798  if (!empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED)) {
2799  $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED] = dol_hash($this->pass, 'openldap'); // Create OpenLDAP password (see LDAP_PASSWORD_HASH_TYPE)
2800  }
2801  } elseif ($conf->global->LDAP_SERVER_PROTOCOLVERSION !== '3') {
2802  // Set LDAP password if possible
2803  // If ldap key is modified and LDAPv3 we use ldap_rename function for avoid lose encrypt password
2804  if (!empty($conf->global->DATABASE_PWD_ENCRYPTED)) {
2805  // Just for the default MD5 !
2806  if (empty($conf->global->MAIN_SECURITY_HASH_ALGO)) {
2807  if ($this->pass_indatabase_crypted && !empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED)) {
2808  // Create OpenLDAP MD5 password from Dolibarr MD5 password
2809  // Note: This suppose that "pass_indatabase_crypted" is a md5 (guaranted by the previous test if "(empty($conf->global->MAIN_SECURITY_HASH_ALGO))"
2810  $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED] = dolGetLdapPasswordHash($this->pass_indatabase_crypted, 'md5frommd5');
2811  }
2812  }
2813  } elseif (!empty($this->pass_indatabase)) {
2814  // Use $this->pass_indatabase value if exists
2815  if (!empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD)) {
2816  $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD] = $this->pass_indatabase; // $this->pass_indatabase = mot de passe non crypte
2817  }
2818  if (!empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED)) {
2819  $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED] = dol_hash($this->pass_indatabase, 'openldap'); // Create OpenLDAP password (see LDAP_PASSWORD_HASH_TYPE)
2820  }
2821  }
2822  }
2823 
2824  // Subscriptions
2825  if ($this->first_subscription_date && !empty($conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE)) {
2826  $info[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE] = dol_print_date($this->first_subscription_date, 'dayhourldap');
2827  }
2828  if (isset($this->first_subscription_amount) && !empty($conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT)) {
2829  $info[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT] = $this->first_subscription_amount;
2830  }
2831  if ($this->last_subscription_date && !empty($conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE)) {
2832  $info[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE] = dol_print_date($this->last_subscription_date, 'dayhourldap');
2833  }
2834  if (isset($this->last_subscription_amount) && !empty($conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT)) {
2835  $info[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT] = $this->last_subscription_amount;
2836  }
2837 
2838  return $info;
2839  }
2840 
2841 
2848  public function info($id)
2849  {
2850  $sql = 'SELECT a.rowid, a.datec as datec,';
2851  $sql .= ' a.datevalid as datev,';
2852  $sql .= ' a.tms as datem,';
2853  $sql .= ' a.fk_user_author, a.fk_user_valid, a.fk_user_mod';
2854  $sql .= ' FROM '.MAIN_DB_PREFIX.'adherent as a';
2855  $sql .= ' WHERE a.rowid = '.((int) $id);
2856 
2857  dol_syslog(get_class($this)."::info", LOG_DEBUG);
2858  $result = $this->db->query($sql);
2859  if ($result) {
2860  if ($this->db->num_rows($result)) {
2861  $obj = $this->db->fetch_object($result);
2862  $this->id = $obj->rowid;
2863 
2864  $this->user_creation_id = $obj->fk_user_author;
2865  $this->user_validation_id = $obj->fk_user_valid;
2866  $this->user_modification_id = $obj->fk_user_mod;
2867  $this->date_creation = $this->db->jdate($obj->datec);
2868  $this->date_validation = $this->db->jdate($obj->datev);
2869  $this->date_modification = $this->db->jdate($obj->datem);
2870  }
2871 
2872  $this->db->free($result);
2873  } else {
2874  dol_print_error($this->db);
2875  }
2876  }
2877 
2883  public function getNbOfEMailings()
2884  {
2885  $sql = "SELECT count(mc.email) as nb";
2886  $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
2887  $sql .= " WHERE mc.email = '".$this->db->escape($this->email)."'";
2888  $sql .= " AND mc.statut NOT IN (-1,0)"; // -1 erreur, 0 non envoye, 1 envoye avec succes
2889 
2890  $resql = $this->db->query($sql);
2891  if ($resql) {
2892  $obj = $this->db->fetch_object($resql);
2893  $nb = $obj->nb;
2894 
2895  $this->db->free($resql);
2896  return $nb;
2897  } else {
2898  $this->error = $this->db->error();
2899  return -1;
2900  }
2901  }
2902 
2913  public function setCategories($categories)
2914  {
2915  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
2916  return parent::setCategoriesCommon($categories, Categorie::TYPE_MEMBER);
2917  }
2918 
2927  public static function replaceThirdparty($db, $origin_id, $dest_id)
2928  {
2929  $tables = array('adherent');
2930 
2931  return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
2932  }
2933 
2939  public function hasDelay()
2940  {
2941  global $conf;
2942 
2943  //Only valid members
2944  if ($this->statut != self::STATUS_VALIDATED) {
2945  return false;
2946  }
2947  if (!$this->datefin) {
2948  return false;
2949  }
2950 
2951  $now = dol_now();
2952 
2953  return $this->datefin < ($now - $conf->adherent->subscription->warning_delay);
2954  }
2955 
2956 
2964  public function sendReminderForExpiredSubscription($daysbeforeendlist = '10')
2965  {
2966  global $conf, $langs, $mysoc, $user;
2967 
2968  $error = 0;
2969  $this->output = '';
2970  $this->error = '';
2971 
2972  $blockingerrormsg = '';
2973 
2974  if (empty($conf->adherent->enabled)) { // Should not happen. If module disabled, cron job should not be visible.
2975  $langs->load("agenda");
2976  $this->output = $langs->trans('ModuleNotEnabled', $langs->transnoentitiesnoconv("Adherent"));
2977  return 0;
2978  }
2979  if (empty($conf->global->MEMBER_REMINDER_EMAIL)) {
2980  $langs->load("agenda");
2981  $this->output = $langs->trans('EventRemindersByEmailNotEnabled', $langs->transnoentitiesnoconv("Adherent"));
2982  return 0;
2983  }
2984 
2985  $now = dol_now();
2986  $nbok = 0;
2987  $nbko = 0;
2988 
2989  $listofmembersok = array();
2990  $listofmembersko = array();
2991 
2992  $arraydaysbeforeend = explode(';', $daysbeforeendlist);
2993  foreach ($arraydaysbeforeend as $daysbeforeend) { // Loop on each delay
2994  dol_syslog(__METHOD__.' - Process delta = '.$daysbeforeend, LOG_DEBUG);
2995 
2996  if (!is_numeric($daysbeforeend)) {
2997  $blockingerrormsg = "Value for delta is not a numeric value";
2998  $nbko++;
2999  break;
3000  }
3001 
3002  $tmp = dol_getdate($now);
3003  $datetosearchfor = dol_time_plus_duree(dol_mktime(0, 0, 0, $tmp['mon'], $tmp['mday'], $tmp['year'], 'tzserver'), $daysbeforeend, 'd');
3004 
3005  $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'adherent';
3006  $sql .= " WHERE entity = ".((int) $conf->entity); // Do not use getEntity('adherent').")" here, we want the batch to be on its entity only;
3007  $sql .= " AND datefin = '".$this->db->idate($datetosearchfor)."'";
3008  //$sql .= " LIMIT 10000";
3009 
3010  $resql = $this->db->query($sql);
3011  if ($resql) {
3012  $num_rows = $this->db->num_rows($resql);
3013 
3014  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
3015  $adherent = new Adherent($this->db);
3016  $formmail = new FormMail($this->db);
3017 
3018  $i = 0;
3019  while ($i < $num_rows) {
3020  $obj = $this->db->fetch_object($resql);
3021 
3022  $adherent->fetch($obj->rowid, '', '', '', true, true);
3023 
3024  if (empty($adherent->email)) {
3025  $nbko++;
3026  $listofmembersko[$adherent->id] = $adherent->id;
3027  } else {
3028  $adherent->fetch_thirdparty();
3029 
3030  // 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.
3031  $languagefromcountrycode = getLanguageCodeFromCountryCode($adherent->country_code ? $adherent->country_code : $adherent->thirdparty->country_code);
3032  $languagecodeformember = (empty($adherent->thirdparty->default_lang) ? ($languagefromcountrycode ? $languagefromcountrycode : $mysoc->default_lang) : $adherent->thirdparty->default_lang);
3033 
3034  // Send reminder email
3035  $outputlangs = new Translate('', $conf);
3036  $outputlangs->setDefaultLang($languagecodeformember);
3037  $outputlangs->loadLangs(array("main", "members"));
3038  dol_syslog("sendReminderForExpiredSubscription Language for member id ".$adherent->id." set to ".$outputlangs->defaultlang." mysoc->default_lang=".$mysoc->default_lang);
3039 
3040  $arraydefaultmessage = null;
3041  $labeltouse = getDolGlobalString('ADHERENT_EMAIL_TEMPLATE_REMIND_EXPIRATION');
3042 
3043  if (!empty($labeltouse)) {
3044  $arraydefaultmessage = $formmail->getEMailTemplate($this->db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
3045  }
3046 
3047  if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
3048  $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $adherent);
3049  //if (is_array($adherent->thirdparty)) $substitutionarraycomp = ...
3050  complete_substitutions_array($substitutionarray, $outputlangs, $adherent);
3051 
3052  $subject = make_substitutions($arraydefaultmessage->topic, $substitutionarray, $outputlangs);
3053  $msg = make_substitutions($arraydefaultmessage->content, $substitutionarray, $outputlangs);
3054  $from = getDolGlobalString('ADHERENT_MAIL_FROM');
3055  $to = $adherent->email;
3056 
3057  $trackid = 'mem'.$adherent->id;
3058  $moreinheader = 'X-Dolibarr-Info: sendReminderForExpiredSubscription'."\r\n";
3059 
3060  include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
3061  $cmail = new CMailFile($subject, $to, $from, $msg, array(), array(), array(), '', '', 0, 1, '', '', $trackid, $moreinheader);
3062  $result = $cmail->sendfile();
3063  if (!$result) {
3064  $error++;
3065  $this->error .= $cmail->error.' ';
3066  if (!is_null($cmail->errors)) {
3067  $this->errors += $cmail->errors;
3068  }
3069  $nbko++;
3070  $listofmembersko[$adherent->id] = $adherent->id;
3071  } else {
3072  $nbok++;
3073  $listofmembersok[$adherent->id] = $adherent->id;
3074 
3075  $message = $msg;
3076  $sendto = $to;
3077  $sendtocc = '';
3078  $sendtobcc = '';
3079  $actioncode = 'EMAIL';
3080  $extraparams = '';
3081 
3082  $actionmsg = '';
3083  $actionmsg2 = $langs->transnoentities('MailSentBy').' '.CMailFile::getValidAddress($from, 4, 0, 1).' '.$langs->transnoentities('To').' '.CMailFile::getValidAddress($sendto, 4, 0, 1);
3084  if ($message) {
3085  $actionmsg = $langs->transnoentities('MailFrom').': '.dol_escape_htmltag($from);
3086  $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTo').': '.dol_escape_htmltag($sendto));
3087  if ($sendtocc) {
3088  $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc').": ".dol_escape_htmltag($sendtocc));
3089  }
3090  $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic').": ".$subject);
3091  $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody').":");
3092  $actionmsg = dol_concatdesc($actionmsg, $message);
3093  }
3094 
3095  require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
3096 
3097  // Insert record of emails sent
3098  $actioncomm = new ActionComm($this->db);
3099 
3100  $actioncomm->type_code = 'AC_OTH_AUTO'; // Type of event ('AC_OTH', 'AC_OTH_AUTO', 'AC_XXX'...)
3101  $actioncomm->code = 'AC_'.$actioncode;
3102  $actioncomm->label = $actionmsg2;
3103  $actioncomm->note_private = $actionmsg;
3104  $actioncomm->fk_project = 0;
3105  $actioncomm->datep = $now;
3106  $actioncomm->datef = $now;
3107  $actioncomm->percentage = -1; // Not applicable
3108  $actioncomm->socid = $adherent->thirdparty->id;
3109  $actioncomm->contact_id = 0;
3110  $actioncomm->authorid = $user->id; // User saving action
3111  $actioncomm->userownerid = $user->id; // Owner of action
3112  // Fields when action is en email (content should be added into note)
3113  $actioncomm->email_msgid = $cmail->msgid;
3114  $actioncomm->email_from = $from;
3115  $actioncomm->email_sender = '';
3116  $actioncomm->email_to = $to;
3117  $actioncomm->email_tocc = $sendtocc;
3118  $actioncomm->email_tobcc = $sendtobcc;
3119  $actioncomm->email_subject = $subject;
3120  $actioncomm->errors_to = '';
3121 
3122  $actioncomm->fk_element = $adherent->id;
3123  $actioncomm->elementtype = $adherent->element;
3124 
3125  $actioncomm->extraparams = $extraparams;
3126 
3127  $actioncomm->create($user);
3128  }
3129  } else {
3130  //$blockingerrormsg = "Can't find email template with label=".$labeltouse.", to use for the reminding email";
3131 
3132  $error++;
3133  $this->error .= "Can't find email template with label=".$labeltouse.", to use for the reminding email ";
3134 
3135  $nbko++;
3136  $listofmembersko[$adherent->id] = $adherent->id;
3137 
3138  break;
3139  }
3140  }
3141 
3142  $i++;
3143  }
3144  } else {
3145  $this->error = $this->db->lasterror();
3146  return 1;
3147  }
3148  }
3149 
3150  if ($blockingerrormsg) {
3151  $this->error = $blockingerrormsg;
3152  return 1;
3153  } else {
3154  $this->output = 'Found '.($nbok + $nbko).' members to send reminder to.';
3155  $this->output .= ' Send email successfuly to '.$nbok.' members';
3156  if (is_array($listofmembersok)) {
3157  $listofids = '';
3158  $i = 0;
3159  foreach ($listofmembersok as $idmember) {
3160  if ($i > 100) {
3161  $listofids .= ', ...';
3162  break;
3163  }
3164  if (empty($listofids)) {
3165  $listofids .= ' [';
3166  } else {
3167  $listofids .= ', ';
3168  }
3169  $listofids .= $idmember;
3170  $i++;
3171  }
3172  if ($listofids) {
3173  $listofids .= ']';
3174  }
3175 
3176  $this->output .= ($listofids ? ' ids='.$listofids : '');
3177  }
3178  if ($nbko) {
3179  $this->output .= ' - Canceled for '.$nbko.' member (no email or email sending error)';
3180  if (is_array($listofmembersko)) {
3181  $listofids = '';
3182  $i = 0;
3183  foreach ($listofmembersko as $idmember) {
3184  if ($i > 100) {
3185  $listofids .= ', ...';
3186  break;
3187  }
3188  if (empty($listofids)) {
3189  $listofids .= ' [';
3190  } else {
3191  $listofids .= ', ';
3192  }
3193  $listofids .= $idmember;
3194  $i++;
3195  }
3196  if ($listofids) {
3197  $listofids .= ']';
3198  }
3199  $this->output .= ($listofids ? ' ids='.$listofids : '');
3200  }
3201  }
3202  }
3203 
3204  return $nbko;
3205  }
3206 }
$object ref
Definition: info.php:78
Class to manage bank accounts.
Class to manage agenda events (actions)
Class to manage members of a foundation.
setThirdPartyId($thirdpartyid)
Set link to a third party.
hasDelay()
Return if a member is late (subscription late) or not.
exclude($user)
Functiun to exlude (set adherent.status to -2) a member TODO A private note should be added to know w...
add_to_abo()
Function to add member into external tools mailing-list, spip, etc.
sendReminderForExpiredSubscription($daysbeforeendlist='10')
Send reminders by emails before subscription end CAN BE A CRON TASK.
_load_ldap_dn($info, $mode=0)
Retourne chaine DN complete dans l'annuaire LDAP pour l'objet.
update($user, $notrigger=0, $nosyncuser=0, $nosyncuserpass=0, $nosyncthirdparty=0, $action='update')
Update a member in database (standard information and password)
setCategories($categories)
Sets object to supplied categories.
getNbOfEMailings()
Return number of mass Emailing received by this member with its email.
update_end_date($user)
Update denormalized last subscription date.
static replaceThirdparty($db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
makeSubstitution($text)
Make substitution of tags into text with value of current object.
const STATUS_EXCLUDED
Excluded.
LibStatut($status, $need_subscription, $date_end_subscription, $mode=0)
Renvoi le libelle d'un statut donne.
fetch_name($firstname, $lastname)
Method to load member from its name.
initAsSpecimen()
Initialise an instance with random values.
del_to_abo()
Function to delete a member from external tools like mailing-list, spip, etc.
resiliate($user)
Fonction qui resilie un adherent.
getCivilityLabel()
Return civility label of a member.
getmorphylib($morphy='', $addbadge=0)
Return translated label by the nature of a adherent (physical or moral)
fetchPartnerships($mode)
Function to get partnerships array.
load_board($user, $mode)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
setPassword($user, $password='', $isencrypted=0, $notrigger=0, $nosyncuser=0)
Change password of a user.
const STATUS_DRAFT
Draft status.
const STATUS_RESILIATED
Resiliated.
fetch_login($login)
Method to load member from its login.
create($user, $notrigger=0)
Create a member into database.
_load_ldap_info()
Initialise tableau info (tableau des attributs LDAP)
getLibStatut($mode=0)
Retourne le libelle du statut d'un adherent (brouillon, valide, resilie, exclu)
info($id)
Load type info information in the member object.
__construct($db)
Constructor.
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....
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.
getNomUrl($withpictoimg=0, $maxlen=0, $option='card', $mode='', $morecss='', $save_lastsearch_value=-1, $notooltip=0, $addlinktonotes=0)
Return clicable name (with picto eventually)
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
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.
setUserId($userid)
Set link to a user.
load_state_board()
Charge indicateurs this->nb de tableau de bord.
fetch($rowid, $ref='', $fk_soc='', $ref_ext='', $fetch_optionals=true, $fetch_subscriptions=true)
Load member from database.
const STATUS_VALIDATED
Validated status.
fetch_subscriptions()
Function to get member subscriptions data: subscriptions, first_subscription_date,...
validate($user)
Function that validate a member.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
static getValidAddress($address, $format, $encode=0, $maxnumberofemail=0)
Return a formatted address string for SMTP protocol.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
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...
setUpperOrLowerCase()
Set to upper or ucwords/lower if needed.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
getFullName($langs, $option=0, $nameorder=-1, $maxlen=0)
Return full name (civility+' '+name+' '+lastname)
deleteExtraFields()
Delete all extra fields values for the current object.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage invoices.
const TYPE_STANDARD
Standard invoice.
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.
Classe permettant la generation du formulaire html d'envoi de mail unitaire Usage: $formail = new For...
Class to manage mailman and spip.
Class to manage payments of customer invoices.
Class to manage payment terms records in dictionary.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage subscriptions of foundation members.
Class to manage translations.
Class to manage Dolibarr users.
Definition: user.class.php:45
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition: date.lib.php:121
clean_url($url, $http=1)
Clean an url string.
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...
getLanguageCodeFromCountryCode($countrycode)
Return default language from country code.
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.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
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...
dolGetFirstLetters($s, $nbofchar=1)
Return first letters of a strings.
dol_strtoupper($string, $encoding="UTF-8")
Convert a string to upper.
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...
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
getArrayOfSocialNetworks()
Get array of social network dictionary.
dol_textishtml($msg, $option=0)
Return if a text is a html content.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null)
Return array of possible common substitutions.
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.
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...
isModEnabled($module)
Is Dolibarr module enabled.
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...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.
dolGetLdapPasswordHash($password, $type='md5')
Returns a specific ldap hash of a password.
dol_hash($chain, $type='0')
Returns a hash (non reversible encryption) of a string.
$conf db
API class for accounts.
Definition: inc.php:41