<?php

session_start();
if($HTTP_SESSION_VARS['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($HTTP_SESSION_VARS['dbName'],$connection) or die("Could not find DB");


$query_login="select ifNull(FI_Shipmentconfirmed,0) from ".$HTTP_SESSION_VARS['dbLabel'].".login where user_account='".$HTTP_SESSION_VARS['useraccount']."' and Upper(Login_Schema) = Upper('".$HTTP_SESSION_VARS['dbName']."')  ";
$resultlogin=mysql_query($query_login,$connection) or die(mysql_error());
$row_login=mysql_fetch_row($resultlogin);
$FI_Shipmentconfirmed=$row_login[0];

if ($FI_Shipmentconfirmed=='' or $FI_Shipmentconfirmed==0)
	header("location:menu.php");
	
	
	
	
	
if($mainmode=='editmode'){

	$query_edit="select shipment_reference,shipments.cltcar_code,shipment_DriverName,shipments.currency_code,ledger_name,
				shipment_totalamount,carType_code,shipmentrouting_reference from shipments
				left join cltcar on cltcar.cltcar_code=shipments.cltcar_code
				left join ledger on ledger.ledger_number=cltcar.Cltcar_Owner
				
where shipment_id='".$shipment_id."'";
	//echo$query_edit;
	$resultedit = mysql_query($query_edit,$connection);
	$row_edit=mysql_fetch_row($resultedit);	
	
	$shipment_reference=$row_edit[0];
	$cltcar_code=$row_edit[1];
	$cltcar_name=$row_edit[2];
	$currency_code=$row_edit[3];
	
	$cltcar_owner=$row_edit[4];
	$totalprice=$row_edit[5];
	$carType_code=$row_edit[6];
	$shipmentrouting_reference=$row_edit[7];

	$mainmode='edit';

}

if($totalprice=='')
	$totalprice='0';
	
	
print <<<HERE
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="default.css" type="text/css" />
<script type="text/javascript" language="javascript">

function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters center' counter
else {
countfield.value = maxlimit - field.value.length;}

}

function showlistareas(num,visitnum){

	var carType_code=document.shipment.carType_code.value;
	
  window.open('List_Shipment_Area.php?carType_code='+carType_code+'&num='+num+'&visitnumber='+visitnum,'List_Shipment_Area','width=600,height=550,left=200,top=50,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function ConfirmDelivery(){
	x=document.shipment;

	if (confirm ( "Are you sure you want to confirm This Shipment ?"))
		{
		x.mainmode.value='confirmshipment';
		x.action='Form_ShipmentRouting_Actions.php';
		x.submit();
		}
	
}

function SaveDelivery(){
	x=document.shipment;
	x.mainmode.value='saveshipment';
	x.action='Form_ShipmentRouting_Actions.php';
	x.submit();
}



function SearchForRef(){
    
	
    win = window.open('Form_ShipmentRoutingPendingSearch.php', 'Form_ShipmentRoutingSearch', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=650,height=450,top=100');		
	win.creator = self;
	win.focus();		
}

function Print_Preview (){
	x = document.shipment;
	var ref=x.shipment_reference.value;
	var shipmentid=x.shipment_id.value;
	x.showprint.value=0;

if (confirm ( "Do you want to Print Shipment Reference"+" "+ref +"?"))
	{
		
	var link = '';
	link = 'Form_ShipmentRouting_Preview.php?shipment_id='+shipmentid;
	window.open(link);
	}

}

function ClearPage() {

	
	if (confirm ( "Are you sure you want to Clear Page?"))
	{
		x = document.shipment;
		x.shipment_reference.value='';
		x.cltcar_code.value='';
		x.cltcar_name.value='';

		x.cltcar_owner.value='';
		x.shipment_id.value='';
		x.mainmode.value='';
		x.carType_code.value='';
		
		x.action='Form_ShipmentRouting_Pending.php';
		x.submit();
	}	
}


function LoadDelivery(){
	x=document.shipment;



	
	
	
	
		
		if (confirm ( "Are you sure you want to Load All Invoices ?"))
		{
		x.mainmode.value='loaddeliveries2';
		x.action='Form_ShipmentRouting_Actions.php';
		x.submit();
		}
	
}

</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Shipment Routing Pending</title>
<script type="text/javascript" src="dropdown.js"></script>
<link rel="stylesheet" href="default.css" type="text/css" />
<link rel="stylesheet" href="short.css" type="text/css" />
<link rel="stylesheet" href="dropdown.css" type="text/css" />
<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; font-size: 11px;}
.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: 12px;}
.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>
</head>
<body>
<form name='shipment' method='post' action=''>
<input type='hidden' name='mainmode' value='$mainmode'>
<input type='hidden' name='shipment_id' value='$shipment_id'>
<input type='hidden' name='showprint' value='$showprint'>


HERE;

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

echo"<table border=0 width='100%'>";
echo '<tr><td colspan="9" align="left" valign="top">';

include_once("MenuBar.php");

print <<< HERE
       </td>
      </tr>
HERE;
print <<<HERE
		<tr><th height="30" colspan="9" align="left" valign="top"><span class="style3">Shipment Routing Pending</span></th></tr>
		<tr><td height="20" colspan="9" align='center'><font size='1' color='#FF0000' face='Verdana'><b>$message</b></font></td></tr>
		<tr><td>
		<table border="0" style='table-layout:fixed'>
		<col width=120>
		<col width=280>
		<col width=120>
		<col width=110>
		<col width=110>
HERE;

echo"	<tr bgcolor='#F7F7F7' height='35'><td align='left'><span class='style11'>Routing Reference</span></td>	
<td colspan='5'><font face='Verdana' size='2'><b>$shipmentrouting_reference</b></font><input type='hidden' name='shipment_reference' value='$shipment_reference' >
	</tr>";	
	
echo"	<tr bgcolor='#F7F7F7' height='35'><td align='left'><span class='style11'>License</span></td>
		<td><input type='text' name='cltcar_code' value='$cltcar_code' readonly maxlength='10'>";

	if($mainmode==''){	
		echo"&nbsp;<label><img src='img/btnopen.jpg' title=' Select License ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onClick='showlistcars(); ' /></label>";
	}
  echo"</td><td align='center'><span class='style11'>Owner</span></td><td colspan='3'><span class='style11'></span><input type='text' name='cltcar_owner' value='$cltcar_owner' readonly maxlength='50' style='width:260px;'>";	
echo"   </tr>";	

echo"	<tr bgcolor='#F7F7F7' height='35'><td align='left'><span class='style11'>Driver Name</span></td>
		<td><input type='text' name='cltcar_name' value='".htmlspecialchars($cltcar_name, ENT_QUOTES)."'  maxlength='50' style='width:260px;'>
		<input type='hidden' name='carType_code' value='".htmlspecialchars($carType_code, ENT_QUOTES)."'  maxlength='30' style='width:260px;'></td>
		<td align='center'><span class='style11'>Total</span></td><td colspan='3'><font face='Verdana' size='2'><b>$totalprice</b></font>&nbsp;&nbsp;&nbsp;<font face='Verdana' size='2'><b>$currency_code</b></font></td>
	
		</tr>";
		
//echo"	<tr bgcolor='#F7F7F7' height='75'><td align='left'><span class='style11'>Remark</span></td>
//		<td colspan='5'><textarea name='shipment_remark'  size=100%  cols=80 rows=4 onKeyDown='textCounter(this.form.shipment_remark,this.form.remLenaddress,140);' onKeyUp='textCounter(this.form.shipment_remark,this.form.remLenaddress,140)';>".htmlspecialchars($shipment_remark, ENT_QUOTES)."</textarea></td>
//		</tr>";	
		
//$lenRemark=strlen($shipment_remark);
//$restRemark=140-$lenRemark;

	//echo"	  <tr bgcolor='#F7F7F7' height='25'><td colspan=6 align=center><span class='style12'>Remaining Chars</span>&nbsp;<input readonly type=text name=remLenaddress size=1 maxlength=3 value='$restRemark' style='font-size:11px; width:25px; height:18px; border:none; background-color:#F7F7F7; '></td></tr>";  

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

echo"<tr><td><table border=0 align=center width=100%> <tr bgcolor=#D8D8D8 height='35'>";
	echo"<td align=center>";
	echo" &nbsp;<input type='button' id='Btnconf' name='Btnconf' value='Confirm'   onclick='ConfirmDelivery();' $style title='Confirm Delivery'";
	
	if($mainmode=='')
		echo ' disabled';
	echo">";
	
		echo" &nbsp;<input type='button' id='Btnsave' name='Btnsave' value='Save'   onclick='SaveDelivery();' $style title='Save Delivery'";
	
	if($mainmode=='')
		echo ' disabled';
	echo">";
	echo" <input name='btnSearch' type='button' id='btnSearch' value='Search' onclick='SearchForRef();' $style title='Search By Reference' >
	<input name='btnClr' type='button' id='btnClr' value='Clear' onclick='ClearPage();' $style title='Clear' >";
/*<input name='btnPrint' type='button' id='btnPrint' value='Print' onclick='Print_Preview();' $style title='Print' 

	if($mainmode=='')
		echo ' disabled';
	echo">&nbsp;";
	*/
	
	echo "<input name='btnLoad' type='button' id='btnLoad' value='Load' onclick='LoadDelivery();' $style title='Load' ";

//	if($mainmode=='')
	//	echo ' disabled';
	echo">";
	
	echo"</td></tr></table>";
	

	echo"<tr><td colspan='8'><table width=100% border='0'>
	<col width=400>
	<col width=180>
	<col width=180>	
	";

		  
	echo"<tr bgcolor='#F7F7F7'><td><span class='style27'>Client</span></td><td bgcolor='#F7F7F7'><span class='style27'>Destination</span></td><td bgcolor='#F7F7F7'><span class='style27'>Amount</td>
	<td bgcolor='#F7F7F7'><span class='style27'>Visit Order</td></tr>";	
		  
	$query_dt="select shipmentdt_id,client_code,client_address,sale_reference,delivery_reference,ledger_name,shipment_amount,area_name,shipmentsdt.area_code,visitnumber from shipmentsdt 
				left join clients on clients.ledger_number=shipmentsdt.client_code
				left join area on area.area_code=shipmentsdt.area_code
				where shipment_id='".$shipment_id."'
				order by  visitnumber asc,client_code";
	//echo$query_dt;		
	$resultdt=mysql_query($query_dt,$connection) or die(mysql_error());
	$i=1;
			while($rowsdt=mysql_fetch_array($resultdt)){
			
			    $area_code='area_code'.$i;
				$$area_code=$rowsdt[8];
				
				$area_name='area_name'.$i;
				$$area_name=$rowsdt[7];
		
				$amount='amount'.$i;
				$$amount=$rowsdt[6];
				
				$visitorder='visitorder'.$i;
				$$visitorder=$rowsdt[9];
				
				$ct+=1;

				if($ct%2==0)
					$Color="style='background-color:".$grid_color1."'";
				else			
					$Color="style='background-color:".$grid_color2."'";	
						
				if($clientcode!=$rowsdt[1]){
					echo "</td></tr>
					<tr ".$Color." >
					<td align='left' bgcolor='#F7F7F7'><span class='style15'>$rowsdt[5] - $rowsdt[1]</span></td>
					
					<td bgcolor='#F7F7F7'><span class='style15'><input type='hidden' name='$area_code' value='".$$area_code."'>
					<input type='text' name='$area_name' value='".$$area_name."'>
					";
			echo"&nbsp;<label><img src='img/btnopen.jpg' title=' Select License ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onClick='showlistareas($i,$rowsdt[9]); ' /></label>";

					
					echo"</span></td>
					<td bgcolor='#F7F7F7'><span class='style15'><input type='text' name='$amount' value='".$$amount."' style='text-align:right;'>
					</td>
					<td bgcolor='#F7F7F7'><span class='style15'><input type='text' name='$visitorder' value='".$$visitorder."' size='5' style='text-align:right;'></td></tr>";
					//echo "<tr bgcolor='#F7F7F7' ><td  align='left'><span class='style27'>Address</span></td><td align='left' colspan='7'><span class='style15'>$rowsdt[2]</td></tr>";
			
				}
				
				
				//echo"<span class='style15'>$rowsdt[3] / $rowsdt[4] &nbsp;</span>";
			
				$clientcode=$rowsdt[1];
				$i=$i+1;
			}
	
	echo"</table></td></tr>";
			

	echo"</td></tr></table>";	
	
	
if($showprint=='1'){

		echo'<script type="text/javascript" language="javascript">Print_Preview();';
		echo"</script>";
} 
	
	
print <<<HERE
</form>
</body>
</html>
HERE;


?>