<?include("includes/connection.php")?>
<?include("includes/func.php")?>
<html>
<head>
<link href="images/class.css" rel="stylesheet" type="text/css">
<title>Register Or Login</title>
</head>
<?
if ($_POST["startagain"]!='') {
	redirect("chooseoptions.php?product=".pdbfx("product"));
}

?>
<body>
<noscript>
<center><br><br><font class=heading><font color=red size=2><b>You cannot use many Features of this website because JavaScript is turned off in your Web browser. To use ATI website order process, turn JavaScript on through your Preferences or Internet Options in your Web browser.</b></font></font></center> <br><br>
</noscript>
<?$step=6;
//include("stepstop.php")?>
<?if ($_POST["submitlogin"]!='')
 {
	 
	 $_SESSION["errmsg"]="";
	 if ($_POST["existing_user"]=='1')
	{
	
	if ($_POST["login_name"]=='' && $_POST["existing_user"]=='1')
		    $_SESSION["errmsg"].="@User Name  Should not be blank";
	if ($_POST["password"]=='' && $_POST["existing_user"]=='1')
		    $_SESSION["errmsg"].="@Password Should not be blank";
	}
	 if ($_POST["existing_user"]=='2')
	{
	if ($_POST["your_name"]=='')
		    $_SESSION["errmsg"].="@Name Should not be blank";
	if ($_POST["your_email"]=='')
		    $_SESSION["errmsg"].="@Email Address  Should not be blank";
	if (!eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$',$_POST["your_email"]) && $_POST["your_email"]!='') 
			$_SESSION["errmsg"].="@Email Address  does not looks like valid.";
	}
	if ($_SESSION["errmsg"]=='' && $_POST["existing_user"]=='1')
	{
		$sql="select * from user_master where active=1 and user_type=3 and user_name='".pdbfx("login_name")."'";
	
		$cmd = mysql_query($sql);
		$rs = mysql_fetch_array($cmd);
	 
		if (cmpfx($rs["user_name"], $_POST["login_name"]) && cmpfx($rs["password"], $_POST["password"])) {
			$_SESSION["username"] = $_POST["login_name"];
			$_SESSION["userid"] = $rs["user_id"];
			if ($_POST["jacket"]==1)
				if ($_POST["type"]=='')
					redirect("Letterman%20Jacket%20Order%20Form.pdf");
				if ($_POST["type"]=='1')
					redirect("order/Diploma%20order%20form.pdf");
				if ($_POST["type"]=='2')
					redirect("order/Diploma%20Cover%20order%20form.pdf");
				if ($_POST["type"]=='3')
					redirect("order/Graduation%20Regalia%20order%20form.pdf");
			else
			redirect("chooseoptions.php?product=".$_POST["product"]);

		}
		else
		{
			 $_SESSION["errmsg"].="@Invalid Login Info,Try again.";
		}

	} //end for login check
	if ($_SESSION["errmsg"]=='' && $_POST["existing_user"]=='2')
	{
		$sql="select count(*) from user_master where active=1 and user_type=3 and email='".pdbfx("your_email")."'";
	
		$cmd = mysql_query($sql);
		$rs = mysql_fetch_array($cmd);
	 
		if ($rs[0]!=0) {
			
				$_SESSION["errmsg"]="@The Email address you used matched to one of existing user.if this is your email address ,you can click <a href=\"#\" onClick=\"javascript:openWin2('forget_password.php?your_email=".str_replace("@","ATTHERATE",$_POST["your_email"])."', 'width=380, height=180');\">Forget password</a> to retrieve your login name & password.";
		}

	} //end for new login check



	if ($_SESSION["errmsg"]==''){ //Insert Order
			
			if ($_POST["existing_user"]=='2')
					{
						$login_name=strtolower(GetRecortarTextoNew(pdbfx("your_name"),5).genpasswordalpha(1).genpasswordnum(4));
						$login_name=PrepareName($login_name);
						$password=genpasswordnum(6);
						$user_date=date("Y-m-d");
						$sql="insert into user_master(first_name,email,user_name,password,user_type,user_date)values('".pdbfx("your_name")."','".pdbfx("your_email")."','".$login_name."','".$password."',3,'".$user_date."')";
						mysql_query($sql);

						$emaildetails="<table width='100%' border='0' cellspacing='1' cellpadding='2' bgcolor='#EEB94A'><tr align='center' class='heading'> 
							<td  align=left width='40%' bgcolor='#FFFFFF'><font  size=2><strong>Your Login Name:</strong></font></td>
							<td class='toplinks' align=left width='60%' bgcolor='#FFFFFF'><font  size=2>".$login_name."</font></td>
						 </tr>
						<tr align='center' class='heading'> 
							<td  align=left width='40%' bgcolor='#FFFFFF'><font  size=2><strong>Your Login Password</strong></font></td>
							<td class='toplinks' align=left width='60%' bgcolor='#FFFFFF'><font  size=2>".$password."</font></td>
						 </tr></table>";
						$orderdetails=$emaildetails.$orderdetails;
					}

		$orderdetails="Dear ".pdbfx('your_name').",<br>Your Registration at ATI is completed.Use below Login info to continue your order at ATI website.<br>".$orderdetails;
		echo "<font class=text color=red><font color=red><br>An Email is sent to your email address <strong> ".pdbfx("your_email")."</strong> with your login name & password.The email should arrive at your mailbox in few seconds.If you face any difficulty please email us at CS@ACATRI.COM<br><br>Use below form to login once you receive the login info in email.</font>";
		$headers = "From:cs@acatri.com\nContent-Type: text/html";
		mail(pdbfx("your_email"),"Your Login/Password From ATI website",$orderdetails,$headers);
		//mail("cs@acatri.com","Copy of order at ATI",$orderdetails,$headers);?>
		<table width="100%" border="0" cellspacing="1" cellpadding="2" ><tr>
</table>
		<?
		//echo $orderdetails;
	}
 }
	?>
 <form name=step3 action="" method=POST>

				  <input type=hidden name=product value="<?=gdbfx("product");?>">
				  <input type=hidden name=jacket value="<?=gdbfx("jacket");?>">
				   <input type=hidden name=type value="<?=gdbfx("type");?>">
<?if ($_SESSION["errmsg"]!=''){?>
<table width="100%" border="0" cellspacing="1" cellpadding="2">
				  <tr>
		<td class="text"><span class="heading">
		

	<br><font color=red>Wait!You are not done yet.Please correct these errors and submit again:</font><br><br>

	<?}?>
		<?if ($_SESSION["errmsg"]!='')
			{
				$temp=split("@",$_SESSION["errmsg"]);
					for($i = 1; $i < count($temp); $i++){ 
							echo "<img src='images/icons/help.gif'> &nbsp; ". $temp[$i] ."<br>";
						}
						 $_SESSION["errmsg"]="";
			?>
		</span><br>
		  <br>
		 </td>
	  </tr>
	 </table>
			<?}?>

<table width="100%" border="0" cellspacing="1" cellpadding="2">
<tr align="center" class="heading"> 
	<td class="toplinks" align=left colspan=2><font  size=2><strong>Please Provide Login info to continue: </font></strong></td>
  </tr>
</table>

<table width="100%" border="0" cellspacing="1" cellpadding="2" bgcolor="#EEB94A">

<tr align="center" class="heading"> 
	<td  align=left width="100%" bgcolor="#FFFFFF" colspan=2>
	<input type=radio name=existing_user value=1 <?if (pdbfx("existing_user")!=2) echo "checked";?>>I am an existing user with&nbsp; <br><br>
	<strong>Login Name: </strong><input type=text class=input name=login_name size=20 maxlength=40 value="<?=pdbfx("login_name");?>">
	<strong>Password: </strong><input type=password class=input name=password size=20 maxlength=40 value="<?=pdbfx("password");?>"> <br>
</td>
 </tr>
<tr align="center" class="heading"> 
	<td  align=left width="100%" bgcolor="#FFFFFF" colspan=2>
	<input type=radio name=existing_user value=2 <?if (pdbfx("existing_user")==2) echo "checked";?>>I am a New user,Give me a username & password to track my orders.
	<table>
	<tr align="center" class="heading"> 
	<td  align=left width="30%" bgcolor="#FFFFFF"><font  size=2><strong>Your Complete Name</strong></font></td>
	<td class="toplinks" align=left width="70%" bgcolor="#FFFFFF"><input type=text class=input name=your_name size=40 maxlength=40 value="<?=pdbfx("your_name");?>"></td>
 </tr>
<tr align="center" class="heading"> 
	<td  align=left width="30%" bgcolor="#FFFFFF"><font  size=2><strong>Email Address</strong></font></td>
	<td class="toplinks" align=left width="70%" bgcolor="#FFFFFF"><input type=text class=input name=your_email size=40 maxlength=40 value="<?=pdbfx("your_email");?>"></td>
 </tr>
 <?echo "<tr>";
echo "<td align=center colspan=\"2\" class=toplinks>Please use a valid email,Your Login Name & password will be email to this Email address.</td></tr>";?>
	</table>
</td>
 </tr>


</table>



<table width="100%" border="0" cellspacing="1" cellpadding="2">
<?echo "<tr>";
echo "<td align=center  class=toplinks><td align=center  class=toplinks><br><input type=submit name=submitlogin value=\"Continue\" class=button></form></td></tr></table>";?>

<table width="100%" border="0" cellspacing="1" cellpadding="2">
  <?echo "<tr>";
echo "<td align=left colspan=\"2\" class=botlinks><br><br>If you forget your login Name or password 
<a href=\"#\" onClick=\"javascript:openWin2('forget_password.php', 'width=380, height=180');\">
<font class=toplinks>Click here</font></a> to find it again.</td></tr></table>";?>




<script>
function openWin2(argURL, argSize) {

	window.open(argURL, "34343" + (new Date()).getTime(), "resizable=yes,scrollbars=yes," + argSize);

}
</script>
</body>
</html>