col-12 col-md-8col-12">
' . $Strings->get("Device Info", false), [
'
' . htmlspecialchars($_GET['id']) . '
is not valid. Please try re-typing it.
',
getSearchBox()
]);
} else if (empty($_GET["id"]) || (!Machine::exists($_GET["id"]) && !Machine::serialExists($_GET["id"]) && !Component::exists($_GET["id"]))) {
// 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;
}
}
$html = '
Tracking code: ' . $trkresp["code"] . '
Current status: ' . trackingStatusToNiceString($trkresp["current"]["status"]) . ": " . $trkresp["current"]["details"]
. '
Last updated: ' . date($SETTINGS["datetime_format"], $trkresp["current"]["date"])
. '
Last location: ' . implode(" ", $trkresp["current"]["location"])
. '
Carrier: ' . $trkresp["carrier"]["name"] .
'
History:
';
foreach ($trkresp["history"] as $his) {
$html .= '
';
$html .= '' . trackingStatusToNiceString($his["status"]) . ": " . $his["details"] . '
';
$html .= date($SETTINGS["datetime_format"], $his["date"]) . '
';
$html .= implode(" ", $his["location"]);
$html .= '
';
}
$html .= '
';
printCard('
' . $Strings->get("Tracking Info", false), [
$html,
getSearchBox()
]);
}
}
if (!$trackingok) {
$body = [];
if (!empty($_GET["id"])) {
$body[] = '
' . str_replace("{id}", htmlspecialchars($_GET['id']), $publicsettings["No device with ID error"]) . "
";
}
$body[] = getSearchBox();
printCard('
' . $Strings->get("Device Info", false), $body);
}
} else {
if (Component::exists($_GET["id"])) {
$component = new Component($_GET["id"]);
$mid = $component->getMachineID();
if (!empty($mid) && Machine::exists($mid)) {
$machine = new Machine($mid);
} else {
// component exists but isn't attached to a machine
$html = '
' . $publicsettings["Component exist but isn't attached to a machine"]
. '
'
. $component->toHTML(true)
. '
';
printCard('
' . $Strings->get("Component", false) . ' #' . $component->getID(), [$html, getSearchBox()]);
}
} else {
if (Machine::exists($_GET["id"])) {
$machine = new Machine($_GET['id']);
} else {
$machine = new Machine(Machine::getIDFromSerial($_GET['id']));
}
$eventshtml = "";
$history = $machine->getEvents();
$events = [];
foreach ($history as $h) {
$events[] = $h;
}
if (count($events) > 0) {
$eventshtml = '
Events:
';
foreach ($history as $h) {
$eventshtml .= '
'
. $h->toHTML(true)
. '
';
}
$eventshtml .= '
';
}
$componentshtml = "";
$components = $machine->getComponents();
if (count($components) > 0) {
$componentshtml = '
Components:
';
foreach ($components as $c) {
$componentshtml .= '
'
. $c->toHTML(true)
. '
';
}
$componentshtml .= '
';
}
$body = [
'
'
. $machine->toHTMLListGroup(true)
. '
'
. $eventshtml
. $componentshtml
. "
",
getSearchBox(true)
];
printCard('
' . $machine->getTypeLabel() . ' Info', $body);
}
}
?>