109 lines
2.8 KiB
PHP
109 lines
2.8 KiB
PHP
|
<?php
|
||
|
|
||
|
require_once 'dbutils.php';
|
||
|
require_once 'config.php';
|
||
|
|
||
|
class OsSystem {
|
||
|
private static function outputEmptyImage() {
|
||
|
$my_img = imagecreate( 1,1 );
|
||
|
$background = imagecolorallocate( $my_img, 0, 0, 255 );
|
||
|
$black = imagecolorallocate($im, 0, 0, 0);
|
||
|
imagecolortransparent($my_img, $black);
|
||
|
header( "Content-type: image/png" );
|
||
|
imagepng( $my_img );
|
||
|
imagecolordeallocate( $background );
|
||
|
imagedestroy( $my_img );
|
||
|
}
|
||
|
|
||
|
public static function getlogo($pdo) {
|
||
|
$sql = "SELECT content as img FROM %images% WHERE name='logo'";
|
||
|
self::outputImageFromDb($pdo, $sql, null);
|
||
|
}
|
||
|
public static function getprodimage($pdo,$prodid) {
|
||
|
$sql = "SELECT content as img FROM %images% WHERE contenttype=? AND productid=?";
|
||
|
$params = array(DbUtils::$TYPE_PRODIMG,$prodid);
|
||
|
self::outputImageFromDb($pdo, $sql, $params);
|
||
|
}
|
||
|
|
||
|
private static function outputImageFromDb($pdo,$sql,$params) {
|
||
|
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
|
||
|
header("Pragma: no-cache");
|
||
|
header("Expires: Mon, 20 Dec 1998 01:00:00 GMT" );
|
||
|
header('Content-Type: ' . image_type_to_mime_type(IMAGETYPE_PNG));
|
||
|
|
||
|
$result = DbUtils::fetchSqlAll($pdo, $sql, $params);
|
||
|
if (count($result) > 0) {
|
||
|
$logoImg = $result[0]["img"];
|
||
|
if ($logoImg != '') {
|
||
|
$img = base64_decode($logoImg);
|
||
|
$php_img = imagecreatefromstring($img);
|
||
|
|
||
|
imagesavealpha($php_img, true);
|
||
|
$color = imagecolorallocatealpha($php_img, 0, 0, 0, 127);
|
||
|
|
||
|
imagepng($php_img, NULL);
|
||
|
imagecolordeallocate( $color );
|
||
|
imagedestroy($php_img);
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
self::outputEmptyImage();
|
||
|
}
|
||
|
|
||
|
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 = OsSystem::checkLastOsAccess($pdo);
|
||
|
echo json_encode($ret);
|
||
|
break;
|
||
|
case "getlogo":
|
||
|
OsSystem::getlogo($pdo);
|
||
|
break;
|
||
|
case "getprodimage":
|
||
|
OsSystem::getprodimage($pdo,$_GET["prodid"]);
|
||
|
break;
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|