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

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

print <<<HERE
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="default.css" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Add Default Values</title>
<script type="text/javascript" language="javascript">
function setdef(){
	if(document.getElementById('chk_default').checked)
		document.getElementById('chk_default').value=1;
	else document.getElementById('chk_default').value=0;
}

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

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.focus();
}

function openvessel(){
	win = window.open('List_Vessel.php?str=2', 'Form_ManifestsSearch', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=800,height=400,top=100');		
	win.focus();
}
function openlocation(str){
	win = window.open('list_location.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 clearform(){
	var x = document.manifestdef;
	x.auto_vessel.value='';
	x.chk_default.value='';
	x.voyage_year.value='';
	x.voyage_number.value='';
	x.line_operator.value='';
	x.voyage_BOLnumber.value='';
	x.voyage_destination.value='';
	x.vessel_id.value='';
	x.Portofloading.value='';
	
	x.Freight_type.value='';
	x.vessel_id.value='';
	x.issued.value='';
	
	x.issued_date.value='';
	x.manifest_date.value='';
	x.received_date.value='';
	
	x.agent1_id.value='';
	x.negotiable_BOL.value='';
	x.term_of_carriage.value='';
	x.linear_meters.value='';
	
	x.action = "Form_ManifestDefaultVal.php";
	x.submit();	 
}

function set_limit(){
	perpage=document.manifestdef.perpage.value;
	document.manifestdef.action='Form_ManifestsSearch.php?perpage='+perpage;
	document.manifestdef.submit();
}

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

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

function submitDefVal(){ 
	var x = document.manifestdef;
	x.action = "Form_Manifests_Action.php?actionmode=saveDefault";
	x.submit();	 
} 
function editRec(id){
	var x = document.manifestdef;
	x.auto_vessel.value=id;
	x.submit();
}
function deleteRec(id){
	var x = document.manifestdef;
	x.action = "Form_Manifests_Action.php?actionmode=deleteDefault&auto_vessel="+id;
	x.submit();	 
}
</script>
<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>
<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;
}
.style11 {color: #999999; font-weight: bold; }
.style12 {
	font-size: 9px;
	color: #999999;
	font-weight: bold;
}
.style15 {color: #5151FF; }
.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: #000000 ;font-size: 10px;}

</style>

</head>
<body >
<form name='manifestdef' method='post' action=''>
<input type='hidden' name='auto_vessel' id='auto_vessel' value='$auto_vessel'>
HERE;

echo"<table border='0' style='table-layout:fixed'>
	  <col width=200>
	  <col width=200>
	  <col width=200>
	  <col width=200>
	  <col width=200>
	  <col width=200>
	  <tr bgcolor='#DDDDDD'>
	    <td align='center' colspan='6'><span class='style16'>Add Default Values</span></td></tr>
	  <tr bgcolor='#DDDDDD' height=30px>
	    <td align='left' colspan='1'><span class='style11'>Search</span></td>
		<td align='left' colspan=4><span class='style11'><input type='text' name='PRef' id='PRef' value='$PRef' size='15' maxlength='30'/><input type='hidden' name='PMode' id='PMode' value='$PMode' size='15' maxlength='30'/></span>
		    <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='btnCancel' value='Cancel' onclick=\"clearform();\" style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'/>";
	echo "	<input type='button' name='saveDef' value='Save' onclick=\"submitDefVal();\" style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'/></td>";		
	echo "<td align='left' valign='center'><span class='style25'>Result per page </span><span class='style11'>
		<select name='perpage' id='perpage' value='$perpage' onchange=set_limit();>";
              


        if ($perpage==20)
			$s20 = 'selected';
		else if ($perpage==30)
			$s30 = 'selected';
		else if ($perpage==40)
			$s40 = 'selected';
		else if ($perpage==50)
			$s50 = 'selected';

			
				
        echo'<option '.$s20.' value="20">20</option>
			 <option '.$s30.' value="30">30</option>
			 <option '.$s40.' value="40">40</option>
			 <option '.$s50.' value="50">50</option>
			 </select></span>';
		
		
		echo "</td>";
		
		
echo" </tr>";

echo"  <tr bgcolor='#DDDDDD'>
		<td height='15' align='center' colspan='6'><font size='1' color='#FF0000' face='Verdana'><b>".$message."</b></font></td>
	  </tr>	";
if($auto_vessel != ''){
	$query = "select default_value, voyage_year, voyage_number, line_operator, voyage_BOLnumber, voyage_destination, vessel_id, Portofloading, Freight_type, issued, 
		   date_format(issued_date,'%d-%m-%y') as issued_date, date_format(Manifest_date,'%d-%m-%y') as Manifest_date, date_format(received_date,'%d-%m-%y') as received_date, 
		   currency, Agent1_id, Negotiable_BOL, term_of_carriage, linear_meters
		   from default_vessel
			where auto_vessel = $auto_vessel;";
	$result = mysql_query($query, $connection);
	$rw = mysql_fetch_row($result);
	$chk_default 		= $rw[0];
	$voyage_year 		= $rw[1];
	$voyage_number 		= $rw[2];
	$line_operator 		= $rw[3];
	
	$voyage_BOLnumber 	= $rw[4];
	$voyage_destination = $rw[5];
	$vessel_id	 		= $rw[6];
	
	$Portofloading 		= $rw[7];
	$Freight_type 		= $rw[8];
	$issued	 			= $rw[9];
	
	$issued_date 		= $rw[10];
	$manifest_date 		= $rw[11];
	$received_date	 	= $rw[12];
	
	$currency 			= $rw[13];
	$agent1_id 			= $rw[14];
	$negotiable_BOL	 	= $rw[15];
	
	$term_of_carriage 	= $rw[16];
	$linear_meters 		= $rw[17];
	
}	
if($chk_default == '') $chk_default = 0;
$current_year= date("y");
if($auto_vessel == '') {
	$voyage_year=$current_year;
	$voyage_BOLnumber = 'I';
}
	
echo "<tr bgcolor='#DDDDDD' height='25'><td colspan='6'> <span class='style25'><input type='checkbox' name='chk_default' id='chk_default' value='$chk_default' onclick=\"setdef();\" ".($chk_default == '1'?'checked':'').">
				Set as Default</span></td></tr>";	  

echo "<tr bgcolor='#DDDDDD' height='25'>
			<td > <span class='style25'>Voy Year</span></td>
			<td> <input type='text' name='voyage_year' id='voyage_year' value='$voyage_year' style='width:100px;'></td>
			<td > <span class='style25'>BL Type</span></td>
			<td> <select name='voyage_BOLnumber' id='voyage_BOLnumber' style='width:100px;'>
			<option value='' ".($voyage_BOLnumber == ''?'selected':'')."></option>
			<option value='I' ".($voyage_BOLnumber == 'I'?'selected':'').">I</option>
			<option value='E' ".($voyage_BOLnumber == 'E'?'selected':'').">E</option>
			<option value='G' ".($voyage_BOLnumber == 'G'?'selected':'').">G</option>
			<option value='G' ".($voyage_BOLnumber == 'G'?'selected':'').">T</option>
			</select></td>
			<td > <span class='style25'>Port of Loading</span></td>
			<td><select name='Portofloading' id='Portofloading' style='width:150px;'>";
$query="select port_name from port";
$res=mysql_query($query,$connection);			
		echo "<option value=''></option>";
		while($row=mysql_fetch_array($res)){
			echo "<option value='$row[0]' ".($row[0]==$Portofloading?'selected':'').">$row[0]</option>";
		}
echo "		</select></td>
	  </tr>";	 

echo "<tr bgcolor='#DDDDDD' height='25'>
			<td > <span class='style25'>Voy No</span></td>
			<td> <input type='text' name='voyage_number' id='voyage_number' value='$voyage_number' style='width:100px;'></td>
			<td > <span class='style25'>Voy Destination</span></td>
			<td><input type='text' name='voyage_destination' id='voyage_destination' value='$voyage_destination' style='width:100px;'>
				<input type='image' src='img/btnopen.jpg' title='Select client ' width='15' height='17 border='0' onmouseover=\"style.cursor='hand'\" onclick='openvoyagedest(5); return false' style='cursor: pointer;'>
			</td>
			<td > <span class='style25'>Freight</span></td>
			<td><select name='Freight_type' id='Freight_type' style='width:50px'>
				<option value='CO' ".($Freight_type=='CO'?'selected':'').">CO</option>
				<option value='PR' ".($Freight_type=='PR'?'selected':'').">PR</option>
			</select></td>
	  </tr>";
echo "<tr bgcolor='#DDDDDD' height='25'>
			<td > <span class='style25'>Line Op</span></td>
			<td> <input type='text' name='line_operator' id='line_operator' value='$line_operator' style='width:100px;'>
				<input type='image' src='img/btnopen.jpg' title='Select client ' width='15' height='17 border='0' onmouseover=\"style.cursor='hand'\" onclick='openoperator(); return false' style='cursor: pointer;'></td>
			<td > <span class='style25'>Vessel</span></td>
			<td> <input type='text' name='vessel_id' id='vessel_id' value='".htmlspecialchars($vessel_id, ENT_QUOTES)."' style='width:100px;'>
			     <input type='image' src='img/btnopen.jpg' title='Select Vessel ' width='15' height='17 border='0' onmouseover=\"style.cursor='hand'\" onclick='openvessel(); return false' style='cursor: pointer;'>
			</td>
			<td > <span class='style25'>Currency</span></td>
			<td><SELECT name='currency' id='currency' >
				<option value=''></option>";
	$cur = "select currency_code from currency";
	$resultcur=mysql_query($cur);
	while($rowcur=mysql_fetch_array($resultcur)){
		
		echo "<option value='$rowcur[0]' ".($rowcur[0]==$currency?'selected':'').">$rowcur[0]</option>";
	}				
echo "		</select></td>
	  </tr>";	  

echo "<tr bgcolor='#DDDDDD' height='25'>
		<td > <span class='style25'>Issue At</span></td>
		<td>
		  <input type='text' name='issued' id='issued' value='".htmlspecialchars($issued, ENT_QUOTES)."' style='width:130px;'>
		  <input type='image' src='img/btnopen.jpg' title='Select Location ' width='15' height='17 border='0' onmouseover=\"style.cursor='hand'\" onclick='openlocation(11); return false' style='cursor: pointer;'>
		</td>
		<td colspan='2'> <span class='style25'>Carrier Signature/the Agent of the carrier</span></td>
		<td colspan='2'> <input type='text' name='agent1_id' id='agent1_id' value='".htmlspecialchars($agent1_id, ENT_QUOTES)."' style='width:180px;'> </td>
	</tr>";
	
echo "<tr bgcolor='#DDDDDD' height='25'>
		<td > <span class='style25'>On</span></td>
		<td>
			<input type='text' name='issued_date' id='issued_date' value='$issued_date' style='width:90px;'>
			<a HREF='#' onClick=\"displayCalendar(document.manifestdef.issued_date,'dd-mm-yyyy',this); return false;\" NAME=\"anchor1\" ID=\"anchor1\" >
			<image src='./img/cal.gif' border=0 align=center ></image></a>
		</td>
		<td colspan='2'> <span class='style25'>Number Of NegotiableB/L Issued</span></td>
		<td colspan='2'> <input type='text' name='negotiable_BOL' id='negotiable_BOL' value='".htmlspecialchars($negotiable_BOL, ENT_QUOTES)."' style='width:180px;'> </td>
	</tr>";

echo "<tr bgcolor='#DDDDDD' height='25'>
		<td > <span class='style25'> Date</span></td>
		<td><input type='text' name='manifest_date' id='manifest_date' value='$manifest_date' style='width:90px;'>
			<a HREF='#' onClick=\"displayCalendar(document.manifestdef.manifest_date,'dd-mm-yyyy',this); return false;\" NAME=\"anchor1\" ID=\"anchor1\" >
			<image src='./img/cal.gif' border=0 align=center ></image></a>
		</td>
		<td colspan='2'> <span class='style25'>TOC</span></td>
		<td colspan='2'><select name='term_of_carriage' id='term_of_carriage' style='width:100px;'>
		<option value=''></option>";
	$query="select code from toc";
	$res=mysql_query($query,$connection) or die(mysql_error());			
	while($row=mysql_fetch_array($res)){
		echo "<option value='$row[0]' ".($row[0]==$term_of_carriage?'selected':'').">$row[0]</option>";
	}	
echo "	</select></td>
	</tr>";	
echo "<tr bgcolor='#DDDDDD' height='25'>
		<td > <span class='style25'> Received Date</span></td>
		<td>
			<input type='text' name='received_date' id='received_date' value='$received_date' style='width:90px;'>
			<a HREF='#' onClick=\"displayCalendar(document.manifestdef.received_date,'dd-mm-yyyy',this); return false;\" NAME=\"anchor1\" ID=\"anchor1\" >
			<image src='./img/cal.gif' border=0 align=center ></image></a>
		</td>
		<td colspan='2'> <span class='style25'>Linear Meters </span></td>
		<td colspan='2'><input type='text' name='linear_meters' id='linear_meters' value='".htmlspecialchars($linear_meters, ENT_QUOTES)."' style='width:100px;'></td>
	</tr>";		
	



$querysearch=" select auto_vessel, if(default_value=1, '&#x2714;','') as default_value, voyage_year, voyage_number, line_operator, voyage_BOLnumber, voyage_destination, vessel_id, Portofloading, Freight_type, issued, 
			   date_format(issued_date,'%d-%m-%y') as issued_date, date_format(Manifest_date,'%d-%m-%y') as Manifest_date, date_format(received_date,'%d-%m-%y') as received_date, 
			   currency, Agent1_id, Negotiable_BOL, term_of_carriage, linear_meters
			   from default_vessel
			   order by auto_vessel desc ";

//echo $querysearch;
$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());
$totalrows = mysql_num_rows($resultsearch);
	
if ($startrange=='')
	$startrange = 0;
if ($perpage=='')
	$perpage = 20;
		
$querysearch = $querysearch." limit ".$startrange.",".$perpage;
$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());		

echo "<tr><td colspan='6'><table width='1200px' cellspacing='0' cellpading='0'>
		<col width=20><col width=20><col width=30><col width=60><col width=60><col width=60><col width=60><col width=90><col width=120>
		<col width=120><col width=120><col width=120><col width=90><col width=90><col width=90>";
	

	echo "	  <tr bgcolor='#CCD8E6'>

		<td  height='25' align='center'><span class='style25'>&nbsp;</span></td>
		<td  height='25' align='center'><span class='style25'>&nbsp;</span></td>
		<td  height='25' align='center'><span class='style25'>Default</span></td>
		<td  height='25' align='center'><span class='style25'>Voy Year</span></td>
		<td  height='25' align='center'><span class='style25'>Voy No</span></td>
		<td  height='25' align='center'><span class='style25'>Line Op</span></td>
		<td  height='25' align='center'><span class='style25'>BL Type</span></td>
		<td  height='25' align='center'><span class='style25'>Vessel</span></td>
		<td  height='25' align='center'><span class='style25'>Destination</span></td>
		<td  height='25' align='center'><span class='style25'>Port of Loading</span></td>
		<td  height='25' align='center'><span class='style25'>Freight</span></td>
		<td  height='25' align='center'><span class='style25'>Issue At</span></td>
		<td  height='25' align='center'><span class='style25'>On</span></td>
		<td  height='25' align='center'><span class='style25'>Date</span></td>
		<td  height='25' align='center'><span class='style25'>Received Date</span></td>
	 </tr>";
		
echo "</table></td></tr>";

echo "<tr><td colspan='6'><div><table width='1200px' cellspacing='0' cellpading='0'>
		<col width=20><col width=20><col width=30><col width=60><col width=60><col width=60><col width=60><col width=90><col width=120>
		<col width=120><col width=120><col width=120><col width=90><col width=90><col width=90>";
		
while($rw = mysql_fetch_array($resultsearch)){
	extract($rw);
	$ct+=1;

	if($ct%2==0)
		$Color="style='background-color:".$grid_color1."'";
	else			
		$Color="style='background-color:".$grid_color2."'";	
	echo "<tr $Color>

		<td  height='25' align='center'><span class='style15'>
			<img border='0' src='img/button_edit.png' width='12' height='12' title='Edit Detail' onmouseover=\"this.style.cursor='pointer'\" onclick=\"editRec('$auto_vessel');\"></span>
		</td>
		<td  height='25' align='center'><span class='style15'>
			<img border='0' src='img/c_delete.png' width='12' height='12' title='Edit Detail' onmouseover=\"this.style.cursor='pointer'\" onclick=\"deleteRec('$auto_vessel');\"></span>
		</td>
		<td  height='25' align='center'><span class='style15'>$default_value</span></td>
		<td  height='25' align='center'><span class='style15'>$voyage_year</span></td>
		<td  height='25' align='center'><span class='style15'>$voyage_number</span></td>
		<td  height='25' align='center'><span class='style15'>$line_operator</span></td>
		<td  height='25' align='center'><span class='style15'>$voyage_BOLnumber</span></td>
		<td  height='25' align='center'><span class='style15'>$vessel_id</span></td>
		<td  height='25' align='center'><span class='style15'>$voyage_destination</span></td>
		<td  height='25' align='center'><span class='style15'>$Portofloading</span></td>
		<td  height='25' align='center'><span class='style15'>$Freight_type</span></td>
		<td  height='25' align='center'><span class='style15'>$issued</span></td>
		<td  height='25' align='center'><span class='style15'>$issued_date</span></td>
		<td  height='25' align='center'><span class='style15'>$Manifest_date</span></td>
		<td  height='25' align='center'><span class='style15'>$received_date</span></td>
	 </tr>";
}		
echo "</table></div></td></tr>";
		
echo"   <tr><td colspan='6'>&nbsp;</td></tr>
		<tr><td colspan=6><table width='100%' border=0><tr><td width='260'>&nbsp;</td><td width='150' 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 width='150' 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><td width='170'>&nbsp;</td></tr>";
		echo"<table>";

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


          

		  

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

HERE;

?>