36 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
37 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
38 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
50 public $element =
'member';
55 public $table_element =
'adherent';
61 public $ismultientitymanaged = 1;
66 public $picto =
'member';
84 public $pass_indatabase;
89 public $pass_indatabase_crypted;
146 public $socialnetworks;
190 public $phone_mobile;
251 public $need_subscription;
262 public $first_subscription_date;
264 public $first_subscription_amount;
266 public $last_subscription_date;
268 public $last_subscription_date_start;
270 public $last_subscription_date_end;
272 public $last_subscription_amount;
274 public $subscriptions = array();
289 public $fields = array(
290 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 10),
291 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' => 1,
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 15,
'index' => 1),
292 'ref_ext' => array(
'type' =>
'varchar(128)',
'label' =>
'Ref ext',
'enabled' => 1,
'visible' => 0,
'position' => 20),
293 'civility' => array(
'type' =>
'varchar(6)',
'label' =>
'Civility',
'enabled' => 1,
'visible' => -1,
'position' => 25),
294 'lastname' => array(
'type' =>
'varchar(50)',
'label' =>
'Lastname',
'enabled' => 1,
'visible' => -1,
'position' => 30),
295 'firstname' => array(
'type' =>
'varchar(50)',
'label' =>
'Firstname',
'enabled' => 1,
'visible' => -1,
'position' => 35),
296 'login' => array(
'type' =>
'varchar(50)',
'label' =>
'Login',
'enabled' => 1,
'visible' => -1,
'position' => 40),
297 'gender' => array(
'type' =>
'varchar(10)',
'label' =>
'Gender',
'enabled' => 1,
'visible' => -1,
'position' => 250),
298 'pass' => array(
'type' =>
'varchar(50)',
'label' =>
'Pass',
'enabled' => 1,
'visible' => -1,
'position' => 45),
299 'pass_crypted' => array(
'type' =>
'varchar(128)',
'label' =>
'Pass crypted',
'enabled' => 1,
'visible' => -1,
'position' => 50),
300 'fk_adherent_type' => array(
'type' =>
'integer',
'label' =>
'Fk adherent type',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 55),
301 'morphy' => array(
'type' =>
'varchar(3)',
'label' =>
'MorPhy',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 60),
302 'societe' => array(
'type' =>
'varchar(128)',
'label' =>
'Societe',
'enabled' => 1,
'visible' => -1,
'position' => 65),
303 'fk_soc' => array(
'type' =>
'integer:Societe:societe/class/societe.class.php',
'label' =>
'ThirdParty',
'enabled' => 1,
'visible' => -1,
'position' => 70),
304 'address' => array(
'type' =>
'text',
'label' =>
'Address',
'enabled' => 1,
'visible' => -1,
'position' => 75),
305 'zip' => array(
'type' =>
'varchar(10)',
'label' =>
'Zip',
'enabled' => 1,
'visible' => -1,
'position' => 80),
306 'town' => array(
'type' =>
'varchar(50)',
'label' =>
'Town',
'enabled' => 1,
'visible' => -1,
'position' => 85),
307 'state_id' => array(
'type' =>
'integer',
'label' =>
'State id',
'enabled' => 1,
'visible' => -1,
'position' => 90),
308 'country' => array(
'type' =>
'integer:Ccountry:core/class/ccountry.class.php',
'label' =>
'Country',
'enabled' => 1,
'visible' => -1,
'position' => 95),
309 'email' => array(
'type' =>
'varchar(255)',
'label' =>
'Email',
'enabled' => 1,
'visible' => -1,
'position' => 100),
310 'socialnetworks' => array(
'type' =>
'text',
'label' =>
'Socialnetworks',
'enabled' => 1,
'visible' => -1,
'position' => 105),
311 'phone' => array(
'type' =>
'varchar(30)',
'label' =>
'Phone',
'enabled' => 1,
'visible' => -1,
'position' => 115),
312 'phone_perso' => array(
'type' =>
'varchar(30)',
'label' =>
'Phone perso',
'enabled' => 1,
'visible' => -1,
'position' => 120),
313 'phone_mobile' => array(
'type' =>
'varchar(30)',
'label' =>
'Phone mobile',
'enabled' => 1,
'visible' => -1,
'position' => 125),
314 'birth' => array(
'type' =>
'date',
'label' =>
'DateOfBirth',
'enabled' => 1,
'visible' => -1,
'position' => 130),
315 'photo' => array(
'type' =>
'varchar(255)',
'label' =>
'Photo',
'enabled' => 1,
'visible' => -1,
'position' => 135),
316 'public' => array(
'type' =>
'smallint(6)',
'label' =>
'Public',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 145),
317 'datefin' => array(
'type' =>
'datetime',
'label' =>
'DateEnd',
'enabled' => 1,
'visible' => -1,
'position' => 150),
318 'note_private' => array(
'type' =>
'text',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 0,
'position' => 155),
319 'note_public' => array(
'type' =>
'text',
'label' =>
'NotePrivate',
'enabled' => 1,
'visible' => 0,
'position' => 160),
320 'datevalid' => array(
'type' =>
'datetime',
'label' =>
'DateValidation',
'enabled' => 1,
'visible' => -1,
'position' => 165),
321 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -1,
'position' => 170),
322 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 175),
323 'fk_user_author' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'Fk user author',
'enabled' => 1,
'visible' => -1,
'position' => 180),
324 'fk_user_mod' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'Fk user mod',
'enabled' => 1,
'visible' => -1,
'position' => 185),
325 'fk_user_valid' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserValidation',
'enabled' => 1,
'visible' => -1,
'position' => 190),
326 'canvas' => array(
'type' =>
'varchar(32)',
'label' =>
'Canvas',
'enabled' => 1,
'visible' => -1,
'position' => 195),
327 'statut' => array(
'type' =>
'smallint(6)',
'label' =>
'Statut',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 500,
328 'arrayofkeyval' => array(0 =>
'Draft', 1 =>
'Validated', -1 =>
'MemberStatusResiliatedShort')),
329 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'Model pdf',
'enabled' => 1,
'visible' => 0,
'position' => 800),
330 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -2,
'position' => 805)
346 $this->array_options = array();
367 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 =
'')
370 global $conf, $langs;
373 if ($msgishtml == -1) {
378 dol_syslog(
'send_an_email msgishtml='.$msgishtml);
385 $from = $conf->email_from;
386 if (!empty($conf->global->ADHERENT_MAIL_FROM)) $from = $conf->global->ADHERENT_MAIL_FROM;
388 $trackid =
'mem'.$this->id;
391 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
392 $mailfile =
new CMailFile($subjecttosend, $this->email, $from, $texttosend, $filename_list, $mimetype_list, $mimefilename_list, $addr_cc, $addr_bcc, $deliveryreceipt, $msgishtml,
'',
'', $trackid, $moreinheader);
393 if ($mailfile->sendfile()) {
396 $this->error = $langs->trans(
"ErrorFailedToSendMail", $from, $this->email).
'. '.$mailfile->error;
410 global $conf, $langs;
418 if ($this->civility_id) $infos .= $langs->transnoentities(
"UserTitle").
": ".$this->
getCivilityLabel().
"\n";
419 $infos .= $langs->transnoentities(
"id").
": ".$this->
id.
"\n";
420 $infos .= $langs->transnoentities(
"Lastname").
": ".$this->lastname.
"\n";
421 $infos .= $langs->transnoentities(
"Firstname").
": ".$this->firstname.
"\n";
422 $infos .= $langs->transnoentities(
"Company").
": ".$this->company.
"\n";
423 $infos .= $langs->transnoentities(
"Address").
": ".$this->address.
"\n";
424 $infos .= $langs->transnoentities(
"Zip").
": ".$this->zip.
"\n";
425 $infos .= $langs->transnoentities(
"Town").
": ".$this->town.
"\n";
426 $infos .= $langs->transnoentities(
"Country").
": ".$this->country.
"\n";
427 $infos .= $langs->transnoentities(
"EMail").
": ".$this->email.
"\n";
428 $infos .= $langs->transnoentities(
"PhonePro").
": ".$this->phone.
"\n";
429 $infos .= $langs->transnoentities(
"PhonePerso").
": ".$this->phone_perso.
"\n";
430 $infos .= $langs->transnoentities(
"PhoneMobile").
": ".$this->phone_mobile.
"\n";
431 if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
432 $infos .= $langs->transnoentities(
"Login").
": ".$this->login.
"\n";
433 $infos .= $langs->transnoentities(
"Password").
": ".$this->pass.
"\n";
435 $infos .= $langs->transnoentities(
"Birthday").
": ".$birthday.
"\n";
436 $infos .= $langs->transnoentities(
"Photo").
": ".$this->photo.
"\n";
437 $infos .= $langs->transnoentities(
"Public").
": ".
yn($this->
public);
440 $substitutionarray = array(
441 '__ID__' => $this->
id,
'__MEMBER_ID__' => $this->
id,
'__CIVILITY__' => $this->
getCivilityLabel(),
442 '__FIRSTNAME__' => $msgishtml ?
dol_htmlentitiesbr($this->firstname) : ($this->firstname ? $this->firstname :
''),
443 '__LASTNAME__' => $msgishtml ?
dol_htmlentitiesbr($this->lastname) : ($this->lastname ? $this->lastname :
''),
445 '__COMPANY__' => $msgishtml ?
dol_htmlentitiesbr($this->company) : ($this->company ? $this->company :
''),
446 '__ADDRESS__' => $msgishtml ?
dol_htmlentitiesbr($this->address) : ($this->address ? $this->address :
''),
447 '__ZIP__' => $msgishtml ?
dol_htmlentitiesbr($this->zip) : ($this->zip ? $this->zip :
''),
'__TOWN__' => $msgishtml ?
dol_htmlentitiesbr($this->town) : ($this->town ? $this->town :
''),
448 '__COUNTRY__' => $msgishtml ?
dol_htmlentitiesbr($this->country) : ($this->country ? $this->country :
''),
449 '__EMAIL__' => $msgishtml ?
dol_htmlentitiesbr($this->email) : ($this->email ? $this->email :
''),
'__BIRTH__' => $msgishtml ?
dol_htmlentitiesbr($birthday) : ($birthday ? $birthday :
''),
450 '__PHOTO__' => $msgishtml ?
dol_htmlentitiesbr($this->photo) : ($this->photo ? $this->photo :
''),
451 '__LOGIN__' => $msgishtml ?
dol_htmlentitiesbr($this->login) : ($this->login ? $this->login :
''),
452 '__PASSWORD__' => $msgishtml ?
dol_htmlentitiesbr($this->pass) : ($this->pass ? $this->pass :
''),
453 '__PHONE__' => $msgishtml ?
dol_htmlentitiesbr($this->phone) : ($this->phone ? $this->phone :
''),
454 '__PHONEPRO__' => $msgishtml ?
dol_htmlentitiesbr($this->phone_perso) : ($this->phone_perso ? $this->phone_perso :
''),
455 '__PHONEMOBILE__' => $msgishtml ?
dol_htmlentitiesbr($this->phone_mobile) : ($this->phone_mobile ? $this->phone_mobile :
''),
475 $morphy = $this->morphy;
477 if ($morphy ==
'phy') {
478 return $langs->trans(
"Physical");
480 if ($morphy ==
'mor') {
481 return $langs->trans(
"Moral");
493 public function create($user, $notrigger = 0)
495 global $conf, $langs;
502 $this->import_key = trim($this->import_key);
505 if (!empty($conf->global->ADHERENT_MAIL_REQUIRED) && !isValidEMail($this->email)) {
506 $langs->load(
"errors");
507 $this->error = $langs->trans(
"ErrorBadEMail", $this->email);
510 if (!$this->datec) $this->datec = $now;
511 if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
512 if (empty($this->login)) {
513 $this->error = $langs->trans(
"ErrorWrongValueForParameterX",
"Login");
521 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"adherent";
522 $sql .=
" (datec,login,fk_user_author,fk_user_mod,fk_user_valid,morphy,fk_adherent_type,entity,import_key)";
524 $sql .=
" '".$this->db->idate($this->datec).
"'";
525 $sql .=
", ".($this->login ?
"'".$this->db->escape($this->login).
"'" :
"null");
526 $sql .=
", ".($user->id > 0 ? $user->id :
"null");
527 $sql .=
", null, null, '".$this->db->escape($this->morphy).
"'";
528 $sql .=
", ".$this->typeid;
529 $sql .=
", ".$conf->entity;
530 $sql .=
", ".(!empty($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
533 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
534 $result = $this->
db->query($sql);
536 $id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"adherent");
539 $this->ref = (string) $id;
542 $result = $this->
update($user, 1, 1, 0, 0,
'add');
544 $this->
db->rollback();
549 if ($this->user_id) {
551 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"user SET";
552 $sql .=
" fk_member = ".$this->id;
553 $sql .=
" WHERE rowid = ".$this->user_id;
554 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
557 $this->error =
'Failed to update user to make link with member';
558 $this->
db->rollback();
572 if (count($this->errors)) {
573 dol_syslog(get_class($this).
"::create ".implode(
',', $this->errors), LOG_ERR);
574 $this->
db->rollback();
581 $this->error =
'Failed to get last insert id';
582 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
583 $this->
db->rollback();
587 $this->error = $this->
db->error();
588 $this->
db->rollback();
605 public function update($user, $notrigger = 0, $nosyncuser = 0, $nosyncuserpass = 0, $nosyncthirdparty = 0, $action =
'update')
607 global $conf, $langs, $hookmanager;
612 dol_syslog(get_class($this).
"::update notrigger=".$notrigger.
", nosyncuser=".$nosyncuser.
", nosyncuserpass=".$nosyncuserpass.
" nosyncthirdparty=".$nosyncthirdparty.
", email=".
616 $this->lastname = trim($this->lastname) ? trim($this->lastname) : trim($this->lastname);
617 $this->firstname = trim($this->firstname) ? trim($this->firstname) : trim($this->firstname);
618 $this->gender = trim($this->gender);
619 $this->address = ($this->address ? $this->address : $this->address);
620 $this->zip = ($this->zip ? $this->zip : $this->zip);
621 $this->town = ($this->town ? $this->town : $this->town);
622 $this->country_id = ($this->country_id > 0 ? $this->country_id : $this->country_id);
623 $this->state_id = ($this->state_id > 0 ? $this->state_id : $this->state_id);
625 $this->note_public = ($this->note_public ? $this->note_public : $this->note_public);
626 $this->note_private = ($this->note_private ? $this->note_private : $this->note_private);
629 if (!empty($conf->global->ADHERENT_MAIL_REQUIRED) && !isValidEMail($this->email)) {
630 $langs->load(
"errors");
631 $this->error = $langs->trans(
"ErrorBadEMail", $this->email);
637 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"adherent SET";
638 $sql .=
" civility = ".($this->civility_id ?
"'".$this->db->escape($this->civility_id).
"'" :
"null");
639 $sql .=
", firstname = ".($this->firstname ?
"'".$this->db->escape($this->firstname).
"'" :
"null");
640 $sql .=
", lastname = ".($this->lastname ?
"'".$this->db->escape($this->lastname).
"'" :
"null");
641 $sql .=
", gender = ".($this->gender != -1 ?
"'".$this->db->escape($this->gender).
"'" :
"null");
642 $sql .=
", login = ".($this->login ?
"'".$this->db->escape($this->login).
"'" :
"null");
643 $sql .=
", societe = ".($this->company ?
"'".$this->db->escape($this->company).
"'" : ($this->societe ?
"'".$this->db->escape($this->societe).
"'" :
"null"));
644 $sql .=
", fk_soc = ".($this->socid > 0 ? $this->
db->escape($this->socid) :
"null");
645 $sql .=
", address = ".($this->address ?
"'".$this->db->escape($this->address).
"'" :
"null");
646 $sql .=
", zip = ".($this->zip ?
"'".$this->db->escape($this->zip).
"'" :
"null");
647 $sql .=
", town = ".($this->town ?
"'".$this->db->escape($this->town).
"'" :
"null");
648 $sql .=
", country = ".($this->country_id > 0 ? $this->
db->escape($this->country_id) :
"null");
649 $sql .=
", state_id = ".($this->state_id > 0 ? $this->
db->escape($this->state_id) :
"null");
650 $sql .=
", email = '".$this->db->escape($this->email).
"'";
651 $sql .=
", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
652 $sql .=
", phone = ".($this->phone ?
"'".$this->db->escape($this->phone).
"'" :
"null");
653 $sql .=
", phone_perso = ".($this->phone_perso ?
"'".$this->db->escape($this->phone_perso).
"'" :
"null");
654 $sql .=
", phone_mobile = ".($this->phone_mobile ?
"'".$this->db->escape($this->phone_mobile).
"'" :
"null");
655 $sql .=
", note_private = ".($this->note_private ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
656 $sql .=
", note_public = ".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
657 $sql .=
", photo = ".($this->photo ?
"'".$this->db->escape($this->photo).
"'" :
"null");
658 $sql .=
", public = '".$this->db->escape($this->
public).
"'";
659 $sql .=
", statut = ".$this->db->escape($this->
statut);
660 $sql .=
", fk_adherent_type = ".$this->db->escape($this->
typeid);
661 $sql .=
", morphy = '".$this->db->escape($this->morphy).
"'";
662 $sql .=
", birth = ".($this->birth ?
"'".$this->db->idate($this->birth).
"'" :
"null");
663 if ($this->socid) $sql .=
", fk_soc = '".$this->db->escape($this->socid).
"'";
664 if ($this->datefin) $sql .=
", datefin = '".$this->db->idate($this->datefin).
"'";
665 if ($this->datevalid) $sql .=
", datevalid = '".$this->db->idate($this->datevalid).
"'";
666 $sql .=
", fk_user_mod = ".($user->id > 0 ? $user->id :
'null');
667 $sql .=
" WHERE rowid = ".$this->id;
670 if (!empty($this->oldcopy) && $this->
typeid != $this->oldcopy->typeid) {
671 $sql2 =
"SELECT libelle as label";
672 $sql2 .=
" FROM ".MAIN_DB_PREFIX.
"adherent_type";
673 $sql2 .=
" WHERE rowid = ".$this->typeid;
674 $resql2 = $this->
db->query($sql2);
676 while ($obj = $this->
db->fetch_object($resql2)) {
677 $this->
type = $obj->label;
682 dol_syslog(get_class($this).
"::update update member", LOG_DEBUG);
685 unset($this->country_code);
686 unset($this->country);
687 unset($this->state_code);
690 $nbrowsaffected += $this->
db->affected_rows(
$resql);
703 if (!$error && $this->pass) {
704 dol_syslog(get_class($this).
"::update update password");
705 if ($this->pass != $this->pass_indatabase && $this->pass != $this->pass_indatabase_crypted) {
706 $isencrypted = empty($conf->global->DATABASE_PWD_ENCRYPTED) ? 0 : 1;
709 $result = $this->
setPassword($user, $this->pass, $isencrypted, $notrigger, $nosyncuserpass);
710 if (!$nbrowsaffected) $nbrowsaffected++;
716 dol_syslog(get_class($this).
"::update update link to user");
717 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"user SET fk_member = NULL WHERE fk_member = ".$this->id;
718 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
721 $this->error = $this->
db->error();
722 $this->
db->rollback();
726 if ($this->user_id > 0) {
727 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"user SET fk_member = ".$this->
id.
" WHERE rowid = ".$this->user_id;
728 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
731 $this->error = $this->
db->error();
732 $this->
db->rollback();
738 if (!$error && $nbrowsaffected) {
740 if (!$error && $this->user_id > 0 && !$nosyncuser) {
741 require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
743 dol_syslog(get_class($this).
"::update update linked user");
745 $luser =
new User($this->
db);
746 $result = $luser->fetch($this->user_id);
753 if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) $luser->login = $this->login;
755 $luser->civility_id = $this->civility_id;
756 $luser->firstname = $this->firstname;
757 $luser->lastname = $this->lastname;
758 $luser->gender = $this->gender;
759 $luser->pass = $this->pass;
762 $luser->birth = $this->birth;
764 $luser->address = $this->address;
765 $luser->zip = $this->zip;
766 $luser->town = $this->town;
767 $luser->country_id = $this->country_id;
768 $luser->state_id = $this->state_id;
770 $luser->email = $this->email;
771 $luser->socialnetworks = $this->socialnetworks;
772 $luser->office_phone = $this->phone;
773 $luser->user_mobile = $this->phone_mobile;
775 $luser->fk_member = $this->id;
777 $result = $luser->update($user, 0, 1, 1);
779 $this->error = $luser->error;
780 dol_syslog(get_class($this).
"::update ".$this->error, LOG_ERR);
784 $this->error = $luser->error;
790 if (!$error && $this->fk_soc > 0 && !$nosyncthirdparty) {
791 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
793 dol_syslog(get_class($this).
"::update update linked thirdparty");
798 $result = $lthirdparty->fetch($this->fk_soc);
801 $lthirdparty->address = $this->address;
802 $lthirdparty->zip = $this->zip;
803 $lthirdparty->town = $this->town;
804 $lthirdparty->email = $this->email;
805 $lthirdparty->socialnetworks = $this->socialnetworks;
806 $lthirdparty->phone = $this->phone;
807 $lthirdparty->state_id = $this->state_id;
808 $lthirdparty->country_id = $this->country_id;
811 $result = $lthirdparty->update($this->fk_soc, $user, 0, 1, 1,
'update');
814 $this->error = $lthirdparty->error;
815 $this->errors = $lthirdparty->errors;
816 dol_syslog(get_class($this).
"::update ".$this->error, LOG_ERR);
819 } elseif ($result < 0) {
820 $this->error = $lthirdparty->error;
826 if (!$error && !$notrigger) {
837 return $nbrowsaffected;
839 $this->
db->rollback();
843 $this->
db->rollback();
844 $this->error = $this->
db->lasterror();
864 $sql =
"SELECT rowid, datec as dateop, dateadh as datedeb, datef as datefin";
865 $sql .=
" FROM ".MAIN_DB_PREFIX.
"subscription";
866 $sql .=
" WHERE fk_adherent=".$this->id;
867 $sql .=
" ORDER by dateadh DESC";
869 dol_syslog(get_class($this).
"::update_end_date", LOG_DEBUG);
872 $obj = $this->
db->fetch_object(
$resql);
873 $dateop = $this->
db->jdate($obj->dateop);
874 $datedeb = $this->
db->jdate($obj->datedeb);
875 $datefin = $this->
db->jdate($obj->datefin);
877 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"adherent SET";
878 $sql .=
" datefin=".($datefin !=
'' ?
"'".$this->db->idate($datefin).
"'" :
"null");
879 $sql .=
" WHERE rowid = ".$this->id;
881 dol_syslog(get_class($this).
"::update_end_date", LOG_DEBUG);
884 $this->last_subscription_date = $dateop;
885 $this->last_subscription_date_start = $datedeb;
886 $this->last_subscription_date_end = $datefin;
887 $this->datefin = $datefin;
891 $this->
db->rollback();
895 $this->error = $this->
db->lasterror();
896 $this->
db->rollback();
909 public function delete($rowid, $user, $notrigger = 0)
911 global $conf, $langs;
918 if (empty($rowid)) $rowid = $this->
id;
922 if (!$error && !$notrigger) {
925 if ($result < 0) $error++;
930 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_member WHERE fk_member = ".$rowid;
931 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
935 $this->error .= $this->
db->lasterror();
941 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"subscription WHERE fk_adherent = ".$rowid;
942 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
946 $this->error .= $this->
db->lasterror();
956 $this->error .= $this->
db->lasterror();
967 dol_syslog(get_class($this).
"::delete erreur ".$errorflag.
" ".$this->error, LOG_ERR);
973 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"adherent WHERE rowid = ".$rowid;
974 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
978 $this->error .= $this->
db->lasterror();
987 $this->
db->rollback();
1003 public function setPassword($user, $password =
'', $isencrypted = 0, $notrigger = 0, $nosyncuser = 0)
1005 global $conf, $langs;
1009 dol_syslog(get_class($this).
"::setPassword user=".$user->id.
" password=".preg_replace(
'/./i',
'*', $password).
" isencrypted=".$isencrypted);
1013 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
1018 $password_crypted =
dol_hash($password);
1020 $password_indatabase =
'';
1021 if (!$isencrypted) {
1022 $password_indatabase = $password;
1028 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"adherent";
1029 $sql .=
" SET pass_crypted = '".$this->db->escape($password_crypted).
"'";
1032 $sql .=
", pass = null";
1034 $sql .=
", pass = '".$this->db->escape($password_indatabase).
"'";
1036 $sql .=
" WHERE rowid = ".$this->id;
1039 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
1040 $result = $this->
db->query($sql);
1042 $nbaffectedrows = $this->
db->affected_rows($result);
1044 if ($nbaffectedrows) {
1045 $this->pass = $password;
1046 $this->pass_indatabase = $password_indatabase;
1047 $this->pass_indatabase_crypted = $password_crypted;
1049 if ($this->user_id && !$nosyncuser) {
1050 require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
1054 $luser =
new User($this->
db);
1055 $result = $luser->fetch($this->user_id);
1058 $result = $luser->setPassword($user, $this->pass, 0, 0, 1);
1060 $this->error = $luser->error;
1061 dol_syslog(get_class($this).
"::setPassword ".$this->error, LOG_ERR);
1065 $this->error = $luser->error;
1070 if (!$error && !$notrigger) {
1072 $result = $this->
call_trigger(
'MEMBER_NEW_PASSWORD', $user);
1075 $this->
db->rollback();
1081 $this->
db->commit();
1084 $this->
db->rollback();
1088 $this->
db->rollback();
1103 global $conf, $langs;
1108 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"user SET fk_member = NULL WHERE fk_member = ".$this->id;
1109 dol_syslog(get_class($this).
"::setUserId", LOG_DEBUG);
1112 $this->error = $this->
db->error();
1113 $this->
db->rollback();
1119 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"user SET fk_member = ".$this->id;
1120 $sql .=
" WHERE rowid = ".$userid;
1121 dol_syslog(get_class($this).
"::setUserId", LOG_DEBUG);
1124 $this->error = $this->
db->error();
1125 $this->
db->rollback();
1130 $this->
db->commit();
1144 global $conf, $langs;
1149 if ($thirdpartyid > 0) {
1150 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"adherent SET fk_soc = null";
1151 $sql .=
" WHERE fk_soc = ".((int) $thirdpartyid);
1152 $sql .=
" AND entity = ".$conf->entity;
1153 dol_syslog(get_class($this).
"::setThirdPartyId", LOG_DEBUG);
1158 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"adherent SET fk_soc = ".($thirdpartyid > 0 ? $thirdpartyid :
'null');
1159 $sql .=
" WHERE rowid = ".$this->id;
1161 dol_syslog(get_class($this).
"::setThirdPartyId", LOG_DEBUG);
1164 $this->
db->commit();
1167 $this->error = $this->
db->error();
1168 $this->
db->rollback();
1186 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"adherent";
1187 $sql .=
" WHERE login='".$this->db->escape($login).
"'";
1188 $sql .=
" AND entity = ".$conf->entity;
1193 $obj = $this->
db->fetch_object(
$resql);
1194 $this->
fetch($obj->rowid);
1214 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"adherent";
1215 $sql .=
" WHERE firstname='".$this->db->escape($firstname).
"'";
1216 $sql .=
" AND lastname='".$this->db->escape($lastname).
"'";
1217 $sql .=
" AND entity = ".$conf->entity;
1222 $obj = $this->
db->fetch_object(
$resql);
1223 $this->
fetch($obj->rowid);
1241 public function fetch($rowid, $ref =
'', $fk_soc =
'', $ref_ext =
'', $fetch_optionals =
true, $fetch_subscriptions =
true)
1245 $sql =
"SELECT d.rowid, d.ref_ext, d.civility as civility_code, d.gender, d.firstname, d.lastname, d.societe as company, d.fk_soc, d.statut, d.public, d.address, d.zip, d.town, d.note_private,";
1246 $sql .=
" d.note_public,";
1247 $sql .=
" d.email, d.socialnetworks, d.phone, d.phone_perso, d.phone_mobile, d.login, d.pass, d.pass_crypted,";
1248 $sql .=
" d.photo, d.fk_adherent_type, d.morphy, d.entity,";
1249 $sql .=
" d.datec as datec,";
1250 $sql .=
" d.tms as datem,";
1251 $sql .=
" d.datefin as datefin,";
1252 $sql .=
" d.birth as birthday,";
1253 $sql .=
" d.datevalid as datev,";
1254 $sql .=
" d.country,";
1255 $sql .=
" d.state_id,";
1256 $sql .=
" d.model_pdf,";
1257 $sql .=
" c.rowid as country_id, c.code as country_code, c.label as country,";
1258 $sql .=
" dep.nom as state, dep.code_departement as state_code,";
1259 $sql .=
" t.libelle as type, t.subscription as subscription,";
1260 $sql .=
" u.rowid as user_id, u.login as user_login";
1261 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent_type as t, ".MAIN_DB_PREFIX.
"adherent as d";
1262 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as c ON d.country = c.rowid";
1263 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_departements as dep ON d.state_id = dep.rowid";
1264 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u ON d.rowid = u.fk_member";
1265 $sql .=
" WHERE d.fk_adherent_type = t.rowid";
1267 $sql .=
" AND d.rowid=".((int) $rowid);
1268 } elseif ($ref || $fk_soc) {
1269 $sql .=
" AND d.entity IN (".getEntity(
'adherent').
")";
1271 $sql .=
" AND d.rowid='".$this->db->escape($ref).
"'";
1272 } elseif ($fk_soc > 0) {
1273 $sql .=
" AND d.fk_soc=".((int) $fk_soc);
1275 } elseif ($ref_ext) {
1276 $sql .=
" AND d.ref_ext='".$this->db->escape($ref_ext).
"'";
1279 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
1283 $obj = $this->
db->fetch_object(
$resql);
1285 $this->entity = $obj->entity;
1286 $this->ref = $obj->rowid;
1287 $this->
id = $obj->rowid;
1288 $this->ref_ext = $obj->ref_ext;
1290 $this->civility_id = $obj->civility_code;
1291 $this->civility_code = $obj->civility_code;
1292 $this->civility = $obj->civility_code ? ($langs->trans(
"Civility".$obj->civility_code) != (
"Civility".$obj->civility_code) ? $langs->trans(
"Civility".$obj->civility_code) : $obj->civility_code) :
'';
1294 $this->firstname = $obj->firstname;
1295 $this->lastname = $obj->lastname;
1296 $this->gender = $obj->gender;
1297 $this->login = $obj->login;
1298 $this->societe = $obj->company;
1299 $this->company = $obj->company;
1300 $this->socid = $obj->fk_soc;
1301 $this->fk_soc = $obj->fk_soc;
1302 $this->address = $obj->address;
1303 $this->zip = $obj->zip;
1304 $this->town = $obj->town;
1306 $this->pass = $obj->pass;
1307 $this->pass_indatabase = $obj->pass;
1308 $this->pass_indatabase_crypted = $obj->pass_crypted;
1310 $this->state_id = $obj->state_id;
1311 $this->state_code = $obj->state_id ? $obj->state_code :
'';
1312 $this->state = $obj->state_id ? $obj->state :
'';
1314 $this->country_id = $obj->country_id;
1315 $this->country_code = $obj->country_code;
1316 if ($langs->trans(
"Country".$obj->country_code) !=
"Country".$obj->country_code) {
1317 $this->country = $langs->transnoentitiesnoconv(
"Country".$obj->country_code);
1319 $this->country = $obj->country;
1322 $this->phone = $obj->phone;
1323 $this->phone_perso = $obj->phone_perso;
1324 $this->phone_mobile = $obj->phone_mobile;
1325 $this->email = $obj->email;
1327 $this->socialnetworks = (array) json_decode($obj->socialnetworks,
true);
1329 $this->photo = $obj->photo;
1330 $this->
statut = $obj->statut;
1331 $this->
public = $obj->public;
1333 $this->datec = $this->
db->jdate($obj->datec);
1334 $this->date_creation = $this->
db->jdate($obj->datec);
1335 $this->datem = $this->
db->jdate($obj->datem);
1336 $this->date_modification = $this->
db->jdate($obj->datem);
1337 $this->datefin = $this->
db->jdate($obj->datefin);
1338 $this->datevalid = $this->
db->jdate($obj->datev);
1339 $this->date_validation = $this->
db->jdate($obj->datev);
1340 $this->birth = $this->
db->jdate($obj->birthday);
1342 $this->note_private = $obj->note_private;
1343 $this->note_public = $obj->note_public;
1344 $this->morphy = $obj->morphy;
1346 $this->
typeid = $obj->fk_adherent_type;
1347 $this->
type = $obj->type;
1348 $this->need_subscription = $obj->subscription;
1350 $this->user_id = $obj->user_id;
1351 $this->user_login = $obj->user_login;
1353 $this->model_pdf = $obj->model_pdf;
1357 if ($fetch_optionals) {
1362 if ($fetch_subscriptions) {
1371 $this->error = $this->
db->lasterror();
1390 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/subscription.class.php';
1392 $sql =
"SELECT c.rowid, c.fk_adherent, c.fk_type, c.subscription, c.note, c.fk_bank,";
1393 $sql .=
" c.tms as datem,";
1394 $sql .=
" c.datec as datec,";
1395 $sql .=
" c.dateadh as dateh,";
1396 $sql .=
" c.datef as datef";
1397 $sql .=
" FROM ".MAIN_DB_PREFIX.
"subscription as c";
1398 $sql .=
" WHERE c.fk_adherent = ".$this->id;
1399 $sql .=
" ORDER BY c.dateadh";
1400 dol_syslog(get_class($this).
"::fetch_subscriptions", LOG_DEBUG);
1404 $this->subscriptions = array();
1407 while ($obj = $this->
db->fetch_object(
$resql)) {
1409 $this->first_subscription_date = $this->
db->jdate($obj->datec);
1410 $this->first_subscription_date_start = $this->
db->jdate($obj->dateh);
1411 $this->first_subscription_date_end = $this->
db->jdate($obj->datef);
1412 $this->first_subscription_amount = $obj->subscription;
1414 $this->last_subscription_date = $this->
db->jdate($obj->datec);
1415 $this->last_subscription_date_start = $this->
db->jdate($obj->datef);
1416 $this->last_subscription_date_end = $this->
db->jdate($obj->datef);
1417 $this->last_subscription_amount = $obj->subscription;
1420 $subscription->id = $obj->rowid;
1421 $subscription->fk_adherent = $obj->fk_adherent;
1422 $subscription->fk_type = $obj->fk_type;
1423 $subscription->amount = $obj->subscription;
1424 $subscription->note = $obj->note;
1425 $subscription->fk_bank = $obj->fk_bank;
1426 $subscription->datem = $this->
db->jdate($obj->datem);
1427 $subscription->datec = $this->
db->jdate($obj->datec);
1428 $subscription->dateh = $this->
db->jdate($obj->dateh);
1429 $subscription->datef = $this->
db->jdate($obj->datef);
1431 $this->subscriptions[] = $subscription;
1437 $this->error = $this->
db->error().
' sql='.$sql;
1457 public function subscription($date, $amount, $accountid = 0, $operation =
'', $label =
'', $num_chq =
'', $emetteur_nom =
'', $emetteur_banque =
'', $datesubend = 0)
1459 global $conf, $langs, $user;
1461 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/subscription.class.php';
1466 if (!$amount) $amount = 0;
1471 $datefin = $datesubend;
1480 $subscription->fk_adherent = $this->id;
1481 $subscription->dateh = $date;
1482 $subscription->datef = $datefin;
1483 $subscription->amount = $amount;
1484 $subscription->note = $label;
1485 $subscription->note_public = $label;
1487 $rowid = $subscription->create($user);
1494 $this->last_subscription_date =
dol_now();
1495 $this->last_subscription_date_start = $date;
1496 $this->last_subscription_date_end = $datefin;
1497 $this->last_subscription_amount = $amount;
1501 $this->
db->commit();
1504 $this->
db->rollback();
1508 $this->error = $subscription->error;
1509 $this->errors = $subscription->errors;
1510 $this->
db->rollback();
1533 public function subscriptionComplementaryActions($subscriptionid, $option, $accountid, $datesubscription, $paymentdate, $operation, $label, $amount, $num_chq, $emetteur_nom =
'', $emetteur_banque =
'', $autocreatethirdparty = 0)
1535 global $conf, $langs, $user, $mysoc;
1539 $this->invoice = null;
1541 dol_syslog(
"subscriptionComplementaryActions subscriptionid=".$subscriptionid.
" option=".$option.
" accountid=".$accountid.
" datesubscription=".$datesubscription.
" paymentdate=".
1542 $paymentdate.
" label=".$label.
" amount=".$amount.
" num_chq=".$num_chq.
" autocreatethirdparty=".$autocreatethirdparty);
1545 if ($option ==
'bankdirect' && $accountid) {
1546 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
1549 $result = $acct->fetch($accountid);
1551 $dateop = $paymentdate;
1553 $insertid = $acct->addline($dateop, $operation, $label, $amount, $num_chq,
'', $user, $emetteur_nom, $emetteur_banque);
1554 if ($insertid > 0) {
1555 $inserturlid = $acct->add_url_line($insertid, $this->
id, DOL_URL_ROOT.
'/adherents/card.php?rowid=', $this->getFullname($langs),
'member');
1556 if ($inserturlid > 0) {
1558 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"subscription SET fk_bank=".$insertid;
1559 $sql .=
" WHERE rowid=".$subscriptionid;
1561 dol_syslog(
"subscription::subscription", LOG_DEBUG);
1565 $this->error = $this->
db->lasterror();
1566 $this->errors[] = $this->error;
1570 $this->error = $acct->error;
1571 $this->errors = $acct->errors;
1575 $this->error = $acct->error;
1576 $this->errors = $acct->errors;
1581 if (($option ==
'bankviainvoice' && $accountid) || $option ==
'invoiceonly') {
1582 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1583 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/paymentterm.class.php';
1589 if (!($this->fk_soc > 0)) {
1590 if ($autocreatethirdparty) {
1595 if ($this->morphy ==
'mor') {
1596 $companyname = $this->company;
1597 if (!empty($fullname)) $companyalias = $fullname;
1599 $companyname = $fullname;
1600 if (!empty($this->company)) $companyalias = $this->company;
1603 $result = $customer->create_from_member($this, $companyname, $companyalias);
1605 $this->error = $customer->error;
1606 $this->errors = $customer->errors;
1609 $this->fk_soc = $result;
1612 $langs->load(
"errors");
1613 $this->error = $langs->trans(
"ErrorMemberNotLinkedToAThirpartyLinkOrCreateFirst");
1614 $this->errors[] = $this->error;
1620 $result = $customer->fetch($this->fk_soc);
1622 $this->error = $customer->error;
1623 $this->errors = $customer->errors;
1631 $invoice->cond_reglement_id = $customer->cond_reglement_id;
1632 if (empty($invoice->cond_reglement_id)) {
1634 $invoice->cond_reglement_id = $paymenttermstatic->getDefaultId();
1635 if (empty($invoice->cond_reglement_id)) {
1637 $this->error =
'ErrorNoPaymentTermRECEPFound';
1638 $this->errors[] = $this->error;
1641 $invoice->socid = $this->fk_soc;
1642 $invoice->date = $datesubscription;
1645 $invoice->linked_objects[
'subscription'] = $subscriptionid;
1646 if (!empty($_POST[
'other_linked_objects']) && is_array($_POST[
'other_linked_objects'])) {
1647 $invoice->linked_objects = array_merge($invoice->linked_objects, $_POST[
'other_linked_objects']);
1650 $result = $invoice->create($user);
1652 $this->error = $invoice->error;
1653 $this->errors = $invoice->errors;
1656 $this->invoice = $invoice;
1662 $idprodsubscription = 0;
1663 if (!empty($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS) && (!empty($conf->product->enabled) || !empty($conf->service->enabled))) $idprodsubscription = $conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS;
1666 if (isset($conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS) && $conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS ==
'defaultforfoundationcountry') {
1670 $result = $invoice->addline($label, 0, 1, $vattouse, 0, 0, $idprodsubscription, 0, $datesubscription,
'', 0, 0,
'',
'TTC', $amount, 1);
1672 $this->error = $invoice->error;
1673 $this->errors = $invoice->errors;
1680 $result = $invoice->validate($user);
1682 $this->error = $invoice->error;
1683 $this->errors = $invoice->errors;
1693 if (!$error && $option ==
'bankviainvoice' && $accountid) {
1694 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
1695 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
1696 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions.lib.php';
1699 $amounts[$invoice->id] =
price2num($amount);
1702 $paiement->datepaye = $paymentdate;
1703 $paiement->amounts = $amounts;
1704 $paiement->paiementid =
dol_getIdFromCode($this->
db, $operation,
'c_paiement',
'code',
'id', 1);
1705 $paiement->num_payment = $num_chq;
1706 $paiement->note_public = $label;
1710 $paiement_id = $paiement->create($user);
1711 if (!$paiement_id > 0) {
1712 $this->error = $paiement->error;
1713 $this->errors = $paiement->errors;
1720 $bank_line_id = $paiement->addPaymentToBank($user,
'payment',
'(SubscriptionPayment)', $accountid, $emetteur_nom, $emetteur_banque);
1721 if (!($bank_line_id > 0)) {
1722 $this->error = $paiement->error;
1723 $this->errors = $paiement->errors;
1728 if (!$error && !empty($bank_line_id)) {
1730 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'subscription SET fk_bank='.$bank_line_id;
1731 $sql .=
' WHERE rowid='.$subscriptionid;
1733 $result = $this->
db->query($sql);
1741 $invoice->set_paid($user);
1747 $outputlangs = $langs;
1749 $lang_id =
GETPOST(
'lang_id');
1750 if ($conf->global->MAIN_MULTILANGS && empty($newlang) && !empty($lang_id)) $newlang = $lang_id;
1751 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $customer->default_lang;
1752 if (!empty($newlang)) {
1753 $outputlangs =
new Translate(
"", $conf);
1754 $outputlangs->setDefaultLang($newlang);
1759 $invoice->generateDocument($invoice->model_pdf, $outputlangs);
1779 global $langs, $conf;
1785 if ($this->
statut == 1) {
1786 dol_syslog(get_class($this).
"::validate statut of member does not allow this", LOG_WARNING);
1792 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"adherent SET";
1793 $sql .=
" statut = 1";
1794 $sql .=
", datevalid = '".$this->db->idate($now).
"'";
1795 $sql .=
", fk_user_valid=".$user->id;
1796 $sql .=
" WHERE rowid = ".$this->id;
1798 dol_syslog(get_class($this).
"::validate", LOG_DEBUG);
1799 $result = $this->
db->query($sql);
1804 $result = $this->
call_trigger(
'MEMBER_VALIDATE', $user);
1807 $this->
db->rollback();
1812 $this->datevalid = $now;
1814 $this->
db->commit();
1817 $this->error = $this->
db->error();
1818 $this->
db->rollback();
1832 global $langs, $conf;
1837 if ($this->
statut == 0) {
1838 dol_syslog(get_class($this).
"::resiliate statut of member does not allow this", LOG_WARNING);
1844 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"adherent SET";
1845 $sql .=
" statut = 0";
1846 $sql .=
", fk_user_valid=".$user->id;
1847 $sql .=
" WHERE rowid = ".$this->id;
1849 $result = $this->
db->query($sql);
1854 $result = $this->
call_trigger(
'MEMBER_RESILIATE', $user);
1857 $this->
db->rollback();
1862 $this->
db->commit();
1865 $this->error = $this->
db->error();
1866 $this->
db->rollback();
1881 global $conf, $langs;
1883 include_once DOL_DOCUMENT_ROOT.
'/mailmanspip/class/mailmanspip.class.php';
1889 if (!empty($conf->global->ADHERENT_USE_MAILMAN) && !empty($conf->mailmanspip->enabled)) {
1890 $result = $mailmanspip->add_to_mailman($this);
1893 if (!empty($mailmanspip->error)) $this->errors[] = $mailmanspip->error;
1896 foreach ($mailmanspip->mladded_ko as $tmplist => $tmpemail) {
1897 $langs->load(
"errors");
1898 $this->errors[] = $langs->trans(
"ErrorFailedToAddToMailmanList", $tmpemail, $tmplist);
1900 foreach ($mailmanspip->mladded_ok as $tmplist => $tmpemail) {
1901 $langs->load(
"mailmanspip");
1902 $this->mesgs[] = $langs->trans(
"SuccessToAddToMailmanList", $tmpemail, $tmplist);
1907 if (!empty($conf->global->ADHERENT_USE_SPIP) && !empty($conf->mailmanspip->enabled)) {
1908 $result = $mailmanspip->add_to_spip($this);
1910 $this->errors[] = $mailmanspip->error;
1931 global $conf, $langs;
1933 include_once DOL_DOCUMENT_ROOT.
'/mailmanspip/class/mailmanspip.class.php';
1939 if (!empty($conf->global->ADHERENT_USE_MAILMAN)) {
1940 $result = $mailmanspip->del_to_mailman($this);
1942 if (!empty($mailmanspip->error)) $this->errors[] = $mailmanspip->error;
1946 foreach ($mailmanspip->mlremoved_ko as $tmplist => $tmpemail) {
1947 $langs->load(
"errors");
1948 $this->errors[] = $langs->trans(
"ErrorFailedToRemoveToMailmanList", $tmpemail, $tmplist);
1950 foreach ($mailmanspip->mlremoved_ok as $tmplist => $tmpemail) {
1951 $langs->load(
"mailmanspip");
1952 $this->mesgs[] = $langs->trans(
"SuccessToRemoveToMailmanList", $tmpemail, $tmplist);
1956 if ($conf->global->ADHERENT_USE_SPIP && !empty($conf->mailmanspip->enabled)) {
1957 $result = $mailmanspip->del_to_spip($this);
1959 $this->errors[] = $mailmanspip->error;
1980 $langs->load(
"dict");
1982 $code = (empty($this->civility_id) ?
'' : $this->civility_id);
1983 if (empty($code))
return '';
1984 return $langs->getLabelFromKey($this->
db,
"Civility".$code,
"c_civility",
"code",
"label", $code);
2000 public function getNomUrl($withpictoimg = 0, $maxlen = 0, $option =
'card', $mode =
'', $morecss =
'', $save_lastsearch_value = -1, $notooltip = 0, $addlinktonotes = 0)
2002 global $conf, $langs;
2004 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpictoimg) $withpictoimg = 0;
2011 if (!empty($this->photo)) {
2012 $label .=
'<div class="photointooltip">';
2013 $label .=
Form::showphoto(
'memberphoto', $this, 80, 0, 0,
'photowithmargin photologintooltip',
'small', 0, 1);
2014 $label .=
'</div><div style="clear: both;"></div>';
2017 $label .=
'<div class="centpercent">';
2018 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Member").
'</u>';
2019 $label .=
' '.$this->getLibStatut(4);
2020 if (!empty($this->ref)) $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
2021 if (!empty($this->firstname) || !empty($this->lastname)) $label .=
'<br><b>'.$langs->trans(
'Name').
':</b> '.$this->
getFullName($langs);
2022 if (!empty($this->company)) $label .=
'<br><b>'.$langs->trans(
'Company').
':</b> '.$this->company;
2025 $url = DOL_URL_ROOT.
'/adherents/card.php?rowid='.$this->id;
2026 if ($option ==
'subscription') {
2027 $url = DOL_URL_ROOT.
'/adherents/subscription.php?rowid='.$this->id;
2030 if ($option !=
'nolink') {
2032 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2033 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/',
$_SERVER[
"PHP_SELF"])) $add_save_lastsearch_values = 1;
2034 if ($add_save_lastsearch_values) $url .=
'&save_lastsearch_values=1';
2037 $linkstart .=
'<a href="'.$url.
'"';
2039 if (empty($notooltip)) {
2040 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2041 $langs->load(
"users");
2042 $label = $langs->trans(
"ShowUser");
2043 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
2045 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
2046 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
2049 $linkstart .= $linkclose.
'>';
2052 $result .= $linkstart;
2053 if ($withpictoimg) $result .=
'<div class="inline-block nopadding valignmiddle">';
2054 if ($withpictoimg) {
2055 $paddafterimage =
'';
2056 if (abs($withpictoimg) == 1) $paddafterimage =
'style="margin-right: 3px;"';
2058 if ($withpictoimg > 0)
2059 $picto =
'<span class="nopadding'.($morecss ?
' userimg'.$morecss :
'').
'">'.
2060 img_object(
'',
'user', $paddafterimage.
' '.($notooltip ?
'' :
'class="classfortooltip"'), 0, 0, $notooltip ? 0 : 1).
'</span>';
2063 $picto =
'<span class="nopadding'.($morecss ?
' userimg'.$morecss :
'').
'"'.($paddafterimage ?
' '.$paddafterimage :
'').
'>';
2064 $picto .=
Form::showphoto(
'memberphoto', $this, 0, 0, 0,
'userphoto'.($withpictoimg == -3 ?
'small' :
''),
'mini', 0, 1);
2065 $picto .=
'</span>';
2069 if ($withpictoimg > -2 && $withpictoimg != 2) {
2070 if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) $result .=
'<span class="nopadding valignmiddle'.((!isset($this->
statut) || $this->statut) ?
'' :
' strikefordisabled').
2071 ($morecss ?
' usertext'.$morecss :
'').
'">';
2072 if ($mode ==
'login') {
2073 $result .=
dol_trunc($this->login, $maxlen);
2074 } elseif ($mode ==
'ref') {
2075 $result .= $this->id;
2077 $result .= $this->
getFullName($langs,
'', ($mode ==
'firstname' ? 2 : ($mode ==
'lastname' ? 4 : -1)), $maxlen);
2079 if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) $result .=
'</span>';
2081 if ($withpictoimg) $result .=
'</div>';
2082 $result .= $linkend;
2084 if ($addlinktonotes) {
2085 if ($this->note_private) {
2086 $notetoshow = $langs->trans(
"ViewPrivateNote").
':<br>'.
dol_string_nohtmltag($this->note_private, 1);
2087 $result .=
' <span class="note inline-block">';
2088 $result .=
'<a href="'.DOL_URL_ROOT.
'/adherents/note.php?id='.$this->
id.
'" class="classfortooltip" title="'.
dol_escape_htmltag($notetoshow).
'">';
2091 $result .=
'</span>';
2106 return $this->
LibStatut($this->
statut, $this->need_subscription, $this->datefin, $mode);
2119 public function LibStatut($status, $need_subscription, $date_end_subscription, $mode = 0)
2123 $langs->load(
"members");
2127 $labelStatusShort =
'';
2129 if ($status == -1) {
2130 $statusType =
'status0';
2131 $labelStatus = $langs->trans(
"MemberStatusDraft");
2132 $labelStatusShort = $langs->trans(
"MemberStatusDraftShort");
2133 } elseif ($status >= 1) {
2134 if ($need_subscription == 0) {
2135 $statusType =
'status4';
2136 $labelStatus = $langs->trans(
"MemberStatusNoSubscription");
2137 $labelStatusShort = $langs->trans(
"MemberStatusNoSubscriptionShort");
2138 } elseif (!$date_end_subscription) {
2139 $statusType =
'status1';
2140 $labelStatus = $langs->trans(
"MemberStatusActive");
2141 $labelStatusShort = $langs->trans(
"MemberStatusActiveShort");
2142 } elseif ($date_end_subscription < time()) {
2143 $statusType =
'status3';
2144 $labelStatus = $langs->trans(
"MemberStatusActiveLate");
2145 $labelStatusShort = $langs->trans(
"MemberStatusActiveLateShort");
2147 $statusType =
'status4';
2148 $labelStatus = $langs->trans(
"MemberStatusPaid");
2149 $labelStatusShort = $langs->trans(
"MemberStatusPaidShort");
2151 } elseif ($status == 0) {
2152 $statusType =
'status6';
2153 $labelStatus = $langs->trans(
"MemberStatusResiliated");
2154 $labelStatusShort = $langs->trans(
"MemberStatusResiliatedShort");
2157 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
2172 $this->nb = array();
2174 $sql =
"SELECT count(a.rowid) as nb";
2175 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent as a";
2176 $sql .=
" WHERE a.statut > 0";
2177 $sql .=
" AND a.entity IN (".getEntity(
'adherent').
")";
2181 while ($obj = $this->
db->fetch_object(
$resql)) {
2182 $this->nb[
"members"] = $obj->nb;
2188 $this->error = $this->
db->error();
2204 global $conf, $langs;
2206 if ($user->socid)
return -1;
2210 $sql =
"SELECT a.rowid, a.datefin, a.statut";
2211 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent as a";
2212 $sql .=
", ".MAIN_DB_PREFIX.
"adherent_type as t";
2213 $sql .=
" WHERE a.fk_adherent_type = t.rowid";
2214 if ($mode ==
'expired') {
2215 $sql .=
" AND a.statut = 1";
2216 $sql .=
" AND a.entity IN (".getEntity(
'adherent').
")";
2217 $sql .=
" AND ((a.datefin IS NULL or a.datefin < '".$this->db->idate($now).
"') AND t.subscription = '1')";
2218 } elseif ($mode ==
'shift') {
2219 $sql .=
" AND a.statut = -1";
2220 $sql .=
" AND a.entity IN (".getEntity(
'adherent').
")";
2225 $langs->load(
"members");
2232 if ($mode ==
'expired') {
2233 $warning_delay = $conf->adherent->subscription->warning_delay / 60 / 60 / 24;
2234 $label = $langs->trans(
"MembersWithSubscriptionToReceive");
2235 $labelShort = $langs->trans(
"MembersWithSubscriptionToReceiveShort");
2236 $url = DOL_URL_ROOT.
'/adherents/list.php?mainmenu=members&statut=1&filter=outofdate';
2237 } elseif ($mode ==
'shift') {
2238 $warning_delay = $conf->adherent->subscription->warning_delay / 60 / 60 / 24;
2239 $url = DOL_URL_ROOT.
'/adherents/list.php?mainmenu=members&statut=-1';
2240 $label = $langs->trans(
"MembersListToValid");
2241 $labelShort = $langs->trans(
"ToValidate");
2245 $response->warning_delay = $warning_delay;
2246 $response->label = $label;
2247 $response->labelShort = $labelShort;
2248 $response->url = $url;
2253 while ($obj = $this->
db->fetch_object(
$resql)) {
2254 $response->nbtodo++;
2256 $adherentstatic->datefin = $this->
db->jdate($obj->datefin);
2257 $adherentstatic->statut = $obj->statut;
2259 if ($adherentstatic->hasDelay()) {
2260 $response->nbtodolate++;
2267 $this->error = $this->
db->error();
2284 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
2286 global $conf, $langs;
2288 $langs->load(
"orders");
2291 $modele =
'standard';
2293 if ($this->model_pdf) {
2294 $modele = $this->model_pdf;
2295 } elseif (!empty($conf->global->ADHERENT_ADDON_PDF)) {
2296 $modele = $conf->global->ADHERENT_ADDON_PDF;
2300 $modelpath =
"core/modules/member/doc/";
2302 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
2315 global $user, $langs;
2321 $this->specimen = 1;
2322 $this->civility_id = 0;
2323 $this->lastname =
'DOLIBARR';
2324 $this->firstname =
'SPECIMEN';
2325 $this->gender =
'man';
2326 $this->login =
'dolibspec';
2327 $this->pass =
'dolibspec';
2328 $this->company =
'Societe ABC';
2329 $this->address =
'61 jump street';
2330 $this->zip =
'75000';
2331 $this->town =
'Paris';
2332 $this->country_id = 1;
2333 $this->country_code =
'FR';
2334 $this->country =
'France';
2335 $this->morphy =
'mor';
2336 $this->email =
'specimen@specimen.com';
2337 $this->socialnetworks = array(
2338 'skype' =>
'skypepseudo',
2339 'twitter' =>
'twitterpseudo',
2340 'facebook' =>
'facebookpseudo',
2341 'linkedin' =>
'linkedinpseudo',
2343 $this->phone =
'0999999999';
2344 $this->phone_perso =
'0999999998';
2345 $this->phone_mobile =
'0999999997';
2346 $this->note_public =
'This is a public note';
2347 $this->note_private =
'This is a private note';
2348 $this->birth = $now;
2353 $this->datefin = $now;
2354 $this->datevalid = $now;
2357 $this->
type =
'Type adherent';
2358 $this->need_subscription = 0;
2360 $this->first_subscription_date = $now;
2361 $this->first_subscription_date_start = $this->first_subscription_date;
2362 $this->first_subscription_date_end =
dol_time_plus_duree($this->first_subscription_date_start, 1,
'y');
2363 $this->first_subscription_amount = 10;
2365 $this->last_subscription_date = $this->first_subscription_date;
2366 $this->last_subscription_date_start = $this->first_subscription_date;
2367 $this->last_subscription_date_end =
dol_time_plus_duree($this->last_subscription_date_start, 1,
'y');
2368 $this->last_subscription_amount = 10;
2389 if ($mode == 0) $dn = $conf->global->LDAP_KEY_MEMBERS.
"=".$info[$conf->global->LDAP_KEY_MEMBERS].
",".$conf->global->LDAP_MEMBER_DN;
2390 if ($mode == 1) $dn = $conf->global->LDAP_MEMBER_DN;
2391 if ($mode == 2) $dn = $conf->global->LDAP_KEY_MEMBERS.
"=".$info[$conf->global->LDAP_KEY_MEMBERS];
2406 global $conf, $langs;
2410 $keymodified =
false;
2413 $info[
"objectclass"] = explode(
',', $conf->global->LDAP_MEMBER_OBJECT_CLASS);
2418 if ($this->morphy ==
'mor' && (empty($this->fullname) || $this->fullname == $this->company)) {
2419 $this->fullname = $this->company;
2420 $this->lastname = $this->company;
2425 'LDAP_MEMBER_FIELD_FULLNAME' =>
'fullname',
2426 'LDAP_MEMBER_FIELD_NAME' =>
'lastname',
2427 'LDAP_MEMBER_FIELD_LOGIN' =>
'login',
2428 'LDAP_MEMBER_FIELD_LOGIN_SAMBA' =>
'login',
2429 'LDAP_MEMBER_FIELD_MAIL' =>
'email'
2433 foreach ($ldapkey as $constname => $varname) {
2434 if (!empty($this->$varname) && !empty($conf->global->$constname)) {
2435 $info[$conf->global->$constname] = $this->$varname;
2438 if (!empty($conf->global->LDAP_KEY_MEMBERS) && $conf->global->LDAP_KEY_MEMBERS == $conf->global->$constname) {
2439 if (!empty($this->oldcopy) && $this->$varname != $this->oldcopy->$varname) $keymodified =
true;
2443 if ($this->firstname && !empty($conf->global->LDAP_MEMBER_FIELD_FIRSTNAME)) $info[$conf->global->LDAP_MEMBER_FIELD_FIRSTNAME] = $this->firstname;
2444 if ($this->poste && !empty($conf->global->LDAP_MEMBER_FIELD_TITLE)) $info[$conf->global->LDAP_MEMBER_FIELD_TITLE] = $this->poste;
2445 if ($this->company && !empty($conf->global->LDAP_MEMBER_FIELD_COMPANY)) $info[$conf->global->LDAP_MEMBER_FIELD_COMPANY] = $this->company;
2446 if ($this->address && !empty($conf->global->LDAP_MEMBER_FIELD_ADDRESS)) $info[$conf->global->LDAP_MEMBER_FIELD_ADDRESS] = $this->address;
2447 if ($this->zip && !empty($conf->global->LDAP_MEMBER_FIELD_ZIP)) $info[$conf->global->LDAP_MEMBER_FIELD_ZIP] = $this->zip;
2448 if ($this->town && !empty($conf->global->LDAP_MEMBER_FIELD_TOWN)) $info[$conf->global->LDAP_MEMBER_FIELD_TOWN] = $this->town;
2449 if ($this->country_code && !empty($conf->global->LDAP_MEMBER_FIELD_COUNTRY)) $info[$conf->global->LDAP_MEMBER_FIELD_COUNTRY] = $this->country_code;
2450 foreach ($socialnetworks as $key => $value) {
2451 if ($this->socialnetworks[$value[
'label']] && !empty($conf->global->{
'LDAP_MEMBER_FIELD_'.strtoupper($value[
'label'])})) {
2452 $info[$conf->global->{
'LDAP_MEMBER_FIELD_'.strtoupper($value[
'label'])}] = $this->socialnetworks[$value[
'label']];
2455 if ($this->phone && !empty($conf->global->LDAP_MEMBER_FIELD_PHONE)) $info[$conf->global->LDAP_MEMBER_FIELD_PHONE] = $this->phone;
2456 if ($this->phone_perso && !empty($conf->global->LDAP_MEMBER_FIELD_PHONE_PERSO)) $info[$conf->global->LDAP_MEMBER_FIELD_PHONE_PERSO] = $this->phone_perso;
2457 if ($this->phone_mobile && !empty($conf->global->LDAP_MEMBER_FIELD_MOBILE)) $info[$conf->global->LDAP_MEMBER_FIELD_MOBILE] = $this->phone_mobile;
2458 if ($this->fax && !empty($conf->global->LDAP_MEMBER_FIELD_FAX)) $info[$conf->global->LDAP_MEMBER_FIELD_FAX] = $this->fax;
2459 if ($this->note_private && !empty($conf->global->LDAP_MEMBER_FIELD_DESCRIPTION)) $info[$conf->global->LDAP_MEMBER_FIELD_DESCRIPTION] =
dol_string_nohtmltag($this->note_private, 2);
2460 if ($this->note_public && !empty($conf->global->LDAP_MEMBER_FIELD_NOTE_PUBLIC)) $info[$conf->global->LDAP_MEMBER_FIELD_NOTE_PUBLIC] =
dol_string_nohtmltag($this->note_public, 2);
2461 if ($this->birth && !empty($conf->global->LDAP_MEMBER_FIELD_BIRTHDATE)) $info[$conf->global->LDAP_MEMBER_FIELD_BIRTHDATE] =
dol_print_date($this->birth,
'dayhourldap');
2462 if (isset($this->
statut) && !empty($conf->global->LDAP_FIELD_MEMBER_STATUS)) $info[$conf->global->LDAP_FIELD_MEMBER_STATUS] = $this->statut;
2463 if ($this->datefin && !empty($conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION)) $info[$conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION] =
dol_print_date($this->datefin,
'dayhourldap');
2466 if (!empty($this->pass)) {
2467 if (!empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD)) {
2468 $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD] = $this->pass;
2470 if (!empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED)) {
2471 $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED] =
dol_hash($this->pass, 4);
2474 elseif ($conf->global->LDAP_SERVER_PROTOCOLVERSION !==
'3') {
2475 if (!empty($conf->global->DATABASE_PWD_ENCRYPTED)) {
2477 if (empty($conf->global->MAIN_SECURITY_HASH_ALGO)) {
2478 if ($this->pass_indatabase_crypted && !empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED)) {
2481 $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED] =
'{md5}'.base64_encode(hex2bin($this->pass_indatabase_crypted));
2485 elseif (!empty($this->pass_indatabase)) {
2486 if (!empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD)) $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD] = $this->pass_indatabase;
2487 if (!empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED)) $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED] =
dol_hash($this->pass_indatabase, 4);
2492 if ($this->first_subscription_date && !empty($conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE)) $info[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE] =
dol_print_date($this->first_subscription_date,
'dayhourldap');
2493 if (isset($this->first_subscription_amount) && !empty($conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT)) $info[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT] = $this->first_subscription_amount;
2494 if ($this->last_subscription_date && !empty($conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE)) $info[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE] =
dol_print_date($this->last_subscription_date,
'dayhourldap');
2495 if (isset($this->last_subscription_amount) && !empty($conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT)) $info[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT] = $this->last_subscription_amount;
2509 $sql =
'SELECT a.rowid, a.datec as datec,';
2510 $sql .=
' a.datevalid as datev,';
2511 $sql .=
' a.tms as datem,';
2512 $sql .=
' a.fk_user_author, a.fk_user_valid, a.fk_user_mod';
2513 $sql .=
' FROM '.MAIN_DB_PREFIX.
'adherent as a';
2514 $sql .=
' WHERE a.rowid = '.$id;
2516 dol_syslog(get_class($this).
"::info", LOG_DEBUG);
2517 $result = $this->
db->query($sql);
2519 if ($this->
db->num_rows($result)) {
2520 $obj = $this->
db->fetch_object($result);
2521 $this->
id = $obj->rowid;
2522 if ($obj->fk_user_author) {
2523 $cuser =
new User($this->
db);
2524 $cuser->fetch($obj->fk_user_author);
2525 $this->user_creation = $cuser;
2528 if ($obj->fk_user_valid) {
2529 $vuser =
new User($this->
db);
2530 $vuser->fetch($obj->fk_user_valid);
2531 $this->user_validation = $vuser;
2534 if ($obj->fk_user_mod) {
2535 $muser =
new User($this->
db);
2536 $muser->fetch($obj->fk_user_mod);
2537 $this->user_modification = $muser;
2540 $this->date_creation = $this->
db->jdate($obj->datec);
2541 $this->date_validation = $this->
db->jdate($obj->datev);
2542 $this->date_modification = $this->
db->jdate($obj->datem);
2545 $this->
db->free($result);
2558 $sql =
"SELECT count(mc.email) as nb";
2559 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mailing_cibles as mc";
2560 $sql .=
" WHERE mc.email = '".$this->db->escape($this->email).
"'";
2561 $sql .=
" AND mc.statut NOT IN (-1,0)";
2565 $obj = $this->
db->fetch_object(
$resql);
2571 $this->error = $this->
db->error();
2589 if (!is_array($categories)) {
2590 $categories = array($categories);
2594 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2596 $existing = $c->containing($this->
id, Categorie::TYPE_MEMBER,
'id');
2599 if (is_array($existing)) {
2600 $to_del = array_diff($existing, $categories);
2601 $to_add = array_diff($categories, $existing);
2604 $to_add = $categories;
2608 foreach ($to_del as $del) {
2609 if ($c->fetch($del) > 0) {
2610 $c->del_type($this, Categorie::TYPE_MEMBER);
2613 foreach ($to_add as $add) {
2614 if ($c->fetch($add) > 0) {
2615 $c->add_type($this, Categorie::TYPE_MEMBER);
2632 $tables = array(
'adherent');
2647 if ($this->
statut <= 0)
return false;
2648 if (!$this->datefin)
return false;
2652 return $this->datefin < ($now - $conf->adherent->subscription->warning_delay);
2665 global $conf, $langs, $mysoc, $user;
2671 $blockingerrormsg =
'';
2673 if (empty($conf->adherent->enabled)) {
2674 $langs->load(
"agenda");
2675 $this->output = $langs->trans(
'ModuleNotEnabled', $langs->transnoentitiesnoconv(
"Adherent"));
2678 if (empty($conf->global->MEMBER_REMINDER_EMAIL)) {
2679 $langs->load(
"agenda");
2680 $this->output = $langs->trans(
'EventRemindersByEmailNotEnabled', $langs->transnoentitiesnoconv(
"Adherent"));
2688 $listofmembersok = array();
2689 $listofmembersko = array();
2691 $arraydaysbeforeend = explode(
';', $daysbeforeendlist);
2692 foreach ($arraydaysbeforeend as $daysbeforeend) {
2693 dol_syslog(__METHOD__.
' - Process delta = '.$daysbeforeend, LOG_DEBUG);
2695 if (!is_numeric($daysbeforeend)) {
2696 $blockingerrormsg =
"Value for delta is not a positive or negative numeric";
2704 $sql =
'SELECT rowid FROM '.MAIN_DB_PREFIX.
'adherent';
2705 $sql .=
" WHERE entity = ".$conf->entity;
2706 $sql .=
" AND datefin = '".$this->db->idate($datetosearchfor).
"'";
2710 $num_rows = $this->
db->num_rows(
$resql);
2712 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
2717 while ($i < $num_rows) {
2718 $obj = $this->
db->fetch_object(
$resql);
2720 $adherent->fetch($obj->rowid,
'',
'',
'',
true,
true);
2722 if (empty($adherent->email)) {
2724 $listofmembersko[$adherent->id] = $adherent->id;
2726 $adherent->fetch_thirdparty();
2729 $languagefromcountrycode =
getLanguageCodeFromCountryCode($adherent->country_code ? $adherent->country_code : $adherent->thirdparty->country_code);
2730 $languagecodeformember = (empty($adherent->thirdparty->default_lang) ? ($languagefromcountrycode ? $languagefromcountrycode : $mysoc->default_lang) : $adherent->thirdparty->default_lang);
2733 $outputlangs =
new Translate(
'', $conf);
2734 $outputlangs->setDefaultLang($languagecodeformember);
2735 $outputlangs->loadLangs(array(
"main",
"members"));
2736 dol_syslog(
"sendReminderForExpiredSubscription Language for member id ".$adherent->id.
" set to ".$outputlangs->defaultlang.
" mysoc->default_lang=".$mysoc->default_lang);
2738 $arraydefaultmessage = null;
2739 $labeltouse = $conf->global->ADHERENT_EMAIL_TEMPLATE_REMIND_EXPIRATION;
2741 if (!empty($labeltouse)) $arraydefaultmessage = $formmail->getEMailTemplate($this->
db,
'member', $user, $outputlangs, 0, 1, $labeltouse);
2743 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
2748 $subject =
make_substitutions($arraydefaultmessage->topic, $substitutionarray, $outputlangs);
2749 $msg =
make_substitutions($arraydefaultmessage->content, $substitutionarray, $outputlangs);
2750 $from = $conf->global->ADHERENT_MAIL_FROM;
2751 $to = $adherent->email;
2753 $trackid =
'mem'.$adherent->id;
2754 $moreinheader =
'X-Dolibarr-Info: sendReminderForExpiredSubscription'.
"\r\n";
2756 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
2757 $cmail =
new CMailFile($subject, $to, $from, $msg, array(), array(), array(),
'',
'', 0, 1,
'',
'', $trackid, $moreinheader);
2758 $result = $cmail->sendfile();
2761 $this->error = $cmail->error;
2762 if (!is_null($cmail->errors)) {
2763 $this->errors += $cmail->errors;
2766 $listofmembersko[$adherent->id] = $adherent->id;
2769 $listofmembersok[$adherent->id] = $adherent->id;
2775 $actioncode =
'EMAIL';
2779 $actionmsg2 = $langs->transnoentities(
'MailSentBy').
' '.
CMailFile::getValidAddress($from, 4, 0, 1).
' '.$langs->transnoentities(
'To').
' '.
2785 $actionmsg =
dol_concatdesc($actionmsg, $langs->transnoentities(
'MailTopic').
": ".$subject);
2786 $actionmsg =
dol_concatdesc($actionmsg, $langs->transnoentities(
'TextUsedInTheMessageBody').
":");
2790 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
2795 $actioncomm->type_code =
'AC_OTH_AUTO';
2796 $actioncomm->code =
'AC_'.$actioncode;
2797 $actioncomm->label = $actionmsg2;
2798 $actioncomm->note_private = $actionmsg;
2799 $actioncomm->fk_project = 0;
2800 $actioncomm->datep = $now;
2801 $actioncomm->datef = $now;
2802 $actioncomm->percentage = -1;
2803 $actioncomm->socid = $adherent->thirdparty->id;
2804 $actioncomm->contact_id = 0;
2805 $actioncomm->authorid = $user->id;
2806 $actioncomm->userownerid = $user->id;
2808 $actioncomm->email_msgid = $cmail->msgid;
2809 $actioncomm->email_from = $from;
2810 $actioncomm->email_sender =
'';
2811 $actioncomm->email_to = $to;
2812 $actioncomm->email_tocc = $sendtocc;
2813 $actioncomm->email_tobcc = $sendtobcc;
2814 $actioncomm->email_subject = $subject;
2815 $actioncomm->errors_to =
'';
2817 $actioncomm->fk_element = $adherent->id;
2818 $actioncomm->elementtype = $adherent->element;
2820 $actioncomm->extraparams = $extraparams;
2822 $actioncomm->create($user);
2825 $blockingerrormsg =
"Can't find email template, defined into member module setup, to use for reminding";
2828 $listofmembersko[$adherent->id] = $adherent->id;
2837 $this->error = $this->
db->lasterror();
2842 if ($blockingerrormsg) {
2843 $this->error = $blockingerrormsg;
2846 $this->output =
'Found '.($nbok + $nbko).
' members to send reminder to.';
2847 $this->output .=
' Send email successfuly to '.$nbok.
' members';
2848 if (is_array($listofmembersok)) {
2851 foreach ($listofmembersok as $idmember) {
2853 $listofids .=
', ...';
2856 if (empty($listofids)) {
2861 $listofids .= $idmember;
2864 if ($listofids) $listofids .=
']';
2865 $this->output .= $listofids;
2868 $this->output .=
' - Canceled for '.$nbko.
' member (no email or email sending error)';
2869 if (is_array($listofmembersko)) {
2872 foreach ($listofmembersko as $idmember) {
2874 $listofids .=
', ...';
2877 if (empty($listofids)) {
2882 $listofids .= $idmember;
2885 if ($listofids) $listofids .=
']';
2886 $this->output .= $listofids;
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
resiliate($user)
Fonction qui resilie un adherent.
del_to_abo()
Function to delete a member from external tools like mailing-list, spip, etc.
LibStatut($status, $need_subscription, $date_end_subscription, $mode=0)
Renvoi le libelle d'un statut donne.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto= 'UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
setCategories($categories)
Sets object to supplied categories.
dol_hash($chain, $type= '0')
Returns a hash of a string.
const TYPE_STANDARD
Standard invoice.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
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...
if(!empty($arrayfields['u.datec']['checked'])) print_liste_field_titre("DateCreationShort"u if(!empty($arrayfields['u.tms']['checked'])) print_liste_field_titre("DateModificationShort"u if(!empty($arrayfields['u.statut']['checked'])) print_liste_field_titre("Status"u statut
subscription($date, $amount, $accountid=0, $operation= '', $label= '', $num_chq= '', $emetteur_nom= '', $emetteur_banque= '', $datesubend=0)
Insert subscription into database and eventually add links to banks, mailman, etc...
getCivilityLabel()
Return civility label of a member.
setUpperOrLowerCase()
Set to upper or ucwords/lower if needed.
Class to manage agenda events (actions)
getArrayOfSocialNetworks()
Get array of social network dictionary.
validate($user)
Function that validate a member.
dol_now($mode= 'auto')
Return date for now.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
Class to manage Dolibarr users.
add_to_abo()
Function to add member into external tools mailing-list, spip, etc.
setUserId($userid)
Set link to a user.
getNomUrl($withpictoimg=0, $maxlen=0, $option= 'card', $mode= '', $morecss= '', $save_lastsearch_value=-1, $notooltip=0, $addlinktonotes=0)
Return clicable name (with picto eventually)
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
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...
setThirdPartyId($thirdpartyid)
Set link to a third party.
_load_ldap_info()
Initialise tableau info (tableau des attributs LDAP)
getFullName($langs, $option=0, $nameorder=-1, $maxlen=0)
Return full name (civility+' '+name+' '+lastname)
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...
create($user, $notrigger=0)
Create a member into database.
fetch_name($firstname, $lastname)
Method to load member from its name.
fetch($rowid, $ref= '', $fk_soc= '', $ref_ext= '', $fetch_optionals=true, $fetch_subscriptions=true)
Load member from database.
$conf db
API class for accounts.
Class to manage bank accounts.
getLanguageCodeFromCountryCode($countrycode)
Return default language from country code.
_load_ldap_dn($info, $mode=0)
Retourne chaine DN complete dans l'annuaire LDAP pour l'objet.
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.
insertExtraFields($trigger= '', $userused=null)
Add/Update all extra fields values for the current object.
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null)
Return array of possible common substitutions.
getNbOfEMailings()
Return number of mass Emailing received by this member with its email.
info($id)
Load type info information in the member object.
setPassword($user, $password= '', $isencrypted=0, $notrigger=0, $nosyncuser=0)
Change password of a user.
Class to manage third parties objects (customers, suppliers, prospects...)
fetch_subscriptions()
Function to get member subscriptions data first_subscription_date, first_subscription_date_start, first_subscription_date_end, first_subscription_amount last_subscription_date, last_subscription_date_start, last_subscription_date_end, last_subscription_amount.
Class to manage categories.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
sendReminderForExpiredSubscription($daysbeforeendlist= '10')
Send reminders by emails before subscription end CAN BE A CRON TASK.
static getValidAddress($address, $format, $encode=0, $maxnumberofemail=0)
Return a formatted address string for SMTP protocol.
static replaceThirdparty($db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,$sendto,$replyto,$message,$filepath,$mimetype,$filename,$cc,$ccc,$deliveryreceipt,$msgishtml,$errors_to,$css,$trackid,$moreinheader,$sendcontext,$replyto); $mailfile->sendfile();.
static commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
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_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
Class to manage payments of customer invoices.
Class to manage members of a foundation.
dol_getdate($timestamp, $fast=false, $forcetimezone= '')
Return an array with locale date info.
fetch_login($login)
Method to load member from its login.
update($user, $notrigger=0, $nosyncuser=0, $nosyncuserpass=0, $nosyncthirdparty=0, $action= 'update')
Update a member in database (standard information and password)
hasDelay()
Return if a member is late (subscription late) or not.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.
deleteExtraFields()
Delete all extra fields values for the current object.
Class to manage translations.
__construct($db)
Constructor.
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...
Class to manage subscriptions of foundation members.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_getIdFromCode($db, $key, $tablename, $fieldkey= 'code', $fieldid= 'id', $entityfilter=0)
Return an id or code from a code or id.
load_state_board()
Charge indicateurs this->nb de tableau de bord.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
call_trigger($triggerName, $user)
Call trigger based on this instance.
makeSubstitution($text)
Make substitution of tags into text with value of current object.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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) Si ...
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.
subscriptionComplementaryActions($subscriptionid, $option, $accountid, $datesubscription, $paymentdate, $operation, $label, $amount, $num_chq, $emetteur_nom= '', $emetteur_banque= '', $autocreatethirdparty=0)
Do complementary actions after subscription recording.
dolGetStatus($statusLabel= '', $statusLabelShort= '', $html= '', $statusType= 'status0', $displayMode=0, $url= '', $params=array())
Output the badge of a status.
make_substitutions($text, $substitutionarray, $outputlangs=null)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
Class to manage invoices.
load_board($user, $mode)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
update_end_date($user)
Update denormalized last subscription date.
Class to manage mailman and spip.
dol_time_plus_duree($time, $duration_value, $duration_unit)
Add a delay to a date.
initAsSpecimen()
Initialise an instance with random values.
getmorphylib($morphy= '')
Return translated label by the nature of a adherent (physical or moral)
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
Class to manage payment terms records in dictionary.
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...
getLibStatut($mode=0)
Retourne le libelle du statut d'un adherent (brouillon, valide, resilie)
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
dol_textishtml($msg, $option=0)
Return if a text is a html content.