<?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");
$path="select manifest_path from setup";
$res = mysql_query($path,$connection);
if($rows = mysql_fetch_array($res)){
	$filepath=$rows[0];
}
$var = array();
$nb=array();
$file1=$_GET['file1'];
$fileall=$_GET['file1'];
$path=$filepath."/".$file1;
/*
if($file1=='Sndbofl1'){$field='Sndbofl1';}
if($file1=='Sndbofl3'){$field='Sndoftl3';}
if($file1=='Sndbofl4'){$field='Sndbofl4';}
//if($file1=='all'){$field1='Sndbofl4';}
$myfile = fopen("$filepath/Import/$file1.txt", "r") or die("Unable to open file!");




$j=0;
while(!feof($myfile)) {
	$q = "select fieldlength,fieldname1 from Sndbofl  where fieldfamily='$field' ";
	$res = mysql_query($q,$connection);
	$file=fgets($myfile);
	$i=0;

//print_R($var);
while($r = mysql_fetch_row($res)){
	
	
		
		
	$var[$r[1]] = $r[0];
	$nb[$r[1]] = $r[0];
	
	 $var[$r[1]]=trim(substr("$file",$i,$r[0]));
	 //$var[$r[1]]=substr("$file",$i,$r[0]);
	 //echo $file;
	// echo "from $i to $i+$r[0]" ;
	 $i=$i+$r[0];
	 


}
//print_R($var);
//echo "<br><br>";
$var[date]=formatdate($var[date]);
	$var[manifest_date]=$var[year]."-".$var[month]."-".$var[day]." ".$var[hour].":".$var[minutes].":".$var[seconds];
	//echo $var[manifest_date]."dateofmani";
	*/
	if(($file1=='Sndbofl1')||($fileall=='all')){
		
	if($fileall=='all'){$file1='Sndbofl1';}
	if($file1=='Sndbofl1'){$field='Sndbofl1';}
	if($file1=='Sndbofl3'){$field='Sndoftl3';}
	if($file1=='Sndbofl4'){$field='Sndbofl4';}
	if($file1=='Sndbofl2'){$field='Sndbofl2';}
	$myfile = fopen("$filepath/Import/$file1.txt", "r") or die("Unable to open file!");




$j=0;
while(!feof($myfile)) {
	$q = "select fieldlength,fieldname1 from Sndbofl  where fieldfamily='$field' ";
	$res = mysql_query($q,$connection);
	$file=fgets($myfile);
	$i=0;

//print_R($var);
while($r = mysql_fetch_row($res)){
	
	
		
		
	$var[$r[1]] = $r[0];
	$nb[$r[1]] = $r[0];
	
	 $var[$r[1]]=trim(substr("$file",$i,$r[0]));
	 //$var[$r[1]]=substr("$file",$i,$r[0]);
	 //echo $file;
	// echo "from $i to $i+$r[0]" ;
	 $i=$i+$r[0];
	 


}
//print_R($var);
//echo "<br><br>";
$var[date]=formatdate($var[date]);
	$var[manifest_date]=$var[year]."-".$var[month]."-".$var[day]." ".$var[hour].":".$var[minutes].":".$var[seconds];
	
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		$query="select count(*) from manifest where voyage_destination='$var[voyage_destination]' and Voyage_year='$var[Voyage_year]' and
		voyage_number='$var[voyage_number]' and 
  voyage_BOLnumber='$var[voyage_BOLnumber]' and  BOL_type='$var[BOL_type]' and BOL_pagenumber='$var[BOL_pagenumber]' and BOL_identification='$var[BOL_identification]'";
// echo $query;
$count=0;
 $res = mysql_query($query,$connection);
 if ($row=mysql_fetch_array($res)){
	$count=$row[0];
 }
 if ($count>0){break;}
 else 
 { 
$boolean="true";

 if(($voyage_destination!='')&&($var[voyage_destination]!=$voyage_destination)){$boolean="false";}
 if(($voyage_year!='')&&($var[Voyage_year]!=$voyage_year)){$boolean="false";}
 if(($voyage_number!='')&&($var[voyage_number]!=$voyage_number)){$boolean="false";}
 if(($bol_number!='')&&($var[voyage_BOLnumber]!=$bol_number)){$boolean="false";}
 if(($voyage_type!='')&&($var[BOL_type]!=$voyage_type)){$boolean="false";}
 if(($voyage_pagenumber!='')&&($var[BOL_pagenumber]!=$voyage_pagenumber)){$boolean="false";}
 
 
 
 
	
	 
	//echo $boolean;
	 if($boolean=="true"){
	// echo "<br><br>";
	 
	/* echo "if (($var[voyage_destination]==$voyage_destination)&&($var[Voyage_year]==$voyage_year)&&($var[voyage_number]==$voyage_number)
		 &&($var[voyage_BOLnumber]==$bol_number)&&($var[BOL_type]==$voyage_type)
	 &&($var[BOL_pagenumber]==$voyage_pagenumber)) ";*/
	// if (($var[voyage_destination]==$voyage_destination)&&($var[Voyage_year]==$voyage_year)&&($var[voyage_number]==$voyage_number)&&($var[voyage_BOLnumber]==$bol_number)&&($var[BOL_type]==$voyage_type)
	// &&($var[BOL_pagenumber]==$voyage_pagenumber)) echo "insert";*/
	// $var[tax1_amount]=str_pad($var[tax1_amount], $nb[tax1_amount],'0',STR_PAD_LEFT);
	$var[tax1_amount]=ltrim($var[tax1_amount], '0');if($var[tax1_amount]==''){$var[tax1_amount]=0;}
	$var[tax2_amount]=ltrim($var[tax2_amount], '0');if($var[tax2_amount]==''){$var[tax2_amount]=0;}
	$var[tax3_amount]=ltrim($var[tax3_amount], '0');if($var[tax3_amount]==''){$var[tax3_amount]=0;}
	$var[tax4_amount]=ltrim($var[tax4_amount], '0');if($var[tax4_amount]==''){$var[tax4_amount]=0;}
	$var[tax5_amount]=ltrim($var[tax5_amount], '0');if($var[tax5_amount]==''){$var[tax5_amount]=0;}
	$var[tax6_amount]=ltrim($var[tax6_amount], '0');if($var[tax6_amount]==''){$var[tax6_amount]=0;}
		
$select="insert into manifest ( voyage_destination,Voyage_year,voyage_number,manifest_date,
 Manifest_sysdate, voyage_BOLnumber, voyage_descripiton, BOL_type, BOL_pagenumber,
 vessel_id, BOL_identification, Shipper1, shipper2, shipper3, shipper4,
 consignee1, consignee2, consignee3, consignee4, 
 Notify1, Notify2, Notify3, Notify4, Agent_Id,
 Precarriage, PlaceofReceipt, Portofloading, PortofDischarge, Placeofdelivery, 
 stamp1_id, stamp2_id, stamp3_id, stamp4_id, stamp5_id, stamp6_id, 
 BOL_freight, issued, Negotiable_BOL, term_of_carriage, Freight_type,
 No_of_tues, currency, tax1_amount, tax2_amount, tax3_amount, tax4_amount, tax5_amount, tax6_amount, 
 
 tax1_desc, tax2_desc, tax3_desc, tax4_desc, tax5_desc, tax6_desc,
 evidence1, evidence2, evidence3, evidence4, evidence5, evidence6,
 Agent1_id, linear_meters, freetimedays, Offernumber, date,year, month, day, hour, minutes, seconds,source_agentcode,line_operator


) values('$var[voyage_destination]','$var[Voyage_year]','$var[voyage_number]','$var[manifest_date]',now(),'$var[voyage_BOLnumber]','$var[voyage_descripiton]','$var[BOL_type]',
'$var[BOL_pagenumber]','$var[vessel_id]'
,'$var[BOL_identification]','$var[Shipper1]','$var[shipper2]','$var[shipper3]','$var[shipper4]','$var[consignee1]','$var[consignee2]'
,'$var[consignee3]','$var[consignee4]','$var[Notify1]','$var[Notify2]','$var[Notify3]','$var[Notify4]','$var[Agent_Id]',
'$var[Precarriage]','$var[PlaceofReceipt]','$var[Portofloading]','$var[PortofDischarge]','$var[Placeofdelivery]','$var[stamp1_id]','$var[stamp2_id]',
'$var[stamp3_id]','$var[stamp4_id]','$var[stamp5_id]'
,'$var[stamp6_id]','$var[BOL_freight]','$var[issued]','$var[Negotiable_BOL]','$var[term_of_carriage]',
'$var[Freight_type]','$var[No_of_tues]','$var[currency]','$var[tax1_amount]','$var[tax2_amount]','$var[tax3_amount]','$var[tax4_amount]',
'$var[tax5_amount]','$var[tax6_amount]','$var[tax1_desc]','$var[tax2_desc]','$var[tax3_desc]','$var[tax4_desc]','$var[tax5_desc]'
,'$var[tax6_desc]'
,'$var[evidence1]'
,'$var[evidence2]','$var[evidence3]','$var[evidence4]','$var[evidence5]','$var[evidence6]','$var[Agent1_id]','$var[linear_meters]'
,'$var[freetimedays]'
,'$var[Offernumber]','$var[date]'
,'$var[year]'
,'$var[month]','$var[day]','$var[hour]','$var[minutes]','$var[seconds]','$var[source_agentcode]','$var[status1]'
)";
//echo $select."<br><br>";
//echo floatval($var[tax1_amount])."<br>";
$res = mysql_query($select,$connection);
	
 }
	
	
	
}

}
}


	if(($file1=='Sndbofl3')||($fileall=='all')){
	
		if($fileall=='all'){$file1='Sndbofl3';}
	if($file1=='Sndbofl1'){$field='Sndbofl1';}
	if($file1=='Sndbofl3'){$field='Sndoftl3';}
	if($file1=='Sndbofl4'){$field='Sndbofl4';}
	$myfile = fopen("$filepath/Import/$file1.txt", "r") or die("Unable to open file!");




$j=0;
while(!feof($myfile)) {
	$q = "select fieldlength,fieldname1 from Sndbofl  where fieldfamily='$field' ";
	$res = mysql_query($q,$connection);
	$file=fgets($myfile);
	$i=0;

//print_R($var);
while($r = mysql_fetch_row($res)){
	
	$manifest_auto='';
		
		
	$var[$r[1]] = $r[0];
	$nb[$r[1]] = $r[0];
	
	 $var[$r[1]]=trim(substr("$file",$i,$r[0]));
	 //$var[$r[1]]=substr("$file",$i,$r[0]);
	 //echo $file;
	// echo "from $i to $i+$r[0]" ;
	 $i=$i+$r[0];
	 


}
//print_R($var);
//echo "<br><br>";
$var[date]=formatdate($var[date]);
	$var[manifest_date]=$var[year]."-".$var[month]."-".$var[day]." ".$var[hour].":".$var[minutes].":".$var[seconds];
	
 
 //echo "<br><br>".$manifest_auto;
		
	//echo $file1."<br>";
	
	$boolean="true";
	 if(($voyage_destination!='')&&($var[voyage_destination]!=$voyage_destination)){$boolean="false";}
 if(($voyage_year!='')&&($var[Voyage_year]!=$voyage_year)){$boolean="false";}
 if(($voyage_number!='')&&($var[voyage_number]!=$voyage_number)){$boolean="false";}
 if(($bol_number!='')&&($var[voyage_BOLnumber]!=$bol_number)){$boolean="false";}
 if(($voyage_type!='')&&($var[BOL_type]!=$voyage_type)){$boolean="false";}
 if(($voyage_pagenumber!='')&&($var[BOL_pagenumber]!=$voyage_pagenumber)){$boolean="false";}
 
	//echo $boolean;
	 if($boolean=="true"){
		 
		 
		 
		$querymanifest="select manifest_auto from manifest where voyage_destination='$var[voyage_destination]' and Voyage_year='$var[Voyage_year]' and
		voyage_number='$var[voyage_number]' and 
  voyage_BOLnumber='$var[voyage_BOLnumber]' and  BOL_type='$var[BOL_type]' and BOL_pagenumber='$var[BOL_pagenumber]' and BOL_identification='$var[BOL_identification]'";
 //echo "<br><br>".$querymanifest."<br><br>";
//$count=0;
 $resmanifest = mysql_query($querymanifest,$connection);
 if($rowmanifest=mysql_fetch_array($resmanifest)){
	 $manifest_auto=$rowmanifest[0];
 }
 if($manifest_auto!='')
 {	 

	
		$query="select count(*) from manifestdt where voyage_destination='$var[voyage_destination]' and Voyage_year='$var[Voyage_year]' and
		voyage_number='$var[voyage_number]' and 
  voyage_BOLnumber='$var[voyage_BOLnumber]' and  BOL_type='$var[BOL_type]' and BOL_pagenumber='$var[BOL_pagenumber]' and BOL_identification='$var[BOL_identification]'";
// echo $query;
$count=0;
 $res = mysql_query($query,$connection);
 if ($row=mysql_fetch_array($res)){
	$count=$row[0];
 }
 if ($count>0){break;}
 else{


	$query="
	insert into manifestdt ( Manifest_date, Manifest_sysdate, client_code, Voyage_year, 
	voyage_number, voyage_destination, voyage_BOLnumber, voyage_descripiton, BOL_type, 
	BOL_pagenumber, vessel_id, BOL_identification, detailsequence, CTRFlag, Container, Marks, Packages,
	Container_Weight, CubeMeters, Agent1, year, 
	month, day, hour, minutes, seconds,manifest_manifestauto,source_agentcode)values('$var[manifest_date]',now(),'$var[client_code]','$var[Voyage_year]'
	
	,'$var[voyage_number]','$var[voyage_destination]','$var[voyage_BOLnumber]','$var[voyage_descripiton]'
	,'$var[BOL_type]','$var[BOL_pagenumber]','$var[vessel_id]','$var[BOL_identification]'
	,'$var[detailsequence]','$var[CTRFlag]','$var[Container]','$var[Marks]','$var[Packages]'
	,'$var[Container_Weight]','$var[CubeMeters]','$var[Agent1]','$var[year]'
	,'$var[month]'
	,'$var[day]','$var[hour]','$var[minutes]','$var[seconds]','$manifest_auto','$var[source_agentcode]'
	)
	";
	//echo $query."<br><br>";
//echo floatval($var[tax1_amount])."<br>";
$res = mysql_query($query,$connection);
	
 }}
	}
}
	
	}
	//echo $file1."<br>";
