<?php
/*************************************************************\
+-------------------------------------------------------------+
| 通灵佛教网在线烧香程序 System                                 |
| Copyright (c) 2003-2010 Alfred China                        |
| All rights reserved.                                        |
+-------------------------------------------------------------+
\*************************************************************/
require_once('chk.php');

if($mode == "add"){
	
	$uname_tmp=stripslashes($username);
	if (strcmp($uname_tmp, $username) !=0){
		echo "<script language=\"JavaScript\">\r\n"; 
		echo " alert(\"会员名非法，请选择其他的会员名\");\r\n"; 
		echo " history.go(-1);\r\n";echo "</script>"; 
		exit; 
	}
		
	$existing_user = ng_query_first("select username from $sql_tbl[users] where username='$username'");
		
	if ($existing_user){
		echo "<script language=\"JavaScript\">\r\n"; 
		echo " alert(\"该会员已被注册，请选择其他的会员名\");\r\n"; 
		echo " history.go(-1);\r\n";echo "</script>"; 
		exit; 
	}

	$existing_email = ng_query_first("select email from $sql_tbl[users] where email = '$email'");
	if ($existing_email){
		echo "<script language=\"JavaScript\">\r\n"; 
		echo " alert(\"该Email已被注册，请选择其他的Email\");\r\n"; 
		echo " history.go(-1);\r\n";echo "</script>"; 
		exit; 
	}
		
	if(!eregi("^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3}$",$email)){
		echo "<script language=\"JavaScript\">\r\n"; 
		echo " alert(\"Email格式不正确，请正确填写\");\r\n"; 
		echo " history.go(-1);\r\n";echo "</script>"; 
		exit; 
	}
	
	if ($passwd1 != $passwd2){
		echo "<script language=\"JavaScript\">\r\n"; 
		echo " alert(\"密码和确认密码不一致，请正确填写\");\r\n"; 
		echo " history.go(-1);\r\n";echo "</script>"; 
		exit; 
	}
		
	$curtime = time();
	$crypted = md5($passwd1);
	db_query("INSERT INTO $sql_tbl[users] (username,password,email,regdtm,logindtm) VALUES ('$username','$crypted', '$email','$curtime','$curtime')");
	$strmess = urlencode("注册成功，请登录！");
	ng_header_location("login.php?strmess=$strmess");
	
}

if ($username != ''){
	$strmess = urlencode("您已经注册并登录，无需重复注册！");
	ng_header_location("index.php?strmess=$strmess");
}

$metawords = $netgou["meta_keywords"];
$metaintro = $netgou["meta_descr"];
$titlename = $netgou["web_name"];

$ng_obstart && function_exists('ob_gzhandler') ? ob_start('ob_gzhandler') : ob_start();
$ng_obstart ? $ng_gzip="Gzip enabled":$ng_gzip="Gzip disabled";
require_once PrintTemp('header');
require_once PrintTemp('reg');
require_once PrintTemp('footer');
$output=str_replace(array('<!--<!--<!---->','<!--<!---->','<!---->'),array('','',''),ob_get_contents());
ob_end_clean();
echo $output;
flush;
exit;
break;
?>