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