22if (!defined(
'NOTOKENRENEWAL')) {
23 define(
'NOTOKENRENEWAL',
'1');
25if (!defined(
'NOREQUIREHTML')) {
26 define(
'NOREQUIREHTML',
'1');
28if (!defined(
'NOREQUIREAJAX')) {
29 define(
'NOREQUIREAJAX',
'1');
31if (!defined(
'NOREQUIRESOC')) {
32 define(
'NOREQUIRESOC',
'1');
35if (!defined(
'NOREQUIREMENU')) {
36 define(
'NOREQUIREMENU',
'1');
38if (!defined(
"NOLOGIN")) {
39 define(
"NOLOGIN",
'1');
41if (!defined(
'NOBROWSERNOTIF')) {
42 define(
'NOBROWSERNOTIF',
'1');
45require
'../../main.inc.php';
46require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
48$action =
GETPOST(
'action',
'aZ09');
50$datetocheckbooking =
GETPOSTINT(
'datetocheck');
74if ($action ==
'verifyavailability') {
78 $response[
"code"] =
"MISSING_ID";
79 $response[
"message"] =
"Missing parameter id";
80 header(
'HTTP/1.0 400 Bad Request');
81 echo json_encode($response);
84 if (empty($datetocheckbooking)) {
86 $response[
"code"] =
"MISSING_DATE_AVAILABILITY";
87 $response[
"message"] =
"Missing parameter datetocheck";
88 header(
'HTTP/1.0 400 Bad Request');
89 echo json_encode($response);
96 $availabilitytab = array();
97 $sql =
"SELECT ba.rowid as id, ba.duration, ba.startHour, ba.endHour, ba.start, ba.end";
98 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bookcal_availabilities as ba";
99 $sql .=
" WHERE ba.fk_bookcal_calendar = ".((int) $id);
100 $sql .=
" AND ba.status = 1";
101 $resql = $db->query($sql);
103 $num = $db->num_rows($resql);
106 $obj = $db->fetch_object($resql);
107 $starttime = $db->jdate($obj->start);
108 $endtime = $db->jdate($obj->end);
109 $offsetmin = $obj->duration % 60;
110 if ($offsetmin == 0) {
113 $startHourstring = $obj->startHour;
114 $endHourstring = $obj->endHour;
115 if ($startHourstring <= 0) {
116 $startHourstring = 0;
118 if ($endHourstring >= 24) {
121 $offsethour = round($obj->duration / 60);
123 if ($datetocheckbooking >= $starttime && $datetocheckbooking <= $endtime) {
124 for ($hour=$startHourstring; $hour < $endHourstring; $hour+= $offsethour) {
125 for ($min=0; $min < 60; $min += $offsetmin) {
129 $hourstring =
"0".$hourstring;
132 $minstring =
"0".$minstring;
134 $response[
"availability"][$hourstring.
":".$minstring] = intval($obj->duration);
141 $response[
"code"] =
"SUCCESS";
143 $response[
"code"] =
"ERROR";
152 $sql =
"SELECT b.datep, b.id";
153 $sql .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm as b";
154 $sql .=
" WHERE b.datep >= '".$db->idate($datetocheckbooking).
"'";
155 $sql .=
" AND b.datep < '".$db->idate($datetocheckbooking_end).
"'";
156 $sql .=
" AND b.code = 'AC_RDV'";
157 $sql .=
" AND b.status = 0";
158 $sql .=
" AND b.fk_bookcal_calendar = ".((int) $id);
159 $resql = $db->query($sql);
161 $num = $db->num_rows($resql);
164 $obj = $db->fetch_object($resql);
165 $datebooking = $db->jdate($obj->datep);
167 $hourstring = $datebookingarray[
"hours"];
168 $minstring = $datebookingarray[
"minutes"];
169 if ($hourstring < 10) {
170 $hourstring =
"0".$hourstring;
172 if ($minstring < 10) {
173 $minstring =
"0".$minstring;
175 $response[
"availability"][$hourstring.
":".$minstring] *= -1;
185echo json_encode($result);
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.