<?php
include("session.php");
include("connect.php");
?>
<html>
<title>ShakeitMAma.Com</title>
<head>
<?php
if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) {
	echo"<link href='item2.css' rel='stylesheet' type='text/css'/>";
}else{
	echo"<link href='item.css' rel='stylesheet' type='text/css'/>";
}	
?>
<style type="text/css">
body {
	font-family: myriad, Sans-Serif, Verdana, Tahoma, Arial;
}

</style>
<script type="text/JavaScript">
function jumppage(numpage){
var gettype = document.getElementById("type").value;
var num = numpage;
window.location="otherlistproduct.php?type="+gettype+"&page="+num;
}
</script>
</head>
<body>
<?php
$getype = "Other";
echo"<input type='hidden' id='type' value='$getype'>";

echo "<br/>";
	$per_page = 9;
	if(($getype == "")||($getype == "all")){
		$query1=mysql_query("SELECT * from product where status='available'");
	}
	else{
		$query1=mysql_query("SELECT * from product where status='available' and type='$getype'");
	}
	
	
	$total=ceil(mysql_num_rows($query1)/$per_page);

	$page =(isset($_GET['page'])) ? (int) $_GET['page'] :1;
	$start=($page-1)*$per_page;
	$page1 = $_GET['page'];
	if($_GET['page'] == ""){
		$pagerewind = 1;
		$pageprev = 1;
	}else{
		$pageprev = $_GET['page'] - 1;	
		$pagerewind = 1;
	}
//check item empty or not??	
if(mysql_num_rows($query1) > 0){	
echo "<table border='0' align='center'>";
echo "<tr>";
	if($page1 != $pagerewind){
		echo"<td><a href='otherlistproduct.php?type=$getype&page=$pagerewind'><img src='button/rewind.png' border='0'></a></td>
			<td><a href='otherlistproduct.php?type=$getype&page=$pageprev'><img src='button/prev.png' border='0'></a></td>";
	}
	else{
		echo"<td><img src='button/rewind.png' border='0'></td>
			<td><img src='button/prev.png' border='0'></td>";
	}
	echo"<td>";
	
	echo"<select onchange='jumppage(this.value)'>";
	
	for($i=1;$i<=$total;$i++){				
		if($i == $_GET['page']){
			echo"<option value='$page1' selected='selected'>$page1</option>";
		}else{
			echo"<option value='$i'>$i</option>";
		}	
	//$i++;	
	}
	if($_GET['page'] == ""){
		$pagenext =  2;	
		$pageforward = $i-1;
	}else{
		$pagenext = $_GET['page'] + 1;	
		$pageforward = $i-1;
	}
	echo"</select>";
	echo "</td>";
	if($page1 != $pageforward){
		echo"<td><a href='otherlistproduct.php?type=$getype&page=$pagenext'><img src='button/next.png' border='0'></a></td>
			<td><a href='otherlistproduct.php?type=$getype&page=$pageforward'><img src='button/forward.png' border='0'></a></td>";
	}
	else{
		echo"<td><img src='button/next.png' border='0'></td>
			<td><img src='button/forward.png' border='0'></td>";
	}	
echo "</tr>";
echo "</table>";
echo "<br/>";
echo "<br/>";
}

if(($getype == "")||($getype == "all")){
	$query=mysql_query("select * from product where status='available' order by sorttime DESC limit $start,$per_page");
}
else{
	$query=mysql_query("select * from product where status='available' and type='$getype' order by sorttime DESC limit $start,$per_page");
}

$count = mysql_num_rows($query);
//check item empty or not??	
if (mysql_num_rows($query) > 0){

echo"<table border='0' align='left'>";
echo"<tr>";
$a = 1;

while($row = mysql_fetch_array($query)){
$ID=$row['id'];
$checkpic = $ID.".";
$query3=mysql_query("select * from promotion where pID='$ID'");
$checkP=mysql_fetch_array($query3);
echo"<td width='316px' height='111px'>";
echo"<a class='linkto' href='product.php?id=$ID'>";
echo"<div class='listbox'>
	<ul class='applist'>
		<li class='norm'> 
			<div class='listiconbox'><div class='overlay'>";			
				if ($row['productPic'] == $checkpic){
					echo"<img src='../company/album/NoImage.jpg' width = '75px' height = '75px' border='0'/>";
				}else{
					echo"<img src='../company/album/$row[productPic]' width = '75px' height = '75px' border='0'/>";
				}			
		echo"</div>
			</div>
			<div class='listdescbox'>
				<div class='fadeout'></div>
				<div class='appname'>".$row["pName"]."<div>
				<div class='listco'>Category : ".$row['type2']."</div>";
				//check promotion
				if($checkP['status'] == "on"){
					echo"<div class='listdets'>Price : ";printf("%10.2f",$row["price"]);echo" ".$row["dollar"]."</br>Promotion : ";printf("%10.2f",$checkP["promotionprice"]);echo" ".$row["dollar"]."</div>";
				}else if($checkP['status'] == "off"){
					echo"<div class='listdets'>Price : ";printf("%10.2f",$row["price"]);echo" ".$row["dollar"]."</div>";
				}
			echo"</div>
		</li>
	</ul>
</div>";
echo"</a>";
//check promotion
if($checkP['status'] == "on"){
	echo"<div class='promotion'></div>";
}else if($checkP['status'] == "off"){
}
echo"</td>";
if ($a == $count){
echo"</tr>";
}
elseif(($a%3) == 0){
echo "</tr><tr>";
}
else{}
$a++;
}
echo"</table>";
}
else{
	echo"<center><h1>No Product</h1></center>";
}
?>
<?php
include("closeconnection.php");
?>
</body>
</html>