<?php

session_start();
header("Content-type: text/html; charset=".$_SESSION['encodingmode']);
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);
}

$querylog="SELECT FL_ClosingFileLogisticsApp as loginaccess, user_account, Language 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());
	while($rows=mysql_fetch_array($resultlog)){
		extract($rows);
	}

if ($loginaccess=='' or $loginaccess==0)
	header("location:menu.php");



$query_navigator = "SELECT LANGUAGE,
       ClearPage,
       Excel,
       Save,
       Print,
       Addd,
       SEARCH,
       Pending,
       CopyJV,
       PaymentRequests,
       ExportExcel
FROM ".$_SESSION['dbLabel'].".mainform_label
WHERE LANGUAGE = '".$Language."'";
$result_navigator = mysql_query($query_navigator, $connection);
$row_navigator    = mysql_fetch_array($result_navigator);
extract($row_navigator);

	
//Read From Setup Table							
$querysetup= " select grid_color1, grid_color2,maxperpage from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}
	

if($mainmode=='')  		$mainmode	= 'insert';
if($startrange=='') 	$startrange = 0;
if($perpage == '' ) 	$perpage 	= $config['trowlimit'][0];
if($lfDate=='')  		$lfDate		= date('Y-m-d');


print <<<HERE

<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
<meta name="viewport" content="width=device-width, initial-scale=1.0"> 

<title>Closing File</title>

<script type="text/javascript" language="javascript">

function SubmitRecord(){
	var x = document.closelog;
	if (x.lfContainerNb.value == ''){
		alert("Container Number is Empty!");
		return 0;
	} else if (x.lfContainerNb.value == ''){
		alert("Container Number is Empty!");
		return 0;
	}else if (x.lfCntrSize.value == ''){
		alert("Container Size is Empty!");
		return 0;
	}else if (x.lfClientCode.value == ''){
		alert("No Client was selected!");
		return 0;
	} else {
		x.action = 'Form_ClosingFileLogistic_Action.php';
		x.submit();
	}
}



function ClearPage(){
	var x = document.closelog;
	if (confirm ( "Are you sure you want to Clear Page?"))
	{
		x.mainmode.value 		= '';		
		x.modedt.value 			= '';		
		x.message.value 		= '';		
		x.printRep.value 		= '';		
		x.lfId.value 			= '';	
		x.lfDate.value 			= '';	
		x.lfTime.value 			= '';	
		x.lfCntrSize.value 		= '';	
		x.lfProjectCode.value 	= '';	
		x.lfProjectDesc.value 	= '';	
		x.lfContainerNb.value 	= '';	
		x.lfClientCode.value 	= '';	
		x.lfClientDesc.value 	= '';	
			
		x.action='Form_ClosingFileLogistic.php';
		x.submit();
	}	
}

