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



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

	
$querysetup="select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2,maxperpage from setup";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}
	


//Access Mode On Insert/Edit/Delete
$InsMode = '';

if(!isset($mode))
$mode='';



if($mode=='editmode' or $mode=='view'){

	$query_edit="select date_format(manifest_date,'%d-%m-%Y'), Voyage_year, voyage_number, voyage_destination, voyage_BOLnumber, BOL_type, BOL_identification,  Shipper1, shipper2, shipper3, shipper4, consignee1, consignee2, consignee3, consignee4,
				Notify1, Notify2, Notify3, Notify4, Precarriage, PlaceofReceipt, Portofloading, PortofDischarge, Placeofdelivery, BOL_freight, issued, date, Negotiable_BOL, term_of_carriage, 
				manifest_id ,BOL_pagenumber from manifest where manifest_auto='".$Manifest_Auto."'";
//echo $query_edit;
	 $resultedit = mysql_query($query_edit, $connection);
	while($row=mysql_fetch_array($resultedit)){

	
	$manifest_date=$row[0];
	$voyage_year=$row[1];
	$voyage_number=$row[2];
	$voyage_destination=$row[3];
	$bol_number=$row[4];
	$voyage_type=$row[5];

	$billoflading=$row[6];
	$Shipper1=$row[7];
	$Shipper2=$row[8];
	$Shipper3=$row[9];
	$Shipper4=$row[10];
	$consignee1=$row[11];
	$consignee2=$row[12];
	$consignee3=$row[13];
	$consignee4=$row[14];
	$notify1=$row[15];
	$notify2=$row[16];
	$notify3=$row[17];
	$notify4=$row[18];
	$precarriage=$row[19];
	$recieptplace=$row[20];
	$portlading=$row[21];
	$portdischarge=$row[22];
	$placedelivery=$row[23];
	$freight=$row[24];
	$issuedat=$row[25];
	$issuedon=$row[26];
	$nonegotiable=$row[27];
	$termcarriage=$row[28];
	$manifest_id=$row[29];
	$voyage_pagenumber=$row[30];
	

	}
	$mode='edit';
}

if($mode=='') $mode='insert';

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"> 
<LINK REL="stylesheet" TYPE="text/css" MEDIA="all" HREF="css/tabs.css">
<title>Imp/Exp</title>
<script type="text/javascript" language="javascript">




function SubmitRecord() {
var perpage=document.Manifest.perpage.value; 

		
//	var voyage_year=document.Manifest.voyage_year.value;
	var file1=document.Manifest.file1.value;
	document.Manifest.action="Form_Manifests_Action.php?file1="+file1;
	document.Manifest.submit();
		
		


}

function Import_manifest(){
	
	var file1=document.Manifest.file1.value;
	document.Manifest.action="Form_Import_Action.php?file1="+file1;
	document.Manifest.submit();
	
}
function Export_manifest(){
	var writemode='';
	if(confirm("do you want to clear the file before export")){
		 writemode='w';
	}
	else writemode='a';
	
	var file1=document.Manifest.file1.value;
	var showCont = 0;
	if (document.getElementById('showCont').checked)
		showCont = 1;
	
	document.Manifest.action="Form_Export_Action.php?file1="+file1+"&writemode="+writemode+"&showCont="+showCont;
				document.Manifest.submit();
	
}

function clearPage(){
	var x = document.Manifest;
	x.mode.value = '';
	x.message.value = '';
	x.ark_voyyear.value = '';
	x.ark_voynb.value = '';
	x.ark_voydest.value = '';
	x.ark_lineop.value = '';
	x.ark_pol.value = '';
	x.ark_pod.value = '';
	x.ark_rcvdate.value = '';
	x.ark_notify.value = '';
	x.ark_vessel.value = '';
	x.ark_shipper.value = '';
	x.ark_cosignee.value = '';
	x.action="Form_ImpExp.php";
	x.submit();	
}

