<?
include_once("inc/config.php");
include_once("inc/ftbbsdbclass.php");
include_once("inc/publicfun.php");
include_once("conn.php");
include_once("ftbbs_nav.php");

$query = "SELECT * FROM {$tablepre}ftbbsmb";
$ftbbsmb=makecache('ftbbsmb.html',$query,$expire);

$name=ftbbs_request(trim($_POST["username"]));
$password=md5(trim($_POST["password"]));
$sex=$_POST["sex"];
$email=ftbbs_request(trim($_POST["email"]));
$codestr=trim($_POST["codestr"]);
$question=trim($_POST["question"]);
$answer=md5(trim($_POST["answer"]));
$now=date("Y-m-d H:i:s");
$ip=GetUserIP(); 
$clubuser_province=trim($_POST["province"]);
$clubuser_city=trim($_POST["city"]);
if ($clubuser_city==""){
$clubuser_city="特区";
}

if ($sex=="男"){
   $userimg="cache5.gif";
   }
else{
   $userimg="cache41.gif"; 
}

$getcodeoff=$ftbbsmb[30];
$regoff=$ftbbsmb[17];
$usernamelng=$ftbbsmb[22];
$pswlng=$ftbbsmb[23];

$jmailoff=$ftbbsmb[24];
$mailuser=$ftbbsmb[25];
$mailpwd=$ftbbsmb[26];
$mailaddress=$ftbbsmb[27];
$mailsmtp=$ftbbsmb[28];

$url=$ftbbsmb[10];
$uploadoff=$ftbbsmb[16];
$regsmstitle=$ftbbsmb[20];
$regsmscontent=$ftbbsmb[21];
$defaulthome=$ftbbsmb[31];
include_once("homeurl.php");

$name = str_replace(' ', '',$name);
$name = preg_replace('/\<(.+?)\>/is', '',$name);

if (CheckName($name)==false){
   ftbbs_msg("用户名不合法!","register.php");
   exit;
}
If ($getcodeoff==1&&$_SESSION["code"]!=$codestr){
   ftbbs_msg("验证码错误!","register.php");
   exit;
}

$sql="select * from {$tablepre}clubuser where clubuser_name='".$name."'";
$rs=mysql_query($sql);
$row = mysql_fetch_array($rs);
$rsnum= mysql_num_rows($rs);
if ($rsnum!=0){
   echo "<script language=\"javascript\">alert(\"该用户已经有人使用，请重新注册!\");window.location=\"register.php\";</script>";
   exit;
}
else{
$strsql="insert into {$tablepre}clubuser(clubuser_name,clubuser_nickname,clubuser_password,clubuser_question,clubuser_answer,clubuser_sex,clubuser_email,clubuser_reg_date,clubuser_lasttime,clubuser_enter_count,clubuser_ip,clubuser_province,clubuser_city,payuser,userimg,jfmsign,jingyuan,tili) values('$name','$name','$password','$question','$answer','$sex','$email','$now','$now',0,'$ip','$clubuser_province','$clubuser_city',0,'$userimg',0,0,100)";
mysql_query($strsql);
$clubuser_id=mysql_insert_id();
//设置cookies
set_cookie('clubuser_id', $clubuser_id, 3600);
set_cookie('username', $name, 3600);
set_cookie('clubuser_password', base64_encode($password), 3600);
//set_cookie('clubuser_password', base64_encode(md5($password)), 3600);

set_cookie('bbsuser', $bbsuser, 3600);
set_cookie('bz', 0, 3600);
set_cookie('bbsadmin', 0, 3600);
set_cookie('payuser', $uploadoff, 3600);
//set_cookie('bokeer', 0, 3600);

$msginfo=$regsmstitle;
$sign=1;
$smscontent=$regsmscontent;
}
mysql_query("insert into {$tablepre}sms(title,content,accepter,bbssystem,indate,IsNew) values('$msginfo','$smscontent','$name',2,'".$getnow."',1)");
session_destroy();//删除保存session的文件
mysql_free_result($rs);

if ($jmailoff==1){
require ("mailclass.php");
$smtpserver = $mailsmtp;//SMTP服务器
$smtpserverport =25;//SMTP服务器端口
$smtpusermail = $mailaddress;//SMTP服务器的用户邮箱
$smtpuser = $mailuser;//SMTP服务器的用户帐号
$smtppass = $mailpwd;//SMTP服务器的用户密码
$smtpemailto = $email;//发送给谁
$mailsubject = $msginfo;//邮件主题
$mailbody = $smscontent;//邮件内容
$mailtype = "TXT";//邮件格式（HTML/TXT）,TXT为文本邮件
$smtp = new smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);//这里面的一个true是表示使用身份验证,否则不使用身份验证.
$smtp->sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, $mailtype);
}

$db->close(); 
//$regurl="default.php";
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?if ($sign==1){?>
<meta http-equiv="refresh" content="3;URL=<?=$homepage?>">
<?}?>
<BR><BR><BR>
<TABLE border=0 align=center>
<TR>
	<TD align=center>
	<?=$msginfo?><BR><BR>
	<?if ($sign==0){?>
	<A HREF="javascript:window.history.back()">[重新注册]</A>
	<?}else{?>
	系统将在3秒钟后自动返回，您也可以直接手工点击<A HREF="<?=$regurl?>"><FONT  COLOR="blue">[返回首页]</FONT></A><BR>
	<?}?>
	</TD>
</TR>
</TABLE>
</body>
</html>