<?php
session_start();
include '../db_connect.php';

function date_formatc($temp_date)
{
list($year, $month, $day) = explode('-', $temp_date);
return "$day/$month/$year";
}

$today_date=date("d/m/Y");
$from_date = $today_date;
$to_date = $today_date;

$cmp_key=$_POST['cmp_key'];


if(trim($_POST['from_date']))
$from_date =$_POST['from_date'];

if(trim($_POST['to_date']))
$to_date =$_POST['to_date'];

$sql="";
	if($_POST['sortby']=='CATEGORY')
		{
		$qrypart="WHERE cat like '". $_POST['searchtype']."%'";
		}
	else if($_POST['sortby']=='STYLENAME'){
		$qrypart="WHERE gencode like '". $_POST['searchtype']."%'";
		}
	else if($_POST['sortby']=='STYLECODE'){
		$qrypart="WHERE code like '". $_POST['searchtype']."%'";
		}
	else if($_POST['sortby']=='STATUS'){
		$qrypart="WHERE status like '". $_POST['searchtype']."%'";
		}
	else
		{
		$qrypart="";	
		}
			$sql = "select * from  prodreg  $qrypart";

if(isset($_POST['next_rec']))
$sql=$sql." limit $_POST[next_rec],200";

	if($result = mysqli_query($con,$sql))
	{
	$no_of_rec=mysqli_num_rows($result);
	if($no_of_rec==0)
	echo "";
	else{
	$show_rec=$no_of_rec;
	if($no_of_rec>200)
	{
	$result = mysqli_query($con,$sql." limit 0,200");
	$show_rec=$_POST[next_rec]+mysqli_num_rows($result);
	}
	
	
	$pcdArray = $_SESSION['SESS_PCD'];
		
	echo "<table id='demotable' border='1'  width='100%' cellspacing='0' ><thead><tr>
	
	<th ><textarea name='stylecode[]'>$pcdArray[PRODCODE]</textarea></th>	
	<th ><textarea name='prodcode[]'>$pcdArray[PRODNAME]</textarea></th>
	<th><textarea name='category[]'>$pcdArray[CAT]</textarea></th>
	<th><textarea name='subcategory[]'>$pcdArray[SUBCAT]</textarea></th>
	<th><textarea name='discrip[]'>MRP</textarea></th>
	<th><textarea name='color[]'>$pcdArray[COLOR]</textarea></th>
	<th ><textarea name='size[]'>$pcdArray[SIZECODE]</textarea></th>
	<th ><textarea name='stock[]'>STOCK</textarea></th>
	<th><textarea name='status[]'>STATUS</textarea></th>
	</tr></thead><tbody>";
	while($row = mysqli_fetch_array($result))
	{
	
	
echo "<tr>
<td><a href='prodentry.php?id=$row[id]' onClick='positionedPopup(this.href,1200,650);return false'><textarea name='prodcode[]' class ='prodcode'>$row[code]</textarea></a></td>
<td><textarea name='stylecode[]' class ='gencode'>$row[gencode]</textarea></td>
<td><textarea name='category[]' class ='cat'>$row[cat]</textarea></td>
<td><textarea name='subcategory[]' class ='subcat'>$row[subcat]</textarea></td>
<td><textarea name='discrip[]' class ='ptotal'>$row[ptotal]</textarea></td>
<td><textarea name='color[]' class ='color' >$row[color]</textarea></td>
<td><textarea name='size[]' class ='callby size' >$row[sizesetcode]</textarea></td>
<td><textarea name='stock[]' class= 'stock'>$row[stock]</textarea></td>
<td><textarea name='status[]' class='status' >$row[status]</textarea></td>
</tr>";


		
	}
$temp_var=0;
if(isset($_POST['next_rec']))
$temp_var=$_POST['next_rec'];

if(isset($_POST[tot_rec]))
$no_of_rec=$_POST[tot_rec];

echo "</tbody></table>###<div style='float:left;font-weight: bold;color: #000;width:30%;padding:5px'>Showing records ".($_POST[next_rec]+1)."-".($show_rec+$temp_var)." of  <span id='tot_rec'>".($no_of_rec)."</span></div>";

if($no_of_rec>200||isset($_POST['next_rec']))
{
echo "<div style='text-align: right;font-weight: bold;color: #000;padding:5px;width:30%;float: left;'>";
for($i=0;($no_of_rec/200)>0;$i++,$no_of_rec-=200)
echo "<span class='links'><a style='color:#000' class='linkspages' href='#' id=".($i*200).">".($i+1)."</a></span>";
echo "</div>";
}
	}
	}
	else 
	echo mysqli_error($con);


mysqli_close($con);
?>