function Import_manifest2(){
	var x = document.Manifest;
	if (x.ark_voyyear.value == ''){
		alert('Voyage Year is Empty!');
		x.ark_voyyear.focus();
		return 0;
	} else if (x.ark_voynb.value == ''){
		alert('Voyage Number is Empty!');
		x.ark_voynb.focus();
		return 0;
	} else if (x.ark_voydest.value == ''){
		alert('Voyage Destination is Empty!');
		x.ark_voydest.focus();
		return 0;
	} else if (x.ark_pol.value == ''){
		alert('Port of Loading is Empty!');
		x.ark_pol.focus();
		return 0;
	} else if (x.ark_pod.value == ''){
		alert('Port of Discharge is Empty!');
		x.ark_pod.focus();
		return 0;
	}
	else {
		document.Manifest.action="Form_Arkas_ImpExp_Action.php?mode=import";
		document.Manifest.submit();	
	}
}

function Export_manifest2(){
	var x = document.Manifest;
	if (x.ark_voyyear.value == ''){
		alert('Voyage Year is Empty!');
		x.ark_voyyear.focus();
		return 0;
	} else if (x.ark_voynb.value == ''){
		alert('Voyage Number is Empty!');
		x.ark_voynb.focus();
		return 0;
	} else if (x.ark_voydest.value == ''){
		alert('Voyage Destination is Empty!');
		x.ark_voydest.focus();
		return 0;
	} else if (x.ark_pol.value == ''){
		alert('Port of Loading is Empty!');
		x.ark_pol.focus();
		return 0;
	} else if (x.ark_pod.value == ''){
		alert('Port of Discharge is Empty!');
		x.ark_pod.focus();
		return 0;
	}
	else {
		document.Manifest.action="Form_Arkas_ImpExp_Action.php?mode=export";
		document.Manifest.submit();	
	}
}

