<?php
!function_exists('html') && exit('ERR');
if($job=='set')
{
	if($webdb[cnzz_pwd]=='no'){
		$display='';
		$webdb[cnzz_pwd]='';
	}else{
		$display='none;';
	}
	$cnzz_open[intval($webdb[cnzz_open])]=' checked ';
	require(dirname(__FILE__)."/"."head.php");
	require(dirname(__FILE__)."/"."template/cnzz/menu.htm");
	require(dirname(__FILE__)."/"."template/cnzz/set.htm");
	require(dirname(__FILE__)."/"."foot.php");
}
elseif($action=='set')
{
	if($webdbs[cnzz_open]&&!$webdbs[cnzz_id]){
		showmsg("統計帳號不存在");
	}
	write_config_cache($webdbs);
	jump("修改succeed",$FROMURL,1);
}
elseif($job=='ask')
{
	if($webdb[cnzz_id]&&$webdb[cnzz_pwd]){
		echo "<META HTTP-EQUIV=REFRESH CONTENT='0;URL=index.php?lfj=cnzz&job=set'>";
		exit;
	}
	$mydomain=preg_replace("/http:\/\/([^\/]+)\/(.*)/is","\\1",$WEBURL);
	require(dirname(__FILE__)."/"."head.php");
	require(dirname(__FILE__)."/"."template/cnzz/menu.htm");
	require(dirname(__FILE__)."/"."template/cnzz/ask.htm");
	require(dirname(__FILE__)."/"."foot.php");
}
elseif($action=='ask')
{
	if(!$mydomain)
	{
		showmsg("域名不能為空");
	}
	$key = md5("{$mydomain}A4bkJUxm");
	$url="http://intf.cnzz.com/user/companion/php168.php?domain=$mydomain&key=$key";
	if( ini_get('allow_url_fopen') && $code=file_get_contents($url) )
	{
	}
	elseif( $code=sockOpenUrl($url) )
	{
	}
	
	if(!strstr($code,'@'))
	{
		echo '<meta http-equiv="Content-Type" content="text/html; charset=big5">';
		if($code=='-1'){
			die("KEY值有誤");
		}elseif($code=='-2'){
			die("域名長度有誤（1~64）");
		}elseif($code=='-3'){
			die("域名輸入有誤");
		}elseif($code=='-4'){
			die("域名插入數據庫有誤");
		}elseif($code=='-5'){
			echo("同一個IP,用戶申請次數過多<hr>");
		}else{
			echo $code;
		}
		$webdbs[cnzz_pwd]='no';
		write_config_cache($webdbs);
		echo "<A HREF='$url'>你的服務器不支持遠程獲取數據,請點擊手工獲取數據,然後把頁面顯示的結果復制出來,在<統計帳號管理>那手工輸入,@前面的數字是統計代碼的帳號,@後面部份的數字是統計代碼的管理密碼,點擊獲取資料</A>";
		exit;
	}
	list($webdbs[cnzz_id],$webdbs[cnzz_pwd])=explode("@",$code);

	write_config_cache($webdbs);
	jump("恭喜你,統計帳號申請succeed","index.php?lfj=cnzz&job=set",2);
}

?>