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