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

?>
<body>
<?$step=6;
include("stepstop.php")?>
<?if ($_POST["submit2"]!='')
 {
	 $_SESSION["errmsg"]="";
	
	if ($_POST["complete_address"]=='')
		    $_SESSION["errmsg"].="@Address Should not be blank";
	if ($_POST["your_phone"]=='')
		    $_SESSION["errmsg"].="@Phone Should not be blank";
	if ($_POST["agree"]!='1')
		    $_SESSION["errmsg"].="@You must agree to pay the order amount to proceed.";
	if ($_SESSION["errmsg"]==''){ //Insert Order
		$sql="select * from user_master where active=1 and user_type=3 and user_id='".$_SESSION["userid"]."'";
	
		$cmd = mysql_query($sql);
		$rs = mysql_fetch_array($cmd);
	 
		
			$userinsert =$_SESSION["userid"];
		
		

	
	
	$getstonetype=getstonetype(gdbfx("stone_number"));
	$getcost=getcost(gdbfx("ring_number"),gdbfx("metal_name"));
	if (gdbfx("Replace_Zicon")=='yes')
		$getcostD=getcostDiamond(gdbfx("ring_number"));
	else
		$getcostD=0;
		if ($getcost >0) {
			if ($getstonetype==1)
				$getcost=($getcost+12+$getcostD);
			if ($getstonetype==2)
				$getcost=($getcost+35+12+$getcostD);
			if ($getstonetype==3)
				$getcost=($getcost+65+12+$getcostD);
		}
		
$order_number="ATI-".genpasswordnum(6);
//calculate the order details:
$orderdetails="<table width='100%' border='0' cellspacing='1' cellpadding='2' bgcolor='#EEB94A'>";
$orderdetails.="<tr align='center' class='heading'> 
	<td  align=left width='30%' bgcolor='#FFFFFF'><font  size=2><strong>Ring</strong></font></td>
	<td class='toplinks' align=left width='70%' bgcolor='#FFFFFF'><font  size=2>".gdbfx('ring_number')."</font></td>
 </tr>
 <tr align='center' class='heading'> 
	<td align=left width='40%' bgcolor='#FFFFFF'><font  size=2><strong>Metal</strong></font></td>
	<td class='toplinks' align=left width='60%' bgcolor='#FFFFFF'><font  size=2>".gdbfx('metal_name')."</font></td>
 </tr>
  <tr align='center' class='heading'> 
	<td  align=left width='40%' bgcolor='#FFFFFF'><font  size=2><strong>Metal Finish</strong></font></td>
	<td class='toplinks' align=left width='60%' bgcolor='#FFFFFF'><font  size=2>".gdbfx('metal_finish')."</font></td>
 </tr>
   <tr align='center' class='heading'> 
	<td  align=left width='40%' bgcolor='#FFFFFF'><font  size=2><strong>Palm Side</strong></font></td>
	<td class='toplinks' align=left width='60%' bgcolor='#FFFFFF'><font  size=2>".gdbfx('Palm_Side')."</font></td>
 </tr>
  <tr align='center' class='heading'> 
	<td  align=left width='40%' bgcolor='#FFFFFF'><font  size=2><strong>Replace Zicon(with Diamonds)</strong></font></td>
	<td class='toplinks' align=left width='60%' bgcolor='#FFFFFF'><font  size=2>".gdbfx('Replace_Zicon')."</font></td>
 </tr>
	<tr align='center' class='heading'> 
	<td  align=left width='40%' bgcolor='#FFFFFF'><font  size=2><strong>School/Univ. Name</strong></font></td>
	<td class='toplinks' align=left width='60%' bgcolor='#FFFFFF'><font  size=2>";
	if (gdbfx("schoolname")!='') 
		$orderdetails.= gdbfx("schoolname");
		else 
			$orderdetails.= "NA";
	$orderdetails.="</font></td>
 </tr>
	<tr align='center' class='heading'> 
	<td  align=left width='40%' bgcolor='#FFFFFF'><font  size=2><strong>Finger Size</strong></font></td>
	<td class='toplinks' align=left width='60%' bgcolor='#FFFFFF'><font  size=2>";
	if (gdbfx("finger_size")!='') 
		$orderdetails.= gdbfx("finger_size");
		else 
			$orderdetails.= "NA";
	$orderdetails.="</font></td>
 </tr>
   <tr align='center' class='heading'> 
	<td  align=left width='40%' bgcolor='#FFFFFF'><font  size=2><strong>Stone Choice</strong></font></td>
	<td class='toplinks' align=left width='60%' bgcolor='#FFFFFF'><font  size=2>".gdbfx('stone_number')."</font></td>
 </tr>
    <tr align='center' class='heading'> 
	<td  align=left width='40%' bgcolor='#FFFFFF'><font  size=2><strong>Stone Cut</strong></font></td>
	<td class='toplinks' align=left width='60%' bgcolor='#FFFFFF'><font  size=2>";

if (getstoneType(gdbfx('stone_number'))!=1) $orderdetails.='<font color=red>NA</font>'; else $orderdetails.=gdbfx('stone_cut_number')."</font></td>";
 $orderdetails.="</tr>
  
 <tr align='center' class='heading'> 
	<td  align=left width='40%' bgcolor='#FFFFFF'><font  size=2><strong>Emblem Under Stone Letter</strong></font></td>
	<td class='toplinks' align=left width='60%' bgcolor='#FFFFFF'><font  size=2>";
 if (gdbfx("stone_cut_number")!="Emblem Under Stone")  
	 $orderdetails.="<font color=red>NA</font>";
	else  $orderdetails.=gdbfx("letter1")."</font></td>";
  $orderdetails.="</tr>
   <tr align='center' class='heading'> 
	<td  align=left width='40%' bgcolor='#FFFFFF'><font  size=2><strong>Encrusting on the Stone Letter</strong></font></td>
	<td class='toplinks' align=left width='60%' bgcolor='#FFFFFF'><font  size=2>";
   if (gdbfx("stone_cut_number")!="Encrusting on the Stone") 
	   $orderdetails.="<font color=red>NA</font>";
   else  $orderdetails.=gdbfx("letter3")."</font></td>";
 $orderdetails.="</tr>

 <tr align='center' class='heading'> 
	<td  align=left width='40%' bgcolor='#FFFFFF'><font  size=2><strong>Letter Shape".gdbfx('stone_letter')."</strong></font></td>
	<td class='toplinks' align=left width='60%' bgcolor='#FFFFF'><font  size=2>";
 if (getstoneType(gdbfx("stone_cut_number"))!=6 || getstoneType(gdbfx('stone_number'))!=1) 		$orderdetails.= '<font color=red>NA</font>'; else $orderdetails.= gdbfx('stone_letter');
 $orderdetails.= "</font></td>
 </tr>
   <tr align='center' class='heading'> 
	<td  align=left width='40%' bgcolor='#FFFFFF'><font  size=2><strong>Crested Cut Letter</strong></font></td>
	<td class='toplinks' align=left width='60%' bgcolor='#FFFFFF'><font  size=2>";
if (getstoneType(gdbfx('stone_cut_number'))!=6 || getstoneType(gdbfx('stone_number'))!=1)    $orderdetails.='<font color=red>NA</font>'; else    $orderdetails.= gdbfx('letter2');
   $orderdetails.= "</font></td>
 </tr>";

if (gdbfx("image")!='') {
   $orderdetails.= " <tr align='center' class='heading'> 
	<td  align=left width='40%' bgcolor='#FFFFFF'><font  size=2><strong>Custom Image</strong></font></td>
	<td class='toplinks' align=left width='60%' bgcolor='#FFFFFF'><font  size=2>";
if (str_contains(gdbfx('image'),'PHOTO') && gdbfx("custom_left_side")!='')    $orderdetails.="<small>".gdbfx('image')."(Custom Image)</small>";
  $orderdetails.= " Used On ";
  if (gdbfx("custom_left_side")==1)
	  $orderdetails.="Left Side";
  if (gdbfx("custom_left_side")==2)
	  $orderdetails.="Right Side";
 $orderdetails.="<br>Image Refrence :".gdbfx('image');
   $orderdetails.= "</font></td></tr>";
	}
 $orderdetails.= "<tr align='center' class='heading'> 
	<td  align=left width='40%' bgcolor='#FFFFFF'><font  size=2><strong>Left Side Writing</strong></font></td>
	<td class='toplinks' align=left width='60%' bgcolor='#FFFFFF'><font  size=2>".gdbfx('left_side_text')."</font></td>
 </tr>
      <tr align='center' class='heading'> 
	<td  align=left width='40%' bgcolor='#FFFFFF'><font  size=2><strong>Right Side Writing</strong></font></td>
	<td class='toplinks' align=left width='60%' bgcolor='#FFFFFF'><font  size=2>".gdbfx('right_side_text')."</font></td>
 </tr>
      <tr align='center' class='heading'> 
	<td  align=left width='40%' bgcolor='#FFFFFF'><font  size=2><strong>Left Side Image</strong></font></td>
	<td class='toplinks' align=left width='60%' bgcolor='#FFFFFF'><font  size=2>".gdbfx('left_side_image')."</font></td>
 </tr>
      <tr align='center' class='heading'> 
	<td  align=left width='40%' bgcolor='#FFFFFF'><font  size=2><strong>Right Side Image</strong></font></td>
	<td class='toplinks' align=left width='60%' bgcolor='#FFFFFF'><font  size=2>".gdbfx('right_side_image')."</font></td>
 </tr>
      <tr align='center' class='heading'> 
	<td  align=left width='40%' bgcolor='#FFFFFF'><font  size=2><strong>Inside Engraving</strong></font></td>
	<td class='toplinks' align=left width='60%' bgcolor='#FFFFFF'><font  size=2>".gdbfx('inside_engraving')."</font></td>
 </tr>
	     <tr align='center' class='heading'> 
	<td  align=left width='40%' bgcolor='#FFFFFF'><font  size=2><strong>Outside Engraving</strong></font></td>
	<td class='toplinks' align=left width='60%' bgcolor='#FFFFFF'><font  size=2>".gdbfx('outside_engraving')."</font></td>
 </tr>
<tr align='center' class='heading'> 
	<td  align=left width='40%' bgcolor='#FFFFFF'><font  size=2><strong>Engraving Font</strong></font></td>
	<td class='toplinks' align=left width='60%' bgcolor='#FFFFFF'><font  size=2>".gdbfx('choose_font')."</font></td>
 </tr>
<tr align='center' class='heading'> 
	<td  align=left width='40%' bgcolor='#FFFFFF'><font  size=2><strong>Person Name</strong></font></td>
	<td class='toplinks' align=left width='60%' bgcolor='#FFFFFF'><font  size=2>".$rs["first_name"]." ".$rs["last_name"]."</font></td>
 </tr>
<tr align='center' class='heading'> 
	<td  align=left width='40%' bgcolor='#FFFFFF'><font  size=2><strong>Person Email</strong></font></td>
	<td class='toplinks' align=left width='60%' bgcolor='#FFFFFF'><font  size=2>".$rs["email"]."</font></td>
 </tr>
<tr align='center' class='heading'> 
	<td  align=left width='40%' bgcolor='#FFFFFF'><font  size=2><strong>Address</strong></font></td>
	<td class='toplinks' align=left width='60%' bgcolor='#FFFFFF'><font  size=2>".pdbfx('complete_address')."</font></td>
 </tr>
<tr align='center' class='heading'> 
	<td  align=left width='40%' bgcolor='#FFFFFF'><font  size=2><strong>Person Phone</strong></font></td>
	<td class='toplinks' align=left width='60%' bgcolor='#FFFFFF'><font  size=2>".pdbfx('your_phone')."</font></td>
 </tr>
<tr align='center' class='heading'> 
	<td  align=left width='40%' bgcolor='#FFFFFF'><font  size=2><strong>Amount To pay</strong></font></td>
	<td class='toplinks' align=left width='60%' bgcolor='#FFFFFF'><font  size=2>".$getcost."</font></td>
 </tr>
<tr align='center' class='heading'> 
	<td  align=left width='40%' bgcolor='#FFFFFF'><font  size=2><strong>Remarks</strong></font></td>
	<td class='toplinks' align=left width='60%' bgcolor='#FFFFFF'><font  size=2>".pdbfx('remarks')."</font></td>
 </tr>";
$order_date=date("Y-m-d H:i:s");
 //Finish order details
 $sql="Insert into order_master(order_details,order_user_id,order_name,order_email,order_address,order_phone,order_amount,order_date,order_comments,order_serial) values('".dbfx($orderdetails)."',".$userinsert.",'".$rs["first_name"]." ".$rs["last_name"]."','".$rs["email"]."','".pdbfx("complete_address")."','".pdbfx("your_phone")."','".$getcost."','".$order_date."','".pdbfx("remarks")."','".$order_number."')";
	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>".$rs["user_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>".$rs["password"]."</font></td>
						 </tr></table>";
						$orderdetails=$emaildetails.$orderdetails;
			

		$orderdetails="Dear ".pdbfx('your_name').",<br> Your order at ATI was received & is in process now.Your order number with us is <font color=black>".$order_number."</font>.Please Quote this number in any correspondance with us.Below is details of your order for your refrence.You can also check status of your order by login at the ATI website and clicking on 'Order Status' link.<br>".$orderdetails;
		echo "<font class=text color=red><font color=red><strong><br>Your Order is now placed,You will receive an confirmation email at your email address in few minutes.Your order number with us is <font color=black>".$order_number."</font>.Please Quote this number in any correspondance with us.You can also check status of your order by login at the ATI website and clicking on 'Order Status' link.<strong></font></font>";
		$headers = "From:cs@acatri.com\nContent-Type: text/html";
		mail($rs["email"],"Your Order at ATI",$orderdetails,$headers);
		mail("cs@acatri.com","Copy of order at ATI",$orderdetails,$headers);?>
		<table width="100%" border="0" cellspacing="1" cellpadding="2" ><tr>
<tr>

<td bgcolor="#FFFFFF" class="toplinks"><a href='javascript:window.close();'><u>Close Window</u></a>

		</td>	
</tr></table>
		<?
		//echo $orderdetails;
		die;
	}
 }
	?>
 <form name=step3 action="" method=POST>

				  <input type=hidden name=product value="<?=gdbfx("product");?>">
				  <input type=hidden name=ring_number value="<?=gdbfx("ring_number");?>">
				  <input type=hidden name=metal_name value="<?=gdbfx("metal_name");?>">
				  <input type=hidden name=metal_finish value="<?=gdbfx("metal_finish");?>">
				   <input type=hidden name=Palm_Side value="<?=gdbfx("Palm_Side");?>">
				    <input type=hidden name=Replace_Zicon value="<?=gdbfx("Replace_Zicon");?>">

				<input type=hidden name=stone_number value="<?=gdbfx("stone_number");?>">
				<input type=hidden name=stone_cut_number value="<?=gdbfx("stone_cut_number");?>">
				<input type=hidden name=letter1 value="<?=gdbfx("letter1");?>">
				<input type=hidden name=letter2 value="<?=gdbfx("letter2");?>">
				<input type=hidden name=letter2 value="<?=gdbfx("letter2");?>">
				<input type=hidden name=schoolname value="<?=gdbfx("schoolname");?>">
				<input type=hidden name=finger_size value="<?=gdbfx("finger_size");?>">
				<input type=hidden name=image value="<?=gdbfx("image");?>">
				<input type=hidden name=left_side_text value="<?=gdbfx("left_side_text");?>">
				<input type=hidden name=right_side_text value="<?=gdbfx("right_side_text");?>">
				<input type=hidden name=left_side_image value="<?=gdbfx("left_side_image");?>">
				<input type=hidden name=right_side_image value="<?=gdbfx("right_side_image");?>">
				<input type=hidden name=inside_engraving value="<?=gdbfx("inside_engraving");?>">
				<input type=hidden name=outside_engraving value="<?=gdbfx("outside_engraving");?>">
				<input type=hidden name=choose_font value="<?=gdbfx("choose_font");?>">
