<?php
$records_per_page = 10;
if(isset($_GET["Pages"])){
	$pages = intval($_GET["Pages"]);
	}else{
	$pages = 1;
}

$total_records = mysql_num_rows($result);
$total_pages;

if($total_records){
   if($total_records<$records_per_page){
   $total_pages = 1;
   }
   else if($total_records%$records_per_page){
   $total_pages = (int)($total_records/$records_per_page) + 1;
   }else{
   $total_pages = $total_records/$records_per_page;                     
   }
}
else{
   $total_pages = 0;
}

$offset = ($pages - 1)*$records_per_page;
@mysql_data_seek($result, $offset);

echo "<div id='mainpage'>";
echo "<table width='70%'>";
echo "<caption><img src='Picture/book.gif' width='30' height='30' />Daily Bookstore Management System - Salary	</caption>";

echo "<div id='bookmenu'>";

echo "<table border='1' cellspacing='0' cellpadding='5' bordercolor='white' align='center' width='90%'>";
echo "<tr>";
echo "<td colspan='11'>";
echo "Total staff found: ".$total_records."";
echo "</td>";
echo "</tr>";

echo "<tr bgcolor='gray' style='color:lightblue'>";
echo "<td width='3'>No.</td>";
echo "<td width='50'>Staff ID</td>";
echo "<td width='200'>Staff Name</td>";
echo "<td width='10'>Salary</td>";
echo "<td width='10'>EPF</td>";
echo "<td width='3'>Socso</td>";
echo "<td width='3'>Allowance</td>";
echo "<td width='3'>Bonus</td>";
echo "<td>Edit</td>";
echo "<td>Delete</td>";
echo "</tr>";

$j = 1;
if($j<$records_per_page);{
for($i=0; $i<$records_per_page; $i++)
{
	$row = mysql_fetch_array($result);
	if($row["staffName"]!=""){
	echo "<tr>";
	echo "<td>".($i + 1)."</td>";
	echo "<td>".$row["staffID"]."</td>";
	echo "<td>".$row["staffName"]."</td>";
	echo "<td>".$row["staffSalary"]."</td>";
	echo "<td>".$row["staffEPF"]."</td>";
	echo "<td>".$row["staffSocso"]."</td>";
	echo "<td>".$row["staffHour"]."</td>";
	echo "<td>".$row["staffOT"]."</td>";
	echo "<td><a href='editstaffsalary.php?staffID=".$row["staffID"]."'>Edit</a></td>";
	echo "<td><a href='deletebook.php?ISBN=".$row["ISBN"]."'>Delete</a></td>";
	echo "</tr>";
	}
	}
$j++;
}	
echo "</table>";
echo "</div>";

echo "<hr/>";

echo "</div>";
echo "<center>";
echo "<div id='page'>";
if($pages>1){
if(($keyword=="")||($searchBy=="")){
echo "<a href='book.php?&sort=".$sort."&Pages=".($pages-1)."'>&nbsp;[Previous]&nbsp;</a>";
}else{
echo "<a href='book.php?keyword=".$keyword."&searchBy=".$searchBy."&search=Search&sort=".$sort."&Pages=".($pages-1)."'>&nbsp;[Previous]&nbsp;</a>";
}
}

for($k=1; $k<=$total_pages; $k++){
	if($k!=$pages){
	if(($keyword=="")||($searchBy=="")){
	echo "<a href=\"book.php?&sort=".$sort."&Pages=".$k."\">&nbsp;[".$k."]&nbsp;</a>";
	}else{
	echo "<a href=\"book.php?keyword=".$keyword."&searchBy=".$searchBy."&search=Search&sort=".$sort."&Pages=".$k."\">".$k."</a>";
	}
	}else
	{
	echo "&nbsp;[$k]&nbsp;"."";
	}
}

if($pages<$total_pages){
if(($keyword=="")||($searchBy=="")){
echo "<a href='book.php?&sort=".$sort."&Pages=".($pages+1)."'>&nbsp;[Next]&nbsp;</a>";
}else{
echo "<a href='book.php?keyword=".$keyword."&searchBy=".$searchBy."&search=Search&sort=".$sort."&Pages=".($pages+1)."'>&nbsp;[Next]&nbsp;</a>";
}
}

echo "</div>";

echo "</center>";

$db = mysql_close();
?>