dolibarr 24.0.2
new.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2001-2002 Jean-Louis Bergamo <jlb@j1b.org>
4 * Copyright (C) 2006-2013 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2012 J. Fernando Lagrange <fernando@demo-tic.org>
7 * Copyright (C) 2018-2026 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2018 Alexandre Spangaro <aspangaro@open-dsi.fr>
9 * Copyright (C) 2021 Waël Almoman <info@almoman.com>
10 * Copyright (C) 2022 Udo Tamm <dev@dolibit.de>
11 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <https://www.gnu.org/licenses/>.
25 */
26
42if (!defined('NOLOGIN')) {
43 define("NOLOGIN", 1); // This means this output page does not require to be logged.
44}
45if (!defined('NOCSRFCHECK')) {
46 define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
47}
48if (!defined('NOBROWSERNOTIF')) {
49 define('NOBROWSERNOTIF', '1');
50}
51
52
53// For MultiCompany module.
54// Do not use GETPOST here, function is not defined and define must be done before including main.inc.php
55// Because 2 entities can have the same ref.
56$entity = (!empty($_GET['entity']) ? (int) $_GET['entity'] : (!empty($_POST['entity']) ? (int) $_POST['entity'] : 1));
57define("DOLENTITY", $entity);
58
59
60// Load Dolibarr environment
61require '../../main.inc.php';
70require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
71require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
72require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
73require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
74require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
75require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
76require_once DOL_DOCUMENT_ROOT.'/core/class/cunits.class.php';
77require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
78
79// Init vars
80$backtopage = GETPOST('backtopage', 'alpha');
81$action = GETPOST('action', 'aZ09');
82
83$errmsg = '';
84$num = 0;
85$error = 0;
86
87// Load translation files
88$langs->loadLangs(array("main", "members", "companies", "install", "other", "errors"));
89
90if (isModEnabled('multicompany')) {
91 force_switch_entity($entity);
92}
93
94// Security check
95if (!isModEnabled('member')) {
96 httponly_accessforbidden('Module Membership not enabled');
97}
98
99if (!getDolGlobalString('MEMBER_ENABLE_PUBLIC')) {
100 httponly_accessforbidden("Auto subscription form for public visitors has not been enabled");
101}
102
103// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
104$hookmanager->initHooks(array('publicnewmembercard', 'globalcard'));
105
106$extrafields = new ExtraFields($db);
107
108$object = new Adherent($db);
109
110$user->loadDefaultValues();
111
112$captchaobj = null;
113if (getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_MEMBER')) {
114 require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
115 $captcha = getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_HANDLER', 'standard');
116 // List of directories where we can find captcha handlers
117 $dirModCaptcha = array_merge(
118 array(
119 'main' => '/core/modules/security/captcha/'
120 ),
121 is_array($conf->modules_parts['captcha']) ? $conf->modules_parts['captcha'] : array()
122 );
123 $fullpathclassfile = '';
124 foreach ($dirModCaptcha as $dir) {
125 $fullpathclassfile = dol_buildpath($dir."modCaptcha".ucfirst($captcha).'.class.php', 0, 2);
126 if ($fullpathclassfile) {
127 break;
128 }
129 }
130 if ($fullpathclassfile) {
131 include_once $fullpathclassfile;
132 // Charging the numbering class
133 $classname = "modCaptcha".ucfirst($captcha);
134 if (class_exists($classname)) {
135 $captchaobj = new $classname($db, $conf, $langs, $user);
136 '@phan-var-force ModeleCaptcha $captchaobj';
138 } else {
139 print 'Error, the captcha handler class '.$classname.' was not found after the include';
140 }
141 } else {
142 print 'Error, the captcha handler '.$captcha.' has no class file found modCaptcha'.ucfirst($captcha);
143 }
144}
145
153function force_switch_entity($newEntity)
154{
155 global $db, $conf;
156
157 if ($newEntity != $conf->entity) {
158 $conf->entity = $newEntity;
159 $conf->setValues($db);
160 }
161}
162
177function llxHeaderVierge($title, $head = "", $disablejs = 0, $disablehead = 0, $arrayofjs = [], $arrayofcss = [], $ws = '') // @phan-suppress-current-line PhanRedefineFunction
178{
179 global $conf, $langs, $mysoc;
180
181 top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss); // Show html headers
182
183 print '<body id="mainbody" class="publicnewmemberform">';
184
185 include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
186 htmlPrintOnlineHeader($mysoc, $langs, 1, getDolGlobalString('MEMBER_PUBLIC_INTERFACE'), 'MEMBER_IMAGE_PUBLIC_REGISTRATION');
187
188 print '<div class="divmainbodylarge">';
189}
190
198function llxFooterVierge() // @phan-suppress-current-line PhanRedefineFunction
199{
200 global $conf, $langs;
201
202 print '</div>';
203
204 printCommonFooter('public');
205
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";
209 }
210
211 print "</body>\n";
212 print "</html>\n";
213}
214
215
216//var_dump(GETPOST('firstname')); exit;
217
218/*
219 * Actions
220 */
221
222$parameters = array();
223// Note that $action and $object may have been modified by some hooks
224$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
225if ($reshook < 0) {
226 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
227}
228
229// Verify if we can find member
230
231if (empty($reshook) && getDolGlobalInt("MEMBER_SEARCH_MEMBER_PUBLIC_FORM_CREATE") && $action == 'add' && !GETPOSTISSET("nofetchmember")) { // Test on permission not required here
232 $memberfound = false;
233
234 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED') && GETPOSTISSET('login')) {
235 // Note that this allow to guess anonymous ID already used. But this is not a problem as it is an anonymous pseudonym.
236 // If we try to new account and option MEMBER_SEARCH_MEMBER_PUBLIC_FORM_CREATE was off, we also get the same error.
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);
243 if ($resql) {
244 if ($db->num_rows($resql) == 1) {
245 $obj = $db->fetch_object($resql);
246 $object->fetch($obj->id);
247 $memberfound = true;
248 }
249 } else {
251 }
252 }
253
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);
264 if ($resql) {
265 if ($db->num_rows($resql) == 1) {
266 $obj = $db->fetch_object($resql);
267 $object->fetch($obj->id);
268 $memberfound = true;
269 }
270 } else {
272 }
273 }
274
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);
284 if ($resql) {
285 if ($db->num_rows($resql) == 1) {
286 $obj = $db->fetch_object($resql);
287 $object->fetch($obj->id);
288 $memberfound = true;
289 }
290 } else {
292 }
293 }
294
295 if ($memberfound) {
296 $action = 'subscription';
297 }
298}
299
300// Action called when page is submitted
301if (empty($reshook) && $action == 'add') { // Test on permission not required here. This is an anonymous form. Check is done on constant to enable and mitigation.
302 $error = 0;
303 $urlback = '';
304
305 $db->begin();
306
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'));
312 $forcecountry = getDolGlobalString('MEMBER_NEWFORM_FORCECOUNTRYCODE');
313 $country_id = $forcecountry ? (int) getCountry($forcecountry, '3', $db, $langs) : GETPOSTINT('country_id');
314
315 if (!in_array($morphy, array('mor', 'phy'))) {
316 $error++;
317 $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv('MemberNature'))."<br>\n";
318 }
319
320 // test if login already exists
321 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
322 if (!GETPOST('member_email')) {
323 $error++;
324 $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("EMail"))."<br>\n";
325 }
326 if (!GETPOST('login')) {
327 $error++;
328 $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Login"))."<br>\n";
329 }
330 $sql = "SELECT login FROM ".MAIN_DB_PREFIX."adherent WHERE login = '".$db->escape(GETPOST('login'))."'";
331 $result = $db->query($sql);
332 if ($result) {
333 $num = $db->num_rows($result);
334 }
335 if ($num != 0) {
336 $error++;
337 $langs->load("errors");
338 $errmsg .= $langs->trans("ErrorLoginAlreadyExists")."<br>\n";
339 }
340 if (!GETPOSTISSET("pass1") || !GETPOSTISSET("pass2") || GETPOST("pass1", 'none') == '' || GETPOST("pass2", 'none') == '' || GETPOST("pass1", 'none') != GETPOST("pass2", 'none')) {
341 $error++;
342 $langs->load("errors");
343 $errmsg .= $langs->trans("ErrorPasswordsMustMatch")."<br>\n";
344 }
345 }
346 if (GETPOST('typeid') <= 0) {
347 $error++;
348 $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type"))."<br>\n";
349 } elseif (!getDolGlobalString('MEMBER_NEWFORM_FORCETYPE')) {
350 // The type must be one of the active types proposed by the form
351 // (when a type is forced by setup, the type posted is ignored and replaced by the forced one)
352 $tmpadht = new AdherentType($db);
353 if (!array_key_exists(GETPOSTINT('typeid'), $tmpadht->liste_array(1))) {
354 $error++;
355 $errmsg .= $langs->trans("ErrorBadValueForParameter", GETPOSTINT('typeid'), $langs->transnoentitiesnoconv("Type"))."<br>\n";
356 }
357 }
358
359 if ($morphy && $morphy != 'mor' && empty($lastname)) {
360 $error++;
361 $langs->load("errors");
362 $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentities("Lastname"));
363 }
364 if ($morphy && $morphy != 'mor' && (!isset($firstname) || $firstname == '')) {
365 $error++;
366 $langs->load("errors");
367 $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentities("Firstname"));
368 }
369 if ($morphy == 'mor' && empty($societe)) {
370 $error++;
371 $langs->load("errors");
372 $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentities("Company"));
373 }
374 if (empty($country_id)) {
375 $error++;
376 $langs->load("errors");
377 $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentities("Country"));
378 }
379 if (getDolGlobalString('ADHERENT_MAIL_REQUIRED') && $email && !isValidEmail($email)) {
380 $error++;
381 $langs->load("errors");
382 $errmsg .= $langs->trans("ErrorBadEMail", $email);
383 }
384 $birthday = dol_mktime(GETPOSTINT("birthhour"), GETPOSTINT("birthmin"), GETPOSTINT("birthsec"), GETPOSTINT("birthmonth"), GETPOSTINT("birthday"), GETPOSTINT("birthyear"));
385 if (GETPOST("birthmonth") && empty($birthday)) {
386 $error++;
387 $langs->load("errors");
388 $errmsg .= $langs->trans("ErrorBadDateFormat")."<br>\n";
389 }
390
391 // TODO Add this in a hook
392 if (getDolGlobalString('MEMBER_NEWFORM_DOLIBARRTURNOVER')) {
393 if (GETPOST("morphy") == 'mor' && GETPOSTFLOAT('budget') <= 0) {
394 $error++;
395 $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("TurnoverOrBudget"))."<br>\n";
396 }
397 }
398
399 // Check Captcha code if is enabled
400 $ok = false;
401 if (getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_MEMBER') && is_object($captchaobj)) {
402 if (method_exists($captchaobj, 'validateCodeAfterLoginSubmit')) {
403 $ok = $captchaobj->validateCodeAfterLoginSubmit(); // @phan-suppress-current-line PhanUndeclaredMethod
404 } else {
405 print 'Error, the captcha handler '.get_class($captchaobj).' does not have any method validateCodeAfterLoginSubmit()';
406 }
407 if (!$ok) {
408 $error++;
409 $langs->load("errors");
410 $errmsg .= $langs->trans("ErrorBadValueForCode")."<br>\n";
411 $action = '';
412 }
413 }
414
415 $public = GETPOSTISSET('public') ? 1 : 0;
416
417 if (!$error) {
418 // E-mail looks OK and login does not exist
419 $adh = new Adherent($db);
420 $adh->statut = -1;
421 $adh->status = -1;
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');
431 $adh->town = GETPOST('town');
432 $adh->email = GETPOST('member_email', 'aZ09arobase');
433 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
434 $adh->login = GETPOST('login');
435 $adh->pass = GETPOST('pass1', 'password');
436 }
437 $adh->photo = GETPOST('photo');
438 $adh->country_id = $country_id;
439 $adh->state_id = GETPOSTINT('state_id');
440 $adh->typeid = getDolGlobalInt("MEMBER_NEWFORM_FORCETYPE", GETPOSTINT('typeid'));
441 $adh->note_private = GETPOST('note_private');
442 $adh->morphy = getDolGlobalString("MEMBER_NEWFORM_FORCEMORPHY", GETPOST('morphy'));
443 $adh->birth = $birthday;
444 $adh->phone = GETPOST('phone');
445 $adh->phone_perso = GETPOST('phone_perso');
446 $adh->phone_mobile = GETPOST('phone_mobile');
447
448 $adh->ip = getUserRemoteIP();
449
450 $nb_post_max = getDolGlobalInt("MAIN_SECURITY_MAX_POST_ON_PUBLIC_PAGES_BY_IP_ADDRESS", 200);
451 $now = dol_now();
452 $minmonthpost = dol_time_plus_duree($now, -1, "m");
453 // Calculate nb of post for IP
454 $nb_post_ip = 0;
455 if ($nb_post_max > 0) { // Calculate only if there is a limit to check
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);
461 if ($resql) {
462 $num = $db->num_rows($resql);
463 $i = 0;
464 while ($i < $num) {
465 $i++;
466 $obj = $db->fetch_object($resql);
467 $nb_post_ip = $obj->nb_adh;
468 }
469 }
470 }
471
472
473 // Fill array 'array_options' with data from add form
474 $extrafields->fetch_name_optionals_label($adh->table_element);
475 $ret = $extrafields->setOptionalsFromPost(null, $adh);
476 if ($ret < 0) {
477 $error++;
478 $errmsg .= $adh->error;
479 }
480
481 if ($nb_post_max > 0 && $nb_post_ip >= $nb_post_max) {
482 $error++;
483 $errmsg .= $langs->trans("AlreadyTooMuchPostOnThisIPAdress");
484 array_push($adh->errors, $langs->trans("AlreadyTooMuchPostOnThisIPAdress"));
485 }
486
487 if (!$error) {
488 $result = $adh->create($user);
489 if ($result > 0) {
490 require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
491 $object = $adh;
492
493 $adht = new AdherentType($db);
494 $adht->fetch($object->typeid);
495
496 if ($object->email) {
497 $subject = '';
498 $msg = '';
499
500 // Send subscription email
501 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
502 $formmail = new FormMail($db);
503 // Set output language
504 $outputlangs = new Translate('', $conf);
505 $outputlangs->setDefaultLang(!empty($object->default_lang) ? $object->default_lang : (empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang));
506 // Load traductions files required by page
507 $outputlangs->loadLangs(array("main", "members"));
508 // Get email content from template
509 $arraydefaultmessage = null;
510 $labeltouse = getDolGlobalString('ADHERENT_EMAIL_TEMPLATE_AUTOREGISTER');
511
512 if (!empty($labeltouse)) {
513 $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
514 }
515
516 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
517 $subject = $arraydefaultmessage->topic;
518 $msg = $arraydefaultmessage->content;
519 }
520
521 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
522 complete_substitutions_array($substitutionarray, $outputlangs, $object);
523 $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
524 $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnValid()), $substitutionarray, $outputlangs);
525
526 if ($subjecttosend && $texttosend) {
527 $moreinheader = 'X-Dolibarr-Info: send_an_email by public/members/new.php'."\r\n";
528
529 $result = $object->sendEmail($texttosend, $subjecttosend, array(), array(), array(), "", "", 0, -1, '', $moreinheader);
530 }
531 /*if ($result < 0) {
532 $error++;
533 setEventMessages($object->error, $object->errors, 'errors');
534 }*/
535 }
536
537 // Send email to the foundation to say a new member subscribed with autosubscribe form
538 if (getDolGlobalString('MAIN_INFO_SOCIETE_MAIL') && getDolGlobalString('ADHERENT_AUTOREGISTER_NOTIF_MAIL_SUBJECT') &&
539 getDolGlobalString('ADHERENT_AUTOREGISTER_NOTIF_MAIL')) {
540 // Define link to login card
541 $appli = constant('DOL_APPLICATION_TITLE');
542 if (getDolGlobalString('MAIN_APPLICATION_TITLE')) {
543 $appli = getDolGlobalString('MAIN_APPLICATION_TITLE');
544 if (preg_match('/\d\.\d/', $appli)) {
545 if (!preg_match('/'.preg_quote(DOL_VERSION, '/').'/', $appli)) {
546 $appli .= " (".DOL_VERSION.")"; // If new title contains a version that is different than core
547 }
548 } else {
549 $appli .= " ".DOL_VERSION;
550 }
551 } else {
552 $appli .= " ".DOL_VERSION;
553 }
554
555 $to = $adh->makeSubstitution(getDolGlobalString('MAIN_INFO_SOCIETE_MAIL'));
556 $email_from = getDolGlobalString('ADHERENT_MAIL_FROM', $conf->email_from);
557 $mailfile = new CMailFile(
558 '['.$appli.'] ' . getDolGlobalString('ADHERENT_AUTOREGISTER_NOTIF_MAIL_SUBJECT'),
559 $to,
560 $email_from,
561 $adh->makeSubstitution(getDolGlobalString('ADHERENT_AUTOREGISTER_NOTIF_MAIL')),
562 array(),
563 array(),
564 array(),
565 "",
566 "",
567 0,
568 -1
569 );
570
571 if (!$mailfile->sendfile()) {
572 dol_syslog($langs->trans("ErrorFailedToSendMail", $email_from, $to), LOG_ERR);
573 }
574 }
575
576 // Auto-create thirdparty on member creation
577 if (getDolGlobalString('ADHERENT_DEFAULT_CREATE_THIRDPARTY')) {
578 $company = new Societe($db);
579 $result = $company->create_from_member($adh);
580 if ($result < 0) {
581 $error++;
582 $errmsg .= implode('<br>', $company->errors);
583 }
584 }
585
586 if (!empty($backtopage)) {
587 $urlback = $backtopage;
588 } elseif (getDolGlobalString('MEMBER_URL_REDIRECT_SUBSCRIPTION')) {
589 $urlback = getDolGlobalString('MEMBER_URL_REDIRECT_SUBSCRIPTION');
590 // TODO Make replacement of __AMOUNT__, etc...
591 } else {
592 $urlback = $_SERVER["PHP_SELF"]."?action=added&token=".newToken();
593 }
594
595 if (getDolGlobalString('MEMBER_NEWFORM_PAYONLINE') && getDolGlobalString('MEMBER_NEWFORM_PAYONLINE') != '-1') {
596 if (empty($adht->caneditamount)) { // If edition of amount not allowed
597 // TODO Check amount is same than the amount required for the type of member
598 // It is not so important because a test is done on return of payment validation.
599 }
600
601 $minimumamountbytype = $adht->minimumamountbytype(1); // Load the array of minimum amount per type
602 $minimumamount = empty($minimumamountbytype[$adh->typeid]) ? 0 : $minimumamountbytype[$adh->typeid];
603 $amount = price2num(GETPOST('amount', 'alpha'), 'MT');
604 $urlback = getOnlinePaymentUrl(0, 'member', $adh->ref, (float) $amount, '', 0);
605 if ($amount < max(getDolGlobalInt("MEMBER_MIN_AMOUNT"), $minimumamount)) {
606 $error++;
607 $errmsg .= $langs->trans("MinimumAmountShort")." : ".price(max(getDolGlobalInt("MEMBER_MIN_AMOUNT"), $minimumamount), 0, $langs, 1, -1, -1, $conf->currency)."<br>\n";
608 }
609
610 if (GETPOST('member_email')) {
611 $urlback .= '&email='.urlencode(GETPOST('member_email'));
612 }
613 if (getDolGlobalString('MEMBER_NEWFORM_PAYONLINE') != '-1' && getDolGlobalString('MEMBER_NEWFORM_PAYONLINE') != 'all') {
614 $urlback .= '&paymentmethod='.urlencode(getDolGlobalString('MEMBER_NEWFORM_PAYONLINE'));
615 }
616 } else {
617 if (!empty($entity)) {
618 $urlback .= '&entity='.((int) $entity);
619 }
620 }
621 } else {
622 $error++;
623 $errmsg .= implode('<br>', $adh->errors);
624 }
625 }
626 }
627
628 if (!$error) {
629 $db->commit();
630
631 header("Location: ".$urlback);
632 exit;
633 } else {
634 $db->rollback();
635 $action = "create";
636 }
637}
638
639// Action called after a submitted was send and member created successfully
640// If MEMBER_URL_REDIRECT_SUBSCRIPTION is set to an url, we never go here because a redirect was done to this url. Same if we ask to redirect to the payment page.
641// backtopage parameter with an url was set on member submit page, we never go here because a redirect was done to this url.
642
643if (empty($reshook) && $action == 'added') { // Test on permission not required here
644 llxHeaderVierge($langs->trans("NewMemberForm"));
645
646 // If we have not been redirected
647 print '<br><br>';
648 print '<div class="center">';
649 print $langs->trans("NewMemberbyWeb");
650 print '</div>';
651
653 exit;
654}
655
656
657/*
658 * View
659 */
660
661$form = new Form($db);
662$formcompany = new FormCompany($db);
663$adht = new AdherentType($db);
664$extrafields->fetch_name_optionals_label($object->table_element); // fetch optionals attributes and labels
665
666
667llxHeaderVierge($langs->trans("NewSubscription"));
668
669print '<br>';
670print load_fiche_titre(img_picto('', 'member_nocolor', 'class="pictofixedwidth"').' &nbsp; '.$langs->trans("NewSubscription"), '', '', 0, '', 'center');
671
672
673print '<div align="center">';
674print '<div id="divsubscribe">';
675
676print '<div class="center subscriptionformhelptext opacitylow justify small margintoponly"><br>';
677if (getDolGlobalString('MEMBER_NEWFORM_TEXT')) {
678 print $langs->trans(getDolGlobalString('MEMBER_NEWFORM_TEXT'))."<br>\n";
679} else {
680 print $langs->trans("NewSubscriptionDesc", getDolGlobalString("MAIN_INFO_SOCIETE_MAIL"))."<br>\n";
681}
682print '</div>';
683print '<br>';
684
685dol_htmloutput_errors($errmsg);
687
688if ($action == "subscription") {
689 $urltocall = DOL_URL_ROOT.'/public/payment/newpayment.php?source=member&ref='.$object->id;
690 print $form->formconfirm($urltocall, $langs->trans("CorrespondingMemberFound"), $langs->trans("CorrespondingMemberFoundQuestion"), "confirm_subscription", '', 'no', 1);
691}
692
693// Print form
694print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="newmember" id="newmember">'."\n";
695print '<input type="hidden" name="token" value="'.newToken().'" />';
696print '<input type="hidden" name="entity" value="'.$entity.'" />';
697print '<input type="hidden" name="page_y" value="" />';
698
699if (getDolGlobalString('MEMBER_SKIP_TABLE') || getDolGlobalString('MEMBER_NEWFORM_FORCETYPE') || in_array($action, array('create', 'subscription'))) {
700 if ($action == 'subscription') {
701 print '<input type="hidden" name="nofetchmember" value="nofetchmember" />';
702 }
703 print '<input type="hidden" name="action" value="add" />';
704 print '<br>';
705
706 //$messagemandatory = '<span class="">'.$langs->trans("FieldsWithAreMandatory", '*').'</span>';
707 //print '<br>'.$messagemandatory.'<br>';
708 //print $langs->trans("FieldsWithIsForPublic",'**').'<br>';
709
710 print dol_get_fiche_head();
711
712 if ($conf->use_javascript_ajax) {
713 print "\n".'<script type="text/javascript">'."\n";
714 print 'jQuery(document).ready(function () {
715 jQuery("#selectcountry_id").change(function() {
716 console.log("We change country, so we reload page");
717 document.newmember.action.value="create";
718 jQuery("#newmember").submit();
719 });
720 function initfieldrequired() {
721 console.log("initfieldrequired");
722 jQuery("#tdcompany").removeClass("fieldrequired");
723 jQuery("#tdlastname").removeClass("fieldrequired");
724 jQuery("#tdfirstname").removeClass("fieldrequired");
725 if (jQuery(\'input[name="morphy"]:checked\').val() == \'mor\') {
726 jQuery("#tdcompany").addClass("fieldrequired");
727 }
728 if (jQuery(\'input[name="morphy"]:checked\').val() == \'phy\') {
729 jQuery("#tdlastname").addClass("fieldrequired");
730 jQuery("#tdfirstname").addClass("fieldrequired");
731 }
732 }
733 jQuery(\'input[name="morphy"]\').change(function() {
734 initfieldrequired();
735 });
736 initfieldrequired();
737 })';
738 print '</script>'."\n";
739 }
740
741 print '<table class="border" summary="form to subscribe" id="tablesubscribe">'."\n";
742
743 // Type
744 if (!getDolGlobalString('MEMBER_NEWFORM_FORCETYPE')) {
745 $typeid = GETPOSTINT("typeid");
746 print '<tr><td class="fieldrequired titlefieldmiddle">'.$langs->trans("MemberType").'</td><td>';
747 $listetype = $adht->liste_array(1);
748 print img_picto('', $adht->picto, 'class="pictofixedwidth"');
749 if (count($listetype)) {
750 print $form->selectarray("typeid", $listetype, (GETPOSTINT('typeid') ? GETPOSTINT('typeid') : $typeid), (count($listetype) > 1 ? 1 : 0), 0, 0, '', 0, 0, 0, '', 'minwidth150 maxwidth300 widthcentpercentminusx', 1);
751 } else {
752 print '<span class="error">'.$langs->trans("NoTypeDefinedGoToSetup").'</span>';
753 }
754 print '</td></tr>'."\n";
755 } else {
756 $adht->fetch(getDolGlobalInt('MEMBER_NEWFORM_FORCETYPE'));
757 print '<input type="hidden" id="typeid" name="typeid" value="' . getDolGlobalString('MEMBER_NEWFORM_FORCETYPE').'">';
758 }
759
760 // Moral/Physic attribute
761 $morphys = [
762 "phy" => $langs->trans("Physical"),
763 "mor" => $langs->trans("Moral"),
764 ];
765 $checkednature = GETPOST("morphy", 'alpha');
766 $listetype_natures = $adht->morphyByType(1); // Load the array of morphy per typeof membership
767 $listetype_natures_json = json_encode($listetype_natures);
768
769 if (!getDolGlobalString('MEMBER_NEWFORM_FORCEMORPHY')) {
770 if (empty($checkednature) && !empty($listetype_natures[GETPOSTINT('typeid')])) {
771 $checkednature = $listetype_natures[GETPOSTINT('typeid')];
772 }
773
774 print '<tr><td class="fieldrequired titlefieldmiddle">'.$langs->trans("MemberNature")."</td><td>\n";
775
776 $disabledphy = '';
777 $disabledmor = '';
778 //$disabledphy = ($checkednature == "mor" ? ' disabled="disabled"' : '');
779 //$disabledmor = ($checkednature == "phy" ? ' disabled="disabled"' : '');
780 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>';
781 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>';
782
783 // Add JS to manage the background of nature
784 if ($conf->use_javascript_ajax) {
785 print '<script>
786 var listetype_natures = '.$listetype_natures_json.';
787
788 jQuery(function($) {
789 function refreshNatureCss() {
790 $(".spannature").each(function(index) {
791 let $span = $("#spannature" + (index + 1));
792 let checked = $span.find(".checkforselect").is(":checked");
793
794 if (checked) {
795 if (index === 0) {
796 $span.addClass("member-individual-back").removeClass("nonature-back member-company-back");
797 } else if (index === 1) {
798 $span.addClass("member-company-back").removeClass("nonature-back member-individual-back");
799 }
800 } else {
801 $span.removeClass("member-individual-back member-company-back")
802 .addClass("nonature-back");
803 }
804 });
805 }
806
807 $(".spannature").on("click", function() {
808 console.log("Nature clicked");
809 refreshNatureCss();
810 });
811
812 $("#typeid").on("change", function() {
813 console.log("Type of membership is modified");
814 let morphy = listetype_natures[$(this).val()];
815 console.log("morphy="+morphy);
816
817 let $phyInput = $("#phisicalinput");
818 let $morInput = $("#moralinput");
819 let $tdLast = $("#tdlastname");
820 let $tdFirst = $("#tdfirstname");
821 let $tdCompany = $("#tdcompany");
822 let $span1 = $("#spannature1");
823 let $span2 = $("#spannature2");
824
825 switch (morphy) {
826 case "phy":
827 $phyInput.prop({disabled: false, checked: true});
828 $morInput.prop({disabled: true, checked: false});
829 $span1.addClass("member-individual-back").removeClass("nonature-back");
830 $span2.removeClass("member-company-back").addClass("nonature-back");
831 $("#phisicalinput").prop("checked", true);
832 $tdLast.addClass("fieldrequired");
833 $tdFirst.addClass("fieldrequired");
834 $tdCompany.removeClass("fieldrequired");
835 break;
836
837 case "mor":
838 $phyInput.prop({disabled: true, checked: false});
839 $morInput.prop({disabled: false, checked: true});
840 $span2.addClass("member-company-back").removeClass("nonature-back");
841 $span1.removeClass("member-individual-back").addClass("nonature-back");
842 $("#moralinput").prop("checked", true);
843 $tdCompany.addClass("fieldrequired");
844 $tdLast.removeClass("fieldrequired");
845 $tdFirst.removeClass("fieldrequired");
846 break;
847
848 default:
849 $phyInput.prop({disabled: false});
850 $morInput.prop({disabled: false});';
851 if ($action != "subscription" && !GETPOST('morphy')) {
852 print '
853 $phyInput.prop({checked: false});
854 $morInput.prop({checked: false});
855 $span1.removeClass("member-individual-back").addClass("nonature-back");
856 $span2.removeClass("member-company-back").addClass("nonature-back");';
857 }
858 print'}
859 });
860
861 // Initial state
862 refreshNatureCss();
863 });
864 </script>';
865 }
866 print '</td></tr>'."\n";
867 } else {
868 //print $morphys[$conf->global->MEMBER_NEWFORM_FORCEMORPHY];
869 print '<input type="hidden" id="morphy" name="morphy" value="' . getDolGlobalString('MEMBER_NEWFORM_FORCEMORPHY').'">';
870 }
871
872 // Company // TODO : optional hide
873 print '<tr id="trcompany" class="trcompany"><td id="tdcompany" class="titlefieldmiddle paddingrightonly'.($checkednature == "mor" ? ' fieldrequired"' : '').'">'.$langs->trans("Company").'</td><td>';
874 print img_picto('', 'company', 'class="pictofixedwidth paddingright"');
875 print '<input type="text" name="societe" class="minwidth150 widthcentpercentminusx" value="'.dol_escape_htmltag(GETPOST('societe')).'"></td></tr>'."\n";
876
877 // Title
878 if (getDolGlobalString('MEMBER_NEWFORM_ASK_TITLE')) {
879 print '<tr><td>'.$langs->trans('UserTitle').'</td><td>';
880 print $formcompany->select_civility(GETPOST('civility_id'), 'civility_id').'</td></tr>'."\n";
881 }
882
883 // Firstname
884 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";
885
886 // Lastname
887 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";
888
889 // EMail
890 print '<tr><td>'.(getDolGlobalString('ADHERENT_MAIL_REQUIRED') ? '<span class="fieldrequired">' : '').$langs->trans("EMail").(getDolGlobalString('ADHERENT_MAIL_REQUIRED') ? '</span>' : '').'</td>';
891 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";
892
893 // Login
894 if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
895 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";
896 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";
897 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";
898 }
899
900 // Gender
901 print '<tr><td>'.$langs->trans("Gender").'</td>';
902 print '<td>';
903 $arraygender = array('man' => $langs->trans("Genderman"), 'woman' => $langs->trans("Genderwoman"), 'other' => $langs->trans("Genderother"));
904 print $form->selectarray('gender', $arraygender, GETPOST('gender', 'alphanohtml'), 1, 0, 0, '', 0, 0, 0, '', 'minwidth150 maxwidth300 widthcentpercentminusx', 1);
905 print '</td></tr>';
906
907 // Address
908 print '<tr><td>'.$langs->trans("Address").'</td><td>'."\n";
909 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";
910
911 // Zip / Town
912 print '<tr><td>'.$langs->trans('Zip').' / '.$langs->trans('Town').'</td><td>';
913 print $formcompany->select_ziptown(GETPOST('zipcode'), 'zipcode', array('town', 'selectcountry_id', 'state_id'), 0, 1, '', 'width75');
914 print ' / ';
915 print $formcompany->select_ziptown(GETPOST('town'), 'town', array('zipcode', 'selectcountry_id', 'state_id'), 0, 1);
916 print '</td></tr>';
917
918 $country_id = GETPOSTINT('country_id');
919
920 // Country
921 print '<tr><td class="fieldrequired">'.$langs->trans('Country').'</td><td>';
922 print img_picto('', 'country', 'class="pictofixedwidth paddingright"');
923 if (!$country_id && getDolGlobalString('MEMBER_NEWFORM_FORCECOUNTRYCODE')) {
924 $country_id = (int) getCountry(getDolGlobalString('MEMBER_NEWFORM_FORCECOUNTRYCODE'), '3', $db, $langs);
925 }
926 if (!$country_id && !empty($conf->geoipmaxmind->enabled)) {
927 $country_code = dol_user_country();
928 //print $country_code;
929 if ($country_code) {
930 $new_country_id = getCountry($country_code, '3', $db, $langs);
931 //print 'xxx'.$country_code.' - '.$new_country_id;
932 if ($new_country_id) {
933 $country_id = $new_country_id;
934 }
935 }
936 }
937 $country_code = getCountry($country_id, '2', $db, $langs);
938 print $form->select_country($country_id, 'country_id', '', 0, 'minwidth150 maxwidth300 widthcentpercentminusx reposition');
939 print '</td></tr>';
940
941 // State
942 if (!getDolGlobalString('SOCIETE_DISABLE_STATE')) {
943 print '<tr><td>'.$langs->trans('State').'</td><td>';
944 if ($country_code) {
945 print img_picto('', 'state', 'class="pictofixedwidth paddingright"');
946 print $formcompany->select_state(GETPOSTINT("state_id"), $country_code, 'state_id', 'minwidth150 maxwidth300 widthcentpercentminusx');
947 }
948 print '</td></tr>';
949 }
950
951 // Pro phone
952 print '<tr><td>'.$langs->trans("PhonePro").'</td>';
953 print '<td>'.img_picto('', 'object_phoning', 'class="pictofixedwidth"').'<input type="text" name="phone" class="maxwidth300 widthcentpercentminusx" value="'.dol_escape_htmltag(GETPOST('phone')).'"></td></tr>';
954
955 // Personal phone
956 print '<tr><td>'.$langs->trans("PhonePerso").'</td>';
957 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>';
958
959 // Mobile phone
960 print '<tr><td>'.$langs->trans("PhoneMobile").'</td>';
961 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>';
962
963 // Birthday
964 print '<tr id="trbirth" class="trbirth"><td>'.$langs->trans("DateOfBirth").'</td><td>';
965 print $form->selectDate(!empty($birthday) ? $birthday : "", 'birth', 0, 0, 1, "newmember", 1, 0);
966 print '</td></tr>'."\n";
967
968 // Photo
969 print '<tr><td>'.$langs->trans("URLPhoto").'</td><td><input type="text" name="photo" class="minwidth150" value="'.dol_escape_htmltag(GETPOST('photo')).'"></td></tr>'."\n";
970
971 // Public
972 if (getDolGlobalString('MEMBER_PUBLIC_ENABLED')) {
973 $linkofpubliclist = DOL_MAIN_URL_ROOT.'/public/members/public_list.php'.((isModEnabled('multicompany')) ? '?entity='.$conf->entity : '');
974 $publiclabel = $langs->trans("Public", getDolGlobalString('MAIN_INFO_SOCIETE_NOM'), $linkofpubliclist);
975 print '<tr><td>'.$form->textwithpicto($langs->trans("MembershipPublic"), $publiclabel).'</td><td><input type="checkbox" name="public"></td></tr>'."\n";
976 }
977
978 // Other attributes
979 $parameters['tpl_context'] = 'public'; // define template context to public
980 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
981
982 // Comments
983 print '<tr>';
984 print '<td class="tdtop"></td>';
985 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>';
986 print '</tr>'."\n";
987
988
989 // Define amount by default to suggest
990 $typeid = getDolGlobalInt('MEMBER_NEWFORM_FORCETYPE', GETPOSTINT('typeid'));
991 $adht = new AdherentType($db);
992 $adht->fetch($typeid);
993 $caneditamount = $adht->caneditamount;
994 $amountbytype = $adht->amountByType(1); // Load the array of amount per type
995 $minimumamountbytype = $adht->minimumamountbytype(1); // Load the array of minimum amount per type
996 foreach ($amountbytype as $k => $v) {
997 $amount = max(0, (float) $v, (float) getDolGlobalInt("MEMBER_MIN_AMOUNT"), $minimumamountbytype[$k]);
998 $amountbytype[$k] = $amount;
999 }
1000
1001 $caneditamountbytype = $adht->caneditamountByType(1); // Load the array of caneditamount per type
1002 $amountformuladescriptionbytype = $adht->amountformuladescriptionbytype(1); // Load the array of amount ormula description per type
1003
1004 // Set amount for the subscription from the type and options:
1005 // - First check the amount of the member type.
1006 $amount = empty($amountbytype[$typeid]) ? 0 : $amountbytype[$typeid];
1007 // - If not set, we accept to have amount defined as parameter (for backward compatibility).
1008 if (empty($amount)) {
1009 $amount = (GETPOST('amount') ? price2num(GETPOST('amount', 'alpha'), 'MT', 2) : '');
1010 }
1011 // - If a min is set, we take it into account
1012 $minimumamount = empty($minimumamountbytype[$typeid]) ? 0 : $minimumamountbytype[$typeid];
1013 $amount = max(0, (float) $amount, (float) getDolGlobalInt("MEMBER_MIN_AMOUNT"), (float) $minimumamount);
1014
1015 // Clean the amount
1016 $amount = price2num($amount);
1017
1018
1019 // Add hook to complete the form
1020 $parameters = array('country_id' => $country_id, 'mode' => 'new');
1021 $reshook = $hookmanager->executeHooks('membershipNewSubscriptionPublicForm', $parameters, $object, $action);
1022 if ($reshook < 0) {
1023 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1024 $error++;
1025 }
1026 // TODO Move this into previous hook
1027 if (getDolGlobalString('MEMBER_NEWFORM_DOLIBARRTURNOVER')) {
1028 $s = $langs->trans("AreYouAPreferredPartner", '<a href="https://partners.dolibarr.org" target="_blank">{s1}</a>');
1029 $s = str_replace('{s1}', 'Preferred Partner', $s);
1030 print '<tr id="trbudget" class="trcompany"><td class="paddingrightonly"><label for="pp" class="small">'.$s.'</label></td><td>';
1031 print '<input type="checkbox" name="pp" id="pp" value="1"'.(GETPOST('pp') ? ' checked="checked"' : '').' class="reposition">';
1032 print '</td></tr>';
1033
1034 print '<tr id="trbudget" class="trcompany"><td class="fieldrequired paddingrightonly"><span class="small">'.$langs->trans("TurnoverOrBudget").'</span></td><td>';
1035
1036 $country_code = dol_getIdFromCode($db, $country_id, 'c_country', 'rowid', 'code');
1037 if ($country_code === 'FR' && $checkednature === 'mor' && GETPOST('pp')) {
1038 print '<input type="text" name="budget" id="budget" class="flat turnover right width100" value="'.GETPOST('budget').'" required>';
1039 } else {
1040 $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+');
1041 print $form->selectarray('budget', $arraybudget, GETPOSTINT('budget'), 1, 0, 0, '', 0, 0, 0, '');
1042 }
1043 print ' € or $';
1044
1045 print '<script type="text/javascript">
1046 jQuery(document).ready(function() {
1047 firstload = true;
1048
1049 newamount = initturnover();
1050 jQuery("#amount").val(newamount);
1051
1052 firstload = false;
1053
1054 jQuery("#selectcountry_id").change(function() {
1055 console.log("We change country (code added for association, replace common code), so we reload page");
1056 jQuery("#budget").val(\'\');
1057 jQuery("#amount").val(\'\');
1058 jQuery("#amounthidden").val(\'\');
1059 });
1060 jQuery("#phisicalinput,#moralinput").click(function() {
1061 console.log("We change the nature of membership");
1062 newamount = initturnover();
1063 jQuery("#amount").val(newamount);
1064 });
1065 jQuery("#pp").change(function() {
1066 console.log("We change the preferred partner status");
1067 selectcountry_id = jQuery("#selectcountry_id").val();
1068 morphy = jQuery("#moralinput").is(\':checked\') ? \'mor\' : \'phy\';
1069 jQuery("#budget").val(\'\');
1070 jQuery("#amount").val(\'\');
1071 jQuery("#amounthidden").val(\'\');
1072 document.newmember.action.value="create";
1073 jQuery("#newmember").submit();
1074 });
1075 jQuery("#budget").change(function() {
1076 console.log("Turnover amount has been modified on change");
1077 newamount = initturnover();
1078 jQuery("#amount").val(newamount);
1079 jQuery("#amounthidden").val(newamount);
1080 });
1081 jQuery("#budget").keyup(function() {
1082 console.log("Turnover amount has been modified on keyup");
1083 newamount = initturnover();
1084 jQuery("#amount").val(newamount);
1085 jQuery("#amounthidden").val(newamount);
1086 });
1087
1088 function initturnover() {
1089 newamount = 0;
1090
1091 morphy = jQuery("#moralinput").is(\':checked\') ? \'mor\' : \'phy\';
1092 selectcountry_id = jQuery("#selectcountry_id").val();
1093 pp = jQuery("#pp").is(\':checked\') ? true : false;
1094 console.log("Set fields according to nature and other properties");
1095 console.log("morphy="+morphy);
1096 console.log("selectcountry_id="+selectcountry_id);
1097 console.log("pp="+pp);
1098
1099 if (morphy == \'phy\') {
1100 jQuery(".amount").val('.((float) $amount).');
1101 jQuery("#trbirth").show();
1102 jQuery(".trcompany").hide();
1103 jQuery(".trbudget").hide();
1104 newamount = '.((float) $amount).';
1105 } else {
1106 jQuery(".amount").val(\'\');
1107 jQuery("#trbirth").hide();
1108 jQuery(".trcompany").show();
1109 jQuery(".trbudget").show();
1110 jQuery(".hideifautoturnover").hide();
1111 if (firstload) {
1112 jQuery("#budget").val(\'\');
1113 }
1114
1115 if (selectcountry_id == 1) {
1116 if (pp) {
1117 console.log("value selected in input text field is "+jQuery("#budget").val());
1118 newamount = Math.max(Math.round(price2numjs(jQuery("#budget").val()) * 0.005), 50);
1119 console.log("newamount = "+newamount);
1120 } else {
1121 console.log("not a pp");
1122 if (jQuery("#budget").val() > 0) {
1123 console.log("value found in budget is "+jQuery("#budget").val());
1124 newamount = jQuery("#budget").val();
1125 } else {
1126 jQuery("#budget").val(\'\');
1127 newamount = \'\';
1128 }
1129 }
1130 } else {
1131 if (jQuery("#budget").val() > 0) {
1132 newamount = jQuery("#budget").val();
1133 } else {
1134 jQuery("#budget").val(\'\');
1135 newamount = \'\';
1136 }
1137 console.log("newamount="+newamount);
1138 }
1139 }
1140
1141 return newamount;
1142 }
1143 });
1144 </script>';
1145 print '</td></tr>'."\n";
1146 }
1147
1148 if (getDolGlobalString('MEMBER_NEWFORM_PAYONLINE')) { // Can be 'all', 'paypal', 'paybox', 'stripe'...
1149 print '<tr><td>'.$langs->trans("Subscription");
1150 if (getDolGlobalString('MEMBER_EXT_URL_SUBSCRIPTION_INFO')) {
1151 print '<br>';
1152 print '<a href="' . getDolGlobalString('MEMBER_EXT_URL_SUBSCRIPTION_INFO').'" rel="external" target="_blank" rel="noopener noreferrer">';
1153 print img_picto('', 'url', 'class="pictofixedwidth"').$langs->trans("SeeHere");
1154 print '</a>';
1155 }
1156 print '</td><td class="nowrap">';
1157
1158 $amountformuladescription = $amountformuladescriptionbytype[$typeid];
1159
1160 $showedamount = $amount > 0 ? $amount : 0;
1161 if ($caneditamount === "1") {
1162 print '<input type="text" name="amount" id="amount" class="flat amount right width75" value="'.$showedamount.'">';
1163 print '<input type="text" name="amount" id="amounthidden" class="flat amount width75 hidden" disabled value="'.$showedamount.'">';
1164 print ' '.$langs->getCurrencySymbol($conf->currency).'<span class="opacitymedium amountdescription hideifautoturnover small">';
1165 if (!getDolGlobalString('MEMBER_NEWFORM_DOLIBARRTURNOVER')) {
1166 print ' - ';
1167 if (empty($amountformuladescription)) {
1168 print $amount > 0 ? $langs->trans("AnyAmountWithAdvisedAmount", price($amount, 0, $langs, 1, -1, -1, $conf->currency)) : $langs->trans("AnyAmountWithoutAdvisedAmount");
1169 } else {
1170 print $amountformuladescription;
1171 }
1172 }
1173 if (getDolGlobalInt("MEMBER_MIN_AMOUNT") > 0 || $minimumamount > 0) {
1174 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);
1175 }
1176 print '</span>';
1177 } else {
1178 print '<input type="text" name="amount" id="amount" class="flat amount width75 right hidden" value="'.$showedamount.'">';
1179 print '<input type="text" name="amount" id="amounthidden" class="flat amount width75" disabled value="'.$showedamount.'">';
1180 print ' '.$langs->getCurrencySymbol($conf->currency).'<span class="opacitymedium amountdescription hideifautoturnover hidden small">';
1181 if (!getDolGlobalString('MEMBER_NEWFORM_DOLIBARRTURNOVER')) {
1182 print ' - ';
1183 print $amount > 0 ? $langs->trans("AnyAmountWithAdvisedAmount", price($amount, 0, $langs, 1, -1, -1, $conf->currency)) : $langs->trans("AnyAmountWithoutAdvisedAmount");
1184 }
1185 print '</span>';
1186 }
1187 print '</td></tr>';
1188 }
1189
1190 // Display Captcha code if is enabled
1191 if (getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_MEMBER') && is_object($captchaobj)) {
1192 print '<tr><td><label><span class="fieldrequired">'.$langs->trans("SecurityCode").'</span></label></td><td><br>';
1193 if (method_exists($captchaobj, 'getCaptchaCodeForForm')) {
1194 print $captchaobj->getCaptchaCodeForForm(''); // @phan-suppress-current-line PhanUndeclaredMethod
1195 } else {
1196 print 'Error, the captcha handler '.get_class($captchaobj).' does not have any method getCaptchaCodeForForm()';
1197 }
1198 print '<br></td></tr>';
1199 }
1200
1201 print "</table>\n";
1202
1203 print dol_get_fiche_end();
1204
1205 // Save / Submit
1206 print '<div class="center">';
1207 print '<input type="submit" value="'.$langs->trans("GetMembershipButtonLabel").'" id="submitsave" class="button">';
1208 if (!empty($backtopage)) {
1209 print ' &nbsp; &nbsp; <input type="submit" value="'.$langs->trans("Cancel").'" id="submitcancel" class="button button-cancel">';
1210 }
1211 print '</div>';
1212
1213 // Add JS to manage the background of amount depending on type
1214 $typeid = getDolGlobalInt('MEMBER_NEWFORM_FORCETYPE', GETPOSTINT('typeid'));
1215 $adht = new AdherentType($db);
1216 $adht->fetch($typeid);
1217 $caneditamountbytype = $adht->caneditamountByType(1); // Load the array of caneditamount per type
1218 $minimumamountbytype = $adht->minimumamountbytype(1); // Load the array of minimum amount per type
1219 $amountbytype = $adht->amountByType(1); // Load the array of amount per type
1220 $amountformuladescriptionbytype = $adht->amountformuladescriptionbytype(1); // Load the array of amount ormula description per type
1221 // Common PHP → JS variables
1222 $caneditamountbytype_json = json_encode($caneditamountbytype);
1223 $minimumamountbytype_json = json_encode($minimumamountbytype);
1224 $amountbytype_json = json_encode($amountbytype);
1225 $amountformuladescriptionbytype_json = json_encode($amountformuladescriptionbytype);
1226 $currencysymbol = $langs->getCurrencySymbol($conf->currency);
1227
1228 if ($conf->use_javascript_ajax) {
1229 print '<script>
1230 // ----- Shared data -----
1231 var amountByType = ' . $amountbytype_json . ';
1232 var canEditAmountByType = ' . $caneditamountbytype_json . ';
1233 var amountFormulaDescriptionByType = ' . $amountformuladescriptionbytype_json . ';
1234 var minimumAmountByType = ' . $minimumamountbytype_json . ';
1235 var memberMinAmount = ' . getDolGlobalInt("MEMBER_MIN_AMOUNT") . ';
1236 var currencySymbol = ' . json_encode($currencysymbol) . ';
1237
1238 // Translations prepared by PHP
1239 var langs = {
1240 AnyAmountWithAdvisedAmount: ' . json_encode($langs->trans("AnyAmountWithAdvisedAmount", "__VAL__")) . ',
1241 AnyAmountWithoutAdvisedAmount: ' . json_encode($langs->trans("AnyAmountWithoutAdvisedAmount")) . ',
1242 MinimumAmountShort: ' . json_encode($langs->trans("MinimumAmountShort", "__VAL__")) . ',
1243 trans: function(key, val) {
1244 if (!this[key]) return key;
1245 return this[key].replace("__VAL__", val || "");
1246 }
1247 };
1248
1249 jQuery(function($) {
1250 // ----- Helpers -----
1251 function getCurrentMin() {
1252 let typeId = $("#typeid").val() || 0;
1253 let minimumAmount = minimumAmountByType[typeId] || 0;
1254 return Math.max(memberMinAmount, minimumAmount);
1255 }
1256
1257 function checkAmount() {
1258 let raw = $("#amount").val() || "";
1259 let val = parseFloat(raw.replace(",", ".")) || 0;
1260 let minimum = getCurrentMin();
1261 if (val < minimum) {
1262 $("#submitsave").prop("disabled", true);
1263 } else {
1264 $("#submitsave").prop("disabled", false);
1265 }
1266 }
1267
1268 function updateAmountAndTexts() {
1269 let typeId = $("#typeid").val();
1270 let amountVal = amountByType[typeId] || 0;
1271 let formattedAmount = parseFloat(amountVal);
1272 let canEdit = canEditAmountByType[typeId] === "1";
1273 let amountFormulaDescription = amountFormulaDescriptionByType[typeId] || "";
1274 let minimumAmount = minimumAmountByType[typeId] || 0;
1275 let minimum = Math.max(memberMinAmount, minimumAmount);
1276
1277 if (canEdit) {
1278 // Editable mode
1279 $("#amount").val(formattedAmount).prop("disabled", false).removeClass("hidden");
1280 $("#amounthidden").addClass("hidden");
1281 $(".hideifautoturnover").removeClass("hidden");
1282
1283 // Description formula or default text
1284 if (amountFormulaDescription.trim() !== "") {
1285 $(".amountdescription").html(" - " + amountFormulaDescription);
1286 } else {
1287 if (amountVal > 0) {
1288 $(".amountdescription").html(" - " + langs.trans("AnyAmountWithAdvisedAmount", formattedAmount + " " + currencySymbol));
1289 } else {
1290 $(".amountdescription").html(" - " + langs.trans("AnyAmountWithoutAdvisedAmount"));
1291 }
1292 }
1293
1294 // Minimum amount label
1295 if (minimum > 0) {
1296 $("#minimumamount")
1297 .html(langs.trans("MinimumAmountShort") + " : " + minimum + " " + currencySymbol)
1298 .removeClass("hidden");
1299 } else {
1300 $("#minimumamount").addClass("hidden");
1301 }
1302 } else {
1303 // Read-only mode
1304 $("#amounthidden").val(formattedAmount).prop("disabled", true).removeClass("hidden");
1305 $("#amount").addClass("hidden");
1306 $(".hideifautoturnover").addClass("hidden");
1307 $("#minimumamount").addClass("hidden");
1308 }
1309
1310 // After updating fields, re‑check the amount validity
1311 checkAmount();
1312 }
1313
1314 // ----- Bind events -----
1315 $("#typeid").on("change", function() {
1316 console.log("Type of membership changed, update amount, description and minimum");
1317 updateAmountAndTexts();
1318 });
1319
1320 $("#amount").on("keyup change", function() {
1321 checkAmount();
1322 });
1323 });
1324 </script>';
1325 }
1326
1327 print "</form>\n";
1328 print "<br>";
1329 print '</div></div>';
1330} else { // Show the table of membership types
1331 // Get units
1332 $measuringUnits = new CUnits($db);
1333 $result = $measuringUnits->fetchAll('', '', 0, 0, array('t.active' => 1));
1334 $units = array();
1335 foreach ($measuringUnits->records as $lines) {
1336 $units[$lines->short_label] = $langs->trans(ucfirst((string) $lines->label));
1337 }
1338
1339 $publiccounters = getDolGlobalString("MEMBER_COUNTERS_ARE_PUBLIC");
1340 $hidevoteallowed = getDolGlobalString("MEMBER_HIDE_VOTE_ALLOWED");
1341
1342 $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,";
1343 $sql .= " COUNT(a.rowid) AS membercount";
1344 $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as d";
1345 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."adherent as a";
1346 $sql .= " ON d.rowid = a.fk_adherent_type AND a.statut > 0";
1347 $sql .= " WHERE d.entity IN (".getEntity('member_type').")";
1348 $sql .= " AND d.statut=1";
1349 $sql .= " GROUP BY d.rowid, d.libelle, d.subscription, d.amount, d.caneditamount, d.vote, d.note, d.duration, d.statut, d.morphy";
1350
1351 $result = $db->query($sql);
1352 if ($result) {
1353 $num = $db->num_rows($result);
1354
1355 print '<br><div class="div-table-responsive">';
1356 print '<table class="tagtable liste noborder">'."\n";
1357 print '<input type="hidden" name="action" value="create">';
1358
1359 print '<tr class="liste_titre">';
1360 print '<th>'.$langs->trans("Label").'</th>';
1361 print '<th class="center">'.$langs->trans("MembershipDuration").'</th>';
1362 print '<th class="center">'.$langs->trans("RecommendedAmount").'</th>';
1363 print '<th class="center">'.$langs->trans("MembersNature").'</th>';
1364 if (empty($hidevoteallowed)) {
1365 print '<th class="center">'.$langs->trans("VoteAllowed").'</th>';
1366 }
1367 if ($publiccounters) {
1368 print '<th class="center">'.$langs->trans("Members").'</th>';
1369 }
1370 print '<th class="center"></th>';
1371 print "</tr>\n";
1372
1373 $i = 0;
1374 while ($i < $num) {
1375 $objp = $db->fetch_object($result); // Load the member type and information on it
1376
1377 $caneditamount = $objp->caneditamount;
1378 $amountbytype = $adht->amountByType(1); // Load the array of amount per type
1379 $minimumamountbytype = $adht->minimumamountbytype(1); // Load the array of amount per type
1380
1381 print '<tr class="oddeven">';
1382
1383 // Label
1384 print '<td>';
1385 print '<div class="twolinesmax-normallineheight minwidth200onall">';
1386 print dolPrintHTML($objp->label);
1387 print '</div>';
1388 print '</td>';
1389
1390 // Duration
1391 print '<td class="center">';
1392 $unit = preg_replace("/[^a-zA-Z]+/", "", $objp->duration);
1393 print '<span class="badge badge-primary">';
1394 print max(1, intval($objp->duration)).' '.$units[$unit];
1395 print '</span>';
1396 print '</td>';
1397
1398 // Amount
1399 print '<td class="center"><span class="amount nowrap">';
1400
1401 // Set amount for the subscription from the the type and options:
1402 // - First check the amount of the member type.
1403 $amount = empty($amountbytype[$objp->rowid]) ? 0 : $amountbytype[$objp->rowid];
1404 $minimumamount = empty($minimumamountbytype[$objp->rowid]) ? 0 : $minimumamountbytype[$objp->rowid];
1405 // - If not set, we accept to have amount defined as parameter (for backward compatibility).
1406 if (empty($amount)) {
1407 $amount = (GETPOST('amount') ? price2num(GETPOST('amount', 'alpha'), 'MT', 2) : '');
1408 }
1409 // - If a min is set, we take it into account
1410 $amount = max(0, (float) $amount, (float) getDolGlobalInt("MEMBER_MIN_AMOUNT"), (float) $minimumamount);
1411
1412 $displayedamount = $amount;
1413
1414 if ($objp->subscription) {
1415 if ($displayedamount > 0 || !$caneditamount) {
1416 print price($displayedamount, 1, $langs, 1, 0, -1, $conf->currency);
1417 }
1418 if ($caneditamount && $displayedamount > 0) {
1419 print $form->textwithpicto('', $langs->transnoentities("CanEditAmountShortForValues"), 1, 'help', '', 0, 3);
1420 } elseif ($caneditamount) {
1421 print $langs->transnoentities("CanEditAmountShort");
1422 }
1423 } else {
1424 print "–"; // No subscription required
1425 }
1426 print '</span></td>';
1427
1428 print '<td class="center minwidth100">';
1429 if ($objp->morphy == 'phy') {
1430 print $langs->trans("Physical");
1431 } elseif ($objp->morphy == 'mor') {
1432 print $langs->trans("Moral");
1433 } else {
1434 print $langs->trans("MorAndPhy");
1435 }
1436 print '</td>';
1437
1438 if (empty($hidevoteallowed)) {
1439 print '<td class="center">'.yn($objp->vote).'</td>';
1440 }
1441 $membercount = $objp->membercount > 0 ? $objp->membercount : "–";
1442 if ($publiccounters) {
1443 print '<td class="center">'.$membercount.'</td>';
1444 }
1445 print '<td class="center"><button class="button button-save reposition" name="typeid" type="submit" name="submit" value="'.$objp->rowid.'">'.$langs->trans("GetMembershipButtonLabel").'</button></td>';
1446 print "</tr>";
1447 $i++;
1448 }
1449
1450 // If no record found
1451 if ($num == 0) {
1452 $colspan = 8;
1453 print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
1454 }
1455
1456 print "</table>";
1457 print '</div>';
1458
1459 print '</form>';
1460 } else {
1462 }
1463}
1464
1465//htmlPrintOnlineFooter($mysoc, $langs);
1467
1468$db->close();
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Class to manage members of a foundation.
Class to manage members type.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Class of dictionary type of thirdparty (used by imports)
Class to manage standard extra fields.
Class to build HTML component for third parties management Only common components are here.
Class to manage generation of HTML components Only common components must be here.
Class to manage a HTML form to send a unitary email Usage: $formail = new FormMail($db) $formmail->pr...
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
llxHeaderVierge($title, $head="", $disablejs=0, $disablehead=0, $arrayofjs=[], $arrayofcss=[], $ws='')
Show header for new prospect.
Definition new.php:123
llxFooterVierge()
Show footer for new societe.
Definition new.php:144
htmlPrintOnlineHeader($mysoc, $langs, $showlogo=1, $alttext='', $subimageconst='', $altlogo1='', $altlogo2='')
Show the header of a company in HTML public pages.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
global $mysoc
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0, $tz='')
Add a delay to a date.
Definition date.lib.php:129
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dolPrintHTML($s, $allowiframe=0, $moreallowedtags=array())
Return a string (that can be on several lines) ready to be output on a HTML page.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_user_country()
Return country code for current user.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
printCommonFooter($zone='private')
Print common footer : conf->global->MAIN_HTML_FOOTER js for switch of menu hider js for conf->global-...
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTFLOAT($paramname, $rounding='', $option=2)
Return the value of a $_GET or $_POST supervariable, converted into float.
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...
dol_htmloutput_events($disabledoutputofmessages=0)
Print formatted messages to output (Used to show messages on html output).
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...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getUserRemoteIP($trusted=0)
Return the real IP of remote user.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_htmloutput_errors($mesgstring='', $mesgarray=array(), $keepembedded=0)
Print formatted error messages to output (Used to show messages on html output).
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs=array(), $arrayofcss=array(), $disableforlogin=0, $disablenofollow=0, $disablenoindex=0)
Output html header of a page.
if(getDolGlobalString( 'MAIN_SECURITY_ENABLECAPTCHA_MEMBER')) force_switch_entity($newEntity)
Force switching conf of entity, even if user is connected Fox example when trying to go on public for...
Definition new.php:153
httponly_accessforbidden($message='1', $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.