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