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