200 global
$conf, $langs;
206 if (!empty(
$conf->use_javascript_ajax)) {
207 print
"\n".
'<!-- Includes JS Footer of Dolibarr -->'.
"\n";
208 print
'<script src="'.DOL_URL_ROOT.
'/core/js/lib_foot.js.php?lang='.$langs->defaultlang.
'"></script>'.
"\n";
222$parameters = array();
224$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
226 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
231if (empty($reshook) &&
getDolGlobalInt(
"MEMBER_SEARCH_MEMBER_PUBLIC_FORM_CREATE") && $action ==
'add' && !
GETPOSTISSET(
"nofetchmember")) {
232 $memberfound =
false;
237 $sql =
"SELECT rowid as id";
238 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent as a";
239 $sql .=
" WHERE a.login = '".$db->escape(
GETPOST(
'login')).
"'";
240 $sql .=
" AND statut = 1";
241 $sql .=
" AND entity IN (".getEntity(
$object->element).
")";
242 $resql = $db->query($sql);
244 if ($db->num_rows($resql) == 1) {
245 $obj = $db->fetch_object($resql);
250 dol_print_error($db);
255 $sql =
"SELECT a.rowid as id";
256 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent as a";
257 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"societe as s";
258 $sql .=
" ON a.fk_soc = s.rowid";
259 $sql .=
" WHERE s.nom = '".$db->escape(
GETPOST(
"societe",
'alphanohtml')).
"'";
260 $sql .=
" AND a.email = '".$db->escape(preg_replace(
'/\s+/',
'',
GETPOST(
"member_email",
'aZ09arobase'))).
"'";
261 $sql .=
" AND a.statut = 1";
262 $sql .=
" AND a.entity IN (".getEntity(
$object->element).
")";
263 $resql = $db->query($sql);
265 if ($db->num_rows($resql) == 1) {
266 $obj = $db->fetch_object($resql);
271 dol_print_error($db);
276 $sql =
"SELECT rowid as id";
277 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent";
278 $sql .=
" WHERE firstname = '".$db->escape(
GETPOST(
"firstname",
'alphanohtml')).
"'";
279 $sql .=
" AND lastname = '".$db->escape(
GETPOST(
"lastname",
'alphanohtml')).
"'";
280 $sql .=
" AND email = '".$db->escape(preg_replace(
'/\s+/',
'',
GETPOST(
"member_email",
'aZ09arobase'))).
"'";
281 $sql .=
" AND statut = 1";
282 $sql .=
" AND entity IN (".getEntity(
$object->element).
")";
283 $resql = $db->query($sql);
285 if ($db->num_rows($resql) == 1) {
286 $obj = $db->fetch_object($resql);
291 dol_print_error($db);
296 $action =
'subscription';
301if (empty($reshook) && $action ==
'add') {
307 $morphy =
GETPOST(
"morphy",
'alphanohtml');
308 $lastname =
GETPOST(
"lastname",
'alphanohtml');
309 $firstname =
GETPOST(
"firstname",
'alphanohtml');
310 $societe =
GETPOST(
"societe",
'alphanohtml');
311 $email = preg_replace(
'/\s+/',
'',
GETPOST(
"member_email",
'aZ09arobase'));
313 $country_id = $forcecountry ? (int)
getCountry($forcecountry,
'3', $db, $langs) :
GETPOSTINT(
'country_id');
315 if (!in_array($morphy, array(
'mor',
'phy'))) {
317 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
'MemberNature')).
"<br>\n";
322 if (!
GETPOST(
'member_email')) {
324 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"EMail")).
"<br>\n";
328 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Login")).
"<br>\n";
330 $sql =
"SELECT login FROM ".MAIN_DB_PREFIX.
"adherent WHERE login = '".$db->escape(
GETPOST(
'login')).
"'";
331 $result = $db->query($sql);
333 $num = $db->num_rows($result);
337 $langs->load(
"errors");
338 $errmsg .= $langs->trans(
"ErrorLoginAlreadyExists").
"<br>\n";
342 $langs->load(
"errors");
343 $errmsg .= $langs->trans(
"ErrorPasswordsMustMatch").
"<br>\n";
348 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")).
"<br>\n";
353 if (!array_key_exists(
GETPOSTINT(
'typeid'), $tmpadht->liste_array(1))) {
355 $errmsg .= $langs->trans(
"ErrorBadValueForParameter",
GETPOSTINT(
'typeid'), $langs->transnoentitiesnoconv(
"Type")).
"<br>\n";
359 if ($morphy && $morphy !=
'mor' && empty($lastname)) {
361 $langs->load(
"errors");
362 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Lastname"));
364 if ($morphy && $morphy !=
'mor' && (!isset($firstname) || $firstname ==
'')) {
366 $langs->load(
"errors");
367 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Firstname"));
369 if ($morphy ==
'mor' && empty($societe)) {
371 $langs->load(
"errors");
372 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Company"));
374 if (empty($country_id)) {
376 $langs->load(
"errors");
377 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Country"));
381 $langs->load(
"errors");
382 $errmsg .= $langs->trans(
"ErrorBadEMail", $email);
385 if (
GETPOST(
"birthmonth") && empty($birthday)) {
387 $langs->load(
"errors");
388 $errmsg .= $langs->trans(
"ErrorBadDateFormat").
"<br>\n";
395 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"TurnoverOrBudget")).
"<br>\n";
401 if (
getDolGlobalString(
'MAIN_SECURITY_ENABLECAPTCHA_MEMBER') && is_object($captchaobj)) {
402 if (method_exists($captchaobj,
'validateCodeAfterLoginSubmit')) {
403 $ok = $captchaobj->validateCodeAfterLoginSubmit();
405 print
'Error, the captcha handler '.get_class($captchaobj).
' does not have any method validateCodeAfterLoginSubmit()';
409 $langs->load(
"errors");
410 $errmsg .= $langs->trans(
"ErrorBadValueForCode").
"<br>\n";
422 $adh->public = $public;
423 $adh->firstname =
GETPOST(
'firstname');
424 $adh->lastname =
GETPOST(
'lastname');
425 $adh->gender =
GETPOST(
'gender');
426 $adh->civility_id =
GETPOST(
'civility_id');
427 $adh->company =
GETPOST(
'societe');
428 $adh->societe = $adh->company;
429 $adh->address =
GETPOST(
'address');
430 $adh->zip =
GETPOST(
'zipcode');
432 $adh->email =
GETPOST(
'member_email',
'aZ09arobase');
434 $adh->login =
GETPOST(
'login');
435 $adh->pass =
GETPOST(
'pass1',
'password');
437 $adh->photo =
GETPOST(
'photo');
438 $adh->country_id = $country_id;
441 $adh->note_private =
GETPOST(
'note_private');
443 $adh->birth = $birthday;
444 $adh->phone =
GETPOST(
'phone');
445 $adh->phone_perso =
GETPOST(
'phone_perso');
446 $adh->phone_mobile =
GETPOST(
'phone_mobile');
450 $nb_post_max =
getDolGlobalInt(
"MAIN_SECURITY_MAX_POST_ON_PUBLIC_PAGES_BY_IP_ADDRESS", 200);
455 if ($nb_post_max > 0) {
456 $sql =
"SELECT COUNT(ref) as nb_adh";
457 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent";
458 $sql .=
" WHERE ip = '".$db->escape($adh->ip).
"'";
459 $sql .=
" AND datec > '".$db->idate($minmonthpost).
"'";
460 $resql = $db->query($sql);
462 $num = $db->num_rows($resql);
466 $obj = $db->fetch_object($resql);
467 $nb_post_ip = $obj->nb_adh;
474 $extrafields->fetch_name_optionals_label($adh->table_element);
475 $ret = $extrafields->setOptionalsFromPost(
null, $adh);
478 $errmsg .= $adh->error;
481 if ($nb_post_max > 0 && $nb_post_ip >= $nb_post_max) {
483 $langs->load(
'errors');
484 $errmsg .= $langs->trans(
"AlreadyTooMuchPostOnThisIPAdress");
485 array_push($adh->errors, $langs->trans(
"AlreadyTooMuchPostOnThisIPAdress"));
489 $result = $adh->create($user);
491 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
502 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
506 $outputlangs->setDefaultLang(!empty(
$object->default_lang) ?
$object->default_lang : (empty(
$object->thirdparty->default_lang) ?
$mysoc->default_lang :
$object->thirdparty->default_lang));
508 $outputlangs->loadLangs(array(
"main",
"members"));
510 $arraydefaultmessage =
null;
513 if (!empty($labeltouse)) {
514 $arraydefaultmessage = $formmail->getEMailTemplate($db,
'member', $user, $outputlangs, 0, 1, $labeltouse);
517 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
518 $subject = $arraydefaultmessage->topic;
519 $msg = $arraydefaultmessage->content;
522 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0,
null, $object);
527 if ($subjecttosend && $texttosend) {
528 $moreinheader =
'X-Dolibarr-Info: send_an_email by public/members/new.php'.
"\r\n";
530 $result =
$object->sendEmail($texttosend, $subjecttosend, array(), array(), array(),
"",
"", 0, -1,
'', $moreinheader);
542 $appli = constant(
'DOL_APPLICATION_TITLE');
545 if (preg_match(
'/\d\.\d/', $appli)) {
546 if (!preg_match(
'/'.preg_quote(DOL_VERSION,
'/').
'/', $appli)) {
547 $appli .=
" (".DOL_VERSION.
")";
550 $appli .=
" ".DOL_VERSION;
553 $appli .=
" ".DOL_VERSION;
572 if (!$mailfile->sendfile()) {
573 dol_syslog($langs->trans(
"ErrorFailedToSendMail", $email_from, $to), LOG_ERR);
580 $result = $company->create_from_member($adh);
583 $errmsg .= implode(
'<br>', $company->errors);
587 if (!empty($backtopage)) {
588 $urlback = $backtopage;
593 $urlback = $_SERVER[
"PHP_SELF"].
"?action=added&token=".
newToken();
597 if (empty($adht->caneditamount)) {
602 $minimumamountbytype = $adht->minimumamountbytype(1);
603 $minimumamount = empty($minimumamountbytype[$adh->typeid]) ? 0 : $minimumamountbytype[$adh->typeid];
605 $urlback = getOnlinePaymentUrl(0,
'member', $adh->ref, (
float) $amount,
'', 0);
606 if ($amount < max(
getDolGlobalInt(
"MEMBER_MIN_AMOUNT"), $minimumamount)) {
608 $errmsg .= $langs->trans(
"MinimumAmountShort").
" : ".
price(max(
getDolGlobalInt(
"MEMBER_MIN_AMOUNT"), $minimumamount), 0, $langs, 1, -1, -1,
$conf->currency).
"<br>\n";
612 $urlback .=
'&email='.urlencode(
GETPOST(
'member_email'));
615 $urlback .=
'&paymentmethod='.urlencode(
getDolGlobalString(
'MEMBER_NEWFORM_PAYONLINE'));
618 if (!empty($entity)) {
619 $urlback .=
'&entity='.((int) $entity);
624 $errmsg .= implode(
'<br>', $adh->errors);
632 header(
"Location: ".$urlback);
644if (empty($reshook) && $action ==
'added') {
649 print
'<div class="center">';
650 print $langs->trans(
"NewMemberbyWeb");
662$form =
new Form($db);
665$extrafields->fetch_name_optionals_label(
$object->table_element);
671print
load_fiche_titre(img_picto(
'',
'member_nocolor',
'class="pictofixedwidth"').
' '.$langs->trans(
"NewSubscription"),
'',
'', 0,
'',
'center');
674print
'<div align="center">';
675print
'<div id="divsubscribe">';
677print
'<div class="center subscriptionformhelptext opacitylow justify small margintoponly"><br>';
681 print $langs->trans(
"NewSubscriptionDesc",
getDolGlobalString(
"MAIN_INFO_SOCIETE_MAIL")).
"<br>\n";
689if ($action ==
"subscription") {
690 $urltocall = DOL_URL_ROOT.
'/public/payment/newpayment.php?source=member&ref='.
$object->id;
691 print $form->formconfirm($urltocall, $langs->trans(
"CorrespondingMemberFound"), $langs->trans(
"CorrespondingMemberFoundQuestion"),
"confirm_subscription",
'',
'no', 1);
695print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" name="newmember" id="newmember">'.
"\n";
696print
'<input type="hidden" name="token" value="'.newToken().
'" />';
697print
'<input type="hidden" name="entity" value="'.$entity.
'" />';
698print
'<input type="hidden" name="page_y" value="" />';
701 if ($action ==
'subscription') {
702 print
'<input type="hidden" name="nofetchmember" value="nofetchmember" />';
704 print
'<input type="hidden" name="action" value="add" />';
713 if (
$conf->use_javascript_ajax) {
714 print
"\n".
'<script type="text/javascript">'.
"\n";
715 print
'jQuery(document).ready(function () {
716 jQuery("#selectcountry_id").change(function() {
717 console.log("We change country, so we reload page");
718 document.newmember.action.value="create";
719 jQuery("#newmember").submit();
721 function initfieldrequired() {
722 console.log("initfieldrequired");
723 jQuery("#tdcompany").removeClass("fieldrequired");
724 jQuery("#tdlastname").removeClass("fieldrequired");
725 jQuery("#tdfirstname").removeClass("fieldrequired");
726 if (jQuery(\'input[name="morphy"]:checked\').val() == \'mor\') {
727 jQuery("#tdcompany").addClass("fieldrequired");
729 if (jQuery(\'input[name="morphy"]:checked\').val() == \'phy\') {
730 jQuery("#tdlastname").addClass("fieldrequired");
731 jQuery("#tdfirstname").addClass("fieldrequired");
734 jQuery(\'input[name="morphy"]\').change(function() {
739 print
'</script>'.
"\n";
742 print
'<table class="border" summary="form to subscribe" id="tablesubscribe">'.
"\n";
747 print
'<tr><td class="fieldrequired titlefieldmiddle">'.$langs->trans(
"MemberType").
'</td><td>';
748 $listetype = $adht->liste_array(1);
749 print img_picto(
'', $adht->picto,
'class="pictofixedwidth"');
750 if (count($listetype)) {
751 print $form->selectarray(
"typeid", $listetype, (
GETPOSTINT(
'typeid') ?
GETPOSTINT(
'typeid') : $typeid), (count($listetype) > 1 ? 1 : 0), 0, 0,
'', 0, 0, 0,
'',
'minwidth150 maxwidth300 widthcentpercentminusx', 1);
753 print
'<span class="error">'.$langs->trans(
"NoTypeDefinedGoToSetup").
'</span>';
755 print
'</td></tr>'.
"\n";
758 print
'<input type="hidden" id="typeid" name="typeid" value="' .
getDolGlobalString(
'MEMBER_NEWFORM_FORCETYPE').
'">';
763 "phy" => $langs->trans(
"Physical"),
764 "mor" => $langs->trans(
"Moral"),
766 $checkednature =
GETPOST(
"morphy",
'alpha');
767 $listetype_natures = $adht->morphyByType(1);
768 $listetype_natures_json = json_encode($listetype_natures);
771 if (empty($checkednature) && !empty($listetype_natures[
GETPOSTINT(
'typeid')])) {
772 $checkednature = $listetype_natures[
GETPOSTINT(
'typeid')];
775 print
'<tr><td class="fieldrequired titlefieldmiddle">'.$langs->trans(
"MemberNature").
"</td><td>\n";
781 print
'<span id="spannature1" class="nonature-back spannature paddinglarge marginrightonly"><label for="phisicalinput" class="valignmiddle">'.$morphys[
"phy"].
'<input id="phisicalinput" class="flat checkforselect marginleftonly valignmiddle" type="radio" name="morphy" value="phy"'.($checkednature ==
"phy" ?
' checked="checked"' :
'').$disabledphy.
'></label></span>';
782 print
'<span id="spannature2" class="nonature-back spannature paddinglarge marginrightonly"><label for="moralinput" class="valignmiddle">'.$morphys[
"mor"].
'<input id="moralinput" class="flat checkforselect marginleftonly valignmiddle" type="radio" name="morphy" value="mor"'.($checkednature ==
"mor" ?
' checked="checked"' :
'').$disabledmor.
'></label></span>';
785 if (
$conf->use_javascript_ajax) {
787 var listetype_natures = '.$listetype_natures_json.
';
790 function refreshNatureCss() {
791 $(".spannature").each(function(index) {
792 let $span = $("#spannature" + (index + 1));
793 let checked = $span.find(".checkforselect").is(":checked");
797 $span.addClass("member-individual-back").removeClass("nonature-back member-company-back");
798 } else if (index === 1) {
799 $span.addClass("member-company-back").removeClass("nonature-back member-individual-back");
802 $span.removeClass("member-individual-back member-company-back")
803 .addClass("nonature-back");
808 $(".spannature").on("click", function() {
809 console.log("Nature clicked");
813 $("#typeid").on("change", function() {
814 console.log("Type of membership is modified");
815 let morphy = listetype_natures[$(this).val()];
816 console.log("morphy="+morphy);
818 let $phyInput = $("#phisicalinput");
819 let $morInput = $("#moralinput");
820 let $tdLast = $("#tdlastname");
821 let $tdFirst = $("#tdfirstname");
822 let $tdCompany = $("#tdcompany");
823 let $span1 = $("#spannature1");
824 let $span2 = $("#spannature2");
828 $phyInput.prop({disabled: false, checked: true});
829 $morInput.prop({disabled: true, checked: false});
830 $span1.addClass("member-individual-back").removeClass("nonature-back");
831 $span2.removeClass("member-company-back").addClass("nonature-back");
832 $("#phisicalinput").prop("checked", true);
833 $tdLast.addClass("fieldrequired");
834 $tdFirst.addClass("fieldrequired");
835 $tdCompany.removeClass("fieldrequired");
839 $phyInput.prop({disabled: true, checked: false});
840 $morInput.prop({disabled: false, checked: true});
841 $span2.addClass("member-company-back").removeClass("nonature-back");
842 $span1.removeClass("member-individual-back").addClass("nonature-back");
843 $("#moralinput").prop("checked", true);
844 $tdCompany.addClass("fieldrequired");
845 $tdLast.removeClass("fieldrequired");
846 $tdFirst.removeClass("fieldrequired");
850 $phyInput.prop({disabled: false});
851 $morInput.prop({disabled: false});';
852 if ($action !=
"subscription" && !
GETPOST(
'morphy')) {
854 $phyInput.prop({checked: false});
855 $morInput.prop({checked: false});
856 $span1.removeClass("member-individual-back").addClass("nonature-back");
857 $span2.removeClass("member-company-back").addClass("nonature-back");';
867 print
'</td></tr>'.
"\n";
870 print
'<input type="hidden" id="morphy" name="morphy" value="' .
getDolGlobalString(
'MEMBER_NEWFORM_FORCEMORPHY').
'">';
874 print
'<tr id="trcompany" class="trcompany"><td id="tdcompany" class="titlefieldmiddle paddingrightonly'.($checkednature ==
"mor" ?
' fieldrequired"' :
'').
'">'.$langs->trans(
"Company").
'</td><td>';
875 print img_picto(
'',
'company',
'class="pictofixedwidth paddingright"');
876 print
'<input type="text" name="societe" class="minwidth150 widthcentpercentminusx" value="'.dol_escape_htmltag(
GETPOST(
'societe')).
'"></td></tr>'.
"\n";
880 print
'<tr><td>'.$langs->trans(
'UserTitle').
'</td><td>';
881 print $formcompany->select_civility(
GETPOST(
'civility_id'),
'civility_id').
'</td></tr>'.
"\n";
885 print
'<tr><td id="tdfirstname" class="classfortooltip'.($checkednature ==
"phy" ?
' fieldrequired"' :
'').
'">'.$langs->trans(
"Firstname").
'</td><td><input type="text" name="firstname" class="minwidth150" value="'.
dol_escape_htmltag(
GETPOST(
'firstname')).
'" spellcheck="false"></td></tr>'.
"\n";
888 print
'<tr><td id="tdlastname" class="classfortooltip'.($checkednature ==
"phy" ?
' fieldrequired"' :
'').
'">'.$langs->trans(
"Lastname").
'</td><td><input type="text" name="lastname" class="minwidth150" value="'.
dol_escape_htmltag(
GETPOST(
'lastname')).
'" spellcheck="false"></td></tr>'.
"\n";
891 print
'<tr><td>'.(getDolGlobalString(
'ADHERENT_MAIL_REQUIRED') ?
'<span class="fieldrequired">' :
'').$langs->trans(
"EMail").(getDolGlobalString(
'ADHERENT_MAIL_REQUIRED') ?
'</span>' :
'').
'</td>';
892 print
'<td>'.img_picto(
'',
'object_email').
' <input type="text" name="member_email" class="minwidth150 maxwidth300 widthcentpercentminusx" maxlength="255" value="'.
dol_escape_htmltag(
GETPOST(
'member_email',
"aZ09arobase")).
'" spellcheck="false"></td></tr>'.
"\n";
896 print
'<tr><td><span class="fieldrequired">'.$langs->trans(
"Login").
' / '.$langs->trans(
"Id").
'</span></td><td><input type="text" name="login" maxlength="50" class="minwidth100" value="'.(
GETPOSTISSET(
"login") ?
GETPOST(
"login",
'alphanohtml', 2) :
$object->login).
'"></td></tr>'.
"\n";
897 print
'<tr><td><span class="fieldrequired">'.$langs->trans(
"Password").
'</span></td><td><input type="password" maxlength="128" name="pass1" class="minwidth100" value="'.
dol_escape_htmltag(
GETPOST(
"pass1",
"none", 2)).
'"></td></tr>'.
"\n";
898 print
'<tr><td><span class="fieldrequired">'.$langs->trans(
"PasswordRetype").
'</span></td><td><input type="password" maxlength="128" name="pass2" class="minwidth100" value="'.
dol_escape_htmltag(
GETPOST(
"pass2",
"none", 2)).
'"></td></tr>'.
"\n";
902 print
'<tr><td>'.$langs->trans(
"Gender").
'</td>';
904 $arraygender = array(
'man' => $langs->trans(
"Genderman"),
'woman' => $langs->trans(
"Genderwoman"),
'other' => $langs->trans(
"Genderother"));
905 print $form->selectarray(
'gender', $arraygender,
GETPOST(
'gender',
'alphanohtml'), 1, 0, 0,
'', 0, 0, 0,
'',
'minwidth150 maxwidth300 widthcentpercentminusx', 1);
909 print
'<tr><td>'.$langs->trans(
"Address").
'</td><td>'.
"\n";
910 print
'<textarea name="address" id="address" wrap="soft" class="quatrevingtpercent" rows="'.ROWS_3.
'">'.
dol_escape_htmltag(
GETPOST(
'address',
'restricthtml'), 0, 1).
'</textarea></td></tr>'.
"\n";
913 print
'<tr><td>'.$langs->trans(
'Zip').
' / '.$langs->trans(
'Town').
'</td><td>';
914 print $formcompany->select_ziptown(
GETPOST(
'zipcode'),
'zipcode', array(
'town',
'selectcountry_id',
'state_id'), 0, 1,
'',
'width75');
916 print $formcompany->select_ziptown(
GETPOST(
'town'),
'town', array(
'zipcode',
'selectcountry_id',
'state_id'), 0, 1);
922 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Country').
'</td><td>';
923 print img_picto(
'',
'country',
'class="pictofixedwidth paddingright"');
927 if (!$country_id && !empty(
$conf->geoipmaxmind->enabled)) {
931 $new_country_id =
getCountry($country_code,
'3', $db, $langs);
933 if ($new_country_id) {
934 $country_id = $new_country_id;
938 $country_code =
getCountry($country_id,
'2', $db, $langs);
939 print $form->select_country($country_id,
'country_id',
'', 0,
'minwidth150 maxwidth300 widthcentpercentminusx reposition');
944 print
'<tr><td>'.$langs->trans(
'State').
'</td><td>';
946 print img_picto(
'',
'state',
'class="pictofixedwidth paddingright"');
947 print $formcompany->select_state(
GETPOSTINT(
"state_id"), $country_code,
'state_id',
'minwidth150 maxwidth300 widthcentpercentminusx');
953 print
'<tr><td>'.$langs->trans(
"PhonePro").
'</td>';
954 print
'<td>'.$form->showPhoneInput(
GETPOST(
'phone'),
'phone', $country_id,
'object_phoning',
'maxwidth300 widthcentpercentminusx').
'</td></tr>';
957 print
'<tr><td>'.$langs->trans(
"PhonePerso").
'</td>';
958 print
'<td>'.$form->showPhoneInput(
GETPOST(
'phone_perso'),
'phone_perso', $country_id,
'object_phoning',
'maxwidth300 widthcentpercentminusx').
'</td></tr>';
961 print
'<tr><td>'.$langs->trans(
"PhoneMobile").
'</td>';
962 print
'<td>'.$form->showPhoneInput(
GETPOST(
'phone_mobile'),
'phone_mobile', $country_id,
'object_phoning_mobile',
'maxwidth300 widthcentpercentminusx').
'</td></tr>';
965 print
'<tr id="trbirth" class="trbirth"><td>'.$langs->trans(
"DateOfBirth").
'</td><td>';
966 print $form->selectDate(!empty($birthday) ? $birthday :
"",
'birth', 0, 0, 1,
"newmember", 1, 0);
967 print
'</td></tr>'.
"\n";
970 print
'<tr><td>'.$langs->trans(
"URLPhoto").
'</td><td><input type="text" name="photo" class="minwidth150" value="'.
dol_escape_htmltag(
GETPOST(
'photo')).
'"></td></tr>'.
"\n";
974 $linkofpubliclist = DOL_MAIN_URL_ROOT.
'/public/members/public_list.php'.((
isModEnabled(
'multicompany')) ?
'?entity='.
$conf->entity :
'');
975 $publiclabel = $langs->trans(
"Public",
getDolGlobalString(
'MAIN_INFO_SOCIETE_NOM'), $linkofpubliclist);
976 print
'<tr><td>'.$form->textwithpicto($langs->trans(
"MembershipPublic"), $publiclabel).
'</td><td><input type="checkbox" name="public"></td></tr>'.
"\n";
980 $parameters[
'tpl_context'] =
'public';
981 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_add.tpl.php';
985 print
'<td class="tdtop"></td>';
986 print
'<td class="tdtop"><textarea placeholder="'.dolPrintHTML($langs->trans(
"Comments")).
'" name="note_private" id="note_private" wrap="soft" class="quatrevingtpercent" rows="'.ROWS_3.
'">'.
dol_escape_htmltag(
GETPOST(
'note_private',
'restricthtml'), 0, 1).
'</textarea></td>';
993 $adht->fetch($typeid);
994 $caneditamount = $adht->caneditamount;
995 $amountbytype = $adht->amountByType(1);
996 $minimumamountbytype = $adht->minimumamountbytype(1);
997 foreach ($amountbytype as $k => $v) {
998 $amount = max(0, (
float) $v, (
float)
getDolGlobalInt(
"MEMBER_MIN_AMOUNT"), $minimumamountbytype[$k]);
999 $amountbytype[$k] = $amount;
1002 $caneditamountbytype = $adht->caneditamountByType(1);
1003 $amountformuladescriptionbytype = $adht->amountformuladescriptionbytype(1);
1007 $amount = empty($amountbytype[$typeid]) ? 0 : $amountbytype[$typeid];
1009 if (empty($amount)) {
1013 $minimumamount = empty($minimumamountbytype[$typeid]) ? 0 : $minimumamountbytype[$typeid];
1014 $amount = max(0, (
float) $amount, (
float)
getDolGlobalInt(
"MEMBER_MIN_AMOUNT"), (
float) $minimumamount);
1021 $parameters = array(
'country_id' => $country_id,
'mode' =>
'new');
1022 $reshook = $hookmanager->executeHooks(
'membershipNewSubscriptionPublicForm', $parameters, $object, $action);
1024 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
1029 $s = $langs->trans(
"AreYouAPreferredPartner",
'<a href="https://partners.dolibarr.org" target="_blank">{s1}</a>');
1030 $s = str_replace(
'{s1}',
'Preferred Partner', $s);
1031 print
'<tr id="trbudget" class="trcompany"><td class="paddingrightonly"><label for="pp" class="small">'.$s.
'</label></td><td>';
1032 print
'<input type="checkbox" name="pp" id="pp" value="1"'.(GETPOST(
'pp') ?
' checked="checked"' :
'').
' class="reposition">';
1035 print
'<tr id="trbudget" class="trcompany"><td class="fieldrequired paddingrightonly"><span class="small">'.$langs->trans(
"TurnoverOrBudget").
'</span></td><td>';
1037 $country_code =
dol_getIdFromCode($db, $country_id,
'c_country',
'rowid',
'code');
1038 if ($country_code ===
'FR' && $checkednature ===
'mor' &&
GETPOST(
'pp')) {
1039 print
'<input type="text" name="budget" id="budget" class="flat turnover right width100" value="'.GETPOST(
'budget').
'" required>';
1041 $arraybudget = array(
'50' =>
'<= 100 000',
'100' =>
'<= 200 000',
'200' =>
'<= 500 000',
'300' =>
'<= 1 500 000',
'600' =>
'<= 3 000 000',
'1000' =>
'<= 5 000 000',
'2000' =>
'5 000 000+');
1042 print $form->selectarray(
'budget', $arraybudget,
GETPOSTINT(
'budget'), 1, 0, 0,
'', 0, 0, 0,
'');
1046 print
'<script type="text/javascript">
1047 jQuery(document).ready(function() {
1050 newamount = initturnover();
1051 jQuery("#amount").val(newamount);
1055 jQuery("#selectcountry_id").change(function() {
1056 console.log("We change country (code added for association, replace common code), so we reload page");
1057 jQuery("#budget").val(\'\');
1058 jQuery("#amount").val(\'\');
1059 jQuery("#amounthidden").val(\'\');
1061 jQuery("#phisicalinput,#moralinput").click(function() {
1062 console.log("We change the nature of membership");
1063 newamount = initturnover();
1064 jQuery("#amount").val(newamount);
1066 jQuery("#pp").change(function() {
1067 console.log("We change the preferred partner status");
1068 selectcountry_id = jQuery("#selectcountry_id").val();
1069 morphy = jQuery("#moralinput").is(\':checked\') ? \'mor\' : \'phy\';
1070 jQuery("#budget").val(\'\');
1071 jQuery("#amount").val(\'\');
1072 jQuery("#amounthidden").val(\'\');
1073 document.newmember.action.value="create";
1074 jQuery("#newmember").submit();
1076 jQuery("#budget").change(function() {
1077 console.log("Turnover amount has been modified on change");
1078 newamount = initturnover();
1079 jQuery("#amount").val(newamount);
1080 jQuery("#amounthidden").val(newamount);
1082 jQuery("#budget").keyup(function() {
1083 console.log("Turnover amount has been modified on keyup");
1084 newamount = initturnover();
1085 jQuery("#amount").val(newamount);
1086 jQuery("#amounthidden").val(newamount);
1089 function initturnover() {
1092 morphy = jQuery("#moralinput").is(\':checked\') ? \'mor\' : \'phy\';
1093 selectcountry_id = jQuery("#selectcountry_id").val();
1094 pp = jQuery("#pp").is(\':checked\') ? true : false;
1095 console.log("Set fields according to nature and other properties");
1096 console.log("morphy="+morphy);
1097 console.log("selectcountry_id="+selectcountry_id);
1098 console.log("pp="+pp);
1100 if (morphy == \'phy\') {
1101 jQuery(".amount").val('.((float) $amount).
');
1102 jQuery("#trbirth").show();
1103 jQuery(".trcompany").hide();
1104 jQuery(".trbudget").hide();
1105 newamount = '.((float) $amount).
';
1107 jQuery(".amount").val(\'\');
1108 jQuery("#trbirth").hide();
1109 jQuery(".trcompany").show();
1110 jQuery(".trbudget").show();
1111 jQuery(".hideifautoturnover").hide();
1113 jQuery("#budget").val(\'\');
1116 if (selectcountry_id == 1) {
1118 console.log("value selected in input text field is "+jQuery("#budget").val());
1119 newamount = Math.max(Math.round(price2numjs(jQuery("#budget").val()) * 0.005), 50);
1120 console.log("newamount = "+newamount);
1122 console.log("not a pp");
1123 if (jQuery("#budget").val() > 0) {
1124 console.log("value found in budget is "+jQuery("#budget").val());
1125 newamount = jQuery("#budget").val();
1127 jQuery("#budget").val(\'\');
1132 if (jQuery("#budget").val() > 0) {
1133 newamount = jQuery("#budget").val();
1135 jQuery("#budget").val(\'\');
1138 console.log("newamount="+newamount);
1146 print
'</td></tr>'.
"\n";
1150 print
'<tr><td>'.$langs->trans(
"Subscription");
1153 print
'<a href="' .
getDolGlobalString(
'MEMBER_EXT_URL_SUBSCRIPTION_INFO').
'" rel="external" target="_blank" rel="noopener noreferrer">';
1154 print img_picto(
'',
'url',
'class="pictofixedwidth"').$langs->trans(
"SeeHere");
1157 print
'</td><td class="nowrap">';
1159 $amountformuladescription = $amountformuladescriptionbytype[$typeid];
1161 $showedamount = $amount > 0 ? $amount : 0;
1162 if ($caneditamount ===
"1") {
1163 print
'<input type="text" name="amount" id="amount" class="flat amount right width75" value="'.$showedamount.
'">';
1164 print
'<input type="text" name="amount" id="amounthidden" class="flat amount width75 hidden" disabled value="'.$showedamount.
'">';
1165 print
' '.$langs->getCurrencySymbol(
$conf->currency).
'<span class="opacitymedium amountdescription hideifautoturnover small">';
1168 if (empty($amountformuladescription)) {
1169 print $amount > 0 ? $langs->trans(
"AnyAmountWithAdvisedAmount",
price($amount, 0, $langs, 1, -1, -1,
$conf->currency)) : $langs->trans(
"AnyAmountWithoutAdvisedAmount");
1171 print $amountformuladescription;
1175 print
'</span><br><span id="minimumamount" class="opacitymedium small">'.$langs->trans(
"MinimumAmountShort").
' : '.
price(max(
getDolGlobalInt(
"MEMBER_MIN_AMOUNT"), $minimumamount), 0, $langs, 1, -1, -1,
$conf->currency);
1179 print
'<input type="text" name="amount" id="amount" class="flat amount width75 right hidden" value="'.$showedamount.
'">';
1180 print
'<input type="text" name="amount" id="amounthidden" class="flat amount width75" disabled value="'.$showedamount.
'">';
1181 print
' '.$langs->getCurrencySymbol(
$conf->currency).
'<span class="opacitymedium amountdescription hideifautoturnover hidden small">';
1184 print $amount > 0 ? $langs->trans(
"AnyAmountWithAdvisedAmount",
price($amount, 0, $langs, 1, -1, -1,
$conf->currency)) : $langs->trans(
"AnyAmountWithoutAdvisedAmount");
1192 if (
getDolGlobalString(
'MAIN_SECURITY_ENABLECAPTCHA_MEMBER') && is_object($captchaobj)) {
1193 print
'<tr><td><label><span class="fieldrequired">'.$langs->trans(
"SecurityCode").
'</span></label></td><td><br>';
1194 if (method_exists($captchaobj,
'getCaptchaCodeForForm')) {
1195 print $captchaobj->getCaptchaCodeForForm(
'');
1197 print
'Error, the captcha handler '.get_class($captchaobj).
' does not have any method getCaptchaCodeForForm()';
1199 print
'<br></td></tr>';
1207 print
'<div class="center">';
1208 print
'<input type="submit" value="'.$langs->trans(
"GetMembershipButtonLabel").
'" id="submitsave" class="button">';
1209 if (!empty($backtopage)) {
1210 print
' <input type="submit" value="'.$langs->trans(
"Cancel").
'" id="submitcancel" class="button button-cancel">';
1217 $adht->fetch($typeid);
1218 $caneditamountbytype = $adht->caneditamountByType(1);
1219 $minimumamountbytype = $adht->minimumamountbytype(1);
1220 $amountbytype = $adht->amountByType(1);
1221 $amountformuladescriptionbytype = $adht->amountformuladescriptionbytype(1);
1223 $caneditamountbytype_json = json_encode($caneditamountbytype);
1224 $minimumamountbytype_json = json_encode($minimumamountbytype);
1225 $amountbytype_json = json_encode($amountbytype);
1226 $amountformuladescriptionbytype_json = json_encode($amountformuladescriptionbytype);
1227 $currencysymbol = $langs->getCurrencySymbol(
$conf->currency);
1229 if (
$conf->use_javascript_ajax) {
1231 // ----- Shared data -----
1232 var amountByType = ' . $amountbytype_json .
';
1233 var canEditAmountByType = ' . $caneditamountbytype_json .
';
1234 var amountFormulaDescriptionByType = ' . $amountformuladescriptionbytype_json .
';
1235 var minimumAmountByType = ' . $minimumamountbytype_json .
';
1237 var currencySymbol = ' . json_encode($currencysymbol) .
';
1239 // Translations prepared by PHP
1241 AnyAmountWithAdvisedAmount: ' . json_encode($langs->trans(
"AnyAmountWithAdvisedAmount",
"__VAL__")) .
',
1242 AnyAmountWithoutAdvisedAmount: ' . json_encode($langs->trans(
"AnyAmountWithoutAdvisedAmount")) .
',
1243 MinimumAmountShort: ' . json_encode($langs->trans(
"MinimumAmountShort",
"__VAL__")) .
',
1244 trans: function(key, val) {
1245 if (!this[key]) return key;
1246 return this[key].replace("__VAL__", val || "");
1250 jQuery(function($) {
1251 // ----- Helpers -----
1252 function getCurrentMin() {
1253 let typeId = $("#typeid").val() || 0;
1254 let minimumAmount = minimumAmountByType[typeId] || 0;
1255 return Math.max(memberMinAmount, minimumAmount);
1258 function checkAmount() {
1259 let raw = $("#amount").val() || "";
1260 let val = parseFloat(raw.replace(",", ".")) || 0;
1261 let minimum = getCurrentMin();
1262 if (val < minimum) {
1263 $("#submitsave").prop("disabled", true);
1265 $("#submitsave").prop("disabled", false);
1269 function updateAmountAndTexts() {
1270 let typeId = $("#typeid").val();
1271 let amountVal = amountByType[typeId] || 0;
1272 let formattedAmount = parseFloat(amountVal);
1273 let canEdit = canEditAmountByType[typeId] === "1";
1274 let amountFormulaDescription = amountFormulaDescriptionByType[typeId] || "";
1275 let minimumAmount = minimumAmountByType[typeId] || 0;
1276 let minimum = Math.max(memberMinAmount, minimumAmount);
1280 $("#amount").val(formattedAmount).prop("disabled", false).removeClass("hidden");
1281 $("#amounthidden").addClass("hidden");
1282 $(".hideifautoturnover").removeClass("hidden");
1284 // Description formula or default text
1285 if (amountFormulaDescription.trim() !== "") {
1286 $(".amountdescription").html(" - " + amountFormulaDescription);
1288 if (amountVal > 0) {
1289 $(".amountdescription").html(" - " + langs.trans("AnyAmountWithAdvisedAmount", formattedAmount + " " + currencySymbol));
1291 $(".amountdescription").html(" - " + langs.trans("AnyAmountWithoutAdvisedAmount"));
1295 // Minimum amount label
1298 .html(langs.trans("MinimumAmountShort") + " : " + minimum + " " + currencySymbol)
1299 .removeClass("hidden");
1301 $("#minimumamount").addClass("hidden");
1305 $("#amounthidden").val(formattedAmount).prop("disabled", true).removeClass("hidden");
1306 $("#amount").addClass("hidden");
1307 $(".hideifautoturnover").addClass("hidden");
1308 $("#minimumamount").addClass("hidden");
1311 // After updating fields, re‑check the amount validity
1315 // ----- Bind events -----
1316 $("#typeid").on("change", function() {
1317 console.log("Type of membership changed, update amount, description and minimum");
1318 updateAmountAndTexts();
1321 $("#amount").on("keyup change", function() {
1330 print
'</div></div>';
1333 $measuringUnits =
new CUnits($db);
1334 $result = $measuringUnits->fetchAll(
'',
'', 0, 0, array(
't.active' => 1));
1336 foreach ($measuringUnits->records as $lines) {
1337 $units[$lines->short_label] = $langs->trans(ucfirst((
string) $lines->label));
1343 $sql =
"SELECT d.rowid, d.libelle as label, d.subscription, d.amount, d.caneditamount, d.vote, d.note, d.duration, d.statut as status, d.morphy,";
1344 $sql .=
" COUNT(a.rowid) AS membercount";
1345 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent_type as d";
1346 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"adherent as a";
1347 $sql .=
" ON d.rowid = a.fk_adherent_type AND a.statut > 0";
1348 $sql .=
" WHERE d.entity IN (".getEntity(
'member_type').
")";
1349 $sql .=
" AND d.statut=1";
1350 $sql .=
" GROUP BY d.rowid, d.libelle, d.subscription, d.amount, d.caneditamount, d.vote, d.note, d.duration, d.statut, d.morphy";
1352 $result = $db->query($sql);
1354 $num = $db->num_rows($result);
1356 print
'<br><div class="div-table-responsive">';
1357 print
'<table class="tagtable liste noborder">'.
"\n";
1358 print
'<input type="hidden" name="action" value="create">';
1360 print
'<tr class="liste_titre">';
1361 print
'<th>'.$langs->trans(
"Label").
'</th>';
1362 print
'<th class="center">'.$langs->trans(
"MembershipDuration").
'</th>';
1363 print
'<th class="center">'.$langs->trans(
"RecommendedAmount").
'</th>';
1364 print
'<th class="center">'.$langs->trans(
"MembersNature").
'</th>';
1365 if (empty($hidevoteallowed)) {
1366 print
'<th class="center">'.$langs->trans(
"VoteAllowed").
'</th>';
1368 if ($publiccounters) {
1369 print
'<th class="center">'.$langs->trans(
"Members").
'</th>';
1371 print
'<th class="center"></th>';
1376 $objp = $db->fetch_object($result);
1378 $caneditamount = $objp->caneditamount;
1379 $amountbytype = $adht->amountByType(1);
1380 $minimumamountbytype = $adht->minimumamountbytype(1);
1382 print
'<tr class="oddeven">';
1386 print
'<div class="twolinesmax-normallineheight minwidth200onall">';
1387 print dolPrintHTML($objp->label);
1392 print
'<td class="center">';
1393 $unit = preg_replace(
"/[^a-zA-Z]+/",
"", $objp->duration);
1394 print
'<span class="badge badge-primary">';
1395 print max(1, intval($objp->duration)).
' '.$units[$unit];
1400 print
'<td class="center"><span class="amount nowrap">';
1404 $amount = empty($amountbytype[$objp->rowid]) ? 0 : $amountbytype[$objp->rowid];
1405 $minimumamount = empty($minimumamountbytype[$objp->rowid]) ? 0 : $minimumamountbytype[$objp->rowid];
1407 if (empty($amount)) {
1411 $amount = max(0, (
float) $amount, (
float)
getDolGlobalInt(
"MEMBER_MIN_AMOUNT"), (
float) $minimumamount);
1413 $displayedamount = $amount;
1415 if ($objp->subscription) {
1416 if ($displayedamount > 0 || !$caneditamount) {
1417 print
price($displayedamount, 1, $langs, 1, 0, -1,
$conf->currency);
1419 if ($caneditamount && $displayedamount > 0) {
1420 print $form->textwithpicto(
'', $langs->transnoentities(
"CanEditAmountShortForValues"), 1,
'help',
'', 0, 3);
1421 } elseif ($caneditamount) {
1422 print $langs->transnoentities(
"CanEditAmountShort");
1427 print
'</span></td>';
1429 print
'<td class="center minwidth100">';
1430 if ($objp->morphy ==
'phy') {
1431 print $langs->trans(
"Physical");
1432 } elseif ($objp->morphy ==
'mor') {
1433 print $langs->trans(
"Moral");
1435 print $langs->trans(
"MorAndPhy");
1439 if (empty($hidevoteallowed)) {
1440 print
'<td class="center">'.yn($objp->vote).
'</td>';
1442 $membercount = $objp->membercount > 0 ? $objp->membercount :
"–";
1443 if ($publiccounters) {
1444 print
'<td class="center">'.$membercount.
'</td>';
1446 print
'<td class="center"><button class="button button-save reposition" name="typeid" type="submit" name="submit" value="'.$objp->rowid.
'">'.$langs->trans(
"GetMembershipButtonLabel").
'</button></td>';
1454 print
'<tr><td colspan="'.$colspan.
'" class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</td></tr>';