<?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);
}

//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);
}

$item   = $_GET['item']; if ($item == ""){$item = $_POST["item"];}
$vtext1 = $_GET['vtext1']; if ($vtext1 == ""){$vtext1 = $_POST["vtext1"];}
$text1value = $_GET['text1value']; if ($text1value == ""){$text1value = $_POST["text1value"];}

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

if($_GET['lcode']!=""){

	$query1=" select distinct project_code, project_name from project ".
			" where project_code ='".$_GET['lcode']."'";
					  
	$result1=mysql_query($query1,$connection) or die(mysql_error());
	while($rows=mysql_fetch_array($result1)){
		extract($rows);

	}

	$_GET['post']="1";

}

//User Access
$querylog=" select ifNull(FA_Project,0) As FA_Project, ifNull(FA_ProjectApp,0) As FA_ProjectApp ".
          " from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')  ";
		  $resultlog=mysql_query($querylog,$connection) or die(mysql_error());
		  
//echo $querylog;
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}




?>

<!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 Projects</title>
<script type="text/javascript" language="javascript">

function clearform()
{
  document.form1.PProject_Code.value='';
  document.form1.PProject_Name.value='';
  document.form1.action='List_Project.php';
  document.form1.submit();
}

function openprojectform(){

 win = window.open('./Form_Project.php?mode=insert', 'Form_Project', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=1000,height=600,top=100,left=100');		
	win.creator = self;
	win.focus();
}

</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="5" bgcolor="#DDDDDD"><span class="style1"> PROJECTS </span></th>
    </tr>
    <tr>
      <td bgcolor="#DDDDDD"> <span style="font-size: 11px; color: #999999; font-weight: bold;">Search for Project  <br> Code / Name</span></td>
      <td bgcolor="#DDDDDD"><input type="text" name="PProject_Code" value="<?php echo $PProject_Code; ?>"  />
        <input name="code1" type="hidden" id="code1"  value="<?php echo $project_code; ?>">
      <td bgcolor="#DDDDDD"><input type="text" name="PProject_Name"  value="<?php echo $PProject_Name; ?>" size='35'/>
        <input name="desc1" type="hidden" id="desc1" value="<?php echo $project_name; ?>" />
		
		<input name="vtext1" type="hidden" id="vtext1" value="<?php echo $vtext1; ?>" />
		<input name="text1value" type="hidden" id="text1value" value="<?php echo $text1value; ?>" /> 
		
	    <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>
		
     <td bgcolor="#DDDDDD">
	
	<?php
	//Gilbert 20-11-2013
	
	if($FA_ProjectApp==1 && $FA_Project==1){
		echo"<input type='button' name='addbtn' value='Add Project' onclick='openprojectform();'style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'/>";
	}
	?>
	 <input name="item" type="hidden" id="item" value="<?php echo $item; ?>" /></td>
    </tr>
	
	
<?php if($_GET['post']=="1") { ?>
<script type="text/javascript" language="javascript">
var FormOption = document.form1.item.value;

if (FormOption == 1)
opener.document.purchase.txtProjectCode.value=document.form1.code1.value;
else
if (FormOption == 2) {

var vtext1 = document.form1.vtext1.value;
var parentText = window.opener.document.getElementById(vtext1);
parentText.value =  document.form1.code1.value;
			
opener.document.purchasereq.txtProjectCode.value=document.form1.code1.value;

}
else if (FormOption == 3) {

var vtext1 = document.form1.vtext1.value;
var parentText = window.opener.document.getElementById(vtext1);
parentText.value =  document.form1.code1.value;
			
//opener.document.purchasereq.txtProjectCode.value=document.form1.code1.value;

}
else if (FormOption == 4) {
opener.document.form1.txtProjectCode.value=document.form1.code1.value;		
//opener.document.purchasereq.txtProjectCode.value=document.form1.code1.value;
}

else if (FormOption == 5) {
opener.document.Setup.txtProjectCode.value=document.form1.code1.value;		
//opener.document.purchasereq.txtProjectCode.value=document.form1.code1.value;
}

else if (FormOption == 6) {
opener.document.form1.projectchoose.value=document.form1.code1.value;		
//opener.document.purchasereq.txtProjectCode.value=document.form1.code1.value;
}
else if (FormOption == 7) {
opener.document.materialreq.txtProjectCode.value=document.form1.code1.value;		
//opener.document.purchasereq.txtProjectCode.value=document.form1.code1.value;
}
self.close();

</script>
<?php } ?>
    <tr bgcolor="#E5E5E5">
      <td width="136"><span class="style2">Project Code </span></td>
      <td width="411" colspan="2"><span class="style2">Project Name </span></td>
      <td width="57"><span class="style3"></span></td>
    </tr>
<?php
		
//Projects List
$queryproject=" select distinct project.project_code, project_name ".
              " from project 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 ".
			  " and project.project_code like '".$PProject_Code."%' ".
			  " and project_name like '%".$PProject_Name."%' ".
			  " order by project.project_code";
$projectresult = mysql_query($queryproject,$connection) or die(mysql_error());
$projectrows   = mysql_num_rows($projectresult);
if ($projectrows == 0)
    $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 ";
			  
$resultproject=mysql_query($queryproject,$connection) or die(mysql_error());		
while($rows=mysql_fetch_array($resultproject)){
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 align="left"><a href="List_Project.php?lcode=<?php echo $project_code; ?>&item=<?php echo $item; ?>&vtext1=<?php echo $vtext1; ?>&text1value=<?php echo $text1value; ?>"><?php echo $project_code; ?></a></td>
      <td colspan="2"><a href="List_Project.php?lcode=<?php echo $project_code; ?>&item=<?php echo $item; ?>&vtext1=<?php echo $vtext1; ?>&text1value=<?php echo $text1value; ?>"><?php echo $project_name; ?></a></td>
      <td>&nbsp;</td>
    </tr>
<?php
}
?>
  </table>
</form>
</body>
</html>
