<?php
$conf_basedir	= "../../";	//相对主目录的位置
$conf_where		= "admin";	//选择调用相应模块
$directory		= basename(dirname(__FILE__));	//定义当前所在的目录，引入模块公用函数
include_once($conf_basedir."base.inc.php");
checkAuth('102');	//判断登录和权限

error_reporting(7);
ini_set("display_errors",true);

/*if($conf_cityflag == 'nj'){
	include(CORE_LIB."/rewrite_nj/UriRewrite.class.php");
}else if($conf_cityflag == 'wh'){
	include(CORE_LIB."/rewrite_wh/UriRewrite.class.php");
}else{
	include(CORE_LIB."/rewrite/UriRewrite.class.php");
}
getShopAnalyUrlCommSunsB("new_agent_shop_page",array('uid'=>123));
*/

//$domain_url = FRAME_URL; //域名地址
$domain_url_sell  = "http://".$conf_cityflag.".sell.house365.com/";
$domain_url_rent  = "http://".$conf_cityflag.".rent.house365.com/";
$memkey = $conf_cityflag."_sitemap_update_info_esfadmin";
if($action == 'insert') {
	$site_num = intval($site_num);
	$now_time = time();
	$lastmod = date("Y-m-d",$now_time);
	if($site_num <10000 || $site_num > 50000){
		$site_num = 10000;
	}
	
	$index_i = 0;
	$data_child = array();
	$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com";
	$data_child_rents[$index_i++]['loc'] = "http://".$conf_cityflag.".rent.house365.com";

	if(in_array($conf_cityflag,array('nj'))){
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news.php";
	}

	if(in_array($conf_cityflag,array('nj','hf','wx','cz','xa'))){
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/agent/";
	}
	$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/agent/list.html";

	if(in_array($conf_cityflag,array('nj'))){
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/ask";
	}

	/* http://{city}.sell.house365.com/district_d*-s* / */
	$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/district/";
	$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/district_i1/";
	
	foreach($uri_district_asc as $v){
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/district_d".$v."/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/district_d".$v."-i1/";
	}
	$streetlist = get_street_list_ts();
	foreach($streetlist as $v){
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/district_d".$uri_district_asc[$v['district']]."-s".$v['id']."/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/district_d".$uri_district_asc[$v['district']]."-s".$v['id']."-i1/";
	}
	/* END */
	
	/* http://{city}.sell.house365.com/subway_d*-s* / */
	if(in_array($conf_cityflag,array('nj','hf','sz','wx','hz'))){
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/subway/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/subway_i1/";

		$arr_railway = get_subway_list_ts();
		foreach($arr_railway as $key => $val){
			foreach($val as $v){
				$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/subway_d".$key."-s".$v."/";
				$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/subway_d".$key."-s".$v."-i1/";
			}
		}
	}
	/* END */

	/* http://{city}.sell.house365.com/brt_d*-s* / */
	if(in_array($conf_cityflag,array('cz'))){
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/brt/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/brt_i1/";

		$arr_railway_brt = get_brt_list_ts();
		foreach($arr_railway_brt as $key => $val){
			foreach($val as $v){
				$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/brt_d".$key."-s".$v."/";
				$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/brt_d".$key."-s".$v."-i1/";
			}
		}
	}
	/* END */

	/* 按学校搜索及详细页 */
	if(in_array($conf_cityflag,array('sz','wx','hz','cz'))){
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/school/";
		$school_list = get_school_list_ts();
		if(!in_array($conf_cityflag,array('sz'))){
			foreach($school_list as $k => $v){
				$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/school_id".$v['id']."/";
			}
		}else{
			foreach($school_list as $k => $v){
				$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/school_sh".$v['id']."/";
			}
		}
	}
	/* END */

	/* http://{city}.rent.house365.com/district_d*-s* / */
	$data_child_rents[$index_i++]['loc'] = "http://".$conf_cityflag.".rent.house365.com/district/";
	$data_child_rents[$index_i++]['loc'] = "http://".$conf_cityflag.".rent.house365.com/district_i1/";
	
	foreach($uri_district_asc as $v){
		$data_child_rents[$index_i++]['loc'] = "http://".$conf_cityflag.".rent.house365.com/district_d".$v."/";
		$data_child_rents[$index_i++]['loc'] = "http://".$conf_cityflag.".rent.house365.com/district_d".$v."-i1/";
	}
	$streetlist = get_street_list_ts();
	foreach($streetlist as $v){
		$data_child_rents[$index_i++]['loc'] = "http://".$conf_cityflag.".rent.house365.com/district_d".$uri_district_asc[$v['district']]."-s".$v['id']."/";
		$data_child_rents[$index_i++]['loc'] = "http://".$conf_cityflag.".rent.house365.com/district_d".$uri_district_asc[$v['district']]."-s".$v['id']."-i1/";
	}
	/* END */

	
	/* http://{city}.rent.house365.com/subway_d*-s* / */
	if(in_array($conf_cityflag,array('nj','hf','sz','wx','hz'))){
		$data_child_rents[$index_i++]['loc'] = "http://".$conf_cityflag.".rent.house365.com/subway/";
		$data_child_rents[$index_i++]['loc'] = "http://".$conf_cityflag.".rent.house365.com/subway_i1/";

		$arr_railway = get_subway_list_ts();
		foreach($arr_railway as $key => $val){
			foreach($val as $v){
				$data_child_rents[$index_i++]['loc'] = "http://".$conf_cityflag.".rent.house365.com/subway_d".$key."-s".$v."/";
				$data_child_rents[$index_i++]['loc'] = "http://".$conf_cityflag.".rent.house365.com/subway_d".$key."-s".$v."-i1/";
			}
		}
	}
	/* END */
	
	$data_child_rents[$index_i++]['loc'] = "http://".$conf_cityflag.".rent.house365.com/bus/";
	$data_child_rents[$index_i++]['loc'] = "http://".$conf_cityflag.".rent.house365.com/bus_i1/";

	/* 租赁方式 */
	foreach($uri_renttype as $k => $v){
		$data_child_rents[$index_i++]['loc'] = "http://".$conf_cityflag.".rent.house365.com/district/dl_r".$k.".html";
	}
	/* END */

	/* 小区 */
	$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/community/";
	
	foreach($uri_district_asc as $v){
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/community_d".$v."/";
	}

	$streetlist = get_street_list_ts();
	foreach($streetlist as $v){
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/community_d".$uri_district_asc[$v['district']]."-s".$v['id']."/";
		
	}

	$community_list = get_community_list_ts();
	foreach($community_list as $v){
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/community_id".$v['id']."/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/community_id".$v['id']."/sell.html";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/community_id".$v['id']."/rent.html";
	}
	/* END */
    
	/******************************************/

	/* 经纪人 */
	$broker_list = get_broker_list_ts();
	foreach($broker_list as $v){
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/agent_bk".$v['uid']."/";
	}
	/* END */

	/* 问答 */
	if(in_array($conf_cityflag,array('nj'))){
		$question_list = get_question_list_ts();
		foreach($question_list as $v){
			$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/ask_".intval($v['q_id']).".html";
		}
	}
	/* END */

	/* 资讯频道 */
	if(in_array($conf_cityflag,array('nj'))){
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esfpd/esfyw/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esfpd/esfbb/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esfpd/esfrdzt/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esfpd/esfdg/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esfpd/esfxqpc/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esfpd/esftpzx/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/project/gfbk/gfcx.php";
	}else if(in_array($conf_cityflag,array('hf'))){
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esfpd/esfyw/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esfpd/esfhq/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esfpd/esfzt/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esfpd/esfdg/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esfpd/esfxqpc/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esfpd/esftpzx/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/project/hf/bk/gfcx.php";
	}else if(in_array($conf_cityflag,array('sz'))){
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esfpd/esfyw/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esfpd/esfschq/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esfpd/esfzt/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esfpd/esfdg/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esfpd/esfxqpc/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esfpd/esftpzx/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/project/sz/bk/gfcx.php";
	}else if(in_array($conf_cityflag,array('wx'))){
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esf/esfyw/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esf/esfyb/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esf/esfzt/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esf/esfdg/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esf/esfxqpc/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esf/esftpzx/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/project/wx/bk/gfcx.php";
	}else if(in_array($conf_cityflag,array('hz'))){
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esf/esfyw/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esf/esfhqbb/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esf/esfjczt/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esf/esfdg/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esf/esfxqpc/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esf/esftpzx/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/project/hz/bk/gfcx.php";
	}else if(in_array($conf_cityflag,array('cz'))){
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esfpd/esfyw/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esfpd/esfhq/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esfpd/esfzt/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esfpd/esfdg/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esfpd/esfxqpc/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esfpd/esftpzx/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/project/cz/bk/gfcx.php";
	}else if(in_array($conf_cityflag,array('xa'))){
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esf/esfyw/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esf/mrhq/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esf/esfzt/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esf/esfdg/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esf/esfxqpc/";
		$data_child[$index_i++]['loc'] = "http://".$conf_cityflag.".sell.house365.com/news/esf/esftpzx/";
	}
	/* END */
	
	$save_path = $conf_basedir."sitemap/".$conf_cityflag."/sell/";
	$data_index = create_sitemap_child_ts($data_child, $site_num, $lastmod, $save_path);
	foreach($data_index as $k => $v){
		$data_index[$k] = $domain_url_sell."sitemap/".$conf_cityflag."/sell/".$v;
	}
	create_sitemap_index_ts($data_index, $lastmod, $save_path.'sitemap.xml');

	$save_path_rents = $conf_basedir."sitemap/".$conf_cityflag."/rent/";
	$data_index_rents = create_sitemap_child_ts($data_child_rents, $site_num, $lastmod, $save_path_rents);
	foreach($data_index_rents as $k => $v){
		$data_index_rents[$k] = $domain_url_rent."sitemap/".$conf_cityflag."/rent/".$v;
	}
	create_sitemap_index_ts($data_index_rents, $lastmod, $save_path_rents.'sitemap.xml');

	$mc->delete($memkey);
	$mc->add($memkey, array('isok'=>1,'last_time'=>$lastmod,'site_num'=>$site_num),false,0);
	echo "<script>alert('操作成功！');location.href='/module/sitemap/sitemap.php';</script>";

}else{

	$css="<link href='http://esfadmin.house365.com/script/css/autocomplete.css' rel='stylesheet' type='text/css' />";
	$js = "<script type='text/javascript' src='http://esfadmin.house365.com/script/js/showpic.js'></script>
	<script type='text/javascript' src='http://esfadmin.house365.com/script/js/public.js'></script>
	<script type='text/javascript' src='http://esfadmin.house365.com/script/js/formValidator.js'></script>
	<script type='text/javascript' src='http://esfadmin.house365.com/script/js/jquery_ui_autocomplete/ui/jquery.ui.core.js'></script>
	<script type='text/javascript' src='http://esfadmin.house365.com/script/js/jquery_ui_autocomplete/ui/jquery.ui.position.js'></script>
	<script type='text/javascript' src='http://esfadmin.house365.com/script/js/jquery_ui_autocomplete/ui/jquery.ui.widget.js'></script>
	<script type='text/javascript' src='http://esfadmin.house365.com/script/js/jquery_ui_autocomplete/ui/jquery.ui.autocomplete.js'></script>";

	$cache = $mc->get($memkey);
	if($cache['isok'] == 1)
	{
		$last_time = $cache['last_time'];
		$site_num  = $cache['site_num'];      //$mc->add($memkey, array('isok'=>1), false, 0);
	}
	else
	{
		$last_time = '暂无更新';
		$site_num = 10000;      
	}
	$now_time = date('Y-m-d',time());
	$address_xml_sell = $domain_url_sell."sitemap/".$conf_cityflag."/sell/sitemap.xml";
	$address_xml_rent = $domain_url_rent."sitemap/".$conf_cityflag."/rent/sitemap.xml";

	//$filexml = fopen($conf_basedir."sitemap/".$conf_cityflag."/sitemap.xml", "w"); 

	include_once(Template("header"));
	include_once(Template("sitemap/sitemap"));
	include_once(Template("footer"));
}
?>