<?php

session_start();
header("Content-type: text/html; charset=".$_SESSION['encodingmode']);
if($_SESSION['dbName']==""){
header("location:../index.php");
}
include("config.inc.php");
include("function.inc.php");

$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass'],true,65536) or die("Could not connect to DB");
mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");

if(	$_SESSION['encodingmode'] == 'utf8' || $_SESSION['encodingmode'] == 'utf-8'){
	mysql_query("SET NAMES 'utf8'"); 
	mysql_query('SET CHARACTER SET utf8'); 
	mysql_set_charset('utf8', $connection);
}	

$queryledger= " select distinct ledger_number, ledger_include ".
              " from ".$_SESSION['dbLabel'].".ledgerstk  ".
			  " where user_account='".$_SESSION['useraccount']."' ".
			  " and (ledger_number is not null and ledger_number != '') ".
			  " order by ledger_number";
$ledgerresult = mysql_query($queryledger,$connection) or die(mysql_error());
$ledgerexist  = mysql_num_rows($ledgerresult);	
$rows=mysql_fetch_array($ledgerresult) ;
$ledgerinclude = $rows[1];
if (empty($ledgerinclude)) $ledgerinclude = 0;


$query1="select grid_color1,grid_color2 from setup";
$result1=mysql_query($query1,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($result1)){
extract($rows);

}

if (!empty($TransDate))
   $TransDate = formatDateNoTime($TransDate);

if (empty($TransID))   
   $TransID = 'null';
   

if (empty($TransDate))   
   $TransDate = 'null';
else
   $TransDate = "'".$TransDate."'"; 
   
   
   
if($_GET['package_code']!=""){

$query1="select package_code as code, package_description as description from package where package_code='".$_GET['package_code']."'";
echo $query1;
$result1=mysql_query($query1,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($result1)){
	extract($rows);
}

$post="1";
}
echo "post is ". $post;
//User Access






?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>List of Package</title>
<script type="text/javascript" language="javascript">

function clearform()
{
	document.form1.package_code.value='';
	document.form1.Cntr_description.value='';
	//document.form1.action='List_Sorpackage.php';
	document.form1.submit();
}

