<?php
/***********************
//	網站地圖
//	採用 php 動態載入最新網站檔案地圖
//	2013-02-20 Nio 新增
//
/**********************/

include('new_lib/lib_nio.php');
include('new_lib/cls_nio.php');
include('new_lib/cls_template.php');
include('new_lib/cls_session.php');
$smarty = new Smarty;
$nio = new nio;	
$templ = new templateC;

$domain = $nio->thisDomain(); 
$web_id = $templ->domain2Id($domain);
$WEB_SET = $nio->webBasicSetAttr($web_id);//找網站基本資料

$session = new sessionC($web_id);

is_loginFirst($web_id);//檢查是否需要登入才能觀看
$nio->logVisitStats($web_id,$session->login_user_id,'n');		//記錄訪客行蹤

//找版型
$arr = $templ->getUserStorageSet(intval($web_id));
if($arr){
	$block_html =  $templ->blockIdArray2Html( $arr['block_set'],intval($web_id)) ;
	if(is_array($block_html) && count($block_html)>0){
		$menu_id = 0;
		$menu_str_len = 0;
		foreach($block_html as $k=>$v){
			if($v['function']=='MENU'){
				if($menu_id==0){
					$menu_id = $k;
					$menu_str_len = strlen($v['content']);
				}else{
					$test_len = strlen($v['content']);
					if( $test_len > $menu_str_len){
						$menu_id = $k;
						$menu_str_len = $test_len;
					}
				}
			}
		}
		if($menu_id > 0){
			$menu_data = $templ->MenuBlock2Array($web_id,$menu_id);
			$smarty->assign('http',($nio::http()));
			$smarty->assign('MENU_DATA',$menu_data);
			$smarty->assign('DOMAIN',$domain);
			$smarty->display('sitemap.tpl');
			die;
		}
	}
}
//找不到版型
header("HTTP/1.0 404 Not Found");
header("Location: http://$domain/404.php"); 
exit;
?>