<?php
include 'header.php';
include "connect.php";
?>

<div class="row" >
	<div class="col-sm-12"><button class="btn btn-blue btn-block">Restore</button></div>
	<div class="col-sm-12">&nbsp</div>
	<div class="col-sm-12">		
		
		<form class="form-inline" method="post" enctype="multipart/form-data">
			<div class="form-group">
				<label for="sd">Select File:</label>
				<input type="file" name="file" id="file">
			</div><br><br>
			<button type="submit" name="submit" id="submit" class="btn btn-info">Restore</button>
		</form>
		</div>
		<?php
		if(isset($_POST['submit']))
		{
			$filename = $_FILES["file"]["name"];
			//echo "$filename";
			

			$templine = '';
			//$lines = file('backup/'.$filename);
			$lines = file('\\\192.168.0.3\Backup\Scanner/'.$filename);	
			foreach ($lines as $line)
			{
				if (substr($line, 0, 2) == '--' || $line == '')
					continue;
				
				$templine .= $line;

				if (substr(trim($line), -1, 1) == ';')
				{
					//mysqli_query($con,$templine) or print('Error performing query \'<strong>' . $templine . '\': ' . mysql_error() . '<br /><br />');
					mysqli_query($con,$templine);
					$templine = '';
				}
			}
			 echo '<div class="alert alert-success alert-dismissible">
    <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
    <strong>Success!</strong> Data Restore Successfuly.
  </div>';
		}
		?>
</div>
</div>
</div>
</div>
		
<?php
include 'footer.php';
?>