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