<?php
include("require.php");
if(isset($_COOKIE["core_user_name"]))
  Header("Location: user.php?action=basic");
elseif($core_useropen==0)
  Header("Location: error.php?id=12");
elseif (isset($_GET['reg']) and $_GET['reg']=="submit")
{
  $_POST['username']=submitfilter(2,$_POST['username']);
  $_POST['email']=submitfilter(2,$_POST['email']);
  $_POST['safemail']=submitfilter(2,$_POST['safemail']);
  $_POST['question']=submitfilter(2,$_POST['question']);
  $_POST['answer']=submitfilter(2,$_POST['answer']);
  $phpcolor->table=$core_mysql_prefix."user";
  $phpcolor->field="*";
  $phpcolor->where="username = '".$_POST['username']."'";
  if(($core_filteruser!="" && eregi($core_filteruser,$_POST['username'])) || preg_match("/[ '.,:;*?~`!@#$%^&+=)(<>{}]|\]|\[|\/|\\\|\"|\|/",$_POST['username']))
    die("0");
  elseif($_POST['question']=="" or $_POST['answer']=="")
    die("1");
  elseif (strlen($_POST['username'])<$core_usershort or strlen($_POST['username'])>$core_userlong)
    die("2");
  elseif ($phpcolor->exist(1))
    die("3");
  elseif (strlen($_POST['passwd'])<$core_pwdshort or strlen($_POST['passwd'])>$core_pwdlong)
    die("4");
  elseif ($_POST['passwd']!= $_POST['passwdy'])
    die("5");
  elseif(!ereg("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$",$_POST['email']) or !ereg("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$",$_POST['safemail']))
    die("6");
  elseif($core_verifyopen==1 && $_POST['verify'] != $_SESSION['auth'])
    die("7");
  else
  {
    $state=1;
	if($core_useraudit=="1")
	  $state=3;
    $user_reg_passwd = md5($_POST['passwd']);
    $time=date('Y-m-d H:i:s',strtotime(date('Y-m-d H:i:s'))+$core_time*60*60);
    $phpcolor->field="username, passwd, email, safemail, question, answer, registered, logintime, loginip, state";
    $phpcolor->where="'".$_POST['username']."', '".$user_reg_passwd."', '".$_POST['email']."', '".$_POST['safemail']."', '".$_POST['question']."', '".$_POST['answer']."', '".$time."', '".$time."', '".$_SERVER['REMOTE_ADDR']."', '".$state."'";
    $phpcolor->write();
	if($core_useraudit=="0")
	{
	  setcookie("core_user_name", $_POST['username'], time()+3600);
      setcookie("core_user_passwd", md5($user_reg_passwd.$core_scode), time()+3600);
	  setcookie("core_user_rank", "0", time()+3600);
      die("8");
	}
	else
	  die("9");
  }
}
else
{
  $tpl->assign("core_verifyopen", $core_verifyopen);
  $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");
}
?>
