dolibarr  x.y.z
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 
37 
38 // For MultiCompany module.
39 // Do not use GETPOST here, function is not defined and define must be done before including main.inc.php
40 // TODO This should be useless. Because entity must be retrieve from object ref and not from url.
41 $entity = (!empty($_GET['entity']) ? (int) $_GET['entity'] : (!empty($_POST['entity']) ? (int) $_POST['entity'] : 1));
42 if (is_numeric($entity)) {
43  define("DOLENTITY", $entity);
44 }
45 
46 // Load Dolibarr environment
47 require '../../main.inc.php';
48 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
49 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
50 require_once DOL_DOCUMENT_ROOT.'/eventorganization/class/conferenceorbooth.class.php';
51 require_once DOL_DOCUMENT_ROOT.'/eventorganization/class/conferenceorboothattendee.class.php';
52 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
53 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
54 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/paymentterm.class.php';
55 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
56 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
57 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.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  httponly_accessforbidden('Module Event organization not enabled');
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  $filter = array();
262 
263  if ($type == 'global') {
264  $filter = array('t.fk_project'=>((int) $id), 'customsql'=>'t.email="'.$db->escape($email).'"');
265  }
266  if ($type == 'conf') {
267  $filter = array('t.fk_actioncomm'=>((int) $id), 'customsql'=>'t.email="'.$db->escape($email).'"');
268  }
269 
270  // Check if there is already an attendee into table eventorganization_conferenceorboothattendee for same event (or conference/booth)
271  $resultfetchconfattendee = $confattendee->fetchAll('', '', 0, 0, $filter);
272 
273  if (is_array($resultfetchconfattendee) && count($resultfetchconfattendee) > 0) {
274  // Found confattendee
275  $confattendee = array_shift($resultfetchconfattendee);
276  } else {
277  // Need to create a confattendee
278  $confattendee->date_creation = dol_now();
279  $confattendee->date_subscription = dol_now();
280  $confattendee->email = $email;
281  $confattendee->fk_project = $project->id;
282  $confattendee->fk_actioncomm = $id;
283  $confattendee->note_public = $note_public;
284 
285  $confattendee->ip = getUserRemoteIP();
286  $nb_post_max = getDolGlobalInt("MAIN_SECURITY_MAX_POST_ON_PUBLIC_PAGES_BY_IP_ADDRESS", 200);
287  $now = dol_now();
288  $minmonthpost = dol_time_plus_duree($now, -1, "m");
289  // Calculate nb of post for IP
290  $nb_post_ip = 0;
291  if ($nb_post_max > 0) { // Calculate only if there is a limit to check
292  $sql = "SELECT COUNT(ref) as nb_attendee";
293  $sql .= " FROM ".MAIN_DB_PREFIX."eventorganization_conferenceorboothattendee";
294  $sql .= " WHERE ip = '".$db->escape($confattendee->ip)."'";
295  $sql .= " AND date_creation > '".$db->idate($minmonthpost)."'";
296  $resql = $db->query($sql);
297  if ($resql) {
298  $num = $db->num_rows($resql);
299  $i = 0;
300  while ($i < $num) {
301  $i++;
302  $obj = $db->fetch_object($resql);
303  $nb_post_ip = $obj->nb_attendee;
304  }
305  }
306  }
307 
308  $resultconforbooth = -1;
309 
310  if ($nb_post_max > 0 && $nb_post_ip >= $nb_post_max) {
311  $error++;
312  $errmsg .= $langs->trans("AlreadyTooMuchPostOnThisIPAdress");
313  array_push($confattendee->errors, $langs->trans("AlreadyTooMuchPostOnThisIPAdress"));
314  setEventMessage($errmsg, 'errors');
315  } else {
316  $resultconfattendee = $confattendee->create($user);
317  }
318  if ($resultconfattendee < 0) {
319  $error++;
320  $errmsg .= $confattendee->error;
321  $errors = array_merge($errors, $confattendee->errors);
322  }
323  }
324 
325  // At this point, we have an existing $confattendee. It may not be linked to a thirdparty.
326  //var_dump($confattendee);
327 
328  // If the registration has already been paid for this attendee
329  if (!empty($confattendee->date_subscription) && !empty($confattendee->amount)) {
330  $securekeyurl = dol_hash($conf->global->EVENTORGANIZATION_SECUREKEY.'conferenceorbooth'.$id, 'master');
331  $redirection = $dolibarr_main_url_root.'/public/eventorganization/subscriptionok.php?id='.((int) $id).'&securekey='.urlencode($securekeyurl);
332 
333  $mesg = $langs->trans("RegistrationAndPaymentWereAlreadyRecorded", $email);
334  setEventMessages($mesg, null, 'mesgs');
335 
336  $db->commit();
337 
338  Header("Location: ".$redirection);
339  exit;
340  }
341 
342  $resultfetchthirdparty = 0;
343 
344  $genericcompanyname = $langs->trans('EventParticipant').' '.($emailcompany ? $emailcompany : $email); // Keep this label simple so we can retreive same thirdparty for another event
345 
346  // Getting the thirdparty or creating it
347  $thirdparty = new Societe($db);
348  $contact = new Contact($db);
349  // Fetch using fk_soc if the attendee was already found
350  if (!empty($confattendee->fk_soc) && $confattendee->fk_soc > 0) {
351  $resultfetchthirdparty = $thirdparty->fetch($confattendee->fk_soc);
352  } else {
353  if (empty($conf->global->EVENTORGANIZATION_DISABLE_RETREIVE_THIRDPARTY_FROM_NAME)) {
354  // Fetch using the field input by end user if we have just created the attendee
355  if ($resultfetchthirdparty <= 0 && !empty($societe) && !empty($emailcompany)) {
356  $resultfetchthirdparty = $thirdparty->fetch('', $societe, '', '', '', '', '', '', '', '', $emailcompany);
357  if ($resultfetchthirdparty > 0) {
358  // We found a unique result with the name + emailcompany, 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("ErrorSeveralCompaniesWithNameContactUs", $mysoc->email);
363  }
364  }
365  // Fetch using the field input by end user if we have just created the attendee
366  if ($resultfetchthirdparty <= 0 && !empty($societe) && !empty($email) && $email != $emailcompany) {
367  $resultfetchthirdparty = $thirdparty->fetch('', $societe, '', '', '', '', '', '', '', '', $email);
368  if ($resultfetchthirdparty > 0) {
369  // We found a unique result with the 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  if ($resultfetchthirdparty <= 0 && !empty($emailcompany)) {
378  // Try to find thirdparty from the email only
379  $resultfetchthirdparty = $thirdparty->fetch('', '', '', '', '', '', '', '', '', '', $emailcompany);
380  if ($resultfetchthirdparty > 0) {
381  // We found a unique result with that email only, so we set the fk_soc of attendee
382  $confattendee->fk_soc = $thirdparty->id;
383  $confattendee->update($user);
384  } elseif ($resultfetchthirdparty == -2) {
385  $thirdparty->error = $langs->trans("ErrorSeveralCompaniesWithEmailContactUs", $mysoc->email);
386  }
387  }
388  if ($resultfetchthirdparty <= 0 && !empty($email) && $email != $emailcompany) {
389  // Try to find thirdparty from the email only
390  $resultfetchthirdparty = $thirdparty->fetch('', '', '', '', '', '', '', '', '', '', $email);
391  if ($resultfetchthirdparty > 0) {
392  // We found a unique result with that email 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 = $langs->trans("ErrorSeveralCompaniesWithEmailContactUs", $mysoc->email);
397  }
398  }
399  if ($resultfetchthirdparty <= 0 && !empty($genericcompanyname)) {
400  // Try to find thirdparty from the generic mail only
401  $resultfetchthirdparty = $thirdparty->fetch('', $genericcompanyname, '', '', '', '', '', '', '', '', '');
402  if ($resultfetchthirdparty > 0) {
403  // We found a unique result with that name + email, so we set the fk_soc of attendee
404  $confattendee->fk_soc = $thirdparty->id;
405  $confattendee->update($user);
406  } elseif ($resultfetchthirdparty == -2) {
407  $thirdparty->error = $langs->trans("ErrorSeveralCompaniesWithNameContactUs", $mysoc->email);
408  }
409  }
410 
411  // TODO Add more tests on a VAT number, profid or a name ?
412 
413  if ($resultfetchthirdparty <= 0 && !empty($email)) {
414  // Try to find the thirdparty from the contact
415  $resultfetchcontact = $contact->fetch('', null, '', $email);
416  if ($resultfetchcontact > 0 && $contact->fk_soc > 0) {
417  $thirdparty->fetch($contact->fk_soc);
418  $confattendee->fk_soc = $thirdparty->id;
419  $confattendee->update($user);
420  $resultfetchthirdparty = 1;
421  }
422  }
423 
424  if ($resultfetchthirdparty <= 0 && !empty($societe)) {
425  // Try to find thirdparty from the company name only
426  $resultfetchthirdparty = $thirdparty->fetch('', $societe, '', '', '', '', '', '', '', '', '');
427  if ($resultfetchthirdparty > 0) {
428  // We found a unique result with that name only, so we set the fk_soc of attendee
429  $confattendee->fk_soc = $thirdparty->id;
430  $confattendee->update($user);
431  } elseif ($resultfetchthirdparty == -2) {
432  $thirdparty->error = "ErrorSeveralCompaniesWithNameContactUs";
433  }
434  }
435  }
436 
437  // If price is empty, no need to create a thirdparty, so we force $resultfetchthirdparty as if we have already found thirdp party.
438  if (empty(floatval($project->price_registration))) {
439  $resultfetchthirdparty = 1;
440  }
441 
442  if ($resultfetchthirdparty < 0) {
443  // If an error was found
444  $error++;
445  $errmsg .= $thirdparty->error;
446  $errors = array_merge($errors, $thirdparty->errors);
447  } elseif ($resultfetchthirdparty == 0) { // No thirdparty found + a payment is expected
448  // Creation of a new thirdparty
449  if (!empty($societe)) {
450  $thirdparty->name = $societe;
451  } else {
452  $thirdparty->name = $genericcompanyname;
453  }
454  $thirdparty->address = GETPOST("address");
455  $thirdparty->zip = GETPOST("zipcode");
456  $thirdparty->town = GETPOST("town");
457  $thirdparty->client = $thirdparty::PROSPECT;
458  $thirdparty->fournisseur = 0;
459  $thirdparty->country_id = GETPOST("country_id", 'int');
460  $thirdparty->state_id = GETPOST("state_id", 'int');
461  $thirdparty->email = ($emailcompany ? $emailcompany : $email);
462 
463  // Load object modCodeTiers
464  $module = (!empty($conf->global->SOCIETE_CODECLIENT_ADDON) ? $conf->global->SOCIETE_CODECLIENT_ADDON : 'mod_codeclient_leopard');
465  if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php') {
466  $module = substr($module, 0, dol_strlen($module) - 4);
467  }
468  $dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
469  foreach ($dirsociete as $dirroot) {
470  $res = dol_include_once($dirroot.$module.'.php');
471  if ($res) {
472  break;
473  }
474  }
475  $modCodeClient = new $module($db);
476 
477  if (empty($tmpcode) && !empty($modCodeClient->code_auto)) {
478  $tmpcode = $modCodeClient->getNextValue($thirdparty, 0);
479  }
480  $thirdparty->code_client = $tmpcode;
481  $readythirdparty = $thirdparty->create($user);
482  if ($readythirdparty < 0) {
483  $error++;
484  $errmsg .= $thirdparty->error;
485  $errors = array_merge($errors, $thirdparty->errors);
486  } else {
487  $thirdparty->country_code = getCountry($thirdparty->country_id, 2, $db, $langs);
488  $thirdparty->country = getCountry($thirdparty->country_code, 0, $db, $langs);
489 
490  // Update attendee country to match country of thirdparty
491  $confattendee->fk_soc = $thirdparty->id;
492  $confattendee->update($user);
493  }
494  }
495  }
496 
497  if (!$error) {
498  // If the registration needs a payment
499  if (!empty(floatval($project->price_registration))) {
500  $outputlangs = $langs;
501 
502  // TODO Use default language of $thirdparty->default_lang to build $outputlang
503 
504  // Get product to use for invoice
505  $productforinvoicerow = new Product($db);
506  $productforinvoicerow->id = 0;
507 
508  $resultprod = 0;
509  if ($conf->global->SERVICE_CONFERENCE_ATTENDEE_SUBSCRIPTION > 0) {
510  $resultprod = $productforinvoicerow->fetch($conf->global->SERVICE_CONFERENCE_ATTENDEE_SUBSCRIPTION);
511  }
512 
513  // Create the draft invoice for the payment
514  if ($resultprod < 0) {
515  $error++;
516  $errmsg .= $productforinvoicerow->error;
517  $errors = array_merge($errors, $productforinvoicerow->errors);
518  } else {
519  $facture = new Facture($db);
520  if (empty($confattendee->fk_invoice)) {
521  $facture->type = Facture::TYPE_STANDARD;
522  $facture->socid = $thirdparty->id;
523  $facture->paye = 0;
524  $facture->date = dol_now();
525  $facture->cond_reglement_id = $confattendee->cond_reglement_id;
526  $facture->fk_project = $project->id;
527  $facture->status = Facture::STATUS_DRAFT;
528 
529  if (empty($facture->cond_reglement_id)) {
530  $paymenttermstatic = new PaymentTerm($confattendee->db);
531  $facture->cond_reglement_id = $paymenttermstatic->getDefaultId();
532  if (empty($facture->cond_reglement_id)) {
533  $error++;
534  $confattendee->error = 'ErrorNoPaymentTermRECEPFound';
535  $confattendee->errors[] = $confattendee->error;
536  }
537  }
538  $resultfacture = $facture->create($user);
539  if ($resultfacture <= 0) {
540  $confattendee->error = $facture->error;
541  $confattendee->errors = $facture->errors;
542  $error++;
543  } else {
544  $confattendee->fk_invoice = $resultfacture;
545  $confattendee->update($user);
546  }
547  } else {
548  $facture->fetch($confattendee->fk_invoice);
549  }
550 
551  // Add link between invoice and the attendee registration
552  /*if (!$error) {
553  $facture->add_object_linked($confattendee->element, $confattendee->id);
554  }*/
555  }
556 
557  if (!$error) {
558  // Add line to draft invoice
559  $vattouse = get_default_tva($mysoc, $thirdparty, $productforinvoicerow->id);
560 
561  $labelforproduct = $outputlangs->trans("EventFee", $project->title);
562  if ($project->location) {
563  $labelforproduct .= ' - '.$project->location;
564  }
565  $date_start = $project->date_start_event;
566  $date_end = $project->date_end_event;
567 
568  // If there is no lines yet, we add one
569  if (empty($facture->lines)) {
570  $pu_ttc = floatval($project->price_registration);
571  $pu_ht = 0;
572  $price_base_type = 'TTC';
573 
574  $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);
575  if ($result <= 0) {
576  $confattendee->error = $facture->error;
577  $confattendee->errors = $facture->errors;
578  $error++;
579  }
580  }
581  }
582 
583  if (!$error) {
584  $db->commit();
585 
586  // Registration was recorded and invoice was generated, but payment not yet done.
587  // TODO
588  // Send an email to says registration shas been received and that we are waiting for the payment.
589  // Should send email template (EventOrganizationEmailRegistrationEvent) saved into conf EVENTORGANIZATION_TEMPLATE_EMAIL_REGISTRATION_EVENT.
590 
591  // Now we redirect to the payment page
592  $sourcetouse = 'organizedeventregistration';
593  $reftouse = $facture->id;
594  $redirection = $dolibarr_main_url_root.'/public/payment/newpayment.php?source='.urlencode($sourcetouse).'&ref='.urlencode($reftouse);
595  if (!empty($conf->global->PAYMENT_SECURITY_TOKEN)) {
596  if (!empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) {
597  $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
598  } else {
599  $redirection .= '&securekey='.urlencode($conf->global->PAYMENT_SECURITY_TOKEN);
600  }
601  }
602 
603  Header("Location: ".$redirection);
604  exit;
605  } else {
606  $db->rollback();
607  }
608  } else {
609  $db->commit();
610 
611  // No price has been set
612  // Validating the subscription
613  $confattendee->setStatut(1);
614 
615  // Sending mail
616  require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
617  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
618  $formmail = new FormMail($db);
619  // Set output language
620  $outputlangs = new Translate('', $conf);
621  $outputlangs->setDefaultLang(empty($thirdparty->default_lang) ? $mysoc->default_lang : $thirdparty->default_lang);
622  // Load traductions files required by page
623  $outputlangs->loadLangs(array("main", "members"));
624  // Get email content from template
625  $arraydefaultmessage = null;
626 
627  $labeltouse = $conf->global->EVENTORGANIZATION_TEMPLATE_EMAIL_AFT_SUBS_EVENT;
628  if (!empty($labeltouse)) {
629  $arraydefaultmessage = $formmail->getEMailTemplate($db, 'eventorganization_send', $user, $outputlangs, $labeltouse, 1, '');
630  }
631 
632  if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
633  $subject = $arraydefaultmessage->topic;
634  $msg = $arraydefaultmessage->content;
635  }
636 
637  $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $thirdparty);
638  complete_substitutions_array($substitutionarray, $outputlangs, $object);
639 
640  $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
641  $texttosend = make_substitutions($msg, $substitutionarray, $outputlangs);
642 
643  $sendto = $thirdparty->email;
644  $from = $conf->global->MAILING_EMAIL_FROM;
645  $urlback = $_SERVER["REQUEST_URI"];
646 
647  $ishtml = dol_textishtml($texttosend); // May contain urls
648 
649  $mailfile = new CMailFile($subjecttosend, $sendto, $from, $texttosend, array(), array(), array(), '', '', 0, $ishtml);
650 
651  $result = $mailfile->sendfile();
652  if ($result) {
653  dol_syslog("EMail sent to ".$sendto, LOG_DEBUG, 0, '_payment');
654  } else {
655  dol_syslog("Failed to send EMail to ".$sendto, LOG_ERR, 0, '_payment');
656  }
657 
658  $securekeyurl = dol_hash($conf->global->EVENTORGANIZATION_SECUREKEY.'conferenceorbooth'.$id, 2);
659  $redirection = $dolibarr_main_url_root.'/public/eventorganization/subscriptionok.php?id='.((int) $id).'&securekey='.urlencode($securekeyurl);
660 
661  Header("Location: ".$redirection);
662  exit;
663  }
664  //Header("Location: ".$urlback);
665  //exit;
666  } else {
667  $db->rollback();
668  }
669 }
670 
671 
672 /*
673  * View
674  */
675 
676 $form = new Form($db);
677 $formcompany = new FormCompany($db);
678 
679 llxHeaderVierge($langs->trans("NewRegistration"));
680 
681 print '<br>';
682 print load_fiche_titre($langs->trans("NewRegistration"), '', '', 0, 0, 'center');
683 
684 
685 print '<div align="center">';
686 print '<div id="divsubscribe">';
687 print '<div class="center subscriptionformhelptext">';
688 
689 // Welcome message
690 
691 print '<span class="opacitymedium">'.$langs->trans("EvntOrgWelcomeMessage").'</span>';
692 print '<br>';
693 print '<span class="eventlabel">'.$project->title . ' '. $conference->label.'</span><br>';
694 if ($project->date_start_event || $project->date_end_event) {
695  print '<span class="fa fa-calendar pictofixedwidth"></span>';
696 }
697 if ($project->date_start_event) {
698  $format = 'day';
699  $tmparray = dol_getdate($project->date_start_event, false, '');
700  if ($tmparray['hours'] || $tmparray['minutes'] || $tmparray['minutes']) {
701  $format = 'dayhour';
702  }
703  print dol_print_date($project->date_start_event, $format);
704 }
705 if ($project->date_start_event && $project->date_end_event) {
706  print ' - ';
707 }
708 if ($project->date_end_event) {
709  $format = 'day';
710  $tmparray = dol_getdate($project->date_end_event, false, '');
711  if ($tmparray['hours'] || $tmparray['minutes'] || $tmparray['minutes']) {
712  $format = 'dayhour';
713  }
714  print dol_print_date($project->date_end_event, $format);
715 }
716 if ($project->date_start_event || $project->date_end_event) {
717  print '<br>';
718 }
719 if ($project->location) {
720  print '<span class="fa fa-map-marked-alt pictofixedwidth"></span>'.$project->location.'<br>';
721 }
722 
723 $maxattendees = 0;
724 if ($conference->id > 0) {
725  /* date of project is not date of event so commented
726  print $langs->trans("Date").': ';
727  print dol_print_date($conference->datep);
728  if ($conference->date_end) {
729  print ' - ';
730  print dol_print_date($conference->datef);
731  }*/
732 } else {
733  /* date of project is not date of event so commented
734  print $langs->trans("Date").': ';
735  print dol_print_date($project->date_start);
736  if ($project->date_end) {
737  print ' - ';
738  print dol_print_date($project->date_end);
739  }*/
740  $maxattendees = $project->max_attendees; // Max attendeed for the project/event
741 }
742 print '</div>';
743 
744 if ($maxattendees && $currentnbofattendees >= $maxattendees) {
745  print '<br>';
746  print '<div class="warning">'.$langs->trans("MaxNbOfAttendeesReached").'</div>';
747  print '<br>';
748 }
749 
750 
751 
752 dol_htmloutput_errors($errmsg, $errors);
753 
754 if ((!empty($conference->id) && $conference->status == ConferenceOrBooth::STATUS_CONFIRMED) || (!empty($project->id) && $project->status == Project::STATUS_VALIDATED)) {
755  if (empty($maxattendees) || $currentnbofattendees < $maxattendees) {
756  // Print form
757  print '<form action="' . $_SERVER["PHP_SELF"] . '" method="POST" name="newmember">' . "\n";
758  print '<input type="hidden" name="token" value="' . newToken() . '" / >';
759  print '<input type="hidden" name="entity" value="' . $entity . '" />';
760  print '<input type="hidden" name="action" value="add" />';
761  print '<input type="hidden" name="type" value="' . $type . '" />';
762  print '<input type="hidden" name="id" value="' . $conference->id . '" />';
763  print '<input type="hidden" name="fk_project" value="' . $project->id . '" />';
764  print '<input type="hidden" name="securekey" value="' . $securekeyreceived . '" />';
765 
766  print '<br>';
767  print '<br>';
768  //print '<span class="opacitymedium">' . $langs->trans("FieldsWithAreMandatory", '*') . '</span><br>';
769  //print $langs->trans("FieldsWithIsForPublic",'**').'<br>';
770 
771  print dol_get_fiche_head('');
772 
773  print '<script type="text/javascript">
774  jQuery(document).ready(function () {
775  jQuery(document).ready(function () {
776  jQuery("#selectcountry_id").change(function() {
777  document.newmember.action.value="create";
778  document.newmember.submit();
779  });
780  });
781  });
782  </script>';
783 
784  print '<table class="border" summary="form to subscribe" id="tablesubscribe">' . "\n";
785 
786  // Email
787  print '<tr><td><span class="fieldrequired">' . $langs->trans("EmailAttendee") . '</span></td><td>';
788  print img_picto('', 'email', 'class="pictofixedwidth"');
789  print '<input type="text" name="email" maxlength="255" class="minwidth200 widthcentpercentminusx maxwidth300" value="' . dol_escape_htmltag(GETPOST('email')) . '" required></td></tr>' . "\n";
790 
791  // Company
792  print '<tr id="trcompany" class="trcompany"><td>';
793  if (!empty(floatval($project->price_registration))) {
794  print '<span class="fieldrequired">';
795  }
796  print $langs->trans("Company");
797  if (!empty(floatval($project->price_registration))) {
798  print '</span>';
799  }
800  print '</td><td>';
801  print img_picto('', 'company', 'class="pictofixedwidth"');
802  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";
803 
804  // Email company for invoice
805  if ($project->price_registration) {
806  print '<tr><td>' . $form->textwithpicto($langs->trans("EmailCompany"), $langs->trans("EmailCompanyForInvoice")) . '</td><td>';
807  print img_picto('', 'email', 'class="pictofixedwidth"');
808  print '<input type="text" name="emailcompany" maxlength="255" class="minwidth200 widthcentpercentminusx maxwidth300" value="' . dol_escape_htmltag(GETPOST('emailcompany')) . '"></td></tr>' . "\n";
809  }
810 
811  // Address
812  print '<tr><td>' . $langs->trans("Address") . '</td><td>' . "\n";
813  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";
814 
815  // Zip / Town
816  print '<tr><td>' . $langs->trans('Zip') . ' / ' . $langs->trans('Town') . '</td><td>';
817  print $formcompany->select_ziptown(GETPOST('zipcode'), 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6, 1);
818  print ' / ';
819  print $formcompany->select_ziptown(GETPOST('town'), 'town', array('zipcode', 'selectcountry_id', 'state_id'), 0, 1);
820  print '</td></tr>';
821 
822  // Country
823  print '<tr><td><span class="fieldrequired">'.$langs->trans('Country').'</span></td><td>';
824  print img_picto('', 'country', 'class="pictofixedwidth"');
825  $country_id = GETPOST('country_id');
826  if (!$country_id && !empty($conf->global->MEMBER_NEWFORM_FORCECOUNTRYCODE)) {
827  $country_id = getCountry($conf->global->MEMBER_NEWFORM_FORCECOUNTRYCODE, 2, $db, $langs);
828  }
829  if (!$country_id && !empty($conf->geoipmaxmind->enabled)) {
830  $country_code = dol_user_country();
831  //print $country_code;
832  if ($country_code) {
833  $new_country_id = getCountry($country_code, 3, $db, $langs);
834  //print 'xxx'.$country_code.' - '.$new_country_id;
835  if ($new_country_id) {
836  $country_id = $new_country_id;
837  }
838  }
839  }
840  $country_code = getCountry($country_id, 2, $db, $langs);
841  print $form->select_country($country_id, 'country_id', '', 0, 'minwidth200 widthcentpercentminusx maxwidth300');
842  print '</td></tr>';
843  // State
844  if (empty($conf->global->SOCIETE_DISABLE_STATE)) {
845  print '<tr><td>' . $langs->trans('State') . '</td><td>';
846  if ($country_code) {
847  print img_picto('', 'state', 'class="pictofixedwidth"');
848  print $formcompany->select_state(GETPOST("state_id"), $country_code);
849  } else {
850  print '';
851  }
852  print '</td></tr>';
853  }
854 
855  if ($project->price_registration) {
856  print '<tr><td>' . $langs->trans('Price') . '</td><td>';
857  print '<span class="amount price-registration">'.price($project->price_registration, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
858  print '</td></tr>';
859  }
860 
861  $notetoshow = $note_public;
862  print '<tr><td>' . $langs->trans('Note') . '</td><td>';
863  if (!empty($conf->global->EVENTORGANIZATION_DEFAULT_NOTE_ON_REGISTRATION)) {
864  $notetoshow = str_replace('\n', "\n", $conf->global->EVENTORGANIZATION_DEFAULT_NOTE_ON_REGISTRATION);
865  }
866  print '<textarea name="note_public" class="centpercent" rows="'.ROWS_9.'">'.dol_escape_htmltag($notetoshow, 0, 1).'</textarea>';
867  print '</td></tr>';
868 
869  print "</table>\n";
870 
871  print dol_get_fiche_end();
872 
873  // Save
874  print '<div class="center">';
875  print '<input type="submit" value="' . $langs->trans("Submit") . '" id="submitsave" class="button">';
876  if (!empty($backtopage)) {
877  print ' &nbsp; &nbsp; <input type="submit" value="' . $langs->trans("Cancel") . '" id="submitcancel" class="button button-cancel">';
878  }
879  print '</div>';
880 
881  print "</form>\n";
882 
883  print "<br>";
884  print '</div></div>';
885  }
886 } else {
887  print $langs->trans("ConferenceIsNotConfirmed");
888 }
889 
891 
892 $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') &&!empty($user->rights->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') &&!empty($user->rights->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)) $resql
Social contributions to pay.
Definition: index.php:745
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:121
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='')
Show tabs of a record.
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.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages 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.
setEventMessage($mesgs, $style='mesgs')
Set event message in dol_events session object.
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null)
Return array of possible common substitutions.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
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.
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:1530
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.