dolibarr 19.0.3
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 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
28if (!defined('NOLOGIN')) {
29 define("NOLOGIN", 1); // This means this output page does not require to be logged.
30}
31if (!defined('NOCSRFCHECK')) {
32 define("NOCSRFCHECK", 1); // We accept to go on this page from external web site.
33}
34if (!defined('NOBROWSERNOTIF')) {
35 define('NOBROWSERNOTIF', '1');
36}
37
38// Load Dolibarr environment
39require '../../main.inc.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
41require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
43require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
44require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
45require_once DOL_DOCUMENT_ROOT.'/bookcal/class/calendar.class.php';
46require_once DOL_DOCUMENT_ROOT.'/bookcal/class/availabilities.class.php';
47require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
48require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
49
50$langs->loadLangs(array("main", "other", "dict", "agenda", "errors", "companies"));
51
52$action = GETPOST('action', 'aZ09');
53$id = GETPOST('id', 'int');
54$id_availability = GETPOST('id_availability', 'int');
55
56$year = GETPOST("year", "int") ? GETPOST("year", "int") : date("Y");
57$month = GETPOST("month", "int") ? GETPOST("month", "int") : date("m");
58$week = GETPOST("week", "int") ? GETPOST("week", "int") : date("W");
59$day = GETPOST("day", "int") ? GETPOST("day", "int") : date("d");
60$dateselect = dol_mktime(0, 0, 0, GETPOST('dateselectmonth', 'int'), GETPOST('dateselectday', 'int'), GETPOST('dateselectyear', 'int'), 'tzuserrel');
61if ($dateselect > 0) {
62 $day = GETPOST('dateselectday', 'int');
63 $month = GETPOST('dateselectmonth', 'int');
64 $year = GETPOST('dateselectyear', 'int');
65}
66$backtopage = GETPOST("backtopage", "alpha");
67
68$object = new Calendar($db);
69$result = $object->fetch($id);
70
71$availability = new Availabilities($db);
72if ($id_availability > 0) {
73 $result = $availability->fetch($id_availability);
74}
75
76$now = dol_now();
77$nowarray = dol_getdate($now);
78$nowyear = $nowarray['year'];
79$nowmonth = $nowarray['mon'];
80$nowday = $nowarray['mday'];
81
82$prev = dol_get_prev_month($month, $year);
83$prev_year = $prev['year'];
84$prev_month = $prev['month'];
85$next = dol_get_next_month($month, $year);
86$next_year = $next['year'];
87$next_month = $next['month'];
88
89$max_day_in_prev_month = date("t", dol_mktime(0, 0, 0, $prev_month, 1, $prev_year, 'gmt')); // Nb of days in previous month
90$max_day_in_month = date("t", dol_mktime(0, 0, 0, $month, 1, $year)); // Nb of days in next month
91// 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)
92$tmpday = -date("w", dol_mktime(12, 0, 0, $month, 1, $year, 'gmt')) + 2; // date('w') is 0 fo sunday
93$tmpday += ((isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1) - 1);
94if ($tmpday >= 1) {
95 $tmpday -= 7; // If tmpday is 0 we start with sunday, if -6, we start with monday of previous week.
96}
97// Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
98$firstdaytoshow = dol_mktime(0, 0, 0, $prev_month, $max_day_in_prev_month + $tmpday, $prev_year, 'tzuserrel');
99$next_day = 7 - ($max_day_in_month + 1 - $tmpday) % 7;
100if ($next_day < 6) {
101 $next_day += 7;
102}
103$lastdaytoshow = dol_mktime(0, 0, 0, $next_month, $next_day, $next_year, 'tzuserrel');
104
105$datechosen = GETPOST('datechosen', 'alpha');
106$datetimechosen = GETPOST('datetimechosen', 'int');
107$isdatechosen = false;
108$timebooking = GETPOST("timebooking");
109$datetimebooking = GETPOST("datetimebooking", 'int');
110$durationbooking = GETPOST("durationbooking", 'int');
122function llxHeaderVierge($title, $head = "", $disablejs = 0, $disablehead = 0, $arrayofjs = [], $arrayofcss = [])
123{
124 global $user, $conf, $langs, $mysoc;
125
126 top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss); // Show html headers
127
128 print '<body id="mainbody" class="publicnewmemberform">';
129
130 // Define urllogo
131 if (getDolGlobalInt('BOOKCAL_SHOW_COMPANY_LOGO') || getDolGlobalString('BOOPKCAL_PUBLIC_INTERFACE_TOPIC')) {
132 // Print logo
133 if (getDolGlobalInt('BOOKCAL_SHOW_COMPANY_LOGO')) {
134 $urllogo = DOL_URL_ROOT.'/theme/common/login_logo.png';
135
136 if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small)) {
137 $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/thumbs/'.$mysoc->logo_small);
138 } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$mysoc->logo)) {
139 $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/'.$mysoc->logo);
140 } elseif (is_readable(DOL_DOCUMENT_ROOT.'/theme/dolibarr_logo.svg')) {
141 $urllogo = DOL_URL_ROOT.'/theme/dolibarr_logo.svg';
142 }
143 }
144 }
145
146 print '<div class="center">';
147 // Output html code for logo
148 print '<div class="backgreypublicpayment">';
149 print '<div class="logopublicpayment">';
150 if ($urllogo) {
151 print '<a href="'.(getDolGlobalString('BOOKCAL_PUBLIC_INTERFACE_TOPIC') ? getDolGlobalString('BOOKCAL_PUBLIC_INTERFACE_TOPIC') : dol_buildpath('/public/ticket/index.php?entity='.$conf->entity, 1)).'">';
152 print '<img id="dolpaymentlogo" src="'.$urllogo.'">';
153 print '</a>';
154 }
155 if (getDolGlobalString('BOOKCAL_PUBLIC_INTERFACE_TOPIC')) {
156 print '<div class="clearboth"></div><strong>'.(getDolGlobalString('BOOKCAL_PUBLIC_INTERFACE_TOPIC') ? getDolGlobalString('BOOKCAL_PUBLIC_INTERFACE_TOPIC') : $langs->trans("BookCalSystem")).'</strong>';
157 }
158 if (empty($urllogo) && ! getDolGlobalString('BOOKCAL_PUBLIC_INTERFACE_TOPIC')) {
159 print $mysoc->name;
160 }
161 print '</div>';
162 if (!getDolGlobalInt('MAIN_HIDE_POWERED_BY')) {
163 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>';
164 }
165 print '</div>';
166
167 print '</div>';
168
169 print '<div class="divmainbodylarge">';
170}
171
172
173/*
174 * Actions
175 */
176
177if ($action == 'add') {
178 $error = 0;
179 $idcontact = 0;
180 $calendar = $object;
181 $contact = new Contact($db);
182 $actioncomm = new ActionComm($db);
183
184 if (!is_object($user)) {
185 $user = new User($db);
186 }
187
188 $db->begin();
189
190 if (!GETPOST("lastname")) {
191 $error++;
192 $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Lastname"))."<br>\n";
193 }
194 if (!GETPOST("firstname")) {
195 $error++;
196 $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Firstname"))."<br>\n";
197 }
198 if (!GETPOST("email")) {
199 $error++;
200 $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Email"))."<br>\n";
201 }
202
203 if (!$error) {
204 $sql = "SELECT s.rowid";
205 $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as s";
206 $sql .= " WHERE s.lastname = '".$db->escape(GETPOST("lastname"))."'";
207 $sql .= " AND s.firstname = '".$db->escape(GETPOST("firstname"))."'";
208 $sql .= " AND s.email = '".$db->escape(GETPOST("email"))."'";
209 $resql = $db->query($sql);
210
211 if ($resql) {
212 $num = $db->num_rows($resql);
213 if ($num > 0) {
214 $obj = $db->fetch_object($resql);
215 $idcontact = $obj->rowid;
216 $contact->fetch($idcontact);
217 } else {
218 $contact->lastname = GETPOST("lastname");
219 $contact->firstname = GETPOST("firstname");
220 $contact->email = GETPOST("email");
221 $result = $contact->create($user);
222 if ($result < 0) {
223 $error++;
224 $errmsg .= $contact->error." ".join(',', $contact->errors);
225 }
226 }
227 } else {
228 $error++;
229 $errmsg .= $db->lasterror();
230 }
231 }
232
233 if (!$error) {
234 $dateend = dol_time_plus_duree(GETPOST("datetimebooking", 'int'), GETPOST("durationbooking"), 'i');
235
236 $actioncomm->label = $langs->trans("BookcalBookingTitle");
237 $actioncomm->type = 'AC_RDV';
238 $actioncomm->type_id = 5;
239 $actioncomm->datep = GETPOST("datetimebooking", 'int');
240 $actioncomm->datef = $dateend;
241 $actioncomm->note_private = GETPOST("description");
242 $actioncomm->percentage = -1;
243 $actioncomm->fk_bookcal_calendar = $id;
244 $actioncomm->userownerid = $calendar->visibility;
245 $actioncomm->contact_id = $contact->id;
246 $actioncomm->socpeopleassigned = $contact->id;
247
248 $result = $actioncomm->create($user);
249 if ($result < 0) {
250 $error++;
251 $errmsg .= $actioncomm->error." ".join(',', $actioncomm->errors);
252 }
253
254 if (!$error) {
255 $sql = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources";
256 $sql .= "(fk_actioncomm, element_type, fk_element, answer_status, mandatory, transparency";
257 $sql .= ") VALUES (";
258 $sql .= (int) $actioncomm->id;
259 $sql .= ", 'socpeople'";
260 $sql .= ", ". (int) $contact->id;
261 $sql .= ", 0, 0, 0)";
262 $resql = $db->query($sql);
263 if (!$resql) {
264 $error++;
265 $errmsg .= $db->lasterror();
266 }
267 }
268 }
269
270 if (!$error) {
271 $db->commit();
272 $action = 'afteradd';
273 } else {
274 $db->rollback();
275 $action = 'create';
276 }
277}
278
279
280/*
281 * View
282 */
283
284$form = new Form($db);
285
286llxHeaderVierge('BookingCalendar');
287
288print '<center><br><h2>'.(!empty($object->label) ? $object->label : $object->ref).'</h2></center>';
289
290dol_htmloutput_errors($errmsg);
291
292if ($action == 'create') {
293 $backtopage = $_SERVER["PHP_SELF"].'?id='.$id.'&datechosen='.$datechosen;
294} else {
295 $backtopage = DOL_URL_ROOT.'/public/bookcal/index.php?id='.$id;
296}
297
298//print '<div class="">';
299
300print '<div class="bookcalpublicarea centpercent center" style="min-width:30%;width:fit-content;height:70%;top:60%;left: 50%;">';
301print '<div class="bookcalform boxtable" style="border:thin solid gray;padding:5px;min-height:50%">';
302if ($action == 'afteradd') {
303 print '<h2>';
304 print $langs->trans("BookingSuccessfullyBooked");
305 print '</h2>';
306 print $langs->trans("BookingReservationHourAfter", dol_print_date(GETPOST("datetimebooking", 'int'), "dayhourtext"));
307} else {
308 $param = '';
309
310 print '<table>';
311 print '<tr>';
312 print '<td>';
313 if ($action == 'create') {
314 print '<span class="opacitymedium">'.$langs->trans("FieldsWithAreMandatory", '*').'</span>';
315 } else {
316 print '<form name="formsearch" action="'.$_SERVER["PHP_SELF"].'">';
317 print '<input type="hidden" name="id" value="'.$id.'">';
318
319 $nav = '<a href="?id='.$id."&year=".$prev_year."&month=".$prev_month.$param.'"><i class="fa fa-chevron-left"></i></a> &nbsp;'."\n";
320 $nav .= ' <span id="month_name">'.dol_print_date(dol_mktime(0, 0, 0, $month, 1, $year), "%b %Y");
321 $nav .= " </span>\n";
322 $nav .= ' &nbsp; <a href="?id='.$id."&year=".$next_year."&month=".$next_month.$param.'"><i class="fa fa-chevron-right"></i></a>'."\n";
323 if (empty($conf->dol_optimize_smallscreen)) {
324 $nav .= ' &nbsp; <a href="?id='.$id."&year=".$nowyear."&amp;month=".$nowmonth."&amp;day=".$nowday.$param.'" class="datenowlink">'.$langs->trans("Today").'</a> ';
325 }
326 $nav .= $form->selectDate($dateselect, 'dateselect', 0, 0, 1, '', 1, 0);
327 $nav .= '<button type="submit" class="liste_titre button_search valignmiddle" name="button_search_x" value="x"><span class="fa fa-search"></span></button>';
328
329 print $nav;
330 print '</form>';
331 }
332 print '</td>';
333 print '<td>';
334 print '<div class="center hidden bookingtab" style="height:50%">';
335 print '<span id="bookingtabspandate"></span>';
336 print '</div>';
337 print '</td>';
338 print '</tr>';
339
340 print '<tr>';
341
342
343 if ($action == 'create') {
344 print '<td>';
345 print '<br>';
346 if (empty($datetimebooking)) {
347 $timebookingarray = explode(" - ", $timebooking);
348 $timestartarray = explode(":", $timebookingarray[0]);
349 $timeendarray = explode(":", $timebookingarray[1]);
350 $datetimebooking = dol_time_plus_duree($datetimechosen, intval($timestartarray[0]), "h");
351 $datetimebooking = dol_time_plus_duree($datetimebooking, intval($timestartarray[1]), "i");
352 }
353 print '<span>'.img_picto("", "calendar")."&nbsp;".dol_print_date($datetimebooking, 'dayhourtext').'</span>';
354 print '</td>';
355 }
356
357 print '<td>';
358 if ($action == "create") {
359 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
360 print '<table class="border" summary="form to subscribe" id="tablesubscribe">'."\n";
361 print '<input type="hidden" name="token" value="'.newToken().'">';
362 print '<input type="hidden" name="action" value="add">';
363 print '<input type="hidden" name="datetimebooking" value="'.$datetimebooking.'">';
364 print '<input type="hidden" name="datechosen" value="'.$datechosen.'">';
365 print '<input type="hidden" name="id" value="'.$id.'">';
366 print '<input type="hidden" name="durationbooking" value="'.$durationbooking.'">';
367
368 // Lastname
369 print '<tr><td>'.$langs->trans("Lastname").' <span class="star">*</span></td><td><input type="text" name="lastname" class="minwidth150" value="'.dol_escape_htmltag(GETPOST('lastname')).'"></td></tr>'."\n";
370 // Firstname
371 print '<tr><td>'.$langs->trans("Firstname").' <span class="star">*</span></td><td><input type="text" name="firstname" class="minwidth150" value="'.dol_escape_htmltag(GETPOST('firstname')).'"></td></tr>'."\n";
372 // EMail
373 print '<tr><td>'.$langs->trans("Email").' <span class="star">*</span></td><td><input type="text" name="email" maxlength="255" class="minwidth150" value="'.dol_escape_htmltag(GETPOST('email')).'"></td></tr>'."\n";
374
375 // Comments
376 print '<tr>';
377 print '<td class="tdtop">'.$langs->trans("Message").'</td>';
378 print '<td class="tdtop"><textarea name="description" id="description" wrap="soft" class="quatrevingtpercent" rows="'.ROWS_2.'">'.dol_escape_htmltag(GETPOST('description', 'restricthtml'), 0, 1).'</textarea></td>';
379 print '</tr>'."\n";
380 print '</table>'."\n";
381 print '<div class="center">';
382 print '<input type="submit" value="'.$langs->trans("Submit").'" id="submitsave" class="button">';
383 print '</div>';
384 print '</form>';
385 } else {
386 print '<table class="centpercent noborder nocellnopadd cal_pannel cal_month">';
387 print ' <tr class="">';
388 // Column title of weeks numbers
389 echo ' <td class="center">#</td>';
390 $i = 0;
391 while ($i < 7) {
392 $numdayinweek = (($i + (isset($conf->global->MAIN_START_WEEK) ? $conf->global->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 tdfordaytitle'.($i == 0 ? ' borderleft' : '').'">';
400 print $langs->trans("Day".$numdayinweek);
401 print ' </td>'."\n";
402 }
403 $i++;
404 }
405 echo ' </tr>'."\n";
406 $todayarray = dol_getdate($now, 'fast');
407 $todaytms = dol_mktime(0, 0, 0, $todayarray['mon'], $todayarray['mday'], $todayarray['year']);
408
409 // Load into an array all days with availabilities of the calendar for the current month $todayarray['mon'] and $todayarray['year']
410 $arrayofavailabledays = array();
411
412 $arrayofavailabilities = $availability->fetchAll('', '', 0, 0, array('status' => '1', 'fk_bookcal_calendar' => $id));
413
414 foreach ($arrayofavailabilities as $key => $value) {
415 $startarray = dol_getdate($value->start);
416 $endarray = dol_getdate($value->end);
417 for ($i = $startarray['mday']; $i <= $endarray['mday']; $i++) {
418 if ($todayarray['mon'] >= $startarray['mon'] && $todayarray['mon'] <= $endarray['mon']) {
419 $arrayofavailabledays[dol_mktime(0, 0, 0, $todayarray['mon'], $i, $todayarray['year'])] = dol_mktime(0, 0, 0, $todayarray['mon'], $i, $todayarray['year']);
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 = date("W", strtotime(date($currdate0)));
436 // Show the week number, and define column width
437 echo ' <td class="center weeknumber opacitymedium" 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 hidden bookingtab" style="height:50%">';
494 print '<div style="margin-top:8px;max-height:330px" class="div-table-responsive-no-min">';
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="buttonlistbooking"></div>';
504 print '</form>';
505 print '</div>';
506 print '</div>';
507
508 print '</td>';
509 }
510 print '</td>';
511 print '</tr>';
512 print '</table>';
513 print '</div>';
514 print '</div>';
515
516 print '<script>';
517 print '
518 function generateBookingButtons(timearray, datestring){
519 console.log("We generate all booking buttons of "+datestring);
520 str = "";
521 for(index in timearray){
522 let hour = new Date("2000-01-01T" + index + ":00");
523 duration = timearray[index];
524 isalreadybooked = false;
525 if (duration < 0) {
526 duration *= -1;
527 isalreadybooked = true;
528 }
529 hour.setMinutes(hour.getMinutes() + duration);
530
531 let hours = hour.getHours().toString().padStart(2, "0"); // Formater pour obtenir deux chiffres
532 let mins = hour.getMinutes().toString().padStart(2, "0"); // Formater pour obtenir deux chiffres
533
534 timerange = index + " - " + `${hours}:${mins}`;
535 str += "<input class=\'button btnsubmitbooking "+(isalreadybooked == true ? "btnbookcalbooked" : "")+"\' type=\'submit\' name=\'timebooking\' value=\'"+timerange+"\' data-duration=\'"+duration+"\'><br>";
536 }
537 $("#buttonlistbooking").html(str);
538 $(".btnsubmitbooking").on("click", function(){
539 duration = $(this).data("duration");
540 $("#durationbooking").val(duration);
541 })
542 }';
543 print '$(document).ready(function() {
544 $(".cal_available").on("click", function(){
545 console.log("We click on cal_available");
546 $(".cal_chosen").removeClass("cal_chosen");
547 $(this).addClass("cal_chosen");
548 datestring = $(this).children("div").data("date");
549 $.ajax({
550 type: "POST",
551 url: "'.DOL_URL_ROOT.'/public/bookcal/bookcalAjax.php",
552 data: {
553 action: "verifyavailability",
554 id: '.$id.',
555 datetocheck: $(this).children("div").data("datetime"),
556 token: "'.currentToken().'",
557 }
558 }).done(function (data) {
559 console.log("We show all booking");
560 if (data["code"] == "SUCCESS") {
561 /* TODO Replace this with a creating of allavailable hours button */
562 console.log(data)
563 timearray = data["availability"];
564 console.log(timearray);
565 generateBookingButtons(timearray, datestring);
566 $(".btnbookcalbooked").prop("disabled", true);
567 } else {
568 if(data["code"] == "NO_DATA_FOUND"){
569 console.log("No booking to hide");
570 } else {
571 console.log(data["message"]);
572 }
573 }
574 });
575 $(".bookingtab").removeClass("hidden");
576 $("#bookingtabspandate").text($(this).children("div").data("date"));
577 $("#datechosen").val($(this).children("div").attr("id"));
578 $("#datetimechosen").val($(this).children("div").data("datetime"));
579 });
580
581 $("btnformbooking")
582
583 '.($datechosen ? '$(".cal_chosen").trigger( "click" )' : '').'
584 });';
585 print '</script>';
586}
587
588llxFooter('', 'public');
589
590
600function show_bookcal_day_events($day, $month, $year, $today = 0)
601{
602 global $conf;
603 if ($conf->use_javascript_ajax) { // Enable the "Show more button..."
604 $conf->global->MAIN_JS_SWITCH_AGENDA = 1;
605 }
606
607 $dateint = sprintf("%04d", $year).'_'.sprintf("%02d", $month).'_'.sprintf("%02d", $day);
608 $eventdatetime = dol_mktime(-1, -1, -1, $month, $day, $year);
609 //print 'show_bookcal_day_events day='.$day.' month='.$month.' year='.$year.' dateint='.$dateint;
610
611 print "\n";
612
613 $curtime = dol_mktime(0, 0, 0, $month, $day, $year);
614 // Line with title of day
615 print '<div id="dayevent_'.$dateint.'" class="dayevent tagtable centpercent nobordernopadding" data-datetime="'.$eventdatetime.'" data-date="'.dol_print_date($eventdatetime, "daytext").'">'."\n";
616 print dol_print_date($curtime, '%d');
617 print '<br>';
618 if ($today) {
619 print img_picto('today', 'fontawesome_circle_fas_black_7px');
620 } else {
621 print '<br>';
622 }
623 print '</div>'; // table
624 print "\n";
625}
if(!defined( 'NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined( 'NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined( 'NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined( 'NOIPCHECK')) llxHeaderVierge()
Header function.
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to manage agenda events (actions)
Class for Availabilities.
Class for Calendar.
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:513
dol_get_next_month($month, $year)
Return next month.
Definition date.lib.php:532
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 informations (by default a local PHP server timestamp) Re...
currentToken()
Return the value of token currently saved into session with name 'token'.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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 dolibarr global constant string value.
dol_htmloutput_errors($mesgstring='', $mesgarray=array(), $keepembedded=0)
Print formated 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)
Ouput html header of a page.
show_bookcal_day_events($day, $month, $year, $today=0)
Show event of a particular day.
Definition index.php:600
Contact()
Old copy.
Definition index.php:572