Detect tracking codes and track shipments in public view
This commit is contained in:
parent
4342f25b90
commit
a308504bbb
@ -3,5 +3,6 @@
|
||||
"Form": "Form",
|
||||
"Machines": "Machines",
|
||||
"Clients": "Clients",
|
||||
"Machine Info": "Machine Info"
|
||||
"Machine Info": "Machine Info",
|
||||
"Tracking Info": "Tracking Info"
|
||||
}
|
||||
|
138
public/index.php
138
public/index.php
@ -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 } ?>">
|
||||
<?php
|
||||
if (empty($_GET["id"]) || (!Machine::exists($_GET["id"]) && !Machine::serialExists($_GET["id"]))) {
|
||||
?>
|
||||
<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
|
||||
if (!empty($_GET["id"])) {
|
||||
?>
|
||||
<p class="text-danger">No machine with ID <code><?php echo htmlspecialchars($_GET['id']); ?></code> could be found.</p>
|
||||
<?php
|
||||
// try package tracking query
|
||||
$trackingok = false;
|
||||
if (!empty($_GET["id"]) && preg_match("/^[a-z0-9]{10,}$/", $_GET["id"])) {
|
||||
$trkresp = json_decode(file_get_contents("https://apis.netsyms.net/packagehelper/track.php?code=$_GET[id]"), true);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
?>
|
||||
<?php if (!isset($_GET["embed"])) { ?>
|
||||
<p>
|
||||
Enter a Netsyms machine ID number or serial number.
|
||||
</p>
|
||||
<form method="GET">
|
||||
<input type="text" name="id" class="form-control" placeholder="Machine ID Number" required />
|
||||
<button type="submit" class="btn btn-primary btn-block mt-2">Get Info</button>
|
||||
</form>
|
||||
<?php } ?>
|
||||
<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>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
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
|
||||
if (!empty($_GET["id"])) {
|
||||
?>
|
||||
<p class="text-danger">No machine with ID <code><?php echo htmlspecialchars($_GET['id']); ?></code> could be found.</p>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<?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>
|
||||
<?php
|
||||
<?php
|
||||
}
|
||||
} else {
|
||||
if (Machine::exists($_GET["id"])) {
|
||||
$machine = new Machine($_GET['id']);
|
||||
|
Loading…
x
Reference in New Issue
Block a user