//echo "Sndbofl4";
	//else 
		if(($file1=='Sndbofl4')||($fileall=='all')){
			
			
			if($fileall=='all'){$file1='Sndbofl4';}
	if($file1=='Sndbofl1'){$field='Sndbofl1';}
	if($file1=='Sndbofl3'){$field='Sndoftl3';}
	if($file1=='Sndbofl4'){$field='Sndbofl4';}
	$myfile = fopen("$filepath/Import/$file1.txt", "r") or die("Unable to open file!");




$j=0;
while(!feof($myfile)) {
	$q = "select fieldlength,fieldname1 from Sndbofl  where fieldfamily='$field' ";
	$res = mysql_query($q,$connection);
	$file=fgets($myfile);
	$i=0;

//print_R($var);
while($r = mysql_fetch_row($res)){
	$manifest_auto='';
	
		
		
	$var[$r[1]] = $r[0];
	$nb[$r[1]] = $r[0];
	
	 $var[$r[1]]=trim(substr("$file",$i,$r[0]));
	 //$var[$r[1]]=substr("$file",$i,$r[0]);
	 //echo $file;
	// echo "from $i to $i+$r[0]" ;
	 $i=$i+$r[0];
	 


}
//print_R($var);
//echo "<br><br>";
$var[date]=formatdate($var[date]);
	$var[manifest_date]=$var[year]."-".$var[month]."-".$var[day]." ".$var[hour].":".$var[minutes].":".$var[seconds];
	
		
			
			
			
			
			
			
			
			
			
			$boolean="true";
	  if(($voyage_destination!='')&&($var[voyage_destination]!=$voyage_destination)){$boolean="false";}
 if(($voyage_year!='')&&($var[Voyage_year]!=$voyage_year)){$boolean="false";}
 if(($voyage_number!='')&&($var[voyage_number]!=$voyage_number)){$boolean="false";}
 if(($bol_number!='')&&($var[voyage_BOLnumber]!=$bol_number)){$boolean="false";}
 if(($voyage_type!='')&&($var[BOL_type]!=$voyage_type)){$boolean="false";}
 if(($voyage_pagenumber!='')&&($var[BOL_pagenumber]!=$voyage_pagenumber)){$boolean="false";}
 
	//echo $boolean;
	 if($boolean=="true"){
		
			
			$querymanifest="select manifest_auto from manifest where voyage_destination='$var[voyage_destination]' and Voyage_year='$var[Voyage_year]' and
		voyage_number='$var[voyage_number]' and 
  voyage_BOLnumber='$var[voyage_BOLnumber]' and  BOL_type='$var[BOL_type]' and BOL_pagenumber='$var[BOL_pagenumber]'";
 //echo "<br><br>".$querymanifest."<br><br>";
//$count=0;
 $resmanifest = mysql_query($querymanifest,$connection);
 if($rowmanifest=mysql_fetch_array($resmanifest)){
	 $manifest_auto=$rowmanifest[0];
 }
 
		if($manifest_auto!='')
 {	 
	
	$query="select count(*) from manifestdesc where voyage_destination='$var[voyage_destination]' and Voyage_year='$var[Voyage_year]' and
		voyage_number='$var[voyage_number]' and 
  voyage_BOLnumber='$var[voyage_BOLnumber]' and  BOL_type='$var[BOL_type]' and BOL_pagenumber='$var[BOL_pagenumber]' and BOL_identification='$var[BOL_identification]'";
// echo $query;
$count=0;
 $res = mysql_query($query,$connection);
 if ($row=mysql_fetch_array($res)){
	$count=$row[0];
 }
 if ($count>0){break;}
 else{
	
		
	$query="
	insert into manifestdesc ( Manifest_date, Manifest_sysdate, client_code, Voyage_year,
	voyage_number, voyage_destination, voyage_BOLnumber, voyage_descripiton, BOL_type, BOL_pagenumber, vessel_id,
	BOL_identification, detailsequence, 
	descriptiongood, Agent1, year, month, day, hour,
	minutes, seconds,manifest_manifestauto,source_agentcode)values('$var[manifest_date]',now(),'$var[client_code]','$var[Voyage_year]'
	
	,'$var[voyage_number]','$var[voyage_destination]','$var[voyage_BOLnumber]','$var[voyage_descripiton]'
	,'$var[BOL_type]','$var[BOL_pagenumber]','$var[vessel_id]','$var[BOL_identification]'
	,'$var[detailsequence]','$var[descriptiongood]','$var[Agent1]','$var[year]'
	,'$var[month]'
	,'$var[day]','$var[hour]','$var[minutes]','$var[seconds]','$manifest_auto','$var[source_agentcode]'
	)
	";
 
	//echo $file1;
	//echo $query."<br><br>";
//echo floatval($var[tax1_amount])."<br>";
$res = mysql_query($query,$connection);
 }}
	
	}
	
}
}



