mirror of
https://github.com/limosek/zaf-plugins.git
synced 2025-01-21 23:45:56 +01:00
Added isfirst
This commit is contained in:
parent
09785e4cf6
commit
326d6363b0
@ -37,3 +37,17 @@ Description::
|
|||||||
Cmd: php getr.php "$from" "$to" "$start_only"
|
Cmd: php getr.php "$from" "$to" "$start_only"
|
||||||
/Item
|
/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
|
||||||
|
|
||||||
|
|
||||||
|
77
booked/isfirst.php
Executable file
77
booked/isfirst.php
Executable file
@ -0,0 +1,77 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
function help() {
|
||||||
|
echo "Parameters: reservation_time interval\n"
|
||||||
|
."Where interval can be 'hour','day' or two datetimes\n"
|
||||||
|
."example1: isfirst '2016-01-01 14:00' day\n"
|
||||||
|
."example2: isfirsr '2016-01-01 14:00' '2016-01-01 00:00' '2016-01-03 00:00'\n";
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
error_reporting(0);
|
||||||
|
session_start();
|
||||||
|
$time=$argv[1];
|
||||||
|
$type=$argv[2];
|
||||||
|
$range=$argv[3];
|
||||||
|
|
||||||
|
define("YOURTIMEZONE",getenv("timezone"));
|
||||||
|
define("BOOKEDWEBSERVICESURL",getenv("url"));
|
||||||
|
|
||||||
|
require_once(__DIR__ . "/bookedapi.php");
|
||||||
|
|
||||||
|
$tz=New DateTimeZone(getenv("timezone"));
|
||||||
|
|
||||||
|
if ($time!="") {
|
||||||
|
$timed=New DateTime(strtr($time,"_"," "));
|
||||||
|
$timed->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";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user