dolibarr 25.0.0-alpha
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';
50require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
51require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
52require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
53require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
54require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
55require_once DOL_DOCUMENT_ROOT.'/bookcal/class/calendar.class.php';
56require_once DOL_DOCUMENT_ROOT.'/bookcal/class/availabilities.class.php';
57require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
58require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
59require_once DOL_DOCUMENT_ROOT.'/core/lib/public.lib.php';
60
61// Security check
62if (!isModEnabled('bookcal')) {
63 httponly_accessforbidden('Module Bookcal isn\'t enabled');
64}
65
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 $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 if ($object->status != $object::STATUS_DRAFT) { // If calendar is open
175 $db->begin();
176
177 if (!GETPOST("lastname")) {
178 $error++;
179 $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Lastname"))."<br>\n";
180 }
181 if (!GETPOST("firstname")) {
182 $error++;
183 $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Firstname"))."<br>\n";
184 }
185 if (!GETPOST("email")) {
186 $error++;
187 $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Email"))."<br>\n";
188 }
189
190 if (!$error) {
191 $sql = "SELECT s.rowid";
192 $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as s";
193 $sql .= " WHERE s.lastname = '".$db->escape(GETPOST("lastname"))."'";
194 $sql .= " AND s.firstname = '".$db->escape(GETPOST("firstname"))."'";
195 $sql .= " AND s.email = '".$db->escape(GETPOST("email"))."'";
196 $resql = $db->query($sql);
197
198 if ($resql) {
199 $num = $db->num_rows($resql);
200 if ($num > 0) {
201 $obj = $db->fetch_object($resql);
202 $idcontact = $obj->rowid;
203 $contact->fetch($idcontact);
204 } else {
205 $contact->lastname = GETPOST("lastname");
206 $contact->firstname = GETPOST("firstname");
207 $contact->email = GETPOST("email");
208 $contact->ip = getUserRemoteIP();
209
210 if (checkNbPostsForASpeceificIp($contact, $nb_post_max) <= 0) {
211 $error++;
212 $errmsg .= implode('<br>', $contact->errors);
213 } else {
214 $result = $contact->create($user);
215 if ($result < 0) {
216 $error++;
217 $errmsg .= $contact->error." ".implode(',', $contact->errors);
218 }
219 }
220 }
221 } else {
222 $error++;
223 $errmsg .= $db->lasterror();
224 }
225 }
226
227 if (!$error) {
228 $dateend = dol_time_plus_duree(GETPOSTINT("datetimebooking"), GETPOSTINT("durationbooking"), 'i');
229
230 $actioncomm->label = $langs->trans("BookcalBookingTitle");
231 $actioncomm->type = 'AC_RDV';
232 $actioncomm->type_id = 5;
233 $actioncomm->datep = GETPOSTINT("datetimebooking");
234 $actioncomm->datef = $dateend;
235 $actioncomm->note_private = GETPOST("description");
236 $actioncomm->percentage = -1;
237 $actioncomm->fk_bookcal_calendar = $id;
238 $actioncomm->userownerid = $calendar->visibility;
239 $actioncomm->contact_id = $contact->id;
240 $actioncomm->socpeopleassigned = [
241 $contact->id => [
242 'id' => $contact->id,
243 'mandatory' => 0,
244 'answer_status' => 0,
245 'transparency' => 0,
246 ]
247 ];
248 $actioncomm->ip = getUserRemoteIP();
249 if (checkNbPostsForASpeceificIp($actioncomm, $nb_post_max) <= 0) {
250 $error++;
251 $errmsg .= implode('<br>', $actioncomm->errors);
252 } else {
253 $result = $actioncomm->create($user);
254 if ($result < 0) {
255 $error++;
256 $errmsg .= $actioncomm->error." ".implode(',', $actioncomm->errors);
257 }
258 }
259 }
260
261 if (!$error) {
262 $db->commit();
263 $action = 'afteradd';
264 } else {
265 $db->rollback();
266 $action = 'create';
267 }
268 } else {
269 $action = 'create';
270 }
271}
272
273
274/*
275 * View
276 */
277
278$form = new Form($db);
279
280
281// Define $urlwithroot
282$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
283$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
284//$urlwithroot = DOL_MAIN_URL_ROOT; // This is to use same domain name than current. For Paypal payment, we can use internal URL like localhost.
285// TODO Replace DOL_URL_ROOT with $urlwithroot ?
286
287
288llxHeaderVierge('BookingCalendar');
289
290print '<center><br><h2>'.(!empty($object->label) ? $object->label : $object->ref).'</h2></center>';
291
292if ($object->status == $object::STATUS_DRAFT) {
293 $langs->trans("errors");
294 $errmsg = $langs->trans("ErrorCalendarIsNotYetOpenOrHasBeenClosed");
295}
296
297dol_htmloutput_errors($errmsg);
298
299if ($action == 'create') {
300 $backtopage = $_SERVER["PHP_SELF"].'?id='.$id.'&datechosen='.$datechosen;
301} else {
302 $backtopage = DOL_URL_ROOT.'/public/bookcal/index.php?id='.$id;
303}
304
305//print '<div class="">';
306
307print '<div class="bookcalpublicarea centpercent center" style="min-width:30%;width:fit-content;height:70%;top:60%;left: 50%;">';
308print '<div class="bookcalform" style="min-height:50%">';
309if ($action == 'afteradd') {
310 print '<h2>';
311 print $langs->trans("BookingSuccessfullyBooked");
312 print '</h2>';
313 print $langs->trans("BookingReservationHourAfter", dol_print_date(GETPOSTINT("datetimebooking"), "dayhourtext"));
314} else {
315 $param = '';
316
317 print '<table class="centpercent">';
318 print '<tr>';
319 print '<td>';
320 if ($action != 'create') {
321 print '<form name="formsearch" class="bookcalsearch" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
322 print '<input type="hidden" name="id" value="'.$id.'">';
323
324 $nav = '<a href="?id='.$id."&year=".$prev_year."&month=".$prev_month.$param.'"><i class="fa fa-chevron-left"></i></a> &nbsp;'."\n";
325 $nav .= ' <span id="month_name">'.dol_print_date(dol_mktime(0, 0, 0, $month, 1, $year), "%b %Y");
326 $nav .= " </span>\n";
327 $nav .= ' &nbsp; <a href="?id='.$id."&year=".$next_year."&month=".$next_month.$param.'"><i class="fa fa-chevron-right"></i></a>'."\n";
328 if (empty($conf->dol_optimize_smallscreen)) {
329 $nav .= ' &nbsp; <a href="?id='.$id."&year=".$nowyear."&amp;month=".$nowmonth."&amp;day=".$nowday.$param.'" class="datenowlink">'.$langs->trans("Today").'</a> ';
330 }
331 $nav .= $form->selectDate($dateselect, 'dateselect', 0, 0, 1, '', 1, 0);
332 $nav .= '<button type="submit" class="liste_titre button_search valignmiddle" name="button_search_x" value="x"><span class="fa fa-search"></span></button>';
333
334 print $nav;
335 print '</form>';
336 }
337 print '</td>';
338 print '<td>';
339 print '<div class="bookingtab hidden" style="height:50%">';
340 print '<div id="bookingtabspandate"></div>';
341 print '</div>';
342 print '</td>';
343 print '</tr>';
344
345 print '<tr>';
346 if ($action == "create") {
347 print '<td>';
348 if (empty($datetimebooking)) {
349 $timebookingarray = explode(" - ", $timebooking);
350 $timestartarray = explode(":", $timebookingarray[0]);
351 $timeendarray = explode(":", $timebookingarray[1]);
352 $datetimebooking = dol_time_plus_duree($datetimechosen, intval($timestartarray[0]), "h");
353 $datetimebooking = dol_time_plus_duree($datetimebooking, intval($timestartarray[1]), "i");
354 }
355 print '<span>'.img_picto("", "calendar")." ".dol_print_date($datetimebooking, 'dayhourtext').'</span>';
356 print '<div class="center"><a href="'.$_SERVER["PHP_SELF"].'?id=1&year=2024&month=2" class="small">('.$langs->trans("SelectANewDate").')</a></div>';
357 print '</td>';
358
359 print '<td>';
360 print '<form method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
361 print '<table class="border" summary="form to subscribe" id="tablesubscribe">'."\n";
362 print '<input type="hidden" name="token" value="'.newToken().'">';
363 print '<input type="hidden" name="action" value="add">';
364 print '<input type="hidden" name="datetimebooking" value="'.$datetimebooking.'">';
365 print '<input type="hidden" name="datechosen" value="'.$datechosen.'">';
366 print '<input type="hidden" name="id" value="'.$id.'">';
367 print '<input type="hidden" name="durationbooking" value="'.$durationbooking.'">';
368
369 // Lastname
370 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";
371 // Firstname
372 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";
373 // EMail
374 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";
375
376 // Comments
377 print '<tr>';
378 print '<td class="tdtop">';
379 print $langs->trans("Message");
380 print '<textarea name="description" id="description" wrap="soft" class="quatrevingtpercent" rows="'.ROWS_4.'">'.dol_escape_htmltag(GETPOST('description', 'restricthtml'), 0, 1).'</textarea></td>';
381 print '</tr>'."\n";
382 print '</table>'."\n";
383 print '<div class="center">';
384 print '<input type="submit" value="'.$langs->trans("Submit").'" id="submitsave" class="button">';
385 print '</div>';
386 print '</form>';
387 print '</td>';
388 } else {
389 print '<td>';
390 print '<table class="centpercent noborder nocellnopadd cal_pannel cal_month">';
391 print ' <tr class="">';
392 // Column title of weeks numbers
393 print ' <td class="center hideonsmartphone">#</td>';
394 $i = 0;
395 while ($i < 7) {
396 $numdayinweek = (($i + getDolGlobalInt('MAIN_START_WEEK', 1)) % 7);
397 if (!empty($conf->dol_optimize_smallscreen)) {
398 print ' <td class="center bold uppercase tdfordaytitle'.($i == 0 ? ' borderleft' : '').'">';
399 $labelshort = array(0 => 'SundayMin', 1 => 'MondayMin', 2 => 'TuesdayMin', 3 => 'WednesdayMin', 4 => 'ThursdayMin', 5 => 'FridayMin', 6 => 'SaturdayMin');
400 print $langs->trans($labelshort[$numdayinweek]);
401 print ' </td>'."\n";
402 } else {
403 print ' <td class="center minwidth75 bold uppercase small tdoverflowmax50 tdfordaytitle'.($i == 0 ? ' borderleft' : '').'">';
404 //$labelshort = array(0=>'SundayMin', 1=>'MondayMin', 2=>'TuesdayMin', 3=>'WednesdayMin', 4=>'ThursdayMin', 5=>'FridayMin', 6=>'SaturdayMin');
405 $labelshort = array(0 => 'Sunday', 1 => 'Monday', 2 => 'Tuesday', 3 => 'Wednesday', 4 => 'Thursday', 5 => 'Friday', 6 => 'Saturday');
406 print $langs->trans($labelshort[$numdayinweek]);
407 print ' </td>'."\n";
408 }
409 $i++;
410 }
411 print ' </tr>'."\n";
412
413 $todayarray = dol_getdate($now, true);
414 $todaytms = dol_mktime(0, 0, 0, $todayarray['mon'], $todayarray['mday'], $todayarray['year']);
415
416 // Load into an array all days with availabilities of the calendar for the current month $todayarray['mon'] and $todayarray['year']
417 $arrayofavailabledays = array();
418
419 $arrayofavailabilities = $availability->fetchAll('', '', 0, 0, '(status:=:1) AND (fk_bookcal_calendar:=:'.((int) $id).')');
420 if ($arrayofavailabilities < 0) {
421 setEventMessages($availability->error, $availability->errors, 'errors');
422 } else {
423 foreach ($arrayofavailabilities as $key => $value) {
424 $startarray = dol_getdate((int) $value->date_start);
425 $endarray = dol_getdate((int) $value->date_end);
426 for ($i = $startarray['mday']; $i <= $endarray['mday']; $i++) {
427 if ($todayarray['mon'] >= $startarray['mon'] && $todayarray['mon'] <= $endarray['mon']) {
428 $arrayofavailabledays[dol_mktime(0, 0, 0, $todayarray['mon'], $i, $todayarray['year'])] = dol_mktime(0, 0, 0, $todayarray['mon'], $i, $todayarray['year']);
429 }
430 }
431 }
432 }
433
434 for ($iter_week = 0; $iter_week < 6; $iter_week++) {
435 echo " <tr>\n";
436 // Get date of the current day, format 'yyyy-mm-dd'
437 if ($tmpday <= 0) { // If number of the current day is in previous month
438 $currdate0 = sprintf("%04d", $prev_year).sprintf("%02d", $prev_month).sprintf("%02d", $max_day_in_prev_month + $tmpday);
439 } elseif ($tmpday <= $max_day_in_month) { // If number of the current day is in current month
440 $currdate0 = sprintf("%04d", $year).sprintf("%02d", $month).sprintf("%02d", $tmpday);
441 } else {// If number of the current day is in next month
442 $currdate0 = sprintf("%04d", $next_year).sprintf("%02d", $next_month).sprintf("%02d", $tmpday - $max_day_in_month);
443 }
444 // Get week number for the targeted date '$currdate0'
445 $numweek0 = idate("W", strtotime(date($currdate0)));
446 // Show the week number, and define column width
447 echo ' <td class="center weeknumber opacitymedium hideonsmartphone" style="min-width: 40px">'.$numweek0.'</td>';
448
449 for ($iter_day = 0; $iter_day < 7; $iter_day++) {
450 if ($tmpday <= 0) {
451 /* Show days before the beginning of the current month (previous month) */
452 $style = 'cal_other_month cal_past';
453 if ($iter_day == 6) {
454 $style .= ' cal_other_month_right';
455 }
456 echo ' <td class="'.$style.' nowrap tdtop" width="14%">';
457 show_bookcal_day_events($max_day_in_prev_month + $tmpday, $prev_month, $prev_year);
458 echo " </td>\n";
459 } elseif ($tmpday <= $max_day_in_month) {
460 /* Show days of the current month */
461 $curtime = dol_mktime(0, 0, 0, $month, $tmpday, $year);
462 $style = 'cal_current_month';
463 if ($iter_day == 6) {
464 $style .= ' cal_current_month_right';
465 }
466 $today = 0;
467 if ($todayarray['mday'] == $tmpday && $todayarray['mon'] == $month && $todayarray['year'] == $year) {
468 $today = 1;
469 }
470 //var_dump($curtime); var_dump($todaytms); var_dump($arrayofavailabledays);
471 if ($curtime > $todaytms && in_array($curtime, $arrayofavailabledays)) {
472 $style .= ' cal_available cursorpointer';
473 }
474 if ($curtime < $todaytms) {
475 $style .= ' cal_past';
476 }
477 $dateint = sprintf("%04d", $year).'_'.sprintf("%02d", $month).'_'.sprintf("%02d", $tmpday);
478 if (!empty(explode('dayevent_', $datechosen)[1]) && explode('dayevent_', $datechosen)[1] == $dateint) {
479 $style .= ' cal_chosen';
480 $isdatechosen = true;
481 }
482 echo ' <td class="'.$style.' nowrap tdtop" width="14%">';
483 show_bookcal_day_events($tmpday, $month, $year, $today);
484 echo "</td>\n";
485 } else {
486 /* Show days after the current month (next month) */
487 $style = 'cal_other_month';
488 if ($iter_day == 6) {
489 $style .= ' cal_other_month_right';
490 }
491 echo ' <td class="'.$style.' nowrap tdtop" width="14%">';
492 show_bookcal_day_events($tmpday - $max_day_in_month, $next_month, $next_year);
493 echo "</td>\n";
494 }
495 $tmpday++;
496 }
497 echo " </tr>\n";
498 }
499 print '</table>';
500 print '</td>';
501
502 print '<td>'; // Column visible after selection of a day
503 print '<div class="center bookingtab" style="height:50%">';
504 print '<div style="height:100%">';
505 print '<form id="formbooking" name="formbooking" method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
506 print '<input type="hidden" name="id" value="'.$id.'">';
507 print '<input type="hidden" name="token" value="'.newToken().'">';
508 print '<input type="hidden" name="action" value="create">';
509 print '<input type="hidden" id="datechosen" name="datechosen" value="">';
510 print '<input type="hidden" id="datetimechosen" name="datetimechosen" value="">';
511 print '<input type="hidden" id="durationbooking" name="durationbooking" value="">';
512
513 print '<div id="bookinghoursection">';
514 print '<br><br><br><br><br><br><div class="opacitymedium center">'.$langs->trans("SelectADay").'</div>';
515 print '</div>';
516 print '</form>';
517 print '</div>';
518 print '</div>';
519
520 print '</td>';
521 }
522 print '</tr>';
523 print '</table>';
524 print '</div>';
525 print '</div>';
526
527 print '<script>';
528 print '
529 function generateBookingButtons(timearray, datestring){
530 console.log("We generate all booking buttons of "+datestring);
531 str = "";
532
533 for (index in timearray){
534 let hour = new Date("2000-01-01T" + index + ":00");
535 duration = timearray[index];
536 isalreadybooked = false;
537 if (duration < 0) {
538 duration *= -1;
539 isalreadybooked = true;
540 }
541 hour.setMinutes(hour.getMinutes() + duration);
542
543 let hours = hour.getHours().toString().padStart(2, "0"); // Formatter pour obtenir deux chiffres
544 let mins = hour.getMinutes().toString().padStart(2, "0"); // Formatter pour obtenir deux chiffres
545
546 timerange = index + " - " + `${hours}:${mins}`;
547 str += \'<input class="button btnsubmitbooking \'+(isalreadybooked == true ? "btnbookcalbooked" : "")+\'" type="submit" name="timebooking" value="\'+timerange+\'" data-duration="\'+duration+\'"><br>\';
548 }
549
550 $("#bookinghoursection").html(str);
551 $(".btnsubmitbooking").on("click", function(){
552 duration = $(this).data("duration");
553 $("#durationbooking").val(duration);
554 })
555 }';
556 print '$(document).ready(function() {
557 $(".cal_available").on("click", function(){
558 console.log("We click on cal_available");
559 $(".cal_chosen").removeClass("cal_chosen");
560 $(this).addClass("cal_chosen");
561 datestring = $(this).children("div").data("date");
562 $.ajax({
563 type: "POST",
564 url: "'.DOL_URL_ROOT.'/public/bookcal/bookcalAjax.php",
565 data: {
566 action: "verifyavailability",
567 id: '.((int) $id).',
568 datetocheck: $(this).children("div").data("datetime"),
569 token: "'.currentToken().'",
570 }
571 }).done(function (data) {
572 console.log("We show all booking");
573 if (data["code"] == "SUCCESS") {
574 /* TODO Replace this with a creating of allavailable hours button */
575 console.log(data)
576 timearray = data["availability"];
577 console.log(timearray);
578 generateBookingButtons(timearray, datestring);
579 $(".btnbookcalbooked").prop("disabled", true);
580 } else {
581 if(data["code"] == "NO_DATA_FOUND"){
582 console.log("No booking to hide");
583 } else {
584 console.log(data["message"]);
585 }
586 }
587 });
588 $(".bookingtab").removeClass("hidden");
589 $("#bookingtabspandate").text($(this).children("div").data("date"));
590 $("#datechosen").val($(this).children("div").attr("id"));
591 $("#datetimechosen").val($(this).children("div").data("datetime"));
592 });
593
594 $("btnformbooking")
595
596 '.($datechosen ? '$(".cal_chosen").trigger( "click" )' : '').'
597 });';
598 print '</script>';
599}
600
601llxFooter('', 'public');
602
603
613function show_bookcal_day_events($day, $month, $year, $today = 0)
614{
615 global $conf;
616 if ($conf->use_javascript_ajax) { // Enable the "Show more button..."
617 $conf->global->MAIN_JS_SWITCH_AGENDA = 1;
618 }
619
620 $dateint = sprintf("%04d", $year).'_'.sprintf("%02d", $month).'_'.sprintf("%02d", $day);
621 $eventdatetime = dol_mktime(-1, -1, -1, $month, $day, $year);
622 //print 'show_bookcal_day_events day='.$day.' month='.$month.' year='.$year.' dateint='.$dateint;
623
624 print "\n";
625
626 $curtime = dol_mktime(0, 0, 0, $month, $day, $year);
627 // Line with title of day
628 print '<div id="dayevent_'.$dateint.'" class="dayevent tagtable centpercent nobordernopadding" data-datetime="'.$eventdatetime.'" data-date="'.dol_print_date($eventdatetime, "daytext").'">'."\n";
629 print dol_print_date($curtime, '%d');
630 print '<br>';
631 if ($today) {
632 print img_picto('today', 'fontawesome_circle_fas_black_7px');
633 } else {
634 print '<br>';
635 }
636 print '</div>'; // table
637 print "\n";
638}
$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:524
dol_get_next_month($month, $year)
Return next month.
Definition date.lib.php:543
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...
currentToken()
Return the value of token currently saved into session with name 'token'.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
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)
dol_htmloutput_errors($mesgstring='', $mesgarray=array(), $keepembedded=0)
Print formatted error messages to output (Used to show messages on html output).
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...
Definition html.lib.php:172
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:613
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.