<?php
session_start();

use PHPMailer\PHPMailer\PHPMailer;


 
 $ids = $_GET['id'];
 

if(isset($_SESSION['uid'])){
 

 
  include '../../config/database.php';
  include '../../config/config.php';
  include 'header.php';


  $msg = "";

}
else{

    header("location:../pages/login.php");
}







if(isset($_POST['set'])){

 $pname = $_POST['pname'];
   $shipdate = $_POST['shipdate'];
   $saddress = $_POST['saddress'];
   $sname = $_POST['sname'];
   $raddress = $_POST['raddress'];
   $rname = $_POST['rname'];
   $email = $_POST['email'];
   $status = $_POST['status'];
   $location = $_POST['location'];
   $pdate = $_POST['pdate'];
 $pid = $_POST['pid'];
  $ids = $_GET['id'];
  
    



   $sql = "UPDATE history SET  pname = '$pname',shipdate = '$shipdate',saddress = '$saddress',sname = '$sname' ,raddress = '$raddress',rname = '$rname',email = '$email', status = '$status',location = '$location', pdate = '$pdate' ,pid = '$pid' WHERE id = '$ids'";
   
   if(mysqli_query($link, $sql)){
      

 //send email


require_once "PHPMailer/PHPMailer.php";
require_once 'PHPMailer/Exception.php';


//PHPMailer Object
$mail = new PHPMailer;

//From email address and name
$mail->From = $emaila;
$mail->FromName = $name;

//To address and name
$mail->addAddress($email);
$mail->addAddress("$email"); //Recipient name is optional

//Address to which recipient will reply

//Send HTML or Plain Text email
$mail->isHTML(true);

$mail->Subject = "Shipment Receipt";

$mail->Body = '



  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>


<div style="background: #f5f7f8;width: 100%;height: 100%; font-family: sans-serif; font-weight: 100;" class="be_container"> 

<div style="background:#fff;max-width: 600px;margin: 0px auto;padding: 30px;"class="be_inner_containr"> <div class="be_header">

<div class="be_logo"> <img src="https://proexpressshippings.com/assets/img/logo/logo-one.png" alt="" width="200" height="100" style="display: block;"/> </div>

<div class="be_user"> <p>Dear: '.$sname.' - Tracking ID: ' .$pid.'</p> </div> 


<div style="clear: both;"></div> 

<div class="be_bluebar" style="background: #1976d2; padding: 20px; color: #fff;margin-top: 10px;">

<h1>Shipment Receipt</h1>

</div> </div> 

<div class="be_body" style="padding: 20px;"> 
<p style="line-height: 25px;"> 




<div class="container">
  
             
  <table class="table table-condensed" >
  <tbody>
         <tr>
        <td>Package Name</td>
         <td>'.$pname.'</td></tr>
        
        <tr>
        <td>Shipment Date</td>
        <td>'.$shipdate .'</td></tr>
        
        <tr>
        <td>Service Type</td>
        <td>'.$servicetype.'</td>
      </tr>
      
      
       <tr>
        <td>Sender Address</td>
        <td>'. $saddress.'</td>
        </tr>
        
        <tr>
        <td>Sender Name</td>
         <td>'.$sname.'</td>
        </tr>
        
        <tr>
        <td>Date</td>
      <td>'.$pdate.'</td>
      </tr>
           
      
      <tr>
        <td>Receiver Address</td>
        <td>'. $raddress.'</td>
        </tr>
        
        <tr>
        <td>Receiver Name</td>
        <td>'.$rname.'</td>
        </tr>
        
        <tr>
        <td>Package Status</td>
       <td>'.$status.'</td>
            </tr>
      
      <tr>
             <td>Location</td>
        <td>'. $location.'</td>
        </tr>
        
        
        <tr>
        <td>Tracking ID</td>
        <td>'.$pid.'</td>
        </tr>
        
        
        <tr>
        <td>Remark</td>
      <td>'.$remark.'</td>
      </tr>
            
      
      
      
      
      
body {
   /* just for this demo. */
   
   padding: 50px;
   padding-top: 0px;
}

.btn {
   /* just for this demo. */
   
   margin-top: 5px;
}

.btn-arrow-right,
.btn-arrow-left {
   position: relative;
   padding-left: 18px;
   padding-right: 18px;
}

.btn-arrow-right {
   padding-left: 36px;
}

.btn-arrow-left {
   padding-right: 36px;
}

.btn-arrow-right:before,
.btn-arrow-right:after,
.btn-arrow-left:before,
.btn-arrow-left:after {
  
   content: "";
   position: absolute;
   top: 5px;
  
   
   width: 22px;
  
   
   height: 22px;
  
   
   background: inherit;
 
   
   border: inherit;
  
   
   border-left-color: transparent;

   border-bottom-color: transparent;
 
   
   border-radius: 0px 4px 0px 0px;
 
   -webkit-border-radius: 0px 4px 0px 0px;
   -moz-border-radius: 0px 4px 0px 0px;
}

.btn-arrow-right:before,
.btn-arrow-right:after {
   transform: rotate(45deg);

   
   -webkit-transform: rotate(45deg);
   -moz-transform: rotate(45deg);
   -o-transform: rotate(45deg);
   -ms-transform: rotate(45deg);
}

.btn-arrow-left:before,
.btn-arrow-left:after {
   transform: rotate(225deg);
   
   
   -webkit-transform: rotate(225deg);
   -moz-transform: rotate(225deg);
   -o-transform: rotate(225deg);
   -ms-transform: rotate(225deg);
}

.btn-arrow-right:before,
.btn-arrow-left:before {
   
   
   left: -11px;
}

.btn-arrow-right:after,
.btn-arrow-left:after {
  
   right: -11px;
}

.btn-arrow-right:after,
.btn-arrow-left:before {
  
   
   z-index: 1;
}

.btn-arrow-right:before,
.btn-arrow-left:after {
   
   
   background-color: white;
}

body{

background-color:
}
</style>
<div class="cantainer"  style="background-color:#4076c7;margin-left:1%;width:98%;">


      
      
      
      
           	<?php 
			
			$sql= "SELECT * FROM track WHERE pid = '$tid'";
			  $result = mysqli_query($link,$sql);
			  if(mysqli_num_rows($result) > 0){
				$row = mysqli_fetch_assoc($result); 
              
				$row['email'];
				if(isset($row['image'])){

					$image = $row['image'];
				}
				  
			  }
				  
				  ?>

<div class="container" align="center">

   <div align="center"><button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Package Image</button></div>
      
     
    </tbody>
  </table>
</div>


</p> <div style="margin-top: 25px;">

 </div> </div> 
 
 <div class="be_footer">
<div style="border-bottom: 1px solid #ccc;"></div> <p> 63C East Wall St. Anaheim, CA 92801 <br>
Copyright ©2023 '.$name.'. </p> </div> </div> </div>';
if($mail->send()) {
   
   $msg = "Package history updated successfuly!";
}
               
           else{
               $msg = "Email send error!";
            }
        

   
}


}
 
 








    ?>




  <!-- Main Content -->
      <div class="main-content">
        <section class="section">
          <div class="section-header">
            <h1><i class="fa fa-home " style="font-size:30px"></i> EDIT HISTORY</h1>
           
          
          </div>


        
   
 
          <hr></hr>
          
        
          
            <div class="box-header with-border">
            
            <?php if($msg != "") echo "<div style='padding:20px;background-color:#dce8f7;color:black'> $msg</div class='btn btn-success'>" ."</br></br>";  ?>
          </br>


 <?php 
 
 $sql= "SELECT * FROM history WHERE id='$ids'";
			  $result = mysqli_query($link,$sql);
			  if(mysqli_num_rows($result) > 0){
				 $row = mysqli_fetch_assoc($result); 
				  if(isset($row['id'])){
$id = $row['id'];				      
$pid = $row['pid'];					
 $pname = $row['pname'];
   $shipdate = $row['shipdate'];
   $saddress = $row['saddress'];
   $sname = $row['sname'];
   $raddress = $row['raddress'];
   $rname = $row['rname'];
   $email = $row['email'];
   $status = $row['status'];
   $location = $row['location'];
   $pdate = $row['pdate'];
   
					  
				  }else{
					}
?>

     <form class="form-horizontal" action="h-edit.php?id=<?php echo $id;?>" method="POST" enctype="multipart/form-data" >

           <legend>History Update</legend>
		   
		
        </div>
 <div class="form-group">
        <input type="text" name="pname"  value="<?php echo $pname;?>" readonly class="form-control">
        
        <input type="hidden" name="id"  value="<?php echo $id;?>" readonly class="form-control">
        </div>

     <div class="form-group">
        <input type="text" name="shipdate " readonly  value="<?php echo $shipdate;?>"  class="form-control">
        </div>

        <div class="form-group">
        <input type="text" name="saddress" readonly  value="<?php echo $saddress;?>" class="form-control">
        </div>
        
     <div class="form-group">
        <input type="text" name="sname"  readonly value="<?php echo $sname;?>"   class="form-control">
        </div>

        <div class="form-group">
        <input type="text" name="raddress " readonly value="<?php echo $raddress;?>"    class="form-control">
        </div>

        <div class="form-group">
        <input type="text" name="rname"  readonly value="<?php echo $rname;?>"  class="form-control">
        </div>
        
     <div class="form-group">
        <input type="text" name="email" readonly value="<?php echo $email;?>"   class="form-control">
        </div>

        <div class="form-group">
        <input type="text" name="status"   placeholder="status" class="form-control">
        </div>
        
     <div class="form-group">
        <input type="text" name="location" placeholder="location"  class="form-control">
        </div>

      <div class="form-group">
        <input type="text" name="pid" value="<?php echo $pid;?>" readonly class="form-control">
        </div>
        
     <div class="form-group">
        <input type="date" name="pdate" placeholder="history date"   class="form-control">
        </div>

       
     

      


    <button style="" type="submit" class="btn btn-success" name="set" > <i class="fa fa-send"></i>&nbsp; Edit history </button>

    </form>

<?php    
          
          }
?>


    </div>
   </div>

   </div>
  </div>
  </section>
</div>

