<?php
error_reporting(0);
if (isset($_POST['itemName']) && isset($_POST['TrackingCode']) && isset($_POST['senderName']) && isset($_POST['receiverName']) && isset($_POST['parcelStat']) && isset($_POST['currLocation']) 
&& isset($_POST['arrivalDate']) &&  isset($_POST['shippingType']) && isset($_POST['taxFee']) && isset($_POST['Pieces']) && isset($_POST['serviceType']) && isset($_POST['destinationAddr']) && 
isset($_POST['itemDesc']) ) {

if (!empty(trim($_POST['itemName'])) && !empty(trim($_POST['TrackingCode'])) && !empty(trim($_POST['senderName'])) && !empty(trim($_POST['receiverName'])) && !empty(trim($_POST['parcelStat'])) && !empty(trim($_POST['currLocation'])) && !empty(trim($_POST['arrivalDate'])) &&  !empty(trim($_POST['shippingType'])) && !empty(trim($_POST['taxFee'])) && !empty(trim($_POST['Pieces'])) && !empty(trim($_POST['serviceType'])) && !empty(trim($_POST['destinationAddr'])) && !empty(trim($_POST['itemDesc'])) ) {
require 'connect.php';
$parcelID = mysqli_real_escape_string($connect, $_POST['parcelID']);
$itemName = mysqli_real_escape_string($connect, $_POST['itemName']);
$TrackingCode = mysqli_real_escape_string($connect, $_POST['TrackingCode']);
$senderName = mysqli_real_escape_string($connect, $_POST['senderName']);
$receiverName = mysqli_real_escape_string($connect, $_POST['receiverName']);
$parcelStat = mysqli_real_escape_string($connect, $_POST['parcelStat']);
$currLocation = mysqli_real_escape_string($connect, $_POST['currLocation']);
$arrivalDate = mysqli_real_escape_string($connect, $_POST['arrivalDate']);
$shippingType = mysqli_real_escape_string($connect, $_POST['shippingType']);
$taxFee = mysqli_real_escape_string($connect, $_POST['taxFee']);
$Pieces = mysqli_real_escape_string($connect, $_POST['Pieces']);
$serviceType = mysqli_real_escape_string($connect, $_POST['serviceType']);
$destinationAddr = mysqli_real_escape_string($connect, $_POST['destinationAddr']);
$itemDesc = mysqli_real_escape_string($connect, $_POST['itemDesc']);

$InsurFee = mysqli_real_escape_string($connect, $_POST['InsurFee'] ?? '');
$Phone = mysqli_real_escape_string($connect, $_POST['Phone'] ?? '');
$Vat = mysqli_real_escape_string($connect, $_POST['Vat'] ?? '');
$TotalFee = mysqli_real_escape_string($connect, $_POST['TotalFee'] ?? '');

$TotalPaid = mysqli_real_escape_string($connect, $_POST['TotalPaid'] ?? '');
$Map = mysqli_real_escape_string($connect, $_POST['Map'] ?? '');

$Email = mysqli_real_escape_string($connect, $_POST['Email'] ?? '');

$updateQuery = mysqli_query($connect, "UPDATE WParcel SET trackCode = '$TrackingCode', Phone = '$Phone', InsurFee = '$InsurFee', Email = '$Email', TotalPaid = '$TotalPaid', Map = '$Map', Vat = '$Vat', TotalFee = '$TotalFee', itemName = '$itemName', senderName = '$senderName', receiverName = '$receiverName', itemDesc = '$itemDesc', destinationAddr = '$destinationAddr', Piece = '$Pieces', currLocation = '$currLocation', status = '$parcelStat', shippingType = '$shippingType', serviceType = '$serviceType', arrivalDate = '$arrivalDate', taxFee = '$taxFee' WHERE ID = '$parcelID'");

if ($updateQuery) {
	echo "<p style='text-align: center; color: green;'> PARCEL successfully updated.</p>";
	
		 // == sms ====

$SendTo = $Phone;
$Message = "Dear customer, Your parcel status has been updated successfully, please log on to our site and track your parcel for more details.";


$Message = str_replace(" ","%20", $Message);
$url = 'https://kullsms.com/customer/api/?username=jephthah160@gmail.com&password=Mankind160&message='.$Message.'&sender=ASD&mobiles='.$SendTo.'.';

function get_http_response_code($theURL) {
$headers = get_headers($theURL);
return substr($headers[0], 9, 3);
}
get_http_response_code($url);
	
	
} else {
	echo "<p style='text-align: center; color: red;'> An error occured, could not send PARCEL.</p>";
}
	

}else {
	echo "<p style='text-align: center; color: red;'> All fields are important</p>";
}

}else {

	header("Location: /home/");
	die();
}
     
  



  ?>