<?
include_once('includes/top.php');
include_once('opendb.php');
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
//$br=$_SESSION['branch'];
if(strlen($user)<=0)
{
  print "<script> alert('Invalid User'); document.location='inde.php' </script>";
  return;
}
?>
<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>Kerala Khadi & Village Industries Board</title>
<script type="text/javascript" src="scripts/jquery-latest.js"></script>
<link type="text/css" href="includes/style1.css" rel="stylesheet" />
<link type="text/css" href="css/form.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.6.1.min.js"></script>
<script type="text/javascript">
        $(function() {
          if ($.browser.msie && $.browser.version.substr(0,1)<7)
          {
			$('li').has('ul').mouseover(function(){
				$(this).children('ul').show();
				}).mouseout(function(){
				$(this).children('ul').hide();
				})
          }
        });        
</script>
<script type="text/javascript">
    $(document).ready(function() {
        var cont_left = $("#container").position().left;
        $("a img").hover(function() {
            // hover in
            //$(this).parent().parent().css("z-index", 1);
            $(this).animate({
               height: "110",
               width: "110",
              
            }, "fast");
        }, function() {
            // hover out
         //   $(this).parent().parent().css("z-index", 0);
            $(this).animate({
                height: "80",
                width: "80",
                
            }, "fast");
        });
        
        $(".img").each(function(index) {
            var left = (index * 160) + cont_left;
            $(this).css("left", left + "px");
        });
    });
</script>
<script type="text/javascript">

/***********************************************
* Disable "Enter" key in Form script
* This notice must stay intact for use
***********************************************/
                
function handleEnter (field, event) {
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) {
			var i;
			for (i = 0; i < field.form.elements.length; i++)
				if (field == field.form.elements[i])
					break;
			i = (i + 1) % field.form.elements.length;
			field.form.elements[i].focus();
			return false;
		} 
		else
		return true;
	}      

</script>
<style>
#txt{
font-family: Arial, Helvetica;
background-color: #F2F2F2;

}
table.form{
font-weight: normal;
} 
</style>
<style>
.cont{
      background-color:#fff;
      //background:url(images/bg-inner.jpg) #e9e0c3 repeat-x;
      width: 100%;position: absolute ;
      height:99%;
      /* Optional - just for DIV)*/
      //border: solid 1px #000000;
      -moz-box-shadow: 0px 5px 5px #888;
      -webkit-box-shadow: 0px 5px 5px #888;
      box-shadow: 0px 5px 10px #888;
    
      }


#pg{
       text-decoration:none;
}
#pg button{
       background-color:#3b5998;
}
</style>

<? //include('includes/top.php'); ?>
<table class="container"><tr><td>

<font style="font-family: 'Trebuchet MS',Verdana,Helvetica,sans-serif; font-size:15px;">  &nbsp;&nbsp;Reports >> Search Item</font>

<style>
th{background-color:steelblue;color:white}
</style>
<link rel="stylesheet" href="style.css" type="text/css" />
<script>
function valid()
{
 
 if(document.f1.pcode.value.length<=0)
 {
   alert("Invalid Partcode.");
   document.f1.pcode.focus();
   return false;
 }

if(document.f1.pname.value.length<=0)
 {
   alert("Invalid Name.");
   document.f1.pname.focus();
   return false;
 }

if ((document.f1.fromyr.value!="") && (isNaN(document.f1.fromyr.value))) 
 {
   alert("Please Enter Numeric Values Only");
   document.f1.fromyr.focus();
   return false;
 }
if (document.f1.fromyr.value.length != 4) 
	{
            alert("FromYear is not proper. Please check");
		document.f1.fromyr.focus();
            return false;
	}

  if ((document.f1.toyear.value!="") && (isNaN(document.f1.toyear.value))) 
	{
    	alert("Please Enter Numeric Values Only");
   	document.f1.toyear.focus();
   	return false;
	}
	if (document.f1.toyear.value.length != 4) 
	{
            alert("ToYear is not proper. Please check");
		document.f1.toyear.focus();
            return false;
	}

if(document.f1.srate.value.length<=0)
 {
   alert("Invalid SaleRate.");
   document.f1.srate.focus();
   return false;
 }
if(document.f1.prate.value.length<=0)
 {
   alert("Invalid Purchase Rate.");
   document.f1.prate.focus();
   return false;
 }



}
</script>
<script type="text/javascript">

