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