<?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>";
						}
			?>
		</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 Personal Info: </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="30%" bgcolor="#FFFFFF"><font  size=2><strong>Complete Address for Delivery</strong></font></td>
	<td class="toplinks" align=left width="70%" bgcolor="#FFFFFF"><textarea name=complete_address class=textarea cols=30 rows=4><?=pdbfx("complete_address");?></textarea></td>
 </tr>
 <tr align="center" class="heading"> 
	<td  align=left width="30%" bgcolor="#FFFFFF"><font  size=2><strong>Phone Number</strong></font></td>
	<td class="toplinks" align=left width="70%" bgcolor="#FFFFFF"><input type=text class=input name=your_phone size=40 maxlength=40 value="<?=pdbfx("your_phone");?>"></td>
 </tr>
<tr align="center" class="heading"> 
	<td  align=left width="40%" bgcolor="#FFFFFF"><font  size=2><strong>Final Cost</strong></font></td>
	<td class="toplinks" align=left width="60%" bgcolor="#FFFFFF"><font  size=3 color=green face=arial><strong>
<?$getstonetype=getstonetype(gdbfx("stone_number"));
	$getcost=getcost(gdbfx("ring_number"),gdbfx("metal_name"));
	if (gdbfx("Replace_Zicon")=='yes')
		$getcostD=getcostDiamond(gdbfx("ring_number"));
	else
		$getcostD=0;

		if ($getcost >0) {
			if ($getstonetype==1)
				echo "$ ".($getcost+12+$getcostD)." (USD)";
			if ($getstonetype==2)
				echo "$ ".($getcost+35+12+$getcostD)." (USD)";
			if ($getstonetype==3)
				echo "$ ".($getcost+65+12+$getcostD)." (USD)";	
		}
		else
			echo $getcost;
		?>