/***********************************************
* Disable "Enter" key in Form script- By Nurul Fadilah(nurul@REMOVETHISvolmedia.com)
* This notice must stay intact for use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
                
function handleEnter (field, event) {
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) {
			var i;
			for (i = 0; i < field.form.elements.length; i++)
				if (field == field.form.elements[i])
					break;
			i = (i + 1) % field.form.elements.length;
			field.form.elements[i].focus();
			return false;
		} 
		else
		return true;
	}      
function pgnfn(str){
            document.getElementById('pgbtn'+str).style.background = "#ccc";
}
</script>
<link href="css/pagination.css" rel="stylesheet" type="text/css" />
<link href="css/grey.css" rel="stylesheet" type="text/css" />
<style>
.paginate {
	//font-family:Arial, Helvetica, sans-serif;
	padding: 3px;
	margin: 3px;
}

.paginate a {
	padding:2px 5px 2px 5px;
	margin:2px;
	border:1px solid #999;
	text-decoration:none;
	color: #666;
}
.paginate a:hover, .paginate a:active {
	border: 1px solid #999;
	color: #000;
}
.paginate span.current {
    margin: 2px;
	padding: 2px 5px 2px 5px;
		border: 1px solid #999;
		
		font-weight: bold;
		background-color: #999;
		color: #FFF;
	}
	.paginate span.disabled {
		padding:2px 5px 2px 5px;
		margin:2px;
		border:1px solid #eee;
		color:#DDD;
	}
	
		
	
</style>
<table align=center><tr><td id='sea_td'><form name='f2' action='' method='post'>
<input type='search' name='seaprice' placeholder='Search By Price'>&nbsp;OR <input type='search' name='sea' placeholder='Search By Itemcode'>&nbsp;OR <input type='search' name='seaname' placeholder='Search By Itemname'>&nbsp;OR <input type='search' name='seagrp' placeholder='Search By Group'>&nbsp;OR <input type='search' name='seasub_grp' placeholder='Search By Subgroup'>&nbsp;
<input type='submit' value='Go' id='reg_sea_bttn' class='sub_btn' name='search_bttn'/>
</form></td></tr></table>
<br>&nbsp;
<?

$targetpage = "seaitem.php";

$limit = 20; 
$sea= $_REQUEST['sea'];
$seaname= $_REQUEST['seaname'];
$seaprice = $_REQUEST['seaprice'];
$seagrp = $_REQUEST['seagrp'];
$seasub_grp = $_REQUEST['seasub_grp'];
if($sea!='')
{
	$query = "SELECT COUNT(*) as num FROM partmaster where partcode like '%$sea%' order by partcode";	
	$total_pages = mysqli_fetch_array(mysqli_query($db,$query));
	$total_pages = $total_pages[num];
}
else if($_REQUEST['seaname']!='')
{
	$query = "SELECT COUNT(*) as num FROM partmaster where partname like '%$seaname%' order by partcode";
	$total_pages = mysqli_fetch_array(mysqli_query($db,$query));
	$total_pages = $total_pages[num];
}
else if($_REQUEST['seaprice']!='')
{
	$query = "SELECT COUNT(*) as num FROM spareprmast where lstprice = '$seaprice'";
	$total_pages = mysqli_fetch_array(mysqli_query($db,$query));
	$total_pages = $total_pages[num];
}
else if($_REQUEST['seagrp']!='')
{
	$query = "SELECT COUNT(*) as num FROM partmaster where gname like '%$seagrp%' order by partcode";
	$total_pages = mysqli_fetch_array(mysqli_query($db,$query));
	$total_pages = $total_pages[num];
}
else if($_REQUEST['seasub_grp']!='')
{
	$query = "SELECT COUNT(*) as num FROM partmaster where subgroup like '%$seasub_grp%' order by partcode";
	$total_pages = mysqli_fetch_array(mysqli_query($db,$query));
	$total_pages = $total_pages[num];
}
else
{
$query = "SELECT COUNT(*) as num FROM partmaster";
	$total_pages = mysqli_fetch_array(mysqli_query($db,$query));
	$total_pages = $total_pages[num];
}

	$stages = 3;
	$page = mysqli_escape_string($_GET['page']);
	if($page){
		$start = ($page - 1) * $limit; 
	}else{
		$start = 0;	
		}
	

if($_REQUEST['sea']!='')
{
	$query1 = "SELECT * FROM partmaster where partcode like '%$sea%' order by partcode LIMIT $start, $limit";

	//$result = mysqli_query($db,$query1);

if ($page == 0){$page = 1;}
	$prev = $page - 1;	
	$next = $page + 1;							
	$lastpage = ceil($total_pages/$limit);		
	$LastPagem1 = $lastpage - 1;					
	
	
	$paginate = '';
	if($lastpage > 1)
	{	
		$paginate .= "<div class='paginate'>";
		// Previous
		if ($page > 1){
			$paginate.= "<a href='$targetpage?sea=$sea&page=$prev'>previous</a>";
		}else{
			$paginate.= "<span class='disabled'>previous</span>";	}
			

		
		// Pages	
		if ($lastpage < 7 + ($stages * 2))	// Not enough pages to breaking it up
		{	
			for ($counter = 1; $counter <= $lastpage; $counter++)
			{
				if ($counter == $page){
					$paginate.= "<span class='current'>$counter</span>";
				}else{
					$paginate.= "<a href='$targetpage?sea=$sea&page=$counter'>$counter</a>";}					
			}
		}
		elseif($lastpage > 5 + ($stages * 2))	// Enough pages to hide a few?
		{
			// Beginning only hide later pages
			if($page < 1 + ($stages * 2))		
			{
for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
				{
					if ($counter == $page){
						$paginate.= "<span class='current'>$counter</span>";
					}else{
						$paginate.= "<a href='$targetpage?sea=$sea&page=$counter'>$counter</a>";}					
				}
				$paginate.= "...";
				$paginate.= "<a href='$targetpage?sea=$sea&page=$LastPagem1'>$LastPagem1</a>";
				$paginate.= "<a href='$targetpage?sea=$sea&page=$lastpage'>$lastpage</a>";		
			}
			// Middle hide some front and some back
			elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))
			{
				$paginate.= "<a href='$targetpage?sea=$sea&page=1'>1</a>";
				$paginate.= "<a href='$targetpage?sea=$sea&page=2'>2</a>";
				$paginate.= "...";
				for ($counter = $page - $stages; $counter <= $page + $stages; $counter++)
				{
					if ($counter == $page){
						$paginate.= "<span class='current'>$counter</span>";
					}else{
						$paginate.= "<a href='$targetpage?sea=$sea&page=$counter'>$counter</a>";}					
				}
				$paginate.= "...";
				$paginate.= "<a href='$targetpage?sea=$sea&page=$LastPagem1'>$LastPagem1</a>";
				$paginate.= "<a href='$targetpage?sea=$sea&page=$lastpage'>$lastpage</a>";		
			}
			// End only hide early pages
			else
			{
				$paginate.= "<a href='$targetpage?sea=$sea&page=1'>1</a>";
				$paginate.= "<a href='$targetpage?sea=$sea&page=2'>2</a>";
				$paginate.= "...";
				for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
				{
					if ($counter == $page){
						$paginate.= "<span class='current'>$counter</span>";
					}else{
						$paginate.= "<a href='$targetpage?sea=$sea&page=$counter'>$counter</a>";}					
				}
			}
		}
					
				// Next
		if ($page < $counter - 1){ 
			$paginate.= "<a href='$targetpage?sea=$sea&page=$next'>next</a>";
		}else{
			$paginate.= "<span class='disabled'>next</span>";
			}
			
		$paginate.= "</div>";		
	
	
}

}
else if($_REQUEST['seaname']!='')
{
	$query1 = "SELECT * FROM partmaster where partname like '%$seaname%' order by partcode LIMIT $start, $limit";

	//$result = mysqli_query($db,$query1);

if ($page == 0){$page = 1;}
	$prev = $page - 1;	
	$next = $page + 1;							
	$lastpage = ceil($total_pages/$limit);		
	$LastPagem1 = $lastpage - 1;					
	
	
	$paginate = '';
	if($lastpage > 1)
	{	
$paginate .= "<div class='paginate'>";
		// Previous
		if ($page > 1){
			$paginate.= "<a href='$targetpage?seaname=$seaname&page=$prev'>previous</a>";
		}else{
			$paginate.= "<span class='disabled'>previous</span>";	}
			

		
		// Pages	
		if ($lastpage < 7 + ($stages * 2))	// Not enough pages to breaking it up
		{	
			for ($counter = 1; $counter <= $lastpage; $counter++)
			{
				if ($counter == $page){
					$paginate.= "<span class='current'>$counter</span>";
				}else{
					$paginate.= "<a href='$targetpage?seaname=$seaname&page=$counter'>$counter</a>";}					
			}
		}
		elseif($lastpage > 5 + ($stages * 2))	// Enough pages to hide a few?
		{
			// Beginning only hide later pages
			if($page < 1 + ($stages * 2))		
			{
for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
				{
					if ($counter == $page){
						$paginate.= "<span class='current'>$counter</span>";
					}else{
						$paginate.= "<a href='$targetpage?seaname=$seaname&page=$counter'>$counter</a>";}					
				}
				$paginate.= "...";
				$paginate.= "<a href='$targetpage?seaname=$seaname&page=$LastPagem1'>$LastPagem1</a>";
				$paginate.= "<a href='$targetpage?seaname=$seaname&page=$lastpage'>$lastpage</a>";		
			}
			// Middle hide some front and some back
			elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))
			{
				$paginate.= "<a href='$targetpage?seaname=$seaname&page=1'>1</a>";
				$paginate.= "<a href='$targetpage?seaname=$seaname&page=2'>2</a>";
				$paginate.= "...";
				for ($counter = $page - $stages; $counter <= $page + $stages; $counter++)
				{
					if ($counter == $page){
						$paginate.= "<span class='current'>$counter</span>";
					}else{
						$paginate.= "<a href='$targetpage?seaname=$seaname&page=$counter'>$counter</a>";}					
				}
				$paginate.= "...";
				$paginate.= "<a href='$targetpage?seaname=$seaname&page=$LastPagem1'>$LastPagem1</a>";
				$paginate.= "<a href='$targetpage?seaname=$seaname&page=$lastpage'>$lastpage</a>";		
			}
			// End only hide early pages
			else
			{
				$paginate.= "<a href='$targetpage?seaname=$seaname&page=1'>1</a>";
				$paginate.= "<a href='$targetpage?seaname=$seaname&page=2'>2</a>";
				$paginate.= "...";
				for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
				{
					if ($counter == $page){
						$paginate.= "<span class='current'>$counter</span>";
					}else{
						$paginate.= "<a href='$targetpage?seaname=$seaname&page=$counter'>$counter</a>";}					
				}
			}
		}
					
				// Next
		if ($page < $counter - 1){ 
			$paginate.= "<a href='$targetpage?seaname=$seaname&page=$next'>next</a>";
		}else{
			$paginate.= "<span class='disabled'>next</span>";
			}
			
		$paginate.= "</div>";		
	
	
}

}
else if($_REQUEST['seagrp']!='')
{
	$query1 = "SELECT * FROM partmaster where gname like '%$seagrp%' order by partcode LIMIT $start, $limit";
	//$result = mysqli_query($db,$query1);

if ($page == 0){$page = 1;}
	$prev = $page - 1;	
	$next = $page + 1;							
	$lastpage = ceil($total_pages/$limit);		
	$LastPagem1 = $lastpage - 1;					
	
	
	$paginate = '';
	if($lastpage > 1)
	{	
$paginate .= "<div class='paginate'>";
		// Previous
		if ($page > 1){
			$paginate.= "<a href='$targetpage?seagrp=$seagrp&page=$prev'>previous</a>";
		}else{
			$paginate.= "<span class='disabled'>previous</span>";	}
			

		
		// Pages	
		if ($lastpage < 7 + ($stages * 2))	// Not enough pages to breaking it up
		{	
			for ($counter = 1; $counter <= $lastpage; $counter++)
			{
				if ($counter == $page){
					$paginate.= "<span class='current'>$counter</span>";
				}else{
					$paginate.= "<a href='$targetpage?seagrp=$seagrp&page=$counter'>$counter</a>";}					
			}
		}
		elseif($lastpage > 5 + ($stages * 2))	// Enough pages to hide a few?
		{
			// Beginning only hide later pages
			if($page < 1 + ($stages * 2))		
			{
for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
				{
					if ($counter == $page){
						$paginate.= "<span class='current'>$counter</span>";
					}else{
						$paginate.= "<a href='$targetpage?seagrp=$seagrp&page=$counter'>$counter</a>";}					
				}
				$paginate.= "...";
				$paginate.= "<a href='$targetpage?seagrp=$seagrp&page=$LastPagem1'>$LastPagem1</a>";
				$paginate.= "<a href='$targetpage?seagrp=$seagrp&page=$lastpage'>$lastpage</a>";		
			}
			// Middle hide some front and some back
			elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))
			{
				$paginate.= "<a href='$targetpage?seagrp=$seagrp&page=1'>1</a>";
				$paginate.= "<a href='$targetpage?seagrp=$seagrp&page=2'>2</a>";
				$paginate.= "...";
				for ($counter = $page - $stages; $counter <= $page + $stages; $counter++)
				{
					if ($counter == $page){
						$paginate.= "<span class='current'>$counter</span>";
					}else{
						$paginate.= "<a href='$targetpage?seagrp=$seagrp&page=$counter'>$counter</a>";}					
				}
				$paginate.= "...";
				$paginate.= "<a href='$targetpage?seagrp=$seagrp&page=$LastPagem1'>$LastPagem1</a>";
				$paginate.= "<a href='$targetpage?seagrp=$seagrp&page=$lastpage'>$lastpage</a>";		
			}
			// End only hide early pages
			else
			{
				$paginate.= "<a href='$targetpage?seagrp=$seagrp&page=1'>1</a>";
				$paginate.= "<a href='$targetpage?seagrp=$seagrp&page=2'>2</a>";
				$paginate.= "...";
				for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
				{
					if ($counter == $page){
						$paginate.= "<span class='current'>$counter</span>";
					}else{
						$paginate.= "<a href='$targetpage?seagrp=$seagrp&page=$counter'>$counter</a>";}					
				}
			}
		}
					
				// Next
		if ($page < $counter - 1){ 
			$paginate.= "<a href='$targetpage?seagrp=$seagrp&page=$next'>next</a>";
		}else{
			$paginate.= "<span class='disabled'>next</span>";
			}
			
		$paginate.= "</div>";		
	
	
}

}
else if($_REQUEST['seasub_grp']!='')
{
	$query1 = "SELECT * FROM partmaster where subgroup like '%$seasub_grp%' order by partcode LIMIT $start, $limit";
	//$result = mysqli_query($db,$query1);

if ($page == 0){$page = 1;}
	$prev = $page - 1;	
	$next = $page + 1;							
	$lastpage = ceil($total_pages/$limit);		
	$LastPagem1 = $lastpage - 1;					
	
	
	$paginate = '';
	if($lastpage > 1)
	{	
$paginate .= "<div class='paginate'>";
		// Previous
		if ($page > 1){
			$paginate.= "<a href='$targetpage?seasub_grp=$seasub_grp&page=$prev'>previous</a>";
		}else{
			$paginate.= "<span class='disabled'>previous</span>";	}
			

		
		// Pages	
		if ($lastpage < 7 + ($stages * 2))	// Not enough pages to breaking it up
		{	
			for ($counter = 1; $counter <= $lastpage; $counter++)
			{
				if ($counter == $page){
					$paginate.= "<span class='current'>$counter</span>";
				}else{
					$paginate.= "<a href='$targetpage?seasub_grp=$seasub_grp&page=$counter'>$counter</a>";}					
			}
		}
		elseif($lastpage > 5 + ($stages * 2))	// Enough pages to hide a few?
		{
			// Beginning only hide later pages
			if($page < 1 + ($stages * 2))		
			{
for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
				{
					if ($counter == $page){
						$paginate.= "<span class='current'>$counter</span>";
					}else{
						$paginate.= "<a href='$targetpage?seasub_grp=$seasub_grp&page=$counter'>$counter</a>";}					
				}
				$paginate.= "...";
				$paginate.= "<a href='$targetpage?seasub_grp=$seasub_grp&page=$LastPagem1'>$LastPagem1</a>";
				$paginate.= "<a href='$targetpage?seasub_grp=$seasub_grp&page=$lastpage'>$lastpage</a>";		
			}
			// Middle hide some front and some back
			elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))
			{
				$paginate.= "<a href='$targetpage?seasub_grp=$seasub_grp&page=1'>1</a>";
				$paginate.= "<a href='$targetpage?seasub_grp=$seasub_grp&page=2'>2</a>";
				$paginate.= "...";
				for ($counter = $page - $stages; $counter <= $page + $stages; $counter++)
				{
					if ($counter == $page){
						$paginate.= "<span class='current'>$counter</span>";
					}else{
						$paginate.= "<a href='$targetpage?seasub_grp=$seasub_grp&page=$counter'>$counter</a>";}					
				}
				$paginate.= "...";
				$paginate.= "<a href='$targetpage?seasub_grp=$seasub_grp&page=$LastPagem1'>$LastPagem1</a>";
				$paginate.= "<a href='$targetpage?seasub_grp=$seasub_grp&page=$lastpage'>$lastpage</a>";		
			}
			// End only hide early pages
			else
			{
				$paginate.= "<a href='$targetpage?seasub_grp=$seasub_grp&page=1'>1</a>";
				$paginate.= "<a href='$targetpage?seasub_grp=$seasub_grp&page=2'>2</a>";
				$paginate.= "...";
				for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
				{
					if ($counter == $page){
						$paginate.= "<span class='current'>$counter</span>";
					}else{
						$paginate.= "<a href='$targetpage?seasub_grp=$seasub_grp&page=$counter'>$counter</a>";}					
				}
			}
		}
					
				// Next
		if ($page < $counter - 1){ 
			$paginate.= "<a href='$targetpage?seasub_grp=$seasub_grp&page=$next'>next</a>";
		}else{
			$paginate.= "<span class='disabled'>next</span>";
			}
			
		$paginate.= "</div>";		
	
	
}

}

else if($_REQUEST['seaprice']!='')
{
	$query_pr = "SELECT partcode FROM spareprmast where lstprice = '$seaprice' order by partcode";
	$res_pr = mysqli_query($db,$query_pr);
	$mparts = '';
	while($row=mysqli_fetch_array($res_pr))
	{
		$mparts = $mparts."'".$row[0]."',";
	}
	$mparts = $mparts."''";
	$query1 = "SELECT * FROM partmaster where partcode in ($mparts) order by partcode LIMIT $start, $limit";
	if ($page == 0){$page = 1;}
		$prev = $page - 1;	
	$next = $page + 1;							
	$lastpage = ceil($total_pages/$limit);		
	$LastPagem1 = $lastpage - 1;					
	$paginate = '';
	if($lastpage > 1)
	{	
		$paginate .= "<div class='paginate'>";
		// Previous
		if ($page > 1){
			$paginate.= "<a href='$targetpage?seaprice=$seaprice&page=$prev'>previous</a>";
		}else{
			$paginate.= "<span class='disabled'>previous</span>";	}
			

		
		// Pages	
		if ($lastpage < 7 + ($stages * 2))	// Not enough pages to breaking it up
		{	
			for ($counter = 1; $counter <= $lastpage; $counter++)
			{
				if ($counter == $page){
					$paginate.= "<span class='current'>$counter</span>";
				}else{
					$paginate.= "<a href='$targetpage?seaprice=$seaprice&page=$counter'>$counter</a>";}					
			}
		}
		elseif($lastpage > 5 + ($stages * 2))	// Enough pages to hide a few?
		{
			// Beginning only hide later pages
			if($page < 1 + ($stages * 2))		
			{
for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
				{
					if ($counter == $page){
						$paginate.= "<span class='current'>$counter</span>";
					}else{
						$paginate.= "<a href='$targetpage?seaprice=$seaprice&page=$counter'>$counter</a>";}					
				}
				$paginate.= "...";
				$paginate.= "<a href='$targetpage?seaprice=$seaprice&page=$LastPagem1'>$LastPagem1</a>";
				$paginate.= "<a href='$targetpage?seaprice=$seaprice&page=$lastpage'>$lastpage</a>";		
			}
			// Middle hide some front and some back
			elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))
			{
				$paginate.= "<a href='$targetpage?seaprice=$seaprice&page=1'>1</a>";
				$paginate.= "<a href='$targetpage?seaprice=$seaprice&page=2'>2</a>";
				$paginate.= "...";
				for ($counter = $page - $stages; $counter <= $page + $stages; $counter++)
				{
					if ($counter == $page){
						$paginate.= "<span class='current'>$counter</span>";
					}else{
						$paginate.= "<a href='$targetpage?seaprice=$seaprice&page=$counter'>$counter</a>";}					
				}
				$paginate.= "...";
				$paginate.= "<a href='$targetpage?seaprice=$seaprice&page=$LastPagem1'>$LastPagem1</a>";
				$paginate.= "<a href='$targetpage?seaprice=$seaprice&page=$lastpage'>$lastpage</a>";		
			}
			// End only hide early pages
			else
			{
				$paginate.= "<a href='$targetpage?seaprice=$seaprice&page=1'>1</a>";
				$paginate.= "<a href='$targetpage?seaprice=$seaprice&page=2'>2</a>";
				$paginate.= "...";
				for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
				{
					if ($counter == $page){
						$paginate.= "<span class='current'>$counter</span>";
					}else{
						$paginate.= "<a href='$targetpage?seaprice=$seaprice&page=$counter'>$counter</a>";}					
				}
			}
		}
					
				// Next
		if ($page < $counter - 1){ 
			$paginate.= "<a href='$targetpage?seaprice=$seaprice&page=$next'>next</a>";
		}else{
			$paginate.= "<span class='disabled'>next</span>";
			}
			
		$paginate.= "</div>";		
	
	
}

}

else
{
$query1 = "SELECT * FROM partmaster LIMIT $start, $limit";

// Initial page num setup
	if ($page == 0){$page = 1;}
	$prev = $page - 1;	
	$next = $page + 1;							
	$lastpage = ceil($total_pages/$limit);		
	$LastPagem1 = $lastpage - 1;					
	
	
	$paginate = '';
	if($lastpage > 1)
	{	
$paginate .= "<div class='paginate'>";
		// Previous
		if ($page > 1){
			$paginate.= "<a href='$targetpage?page=$prev'>previous</a>";
		}else{
			$paginate.= "<span class='disabled'>previous</span>";	}
			

		
		// Pages	
		if ($lastpage < 7 + ($stages * 2))	// Not enough pages to breaking it up
		{	
			for ($counter = 1; $counter <= $lastpage; $counter++)
			{
				if ($counter == $page){
					$paginate.= "<span class='current'>$counter</span>";
				}else{
					$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}					
			}
		}
		elseif($lastpage > 5 + ($stages * 2))	// Enough pages to hide a few?
		{
			// Beginning only hide later pages
			if($page < 1 + ($stages * 2))		
			{
for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
				{
					if ($counter == $page){
						$paginate.= "<span class='current'>$counter</span>";
					}else{
						$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}					
				}
				$paginate.= "...";
				$paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>";
				$paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>";		
			}
			// Middle hide some front and some back
			elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))
			{
				$paginate.= "<a href='$targetpage?page=1'>1</a>";
				$paginate.= "<a href='$targetpage?page=2'>2</a>";
				$paginate.= "...";
				for ($counter = $page - $stages; $counter <= $page + $stages; $counter++)
				{
					if ($counter == $page){
						$paginate.= "<span class='current'>$counter</span>";
					}else{
						$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}					
				}
				$paginate.= "...";
				$paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>";
				$paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>";		
			}
			// End only hide early pages
			else
			{
				$paginate.= "<a href='$targetpage?page=1'>1</a>";
				$paginate.= "<a href='$targetpage?page=2'>2</a>";
				$paginate.= "...";
				for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
				{
					if ($counter == $page){
						$paginate.= "<span class='current'>$counter</span>";
					}else{
						$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}					
				}
			}
		}
					
				// Next
		if ($page < $counter - 1){ 
			$paginate.= "<a href='$targetpage?page=$next'>next</a>";
		}else{
			$paginate.= "<span class='disabled'>next</span>";
			}
			
		$paginate.= "</div>";		
	
	
}
}
?>

<body>
<center>
<table cellspacing=1 cellpadding=1 bgcolor=black>
<tr><td align=center bgcolor='white'>


<table cellspacing=1 cellpadding=5 class=report>
<th>No <th>Group <th>Sub Group Name<th>Itemcode<th>ItemName<th>BuyPrice<th>SellPrice<th>Reduction<th>Opening<th>Current<th>Location
<?
$k=1;
$i=1;
//$res=mysqli_query($db,"select * from partmaster order by partcode limit 20");
$res= mysqli_query($db,$query1);
while($row=mysqli_fetch_array($res))
{
$query="select ndpcost,lstprice from spareprmast where partcode='$row[partcode]'";
$ex=mysqli_query($db,$query);
$rw=mysqli_fetch_array($ex);
$query1="select opstk,curstk,location from sparestock where itemcode='$row[partcode]'";
$ex1=mysqli_query($db,$query1);
$rw1=mysqli_fetch_array($ex1);
 print "<tr bgcolor='white' onMouseOver=bgColor='b8d7b4'; onMouseOut=bgColor='white'>";
 

$qry=mysqli_query($db,"select sum(qty) from invoice where org_item='$row[partname]' and brcode='$brcode'");
$qry1=mysqli_fetch_row($qry);


//$qty=$ror[qty]-$qry1[0];
print "<td>".$k++."</td><td>$row[gname]</td><td>$row[3]</td>";

 print "<td align=left>$row[partcode]</td><td align=left>$row[partname]</td><td align=right>$rw[0]</td><td align=right>$rw[1]</td><td align=right>$row[10]</td><td align=right>$rw1[0]</td>
<td align=right>$rw1[1]</td>
<td align=right>$rw1[2]</td></tr>";


$i++;
}


?>
</form>
</table>
<div align=center>
<?php

 echo $total_pages.' Results';
 // pagination
 echo $paginate;	

?>
</div>
</td></tr></table>
<script>
function position_fix(str){
document.getElementById('pos').value=str;
}
</script>