From 8fb42b00618f7534464748dd30d6e6a669dbbbf5 Mon Sep 17 00:00:00 2001 From: Lucas Marcouiller <45882981+Hystepik@users.noreply.github.com> Date: Fri, 17 Oct 2025 18:13:39 +0200 Subject: [PATCH] New fetch member to redirect to membership payment (#35808) * New fetch member to redirect to membership payment * add constant * fix CI * Update new.php * Fix formatting of conditional check for member search --------- Co-authored-by: Lucas Marcouiller Co-authored-by: Laurent Destailleur --- htdocs/adherents/admin/website.php | 7 +++ htdocs/langs/en_US/members.lang | 3 + htdocs/public/members/new.php | 91 +++++++++++++++++++++++++++--- 3 files changed, 94 insertions(+), 7 deletions(-) diff --git a/htdocs/adherents/admin/website.php b/htdocs/adherents/admin/website.php index 3942635e4b7..34fe35153ca 100644 --- a/htdocs/adherents/admin/website.php +++ b/htdocs/adherents/admin/website.php @@ -312,6 +312,13 @@ if (getDolGlobalString('MEMBER_ENABLE_PUBLIC')) { print $form->selectarray("MEMBER_NEWFORM_PAYONLINE", $listofval, getDolGlobalString('MEMBER_NEWFORM_PAYONLINE'), 0); print "\n"; + // Search a member after member creation form + print ''; + print $langs->trans("MEMBER_SEARCH_MEMBER_PUBLIC_FORM_CREATE"); + print ''; + print $form->selectyesno("MEMBER_SEARCH_MEMBER_PUBLIC_FORM_CREATE"); // Reverse the logic "hide -> show" for retrocompatibility + print "\n"; + print ''; print ''; diff --git a/htdocs/langs/en_US/members.lang b/htdocs/langs/en_US/members.lang index 9735fa94023..31fbff8f215 100644 --- a/htdocs/langs/en_US/members.lang +++ b/htdocs/langs/en_US/members.lang @@ -262,3 +262,6 @@ MergeMembers=Merge members ConfirmMergeMembers=Are you sure you want to merge the chosen member with the current one ? ErrorMembersMerge=There was an error when merging the members. Please check the log. Changes have been reverted. ConfirmCreateMember=Confirm create member +CorrespondingMemberFound=Corresponding member found +CorrespondingMemberFoundQuestion=A member has been found with the given information.
Do you want to renew your membership? +MEMBER_SEARCH_MEMBER_PUBLIC_FORM_CREATE=Searches for a member matching the information entered in the public member creation form. If a member is found, redirects the user to the membership payment form diff --git a/htdocs/public/members/new.php b/htdocs/public/members/new.php index 055f0700971..14a19156b76 100644 --- a/htdocs/public/members/new.php +++ b/htdocs/public/members/new.php @@ -194,6 +194,73 @@ if ($reshook < 0) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); } +// Verify if we can find member +if (empty($reshook) && getDolGlobalInt("MEMBER_SEARCH_MEMBER_PUBLIC_FORM_CREATE") && $action == 'add' && !GETPOSTISSET("nofetchmember")) { // Test on permission not required here + $memberfound = false; + if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED') && GETPOSTISSET('login')) { + $sql = "SELECT rowid as id"; + $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a"; + $sql .= " WHERE a.login = '".$db->escape(GETPOST('login'))."'"; + $sql .= " AND statut = 1"; + $sql .= " AND entity IN (".getEntity($object->element).")"; + $resql = $db->query($sql); + if ($resql) { + if ($db->num_rows($resql) == 1) { + $obj = $db->fetch_object($resql); + $object->fetch($obj->id); + $memberfound = true; + } + } else { + dol_print_error($db); + } + } + + if (!$memberfound && GETPOST("morphy") == 'mor' && GETPOSTISSET("societe") ) { + $sql = "SELECT a.rowid as id"; + $sql .= " FROM ".MAIN_DB_PREFIX."adherent as a"; + $sql .= " JOIN ".MAIN_DB_PREFIX."societe as s"; + $sql .= " ON a.fk_soc = s.rowid"; + $sql .= " WHERE s.nom = '".$db->escape(GETPOST("societe", 'alphanohtml'))."'"; + $sql .= " AND a.email = '".$db->escape(preg_replace('/\s+/', '', GETPOST("member_email", 'aZ09arobase')))."'"; + $sql .= " AND a.statut = 1"; + $sql .= " AND a.entity IN (".getEntity($object->element).")"; + $resql = $db->query($sql); + if ($resql) { + if ($db->num_rows($resql) == 1) { + $obj = $db->fetch_object($resql); + $object->fetch($obj->id); + $memberfound = true; + } + } else { + dol_print_error($db); + } + } + + if (!$memberfound && GETPOST("morphy") == 'phy' && GETPOSTISSET("lastname") && GETPOSTISSET("firstname") && !empty(GETPOST("member_email", 'aZ09arobase'))) { + $sql = "SELECT rowid as id"; + $sql .= " FROM ".MAIN_DB_PREFIX."adherent"; + $sql .= " WHERE firstname = '".$db->escape(GETPOST("firstname", 'alphanohtml'))."'"; + $sql .= " AND lastname = '".$db->escape(GETPOST("lastname", 'alphanohtml'))."'"; + $sql .= " AND email = '".$db->escape(preg_replace('/\s+/', '', GETPOST("member_email", 'aZ09arobase')))."'"; + $sql .= " AND statut = 1"; + $sql .= " AND entity IN (".getEntity($object->element).")"; + $resql = $db->query($sql); + if ($resql) { + if ($db->num_rows($resql) == 1) { + $obj = $db->fetch_object($resql); + $object->fetch($obj->id); + $memberfound = true; + } + } else { + dol_print_error($db); + } + } + + if ($memberfound) { + $action = 'subscription'; + } +} + // Action called when page is submitted if (empty($reshook) && $action == 'add') { // Test on permission not required here. This is an anonymous form. Check is done on constant to enable and mitigation. $error = 0; @@ -546,13 +613,21 @@ print ''; dol_htmloutput_errors($errmsg); dol_htmloutput_events(); +if ($action == "subscription") { + $urltocall = DOL_URL_ROOT.'/public/payment/newpayment.php?source=member&ref='.$object->id; + print $form->formconfirm($urltocall, $langs->trans("CorrespondingMemberFound"), $langs->trans("CorrespondingMemberFoundQuestion"), "confirm_subscription", '', 'no', 1); +} + // Print form print '
'."\n"; print ''; print ''; print ''; -if (getDolGlobalString('MEMBER_SKIP_TABLE') || getDolGlobalString('MEMBER_NEWFORM_FORCETYPE') || $action == 'create') { +if (getDolGlobalString('MEMBER_SKIP_TABLE') || getDolGlobalString('MEMBER_NEWFORM_FORCETYPE') || in_array($action, array('create', 'subscription'))) { + if ($action == 'subscription') { + print ''; + } print ''; print '
'; @@ -689,12 +764,14 @@ if (getDolGlobalString('MEMBER_SKIP_TABLE') || getDolGlobalString('MEMBER_NEWFOR $tdFirst.removeClass("fieldrequired"); break; - default: - $phyInput.prop({disabled: false, checked: false}); - $morInput.prop({disabled: false, checked: false}); - $span1.removeClass("member-individual-back").addClass("nonature-back"); - $span2.removeClass("member-company-back").addClass("nonature-back"); - } + default:'; + if ($action != "subscription") { + print ' $phyInput.prop({disabled: false, checked: false}); + $morInput.prop({disabled: false, checked: false}); + $span1.removeClass("member-individual-back").addClass("nonature-back"); + $span2.removeClass("member-company-back").addClass("nonature-back");'; + } + print'} }); // Initial state