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