<?php
require dirname(__FILE__) . '/../jxcms/common.php';
$pid = intval(R('pid'));
$sid = intval(R('sid'));
$areaObj = M('area');
$response = array();
if ($sid) {
	while ($sid) {
		$tmp = array();
		$pid = $areaObj -> area($sid, 'pid');
		$areas = $areaObj -> child($pid);
		if ($areas) {
			foreach($areas as $area) {
				$sel = $area['areaid'] == $sid ? 1 : 0;
				$tmp[] = array('areaid' => $area['areaid'], 'name' => $area['name'], 'sel' => $sel);
			}
			$sid = $area['pid'];
		}
		if ($tmp) $response[] = $tmp;
	}
	if ($response) $response = array_reverse($response);
} else {
	$tmp = array();
	$areas = $areaObj -> child($pid);
	if ($areas) {
		foreach($areas as $area) {
			$tmp[] = array('areaid' => $area['areaid'], 'name' => $area['name'], 'sel' => 0);
		}
	}
	if ($tmp) $response[] = $tmp;
}
unset($areaObj, $areas);
if ($response) echo json_encode($response);
//echo 'Memory:' . get_run_memory() . ' Time:' . get_run_time();
?>
