<?php

session_start();
if($_SESSION['dbName']==""){
header("location:../index.php");
}


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

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

}

$queryProjExist = " select project_code from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."' and ifnull(project_code,'') <> '' ";
$resProjExist = mysql_query($queryProjExist, $connection);
$ProjectExist = mysql_num_rows($resProjExist);

//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>
<?php if(	$_SESSION['encodingmode'] == 'utf8' || $_SESSION['encodingmode'] == 'utf-8'){ ?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php } else ?>
<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.PLedger_number.value='';
	document.form1.Submit.click();

}

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  name="form1" method="post" action="">
  <table width="800" border="0" align="center">
    <tr>
      <th colspan="3" 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" colspan=2><input type="text" name="PLedger_number" value="<?php echo $PLedger_number; ?>"  />
        <input name="code1" type="hidden" id="code1"  value="<?php echo $lcode; ?>">
        <input name="item" type="hidden" id="item"  value="<?php echo $item; ?>">
	


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

	<?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;'/>";
	}
	?>
	
		</td>

	                    
    </tr>
<?php if($post=="1") { ?>
<script type="text/javascript" language="javascript">
if (document.form1.item.value==1)
{
if (document.form1.Project.value==0)
opener.document.transfer.fromproject.value=document.form1.code1.value;
else
opener.document.transfer.toproject.value=document.form1.code1.value;
}
else if (document.form1.item.value==2)
{
if (document.form1.Project.value==0)
opener.document.transferrequest.fromproject.value=document.form1.code1.value;
else
opener.document.transferrequest.toproject.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>
      
    </tr>
<?php	
	// default project
	$query="select project_code from ".$_SESSION['dbLabel'].".loginstk where default_project = 1 and user_account='".$_SESSION['useraccount']."'";
	$defaultproject=mysql_query($query,$connection) or die(mysql_error());
	$rows = mysql_fetch_row($defaultproject);
	$defaultprojectcode = $rows[0];
							
	if ($fromproject=='')
	$fromproject = $defaultprojectcode;

	$sqlproject = "select project_code,project_name from project where 1=1 ";
	//stopped by nadine
	// project_code in (select project_code from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."')
	$resultdefaultproject=mysql_query($sqlproject,$connection) or die(mysql_error());
							
	$sqlproject1 = "select project_code,project_name from project where if('$ProjectExist'=1, project_code in 
			(select project_code from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."'), 1=1) ";
			
		if(mysql_num_rows($resultdefaultproject)=="0")
			{
				$sqlproject = "select project_code,project_name	from project where 1=1 ";							
				$sqlproject1 = "select project_code,project_name from project where 1=1  ";	
			}									
			else
			if (($edit=='yes' or $ref!='') and $fromprojectedit!='')
			{
				$sqlproject = "select '".$fromprojectedit."' , '".$fromprojectnameedit."' from dual union " . $sqlproject;
				$sqlproject1 = "select '".$toprojectedit."' , '".$toprojectnameedit."' from dual union " . $sqlproject1;			
			}
	// show non blocked projects for transfer		
	if ($item == 1){
		$sqlproject  .= " and ifnull(project_blocked,0) = 0 ";
		$sqlproject1 .= " and ifnull(project_blocked,0) = 0 ";
	}
	
	if ($PLedger_number != ''){
		$sqlproject  .=  " and (Project_Code like '".$PLedger_number."%' or Project_Name like '%".$PLedger_number."%') ";
		$sqlproject1 .=  " and (Project_Code like '".$PLedger_number."%' or Project_Name like '%".$PLedger_number."%') ";
	}
	$sqlproject  .= " order by project_code ";
	$sqlproject1 .= " order by project_code ";

	if($item==1 && $Project ==1 && $TransType=='Tr')
		$projectresultfrom = mysql_query($sqlproject1,$connection) or die(mysql_error());
	else $projectresultfrom = mysql_query($sqlproject,$connection) or die(mysql_error());
	
	
 
while($rows=mysql_fetch_array($projectresultfrom)){


$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_TrsProject.php?item=<?php echo $item; ?>&post=1&lcode=<?php echo $rows[0]; ?>&desc1=<?php echo $rows[1]; ?>&Project=<?php echo $Project; ?>"><?php echo $rows[0]; ?></a></td>
      <td colspan="2"><a href="List_TrsProject.php?item=<?php echo $item; ?>&post=1&lcode=<?php echo $rows[0]; ?>&desc1=<?php echo $rows[1]; ?>&Project=<?php echo $Project; ?>"><?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>

