<?
include("connect.php");
include("security.php");
$type1 = "1";
$type2 = "2";
include("pagepermission.php");
if($_REQUEST['add'])
{
	$qrysel = "select * from registration where username='".$_REQUEST['username']."' or email='".$_REQUEST['email']."'";
	$rsqrysel = mysql_query($qrysel);
	$totalrows = mysql_affected_rows();
	if($totalrows>0)
	{
		header("location: message.php?msg=4");
		exit;
	}
	
	$username=$_REQUEST['username'];
	$fname=$_REQUEST['fname'];
	$lname=$_REQUEST['lname'];
	$gender=$_REQUEST["gender"];
	$bdate=$_REQUEST["cmbdate"]."-".$_REQUEST["cmbmonth"]."-".$_REQUEST["cmbyear"];
	$address1=$_REQUEST['address1'];
	$address2=$_REQUEST['address2'];
	$city=$_REQUEST['city'];
	$state=$_REQUEST['state'];
	$zipcode=$_REQUEST['zipcode'];
	$phone=$_REQUEST['phone'];
	$email=$_REQUEST['email'];
	$pass=$_REQUEST['pass_word'];
	$mobileno = $_REQUEST["mobileno"];
	
	$countryinfo = explode("|",$_REQUEST['country']);
	$country=$countryinfo[0];
	$countrycode=$countryinfo[1];
	$fullmobile = "+".$countrycode.$mobileno;
	$verifycode = md5($username);
	
	
	$qryins = "Insert into registration (username,firstname,lastname,sex,birth_date,addressline1,addressline2,city,state,country,postcode,phone,email,password,mobile_no,full_mobileno,register_date,verify_code) values('$username','$fname','$lname','$gender','$bdate','$address1','$address2','$city','$state','$country','$zipcode','$phone','$email','$pass','$mobileno','$fullmobile',NOW(),'$verifycode')";
	$resultu=mysql_query($qryins);
	header("location:message.php?msg=2");
	exit;
			
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?=$lng_characset;?>" />
<title>Untitled Document</title>
<link rel="stylesheet" href="main.css" type="text/css">
<script language="javascript" src="Validation.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
function validation(f1){

	if(f1.username.value.length<=0)
	{
		alert("请输入用户名!");
		f1.username.focus();
		return false;
	}

	if(f1.username.value.length<4)
	{
		alert("用户名太短!");
		f1.username.focus();
		return false;
	}

	if(f1.fname.value.length<=0)
	{
		alert("请输入您的姓名!");
		f1.fname.focus();
		return false;
	}
	/*
	if(f1.lname.value.length<=0)
	{
		alert("Please Enter Your Last Name!");
		f1.lname.focus();	
		return false;
	}
	*/
	if(f1.cmbdate.value=="none")
	{
		alert("请选择您的出生日期!");
		f1.cmbdate.focus();	
		return false;	
	}

	if(f1.cmbmonth.value=="none")
	{
		alert("请选择您的出生日期!");
		f1.cmbmonth.focus();	
		return false;	
	}
	
	if(f1.cmbyear.value=="none")
	{
		alert("请选择您的出生日期!");
		f1.cmbyear.focus();	
		return false;	
	}

	/*if(f1.address1.value.length<=0)
	{
		alert("Please Enter Your Address!");
		f1.address1.focus();	
		return false;
	}
	
	if(f1.city.value.length<=0)
	{
		alert("Please Enter Your City!");
		f1.city.focus();	
		return false;
	}
	
	if(f1.state.value.length<=0)
	{
		alert("Please Enter Your State!");
		f1.state.focus();	
		return false;
	}
	
	if(f1.country.value.length<=0)
	{
		alert("Please Enter Your Country!");
		f1.country.focus();	
		return false;
	}
	
	if(f1.zipcode.value.length<=0)
	{
		alert("Please Enter Your Zipcode!");
		f1.zipcode.focus();	
		return false;
	}
	if(f1.phone.value.length<=0)
	{
		alert("Please Enter Your Phone Number!");
		f1.phone.focus();	
		return false;
	}*/
	/*
	if(f1.country.value=="none")
	{
		alert("Please Select Your Country!");
		f1.country.focus();	
		return false;
	}*/
	if(f1.email.value.length<=0)
	{
		alert("请输入您的EMAIL!");
		f1.email.focus();	
		return false;
	}
	
	if(f1.cnfemail.value.length<=0)
	{
		alert("请确认您的EMAIL!");
		f1.cnfemail.focus();	
		return false;
	}
	
	if(f1.email.value!=f1.cnfemail.value)
	{
		alert("两次输入的EMAIL不一样!");
		f1.cnfemail.focus();
		f1.cnfemail.select();
		return false;		
	}
	else
	{
		if(!validate_email(f1.email.value,"请输入正确的EMAIL地址!"))
			{
				f1.email.select();
				return false;
			}
	}
	
	if(f1.pass_word.value=="")
	{
		alert("请输入密码!");
		f1.pass_word.focus();
		return false;
	}
	
	if(f1.pass_word.value.length<6)
	{
		alert("密码太短!");
		f1.pass_word.focus();
		f1.pass_word.select();
		return false;
	}
	
	if(f1.cpassword.value=="")
	{
		alert("请确认密码!");
		f1.cpassword.focus();		
		return false;
	}
	
	if(f1.cpassword.value!=f1.pass_word.value)
	{
		alert("两次输入的密码不一样!");
		f1.pass_word.focus();
		f1.cpassword.select();
		return false;
	}	
}
function validate_email(field,alerttxt){
	with (field){
		var value;
		value = document.newmember.email.value;
		apos=value.indexOf("@");
		dotpos=value.lastIndexOf(".");
		if (apos<1||dotpos-apos<2){
			alert(alerttxt);return false;
		}else{
			return true;
		}
	}
}
</script>
</head>

<body>
<TABLE cellSpacing=10 cellPadding=0  border=0 width="650">
		<TR>
			<TD class="H1">Add Member</TD>
		</TR>
		<TR>
			<TD background="images/vdots.gif"><IMG height=1 
			  src="images/spacer.gif" width=1 border=0></TD>
		</TR>
	<? if($msg){ ?>
		<tr>
			<td bgcolor="#F1F0EF" style='color:#FF0000;' align="center"><?=$msg?></td>
		</tr>
	<? } ?>
<tr><td>
<!-- changeble part starts -->
<form action="addmembers.php" method="post" name="newmember" onsubmit="return validation(this);">
<TABLE cellSpacing=2 cellPadding=1 width="650" border=0>
   <TBODY>
     <TR align="right"> 
       <TD colSpan=3 class="a">* 必填项</TD>
     </TR>
     <TR> 
        <TD class=th-d colSpan=3>基本信息</TD>
     </TR>
     <TR> 
       <TD width="182" align=right><IMG height=5 src="images/spacer.gif" width=1 border=0></TD>
       <TD width="458"> </TD>
     </TR>
   	 <tr>
	  <td class="normal" align="right"><font class="a">*</font>&nbsp;用户名 :&nbsp;</td>									
 	  <td><input type="text" name="username"></td>
	 </tr>
     <tr>
	  <td class="normal" align="right"><font class="a">*</font>&nbsp;名 :&nbsp;</td>	  
	  <td><input type="text" name="fname"></td>
	</tr>
	<tr>
	  <td class="normal" align="right"><font class="a">*</font>&nbsp;姓 :&nbsp;</td>
	  <td><input type="text" name="lname"></td>
	</tr>
	<tr>
	  <td class="normal" align="right">&nbsp;性别 :&nbsp;</td>
	  <td><select name="gender" style="background:#F7F7F7">
	  		<option value="Male">男</option>
			<option value="Female">女</option>
		</select>
	   </td>
    </tr>
	<tr>
	  <td class="normal" align="right"><font class="a">*</font>&nbsp;出生日期 :&nbsp;</td>
	  <td>
		  <select name="cmbdate" style="background:#F7F7F7">
  	  		<option value="none" selected="selected">--</option>
	  		<?
				for($i=1;$i<=31;$i++)
				{
					if($i<=9)
					{
						$i="0".$i;
					}
			?>
				<option value="<?=$i;?>"><?=$i;?></option>
			<?	
				}
			?>
		  </select>
		  <select name="cmbmonth" style="background:#F7F7F7">
	  		<option value="none" selected="selected">--</option>
	  		<?
				for($i=1;$i<=12;$i++)
				{
					if($i<=9)
					{
						$i="0".$i;
					}
			?>
				<option value="<?=$i;?>"><?=$i;?></option>
			<?	
				}
			?>
		  </select>
		  <select name="cmbyear" style="background:#F7F7F7">
	  		<option value="none" selected="selected">----</option>
	  		<?
				for($i=1950;$i<=2020;$i++)
				{
			?>
				<option value="<?=$i;?>"><?=$i;?></option>
			<?	
				}
			?>
		  </select>
	   </td>
    </tr>
    <tr>
	  <td class="normal" align="right">&nbsp;地址1 :&nbsp;</td>
	  <td><input type="text" name="address1" /></td>
    </tr>
    <tr>
	  <td class="normal" align="right">&nbsp;地址2 :&nbsp;</td>
	  <td><input type="text" name="address2" /></td>
    </tr>
	<tr>
	 <td class="normal" align="right">&nbsp;市县区 :&nbsp;</td>
	 <td><input type="text" name="city"></td>
	</tr>
    <tr>
	 <td class="normal" align="right">&nbsp;省 :&nbsp;</td>
	 <td><input type="text" name="state"></td>
	</tr>
    <tr>
	 <td class="normal" align="right"><font class="a">*</font>&nbsp;国家/地区 :&nbsp;</td>
	 <td><select name="country" style="width:100pt;">
     	<option value="none">请选择一个</option>
	 	 <? 
		 	$qrycou = "select * from countries order by printable_name";
			$rescou = mysql_query($qrycou);
			while($cou=mysql_fetch_array($rescou))
			{
		 ?>
		 	<option value="<?=$cou["countryId"];?>|<?=$cou["countrycode"];?>"><?=$cou["printable_name"];?></option>
		 <?
		 }
		 ?>
		 </select>
	 </td>
	</tr>
	<tr>
	 <td class="normal" align="right">&nbsp;邮编 :&nbsp;</td>
	 <td><input type="text" name="zipcode"></td>
	</tr>
	<tr>
	 <td class="normal" align="right">&nbsp;电话号码 :&nbsp;</td>
	 <td><input type="text" name="phone"></td>
	</tr>
	<tr>
	 <td class="normal" align="right">&nbsp;手机号码 :&nbsp;</td>
	 <td><input type="text" name="mobileno"></td>
	</tr>
	<tr>
	 <td class="normal" align="right"><font class="a">*</font>&nbsp;电子邮件 :&nbsp;</td>
 	 <td><input type="text" name="email"></td>
	</tr>
	<tr>
	 <td class="normal" align="right"><font class="a">*</font>&nbsp;确认电子邮件 :&nbsp;</td>
	<td><input type="text" name="cnfemail"></td>
	</tr>
    <tr>
	 <td class="normal" align="right"><font class="a">*</font>&nbsp;密码 :&nbsp;</td>
	 <td><input type="password" name="pass_word"></td>
	</tr>
	<tr>
	 <td class="normal" align="right"><font class="a">*</font>&nbsp;确认密码 :&nbsp;</td>
	 <td><input type="password" name="cpassword"></td>
    </tr>
	<tr>
	 <td>&nbsp;</td><td>&nbsp;</td>
	</tr>
	<TR> 
     <TD align=right>&nbsp;</TD>
     <TD><INPUT type="submit" value="新增" name="add" class="bttn"></TD>
    </TR>
   </TBODY>
  </TABLE>
</form></td></tr></TABLE>
<!-- changeble part ends -->
</body>
</html>
