<?php

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


include("config.inc.php");
include("functions_Logistics.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_TransporterLogisticsApp 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");


class tabs {
	var $name;
	var $tabs;
	var $active;
	var $current;
function start($name){
		if (empty($this->active)){ $this->active = $name; }
		$this->current = $name;
		ob_start();
	}
	function end(){
		$this->tabs[$this->current] = ob_get_contents();
		ob_end_clean();
	}
	function run(){
	
	
	
		if (count($this->tabs) > 0){
			echo "<DIV CLASS='tabs'>\n";
			$jsClear = "";
			foreach($this->tabs as $tabname => $tabcontent){
				$tabid = "tab_".$this->name."_$tabname";
				$contentid = "tabcontent_".$this->name."_$tabname";
				$jsClear .= "\tdocument.getElementById('$tabid').className = 'tab_inactive';\n";
				$jsClear .= "\tdocument.getElementById('$contentid').style.display = 'none';\n";
			}
			echo "<script type=\"text/javascript\">\n";
			echo "function tab_".$this->name."(id,fieldname){\n";
			echo "$jsClear";
			
			echo "\tdocument.getElementById('tab_".$this->name."_'+id).className = 'tab_active';\n";
			echo "\tdocument.getElementById('tabcontent_".$this->name."_'+id).style.display = '';\n";
			
			echo"	
				//alert(fieldname);
				if(fieldname!='' && fieldname!=undefined)
					
					document.clientdt[fieldname].focus();
				";
			echo "}\n";
			echo "</script>\n";
			foreach($this->tabs as $tabname => $tabcontent){
				$tabid = "tab_".$this->name."_$tabname";
				$contentid = "tabcontent_".$this->name."_$tabname";
				echo "<DIV CLASS='";
				if ($this->active == $tabname){ echo "tab_active"; }else{ echo "tab_inactive"; }
				echo "' ID='$tabid' ";
				echo "onClick=\"tab_".$this->name."('$tabname');\">$tabname</DIV>\n";
			}
			echo "<DIV STYLE='float: center; clear:both;'></DIV>\n";
			foreach($this->tabs as $tabname => $tabcontent){
				$contentid = "tabcontent_".$this->name."_$tabname";
				echo "<DIV ID = '$contentid' CLASS='tab_content' STYLE='display: ";
				if ($this->active == $tabname){ echo "block"; }else{ echo "none"; }
				echo ";'>$tabcontent</DIV>\n";
			}
			echo "</DIV>\n";
			echo "<DIV STYLE='clear: both;'></DIV>\n";
		}}
}	


$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($creationDate=='')  	$creationDate	= date('d/m/Y');

$tab1 = "20 FT";
$tab2 = "40 FT";


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>Logistic Transport</title>

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

