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