28if (!defined(
'NOLOGIN')) {
31if (!defined(
'NOCSRFCHECK')) {
32 define(
"NOCSRFCHECK", 1);
34if (!defined(
'NOBROWSERNOTIF')) {
35 define(
'NOBROWSERNOTIF',
'1');
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';
50$langs->loadLangs(array(
"main",
"other",
"dict",
"agenda",
"errors",
"companies"));
52$action =
GETPOST(
'action',
'aZ09');
54$id_availability =
GETPOST(
'id_availability',
'int');
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");
62 $day =
GETPOST(
'dateselectday',
'int');
63 $month =
GETPOST(
'dateselectmonth',
'int');
64 $year =
GETPOST(
'dateselectyear',
'int');
66$backtopage =
GETPOST(
"backtopage",
"alpha");
69$result = $object->fetch($id);
72if ($id_availability > 0) {
73 $result = $availability->fetch($id_availability);
78$nowyear = $nowarray[
'year'];
79$nowmonth = $nowarray[
'mon'];
80$nowday = $nowarray[
'mday'];
83$prev_year = $prev[
'year'];
84$prev_month = $prev[
'month'];
86$next_year = $next[
'year'];
87$next_month = $next[
'month'];
89$max_day_in_prev_month = date(
"t",
dol_mktime(0, 0, 0, $prev_month, 1, $prev_year,
'gmt'));
90$max_day_in_month = date(
"t",
dol_mktime(0, 0, 0, $month, 1, $year));
92$tmpday = -date(
"w",
dol_mktime(12, 0, 0, $month, 1, $year,
'gmt')) + 2;
93$tmpday += ((isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1) - 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;
103$lastdaytoshow =
dol_mktime(0, 0, 0, $next_month, $next_day, $next_year,
'tzuserrel');
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 = [])
124 global $user, $conf, $langs, $mysoc;
126 top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
128 print
'<body id="mainbody" class="publicnewmemberform">';
134 $urllogo = DOL_URL_ROOT.
'/theme/common/login_logo.png';
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&entity='.$conf->entity.
'&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&entity='.$conf->entity.
'&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';
146 print
'<div class="center">';
148 print
'<div class="backgreypublicpayment">';
149 print
'<div class="logopublicpayment">';
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.
'">';
156 print
'<div class="clearboth"></div><strong>'.(getDolGlobalString(
'BOOKCAL_PUBLIC_INTERFACE_TOPIC') ?
getDolGlobalString(
'BOOKCAL_PUBLIC_INTERFACE_TOPIC') : $langs->trans(
"BookCalSystem")).
'</strong>';
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>';
169 print
'<div class="divmainbodylarge">';
177if ($action ==
'add') {
184 if (!is_object($user)) {
185 $user =
new User($db);
192 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Lastname")).
"<br>\n";
196 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Firstname")).
"<br>\n";
200 $errmsg .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Email")).
"<br>\n";
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);
212 $num = $db->num_rows($resql);
214 $obj = $db->fetch_object($resql);
215 $idcontact = $obj->rowid;
216 $contact->fetch($idcontact);
218 $contact->lastname =
GETPOST(
"lastname");
219 $contact->firstname =
GETPOST(
"firstname");
220 $contact->email =
GETPOST(
"email");
221 $result = $contact->create($user);
224 $errmsg .= $contact->error.
" ".join(
',', $contact->errors);
229 $errmsg .= $db->lasterror();
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;
248 $result = $actioncomm->create($user);
251 $errmsg .= $actioncomm->error.
" ".join(
',', $actioncomm->errors);
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);
265 $errmsg .= $db->lasterror();
272 $action =
'afteradd';
284$form =
new Form($db);
288print
'<center><br><h2>'.(!empty($object->label) ? $object->label : $object->ref).
'</h2></center>';
292if ($action ==
'create') {
293 $backtopage = $_SERVER[
"PHP_SELF"].
'?id='.$id.
'&datechosen='.$datechosen;
295 $backtopage = DOL_URL_ROOT.
'/public/bookcal/index.php?id='.$id;
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') {
304 print $langs->trans(
"BookingSuccessfullyBooked");
306 print $langs->trans(
"BookingReservationHourAfter",
dol_print_date(
GETPOST(
"datetimebooking",
'int'),
"dayhourtext"));
313 if ($action ==
'create') {
314 print
'<span class="opacitymedium">'.$langs->trans(
"FieldsWithAreMandatory",
'*').
'</span>';
316 print
'<form name="formsearch" action="'.$_SERVER[
"PHP_SELF"].
'">';
317 print
'<input type="hidden" name="id" value="'.$id.
'">';
319 $nav =
'<a href="?id='.$id.
"&year=".$prev_year.
"&month=".$prev_month.$param.
'"><i class="fa fa-chevron-left"></i></a> '.
"\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 .=
' <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 .=
' <a href="?id='.$id.
"&year=".$nowyear.
"&month=".$nowmonth.
"&day=".$nowday.$param.
'" class="datenowlink">'.$langs->trans(
"Today").
'</a> ';
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>';
334 print
'<div class="center hidden bookingtab" style="height:50%">';
335 print
'<span id="bookingtabspandate"></span>';
343 if ($action ==
'create') {
346 if (empty($datetimebooking)) {
347 $timebookingarray = explode(
" - ", $timebooking);
348 $timestartarray = explode(
":", $timebookingarray[0]);
349 $timeendarray = explode(
":", $timebookingarray[1]);
353 print
'<span>'.img_picto(
"",
"calendar").
" ".
dol_print_date($datetimebooking,
'dayhourtext').
'</span>';
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.
'">';
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";
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";
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";
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>';
380 print
'</table>'.
"\n";
381 print
'<div class="center">';
382 print
'<input type="submit" value="'.$langs->trans(
"Submit").
'" id="submitsave" class="button">';
386 print
'<table class="centpercent noborder nocellnopadd cal_pannel cal_month">';
387 print
' <tr class="">';
389 echo
' <td class="center">#</td>';
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]);
399 print
' <td class="center minwidth75 bold uppercase tdfordaytitle'.($i == 0 ?
' borderleft' :
'').
'">';
400 print $langs->trans(
"Day".$numdayinweek);
407 $todaytms =
dol_mktime(0, 0, 0, $todayarray[
'mon'], $todayarray[
'mday'], $todayarray[
'year']);
410 $arrayofavailabledays = array();
412 $arrayofavailabilities = $availability->fetchAll(
'',
'', 0, 0, array(
'status' =>
'1',
'fk_bookcal_calendar' => $id));
414 foreach ($arrayofavailabilities as $key => $value) {
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']);
424 for ($iter_week = 0; $iter_week < 6; $iter_week++) {
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) {
430 $currdate0 = sprintf(
"%04d", $year).sprintf(
"%02d", $month).sprintf(
"%02d", $tmpday);
432 $currdate0 = sprintf(
"%04d", $next_year).sprintf(
"%02d", $next_month).sprintf(
"%02d", $tmpday - $max_day_in_month);
435 $numweek0 = date(
"W", strtotime(date($currdate0)));
437 echo
' <td class="center weeknumber opacitymedium" style="min-width: 40px">'.$numweek0.
'</td>';
439 for ($iter_day = 0; $iter_day < 7; $iter_day++) {
442 $style =
'cal_other_month cal_past';
443 if ($iter_day == 6) {
444 $style .=
' cal_other_month_right';
446 echo
' <td class="'.$style.
' nowrap tdtop" width="14%">';
449 } elseif ($tmpday <= $max_day_in_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';
457 if ($todayarray[
'mday'] == $tmpday && $todayarray[
'mon'] == $month && $todayarray[
'year'] == $year) {
461 if ($curtime > $todaytms && in_array($curtime, $arrayofavailabledays)) {
462 $style .=
' cal_available cursorpointer';
464 if ($curtime < $todaytms) {
465 $style .=
' cal_past';
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;
472 echo
' <td class="'.$style.
' nowrap tdtop" width="14%">';
477 $style =
'cal_other_month';
478 if ($iter_day == 6) {
479 $style .=
' cal_other_month_right';
481 echo
' <td class="'.$style.
' nowrap tdtop" width="14%">';
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="">';
503 print
'<div id="buttonlistbooking"></div>';
518 function generateBookingButtons(timearray, datestring){
519 console.log("We generate all booking buttons of "+datestring);
521 for(index in timearray){
522 let hour = new Date("2000-01-01T" + index + ":00");
523 duration = timearray[index];
524 isalreadybooked = false;
527 isalreadybooked = true;
529 hour.setMinutes(hour.getMinutes() + duration);
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
534 timerange = index + " - " + `${hours}:${mins}`;
535 str += "<input class=\'button btnsubmitbooking "+(isalreadybooked == true ? "btnbookcalbooked" : "")+"\' type=\'submit\' name=\'timebooking\' value=\'"+timerange+"\' data-duration=\'"+duration+"\'><br>";
537 $("#buttonlistbooking").html(str);
538 $(".btnsubmitbooking").on("click", function(){
539 duration = $(this).data("duration");
540 $("#durationbooking").val(duration);
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");
551 url: "'.DOL_URL_ROOT.
'/public/bookcal/bookcalAjax.php",
553 action: "verifyavailability",
555 datetocheck: $(this).children("div").data("datetime"),
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 */
563 timearray = data["availability"];
564 console.log(timearray);
565 generateBookingButtons(timearray, datestring);
566 $(".btnbookcalbooked").prop("disabled", true);
568 if(data["code"] == "NO_DATA_FOUND"){
569 console.log("No booking to hide");
571 console.log(data["message"]);
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"));
583 '.($datechosen ?
'$(".cal_chosen").trigger( "click" )' :
'').
'
603 if ($conf->use_javascript_ajax) {
604 $conf->global->MAIN_JS_SWITCH_AGENDA = 1;
607 $dateint = sprintf(
"%04d", $year).
'_'.sprintf(
"%02d", $month).
'_'.sprintf(
"%02d", $day);
608 $eventdatetime =
dol_mktime(-1, -1, -1, $month, $day, $year);
613 $curtime =
dol_mktime(0, 0, 0, $month, $day, $year);
615 print
'<div id="dayevent_'.$dateint.
'" class="dayevent tagtable centpercent nobordernopadding" data-datetime="'.$eventdatetime.
'" data-date="'.
dol_print_date($eventdatetime,
"daytext").
'">'.
"\n";
619 print
img_picto(
'today',
'fontawesome_circle_fas_black_7px');
if(!defined( 'NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined( 'NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined( 'NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined( 'NOIPCHECK')) llxHeaderVierge()
Header function.
Class to manage agenda events (actions)
Class for Availabilities.
Class to manage Dolibarr users.
dol_get_prev_month($month, $year)
Return previous month.
dol_get_next_month($month, $year)
Return next month.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
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.