dolibarr 21.0.0-alpha
adherent.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org>
4 * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
6 * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
7 * Copyright (C) 2009-2017 Regis Houssin <regis.houssin@inodbox.com>
8 * Copyright (C) 2014-2018 Alexandre Spangaro <alexandre@inovea-conseil.com>
9 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
10 * Copyright (C) 2015-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 $this->import_key = trim($this->import_key);
630
631 // Check parameters
632 if (getDolGlobalString('ADHERENT_MAIL_REQUIRED') && !isValidEmail($this->email)) {
633 $langs->load("errors");
634 $this->error = $langs->trans("ErrorBadEMail", $this->email);
635 return -1;
636 }
637 if (!$this->datec) {
638 $this->datec = $now;
639 }
640 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
641 if (empty($this->login)) {
642 $this->error = $langs->trans("ErrorWrongValueForParameterX", "Login");
643 return -1;
644 }
645 }
646
647 $this->db->begin();
648
649 // Insert member
650 $sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent";
651 $sql .= " (ref, datec,login,fk_user_author,fk_user_mod,fk_user_valid,morphy,fk_adherent_type,entity,import_key, ip)";
652 $sql .= " VALUES (";
653 $sql .= " '(PROV)'";
654 $sql .= ", '".$this->db->idate($this->datec)."'";
655 $sql .= ", ".($this->login ? "'".$this->db->escape($this->login)."'" : "null");
656 $sql .= ", ".($user->id > 0 ? $user->id : "null"); // Can be null because member can be created by a guest or a script
657 $sql .= ", null, null, '".$this->db->escape($this->morphy)."'";
658 $sql .= ", ".((int) $this->typeid);
659 $sql .= ", ".$conf->entity;
660 $sql .= ", ".(!empty($this->import_key) ? "'".$this->db->escape($this->import_key)."'" : "null");
661 $sql .= ", ".(!empty($this->ip) ? "'".$this->db->escape($this->ip)."'" : "null");
662 $sql .= ")";
663
664 dol_syslog(get_class($this)."::create", LOG_DEBUG);
665 $result = $this->db->query($sql);
666 if ($result) {
667 $id = $this->db->last_insert_id(MAIN_DB_PREFIX."adherent");
668 if ($id > 0) {
669 $this->id = $id;
670 if (getDolGlobalString('MEMBER_CODEMEMBER_ADDON') == '') {
671 // keep old numbering
672 $this->ref = (string) $id;
673 } else {
674 // auto code
675 $modfile = dol_buildpath('core/modules/member/'.getDolGlobalString('MEMBER_CODEMEMBER_ADDON').'.php', 0);
676 try {
677 require_once $modfile;
678 $modname = getDolGlobalString('MEMBER_CODEMEMBER_ADDON');
679 $modCodeMember = new $modname();
680 '@phan-var-force ModeleNumRefMembers $modCodeMember';
681 $this->ref = $modCodeMember->getNextValue($mysoc, $this);
682 } catch (Exception $e) {
683 dol_syslog($e->getMessage(), LOG_ERR);
684 $error++;
685 }
686 }
687
688 // Update minor fields
689 $result = $this->update($user, 1, 1, 0, 0, 'add'); // nosync is 1 to avoid update data of user
690 if ($result < 0) {
691 $this->db->rollback();
692 return -1;
693 }
694
695 // Add link to user
696 if ($this->user_id) {
697 // Add link to user
698 $sql = "UPDATE ".MAIN_DB_PREFIX."user SET";
699 $sql .= " fk_member = ".((int) $this->id);
700 $sql .= " WHERE rowid = ".((int) $this->user_id);
701 dol_syslog(get_class($this)."::create", LOG_DEBUG);
702 $resql = $this->db->query($sql);
703 if (!$resql) {
704 $this->error = 'Failed to update user to make link with member';
705 $this->db->rollback();
706 return -4;
707 }
708 }
709
710 if (!$notrigger) {
711 // Call trigger
712 $result = $this->call_trigger('MEMBER_CREATE', $user);
713 if ($result < 0) {
714 $error++;
715 }
716 // End call triggers
717 }
718
719 if (count($this->errors)) {
720 dol_syslog(get_class($this)."::create ".implode(',', $this->errors), LOG_ERR);
721 $this->db->rollback();
722 return -3;
723 } else {
724 $this->db->commit();
725 return $this->id;
726 }
727 } else {
728 $this->error = 'Failed to get last insert id';
729 dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
730 $this->db->rollback();
731 return -2;
732 }
733 } else {
734 $this->error = $this->db->error();
735 $this->db->rollback();
736 return -1;
737 }
738 }
739
740
752 public function update($user, $notrigger = 0, $nosyncuser = 0, $nosyncuserpass = 0, $nosyncthirdparty = 0, $action = 'update')
753 {
754 global $langs, $hookmanager;
755
756 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
757
758 $nbrowsaffected = 0;
759 $error = 0;
760
761 dol_syslog(get_class($this)."::update notrigger=".$notrigger.", nosyncuser=".$nosyncuser.", nosyncuserpass=".$nosyncuserpass." nosyncthirdparty=".$nosyncthirdparty.", email=".$this->email);
762
763 // Clean parameters
764 $this->lastname = trim($this->lastname) ? trim($this->lastname) : trim($this->lastname);
765 $this->firstname = trim($this->firstname) ? trim($this->firstname) : trim($this->firstname);
766 $this->gender = trim($this->gender);
767 // $this->address = ($this->address ? $this->address : $this->address);
768 // $this->zip = ($this->zip ? $this->zip : $this->zip);
769 // $this->town = ($this->town ? $this->town : $this->town);
770 // $this->country_id = ($this->country_id > 0 ? $this->country_id : $this->country_id);
771 // $this->state_id = ($this->state_id > 0 ? $this->state_id : $this->state_id);
772 // $this->note_public = ($this->note_public ? $this->note_public : $this->note_public);
773 // $this->note_private = ($this->note_private ? $this->note_private : $this->note_private);
774 $this->url = $this->url ? clean_url($this->url, 0) : '';
775 $this->setUpperOrLowerCase();
776 // Check parameters
777 if (getDolGlobalString('ADHERENT_MAIL_REQUIRED') && !isValidEmail($this->email)) {
778 $langs->load("errors");
779 $this->error = $langs->trans("ErrorBadEMail", $this->email);
780 return -1;
781 }
782
783 $this->db->begin();
784
785 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
786 $sql .= " ref = '".$this->db->escape($this->ref)."'";
787 $sql .= ", civility = ".($this->civility_id ? "'".$this->db->escape($this->civility_id)."'" : "null");
788 $sql .= ", firstname = ".($this->firstname ? "'".$this->db->escape($this->firstname)."'" : "null");
789 $sql .= ", lastname = ".($this->lastname ? "'".$this->db->escape($this->lastname)."'" : "null");
790 $sql .= ", gender = ".($this->gender != -1 ? "'".$this->db->escape($this->gender)."'" : "null"); // 'man' or 'woman'
791 $sql .= ", login = ".($this->login ? "'".$this->db->escape($this->login)."'" : "null");
792 $sql .= ", societe = ".($this->company ? "'".$this->db->escape($this->company)."'" : ($this->societe ? "'".$this->db->escape($this->societe)."'" : "null"));
793 if ($this->socid) {
794 $sql .= ", fk_soc = ".($this->socid > 0 ? (int) $this->socid : "null"); // Must be modified only when creating from a third-party
795 }
796 $sql .= ", address = ".($this->address ? "'".$this->db->escape($this->address)."'" : "null");
797 $sql .= ", zip = ".($this->zip ? "'".$this->db->escape($this->zip)."'" : "null");
798 $sql .= ", town = ".($this->town ? "'".$this->db->escape($this->town)."'" : "null");
799 $sql .= ", country = ".($this->country_id > 0 ? (int) $this->country_id : "null");
800 $sql .= ", state_id = ".($this->state_id > 0 ? (int) $this->state_id : "null");
801 $sql .= ", email = '".$this->db->escape($this->email)."'";
802 $sql .= ", url = ".(!empty($this->url) ? "'".$this->db->escape($this->url)."'" : "null");
803 $sql .= ", socialnetworks = ".($this->socialnetworks ? "'".$this->db->escape(json_encode($this->socialnetworks))."'" : "null");
804 $sql .= ", phone = ".($this->phone ? "'".$this->db->escape($this->phone)."'" : "null");
805 $sql .= ", phone_perso = ".($this->phone_perso ? "'".$this->db->escape($this->phone_perso)."'" : "null");
806 $sql .= ", phone_mobile = ".($this->phone_mobile ? "'".$this->db->escape($this->phone_mobile)."'" : "null");
807 $sql .= ", note_private = ".($this->note_private ? "'".$this->db->escape($this->note_private)."'" : "null");
808 $sql .= ", note_public = ".($this->note_public ? "'".$this->db->escape($this->note_public)."'" : "null");
809 $sql .= ", photo = ".($this->photo ? "'".$this->db->escape($this->photo)."'" : "null");
810 $sql .= ", public = ".(int) $this->public;
811 $sql .= ", statut = ".(int) $this->statut;
812 $sql .= ", default_lang = ".(!empty($this->default_lang) ? "'".$this->db->escape($this->default_lang)."'" : "null");
813 $sql .= ", fk_adherent_type = ".(int) $this->typeid;
814 $sql .= ", morphy = '".$this->db->escape($this->morphy)."'";
815 $sql .= ", birth = ".($this->birth ? "'".$this->db->idate($this->birth)."'" : "null");
816
817 if ($this->datefin) {
818 $sql .= ", datefin = '".$this->db->idate($this->datefin)."'"; // Must be modified only when deleting a subscription
819 }
820 if ($this->datevalid) {
821 $sql .= ", datevalid = '".$this->db->idate($this->datevalid)."'"; // Must be modified only when validating a member
822 }
823 $sql .= ", fk_user_mod = ".($user->id > 0 ? $user->id : 'null'); // Can be null because member can be create by a guest
824 $sql .= " WHERE rowid = ".((int) $this->id);
825
826 // If we change the type of membership, we set also label of new type
827 if (!empty($this->oldcopy) && $this->typeid != $this->oldcopy->typeid) {
828 $sql2 = "SELECT libelle as label";
829 $sql2 .= " FROM ".MAIN_DB_PREFIX."adherent_type";
830 $sql2 .= " WHERE rowid = ".((int) $this->typeid);
831 $resql2 = $this->db->query($sql2);
832 if ($resql2) {
833 while ($obj = $this->db->fetch_object($resql2)) {
834 $this->type = $obj->label;
835 }
836 }
837 }
838
839 dol_syslog(get_class($this)."::update update member", LOG_DEBUG);
840 $resql = $this->db->query($sql);
841 if ($resql) {
842 unset($this->country_code);
843 unset($this->country);
844 unset($this->state_code);
845 unset($this->state);
846
847 $nbrowsaffected += $this->db->affected_rows($resql);
848
849 $action = 'update';
850
851 // Actions on extra fields
852 if (!$error) {
853 $result = $this->insertExtraFields();
854 if ($result < 0) {
855 $error++;
856 }
857 }
858
859 // Update password
860 if (!$error && $this->pass) {
861 dol_syslog(get_class($this)."::update update password");
862 if ($this->pass != $this->pass_indatabase && $this->pass != $this->pass_indatabase_crypted) {
863 $isencrypted = getDolGlobalString('DATABASE_PWD_ENCRYPTED') ? 1 : 0;
864
865 // If password to set differs from the one found into database
866 $result = $this->setPassword($user, $this->pass, $isencrypted, $notrigger, $nosyncuserpass);
867 if (!$nbrowsaffected) {
868 $nbrowsaffected++;
869 }
870 }
871 }
872
873 // Remove links to user and replace with new one
874 if (!$error) {
875 dol_syslog(get_class($this)."::update update link to user");
876 $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = NULL WHERE fk_member = ".((int) $this->id);
877 dol_syslog(get_class($this)."::update", LOG_DEBUG);
878 $resql = $this->db->query($sql);
879 if (!$resql) {
880 $this->error = $this->db->error();
881 $this->db->rollback();
882 return -5;
883 }
884 // If there is a user linked to this member
885 if ($this->user_id > 0) {
886 $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = ".((int) $this->id)." WHERE rowid = ".((int) $this->user_id);
887 dol_syslog(get_class($this)."::update", LOG_DEBUG);
888 $resql = $this->db->query($sql);
889 if (!$resql) {
890 $this->error = $this->db->error();
891 $this->db->rollback();
892 return -5;
893 }
894 }
895 }
896
897 if (!$error && $nbrowsaffected) { // If something has change in main data
898 // Update information on linked user if it is an update
899 if (!$error && $this->user_id > 0 && !$nosyncuser) {
900 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
901
902 dol_syslog(get_class($this)."::update update linked user");
903
904 $luser = new User($this->db);
905 $result = $luser->fetch($this->user_id);
906
907 if ($result >= 0) {
908 //var_dump($this->user_login);exit;
909 //var_dump($this->login);exit;
910
911 // 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.
912 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
913 $luser->login = $this->login;
914 }
915
916 $luser->ref = $this->ref;
917 $luser->civility_id = $this->civility_id;
918 $luser->firstname = $this->firstname;
919 $luser->lastname = $this->lastname;
920 $luser->gender = $this->gender;
921 $luser->pass = $this->pass;
922 //$luser->socid=$this->fk_soc; // We do not enable this. This may transform a user into an external user.
923
924 $luser->birth = $this->birth;
925
926 $luser->address = $this->address;
927 $luser->zip = $this->zip;
928 $luser->town = $this->town;
929 $luser->country_id = $this->country_id;
930 $luser->state_id = $this->state_id;
931
932 $luser->email = $this->email;
933 $luser->socialnetworks = $this->socialnetworks;
934 $luser->office_phone = $this->phone;
935 $luser->user_mobile = $this->phone_mobile;
936
937 $luser->lang = $this->default_lang;
938
939 $luser->fk_member = $this->id;
940
941 $result = $luser->update($user, 0, 1, 1); // Use nosync to 1 to avoid cyclic updates
942 if ($result < 0) {
943 $this->error = $luser->error;
944 dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
945 $error++;
946 }
947 } else {
948 $this->error = $luser->error;
949 $error++;
950 }
951 }
952
953 // Update information on linked thirdparty if it is an update
954 if (!$error && $this->fk_soc > 0 && !$nosyncthirdparty) {
955 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
956
957 dol_syslog(get_class($this)."::update update linked thirdparty");
958
959 // This member is linked with a thirdparty, so we also update thirdparty information
960 // if this is an update.
961 $lthirdparty = new Societe($this->db);
962 $result = $lthirdparty->fetch($this->fk_soc);
963
964 if ($result > 0) {
965 $lthirdparty->address = $this->address;
966 $lthirdparty->zip = $this->zip;
967 $lthirdparty->town = $this->town;
968 $lthirdparty->email = $this->email;
969 $lthirdparty->socialnetworks = $this->socialnetworks;
970 $lthirdparty->phone = $this->phone;
971 $lthirdparty->state_id = $this->state_id;
972 $lthirdparty->country_id = $this->country_id;
973 //$lthirdparty->phone_mobile=$this->phone_mobile;
974 $lthirdparty->default_lang = $this->default_lang;
975
976 $result = $lthirdparty->update($this->fk_soc, $user, 0, 1, 1, 'update'); // Use sync to 0 to avoid cyclic updates
977
978 if ($result < 0) {
979 $this->error = $lthirdparty->error;
980 $this->errors = $lthirdparty->errors;
981 dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
982 $error++;
983 }
984 } elseif ($result < 0) {
985 $this->error = $lthirdparty->error;
986 $error++;
987 }
988 }
989 }
990
991 if (!$error && !$notrigger) {
992 // Call trigger
993 $result = $this->call_trigger('MEMBER_MODIFY', $user);
994 if ($result < 0) {
995 $error++;
996 }
997 // End call triggers
998 }
999
1000 if (!$error) {
1001 $this->db->commit();
1002 return $nbrowsaffected;
1003 } else {
1004 $this->db->rollback();
1005 return -1;
1006 }
1007 } else {
1008 $this->db->rollback();
1009 $this->error = $this->db->lasterror();
1010 return -2;
1011 }
1012 }
1013
1014
1015 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1023 public function update_end_date($user)
1024 {
1025 // phpcs:enable
1026 $this->db->begin();
1027
1028 // Search for last subscription id and end date
1029 $sql = "SELECT rowid, datec as dateop, dateadh as datedeb, datef as datefin";
1030 $sql .= " FROM ".MAIN_DB_PREFIX."subscription";
1031 $sql .= " WHERE fk_adherent = ".((int) $this->id);
1032 $sql .= " ORDER by dateadh DESC"; // Sort by start subscription date
1033
1034 dol_syslog(get_class($this)."::update_end_date", LOG_DEBUG);
1035 $resql = $this->db->query($sql);
1036 if ($resql) {
1037 $obj = $this->db->fetch_object($resql);
1038 $dateop = $this->db->jdate($obj->dateop);
1039 $datedeb = $this->db->jdate($obj->datedeb);
1040 $datefin = $this->db->jdate($obj->datefin);
1041
1042 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
1043 $sql .= " datefin=".($datefin != '' ? "'".$this->db->idate($datefin)."'" : "null");
1044 $sql .= " WHERE rowid = ".((int) $this->id);
1045
1046 dol_syslog(get_class($this)."::update_end_date", LOG_DEBUG);
1047 $resql = $this->db->query($sql);
1048 if ($resql) {
1049 $this->last_subscription_date = $dateop;
1050 $this->last_subscription_date_start = $datedeb;
1051 $this->last_subscription_date_end = $datefin;
1052 $this->datefin = $datefin;
1053 $this->db->commit();
1054 return 1;
1055 } else {
1056 $this->db->rollback();
1057 return -1;
1058 }
1059 } else {
1060 $this->error = $this->db->lasterror();
1061 $this->db->rollback();
1062 return -1;
1063 }
1064 }
1065
1073 public function delete($user, $notrigger = 0)
1074 {
1075 $result = 0;
1076 $error = 0;
1077 $errorflag = 0;
1078
1079 // Check parameters
1080 $rowid = $this->id;
1081
1082 $this->db->begin();
1083
1084 if (!$error && !$notrigger) {
1085 // Call trigger
1086 $result = $this->call_trigger('MEMBER_DELETE', $user);
1087 if ($result < 0) {
1088 $error++;
1089 }
1090 // End call triggers
1091 }
1092
1093 // Remove category
1094 $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_member WHERE fk_member = ".((int) $rowid);
1095 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1096 $resql = $this->db->query($sql);
1097 if (!$resql) {
1098 $error++;
1099 $this->error .= $this->db->lasterror();
1100 $errorflag = -1;
1101 }
1102
1103 // Remove subscription
1104 if (!$error) {
1105 $sql = "DELETE FROM ".MAIN_DB_PREFIX."subscription WHERE fk_adherent = ".((int) $rowid);
1106 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1107 $resql = $this->db->query($sql);
1108 if (!$resql) {
1109 $error++;
1110 $this->error .= $this->db->lasterror();
1111 $errorflag = -2;
1112 }
1113 }
1114
1115 // Remove linked user
1116 if (!$error) {
1117 $ret = $this->setUserId(0);
1118 if ($ret < 0) {
1119 $error++;
1120 $this->error .= $this->db->lasterror();
1121 $errorflag = -3;
1122 }
1123 }
1124
1125 // Removed extrafields
1126 if (!$error) {
1127 $result = $this->deleteExtraFields();
1128 if ($result < 0) {
1129 $error++;
1130 $errorflag = -4;
1131 dol_syslog(get_class($this)."::delete erreur ".$errorflag." ".$this->error, LOG_ERR);
1132 }
1133 }
1134
1135 // Remove adherent
1136 if (!$error) {
1137 $sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent WHERE rowid = ".((int) $rowid);
1138 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1139 $resql = $this->db->query($sql);
1140 if (!$resql) {
1141 $error++;
1142 $this->error .= $this->db->lasterror();
1143 $errorflag = -5;
1144 }
1145 }
1146
1147 if (!$error) {
1148 $this->db->commit();
1149 return 1;
1150 } else {
1151 $this->db->rollback();
1152 return $errorflag;
1153 }
1154 }
1155
1156
1167 public function setPassword($user, $password = '', $isencrypted = 0, $notrigger = 0, $nosyncuser = 0)
1168 {
1169 global $conf, $langs;
1170
1171 $error = 0;
1172
1173 dol_syslog(get_class($this)."::setPassword user=".$user->id." password=".preg_replace('/./i', '*', $password)." isencrypted=".$isencrypted);
1174
1175 // If new password not provided, we generate one
1176 if (!$password) {
1177 require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
1178 $password = getRandomPassword(false);
1179 }
1180
1181 // Crypt password
1182 $password_crypted = dol_hash($password);
1183
1184 $password_indatabase = '';
1185 if (!$isencrypted) {
1186 $password_indatabase = $password;
1187 }
1188
1189 $this->db->begin();
1190
1191 // Mise a jour
1192 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent";
1193 $sql .= " SET pass_crypted = '".$this->db->escape($password_crypted)."'";
1194 if ($isencrypted) {
1195 $sql .= ", pass = null";
1196 } else {
1197 $sql .= ", pass = '".$this->db->escape($password_indatabase)."'";
1198 }
1199 $sql .= " WHERE rowid = ".((int) $this->id);
1200
1201 //dol_syslog("Adherent::Password sql=hidden");
1202 dol_syslog(get_class($this)."::setPassword", LOG_DEBUG);
1203 $result = $this->db->query($sql);
1204 if ($result) {
1205 $nbaffectedrows = $this->db->affected_rows($result);
1206
1207 if ($nbaffectedrows) {
1208 $this->pass = $password;
1209 $this->pass_indatabase = $password_indatabase;
1210 $this->pass_indatabase_crypted = $password_crypted;
1211
1212 if ($this->user_id && !$nosyncuser) {
1213 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
1214
1215 // This member is linked with a user, so we also update users information
1216 // if this is an update.
1217 $luser = new User($this->db);
1218 $result = $luser->fetch($this->user_id);
1219
1220 if ($result >= 0) {
1221 $result = $luser->setPassword($user, $this->pass, 0, 0, 1);
1222 if (is_int($result) && $result < 0) {
1223 $this->error = $luser->error;
1224 dol_syslog(get_class($this)."::setPassword ".$this->error, LOG_ERR);
1225 $error++;
1226 }
1227 } else {
1228 $this->error = $luser->error;
1229 $error++;
1230 }
1231 }
1232
1233 if (!$error && !$notrigger) {
1234 // Call trigger
1235 $result = $this->call_trigger('MEMBER_NEW_PASSWORD', $user);
1236 if ($result < 0) {
1237 $error++;
1238 $this->db->rollback();
1239 return -1;
1240 }
1241 // End call triggers
1242 }
1243
1244 $this->db->commit();
1245 return $this->pass;
1246 } else {
1247 $this->db->rollback();
1248 return 0;
1249 }
1250 } else {
1251 $this->db->rollback();
1252 dol_print_error($this->db);
1253 return -1;
1254 }
1255 }
1256
1257
1264 public function setUserId($userid)
1265 {
1266 global $conf, $langs;
1267
1268 $this->db->begin();
1269
1270 // If user is linked to this member, remove old link to this member
1271 $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = NULL WHERE fk_member = ".((int) $this->id);
1272 dol_syslog(get_class($this)."::setUserId", LOG_DEBUG);
1273 $resql = $this->db->query($sql);
1274 if (!$resql) {
1275 $this->error = $this->db->error();
1276 $this->db->rollback();
1277 return -1;
1278 }
1279
1280 // Set link to user
1281 if ($userid > 0) {
1282 $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = ".((int) $this->id);
1283 $sql .= " WHERE rowid = ".((int) $userid);
1284 dol_syslog(get_class($this)."::setUserId", LOG_DEBUG);
1285 $resql = $this->db->query($sql);
1286 if (!$resql) {
1287 $this->error = $this->db->error();
1288 $this->db->rollback();
1289 return -2;
1290 }
1291 }
1292
1293 $this->db->commit();
1294
1295 return 1;
1296 }
1297
1298
1305 public function setThirdPartyId($thirdpartyid)
1306 {
1307 global $conf, $langs;
1308
1309 $this->db->begin();
1310
1311 // Remove link to third party onto any other members
1312 if ($thirdpartyid > 0) {
1313 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET fk_soc = null";
1314 $sql .= " WHERE fk_soc = ".((int) $thirdpartyid);
1315 $sql .= " AND entity = ".$conf->entity;
1316 dol_syslog(get_class($this)."::setThirdPartyId", LOG_DEBUG);
1317 $resql = $this->db->query($sql);
1318 }
1319
1320 // Add link to third party for current member
1321 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET fk_soc = ".($thirdpartyid > 0 ? (int) $thirdpartyid : 'null');
1322 $sql .= " WHERE rowid = ".((int) $this->id);
1323
1324 dol_syslog(get_class($this)."::setThirdPartyId", LOG_DEBUG);
1325 $resql = $this->db->query($sql);
1326 if ($resql) {
1327 $this->db->commit();
1328 return 1;
1329 } else {
1330 $this->error = $this->db->error();
1331 $this->db->rollback();
1332 return -1;
1333 }
1334 }
1335
1336
1337 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1344 public function fetch_login($login)
1345 {
1346 // phpcs:enable
1347 global $conf;
1348
1349 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."adherent";
1350 $sql .= " WHERE login='".$this->db->escape($login)."'";
1351 $sql .= " AND entity = ".$conf->entity;
1352
1353 $resql = $this->db->query($sql);
1354 if ($resql) {
1355 if ($this->db->num_rows($resql)) {
1356 $obj = $this->db->fetch_object($resql);
1357 $this->fetch($obj->rowid);
1358 }
1359 } else {
1360 dol_print_error($this->db);
1361 }
1362 }
1363
1364 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1372 public function fetch_name($firstname, $lastname)
1373 {
1374 // phpcs:enable
1375 global $conf;
1376
1377 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."adherent";
1378 $sql .= " WHERE firstname='".$this->db->escape($firstname)."'";
1379 $sql .= " AND lastname='".$this->db->escape($lastname)."'";
1380 $sql .= " AND entity = ".$conf->entity;
1381
1382 $resql = $this->db->query($sql);
1383 if ($resql) {
1384 if ($this->db->num_rows($resql)) {
1385 $obj = $this->db->fetch_object($resql);
1386 $this->fetch($obj->rowid);
1387 }
1388 } else {
1389 dol_print_error($this->db);
1390 }
1391 }
1392
1404 public function fetch($rowid, $ref = '', $fk_soc = 0, $ref_ext = '', $fetch_optionals = true, $fetch_subscriptions = true)
1405 {
1406 global $langs;
1407
1408 $sql = "SELECT d.rowid, d.ref, d.ref_ext, d.civility as civility_code, d.gender, d.firstname, d.lastname,";
1409 $sql .= " d.societe as company, d.fk_soc, d.statut, d.public, d.address, d.zip, d.town, d.note_private,";
1410 $sql .= " d.note_public,";
1411 $sql .= " d.email, d.url, d.socialnetworks, d.phone, d.phone_perso, d.phone_mobile, d.login, d.pass, d.pass_crypted,";
1412 $sql .= " d.photo, d.fk_adherent_type, d.morphy, d.entity,";
1413 $sql .= " d.datec as datec,";
1414 $sql .= " d.tms as datem,";
1415 $sql .= " d.datefin as datefin, d.default_lang,";
1416 $sql .= " d.birth as birthday,";
1417 $sql .= " d.datevalid as datev,";
1418 $sql .= " d.country,";
1419 $sql .= " d.state_id,";
1420 $sql .= " d.model_pdf,";
1421 $sql .= " c.rowid as country_id, c.code as country_code, c.label as country,";
1422 $sql .= " dep.nom as state, dep.code_departement as state_code,";
1423 $sql .= " t.libelle as type, t.subscription as subscription,";
1424 $sql .= " u.rowid as user_id, u.login as user_login";
1425 $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as t, ".MAIN_DB_PREFIX."adherent as d";
1426 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON d.country = c.rowid";
1427 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as dep ON d.state_id = dep.rowid";
1428 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON d.rowid = u.fk_member";
1429 $sql .= " WHERE d.fk_adherent_type = t.rowid";
1430 if ($rowid) {
1431 $sql .= " AND d.rowid=".((int) $rowid);
1432 } elseif ($ref || $fk_soc) {
1433 $sql .= " AND d.entity IN (".getEntity('adherent').")";
1434 if ($ref) {
1435 $sql .= " AND d.ref='".$this->db->escape($ref)."'";
1436 } elseif ($fk_soc > 0) {
1437 $sql .= " AND d.fk_soc=".((int) $fk_soc);
1438 }
1439 } elseif ($ref_ext) {
1440 $sql .= " AND d.ref_ext='".$this->db->escape($ref_ext)."'";
1441 }
1442
1443 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
1444 $resql = $this->db->query($sql);
1445 if ($resql) {
1446 if ($this->db->num_rows($resql)) {
1447 $obj = $this->db->fetch_object($resql);
1448
1449 $this->entity = $obj->entity;
1450 $this->id = $obj->rowid;
1451 $this->ref = $obj->ref;
1452 $this->ref_ext = $obj->ref_ext;
1453
1454 $this->civility_id = $obj->civility_code; // Bad. Kept for backward compatibility
1455 $this->civility_code = $obj->civility_code;
1456 $this->civility = $obj->civility_code ? ($langs->trans("Civility".$obj->civility_code) != "Civility".$obj->civility_code ? $langs->trans("Civility".$obj->civility_code) : $obj->civility_code) : '';
1457
1458 $this->firstname = $obj->firstname;
1459 $this->lastname = $obj->lastname;
1460 $this->gender = $obj->gender;
1461 $this->login = $obj->login;
1462 $this->societe = $obj->company;
1463 $this->company = $obj->company;
1464 $this->socid = $obj->fk_soc;
1465 $this->fk_soc = $obj->fk_soc; // For backward compatibility
1466 $this->address = $obj->address;
1467 $this->zip = $obj->zip;
1468 $this->town = $obj->town;
1469
1470 $this->pass = $obj->pass;
1471 $this->pass_indatabase = $obj->pass;
1472 $this->pass_indatabase_crypted = $obj->pass_crypted;
1473
1474 $this->state_id = $obj->state_id;
1475 $this->state_code = $obj->state_id ? $obj->state_code : '';
1476 $this->state = $obj->state_id ? $obj->state : '';
1477
1478 $this->country_id = $obj->country_id;
1479 $this->country_code = $obj->country_code;
1480 if ($langs->trans("Country".$obj->country_code) != "Country".$obj->country_code) {
1481 $this->country = $langs->transnoentitiesnoconv("Country".$obj->country_code);
1482 } else {
1483 $this->country = $obj->country;
1484 }
1485
1486 $this->phone = $obj->phone;
1487 $this->phone_perso = $obj->phone_perso;
1488 $this->phone_mobile = $obj->phone_mobile;
1489 $this->email = $obj->email;
1490 $this->url = $obj->url;
1491
1492 $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks, true) : array());
1493
1494 $this->photo = $obj->photo;
1495 $this->statut = $obj->statut;
1496 $this->status = $obj->statut;
1497 $this->public = $obj->public;
1498
1499 $this->datec = $this->db->jdate($obj->datec);
1500 $this->date_creation = $this->db->jdate($obj->datec);
1501 $this->datem = $this->db->jdate($obj->datem);
1502 $this->date_modification = $this->db->jdate($obj->datem);
1503 $this->datefin = $this->db->jdate($obj->datefin);
1504 $this->datevalid = $this->db->jdate($obj->datev);
1505 $this->date_validation = $this->db->jdate($obj->datev);
1506 $this->birth = $this->db->jdate($obj->birthday);
1507
1508 $this->default_lang = $obj->default_lang;
1509
1510 $this->note_private = $obj->note_private;
1511 $this->note_public = $obj->note_public;
1512 $this->morphy = $obj->morphy;
1513
1514 $this->typeid = $obj->fk_adherent_type;
1515 $this->type = $obj->type;
1516 $this->need_subscription = $obj->subscription;
1517
1518 $this->user_id = $obj->user_id;
1519 $this->user_login = $obj->user_login;
1520
1521 $this->model_pdf = $obj->model_pdf;
1522
1523 // Retrieve all extrafield
1524 // fetch optionals attributes and labels
1525 if ($fetch_optionals) {
1526 $this->fetch_optionals();
1527 }
1528
1529 // Load other properties
1530 if ($fetch_subscriptions) {
1531 $result = $this->fetch_subscriptions();
1532 }
1533
1534 return $this->id;
1535 } else {
1536 return 0;
1537 }
1538 } else {
1539 $this->error = $this->db->lasterror();
1540 return -1;
1541 }
1542 }
1543
1544
1545 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1554 public function fetch_subscriptions()
1555 {
1556 // phpcs:enable
1557 global $langs;
1558
1559 require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
1560
1561 $sql = "SELECT c.rowid, c.fk_adherent, c.fk_type, c.subscription, c.note as note_public, c.fk_bank,";
1562 $sql .= " c.tms as datem,";
1563 $sql .= " c.datec as datec,";
1564 $sql .= " c.dateadh as dateh,";
1565 $sql .= " c.datef as datef";
1566 $sql .= " FROM ".MAIN_DB_PREFIX."subscription as c";
1567 $sql .= " WHERE c.fk_adherent = ".((int) $this->id);
1568 $sql .= " ORDER BY c.dateadh";
1569 dol_syslog(get_class($this)."::fetch_subscriptions", LOG_DEBUG);
1570
1571 $resql = $this->db->query($sql);
1572 if ($resql) {
1573 $this->subscriptions = array();
1574
1575 $i = 0;
1576 while ($obj = $this->db->fetch_object($resql)) {
1577 if ($i == 0) {
1578 $this->first_subscription_date = $this->db->jdate($obj->datec);
1579 $this->first_subscription_date_start = $this->db->jdate($obj->dateh);
1580 $this->first_subscription_date_end = $this->db->jdate($obj->datef);
1581 $this->first_subscription_amount = $obj->subscription;
1582 }
1583 $this->last_subscription_date = $this->db->jdate($obj->datec);
1584 $this->last_subscription_date_start = $this->db->jdate($obj->dateh);
1585 $this->last_subscription_date_end = $this->db->jdate($obj->datef);
1586 $this->last_subscription_amount = $obj->subscription;
1587
1588 $subscription = new Subscription($this->db);
1589 $subscription->id = $obj->rowid;
1590 $subscription->fk_adherent = $obj->fk_adherent;
1591 $subscription->fk_type = $obj->fk_type;
1592 $subscription->amount = $obj->subscription;
1593 $subscription->note = $obj->note_public;
1594 $subscription->note_public = $obj->note_public;
1595 $subscription->fk_bank = $obj->fk_bank;
1596 $subscription->datem = $this->db->jdate($obj->datem);
1597 $subscription->datec = $this->db->jdate($obj->datec);
1598 $subscription->dateh = $this->db->jdate($obj->dateh);
1599 $subscription->datef = $this->db->jdate($obj->datef);
1600
1601 $this->subscriptions[] = $subscription;
1602
1603 $i++;
1604 }
1605 return 1;
1606 } else {
1607 $this->error = $this->db->error().' sql='.$sql;
1608 return -1;
1609 }
1610 }
1611
1612
1619 public function fetchPartnerships($mode)
1620 {
1621 global $langs;
1622
1623 require_once DOL_DOCUMENT_ROOT.'/partnership/class/partnership.class.php';
1624
1625
1626 $this->partnerships[] = array();
1627
1628 return 1;
1629 }
1630
1631
1647 public function subscription($date, $amount, $accountid = 0, $operation = '', $label = '', $num_chq = '', $emetteur_nom = '', $emetteur_banque = '', $datesubend = 0, $fk_type = null)
1648 {
1649 global $conf, $langs, $user;
1650
1651 require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
1652
1653 $error = 0;
1654
1655 // Clean parameters
1656 if (!$amount) {
1657 $amount = 0;
1658 }
1659
1660 $this->db->begin();
1661
1662 if ($datesubend) {
1663 $datefin = $datesubend;
1664 } else {
1665 // If no end date, end date = date + 1 year - 1 day
1666 $datefin = dol_time_plus_duree($date, 1, 'y');
1667 $datefin = dol_time_plus_duree($datefin, -1, 'd');
1668 }
1669
1670 // Create subscription
1671 $subscription = new Subscription($this->db);
1672 $subscription->fk_adherent = $this->id;
1673 $subscription->dateh = $date; // Date of new subscription
1674 $subscription->datef = $datefin; // End data of new subscription
1675 $subscription->amount = $amount;
1676 $subscription->note = $label; // deprecated
1677 $subscription->note_public = $label;
1678 $subscription->fk_type = $fk_type;
1679
1680 $rowid = $subscription->create($user);
1681 if ($rowid > 0) {
1682 // Update denormalized subscription end date (read database subscription to find values)
1683 // This will also update this->datefin
1684 $result = $this->update_end_date($user);
1685 if ($result > 0) {
1686 // Change properties of object (used by triggers)
1687 $this->last_subscription_date = dol_now();
1688 $this->last_subscription_date_start = $date;
1689 $this->last_subscription_date_end = $datefin;
1690 $this->last_subscription_amount = $amount;
1691 }
1692
1693 if (!$error) {
1694 $this->db->commit();
1695 return $rowid;
1696 } else {
1697 $this->db->rollback();
1698 return -2;
1699 }
1700 } else {
1701 $this->setErrorsFromObject($subscription);
1702 $this->db->rollback();
1703 return -1;
1704 }
1705 }
1706
1707
1727 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 = '')
1728 {
1729 global $conf, $langs, $user, $mysoc;
1730
1731 $error = 0;
1732
1733 $this->invoice = null; // This will contains invoice if an invoice is created
1734
1735 dol_syslog("subscriptionComplementaryActions subscriptionid=".$subscriptionid." option=".$option." accountid=".$accountid." datesubscription=".$datesubscription." paymentdate=".
1736 $paymentdate." label=".$label." amount=".$amount." num_chq=".$num_chq." autocreatethirdparty=".$autocreatethirdparty);
1737
1738 // Insert into bank account directlty (if option chosen for) + link to llx_subscription if option is 'bankdirect'
1739 if ($option == 'bankdirect' && $accountid) {
1740 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
1741
1742 $acct = new Account($this->db);
1743 $result = $acct->fetch($accountid);
1744
1745 $dateop = $paymentdate;
1746
1747 $insertid = $acct->addline($dateop, $operation, $label, $amount, $num_chq, 0, $user, $emetteur_nom, $emetteur_banque);
1748 if ($insertid > 0) {
1749 $inserturlid = $acct->add_url_line($insertid, $this->id, DOL_URL_ROOT.'/adherents/card.php?rowid=', $this->getFullName($langs), 'member');
1750 if ($inserturlid > 0) {
1751 // Update table subscription
1752 $sql = "UPDATE ".MAIN_DB_PREFIX."subscription SET fk_bank=".((int) $insertid);
1753 $sql .= " WHERE rowid=".((int) $subscriptionid);
1754
1755 dol_syslog("subscription::subscription", LOG_DEBUG);
1756 $resql = $this->db->query($sql);
1757 if (!$resql) {
1758 $error++;
1759 $this->error = $this->db->lasterror();
1760 $this->errors[] = $this->error;
1761 }
1762 } else {
1763 $error++;
1764 $this->setErrorsFromObject($acct);
1765 }
1766 } else {
1767 $error++;
1768 $this->setErrorsFromObject($acct);
1769 }
1770 }
1771
1772 // If option chosen, we create invoice
1773 if (($option == 'bankviainvoice' && $accountid) || $option == 'invoiceonly') {
1774 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1775 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/paymentterm.class.php';
1776
1777 $invoice = new Facture($this->db);
1778 $customer = new Societe($this->db);
1779
1780 if (!$error) {
1781 if (!($this->fk_soc > 0)) { // If not yet linked to a company
1782 if ($autocreatethirdparty) {
1783 // Create a linked thirdparty to member
1784 $companyalias = '';
1785 $fullname = $this->getFullName($langs);
1786
1787 if ($this->morphy == 'mor') {
1788 $companyname = $this->company;
1789 if (!empty($fullname)) {
1790 $companyalias = $fullname;
1791 }
1792 } else {
1793 $companyname = $fullname;
1794 if (!empty($this->company)) {
1795 $companyalias = $this->company;
1796 }
1797 }
1798
1799 $result = $customer->create_from_member($this, $companyname, $companyalias);
1800 if ($result < 0) {
1801 $this->error = $customer->error;
1802 $this->errors = $customer->errors;
1803 $error++;
1804 } else {
1805 $this->fk_soc = $result;
1806 }
1807 } else {
1808 $langs->load("errors");
1809 $this->error = $langs->trans("ErrorMemberNotLinkedToAThirpartyLinkOrCreateFirst");
1810 $this->errors[] = $this->error;
1811 $error++;
1812 }
1813 }
1814 }
1815 if (!$error) {
1816 $result = $customer->fetch($this->fk_soc);
1817 if ($result <= 0) {
1818 $this->error = $customer->error;
1819 $this->errors = $customer->errors;
1820 $error++;
1821 }
1822 }
1823
1824 if (!$error) {
1825 // Create draft invoice
1826 $invoice->type = Facture::TYPE_STANDARD;
1827 $invoice->cond_reglement_id = $customer->cond_reglement_id;
1828 if (empty($invoice->cond_reglement_id)) {
1829 $paymenttermstatic = new PaymentTerm($this->db);
1830 $invoice->cond_reglement_id = $paymenttermstatic->getDefaultId();
1831 if (empty($invoice->cond_reglement_id)) {
1832 $error++;
1833 $this->error = 'ErrorNoPaymentTermRECEPFound';
1834 $this->errors[] = $this->error;
1835 }
1836 }
1837 $invoice->socid = $this->fk_soc;
1838 //$invoice->date = $datesubscription;
1839 $invoice->date = dol_now();
1840
1841 // Possibility to add external linked objects with hooks
1842 $invoice->linked_objects['subscription'] = $subscriptionid;
1843 if (GETPOSTISARRAY('other_linked_objects')) {
1844 $invoice->linked_objects = array_merge($invoice->linked_objects, GETPOST('other_linked_objects', 'array:int'));
1845 }
1846
1847 $result = $invoice->create($user);
1848 if ($result <= 0) {
1849 $this->error = $invoice->error;
1850 $this->errors = $invoice->errors;
1851 $error++;
1852 } else {
1853 $this->invoice = $invoice;
1854 }
1855 }
1856
1857 if (!$error) {
1858 // Add line to draft invoice
1859 $idprodsubscription = 0;
1860 if (getDolGlobalString('ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS') && (isModEnabled("product") || isModEnabled("service"))) {
1861 $idprodsubscription = getDolGlobalString('ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS');
1862 }
1863
1864 $vattouse = 0;
1865 if (getDolGlobalString('ADHERENT_VAT_FOR_SUBSCRIPTIONS') == 'defaultforfoundationcountry') {
1866 $vattouse = get_default_tva($mysoc, $mysoc, $idprodsubscription);
1867 }
1868 //print xx".$vattouse." - ".$mysoc." - ".$customer;exit;
1869 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1870 $result = $invoice->addline($label, 0, 1, $vattouse, 0, 0, $idprodsubscription, 0, $datesubscription, '', 0, 0, 0, 'TTC', $amount, 1);
1871 if ($result <= 0) {
1872 $this->error = $invoice->error;
1873 $this->errors = $invoice->errors;
1874 $error++;
1875 }
1876 }
1877
1878 if (!$error) {
1879 // Validate invoice
1880 $result = $invoice->validate($user);
1881 if ($result <= 0) {
1882 $this->error = $invoice->error;
1883 $this->errors = $invoice->errors;
1884 $error++;
1885 }
1886 }
1887
1888 if (!$error) {
1889 // TODO Link invoice with subscription ?
1890 }
1891
1892 // Add payment onto invoice
1893 if (!$error && $option == 'bankviainvoice' && $accountid) {
1894 require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
1895 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
1896 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
1897
1898 $amounts = array();
1899 $amounts[$invoice->id] = (float) price2num($amount);
1900
1901 $paiement = new Paiement($this->db);
1902 $paiement->datepaye = $paymentdate;
1903 $paiement->amounts = $amounts;
1904 $paiement->paiementcode = $operation;
1905 $paiement->paiementid = dol_getIdFromCode($this->db, $operation, 'c_paiement', 'code', 'id', 1);
1906 $paiement->num_payment = $num_chq;
1907 $paiement->note_public = $label;
1908 $paiement->ext_payment_id = $ext_payment_id;
1909 $paiement->ext_payment_site = $ext_payment_site;
1910
1911 if (!$error) {
1912 // Create payment line for invoice
1913 $paiement_id = $paiement->create($user);
1914 if (!($paiement_id > 0)) {
1915 $this->error = $paiement->error;
1916 $this->errors = $paiement->errors;
1917 $error++;
1918 }
1919 }
1920
1921 if (!$error) {
1922 // Add transaction into bank account
1923 $bank_line_id = $paiement->addPaymentToBank($user, 'payment', '(SubscriptionPayment)', $accountid, $emetteur_nom, $emetteur_banque);
1924 if (!($bank_line_id > 0)) {
1925 $this->error = $paiement->error;
1926 $this->errors = $paiement->errors;
1927 $error++;
1928 }
1929 }
1930
1931 if (!$error && !empty($bank_line_id)) {
1932 // Update fk_bank into subscription table
1933 $sql = 'UPDATE '.MAIN_DB_PREFIX.'subscription SET fk_bank='.((int) $bank_line_id);
1934 $sql .= ' WHERE rowid='.((int) $subscriptionid);
1935
1936 $result = $this->db->query($sql);
1937 if (!$result) {
1938 $error++;
1939 }
1940 }
1941
1942 if (!$error) {
1943 // Set invoice as paid
1944 $invoice->setPaid($user);
1945 }
1946 }
1947
1948 if (!$error) {
1949 // Define output language
1950 $outputlangs = $langs;
1951 $newlang = '';
1952 $lang_id = GETPOST('lang_id');
1953 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && !empty($lang_id)) {
1954 $newlang = $lang_id;
1955 }
1956 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
1957 $newlang = $customer->default_lang;
1958 }
1959 if (!empty($newlang)) {
1960 $outputlangs = new Translate("", $conf);
1961 $outputlangs->setDefaultLang($newlang);
1962 }
1963 // Generate PDF (whatever is option MAIN_DISABLE_PDF_AUTOUPDATE) so we can include it into email
1964 //if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE'))
1965
1966 $invoice->generateDocument($invoice->model_pdf, $outputlangs);
1967 }
1968 }
1969
1970 if ($error) {
1971 return -1;
1972 } else {
1973 return 1;
1974 }
1975 }
1976
1977
1984 public function validate($user)
1985 {
1986 global $langs, $conf;
1987
1988 $error = 0;
1989 $now = dol_now();
1990
1991 // Check parameters
1992 if ($this->statut == self::STATUS_VALIDATED) {
1993 dol_syslog(get_class($this)."::validate statut of member does not allow this", LOG_WARNING);
1994 return 0;
1995 }
1996
1997 $this->db->begin();
1998
1999 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
2000 $sql .= " statut = ".self::STATUS_VALIDATED;
2001 $sql .= ", datevalid = '".$this->db->idate($now)."'";
2002 $sql .= ", fk_user_valid = ".((int) $user->id);
2003 $sql .= " WHERE rowid = ".((int) $this->id);
2004
2005 dol_syslog(get_class($this)."::validate", LOG_DEBUG);
2006 $result = $this->db->query($sql);
2007 if ($result) {
2008 $this->statut = self::STATUS_VALIDATED;
2009
2010 // Call trigger
2011 $result = $this->call_trigger('MEMBER_VALIDATE', $user);
2012 if ($result < 0) {
2013 $error++;
2014 $this->db->rollback();
2015 return -1;
2016 }
2017 // End call triggers
2018
2019 $this->datevalid = $now;
2020
2021 $this->db->commit();
2022 return 1;
2023 } else {
2024 $this->error = $this->db->error();
2025 $this->db->rollback();
2026 return -1;
2027 }
2028 }
2029
2030
2037 public function resiliate($user)
2038 {
2039 global $langs, $conf;
2040
2041 $error = 0;
2042
2043 // Check parameters
2044 if ($this->statut == self::STATUS_RESILIATED) {
2045 dol_syslog(get_class($this)."::resiliate statut of member does not allow this", LOG_WARNING);
2046 return 0;
2047 }
2048
2049 $this->db->begin();
2050
2051 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
2052 $sql .= " statut = ".self::STATUS_RESILIATED;
2053 $sql .= ", fk_user_valid=".$user->id;
2054 $sql .= " WHERE rowid = ".((int) $this->id);
2055
2056 $result = $this->db->query($sql);
2057 if ($result) {
2058 $this->statut = self::STATUS_RESILIATED;
2059
2060 // Call trigger
2061 $result = $this->call_trigger('MEMBER_RESILIATE', $user);
2062 if ($result < 0) {
2063 $error++;
2064 $this->db->rollback();
2065 return -1;
2066 }
2067 // End call triggers
2068
2069 $this->db->commit();
2070 return 1;
2071 } else {
2072 $this->error = $this->db->error();
2073 $this->db->rollback();
2074 return -1;
2075 }
2076 }
2077
2087 public function exclude($user)
2088 {
2089 $error = 0;
2090
2091 // Check parameters
2092 if ($this->statut == self::STATUS_EXCLUDED) {
2093 dol_syslog(get_class($this)."::resiliate statut of member does not allow this", LOG_WARNING);
2094 return 0;
2095 }
2096
2097 $this->db->begin();
2098
2099 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
2100 $sql .= " statut = ".self::STATUS_EXCLUDED;
2101 $sql .= ", fk_user_valid=".$user->id;
2102 $sql .= " WHERE rowid = ".((int) $this->id);
2103
2104 $result = $this->db->query($sql);
2105 if ($result) {
2106 $this->statut = self::STATUS_EXCLUDED;
2107
2108 // Call trigger
2109 $result = $this->call_trigger('MEMBER_EXCLUDE', $user);
2110 if ($result < 0) {
2111 $error++;
2112 $this->db->rollback();
2113 return -1;
2114 }
2115 // End call triggers
2116
2117 $this->db->commit();
2118 return 1;
2119 } else {
2120 $this->error = $this->db->error();
2121 $this->db->rollback();
2122 return -1;
2123 }
2124 }
2125
2126 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2132 public function add_to_abo()
2133 {
2134 // phpcs:enable
2135 global $langs;
2136
2137 include_once DOL_DOCUMENT_ROOT.'/mailmanspip/class/mailmanspip.class.php';
2138 $mailmanspip = new MailmanSpip($this->db);
2139
2140 $err = 0;
2141
2142 // mailman
2143 if (getDolGlobalString('ADHERENT_USE_MAILMAN') && isModEnabled('mailmanspip')) {
2144 $result = $mailmanspip->add_to_mailman($this);
2145
2146 if ($result < 0) {
2147 if (!empty($mailmanspip->error)) {
2148 $this->errors[] = $mailmanspip->error;
2149 }
2150 $err += 1;
2151 }
2152 foreach ($mailmanspip->mladded_ko as $tmplist => $tmpemail) {
2153 $langs->load("errors");
2154 $this->errors[] = $langs->trans("ErrorFailedToAddToMailmanList", $tmpemail, $tmplist);
2155 }
2156 foreach ($mailmanspip->mladded_ok as $tmplist => $tmpemail) {
2157 $langs->load("mailmanspip");
2158 $this->mesgs[] = $langs->trans("SuccessToAddToMailmanList", $tmpemail, $tmplist);
2159 }
2160 }
2161
2162 // spip
2163 if (getDolGlobalString('ADHERENT_USE_SPIP') && isModEnabled('mailmanspip')) {
2164 $result = $mailmanspip->add_to_spip($this);
2165 if ($result < 0) {
2166 $this->errors[] = $mailmanspip->error;
2167 $err += 1;
2168 }
2169 }
2170 if ($err) {
2171 return -$err;
2172 } else {
2173 return 1;
2174 }
2175 }
2176
2177
2178 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2184 public function del_to_abo()
2185 {
2186 // phpcs:enable
2187 global $conf, $langs;
2188
2189 include_once DOL_DOCUMENT_ROOT.'/mailmanspip/class/mailmanspip.class.php';
2190 $mailmanspip = new MailmanSpip($this->db);
2191
2192 $err = 0;
2193
2194 // mailman
2195 if (getDolGlobalString('ADHERENT_USE_MAILMAN')) {
2196 $result = $mailmanspip->del_to_mailman($this);
2197 if ($result < 0) {
2198 if (!empty($mailmanspip->error)) {
2199 $this->errors[] = $mailmanspip->error;
2200 }
2201 $err += 1;
2202 }
2203
2204 foreach ($mailmanspip->mlremoved_ko as $tmplist => $tmpemail) {
2205 $langs->load("errors");
2206 $this->errors[] = $langs->trans("ErrorFailedToRemoveToMailmanList", $tmpemail, $tmplist);
2207 }
2208 foreach ($mailmanspip->mlremoved_ok as $tmplist => $tmpemail) {
2209 $langs->load("mailmanspip");
2210 $this->mesgs[] = $langs->trans("SuccessToRemoveToMailmanList", $tmpemail, $tmplist);
2211 }
2212 }
2213
2214 if (getDolGlobalString('ADHERENT_USE_SPIP') && isModEnabled('mailmanspip')) {
2215 $result = $mailmanspip->del_to_spip($this);
2216 if ($result < 0) {
2217 $this->errors[] = $mailmanspip->error;
2218 $err += 1;
2219 }
2220 }
2221 if ($err) {
2222 // error
2223 return -$err;
2224 } else {
2225 return 1;
2226 }
2227 }
2228
2229
2235 public function getCivilityLabel()
2236 {
2237 global $langs;
2238 $langs->load("dict");
2239
2240 $code = (empty($this->civility_id) ? '' : $this->civility_id);
2241 if (empty($code)) {
2242 return '';
2243 }
2244 return $langs->getLabelFromKey($this->db, "Civility".$code, "c_civility", "code", "label", $code);
2245 }
2246
2253 public function getTooltipContentArray($params)
2254 {
2255 global $langs;
2256
2257 $langs->loadLangs(['members', 'companies']);
2258 $nofetch = !empty($params['nofetch']);
2259
2260 $datas = array();
2261
2262 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
2263 $langs->load("users");
2264 return ['optimize' => $langs->trans("ShowUser")];
2265 }
2266 if (!empty($this->photo)) {
2267 $photo = '<div class="photointooltip floatright">';
2268 $photo .= Form::showphoto('memberphoto', $this, 80, 0, 0, 'photoref photowithmargin photologintooltip', 'small', 0, 1);
2269 $photo .= '</div>';
2270 $datas['photo'] = $photo;
2271 }
2272
2273 $datas['divopen'] = '<div class="centpercent">';
2274 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Member").'</u> '.$this->getLibStatut(4);
2275 if (!empty($this->morphy)) {
2276 $datas['picto'] .= '&nbsp;' . $this->getmorphylib('', 1);
2277 }
2278 if (!empty($this->ref)) {
2279 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
2280 }
2281 if (!empty($this->login)) {
2282 $datas['login'] = '<br><b>'.$langs->trans('Login').':</b> '.$this->login;
2283 }
2284 if (!empty($this->firstname) || !empty($this->lastname)) {
2285 $datas['name'] = '<br><b>'.$langs->trans('Name').':</b> '.$this->getFullName($langs);
2286 }
2287 if (!empty($this->company)) {
2288 $datas['company'] = '<br><b>'.$langs->trans('Company').':</b> '.$this->company;
2289 }
2290 if (!empty($this->email)) {
2291 $datas['email'] = '<br><b>'.$langs->trans("EMail").':</b> '.$this->email;
2292 }
2293 $datas['address'] = '<br><b>'.$langs->trans("Address").':</b> '.dol_format_address($this, 1, ' ', $langs);
2294 // show categories for this record only in ajax to not overload lists
2295 if (isModEnabled('category') && !$nofetch) {
2296 require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
2297 $form = new Form($this->db);
2298 $datas['categories'] = '<br>' . $form->showCategories($this->id, Categorie::TYPE_MEMBER, 1);
2299 }
2300 $datas['divclose'] = '</div>';
2301
2302 return $datas;
2303 }
2304
2318 public function getNomUrl($withpictoimg = 0, $maxlen = 0, $option = 'card', $mode = '', $morecss = '', $save_lastsearch_value = -1, $notooltip = 0, $addlinktonotes = 0)
2319 {
2320 global $conf, $langs, $hookmanager;
2321
2322 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') && $withpictoimg) {
2323 $withpictoimg = 0;
2324 }
2325
2326 $result = '';
2327 $linkstart = '';
2328 $linkend = '';
2329 $classfortooltip = 'classfortooltip';
2330 $dataparams = '';
2331 $params = [
2332 'id' => $this->id,
2333 'objecttype' => $this->element,
2334 'option' => $option,
2335 'nofetch' => 1,
2336 ];
2337 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
2338 $classfortooltip = 'classforajaxtooltip';
2339 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
2340 $label = '';
2341 } else {
2342 $label = implode($this->getTooltipContentArray($params));
2343 }
2344
2345 $url = DOL_URL_ROOT.'/adherents/card.php?rowid='.((int) $this->id);
2346 if ($option == 'subscription') {
2347 $url = DOL_URL_ROOT.'/adherents/subscription.php?rowid='.((int) $this->id);
2348 }
2349
2350 if ($option != 'nolink') {
2351 // Add param to save lastsearch_values or not
2352 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2353 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
2354 $add_save_lastsearch_values = 1;
2355 }
2356 if ($add_save_lastsearch_values) {
2357 $url .= '&save_lastsearch_values=1';
2358 }
2359 }
2360
2361 $linkstart .= '<a href="'.$url.'"';
2362 $linkclose = "";
2363 if (empty($notooltip)) {
2364 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
2365 $langs->load("users");
2366 $label = $langs->trans("ShowUser");
2367 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
2368 }
2369 $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
2370 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
2371 }
2372
2373 $linkstart .= $linkclose.'>';
2374 $linkend = '</a>';
2375
2376 $result .= $linkstart;
2377
2378 if ($withpictoimg) {
2379 $paddafterimage = '';
2380 if (abs($withpictoimg) == 1 || abs($withpictoimg) == 4) {
2381 $morecss .= ' paddingrightonly';
2382 }
2383 // Only picto
2384 if ($withpictoimg > 0) {
2385 $picto = '<span class="nopadding'.($morecss ? ' userimg'.$morecss : '').'">'.img_object('', 'user', $paddafterimage.' '.($notooltip ? '' : $dataparams), 0, 0, $notooltip ? 0 : 1).'</span>';
2386 } else {
2387 // Picto must be a photo
2388 $picto = '<span class="nopadding'.($morecss ? ' userimg'.$morecss : '').'"'.($paddafterimage ? ' '.$paddafterimage : '').'>';
2389 $picto .= Form::showphoto('memberphoto', $this, 0, 0, 0, 'userphoto'.(($withpictoimg == -3 || $withpictoimg == -4) ? 'small' : ''), 'mini', 0, 1);
2390 $picto .= '</span>';
2391 }
2392 $result .= $picto;
2393 }
2394 if (($withpictoimg > -2 && $withpictoimg != 2) || $withpictoimg == -4) {
2395 if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
2396 $result .= '<span class="nopadding valignmiddle'.((!isset($this->statut) || $this->statut) ? '' : ' strikefordisabled').
2397 ($morecss ? ' usertext'.$morecss : '').'">';
2398 }
2399 if ($mode == 'login') {
2400 $result .= dol_trunc($this->login, $maxlen);
2401 } elseif ($mode == 'ref') {
2402 $result .= $this->ref;
2403 } else {
2404 $result .= $this->getFullName($langs, 0, ($mode == 'firstname' ? 2 : ($mode == 'lastname' ? 4 : -1)), $maxlen);
2405 }
2406 if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
2407 $result .= '</span>';
2408 }
2409 }
2410
2411 $result .= $linkend;
2412
2413 if ($addlinktonotes) {
2414 if ($this->note_private) {
2415 $notetoshow = $langs->trans("ViewPrivateNote").':<br>'.dol_string_nohtmltag($this->note_private, 1);
2416 $result .= ' <span class="note inline-block">';
2417 $result .= '<a href="'.DOL_URL_ROOT.'/adherents/note.php?id='.$this->id.'" class="classfortooltip" title="'.dol_escape_htmltag($notetoshow).'">';
2418 $result .= img_picto('', 'note');
2419 $result .= '</a>';
2420 $result .= '</span>';
2421 }
2422 }
2423 global $action;
2424 $hookmanager->initHooks(array($this->element . 'dao'));
2425 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
2426 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
2427 if ($reshook > 0) {
2428 $result = $hookmanager->resPrint;
2429 } else {
2430 $result .= $hookmanager->resPrint;
2431 }
2432 return $result;
2433 }
2434
2441 public function getLibStatut($mode = 0)
2442 {
2443 return $this->LibStatut($this->statut, $this->need_subscription, $this->datefin, $mode);
2444 }
2445
2446 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2456 public function LibStatut($status, $need_subscription, $date_end_subscription, $mode = 0)
2457 {
2458 // phpcs:enable
2459 global $langs;
2460 $langs->load("members");
2461
2462 $statusType = '';
2463 $labelStatus = '';
2464 $labelStatusShort = '';
2465
2466 if ($status == self::STATUS_DRAFT) {
2467 $statusType = 'status0';
2468 $labelStatus = $langs->trans("MemberStatusDraft");
2469 $labelStatusShort = $langs->trans("MemberStatusDraftShort");
2470 } elseif ($status >= self::STATUS_VALIDATED) {
2471 if ($need_subscription === 0) {
2472 $statusType = 'status4';
2473 $labelStatus = $langs->trans("Validated").' - '.$langs->trans("MemberStatusNoSubscription");
2474 $labelStatusShort = $langs->trans("MemberStatusNoSubscriptionShort");
2475 } elseif (!$date_end_subscription) {
2476 $statusType = 'status1';
2477 $labelStatus = $langs->trans("Validated").' - '.$langs->trans("WaitingSubscription");
2478 $labelStatusShort = $langs->trans("WaitingSubscriptionShort");
2479 } elseif ($date_end_subscription < dol_now()) { // expired
2480 $statusType = 'status8';
2481 $labelStatus = $langs->trans("Validated").' - '.$langs->trans("MemberStatusActiveLate");
2482 $labelStatusShort = $langs->trans("MemberStatusActiveLateShort");
2483 } else {
2484 $statusType = 'status4';
2485 $labelStatus = $langs->trans("Validated").' - '.$langs->trans("MemberStatusPaid");
2486 $labelStatusShort = $langs->trans("MemberStatusPaidShort");
2487 }
2488 } elseif ($status == self::STATUS_RESILIATED) {
2489 $statusType = 'status6';
2490 $labelStatus = $langs->transnoentitiesnoconv("MemberStatusResiliated");
2491 $labelStatusShort = $langs->transnoentitiesnoconv("MemberStatusResiliatedShort");
2492 } elseif ($status == self::STATUS_EXCLUDED) {
2493 $statusType = 'status10';
2494 $labelStatus = $langs->transnoentitiesnoconv("MemberStatusExcluded");
2495 $labelStatusShort = $langs->transnoentitiesnoconv("MemberStatusExcludedShort");
2496 }
2497
2498 return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode);
2499 }
2500
2501
2507 public function loadStateBoard()
2508 {
2509 global $conf;
2510
2511 $this->nb = array();
2512
2513 $sql = "SELECT count(a.rowid) as nb";
2514 $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a";
2515 $sql .= " WHERE a.statut > 0";
2516 $sql .= " AND a.entity IN (".getEntity('adherent').")";
2517
2518 $resql = $this->db->query($sql);
2519 if ($resql) {
2520 while ($obj = $this->db->fetch_object($resql)) {
2521 $this->nb["members"] = $obj->nb;
2522 }
2523 $this->db->free($resql);
2524 return 1;
2525 } else {
2526 dol_print_error($this->db);
2527 $this->error = $this->db->error();
2528 return -1;
2529 }
2530 }
2531
2532 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2540 public function load_board($user, $mode)
2541 {
2542 // phpcs:enable
2543 global $conf, $langs;
2544
2545 if ($user->socid) {
2546 return -1; // protection pour eviter appel par utilisateur externe
2547 }
2548
2549 $now = dol_now();
2550
2551 $sql = "SELECT a.rowid, a.datefin, a.statut";
2552 $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a";
2553 $sql .= ", ".MAIN_DB_PREFIX."adherent_type as t";
2554 $sql .= " WHERE a.fk_adherent_type = t.rowid";
2555 if ($mode == 'expired') {
2556 $sql .= " AND a.statut = ".self::STATUS_VALIDATED;
2557 $sql .= " AND a.entity IN (".getEntity('adherent').")";
2558 $sql .= " AND ((a.datefin IS NULL or a.datefin < '".$this->db->idate($now)."') AND t.subscription = '1')";
2559 } elseif ($mode == 'shift') {
2560 $sql .= " AND a.statut = ".self::STATUS_DRAFT;
2561 $sql .= " AND a.entity IN (".getEntity('adherent').")";
2562 }
2563
2564 $resql = $this->db->query($sql);
2565 if ($resql) {
2566 $langs->load("members");
2567
2568 $warning_delay = 0;
2569 $url = '';
2570 $label = '';
2571 $labelShort = '';
2572
2573 if ($mode == 'expired') {
2574 $warning_delay = $conf->adherent->subscription->warning_delay / 60 / 60 / 24;
2575 $label = $langs->trans("MembersWithSubscriptionToReceive");
2576 $labelShort = $langs->trans("MembersWithSubscriptionToReceiveShort");
2577 $url = DOL_URL_ROOT.'/adherents/list.php?mainmenu=members&amp;statut='.self::STATUS_VALIDATED.'&amp;filter=outofdate';
2578 } elseif ($mode == 'shift') {
2579 $warning_delay = $conf->adherent->subscription->warning_delay / 60 / 60 / 24;
2580 $url = DOL_URL_ROOT.'/adherents/list.php?mainmenu=members&amp;statut='.self::STATUS_DRAFT;
2581 $label = $langs->trans("MembersListToValid");
2582 $labelShort = $langs->trans("ToValidate");
2583 }
2584
2585 $response = new WorkboardResponse();
2586 $response->warning_delay = $warning_delay;
2587 $response->label = $label;
2588 $response->labelShort = $labelShort;
2589 $response->url = $url;
2590 $response->img = img_object('', "user");
2591
2592 $adherentstatic = new Adherent($this->db);
2593
2594 while ($obj = $this->db->fetch_object($resql)) {
2595 $response->nbtodo++;
2596
2597 $adherentstatic->datefin = $this->db->jdate($obj->datefin);
2598 $adherentstatic->statut = $obj->statut;
2599
2600 if ($adherentstatic->hasDelay()) {
2601 $response->nbtodolate++;
2602 }
2603 }
2604
2605 return $response;
2606 } else {
2607 dol_print_error($this->db);
2608 $this->error = $this->db->error();
2609 return -1;
2610 }
2611 }
2612
2613
2625 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
2626 {
2627 global $conf, $langs;
2628
2629 $langs->load("orders");
2630
2631 if (!dol_strlen($modele)) {
2632 $modele = 'standard';
2633
2634 if ($this->model_pdf) {
2635 $modele = $this->model_pdf;
2636 } elseif (getDolGlobalString('ADHERENT_ADDON_PDF')) {
2637 $modele = getDolGlobalString('ADHERENT_ADDON_PDF');
2638 }
2639 }
2640
2641 $modelpath = "core/modules/member/doc/";
2642
2643 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
2644 }
2645
2646
2654 public function initAsSpecimen()
2655 {
2656 global $user, $langs;
2657 $now = dol_now();
2658
2659 // Initialise parameters
2660 $this->id = 0;
2661 $this->ref = 'ABC001';
2662 $this->entity = 1;
2663 $this->specimen = 1;
2664 $this->civility_id = 'MR';
2665 $this->lastname = 'DOLIBARR';
2666 $this->firstname = 'SPECIMEN';
2667 $this->gender = 'man';
2668 $this->login = 'dolibspec';
2669 $this->pass = 'dolibspec';
2670 $this->company = 'Societe ABC';
2671 $this->address = '61 jump street';
2672 $this->zip = '75000';
2673 $this->town = 'Paris';
2674 $this->country_id = 1;
2675 $this->country_code = 'FR';
2676 $this->country = 'France';
2677 $this->morphy = 'mor';
2678 $this->email = 'specimen@specimen.com';
2679 $this->socialnetworks = array(
2680 'skype' => 'skypepseudo',
2681 'twitter' => 'twitterpseudo',
2682 'facebook' => 'facebookpseudo',
2683 'linkedin' => 'linkedinpseudo',
2684 );
2685 $this->phone = '0999999999';
2686 $this->phone_perso = '0999999998';
2687 $this->phone_mobile = '0999999997';
2688 $this->note_public = 'This is a public note';
2689 $this->note_private = 'This is a private note';
2690 $this->birth = $now;
2691 $this->photo = '';
2692 $this->public = 1;
2693 $this->statut = self::STATUS_DRAFT;
2694 $this->status = self::STATUS_DRAFT;
2695
2696 $this->datefin = $now;
2697 $this->datevalid = $now;
2698 $this->default_lang = '';
2699
2700 $this->typeid = 1; // Id type adherent
2701 $this->type = 'Type adherent'; // Libelle type adherent
2702 $this->need_subscription = 0;
2703
2704 $this->first_subscription_date = $now;
2705 $this->first_subscription_date_start = $this->first_subscription_date;
2706 $this->first_subscription_date_end = dol_time_plus_duree($this->first_subscription_date_start, 1, 'y');
2707 $this->first_subscription_amount = 10;
2708
2709 $this->last_subscription_date = $this->first_subscription_date;
2710 $this->last_subscription_date_start = $this->first_subscription_date;
2711 $this->last_subscription_date_end = dol_time_plus_duree($this->last_subscription_date_start, 1, 'y');
2712 $this->last_subscription_amount = 10;
2713 return 1;
2714 }
2715
2716
2717 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2718 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2728 public function _load_ldap_dn($info, $mode = 0)
2729 {
2730 // phpcs:enable
2731 global $conf;
2732 $dn = '';
2733 if ($mode == 0) {
2734 $dn = getDolGlobalString('LDAP_KEY_MEMBERS') . "=".$info[getDolGlobalString('LDAP_KEY_MEMBERS')]."," . getDolGlobalString('LDAP_MEMBER_DN');
2735 }
2736 if ($mode == 1) {
2737 $dn = getDolGlobalString('LDAP_MEMBER_DN');
2738 }
2739 if ($mode == 2) {
2740 $dn = getDolGlobalString('LDAP_KEY_MEMBERS') . "=".$info[getDolGlobalString('LDAP_KEY_MEMBERS')];
2741 }
2742 return $dn;
2743 }
2744
2745
2746 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2747 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2753 public function _load_ldap_info()
2754 {
2755 // phpcs:enable
2756 global $conf, $langs;
2757
2758 $info = array();
2759 $socialnetworks = getArrayOfSocialNetworks();
2760 $keymodified = false;
2761
2762 // Object classes
2763 $info["objectclass"] = explode(',', getDolGlobalString('LDAP_MEMBER_OBJECT_CLASS'));
2764
2765 $this->fullname = $this->getFullName($langs);
2766
2767 // For avoid ldap error when firstname and lastname are empty
2768 if ($this->morphy == 'mor' && (empty($this->fullname) || $this->fullname == $this->company)) {
2769 $this->fullname = $this->company;
2770 $this->lastname = $this->company;
2771 }
2772
2773 // Possible LDAP KEY (constname => varname)
2774 $ldapkey = array(
2775 'LDAP_MEMBER_FIELD_FULLNAME' => 'fullname',
2776 'LDAP_MEMBER_FIELD_NAME' => 'lastname',
2777 'LDAP_MEMBER_FIELD_LOGIN' => 'login',
2778 'LDAP_MEMBER_FIELD_LOGIN_SAMBA' => 'login',
2779 'LDAP_MEMBER_FIELD_MAIL' => 'email'
2780 );
2781
2782 // Member
2783 foreach ($ldapkey as $constname => $varname) {
2784 if (!empty($this->$varname) && getDolGlobalString($constname)) {
2785 $info[getDolGlobalString($constname)] = $this->$varname;
2786
2787 // Check if it is the LDAP key and if its value has been changed
2788 if (getDolGlobalString('LDAP_KEY_MEMBERS') && getDolGlobalString('LDAP_KEY_MEMBERS') == getDolGlobalString($constname)) {
2789 if (!empty($this->oldcopy) && $this->$varname != $this->oldcopy->$varname) {
2790 $keymodified = true; // For check if LDAP key has been modified
2791 }
2792 }
2793 }
2794 }
2795 if ($this->firstname && getDolGlobalString('LDAP_MEMBER_FIELD_FIRSTNAME')) {
2796 $info[getDolGlobalString('LDAP_MEMBER_FIELD_FIRSTNAME')] = $this->firstname;
2797 }
2798 if ($this->poste && getDolGlobalString('LDAP_MEMBER_FIELD_TITLE')) {
2799 $info[getDolGlobalString('LDAP_MEMBER_FIELD_TITLE')] = $this->poste;
2800 }
2801 if ($this->company && getDolGlobalString('LDAP_MEMBER_FIELD_COMPANY')) {
2802 $info[getDolGlobalString('LDAP_MEMBER_FIELD_COMPANY')] = $this->company;
2803 }
2804 if ($this->address && getDolGlobalString('LDAP_MEMBER_FIELD_ADDRESS')) {
2805 $info[getDolGlobalString('LDAP_MEMBER_FIELD_ADDRESS')] = $this->address;
2806 }
2807 if ($this->zip && getDolGlobalString('LDAP_MEMBER_FIELD_ZIP')) {
2808 $info[getDolGlobalString('LDAP_MEMBER_FIELD_ZIP')] = $this->zip;
2809 }
2810 if ($this->town && getDolGlobalString('LDAP_MEMBER_FIELD_TOWN')) {
2811 $info[getDolGlobalString('LDAP_MEMBER_FIELD_TOWN')] = $this->town;
2812 }
2813 if ($this->country_code && getDolGlobalString('LDAP_MEMBER_FIELD_COUNTRY')) {
2814 $info[getDolGlobalString('LDAP_MEMBER_FIELD_COUNTRY')] = $this->country_code;
2815 }
2816 foreach ($socialnetworks as $key => $value) {
2817 if ($this->socialnetworks[$value['label']] && getDolGlobalString('LDAP_MEMBER_FIELD_'.strtoupper($value['label']))) {
2818 $info[getDolGlobalString('LDAP_MEMBER_FIELD_'.strtoupper($value['label']))] = $this->socialnetworks[$value['label']];
2819 }
2820 }
2821 if ($this->phone && getDolGlobalString('LDAP_MEMBER_FIELD_PHONE')) {
2822 $info[getDolGlobalString('LDAP_MEMBER_FIELD_PHONE')] = $this->phone;
2823 }
2824 if ($this->phone_perso && getDolGlobalString('LDAP_MEMBER_FIELD_PHONE_PERSO')) {
2825 $info[getDolGlobalString('LDAP_MEMBER_FIELD_PHONE_PERSO')] = $this->phone_perso;
2826 }
2827 if ($this->phone_mobile && getDolGlobalString('LDAP_MEMBER_FIELD_MOBILE')) {
2828 $info[getDolGlobalString('LDAP_MEMBER_FIELD_MOBILE')] = $this->phone_mobile;
2829 }
2830 if ($this->fax && getDolGlobalString('LDAP_MEMBER_FIELD_FAX')) {
2831 $info[getDolGlobalString('LDAP_MEMBER_FIELD_FAX')] = $this->fax;
2832 }
2833 if ($this->note_private && getDolGlobalString('LDAP_MEMBER_FIELD_DESCRIPTION')) {
2834 $info[getDolGlobalString('LDAP_MEMBER_FIELD_DESCRIPTION')] = dol_string_nohtmltag($this->note_private, 2);
2835 }
2836 if ($this->note_public && getDolGlobalString('LDAP_MEMBER_FIELD_NOTE_PUBLIC')) {
2837 $info[getDolGlobalString('LDAP_MEMBER_FIELD_NOTE_PUBLIC')] = dol_string_nohtmltag($this->note_public, 2);
2838 }
2839 if ($this->birth && getDolGlobalString('LDAP_MEMBER_FIELD_BIRTHDATE')) {
2840 $info[getDolGlobalString('LDAP_MEMBER_FIELD_BIRTHDATE')] = dol_print_date($this->birth, 'dayhourldap');
2841 }
2842 if (isset($this->statut) && getDolGlobalString('LDAP_FIELD_MEMBER_STATUS')) {
2843 $info[getDolGlobalString('LDAP_FIELD_MEMBER_STATUS')] = $this->statut;
2844 }
2845 if ($this->datefin && getDolGlobalString('LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION')) {
2846 $info[getDolGlobalString('LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION')] = dol_print_date($this->datefin, 'dayhourldap');
2847 }
2848
2849 // When password is modified
2850 if (!empty($this->pass)) {
2851 if (getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD')) {
2852 $info[getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD')] = $this->pass; // this->pass = Unencrypted password
2853 }
2854 if (getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')) {
2855 $info[getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')] = dol_hash($this->pass, 'openldap'); // Create OpenLDAP password (see LDAP_PASSWORD_HASH_TYPE)
2856 }
2857 } elseif (getDolGlobalString('LDAP_SERVER_PROTOCOLVERSION') !== '3') {
2858 // Set LDAP password if possible
2859 // If ldap key is modified and LDAPv3 we use ldap_rename function for avoid lose encrypt password
2860 if (getDolGlobalString('DATABASE_PWD_ENCRYPTED')) { // This should be on on default installation
2861 // Just for the case we use old md5 encryption (deprecated, no more used, kept for compatibility)
2862 if (!getDolGlobalString('MAIN_SECURITY_HASH_ALGO') || getDolGlobalString('MAIN_SECURITY_HASH_ALGO') == 'md5') {
2863 if ($this->pass_indatabase_crypted && getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')) {
2864 // Create OpenLDAP MD5 password from Dolibarr MD5 password
2865 // Note: This suppose that "pass_indatabase_crypted" is a md5 (this should not happen anymore)"
2866 $info[getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')] = dolGetLdapPasswordHash($this->pass_indatabase_crypted, 'md5frommd5');
2867 }
2868 }
2869 } elseif (!empty($this->pass_indatabase)) {
2870 // Use $this->pass_indatabase value if exists
2871 if (getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD')) {
2872 $info[getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD')] = $this->pass_indatabase; // $this->pass_indatabase = Unencrypted password
2873 }
2874 if (getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')) {
2875 $info[getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')] = dol_hash($this->pass_indatabase, 'openldap'); // Create OpenLDAP password (see LDAP_PASSWORD_HASH_TYPE)
2876 }
2877 }
2878 }
2879
2880 // Subscriptions
2881 if ($this->first_subscription_date && getDolGlobalString('LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE')) {
2882 $info[getDolGlobalString('LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE')] = dol_print_date($this->first_subscription_date, 'dayhourldap');
2883 }
2884 if (isset($this->first_subscription_amount) && getDolGlobalString('LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT')) {
2885 $info[getDolGlobalString('LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT')] = $this->first_subscription_amount;
2886 }
2887 if ($this->last_subscription_date && getDolGlobalString('LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE')) {
2888 $info[getDolGlobalString('LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE')] = dol_print_date($this->last_subscription_date, 'dayhourldap');
2889 }
2890 if (isset($this->last_subscription_amount) && getDolGlobalString('LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT')) {
2891 $info[getDolGlobalString('LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT')] = $this->last_subscription_amount;
2892 }
2893
2894 return $info;
2895 }
2896
2897
2904 public function info($id)
2905 {
2906 $sql = 'SELECT a.rowid, a.datec as datec,';
2907 $sql .= ' a.datevalid as datev,';
2908 $sql .= ' a.tms as datem,';
2909 $sql .= ' a.fk_user_author, a.fk_user_valid, a.fk_user_mod';
2910 $sql .= ' FROM '.MAIN_DB_PREFIX.'adherent as a';
2911 $sql .= ' WHERE a.rowid = '.((int) $id);
2912
2913 dol_syslog(get_class($this)."::info", LOG_DEBUG);
2914 $result = $this->db->query($sql);
2915 if ($result) {
2916 if ($this->db->num_rows($result)) {
2917 $obj = $this->db->fetch_object($result);
2918
2919 $this->id = $obj->rowid;
2920
2921 $this->user_creation_id = $obj->fk_user_author;
2922 $this->user_validation_id = $obj->fk_user_valid;
2923 $this->user_modification_id = $obj->fk_user_mod;
2924 $this->date_creation = $this->db->jdate($obj->datec);
2925 $this->date_validation = $this->db->jdate($obj->datev);
2926 $this->date_modification = $this->db->jdate($obj->datem);
2927 }
2928
2929 $this->db->free($result);
2930 } else {
2931 dol_print_error($this->db);
2932 }
2933 }
2934
2940 public function getNbOfEMailings()
2941 {
2942 $sql = "SELECT count(mc.email) as nb";
2943 $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
2944 $sql .= " WHERE mc.email = '".$this->db->escape($this->email)."'";
2945 $sql .= " AND mc.statut NOT IN (-1,0)"; // -1 erreur, 0 non envoye, 1 envoye avec success
2946
2947 $resql = $this->db->query($sql);
2948 if ($resql) {
2949 $obj = $this->db->fetch_object($resql);
2950 $nb = $obj->nb;
2951
2952 $this->db->free($resql);
2953 return $nb;
2954 } else {
2955 $this->error = $this->db->error();
2956 return -1;
2957 }
2958 }
2959
2970 public function setCategories($categories)
2971 {
2972 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
2973 return parent::setCategoriesCommon($categories, Categorie::TYPE_MEMBER);
2974 }
2975
2984 public static function replaceThirdparty($db, $origin_id, $dest_id)
2985 {
2986 $tables = array('adherent');
2987
2988 return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
2989 }
2990
2996 public function hasDelay()
2997 {
2998 global $conf;
2999
3000 //Only valid members
3001 if ($this->statut != self::STATUS_VALIDATED) {
3002 return false;
3003 }
3004 if (!$this->datefin) {
3005 return false;
3006 }
3007
3008 $now = dol_now();
3009
3010 return $this->datefin < ($now - $conf->adherent->subscription->warning_delay);
3011 }
3012
3013
3021 public function sendReminderForExpiredSubscription($daysbeforeendlist = '10')
3022 {
3023 global $conf, $langs, $mysoc, $user;
3024
3025 $error = 0;
3026 $this->output = '';
3027 $this->error = '';
3028
3029 $blockingerrormsg = '';
3030
3031 if (!isModEnabled('member')) { // Should not happen. If module disabled, cron job should not be visible.
3032 $langs->load("agenda");
3033 $this->output = $langs->trans('ModuleNotEnabled', $langs->transnoentitiesnoconv("Adherent"));
3034 return 0;
3035 }
3036 if (!getDolGlobalString('MEMBER_REMINDER_EMAIL')) {
3037 $langs->load("agenda");
3038 $this->output = $langs->trans('EventRemindersByEmailNotEnabled', $langs->transnoentitiesnoconv("Adherent"));
3039 return 0;
3040 }
3041
3042 $now = dol_now();
3043 $nbok = 0;
3044 $nbko = 0;
3045
3046 $listofmembersok = array();
3047 $listofmembersko = array();
3048
3049 $arraydaysbeforeend = explode(';', $daysbeforeendlist);
3050 foreach ($arraydaysbeforeend as $daysbeforeend) { // Loop on each delay
3051 dol_syslog(__METHOD__.' - Process delta = '.$daysbeforeend, LOG_DEBUG);
3052
3053 if (!is_numeric($daysbeforeend)) {
3054 $blockingerrormsg = "Value for delta is not a numeric value";
3055 $nbko++;
3056 break;
3057 }
3058
3059 $tmp = dol_getdate($now);
3060 $datetosearchfor = dol_time_plus_duree(dol_mktime(0, 0, 0, $tmp['mon'], $tmp['mday'], $tmp['year'], 'tzserver'), (int) $daysbeforeend, 'd');
3061
3062 $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'adherent';
3063 $sql .= " WHERE entity = ".((int) $conf->entity); // Do not use getEntity('adherent').")" here, we want the batch to be on its entity only;
3064 $sql .= " AND statut = 1";
3065 $sql .= " AND datefin = '".$this->db->idate($datetosearchfor)."'";
3066 //$sql .= " LIMIT 10000";
3067
3068 $resql = $this->db->query($sql);
3069 if ($resql) {
3070 $num_rows = $this->db->num_rows($resql);
3071
3072 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
3073 $adherent = new Adherent($this->db);
3074 $formmail = new FormMail($this->db);
3075
3076 $i = 0;
3077 while ($i < $num_rows) {
3078 $obj = $this->db->fetch_object($resql);
3079
3080 $adherent->fetch($obj->rowid, '', 0, '', true, true);
3081
3082 if (empty($adherent->email)) {
3083 $nbko++;
3084 $listofmembersko[$adherent->id] = $adherent->id;
3085 } else {
3086 $adherent->fetch_thirdparty();
3087
3088 // 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.
3089 $languagefromcountrycode = getLanguageCodeFromCountryCode($adherent->country_code ? $adherent->country_code : $adherent->thirdparty->country_code);
3090 $languagecodeformember = (empty($adherent->thirdparty->default_lang) ? ($languagefromcountrycode ? $languagefromcountrycode : $mysoc->default_lang) : $adherent->thirdparty->default_lang);
3091
3092 // Send reminder email
3093 $outputlangs = new Translate('', $conf);
3094 $outputlangs->setDefaultLang($languagecodeformember);
3095 $outputlangs->loadLangs(array("main", "members"));
3096 dol_syslog("sendReminderForExpiredSubscription Language for member id ".$adherent->id." set to ".$outputlangs->defaultlang." mysoc->default_lang=".$mysoc->default_lang);
3097
3098 $arraydefaultmessage = null;
3099 $labeltouse = getDolGlobalString('ADHERENT_EMAIL_TEMPLATE_REMIND_EXPIRATION');
3100
3101 if (!empty($labeltouse)) {
3102 $arraydefaultmessage = $formmail->getEMailTemplate($this->db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
3103 }
3104
3105 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
3106 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $adherent);
3107 //if (is_array($adherent->thirdparty)) $substitutionarraycomp = ...
3108 complete_substitutions_array($substitutionarray, $outputlangs, $adherent);
3109
3110 $subject = make_substitutions($arraydefaultmessage->topic, $substitutionarray, $outputlangs);
3111 $msg = make_substitutions($arraydefaultmessage->content, $substitutionarray, $outputlangs);
3112 $from = getDolGlobalString('ADHERENT_MAIL_FROM');
3113 $to = $adherent->email;
3114 $cc = getDolGlobalString('ADHERENT_CC_MAIL_FROM');
3115
3116 $trackid = 'mem'.$adherent->id;
3117 $moreinheader = 'X-Dolibarr-Info: sendReminderForExpiredSubscription'."\r\n";
3118
3119 include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
3120 $cmail = new CMailFile($subject, $to, $from, $msg, array(), array(), array(), $cc, '', 0, 1, '', '', $trackid, $moreinheader);
3121 $result = $cmail->sendfile();
3122 if (!$result) {
3123 $error++;
3124 $this->error .= $cmail->error.' ';
3125 if (!is_null($cmail->errors)) {
3126 $this->errors += $cmail->errors;
3127 }
3128 $nbko++;
3129 $listofmembersko[$adherent->id] = $adherent->id;
3130 } else {
3131 $nbok++;
3132 $listofmembersok[$adherent->id] = $adherent->id;
3133
3134 $message = $msg;
3135 $sendto = $to;
3136 $sendtocc = '';
3137 $sendtobcc = '';
3138 $actioncode = 'EMAIL';
3139 $extraparams = '';
3140
3141 $actionmsg = '';
3142 $actionmsg2 = $langs->transnoentities('MailSentByTo', CMailFile::getValidAddress($from, 4, 0, 1), CMailFile::getValidAddress($sendto, 4, 0, 1));
3143 if ($message) {
3144 $actionmsg = $langs->transnoentities('MailFrom').': '.dol_escape_htmltag($from);
3145 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTo').': '.dol_escape_htmltag($sendto));
3146 if ($sendtocc) {
3147 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc').": ".dol_escape_htmltag($sendtocc));
3148 }
3149 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic').": ".$subject);
3150 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody').":");
3151 $actionmsg = dol_concatdesc($actionmsg, $message);
3152 }
3153
3154 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
3155
3156 // Insert record of emails sent
3157 $actioncomm = new ActionComm($this->db);
3158
3159 $actioncomm->type_code = 'AC_OTH_AUTO'; // Type of event ('AC_OTH', 'AC_OTH_AUTO', 'AC_XXX'...)
3160 $actioncomm->code = 'AC_'.$actioncode;
3161 $actioncomm->label = $actionmsg2;
3162 $actioncomm->note_private = $actionmsg;
3163 $actioncomm->fk_project = 0;
3164 $actioncomm->datep = $now;
3165 $actioncomm->datef = $now;
3166 $actioncomm->percentage = -1; // Not applicable
3167 $actioncomm->socid = $adherent->thirdparty->id;
3168 $actioncomm->contact_id = 0;
3169 $actioncomm->authorid = $user->id; // User saving action
3170 $actioncomm->userownerid = $user->id; // Owner of action
3171 // Fields when action is en email (content should be added into note)
3172 $actioncomm->email_msgid = $cmail->msgid;
3173 $actioncomm->email_from = $from;
3174 $actioncomm->email_sender = '';
3175 $actioncomm->email_to = $to;
3176 $actioncomm->email_tocc = $sendtocc;
3177 $actioncomm->email_tobcc = $sendtobcc;
3178 $actioncomm->email_subject = $subject;
3179 $actioncomm->errors_to = '';
3180
3181 $actioncomm->fk_element = $adherent->id;
3182 $actioncomm->elementid = $adherent->id;
3183 $actioncomm->elementtype = $adherent->element;
3184
3185 $actioncomm->extraparams = $extraparams;
3186
3187 $actioncomm->create($user);
3188 }
3189 } else {
3190 //$blockingerrormsg = "Can't find email template with label=".$labeltouse.", to use for the reminding email";
3191
3192 $error++;
3193 $this->error .= "Can't find email template with label=".$labeltouse.", to use for the reminding email ";
3194
3195 $nbko++;
3196 $listofmembersko[$adherent->id] = $adherent->id;
3197
3198 break;
3199 }
3200 }
3201
3202 $i++;
3203 }
3204 } else {
3205 $this->error = $this->db->lasterror();
3206 return 1;
3207 }
3208 }
3209
3210 if ($blockingerrormsg) {
3211 $this->error = $blockingerrormsg;
3212 return 1;
3213 } else {
3214 $this->output = 'Found '.($nbok + $nbko).' members to send reminder to.';
3215 $this->output .= ' Send email successfully to '.$nbok.' members';
3216 if (is_array($listofmembersok)) {
3217 $listofids = '';
3218 $i = 0;
3219 foreach ($listofmembersok as $idmember) {
3220 if ($i > 100) {
3221 $listofids .= ', ...';
3222 break;
3223 }
3224 if (empty($listofids)) {
3225 $listofids .= ' [';
3226 } else {
3227 $listofids .= ', ';
3228 }
3229 $listofids .= $idmember;
3230 $i++;
3231 }
3232 if ($listofids) {
3233 $listofids .= ']';
3234 }
3235
3236 $this->output .= ($listofids ? ' ids='.$listofids : '');
3237 }
3238 if ($nbko) {
3239 $this->output .= ' - Canceled for '.$nbko.' member (no email or email sending error)';
3240 if (is_array($listofmembersko)) {
3241 $listofids = '';
3242 $i = 0;
3243 foreach ($listofmembersko as $idmember) {
3244 if ($i > 100) {
3245 $listofids .= ', ...';
3246 break;
3247 }
3248 if (empty($listofids)) {
3249 $listofids .= ' [';
3250 } else {
3251 $listofids .= ', ';
3252 }
3253 $listofids .= $idmember;
3254 $i++;
3255 }
3256 if ($listofids) {
3257 $listofids .= ']';
3258 }
3259 $this->output .= ($listofids ? ' ids='.$listofids : '');
3260 }
3261 }
3262 }
3263
3264 return $nbko;
3265 }
3266
3274 public function getKanbanView($option = '', $arraydata = null)
3275 {
3276 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
3277
3278 $return = '<div class="box-flex-item box-flex-grow-zero">';
3279 $return .= '<div class="info-box info-box-sm">';
3280 $return .= '<span class="info-box-icon bg-infobox-action">';
3281 if (property_exists($this, 'photo') || !empty($this->photo)) {
3282 $return .= Form::showphoto('memberphoto', $this, 0, 60, 0, 'photokanban photoref photowithmargin photologintooltip', 'small', 0, 1);
3283 } else {
3284 $return .= img_picto('', 'user');
3285 }
3286 $return .= '</span>';
3287 $return .= '<div class="info-box-content">';
3288 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
3289 if ($selected >= 0) {
3290 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
3291 }
3292 $return .= '<br><span class="info-box-label paddingright">'.$this->getmorphylib('', 2).'</span>';
3293 $return .= '<span class="info-box-label opacitymedium">'.$this->type.'</span>';
3294
3295 if (method_exists($this, 'getLibStatut')) {
3296 $return .= '<br><div class="info-box-status paddingtop">';
3297 $return .= $this->LibStatut($this->status, $this->need_subscription, $this->datefin, 5);
3298 $return .= '</div>';
3299 }
3300 $return .= '</div>';
3301 $return .= '</div>';
3302 $return .= '</div>';
3303 return $return;
3304 }
3305}
$object ref
Definition info.php:79
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.
sendReminderForExpiredSubscription($daysbeforeendlist='10')
Send reminders by emails before subscription end CAN BE A CRON TASK.
_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.
fetch_login($login)
Method to load member from its login.
create($user, $notrigger=0)
Create a member into database.
_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:162
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)
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...
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
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:137
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.
dolGetLdapPasswordHash($password, $type='md5')
Returns a specific ldap hash of a password.
dol_hash($chain, $type='0', $nosalt=0)
Returns a hash (non reversible encryption) of a string.