From 326d6363b0e40c49d304c46bbd898c0931d62b1a Mon Sep 17 00:00:00 2001 From: Lukas Macura Date: Fri, 16 Dec 2016 13:25:26 +0100 Subject: [PATCH] Added isfirst --- booked/control.zaf | 14 +++++++++ booked/isfirst.php | 77 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100755 booked/isfirst.php diff --git a/booked/control.zaf b/booked/control.zaf index 7c366d3..cb068d5 100644 --- a/booked/control.zaf +++ b/booked/control.zaf @@ -37,3 +37,17 @@ Description:: Cmd: php getr.php "$from" "$to" "$start_only" /Item +Item is_first: +Return: int +Parameters:: + time 'now' '' + range1 'day' '' + range2 'no' '' +:: +Description:: + Returns 1 if registration in time is first at given interval. Range can be day, hour or two dates (from range1 to range2) +:: +Cmd: php isfirst.php "$time" "$range1" "$range2" +/Item + + diff --git a/booked/isfirst.php b/booked/isfirst.php new file mode 100755 index 0000000..0a1f4bf --- /dev/null +++ b/booked/isfirst.php @@ -0,0 +1,77 @@ +setTimezone($tz); + $time=$timed->getTimestamp(); + } else { + help(); + } + switch ($type) { + case "day": + $startd=New DateTime("00:00",$tz); + $endd=New DateTime("23:59",$tz); + $start=$startd->getTimestamp(); + $end=$endd->getTimestamp(); + break; + + case "hour": + $startd=New DateTime(date("H").":00",$tz); + $endd=New DateTime(date("H").":59",$tz); + $start=$startd->getTimestamp(); + $end=$endd->getTimestamp(); + break; + default: + $startd=New DateTime($type,$tz); + if ($range) { + $endd=New DateTime($range,$tz); + $start=$startd->getTimestamp(); + $end=$endd->getTimestamp(); + } else { + help(); + } + } + + $bookedapiclient = new bookedapiclient(getenv("username"), getenv("password")); + $bookedapiclient-> authenticate(); + $reservations=$bookedapiclient->getReservation(null,null,null,date("c",$start),date("c",$end)); + + $r=$reservations["reservations"][0]; + $rstart=New DateTime($r["startDate"]); + $rstart->setTimezone($tz); + $rend=New DateTime($r["endDate"]); + $rend->setTimezone($tz); + $rsstart=$rstart->getTimestamp(); + $rsend=$rend->getTimestamp(); + + #echo $rstart->format("Y-m-d H:i") . "," . $rend->format("Y-m-d H:i") . "," . $timed->format("Y-m-d H:i") . "\n"; + + if ($rsstart<=$time && $rsend>=$time) { + echo "1\n"; + } else { + echo "0\n"; + } + + +