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