<?php

$cms_root_path = "../../../";
require_once($cms_root_path."includes/compatibility_includer.php");

$sub_id = 0;
$listing_container = false;
if (!empty($_GET['sub_id'])) {
    $sub_id = $_GET['sub_id'];
    $page = new Page();
    $page->get($sub_id);
    $listing_container = $page->listing_container;
}

$site_tree = CMSNav::siteTree(
    $sub_id,
    PHP_INT_MAX,
    array(
        'check_innav'=>false,
        'check_published'=>false
    )
);

$is_admin = ( $adminuser->user['id'] == MTCADMIN_USERID ? true : false );

$options = array(
    'first_container_id' => 'site-tree',
    'title_container_tag' => 'span',
    'is_admin' => $is_admin
);

if ( !empty($_GET['active_page_id']) ) {
    $options['active_page_id'] = $_GET['active_page_id'];
}

header('Content-Type: application/json');

ob_start();
CMSNav::generateSiteTreeMenu($site_tree, $options, $listing_container);
$html = ob_get_contents();
ob_end_clean();

exit(
    json_encode([
        "success" => true,
        "result" => [
            "html" => $html,
            "site_tree" => $site_tree
        ]
    ])
);
