dolibarr 24.0.0-beta
index.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2006-2017 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2009-2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2023 anthony Berton <anthony.berton@bb2a.fr>
6 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
7 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
30if (!defined('NOLOGIN')) {
31 define("NOLOGIN", 1); // This means this output page does not require to be logged.
32}
33if (!defined('NOCSRFCHECK')) {
34 define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
35}
36if (!defined('NOBROWSERNOTIF')) {
37 define('NOBROWSERNOTIF', '1');
38}
39
40// Load Dolibarr environment
41require '../../main.inc.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
43require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
44require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
45require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
46require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
47require_once DOL_DOCUMENT_ROOT.'/bookcal/class/calendar.class.php';
48require_once DOL_DOCUMENT_ROOT.'/bookcal/class/availabilities.class.php';
49require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
50require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
51require_once DOL_DOCUMENT_ROOT.'/core/lib/public.lib.php';
52
53// Security check
54if (!isModEnabled('bookcal')) {
55 httponly_accessforbidden('Module Bookcal isn\'t enabled');
56}
57
66$langs->loadLangs(array("main", "other", "dict", "agenda", "errors", "companies"));
67
68$action = GETPOST('action', 'aZ09');
69$id = GETPOSTINT('id');
70$id_availability = GETPOSTINT('id_availability');
71
72$year = GETPOSTINT("year") ? GETPOSTINT("year") : idate("Y");
73$month = GETPOSTINT("month") ? GETPOSTINT("month") : idate("m");
74$week = GETPOSTINT("week") ? GETPOSTINT("week") : idate("W");
75$day = GETPOSTINT("day") ? GETPOSTINT("day") : idate("d");
76$dateselect = dol_mktime(0, 0, 0, GETPOSTINT('dateselectmonth'), GETPOSTINT('dateselectday'), GETPOSTINT('dateselectyear'), 'tzuserrel');
77if ($dateselect > 0) {
78 $day = GETPOSTINT('dateselectday');
79 $month = GETPOSTINT('dateselectmonth');
80 $year = GETPOSTINT('dateselectyear');
81}
82$backtopage = GETPOST("backtopage", "alpha");
83
84$object = new Calendar($db);
85$result = $object->fetch($id);
86
87$availability = new Availabilities($db);
88if ($id_availability > 0) {
89 $result = $availability->fetch($id_availability);
90}
91
92$now = dol_now();
93$nowarray = dol_getdate($now);
94$nowyear = $nowarray['year'];
95$nowmonth = $nowarray['mon'];
96$nowday = $nowarray['mday'];
97
98$prev = dol_get_prev_month($month, $year);
99$prev_year = $prev['year'];
100$prev_month = $prev['month'];
101$next = dol_get_next_month($month, $year);
102$next_year = $next['year'];
103$next_month = $next['month'];
104
105$max_day_in_prev_month = idate("t", dol_mktime(0, 0, 0, $prev_month, 1, $prev_year, 'gmt')); // Nb of days in previous month
106$max_day_in_month = idate("t", dol_mktime(0, 0, 0, $month, 1, $year)); // Nb of days in next month
107// tmpday is a negative or null cursor to know how many days before the 1st to show on month view (if tmpday=0, 1st is monday)
108$tmpday = - idate("w", dol_mktime(12, 0, 0, $month, 1, $year, 'gmt')) + 2; // idate('w') is 0 for sunday
109$tmpday += (getDolGlobalInt('MAIN_START_WEEK', 1) - 1);
110if ($tmpday >= 1) {
111 $tmpday -= 7; // If tmpday is 0 we start with sunday, if -6, we start with monday of previous week.
112}
113// Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
114$firstdaytoshow = dol_mktime(0, 0, 0, $prev_month, $max_day_in_prev_month + $tmpday, $prev_year, 'tzuserrel');
115$next_day = 7 - ($max_day_in_month + 1 - $tmpday) % 7;
116if ($next_day < 6) {
117 $next_day += 7;
118}
119$lastdaytoshow = dol_mktime(0, 0, 0, $next_month, $next_day, $next_year, 'tzuserrel');
120
121$datechosen = GETPOST('datechosen', 'alpha');
122$datetimechosen = GETPOSTINT('datetimechosen');
123$isdatechosen = false;
124$timebooking = GETPOST("timebooking");
125$datetimebooking = GETPOSTINT("datetimebooking");
126$durationbooking = GETPOSTINT("durationbooking");
127$errmsg = '';
128
143function llxHeaderVierge($title, $head = "", $disablejs = 0, $disablehead = 0, $arrayofjs = [], $arrayofcss = [], $ws = '') // @phan-suppress-current-line PhanRedefineFunction
144{
145 global $conf, $langs, $mysoc;
146
147 top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss); // Show html headers
148
149 print '<body id="mainbody" class="publicnewmemberform">';
150
151 include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
152 htmlPrintOnlineHeader($mysoc, $langs, 1, getDolGlobalString('BOOKCAL_PUBLIC_INTERFACE_TOPIC', $langs->trans("BookCalSystem")), 'BOOKCAL_PUBLIC_INTERFACE_IMAGE');
153
154 print '<div class="divmainbodylarge">';
155}
156
157
158/*
159 * Actions
160 */
161
162if ($action == 'add') { // Test on permission not required here (anonymous action protected by mitigation of /public/... urls)
163 $error = 0;
164 $idcontact = 0;
165 $calendar = $object;
166 $contact = new Contact($db);
167 $actioncomm = new ActionComm($db);
168 $nb_post_max = getDolGlobalInt("MAIN_SECURITY_MAX_POST_ON_PUBLIC_PAGES_BY_IP_ADDRESS", 200);
169
170 if (!is_object($user)) {
171 $user = new User($db);
172 }
173
174 $db->begin();
175
176 if (!GETPOST("lastname")) {
177 $error++;
178 $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Lastname"))."<br>\n";
179 }
180 if (!GETPOST("firstname")) {
181 $error++;
182 $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Firstname"))."<br>\n";
183 }
184 if (!GETPOST("email")) {
185 $error++;
186 $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Email"))."<br>\n";
187 }
188
189 if (!$error) {
190 $sql = "SELECT s.rowid";
191 $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as s";
192 $sql .= " WHERE s.lastname = '".$db->escape(GETPOST("lastname"))."'";
193 $sql .= " AND s.firstname = '".$db->escape(GETPOST("firstname"))."'";
194 $sql .= " AND s.email = '".$db->escape(GETPOST("email"))."'";
195 $resql = $db->query($sql);
196
197 if ($resql) {
198 $num = $db->num_rows($resql);
199 if ($num > 0) {
200 $obj = $db->fetch_object($resql);
201 $idcontact = $obj->rowid;
202 $contact->fetch($idcontact);
203 } else {
204 $contact->lastname = GETPOST("lastname");
205 $contact->firstname = GETPOST("firstname");
206 $contact->email = GETPOST("email");
207 $contact->ip = getUserRemoteIP();
208
209 if (checkNbPostsForASpeceificIp($contact, $nb_post_max) <= 0) {
210 $error++;
211 $errmsg .= implode('<br>', $contact->errors);
212 } else {
213 $result = $contact->create($user);
214 if ($result < 0) {
215 $error++;
216 $errmsg .= $contact->error." ".implode(',', $contact->errors);
217 }
218 }
219 }
220 } else {
221 $error++;
222 $errmsg .= $db->lasterror();
223 }
224 }
225
226 if (!$error) {
227 $dateend = dol_time_plus_duree(GETPOSTINT("datetimebooking"), GETPOSTINT("durationbooking"), 'i');
228
229 $actioncomm->label = $langs->trans("BookcalBookingTitle");
230 $actioncomm->type = 'AC_RDV';
231 $actioncomm->type_id = 5;
232 $actioncomm->datep = GETPOSTINT("datetimebooking");
233 $actioncomm->datef = $dateend;
234 $actioncomm->note_private = GETPOST("description");
235 $actioncomm->percentage = -1;
236 $actioncomm->fk_bookcal_calendar = $id;
237 $actioncomm->userownerid = $calendar->visibility;
238 $actioncomm->contact_id = $contact->id;
239 $actioncomm->socpeopleassigned = [
240 $contact->id => [
241 'id' => $contact->id,
242 'mandatory' => 0,
243 'answer_status' => 0,
244 'transparency' => 0,
245 ]
246 ];
247 $actioncomm->ip = getUserRemoteIP();
248 if (checkNbPostsForASpeceificIp($actioncomm, $nb_post_max) <= 0) {
249 $error++;
250 $errmsg .= implode('<br>', $actioncomm->errors);
251 } else {
252 $result = $actioncomm->create($user);
253 if ($result < 0) {
254 $error++;
255 $errmsg .= $actioncomm->error." ".implode(',', $actioncomm->errors);
256 }
257 }
258 }
259
260 if (!$error) {
261 $db->commit();
262 $action = 'afteradd';
263 } else {
264 $db->rollback();
265 $action = 'create';
266 }
267}
268
269
270/*
271 * View
272 */
273
274$form = new Form($db);
275
276
277// Define $urlwithroot
278$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
279$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
280//$urlwithroot = DOL_MAIN_URL_ROOT; // This is to use same domain name than current. For Paypal payment, we can use internal URL like localhost.
281// TODO Replace DOL_URL_ROOT with $urlwithroot ?
282
283
284llxHeaderVierge('BookingCalendar');
285
286print '<center><br><h2>'.(!empty($object->label) ? $object->label : $object->ref).'</h2></center>';
287
288if ($object->status == $object::STATUS_DRAFT) {
289 $langs->trans("errors");
290 $errmsg = $langs->trans("ErrorCalendarIsNotYetOpenOrHasBeenClosed");
291}
292
293dol_htmloutput_errors($errmsg);
294
295if ($action == 'create') {
296 $backtopage = $_SERVER["PHP_SELF"].'?id='.$id.'&datechosen='.$datechosen;
297} else {
298 $backtopage = DOL_URL_ROOT.'/public/bookcal/index.php?id='.$id;
299}
300
301//print '<div class="">';
302
303print '<div class="bookcalpublicarea centpercent center" style="min-width:30%;width:fit-content;height:70%;top:60%;left: 50%;">';
304print '<div class="bookcalform" style="min-height:50%">';
305if ($action == 'afteradd') {
306 print '<h2>';
307 print $langs->trans("BookingSuccessfullyBooked");
308 print '</h2>';
309 print $langs->trans("BookingReservationHourAfter", dol_print_date(GETPOSTINT("datetimebooking"), "dayhourtext"));
310} else {
311 $param = '';
312
313 print '<table class="centpercent">';
314 print '<tr>';
315 print '<td>';
316 if ($action != 'create') {
317 print '<form name="formsearch" class="bookcalsearch" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
318 print '<input type="hidden" name="id" value="'.$id.'">';
319
320 $nav = '<a href="?id='.$id."&year=".$prev_year."&month=".$prev_month.$param.'"><i class="fa fa-chevron-left"></i></a> &nbsp;'."\n";
321 $nav .= ' <span id="month_name">'.dol_print_date(dol_mktime(0, 0, 0, $month, 1, $year), "%b %Y");
322 $nav .= " </span>\n";
323 $nav .= ' &nbsp; <a href="?id='.$id."&year=".$next_year."&month=".$next_month.$param.'"><i class="fa fa-chevron-right"></i></a>'."\n";
324 if (empty($conf->dol_optimize_smallscreen)) {
325 $nav .= ' &nbsp; <a href="?id='.$id."&year=".$nowyear."&amp;month=".$nowmonth."&amp;day=".$nowday.$param.'" class="datenowlink">'.$langs->trans("Today").'</a> ';
326 }
327 $nav .= $form->selectDate($dateselect, 'dateselect', 0, 0, 1, '', 1, 0);
328 $nav .= '<button type="submit" class="liste_titre button_search valignmiddle" name="button_search_x" value="x"><span class="fa fa-search"></span></button>';
329
330 print $nav;
331 print '</form>';
332 }
333 print '</td>';
334 print '<td>';
335 print '<div class="bookingtab hidden" style="height:50%">';
336 print '<div id="bookingtabspandate"></div>';
337 print '</div>';
338 print '</td>';
339 print '</tr>';
340
341 print '<tr>';
342 if ($action == "create") {
343 print '<td>';
344 if (empty($datetimebooking)) {
345 $timebookingarray = explode(" - ", $timebooking);
346 $timestartarray = explode(":", $timebookingarray[0]);
347 $timeendarray = explode(":", $timebookingarray[1]);
348 $datetimebooking = dol_time_plus_duree($datetimechosen, intval($timestartarray[0]), "h");
349 $datetimebooking = dol_time_plus_duree($datetimebooking, intval($timestartarray[1]), "i");
350 }
351 print '<span>'.img_picto("", "calendar")." ".dol_print_date($datetimebooking, 'dayhourtext').'</span>';
352 print '<div class="center"><a href="'.$_SERVER["PHP_SELF"].'?id=1&year=2024&month=2" class="small">('.$langs->trans("SelectANewDate").')</a></div>';
353 print '</td>';
354
355 print '<td>';
356 print '<form method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
357 print '<table class="border" summary="form to subscribe" id="tablesubscribe">'."\n";
358 print '<input type="hidden" name="token" value="'.newToken().'">';
359 print '<input type="hidden" name="action" value="add">';
360 print '<input type="hidden" name="datetimebooking" value="'.$datetimebooking.'">';
361 print '<input type="hidden" name="datechosen" value="'.$datechosen.'">';
362 print '<input type="hidden" name="id" value="'.$id.'">';
363 print '<input type="hidden" name="durationbooking" value="'.$durationbooking.'">';
364
365 // Lastname
366 print '<tr><td><input autofocus type="text" name="lastname" class="minwidth150" placeholder="'.dol_escape_htmltag($langs->trans("Lastname").'*').'" value="'.dol_escape_htmltag(GETPOST('lastname')).'"></td></tr>'."\n";
367 // Firstname
368 print '<tr><td><input type="text" name="firstname" class="minwidth150" placeholder="'.dol_escape_htmltag($langs->trans("Firstname").'*').'" value="'.dol_escape_htmltag(GETPOST('firstname')).'"></td></tr>'."\n";
369 // EMail
370 print '<tr><td><input type="email" name="email" maxlength="255" class="minwidth150" placeholder="'.dol_escape_htmltag($langs->trans("Email").'*').'" value="'.dol_escape_htmltag(GETPOST('email')).'"></td></tr>'."\n";
371
372 // Comments
373 print '<tr>';
374 print '<td class="tdtop">';
375 print $langs->trans("Message");
376 print '<textarea name="description" id="description" wrap="soft" class="quatrevingtpercent" rows="'.ROWS_4.'">'.dol_escape_htmltag(GETPOST('description', 'restricthtml'), 0, 1).'</textarea></td>';
377 print '</tr>'."\n";
378 print '</table>'."\n";
379 print '<div class="center">';
380 print '<input type="submit" value="'.$langs->trans("Submit").'" id="submitsave" class="button">';
381 print '</div>';
382 print '</form>';
383 print '</td>';
384 } else {
385 print '<td>';
386 print '<table class="centpercent noborder nocellnopadd cal_pannel cal_month">';
387 print ' <tr class="">';
388 // Column title of weeks numbers
389 print ' <td class="center hideonsmartphone">#</td>';
390 $i = 0;
391 while ($i < 7) {
392 $numdayinweek = (($i + getDolGlobalInt('MAIN_START_WEEK', 1)) % 7);
393 if (!empty($conf->dol_optimize_smallscreen)) {
394 print ' <td class="center bold uppercase tdfordaytitle'.($i == 0 ? ' borderleft' : '').'">';
395 $labelshort = array(0 => 'SundayMin', 1 => 'MondayMin', 2 => 'TuesdayMin', 3 => 'WednesdayMin', 4 => 'ThursdayMin', 5 => 'FridayMin', 6 => 'SaturdayMin');
396 print $langs->trans($labelshort[$numdayinweek]);
397 print ' </td>'."\n";
398 } else {
399 print ' <td class="center minwidth75 bold uppercase small tdoverflowmax50 tdfordaytitle'.($i == 0 ? ' borderleft' : '').'">';
400 //$labelshort = array(0=>'SundayMin', 1=>'MondayMin', 2=>'TuesdayMin', 3=>'WednesdayMin', 4=>'ThursdayMin', 5=>'FridayMin', 6=>'SaturdayMin');
401 $labelshort = array(0 => 'Sunday', 1 => 'Monday', 2 => 'Tuesday', 3 => 'Wednesday', 4 => 'Thursday', 5 => 'Friday', 6 => 'Saturday');
402 print $langs->trans($labelshort[$numdayinweek]);
403 print ' </td>'."\n";
404 }
405 $i++;
406 }
407 print ' </tr>'."\n";
408
409 $todayarray = dol_getdate($now, true);
410 $todaytms = dol_mktime(0, 0, 0, $todayarray['mon'], $todayarray['mday'], $todayarray['year']);
411
412 // Load into an array all days with availabilities of the calendar for the current month $todayarray['mon'] and $todayarray['year']
413 $arrayofavailabledays = array();
414
415 $arrayofavailabilities = $availability->fetchAll('', '', 0, 0, '(status:=:1) AND (fk_bookcal_calendar:=:'.((int) $id).')');
416 if ($arrayofavailabilities < 0) {
417 setEventMessages($availability->error, $availability->errors, 'errors');
418 } else {
419 foreach ($arrayofavailabilities as $key => $value) {
420 $startarray = dol_getdate((int) $value->start);
421 $endarray = dol_getdate((int) $value->end);
422 for ($i = $startarray['mday']; $i <= $endarray['mday']; $i++) {
423 if ($todayarray['mon'] >= $startarray['mon'] && $todayarray['mon'] <= $endarray['mon']) {
424 $arrayofavailabledays[dol_mktime(0, 0, 0, $todayarray['mon'], $i, $todayarray['year'])] = dol_mktime(0, 0, 0, $todayarray['mon'], $i, $todayarray['year']);
425 }
426 }
427 }
428 }
429
430 for ($iter_week = 0; $iter_week < 6; $iter_week++) {
431 echo " <tr>\n";
432 // Get date of the current day, format 'yyyy-mm-dd'
433 if ($tmpday <= 0) { // If number of the current day is in previous month
434 $currdate0 = sprintf("%04d", $prev_year).sprintf("%02d", $prev_month).sprintf("%02d", $max_day_in_prev_month + $tmpday);
435 } elseif ($tmpday <= $max_day_in_month) { // If number of the current day is in current month
436 $currdate0 = sprintf("%04d", $year).sprintf("%02d", $month).sprintf("%02d", $tmpday);
437 } else {// If number of the current day is in next month
438 $currdate0 = sprintf("%04d", $next_year).sprintf("%02d", $next_month).sprintf("%02d", $tmpday - $max_day_in_month);
439 }
440 // Get week number for the targeted date '$currdate0'
441 $numweek0 = idate("W", strtotime(date($currdate0)));
442 // Show the week number, and define column width
443 echo ' <td class="center weeknumber opacitymedium hideonsmartphone" style="min-width: 40px">'.$numweek0.'</td>';
444
445 for ($iter_day = 0; $iter_day < 7; $iter_day++) {
446 if ($tmpday <= 0) {
447 /* Show days before the beginning of the current month (previous month) */
448 $style = 'cal_other_month cal_past';
449 if ($iter_day == 6) {
450 $style .= ' cal_other_month_right';
451 }
452 echo ' <td class="'.$style.' nowrap tdtop" width="14%">';
453 show_bookcal_day_events($max_day_in_prev_month + $tmpday, $prev_month, $prev_year);
454 echo " </td>\n";
455 } elseif ($tmpday <= $max_day_in_month) {
456 /* Show days of the current month */
457 $curtime = dol_mktime(0, 0, 0, $month, $tmpday, $year);
458 $style = 'cal_current_month';
459 if ($iter_day == 6) {
460 $style .= ' cal_current_month_right';
461 }
462 $today = 0;
463 if ($todayarray['mday'] == $tmpday && $todayarray['mon'] == $month && $todayarray['year'] == $year) {
464 $today = 1;
465 }
466 //var_dump($curtime); var_dump($todaytms); var_dump($arrayofavailabledays);
467 if ($curtime > $todaytms && in_array($curtime, $arrayofavailabledays)) {
468 $style .= ' cal_available cursorpointer';
469 }
470 if ($curtime < $todaytms) {
471 $style .= ' cal_past';
472 }
473 $dateint = sprintf("%04d", $year).'_'.sprintf("%02d", $month).'_'.sprintf("%02d", $tmpday);
474 if (!empty(explode('dayevent_', $datechosen)[1]) && explode('dayevent_', $datechosen)[1] == $dateint) {
475 $style .= ' cal_chosen';
476 $isdatechosen = true;
477 }
478 echo ' <td class="'.$style.' nowrap tdtop" width="14%">';
479 show_bookcal_day_events($tmpday, $month, $year, $today);
480 echo "</td>\n";
481 } else {
482 /* Show days after the current month (next month) */
483 $style = 'cal_other_month';
484 if ($iter_day == 6) {
485 $style .= ' cal_other_month_right';
486 }
487 echo ' <td class="'.$style.' nowrap tdtop" width="14%">';
488 show_bookcal_day_events($tmpday - $max_day_in_month, $next_month, $next_year);
489 echo "</td>\n";
490 }
491 $tmpday++;
492 }
493 echo " </tr>\n";
494 }
495 print '</table>';
496 print '</td>';
497
498 print '<td>'; // Column visible after selection of a day
499 print '<div class="center bookingtab" style="height:50%">';
500 print '<div style="height:100%">';
501 print '<form id="formbooking" name="formbooking" method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
502 print '<input type="hidden" name="id" value="'.$id.'">';
503 print '<input type="hidden" name="token" value="'.newToken().'">';
504 print '<input type="hidden" name="action" value="create">';
505 print '<input type="hidden" id="datechosen" name="datechosen" value="">';
506 print '<input type="hidden" id="datetimechosen" name="datetimechosen" value="">';
507 print '<input type="hidden" id="durationbooking" name="durationbooking" value="">';
508
509 print '<div id="bookinghoursection">';
510 print '<br><br><br><br><br><br><div class="opacitymedium center">'.$langs->trans("SelectADay").'</div>';
511 print '</div>';
512 print '</form>';
513 print '</div>';
514 print '</div>';
515
516 print '</td>';
517 }
518 print '</tr>';
519 print '</table>';
520 print '</div>';
521 print '</div>';
522
523 print '<script>';
524 print '
525 function generateBookingButtons(timearray, datestring){
526 console.log("We generate all booking buttons of "+datestring);
527 str = "";
528
529 for (index in timearray){
530 let hour = new Date("2000-01-01T" + index + ":00");
531 duration = timearray[index];
532 isalreadybooked = false;
533 if (duration < 0) {
534 duration *= -1;
535 isalreadybooked = true;
536 }
537 hour.setMinutes(hour.getMinutes() + duration);
538
539 let hours = hour.getHours().toString().padStart(2, "0"); // Formatter pour obtenir deux chiffres
540 let mins = hour.getMinutes().toString().padStart(2, "0"); // Formatter pour obtenir deux chiffres
541
542 timerange = index + " - " + `${hours}:${mins}`;
543 str += \'<input class="button btnsubmitbooking \'+(isalreadybooked == true ? "btnbookcalbooked" : "")+\'" type="submit" name="timebooking" value="\'+timerange+\'" data-duration="\'+duration+\'"><br>\';
544 }
545
546 $("#bookinghoursection").html(str);
547 $(".btnsubmitbooking").on("click", function(){
548 duration = $(this).data("duration");
549 $("#durationbooking").val(duration);
550 })
551 }';
552 print '$(document).ready(function() {
553 $(".cal_available").on("click", function(){
554 console.log("We click on cal_available");
555 $(".cal_chosen").removeClass("cal_chosen");
556 $(this).addClass("cal_chosen");
557 datestring = $(this).children("div").data("date");
558 $.ajax({
559 type: "POST",
560 url: "'.DOL_URL_ROOT.'/public/bookcal/bookcalAjax.php",
561 data: {
562 action: "verifyavailability",
563 id: '.((int) $id).',
564 datetocheck: $(this).children("div").data("datetime"),
565 token: "'.currentToken().'",
566 }
567 }).done(function (data) {
568 console.log("We show all booking");
569 if (data["code"] == "SUCCESS") {
570 /* TODO Replace this with a creating of allavailable hours button */
571 console.log(data)
572 timearray = data["availability"];
573 console.log(timearray);
574 generateBookingButtons(timearray, datestring);
575 $(".btnbookcalbooked").prop("disabled", true);
576 } else {
577 if(data["code"] == "NO_DATA_FOUND"){
578 console.log("No booking to hide");
579 } else {
580 console.log(data["message"]);
581 }
582 }
583 });
584 $(".bookingtab").removeClass("hidden");
585 $("#bookingtabspandate").text($(this).children("div").data("date"));
586 $("#datechosen").val($(this).children("div").attr("id"));
587 $("#datetimechosen").val($(this).children("div").data("datetime"));
588 });
589
590 $("btnformbooking")
591
592 '.($datechosen ? '$(".cal_chosen").trigger( "click" )' : '').'
593 });';
594 print '</script>';
595}
596
597llxFooter('', 'public');
598
599
609function show_bookcal_day_events($day, $month, $year, $today = 0)
610{
611 global $conf;
612 if ($conf->use_javascript_ajax) { // Enable the "Show more button..."
613 $conf->global->MAIN_JS_SWITCH_AGENDA = 1;
614 }
615
616 $dateint = sprintf("%04d", $year).'_'.sprintf("%02d", $month).'_'.sprintf("%02d", $day);
617 $eventdatetime = dol_mktime(-1, -1, -1, $month, $day, $year);
618 //print 'show_bookcal_day_events day='.$day.' month='.$month.' year='.$year.' dateint='.$dateint;
619
620 print "\n";
621
622 $curtime = dol_mktime(0, 0, 0, $month, $day, $year);
623 // Line with title of day
624 print '<div id="dayevent_'.$dateint.'" class="dayevent tagtable centpercent nobordernopadding" data-datetime="'.$eventdatetime.'" data-date="'.dol_print_date($eventdatetime, "daytext").'">'."\n";
625 print dol_print_date($curtime, '%d');
626 print '<br>';
627 if ($today) {
628 print img_picto('today', 'fontawesome_circle_fas_black_7px');
629 } else {
630 print '<br>';
631 }
632 print '</div>'; // table
633 print "\n";
634}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
global $dolibarr_main_url_root
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
Class to manage agenda events (actions)
Class for Availabilities.
Class for Calendar.
Class to manage contact/addresses.
Class to manage generation of HTML components Only common components must be here.
Class to manage Dolibarr users.
htmlPrintOnlineHeader($mysoc, $langs, $showlogo=1, $alttext='', $subimageconst='', $altlogo1='', $altlogo2='')
Show the header of a company in HTML public pages.
global $mysoc
dol_get_prev_month($month, $year)
Return previous month.
Definition date.lib.php:523
dol_get_next_month($month, $year)
Return next month.
Definition date.lib.php:542
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition date.lib.php:126
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getUserRemoteIP($trusted=0)
Return the real IP of remote user.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_htmloutput_errors($mesgstring='', $mesgarray=array(), $keepembedded=0)
Print formatted error messages to output (Used to show messages on html output).
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs=array(), $arrayofcss=array(), $disableforlogin=0, $disablenofollow=0, $disablenoindex=0)
Output html header of a page.
llxHeaderVierge($title, $head="", $disablejs=0, $disablehead=0, $arrayofjs=[], $arrayofcss=[], $ws='')
Show header for booking.
Definition index.php:143
show_bookcal_day_events($day, $month, $year, $today=0)
Show event of a particular day.
Definition index.php:609
checkNbPostsForASpeceificIp($object, $nb_post_max)
Check if the object exceeded the number of posts for a specific ip in the same week.
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as date
Definition receipt.php:487
httponly_accessforbidden($message='1', $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.