<?php
session_start();

include("config.inc.php");

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


$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);

}

$str   = $_GET['str']; if ($str == ""){$str = $_POST["str"];}
$post  = $_GET['post'];if ($post == ""){$post = $_POST["post"];}

$PRef  = $_POST["PRef"]; if ($PRef == ""){$PRef = $_GET["PRef"];}

//Read From Module Table
$querymodule=" Select ifNull(Module_ProjectParent,0) As Module_ProjectParent From Module";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}

?>

<!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=iso-8859-1" />
<title>List of Shipment Ref</title>
<script type="text/javascript" language="javascript">

function clearform()
{
  document.form1.PRef.value='';
  document.form1.action='List_Project_orderbycode.php';
  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: #999999}
-->
</style></head>

<body>
<form id="form1" name="form1" method="post" action="">
  <table width="800" border="0" align="center">
    <tr>
      <th colspan="3" bgcolor="#DDDDDD"><span class="style1"> Shipment Ref </span></th>
    </tr>
    <tr>
      <td bgcolor="#DDDDDD"> <span style="font-size: 11px; color: #999999; font-weight: bold;">Search for Shipment Ref <br> Code / Name</span></td>
      <td bgcolor="#DDDDDD" colspan=2><input type="text" name="PRef" value="<?php echo $PRef; ?>"  />
        <input name="code1" type="hidden" id="code1"  value="<?php echo $_GET['lcode']; ?>">
		   <input name="str" type="hidden"   value="<?php echo $str; ?>">


        <input name="desc1" type="hidden" id="desc1" value="<?php echo $_GET['desc1']; ?>" />
	    <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;'/></td>

	                    
    </tr>
<?php if($post=="1") { ?>
<script type="text/javascript" language="javascript">


if(document.form1.str.value=='1'){
opener.document.clientdt.project_code.value=document.form1.code1.value;
opener.document.clientdt.project_name.value=document.form1.desc1.value;
}

 else if(document.form1.str.value=='2'){
 
 opener.document.supplierdt.project_code.value=document.form1.code1.value;
opener.document.supplierdt.project_name.value=document.form1.desc1.value;
 
 
 }
 
 
  else if(document.form1.str.value=='3'){
 
 opener.document.ledger.project_code.value=document.form1.code1.value;
opener.document.ledger.project_name.value=document.form1.desc1.value;
 
 
 }
 
  else if(document.form1.str.value=='4'){
 
 opener.document.LedgerGroup.project_code.value=document.form1.code1.value;
opener.document.LedgerGroup.project_name.value=document.form1.desc1.value;
 
 
 }
  else if(document.form1.str.value=='5'){
 
 opener.document.AccType.project_code.value=document.form1.code1.value;
opener.document.AccType.project_name.value=document.form1.desc1.value;
 
 
 }
 
else if(document.form1.str.value=='6'){
  opener.document.journal.project_code.value=document.form1.code1.value;
}

else if(document.form1.str.value=='7'){
  opener.document.cst.project_code.value=document.form1.code1.value;
}

else if(document.form1.str.value=='8'){
	opener.document.items.project_code.value=document.form1.code1.value;
	opener.document.items.project_name.value=document.form1.desc1.value;
 }
 else if(document.form1.str.value=='9'){
	opener.document.useraccess.project_code.value=document.form1.code1.value;
	opener.document.useraccess.project_name.value=document.form1.desc1.value;
 }
 else if(document.form1.str.value=='10'){
	opener.document.clientdt.clientipproject_code.value=document.form1.code1.value;
	
 }
 else if(document.form1.str.value=='11'){
	opener.document.useraccess.aproject_code.value=document.form1.code1.value;
	opener.document.useraccess.aproject_desc.value=document.form1.desc1.value;
 }
 else if(document.form1.str.value=='30'){
	opener.document.useraccess.projectlimit_project_code.value=document.form1.code1.value;
	opener.document.useraccess.projectlimit_project_name.value=document.form1.desc1.value;
 }
 else if(document.form1.str.value=='31'){
	opener.document.form1.fromproject.value=document.form1.code1.value;
	opener.document.form1.fromproject_name.value=document.form1.desc1.value;
	opener.document.form1.toproject.value=document.form1.code1.value;
	opener.document.form1.toproject_name.value=document.form1.desc1.value;
 }
 else if(document.form1.str.value=='32'){ 
	opener.document.form1.toproject.value=document.form1.code1.value;
	opener.document.form1.toproject_name.value=document.form1.desc1.value;
 }
self.close();


</script>
<?php } ?>
    <tr bgcolor="#E5E5E5">
      <td width="136"><span class="style2">Shipment Ref Code </span></td>
      <td width="411" colspan="2"><span class="style2">Shipment Ref  Name </span></td>
      
    </tr>
<?php

//maroun
$querymasterproject=" select distinct Masterproject from ".$_SESSION['dbLabel'].".loginstk ".
					" where loginstk.user_account='".$_SESSION['useraccount']."' ".
					" and (Masterproject is not null and Masterproject != '') ";
														 
$projectmasterresult = mysql_query($querymasterproject,$connection) or die(mysql_error());
$projectmasterexist   = mysql_num_rows($projectmasterresult);



$query1=" select distinct project.project_code,project.project_name ".
		" from project ";
		 if ($projectmasterexist > 0) {	
						  $query1= $query1." inner join ( select distinct Masterproject from ".$_SESSION['dbLabel'].".loginstk ".
														 "			   where loginstk.user_account='".$_SESSION['useraccount']."' ".
														 "             and (Masterproject is not null and Masterproject != '') ".
														 "			 ) PrjMasterQry on Project.project_code like concat(PrjMasterQry.Masterproject,'%') ";
						
						}		
 $query1=$query1."left join ".$_SESSION['dbLabel'].".loginstk on (($Module_ProjectParent=1 and project.project_code like concat(ifnull(loginstk.project_code,project.project_code),'%')) or ($Module_ProjectParent=0 and project.project_code = loginstk.project_code )) ".
			  " where user_account='".$_SESSION['useraccount']."' ".
			  " And (loginstk.project_code is not null and loginstk.project_code != '') ".
			  " And ifnull(project.project_deactivate,0) = 0 ";
			  
$query1=$query1." And (project.project_code like"."('%".$PRef."%') or project.project_name like"."('%".$PRef."%')) and ifnull(project.Project_Deactivate,0)=0 ";

		 
$query1=$query1." order by project.project_code";
	
$result1=mysql_query($query1,$connection) or die(mysql_error());

$projectrows   = mysql_num_rows($result1);
if ($projectrows == 0 && $PRef == ''){
    $queryproject=" select distinct project_code, project_name from project ".
	              " where project.project_code like '%".$PProject_Code."%' ".
				  " and project_name like '%".$PProject_Name."%' ".
				  " and ifnull(project.project_deactivate,0) = 0 ".
				  " order by project_code ";
			  
$result1=mysql_query($queryproject,$connection) or die(mysql_error());		
}

while($rows=mysql_fetch_array($result1)){


$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 align="left"><a href="List_Project_orderbycode.php?str=<?php echo $str; ?>&post=1&lcode=<?php echo $rows[0]; ?>&desc1=<?php echo $rows[1]; ?>"><?php echo $rows[0]; ?></a></td>
      <td colspan="2"><a href="List_Project_orderbycode.php?str=<?php echo $str; ?>&post=1&lcode=<?php echo $rows[0]; ?>&desc1=<?php echo $rows[1]; ?>"><?php echo $rows[1]; ?></a></td>

    </tr>
<?php
}

function explodeword($date)
{

$trim = explode('/',$date);
$trim = "$trim[2]"."-"."$trim[1]"."-"."$trim[0]";
return $trim;
}
?>
  </table>
</form>
</body>
</html>
