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