diff --git a/lib/events.json b/custom/events.json similarity index 100% rename from lib/events.json rename to custom/events.json diff --git a/custom/public.json b/custom/public.json new file mode 100644 index 0000000..25ea0de --- /dev/null +++ b/custom/public.json @@ -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 {id} could be found.", + "Component exist but isn't attached to a machine": "This component ID exists in the system but has no associated device." +} diff --git a/langs/en/events.json b/langs/en/events.json index 405af31..2e35e5c 100644 --- a/langs/en/events.json +++ b/langs/en/events.json @@ -1,5 +1,6 @@ { "Date": "Date", "Technician": "Technician", - "Event": "Event" + "Event": "Event", + "event html label": "{name} on {date}" } diff --git a/langs/en/labels.json b/langs/en/labels.json index 1742298..0520a41 100644 --- a/langs/en/labels.json +++ b/langs/en/labels.json @@ -3,6 +3,6 @@ "Private Notes": "Private Notes", "Machine ID": "Machine ID", "Back": "Back", - "Components": "Components" - + "Components": "Components", + "Component": "Component" } \ No newline at end of file diff --git a/langs/en/machines.json b/langs/en/machines.json index ba7ff05..a6c577c 100644 --- a/langs/en/machines.json +++ b/langs/en/machines.json @@ -14,5 +14,6 @@ "Tested On": "Tested On", "Capacity": "Capacity", "Last Event": "Last Event", - "Client": "Client" + "Client": "Client", + "OS": "OS" } diff --git a/langs/en/public.json b/langs/en/public.json new file mode 100644 index 0000000..e8fc5c2 --- /dev/null +++ b/langs/en/public.json @@ -0,0 +1,4 @@ +{ + "Get Info": "Get Info", + "Number": "Number" +} diff --git a/lib/Component.lib.php b/lib/Component.lib.php index ebf15f4..176ab5e 100644 --- a/lib/Component.lib.php +++ b/lib/Component.lib.php @@ -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 "" . $Strings->get("Tested On", false) . ": " . date($SETTINGS["date_format"], strtotime($this->getTestedDate())) . "
"; + } + return ""; + } + if ($type == "Price") { + if (!empty($this->getPrice())) { + return "" . $Strings->get("Price", false) . ": $" . number_format($this->getPrice(), 2) . "
"; + } + return ""; + } + if ($type == "PublicNotes") { + if (!empty($this->getPublicNotes())) { + return "
" . ($public ? $Strings->get("Notes", false) : $Strings->get("Public Notes", false)) . ":
" . htmlspecialchars($this->getPublicNotes()) . "
"; + } + return ""; + } + if ($type == "PrivateNotes") { + if (!empty($this->getPrivateNotes()) && $public == false) { + return "
" . $Strings->get("Private Notes", false) . ":
" . htmlspecialchars($this->getPublicNotes()) . "
"; + } + return ""; + } + if (empty($this->{"get$type"}())) { + return ""; + } + return "" . $Strings->get($type, false) . ": " . htmlspecialchars($this->{"get$type"}()) . "
"; + }; + $html = ""; + if ($public == false) { + $html .= << + Detach + Edit + +HTML; + } + $html .= <<{$func($this->getTypeName())}
+ {$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(); } diff --git a/lib/Event.lib.php b/lib/Event.lib.php index a7b4b59..5e09434 100644 --- a/lib/Event.lib.php +++ b/lib/Event.lib.php @@ -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 .= "
\n"; + if (!empty($this->getTechUID()) && $public == false) { + $html .= "" . $Strings->get("Technician", false) . ": " . htmlspecialchars((new User($this->getTechUID()))->getName()) . "
\n"; + } + if (!empty($this->getPublicNotes())) { + $html .= "
" . ($public ? $Strings->get("Notes", false) : $Strings->get("Public Notes", false)) . ":
" . htmlspecialchars($this->getPublicNotes()) . "
"; + } + if (!empty($this->getPrivateNotes()) && $public == false) { + $html .= "
" . $Strings->get("Private Notes", false) . ":
" . htmlspecialchars($this->getPrivateNotes()) . "
"; + } + return $html; + } + public function jsonSerialize() { return $this->toArray(); } diff --git a/lib/Machine.lib.php b/lib/Machine.lib.php index e4ca950..3eb51f0 100644 --- a/lib/Machine.lib.php +++ b/lib/Machine.lib.php @@ -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 = "" . $Strings->get("Client", false) . ": " . htmlspecialchars($client->getName()) . "
"; + $rtn .= "
"; + if (!empty($client->getPhone())) { + $rtn .= "Phone: " . $client->getPhone() . "
"; + } + if (!empty($client->getEmail())) { + $rtn .= "Email: " . $client->getEmail() . "
"; + } + if (!empty($client->getBillingAddress())) { + $rtn .= "" . $Strings->get("Billing Address", false) + . ":
" + . str_replace("\n", "\n
", htmlspecialchars($client->getBillingAddress())) + . "
"; + } + if (!empty($client->getMailingAddress())) { + $rtn .= "" . $Strings->get("Mailing Address", false) + . ":
" + . str_replace("\n", "\n
", htmlspecialchars($client->getMailingAddress())) + . "
"; + } + $rtn .= "
"; + return $rtn; + } + return ""; + } + if ($type == "Condition") { + if (!empty($this->getCondition())) { + $rtn = "" . $Strings->get("Condition", false) . ": "; + $val = $this->getCondition(); + $filled = floor($val); + $empty = 10; + while ($filled > 0) { + $filled--; + $empty--; + $rtn .= " "; + } + if ($val - floor($val) > 0.75) { + $empty--; + $rtn .= " "; + } else if ($val - floor($val) > 0.25) { + $empty--; + $rtn .= " "; + } + while ($empty > 0) { + $empty--; + $rtn .= " "; + } + $rtn .= " ($val/10)"; + return $rtn; + } + return ""; + } + if ($type == "Price") { + if (!empty($this->getPrice())) { + return "" . $Strings->get("Price", false) . ": $" . number_format($this->getPrice(), 2) . "
"; + } + return ""; + } + if ($type == "PublicNotes") { + if (!empty($this->getPublicNotes())) { + return "" . ($public ? $Strings->get("Notes", false) : $Strings->get("Public Notes", false)) . ":
" . htmlspecialchars($this->getPublicNotes()) . "
"; + } + return ""; + } + if ($type == "PrivateNotes") { + if (!empty($this->getPrivateNotes()) && $public == false) { + return "" . $Strings->get("Private Notes", false) . ":
" . htmlspecialchars($this->getPrivateNotes()) . "
"; + } + return ""; + } + if ($type == "ID") { + return "" . $publicsettings["ID number label"] . ": " . htmlspecialchars($this->getID()) . "
"; + } + if (empty($this->{"get$type"}())) { + return ""; + } + return "" . $Strings->get($type, false) . ": " . htmlspecialchars($this->{"get$type"}()) . "
"; + }; + + $props = ["Client", "OS", "Serial", "Manufacturer", "Model", "Condition", "Price", "PrivateNotes", "PublicNotes"]; + + if ($public) { + $props = ["ID"] + $props; + } + + $html = '
'; + + foreach ($props as $prop) { + $l = $line($prop); + if (empty($l)) { + continue; + } + $html .= '
'; + $html .= $l; + $html .= '
'; + } + + $html .= '
'; + + return $html; + } + public function jsonSerialize() { return $this->toArray(); } diff --git a/pages/viewmachine.php b/pages/viewmachine.php index ae5c4fe..2f1855b 100644 --- a/pages/viewmachine.php +++ b/pages/viewmachine.php @@ -51,102 +51,9 @@ $machine = new Machine($machineid);
Device Info:
-
- getClientID())) { - $client = Clients::getClient($machine->getClientID()); - ?> -
- get("Client"); ?>: getName()); ?> -
-
- getPhone())) { ?> - Phone: getPhone(); ?> -
- - getBillingAddress())) { ?> - Billing address:
", htmlspecialchars($client->getBillingAddress())); ?> -
- - getMailingAddress())) { ?> - Mailing address:
", htmlspecialchars($client->getMailingAddress())); ?> - -
-
-
- - getOS())) { ?> -
- get("OS/Software"); ?>: getOS()); ?> -
- - getSerial())) { ?> -
- get("Serial"); ?>: getSerial()); ?> -
- - getManufacturer())) { ?> -
- get("Manufacturer"); ?>: getManufacturer()); ?> -
- - getModel())) { ?> -
- get("Model"); ?>: getModel()); ?> -
- - getCondition())) { ?> -
- get("Condition"); ?>: getCondition(); - $filled = floor($val); - $empty = 10; - while ($filled > 0) { - $filled--; - $empty--; - echo " "; - } - if ($val - floor($val) > 0.75) { - $empty--; - echo " "; - } else if ($val - floor($val) > 0.25) { - $empty--; - echo " "; - } - while ($empty > 0) { - $empty--; - echo " "; - } - echo " ($val/10)"; - ?> -
- - getPrice())) { ?> -
- get("Price"); ?>: $getPrice(), 2); ?> -
- - getPrivateNotes())) { - ?> -
- get("Private Notes"); ?>:
", htmlspecialchars($machine->getPrivateNotes())); ?>
-
- getPublicNotes())) { - ?> -
- get("Public Notes"); ?>:
", htmlspecialchars($machine->getPublicNotes())); ?>
-
- -
- toHTMLListGroup(false); + $history = $machine->getEvents(); if (count($history) > 0) { @@ -156,18 +63,11 @@ $machine = new Machine($machineid);
\n"; - echo "" . $h->getName() . " on " . date($SETTINGS["datetime_format"], strtotime($h->getDate())) . "
\n"; - if (!empty($h->getTechUID())) { - echo "Technician: " . htmlspecialchars((new User($h->getTechUID()))->getName()) . "
\n"; - } - if (!empty($h->getPublicNotes())) { - echo "
Public Notes:
" . str_replace("\n", "\n
", htmlspecialchars($h->getPublicNotes())) . "
"; - } - if (!empty($h->getPrivateNotes())) { - echo "
Private Notes:
" . str_replace("\n", "\n
", htmlspecialchars($h->getPrivateNotes())) . "
"; - } - echo "\n
\n"; + ?> +
+ toHTML(false); ?> +
+
@@ -189,64 +89,7 @@ $machine = new Machine($machineid); foreach ($components as $c) { ?>
- - getTypeName(); ?>
- getModel())) { - ?> - get("Model"); ?>: getModel()); ?>
- getCapacity())) { - ?> - get("Capacity"); ?>: getCapacity()); ?>
- getSerial())) { - ?> - get("Serial"); ?>: getSerial()); ?>
- getManufacturer())) { - ?> - get("Manufacturer"); ?>: getManufacturer()); ?>
- getTestedDate())) { - ?> - get("Tested On"); ?>: getTestedDate())); ?>
- getPrice())) { - ?> - get("Price"); ?>: $getPrice(), 2); ?> - getPublicNotes())) { - ?> -
- Public Notes:
-
", htmlspecialchars($c->getPublicNotes())); ?>
-
- getPrivateNotes())) { - ?> -
- Private Notes:
-
", htmlspecialchars($c->getPrivateNotes())); ?>
-
- + toHTML(false); ?>
' . ($searchagain ? $publicsettings["Look up another device prompt"] : $publicsettings["Search box prompt"]) . '

' + . 'get("Number", false)) . '" required />' + . '' + . '
'; + 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 '
'; + echo '

