Remove duplicate HTML code by making reusable functions do the work
This commit is contained in:
parent
c1cd54f7aa
commit
df6a3b7e1d
9
custom/public.json
Normal file
9
custom/public.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"ID number label": "Device ID",
|
||||
"Page title": "Device Lookup",
|
||||
"ID number search box placeholder": "Device/Machine ID Number",
|
||||
"Search box prompt": "Enter a Netsyms Device ID number, serial number, or tracking code.",
|
||||
"Look up another device prompt": "Look up another device:",
|
||||
"No device with ID error": "No device with ID <code>{id}</code> could be found.",
|
||||
"Component exist but isn't attached to a machine": "This component ID exists in the system but has no associated device."
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
{
|
||||
"Date": "Date",
|
||||
"Technician": "Technician",
|
||||
"Event": "Event"
|
||||
"Event": "Event",
|
||||
"event html label": "<b>{name}</b> on {date}"
|
||||
}
|
||||
|
@ -3,6 +3,6 @@
|
||||
"Private Notes": "Private Notes",
|
||||
"Machine ID": "Machine ID",
|
||||
"Back": "Back",
|
||||
"Components": "Components"
|
||||
|
||||
"Components": "Components",
|
||||
"Component": "Component"
|
||||
}
|
@ -14,5 +14,6 @@
|
||||
"Tested On": "Tested On",
|
||||
"Capacity": "Capacity",
|
||||
"Last Event": "Last Event",
|
||||
"Client": "Client"
|
||||
"Client": "Client",
|
||||
"OS": "OS"
|
||||
}
|
||||
|
4
langs/en/public.json
Normal file
4
langs/en/public.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"Get Info": "Get Info",
|
||||
"Number": "Number"
|
||||
}
|
@ -89,6 +89,69 @@ class Component implements JsonSerializable {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the component's info to HTML
|
||||
* @param bool $public
|
||||
*/
|
||||
public function toHTML(bool $public = true): string {
|
||||
global $Strings;
|
||||
$func = function($param) {
|
||||
return $param;
|
||||
};
|
||||
$line = function($type) use ($public): string {
|
||||
global $Strings, $SETTINGS;
|
||||
if ($type == "TestedDate") {
|
||||
if (!empty($this->getTestedDate())) {
|
||||
return "<b>" . $Strings->get("Tested On", false) . ":</b> " . date($SETTINGS["date_format"], strtotime($this->getTestedDate())) . "<br />";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
if ($type == "Price") {
|
||||
if (!empty($this->getPrice())) {
|
||||
return "<b>" . $Strings->get("Price", false) . ":</b> $" . number_format($this->getPrice(), 2) . "<br />";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
if ($type == "PublicNotes") {
|
||||
if (!empty($this->getPublicNotes())) {
|
||||
return "<div><b>" . ($public ? $Strings->get("Notes", false) : $Strings->get("Public Notes", false)) . ":</b><br /><div class=\"ml-3\">" . htmlspecialchars($this->getPublicNotes()) . "</div></div>";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
if ($type == "PrivateNotes") {
|
||||
if (!empty($this->getPrivateNotes()) && $public == false) {
|
||||
return "<div><b>" . $Strings->get("Private Notes", false) . ":</b><br /><div class=\"ml-3\">" . htmlspecialchars($this->getPublicNotes()) . "</div></div>";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
if (empty($this->{"get$type"}())) {
|
||||
return "";
|
||||
}
|
||||
return "<b>" . $Strings->get($type, false) . ":</b> " . htmlspecialchars($this->{"get$type"}()) . "<br />";
|
||||
};
|
||||
$html = "";
|
||||
if ($public == false) {
|
||||
$html .= <<<HTML
|
||||
<div class="float-right">
|
||||
<a class="btn btn-danger btn-sm" href="./action.php?action=unlinkcomponent&source=viewmachine&id={$func($this->getID())}&machine={$func($this->getMachineID())}"><i class="fas fa-unlink"></i> Detach</a>
|
||||
<a class="btn btn-primary btn-sm" href="./app.php?page=editcomponent&id={$func($this->getID())}"><i class="fas fa-edit"></i> Edit</a>
|
||||
</div>
|
||||
HTML;
|
||||
}
|
||||
$html .= <<<HTML
|
||||
<b>{$func($this->getTypeName())}</b><br />
|
||||
{$line("Model")}
|
||||
{$line("Capacity")}
|
||||
{$line("Serial")}
|
||||
{$line("TestedDate")}
|
||||
{$line("Price")}
|
||||
{$line("Manufacturer")}
|
||||
{$line("PrivateNotes")}
|
||||
{$line("PublicNotes")}
|
||||
HTML;
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function jsonSerialize() {
|
||||
return $this->toArray();
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ class Event implements JsonSerializable {
|
||||
}
|
||||
|
||||
public static function getTypes() {
|
||||
$list = json_decode(file_get_contents(__DIR__ . '/events.json'), true);
|
||||
$list = json_decode(file_get_contents(__DIR__ . '/../custom/events.json'), true);
|
||||
|
||||
return $list;
|
||||
}
|
||||
@ -117,6 +117,30 @@ class Event implements JsonSerializable {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the events's info to HTML
|
||||
* @param bool $public
|
||||
*/
|
||||
public function toHTML(bool $public = true): string {
|
||||
global $Strings, $SETTINGS;
|
||||
|
||||
$html = $Strings->build("event html label", [
|
||||
"name" => $this->getName(),
|
||||
"date" => date($SETTINGS["datetime_format"], strtotime($this->getDate()))
|
||||
], false);
|
||||
$html .= "<br>\n";
|
||||
if (!empty($this->getTechUID()) && $public == false) {
|
||||
$html .= "<b>" . $Strings->get("Technician", false) . ":</b> " . htmlspecialchars((new User($this->getTechUID()))->getName()) . "<br>\n";
|
||||
}
|
||||
if (!empty($this->getPublicNotes())) {
|
||||
$html .= "<div><b>" . ($public ? $Strings->get("Notes", false) : $Strings->get("Public Notes", false)) . ":</b><br><div class=\"ml-3\">" . htmlspecialchars($this->getPublicNotes()) . "</div></div>";
|
||||
}
|
||||
if (!empty($this->getPrivateNotes()) && $public == false) {
|
||||
$html .= "<div><b>" . $Strings->get("Private Notes", false) . ":</b><br><div class=\"ml-3\">" . htmlspecialchars($this->getPrivateNotes()) . "</div></div>";
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function jsonSerialize() {
|
||||
return $this->toArray();
|
||||
}
|
||||
|
@ -151,6 +151,119 @@ class Machine implements JsonSerializable {
|
||||
return [];
|
||||
}
|
||||
|
||||
public function toHTMLListGroup(bool $public = true): string {
|
||||
global $Strings;
|
||||
$func = function($param) {
|
||||
return $param;
|
||||
};
|
||||
$line = function($type) use ($public): string {
|
||||
global $Strings, $SETTINGS;
|
||||
$publicsettings = json_decode(file_get_contents(__DIR__ . "/../custom/public.json"), true);
|
||||
if ($type == "Client") {
|
||||
if (!empty($this->getClientID()) && $public == false) {
|
||||
$client = Clients::getClient($this->getClientID());
|
||||
$rtn = "<b>" . $Strings->get("Client", false) . ":</b> " . htmlspecialchars($client->getName()) . "<br>";
|
||||
$rtn .= "<div class=\"ml-3\">";
|
||||
if (!empty($client->getPhone())) {
|
||||
$rtn .= "<b>Phone:</b> " . $client->getPhone() . "<br>";
|
||||
}
|
||||
if (!empty($client->getEmail())) {
|
||||
$rtn .= "<b>Email:</b> " . $client->getEmail() . "<br>";
|
||||
}
|
||||
if (!empty($client->getBillingAddress())) {
|
||||
$rtn .= "<b>" . $Strings->get("Billing Address", false)
|
||||
. ":</b><br>"
|
||||
. str_replace("\n", "\n<br>", htmlspecialchars($client->getBillingAddress()))
|
||||
. "<br>";
|
||||
}
|
||||
if (!empty($client->getMailingAddress())) {
|
||||
$rtn .= "<b>" . $Strings->get("Mailing Address", false)
|
||||
. ":</b><br>"
|
||||
. str_replace("\n", "\n<br>", htmlspecialchars($client->getMailingAddress()))
|
||||
. "<br>";
|
||||
}
|
||||
$rtn .= "</div>";
|
||||
return $rtn;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
if ($type == "Condition") {
|
||||
if (!empty($this->getCondition())) {
|
||||
$rtn = "<b>" . $Strings->get("Condition", false) . "</b>: ";
|
||||
$val = $this->getCondition();
|
||||
$filled = floor($val);
|
||||
$empty = 10;
|
||||
while ($filled > 0) {
|
||||
$filled--;
|
||||
$empty--;
|
||||
$rtn .= "<i class=\"fas fa-star\"></i> ";
|
||||
}
|
||||
if ($val - floor($val) > 0.75) {
|
||||
$empty--;
|
||||
$rtn .= "<i class=\"fas fa-star\"></i> ";
|
||||
} else if ($val - floor($val) > 0.25) {
|
||||
$empty--;
|
||||
$rtn .= "<i class=\"fas fa-star-half-alt\"></i> ";
|
||||
}
|
||||
while ($empty > 0) {
|
||||
$empty--;
|
||||
$rtn .= "<i class=\"far fa-star\"></i> ";
|
||||
}
|
||||
$rtn .= " ($val/10)";
|
||||
return $rtn;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
if ($type == "Price") {
|
||||
if (!empty($this->getPrice())) {
|
||||
return "<b>" . $Strings->get("Price", false) . ":</b> $" . number_format($this->getPrice(), 2) . "<br />";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
if ($type == "PublicNotes") {
|
||||
if (!empty($this->getPublicNotes())) {
|
||||
return "<b>" . ($public ? $Strings->get("Notes", false) : $Strings->get("Public Notes", false)) . ":</b><br /><div class=\"ml-3\">" . htmlspecialchars($this->getPublicNotes()) . "</div>";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
if ($type == "PrivateNotes") {
|
||||
if (!empty($this->getPrivateNotes()) && $public == false) {
|
||||
return "<b>" . $Strings->get("Private Notes", false) . ":</b><br /><div class=\"ml-3\">" . htmlspecialchars($this->getPrivateNotes()) . "</div>";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
if ($type == "ID") {
|
||||
return "<b>" . $publicsettings["ID number label"] . ":</b> " . htmlspecialchars($this->getID()) . "<br />";
|
||||
}
|
||||
if (empty($this->{"get$type"}())) {
|
||||
return "";
|
||||
}
|
||||
return "<b>" . $Strings->get($type, false) . ":</b> " . htmlspecialchars($this->{"get$type"}()) . "<br />";
|
||||
};
|
||||
|
||||
$props = ["Client", "OS", "Serial", "Manufacturer", "Model", "Condition", "Price", "PrivateNotes", "PublicNotes"];
|
||||
|
||||
if ($public) {
|
||||
$props = ["ID"] + $props;
|
||||
}
|
||||
|
||||
$html = '<div class="list-group">';
|
||||
|
||||
foreach ($props as $prop) {
|
||||
$l = $line($prop);
|
||||
if (empty($l)) {
|
||||
continue;
|
||||
}
|
||||
$html .= '<div class="list-group-item">';
|
||||
$html .= $l;
|
||||
$html .= '</div>';
|
||||
}
|
||||
|
||||
$html .= '</div>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function jsonSerialize() {
|
||||
return $this->toArray();
|
||||
}
|
||||
|
@ -51,102 +51,9 @@ $machine = new Machine($machineid);
|
||||
<div class="row">
|
||||
<div class="col-sm-6 mb-3">
|
||||
<h6>Device Info:</h6>
|
||||
<div class="list-group">
|
||||
<?php
|
||||
if (!empty($machine->getClientID())) {
|
||||
$client = Clients::getClient($machine->getClientID());
|
||||
?>
|
||||
<div class="list-group-item">
|
||||
<b><?php $Strings->get("Client"); ?></b>: <?php echo htmlspecialchars($client->getName()); ?>
|
||||
<br />
|
||||
<div class="ml-3">
|
||||
<?php if (!empty($client->getPhone())) { ?>
|
||||
<b>Phone:</b> <?php echo $client->getPhone(); ?>
|
||||
<br />
|
||||
<?php } ?>
|
||||
<?php if (!empty($client->getBillingAddress())) { ?>
|
||||
<b>Billing address:</b><br><?php echo str_replace("\n", "\n<br>", htmlspecialchars($client->getBillingAddress())); ?>
|
||||
<br />
|
||||
<?php } ?>
|
||||
<?php if (!empty($client->getMailingAddress())) { ?>
|
||||
<b>Mailing address:</b><br><?php echo str_replace("\n", "\n<br>", htmlspecialchars($client->getMailingAddress())); ?>
|
||||
<?php } ?>
|
||||
<br />
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<?php if (!empty($machine->getOS())) { ?>
|
||||
<div class="list-group-item">
|
||||
<b><?php $Strings->get("OS/Software"); ?></b>: <?php echo htmlspecialchars($machine->getOS()); ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php if (!empty($machine->getSerial())) { ?>
|
||||
<div class="list-group-item">
|
||||
<b><?php $Strings->get("Serial"); ?></b>: <?php echo htmlspecialchars($machine->getSerial()); ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php if (!empty($machine->getManufacturer())) { ?>
|
||||
<div class="list-group-item">
|
||||
<b><?php $Strings->get("Manufacturer"); ?></b>: <?php echo htmlspecialchars($machine->getManufacturer()); ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php if (!empty($machine->getModel())) { ?>
|
||||
<div class="list-group-item">
|
||||
<b><?php $Strings->get("Model"); ?></b>: <?php echo htmlspecialchars($machine->getModel()); ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php if (!empty($machine->getCondition())) { ?>
|
||||
<div class="list-group-item">
|
||||
<b><?php $Strings->get("Condition"); ?></b>: <?php
|
||||
$val = $machine->getCondition();
|
||||
$filled = floor($val);
|
||||
$empty = 10;
|
||||
while ($filled > 0) {
|
||||
$filled--;
|
||||
$empty--;
|
||||
echo "<i class=\"fas fa-star\"></i> ";
|
||||
}
|
||||
if ($val - floor($val) > 0.75) {
|
||||
$empty--;
|
||||
echo "<i class=\"fas fa-star\"></i> ";
|
||||
} else if ($val - floor($val) > 0.25) {
|
||||
$empty--;
|
||||
echo "<i class=\"fas fa-star-half-alt\"></i> ";
|
||||
}
|
||||
while ($empty > 0) {
|
||||
$empty--;
|
||||
echo "<i class=\"far fa-star\"></i> ";
|
||||
}
|
||||
echo " ($val/10)";
|
||||
?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php if (!empty($machine->getPrice())) { ?>
|
||||
<div class="list-group-item">
|
||||
<b><?php $Strings->get("Price"); ?></b>: $<?php echo number_format($machine->getPrice(), 2); ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php
|
||||
if (!empty($machine->getPrivateNotes())) {
|
||||
?>
|
||||
<div class="list-group-item">
|
||||
<b><?php $Strings->get("Private Notes"); ?></b>:<br><div class="ml-3"><?php echo str_replace("\n", "\n<br>", htmlspecialchars($machine->getPrivateNotes())); ?></div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
if (!empty($machine->getPublicNotes())) {
|
||||
?>
|
||||
<div class="list-group-item">
|
||||
<b><?php $Strings->get("Public Notes"); ?></b>:<br><div class="ml-3"><?php echo str_replace("\n", "\n<br>", htmlspecialchars($machine->getPublicNotes())); ?></div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
echo $machine->toHTMLListGroup(false);
|
||||
|
||||
$history = $machine->getEvents();
|
||||
|
||||
if (count($history) > 0) {
|
||||
@ -156,18 +63,11 @@ $machine = new Machine($machineid);
|
||||
<div class="list-group">
|
||||
<?php
|
||||
foreach ($history as $h) {
|
||||
echo "<div class=\"list-group-item\">\n";
|
||||
echo "<b>" . $h->getName() . "</b> on " . date($SETTINGS["datetime_format"], strtotime($h->getDate())) . "<br />\n";
|
||||
if (!empty($h->getTechUID())) {
|
||||
echo "<b>Technician:</b> " . htmlspecialchars((new User($h->getTechUID()))->getName()) . "<br />\n";
|
||||
}
|
||||
if (!empty($h->getPublicNotes())) {
|
||||
echo "<div><b>Public Notes:</b><br /><div class=\"ml-3\">" . str_replace("\n", "\n<br>", htmlspecialchars($h->getPublicNotes())) . "</div></div>";
|
||||
}
|
||||
if (!empty($h->getPrivateNotes())) {
|
||||
echo "<div><b>Private Notes:</b><br /><div class=\"ml-3\">" . str_replace("\n", "\n<br>", htmlspecialchars($h->getPrivateNotes())) . "</div></div>";
|
||||
}
|
||||
echo "\n</div>\n";
|
||||
?>
|
||||
<div class="list-group-item">
|
||||
<?php echo $h->toHTML(false); ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
@ -189,64 +89,7 @@ $machine = new Machine($machineid);
|
||||
foreach ($components as $c) {
|
||||
?>
|
||||
<div class="list-group-item">
|
||||
<div class="float-right">
|
||||
<a class="btn btn-danger btn-sm" href="./action.php?action=unlinkcomponent&source=viewmachine&id=<?php echo $c->getID(); ?>&machine=<?php echo $machine->getID(); ?>"><i class="fas fa-unlink"></i> <?php $Strings->get("Detach"); ?></a>
|
||||
<a class="btn btn-primary btn-sm" href="./app.php?page=editcomponent&id=<?php echo $c->getID(); ?>"><i class="fas fa-edit"></i> <?php $Strings->get("Edit"); ?></a>
|
||||
</div>
|
||||
<b><?php echo $c->getTypeName(); ?></b><br />
|
||||
<?php
|
||||
if (!empty($c->getModel())) {
|
||||
?>
|
||||
<b><?php $Strings->get("Model"); ?></b>: <?php echo htmlspecialchars($c->getModel()); ?><br />
|
||||
<?php
|
||||
}
|
||||
|
||||
if (!empty($c->getCapacity())) {
|
||||
?>
|
||||
<b><?php $Strings->get("Capacity"); ?></b>: <?php echo htmlspecialchars($c->getCapacity()); ?><br />
|
||||
<?php
|
||||
}
|
||||
|
||||
if (!empty($c->getSerial())) {
|
||||
?>
|
||||
<b><?php $Strings->get("Serial"); ?></b>: <?php echo htmlspecialchars($c->getSerial()); ?><br />
|
||||
<?php
|
||||
}
|
||||
|
||||
if (!empty($c->getManufacturer())) {
|
||||
?>
|
||||
<b><?php $Strings->get("Manufacturer"); ?></b>: <?php echo htmlspecialchars($c->getManufacturer()); ?><br />
|
||||
<?php
|
||||
}
|
||||
|
||||
if (!empty($c->getTestedDate())) {
|
||||
?>
|
||||
<b><?php $Strings->get("Tested On"); ?></b>: <?php echo date($SETTINGS["datetime_format"], strtotime($c->getTestedDate())); ?><br />
|
||||
<?php
|
||||
}
|
||||
|
||||
if (!empty($c->getPrice())) {
|
||||
?>
|
||||
<b><?php $Strings->get("Price"); ?></b>: $<?php echo number_format($c->getPrice(), 2); ?>
|
||||
<?php
|
||||
}
|
||||
|
||||
if (!empty($c->getPublicNotes())) {
|
||||
?>
|
||||
<div>
|
||||
<b>Public Notes:</b><br />
|
||||
<div class="ml-3"><?php echo str_replace("\n", "\n<br>", htmlspecialchars($c->getPublicNotes())); ?></div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
if (!empty($c->getPrivateNotes())) {
|
||||
?>
|
||||
<div>
|
||||
<b>Private Notes:</b><br />
|
||||
<div class="ml-3"><?php echo str_replace("\n", "\n<br>", htmlspecialchars($c->getPrivateNotes())); ?></div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php echo $c->toHTML(false); ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
500
public/index.php
500
public/index.php
@ -7,6 +7,47 @@
|
||||
*/
|
||||
|
||||
require_once __DIR__ . "/../lib/required_public.php";
|
||||
|
||||
$publicsettings = json_decode(file_get_contents(__DIR__ . "/../custom/public.json"), true);
|
||||
|
||||
function getSearchBox(bool $searchagain = false): string {
|
||||
global $publicsettings, $Strings;
|
||||
if (isset($_GET["embed"])) {
|
||||
return "";
|
||||
}
|
||||
$html = '<p>' . ($searchagain ? $publicsettings["Look up another device prompt"] : $publicsettings["Search box prompt"]) . '</p><form method="GET">'
|
||||
. '<input type="text" name="id" class="form-control" placeholder="' . ($searchagain ? $publicsettings["ID number search box placeholder"] : $Strings->get("Number", false)) . '" required />'
|
||||
. '<button type="submit" class="btn btn-primary btn-block mt-2">' . $Strings->get("Get Info", false) . '</button>'
|
||||
. '</form>';
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output a Bootstrap card div with the given header HTML and body HTML.
|
||||
* @param string $header
|
||||
* @param (string|array) $body string or array of strings
|
||||
*/
|
||||
function printCard($header, $body) {
|
||||
echo '<div class="card">';
|
||||
echo ' <h3 class="card-header d-flex">';
|
||||
echo ' <div>';
|
||||
echo ' ' . $header;
|
||||
echo ' </div>';
|
||||
echo ' </h3>';
|
||||
if (is_array($body)) {
|
||||
foreach ($body as $b) {
|
||||
if (empty($b)) {
|
||||
continue;
|
||||
}
|
||||
echo ' <div class="card-body">';
|
||||
echo $b;
|
||||
echo ' </div>';
|
||||
}
|
||||
} else {
|
||||
echo $body;
|
||||
}
|
||||
echo "<div>";
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<meta charset="UTF-8" />
|
||||
@ -38,33 +79,10 @@ if (isset($_GET["backgroundcolor"]) && !empty($_GET["backgroundcolor"]) && preg_
|
||||
<?php
|
||||
if (!empty($_GET["id"]) && strpos($_GET["id"], "68") === 0 && !CheckDigit::validateS10($_GET["id"])) {
|
||||
// Made a typo in the machine ID
|
||||
?>
|
||||
<div class="card">
|
||||
<h3 class="card-header d-flex">
|
||||
<div>
|
||||
<i class="fas fa-desktop"></i> <?php $Strings->get("Device Info"); ?>
|
||||
</div>
|
||||
</h3>
|
||||
<div class="card-body">
|
||||
<?php
|
||||
if (!empty($_GET["id"])) {
|
||||
?>
|
||||
<p class="text-danger"><code><?php echo htmlspecialchars($_GET['id']); ?></code> is not valid. Please try re-typing it.</p>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<?php if (!isset($_GET["embed"])) { ?>
|
||||
<p>
|
||||
Enter a <?php echo $SETTINGS["branding"]["machineidnumber"]; ?>, 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
|
||||
printCard('<i class="fas fa-desktop"></i> ' . $Strings->get("Device Info", false), [
|
||||
'<p class="text-danger"><code>' . htmlspecialchars($_GET['id']) . '</code> is not valid. Please try re-typing it.</p>',
|
||||
getSearchBox()
|
||||
]);
|
||||
} else if (empty($_GET["id"]) || (!Machine::exists($_GET["id"]) && !Machine::serialExists($_GET["id"]) && !Component::exists($_GET["id"]))) {
|
||||
// try package tracking query
|
||||
$trackingok = false;
|
||||
@ -93,377 +111,127 @@ if (isset($_GET["backgroundcolor"]) && !empty($_GET["backgroundcolor"]) && preg_
|
||||
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">
|
||||
|
||||
$html = '<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>
|
||||
<b>Tracking code:</b> <span style="font-family: \'Ubuntu Mono\', monospace;">' . $trkresp["code"] . '</span>
|
||||
</div>
|
||||
<div class="list-group-item">
|
||||
<b>Current status:</b> <?php echo trackingStatusToNiceString($trkresp["current"]["status"]) . ": " . $trkresp["current"]["details"]; ?>
|
||||
</div>
|
||||
<b>Current status:</b> ' . 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>
|
||||
<b>Last updated:</b> ' . date($SETTINGS["datetime_format"], $trkresp["current"]["date"])
|
||||
. '</div>
|
||||
<div class="list-group-item">
|
||||
<b>Last location:</b> <?php echo implode(" ", $trkresp["current"]["location"]); ?>
|
||||
</div>
|
||||
<b>Last location:</b> ' . implode(" ", $trkresp["current"]["location"])
|
||||
. '</div>
|
||||
<div class="list-group-item">
|
||||
<b>Carrier:</b> <?php echo $trkresp["carrier"]["name"]; ?>
|
||||
</div>
|
||||
<b>Carrier:</b> ' . $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 class="list-group">';
|
||||
foreach ($trkresp["history"] as $his) {
|
||||
$html .= '<div class="list-group-item">';
|
||||
$html .= '<b>' . trackingStatusToNiceString($his["status"]) . ":</b> " . $his["details"] . '<br>';
|
||||
$html .= date($SETTINGS["datetime_format"], $his["date"]) . '<br>';
|
||||
$html .= implode(" ", $his["location"]);
|
||||
$html .= '</div>';
|
||||
}
|
||||
$html .= '</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php if (!isset($_GET["embed"])) { ?>
|
||||
<p>
|
||||
Enter a <?php echo $SETTINGS["branding"]["machineidnumber"]; ?>, 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
|
||||
</div>';
|
||||
|
||||
printCard('<i class="fas fa-box"></i> ' . $Strings->get("Tracking Info", false), [
|
||||
$html,
|
||||
getSearchBox()
|
||||
]);
|
||||
}
|
||||
}
|
||||
if (!$trackingok) {
|
||||
?>
|
||||
<div class="card">
|
||||
<h3 class="card-header d-flex">
|
||||
<div>
|
||||
<i class="fas fa-desktop"></i> <?php $Strings->get("Device Info"); ?>
|
||||
</div>
|
||||
</h3>
|
||||
<div class="card-body">
|
||||
<?php
|
||||
if (!empty($_GET["id"])) {
|
||||
?>
|
||||
<p class="text-danger">No device with ID <code><?php echo htmlspecialchars($_GET['id']); ?></code> could be found.</p>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<?php if (!isset($_GET["embed"])) { ?>
|
||||
<p>
|
||||
Enter a <?php echo $SETTINGS["branding"]["machineidnumber"]; ?>, 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
|
||||
$body = [];
|
||||
if (!empty($_GET["id"])) {
|
||||
$body[] = '<p class="text-danger">' . str_replace("{id}", htmlspecialchars($_GET['id']), $publicsettings["No device with ID error"]) . "</p>";
|
||||
}
|
||||
$body[] = getSearchBox();
|
||||
printCard('<i class="fas fa-desktop"></i> ' . $Strings->get("Device Info", false), $body);
|
||||
}
|
||||
} else {
|
||||
if (Machine::exists($_GET["id"])) {
|
||||
$machine = new Machine($_GET['id']);
|
||||
} else if (Component::exists($_GET["id"])) {
|
||||
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
|
||||
?>
|
||||
<div class="card">
|
||||
<h3 class="card-header d-flex">
|
||||
<div>
|
||||
<i class="fas fa-memory"></i> <?php echo $component->getTypeName(); ?> Info
|
||||
</div>
|
||||
</h3>
|
||||
<div class="card-body">
|
||||
<div class="alert alert-info">
|
||||
<i class="fas fa-info-circle"></i> This component ID exists in the system but has no associated device.
|
||||
</div>
|
||||
$html = '<div class="alert alert-info">
|
||||
<i class="fas fa-info-circle"></i> ' . $publicsettings["Component exist but isn't attached to a machine"]
|
||||
. '</div>
|
||||
<div class="row">
|
||||
<div class="col-12 mb-3">
|
||||
<div class="list-group">
|
||||
<div class="list-group-item">
|
||||
<b><?php $Strings->get("ID"); ?></b>: <?php echo htmlspecialchars($component->getID()); ?>
|
||||
</div>
|
||||
<?php if (!empty($component->getModel())) { ?>
|
||||
<div class="list-group-item"><b><?php $Strings->get("Model"); ?></b>: <?php echo htmlspecialchars($component->getModel()); ?></div>
|
||||
<?php
|
||||
}
|
||||
|
||||
if (!empty($component->getCapacity())) {
|
||||
?>
|
||||
<div class="list-group-item"><b><?php $Strings->get("Capacity"); ?></b>: <?php echo htmlspecialchars($component->getCapacity()); ?></div>
|
||||
<?php
|
||||
}
|
||||
|
||||
if (!empty($component->getSerial())) {
|
||||
?>
|
||||
<div class="list-group-item"><b><?php $Strings->get("Serial"); ?></b>: <?php echo htmlspecialchars($component->getSerial()); ?></div>
|
||||
<?php
|
||||
}
|
||||
|
||||
if (!empty($component->getTestedDate())) {
|
||||
?>
|
||||
<div class="list-group-item"><b><?php $Strings->get("Tested On"); ?></b>: <?php echo date($SETTINGS["date_format"], strtotime($component->getTestedDate())); ?></div>
|
||||
<?php
|
||||
}
|
||||
|
||||
if (!empty($component->getPrice())) {
|
||||
?>
|
||||
<div class="list-group-item"><b><?php $Strings->get("Price"); ?></b>: $<?php echo number_format($component->getPrice(), 2); ?></div>
|
||||
<?php
|
||||
}
|
||||
|
||||
if (!empty($component->getManufacturer())) {
|
||||
?>
|
||||
<div class="list-group-item"><b><?php $Strings->get("Manufacturer"); ?></b>: <?php echo htmlspecialchars($component->getManufacturer()); ?></div>
|
||||
<?php
|
||||
}
|
||||
|
||||
if (!empty($component->getPublicNotes())) {
|
||||
?>
|
||||
<div class="list-group-item">
|
||||
<b>Notes:</b><br>
|
||||
<div class="ml-3"><?php echo htmlspecialchars($component->getPublicNotes()); ?></div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php /* Hide this box if we're embedded in another page */ if (!isset($_GET["embed"])) { ?>
|
||||
<div class="card-body">
|
||||
<p>
|
||||
Look up another device:
|
||||
</p>
|
||||
<form method="GET">
|
||||
<input type="text" name="id" class="form-control" placeholder="<?php echo $SETTINGS["branding"]["shortmachineid"]; ?>" required />
|
||||
<button type="submit" class="btn btn-primary btn-block mt-2">Get Info</button>
|
||||
</form>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php
|
||||
<div class="list-group-item">'
|
||||
. $component->toHTML(true)
|
||||
. '</div></div></div></div>';
|
||||
printCard('<i class="fas fa-memory"></i> ' . $Strings->get("Component", false) . ' #' . $component->getID(), [$html, getSearchBox()]);
|
||||
}
|
||||
} else {
|
||||
$machine = new Machine(Machine::getIDFromSerial($_GET['id']));
|
||||
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 = '<div class="col-sm-6 mb-3">
|
||||
<h6>Events:</h6>
|
||||
<div class="list-group">';
|
||||
foreach ($history as $h) {
|
||||
$eventshtml .= '<div class="list-group-item">'
|
||||
. $h->toHTML(true)
|
||||
. '</div>';
|
||||
}
|
||||
$eventshtml .= '</div></div>';
|
||||
}
|
||||
|
||||
|
||||
$componentshtml = "";
|
||||
$components = $machine->getComponents();
|
||||
|
||||
if (count($components) > 0) {
|
||||
$componentshtml = '<div class="col-sm-6 mb-3"><h6>Components:</h6><div class="list-group">';
|
||||
foreach ($components as $c) {
|
||||
$componentshtml .= '<div class = "list-group-item">'
|
||||
. $c->toHTML(true)
|
||||
. '</div>';
|
||||
}
|
||||
$componentshtml .= '</div></div>';
|
||||
}
|
||||
|
||||
$body = [
|
||||
'<div class="row"><div class="col-12 mb-3">'
|
||||
. $machine->toHTMLListGroup(true)
|
||||
. '</div>'
|
||||
. $eventshtml
|
||||
. $componentshtml
|
||||
. "</div>",
|
||||
getSearchBox(true)
|
||||
];
|
||||
|
||||
printCard('<i class="' . $machine->getIcon() . '"></i> ' . $machine->getTypeLabel() . ' Info', $body);
|
||||
}
|
||||
?>
|
||||
<div class="card">
|
||||
<h3 class="card-header d-flex">
|
||||
<div>
|
||||
<i class="<?php echo $machine->getIcon(); ?>"></i> <?php echo $machine->getTypeLabel(); ?> 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><?php $Strings->get("ID"); ?></b>: <?php echo htmlspecialchars($machine->getID()); ?>
|
||||
</div>
|
||||
<?php if (!empty($machine->getOS())) { ?>
|
||||
<div class="list-group-item">
|
||||
<b><?php $Strings->get("OS/Software"); ?></b>: <?php echo htmlspecialchars($machine->getOS()); ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php if (!empty($machine->getSerial())) { ?>
|
||||
<div class="list-group-item">
|
||||
<b><?php $Strings->get("Serial"); ?></b>: <?php echo htmlspecialchars($machine->getSerial()); ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php if (!empty($machine->getManufacturer())) { ?>
|
||||
<div class="list-group-item">
|
||||
<b><?php $Strings->get("Manufacturer"); ?></b>: <?php echo htmlspecialchars($machine->getManufacturer()); ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php if (!empty($machine->getModel())) { ?>
|
||||
<div class="list-group-item">
|
||||
<b><?php $Strings->get("Model"); ?></b>: <?php echo htmlspecialchars($machine->getModel()); ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php
|
||||
if ($machine->getCondition() > 0) {
|
||||
?>
|
||||
<div class="list-group-item">
|
||||
<b><?php $Strings->get("Condition"); ?></b>: <?php
|
||||
$val = $machine->getCondition();
|
||||
$filled = floor($val);
|
||||
$empty = 10;
|
||||
while ($filled > 0) {
|
||||
$filled--;
|
||||
$empty--;
|
||||
echo "<i class=\"fas fa-star\"></i> ";
|
||||
}
|
||||
if ($val - floor($val) > 0.75) {
|
||||
$empty--;
|
||||
echo "<i class=\"fas fa-star\"></i> ";
|
||||
} else if ($val - floor($val) > 0.25) {
|
||||
$empty--;
|
||||
echo "<i class=\"fas fa-star-half-alt\"></i> ";
|
||||
}
|
||||
while ($empty > 0) {
|
||||
$empty--;
|
||||
echo "<i class=\"far fa-star\"></i> ";
|
||||
}
|
||||
echo " ($val/10)";
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<?php
|
||||
if ($machine->getPrice() > 0) {
|
||||
?>
|
||||
<div class="list-group-item">
|
||||
<b><?php $Strings->get("Price"); ?></b>: $<?php echo number_format($machine->getPrice(), 2); ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<?php
|
||||
if (!empty($machine->getPublicNotes())) {
|
||||
?>
|
||||
<div class="list-group-item">
|
||||
<b><?php $Strings->get("Notes"); ?></b>: <?php echo str_replace("\n", "\n<br>", htmlspecialchars($machine->getPublicNotes())); ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
$history = $machine->getEvents();
|
||||
$events = [];
|
||||
foreach ($history as $h) {
|
||||
$events[] = $h;
|
||||
}
|
||||
|
||||
if (count($events) > 0) {
|
||||
?>
|
||||
<div class="col-sm-6 mb-3">
|
||||
<h6>Events:</h6>
|
||||
<div class="list-group">
|
||||
<?php
|
||||
foreach ($history as $h) {
|
||||
echo "<div class=\"list-group-item\">\n";
|
||||
echo "<b>" . $h->getName() . "</b> on " . date($SETTINGS["datetime_format"], strtotime($h->getDate())) . "<br />\n";
|
||||
if (!empty($h->getPublicNotes())) {
|
||||
echo "<div><b>Notes:</b><br /><div class=\"ml-3\">" . htmlspecialchars($h->getPublicNotes()) . "</div></div>";
|
||||
}
|
||||
echo "\n</div>\n";
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
$components = $machine->getComponents();
|
||||
|
||||
if (count($components) > 0) {
|
||||
?>
|
||||
<div class="col-sm-6 mb-3">
|
||||
<h6>Components:</h6>
|
||||
<div class="list-group">
|
||||
<?php
|
||||
foreach ($components as $c) {
|
||||
?>
|
||||
<div class = "list-group-item">
|
||||
|
||||
<b><?php echo $c->getTypeName(); ?></b><br />
|
||||
<?php
|
||||
if (!empty($c->getModel())) {
|
||||
?>
|
||||
<b><?php $Strings->get("Model"); ?></b>: <?php echo htmlspecialchars($c->getModel()); ?><br />
|
||||
<?php
|
||||
}
|
||||
|
||||
if (!empty($c->getCapacity())) {
|
||||
?>
|
||||
<b><?php $Strings->get("Capacity"); ?></b>: <?php echo htmlspecialchars($c->getCapacity()); ?><br />
|
||||
<?php
|
||||
}
|
||||
|
||||
if (!empty($c->getSerial())) {
|
||||
?>
|
||||
<b><?php $Strings->get("Serial"); ?></b>: <?php echo htmlspecialchars($c->getSerial()); ?><br />
|
||||
<?php
|
||||
}
|
||||
|
||||
if (!empty($c->getTestedDate())) {
|
||||
?>
|
||||
<b><?php $Strings->get("Tested On"); ?></b>: <?php echo date($SETTINGS["date_format"], strtotime($c->getTestedDate())); ?><br />
|
||||
<?php
|
||||
}
|
||||
|
||||
if (!empty($c->getPrice())) {
|
||||
?>
|
||||
<b><?php $Strings->get("Price"); ?></b>: $<?php echo number_format($c->getPrice(), 2); ?><br />
|
||||
<?php
|
||||
}
|
||||
|
||||
if (!empty($c->getManufacturer())) {
|
||||
?>
|
||||
<b><?php $Strings->get("Manufacturer"); ?></b>: <?php echo htmlspecialchars($c->getManufacturer()); ?><br />
|
||||
<?php
|
||||
}
|
||||
|
||||
if (!empty($c->getPublicNotes())) {
|
||||
?>
|
||||
<div>
|
||||
<b>Notes:</b><br />
|
||||
<div class="ml-3"><?php echo htmlspecialchars($c->getPublicNotes()); ?></div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<?php /* Hide this box if we're embedded in another page */ if (!isset($_GET["embed"])) { ?>
|
||||
<div class="card-body">
|
||||
<p>
|
||||
Look up another device:
|
||||
</p>
|
||||
<form method="GET">
|
||||
<input type="text" name="id" class="form-control" placeholder="<?php echo $SETTINGS["branding"]["shortmachineid"]; ?>" required />
|
||||
<button type="submit" class="btn btn-primary btn-block mt-2">Get Info</button>
|
||||
</form>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user