dolibarr  17.0.4
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-2019 Frédéric France <frederic.france@netlogic.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  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <https://www.gnu.org/licenses/>.
24  */
25 
42 if (!defined('NOLOGIN')) {
43  define("NOLOGIN", 1); // This means this output page does not require to be logged.
44 }
45 if (!defined('NOCSRFCHECK')) {
46  define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
47 }
48 if (!defined('NOBROWSERNOTIF')) {
49  define('NOBROWSERNOTIF', '1');
50 }
51 if (!defined('NOIPCHECK')) {
52  define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
53 }
54 
55 // For MultiCompany module.
56 // Do not use GETPOST here, function is not defined and define must be done before including main.inc.php
57 $entity = (!empty($_GET['entity']) ? (int) $_GET['entity'] : (!empty($_POST['entity']) ? (int) $_POST['entity'] : 1));
58 if (is_numeric($entity)) {
59  define("DOLENTITY", $entity);
60 }
61 
62 
63 // Load Dolibarr environment
64 require '../../main.inc.php';
65 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
66 require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
67 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
68 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
69 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
70 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
71 require_once DOL_DOCUMENT_ROOT.'/core/class/cunits.class.php';
72 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
73 
74 // Init vars
75 $backtopage = GETPOST('backtopage', 'alpha');
76 $action = GETPOST('action', 'aZ09');
77 
78 $errmsg = '';
79 $num = 0;
80 $error = 0;
81 
82 // Load translation files
83 $langs->loadLangs(array("main", "members", "companies", "install", "other"));
84 
85 // Security check
86 if (empty($conf->adherent->enabled)) {
87  httponly_accessforbidden('Module Membership not enabled');
88 }
89 
90 if (empty($conf->global->MEMBER_ENABLE_PUBLIC)) {
91  httponly_accessforbidden("Auto subscription form for public visitors has not been enabled");
92 }
93 
94 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
95 $hookmanager->initHooks(array('publicnewmembercard', 'globalcard'));
96 
97 $extrafields = new ExtraFields($db);
98 
99 $object = new Adherent($db);
100 
101 $user->loadDefaultValues();
102 
103 
115 function llxHeaderVierge($title, $head = "", $disablejs = 0, $disablehead = 0, $arrayofjs = '', $arrayofcss = '')
116 {
117  global $user, $conf, $langs, $mysoc;
118 
119  top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss); // Show html headers
120 
121  print '<body id="mainbody" class="publicnewmemberform">';
122 
123  // Define urllogo
124  $urllogo = DOL_URL_ROOT.'/theme/common/login_logo.png';
125 
126  if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small)) {
127  $urllogo = DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file='.urlencode('logos/thumbs/'.$mysoc->logo_small);
128  } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$mysoc->logo)) {
129  $urllogo = DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file='.urlencode('logos/'.$mysoc->logo);
130  } elseif (is_readable(DOL_DOCUMENT_ROOT.'/theme/dolibarr_logo.svg')) {
131  $urllogo = DOL_URL_ROOT.'/theme/dolibarr_logo.svg';
132  }
133 
134  print '<div class="center">';
135 
136  // Output html code for logo
137  if ($urllogo) {
138  print '<div class="backgreypublicpayment">';
139  print '<div class="logopublicpayment">';
140  print '<img id="dolpaymentlogo" src="'.$urllogo.'">';
141  print '</div>';
142  if (empty($conf->global->MAIN_HIDE_POWERED_BY)) {
143  print '<div class="poweredbypublicpayment opacitymedium right"><a class="poweredbyhref" href="https://www.dolibarr.org?utm_medium=website&utm_source=poweredby" target="dolibarr" rel="noopener">'.$langs->trans("PoweredBy").'<br><img class="poweredbyimg" src="'.DOL_URL_ROOT.'/theme/dolibarr_logo.svg" width="80px"></a></div>';
144  }
145  print '</div>';
146  }
147 
148  if (!empty($conf->global->MEMBER_IMAGE_PUBLIC_REGISTRATION)) {
149  print '<div class="backimagepublicregistration">';
150  print '<img id="idEVENTORGANIZATION_IMAGE_PUBLIC_INTERFACE" src="'.$conf->global->MEMBER_IMAGE_PUBLIC_REGISTRATION.'">';
151  print '</div>';
152  }
153 
154  print '</div>';
155 
156  print '<div class="divmainbodylarge">';
157 }
158 
164 function llxFooterVierge()
165 {
166  print '</div>';
167 
168  printCommonFooter('public');
169 
170  print "</body>\n";
171  print "</html>\n";
172 }
173 
174 
175 
176 /*
177  * Actions
178  */
179 
180 $parameters = array();
181 // Note that $action and $object may have been modified by some hooks
182 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
183 if ($reshook < 0) {
184  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
185 }
186 
187 // Action called when page is submitted
188 if (empty($reshook) && $action == 'add') {
189  $error = 0;
190  $urlback = '';
191 
192  $db->begin();
193 
194  // test if login already exists
195  if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
196  if (!GETPOST('login')) {
197  $error++;
198  $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Login"))."<br>\n";
199  }
200  $sql = "SELECT login FROM ".MAIN_DB_PREFIX."adherent WHERE login = '".$db->escape(GETPOST('login'))."'";
201  $result = $db->query($sql);
202  if ($result) {
203  $num = $db->num_rows($result);
204  }
205  if ($num != 0) {
206  $error++;
207  $langs->load("errors");
208  $errmsg .= $langs->trans("ErrorLoginAlreadyExists")."<br>\n";
209  }
210  if (!GETPOSTISSET("pass1") || !GETPOSTISSET("pass2") || GETPOST("pass1", 'none') == '' || GETPOST("pass2", 'none') == '' || GETPOST("pass1", 'none') != GETPOST("pass2", 'none')) {
211  $error++;
212  $langs->load("errors");
213  $errmsg .= $langs->trans("ErrorPasswordsMustMatch")."<br>\n";
214  }
215  if (!GETPOST('email')) {
216  $error++;
217  $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("EMail"))."<br>\n";
218  }
219  }
220  if (GETPOST('typeid') <= 0) {
221  $error++;
222  $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type"))."<br>\n";
223  }
224  if (!in_array(GETPOST('morphy'), array('mor', 'phy'))) {
225  $error++;
226  $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv('Nature'))."<br>\n";
227  }
228  if (!GETPOST('lastname')) {
229  $error++;
230  $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Lastname"))."<br>\n";
231  }
232  if (!GETPOST('firstname')) {
233  $error++;
234  $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Firstname"))."<br>\n";
235  }
236  if (!empty($conf->global->ADHERENT_MAIL_REQUIRED) && empty(GETPOST('email'))) {
237  $error++;
238  $errmsg .= $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Email'))."<br>\n";
239  } elseif (GETPOST("email") && !isValidEmail(GETPOST("email"))) {
240  $langs->load('errors');
241  $error++;
242  $errmsg .= $langs->trans("ErrorBadEMail", GETPOST("email"))."<br>\n";
243  }
244  $birthday = dol_mktime(GETPOST("birthhour", 'int'), GETPOST("birthmin", 'int'), GETPOST("birthsec", 'int'), GETPOST("birthmonth", 'int'), GETPOST("birthday", 'int'), GETPOST("birthyear", 'int'));
245  if (GETPOST("birthmonth") && empty($birthday)) {
246  $error++;
247  $langs->load("errors");
248  $errmsg .= $langs->trans("ErrorBadDateFormat")."<br>\n";
249  }
250  if (!empty($conf->global->MEMBER_NEWFORM_DOLIBARRTURNOVER)) {
251  if (GETPOST("morphy") == 'mor' && GETPOST('budget') <= 0) {
252  $error++;
253  $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("TurnoverOrBudget"))."<br>\n";
254  }
255  }
256 
257  $public = GETPOSTISSET('public') ? 1 : 0;
258 
259  if (!$error) {
260  // E-mail looks OK and login does not exist
261  $adh = new Adherent($db);
262  $adh->statut = -1;
263  $adh->public = $public;
264  $adh->firstname = GETPOST('firstname');
265  $adh->lastname = GETPOST('lastname');
266  $adh->gender = GETPOST('gender');
267  $adh->civility_id = GETPOST('civility_id');
268  $adh->societe = GETPOST('societe');
269  $adh->address = GETPOST('address');
270  $adh->zip = GETPOST('zipcode');
271  $adh->town = GETPOST('town');
272  $adh->email = GETPOST('email');
273  if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
274  $adh->login = GETPOST('login');
275  $adh->pass = GETPOST('pass1');
276  }
277  $adh->photo = GETPOST('photo');
278  $adh->country_id = getDolGlobalString("MEMBER_NEWFORM_FORCECOUNTRYCODE", GETPOST('country_id', 'int'));
279  $adh->state_id = GETPOST('state_id', 'int');
280  $adh->typeid = getDolGlobalString("MEMBER_NEWFORM_FORCETYPE", GETPOST('typeid', 'int'));
281  $adh->note_private = GETPOST('note_private');
282  $adh->morphy = getDolGlobalString("MEMBER_NEWFORM_FORCEMORPHY", GETPOST('morphy'));
283  $adh->birth = $birthday;
284 
285  $adh->ip = getUserRemoteIP();
286 
287  $nb_post_max = getDolGlobalInt("MAIN_SECURITY_MAX_POST_ON_PUBLIC_PAGES_BY_IP_ADDRESS", 200);
288  $now = dol_now();
289  $minmonthpost = dol_time_plus_duree($now, -1, "m");
290  // Calculate nb of post for IP
291  $nb_post_ip = 0;
292  if ($nb_post_max > 0) { // Calculate only if there is a limit to check
293  $sql = "SELECT COUNT(ref) as nb_adh";
294  $sql .= " FROM ".MAIN_DB_PREFIX."adherent";
295  $sql .= " WHERE ip = '".$db->escape($adh->ip)."'";
296  $sql .= " AND datec > '".$db->idate($minmonthpost)."'";
297  $resql = $db->query($sql);
298  if ($resql) {
299  $num = $db->num_rows($resql);
300  $i = 0;
301  while ($i < $num) {
302  $i++;
303  $obj = $db->fetch_object($resql);
304  $nb_post_ip = $obj->nb_adh;
305  }
306  }
307  }
308 
309 
310  // Fill array 'array_options' with data from add form
311  $extrafields->fetch_name_optionals_label($adh->table_element);
312  $ret = $extrafields->setOptionalsFromPost(null, $adh);
313  if ($ret < 0) {
314  $error++;
315  $errmsg .= $adh->error;
316  }
317 
318  if ($nb_post_max > 0 && $nb_post_ip >= $nb_post_max) {
319  $error++;
320  $errmsg .= $langs->trans("AlreadyTooMuchPostOnThisIPAdress");
321  array_push($adh->errors, $langs->trans("AlreadyTooMuchPostOnThisIPAdress"));
322  }
323 
324  if (!$error) {
325  $result = $adh->create($user);
326  if ($result > 0) {
327  require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
328  $object = $adh;
329 
330  $adht = new AdherentType($db);
331  $adht->fetch($object->typeid);
332 
333  if ($object->email) {
334  $subject = '';
335  $msg = '';
336 
337  // Send subscription email
338  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
339  $formmail = new FormMail($db);
340  // Set output language
341  $outputlangs = new Translate('', $conf);
342  $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
343  // Load traductions files required by page
344  $outputlangs->loadLangs(array("main", "members"));
345  // Get email content from template
346  $arraydefaultmessage = null;
347  $labeltouse = $conf->global->ADHERENT_EMAIL_TEMPLATE_AUTOREGISTER;
348 
349  if (!empty($labeltouse)) {
350  $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
351  }
352 
353  if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
354  $subject = $arraydefaultmessage->topic;
355  $msg = $arraydefaultmessage->content;
356  }
357 
358  $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
359  complete_substitutions_array($substitutionarray, $outputlangs, $object);
360  $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
361  $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnValid()), $substitutionarray, $outputlangs);
362 
363  if ($subjecttosend && $texttosend) {
364  $moreinheader = 'X-Dolibarr-Info: send_an_email by public/members/new.php'."\r\n";
365 
366  $result = $object->send_an_email($texttosend, $subjecttosend, array(), array(), array(), "", "", 0, -1, '', $moreinheader);
367  }
368  /*if ($result < 0) {
369  $error++;
370  setEventMessages($object->error, $object->errors, 'errors');
371  }*/
372  }
373 
374  // Send email to the foundation to say a new member subscribed with autosubscribe form
375  if (!empty($conf->global->MAIN_INFO_SOCIETE_MAIL) && !empty($conf->global->ADHERENT_AUTOREGISTER_NOTIF_MAIL_SUBJECT) &&
376  !empty($conf->global->ADHERENT_AUTOREGISTER_NOTIF_MAIL)) {
377  // Define link to login card
378  $appli = constant('DOL_APPLICATION_TITLE');
379  if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
380  $appli = $conf->global->MAIN_APPLICATION_TITLE;
381  if (preg_match('/\d\.\d/', $appli)) {
382  if (!preg_match('/'.preg_quote(DOL_VERSION).'/', $appli)) {
383  $appli .= " (".DOL_VERSION.")"; // If new title contains a version that is different than core
384  }
385  } else {
386  $appli .= " ".DOL_VERSION;
387  }
388  } else {
389  $appli .= " ".DOL_VERSION;
390  }
391 
392  $to = $adh->makeSubstitution($conf->global->MAIN_INFO_SOCIETE_MAIL);
393  $from = $conf->global->ADHERENT_MAIL_FROM;
394  $mailfile = new CMailFile(
395  '['.$appli.'] '.$conf->global->ADHERENT_AUTOREGISTER_NOTIF_MAIL_SUBJECT,
396  $to,
397  $from,
398  $adh->makeSubstitution($conf->global->ADHERENT_AUTOREGISTER_NOTIF_MAIL),
399  array(),
400  array(),
401  array(),
402  "",
403  "",
404  0,
405  -1
406  );
407 
408  if (!$mailfile->sendfile()) {
409  dol_syslog($langs->trans("ErrorFailedToSendMail", $from, $to), LOG_ERR);
410  }
411  }
412 
413  // Auto-create thirdparty on member creation
414  if (!empty($conf->global->ADHERENT_DEFAULT_CREATE_THIRDPARTY)) {
415  $company = new Societe($db);
416  $result = $company->create_from_member($adh);
417  if ($result < 0) {
418  $error++;
419  $errmsg .= join('<br>', $company->errors);
420  }
421  }
422 
423  if (!empty($backtopage)) {
424  $urlback = $backtopage;
425  } elseif (!empty($conf->global->MEMBER_URL_REDIRECT_SUBSCRIPTION)) {
426  $urlback = $conf->global->MEMBER_URL_REDIRECT_SUBSCRIPTION;
427  // TODO Make replacement of __AMOUNT__, etc...
428  } else {
429  $urlback = $_SERVER["PHP_SELF"]."?action=added&token=".newToken();
430  }
431 
432  if (!empty($conf->global->MEMBER_NEWFORM_PAYONLINE) && $conf->global->MEMBER_NEWFORM_PAYONLINE != '-1') {
433  if (empty($adht->caneditamount)) { // If edition of amount not allowed
434  // TODO Check amount is same than the amount required for the type of member or if not defined as the defeault amount into $conf->global->MEMBER_NEWFORM_AMOUNT
435  // It is not so important because a test is done on return of payment validation.
436  }
437 
438  $urlback = getOnlinePaymentUrl(0, 'member', $adh->ref, price2num(GETPOST('amount', 'alpha'), 'MT'), '', 0);
439 
440  if (GETPOST('email')) {
441  $urlback .= '&email='.urlencode(GETPOST('email'));
442  }
443  if ($conf->global->MEMBER_NEWFORM_PAYONLINE != '-1' && $conf->global->MEMBER_NEWFORM_PAYONLINE != 'all') {
444  $urlback .= '&paymentmethod='.urlencode($conf->global->MEMBER_NEWFORM_PAYONLINE);
445  }
446  } else {
447  if (!empty($entity)) {
448  $urlback .= '&entity='.((int) $entity);
449  }
450  }
451  } else {
452  $error++;
453  $errmsg .= join('<br>', $adh->errors);
454  }
455  }
456  }
457 
458  if (!$error) {
459  $db->commit();
460 
461  Header("Location: ".$urlback);
462  exit;
463  } else {
464  $db->rollback();
465  $action = "create";
466  }
467 }
468 
469 // Action called after a submitted was send and member created successfully
470 // 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.
471 // backtopage parameter with an url was set on member submit page, we never go here because a redirect was done to this url.
472 
473 if (empty($reshook) && $action == 'added') {
474  llxHeaderVierge($langs->trans("NewMemberForm"));
475 
476  // If we have not been redirected
477  print '<br><br>';
478  print '<div class="center">';
479  print $langs->trans("NewMemberbyWeb");
480  print '</div>';
481 
482  llxFooterVierge();
483  exit;
484 }
485 
486 
487 
488 /*
489  * View
490  */
491 
492 $form = new Form($db);
493 $formcompany = new FormCompany($db);
494 $adht = new AdherentType($db);
495 $extrafields->fetch_name_optionals_label($object->table_element); // fetch optionals attributes and labels
496 
497 
498 llxHeaderVierge($langs->trans("NewSubscription"));
499 
500 print '<br>';
501 print load_fiche_titre($langs->trans("NewSubscription"), '', '', 0, 0, 'center');
502 
503 
504 print '<div align="center">';
505 print '<div id="divsubscribe">';
506 
507 print '<div class="center subscriptionformhelptext opacitymedium justify">';
508 if (!empty($conf->global->MEMBER_NEWFORM_TEXT)) {
509  print $langs->trans($conf->global->MEMBER_NEWFORM_TEXT)."<br>\n";
510 } else {
511  print $langs->trans("NewSubscriptionDesc", getDolGlobalString("MAIN_INFO_SOCIETE_MAIL"))."<br>\n";
512 }
513 print '</div>';
514 
515 dol_htmloutput_errors($errmsg);
517 
518 // Print form
519 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="newmember">'."\n";
520 print '<input type="hidden" name="token" value="'.newToken().'" / >';
521 print '<input type="hidden" name="entity" value="'.$entity.'" />';
522 
523 if (!empty($conf->global->MEMBER_SKIP_TABLE) || !empty($conf->global->MEMBER_NEWFORM_FORCETYPE) || $action == 'create') {
524  print '<input type="hidden" name="action" value="add" />';
525  print '<br>';
526  print '<br><span class="opacitymedium">'.$langs->trans("FieldsWithAreMandatory", '*').'</span><br>';
527  //print $langs->trans("FieldsWithIsForPublic",'**').'<br>';
528 
529  print dol_get_fiche_head('');
530 
531  print '<script type="text/javascript">
532  jQuery(document).ready(function () {
533  jQuery(document).ready(function () {
534  function initmorphy()
535  {
536  console.log("Call initmorphy");
537  if (jQuery("#morphy").val() == \'phy\') {
538  jQuery("#trcompany").hide();
539  }
540  if (jQuery("#morphy").val() == \'mor\') {
541  jQuery("#trcompany").show();
542  }
543  };
544  initmorphy();
545  jQuery("#morphy").change(function() {
546  initmorphy();
547  });
548  jQuery("#selectcountry_id").change(function() {
549  document.newmember.action.value="create";
550  document.newmember.submit();
551  });
552  jQuery("#typeid").change(function() {
553  document.newmember.action.value="create";
554  document.newmember.submit();
555  });
556  });
557  });
558  </script>';
559 
560 
561  print '<table class="border" summary="form to subscribe" id="tablesubscribe">'."\n";
562 
563  // Type
564  if (empty($conf->global->MEMBER_NEWFORM_FORCETYPE)) {
565  $listoftype = $adht->liste_array();
566  $tmp = array_keys($listoftype);
567  $defaulttype = '';
568  $isempty = 1;
569  if (count($listoftype) == 1) {
570  $defaulttype = $tmp[0];
571  $isempty = 0;
572  }
573  print '<tr><td class="titlefield">'.$langs->trans("Type").' <span style="color: red">*</span></td><td>';
574  print $form->selectarray("typeid", $adht->liste_array(1), GETPOST('typeid') ? GETPOST('typeid') : $defaulttype, $isempty);
575  print '</td></tr>'."\n";
576  } else {
577  $adht->fetch($conf->global->MEMBER_NEWFORM_FORCETYPE);
578  print '<input type="hidden" id="typeid" name="typeid" value="'.$conf->global->MEMBER_NEWFORM_FORCETYPE.'">';
579  }
580 
581  // Moral/Physic attribute
582  $morphys["phy"] = $langs->trans("Physical");
583  $morphys["mor"] = $langs->trans("Moral");
584  if (empty($conf->global->MEMBER_NEWFORM_FORCEMORPHY)) {
585  print '<tr class="morphy"><td class="titlefield">'.$langs->trans('MemberNature').' <span style="color: red">*</span></td><td>'."\n";
586  print $form->selectarray("morphy", $morphys, GETPOST('morphy'), 1);
587  print '</td></tr>'."\n";
588  } else {
589  //print $morphys[$conf->global->MEMBER_NEWFORM_FORCEMORPHY];
590  print '<input type="hidden" id="morphy" name="morphy" value="'.$conf->global->MEMBER_NEWFORM_FORCEMORPHY.'">';
591  }
592 
593  // Company // TODO : optional hide
594  print '<tr id="trcompany" class="trcompany"><td>'.$langs->trans("Company").'</td><td>';
595  print img_picto('', 'company', 'class="pictofixedwidth"');
596  print '<input type="text" name="societe" class="minwidth150 widthcentpercentminusx" value="'.dol_escape_htmltag(GETPOST('societe')).'"></td></tr>'."\n";
597 
598  // Title
599  print '<tr><td class="titlefield">'.$langs->trans('UserTitle').'</td><td>';
600  print $formcompany->select_civility(GETPOST('civility_id'), 'civility_id').'</td></tr>'."\n";
601 
602  // Lastname
603  print '<tr><td>'.$langs->trans("Lastname").' <span style="color: red">*</span></td><td><input type="text" name="lastname" class="minwidth150" value="'.dol_escape_htmltag(GETPOST('lastname')).'"></td></tr>'."\n";
604 
605  // Firstname
606  print '<tr><td>'.$langs->trans("Firstname").' <span style="color: red">*</span></td><td><input type="text" name="firstname" class="minwidth150" value="'.dol_escape_htmltag(GETPOST('firstname')).'"></td></tr>'."\n";
607 
608  // EMail
609  print '<tr><td>'.$langs->trans("Email").(getDolGlobalString("ADHERENT_MAIL_REQUIRED") ? ' <span style="color:red;">*</span>' : '').'</td><td>';
610  //print img_picto('', 'email', 'class="pictofixedwidth"');
611  print '<input type="text" name="email" maxlength="255" class="minwidth200" value="'.dol_escape_htmltag(GETPOST('email')).'"></td></tr>'."\n";
612 
613  // Login
614  if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
615  print '<tr><td>'.$langs->trans("Login").' <span style="color: red">*</span></td><td><input type="text" name="login" maxlength="50" class="minwidth100"value="'.dol_escape_htmltag(GETPOST('login')).'"></td></tr>'."\n";
616  print '<tr><td>'.$langs->trans("Password").' <span style="color: red">*</span></td><td><input type="password" maxlength="128" name="pass1" class="minwidth100" value="'.dol_escape_htmltag(GETPOST("pass1", "none", 2)).'"></td></tr>'."\n";
617  print '<tr><td>'.$langs->trans("PasswordRetype").' <span style="color: red">*</span></td><td><input type="password" maxlength="128" name="pass2" class="minwidth100" value="'.dol_escape_htmltag(GETPOST("pass2", "none", 2)).'"></td></tr>'."\n";
618  }
619 
620  // Gender
621  print '<tr><td>'.$langs->trans("Gender").'</td>';
622  print '<td>';
623  $arraygender = array('man'=>$langs->trans("Genderman"), 'woman'=>$langs->trans("Genderwoman"), 'other'=>$langs->trans("Genderother"));
624  print $form->selectarray('gender', $arraygender, GETPOST('gender', 'alphanohtml'), 1, 0, 0, '', 0, 0, 0, '', '', 1);
625  print '</td></tr>';
626 
627  // Address
628  print '<tr><td>'.$langs->trans("Address").'</td><td>'."\n";
629  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";
630 
631  // Zip / Town
632  print '<tr><td>'.$langs->trans('Zip').' / '.$langs->trans('Town').'</td><td>';
633  print $formcompany->select_ziptown(GETPOST('zipcode'), 'zipcode', array('town', 'selectcountry_id', 'state_id'), 0, 1, '', 'width75');
634  print ' / ';
635  print $formcompany->select_ziptown(GETPOST('town'), 'town', array('zipcode', 'selectcountry_id', 'state_id'), 0, 1);
636  print '</td></tr>';
637 
638  // Country
639  print '<tr><td>'.$langs->trans('Country').'</td><td>';
640  print img_picto('', 'country', 'class="pictofixedwidth"');
641  $country_id = GETPOST('country_id', 'int');
642  if (!$country_id && !empty($conf->global->MEMBER_NEWFORM_FORCECOUNTRYCODE)) {
643  $country_id = getCountry($conf->global->MEMBER_NEWFORM_FORCECOUNTRYCODE, 2, $db, $langs);
644  }
645  if (!$country_id && !empty($conf->geoipmaxmind->enabled)) {
646  $country_code = dol_user_country();
647  //print $country_code;
648  if ($country_code) {
649  $new_country_id = getCountry($country_code, 3, $db, $langs);
650  //print 'xxx'.$country_code.' - '.$new_country_id;
651  if ($new_country_id) {
652  $country_id = $new_country_id;
653  }
654  }
655  }
656  $country_code = getCountry($country_id, 2, $db, $langs);
657  print $form->select_country($country_id, 'country_id');
658  print '</td></tr>';
659  // State
660  if (empty($conf->global->SOCIETE_DISABLE_STATE)) {
661  print '<tr><td>'.$langs->trans('State').'</td><td>';
662  if ($country_code) {
663  print $formcompany->select_state(GETPOST("state_id"), $country_code);
664  }
665  print '</td></tr>';
666  }
667 
668  // Birthday
669  print '<tr id="trbirth" class="trbirth"><td>'.$langs->trans("DateOfBirth").'</td><td>';
670  print $form->selectDate(!empty($birthday) ? $birthday : "", 'birth', 0, 0, 1, "newmember", 1, 0);
671  print '</td></tr>'."\n";
672 
673  // Photo
674  print '<tr><td>'.$langs->trans("URLPhoto").'</td><td><input type="text" name="photo" class="minwidth150" value="'.dol_escape_htmltag(GETPOST('photo')).'"></td></tr>'."\n";
675 
676  // Public
677  print '<tr><td>'.$langs->trans("Public").'</td><td><input type="checkbox" name="public"></td></tr>'."\n";
678 
679  // Other attributes
680  $parameters['tpl_context']='public'; // define template context to public
681  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
682 
683  // Comments
684  print '<tr>';
685  print '<td class="tdtop">'.$langs->trans("Comments").'</td>';
686  print '<td class="tdtop"><textarea name="note_private" id="note_private" wrap="soft" class="quatrevingtpercent" rows="'.ROWS_3.'">'.dol_escape_htmltag(GETPOST('note_private', 'restricthtml'), 0, 1).'</textarea></td>';
687  print '</tr>'."\n";
688 
689  // Add specific fields used by Dolibarr foundation for example
690  // TODO Move this into generic feature.
691  if (!empty($conf->global->MEMBER_NEWFORM_DOLIBARRTURNOVER)) {
692  $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+');
693  print '<tr id="trbudget" class="trcompany"><td>'.$langs->trans("TurnoverOrBudget").' <span style="color: red">*</span></td><td>';
694  print $form->selectarray('budget', $arraybudget, GETPOST('budget'), 1);
695  print ' € or $';
696 
697  print '<script type="text/javascript">
698  jQuery(document).ready(function () {
699  initturnover();
700  jQuery("#morphy").click(function() {
701  initturnover();
702  });
703  jQuery("#budget").change(function() {
704  if (jQuery("#budget").val() > 0) { jQuery(".amount").val(jQuery("#budget").val()); }
705  else { jQuery("#budget").val(\'\'); }
706  });
707  /*jQuery("#typeid").change(function() {
708  if (jQuery("#typeid").val()==1) { jQuery("#morphy").val(\'mor\'); }
709  if (jQuery("#typeid").val()==2) { jQuery("#morphy").val(\'phy\'); }
710  if (jQuery("#typeid").val()==3) { jQuery("#morphy").val(\'mor\'); }
711  if (jQuery("#typeid").val()==4) { jQuery("#morphy").val(\'mor\'); }
712  initturnover();
713  });*/
714  function initturnover() {
715  if (jQuery("#morphy").val()==\'phy\') {
716  jQuery(".amount").val(20);
717  jQuery("#trbudget").hide();
718  jQuery("#trcompany").hide();
719  }
720  if (jQuery("#morphy").val()==\'mor\') {
721  jQuery(".amount").val(\'\');
722  jQuery("#trcompany").show();
723  jQuery("#trbirth").hide();
724  jQuery("#trbudget").show();
725  if (jQuery("#budget").val() > 0) { jQuery(".amount").val(jQuery("#budget").val()); }
726  else { jQuery("#budget").val(\'\'); }
727  }
728  }
729  });
730  </script>';
731  print '</td></tr>'."\n";
732  }
733 
734  if (!empty($conf->global->MEMBER_NEWFORM_PAYONLINE)) {
735  $typeid = $conf->global->MEMBER_NEWFORM_FORCETYPE ? $conf->global->MEMBER_NEWFORM_FORCETYPE : GETPOST('typeid', 'int');
736  $adht = new AdherentType($db);
737  $adht->fetch($typeid);
738  $caneditamount = $adht->caneditamount;
739 
740  // Set amount for the subscription:
741  // - First check the amount of the member type.
742  $amountbytype = $adht->amountByType(1); // Load the array of amount per type
743  $amount = empty($amountbytype[$typeid]) ? (isset($amount) ? $amount : 0) : $amountbytype[$typeid];
744  // - If not found, take the default amount only of the user is authorized to edit it
745  if ($caneditamount && empty($amount) && !empty($conf->global->MEMBER_NEWFORM_AMOUNT)) {
746  $amount = $conf->global->MEMBER_NEWFORM_AMOUNT;
747  }
748  // - If not set, we accept ot have amount defined as parameter (for backward compatibility).
749  if (empty($amount)) {
750  $amount = (GETPOST('amount') ? price2num(GETPOST('amount', 'alpha'), 'MT', 2) : '');
751  }
752 
753  // Clean the amount
754  $amount = price2num($amount);
755  $showedamount = $amount>0? $amount: 0;
756  // $conf->global->MEMBER_NEWFORM_PAYONLINE is 'paypal', 'paybox' or 'stripe'
757  print '<tr><td>'.$langs->trans("Subscription");
758  if (!empty($conf->global->MEMBER_EXT_URL_SUBSCRIPTION_INFO)) {
759  print ' - <a href="'.$conf->global->MEMBER_EXT_URL_SUBSCRIPTION_INFO.'" rel="external" target="_blank" rel="noopener noreferrer">'.$langs->trans("SeeHere").'</a>';
760  }
761  print '</td><td class="nowrap">';
762 
763  if (empty($amount) && !empty($conf->global->MEMBER_NEWFORM_AMOUNT)) {
764  $amount = $conf->global->MEMBER_NEWFORM_AMOUNT;
765  }
766 
767  if ($caneditamount) {
768  print '<input type="text" name="amount" id="amount" class="flat amount width50" value="'.$showedamount.'">';
769  print ' '.$langs->trans("Currency".$conf->currency).'<span class="opacitymedium"> – ';
770  print $amount > 0 ? $langs->trans("AnyAmountWithAdvisedAmount", price($amount, 0, $langs, 1, -1, -1, $conf->currency)): $langs->trans("AnyAmountWithoutAdvisedAmount");
771  print '</span>';
772  } else {
773  print '<input type="hidden" name="amount" id="amount" class="flat amount" value="'.$showedamount.'">';
774  print '<input type="text" name="amount" id="amounthidden" class="flat amount width50" disabled value="'.$showedamount.'">';
775  print ' '.$langs->trans("Currency".$conf->currency);
776  }
777  print '</td></tr>';
778  }
779 
780  print "</table>\n";
781 
782  print dol_get_fiche_end();
783 
784  // Save / Submit
785  print '<div class="center">';
786  print '<input type="submit" value="'.$langs->trans("GetMembershipButtonLabel").'" id="submitsave" class="button">';
787  if (!empty($backtopage)) {
788  print ' &nbsp; &nbsp; <input type="submit" value="'.$langs->trans("Cancel").'" id="submitcancel" class="button button-cancel">';
789  }
790  print '</div>';
791 
792 
793  print "</form>\n";
794  print "<br>";
795  print '</div></div>';
796 } else { // Show the table of membership types
797  // Get units
798  $measuringUnits = new CUnits($db);
799  $result = $measuringUnits->fetchAll('', '', 0, 0, array('t.active' => 1));
800  $units = array();
801  foreach ($measuringUnits->records as $lines)
802  $units[$lines->short_label] = $langs->trans(ucfirst($lines->label));
803 
804  $publiccounters = getDolGlobalString("MEMBER_COUNTERS_ARE_PUBLIC");
805 
806  $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,";
807  $sql .= " COUNT(a.rowid) AS membercount";
808  $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as d";
809  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."adherent as a";
810  $sql .= " ON d.rowid = a.fk_adherent_type AND a.statut > 0";
811  $sql .= " WHERE d.entity IN (".getEntity('member_type').")";
812  $sql .= " AND d.statut=1";
813  $sql .= " GROUP BY d.rowid, d.libelle, d.subscription, d.amount, d.caneditamount, d.vote, d.note, d.duration, d.statut, d.morphy";
814 
815  $result = $db->query($sql);
816  if ($result) {
817  $num = $db->num_rows($result);
818 
819  print '<br><div class="div-table-responsive">';
820  print '<table class="tagtable liste">'."\n";
821  print '<input type="hidden" name="action" value="create">';
822 
823  print '<tr class="liste_titre">';
824  print '<th>'.$langs->trans("Label").'</th>';
825  print '<th class="center">'.$langs->trans("MembershipDuration").'</th>';
826  print '<th class="center">'.$langs->trans("Amount").'</th>';
827  print '<th class="center">'.$langs->trans("MembersNature").'</th>';
828  print '<th class="center">'.$langs->trans("VoteAllowed").'</th>';
829  if ($publiccounters) print '<th class="center">'.$langs->trans("Members").'</th>';
830  print '<th class="center">'.$langs->trans("NewSubscription").'</th>';
831  print "</tr>\n";
832 
833  $i = 0;
834  while ($i < $num) {
835  $objp = $db->fetch_object($result); // Load the member type and information on it
836 
837  print '<tr class="oddeven">';
838  print '<td>'.dol_escape_htmltag($objp->label).'</td>';
839  print '<td class="nowrap">';
840  $unit = preg_replace("/[^a-zA-Z]+/", "", $objp->duration);
841  print max(1, intval($objp->duration)).' '.$units[$unit];
842  print '</td>';
843  print '<td class="center"><span class="amount nowrap">';
844  $displayedamount = max(intval($objp->amount), intval(getDolGlobalInt("MEMBER_MIN_AMOUNT")));
845  $caneditamount = $objp->caneditamount;
846  if ($objp->subscription) {
847  if ($displayedamount > 0 || !$caneditamount) {
848  print $displayedamount.' '.strtoupper($conf->currency);
849  }
850  if ($caneditamount && $displayedamount>0) {
851  print $form->textwithpicto('', $langs->transnoentities("CanEditAmountShortForValues"), 1, 'help', '', 0, 3);
852  } elseif ($caneditamount) {
853  print $langs->transnoentities("CanEditAmountShort");
854  }
855  } else {
856  print "–"; // No subscription required
857  }
858  print '</span></td>';
859  print '<td class="center">';
860  if ($objp->morphy == 'phy') {
861  print $langs->trans("Physical");
862  } elseif ($objp->morphy == 'mor') {
863  print $langs->trans("Moral");
864  } else {
865  print $langs->trans("MorAndPhy");
866  }
867  print '</td>';
868  print '<td class="center">'.yn($objp->vote).'</td>';
869  $membercount = $objp->membercount>0? $objp->membercount: "–";
870  if ($publiccounters) print '<td class="center">'.$membercount.'</td>';
871  print '<td class="center"><button class="button button-save reposition" name="typeid" type="submit" name="submit" value="'.$objp->rowid.'">'.$langs->trans("GetMembershipButtonLabel").'</button></td>';
872  print "</tr>";
873  $i++;
874  }
875 
876  // If no record found
877  if ($num == 0) {
878  $colspan = 8;
879  print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
880  }
881 
882  print "</table>";
883  print '</div>';
884 
885  print '</form>';
886  } else {
887  dol_print_error($db);
888  }
889 }
890 
891 
893 
894 $db->close();
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.
Classe permettant la generation du formulaire html d'envoi de mail unitaire Usage: $formail = new For...
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition: date.lib.php:121
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_user_country()
Return country code for current user.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
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.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
newToken()
Return the value of token currently saved into session with name 'newtoken'.
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 formated 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...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null)
Return array of possible common substitutions.
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.
getUserRemoteIP()
Return the IP of remote user.
dol_htmloutput_errors($mesgstring='', $mesgarray=array(), $keepembedded=0)
Print formated 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.
top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $disableforlogin=0, $disablenofollow=0, $disablenoindex=0)
Ouput html header of a page.
Definition: main.inc.php:1571
llxHeaderVierge($title, $head="", $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='')
Show header for new member.
Definition: new.php:115
llxFooterVierge()
Show footer for new member.
Definition: new.php:164
httponly_accessforbidden($message=1, $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.