<?php $PageSecurity = 4;
global  $db;
include('includes/session.inc');
include('includes/SQL_CommonFunctions.inc');
include('includes/function_lib.php');
include('includes/stockcalculation.php');


if(isset($_REQUEST['impsave']))
{
	if($_FILES['imprt']['type']!='')
	{
		DB_query("TRUNCATE TABLE log_addmrnbox1",$db); 
		$infile=addslashes($_FILES['imprt']['tmp_name']);	

		$sql="LOAD DATA LOCAL INFILE '$infile' INTO TABLE `log_addmrnbox1` FIELDS TERMINATED BY ',' ENCLOSED BY '".'"'."' LINES TERMINATED BY '\r\n'   IGNORE 1 LINES;";
		DB_query($sql,$db);

		$qryin = "select package_no, no_of_package, content, layout, itemid, itemname from log_addmrnbox1";
		$qryinp = DB_query($qryin,$db);
		while($qryrow=DB_fetch_array($qryinp))
		{	
			$qryinc = "select id from log_addmrnbox where package_no='".$qryrow['package_no']."'";
			$qryinpc = DB_query($qryinc,$db);
			if(DB_num_rows($qryinpc)>0)
			{
				continue;
			}else{	
		
				$sql1 = "INSERT INTO log_addmrnbox (id, grn_id, package_no, no_of_package, content, layout, type, store, itemid, itemname) VALUES ('', '".$_REQUEST['grnid']."', '".$qryrow['package_no']."', '".$qryrow['no_of_package']."', '".htmlentities($qryrow['content'], ENT_QUOTES)."', '".$qryrow['layout']."', 1, '".$_REQUEST['store']."', '".$qryrow['itemid']."', '".$qryrow['itemname']."')";
				if(DB_query($sql1,$db)){$mm=1;}
			}
		}
		DB_query("TRUNCATE TABLE log_addmrnbox1",$db);
		if($mm==1){
		echo $msg="<br><font color='#009933' size='+1'>Boxes Details had been imported successfully.</font>";
		}else{
		echo $msg="<br><font color='#009933' size='+1'>Boxes Details had not been imported successfully.</font>";
		}
	}
	else
	$msg="<br><font color='red' size='+1'>Error: Invalid file type.</font>";
} 
?>
<table cellpadding="0" width="100%">
	<tr>
		<td valign="top" align="center">
		<form method="post" action="" enctype="multipart/form-data">
			<table width="50%" border="0" cellpadding="0" cellspacing="0" style="border:1px solid #000000;">
				<tr>
					<td colspan="2" align="center"><h2>Import Boxes for <?php echo $s->GetFieldValue('log_add_mrn','id="'.$_REQUEST['grnid'].'"','grn_no');?></h2><br></td>
				</tr>
				<tr>
					<td><strong>Import File</strong></td>
					<td><input type="file" name="imprt" id="imprt" /></td>
				</tr>
				<tr>
					<td colspan="2">&nbsp;</td>
				</tr>
				<tr>
					<td colspan="2" align="center"><input type="submit" name="impsave" value="Upload" /></td>
				</tr>
			</table>
		</form>
		</td>
	</tr>
</table>
