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