<?
include_once('includes/top.php');
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
//$br=$_SESSION['branch'];
if(strlen($user)<=0)
{
  print "<script> alert('Invalid User'); document.location='inde.php' </script>";
  return;
}
include_once('opendb.php');
if(isset($_POST[upd]))
{
   $ff=$_POST['ff'];
   if($ff !="none")
   {
       $target_dir = "upld/";
       $target_file = $target_dir . basename($_FILES["ff"]["name"]);
       $uploadOk = 1;
       $fl=$_FILES['ff']['name'];
       //echo $fl;
       if (move_uploaded_file($_FILES["ff"]["tmp_name"], $target_file)) {
           echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
       } else {
           echo "Sorry, there was an error uploading your file.";
       }
       print "=> File copied :".$fl."<br>";
   }
   $fp=fopen($target_file,"r") or die("Cant open file");
   $i=1;
   $dt=date("Y-m-d H:i:s");
   $slno = 1;
   while(!feof($fp))
   {
      $line=fgets($fp,1024);
      $spline=explode("\t",$line);
      $item_code = trim($spline[0]); 
      $location  = trim($spline[1]);
      $mflg = 0;
      $msg = "";
      if(strlen($item_code)<= 0){
          $msg .= 'Blank Item Code....!';$mflg = 1;}
      if(strlen($location)<= 0){
          $msg .= 'Blank Location Name....!';$mflg = 1;}
      $group=mysqli_query($db,"select partcode from partmaster where partcode='$item_code'");
      if(mysqli_num_rows($group)<=0)
      {
          $msg .= 'Item Not Found....!';$mflg = 1;
      }
      if($mflg == 0)
      {
          $sql="update sparestock set location = '$location' where itemcode = '$item_code' and brcode = '$brcode'";
          mysqli_query($db,$sql) or die(mysqli_error($db));    
          print 'Successfully Updated : Line Item #'.$slno.$item_code.$location."<br>";
      }
      else
      {
          print 'Error on Line Item #'.$slno.$msg."<br>";
      }
      ++$slno;
   }
   print "<script> alert('Done');</script>";
}
?>
<link type="text/css" href="includes/style1.css" rel="stylesheet" />
<link type="text/css" href="css/form1.css" rel="stylesheet" />
<style>
tr{background-color:c1d799}
.mnu{margin-left:5}
</style>
<style>
.tooltip {
    position: relative;
    display: inline-block;
    border-bottom: 1px dotted black;
}

.tooltip .tooltiptext {
    visibility: hidden;
    width: 160px;
    background-color: red;
    color: white;
    text-align: center;
    border-radius: 6px;
    padding: 5px 0;

    /* Position the tooltip */
    position: absolute;
    z-index: 1;
}

.tooltip:hover .tooltiptext {
    visibility: visible;
}
</style>
<center>
<br><br><br><br><br><br>
<form action='upldlocation.php' method='post' ENCTYPE="multipart/form-data">
<table border=1>
<tr><td>
<table>
<th colspan=2>Upload Item Location Data
<tr><td>File <input type=file name='ff'></td><td><input type=submit value='Upload' name='upd'></td></tr>
<tr><td><div class="tooltip"><font size='1'><font face='Courier New'>Format for Uploading
  <span class="tooltiptext">|----1----|-----2----|<br>|ITEMCODE | LOCATION |</span>
</div>
</td></tr>
</table>
</td></tr>
</table>
</form>
