<?php
session_start();
include_once '../../common.php';
include_once '../../conn.php';
if($dailiid == "admin") {
	echo  $dailiid="";
}
if(!isset($_SESSION['username'])) {
	echo "<script>alert('身份已失效请重新登录!')</script><script>location.href='index.php'</script>";
	exit;
}
$username=ubo($_SESSION['username']);
if($_POST) {
	$uid=ubo(iconv("UTF-8","GB2312",$_POST['uid']));
	$ma=ubo(iconv("UTF-8","GB2312",$_POST['ma']));
	date_default_timezone_set('PRC');
	if($uid==null) {
		$msg=iconv("GB2312","UTF-8","uid不能为空");
		$json_data = array ('zt'=>"0",'msg'=>$msg);
		echo json_encode($json_data);
	} else if($ma==null) {
		$msg=iconv("GB2312","UTF-8","代理码不能为空");
		$json_data = array ('zt'=>"0",'msg'=>$msg);
		echo json_encode($json_data);
	} else {
		$type="WHERE uid='$uid'";
		$row=queryall(user,$type);
		if($row) {
			$msg=iconv("GB2312","UTF-8","绑定失败！该uid已绑定其他代理码！");
			$json_data = array ('zt'=>"0",'msg'=>$msg);
			echo json_encode($json_data);
		} else {
			$row=queryall(zhucema,"where ma='".$ma."'");
			if($row) {
				$uid=(int)$uid;
				$type="(`uid`, `recommend`, `bindtime`, `welfare`, `account`, `ip`) VALUES ('$uid','$ma','".date("Y-m-d H:i:s",time())."', 0,null,null)";
				dbinsert(user,$type);
				echo json_encode(array('zt'=>"1"));
			} else {
				$msg=iconv("GB2312","UTF-8","绑定失败！该代理码不存在！");
				$json_data = array ('zt'=>"0",'msg'=>$msg);
		        echo json_encode($json_data);
			}
		}
	}
} else {
	$msg=iconv("GB2312","UTF-8","参数错误");
	$json_data = array ('zt'=>"0",'msg'=>$msg);
	echo json_encode($json_data);
}
?>