'; + echo '
'; + echo ' ' . $header; + echo '
'; + echo '

'; + if (is_array($body)) { + foreach ($body as $b) { + if (empty($b)) { + continue; + } + echo '
'; + echo $b; + echo '
'; + } + } else { + echo $body; + } + echo "
"; +} ?> @@ -38,33 +79,10 @@ if (isset($_GET["backgroundcolor"]) && !empty($_GET["backgroundcolor"]) && preg_ -
-

-
- get("Device Info"); ?> -
-

-
- -

is not valid. Please try re-typing it.

- - -

- Enter a , serial number, or tracking code. -

-
- - -
- -
-
- ' . $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; @@ -93,377 +111,127 @@ if (isset($_GET["backgroundcolor"]) && !empty($_GET["backgroundcolor"]) && preg_ return $status; } } - ?> -
-

-
- get("Tracking Info"); ?> -
-

-
-
+ + $html = '
- Tracking code: + Tracking code: ' . $trkresp["code"] . '
- Current status: -
+ Current status: ' . trackingStatusToNiceString($trkresp["current"]["status"]) . ": " . $trkresp["current"]["details"] + . '
- Last updated: -
+ Last updated: ' . date($SETTINGS["datetime_format"], $trkresp["current"]["date"]) + . '
- Last location: -
+ Last location: ' . implode(" ", $trkresp["current"]["location"]) + . '
- Carrier: -
+ 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 .= '
-
- -

