<?php
session_start() ;

if(!session_is_registered("member_level")) {
echo "<meta http-equiv='refresh' content='0;url=./home.php'>" ;
exit() ;
}
$mlevel = $_SESSION["member_level"];	
if($mlevel!=2) {
echo "<meta http-equiv='refresh' content='0;url=./home.php'>" ;
exit() ;
}

?>


<style type="text/css">
<!--
body,td,th {
	color: #003366;
}
body {
	background-color: #FFFFFF;
}
-->
</style>
<?php 


		if (isset($_GET["add2cart"]) && $_GET["add2cart"]>0) //add product to cart with productID=$add
		{

			//$_SESSION[gids] contains product IDs
			//$_SESSION[counts] contains product quantities ($_SESSION[counts][$i] corresponds to $_SESSION[gids][$i])
			//$_SESSION[gids][$i] == 0 means $i-element is 'empty'
			if (!isset($_SESSION["gids"]))
			{
				$_SESSION["gids"] = array();
				$_SESSION["counts"] = array();
				$_SESSION["details"] = array();
				$_SESSION["details1"] = array();
				$_SESSION["details2"] = array();
			}
			//check for current item in the current shopping cart content
		//	$i=0;
		//	while ($i<count($_SESSION["gids"]) && $_SESSION["gids"][$i] != $_GET["add2cart"]) $i++;
		//	if ($i < count($_SESSION["gids"])) //increase current product's quantity
		//	{
		//		$_SESSION["counts"][$i]++;
		//	}
		//	else //no item - add it to $gids array
			{
				$_SESSION["gids"][] = $_GET["add2cart"];
				$_SESSION["counts"][] = $_GET["amount"];
				$_SESSION["details"][] =  "";
				$_SESSION["details1"][] =  $_GET["idsize"];
				$_SESSION["details2"][] =  $_GET["idsize2"];
			}
			

           echo "<meta http-equiv='refresh' content='0;url=./cart.php?show=30'>" ;
			
		}elseif (isset($_GET["show"])){
		$show=0;
echo "<meta http-equiv='refresh' content='$show;url=./cart.php'>" ;

include("./member/config.inc.php") ;
mysql_select_db($db) ;
@mysql_select_db($db) or die( "Unable to select database");
mysql_db_query($db,"SET NAMES tis620");// 

mysql_query("SET character_set_results=tis620");
mysql_query("SET character_set_client=''tis620''");
mysql_query("SET character_set_connection=''tis620''");
mysql_query("collation_connection = tis620_thai_ci");
mysql_query("collation_database = tis620_thai_ci");
mysql_query("collation_server = tis620_thai_ci");

			$i=0;
			if(count($_SESSION["gids"])<1)exit();
			
//echo "<center><br><strong>สินค้าที่สั่ง</strong> <br><br><table cellspacing=1 cellpadding=3 bgcolor=555555>";			
//echo " <tr><td bgcolor=DDDDFF align=\"center\">รหัส</td><td bgcolor=DDDDFF  align=\"center\">ประเภท</td><td bgcolor=DDDDFF  align=\"center\">ชื่อสินค้า</td><td bgcolor=DDDDFF  align=\"center\">รูป</td><td bgcolor=DDDDFF  align=\"center\">  จำนวน (ชิ้น) </td><td bgcolor=DDDDFF  align=\"center\">  ขนาด </td></tr>";

			while ($i<count($_SESSION["gids"]))
			   {
 			       $b1=$_SESSION["gids"][$i];
 			       $b2=$_SESSION["counts"][$i];
 			       $b3=$_SESSION["details"][$i];
 			       $b4=$_SESSION["details1"][$i];
 			       $b5=$_SESSION["details2"][$i];
				   /*
                   $query="SELECT * FROM product WHERE id = $b1";
                    $result = mysql_query($query) or die ("Err Can not to result") ;
                    $dbarr = mysql_fetch_array($result) ;
				   
$query2="SELECT * FROM productsize WHERE id = '$b3' ";
$result2=mysql_query($query2);
$num2=mysql_numrows($result2);
$db2arr = mysql_fetch_array($result2) ;
				   */
 				  //echo " <tr><td bgcolor=EEEEFF align=\"center\">".$dbarr['model']."</td><td bgcolor=EEEEFF  align=\"center\">".$dbarr['type']."</td><td bgcolor=EEEEFF  align=\"center\">".$dbarr['name']."</td><td bgcolor=EEEEFF  align=\"center\"><img src=\"zz0504.php?id=$b1\" width=100 height=130></td><td bgcolor=EEEEFF  align=\"center\">$b2 </td><td bgcolor=EEEEFF  align=\"center\">น้ำหนัก".$db2arr['weight']."/ขนาด".$db2arr['size']."</td></tr>";
				  
				  $i++;
				}				
//echo "</table></center>";			
	echo "<p>เรียบร้อยแล้วครับ</p><script>window.close() </script>";
?>
        <form name="counter">
          <div align="center">
            <p>เรียบร้อยแล้วครับ</p>
          </div>
        </form> 

<div align="center">
  <script> 
 var seconds=<?php echo $show; ?>;
 document.counter.d2.value='<?php echo $show; ?>'; 

function display(){ 
if( seconds>0)
{
    seconds-=1 
    document.counter.d2.value=seconds
    setTimeout("display()",1000) 
}	
} 
display() 
</script>

<?php

		}	else{
	echo "<script>window.close() </script>";
		}
		
?>
