From 263e110ca3aebbb74f1430211479335465c23348 Mon Sep 17 00:00:00 2001 From: NextGestion Date: Mon, 19 Apr 2021 13:19:32 +0100 Subject: [PATCH] Enhance module Member --- htdocs/adherents/admin/member.php | 6 +++++ htdocs/adherents/list.php | 39 +++++++++++++++++++++++++++++ htdocs/core/lib/functions.lib.php | 2 ++ htdocs/langs/en_US/admin.lang | 1 + htdocs/langs/en_US/main.lang | 1 + htdocs/langs/en_US/members.lang | 1 + htdocs/public/payment/paymentok.php | 21 ++++++++++++++++ 7 files changed, 71 insertions(+) diff --git a/htdocs/adherents/admin/member.php b/htdocs/adherents/admin/member.php index 62291791fc5..b3c7646689b 100644 --- a/htdocs/adherents/admin/member.php +++ b/htdocs/adherents/admin/member.php @@ -107,6 +107,7 @@ if ($action == 'set_default') { $res1 = dolibarr_set_const($db, 'ADHERENT_LOGIN_NOT_REQUIRED', GETPOST('ADHERENT_LOGIN_NOT_REQUIRED', 'alpha') ? 0 : 1, 'chaine', 0, '', $conf->entity); $res2 = dolibarr_set_const($db, 'ADHERENT_MAIL_REQUIRED', GETPOST('ADHERENT_MAIL_REQUIRED', 'alpha'), 'chaine', 0, '', $conf->entity); $res3 = dolibarr_set_const($db, 'ADHERENT_DEFAULT_SENDINFOBYMAIL', GETPOST('ADHERENT_DEFAULT_SENDINFOBYMAIL', 'alpha'), 'chaine', 0, '', $conf->entity); + $res3 = dolibarr_set_const($db, 'ADHERENT_CREATE_EXTERNAL_USER_LOGIN', GETPOST('ADHERENT_CREATE_EXTERNAL_USER_LOGIN', 'alpha'), 'chaine', 0, '', $conf->entity); $res4 = dolibarr_set_const($db, 'ADHERENT_BANK_USE', GETPOST('ADHERENT_BANK_USE', 'alpha'), 'chaine', 0, '', $conf->entity); // Use vat for invoice creation if ($conf->facture->enabled) { @@ -219,6 +220,11 @@ print ''.$langs->trans("MemberSendInformationByMailByDef print $form->selectyesno('ADHERENT_DEFAULT_SENDINFOBYMAIL', (!empty($conf->global->ADHERENT_DEFAULT_SENDINFOBYMAIL) ? $conf->global->ADHERENT_DEFAULT_SENDINFOBYMAIL : 0), 1); print "\n"; +// Create an external user login for each new member subscription validated +print ''.$langs->trans("MemberCreateAnExternalUserForSubscriptionValidated").''; +print $form->selectyesno('ADHERENT_CREATE_EXTERNAL_USER_LOGIN', (!empty($conf->global->ADHERENT_CREATE_EXTERNAL_USER_LOGIN) ? $conf->global->ADHERENT_CREATE_EXTERNAL_USER_LOGIN : 0), 1); +print "\n"; + // Insert subscription into bank account print ''.$langs->trans("MoreActionsOnSubscription").''; $arraychoices = array('0'=>$langs->trans("None")); diff --git a/htdocs/adherents/list.php b/htdocs/adherents/list.php index 9560a284e2a..5dd0e1e5d74 100644 --- a/htdocs/adherents/list.php +++ b/htdocs/adherents/list.php @@ -247,6 +247,42 @@ if (empty($reshook)) { } } + // Create external user + if ($massaction == 'createexternaluser' && $user->rights->adherent->creer && $user->rights->user->user->creer) { + $tmpmember = new Adherent($db); + $error = 0; + $nbcreated = 0; + + $db->begin(); + + foreach ($toselect as $idtoclose) { + $tmpmember->fetch($idtoclose); + + if(!empty($tmpmember->fk_soc)){ + $nuser = new User($db); + $tmpuser = dol_clone($tmpmember); + + $result = $nuser->create_from_member($tmpuser, $tmpmember->login); + + if ($result < 0 && !count($tmpmember->errors)) { + setEventMessages($tmpmember->error, $tmpmember->errors, 'errors'); + } else { + if ($result > 0) { + $nbcreated++; + } + } + } + } + + if (!$error) { + setEventMessages($langs->trans("XExternalUserCreated", $nbcreated), null, 'mesgs'); + + $db->commit(); + } else { + $db->rollback(); + } + } + // Mass actions $objectclass = 'Adherent'; $objectlabel = 'Members'; @@ -555,6 +591,9 @@ if ($user->rights->adherent->supprimer) { if ($user->rights->societe->creer) { $arrayofmassactions['preaffecttag'] = img_picto('', 'category', 'class="pictofixedwidth"').$langs->trans("AffectTag"); } +if ($user->rights->adherent->creer && $user->rights->user->user->creer) { + $arrayofmassactions['createexternaluser'] = img_picto('', 'user', 'class="pictofixedwidth"').$langs->trans("CreateExternalUser"); +} if (in_array($massaction, array('presend', 'predelete','preaffecttag'))) { $arrayofmassactions = array(); } diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 2b981530834..7f2d7eff7a8 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -6835,6 +6835,7 @@ function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null, $substitutionarray['__MEMBER_CIVILITY__'] = '__MEMBER_CIVILITY__'; $substitutionarray['__MEMBER_FIRSTNAME__'] = '__MEMBER_FIRSTNAME__'; $substitutionarray['__MEMBER_LASTNAME__'] = '__MEMBER_LASTNAME__'; + $substitutionarray['__MEMBER_USER_LOGIN_INFORMATION__'] = 'Login and pass of the external user account'; /*$substitutionarray['__MEMBER_NOTE_PUBLIC__'] = '__MEMBER_NOTE_PUBLIC__'; $substitutionarray['__MEMBER_NOTE_PRIVATE__'] = '__MEMBER_NOTE_PRIVATE__';*/ } @@ -6910,6 +6911,7 @@ function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null, } $substitutionarray['__MEMBER_FIRSTNAME__'] = (isset($object->firstname) ? $object->firstname : ''); $substitutionarray['__MEMBER_LASTNAME__'] = (isset($object->lastname) ? $object->lastname : ''); + $substitutionarray['__MEMBER_USER_LOGIN_INFORMATION__'] = ''; if (method_exists($object, 'getFullName')) { $substitutionarray['__MEMBER_FULLNAME__'] = $object->getFullName($outputlangs); } diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index b103d0082ba..7a35efb30e1 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1431,6 +1431,7 @@ MemberMainOptions=Main options AdherentLoginRequired= Manage a Login for each member AdherentMailRequired=Email required to create a new member MemberSendInformationByMailByDefault=Checkbox to send mail confirmation to members (validation or new subscription) is on by default +MemberCreateAnExternalUserForSubscriptionValidated=Create an external user login for each new member subscription validated VisitorCanChooseItsPaymentMode=Visitor can choose from available payment modes MEMBER_REMINDER_EMAIL=Enable automatic reminder by email of expired subscriptions. Note: Module %s must be enabled and correctly setup to send reminders. MembersDocModules=Document templates for documents generated from member record diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 51d4d99bd8c..4dca585538a 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -1125,6 +1125,7 @@ UpdateForAllLines=Update for all lines OnHold=On hold Civility=Civility AffectTag=Affect Tag +CreateExternalUser=Create external user ConfirmAffectTag=Bulk Tag Affect ConfirmAffectTagQuestion=Are you sure you want to affect tags to the %s selected record(s)? CategTypeNotFound=No tag type found for type of records diff --git a/htdocs/langs/en_US/members.lang b/htdocs/langs/en_US/members.lang index 2ab2fb87270..52bc295c974 100644 --- a/htdocs/langs/en_US/members.lang +++ b/htdocs/langs/en_US/members.lang @@ -213,3 +213,4 @@ SendReminderForExpiredSubscription=Send reminder by email to members when subscr MembershipPaid=Membership paid for current period (until %s) YouMayFindYourInvoiceInThisEmail=You may find your invoice attached to this email XMembersClosed=%s member(s) closed +XExternalUserCreated=%s external user(s) created diff --git a/htdocs/public/payment/paymentok.php b/htdocs/public/payment/paymentok.php index 1942635001f..d61bb4d20d1 100644 --- a/htdocs/public/payment/paymentok.php +++ b/htdocs/public/payment/paymentok.php @@ -623,6 +623,27 @@ if ($ispaymentok) { } $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object); + + // Create external user + if(!empty($conf->global->ADHERENT_CREATE_EXTERNAL_USER_LOGIN)){ + $infouserlogin = ''; + $nuser = new User($db); + $tmpuser = dol_clone($object); + + $result = $nuser->create_from_member($tmpuser, $object->login); + $newpassword = $nuser->setPassword($user, ''); + + if ($result < 0) { + $outputlangs->load("errors"); + $postactionmessages[] = 'Error in create external user : '.$nuser->error; + } else { + $infouserlogin .= $outputlangs->trans("Login").': '.$nuser->login."
"."\n"; + $infouserlogin .= $outputlangs->trans("Password").': '.$newpassword; + $postactionmessages[] = $langs->trans("NewUserCreated", $nuser->login); + } + $substitutionarray['__MEMBER_USER_LOGIN_INFORMATION__'] = $infouserlogin; + } + complete_substitutions_array($substitutionarray, $outputlangs, $object); $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs); $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnSubscription()), $substitutionarray, $outputlangs);