<?php
session_start();
require'Database.php';
$database = new Database;
if(!$_SESSION['username']){
	header('Location: ../index.php');
	die();
}else{
$database->query("SELECT * FROM shipment");
$rows = $database->resultset();

?>	
<!DOCTYPE html>
<html lang="en">
  <?php include'head.php'; ?>
  <body class="app sidebar-mini rtl">
    <!-- Navbar-->
    <?php include'topnav.php'; ?>
    <!-- Sidebar menu-->
    <div class="app-sidebar__overlay" data-toggle="sidebar"></div>
    <?php include'nav.php'; ?>
    <main class="app-content">
      
        <div class="clearfix"></div>
        <div class="col-md-12">
          <div class="tile">
            <h3 class="tile-title">Update Shipment</h3>
            <div class="table-responsive">
              <form method="post" class="form">
              <div class="row">
                <div class="col-6">
                  
                </div>
                <div class="col-6">
                    
                    
                <form action="invest.php" method="post">
                    
    <select class="form-control" name="detail">
           <option disabled selected>-- Tracking Number --</option>
        <?php foreach($rows as $row) : ?>
 <?php ?>

      <option value="<?php echo $row['track_no'] ?>" ><?php echo $row['track_no'] ?></option>;
 
<?php endforeach; ?> 

</select><br>

<select name="email" class="form-control">
     <option disabled selected>-- Email --</option>
     <option value="<?php echo $row['email'] ?>" ><?php echo $row['email'] ?></option>;
                   
                  </select><br/>

        <input type="text" class="form-control" placeholder="Enter Current Location" name="status"><br><br>
        
      
        


                 <button class="btn btn" name="submit">Update Location</button>
                </tbody>
                  </form>
              
                </div>

              </div>
                  

            </div>
          </div>
          <?php
          include "../../ajax/connect.php";
    



            if(isset($_POST["submit"])){
                $confirm = $_POST["detail"];
                $status = $_POST["status"];
                $email = $_POST["email"];

                        $adduser = $conn->query("UPDATE shipment SET location='$status' WHERE track_no= '$confirm'");
        if($adduser){
			//Send Email
			$from = "support@Airsuitlogcompany.com";
			$to = "$email";
			$subject = " DELIVERY LOCATION UPDATED";
	   
			$headers = "From:" .$from . "\r\n";
			$headers .= "MIME-Version: 1.0" . "\r\n";
			$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
			$headers .= "<center><img src='https://Airsuitlogcompany.com/logo.png'/></center>" . "\r\n";
			$headers .= "<center><h3 style='color:#fffff;'>LOCATION UPDATE, $sender</h3></center>" . "\r\n";
			$headers .= "<center><h5 style='color:#8B0815;'>Your delivery Location has been updated !</h5></center>" . "\r\n";
			$headers .= "<center><h4 style='color:#fffff;'>The current Location is: $status</h4></center>" . "\r\n";
			
			$headers .= "<center><h5 style='color:#8B0815;'>kindly visit our website to track your delivery, for more information please contact our support team!</h5></center>" . "\r\n";
			
			$headers .= "<center><h5 style='color:#fffff;'>Thank you for choosing wideserviceintldelivery The Best delivery platform</h5></center>" . "\r\n";
  
  
			$headers .= "<center></center>" . "\r\n";
			
			
		  
			mail($to,$subject,$message,$headers);               
		}
 echo "<center><font color='red'><br><br><br>You have successful Updated the Shipment</br></font></center>";
                $sql = "";


            }

          ?>
        </div>
        </div>
    </main>

    <!-- Essential javascripts for application to work-->
    <script src="js/jquery-3.2.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>
<?php
}
?>