ordersprinter/gastsystem/php/system.php

58 lines
1.2 KiB
PHP

<?php
require_once 'dbutils.php';
require_once 'config.php';
class System {
public static function checkLastOsAccess($pdo) {
$timezone = self::getTimeZone($pdo);
date_default_timezone_set($timezone);
$sql = "SELECT date FROM %gueststatus% WHERE item=?";
$result = DbUtils::fetchSqlAll($pdo, $sql, array('lastosaccess'));
if (count($result) == 0) {
$msg = "0";
} else {
$lastaccess = $result[0]["date"];
$date = new DateTime();
$currentTimeStamp = $date->getTimestamp();
if (($currentTimeStamp - $lastaccess) > 60) {
$msg = 0;
} else {
$msg = 1;
}
}
return array("status" => "OK","msg" => $msg);
}
public static function getTimeZone($pdo) {
$sql = "select value from %ossystem% where item=?";
$result = DbUtils::fetchSqlAll($pdo, $sql, array("timezone"));
if (count($result) == 1) {
return $result[0]["value"];
} else {
return "Europe/Berlin";
}
}
}
if (isset($_GET["command"])) {
$command = $_GET["command"];
$pdo = DbUtils::openDbAndReturnPdoStatic();
switch ($command) {
case "getlastosaccess":
$ret = System::checkLastOsAccess($pdo);
echo json_encode($ret);
break;
default:
break;
}
}