
<?php
include_once("../config.php");

if(empty($_REQUEST["usernameR"])){exit();}
if(empty($_REQUEST["passwordR"])){exit();}
if(empty($_REQUEST["emailR"])){exit();}
if(empty($_REQUEST["sexR"])){exit();}

$usernameR = iconv("UTF-8","gbk",trim($_REQUEST["usernameR"]));
$passwordR = trim($_REQUEST["passwordR"]);
$emailR = trim($_REQUEST["emailR"]);
if($_REQUEST["sexR"]==1){$sex=1;}elseif($_REQUEST["sexR"]==11){$sex=0;}

	if(strstr($emailR,"@")&&strstr($emailR,".")){
	}else{
		$results[] = "<options>";
		$results[] = "<option><ReturnData>HH</ReturnData></option>";
		$results[] = "</options>";
		print implode("\n", $results);
		exit();
	}

	$con=mysql_connect(constant('UC_DBHOST'),constant('UC_DBUSER'),constant('UC_DBPW'));
	mysql_select_db(constant('UC_DBNAME'),$con);
	mysql_query("set names 'gbk'");

	$tablename1=constant('UC_DBTABLEPRE')."members";
	$tablename1=str_replace("`ushow`.",'',$tablename1);
	$result=mysql_query("select count(*) as hehe from $tablename1 where username='$usernameR'");
	$count=mysql_fetch_assoc($result);
	if($count[hehe]!=0){
		$results[] = "<options>";
		$results[] = "<option><ReturnData>UN</ReturnData></option>";
		$results[] = "</options>";
		print implode("\n", $results);
		exit();
	}
	$resultEmail=mysql_query("select count(*) as email from $tablename1 where email='$emailR'");
	$countEmail=mysql_fetch_assoc($resultEmail);
	if($countEmail[email]!=0){
		$results[] = "<options>";
		$results[] = "<option><ReturnData>EM</ReturnData></option>";
		$results[] = "</options>";
		print implode("\n", $results);
		exit();
	}
       
if($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"]){ 
$ip = $HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"]; 
}elseif($HTTP_SERVER_VARS["HTTP_CLIENT_IP"]){ 
$ip = $HTTP_SERVER_VARS["HTTP_CLIENT_IP"]; 
}elseif($HTTP_SERVER_VARS["REMOTE_ADDR"]){ 
$ip = $HTTP_SERVER_VARS["REMOTE_ADDR"]; 
}elseif(getenv("HTTP_X_FORWARDED_FOR")){ 
$ip = getenv("HTTP_X_FORWARDED_FOR"); 
}elseif(getenv("HTTP_CLIENT_IP")){ 
$ip = getenv("HTTP_CLIENT_IP"); 
}elseif(getenv("REMOTE_ADDR")){ 
$ip = getenv("REMOTE_ADDR"); 
}else{ 
$ip = "unknown"; 
} 

	$time=time();
	if($ip == "unknown"){$ipl=0;}else{$ipl=ip2long($ip);}
	$salt = substr(uniqid(rand()), 0, 6);
    $password1=md5(md5($passwordR).$salt);

	mysql_query("insert  into $tablename1 (username,password,email,regip,regdate,salt) values('$usernameR','$password1','$emailR','$ip',$time,'$salt')");
    $result2=mysql_query("select uid from $tablename1 where username='$usernameR'");
	$row=mysql_fetch_array($result2);//从uc取得uid

    $tablename2=$_SC['tablepre']."member";
	$password2=md5("$row[uid]|$time");
	$ss1 = mysql_query("insert  into $tablename2 (uid,username,password) values($row[uid],'$usernameR','$password2')");
	$rr1 = mysql_affected_rows();
    $tablename3=$_SC['tablepre']."space";
	$ss2 = mysql_query("insert  into $tablename3 (uid,groupid,credit,username,dateline,lastlogin,ip,regip) values($row[uid],5,10,'$usernameR',$time,$time,$ipl,$ipl)");
	$rr2 = mysql_affected_rows();
	$tablename4=$_SC['tablepre']."spacefield";
	$ss3 = mysql_query("insert  into $tablename4 (uid,sex,email) values($row[uid],$sex,'$emailR')");
	$rr3 = mysql_affected_rows();

    if($ss1&&$ss2&&$ss3){
			$results[] = "<options>";
			$results[] = "<option><ReturnData>OK</ReturnData></option>";
			$results[] = "</options>";
			print implode("\n", $results);
	}else{
			$results[] = "<options>";
			$results[] = "<option><ReturnData>WR</ReturnData></option>";
			$results[] = "</options>";
			if($rr1 != 1)
				mysql_query("delete from $tablename1 where username = '$usernameR'");
			if($rr2 != 1)
				mysql_query("delete from $tablename2 where username = '$usernameR'");
			if($rr3 != 1)
				mysql_query("delete from $tablename3 where username = '$usernameR'");
			print implode("\n", $results);
	}

	
?>