70 lines
1.7 KiB
PHP
70 lines
1.7 KiB
PHP
<?php
|
|
|
|
require_once 'dbutils.php';
|
|
require_once 'config.php';
|
|
|
|
class Menu {
|
|
public static function getmenu($pdo) {
|
|
$sql = "SELECT value FROM %ossystem% WHERE item=?";
|
|
$result = DbUtils::fetchSqlAll($pdo, $sql, array('products'));
|
|
|
|
if (is_null($result) || (count($result) == 0)) {
|
|
return array("status" => "ERROR","msg" => "Keine Produktdefinition hinterlegt.");
|
|
}
|
|
|
|
$products = json_decode($result[0]["value"], true);
|
|
|
|
$sql = "SELECT value FROM %ossystem% WHERE item=?";
|
|
$result = DbUtils::fetchSqlAll($pdo, $sql, array('types'));
|
|
|
|
if (is_null($result) || (count($result) == 0)) {
|
|
return array("status" => "ERROR","msg" => "Keine Produktdefinition hinterlegt.");
|
|
}
|
|
|
|
$types = json_decode($result[0]["value"], true);
|
|
foreach ($types as &$t) {
|
|
$typeid = $t["id"];
|
|
$t["hasprodimages"] = self::hasTypeProdImages($pdo, $types, $products, $typeid);
|
|
}
|
|
|
|
return array("status" => "OK","msg" => array("types" => $types,"products" => $products));
|
|
}
|
|
|
|
private static function hasTypeProdImages($pdo,$alltypes,$allproducts,$typeid) {
|
|
$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) {
|
|
$img = DbUtils::fetchSqlAll($pdo, $sql, array(DbUtils::$TYPE_PRODIMG,$prodid));
|
|
if (count($img) > 0) {
|
|
$imgdata = $img[0]["content"];
|
|
if ($imgdata != '') {
|
|
return 1;
|
|
}
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
}
|
|
|
|
if (isset($_GET["command"])) {
|
|
$command = $_GET["command"];
|
|
|
|
$pdo = DbUtils::openDbAndReturnPdoStatic();
|
|
|
|
switch ($command) {
|
|
case "getmenu":
|
|
$ret = Menu::getmenu($pdo);
|
|
echo json_encode($ret);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|