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