dolibarr  20.0.0-beta
attendee_new.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2021 Dorian Vabre <dorian.vabre@gmail.com>
3  * Copyright (C) 2023 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
26 if (!defined('NOLOGIN')) {
27  define("NOLOGIN", 1); // This means this output page does not require to be logged.
28 }
29 if (!defined('NOCSRFCHECK')) {
30  define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
31 }
32 if (!defined('NOIPCHECK')) {
33  define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
34 }
35 if (!defined('NOBROWSERNOTIF')) {
36  define('NOBROWSERNOTIF', '1');
37 }
38 if (!defined('NOIPCHECK')) {
39  define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
40 }
41 
42 
43 // For MultiCompany module.
44 // Do not use GETPOST here, function is not defined and define must be done before including main.inc.php
45 // Because 2 entities can have the same ref
46 $entity = (!empty($_GET['entity']) ? (int) $_GET['entity'] : (!empty($_POST['entity']) ? (int) $_POST['entity'] : 1));
47 if (is_numeric($entity)) {
48  define("DOLENTITY", $entity);
49 }
50 
51 // Load Dolibarr environment
52 require '../../main.inc.php';
53 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
54 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
55 require_once DOL_DOCUMENT_ROOT.'/eventorganization/class/conferenceorbooth.class.php';
56 require_once DOL_DOCUMENT_ROOT.'/eventorganization/class/conferenceorboothattendee.class.php';
57 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
58 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
59 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/paymentterm.class.php';
60 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
61 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
62 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
63 
64 global $dolibarr_main_url_root;
65 
66 // Init vars
67 $errmsg = '';
68 $errors = array();
69 $error = 0;
70 $backtopage = GETPOST('backtopage', 'alpha');
71 $action = GETPOST('action', 'aZ09');
72 
73 $email = GETPOST("email");
74 $societe = GETPOST("societe");
75 $emailcompany = GETPOST("emailcompany");
76 $note_public = GETPOST('note_public', "restricthtml");
77 $firstname = GETPOST('firstname');
78 $lastname = GETPOST('lastname');
79 
80 // Getting id from Post and decoding it
81 $type = GETPOST('type', 'aZ09');
82 if ($type == 'conf') {
83  $id = GETPOSTINT('id');
84 } else {
85  $id = GETPOSTINT('fk_project') ? GETPOSTINT('fk_project') : GETPOSTINT('id');
86 }
87 
88 $conference = new ConferenceOrBooth($db);
89 $project = new Project($db);
90 
91 if ($type == 'conf') {
92  $resultconf = $conference->fetch($id);
93  if ($resultconf < 0) {
94  print 'Bad value for parameter id';
95  exit;
96  }
97  $resultproject = $project->fetch($conference->fk_project);
98  if ($resultproject < 0) {
99  $error++;
100  $errmsg .= $project->error;
101  $errors = array_merge($errors, $project->errors);
102  }
103 }
104 
105 $currentnbofattendees = 0;
106 if ($type == 'global') {
107  $resultproject = $project->fetch($id);
108  if ($resultproject < 0) {
109  $error++;
110  $errmsg .= $project->error;
111  $errors = array_merge($errors, $project->errors);
112  } else {
113  $sql = "SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."eventorganization_conferenceorboothattendee";
114  $sql .= " WHERE fk_project = ".((int) $project->id);
115  $sql .= " AND status IN (0, 1)";
116 
117  $resql = $db->query($sql);
118  if ($resql) {
119  $obj = $db->fetch_object($resql);
120  if ($obj) {
121  $currentnbofattendees = $obj->nb;
122  } else {
123  dol_print_error($db);
124  }
125  }
126  }
127 }
128 
129 // Security check
130 $securekeyreceived = GETPOST('securekey', 'alpha');
131 $securekeytocompare = dol_hash(getDolGlobalString('EVENTORGANIZATION_SECUREKEY').'conferenceorbooth'.((int) $id), 'md5');
132 
133 // We check if the securekey collected is OK
134 if ($securekeytocompare != $securekeyreceived) {
135  print $langs->trans('MissingOrBadSecureKey');
136  exit;
137 }
138 
139 // Load translation files
140 $langs->loadLangs(array("main", "companies", "install", "other", "eventorganization"));
141 
142 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
143 $hookmanager->initHooks(array('publicnewmembercard', 'globalcard'));
144 
145 $extrafields = new ExtraFields($db);
146 
147 $user->loadDefaultValues();
148 
149 // Security check
150 if (empty($conf->eventorganization->enabled)) {
151  httponly_accessforbidden('Module Event organization not enabled');
152 }
153 
154 
166 function llxHeaderVierge($title, $head = "", $disablejs = 0, $disablehead = 0, $arrayofjs = [], $arrayofcss = [])
167 {
168  global $conf, $langs, $mysoc;
169 
170  top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss); // Show html headers
171 
172  print '<body id="mainbody" class="publicnewmemberform">';
173 
174  // Define urllogo
175  $urllogo = DOL_URL_ROOT.'/theme/common/login_logo.png';
176 
177  if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small)) {
178  $urllogo = DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file='.urlencode('logos/thumbs/'.$mysoc->logo_small);
179  } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$mysoc->logo)) {
180  $urllogo = DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=mycompany&amp;file='.urlencode('logos/'.$mysoc->logo);
181  } elseif (is_readable(DOL_DOCUMENT_ROOT.'/theme/dolibarr_logo.svg')) {
182  $urllogo = DOL_URL_ROOT.'/theme/dolibarr_logo.svg';
183  }
184 
185  print '<div class="center">';
186  // Output html code for logo
187  if ($urllogo) {
188  print '<div class="backgreypublicpayment">';
189  print '<div class="logopublicpayment">';
190  print '<img id="dolpaymentlogo" src="'.$urllogo.'"';
191  print '>';
192  print '</div>';
193  if (!getDolGlobalString('MAIN_HIDE_POWERED_BY')) {
194  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>';
195  }
196  print '</div>';
197  }
198 
199  if (getDolGlobalString('EVENTORGANIZATION_IMAGE_PUBLIC_INTERFACE')) {
200  print '<div class="backimagepubliceventorganizationsubscription">';
201  print '<img id="idEVENTORGANIZATION_IMAGE_PUBLIC_INTERFACE" src="' . getDolGlobalString('EVENTORGANIZATION_IMAGE_PUBLIC_INTERFACE').'">';
202  print '</div>';
203  }
204 
205  print '</div>';
206 
207  print '<div class="divmainbodylarge">';
208 }
209 
215 function llxFooterVierge()
216 {
217  print '</div>';
218 
219  printCommonFooter('public');
220 
221  print "</body>\n";
222  print "</html>\n";
223 }
224 
225 
226 
227 /*
228  * Actions
229  */
230 
231 $parameters = array();
232 // Note that $action and $object may have been modified by some hooks
233 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
234 if ($reshook < 0) {
235  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
236 }
237 
238 // Action called when page is submitted
239 if (empty($reshook) && $action == 'add' && (!empty($conference->id) && $conference->status == 2 || !empty($project->id) && $project->status == Project::STATUS_VALIDATED)) {
240  $error = 0;
241 
242  $urlback = '';
243 
244  $db->begin();
245 
246  if (!GETPOST("email")) {
247  $error++;
248  $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Email"))."<br>\n";
249  }
250  // If the price has been set, name is required for the invoice
251  if (!GETPOST("societe") && !empty((float) $project->price_registration)) {
252  $error++;
253  $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Company"))."<br>\n";
254  }
255  if (GETPOST("email") && !isValidEmail(GETPOST("email"))) {
256  $error++;
257  $langs->load("errors");
258  $errmsg .= $langs->trans("ErrorBadEMail", GETPOST("email"))."<br>\n";
259  }
260  if (!GETPOST("country_id")) {
261  $error++;
262  $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Country"))."<br>\n";
263  }
264 
265  if (!$error) {
266  // Check if attendee already exists (by email and for this event)
267  $confattendee = new ConferenceOrBoothAttendee($db);
268 
269  $filter = array();
270 
271  if ($type == 'global') {
272  $filter = "(t.fk_project:=:".((int) $id).") AND (t.email:=:'".$db->escape($email)."')";
273  }
274  if ($type == 'conf') {
275  $filter = "(t.fk_actioncomm:=:".((int) $id).") AND (t.email:=:'".$db->escape($email)."')";
276  }
277 
278  // Check if there is already an attendee into table eventorganization_conferenceorboothattendee for same event (or conference/booth)
279  $resultfetchconfattendee = $confattendee->fetchAll('', '', 0, 0, $filter);
280 
281  if (is_array($resultfetchconfattendee) && count($resultfetchconfattendee) > 0) {
282  // Found confattendee
283  $confattendee = array_shift($resultfetchconfattendee);
284  } else {
285  // Need to create a confattendee
286  $confattendee->date_creation = dol_now();
287  $confattendee->date_subscription = dol_now();
288  $confattendee->email = $email;
289  $confattendee->fk_project = $project->id;
290  $confattendee->fk_actioncomm = $id;
291  $confattendee->note_public = $note_public;
292  $confattendee->firstname = $firstname;
293  $confattendee->lastname = $lastname;
294 
295  $confattendee->ip = getUserRemoteIP();
296  $nb_post_max = getDolGlobalInt("MAIN_SECURITY_MAX_POST_ON_PUBLIC_PAGES_BY_IP_ADDRESS", 200);
297  $now = dol_now();
298  $minmonthpost = dol_time_plus_duree($now, -1, "m");
299  // Calculate nb of post for IP
300  $nb_post_ip = 0;
301  if ($nb_post_max > 0) { // Calculate only if there is a limit to check
302  $sql = "SELECT COUNT(ref) as nb_attendee";
303  $sql .= " FROM ".MAIN_DB_PREFIX."eventorganization_conferenceorboothattendee";
304  $sql .= " WHERE ip = '".$db->escape($confattendee->ip)."'";
305  $sql .= " AND date_creation > '".$db->idate($minmonthpost)."'";
306  $resql = $db->query($sql);
307  if ($resql) {
308  $num = $db->num_rows($resql);
309  $i = 0;
310  while ($i < $num) {
311  $i++;
312  $obj = $db->fetch_object($resql);
313  $nb_post_ip = $obj->nb_attendee;
314  }
315  }
316  }
317 
318  $resultconforbooth = -1;
319 
320  if ($nb_post_max > 0 && $nb_post_ip >= $nb_post_max) {
321  $error++;
322  $errmsg .= $langs->trans("AlreadyTooMuchPostOnThisIPAdress");
323  array_push($confattendee->errors, $langs->trans("AlreadyTooMuchPostOnThisIPAdress"));
324  setEventMessage($errmsg, 'errors');
325  } else {
326  $resultconfattendee = $confattendee->create($user);
327  }
328  if ($resultconfattendee < 0) {
329  $error++;
330  $errmsg .= $confattendee->error;
331  $errors = array_merge($errors, $confattendee->errors);
332  }
333  }
334 
335  // At this point, we have an existing $confattendee. It may not be linked to a thirdparty.
336  //var_dump($confattendee);
337 
338  // If the registration has already been paid for this attendee
339  if (!empty($confattendee->date_subscription) && !empty($confattendee->amount)) {
340  $securekeyurl = dol_hash(getDolGlobalString('EVENTORGANIZATION_SECUREKEY') . 'conferenceorbooth'.$id, 'master');
341  $redirection = $dolibarr_main_url_root.'/public/eventorganization/subscriptionok.php?id='.((int) $id).'&securekey='.urlencode($securekeyurl);
342 
343  $mesg = $langs->trans("RegistrationAndPaymentWereAlreadyRecorded", $email);
344  setEventMessages($mesg, null, 'mesgs');
345 
346  $db->commit();
347 
348  header("Location: ".$redirection);
349  exit;
350  }
351 
352  $resultfetchthirdparty = 0;
353 
354  $genericcompanyname = $langs->trans('EventParticipant').' '.($emailcompany ? $emailcompany : $email); // Keep this label simple so we can retrieve same thirdparty for another event
355 
356  // Getting the thirdparty or creating it
357  $thirdparty = new Societe($db);
358  $contact = new Contact($db);
359  // Fetch using fk_soc if the attendee was already found
360  if (!empty($confattendee->fk_soc) && $confattendee->fk_soc > 0) {
361  $resultfetchthirdparty = $thirdparty->fetch($confattendee->fk_soc);
362  } else {
363  if (!getDolGlobalString('EVENTORGANIZATION_DISABLE_RETREIVE_THIRDPARTY_FROM_NAME')) {
364  // Fetch using the field input by end user if we have just created the attendee
365  if ($resultfetchthirdparty <= 0 && !empty($societe) && !empty($emailcompany)) {
366  $resultfetchthirdparty = $thirdparty->fetch('', $societe, '', '', '', '', '', '', '', '', $emailcompany);
367  if ($resultfetchthirdparty > 0) {
368  // We found a unique result with the name + emailcompany, so we set the fk_soc of attendee
369  $confattendee->fk_soc = $thirdparty->id;
370  $confattendee->update($user);
371  } elseif ($resultfetchthirdparty == -2) {
372  $thirdparty->error = $langs->trans("ErrorSeveralCompaniesWithNameContactUs", $mysoc->email);
373  }
374  }
375  // Fetch using the field input by end user if we have just created the attendee
376  if ($resultfetchthirdparty <= 0 && !empty($societe) && !empty($email) && $email != $emailcompany) {
377  $resultfetchthirdparty = $thirdparty->fetch('', $societe, '', '', '', '', '', '', '', '', $email);
378  if ($resultfetchthirdparty > 0) {
379  // We found a unique result with the name + email, so we set the fk_soc of attendee
380  $confattendee->fk_soc = $thirdparty->id;
381  $confattendee->update($user);
382  } elseif ($resultfetchthirdparty == -2) {
383  $thirdparty->error = $langs->trans("ErrorSeveralCompaniesWithNameContactUs", $mysoc->email);
384  }
385  }
386  }
387  if ($resultfetchthirdparty <= 0 && !empty($emailcompany)) {
388  // Try to find thirdparty from the email only
389  $resultfetchthirdparty = $thirdparty->fetch('', '', '', '', '', '', '', '', '', '', $emailcompany);
390  if ($resultfetchthirdparty > 0) {
391  // We found a unique result with that email only, so we set the fk_soc of attendee
392  $confattendee->fk_soc = $thirdparty->id;
393  $confattendee->update($user);
394  } elseif ($resultfetchthirdparty == -2) {
395  $thirdparty->error = $langs->trans("ErrorSeveralCompaniesWithEmailContactUs", $mysoc->email);
396  }
397  }
398  if ($resultfetchthirdparty <= 0 && !empty($email) && $email != $emailcompany) {
399  // Try to find thirdparty from the email only
400  $resultfetchthirdparty = $thirdparty->fetch('', '', '', '', '', '', '', '', '', '', $email);
401  if ($resultfetchthirdparty > 0) {
402  // We found a unique result with that email only, so we set the fk_soc of attendee
403  $confattendee->fk_soc = $thirdparty->id;
404  $confattendee->update($user);
405  } elseif ($resultfetchthirdparty == -2) {
406  $thirdparty->error = $langs->trans("ErrorSeveralCompaniesWithEmailContactUs", $mysoc->email);
407  }
408  }
409  if ($resultfetchthirdparty <= 0 && !empty($genericcompanyname)) {
410  // Try to find thirdparty from the generic mail only
411  $resultfetchthirdparty = $thirdparty->fetch('', $genericcompanyname, '', '', '', '', '', '', '', '', '');
412  if ($resultfetchthirdparty > 0) {
413  // We found a unique result with that name + email, so we set the fk_soc of attendee
414  $confattendee->fk_soc = $thirdparty->id;
415  $confattendee->update($user);
416  } elseif ($resultfetchthirdparty == -2) {
417  $thirdparty->error = $langs->trans("ErrorSeveralCompaniesWithNameContactUs", $mysoc->email);
418  }
419  }
420 
421  // TODO Add more tests on a VAT number, profid or a name ?
422 
423  if ($resultfetchthirdparty <= 0 && !empty($email)) {
424  // Try to find the thirdparty from the contact
425  $resultfetchcontact = $contact->fetch('', null, '', $email);
426  if ($resultfetchcontact > 0 && $contact->fk_soc > 0) {
427  $thirdparty->fetch($contact->fk_soc);
428  $confattendee->fk_soc = $thirdparty->id;
429  $confattendee->update($user);
430  $resultfetchthirdparty = 1;
431  }
432  }
433 
434  if ($resultfetchthirdparty <= 0 && !empty($societe)) {
435  // Try to find thirdparty from the company name only
436  $resultfetchthirdparty = $thirdparty->fetch('', $societe, '', '', '', '', '', '', '', '', '');
437  if ($resultfetchthirdparty > 0) {
438  // We found a unique result with that name only, so we set the fk_soc of attendee
439  $confattendee->fk_soc = $thirdparty->id;
440  $confattendee->update($user);
441  } elseif ($resultfetchthirdparty == -2) {
442  $thirdparty->error = "ErrorSeveralCompaniesWithNameContactUs";
443  }
444  }
445  }
446 
447  // If price is empty, no need to create a thirdparty, so we force $resultfetchthirdparty as if we have already found thirdp party.
448  if (empty((float) $project->price_registration)) {
449  $resultfetchthirdparty = 1;
450  }
451 
452  if ($resultfetchthirdparty < 0) {
453  // If an error was found
454  $error++;
455  $errmsg .= $thirdparty->error;
456  $errors = array_merge($errors, $thirdparty->errors);
457  } elseif ($resultfetchthirdparty == 0) { // No thirdparty found + a payment is expected
458  // Creation of a new thirdparty
459  if (!empty($societe)) {
460  $thirdparty->name = $societe;
461  } else {
462  $thirdparty->name = $genericcompanyname;
463  }
464  $thirdparty->address = GETPOST("address");
465  $thirdparty->zip = GETPOST("zipcode");
466  $thirdparty->town = GETPOST("town");
467  $thirdparty->client = $thirdparty::PROSPECT;
468  $thirdparty->fournisseur = 0;
469  $thirdparty->country_id = GETPOSTINT("country_id");
470  $thirdparty->state_id = GETPOSTINT("state_id");
471  $thirdparty->email = ($emailcompany ? $emailcompany : $email);
472 
473  // Load object modCodeTiers
474  $module = getDolGlobalString('SOCIETE_CODECLIENT_ADDON', 'mod_codeclient_leopard');
475  if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') {
476  $module = substr($module, 0, dol_strlen($module) - 4);
477  }
478  $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
479  foreach ($dirsociete as $dirroot) {
480  $res = dol_include_once($dirroot.$module.'.php');
481  if ($res) {
482  break;
483  }
484  }
485  $modCodeClient = new $module($db);
486 
487  if (empty($tmpcode) && !empty($modCodeClient->code_auto)) {
488  $tmpcode = $modCodeClient->getNextValue($thirdparty, 0);
489  }
490  $thirdparty->code_client = $tmpcode;
491  $readythirdparty = $thirdparty->create($user);
492  if ($readythirdparty < 0) {
493  $error++;
494  $errmsg .= $thirdparty->error;
495  $errors = array_merge($errors, $thirdparty->errors);
496  } else {
497  $thirdparty->country_code = getCountry($thirdparty->country_id, 2, $db, $langs);
498  $thirdparty->country = getCountry($thirdparty->country_code, 0, $db, $langs);
499 
500  // Update attendee country to match country of thirdparty
501  $confattendee->fk_soc = $thirdparty->id;
502  $confattendee->update($user);
503  }
504  }
505  }
506 
507  if (!$error) {
508  // If the registration needs a payment
509  if (!empty((float) $project->price_registration)) {
510  $outputlangs = $langs;
511 
512  // TODO Use default language of $thirdparty->default_lang to build $outputlang
513 
514  $outputlangs->loadLangs(array("eventorganization"));
515 
516  // Get product to use for invoice
517  $productforinvoicerow = new Product($db);
518  $productforinvoicerow->id = 0;
519 
520  $resultprod = 0;
521  if (getDolGlobalInt('SERVICE_CONFERENCE_ATTENDEE_SUBSCRIPTION') > 0) {
522  $resultprod = $productforinvoicerow->fetch(getDolGlobalString('SERVICE_CONFERENCE_ATTENDEE_SUBSCRIPTION'));
523  }
524 
525  // Create the draft invoice for the payment
526  if ($resultprod < 0) {
527  $error++;
528  $errmsg .= $productforinvoicerow->error;
529  $errors = array_merge($errors, $productforinvoicerow->errors);
530  } else {
531  $facture = new Facture($db);
532  if (empty($confattendee->fk_invoice)) {
533  $facture->type = Facture::TYPE_STANDARD;
534  $facture->socid = $thirdparty->id;
535  $facture->paye = 0;
536  $facture->date = dol_now();
537  $facture->cond_reglement_id = $confattendee->cond_reglement_id;
538  $facture->fk_project = $project->id;
539  $facture->status = Facture::STATUS_DRAFT;
540 
541  if (empty($facture->cond_reglement_id)) {
542  $paymenttermstatic = new PaymentTerm($confattendee->db);
543  $facture->cond_reglement_id = $paymenttermstatic->getDefaultId();
544  if (empty($facture->cond_reglement_id)) {
545  $error++;
546  $confattendee->error = 'ErrorNoPaymentTermRECEPFound';
547  $confattendee->errors[] = $confattendee->error;
548  }
549  }
550  $resultfacture = $facture->create($user);
551  if ($resultfacture <= 0) {
552  $confattendee->error = $facture->error;
553  $confattendee->errors = $facture->errors;
554  $error++;
555  } else {
556  $confattendee->fk_invoice = $resultfacture;
557  $confattendee->update($user);
558  }
559  } else {
560  $facture->fetch($confattendee->fk_invoice);
561  }
562 
563  // Add link between invoice and the attendee registration
564  /*if (!$error) {
565  $facture->add_object_linked($confattendee->element, $confattendee->id);
566  }*/
567  }
568 
569  if (!$error) {
570  // Add line to draft invoice
571  $vattouse = get_default_tva($mysoc, $thirdparty, $productforinvoicerow->id);
572 
573  $labelforproduct = $outputlangs->trans("EventFee", $project->title);
574  if ($project->location) {
575  $labelforproduct .= ' - '.$project->location;
576  }
577  $date_start = $project->date_start_event;
578  $date_end = $project->date_end_event;
579 
580  // If there is no lines yet, we add one
581  if (empty($facture->lines)) {
582  $pu_ttc = (float) $project->price_registration;
583  $pu_ht = 0;
584  $price_base_type = 'TTC';
585 
586  $result = $facture->addline($labelforproduct, $pu_ht, 1, $vattouse, 0, 0, $productforinvoicerow->id, 0, $date_start, $date_end, 0, 0, '', $price_base_type, $pu_ttc, 1);
587  if ($result <= 0) {
588  $confattendee->error = $facture->error;
589  $confattendee->errors = $facture->errors;
590  $error++;
591  }
592  }
593  }
594 
595  if (!$error) {
596  $db->commit();
597 
598  // Registration was recorded and invoice was generated, but payment not yet done.
599  // TODO
600  // Send an email to says registration shas been received and that we are waiting for the payment.
601  // Should send email template (EventOrganizationEmailRegistrationEvent) saved into conf EVENTORGANIZATION_TEMPLATE_EMAIL_REGISTRATION_EVENT.
602 
603  // Now we redirect to the payment page
604  $sourcetouse = 'organizedeventregistration';
605  $reftouse = $facture->id;
606  $redirection = $dolibarr_main_url_root.'/public/payment/newpayment.php?source='.urlencode((string) ($sourcetouse)).'&ref='.urlencode((string) ($reftouse));
607  if (getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
608  if (getDolGlobalString('PAYMENT_SECURITY_TOKEN_UNIQUE')) {
609  $redirection .= '&securekey='.dol_hash(getDolGlobalString('PAYMENT_SECURITY_TOKEN') . $sourcetouse . $reftouse, 2); // Use the source in the hash to avoid duplicates if the references are identical
610  } else {
611  $redirection .= '&securekey='.urlencode(getDolGlobalString('PAYMENT_SECURITY_TOKEN'));
612  }
613  }
614 
615  header("Location: ".$redirection);
616  exit;
617  } else {
618  $db->rollback();
619  }
620  } else {
621  $db->commit();
622 
623  // No price has been set
624  // Validating the subscription
625  $confattendee->setStatut(1);
626 
627  // Sending mail
628  require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
629  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
630  $formmail = new FormMail($db);
631  // Set output language
632  $outputlangs = new Translate('', $conf);
633  $outputlangs->setDefaultLang(empty($thirdparty->default_lang) ? $mysoc->default_lang : $thirdparty->default_lang);
634  // Load traductions files required by page
635  $outputlangs->loadLangs(array("main", "members", "eventorganization"));
636  // Get email content from template
637  $arraydefaultmessage = null;
638 
639  $labeltouse = getDolGlobalString('EVENTORGANIZATION_TEMPLATE_EMAIL_AFT_SUBS_EVENT');
640  if (!empty($labeltouse)) {
641  $arraydefaultmessage = $formmail->getEMailTemplate($db, 'eventorganization_send', $user, $outputlangs, $labeltouse, 1, '');
642  }
643 
644  if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
645  $subject = $arraydefaultmessage->topic;
646  $msg = $arraydefaultmessage->content;
647  }
648 
649  $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $thirdparty);
650  complete_substitutions_array($substitutionarray, $outputlangs, $object);
651 
652  $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
653  $texttosend = make_substitutions($msg, $substitutionarray, $outputlangs);
654 
655  $sendto = $thirdparty->email;
656  $from = getDolGlobalString('MAILING_EMAIL_FROM');
657  $urlback = $_SERVER["REQUEST_URI"];
658 
659  $ishtml = dol_textishtml($texttosend); // May contain urls
660 
661  $mailfile = new CMailFile($subjecttosend, $sendto, $from, $texttosend, array(), array(), array(), '', '', 0, $ishtml);
662 
663  $result = $mailfile->sendfile();
664  if ($result) {
665  dol_syslog("EMail sent to ".$sendto, LOG_DEBUG, 0, '_payment');
666  } else {
667  dol_syslog("Failed to send EMail to ".$sendto, LOG_ERR, 0, '_payment');
668  }
669 
670  $securekeyurl = dol_hash(getDolGlobalString('EVENTORGANIZATION_SECUREKEY') . 'conferenceorbooth'.$id, 2);
671  $redirection = $dolibarr_main_url_root.'/public/eventorganization/subscriptionok.php?id='.((int) $id).'&securekey='.urlencode($securekeyurl);
672 
673  header("Location: ".$redirection);
674  exit;
675  }
676  //Header("Location: ".$urlback);
677  //exit;
678  } else {
679  $db->rollback();
680  }
681 }
682 
683 
684 /*
685  * View
686  */
687 
688 $form = new Form($db);
689 $formcompany = new FormCompany($db);
690 
691 llxHeaderVierge($langs->trans("NewRegistration"));
692 
693 
694 print '<div align="center">';
695 print '<div id="divsubscribe">';
696 
697 // Sub banner
698 print '<div class="center subscriptionformbanner subbanner justify margintoponly paddingtop marginbottomonly padingbottom">';
699 print load_fiche_titre($langs->trans("NewRegistration"), '', '', 0, 0, 'center');
700 // Welcome message
701 print '<span class="opacitymedium">'.$langs->trans("EvntOrgWelcomeMessage").'</span>';
702 print '<br>';
703 // Title
704 print '<span class="eventlabel large">'.dol_escape_htmltag($project->title . ' '. $conference->label).'</span><br>';
705 print '</div>';
706 
707 // Help text
708 print '<div class="justify subscriptionformhelptext">';
709 
710 if ($project->date_start_event || $project->date_end_event) {
711  print '<br><span class="fa fa-calendar pictofixedwidth opacitymedium"></span>';
712 }
713 if ($project->date_start_event) {
714  $format = 'day';
715  $tmparray = dol_getdate($project->date_start_event, false, '');
716  if ($tmparray['hours'] || $tmparray['minutes'] || $tmparray['minutes']) {
717  $format = 'dayhour';
718  }
719  print dol_print_date($project->date_start_event, $format);
720 }
721 if ($project->date_start_event && $project->date_end_event) {
722  print ' - ';
723 }
724 if ($project->date_end_event) {
725  $format = 'day';
726  $tmparray = dol_getdate($project->date_end_event, false, '');
727  if ($tmparray['hours'] || $tmparray['minutes'] || $tmparray['minutes']) {
728  $format = 'dayhour';
729  }
730  print dol_print_date($project->date_end_event, $format);
731 }
732 if ($project->date_start_event || $project->date_end_event) {
733  print '<br>';
734 }
735 if ($project->location) {
736  print '<span class="fa fa-map-marked-alt pictofixedwidth opacitymedium"></span>'.dol_escape_htmltag($project->location).'<br>';
737 }
738 if ($project->note_public) {
739  print '<br><span class="opacitymedium">'.dol_htmlentitiesbr($project->note_public).'</span><br>';
740 }
741 
742 print '</div>';
743 
744 
745 $maxattendees = 0;
746 if ($conference->id > 0) {
747  /* date of project is not date of event so commented
748  print $langs->trans("Date").': ';
749  print dol_print_date($conference->datep);
750  if ($conference->date_end) {
751  print ' - ';
752  print dol_print_date($conference->datef);
753  }*/
754 } else {
755  /* date of project is not date of event so commented
756  print $langs->trans("Date").': ';
757  print dol_print_date($project->date_start);
758  if ($project->date_end) {
759  print ' - ';
760  print dol_print_date($project->date_end);
761  }*/
762  $maxattendees = $project->max_attendees; // Max attendeed for the project/event
763 }
764 
765 if ($maxattendees && $currentnbofattendees >= $maxattendees) {
766  print '<br>';
767  print '<div class="warning">'.$langs->trans("MaxNbOfAttendeesReached").'</div>';
768  print '<br>';
769 }
770 
771 
772 
773 dol_htmloutput_errors($errmsg, $errors);
774 
775 if ((!empty($conference->id) && $conference->status == ConferenceOrBooth::STATUS_CONFIRMED) || (!empty($project->id) && $project->status == Project::STATUS_VALIDATED)) {
776  if (empty($maxattendees) || $currentnbofattendees < $maxattendees) {
777  // Print form
778  print '<form action="' . $_SERVER["PHP_SELF"] . '" method="POST" name="newmember">' . "\n";
779  print '<input type="hidden" name="token" value="' . newToken() . '" / >';
780  print '<input type="hidden" name="entity" value="' . $entity . '" />';
781  print '<input type="hidden" name="action" value="add" />';
782  print '<input type="hidden" name="type" value="' . $type . '" />';
783  print '<input type="hidden" name="id" value="' . $conference->id . '" />';
784  print '<input type="hidden" name="fk_project" value="' . $project->id . '" />';
785  print '<input type="hidden" name="securekey" value="' . $securekeyreceived . '" />';
786 
787  print '<br>';
788  print '<br>';
789  //print '<span class="opacitymedium">' . $langs->trans("FieldsWithAreMandatory", '*') . '</span><br>';
790  //print $langs->trans("FieldsWithIsForPublic",'**').'<br>';
791 
792  print dol_get_fiche_head();
793 
794  print '<script type="text/javascript">
795  jQuery(document).ready(function () {
796  jQuery(document).ready(function () {
797  jQuery("#selectcountry_id").change(function() {
798  document.newmember.action.value="create";
799  document.newmember.submit();
800  });
801  });
802  });
803  </script>';
804 
805  print '<table class="border" summary="form to subscribe" id="tablesubscribe">' . "\n";
806 
807  // Firstname
808  print '<tr><td><span class="fieldrequired">';
809  print $langs->trans("Firstname") . '</span></td><td>';
810  print img_picto('', 'user', 'class="pictofixedwidth"');
811  print '<input type="text" name="firstname" maxlength="255" class="minwidth200 maxwidth300" value="' . dol_escape_htmltag($firstname) . '" required autofocus></td></tr>' . "\n";
812 
813  // Lastname
814  print '<tr><td><span class="fieldrequired">';
815  print $langs->trans("Lastname") . '</span></td><td>';
816  print img_picto('', 'user', 'class="pictofixedwidth"');
817  print '<input type="text" name="lastname" maxlength="255" class="minwidth200 maxwidth300" value="' . dol_escape_htmltag($lastname) . '" required></td></tr>' . "\n";
818 
819  // Email
820  print '<tr><td><span class="fieldrequired">' . $langs->trans("EmailAttendee") . '</span></td><td>';
821  print img_picto('', 'email', 'class="pictofixedwidth"');
822  print '<input type="text" name="email" maxlength="255" class="minwidth200 widthcentpercentminusx maxwidth300" value="' . dol_escape_htmltag(GETPOST('email')) . '" required></td></tr>' . "\n";
823 
824  // Company
825  print '<tr id="trcompany" class="trcompany"><td>';
826  if (!empty((float) $project->price_registration)) {
827  print '<span class="fieldrequired">';
828  }
829  print $langs->trans("Company");
830  if (!empty((float) $project->price_registration)) {
831  print '</span>';
832  }
833  print '</td><td>';
834  print img_picto('', 'company', 'class="pictofixedwidth"');
835  print '<input type="text" name="societe" class="minwidth200 widthcentpercentminusx maxwidth300" value="' . dol_escape_htmltag(GETPOST('societe')) . '"'.(empty((float) $project->price_registration) ? '' : ' required').'></td></tr>' . "\n";
836 
837  // Email company for invoice
838  if ($project->price_registration) {
839  print '<tr><td>' . $form->textwithpicto($langs->trans("EmailCompany"), $langs->trans("EmailCompanyForInvoice")) . '</td><td>';
840  print img_picto('', 'email', 'class="pictofixedwidth"');
841  print '<input type="text" name="emailcompany" maxlength="255" class="minwidth200 widthcentpercentminusx maxwidth300" value="' . dol_escape_htmltag(GETPOST('emailcompany')) . '"></td></tr>' . "\n";
842  }
843 
844  // Address
845  print '<tr><td>' . $langs->trans("Address") . '</td><td>' . "\n";
846  print '<textarea name="address" id="address" wrap="soft" class="centpercent" rows="' . ROWS_2 . '">' . dol_escape_htmltag(GETPOST('address', 'restricthtml'), 0, 1) . '</textarea></td></tr>' . "\n";
847 
848  // Zip / Town
849  print '<tr><td>' . $langs->trans('Zip') . ' / ' . $langs->trans('Town') . '</td><td>';
850  print $formcompany->select_ziptown(GETPOST('zipcode'), 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6, 1);
851  print ' / ';
852  print $formcompany->select_ziptown(GETPOST('town'), 'town', array('zipcode', 'selectcountry_id', 'state_id'), 0, 1);
853  print '</td></tr>';
854 
855  // Country
856  print '<tr><td><span class="fieldrequired">'.$langs->trans('Country').'</span></td><td>';
857  print img_picto('', 'country', 'class="pictofixedwidth"');
858  $country_id = GETPOST('country_id');
859  if (!$country_id && getDolGlobalString('MEMBER_NEWFORM_FORCECOUNTRYCODE')) {
860  $country_id = getCountry($conf->global->MEMBER_NEWFORM_FORCECOUNTRYCODE, 2, $db, $langs);
861  }
862  if (!$country_id && !empty($conf->geoipmaxmind->enabled)) {
863  $country_code = dol_user_country();
864  //print $country_code;
865  if ($country_code) {
866  $new_country_id = getCountry($country_code, 3, $db, $langs);
867  //print 'xxx'.$country_code.' - '.$new_country_id;
868  if ($new_country_id) {
869  $country_id = $new_country_id;
870  }
871  }
872  }
873  $country_code = getCountry($country_id, 2, $db, $langs);
874  print $form->select_country($country_id, 'country_id', '', 0, 'minwidth200 widthcentpercentminusx maxwidth300');
875  print '</td></tr>';
876  // State
877  if (!getDolGlobalString('SOCIETE_DISABLE_STATE')) {
878  print '<tr><td>' . $langs->trans('State') . '</td><td>';
879  if ($country_code) {
880  print img_picto('', 'state', 'class="pictofixedwidth"');
881  print $formcompany->select_state(GETPOST("state_id"), $country_code);
882  } else {
883  print '';
884  }
885  print '</td></tr>';
886  }
887 
888  if ($project->price_registration) {
889  print '<tr><td>' . $langs->trans('Price') . '</td><td>';
890  print '<span class="amount price-registration">'.price($project->price_registration, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
891  print '</td></tr>';
892  }
893 
894  $notetoshow = $note_public;
895  print '<tr><td>' . $langs->trans('Note') . '</td><td>';
896  if (getDolGlobalString('EVENTORGANIZATION_DEFAULT_NOTE_ON_REGISTRATION')) {
897  $notetoshow = str_replace('\n', "\n", $conf->global->EVENTORGANIZATION_DEFAULT_NOTE_ON_REGISTRATION);
898  }
899  print '<textarea name="note_public" class="centpercent" rows="'.ROWS_9.'">'.dol_escape_htmltag($notetoshow, 0, 1).'</textarea>';
900  print '</td></tr>';
901 
902  print "</table>\n";
903 
904  print dol_get_fiche_end();
905 
906  // Save
907  print '<div class="center">';
908  print '<input type="submit" value="' . $langs->trans("Submit") . '" id="submitsave" class="button">';
909  if (!empty($backtopage)) {
910  print ' &nbsp; &nbsp; <input type="submit" value="' . $langs->trans("Cancel") . '" id="submitcancel" class="button button-cancel">';
911  }
912  print '</div>';
913 
914  print "</form>\n";
915 
916  print "<br>";
917  }
918 } else {
919  print '<br><br>';
920  print $langs->trans("ConferenceIsNotConfirmed");
921  print '<br><br>';
922 }
923 
924 print '</div></div>';
925 
927 
928 $db->close();
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
if(empty($conf->eventorganization->enabled)) llxHeaderVierge($title, $head="", $disablejs=0, $disablehead=0, $arrayofjs=[], $arrayofcss=[])
Show header for new member.
llxFooterVierge()
Show footer for new member.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Class for ConferenceOrBoothAttendee.
Class for ConferenceOrBooth.
Class to manage contact/addresses.
Class to manage standard extra fields.
Class to manage invoices.
const STATUS_DRAFT
Draft status.
const TYPE_STANDARD
Standard invoice.
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 permettant la generation du formulaire html d'envoi de mail unitaire Usage: $formail = new Form...
Class to manage payment terms records in dictionary.
Class to manage products or services.
Class to manage projects.
const STATUS_VALIDATED
Open/Validated status.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:745
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition: date.lib.php:124
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_user_country()
Return country code for current user.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
setEventMessage($mesgs, $style='mesgs', $noduplicate=0)
Set event message 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-...
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
newToken()
Return the value of token currently saved into session with name 'newtoken'.
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...
dol_textishtml($msg, $option=0)
Return if a text is a html content.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null, $include=null)
Return array of possible common substitutions.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
getUserRemoteIP()
Return the IP of remote user.
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
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_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
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.
Definition: main.inc.php:1786
div float
Buy price without taxes.
Definition: style.css.php:960
httponly_accessforbidden($message='1', $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.
dol_hash($chain, $type='0', $nosalt=0)
Returns a hash (non reversible encryption) of a string.