<?php
include("require.php");
if(isset($_COOKIE["core_user_name"]))
  jump("user.php?action=basic");
if($core_useropen==0)
  jump("error.php?id=12");
if (isset($_GET['action']) and $_GET['action']=="usercode")
{
  if($_POST['email']=="" or !ereg("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$",$_POST['email']))
    die("3");
  $phpcolor->table="user_code";
  $phpcolor->field="code";
  $phpcolor->where="email = '".$_POST['email']."' and state='1'";
  if($usercode=$phpcolor->exist(1))
  {
	$zt="感谢您选择注册".$core_barname;
	$nr="您好，感谢您选择注册".$core_barname."，您的邮箱认证码为：".$usercode['code']."。（本消息为系统自动发送，请勿回复，如有疑问请到".$core_bartype."帮助吧咨询）";
    $smtp = new smtp($core_stmpserver,$core_stmpport,true,$core_stmpacc,$core_stmppwd);
    $smtp->debug =  false;
    $smtp->sendmail($_POST['email'], $core_stmpmail, $zt, $nr, 'HTML');
    die("1");
  }
  $phpcolor->where="email = '".$_POST['email']."'";
  if($phpcolor->exist(1))
    die("2");
  else
  {
	$time=date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+$core_time*3600);
    $rscode = (time()+$core_time*3600).rand(1000,9999);
	$usercode=md5($rscode);
	$phpcolor->table="user_code";
	$phpcolor->field="email, code, time, state";
    $phpcolor->where="'".$_POST['email']."', '".$usercode."', '".$time."', '1'";
    $phpcolor->write();
    $zt="感谢您选择注册".$core_barname;
	$nr="您好，感谢您选择注册".$core_barname."，您的邮箱认证码为：".$usercode."。（本消息为系统自动发送，请勿回复，如有疑问请到".$core_bartype."帮助吧咨询）";
    $smtp = new smtp($core_stmpserver,$core_stmpport,true,$core_stmpacc,$core_stmppwd);
    $smtp->debug =  false;
    $smtp->sendmail($_POST['email'], $core_stmpmail, $zt, $nr, 'HTML');
    die("1");
  }
}
elseif (isset($_GET['reg']) and $_GET['reg']=="submit")
{
  $_POST['username']=mb_convert_encoding($_POST['username'], "gbk", "UTF-8");
  $_POST['question']=iconv("UTF-8", "gbk", $_POST['question']);
  $_POST['answer']=iconv("UTF-8", "gbk", $_POST['answer']);
  //禁用词语
  $phpcolor->table="filter";
  $phpcolor->field="content";
  $phpcolor->where="type='1' and (fanwei='0' or fanwei='3')";
  $rs=$phpcolor->assignment();
  for ($count=0;$count<count($rs);$count++)
  {
    if(strpos($_POST['username'],$rs[$count]['content']))
      die("10");
  }
  //审核词语
  $phpcolor->where="type='3' and (fanwei='0' or fanwei='3')";
  $rs=$phpcolor->assignment();
  for ($count=0;$count<count($rs);$count++)
  {
    if(strpos($_POST['username'],$rs[$count]['content']))
      $core_useraudit="1";
  }
  $phpcolor->table="user";
  $phpcolor->field="*";
  $phpcolor->where="username = '".$_POST['username']."'";
  if(preg_match("/[ '.,:;*?~`!@#$%^&+=)(<>{}]|\]|\[|\/|\\\|\"|\|/",$_POST['username']))
    die("10");
  if($_POST['question']=="" or $_POST['answer']=="")
    die("1");
  if (strlen($_POST['username'])<$core_usershort or strlen($_POST['username'])>$core_userlong)
    die("2");
  if ($phpcolor->exist(1))
    die("3");
  if (strlen($_POST['passwd'])<$core_pwdshort or strlen($_POST['passwd'])>$core_pwdlong)
    die("4");
  if ($_POST['passwd']!= $_POST['passwdy'])
    die("5");
  if(!ereg("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$",$_POST['email']))
    die("6");
  if($core_vreg==1 && $_POST['verify'] != $_SESSION['auth'])
    die("7");
  $phpcolor->table="user_code";
  $phpcolor->field="code";
  $phpcolor->where="email = '".$_POST['email']."' and state='1'";
  if($core_usercode==1 && !$usercode=$phpcolor->exist(1))
    die("11");
  if($core_usercode==1 && $_POST['usercode'] != $usercode['code'])
    die("12");
  //整合UC
  if ($uc_open=="1")
  {
	$phpcolor->close();
    $uc = new mysql();
    $uc->open($uc_dbhost,$uc_dbuser,$uc_dbpw,$uc_dbname);
	$uc->table="members";
	$uc->field="*";
    $uc->where="username = '".$_POST['username']."'";
    if($phpcolor->exist(1))
	  die("3");
	$salt=rand(100000,999999);
    $ucpasswd=md5(md5($_POST['passwd']).$salt);
    $time=strtotime(date('Y-m-d H:i:s'))+$core_time*60*60;
    $uc->field="username, password, email, regip, regdate, salt";
    $uc->where="'".$_POST['username']."', '".$ucpasswd."', '".$_POST['email']."', '".$_SERVER['REMOTE_ADDR']."', '".$time."', '".$salt."'";
    $uc->write();
    $uc->table="memberfields";
    $uc->field="blacklist";
    $uc->where="''";
    $uc->write();
	$uc->close();
	$phpcolor->open();
  }
  $time=date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+$core_time*3600);
  if(isset($_COOKIE['spreadid']) && isset($_COOKIE['spreadcode']) && isset($_COOKIE['spreadname']) &&  $int_uspread!="0")
  {
    $timers=strtotime(date('Y-m-d H:i:s'))+$core_time*3600-3600*24;
    $timers=date('Y-m-d H:i:s',$timers);
    $phpcolor->table="spread";
    $phpcolor->field="*";
    $phpcolor->where="uid = '".$_COOKIE['spreadid']."' and spreadcode = '".$_COOKIE['spreadcode']."' and time>'".$timers."' and type='1'";
    $yz1=$phpcolor->exist(2);
    $phpcolor->where="uid = '".$_COOKIE['spreadid']."' and spreadcode = '".$_COOKIE['spreadcode']."' and info='推广注册'";
    $yz2=$phpcolor->exist(2);
    $macrs=new GetMacAddr(PHP_OS);
    $mac=$macrs->mac_addr;
    if($mac=="")
      $mac="无法获取";
    if($yz1 && !$yz2)
    {
      if($int_uspreadfr>0)
	    $phpcolor->upintegral($_COOKIE['spreadname'],$_POST['username'],$int_uspreadfr,7,$time);
      $phpcolor->table="spread";
      $phpcolor->field="info ,uid, ip, mac, spreadcode, time, type";
      $phpcolor->where="'推广注册','".$_COOKIE['spreadid']."','".$_SERVER['REMOTE_ADDR']."','".$mac."','".$_COOKIE['spreadcode']."','".$time."', '1'";
      $phpcolor->write();
	}
	else
	{
	  $phpcolor->table="spread";
      $phpcolor->field="info ,uid, ip, mac, spreadcode, time, type";
      $phpcolor->where="'推广注册','".$_COOKIE['spreadid']."','".$_SERVER['REMOTE_ADDR']."','".$mac."','".$_COOKIE['spreadcode']."','".$time."', '2'";
      $phpcolor->write();
	}
  }
  $state=1;
  if($core_useraudit=="1")
    $state=3;
  $user_reg_passwd = md5($_POST['passwd']);
  $phpcolor->table="user";
  $phpcolor->field="username, passwd, email, question, answer, registered, logintime, loginip, state";
  $phpcolor->where="'".$_POST['username']."', '".$user_reg_passwd."', '".$_POST['email']."', '".$_POST['question']."', '".$_POST['answer']."', '".$time."', '".$time."', '".$_SERVER['REMOTE_ADDR']."', '".$state."'";
  $phpcolor->write();
  if($core_usercode==1)
  {
    $userid=mysql_insert_id();
	$phpcolor->table="user_code";
    $phpcolor->where="email = '".$_POST['email']."'";
    $phpcolor->field="uid='".$userid."',state='2'";
    $phpcolor->upgrade();
  }
  if($core_useraudit=="0")
  {
    setcookie("core_user_name", $_POST['username'], time()+$core_time*3600+3600);
    setcookie("core_user_passwd", md5($user_reg_passwd.$core_scode), time()+$core_time*3600+3600);
    setcookie("core_user_rank", "0", time()+$core_time*3600+3600);
	setcookie("core_user_long", "0", time()+$core_time*3600+3600);
    die("8");
  }
  die("9");
}
$tpl->assign("core_usercode", $core_usercode);
$tpl->assign("core_vreg", $core_vreg);
$tpl->assign("core_usershort", $core_usershort);
$tpl->assign("core_userlong", $core_userlong);
$tpl->assign("core_pwdshort", $core_pwdshort);
$tpl->assign("core_pwdlong", $core_pwdlong);
$tpl -> assign("core_header_title", "注册 - ");
$tpl -> display("$core_style/reg.htm");
?>
