dolibarr  18.0.0-alpha
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-2023 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 
95  public $fullname;
96 
100  public $civility_id;
101  public $civility_code;
102  public $civility;
103 
109  public $societe;
110 
114  public $company;
115 
121  public $fk_soc;
122 
126  public $socid;
127 
131  public $address;
132 
136  public $zip;
137 
141  public $town;
142 
146  public $state_id;
147 
151  public $state_code;
152 
156  public $state;
157 
161  public $email;
162 
166  public $url;
167 
171  public $socialnetworks;
172 
178  public $skype;
179 
185  public $twitter;
186 
192  public $facebook;
193 
199  public $linkedin;
200 
204  public $phone;
205 
209  public $phone_perso;
210 
214  public $phone_pro;
215 
219  public $phone_mobile;
220 
224  public $fax;
225 
229  public $poste;
230 
234  public $morphy;
235 
239  public $public;
240 
245  public $default_lang;
246 
250  public $photo;
251 
257  public $datec;
258 
264  public $datem;
265 
266  public $datevalid;
267 
271  public $gender;
272 
273  public $birth;
274 
278  public $typeid;
279 
283  public $type;
284 
288  public $need_subscription;
289 
293  public $user_id;
294 
298  public $user_login;
299 
300  public $datefin;
301 
302 
303  // Fields loaded by fetch_subscriptions() from member table
304 
305  public $first_subscription_date;
306 
307  public $first_subscription_date_start;
308 
309  public $first_subscription_date_end;
310 
311  public $first_subscription_amount;
312 
313  public $last_subscription_date;
314 
315  public $last_subscription_date_start;
316 
317  public $last_subscription_date_end;
318 
319  public $last_subscription_amount;
320 
321  public $subscriptions = array();
322 
326  public $ip;
327 
328  // Fields loaded by fetchPartnerships() from partnership table
329 
330  public $partnerships = array();
331 
332 
336  public $oldcopy;
337 
341  public $entity;
342 
346  public $fields = array(
347  'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 10),
348  'ref' => array('type' => 'varchar(30)', 'label' => 'Ref', 'default' => 1, 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 12, 'index' => 1),
349  'entity' => array('type' => 'integer', 'label' => 'Entity', 'default' => 1, 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 15, 'index' => 1),
350  'ref_ext' => array('type' => 'varchar(128)', 'label' => 'Ref ext', 'enabled' => 1, 'visible' => 0, 'position' => 20),
351  'civility' => array('type' => 'varchar(6)', 'label' => 'Civility', 'enabled' => 1, 'visible' => -1, 'position' => 25),
352  'lastname' => array('type' => 'varchar(50)', 'label' => 'Lastname', 'enabled' => 1, 'visible' => -1, 'position' => 30, 'showoncombobox'=>1),
353  'firstname' => array('type' => 'varchar(50)', 'label' => 'Firstname', 'enabled' => 1, 'visible' => -1, 'position' => 35, 'showoncombobox'=>1),
354  'login' => array('type' => 'varchar(50)', 'label' => 'Login', 'enabled' => 1, 'visible' => -1, 'position' => 40),
355  'gender' => array('type' => 'varchar(10)', 'label' => 'Gender', 'enabled' => 1, 'visible' => -1, 'position' => 250),
356  'pass' => array('type' => 'varchar(50)', 'label' => 'Pass', 'enabled' => 1, 'visible' => -1, 'position' => 45),
357  'pass_crypted' => array('type' => 'varchar(128)', 'label' => 'Pass crypted', 'enabled' => 1, 'visible' => -1, 'position' => 50),
358  'fk_adherent_type' => array('type' => 'integer', 'label' => 'Fk adherent type', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 55),
359  'morphy' => array('type' => 'varchar(3)', 'label' => 'MorPhy', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 60),
360  'societe' => array('type' => 'varchar(128)', 'label' => 'Societe', 'enabled' => 1, 'visible' => -1, 'position' => 65, 'showoncombobox'=>2),
361  'fk_soc' => array('type' => 'integer:Societe:societe/class/societe.class.php', 'label' => 'ThirdParty', 'enabled' => 1, 'visible' => -1, 'position' => 70),
362  'address' => array('type' => 'text', 'label' => 'Address', 'enabled' => 1, 'visible' => -1, 'position' => 75),
363  'zip' => array('type' => 'varchar(10)', 'label' => 'Zip', 'enabled' => 1, 'visible' => -1, 'position' => 80),
364  'town' => array('type' => 'varchar(50)', 'label' => 'Town', 'enabled' => 1, 'visible' => -1, 'position' => 85),
365  'state_id' => array('type' => 'integer', 'label' => 'State id', 'enabled' => 1, 'visible' => -1, 'position' => 90),
366  'country' => array('type' => 'integer:Ccountry:core/class/ccountry.class.php', 'label' => 'Country', 'enabled' => 1, 'visible' => -1, 'position' => 95),
367  'email' => array('type' => 'varchar(255)', 'label' => 'Email', 'enabled' => 1, 'visible' => -1, 'position' => 100),
368  'url' =>array('type'=>'varchar(255)', 'label'=>'Url', 'enabled'=>1, 'visible'=>-1, 'position'=>110),
369  'socialnetworks' => array('type' => 'text', 'label' => 'Socialnetworks', 'enabled' => 1, 'visible' => -1, 'position' => 105),
370  'phone' => array('type' => 'varchar(30)', 'label' => 'Phone', 'enabled' => 1, 'visible' => -1, 'position' => 115),
371  'phone_perso' => array('type' => 'varchar(30)', 'label' => 'Phone perso', 'enabled' => 1, 'visible' => -1, 'position' => 120),
372  'phone_mobile' => array('type' => 'varchar(30)', 'label' => 'Phone mobile', 'enabled' => 1, 'visible' => -1, 'position' => 125),
373  'birth' => array('type' => 'date', 'label' => 'DateOfBirth', 'enabled' => 1, 'visible' => -1, 'position' => 130),
374  'photo' => array('type' => 'varchar(255)', 'label' => 'Photo', 'enabled' => 1, 'visible' => -1, 'position' => 135),
375  'public' => array('type' => 'smallint(6)', 'label' => 'Public', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 145),
376  'datefin' => array('type' => 'datetime', 'label' => 'DateEnd', 'enabled' => 1, 'visible' => -1, 'position' => 150),
377  'default_lang' =>array('type'=>'varchar(6)', 'label'=>'Default lang', 'enabled'=>1, 'visible'=>-1, 'position'=> 153),
378  'note_public' => array('type' => 'text', 'label' => 'NotePublic', 'enabled' => 1, 'visible' => 0, 'position' => 155),
379  'note_private' => array('type' => 'text', 'label' => 'NotePrivate', 'enabled' => 1, 'visible' => 0, 'position' => 160),
380  'datevalid' => array('type' => 'datetime', 'label' => 'DateValidation', 'enabled' => 1, 'visible' => -1, 'position' => 165),
381  'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -1, 'position' => 170),
382  'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 175),
383  'fk_user_author' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'Fk user author', 'enabled' => 1, 'visible' => -1, 'position' => 180),
384  'fk_user_mod' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'Fk user mod', 'enabled' => 1, 'visible' => -1, 'position' => 185),
385  'fk_user_valid' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserValidation', 'enabled' => 1, 'visible' => -1, 'position' => 190),
386  'canvas' => array('type' => 'varchar(32)', 'label' => 'Canvas', 'enabled' => 1, 'visible' => -1, 'position' => 195),
387  'statut' => array('type' => 'smallint(6)', 'label' => 'Statut', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 500,
388  'arrayofkeyval' => array(-1 => 'Draft', 1 => 'Validated', 0 => 'MemberStatusResiliatedShort', -2 => 'MemberStatusExcludedShort')),
389  'model_pdf' => array('type' => 'varchar(255)', 'label' => 'Model pdf', 'enabled' => 1, 'visible' => 0, 'position' => 800),
390  'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'visible' => -2, 'position' => 805)
391  );
392 
396  const STATUS_DRAFT = -1;
400  const STATUS_VALIDATED = 1;
404  const STATUS_RESILIATED = 0;
408  const STATUS_EXCLUDED = -2;
409 
410 
416  public function __construct($db)
417  {
418  $this->db = $db;
419  $this->statut = self::STATUS_DRAFT;
420  $this->status = $this->statut;
421  // l'adherent n'est pas public par defaut
422  $this->public = 0;
423  // les champs optionnels sont vides
424  $this->array_options = array();
425  }
426 
427 
428  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
447  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 = '')
448  {
449  // phpcs:enable
450  dol_syslog('Warning using deprecated Adherent::send_an_email', LOG_WARNING);
451 
452  return $this->sendEmail($text, $subject, $filename_list, $mimetype_list, $mimefilename_list, $addr_cc, $addr_bcc, $deliveryreceipt, $msgishtml, $errors_to, $moreinheader);
453  }
454 
472  public function sendEmail($text, $subject, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array(), $addr_cc = "", $addr_bcc = "", $deliveryreceipt = 0, $msgishtml = -1, $errors_to = '', $moreinheader = '')
473  {
474  global $conf, $langs;
475 
476  // Detect if message is HTML
477  if ($msgishtml == -1) {
478  $msgishtml = 0;
479  if (dol_textishtml($text, 0)) {
480  $msgishtml = 1;
481  }
482  }
483 
484  dol_syslog('send_an_email msgishtml='.$msgishtml);
485 
486  $texttosend = $this->makeSubstitution($text);
487  $subjecttosend = $this->makeSubstitution($subject);
488  if ($msgishtml) {
489  $texttosend = dol_htmlentitiesbr($texttosend);
490  }
491 
492  // Envoi mail confirmation
493  $from = $conf->email_from;
494  if (!empty(getDolGlobalString('ADHERENT_MAIL_FROM'))) {
495  $from = getDolGlobalString('ADHERENT_MAIL_FROM');
496  }
497 
498  $trackid = 'mem'.$this->id;
499 
500  // Send email (substitutionarray must be done just before this)
501  include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
502  $mailfile = new CMailFile($subjecttosend, $this->email, $from, $texttosend, $filename_list, $mimetype_list, $mimefilename_list, $addr_cc, $addr_bcc, $deliveryreceipt, $msgishtml, '', '', $trackid, $moreinheader);
503  if ($mailfile->sendfile()) {
504  return 1;
505  } else {
506  $this->error = $langs->trans("ErrorFailedToSendMail", $from, $this->email).'. '.$mailfile->error;
507  return -1;
508  }
509  }
510 
511 
518  public function makeSubstitution($text)
519  {
520  global $conf, $langs;
521 
522  $birthday = dol_print_date($this->birth, 'day');
523 
524  $msgishtml = 0;
525  if (dol_textishtml($text, 1)) {
526  $msgishtml = 1;
527  }
528 
529  $infos = '';
530  if ($this->civility_id) {
531  $infos .= $langs->transnoentities("UserTitle").": ".$this->getCivilityLabel()."\n";
532  }
533  $infos .= $langs->transnoentities("id").": ".$this->id."\n";
534  $infos .= $langs->transnoentities("ref").": ".$this->ref."\n";
535  $infos .= $langs->transnoentities("Lastname").": ".$this->lastname."\n";
536  $infos .= $langs->transnoentities("Firstname").": ".$this->firstname."\n";
537  $infos .= $langs->transnoentities("Company").": ".$this->company."\n";
538  $infos .= $langs->transnoentities("Address").": ".$this->address."\n";
539  $infos .= $langs->transnoentities("Zip").": ".$this->zip."\n";
540  $infos .= $langs->transnoentities("Town").": ".$this->town."\n";
541  $infos .= $langs->transnoentities("Country").": ".$this->country."\n";
542  $infos .= $langs->transnoentities("EMail").": ".$this->email."\n";
543  $infos .= $langs->transnoentities("PhonePro").": ".$this->phone."\n";
544  $infos .= $langs->transnoentities("PhonePerso").": ".$this->phone_perso."\n";
545  $infos .= $langs->transnoentities("PhoneMobile").": ".$this->phone_mobile."\n";
546  if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
547  $infos .= $langs->transnoentities("Login").": ".$this->login."\n";
548  $infos .= $langs->transnoentities("Password").": ".$this->pass."\n";
549  }
550  $infos .= $langs->transnoentities("Birthday").": ".$birthday."\n";
551  $infos .= $langs->transnoentities("Photo").": ".$this->photo."\n";
552  $infos .= $langs->transnoentities("Public").": ".yn($this->public);
553 
554  // Substitutions
555  $substitutionarray = array(
556  '__ID__' => $this->id,
557  '__REF__' => $this->ref,
558  '__MEMBER_ID__' => $this->id,
559  '__CIVILITY__' => $this->getCivilityLabel(),
560  '__FIRSTNAME__' => $msgishtml ? dol_htmlentitiesbr($this->firstname) : ($this->firstname ? $this->firstname : ''),
561  '__LASTNAME__' => $msgishtml ? dol_htmlentitiesbr($this->lastname) : ($this->lastname ? $this->lastname : ''),
562  '__FULLNAME__' => $msgishtml ? dol_htmlentitiesbr($this->getFullName($langs)) : $this->getFullName($langs),
563  '__COMPANY__' => $msgishtml ? dol_htmlentitiesbr($this->company) : ($this->company ? $this->company : ''),
564  '__ADDRESS__' => $msgishtml ? dol_htmlentitiesbr($this->address) : ($this->address ? $this->address : ''),
565  '__ZIP__' => $msgishtml ? dol_htmlentitiesbr($this->zip) : ($this->zip ? $this->zip : ''),
566  '__TOWN__' => $msgishtml ? dol_htmlentitiesbr($this->town) : ($this->town ? $this->town : ''),
567  '__COUNTRY__' => $msgishtml ? dol_htmlentitiesbr($this->country) : ($this->country ? $this->country : ''),
568  '__EMAIL__' => $msgishtml ? dol_htmlentitiesbr($this->email) : ($this->email ? $this->email : ''),
569  '__BIRTH__' => $msgishtml ? dol_htmlentitiesbr($birthday) : ($birthday ? $birthday : ''),
570  '__PHOTO__' => $msgishtml ? dol_htmlentitiesbr($this->photo) : ($this->photo ? $this->photo : ''),
571  '__LOGIN__' => $msgishtml ? dol_htmlentitiesbr($this->login) : ($this->login ? $this->login : ''),
572  '__PASSWORD__' => $msgishtml ? dol_htmlentitiesbr($this->pass) : ($this->pass ? $this->pass : ''),
573  '__PHONE__' => $msgishtml ? dol_htmlentitiesbr($this->phone) : ($this->phone ? $this->phone : ''),
574  '__PHONEPRO__' => $msgishtml ? dol_htmlentitiesbr($this->phone_perso) : ($this->phone_perso ? $this->phone_perso : ''),
575  '__PHONEMOBILE__' => $msgishtml ? dol_htmlentitiesbr($this->phone_mobile) : ($this->phone_mobile ? $this->phone_mobile : ''),
576  '__TYPE__' => $msgishtml ? dol_htmlentitiesbr($this->type) : ($this->type ? $this->type : '')
577  );
578 
579  complete_substitutions_array($substitutionarray, $langs, $this);
580 
581  return make_substitutions($text, $substitutionarray, $langs);
582  }
583 
584 
592  public function getmorphylib($morphy = '', $addbadge = 0)
593  {
594  global $langs;
595 
596  // Clean var
597  if (!$morphy) {
598  $morphy = $this->morphy;
599  }
600 
601  if ($addbadge) {
602  $s = '';
603  $labeltoshowm = $langs->trans("Moral");
604  $labeltoshowp = $langs->trans("Physical");
605  if ($morphy == 'phy') {
606  $labeltoshow = $labeltoshowp;
607  if ($addbadge == 2) {
608  $labeltoshow = dol_strtoupper(dolGetFirstLetters($labeltoshowp));
609  if ($labeltoshow == dol_strtoupper(dolGetFirstLetters($labeltoshowm))) {
610  $labeltoshow = dol_strtoupper(dolGetFirstLetters($labeltoshowp, 2));
611  }
612  }
613  $s .= '<span class="member-individual-back paddingleftimp paddingrightimp" title="'.$langs->trans("Physical").'">'.$labeltoshow.'</span>';
614  }
615  if ($morphy == 'mor') {
616  $labeltoshow = $labeltoshowm;
617  if ($addbadge == 2) {
618  $labeltoshow = dol_strtoupper(dolGetFirstLetters($labeltoshowm));
619  if ($labeltoshow == dol_strtoupper(dolGetFirstLetters($labeltoshowp))) {
620  $labeltoshow = dol_strtoupper(dolGetFirstLetters($labeltoshowm, 2));
621  }
622  }
623  $s .= '<span class="member-company-back paddingleftimp paddingrightimp" title="'.$langs->trans("Moral").'">'.$labeltoshow.'</span>';
624  }
625  } else {
626  if ($morphy == 'phy') {
627  $s = $langs->trans("Physical");
628  } elseif ($morphy == 'mor') {
629  $s = $langs->trans("Moral");
630  }
631  }
632 
633  return $s;
634  }
635 
643  public function create($user, $notrigger = 0)
644  {
645  global $conf, $langs, $mysoc;
646 
647  $error = 0;
648 
649  $now = dol_now();
650 
651  // Clean parameters
652  $this->import_key = trim($this->import_key);
653 
654  // Check parameters
655  if (!empty($conf->global->ADHERENT_MAIL_REQUIRED) && !isValidEMail($this->email)) {
656  $langs->load("errors");
657  $this->error = $langs->trans("ErrorBadEMail", $this->email);
658  return -1;
659  }
660  if (!$this->datec) {
661  $this->datec = $now;
662  }
663  if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
664  if (empty($this->login)) {
665  $this->error = $langs->trans("ErrorWrongValueForParameterX", "Login");
666  return -1;
667  }
668  }
669 
670  $this->db->begin();
671 
672  // Insert member
673  $sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent";
674  $sql .= " (ref, datec,login,fk_user_author,fk_user_mod,fk_user_valid,morphy,fk_adherent_type,entity,import_key, ip)";
675  $sql .= " VALUES (";
676  $sql .= " '(PROV)'";
677  $sql .= ", '".$this->db->idate($this->datec)."'";
678  $sql .= ", ".($this->login ? "'".$this->db->escape($this->login)."'" : "null");
679  $sql .= ", ".($user->id > 0 ? $user->id : "null"); // Can be null because member can be created by a guest or a script
680  $sql .= ", null, null, '".$this->db->escape($this->morphy)."'";
681  $sql .= ", ".((int) $this->typeid);
682  $sql .= ", ".$conf->entity;
683  $sql .= ", ".(!empty($this->import_key) ? "'".$this->db->escape($this->import_key)."'" : "null");
684  $sql .= ", ".(!empty($this->ip) ? "'".$this->db->escape($this->ip)."'" : "null");
685  $sql .= ")";
686 
687  dol_syslog(get_class($this)."::create", LOG_DEBUG);
688  $result = $this->db->query($sql);
689  if ($result) {
690  $id = $this->db->last_insert_id(MAIN_DB_PREFIX."adherent");
691  if ($id > 0) {
692  $this->id = $id;
693  if (getDolGlobalString('MEMBER_CODEMEMBER_ADDON') == '') {
694  // keep old numbering
695  $this->ref = (string) $id;
696  } else {
697  // auto code
698  $modfile = dol_buildpath('core/modules/member/'.getDolGlobalString('MEMBER_CODEMEMBER_ADDON').'.php', 0);
699  try {
700  require_once $modfile;
701  $modname = getDolGlobalString('MEMBER_CODEMEMBER_ADDON');
702  $modCodeMember = new $modname;
703  $this->ref = $modCodeMember->getNextValue($mysoc, $this);
704  } catch (Exception $e) {
705  dol_syslog($e->getMessage(), LOG_ERR);
706  $error++;
707  }
708  }
709 
710  // Update minor fields
711  $result = $this->update($user, 1, 1, 0, 0, 'add'); // nosync is 1 to avoid update data of user
712  if ($result < 0) {
713  $this->db->rollback();
714  return -1;
715  }
716 
717  // Add link to user
718  if ($this->user_id) {
719  // Add link to user
720  $sql = "UPDATE ".MAIN_DB_PREFIX."user SET";
721  $sql .= " fk_member = ".((int) $this->id);
722  $sql .= " WHERE rowid = ".((int) $this->user_id);
723  dol_syslog(get_class($this)."::create", LOG_DEBUG);
724  $resql = $this->db->query($sql);
725  if (!$resql) {
726  $this->error = 'Failed to update user to make link with member';
727  $this->db->rollback();
728  return -4;
729  }
730  }
731 
732  if (!$notrigger) {
733  // Call trigger
734  $result = $this->call_trigger('MEMBER_CREATE', $user);
735  if ($result < 0) {
736  $error++;
737  }
738  // End call triggers
739  }
740 
741  if (count($this->errors)) {
742  dol_syslog(get_class($this)."::create ".implode(',', $this->errors), LOG_ERR);
743  $this->db->rollback();
744  return -3;
745  } else {
746  $this->db->commit();
747  return $this->id;
748  }
749  } else {
750  $this->error = 'Failed to get last insert id';
751  dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
752  $this->db->rollback();
753  return -2;
754  }
755  } else {
756  $this->error = $this->db->error();
757  $this->db->rollback();
758  return -1;
759  }
760  }
761 
762 
774  public function update($user, $notrigger = 0, $nosyncuser = 0, $nosyncuserpass = 0, $nosyncthirdparty = 0, $action = 'update')
775  {
776  global $conf, $langs, $hookmanager;
777 
778  require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
779 
780  $nbrowsaffected = 0;
781  $error = 0;
782 
783  dol_syslog(get_class($this)."::update notrigger=".$notrigger.", nosyncuser=".$nosyncuser.", nosyncuserpass=".$nosyncuserpass." nosyncthirdparty=".$nosyncthirdparty.", email=".$this->email);
784 
785  // Clean parameters
786  $this->lastname = trim($this->lastname) ? trim($this->lastname) : trim($this->lastname);
787  $this->firstname = trim($this->firstname) ? trim($this->firstname) : trim($this->firstname);
788  $this->gender = trim($this->gender);
789  $this->address = ($this->address ? $this->address : $this->address);
790  $this->zip = ($this->zip ? $this->zip : $this->zip);
791  $this->town = ($this->town ? $this->town : $this->town);
792  $this->country_id = ($this->country_id > 0 ? $this->country_id : $this->country_id);
793  $this->state_id = ($this->state_id > 0 ? $this->state_id : $this->state_id);
794  $this->note_public = ($this->note_public ? $this->note_public : $this->note_public);
795  $this->note_private = ($this->note_private ? $this->note_private : $this->note_private);
796  $this->url = $this->url ?clean_url($this->url, 0) : '';
797  $this->setUpperOrLowerCase();
798  // Check parameters
799  if (!empty($conf->global->ADHERENT_MAIL_REQUIRED) && !isValidEMail($this->email)) {
800  $langs->load("errors");
801  $this->error = $langs->trans("ErrorBadEMail", $this->email);
802  return -1;
803  }
804 
805  $this->db->begin();
806 
807  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
808  $sql .= " ref = '".$this->db->escape($this->ref)."'";
809  $sql .= ", civility = ".($this->civility_id ? "'".$this->db->escape($this->civility_id)."'" : "null");
810  $sql .= ", firstname = ".($this->firstname ? "'".$this->db->escape($this->firstname)."'" : "null");
811  $sql .= ", lastname = ".($this->lastname ? "'".$this->db->escape($this->lastname)."'" : "null");
812  $sql .= ", gender = ".($this->gender != -1 ? "'".$this->db->escape($this->gender)."'" : "null"); // 'man' or 'woman'
813  $sql .= ", login = ".($this->login ? "'".$this->db->escape($this->login)."'" : "null");
814  $sql .= ", societe = ".($this->company ? "'".$this->db->escape($this->company)."'" : ($this->societe ? "'".$this->db->escape($this->societe)."'" : "null"));
815  if ($this->socid) {
816  $sql .= ", fk_soc = ".($this->socid > 0 ? $this->db->escape($this->socid) : "null"); // Must be modified only when creating from a third-party
817  }
818  $sql .= ", address = ".($this->address ? "'".$this->db->escape($this->address)."'" : "null");
819  $sql .= ", zip = ".($this->zip ? "'".$this->db->escape($this->zip)."'" : "null");
820  $sql .= ", town = ".($this->town ? "'".$this->db->escape($this->town)."'" : "null");
821  $sql .= ", country = ".($this->country_id > 0 ? $this->db->escape($this->country_id) : "null");
822  $sql .= ", state_id = ".($this->state_id > 0 ? $this->db->escape($this->state_id) : "null");
823  $sql .= ", email = '".$this->db->escape($this->email)."'";
824  $sql .= ", url = ".(!empty($this->url) ? "'".$this->db->escape($this->url)."'" : "null");
825  $sql .= ", socialnetworks = ".($this->socialnetworks ? "'".$this->db->escape(json_encode($this->socialnetworks))."'" : "null");
826  $sql .= ", phone = ".($this->phone ? "'".$this->db->escape($this->phone)."'" : "null");
827  $sql .= ", phone_perso = ".($this->phone_perso ? "'".$this->db->escape($this->phone_perso)."'" : "null");
828  $sql .= ", phone_mobile = ".($this->phone_mobile ? "'".$this->db->escape($this->phone_mobile)."'" : "null");
829  $sql .= ", note_private = ".($this->note_private ? "'".$this->db->escape($this->note_private)."'" : "null");
830  $sql .= ", note_public = ".($this->note_public ? "'".$this->db->escape($this->note_public)."'" : "null");
831  $sql .= ", photo = ".($this->photo ? "'".$this->db->escape($this->photo)."'" : "null");
832  $sql .= ", public = '".$this->db->escape($this->public)."'";
833  $sql .= ", statut = ".$this->db->escape($this->statut);
834  $sql .= ", default_lang = ".(!empty($this->default_lang) ? "'".$this->db->escape($this->default_lang)."'" : "null");
835  $sql .= ", fk_adherent_type = ".$this->db->escape($this->typeid);
836  $sql .= ", morphy = '".$this->db->escape($this->morphy)."'";
837  $sql .= ", birth = ".($this->birth ? "'".$this->db->idate($this->birth)."'" : "null");
838 
839  if ($this->datefin) {
840  $sql .= ", datefin = '".$this->db->idate($this->datefin)."'"; // Must be modified only when deleting a subscription
841  }
842  if ($this->datevalid) {
843  $sql .= ", datevalid = '".$this->db->idate($this->datevalid)."'"; // Must be modified only when validating a member
844  }
845  $sql .= ", fk_user_mod = ".($user->id > 0 ? $user->id : 'null'); // Can be null because member can be create by a guest
846  $sql .= " WHERE rowid = ".((int) $this->id);
847 
848  // If we change the type of membership, we set also label of new type
849  if (!empty($this->oldcopy) && $this->typeid != $this->oldcopy->typeid) {
850  $sql2 = "SELECT libelle as label";
851  $sql2 .= " FROM ".MAIN_DB_PREFIX."adherent_type";
852  $sql2 .= " WHERE rowid = ".((int) $this->typeid);
853  $resql2 = $this->db->query($sql2);
854  if ($resql2) {
855  while ($obj = $this->db->fetch_object($resql2)) {
856  $this->type = $obj->label;
857  }
858  }
859  }
860 
861  dol_syslog(get_class($this)."::update update member", LOG_DEBUG);
862  $resql = $this->db->query($sql);
863  if ($resql) {
864  unset($this->country_code);
865  unset($this->country);
866  unset($this->state_code);
867  unset($this->state);
868 
869  $nbrowsaffected += $this->db->affected_rows($resql);
870 
871  $action = 'update';
872 
873  // Actions on extra fields
874  if (!$error) {
875  $result = $this->insertExtraFields();
876  if ($result < 0) {
877  $error++;
878  }
879  }
880 
881  // Update password
882  if (!$error && $this->pass) {
883  dol_syslog(get_class($this)."::update update password");
884  if ($this->pass != $this->pass_indatabase && $this->pass != $this->pass_indatabase_crypted) {
885  $isencrypted = empty($conf->global->DATABASE_PWD_ENCRYPTED) ? 0 : 1;
886 
887  // If password to set differs from the one found into database
888  $result = $this->setPassword($user, $this->pass, $isencrypted, $notrigger, $nosyncuserpass);
889  if (!$nbrowsaffected) {
890  $nbrowsaffected++;
891  }
892  }
893  }
894 
895  // Remove links to user and replace with new one
896  if (!$error) {
897  dol_syslog(get_class($this)."::update update link to user");
898  $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = NULL WHERE fk_member = ".((int) $this->id);
899  dol_syslog(get_class($this)."::update", LOG_DEBUG);
900  $resql = $this->db->query($sql);
901  if (!$resql) {
902  $this->error = $this->db->error();
903  $this->db->rollback();
904  return -5;
905  }
906  // If there is a user linked to this member
907  if ($this->user_id > 0) {
908  $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = ".((int) $this->id)." WHERE rowid = ".((int) $this->user_id);
909  dol_syslog(get_class($this)."::update", LOG_DEBUG);
910  $resql = $this->db->query($sql);
911  if (!$resql) {
912  $this->error = $this->db->error();
913  $this->db->rollback();
914  return -5;
915  }
916  }
917  }
918 
919  if (!$error && $nbrowsaffected) { // If something has change in main data
920  // Update information on linked user if it is an update
921  if (!$error && $this->user_id > 0 && !$nosyncuser) {
922  require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
923 
924  dol_syslog(get_class($this)."::update update linked user");
925 
926  $luser = new User($this->db);
927  $result = $luser->fetch($this->user_id);
928 
929  if ($result >= 0) {
930  //var_dump($this->user_login);exit;
931  //var_dump($this->login);exit;
932 
933  // 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.
934  if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
935  $luser->login = $this->login;
936  }
937 
938  $luser->ref = $this->ref;
939  $luser->civility_id = $this->civility_id;
940  $luser->firstname = $this->firstname;
941  $luser->lastname = $this->lastname;
942  $luser->gender = $this->gender;
943  $luser->pass = $this->pass;
944  //$luser->socid=$this->fk_soc; // We do not enable this. This may transform a user into an external user.
945 
946  $luser->birth = $this->birth;
947 
948  $luser->address = $this->address;
949  $luser->zip = $this->zip;
950  $luser->town = $this->town;
951  $luser->country_id = $this->country_id;
952  $luser->state_id = $this->state_id;
953 
954  $luser->email = $this->email;
955  $luser->socialnetworks = $this->socialnetworks;
956  $luser->office_phone = $this->phone;
957  $luser->user_mobile = $this->phone_mobile;
958 
959  $luser->lang = $this->default_lang;
960 
961  $luser->fk_member = $this->id;
962 
963  $result = $luser->update($user, 0, 1, 1); // Use nosync to 1 to avoid cyclic updates
964  if ($result < 0) {
965  $this->error = $luser->error;
966  dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
967  $error++;
968  }
969  } else {
970  $this->error = $luser->error;
971  $error++;
972  }
973  }
974 
975  // Update information on linked thirdparty if it is an update
976  if (!$error && $this->fk_soc > 0 && !$nosyncthirdparty) {
977  require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
978 
979  dol_syslog(get_class($this)."::update update linked thirdparty");
980 
981  // This member is linked with a thirdparty, so we also update thirdparty informations
982  // if this is an update.
983  $lthirdparty = new Societe($this->db);
984  $result = $lthirdparty->fetch($this->fk_soc);
985 
986  if ($result > 0) {
987  $lthirdparty->address = $this->address;
988  $lthirdparty->zip = $this->zip;
989  $lthirdparty->town = $this->town;
990  $lthirdparty->email = $this->email;
991  $lthirdparty->socialnetworks = $this->socialnetworks;
992  $lthirdparty->phone = $this->phone;
993  $lthirdparty->state_id = $this->state_id;
994  $lthirdparty->country_id = $this->country_id;
995  //$lthirdparty->phone_mobile=$this->phone_mobile;
996  $lthirdparty->default_lang = $this->default_lang;
997 
998  $result = $lthirdparty->update($this->fk_soc, $user, 0, 1, 1, 'update'); // Use sync to 0 to avoid cyclic updates
999 
1000  if ($result < 0) {
1001  $this->error = $lthirdparty->error;
1002  $this->errors = $lthirdparty->errors;
1003  dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
1004  $error++;
1005  }
1006  } elseif ($result < 0) {
1007  $this->error = $lthirdparty->error;
1008  $error++;
1009  }
1010  }
1011  }
1012 
1013  if (!$error && !$notrigger) {
1014  // Call trigger
1015  $result = $this->call_trigger('MEMBER_MODIFY', $user);
1016  if ($result < 0) {
1017  $error++;
1018  }
1019  // End call triggers
1020  }
1021 
1022  if (!$error) {
1023  $this->db->commit();
1024  return $nbrowsaffected;
1025  } else {
1026  $this->db->rollback();
1027  return -1;
1028  }
1029  } else {
1030  $this->db->rollback();
1031  $this->error = $this->db->lasterror();
1032  return -2;
1033  }
1034  }
1035 
1036 
1037  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1045  public function update_end_date($user)
1046  {
1047  // phpcs:enable
1048  $this->db->begin();
1049 
1050  // Search for last subscription id and end date
1051  $sql = "SELECT rowid, datec as dateop, dateadh as datedeb, datef as datefin";
1052  $sql .= " FROM ".MAIN_DB_PREFIX."subscription";
1053  $sql .= " WHERE fk_adherent = ".((int) $this->id);
1054  $sql .= " ORDER by dateadh DESC"; // Sort by start subscription date
1055 
1056  dol_syslog(get_class($this)."::update_end_date", LOG_DEBUG);
1057  $resql = $this->db->query($sql);
1058  if ($resql) {
1059  $obj = $this->db->fetch_object($resql);
1060  $dateop = $this->db->jdate($obj->dateop);
1061  $datedeb = $this->db->jdate($obj->datedeb);
1062  $datefin = $this->db->jdate($obj->datefin);
1063 
1064  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
1065  $sql .= " datefin=".($datefin != '' ? "'".$this->db->idate($datefin)."'" : "null");
1066  $sql .= " WHERE rowid = ".((int) $this->id);
1067 
1068  dol_syslog(get_class($this)."::update_end_date", LOG_DEBUG);
1069  $resql = $this->db->query($sql);
1070  if ($resql) {
1071  $this->last_subscription_date = $dateop;
1072  $this->last_subscription_date_start = $datedeb;
1073  $this->last_subscription_date_end = $datefin;
1074  $this->datefin = $datefin;
1075  $this->db->commit();
1076  return 1;
1077  } else {
1078  $this->db->rollback();
1079  return -1;
1080  }
1081  } else {
1082  $this->error = $this->db->lasterror();
1083  $this->db->rollback();
1084  return -1;
1085  }
1086  }
1087 
1096  public function delete($rowid, $user, $notrigger = 0)
1097  {
1098  global $conf, $langs;
1099 
1100  $result = 0;
1101  $error = 0;
1102  $errorflag = 0;
1103 
1104  // Check parameters
1105  if (empty($rowid)) {
1106  $rowid = $this->id;
1107  }
1108 
1109  $this->db->begin();
1110 
1111  if (!$error && !$notrigger) {
1112  // Call trigger
1113  $result = $this->call_trigger('MEMBER_DELETE', $user);
1114  if ($result < 0) {
1115  $error++;
1116  }
1117  // End call triggers
1118  }
1119 
1120  // Remove category
1121  $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_member WHERE fk_member = ".((int) $rowid);
1122  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1123  $resql = $this->db->query($sql);
1124  if (!$resql) {
1125  $error++;
1126  $this->error .= $this->db->lasterror();
1127  $errorflag = -1;
1128  }
1129 
1130  // Remove subscription
1131  if (!$error) {
1132  $sql = "DELETE FROM ".MAIN_DB_PREFIX."subscription WHERE fk_adherent = ".((int) $rowid);
1133  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1134  $resql = $this->db->query($sql);
1135  if (!$resql) {
1136  $error++;
1137  $this->error .= $this->db->lasterror();
1138  $errorflag = -2;
1139  }
1140  }
1141 
1142  // Remove linked user
1143  if (!$error) {
1144  $ret = $this->setUserId(0);
1145  if ($ret < 0) {
1146  $error++;
1147  $this->error .= $this->db->lasterror();
1148  $errorflag = -3;
1149  }
1150  }
1151 
1152  // Removed extrafields
1153  if (!$error) {
1154  $result = $this->deleteExtraFields();
1155  if ($result < 0) {
1156  $error++;
1157  $errorflag = -4;
1158  dol_syslog(get_class($this)."::delete erreur ".$errorflag." ".$this->error, LOG_ERR);
1159  }
1160  }
1161 
1162  // Remove adherent
1163  if (!$error) {
1164  $sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent WHERE rowid = ".((int) $rowid);
1165  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1166  $resql = $this->db->query($sql);
1167  if (!$resql) {
1168  $error++;
1169  $this->error .= $this->db->lasterror();
1170  $errorflag = -5;
1171  }
1172  }
1173 
1174  if (!$error) {
1175  $this->db->commit();
1176  return 1;
1177  } else {
1178  $this->db->rollback();
1179  return $errorflag;
1180  }
1181  }
1182 
1183 
1194  public function setPassword($user, $password = '', $isencrypted = 0, $notrigger = 0, $nosyncuser = 0)
1195  {
1196  global $conf, $langs;
1197 
1198  $error = 0;
1199 
1200  dol_syslog(get_class($this)."::setPassword user=".$user->id." password=".preg_replace('/./i', '*', $password)." isencrypted=".$isencrypted);
1201 
1202  // If new password not provided, we generate one
1203  if (!$password) {
1204  require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
1205  $password = getRandomPassword(false);
1206  }
1207 
1208  // Crypt password
1209  $password_crypted = dol_hash($password);
1210 
1211  $password_indatabase = '';
1212  if (!$isencrypted) {
1213  $password_indatabase = $password;
1214  }
1215 
1216  $this->db->begin();
1217 
1218  // Mise a jour
1219  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent";
1220  $sql .= " SET pass_crypted = '".$this->db->escape($password_crypted)."'";
1221  //if (!empty($conf->global->DATABASE_PWD_ENCRYPTED))
1222  if ($isencrypted) {
1223  $sql .= ", pass = null";
1224  } else {
1225  $sql .= ", pass = '".$this->db->escape($password_indatabase)."'";
1226  }
1227  $sql .= " WHERE rowid = ".((int) $this->id);
1228 
1229  //dol_syslog("Adherent::Password sql=hidden");
1230  dol_syslog(get_class($this)."::setPassword", LOG_DEBUG);
1231  $result = $this->db->query($sql);
1232  if ($result) {
1233  $nbaffectedrows = $this->db->affected_rows($result);
1234 
1235  if ($nbaffectedrows) {
1236  $this->pass = $password;
1237  $this->pass_indatabase = $password_indatabase;
1238  $this->pass_indatabase_crypted = $password_crypted;
1239 
1240  if ($this->user_id && !$nosyncuser) {
1241  require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
1242 
1243  // This member is linked with a user, so we also update users informations
1244  // if this is an update.
1245  $luser = new User($this->db);
1246  $result = $luser->fetch($this->user_id);
1247 
1248  if ($result >= 0) {
1249  $result = $luser->setPassword($user, $this->pass, 0, 0, 1);
1250  if ($result < 0) {
1251  $this->error = $luser->error;
1252  dol_syslog(get_class($this)."::setPassword ".$this->error, LOG_ERR);
1253  $error++;
1254  }
1255  } else {
1256  $this->error = $luser->error;
1257  $error++;
1258  }
1259  }
1260 
1261  if (!$error && !$notrigger) {
1262  // Call trigger
1263  $result = $this->call_trigger('MEMBER_NEW_PASSWORD', $user);
1264  if ($result < 0) {
1265  $error++;
1266  $this->db->rollback();
1267  return -1;
1268  }
1269  // End call triggers
1270  }
1271 
1272  $this->db->commit();
1273  return $this->pass;
1274  } else {
1275  $this->db->rollback();
1276  return 0;
1277  }
1278  } else {
1279  $this->db->rollback();
1280  dol_print_error($this->db);
1281  return -1;
1282  }
1283  }
1284 
1285 
1292  public function setUserId($userid)
1293  {
1294  global $conf, $langs;
1295 
1296  $this->db->begin();
1297 
1298  // If user is linked to this member, remove old link to this member
1299  $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = NULL WHERE fk_member = ".((int) $this->id);
1300  dol_syslog(get_class($this)."::setUserId", LOG_DEBUG);
1301  $resql = $this->db->query($sql);
1302  if (!$resql) {
1303  $this->error = $this->db->error();
1304  $this->db->rollback();
1305  return -1;
1306  }
1307 
1308  // Set link to user
1309  if ($userid > 0) {
1310  $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = ".((int) $this->id);
1311  $sql .= " WHERE rowid = ".((int) $userid);
1312  dol_syslog(get_class($this)."::setUserId", LOG_DEBUG);
1313  $resql = $this->db->query($sql);
1314  if (!$resql) {
1315  $this->error = $this->db->error();
1316  $this->db->rollback();
1317  return -2;
1318  }
1319  }
1320 
1321  $this->db->commit();
1322 
1323  return 1;
1324  }
1325 
1326 
1333  public function setThirdPartyId($thirdpartyid)
1334  {
1335  global $conf, $langs;
1336 
1337  $this->db->begin();
1338 
1339  // Remove link to third party onto any other members
1340  if ($thirdpartyid > 0) {
1341  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET fk_soc = null";
1342  $sql .= " WHERE fk_soc = ".((int) $thirdpartyid);
1343  $sql .= " AND entity = ".$conf->entity;
1344  dol_syslog(get_class($this)."::setThirdPartyId", LOG_DEBUG);
1345  $resql = $this->db->query($sql);
1346  }
1347 
1348  // Add link to third party for current member
1349  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET fk_soc = ".($thirdpartyid > 0 ? $thirdpartyid : 'null');
1350  $sql .= " WHERE rowid = ".((int) $this->id);
1351 
1352  dol_syslog(get_class($this)."::setThirdPartyId", LOG_DEBUG);
1353  $resql = $this->db->query($sql);
1354  if ($resql) {
1355  $this->db->commit();
1356  return 1;
1357  } else {
1358  $this->error = $this->db->error();
1359  $this->db->rollback();
1360  return -1;
1361  }
1362  }
1363 
1364 
1365  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1372  public function fetch_login($login)
1373  {
1374  // phpcs:enable
1375  global $conf;
1376 
1377  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."adherent";
1378  $sql .= " WHERE login='".$this->db->escape($login)."'";
1379  $sql .= " AND entity = ".$conf->entity;
1380 
1381  $resql = $this->db->query($sql);
1382  if ($resql) {
1383  if ($this->db->num_rows($resql)) {
1384  $obj = $this->db->fetch_object($resql);
1385  $this->fetch($obj->rowid);
1386  }
1387  } else {
1388  dol_print_error($this->db);
1389  }
1390  }
1391 
1392  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1400  public function fetch_name($firstname, $lastname)
1401  {
1402  // phpcs:enable
1403  global $conf;
1404 
1405  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."adherent";
1406  $sql .= " WHERE firstname='".$this->db->escape($firstname)."'";
1407  $sql .= " AND lastname='".$this->db->escape($lastname)."'";
1408  $sql .= " AND entity = ".$conf->entity;
1409 
1410  $resql = $this->db->query($sql);
1411  if ($resql) {
1412  if ($this->db->num_rows($resql)) {
1413  $obj = $this->db->fetch_object($resql);
1414  $this->fetch($obj->rowid);
1415  }
1416  } else {
1417  dol_print_error($this->db);
1418  }
1419  }
1420 
1432  public function fetch($rowid, $ref = '', $fk_soc = '', $ref_ext = '', $fetch_optionals = true, $fetch_subscriptions = true)
1433  {
1434  global $langs;
1435 
1436  $sql = "SELECT d.rowid, d.ref, d.ref_ext, d.civility as civility_code, d.gender, d.firstname, d.lastname,";
1437  $sql .= " d.societe as company, d.fk_soc, d.statut, d.public, d.address, d.zip, d.town, d.note_private,";
1438  $sql .= " d.note_public,";
1439  $sql .= " d.email, d.url, d.socialnetworks, d.phone, d.phone_perso, d.phone_mobile, d.login, d.pass, d.pass_crypted,";
1440  $sql .= " d.photo, d.fk_adherent_type, d.morphy, d.entity,";
1441  $sql .= " d.datec as datec,";
1442  $sql .= " d.tms as datem,";
1443  $sql .= " d.datefin as datefin, d.default_lang,";
1444  $sql .= " d.birth as birthday,";
1445  $sql .= " d.datevalid as datev,";
1446  $sql .= " d.country,";
1447  $sql .= " d.state_id,";
1448  $sql .= " d.model_pdf,";
1449  $sql .= " c.rowid as country_id, c.code as country_code, c.label as country,";
1450  $sql .= " dep.nom as state, dep.code_departement as state_code,";
1451  $sql .= " t.libelle as type, t.subscription as subscription,";
1452  $sql .= " u.rowid as user_id, u.login as user_login";
1453  $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as t, ".MAIN_DB_PREFIX."adherent as d";
1454  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON d.country = c.rowid";
1455  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as dep ON d.state_id = dep.rowid";
1456  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON d.rowid = u.fk_member";
1457  $sql .= " WHERE d.fk_adherent_type = t.rowid";
1458  if ($rowid) {
1459  $sql .= " AND d.rowid=".((int) $rowid);
1460  } elseif ($ref || $fk_soc) {
1461  $sql .= " AND d.entity IN (".getEntity('adherent').")";
1462  if ($ref) {
1463  $sql .= " AND d.ref='".$this->db->escape($ref)."'";
1464  } elseif ($fk_soc > 0) {
1465  $sql .= " AND d.fk_soc=".((int) $fk_soc);
1466  }
1467  } elseif ($ref_ext) {
1468  $sql .= " AND d.ref_ext='".$this->db->escape($ref_ext)."'";
1469  }
1470 
1471  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
1472  $resql = $this->db->query($sql);
1473  if ($resql) {
1474  if ($this->db->num_rows($resql)) {
1475  $obj = $this->db->fetch_object($resql);
1476 
1477  $this->entity = $obj->entity;
1478  $this->id = $obj->rowid;
1479  $this->ref = $obj->ref;
1480  $this->ref_ext = $obj->ref_ext;
1481 
1482  $this->civility_id = $obj->civility_code; // Bad. Kept for backard compatibility
1483  $this->civility_code = $obj->civility_code;
1484  $this->civility = $obj->civility_code ? ($langs->trans("Civility".$obj->civility_code) != ("Civility".$obj->civility_code) ? $langs->trans("Civility".$obj->civility_code) : $obj->civility_code) : '';
1485 
1486  $this->firstname = $obj->firstname;
1487  $this->lastname = $obj->lastname;
1488  $this->gender = $obj->gender;
1489  $this->login = $obj->login;
1490  $this->societe = $obj->company;
1491  $this->company = $obj->company;
1492  $this->socid = $obj->fk_soc;
1493  $this->fk_soc = $obj->fk_soc; // For backward compatibility
1494  $this->address = $obj->address;
1495  $this->zip = $obj->zip;
1496  $this->town = $obj->town;
1497 
1498  $this->pass = $obj->pass;
1499  $this->pass_indatabase = $obj->pass;
1500  $this->pass_indatabase_crypted = $obj->pass_crypted;
1501 
1502  $this->state_id = $obj->state_id;
1503  $this->state_code = $obj->state_id ? $obj->state_code : '';
1504  $this->state = $obj->state_id ? $obj->state : '';
1505 
1506  $this->country_id = $obj->country_id;
1507  $this->country_code = $obj->country_code;
1508  if ($langs->trans("Country".$obj->country_code) != "Country".$obj->country_code) {
1509  $this->country = $langs->transnoentitiesnoconv("Country".$obj->country_code);
1510  } else {
1511  $this->country = $obj->country;
1512  }
1513 
1514  $this->phone = $obj->phone;
1515  $this->phone_perso = $obj->phone_perso;
1516  $this->phone_mobile = $obj->phone_mobile;
1517  $this->email = $obj->email;
1518  $this->url = $obj->url;
1519 
1520  $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks, true) : array());
1521 
1522  $this->photo = $obj->photo;
1523  $this->statut = $obj->statut;
1524  $this->status = $obj->statut;
1525  $this->public = $obj->public;
1526 
1527  $this->datec = $this->db->jdate($obj->datec);
1528  $this->date_creation = $this->db->jdate($obj->datec);
1529  $this->datem = $this->db->jdate($obj->datem);
1530  $this->date_modification = $this->db->jdate($obj->datem);
1531  $this->datefin = $this->db->jdate($obj->datefin);
1532  $this->datevalid = $this->db->jdate($obj->datev);
1533  $this->date_validation = $this->db->jdate($obj->datev);
1534  $this->birth = $this->db->jdate($obj->birthday);
1535 
1536  $this->default_lang = $obj->default_lang;
1537 
1538  $this->note_private = $obj->note_private;
1539  $this->note_public = $obj->note_public;
1540  $this->morphy = $obj->morphy;
1541 
1542  $this->typeid = $obj->fk_adherent_type;
1543  $this->type = $obj->type;
1544  $this->need_subscription = $obj->subscription;
1545 
1546  $this->user_id = $obj->user_id;
1547  $this->user_login = $obj->user_login;
1548 
1549  $this->model_pdf = $obj->model_pdf;
1550 
1551  // Retrieve all extrafield
1552  // fetch optionals attributes and labels
1553  if ($fetch_optionals) {
1554  $this->fetch_optionals();
1555  }
1556 
1557  // Load other properties
1558  if ($fetch_subscriptions) {
1559  $result = $this->fetch_subscriptions();
1560  }
1561 
1562  return $this->id;
1563  } else {
1564  return 0;
1565  }
1566  } else {
1567  $this->error = $this->db->lasterror();
1568  return -1;
1569  }
1570  }
1571 
1572 
1573  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1582  public function fetch_subscriptions()
1583  {
1584  // phpcs:enable
1585  global $langs;
1586 
1587  require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
1588 
1589  $sql = "SELECT c.rowid, c.fk_adherent, c.fk_type, c.subscription, c.note as note_public, c.fk_bank,";
1590  $sql .= " c.tms as datem,";
1591  $sql .= " c.datec as datec,";
1592  $sql .= " c.dateadh as dateh,";
1593  $sql .= " c.datef as datef";
1594  $sql .= " FROM ".MAIN_DB_PREFIX."subscription as c";
1595  $sql .= " WHERE c.fk_adherent = ".((int) $this->id);
1596  $sql .= " ORDER BY c.dateadh";
1597  dol_syslog(get_class($this)."::fetch_subscriptions", LOG_DEBUG);
1598 
1599  $resql = $this->db->query($sql);
1600  if ($resql) {
1601  $this->subscriptions = array();
1602 
1603  $i = 0;
1604  while ($obj = $this->db->fetch_object($resql)) {
1605  if ($i == 0) {
1606  $this->first_subscription_date = $this->db->jdate($obj->datec);
1607  $this->first_subscription_date_start = $this->db->jdate($obj->dateh);
1608  $this->first_subscription_date_end = $this->db->jdate($obj->datef);
1609  $this->first_subscription_amount = $obj->subscription;
1610  }
1611  $this->last_subscription_date = $this->db->jdate($obj->datec);
1612  $this->last_subscription_date_start = $this->db->jdate($obj->dateh);
1613  $this->last_subscription_date_end = $this->db->jdate($obj->datef);
1614  $this->last_subscription_amount = $obj->subscription;
1615 
1616  $subscription = new Subscription($this->db);
1617  $subscription->id = $obj->rowid;
1618  $subscription->fk_adherent = $obj->fk_adherent;
1619  $subscription->fk_type = $obj->fk_type;
1620  $subscription->amount = $obj->subscription;
1621  $subscription->note = $obj->note_public;
1622  $subscription->note_public = $obj->note_public;
1623  $subscription->fk_bank = $obj->fk_bank;
1624  $subscription->datem = $this->db->jdate($obj->datem);
1625  $subscription->datec = $this->db->jdate($obj->datec);
1626  $subscription->dateh = $this->db->jdate($obj->dateh);
1627  $subscription->datef = $this->db->jdate($obj->datef);
1628 
1629  $this->subscriptions[] = $subscription;
1630 
1631  $i++;
1632  }
1633  return 1;
1634  } else {
1635  $this->error = $this->db->error().' sql='.$sql;
1636  return -1;
1637  }
1638  }
1639 
1640 
1647  public function fetchPartnerships($mode)
1648  {
1649  global $langs;
1650 
1651  require_once DOL_DOCUMENT_ROOT.'/partnership/class/partnership.class.php';
1652 
1653 
1654  $this->partnerships[] = array();
1655 
1656  return 1;
1657  }
1658 
1659 
1675  public function subscription($date, $amount, $accountid = 0, $operation = '', $label = '', $num_chq = '', $emetteur_nom = '', $emetteur_banque = '', $datesubend = 0, $fk_type = null)
1676  {
1677  global $conf, $langs, $user;
1678 
1679  require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
1680 
1681  $error = 0;
1682 
1683  // Clean parameters
1684  if (!$amount) {
1685  $amount = 0;
1686  }
1687 
1688  $this->db->begin();
1689 
1690  if ($datesubend) {
1691  $datefin = $datesubend;
1692  } else {
1693  // If no end date, end date = date + 1 year - 1 day
1694  $datefin = dol_time_plus_duree($date, 1, 'y');
1695  $datefin = dol_time_plus_duree($datefin, -1, 'd');
1696  }
1697 
1698  // Create subscription
1699  $subscription = new Subscription($this->db);
1700  $subscription->fk_adherent = $this->id;
1701  $subscription->dateh = $date; // Date of new subscription
1702  $subscription->datef = $datefin; // End data of new subscription
1703  $subscription->amount = $amount;
1704  $subscription->note = $label; // deprecated
1705  $subscription->note_public = $label;
1706  $subscription->fk_type = $fk_type;
1707 
1708  $rowid = $subscription->create($user);
1709  if ($rowid > 0) {
1710  // Update denormalized subscription end date (read database subscription to find values)
1711  // This will also update this->datefin
1712  $result = $this->update_end_date($user);
1713  if ($result > 0) {
1714  // Change properties of object (used by triggers)
1715  $this->last_subscription_date = dol_now();
1716  $this->last_subscription_date_start = $date;
1717  $this->last_subscription_date_end = $datefin;
1718  $this->last_subscription_amount = $amount;
1719  }
1720 
1721  if (!$error) {
1722  $this->db->commit();
1723  return $rowid;
1724  } else {
1725  $this->db->rollback();
1726  return -2;
1727  }
1728  } else {
1729  $this->setErrorsFromObject($subscription);
1730  $this->db->rollback();
1731  return -1;
1732  }
1733  }
1734 
1735 
1755  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 = '')
1756  {
1757  global $conf, $langs, $user, $mysoc;
1758 
1759  $error = 0;
1760 
1761  $this->invoice = null; // This will contains invoice if an invoice is created
1762 
1763  dol_syslog("subscriptionComplementaryActions subscriptionid=".$subscriptionid." option=".$option." accountid=".$accountid." datesubscription=".$datesubscription." paymentdate=".
1764  $paymentdate." label=".$label." amount=".$amount." num_chq=".$num_chq." autocreatethirdparty=".$autocreatethirdparty);
1765 
1766  // Insert into bank account directlty (if option choosed for) + link to llx_subscription if option is 'bankdirect'
1767  if ($option == 'bankdirect' && $accountid) {
1768  require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
1769 
1770  $acct = new Account($this->db);
1771  $result = $acct->fetch($accountid);
1772 
1773  $dateop = $paymentdate;
1774 
1775  $insertid = $acct->addline($dateop, $operation, $label, $amount, $num_chq, '', $user, $emetteur_nom, $emetteur_banque);
1776  if ($insertid > 0) {
1777  $inserturlid = $acct->add_url_line($insertid, $this->id, DOL_URL_ROOT.'/adherents/card.php?rowid=', $this->getFullname($langs), 'member');
1778  if ($inserturlid > 0) {
1779  // Update table subscription
1780  $sql = "UPDATE ".MAIN_DB_PREFIX."subscription SET fk_bank=".((int) $insertid);
1781  $sql .= " WHERE rowid=".((int) $subscriptionid);
1782 
1783  dol_syslog("subscription::subscription", LOG_DEBUG);
1784  $resql = $this->db->query($sql);
1785  if (!$resql) {
1786  $error++;
1787  $this->error = $this->db->lasterror();
1788  $this->errors[] = $this->error;
1789  }
1790  } else {
1791  $error++;
1792  $this->setErrorsFromObject($acct);
1793  }
1794  } else {
1795  $error++;
1796  $this->setErrorsFromObject($acct);
1797  }
1798  }
1799 
1800  // If option choosed, we create invoice
1801  if (($option == 'bankviainvoice' && $accountid) || $option == 'invoiceonly') {
1802  require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1803  require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/paymentterm.class.php';
1804 
1805  $invoice = new Facture($this->db);
1806  $customer = new Societe($this->db);
1807 
1808  if (!$error) {
1809  if (!($this->fk_soc > 0)) { // If not yet linked to a company
1810  if ($autocreatethirdparty) {
1811  // Create a linked thirdparty to member
1812  $companyalias = '';
1813  $fullname = $this->getFullName($langs);
1814 
1815  if ($this->morphy == 'mor') {
1816  $companyname = $this->company;
1817  if (!empty($fullname)) {
1818  $companyalias = $fullname;
1819  }
1820  } else {
1821  $companyname = $fullname;
1822  if (!empty($this->company)) {
1823  $companyalias = $this->company;
1824  }
1825  }
1826 
1827  $result = $customer->create_from_member($this, $companyname, $companyalias);
1828  if ($result < 0) {
1829  $this->error = $customer->error;
1830  $this->errors = $customer->errors;
1831  $error++;
1832  } else {
1833  $this->fk_soc = $result;
1834  }
1835  } else {
1836  $langs->load("errors");
1837  $this->error = $langs->trans("ErrorMemberNotLinkedToAThirpartyLinkOrCreateFirst");
1838  $this->errors[] = $this->error;
1839  $error++;
1840  }
1841  }
1842  }
1843  if (!$error) {
1844  $result = $customer->fetch($this->fk_soc);
1845  if ($result <= 0) {
1846  $this->error = $customer->error;
1847  $this->errors = $customer->errors;
1848  $error++;
1849  }
1850  }
1851 
1852  if (!$error) {
1853  // Create draft invoice
1854  $invoice->type = Facture::TYPE_STANDARD;
1855  $invoice->cond_reglement_id = $customer->cond_reglement_id;
1856  if (empty($invoice->cond_reglement_id)) {
1857  $paymenttermstatic = new PaymentTerm($this->db);
1858  $invoice->cond_reglement_id = $paymenttermstatic->getDefaultId();
1859  if (empty($invoice->cond_reglement_id)) {
1860  $error++;
1861  $this->error = 'ErrorNoPaymentTermRECEPFound';
1862  $this->errors[] = $this->error;
1863  }
1864  }
1865  $invoice->socid = $this->fk_soc;
1866  //$invoice->date = $datesubscription;
1867  $invoice->date = dol_now();
1868 
1869  // Possibility to add external linked objects with hooks
1870  $invoice->linked_objects['subscription'] = $subscriptionid;
1871  if (!empty($_POST['other_linked_objects']) && is_array($_POST['other_linked_objects'])) {
1872  $invoice->linked_objects = array_merge($invoice->linked_objects, $_POST['other_linked_objects']);
1873  }
1874 
1875  $result = $invoice->create($user);
1876  if ($result <= 0) {
1877  $this->error = $invoice->error;
1878  $this->errors = $invoice->errors;
1879  $error++;
1880  } else {
1881  $this->invoice = $invoice;
1882  }
1883  }
1884 
1885  if (!$error) {
1886  // Add line to draft invoice
1887  $idprodsubscription = 0;
1888  if (!empty($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS) && (isModEnabled("product") || isModEnabled("service"))) {
1889  $idprodsubscription = $conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS;
1890  }
1891 
1892  $vattouse = 0;
1893  if (isset($conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS) && $conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS == 'defaultforfoundationcountry') {
1894  $vattouse = get_default_tva($mysoc, $mysoc, $idprodsubscription);
1895  }
1896  //print xx".$vattouse." - ".$mysoc." - ".$customer;exit;
1897  $result = $invoice->addline($label, 0, 1, $vattouse, 0, 0, $idprodsubscription, 0, $datesubscription, '', 0, 0, '', 'TTC', $amount, 1);
1898  if ($result <= 0) {
1899  $this->error = $invoice->error;
1900  $this->errors = $invoice->errors;
1901  $error++;
1902  }
1903  }
1904 
1905  if (!$error) {
1906  // Validate invoice
1907  $result = $invoice->validate($user);
1908  if ($result <= 0) {
1909  $this->error = $invoice->error;
1910  $this->errors = $invoice->errors;
1911  $error++;
1912  }
1913  }
1914 
1915  if (!$error) {
1916  // TODO Link invoice with subscription ?
1917  }
1918 
1919  // Add payment onto invoice
1920  if (!$error && $option == 'bankviainvoice' && $accountid) {
1921  require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
1922  require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
1923  require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
1924 
1925  $amounts = array();
1926  $amounts[$invoice->id] = price2num($amount);
1927 
1928  $paiement = new Paiement($this->db);
1929  $paiement->datepaye = $paymentdate;
1930  $paiement->amounts = $amounts;
1931  $paiement->paiementcode = $operation;
1932  $paiement->paiementid = dol_getIdFromCode($this->db, $operation, 'c_paiement', 'code', 'id', 1);
1933  $paiement->num_payment = $num_chq;
1934  $paiement->note_public = $label;
1935  $paiement->ext_payment_id = $ext_payment_id;
1936  $paiement->ext_payment_site = $ext_payment_site;
1937 
1938  if (!$error) {
1939  // Create payment line for invoice
1940  $paiement_id = $paiement->create($user);
1941  if (!($paiement_id > 0)) {
1942  $this->error = $paiement->error;
1943  $this->errors = $paiement->errors;
1944  $error++;
1945  }
1946  }
1947 
1948  if (!$error) {
1949  // Add transaction into bank account
1950  $bank_line_id = $paiement->addPaymentToBank($user, 'payment', '(SubscriptionPayment)', $accountid, $emetteur_nom, $emetteur_banque);
1951  if (!($bank_line_id > 0)) {
1952  $this->error = $paiement->error;
1953  $this->errors = $paiement->errors;
1954  $error++;
1955  }
1956  }
1957 
1958  if (!$error && !empty($bank_line_id)) {
1959  // Update fk_bank into subscription table
1960  $sql = 'UPDATE '.MAIN_DB_PREFIX.'subscription SET fk_bank='.((int) $bank_line_id);
1961  $sql .= ' WHERE rowid='.((int) $subscriptionid);
1962 
1963  $result = $this->db->query($sql);
1964  if (!$result) {
1965  $error++;
1966  }
1967  }
1968 
1969  if (!$error) {
1970  // Set invoice as paid
1971  $invoice->setPaid($user);
1972  }
1973  }
1974 
1975  if (!$error) {
1976  // Define output language
1977  $outputlangs = $langs;
1978  $newlang = '';
1979  $lang_id = GETPOST('lang_id');
1980  if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && !empty($lang_id)) {
1981  $newlang = $lang_id;
1982  }
1983  if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
1984  $newlang = $customer->default_lang;
1985  }
1986  if (!empty($newlang)) {
1987  $outputlangs = new Translate("", $conf);
1988  $outputlangs->setDefaultLang($newlang);
1989  }
1990  // Generate PDF (whatever is option MAIN_DISABLE_PDF_AUTOUPDATE) so we can include it into email
1991  //if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
1992 
1993  $invoice->generateDocument($invoice->model_pdf, $outputlangs);
1994  }
1995  }
1996 
1997  if ($error) {
1998  return -1;
1999  } else {
2000  return 1;
2001  }
2002  }
2003 
2004 
2011  public function validate($user)
2012  {
2013  global $langs, $conf;
2014 
2015  $error = 0;
2016  $now = dol_now();
2017 
2018  // Check parameters
2019  if ($this->statut == self::STATUS_VALIDATED) {
2020  dol_syslog(get_class($this)."::validate statut of member does not allow this", LOG_WARNING);
2021  return 0;
2022  }
2023 
2024  $this->db->begin();
2025 
2026  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
2027  $sql .= " statut = ".self::STATUS_VALIDATED;
2028  $sql .= ", datevalid = '".$this->db->idate($now)."'";
2029  $sql .= ", fk_user_valid = ".((int) $user->id);
2030  $sql .= " WHERE rowid = ".((int) $this->id);
2031 
2032  dol_syslog(get_class($this)."::validate", LOG_DEBUG);
2033  $result = $this->db->query($sql);
2034  if ($result) {
2035  $this->statut = self::STATUS_VALIDATED;
2036 
2037  // Call trigger
2038  $result = $this->call_trigger('MEMBER_VALIDATE', $user);
2039  if ($result < 0) {
2040  $error++;
2041  $this->db->rollback();
2042  return -1;
2043  }
2044  // End call triggers
2045 
2046  $this->datevalid = $now;
2047 
2048  $this->db->commit();
2049  return 1;
2050  } else {
2051  $this->error = $this->db->error();
2052  $this->db->rollback();
2053  return -1;
2054  }
2055  }
2056 
2057 
2064  public function resiliate($user)
2065  {
2066  global $langs, $conf;
2067 
2068  $error = 0;
2069 
2070  // Check parameters
2071  if ($this->statut == self::STATUS_RESILIATED) {
2072  dol_syslog(get_class($this)."::resiliate statut of member does not allow this", LOG_WARNING);
2073  return 0;
2074  }
2075 
2076  $this->db->begin();
2077 
2078  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
2079  $sql .= " statut = ".self::STATUS_RESILIATED;
2080  $sql .= ", fk_user_valid=".$user->id;
2081  $sql .= " WHERE rowid = ".((int) $this->id);
2082 
2083  $result = $this->db->query($sql);
2084  if ($result) {
2085  $this->statut = self::STATUS_RESILIATED;
2086 
2087  // Call trigger
2088  $result = $this->call_trigger('MEMBER_RESILIATE', $user);
2089  if ($result < 0) {
2090  $error++;
2091  $this->db->rollback();
2092  return -1;
2093  }
2094  // End call triggers
2095 
2096  $this->db->commit();
2097  return 1;
2098  } else {
2099  $this->error = $this->db->error();
2100  $this->db->rollback();
2101  return -1;
2102  }
2103  }
2104 
2114  public function exclude($user)
2115  {
2116  global $langs, $conf;
2117 
2118  $error = 0;
2119 
2120  // Check parameters
2121  if ($this->statut == self::STATUS_EXCLUDED) {
2122  dol_syslog(get_class($this)."::resiliate statut of member does not allow this", LOG_WARNING);
2123  return 0;
2124  }
2125 
2126  $this->db->begin();
2127 
2128  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
2129  $sql .= " statut = ".self::STATUS_EXCLUDED;
2130  $sql .= ", fk_user_valid=".$user->id;
2131  $sql .= " WHERE rowid = ".((int) $this->id);
2132 
2133  $result = $this->db->query($sql);
2134  if ($result) {
2135  $this->statut = self::STATUS_EXCLUDED;
2136 
2137  // Call trigger
2138  $result = $this->call_trigger('MEMBER_EXCLUDE', $user);
2139  if ($result < 0) {
2140  $error++;
2141  $this->db->rollback();
2142  return -1;
2143  }
2144  // End call triggers
2145 
2146  $this->db->commit();
2147  return 1;
2148  } else {
2149  $this->error = $this->db->error();
2150  $this->db->rollback();
2151  return -1;
2152  }
2153  }
2154 
2155  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2161  public function add_to_abo()
2162  {
2163  // phpcs:enable
2164  global $conf, $langs;
2165 
2166  include_once DOL_DOCUMENT_ROOT.'/mailmanspip/class/mailmanspip.class.php';
2167  $mailmanspip = new MailmanSpip($this->db);
2168 
2169  $err = 0;
2170 
2171  // mailman
2172  if (!empty($conf->global->ADHERENT_USE_MAILMAN) && isModEnabled('mailmanspip')) {
2173  $result = $mailmanspip->add_to_mailman($this);
2174 
2175  if ($result < 0) {
2176  if (!empty($mailmanspip->error)) {
2177  $this->errors[] = $mailmanspip->error;
2178  }
2179  $err += 1;
2180  }
2181  foreach ($mailmanspip->mladded_ko as $tmplist => $tmpemail) {
2182  $langs->load("errors");
2183  $this->errors[] = $langs->trans("ErrorFailedToAddToMailmanList", $tmpemail, $tmplist);
2184  }
2185  foreach ($mailmanspip->mladded_ok as $tmplist => $tmpemail) {
2186  $langs->load("mailmanspip");
2187  $this->mesgs[] = $langs->trans("SuccessToAddToMailmanList", $tmpemail, $tmplist);
2188  }
2189  }
2190 
2191  // spip
2192  if (!empty($conf->global->ADHERENT_USE_SPIP) && isModEnabled('mailmanspip')) {
2193  $result = $mailmanspip->add_to_spip($this);
2194  if ($result < 0) {
2195  $this->errors[] = $mailmanspip->error;
2196  $err += 1;
2197  }
2198  }
2199  if ($err) {
2200  return -$err;
2201  } else {
2202  return 1;
2203  }
2204  }
2205 
2206 
2207  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2213  public function del_to_abo()
2214  {
2215  // phpcs:enable
2216  global $conf, $langs;
2217 
2218  include_once DOL_DOCUMENT_ROOT.'/mailmanspip/class/mailmanspip.class.php';
2219  $mailmanspip = new MailmanSpip($this->db);
2220 
2221  $err = 0;
2222 
2223  // mailman
2224  if (!empty($conf->global->ADHERENT_USE_MAILMAN)) {
2225  $result = $mailmanspip->del_to_mailman($this);
2226  if ($result < 0) {
2227  if (!empty($mailmanspip->error)) {
2228  $this->errors[] = $mailmanspip->error;
2229  }
2230  $err += 1;
2231  }
2232 
2233  foreach ($mailmanspip->mlremoved_ko as $tmplist => $tmpemail) {
2234  $langs->load("errors");
2235  $this->errors[] = $langs->trans("ErrorFailedToRemoveToMailmanList", $tmpemail, $tmplist);
2236  }
2237  foreach ($mailmanspip->mlremoved_ok as $tmplist => $tmpemail) {
2238  $langs->load("mailmanspip");
2239  $this->mesgs[] = $langs->trans("SuccessToRemoveToMailmanList", $tmpemail, $tmplist);
2240  }
2241  }
2242 
2243  if ($conf->global->ADHERENT_USE_SPIP && isModEnabled('mailmanspip')) {
2244  $result = $mailmanspip->del_to_spip($this);
2245  if ($result < 0) {
2246  $this->errors[] = $mailmanspip->error;
2247  $err += 1;
2248  }
2249  }
2250  if ($err) {
2251  // error
2252  return -$err;
2253  } else {
2254  return 1;
2255  }
2256  }
2257 
2258 
2264  public function getCivilityLabel()
2265  {
2266  global $langs;
2267  $langs->load("dict");
2268 
2269  $code = (empty($this->civility_id) ? '' : $this->civility_id);
2270  if (empty($code)) {
2271  return '';
2272  }
2273  return $langs->getLabelFromKey($this->db, "Civility".$code, "c_civility", "code", "label", $code);
2274  }
2275 
2282  public function getTooltipContentArray($params)
2283  {
2284  global $conf, $langs;
2285 
2286  $langs->loadLangs(['members', 'companies']);
2287  $nofetch = !empty($params['nofetch']);
2288 
2289  $datas = array();
2290 
2291  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2292  $langs->load("users");
2293  return ['optimize' => $langs->trans("ShowUser")];
2294  }
2295  if (!empty($this->photo)) {
2296  $photo = '<div class="photointooltip floatright">';
2297  $photo .= Form::showphoto('memberphoto', $this, 80, 0, 0, 'photoref photowithmargin photologintooltip', 'small', 0, 1);
2298  $photo .= '</div>';
2299  $datas['photo'] = $photo;
2300  }
2301 
2302  $datas['divopen'] = '<div class="centpercent">';
2303  $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Member").'</u> '.$this->getLibStatut(4);
2304  if (!empty($this->morphy)) {
2305  $datas['picto'] .= '&nbsp;' . $this->getmorphylib('', 1);
2306  }
2307  if (!empty($this->ref)) {
2308  $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
2309  }
2310  if (!empty($this->login)) {
2311  $datas['login'] = '<br><b>'.$langs->trans('Login').':</b> '.$this->login;
2312  }
2313  if (!empty($this->firstname) || !empty($this->lastname)) {
2314  $datas['name'] = '<br><b>'.$langs->trans('Name').':</b> '.$this->getFullName($langs);
2315  }
2316  if (!empty($this->company)) {
2317  $datas['company'] = '<br><b>'.$langs->trans('Company').':</b> '.$this->company;
2318  }
2319  if (!empty($this->email)) {
2320  $datas['email'] = '<br><b>'.$langs->trans("EMail").':</b> '.$this->email;
2321  }
2322  $datas['address'] = '<br><b>'.$langs->trans("Address").':</b> '.dol_format_address($this, 1, ' ', $langs);
2323  // show categories for this record only in ajax to not overload lists
2324  if (isModEnabled('categorie') && !$nofetch) {
2325  require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
2326  $form = new Form($this->db);
2327  $datas['categories'] = '<br>' . $form->showCategories($this->id, Categorie::TYPE_MEMBER, 1);
2328  }
2329  $datas['divclose'] = '</div>';
2330 
2331  return $datas;
2332  }
2333 
2347  public function getNomUrl($withpictoimg = 0, $maxlen = 0, $option = 'card', $mode = '', $morecss = '', $save_lastsearch_value = -1, $notooltip = 0, $addlinktonotes = 0)
2348  {
2349  global $conf, $langs, $hookmanager;
2350 
2351  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpictoimg) {
2352  $withpictoimg = 0;
2353  }
2354 
2355  $result = '';
2356  $linkstart = '';
2357  $linkend = '';
2358  $classfortooltip = 'classfortooltip';
2359  $dataparams = '';
2360  $params = [
2361  'id' => $this->id,
2362  'objecttype' => $this->element,
2363  'option' => $option,
2364  'nofetch' => 1,
2365  ];
2366  if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
2367  $classfortooltip = 'classforajaxtooltip';
2368  $dataparams = ' data-params='.json_encode($params);
2369  // $label = $langs->trans('Loading');
2370  }
2371  $label = implode($this->getTooltipContentArray($params));
2372 
2373  $url = DOL_URL_ROOT.'/adherents/card.php?rowid='.((int) $this->id);
2374  if ($option == 'subscription') {
2375  $url = DOL_URL_ROOT.'/adherents/subscription.php?rowid='.((int) $this->id);
2376  }
2377 
2378  if ($option != 'nolink') {
2379  // Add param to save lastsearch_values or not
2380  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2381  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
2382  $add_save_lastsearch_values = 1;
2383  }
2384  if ($add_save_lastsearch_values) {
2385  $url .= '&save_lastsearch_values=1';
2386  }
2387  }
2388 
2389  $linkstart .= '<a href="'.$url.'"';
2390  $linkclose = "";
2391  if (empty($notooltip)) {
2392  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2393  $langs->load("users");
2394  $label = $langs->trans("ShowUser");
2395  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
2396  }
2397  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
2398  $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
2399  }
2400 
2401  $linkstart .= $linkclose.'>';
2402  $linkend = '</a>';
2403 
2404  $result .= $linkstart;
2405  if ($withpictoimg) {
2406  $result .= '<div class="inline-block nopadding valignmiddle">';
2407  }
2408  if ($withpictoimg) {
2409  $paddafterimage = '';
2410  if (abs($withpictoimg) == 1) {
2411  $morecss .= ' paddingrightonly';
2412  }
2413  // Only picto
2414  if ($withpictoimg > 0) {
2415  $picto = '<span class="nopadding'.($morecss ? ' userimg'.$morecss : '').'">'.
2416  img_object('', 'user', $paddafterimage.' '.($notooltip ? '' : $dataparams.' class="'.$classfortooltip.'"'), 0, 0, $notooltip ? 0 : 1).'</span>';
2417  } else {
2418  // Picto must be a photo
2419  $picto = '<span class="nopadding'.($morecss ? ' userimg'.$morecss : '').'"'.($paddafterimage ? ' '.$paddafterimage : '').'>';
2420  $picto .= Form::showphoto('memberphoto', $this, 0, 0, 0, 'userphoto'.($withpictoimg == -3 ? 'small' : ''), 'mini', 0, 1);
2421  $picto .= '</span>';
2422  }
2423  $result .= $picto;
2424  }
2425  if ($withpictoimg > -2 && $withpictoimg != 2) {
2426  if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2427  $result .= '<span class="nopadding valignmiddle'.((!isset($this->statut) || $this->statut) ? '' : ' strikefordisabled').
2428  ($morecss ? ' usertext'.$morecss : '').'">';
2429  }
2430  if ($mode == 'login') {
2431  $result .= dol_trunc($this->login, $maxlen);
2432  } elseif ($mode == 'ref') {
2433  $result .= $this->ref;
2434  } else {
2435  $result .= $this->getFullName($langs, '', ($mode == 'firstname' ? 2 : ($mode == 'lastname' ? 4 : -1)), $maxlen);
2436  }
2437  if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2438  $result .= '</span>';
2439  }
2440  }
2441  if ($withpictoimg) {
2442  $result .= '</div>';
2443  }
2444  $result .= $linkend;
2445 
2446  if ($addlinktonotes) {
2447  if ($this->note_private) {
2448  $notetoshow = $langs->trans("ViewPrivateNote").':<br>'.dol_string_nohtmltag($this->note_private, 1);
2449  $result .= ' <span class="note inline-block">';
2450  $result .= '<a href="'.DOL_URL_ROOT.'/adherents/note.php?id='.$this->id.'" class="classfortooltip" title="'.dol_escape_htmltag($notetoshow).'">';
2451  $result .= img_picto('', 'note');
2452  $result .= '</a>';
2453  $result .= '</span>';
2454  }
2455  }
2456  global $action;
2457  $hookmanager->initHooks(array($this->element . 'dao'));
2458  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
2459  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
2460  if ($reshook > 0) {
2461  $result = $hookmanager->resPrint;
2462  } else {
2463  $result .= $hookmanager->resPrint;
2464  }
2465  return $result;
2466  }
2467 
2474  public function getLibStatut($mode = 0)
2475  {
2476  return $this->LibStatut($this->statut, $this->need_subscription, $this->datefin, $mode);
2477  }
2478 
2479  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2489  public function LibStatut($status, $need_subscription, $date_end_subscription, $mode = 0)
2490  {
2491  // phpcs:enable
2492  global $langs;
2493  $langs->load("members");
2494 
2495  $statusType = '';
2496  $labelStatus = '';
2497  $labelStatusShort = '';
2498 
2499  if ($status == self::STATUS_DRAFT) {
2500  $statusType = 'status0';
2501  $labelStatus = $langs->trans("MemberStatusDraft");
2502  $labelStatusShort = $langs->trans("MemberStatusDraftShort");
2503  } elseif ($status >= self::STATUS_VALIDATED) {
2504  if ($need_subscription === 0) {
2505  $statusType = 'status4';
2506  $labelStatus = $langs->trans("MemberStatusNoSubscription");
2507  $labelStatusShort = $langs->trans("MemberStatusNoSubscriptionShort");
2508  } elseif (!$date_end_subscription) {
2509  $statusType = 'status1';
2510  $labelStatus = $langs->trans("MemberStatusActive");
2511  $labelStatusShort = $langs->trans("MemberStatusActiveShort");
2512  } elseif ($date_end_subscription < dol_now()) { // expired
2513  $statusType = 'status8';
2514  $labelStatus = $langs->trans("MemberStatusActiveLate");
2515  $labelStatusShort = $langs->trans("MemberStatusActiveLateShort");
2516  } else {
2517  $statusType = 'status4';
2518  $labelStatus = $langs->trans("MemberStatusPaid");
2519  $labelStatusShort = $langs->trans("MemberStatusPaidShort");
2520  }
2521  } elseif ($status == self::STATUS_RESILIATED) {
2522  $statusType = 'status6';
2523  $labelStatus = $langs->transnoentitiesnoconv("MemberStatusResiliated");
2524  $labelStatusShort = $langs->transnoentitiesnoconv("MemberStatusResiliatedShort");
2525  } elseif ($status == self::STATUS_EXCLUDED) {
2526  $statusType = 'status10';
2527  $labelStatus = $langs->transnoentitiesnoconv("MemberStatusExcluded");
2528  $labelStatusShort = $langs->transnoentitiesnoconv("MemberStatusExcludedShort");
2529  }
2530 
2531  return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode);
2532  }
2533 
2534 
2535  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2541  public function load_state_board()
2542  {
2543  // phpcs:enable
2544  global $conf;
2545 
2546  $this->nb = array();
2547 
2548  $sql = "SELECT count(a.rowid) as nb";
2549  $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a";
2550  $sql .= " WHERE a.statut > 0";
2551  $sql .= " AND a.entity IN (".getEntity('adherent').")";
2552 
2553  $resql = $this->db->query($sql);
2554  if ($resql) {
2555  while ($obj = $this->db->fetch_object($resql)) {
2556  $this->nb["members"] = $obj->nb;
2557  }
2558  $this->db->free($resql);
2559  return 1;
2560  } else {
2561  dol_print_error($this->db);
2562  $this->error = $this->db->error();
2563  return -1;
2564  }
2565  }
2566 
2567  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2575  public function load_board($user, $mode)
2576  {
2577  // phpcs:enable
2578  global $conf, $langs;
2579 
2580  if ($user->socid) {
2581  return -1; // protection pour eviter appel par utilisateur externe
2582  }
2583 
2584  $now = dol_now();
2585 
2586  $sql = "SELECT a.rowid, a.datefin, a.statut";
2587  $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a";
2588  $sql .= ", ".MAIN_DB_PREFIX."adherent_type as t";
2589  $sql .= " WHERE a.fk_adherent_type = t.rowid";
2590  if ($mode == 'expired') {
2591  $sql .= " AND a.statut = ".self::STATUS_VALIDATED;
2592  $sql .= " AND a.entity IN (".getEntity('adherent').")";
2593  $sql .= " AND ((a.datefin IS NULL or a.datefin < '".$this->db->idate($now)."') AND t.subscription = '1')";
2594  } elseif ($mode == 'shift') {
2595  $sql .= " AND a.statut = ".self::STATUS_DRAFT;
2596  $sql .= " AND a.entity IN (".getEntity('adherent').")";
2597  }
2598 
2599  $resql = $this->db->query($sql);
2600  if ($resql) {
2601  $langs->load("members");
2602 
2603  $warning_delay = 0;
2604  $url = '';
2605  $label = '';
2606  $labelShort = '';
2607 
2608  if ($mode == 'expired') {
2609  $warning_delay = $conf->adherent->subscription->warning_delay / 60 / 60 / 24;
2610  $label = $langs->trans("MembersWithSubscriptionToReceive");
2611  $labelShort = $langs->trans("MembersWithSubscriptionToReceiveShort");
2612  $url = DOL_URL_ROOT.'/adherents/list.php?mainmenu=members&amp;statut='.self::STATUS_VALIDATED.'&amp;filter=outofdate';
2613  } elseif ($mode == 'shift') {
2614  $warning_delay = $conf->adherent->subscription->warning_delay / 60 / 60 / 24;
2615  $url = DOL_URL_ROOT.'/adherents/list.php?mainmenu=members&amp;statut='.self::STATUS_DRAFT;
2616  $label = $langs->trans("MembersListToValid");
2617  $labelShort = $langs->trans("ToValidate");
2618  }
2619 
2620  $response = new WorkboardResponse();
2621  $response->warning_delay = $warning_delay;
2622  $response->label = $label;
2623  $response->labelShort = $labelShort;
2624  $response->url = $url;
2625  $response->img = img_object('', "user");
2626 
2627  $adherentstatic = new Adherent($this->db);
2628 
2629  while ($obj = $this->db->fetch_object($resql)) {
2630  $response->nbtodo++;
2631 
2632  $adherentstatic->datefin = $this->db->jdate($obj->datefin);
2633  $adherentstatic->statut = $obj->statut;
2634 
2635  if ($adherentstatic->hasDelay()) {
2636  $response->nbtodolate++;
2637  }
2638  }
2639 
2640  return $response;
2641  } else {
2642  dol_print_error($this->db);
2643  $this->error = $this->db->error();
2644  return -1;
2645  }
2646  }
2647 
2648 
2660  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
2661  {
2662  global $conf, $langs;
2663 
2664  $langs->load("orders");
2665 
2666  if (!dol_strlen($modele)) {
2667  $modele = 'standard';
2668 
2669  if ($this->model_pdf) {
2670  $modele = $this->model_pdf;
2671  } elseif (!empty($conf->global->ADHERENT_ADDON_PDF)) {
2672  $modele = $conf->global->ADHERENT_ADDON_PDF;
2673  }
2674  }
2675 
2676  $modelpath = "core/modules/member/doc/";
2677 
2678  return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
2679  }
2680 
2681 
2689  public function initAsSpecimen()
2690  {
2691  global $user, $langs;
2692  $now = dol_now();
2693 
2694  // Initialise parametres
2695  $this->id = 0;
2696  $this->ref = 'ABC001';
2697  $this->entity = 1;
2698  $this->specimen = 1;
2699  $this->civility_id = 0;
2700  $this->lastname = 'DOLIBARR';
2701  $this->firstname = 'SPECIMEN';
2702  $this->gender = 'man';
2703  $this->login = 'dolibspec';
2704  $this->pass = 'dolibspec';
2705  $this->company = 'Societe ABC';
2706  $this->address = '61 jump street';
2707  $this->zip = '75000';
2708  $this->town = 'Paris';
2709  $this->country_id = 1;
2710  $this->country_code = 'FR';
2711  $this->country = 'France';
2712  $this->morphy = 'mor';
2713  $this->email = 'specimen@specimen.com';
2714  $this->socialnetworks = array(
2715  'skype' => 'skypepseudo',
2716  'twitter' => 'twitterpseudo',
2717  'facebook' => 'facebookpseudo',
2718  'linkedin' => 'linkedinpseudo',
2719  );
2720  $this->phone = '0999999999';
2721  $this->phone_perso = '0999999998';
2722  $this->phone_mobile = '0999999997';
2723  $this->note_public = 'This is a public note';
2724  $this->note_private = 'This is a private note';
2725  $this->birth = $now;
2726  $this->photo = '';
2727  $this->public = 1;
2728  $this->statut = self::STATUS_DRAFT;
2729 
2730  $this->datefin = $now;
2731  $this->datevalid = $now;
2732  $this->default_lang = '';
2733 
2734  $this->typeid = 1; // Id type adherent
2735  $this->type = 'Type adherent'; // Libelle type adherent
2736  $this->need_subscription = 0;
2737 
2738  $this->first_subscription_date = $now;
2739  $this->first_subscription_date_start = $this->first_subscription_date;
2740  $this->first_subscription_date_end = dol_time_plus_duree($this->first_subscription_date_start, 1, 'y');
2741  $this->first_subscription_amount = 10;
2742 
2743  $this->last_subscription_date = $this->first_subscription_date;
2744  $this->last_subscription_date_start = $this->first_subscription_date;
2745  $this->last_subscription_date_end = dol_time_plus_duree($this->last_subscription_date_start, 1, 'y');
2746  $this->last_subscription_amount = 10;
2747  return 1;
2748  }
2749 
2750 
2751  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2752  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2762  public function _load_ldap_dn($info, $mode = 0)
2763  {
2764  // phpcs:enable
2765  global $conf;
2766  $dn = '';
2767  if ($mode == 0) {
2768  $dn = $conf->global->LDAP_KEY_MEMBERS."=".$info[$conf->global->LDAP_KEY_MEMBERS].",".$conf->global->LDAP_MEMBER_DN;
2769  }
2770  if ($mode == 1) {
2771  $dn = $conf->global->LDAP_MEMBER_DN;
2772  }
2773  if ($mode == 2) {
2774  $dn = $conf->global->LDAP_KEY_MEMBERS."=".$info[$conf->global->LDAP_KEY_MEMBERS];
2775  }
2776  return $dn;
2777  }
2778 
2779 
2780  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2781  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2787  public function _load_ldap_info()
2788  {
2789  // phpcs:enable
2790  global $conf, $langs;
2791 
2792  $info = array();
2793  $socialnetworks = getArrayOfSocialNetworks();
2794  $keymodified = false;
2795 
2796  // Object classes
2797  $info["objectclass"] = explode(',', $conf->global->LDAP_MEMBER_OBJECT_CLASS);
2798 
2799  $this->fullname = $this->getFullName($langs);
2800 
2801  // For avoid ldap error when firstname and lastname are empty
2802  if ($this->morphy == 'mor' && (empty($this->fullname) || $this->fullname == $this->company)) {
2803  $this->fullname = $this->company;
2804  $this->lastname = $this->company;
2805  }
2806 
2807  // Possible LDAP KEY (constname => varname)
2808  $ldapkey = array(
2809  'LDAP_MEMBER_FIELD_FULLNAME' => 'fullname',
2810  'LDAP_MEMBER_FIELD_NAME' => 'lastname',
2811  'LDAP_MEMBER_FIELD_LOGIN' => 'login',
2812  'LDAP_MEMBER_FIELD_LOGIN_SAMBA' => 'login',
2813  'LDAP_MEMBER_FIELD_MAIL' => 'email'
2814  );
2815 
2816  // Member
2817  foreach ($ldapkey as $constname => $varname) {
2818  if (!empty($this->$varname) && !empty($conf->global->$constname)) {
2819  $info[$conf->global->$constname] = $this->$varname;
2820 
2821  // Check if it is the LDAP key and if its value has been changed
2822  if (!empty($conf->global->LDAP_KEY_MEMBERS) && $conf->global->LDAP_KEY_MEMBERS == $conf->global->$constname) {
2823  if (!empty($this->oldcopy) && $this->$varname != $this->oldcopy->$varname) {
2824  $keymodified = true; // For check if LDAP key has been modified
2825  }
2826  }
2827  }
2828  }
2829  if ($this->firstname && !empty($conf->global->LDAP_MEMBER_FIELD_FIRSTNAME)) {
2830  $info[$conf->global->LDAP_MEMBER_FIELD_FIRSTNAME] = $this->firstname;
2831  }
2832  if ($this->poste && !empty($conf->global->LDAP_MEMBER_FIELD_TITLE)) {
2833  $info[$conf->global->LDAP_MEMBER_FIELD_TITLE] = $this->poste;
2834  }
2835  if ($this->company && !empty($conf->global->LDAP_MEMBER_FIELD_COMPANY)) {
2836  $info[$conf->global->LDAP_MEMBER_FIELD_COMPANY] = $this->company;
2837  }
2838  if ($this->address && !empty($conf->global->LDAP_MEMBER_FIELD_ADDRESS)) {
2839  $info[$conf->global->LDAP_MEMBER_FIELD_ADDRESS] = $this->address;
2840  }
2841  if ($this->zip && !empty($conf->global->LDAP_MEMBER_FIELD_ZIP)) {
2842  $info[$conf->global->LDAP_MEMBER_FIELD_ZIP] = $this->zip;
2843  }
2844  if ($this->town && !empty($conf->global->LDAP_MEMBER_FIELD_TOWN)) {
2845  $info[$conf->global->LDAP_MEMBER_FIELD_TOWN] = $this->town;
2846  }
2847  if ($this->country_code && !empty($conf->global->LDAP_MEMBER_FIELD_COUNTRY)) {
2848  $info[$conf->global->LDAP_MEMBER_FIELD_COUNTRY] = $this->country_code;
2849  }
2850  foreach ($socialnetworks as $key => $value) {
2851  if ($this->socialnetworks[$value['label']] && !empty($conf->global->{'LDAP_MEMBER_FIELD_'.strtoupper($value['label'])})) {
2852  $info[$conf->global->{'LDAP_MEMBER_FIELD_'.strtoupper($value['label'])}] = $this->socialnetworks[$value['label']];
2853  }
2854  }
2855  if ($this->phone && !empty($conf->global->LDAP_MEMBER_FIELD_PHONE)) {
2856  $info[$conf->global->LDAP_MEMBER_FIELD_PHONE] = $this->phone;
2857  }
2858  if ($this->phone_perso && !empty($conf->global->LDAP_MEMBER_FIELD_PHONE_PERSO)) {
2859  $info[$conf->global->LDAP_MEMBER_FIELD_PHONE_PERSO] = $this->phone_perso;
2860  }
2861  if ($this->phone_mobile && !empty($conf->global->LDAP_MEMBER_FIELD_MOBILE)) {
2862  $info[$conf->global->LDAP_MEMBER_FIELD_MOBILE] = $this->phone_mobile;
2863  }
2864  if ($this->fax && !empty($conf->global->LDAP_MEMBER_FIELD_FAX)) {
2865  $info[$conf->global->LDAP_MEMBER_FIELD_FAX] = $this->fax;
2866  }
2867  if ($this->note_private && !empty($conf->global->LDAP_MEMBER_FIELD_DESCRIPTION)) {
2868  $info[$conf->global->LDAP_MEMBER_FIELD_DESCRIPTION] = dol_string_nohtmltag($this->note_private, 2);
2869  }
2870  if ($this->note_public && !empty($conf->global->LDAP_MEMBER_FIELD_NOTE_PUBLIC)) {
2871  $info[$conf->global->LDAP_MEMBER_FIELD_NOTE_PUBLIC] = dol_string_nohtmltag($this->note_public, 2);
2872  }
2873  if ($this->birth && !empty($conf->global->LDAP_MEMBER_FIELD_BIRTHDATE)) {
2874  $info[$conf->global->LDAP_MEMBER_FIELD_BIRTHDATE] = dol_print_date($this->birth, 'dayhourldap');
2875  }
2876  if (isset($this->statut) && !empty($conf->global->LDAP_FIELD_MEMBER_STATUS)) {
2877  $info[$conf->global->LDAP_FIELD_MEMBER_STATUS] = $this->statut;
2878  }
2879  if ($this->datefin && !empty($conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION)) {
2880  $info[$conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION] = dol_print_date($this->datefin, 'dayhourldap');
2881  }
2882 
2883  // When password is modified
2884  if (!empty($this->pass)) {
2885  if (!empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD)) {
2886  $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD] = $this->pass; // this->pass = mot de passe non crypte
2887  }
2888  if (!empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED)) {
2889  $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED] = dol_hash($this->pass, 'openldap'); // Create OpenLDAP password (see LDAP_PASSWORD_HASH_TYPE)
2890  }
2891  } elseif ($conf->global->LDAP_SERVER_PROTOCOLVERSION !== '3') {
2892  // Set LDAP password if possible
2893  // If ldap key is modified and LDAPv3 we use ldap_rename function for avoid lose encrypt password
2894  if (!empty($conf->global->DATABASE_PWD_ENCRYPTED)) {
2895  // Just for the default MD5 !
2896  if (empty($conf->global->MAIN_SECURITY_HASH_ALGO)) {
2897  if ($this->pass_indatabase_crypted && !empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED)) {
2898  // Create OpenLDAP MD5 password from Dolibarr MD5 password
2899  // Note: This suppose that "pass_indatabase_crypted" is a md5 (guaranted by the previous test if "(empty($conf->global->MAIN_SECURITY_HASH_ALGO))"
2900  $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED] = dolGetLdapPasswordHash($this->pass_indatabase_crypted, 'md5frommd5');
2901  }
2902  }
2903  } elseif (!empty($this->pass_indatabase)) {
2904  // Use $this->pass_indatabase value if exists
2905  if (!empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD)) {
2906  $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD] = $this->pass_indatabase; // $this->pass_indatabase = mot de passe non crypte
2907  }
2908  if (!empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED)) {
2909  $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED] = dol_hash($this->pass_indatabase, 'openldap'); // Create OpenLDAP password (see LDAP_PASSWORD_HASH_TYPE)
2910  }
2911  }
2912  }
2913 
2914  // Subscriptions
2915  if ($this->first_subscription_date && !empty($conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE)) {
2916  $info[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE] = dol_print_date($this->first_subscription_date, 'dayhourldap');
2917  }
2918  if (isset($this->first_subscription_amount) && !empty($conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT)) {
2919  $info[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT] = $this->first_subscription_amount;
2920  }
2921  if ($this->last_subscription_date && !empty($conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE)) {
2922  $info[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE] = dol_print_date($this->last_subscription_date, 'dayhourldap');
2923  }
2924  if (isset($this->last_subscription_amount) && !empty($conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT)) {
2925  $info[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT] = $this->last_subscription_amount;
2926  }
2927 
2928  return $info;
2929  }
2930 
2931 
2938  public function info($id)
2939  {
2940  $sql = 'SELECT a.rowid, a.datec as datec,';
2941  $sql .= ' a.datevalid as datev,';
2942  $sql .= ' a.tms as datem,';
2943  $sql .= ' a.fk_user_author, a.fk_user_valid, a.fk_user_mod';
2944  $sql .= ' FROM '.MAIN_DB_PREFIX.'adherent as a';
2945  $sql .= ' WHERE a.rowid = '.((int) $id);
2946 
2947  dol_syslog(get_class($this)."::info", LOG_DEBUG);
2948  $result = $this->db->query($sql);
2949  if ($result) {
2950  if ($this->db->num_rows($result)) {
2951  $obj = $this->db->fetch_object($result);
2952  $this->id = $obj->rowid;
2953 
2954  $this->user_creation_id = $obj->fk_user_author;
2955  $this->user_validation_id = $obj->fk_user_valid;
2956  $this->user_modification_id = $obj->fk_user_mod;
2957  $this->date_creation = $this->db->jdate($obj->datec);
2958  $this->date_validation = $this->db->jdate($obj->datev);
2959  $this->date_modification = $this->db->jdate($obj->datem);
2960  }
2961 
2962  $this->db->free($result);
2963  } else {
2964  dol_print_error($this->db);
2965  }
2966  }
2967 
2973  public function getNbOfEMailings()
2974  {
2975  $sql = "SELECT count(mc.email) as nb";
2976  $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
2977  $sql .= " WHERE mc.email = '".$this->db->escape($this->email)."'";
2978  $sql .= " AND mc.statut NOT IN (-1,0)"; // -1 erreur, 0 non envoye, 1 envoye avec succes
2979 
2980  $resql = $this->db->query($sql);
2981  if ($resql) {
2982  $obj = $this->db->fetch_object($resql);
2983  $nb = $obj->nb;
2984 
2985  $this->db->free($resql);
2986  return $nb;
2987  } else {
2988  $this->error = $this->db->error();
2989  return -1;
2990  }
2991  }
2992 
3003  public function setCategories($categories)
3004  {
3005  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
3006  return parent::setCategoriesCommon($categories, Categorie::TYPE_MEMBER);
3007  }
3008 
3017  public static function replaceThirdparty($db, $origin_id, $dest_id)
3018  {
3019  $tables = array('adherent');
3020 
3021  return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
3022  }
3023 
3029  public function hasDelay()
3030  {
3031  global $conf;
3032 
3033  //Only valid members
3034  if ($this->statut != self::STATUS_VALIDATED) {
3035  return false;
3036  }
3037  if (!$this->datefin) {
3038  return false;
3039  }
3040 
3041  $now = dol_now();
3042 
3043  return $this->datefin < ($now - $conf->adherent->subscription->warning_delay);
3044  }
3045 
3046 
3054  public function sendReminderForExpiredSubscription($daysbeforeendlist = '10')
3055  {
3056  global $conf, $langs, $mysoc, $user;
3057 
3058  $error = 0;
3059  $this->output = '';
3060  $this->error = '';
3061 
3062  $blockingerrormsg = '';
3063 
3064  if (empty($conf->adherent->enabled)) { // Should not happen. If module disabled, cron job should not be visible.
3065  $langs->load("agenda");
3066  $this->output = $langs->trans('ModuleNotEnabled', $langs->transnoentitiesnoconv("Adherent"));
3067  return 0;
3068  }
3069  if (empty($conf->global->MEMBER_REMINDER_EMAIL)) {
3070  $langs->load("agenda");
3071  $this->output = $langs->trans('EventRemindersByEmailNotEnabled', $langs->transnoentitiesnoconv("Adherent"));
3072  return 0;
3073  }
3074 
3075  $now = dol_now();
3076  $nbok = 0;
3077  $nbko = 0;
3078 
3079  $listofmembersok = array();
3080  $listofmembersko = array();
3081 
3082  $arraydaysbeforeend = explode(';', $daysbeforeendlist);
3083  foreach ($arraydaysbeforeend as $daysbeforeend) { // Loop on each delay
3084  dol_syslog(__METHOD__.' - Process delta = '.$daysbeforeend, LOG_DEBUG);
3085 
3086  if (!is_numeric($daysbeforeend)) {
3087  $blockingerrormsg = "Value for delta is not a numeric value";
3088  $nbko++;
3089  break;
3090  }
3091 
3092  $tmp = dol_getdate($now);
3093  $datetosearchfor = dol_time_plus_duree(dol_mktime(0, 0, 0, $tmp['mon'], $tmp['mday'], $tmp['year'], 'tzserver'), $daysbeforeend, 'd');
3094 
3095  $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'adherent';
3096  $sql .= " WHERE entity = ".((int) $conf->entity); // Do not use getEntity('adherent').")" here, we want the batch to be on its entity only;
3097  $sql .= " AND datefin = '".$this->db->idate($datetosearchfor)."'";
3098  //$sql .= " LIMIT 10000";
3099 
3100  $resql = $this->db->query($sql);
3101  if ($resql) {
3102  $num_rows = $this->db->num_rows($resql);
3103 
3104  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
3105  $adherent = new Adherent($this->db);
3106  $formmail = new FormMail($this->db);
3107 
3108  $i = 0;
3109  while ($i < $num_rows) {
3110  $obj = $this->db->fetch_object($resql);
3111 
3112  $adherent->fetch($obj->rowid, '', '', '', true, true);
3113 
3114  if (empty($adherent->email)) {
3115  $nbko++;
3116  $listofmembersko[$adherent->id] = $adherent->id;
3117  } else {
3118  $adherent->fetch_thirdparty();
3119 
3120  // 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.
3121  $languagefromcountrycode = getLanguageCodeFromCountryCode($adherent->country_code ? $adherent->country_code : $adherent->thirdparty->country_code);
3122  $languagecodeformember = (empty($adherent->thirdparty->default_lang) ? ($languagefromcountrycode ? $languagefromcountrycode : $mysoc->default_lang) : $adherent->thirdparty->default_lang);
3123 
3124  // Send reminder email
3125  $outputlangs = new Translate('', $conf);
3126  $outputlangs->setDefaultLang($languagecodeformember);
3127  $outputlangs->loadLangs(array("main", "members"));
3128  dol_syslog("sendReminderForExpiredSubscription Language for member id ".$adherent->id." set to ".$outputlangs->defaultlang." mysoc->default_lang=".$mysoc->default_lang);
3129 
3130  $arraydefaultmessage = null;
3131  $labeltouse = getDolGlobalString('ADHERENT_EMAIL_TEMPLATE_REMIND_EXPIRATION');
3132 
3133  if (!empty($labeltouse)) {
3134  $arraydefaultmessage = $formmail->getEMailTemplate($this->db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
3135  }
3136 
3137  if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
3138  $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $adherent);
3139  //if (is_array($adherent->thirdparty)) $substitutionarraycomp = ...
3140  complete_substitutions_array($substitutionarray, $outputlangs, $adherent);
3141 
3142  $subject = make_substitutions($arraydefaultmessage->topic, $substitutionarray, $outputlangs);
3143  $msg = make_substitutions($arraydefaultmessage->content, $substitutionarray, $outputlangs);
3144  $from = getDolGlobalString('ADHERENT_MAIL_FROM');
3145  $to = $adherent->email;
3146 
3147  $trackid = 'mem'.$adherent->id;
3148  $moreinheader = 'X-Dolibarr-Info: sendReminderForExpiredSubscription'."\r\n";
3149 
3150  include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
3151  $cmail = new CMailFile($subject, $to, $from, $msg, array(), array(), array(), '', '', 0, 1, '', '', $trackid, $moreinheader);
3152  $result = $cmail->sendfile();
3153  if (!$result) {
3154  $error++;
3155  $this->error .= $cmail->error.' ';
3156  if (!is_null($cmail->errors)) {
3157  $this->errors += $cmail->errors;
3158  }
3159  $nbko++;
3160  $listofmembersko[$adherent->id] = $adherent->id;
3161  } else {
3162  $nbok++;
3163  $listofmembersok[$adherent->id] = $adherent->id;
3164 
3165  $message = $msg;
3166  $sendto = $to;
3167  $sendtocc = '';
3168  $sendtobcc = '';
3169  $actioncode = 'EMAIL';
3170  $extraparams = '';
3171 
3172  $actionmsg = '';
3173  $actionmsg2 = $langs->transnoentities('MailSentBy').' '.CMailFile::getValidAddress($from, 4, 0, 1).' '.$langs->transnoentities('To').' '.CMailFile::getValidAddress($sendto, 4, 0, 1);
3174  if ($message) {
3175  $actionmsg = $langs->transnoentities('MailFrom').': '.dol_escape_htmltag($from);
3176  $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTo').': '.dol_escape_htmltag($sendto));
3177  if ($sendtocc) {
3178  $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc').": ".dol_escape_htmltag($sendtocc));
3179  }
3180  $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic').": ".$subject);
3181  $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody').":");
3182  $actionmsg = dol_concatdesc($actionmsg, $message);
3183  }
3184 
3185  require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
3186 
3187  // Insert record of emails sent
3188  $actioncomm = new ActionComm($this->db);
3189 
3190  $actioncomm->type_code = 'AC_OTH_AUTO'; // Type of event ('AC_OTH', 'AC_OTH_AUTO', 'AC_XXX'...)
3191  $actioncomm->code = 'AC_'.$actioncode;
3192  $actioncomm->label = $actionmsg2;
3193  $actioncomm->note_private = $actionmsg;
3194  $actioncomm->fk_project = 0;
3195  $actioncomm->datep = $now;
3196  $actioncomm->datef = $now;
3197  $actioncomm->percentage = -1; // Not applicable
3198  $actioncomm->socid = $adherent->thirdparty->id;
3199  $actioncomm->contact_id = 0;
3200  $actioncomm->authorid = $user->id; // User saving action
3201  $actioncomm->userownerid = $user->id; // Owner of action
3202  // Fields when action is en email (content should be added into note)
3203  $actioncomm->email_msgid = $cmail->msgid;
3204  $actioncomm->email_from = $from;
3205  $actioncomm->email_sender = '';
3206  $actioncomm->email_to = $to;
3207  $actioncomm->email_tocc = $sendtocc;
3208  $actioncomm->email_tobcc = $sendtobcc;
3209  $actioncomm->email_subject = $subject;
3210  $actioncomm->errors_to = '';
3211 
3212  $actioncomm->fk_element = $adherent->id;
3213  $actioncomm->elementtype = $adherent->element;
3214 
3215  $actioncomm->extraparams = $extraparams;
3216 
3217  $actioncomm->create($user);
3218  }
3219  } else {
3220  //$blockingerrormsg = "Can't find email template with label=".$labeltouse.", to use for the reminding email";
3221 
3222  $error++;
3223  $this->error .= "Can't find email template with label=".$labeltouse.", to use for the reminding email ";
3224 
3225  $nbko++;
3226  $listofmembersko[$adherent->id] = $adherent->id;
3227 
3228  break;
3229  }
3230  }
3231 
3232  $i++;
3233  }
3234  } else {
3235  $this->error = $this->db->lasterror();
3236  return 1;
3237  }
3238  }
3239 
3240  if ($blockingerrormsg) {
3241  $this->error = $blockingerrormsg;
3242  return 1;
3243  } else {
3244  $this->output = 'Found '.($nbok + $nbko).' members to send reminder to.';
3245  $this->output .= ' Send email successfuly to '.$nbok.' members';
3246  if (is_array($listofmembersok)) {
3247  $listofids = '';
3248  $i = 0;
3249  foreach ($listofmembersok as $idmember) {
3250  if ($i > 100) {
3251  $listofids .= ', ...';
3252  break;
3253  }
3254  if (empty($listofids)) {
3255  $listofids .= ' [';
3256  } else {
3257  $listofids .= ', ';
3258  }
3259  $listofids .= $idmember;
3260  $i++;
3261  }
3262  if ($listofids) {
3263  $listofids .= ']';
3264  }
3265 
3266  $this->output .= ($listofids ? ' ids='.$listofids : '');
3267  }
3268  if ($nbko) {
3269  $this->output .= ' - Canceled for '.$nbko.' member (no email or email sending error)';
3270  if (is_array($listofmembersko)) {
3271  $listofids = '';
3272  $i = 0;
3273  foreach ($listofmembersko as $idmember) {
3274  if ($i > 100) {
3275  $listofids .= ', ...';
3276  break;
3277  }
3278  if (empty($listofids)) {
3279  $listofids .= ' [';
3280  } else {
3281  $listofids .= ', ';
3282  }
3283  $listofids .= $idmember;
3284  $i++;
3285  }
3286  if ($listofids) {
3287  $listofids .= ']';
3288  }
3289  $this->output .= ($listofids ? ' ids='.$listofids : '');
3290  }
3291  }
3292  }
3293 
3294  return $nbko;
3295  }
3296 
3304  public function getKanbanView($option = '', $arraydata = null)
3305  {
3306 
3307  $return = '<div class="box-flex-item box-flex-grow-zero">';
3308  $return .= '<div class="info-box info-box-sm">';
3309  $return .= '<span class="info-box-icon bg-infobox-action">';
3310 
3311  if (property_exists($this, 'photo') || !empty($this->photo)) {
3312  $return.= Form::showphoto('memberphoto', $this, 0, 60, 0, 'photokanban photoref photowithmargin photologintooltip', 'small', 0, 1);
3313  } else {
3314  $return .= img_picto('', 'user');
3315  }
3316  $return .= '</span>';
3317  $return .= '<div class="info-box-content">';
3318  $return .= '<span class="info-box-ref">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
3319  if (property_exists($this, 'type')) {
3320  $return .= '<br><span class="info-box-label opacitymedium">'.$this->type.'</span>';
3321  }
3322  if (method_exists($this, 'getmorphylib')) {
3323  $return .= '<br><span class="info-box-label">'.$this->getmorphylib('', 2).'</span>';
3324  }
3325  if (method_exists($this, 'getLibStatut')) {
3326  $return .= '<br><div class="info-box-status margintoponly">'.$this->getLibStatut(5).'</div>';
3327  }
3328  $return .= '</div>';
3329  $return .= '</div>';
3330  $return .= '</div>';
3331  return $return;
3332  }
3333 }
make_substitutions
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
Definition: functions.lib.php:8210
dol_getdate
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
Definition: functions.lib.php:2816
Adherent\STATUS_RESILIATED
const STATUS_RESILIATED
Resiliated.
Definition: adherent.class.php:404
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:50
clean_url
clean_url($url, $http=1)
Clean an url string.
Definition: functions2.lib.php:825
db
$conf db
API class for accounts.
Definition: inc.php:41
yn
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
Definition: functions.lib.php:6699
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1504
Adherent\create
create($user, $notrigger=0)
Create a member into database.
Definition: adherent.class.php:643
Adherent\fetch_name
fetch_name($firstname, $lastname)
Method to load member from its name.
Definition: adherent.class.php:1400
dol_trunc
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
Definition: functions.lib.php:3950
Adherent\validate
validate($user)
Function that validate a member.
Definition: adherent.class.php:2011
ActionComm
Class to manage agenda events (actions)
Definition: actioncomm.class.php:38
Adherent\info
info($id)
Load type info information in the member object.
Definition: adherent.class.php:2938
Adherent\resiliate
resiliate($user)
Fonction qui resilie un adherent.
Definition: adherent.class.php:2064
Adherent\fetch
fetch($rowid, $ref='', $fk_soc='', $ref_ext='', $fetch_optionals=true, $fetch_subscriptions=true)
Load member from database.
Definition: adherent.class.php:1432
$sql
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)) $sql
Social contributions to pay.
Definition: index.php:745
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:530
CommonObject\setUpperOrLowerCase
setUpperOrLowerCase()
Set to upper or ucwords/lower if needed.
Definition: commonobject.class.php:828
Adherent\send_an_email
send_an_email($text, $subject, $filename_list=array(), $mimetype_list=array(), $mimefilename_list=array(), $addr_cc="", $addr_bcc="", $deliveryreceipt=0, $msgishtml=-1, $errors_to='', $moreinheader='')
Function sending an email to the current member with the text supplied in parameter.
Definition: adherent.class.php:447
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4994
CommonObject\setErrorsFromObject
setErrorsFromObject($object)
setErrorsFromObject
Definition: commonobject.class.php:679
Adherent\fetch_subscriptions
fetch_subscriptions()
Function to get member subscriptions data: subscriptions, first_subscription_date,...
Definition: adherent.class.php:1582
Adherent\load_board
load_board($user, $mode)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
Definition: adherent.class.php:2575
Translate
Class to manage translations.
Definition: translate.class.php:30
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1072
MailmanSpip
Class to manage mailman and spip.
Definition: mailmanspip.class.php:40
Adherent\getNomUrl
getNomUrl($withpictoimg=0, $maxlen=0, $option='card', $mode='', $morecss='', $save_lastsearch_value=-1, $notooltip=0, $addlinktonotes=0)
Return clicable name (with picto eventually)
Definition: adherent.class.php:2347
Adherent\getCivilityLabel
getCivilityLabel()
Return civility label of a member.
Definition: adherent.class.php:2264
CMailFile
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Definition: CMailFile.class.php:40
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
PaymentTerm
Class to manage payment terms records in dictionary.
Definition: paymentterm.class.php:28
getLanguageCodeFromCountryCode
getLanguageCodeFromCountryCode($countrycode)
Return default language from country code.
Definition: functions.lib.php:9162
Facture
Class to manage invoices.
Definition: facture.class.php:60
CommonObject
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Definition: commonobject.class.php:45
CommonObject\getFullName
getFullName($langs, $option=0, $nameorder=-1, $maxlen=0)
Return full name (civility+' '+name+' '+lastname)
Definition: commonobject.class.php:800
Adherent\getmorphylib
getmorphylib($morphy='', $addbadge=0)
Return translated label by the nature of a adherent (physical or moral)
Definition: adherent.class.php:592
getArrayOfSocialNetworks
getArrayOfSocialNetworks()
Get array of social network dictionary.
Definition: functions.lib.php:3134
Adherent\LibStatut
LibStatut($status, $need_subscription, $date_end_subscription, $mode=0)
Renvoi le libelle d'un statut donne.
Definition: adherent.class.php:2489
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5834
CMailFile\getValidAddress
static getValidAddress($address, $format, $encode=0, $maxnumberofemail=0)
Return a formatted address string for SMTP protocol.
Definition: CMailFile.class.php:1866
getRandomPassword
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.
Definition: security2.lib.php:482
Adherent\add_to_abo
add_to_abo()
Function to add member into external tools mailing-list, spip, etc.
Definition: adherent.class.php:2161
Adherent\setUserId
setUserId($userid)
Set link to a user.
Definition: adherent.class.php:1292
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2566
WorkboardResponse
Definition: workboardresponse.class.php:24
dol_concatdesc
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
Definition: functions.lib.php:7590
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:4025
CommonObject\commonGenerateDocument
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
Definition: commonobject.class.php:5460
dol_strtoupper
dol_strtoupper($string, $encoding="UTF-8")
Convert a string to upper.
Definition: functions.lib.php:1577
dolGetLdapPasswordHash
dolGetLdapPasswordHash($password, $type='md5')
Returns a specific ldap hash of a password.
Definition: security.lib.php:284
dol_hash
dol_hash($chain, $type='0')
Returns a hash (non reversible encryption) of a string.
Definition: security.lib.php:210
Adherent\load_state_board
load_state_board()
Charge indicateurs this->nb de tableau de bord.
Definition: adherent.class.php:2541
Exception
dolGetFirstLetters
dolGetFirstLetters($s, $nbofchar=1)
Return first letters of a strings.
Definition: functions.lib.php:3869
Adherent\subscription
subscription($date, $amount, $accountid=0, $operation='', $label='', $num_chq='', $emetteur_nom='', $emetteur_banque='', $datesubend=0, $fk_type=null)
Insert subscription into database and eventually add links to banks, mailman, etc....
Definition: adherent.class.php:1675
Adherent\_load_ldap_info
_load_ldap_info()
Initialise tableau info (tableau des attributs LDAP)
Definition: adherent.class.php:2787
dol_getIdFromCode
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
Definition: functions.lib.php:8911
Adherent\getTooltipContentArray
getTooltipContentArray($params)
getTooltipContentArray
Definition: adherent.class.php:2282
Adherent\exclude
exclude($user)
Functiun to exlude (set adherent.status to -2) a member TODO A private note should be added to know w...
Definition: adherent.class.php:2114
Adherent\STATUS_VALIDATED
const STATUS_VALIDATED
Validated status.
Definition: adherent.class.php:400
Adherent\fetch_login
fetch_login($login)
Method to load member from its login.
Definition: adherent.class.php:1372
Adherent\hasDelay
hasDelay()
Return if a member is late (subscription late) or not.
Definition: adherent.class.php:3029
CommonObject\insertExtraFields
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
Definition: commonobject.class.php:6229
Adherent\__construct
__construct($db)
Constructor.
Definition: adherent.class.php:416
Adherent\generateDocument
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
Definition: adherent.class.php:2660
Adherent\_load_ldap_dn
_load_ldap_dn($info, $mode=0)
Retourne chaine DN complete dans l'annuaire LDAP pour l'objet.
Definition: adherent.class.php:2762
getCommonSubstitutionArray
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null)
Return array of possible common substitutions.
Definition: functions.lib.php:7617
Adherent\getNbOfEMailings
getNbOfEMailings()
Return number of mass Emailing received by this member with its email.
Definition: adherent.class.php:2973
dol_string_nohtmltag
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
Definition: functions.lib.php:6921
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1639
Adherent\initAsSpecimen
initAsSpecimen()
Initialise an instance with random values.
Definition: adherent.class.php:2689
Adherent\update
update($user, $notrigger=0, $nosyncuser=0, $nosyncuserpass=0, $nosyncthirdparty=0, $action='update')
Update a member in database (standard information and password)
Definition: adherent.class.php:774
Subscription
Class to manage subscriptions of foundation members.
Definition: subscription.class.php:33
dol_format_address
dol_format_address($object, $withcountry=0, $sep="\n", $outputlangs='', $mode=0, $extralangcode='')
Return a formated address (part address/zip/town/state) according to country rules.
Definition: functions.lib.php:2445
Adherent
Class to manage members of a foundation.
Definition: adherent.class.php:46
CommonObject\fetch_optionals
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
Definition: commonobject.class.php:6080
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:82
Adherent\STATUS_EXCLUDED
const STATUS_EXCLUDED
Excluded.
Definition: adherent.class.php:408
Adherent\getLibStatut
getLibStatut($mode=0)
Retourne le libelle du statut d'un adherent (brouillon, valide, resilie, exclu)
Definition: adherent.class.php:2474
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3888
get_default_tva
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
Definition: functions.lib.php:6499
Adherent\replaceThirdparty
static replaceThirdparty($db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
Definition: adherent.class.php:3017
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:147
Adherent\del_to_abo
del_to_abo()
Function to delete a member from external tools like mailing-list, spip, etc.
Definition: adherent.class.php:2213
Adherent\STATUS_DRAFT
const STATUS_DRAFT
Draft status.
Definition: adherent.class.php:396
ref
$object ref
Definition: info.php:78
Adherent\sendReminderForExpiredSubscription
sendReminderForExpiredSubscription($daysbeforeendlist='10')
Send reminders by emails before subscription end CAN BE A CRON TASK.
Definition: adherent.class.php:3054
dol_time_plus_duree
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition: date.lib.php:122
User
Class to manage Dolibarr users.
Definition: user.class.php:44
Paiement
Class to manage payments of customer invoices.
Definition: paiement.class.php:41
Facture\TYPE_STANDARD
const TYPE_STANDARD
Standard invoice.
Definition: facture.class.php:377
CommonObject\deleteExtraFields
deleteExtraFields()
Delete all extra fields values for the current object.
Definition: commonobject.class.php:6189
Adherent\sendEmail
sendEmail($text, $subject, $filename_list=array(), $mimetype_list=array(), $mimefilename_list=array(), $addr_cc="", $addr_bcc="", $deliveryreceipt=0, $msgishtml=-1, $errors_to='', $moreinheader='')
Function sending an email to the current member with the text supplied in parameter.
Definition: adherent.class.php:472
Adherent\update_end_date
update_end_date($user)
Update denormalized last subscription date.
Definition: adherent.class.php:1045
dolGetStatus
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
Definition: functions.lib.php:10767
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4361
Adherent\getKanbanView
getKanbanView($option='', $arraydata=null)
Return clicable link of object (with eventually picto)
Definition: adherent.class.php:3304
dol_htmlentitiesbr
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
Definition: functions.lib.php:7325
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2947
Adherent\subscriptionComplementaryActions
subscriptionComplementaryActions($subscriptionid, $option, $accountid, $datesubscription, $paymentdate, $operation, $label, $amount, $num_chq, $emetteur_nom='', $emetteur_banque='', $autocreatethirdparty=0, $ext_payment_id='', $ext_payment_site='')
Do complementary actions after subscription recording.
Definition: adherent.class.php:1755
Form\showphoto
static showphoto($modulepart, $object, $width=100, $height=0, $caneditfield=0, $cssclass='photowithmargin', $imagesize='', $addlinktofullsize=1, $cache=0, $forcecapture='', $noexternsourceoverwrite=0)
Return HTML code to output a photo.
Definition: html.form.class.php:9449
CommonObject\call_trigger
call_trigger($triggerName, $user)
Call trigger based on this instance.
Definition: commonobject.class.php:5864
dol_textishtml
dol_textishtml($msg, $option=0)
Return if a text is a html content.
Definition: functions.lib.php:7523
FormMail
Classe permettant la generation du formulaire html d'envoi de mail unitaire Usage: $formail = new For...
Definition: html.formmail.class.php:38
Adherent\fetchPartnerships
fetchPartnerships($mode)
Function to get partnerships array.
Definition: adherent.class.php:1647
dol_mktime
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Definition: functions.lib.php:2859
Adherent\setPassword
setPassword($user, $password='', $isencrypted=0, $notrigger=0, $nosyncuser=0)
Change password of a user.
Definition: adherent.class.php:1194
Adherent\makeSubstitution
makeSubstitution($text)
Make substitution of tags into text with value of current object.
Definition: adherent.class.php:518
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:96
Adherent\setCategories
setCategories($categories)
Sets object to supplied categories.
Definition: adherent.class.php:3003
CommonObject\commonReplaceThirdparty
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
Definition: commonobject.class.php:8570
type
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119
Account
Class to manage bank accounts.
Definition: account.class.php:39
complete_substitutions_array
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
Definition: functions.lib.php:8333
Adherent\setThirdPartyId
setThirdPartyId($thirdpartyid)
Set link to a third party.
Definition: adherent.class.php:1333