function loadOperation(){
	window.open('Form_LoadOperationLogistic.php','Search','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');	
}
function SearchTransport(){
	window.open('Form_SearchTransport.php','Search','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');	
}
function ShowlistLogisticOp(vFrm, vItem, vCode,vIndex){
	var vCode = encodeURIComponent(document.getElementById(vCode).value);
	
	window.open('List_LogisticOpSetup.php?frm='+vFrm+'&item='+vItem+'&index='+vIndex+'&PCode='+vCode,'List','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}
function saveRow(rowId,index,cType){
	let x = document.translog;
	
	let mainmode	 		= x.mainmode.value;
	let tlId	 			= x.tlId.value;
	let creationDate 		= x.creationDate.value;
	let tlProjectCode 		= x.tlProjectCode.value;
	let tlDestinationId 	= x.tlDestinationId.value;
	let tlTerminalId 		= x.tlTerminalId.value;
	
	let tlCntrNo	 		= document.getElementById('tlCntrNo'+cType+'-'+index).value;
	let tlCntrSize	 		= document.getElementById('tlCntrSize'+cType+'-'+index).value;
	let tlTruckNo	 		= document.getElementById('tlTruckNo'+cType+'-'+index).value;
	let tlTransporterId		= document.getElementById('tlTransporterId'+cType+'-'+index).value;
	let tlPickUpPntId		= document.getElementById('tlPickUpPntId'+cType+'-'+index).value;
	let tlStatus			= document.getElementById('tlStatus'+cType+'-'+index).value;
	let tlOutPortD			= document.getElementById('tlOutPortD'+cType+'-'+index).value;
	let tlOutPortT			= document.getElementById('tlOutPortT'+cType+'-'+index).value;
	let tlArrivalClientD	= document.getElementById('tlArrivalClientD'+cType+'-'+index).value;
	let tlArrivalClientT	= document.getElementById('tlArrivalClientT'+cType+'-'+index).value;
	let tlOffloadD			= document.getElementById('tlOffloadD'+cType+'-'+index).value;
	let tlOffloadT			= document.getElementById('tlOffloadT'+cType+'-'+index).value;
	let tlDropEmptyD		= document.getElementById('tlDropEmptyD'+cType+'-'+index).value;
	let tlDropEmptyT		= document.getElementById('tlDropEmptyT'+cType+'-'+index).value;
	let tlTimeTDOD			= document.getElementById('tlTimeTDOD'+cType+'-'+index).value;
	let tlTimeTDOT			= document.getElementById('tlTimeTDOT'+cType+'-'+index).value;
	let tlDaysReach			= document.getElementById('tlDaysReach'+cType+'-'+index).value;
	let tlDaysOffload		= document.getElementById('tlDaysOffload'+cType+'-'+index).value;
	let tlDaysDrop			= document.getElementById('tlDaysDrop'+cType+'-'+index).value;
	let tlDriverName		= document.getElementById('tlDriverName'+cType+'-'+index).value;
	let tlDriverPhone		= document.getElementById('tlDriverPhone'+cType+'-'+index).value;
	let tlCardWaybillReturnD= document.getElementById('tlCardWaybillReturnD'+cType+'-'+index).value;
	let tlCardWaybillReturnT= document.getElementById('tlCardWaybillReturnT'+cType+'-'+index).value;
	
	
	if (tlProjectCode == ''){
		alert ('File Field is Empty!');
		return 0;
	}
	else {
		document.getElementById('loadergif').style.display='block';
		if (window.XMLHttpRequest)
			  {// code for IE7+, Firefox, Chrome, Opera, Safari
			  xmlhttp=new XMLHttpRequest();
			  }
			else
			  {// code for IE6, IE5
			  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			  }
			xmlhttp.onreadystatechange=function()
			  {
			  if (xmlhttp.readyState==4 && xmlhttp.status==200)
				{	
					var data = xmlhttp.responseText.split("[BRK]");
					if (data[1] != '') alert(data[1]);
					document.getElementById('loadergif').style.display='none';
					document.getElementById('div-container'+cType).innerHTML = data[2];
					
				}
			  }
		xmlhttp.open("GET",'Form_TransporterLogistic_Action.php?mainmode='+mainmode+'&tlId='+tlId+'&modedt=editDetail&rowId='+rowId+'&creationDate='+creationDate
				+'&tlProjectCode='+tlProjectCode+'&tlDestinationId='+tlDestinationId+'&tlTerminalId='+tlTerminalId
				+'&tlCntrNo='+tlCntrNo+'&tlCntrSize='+tlCntrSize+'&tlTruckNo='+tlTruckNo+'&tlTransporterId='+tlTransporterId+'&tlPickUpPntId='+tlPickUpPntId
				+'&tlStatus='+tlStatus+'&tlOutPortD='+tlOutPortD+'&tlOutPortT='+tlOutPortT+'&tlArrivalClientD='+tlArrivalClientD+'&tlArrivalClientT='+tlArrivalClientT
				+'&tlOffloadD='+tlOffloadD+'&tlOffloadT='+tlOffloadT+'&tlDropEmptyD='+tlDropEmptyD+'&tlDropEmptyT='+tlDropEmptyT+'&tlTimeTDOD='+tlTimeTDOD
				+'&tlTimeTDOT='+tlTimeTDOT+'&tlDaysReach='+tlDaysReach+'&tlDaysOffload='+tlDaysOffload+'&tlDaysDrop='+tlDaysDrop+'&cType='+cType
				+'&tlDriverName='+tlDriverName+'&tlDriverPhone='+tlDriverPhone+'&tlCardWaybillReturnD='+tlCardWaybillReturnD+'&tlCardWaybillReturnT='+tlCardWaybillReturnT,true);
		xmlhttp.send();
	}
}
function deleteRow(rowId,index,cType){
	let tlId	= document.translog.tlId.value;
	if(confirm("Are you sure you want to delete this Record?")){
	if (window.XMLHttpRequest)
			  {// code for IE7+, Firefox, Chrome, Opera, Safari
			  xmlhttp=new XMLHttpRequest();
			  }
			else
			  {// code for IE6, IE5
			  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			  }
			xmlhttp.onreadystatechange=function()
			  {
			  if (xmlhttp.readyState==4 && xmlhttp.status==200)
				{	
					var data = xmlhttp.responseText.split("[BRK]");
					if (data[1] != '') alert(data[1]);
					document.getElementById('div-container'+cType).innerHTML = data[2];
					document.getElementById('tlSerialNo').value = data[3];
					
				}
			  }
		xmlhttp.open("GET",'Form_TransporterLogistic_Action.php?mainmode=&tlId='+tlId+'&modedt=deleteDetail&rowId='+rowId+'&cType='+cType,true);
		xmlhttp.send();
	}
	
}
function getLogisticDays(cType, index){
	let tlOutPortD			= document.getElementById('tlOutPortD'+cType+'-'+index).value;
	let tlOutPortT			= document.getElementById('tlOutPortT'+cType+'-'+index).value;
	let tlArrivalClientD	= document.getElementById('tlArrivalClientD'+cType+'-'+index).value;
	let tlArrivalClientT	= document.getElementById('tlArrivalClientT'+cType+'-'+index).value;
	let tlOffloadD			= document.getElementById('tlOffloadD'+cType+'-'+index).value;
	let tlOffloadT			= document.getElementById('tlOffloadT'+cType+'-'+index).value;
	let tlDropEmptyD		= document.getElementById('tlDropEmptyD'+cType+'-'+index).value;
	let tlDropEmptyT		= document.getElementById('tlDropEmptyT'+cType+'-'+index).value;
	
	
	if (window.XMLHttpRequest)
			  {// code for IE7+, Firefox, Chrome, Opera, Safari
			  xmlhttp=new XMLHttpRequest();
			  }
			else
			  {// code for IE6, IE5
			  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			  }
			xmlhttp.onreadystatechange=function()
			  {
			  if (xmlhttp.readyState==4 && xmlhttp.status==200)
				{	
					var data = xmlhttp.responseText.split("[BRK]");
					document.getElementById('tlDaysReach'+cType+'-'+index).value = data[1];
					document.getElementById('tlDaysOffload'+cType+'-'+index).value = data[2];
					document.getElementById('tlDaysDrop'+cType+'-'+index).value = data[3];
					
				}
			  }
		xmlhttp.open("GET",'Form_TransporterLogistic_Action.php?mainmode=&modedt=getDays&tlOutPortD='+tlOutPortD+'&tlOutPortT='+tlOutPortT
				+'&tlArrivalClientD='+tlArrivalClientD+'&tlArrivalClientT='+tlArrivalClientT+'&tlOffloadD='+tlOffloadD+'&tlOffloadT='+tlOffloadT
				+'&tlDropEmptyD='+tlDropEmptyD+'&tlDropEmptyT='+tlDropEmptyT,true);
		xmlhttp.send();
}

function ClearPage(){
	let x = document.translog;
	
	x.mainmode.value = '';
	x.tlId.value = '';
	x.creationDate.value = '';
	x.tlProjectCode.value = '';
	x.tlDestinationId.value = '';
	x.tlDestination.value = '';
	x.tlTerminalId.value = '';
	x.tlTerminal.value = '';
	x.tlSerialNo.value = '';
	x.action ='Form_TransporterLogistic.php';
	x.submit();
	
}

function SubmitRecord(){
	let x = document.translog;
	x.action ='Form_TransporterLogistic_Action.php';
	x.submit();	
}
</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;}

table.subtable  tr  td {
	padding-left: 5px;
}
table.subtable  tr  td input {
	height: 22px;
	width: 90%;
}

table  tr  td input {
	font-size: 13px;
    font-family: sans-serif;	
}
.divStyle {
	width: 100%;
    height: 400px;
    overflow-y: scroll;
    overflow-x: scroll;
}
input:focus, select:focus {
	border: 2px solid #008b8b;
}
input:hover, select:hover {
	border: 1px solid #008b8b;
}
</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='translog' method='post' enctype='multipart/form-data' >
<input type='hidden' name='mainmode' value='$mainmode'>
<input type=hidden name='message' value='$message'>
<input type=hidden name='tlId' value='$tlId'>
<input type=hidden name='vTabFocus' value='$vTabFocus'>


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


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'>Transport</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 ($tlId != '')
		echo " <button type='button' id='btnPost' name='btnPost' onclick=\"SubmitRecord();return false;\" title='Save Changes'><span><span>$Save</span></span></button>";			
	if ($tlId == '')
	echo " <button type='button' id='btnLoad' name='btnLoad' onclick='SearchTransport(); return false;' title='Search Transport'><span><span>Search</span></span></button>";			
	if ($tlId == '')
	echo " <button type='button' id='btnLoad' name='btnLoad' onclick='loadOperation(); return false;' title='Load From Operations'><span><span>Load From Operation</span></span></button>";			
echo"		</td>
			<td align='left' width='240px'></td><td align='left'>";
	
echo "</td></tr>";
echo"	</table>";
echo"</td></tr>";

if ($tlId != ''){
	$query = "select date_format(LT_Date,'%d/%m/%Y'), LT_ProjectCode, Project_Name, LT_DestinationId, Destination_Code, LT_TerminalId, Terminal_Code, LT_SerialNo
			from Logistic_Transport
			inner join project on Project_Code = LT_ProjectCode
			left join logistic_destination on Destination_Id = LT_DestinationId
			left join logistic_terminal on Terminal_Id = LT_TerminalId
			where LT_Id = $tlId";
	$result = mysql_query($query, $connection);
	$row = mysql_fetch_row($result);
	$creationDate 		= $row[0];
	$tlProjectCode 		= $row[1];
	$tlProjectDesc 		= $row[2];
	$tlDestinationId 	= $row[3];
	$tlDestination 		= $row[4];
	$tlTerminalId	 	= $row[5];
	$tlTerminal 		= $row[6];
	$tlSerialNo 		= $row[7];
	
}
echo"<tr><td id='content-body'>";	

echo"<table border='0'  align='center' valign='top' width=100% class='tablecontent'>
	<col width=100%>";
	echo "<tr><td align='center'><div id='loadergif' style='position: absolute; top: 50%; right: 50%;display:none;'><img src='img/Loading_icon.gif' height='150px' width='150px'></div></td></tr>";	
	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=15%><col width=30%><col width=15%><col width=40%>";
	echo "<tr>
			<td><span class='style1'>Creation Date:</span></td>
			<td><b>$creationDate </b><input type='hidden' name='creationDate' id='creationDate' value='$creationDate' ></td>  
			<td><span class='style1'>File:</span></td>
			<td><input type='text' name='tlProjectCode' id='tlProjectCode' value='$tlProjectCode' style='width: 30%;'> <input type='text' name='tlProjectDesc' id='tlProjectDesc' value='$tlProjectDesc' style='width: 50%;'></td>  
		</tr>";	
	echo "<tr>
		<td><span class='style1'>Destination:</span></td>
		<td><input type='text' name='tlDestination' id='tlDestination' value='$tlDestination' style='width: 50%;' readonly>
			<input type='hidden' name='tlDestinationId' id='tlDestinationId' value='$tlDestinationId' >
			<img src='img/btnopen.jpg' width='15' height='15' onclick=\"ShowlistLogisticOp('6','2','tlDestination','');\" title='Select Terminal' onmouseover=\"style.cursor='hand';\">
		</td>  
		<td><span class='style1'>Terminal:</span></td>
		<td><input type='text' name='tlTerminal' id='tlTerminal' value='$tlTerminal' style='width: 30%;'>
			<input type='hidden' name='tlTerminalId' id='tlTerminalId' value='$tlTerminalId' >
			<img src='img/btnopen.jpg' width='15' height='15' onclick=\"ShowlistLogisticOp('5','2','tlTerminal','');\" title='Select Terminal' onmouseover=\"style.cursor='hand';\">
		</td>  
	</tr>";	
	echo "<tr>
		<td><span class='style1'>S/N:</span></td>
		<td><input type='text' name='tlSerialNo' id='tlSerialNo' value='$tlSerialNo' style='width: 50%;' readonly></td>  
		<td></td>
		<td></td>  
	</tr>";	
	echo "<tr height='20px'><td colspan='4'></td></tr>";	
	echo "</table>"; 	 
	$tabs = new tabs("Logistics");	
	
	$tabs->start($tab1);		
	echo"<table border='0' style='table-layout:fixed' align='left' valign='top' width='100%'>
      <col width=100%>";
	
	echo"<tr bgcolor='#F7F7F7' height='25'>
		<td valign='center' align='left'><div id='div-container20' class='divStyle'>";
		// function in fuctions_Logistics.php
		drawTransporterDt('20', $tlId, $connection);
	echo "</div></td></tr>";	 
	echo "</table>"; 	
	$tabs->end();
	
	$tabs->start($tab2);
	echo"<table border='0' style='table-layout:fixed' align='left' valign='top' width='100%'>
      <col width=100%>";
	
	echo"<tr bgcolor='#F7F7F7' height='25'>
		<td valign='center' align='left'><div id='div-container40' class='divStyle'>";
		// function in fuctions_Logistics.php
		drawTransporterDt('40', $tlId, $connection);
	echo "</div></td></tr>";	 
	echo "</table>";  
	$tabs->end();
	
	$tabs->run();

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($vTabFocus!=''){
	echo'<script type="text/javascript" language="javascript">';
	echo"tab_('$vTabFocus','');";
	echo'</script>';	
}	


print <<<HERE

</body>

HERE;

?>