<?php

include_once('../../conf/config.inc.php');
include_once(DATEIPFAD . 'conf/db.inc.php');
include_once(DATEIPFAD . 'includes/functions.shopeinstellung.inc.php');
include_once(DATEIPFAD . 'includes/functions.kategorie.inc.php');
include_once(DATEIPFAD . 'includes/functions.seo.inc.php');
include_once(DATEIPFAD . 'includes/functions.easymarketing.inc.php');

$einstellungen = GetEinstellungen('access_token', 'easymarketing');
if($_GET['shop_token'] !== getShopToken() || !$einstellungen->easymarketing->access_token) {
    header($_SERVER["SERVER_PROTOCOL"] . ' 401 Unauthorized');
    echo '<h1>Error 401 - You are not allowed to access this resource</h1>';
    exit;
}

$resultObj = new stdClass();
if($_GET['id'] == 0) {
    $resultObj->id = 0;
    $resultObj->name = 'root';
    $resultObj->url = URLPFAD;
    $resultObj->children = getCategoryChildIdsArray(0);
} else {
    $category = GetKategorieDetail($_GET['id']);
    if($category && $category->aktiv) {
        $resultObj->id = $category->id;
        $resultObj->name = $category->name;
        $seoUrlArray = GetSEOURLArray(array($category->id), SEOURL_TYPE_KATEGORIE, GetDefaultLanguageID(), array());
        $resultObj->url = GetKategorieLink($category->id, $seoUrlArray['kategorie'][$category->id]);
        $resultObj->children = getCategoryChildIdsArray($category->id);
    }
}

echo json_encode($resultObj);
