<?php
include("includes/connect.php");
$oid=$_REQUEST['oid'];
if(isset($_POST['submit']))
{
	$oid= mysqli_real_escape_string($con,$_POST['order_id']);
	$filename=$_FILES['file']['name'];
	$destination='invoice/' . $filename;
	$extension = pathinfo($filename, PATHINFO_EXTENSION);
	$file = $_FILES['file']['tmp_name'];
	$size = $_FILES['file']['size'];

	if(!in_array($extension, ['pdf']))
	{
		echo "Invalid File type";
	}
	elseif($_FILES['file']['size']>2000000)
	{
		echo "File too large";
	}
	else
	{
		if(move_uploaded_file($file,$destination))
		{
			echo $sql="insert into tbl_invoice (order_id, invoice) values ('".$oid."','".$filename."')";
			if(mysqli_query($con,$sql))
			{
				echo "File uploaded successfully";
       header("Location:users.php");
			}
		}
		else
		{
			echo "Failed to upload file";
      header("Location:users.php");
		}
	}
}
?>


<!DOCTYPE html>
<html lang="en">
  <head>
   <meta name="description" content="Vali is a responsive and free admin theme built with Bootstrap 4, SASS and PUG.js. It's fully customizable and modular.">
    <!-- Twitter meta-->
   <meta property="twitter:card" content="summary_large_image">
    <meta property="twitter:site" content="@pratikborsadiya">
    <meta property="twitter:creator" content="@pratikborsadiya">
    <!-- Open Graph Meta-->
    <meta property="og:type" content="website">
    <meta property="og:site_name" content="Vali Admin">
    <meta property="og:title" content="Vali - Free Bootstrap 4 admin theme">
    <meta property="og:url" content="http://pratikborsadiya.in/blog/vali-admin">
    <meta property="og:image" content="http://pratikborsadiya.in/blog/vali-admin/hero-social.png">
    <meta property="og:description" content="Vali is a responsive and free admin theme built with Bootstrap 4, SASS and PUG.js. It's fully customizable and modular.">
    <title>Asianet Admin</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- Main CSS-->
    <link rel="stylesheet" type="text/css" href="css/main.css">
    <!-- Font-icon css-->
    <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
	<style>
		@media print {
  #printPageButton {
    display: none;
  }
}
</style>
  </head>
  <body class="app sidebar-mini">
    <!-- Navbar-->
    <header class="app-header"><a class="app-header__logo" href="index.html"><img src="images/asianetweb.png" height="50px"></a>
    <!-- Sidebar toggle button--><a class="app-sidebar__toggle" href="#" data-toggle="sidebar" aria-label="Hide Sidebar"></a>
    <!-- Navbar Right Menu-->
    <ul class="app-nav">
     
    <!-- User Menu-->
    <li class="dropdown"><a class="app-nav__item" href="#" data-toggle="dropdown" aria-label="Open Profile Menu"><i class="fa fa-user fa-lg"></i></a>
    <ul class="dropdown-menu settings-menu dropdown-menu-right">
      <li><a class="dropdown-item" href="page-user.html"><i class="fa fa-cog fa-lg"></i> Settings</a></li>
      <li><a class="dropdown-item" href="page-user.html"><i class="fa fa-user fa-lg"></i> Profile</a></li>
      <li><a class="dropdown-item" href="page-login.html"><i class="fa fa-sign-out fa-lg"></i> Logout</a></li>
    </ul>
  </li>
</ul>
</header>
<!-- Sidebar menu-->
<div class="app-sidebar__overlay" data-toggle="sidebar"></div>
	   <?php include 'includes/side_bar.php';?>

<main class="app-content">

 
     <form action="" method="post" enctype="multipart/form-data">
		 <h2>Upload Invoice</h2>
		 <div class="form-group">
			<input type="file" name="file" value="" class="form-control"  accept="application/pdf"/>
		 </div>
		 <input type="hidden" name="order_id" value="<?php echo $oid;?>"/>
		 <div class="form-group">
			 <input type="submit" name="submit" value="Submit" class="btn btn-primary"/>
		 </div>
	 </form>
      
    

</main>
<!-- Essential javascripts for application to work-->
<script src="js/jquery-3.3.1.min.js"></script>
<script src="js/popper.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/main.js"></script>
<!-- The javascript plugin to display page loading on top-->
<script src="js/plugins/pace.min.js"></script>
<!-- Page specific javascripts-->
<!-- Google analytics script-->
<script type="text/javascript">
if(document.location.hostname == 'pratikborsadiya.in') {
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  ga('create', 'UA-72504830-1', 'auto');
  ga('send', 'pageview');
}
</script>
</body>
</html>