function openvoyagedest(str){
	win = window.open('list_voydest.php?str='+str, 'clientlist', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=750,height=500,top=100');		
	//win.creator = self;
	win.focus();
}

function openoperator(str){
	win = window.open('list_operator.php?str='+str, 'containerlist', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=750,height=500,top=100');		
	
	win.focus();
}

function openvessel(str){
	win = window.open('List_Vessel.php?str='+str, 'Form_ManifestsSearch', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=800,height=400,top=100');		
	win.focus();
}

function openAgent(str){
	win = window.open('list_agent.php?str='+str, 'agentlist', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=900,height=500,top=100');		
	win.focus();
}
</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;}

</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="tabs.css">

<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">
</head>
<body >
<form name='Manifest' method='post' onKeyPress="return submitenter(this,event)">
<input type=hidden name='mode' value='$mode'>
<input type=hidden name='message' value='$message'>
<input type=hidden name='Manifest_Auto' value='$Manifest_Auto'>
HERE;



if($mode==''){
$status='disabled';
$dis='disabled';

}

if($mode=='view'){

$status='readonly';
$dis='disabled';

}

if($mode=='insert')
$status='';

//$style= "style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'";

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'>
			<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'>Import / Export</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 "&nbsp;";
					
							echo"</td>
								
							
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td id='content-body'>";
			
echo "	<table border='0'  align='center' valign='top'  class='tablecontent' >
		<col width=100%>
			<tr bgcolor='#F7F7F7' >
				<td valign='top' align='left' >";
$tabs = new tabs("impexp");		

$tabs->start("Tarros");						
	echo "<table border=0 cellpadding=0 cellspacing=0>";
	echo "<col width='120px'><col width='120px'><col width='120px'><col width='120px'><col width='120px'><col width='120px'>";
	echo "<tr>
			<td colspan='6'>
				<button type='button' id='btnPost' name='btnPost' onclick='Import_manifest(); return false;' title='Save Changes' $Insmode><span><span>import</span></span></button>&nbsp;
				<button type='export' id='export' name='export' onclick='Export_manifest(); return false;' title='Export' ><span><span>export</span></span></button>
			</td>
		 </tr>";
	echo "<tr height='10px'><td colspan='6'></td></tr>";
	echo "<tr><td colspan='6'><select name='file1' style='width:100px;'>
			<option value='all' >All File</option>
			<option value='Sndbofl1' >Sndbofl1</option>
			<option value='Sndbofl2' >Sndbofl2</option>
			<option value='Sndbofl3' >Sndbofl3</option>
			<option value='Sndbofl4' >Sndbofl4</option>
			</select></td></tr>";
	echo "<tr bgcolor='#F7F7F7' >";
	echo "  <td><span class='style1'>voyage year</span> </td>
			<td><input type='text' name='voyage_year'  size=2 maxlength='2' value='".htmlspecialchars($voyage_year, ENT_QUOTES)."'></td>";
	echo "<td><span class='style1'>voyage number  </span></td>
		  <td><input type='text' name='voyage_number'  size=3 maxlength='3' value='".htmlspecialchars($voyage_number, ENT_QUOTES)."'></td>";
	echo "<td><span class='style1'>voyage destination </span></td>
		  <td><input type='text' name='voyage_destination' size=3 maxlength='3' value='".htmlspecialchars($voyage_destination, ENT_QUOTES)."'></td>";	  
	echo "</tr>";
	
	echo "<tr height='10px'><td colspan='6'></td></tr>";
	
	echo "<tr bgcolor='#F7F7F7'>";
	echo "	<td><span class='style1'>Bol Number </span></td>
			<td><input type='text' name='bol_number' size=3  maxlength='3' value='".htmlspecialchars($bol_number, ENT_QUOTES)."'></td>";
	echo "<td><span class='style1'>Bol Type </span></td>
		<td><select name='voyage_type' >
			<option value=''></option>
			<option value='I'>I</option>
			<option value='E'>E</option>
			<option value='G'>G</option>
		</select></td>";
	echo "<td><span class='style1' >Bol page number </span></td>
		  <td><input type='text' name='voyage_pagenumber' value='".htmlspecialchars($voyage_pagenumber, ENT_QUOTES)."' maxlength='2' size=2></td>";		
	echo "</tr>";
	
	echo "<tr height='10px'><td colspan='6'></td></tr>";
	
	echo "<tr height='10px'>
			<td><span class='style1' >Local agent </span></td>
			<td><input type='text' name='Localagent' value='".htmlspecialchars($Localagent, ENT_QUOTES)."' maxlength='2' size=2></td>
			<td colspan='2'><span class='style1' ><input type='checkbox' name='showCont' id='showCont'>Show All Containers (FULL+EMPTY)</span></td>
			<td colspan='2'></td></tr>";
	
	echo "</table>";
$tabs->end();

$tabs->start("Arkas");	
		echo "<table border=0 cellpadding=0 cellspacing=0>";
		echo "<col width='120px'><col width='160px'><col width='120px'><col width='160px'><col width='120px'><col width='120px'><col width='120px'><col width='160px'>";
		echo "<tr>
				<td colspan='8'>
					<button type='button' id='btnPost' name='btnPost' onclick='clearPage(); return false;' title='Clear'><span><span>Clear</span></span></button>&nbsp;
					<button type='button' id='btnPost' name='btnPost' onclick='Import_manifest2(); return false;' title='Import'><span><span>import</span></span></button>&nbsp;
					<button type='export' id='export' name='export' onclick='Export_manifest2(); return false;' title='Export' ><span><span>export</span></span></button>
				</td>
			 </tr>";
		echo "<tr height='10px'><td colspan='8'></td></tr>";
	
	$ark_voyyear = date("y");
		echo "<tr height='30px'>
				<td><span class='style1'>Voy Year</span></td>
				<td><input type='text' name='ark_voyyear' id='ark_voyyear' value='$ark_voyyear' style='width:50px;' maxlength='2'></td>
				<td><span class='style1'>Voy Number</span></td>
				<td><input type='text' name='ark_voynb' id='ark_voynb' value='$ark_voynb' style='width:50px;'></td>
				<td><span class='style1'>Voy Destination</span></td>
				<td><input type='text' name='ark_voydest' id='ark_voydest' value='$ark_voydest' style='width:90px;'>
					<input type='image' src='img/btnopen.jpg' title='Select Destination ' width='15' height='17 border='0' onmouseover=\"style.cursor='hand'\" 
					onclick=\"openvoyagedest('6'); return false;\" style='cursor: pointer;'></td>
				<td><span class='style1'>Line Op.</span></td>	
				<td><input type='text' name='ark_lineop' id='ark_lineop' value='$ark_lineop' style='width:90px;'>
				<input type='image' src='img/btnopen.jpg' title='Select client ' width='15' height='17 border='0' onmouseover=\"style.cursor='hand'\" 
				onclick=\"openoperator('3'); return false;\" style='cursor: pointer;'></td>
			</tr>";
			
		echo "<tr height='30px'>
				<td><span class='style1'>Port of Loading</span></td>
				<td><select name='ark_pol' id='ark_pol' style='width:140px;' >
					<option value=''></option>";
				$query="select port_name from port order by port_name";
				$res=mysql_query($query,$connection);	
				while($row=mysql_fetch_array($res)){
					echo "<option value='$row[0]' ".($ark_pol==$row[0]?'selected':'').">$row[0]</option>";
				}				
		echo "	</select></td>
				<td><span class='style1'>Port of Discharge</span></td>
				<td><select name='ark_pod' id='ark_pod' style='width:140px;' >
					<option value=''></option>";
				$res=mysql_query($query,$connection);	
				while($row=mysql_fetch_array($res)){
					echo "<option value='$row[0]' ".($ark_pod==$row[0]?'selected':'').">$row[0]</option>";
				}		
		echo "	</select></td>	
				<td><span class='style1'>Received Date</span></td>
				<td><input type='text' name='ark_rcvdate' id='ark_rcvdate' style='width:90px;' value='".$ark_rcvdate."'>
					<a HREF='#' onClick=\"displayCalendar(document.Manifest.ark_rcvdate,'dd-mm-yyyy',this); return false;\" NAME=\"anchor1\" ID=\"anchor1\" >
					<image src='./img/cal.gif' border=0 align=center ></image></a></td>
				<td><span class='style1'>Notify</span></td>	
				<td><input type='text' name='ark_notify' id='ark_notify' style='width:160px;' value='".$ark_notify."'></td>
			</tr>";
			
		echo "<tr height='30px'>
				<td><span class='style1'>Vessel</span></td>
				<td><input type='text' name='ark_vessel'  id='ark_vessel' value='".$ark_vessel."' style='width:130px;'>
					<input type='image' src='img/btnopen.jpg' title='Select Vessel ' width='15' height='17 border='0' onmouseover=\"style.cursor='hand'\" 
					onclick=\"openvessel('3'); return false;\" style='cursor: pointer;'>
				<td><span class='style1'>Shipper</span></td>
				<td><input type='text' name='ark_shipper'  id='ark_shipper' value='".$ark_shipper."' style='width:130px;'>
					<input type='image' src='img/btnopen.jpg' title='Select client ' width='15' height='17 border='0' onmouseover=\"style.cursor='hand'\" 
					onclick=\"openoperator('4'); return false;\" style='cursor: pointer;'></td>
				<td><span class='style1'>Cosignee</span></td>	
				<td colspan='2'><input type='text' name='ark_cosignee'  id='ark_cosignee' value='".$ark_cosignee."' style='width:180px;'>
					<input type='image' src='img/btnopen.jpg' title='Select Source Agent ' width='15' height='17 border='0' onmouseover=\"style.cursor='hand'\" 
					onclick=\"openAgent('5'); return false;\" style='cursor: pointer;'></td>
				<td><input type='checkbox' name='ark_showCont' id='ark_showCont'><span class='style1'>Show All Containers(FULL+EMPTY)</span></td>
			</tr>";	
		
		echo "</table>";	
$tabs->end();		
$tabs->run();			
echo "</td>";

echo" <td colspan='3' bgcolor='#F5F5F5'>&nbsp;</td>";		
echo" </tr>";
echo"   </table>";
	
echo "</td></tr><tr height='30'><td align='center' id='content-bottom' ></td></tr>"; 
 echo" </table>";

print <<<HERE
</form>
</body>

HERE;

?>














