<?php 
require "../Run.php";
$css = '<style>table.bdurl{border:1px solid #efefef;width:100%;font-size:16px;}
.bdurl tr td input.submit{background:#fff;border-left:1px solid #efefef}
.bdurl input{border:none;font-size:16px;width:100%;}
.bdurl tr td.text{font-size:16px;width:80px;text-align:center;}</style>'.$css;
echo head('网站域名绑定系统').'<body>'.UBB($wap_top,$wapid);
if($admin == 1||$admin == 2){
if($_GET['act'] == 'add'){
if($_POST['url'] == NULL||$_POST['url']==''){
	echo '<div class="tip">不能绑定空域名</div>';
}else{
    $sql="SELECT url FROM urlzf WHERE url='{$_POST['url']}'";
	$logininfo=mysql_query($sql);
    if($logininfo && mysql_num_rows($logininfo)>0){
	echo '<div class="tip">域名已经被绑定，请绑定其他域名！ </div>';
	}else{
		if(stristr($_POST['url'],sys_config('zj_url')) == sys_config('zj_url') && $admin !=1 ){
			echo '<div class="tip">普通不得擅自绑定系统域名（超级管理员例外）！</div>';
		}else{
	    $sql = "INSERT INTO urlzf(siteid,url,ps,zhuanfa,go_url) VALUES ('{$wapid}','{$_POST['url']}', 'user','NO','NULL')";
        $url = mysql_query($sql);	
	    if($url && mysql_affected_rows()>0){
			echo '域名绑定成功';
	    }else{
			echo '域名绑定失败';
				}
			}
		}
	}
}
if($_GET['act'] == 'del'){
	mysql_query("DELETE FROM urlzf WHERE url='{$_GET['host']}' AND siteid='{$wapid}'");
}
	echo '<div class="title">绑定域名</div>'; 
	echo '<div class="content"><form action="?act=add" method="post"><table class="bdurl"><tr><td class="text">
	http://</td><td><input style="float:left" type ="text" name="url" value="baidu.com"></td><td width="80"><input type="submit" value="绑定域名" class="submit">
	</td></tr></table></form></div>';
	echo '<div class="tip">绑定说明:绑定域名请解析至本站IP地址<b>'.GetHostByName($_SERVER['SERVER_NAME']).'</b>，为确保您的域名不被其他子站抢先绑定，请您在域名解析之前提前在本页绑定。请不要绑定未注册的系统域名！</div>'; 
	echo '<div class="title">已绑定域名</div>'; 
  $sql="SELECT id,siteid,url,ps,zhuanfa,go_url FROM urlzf WHERE siteid='{$wapid}'";
  $result=mysql_query($sql);
  if($result && mysql_num_rows($result)>0){
	$num=0;
	while(list($id,$siteid,$url,$ps,$zhuanfa,$go_url)=mysql_fetch_row($result)){
	   $div = $num++%2 == 0?'line1':'line2';
	   if($ps == 'system'){
	   	    echo '<div class="'.$div.'">'.$url.'<a href="http://'.$url.'">立刻访问</a>[系统域名]</div>';
		}else{
			echo '<div class="'.$div.'">'.$url.'<a href="http://'.$url.'">立刻访问</a>|<a href="?act=del&host='.$url.'">解除绑定</a></div>';
			}
		}
	}else{
		echo '没有绑定任何域名';
	}
	}else{
echo '<div class="tip">抱歉，您的权限不足</div>';
	}
	echo '<div class="mylink"><a href="http://'.HTTP_HOST.'/admin/wap_admin.php?">返回上级</a><a href="http://'.HTTP_HOST.'/index.php?">网站首页</a></div>';
echo UBB($wap_bottom,$wapid).'</body></html>';
?>