<?php include('../includes/connection.php');
@session_start();

if(!isset($_SESSION['admin_login'])) {
  header("Location: login.php");
  }

 include('header.php'); 

$msg = 0;

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

    $sender_name = str_replace("'", "\'", $_POST['sender_name']);
    $sender_address = str_replace("'", "\'", $_POST['sender_address']);
    $sender_phone = str_replace("'", "\'", $_POST['sender_phone']);
    $sender_email = str_replace("'", "\'", $_POST['sender_email']);
    $content_remark = str_replace("'", "\'", $_POST['content_remark']);
    // $usd = str_replace("'", "\'", $_POST['usd']);
    $content_information = str_replace("'", "\'", $_POST['content_information']);
    $country = str_replace("'", "\'", $_POST['country']);
    $state = str_replace("'", "\'", $_POST['state']);
    $city = str_replace("'", "\'", $_POST['city']);
    $postal = str_replace("'", "\'", $_POST['postal']);
    $destination = str_replace("'", "\'", $_POST['destination']);
    $recipient_name = str_replace("'", "\'", $_POST['recipient_name']);
    $recipient_address = str_replace("'", "\'", $_POST['recipient_address']);
    $recipient_phone = str_replace("'", "\'", $_POST['recipient_phone']);
    $recipient_identity = str_replace("'", "\'", $_POST['recipient_identity']);
    $recipient_email = str_replace("'", "\'", $_POST['recipient_email']);
    $shipping_number = str_replace("'", "\'", $_POST['shipping_number']);
    $posting_date = str_replace("'", "\'", $_POST['posting_date']);
    $shipping_date = str_replace("'", "\'", $_POST['shipping_date']);
    $estimate_date = str_replace("'", "\'", $_POST['estimate_date']);
    $status = str_replace("'", "\'", $_POST['status']);
    $status_remark = str_replace("'", "\'", $_POST['status_remark']);


    mysqli_query($DB_CONN,"INSERT INTO `shipping`(`sender_name`, `sender_address`, `sender_phone`, `sender_email`, `content_remark`, `content_information`, `country`, `state`, `city`, `postal`, `destination`, `recipient_name`, `recipient_address`, `recipient_phone`, `recipient_identity`, `recipient_email`, `shipping_number`, `posting_date`, `shipping_date`, `estimate_date`, `status`, `status_remark`) VALUES ('{$sender_name}','{$sender_address}','{$sender_phone}','{$sender_email}','{$content_remark}','{$content_information}','{$country}','{$state}','{$city}','{$postal}','{$destination}','{$recipient_name}','{$recipient_address}','{$recipient_phone}','{$recipient_identity}','{$recipient_email}','{$shipping_number}','{$posting_date}','{$shipping_date}','{$estimate_date}','{$status}','{$status_remark}')");
    
    
    $insertid = mysqli_insert_id($DB_CONN);
    
    mysqli_query($DB_CONN,"INSERT INTO `statuses`(`status`,`status_remark`, `date`,`destination`,`shipping_id`) VALUES ('{$status}','{$status_remark}','{$shipping_date}','{$destination}','{$insertid}')");
    

    $msg = 1;
    $msg_alert = '<br> <div class="alert alert-success alert-dismissible"> <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
      <strong> Success! </strong> Shipping Added Successfully </div>';
}



$n=10; 
function getName($n) { 
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; 
    $randomString = ''; 
  
    for ($i = 0; $i < $n; $i++) { 
        $index = rand(0, strlen($characters) - 1); 
        $randomString .= $characters[$index]; 
    } 
  
    return $randomString; 
} 
  
 
 ?>
      

