dolibarr  13.0.2
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-2020 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  *
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation; either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program. If not, see <https://www.gnu.org/licenses/>.
29  */
30 
36 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
38 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
39 
40 
44 class Adherent extends CommonObject
45 {
46 
50  public $element = 'member';
51 
55  public $table_element = 'adherent';
56 
61  public $ismultientitymanaged = 1;
62 
66  public $picto = 'member';
67 
68 
69  public $mesgs;
70 
74  public $login;
75 
79  public $pass;
80 
84  public $pass_indatabase;
85 
89  public $pass_indatabase_crypted;
90 
95  public $societe;
96 
100  public $company;
101 
105  public $fk_soc;
106  public $socid;
107 
111  public $address;
112 
116  public $zip;
117 
121  public $town;
122 
126  public $state_id;
127 
131  public $state_code;
132 
136  public $state;
137 
141  public $email;
142 
146  public $socialnetworks;
147 
152  public $skype;
153 
158  public $twitter;
159 
164  public $facebook;
165 
170  public $linkedin;
171 
175  public $phone;
176 
180  public $phone_perso;
181 
185  public $phone_pro;
186 
190  public $phone_mobile;
191 
195  public $fax;
196 
200  public $poste;
201 
205  public $morphy;
206 
207  public $public;
208 
209  // -1:brouillon, 0:resilie, >=1:valide,paye
210  // def in common object
211  //public $status;
212 
216  public $photo;
217 
223  public $datec;
224 
230  public $datem;
231 
232  public $datevalid;
233 
237  public $gender;
238 
239  public $birth;
240 
244  public $typeid;
245 
249  public $type;
250 
251  public $need_subscription;
252 
253  public $user_id;
254 
255  public $user_login;
256 
257  public $datefin;
258 
259  // From member table
260 
261  // Fields loaded by fetch_subscriptions()
262  public $first_subscription_date;
263 
264  public $first_subscription_amount;
265 
266  public $last_subscription_date;
267 
268  public $last_subscription_date_start;
269 
270  public $last_subscription_date_end;
271 
272  public $last_subscription_amount;
273 
274  public $subscriptions = array();
275 
279  public $oldcopy;
280 
284  public $entity;
285 
289  public $fields = array(
290  'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 10),
291  'entity' => array('type' => 'integer', 'label' => 'Entity', 'default' => 1, 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 15, 'index' => 1),
292  'ref_ext' => array('type' => 'varchar(128)', 'label' => 'Ref ext', 'enabled' => 1, 'visible' => 0, 'position' => 20),
293  'civility' => array('type' => 'varchar(6)', 'label' => 'Civility', 'enabled' => 1, 'visible' => -1, 'position' => 25),
294  'lastname' => array('type' => 'varchar(50)', 'label' => 'Lastname', 'enabled' => 1, 'visible' => -1, 'position' => 30),
295  'firstname' => array('type' => 'varchar(50)', 'label' => 'Firstname', 'enabled' => 1, 'visible' => -1, 'position' => 35),
296  'login' => array('type' => 'varchar(50)', 'label' => 'Login', 'enabled' => 1, 'visible' => -1, 'position' => 40),
297  'gender' => array('type' => 'varchar(10)', 'label' => 'Gender', 'enabled' => 1, 'visible' => -1, 'position' => 250),
298  'pass' => array('type' => 'varchar(50)', 'label' => 'Pass', 'enabled' => 1, 'visible' => -1, 'position' => 45),
299  'pass_crypted' => array('type' => 'varchar(128)', 'label' => 'Pass crypted', 'enabled' => 1, 'visible' => -1, 'position' => 50),
300  'fk_adherent_type' => array('type' => 'integer', 'label' => 'Fk adherent type', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 55),
301  'morphy' => array('type' => 'varchar(3)', 'label' => 'MorPhy', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 60),
302  'societe' => array('type' => 'varchar(128)', 'label' => 'Societe', 'enabled' => 1, 'visible' => -1, 'position' => 65),
303  'fk_soc' => array('type' => 'integer:Societe:societe/class/societe.class.php', 'label' => 'ThirdParty', 'enabled' => 1, 'visible' => -1, 'position' => 70),
304  'address' => array('type' => 'text', 'label' => 'Address', 'enabled' => 1, 'visible' => -1, 'position' => 75),
305  'zip' => array('type' => 'varchar(10)', 'label' => 'Zip', 'enabled' => 1, 'visible' => -1, 'position' => 80),
306  'town' => array('type' => 'varchar(50)', 'label' => 'Town', 'enabled' => 1, 'visible' => -1, 'position' => 85),
307  'state_id' => array('type' => 'integer', 'label' => 'State id', 'enabled' => 1, 'visible' => -1, 'position' => 90),
308  'country' => array('type' => 'integer:Ccountry:core/class/ccountry.class.php', 'label' => 'Country', 'enabled' => 1, 'visible' => -1, 'position' => 95),
309  'email' => array('type' => 'varchar(255)', 'label' => 'Email', 'enabled' => 1, 'visible' => -1, 'position' => 100),
310  'socialnetworks' => array('type' => 'text', 'label' => 'Socialnetworks', 'enabled' => 1, 'visible' => -1, 'position' => 105),
311  'phone' => array('type' => 'varchar(30)', 'label' => 'Phone', 'enabled' => 1, 'visible' => -1, 'position' => 115),
312  'phone_perso' => array('type' => 'varchar(30)', 'label' => 'Phone perso', 'enabled' => 1, 'visible' => -1, 'position' => 120),
313  'phone_mobile' => array('type' => 'varchar(30)', 'label' => 'Phone mobile', 'enabled' => 1, 'visible' => -1, 'position' => 125),
314  'birth' => array('type' => 'date', 'label' => 'DateOfBirth', 'enabled' => 1, 'visible' => -1, 'position' => 130),
315  'photo' => array('type' => 'varchar(255)', 'label' => 'Photo', 'enabled' => 1, 'visible' => -1, 'position' => 135),
316  'public' => array('type' => 'smallint(6)', 'label' => 'Public', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 145),
317  'datefin' => array('type' => 'datetime', 'label' => 'DateEnd', 'enabled' => 1, 'visible' => -1, 'position' => 150),
318  'note_private' => array('type' => 'text', 'label' => 'NotePublic', 'enabled' => 1, 'visible' => 0, 'position' => 155),
319  'note_public' => array('type' => 'text', 'label' => 'NotePrivate', 'enabled' => 1, 'visible' => 0, 'position' => 160),
320  'datevalid' => array('type' => 'datetime', 'label' => 'DateValidation', 'enabled' => 1, 'visible' => -1, 'position' => 165),
321  'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -1, 'position' => 170),
322  'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 175),
323  'fk_user_author' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'Fk user author', 'enabled' => 1, 'visible' => -1, 'position' => 180),
324  'fk_user_mod' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'Fk user mod', 'enabled' => 1, 'visible' => -1, 'position' => 185),
325  'fk_user_valid' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserValidation', 'enabled' => 1, 'visible' => -1, 'position' => 190),
326  'canvas' => array('type' => 'varchar(32)', 'label' => 'Canvas', 'enabled' => 1, 'visible' => -1, 'position' => 195),
327  'statut' => array('type' => 'smallint(6)', 'label' => 'Statut', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 500,
328  'arrayofkeyval' => array(0 => 'Draft', 1 => 'Validated', -1 => 'MemberStatusResiliatedShort')),
329  'model_pdf' => array('type' => 'varchar(255)', 'label' => 'Model pdf', 'enabled' => 1, 'visible' => 0, 'position' => 800),
330  'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'visible' => -2, 'position' => 805)
331  );
332 
333 
339  public function __construct($db)
340  {
341  $this->db = $db;
342  $this->statut = -1;
343  // l'adherent n'est pas public par defaut
344  $this->public = 0;
345  // les champs optionnels sont vides
346  $this->array_options = array();
347  }
348 
349 
350  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
367  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 = '')
368  {
369  // phpcs:enable
370  global $conf, $langs;
371 
372  // Detect if message is HTML
373  if ($msgishtml == -1) {
374  $msgishtml = 0;
375  if (dol_textishtml($text, 0)) $msgishtml = 1;
376  }
377 
378  dol_syslog('send_an_email msgishtml='.$msgishtml);
379 
380  $texttosend = $this->makeSubstitution($text);
381  $subjecttosend = $this->makeSubstitution($subject);
382  if ($msgishtml) $texttosend = dol_htmlentitiesbr($texttosend);
383 
384  // Envoi mail confirmation
385  $from = $conf->email_from;
386  if (!empty($conf->global->ADHERENT_MAIL_FROM)) $from = $conf->global->ADHERENT_MAIL_FROM;
387 
388  $trackid = 'mem'.$this->id;
389 
390  // Send email (substitutionarray must be done just before this)
391  include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
392  $mailfile = new CMailFile($subjecttosend, $this->email, $from, $texttosend, $filename_list, $mimetype_list, $mimefilename_list, $addr_cc, $addr_bcc, $deliveryreceipt, $msgishtml, '', '', $trackid, $moreinheader);
393  if ($mailfile->sendfile()) {
394  return 1;
395  } else {
396  $this->error = $langs->trans("ErrorFailedToSendMail", $from, $this->email).'. '.$mailfile->error;
397  return -1;
398  }
399  }
400 
401 
408  public function makeSubstitution($text)
409  {
410  global $conf, $langs;
411 
412  $birthday = dol_print_date($this->birth, 'day');
413 
414  $msgishtml = 0;
415  if (dol_textishtml($text, 1)) $msgishtml = 1;
416 
417  $infos = '';
418  if ($this->civility_id) $infos .= $langs->transnoentities("UserTitle").": ".$this->getCivilityLabel()."\n";
419  $infos .= $langs->transnoentities("id").": ".$this->id."\n";
420  $infos .= $langs->transnoentities("Lastname").": ".$this->lastname."\n";
421  $infos .= $langs->transnoentities("Firstname").": ".$this->firstname."\n";
422  $infos .= $langs->transnoentities("Company").": ".$this->company."\n";
423  $infos .= $langs->transnoentities("Address").": ".$this->address."\n";
424  $infos .= $langs->transnoentities("Zip").": ".$this->zip."\n";
425  $infos .= $langs->transnoentities("Town").": ".$this->town."\n";
426  $infos .= $langs->transnoentities("Country").": ".$this->country."\n";
427  $infos .= $langs->transnoentities("EMail").": ".$this->email."\n";
428  $infos .= $langs->transnoentities("PhonePro").": ".$this->phone."\n";
429  $infos .= $langs->transnoentities("PhonePerso").": ".$this->phone_perso."\n";
430  $infos .= $langs->transnoentities("PhoneMobile").": ".$this->phone_mobile."\n";
431  if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
432  $infos .= $langs->transnoentities("Login").": ".$this->login."\n";
433  $infos .= $langs->transnoentities("Password").": ".$this->pass."\n";
434  }
435  $infos .= $langs->transnoentities("Birthday").": ".$birthday."\n";
436  $infos .= $langs->transnoentities("Photo").": ".$this->photo."\n";
437  $infos .= $langs->transnoentities("Public").": ".yn($this->public);
438 
439  // Substitutions
440  $substitutionarray = array(
441  '__ID__' => $this->id, '__MEMBER_ID__' => $this->id, '__CIVILITY__' => $this->getCivilityLabel(),
442  '__FIRSTNAME__' => $msgishtml ? dol_htmlentitiesbr($this->firstname) : ($this->firstname ? $this->firstname : ''),
443  '__LASTNAME__' => $msgishtml ? dol_htmlentitiesbr($this->lastname) : ($this->lastname ? $this->lastname : ''),
444  '__FULLNAME__' => $msgishtml ? dol_htmlentitiesbr($this->getFullName($langs)) : $this->getFullName($langs),
445  '__COMPANY__' => $msgishtml ? dol_htmlentitiesbr($this->company) : ($this->company ? $this->company : ''),
446  '__ADDRESS__' => $msgishtml ? dol_htmlentitiesbr($this->address) : ($this->address ? $this->address : ''),
447  '__ZIP__' => $msgishtml ? dol_htmlentitiesbr($this->zip) : ($this->zip ? $this->zip : ''), '__TOWN__' => $msgishtml ? dol_htmlentitiesbr($this->town) : ($this->town ? $this->town : ''),
448  '__COUNTRY__' => $msgishtml ? dol_htmlentitiesbr($this->country) : ($this->country ? $this->country : ''),
449  '__EMAIL__' => $msgishtml ? dol_htmlentitiesbr($this->email) : ($this->email ? $this->email : ''), '__BIRTH__' => $msgishtml ? dol_htmlentitiesbr($birthday) : ($birthday ? $birthday : ''),
450  '__PHOTO__' => $msgishtml ? dol_htmlentitiesbr($this->photo) : ($this->photo ? $this->photo : ''),
451  '__LOGIN__' => $msgishtml ? dol_htmlentitiesbr($this->login) : ($this->login ? $this->login : ''),
452  '__PASSWORD__' => $msgishtml ? dol_htmlentitiesbr($this->pass) : ($this->pass ? $this->pass : ''),
453  '__PHONE__' => $msgishtml ? dol_htmlentitiesbr($this->phone) : ($this->phone ? $this->phone : ''),
454  '__PHONEPRO__' => $msgishtml ? dol_htmlentitiesbr($this->phone_perso) : ($this->phone_perso ? $this->phone_perso : ''),
455  '__PHONEMOBILE__' => $msgishtml ? dol_htmlentitiesbr($this->phone_mobile) : ($this->phone_mobile ? $this->phone_mobile : ''),
456  '__TYPE__' => $msgishtml ? dol_htmlentitiesbr($this->type) : ($this->type ? $this->type : '')
457  );
458 
459  complete_substitutions_array($substitutionarray, $langs, $this);
460 
461  return make_substitutions($text, $substitutionarray, $langs);
462  }
463 
464 
471  public function getmorphylib($morphy = '')
472  {
473  global $langs;
474  if (!$morphy) {
475  $morphy = $this->morphy;
476  }
477  if ($morphy == 'phy') {
478  return $langs->trans("Physical");
479  }
480  if ($morphy == 'mor') {
481  return $langs->trans("Moral");
482  }
483  return $morphy;
484  }
485 
493  public function create($user, $notrigger = 0)
494  {
495  global $conf, $langs;
496 
497  $error = 0;
498 
499  $now = dol_now();
500 
501  // Clean parameters
502  $this->import_key = trim($this->import_key);
503 
504  // Check parameters
505  if (!empty($conf->global->ADHERENT_MAIL_REQUIRED) && !isValidEMail($this->email)) {
506  $langs->load("errors");
507  $this->error = $langs->trans("ErrorBadEMail", $this->email);
508  return -1;
509  }
510  if (!$this->datec) $this->datec = $now;
511  if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
512  if (empty($this->login)) {
513  $this->error = $langs->trans("ErrorWrongValueForParameterX", "Login");
514  return -1;
515  }
516  }
517 
518  $this->db->begin();
519 
520  // Insert member
521  $sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent";
522  $sql .= " (datec,login,fk_user_author,fk_user_mod,fk_user_valid,morphy,fk_adherent_type,entity,import_key)";
523  $sql .= " VALUES (";
524  $sql .= " '".$this->db->idate($this->datec)."'";
525  $sql .= ", ".($this->login ? "'".$this->db->escape($this->login)."'" : "null");
526  $sql .= ", ".($user->id > 0 ? $user->id : "null"); // Can be null because member can be created by a guest or a script
527  $sql .= ", null, null, '".$this->db->escape($this->morphy)."'";
528  $sql .= ", ".$this->typeid;
529  $sql .= ", ".$conf->entity;
530  $sql .= ", ".(!empty($this->import_key) ? "'".$this->db->escape($this->import_key)."'" : "null");
531  $sql .= ")";
532 
533  dol_syslog(get_class($this)."::create", LOG_DEBUG);
534  $result = $this->db->query($sql);
535  if ($result) {
536  $id = $this->db->last_insert_id(MAIN_DB_PREFIX."adherent");
537  if ($id > 0) {
538  $this->id = $id;
539  $this->ref = (string) $id;
540 
541  // Update minor fields
542  $result = $this->update($user, 1, 1, 0, 0, 'add'); // nosync is 1 to avoid update data of user
543  if ($result < 0) {
544  $this->db->rollback();
545  return -1;
546  }
547 
548  // Add link to user
549  if ($this->user_id) {
550  // Add link to user
551  $sql = "UPDATE ".MAIN_DB_PREFIX."user SET";
552  $sql .= " fk_member = ".$this->id;
553  $sql .= " WHERE rowid = ".$this->user_id;
554  dol_syslog(get_class($this)."::create", LOG_DEBUG);
555  $resql = $this->db->query($sql);
556  if (!$resql) {
557  $this->error = 'Failed to update user to make link with member';
558  $this->db->rollback();
559  return -4;
560  }
561  }
562 
563  if (!$notrigger) {
564  // Call trigger
565  $result = $this->call_trigger('MEMBER_CREATE', $user);
566  if ($result < 0) {
567  $error++;
568  }
569  // End call triggers
570  }
571 
572  if (count($this->errors)) {
573  dol_syslog(get_class($this)."::create ".implode(',', $this->errors), LOG_ERR);
574  $this->db->rollback();
575  return -3;
576  } else {
577  $this->db->commit();
578  return $this->id;
579  }
580  } else {
581  $this->error = 'Failed to get last insert id';
582  dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
583  $this->db->rollback();
584  return -2;
585  }
586  } else {
587  $this->error = $this->db->error();
588  $this->db->rollback();
589  return -1;
590  }
591  }
592 
593 
605  public function update($user, $notrigger = 0, $nosyncuser = 0, $nosyncuserpass = 0, $nosyncthirdparty = 0, $action = 'update')
606  {
607  global $conf, $langs, $hookmanager;
608 
609  $nbrowsaffected = 0;
610  $error = 0;
611 
612  dol_syslog(get_class($this)."::update notrigger=".$notrigger.", nosyncuser=".$nosyncuser.", nosyncuserpass=".$nosyncuserpass." nosyncthirdparty=".$nosyncthirdparty.", email=".
613  $this->email);
614 
615  // Clean parameters
616  $this->lastname = trim($this->lastname) ? trim($this->lastname) : trim($this->lastname);
617  $this->firstname = trim($this->firstname) ? trim($this->firstname) : trim($this->firstname);
618  $this->gender = trim($this->gender);
619  $this->address = ($this->address ? $this->address : $this->address);
620  $this->zip = ($this->zip ? $this->zip : $this->zip);
621  $this->town = ($this->town ? $this->town : $this->town);
622  $this->country_id = ($this->country_id > 0 ? $this->country_id : $this->country_id);
623  $this->state_id = ($this->state_id > 0 ? $this->state_id : $this->state_id);
624  $this->setUpperOrLowerCase();
625  $this->note_public = ($this->note_public ? $this->note_public : $this->note_public);
626  $this->note_private = ($this->note_private ? $this->note_private : $this->note_private);
627 
628  // Check parameters
629  if (!empty($conf->global->ADHERENT_MAIL_REQUIRED) && !isValidEMail($this->email)) {
630  $langs->load("errors");
631  $this->error = $langs->trans("ErrorBadEMail", $this->email);
632  return -1;
633  }
634 
635  $this->db->begin();
636 
637  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
638  $sql .= " civility = ".($this->civility_id ? "'".$this->db->escape($this->civility_id)."'" : "null");
639  $sql .= ", firstname = ".($this->firstname ? "'".$this->db->escape($this->firstname)."'" : "null");
640  $sql .= ", lastname = ".($this->lastname ? "'".$this->db->escape($this->lastname)."'" : "null");
641  $sql .= ", gender = ".($this->gender != -1 ? "'".$this->db->escape($this->gender)."'" : "null"); // 'man' or 'woman'
642  $sql .= ", login = ".($this->login ? "'".$this->db->escape($this->login)."'" : "null");
643  $sql .= ", societe = ".($this->company ? "'".$this->db->escape($this->company)."'" : ($this->societe ? "'".$this->db->escape($this->societe)."'" : "null"));
644  $sql .= ", fk_soc = ".($this->socid > 0 ? $this->db->escape($this->socid) : "null");
645  $sql .= ", address = ".($this->address ? "'".$this->db->escape($this->address)."'" : "null");
646  $sql .= ", zip = ".($this->zip ? "'".$this->db->escape($this->zip)."'" : "null");
647  $sql .= ", town = ".($this->town ? "'".$this->db->escape($this->town)."'" : "null");
648  $sql .= ", country = ".($this->country_id > 0 ? $this->db->escape($this->country_id) : "null");
649  $sql .= ", state_id = ".($this->state_id > 0 ? $this->db->escape($this->state_id) : "null");
650  $sql .= ", email = '".$this->db->escape($this->email)."'";
651  $sql .= ", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks))."'";
652  $sql .= ", phone = ".($this->phone ? "'".$this->db->escape($this->phone)."'" : "null");
653  $sql .= ", phone_perso = ".($this->phone_perso ? "'".$this->db->escape($this->phone_perso)."'" : "null");
654  $sql .= ", phone_mobile = ".($this->phone_mobile ? "'".$this->db->escape($this->phone_mobile)."'" : "null");
655  $sql .= ", note_private = ".($this->note_private ? "'".$this->db->escape($this->note_private)."'" : "null");
656  $sql .= ", note_public = ".($this->note_public ? "'".$this->db->escape($this->note_public)."'" : "null");
657  $sql .= ", photo = ".($this->photo ? "'".$this->db->escape($this->photo)."'" : "null");
658  $sql .= ", public = '".$this->db->escape($this->public)."'";
659  $sql .= ", statut = ".$this->db->escape($this->statut);
660  $sql .= ", fk_adherent_type = ".$this->db->escape($this->typeid);
661  $sql .= ", morphy = '".$this->db->escape($this->morphy)."'";
662  $sql .= ", birth = ".($this->birth ? "'".$this->db->idate($this->birth)."'" : "null");
663  if ($this->socid) $sql .= ", fk_soc = '".$this->db->escape($this->socid)."'"; // Must be modified only when creating from a third-party
664  if ($this->datefin) $sql .= ", datefin = '".$this->db->idate($this->datefin)."'"; // Must be modified only when deleting a subscription
665  if ($this->datevalid) $sql .= ", datevalid = '".$this->db->idate($this->datevalid)."'"; // Must be modified only when validating a member
666  $sql .= ", fk_user_mod = ".($user->id > 0 ? $user->id : 'null'); // Can be null because member can be create by a guest
667  $sql .= " WHERE rowid = ".$this->id;
668 
669  // If we change the type of membership, we set also label of new type
670  if (!empty($this->oldcopy) && $this->typeid != $this->oldcopy->typeid) {
671  $sql2 = "SELECT libelle as label";
672  $sql2 .= " FROM ".MAIN_DB_PREFIX."adherent_type";
673  $sql2 .= " WHERE rowid = ".$this->typeid;
674  $resql2 = $this->db->query($sql2);
675  if ($resql2) {
676  while ($obj = $this->db->fetch_object($resql2)) {
677  $this->type = $obj->label;
678  }
679  }
680  }
681 
682  dol_syslog(get_class($this)."::update update member", LOG_DEBUG);
683  $resql = $this->db->query($sql);
684  if ($resql) {
685  unset($this->country_code);
686  unset($this->country);
687  unset($this->state_code);
688  unset($this->state);
689 
690  $nbrowsaffected += $this->db->affected_rows($resql);
691 
692  $action = 'update';
693 
694  // Actions on extra fields
695  if (!$error) {
696  $result = $this->insertExtraFields();
697  if ($result < 0) {
698  $error++;
699  }
700  }
701 
702  // Update password
703  if (!$error && $this->pass) {
704  dol_syslog(get_class($this)."::update update password");
705  if ($this->pass != $this->pass_indatabase && $this->pass != $this->pass_indatabase_crypted) {
706  $isencrypted = empty($conf->global->DATABASE_PWD_ENCRYPTED) ? 0 : 1;
707 
708  // If password to set differs from the one found into database
709  $result = $this->setPassword($user, $this->pass, $isencrypted, $notrigger, $nosyncuserpass);
710  if (!$nbrowsaffected) $nbrowsaffected++;
711  }
712  }
713 
714  // Remove links to user and replace with new one
715  if (!$error) {
716  dol_syslog(get_class($this)."::update update link to user");
717  $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = NULL WHERE fk_member = ".$this->id;
718  dol_syslog(get_class($this)."::update", LOG_DEBUG);
719  $resql = $this->db->query($sql);
720  if (!$resql) {
721  $this->error = $this->db->error();
722  $this->db->rollback();
723  return -5;
724  }
725  // If there is a user linked to this member
726  if ($this->user_id > 0) {
727  $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = ".$this->id." WHERE rowid = ".$this->user_id;
728  dol_syslog(get_class($this)."::update", LOG_DEBUG);
729  $resql = $this->db->query($sql);
730  if (!$resql) {
731  $this->error = $this->db->error();
732  $this->db->rollback();
733  return -5;
734  }
735  }
736  }
737 
738  if (!$error && $nbrowsaffected) { // If something has change in main data
739  // Update information on linked user if it is an update
740  if (!$error && $this->user_id > 0 && !$nosyncuser) {
741  require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
742 
743  dol_syslog(get_class($this)."::update update linked user");
744 
745  $luser = new User($this->db);
746  $result = $luser->fetch($this->user_id);
747 
748  if ($result >= 0) {
749  //var_dump($this->user_login);exit;
750  //var_dump($this->login);exit;
751 
752  // 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.
753  if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) $luser->login = $this->login;
754 
755  $luser->civility_id = $this->civility_id;
756  $luser->firstname = $this->firstname;
757  $luser->lastname = $this->lastname;
758  $luser->gender = $this->gender;
759  $luser->pass = $this->pass;
760  //$luser->socid=$this->fk_soc; // We do not enable this. This may transform a user into an external user.
761 
762  $luser->birth = $this->birth;
763 
764  $luser->address = $this->address;
765  $luser->zip = $this->zip;
766  $luser->town = $this->town;
767  $luser->country_id = $this->country_id;
768  $luser->state_id = $this->state_id;
769 
770  $luser->email = $this->email;
771  $luser->socialnetworks = $this->socialnetworks;
772  $luser->office_phone = $this->phone;
773  $luser->user_mobile = $this->phone_mobile;
774 
775  $luser->fk_member = $this->id;
776 
777  $result = $luser->update($user, 0, 1, 1); // Use nosync to 1 to avoid cyclic updates
778  if ($result < 0) {
779  $this->error = $luser->error;
780  dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
781  $error++;
782  }
783  } else {
784  $this->error = $luser->error;
785  $error++;
786  }
787  }
788 
789  // Update information on linked thirdparty if it is an update
790  if (!$error && $this->fk_soc > 0 && !$nosyncthirdparty) {
791  require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
792 
793  dol_syslog(get_class($this)."::update update linked thirdparty");
794 
795  // This member is linked with a thirdparty, so we also update thirdparty informations
796  // if this is an update.
797  $lthirdparty = new Societe($this->db);
798  $result = $lthirdparty->fetch($this->fk_soc);
799 
800  if ($result > 0) {
801  $lthirdparty->address = $this->address;
802  $lthirdparty->zip = $this->zip;
803  $lthirdparty->town = $this->town;
804  $lthirdparty->email = $this->email;
805  $lthirdparty->socialnetworks = $this->socialnetworks;
806  $lthirdparty->phone = $this->phone;
807  $lthirdparty->state_id = $this->state_id;
808  $lthirdparty->country_id = $this->country_id;
809  //$lthirdparty->phone_mobile=$this->phone_mobile;
810 
811  $result = $lthirdparty->update($this->fk_soc, $user, 0, 1, 1, 'update'); // Use sync to 0 to avoid cyclic updates
812 
813  if ($result < 0) {
814  $this->error = $lthirdparty->error;
815  $this->errors = $lthirdparty->errors;
816  dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
817  $error++;
818  }
819  } elseif ($result < 0) {
820  $this->error = $lthirdparty->error;
821  $error++;
822  }
823  }
824  }
825 
826  if (!$error && !$notrigger) {
827  // Call trigger
828  $result = $this->call_trigger('MEMBER_MODIFY', $user);
829  if ($result < 0) {
830  $error++;
831  }
832  // End call triggers
833  }
834 
835  if (!$error) {
836  $this->db->commit();
837  return $nbrowsaffected;
838  } else {
839  $this->db->rollback();
840  return -1;
841  }
842  } else {
843  $this->db->rollback();
844  $this->error = $this->db->lasterror();
845  return -2;
846  }
847  }
848 
849 
850  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
858  public function update_end_date($user)
859  {
860  // phpcs:enable
861  $this->db->begin();
862 
863  // Search for last subscription id and end date
864  $sql = "SELECT rowid, datec as dateop, dateadh as datedeb, datef as datefin";
865  $sql .= " FROM ".MAIN_DB_PREFIX."subscription";
866  $sql .= " WHERE fk_adherent=".$this->id;
867  $sql .= " ORDER by dateadh DESC"; // Sort by start subscription date
868 
869  dol_syslog(get_class($this)."::update_end_date", LOG_DEBUG);
870  $resql = $this->db->query($sql);
871  if ($resql) {
872  $obj = $this->db->fetch_object($resql);
873  $dateop = $this->db->jdate($obj->dateop);
874  $datedeb = $this->db->jdate($obj->datedeb);
875  $datefin = $this->db->jdate($obj->datefin);
876 
877  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
878  $sql .= " datefin=".($datefin != '' ? "'".$this->db->idate($datefin)."'" : "null");
879  $sql .= " WHERE rowid = ".$this->id;
880 
881  dol_syslog(get_class($this)."::update_end_date", LOG_DEBUG);
882  $resql = $this->db->query($sql);
883  if ($resql) {
884  $this->last_subscription_date = $dateop;
885  $this->last_subscription_date_start = $datedeb;
886  $this->last_subscription_date_end = $datefin;
887  $this->datefin = $datefin;
888  $this->db->commit();
889  return 1;
890  } else {
891  $this->db->rollback();
892  return -1;
893  }
894  } else {
895  $this->error = $this->db->lasterror();
896  $this->db->rollback();
897  return -1;
898  }
899  }
900 
909  public function delete($rowid, $user, $notrigger = 0)
910  {
911  global $conf, $langs;
912 
913  $result = 0;
914  $error = 0;
915  $errorflag = 0;
916 
917  // Check parameters
918  if (empty($rowid)) $rowid = $this->id;
919 
920  $this->db->begin();
921 
922  if (!$error && !$notrigger) {
923  // Call trigger
924  $result = $this->call_trigger('MEMBER_DELETE', $user);
925  if ($result < 0) $error++;
926  // End call triggers
927  }
928 
929  // Remove category
930  $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_member WHERE fk_member = ".$rowid;
931  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
932  $resql = $this->db->query($sql);
933  if (!$resql) {
934  $error++;
935  $this->error .= $this->db->lasterror();
936  $errorflag = -1;
937  }
938 
939  // Remove subscription
940  if (!$error) {
941  $sql = "DELETE FROM ".MAIN_DB_PREFIX."subscription WHERE fk_adherent = ".$rowid;
942  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
943  $resql = $this->db->query($sql);
944  if (!$resql) {
945  $error++;
946  $this->error .= $this->db->lasterror();
947  $errorflag = -2;
948  }
949  }
950 
951  // Remove linked user
952  if (!$error) {
953  $ret = $this->setUserId(0);
954  if ($ret < 0) {
955  $error++;
956  $this->error .= $this->db->lasterror();
957  $errorflag = -3;
958  }
959  }
960 
961  // Removed extrafields
962  if (!$error) {
963  $result = $this->deleteExtraFields();
964  if ($result < 0) {
965  $error++;
966  $errorflag = -4;
967  dol_syslog(get_class($this)."::delete erreur ".$errorflag." ".$this->error, LOG_ERR);
968  }
969  }
970 
971  // Remove adherent
972  if (!$error) {
973  $sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent WHERE rowid = ".$rowid;
974  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
975  $resql = $this->db->query($sql);
976  if (!$resql) {
977  $error++;
978  $this->error .= $this->db->lasterror();
979  $errorflag = -5;
980  }
981  }
982 
983  if (!$error) {
984  $this->db->commit();
985  return 1;
986  } else {
987  $this->db->rollback();
988  return $errorflag;
989  }
990  }
991 
992 
1003  public function setPassword($user, $password = '', $isencrypted = 0, $notrigger = 0, $nosyncuser = 0)
1004  {
1005  global $conf, $langs;
1006 
1007  $error = 0;
1008 
1009  dol_syslog(get_class($this)."::setPassword user=".$user->id." password=".preg_replace('/./i', '*', $password)." isencrypted=".$isencrypted);
1010 
1011  // If new password not provided, we generate one
1012  if (!$password) {
1013  require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
1014  $password = getRandomPassword(false);
1015  }
1016 
1017  // Crypt password
1018  $password_crypted = dol_hash($password);
1019 
1020  $password_indatabase = '';
1021  if (!$isencrypted) {
1022  $password_indatabase = $password;
1023  }
1024 
1025  $this->db->begin();
1026 
1027  // Mise a jour
1028  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent";
1029  $sql .= " SET pass_crypted = '".$this->db->escape($password_crypted)."'";
1030  //if (! empty($conf->global->DATABASE_PWD_ENCRYPTED))
1031  if ($isencrypted) {
1032  $sql .= ", pass = null";
1033  } else {
1034  $sql .= ", pass = '".$this->db->escape($password_indatabase)."'";
1035  }
1036  $sql .= " WHERE rowid = ".$this->id;
1037 
1038  //dol_syslog("Adherent::Password sql=hidden");
1039  dol_syslog(get_class($this)."::setPassword", LOG_DEBUG);
1040  $result = $this->db->query($sql);
1041  if ($result) {
1042  $nbaffectedrows = $this->db->affected_rows($result);
1043 
1044  if ($nbaffectedrows) {
1045  $this->pass = $password;
1046  $this->pass_indatabase = $password_indatabase;
1047  $this->pass_indatabase_crypted = $password_crypted;
1048 
1049  if ($this->user_id && !$nosyncuser) {
1050  require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
1051 
1052  // This member is linked with a user, so we also update users informations
1053  // if this is an update.
1054  $luser = new User($this->db);
1055  $result = $luser->fetch($this->user_id);
1056 
1057  if ($result >= 0) {
1058  $result = $luser->setPassword($user, $this->pass, 0, 0, 1);
1059  if ($result < 0) {
1060  $this->error = $luser->error;
1061  dol_syslog(get_class($this)."::setPassword ".$this->error, LOG_ERR);
1062  $error++;
1063  }
1064  } else {
1065  $this->error = $luser->error;
1066  $error++;
1067  }
1068  }
1069 
1070  if (!$error && !$notrigger) {
1071  // Call trigger
1072  $result = $this->call_trigger('MEMBER_NEW_PASSWORD', $user);
1073  if ($result < 0) {
1074  $error++;
1075  $this->db->rollback();
1076  return -1;
1077  }
1078  // End call triggers
1079  }
1080 
1081  $this->db->commit();
1082  return $this->pass;
1083  } else {
1084  $this->db->rollback();
1085  return 0;
1086  }
1087  } else {
1088  $this->db->rollback();
1089  dol_print_error($this->db);
1090  return -1;
1091  }
1092  }
1093 
1094 
1101  public function setUserId($userid)
1102  {
1103  global $conf, $langs;
1104 
1105  $this->db->begin();
1106 
1107  // If user is linked to this member, remove old link to this member
1108  $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = NULL WHERE fk_member = ".$this->id;
1109  dol_syslog(get_class($this)."::setUserId", LOG_DEBUG);
1110  $resql = $this->db->query($sql);
1111  if (!$resql) {
1112  $this->error = $this->db->error();
1113  $this->db->rollback();
1114  return -1;
1115  }
1116 
1117  // Set link to user
1118  if ($userid > 0) {
1119  $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = ".$this->id;
1120  $sql .= " WHERE rowid = ".$userid;
1121  dol_syslog(get_class($this)."::setUserId", LOG_DEBUG);
1122  $resql = $this->db->query($sql);
1123  if (!$resql) {
1124  $this->error = $this->db->error();
1125  $this->db->rollback();
1126  return -2;
1127  }
1128  }
1129 
1130  $this->db->commit();
1131 
1132  return 1;
1133  }
1134 
1135 
1142  public function setThirdPartyId($thirdpartyid)
1143  {
1144  global $conf, $langs;
1145 
1146  $this->db->begin();
1147 
1148  // Remove link to third party onto any other members
1149  if ($thirdpartyid > 0) {
1150  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET fk_soc = null";
1151  $sql .= " WHERE fk_soc = ".((int) $thirdpartyid);
1152  $sql .= " AND entity = ".$conf->entity;
1153  dol_syslog(get_class($this)."::setThirdPartyId", LOG_DEBUG);
1154  $resql = $this->db->query($sql);
1155  }
1156 
1157  // Add link to third party for current member
1158  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET fk_soc = ".($thirdpartyid > 0 ? $thirdpartyid : 'null');
1159  $sql .= " WHERE rowid = ".$this->id;
1160 
1161  dol_syslog(get_class($this)."::setThirdPartyId", LOG_DEBUG);
1162  $resql = $this->db->query($sql);
1163  if ($resql) {
1164  $this->db->commit();
1165  return 1;
1166  } else {
1167  $this->error = $this->db->error();
1168  $this->db->rollback();
1169  return -1;
1170  }
1171  }
1172 
1173 
1174  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1181  public function fetch_login($login)
1182  {
1183  // phpcs:enable
1184  global $conf;
1185 
1186  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."adherent";
1187  $sql .= " WHERE login='".$this->db->escape($login)."'";
1188  $sql .= " AND entity = ".$conf->entity;
1189 
1190  $resql = $this->db->query($sql);
1191  if ($resql) {
1192  if ($this->db->num_rows($resql)) {
1193  $obj = $this->db->fetch_object($resql);
1194  $this->fetch($obj->rowid);
1195  }
1196  } else {
1197  dol_print_error($this->db);
1198  }
1199  }
1200 
1201  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1209  public function fetch_name($firstname, $lastname)
1210  {
1211  // phpcs:enable
1212  global $conf;
1213 
1214  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."adherent";
1215  $sql .= " WHERE firstname='".$this->db->escape($firstname)."'";
1216  $sql .= " AND lastname='".$this->db->escape($lastname)."'";
1217  $sql .= " AND entity = ".$conf->entity;
1218 
1219  $resql = $this->db->query($sql);
1220  if ($resql) {
1221  if ($this->db->num_rows($resql)) {
1222  $obj = $this->db->fetch_object($resql);
1223  $this->fetch($obj->rowid);
1224  }
1225  } else {
1226  dol_print_error($this->db);
1227  }
1228  }
1229 
1241  public function fetch($rowid, $ref = '', $fk_soc = '', $ref_ext = '', $fetch_optionals = true, $fetch_subscriptions = true)
1242  {
1243  global $langs;
1244 
1245  $sql = "SELECT d.rowid, d.ref_ext, d.civility as civility_code, d.gender, d.firstname, d.lastname, d.societe as company, d.fk_soc, d.statut, d.public, d.address, d.zip, d.town, d.note_private,";
1246  $sql .= " d.note_public,";
1247  $sql .= " d.email, d.socialnetworks, d.phone, d.phone_perso, d.phone_mobile, d.login, d.pass, d.pass_crypted,";
1248  $sql .= " d.photo, d.fk_adherent_type, d.morphy, d.entity,";
1249  $sql .= " d.datec as datec,";
1250  $sql .= " d.tms as datem,";
1251  $sql .= " d.datefin as datefin,";
1252  $sql .= " d.birth as birthday,";
1253  $sql .= " d.datevalid as datev,";
1254  $sql .= " d.country,";
1255  $sql .= " d.state_id,";
1256  $sql .= " d.model_pdf,";
1257  $sql .= " c.rowid as country_id, c.code as country_code, c.label as country,";
1258  $sql .= " dep.nom as state, dep.code_departement as state_code,";
1259  $sql .= " t.libelle as type, t.subscription as subscription,";
1260  $sql .= " u.rowid as user_id, u.login as user_login";
1261  $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as t, ".MAIN_DB_PREFIX."adherent as d";
1262  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON d.country = c.rowid";
1263  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as dep ON d.state_id = dep.rowid";
1264  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON d.rowid = u.fk_member";
1265  $sql .= " WHERE d.fk_adherent_type = t.rowid";
1266  if ($rowid) {
1267  $sql .= " AND d.rowid=".((int) $rowid);
1268  } elseif ($ref || $fk_soc) {
1269  $sql .= " AND d.entity IN (".getEntity('adherent').")";
1270  if ($ref) {
1271  $sql .= " AND d.rowid='".$this->db->escape($ref)."'";
1272  } elseif ($fk_soc > 0) {
1273  $sql .= " AND d.fk_soc=".((int) $fk_soc);
1274  }
1275  } elseif ($ref_ext) {
1276  $sql .= " AND d.ref_ext='".$this->db->escape($ref_ext)."'";
1277  }
1278 
1279  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
1280  $resql = $this->db->query($sql);
1281  if ($resql) {
1282  if ($this->db->num_rows($resql)) {
1283  $obj = $this->db->fetch_object($resql);
1284 
1285  $this->entity = $obj->entity;
1286  $this->ref = $obj->rowid;
1287  $this->id = $obj->rowid;
1288  $this->ref_ext = $obj->ref_ext;
1289 
1290  $this->civility_id = $obj->civility_code; // Bad. Kept for backard compatibility
1291  $this->civility_code = $obj->civility_code;
1292  $this->civility = $obj->civility_code ? ($langs->trans("Civility".$obj->civility_code) != ("Civility".$obj->civility_code) ? $langs->trans("Civility".$obj->civility_code) : $obj->civility_code) : '';
1293 
1294  $this->firstname = $obj->firstname;
1295  $this->lastname = $obj->lastname;
1296  $this->gender = $obj->gender;
1297  $this->login = $obj->login;
1298  $this->societe = $obj->company;
1299  $this->company = $obj->company;
1300  $this->socid = $obj->fk_soc;
1301  $this->fk_soc = $obj->fk_soc; // For backward compatibility
1302  $this->address = $obj->address;
1303  $this->zip = $obj->zip;
1304  $this->town = $obj->town;
1305 
1306  $this->pass = $obj->pass;
1307  $this->pass_indatabase = $obj->pass;
1308  $this->pass_indatabase_crypted = $obj->pass_crypted;
1309 
1310  $this->state_id = $obj->state_id;
1311  $this->state_code = $obj->state_id ? $obj->state_code : '';
1312  $this->state = $obj->state_id ? $obj->state : '';
1313 
1314  $this->country_id = $obj->country_id;
1315  $this->country_code = $obj->country_code;
1316  if ($langs->trans("Country".$obj->country_code) != "Country".$obj->country_code) {
1317  $this->country = $langs->transnoentitiesnoconv("Country".$obj->country_code);
1318  } else {
1319  $this->country = $obj->country;
1320  }
1321 
1322  $this->phone = $obj->phone;
1323  $this->phone_perso = $obj->phone_perso;
1324  $this->phone_mobile = $obj->phone_mobile;
1325  $this->email = $obj->email;
1326 
1327  $this->socialnetworks = (array) json_decode($obj->socialnetworks, true);
1328 
1329  $this->photo = $obj->photo;
1330  $this->statut = $obj->statut;
1331  $this->public = $obj->public;
1332 
1333  $this->datec = $this->db->jdate($obj->datec);
1334  $this->date_creation = $this->db->jdate($obj->datec);
1335  $this->datem = $this->db->jdate($obj->datem);
1336  $this->date_modification = $this->db->jdate($obj->datem);
1337  $this->datefin = $this->db->jdate($obj->datefin);
1338  $this->datevalid = $this->db->jdate($obj->datev);
1339  $this->date_validation = $this->db->jdate($obj->datev);
1340  $this->birth = $this->db->jdate($obj->birthday);
1341 
1342  $this->note_private = $obj->note_private;
1343  $this->note_public = $obj->note_public;
1344  $this->morphy = $obj->morphy;
1345 
1346  $this->typeid = $obj->fk_adherent_type;
1347  $this->type = $obj->type;
1348  $this->need_subscription = $obj->subscription;
1349 
1350  $this->user_id = $obj->user_id;
1351  $this->user_login = $obj->user_login;
1352 
1353  $this->model_pdf = $obj->model_pdf;
1354 
1355  // Retrieve all extrafield
1356  // fetch optionals attributes and labels
1357  if ($fetch_optionals) {
1358  $this->fetch_optionals();
1359  }
1360 
1361  // Load other properties
1362  if ($fetch_subscriptions) {
1363  $result = $this->fetch_subscriptions();
1364  }
1365 
1366  return $this->id;
1367  } else {
1368  return 0;
1369  }
1370  } else {
1371  $this->error = $this->db->lasterror();
1372  return -1;
1373  }
1374  }
1375 
1376 
1377  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1385  public function fetch_subscriptions()
1386  {
1387  // phpcs:enable
1388  global $langs;
1389 
1390  require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
1391 
1392  $sql = "SELECT c.rowid, c.fk_adherent, c.fk_type, c.subscription, c.note, c.fk_bank,";
1393  $sql .= " c.tms as datem,";
1394  $sql .= " c.datec as datec,";
1395  $sql .= " c.dateadh as dateh,";
1396  $sql .= " c.datef as datef";
1397  $sql .= " FROM ".MAIN_DB_PREFIX."subscription as c";
1398  $sql .= " WHERE c.fk_adherent = ".$this->id;
1399  $sql .= " ORDER BY c.dateadh";
1400  dol_syslog(get_class($this)."::fetch_subscriptions", LOG_DEBUG);
1401 
1402  $resql = $this->db->query($sql);
1403  if ($resql) {
1404  $this->subscriptions = array();
1405 
1406  $i = 0;
1407  while ($obj = $this->db->fetch_object($resql)) {
1408  if ($i == 0) {
1409  $this->first_subscription_date = $this->db->jdate($obj->datec);
1410  $this->first_subscription_date_start = $this->db->jdate($obj->dateh);
1411  $this->first_subscription_date_end = $this->db->jdate($obj->datef);
1412  $this->first_subscription_amount = $obj->subscription;
1413  }
1414  $this->last_subscription_date = $this->db->jdate($obj->datec);
1415  $this->last_subscription_date_start = $this->db->jdate($obj->datef);
1416  $this->last_subscription_date_end = $this->db->jdate($obj->datef);
1417  $this->last_subscription_amount = $obj->subscription;
1418 
1419  $subscription = new Subscription($this->db);
1420  $subscription->id = $obj->rowid;
1421  $subscription->fk_adherent = $obj->fk_adherent;
1422  $subscription->fk_type = $obj->fk_type;
1423  $subscription->amount = $obj->subscription;
1424  $subscription->note = $obj->note;
1425  $subscription->fk_bank = $obj->fk_bank;
1426  $subscription->datem = $this->db->jdate($obj->datem);
1427  $subscription->datec = $this->db->jdate($obj->datec);
1428  $subscription->dateh = $this->db->jdate($obj->dateh);
1429  $subscription->datef = $this->db->jdate($obj->datef);
1430 
1431  $this->subscriptions[] = $subscription;
1432 
1433  $i++;
1434  }
1435  return 1;
1436  } else {
1437  $this->error = $this->db->error().' sql='.$sql;
1438  return -1;
1439  }
1440  }
1441 
1442 
1457  public function subscription($date, $amount, $accountid = 0, $operation = '', $label = '', $num_chq = '', $emetteur_nom = '', $emetteur_banque = '', $datesubend = 0)
1458  {
1459  global $conf, $langs, $user;
1460 
1461  require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
1462 
1463  $error = 0;
1464 
1465  // Clean parameters
1466  if (!$amount) $amount = 0;
1467 
1468  $this->db->begin();
1469 
1470  if ($datesubend) {
1471  $datefin = $datesubend;
1472  } else {
1473  // If no end date, end date = date + 1 year - 1 day
1474  $datefin = dol_time_plus_duree($date, 1, 'y');
1475  $datefin = dol_time_plus_duree($datefin, -1, 'd');
1476  }
1477 
1478  // Create subscription
1479  $subscription = new Subscription($this->db);
1480  $subscription->fk_adherent = $this->id;
1481  $subscription->dateh = $date; // Date of new subscription
1482  $subscription->datef = $datefin; // End data of new subscription
1483  $subscription->amount = $amount;
1484  $subscription->note = $label; // deprecated
1485  $subscription->note_public = $label;
1486 
1487  $rowid = $subscription->create($user);
1488  if ($rowid > 0) {
1489  // Update denormalized subscription end date (read database subscription to find values)
1490  // This will also update this->datefin
1491  $result = $this->update_end_date($user);
1492  if ($result > 0) {
1493  // Change properties of object (used by triggers)
1494  $this->last_subscription_date = dol_now();
1495  $this->last_subscription_date_start = $date;
1496  $this->last_subscription_date_end = $datefin;
1497  $this->last_subscription_amount = $amount;
1498  }
1499 
1500  if (!$error) {
1501  $this->db->commit();
1502  return $rowid;
1503  } else {
1504  $this->db->rollback();
1505  return -2;
1506  }
1507  } else {
1508  $this->error = $subscription->error;
1509  $this->errors = $subscription->errors;
1510  $this->db->rollback();
1511  return -1;
1512  }
1513  }
1514 
1515 
1533  public function subscriptionComplementaryActions($subscriptionid, $option, $accountid, $datesubscription, $paymentdate, $operation, $label, $amount, $num_chq, $emetteur_nom = '', $emetteur_banque = '', $autocreatethirdparty = 0)
1534  {
1535  global $conf, $langs, $user, $mysoc;
1536 
1537  $error = 0;
1538 
1539  $this->invoice = null; // This will contains invoice if an invoice is created
1540 
1541  dol_syslog("subscriptionComplementaryActions subscriptionid=".$subscriptionid." option=".$option." accountid=".$accountid." datesubscription=".$datesubscription." paymentdate=".
1542  $paymentdate." label=".$label." amount=".$amount." num_chq=".$num_chq." autocreatethirdparty=".$autocreatethirdparty);
1543 
1544  // Insert into bank account directlty (if option choosed for) + link to llx_subscription if option is 'bankdirect'
1545  if ($option == 'bankdirect' && $accountid) {
1546  require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
1547 
1548  $acct = new Account($this->db);
1549  $result = $acct->fetch($accountid);
1550 
1551  $dateop = $paymentdate;
1552 
1553  $insertid = $acct->addline($dateop, $operation, $label, $amount, $num_chq, '', $user, $emetteur_nom, $emetteur_banque);
1554  if ($insertid > 0) {
1555  $inserturlid = $acct->add_url_line($insertid, $this->id, DOL_URL_ROOT.'/adherents/card.php?rowid=', $this->getFullname($langs), 'member');
1556  if ($inserturlid > 0) {
1557  // Update table subscription
1558  $sql = "UPDATE ".MAIN_DB_PREFIX."subscription SET fk_bank=".$insertid;
1559  $sql .= " WHERE rowid=".$subscriptionid;
1560 
1561  dol_syslog("subscription::subscription", LOG_DEBUG);
1562  $resql = $this->db->query($sql);
1563  if (!$resql) {
1564  $error++;
1565  $this->error = $this->db->lasterror();
1566  $this->errors[] = $this->error;
1567  }
1568  } else {
1569  $error++;
1570  $this->error = $acct->error;
1571  $this->errors = $acct->errors;
1572  }
1573  } else {
1574  $error++;
1575  $this->error = $acct->error;
1576  $this->errors = $acct->errors;
1577  }
1578  }
1579 
1580  // If option choosed, we create invoice
1581  if (($option == 'bankviainvoice' && $accountid) || $option == 'invoiceonly') {
1582  require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1583  require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/paymentterm.class.php';
1584 
1585  $invoice = new Facture($this->db);
1586  $customer = new Societe($this->db);
1587 
1588  if (!$error) {
1589  if (!($this->fk_soc > 0)) { // If not yet linked to a company
1590  if ($autocreatethirdparty) {
1591  // Create a linked thirdparty to member
1592  $companyalias = '';
1593  $fullname = $this->getFullName($langs);
1594 
1595  if ($this->morphy == 'mor') {
1596  $companyname = $this->company;
1597  if (!empty($fullname)) $companyalias = $fullname;
1598  } else {
1599  $companyname = $fullname;
1600  if (!empty($this->company)) $companyalias = $this->company;
1601  }
1602 
1603  $result = $customer->create_from_member($this, $companyname, $companyalias);
1604  if ($result < 0) {
1605  $this->error = $customer->error;
1606  $this->errors = $customer->errors;
1607  $error++;
1608  } else {
1609  $this->fk_soc = $result;
1610  }
1611  } else {
1612  $langs->load("errors");
1613  $this->error = $langs->trans("ErrorMemberNotLinkedToAThirpartyLinkOrCreateFirst");
1614  $this->errors[] = $this->error;
1615  $error++;
1616  }
1617  }
1618  }
1619  if (!$error) {
1620  $result = $customer->fetch($this->fk_soc);
1621  if ($result <= 0) {
1622  $this->error = $customer->error;
1623  $this->errors = $customer->errors;
1624  $error++;
1625  }
1626  }
1627 
1628  if (!$error) {
1629  // Create draft invoice
1630  $invoice->type = Facture::TYPE_STANDARD;
1631  $invoice->cond_reglement_id = $customer->cond_reglement_id;
1632  if (empty($invoice->cond_reglement_id)) {
1633  $paymenttermstatic = new PaymentTerm($this->db);
1634  $invoice->cond_reglement_id = $paymenttermstatic->getDefaultId();
1635  if (empty($invoice->cond_reglement_id)) {
1636  $error++;
1637  $this->error = 'ErrorNoPaymentTermRECEPFound';
1638  $this->errors[] = $this->error;
1639  }
1640  }
1641  $invoice->socid = $this->fk_soc;
1642  $invoice->date = $datesubscription;
1643 
1644  // Possibility to add external linked objects with hooks
1645  $invoice->linked_objects['subscription'] = $subscriptionid;
1646  if (!empty($_POST['other_linked_objects']) && is_array($_POST['other_linked_objects'])) {
1647  $invoice->linked_objects = array_merge($invoice->linked_objects, $_POST['other_linked_objects']);
1648  }
1649 
1650  $result = $invoice->create($user);
1651  if ($result <= 0) {
1652  $this->error = $invoice->error;
1653  $this->errors = $invoice->errors;
1654  $error++;
1655  } else {
1656  $this->invoice = $invoice;
1657  }
1658  }
1659 
1660  if (!$error) {
1661  // Add line to draft invoice
1662  $idprodsubscription = 0;
1663  if (!empty($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS) && (!empty($conf->product->enabled) || !empty($conf->service->enabled))) $idprodsubscription = $conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS;
1664 
1665  $vattouse = 0;
1666  if (isset($conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS) && $conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS == 'defaultforfoundationcountry') {
1667  $vattouse = get_default_tva($mysoc, $mysoc, $idprodsubscription);
1668  }
1669  //print xx".$vattouse." - ".$mysoc." - ".$customer;exit;
1670  $result = $invoice->addline($label, 0, 1, $vattouse, 0, 0, $idprodsubscription, 0, $datesubscription, '', 0, 0, '', 'TTC', $amount, 1);
1671  if ($result <= 0) {
1672  $this->error = $invoice->error;
1673  $this->errors = $invoice->errors;
1674  $error++;
1675  }
1676  }
1677 
1678  if (!$error) {
1679  // Validate invoice
1680  $result = $invoice->validate($user);
1681  if ($result <= 0) {
1682  $this->error = $invoice->error;
1683  $this->errors = $invoice->errors;
1684  $error++;
1685  }
1686  }
1687 
1688  if (!$error) {
1689  // TODO Link invoice with subscription ?
1690  }
1691 
1692  // Add payment onto invoice
1693  if (!$error && $option == 'bankviainvoice' && $accountid) {
1694  require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
1695  require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
1696  require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
1697 
1698  $amounts = array();
1699  $amounts[$invoice->id] = price2num($amount);
1700 
1701  $paiement = new Paiement($this->db);
1702  $paiement->datepaye = $paymentdate;
1703  $paiement->amounts = $amounts;
1704  $paiement->paiementid = dol_getIdFromCode($this->db, $operation, 'c_paiement', 'code', 'id', 1);
1705  $paiement->num_payment = $num_chq;
1706  $paiement->note_public = $label;
1707 
1708  if (!$error) {
1709  // Create payment line for invoice
1710  $paiement_id = $paiement->create($user);
1711  if (!$paiement_id > 0) {
1712  $this->error = $paiement->error;
1713  $this->errors = $paiement->errors;
1714  $error++;
1715  }
1716  }
1717 
1718  if (!$error) {
1719  // Add transaction into bank account
1720  $bank_line_id = $paiement->addPaymentToBank($user, 'payment', '(SubscriptionPayment)', $accountid, $emetteur_nom, $emetteur_banque);
1721  if (!($bank_line_id > 0)) {
1722  $this->error = $paiement->error;
1723  $this->errors = $paiement->errors;
1724  $error++;
1725  }
1726  }
1727 
1728  if (!$error && !empty($bank_line_id)) {
1729  // Update fk_bank into subscription table
1730  $sql = 'UPDATE '.MAIN_DB_PREFIX.'subscription SET fk_bank='.$bank_line_id;
1731  $sql .= ' WHERE rowid='.$subscriptionid;
1732 
1733  $result = $this->db->query($sql);
1734  if (!$result) {
1735  $error++;
1736  }
1737  }
1738 
1739  if (!$error) {
1740  // Set invoice as paid
1741  $invoice->set_paid($user);
1742  }
1743  }
1744 
1745  if (!$error) {
1746  // Define output language
1747  $outputlangs = $langs;
1748  $newlang = '';
1749  $lang_id = GETPOST('lang_id');
1750  if ($conf->global->MAIN_MULTILANGS && empty($newlang) && !empty($lang_id)) $newlang = $lang_id;
1751  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $customer->default_lang;
1752  if (!empty($newlang)) {
1753  $outputlangs = new Translate("", $conf);
1754  $outputlangs->setDefaultLang($newlang);
1755  }
1756  // Generate PDF (whatever is option MAIN_DISABLE_PDF_AUTOUPDATE) so we can include it into email
1757  //if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
1758 
1759  $invoice->generateDocument($invoice->model_pdf, $outputlangs);
1760  }
1761  }
1762 
1763  if ($error) {
1764  return -1;
1765  } else {
1766  return 1;
1767  }
1768  }
1769 
1770 
1777  public function validate($user)
1778  {
1779  global $langs, $conf;
1780 
1781  $error = 0;
1782  $now = dol_now();
1783 
1784  // Check parameters
1785  if ($this->statut == 1) {
1786  dol_syslog(get_class($this)."::validate statut of member does not allow this", LOG_WARNING);
1787  return 0;
1788  }
1789 
1790  $this->db->begin();
1791 
1792  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
1793  $sql .= " statut = 1";
1794  $sql .= ", datevalid = '".$this->db->idate($now)."'";
1795  $sql .= ", fk_user_valid=".$user->id;
1796  $sql .= " WHERE rowid = ".$this->id;
1797 
1798  dol_syslog(get_class($this)."::validate", LOG_DEBUG);
1799  $result = $this->db->query($sql);
1800  if ($result) {
1801  $this->statut = 1;
1802 
1803  // Call trigger
1804  $result = $this->call_trigger('MEMBER_VALIDATE', $user);
1805  if ($result < 0) {
1806  $error++;
1807  $this->db->rollback();
1808  return -1;
1809  }
1810  // End call triggers
1811 
1812  $this->datevalid = $now;
1813 
1814  $this->db->commit();
1815  return 1;
1816  } else {
1817  $this->error = $this->db->error();
1818  $this->db->rollback();
1819  return -1;
1820  }
1821  }
1822 
1823 
1830  public function resiliate($user)
1831  {
1832  global $langs, $conf;
1833 
1834  $error = 0;
1835 
1836  // Check parameters
1837  if ($this->statut == 0) {
1838  dol_syslog(get_class($this)."::resiliate statut of member does not allow this", LOG_WARNING);
1839  return 0;
1840  }
1841 
1842  $this->db->begin();
1843 
1844  $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
1845  $sql .= " statut = 0";
1846  $sql .= ", fk_user_valid=".$user->id;
1847  $sql .= " WHERE rowid = ".$this->id;
1848 
1849  $result = $this->db->query($sql);
1850  if ($result) {
1851  $this->statut = 0;
1852 
1853  // Call trigger
1854  $result = $this->call_trigger('MEMBER_RESILIATE', $user);
1855  if ($result < 0) {
1856  $error++;
1857  $this->db->rollback();
1858  return -1;
1859  }
1860  // End call triggers
1861 
1862  $this->db->commit();
1863  return 1;
1864  } else {
1865  $this->error = $this->db->error();
1866  $this->db->rollback();
1867  return -1;
1868  }
1869  }
1870 
1871 
1872  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1878  public function add_to_abo()
1879  {
1880  // phpcs:enable
1881  global $conf, $langs;
1882 
1883  include_once DOL_DOCUMENT_ROOT.'/mailmanspip/class/mailmanspip.class.php';
1884  $mailmanspip = new MailmanSpip($this->db);
1885 
1886  $err = 0;
1887 
1888  // mailman
1889  if (!empty($conf->global->ADHERENT_USE_MAILMAN) && !empty($conf->mailmanspip->enabled)) {
1890  $result = $mailmanspip->add_to_mailman($this);
1891 
1892  if ($result < 0) {
1893  if (!empty($mailmanspip->error)) $this->errors[] = $mailmanspip->error;
1894  $err += 1;
1895  }
1896  foreach ($mailmanspip->mladded_ko as $tmplist => $tmpemail) {
1897  $langs->load("errors");
1898  $this->errors[] = $langs->trans("ErrorFailedToAddToMailmanList", $tmpemail, $tmplist);
1899  }
1900  foreach ($mailmanspip->mladded_ok as $tmplist => $tmpemail) {
1901  $langs->load("mailmanspip");
1902  $this->mesgs[] = $langs->trans("SuccessToAddToMailmanList", $tmpemail, $tmplist);
1903  }
1904  }
1905 
1906  // spip
1907  if (!empty($conf->global->ADHERENT_USE_SPIP) && !empty($conf->mailmanspip->enabled)) {
1908  $result = $mailmanspip->add_to_spip($this);
1909  if ($result < 0) {
1910  $this->errors[] = $mailmanspip->error;
1911  $err += 1;
1912  }
1913  }
1914  if ($err) {
1915  return -$err;
1916  } else {
1917  return 1;
1918  }
1919  }
1920 
1921 
1922  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1928  public function del_to_abo()
1929  {
1930  // phpcs:enable
1931  global $conf, $langs;
1932 
1933  include_once DOL_DOCUMENT_ROOT.'/mailmanspip/class/mailmanspip.class.php';
1934  $mailmanspip = new MailmanSpip($this->db);
1935 
1936  $err = 0;
1937 
1938  // mailman
1939  if (!empty($conf->global->ADHERENT_USE_MAILMAN)) {
1940  $result = $mailmanspip->del_to_mailman($this);
1941  if ($result < 0) {
1942  if (!empty($mailmanspip->error)) $this->errors[] = $mailmanspip->error;
1943  $err += 1;
1944  }
1945 
1946  foreach ($mailmanspip->mlremoved_ko as $tmplist => $tmpemail) {
1947  $langs->load("errors");
1948  $this->errors[] = $langs->trans("ErrorFailedToRemoveToMailmanList", $tmpemail, $tmplist);
1949  }
1950  foreach ($mailmanspip->mlremoved_ok as $tmplist => $tmpemail) {
1951  $langs->load("mailmanspip");
1952  $this->mesgs[] = $langs->trans("SuccessToRemoveToMailmanList", $tmpemail, $tmplist);
1953  }
1954  }
1955 
1956  if ($conf->global->ADHERENT_USE_SPIP && !empty($conf->mailmanspip->enabled)) {
1957  $result = $mailmanspip->del_to_spip($this);
1958  if ($result < 0) {
1959  $this->errors[] = $mailmanspip->error;
1960  $err += 1;
1961  }
1962  }
1963  if ($err) {
1964  // error
1965  return -$err;
1966  } else {
1967  return 1;
1968  }
1969  }
1970 
1971 
1977  public function getCivilityLabel()
1978  {
1979  global $langs;
1980  $langs->load("dict");
1981 
1982  $code = (empty($this->civility_id) ? '' : $this->civility_id);
1983  if (empty($code)) return '';
1984  return $langs->getLabelFromKey($this->db, "Civility".$code, "c_civility", "code", "label", $code);
1985  }
1986 
2000  public function getNomUrl($withpictoimg = 0, $maxlen = 0, $option = 'card', $mode = '', $morecss = '', $save_lastsearch_value = -1, $notooltip = 0, $addlinktonotes = 0)
2001  {
2002  global $conf, $langs;
2003 
2004  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpictoimg) $withpictoimg = 0;
2005 
2006  $result = '';
2007  $label = '';
2008  $linkstart = '';
2009  $linkend = '';
2010 
2011  if (!empty($this->photo)) {
2012  $label .= '<div class="photointooltip">';
2013  $label .= Form::showphoto('memberphoto', $this, 80, 0, 0, 'photowithmargin photologintooltip', 'small', 0, 1);
2014  $label .= '</div><div style="clear: both;"></div>';
2015  }
2016 
2017  $label .= '<div class="centpercent">';
2018  $label .= img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Member").'</u>';
2019  $label .= ' '.$this->getLibStatut(4);
2020  if (!empty($this->ref)) $label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
2021  if (!empty($this->firstname) || !empty($this->lastname)) $label .= '<br><b>'.$langs->trans('Name').':</b> '.$this->getFullName($langs);
2022  if (!empty($this->company)) $label .= '<br><b>'.$langs->trans('Company').':</b> '.$this->company;
2023  $label .= '</div>';
2024 
2025  $url = DOL_URL_ROOT.'/adherents/card.php?rowid='.$this->id;
2026  if ($option == 'subscription') {
2027  $url = DOL_URL_ROOT.'/adherents/subscription.php?rowid='.$this->id;
2028  }
2029 
2030  if ($option != 'nolink') {
2031  // Add param to save lastsearch_values or not
2032  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2033  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
2034  if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
2035  }
2036 
2037  $linkstart .= '<a href="'.$url.'"';
2038  $linkclose = "";
2039  if (empty($notooltip)) {
2040  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2041  $langs->load("users");
2042  $label = $langs->trans("ShowUser");
2043  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
2044  }
2045  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
2046  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
2047  }
2048 
2049  $linkstart .= $linkclose.'>';
2050  $linkend = '</a>';
2051 
2052  $result .= $linkstart;
2053  if ($withpictoimg) $result .= '<div class="inline-block nopadding valignmiddle">';
2054  if ($withpictoimg) {
2055  $paddafterimage = '';
2056  if (abs($withpictoimg) == 1) $paddafterimage = 'style="margin-right: 3px;"';
2057  // Only picto
2058  if ($withpictoimg > 0)
2059  $picto = '<span class="nopadding'.($morecss ? ' userimg'.$morecss : '').'">'.
2060  img_object('', 'user', $paddafterimage.' '.($notooltip ? '' : 'class="classfortooltip"'), 0, 0, $notooltip ? 0 : 1).'</span>';
2061  // Picto must be a photo
2062  else {
2063  $picto = '<span class="nopadding'.($morecss ? ' userimg'.$morecss : '').'"'.($paddafterimage ? ' '.$paddafterimage : '').'>';
2064  $picto .= Form::showphoto('memberphoto', $this, 0, 0, 0, 'userphoto'.($withpictoimg == -3 ? 'small' : ''), 'mini', 0, 1);
2065  $picto .= '</span>';
2066  }
2067  $result .= $picto;
2068  }
2069  if ($withpictoimg > -2 && $withpictoimg != 2) {
2070  if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) $result .= '<span class="nopadding valignmiddle'.((!isset($this->statut) || $this->statut) ? '' : ' strikefordisabled').
2071  ($morecss ? ' usertext'.$morecss : '').'">';
2072  if ($mode == 'login') {
2073  $result .= dol_trunc($this->login, $maxlen);
2074  } elseif ($mode == 'ref') {
2075  $result .= $this->id;
2076  } else {
2077  $result .= $this->getFullName($langs, '', ($mode == 'firstname' ? 2 : ($mode == 'lastname' ? 4 : -1)), $maxlen);
2078  }
2079  if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) $result .= '</span>';
2080  }
2081  if ($withpictoimg) $result .= '</div>';
2082  $result .= $linkend;
2083 
2084  if ($addlinktonotes) {
2085  if ($this->note_private) {
2086  $notetoshow = $langs->trans("ViewPrivateNote").':<br>'.dol_string_nohtmltag($this->note_private, 1);
2087  $result .= ' <span class="note inline-block">';
2088  $result .= '<a href="'.DOL_URL_ROOT.'/adherents/note.php?id='.$this->id.'" class="classfortooltip" title="'.dol_escape_htmltag($notetoshow).'">';
2089  $result .= img_picto('', 'note');
2090  $result .= '</a>';
2091  $result .= '</span>';
2092  }
2093  }
2094 
2095  return $result;
2096  }
2097 
2104  public function getLibStatut($mode = 0)
2105  {
2106  return $this->LibStatut($this->statut, $this->need_subscription, $this->datefin, $mode);
2107  }
2108 
2109  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2119  public function LibStatut($status, $need_subscription, $date_end_subscription, $mode = 0)
2120  {
2121  // phpcs:enable
2122  global $langs;
2123  $langs->load("members");
2124 
2125  $statusType = '';
2126  $labelStatus = '';
2127  $labelStatusShort = '';
2128 
2129  if ($status == -1) {
2130  $statusType = 'status0';
2131  $labelStatus = $langs->trans("MemberStatusDraft");
2132  $labelStatusShort = $langs->trans("MemberStatusDraftShort");
2133  } elseif ($status >= 1) {
2134  if ($need_subscription == 0) {
2135  $statusType = 'status4';
2136  $labelStatus = $langs->trans("MemberStatusNoSubscription");
2137  $labelStatusShort = $langs->trans("MemberStatusNoSubscriptionShort");
2138  } elseif (!$date_end_subscription) {
2139  $statusType = 'status1';
2140  $labelStatus = $langs->trans("MemberStatusActive");
2141  $labelStatusShort = $langs->trans("MemberStatusActiveShort");
2142  } elseif ($date_end_subscription < time()) {
2143  $statusType = 'status3';
2144  $labelStatus = $langs->trans("MemberStatusActiveLate");
2145  $labelStatusShort = $langs->trans("MemberStatusActiveLateShort");
2146  } else {
2147  $statusType = 'status4';
2148  $labelStatus = $langs->trans("MemberStatusPaid");
2149  $labelStatusShort = $langs->trans("MemberStatusPaidShort");
2150  }
2151  } elseif ($status == 0) {
2152  $statusType = 'status6';
2153  $labelStatus = $langs->trans("MemberStatusResiliated");
2154  $labelStatusShort = $langs->trans("MemberStatusResiliatedShort");
2155  }
2156 
2157  return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode);
2158  }
2159 
2160 
2161  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2167  public function load_state_board()
2168  {
2169  // phpcs:enable
2170  global $conf;
2171 
2172  $this->nb = array();
2173 
2174  $sql = "SELECT count(a.rowid) as nb";
2175  $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a";
2176  $sql .= " WHERE a.statut > 0";
2177  $sql .= " AND a.entity IN (".getEntity('adherent').")";
2178 
2179  $resql = $this->db->query($sql);
2180  if ($resql) {
2181  while ($obj = $this->db->fetch_object($resql)) {
2182  $this->nb["members"] = $obj->nb;
2183  }
2184  $this->db->free($resql);
2185  return 1;
2186  } else {
2187  dol_print_error($this->db);
2188  $this->error = $this->db->error();
2189  return -1;
2190  }
2191  }
2192 
2193  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2201  public function load_board($user, $mode)
2202  {
2203  // phpcs:enable
2204  global $conf, $langs;
2205 
2206  if ($user->socid) return -1; // protection pour eviter appel par utilisateur externe
2207 
2208  $now = dol_now();
2209 
2210  $sql = "SELECT a.rowid, a.datefin, a.statut";
2211  $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a";
2212  $sql .= ", ".MAIN_DB_PREFIX."adherent_type as t";
2213  $sql .= " WHERE a.fk_adherent_type = t.rowid";
2214  if ($mode == 'expired') {
2215  $sql .= " AND a.statut = 1";
2216  $sql .= " AND a.entity IN (".getEntity('adherent').")";
2217  $sql .= " AND ((a.datefin IS NULL or a.datefin < '".$this->db->idate($now)."') AND t.subscription = '1')";
2218  } elseif ($mode == 'shift') {
2219  $sql .= " AND a.statut = -1";
2220  $sql .= " AND a.entity IN (".getEntity('adherent').")";
2221  }
2222 
2223  $resql = $this->db->query($sql);
2224  if ($resql) {
2225  $langs->load("members");
2226 
2227  $warning_delay = 0;
2228  $url = '';
2229  $label = '';
2230  $labelShort = '';
2231 
2232  if ($mode == 'expired') {
2233  $warning_delay = $conf->adherent->subscription->warning_delay / 60 / 60 / 24;
2234  $label = $langs->trans("MembersWithSubscriptionToReceive");
2235  $labelShort = $langs->trans("MembersWithSubscriptionToReceiveShort");
2236  $url = DOL_URL_ROOT.'/adherents/list.php?mainmenu=members&amp;statut=1&amp;filter=outofdate';
2237  } elseif ($mode == 'shift') {
2238  $warning_delay = $conf->adherent->subscription->warning_delay / 60 / 60 / 24;
2239  $url = DOL_URL_ROOT.'/adherents/list.php?mainmenu=members&amp;statut=-1';
2240  $label = $langs->trans("MembersListToValid");
2241  $labelShort = $langs->trans("ToValidate");
2242  }
2243 
2244  $response = new WorkboardResponse();
2245  $response->warning_delay = $warning_delay;
2246  $response->label = $label;
2247  $response->labelShort = $labelShort;
2248  $response->url = $url;
2249  $response->img = img_object('', "user");
2250 
2251  $adherentstatic = new Adherent($this->db);
2252 
2253  while ($obj = $this->db->fetch_object($resql)) {
2254  $response->nbtodo++;
2255 
2256  $adherentstatic->datefin = $this->db->jdate($obj->datefin);
2257  $adherentstatic->statut = $obj->statut;
2258 
2259  if ($adherentstatic->hasDelay()) {
2260  $response->nbtodolate++;
2261  }
2262  }
2263 
2264  return $response;
2265  } else {
2266  dol_print_error($this->db);
2267  $this->error = $this->db->error();
2268  return -1;
2269  }
2270  }
2271 
2272 
2284  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
2285  {
2286  global $conf, $langs;
2287 
2288  $langs->load("orders");
2289 
2290  if (!dol_strlen($modele)) {
2291  $modele = 'standard';
2292 
2293  if ($this->model_pdf) {
2294  $modele = $this->model_pdf;
2295  } elseif (!empty($conf->global->ADHERENT_ADDON_PDF)) {
2296  $modele = $conf->global->ADHERENT_ADDON_PDF;
2297  }
2298  }
2299 
2300  $modelpath = "core/modules/member/doc/";
2301 
2302  return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
2303  }
2304 
2305 
2313  public function initAsSpecimen()
2314  {
2315  global $user, $langs;
2316  $now = dol_now();
2317 
2318  // Initialise parametres
2319  $this->id = 0;
2320  $this->entity = 1;
2321  $this->specimen = 1;
2322  $this->civility_id = 0;
2323  $this->lastname = 'DOLIBARR';
2324  $this->firstname = 'SPECIMEN';
2325  $this->gender = 'man';
2326  $this->login = 'dolibspec';
2327  $this->pass = 'dolibspec';
2328  $this->company = 'Societe ABC';
2329  $this->address = '61 jump street';
2330  $this->zip = '75000';
2331  $this->town = 'Paris';
2332  $this->country_id = 1;
2333  $this->country_code = 'FR';
2334  $this->country = 'France';
2335  $this->morphy = 'mor';
2336  $this->email = 'specimen@specimen.com';
2337  $this->socialnetworks = array(
2338  'skype' => 'skypepseudo',
2339  'twitter' => 'twitterpseudo',
2340  'facebook' => 'facebookpseudo',
2341  'linkedin' => 'linkedinpseudo',
2342  );
2343  $this->phone = '0999999999';
2344  $this->phone_perso = '0999999998';
2345  $this->phone_mobile = '0999999997';
2346  $this->note_public = 'This is a public note';
2347  $this->note_private = 'This is a private note';
2348  $this->birth = $now;
2349  $this->photo = '';
2350  $this->public = 1;
2351  $this->statut = 0;
2352 
2353  $this->datefin = $now;
2354  $this->datevalid = $now;
2355 
2356  $this->typeid = 1; // Id type adherent
2357  $this->type = 'Type adherent'; // Libelle type adherent
2358  $this->need_subscription = 0;
2359 
2360  $this->first_subscription_date = $now;
2361  $this->first_subscription_date_start = $this->first_subscription_date;
2362  $this->first_subscription_date_end = dol_time_plus_duree($this->first_subscription_date_start, 1, 'y');
2363  $this->first_subscription_amount = 10;
2364 
2365  $this->last_subscription_date = $this->first_subscription_date;
2366  $this->last_subscription_date_start = $this->first_subscription_date;
2367  $this->last_subscription_date_end = dol_time_plus_duree($this->last_subscription_date_start, 1, 'y');
2368  $this->last_subscription_amount = 10;
2369  return 1;
2370  }
2371 
2372 
2373  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2374  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2384  public function _load_ldap_dn($info, $mode = 0)
2385  {
2386  // phpcs:enable
2387  global $conf;
2388  $dn = '';
2389  if ($mode == 0) $dn = $conf->global->LDAP_KEY_MEMBERS."=".$info[$conf->global->LDAP_KEY_MEMBERS].",".$conf->global->LDAP_MEMBER_DN;
2390  if ($mode == 1) $dn = $conf->global->LDAP_MEMBER_DN;
2391  if ($mode == 2) $dn = $conf->global->LDAP_KEY_MEMBERS."=".$info[$conf->global->LDAP_KEY_MEMBERS];
2392  return $dn;
2393  }
2394 
2395 
2396  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2397  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2403  public function _load_ldap_info()
2404  {
2405  // phpcs:enable
2406  global $conf, $langs;
2407 
2408  $info = array();
2409  $socialnetworks = getArrayOfSocialNetworks();
2410  $keymodified = false;
2411 
2412  // Object classes
2413  $info["objectclass"] = explode(',', $conf->global->LDAP_MEMBER_OBJECT_CLASS);
2414 
2415  $this->fullname = $this->getFullName($langs);
2416 
2417  // For avoid ldap error when firstname and lastname are empty
2418  if ($this->morphy == 'mor' && (empty($this->fullname) || $this->fullname == $this->company)) {
2419  $this->fullname = $this->company;
2420  $this->lastname = $this->company;
2421  }
2422 
2423  // Possible LDAP KEY (constname => varname)
2424  $ldapkey = array(
2425  'LDAP_MEMBER_FIELD_FULLNAME' => 'fullname',
2426  'LDAP_MEMBER_FIELD_NAME' => 'lastname',
2427  'LDAP_MEMBER_FIELD_LOGIN' => 'login',
2428  'LDAP_MEMBER_FIELD_LOGIN_SAMBA' => 'login',
2429  'LDAP_MEMBER_FIELD_MAIL' => 'email'
2430  );
2431 
2432  // Member
2433  foreach ($ldapkey as $constname => $varname) {
2434  if (!empty($this->$varname) && !empty($conf->global->$constname)) {
2435  $info[$conf->global->$constname] = $this->$varname;
2436 
2437  // Check if it is the LDAP key and if its value has been changed
2438  if (!empty($conf->global->LDAP_KEY_MEMBERS) && $conf->global->LDAP_KEY_MEMBERS == $conf->global->$constname) {
2439  if (!empty($this->oldcopy) && $this->$varname != $this->oldcopy->$varname) $keymodified = true; // For check if LDAP key has been modified
2440  }
2441  }
2442  }
2443  if ($this->firstname && !empty($conf->global->LDAP_MEMBER_FIELD_FIRSTNAME)) $info[$conf->global->LDAP_MEMBER_FIELD_FIRSTNAME] = $this->firstname;
2444  if ($this->poste && !empty($conf->global->LDAP_MEMBER_FIELD_TITLE)) $info[$conf->global->LDAP_MEMBER_FIELD_TITLE] = $this->poste;
2445  if ($this->company && !empty($conf->global->LDAP_MEMBER_FIELD_COMPANY)) $info[$conf->global->LDAP_MEMBER_FIELD_COMPANY] = $this->company;
2446  if ($this->address && !empty($conf->global->LDAP_MEMBER_FIELD_ADDRESS)) $info[$conf->global->LDAP_MEMBER_FIELD_ADDRESS] = $this->address;
2447  if ($this->zip && !empty($conf->global->LDAP_MEMBER_FIELD_ZIP)) $info[$conf->global->LDAP_MEMBER_FIELD_ZIP] = $this->zip;
2448  if ($this->town && !empty($conf->global->LDAP_MEMBER_FIELD_TOWN)) $info[$conf->global->LDAP_MEMBER_FIELD_TOWN] = $this->town;
2449  if ($this->country_code && !empty($conf->global->LDAP_MEMBER_FIELD_COUNTRY)) $info[$conf->global->LDAP_MEMBER_FIELD_COUNTRY] = $this->country_code;
2450  foreach ($socialnetworks as $key => $value) {
2451  if ($this->socialnetworks[$value['label']] && !empty($conf->global->{'LDAP_MEMBER_FIELD_'.strtoupper($value['label'])})) {
2452  $info[$conf->global->{'LDAP_MEMBER_FIELD_'.strtoupper($value['label'])}] = $this->socialnetworks[$value['label']];
2453  }
2454  }
2455  if ($this->phone && !empty($conf->global->LDAP_MEMBER_FIELD_PHONE)) $info[$conf->global->LDAP_MEMBER_FIELD_PHONE] = $this->phone;
2456  if ($this->phone_perso && !empty($conf->global->LDAP_MEMBER_FIELD_PHONE_PERSO)) $info[$conf->global->LDAP_MEMBER_FIELD_PHONE_PERSO] = $this->phone_perso;
2457  if ($this->phone_mobile && !empty($conf->global->LDAP_MEMBER_FIELD_MOBILE)) $info[$conf->global->LDAP_MEMBER_FIELD_MOBILE] = $this->phone_mobile;
2458  if ($this->fax && !empty($conf->global->LDAP_MEMBER_FIELD_FAX)) $info[$conf->global->LDAP_MEMBER_FIELD_FAX] = $this->fax;
2459  if ($this->note_private && !empty($conf->global->LDAP_MEMBER_FIELD_DESCRIPTION)) $info[$conf->global->LDAP_MEMBER_FIELD_DESCRIPTION] = dol_string_nohtmltag($this->note_private, 2);
2460  if ($this->note_public && !empty($conf->global->LDAP_MEMBER_FIELD_NOTE_PUBLIC)) $info[$conf->global->LDAP_MEMBER_FIELD_NOTE_PUBLIC] = dol_string_nohtmltag($this->note_public, 2);
2461  if ($this->birth && !empty($conf->global->LDAP_MEMBER_FIELD_BIRTHDATE)) $info[$conf->global->LDAP_MEMBER_FIELD_BIRTHDATE] = dol_print_date($this->birth, 'dayhourldap');
2462  if (isset($this->statut) && !empty($conf->global->LDAP_FIELD_MEMBER_STATUS)) $info[$conf->global->LDAP_FIELD_MEMBER_STATUS] = $this->statut;
2463  if ($this->datefin && !empty($conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION)) $info[$conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION] = dol_print_date($this->datefin, 'dayhourldap');
2464 
2465  // When password is modified
2466  if (!empty($this->pass)) {
2467  if (!empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD)) {
2468  $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD] = $this->pass; // this->pass = mot de passe non crypte
2469  }
2470  if (!empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED)) {
2471  $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED] = dol_hash($this->pass, 4); // Create OpenLDAP MD5 password (TODO add type of encryption)
2472  }
2473  } // Set LDAP password if possible
2474  elseif ($conf->global->LDAP_SERVER_PROTOCOLVERSION !== '3') { // If ldap key is modified and LDAPv3 we use ldap_rename function for avoid lose encrypt password
2475  if (!empty($conf->global->DATABASE_PWD_ENCRYPTED)) {
2476  // Just for the default MD5 !
2477  if (empty($conf->global->MAIN_SECURITY_HASH_ALGO)) {
2478  if ($this->pass_indatabase_crypted && !empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED)) {
2479  // Create OpenLDAP MD5 password from Dolibarr MD5 password
2480  // Note: This suppose that "pass_indatabase_crypted" is a md5 (guaranted by the previous test if "(empty($conf->global->MAIN_SECURITY_HASH_ALGO))"
2481  $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED] = '{md5}'.base64_encode(hex2bin($this->pass_indatabase_crypted));
2482  }
2483  }
2484  } // Use $this->pass_indatabase value if exists
2485  elseif (!empty($this->pass_indatabase)) {
2486  if (!empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD)) $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD] = $this->pass_indatabase; // $this->pass_indatabase = mot de passe non crypte
2487  if (!empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED)) $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED] = dol_hash($this->pass_indatabase, 4); // md5 for OpenLdap TODO add type of encryption
2488  }
2489  }
2490 
2491  // Subscriptions
2492  if ($this->first_subscription_date && !empty($conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE)) $info[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE] = dol_print_date($this->first_subscription_date, 'dayhourldap');
2493  if (isset($this->first_subscription_amount) && !empty($conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT)) $info[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT] = $this->first_subscription_amount;
2494  if ($this->last_subscription_date && !empty($conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE)) $info[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE] = dol_print_date($this->last_subscription_date, 'dayhourldap');
2495  if (isset($this->last_subscription_amount) && !empty($conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT)) $info[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT] = $this->last_subscription_amount;
2496 
2497  return $info;
2498  }
2499 
2500 
2507  public function info($id)
2508  {
2509  $sql = 'SELECT a.rowid, a.datec as datec,';
2510  $sql .= ' a.datevalid as datev,';
2511  $sql .= ' a.tms as datem,';
2512  $sql .= ' a.fk_user_author, a.fk_user_valid, a.fk_user_mod';
2513  $sql .= ' FROM '.MAIN_DB_PREFIX.'adherent as a';
2514  $sql .= ' WHERE a.rowid = '.$id;
2515 
2516  dol_syslog(get_class($this)."::info", LOG_DEBUG);
2517  $result = $this->db->query($sql);
2518  if ($result) {
2519  if ($this->db->num_rows($result)) {
2520  $obj = $this->db->fetch_object($result);
2521  $this->id = $obj->rowid;
2522  if ($obj->fk_user_author) {
2523  $cuser = new User($this->db);
2524  $cuser->fetch($obj->fk_user_author);
2525  $this->user_creation = $cuser;
2526  }
2527 
2528  if ($obj->fk_user_valid) {
2529  $vuser = new User($this->db);
2530  $vuser->fetch($obj->fk_user_valid);
2531  $this->user_validation = $vuser;
2532  }
2533 
2534  if ($obj->fk_user_mod) {
2535  $muser = new User($this->db);
2536  $muser->fetch($obj->fk_user_mod);
2537  $this->user_modification = $muser;
2538  }
2539 
2540  $this->date_creation = $this->db->jdate($obj->datec);
2541  $this->date_validation = $this->db->jdate($obj->datev);
2542  $this->date_modification = $this->db->jdate($obj->datem);
2543  }
2544 
2545  $this->db->free($result);
2546  } else {
2547  dol_print_error($this->db);
2548  }
2549  }
2550 
2556  public function getNbOfEMailings()
2557  {
2558  $sql = "SELECT count(mc.email) as nb";
2559  $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
2560  $sql .= " WHERE mc.email = '".$this->db->escape($this->email)."'";
2561  $sql .= " AND mc.statut NOT IN (-1,0)"; // -1 erreur, 0 non envoye, 1 envoye avec succes
2562 
2563  $resql = $this->db->query($sql);
2564  if ($resql) {
2565  $obj = $this->db->fetch_object($resql);
2566  $nb = $obj->nb;
2567 
2568  $this->db->free($resql);
2569  return $nb;
2570  } else {
2571  $this->error = $this->db->error();
2572  return -1;
2573  }
2574  }
2575 
2586  public function setCategories($categories)
2587  {
2588  // Handle single category
2589  if (!is_array($categories)) {
2590  $categories = array($categories);
2591  }
2592 
2593  // Get current categories
2594  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
2595  $c = new Categorie($this->db);
2596  $existing = $c->containing($this->id, Categorie::TYPE_MEMBER, 'id');
2597 
2598  // Diff
2599  if (is_array($existing)) {
2600  $to_del = array_diff($existing, $categories);
2601  $to_add = array_diff($categories, $existing);
2602  } else {
2603  $to_del = array(); // Nothing to delete
2604  $to_add = $categories;
2605  }
2606 
2607  // Process
2608  foreach ($to_del as $del) {
2609  if ($c->fetch($del) > 0) {
2610  $c->del_type($this, Categorie::TYPE_MEMBER);
2611  }
2612  }
2613  foreach ($to_add as $add) {
2614  if ($c->fetch($add) > 0) {
2615  $c->add_type($this, Categorie::TYPE_MEMBER);
2616  }
2617  }
2618 
2619  return;
2620  }
2621 
2630  public static function replaceThirdparty($db, $origin_id, $dest_id)
2631  {
2632  $tables = array('adherent');
2633 
2634  return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
2635  }
2636 
2642  public function hasDelay()
2643  {
2644  global $conf;
2645 
2646  //Only valid members
2647  if ($this->statut <= 0) return false;
2648  if (!$this->datefin) return false;
2649 
2650  $now = dol_now();
2651 
2652  return $this->datefin < ($now - $conf->adherent->subscription->warning_delay);
2653  }
2654 
2655 
2663  public function sendReminderForExpiredSubscription($daysbeforeendlist = '10')
2664  {
2665  global $conf, $langs, $mysoc, $user;
2666 
2667  $error = 0;
2668  $this->output = '';
2669  $this->error = '';
2670 
2671  $blockingerrormsg = '';
2672 
2673  if (empty($conf->adherent->enabled)) { // Should not happen. If module disabled, cron job should not be visible.
2674  $langs->load("agenda");
2675  $this->output = $langs->trans('ModuleNotEnabled', $langs->transnoentitiesnoconv("Adherent"));
2676  return 0;
2677  }
2678  if (empty($conf->global->MEMBER_REMINDER_EMAIL)) {
2679  $langs->load("agenda");
2680  $this->output = $langs->trans('EventRemindersByEmailNotEnabled', $langs->transnoentitiesnoconv("Adherent"));
2681  return 0;
2682  }
2683 
2684  $now = dol_now();
2685  $nbok = 0;
2686  $nbko = 0;
2687 
2688  $listofmembersok = array();
2689  $listofmembersko = array();
2690 
2691  $arraydaysbeforeend = explode(';', $daysbeforeendlist);
2692  foreach ($arraydaysbeforeend as $daysbeforeend) { // Loop on each delay
2693  dol_syslog(__METHOD__.' - Process delta = '.$daysbeforeend, LOG_DEBUG);
2694 
2695  if (!is_numeric($daysbeforeend)) {
2696  $blockingerrormsg = "Value for delta is not a positive or negative numeric";
2697  $nbko++;
2698  break;
2699  }
2700 
2701  $tmp = dol_getdate($now);
2702  $datetosearchfor = dol_time_plus_duree(dol_mktime(0, 0, 0, $tmp['mon'], $tmp['mday'], $tmp['year']), $daysbeforeend, 'd');
2703 
2704  $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'adherent';
2705  $sql .= " WHERE entity = ".$conf->entity; // Do not use getEntity('adherent').")" here, we want the batch to be on its entity only;
2706  $sql .= " AND datefin = '".$this->db->idate($datetosearchfor)."'";
2707 
2708  $resql = $this->db->query($sql);
2709  if ($resql) {
2710  $num_rows = $this->db->num_rows($resql);
2711 
2712  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
2713  $adherent = new Adherent($this->db);
2714  $formmail = new FormMail($this->db);
2715 
2716  $i = 0;
2717  while ($i < $num_rows) {
2718  $obj = $this->db->fetch_object($resql);
2719 
2720  $adherent->fetch($obj->rowid, '', '', '', true, true);
2721 
2722  if (empty($adherent->email)) {
2723  $nbko++;
2724  $listofmembersko[$adherent->id] = $adherent->id;
2725  } else {
2726  $adherent->fetch_thirdparty();
2727 
2728  // 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.
2729  $languagefromcountrycode = getLanguageCodeFromCountryCode($adherent->country_code ? $adherent->country_code : $adherent->thirdparty->country_code);
2730  $languagecodeformember = (empty($adherent->thirdparty->default_lang) ? ($languagefromcountrycode ? $languagefromcountrycode : $mysoc->default_lang) : $adherent->thirdparty->default_lang);
2731 
2732  // Send reminder email
2733  $outputlangs = new Translate('', $conf);
2734  $outputlangs->setDefaultLang($languagecodeformember);
2735  $outputlangs->loadLangs(array("main", "members"));
2736  dol_syslog("sendReminderForExpiredSubscription Language for member id ".$adherent->id." set to ".$outputlangs->defaultlang." mysoc->default_lang=".$mysoc->default_lang);
2737 
2738  $arraydefaultmessage = null;
2739  $labeltouse = $conf->global->ADHERENT_EMAIL_TEMPLATE_REMIND_EXPIRATION;
2740 
2741  if (!empty($labeltouse)) $arraydefaultmessage = $formmail->getEMailTemplate($this->db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
2742 
2743  if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
2744  $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $adherent);
2745  //if (is_array($adherent->thirdparty)) $substitutionarraycomp = ...
2746  complete_substitutions_array($substitutionarray, $outputlangs, $adherent);
2747 
2748  $subject = make_substitutions($arraydefaultmessage->topic, $substitutionarray, $outputlangs);
2749  $msg = make_substitutions($arraydefaultmessage->content, $substitutionarray, $outputlangs);
2750  $from = $conf->global->ADHERENT_MAIL_FROM;
2751  $to = $adherent->email;
2752 
2753  $trackid = 'mem'.$adherent->id;
2754  $moreinheader = 'X-Dolibarr-Info: sendReminderForExpiredSubscription'."\r\n";
2755 
2756  include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
2757  $cmail = new CMailFile($subject, $to, $from, $msg, array(), array(), array(), '', '', 0, 1, '', '', $trackid, $moreinheader);
2758  $result = $cmail->sendfile();
2759  if (!$result) {
2760  $error++;
2761  $this->error = $cmail->error;
2762  if (!is_null($cmail->errors)) {
2763  $this->errors += $cmail->errors;
2764  }
2765  $nbko++;
2766  $listofmembersko[$adherent->id] = $adherent->id;
2767  } else {
2768  $nbok++;
2769  $listofmembersok[$adherent->id] = $adherent->id;
2770 
2771  $message = $msg;
2772  $sendto = $to;
2773  $sendtocc = '';
2774  $sendtobcc = '';
2775  $actioncode = 'EMAIL';
2776  $extraparams = '';
2777 
2778  $actionmsg = '';
2779  $actionmsg2 = $langs->transnoentities('MailSentBy').' '.CMailFile::getValidAddress($from, 4, 0, 1).' '.$langs->transnoentities('To').' '.
2780  CMailFile::getValidAddress($sendto, 4, 0, 1);
2781  if ($message) {
2782  $actionmsg = $langs->transnoentities('MailFrom').': '.dol_escape_htmltag($from);
2783  $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTo').': '.dol_escape_htmltag($sendto));
2784  if ($sendtocc) $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc').": ".dol_escape_htmltag($sendtocc));
2785  $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic').": ".$subject);
2786  $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody').":");
2787  $actionmsg = dol_concatdesc($actionmsg, $message);
2788  }
2789 
2790  require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
2791 
2792  // Insert record of emails sent
2793  $actioncomm = new ActionComm($this->db);
2794 
2795  $actioncomm->type_code = 'AC_OTH_AUTO'; // Type of event ('AC_OTH', 'AC_OTH_AUTO', 'AC_XXX'...)
2796  $actioncomm->code = 'AC_'.$actioncode;
2797  $actioncomm->label = $actionmsg2;
2798  $actioncomm->note_private = $actionmsg;
2799  $actioncomm->fk_project = 0;
2800  $actioncomm->datep = $now;
2801  $actioncomm->datef = $now;
2802  $actioncomm->percentage = -1; // Not applicable
2803  $actioncomm->socid = $adherent->thirdparty->id;
2804  $actioncomm->contact_id = 0;
2805  $actioncomm->authorid = $user->id; // User saving action
2806  $actioncomm->userownerid = $user->id; // Owner of action
2807  // Fields when action is en email (content should be added into note)
2808  $actioncomm->email_msgid = $cmail->msgid;
2809  $actioncomm->email_from = $from;
2810  $actioncomm->email_sender = '';
2811  $actioncomm->email_to = $to;
2812  $actioncomm->email_tocc = $sendtocc;
2813  $actioncomm->email_tobcc = $sendtobcc;
2814  $actioncomm->email_subject = $subject;
2815  $actioncomm->errors_to = '';
2816 
2817  $actioncomm->fk_element = $adherent->id;
2818  $actioncomm->elementtype = $adherent->element;
2819 
2820  $actioncomm->extraparams = $extraparams;
2821 
2822  $actioncomm->create($user);
2823  }
2824  } else {
2825  $blockingerrormsg = "Can't find email template, defined into member module setup, to use for reminding";
2826 
2827  $nbko++;
2828  $listofmembersko[$adherent->id] = $adherent->id;
2829 
2830  break;
2831  }
2832  }
2833 
2834  $i++;
2835  }
2836  } else {
2837  $this->error = $this->db->lasterror();
2838  return 1;
2839  }
2840  }
2841 
2842  if ($blockingerrormsg) {
2843  $this->error = $blockingerrormsg;
2844  return 1;
2845  } else {
2846  $this->output = 'Found '.($nbok + $nbko).' members to send reminder to.';
2847  $this->output .= ' Send email successfuly to '.$nbok.' members';
2848  if (is_array($listofmembersok)) {
2849  $listofids = '';
2850  $i = 0;
2851  foreach ($listofmembersok as $idmember) {
2852  if ($i > 100) {
2853  $listofids .= ', ...';
2854  break;
2855  }
2856  if (empty($listofids)) {
2857  $listofids .= ' [';
2858  } else {
2859  $listofids .= ', ';
2860  }
2861  $listofids .= $idmember;
2862  $i++;
2863  }
2864  if ($listofids) $listofids .= ']';
2865  $this->output .= $listofids;
2866  }
2867  if ($nbko) {
2868  $this->output .= ' - Canceled for '.$nbko.' member (no email or email sending error)';
2869  if (is_array($listofmembersko)) {
2870  $listofids = '';
2871  $i = 0;
2872  foreach ($listofmembersko as $idmember) {
2873  if ($i > 100) {
2874  $listofids .= ', ...';
2875  break;
2876  }
2877  if (empty($listofids)) {
2878  $listofids .= ' [';
2879  } else {
2880  $listofids .= ', ';
2881  }
2882  $listofids .= $idmember;
2883  $i++;
2884  }
2885  if ($listofids) $listofids .= ']';
2886  $this->output .= $listofids;
2887  }
2888  }
2889  }
2890 
2891  return 0;
2892  }
2893 }
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
resiliate($user)
Fonction qui resilie un adherent.
del_to_abo()
Function to delete a member from external tools like mailing-list, spip, etc.
LibStatut($status, $need_subscription, $date_end_subscription, $mode=0)
Renvoi le libelle d&#39;un statut donne.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto= 'UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
setCategories($categories)
Sets object to supplied categories.
dol_hash($chain, $type= '0')
Returns a hash of a string.
Classe permettant la generation du formulaire html d&#39;envoi de mail unitaire Usage: $formail = new For...
const TYPE_STANDARD
Standard invoice.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
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...
if(!empty($arrayfields['u.datec']['checked'])) print_liste_field_titre("DateCreationShort"u if(!empty($arrayfields['u.tms']['checked'])) print_liste_field_titre("DateModificationShort"u if(!empty($arrayfields['u.statut']['checked'])) print_liste_field_titre("Status"u statut
Definition: list.php:632
subscription($date, $amount, $accountid=0, $operation= '', $label= '', $num_chq= '', $emetteur_nom= '', $emetteur_banque= '', $datesubend=0)
Insert subscription into database and eventually add links to banks, mailman, etc...
getCivilityLabel()
Return civility label of a member.
setUpperOrLowerCase()
Set to upper or ucwords/lower if needed.
Class to manage agenda events (actions)
getArrayOfSocialNetworks()
Get array of social network dictionary.
validate($user)
Function that validate a member.
dol_now($mode= 'auto')
Return date for now.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
Class to manage Dolibarr users.
Definition: user.class.php:44
add_to_abo()
Function to add member into external tools mailing-list, spip, etc.
setUserId($userid)
Set link to a user.
getNomUrl($withpictoimg=0, $maxlen=0, $option= 'card', $mode= '', $morecss= '', $save_lastsearch_value=-1, $notooltip=0, $addlinktonotes=0)
Return clicable name (with picto eventually)
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
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...
setThirdPartyId($thirdpartyid)
Set link to a third party.
_load_ldap_info()
Initialise tableau info (tableau des attributs LDAP)
getFullName($langs, $option=0, $nameorder=-1, $maxlen=0)
Return full name (civility+&#39; &#39;+name+&#39; &#39;+lastname)
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...
create($user, $notrigger=0)
Create a member into database.
fetch_name($firstname, $lastname)
Method to load member from its name.
fetch($rowid, $ref= '', $fk_soc= '', $ref_ext= '', $fetch_optionals=true, $fetch_subscriptions=true)
Load member from database.
$conf db
API class for accounts.
Definition: inc.php:54
Class to manage bank accounts.
getLanguageCodeFromCountryCode($countrycode)
Return default language from country code.
_load_ldap_dn($info, $mode=0)
Retourne chaine DN complete dans l&#39;annuaire LDAP pour l&#39;objet.
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.
insertExtraFields($trigger= '', $userused=null)
Add/Update all extra fields values for the current object.
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null)
Return array of possible common substitutions.
getNbOfEMailings()
Return number of mass Emailing received by this member with its email.
info($id)
Load type info information in the member object.
setPassword($user, $password= '', $isencrypted=0, $notrigger=0, $nosyncuser=0)
Change password of a user.
Class to manage third parties objects (customers, suppliers, prospects...)
fetch_subscriptions()
Function to get member subscriptions data first_subscription_date, first_subscription_date_start, first_subscription_date_end, first_subscription_amount last_subscription_date, last_subscription_date_start, last_subscription_date_end, last_subscription_amount.
Class to manage categories.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
sendReminderForExpiredSubscription($daysbeforeendlist= '10')
Send reminders by emails before subscription end CAN BE A CRON TASK.
static getValidAddress($address, $format, $encode=0, $maxnumberofemail=0)
Return a formatted address string for SMTP protocol.
static replaceThirdparty($db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,$sendto,$replyto,$message,$filepath,$mimetype,$filename,$cc,$ccc,$deliveryreceipt,$msgishtml,$errors_to,$css,$trackid,$moreinheader,$sendcontext,$replyto); $mailfile-&gt;sendfile();.
static commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
Class to manage payments of customer invoices.
Class to manage members of a foundation.
dol_getdate($timestamp, $fast=false, $forcetimezone= '')
Return an array with locale date info.
fetch_login($login)
Method to load member from its login.
update($user, $notrigger=0, $nosyncuser=0, $nosyncuserpass=0, $nosyncthirdparty=0, $action= 'update')
Update a member in database (standard information and password)
hasDelay()
Return if a member is late (subscription late) or not.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.
deleteExtraFields()
Delete all extra fields values for the current object.
Class to manage translations.
__construct($db)
Constructor.
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this-&gt;array_options This method is in most cases call...
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.
Class to manage subscriptions of foundation members.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_getIdFromCode($db, $key, $tablename, $fieldkey= 'code', $fieldid= 'id', $entityfilter=0)
Return an id or code from a code or id.
load_state_board()
Charge indicateurs this-&gt;nb de tableau de bord.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
call_trigger($triggerName, $user)
Call trigger based on this instance.
makeSubstitution($text)
Make substitution of tags into text with value of current object.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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) Si ...
dol_trunc($string, $size=40, $trunc= 'right', $stringencoding= 'UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding &#39;...&#39; if string larger than length.
subscriptionComplementaryActions($subscriptionid, $option, $accountid, $datesubscription, $paymentdate, $operation, $label, $amount, $num_chq, $emetteur_nom= '', $emetteur_banque= '', $autocreatethirdparty=0)
Do complementary actions after subscription recording.
dolGetStatus($statusLabel= '', $statusLabelShort= '', $html= '', $statusType= 'status0', $displayMode=0, $url= '', $params=array())
Output the badge of a status.
make_substitutions($text, $substitutionarray, $outputlangs=null)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=&gt;newva...
Class to manage invoices.
load_board($user, $mode)
Load indicators for dashboard (this-&gt;nbtodo and this-&gt;nbtodolate)
update_end_date($user)
Update denormalized last subscription date.
Class to manage mailman and spip.
dol_time_plus_duree($time, $duration_value, $duration_unit)
Add a delay to a date.
Definition: date.lib.php:114
initAsSpecimen()
Initialise an instance with random values.
getmorphylib($morphy= '')
Return translated label by the nature of a adherent (physical or moral)
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:105
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
Class to manage payment terms records in dictionary.
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 &quot;subst...
getLibStatut($mode=0)
Retourne le libelle du statut d&#39;un adherent (brouillon, valide, resilie)
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
dol_textishtml($msg, $option=0)
Return if a text is a html content.