dolibarr 21.0.0-beta
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-2024 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 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
102 public $civility_id;
103
107 public $civility_code;
108
112 public $civility;
113
119 public $societe;
120
124 public $company;
125
131 public $fk_soc;
132
136 public $socid;
137
141 public $socialnetworks;
142
146 public $phone;
147
151 public $phone_perso;
152
156 public $phone_pro;
157
161 public $phone_mobile;
162
166 public $fax;
167
171 public $poste;
172
176 public $morphy;
177
181 public $public;
182
187 public $default_lang;
188
192 public $photo;
193
199 public $datec;
200
206 public $datem;
207
211 public $datevalid;
212
216 public $gender;
217
221 public $birth;
222
226 public $typeid;
227
231 public $type;
232
236 public $need_subscription;
237
241 public $user_id;
242
246 public $user_login;
247
251 public $datefin;
252
253
254 // Fields loaded by fetch_subscriptions() from member table
255
259 public $first_subscription_date;
260
264 public $first_subscription_date_start;
265
269 public $first_subscription_date_end;
270
274 public $first_subscription_amount;
275
279 public $last_subscription_date;
280
284 public $last_subscription_date_start;
285
289 public $last_subscription_date_end;
290
294 public $last_subscription_amount;
295
299 public $subscriptions = array();
300
304 public $ip;
305
306 // Fields loaded by fetchPartnerships() from partnership table
307
311 public $partnerships = array();
312
316 public $invoice;
317
318
322 public $fields = array(
323 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 10),
324 'ref' => array('type' => 'varchar(30)', 'label' => 'Ref', 'default' => '1', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'position' => 12, 'index' => 1),
325 'entity' => array('type' => 'integer', 'label' => 'Entity', 'default' => '1', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 15, 'index' => 1),
326 'ref_ext' => array('type' => 'varchar(128)', 'label' => 'Ref ext', 'enabled' => 1, 'visible' => 0, 'position' => 20),
327 'civility' => array('type' => 'varchar(6)', 'label' => 'Civility', 'enabled' => 1, 'visible' => -1, 'position' => 25),
328 'lastname' => array('type' => 'varchar(50)', 'label' => 'Lastname', 'enabled' => 1, 'visible' => 1, 'position' => 30, 'showoncombobox' => 1),
329 'firstname' => array('type' => 'varchar(50)', 'label' => 'Firstname', 'enabled' => 1, 'visible' => 1, 'position' => 35, 'showoncombobox' => 1),
330 'login' => array('type' => 'varchar(50)', 'label' => 'Login', 'enabled' => 1, 'visible' => 1, 'position' => 40),
331 'pass' => array('type' => 'varchar(50)', 'label' => 'Pass', 'enabled' => 1, 'visible' => -1, 'position' => 45),
332 'pass_crypted' => array('type' => 'varchar(128)', 'label' => 'Pass crypted', 'enabled' => 1, 'visible' => -1, 'position' => 50),
333 'morphy' => array('type' => 'varchar(3)', 'label' => 'MemberNature', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'position' => 55),
334 'fk_adherent_type' => array('type' => 'integer', 'label' => 'Fk adherent type', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'position' => 60),
335 'societe' => array('type' => 'varchar(128)', 'label' => 'Societe', 'enabled' => 1, 'visible' => 1, 'position' => 65, 'showoncombobox' => 2),
336 'fk_soc' => array('type' => 'integer:Societe:societe/class/societe.class.php', 'label' => 'ThirdParty', 'enabled' => 1, 'visible' => 1, 'position' => 70),
337 'address' => array('type' => 'text', 'label' => 'Address', 'enabled' => 1, 'visible' => -1, 'position' => 75),
338 'zip' => array('type' => 'varchar(10)', 'label' => 'Zip', 'enabled' => 1, 'visible' => -1, 'position' => 80),
339 'town' => array('type' => 'varchar(50)', 'label' => 'Town', 'enabled' => 1, 'visible' => -1, 'position' => 85),
340 'state_id' => array('type' => 'integer', 'label' => 'State id', 'enabled' => 1, 'visible' => -1, 'position' => 90),
341 'country' => array('type' => 'integer:Ccountry:core/class/ccountry.class.php', 'label' => 'Country', 'enabled' => 1, 'visible' => 1, 'position' => 95),
342 'phone' => array('type' => 'varchar(30)', 'label' => 'Phone', 'enabled' => 1, 'visible' => -1, 'position' => 115),
343 'phone_perso' => array('type' => 'varchar(30)', 'label' => 'Phone perso', 'enabled' => 1, 'visible' => -1, 'position' => 120),
344 'phone_mobile' => array('type' => 'varchar(30)', 'label' => 'Phone mobile', 'enabled' => 1, 'visible' => -1, 'position' => 125),
345 'email' => array('type' => 'varchar(255)', 'label' => 'Email', 'enabled' => 1, 'visible' => 1, 'position' => 126),
346 'url' => array('type' => 'varchar(255)', 'label' => 'Url', 'enabled' => 1, 'visible' => -1, 'position' => 127),
347 'socialnetworks' => array('type' => 'text', 'label' => 'Socialnetworks', 'enabled' => 1, 'visible' => -1, 'position' => 128),
348 'birth' => array('type' => 'date', 'label' => 'DateOfBirth', 'enabled' => 1, 'visible' => -1, 'position' => 130),
349 'gender' => array('type' => 'varchar(10)', 'label' => 'Gender', 'enabled' => 1, 'visible' => -1, 'position' => 132),
350 'photo' => array('type' => 'varchar(255)', 'label' => 'Photo', 'enabled' => 1, 'visible' => -1, 'position' => 135),
351 'public' => array('type' => 'smallint(6)', 'label' => 'Public', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 145),
352 'datefin' => array('type' => 'datetime', 'label' => 'DateEnd', 'enabled' => 1, 'visible' => 1, 'position' => 150),
353 'default_lang' => array('type' => 'varchar(6)', 'label' => 'Default lang', 'enabled' => 1, 'visible' => -1, 'position' => 153),
354 'note_public' => array('type' => 'text', 'label' => 'NotePublic', 'enabled' => 1, 'visible' => 0, 'position' => 155),
355 'note_private' => array('type' => 'text', 'label' => 'NotePrivate', 'enabled' => 1, 'visible' => 0, 'position' => 160),
356 'datevalid' => array('type' => 'datetime', 'label' => 'DateValidation', 'enabled' => 1, 'visible' => -1, 'position' => 165),
357 'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -1, 'position' => 170),
358 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 175),
359 'fk_user_author' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'Fk user author', 'enabled' => 1, 'visible' => -1, 'position' => 180),
360 'fk_user_mod' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'Fk user mod', 'enabled' => 1, 'visible' => -1, 'position' => 185),
361 'fk_user_valid' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserValidation', 'enabled' => 1, 'visible' => -1, 'position' => 190),
362 'canvas' => array('type' => 'varchar(32)', 'label' => 'Canvas', 'enabled' => 1, 'visible' => -1, 'position' => 195),
363 'statut' => array('type' => 'smallint(6)', 'label' => 'Statut', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'position' => 500, 'arrayofkeyval' => array(-1 => 'Draft', 1 => 'Validated', 0 => 'MemberStatusResiliatedShort', -2 => 'MemberStatusExcludedShort')),
364 'model_pdf' => array('type' => 'varchar(255)', 'label' => 'Model pdf', 'enabled' => 1, 'visible' => 0, 'position' => 800),
365 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'visible' => -2, 'position' => 805)
366 );
367
371 const STATUS_DRAFT = -1;
383 const STATUS_EXCLUDED = -2;
384
385
391 public function __construct($db)
392 {
393 $this->db = $db;
394 $this->statut = self::STATUS_DRAFT;
395 $this->status = self::STATUS_DRAFT;
396 // l'adherent n'est pas public par default
397 $this->public = 0;
398 $this->ismultientitymanaged = 1;
399 $this->isextrafieldmanaged = 1;
400 // les champs optionnels sont vides
401 $this->array_options = array();
402 }
403
404
405 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
424 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 = '')
425 {
426 // phpcs:enable
427 dol_syslog('Warning using deprecated Adherent::send_an_email', LOG_WARNING);
428
429 return $this->sendEmail($text, $subject, $filename_list, $mimetype_list, $mimefilename_list, $addr_cc, $addr_bcc, $deliveryreceipt, $msgishtml, $errors_to, $moreinheader);
430 }
431
449 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 = '')
450 {
451 global $conf, $langs;
452
453 // Detect if message is HTML
454 if ($msgishtml == -1) {
455 $msgishtml = 0;
456 if (dol_textishtml($text, 0)) {
457 $msgishtml = 1;
458 }
459 }
460
461 dol_syslog('sendEmail msgishtml='.$msgishtml);
462
463 $texttosend = $this->makeSubstitution($text);
464 $subjecttosend = $this->makeSubstitution($subject);
465 if ($msgishtml) {
466 $texttosend = dol_htmlentitiesbr($texttosend);
467 }
468
469 // Envoi mail confirmation
470 $from = $conf->email_from;
471 if (getDolGlobalString('ADHERENT_MAIL_FROM')) {
472 $from = getDolGlobalString('ADHERENT_MAIL_FROM');
473 }
474
475 $trackid = 'mem'.$this->id;
476
477 // Send email (substitutionarray must be done just before this)
478 include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
479 $mailfile = new CMailFile($subjecttosend, $this->email, $from, $texttosend, $filename_list, $mimetype_list, $mimefilename_list, $addr_cc, $addr_bcc, $deliveryreceipt, $msgishtml, '', '', $trackid, $moreinheader);
480 if ($mailfile->sendfile()) {
481 return 1;
482 } else {
483 $this->error = $langs->trans("ErrorFailedToSendMail", $from, $this->email).'. '.$mailfile->error;
484 return -1;
485 }
486 }
487
488
495 public function makeSubstitution($text)
496 {
497 global $langs;
498
499 $birthday = dol_print_date($this->birth, 'day');
500
501 $msgishtml = 0;
502 if (dol_textishtml($text, 1)) {
503 $msgishtml = 1;
504 }
505
506 $infos = '';
507 if ($this->civility_id) {
508 $infos .= $langs->transnoentities("UserTitle").": ".$this->getCivilityLabel()."\n";
509 }
510 $infos .= $langs->transnoentities("id").": ".$this->id."\n";
511 $infos .= $langs->transnoentities("ref").": ".$this->ref."\n";
512 $infos .= $langs->transnoentities("Lastname").": ".$this->lastname."\n";
513 $infos .= $langs->transnoentities("Firstname").": ".$this->firstname."\n";
514 $infos .= $langs->transnoentities("Company").": ".$this->company."\n";
515 $infos .= $langs->transnoentities("Address").": ".$this->address."\n";
516 $infos .= $langs->transnoentities("Zip").": ".$this->zip."\n";
517 $infos .= $langs->transnoentities("Town").": ".$this->town."\n";
518 $infos .= $langs->transnoentities("Country").": ".$this->country."\n";
519 $infos .= $langs->transnoentities("EMail").": ".$this->email."\n";
520 $infos .= $langs->transnoentities("PhonePro").": ".$this->phone."\n";
521 $infos .= $langs->transnoentities("PhonePerso").": ".$this->phone_perso."\n";
522 $infos .= $langs->transnoentities("PhoneMobile").": ".$this->phone_mobile."\n";
523 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
524 $infos .= $langs->transnoentities("Login").": ".$this->login."\n";
525 $infos .= $langs->transnoentities("Password").": ".$this->pass."\n";
526 }
527 $infos .= $langs->transnoentities("Birthday").": ".$birthday."\n";
528 $infos .= $langs->transnoentities("Photo").": ".$this->photo."\n";
529 $infos .= $langs->transnoentities("Public").": ".yn($this->public);
530
531 // Substitutions
532 $substitutionarray = array(
533 '__ID__' => $this->id,
534 '__REF__' => $this->ref,
535 '__MEMBER_ID__' => $this->id,
536 '__CIVILITY__' => $this->getCivilityLabel(),
537 '__FIRSTNAME__' => $msgishtml ? dol_htmlentitiesbr($this->firstname) : ($this->firstname ? $this->firstname : ''),
538 '__LASTNAME__' => $msgishtml ? dol_htmlentitiesbr($this->lastname) : ($this->lastname ? $this->lastname : ''),
539 '__FULLNAME__' => $msgishtml ? dol_htmlentitiesbr($this->getFullName($langs)) : $this->getFullName($langs),
540 '__COMPANY__' => $msgishtml ? dol_htmlentitiesbr($this->company) : ($this->company ? $this->company : ''),
541 '__ADDRESS__' => $msgishtml ? dol_htmlentitiesbr($this->address) : ($this->address ? $this->address : ''),
542 '__ZIP__' => $msgishtml ? dol_htmlentitiesbr($this->zip) : ($this->zip ? $this->zip : ''),
543 '__TOWN__' => $msgishtml ? dol_htmlentitiesbr($this->town) : ($this->town ? $this->town : ''),
544 '__COUNTRY__' => $msgishtml ? dol_htmlentitiesbr($this->country) : ($this->country ? $this->country : ''),
545 '__EMAIL__' => $msgishtml ? dol_htmlentitiesbr($this->email) : ($this->email ? $this->email : ''),
546 '__BIRTH__' => $msgishtml ? dol_htmlentitiesbr($birthday) : ($birthday ? $birthday : ''),
547 '__PHOTO__' => $msgishtml ? dol_htmlentitiesbr($this->photo) : ($this->photo ? $this->photo : ''),
548 '__LOGIN__' => $msgishtml ? dol_htmlentitiesbr($this->login) : ($this->login ? $this->login : ''),
549 '__PASSWORD__' => $msgishtml ? dol_htmlentitiesbr($this->pass) : ($this->pass ? $this->pass : ''),
550 '__PHONE__' => $msgishtml ? dol_htmlentitiesbr($this->phone) : ($this->phone ? $this->phone : ''),
551 '__PHONEPRO__' => $msgishtml ? dol_htmlentitiesbr($this->phone_perso) : ($this->phone_perso ? $this->phone_perso : ''),
552 '__PHONEMOBILE__' => $msgishtml ? dol_htmlentitiesbr($this->phone_mobile) : ($this->phone_mobile ? $this->phone_mobile : ''),
553 '__TYPE__' => $msgishtml ? dol_htmlentitiesbr($this->type) : ($this->type ? $this->type : '')
554 );
555
556 complete_substitutions_array($substitutionarray, $langs, $this);
557
558 return make_substitutions($text, $substitutionarray, $langs);
559 }
560
561
569 public function getmorphylib($morphy = '', $addbadge = 0)
570 {
571 global $langs;
572 $s = '';
573
574 // Clean var
575 if (!$morphy) {
576 $morphy = $this->morphy;
577 }
578
579 if ($addbadge) {
580 $labeltoshowm = $langs->trans("Moral");
581 $labeltoshowp = $langs->trans("Physical");
582 if ($morphy == 'phy') {
583 $labeltoshow = $labeltoshowp;
584 if ($addbadge == 2) {
585 $labeltoshow = dol_strtoupper(dolGetFirstLetters($labeltoshowp));
586 if ($labeltoshow == dol_strtoupper(dolGetFirstLetters($labeltoshowm))) {
587 $labeltoshow = dol_strtoupper(dolGetFirstLetters($labeltoshowp, 2));
588 }
589 }
590 $s .= '<span class="member-individual-back paddingleftimp paddingrightimp" title="'.$langs->trans("Physical").'">'.$labeltoshow.'</span>';
591 }
592 if ($morphy == 'mor') {
593 $labeltoshow = $labeltoshowm;
594 if ($addbadge == 2) {
595 $labeltoshow = dol_strtoupper(dolGetFirstLetters($labeltoshowm));
596 if ($labeltoshow == dol_strtoupper(dolGetFirstLetters($labeltoshowp))) {
597 $labeltoshow = dol_strtoupper(dolGetFirstLetters($labeltoshowm, 2));
598 }
599 }
600 $s .= '<span class="member-company-back paddingleftimp paddingrightimp" title="'.$langs->trans("Moral").'">'.$labeltoshow.'</span>';
601 }
602 } else {
603 if ($morphy == 'phy') {
604 $s = $langs->trans("Physical");
605 } elseif ($morphy == 'mor') {
606 $s = $langs->trans("Moral");
607 }
608 }
609
610 return $s;
611 }
612
620 public function create($user, $notrigger = 0)
621 {
622 global $conf, $langs, $mysoc;
623
624 $error = 0;
625
626 $now = dol_now();
627
628 // Clean parameters
629 if (isset($this->import_key)) {
630 $this->import_key = trim($this->import_key);
631 }
632
633 // Check parameters
634 if (getDolGlobalString('ADHERENT_MAIL_REQUIRED') && !isValidEmail($this->email)) {
635 $langs->load("errors");
636 $this->error = $langs->trans("ErrorBadEMail", $this->email);
637 return -1;
638 }
639 if (!$this->datec) {
640 $this->datec = $now;
641 }
642 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
643 if (empty($this->login)) {
644 $this->error = $langs->trans("ErrorWrongValueForParameterX", "Login");
645 return -1;
646 }
647 }
648
649 // setEntity will set entity with the right value if empty or change it for the right value if multicompany module is active
650 $this->entity = setEntity($this);
651
652 $this->db->begin();
653
654 // Insert member
655 $sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent";
656 $sql .= " (ref, datec,login,fk_user_author,fk_user_mod,fk_user_valid,morphy,fk_adherent_type,entity,import_key, ip)";
657 $sql .= " VALUES (";
658 $sql .= " '(PROV)'";
659 $sql .= ", '".$this->db->idate($this->datec)."'";
660 $sql .= ", ".($this->login ? "'".$this->db->escape($this->login)."'" : "null");
661 $sql .= ", ".($user->id > 0 ? $user->id : "null"); // Can be null because member can be created by a guest or a script
662 $sql .= ", null, null, '".$this->db->escape($this->morphy)."'";
663 $sql .= ", ".((int) $this->typeid);
664 $sql .= ", ".((int) $this->entity);
665 $sql .= ", ".(!empty($this->import_key) ? "'".$this->db->escape($this->import_key)."'" : "null");
666 $sql .= ", ".(!empty($this->ip) ? "'".$this->db->escape($this->ip)."'" : "null");
667 $sql .= ")";
668
669 dol_syslog(get_class($this)."::create", LOG_DEBUG);
670 $result = $this->db->query($sql);
671 if ($result) {
672 $id = $this->db->last_insert_id(MAIN_DB_PREFIX."adherent");
673 if ($id > 0) {
674 $this->id = $id;
675 if (getDolGlobalString('MEMBER_CODEMEMBER_ADDON') == '') {
676 // keep old numbering
677 $this->ref = (string) $id;
678 } else {
679 // auto code
680 $modfile = dol_buildpath('core/modules/member/'.getDolGlobalString('MEMBER_CODEMEMBER_ADDON').'.php', 0);
681 try {
682 require_once $modfile;
683 $modname = getDolGlobalString('MEMBER_CODEMEMBER_ADDON');
684 $modCodeMember = new $modname();
685 '@phan-var-force ModeleNumRefMembers $modCodeMember';
687 $this->ref = $modCodeMember->getNextValue($mysoc, $this);
688 } catch (Exception $e) {
689 dol_syslog($e->getMessage(), LOG_ERR);
690 $error++;
691 }
692 }
693
694 // Update minor fields
695 $result = $this->update($user, 1, 1, 0, 0, 'add'); // nosync is 1 to avoid update data of user
696 if ($result < 0) {
697 $this->db->rollback();
698 return -1;
699 }
700
701 // Add link to user
702 if ($this->user_id) {
703 // Add link to user
704 $sql = "UPDATE ".MAIN_DB_PREFIX."user SET";
705 $sql .= " fk_member = ".((int) $this->id);
706 $sql .= " WHERE rowid = ".((int) $this->user_id);
707 dol_syslog(get_class($this)."::create", LOG_DEBUG);
708 $resql = $this->db->query($sql);
709 if (!$resql) {
710 $this->error = 'Failed to update user to make link with member';
711 $this->db->rollback();
712 return -4;
713 }
714 }
715
716 if (!$notrigger) {
717 // Call trigger
718 $result = $this->call_trigger('MEMBER_CREATE', $user);
719 if ($result < 0) {
720 $error++;
721 }
722 // End call triggers
723 }
724
725 if (count($this->errors)) {
726 dol_syslog(get_class($this)."::create ".implode(',', $this->errors), LOG_ERR);
727 $this->db->rollback();
728 return -3;
729 } else {
730 $this->db->commit();
731 return $this->id;
732 }
733 } else {
734 $this->error = 'Failed to get last insert id';
735 dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
736 $this->db->rollback();
737 return -2;
738 }
739 } else {
740 $this->error = $this->db->error();
741 $this->db->rollback();
742 return -1;
743 }
744 }
745
746
758 public function update($user, $notrigger = 0, $nosyncuser = 0, $nosyncuserpass = 0, $nosyncthirdparty = 0, $action = 'update')
759 {
760 global $langs, $hookmanager;
761
762 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
763
764 $nbrowsaffected = 0;
765 $error = 0;
766
767 dol_syslog(get_class($this)."::update notrigger=".$notrigger.", nosyncuser=".$nosyncuser.", nosyncuserpass=".$nosyncuserpass." nosyncthirdparty=".$nosyncthirdparty.", email=".$this->email);
768
769 // Clean parameters
770 $this->lastname = trim($this->lastname) ? trim($this->lastname) : trim($this->lastname);
771 $this->firstname = trim($this->firstname) ? trim($this->firstname) : trim($this->firstname);
772 $this->gender = trim($this->gender);
773 // $this->address = ($this->address ? $this->address : $this->address);
774 // $this->zip = ($this->zip ? $this->zip : $this->zip);
775 // $this->town = ($this->town ? $this->town : $this->town);
776 // $this->country_id = ($this->country_id > 0 ? $this->country_id : $this->country_id);
777 // $this->state_id = ($this->state_id > 0 ? $this->state_id : $this->state_id);
778 // $this->note_public = ($this->note_public ? $this->note_public : $this->note_public);
779 // $this->note_private = ($this->note_private ? $this->note_private : $this->note_private);
780 $this->url = $this->url ? clean_url($this->url, 0) : '';
781 $this->setUpperOrLowerCase();
782 // Check parameters
783 if (getDolGlobalString('ADHERENT_MAIL_REQUIRED') && !isValidEmail($this->email)) {
784 $langs->load("errors");
785 $this->error = $langs->trans("ErrorBadEMail", $this->email);
786 return -1;
787 }
788
789 $this->db->begin();
790
791 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
792 $sql .= " ref = '".$this->db->escape($this->ref)."'";
793 $sql .= ", civility = ".($this->civility_id ? "'".$this->db->escape($this->civility_id)."'" : "null");
794 $sql .= ", firstname = ".($this->firstname ? "'".$this->db->escape($this->firstname)."'" : "null");
795 $sql .= ", lastname = ".($this->lastname ? "'".$this->db->escape($this->lastname)."'" : "null");
796 $sql .= ", gender = ".($this->gender != -1 ? "'".$this->db->escape($this->gender)."'" : "null"); // 'man' or 'woman'
797 $sql .= ", login = ".($this->login ? "'".$this->db->escape($this->login)."'" : "null");
798 $sql .= ", societe = ".($this->company ? "'".$this->db->escape($this->company)."'" : ($this->societe ? "'".$this->db->escape($this->societe)."'" : "null"));
799 if ($this->socid) {
800 $sql .= ", fk_soc = ".($this->socid > 0 ? (int) $this->socid : "null"); // Must be modified only when creating from a third-party
801 }
802 $sql .= ", address = ".($this->address ? "'".$this->db->escape($this->address)."'" : "null");
803 $sql .= ", zip = ".($this->zip ? "'".$this->db->escape($this->zip)."'" : "null");
804 $sql .= ", town = ".($this->town ? "'".$this->db->escape($this->town)."'" : "null");
805 $sql .= ", country = ".($this->country_id > 0 ? (int) $this->country_id : "null");
806 $sql .= ", state_id = ".($this->state_id > 0 ? (int) $this->state_id : "null");
807 $sql .= ", email = '".$this->db->escape($this->email)."'";
808 $sql .= ", url = ".(!empty($this->url) ? "'".$this->db->escape($this->url)."'" : "null");
809 $sql .= ", socialnetworks = ".($this->socialnetworks ? "'".$this->db->escape(json_encode($this->socialnetworks))."'" : "null");
810 $sql .= ", phone = ".($this->phone ? "'".$this->db->escape($this->phone)."'" : "null");
811 $sql .= ", phone_perso = ".($this->phone_perso ? "'".$this->db->escape($this->phone_perso)."'" : "null");
812 $sql .= ", phone_mobile = ".($this->phone_mobile ? "'".$this->db->escape($this->phone_mobile)."'" : "null");
813 $sql .= ", note_private = ".($this->note_private ? "'".$this->db->escape($this->note_private)."'" : "null");
814 $sql .= ", note_public = ".($this->note_public ? "'".$this->db->escape($this->note_public)."'" : "null");
815 $sql .= ", photo = ".($this->photo ? "'".$this->db->escape($this->photo)."'" : "null");
816 $sql .= ", public = ".(int) $this->public;
817 $sql .= ", statut = ".(int) $this->statut;
818 $sql .= ", default_lang = ".(!empty($this->default_lang) ? "'".$this->db->escape($this->default_lang)."'" : "null");
819 $sql .= ", fk_adherent_type = ".(int) $this->typeid;
820 $sql .= ", morphy = '".$this->db->escape($this->morphy)."'";
821 $sql .= ", birth = ".($this->birth ? "'".$this->db->idate($this->birth)."'" : "null");
822
823 if ($this->datefin) {
824 $sql .= ", datefin = '".$this->db->idate($this->datefin)."'"; // Must be modified only when deleting a subscription
825 }
826 if ($this->datevalid) {
827 $sql .= ", datevalid = '".$this->db->idate($this->datevalid)."'"; // Must be modified only when validating a member
828 }
829 $sql .= ", fk_user_mod = ".($user->id > 0 ? $user->id : 'null'); // Can be null because member can be create by a guest
830 $sql .= " WHERE rowid = ".((int) $this->id);
831
832 // If we change the type of membership, we set also label of new type..
833 '@phan-var-force Adherent $oldcopy';
834 if (!empty($this->oldcopy) && $this->typeid != $this->oldcopy->typeid) {
835 $sql2 = "SELECT libelle as label";
836 $sql2 .= " FROM ".MAIN_DB_PREFIX."adherent_type";
837 $sql2 .= " WHERE rowid = ".((int) $this->typeid);
838 $resql2 = $this->db->query($sql2);
839 if ($resql2) {
840 while ($obj = $this->db->fetch_object($resql2)) {
841 $this->type = $obj->label;
842 }
843 }
844 }
845
846 dol_syslog(get_class($this)."::update update member", LOG_DEBUG);
847 $resql = $this->db->query($sql);
848 if ($resql) {
849 unset($this->country_code);
850 unset($this->country);
851 unset($this->state_code);
852 unset($this->state);
853
854 $nbrowsaffected += $this->db->affected_rows($resql);
855
856 $action = 'update';
857
858 // Actions on extra fields
859 if (!$error) {
860 $result = $this->insertExtraFields();
861 if ($result < 0) {
862 $error++;
863 }
864 }
865
866 // Update password
867 if (!$error && $this->pass) {
868 dol_syslog(get_class($this)."::update update password");
869 if ($this->pass != $this->pass_indatabase && $this->pass != $this->pass_indatabase_crypted) {
870 $isencrypted = getDolGlobalString('DATABASE_PWD_ENCRYPTED') ? 1 : 0;
871
872 // If password to set differs from the one found into database
873 $result = $this->setPassword($user, $this->pass, $isencrypted, $notrigger, $nosyncuserpass);
874 if (!$nbrowsaffected) {
875 $nbrowsaffected++;
876 }
877 }
878 }
879
880 // Remove links to user and replace with new one
881 if (!$error) {
882 dol_syslog(get_class($this)."::update update link to user");
883 $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = NULL WHERE fk_member = ".((int) $this->id);
884 dol_syslog(get_class($this)."::update", LOG_DEBUG);
885 $resql = $this->db->query($sql);
886 if (!$resql) {
887 $this->error = $this->db->error();
888 $this->db->rollback();
889 return -5;
890 }
891 // If there is a user linked to this member
892 if ($this->user_id > 0) {
893 $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = ".((int) $this->id)." WHERE rowid = ".((int) $this->user_id);
894 dol_syslog(get_class($this)."::update", LOG_DEBUG);
895 $resql = $this->db->query($sql);
896 if (!$resql) {
897 $this->error = $this->db->error();
898 $this->db->rollback();
899 return -5;
900 }
901 }
902 }
903
904 if (!$error && $nbrowsaffected) { // If something has change in main data
905 // Update information on linked user if it is an update
906 if (!$error && $this->user_id > 0 && !$nosyncuser) {
907 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
908
909 dol_syslog(get_class($this)."::update update linked user");
910
911 $luser = new User($this->db);
912 $result = $luser->fetch($this->user_id);
913
914 if ($result >= 0) {
915 //var_dump($this->user_login);exit;
916 //var_dump($this->login);exit;
917
918 // 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.
919 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
920 $luser->login = $this->login;
921 }
922
923 $luser->ref = $this->ref;
924 $luser->civility_id = $this->civility_id;
925 $luser->firstname = $this->firstname;
926 $luser->lastname = $this->lastname;
927 $luser->gender = $this->gender;
928 $luser->pass = $this->pass;
929 //$luser->socid=$this->fk_soc; // We do not enable this. This may transform a user into an external user.
930
931 $luser->birth = $this->birth;
932
933 $luser->address = $this->address;
934 $luser->zip = $this->zip;
935 $luser->town = $this->town;
936 $luser->country_id = $this->country_id;
937 $luser->state_id = $this->state_id;
938
939 $luser->email = $this->email;
940 $luser->socialnetworks = $this->socialnetworks;
941 $luser->office_phone = $this->phone;
942 $luser->user_mobile = $this->phone_mobile;
943
944 $luser->lang = $this->default_lang;
945
946 $luser->fk_member = $this->id;
947
948 $result = $luser->update($user, 0, 1, 1); // Use nosync to 1 to avoid cyclic updates
949 if ($result < 0) {
950 $this->error = $luser->error;
951 dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
952 $error++;
953 }
954 } else {
955 $this->error = $luser->error;
956 $error++;
957 }
958 }
959
960 // Update information on linked thirdparty if it is an update
961 if (!$error && $this->fk_soc > 0 && !$nosyncthirdparty) {
962 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
963
964 dol_syslog(get_class($this)."::update update linked thirdparty");
965
966 // This member is linked with a thirdparty, so we also update thirdparty information
967 // if this is an update.
968 $lthirdparty = new Societe($this->db);
969 $result = $lthirdparty->fetch($this->fk_soc);
970
971 if ($result > 0) {
972 $lthirdparty->address = $this->address;
973 $lthirdparty->zip = $this->zip;
974 $lthirdparty->town = $this->town;
975 $lthirdparty->email = $this->email;
976 $lthirdparty->socialnetworks = $this->socialnetworks;
977 $lthirdparty->phone = $this->phone;
978 $lthirdparty->state_id = $this->state_id;
979 $lthirdparty->country_id = $this->country_id;
980 //$lthirdparty->phone_mobile=$this->phone_mobile;
981 $lthirdparty->default_lang = $this->default_lang;
982
983 $result = $lthirdparty->update($this->fk_soc, $user, 0, 1, 1, 'update'); // Use sync to 0 to avoid cyclic updates
984
985 if ($result < 0) {
986 $this->error = $lthirdparty->error;
987 $this->errors = $lthirdparty->errors;
988 dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
989 $error++;
990 }
991 } elseif ($result < 0) {
992 $this->error = $lthirdparty->error;
993 $error++;
994 }
995 }
996 }
997
998 if (!$error && !$notrigger) {
999 // Call trigger
1000 $result = $this->call_trigger('MEMBER_MODIFY', $user);
1001 if ($result < 0) {
1002 $error++;
1003 }
1004 // End call triggers
1005 }
1006
1007 if (!$error) {
1008 $this->db->commit();
1009 return $nbrowsaffected;
1010 } else {
1011 $this->db->rollback();
1012 return -1;
1013 }
1014 } else {
1015 $this->db->rollback();
1016 $this->error = $this->db->lasterror();
1017 return -2;
1018 }
1019 }
1020
1021
1022 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1030 public function update_end_date($user)
1031 {
1032 // phpcs:enable
1033 $this->db->begin();
1034
1035 // Search for last subscription id and end date
1036 $sql = "SELECT rowid, datec as dateop, dateadh as datedeb, datef as datefin";
1037 $sql .= " FROM ".MAIN_DB_PREFIX."subscription";
1038 $sql .= " WHERE fk_adherent = ".((int) $this->id);
1039 $sql .= " ORDER by dateadh DESC"; // Sort by start subscription date
1040
1041 dol_syslog(get_class($this)."::update_end_date", LOG_DEBUG);
1042 $resql = $this->db->query($sql);
1043 if ($resql) {
1044 $obj = $this->db->fetch_object($resql);
1045 $dateop = $this->db->jdate($obj->dateop);
1046 $datedeb = $this->db->jdate($obj->datedeb);
1047 $datefin = $this->db->jdate($obj->datefin);
1048
1049 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
1050 $sql .= " datefin=".($datefin != '' ? "'".$this->db->idate($datefin)."'" : "null");
1051 $sql .= " WHERE rowid = ".((int) $this->id);
1052
1053 dol_syslog(get_class($this)."::update_end_date", LOG_DEBUG);
1054 $resql = $this->db->query($sql);
1055 if ($resql) {
1056 $this->last_subscription_date = $dateop;
1057 $this->last_subscription_date_start = $datedeb;
1058 $this->last_subscription_date_end = $datefin;
1059 $this->datefin = $datefin;
1060 $this->db->commit();
1061 return 1;
1062 } else {
1063 $this->db->rollback();
1064 return -1;
1065 }
1066 } else {
1067 $this->error = $this->db->lasterror();
1068 $this->db->rollback();
1069 return -1;
1070 }
1071 }
1072
1080 public function delete($user, $notrigger = 0)
1081 {
1082 $result = 0;
1083 $error = 0;
1084 $errorflag = 0;
1085
1086 // Check parameters
1087 $rowid = $this->id;
1088
1089 $this->db->begin();
1090
1091 if (!$error && !$notrigger) {
1092 // Call trigger
1093 $result = $this->call_trigger('MEMBER_DELETE', $user);
1094 if ($result < 0) {
1095 $error++;
1096 }
1097 // End call triggers
1098 }
1099
1100 // Remove category
1101 $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_member WHERE fk_member = ".((int) $rowid);
1102 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1103 $resql = $this->db->query($sql);
1104 if (!$resql) {
1105 $error++;
1106 $this->error .= $this->db->lasterror();
1107 $errorflag = -1;
1108 }
1109
1110 // Remove subscription
1111 if (!$error) {
1112 $sql = "DELETE FROM ".MAIN_DB_PREFIX."subscription WHERE fk_adherent = ".((int) $rowid);
1113 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1114 $resql = $this->db->query($sql);
1115 if (!$resql) {
1116 $error++;
1117 $this->error .= $this->db->lasterror();
1118 $errorflag = -2;
1119 }
1120 }
1121
1122 // Remove linked user
1123 if (!$error) {
1124 $ret = $this->setUserId(0);
1125 if ($ret < 0) {
1126 $error++;
1127 $this->error .= $this->db->lasterror();
1128 $errorflag = -3;
1129 }
1130 }
1131
1132 // Removed extrafields
1133 if (!$error) {
1134 $result = $this->deleteExtraFields();
1135 if ($result < 0) {
1136 $error++;
1137 $errorflag = -4;
1138 dol_syslog(get_class($this)."::delete erreur ".$errorflag." ".$this->error, LOG_ERR);
1139 }
1140 }
1141
1142 // Remove adherent
1143 if (!$error) {
1144 $sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent WHERE rowid = ".((int) $rowid);
1145 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1146 $resql = $this->db->query($sql);
1147 if (!$resql) {
1148 $error++;
1149 $this->error .= $this->db->lasterror();
1150 $errorflag = -5;
1151 }
1152 }
1153
1154 if (!$error) {
1155 $this->db->commit();
1156 return 1;
1157 } else {
1158 $this->db->rollback();
1159 return $errorflag;
1160 }
1161 }
1162
1163
1174 public function setPassword($user, $password = '', $isencrypted = 0, $notrigger = 0, $nosyncuser = 0)
1175 {
1176 global $conf, $langs;
1177
1178 $error = 0;
1179
1180 dol_syslog(get_class($this)."::setPassword user=".$user->id." password=".preg_replace('/./i', '*', $password)." isencrypted=".$isencrypted);
1181
1182 // If new password not provided, we generate one
1183 if (!$password) {
1184 require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
1185 $password = getRandomPassword(false);
1186 }
1187
1188 // Crypt password
1189 $password_crypted = dol_hash($password);
1190
1191 $password_indatabase = '';
1192 if (!$isencrypted) {
1193 $password_indatabase = $password;
1194 }
1195
1196 $this->db->begin();
1197
1198 // Mise a jour
1199 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent";
1200 $sql .= " SET pass_crypted = '".$this->db->escape($password_crypted)."'";
1201 if ($isencrypted) {
1202 $sql .= ", pass = null";
1203 } else {
1204 $sql .= ", pass = '".$this->db->escape($password_indatabase)."'";
1205 }
1206 $sql .= " WHERE rowid = ".((int) $this->id);
1207
1208 //dol_syslog("Adherent::Password sql=hidden");
1209 dol_syslog(get_class($this)."::setPassword", LOG_DEBUG);
1210 $result = $this->db->query($sql);
1211 if ($result) {
1212 $nbaffectedrows = $this->db->affected_rows($result);
1213
1214 if ($nbaffectedrows) {
1215 $this->pass = $password;
1216 $this->pass_indatabase = $password_indatabase;
1217 $this->pass_indatabase_crypted = $password_crypted;
1218
1219 if ($this->user_id && !$nosyncuser) {
1220 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
1221
1222 // This member is linked with a user, so we also update users information
1223 // if this is an update.
1224 $luser = new User($this->db);
1225 $result = $luser->fetch($this->user_id);
1226
1227 if ($result >= 0) {
1228 $result = $luser->setPassword($user, $this->pass, 0, 0, 1);
1229 if (is_int($result) && $result < 0) {
1230 $this->error = $luser->error;
1231 dol_syslog(get_class($this)."::setPassword ".$this->error, LOG_ERR);
1232 $error++;
1233 }
1234 } else {
1235 $this->error = $luser->error;
1236 $error++;
1237 }
1238 }
1239
1240 if (!$error && !$notrigger) {
1241 // Call trigger
1242 $result = $this->call_trigger('MEMBER_NEW_PASSWORD', $user);
1243 if ($result < 0) {
1244 $error++;
1245 $this->db->rollback();
1246 return -1;
1247 }
1248 // End call triggers
1249 }
1250
1251 $this->db->commit();
1252 return $this->pass;
1253 } else {
1254 $this->db->rollback();
1255 return 0;
1256 }
1257 } else {
1258 $this->db->rollback();
1259 dol_print_error($this->db);
1260 return -1;
1261 }
1262 }
1263
1264
1271 public function setUserId($userid)
1272 {
1273 global $conf, $langs;
1274
1275 $this->db->begin();
1276
1277 // If user is linked to this member, remove old link to this member
1278 $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = NULL WHERE fk_member = ".((int) $this->id);
1279 dol_syslog(get_class($this)."::setUserId", LOG_DEBUG);
1280 $resql = $this->db->query($sql);
1281 if (!$resql) {
1282 $this->error = $this->db->error();
1283 $this->db->rollback();
1284 return -1;
1285 }
1286
1287 // Set link to user
1288 if ($userid > 0) {
1289 $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = ".((int) $this->id);
1290 $sql .= " WHERE rowid = ".((int) $userid);
1291 dol_syslog(get_class($this)."::setUserId", LOG_DEBUG);
1292 $resql = $this->db->query($sql);
1293 if (!$resql) {
1294 $this->error = $this->db->error();
1295 $this->db->rollback();
1296 return -2;
1297 }
1298 }
1299
1300 $this->db->commit();
1301
1302 return 1;
1303 }
1304
1305
1312 public function setThirdPartyId($thirdpartyid)
1313 {
1314 global $conf, $langs;
1315
1316 $this->db->begin();
1317
1318 // Remove link to third party onto any other members
1319 if ($thirdpartyid > 0) {
1320 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET fk_soc = null";
1321 $sql .= " WHERE fk_soc = ".((int) $thirdpartyid);
1322 $sql .= " AND entity = ".$conf->entity;
1323 dol_syslog(get_class($this)."::setThirdPartyId", LOG_DEBUG);
1324 $resql = $this->db->query($sql);
1325 }
1326
1327 // Add link to third party for current member
1328 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET fk_soc = ".($thirdpartyid > 0 ? (int) $thirdpartyid : 'null');
1329 $sql .= " WHERE rowid = ".((int) $this->id);
1330
1331 dol_syslog(get_class($this)."::setThirdPartyId", LOG_DEBUG);
1332 $resql = $this->db->query($sql);
1333 if ($resql) {
1334 $this->db->commit();
1335 return 1;
1336 } else {
1337 $this->error = $this->db->error();
1338 $this->db->rollback();
1339 return -1;
1340 }
1341 }
1342
1343
1344 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1351 public function fetch_login($login)
1352 {
1353 // phpcs:enable
1354 global $conf;
1355
1356 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."adherent";
1357 $sql .= " WHERE login='".$this->db->escape($login)."'";
1358 $sql .= " AND entity = ".$conf->entity;
1359
1360 $resql = $this->db->query($sql);
1361 if ($resql) {
1362 if ($this->db->num_rows($resql)) {
1363 $obj = $this->db->fetch_object($resql);
1364 $this->fetch($obj->rowid);
1365 }
1366 } else {
1367 dol_print_error($this->db);
1368 }
1369 }
1370
1371 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1379 public function fetch_name($firstname, $lastname)
1380 {
1381 // phpcs:enable
1382 global $conf;
1383
1384 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."adherent";
1385 $sql .= " WHERE firstname='".$this->db->escape($firstname)."'";
1386 $sql .= " AND lastname='".$this->db->escape($lastname)."'";
1387 $sql .= " AND entity = ".$conf->entity;
1388
1389 $resql = $this->db->query($sql);
1390 if ($resql) {
1391 if ($this->db->num_rows($resql)) {
1392 $obj = $this->db->fetch_object($resql);
1393 $this->fetch($obj->rowid);
1394 }
1395 } else {
1396 dol_print_error($this->db);
1397 }
1398 }
1399
1411 public function fetch($rowid, $ref = '', $fk_soc = 0, $ref_ext = '', $fetch_optionals = true, $fetch_subscriptions = true)
1412 {
1413 global $langs;
1414
1415 $sql = "SELECT d.rowid, d.ref, d.ref_ext, d.civility as civility_code, d.gender, d.firstname, d.lastname,";
1416 $sql .= " d.societe as company, d.fk_soc, d.statut, d.public, d.address, d.zip, d.town, d.note_private,";
1417 $sql .= " d.note_public,";
1418 $sql .= " d.email, d.url, d.socialnetworks, d.phone, d.phone_perso, d.phone_mobile, d.login, d.pass, d.pass_crypted,";
1419 $sql .= " d.photo, d.fk_adherent_type, d.morphy, d.entity,";
1420 $sql .= " d.datec as datec,";
1421 $sql .= " d.tms as datem,";
1422 $sql .= " d.datefin as datefin, d.default_lang,";
1423 $sql .= " d.birth as birthday,";
1424 $sql .= " d.datevalid as datev,";
1425 $sql .= " d.country,";
1426 $sql .= " d.state_id,";
1427 $sql .= " d.model_pdf,";
1428 $sql .= " c.rowid as country_id, c.code as country_code, c.label as country,";
1429 $sql .= " dep.nom as state, dep.code_departement as state_code,";
1430 $sql .= " t.libelle as type, t.subscription as subscription,";
1431 $sql .= " u.rowid as user_id, u.login as user_login";
1432 $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as t, ".MAIN_DB_PREFIX."adherent as d";
1433 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON d.country = c.rowid";
1434 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as dep ON d.state_id = dep.rowid";
1435 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON d.rowid = u.fk_member";
1436 $sql .= " WHERE d.fk_adherent_type = t.rowid";
1437 if ($rowid) {
1438 $sql .= " AND d.rowid=".((int) $rowid);
1439 } elseif ($ref || $fk_soc) {
1440 $sql .= " AND d.entity IN (".getEntity('adherent').")";
1441 if ($ref) {
1442 $sql .= " AND d.ref='".$this->db->escape($ref)."'";
1443 } elseif ($fk_soc > 0) {
1444 $sql .= " AND d.fk_soc=".((int) $fk_soc);
1445 }
1446 } elseif ($ref_ext) {
1447 $sql .= " AND d.ref_ext='".$this->db->escape($ref_ext)."'";
1448 }
1449
1450 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
1451 $resql = $this->db->query($sql);
1452 if ($resql) {
1453 if ($this->db->num_rows($resql)) {
1454 $obj = $this->db->fetch_object($resql);
1455
1456 $this->entity = $obj->entity;
1457 $this->id = $obj->rowid;
1458 $this->ref = $obj->ref;
1459 $this->ref_ext = $obj->ref_ext;
1460
1461 $this->civility_id = $obj->civility_code; // Bad. Kept for backward compatibility
1462 $this->civility_code = $obj->civility_code;
1463 $this->civility = $obj->civility_code ? ($langs->trans("Civility".$obj->civility_code) != "Civility".$obj->civility_code ? $langs->trans("Civility".$obj->civility_code) : $obj->civility_code) : '';
1464
1465 $this->firstname = $obj->firstname;
1466 $this->lastname = $obj->lastname;
1467 $this->gender = $obj->gender;
1468 $this->login = $obj->login;
1469 $this->societe = $obj->company;
1470 $this->company = $obj->company;
1471 $this->socid = $obj->fk_soc;
1472 $this->fk_soc = $obj->fk_soc; // For backward compatibility
1473 $this->address = $obj->address;
1474 $this->zip = $obj->zip;
1475 $this->town = $obj->town;
1476
1477 $this->pass = $obj->pass;
1478 $this->pass_indatabase = $obj->pass;
1479 $this->pass_indatabase_crypted = $obj->pass_crypted;
1480
1481 $this->state_id = $obj->state_id;
1482 $this->state_code = $obj->state_id ? $obj->state_code : '';
1483 $this->state = $obj->state_id ? $obj->state : '';
1484
1485 $this->country_id = $obj->country_id;
1486 $this->country_code = $obj->country_code;
1487 if ($langs->trans("Country".$obj->country_code) != "Country".$obj->country_code) {
1488 $this->country = $langs->transnoentitiesnoconv("Country".$obj->country_code);
1489 } else {
1490 $this->country = $obj->country;
1491 }
1492
1493 $this->phone = $obj->phone;
1494 $this->phone_perso = $obj->phone_perso;
1495 $this->phone_mobile = $obj->phone_mobile;
1496 $this->email = $obj->email;
1497 $this->url = $obj->url;
1498
1499 $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks, true) : array());
1500
1501 $this->photo = $obj->photo;
1502 $this->statut = $obj->statut;
1503 $this->status = $obj->statut;
1504 $this->public = $obj->public;
1505
1506 $this->datec = $this->db->jdate($obj->datec);
1507 $this->date_creation = $this->db->jdate($obj->datec);
1508 $this->datem = $this->db->jdate($obj->datem);
1509 $this->date_modification = $this->db->jdate($obj->datem);
1510 $this->datefin = $this->db->jdate($obj->datefin);
1511 $this->datevalid = $this->db->jdate($obj->datev);
1512 $this->date_validation = $this->db->jdate($obj->datev);
1513 $this->birth = $this->db->jdate($obj->birthday);
1514
1515 $this->default_lang = $obj->default_lang;
1516
1517 $this->note_private = $obj->note_private;
1518 $this->note_public = $obj->note_public;
1519 $this->morphy = $obj->morphy;
1520
1521 $this->typeid = $obj->fk_adherent_type;
1522 $this->type = $obj->type;
1523 $this->need_subscription = $obj->subscription;
1524
1525 $this->user_id = $obj->user_id;
1526 $this->user_login = $obj->user_login;
1527
1528 $this->model_pdf = $obj->model_pdf;
1529
1530 // Retrieve all extrafield
1531 // fetch optionals attributes and labels
1532 if ($fetch_optionals) {
1533 $this->fetch_optionals();
1534 }
1535
1536 // Load other properties
1537 if ($fetch_subscriptions) {
1538 $result = $this->fetch_subscriptions();
1539 }
1540
1541 return $this->id;
1542 } else {
1543 return 0;
1544 }
1545 } else {
1546 $this->error = $this->db->lasterror();
1547 return -1;
1548 }
1549 }
1550
1551
1552 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1561 public function fetch_subscriptions()
1562 {
1563 // phpcs:enable
1564 global $langs;
1565
1566 require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
1567
1568 $sql = "SELECT c.rowid, c.fk_adherent, c.fk_type, c.subscription, c.note as note_public, c.fk_bank,";
1569 $sql .= " c.tms as datem,";
1570 $sql .= " c.datec as datec,";
1571 $sql .= " c.dateadh as dateh,";
1572 $sql .= " c.datef as datef";
1573 $sql .= " FROM ".MAIN_DB_PREFIX."subscription as c";
1574 $sql .= " WHERE c.fk_adherent = ".((int) $this->id);
1575 $sql .= " ORDER BY c.dateadh";
1576 dol_syslog(get_class($this)."::fetch_subscriptions", LOG_DEBUG);
1577
1578 $resql = $this->db->query($sql);
1579 if ($resql) {
1580 $this->subscriptions = array();
1581
1582 $i = 0;
1583 while ($obj = $this->db->fetch_object($resql)) {
1584 if ($i == 0) {
1585 $this->first_subscription_date = $this->db->jdate($obj->datec);
1586 $this->first_subscription_date_start = $this->db->jdate($obj->dateh);
1587 $this->first_subscription_date_end = $this->db->jdate($obj->datef);
1588 $this->first_subscription_amount = $obj->subscription;
1589 }
1590 $this->last_subscription_date = $this->db->jdate($obj->datec);
1591 $this->last_subscription_date_start = $this->db->jdate($obj->dateh);
1592 $this->last_subscription_date_end = $this->db->jdate($obj->datef);
1593 $this->last_subscription_amount = $obj->subscription;
1594
1595 $subscription = new Subscription($this->db);
1596 $subscription->id = $obj->rowid;
1597 $subscription->fk_adherent = $obj->fk_adherent;
1598 $subscription->fk_type = $obj->fk_type;
1599 $subscription->amount = $obj->subscription;
1600 $subscription->note = $obj->note_public;
1601 $subscription->note_public = $obj->note_public;
1602 $subscription->fk_bank = $obj->fk_bank;
1603 $subscription->datem = $this->db->jdate($obj->datem);
1604 $subscription->datec = $this->db->jdate($obj->datec);
1605 $subscription->dateh = $this->db->jdate($obj->dateh);
1606 $subscription->datef = $this->db->jdate($obj->datef);
1607
1608 $this->subscriptions[] = $subscription;
1609
1610 $i++;
1611 }
1612 return 1;
1613 } else {
1614 $this->error = $this->db->error().' sql='.$sql;
1615 return -1;
1616 }
1617 }
1618
1619
1626 public function fetchPartnerships($mode)
1627 {
1628 global $langs;
1629
1630 require_once DOL_DOCUMENT_ROOT.'/partnership/class/partnership.class.php';
1631
1632
1633 $this->partnerships[] = array();
1634
1635 return 1;
1636 }
1637
1638
1654 public function subscription($date, $amount, $accountid = 0, $operation = '', $label = '', $num_chq = '', $emetteur_nom = '', $emetteur_banque = '', $datesubend = 0, $fk_type = null)
1655 {
1656 global $conf, $langs, $user;
1657
1658 require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
1659
1660 $error = 0;
1661
1662 // Clean parameters
1663 if (!$amount) {
1664 $amount = 0;
1665 }
1666
1667 $this->db->begin();
1668
1669 if ($datesubend) {
1670 $datefin = $datesubend;
1671 } else {
1672 // If no end date, end date = date + 1 year - 1 day
1673 $datefin = dol_time_plus_duree($date, 1, 'y');
1674 $datefin = dol_time_plus_duree($datefin, -1, 'd');
1675 }
1676
1677 // Create subscription
1678 $subscription = new Subscription($this->db);
1679 $subscription->fk_adherent = $this->id;
1680 $subscription->dateh = $date; // Date of new subscription
1681 $subscription->datef = $datefin; // End data of new subscription
1682 $subscription->amount = $amount;
1683 $subscription->note = $label; // deprecated
1684 $subscription->note_public = $label;
1685 $subscription->fk_type = $fk_type;
1686
1687 $rowid = $subscription->create($user);
1688 if ($rowid > 0) {
1689 // Update denormalized subscription end date (read database subscription to find values)
1690 // This will also update this->datefin
1691 $result = $this->update_end_date($user);
1692 if ($result > 0) {
1693 // Change properties of object (used by triggers)
1694 $this->last_subscription_date = dol_now();
1695 $this->last_subscription_date_start = $date;
1696 $this->last_subscription_date_end = $datefin;
1697 $this->last_subscription_amount = $amount;
1698 }
1699
1700 if (!$error) {
1701 $this->db->commit();
1702 return $rowid;
1703 } else {
1704 $this->db->rollback();
1705 return -2;
1706 }
1707 } else {
1708 $this->setErrorsFromObject($subscription);
1709 $this->db->rollback();
1710 return -1;
1711 }
1712 }
1713
1714
1734 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 = '')
1735 {
1736 global $conf, $langs, $user, $mysoc;
1737
1738 $error = 0;
1739
1740 $this->invoice = null; // This will contains invoice if an invoice is created
1741
1742 dol_syslog("subscriptionComplementaryActions subscriptionid=".$subscriptionid." option=".$option." accountid=".$accountid." datesubscription=".$datesubscription." paymentdate=".
1743 $paymentdate." label=".$label." amount=".$amount." num_chq=".$num_chq." autocreatethirdparty=".$autocreatethirdparty);
1744
1745 // Insert into bank account directlty (if option chosen for) + link to llx_subscription if option is 'bankdirect'
1746 if ($option == 'bankdirect' && $accountid) {
1747 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
1748
1749 $acct = new Account($this->db);
1750 $result = $acct->fetch($accountid);
1751
1752 $dateop = $paymentdate;
1753
1754 $insertid = $acct->addline($dateop, $operation, $label, $amount, $num_chq, 0, $user, $emetteur_nom, $emetteur_banque);
1755 if ($insertid > 0) {
1756 $inserturlid = $acct->add_url_line($insertid, $this->id, DOL_URL_ROOT.'/adherents/card.php?rowid=', $this->getFullName($langs), 'member');
1757 if ($inserturlid > 0) {
1758 // Update table subscription
1759 $sql = "UPDATE ".MAIN_DB_PREFIX."subscription SET fk_bank=".((int) $insertid);
1760 $sql .= " WHERE rowid=".((int) $subscriptionid);
1761
1762 dol_syslog("subscription::subscription", LOG_DEBUG);
1763 $resql = $this->db->query($sql);
1764 if (!$resql) {
1765 $error++;
1766 $this->error = $this->db->lasterror();
1767 $this->errors[] = $this->error;
1768 }
1769 } else {
1770 $error++;
1771 $this->setErrorsFromObject($acct);
1772 }
1773 } else {
1774 $error++;
1775 $this->setErrorsFromObject($acct);
1776 }
1777 }
1778
1779 // If option chosen, we create invoice
1780 if (($option == 'bankviainvoice' && $accountid) || $option == 'invoiceonly') {
1781 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1782 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/paymentterm.class.php';
1783
1784 $invoice = new Facture($this->db);
1785 $customer = new Societe($this->db);
1786
1787 if (!$error) {
1788 if (!($this->fk_soc > 0)) { // If not yet linked to a company
1789 if ($autocreatethirdparty) {
1790 // Create a linked thirdparty to member
1791 $companyalias = '';
1792 $fullname = $this->getFullName($langs);
1793
1794 if ($this->morphy == 'mor') {
1795 $companyname = $this->company;
1796 if (!empty($fullname)) {
1797 $companyalias = $fullname;
1798 }
1799 } else {
1800 $companyname = $fullname;
1801 if (!empty($this->company)) {
1802 $companyalias = $this->company;
1803 }
1804 }
1805
1806 $result = $customer->create_from_member($this, $companyname, $companyalias);
1807 if ($result < 0) {
1808 $this->error = $customer->error;
1809 $this->errors = $customer->errors;
1810 $error++;
1811 } else {
1812 $this->fk_soc = $result;
1813 }
1814 } else {
1815 $langs->load("errors");
1816 $this->error = $langs->trans("ErrorMemberNotLinkedToAThirpartyLinkOrCreateFirst");
1817 $this->errors[] = $this->error;
1818 $error++;
1819 }
1820 }
1821 }
1822 if (!$error) {
1823 $result = $customer->fetch($this->fk_soc);
1824 if ($result <= 0) {
1825 $this->error = $customer->error;
1826 $this->errors = $customer->errors;
1827 $error++;
1828 }
1829 }
1830
1831 if (!$error) {
1832 // Create draft invoice
1833 $invoice->type = Facture::TYPE_STANDARD;
1834 $invoice->cond_reglement_id = $customer->cond_reglement_id;
1835 if (empty($invoice->cond_reglement_id)) {
1836 $paymenttermstatic = new PaymentTerm($this->db);
1837 $invoice->cond_reglement_id = $paymenttermstatic->getDefaultId();
1838 if (empty($invoice->cond_reglement_id)) {
1839 $error++;
1840 $this->error = 'ErrorNoPaymentTermRECEPFound';
1841 $this->errors[] = $this->error;
1842 }
1843 }
1844 $invoice->socid = $this->fk_soc;
1845 // set customer's payment bank account on the invoice
1846 if (!empty($customer->fk_account)) {
1847 $invoice->fk_account = $customer->fk_account;
1848 } elseif (getDolGlobalString('FACTURE_RIB_NUMBER')) {
1849 // set default bank account from invoice module settings
1850 $invoice->fk_account = (int) getDolGlobalString('FACTURE_RIB_NUMBER');
1851 }
1852 //set customer's payment method on the invoice
1853 if (!empty($customer->mode_reglement_id)) {
1854 $invoice->mode_reglement_id = $customer->mode_reglement_id;
1855 }
1856 //$invoice->date = $datesubscription;
1857 $invoice->date = dol_now();
1858
1859 // Possibility to add external linked objects with hooks
1860 $invoice->linked_objects['subscription'] = $subscriptionid;
1861 if (GETPOSTISARRAY('other_linked_objects')) {
1862 $invoice->linked_objects = array_merge($invoice->linked_objects, GETPOST('other_linked_objects', 'array:int'));
1863 }
1864
1865 $result = $invoice->create($user);
1866 if ($result <= 0) {
1867 $this->error = $invoice->error;
1868 $this->errors = $invoice->errors;
1869 $error++;
1870 } else {
1871 $this->invoice = $invoice;
1872 }
1873 }
1874
1875 if (!$error) {
1876 // Add line to draft invoice
1877 $idprodsubscription = 0;
1878 if (getDolGlobalString('ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS') && (isModEnabled("product") || isModEnabled("service"))) {
1879 $idprodsubscription = getDolGlobalString('ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS');
1880 }
1881
1882 $vattouse = 0;
1883 if (getDolGlobalString('ADHERENT_VAT_FOR_SUBSCRIPTIONS') == 'defaultforfoundationcountry') {
1884 $vattouse = get_default_tva($mysoc, $mysoc, $idprodsubscription);
1885 }
1886 //print xx".$vattouse." - ".$mysoc." - ".$customer;exit;
1887 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1888 $result = $invoice->addline($label, 0, 1, $vattouse, 0, 0, $idprodsubscription, 0, $datesubscription, '', 0, 0, 0, 'TTC', $amount, 1);
1889 if ($result <= 0) {
1890 $this->error = $invoice->error;
1891 $this->errors = $invoice->errors;
1892 $error++;
1893 }
1894 }
1895
1896 if (!$error) {
1897 // Validate invoice
1898 $result = $invoice->validate($user);
1899 if ($result <= 0) {
1900 $this->error = $invoice->error;
1901 $this->errors = $invoice->errors;
1902 $error++;
1903 }
1904 }
1905
1906 if (!$error) {
1907 // TODO Link invoice with subscription ?
1908 }
1909
1910 // Add payment onto invoice
1911 if (!$error && $option == 'bankviainvoice' && $accountid) {
1912 require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
1913 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
1914 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
1915
1916 $amounts = array();
1917 $amounts[$invoice->id] = (float) price2num($amount);
1918
1919 $paiement = new Paiement($this->db);
1920 $paiement->datepaye = $paymentdate;
1921 $paiement->amounts = $amounts;
1922 $paiement->paiementcode = $operation;
1923 $paiement->paiementid = dol_getIdFromCode($this->db, $operation, 'c_paiement', 'code', 'id', 1);
1924 $paiement->num_payment = $num_chq;
1925 $paiement->note_public = $label;
1926 $paiement->ext_payment_id = $ext_payment_id;
1927 $paiement->ext_payment_site = $ext_payment_site;
1928
1929 if (!$error) {
1930 // Create payment line for invoice
1931 $paiement_id = $paiement->create($user);
1932 if (!($paiement_id > 0)) {
1933 $this->error = $paiement->error;
1934 $this->errors = $paiement->errors;
1935 $error++;
1936 }
1937 }
1938
1939 if (!$error) {
1940 // Add transaction into bank account
1941 $bank_line_id = $paiement->addPaymentToBank($user, 'payment', '(SubscriptionPayment)', $accountid, $emetteur_nom, $emetteur_banque);
1942 if (!($bank_line_id > 0)) {
1943 $this->error = $paiement->error;
1944 $this->errors = $paiement->errors;
1945 $error++;
1946 }
1947 }
1948
1949 if (!$error && !empty($bank_line_id)) {
1950 // Update fk_bank into subscription table
1951 $sql = 'UPDATE '.MAIN_DB_PREFIX.'subscription SET fk_bank='.((int) $bank_line_id);
1952 $sql .= ' WHERE rowid='.((int) $subscriptionid);
1953
1954 $result = $this->db->query($sql);
1955 if (!$result) {
1956 $error++;
1957 }
1958 }
1959
1960 if (!$error) {
1961 // Set invoice as paid
1962 $invoice->setPaid($user);
1963 }
1964 }
1965
1966 if (!$error) {
1967 // Define output language
1968 $outputlangs = $langs;
1969 $newlang = '';
1970 $lang_id = GETPOST('lang_id');
1971 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && !empty($lang_id)) {
1972 $newlang = $lang_id;
1973 }
1974 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
1975 $newlang = $customer->default_lang;
1976 }
1977 if (!empty($newlang)) {
1978 $outputlangs = new Translate("", $conf);
1979 $outputlangs->setDefaultLang($newlang);
1980 }
1981 // Generate PDF (whatever is option MAIN_DISABLE_PDF_AUTOUPDATE) so we can include it into email
1982 //if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE'))
1983
1984 $invoice->generateDocument($invoice->model_pdf, $outputlangs);
1985 }
1986 }
1987
1988 if ($error) {
1989 return -1;
1990 } else {
1991 return 1;
1992 }
1993 }
1994
1995
2002 public function validate($user)
2003 {
2004 global $langs, $conf;
2005
2006 $error = 0;
2007 $now = dol_now();
2008
2009 // Check parameters
2010 if ($this->statut == self::STATUS_VALIDATED) {
2011 dol_syslog(get_class($this)."::validate statut of member does not allow this", LOG_WARNING);
2012 return 0;
2013 }
2014
2015 $this->db->begin();
2016
2017 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
2018 $sql .= " statut = ".self::STATUS_VALIDATED;
2019 $sql .= ", datevalid = '".$this->db->idate($now)."'";
2020 $sql .= ", fk_user_valid = ".((int) $user->id);
2021 $sql .= " WHERE rowid = ".((int) $this->id);
2022
2023 dol_syslog(get_class($this)."::validate", LOG_DEBUG);
2024 $result = $this->db->query($sql);
2025 if ($result) {
2026 $this->statut = self::STATUS_VALIDATED;
2027
2028 // Call trigger
2029 $result = $this->call_trigger('MEMBER_VALIDATE', $user);
2030 if ($result < 0) {
2031 $error++;
2032 $this->db->rollback();
2033 return -1;
2034 }
2035 // End call triggers
2036
2037 $this->datevalid = $now;
2038
2039 $this->db->commit();
2040 return 1;
2041 } else {
2042 $this->error = $this->db->error();
2043 $this->db->rollback();
2044 return -1;
2045 }
2046 }
2047
2048
2055 public function resiliate($user)
2056 {
2057 global $langs, $conf;
2058
2059 $error = 0;
2060
2061 // Check parameters
2062 if ($this->statut == self::STATUS_RESILIATED) {
2063 dol_syslog(get_class($this)."::resiliate statut of member does not allow this", LOG_WARNING);
2064 return 0;
2065 }
2066
2067 $this->db->begin();
2068
2069 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
2070 $sql .= " statut = ".self::STATUS_RESILIATED;
2071 $sql .= ", fk_user_valid=".$user->id;
2072 $sql .= " WHERE rowid = ".((int) $this->id);
2073
2074 $result = $this->db->query($sql);
2075 if ($result) {
2076 $this->statut = self::STATUS_RESILIATED;
2077
2078 // Call trigger
2079 $result = $this->call_trigger('MEMBER_RESILIATE', $user);
2080 if ($result < 0) {
2081 $error++;
2082 $this->db->rollback();
2083 return -1;
2084 }
2085 // End call triggers
2086
2087 $this->db->commit();
2088 return 1;
2089 } else {
2090 $this->error = $this->db->error();
2091 $this->db->rollback();
2092 return -1;
2093 }
2094 }
2095
2105 public function exclude($user)
2106 {
2107 $error = 0;
2108
2109 // Check parameters
2110 if ($this->statut == self::STATUS_EXCLUDED) {
2111 dol_syslog(get_class($this)."::resiliate statut of member does not allow this", LOG_WARNING);
2112 return 0;
2113 }
2114
2115 $this->db->begin();
2116
2117 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
2118 $sql .= " statut = ".self::STATUS_EXCLUDED;
2119 $sql .= ", fk_user_valid=".$user->id;
2120 $sql .= " WHERE rowid = ".((int) $this->id);
2121
2122 $result = $this->db->query($sql);
2123 if ($result) {
2124 $this->statut = self::STATUS_EXCLUDED;
2125
2126 // Call trigger
2127 $result = $this->call_trigger('MEMBER_EXCLUDE', $user);
2128 if ($result < 0) {
2129 $error++;
2130 $this->db->rollback();
2131 return -1;
2132 }
2133 // End call triggers
2134
2135 $this->db->commit();
2136 return 1;
2137 } else {
2138 $this->error = $this->db->error();
2139 $this->db->rollback();
2140 return -1;
2141 }
2142 }
2143
2144 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2150 public function add_to_abo()
2151 {
2152 // phpcs:enable
2153 global $langs;
2154
2155 include_once DOL_DOCUMENT_ROOT.'/mailmanspip/class/mailmanspip.class.php';
2156 $mailmanspip = new MailmanSpip($this->db);
2157
2158 $err = 0;
2159
2160 // mailman
2161 if (getDolGlobalString('ADHERENT_USE_MAILMAN') && isModEnabled('mailmanspip')) {
2162 $result = $mailmanspip->add_to_mailman($this);
2163
2164 if ($result < 0) {
2165 if (!empty($mailmanspip->error)) {
2166 $this->errors[] = $mailmanspip->error;
2167 }
2168 $err += 1;
2169 }
2170 foreach ($mailmanspip->mladded_ko as $tmplist => $tmpemail) {
2171 $langs->load("errors");
2172 $this->errors[] = $langs->trans("ErrorFailedToAddToMailmanList", $tmpemail, $tmplist);
2173 }
2174 foreach ($mailmanspip->mladded_ok as $tmplist => $tmpemail) {
2175 $langs->load("mailmanspip");
2176 $this->mesgs[] = $langs->trans("SuccessToAddToMailmanList", $tmpemail, $tmplist);
2177 }
2178 }
2179
2180 // spip
2181 if (getDolGlobalString('ADHERENT_USE_SPIP') && isModEnabled('mailmanspip')) {
2182 $result = $mailmanspip->add_to_spip($this);
2183 if ($result < 0) {
2184 $this->errors[] = $mailmanspip->error;
2185 $err += 1;
2186 }
2187 }
2188 if ($err) {
2189 return -$err;
2190 } else {
2191 return 1;
2192 }
2193 }
2194
2195
2196 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2202 public function del_to_abo()
2203 {
2204 // phpcs:enable
2205 global $conf, $langs;
2206
2207 include_once DOL_DOCUMENT_ROOT.'/mailmanspip/class/mailmanspip.class.php';
2208 $mailmanspip = new MailmanSpip($this->db);
2209
2210 $err = 0;
2211
2212 // mailman
2213 if (getDolGlobalString('ADHERENT_USE_MAILMAN')) {
2214 $result = $mailmanspip->del_to_mailman($this);
2215 if ($result < 0) {
2216 if (!empty($mailmanspip->error)) {
2217 $this->errors[] = $mailmanspip->error;
2218 }
2219 $err += 1;
2220 }
2221
2222 foreach ($mailmanspip->mlremoved_ko as $tmplist => $tmpemail) {
2223 $langs->load("errors");
2224 $this->errors[] = $langs->trans("ErrorFailedToRemoveToMailmanList", $tmpemail, $tmplist);
2225 }
2226 foreach ($mailmanspip->mlremoved_ok as $tmplist => $tmpemail) {
2227 $langs->load("mailmanspip");
2228 $this->mesgs[] = $langs->trans("SuccessToRemoveToMailmanList", $tmpemail, $tmplist);
2229 }
2230 }
2231
2232 if (getDolGlobalString('ADHERENT_USE_SPIP') && isModEnabled('mailmanspip')) {
2233 $result = $mailmanspip->del_to_spip($this);
2234 if ($result < 0) {
2235 $this->errors[] = $mailmanspip->error;
2236 $err += 1;
2237 }
2238 }
2239 if ($err) {
2240 // error
2241 return -$err;
2242 } else {
2243 return 1;
2244 }
2245 }
2246
2247
2253 public function getCivilityLabel()
2254 {
2255 global $langs;
2256 $langs->load("dict");
2257
2258 $code = (empty($this->civility_id) ? '' : $this->civility_id);
2259 if (empty($code)) {
2260 return '';
2261 }
2262 return $langs->getLabelFromKey($this->db, "Civility".$code, "c_civility", "code", "label", $code);
2263 }
2264
2271 public function getTooltipContentArray($params)
2272 {
2273 global $langs;
2274
2275 $langs->loadLangs(['members', 'companies']);
2276 $nofetch = !empty($params['nofetch']);
2277
2278 $datas = array();
2279
2280 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
2281 $langs->load("users");
2282 return ['optimize' => $langs->trans("ShowUser")];
2283 }
2284 if (!empty($this->photo)) {
2285 $photo = '<div class="photointooltip floatright">';
2286 $photo .= Form::showphoto('memberphoto', $this, 80, 0, 0, 'photoref photowithmargin photologintooltip', 'small', 0, 1);
2287 $photo .= '</div>';
2288 $datas['photo'] = $photo;
2289 }
2290
2291 $datas['divopen'] = '<div class="centpercent">';
2292 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Member").'</u> '.$this->getLibStatut(4);
2293 if (!empty($this->morphy)) {
2294 $datas['picto'] .= '&nbsp;' . $this->getmorphylib('', 1);
2295 }
2296 if (!empty($this->ref)) {
2297 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
2298 }
2299 if (!empty($this->login)) {
2300 $datas['login'] = '<br><b>'.$langs->trans('Login').':</b> '.$this->login;
2301 }
2302 if (!empty($this->firstname) || !empty($this->lastname)) {
2303 $datas['name'] = '<br><b>'.$langs->trans('Name').':</b> '.$this->getFullName($langs);
2304 }
2305 if (!empty($this->company)) {
2306 $datas['company'] = '<br><b>'.$langs->trans('Company').':</b> '.$this->company;
2307 }
2308 if (!empty($this->email)) {
2309 $datas['email'] = '<br><b>'.$langs->trans("EMail").':</b> '.$this->email;
2310 }
2311 $datas['address'] = '<br><b>'.$langs->trans("Address").':</b> '.dol_format_address($this, 1, ' ', $langs);
2312 // show categories for this record only in ajax to not overload lists
2313 if (isModEnabled('category') && !$nofetch) {
2314 require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
2315 $form = new Form($this->db);
2316 $datas['categories'] = '<br>' . $form->showCategories($this->id, Categorie::TYPE_MEMBER, 1);
2317 }
2318 $datas['divclose'] = '</div>';
2319
2320 return $datas;
2321 }
2322
2336 public function getNomUrl($withpictoimg = 0, $maxlen = 0, $option = 'card', $mode = '', $morecss = '', $save_lastsearch_value = -1, $notooltip = 0, $addlinktonotes = 0)
2337 {
2338 global $conf, $langs, $hookmanager;
2339
2340 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') && $withpictoimg) {
2341 $withpictoimg = 0;
2342 }
2343
2344 $result = '';
2345 $linkstart = '';
2346 $linkend = '';
2347 $classfortooltip = 'classfortooltip';
2348 $dataparams = '';
2349 $params = [
2350 'id' => $this->id,
2351 'objecttype' => $this->element,
2352 'option' => $option,
2353 'nofetch' => 1,
2354 ];
2355 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
2356 $classfortooltip = 'classforajaxtooltip';
2357 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
2358 $label = '';
2359 } else {
2360 $label = implode($this->getTooltipContentArray($params));
2361 }
2362
2363 $url = DOL_URL_ROOT.'/adherents/card.php?rowid='.((int) $this->id);
2364 if ($option == 'subscription') {
2365 $url = DOL_URL_ROOT.'/adherents/subscription.php?rowid='.((int) $this->id);
2366 }
2367
2368 if ($option != 'nolink') {
2369 // Add param to save lastsearch_values or not
2370 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2371 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
2372 $add_save_lastsearch_values = 1;
2373 }
2374 if ($add_save_lastsearch_values) {
2375 $url .= '&save_lastsearch_values=1';
2376 }
2377 }
2378
2379 $linkstart .= '<a href="'.$url.'"';
2380 $linkclose = "";
2381 if (empty($notooltip)) {
2382 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
2383 $langs->load("users");
2384 $label = $langs->trans("ShowUser");
2385 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
2386 }
2387 $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
2388 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
2389 }
2390
2391 $linkstart .= $linkclose.'>';
2392 $linkend = '</a>';
2393
2394 $result .= $linkstart;
2395
2396 if ($withpictoimg) {
2397 $paddafterimage = '';
2398 if (abs($withpictoimg) == 1 || abs($withpictoimg) == 4) {
2399 $morecss .= ' paddingrightonly';
2400 }
2401 // Only picto
2402 if ($withpictoimg > 0) {
2403 $picto = '<span class="nopadding'.($morecss ? ' userimg'.$morecss : '').'">'.img_object('', 'user', $paddafterimage.' '.($notooltip ? '' : $dataparams), 0, 0, $notooltip ? 0 : 1).'</span>';
2404 } else {
2405 // Picto must be a photo
2406 $picto = '<span class="nopadding'.($morecss ? ' userimg'.$morecss : '').'"'.($paddafterimage ? ' '.$paddafterimage : '').'>';
2407 $picto .= Form::showphoto('memberphoto', $this, 0, 0, 0, 'userphoto'.(($withpictoimg == -3 || $withpictoimg == -4) ? 'small' : ''), 'mini', 0, 1);
2408 $picto .= '</span>';
2409 }
2410 $result .= $picto;
2411 }
2412 if (($withpictoimg > -2 && $withpictoimg != 2) || $withpictoimg == -4) {
2413 if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
2414 $result .= '<span class="nopadding valignmiddle'.((!isset($this->statut) || $this->statut) ? '' : ' strikefordisabled').
2415 ($morecss ? ' usertext'.$morecss : '').'">';
2416 }
2417 if ($mode == 'login') {
2418 $result .= dol_trunc($this->login, $maxlen);
2419 } elseif ($mode == 'ref') {
2420 $result .= $this->ref;
2421 } else {
2422 $result .= $this->getFullName($langs, 0, ($mode == 'firstname' ? 2 : ($mode == 'lastname' ? 4 : -1)), $maxlen);
2423 }
2424 if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
2425 $result .= '</span>';
2426 }
2427 }
2428
2429 $result .= $linkend;
2430
2431 if ($addlinktonotes) {
2432 if ($this->note_private) {
2433 $notetoshow = $langs->trans("ViewPrivateNote").':<br>'.dol_string_nohtmltag($this->note_private, 1);
2434 $result .= ' <span class="note inline-block">';
2435 $result .= '<a href="'.DOL_URL_ROOT.'/adherents/note.php?id='.$this->id.'" class="classfortooltip" title="'.dol_escape_htmltag($notetoshow).'">';
2436 $result .= img_picto('', 'note');
2437 $result .= '</a>';
2438 $result .= '</span>';
2439 }
2440 }
2441 global $action;
2442 $hookmanager->initHooks(array($this->element . 'dao'));
2443 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
2444 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
2445 if ($reshook > 0) {
2446 $result = $hookmanager->resPrint;
2447 } else {
2448 $result .= $hookmanager->resPrint;
2449 }
2450 return $result;
2451 }
2452
2459 public function getLibStatut($mode = 0)
2460 {
2461 return $this->LibStatut($this->statut, $this->need_subscription, $this->datefin, $mode);
2462 }
2463
2464 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2474 public function LibStatut($status, $need_subscription, $date_end_subscription, $mode = 0)
2475 {
2476 // phpcs:enable
2477 global $langs;
2478 $langs->load("members");
2479
2480 $statusType = '';
2481 $labelStatus = '';
2482 $labelStatusShort = '';
2483
2484 if ($status == self::STATUS_DRAFT) {
2485 $statusType = 'status0';
2486 $labelStatus = $langs->trans("MemberStatusDraft");
2487 $labelStatusShort = $langs->trans("MemberStatusDraftShort");
2488 } elseif ($status >= self::STATUS_VALIDATED) {
2489 if ($need_subscription === 0) {
2490 $statusType = 'status4';
2491 $labelStatus = $langs->trans("Validated").' - '.$langs->trans("MemberStatusNoSubscription");
2492 $labelStatusShort = $langs->trans("MemberStatusNoSubscriptionShort");
2493 } elseif (!$date_end_subscription) {
2494 $statusType = 'status1';
2495 $labelStatus = $langs->trans("Validated").' - '.$langs->trans("WaitingSubscription");
2496 $labelStatusShort = $langs->trans("WaitingSubscriptionShort");
2497 } elseif ($date_end_subscription < dol_now()) { // expired
2498 $statusType = 'status8';
2499 $labelStatus = $langs->trans("Validated").' - '.$langs->trans("MemberStatusActiveLate");
2500 $labelStatusShort = $langs->trans("MemberStatusActiveLateShort");
2501 } else {
2502 $statusType = 'status4';
2503 $labelStatus = $langs->trans("Validated").' - '.$langs->trans("MemberStatusPaid");
2504 $labelStatusShort = $langs->trans("MemberStatusPaidShort");
2505 }
2506 } elseif ($status == self::STATUS_RESILIATED) {
2507 $statusType = 'status6';
2508 $labelStatus = $langs->transnoentitiesnoconv("MemberStatusResiliated");
2509 $labelStatusShort = $langs->transnoentitiesnoconv("MemberStatusResiliatedShort");
2510 } elseif ($status == self::STATUS_EXCLUDED) {
2511 $statusType = 'status10';
2512 $labelStatus = $langs->transnoentitiesnoconv("MemberStatusExcluded");
2513 $labelStatusShort = $langs->transnoentitiesnoconv("MemberStatusExcludedShort");
2514 }
2515
2516 return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode);
2517 }
2518
2519
2525 public function loadStateBoard()
2526 {
2527 global $conf;
2528
2529 $this->nb = array();
2530
2531 $sql = "SELECT count(a.rowid) as nb";
2532 $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a";
2533 $sql .= " WHERE a.statut > 0";
2534 $sql .= " AND a.entity IN (".getEntity('adherent').")";
2535
2536 $resql = $this->db->query($sql);
2537 if ($resql) {
2538 while ($obj = $this->db->fetch_object($resql)) {
2539 $this->nb["members"] = $obj->nb;
2540 }
2541 $this->db->free($resql);
2542 return 1;
2543 } else {
2544 dol_print_error($this->db);
2545 $this->error = $this->db->error();
2546 return -1;
2547 }
2548 }
2549
2550 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2558 public function load_board($user, $mode)
2559 {
2560 // phpcs:enable
2561 global $conf, $langs;
2562
2563 if ($user->socid) {
2564 return -1; // protection pour eviter appel par utilisateur externe
2565 }
2566
2567 $now = dol_now();
2568
2569 $sql = "SELECT a.rowid, a.datefin, a.statut";
2570 $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a";
2571 $sql .= ", ".MAIN_DB_PREFIX."adherent_type as t";
2572 $sql .= " WHERE a.fk_adherent_type = t.rowid";
2573 if ($mode == 'expired') {
2574 $sql .= " AND a.statut = ".self::STATUS_VALIDATED;
2575 $sql .= " AND a.entity IN (".getEntity('adherent').")";
2576 $sql .= " AND ((a.datefin IS NULL or a.datefin < '".$this->db->idate($now)."') AND t.subscription = '1')";
2577 } elseif ($mode == 'shift') {
2578 $sql .= " AND a.statut = ".self::STATUS_DRAFT;
2579 $sql .= " AND a.entity IN (".getEntity('adherent').")";
2580 }
2581
2582 $resql = $this->db->query($sql);
2583 if ($resql) {
2584 $langs->load("members");
2585
2586 $warning_delay = 0;
2587 $url = '';
2588 $label = '';
2589 $labelShort = '';
2590
2591 if ($mode == 'expired') {
2592 $warning_delay = $conf->adherent->subscription->warning_delay / 60 / 60 / 24;
2593 $label = $langs->trans("MembersWithSubscriptionToReceive");
2594 $labelShort = $langs->trans("MembersWithSubscriptionToReceiveShort");
2595 $url = DOL_URL_ROOT.'/adherents/list.php?mainmenu=members&amp;statut='.self::STATUS_VALIDATED.'&amp;filter=outofdate';
2596 } elseif ($mode == 'shift') {
2597 $warning_delay = $conf->adherent->subscription->warning_delay / 60 / 60 / 24;
2598 $url = DOL_URL_ROOT.'/adherents/list.php?mainmenu=members&amp;statut='.self::STATUS_DRAFT;
2599 $label = $langs->trans("MembersListToValid");
2600 $labelShort = $langs->trans("ToValidate");
2601 }
2602
2603 $response = new WorkboardResponse();
2604 $response->warning_delay = $warning_delay;
2605 $response->label = $label;
2606 $response->labelShort = $labelShort;
2607 $response->url = $url;
2608 $response->img = img_object('', "user");
2609
2610 $adherentstatic = new Adherent($this->db);
2611
2612 while ($obj = $this->db->fetch_object($resql)) {
2613 $response->nbtodo++;
2614
2615 $adherentstatic->datefin = $this->db->jdate($obj->datefin);
2616 $adherentstatic->statut = $obj->statut;
2617
2618 if ($adherentstatic->hasDelay()) {
2619 $response->nbtodolate++;
2620 }
2621 }
2622
2623 return $response;
2624 } else {
2625 dol_print_error($this->db);
2626 $this->error = $this->db->error();
2627 return -1;
2628 }
2629 }
2630
2631
2643 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
2644 {
2645 global $conf, $langs;
2646
2647 $langs->load("orders");
2648
2649 if (!dol_strlen($modele)) {
2650 $modele = 'standard';
2651
2652 if ($this->model_pdf) {
2653 $modele = $this->model_pdf;
2654 } elseif (getDolGlobalString('ADHERENT_ADDON_PDF')) {
2655 $modele = getDolGlobalString('ADHERENT_ADDON_PDF');
2656 }
2657 }
2658
2659 $modelpath = "core/modules/member/doc/";
2660
2661 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
2662 }
2663
2664
2672 public function initAsSpecimen()
2673 {
2674 global $user, $langs;
2675 $now = dol_now();
2676
2677 // Initialise parameters
2678 $this->id = 0;
2679 $this->ref = 'ABC001';
2680 $this->entity = 1;
2681 $this->specimen = 1;
2682 $this->civility_id = 'MR';
2683 $this->lastname = 'DOLIBARR';
2684 $this->firstname = 'SPECIMEN';
2685 $this->gender = 'man';
2686 $this->login = 'dolibspec';
2687 $this->pass = 'dolibspec';
2688 $this->company = 'Societe ABC';
2689 $this->address = '61 jump street';
2690 $this->zip = '75000';
2691 $this->town = 'Paris';
2692 $this->country_id = 1;
2693 $this->country_code = 'FR';
2694 $this->country = 'France';
2695 $this->morphy = 'mor';
2696 $this->email = 'specimen@specimen.com';
2697 $this->socialnetworks = array(
2698 'skype' => 'skypepseudo',
2699 'twitter' => 'twitterpseudo',
2700 'facebook' => 'facebookpseudo',
2701 'linkedin' => 'linkedinpseudo',
2702 );
2703 $this->phone = '0999999999';
2704 $this->phone_perso = '0999999998';
2705 $this->phone_mobile = '0999999997';
2706 $this->note_public = 'This is a public note';
2707 $this->note_private = 'This is a private note';
2708 $this->birth = $now;
2709 $this->photo = '';
2710 $this->public = 1;
2711 $this->statut = self::STATUS_DRAFT;
2712 $this->status = self::STATUS_DRAFT;
2713
2714 $this->datefin = $now;
2715 $this->datevalid = $now;
2716 $this->default_lang = '';
2717
2718 $this->typeid = 1; // Id type adherent
2719 $this->type = 'Type adherent'; // Libelle type adherent
2720 $this->need_subscription = 0;
2721
2722 $this->first_subscription_date = $now;
2723 $this->first_subscription_date_start = $this->first_subscription_date;
2724 $this->first_subscription_date_end = dol_time_plus_duree($this->first_subscription_date_start, 1, 'y');
2725 $this->first_subscription_amount = 10;
2726
2727 $this->last_subscription_date = $this->first_subscription_date;
2728 $this->last_subscription_date_start = $this->first_subscription_date;
2729 $this->last_subscription_date_end = dol_time_plus_duree($this->last_subscription_date_start, 1, 'y');
2730 $this->last_subscription_amount = 10;
2731 return 1;
2732 }
2733
2734
2735 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2736 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2746 public function _load_ldap_dn($info, $mode = 0)
2747 {
2748 // phpcs:enable
2749 global $conf;
2750 $dn = '';
2751 if ($mode == 0) {
2752 $dn = getDolGlobalString('LDAP_KEY_MEMBERS') . "=".$info[getDolGlobalString('LDAP_KEY_MEMBERS')]."," . getDolGlobalString('LDAP_MEMBER_DN');
2753 }
2754 if ($mode == 1) {
2755 $dn = getDolGlobalString('LDAP_MEMBER_DN');
2756 }
2757 if ($mode == 2) {
2758 $dn = getDolGlobalString('LDAP_KEY_MEMBERS') . "=".$info[getDolGlobalString('LDAP_KEY_MEMBERS')];
2759 }
2760 return $dn;
2761 }
2762
2763
2764 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2765 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2771 public function _load_ldap_info()
2772 {
2773 // phpcs:enable
2774 global $conf, $langs;
2775
2776 $info = array();
2777 $socialnetworks = getArrayOfSocialNetworks();
2778 $keymodified = false;
2779
2780 // Object classes
2781 $info["objectclass"] = explode(',', getDolGlobalString('LDAP_MEMBER_OBJECT_CLASS'));
2782
2783 $this->fullname = $this->getFullName($langs);
2784
2785 // For avoid ldap error when firstname and lastname are empty
2786 if ($this->morphy == 'mor' && (empty($this->fullname) || $this->fullname == $this->company)) {
2787 $this->fullname = $this->company;
2788 $this->lastname = $this->company;
2789 }
2790
2791 // Possible LDAP KEY (constname => varname)
2792 $ldapkey = array(
2793 'LDAP_MEMBER_FIELD_FULLNAME' => 'fullname',
2794 'LDAP_MEMBER_FIELD_NAME' => 'lastname',
2795 'LDAP_MEMBER_FIELD_LOGIN' => 'login',
2796 'LDAP_MEMBER_FIELD_LOGIN_SAMBA' => 'login',
2797 'LDAP_MEMBER_FIELD_MAIL' => 'email'
2798 );
2799
2800 // Member
2801 foreach ($ldapkey as $constname => $varname) {
2802 if (!empty($this->$varname) && getDolGlobalString($constname)) {
2803 $info[getDolGlobalString($constname)] = $this->$varname;
2804
2805 // Check if it is the LDAP key and if its value has been changed
2806 if (getDolGlobalString('LDAP_KEY_MEMBERS') && getDolGlobalString('LDAP_KEY_MEMBERS') == getDolGlobalString($constname)) {
2807 if (!empty($this->oldcopy) && $this->$varname != $this->oldcopy->$varname) {
2808 $keymodified = true; // For check if LDAP key has been modified
2809 }
2810 }
2811 }
2812 }
2813 if ($this->firstname && getDolGlobalString('LDAP_MEMBER_FIELD_FIRSTNAME')) {
2814 $info[getDolGlobalString('LDAP_MEMBER_FIELD_FIRSTNAME')] = $this->firstname;
2815 }
2816 if ($this->poste && getDolGlobalString('LDAP_MEMBER_FIELD_TITLE')) {
2817 $info[getDolGlobalString('LDAP_MEMBER_FIELD_TITLE')] = $this->poste;
2818 }
2819 if ($this->company && getDolGlobalString('LDAP_MEMBER_FIELD_COMPANY')) {
2820 $info[getDolGlobalString('LDAP_MEMBER_FIELD_COMPANY')] = $this->company;
2821 }
2822 if ($this->address && getDolGlobalString('LDAP_MEMBER_FIELD_ADDRESS')) {
2823 $info[getDolGlobalString('LDAP_MEMBER_FIELD_ADDRESS')] = $this->address;
2824 }
2825 if ($this->zip && getDolGlobalString('LDAP_MEMBER_FIELD_ZIP')) {
2826 $info[getDolGlobalString('LDAP_MEMBER_FIELD_ZIP')] = $this->zip;
2827 }
2828 if ($this->town && getDolGlobalString('LDAP_MEMBER_FIELD_TOWN')) {
2829 $info[getDolGlobalString('LDAP_MEMBER_FIELD_TOWN')] = $this->town;
2830 }
2831 if ($this->country_code && getDolGlobalString('LDAP_MEMBER_FIELD_COUNTRY')) {
2832 $info[getDolGlobalString('LDAP_MEMBER_FIELD_COUNTRY')] = $this->country_code;
2833 }
2834 foreach ($socialnetworks as $key => $value) {
2835 if ($this->socialnetworks[$value['label']] && getDolGlobalString('LDAP_MEMBER_FIELD_'.strtoupper($value['label']))) {
2836 $info[getDolGlobalString('LDAP_MEMBER_FIELD_'.strtoupper($value['label']))] = $this->socialnetworks[$value['label']];
2837 }
2838 }
2839 if ($this->phone && getDolGlobalString('LDAP_MEMBER_FIELD_PHONE')) {
2840 $info[getDolGlobalString('LDAP_MEMBER_FIELD_PHONE')] = $this->phone;
2841 }
2842 if ($this->phone_perso && getDolGlobalString('LDAP_MEMBER_FIELD_PHONE_PERSO')) {
2843 $info[getDolGlobalString('LDAP_MEMBER_FIELD_PHONE_PERSO')] = $this->phone_perso;
2844 }
2845 if ($this->phone_mobile && getDolGlobalString('LDAP_MEMBER_FIELD_MOBILE')) {
2846 $info[getDolGlobalString('LDAP_MEMBER_FIELD_MOBILE')] = $this->phone_mobile;
2847 }
2848 if ($this->fax && getDolGlobalString('LDAP_MEMBER_FIELD_FAX')) {
2849 $info[getDolGlobalString('LDAP_MEMBER_FIELD_FAX')] = $this->fax;
2850 }
2851 if ($this->note_private && getDolGlobalString('LDAP_MEMBER_FIELD_DESCRIPTION')) {
2852 $info[getDolGlobalString('LDAP_MEMBER_FIELD_DESCRIPTION')] = dol_string_nohtmltag($this->note_private, 2);
2853 }
2854 if ($this->note_public && getDolGlobalString('LDAP_MEMBER_FIELD_NOTE_PUBLIC')) {
2855 $info[getDolGlobalString('LDAP_MEMBER_FIELD_NOTE_PUBLIC')] = dol_string_nohtmltag($this->note_public, 2);
2856 }
2857 if ($this->birth && getDolGlobalString('LDAP_MEMBER_FIELD_BIRTHDATE')) {
2858 $info[getDolGlobalString('LDAP_MEMBER_FIELD_BIRTHDATE')] = dol_print_date($this->birth, 'dayhourldap');
2859 }
2860 if (isset($this->statut) && getDolGlobalString('LDAP_FIELD_MEMBER_STATUS')) {
2861 $info[getDolGlobalString('LDAP_FIELD_MEMBER_STATUS')] = $this->statut;
2862 }
2863 if ($this->datefin && getDolGlobalString('LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION')) {
2864 $info[getDolGlobalString('LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION')] = dol_print_date($this->datefin, 'dayhourldap');
2865 }
2866
2867 // When password is modified
2868 if (!empty($this->pass)) {
2869 if (getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD')) {
2870 $info[getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD')] = $this->pass; // this->pass = Unencrypted password
2871 }
2872 if (getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')) {
2873 $info[getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')] = dol_hash($this->pass, 'openldap'); // Create OpenLDAP password (see LDAP_PASSWORD_HASH_TYPE)
2874 }
2875 } elseif (getDolGlobalString('LDAP_SERVER_PROTOCOLVERSION') !== '3') {
2876 // Set LDAP password if possible
2877 // If ldap key is modified and LDAPv3 we use ldap_rename function for avoid lose encrypt password
2878 if (getDolGlobalString('DATABASE_PWD_ENCRYPTED')) { // This should be on on default installation
2879 // Just for the case we use old md5 encryption (deprecated, no more used, kept for compatibility)
2880 if (!getDolGlobalString('MAIN_SECURITY_HASH_ALGO') || getDolGlobalString('MAIN_SECURITY_HASH_ALGO') == 'md5') {
2881 if ($this->pass_indatabase_crypted && getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')) {
2882 // Create OpenLDAP MD5 password from Dolibarr MD5 password
2883 // Note: This suppose that "pass_indatabase_crypted" is a md5 (this should not happen anymore)"
2884 $info[getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')] = dolGetLdapPasswordHash($this->pass_indatabase_crypted, 'md5frommd5');
2885 }
2886 }
2887 } elseif (!empty($this->pass_indatabase)) {
2888 // Use $this->pass_indatabase value if exists
2889 if (getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD')) {
2890 $info[getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD')] = $this->pass_indatabase; // $this->pass_indatabase = Unencrypted password
2891 }
2892 if (getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')) {
2893 $info[getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')] = dol_hash($this->pass_indatabase, 'openldap'); // Create OpenLDAP password (see LDAP_PASSWORD_HASH_TYPE)
2894 }
2895 }
2896 }
2897
2898 // Subscriptions
2899 if ($this->first_subscription_date && getDolGlobalString('LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE')) {
2900 $info[getDolGlobalString('LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE')] = dol_print_date($this->first_subscription_date, 'dayhourldap');
2901 }
2902 if (isset($this->first_subscription_amount) && getDolGlobalString('LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT')) {
2903 $info[getDolGlobalString('LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT')] = $this->first_subscription_amount;
2904 }
2905 if ($this->last_subscription_date && getDolGlobalString('LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE')) {
2906 $info[getDolGlobalString('LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE')] = dol_print_date($this->last_subscription_date, 'dayhourldap');
2907 }
2908 if (isset($this->last_subscription_amount) && getDolGlobalString('LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT')) {
2909 $info[getDolGlobalString('LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT')] = $this->last_subscription_amount;
2910 }
2911
2912 return $info;
2913 }
2914
2915
2922 public function info($id)
2923 {
2924 $sql = 'SELECT a.rowid, a.datec as datec,';
2925 $sql .= ' a.datevalid as datev,';
2926 $sql .= ' a.tms as datem,';
2927 $sql .= ' a.fk_user_author, a.fk_user_valid, a.fk_user_mod';
2928 $sql .= ' FROM '.MAIN_DB_PREFIX.'adherent as a';
2929 $sql .= ' WHERE a.rowid = '.((int) $id);
2930
2931 dol_syslog(get_class($this)."::info", LOG_DEBUG);
2932 $result = $this->db->query($sql);
2933 if ($result) {
2934 if ($this->db->num_rows($result)) {
2935 $obj = $this->db->fetch_object($result);
2936
2937 $this->id = $obj->rowid;
2938
2939 $this->user_creation_id = $obj->fk_user_author;
2940 $this->user_validation_id = $obj->fk_user_valid;
2941 $this->user_modification_id = $obj->fk_user_mod;
2942 $this->date_creation = $this->db->jdate($obj->datec);
2943 $this->date_validation = $this->db->jdate($obj->datev);
2944 $this->date_modification = $this->db->jdate($obj->datem);
2945 }
2946
2947 $this->db->free($result);
2948 } else {
2949 dol_print_error($this->db);
2950 }
2951 }
2952
2958 public function getNbOfEMailings()
2959 {
2960 $sql = "SELECT count(mc.email) as nb";
2961 $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
2962 $sql .= " WHERE mc.email = '".$this->db->escape($this->email)."'";
2963 $sql .= " AND mc.statut NOT IN (-1,0)"; // -1 erreur, 0 non envoye, 1 envoye avec success
2964
2965 $resql = $this->db->query($sql);
2966 if ($resql) {
2967 $obj = $this->db->fetch_object($resql);
2968 $nb = $obj->nb;
2969
2970 $this->db->free($resql);
2971 return $nb;
2972 } else {
2973 $this->error = $this->db->error();
2974 return -1;
2975 }
2976 }
2977
2988 public function setCategories($categories)
2989 {
2990 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
2991 return parent::setCategoriesCommon($categories, Categorie::TYPE_MEMBER);
2992 }
2993
3002 public static function replaceThirdparty($db, $origin_id, $dest_id)
3003 {
3004 $tables = array('adherent');
3005
3006 return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
3007 }
3008
3014 public function hasDelay()
3015 {
3016 global $conf;
3017
3018 //Only valid members
3019 if ($this->statut != self::STATUS_VALIDATED) {
3020 return false;
3021 }
3022 if (!$this->datefin) {
3023 return false;
3024 }
3025
3026 $now = dol_now();
3027
3028 return $this->datefin < ($now - $conf->adherent->subscription->warning_delay);
3029 }
3030
3031
3040 public function sendReminderForExpiredSubscription($daysbeforeendlist = '10', $fk_adherent_type = 0)
3041 {
3042 global $conf, $langs, $mysoc, $user;
3043
3044 $error = 0;
3045 $this->output = '';
3046 $this->error = '';
3047
3048 $blockingerrormsg = '';
3049
3050 if (!isModEnabled('member')) { // Should not happen. If module disabled, cron job should not be visible.
3051 $langs->load("agenda");
3052 $this->output = $langs->trans('ModuleNotEnabled', $langs->transnoentitiesnoconv("Adherent"));
3053 return 0;
3054 }
3055 if (!getDolGlobalString('MEMBER_REMINDER_EMAIL')) {
3056 $langs->load("agenda");
3057 $this->output = $langs->trans('EventRemindersByEmailNotEnabled', $langs->transnoentitiesnoconv("Adherent"));
3058 return 0;
3059 }
3060
3061 $now = dol_now();
3062 $nbok = 0;
3063 $nbko = 0;
3064
3065 $listofmembersok = array();
3066 $listofmembersko = array();
3067
3068 $arraydaysbeforeend = explode(';', $daysbeforeendlist);
3069 foreach ($arraydaysbeforeend as $daysbeforeend) { // Loop on each delay
3070 dol_syslog(__METHOD__.' - Process delta = '.$daysbeforeend, LOG_DEBUG);
3071
3072 if (!is_numeric($daysbeforeend)) {
3073 $blockingerrormsg = "Value for delta is not a numeric value";
3074 $nbko++;
3075 break;
3076 }
3077
3078 $tmp = dol_getdate($now);
3079 $datetosearchfor = dol_time_plus_duree(dol_mktime(0, 0, 0, $tmp['mon'], $tmp['mday'], $tmp['year'], 'tzserver'), (int) $daysbeforeend, 'd');
3080
3081 $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'adherent';
3082 $sql .= " WHERE entity = ".((int) $conf->entity); // Do not use getEntity('adherent').")" here, we want the batch to be on its entity only;
3083 $sql .= " AND statut = 1";
3084 $sql .= " AND datefin = '".$this->db->idate($datetosearchfor)."'";
3085 if ((int) $fk_adherent_type > 0) {
3086 $sql .= " AND fk_adherent_type = ".((int) $fk_adherent_type);
3087 }
3088 //$sql .= " LIMIT 10000";
3089
3090 $resql = $this->db->query($sql);
3091 if ($resql) {
3092 $num_rows = $this->db->num_rows($resql);
3093
3094 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
3095 $adherent = new Adherent($this->db);
3096 $formmail = new FormMail($this->db);
3097
3098 $i = 0;
3099 while ($i < $num_rows) {
3100 $obj = $this->db->fetch_object($resql);
3101
3102 $adherent->fetch($obj->rowid, '', 0, '', true, true);
3103
3104 if (empty($adherent->email)) {
3105 $nbko++;
3106 $listofmembersko[$adherent->id] = $adherent->id;
3107 } else {
3108 $thirdpartyres = $adherent->fetch_thirdparty();
3109 if ($thirdpartyres === -1 ) {
3110 $languagecodeformember = $mysoc->default_lang;
3111 } else {
3112 // 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.
3113 $languagefromcountrycode = getLanguageCodeFromCountryCode($adherent->country_code ? $adherent->country_code : $adherent->thirdparty->country_code);
3114 $languagecodeformember = (empty($adherent->thirdparty->default_lang) ? ($languagefromcountrycode ? $languagefromcountrycode : $mysoc->default_lang) : $adherent->thirdparty->default_lang);
3115 }
3116
3117 // Send reminder email
3118 $outputlangs = new Translate('', $conf);
3119 $outputlangs->setDefaultLang($languagecodeformember);
3120 $outputlangs->loadLangs(array("main", "members"));
3121 dol_syslog("sendReminderForExpiredSubscription Language for member id ".$adherent->id." set to ".$outputlangs->defaultlang." mysoc->default_lang=".$mysoc->default_lang);
3122
3123 $arraydefaultmessage = null;
3124 $labeltouse = getDolGlobalString('ADHERENT_EMAIL_TEMPLATE_REMIND_EXPIRATION');
3125
3126 if (!empty($labeltouse)) {
3127 $arraydefaultmessage = $formmail->getEMailTemplate($this->db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
3128 }
3129
3130 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
3131 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $adherent);
3132 //if (is_array($adherent->thirdparty)) $substitutionarraycomp = ...
3133 complete_substitutions_array($substitutionarray, $outputlangs, $adherent);
3134
3135 $subject = make_substitutions($arraydefaultmessage->topic, $substitutionarray, $outputlangs);
3136 $msg = make_substitutions($arraydefaultmessage->content, $substitutionarray, $outputlangs);
3137 $from = getDolGlobalString('ADHERENT_MAIL_FROM');
3138 $to = $adherent->email;
3139 $cc = getDolGlobalString('ADHERENT_CC_MAIL_FROM');
3140
3141 $trackid = 'mem'.$adherent->id;
3142 $moreinheader = 'X-Dolibarr-Info: sendReminderForExpiredSubscription'."\r\n";
3143
3144 include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
3145 $cmail = new CMailFile($subject, $to, $from, $msg, array(), array(), array(), $cc, '', 0, 1, '', '', $trackid, $moreinheader);
3146 $result = $cmail->sendfile();
3147 if (!$result) {
3148 $error++;
3149 $this->error .= $cmail->error.' ';
3150 if (!is_null($cmail->errors)) {
3151 $this->errors += $cmail->errors;
3152 }
3153 $nbko++;
3154 $listofmembersko[$adherent->id] = $adherent->id;
3155 } else {
3156 $nbok++;
3157 $listofmembersok[$adherent->id] = $adherent->id;
3158
3159 $message = $msg;
3160 $sendto = $to;
3161 $sendtocc = '';
3162 $sendtobcc = '';
3163 $actioncode = 'EMAIL';
3164 $extraparams = '';
3165
3166 $actionmsg = '';
3167 $actionmsg2 = $langs->transnoentities('MailSentByTo', CMailFile::getValidAddress($from, 4, 0, 1), CMailFile::getValidAddress($sendto, 4, 0, 1));
3168 if ($message) {
3169 $actionmsg = $langs->transnoentities('MailFrom').': '.dol_escape_htmltag($from);
3170 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTo').': '.dol_escape_htmltag($sendto));
3171 if ($sendtocc) {
3172 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc').": ".dol_escape_htmltag($sendtocc));
3173 }
3174 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic').": ".$subject);
3175 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody').":");
3176 $actionmsg = dol_concatdesc($actionmsg, $message);
3177 }
3178
3179 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
3180
3181 // Insert record of emails sent
3182 $actioncomm = new ActionComm($this->db);
3183
3184 $actioncomm->type_code = 'AC_OTH_AUTO'; // Type of event ('AC_OTH', 'AC_OTH_AUTO', 'AC_XXX'...)
3185 $actioncomm->code = 'AC_'.$actioncode;
3186 $actioncomm->label = $actionmsg2;
3187 $actioncomm->note_private = $actionmsg;
3188 $actioncomm->fk_project = 0;
3189 $actioncomm->datep = $now;
3190 $actioncomm->datef = $now;
3191 $actioncomm->percentage = -1; // Not applicable
3192 $actioncomm->socid = $adherent->thirdparty->id;
3193 $actioncomm->contact_id = 0;
3194 $actioncomm->authorid = $user->id; // User saving action
3195 $actioncomm->userownerid = $user->id; // Owner of action
3196 // Fields when action is en email (content should be added into note)
3197 $actioncomm->email_msgid = $cmail->msgid;
3198 $actioncomm->email_from = $from;
3199 $actioncomm->email_sender = '';
3200 $actioncomm->email_to = $to;
3201 $actioncomm->email_tocc = $sendtocc;
3202 $actioncomm->email_tobcc = $sendtobcc;
3203 $actioncomm->email_subject = $subject;
3204 $actioncomm->errors_to = '';
3205
3206 $actioncomm->fk_element = $adherent->id;
3207 $actioncomm->elementid = $adherent->id;
3208 $actioncomm->elementtype = $adherent->element;
3209
3210 $actioncomm->extraparams = $extraparams;
3211
3212 $actioncomm->create($user);
3213 }
3214 } else {
3215 //$blockingerrormsg = "Can't find email template with label=".$labeltouse.", to use for the reminding email";
3216
3217 $error++;
3218 $this->error .= "Can't find email template with label=".$labeltouse.", to use for the reminding email ";
3219
3220 $nbko++;
3221 $listofmembersko[$adherent->id] = $adherent->id;
3222
3223 break;
3224 }
3225 }
3226
3227 $i++;
3228 }
3229 } else {
3230 $this->error = $this->db->lasterror();
3231 return 1;
3232 }
3233 }
3234
3235 if ($blockingerrormsg) {
3236 $this->error = $blockingerrormsg;
3237 return 1;
3238 } else {
3239 $this->output = 'Found '.($nbok + $nbko).' members to send reminder to.';
3240 $this->output .= ' Send email successfully to '.$nbok.' members';
3241 if (is_array($listofmembersok)) {
3242 $listofids = '';
3243 $i = 0;
3244 foreach ($listofmembersok as $idmember) {
3245 if ($i > 100) {
3246 $listofids .= ', ...';
3247 break;
3248 }
3249 if (empty($listofids)) {
3250 $listofids .= ' [';
3251 } else {
3252 $listofids .= ', ';
3253 }
3254 $listofids .= $idmember;
3255 $i++;
3256 }
3257 if ($listofids) {
3258 $listofids .= ']';
3259 }
3260
3261 $this->output .= ($listofids ? ' ids='.$listofids : '');
3262 }
3263 if ($nbko) {
3264 $this->output .= ' - Canceled for '.$nbko.' member (no email or email sending error)';
3265 if (is_array($listofmembersko)) {
3266 $listofids = '';
3267 $i = 0;
3268 foreach ($listofmembersko as $idmember) {
3269 if ($i > 100) {
3270 $listofids .= ', ...';
3271 break;
3272 }
3273 if (empty($listofids)) {
3274 $listofids .= ' [';
3275 } else {
3276 $listofids .= ', ';
3277 }
3278 $listofids .= $idmember;
3279 $i++;
3280 }
3281 if ($listofids) {
3282 $listofids .= ']';
3283 }
3284 $this->output .= ($listofids ? ' ids='.$listofids : '');
3285 }
3286 }
3287 }
3288
3289 return $nbko;
3290 }
3291
3299 public function getKanbanView($option = '', $arraydata = null)
3300 {
3301 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
3302
3303 $return = '<div class="box-flex-item box-flex-grow-zero">';
3304 $return .= '<div class="info-box info-box-sm">';
3305 $return .= '<span class="info-box-icon bg-infobox-action">';
3306 if (property_exists($this, 'photo') || !empty($this->photo)) {
3307 $return .= Form::showphoto('memberphoto', $this, 0, 60, 0, 'photokanban photowithmargin photologintooltip', 'small', 0, 1);
3308 } else {
3309 $return .= img_picto('', 'user');
3310 }
3311 $return .= '</span>';
3312 $return .= '<div class="info-box-content">';
3313 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
3314 if ($selected >= 0) {
3315 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
3316 }
3317 $return .= '<br><span class="info-box-label paddingright">'.$this->getmorphylib('', 2).'</span>';
3318 $return .= '<span class="info-box-label opacitymedium">'.$this->type.'</span>';
3319
3320 if (method_exists($this, 'getLibStatut')) {
3321 $return .= '<br><div class="info-box-status paddingtop">';
3322 $return .= $this->LibStatut($this->status, $this->need_subscription, $this->datefin, 5);
3323 $return .= '</div>';
3324 }
3325 $return .= '</div>';
3326 $return .= '</div>';
3327 $return .= '</div>';
3328 return $return;
3329 }
3330}
$object ref
Definition info.php:89
Class to manage bank accounts.
Class to manage agenda events (actions)
Class to manage members of a foundation.
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)
Retourne chaine DN complete dans l'annuaire LDAP pour l'objet.
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.
fetch($rowid, $ref='', $fk_soc=0, $ref_ext='', $fetch_optionals=true, $fetch_subscriptions=true)
Load member from database.
del_to_abo()
Function to delete a member from external tools like mailing-list, spip, etc.
resiliate($user)
Fonction qui resilie un adherent.
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.
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
const STATUS_DRAFT
Draft status.
const STATUS_RESILIATED
Resiliated.
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.
__construct($db)
Constructor.
subscription($date, $amount, $accountid=0, $operation='', $label='', $num_chq='', $emetteur_nom='', $emetteur_banque='', $datesubend=0, $fk_type=null)
Insert subscription into database and eventually add links to banks, mailman, etc....
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,...
validate($user)
Function that validate a member.
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.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
setErrorsFromObject($object)
setErrorsFromObject
deleteExtraFields()
Delete all extra fields values for the current object.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
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)
Return HTML code to output a photo.
Class permettant la generation du formulaire html d'envoi de mail unitaire Usage: $formail = new Form...
Class to manage mailman and spip.
Class to manage payments of customer invoices.
Class to manage payment terms records in dictionary.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage subscriptions of foundation members.
Class to manage translations.
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:171
getFullName($langs, $option=0, $nameorder=-1, $maxlen=0)
Return full name (civility+' '+name+' '+lastname)
setUpperOrLowerCase()
Set to upper or ucwords/lower if needed.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition date.lib.php:125
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").
clean_url($url, $http=1)
Clean an url string.
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...
getLanguageCodeFromCountryCode($countrycode)
Return default language from country code.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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)
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 '.
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.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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...
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null, $include=null)
Return array of possible common substitutions.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
div refaddress div address
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:149
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)
Returns a hash (non reversible encryption) of a string.