- Enter a , serial number, or tracking code. -

-
- - -
- -
-
- '; + + printCard(' ' . $Strings->get("Tracking Info", false), [ + $html, + getSearchBox() + ]); } } if (!$trackingok) { - ?> -
-

-
- get("Device Info"); ?> -
-

-
- -

No device with ID could be found.

- - -

- Enter a , serial number, or tracking code. -

-
- - -
- -
-
- ' . str_replace("{id}", htmlspecialchars($_GET['id']), $publicsettings["No device with ID error"]) . "

"; + } + $body[] = getSearchBox(); + printCard(' ' . $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 - ?> -
-

-
- getTypeName(); ?> Info -
-

-
-
- This component ID exists in the system but has no associated device. -
+ $html = '
+ ' . $publicsettings["Component exist but isn't attached to a machine"] + . '
-
- get("ID"); ?>: getID()); ?> -
- getModel())) { ?> -
get("Model"); ?>: getModel()); ?>
- getCapacity())) { - ?> -
get("Capacity"); ?>: getCapacity()); ?>
- getSerial())) { - ?> -
get("Serial"); ?>: getSerial()); ?>
- getTestedDate())) { - ?> -
get("Tested On"); ?>: getTestedDate())); ?>
- getPrice())) { - ?> -
get("Price"); ?>: $getPrice(), 2); ?>
- getManufacturer())) { - ?> -
get("Manufacturer"); ?>: getManufacturer()); ?>
- getPublicNotes())) { - ?> -
- Notes:
-
getPublicNotes()); ?>
-
- -
-
-
-
- -
-

