<?php
session_start();
$username = $_SESSION['membership'];
include("connect.php");

$ISBN = $_GET["ISBN"];

$result = mysql_query("SELECT * FROM item WHERE ISBN = '$ISBN'");

$row = mysql_fetch_array($result);

echo "<div id='main'>";
echo "<center>";
echo "<h3>Book Detail</h3>";
echo "</div>";

echo "<div id='bookmenu'>";
echo "<form name='q1form' method='GET' action='addcart.php'>";
echo "<table border='0' cellspacing='2' cellpadding='1' bordercolor='black' width='80%'>";

	echo "<tr>";
	echo "<td colspan='3'></td>";
	echo "</tr>";
	
	echo "<tr>";
	echo "<th colspan='3' style='font-size:15pt'><input type='hidden' name='itemName' value='".$row["itemName"]."'>".$row["itemName"]."</th>";
	echo "</tr>";
	
	echo "<tr>";
	echo "<td rowspan='6' weight='20%' align='center'>";
	echo "<img src=/bookstore/bookstaff/".$row["itemImage"]." height='200' weight='200' style='margin:10 10 10 10'>";
	echo "</td>";
	echo "</tr>";
	
	echo "<tr>";
	echo "<th width='15%'>ISBN:</th>";
	echo "<td width='65%'><input type='hidden' name='ISBN' value='".$row["ISBN"]."'>".$row["ISBN"]."</td>";
	echo "</tr>";
	
	echo "<tr>";
	echo "<th>Author:</th>";
	echo "<td>".$row["itemAuthor"]."</td>";
	echo "</tr>";
	
	echo "<tr>";
	echo "<th>Publisher:</th>";
	echo "<td>".$row["itemPublisher"]."</td>";
	echo "</tr>";
	
	echo "<tr>";
	echo "<th>Issue Date:</th>";
	echo "<td>".$row["itemDate"]."</td>";
	echo "</tr>";
	
	echo "<tr>";
	echo "<th>Category:</th>";
	echo "<td>".$row["itemCategory"]."</td>";
	echo "</tr>";
	
	echo "<tr>";
	echo "<td align='center'><br/>";
if($row[itemQuantity]>0){
	$tem = $row[itemQuantity];
	echo "<name='temQuantity'>";
	echo "<select name='temQuantity'>";
	for($j=1; $j<=$tem; $j++)
	{
	echo "<option value='$j'>".$j;
	echo "</option>";
	}
	echo "</select>";
	echo "<input type='hidden' name='ISBN' value='$row[ISBN]'>";
	echo "<input type='hidden' name='itemPrice' value='$row[itemPrice]'>";
	echo "<input type='submit' name='add' value='Add Cart'>";
}else{
	echo "<name='temQuantity' value='".$row["temQuantity"]."'>";
	echo "<select name='temQuantity' onchange='this.form.submit()' value='Save' name='Save''>";
	$temQuantityArray = array("1", "2", "3", "4", "5", "6", "7", "8", "9");
	for($m = 0; $m < 9 ; $m++)
	{if($row["temQuantity"] == $temQuantityArray[$m])
	{echo "<option selected>".$temQuantityArray[$m];
	}else{
	echo "<option>".$temQuantityArray[$m];
	}
	}
	echo "</select>";
	echo "<input type='hidden' name='ISBN' value='$row[ISBN]'>";
	echo "<input type='hidden' name='itemPrice' value='$row[itemPrice]'>";
	echo "<input type='submit' name='add' value='Add Cart'>";
}
	echo "</td>";
	echo "<th>Price:</th>";
	echo "<td><input type='hidden' name='itemPrice' value='".$row["itemPrice"]."'>RM";
	printf("%10.2f",$row["itemPrice"]);
	echo "</td>";
	echo "</tr>";
	
	echo "<tr>";
	echo "<td align='center'><br/>";
	echo "<div id='commonlink'>";
	echo "<a href='bookmenu.php'>Back To Result</a><br/>";
	echo "</div>";
	echo "<th>Available:</th>";
	echo "<td><input type='hidden' name='itemQuantity' value='".$row["itemQuantity"]."'>".$row["itemQuantity"]."</td>";
	echo "</tr>";
	
	echo "</form>";
	
	echo "<tr>";
	echo "<td colapsn='3' width='30%'>";
	echo "</td>";
	echo "</tr>";
	
	echo "<tr>";
	echo "<td colspan='3' width='100%'>";
	echo "<a name='summarybox'></a>";