function openpackageform(){

 win = window.open('./Form_Package.php?mainmode=insert&addpackage=1', 'Form_Package', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=1000,height=750,top=20,left=100');		
	win.creator = self;
	win.focus();
}

function SetNextPage(startrange,perpage){
	vFrm       = document.form1.frm.value;
	vItem 	   = document.form1.item1.value;
	vTransDate = document.form1.TransDate.value;
	vcurCode   = document.form1.curCode.value;
	index   = document.form1.index.value;
	
	document.form1.action='List_Sorpackage.php?package_code=&package_code=&frm='+vFrm+'&item1='+vItem+'&TransDate='+vTransDate+'&curCode='+curCode+'&startrange='+startrange+'&perpage='+perpage+'&index='+index;
	document.form1.submit();
}

function SetPrvPage(startrange,perpage){
	vFrm       = document.form1.frm.value;
	vItem 	   = document.form1.item1.value;
	vTransDate = document.form1.TransDate.value;
	vcurCode   = document.form1.curCode.value;
	index   = document.form1.index.value;
	
	document.form1.action='List_Sorpackage.php?package_code=&package_code=&frm='+vFrm+'&item1='+vItem+'&TransDate='+vTransDate+'&curCode='+curCode+'&startrange='+startrange+'&perpage='+perpage+'&index='+index;
	document.form1.submit();
}
function RefreshPage(){
	vFrm       = document.form1.frm.value;
	vItem 	   = document.form1.item1.value;
	vTransDate = document.form1.TransDate.value;
	vcurCode   = document.form1.curCode.value;
	vPerPage   = document.form1.perpage.value;
	index   = document.form1.index.value;
	
	document.form1.action='List_Sorpackage.php?package_code=&package_code=&frm='+vFrm+'&item1='+vItem+'&TransDate='+vTransDate+'&curCode='+curCode+'&startrange=0&perpage='+vPerPage+'&index='+index;
	document.form1.submit();
}

function SubmitForm() {
	vFrm       = document.form1.frm.value;
	vItem 	   = document.form1.item1.value;
	vTransDate = document.form1.TransDate.value;
	vcurCode   = document.form1.curCode.value;
	vPerPage   = document.form1.perpage.value;
	index   = document.form1.index.value;
	
	document.form1.action='List_Sorpackage.php?package_code=&package_code=&frm='+vFrm+'&item1='+vItem+'&TransDate='+vTransDate+'&curCode='+curCode+'&startrange=0&perpage='+vPerPage+'&index='+index;
	document.form1.submit();
}


</script>
<style type="text/css">
<!--
body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 14px;
}
.style1 {
	color: #333333;
	font-weight: bold;
}
.style2 {
	color: #999999;
	font-weight: bold;
}
.style3 {color: #3500FF; font-size: 13px;}
-->
</style></head>

<body>
<form id="form1" name="form1" method="post" action="" onsubmit="SubmitForm();">
  <table width="800" border="0" cellspacing="1" align="center">
    <tr>
      <th colspan="3" bgcolor="#DDDDDD"><span class="style1"> Package </span></th>
    </tr>
    <tr>
      <td bgcolor="#DDDDDD"> <span style="font-size: 11px; color: #999999; font-weight: bold;">Search for package  <br> Code / description</span></td>
      <td bgcolor="#DDDDDD" colspan="3">
	    <input type="text" name="package_code1" value="<?php echo $package_code1; ?>" style="width:100px;" />
        <input type="text" name="Cntr_description1"  value="<?php echo $package_description1; ?>" style="width:200px;"/>
        <input name="code" type="hidden" id="code"  value="<?php echo $code; ?>">
		<input name="description" type="hidden" id="description" value="<?php echo $description; ?>" />
		<input name="index" type="hidden" id="index" value="<?php echo $_GET['index']; ?>" />
		     <input type="submit" name="Submit" value="Find" style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'/>
		<input type="button" name="cancelbtn" value="Cancel" onclick='clearform();'style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'/>

<?php

echo" <span style='font-size: 11px; color: #999999; font-weight: bold;'>Per page </span><select name='perpage' id='perpage' value='$perpage' onchange='RefreshPage();' >";

if ($perpage==20)		$s20 = 'selected';
else if ($perpage==30)	$s30 = 'selected';
else if ($perpage==40)	$s40 = 'selected';
else if ($perpage==50)	$s50 = 'selected';
		
echo"	<option ".$s20." value='20'>20</option>
		<option ".$s30." value='30'>30</option>
		<option ".$s40." value='40'>40</option>
		<option ".$s50." value='50'>50</option>
		</select>";
?>
		
		</td>
 
	<?php 
	//Gilbert 19-11-2013
	
	
	?>  
	  
	  <input name="item1" type="hidden" id="item1" value="<?php echo $_GET['item']; ?>" /><input name="frm" type="hidden" id="frm" value="<?php echo $_GET['frm']; ?>" />
	  <input name="TransDate" type="hidden" id="TransDate" value="<?php echo $_GET['TransDate']; ?>" />
	  <input name="curCode" type="hidden" id="curCode" value="<?php echo $_GET['curCode']; ?>" />
	  
    </tr>
<?php if($post=="1") { ?>
<script type="text/javascript" language="javascript">

var FormOption = document.form1.frm.value;
var index = document.form1.index.value;

if(FormOption == 1){
	
	opener.document.getElementById('Mandt_package['+index+']').value=document.form1.code.value;
	opener.document.getElementById('Mandt_pack_Desc['+index+']').value= document.form1.description.value;

	}
//self.close();
self.focus();
setTimeout("self.close();",10);

</script>
<?php } ?>
    <tr bgcolor="#E5E5E5"><td colspan=3>
	<table>
	<col width="300">
	<col width="300">
	<tr>
      <td ><span class="style2">package Code </span></td>
      <td width="500"><span class="style2">package description </span></td>
	  </tr>
     </table></td>
    </tr>
<?php
$query1=" select package_id, package_code, package_description from package ".
        " where package_code like ".GetSQLValueString($package_code1.'%','text')." ".
		" and package_description like ".GetSQLValueString('%'.$package_description1.'%','text');
		$query1 = $query1." order by package_id";	  
		
		//ECHO  $query1;
$resultsearch=mysql_query($query1,$connection) or die(mysql_error());
$totalrows = mysql_num_rows($resultsearch);
	
if ($startrange=='') $startrange = 0;
if ($perpage=='')	 $perpage = 20;
		
$query1 = $query1." limit ".$startrange.",".$perpage;
	echo $query1;
$result1=mysql_query($query1,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($result1)){
	extract($rows);

	$ct+=1;

	if($ct%2==0)
	{
		$Color="style='color:#0000FF;background-color:".$grid_color1."'";
		
		}else{
			
		$Color="style='color:#0000FF;background-color:".$grid_color2."'";	
	}

	?>
		<tr <?php echo $Color; ?>><td colspan=3>
		<table>
	<col width="300">
	<col width="300">
	<tr>
		  <td align="left"><span class="style3"><a href="List_Sorpackage.php?index=<?php echo $_GET['index'];?>&package_code=<?php echo $package_code; ?>&frm=<?php echo $_GET['frm']; ?>&item=<?php echo $_GET['item']; ?>&curCode=<?php echo $currency_code; ?>&packageTelephone=<?php echo $packageTelephone; ?>&packageEmail=<?php echo $packageEmail; ?>"><?php echo $package_code; ?></a></span></td>
		  <td><span class="style3"><a href="List_Sorpackage.php?index=<?php echo $_GET['index'];?>&package_code=<?php echo $package_code; ?>&frm=<?php echo $_GET['frm']; ?>&item=<?php echo $_GET['item']; ?>&curCode=<?php echo $currency_code; ?>&packageTelephone=<?php echo $packageTelephone; ?>&packageEmail=<?php echo $packageEmail; ?>"><?php echo $package_description; ?></a></span></td>
		  <td><span class="style3"><?php echo $Salesmen_Code; ?></span></td>
		</table></td></tr>
		</tr>
	<?php
	
}

echo"<tr><td colspan='3'>&nbsp;</td></tr>
	 <tr><td colspan='3'><table width='100%' border=0><tr><td width='270'>&nbsp;</td><td width='130' align='center'>";
		
$diff= $startrange - $perpage;
		
if (($diff) >= 0 ){
	$prvstartrange = $startrange - $perpage;
	echo"<img src='img/arrowleft.jpg' title='Previous' onMouseOver=\"style.cursor='hand'\"  onclick=SetPrvPage('".$prvstartrange."','".$perpage."')>";
}
else
	echo "&nbsp;";
		
echo"</td><td width='130' align='center'>";
		
		
if ($startrange <= $totalrows){
	$startrange = $startrange + $perpage;
	if  ($startrange <= $totalrows)
		echo"<img src='img/arrowright.jpg' title='Next' onMouseOver=\"style.cursor='hand'\" onclick=SetNextPage('".$startrange."','".$perpage."')>";
} else
	echo "&nbsp;";
			
echo"</td><td width='270'>&nbsp;</td></tr>";
echo"</table>";
echo"</td></tr>";
	
?>
  </table>
</form>
</body>
</html>
