Detect tracking codes and track shipments in public view

master
Skylar Ittner 4 years ago
parent 4342f25b90
commit a308504bbb

@ -3,5 +3,6 @@
"Form": "Form", "Form": "Form",
"Machines": "Machines", "Machines": "Machines",
"Clients": "Clients", "Clients": "Clients",
"Machine Info": "Machine Info" "Machine Info": "Machine Info",
"Tracking Info": "Tracking Info"
} }

@ -37,33 +37,123 @@ if (isset($_GET["backgroundcolor"]) && !empty($_GET["backgroundcolor"]) && preg_
<div class="<?php if (!isset($_GET["embed"])) { ?>col-12 col-md-8<?php } else { ?>col-12<?php } ?>"> <div class="<?php if (!isset($_GET["embed"])) { ?>col-12 col-md-8<?php } else { ?>col-12<?php } ?>">
<?php <?php
if (empty($_GET["id"]) || (!Machine::exists($_GET["id"]) && !Machine::serialExists($_GET["id"]))) { if (empty($_GET["id"]) || (!Machine::exists($_GET["id"]) && !Machine::serialExists($_GET["id"]))) {
?> // try package tracking query
<div class="card"> $trackingok = false;
<h3 class="card-header d-flex"> if (!empty($_GET["id"]) && preg_match("/^[a-z0-9]{10,}$/", $_GET["id"])) {
<div> $trkresp = json_decode(file_get_contents("https://apis.netsyms.net/packagehelper/track.php?code=$_GET[id]"), true);
<i class="fas fa-desktop"></i> <?php $Strings->get("Machine Info"); ?>
if ($trkresp["status"] == "OK" && $trkresp["current"]["status"] != "UNKNOWN" && $trkresp["service"]["id"] != null) {
$trackingok = true;
function trackingStatusToNiceString($status) {
switch ($status) {
case "UNKNOWN":
return "Unknown";
case "PRE_TRANSIT":
return "Pre-transit";
case "TRANSIT":
return "In Transit";
case "DELIVERED":
return "Delivered";
case "RETURNED":
return "Returned";
case "FAILURE":
return "Failure";
default:
return $status;
}
}
?>
<div class="card">
<h3 class="card-header d-flex">
<div>
<i class="fas fa-box"></i> <?php $Strings->get("Tracking Info"); ?>
</div>
</h3>
<div class="card-body">
<div class="row">
<div class="col-12 mb-3">
<div class="list-group">
<div class="list-group-item">
<b>Tracking code:</b> <span style="font-family: 'Ubuntu Mono', monospace;"><?php echo $trkresp["code"]; ?></span>
</div>
<div class="list-group-item">
<b>Current status:</b> <?php echo trackingStatusToNiceString($trkresp["current"]["status"]) . ": " . $trkresp["current"]["details"]; ?>
</div>
<div class="list-group-item">
<b>Last updated:</b> <?php echo date($SETTINGS["datetime_format"], $trkresp["current"]["date"]); ?>
</div>
<div class="list-group-item">
<b>Last location:</b> <?php echo implode(" ", $trkresp["current"]["location"]); ?>
</div>
<div class="list-group-item">
<b>Carrier:</b> <?php echo $trkresp["carrier"]["name"]; ?>
</div>
</div>
</div>
<div class="col-12 mb-3">
<h6>History:</h6>
<div class="list-group">
<?php
foreach ($trkresp["history"] as $his) {
?>
<div class="list-group-item">
<?php echo trackingStatusToNiceString($his["status"]) . ": " . $his["details"]; ?><br />
<?php echo date($SETTINGS["datetime_format"], $his["date"]); ?><br />
<?php echo implode(" ", $his["location"]); ?>
</div>
<?php
}
?>
</div>
</div>
</div>
<?php if (!isset($_GET["embed"])) { ?>
<p>
Enter a Netsyms machine ID number, serial number, or tracking code.
</p>
<form method="GET">
<input type="text" name="id" class="form-control" placeholder="Number" required />
<button type="submit" class="btn btn-primary btn-block mt-2">Get Info</button>
</form>
<?php } ?>
</div>
</div> </div>
</h3>
<div class="card-body">
<?php <?php
if (!empty($_GET["id"])) { }
?> }
<p class="text-danger">No machine with ID <code><?php echo htmlspecialchars($_GET['id']); ?></code> could be found.</p> if (!$trackingok) {
?>
<div class="card">
<h3 class="card-header d-flex">
<div>
<i class="fas fa-desktop"></i> <?php $Strings->get("Machine Info"); ?>
</div>
</h3>
<div class="card-body">
<?php <?php
} if (!empty($_GET["id"])) {
?> ?>
<?php if (!isset($_GET["embed"])) { ?> <p class="text-danger">No machine with ID <code><?php echo htmlspecialchars($_GET['id']); ?></code> could be found.</p>
<p> <?php
Enter a Netsyms machine ID number or serial number. }
</p> ?>
<form method="GET"> <?php if (!isset($_GET["embed"])) { ?>
<input type="text" name="id" class="form-control" placeholder="Machine ID Number" required /> <p>
<button type="submit" class="btn btn-primary btn-block mt-2">Get Info</button> Enter a Netsyms machine ID number, serial number, or tracking code.
</form> </p>
<?php } ?> <form method="GET">
<input type="text" name="id" class="form-control" placeholder="Number" required />
<button type="submit" class="btn btn-primary btn-block mt-2">Get Info</button>
</form>
<?php } ?>
</div>
</div> </div>
</div> <?php
<?php }
} else { } else {
if (Machine::exists($_GET["id"])) { if (Machine::exists($_GET["id"])) {
$machine = new Machine($_GET['id']); $machine = new Machine($_GET['id']);

Loading…
Cancel
Save