<?php
include("../session.php");
include("../connect.php");

$user=$_SESSION['company'];				
?>
<html>
<head>
<title>User Page(Company profile)</title>
<link href="header.css" rel="stylesheet" type="text/css"/>
<style type="text/css">
	a#pag {color:black;font-family: Century Gothic, Segoe UI; text-decoration:none; font-size:13px}
</style>
<script type="text/JavaScript">
 
function confirmDelete(){
var agree=confirm("Are you sure you want to move selected file to trash?");
if (agree)
     return true ;
else
     return false ;
}
</script>
<script type="text/JavaScript">
 
function confirmA(all){

var countINT = 0;
for (i = 0; i < all; i++){
	if(document.getElementById("check"+i).checked){
		countINT = countINT  + 1;
	}else{}	
}
if(countINT < 1){
	//alert(all+","+countINT);
	alert("AT least select one");
	return false;
}else{
	return true;
}
}

function checkempty(getvalue){
var keywordA = getvalue;
if (keywordA.length < 1){
alert("Please fill in something at search column");
return false;
}else{
return true;
}
}

</script>
</head>
<div id="content2">
<body>
<!-----------------Outer table--------------->
<table width=1000 border=0 cellspacing=10 cellpadding=3 >
<tr>
	<td colspan=2>
	<?php include("head.php");?>
	</td>
	</tr>
<tr>
	<td colspan=2>
	<div class=main>&nbsp;&nbsp;>>
			<a href="<?php echo"company.php";?>">&nbsp;Home&nbsp;</a>>>
			&nbsp;Remove Product&nbsp;
			</div></td>
	</tr>
<tr>
	
	<td valign=top colspan=2>
	<!--------------------Inner table 2----------------------->
<div id="inner">
<?php include("productHead.php");?>
<form name="searchForm" method="post">
<table border="0" cellspacing="5" cellpadding="5" align="right">
<tr>
	<td align="right">
		<input type="hidden" name="searchBy" value="pName"/>
		<input type="text" id="keyword" name="keywords">&nbsp;&nbsp;
		<input type="submit" name="search" value="Search Name" style = "background-color: #9191FF; border: 0px; color: #FBFDFB; width:100; height:23; font-family: Segoe UI" onclick="return checkempty(keyword.value)">
		<input type="submit" name="showAll" value="ShowAll" style = "background-color: #9191FF; border: 0px; color: #FBFDFB; width:70; height:23; font-family: Segoe UI">
	</td>
</tr>
</table>
</form>
<?php
if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE){ 
		echo "<br/><br/><br/>";
} 
elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== FALSE){
		echo "<br/><br/><br/>";
}
elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== FALSE){ 
		echo "<br/>";
}			
elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'Safari') !== FALSE){ 
}			
else{ 
}			
?>	
<?php
if($_POST["search"] == "Search Name"){
	$searchBy = $_POST["searchBy"];
	$keywords = $_POST["keywords"];
	$result = mysql_query("SELECT * FROM product WHERE ".$searchBy." LIKE '%".$keywords."%' AND companyID='$user' AND status='available' ORDER BY id");
}
else if($_POST["showAll"] == "ShowAll"){
	$limit = 5; //max displayed per page
    $start = $_GET['start']; //get start variable
    if(isset($_POST["showAll"]))
	{	$start = 0;}
 	else
 	{	if (!$start) {$start = 0;}}
	
	$sql = mysql_query("select * from product where companyID='$user' AND status='available' ORDER BY id ");
	$record_count = mysql_num_rows($sql);
	$max_pages = $record_count / $limit;
	
	$result = mysql_query("select * from product where companyID='$user' AND status='available' ORDER BY id LIMIT $start,$limit");
}
else{
	$limit = 5; //max displayed per page
    $start = $_GET['start']; //get start variable
    if(isset($_POST["showAll"]))
	{	$start = 0;}
 	else
 	{	if (!$start) {$start = 0;}}
	
	$sql = mysql_query("select * from product where companyID='$user' AND status='available' ORDER BY id ");
	$record_count = mysql_num_rows($sql);
	$max_pages = $record_count / $limit;
	
	$result = mysql_query("select * from product where companyID='$user' AND status='available' ORDER BY id LIMIT $start,$limit");
}

echo "<form action='removeproduct2.php' method='post' onsubmit='return confirmDelete()'>";
echo "<table align = 'center' border = '1' cellpadding = '5' cellspacing = '2' width = '850' style = 'border:solid;border-color:white'>";
echo "<tr style='background-color:#76888f'>";
//copy add
echo "<th id = 'table_data' width='5%'></th>";
echo "<th id = 'table_data' width='10%'> ID</th>";
echo "<th id = 'table_data' width='25%'> Product Name</th>";
echo "<th id = 'table_data' width='15%'> Picture</th>";
//until here
echo "</tr>";

$i=0;
while($row = mysql_fetch_array($result)){		
	$ID=$row['id'];
	$checkpic = $ID.".";
	echo"<tr style='background-color:#BDBDBD'>";
	echo "<td align='center'width = '10'><input type='checkbox' name='check[$i]' id='check".$i."' value=''/></td>";
	echo "<td align=center><input type='hidden' name='id[]' value='".$row["id"]."'>" . $row['id']."</td>";
	echo "<td align=center><input type='hidden' name='name[]' value='".$row["pName"]."'>" . $row['pName']."</td>";
	if ($row["productPic"] == $checkpic){
		echo "<td align=center><img src='album/NoImage.jpg' width = '80' height = '80'/></td>";
	}
	else{
		echo "<td align=center><img src='album/$row[productPic]' width = '80' height = '80'/></td>";
	}
	echo "</tr>";
	$i++;			
}

echo "<tr align='center' style='background-color:#76888f'><td colspan='4'><input type='submit' name='submit' onclick='return confirmA($i)' value='Move selected product to trash'></td></tr>";
echo "</table>";
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



echo "<div id='pageNavi'>";
//setup prev and next variables
$prev = $start - $limit;
$next = $start + $limit;

//show prev button
echo "<p align='center'>";
if (!($start<=0))
       {echo "<a href='removeproduct.php?start=$prev' id='pag'>Previous</a> ";}

//show page numbers and set variable for first page
$p=1;
for ($x=0;$x<$record_count;$x=$x+$limit)
{
 if ($start!=$x)
    {echo "<a href='removeproduct.php?start=$x' id='pag'>$p</a> ";}
 else
    {echo "<a href='removeproduct.php?start=$x' style='color: #ff2626; font-family: Segoe UI Light' id='pag'><b>Page $p </b></a> ";}
 $p++;
}

//show next button
if (!($start>=$record_count-$limit))
       {echo " <a href='removeproduct.php?start=$next' id='pag'>Next</a>";}
echo "</p>";

echo "</div>";

//$result->free();
echo"</form>";
?>
<table width="100%">
<tr>
	<td align="center">
		<a href="company.php">
			<font size="4cm" color="purple">Back</font>
		</a>
	</td>
</tr>
</table>

	</div>
	<!----------------------End inner table 2-------------------->
	
	</td>
	</tr>
</table>
<!-----------------------End outer table-------------------------->
</div>

<?php 
include("../closeconnection.php");
?>

</body>
</html>