
<?php
session_start();

use PHPMailer\PHPMailer\PHPMailer;


if(isset($_SESSION['uid'])){
 
 
 $pid = $_GET['pid'];
  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'];
  $remark = $_POST['remark'];
  
  
    



   $sql = "INSERT INTO history (pname,shipdate,saddress,sname,raddress,rname,email,status,location,pdate,pid,remark) VALUES ('$pname','$shipdate','$saddress','$sname','$raddress','$rname','$email','$status','$location','$pdate','$pid','$remark')";
   
   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://carrierexpressdelivery.com/assets/img/logo/logo-one.png" alt="" width="200" height="100" style="display: block;"/> </div>



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

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

<h1>PACKAGE TRACKING DETAILS</h1>

</div> </div> 

<div class="be_body" style="padding: 20px;"> 






  <div class="be_user"> <h5>Dear '.$rname.', you are receiving this message due to a priority package scheduled for delivery to your location. <br> This email notification is to enable you track your package and to follow up on any required thing you need to do inorder to have your package delivered successfully.<br> The details below outlines your delivery informations</h5><br>
  
  
  <h3>Tracking ID: ' .$pid.'</h3> </div> 

           

         
         
        <div class="be_user"><h4>Package Name:'.$pname.'<br>
        
       
      
       Sender Address:'.$saddress.' <br>
        
        Sender Name:'.$sname.'<br>
        
        Date: '.$pdate.' <br>
           
         Receiver Name: '.$rname.'<br>
        
        Package Status:'.$status.' <br>
      
        Location:'. $location.'<br>
        
       Remark:'.$remark.'
       
      
       
      
      </h4></div>
      
      
      <div class="be_user"> <h5>Reply to us incase of any more clarifications needed or chat us up on our support chat through our chat box on the website page.</div>
      
         <div class="be_user"><center> <h3>Regards,<br>
      Prime Xpert Delivery Team. </h3><br>
      https://carrierexpressdelivery.com
      </center></div>
 <div class="be_footer">
<div style="border-bottom: 1px solid #ccc;"></div> <h5> 63C East Wall St. Anaheim, CA 92801 <br>
Copyright ©2023 '.$name.'. </h5> </div> </div> </div>';
if($mail->send()) {
   
   $msg = "New Package history has been added 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> New Package 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 pid='$pid'";
			  $result = mysqli_query($link,$sql);
			  if(mysqli_num_rows($result) > 0){
				 $row = mysqli_fetch_assoc($result); 
				  if(isset($row['pid'])){
				      
$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="history-edit.php?pid=<?php echo $pid;?>" method="POST" enctype="multipart/form-data" >

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

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

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

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

        <div class="form-group">
        <input type="hidden" 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="text" name="remark" placeholder="Remark" class="form-control">
        </div>
        
        
        
        
     <div class="form-group">
         <label>Date</label>
        <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; Add new history </button>

    </form>

<?php    
          
          }
?>


    </div>
   </div>

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