function ShowlistProject(){
	var vProjectCode = encodeURIComponent(document.getElementById('lfProjectCode').value);
	window.open('List_SorProject.php?frm=45&item=','mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}


function ShowlistClient(){
	var vLedger = encodeURIComponent(document.getElementById('lfClientCode').value);
	var vDate = document.getElementById('lfDate').value;
	
	window.open('List_SorClient.php?frm=20&item=1&PLedger_number='+vLedger+'&TransDate='+vDate,'Clients','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function ShowlistClosingFiles(){
	
	window.open('Form_SearchClosingFileLogistic.php','List','width=900,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function SetNextPage(startrange,perpage){
	document.closelog.action='Form_ClosingFileLogistic.php?PRef=&startrange='+startrange+'&perpage='+perpage;
	document.closelog.submit();
}

function SetPrvPage(startrange,perpage){
	document.closelog.action='Form_ClosingFileLogistic.php?PRef=&startrange='+startrange+'&perpage='+perpage;
	document.closelog.submit();
}

function set_limit(){

	perpage=document.closelog.perpage.value;
	document.closelog.action='Form_ClosingFileLogistic.php?perpage='+perpage+'&startrange=0';
	document.closelog.submit();
}

function PrintRecord(vlfId){
	if (confirm ( "Print Closing File Report?"))
	{
		window.open('Rep_LogisticClosingFile.php?id='+vlfId);
		window.focus();
	}
}

function setDocument(vField){
	if (document.getElementById(vField).checked)
		document.getElementById(vField).value = 1;
	else 
		document.getElementById(vField).value = 0;
}
</script>
<style type="text/css">

body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}
body {
	margin-top: 2px;
	margin-left: 1px;
}
a:link {
	text-decoration: none;
	color: #0000FF;
}
a:visited {
	text-decoration: none;
	color: #0000FF;
}
a:hover {
	text-decoration: none;
	color: #0000FF;
}
a:active {
	text-decoration: none;
	color: #0000FF;
}
.style1 {color: #999999; font-weight: bold; }
.style12 {
	font-size: 9px;
	color: #999999;
	font-weight: bold;
}
.style15 {color: #5151FF; font-size: 10px;}
.style16 {
	font-size: 16px;
	color: #FF0000;
	font-weight: bold;
	font-family: "Times New Roman", Times, serif;
}
.style17 {font-size: 9px}
.style25 {color: #999999; font-weight: bold; font-size: 10px; }
.style26 {color: #FF0000}
.style27 {color: #999999 ;font-size: 10px;}
.style28 {color: #FFFFFF ;font-size: 10px;}

input:focus, select:focus {
	border: 2px solid #008b8b;
}
input:hover, select:hover {
	border: 1px solid #008b8b;
}

table.subtable tr:first-child td {
	border-top: 1px solid darkgray;
	border-bottom: 1px solid darkgray;
}
table.subtable tr:first-child td:first-child {
	border-left: 1px solid darkgray;
}
table.subtable tr:first-child td:last-child {
	border-right: 1px solid darkgray;
}

table.tabledt {
	border: 2px solid white;
}

table.tabledt tr td{
	border-right: 2px solid white;
	border-bottom: 2px solid white;
}
</style>
<link type="text/css" rel="stylesheet" href="dhtmlgoodies_calendar.css?random=20051112" media="screen"></LINK>
<SCRIPT type="text/javascript" src="dhtmlgoodies_calendar.js?random=20060118"></script>
<LINK REL="stylesheet" TYPE="text/css" MEDIA="all" HREF="css/tabs.css">
<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">
</head>
<body >
<form name='closelog' method='post' enctype='multipart/form-data' >
<input type='hidden' name='mainmode' value='$mainmode'>
<input type='hidden' name='modedt' value='$modedt'>
<input type=hidden name='message' value='$message'>
<input type=hidden name='lfId' value='$lfId'>
<input type=hidden name='printRep' value='$printRep'>
HERE;


echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' class='layout-width'>";
include_once("header.php");
echo" <tr><td  valign='top'>";

include_once("sidemenu.php");
echo"  </td></tr>";

if ($mainmode == 'edit' && $lfId != ''){
	$query = "select date_format(LCF_Date,'%Y-%m-%d'), date_format(LCF_Date,'%H:%i'), LCF_ContainerSize, LCF_ProjectCode, project_name,
			LCF_ContainerNumber, LCF_ClientCode, ledger_name
			from Logistic_ClosingFile 
			inner join project on project.project_code = LCF_ProjectCode
			left join clients on clients.ledger_number = LCF_ClientCode
			where LCF_Id = $lfId ";	
	$result = mysql_query($query, $connection);
	$row = mysql_fetch_row($result);	
	$lfDate 		= $row[0];
	$lfTime 		= $row[1];
	$lfCntrSize 	= $row[2];
	$lfProjectCode 	= $row[3];
	$lfProjectDesc 	= $row[4];
	$lfContainerNb 	= $row[5];
	$lfClientCode 	= $row[6];
	$lfClientDesc 	= $row[7];
	
}

echo" <tr style='height:26px;'>
		<td  valign='top' id='content-top'>";

	echo "<table border='0' cellpadding='0' cellspacing='0' style='table-layout:fixed; height:26px;' class='layout-width'>
			<tr style='height:26px;'>
				<td style='width:38px; height:26px;'>&nbsp;</td>
				<td valign='middle' style='width:300px; height:26px;'><span class='title' style='text-transform: uppercase'>Closing File</span></td>
				<td class='message' valign='middle' style='height:26px;'>".htmlspecialchars($message, ENT_QUOTES)."</td>
			</tr></table>
		</td>
	  </tr>";


echo"<tr>
		<td  height='34'  valign='top' id='content-top2'>
			<table border='0' cellpadding='0' cellspacing='0' class='layout-width'>
			<tr>
				<td width='38'  height='34'>&nbsp;</td>
				<td valign='middle' height='34' width='720px'>";
echo"		<button type='button' id='btnClear' name='btnClear' onclick='ClearPage(); return false;' title='Clear Page'><span><span>$ClearPage</span></span></button>";
if ($lfId == '')
echo"		<button type='button' id='btnSearch' name='btnSearch' onclick='ShowlistClosingFiles(); return false;' title='Search'><span><span>Search</span></span></button>";


echo"		<button type='button' id='btnPost' name='btnPost' onclick=\"SubmitRecord();return false;\" title='Save Changes'><span><span>$Save</span></span></button>";

echo"   </td><td align='left' width='240px'></td><td align='left'>";
	
		
echo "</td></tr>";
echo"	</table>";
echo"</td></tr>";

echo"<tr><td id='content-body'>";	

echo"<table border='0'  align='center' valign='top' width=100% class='tablecontent'>
	<col width=100%>";
		
	echo"   <tr bgcolor='#F7F7F7'><td valign='top'  align='left'>";	  
	
echo"<table border='0' style='table-layout:fixed' align='left' valign='top' width='100%'>
      <col width=10%><col width=20%><col width=10%><col width=20%><col width=10%><col width=20%>";

//1st row	  
echo"<tr bgcolor='#F7F7F7' height='25'>
		<td valign='center' align='left' ><span class='style1'>Date<span class='style26'>*</span></span>";
echo"	</td>";
echo"	<td ><input type='date' name='lfDate' id='lfDate' value='$lfDate' style='font-size:12px; width:120px; height:20px;' />
			<input type='time' name='lfTime' id='lfTime' value='$lfTime' style='font-size:12px; width:90px; height:20px;' />
		</td>
		<td></td>
		<td></td>
		<td><span class='style1'>Container Size</span></td>
		<td ><input type='text' name='lfCntrSize' id='lfCntrSize' value='$lfCntrSize' style='font-size:12px; width:90px; height:20px;' /></td>
	</tr>";

echo"<tr>
		<td><span class='style1'>File</span></td>
		<td colspan='3'><input type='text' name='lfProjectCode' id='lfProjectCode' value='$lfProjectCode' style='font-size:12px; width:150px; height:20px;' maxlength='20' readonly />
			<input type='text' name='lfProjectDesc' id='lfProjectDesc' value='".htmlspecialchars($lfProjectDesc,ENT_QUOTES)."' style='font-size:12px; width:200px; height:20px;' readonly/>	
			<img src='img/btnopen.jpg' weight='15' height='20' onclick=\"ShowlistProject();\" title='Select File' onmouseover=\"style.cursor='hand';\">			
		</td>
		<td><span class='style1'>Container #</span></td>
		<td><input type='text' name='lfContainerNb' id='lfContainerNb' value='$lfContainerNb' style='font-size:12px; width:90px; height:20px;' />
		
		</td>
	</tr>";
	
echo"<tr>
		<td><span class='style1'>Client<span class='style26'>*</span></span></td>
		<td colspan='3'><input type='text' name='lfClientCode' id='lfClientCode' value='".htmlspecialchars($lfClientCode,ENT_QUOTES)."' style='font-size:12px; width:150px; height:20px;' maxlength='20' readonly/>
			<input type='text' name='lfClientDesc' id='lfClientDesc' value='".htmlspecialchars($lfClientDesc,ENT_QUOTES)."' style='font-size:12px; width:200px; height:20px;' readonly/>
			<img src='img/btnopen.jpg' weight='15' height='20' onclick=\"ShowlistClient();\" title='Select Client' onmouseover=\"style.cursor='hand';\">	
		</td>
		<td></td>
		<td></td>
	</tr>";

echo"<tr height='30px'>
	<td><span class='style1'>Files Details</span></td>
	<td colspan='3'></td>
	<td></td>
	<td></td>
</tr>";

echo "<tr><td colspan='6'><div style='width:70%;'><table cellpadding=0 cellspacing=0 width='100%' class='tabledt'><col width='60%'><col width='20%'><col width='20%'>";
echo "<tr bgcolor='#c0c0c0' height='25px'><td><span class='style1'>DOCUMENT</span></td><td align='center'><span class='style1'>ORIGINAL</span></td><td align='center'><span class='style1'>COPY</span></td></tr>";

$querydoc = "select LDI_Id, LDI_DocumentDesc from Logistic_DocumentInfo ";
$resdoc = mysql_query($querydoc, $connection);
while ($rwdoc = mysql_fetch_array($resdoc)){
	$ldId = $rwdoc[0];
	$org = 'original-'.$ldId;
	$copy = 'copy-'.$ldId;
	$detailId = 'detailId-'.$ldId;
	
	$querydt = "select LCFdt_id, ifnull(Chk_Original,0), ifnull(Chk_Copy,0) from Logistic_ClosingFiledt where LCF_Id = $lfId and Document_id = $ldId ";//echo $querydt;
	$resdt = mysql_query($querydt, $connection);
	$rowdt = mysql_fetch_row($resdt);
	$lfDtId = $rowdt[0];
	$$org  = $rowdt[1];
	$$copy = $rowdt[2];
	
	echo "<tr height='20px'><td><span class='style1'>$rwdoc[1]</span><input type='hidden' name='$detailId' id='$detailId' value='$lfDtId'></td>
			<td align='center'><input type='checkbox' name='$org' id='$org' value='".$$org."' ".($$org=='1'?'checked':'')." onclick=\"setDocument('$org')\"></td>
			<td align='center'><input type='checkbox' name='$copy' id='$copy' value='".$$copy."' ".($$copy=='1'?'checked':'')." onclick=\"setDocument('$copy')\"></td>
		</tr>";

	
}

echo "</table></div></td></tr>";
echo"</table>";
	
	
echo "</td></tr>";



echo"<tr><td >&nbsp;</td><td 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  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></tr>";
echo "</table></td></tr>";		
  
echo" <tr height='30'><td align='center' id='content-bottom' ></td></tr>";
include("footer.php");	

print <<< HERE
      
	  </table>
	  </form>
HERE;

if ($printRep == 1 && $lfId != ''){
	echo "<script>
		PrintRecord('$lfId');
		ClearPage();
		</script>";
}

print <<<HERE

</body>

HERE;

?>