dolibarr 21.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 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}
62$langs->loadLangs(array("main", "other", "dict", "agenda", "errors", "companies"));
63
64$action = GETPOST('action', 'aZ09');
65$id = GETPOSTINT('id');
66$id_availability = GETPOSTINT('id_availability');
67
68$year = GETPOSTINT("year") ? GETPOSTINT("year") : idate("Y");
69$month = GETPOSTINT("month") ? GETPOSTINT("month") : idate("m");
70$week = GETPOSTINT("week") ? GETPOSTINT("week") : idate("W");
71$day = GETPOSTINT("day") ? GETPOSTINT("day") : idate("d");
72$dateselect = dol_mktime(0, 0, 0, GETPOSTINT('dateselectmonth'), GETPOSTINT('dateselectday'), GETPOSTINT('dateselectyear'), 'tzuserrel');
73if ($dateselect > 0) {
74 $day = GETPOSTINT('dateselectday');
75 $month = GETPOSTINT('dateselectmonth');
76 $year = GETPOSTINT('dateselectyear');
77}
78$backtopage = GETPOST("backtopage", "alpha");
79
80$object = new Calendar($db);
81$result = $object->fetch($id);
82
83$availability = new Availabilities($db);
84if ($id_availability > 0) {
85 $result = $availability->fetch($id_availability);
86}
87
88$now = dol_now();
89$nowarray = dol_getdate($now);
90$nowyear = $nowarray['year'];
91$nowmonth = $nowarray['mon'];
92$nowday = $nowarray['mday'];
93
94$prev = dol_get_prev_month($month, $year);
95$prev_year = $prev['year'];
96$prev_month = $prev['month'];
97$next = dol_get_next_month($month, $year);
98$next_year = $next['year'];
99$next_month = $next['month'];
100
101$max_day_in_prev_month = idate("t", dol_mktime(0, 0, 0, $prev_month, 1, $prev_year, 'gmt')); // Nb of days in previous month
102$max_day_in_month = idate("t", dol_mktime(0, 0, 0, $month, 1, $year)); // Nb of days in next month
103// 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)
104$tmpday = - idate("w", dol_mktime(12, 0, 0, $month, 1, $year, 'gmt')) + 2; // idate('w') is 0 for sunday
105$tmpday += (getDolGlobalInt('MAIN_START_WEEK', 1) - 1);
106if ($tmpday >= 1) {
107 $tmpday -= 7; // If tmpday is 0 we start with sunday, if -6, we start with monday of previous week.
108}
109// Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
110$firstdaytoshow = dol_mktime(0, 0, 0, $prev_month, $max_day_in_prev_month + $tmpday, $prev_year, 'tzuserrel');
111$next_day = 7 - ($max_day_in_month + 1 - $tmpday) % 7;
112if ($next_day < 6) {
113 $next_day += 7;
114}
115$lastdaytoshow = dol_mktime(0, 0, 0, $next_month, $next_day, $next_year, 'tzuserrel');
116
117$datechosen = GETPOST('datechosen', 'alpha');
118$datetimechosen = GETPOSTINT('datetimechosen');
119$isdatechosen = false;
120$timebooking = GETPOST("timebooking");
121$datetimebooking = GETPOSTINT("datetimebooking");
122$durationbooking = GETPOSTINT("durationbooking");
123$errmsg = '';
124
136function llxHeaderVierge($title, $head = "", $disablejs = 0, $disablehead = 0, $arrayofjs = [], $arrayofcss = [])
137{
138 global $conf, $langs, $mysoc;
139
140 top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss); // Show html headers
141
142 print '<body id="mainbody" class="publicnewmemberform">';
143
144 $urllogo = '';
145
146 // Define urllogo
147 if (getDolGlobalInt('BOOKCAL_SHOW_COMPANY_LOGO') || getDolGlobalString('BOOPKCAL_PUBLIC_INTERFACE_TOPIC')) {
148 // Print logo
149 if (getDolGlobalInt('BOOKCAL_SHOW_COMPANY_LOGO')) {
150 $urllogo = DOL_URL_ROOT.'/theme/common/login_logo.png';
151
152 if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small)) {
153 $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/thumbs/'.$mysoc->logo_small);
154 } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$mysoc->logo)) {
155 $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/'.$mysoc->logo);
156 } elseif (is_readable(DOL_DOCUMENT_ROOT.'/theme/dolibarr_logo.svg')) {
157 $urllogo = DOL_URL_ROOT.'/theme/dolibarr_logo.svg';
158 }
159 }
160 }
161
162 print '<div class="center">';
163 // Output html code for logo
164 print '<div class="backgreypublicpayment">';
165 print '<div class="logopublicpayment">';
166 if ($urllogo) {
167 print '<a href="'.(getDolGlobalString('BOOKCAL_PUBLIC_INTERFACE_TOPIC') ? getDolGlobalString('BOOKCAL_PUBLIC_INTERFACE_TOPIC') : dol_buildpath('/public/ticket/index.php?entity='.$conf->entity, 1)).'">';
168 print '<img id="dolpaymentlogo" src="'.$urllogo.'">';
169 print '</a>';
170 }
171 if (getDolGlobalString('BOOKCAL_PUBLIC_INTERFACE_TOPIC')) {
172 print '<div class="clearboth"></div><strong>'.(getDolGlobalString('BOOKCAL_PUBLIC_INTERFACE_TOPIC') ? getDolGlobalString('BOOKCAL_PUBLIC_INTERFACE_TOPIC') : $langs->trans("BookCalSystem")).'</strong>';
173 }
174 if (empty($urllogo) && ! getDolGlobalString('BOOKCAL_PUBLIC_INTERFACE_TOPIC')) {
175 print $mysoc->name;
176 }
177 print '</div>';
178 if (!getDolGlobalInt('MAIN_HIDE_POWERED_BY')) {
179 print '<div class="poweredbypublicpayment opacitymedium right hideonsmartphone"><a class="poweredbyhref" href="https://www.dolibarr.org?utm_medium=website&utm_source=poweredby" target="dolibarr" rel="noopener">'.$langs->trans("PoweredBy").'<br><img src="'.DOL_URL_ROOT.'/theme/dolibarr_logo.svg" width="80px"></a></div>';
180 }
181 print '</div>';
182
183 print '</div>';
184
185 print '<div class="divmainbodylarge">';
186}
187
188
189/*
190 * Actions
191 */
192
193if ($action == 'add' ) { // Test on permission not required here (anonymous action protected by mitigation of /public/... urls)
194 $error = 0;
195 $idcontact = 0;
196 $calendar = $object;
197 $contact = new Contact($db);
198 $actioncomm = new ActionComm($db);
199 $nb_post_max = getDolGlobalInt("MAIN_SECURITY_MAX_POST_ON_PUBLIC_PAGES_BY_IP_ADDRESS", 200);
200
201 if (!is_object($user)) {
202 $user = new User($db);
203 }
204
205 $db->begin();
206
207 if (!GETPOST("lastname")) {
208 $error++;
209 $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Lastname"))."<br>\n";
210 }
211 if (!GETPOST("firstname")) {
212 $error++;
213 $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Firstname"))."<br>\n";
214 }
215 if (!GETPOST("email")) {
216 $error++;
217 $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Email"))."<br>\n";
218 }
219
220 if (!$error) {
221 $sql = "SELECT s.rowid";
222 $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as s";
223 $sql .= " WHERE s.lastname = '".$db->escape(GETPOST("lastname"))."'";
224 $sql .= " AND s.firstname = '".$db->escape(GETPOST("firstname"))."'";
225 $sql .= " AND s.email = '".$db->escape(GETPOST("email"))."'";
226 $resql = $db->query($sql);
227
228 if ($resql) {
229 $num = $db->num_rows($resql);
230 if ($num > 0) {
231 $obj = $db->fetch_object($resql);
232 $idcontact = $obj->rowid;
233 $contact->fetch($idcontact);
234 } else {
235 $contact->lastname = GETPOST("lastname");
236 $contact->firstname = GETPOST("firstname");
237 $contact->email = GETPOST("email");
238 $contact->ip = getUserRemoteIP();
239
240 if (checkNbPostsForASpeceificIp($contact, $nb_post_max) <= 0) {
241 $error++;
242 $errmsg .= implode('<br>', $contact->errors);
243 } else {
244 $result = $contact->create($user);
245 if ($result < 0) {
246 $error++;
247 $errmsg .= $contact->error." ".implode(',', $contact->errors);
248 }
249 }
250 }
251 } else {
252 $error++;
253 $errmsg .= $db->lasterror();
254 }
255 }
256
257 if (!$error) {
258 $dateend = dol_time_plus_duree(GETPOSTINT("datetimebooking"), GETPOSTINT("durationbooking"), 'i');
259
260 $actioncomm->label = $langs->trans("BookcalBookingTitle");
261 $actioncomm->type = 'AC_RDV';
262 $actioncomm->type_id = 5;
263 $actioncomm->datep = GETPOSTINT("datetimebooking");
264 $actioncomm->datef = $dateend;
265 $actioncomm->note_private = GETPOST("description");
266 $actioncomm->percentage = -1;
267 $actioncomm->fk_bookcal_calendar = $id;
268 $actioncomm->userownerid = $calendar->visibility;
269 $actioncomm->contact_id = $contact->id;
270 $actioncomm->socpeopleassigned = [
271 $contact->id => [
272 'id' => $contact->id,
273 'mandatory' => 0,
274 'answer_status' => 0,
275 'transparency' =>0,
276 ]
277 ];
278 $actioncomm->ip = getUserRemoteIP();
279 if (checkNbPostsForASpeceificIp($actioncomm, $nb_post_max) <= 0) {
280 $error++;
281 $errmsg .= implode('<br>', $actioncomm->errors);
282 } else {
283 $result = $actioncomm->create($user);
284 if ($result < 0) {
285 $error++;
286 $errmsg .= $actioncomm->error." ".implode(',', $actioncomm->errors);
287 }
288 }
289 }
290
291 if (!$error) {
292 $db->commit();
293 $action = 'afteradd';
294 } else {
295 $db->rollback();
296 $action = 'create';
297 }
298}
299
300
301/*
302 * View
303 */
304
305$form = new Form($db);
306
307llxHeaderVierge('BookingCalendar');
308
309print '<center><br><h2>'.(!empty($object->label) ? $object->label : $object->ref).'</h2></center>';
310
311dol_htmloutput_errors($errmsg);
312
313if ($action == 'create') {
314 $backtopage = $_SERVER["PHP_SELF"].'?id='.$id.'&datechosen='.$datechosen;
315} else {
316 $backtopage = DOL_URL_ROOT.'/public/bookcal/index.php?id='.$id;
317}
318
319//print '<div class="">';
320
321print '<div class="bookcalpublicarea centpercent center" style="min-width:30%;width:fit-content;height:70%;top:60%;left: 50%;">';
322print '<div class="bookcalform" style="min-height:50%">';
323if ($action == 'afteradd') {
324 print '<h2>';
325 print $langs->trans("BookingSuccessfullyBooked");
326 print '</h2>';
327 print $langs->trans("BookingReservationHourAfter", dol_print_date(GETPOSTINT("datetimebooking"), "dayhourtext"));
328} else {
329 $param = '';
330
331 print '<table class="centpercent">';
332 print '<tr>';
333 print '<td>';
334 if ($action != 'create') {
335 print '<form name="formsearch" action="'.$_SERVER["PHP_SELF"].'">';
336 print '<input type="hidden" name="id" value="'.$id.'">';
337
338 $nav = '<a href="?id='.$id."&year=".$prev_year."&month=".$prev_month.$param.'"><i class="fa fa-chevron-left"></i></a> &nbsp;'."\n";
339 $nav .= ' <span id="month_name">'.dol_print_date(dol_mktime(0, 0, 0, $month, 1, $year), "%b %Y");
340 $nav .= " </span>\n";
341 $nav .= ' &nbsp; <a href="?id='.$id."&year=".$next_year."&month=".$next_month.$param.'"><i class="fa fa-chevron-right"></i></a>'."\n";
342 if (empty($conf->dol_optimize_smallscreen)) {
343 $nav .= ' &nbsp; <a href="?id='.$id."&year=".$nowyear."&amp;month=".$nowmonth."&amp;day=".$nowday.$param.'" class="datenowlink">'.$langs->trans("Today").'</a> ';
344 }
345 $nav .= $form->selectDate($dateselect, 'dateselect', 0, 0, 1, '', 1, 0);
346 $nav .= '<button type="submit" class="liste_titre button_search valignmiddle" name="button_search_x" value="x"><span class="fa fa-search"></span></button>';
347
348 print $nav;
349 print '</form>';
350 }
351 print '</td>';
352 print '<td>';
353 print '<div class="bookingtab hidden" style="height:50%">';
354 print '<div id="bookingtabspandate"></div>';
355 print '</div>';
356 print '</td>';
357 print '</tr>';
358
359 print '<tr>';
360 if ($action == "create") {
361 print '<td>';
362 if (empty($datetimebooking)) {
363 $timebookingarray = explode(" - ", $timebooking);
364 $timestartarray = explode(":", $timebookingarray[0]);
365 $timeendarray = explode(":", $timebookingarray[1]);
366 $datetimebooking = dol_time_plus_duree($datetimechosen, intval($timestartarray[0]), "h");
367 $datetimebooking = dol_time_plus_duree($datetimebooking, intval($timestartarray[1]), "i");
368 }
369 print '<span>'.img_picto("", "calendar")." ".dol_print_date($datetimebooking, 'dayhourtext').'</span>';
370 print '<div class="center"><a href="'.$_SERVER["PHP_SELF"].'?id=1&year=2024&month=2" class="small">('.$langs->trans("SelectANewDate").')</a></div>';
371 print '</td>';
372
373 print '<td>';
374 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
375 print '<table class="border" summary="form to subscribe" id="tablesubscribe">'."\n";
376 print '<input type="hidden" name="token" value="'.newToken().'">';
377 print '<input type="hidden" name="action" value="add">';
378 print '<input type="hidden" name="datetimebooking" value="'.$datetimebooking.'">';
379 print '<input type="hidden" name="datechosen" value="'.$datechosen.'">';
380 print '<input type="hidden" name="id" value="'.$id.'">';
381 print '<input type="hidden" name="durationbooking" value="'.$durationbooking.'">';
382
383 // Lastname
384 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";
385 // Firstname
386 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";
387 // EMail
388 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";
389
390 // Comments
391 print '<tr>';
392 print '<td class="tdtop">';
393 print $langs->trans("Message");
394 print '<textarea name="description" id="description" wrap="soft" class="quatrevingtpercent" rows="'.ROWS_4.'">'.dol_escape_htmltag(GETPOST('description', 'restricthtml'), 0, 1).'</textarea></td>';
395 print '</tr>'."\n";
396 print '</table>'."\n";
397 print '<div class="center">';
398 print '<input type="submit" value="'.$langs->trans("Submit").'" id="submitsave" class="button">';
399 print '</div>';
400 print '</form>';
401 print '</td>';
402 } else {
403 print '<td>';
404 print '<table class="centpercent noborder nocellnopadd cal_pannel cal_month">';
405 print ' <tr class="">';
406 // Column title of weeks numbers
407 print ' <td class="center hideonsmartphone">#</td>';
408 $i = 0;
409 while ($i < 7) {
410 $numdayinweek = (($i + (isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1)) % 7);
411 if (!empty($conf->dol_optimize_smallscreen)) {
412 print ' <td class="center bold uppercase tdfordaytitle'.($i == 0 ? ' borderleft' : '').'">';
413 $labelshort = array(0 => 'SundayMin', 1 => 'MondayMin', 2 => 'TuesdayMin', 3 => 'WednesdayMin', 4 => 'ThursdayMin', 5 => 'FridayMin', 6 => 'SaturdayMin');
414 print $langs->trans($labelshort[$numdayinweek]);
415 print ' </td>'."\n";
416 } else {
417 print ' <td class="center minwidth75 bold uppercase small tdoverflowmax50 tdfordaytitle'.($i == 0 ? ' borderleft' : '').'">';
418 //$labelshort = array(0=>'SundayMin', 1=>'MondayMin', 2=>'TuesdayMin', 3=>'WednesdayMin', 4=>'ThursdayMin', 5=>'FridayMin', 6=>'SaturdayMin');
419 $labelshort = array(0 => 'Sunday', 1 => 'Monday', 2 => 'Tuesday', 3 => 'Wednesday', 4 => 'Thursday', 5 => 'Friday', 6 => 'Saturday');
420 print $langs->trans($labelshort[$numdayinweek]);
421 print ' </td>'."\n";
422 }
423 $i++;
424 }
425 print ' </tr>'."\n";
426
427 $todayarray = dol_getdate($now, true);
428 $todaytms = dol_mktime(0, 0, 0, $todayarray['mon'], $todayarray['mday'], $todayarray['year']);
429
430 // Load into an array all days with availabilities of the calendar for the current month $todayarray['mon'] and $todayarray['year']
431 $arrayofavailabledays = array();
432
433 $arrayofavailabilities = $availability->fetchAll('', '', 0, 0, '(status:=:1) AND (fk_bookcal_calendar:=:'.((int) $id).')');
434 if ($arrayofavailabilities < 0) {
435 setEventMessages($availability->error, $availability->errors, 'errors');
436 } else {
437 foreach ($arrayofavailabilities as $key => $value) {
438 $startarray = dol_getdate($value->start);
439 $endarray = dol_getdate($value->end);
440 for ($i = $startarray['mday']; $i <= $endarray['mday']; $i++) {
441 if ($todayarray['mon'] >= $startarray['mon'] && $todayarray['mon'] <= $endarray['mon']) {
442 $arrayofavailabledays[dol_mktime(0, 0, 0, $todayarray['mon'], $i, $todayarray['year'])] = dol_mktime(0, 0, 0, $todayarray['mon'], $i, $todayarray['year']);
443 }
444 }
445 }
446 }
447
448 for ($iter_week = 0; $iter_week < 6; $iter_week++) {
449 echo " <tr>\n";
450 // Get date of the current day, format 'yyyy-mm-dd'
451 if ($tmpday <= 0) { // If number of the current day is in previous month
452 $currdate0 = sprintf("%04d", $prev_year).sprintf("%02d", $prev_month).sprintf("%02d", $max_day_in_prev_month + $tmpday);
453 } elseif ($tmpday <= $max_day_in_month) { // If number of the current day is in current month
454 $currdate0 = sprintf("%04d", $year).sprintf("%02d", $month).sprintf("%02d", $tmpday);
455 } else {// If number of the current day is in next month
456 $currdate0 = sprintf("%04d", $next_year).sprintf("%02d", $next_month).sprintf("%02d", $tmpday - $max_day_in_month);
457 }
458 // Get week number for the targeted date '$currdate0'
459 $numweek0 = idate("W", strtotime(date($currdate0)));
460 // Show the week number, and define column width
461 echo ' <td class="center weeknumber opacitymedium hideonsmartphone" style="min-width: 40px">'.$numweek0.'</td>';
462
463 for ($iter_day = 0; $iter_day < 7; $iter_day++) {
464 if ($tmpday <= 0) {
465 /* Show days before the beginning of the current month (previous month) */
466 $style = 'cal_other_month cal_past';
467 if ($iter_day == 6) {
468 $style .= ' cal_other_month_right';
469 }
470 echo ' <td class="'.$style.' nowrap tdtop" width="14%">';
471 show_bookcal_day_events($max_day_in_prev_month + $tmpday, $prev_month, $prev_year);
472 echo " </td>\n";
473 } elseif ($tmpday <= $max_day_in_month) {
474 /* Show days of the current month */
475 $curtime = dol_mktime(0, 0, 0, $month, $tmpday, $year);
476 $style = 'cal_current_month';
477 if ($iter_day == 6) {
478 $style .= ' cal_current_month_right';
479 }
480 $today = 0;
481 if ($todayarray['mday'] == $tmpday && $todayarray['mon'] == $month && $todayarray['year'] == $year) {
482 $today = 1;
483 }
484 //var_dump($curtime); var_dump($todaytms); var_dump($arrayofavailabledays);
485 if ($curtime > $todaytms && in_array($curtime, $arrayofavailabledays)) {
486 $style .= ' cal_available cursorpointer';
487 }
488 if ($curtime < $todaytms) {
489 $style .= ' cal_past';
490 }
491 $dateint = sprintf("%04d", $year).'_'.sprintf("%02d", $month).'_'.sprintf("%02d", $tmpday);
492 if (!empty(explode('dayevent_', $datechosen)[1]) && explode('dayevent_', $datechosen)[1] == $dateint) {
493 $style .= ' cal_chosen';
494 $isdatechosen = true;
495 }
496 echo ' <td class="'.$style.' nowrap tdtop" width="14%">';
497 show_bookcal_day_events($tmpday, $month, $year, $today);
498 echo "</td>\n";
499 } else {
500 /* Show days after the current month (next month) */
501 $style = 'cal_other_month';
502 if ($iter_day == 6) {
503 $style .= ' cal_other_month_right';
504 }
505 echo ' <td class="'.$style.' nowrap tdtop" width="14%">';
506 show_bookcal_day_events($tmpday - $max_day_in_month, $next_month, $next_year);
507 echo "</td>\n";
508 }
509 $tmpday++;
510 }
511 echo " </tr>\n";
512 }
513 print '</table>';
514 print '</td>';
515
516 print '<td>'; // Column visible after selection of a day
517 print '<div class="center bookingtab" style="height:50%">';
518 print '<div style="height:100%">';
519 print '<form id="formbooking" name="formbooking" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
520 print '<input type="hidden" name="id" value="'.$id.'">';
521 print '<input type="hidden" name="token" value="'.newToken().'">';
522 print '<input type="hidden" name="action" value="create">';
523 print '<input type="hidden" id="datechosen" name="datechosen" value="">';
524 print '<input type="hidden" id="datetimechosen" name="datetimechosen" value="">';
525 print '<input type="hidden" id="durationbooking" name="durationbooking" value="">';
526
527 print '<div id="bookinghoursection">';
528 print '<br><br><br><br><br><br><div class="opacitymedium center">'.$langs->trans("SelectADay").'</div>';
529 print '</div>';
530 print '</form>';
531 print '</div>';
532 print '</div>';
533
534 print '</td>';
535 }
536 print '</tr>';
537 print '</table>';
538 print '</div>';
539 print '</div>';
540
541 print '<script>';
542 print '
543 function generateBookingButtons(timearray, datestring){
544 console.log("We generate all booking buttons of "+datestring);
545 str = "";
546
547 for (index in timearray){
548 let hour = new Date("2000-01-01T" + index + ":00");
549 duration = timearray[index];
550 isalreadybooked = false;
551 if (duration < 0) {
552 duration *= -1;
553 isalreadybooked = true;
554 }
555 hour.setMinutes(hour.getMinutes() + duration);
556
557 let hours = hour.getHours().toString().padStart(2, "0"); // Formatter pour obtenir deux chiffres
558 let mins = hour.getMinutes().toString().padStart(2, "0"); // Formatter pour obtenir deux chiffres
559
560 timerange = index + " - " + `${hours}:${mins}`;
561 str += \'<input class="button btnsubmitbooking \'+(isalreadybooked == true ? "btnbookcalbooked" : "")+\'" type="submit" name="timebooking" value="\'+timerange+\'" data-duration="\'+duration+\'"><br>\';
562 }
563
564 $("#bookinghoursection").html(str);
565 $(".btnsubmitbooking").on("click", function(){
566 duration = $(this).data("duration");
567 $("#durationbooking").val(duration);
568 })
569 }';
570 print '$(document).ready(function() {
571 $(".cal_available").on("click", function(){
572 console.log("We click on cal_available");
573 $(".cal_chosen").removeClass("cal_chosen");
574 $(this).addClass("cal_chosen");
575 datestring = $(this).children("div").data("date");
576 $.ajax({
577 type: "POST",
578 url: "'.DOL_URL_ROOT.'/public/bookcal/bookcalAjax.php",
579 data: {
580 action: "verifyavailability",
581 id: '.$id.',
582 datetocheck: $(this).children("div").data("datetime"),
583 token: "'.currentToken().'",
584 }
585 }).done(function (data) {
586 console.log("We show all booking");
587 if (data["code"] == "SUCCESS") {
588 /* TODO Replace this with a creating of allavailable hours button */
589 console.log(data)
590 timearray = data["availability"];
591 console.log(timearray);
592 generateBookingButtons(timearray, datestring);
593 $(".btnbookcalbooked").prop("disabled", true);
594 } else {
595 if(data["code"] == "NO_DATA_FOUND"){
596 console.log("No booking to hide");
597 } else {
598 console.log(data["message"]);
599 }
600 }
601 });
602 $(".bookingtab").removeClass("hidden");
603 $("#bookingtabspandate").text($(this).children("div").data("date"));
604 $("#datechosen").val($(this).children("div").attr("id"));
605 $("#datetimechosen").val($(this).children("div").data("datetime"));
606 });
607
608 $("btnformbooking")
609
610 '.($datechosen ? '$(".cal_chosen").trigger( "click" )' : '').'
611 });';
612 print '</script>';
613}
614
615llxFooter('', 'public');
616
617
627function show_bookcal_day_events($day, $month, $year, $today = 0)
628{
629 global $conf;
630 if ($conf->use_javascript_ajax) { // Enable the "Show more button..."
631 $conf->global->MAIN_JS_SWITCH_AGENDA = 1;
632 }
633
634 $dateint = sprintf("%04d", $year).'_'.sprintf("%02d", $month).'_'.sprintf("%02d", $day);
635 $eventdatetime = dol_mktime(-1, -1, -1, $month, $day, $year);
636 //print 'show_bookcal_day_events day='.$day.' month='.$month.' year='.$year.' dateint='.$dateint;
637
638 print "\n";
639
640 $curtime = dol_mktime(0, 0, 0, $month, $day, $year);
641 // Line with title of day
642 print '<div id="dayevent_'.$dateint.'" class="dayevent tagtable centpercent nobordernopadding" data-datetime="'.$eventdatetime.'" data-date="'.dol_print_date($eventdatetime, "daytext").'">'."\n";
643 print dol_print_date($curtime, '%d');
644 print '<br>';
645 if ($today) {
646 print img_picto('today', 'fontawesome_circle_fas_black_7px');
647 } else {
648 print '<br>';
649 }
650 print '</div>'; // table
651 print "\n";
652}
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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.
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
llxFooter()
Footer empty.
Definition document.php:107
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)
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.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
getUserRemoteIP()
Return the IP of remote user.
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:627
llxHeaderVierge($title, $head="", $disablejs=0, $disablehead=0, $arrayofjs=[], $arrayofcss=[])
Show header for booking.
Definition index.php:136
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.