?>

<DIV id="cntR"  style="float:left;display:block;clear:both;">
<DIV id="NewsTop">
<DIV id="NewsTop_tit">
<P class="topTit">Book Information</P>
<P class="topC0">Summary</P>
<?php
//<P class="topC0">Rating</P>
?>
<P class="topC0">Comment</P>
</DIV>
<DIV id="NewsTop_cnt">
<SPAN title="Don't delete me"></SPAN>
<SPAN>
<?php
echo "$row[itemSummary]";	
?>
</SPAN>
<!--<SPAN>
<?php
//echo "normal";	
?>
</SPAN>!-->
<SPAN>
<?php

$result2 = mysql_query("SELECT * FROM bookmessage WHERE ISBN = '$ISBN'");
$num_results2 = mysql_num_rows($result2);

echo "<table border='0' cellspacing='0' cellpadding='5' bordercolor='black' width='80%' align='center'>";

if($num_results2>0){
for ($j=0; $j <$num_results2; $j++)
{
$row2 = mysql_fetch_array($result2);

$ID = $row2['memLname'];
$result3 = mysql_query("SELECT memberImage FROM membership WHERE memberLname = '$ID'");
$row3 = mysql_fetch_array($result3);

echo "<tr>";
echo "<td width='5%'>".($j+1)."</td>";

$pic = $row['memberImage'];

if($row3['memberImage']!=""){
echo "<td width='5%'><a href='personalspace.php?membername=$ID'><img src=".$row3['memberImage']." width='50' height='50'></a></td>";
}else{
echo "<td width='5%'><a href='personalspace.php?membername=$ID'><img src='avatar.gif' width='50' height='50'></a></td>";
}
echo "<td width='70%'>".$row2['comment']."<br/>";
echo "<font size='1'>Commented By <a href='personalspace.php?membername=$ID'> ".$row2['memLname']." </a>, ".$row2['time']."</font></td>";
$memLname = $row2['memLname'];

if($_SESSION['membership']== $memLname)
{
echo "<form name='deletecomment' method='post' action='commentaction.php'>";
echo "<td width='25%'><input type='hidden' name='memLname' value='$username'><input type='hidden' name='ISBN' value='$ISBN'><input type='submit' name='Delete' value='Delete'></td>";
echo "</form>";
echo "</tr>";
}else{
echo "<td></td>";
echo "</tr>";
}
echo "<tr><td colspan='4'><br/></td></tr>";
}

}else{
echo "<tr>";
echo "<td colspan='4'><center>Currently no comment here.</center></td>";
echo "</tr>";
}

if($_SESSION['membership']!= null)
{
echo "<form name='bookcomment' method='post' action='commentaction.php'>";
echo "<tr>";
echo "<td colspan='4'><center><textarea name='bookcomment' rows='5' cols='100' maxlength='10000'></textarea></center></td>";
echo "</tr>";

echo "<tr>";
echo "<td align='right' colspan='3'><input type='hidden' name='memLname' value='$username'><input type='hidden' name='ISBN' value='$ISBN'><center><input type='submit' name='Submit' value='Submit'></td>";
echo "</tr>";
echo "</form>";
}else{
echo "<tr colspan='4'>";
echo "<td></td>";
echo "</tr>";
}
echo "</table>";
?>

</SPAN>
</DIV>
<SCRIPT>
var Tags=document.getElementById('NewsTop_tit').getElementsByTagName('p'); 
var TagsCnt=document.getElementById('NewsTop_cnt').getElementsByTagName('span'); 
var len=Tags.length; 
var flag=1;//ÐÞ¸ÄÄ¬ÈÏÖµ
for(i=1;i<len;i++){
Tags[i].value = i;
Tags[i].onmouseover=function(){changeNav(this.value)}; 
TagsCnt[i].className='undis'; 
}
Tags[flag].className='topC1';
TagsCnt[flag].className='dis';
function changeNav(v){ 
Tags[flag].className='topC0';
TagsCnt[flag].className='undis';
flag=v; 
Tags[v].className='topC1';
TagsCnt[v].className='dis';
}
</SCRIPT>
</DIV>
</DIV>

</td>
</tr>
	
	
<?php
	
	echo "</tr>";
	
echo "</table>";
echo "</div>";
echo "</center>";

$db = mysql_close();

?>