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