<?php

$cms_root_path = '../../../';
require_once $cms_root_path . 'includes/compatibility_includer.php';

//Check required params were passed.
if (
    empty($_REQUEST['page_id'])
    || !is_numeric($_REQUEST['page_id'])
    || !isset($_REQUEST['with_data'])
    || $adminuser->user['id'] != MTCADMIN_USERID
) {
    exit('false');
}

$pagedata = new Pagedata();

if (!empty($_REQUEST['page_list_id']) && is_numeric($_REQUEST['page_list_id'])) {
    if ($pagedata->get(0, $_REQUEST['page_list_id'], 0, 0, (bool) $_REQUEST['with_data'], true) === false) {
        exit('false');
    }
} else {
    if ($pagedata->get($_REQUEST['page_id'], 0, 0, 0, (bool) $_REQUEST['with_data'], true) === false) {
        exit('false');
    }
}

// Output JSON instead of PHP serialized data for safer transport
header('Content-Type: application/json');
echo json_encode($pagedata->pagedata);
