ordersprinter/gastsystem/php/menu.php

66 lines
1.5 KiB
PHP

<?php
require_once 'dbutils.php';
require_once 'config.php';
defined('DB') || define ( 'DB','mysql' );
class Menu {
public static function getmenu($pdo) {
$productsJson = DbUtils::getConfigItem($pdo, 'products', null);
if (is_null($productsJson)) {
return array("status" => "ERROR","msg" => "Keine Produktdefinition hinterlegt.");
}
$products = json_decode($productsJson,true);
$typesJson = DbUtils::getConfigItem($pdo, 'types', null);
if (is_null($typesJson)) {
return array("status" => "ERROR","msg" => "Keine Produktdefinition hinterlegt.");
}
$types = json_decode($typesJson,true);
foreach ($types as &$t) {
$typeid = $t["id"];
$t["hasprodimages"] = self::hasTypeProdImages($pdo, $products, $typeid);
}
return array("status" => "OK","msg" => array("types" => $types,"products" => $products));
}
private static function hasTypeProdImages($pdo,$allproducts,$typeid) {
$prodids = array();
foreach($allproducts as $p) {
if ($p["ref"] == $typeid) {
$prodids[] = $p["id"];
}
}
$sql = "SELECT COALESCE(content,'') as content FROM %images% WHERE contenttype=? AND productid=?";
foreach($prodids as $prodid) {
$img = DbUtils::getImageData($pdo, '', $prodid);
if (!is_null($img)) {
return 1;
}
}
return 0;
}
}
if (isset($_GET["command"])) {
$command = $_GET["command"];
$pdo = null;
if (DB == "mysql") {
$pdo = DbUtils::openDbAndReturnPdoStatic();
}
switch ($command) {
case "getmenu":
$ret = Menu::getmenu($pdo);
echo json_encode($ret);
break;
default:
break;
}
}