dolibarr 25.0.0-alpha
adherent.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org>
4 * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
6 * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
7 * Copyright (C) 2009-2017 Regis Houssin <regis.houssin@inodbox.com>
8 * Copyright (C) 2014-2018 Alexandre Spangaro <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((string) $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 (is_object($langs) && $langs->trans("Country".$obj->country_code) != "Country".$obj->country_code) { // $langs may be null with NOREQUIRETRAN
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
2142 $amounts = array();
2143 $amounts[$invoice->id] = (float) price2num($amount);
2144
2145 $paiement = new Paiement($this->db);
2146 $paiement->datepaye = $paymentdate;
2147 $paiement->amounts = $amounts;
2148 $paiement->paiementcode = $operation;
2149 $paiement->paiementid = dol_getIdFromCode($this->db, $operation, 'c_paiement', 'code', 'id', 1);
2150 $paiement->num_payment = $num_chq;
2151 $paiement->note_public = $label;
2152 $paiement->ext_payment_id = $ext_payment_id;
2153 $paiement->ext_payment_site = $ext_payment_site;
2154
2155 // Create payment line for invoice
2156 $paiement_id = $paiement->create($user);
2157 if (!($paiement_id > 0)) {
2158 $this->setErrorsFromObject($paiement);
2159 $error++;
2160 }
2161
2162 if (!$error) {
2163 // Add transaction into bank account
2164 $bank_line_id = $paiement->addPaymentToBank($user, 'payment', '(SubscriptionPayment)', $accountid, $emetteur_nom, $emetteur_banque);
2165 if (!($bank_line_id > 0)) {
2166 $this->setErrorsFromObject($paiement);
2167 $error++;
2168 }
2169 }
2170
2171 if (!$error && !empty($bank_line_id)) {
2172 // Update fk_bank into subscription table
2173 $sql = 'UPDATE '.MAIN_DB_PREFIX.'subscription SET fk_bank='.((int) $bank_line_id);
2174 $sql .= ' WHERE rowid='.((int) $subscriptionid);
2175
2176 $result = $this->db->query($sql);
2177 if (!$result) {
2178 $error++;
2179 }
2180 }
2181
2182 if (!$error) {
2183 // Set invoice as paid
2184 $invoice->setPaid($user);
2185 }
2186 }
2187
2188 if (!$error) {
2189 // Define output language
2190 $outputlangs = $langs;
2191 $newlang = $this->default_lang;
2192 $lang_id = GETPOST('lang_id');
2193 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && !empty($lang_id)) {
2194 $newlang = $lang_id;
2195 }
2196 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
2197 $newlang = $customer->default_lang;
2198 }
2199 if (!empty($newlang)) {
2200 $outputlangs = new Translate("", $conf);
2201 $outputlangs->setDefaultLang($newlang);
2202 }
2203 // Generate PDF (whatever is option MAIN_DISABLE_PDF_AUTOUPDATE) so we can include it into email
2204 //if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE'))
2205
2206 $invoice->fetch($invoice->id); // Reload invoice object data
2207 $invoice->generateDocument($invoice->model_pdf, $outputlangs);
2208 }
2209 }
2210
2211 if ($error) {
2212 return -1;
2213 } else {
2214 return 1;
2215 }
2216 }
2217
2218
2226 public function validate($user, $notrigger = 0)
2227 {
2228 global $langs, $conf;
2229
2230 $error = 0;
2231 $now = dol_now();
2232
2233 // Check parameters
2234 if ($this->status == self::STATUS_VALIDATED) {
2235 dol_syslog(get_class($this)."::validate statut of member does not allow this", LOG_WARNING);
2236 return 0;
2237 }
2238
2239 $this->db->begin();
2240
2241 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
2242 $sql .= " statut = ".self::STATUS_VALIDATED;
2243 $sql .= ", datevalid = '".$this->db->idate($now)."'";
2244 $sql .= ", fk_user_valid = ".((int) $user->id);
2245 $sql .= " WHERE rowid = ".((int) $this->id);
2246
2247 dol_syslog(get_class($this)."::validate", LOG_DEBUG);
2248 $result = $this->db->query($sql);
2249 if ($result) {
2250 $this->statut = self::STATUS_VALIDATED;
2252
2253 // Call trigger
2254 if (!$notrigger) {
2255 $result = $this->call_trigger('MEMBER_VALIDATE', $user);
2256 if ($result < 0) {
2257 $error++;
2258 $this->db->rollback();
2259 return -1;
2260 }
2261 }
2262 // End call triggers
2263
2264 $this->datevalid = $now;
2265
2266 $this->db->commit();
2267 return 1;
2268 } else {
2269 $this->error = $this->db->error();
2270 $this->db->rollback();
2271 return -1;
2272 }
2273 }
2274
2275
2282 public function resiliate($user)
2283 {
2284 global $langs, $conf;
2285
2286 $error = 0;
2287
2288 // Check parameters
2289 if ($this->status == self::STATUS_RESILIATED) {
2290 dol_syslog(get_class($this)."::resiliate statut of member does not allow this", LOG_WARNING);
2291 return 0;
2292 }
2293
2294 $this->db->begin();
2295
2296 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
2297 $sql .= " statut = ".((int) self::STATUS_RESILIATED);
2298 $sql .= ", fk_user_valid = ".((int) $user->id);
2299 $sql .= " WHERE rowid = ".((int) $this->id);
2300
2301 $result = $this->db->query($sql);
2302 if ($result) {
2303 $this->statut = self::STATUS_RESILIATED;
2305
2306 // Call trigger
2307 $result = $this->call_trigger('MEMBER_RESILIATE', $user);
2308 if ($result < 0) {
2309 $error++;
2310 $this->db->rollback();
2311 return -1;
2312 }
2313 // End call triggers
2314
2315 $this->db->commit();
2316 return 1;
2317 } else {
2318 $this->error = $this->db->error();
2319 $this->db->rollback();
2320 return -1;
2321 }
2322 }
2323
2333 public function exclude($user)
2334 {
2335 $error = 0;
2336
2337 // Check parameters
2338 if ($this->status == self::STATUS_EXCLUDED) {
2339 dol_syslog(get_class($this)."::resiliate statut of member does not allow this", LOG_WARNING);
2340 return 0;
2341 }
2342
2343 $this->db->begin();
2344
2345 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
2346 $sql .= " statut = ".((int) self::STATUS_EXCLUDED);
2347 $sql .= ", fk_user_valid = ".((int) $user->id);
2348 $sql .= " WHERE rowid = ".((int) $this->id);
2349
2350 $result = $this->db->query($sql);
2351 if ($result) {
2352 $this->statut = self::STATUS_EXCLUDED;
2354
2355 // Call trigger
2356 $result = $this->call_trigger('MEMBER_EXCLUDE', $user);
2357 if ($result < 0) {
2358 $error++;
2359 $this->db->rollback();
2360 return -1;
2361 }
2362 // End call triggers
2363
2364 $this->db->commit();
2365 return 1;
2366 } else {
2367 $this->error = $this->db->error();
2368 $this->db->rollback();
2369 return -1;
2370 }
2371 }
2372
2373 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2379 public function add_to_abo()
2380 {
2381 // phpcs:enable
2382 global $langs;
2383
2384 include_once DOL_DOCUMENT_ROOT.'/mailmanspip/class/mailmanspip.class.php';
2385 $mailmanspip = new MailmanSpip($this->db);
2386
2387 $err = 0;
2388
2389 // mailman
2390 if (getDolGlobalString('ADHERENT_USE_MAILMAN') && isModEnabled('mailmanspip')) {
2391 $result = $mailmanspip->add_to_mailman($this);
2392
2393 if ($result < 0) {
2394 if (!empty($mailmanspip->error)) {
2395 $this->errors[] = $mailmanspip->error;
2396 }
2397 $err += 1;
2398 }
2399 foreach ($mailmanspip->mladded_ko as $tmplist => $tmpemail) {
2400 $langs->load("errors");
2401 $this->errors[] = $langs->trans("ErrorFailedToAddToMailmanList", $tmpemail, $tmplist);
2402 }
2403 foreach ($mailmanspip->mladded_ok as $tmplist => $tmpemail) {
2404 $langs->load("mailmanspip");
2405 $this->mesgs[] = $langs->trans("SuccessToAddToMailmanList", $tmpemail, $tmplist);
2406 }
2407 }
2408
2409 // spip
2410 if (getDolGlobalString('ADHERENT_USE_SPIP') && isModEnabled('mailmanspip')) {
2411 $result = $mailmanspip->add_to_spip($this);
2412 if ($result < 0) {
2413 $this->errors[] = $mailmanspip->error;
2414 $err += 1;
2415 }
2416 }
2417 if ($err) {
2418 return -$err;
2419 } else {
2420 return 1;
2421 }
2422 }
2423
2424
2425 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2431 public function del_to_abo()
2432 {
2433 // phpcs:enable
2434 global $conf, $langs;
2435
2436 include_once DOL_DOCUMENT_ROOT.'/mailmanspip/class/mailmanspip.class.php';
2437 $mailmanspip = new MailmanSpip($this->db);
2438
2439 $err = 0;
2440
2441 // mailman
2442 if (getDolGlobalString('ADHERENT_USE_MAILMAN')) {
2443 $result = $mailmanspip->del_to_mailman($this);
2444 if ($result < 0) {
2445 if (!empty($mailmanspip->error)) {
2446 $this->errors[] = $mailmanspip->error;
2447 }
2448 $err += 1;
2449 }
2450
2451 foreach ($mailmanspip->mlremoved_ko as $tmplist => $tmpemail) {
2452 $langs->load("errors");
2453 $this->errors[] = $langs->trans("ErrorFailedToRemoveToMailmanList", $tmpemail, $tmplist);
2454 }
2455 foreach ($mailmanspip->mlremoved_ok as $tmplist => $tmpemail) {
2456 $langs->load("mailmanspip");
2457 $this->mesgs[] = $langs->trans("SuccessToRemoveToMailmanList", $tmpemail, $tmplist);
2458 }
2459 }
2460
2461 if (getDolGlobalString('ADHERENT_USE_SPIP') && isModEnabled('mailmanspip')) {
2462 $result = $mailmanspip->del_to_spip($this);
2463 if ($result < 0) {
2464 $this->errors[] = $mailmanspip->error;
2465 $err += 1;
2466 }
2467 }
2468 if ($err) {
2469 // error
2470 return -$err;
2471 } else {
2472 return 1;
2473 }
2474 }
2475
2476
2482 public function getCivilityLabel()
2483 {
2484 global $langs;
2485 $langs->load("dict");
2486
2487 $code = (empty($this->civility_id) ? '' : $this->civility_id);
2488 if (empty($code)) {
2489 return '';
2490 }
2491 return $langs->getLabelFromKey($this->db, "Civility".$code, "c_civility", "code", "label", $code);
2492 }
2493
2500 public function getTooltipContentArray($params)
2501 {
2502 global $langs;
2503
2504 $langs->loadLangs(['members', 'companies']);
2505 $nofetch = !empty($params['nofetch']);
2506
2507 $datas = array();
2508
2509 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
2510 $langs->load("users");
2511 return ['optimize' => $langs->trans("ShowUser")];
2512 }
2513 if (!empty($this->photo)) {
2514 $photo = '<div class="photointooltip floatright">';
2515 $photo .= Form::showphoto('memberphoto', $this, 80, 0, 0, 'photoref photowithmargin photologintooltip', 'small', 0, 1);
2516 $photo .= '</div>';
2517 $datas['photo'] = $photo;
2518 }
2519
2520 $datas['divopen'] = '<div class="centpercent">';
2521 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Member").'</u> '.$this->getLibStatut(4);
2522 if (!empty($this->morphy)) {
2523 $datas['picto'] .= '&nbsp;' . $this->getmorphylib('', 1);
2524 }
2525 if (!empty($this->ref)) {
2526 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
2527 }
2528 if (!empty($this->login)) {
2529 $datas['login'] = '<br><b>'.$langs->trans('Login').':</b> '.$this->login;
2530 }
2531 if (!empty($this->firstname) || !empty($this->lastname)) {
2532 $datas['name'] = '<br><b>'.$langs->trans('Name').':</b> '.$this->getFullName($langs);
2533 }
2534 if (!empty($this->company)) {
2535 $datas['company'] = '<br><b>'.$langs->trans('Company').':</b> '.$this->company;
2536 }
2537 if (!empty($this->email)) {
2538 $datas['email'] = '<br><b>'.$langs->trans("EMail").':</b> '.$this->email;
2539 }
2540 $datas['address'] = '<br><b>'.$langs->trans("Address").':</b> '.dol_format_address($this, 1, ' ', $langs);
2541 // show categories for this record only in ajax to not overload lists
2542 if (isModEnabled('category') && !$nofetch) {
2543 require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
2544 $form = new Form($this->db);
2545 $datas['categories'] = '<br>' . $form->showCategories($this->id, Categorie::TYPE_MEMBER, 1);
2546 }
2547 $datas['divclose'] = '</div>';
2548
2549 return $datas;
2550 }
2551
2565 public function getNomUrl($withpictoimg = 0, $maxlen = 0, $option = 'card', $mode = '', $morecss = '', $save_lastsearch_value = -1, $notooltip = 0, $addlinktonotes = 0)
2566 {
2567 global $langs, $hookmanager;
2568
2569 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') && $withpictoimg) {
2570 $withpictoimg = 0;
2571 }
2572
2573 $result = '';
2574 $linkstart = '';
2575 $linkend = '';
2576 $classfortooltip = 'classfortooltip';
2577 $dataparams = '';
2578 $params = [
2579 'id' => $this->id,
2580 'objecttype' => $this->element,
2581 'option' => $option,
2582 'nofetch' => 1,
2583 ];
2584 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
2585 $classfortooltip = 'classforajaxtooltip';
2586 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
2587 $label = '';
2588 } else {
2589 $label = implode($this->getTooltipContentArray($params));
2590 }
2591
2592 $baseurl = DOL_URL_ROOT . '/adherents/card.php';
2593 if ($option == 'subscription') {
2594 $baseurl = DOL_URL_ROOT . '/adherents/subscription.php';
2595 }
2596 $query = ['rowid' => $this->id];
2597
2598 if ($option != 'nolink') {
2599 // Add param to save lastsearch_values or not
2600 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2601 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
2602 $add_save_lastsearch_values = 1;
2603 }
2604 if ($add_save_lastsearch_values) {
2605 $query = array_merge($query, ['save_lastsearch_values' => 1]);
2606 }
2607 }
2608 $url = dolBuildUrl($baseurl, $query);
2609
2610 $linkstart .= '<a href="'.$url.'"';
2611 $linkclose = "";
2612 if (empty($notooltip)) {
2613 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
2614 $langs->load("users");
2615 $label = $langs->trans("ShowUser");
2616 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
2617 }
2618 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
2619 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
2620 }
2621
2622 $linkstart .= $linkclose.'>';
2623 $linkend = '</a>';
2624
2625 $result .= $linkstart;
2626
2627 if ($withpictoimg) {
2628 if (abs($withpictoimg) == 1 || abs($withpictoimg) == 4) {
2629 $morecss .= ' paddingrightonly';
2630 }
2631 // Only picto
2632 if ($withpictoimg > 0) {
2633 $picto = '<span class="nopadding'.($morecss ? ' userimg'.$morecss : '').'">'.img_object('', 'user', ($withpictoimg != 2 ? 'class="pictofixedwidth"' : '').' '.($notooltip ? '' : $dataparams), 0, 0, $notooltip ? 0 : 1).'</span>';
2634 } else {
2635 // Picto must be a photo
2636 $picto = '<span class="nopadding'.($morecss ? ' userimg'.$morecss : '').'">';
2637 $picto .= Form::showphoto('memberphoto', $this, 0, 0, 0, 'userphoto'.(($withpictoimg == -3 || $withpictoimg == -4) ? 'small' : ''), 'mini', 0, 1);
2638 $picto .= '</span>';
2639 }
2640 $result .= $picto;
2641 }
2642 if (($withpictoimg > -2 && $withpictoimg != 2) || $withpictoimg == -4) {
2643 if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
2644 $result .= '<span class="nopadding valignmiddle'.((!isset($this->status) || $this->status) ? '' : ' strikefordisabled').
2645 ($morecss ? ' usertext'.$morecss : '').'">';
2646 }
2647 if ($mode == 'login') {
2648 $result .= dol_trunc(isset($this->login) ? $this->login : '', $maxlen);
2649 } elseif ($mode == 'ref') {
2650 $result .= $this->ref;
2651 } else {
2652 if (empty($this->lastname) && empty($this->firstname) && !empty($this->company)) {
2653 $result .= $this->company;
2654 } else {
2655 $result .= $this->getFullName($langs, 0, ($mode == 'firstname' ? 2 : ($mode == 'lastname' ? 4 : -1)), $maxlen);
2656 }
2657 }
2658 if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
2659 $result .= '</span>';
2660 }
2661 }
2662
2663 $result .= $linkend;
2664
2665 if ($addlinktonotes) {
2666 if ($this->note_private) {
2667 $notetoshow = $langs->trans("ViewPrivateNote").':<br>'.dol_string_nohtmltag($this->note_private, 1);
2668 $result .= ' <span class="note inline-block">';
2669 $result .= '<a href="'.DOL_URL_ROOT.'/adherents/note.php?id='.$this->id.'" class="classfortooltip" title="'.dol_escape_htmltag($notetoshow).'">';
2670 $result .= img_picto('', 'note');
2671 $result .= '</a>';
2672 $result .= '</span>';
2673 }
2674 }
2675 global $action;
2676 $hookmanager->initHooks(array($this->element . 'dao'));
2677 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
2678 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
2679 if ($reshook > 0) {
2680 $result = $hookmanager->resPrint;
2681 } else {
2682 $result .= $hookmanager->resPrint;
2683 }
2684 return $result;
2685 }
2686
2693 public function getLibStatut($mode = 0)
2694 {
2695 return $this->LibStatut($this->status, $this->need_subscription, $this->datefin, $mode);
2696 }
2697
2698 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2708 public function LibStatut($status, $need_subscription, $date_end_subscription, $mode = 0)
2709 {
2710 // phpcs:enable
2711 global $langs;
2712 $langs->load("members");
2713
2714 $statusType = '';
2715 $labelStatus = '';
2716 $labelStatusShort = '';
2717
2718 if ($status == self::STATUS_DRAFT) {
2719 $statusType = 'status0';
2720 $labelStatus = $langs->trans("MemberStatusDraft");
2721 $labelStatusShort = $langs->trans("MemberStatusDraftShort");
2722 } elseif ($status >= self::STATUS_VALIDATED) {
2723 if (empty($need_subscription)) {
2724 $statusType = 'status4';
2725 $labelStatus = $langs->trans("Validated").' - '.$langs->trans("SubscriptionNotNeeded");
2726 $labelStatusShort = $langs->trans("MemberStatusNoSubscriptionShort");
2727 } elseif (!$date_end_subscription) {
2728 $statusType = 'status1';
2729 $labelStatus = $langs->trans("Validated").' - '.$langs->trans("WaitingSubscription");
2730 $labelStatusShort = $langs->trans("WaitingSubscriptionShort");
2731 } elseif ($date_end_subscription < dol_now()) { // expired
2732 $statusType = 'status2';
2733 $labelStatus = $langs->trans("Validated").' - '.$langs->trans("MemberStatusActiveLate");
2734 $labelStatusShort = $langs->trans("MemberStatusActiveLateShort");
2735 } else {
2736 $statusType = 'status4';
2737 $labelStatus = $langs->trans("Validated").' - '.$langs->trans("MemberStatusPaid");
2738 $labelStatusShort = $langs->trans("MemberStatusPaidShort");
2739 }
2740 } elseif ($status == self::STATUS_RESILIATED) {
2741 $statusType = 'status6';
2742 $labelStatus = $langs->transnoentitiesnoconv("MemberStatusResiliated");
2743 $labelStatusShort = $langs->transnoentitiesnoconv("MemberStatusResiliatedShort");
2744 } elseif ($status == self::STATUS_EXCLUDED) {
2745 $statusType = 'status10';
2746 $labelStatus = $langs->transnoentitiesnoconv("MemberStatusExcluded");
2747 $labelStatusShort = $langs->transnoentitiesnoconv("MemberStatusExcludedShort");
2748 }
2749
2750 return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode);
2751 }
2752
2753
2759 public function loadStateBoard()
2760 {
2761 global $conf;
2762
2763 $this->nb = array();
2764
2765 $sql = "SELECT count(a.rowid) as nb";
2766 $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a";
2767 $sql .= " WHERE a.statut > 0";
2768 $sql .= " AND a.entity IN (".getEntity('adherent').")";
2769
2770 $resql = $this->db->query($sql);
2771 if ($resql) {
2772 while ($obj = $this->db->fetch_object($resql)) {
2773 $this->nb["members"] = $obj->nb;
2774 }
2775 $this->db->free($resql);
2776 return 1;
2777 } else {
2778 dol_print_error($this->db);
2779 $this->error = $this->db->error();
2780 return -1;
2781 }
2782 }
2783
2784 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2792 public function load_board($user, $mode)
2793 {
2794 // phpcs:enable
2795 global $conf, $langs;
2796
2797 if ($user->socid) {
2798 return -1; // Protection to prevent calls by external users
2799 }
2800
2801 $now = dol_now();
2802
2803 // The count and the number of late members are computed by the database instead of reading every member. A validated
2804 // member is late when the end date of the subscription is set and before now minus the warning delay (the rule of
2805 // hasDelay()); a draft member ('shift' mode) is never late.
2806 $sql = "SELECT COUNT(a.rowid) as nb,";
2807 if ($mode == 'expired') {
2808 $sql .= " SUM(CASE WHEN a.datefin IS NOT NULL AND a.datefin < '".$this->db->idate($now - getWarningDelay('member', 'subscription'))."' THEN 1 ELSE 0 END) as nblate";
2809 } else {
2810 $sql .= " 0 as nblate";
2811 }
2812 $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a";
2813 $sql .= ", ".MAIN_DB_PREFIX."adherent_type as t";
2814 $sql .= " WHERE a.fk_adherent_type = t.rowid";
2815 if ($mode == 'expired') {
2816 $sql .= " AND a.statut = ".self::STATUS_VALIDATED;
2817 $sql .= " AND a.entity IN (".getEntity('adherent').")";
2818 $sql .= " AND ((a.datefin IS NULL or a.datefin < '".$this->db->idate($now)."') AND t.subscription = '1')";
2819 } elseif ($mode == 'shift') {
2820 $sql .= " AND a.statut = ".self::STATUS_DRAFT;
2821 $sql .= " AND a.entity IN (".getEntity('adherent').")";
2822 }
2823
2824 $resql = $this->db->query($sql);
2825 if ($resql) {
2826 $langs->load("members");
2827
2828 $warning_delay = 0;
2829 $url = '';
2830 $label = '';
2831 $labelShort = '';
2832
2833 if ($mode == 'expired') {
2834 $warning_delay = getWarningDelay('member', 'subscription') / 60 / 60 / 24;
2835 $label = $langs->trans("MembersWithSubscriptionToReceive");
2836 $labelShort = $langs->trans("MembersWithSubscriptionToReceiveShort");
2837 $url = dolBuildUrl(DOL_URL_ROOT.'/adherents/list.php', ['mainmenu' => 'members', 'statut' => self::STATUS_VALIDATED, 'filter' => 'outofdate']);
2838 } elseif ($mode == 'shift') {
2839 $warning_delay = getWarningDelay('member', 'subscription') / 60 / 60 / 24;
2840 $url = dolBuildUrl(DOL_URL_ROOT.'/adherents/list.php', ['mainmenu' => 'members', 'statut' => self::STATUS_DRAFT]);
2841 $label = $langs->trans("MembersListToValid");
2842 $labelShort = $langs->trans("ToValidate");
2843 }
2844
2845 $response = new WorkboardResponse();
2846 $response->warning_delay = $warning_delay;
2847 $response->label = $label;
2848 $response->labelShort = $labelShort;
2849 $response->url = $url;
2850 $response->img = img_object('', "user");
2851
2852 $obj = $this->db->fetch_object($resql);
2853 if ($obj) {
2854 $response->nbtodo = (int) $obj->nb;
2855 $response->nbtodolate = (int) $obj->nblate;
2856 }
2857
2858 return $response;
2859 } else {
2860 dol_print_error($this->db);
2861 $this->error = $this->db->error();
2862 return -1;
2863 }
2864 }
2865
2866
2878 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
2879 {
2880 global $conf, $langs;
2881
2882 $langs->load("orders");
2883
2884 if (!dol_strlen($modele)) {
2885 $modele = 'standard';
2886
2887 if ($this->model_pdf) {
2888 $modele = $this->model_pdf;
2889 } elseif (getDolGlobalString('ADHERENT_ADDON_PDF')) {
2890 $modele = getDolGlobalString('ADHERENT_ADDON_PDF');
2891 }
2892 }
2893
2894 $modelpath = "core/modules/member/doc/";
2895
2896 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
2897 }
2898
2899
2907 public function initAsSpecimen()
2908 {
2909 global $user, $langs;
2910 $now = dol_now();
2911
2912 // Initialise parameters
2913 $this->id = 0;
2914 $this->ref = 'ABC001';
2915 $this->entity = 1;
2916 $this->specimen = 1;
2917 $this->civility_id = 'MR';
2918 $this->lastname = 'DOLIBARR';
2919 $this->firstname = 'SPECIMEN';
2920 $this->gender = 'man';
2921 $this->login = 'dolibspec';
2922 $this->pass = 'dolibspec';
2923 $this->company = 'Societe ABC';
2924 $this->address = '61 jump street';
2925 $this->zip = '75000';
2926 $this->town = 'Paris';
2927 $this->country_id = 1;
2928 $this->country_code = 'FR';
2929 $this->country = 'France';
2930 $this->morphy = 'mor';
2931 $this->email = 'specimen@specimen.com';
2932 $this->socialnetworks = array(
2933 'skype' => 'skypepseudo',
2934 'twitter' => 'twitterpseudo',
2935 'facebook' => 'facebookpseudo',
2936 'linkedin' => 'linkedinpseudo',
2937 );
2938 $this->phone = '0999999999';
2939 $this->phone_perso = '0999999998';
2940 $this->phone_mobile = '0999999997';
2941 $this->note_public = 'This is a public note';
2942 $this->note_private = 'This is a private note';
2943 $this->birth = $now;
2944 $this->photo = '';
2945 $this->public = 1;
2946 $this->statut = self::STATUS_DRAFT;
2947 $this->status = self::STATUS_DRAFT;
2948
2949 $this->datefin = $now;
2950 $this->datevalid = $now;
2951 $this->default_lang = '';
2952
2953 $this->typeid = 1; // Id type adherent
2954 $this->type = 'Type adherent'; // Libelle type adherent
2955 $this->need_subscription = 0;
2956
2957 $this->first_subscription_date = $now;
2958 $this->first_subscription_date_start = $this->first_subscription_date;
2959 $this->first_subscription_date_end = dol_time_plus_duree($this->first_subscription_date_start, 1, 'y');
2960 $this->first_subscription_amount = 10;
2961
2962 $this->last_subscription_date = $this->first_subscription_date;
2963 $this->last_subscription_date_start = $this->first_subscription_date;
2964 $this->last_subscription_date_end = dol_time_plus_duree($this->last_subscription_date_start, 1, 'y');
2965 $this->last_subscription_amount = 10;
2966 return 1;
2967 }
2968
2969
2970 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2971 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2981 public function _load_ldap_dn($info, $mode = 0)
2982 {
2983 // phpcs:enable
2984 global $conf;
2985 $dn = '';
2986 if ($mode == 0) {
2987 $dn = getDolGlobalString('LDAP_KEY_MEMBERS') . "=".$info[getDolGlobalString('LDAP_KEY_MEMBERS')]."," . getDolGlobalString('LDAP_MEMBER_DN');
2988 }
2989 if ($mode == 1) {
2990 $dn = getDolGlobalString('LDAP_MEMBER_DN');
2991 }
2992 if ($mode == 2) {
2993 $dn = getDolGlobalString('LDAP_KEY_MEMBERS') . "=".$info[getDolGlobalString('LDAP_KEY_MEMBERS')];
2994 }
2995 return $dn;
2996 }
2997
2998
2999 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
3000 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
3006 public function _load_ldap_info()
3007 {
3008 // phpcs:enable
3009 global $conf, $langs;
3010
3011 $info = array();
3012 $socialnetworks = getArrayOfSocialNetworks();
3013 $keymodified = false;
3014
3015 // Object classes
3016 $info["objectclass"] = explode(',', getDolGlobalString('LDAP_MEMBER_OBJECT_CLASS'));
3017
3018 $this->fullname = $this->getFullName($langs);
3019
3020 // For avoid ldap error when firstname and lastname are empty
3021 if ($this->morphy == 'mor' && (empty($this->fullname) || $this->fullname == $this->company)) {
3022 $this->fullname = $this->company;
3023 $this->lastname = $this->company;
3024 }
3025
3026 // Possible LDAP KEY (constname => varname)
3027 $ldapkey = array(
3028 'LDAP_MEMBER_FIELD_FULLNAME' => 'fullname',
3029 'LDAP_MEMBER_FIELD_NAME' => 'lastname',
3030 'LDAP_MEMBER_FIELD_LOGIN' => 'login',
3031 'LDAP_MEMBER_FIELD_LOGIN_SAMBA' => 'login',
3032 'LDAP_MEMBER_FIELD_MAIL' => 'email'
3033 );
3034
3035 // Member
3036 foreach ($ldapkey as $constname => $varname) {
3037 if (!empty($this->$varname) && getDolGlobalString($constname)) {
3038 $info[getDolGlobalString($constname)] = $this->$varname;
3039
3040 // Check if it is the LDAP key and if its value has been changed
3041 if (getDolGlobalString('LDAP_KEY_MEMBERS') && getDolGlobalString('LDAP_KEY_MEMBERS') == getDolGlobalString($constname)) {
3042 if (!empty($this->oldcopy) && $this->$varname != $this->oldcopy->$varname) {
3043 $keymodified = true; // For check if LDAP key has been modified
3044 }
3045 }
3046 }
3047 }
3048 if ($this->firstname && getDolGlobalString('LDAP_MEMBER_FIELD_FIRSTNAME')) {
3049 $info[getDolGlobalString('LDAP_MEMBER_FIELD_FIRSTNAME')] = $this->firstname;
3050 }
3051 if ($this->poste && getDolGlobalString('LDAP_MEMBER_FIELD_TITLE')) {
3052 $info[getDolGlobalString('LDAP_MEMBER_FIELD_TITLE')] = $this->poste;
3053 }
3054 if ($this->company && getDolGlobalString('LDAP_MEMBER_FIELD_COMPANY')) {
3055 $info[getDolGlobalString('LDAP_MEMBER_FIELD_COMPANY')] = $this->company;
3056 }
3057 if ($this->address && getDolGlobalString('LDAP_MEMBER_FIELD_ADDRESS')) {
3058 $info[getDolGlobalString('LDAP_MEMBER_FIELD_ADDRESS')] = $this->address;
3059 }
3060 if ($this->zip && getDolGlobalString('LDAP_MEMBER_FIELD_ZIP')) {
3061 $info[getDolGlobalString('LDAP_MEMBER_FIELD_ZIP')] = $this->zip;
3062 }
3063 if ($this->town && getDolGlobalString('LDAP_MEMBER_FIELD_TOWN')) {
3064 $info[getDolGlobalString('LDAP_MEMBER_FIELD_TOWN')] = $this->town;
3065 }
3066 if ($this->country_code && getDolGlobalString('LDAP_MEMBER_FIELD_COUNTRY')) {
3067 $info[getDolGlobalString('LDAP_MEMBER_FIELD_COUNTRY')] = $this->country_code;
3068 }
3069 foreach ($socialnetworks as $key => $value) {
3070 if ($this->socialnetworks[$value['label']] && getDolGlobalString('LDAP_MEMBER_FIELD_'.strtoupper($value['label']))) {
3071 $info[getDolGlobalString('LDAP_MEMBER_FIELD_'.strtoupper($value['label']))] = $this->socialnetworks[$value['label']];
3072 }
3073 }
3074 if ($this->phone && getDolGlobalString('LDAP_MEMBER_FIELD_PHONE')) {
3075 $info[getDolGlobalString('LDAP_MEMBER_FIELD_PHONE')] = $this->phone;
3076 }
3077 if ($this->phone_perso && getDolGlobalString('LDAP_MEMBER_FIELD_PHONE_PERSO')) {
3078 $info[getDolGlobalString('LDAP_MEMBER_FIELD_PHONE_PERSO')] = $this->phone_perso;
3079 }
3080 if ($this->phone_mobile && getDolGlobalString('LDAP_MEMBER_FIELD_MOBILE')) {
3081 $info[getDolGlobalString('LDAP_MEMBER_FIELD_MOBILE')] = $this->phone_mobile;
3082 }
3083 if ($this->fax && getDolGlobalString('LDAP_MEMBER_FIELD_FAX')) {
3084 $info[getDolGlobalString('LDAP_MEMBER_FIELD_FAX')] = $this->fax;
3085 }
3086 if ($this->note_private && getDolGlobalString('LDAP_MEMBER_FIELD_DESCRIPTION')) {
3087 $info[getDolGlobalString('LDAP_MEMBER_FIELD_DESCRIPTION')] = dol_string_nohtmltag($this->note_private, 2);
3088 }
3089 if ($this->note_public && getDolGlobalString('LDAP_MEMBER_FIELD_NOTE_PUBLIC')) {
3090 $info[getDolGlobalString('LDAP_MEMBER_FIELD_NOTE_PUBLIC')] = dol_string_nohtmltag($this->note_public, 2);
3091 }
3092 if ($this->birth && getDolGlobalString('LDAP_MEMBER_FIELD_BIRTHDATE')) {
3093 $info[getDolGlobalString('LDAP_MEMBER_FIELD_BIRTHDATE')] = dol_print_date($this->birth, 'dayhourldap');
3094 }
3095 if (isset($this->statut) && getDolGlobalString('LDAP_FIELD_MEMBER_STATUS')) {
3096 $info[getDolGlobalString('LDAP_FIELD_MEMBER_STATUS')] = $this->statut;
3097 }
3098 if ($this->datefin && getDolGlobalString('LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION')) {
3099 $info[getDolGlobalString('LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION')] = dol_print_date($this->datefin, 'dayhourldap');
3100 }
3101
3102 // When password is modified
3103 if (!empty($this->pass)) {
3104 if (getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD')) {
3105 $info[getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD')] = $this->pass; // this->pass = Unencrypted password
3106 }
3107 if (getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')) {
3108 $info[getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')] = dol_hash($this->pass, 'openldap'); // Create OpenLDAP password (see LDAP_PASSWORD_HASH_TYPE)
3109 }
3110 } elseif (getDolGlobalString('LDAP_SERVER_PROTOCOLVERSION') !== '3') {
3111 // Set LDAP password if possible
3112 // If ldap key is modified and LDAPv3 we use ldap_rename function for avoid lose encrypt password
3113 if (getDolGlobalString('DATABASE_PWD_ENCRYPTED')) { // This should be on on default installation
3114 // Just for the case we use old md5 encryption (deprecated, no more used, kept for compatibility)
3115 if (!getDolGlobalString('MAIN_SECURITY_HASH_ALGO') || getDolGlobalString('MAIN_SECURITY_HASH_ALGO') == 'md5') {
3116 if ($this->pass_indatabase_crypted && getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')) {
3117 // Create OpenLDAP MD5 password from Dolibarr MD5 password
3118 // Note: This suppose that "pass_indatabase_crypted" is a md5 (this should not happen anymore)"
3119 $info[getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')] = dolGetLdapPasswordHash($this->pass_indatabase_crypted, 'md5frommd5');
3120 }
3121 }
3122 } elseif (!empty($this->pass_indatabase)) {
3123 // Use $this->pass_indatabase value if exists
3124 if (getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD')) {
3125 $info[getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD')] = $this->pass_indatabase; // $this->pass_indatabase = Unencrypted password
3126 }
3127 if (getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')) {
3128 $info[getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')] = dol_hash($this->pass_indatabase, 'openldap'); // Create OpenLDAP password (see LDAP_PASSWORD_HASH_TYPE)
3129 }
3130 }
3131 }
3132
3133 // Subscriptions
3134 if ($this->first_subscription_date && getDolGlobalString('LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE')) {
3135 $info[getDolGlobalString('LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE')] = dol_print_date($this->first_subscription_date, 'dayhourldap');
3136 }
3137 if (isset($this->first_subscription_amount) && getDolGlobalString('LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT')) {
3138 $info[getDolGlobalString('LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT')] = $this->first_subscription_amount;
3139 }
3140 if ($this->last_subscription_date && getDolGlobalString('LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE')) {
3141 $info[getDolGlobalString('LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE')] = dol_print_date($this->last_subscription_date, 'dayhourldap');
3142 }
3143 if (isset($this->last_subscription_amount) && getDolGlobalString('LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT')) {
3144 $info[getDolGlobalString('LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT')] = $this->last_subscription_amount;
3145 }
3146
3147 return $info;
3148 }
3149
3150
3157 public function info($id)
3158 {
3159 $sql = 'SELECT a.rowid, a.datec as datec,';
3160 $sql .= ' a.datevalid as datev,';
3161 $sql .= ' GREATEST(a.tms, COALESCE(aef.tms, a.tms)) as datem,';
3162 $sql .= ' a.fk_user_author, a.fk_user_valid, a.fk_user_mod';
3163 $sql .= ' FROM '.MAIN_DB_PREFIX.'adherent as a';
3164 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'adherent_extrafields as aef ON aef.fk_object = a.rowid';
3165 $sql .= ' WHERE a.rowid = '.((int) $id);
3166
3167 dol_syslog(get_class($this)."::info", LOG_DEBUG);
3168 $result = $this->db->query($sql);
3169 if ($result) {
3170 if ($this->db->num_rows($result)) {
3171 $obj = $this->db->fetch_object($result);
3172
3173 $this->id = $obj->rowid;
3174
3175 $this->user_creation_id = $obj->fk_user_author;
3176 $this->user_validation_id = $obj->fk_user_valid;
3177 $this->user_modification_id = $obj->fk_user_mod;
3178 $this->date_creation = $this->db->jdate($obj->datec);
3179 $this->date_validation = $this->db->jdate($obj->datev);
3180 $this->date_modification = $this->db->jdate($obj->datem);
3181 }
3182
3183 $this->db->free($result);
3184 } else {
3185 dol_print_error($this->db);
3186 }
3187 }
3188
3194 public function getNbOfEMailings()
3195 {
3196 $sql = "SELECT count(mc.email) as nb";
3197 $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
3198 $sql .= " WHERE mc.email = '".$this->db->escape($this->email)."'";
3199 $sql .= " AND mc.statut NOT IN (-1,0)"; // -1 error, 0 not sent, 1 sent with success
3200
3201 $resql = $this->db->query($sql);
3202 if ($resql) {
3203 $obj = $this->db->fetch_object($resql);
3204 $nb = (int) $obj->nb;
3205
3206 $this->db->free($resql);
3207 return $nb;
3208 } else {
3209 $this->error = $this->db->error();
3210 return -1;
3211 }
3212 }
3213
3224 public function setCategories($categories)
3225 {
3226 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
3227 return parent::setCategoriesCommon($categories, Categorie::TYPE_MEMBER);
3228 }
3229
3238 public static function replaceThirdparty($db, $origin_id, $dest_id)
3239 {
3240 $tables = array('adherent');
3241
3242 return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
3243 }
3244
3250 public function hasDelay()
3251 {
3252 global $conf;
3253
3254 //Only valid members
3255 if ($this->status != self::STATUS_VALIDATED) {
3256 return false;
3257 }
3258 if (!$this->datefin) {
3259 return false;
3260 }
3261
3262 $now = dol_now();
3263
3264 return $this->datefin < ($now - getWarningDelay('member', 'subscription'));
3265 }
3266
3267
3276 public function sendReminderForExpiredSubscription($daysbeforeendlist = '10', $fk_adherent_type = 0)
3277 {
3278 global $conf, $langs, $mysoc, $user;
3279
3280 $error = 0;
3281 $this->output = '';
3282 $this->error = '';
3283
3284 $blockingerrormsg = '';
3285
3286 if (!isModEnabled('member')) { // Should not happen. If module disabled, cron job should not be visible.
3287 $langs->load("agenda");
3288 $this->output = $langs->trans('ModuleNotEnabled', $langs->transnoentitiesnoconv("Adherent"));
3289 return 0;
3290 }
3291 if (!getDolGlobalString('MEMBER_REMINDER_EMAIL')) {
3292 $langs->load("agenda");
3293 $this->output = $langs->trans('EventRemindersByEmailNotEnabled', $langs->transnoentitiesnoconv("Adherent"));
3294 return 0;
3295 }
3296
3297 $now = dol_now();
3298 $nbok = 0;
3299 $nbko = 0;
3300
3301 $listofmembersok = array();
3302 $listofmembersko = array();
3303
3304 $arraydaysbeforeend = explode(';', $daysbeforeendlist);
3305 foreach ($arraydaysbeforeend as $daysbeforeend) { // Loop on each delay
3306 dol_syslog(__METHOD__.' - Process delta = '.$daysbeforeend, LOG_DEBUG);
3307
3308 if (!is_numeric($daysbeforeend)) {
3309 $blockingerrormsg = "Value for delta is not a numeric value";
3310 $nbko++;
3311 break;
3312 }
3313
3314 $tmp = dol_getdate($now);
3315 $datetosearchfor = dol_time_plus_duree(dol_mktime(0, 0, 0, $tmp['mon'], $tmp['mday'], $tmp['year'], 'tzserver'), (int) $daysbeforeend, 'd');
3316 $datetosearchforend = dol_time_plus_duree(dol_mktime(23, 59, 59, $tmp['mon'], $tmp['mday'], $tmp['year'], 'tzserver'), (int) $daysbeforeend, 'd');
3317
3318 $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'adherent';
3319 $sql .= " WHERE entity = ".((int) $conf->entity); // Do not use getEntity('adherent').")" here, we want the batch to be on its entity only;
3320 $sql .= " AND statut = 1";
3321 $sql .= " AND datefin >= '".$this->db->idate($datetosearchfor)."'";
3322 $sql .= " AND datefin <= '".$this->db->idate($datetosearchforend)."'";
3323 if ((int) $fk_adherent_type > 0) {
3324 $sql .= " AND fk_adherent_type = ".((int) $fk_adherent_type);
3325 }
3326 //$sql .= " LIMIT 10000";
3327
3328 $resql = $this->db->query($sql);
3329 if ($resql) {
3330 $num_rows = $this->db->num_rows($resql);
3331
3332 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
3333 $formmail = new FormMail($this->db);
3334
3335 $i = 0;
3336 while ($i < $num_rows) {
3337 $obj = $this->db->fetch_object($resql);
3338
3339 // A new object for each member: fetch() does not reset the properties loaded for the previous member,
3340 // like ->thirdparty that would be reused for a member that has no third party.
3341 $adherent = new Adherent($this->db);
3342 $adherent->fetch($obj->rowid, '', 0, '', true, true);
3343
3344 if (empty($adherent->email)) {
3345 $nbko++;
3346 $listofmembersko[$adherent->id] = $adherent->id;
3347 } else {
3348 $thirdpartyres = $adherent->fetch_thirdparty();
3349 if ($thirdpartyres === -1) {
3350 $languagecodeformember = $mysoc->default_lang;
3351 } else {
3352 // 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.
3353 $languagefromcountrycode = getLanguageCodeFromCountryCode($adherent->country_code ? $adherent->country_code : (is_object($adherent->thirdparty) ? $adherent->thirdparty->country_code : ''));
3354 $languagecodeformember = (empty($adherent->thirdparty->default_lang) ? ($languagefromcountrycode ? $languagefromcountrycode : $mysoc->default_lang) : $adherent->thirdparty->default_lang);
3355 }
3356 if (!empty($adherent->default_lang)) {
3357 // The language set on the member itself has priority
3358 $languagecodeformember = $adherent->default_lang;
3359 }
3360
3361 // Send reminder email
3362 $outputlangs = new Translate('', $conf);
3363 $outputlangs->setDefaultLang($languagecodeformember);
3364 $outputlangs->loadLangs(array("main", "members"));
3365 dol_syslog("sendReminderForExpiredSubscription Language for member id ".$adherent->id." set to ".$outputlangs->defaultlang." mysoc->default_lang=".$mysoc->default_lang);
3366
3367 $arraydefaultmessage = null;
3368 $labeltouse = getDolGlobalString('ADHERENT_EMAIL_TEMPLATE_REMIND_EXPIRATION');
3369
3370 if (!empty($labeltouse)) {
3371 $arraydefaultmessage = $formmail->getEMailTemplate($this->db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
3372 }
3373
3374 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
3375 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $adherent);
3376 //if (is_array($adherent->thirdparty)) $substitutionarraycomp = ...
3377 complete_substitutions_array($substitutionarray, $outputlangs, $adherent);
3378
3379 $subject = make_substitutions($arraydefaultmessage->topic, $substitutionarray, $outputlangs);
3380 $msg = make_substitutions($arraydefaultmessage->content, $substitutionarray, $outputlangs);
3381 $email_from = getDolGlobalString('ADHERENT_MAIL_FROM', $conf->email_from);
3382 $to = $adherent->email;
3383 $cc = getDolGlobalString('ADHERENT_CC_MAIL_FROM');
3384
3385 $trackid = 'mem'.$adherent->id;
3386 $moreinheader = 'X-Dolibarr-Info: sendReminderForExpiredSubscription'."\r\n";
3387
3388 include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
3389 $cmail = new CMailFile($subject, $to, $email_from, $msg, array(), array(), array(), $cc, '', 0, 1, '', '', $trackid, $moreinheader);
3390 $result = $cmail->sendfile();
3391 if (!$result) {
3392 $error++;
3393 $this->error .= $cmail->error.' ';
3394 if (!is_null($cmail->errors)) {
3395 $this->errors += $cmail->errors;
3396 }
3397 $nbko++;
3398 $listofmembersko[$adherent->id] = $adherent->id;
3399 } else {
3400 $nbok++;
3401 $listofmembersok[$adherent->id] = $adherent->id;
3402
3403 $message = $msg;
3404 $sendto = $to;
3405 $sendtocc = '';
3406 $sendtobcc = '';
3407 $actioncode = 'EMAIL';
3408 $extraparams = array();
3409
3410 $actionmsg = '';
3411 $actionmsg2 = $langs->transnoentities('MailSentByTo', CMailFile::getValidAddress($email_from, 4, 0, 1), CMailFile::getValidAddress($sendto, 4, 0, 1));
3412 if ($message) {
3413 $actionmsg = $langs->transnoentities('MailFrom').': '.dol_escape_htmltag($email_from);
3414 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTo').': '.dol_escape_htmltag($sendto));
3415 // if ($sendtocc) {
3416 // $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc').": ".dol_escape_htmltag($sendtocc));
3417 // }
3418 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic').": ".$subject);
3419 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody').":");
3420 $actionmsg = dol_concatdesc($actionmsg, $message);
3421 }
3422
3423 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
3424
3425 // Insert record of emails sent
3426 $actioncomm = new ActionComm($this->db);
3427
3428 $actioncomm->type_code = 'AC_OTH_AUTO'; // Type of event ('AC_OTH', 'AC_OTH_AUTO', 'AC_XXX'...)
3429 $actioncomm->code = 'AC_'.$actioncode;
3430 $actioncomm->label = $actionmsg2;
3431 $actioncomm->note_private = $actionmsg;
3432 $actioncomm->fk_project = 0;
3433 $actioncomm->datep = $now;
3434 $actioncomm->datef = $now;
3435 $actioncomm->percentage = -1; // Not applicable
3436 $actioncomm->socid = (is_object($adherent->thirdparty) ? $adherent->thirdparty->id : 0);
3437 $actioncomm->contact_id = 0;
3438 $actioncomm->authorid = $user->id; // User saving action
3439 $actioncomm->userownerid = $user->id; // Owner of action
3440 // Fields when action is an email (content should be added into note)
3441 $actioncomm->email_msgid = $cmail->msgid;
3442 $actioncomm->email_from = $email_from;
3443 $actioncomm->email_sender = '';
3444 $actioncomm->email_to = $to;
3445 $actioncomm->email_tocc = $sendtocc;
3446 $actioncomm->email_tobcc = $sendtobcc;
3447 $actioncomm->email_subject = $subject;
3448 $actioncomm->errors_to = '';
3449
3450 $actioncomm->fk_element = $adherent->id;
3451 $actioncomm->elementid = $adherent->id;
3452 $actioncomm->elementtype = $adherent->element;
3453
3454 $actioncomm->extraparams = $extraparams;
3455
3456 $actioncomm->create($user);
3457 }
3458 } else {
3459 //$blockingerrormsg = "Can't find email template with label=".$labeltouse.", to use for the reminding email";
3460
3461 $error++;
3462 $this->error .= "Can't find email template with label=".$labeltouse.", to use for the reminding email ";
3463
3464 $nbko++;
3465 $listofmembersko[$adherent->id] = $adherent->id;
3466
3467 // Do not break here: a template issue for one member (ex: not found for its language) must not prevent
3468 // the reminder from being sent to the other members due the same day.
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}
$propal type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition propal.php:281
$object ref
Definition info.php:90
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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.
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:127
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").
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:66
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.
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
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_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
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.
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...
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_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)
Definition html.lib.php:183
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.
div refaddress div address