<?php 
$MyId="";
$MyNameIs="";
if(!isset($_SESSION)) { 
ini_set('session.save_path', 'tmp');
        session_start();
		if (isset($_SESSION["user"])) {
        $MyNameIs =  $_SESSION["user"];
		include_once "storescripts/connect_to_mysql.php";
		$q3 =mysql_query("SELECT * FROM users WHERE username ='$MyNameIs' LIMIT 1");
             $r3 = mysql_fetch_array($q3);
             $MyId = $r3["id"];
    }else{

} 
    } elseif (isset($_SESSION["user"])){
	
	$MyNameIs =  $_SESSION["user"];
	include_once "storescripts/connect_to_mysql.php";
	$q3 =mysql_query("SELECT * FROM users WHERE username ='$MyNameIs' LIMIT 1");
             $r3 = mysql_fetch_array($q3);
             $MyId = $r3["id"];
}
?>





<?php
error_reporting(E_ALL);
ini_set('display_error','1');
?>
<?php
if(isset($_GET['id'])){
include "storescripts/connect_to_mysql.php";
$id=preg_replace('#[^0-9]#i','',$_GET['id']);
$sql=mysql_query("SELECT * FROM products WHERE id='$id' LIMIT 1");
$productCount = mysql_num_rows($sql);
if($productCount>0){
while($row = mysql_fetch_array($sql)){
$product_name = $row["product_name"]; 
$price=$row["price"];
$details=$row["details"];
$meta=$row["meta"];
$category=$row["category"];
$data_added=strftime("%b%d,%y",strtotime($row["date_added"]));   

$qwery=mysql_query("SELECT * FROM sub_category WHERE sid='$category' LIMIT 1");
$r = mysql_fetch_array($qwery);
$sub_category = $r["sname"];
$c_id = $r["cid"];

$qq =mysql_query("SELECT * FROM category WHERE cid='$c_id' LIMIT 1");
$ro = mysql_fetch_array($qq);
$category_name = $ro["name"];
}
}
else {
echo "That item dose not exist";
exit();
}
}else {
echo "Data to render this page is missing";
exit();
}

mysql_close(); 
include_once("templet_header.php");
?> 

<?php 
// Connect to the MySQL database  
include "storescripts/connect_to_mysql.php";
//Run a select query to get my letest 6 item
$comments = "";
$sql = mysql_query("SELECT * FROM comments WHERE pid = '$id' ORDER BY date DESC");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
	while($row = mysql_fetch_array($sql)){ 
             $uid = $row["uid"];
			 $txt = $row["txt"];
			 $date_added = $row["date"];
			 
			 $q1 =mysql_query("SELECT * FROM users WHERE id='$uid' LIMIT 1");
             $r1 = mysql_fetch_array($q1);
             $user_name = $r1["username"];	 
			 
			 $pic = '<img style="border:#00000 0px solid;" src="user_img/' . $uid . '.jpg" alt="' . $user_name . '" width="70" height="70" border="1" />';
			 
			 $comments .= '
        		 <table width="48%" border="0" cellspacing="0" cellpadding="15">
    <tr>
      <td  rowspan="2"><h3 align="right">'.$pic.'<h3></td>
      <td><h5 align="left"> '.$user_name.' &nbsp;'. $date_added.'</h5></td>
    </tr>
    <tr>
      <td  height="46" valign="top"> <h3 align="left">'.$txt.'</h3> </td>
    </tr>
  </table>
      ';
    }
} else {

	$dynamicList="We have no products listed in our store yet";
}
mysql_close();

?>
<?php 

$comentform ='<form id="comment" name="form2" method="post" action="addcomment.php">        
          <table width="486" >
            <tr>
              <td width="153"><img style="border:#00000 0px solid;" src="user_img/' . $MyId . '.jpg" alt="' . $MyNameIs . '" width="60" height="60" border="1"/></td>
              <td width="317"><p>
                  <textarea name="text" cols="50" rows="3"  rowspan="3"></textarea>
              </p></td>
            </tr>
          </table>
          <table width="487" border="0" cols="66"  rowspan="3">
            <tr>
              <td width="252">&nbsp;</td>
              
              <td width="87"><div align="right">
                <input type="submit" width="50px" name="button2" id="button2" value="comment" />
                
                <input type="hidden" name="myid" id="myid" value="'.$MyId.'"/>
                
                <input type="hidden" name="productid" id="myid" value="'.$id.'"/>
                
              </div></td>
            </tr>
          </table>
</form> ' ;

?>
<!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=utf-8" />


<meta name="description" content="<?php echo $details; ?>">
<meta name="keywords" content="<?php echo $meta; ?>">
<meta name="product name" content="<?php echo $product_name; ?>">
<meta name="keywords" content="adaestore, ADAESTORE, product, category, nokia, samsung, cameras" />
<meta name="description" content="adaestore, ADAESTORE, product, category, nokia, samsung, cameras" />
<title><?php echo $product_name; ?></title>
<link rel ="stylesheet" href="style/css" media="screen" />
<style type="text/css">

<!--
.style3 {
font-size:60px;

}
.style5 {font-size: 24px}
-->
</style>

</head>
<body>
<table width="100%" border="0" bordercolor="#000000">
    <tr>
      <td height="52" valign="top"><div id = "PageContet">
        <table width="100%" border="0" cellspacing="0" cellpadding="15">
          <tr>
            <td width="34%" rowspan="3" valign="top"><div align="center"><img src="inventory_images/<?php echo $id; ?>.jpg" width="300" height="300" alt="alt" "<?php echo $product_name; ?>"/><br/>
                <a href ="inventory_images/<?php echo $id; ?>.jpg"> view full size image</a></div></td>
            <td height="49" colspan="2" valing="top"><div align="left" class="style3"><?php echo $product_name; ?></div></td>
          </tr>
          <tr>
            <td height="89" colspan="2" valing="top"><div align="left" style="font-size:24px"><?php echo $category_name . " - "; ?> <?php echo $sub_category;?> </div></td>
          </tr>
          <tr>
            <td width="17%" valing="top"><h3 align="left"><?php echo "price :".$price."$";?><br/>
                    <?php echo $details; ?></h3>
                    
                    
                    
              <?php   $b='<form id="form1" name="form1" method="post" action="cart.php">
                  <div align="left">
                    <input type="hidden" name="pid" id="pid" value="'.$id.'"/>
                    <input type="submit" name="button" id="button" value="Add to Sopping Cart"/>
                  </div>
                </form>';
				?>
                
              <?php   if (isset($_SESSION["user"])) {echo $b;} ?>
                
                
                </td>
            <td width="49%" valing="top">&nbsp;</td>
          </tr>
        </table>
      </div>
<?php 
	  if (isset($_SESSION["user"])) {echo $comentform; }
	    else {}
?>
        <p><?php echo $comments ; ?></p>
        <p>&nbsp;</p>
          <p align="left">&nbsp;</p>
      </td>
      <td width="13%" valign="top"><?php include_once("right.php");?>
          <div align="left"></div></td>
    </tr>
  </table>
  
  <p>&nbsp;  </p>
<div align="center">
    <?php include_once("templet_footer.php");?>
</div>
		 
</body>
</html>