<?session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
include("../opendb.php");
//print sizeof($a);

if(isset($_POST[upd]))
{
$ff=$_REQUEST['ff'];
if($ff !="none")
{
$fl=$_FILES['ff']['name'];

   $file_dir=".";
  $tmp_name=$_FILES['ff']['tmp_name'];

   move_uploaded_file($tmp_name,"txtfiles/".$fl) or die(' err:could not copy file'.$fl);
  print "File copied :".$fl;
 }
$fp=fopen("txtfiles/".$fl,"r") or die("Cant open file");

$i=1;
include("../opendb.php");
//mysqli_query($db,"delete from partmaster")or die('Err:'.mysqli_error($db));

$i=1;
while(!feof($fp))
{
 $line=fgets($fp,1024);
 $spline=explode("\t",$line);
//print_r($spline);
if(strlen($spline[0])>0 )
{
if($spline[14]<=0)
{
$spline[14]=0.00;
}
if($spline[15]<=0)
{
$spline[15]=0.00;
}
if($spline[16]<=0)
{
$spline[16]=0.00;
}
if($spline[18]<=0)
{
$spline[18]=0.00;
}
if($spline[19]<=0)
{
$spline[19]=0.00;
}
if($spline[20]<=0)
{
$spline[20]=0.00;
}
if($spline[21]<=0)
{
$spline[21]=0.00;
}
if($spline[22]<=0)
{
$spline[22]=0.00;
}
$spline[13]= trim(preg_replace('/\t+/', '',$spline[13]));
$spline[16]= trim(preg_replace('/\t+/', '',$spline[16]));
$sql="insert into partmaster(partcode,partname,group1,subgroup,model,reordlevel,active,block_pur,unit,tax_sales,staxtype,tax_pur,p_taxtype,cenvat,edu_cess,add_cess,acconmrp,location,hand_charge,minordlevel,maxordlevel,cost,cessonvat) values('".addslashes(trim($spline[0]))."','$spline[1]','$spline[2]','$spline[3]','$spline[4]','$spline[5]','$spline[6]','".$spline[7]. "','".$spline[8]."','".$spline[9]."','".$spline[10]."','".$spline[11]."','".$spline[12]."','".$spline[13]."','".trim($spline[14])."','".trim($spline[15])."','".$spline[16]."','".$spline[17]."','".$spline[18] ."','".$spline[19]."','".$spline[20]."','".$spline[21]."','".$spline[22]."')";

//print $i++.". ".$sql."<br>";
mysqli_query($db,$sql) or die('Insert Err:'.mysqli_error($db));
}
}
print "<script> alert('Done');</script>";
}

?>

<link rel="stylesheet" href="style.css" type="text/css" />
<style>
body,td{font-family:'arial narrow';letter-spacing:1;}
//etr{background-color:c1d799}
.mnu{margin-left:5}
</style>
<center>
<br><br><br><br><br><br>
<form action='<?print $PHP_SELF?>' method='post' ENCTYPE="multipart/form-data">
<table border=0 width=60% cellspacing=1 cellpadding=1 bgcolor='darkbrown'>
<tr><td align=center bgcolor=white>
<table >
<th colspan=2 bgColor=c1d799>Upload Part Master
<tr><td>File </td><td><input type=file name='ff'></td></tr>
<tr bgColor='lightsteelblue'><td align=center colspan=2 ><input type=submit value='Upload' name='upd'></td></tr>
</table>
</td></tr>
</table>
</form>