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