<?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_OperationLogisticSetupApp 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($olStatus=='')  		$olStatus	= 'PENDING';
if($olOBLFrom=='')  	$olOBLFrom	= 'BANK';
if($olDate=='')  		$olDate		= date('d/m/Y');

$tab1 = "Service";
$tab2 = "Dealer";
$tab3 = "Ship Co";
$tab4 = "Team";
$tab5 = "Terminal";
$tab6 = "Destination";
$tab7 = "Transporter";
$tab8 = "Pick Up Point";


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>Logistics Setup</title>

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

function saveRow(rowId, index, tablename){
	let str = 'Form_OperationsLogistics_Setup_Action.php?mainmode=save&tablename='+tablename+'&rowId='+rowId;
	let allowSave = 1;
	let vCode;
	document.getElementById('loadergif').style.display='block';
	
	if (tablename == 'service'){
		let serviceCode = encodeURIComponent(document.getElementById('serviceCode'+index).value);
		let serviceDesc = encodeURIComponent(document.getElementById('serviceDesc'+index).value);
		let serviceSeq  = document.getElementById('serviceSeq'+index).value;
		vCode = serviceCode;
		
		str = str+'&serviceCode='+serviceCode+'&serviceDesc='+serviceDesc+'&serviceSeq='+serviceSeq;
	}
	
	if (tablename == 'dealer'){
		let dealerCode = encodeURIComponent(document.getElementById('dealerCode'+index).value);
		let dealerDesc = encodeURIComponent(document.getElementById('dealerDesc'+index).value);
		vCode = dealerCode;
		str = str+'&dealerCode='+dealerCode+'&dealerDesc='+dealerDesc;
	}
	
	if (tablename == 'ship'){
		let shipCode = encodeURIComponent(document.getElementById('shipCode'+index).value);
		let shipDesc = encodeURIComponent(document.getElementById('shipDesc'+index).value);
		vCode = shipCode;
		str = str+'&shipCode='+shipCode+'&shipDesc='+shipDesc;
	}
	
	if (tablename == 'team'){
		let teamCode = encodeURIComponent(document.getElementById('teamCode'+index).value);
		let teamDesc = encodeURIComponent(document.getElementById('teamDesc'+index).value);
		vCode = teamCode;
		str = str+'&teamCode='+teamCode+'&teamDesc='+teamDesc;
	}
	
	if (tablename == 'terminal'){
		let terminalCode = encodeURIComponent(document.getElementById('terminalCode'+index).value);
		let terminalDesc = encodeURIComponent(document.getElementById('terminalDesc'+index).value);
		vCode = terminalCode;
		str = str+'&terminalCode='+terminalCode+'&terminalDesc='+terminalDesc;
	}
	
	if (tablename == 'destination'){
		let destinationCode = encodeURIComponent(document.getElementById('destinationCode'+index).value);
		let destinationDesc = encodeURIComponent(document.getElementById('destinationDesc'+index).value);
		vCode = destinationCode;
		str = str+'&destinationCode='+destinationCode+'&destinationDesc='+destinationDesc;
	}
	
	if (tablename == 'transporter'){
		let transporterCode = encodeURIComponent(document.getElementById('transporterCode'+index).value);
		let transporterDesc = encodeURIComponent(document.getElementById('transporterDesc'+index).value);
		vCode = transporterCode;
		str = str+'&transporterCode='+transporterCode+'&transporterDesc='+transporterDesc;
	}
	
	if (tablename == 'pickup'){
		let pickupCode = encodeURIComponent(document.getElementById('pickupCode'+index).value);
		let pickupDesc = encodeURIComponent(document.getElementById('pickupDesc'+index).value);
		vCode = pickupCode;
		str = str+'&pickupCode='+pickupCode+'&pickupDesc='+pickupDesc;
	}
	
	if (vCode == ''){
		alert('Code Field is Empty!');
		document.getElementById('loadergif').style.display='none';
		allowSave = 0;
		return 0;
	}
		
	if(allowSave == 1){
		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('loadergif').style.display='none';
					if (data[1] != '') alert(data[1]); 
					document.getElementById('div-'+tablename).innerHTML = data[2];
				}
			  }
		xmlhttp.open("GET",str,true);
		xmlhttp.send(); 
	} 
}

function deleteRow(rowId, index, tablename){
	let str = 'Form_OperationsLogistics_Setup_Action.php?mainmode=delete&tablename='+tablename+'&rowId='+rowId;
	document.getElementById('loadergif').style.display='block';
	
	
	if(confirm("Delete Selected 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]");
					document.getElementById('loadergif').style.display='none';
					if (data[1] != '') alert(data[1]); 
					document.getElementById('div-'+tablename).innerHTML = data[2];
				}
			  }
		xmlhttp.open("GET",str,true);
		xmlhttp.send(); 
	} 
}
</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: 18px;
	width: 90%;
}

.divStyle {
	width: 100%;
    height: 400px;
    overflow-y: scroll;
    overflow-x: hidden;
}
</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='losetup' method='post' enctype='multipart/form-data' >
<input type='hidden' name='mainmode' value='$mainmode'>
<input type=hidden name='message' value='$message'>
<input type=hidden name='olId' value='$olId'>
<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'>Logistics Setup</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"		</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><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'>";	  
	
	$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-service' class='divStyle'>";
		// function in fuctions_Logistics.php
		drawService($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-dealer' class='divStyle'>";
		// function in fuctions_Logistics.php
		drawDealer($connection);	
	echo "</div></td></tr>";	 
	echo "</table>";  
	$tabs->end();
	
	$tabs->start($tab3);
	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-ship' class='divStyle'>";
		// function in fuctions_Logistics.php
		drawShipCo($connection);	
	echo "</div></td></tr>";	
	echo "</table>";
	$tabs->end();
	
	$tabs->start($tab4);
	echo"<table border='0' style='table-layout:fixed' align='left' valign='top' width='100%'>
      <col width=10%>";
	echo"<tr bgcolor='#F7F7F7' height='25'>
		<td valign='center' align='left'><div id='div-team' class='divStyle'>";
		// function in fuctions_Logistics.php
		drawTeam($connection);	
	echo "</div></td></tr>";	
	echo "</table>";
	$tabs->end();
	
	$tabs->start($tab5);
	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-terminal' class='divStyle'>";
		// function in fuctions_Logistics.php
		drawTerminal($connection);	
	echo "</div></td></tr>";
	echo "</table>";
	$tabs->end();
	
	$tabs->start($tab6);
	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-destination' class='divStyle'>";
		// function in fuctions_Logistics.php
		drawDestination($connection);	
	echo "</div></td></tr>";
	echo "</table>";
	$tabs->end();
	
	$tabs->start($tab7);
	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-transporter' class='divStyle'>";
		// function in fuctions_Logistics.php
		drawTransporter($connection);	
	echo "</div></td></tr>";
	echo "</table>";
	$tabs->end();
	
	$tabs->start($tab8);
	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-pickup' class='divStyle'>";
		// function in fuctions_Logistics.php
		drawPickUp($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;

?>