dolibarr 19.0.4
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 (!getDolGlobalString('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 (getDolGlobalString('EVENTORGANIZATION_IMAGE_PUBLIC_INTERFACE')) {
199 print '<div class="backimagepubliceventorganizationsubscription">';
200 print '<img id="idEVENTORGANIZATION_IMAGE_PUBLIC_INTERFACE" src="' . getDolGlobalString('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((float) $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(getDolGlobalString('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 (!getDolGlobalString('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((float) $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 = (getDolGlobalString('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((float) $project->price_registration)) {
509 $outputlangs = $langs;
510
511 // TODO Use default language of $thirdparty->default_lang to build $outputlang
512
513 $outputlangs->loadLangs(array("eventorganization"));
514
515 // Get product to use for invoice
516 $productforinvoicerow = new Product($db);
517 $productforinvoicerow->id = 0;
518
519 $resultprod = 0;
520 if (getDolGlobalInt('SERVICE_CONFERENCE_ATTENDEE_SUBSCRIPTION') > 0) {
521 $resultprod = $productforinvoicerow->fetch($conf->global->SERVICE_CONFERENCE_ATTENDEE_SUBSCRIPTION);
522 }
523
524 // Create the draft invoice for the payment
525 if ($resultprod < 0) {
526 $error++;
527 $errmsg .= $productforinvoicerow->error;
528 $errors = array_merge($errors, $productforinvoicerow->errors);
529 } else {
530 $facture = new Facture($db);
531 if (empty($confattendee->fk_invoice)) {
532 $facture->type = Facture::TYPE_STANDARD;
533 $facture->socid = $thirdparty->id;
534 $facture->paye = 0;
535 $facture->date = dol_now();
536 $facture->cond_reglement_id = $confattendee->cond_reglement_id;
537 $facture->fk_project = $project->id;
538 $facture->status = Facture::STATUS_DRAFT;
539
540 if (empty($facture->cond_reglement_id)) {
541 $paymenttermstatic = new PaymentTerm($confattendee->db);
542 $facture->cond_reglement_id = $paymenttermstatic->getDefaultId();
543 if (empty($facture->cond_reglement_id)) {
544 $error++;
545 $confattendee->error = 'ErrorNoPaymentTermRECEPFound';
546 $confattendee->errors[] = $confattendee->error;
547 }
548 }
549 $resultfacture = $facture->create($user);
550 if ($resultfacture <= 0) {
551 $confattendee->error = $facture->error;
552 $confattendee->errors = $facture->errors;
553 $error++;
554 } else {
555 $confattendee->fk_invoice = $resultfacture;
556 $confattendee->update($user);
557 }
558 } else {
559 $facture->fetch($confattendee->fk_invoice);
560 }
561
562 // Add link between invoice and the attendee registration
563 /*if (!$error) {
564 $facture->add_object_linked($confattendee->element, $confattendee->id);
565 }*/
566 }
567
568 if (!$error) {
569 // Add line to draft invoice
570 $vattouse = get_default_tva($mysoc, $thirdparty, $productforinvoicerow->id);
571
572 $labelforproduct = $outputlangs->trans("EventFee", $project->title);
573 if ($project->location) {
574 $labelforproduct .= ' - '.$project->location;
575 }
576 $date_start = $project->date_start_event;
577 $date_end = $project->date_end_event;
578
579 // If there is no lines yet, we add one
580 if (empty($facture->lines)) {
581 $pu_ttc = (float) $project->price_registration;
582 $pu_ht = 0;
583 $price_base_type = 'TTC';
584
585 $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);
586 if ($result <= 0) {
587 $confattendee->error = $facture->error;
588 $confattendee->errors = $facture->errors;
589 $error++;
590 }
591 }
592 }
593
594 if (!$error) {
595 $db->commit();
596
597 // Registration was recorded and invoice was generated, but payment not yet done.
598 // TODO
599 // Send an email to says registration shas been received and that we are waiting for the payment.
600 // Should send email template (EventOrganizationEmailRegistrationEvent) saved into conf EVENTORGANIZATION_TEMPLATE_EMAIL_REGISTRATION_EVENT.
601
602 // Now we redirect to the payment page
603 $sourcetouse = 'organizedeventregistration';
604 $reftouse = $facture->id;
605 $redirection = $dolibarr_main_url_root.'/public/payment/newpayment.php?source='.urlencode($sourcetouse).'&ref='.urlencode($reftouse);
606 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN')) {
607 if (getDolGlobalString('PAYMENT_SECURITY_TOKEN_UNIQUE')) {
608 $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
609 } else {
610 $redirection .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
611 }
612 }
613
614 Header("Location: ".$redirection);
615 exit;
616 } else {
617 $db->rollback();
618 }
619 } else {
620 $db->commit();
621
622 // No price has been set
623 // Validating the subscription
624 $confattendee->setStatut(1);
625
626 // Sending mail
627 require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
628 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
629 $formmail = new FormMail($db);
630 // Set output language
631 $outputlangs = new Translate('', $conf);
632 $outputlangs->setDefaultLang(empty($thirdparty->default_lang) ? $mysoc->default_lang : $thirdparty->default_lang);
633 // Load traductions files required by page
634 $outputlangs->loadLangs(array("main", "members", "eventorganization"));
635 // Get email content from template
636 $arraydefaultmessage = null;
637
638 $labeltouse = getDolGlobalString('EVENTORGANIZATION_TEMPLATE_EMAIL_AFT_SUBS_EVENT');
639 if (!empty($labeltouse)) {
640 $arraydefaultmessage = $formmail->getEMailTemplate($db, 'eventorganization_send', $user, $outputlangs, $labeltouse, 1, '');
641 }
642
643 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
644 $subject = $arraydefaultmessage->topic;
645 $msg = $arraydefaultmessage->content;
646 }
647
648 $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $thirdparty);
649 complete_substitutions_array($substitutionarray, $outputlangs, $object);
650
651 $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
652 $texttosend = make_substitutions($msg, $substitutionarray, $outputlangs);
653
654 $sendto = $thirdparty->email;
655 $from = $conf->global->MAILING_EMAIL_FROM;
656 $urlback = $_SERVER["REQUEST_URI"];
657
658 $ishtml = dol_textishtml($texttosend); // May contain urls
659
660 $mailfile = new CMailFile($subjecttosend, $sendto, $from, $texttosend, array(), array(), array(), '', '', 0, $ishtml);
661
662 $result = $mailfile->sendfile();
663 if ($result) {
664 dol_syslog("EMail sent to ".$sendto, LOG_DEBUG, 0, '_payment');
665 } else {
666 dol_syslog("Failed to send EMail to ".$sendto, LOG_ERR, 0, '_payment');
667 }
668
669 $securekeyurl = dol_hash(getDolGlobalString('EVENTORGANIZATION_SECUREKEY') . 'conferenceorbooth'.$id, 2);
670 $redirection = $dolibarr_main_url_root.'/public/eventorganization/subscriptionok.php?id='.((int) $id).'&securekey='.urlencode($securekeyurl);
671
672 Header("Location: ".$redirection);
673 exit;
674 }
675 //Header("Location: ".$urlback);
676 //exit;
677 } else {
678 $db->rollback();
679 }
680}
681
682
683/*
684 * View
685 */
686
687$form = new Form($db);
688$formcompany = new FormCompany($db);
689
690llxHeaderVierge($langs->trans("NewRegistration"));
691
692
693print '<div align="center">';
694print '<div id="divsubscribe">';
695
696// Sub banner
697print '<div class="center subscriptionformbanner subbanner justify margintoponly paddingtop marginbottomonly padingbottom">';
698print load_fiche_titre($langs->trans("NewRegistration"), '', '', 0, 0, 'center');
699// Welcome message
700print '<span class="opacitymedium">'.$langs->trans("EvntOrgWelcomeMessage").'</span>';
701print '<br>';
702// Title
703print '<span class="eventlabel large">'.dol_escape_htmltag($project->title . ' '. $conference->label).'</span><br>';
704print '</div>';
705
706// Help text
707print '<div class="justify subscriptionformhelptext">';
708
709if ($project->date_start_event || $project->date_end_event) {
710 print '<br><span class="fa fa-calendar pictofixedwidth opacitymedium"></span>';
711}
712if ($project->date_start_event) {
713 $format = 'day';
714 $tmparray = dol_getdate($project->date_start_event, false, '');
715 if ($tmparray['hours'] || $tmparray['minutes'] || $tmparray['minutes']) {
716 $format = 'dayhour';
717 }
718 print dol_print_date($project->date_start_event, $format);
719}
720if ($project->date_start_event && $project->date_end_event) {
721 print ' - ';
722}
723if ($project->date_end_event) {
724 $format = 'day';
725 $tmparray = dol_getdate($project->date_end_event, false, '');
726 if ($tmparray['hours'] || $tmparray['minutes'] || $tmparray['minutes']) {
727 $format = 'dayhour';
728 }
729 print dol_print_date($project->date_end_event, $format);
730}
731if ($project->date_start_event || $project->date_end_event) {
732 print '<br>';
733}
734if ($project->location) {
735 print '<span class="fa fa-map-marked-alt pictofixedwidth opacitymedium"></span>'.dol_escape_htmltag($project->location).'<br>';
736}
737if ($project->note_public) {
738 print '<br><span class="opacitymedium">'.dol_htmlentitiesbr($project->note_public).'</span><br>';
739}
740
741print '</div>';
742
743
744$maxattendees = 0;
745if ($conference->id > 0) {
746 /* date of project is not date of event so commented
747 print $langs->trans("Date").': ';
748 print dol_print_date($conference->datep);
749 if ($conference->date_end) {
750 print ' - ';
751 print dol_print_date($conference->datef);
752 }*/
753} else {
754 /* date of project is not date of event so commented
755 print $langs->trans("Date").': ';
756 print dol_print_date($project->date_start);
757 if ($project->date_end) {
758 print ' - ';
759 print dol_print_date($project->date_end);
760 }*/
761 $maxattendees = $project->max_attendees; // Max attendeed for the project/event
762}
763
764if ($maxattendees && $currentnbofattendees >= $maxattendees) {
765 print '<br>';
766 print '<div class="warning">'.$langs->trans("MaxNbOfAttendeesReached").'</div>';
767 print '<br>';
768}
769
770
771
772dol_htmloutput_errors($errmsg, $errors);
773
774if ((!empty($conference->id) && $conference->status == ConferenceOrBooth::STATUS_CONFIRMED) || (!empty($project->id) && $project->status == Project::STATUS_VALIDATED)) {
775 if (empty($maxattendees) || $currentnbofattendees < $maxattendees) {
776 // Print form
777 print '<form action="' . $_SERVER["PHP_SELF"] . '" method="POST" name="newmember">' . "\n";
778 print '<input type="hidden" name="token" value="' . newToken() . '" / >';
779 print '<input type="hidden" name="entity" value="' . $entity . '" />';
780 print '<input type="hidden" name="action" value="add" />';
781 print '<input type="hidden" name="type" value="' . $type . '" />';
782 print '<input type="hidden" name="id" value="' . $conference->id . '" />';
783 print '<input type="hidden" name="fk_project" value="' . $project->id . '" />';
784 print '<input type="hidden" name="securekey" value="' . $securekeyreceived . '" />';
785
786 print '<br>';
787 print '<br>';
788 //print '<span class="opacitymedium">' . $langs->trans("FieldsWithAreMandatory", '*') . '</span><br>';
789 //print $langs->trans("FieldsWithIsForPublic",'**').'<br>';
790
791 print dol_get_fiche_head('');
792
793 print '<script type="text/javascript">
794 jQuery(document).ready(function () {
795 jQuery(document).ready(function () {
796 jQuery("#selectcountry_id").change(function() {
797 document.newmember.action.value="create";
798 document.newmember.submit();
799 });
800 });
801 });
802 </script>';
803
804 print '<table class="border" summary="form to subscribe" id="tablesubscribe">' . "\n";
805
806 // Firstname
807 print '<tr><td><span class="fieldrequired">' . $langs->trans("Firstname") . '</span></td><td>';
808 print '<input type="text" name="firstname" maxlength="255" class="minwidth200 maxwidth300" value="' . dol_escape_htmltag($firstname) . '" required autofocus></td></tr>' . "\n";
809
810 // Lastname
811 print '<tr><td><span class="fieldrequired">' . $langs->trans("Lastname") . '</span></td><td>';
812 print '<input type="text" name="lastname" maxlength="255" class="minwidth200 maxwidth300" value="' . dol_escape_htmltag($lastname) . '" required></td></tr>' . "\n";
813
814 // Email
815 print '<tr><td><span class="fieldrequired">' . $langs->trans("EmailAttendee") . '</span></td><td>';
816 print img_picto('', 'email', 'class="pictofixedwidth"');
817 print '<input type="text" name="email" maxlength="255" class="minwidth200 widthcentpercentminusx maxwidth300" value="' . dol_escape_htmltag(GETPOST('email')) . '" required></td></tr>' . "\n";
818
819 // Company
820 print '<tr id="trcompany" class="trcompany"><td>';
821 if (!empty((float) $project->price_registration)) {
822 print '<span class="fieldrequired">';
823 }
824 print $langs->trans("Company");
825 if (!empty((float) $project->price_registration)) {
826 print '</span>';
827 }
828 print '</td><td>';
829 print img_picto('', 'company', 'class="pictofixedwidth"');
830 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";
831
832 // Email company for invoice
833 if ($project->price_registration) {
834 print '<tr><td>' . $form->textwithpicto($langs->trans("EmailCompany"), $langs->trans("EmailCompanyForInvoice")) . '</td><td>';
835 print img_picto('', 'email', 'class="pictofixedwidth"');
836 print '<input type="text" name="emailcompany" maxlength="255" class="minwidth200 widthcentpercentminusx maxwidth300" value="' . dol_escape_htmltag(GETPOST('emailcompany')) . '"></td></tr>' . "\n";
837 }
838
839 // Address
840 print '<tr><td>' . $langs->trans("Address") . '</td><td>' . "\n";
841 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";
842
843 // Zip / Town
844 print '<tr><td>' . $langs->trans('Zip') . ' / ' . $langs->trans('Town') . '</td><td>';
845 print $formcompany->select_ziptown(GETPOST('zipcode'), 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6, 1);
846 print ' / ';
847 print $formcompany->select_ziptown(GETPOST('town'), 'town', array('zipcode', 'selectcountry_id', 'state_id'), 0, 1);
848 print '</td></tr>';
849
850 // Country
851 print '<tr><td><span class="fieldrequired">'.$langs->trans('Country').'</span></td><td>';
852 print img_picto('', 'country', 'class="pictofixedwidth"');
853 $country_id = GETPOST('country_id');
854 if (!$country_id && getDolGlobalString('MEMBER_NEWFORM_FORCECOUNTRYCODE')) {
855 $country_id = getCountry($conf->global->MEMBER_NEWFORM_FORCECOUNTRYCODE, 2, $db, $langs);
856 }
857 if (!$country_id && !empty($conf->geoipmaxmind->enabled)) {
858 $country_code = dol_user_country();
859 //print $country_code;
860 if ($country_code) {
861 $new_country_id = getCountry($country_code, 3, $db, $langs);
862 //print 'xxx'.$country_code.' - '.$new_country_id;
863 if ($new_country_id) {
864 $country_id = $new_country_id;
865 }
866 }
867 }
868 $country_code = getCountry($country_id, 2, $db, $langs);
869 print $form->select_country($country_id, 'country_id', '', 0, 'minwidth200 widthcentpercentminusx maxwidth300');
870 print '</td></tr>';
871 // State
872 if (!getDolGlobalString('SOCIETE_DISABLE_STATE')) {
873 print '<tr><td>' . $langs->trans('State') . '</td><td>';
874 if ($country_code) {
875 print img_picto('', 'state', 'class="pictofixedwidth"');
876 print $formcompany->select_state(GETPOST("state_id"), $country_code);
877 } else {
878 print '';
879 }
880 print '</td></tr>';
881 }
882
883 if ($project->price_registration) {
884 print '<tr><td>' . $langs->trans('Price') . '</td><td>';
885 print '<span class="amount price-registration">'.price($project->price_registration, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
886 print '</td></tr>';
887 }
888
889 $notetoshow = $note_public;
890 print '<tr><td>' . $langs->trans('Note') . '</td><td>';
891 if (getDolGlobalString('EVENTORGANIZATION_DEFAULT_NOTE_ON_REGISTRATION')) {
892 $notetoshow = str_replace('\n', "\n", $conf->global->EVENTORGANIZATION_DEFAULT_NOTE_ON_REGISTRATION);
893 }
894 print '<textarea name="note_public" class="centpercent" rows="'.ROWS_9.'">'.dol_escape_htmltag($notetoshow, 0, 1).'</textarea>';
895 print '</td></tr>';
896
897 print "</table>\n";
898
899 print dol_get_fiche_end();
900
901 // Save
902 print '<div class="center">';
903 print '<input type="submit" value="' . $langs->trans("Submit") . '" id="submitsave" class="button">';
904 if (!empty($backtopage)) {
905 print ' &nbsp; &nbsp; <input type="submit" value="' . $langs->trans("Cancel") . '" id="submitcancel" class="button button-cancel">';
906 }
907 print '</div>';
908
909 print "</form>\n";
910
911 print "<br>";
912 }
913} else {
914 print '<br><br>';
915 print $langs->trans("ConferenceIsNotConfirmed");
916 print '<br><br>';
917}
918
919print '</div></div>';
920
922
923$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 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:125
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 a 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=array(), $arrayofcss=array(), $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', $nosalt=0)
Returns a hash (non reversible encryption) of a string.
Contact()
Old copy.
Definition index.php:572