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);
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);
254 if (!$memberfound &&
GETPOST(
"morphy") ==
'mor' && GETPOSTISSET(
"societe")) {
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);
275 if (!$memberfound &&
GETPOST(
"morphy") ==
'phy' && GETPOSTISSET(
"lastname") && GETPOSTISSET(
"firstname") && !empty(
GETPOST(
"member_email",
'aZ09arobase'))) {
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);
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'));
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";
340 if (!GETPOSTISSET(
"pass1") || !GETPOSTISSET(
"pass2") ||
GETPOST(
"pass1",
'none') ==
'' ||
GETPOST(
"pass2",
'none') ==
'' ||
GETPOST(
"pass1",
'none') !=
GETPOST(
"pass2",
'none')) {
342 $langs->load(
"errors");
343 $errmsg .= $langs->trans(
"ErrorPasswordsMustMatch").
"<br>\n";
348 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")).
"<br>\n";
351 if ($morphy && $morphy !=
'mor' && empty($lastname)) {
353 $langs->load(
"errors");
354 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Lastname"));
356 if ($morphy && $morphy !=
'mor' && (!isset($firstname) || $firstname ==
'')) {
358 $langs->load(
"errors");
359 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Firstname"));
361 if ($morphy ==
'mor' && empty($societe)) {
363 $langs->load(
"errors");
364 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Company"));
366 if (empty($country_id)) {
368 $langs->load(
"errors");
369 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Country"));
373 $langs->load(
"errors");
374 $errmsg .= $langs->trans(
"ErrorBadEMail", $email);
377 if (
GETPOST(
"birthmonth") && empty($birthday)) {
379 $langs->load(
"errors");
380 $errmsg .= $langs->trans(
"ErrorBadDateFormat").
"<br>\n";
387 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"TurnoverOrBudget")).
"<br>\n";
393 if (
getDolGlobalString(
'MAIN_SECURITY_ENABLECAPTCHA_MEMBER') && is_object($captchaobj)) {
394 if (method_exists($captchaobj,
'validateCodeAfterLoginSubmit')) {
395 $ok = $captchaobj->validateCodeAfterLoginSubmit();
397 print
'Error, the captcha handler '.get_class($captchaobj).
' does not have any method validateCodeAfterLoginSubmit()';
401 $langs->load(
"errors");
402 $errmsg .= $langs->trans(
"ErrorBadValueForCode").
"<br>\n";
407 $public = GETPOSTISSET(
'public') ? 1 : 0;
414 $adh->public = $public;
415 $adh->firstname =
GETPOST(
'firstname');
416 $adh->lastname =
GETPOST(
'lastname');
417 $adh->gender =
GETPOST(
'gender');
418 $adh->civility_id =
GETPOST(
'civility_id');
419 $adh->company =
GETPOST(
'societe');
420 $adh->societe = $adh->company;
421 $adh->address =
GETPOST(
'address');
422 $adh->zip =
GETPOST(
'zipcode');
424 $adh->email =
GETPOST(
'member_email',
'aZ09arobase');
426 $adh->login =
GETPOST(
'login');
427 $adh->pass =
GETPOST(
'pass1',
'password');
429 $adh->photo =
GETPOST(
'photo');
430 $adh->country_id = $country_id;
433 $adh->note_private =
GETPOST(
'note_private');
435 $adh->birth = $birthday;
436 $adh->phone =
GETPOST(
'phone');
437 $adh->phone_perso =
GETPOST(
'phone_perso');
438 $adh->phone_mobile =
GETPOST(
'phone_mobile');
442 $nb_post_max =
getDolGlobalInt(
"MAIN_SECURITY_MAX_POST_ON_PUBLIC_PAGES_BY_IP_ADDRESS", 200);
447 if ($nb_post_max > 0) {
448 $sql =
"SELECT COUNT(ref) as nb_adh";
449 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent";
450 $sql .=
" WHERE ip = '".$db->escape($adh->ip).
"'";
451 $sql .=
" AND datec > '".$db->idate($minmonthpost).
"'";
452 $resql =
$db->query($sql);
454 $num =
$db->num_rows($resql);
458 $obj =
$db->fetch_object($resql);
459 $nb_post_ip = $obj->nb_adh;
466 $extrafields->fetch_name_optionals_label($adh->table_element);
467 $ret = $extrafields->setOptionalsFromPost(
null, $adh);
470 $errmsg .= $adh->error;
473 if ($nb_post_max > 0 && $nb_post_ip >= $nb_post_max) {
475 $errmsg .= $langs->trans(
"AlreadyTooMuchPostOnThisIPAdress");
476 array_push($adh->errors, $langs->trans(
"AlreadyTooMuchPostOnThisIPAdress"));
480 $result = $adh->create($user);
482 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
493 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
497 $outputlangs->setDefaultLang(empty(
$object->thirdparty->default_lang) ?
$mysoc->default_lang :
$object->thirdparty->default_lang);
499 $outputlangs->loadLangs(array(
"main",
"members"));
501 $arraydefaultmessage =
null;
504 if (!empty($labeltouse)) {
505 $arraydefaultmessage = $formmail->getEMailTemplate(
$db,
'member', $user, $outputlangs, 0, 1, $labeltouse);
508 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
509 $subject = $arraydefaultmessage->topic;
510 $msg = $arraydefaultmessage->content;
513 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0,
null, $object);
518 if ($subjecttosend && $texttosend) {
519 $moreinheader =
'X-Dolibarr-Info: send_an_email by public/members/new.php'.
"\r\n";
521 $result =
$object->sendEmail($texttosend, $subjecttosend, array(), array(), array(),
"",
"", 0, -1,
'', $moreinheader);
533 $appli = constant(
'DOL_APPLICATION_TITLE');
536 if (preg_match(
'/\d\.\d/', $appli)) {
537 if (!preg_match(
'/'.preg_quote(DOL_VERSION,
'/').
'/', $appli)) {
538 $appli .=
" (".DOL_VERSION.
")";
541 $appli .=
" ".DOL_VERSION;
544 $appli .=
" ".DOL_VERSION;
563 if (!$mailfile->sendfile()) {
564 dol_syslog($langs->trans(
"ErrorFailedToSendMail", $from, $to), LOG_ERR);
571 $result = $company->create_from_member($adh);
574 $errmsg .= implode(
'<br>', $company->errors);
578 if (!empty($backtopage)) {
579 $urlback = $backtopage;
584 $urlback = $_SERVER[
"PHP_SELF"].
"?action=added&token=".newToken();
588 if (empty($adht->caneditamount)) {
593 $minimumamountbytype = $adht->minimumamountbytype(1);
594 $minimumamount = empty($minimumamountbytype[$adh->typeid]) ? 0 : $minimumamountbytype[$adh->typeid];
596 $urlback = getOnlinePaymentUrl(0,
'member', $adh->ref, (
float) $amount,
'', 0);
597 if ($amount < max(
getDolGlobalInt(
"MEMBER_MIN_AMOUNT"), $minimumamount)) {
599 $errmsg .= $langs->trans(
"MinimumAmountShort").
" : ".
price(max(
getDolGlobalInt(
"MEMBER_MIN_AMOUNT"), $minimumamount), 0, $langs, 1, -1, -1,
$conf->currency).
"<br>\n";
603 $urlback .=
'&email='.urlencode(
GETPOST(
'member_email'));
606 $urlback .=
'&paymentmethod='.urlencode(
getDolGlobalString(
'MEMBER_NEWFORM_PAYONLINE'));
609 if (!empty($entity)) {
610 $urlback .=
'&entity='.((int) $entity);
615 $errmsg .= implode(
'<br>', $adh->errors);
623 header(
"Location: ".$urlback);
635if (empty($reshook) && $action ==
'added') {
640 print
'<div class="center">';
641 print $langs->trans(
"NewMemberbyWeb");
656$extrafields->fetch_name_optionals_label(
$object->table_element);
662print
load_fiche_titre(
img_picto(
'',
'member_nocolor',
'class="pictofixedwidth"').
' '.$langs->trans(
"NewSubscription"),
'',
'', 0,
'',
'center');
665print
'<div align="center">';
666print
'<div id="divsubscribe">';
668print
'<div class="center subscriptionformhelptext opacitymedium justify">';
672 print $langs->trans(
"NewSubscriptionDesc",
getDolGlobalString(
"MAIN_INFO_SOCIETE_MAIL")).
"<br>\n";
679if ($action ==
"subscription") {
680 $urltocall = DOL_URL_ROOT.
'/public/payment/newpayment.php?source=member&ref='.
$object->id;
681 print $form->formconfirm($urltocall, $langs->trans(
"CorrespondingMemberFound"), $langs->trans(
"CorrespondingMemberFoundQuestion"),
"confirm_subscription",
'',
'no', 1);
685print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST" name="newmember" id="newmember">'.
"\n";
686print
'<input type="hidden" name="token" value="'.newToken().
'" />';
687print
'<input type="hidden" name="entity" value="'.$entity.
'" />';
688print
'<input type="hidden" name="page_y" value="" />';
691 if ($action ==
'subscription') {
692 print
'<input type="hidden" name="nofetchmember" value="nofetchmember" />';
694 print
'<input type="hidden" name="action" value="add" />';
703 if (
$conf->use_javascript_ajax) {
704 print
"\n".
'<script type="text/javascript">'.
"\n";
705 print
'jQuery(document).ready(function () {
706 jQuery("#selectcountry_id").change(function() {
707 console.log("We change country, so we reload page");
708 document.newmember.action.value="create";
709 jQuery("#newmember").submit();
711 function initfieldrequired() {
712 console.log("initfieldrequired");
713 jQuery("#tdcompany").removeClass("fieldrequired");
714 jQuery("#tdlastname").removeClass("fieldrequired");
715 jQuery("#tdfirstname").removeClass("fieldrequired");
716 if (jQuery(\'input[name="morphy"]:checked\').val() == \'mor\') {
717 jQuery("#tdcompany").addClass("fieldrequired");
719 if (jQuery(\'input[name="morphy"]:checked\').val() == \'phy\') {
720 jQuery("#tdlastname").addClass("fieldrequired");
721 jQuery("#tdfirstname").addClass("fieldrequired");
724 jQuery(\'input[name="morphy"]\').change(function() {
729 print
'</script>'.
"\n";
732 print
'<table class="border" summary="form to subscribe" id="tablesubscribe">'.
"\n";
737 print
'<tr><td class="fieldrequired titlefieldmiddle">'.$langs->trans(
"MemberType").
'</td><td>';
738 $listetype = $adht->liste_array(1);
739 print
img_picto(
'', $adht->picto,
'class="pictofixedwidth"');
740 if (count($listetype)) {
741 print $form->selectarray(
"typeid", $listetype, (
GETPOSTINT(
'typeid') ?
GETPOSTINT(
'typeid') : $typeid), (count($listetype) > 1 ? 1 : 0), 0, 0,
'', 0, 0, 0,
'',
'minwidth150 maxwidth300 widthcentpercentminusx', 1);
743 print
'<span class="error">'.$langs->trans(
"NoTypeDefinedGoToSetup").
'</span>';
745 print
'</td></tr>'.
"\n";
748 print
'<input type="hidden" id="typeid" name="typeid" value="' .
getDolGlobalString(
'MEMBER_NEWFORM_FORCETYPE').
'">';
753 "phy" => $langs->trans(
"Physical"),
754 "mor" => $langs->trans(
"Moral"),
756 $checkednature =
GETPOST(
"morphy",
'alpha');
757 $listetype_natures = $adht->morphyByType(1);
758 $listetype_natures_json = json_encode($listetype_natures);
761 if (empty($checkednature) && !empty($listetype_natures[
GETPOSTINT(
'typeid')])) {
762 $checkednature = $listetype_natures[
GETPOSTINT(
'typeid')];
765 print
'<tr><td class="fieldrequired titlefieldmiddle">'.$langs->trans(
"MemberNature").
"</td><td>\n";
771 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>';
772 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>';
775 if (
$conf->use_javascript_ajax) {
777 var listetype_natures = '.$listetype_natures_json.
';
780 function refreshNatureCss() {
781 $(".spannature").each(function(index) {
782 let $span = $("#spannature" + (index + 1));
783 let checked = $span.find(".checkforselect").is(":checked");
787 $span.addClass("member-individual-back").removeClass("nonature-back member-company-back");
788 } else if (index === 1) {
789 $span.addClass("member-company-back").removeClass("nonature-back member-individual-back");
792 $span.removeClass("member-individual-back member-company-back")
793 .addClass("nonature-back");
798 $(".spannature").on("click", function() {
799 console.log("Nature clicked");
803 $("#typeid").on("change", function() {
804 console.log("Type of membership is modified");
805 let morphy = listetype_natures[$(this).val()];
806 console.log("morphy="+morphy);
808 let $phyInput = $("#phisicalinput");
809 let $morInput = $("#moralinput");
810 let $tdLast = $("#tdlastname");
811 let $tdFirst = $("#tdfirstname");
812 let $tdCompany = $("#tdcompany");
813 let $span1 = $("#spannature1");
814 let $span2 = $("#spannature2");
818 $phyInput.prop({disabled: false, checked: true});
819 $morInput.prop({disabled: true, checked: false});
820 $span1.addClass("member-individual-back").removeClass("nonature-back");
821 $span2.removeClass("member-company-back").addClass("nonature-back");
822 $("#phisicalinput").prop("checked", true);
823 $tdLast.addClass("fieldrequired");
824 $tdFirst.addClass("fieldrequired");
825 $tdCompany.removeClass("fieldrequired");
829 $phyInput.prop({disabled: true, checked: false});
830 $morInput.prop({disabled: false, checked: true});
831 $span2.addClass("member-company-back").removeClass("nonature-back");
832 $span1.removeClass("member-individual-back").addClass("nonature-back");
833 $("#moralinput").prop("checked", true);
834 $tdCompany.addClass("fieldrequired");
835 $tdLast.removeClass("fieldrequired");
836 $tdFirst.removeClass("fieldrequired");
840 $phyInput.prop({disabled: false});
841 $morInput.prop({disabled: false});';
842 if ($action !=
"subscription" && !
GETPOST(
'morphy')) {
844 $phyInput.prop({checked: false});
845 $morInput.prop({checked: false});
846 $span1.removeClass("member-individual-back").addClass("nonature-back");
847 $span2.removeClass("member-company-back").addClass("nonature-back");';
857 print
'</td></tr>'.
"\n";
860 print
'<input type="hidden" id="morphy" name="morphy" value="' .
getDolGlobalString(
'MEMBER_NEWFORM_FORCEMORPHY').
'">';
864 print
'<tr id="trcompany" class="trcompany"><td id="tdcompany" class="titlefieldmiddle paddingrightonly'.($checkednature ==
"mor" ?
' fieldrequired"' :
'').
'">'.$langs->trans(
"Company").
'</td><td>';
865 print
img_picto(
'',
'company',
'class="pictofixedwidth paddingright"');
866 print
'<input type="text" name="societe" class="minwidth150 widthcentpercentminusx" value="'.dol_escape_htmltag(
GETPOST(
'societe')).
'"></td></tr>'.
"\n";
870 print
'<tr><td>'.$langs->trans(
'UserTitle').
'</td><td>';
871 print $formcompany->select_civility(
GETPOST(
'civility_id'),
'civility_id').
'</td></tr>'.
"\n";
875 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";
878 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";
881 print
'<tr><td>'.(getDolGlobalString(
'ADHERENT_MAIL_REQUIRED') ?
'<span class="fieldrequired">' :
'').$langs->trans(
"EMail").(getDolGlobalString(
'ADHERENT_MAIL_REQUIRED') ?
'</span>' :
'').
'</td>';
882 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";
886 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";
887 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";
888 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";
892 print
'<tr><td>'.$langs->trans(
"Gender").
'</td>';
894 $arraygender = array(
'man' => $langs->trans(
"Genderman"),
'woman' => $langs->trans(
"Genderwoman"),
'other' => $langs->trans(
"Genderother"));
895 print $form->selectarray(
'gender', $arraygender,
GETPOST(
'gender',
'alphanohtml'), 1, 0, 0,
'', 0, 0, 0,
'',
'minwidth150 maxwidth300 widthcentpercentminusx', 1);
899 print
'<tr><td>'.$langs->trans(
"Address").
'</td><td>'.
"\n";
900 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";
903 print
'<tr><td>'.$langs->trans(
'Zip').
' / '.$langs->trans(
'Town').
'</td><td>';
904 print $formcompany->select_ziptown(
GETPOST(
'zipcode'),
'zipcode', array(
'town',
'selectcountry_id',
'state_id'), 0, 1,
'',
'width75');
906 print $formcompany->select_ziptown(
GETPOST(
'town'),
'town', array(
'zipcode',
'selectcountry_id',
'state_id'), 0, 1);
912 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Country').
'</td><td>';
913 print
img_picto(
'',
'country',
'class="pictofixedwidth paddingright"');
917 if (!$country_id && !empty(
$conf->geoipmaxmind->enabled)) {
921 $new_country_id =
getCountry($country_code,
'3',
$db, $langs);
923 if ($new_country_id) {
924 $country_id = $new_country_id;
929 print $form->select_country($country_id,
'country_id',
'', 0,
'minwidth150 maxwidth300 widthcentpercentminusx reposition');
934 print
'<tr><td>'.$langs->trans(
'State').
'</td><td>';
936 print
img_picto(
'',
'state',
'class="pictofixedwidth paddingright"');
937 print $formcompany->select_state(
GETPOSTINT(
"state_id"), $country_code,
'state_id',
'minwidth150 maxwidth300 widthcentpercentminusx');
943 print
'<tr><td>'.$langs->trans(
"PhonePro").
'</td>';
944 print
'<td>'.img_picto(
'',
'object_phoning',
'class="pictofixedwidth"').
'<input type="text" name="phone" class="maxwidth300 widthcentpercentminusx" value="'.
dol_escape_htmltag(
GETPOST(
'phone')).
'"></td></tr>';
947 print
'<tr><td>'.$langs->trans(
"PhonePerso").
'</td>';
948 print
'<td>'.img_picto(
'',
'object_phoning',
'class="pictofixedwidth"').
'<input type="text" name="phone_perso" class="maxwidth300 widthcentpercentminusx" value="'.
dol_escape_htmltag(
GETPOST(
'phone_perso')).
'"></td></tr>';
951 print
'<tr><td>'.$langs->trans(
"PhoneMobile").
'</td>';
952 print
'<td>'.img_picto(
'',
'object_phoning_mobile',
'class="pictofixedwidth"').
'<input type="text" name="phone_mobile" class="maxwidth300 widthcentpercentminusx" value="'.
dol_escape_htmltag(
GETPOST(
'phone_mobile')).
'"></td></tr>';
955 print
'<tr id="trbirth" class="trbirth"><td>'.$langs->trans(
"DateOfBirth").
'</td><td>';
956 print $form->selectDate(!empty($birthday) ? $birthday :
"",
'birth', 0, 0, 1,
"newmember", 1, 0);
957 print
'</td></tr>'.
"\n";
960 print
'<tr><td>'.$langs->trans(
"URLPhoto").
'</td><td><input type="text" name="photo" class="minwidth150" value="'.
dol_escape_htmltag(
GETPOST(
'photo')).
'"></td></tr>'.
"\n";
964 $linkofpubliclist = DOL_MAIN_URL_ROOT.
'/public/members/public_list.php'.((
isModEnabled(
'multicompany')) ?
'?entity='.
$conf->entity :
'');
965 $publiclabel = $langs->trans(
"Public",
getDolGlobalString(
'MAIN_INFO_SOCIETE_NOM'), $linkofpubliclist);
966 print
'<tr><td>'.$form->textwithpicto($langs->trans(
"MembershipPublic"), $publiclabel).
'</td><td><input type="checkbox" name="public"></td></tr>'.
"\n";
970 $parameters[
'tpl_context'] =
'public';
971 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_add.tpl.php';
975 print
'<td class="tdtop"></td>';
976 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>';
983 $adht->fetch($typeid);
984 $caneditamount = $adht->caneditamount;
985 $amountbytype = $adht->amountByType(1);
986 $minimumamountbytype = $adht->minimumamountbytype(1);
987 foreach ($amountbytype as $k => $v) {
988 $amount = max(0, (
float) $v, (
float)
getDolGlobalInt(
"MEMBER_MIN_AMOUNT"), $minimumamountbytype[$k]);
989 $amountbytype[$k] = $amount;
992 $caneditamountbytype = $adht->caneditamountByType(1);
993 $amountformuladescriptionbytype = $adht->amountformuladescriptionbytype(1);
997 $amount = empty($amountbytype[$typeid]) ? 0 : $amountbytype[$typeid];
999 if (empty($amount)) {
1003 $minimumamount = empty($minimumamountbytype[$typeid]) ? 0 : $minimumamountbytype[$typeid];
1004 $amount = max(0, (
float) $amount, (
float)
getDolGlobalInt(
"MEMBER_MIN_AMOUNT"), (
float) $minimumamount);
1011 $parameters = array(
'country_id' => $country_id,
'mode' =>
'new');
1012 $reshook = $hookmanager->executeHooks(
'membershipNewSubscriptionPublicForm', $parameters, $object, $action);
1019 $s = $langs->trans(
"AreYouAPreferredPartner",
'<a href="https://partners.dolibarr.org" target="_blank">{s1}</a>');
1020 $s = str_replace(
'{s1}',
'Preferred Partner', $s);
1021 print
'<tr id="trbudget" class="trcompany"><td class="paddingrightonly"><label for="pp" class="small">'.$s.
'</label></td><td>';
1022 print
'<input type="checkbox" name="pp" id="pp" value="1"'.(GETPOST(
'pp') ?
' checked="checked"' :
'').
' class="reposition">';
1025 print
'<tr id="trbudget" class="trcompany"><td class="fieldrequired paddingrightonly"><span class="small">'.$langs->trans(
"TurnoverOrBudget").
'</span></td><td>';
1028 if ($country_code ===
'FR' && $checkednature ===
'mor' &&
GETPOST(
'pp')) {
1029 print
'<input type="text" name="budget" id="budget" class="flat turnover right width100" value="'.GETPOST(
'budget').
'" required>';
1031 $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+');
1032 print $form->selectarray(
'budget', $arraybudget,
GETPOSTINT(
'budget'), 1, 0, 0,
'', 0, 0, 0,
'');
1036 print
'<script type="text/javascript">
1037 jQuery(document).ready(function() {
1040 newamount = initturnover();
1041 jQuery("#amount").val(newamount);
1045 jQuery("#selectcountry_id").change(function() {
1046 console.log("We change country (code added for association, replace common code), so we reload page");
1047 jQuery("#budget").val(\'\');
1048 jQuery("#amount").val(\'\');
1049 jQuery("#amounthidden").val(\'\');
1051 jQuery("#phisicalinput,#moralinput").click(function() {
1052 console.log("We change the nature of membership");
1053 newamount = initturnover();
1054 jQuery("#amount").val(newamount);
1056 jQuery("#pp").change(function() {
1057 console.log("We change the preferred partner status");
1058 selectcountry_id = jQuery("#selectcountry_id").val();
1059 morphy = jQuery("#moralinput").is(\':checked\') ? \'mor\' : \'phy\';
1060 jQuery("#budget").val(\'\');
1061 jQuery("#amount").val(\'\');
1062 jQuery("#amounthidden").val(\'\');
1063 document.newmember.action.value="create";
1064 jQuery("#newmember").submit();
1066 jQuery("#budget").change(function() {
1067 console.log("Turnover amount has been modified on change");
1068 newamount = initturnover();
1069 jQuery("#amount").val(newamount);
1070 jQuery("#amounthidden").val(newamount);
1072 jQuery("#budget").keyup(function() {
1073 console.log("Turnover amount has been modified on keyup");
1074 newamount = initturnover();
1075 jQuery("#amount").val(newamount);
1076 jQuery("#amounthidden").val(newamount);
1079 function initturnover() {
1082 morphy = jQuery("#moralinput").is(\':checked\') ? \'mor\' : \'phy\';
1083 selectcountry_id = jQuery("#selectcountry_id").val();
1084 pp = jQuery("#pp").is(\':checked\') ? true : false;
1085 console.log("Set fields according to nature and other properties");
1086 console.log("morphy="+morphy);
1087 console.log("selectcountry_id="+selectcountry_id);
1088 console.log("pp="+pp);
1090 if (morphy == \'phy\') {
1091 jQuery(".amount").val('.((float) $amount).
');
1092 jQuery("#trbirth").show();
1093 jQuery(".trcompany").hide();
1094 jQuery(".trbudget").hide();
1095 newamount = '.((float) $amount).
';
1097 jQuery(".amount").val(\'\');
1098 jQuery("#trbirth").hide();
1099 jQuery(".trcompany").show();
1100 jQuery(".trbudget").show();
1101 jQuery(".hideifautoturnover").hide();
1103 jQuery("#budget").val(\'\');
1106 if (selectcountry_id == 1) {
1108 console.log("value selected in input text field is "+jQuery("#budget").val());
1109 newamount = Math.max(Math.round(price2numjs(jQuery("#budget").val()) * 0.005), 50);
1110 console.log("newamount = "+newamount);
1112 console.log("not a pp");
1113 if (jQuery("#budget").val() > 0) {
1114 console.log("value found in budget is "+jQuery("#budget").val());
1115 newamount = jQuery("#budget").val();
1117 jQuery("#budget").val(\'\');
1122 if (jQuery("#budget").val() > 0) {
1123 newamount = jQuery("#budget").val();
1125 jQuery("#budget").val(\'\');
1128 console.log("newamount="+newamount);
1136 print
'</td></tr>'.
"\n";
1140 print
'<tr><td>'.$langs->trans(
"Subscription");
1143 print
'<a href="' .
getDolGlobalString(
'MEMBER_EXT_URL_SUBSCRIPTION_INFO').
'" rel="external" target="_blank" rel="noopener noreferrer">';
1144 print
img_picto(
'',
'url',
'class="pictofixedwidth"').$langs->trans(
"SeeHere");
1147 print
'</td><td class="nowrap">';
1149 $amountformuladescription = $amountformuladescriptionbytype[$typeid];
1151 $showedamount = $amount > 0 ? $amount : 0;
1152 if ($caneditamount ===
"1") {
1153 print
'<input type="text" name="amount" id="amount" class="flat amount right width75" value="'.$showedamount.
'">';
1154 print
'<input type="text" name="amount" id="amounthidden" class="flat amount width75 hidden" disabled value="'.$showedamount.
'">';
1155 print
' '.$langs->getCurrencySymbol(
$conf->currency).
'<span class="opacitymedium amountdescription hideifautoturnover small">';
1158 if (empty($amountformuladescription)) {
1159 print $amount > 0 ? $langs->trans(
"AnyAmountWithAdvisedAmount",
price($amount, 0, $langs, 1, -1, -1,
$conf->currency)) : $langs->trans(
"AnyAmountWithoutAdvisedAmount");
1161 print $amountformuladescription;
1165 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);
1169 print
'<input type="text" name="amount" id="amount" class="flat amount width75 right hidden" value="'.$showedamount.
'">';
1170 print
'<input type="text" name="amount" id="amounthidden" class="flat amount width75" disabled value="'.$showedamount.
'">';
1171 print
' '.$langs->getCurrencySymbol(
$conf->currency).
'<span class="opacitymedium amountdescription hideifautoturnover hidden small">';
1174 print $amount > 0 ? $langs->trans(
"AnyAmountWithAdvisedAmount",
price($amount, 0, $langs, 1, -1, -1,
$conf->currency)) : $langs->trans(
"AnyAmountWithoutAdvisedAmount");
1182 if (
getDolGlobalString(
'MAIN_SECURITY_ENABLECAPTCHA_MEMBER') && is_object($captchaobj)) {
1183 print
'<tr><td><label><span class="fieldrequired">'.$langs->trans(
"SecurityCode").
'</span></label></td><td><br>';
1184 if (method_exists($captchaobj,
'getCaptchaCodeForForm')) {
1185 print $captchaobj->getCaptchaCodeForForm(
'');
1187 print
'Error, the captcha handler '.get_class($captchaobj).
' does not have any method getCaptchaCodeForForm()';
1189 print
'<br></td></tr>';
1197 print
'<div class="center">';
1198 print
'<input type="submit" value="'.$langs->trans(
"GetMembershipButtonLabel").
'" id="submitsave" class="button">';
1199 if (!empty($backtopage)) {
1200 print
' <input type="submit" value="'.$langs->trans(
"Cancel").
'" id="submitcancel" class="button button-cancel">';
1207 $adht->fetch($typeid);
1208 $caneditamountbytype = $adht->caneditamountByType(1);
1209 $minimumamountbytype = $adht->minimumamountbytype(1);
1210 $amountbytype = $adht->amountByType(1);
1211 $amountformuladescriptionbytype = $adht->amountformuladescriptionbytype(1);
1213 $caneditamountbytype_json = json_encode($caneditamountbytype);
1214 $minimumamountbytype_json = json_encode($minimumamountbytype);
1215 $amountbytype_json = json_encode($amountbytype);
1216 $amountformuladescriptionbytype_json = json_encode($amountformuladescriptionbytype);
1217 $currencysymbol = $langs->getCurrencySymbol(
$conf->currency);
1219 if (
$conf->use_javascript_ajax) {
1221 // ----- Shared data -----
1222 var amountByType = ' . $amountbytype_json .
';
1223 var canEditAmountByType = ' . $caneditamountbytype_json .
';
1224 var amountFormulaDescriptionByType = ' . $amountformuladescriptionbytype_json .
';
1225 var minimumAmountByType = ' . $minimumamountbytype_json .
';
1227 var currencySymbol = ' . json_encode($currencysymbol) .
';
1229 // Translations prepared by PHP
1231 AnyAmountWithAdvisedAmount: ' . json_encode($langs->trans(
"AnyAmountWithAdvisedAmount",
"__VAL__")) .
',
1232 AnyAmountWithoutAdvisedAmount: ' . json_encode($langs->trans(
"AnyAmountWithoutAdvisedAmount")) .
',
1233 MinimumAmountShort: ' . json_encode($langs->trans(
"MinimumAmountShort",
"__VAL__")) .
',
1234 trans: function(key, val) {
1235 if (!this[key]) return key;
1236 return this[key].replace("__VAL__", val || "");
1240 jQuery(function($) {
1241 // ----- Helpers -----
1242 function getCurrentMin() {
1243 let typeId = $("#typeid").val() || 0;
1244 let minimumAmount = minimumAmountByType[typeId] || 0;
1245 return Math.max(memberMinAmount, minimumAmount);
1248 function checkAmount() {
1249 let raw = $("#amount").val() || "";
1250 let val = parseFloat(raw.replace(",", ".")) || 0;
1251 let minimum = getCurrentMin();
1252 if (val < minimum) {
1253 $("#submitsave").prop("disabled", true);
1255 $("#submitsave").prop("disabled", false);
1259 function updateAmountAndTexts() {
1260 let typeId = $("#typeid").val();
1261 let amountVal = amountByType[typeId] || 0;
1262 let formattedAmount = parseFloat(amountVal);
1263 let canEdit = canEditAmountByType[typeId] === "1";
1264 let amountFormulaDescription = amountFormulaDescriptionByType[typeId] || "";
1265 let minimumAmount = minimumAmountByType[typeId] || 0;
1266 let minimum = Math.max(memberMinAmount, minimumAmount);
1270 $("#amount").val(formattedAmount).prop("disabled", false).removeClass("hidden");
1271 $("#amounthidden").addClass("hidden");
1272 $(".hideifautoturnover").removeClass("hidden");
1274 // Description formula or default text
1275 if (amountFormulaDescription.trim() !== "") {
1276 $(".amountdescription").html(" - " + amountFormulaDescription);
1278 if (amountVal > 0) {
1279 $(".amountdescription").html(" - " + langs.trans("AnyAmountWithAdvisedAmount", formattedAmount + " " + currencySymbol));
1281 $(".amountdescription").html(" - " + langs.trans("AnyAmountWithoutAdvisedAmount"));
1285 // Minimum amount label
1288 .html(langs.trans("MinimumAmountShort") + " : " + minimum + " " + currencySymbol)
1289 .removeClass("hidden");
1291 $("#minimumamount").addClass("hidden");
1295 $("#amounthidden").val(formattedAmount).prop("disabled", true).removeClass("hidden");
1296 $("#amount").addClass("hidden");
1297 $(".hideifautoturnover").addClass("hidden");
1298 $("#minimumamount").addClass("hidden");
1301 // After updating fields, re‑check the amount validity
1305 // ----- Bind events -----
1306 $("#typeid").on("change", function() {
1307 console.log("Type of membership changed, update amount, description and minimum");
1308 updateAmountAndTexts();
1311 $("#amount").on("keyup change", function() {
1320 print
'</div></div>';
1324 $result = $measuringUnits->fetchAll(
'',
'', 0, 0, array(
't.active' => 1));
1326 foreach ($measuringUnits->records as $lines) {
1327 $units[$lines->short_label] = $langs->trans(ucfirst((
string) $lines->label));
1333 $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,";
1334 $sql .=
" COUNT(a.rowid) AS membercount";
1335 $sql .=
" FROM ".MAIN_DB_PREFIX.
"adherent_type as d";
1336 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"adherent as a";
1337 $sql .=
" ON d.rowid = a.fk_adherent_type AND a.statut > 0";
1338 $sql .=
" WHERE d.entity IN (".getEntity(
'member_type').
")";
1339 $sql .=
" AND d.statut=1";
1340 $sql .=
" GROUP BY d.rowid, d.libelle, d.subscription, d.amount, d.caneditamount, d.vote, d.note, d.duration, d.statut, d.morphy";
1342 $result =
$db->query($sql);
1344 $num =
$db->num_rows($result);
1346 print
'<br><div class="div-table-responsive">';
1347 print
'<table class="tagtable liste">'.
"\n";
1348 print
'<input type="hidden" name="action" value="create">';
1350 print
'<tr class="liste_titre">';
1351 print
'<th>'.$langs->trans(
"Label").
'</th>';
1352 print
'<th class="center">'.$langs->trans(
"MembershipDuration").
'</th>';
1353 print
'<th class="center">'.$langs->trans(
"RecommendedAmount").
'</th>';
1354 print
'<th class="center">'.$langs->trans(
"MembersNature").
'</th>';
1355 if (empty($hidevoteallowed)) {
1356 print
'<th class="center">'.$langs->trans(
"VoteAllowed").
'</th>';
1358 if ($publiccounters) {
1359 print
'<th class="center">'.$langs->trans(
"Members").
'</th>';
1361 print
'<th class="center">'.$langs->trans(
"NewSubscription").
'</th>';
1366 $objp =
$db->fetch_object($result);
1368 $caneditamount = $objp->caneditamount;
1369 $amountbytype = $adht->amountByType(1);
1370 $minimumamountbytype = $adht->minimumamountbytype(1);
1372 print
'<tr class="oddeven">';
1374 print
'<td>'.dolPrintHTML($objp->label).
'</td>';
1376 print
'<td class="center">';
1377 $unit = preg_replace(
"/[^a-zA-Z]+/",
"", $objp->duration);
1378 print max(1, intval($objp->duration)).
' '.$units[$unit];
1381 print
'<td class="center"><span class="amount nowrap">';
1385 $amount = empty($amountbytype[$objp->rowid]) ? 0 : $amountbytype[$objp->rowid];
1386 $minimumamount = empty($minimumamountbytype[$objp->rowid]) ? 0 : $minimumamountbytype[$objp->rowid];
1388 if (empty($amount)) {
1392 $amount = max(0, (
float) $amount, (
float)
getDolGlobalInt(
"MEMBER_MIN_AMOUNT"), (
float) $minimumamount);
1394 $displayedamount = $amount;
1396 if ($objp->subscription) {
1397 if ($displayedamount > 0 || !$caneditamount) {
1398 print
price($displayedamount, 1, $langs, 1, 0, -1,
$conf->currency);
1400 if ($caneditamount && $displayedamount > 0) {
1401 print $form->textwithpicto(
'', $langs->transnoentities(
"CanEditAmountShortForValues"), 1,
'help',
'', 0, 3);
1402 } elseif ($caneditamount) {
1403 print $langs->transnoentities(
"CanEditAmountShort");
1408 print
'</span></td>';
1409 print
'<td class="center">';
1410 if ($objp->morphy ==
'phy') {
1411 print $langs->trans(
"Physical");
1412 } elseif ($objp->morphy ==
'mor') {
1413 print $langs->trans(
"Moral");
1415 print $langs->trans(
"MorAndPhy");
1418 if (empty($hidevoteallowed)) {
1419 print
'<td class="center">'.yn($objp->vote).
'</td>';
1421 $membercount = $objp->membercount > 0 ? $objp->membercount :
"–";
1422 if ($publiccounters) {
1423 print
'<td class="center">'.$membercount.
'</td>';
1425 print
'<td class="center"><button class="button button-save reposition" name="typeid" type="submit" name="submit" value="'.$objp->rowid.
'">'.$langs->trans(
"GetMembershipButtonLabel").
'</button></td>';
1433 print
'<tr><td colspan="'.$colspan.
'" class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</td></tr>';