dolibarr 19.0.3
adherent.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org>
4 * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
6 * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
7 * Copyright (C) 2009-2017 Regis Houssin <regis.houssin@inodbox.com>
8 * Copyright (C) 2014-2018 Alexandre Spangaro <aspangaro@open-dsi.fr>
9 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
10 * Copyright (C) 2015-2023 Frédéric France <frederic.france@netlogic.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 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 3 of the License, or
22 * (at your option) any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program. If not, see <https://www.gnu.org/licenses/>.
31 */
32
38require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
39require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
40require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
41require_once DOL_DOCUMENT_ROOT.'/core/class/commonpeople.class.php';
42
43
48{
49 use CommonPeople;
50
54 public $element = 'member';
55
59 public $table_element = 'adherent';
60
65 public $ismultientitymanaged = 1;
66
70 public $isextrafieldmanaged = 1;
71
75 public $picto = 'member';
76
77
78 public $mesgs;
79
83 public $login;
84
88 public $pass;
89
93 public $pass_indatabase;
94
98 public $pass_indatabase_crypted;
99
103 public $fullname;
104
108 public $civility_id;
109 public $civility_code;
110 public $civility;
111
117 public $societe;
118
122 public $company;
123
129 public $fk_soc;
130
134 public $socid;
135
139 public $socialnetworks;
140
144 public $phone;
145
149 public $phone_perso;
150
154 public $phone_pro;
155
159 public $phone_mobile;
160
164 public $fax;
165
169 public $poste;
170
174 public $morphy;
175
179 public $public;
180
185 public $default_lang;
186
190 public $photo;
191
197 public $datec;
198
204 public $datem;
205
206 public $datevalid;
207
211 public $gender;
212
213 public $birth;
214
218 public $typeid;
219
223 public $type;
224
228 public $need_subscription;
229
233 public $user_id;
234
238 public $user_login;
239
240 public $datefin;
241
242
243 // Fields loaded by fetch_subscriptions() from member table
244
245 public $first_subscription_date;
246
247 public $first_subscription_date_start;
248
249 public $first_subscription_date_end;
250
251 public $first_subscription_amount;
252
253 public $last_subscription_date;
254
255 public $last_subscription_date_start;
256
257 public $last_subscription_date_end;
258
259 public $last_subscription_amount;
260
261 public $subscriptions = array();
262
266 public $ip;
267
268 // Fields loaded by fetchPartnerships() from partnership table
269
270 public $partnerships = array();
271
275 public $invoice;
276
277
281 public $fields = array(
282 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 10),
283 'ref' => array('type' => 'varchar(30)', 'label' => 'Ref', 'default' => 1, 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'position' => 12, 'index' => 1),
284 'entity' => array('type' => 'integer', 'label' => 'Entity', 'default' => 1, 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 15, 'index' => 1),
285 'ref_ext' => array('type' => 'varchar(128)', 'label' => 'Ref ext', 'enabled' => 1, 'visible' => 0, 'position' => 20),
286 'civility' => array('type' => 'varchar(6)', 'label' => 'Civility', 'enabled' => 1, 'visible' => -1, 'position' => 25),
287 'lastname' => array('type' => 'varchar(50)', 'label' => 'Lastname', 'enabled' => 1, 'visible' => 1, 'position' => 30, 'showoncombobox'=>1),
288 'firstname' => array('type' => 'varchar(50)', 'label' => 'Firstname', 'enabled' => 1, 'visible' => 1, 'position' => 35, 'showoncombobox'=>1),
289 'login' => array('type' => 'varchar(50)', 'label' => 'Login', 'enabled' => 1, 'visible' => 1, 'position' => 40),
290 'pass' => array('type' => 'varchar(50)', 'label' => 'Pass', 'enabled' => 1, 'visible' => -1, 'position' => 45),
291 'pass_crypted' => array('type' => 'varchar(128)', 'label' => 'Pass crypted', 'enabled' => 1, 'visible' => -1, 'position' => 50),
292 'morphy' => array('type' => 'varchar(3)', 'label' => 'MemberNature', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'position' => 55),
293 'fk_adherent_type' => array('type' => 'integer', 'label' => 'Fk adherent type', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'position' => 60),
294 'societe' => array('type' => 'varchar(128)', 'label' => 'Societe', 'enabled' => 1, 'visible' => 1, 'position' => 65, 'showoncombobox'=>2),
295 'fk_soc' => array('type' => 'integer:Societe:societe/class/societe.class.php', 'label' => 'ThirdParty', 'enabled' => 1, 'visible' => 1, 'position' => 70),
296 'address' => array('type' => 'text', 'label' => 'Address', 'enabled' => 1, 'visible' => -1, 'position' => 75),
297 'zip' => array('type' => 'varchar(10)', 'label' => 'Zip', 'enabled' => 1, 'visible' => -1, 'position' => 80),
298 'town' => array('type' => 'varchar(50)', 'label' => 'Town', 'enabled' => 1, 'visible' => -1, 'position' => 85),
299 'state_id' => array('type' => 'integer', 'label' => 'State id', 'enabled' => 1, 'visible' => -1, 'position' => 90),
300 'country' => array('type' => 'integer:Ccountry:core/class/ccountry.class.php', 'label' => 'Country', 'enabled' => 1, 'visible' => 1, 'position' => 95),
301 'phone' => array('type' => 'varchar(30)', 'label' => 'Phone', 'enabled' => 1, 'visible' => -1, 'position' => 115),
302 'phone_perso' => array('type' => 'varchar(30)', 'label' => 'Phone perso', 'enabled' => 1, 'visible' => -1, 'position' => 120),
303 'phone_mobile' => array('type' => 'varchar(30)', 'label' => 'Phone mobile', 'enabled' => 1, 'visible' => -1, 'position' => 125),
304 'email' => array('type' => 'varchar(255)', 'label' => 'Email', 'enabled' => 1, 'visible' => 1, 'position' => 126),
305 'url' =>array('type'=>'varchar(255)', 'label'=>'Url', 'enabled'=>1, 'visible'=>-1, 'position'=>127),
306 'socialnetworks' => array('type' => 'text', 'label' => 'Socialnetworks', 'enabled' => 1, 'visible' => -1, 'position' => 128),
307 'birth' => array('type' => 'date', 'label' => 'DateOfBirth', 'enabled' => 1, 'visible' => -1, 'position' => 130),
308 'gender' => array('type' => 'varchar(10)', 'label' => 'Gender', 'enabled' => 1, 'visible' => -1, 'position' => 132),
309 'photo' => array('type' => 'varchar(255)', 'label' => 'Photo', 'enabled' => 1, 'visible' => -1, 'position' => 135),
310 'public' => array('type' => 'smallint(6)', 'label' => 'Public', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 145),
311 'datefin' => array('type' => 'datetime', 'label' => 'DateEnd', 'enabled' => 1, 'visible' => 1, 'position' => 150),
312 'default_lang' =>array('type'=>'varchar(6)', 'label'=>'Default lang', 'enabled'=>1, 'visible'=>-1, 'position'=> 153),
313 'note_public' => array('type' => 'text', 'label' => 'NotePublic', 'enabled' => 1, 'visible' => 0, 'position' => 155),
314 'note_private' => array('type' => 'text', 'label' => 'NotePrivate', 'enabled' => 1, 'visible' => 0, 'position' => 160),
315 'datevalid' => array('type' => 'datetime', 'label' => 'DateValidation', 'enabled' => 1, 'visible' => -1, 'position' => 165),
316 'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -1, 'position' => 170),
317 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 175),
318 'fk_user_author' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'Fk user author', 'enabled' => 1, 'visible' => -1, 'position' => 180),
319 'fk_user_mod' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'Fk user mod', 'enabled' => 1, 'visible' => -1, 'position' => 185),
320 'fk_user_valid' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserValidation', 'enabled' => 1, 'visible' => -1, 'position' => 190),
321 'canvas' => array('type' => 'varchar(32)', 'label' => 'Canvas', 'enabled' => 1, 'visible' => -1, 'position' => 195),
322 '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')),
323 'model_pdf' => array('type' => 'varchar(255)', 'label' => 'Model pdf', 'enabled' => 1, 'visible' => 0, 'position' => 800),
324 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'visible' => -2, 'position' => 805)
325 );
326
330 const STATUS_DRAFT = -1;
342 const STATUS_EXCLUDED = -2;
343
344
350 public function __construct($db)
351 {
352 $this->db = $db;
353 $this->statut = self::STATUS_DRAFT;
354 $this->status = self::STATUS_DRAFT;
355 // l'adherent n'est pas public par defaut
356 $this->public = 0;
357 // les champs optionnels sont vides
358 $this->array_options = array();
359 }
360
361
362 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
381 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 = '')
382 {
383 // phpcs:enable
384 dol_syslog('Warning using deprecated Adherent::send_an_email', LOG_WARNING);
385
386 return $this->sendEmail($text, $subject, $filename_list, $mimetype_list, $mimefilename_list, $addr_cc, $addr_bcc, $deliveryreceipt, $msgishtml, $errors_to, $moreinheader);
387 }
388
406 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 = '')
407 {
408 global $conf, $langs;
409
410 // Detect if message is HTML
411 if ($msgishtml == -1) {
412 $msgishtml = 0;
413 if (dol_textishtml($text, 0)) {
414 $msgishtml = 1;
415 }
416 }
417
418 dol_syslog('sendEmail msgishtml='.$msgishtml);
419
420 $texttosend = $this->makeSubstitution($text);
421 $subjecttosend = $this->makeSubstitution($subject);
422 if ($msgishtml) {
423 $texttosend = dol_htmlentitiesbr($texttosend);
424 }
425
426 // Envoi mail confirmation
427 $from = $conf->email_from;
428 if (getDolGlobalString('ADHERENT_MAIL_FROM')) {
429 $from = getDolGlobalString('ADHERENT_MAIL_FROM');
430 }
431
432 $trackid = 'mem'.$this->id;
433
434 // Send email (substitutionarray must be done just before this)
435 include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
436 $mailfile = new CMailFile($subjecttosend, $this->email, $from, $texttosend, $filename_list, $mimetype_list, $mimefilename_list, $addr_cc, $addr_bcc, $deliveryreceipt, $msgishtml, '', '', $trackid, $moreinheader);
437 if ($mailfile->sendfile()) {
438 return 1;
439 } else {
440 $this->error = $langs->trans("ErrorFailedToSendMail", $from, $this->email).'. '.$mailfile->error;
441 return -1;
442 }
443 }
444
445
452 public function makeSubstitution($text)
453 {
454 global $conf, $langs;
455
456 $birthday = dol_print_date($this->birth, 'day');
457
458 $msgishtml = 0;
459 if (dol_textishtml($text, 1)) {
460 $msgishtml = 1;
461 }
462
463 $infos = '';
464 if ($this->civility_id) {
465 $infos .= $langs->transnoentities("UserTitle").": ".$this->getCivilityLabel()."\n";
466 }
467 $infos .= $langs->transnoentities("id").": ".$this->id."\n";
468 $infos .= $langs->transnoentities("ref").": ".$this->ref."\n";
469 $infos .= $langs->transnoentities("Lastname").": ".$this->lastname."\n";
470 $infos .= $langs->transnoentities("Firstname").": ".$this->firstname."\n";
471 $infos .= $langs->transnoentities("Company").": ".$this->company."\n";
472 $infos .= $langs->transnoentities("Address").": ".$this->address."\n";
473 $infos .= $langs->transnoentities("Zip").": ".$this->zip."\n";
474 $infos .= $langs->transnoentities("Town").": ".$this->town."\n";
475 $infos .= $langs->transnoentities("Country").": ".$this->country."\n";
476 $infos .= $langs->transnoentities("EMail").": ".$this->email."\n";
477 $infos .= $langs->transnoentities("PhonePro").": ".$this->phone."\n";
478 $infos .= $langs->transnoentities("PhonePerso").": ".$this->phone_perso."\n";
479 $infos .= $langs->transnoentities("PhoneMobile").": ".$this->phone_mobile."\n";
480 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
481 $infos .= $langs->transnoentities("Login").": ".$this->login."\n";
482 $infos .= $langs->transnoentities("Password").": ".$this->pass."\n";
483 }
484 $infos .= $langs->transnoentities("Birthday").": ".$birthday."\n";
485 $infos .= $langs->transnoentities("Photo").": ".$this->photo."\n";
486 $infos .= $langs->transnoentities("Public").": ".yn($this->public);
487
488 // Substitutions
489 $substitutionarray = array(
490 '__ID__' => $this->id,
491 '__REF__' => $this->ref,
492 '__MEMBER_ID__' => $this->id,
493 '__CIVILITY__' => $this->getCivilityLabel(),
494 '__FIRSTNAME__' => $msgishtml ? dol_htmlentitiesbr($this->firstname) : ($this->firstname ? $this->firstname : ''),
495 '__LASTNAME__' => $msgishtml ? dol_htmlentitiesbr($this->lastname) : ($this->lastname ? $this->lastname : ''),
496 '__FULLNAME__' => $msgishtml ? dol_htmlentitiesbr($this->getFullName($langs)) : $this->getFullName($langs),
497 '__COMPANY__' => $msgishtml ? dol_htmlentitiesbr($this->company) : ($this->company ? $this->company : ''),
498 '__ADDRESS__' => $msgishtml ? dol_htmlentitiesbr($this->address) : ($this->address ? $this->address : ''),
499 '__ZIP__' => $msgishtml ? dol_htmlentitiesbr($this->zip) : ($this->zip ? $this->zip : ''),
500 '__TOWN__' => $msgishtml ? dol_htmlentitiesbr($this->town) : ($this->town ? $this->town : ''),
501 '__COUNTRY__' => $msgishtml ? dol_htmlentitiesbr($this->country) : ($this->country ? $this->country : ''),
502 '__EMAIL__' => $msgishtml ? dol_htmlentitiesbr($this->email) : ($this->email ? $this->email : ''),
503 '__BIRTH__' => $msgishtml ? dol_htmlentitiesbr($birthday) : ($birthday ? $birthday : ''),
504 '__PHOTO__' => $msgishtml ? dol_htmlentitiesbr($this->photo) : ($this->photo ? $this->photo : ''),
505 '__LOGIN__' => $msgishtml ? dol_htmlentitiesbr($this->login) : ($this->login ? $this->login : ''),
506 '__PASSWORD__' => $msgishtml ? dol_htmlentitiesbr($this->pass) : ($this->pass ? $this->pass : ''),
507 '__PHONE__' => $msgishtml ? dol_htmlentitiesbr($this->phone) : ($this->phone ? $this->phone : ''),
508 '__PHONEPRO__' => $msgishtml ? dol_htmlentitiesbr($this->phone_perso) : ($this->phone_perso ? $this->phone_perso : ''),
509 '__PHONEMOBILE__' => $msgishtml ? dol_htmlentitiesbr($this->phone_mobile) : ($this->phone_mobile ? $this->phone_mobile : ''),
510 '__TYPE__' => $msgishtml ? dol_htmlentitiesbr($this->type) : ($this->type ? $this->type : '')
511 );
512
513 complete_substitutions_array($substitutionarray, $langs, $this);
514
515 return make_substitutions($text, $substitutionarray, $langs);
516 }
517
518
526 public function getmorphylib($morphy = '', $addbadge = 0)
527 {
528 global $langs;
529
530 // Clean var
531 if (!$morphy) {
532 $morphy = $this->morphy;
533 }
534
535 if ($addbadge) {
536 $s = '';
537 $labeltoshowm = $langs->trans("Moral");
538 $labeltoshowp = $langs->trans("Physical");
539 if ($morphy == 'phy') {
540 $labeltoshow = $labeltoshowp;
541 if ($addbadge == 2) {
542 $labeltoshow = dol_strtoupper(dolGetFirstLetters($labeltoshowp));
543 if ($labeltoshow == dol_strtoupper(dolGetFirstLetters($labeltoshowm))) {
544 $labeltoshow = dol_strtoupper(dolGetFirstLetters($labeltoshowp, 2));
545 }
546 }
547 $s .= '<span class="member-individual-back paddingleftimp paddingrightimp" title="'.$langs->trans("Physical").'">'.$labeltoshow.'</span>';
548 }
549 if ($morphy == 'mor') {
550 $labeltoshow = $labeltoshowm;
551 if ($addbadge == 2) {
552 $labeltoshow = dol_strtoupper(dolGetFirstLetters($labeltoshowm));
553 if ($labeltoshow == dol_strtoupper(dolGetFirstLetters($labeltoshowp))) {
554 $labeltoshow = dol_strtoupper(dolGetFirstLetters($labeltoshowm, 2));
555 }
556 }
557 $s .= '<span class="member-company-back paddingleftimp paddingrightimp" title="'.$langs->trans("Moral").'">'.$labeltoshow.'</span>';
558 }
559 } else {
560 if ($morphy == 'phy') {
561 $s = $langs->trans("Physical");
562 } elseif ($morphy == 'mor') {
563 $s = $langs->trans("Moral");
564 }
565 }
566
567 return $s;
568 }
569
577 public function create($user, $notrigger = 0)
578 {
579 global $conf, $langs, $mysoc;
580
581 $error = 0;
582
583 $now = dol_now();
584
585 // Clean parameters
586 $this->import_key = trim($this->import_key);
587
588 // Check parameters
589 if (getDolGlobalString('ADHERENT_MAIL_REQUIRED') && !isValidEMail($this->email)) {
590 $langs->load("errors");
591 $this->error = $langs->trans("ErrorBadEMail", $this->email);
592 return -1;
593 }
594 if (!$this->datec) {
595 $this->datec = $now;
596 }
597 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
598 if (empty($this->login)) {
599 $this->error = $langs->trans("ErrorWrongValueForParameterX", "Login");
600 return -1;
601 }
602 }
603
604 $this->db->begin();
605
606 // Insert member
607 $sql = "INSERT INTO ".MAIN_DB_PREFIX."adherent";
608 $sql .= " (ref, datec,login,fk_user_author,fk_user_mod,fk_user_valid,morphy,fk_adherent_type,entity,import_key, ip)";
609 $sql .= " VALUES (";
610 $sql .= " '(PROV)'";
611 $sql .= ", '".$this->db->idate($this->datec)."'";
612 $sql .= ", ".($this->login ? "'".$this->db->escape($this->login)."'" : "null");
613 $sql .= ", ".($user->id > 0 ? $user->id : "null"); // Can be null because member can be created by a guest or a script
614 $sql .= ", null, null, '".$this->db->escape($this->morphy)."'";
615 $sql .= ", ".((int) $this->typeid);
616 $sql .= ", ".$conf->entity;
617 $sql .= ", ".(!empty($this->import_key) ? "'".$this->db->escape($this->import_key)."'" : "null");
618 $sql .= ", ".(!empty($this->ip) ? "'".$this->db->escape($this->ip)."'" : "null");
619 $sql .= ")";
620
621 dol_syslog(get_class($this)."::create", LOG_DEBUG);
622 $result = $this->db->query($sql);
623 if ($result) {
624 $id = $this->db->last_insert_id(MAIN_DB_PREFIX."adherent");
625 if ($id > 0) {
626 $this->id = $id;
627 if (getDolGlobalString('MEMBER_CODEMEMBER_ADDON') == '') {
628 // keep old numbering
629 $this->ref = (string) $id;
630 } else {
631 // auto code
632 $modfile = dol_buildpath('core/modules/member/'.getDolGlobalString('MEMBER_CODEMEMBER_ADDON').'.php', 0);
633 try {
634 require_once $modfile;
635 $modname = getDolGlobalString('MEMBER_CODEMEMBER_ADDON');
636 $modCodeMember = new $modname();
637 $this->ref = $modCodeMember->getNextValue($mysoc, $this);
638 } catch (Exception $e) {
639 dol_syslog($e->getMessage(), LOG_ERR);
640 $error++;
641 }
642 }
643
644 // Update minor fields
645 $result = $this->update($user, 1, 1, 0, 0, 'add'); // nosync is 1 to avoid update data of user
646 if ($result < 0) {
647 $this->db->rollback();
648 return -1;
649 }
650
651 // Add link to user
652 if ($this->user_id) {
653 // Add link to user
654 $sql = "UPDATE ".MAIN_DB_PREFIX."user SET";
655 $sql .= " fk_member = ".((int) $this->id);
656 $sql .= " WHERE rowid = ".((int) $this->user_id);
657 dol_syslog(get_class($this)."::create", LOG_DEBUG);
658 $resql = $this->db->query($sql);
659 if (!$resql) {
660 $this->error = 'Failed to update user to make link with member';
661 $this->db->rollback();
662 return -4;
663 }
664 }
665
666 if (!$notrigger) {
667 // Call trigger
668 $result = $this->call_trigger('MEMBER_CREATE', $user);
669 if ($result < 0) {
670 $error++;
671 }
672 // End call triggers
673 }
674
675 if (count($this->errors)) {
676 dol_syslog(get_class($this)."::create ".implode(',', $this->errors), LOG_ERR);
677 $this->db->rollback();
678 return -3;
679 } else {
680 $this->db->commit();
681 return $this->id;
682 }
683 } else {
684 $this->error = 'Failed to get last insert id';
685 dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
686 $this->db->rollback();
687 return -2;
688 }
689 } else {
690 $this->error = $this->db->error();
691 $this->db->rollback();
692 return -1;
693 }
694 }
695
696
708 public function update($user, $notrigger = 0, $nosyncuser = 0, $nosyncuserpass = 0, $nosyncthirdparty = 0, $action = 'update')
709 {
710 global $langs, $hookmanager;
711
712 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
713
714 $nbrowsaffected = 0;
715 $error = 0;
716
717 dol_syslog(get_class($this)."::update notrigger=".$notrigger.", nosyncuser=".$nosyncuser.", nosyncuserpass=".$nosyncuserpass." nosyncthirdparty=".$nosyncthirdparty.", email=".$this->email);
718
719 // Clean parameters
720 $this->lastname = trim($this->lastname) ? trim($this->lastname) : trim($this->lastname);
721 $this->firstname = trim($this->firstname) ? trim($this->firstname) : trim($this->firstname);
722 $this->gender = trim($this->gender);
723 $this->address = ($this->address ? $this->address : $this->address);
724 $this->zip = ($this->zip ? $this->zip : $this->zip);
725 $this->town = ($this->town ? $this->town : $this->town);
726 $this->country_id = ($this->country_id > 0 ? $this->country_id : $this->country_id);
727 $this->state_id = ($this->state_id > 0 ? $this->state_id : $this->state_id);
728 $this->note_public = ($this->note_public ? $this->note_public : $this->note_public);
729 $this->note_private = ($this->note_private ? $this->note_private : $this->note_private);
730 $this->url = $this->url ? clean_url($this->url, 0) : '';
731 $this->setUpperOrLowerCase();
732 // Check parameters
733 if (getDolGlobalString('ADHERENT_MAIL_REQUIRED') && !isValidEMail($this->email)) {
734 $langs->load("errors");
735 $this->error = $langs->trans("ErrorBadEMail", $this->email);
736 return -1;
737 }
738
739 $this->db->begin();
740
741 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
742 $sql .= " ref = '".$this->db->escape($this->ref)."'";
743 $sql .= ", civility = ".($this->civility_id ? "'".$this->db->escape($this->civility_id)."'" : "null");
744 $sql .= ", firstname = ".($this->firstname ? "'".$this->db->escape($this->firstname)."'" : "null");
745 $sql .= ", lastname = ".($this->lastname ? "'".$this->db->escape($this->lastname)."'" : "null");
746 $sql .= ", gender = ".($this->gender != -1 ? "'".$this->db->escape($this->gender)."'" : "null"); // 'man' or 'woman'
747 $sql .= ", login = ".($this->login ? "'".$this->db->escape($this->login)."'" : "null");
748 $sql .= ", societe = ".($this->company ? "'".$this->db->escape($this->company)."'" : ($this->societe ? "'".$this->db->escape($this->societe)."'" : "null"));
749 if ($this->socid) {
750 $sql .= ", fk_soc = ".($this->socid > 0 ? $this->db->escape($this->socid) : "null"); // Must be modified only when creating from a third-party
751 }
752 $sql .= ", address = ".($this->address ? "'".$this->db->escape($this->address)."'" : "null");
753 $sql .= ", zip = ".($this->zip ? "'".$this->db->escape($this->zip)."'" : "null");
754 $sql .= ", town = ".($this->town ? "'".$this->db->escape($this->town)."'" : "null");
755 $sql .= ", country = ".($this->country_id > 0 ? $this->db->escape($this->country_id) : "null");
756 $sql .= ", state_id = ".($this->state_id > 0 ? $this->db->escape($this->state_id) : "null");
757 $sql .= ", email = '".$this->db->escape($this->email)."'";
758 $sql .= ", url = ".(!empty($this->url) ? "'".$this->db->escape($this->url)."'" : "null");
759 $sql .= ", socialnetworks = ".($this->socialnetworks ? "'".$this->db->escape(json_encode($this->socialnetworks))."'" : "null");
760 $sql .= ", phone = ".($this->phone ? "'".$this->db->escape($this->phone)."'" : "null");
761 $sql .= ", phone_perso = ".($this->phone_perso ? "'".$this->db->escape($this->phone_perso)."'" : "null");
762 $sql .= ", phone_mobile = ".($this->phone_mobile ? "'".$this->db->escape($this->phone_mobile)."'" : "null");
763 $sql .= ", note_private = ".($this->note_private ? "'".$this->db->escape($this->note_private)."'" : "null");
764 $sql .= ", note_public = ".($this->note_public ? "'".$this->db->escape($this->note_public)."'" : "null");
765 $sql .= ", photo = ".($this->photo ? "'".$this->db->escape($this->photo)."'" : "null");
766 $sql .= ", public = '".$this->db->escape($this->public)."'";
767 $sql .= ", statut = ".$this->db->escape($this->statut);
768 $sql .= ", default_lang = ".(!empty($this->default_lang) ? "'".$this->db->escape($this->default_lang)."'" : "null");
769 $sql .= ", fk_adherent_type = ".$this->db->escape($this->typeid);
770 $sql .= ", morphy = '".$this->db->escape($this->morphy)."'";
771 $sql .= ", birth = ".($this->birth ? "'".$this->db->idate($this->birth)."'" : "null");
772
773 if ($this->datefin) {
774 $sql .= ", datefin = '".$this->db->idate($this->datefin)."'"; // Must be modified only when deleting a subscription
775 }
776 if ($this->datevalid) {
777 $sql .= ", datevalid = '".$this->db->idate($this->datevalid)."'"; // Must be modified only when validating a member
778 }
779 $sql .= ", fk_user_mod = ".($user->id > 0 ? $user->id : 'null'); // Can be null because member can be create by a guest
780 $sql .= " WHERE rowid = ".((int) $this->id);
781
782 // If we change the type of membership, we set also label of new type
783 if (!empty($this->oldcopy) && $this->typeid != $this->oldcopy->typeid) {
784 $sql2 = "SELECT libelle as label";
785 $sql2 .= " FROM ".MAIN_DB_PREFIX."adherent_type";
786 $sql2 .= " WHERE rowid = ".((int) $this->typeid);
787 $resql2 = $this->db->query($sql2);
788 if ($resql2) {
789 while ($obj = $this->db->fetch_object($resql2)) {
790 $this->type = $obj->label;
791 }
792 }
793 }
794
795 dol_syslog(get_class($this)."::update update member", LOG_DEBUG);
796 $resql = $this->db->query($sql);
797 if ($resql) {
798 unset($this->country_code);
799 unset($this->country);
800 unset($this->state_code);
801 unset($this->state);
802
803 $nbrowsaffected += $this->db->affected_rows($resql);
804
805 $action = 'update';
806
807 // Actions on extra fields
808 if (!$error) {
809 $result = $this->insertExtraFields();
810 if ($result < 0) {
811 $error++;
812 }
813 }
814
815 // Update password
816 if (!$error && $this->pass) {
817 dol_syslog(get_class($this)."::update update password");
818 if ($this->pass != $this->pass_indatabase && $this->pass != $this->pass_indatabase_crypted) {
819 $isencrypted = !getDolGlobalString('DATABASE_PWD_ENCRYPTED') ? 0 : 1;
820
821 // If password to set differs from the one found into database
822 $result = $this->setPassword($user, $this->pass, $isencrypted, $notrigger, $nosyncuserpass);
823 if (!$nbrowsaffected) {
824 $nbrowsaffected++;
825 }
826 }
827 }
828
829 // Remove links to user and replace with new one
830 if (!$error) {
831 dol_syslog(get_class($this)."::update update link to user");
832 $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = NULL WHERE fk_member = ".((int) $this->id);
833 dol_syslog(get_class($this)."::update", LOG_DEBUG);
834 $resql = $this->db->query($sql);
835 if (!$resql) {
836 $this->error = $this->db->error();
837 $this->db->rollback();
838 return -5;
839 }
840 // If there is a user linked to this member
841 if ($this->user_id > 0) {
842 $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = ".((int) $this->id)." WHERE rowid = ".((int) $this->user_id);
843 dol_syslog(get_class($this)."::update", LOG_DEBUG);
844 $resql = $this->db->query($sql);
845 if (!$resql) {
846 $this->error = $this->db->error();
847 $this->db->rollback();
848 return -5;
849 }
850 }
851 }
852
853 if (!$error && $nbrowsaffected) { // If something has change in main data
854 // Update information on linked user if it is an update
855 if (!$error && $this->user_id > 0 && !$nosyncuser) {
856 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
857
858 dol_syslog(get_class($this)."::update update linked user");
859
860 $luser = new User($this->db);
861 $result = $luser->fetch($this->user_id);
862
863 if ($result >= 0) {
864 //var_dump($this->user_login);exit;
865 //var_dump($this->login);exit;
866
867 // 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.
868 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
869 $luser->login = $this->login;
870 }
871
872 $luser->ref = $this->ref;
873 $luser->civility_id = $this->civility_id;
874 $luser->firstname = $this->firstname;
875 $luser->lastname = $this->lastname;
876 $luser->gender = $this->gender;
877 $luser->pass = $this->pass;
878 //$luser->socid=$this->fk_soc; // We do not enable this. This may transform a user into an external user.
879
880 $luser->birth = $this->birth;
881
882 $luser->address = $this->address;
883 $luser->zip = $this->zip;
884 $luser->town = $this->town;
885 $luser->country_id = $this->country_id;
886 $luser->state_id = $this->state_id;
887
888 $luser->email = $this->email;
889 $luser->socialnetworks = $this->socialnetworks;
890 $luser->office_phone = $this->phone;
891 $luser->user_mobile = $this->phone_mobile;
892
893 $luser->lang = $this->default_lang;
894
895 $luser->fk_member = $this->id;
896
897 $result = $luser->update($user, 0, 1, 1); // Use nosync to 1 to avoid cyclic updates
898 if ($result < 0) {
899 $this->error = $luser->error;
900 dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
901 $error++;
902 }
903 } else {
904 $this->error = $luser->error;
905 $error++;
906 }
907 }
908
909 // Update information on linked thirdparty if it is an update
910 if (!$error && $this->fk_soc > 0 && !$nosyncthirdparty) {
911 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
912
913 dol_syslog(get_class($this)."::update update linked thirdparty");
914
915 // This member is linked with a thirdparty, so we also update thirdparty informations
916 // if this is an update.
917 $lthirdparty = new Societe($this->db);
918 $result = $lthirdparty->fetch($this->fk_soc);
919
920 if ($result > 0) {
921 $lthirdparty->address = $this->address;
922 $lthirdparty->zip = $this->zip;
923 $lthirdparty->town = $this->town;
924 $lthirdparty->email = $this->email;
925 $lthirdparty->socialnetworks = $this->socialnetworks;
926 $lthirdparty->phone = $this->phone;
927 $lthirdparty->state_id = $this->state_id;
928 $lthirdparty->country_id = $this->country_id;
929 //$lthirdparty->phone_mobile=$this->phone_mobile;
930 $lthirdparty->default_lang = $this->default_lang;
931
932 $result = $lthirdparty->update($this->fk_soc, $user, 0, 1, 1, 'update'); // Use sync to 0 to avoid cyclic updates
933
934 if ($result < 0) {
935 $this->error = $lthirdparty->error;
936 $this->errors = $lthirdparty->errors;
937 dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
938 $error++;
939 }
940 } elseif ($result < 0) {
941 $this->error = $lthirdparty->error;
942 $error++;
943 }
944 }
945 }
946
947 if (!$error && !$notrigger) {
948 // Call trigger
949 $result = $this->call_trigger('MEMBER_MODIFY', $user);
950 if ($result < 0) {
951 $error++;
952 }
953 // End call triggers
954 }
955
956 if (!$error) {
957 $this->db->commit();
958 return $nbrowsaffected;
959 } else {
960 $this->db->rollback();
961 return -1;
962 }
963 } else {
964 $this->db->rollback();
965 $this->error = $this->db->lasterror();
966 return -2;
967 }
968 }
969
970
971 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
979 public function update_end_date($user)
980 {
981 // phpcs:enable
982 $this->db->begin();
983
984 // Search for last subscription id and end date
985 $sql = "SELECT rowid, datec as dateop, dateadh as datedeb, datef as datefin";
986 $sql .= " FROM ".MAIN_DB_PREFIX."subscription";
987 $sql .= " WHERE fk_adherent = ".((int) $this->id);
988 $sql .= " ORDER by dateadh DESC"; // Sort by start subscription date
989
990 dol_syslog(get_class($this)."::update_end_date", LOG_DEBUG);
991 $resql = $this->db->query($sql);
992 if ($resql) {
993 $obj = $this->db->fetch_object($resql);
994 $dateop = $this->db->jdate($obj->dateop);
995 $datedeb = $this->db->jdate($obj->datedeb);
996 $datefin = $this->db->jdate($obj->datefin);
997
998 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
999 $sql .= " datefin=".($datefin != '' ? "'".$this->db->idate($datefin)."'" : "null");
1000 $sql .= " WHERE rowid = ".((int) $this->id);
1001
1002 dol_syslog(get_class($this)."::update_end_date", LOG_DEBUG);
1003 $resql = $this->db->query($sql);
1004 if ($resql) {
1005 $this->last_subscription_date = $dateop;
1006 $this->last_subscription_date_start = $datedeb;
1007 $this->last_subscription_date_end = $datefin;
1008 $this->datefin = $datefin;
1009 $this->db->commit();
1010 return 1;
1011 } else {
1012 $this->db->rollback();
1013 return -1;
1014 }
1015 } else {
1016 $this->error = $this->db->lasterror();
1017 $this->db->rollback();
1018 return -1;
1019 }
1020 }
1021
1030 public function delete($rowid, $user, $notrigger = 0)
1031 {
1032 $result = 0;
1033 $error = 0;
1034 $errorflag = 0;
1035
1036 // Check parameters
1037 if (empty($rowid)) {
1038 $rowid = $this->id;
1039 }
1040
1041 $this->db->begin();
1042
1043 if (!$error && !$notrigger) {
1044 // Call trigger
1045 $result = $this->call_trigger('MEMBER_DELETE', $user);
1046 if ($result < 0) {
1047 $error++;
1048 }
1049 // End call triggers
1050 }
1051
1052 // Remove category
1053 $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_member WHERE fk_member = ".((int) $rowid);
1054 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1055 $resql = $this->db->query($sql);
1056 if (!$resql) {
1057 $error++;
1058 $this->error .= $this->db->lasterror();
1059 $errorflag = -1;
1060 }
1061
1062 // Remove subscription
1063 if (!$error) {
1064 $sql = "DELETE FROM ".MAIN_DB_PREFIX."subscription WHERE fk_adherent = ".((int) $rowid);
1065 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1066 $resql = $this->db->query($sql);
1067 if (!$resql) {
1068 $error++;
1069 $this->error .= $this->db->lasterror();
1070 $errorflag = -2;
1071 }
1072 }
1073
1074 // Remove linked user
1075 if (!$error) {
1076 $ret = $this->setUserId(0);
1077 if ($ret < 0) {
1078 $error++;
1079 $this->error .= $this->db->lasterror();
1080 $errorflag = -3;
1081 }
1082 }
1083
1084 // Removed extrafields
1085 if (!$error) {
1086 $result = $this->deleteExtraFields();
1087 if ($result < 0) {
1088 $error++;
1089 $errorflag = -4;
1090 dol_syslog(get_class($this)."::delete erreur ".$errorflag." ".$this->error, LOG_ERR);
1091 }
1092 }
1093
1094 // Remove adherent
1095 if (!$error) {
1096 $sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent WHERE rowid = ".((int) $rowid);
1097 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1098 $resql = $this->db->query($sql);
1099 if (!$resql) {
1100 $error++;
1101 $this->error .= $this->db->lasterror();
1102 $errorflag = -5;
1103 }
1104 }
1105
1106 if (!$error) {
1107 $this->db->commit();
1108 return 1;
1109 } else {
1110 $this->db->rollback();
1111 return $errorflag;
1112 }
1113 }
1114
1115
1126 public function setPassword($user, $password = '', $isencrypted = 0, $notrigger = 0, $nosyncuser = 0)
1127 {
1128 global $conf, $langs;
1129
1130 $error = 0;
1131
1132 dol_syslog(get_class($this)."::setPassword user=".$user->id." password=".preg_replace('/./i', '*', $password)." isencrypted=".$isencrypted);
1133
1134 // If new password not provided, we generate one
1135 if (!$password) {
1136 require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
1137 $password = getRandomPassword(false);
1138 }
1139
1140 // Crypt password
1141 $password_crypted = dol_hash($password);
1142
1143 $password_indatabase = '';
1144 if (!$isencrypted) {
1145 $password_indatabase = $password;
1146 }
1147
1148 $this->db->begin();
1149
1150 // Mise a jour
1151 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent";
1152 $sql .= " SET pass_crypted = '".$this->db->escape($password_crypted)."'";
1153 if ($isencrypted) {
1154 $sql .= ", pass = null";
1155 } else {
1156 $sql .= ", pass = '".$this->db->escape($password_indatabase)."'";
1157 }
1158 $sql .= " WHERE rowid = ".((int) $this->id);
1159
1160 //dol_syslog("Adherent::Password sql=hidden");
1161 dol_syslog(get_class($this)."::setPassword", LOG_DEBUG);
1162 $result = $this->db->query($sql);
1163 if ($result) {
1164 $nbaffectedrows = $this->db->affected_rows($result);
1165
1166 if ($nbaffectedrows) {
1167 $this->pass = $password;
1168 $this->pass_indatabase = $password_indatabase;
1169 $this->pass_indatabase_crypted = $password_crypted;
1170
1171 if ($this->user_id && !$nosyncuser) {
1172 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
1173
1174 // This member is linked with a user, so we also update users informations
1175 // if this is an update.
1176 $luser = new User($this->db);
1177 $result = $luser->fetch($this->user_id);
1178
1179 if ($result >= 0) {
1180 $result = $luser->setPassword($user, $this->pass, 0, 0, 1);
1181 if (is_int($result) && $result < 0) {
1182 $this->error = $luser->error;
1183 dol_syslog(get_class($this)."::setPassword ".$this->error, LOG_ERR);
1184 $error++;
1185 }
1186 } else {
1187 $this->error = $luser->error;
1188 $error++;
1189 }
1190 }
1191
1192 if (!$error && !$notrigger) {
1193 // Call trigger
1194 $result = $this->call_trigger('MEMBER_NEW_PASSWORD', $user);
1195 if ($result < 0) {
1196 $error++;
1197 $this->db->rollback();
1198 return -1;
1199 }
1200 // End call triggers
1201 }
1202
1203 $this->db->commit();
1204 return $this->pass;
1205 } else {
1206 $this->db->rollback();
1207 return 0;
1208 }
1209 } else {
1210 $this->db->rollback();
1211 dol_print_error($this->db);
1212 return -1;
1213 }
1214 }
1215
1216
1223 public function setUserId($userid)
1224 {
1225 global $conf, $langs;
1226
1227 $this->db->begin();
1228
1229 // If user is linked to this member, remove old link to this member
1230 $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = NULL WHERE fk_member = ".((int) $this->id);
1231 dol_syslog(get_class($this)."::setUserId", LOG_DEBUG);
1232 $resql = $this->db->query($sql);
1233 if (!$resql) {
1234 $this->error = $this->db->error();
1235 $this->db->rollback();
1236 return -1;
1237 }
1238
1239 // Set link to user
1240 if ($userid > 0) {
1241 $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = ".((int) $this->id);
1242 $sql .= " WHERE rowid = ".((int) $userid);
1243 dol_syslog(get_class($this)."::setUserId", LOG_DEBUG);
1244 $resql = $this->db->query($sql);
1245 if (!$resql) {
1246 $this->error = $this->db->error();
1247 $this->db->rollback();
1248 return -2;
1249 }
1250 }
1251
1252 $this->db->commit();
1253
1254 return 1;
1255 }
1256
1257
1264 public function setThirdPartyId($thirdpartyid)
1265 {
1266 global $conf, $langs;
1267
1268 $this->db->begin();
1269
1270 // Remove link to third party onto any other members
1271 if ($thirdpartyid > 0) {
1272 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET fk_soc = null";
1273 $sql .= " WHERE fk_soc = ".((int) $thirdpartyid);
1274 $sql .= " AND entity = ".$conf->entity;
1275 dol_syslog(get_class($this)."::setThirdPartyId", LOG_DEBUG);
1276 $resql = $this->db->query($sql);
1277 }
1278
1279 // Add link to third party for current member
1280 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET fk_soc = ".($thirdpartyid > 0 ? $thirdpartyid : 'null');
1281 $sql .= " WHERE rowid = ".((int) $this->id);
1282
1283 dol_syslog(get_class($this)."::setThirdPartyId", LOG_DEBUG);
1284 $resql = $this->db->query($sql);
1285 if ($resql) {
1286 $this->db->commit();
1287 return 1;
1288 } else {
1289 $this->error = $this->db->error();
1290 $this->db->rollback();
1291 return -1;
1292 }
1293 }
1294
1295
1296 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1303 public function fetch_login($login)
1304 {
1305 // phpcs:enable
1306 global $conf;
1307
1308 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."adherent";
1309 $sql .= " WHERE login='".$this->db->escape($login)."'";
1310 $sql .= " AND entity = ".$conf->entity;
1311
1312 $resql = $this->db->query($sql);
1313 if ($resql) {
1314 if ($this->db->num_rows($resql)) {
1315 $obj = $this->db->fetch_object($resql);
1316 $this->fetch($obj->rowid);
1317 }
1318 } else {
1319 dol_print_error($this->db);
1320 }
1321 }
1322
1323 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1331 public function fetch_name($firstname, $lastname)
1332 {
1333 // phpcs:enable
1334 global $conf;
1335
1336 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."adherent";
1337 $sql .= " WHERE firstname='".$this->db->escape($firstname)."'";
1338 $sql .= " AND lastname='".$this->db->escape($lastname)."'";
1339 $sql .= " AND entity = ".$conf->entity;
1340
1341 $resql = $this->db->query($sql);
1342 if ($resql) {
1343 if ($this->db->num_rows($resql)) {
1344 $obj = $this->db->fetch_object($resql);
1345 $this->fetch($obj->rowid);
1346 }
1347 } else {
1348 dol_print_error($this->db);
1349 }
1350 }
1351
1363 public function fetch($rowid, $ref = '', $fk_soc = 0, $ref_ext = '', $fetch_optionals = true, $fetch_subscriptions = true)
1364 {
1365 global $langs;
1366
1367 $sql = "SELECT d.rowid, d.ref, d.ref_ext, d.civility as civility_code, d.gender, d.firstname, d.lastname,";
1368 $sql .= " d.societe as company, d.fk_soc, d.statut, d.public, d.address, d.zip, d.town, d.note_private,";
1369 $sql .= " d.note_public,";
1370 $sql .= " d.email, d.url, d.socialnetworks, d.phone, d.phone_perso, d.phone_mobile, d.login, d.pass, d.pass_crypted,";
1371 $sql .= " d.photo, d.fk_adherent_type, d.morphy, d.entity,";
1372 $sql .= " d.datec as datec,";
1373 $sql .= " d.tms as datem,";
1374 $sql .= " d.datefin as datefin, d.default_lang,";
1375 $sql .= " d.birth as birthday,";
1376 $sql .= " d.datevalid as datev,";
1377 $sql .= " d.country,";
1378 $sql .= " d.state_id,";
1379 $sql .= " d.model_pdf,";
1380 $sql .= " c.rowid as country_id, c.code as country_code, c.label as country,";
1381 $sql .= " dep.nom as state, dep.code_departement as state_code,";
1382 $sql .= " t.libelle as type, t.subscription as subscription,";
1383 $sql .= " u.rowid as user_id, u.login as user_login";
1384 $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as t, ".MAIN_DB_PREFIX."adherent as d";
1385 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON d.country = c.rowid";
1386 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as dep ON d.state_id = dep.rowid";
1387 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON d.rowid = u.fk_member";
1388 $sql .= " WHERE d.fk_adherent_type = t.rowid";
1389 if ($rowid) {
1390 $sql .= " AND d.rowid=".((int) $rowid);
1391 } elseif ($ref || $fk_soc) {
1392 $sql .= " AND d.entity IN (".getEntity('adherent').")";
1393 if ($ref) {
1394 $sql .= " AND d.ref='".$this->db->escape($ref)."'";
1395 } elseif ($fk_soc > 0) {
1396 $sql .= " AND d.fk_soc=".((int) $fk_soc);
1397 }
1398 } elseif ($ref_ext) {
1399 $sql .= " AND d.ref_ext='".$this->db->escape($ref_ext)."'";
1400 }
1401
1402 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
1403 $resql = $this->db->query($sql);
1404 if ($resql) {
1405 if ($this->db->num_rows($resql)) {
1406 $obj = $this->db->fetch_object($resql);
1407
1408 $this->entity = $obj->entity;
1409 $this->id = $obj->rowid;
1410 $this->ref = $obj->ref;
1411 $this->ref_ext = $obj->ref_ext;
1412
1413 $this->civility_id = $obj->civility_code; // Bad. Kept for backard compatibility
1414 $this->civility_code = $obj->civility_code;
1415 $this->civility = $obj->civility_code ? ($langs->trans("Civility".$obj->civility_code) != "Civility".$obj->civility_code ? $langs->trans("Civility".$obj->civility_code) : $obj->civility_code) : '';
1416
1417 $this->firstname = $obj->firstname;
1418 $this->lastname = $obj->lastname;
1419 $this->gender = $obj->gender;
1420 $this->login = $obj->login;
1421 $this->societe = $obj->company;
1422 $this->company = $obj->company;
1423 $this->socid = $obj->fk_soc;
1424 $this->fk_soc = $obj->fk_soc; // For backward compatibility
1425 $this->address = $obj->address;
1426 $this->zip = $obj->zip;
1427 $this->town = $obj->town;
1428
1429 $this->pass = $obj->pass;
1430 $this->pass_indatabase = $obj->pass;
1431 $this->pass_indatabase_crypted = $obj->pass_crypted;
1432
1433 $this->state_id = $obj->state_id;
1434 $this->state_code = $obj->state_id ? $obj->state_code : '';
1435 $this->state = $obj->state_id ? $obj->state : '';
1436
1437 $this->country_id = $obj->country_id;
1438 $this->country_code = $obj->country_code;
1439 if ($langs->trans("Country".$obj->country_code) != "Country".$obj->country_code) {
1440 $this->country = $langs->transnoentitiesnoconv("Country".$obj->country_code);
1441 } else {
1442 $this->country = $obj->country;
1443 }
1444
1445 $this->phone = $obj->phone;
1446 $this->phone_perso = $obj->phone_perso;
1447 $this->phone_mobile = $obj->phone_mobile;
1448 $this->email = $obj->email;
1449 $this->url = $obj->url;
1450
1451 $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks, true) : array());
1452
1453 $this->photo = $obj->photo;
1454 $this->statut = $obj->statut;
1455 $this->status = $obj->statut;
1456 $this->public = $obj->public;
1457
1458 $this->datec = $this->db->jdate($obj->datec);
1459 $this->date_creation = $this->db->jdate($obj->datec);
1460 $this->datem = $this->db->jdate($obj->datem);
1461 $this->date_modification = $this->db->jdate($obj->datem);
1462 $this->datefin = $this->db->jdate($obj->datefin);
1463 $this->datevalid = $this->db->jdate($obj->datev);
1464 $this->date_validation = $this->db->jdate($obj->datev);
1465 $this->birth = $this->db->jdate($obj->birthday);
1466
1467 $this->default_lang = $obj->default_lang;
1468
1469 $this->note_private = $obj->note_private;
1470 $this->note_public = $obj->note_public;
1471 $this->morphy = $obj->morphy;
1472
1473 $this->typeid = $obj->fk_adherent_type;
1474 $this->type = $obj->type;
1475 $this->need_subscription = $obj->subscription;
1476
1477 $this->user_id = $obj->user_id;
1478 $this->user_login = $obj->user_login;
1479
1480 $this->model_pdf = $obj->model_pdf;
1481
1482 // Retrieve all extrafield
1483 // fetch optionals attributes and labels
1484 if ($fetch_optionals) {
1485 $this->fetch_optionals();
1486 }
1487
1488 // Load other properties
1489 if ($fetch_subscriptions) {
1490 $result = $this->fetch_subscriptions();
1491 }
1492
1493 return $this->id;
1494 } else {
1495 return 0;
1496 }
1497 } else {
1498 $this->error = $this->db->lasterror();
1499 return -1;
1500 }
1501 }
1502
1503
1504 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1513 public function fetch_subscriptions()
1514 {
1515 // phpcs:enable
1516 global $langs;
1517
1518 require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
1519
1520 $sql = "SELECT c.rowid, c.fk_adherent, c.fk_type, c.subscription, c.note as note_public, c.fk_bank,";
1521 $sql .= " c.tms as datem,";
1522 $sql .= " c.datec as datec,";
1523 $sql .= " c.dateadh as dateh,";
1524 $sql .= " c.datef as datef";
1525 $sql .= " FROM ".MAIN_DB_PREFIX."subscription as c";
1526 $sql .= " WHERE c.fk_adherent = ".((int) $this->id);
1527 $sql .= " ORDER BY c.dateadh";
1528 dol_syslog(get_class($this)."::fetch_subscriptions", LOG_DEBUG);
1529
1530 $resql = $this->db->query($sql);
1531 if ($resql) {
1532 $this->subscriptions = array();
1533
1534 $i = 0;
1535 while ($obj = $this->db->fetch_object($resql)) {
1536 if ($i == 0) {
1537 $this->first_subscription_date = $this->db->jdate($obj->datec);
1538 $this->first_subscription_date_start = $this->db->jdate($obj->dateh);
1539 $this->first_subscription_date_end = $this->db->jdate($obj->datef);
1540 $this->first_subscription_amount = $obj->subscription;
1541 }
1542 $this->last_subscription_date = $this->db->jdate($obj->datec);
1543 $this->last_subscription_date_start = $this->db->jdate($obj->dateh);
1544 $this->last_subscription_date_end = $this->db->jdate($obj->datef);
1545 $this->last_subscription_amount = $obj->subscription;
1546
1547 $subscription = new Subscription($this->db);
1548 $subscription->id = $obj->rowid;
1549 $subscription->fk_adherent = $obj->fk_adherent;
1550 $subscription->fk_type = $obj->fk_type;
1551 $subscription->amount = $obj->subscription;
1552 $subscription->note = $obj->note_public;
1553 $subscription->note_public = $obj->note_public;
1554 $subscription->fk_bank = $obj->fk_bank;
1555 $subscription->datem = $this->db->jdate($obj->datem);
1556 $subscription->datec = $this->db->jdate($obj->datec);
1557 $subscription->dateh = $this->db->jdate($obj->dateh);
1558 $subscription->datef = $this->db->jdate($obj->datef);
1559
1560 $this->subscriptions[] = $subscription;
1561
1562 $i++;
1563 }
1564 return 1;
1565 } else {
1566 $this->error = $this->db->error().' sql='.$sql;
1567 return -1;
1568 }
1569 }
1570
1571
1578 public function fetchPartnerships($mode)
1579 {
1580 global $langs;
1581
1582 require_once DOL_DOCUMENT_ROOT.'/partnership/class/partnership.class.php';
1583
1584
1585 $this->partnerships[] = array();
1586
1587 return 1;
1588 }
1589
1590
1606 public function subscription($date, $amount, $accountid = 0, $operation = '', $label = '', $num_chq = '', $emetteur_nom = '', $emetteur_banque = '', $datesubend = 0, $fk_type = null)
1607 {
1608 global $conf, $langs, $user;
1609
1610 require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
1611
1612 $error = 0;
1613
1614 // Clean parameters
1615 if (!$amount) {
1616 $amount = 0;
1617 }
1618
1619 $this->db->begin();
1620
1621 if ($datesubend) {
1622 $datefin = $datesubend;
1623 } else {
1624 // If no end date, end date = date + 1 year - 1 day
1625 $datefin = dol_time_plus_duree($date, 1, 'y');
1626 $datefin = dol_time_plus_duree($datefin, -1, 'd');
1627 }
1628
1629 // Create subscription
1630 $subscription = new Subscription($this->db);
1631 $subscription->fk_adherent = $this->id;
1632 $subscription->dateh = $date; // Date of new subscription
1633 $subscription->datef = $datefin; // End data of new subscription
1634 $subscription->amount = $amount;
1635 $subscription->note = $label; // deprecated
1636 $subscription->note_public = $label;
1637 $subscription->fk_type = $fk_type;
1638
1639 $rowid = $subscription->create($user);
1640 if ($rowid > 0) {
1641 // Update denormalized subscription end date (read database subscription to find values)
1642 // This will also update this->datefin
1643 $result = $this->update_end_date($user);
1644 if ($result > 0) {
1645 // Change properties of object (used by triggers)
1646 $this->last_subscription_date = dol_now();
1647 $this->last_subscription_date_start = $date;
1648 $this->last_subscription_date_end = $datefin;
1649 $this->last_subscription_amount = $amount;
1650 }
1651
1652 if (!$error) {
1653 $this->db->commit();
1654 return $rowid;
1655 } else {
1656 $this->db->rollback();
1657 return -2;
1658 }
1659 } else {
1660 $this->setErrorsFromObject($subscription);
1661 $this->db->rollback();
1662 return -1;
1663 }
1664 }
1665
1666
1686 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 = '')
1687 {
1688 global $conf, $langs, $user, $mysoc;
1689
1690 $error = 0;
1691
1692 $this->invoice = null; // This will contains invoice if an invoice is created
1693
1694 dol_syslog("subscriptionComplementaryActions subscriptionid=".$subscriptionid." option=".$option." accountid=".$accountid." datesubscription=".$datesubscription." paymentdate=".
1695 $paymentdate." label=".$label." amount=".$amount." num_chq=".$num_chq." autocreatethirdparty=".$autocreatethirdparty);
1696
1697 // Insert into bank account directlty (if option choosed for) + link to llx_subscription if option is 'bankdirect'
1698 if ($option == 'bankdirect' && $accountid) {
1699 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
1700
1701 $acct = new Account($this->db);
1702 $result = $acct->fetch($accountid);
1703
1704 $dateop = $paymentdate;
1705
1706 $insertid = $acct->addline($dateop, $operation, $label, $amount, $num_chq, '', $user, $emetteur_nom, $emetteur_banque);
1707 if ($insertid > 0) {
1708 $inserturlid = $acct->add_url_line($insertid, $this->id, DOL_URL_ROOT.'/adherents/card.php?rowid=', $this->getFullname($langs), 'member');
1709 if ($inserturlid > 0) {
1710 // Update table subscription
1711 $sql = "UPDATE ".MAIN_DB_PREFIX."subscription SET fk_bank=".((int) $insertid);
1712 $sql .= " WHERE rowid=".((int) $subscriptionid);
1713
1714 dol_syslog("subscription::subscription", LOG_DEBUG);
1715 $resql = $this->db->query($sql);
1716 if (!$resql) {
1717 $error++;
1718 $this->error = $this->db->lasterror();
1719 $this->errors[] = $this->error;
1720 }
1721 } else {
1722 $error++;
1723 $this->setErrorsFromObject($acct);
1724 }
1725 } else {
1726 $error++;
1727 $this->setErrorsFromObject($acct);
1728 }
1729 }
1730
1731 // If option choosed, we create invoice
1732 if (($option == 'bankviainvoice' && $accountid) || $option == 'invoiceonly') {
1733 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1734 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/paymentterm.class.php';
1735
1736 $invoice = new Facture($this->db);
1737 $customer = new Societe($this->db);
1738
1739 if (!$error) {
1740 if (!($this->fk_soc > 0)) { // If not yet linked to a company
1741 if ($autocreatethirdparty) {
1742 // Create a linked thirdparty to member
1743 $companyalias = '';
1744 $fullname = $this->getFullName($langs);
1745
1746 if ($this->morphy == 'mor') {
1747 $companyname = $this->company;
1748 if (!empty($fullname)) {
1749 $companyalias = $fullname;
1750 }
1751 } else {
1752 $companyname = $fullname;
1753 if (!empty($this->company)) {
1754 $companyalias = $this->company;
1755 }
1756 }
1757
1758 $result = $customer->create_from_member($this, $companyname, $companyalias);
1759 if ($result < 0) {
1760 $this->error = $customer->error;
1761 $this->errors = $customer->errors;
1762 $error++;
1763 } else {
1764 $this->fk_soc = $result;
1765 }
1766 } else {
1767 $langs->load("errors");
1768 $this->error = $langs->trans("ErrorMemberNotLinkedToAThirpartyLinkOrCreateFirst");
1769 $this->errors[] = $this->error;
1770 $error++;
1771 }
1772 }
1773 }
1774 if (!$error) {
1775 $result = $customer->fetch($this->fk_soc);
1776 if ($result <= 0) {
1777 $this->error = $customer->error;
1778 $this->errors = $customer->errors;
1779 $error++;
1780 }
1781 }
1782
1783 if (!$error) {
1784 // Create draft invoice
1785 $invoice->type = Facture::TYPE_STANDARD;
1786 $invoice->cond_reglement_id = $customer->cond_reglement_id;
1787 if (empty($invoice->cond_reglement_id)) {
1788 $paymenttermstatic = new PaymentTerm($this->db);
1789 $invoice->cond_reglement_id = $paymenttermstatic->getDefaultId();
1790 if (empty($invoice->cond_reglement_id)) {
1791 $error++;
1792 $this->error = 'ErrorNoPaymentTermRECEPFound';
1793 $this->errors[] = $this->error;
1794 }
1795 }
1796 $invoice->socid = $this->fk_soc;
1797 //$invoice->date = $datesubscription;
1798 $invoice->date = dol_now();
1799
1800 // Possibility to add external linked objects with hooks
1801 $invoice->linked_objects['subscription'] = $subscriptionid;
1802 if (!empty($_POST['other_linked_objects']) && is_array($_POST['other_linked_objects'])) {
1803 $invoice->linked_objects = array_merge($invoice->linked_objects, $_POST['other_linked_objects']);
1804 }
1805
1806 $result = $invoice->create($user);
1807 if ($result <= 0) {
1808 $this->error = $invoice->error;
1809 $this->errors = $invoice->errors;
1810 $error++;
1811 } else {
1812 $this->invoice = $invoice;
1813 }
1814 }
1815
1816 if (!$error) {
1817 // Add line to draft invoice
1818 $idprodsubscription = 0;
1819 if (getDolGlobalString('ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS') && (isModEnabled("product") || isModEnabled("service"))) {
1820 $idprodsubscription = $conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS;
1821 }
1822
1823 $vattouse = 0;
1824 if (getDolGlobalString('ADHERENT_VAT_FOR_SUBSCRIPTIONS') == 'defaultforfoundationcountry') {
1825 $vattouse = get_default_tva($mysoc, $mysoc, $idprodsubscription);
1826 }
1827 //print xx".$vattouse." - ".$mysoc." - ".$customer;exit;
1828 $result = $invoice->addline($label, 0, 1, $vattouse, 0, 0, $idprodsubscription, 0, $datesubscription, '', 0, 0, '', 'TTC', $amount, 1);
1829 if ($result <= 0) {
1830 $this->error = $invoice->error;
1831 $this->errors = $invoice->errors;
1832 $error++;
1833 }
1834 }
1835
1836 if (!$error) {
1837 // Validate invoice
1838 $result = $invoice->validate($user);
1839 if ($result <= 0) {
1840 $this->error = $invoice->error;
1841 $this->errors = $invoice->errors;
1842 $error++;
1843 }
1844 }
1845
1846 if (!$error) {
1847 // TODO Link invoice with subscription ?
1848 }
1849
1850 // Add payment onto invoice
1851 if (!$error && $option == 'bankviainvoice' && $accountid) {
1852 require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
1853 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
1854 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
1855
1856 $amounts = array();
1857 $amounts[$invoice->id] = price2num($amount);
1858
1859 $paiement = new Paiement($this->db);
1860 $paiement->datepaye = $paymentdate;
1861 $paiement->amounts = $amounts;
1862 $paiement->paiementcode = $operation;
1863 $paiement->paiementid = dol_getIdFromCode($this->db, $operation, 'c_paiement', 'code', 'id', 1);
1864 $paiement->num_payment = $num_chq;
1865 $paiement->note_public = $label;
1866 $paiement->ext_payment_id = $ext_payment_id;
1867 $paiement->ext_payment_site = $ext_payment_site;
1868
1869 if (!$error) {
1870 // Create payment line for invoice
1871 $paiement_id = $paiement->create($user);
1872 if (!($paiement_id > 0)) {
1873 $this->error = $paiement->error;
1874 $this->errors = $paiement->errors;
1875 $error++;
1876 }
1877 }
1878
1879 if (!$error) {
1880 // Add transaction into bank account
1881 $bank_line_id = $paiement->addPaymentToBank($user, 'payment', '(SubscriptionPayment)', $accountid, $emetteur_nom, $emetteur_banque);
1882 if (!($bank_line_id > 0)) {
1883 $this->error = $paiement->error;
1884 $this->errors = $paiement->errors;
1885 $error++;
1886 }
1887 }
1888
1889 if (!$error && !empty($bank_line_id)) {
1890 // Update fk_bank into subscription table
1891 $sql = 'UPDATE '.MAIN_DB_PREFIX.'subscription SET fk_bank='.((int) $bank_line_id);
1892 $sql .= ' WHERE rowid='.((int) $subscriptionid);
1893
1894 $result = $this->db->query($sql);
1895 if (!$result) {
1896 $error++;
1897 }
1898 }
1899
1900 if (!$error) {
1901 // Set invoice as paid
1902 $invoice->setPaid($user);
1903 }
1904 }
1905
1906 if (!$error) {
1907 // Define output language
1908 $outputlangs = $langs;
1909 $newlang = '';
1910 $lang_id = GETPOST('lang_id');
1911 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && !empty($lang_id)) {
1912 $newlang = $lang_id;
1913 }
1914 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
1915 $newlang = $customer->default_lang;
1916 }
1917 if (!empty($newlang)) {
1918 $outputlangs = new Translate("", $conf);
1919 $outputlangs->setDefaultLang($newlang);
1920 }
1921 // Generate PDF (whatever is option MAIN_DISABLE_PDF_AUTOUPDATE) so we can include it into email
1922 //if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE'))
1923
1924 $invoice->generateDocument($invoice->model_pdf, $outputlangs);
1925 }
1926 }
1927
1928 if ($error) {
1929 return -1;
1930 } else {
1931 return 1;
1932 }
1933 }
1934
1935
1942 public function validate($user)
1943 {
1944 global $langs, $conf;
1945
1946 $error = 0;
1947 $now = dol_now();
1948
1949 // Check parameters
1950 if ($this->statut == self::STATUS_VALIDATED) {
1951 dol_syslog(get_class($this)."::validate statut of member does not allow this", LOG_WARNING);
1952 return 0;
1953 }
1954
1955 $this->db->begin();
1956
1957 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
1958 $sql .= " statut = ".self::STATUS_VALIDATED;
1959 $sql .= ", datevalid = '".$this->db->idate($now)."'";
1960 $sql .= ", fk_user_valid = ".((int) $user->id);
1961 $sql .= " WHERE rowid = ".((int) $this->id);
1962
1963 dol_syslog(get_class($this)."::validate", LOG_DEBUG);
1964 $result = $this->db->query($sql);
1965 if ($result) {
1967
1968 // Call trigger
1969 $result = $this->call_trigger('MEMBER_VALIDATE', $user);
1970 if ($result < 0) {
1971 $error++;
1972 $this->db->rollback();
1973 return -1;
1974 }
1975 // End call triggers
1976
1977 $this->datevalid = $now;
1978
1979 $this->db->commit();
1980 return 1;
1981 } else {
1982 $this->error = $this->db->error();
1983 $this->db->rollback();
1984 return -1;
1985 }
1986 }
1987
1988
1995 public function resiliate($user)
1996 {
1997 global $langs, $conf;
1998
1999 $error = 0;
2000
2001 // Check parameters
2002 if ($this->statut == self::STATUS_RESILIATED) {
2003 dol_syslog(get_class($this)."::resiliate statut of member does not allow this", LOG_WARNING);
2004 return 0;
2005 }
2006
2007 $this->db->begin();
2008
2009 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
2010 $sql .= " statut = ".self::STATUS_RESILIATED;
2011 $sql .= ", fk_user_valid=".$user->id;
2012 $sql .= " WHERE rowid = ".((int) $this->id);
2013
2014 $result = $this->db->query($sql);
2015 if ($result) {
2017
2018 // Call trigger
2019 $result = $this->call_trigger('MEMBER_RESILIATE', $user);
2020 if ($result < 0) {
2021 $error++;
2022 $this->db->rollback();
2023 return -1;
2024 }
2025 // End call triggers
2026
2027 $this->db->commit();
2028 return 1;
2029 } else {
2030 $this->error = $this->db->error();
2031 $this->db->rollback();
2032 return -1;
2033 }
2034 }
2035
2045 public function exclude($user)
2046 {
2047 $error = 0;
2048
2049 // Check parameters
2050 if ($this->statut == self::STATUS_EXCLUDED) {
2051 dol_syslog(get_class($this)."::resiliate statut of member does not allow this", LOG_WARNING);
2052 return 0;
2053 }
2054
2055 $this->db->begin();
2056
2057 $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET";
2058 $sql .= " statut = ".self::STATUS_EXCLUDED;
2059 $sql .= ", fk_user_valid=".$user->id;
2060 $sql .= " WHERE rowid = ".((int) $this->id);
2061
2062 $result = $this->db->query($sql);
2063 if ($result) {
2065
2066 // Call trigger
2067 $result = $this->call_trigger('MEMBER_EXCLUDE', $user);
2068 if ($result < 0) {
2069 $error++;
2070 $this->db->rollback();
2071 return -1;
2072 }
2073 // End call triggers
2074
2075 $this->db->commit();
2076 return 1;
2077 } else {
2078 $this->error = $this->db->error();
2079 $this->db->rollback();
2080 return -1;
2081 }
2082 }
2083
2084 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2090 public function add_to_abo()
2091 {
2092 // phpcs:enable
2093 global $langs;
2094
2095 include_once DOL_DOCUMENT_ROOT.'/mailmanspip/class/mailmanspip.class.php';
2096 $mailmanspip = new MailmanSpip($this->db);
2097
2098 $err = 0;
2099
2100 // mailman
2101 if (getDolGlobalString('ADHERENT_USE_MAILMAN') && isModEnabled('mailmanspip')) {
2102 $result = $mailmanspip->add_to_mailman($this);
2103
2104 if ($result < 0) {
2105 if (!empty($mailmanspip->error)) {
2106 $this->errors[] = $mailmanspip->error;
2107 }
2108 $err += 1;
2109 }
2110 foreach ($mailmanspip->mladded_ko as $tmplist => $tmpemail) {
2111 $langs->load("errors");
2112 $this->errors[] = $langs->trans("ErrorFailedToAddToMailmanList", $tmpemail, $tmplist);
2113 }
2114 foreach ($mailmanspip->mladded_ok as $tmplist => $tmpemail) {
2115 $langs->load("mailmanspip");
2116 $this->mesgs[] = $langs->trans("SuccessToAddToMailmanList", $tmpemail, $tmplist);
2117 }
2118 }
2119
2120 // spip
2121 if (getDolGlobalString('ADHERENT_USE_SPIP') && isModEnabled('mailmanspip')) {
2122 $result = $mailmanspip->add_to_spip($this);
2123 if ($result < 0) {
2124 $this->errors[] = $mailmanspip->error;
2125 $err += 1;
2126 }
2127 }
2128 if ($err) {
2129 return -$err;
2130 } else {
2131 return 1;
2132 }
2133 }
2134
2135
2136 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2142 public function del_to_abo()
2143 {
2144 // phpcs:enable
2145 global $conf, $langs;
2146
2147 include_once DOL_DOCUMENT_ROOT.'/mailmanspip/class/mailmanspip.class.php';
2148 $mailmanspip = new MailmanSpip($this->db);
2149
2150 $err = 0;
2151
2152 // mailman
2153 if (getDolGlobalString('ADHERENT_USE_MAILMAN')) {
2154 $result = $mailmanspip->del_to_mailman($this);
2155 if ($result < 0) {
2156 if (!empty($mailmanspip->error)) {
2157 $this->errors[] = $mailmanspip->error;
2158 }
2159 $err += 1;
2160 }
2161
2162 foreach ($mailmanspip->mlremoved_ko as $tmplist => $tmpemail) {
2163 $langs->load("errors");
2164 $this->errors[] = $langs->trans("ErrorFailedToRemoveToMailmanList", $tmpemail, $tmplist);
2165 }
2166 foreach ($mailmanspip->mlremoved_ok as $tmplist => $tmpemail) {
2167 $langs->load("mailmanspip");
2168 $this->mesgs[] = $langs->trans("SuccessToRemoveToMailmanList", $tmpemail, $tmplist);
2169 }
2170 }
2171
2172 if ($conf->global->ADHERENT_USE_SPIP && isModEnabled('mailmanspip')) {
2173 $result = $mailmanspip->del_to_spip($this);
2174 if ($result < 0) {
2175 $this->errors[] = $mailmanspip->error;
2176 $err += 1;
2177 }
2178 }
2179 if ($err) {
2180 // error
2181 return -$err;
2182 } else {
2183 return 1;
2184 }
2185 }
2186
2187
2193 public function getCivilityLabel()
2194 {
2195 global $langs;
2196 $langs->load("dict");
2197
2198 $code = (empty($this->civility_id) ? '' : $this->civility_id);
2199 if (empty($code)) {
2200 return '';
2201 }
2202 return $langs->getLabelFromKey($this->db, "Civility".$code, "c_civility", "code", "label", $code);
2203 }
2204
2211 public function getTooltipContentArray($params)
2212 {
2213 global $langs;
2214
2215 $langs->loadLangs(['members', 'companies']);
2216 $nofetch = !empty($params['nofetch']);
2217
2218 $datas = array();
2219
2220 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
2221 $langs->load("users");
2222 return ['optimize' => $langs->trans("ShowUser")];
2223 }
2224 if (!empty($this->photo)) {
2225 $photo = '<div class="photointooltip floatright">';
2226 $photo .= Form::showphoto('memberphoto', $this, 80, 0, 0, 'photoref photowithmargin photologintooltip', 'small', 0, 1);
2227 $photo .= '</div>';
2228 $datas['photo'] = $photo;
2229 }
2230
2231 $datas['divopen'] = '<div class="centpercent">';
2232 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Member").'</u> '.$this->getLibStatut(4);
2233 if (!empty($this->morphy)) {
2234 $datas['picto'] .= '&nbsp;' . $this->getmorphylib('', 1);
2235 }
2236 if (!empty($this->ref)) {
2237 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
2238 }
2239 if (!empty($this->login)) {
2240 $datas['login'] = '<br><b>'.$langs->trans('Login').':</b> '.$this->login;
2241 }
2242 if (!empty($this->firstname) || !empty($this->lastname)) {
2243 $datas['name'] = '<br><b>'.$langs->trans('Name').':</b> '.$this->getFullName($langs);
2244 }
2245 if (!empty($this->company)) {
2246 $datas['company'] = '<br><b>'.$langs->trans('Company').':</b> '.$this->company;
2247 }
2248 if (!empty($this->email)) {
2249 $datas['email'] = '<br><b>'.$langs->trans("EMail").':</b> '.$this->email;
2250 }
2251 $datas['address'] = '<br><b>'.$langs->trans("Address").':</b> '.dol_format_address($this, 1, ' ', $langs);
2252 // show categories for this record only in ajax to not overload lists
2253 if (isModEnabled('categorie') && !$nofetch) {
2254 require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
2255 $form = new Form($this->db);
2256 $datas['categories'] = '<br>' . $form->showCategories($this->id, Categorie::TYPE_MEMBER, 1);
2257 }
2258 $datas['divclose'] = '</div>';
2259
2260 return $datas;
2261 }
2262
2276 public function getNomUrl($withpictoimg = 0, $maxlen = 0, $option = 'card', $mode = '', $morecss = '', $save_lastsearch_value = -1, $notooltip = 0, $addlinktonotes = 0)
2277 {
2278 global $conf, $langs, $hookmanager;
2279
2280 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') && $withpictoimg) {
2281 $withpictoimg = 0;
2282 }
2283
2284 $result = '';
2285 $linkstart = '';
2286 $linkend = '';
2287 $classfortooltip = 'classfortooltip';
2288 $dataparams = '';
2289 $params = [
2290 'id' => $this->id,
2291 'objecttype' => $this->element,
2292 'option' => $option,
2293 'nofetch' => 1,
2294 ];
2295 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
2296 $classfortooltip = 'classforajaxtooltip';
2297 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
2298 $label = '';
2299 } else {
2300 $label = implode($this->getTooltipContentArray($params));
2301 }
2302
2303 $url = DOL_URL_ROOT.'/adherents/card.php?rowid='.((int) $this->id);
2304 if ($option == 'subscription') {
2305 $url = DOL_URL_ROOT.'/adherents/subscription.php?rowid='.((int) $this->id);
2306 }
2307
2308 if ($option != 'nolink') {
2309 // Add param to save lastsearch_values or not
2310 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2311 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
2312 $add_save_lastsearch_values = 1;
2313 }
2314 if ($add_save_lastsearch_values) {
2315 $url .= '&save_lastsearch_values=1';
2316 }
2317 }
2318
2319 $linkstart .= '<a href="'.$url.'"';
2320 $linkclose = "";
2321 if (empty($notooltip)) {
2322 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
2323 $langs->load("users");
2324 $label = $langs->trans("ShowUser");
2325 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
2326 }
2327 $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
2328 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
2329 }
2330
2331 $linkstart .= $linkclose.'>';
2332 $linkend = '</a>';
2333
2334 $result .= $linkstart;
2335 if ($withpictoimg) {
2336 $result .= '<div class="inline-block nopadding valignmiddle">';
2337 }
2338 if ($withpictoimg) {
2339 $paddafterimage = '';
2340 if (abs($withpictoimg) == 1 || abs($withpictoimg) == 4) {
2341 $morecss .= ' paddingrightonly';
2342 }
2343 // Only picto
2344 if ($withpictoimg > 0) {
2345 $picto = '<span class="nopadding'.($morecss ? ' userimg'.$morecss : '').'">'.img_object('', 'user', $paddafterimage.' '.($notooltip ? '' : $dataparams), 0, 0, $notooltip ? 0 : 1).'</span>';
2346 } else {
2347 // Picto must be a photo
2348 $picto = '<span class="nopadding'.($morecss ? ' userimg'.$morecss : '').'"'.($paddafterimage ? ' '.$paddafterimage : '').'>';
2349 $picto .= Form::showphoto('memberphoto', $this, 0, 0, 0, 'userphoto'.(($withpictoimg == -3 || $withpictoimg == -4) ? 'small' : ''), 'mini', 0, 1);
2350 $picto .= '</span>';
2351 }
2352 $result .= $picto;
2353 }
2354 if (($withpictoimg > -2 && $withpictoimg != 2) || $withpictoimg == -4) {
2355 if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
2356 $result .= '<span class="nopadding valignmiddle'.((!isset($this->statut) || $this->statut) ? '' : ' strikefordisabled').
2357 ($morecss ? ' usertext'.$morecss : '').'">';
2358 }
2359 if ($mode == 'login') {
2360 $result .= dol_trunc($this->login, $maxlen);
2361 } elseif ($mode == 'ref') {
2362 $result .= $this->ref;
2363 } else {
2364 $result .= $this->getFullName($langs, '', ($mode == 'firstname' ? 2 : ($mode == 'lastname' ? 4 : -1)), $maxlen);
2365 }
2366 if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
2367 $result .= '</span>';
2368 }
2369 }
2370 if ($withpictoimg) {
2371 $result .= '</div>';
2372 }
2373 $result .= $linkend;
2374
2375 if ($addlinktonotes) {
2376 if ($this->note_private) {
2377 $notetoshow = $langs->trans("ViewPrivateNote").':<br>'.dol_string_nohtmltag($this->note_private, 1);
2378 $result .= ' <span class="note inline-block">';
2379 $result .= '<a href="'.DOL_URL_ROOT.'/adherents/note.php?id='.$this->id.'" class="classfortooltip" title="'.dol_escape_htmltag($notetoshow).'">';
2380 $result .= img_picto('', 'note');
2381 $result .= '</a>';
2382 $result .= '</span>';
2383 }
2384 }
2385 global $action;
2386 $hookmanager->initHooks(array($this->element . 'dao'));
2387 $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
2388 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
2389 if ($reshook > 0) {
2390 $result = $hookmanager->resPrint;
2391 } else {
2392 $result .= $hookmanager->resPrint;
2393 }
2394 return $result;
2395 }
2396
2403 public function getLibStatut($mode = 0)
2404 {
2405 return $this->LibStatut($this->statut, $this->need_subscription, $this->datefin, $mode);
2406 }
2407
2408 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2418 public function LibStatut($status, $need_subscription, $date_end_subscription, $mode = 0)
2419 {
2420 // phpcs:enable
2421 global $langs;
2422 $langs->load("members");
2423
2424 $statusType = '';
2425 $labelStatus = '';
2426 $labelStatusShort = '';
2427
2428 if ($status == self::STATUS_DRAFT) {
2429 $statusType = 'status0';
2430 $labelStatus = $langs->trans("MemberStatusDraft");
2431 $labelStatusShort = $langs->trans("MemberStatusDraftShort");
2432 } elseif ($status >= self::STATUS_VALIDATED) {
2433 if ($need_subscription === 0) {
2434 $statusType = 'status4';
2435 $labelStatus = $langs->trans("MemberStatusNoSubscription");
2436 $labelStatusShort = $langs->trans("MemberStatusNoSubscriptionShort");
2437 } elseif (!$date_end_subscription) {
2438 $statusType = 'status1';
2439 $labelStatus = $langs->trans("WaitingSubscription");
2440 $labelStatusShort = $langs->trans("WaitingSubscriptionShort");
2441 } elseif ($date_end_subscription < dol_now()) { // expired
2442 $statusType = 'status8';
2443 $labelStatus = $langs->trans("MemberStatusActiveLate");
2444 $labelStatusShort = $langs->trans("MemberStatusActiveLateShort");
2445 } else {
2446 $statusType = 'status4';
2447 $labelStatus = $langs->trans("MemberStatusPaid");
2448 $labelStatusShort = $langs->trans("MemberStatusPaidShort");
2449 }
2450 } elseif ($status == self::STATUS_RESILIATED) {
2451 $statusType = 'status6';
2452 $labelStatus = $langs->transnoentitiesnoconv("MemberStatusResiliated");
2453 $labelStatusShort = $langs->transnoentitiesnoconv("MemberStatusResiliatedShort");
2454 } elseif ($status == self::STATUS_EXCLUDED) {
2455 $statusType = 'status10';
2456 $labelStatus = $langs->transnoentitiesnoconv("MemberStatusExcluded");
2457 $labelStatusShort = $langs->transnoentitiesnoconv("MemberStatusExcludedShort");
2458 }
2459
2460 return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode);
2461 }
2462
2463
2464 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2470 public function load_state_board()
2471 {
2472 // phpcs:enable
2473 global $conf;
2474
2475 $this->nb = array();
2476
2477 $sql = "SELECT count(a.rowid) as nb";
2478 $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a";
2479 $sql .= " WHERE a.statut > 0";
2480 $sql .= " AND a.entity IN (".getEntity('adherent').")";
2481
2482 $resql = $this->db->query($sql);
2483 if ($resql) {
2484 while ($obj = $this->db->fetch_object($resql)) {
2485 $this->nb["members"] = $obj->nb;
2486 }
2487 $this->db->free($resql);
2488 return 1;
2489 } else {
2490 dol_print_error($this->db);
2491 $this->error = $this->db->error();
2492 return -1;
2493 }
2494 }
2495
2496 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2504 public function load_board($user, $mode)
2505 {
2506 // phpcs:enable
2507 global $conf, $langs;
2508
2509 if ($user->socid) {
2510 return -1; // protection pour eviter appel par utilisateur externe
2511 }
2512
2513 $now = dol_now();
2514
2515 $sql = "SELECT a.rowid, a.datefin, a.statut";
2516 $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a";
2517 $sql .= ", ".MAIN_DB_PREFIX."adherent_type as t";
2518 $sql .= " WHERE a.fk_adherent_type = t.rowid";
2519 if ($mode == 'expired') {
2520 $sql .= " AND a.statut = ".self::STATUS_VALIDATED;
2521 $sql .= " AND a.entity IN (".getEntity('adherent').")";
2522 $sql .= " AND ((a.datefin IS NULL or a.datefin < '".$this->db->idate($now)."') AND t.subscription = '1')";
2523 } elseif ($mode == 'shift') {
2524 $sql .= " AND a.statut = ".self::STATUS_DRAFT;
2525 $sql .= " AND a.entity IN (".getEntity('adherent').")";
2526 }
2527
2528 $resql = $this->db->query($sql);
2529 if ($resql) {
2530 $langs->load("members");
2531
2532 $warning_delay = 0;
2533 $url = '';
2534 $label = '';
2535 $labelShort = '';
2536
2537 if ($mode == 'expired') {
2538 $warning_delay = $conf->adherent->subscription->warning_delay / 60 / 60 / 24;
2539 $label = $langs->trans("MembersWithSubscriptionToReceive");
2540 $labelShort = $langs->trans("MembersWithSubscriptionToReceiveShort");
2541 $url = DOL_URL_ROOT.'/adherents/list.php?mainmenu=members&amp;statut='.self::STATUS_VALIDATED.'&amp;filter=outofdate';
2542 } elseif ($mode == 'shift') {
2543 $warning_delay = $conf->adherent->subscription->warning_delay / 60 / 60 / 24;
2544 $url = DOL_URL_ROOT.'/adherents/list.php?mainmenu=members&amp;statut='.self::STATUS_DRAFT;
2545 $label = $langs->trans("MembersListToValid");
2546 $labelShort = $langs->trans("ToValidate");
2547 }
2548
2549 $response = new WorkboardResponse();
2550 $response->warning_delay = $warning_delay;
2551 $response->label = $label;
2552 $response->labelShort = $labelShort;
2553 $response->url = $url;
2554 $response->img = img_object('', "user");
2555
2556 $adherentstatic = new Adherent($this->db);
2557
2558 while ($obj = $this->db->fetch_object($resql)) {
2559 $response->nbtodo++;
2560
2561 $adherentstatic->datefin = $this->db->jdate($obj->datefin);
2562 $adherentstatic->statut = $obj->statut;
2563
2564 if ($adherentstatic->hasDelay()) {
2565 $response->nbtodolate++;
2566 }
2567 }
2568
2569 return $response;
2570 } else {
2571 dol_print_error($this->db);
2572 $this->error = $this->db->error();
2573 return -1;
2574 }
2575 }
2576
2577
2589 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
2590 {
2591 global $conf, $langs;
2592
2593 $langs->load("orders");
2594
2595 if (!dol_strlen($modele)) {
2596 $modele = 'standard';
2597
2598 if ($this->model_pdf) {
2599 $modele = $this->model_pdf;
2600 } elseif (getDolGlobalString('ADHERENT_ADDON_PDF')) {
2601 $modele = $conf->global->ADHERENT_ADDON_PDF;
2602 }
2603 }
2604
2605 $modelpath = "core/modules/member/doc/";
2606
2607 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
2608 }
2609
2610
2618 public function initAsSpecimen()
2619 {
2620 global $user, $langs;
2621 $now = dol_now();
2622
2623 // Initialise parametres
2624 $this->id = 0;
2625 $this->ref = 'ABC001';
2626 $this->entity = 1;
2627 $this->specimen = 1;
2628 $this->civility_id = 0;
2629 $this->lastname = 'DOLIBARR';
2630 $this->firstname = 'SPECIMEN';
2631 $this->gender = 'man';
2632 $this->login = 'dolibspec';
2633 $this->pass = 'dolibspec';
2634 $this->company = 'Societe ABC';
2635 $this->address = '61 jump street';
2636 $this->zip = '75000';
2637 $this->town = 'Paris';
2638 $this->country_id = 1;
2639 $this->country_code = 'FR';
2640 $this->country = 'France';
2641 $this->morphy = 'mor';
2642 $this->email = 'specimen@specimen.com';
2643 $this->socialnetworks = array(
2644 'skype' => 'skypepseudo',
2645 'twitter' => 'twitterpseudo',
2646 'facebook' => 'facebookpseudo',
2647 'linkedin' => 'linkedinpseudo',
2648 );
2649 $this->phone = '0999999999';
2650 $this->phone_perso = '0999999998';
2651 $this->phone_mobile = '0999999997';
2652 $this->note_public = 'This is a public note';
2653 $this->note_private = 'This is a private note';
2654 $this->birth = $now;
2655 $this->photo = '';
2656 $this->public = 1;
2657 $this->statut = self::STATUS_DRAFT;
2658
2659 $this->datefin = $now;
2660 $this->datevalid = $now;
2661 $this->default_lang = '';
2662
2663 $this->typeid = 1; // Id type adherent
2664 $this->type = 'Type adherent'; // Libelle type adherent
2665 $this->need_subscription = 0;
2666
2667 $this->first_subscription_date = $now;
2668 $this->first_subscription_date_start = $this->first_subscription_date;
2669 $this->first_subscription_date_end = dol_time_plus_duree($this->first_subscription_date_start, 1, 'y');
2670 $this->first_subscription_amount = 10;
2671
2672 $this->last_subscription_date = $this->first_subscription_date;
2673 $this->last_subscription_date_start = $this->first_subscription_date;
2674 $this->last_subscription_date_end = dol_time_plus_duree($this->last_subscription_date_start, 1, 'y');
2675 $this->last_subscription_amount = 10;
2676 return 1;
2677 }
2678
2679
2680 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2681 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2691 public function _load_ldap_dn($info, $mode = 0)
2692 {
2693 // phpcs:enable
2694 global $conf;
2695 $dn = '';
2696 if ($mode == 0) {
2697 $dn = getDolGlobalString('LDAP_KEY_MEMBERS') . "=".$info[getDolGlobalString('LDAP_KEY_MEMBERS')]."," . getDolGlobalString('LDAP_MEMBER_DN');
2698 }
2699 if ($mode == 1) {
2700 $dn = $conf->global->LDAP_MEMBER_DN;
2701 }
2702 if ($mode == 2) {
2703 $dn = getDolGlobalString('LDAP_KEY_MEMBERS') . "=".$info[getDolGlobalString('LDAP_KEY_MEMBERS')];
2704 }
2705 return $dn;
2706 }
2707
2708
2709 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2710 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
2716 public function _load_ldap_info()
2717 {
2718 // phpcs:enable
2719 global $conf, $langs;
2720
2721 $info = array();
2722 $socialnetworks = getArrayOfSocialNetworks();
2723 $keymodified = false;
2724
2725 // Object classes
2726 $info["objectclass"] = explode(',', getDolGlobalString('LDAP_MEMBER_OBJECT_CLASS'));
2727
2728 $this->fullname = $this->getFullName($langs);
2729
2730 // For avoid ldap error when firstname and lastname are empty
2731 if ($this->morphy == 'mor' && (empty($this->fullname) || $this->fullname == $this->company)) {
2732 $this->fullname = $this->company;
2733 $this->lastname = $this->company;
2734 }
2735
2736 // Possible LDAP KEY (constname => varname)
2737 $ldapkey = array(
2738 'LDAP_MEMBER_FIELD_FULLNAME' => 'fullname',
2739 'LDAP_MEMBER_FIELD_NAME' => 'lastname',
2740 'LDAP_MEMBER_FIELD_LOGIN' => 'login',
2741 'LDAP_MEMBER_FIELD_LOGIN_SAMBA' => 'login',
2742 'LDAP_MEMBER_FIELD_MAIL' => 'email'
2743 );
2744
2745 // Member
2746 foreach ($ldapkey as $constname => $varname) {
2747 if (!empty($this->$varname) && getDolGlobalString($constname)) {
2748 $info[getDolGlobalString($constname)] = $this->$varname;
2749
2750 // Check if it is the LDAP key and if its value has been changed
2751 if (getDolGlobalString('LDAP_KEY_MEMBERS') && getDolGlobalString('LDAP_KEY_MEMBERS') == getDolGlobalString($constname)) {
2752 if (!empty($this->oldcopy) && $this->$varname != $this->oldcopy->$varname) {
2753 $keymodified = true; // For check if LDAP key has been modified
2754 }
2755 }
2756 }
2757 }
2758 if ($this->firstname && getDolGlobalString('LDAP_MEMBER_FIELD_FIRSTNAME')) {
2759 $info[getDolGlobalString('LDAP_MEMBER_FIELD_FIRSTNAME')] = $this->firstname;
2760 }
2761 if ($this->poste && getDolGlobalString('LDAP_MEMBER_FIELD_TITLE')) {
2762 $info[getDolGlobalString('LDAP_MEMBER_FIELD_TITLE')] = $this->poste;
2763 }
2764 if ($this->company && getDolGlobalString('LDAP_MEMBER_FIELD_COMPANY')) {
2765 $info[getDolGlobalString('LDAP_MEMBER_FIELD_COMPANY')] = $this->company;
2766 }
2767 if ($this->address && getDolGlobalString('LDAP_MEMBER_FIELD_ADDRESS')) {
2768 $info[getDolGlobalString('LDAP_MEMBER_FIELD_ADDRESS')] = $this->address;
2769 }
2770 if ($this->zip && getDolGlobalString('LDAP_MEMBER_FIELD_ZIP')) {
2771 $info[getDolGlobalString('LDAP_MEMBER_FIELD_ZIP')] = $this->zip;
2772 }
2773 if ($this->town && getDolGlobalString('LDAP_MEMBER_FIELD_TOWN')) {
2774 $info[getDolGlobalString('LDAP_MEMBER_FIELD_TOWN')] = $this->town;
2775 }
2776 if ($this->country_code && getDolGlobalString('LDAP_MEMBER_FIELD_COUNTRY')) {
2777 $info[getDolGlobalString('LDAP_MEMBER_FIELD_COUNTRY')] = $this->country_code;
2778 }
2779 foreach ($socialnetworks as $key => $value) {
2780 if ($this->socialnetworks[$value['label']] && getDolGlobalString('LDAP_MEMBER_FIELD_'.strtoupper($value['label']))) {
2781 $info[getDolGlobalString('LDAP_MEMBER_FIELD_'.strtoupper($value['label']))] = $this->socialnetworks[$value['label']];
2782 }
2783 }
2784 if ($this->phone && getDolGlobalString('LDAP_MEMBER_FIELD_PHONE')) {
2785 $info[getDolGlobalString('LDAP_MEMBER_FIELD_PHONE')] = $this->phone;
2786 }
2787 if ($this->phone_perso && getDolGlobalString('LDAP_MEMBER_FIELD_PHONE_PERSO')) {
2788 $info[getDolGlobalString('LDAP_MEMBER_FIELD_PHONE_PERSO')] = $this->phone_perso;
2789 }
2790 if ($this->phone_mobile && getDolGlobalString('LDAP_MEMBER_FIELD_MOBILE')) {
2791 $info[getDolGlobalString('LDAP_MEMBER_FIELD_MOBILE')] = $this->phone_mobile;
2792 }
2793 if ($this->fax && getDolGlobalString('LDAP_MEMBER_FIELD_FAX')) {
2794 $info[getDolGlobalString('LDAP_MEMBER_FIELD_FAX')] = $this->fax;
2795 }
2796 if ($this->note_private && getDolGlobalString('LDAP_MEMBER_FIELD_DESCRIPTION')) {
2797 $info[getDolGlobalString('LDAP_MEMBER_FIELD_DESCRIPTION')] = dol_string_nohtmltag($this->note_private, 2);
2798 }
2799 if ($this->note_public && getDolGlobalString('LDAP_MEMBER_FIELD_NOTE_PUBLIC')) {
2800 $info[getDolGlobalString('LDAP_MEMBER_FIELD_NOTE_PUBLIC')] = dol_string_nohtmltag($this->note_public, 2);
2801 }
2802 if ($this->birth && getDolGlobalString('LDAP_MEMBER_FIELD_BIRTHDATE')) {
2803 $info[getDolGlobalString('LDAP_MEMBER_FIELD_BIRTHDATE')] = dol_print_date($this->birth, 'dayhourldap');
2804 }
2805 if (isset($this->statut) && getDolGlobalString('LDAP_FIELD_MEMBER_STATUS')) {
2806 $info[getDolGlobalString('LDAP_FIELD_MEMBER_STATUS')] = $this->statut;
2807 }
2808 if ($this->datefin && getDolGlobalString('LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION')) {
2809 $info[getDolGlobalString('LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION')] = dol_print_date($this->datefin, 'dayhourldap');
2810 }
2811
2812 // When password is modified
2813 if (!empty($this->pass)) {
2814 if (getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD')) {
2815 $info[getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD')] = $this->pass; // this->pass = mot de passe non crypte
2816 }
2817 if (getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')) {
2818 $info[getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')] = dol_hash($this->pass, 'openldap'); // Create OpenLDAP password (see LDAP_PASSWORD_HASH_TYPE)
2819 }
2820 } elseif (getDolGlobalString('LDAP_SERVER_PROTOCOLVERSION') !== '3') {
2821 // Set LDAP password if possible
2822 // If ldap key is modified and LDAPv3 we use ldap_rename function for avoid lose encrypt password
2823 if (getDolGlobalString('DATABASE_PWD_ENCRYPTED')) { // This should be on on default installation
2824 // Just for the case we use old md5 encryption (deprecated, no more used, kept for compatibility)
2825 if (!getDolGlobalString('MAIN_SECURITY_HASH_ALGO') || getDolGlobalString('MAIN_SECURITY_HASH_ALGO') == 'md5') {
2826 if ($this->pass_indatabase_crypted && getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')) {
2827 // Create OpenLDAP MD5 password from Dolibarr MD5 password
2828 // Note: This suppose that "pass_indatabase_crypted" is a md5 (this should not happen anymore)"
2829 $info[getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')] = dolGetLdapPasswordHash($this->pass_indatabase_crypted, 'md5frommd5');
2830 }
2831 }
2832 } elseif (!empty($this->pass_indatabase)) {
2833 // Use $this->pass_indatabase value if exists
2834 if (getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD')) {
2835 $info[getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD')] = $this->pass_indatabase; // $this->pass_indatabase = mot de passe non crypte
2836 }
2837 if (getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')) {
2838 $info[getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')] = dol_hash($this->pass_indatabase, 'openldap'); // Create OpenLDAP password (see LDAP_PASSWORD_HASH_TYPE)
2839 }
2840 }
2841 }
2842
2843 // Subscriptions
2844 if ($this->first_subscription_date && getDolGlobalString('LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE')) {
2845 $info[getDolGlobalString('LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE')] = dol_print_date($this->first_subscription_date, 'dayhourldap');
2846 }
2847 if (isset($this->first_subscription_amount) && getDolGlobalString('LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT')) {
2848 $info[getDolGlobalString('LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT')] = $this->first_subscription_amount;
2849 }
2850 if ($this->last_subscription_date && getDolGlobalString('LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE')) {
2851 $info[getDolGlobalString('LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE')] = dol_print_date($this->last_subscription_date, 'dayhourldap');
2852 }
2853 if (isset($this->last_subscription_amount) && getDolGlobalString('LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT')) {
2854 $info[getDolGlobalString('LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT')] = $this->last_subscription_amount;
2855 }
2856
2857 return $info;
2858 }
2859
2860
2867 public function info($id)
2868 {
2869 $sql = 'SELECT a.rowid, a.datec as datec,';
2870 $sql .= ' a.datevalid as datev,';
2871 $sql .= ' a.tms as datem,';
2872 $sql .= ' a.fk_user_author, a.fk_user_valid, a.fk_user_mod';
2873 $sql .= ' FROM '.MAIN_DB_PREFIX.'adherent as a';
2874 $sql .= ' WHERE a.rowid = '.((int) $id);
2875
2876 dol_syslog(get_class($this)."::info", LOG_DEBUG);
2877 $result = $this->db->query($sql);
2878 if ($result) {
2879 if ($this->db->num_rows($result)) {
2880 $obj = $this->db->fetch_object($result);
2881
2882 $this->id = $obj->rowid;
2883
2884 $this->user_creation_id = $obj->fk_user_author;
2885 $this->user_validation_id = $obj->fk_user_valid;
2886 $this->user_modification_id = $obj->fk_user_mod;
2887 $this->date_creation = $this->db->jdate($obj->datec);
2888 $this->date_validation = $this->db->jdate($obj->datev);
2889 $this->date_modification = $this->db->jdate($obj->datem);
2890 }
2891
2892 $this->db->free($result);
2893 } else {
2894 dol_print_error($this->db);
2895 }
2896 }
2897
2903 public function getNbOfEMailings()
2904 {
2905 $sql = "SELECT count(mc.email) as nb";
2906 $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
2907 $sql .= " WHERE mc.email = '".$this->db->escape($this->email)."'";
2908 $sql .= " AND mc.statut NOT IN (-1,0)"; // -1 erreur, 0 non envoye, 1 envoye avec succes
2909
2910 $resql = $this->db->query($sql);
2911 if ($resql) {
2912 $obj = $this->db->fetch_object($resql);
2913 $nb = $obj->nb;
2914
2915 $this->db->free($resql);
2916 return $nb;
2917 } else {
2918 $this->error = $this->db->error();
2919 return -1;
2920 }
2921 }
2922
2933 public function setCategories($categories)
2934 {
2935 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
2936 return parent::setCategoriesCommon($categories, Categorie::TYPE_MEMBER);
2937 }
2938
2947 public static function replaceThirdparty($db, $origin_id, $dest_id)
2948 {
2949 $tables = array('adherent');
2950
2951 return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
2952 }
2953
2959 public function hasDelay()
2960 {
2961 global $conf;
2962
2963 //Only valid members
2964 if ($this->statut != self::STATUS_VALIDATED) {
2965 return false;
2966 }
2967 if (!$this->datefin) {
2968 return false;
2969 }
2970
2971 $now = dol_now();
2972
2973 return $this->datefin < ($now - $conf->adherent->subscription->warning_delay);
2974 }
2975
2976
2984 public function sendReminderForExpiredSubscription($daysbeforeendlist = '10')
2985 {
2986 global $conf, $langs, $mysoc, $user;
2987
2988 $error = 0;
2989 $this->output = '';
2990 $this->error = '';
2991
2992 $blockingerrormsg = '';
2993
2994 if (!isModEnabled('adherent')) { // Should not happen. If module disabled, cron job should not be visible.
2995 $langs->load("agenda");
2996 $this->output = $langs->trans('ModuleNotEnabled', $langs->transnoentitiesnoconv("Adherent"));
2997 return 0;
2998 }
2999 if (!getDolGlobalString('MEMBER_REMINDER_EMAIL')) {
3000 $langs->load("agenda");
3001 $this->output = $langs->trans('EventRemindersByEmailNotEnabled', $langs->transnoentitiesnoconv("Adherent"));
3002 return 0;
3003 }
3004
3005 $now = dol_now();
3006 $nbok = 0;
3007 $nbko = 0;
3008
3009 $listofmembersok = array();
3010 $listofmembersko = array();
3011
3012 $arraydaysbeforeend = explode(';', $daysbeforeendlist);
3013 foreach ($arraydaysbeforeend as $daysbeforeend) { // Loop on each delay
3014 dol_syslog(__METHOD__.' - Process delta = '.$daysbeforeend, LOG_DEBUG);
3015
3016 if (!is_numeric($daysbeforeend)) {
3017 $blockingerrormsg = "Value for delta is not a numeric value";
3018 $nbko++;
3019 break;
3020 }
3021
3022 $tmp = dol_getdate($now);
3023 $datetosearchfor = dol_time_plus_duree(dol_mktime(0, 0, 0, $tmp['mon'], $tmp['mday'], $tmp['year'], 'tzserver'), $daysbeforeend, 'd');
3024
3025 $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'adherent';
3026 $sql .= " WHERE entity = ".((int) $conf->entity); // Do not use getEntity('adherent').")" here, we want the batch to be on its entity only;
3027 $sql .= " AND statut = 1";
3028 $sql .= " AND datefin = '".$this->db->idate($datetosearchfor)."'";
3029 //$sql .= " LIMIT 10000";
3030
3031 $resql = $this->db->query($sql);
3032 if ($resql) {
3033 $num_rows = $this->db->num_rows($resql);
3034
3035 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
3036 $adherent = new Adherent($this->db);
3037 $formmail = new FormMail($this->db);
3038
3039 $i = 0;
3040 while ($i < $num_rows) {
3041 $obj = $this->db->fetch_object($resql);
3042
3043 $adherent->fetch($obj->rowid, '', '', '', true, true);
3044
3045 if (empty($adherent->email)) {
3046 $nbko++;
3047 $listofmembersko[$adherent->id] = $adherent->id;
3048 } else {
3049 $adherent->fetch_thirdparty();
3050
3051 // 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.
3052 $languagefromcountrycode = getLanguageCodeFromCountryCode($adherent->country_code ? $adherent->country_code : $adherent->thirdparty->country_code);
3053 $languagecodeformember = (empty($adherent->thirdparty->default_lang) ? ($languagefromcountrycode ? $languagefromcountrycode : $mysoc->default_lang) : $adherent->thirdparty->default_lang);
3054
3055 // Send reminder email
3056 $outputlangs = new Translate('', $conf);
3057 $outputlangs->setDefaultLang($languagecodeformember);
3058 $outputlangs->loadLangs(array("main", "members"));
3059 dol_syslog("sendReminderForExpiredSubscription Language for member id ".$adherent->id." set to ".$outputlangs->defaultlang." mysoc->default_lang=".$mysoc->default_lang);
3060
3061 $arraydefaultmessage = null;
3062 $labeltouse = getDolGlobalString('ADHERENT_EMAIL_TEMPLATE_REMIND_EXPIRATION');
3063
3064 if (!empty($labeltouse)) {
3065 $arraydefaultmessage = $formmail->getEMailTemplate($this->db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
3066 }
3067
3068 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
3069 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $adherent);
3070 //if (is_array($adherent->thirdparty)) $substitutionarraycomp = ...
3071 complete_substitutions_array($substitutionarray, $outputlangs, $adherent);
3072
3073 $subject = make_substitutions($arraydefaultmessage->topic, $substitutionarray, $outputlangs);
3074 $msg = make_substitutions($arraydefaultmessage->content, $substitutionarray, $outputlangs);
3075 $from = getDolGlobalString('ADHERENT_MAIL_FROM');
3076 $to = $adherent->email;
3077 $cc = getDolGlobalString('ADHERENT_CC_MAIL_FROM');
3078
3079 $trackid = 'mem'.$adherent->id;
3080 $moreinheader = 'X-Dolibarr-Info: sendReminderForExpiredSubscription'."\r\n";
3081
3082 include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
3083 $cmail = new CMailFile($subject, $to, $from, $msg, array(), array(), array(), $cc, '', 0, 1, '', '', $trackid, $moreinheader);
3084 $result = $cmail->sendfile();
3085 if (!$result) {
3086 $error++;
3087 $this->error .= $cmail->error.' ';
3088 if (!is_null($cmail->errors)) {
3089 $this->errors += $cmail->errors;
3090 }
3091 $nbko++;
3092 $listofmembersko[$adherent->id] = $adherent->id;
3093 } else {
3094 $nbok++;
3095 $listofmembersok[$adherent->id] = $adherent->id;
3096
3097 $message = $msg;
3098 $sendto = $to;
3099 $sendtocc = '';
3100 $sendtobcc = '';
3101 $actioncode = 'EMAIL';
3102 $extraparams = '';
3103
3104 $actionmsg = '';
3105 $actionmsg2 = $langs->transnoentities('MailSentBy').' '.CMailFile::getValidAddress($from, 4, 0, 1).' '.$langs->transnoentities('To').' '.CMailFile::getValidAddress($sendto, 4, 0, 1);
3106 if ($message) {
3107 $actionmsg = $langs->transnoentities('MailFrom').': '.dol_escape_htmltag($from);
3108 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTo').': '.dol_escape_htmltag($sendto));
3109 if ($sendtocc) {
3110 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc').": ".dol_escape_htmltag($sendtocc));
3111 }
3112 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic').": ".$subject);
3113 $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody').":");
3114 $actionmsg = dol_concatdesc($actionmsg, $message);
3115 }
3116
3117 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
3118
3119 // Insert record of emails sent
3120 $actioncomm = new ActionComm($this->db);
3121
3122 $actioncomm->type_code = 'AC_OTH_AUTO'; // Type of event ('AC_OTH', 'AC_OTH_AUTO', 'AC_XXX'...)
3123 $actioncomm->code = 'AC_'.$actioncode;
3124 $actioncomm->label = $actionmsg2;
3125 $actioncomm->note_private = $actionmsg;
3126 $actioncomm->fk_project = 0;
3127 $actioncomm->datep = $now;
3128 $actioncomm->datef = $now;
3129 $actioncomm->percentage = -1; // Not applicable
3130 $actioncomm->socid = $adherent->thirdparty->id;
3131 $actioncomm->contact_id = 0;
3132 $actioncomm->authorid = $user->id; // User saving action
3133 $actioncomm->userownerid = $user->id; // Owner of action
3134 // Fields when action is en email (content should be added into note)
3135 $actioncomm->email_msgid = $cmail->msgid;
3136 $actioncomm->email_from = $from;
3137 $actioncomm->email_sender = '';
3138 $actioncomm->email_to = $to;
3139 $actioncomm->email_tocc = $sendtocc;
3140 $actioncomm->email_tobcc = $sendtobcc;
3141 $actioncomm->email_subject = $subject;
3142 $actioncomm->errors_to = '';
3143
3144 $actioncomm->fk_element = $adherent->id;
3145 $actioncomm->elementtype = $adherent->element;
3146
3147 $actioncomm->extraparams = $extraparams;
3148
3149 $actioncomm->create($user);
3150 }
3151 } else {
3152 //$blockingerrormsg = "Can't find email template with label=".$labeltouse.", to use for the reminding email";
3153
3154 $error++;
3155 $this->error .= "Can't find email template with label=".$labeltouse.", to use for the reminding email ";
3156
3157 $nbko++;
3158 $listofmembersko[$adherent->id] = $adherent->id;
3159
3160 break;
3161 }
3162 }
3163
3164 $i++;
3165 }
3166 } else {
3167 $this->error = $this->db->lasterror();
3168 return 1;
3169 }
3170 }
3171
3172 if ($blockingerrormsg) {
3173 $this->error = $blockingerrormsg;
3174 return 1;
3175 } else {
3176 $this->output = 'Found '.($nbok + $nbko).' members to send reminder to.';
3177 $this->output .= ' Send email successfuly to '.$nbok.' members';
3178 if (is_array($listofmembersok)) {
3179 $listofids = '';
3180 $i = 0;
3181 foreach ($listofmembersok as $idmember) {
3182 if ($i > 100) {
3183 $listofids .= ', ...';
3184 break;
3185 }
3186 if (empty($listofids)) {
3187 $listofids .= ' [';
3188 } else {
3189 $listofids .= ', ';
3190 }
3191 $listofids .= $idmember;
3192 $i++;
3193 }
3194 if ($listofids) {
3195 $listofids .= ']';
3196 }
3197
3198 $this->output .= ($listofids ? ' ids='.$listofids : '');
3199 }
3200 if ($nbko) {
3201 $this->output .= ' - Canceled for '.$nbko.' member (no email or email sending error)';
3202 if (is_array($listofmembersko)) {
3203 $listofids = '';
3204 $i = 0;
3205 foreach ($listofmembersko as $idmember) {
3206 if ($i > 100) {
3207 $listofids .= ', ...';
3208 break;
3209 }
3210 if (empty($listofids)) {
3211 $listofids .= ' [';
3212 } else {
3213 $listofids .= ', ';
3214 }
3215 $listofids .= $idmember;
3216 $i++;
3217 }
3218 if ($listofids) {
3219 $listofids .= ']';
3220 }
3221 $this->output .= ($listofids ? ' ids='.$listofids : '');
3222 }
3223 }
3224 }
3225
3226 return $nbko;
3227 }
3228
3236 public function getKanbanView($option = '', $arraydata = null)
3237 {
3238 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
3239
3240 $return = '<div class="box-flex-item box-flex-grow-zero">';
3241 $return .= '<div class="info-box info-box-sm">';
3242 $return .= '<span class="info-box-icon bg-infobox-action">';
3243 if (property_exists($this, 'photo') || !empty($this->photo)) {
3244 $return.= Form::showphoto('memberphoto', $this, 0, 60, 0, 'photokanban photoref photowithmargin photologintooltip', 'small', 0, 1);
3245 } else {
3246 $return .= img_picto('', 'user');
3247 }
3248 $return .= '</span>';
3249 $return .= '<div class="info-box-content">';
3250 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
3251 if ($selected >= 0) {
3252 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
3253 }
3254 if (property_exists($this, 'type')) {
3255 $return .= '<br><span class="info-box-label opacitymedium">'.$this->type.'</span>';
3256 }
3257 if (method_exists($this, 'getmorphylib')) {
3258 $return .= '<br><span class="info-box-label">'.$this->getmorphylib('', 2).'</span>';
3259 }
3260 if (method_exists($this, 'getLibStatut')) {
3261 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
3262 }
3263 $return .= '</div>';
3264 $return .= '</div>';
3265 $return .= '</div>';
3266 return $return;
3267 }
3268}
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Definition security.php:604
$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 exlude (set adherent.status to -2) a member TODO A private note should be added to know w...
add_to_abo()
Function to add member into external tools mailing-list, spip, etc.
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 clicable 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 attributs 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 clicable 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.
load_state_board()
Charge indicateurs this->nb de tableau de bord.
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)
Classe permettant la generation du formulaire html d'envoi de mail unitaire Usage: $formail = new For...
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.
trait CommonPeople
Superclass for thirdparties, contacts, members or users.
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
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 informations (by default a local PHP server timestamp) Re...
getLanguageCodeFromCountryCode($countrycode)
Return default language from country code.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_format_address($object, $withcountry=0, $sep="\n", $outputlangs='', $mode=0, $extralangcode='')
Return a formated address (part address/zip/town/state) according to country rules.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
dolGetFirstLetters($s, $nbofchar=1)
Return first letters of a strings.
dol_strtoupper($string, $encoding="UTF-8")
Convert a string to upper.
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
getArrayOfSocialNetworks()
Get array of social network dictionary.
dol_textishtml($msg, $option=0)
Return if a text is a html content.
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_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.
getDolGlobalString($key, $default='')
Return 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...
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e e e e e statut
Definition invoice.php:1907
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:121
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.