if(($file1=='Sndbofl2')||($fileall=='all')){
			
			
			if($fileall=='all'){$file1='Sndbofl2';}
	if($file1=='Sndbofl1'){$field='Sndbofl1';}
	if($file1=='Sndbofl3'){$field='Sndoftl3';}
	if($file1=='Sndbofl4'){$field='Sndbofl4';}
	if($file1=='Sndbofl2'){$field='Sndbofl2';}
	$myfile = fopen("$filepath/Import/$file1.txt", "r") or die("Unable to open file!");




$j=0;
while(!feof($myfile)) {
	$q = "select fieldlength,fieldname1 from Sndbofl  where fieldfamily='$field' ";
	$res = mysql_query($q,$connection);
	$file=fgets($myfile);
	$i=0;

//print_R($var);
while($r = mysql_fetch_row($res)){
	$manifest_auto='';
	
		
		
	$var[$r[1]] = $r[0];
	$nb[$r[1]] = $r[0];
	
	 $var[$r[1]]=trim(substr("$file",$i,$r[0]));
	 //$var[$r[1]]=substr("$file",$i,$r[0]);
	 //echo $file;
	// echo "from $i to $i+$r[0]" ;
	 $i=$i+$r[0];
	 


}
//print_R($var);
//echo "<br><br>";
//$var[date]=formatdate($var[date]);
	//$var[manifest_date]=$var[year]."-".$var[month]."-".$var[day]." ".$var[hour].":".$var[minutes].":".$var[seconds];
	
		
			
			
			
			
			
			
			
			
			
			$boolean="true";
	  if(($voyage_destination!='')&&($var[voyage_destination]!=$voyage_destination)){$boolean="false";}
 if(($voyage_year!='')&&($var[Voyage_year]!=$voyage_year)){$boolean="false";}
 if(($voyage_number!='')&&($var[voyage_number]!=$voyage_number)){$boolean="false";}
 if(($bol_number!='')&&($var[voyage_BOLnumber]!=$bol_number)){$boolean="false";}
 if(($voyage_type!='')&&($var[BOL_type]!=$voyage_type)){$boolean="false";}
 if(($voyage_pagenumber!='')&&($var[BOL_pagenumber]!=$voyage_pagenumber)){$boolean="false";}
 
	//echo $boolean;
	 if($boolean=="true"){
		
			
			$querymanifest="select manifest_auto,stampdescstatus from manifest where voyage_destination='$var[voyage_destination]' and Voyage_year='$var[Voyage_year]' and
		voyage_number='$var[voyage_number]' and 
  voyage_BOLnumber='$var[voyage_BOLnumber]' and  BOL_type='$var[BOL_type]' and BOL_pagenumber='$var[BOL_pagenumber]'";
 //echo "<br><br>".$querymanifest."<br><br>";
//$count=0;
 $resmanifest = mysql_query($querymanifest,$connection);
 if($rowmanifest=mysql_fetch_array($resmanifest)){
	 $manifest_auto=$rowmanifest[0];
	 $stampdescstatus=$rowmanifest[1];
 }
 		if($manifest_auto!='')
 {	


		
		if($stampdescstatus){
			
			
			$query="select count(*) from manifeststamp where voyage_destination='$var[voyage_destination]' and Voyage_year='$var[Voyage_year]' and
		voyage_number='$var[voyage_number]' and 
  voyage_BOLnumber='$var[voyage_BOLnumber]' and  BOL_type='$var[BOL_type]' and BOL_pagenumber='$var[BOL_pagenumber]' ";
// echo $query;
$count=0;
 $res = mysql_query($query,$connection);
 if ($row=mysql_fetch_array($res)){
	$count=$row[0];
 }
 if ($count>0){break;}
 else{
			
		$var[stampdesc1]= ereg_replace("'", "\'", $var[stampdesc1]);
		$var[stampdesc2]= ereg_replace("'", "\'", $var[stampdesc2]);
		$var[stampdesc3]= ereg_replace("'", "\'", $var[stampdesc3]);
		$var[stampdesc4]= ereg_replace("'", "\'", $var[stampdesc4]);
		$var[stampdesc5]= ereg_replace("'", "\'", $var[stampdesc5]);
		$var[stampdesc6]= ereg_replace("'", "\'", $var[stampdesc6]);
		$var[stampdesc7]= ereg_replace("'", "\'", $var[stampdesc7]);
		$var[stampdesc8]= ereg_replace("'", "\'", $var[stampdesc8]);
		$var[stampdesc9]= ereg_replace("'", "\'", $var[stampdesc9]);
		$var[stampdesc10]= ereg_replace("'", "\'", $var[stampdesc10]);
		$var[stampdesc11]= ereg_replace("'", "\'", $var[stampdesc11]);
		$var[stampdesc12]= ereg_replace("'", "\'", $var[stampdesc12]);
		$var[stampdesc13]= ereg_replace("'", "\'", $var[stampdesc13]);
		$var[stampdesc14]= ereg_replace("'", "\'", $var[stampdesc14]);
		$var[stampdesc15]= ereg_replace("'", "\'", $var[stampdesc15]);
		$var[stampdesc16]= ereg_replace("'", "\'", $var[stampdesc16]);
		$var[stampdesc17]= ereg_replace("'", "\'", $var[stampdesc17]);
		$var[stampdesc18]= ereg_replace("'", "\'", $var[stampdesc18]);
		$var[stampdesc19]= ereg_replace("'", "\'", $var[stampdesc19]);
		$var[stampdesc20]= ereg_replace("'", "\'", $var[stampdesc20]);
		$var[stampdesc21]= ereg_replace("'", "\'", $var[stampdesc21]);
		$var[stampdesc22]= ereg_replace("'", "\'", $var[stampdesc22]);
		
	$query="
	insert into manifeststamp (  Voyage_year,
	voyage_number, voyage_destination, voyage_BOLnumber, BOL_type, BOL_pagenumber,
	source_agentcode,
	 stampdesc1, stampdesc2, stampdesc3, stampdesc4, stampdesc5, stampdesc6, stampdesc7, stampdesc8, stampdesc9, stampdesc10, stampdesc11,
 stampdesc12, stampdesc13, stampdesc14, stampdesc15, stampdesc16, stampdesc17, stampdesc18, stampdesc19, stampdesc20, stampdesc21, stampdesc22,
  stampcode1, stampcode2, stampcode3, stampcode4, stampcode5, stampcode6,

	year, month, day, hour,
	minutes, seconds,manifest_manifestauto)values('$var[Voyage_year]'
	
	,'$var[voyage_number]','$var[voyage_destination]','$var[voyage_BOLnumber]'
	,'$var[BOL_type]','$var[BOL_pagenumber]','$var[source_agentcode]',
	
	'$var[stampdesc1]',
	'$var[stampdesc2]',
	'$var[stampdesc3]',
	'$var[stampdesc4]',
	'$var[stampdesc5]',
	'$var[stampdesc6]',
	'$var[stampdesc7]',
	'$var[stampdesc8]',
	'$var[stampdesc9]',
	'$var[stampdesc10]',
	'$var[stampdesc11]',
	'$var[stampdesc12]',
	'$var[stampdesc13]',
	'$var[stampdesc14]',
	'$var[stampdesc15]',
	'$var[stampdesc16]',
	'$var[stampdesc17]',
	'$var[stampdesc18]',
	'$var[stampdesc19]',
	'$var[stampdesc20]',
	'$var[stampdesc21]',
	'$var[stampdesc22]',
	'$var[stampcode1]',
	'$var[stampcode2]',
	'$var[stampcode3]',
	'$var[stampcode4]',
	'$var[stampcode5]',
	'$var[stampcode6]',
	'$var[year]'
	,'$var[month]'
	,'$var[day]','$var[hour]','$var[minutes]','$var[seconds]','$manifest_auto'
	)
	";
	//echo $file1;
	echo $query."<br><br>";
//	exit;
//echo floatval($var[tax1_amount])."<br>";
$res = mysql_query($query,$connection);
		}}
	 }
	}
	
}
}


function formatdate($dateval){
	if($dateval != ''){
	$ndate = explode("/", $dateval);
	$dateval = $ndate[2]."-".$ndate[1]."-".$ndate[0];
}
	return $dateval;
}
header('Location: ' . $_SERVER['HTTP_REFERER']);
?>