</strong></font></td>
 </tr>
 <tr align="center" class="heading"> 
	<td  align=left width="100%" bgcolor="#FFFFFF" colspan=2>
	<input type=radio name=agree value=1 <?if (pdbfx("agree")==1) echo "checked";?>>I agree to pay above amount for my order.
</td>
 </tr>
 <tr align="center" class="heading"> 
	<td  align=left width="30%" bgcolor="#FFFFFF"><font  size=2><strong>Any Remarks</strong></font></td>
	<td class="toplinks" align=left width="70%" bgcolor="#FFFFFF"><textarea name=remarks class=textarea cols=30 rows=4><?=pdbfx("remarks");?></textarea></td>
 </tr>
</table>

<table width="100%" border="0" cellspacing="1" cellpadding="2">
<?echo "<tr>";
echo "<td align=center colspan=\"2\" class=toplinks>Once you click \"Submit Order\" button below your order will be sent to ATI.You will receive a welcome email with your order details.You can track status of your order online using your Login Name & password.</td></tr></table>";?>

<table width="100%" border="0" cellspacing="1" cellpadding="2">
<?echo "<tr>";
echo "<td align=center  class=toplinks><br><a href=\"javascript:history.back();\"><input type=submit name=startagain value=\"Back\" class=button></a></td><td align=center  class=toplinks><br><input type=submit name=submit2 value=\"Submit order\" class=button></form></td></form </tr></table>";?>


<form name=step3 action="" method=POST>  <input type=hidden name=product value="<?=gdbfx("product");?>"><br><br><input type=submit name=startagain value="Start again" class=button></form>



<script>
function openWin(argURL, argSize) {

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

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