<div id="content-wrapper">
    <div class="container-fluid">
          <!-- Breadcrumbs-->
          <ol class="breadcrumb">
            <li class="breadcrumb-item">
              <a href="#"> Dashboard </a>
            </li>
            <li class="breadcrumb-item active"> Shipping </li>
          </ol>

        <?php if ($msg=='1') {
              echo $msg_alert;
            } ?>

        <!-- DataTables Example -->
        <div class="card mb-3">
            <div class="card-header">
                <i class="fas fa-table"> </i> &nbsp;  Add Shipping
                <a href="view_shipping.php" class="btn btn-info btn-sm"  style="float: right;"> View Shipping </a>
            </div>

         

            <div class="card-body">
               <form method="POST" action="">
                  <div class="container">
                      <div class="row">
                         
                              <div class="col-md-6">
                                 <label> Sender Name  </label>
                                 <input type="text" name="sender_name" placeholder="Enter Sender Name" class="form-control" required>
                              </div>

                              <div class="col-md-6">
                                  <label> Sender Email  </label>
                                  <input type="email" name="sender_email" placeholder="Enter Sender Email" class="form-control" required >
                              </div>

                              <div class="col-md-6">
                                 <label> Sender Phone  </label>
                                 <input type="text" name="sender_phone" placeholder="Enter Sender Phone" class="form-control" required>
                              </div>

                              <div class="col-md-6">
                                  <label> Sender Address  </label>
                                  <textarea name="sender_address" class="form-control" required></textarea>
                              </div>


                                      <div class="col-md-12">  <h5> SHIPPING INFORMATION </h5> <br> </div>

                              

                              <!--<div class="col-md-6">-->
                              <!--    <label> USD  </label>-->
                              <!--    <input type="text" name="usd" placeholder="Enter Sender Email" class="form-control" required >-->
                              <!--</div>-->

                              

                              <div class="col-md-6">
                                 <label> Content Remark  </label>
                                 <textarea name="content_remark" class="form-control" required></textarea>
                              </div>

                              <div class="col-md-6">
                                 <label> Content Information  </label>
                                 <textarea name="content_information" class="form-control" required></textarea>
                              </div>


                                    <div class="col-md-12"> <br> <h5> RECIPIENT INFORMATION </h5>  <br></div>

                              <div class="col-md-6">
                                 <label> Identification Card </label>
                                 <input type="text" name="recipient_identity" placeholder="Enter Identification Card" class="form-control" required>
                              </div>


                              <div class="col-md-6">
                                 <label> Recipient Name  </label>
                                 <input type="text" name="recipient_name" placeholder="Enter Recipient Name" class="form-control" required>
                              </div>

                              <div class="col-md-6">
                                  <label> Recipient Email  </label>
                                  <input type="email" name="recipient_email" placeholder="Enter Recipient Email " class="form-control" required >
                              </div>

                              <div class="col-md-6">
                                 <label> Recipient Phone  </label>
                                 <input type="text" name="recipient_phone" placeholder="Enter Recipient Phone" class="form-control" required>
                              </div>

                              <div class="col-md-6">
                                  <label> Recipient Address  </label>
                                  <input type="text" name="recipient_address" placeholder="Enter Address" class="form-control" required >
                              </div>
                              
                              
                              <div class="col-md-6">
                                  <label> Country  </label>
                                  <input type="text" name="country" placeholder="Enter Country" class="form-control" required >
                              </div>

                              <div class="col-md-6">
                                  <label> State  </label>
                                  <input type="text" name="state" placeholder="Enter State" class="form-control" required >
                              </div>

                              <div class="col-md-6">
                                  <label> City  </label>
                                  <input type="text" name="city" placeholder="Enter City" class="form-control" required >
                              </div>

                              <div class="col-md-6">
                                  <label> Destination  </label>
                                  <input type="text" name="destination" placeholder="Enter Destination" class="form-control" required >
                              </div>

                              <div class="col-md-6">
                                  <label> Postal Code  </label>
                                  <input type="text" name="postal" placeholder="Enter Postal Code " class="form-control" required >
                              </div>



                                    <div class="col-md-12"> <br> <h5> More Details </h5>  <br></div>

                              <div class="col-md-6">
                                 <label> Shipping Number </label>
                                 <input type="text" name="shipping_number" value="<?php echo getName($n);; ?>" class="form-control" readonly>
                              </div>


                              <div class="col-md-6">
                                 <label> Posting Date  </label>
                                 <input type="date" name="posting_date" class="form-control" required>
                              </div>

                              <div class="col-md-6">
                                  <label> Shipping Date  </label>
                                  <input type="date" name="shipping_date" class="form-control" required >
                              </div>

                              <div class="col-md-6">
                                 <label> Estimated Date of Delivery  </label>
                                 <input type="date" name="estimate_date" placeholder="Enter Recipient Phone" class="form-control" required>
                              </div>

                              <div class="col-md-6">
                                  <label> Status Remark  </label>
                                  <textarea name="status_remark" class="form-control" required></textarea>
                              </div>

                              <div class="col-md-6">
                                  <label> Shipping Status  </label>
                                  <select name="status" class="form-control">
                                      <option value=""> - Select Status - </option>

                                      <option value="In Warehouse"> In Warehouse </option>
                                      <option value="Processing"> Processing   </option>
                                      <option value="Intransit"> Intransit </option>
                                      <option value="Custom"> Custom</option>
                                      <option value="Held by custom"> Held by custom </option>
                                      <option value="Available for pick up"> Available for pick up  </option>
                                      <option value="Delivered"> Delivered </option>

                                  </select>
                              </div>



                              <div class="col-md-6">
                                  <br> <button class="btn btn-success form-control" type="submit" name="submit" > Click to Save </button>
                              </div>
                              

                                      

                              
                            
                           

                           
                      </div>
                  </div> 
                </form> 
            </div>

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


    <!-- Scroll to Top Button-->
    <a class="scroll-to-top rounded" href="#page-top">
      <i class="fas fa-angle-up"></i>
    </a>

<?php  include('footer.php'); ?>