<?php
//-----------------------------------------------------------------------------
//    ID002同学录 单班级 (PHP & MySQL) 1.0 标准版
//-----------------------------------------------------------------------------
//    Copyright(C) aNErG, 2003. All rights reserved
//
//    技术支持 http://anerg.126.com
//-----------------------------------------------------------------------------
//    本软件对个人完全免费使用
//
//    如用于商业用途,您必须与我联系并支付RMB ￥20
//-----------------------------------------------------------------------------
include ('conn.php') ;
require('function.php');  ?>
<? if($HTTP_POST_VARS["username"]=="" || $HTTP_POST_VARS["userpwd"]=="" || $HTTP_POST_VARS["useremail"]=="" || !ereg("^[a-zA-Z0-9_\.]+\@([0-9A-Za-z][0-9A-Za-z-]+\.)+[A-Za-z]{2,3}$",$HTTP_POST_VARS["useremail"]))
{echo "<div align='center'>您的输入有误，请确定用户名、密码和E-mail的输入都是正确的.</div>";
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title><?php echo $classname ?>成员资料保存</title>
<link href="css.css" rel="stylesheet" type="text/css">
<meta http-equiv=Refresh content="2; url=javascript:history.back(1)">
</head>

<body>
<? }
else{
$username=htmlspecialchars($HTTP_POST_VARS["username"]);
$query="select username from classuser where username='$username'";
$result=mysql_db_query("$dbname",$query);
$n=mysql_num_rows($result);
if($n==0){
$username=htmlspecialchars($HTTP_POST_VARS["username"]);
$userpwd=htmlspecialchars($HTTP_POST_VARS["userpwd"]);
$userpwd=encrypt($userpwd);
$useremail=htmlspecialchars($HTTP_POST_VARS["useremail"]);
$sex=$HTTP_POST_VARS["sex"];
if($HTTP_POST_VARS["userqq"]==""){$userqq="--";}
else{$userqq=htmlspecialchars($HTTP_POST_VARS["userqq"]);}
if($HTTP_POST_VARS["usermsn"]==""){$usermsn="--";}
else{$usermsn=htmlspecialchars($HTTP_POST_VARS["usermsn"]);}
if($HTTP_POST_VARS["usericq"]==""){$usericq="--";}
else{$usericq=htmlspecialchars($HTTP_POST_VARS["usericq"]);}
if($HTTP_POST_VARS["userphone"]==""){$userphone="--";}
else{$userphone=htmlspecialchars($HTTP_POST_VARS["userphone"]);}
if($HTTP_POST_VARS["mobilephone"]==""){$mobilephone="--";}
else{$mobilephone=htmlspecialchars($HTTP_POST_VARS["mobilephone"]);}
if($HTTP_POST_VARS["birthday"]==""){$birthday="我的生日才不要告诉你呢";}
else{$birthday=htmlspecialchars($HTTP_POST_VARS["birthday"]);}
$userinfo=$HTTP_POST_VARS["userinfo"];
$userinfo=checkinfo($userinfo);
$add_date=date("y-m-j H:i:U");
$query="INSERT INTO classuser VALUES('','$username','$userpwd','$useremail','$sex','$userqq','$usermsn',
'$usericq','$add_date','$birthday','$userphone','$mobilephone','$userinfo','')";
$result=mysql_db_query("$dbname",$query);
if(mysql_affected_rows()==1)
{
   setcookie("class_username",$username,time()+650);
   setcookie("class_userpwd",$userpwd,time()+650);
   $ctime=date("U");
   $cid=encrypt($username);
   	 $query="select cname from classcookie where cname='$username'";
     $result=mysql_db_query("$dbname",$query);
	 $arr=mysql_fetch_array($result);
	 $num=$arr["count(*)"];
	 if($num==0){
      $query="INSERT INTO classcookie VALUES('$cid','$username','$ctime')";
      $result=mysql_db_query("$dbname",$query);}
   echo"$username 欢迎你加入我们!";

}else{echo "加入出错了！请重试！";}
}else{echo "用户名已存在，请换一个！";}

?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title><?php echo $classname ?>成员资料保存</title>
<link href="css.css" rel="stylesheet" type="text/css">
<meta http-equiv=Refresh content="2; url=index.php">
</head>
<? } ?>