dolibarr 24.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 <alexandre@inovea-conseil.com>
9 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
10 * Copyright (C) 2015-2026 Frédéric France <frederic.france@free.fr>
11 * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
12 * Copyright (C) 2016 Juanjo Menent <jmenent@2byte.es>
13 * Copyright (C) 2018-2019 Thibault FOUCART <support@ptibogxiv.net>
14 * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
15 * Copyright (C) 2020 Josep Lluís Amador <joseplluis@lliuretic.cat>
16 * Copyright (C) 2021 Waël Almoman <info@almoman.com>
17 * Copyright (C) 2021 Philippe Grand <philippe.grand@atoo-net.com>
18 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
19 *
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 3 of the License, or
23 * (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * You should have received a copy of the GNU General Public License
31 * along with this program. If not, see <https://www.gnu.org/licenses/>.
32 */
33
39require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
41require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
42require_once DOL_DOCUMENT_ROOT.'/core/class/commonpeople.class.php';
43
44
49{
50 use CommonPeople;
51
55 public $element = 'member';
56
60 public $table_element = 'adherent';
61
65 public $picto = 'member';
66
70 public $mesgs;
71
75 public $login;
76
80 public $pass;
81
85 public $pass_indatabase;
86
90 public $pass_indatabase_crypted;
91
95 public $fullname;
96
101 public $civility_id;
102
106 public $civility_code;
107
111 public $civility;
112
118 public $societe;
119
123 public $company;
124
130 public $fk_soc;
131
135 public $socid;
136
140 public $socialnetworks;
141
145 public $phone;
146
150 public $phone_perso;
151
155 public $phone_pro;
156
160 public $phone_mobile;
161
165 public $fax;
166
170 public $poste;
171
175 public $morphy;
176
180 public $public;
181
186 public $default_lang;
187
191 public $photo;
192
198 public $datec;
199
205 public $datem;
206
210 public $datevalid;
211
215 public $gender;
216
220 public $birth;
221
225 public $typeid;
226
230 public $type;
231
235 public $need_subscription;
236
240 public $user_id;
241
245 public $user_login;
246
250 public $datefin;
251
252
253 // Fields loaded by fetch_subscriptions() from member table
254
258 public $first_subscription_date;
259
263 public $first_subscription_date_start;
264
268 public $first_subscription_date_end;
269
273 public $first_subscription_amount;
274
278 public $last_subscription_date;
279
283 public $last_subscription_date_start;
284
288 public $last_subscription_date_end;
289
293 public $last_subscription_amount;
294
298 public $subscriptions = array();
299
303 public $ip;
304
305 // Fields loaded by fetchPartnerships() from partnership table
306
310 public $partnerships = array();
311
315 public $invoice;
316
358 public $fields = array(
359 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 10),
360 'ref' => array('type' => 'varchar(30)', 'label' => 'Ref', 'default' => '1', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'position' => 12, 'index' => 1),
361 'entity' => array('type' => 'integer', 'label' => 'Entity', 'default' => '1', 'enabled' => 1, 'visible' => 3, 'notnull' => 1, 'position' => 15, 'index' => 1),
362 'ref_ext' => array('type' => 'varchar(128)', 'label' => 'RefExt', 'enabled' => 1, 'visible' => 0, 'position' => 20),
363 'civility' => array('type' => 'varchar(6)', 'label' => 'Civility', 'enabled' => 1, 'visible' => -1, 'position' => 25),
364 'lastname' => array('type' => 'varchar(50)', 'label' => 'Lastname', 'enabled' => 1, 'visible' => 1, 'position' => 30, 'showoncombobox' => 1),
365 'firstname' => array('type' => 'varchar(50)', 'label' => 'Firstname', 'enabled' => 1, 'visible' => 1, 'position' => 35, 'showoncombobox' => 1),
366 'login' => array('type' => 'varchar(50)', 'label' => 'Login', 'enabled' => 1, 'visible' => -1, 'position' => 40),
367 'pass' => array('type' => 'varchar(50)', 'label' => 'Pass', 'enabled' => 1, 'visible' => 3, 'position' => 45),
368 'pass_crypted' => array('type' => 'varchar(128)', 'label' => 'Pass crypted', 'enabled' => 1, 'visible' => 3, 'position' => 50),
369 'morphy' => array('type' => 'varchar(3)', 'label' => 'MemberNature', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'position' => 55),
370 'fk_adherent_type' => array('type' => 'integer', 'label' => 'MemberType', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'position' => 60),
371 'societe' => array('type' => 'varchar(128)', 'label' => 'Societe', 'enabled' => 1, 'visible' => 1, 'position' => 65, 'showoncombobox' => 2),
372 'fk_soc' => array('type' => 'integer:Societe:societe/class/societe.class.php', 'label' => 'LinkedToDolibarrThirdParty', 'enabled' => 1, 'visible' => 1, 'position' => 70),
373 'address' => array('type' => 'text', 'label' => 'Address', 'enabled' => 1, 'visible' => -1, 'position' => 75),
374 'zip' => array('type' => 'varchar(10)', 'label' => 'Zip', 'enabled' => 1, 'visible' => -1, 'position' => 80),
375 'town' => array('type' => 'varchar(50)', 'label' => 'Town', 'enabled' => 1, 'visible' => -1, 'position' => 85),
376 'state_id' => array('type' => 'integer', 'label' => 'State', 'enabled' => 1, 'visible' => -1, 'position' => 90),
377 'country' => array('type' => 'integer:Ccountry:core/class/ccountry.class.php', 'label' => 'Country', 'enabled' => 1, 'visible' => 1, 'position' => 95),
378 'phone' => array('type' => 'varchar(30)', 'label' => 'Phone', 'enabled' => 1, 'visible' => -1, 'position' => 115),
379 'phone_perso' => array('type' => 'varchar(30)', 'label' => 'Phone perso', 'enabled' => 1, 'visible' => -1, 'position' => 120),
380 'phone_mobile' => array('type' => 'varchar(30)', 'label' => 'Phone mobile', 'enabled' => 1, 'visible' => -1, 'position' => 125),
381 'email' => array('type' => 'varchar(255)', 'label' => 'Email', 'enabled' => 1, 'visible' => 1, 'position' => 126),
382 'url' => array('type' => 'varchar(255)', 'label' => 'Url', 'enabled' => 1, 'visible' => -1, 'position' => 127),
383 'socialnetworks' => array('type' => 'text', 'label' => 'Socialnetworks', 'enabled' => 1, 'visible' => 3, 'position' => 128),
384 'birth' => array('type' => 'date', 'label' => 'DateOfBirth', 'enabled' => 1, 'visible' => -1, 'position' => 130),
385 'gender' => array('type' => 'varchar(10)', 'label' => 'Gender', 'enabled' => 1, 'visible' => -1, 'position' => 132),
386 'photo' => array('type' => 'varchar(255)', 'label' => 'Photo', 'enabled' => 1, 'visible' => -1, 'position' => 135),
387 'public' => array('type' => 'smallint(6)', 'label' => 'Public', 'enabled' => 1, 'visible' => 3, 'notnull' => 1, 'position' => 145),
388 'datefin' => array('type' => 'datetime', 'label' => 'DateEnd', 'enabled' => 1, 'visible' => 1, 'position' => 150),
389 'default_lang' => array('type' => 'varchar(6)', 'label' => 'Default lang', 'enabled' => 1, 'visible' => -1, 'position' => 153),
390 'note_public' => array('type' => 'text', 'label' => 'NotePublic', 'enabled' => 1, 'visible' => 0, 'position' => 155),
391 'note_private' => array('type' => 'text', 'label' => 'NotePrivate', 'enabled' => 1, 'visible' => 0, 'position' => 160),
392 'datevalid' => array('type' => 'datetime', 'label' => 'DateValidation', 'enabled' => 1, 'visible' => -1, 'position' => 165),
393 'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -1, 'position' => 170),
394 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 175),
395 'fk_user_author' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserCreation', 'enabled' => 1, 'visible' => 3, 'position' => 180),
396 'fk_user_mod' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModification', 'enabled' => 1, 'visible' => 3, 'position' => 185),
397 'fk_user_valid' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserValidation', 'enabled' => 1, 'visible' => 3, 'position' => 190),
398 'canvas' => array('type' => 'varchar(32)', 'label' => 'Canvas', 'enabled' => 1, 'visible' => 0, 'position' => 195),
399 'model_pdf' => array('type' => 'varchar(255)', 'label' => 'Model pdf', 'enabled' => 1, 'visible' => 0, 'position' => 800),
400 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'visible' => -2, 'position' => 805),
401 'statut' => array('type' => 'smallint(6)', 'label' => 'Statut', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'position' => 1000, 'arrayofkeyval' => array(-1 => 'Draft', 1 => 'Validated', 0 => 'MemberStatusResiliatedShort', -2 => 'MemberStatusExcludedShort'))
402 );
403
407 const STATUS_DRAFT = -1;
419 const STATUS_EXCLUDED = -2;
420
421
427 public function __construct($db)
428 {
429 $this->db = $db;
430 $this->statut = self::STATUS_DRAFT;
431 $this->status = self::STATUS_DRAFT;
432 // l'adherent n'est pas public par default
433 $this->public = 0;
434 $this->ismultientitymanaged = 1;
435 $this->isextrafieldmanaged = 1;
436 // Optional fields are empty
437 $this->array_options = array();
438
439 $this->fields['ref_ext']['visible'] = getDolGlobalInt('MAIN_LIST_SHOW_REF_EXT');
440 }
441
442
443 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
462 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 = '')
463 {
464 // phpcs:enable
465 dol_syslog('Warning using deprecated Adherent::send_an_email', LOG_WARNING);
466
467 return $this->sendEmail($text, $subject, $filename_list, $mimetype_list, $mimefilename_list, $addr_cc, $addr_bcc, $deliveryreceipt, $msgishtml, $errors_to, $moreinheader);
468 }
469
487 public function sendEmail($text, $subject, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array(), $addr_cc = "", $addr_bcc = "", $deliveryreceipt = 0, $msgishtml = -1, $errors_to = '', $moreinheader = '')
488 {
489 global $conf, $langs;
490
491 // Detect if message is HTML
492 if ($msgishtml == -1) {
493 $msgishtml = 0;
494 if (dol_textishtml($text, 0)) {
495 $msgishtml = 1;
496 }
497 }
498
499 dol_syslog('sendEmail msgishtml='.$msgishtml);
500
501 $texttosend = $this->makeSubstitution($text);
502 $subjecttosend = $this->makeSubstitution($subject);
503 if ($msgishtml) {
504 $texttosend = dol_htmlentitiesbr($texttosend);
505 }
506
507 // Send mail confirmation
508 $email_from = getDolGlobalString('ADHERENT_MAIL_FROM', $conf->email_from);
509
510 $trackid = 'mem'.$this->id;
511
512 // Send email (substitutionarray must be done just before this)
513 include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
514 $mailfile = new CMailFile($subjecttosend, (string) $this->email, $email_from, $texttosend, $filename_list, $mimetype_list, $mimefilename_list, $addr_cc, $addr_bcc, $deliveryreceipt, $msgishtml, '', '', $trackid, $moreinheader);
515 if ($mailfile->sendfile()) {
516 return 1;
517 } else {
518 $this->error = $langs->trans("ErrorFailedToSendMail", $email_from, (string) $this->email).'. '.$mailfile->error;
519 return -1;
520 }
521 }
522
523
530 public function makeSubstitution($text)
531 {
532 global $langs;
533
534 $birthday = dol_print_date($this->birth, 'day');
535 $photo = isset($this->photo) ? $this->photo : '';
536 $login = isset($this->login) ? $this->login : '';
537 $type = isset($this->type) ? $this->type : '';
538 $pass = isset($this->pass) ? $this->pass : '';
539
540 $msgishtml = 0;
541 if (dol_textishtml($text, 1)) {
542 $msgishtml = 1;
543 }
544
545 $infos = '';
546 if ($this->civility_id) {
547 $infos .= $langs->transnoentities("UserTitle").": ".$this->getCivilityLabel()."\n";
548 }
549 $infos .= $langs->transnoentities("Id").": ".$this->id."\n";
550 $infos .= $langs->transnoentities("Ref").": ".$this->ref."\n";
551 $infos .= $langs->transnoentities("Lastname").": ".$this->lastname."\n";
552 $infos .= $langs->transnoentities("Firstname").": ".$this->firstname."\n";
553 $infos .= $langs->transnoentities("Company").": ".$this->company."\n";
554 $infos .= $langs->transnoentities("Address").": ".$this->address."\n";
555 $infos .= $langs->transnoentities("Zip").": ".$this->zip."\n";
556 $infos .= $langs->transnoentities("Town").": ".$this->town."\n";
557 $infos .= $langs->transnoentities("Country").": ".$this->country."\n";
558 $infos .= $langs->transnoentities("EMail").": ".$this->email."\n";
559 $infos .= $langs->transnoentities("PhonePro").": ".$this->phone."\n";
560 $infos .= $langs->transnoentities("PhonePerso").": ".$this->phone_perso."\n";
561 $infos .= $langs->transnoentities("PhoneMobile").": ".$this->phone_mobile."\n";
562 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
563 $infos .= $langs->transnoentities("Login").": ".$login."\n";
564 $infos .= $langs->transnoentities("Password").": ".$pass."\n";
565 }
566 $infos .= $langs->transnoentities("Birthday").": ".$birthday."\n";
567 $infos .= $langs->transnoentities("Photo").": ".$photo."\n";
568 $infos .= $langs->transnoentities("Public").": ".yn($this->public);
569
570 // Substitutions
571 $substitutionarray = array(
572 '__ID__' => $this->id,
573 '__REF__' => $this->ref,
574 '__MEMBER_ID__' => $this->id,
575 '__CIVILITY__' => $this->getCivilityLabel(),
576 '__FIRSTNAME__' => $msgishtml ? dol_htmlentitiesbr($this->firstname) : ($this->firstname ? $this->firstname : ''),
577 '__LASTNAME__' => $msgishtml ? dol_htmlentitiesbr($this->lastname) : ($this->lastname ? $this->lastname : ''),
578 '__FULLNAME__' => $msgishtml ? dol_htmlentitiesbr($this->getFullName($langs)) : $this->getFullName($langs),
579 '__COMPANY__' => $msgishtml ? dol_htmlentitiesbr((string) $this->company) : ($this->company ? $this->company : ''),
580 '__ADDRESS__' => $msgishtml ? dol_htmlentitiesbr((string) $this->address) : ($this->address ? $this->address : ''),
581 '__ZIP__' => $msgishtml ? dol_htmlentitiesbr((string) $this->zip) : ($this->zip ? $this->zip : ''),
582 '__TOWN__' => $msgishtml ? dol_htmlentitiesbr((string) $this->town) : ($this->town ? $this->town : ''),
583 '__COUNTRY__' => $msgishtml ? dol_htmlentitiesbr($this->country) : ($this->country ? $this->country : ''),
584 '__EMAIL__' => $msgishtml ? dol_htmlentitiesbr((string) $this->email) : ($this->email ? $this->email : ''),
585 '__BIRTH__' => $msgishtml ? dol_htmlentitiesbr($birthday) : ($birthday ? $birthday : ''),
586 '__PHOTO__' => $msgishtml ? dol_htmlentitiesbr($photo) : $photo,
587 '__LOGIN__' => $msgishtml ? dol_htmlentitiesbr($login) : $login,
588 '__PASSWORD__' => $msgishtml ? dol_htmlentitiesbr($pass) : $pass,
589 '__PHONE__' => $msgishtml ? dol_htmlentitiesbr($this->phone) : ($this->phone ? $this->phone : ''),
590 '__PHONEPRO__' => $msgishtml ? dol_htmlentitiesbr($this->phone_perso) : ($this->phone_perso ? $this->phone_perso : ''),
591 '__PHONEMOBILE__' => $msgishtml ? dol_htmlentitiesbr($this->phone_mobile) : ($this->phone_mobile ? $this->phone_mobile : ''),
592 '__TYPE__' => $msgishtml ? dol_htmlentitiesbr($type) : $type,
593 );
594
595 complete_substitutions_array($substitutionarray, $langs, $this);
596
597 return make_substitutions($text, $substitutionarray, $langs);
598 }
599
600
608 public function getmorphylib($morphy = '', $addbadge = 0)
609 {
610 global $langs;
611 $s = '';
612
613 // Clean var
614 if (!$morphy) {
615 $morphy = $this->morphy;
616 }
617
618 if ($addbadge) {
619 $labeltoshowm = $langs->trans("Moral");
620 $labeltoshowp = $langs->trans("Physical");
621 if ($morphy == 'phy') {
622 $labeltoshow = $labeltoshowp;
623 if ($addbadge == 2) {
624 $labeltoshow = dol_strtoupper(dolGetFirstLetters($labeltoshowp));
625 if ($labeltoshow == dol_strtoupper(dolGetFirstLetters($labeltoshowm))) {
626 $labeltoshow = dol_strtoupper(dolGetFirstLetters($labeltoshowp, 2));
627 }
628 }
629 $s .= '<span class="member-individual-back paddingleftimp paddingrightimp" title="'.$langs->trans("Physical").'">'.$labeltoshow.'</span>';
630 }
631 if ($morphy == 'mor') {
632 $labeltoshow = $labeltoshowm;
633 if ($addbadge == 2) {
634 $labeltoshow = dol_strtoupper(dolGetFirstLetters($labeltoshowm));
635 if ($labeltoshow == dol_strtoupper(dolGetFirstLetters($labeltoshowp))) {
636 $labeltoshow = dol_strtoupper(dolGetFirstLetters($labeltoshowm, 2));
637 }
638 }
639 $s .= '<span class="member-company-back paddingleftimp paddingrightimp" title="'.$langs->trans("Moral").'">'.$labeltoshow.'</span>';
640 }
641 } else {
642 if ($morphy == 'phy') {
643 $s = $langs->trans("Physical");
644 } elseif ($morphy == 'mor') {
645 $s = $langs->trans("Moral");
646 }
647 }
648
649 return $s;
650 }
651
659 public function create($user, $notrigger = 0)
660 {
661 global $langs, $mysoc;
662
663 $error = 0;
664
665 $now = dol_now();
666
667 // Clean parameters
668 if (isset($this->import_key)) {
669 $this->import_key = trim($this->import_key);
670 }
671
672 // Check parameters
673 if (getDolGlobalString('ADHERENT_MAIL_REQUIRED') && !isValidEmail((string) $this->email)) {
674 $langs->load("errors");
675 $this->error = $langs->trans("ErrorBadEMail", (string) $this->email);
676 return -1;
677 }
678 if (!$this->datec) {
679 $this->datec = $now;
680 }
681 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
682 if (empty($this->login)) {
683 $this->error = $langs->trans("ErrorWrongValueForParameterX", "Login");
684 return -1;
685 }
686 }
687
688 // setEntity will set entity with the right value if empty or change it for the right value if multicompany module is active
689 $this->entity = setEntity($this);
690
691 $this->db->begin();
692
693 // Insert member
694 $sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent";
695 $sql .= " (ref, datec, login, fk_user_author, fk_user_mod, fk_user_valid, morphy, fk_adherent_type, entity, import_key, ip)";
696 $sql .= " VALUES (";
697 $sql .= " '(PROV)'";
698 $sql .= ", '".$this->db->idate($this->datec)."'";
699 $sql .= ", ".($this->login ? "'".$this->db->escape($this->login)."'" : "null");
700 $sql .= ", ".($user->id > 0 ? ((int) $user->id) : "null"); // Can be null because member can be created by a guest or a script
701 $sql .= ", null, null, '".$this->db->escape($this->morphy)."'";
702 $sql .= ", ".((int) $this->typeid);
703 $sql .= ", ".((int) $this->entity);
704 $sql .= ", ".(!empty($this->import_key) ? "'".$this->db->escape($this->import_key)."'" : "null");
705 $sql .= ", ".(!empty($this->ip) ? "'".$this->db->escape($this->ip)."'" : "null");
706 $sql .= ")";
707
708 dol_syslog(get_class($this)."::create", LOG_DEBUG);
709 $result = $this->db->query($sql);
710 if ($result) {
711 $id = $this->db->last_insert_id(MAIN_DB_PREFIX."adherent");
712 if ($id > 0) {
713 $this->id = $id;
714
715 $modulenum = getDolGlobalString('MEMBER_CODEMEMBER_ADDON', 'mod_member_simple');
716
717 $modfile = dol_buildpath('core/modules/member/'.$modulenum.'.php', 0);
718 try {
719 require_once $modfile;
720 $modname = $modulenum;
721 $modCodeMember = new $modname();
722 '@phan-var-force ModeleNumRefMembers $modCodeMember';
724 $this->ref = $modCodeMember->getNextValue($mysoc, $this);
725 } catch (Exception $e) {
726 dol_syslog($e->getMessage(), LOG_ERR);
727 $error++;
728 }
729
730 // Update minor fields
731 $result = $this->update($user, 1, 1, 0, 0, 'add'); // nosync is 1 to avoid update data of user
732 if ($result < 0) {
733 $this->db->rollback();
734 return -1;
735 }
736
737 // Add link to user
738 if ($this->user_id) {
739 // Add link to user
740 $sql = "UPDATE ".MAIN_DB_PREFIX."user SET";
741 $sql .= " fk_member = ".((int) $this->id);
742 $sql .= " WHERE rowid = ".((int) $this->user_id);
743 dol_syslog(get_class($this)."::create", LOG_DEBUG);
744 $resql = $this->db->query($sql);
745 if (!$resql) {
746 $this->error = 'Failed to update user to make link with member';
747 $this->db->rollback();
748 return -4;
749 }
750 }
751
752 if (!$notrigger) {
753 // Call trigger
754 $result = $this->call_trigger('MEMBER_CREATE', $user);
755 if ($result < 0) {
756 $error++;
757 }
758 // End call triggers
759 }
760
761 if (count($this->errors)) {
762 dol_syslog(get_class($this)."::create ".implode(',', $this->errors), LOG_ERR);
763 $this->db->rollback();
764 return -3;
765 } else {
766 $this->db->commit();
767 return $this->id;
768 }
769 } else {
770 $this->error = 'Failed to get last insert id';
771 dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
772 $this->db->rollback();
773 return -2;
774 }
775 } else {
776 $this->error = $this->db->error();
777 $this->db->rollback();
778 return -1;
779 }
780 }
781
782
794 public function update($user, $notrigger = 0, $nosyncuser = 0, $nosyncuserpass = 0, $nosyncthirdparty = 0, $action = 'update')
795 {
796 global $langs, $hookmanager;
797
798 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
799
800 if (empty($this->country_id) && !empty($this->country_code)) {
801 $country_id = getCountry($this->country_code, '3');
802 $this->country_id = is_int($country_id) ? $country_id : 0;
803 }
804
805 $nbrowsaffected = 0;
806 $error = 0;
807
808 dol_syslog(get_class($this)."::update notrigger=".$notrigger.", nosyncuser=".$nosyncuser.", nosyncuserpass=".$nosyncuserpass." nosyncthirdparty=".$nosyncthirdparty.", email=".$this->email);
809
810 // Clean parameters
811 $this->lastname = trim($this->lastname) ? trim($this->lastname) : trim($this->lastname);
812 $this->firstname = trim($this->firstname) ? trim($this->firstname) : trim($this->firstname);
813 // civility_code is the reference property. Fall back to the deprecated civility_id alias only when civility_code was not set by the caller.
814 if (empty($this->civility_code) && !empty($this->civility_id)) {
815 $this->civility_code = $this->civility_id;
816 }
817 if (isset($this->gender)) {
818 $this->gender = trim($this->gender);
819 }
820 // $this->address = ($this->address ? $this->address : $this->address);
821 // $this->zip = ($this->zip ? $this->zip : $this->zip);
822 // $this->town = ($this->town ? $this->town : $this->town);
823 // $this->country_id = ($this->country_id > 0 ? $this->country_id : $this->country_id);
824 // $this->state_id = ($this->state_id > 0 ? $this->state_id : $this->state_id);
825 // $this->note_public = ($this->note_public ? $this->note_public : $this->note_public);
826 // $this->note_private = ($this->note_private ? $this->note_private : $this->note_private);
827 $this->url = $this->url ? clean_url($this->url, 0) : '';
828 $this->setUpperOrLowerCase();
829
830 // Check parameters
831 if (getDolGlobalString('ADHERENT_MAIL_REQUIRED') && !isValidEmail((string) $this->email)) {
832 $langs->load("errors");
833 $this->error = $langs->trans("ErrorBadEMail", (string) $this->email);
834 return -1;
835 }
836
837 $this->db->begin();
838
839 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
840 $sql .= " ref = '".$this->db->escape($this->ref)."'";
841 $sql .= ", ref_ext = ".(empty($this->ref_ext) ? "null" : "'".$this->db->escape($this->ref_ext)."'");
842 $sql .= ", civility = ".($this->civility_code ? "'".$this->db->escape($this->civility_code)."'" : "null");
843 $sql .= ", firstname = ".($this->firstname ? "'".$this->db->escape($this->firstname)."'" : "null");
844 $sql .= ", lastname = ".($this->lastname ? "'".$this->db->escape($this->lastname)."'" : "null");
845 $sql .= ", gender = ".($this->gender != -1 ? "'".$this->db->escape($this->gender)."'" : "null"); // 'man' or 'woman'
846 $sql .= ", login = ".($this->login ? "'".$this->db->escape($this->login)."'" : "null");
847 $sql .= ", societe = ".($this->company ? "'".$this->db->escape($this->company)."'" : ($this->societe ? "'".$this->db->escape($this->societe)."'" : "null"));
848 if ($this->socid) {
849 $sql .= ", fk_soc = ".($this->socid > 0 ? (int) $this->socid : "null"); // Must be modified only when creating from a third-party
850 }
851 $sql .= ", address = ".($this->address ? "'".$this->db->escape($this->address)."'" : "null");
852 $sql .= ", zip = ".($this->zip ? "'".$this->db->escape($this->zip)."'" : "null");
853 $sql .= ", town = ".($this->town ? "'".$this->db->escape($this->town)."'" : "null");
854 $sql .= ", country = ".($this->country_id > 0 ? (int) $this->country_id : "null");
855 $sql .= ", state_id = ".($this->state_id > 0 ? (int) $this->state_id : "null");
856 $sql .= ", email = '".$this->db->escape((string) $this->email)."'";
857 $sql .= ", url = ".(!empty($this->url) ? "'".$this->db->escape($this->url)."'" : "null");
858 $sql .= ", socialnetworks = ".($this->socialnetworks ? "'".$this->db->escape(json_encode($this->socialnetworks))."'" : "null");
859 $sql .= ", phone = ".($this->phone ? "'".$this->db->escape($this->phone)."'" : "null");
860 $sql .= ", phone_perso = ".($this->phone_perso ? "'".$this->db->escape($this->phone_perso)."'" : "null");
861 $sql .= ", phone_mobile = ".($this->phone_mobile ? "'".$this->db->escape($this->phone_mobile)."'" : "null");
862 $sql .= ", note_private = ".($this->note_private ? "'".$this->db->escape($this->note_private)."'" : "null");
863 $sql .= ", note_public = ".($this->note_public ? "'".$this->db->escape($this->note_public)."'" : "null");
864 $sql .= ", photo = ".($this->photo ? "'".$this->db->escape($this->photo)."'" : "null");
865 $sql .= ", public = ".(int) $this->public;
866 $sql .= ", statut = ".(int) $this->statut;
867 $sql .= ", default_lang = ".(!empty($this->default_lang) ? "'".$this->db->escape($this->default_lang)."'" : "null");
868 $sql .= ", fk_adherent_type = ".(int) $this->typeid;
869 $sql .= ", morphy = '".$this->db->escape($this->morphy)."'";
870 $sql .= ", birth = ".($this->birth ? "'".$this->db->idate($this->birth)."'" : "null");
871
872 if ($this->datefin) {
873 $sql .= ", datefin = '".$this->db->idate($this->datefin)."'"; // Must be modified only when deleting a subscription
874 }
875 if ($this->datevalid) {
876 $sql .= ", datevalid = '".$this->db->idate($this->datevalid)."'"; // Must be modified only when validating a member
877 }
878 $sql .= ", fk_user_mod = ".($user->id > 0 ? ((int) $user->id) : 'null'); // Can be null because member can be create by a guest
879 $sql .= " WHERE rowid = ".((int) $this->id);
880
881 // If we change the type of membership, we set also label of new type..
882 '@phan-var-force Adherent $oldcopy';
883 if (!empty($this->oldcopy) && $this->typeid != $this->oldcopy->typeid) {
884 $sql2 = "SELECT libelle as label";
885 $sql2 .= " FROM ".MAIN_DB_PREFIX."adherent_type";
886 $sql2 .= " WHERE rowid = ".((int) $this->typeid);
887 $resql2 = $this->db->query($sql2);
888 if ($resql2) {
889 while ($obj = $this->db->fetch_object($resql2)) {
890 $this->type = $obj->label;
891 }
892 }
893 }
894
895 dol_syslog(get_class($this)."::update update member", LOG_DEBUG);
896 $resql = $this->db->query($sql);
897 if ($resql) {
898 unset($this->country_code);
899 unset($this->country);
900 unset($this->state_code);
901 unset($this->state);
902
903 $nbrowsaffected += $this->db->affected_rows($resql);
904
905 $action = 'update';
906
907 // Actions on extra fields
908 $result = $this->insertExtraFields();
909 if ($result < 0) {
910 $error++;
911 }
912
913 // Update password
914 if (!$error && $this->pass) {
915 dol_syslog(get_class($this)."::update update password");
916 if ($this->pass != $this->pass_indatabase && $this->pass != $this->pass_indatabase_crypted) {
917 $isencrypted = getDolGlobalString('DATABASE_PWD_ENCRYPTED') ? 1 : 0;
918
919 // If password to set differs from the one found into database
920 $result = $this->setPassword($user, $this->pass, $isencrypted, $notrigger, $nosyncuserpass);
921 if (!$nbrowsaffected) {
922 $nbrowsaffected++;
923 }
924 }
925 }
926
927 // Remove links to user and replace with new one
928 if (!$error) {
929 dol_syslog(get_class($this)."::update update link to user");
930 $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = NULL WHERE fk_member = ".((int) $this->id);
931 dol_syslog(get_class($this)."::update", LOG_DEBUG);
932 $resql = $this->db->query($sql);
933 if (!$resql) {
934 $this->error = $this->db->error();
935 $this->db->rollback();
936 return -5;
937 }
938 // If there is a user linked to this member
939 if ($this->user_id > 0) {
940 $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = ".((int) $this->id)." WHERE rowid = ".((int) $this->user_id);
941 dol_syslog(get_class($this)."::update", LOG_DEBUG);
942 $resql = $this->db->query($sql);
943 if (!$resql) {
944 $this->error = $this->db->error();
945 $this->db->rollback();
946 return -5;
947 }
948 }
949 }
950
951 if (!$error && $nbrowsaffected) { // If something has change in main data
952 // Update information on linked user if it is an update
953 if ($this->user_id > 0 && !$nosyncuser) {
954 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
955
956 dol_syslog(get_class($this)."::update update linked user");
957
958 $luser = new User($this->db);
959 $result = $luser->fetch($this->user_id);
960
961 if ($result >= 0) {
962 // 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.
963 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
964 $luser->login = $this->login;
965 }
966
967 $luser->ref = $this->ref;
968 $luser->civility_code = $this->civility_code;
969 $luser->firstname = $this->firstname;
970 $luser->lastname = $this->lastname;
971 $luser->gender = $this->gender;
972 $luser->pass = isset($this->pass) ? $this->pass : '';
973 //$luser->socid=$this->fk_soc; // We do not enable this. This may transform a user into an external user.
974
975 $luser->birth = $this->birth;
976
977 $luser->address = $this->address;
978 $luser->zip = $this->zip;
979 $luser->town = $this->town;
980 $luser->country_id = $this->country_id;
981 $luser->state_id = $this->state_id;
982
983 $luser->email = $this->email;
984 $luser->socialnetworks = $this->socialnetworks;
985 $luser->office_phone = $this->phone;
986 $luser->user_mobile = $this->phone_mobile;
987
988 $luser->lang = $this->default_lang;
989
990 $luser->fk_member = $this->id;
991
992 $result = $luser->update($user, 0, 1, 1); // Use nosync to 1 to avoid cyclic updates
993 if ($result < 0) {
994 $this->error = $luser->error;
995 dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
996 $error++;
997 }
998 } else {
999 $this->error = $luser->error;
1000 $error++;
1001 }
1002 }
1003
1004 // Update information on linked thirdparty if it is an update
1005 if (!$error && $this->socid > 0 && !$nosyncthirdparty) {
1006 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
1007
1008 dol_syslog(get_class($this)."::update update linked thirdparty");
1009
1010 // This member is linked with a thirdparty, so we also update thirdparty information
1011 // if this is an update.
1012 $lthirdparty = new Societe($this->db);
1013 $result = $lthirdparty->fetch($this->socid);
1014
1015 if ($result > 0) {
1016 $lthirdparty->address = $this->address;
1017 $lthirdparty->zip = $this->zip;
1018 $lthirdparty->town = $this->town;
1019 $lthirdparty->email = $this->email;
1020 $lthirdparty->socialnetworks = $this->socialnetworks;
1021 $lthirdparty->phone = $this->phone;
1022 $lthirdparty->state_id = $this->state_id;
1023 $lthirdparty->country_id = $this->country_id;
1024 //$lthirdparty->phone_mobile=$this->phone_mobile;
1025 $lthirdparty->default_lang = $this->default_lang;
1026
1027 $result = $lthirdparty->update($this->socid, $user, 0, 1, 1, 'update'); // Use sync to 0 to avoid cyclic updates
1028
1029 if ($result < 0) {
1030 $this->error = $lthirdparty->error;
1031 $this->errors = $lthirdparty->errors;
1032 dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
1033 $error++;
1034 }
1035 } elseif ($result < 0) {
1036 $this->error = $lthirdparty->error;
1037 $error++;
1038 }
1039 }
1040 }
1041
1042 if (!$error && !$notrigger) {
1043 // Call trigger
1044 $result = $this->call_trigger('MEMBER_MODIFY', $user);
1045 if ($result < 0) {
1046 $error++;
1047 }
1048 // End call triggers
1049 }
1050
1051 if (!$error) {
1052 $this->db->commit();
1053 return $nbrowsaffected;
1054 } else {
1055 $this->db->rollback();
1056 return -1;
1057 }
1058 } else {
1059 $this->db->rollback();
1060 $this->error = $this->db->lasterror();
1061 return -2;
1062 }
1063 }
1064
1065
1066 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1074 public function update_end_date($user)
1075 {
1076 // phpcs:enable
1077 $this->db->begin();
1078
1079 // Search for last subscription id and end date
1080 $sql = "SELECT rowid, datec as dateop, dateadh as datedeb, datef as datefin";
1081 $sql .= " FROM ".MAIN_DB_PREFIX."subscription";
1082 $sql .= " WHERE fk_adherent = ".((int) $this->id);
1083 $sql .= " ORDER by dateadh DESC"; // Sort by start subscription date
1084
1085 dol_syslog(get_class($this)."::update_end_date", LOG_DEBUG);
1086 $resql = $this->db->query($sql);
1087 if ($resql) {
1088 // The last subscription is the one with the latest start date (first record), but the end date of the member is
1089 // the latest end date of all its subscriptions: a short subscription that starts after a longer one must not
1090 // shorten the membership. There is no record at all when the last subscription of the member was deleted.
1091 $dateop = '';
1092 $datedeb = '';
1093 $datefin = '';
1094 $dateendmember = '';
1095 $i = 0;
1096 while ($obj = $this->db->fetch_object($resql)) {
1097 $dateendsubscription = $this->db->jdate($obj->datefin);
1098 if ($i == 0) {
1099 $dateop = $this->db->jdate($obj->dateop);
1100 $datedeb = $this->db->jdate($obj->datedeb);
1101 $datefin = $dateendsubscription;
1102 }
1103 if ($dateendsubscription != '' && ($dateendmember == '' || $dateendsubscription > $dateendmember)) {
1104 $dateendmember = $dateendsubscription;
1105 }
1106 $i++;
1107 }
1108
1109 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
1110 $sql .= " datefin=".($dateendmember != '' ? "'".$this->db->idate($dateendmember)."'" : "null");
1111 $sql .= " WHERE rowid = ".((int) $this->id);
1112
1113 dol_syslog(get_class($this)."::update_end_date", LOG_DEBUG);
1114 $resql = $this->db->query($sql);
1115 if ($resql) {
1116 $this->last_subscription_date = $dateop;
1117 $this->last_subscription_date_start = $datedeb;
1118 $this->last_subscription_date_end = $datefin;
1119 $this->datefin = $dateendmember;
1120 $this->db->commit();
1121 return 1;
1122 } else {
1123 $this->db->rollback();
1124 return -1;
1125 }
1126 } else {
1127 $this->error = $this->db->lasterror();
1128 $this->db->rollback();
1129 return -1;
1130 }
1131 }
1132
1140 public function delete($user, $notrigger = 0)
1141 {
1142 $result = 0;
1143 $error = 0;
1144 $errorflag = 0;
1145
1146 // Check parameters
1147 $rowid = $this->id;
1148
1149 $this->db->begin();
1150
1151 if (!$notrigger) {
1152 // Call trigger
1153 $result = $this->call_trigger('MEMBER_DELETE', $user);
1154 if ($result < 0) {
1155 $error++;
1156 }
1157 // End call triggers
1158 }
1159
1160 // Remove category
1161 $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_member WHERE fk_member = ".((int) $rowid);
1162 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1163 $resql = $this->db->query($sql);
1164 if (!$resql) {
1165 $error++;
1166 $this->error .= $this->db->lasterror();
1167 $errorflag = -1;
1168 }
1169
1170 // Remove subscription
1171 if (!$error) {
1172 $sql = "DELETE FROM ".MAIN_DB_PREFIX."subscription WHERE fk_adherent = ".((int) $rowid);
1173 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1174 $resql = $this->db->query($sql);
1175 if (!$resql) {
1176 $error++;
1177 $this->error .= $this->db->lasterror();
1178 $errorflag = -2;
1179 }
1180 }
1181
1182 // Remove linked user
1183 if (!$error) {
1184 $ret = $this->setUserId(0);
1185 if ($ret < 0) {
1186 $error++;
1187 $this->error .= $this->db->lasterror();
1188 $errorflag = -3;
1189 }
1190 }
1191
1192 // Removed extrafields
1193 if (!$error) {
1194 $result = $this->deleteExtraFields();
1195 if ($result < 0) {
1196 $error++;
1197 $errorflag = -4;
1198 dol_syslog(get_class($this)."::delete erreur ".$errorflag." ".$this->error, LOG_ERR);
1199 }
1200 }
1201
1202 // Remove adherent
1203 if (!$error) {
1204 $sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent WHERE rowid = ".((int) $rowid);
1205 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1206 $resql = $this->db->query($sql);
1207 if (!$resql) {
1208 $error++;
1209 $this->error .= $this->db->lasterror();
1210 $errorflag = -5;
1211 }
1212 }
1213
1214 if (!$error) {
1215 $this->db->commit();
1216 return 1;
1217 } else {
1218 $this->db->rollback();
1219 return $errorflag;
1220 }
1221 }
1222
1233 public function mergeMembers($member_origin_id)
1234 {
1235 global $conf, $langs, $hookmanager, $user, $action;
1236
1237 $error = 0;
1238 $member_origin = new Adherent($this->db); // The member that we will delete
1239
1240 dol_syslog("mergeMembers merge member id=".$member_origin_id." (will be deleted) into the member id=".$this->id);
1241 if ($member_origin->fetch($member_origin_id) < 1) {
1242 $this->error = $langs->trans('ErrorRecordNotFound');
1243 $error++;
1244 }
1245
1246 if (!$error) {
1247 $this->db->begin();
1248 $listofproperties = array(
1249 'ref_ext', 'civility', 'lastname', 'firstname', 'morphy', 'societe', 'socid', 'user_id','address',
1250 'zip', 'town', 'state_id', 'country', 'phone', 'phone_perso', 'phone_mobile', 'email',
1251 'url', 'socialnetworks', 'birth', 'gender', 'photo', 'public', 'datefin', 'default_lang',
1252 'canvas', 'model_pdf', 'import_key'
1253 );
1254 foreach ($listofproperties as $property) {
1255 if (empty($this->$property)) {
1256 $this->$property = $member_origin->$property;
1257 }
1258 }
1259
1260 // Concat some data
1261 $listofproperties = array(
1262 'note_public', 'note_private'
1263 );
1264 foreach ($listofproperties as $property) {
1265 $this->$property = dol_concatdesc($this->$property, $member_origin->$property);
1266 }
1267
1268 // Merge extrafields
1269 if (is_array($member_origin->array_options)) {
1270 foreach ($member_origin->array_options as $key => $val) {
1271 if (empty($this->array_options[$key])) {
1272 $this->array_options[$key] = $val;
1273 }
1274 }
1275 }
1276
1277 // Merge categories
1278 include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1279 $static_cat = new Categorie($this->db);
1280 $custcats_ori = $static_cat->containing($member_origin->id, 'member', 'id');
1281 $custcats = $static_cat->containing($this->id, 'member', 'id');
1282 $custcats = array_merge($custcats, $custcats_ori);
1283 $this->setCategories($custcats);
1284
1285 $result = $this->update($user, 1, 1, 1, 1, 'merge');
1286 if ($result < 0) {
1287 $error++;
1288 }
1289
1290 // Merge subscriptions
1291 if (!$error && $member_origin->fetch_subscriptions() < 1) {
1292 $error++;
1293 }
1294
1295 if (!$error) {
1296 foreach ($member_origin->subscriptions as $key => $subscription) {
1297 $subscription->fk_adherent = $this->id;
1298 $result = $subscription->update($user);
1299 if ($result < 0) {
1300 $error++;
1301 break;
1302 }
1303 }
1304 }
1305
1306 // External modules should update their ones too
1307 if (!$error) {
1308 $parameters = array('member_origin' => $member_origin->id, 'member_dest' => $this->id);
1309 $reshook = $hookmanager->executeHooks('replaceMember', $parameters, $this, $action);
1310
1311 if ($reshook < 0) {
1312 $this->setErrorsFromObject($hookmanager);
1313 $error++;
1314 }
1315 }
1316
1317 if (!$error) {
1318 $this->context = array('merge' => 1, 'mergefromid' => $member_origin->id);
1319
1320 // Call trigger
1321 $result = $this->call_trigger('MEMBER_MODIFY', $user);
1322 if ($result < 0) {
1323 $error++;
1324 }
1325 // End call triggers
1326 }
1327
1328 if (!$error) {
1329 // We finally remove the old member
1330 if ($member_origin->delete($user) < 1) {
1331 $this->setErrorsFromObject($member_origin);
1332 $error++;
1333 }
1334 }
1335
1336 if (!$error) {
1337 // Move files from the dir of the third party to delete into the dir of the third party to keep
1338 if (!empty($conf->adherent->multidir_output[$this->entity])) {
1339 $srcdir = $conf->adherent->multidir_output[$this->entity]."/".$member_origin->id;
1340 $destdir = $conf->adherent->multidir_output[$this->entity]."/".$this->id;
1341
1342 if (dol_is_dir($srcdir)) {
1343 $dirlist = dol_dir_list($srcdir, 'files', 1);
1344 foreach ($dirlist as $filetomove) {
1345 $destfile = $destdir.'/'.$filetomove['relativename'];
1346 $result = dol_move($filetomove['fullname'], $destfile, '0', 0, 0, 1);
1347 if (!$result) {
1348 $error++;
1349 }
1350 }
1351 }
1352 }
1353 }
1354
1355 if (!$error) {
1356 $this->db->commit();
1357 return 0;
1358 } else {
1359 $langs->load("errors");
1360 $this->error = $langs->trans('ErrorMembersMerge');
1361 $this->db->rollback();
1362 return -1;
1363 }
1364 }
1365 return -1;
1366 }
1367
1378 public function setPassword($user, $password = '', $isencrypted = 0, $notrigger = 0, $nosyncuser = 0)
1379 {
1380 global $conf, $langs;
1381
1382 $error = 0;
1383
1384 dol_syslog(get_class($this)."::setPassword user=".$user->id." password=".preg_replace('/./i', '*', $password)." isencrypted=".$isencrypted);
1385
1386 // If new password not provided, we generate one
1387 if (!$password) {
1388 require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
1389 $password = getRandomPassword(false);
1390 }
1391
1392 // Crypt password
1393 $password_crypted = dol_hash($password);
1394
1395 $password_indatabase = '';
1396 if (!$isencrypted) {
1397 $password_indatabase = $password;
1398 }
1399
1400 $this->db->begin();
1401
1402 // Mise a jour
1403 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent";
1404 $sql .= " SET pass_crypted = '".$this->db->escape($password_crypted)."'";
1405 if ($isencrypted) {
1406 $sql .= ", pass = null";
1407 } else {
1408 $sql .= ", pass = '".$this->db->escape($password_indatabase)."'";
1409 }
1410 $sql .= " WHERE rowid = ".((int) $this->id);
1411
1412 //dol_syslog("Adherent::Password sql=hidden");
1413 dol_syslog(get_class($this)."::setPassword", LOG_DEBUG);
1414 $result = $this->db->query($sql);
1415 if ($result) {
1416 $nbaffectedrows = $this->db->affected_rows($result);
1417
1418 if ($nbaffectedrows) {
1419 $this->pass = $password;
1420 $this->pass_indatabase = $password_indatabase;
1421 $this->pass_indatabase_crypted = $password_crypted;
1422
1423 if ($this->user_id && !$nosyncuser) {
1424 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
1425
1426 // This member is linked with a user, so we also update users information
1427 // if this is an update.
1428 $luser = new User($this->db);
1429 $result = $luser->fetch($this->user_id);
1430
1431 if ($result >= 0) {
1432 $result = $luser->setPassword($user, $this->pass, 0, 0, 1);
1433 if (is_int($result) && $result < 0) {
1434 $this->error = $luser->error;
1435 dol_syslog(get_class($this)."::setPassword ".$this->error, LOG_ERR);
1436 $error++;
1437 }
1438 } else {
1439 $this->error = $luser->error;
1440 $error++;
1441 }
1442 }
1443
1444 if (!$error && !$notrigger) {
1445 // Call trigger
1446 $result = $this->call_trigger('MEMBER_NEW_PASSWORD', $user);
1447 if ($result < 0) {
1448 $error++;
1449 $this->db->rollback();
1450 return -1;
1451 }
1452 // End call triggers
1453 }
1454
1455 $this->db->commit();
1456 return $this->pass;
1457 } else {
1458 $this->db->rollback();
1459 return 0;
1460 }
1461 } else {
1462 $this->db->rollback();
1463 dol_print_error($this->db);
1464 return -1;
1465 }
1466 }
1467
1468
1475 public function setUserId($userid)
1476 {
1477 global $conf, $langs;
1478
1479 $this->db->begin();
1480
1481 // If user is linked to this member, remove old link to this member
1482 $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = NULL WHERE fk_member = ".((int) $this->id);
1483 dol_syslog(get_class($this)."::setUserId", LOG_DEBUG);
1484 $resql = $this->db->query($sql);
1485 if (!$resql) {
1486 $this->error = $this->db->error();
1487 $this->db->rollback();
1488 return -1;
1489 }
1490
1491 // Set link to user
1492 if ($userid > 0) {
1493 $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = ".((int) $this->id);
1494 $sql .= " WHERE rowid = ".((int) $userid);
1495 dol_syslog(get_class($this)."::setUserId", LOG_DEBUG);
1496 $resql = $this->db->query($sql);
1497 if (!$resql) {
1498 $this->error = $this->db->error();
1499 $this->db->rollback();
1500 return -2;
1501 }
1502 }
1503
1504 $this->db->commit();
1505
1506 return 1;
1507 }
1508
1509
1516 public function setThirdPartyId($thirdpartyid)
1517 {
1518 global $conf, $langs;
1519
1520 $this->db->begin();
1521
1522 // Remove link to third party onto any other members
1523 if ($thirdpartyid > 0) {
1524 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET fk_soc = null";
1525 $sql .= " WHERE fk_soc = ".((int) $thirdpartyid);
1526 $sql .= " AND entity = ".((int) $conf->entity);
1527 dol_syslog(get_class($this)."::setThirdPartyId", LOG_DEBUG);
1528 $resql = $this->db->query($sql);
1529 }
1530
1531 // Add link to third party for current member
1532 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET fk_soc = ".($thirdpartyid > 0 ? (int) $thirdpartyid : 'null');
1533 $sql .= " WHERE rowid = ".((int) $this->id);
1534
1535 dol_syslog(get_class($this)."::setThirdPartyId", LOG_DEBUG);
1536 $resql = $this->db->query($sql);
1537 if ($resql) {
1538 $this->db->commit();
1539 return 1;
1540 } else {
1541 $this->error = $this->db->error();
1542 $this->db->rollback();
1543 return -1;
1544 }
1545 }
1546
1547
1548 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1555 public function fetch_login($login)
1556 {
1557 // phpcs:enable
1558 global $conf;
1559
1560 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."adherent";
1561 $sql .= " WHERE login='".$this->db->escape($login)."'";
1562 $sql .= " AND entity = ".((int) $conf->entity);
1563
1564 $resql = $this->db->query($sql);
1565 if ($resql) {
1566 if ($this->db->num_rows($resql)) {
1567 $obj = $this->db->fetch_object($resql);
1568 $this->fetch($obj->rowid);
1569 }
1570 } else {
1571 dol_print_error($this->db);
1572 }
1573 }
1574
1575 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1583 public function fetch_name($firstname, $lastname)
1584 {
1585 // phpcs:enable
1586 global $conf;
1587
1588 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."adherent";
1589 $sql .= " WHERE firstname='".$this->db->escape($firstname)."'";
1590 $sql .= " AND lastname='".$this->db->escape($lastname)."'";
1591 $sql .= " AND entity = ".((int) $conf->entity);
1592
1593 $resql = $this->db->query($sql);
1594 if ($resql) {
1595 if ($this->db->num_rows($resql)) {
1596 $obj = $this->db->fetch_object($resql);
1597 $this->fetch($obj->rowid);
1598 }
1599 } else {
1600 dol_print_error($this->db);
1601 }
1602 }
1603
1615 public function fetch($rowid, $ref = '', $socid = 0, $ref_ext = '', $fetch_optionals = true, $fetch_subscriptions = true)
1616 {
1617 global $langs;
1618
1619 $sql = "SELECT d.rowid, d.ref, d.ref_ext, d.civility as civility_code, d.gender, d.firstname, d.lastname,";
1620 $sql .= " d.societe as company, d.fk_soc as socid, d.statut, d.public, d.address, d.zip, d.town, d.note_private,";
1621 $sql .= " d.note_public,";
1622 $sql .= " d.email, d.url, d.socialnetworks, d.phone, d.phone_perso, d.phone_mobile, d.login, d.pass, d.pass_crypted,";
1623 $sql .= " d.photo, d.fk_adherent_type, d.morphy, d.entity,";
1624 $sql .= " d.datec as datec,";
1625 $sql .= " GREATEST(d.tms, COALESCE(aef.tms, d.tms)) as datem,";
1626 $sql .= " d.datefin as datefin, d.default_lang,";
1627 $sql .= " d.birth as birthday,";
1628 $sql .= " d.datevalid as datev,";
1629 $sql .= " d.country,";
1630 $sql .= " d.state_id,";
1631 $sql .= " d.model_pdf,";
1632 $sql .= " c.rowid as country_id, c.code as country_code, c.label as country,";
1633 $sql .= " dep.nom as state, dep.code_departement as state_code,";
1634 $sql .= " t.libelle as type, t.subscription as subscription,";
1635 $sql .= " u.rowid as user_id, u.login as user_login";
1636 $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as t, ".MAIN_DB_PREFIX."adherent as d";
1637 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'adherent_extrafields as aef ON aef.fk_object = d.rowid';
1638 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON d.country = c.rowid";
1639 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as dep ON d.state_id = dep.rowid";
1640 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON d.rowid = u.fk_member";
1641 $sql .= " WHERE d.fk_adherent_type = t.rowid";
1642 if ($rowid) {
1643 $sql .= " AND d.rowid=".((int) $rowid);
1644 } elseif ($ref || $socid) {
1645 $sql .= " AND d.entity IN (".getEntity('adherent').")";
1646 if ($ref) {
1647 $sql .= " AND d.ref='".$this->db->escape($ref)."'";
1648 } elseif ($socid > 0) {
1649 $sql .= " AND d.fk_soc=".((int) $socid);
1650 }
1651 } elseif ($ref_ext) {
1652 $sql .= " AND d.ref_ext='".$this->db->escape($ref_ext)."'";
1653 }
1654
1655 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
1656 $resql = $this->db->query($sql);
1657 if ($resql) {
1658 if ($this->db->num_rows($resql)) {
1659 $obj = $this->db->fetch_object($resql);
1660
1661 $this->entity = $obj->entity;
1662 $this->id = $obj->rowid;
1663 $this->ref = $obj->ref;
1664 $this->ref_ext = $obj->ref_ext;
1665
1666 $this->civility_id = $obj->civility_code; // Bad. Kept for backward compatibility
1667 $this->civility_code = $obj->civility_code;
1668 $this->civility = $obj->civility_code ? ($langs->trans("Civility".$obj->civility_code) != "Civility".$obj->civility_code ? $langs->trans("Civility".$obj->civility_code) : $obj->civility_code) : '';
1669
1670 $this->firstname = $obj->firstname;
1671 $this->lastname = $obj->lastname;
1672 $this->gender = $obj->gender;
1673 $this->login = $obj->login;
1674 $this->societe = $obj->company;
1675 $this->company = $obj->company;
1676 $this->socid = $obj->socid;
1677 $this->fk_soc = $obj->socid; // For backward compatibility
1678 $this->address = $obj->address;
1679 $this->zip = $obj->zip;
1680 $this->town = $obj->town;
1681
1682 $this->pass = $obj->pass;
1683 $this->pass_indatabase = $obj->pass;
1684 $this->pass_indatabase_crypted = $obj->pass_crypted;
1685
1686 $this->state_id = $obj->state_id;
1687 $this->state_code = $obj->state_id ? $obj->state_code : '';
1688 $this->state = $obj->state_id ? $obj->state : '';
1689
1690 $this->country_id = $obj->country_id;
1691 $this->country_code = $obj->country_code;
1692 if ($langs->trans("Country".$obj->country_code) != "Country".$obj->country_code) {
1693 $this->country = $langs->transnoentitiesnoconv("Country".$obj->country_code);
1694 } else {
1695 $this->country = $obj->country;
1696 }
1697
1698 $this->phone = $obj->phone;
1699 $this->phone_perso = $obj->phone_perso;
1700 $this->phone_mobile = $obj->phone_mobile;
1701 $this->email = $obj->email;
1702 $this->url = $obj->url;
1703
1704 $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks, true) : array());
1705
1706 $this->photo = $obj->photo;
1707 $this->statut = $obj->statut;
1708 $this->status = $obj->statut;
1709 $this->public = $obj->public;
1710
1711 $this->datec = $this->db->jdate($obj->datec);
1712 $this->date_creation = $this->db->jdate($obj->datec);
1713 $this->datem = $this->db->jdate($obj->datem);
1714 $this->date_modification = $this->db->jdate($obj->datem);
1715 $this->datefin = $this->db->jdate($obj->datefin);
1716 $this->datevalid = $this->db->jdate($obj->datev);
1717 $this->date_validation = $this->db->jdate($obj->datev);
1718 $this->birth = $this->db->jdate($obj->birthday);
1719
1720 $this->default_lang = $obj->default_lang;
1721
1722 $this->note_private = $obj->note_private;
1723 $this->note_public = $obj->note_public;
1724 $this->morphy = $obj->morphy;
1725
1726 $this->typeid = $obj->fk_adherent_type;
1727 $this->type = $obj->type;
1728 $this->need_subscription = $obj->subscription;
1729
1730 $this->user_id = $obj->user_id;
1731 $this->user_login = $obj->user_login;
1732
1733 $this->model_pdf = $obj->model_pdf;
1734
1735 // Retrieve all extrafield
1736 // fetch optionals attributes and labels
1737 if ($fetch_optionals) {
1738 $this->fetch_optionals();
1739 }
1740
1741 // Load other properties
1742 if ($fetch_subscriptions) {
1743 $result = $this->fetch_subscriptions();
1744 }
1745
1746 return $this->id;
1747 } else {
1748 return 0;
1749 }
1750 } else {
1751 $this->error = $this->db->lasterror();
1752 return -1;
1753 }
1754 }
1755
1756
1757 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1766 public function fetch_subscriptions()
1767 {
1768 // phpcs:enable
1769 require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
1770
1771 $sql = "SELECT c.rowid, c.fk_adherent, c.fk_type, c.subscription, c.note as note_public, c.fk_bank,";
1772 $sql .= " c.tms as datem,";
1773 $sql .= " c.datec as datec,";
1774 $sql .= " c.dateadh as dateh,";
1775 $sql .= " c.datef as datef";
1776 $sql .= " FROM ".MAIN_DB_PREFIX."subscription as c";
1777 $sql .= " WHERE c.fk_adherent = ".((int) $this->id);
1778 $sql .= " ORDER BY c.dateadh";
1779 dol_syslog(get_class($this)."::fetch_subscriptions", LOG_DEBUG);
1780
1781 $resql = $this->db->query($sql);
1782 if ($resql) {
1783 $this->subscriptions = array();
1784
1785 $i = 0;
1786 while ($obj = $this->db->fetch_object($resql)) {
1787 if ($i == 0) {
1788 $this->first_subscription_date = $this->db->jdate($obj->datec);
1789 $this->first_subscription_date_start = $this->db->jdate($obj->dateh);
1790 $this->first_subscription_date_end = $this->db->jdate($obj->datef);
1791 $this->first_subscription_amount = $obj->subscription;
1792 }
1793 $this->last_subscription_date = $this->db->jdate($obj->datec);
1794 $this->last_subscription_date_start = $this->db->jdate($obj->dateh);
1795 $this->last_subscription_date_end = $this->db->jdate($obj->datef);
1796 $this->last_subscription_amount = (float) $obj->subscription;
1797
1798 $subscription = new Subscription($this->db);
1799 $subscription->id = $obj->rowid;
1800 $subscription->fk_adherent = $obj->fk_adherent;
1801 $subscription->fk_type = $obj->fk_type;
1802 $subscription->amount = (float) $obj->subscription;
1803 $subscription->note = $obj->note_public;
1804 $subscription->note_public = $obj->note_public;
1805 $subscription->fk_bank = $obj->fk_bank;
1806 $subscription->datem = $this->db->jdate($obj->datem);
1807 $subscription->datec = $this->db->jdate($obj->datec);
1808 $subscription->dateh = $this->db->jdate($obj->dateh);
1809 $subscription->datef = $this->db->jdate($obj->datef);
1810
1811 $this->subscriptions[] = $subscription;
1812
1813 $i++;
1814 }
1815 return 1;
1816 } else {
1817 $this->error = $this->db->error().' sql='.$sql;
1818 return -1;
1819 }
1820 }
1821
1822
1829 public function fetchPartnerships($mode)
1830 {
1831 require_once DOL_DOCUMENT_ROOT.'/partnership/class/partnership.class.php';
1832
1833
1834 $this->partnerships[] = array();
1835
1836 return 1;
1837 }
1838
1839
1856 public function subscription($date, $amount, $accountid = 0, $operation = '', $label = '', $num_chq = '', $emetteur_nom = '', $emetteur_banque = '', $datesubend = 0, $fk_type = null, $ref_ext = '')
1857 {
1858 global $user;
1859
1860 require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
1861
1862 $error = 0;
1863
1864 // Clean parameters
1865 if (!$amount) {
1866 $amount = 0;
1867 }
1868
1869 $this->db->begin();
1870
1871 if ($datesubend) {
1872 $datefin = $datesubend;
1873 } else {
1874 // If no end date, end date = date + 1 year - 1 day
1875 $datefin = dol_time_plus_duree($date, 1, 'y');
1876 $datefin = dol_time_plus_duree($datefin, -1, 'd');
1877 }
1878
1879 // Create subscription
1880 $subscription = new Subscription($this->db);
1881 $subscription->fk_adherent = $this->id;
1882 $subscription->dateh = $date; // Date of new subscription
1883 $subscription->datef = $datefin; // End data of new subscription
1884 $subscription->amount = $amount;
1885 $subscription->note_public = $label;
1886 $subscription->note_private = '';
1887 $subscription->fk_type = $fk_type;
1888 $subscription->ref_ext = $ref_ext;
1889
1890 if (empty($subscription->user_creation_id)) {
1891 $subscription->user_creation_id = $user->id;
1892 }
1893
1894 $rowid = $subscription->create($user);
1895 if ($rowid > 0) {
1896 // Update denormalized subscription end date (read database subscription to find values)
1897 // This will also update this->datefin
1898 $result = $this->update_end_date($user);
1899 if ($result > 0) {
1900 // Change properties of object (used by triggers)
1901 $this->last_subscription_date = dol_now();
1902 $this->last_subscription_date_start = $date;
1903 $this->last_subscription_date_end = $datefin;
1904 $this->last_subscription_amount = $amount;
1905 } else {
1906 $error++;
1907 }
1908
1909 if (!$error) {
1910 $this->db->commit();
1911 return $rowid;
1912 } else {
1913 $this->db->rollback();
1914 return -2;
1915 }
1916 } else {
1917 $this->setErrorsFromObject($subscription);
1918 $this->db->rollback();
1919 return -1;
1920 }
1921 }
1922
1923
1943 public function subscriptionComplementaryActions($subscriptionid, $option, $accountid, $datesubscription, $paymentdate, $operation, $label, $amount, $num_chq, $emetteur_nom = '', $emetteur_banque = '', $autocreatethirdparty = 0, $ext_payment_id = '', $ext_payment_site = '')
1944 {
1945 global $conf, $langs, $user, $mysoc;
1946
1947 $error = 0;
1948
1949 $this->invoice = null; // This will contains invoice if an invoice is created
1950
1951 dol_syslog("subscriptionComplementaryActions subscriptionid=".$subscriptionid." option=".$option." accountid=".$accountid." datesubscription=".$datesubscription." paymentdate=".
1952 $paymentdate." label=".$label." amount=".$amount." num_chq=".$num_chq." autocreatethirdparty=".$autocreatethirdparty);
1953
1954 // Insert into bank account directlty (if option chosen for) + link to llx_subscription if option is 'bankdirect'
1955 if ($option == 'bankdirect' && $accountid) {
1956 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
1957
1958 $acct = new Account($this->db);
1959 $result = $acct->fetch($accountid);
1960
1961 $dateop = $paymentdate;
1962
1963 $insertid = $acct->addline($dateop, $operation, $label, $amount, $num_chq, 0, $user, $emetteur_nom, $emetteur_banque);
1964 if ($insertid > 0) {
1965 $inserturlid = $acct->add_url_line($insertid, $this->id, DOL_URL_ROOT.'/adherents/card.php?rowid=', $this->getFullName($langs), 'member');
1966 if ($inserturlid > 0) {
1967 // Update table subscription
1968 $sql = "UPDATE ".MAIN_DB_PREFIX."subscription SET fk_bank=".((int) $insertid);
1969 $sql .= " WHERE rowid=".((int) $subscriptionid);
1970
1971 dol_syslog("subscription::subscription", LOG_DEBUG);
1972 $resql = $this->db->query($sql);
1973 if (!$resql) {
1974 $error++;
1975 $this->error = $this->db->lasterror();
1976 $this->errors[] = $this->error;
1977 }
1978 } else {
1979 $error++;
1980 $this->setErrorsFromObject($acct);
1981 }
1982 } else {
1983 $error++;
1984 $this->setErrorsFromObject($acct);
1985 }
1986 }
1987
1988 // If option chosen, we create invoice
1989 if (($option == 'bankviainvoice' && $accountid) || $option == 'invoiceonly') {
1990 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1991 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/paymentterm.class.php';
1992
1993 $invoice = new Facture($this->db);
1994 $customer = new Societe($this->db);
1995
1996 if (!$error) {
1997 if (!($this->socid > 0)) { // If not yet linked to a company
1998 if ($autocreatethirdparty) {
1999 // Create a linked thirdparty to member
2000 $companyalias = '';
2001 $fullname = $this->getFullName($langs);
2002
2003 if ($this->morphy == 'mor') {
2004 $companyname = $this->company;
2005 if (!empty($fullname)) {
2006 $companyalias = $fullname;
2007 }
2008 } else {
2009 $companyname = $fullname;
2010 if (!empty($this->company)) {
2011 $companyalias = $this->company;
2012 }
2013 }
2014
2015 $result = $customer->create_from_member($this, (string) $companyname, $companyalias);
2016 if ($result < 0) {
2017 $this->error = $customer->error;
2018 $this->errors = $customer->errors;
2019 $error++;
2020 } else {
2021 $this->fk_soc = $result;
2022 $this->socid = $result;
2023 }
2024 } else {
2025 $langs->load("errors");
2026 $this->error = $langs->trans("ErrorMemberNotLinkedToAThirpartyLinkOrCreateFirst");
2027 $this->errors[] = $this->error;
2028 $error++;
2029 }
2030 }
2031 }
2032 if (!$error) {
2033 $result = $customer->fetch($this->socid);
2034 if ($result <= 0) {
2035 $this->error = $customer->error;
2036 $this->errors = $customer->errors;
2037 $error++;
2038 }
2039 }
2040
2041 if (!$error) {
2042 // Create draft invoice
2043 $invoice->type = Facture::TYPE_STANDARD;
2044 $invoice->cond_reglement_id = $customer->cond_reglement_id;
2045 if (empty($invoice->cond_reglement_id)) {
2046 $paymenttermstatic = new PaymentTerm($this->db);
2047 $invoice->cond_reglement_id = $paymenttermstatic->getDefaultId();
2048 if (empty($invoice->cond_reglement_id)) {
2049 $error++;
2050 $this->error = 'ErrorNoPaymentTermRECEPFound';
2051 $this->errors[] = $this->error;
2052 }
2053 }
2054 $invoice->socid = $this->socid;
2055 // set customer's payment bank account on the invoice
2056 if (!empty($customer->fk_account)) {
2057 $invoice->fk_account = $customer->fk_account;
2058 } elseif (getDolGlobalString('FACTURE_RIB_NUMBER')) {
2059 // set default bank account from invoice module settings
2060 $invoice->fk_account = (int) getDolGlobalString('FACTURE_RIB_NUMBER');
2061 }
2062 //set customer's payment method on the invoice
2063 if (!empty($customer->mode_reglement_id)) {
2064 $invoice->mode_reglement_id = $customer->mode_reglement_id;
2065 }
2066 //$invoice->date = $datesubscription;
2067 $invoice->date = dol_now();
2068
2069 // Possibility to add external linked objects with hooks
2070 $invoice->linked_objects['subscription'] = $subscriptionid;
2071 if (GETPOSTISARRAY('other_linked_objects')) {
2072 $invoice->linked_objects = array_merge($invoice->linked_objects, GETPOST('other_linked_objects', 'array:int'));
2073 }
2074
2075 $result = $invoice->create($user);
2076 if ($result <= 0) {
2077 $this->setErrorsFromObject($invoice);
2078 $error++;
2079 } else {
2080 $this->invoice = $invoice;
2081 }
2082 }
2083
2084 if (!$error) {
2085 // Add line to draft invoice
2086 $idprodsubscription = 0;
2087 if (getDolGlobalString('ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS') && (isModEnabled("product") || isModEnabled("service"))) {
2088 $idprodsubscription = getDolGlobalString('ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS');
2089 }
2090
2091 $vattouse = 0;
2092 if (getDolGlobalString('ADHERENT_VAT_FOR_SUBSCRIPTIONS') == 'defaultforfoundationcountry') {
2093 $vattouse = get_default_tva($mysoc, $mysoc, $idprodsubscription);
2094 } elseif (getDolGlobalInt('ADHERENT_VAT_FOR_SUBSCRIPTIONS') > 0) {
2095 $sql = "SELECT t.taux as vat_default_rate, t.code as vat_default_code, einvoice_vatex";
2096 $sql .= " FROM " . $this->db->prefix() . "c_tva as t";
2097 //$sql .= " INNER JOIN " . $this->db->prefix() . "c_departements as d ON t.fk_department_buyer = d.rowid";
2098 $sql .= " WHERE t.active > 0";
2099 $sql .= " AND t.entity IN (".getEntity('c_tva').")";
2100 $sql .= " AND t.rowid = ".(getDolGlobalInt('ADHERENT_VAT_FOR_SUBSCRIPTIONS'));
2101
2102 $res = $this->db->query($sql);
2103 if ($res) {
2104 if ($this->db->num_rows($res)) {
2105 $obj = $this->db->fetch_object($res);
2106
2107 $vattouse = $obj->vat_default_rate . ' (' . $obj->vat_default_code . ')';
2108 }
2109 $this->db->free($res);
2110 } else {
2111 dol_print_error($this->db);
2112 }
2113 }
2114
2115 //print xx".$vattouse." - ".$mysoc." - ".$customer;exit;
2116 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
2117 $result = $invoice->addline($label, 0, 1, $vattouse, 0, 0, $idprodsubscription, 0, $datesubscription, '', 0, 0, 0, 'TTC', $amount, 1);
2118 if ($result <= 0) {
2119 $this->setErrorsFromObject($invoice);
2120 $error++;
2121 }
2122 }
2123
2124 if (!$error) {
2125 // Validate invoice
2126 $result = $invoice->validate($user);
2127 if ($result <= 0) {
2128 $this->setErrorsFromObject($invoice);
2129 $error++;
2130 }
2131 }
2132
2133 if (!$error) {
2134 // TODO Link invoice with subscription ?
2135 }
2136
2137 // Add payment onto invoice
2138 if (!$error && $option == 'bankviainvoice' && $accountid) {
2139 require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
2140 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
2141 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
2142
2143 $amounts = array();
2144 $amounts[$invoice->id] = (float) price2num($amount);
2145
2146 $paiement = new Paiement($this->db);
2147 $paiement->datepaye = $paymentdate;
2148 $paiement->amounts = $amounts;
2149 $paiement->paiementcode = $operation;
2150 $paiement->paiementid = dol_getIdFromCode($this->db, $operation, 'c_paiement', 'code', 'id', 1);
2151 $paiement->num_payment = $num_chq;
2152 $paiement->note_public = $label;
2153 $paiement->ext_payment_id = $ext_payment_id;
2154 $paiement->ext_payment_site = $ext_payment_site;
2155
2156 // Create payment line for invoice
2157 $paiement_id = $paiement->create($user);
2158 if (!($paiement_id > 0)) {
2159 $this->setErrorsFromObject($paiement);
2160 $error++;
2161 }
2162
2163 if (!$error) {
2164 // Add transaction into bank account
2165 $bank_line_id = $paiement->addPaymentToBank($user, 'payment', '(SubscriptionPayment)', $accountid, $emetteur_nom, $emetteur_banque);
2166 if (!($bank_line_id > 0)) {
2167 $this->setErrorsFromObject($paiement);
2168 $error++;
2169 }
2170 }
2171
2172 if (!$error && !empty($bank_line_id)) {
2173 // Update fk_bank into subscription table
2174 $sql = 'UPDATE '.MAIN_DB_PREFIX.'subscription SET fk_bank='.((int) $bank_line_id);
2175 $sql .= ' WHERE rowid='.((int) $subscriptionid);
2176
2177 $result = $this->db->query($sql);
2178 if (!$result) {
2179 $error++;
2180 }
2181 }
2182
2183 if (!$error) {
2184 // Set invoice as paid
2185 $invoice->setPaid($user);
2186 }
2187 }
2188
2189 if (!$error) {
2190 // Define output language
2191 $outputlangs = $langs;
2192 $newlang = '';
2193 $lang_id = GETPOST('lang_id');
2194 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && !empty($lang_id)) {
2195 $newlang = $lang_id;
2196 }
2197 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
2198 $newlang = $customer->default_lang;
2199 }
2200 if (!empty($newlang)) {
2201 $outputlangs = new Translate("", $conf);
2202 $outputlangs->setDefaultLang($newlang);
2203 }
2204 // Generate PDF (whatever is option MAIN_DISABLE_PDF_AUTOUPDATE) so we can include it into email
2205 //if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE'))
2206
2207 $invoice->fetch($invoice->id); // Reload invoice object data
2208 $invoice->generateDocument($invoice->model_pdf, $outputlangs);
2209 }
2210 }
2211
2212 if ($error) {
2213 return -1;
2214 } else {
2215 return 1;
2216 }
2217 }
2218
2219
2227 public function validate($user, $notrigger = 0)
2228 {
2229 global $langs, $conf;
2230
2231 $error = 0;
2232 $now = dol_now();
2233
2234 // Check parameters
2235 if ($this->status == self::STATUS_VALIDATED) {
2236 dol_syslog(get_class($this)."::validate statut of member does not allow this", LOG_WARNING);
2237 return 0;
2238 }
2239
2240 $this->db->begin();
2241
2242 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
2243 $sql .= " statut = ".self::STATUS_VALIDATED;
2244 $sql .= ", datevalid = '".$this->db->idate($now)."'";
2245 $sql .= ", fk_user_valid = ".((int) $user->id);
2246 $sql .= " WHERE rowid = ".((int) $this->id);
2247
2248 dol_syslog(get_class($this)."::validate", LOG_DEBUG);
2249 $result = $this->db->query($sql);
2250 if ($result) {
2251 $this->statut = self::STATUS_VALIDATED;
2253
2254 // Call trigger
2255 if (!$notrigger) {
2256 $result = $this->call_trigger('MEMBER_VALIDATE', $user);
2257 if ($result < 0) {
2258 $error++;
2259 $this->db->rollback();
2260 return -1;
2261 }
2262 }
2263 // End call triggers
2264
2265 $this->datevalid = $now;
2266
2267 $this->db->commit();
2268 return 1;
2269 } else {
2270 $this->error = $this->db->error();
2271 $this->db->rollback();
2272 return -1;
2273 }
2274 }
2275
2276
2283 public function resiliate($user)
2284 {
2285 global $langs, $conf;
2286
2287 $error = 0;
2288
2289 // Check parameters
2290 if ($this->status == self::STATUS_RESILIATED) {
2291 dol_syslog(get_class($this)."::resiliate statut of member does not allow this", LOG_WARNING);
2292 return 0;
2293 }
2294
2295 $this->db->begin();
2296
2297 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
2298 $sql .= " statut = ".((int) self::STATUS_RESILIATED);
2299 $sql .= ", fk_user_valid = ".((int) $user->id);
2300 $sql .= " WHERE rowid = ".((int) $this->id);
2301
2302 $result = $this->db->query($sql);
2303 if ($result) {
2304 $this->statut = self::STATUS_RESILIATED;
2306
2307 // Call trigger
2308 $result = $this->call_trigger('MEMBER_RESILIATE', $user);
2309 if ($result < 0) {
2310 $error++;
2311 $this->db->rollback();
2312 return -1;
2313 }
2314 // End call triggers
2315
2316 $this->db->commit();
2317 return 1;
2318 } else {
2319 $this->error = $this->db->error();
2320 $this->db->rollback();
2321 return -1;
2322 }
2323 }
2324
2334 public function exclude($user)
2335 {
2336 $error = 0;
2337
2338 // Check parameters
2339 if ($this->status == self::STATUS_EXCLUDED) {
2340 dol_syslog(get_class($this)."::resiliate statut of member does not allow this", LOG_WARNING);
2341 return 0;
2342 }
2343
2344 $this->db->begin();
2345
2346 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
2347 $sql .= " statut = ".((int) self::STATUS_EXCLUDED);
2348 $sql .= ", fk_user_valid = ".((int) $user->id);
2349 $sql .= " WHERE rowid = ".((int) $this->id);
2350
2351 $result = $this->db->query($sql);
2352 if ($result) {
2353 $this->statut = self::STATUS_EXCLUDED;
2355
2356 // Call trigger
2357 $result = $this->call_trigger('MEMBER_EXCLUDE', $user);
2358 if ($result < 0) {
2359 $error++;
2360 $this->db->rollback();
2361 return -1;
2362 }
2363 // End call triggers
2364
2365 $this->db->commit();
2366 return 1;
2367 } else {
2368 $this->error = $this->db->error();
2369 $this->db->rollback();
2370 return -1;
2371 }
2372 }
2373
2374 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2380 public function add_to_abo()
2381 {
2382 // phpcs:enable
2383 global $langs;
2384
2385 include_once DOL_DOCUMENT_ROOT.'/mailmanspip/class/mailmanspip.class.php';
2386 $mailmanspip = new MailmanSpip($this->db);
2387
2388 $err = 0;
2389
2390 // mailman
2391 if (getDolGlobalString('ADHERENT_USE_MAILMAN') && isModEnabled('mailmanspip')) {
2392 $result = $mailmanspip->add_to_mailman($this);
2393
2394 if ($result < 0) {
2395 if (!empty($mailmanspip->error)) {
2396 $this->errors[] = $mailmanspip->error;
2397 }
2398 $err += 1;
2399 }
2400 foreach ($mailmanspip->mladded_ko as $tmplist => $tmpemail) {
2401 $langs->load("errors");
2402 $this->errors[] = $langs->trans("ErrorFailedToAddToMailmanList", $tmpemail, $tmplist);
2403 }
2404 foreach ($mailmanspip->mladded_ok as $tmplist => $tmpemail) {
2405 $langs->load("mailmanspip");
2406 $this->mesgs[] = $langs->trans("SuccessToAddToMailmanList", $tmpemail, $tmplist);
2407 }
2408 }
2409
2410 // spip
2411 if (getDolGlobalString('ADHERENT_USE_SPIP') && isModEnabled('mailmanspip')) {
2412 $result = $mailmanspip->add_to_spip($this);
2413 if ($result < 0) {
2414 $this->errors[] = $mailmanspip->error;
2415 $err += 1;
2416 }
2417 }
2418 if ($err) {
2419 return -$err;
2420 } else {
2421 return 1;
2422 }
2423 }
2424
2425
2426 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2432 public function del_to_abo()
2433 {
2434 // phpcs:enable
2435 global $conf, $langs;
2436
2437 include_once DOL_DOCUMENT_ROOT.'/mailmanspip/class/mailmanspip.class.php';
2438 $mailmanspip = new MailmanSpip($this->db);
2439
2440 $err = 0;
2441
2442 // mailman
2443 if (getDolGlobalString('ADHERENT_USE_MAILMAN')) {
2444 $result = $mailmanspip->del_to_mailman($this);
2445 if ($result < 0) {
2446 if (!empty($mailmanspip->error)) {
2447 $this->errors[] = $mailmanspip->error;
2448 }
2449 $err += 1;
2450 }
2451
2452 foreach ($mailmanspip->mlremoved_ko as $tmplist => $tmpemail) {
2453 $langs->load("errors");
2454 $this->errors[] = $langs->trans("ErrorFailedToRemoveToMailmanList", $tmpemail, $tmplist);
2455 }
2456 foreach ($mailmanspip->mlremoved_ok as $tmplist => $tmpemail) {
2457 $langs->load("mailmanspip");
2458 $this->mesgs[] = $langs->trans("SuccessToRemoveToMailmanList", $tmpemail, $tmplist);
2459 }
2460 }
2461
2462 if (getDolGlobalString('ADHERENT_USE_SPIP') && isModEnabled('mailmanspip')) {
2463 $result = $mailmanspip->del_to_spip($this);
2464 if ($result < 0) {
2465 $this->errors[] = $mailmanspip->error;
2466 $err += 1;
2467 }
2468 }
2469 if ($err) {
2470 // error
2471 return -$err;
2472 } else {
2473 return 1;
2474 }
2475 }
2476
2477
2483 public function getCivilityLabel()
2484 {
2485 global $langs;
2486 $langs->load("dict");
2487
2488 $code = (empty($this->civility_id) ? '' : $this->civility_id);
2489 if (empty($code)) {
2490 return '';
2491 }
2492 return $langs->getLabelFromKey($this->db, "Civility".$code, "c_civility", "code", "label", $code);
2493 }
2494
2501 public function getTooltipContentArray($params)
2502 {
2503 global $langs;
2504
2505 $langs->loadLangs(['members', 'companies']);
2506 $nofetch = !empty($params['nofetch']);
2507
2508 $datas = array();
2509
2510 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
2511 $langs->load("users");
2512 return ['optimize' => $langs->trans("ShowUser")];
2513 }
2514 if (!empty($this->photo)) {
2515 $photo = '<div class="photointooltip floatright">';
2516 $photo .= Form::showphoto('memberphoto', $this, 80, 0, 0, 'photoref photowithmargin photologintooltip', 'small', 0, 1);
2517 $photo .= '</div>';
2518 $datas['photo'] = $photo;
2519 }
2520
2521 $datas['divopen'] = '<div class="centpercent">';
2522 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Member").'</u> '.$this->getLibStatut(4);
2523 if (!empty($this->morphy)) {
2524 $datas['picto'] .= '&nbsp;' . $this->getmorphylib('', 1);
2525 }
2526 if (!empty($this->ref)) {
2527 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
2528 }
2529 if (!empty($this->login)) {
2530 $datas['login'] = '<br><b>'.$langs->trans('Login').':</b> '.$this->login;
2531 }
2532 if (!empty($this->firstname) || !empty($this->lastname)) {
2533 $datas['name'] = '<br><b>'.$langs->trans('Name').':</b> '.$this->getFullName($langs);
2534 }
2535 if (!empty($this->company)) {
2536 $datas['company'] = '<br><b>'.$langs->trans('Company').':</b> '.$this->company;
2537 }
2538 if (!empty($this->email)) {
2539 $datas['email'] = '<br><b>'.$langs->trans("EMail").':</b> '.$this->email;
2540 }
2541 $datas['address'] = '<br><b>'.$langs->trans("Address").':</b> '.dol_format_address($this, 1, ' ', $langs);
2542 // show categories for this record only in ajax to not overload lists
2543 if (isModEnabled('category') && !$nofetch) {
2544 require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
2545 $form = new Form($this->db);
2546 $datas['categories'] = '<br>' . $form->showCategories($this->id, Categorie::TYPE_MEMBER, 1);
2547 }
2548 $datas['divclose'] = '</div>';
2549
2550 return $datas;
2551 }
2552
2566 public function getNomUrl($withpictoimg = 0, $maxlen = 0, $option = 'card', $mode = '', $morecss = '', $save_lastsearch_value = -1, $notooltip = 0, $addlinktonotes = 0)
2567 {
2568 global $langs, $hookmanager;
2569
2570 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') && $withpictoimg) {
2571 $withpictoimg = 0;
2572 }
2573
2574 $result = '';
2575 $linkstart = '';
2576 $linkend = '';
2577 $classfortooltip = 'classfortooltip';
2578 $dataparams = '';
2579 $params = [
2580 'id' => $this->id,
2581 'objecttype' => $this->element,
2582 'option' => $option,
2583 'nofetch' => 1,
2584 ];
2585 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
2586 $classfortooltip = 'classforajaxtooltip';
2587 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
2588 $label = '';
2589 } else {
2590 $label = implode($this->getTooltipContentArray($params));
2591 }
2592
2593 $baseurl = DOL_URL_ROOT . '/adherents/card.php';
2594 if ($option == 'subscription') {
2595 $baseurl = DOL_URL_ROOT . '/adherents/subscription.php';
2596 }
2597 $query = ['rowid' => $this->id];
2598
2599 if ($option != 'nolink') {
2600 // Add param to save lastsearch_values or not
2601 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2602 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
2603 $add_save_lastsearch_values = 1;
2604 }
2605 if ($add_save_lastsearch_values) {
2606 $query = array_merge($query, ['save_lastsearch_values' => 1]);
2607 }
2608 }
2609 $url = dolBuildUrl($baseurl, $query);
2610
2611 $linkstart .= '<a href="'.$url.'"';
2612 $linkclose = "";
2613 if (empty($notooltip)) {
2614 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
2615 $langs->load("users");
2616 $label = $langs->trans("ShowUser");
2617 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
2618 }
2619 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
2620 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
2621 }
2622
2623 $linkstart .= $linkclose.'>';
2624 $linkend = '</a>';
2625
2626 $result .= $linkstart;
2627
2628 if ($withpictoimg) {
2629 if (abs($withpictoimg) == 1 || abs($withpictoimg) == 4) {
2630 $morecss .= ' paddingrightonly';
2631 }
2632 // Only picto
2633 if ($withpictoimg > 0) {
2634 $picto = '<span class="nopadding'.($morecss ? ' userimg'.$morecss : '').'">'.img_object('', 'user', ' '.($notooltip ? '' : $dataparams), 0, 0, $notooltip ? 0 : 1).'</span>';
2635 } else {
2636 // Picto must be a photo
2637 $picto = '<span class="nopadding'.($morecss ? ' userimg'.$morecss : '').'">';
2638 $picto .= Form::showphoto('memberphoto', $this, 0, 0, 0, 'userphoto'.(($withpictoimg == -3 || $withpictoimg == -4) ? 'small' : ''), 'mini', 0, 1);
2639 $picto .= '</span>';
2640 }
2641 $result .= $picto;
2642 }
2643 if (($withpictoimg > -2 && $withpictoimg != 2) || $withpictoimg == -4) {
2644 if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
2645 $result .= '<span class="nopadding valignmiddle'.((!isset($this->status) || $this->status) ? '' : ' strikefordisabled').
2646 ($morecss ? ' usertext'.$morecss : '').'">';
2647 }
2648 if ($mode == 'login') {
2649 $result .= dol_trunc(isset($this->login) ? $this->login : '', $maxlen);
2650 } elseif ($mode == 'ref') {
2651 $result .= $this->ref;
2652 } else {
2653 if (empty($this->lastname) && empty($this->firstname) && !empty($this->company)) {
2654 $result .= $this->company;
2655 } else {
2656 $result .= $this->getFullName($langs, 0, ($mode == 'firstname' ? 2 : ($mode == 'lastname' ? 4 : -1)), $maxlen);
2657 }
2658 }
2659 if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
2660 $result .= '</span>';
2661 }
2662 }
2663
2664 $result .= $linkend;
2665
2666 if ($addlinktonotes) {
2667 if ($this->note_private) {
2668 $notetoshow = $langs->trans("ViewPrivateNote").':<br>'.dol_string_nohtmltag($this->note_private, 1);
2669 $result .= ' <span class="note inline-block">';
2670 $result .= '<a href="'.DOL_URL_ROOT.'/adherents/note.php?id='.$this->id.'" class="classfortooltip" title="'.dol_escape_htmltag($notetoshow).'">';
2671 $result .= img_picto('', 'note');
2672 $result .= '</a>';
2673 $result .= '</span>';
2674 }
2675 }
2676 global $action;
2677 $hookmanager->initHooks(array($this->element . 'dao'));
2678 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
2679 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
2680 if ($reshook > 0) {
2681 $result = $hookmanager->resPrint;
2682 } else {
2683 $result .= $hookmanager->resPrint;
2684 }
2685 return $result;
2686 }
2687
2694 public function getLibStatut($mode = 0)
2695 {
2696 return $this->LibStatut($this->status, $this->need_subscription, $this->datefin, $mode);
2697 }
2698
2699 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2709 public function LibStatut($status, $need_subscription, $date_end_subscription, $mode = 0)
2710 {
2711 // phpcs:enable
2712 global $langs;
2713 $langs->load("members");
2714
2715 $statusType = '';
2716 $labelStatus = '';
2717 $labelStatusShort = '';
2718
2719 if ($status == self::STATUS_DRAFT) {
2720 $statusType = 'status0';
2721 $labelStatus = $langs->trans("MemberStatusDraft");
2722 $labelStatusShort = $langs->trans("MemberStatusDraftShort");
2723 } elseif ($status >= self::STATUS_VALIDATED) {
2724 if (empty($need_subscription)) {
2725 $statusType = 'status4';
2726 $labelStatus = $langs->trans("Validated").' - '.$langs->trans("SubscriptionNotNeeded");
2727 $labelStatusShort = $langs->trans("MemberStatusNoSubscriptionShort");
2728 } elseif (!$date_end_subscription) {
2729 $statusType = 'status1';
2730 $labelStatus = $langs->trans("Validated").' - '.$langs->trans("WaitingSubscription");
2731 $labelStatusShort = $langs->trans("WaitingSubscriptionShort");
2732 } elseif ($date_end_subscription < dol_now()) { // expired
2733 $statusType = 'status2';
2734 $labelStatus = $langs->trans("Validated").' - '.$langs->trans("MemberStatusActiveLate");
2735 $labelStatusShort = $langs->trans("MemberStatusActiveLateShort");
2736 } else {
2737 $statusType = 'status4';
2738 $labelStatus = $langs->trans("Validated").' - '.$langs->trans("MemberStatusPaid");
2739 $labelStatusShort = $langs->trans("MemberStatusPaidShort");
2740 }
2741 } elseif ($status == self::STATUS_RESILIATED) {
2742 $statusType = 'status6';
2743 $labelStatus = $langs->transnoentitiesnoconv("MemberStatusResiliated");
2744 $labelStatusShort = $langs->transnoentitiesnoconv("MemberStatusResiliatedShort");
2745 } elseif ($status == self::STATUS_EXCLUDED) {
2746 $statusType = 'status10';
2747 $labelStatus = $langs->transnoentitiesnoconv("MemberStatusExcluded");
2748 $labelStatusShort = $langs->transnoentitiesnoconv("MemberStatusExcludedShort");
2749 }
2750
2751 return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode);
2752 }
2753
2754
2760 public function loadStateBoard()
2761 {
2762 global $conf;
2763
2764 $this->nb = array();
2765
2766 $sql = "SELECT count(a.rowid) as nb";
2767 $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a";
2768 $sql .= " WHERE a.statut > 0";
2769 $sql .= " AND a.entity IN (".getEntity('adherent').")";
2770
2771 $resql = $this->db->query($sql);
2772 if ($resql) {
2773 while ($obj = $this->db->fetch_object($resql)) {
2774 $this->nb["members"] = $obj->nb;
2775 }
2776 $this->db->free($resql);
2777 return 1;
2778 } else {
2779 dol_print_error($this->db);
2780 $this->error = $this->db->error();
2781 return -1;
2782 }
2783 }
2784
2785 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2793 public function load_board($user, $mode)
2794 {
2795 // phpcs:enable
2796 global $conf, $langs;
2797
2798 if ($user->socid) {
2799 return -1; // Protection to prevent calls by external users
2800 }
2801
2802 $now = dol_now();
2803
2804 $sql = "SELECT a.rowid, a.datefin, a.statut as status";
2805 $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a";
2806 $sql .= ", ".MAIN_DB_PREFIX."adherent_type as t";
2807 $sql .= " WHERE a.fk_adherent_type = t.rowid";
2808 if ($mode == 'expired') {
2809 $sql .= " AND a.statut = ".self::STATUS_VALIDATED;
2810 $sql .= " AND a.entity IN (".getEntity('adherent').")";
2811 $sql .= " AND ((a.datefin IS NULL or a.datefin < '".$this->db->idate($now)."') AND t.subscription = '1')";
2812 } elseif ($mode == 'shift') {
2813 $sql .= " AND a.statut = ".self::STATUS_DRAFT;
2814 $sql .= " AND a.entity IN (".getEntity('adherent').")";
2815 }
2816
2817 $resql = $this->db->query($sql);
2818 if ($resql) {
2819 $langs->load("members");
2820
2821 $warning_delay = 0;
2822 $url = '';
2823 $label = '';
2824 $labelShort = '';
2825
2826 if ($mode == 'expired') {
2827 $warning_delay = getWarningDelay('member', 'subscription') / 60 / 60 / 24;
2828 $label = $langs->trans("MembersWithSubscriptionToReceive");
2829 $labelShort = $langs->trans("MembersWithSubscriptionToReceiveShort");
2830 $url = dolBuildUrl(DOL_URL_ROOT.'/adherents/list.php', ['mainmenu' => 'members', 'statut' => self::STATUS_VALIDATED, 'filter' => 'outofdate']);
2831 } elseif ($mode == 'shift') {
2832 $warning_delay = getWarningDelay('member', 'subscription') / 60 / 60 / 24;
2833 $url = dolBuildUrl(DOL_URL_ROOT.'/adherents/list.php', ['mainmenu' => 'members', 'statut' => self::STATUS_DRAFT]);
2834 $label = $langs->trans("MembersListToValid");
2835 $labelShort = $langs->trans("ToValidate");
2836 }
2837
2838 $response = new WorkboardResponse();
2839 $response->warning_delay = $warning_delay;
2840 $response->label = $label;
2841 $response->labelShort = $labelShort;
2842 $response->url = $url;
2843 $response->img = img_object('', "user");
2844
2845 $adherentstatic = new Adherent($this->db);
2846
2847 while ($obj = $this->db->fetch_object($resql)) {
2848 $response->nbtodo++;
2849
2850 $adherentstatic->datefin = $this->db->jdate($obj->datefin);
2851 $adherentstatic->statut = $obj->status;
2852 $adherentstatic->status = $obj->status;
2853
2854 if ($adherentstatic->hasDelay()) {
2855 $response->nbtodolate++;
2856 }
2857 }
2858
2859 return $response;
2860 } else {
2861 dol_print_error($this->db);
2862 $this->error = $this->db->error();
2863 return -1;
2864 }
2865 }
2866
2867
2879 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
2880 {
2881 global $conf, $langs;
2882
2883 $langs->load("orders");
2884
2885 if (!dol_strlen($modele)) {
2886 $modele = 'standard';
2887
2888 if ($this->model_pdf) {
2889 $modele = $this->model_pdf;
2890 } elseif (getDolGlobalString('ADHERENT_ADDON_PDF')) {
2891 $modele = getDolGlobalString('ADHERENT_ADDON_PDF');
2892 }
2893 }
2894
2895 $modelpath = "core/modules/member/doc/";
2896
2897 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
2898 }
2899
2900
2908 public function initAsSpecimen()
2909 {
2910 global $user, $langs;
2911 $now = dol_now();
2912
2913 // Initialise parameters
2914 $this->id = 0;
2915 $this->ref = 'ABC001';
2916 $this->entity = 1;
2917 $this->specimen = 1;
2918 $this->civility_id = 'MR';
2919 $this->lastname = 'DOLIBARR';
2920 $this->firstname = 'SPECIMEN';
2921 $this->gender = 'man';
2922 $this->login = 'dolibspec';
2923 $this->pass = 'dolibspec';
2924 $this->company = 'Societe ABC';
2925 $this->address = '61 jump street';
2926 $this->zip = '75000';
2927 $this->town = 'Paris';
2928 $this->country_id = 1;
2929 $this->country_code = 'FR';
2930 $this->country = 'France';
2931 $this->morphy = 'mor';
2932 $this->email = 'specimen@specimen.com';
2933 $this->socialnetworks = array(
2934 'skype' => 'skypepseudo',
2935 'twitter' => 'twitterpseudo',
2936 'facebook' => 'facebookpseudo',
2937 'linkedin' => 'linkedinpseudo',
2938 );
2939 $this->phone = '0999999999';
2940 $this->phone_perso = '0999999998';
2941 $this->phone_mobile = '0999999997';
2942 $this->note_public = 'This is a public note';
2943 $this->note_private = 'This is a private note';
2944 $this->birth = $now;
2945 $this->photo = '';
2946 $this->public = 1;
2947 $this->statut = self::STATUS_DRAFT;
2948 $this->status = self::STATUS_DRAFT;
2949
2950 $this->datefin = $now;
2951 $this->datevalid = $now;
2952 $this->default_lang = '';
2953
2954 $this->typeid = 1; // Id type adherent
2955 $this->type = 'Type adherent'; // Libelle type adherent
2956 $this->need_subscription = 0;
2957
2958 $this->first_subscription_date = $now;
2959 $this->first_subscription_date_start = $this->first_subscription_date;
2960 $this->first_subscription_date_end = dol_time_plus_duree($this->first_subscription_date_start, 1, 'y');
2961 $this->first_subscription_amount = 10;
2962
2963 $this->last_subscription_date = $this->first_subscription_date;
2964 $this->last_subscription_date_start = $this->first_subscription_date;
2965 $this->last_subscription_date_end = dol_time_plus_duree($this->last_subscription_date_start, 1, 'y');
2966 $this->last_subscription_amount = 10;
2967 return 1;
2968 }
2969
2970
2971 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2972 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2982 public function _load_ldap_dn($info, $mode = 0)
2983 {
2984 // phpcs:enable
2985 global $conf;
2986 $dn = '';
2987 if ($mode == 0) {
2988 $dn = getDolGlobalString('LDAP_KEY_MEMBERS') . "=".$info[getDolGlobalString('LDAP_KEY_MEMBERS')]."," . getDolGlobalString('LDAP_MEMBER_DN');
2989 }
2990 if ($mode == 1) {
2991 $dn = getDolGlobalString('LDAP_MEMBER_DN');
2992 }
2993 if ($mode == 2) {
2994 $dn = getDolGlobalString('LDAP_KEY_MEMBERS') . "=".$info[getDolGlobalString('LDAP_KEY_MEMBERS')];
2995 }
2996 return $dn;
2997 }
2998
2999
3000 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
3001 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
3007 public function _load_ldap_info()
3008 {
3009 // phpcs:enable
3010 global $conf, $langs;
3011
3012 $info = array();
3013 $socialnetworks = getArrayOfSocialNetworks();
3014 $keymodified = false;
3015
3016 // Object classes
3017 $info["objectclass"] = explode(',', getDolGlobalString('LDAP_MEMBER_OBJECT_CLASS'));
3018
3019 $this->fullname = $this->getFullName($langs);
3020
3021 // For avoid ldap error when firstname and lastname are empty
3022 if ($this->morphy == 'mor' && (empty($this->fullname) || $this->fullname == $this->company)) {
3023 $this->fullname = $this->company;
3024 $this->lastname = $this->company;
3025 }
3026
3027 // Possible LDAP KEY (constname => varname)
3028 $ldapkey = array(
3029 'LDAP_MEMBER_FIELD_FULLNAME' => 'fullname',
3030 'LDAP_MEMBER_FIELD_NAME' => 'lastname',
3031 'LDAP_MEMBER_FIELD_LOGIN' => 'login',
3032 'LDAP_MEMBER_FIELD_LOGIN_SAMBA' => 'login',
3033 'LDAP_MEMBER_FIELD_MAIL' => 'email'
3034 );
3035
3036 // Member
3037 foreach ($ldapkey as $constname => $varname) {
3038 if (!empty($this->$varname) && getDolGlobalString($constname)) {
3039 $info[getDolGlobalString($constname)] = $this->$varname;
3040
3041 // Check if it is the LDAP key and if its value has been changed
3042 if (getDolGlobalString('LDAP_KEY_MEMBERS') && getDolGlobalString('LDAP_KEY_MEMBERS') == getDolGlobalString($constname)) {
3043 if (!empty($this->oldcopy) && $this->$varname != $this->oldcopy->$varname) {
3044 $keymodified = true; // For check if LDAP key has been modified
3045 }
3046 }
3047 }
3048 }
3049 if ($this->firstname && getDolGlobalString('LDAP_MEMBER_FIELD_FIRSTNAME')) {
3050 $info[getDolGlobalString('LDAP_MEMBER_FIELD_FIRSTNAME')] = $this->firstname;
3051 }
3052 if ($this->poste && getDolGlobalString('LDAP_MEMBER_FIELD_TITLE')) {
3053 $info[getDolGlobalString('LDAP_MEMBER_FIELD_TITLE')] = $this->poste;
3054 }
3055 if ($this->company && getDolGlobalString('LDAP_MEMBER_FIELD_COMPANY')) {
3056 $info[getDolGlobalString('LDAP_MEMBER_FIELD_COMPANY')] = $this->company;
3057 }
3058 if ($this->address && getDolGlobalString('LDAP_MEMBER_FIELD_ADDRESS')) {
3059 $info[getDolGlobalString('LDAP_MEMBER_FIELD_ADDRESS')] = $this->address;
3060 }
3061 if ($this->zip && getDolGlobalString('LDAP_MEMBER_FIELD_ZIP')) {
3062 $info[getDolGlobalString('LDAP_MEMBER_FIELD_ZIP')] = $this->zip;
3063 }
3064 if ($this->town && getDolGlobalString('LDAP_MEMBER_FIELD_TOWN')) {
3065 $info[getDolGlobalString('LDAP_MEMBER_FIELD_TOWN')] = $this->town;
3066 }
3067 if ($this->country_code && getDolGlobalString('LDAP_MEMBER_FIELD_COUNTRY')) {
3068 $info[getDolGlobalString('LDAP_MEMBER_FIELD_COUNTRY')] = $this->country_code;
3069 }
3070 foreach ($socialnetworks as $key => $value) {
3071 if ($this->socialnetworks[$value['label']] && getDolGlobalString('LDAP_MEMBER_FIELD_'.strtoupper($value['label']))) {
3072 $info[getDolGlobalString('LDAP_MEMBER_FIELD_'.strtoupper($value['label']))] = $this->socialnetworks[$value['label']];
3073 }
3074 }
3075 if ($this->phone && getDolGlobalString('LDAP_MEMBER_FIELD_PHONE')) {
3076 $info[getDolGlobalString('LDAP_MEMBER_FIELD_PHONE')] = $this->phone;
3077 }
3078 if ($this->phone_perso && getDolGlobalString('LDAP_MEMBER_FIELD_PHONE_PERSO')) {
3079 $info[getDolGlobalString('LDAP_MEMBER_FIELD_PHONE_PERSO')] = $this->phone_perso;
3080 }
3081 if ($this->phone_mobile && getDolGlobalString('LDAP_MEMBER_FIELD_MOBILE')) {
3082 $info[getDolGlobalString('LDAP_MEMBER_FIELD_MOBILE')] = $this->phone_mobile;
3083 }
3084 if ($this->fax && getDolGlobalString('LDAP_MEMBER_FIELD_FAX')) {
3085 $info[getDolGlobalString('LDAP_MEMBER_FIELD_FAX')] = $this->fax;
3086 }
3087 if ($this->note_private && getDolGlobalString('LDAP_MEMBER_FIELD_DESCRIPTION')) {
3088 $info[getDolGlobalString('LDAP_MEMBER_FIELD_DESCRIPTION')] = dol_string_nohtmltag($this->note_private, 2);
3089 }
3090 if ($this->note_public && getDolGlobalString('LDAP_MEMBER_FIELD_NOTE_PUBLIC')) {
3091 $info[getDolGlobalString('LDAP_MEMBER_FIELD_NOTE_PUBLIC')] = dol_string_nohtmltag($this->note_public, 2);
3092 }
3093 if ($this->birth && getDolGlobalString('LDAP_MEMBER_FIELD_BIRTHDATE')) {
3094 $info[getDolGlobalString('LDAP_MEMBER_FIELD_BIRTHDATE')] = dol_print_date($this->birth, 'dayhourldap');
3095 }
3096 if (isset($this->statut) && getDolGlobalString('LDAP_FIELD_MEMBER_STATUS')) {
3097 $info[getDolGlobalString('LDAP_FIELD_MEMBER_STATUS')] = $this->statut;
3098 }
3099 if ($this->datefin && getDolGlobalString('LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION')) {
3100 $info[getDolGlobalString('LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION')] = dol_print_date($this->datefin, 'dayhourldap');
3101 }
3102
3103 // When password is modified
3104 if (!empty($this->pass)) {
3105 if (getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD')) {
3106 $info[getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD')] = $this->pass; // this->pass = Unencrypted password
3107 }
3108 if (getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')) {
3109 $info[getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')] = dol_hash($this->pass, 'openldap'); // Create OpenLDAP password (see LDAP_PASSWORD_HASH_TYPE)
3110 }
3111 } elseif (getDolGlobalString('LDAP_SERVER_PROTOCOLVERSION') !== '3') {
3112 // Set LDAP password if possible
3113 // If ldap key is modified and LDAPv3 we use ldap_rename function for avoid lose encrypt password
3114 if (getDolGlobalString('DATABASE_PWD_ENCRYPTED')) { // This should be on on default installation
3115 // Just for the case we use old md5 encryption (deprecated, no more used, kept for compatibility)
3116 if (!getDolGlobalString('MAIN_SECURITY_HASH_ALGO') || getDolGlobalString('MAIN_SECURITY_HASH_ALGO') == 'md5') {
3117 if ($this->pass_indatabase_crypted && getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')) {
3118 // Create OpenLDAP MD5 password from Dolibarr MD5 password
3119 // Note: This suppose that "pass_indatabase_crypted" is a md5 (this should not happen anymore)"
3120 $info[getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')] = dolGetLdapPasswordHash($this->pass_indatabase_crypted, 'md5frommd5');
3121 }
3122 }
3123 } elseif (!empty($this->pass_indatabase)) {
3124 // Use $this->pass_indatabase value if exists
3125 if (getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD')) {
3126 $info[getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD')] = $this->pass_indatabase; // $this->pass_indatabase = Unencrypted password
3127 }
3128 if (getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')) {
3129 $info[getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')] = dol_hash($this->pass_indatabase, 'openldap'); // Create OpenLDAP password (see LDAP_PASSWORD_HASH_TYPE)
3130 }
3131 }
3132 }
3133
3134 // Subscriptions
3135 if ($this->first_subscription_date && getDolGlobalString('LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE')) {
3136 $info[getDolGlobalString('LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE')] = dol_print_date($this->first_subscription_date, 'dayhourldap');
3137 }
3138 if (isset($this->first_subscription_amount) && getDolGlobalString('LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT')) {
3139 $info[getDolGlobalString('LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT')] = $this->first_subscription_amount;
3140 }
3141 if ($this->last_subscription_date && getDolGlobalString('LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE')) {
3142 $info[getDolGlobalString('LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE')] = dol_print_date($this->last_subscription_date, 'dayhourldap');
3143 }
3144 if (isset($this->last_subscription_amount) && getDolGlobalString('LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT')) {
3145 $info[getDolGlobalString('LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT')] = $this->last_subscription_amount;
3146 }
3147
3148 return $info;
3149 }
3150
3151
3158 public function info($id)
3159 {
3160 $sql = 'SELECT a.rowid, a.datec as datec,';
3161 $sql .= ' a.datevalid as datev,';
3162 $sql .= ' GREATEST(a.tms, COALESCE(aef.tms, a.tms)) as datem,';
3163 $sql .= ' a.fk_user_author, a.fk_user_valid, a.fk_user_mod';
3164 $sql .= ' FROM '.MAIN_DB_PREFIX.'adherent as a';
3165 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'adherent_extrafields as aef ON aef.fk_object = a.rowid';
3166 $sql .= ' WHERE a.rowid = '.((int) $id);
3167
3168 dol_syslog(get_class($this)."::info", LOG_DEBUG);
3169 $result = $this->db->query($sql);
3170 if ($result) {
3171 if ($this->db->num_rows($result)) {
3172 $obj = $this->db->fetch_object($result);
3173
3174 $this->id = $obj->rowid;
3175
3176 $this->user_creation_id = $obj->fk_user_author;
3177 $this->user_validation_id = $obj->fk_user_valid;
3178 $this->user_modification_id = $obj->fk_user_mod;
3179 $this->date_creation = $this->db->jdate($obj->datec);
3180 $this->date_validation = $this->db->jdate($obj->datev);
3181 $this->date_modification = $this->db->jdate($obj->datem);
3182 }
3183
3184 $this->db->free($result);
3185 } else {
3186 dol_print_error($this->db);
3187 }
3188 }
3189
3195 public function getNbOfEMailings()
3196 {
3197 $sql = "SELECT count(mc.email) as nb";
3198 $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
3199 $sql .= " WHERE mc.email = '".$this->db->escape($this->email)."'";
3200 $sql .= " AND mc.statut NOT IN (-1,0)"; // -1 error, 0 not sent, 1 sent with success
3201
3202 $resql = $this->db->query($sql);
3203 if ($resql) {
3204 $obj = $this->db->fetch_object($resql);
3205 $nb = (int) $obj->nb;
3206
3207 $this->db->free($resql);
3208 return $nb;
3209 } else {
3210 $this->error = $this->db->error();
3211 return -1;
3212 }
3213 }
3214
3225 public function setCategories($categories)
3226 {
3227 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
3228 return parent::setCategoriesCommon($categories, Categorie::TYPE_MEMBER);
3229 }
3230
3239 public static function replaceThirdparty($db, $origin_id, $dest_id)
3240 {
3241 $tables = array('adherent');
3242
3243 return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
3244 }
3245
3251 public function hasDelay()
3252 {
3253 global $conf;
3254
3255 //Only valid members
3256 if ($this->status != self::STATUS_VALIDATED) {
3257 return false;
3258 }
3259 if (!$this->datefin) {
3260 return false;
3261 }
3262
3263 $now = dol_now();
3264
3265 return $this->datefin < ($now - getWarningDelay('member', 'subscription'));
3266 }
3267
3268
3277 public function sendReminderForExpiredSubscription($daysbeforeendlist = '10', $fk_adherent_type = 0)
3278 {
3279 global $conf, $langs, $mysoc, $user;
3280
3281 $error = 0;
3282 $this->output = '';
3283 $this->error = '';
3284
3285 $blockingerrormsg = '';
3286
3287 if (!isModEnabled('member')) { // Should not happen. If module disabled, cron job should not be visible.
3288 $langs->load("agenda");
3289 $this->output = $langs->trans('ModuleNotEnabled', $langs->transnoentitiesnoconv("Adherent"));
3290 return 0;
3291 }
3292 if (!getDolGlobalString('MEMBER_REMINDER_EMAIL')) {
3293 $langs->load("agenda");
3294 $this->output = $langs->trans('EventRemindersByEmailNotEnabled', $langs->transnoentitiesnoconv("Adherent"));
3295 return 0;
3296 }
3297
3298 $now = dol_now();
3299 $nbok = 0;
3300 $nbko = 0;
3301
3302 $listofmembersok = array();
3303 $listofmembersko = array();
3304
3305 $arraydaysbeforeend = explode(';', $daysbeforeendlist);
3306 foreach ($arraydaysbeforeend as $daysbeforeend) { // Loop on each delay
3307 dol_syslog(__METHOD__.' - Process delta = '.$daysbeforeend, LOG_DEBUG);
3308
3309 if (!is_numeric($daysbeforeend)) {
3310 $blockingerrormsg = "Value for delta is not a numeric value";
3311 $nbko++;
3312 break;
3313 }
3314
3315 $tmp = dol_getdate($now);
3316 $datetosearchfor = dol_time_plus_duree(dol_mktime(0, 0, 0, $tmp['mon'], $tmp['mday'], $tmp['year'], 'tzserver'), (int) $daysbeforeend, 'd');
3317 $datetosearchforend = dol_time_plus_duree(dol_mktime(23, 59, 59, $tmp['mon'], $tmp['mday'], $tmp['year'], 'tzserver'), (int) $daysbeforeend, 'd');
3318
3319 $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'adherent';
3320 $sql .= " WHERE entity = ".((int) $conf->entity); // Do not use getEntity('adherent').")" here, we want the batch to be on its entity only;
3321 $sql .= " AND statut = 1";
3322 $sql .= " AND datefin >= '".$this->db->idate($datetosearchfor)."'";
3323 $sql .= " AND datefin <= '".$this->db->idate($datetosearchforend)."'";
3324 if ((int) $fk_adherent_type > 0) {
3325 $sql .= " AND fk_adherent_type = ".((int) $fk_adherent_type);
3326 }
3327 //$sql .= " LIMIT 10000";
3328
3329 $resql = $this->db->query($sql);
3330 if ($resql) {
3331 $num_rows = $this->db->num_rows($resql);
3332
3333 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
3334 $formmail = new FormMail($this->db);
3335
3336 $i = 0;
3337 while ($i < $num_rows) {
3338 $obj = $this->db->fetch_object($resql);
3339
3340 // A new object for each member: fetch() does not reset the properties loaded for the previous member,
3341 // like ->thirdparty that would be reused for a member that has no third party.
3342 $adherent = new Adherent($this->db);
3343 $adherent->fetch($obj->rowid, '', 0, '', true, true);
3344
3345 if (empty($adherent->email)) {
3346 $nbko++;
3347 $listofmembersko[$adherent->id] = $adherent->id;
3348 } else {
3349 $thirdpartyres = $adherent->fetch_thirdparty();
3350 if ($thirdpartyres === -1) {
3351 $languagecodeformember = $mysoc->default_lang;
3352 } else {
3353 // 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.
3354 $languagefromcountrycode = getLanguageCodeFromCountryCode($adherent->country_code ? $adherent->country_code : (is_object($adherent->thirdparty) ? $adherent->thirdparty->country_code : ''));
3355 $languagecodeformember = (empty($adherent->thirdparty->default_lang) ? ($languagefromcountrycode ? $languagefromcountrycode : $mysoc->default_lang) : $adherent->thirdparty->default_lang);
3356 }
3357 if (!empty($adherent->default_lang)) {
3358 // The language set on the member itself has priority
3359 $languagecodeformember = $adherent->default_lang;
3360 }
3361
3362 // Send reminder email
3363 $outputlangs = new Translate('', $conf);
3364 $outputlangs->setDefaultLang($languagecodeformember);
3365 $outputlangs->loadLangs(array("main", "members"));
3366 dol_syslog("sendReminderForExpiredSubscription Language for member id ".$adherent->id." set to ".$outputlangs->defaultlang." mysoc->default_lang=".$mysoc->default_lang);
3367
3368 $arraydefaultmessage = null;
3369 $labeltouse = getDolGlobalString('ADHERENT_EMAIL_TEMPLATE_REMIND_EXPIRATION');
3370
3371 if (!empty($labeltouse)) {
3372 $arraydefaultmessage = $formmail->getEMailTemplate($this->db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
3373 }
3374
3375 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
3376 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $adherent);
3377 //if (is_array($adherent->thirdparty)) $substitutionarraycomp = ...
3378 complete_substitutions_array($substitutionarray, $outputlangs, $adherent);
3379
3380 $subject = make_substitutions($arraydefaultmessage->topic, $substitutionarray, $outputlangs);
3381 $msg = make_substitutions($arraydefaultmessage->content, $substitutionarray, $outputlangs);
3382 $email_from = getDolGlobalString('ADHERENT_MAIL_FROM', $conf->email_from);
3383 $to = $adherent->email;
3384 $cc = getDolGlobalString('ADHERENT_CC_MAIL_FROM');
3385
3386 $trackid = 'mem'.$adherent->id;
3387 $moreinheader = 'X-Dolibarr-Info: sendReminderForExpiredSubscription'."\r\n";
3388
3389 include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
3390 $cmail = new CMailFile($subject, $to, $email_from, $msg, array(), array(), array(), $cc, '', 0, 1, '', '', $trackid, $moreinheader);
3391 $result = $cmail->sendfile();
3392 if (!$result) {
3393 $error++;
3394 $this->error .= $cmail->error.' ';
3395 if (!is_null($cmail->errors)) {
3396 $this->errors += $cmail->errors;
3397 }
3398 $nbko++;
3399 $listofmembersko[$adherent->id] = $adherent->id;
3400 } else {
3401 $nbok++;
3402 $listofmembersok[$adherent->id] = $adherent->id;
3403
3404 $message = $msg;
3405 $sendto = $to;
3406 $sendtocc = '';
3407 $sendtobcc = '';
3408 $actioncode = 'EMAIL';
3409 $extraparams = array();
3410
3411 $actionmsg = '';
3412 $actionmsg2 = $langs->transnoentities('MailSentByTo', CMailFile::getValidAddress($email_from, 4, 0, 1), CMailFile::getValidAddress($sendto, 4, 0, 1));
3413 if ($message) {
3414 $actionmsg = $langs->transnoentities('MailFrom').': '.dol_escape_htmltag($email_from);
3415 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTo').': '.dol_escape_htmltag($sendto));
3416 // if ($sendtocc) {
3417 // $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc').": ".dol_escape_htmltag($sendtocc));
3418 // }
3419 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic').": ".$subject);
3420 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody').":");
3421 $actionmsg = dol_concatdesc($actionmsg, $message);
3422 }
3423
3424 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
3425
3426 // Insert record of emails sent
3427 $actioncomm = new ActionComm($this->db);
3428
3429 $actioncomm->type_code = 'AC_OTH_AUTO'; // Type of event ('AC_OTH', 'AC_OTH_AUTO', 'AC_XXX'...)
3430 $actioncomm->code = 'AC_'.$actioncode;
3431 $actioncomm->label = $actionmsg2;
3432 $actioncomm->note_private = $actionmsg;
3433 $actioncomm->fk_project = 0;
3434 $actioncomm->datep = $now;
3435 $actioncomm->datef = $now;
3436 $actioncomm->percentage = -1; // Not applicable
3437 $actioncomm->socid = (is_object($adherent->thirdparty) ? $adherent->thirdparty->id : 0);
3438 $actioncomm->contact_id = 0;
3439 $actioncomm->authorid = $user->id; // User saving action
3440 $actioncomm->userownerid = $user->id; // Owner of action
3441 // Fields when action is an email (content should be added into note)
3442 $actioncomm->email_msgid = $cmail->msgid;
3443 $actioncomm->email_from = $email_from;
3444 $actioncomm->email_sender = '';
3445 $actioncomm->email_to = $to;
3446 $actioncomm->email_tocc = $sendtocc;
3447 $actioncomm->email_tobcc = $sendtobcc;
3448 $actioncomm->email_subject = $subject;
3449 $actioncomm->errors_to = '';
3450
3451 $actioncomm->fk_element = $adherent->id;
3452 $actioncomm->elementid = $adherent->id;
3453 $actioncomm->elementtype = $adherent->element;
3454
3455 $actioncomm->extraparams = $extraparams;
3456
3457 $actioncomm->create($user);
3458 }
3459 } else {
3460 //$blockingerrormsg = "Can't find email template with label=".$labeltouse.", to use for the reminding email";
3461
3462 $error++;
3463 $this->error .= "Can't find email template with label=".$labeltouse.", to use for the reminding email ";
3464
3465 $nbko++;
3466 $listofmembersko[$adherent->id] = $adherent->id;
3467
3468 break;
3469 }
3470 }
3471
3472 $i++;
3473 }
3474 } else {
3475 $this->error = $this->db->lasterror();
3476 return 1;
3477 }
3478 }
3479
3480 if ($blockingerrormsg) {
3481 $this->error = $blockingerrormsg;
3482 return 1;
3483 } else {
3484 $this->output = 'Found '.($nbok + $nbko).' members to send reminder to.';
3485 $this->output .= ' Send email successfully to '.$nbok.' members';
3486 $listofids = '';
3487 $i = 0;
3488 foreach ($listofmembersok as $idmember) {
3489 if ($i > 100) {
3490 $listofids .= ', ...';
3491 break;
3492 }
3493 if (empty($listofids)) {
3494 $listofids .= ' [';
3495 } else {
3496 $listofids .= ', ';
3497 }
3498 $listofids .= $idmember;
3499 $i++;
3500 }
3501 if ($listofids) {
3502 $listofids .= ']';
3503 }
3504 $this->output .= ($listofids ? ' ids='.$listofids : '');
3505
3506 if ($nbko) {
3507 $this->output .= ' - Canceled for '.$nbko.' member (no email or email sending error)';
3508 $listofids = '';
3509 $i = 0;
3510 foreach ($listofmembersko as $idmember) {
3511 if ($i > 100) {
3512 $listofids .= ', ...';
3513 break;
3514 }
3515 if (empty($listofids)) {
3516 $listofids .= ' [';
3517 } else {
3518 $listofids .= ', ';
3519 }
3520 $listofids .= $idmember;
3521 $i++;
3522 }
3523 if ($listofids) {
3524 $listofids .= ']';
3525 }
3526 $this->output .= ($listofids ? ' ids='.$listofids : '');
3527 }
3528 }
3529
3530 return $nbko;
3531 }
3532
3540 public function getKanbanView($option = '', $arraydata = null)
3541 {
3542 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
3543
3544 $return = '<div class="box-flex-item box-flex-grow-zero">';
3545 $return .= '<div class="info-box info-box-sm">';
3546 $return .= '<span class="info-box-icon bg-infobox-action">';
3547 if (!empty($this->photo)) {
3548 $return .= Form::showphoto('memberphoto', $this, 0, 60, 0, 'photokanban photowithmargin photologintooltip', 'small', 0, 1);
3549 } else {
3550 $return .= img_picto('', 'user');
3551 }
3552 $return .= '</span>';
3553 $return .= '<div class="info-box-content">';
3554 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . $this->getNomUrl() . '</span>';
3555 if ($selected >= 0) {
3556 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
3557 }
3558 $return .= '<br><span class="info-box-label paddingright">'.$this->getmorphylib('', 2).'</span>';
3559 $return .= '<span class="info-box-label opacitymedium">'.$this->type.'</span>';
3560
3561 $return .= '<br><div class="info-box-status paddingtop">';
3562 $return .= $this->LibStatut($this->status, $this->need_subscription, $this->datefin, 5);
3563 $return .= '</div>';
3564 $return .= '</div>';
3565 $return .= '</div>';
3566 $return .= '</div>';
3567 return $return;
3568 }
3569}
$object ref
Definition info.php:90
Class to manage bank accounts.
Class to manage agenda events (actions)
Class to manage members of a foundation.
mergeMembers($member_origin_id)
Merge a member with current one, deleting the given company $member_origin_id.
setThirdPartyId($thirdpartyid)
Set link to a third party.
hasDelay()
Return if a member is late (subscription late) or not.
exclude($user)
Functiun to exclude (set adherent.status to -2) a member TODO A private note should be added to know ...
add_to_abo()
Function to add member into external tools mailing-list, spip, etc.
loadStateBoard()
Load indicators this->nb in state board.
_load_ldap_dn($info, $mode=0)
Returns the complete DN (Distinguished Name) string in the LDAP directory for the object.
update($user, $notrigger=0, $nosyncuser=0, $nosyncuserpass=0, $nosyncthirdparty=0, $action='update')
Update a member in database (standard information and password)
setCategories($categories)
Sets object to supplied categories.
getTooltipContentArray($params)
getTooltipContentArray
getNbOfEMailings()
Return number of mass Emailing received by this member with its email.
update_end_date($user)
Update denormalized last subscription date.
static replaceThirdparty($db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
makeSubstitution($text)
Make substitution of tags into text with value of current object.
const STATUS_EXCLUDED
Excluded.
LibStatut($status, $need_subscription, $date_end_subscription, $mode=0)
Renvoi le libelle d'un statut donne.
fetch_name($firstname, $lastname)
Method to load member from its name.
initAsSpecimen()
Initialise an instance with random values.
del_to_abo()
Function to delete a member from external tools like mailing-list, spip, etc.
resiliate($user)
Function that terminates a member.
getCivilityLabel()
Return civility label of a member.
getmorphylib($morphy='', $addbadge=0)
Return translated label by the nature of a adherent (physical or moral)
sendEmail($text, $subject, $filename_list=array(), $mimetype_list=array(), $mimefilename_list=array(), $addr_cc="", $addr_bcc="", $deliveryreceipt=0, $msgishtml=-1, $errors_to='', $moreinheader='')
Function sending an email to the current member with the text supplied in parameter.
fetchPartnerships($mode)
Function to get partnerships array.
load_board($user, $mode)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
setPassword($user, $password='', $isencrypted=0, $notrigger=0, $nosyncuser=0)
Change password of a user.
$fields
'type' field format: 'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortf...
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
const STATUS_DRAFT
Draft status.
const STATUS_RESILIATED
Resiliated (membership end and was not renew)
sendReminderForExpiredSubscription($daysbeforeendlist='10', $fk_adherent_type=0)
Send reminders by emails before subscription end CAN BE A CRON TASK.
fetch_login($login)
Method to load member from its login.
_load_ldap_info()
Initialise tableau info (tableau des attributes LDAP)
getLibStatut($mode=0)
Retourne le libelle du statut d'un adherent (brouillon, valide, resilie, exclu)
info($id)
Load type info information in the member object.
subscription($date, $amount, $accountid=0, $operation='', $label='', $num_chq='', $emetteur_nom='', $emetteur_banque='', $datesubend=0, $fk_type=null, $ref_ext='')
Insert subscription into database and eventually add links to banks, mailman, etc....
__construct($db)
Constructor.
validate($user, $notrigger=0)
Function that validate a member.
send_an_email($text, $subject, $filename_list=array(), $mimetype_list=array(), $mimefilename_list=array(), $addr_cc="", $addr_bcc="", $deliveryreceipt=0, $msgishtml=-1, $errors_to='', $moreinheader='')
Function sending an email to the current member with the text supplied in parameter.
getNomUrl($withpictoimg=0, $maxlen=0, $option='card', $mode='', $morecss='', $save_lastsearch_value=-1, $notooltip=0, $addlinktonotes=0)
Return clickable name (with picto eventually)
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
subscriptionComplementaryActions($subscriptionid, $option, $accountid, $datesubscription, $paymentdate, $operation, $label, $amount, $num_chq, $emetteur_nom='', $emetteur_banque='', $autocreatethirdparty=0, $ext_payment_id='', $ext_payment_site='')
Do complementary actions after subscription recording.
setUserId($userid)
Set link to a user.
const STATUS_VALIDATED
Validated status.
fetch_subscriptions()
Function to get member subscriptions data: subscriptions, first_subscription_date,...
fetch($rowid, $ref='', $socid=0, $ref_ext='', $fetch_optionals=true, $fetch_subscriptions=true)
Load member from database.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
static getValidAddress($address, $format, $encode=0, $maxnumberofemail=0)
Return a formatted address string for SMTP protocol.
Class to manage categories.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
setErrorsFromObject($object)
setErrorsFromObject
deleteExtraFields()
Delete all extra fields values for the current object.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
Class to manage invoices.
const TYPE_STANDARD
Standard invoice.
Class to manage generation of HTML components Only common components must be here.
static showphoto($modulepart, $object, $width=100, $height=0, $caneditfield=0, $cssclass='photowithmargin', $imagesize='', $addlinktofullsize=1, $cache=0, $forcecapture='', $noexternsourceoverwrite=0, $usesharelinkifavailable=0)
Return HTML code to output a photo.
Class to manage a HTML form to send a unitary email Usage: $formail = new FormMail($db) $formmail->pr...
Class to manage mailman and spip.
Class to manage payments of customer invoices.
Class to manage payment terms records in dictionary.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage subscriptions of foundation members.
Class to manage translations.
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:169
getFullName($langs, $option=0, $nameorder=-1, $maxlen=0)
Return full name (civility+' '+name+' '+lastname)
setUpperOrLowerCase()
Set to upper or ucwords/lower if needed.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
global $mysoc
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0, $tz='')
Add a delay to a date.
Definition date.lib.php:129
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as p label as s rowid as s nom as s email
Sender: Who sends the email ("Sender" has sent emails on behalf of "From").
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_move($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=1, $moreinfo=array(), $entity=null)
Move a file into another name.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:64
dol_is_dir($folder)
Test if filename is a directory.
clean_url($url, $http=1)
Clean an url string.
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
getLanguageCodeFromCountryCode($countrycode)
Return default language from country code.
setEntity($currentobject)
Set entity id to use when to create an object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dol_format_address($object, $withcountry=0, $sep="\n", $outputlangs=null, $mode=0, $extralangcode='')
Return a formatted address (part address/zip/town/state) according to country rules.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
GETPOSTISARRAY($paramname, $method=0)
Return true if the parameter $paramname is submit from a POST OR GET as an array.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
dolGetFirstLetters($s, $nbofchar=1)
Return first letters of a strings.
dol_strtoupper($string, $encoding="UTF-8")
Convert a string to upper.
yn($yesno, $format=1, $color=0)
Return yes or no in current language.
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
getArrayOfSocialNetworks()
Get array of social network dictionary.
dol_textishtml($msg, $option=0)
Return if a text is a html content.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
getWarningDelay($module, $parmlevel1, $parmlevel2='')
Return a warning delay You can use it like this: if (getWarningDelay('module', 'paramlevel1')) It rep...
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
div refaddress div address
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition repair.php:137
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.
dolGetLdapPasswordHash($password, $type='md5')
Returns a specific ldap hash of a password.
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.