- Look up another device: -

-
- " required /> - -
-
- -
- ' + . $component->toHTML(true) + . ''; + printCard(' ' . $Strings->get("Component", false) . ' #' . $component->getID(), [$html, getSearchBox()]); } } else { - $machine = new Machine(Machine::getIDFromSerial($_GET['id'])); - } - ?> -
-

-
- getTypeLabel(); ?> Info -
-

-
-
-
-
-
- get("ID"); ?>: getID()); ?> -
- getOS())) { ?> -
- get("OS/Software"); ?>: getOS()); ?> -
- - getSerial())) { ?> -
- get("Serial"); ?>: getSerial()); ?> -
- - getManufacturer())) { ?> -
- get("Manufacturer"); ?>: getManufacturer()); ?> -
- - getModel())) { ?> -
- get("Model"); ?>: getModel()); ?> -
- - getCondition() > 0) { - ?> -
- get("Condition"); ?>: getCondition(); - $filled = floor($val); - $empty = 10; - while ($filled > 0) { - $filled--; - $empty--; - echo " "; - } - if ($val - floor($val) > 0.75) { - $empty--; - echo " "; - } else if ($val - floor($val) > 0.25) { - $empty--; - echo " "; - } - while ($empty > 0) { - $empty--; - echo " "; - } - echo " ($val/10)"; - ?> -
- - getPrice() > 0) { - ?> -
- get("Price"); ?>: $getPrice(), 2); ?> -
- - getPublicNotes())) { - ?> -
- get("Notes"); ?>: ", htmlspecialchars($machine->getPublicNotes())); ?> -
- -
-
- - getEvents(); - $events = []; - foreach ($history as $h) { - $events[] = $h; - } - - if (count($events) > 0) { - ?> -
-
Events:
-
- \n"; - echo "" . $h->getName() . " on " . date($SETTINGS["datetime_format"], strtotime($h->getDate())) . "
\n"; - if (!empty($h->getPublicNotes())) { - echo "
Notes:
" . htmlspecialchars($h->getPublicNotes()) . "
"; - } - echo "\n
\n"; - } - ?> -
-
- getComponents(); - - if (count($components) > 0) { - ?> -
-
Components:
-
- -
- - getTypeName(); ?>
- getModel())) { - ?> - get("Model"); ?>: getModel()); ?>
- getCapacity())) { - ?> - get("Capacity"); ?>: getCapacity()); ?>
- getEvents(); + $events = []; + foreach ($history as $h) { + $events[] = $h; + } + if (count($events) > 0) { + $eventshtml = '
+
Events:
+
'; + foreach ($history as $h) { + $eventshtml .= '
' + . $h->toHTML(true) + . '
'; + } + $eventshtml .= '
'; + } - if (!empty($c->getSerial())) { - ?> - get("Serial"); ?>: getSerial()); ?>
- getTestedDate())) { - ?> - get("Tested On"); ?>: getTestedDate())); ?>
- getComponents(); - if (!empty($c->getPrice())) { - ?> - get("Price"); ?>: $getPrice(), 2); ?>
- 0) { + $componentshtml = '
Components:
'; + foreach ($components as $c) { + $componentshtml .= '
' + . $c->toHTML(true) + . '
'; + } + $componentshtml .= '
'; + } - if (!empty($c->getManufacturer())) { - ?> - get("Manufacturer"); ?>: getManufacturer()); ?>
-
' + . $machine->toHTMLListGroup(true) + . '
' + . $eventshtml + . $componentshtml + . "
", + getSearchBox(true) + ]; - if (!empty($c->getPublicNotes())) { - ?> -
- Notes:
-
getPublicNotes()); ?>
-
- -
- -
-
- -
- - -
-

- Look up another device: -

-
- " required /> - -
-
- - - getIcon() . '"> ' . $machine->getTypeLabel() . ' Info', $body); + } } ?>