You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

158 lines
5.5 KiB
PHP

<?php
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
?>
<div class="container mt-4">
<div class="d-flex justify-content-center">
<div class="card">
<img class="card-img-top p-4 mx-auto" style="max-width: 100%; width: 400px;" src="<?php echo LOGO_URL; ?>" alt="<?php echo LOGO_ALT; ?>" />
<div class="card-body py-0">
<h5>
Machine #<?php echo htmlspecialchars($_GET['serial']); ?>
</h5>
</div>
<div class="card-body">
<div class="row">
<?php
require_once __DIR__ . "/../machine.php";
try {
$machine = new Machine($_GET['serial']);
$info = $machine->getMachineInfo();
if (count($info) > 0) {
?>
<div class="col-sm-6 mb-3">
<h6>Machine Info:</h6>
<div class="list-group">
<?php
foreach ($info as $key => $val) {
if (empty($val)) {
continue;
}
$echo = "";
switch ($key) {
case "model":
$echo = "Model: " . htmlspecialchars($val);
break;
case "condition":
$filled = floor($val);
$echo = "Condition: ";
$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> ";
}
break;
case "price":
$echo = "Est. Value: $" . number_format($val * 1.0, 2);
break;
case "os":
$echo = "Operating System: " . htmlspecialchars($val);
break;
case "serial":
$echo = "Serial: " . htmlspecialchars($val);
break;
case "manufacturer":
$echo = "OEM: " . htmlspecialchars($val);
break;
case "notes":
$echo = "<div>" . htmlspecialchars($val) . "</div>";
break;
}
if ($echo != "") {
echo "<div class=\"list-group-item\">\n$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) {
echo "<div class=\"list-group-item\">\n";
echo "<b>$c[type]</b><br />\n";
echo "Serial: $c[serial]<br />\n";
if (!empty($c['tested'])) {
echo "Tested on: " . date(DATETIME_FORMAT, strtotime($c['tested'])) . "<br />\n";
}
if (!empty($c['capacity'])) {
echo "Capacity: $c[capacity]<br />\n";
}
if (!empty($c['model'])) {
echo "Model: $c[model]<br />\n";
}
if (!empty($h['notes'])) {
echo "<div>" . htmlspecialchars($h['notes']) . "</div>";
}
echo "\n</div>\n";
}
?>
</div>
</div>
<?php
}
$history = $machine->getHistory();
if (count($history) > 0) {
?>
<div class="col-sm-6 mb-3">
<h6>History:</h6>
<div class="list-group">
<?php
foreach ($history as $h) {
echo "<div class=\"list-group-item\">\n";
echo "<b>$h[eventname]</b> on " . date(DATETIME_FORMAT, strtotime($h['date'])) . "<br />\n";
if (!empty($h['notes'])) {
echo "<div>" . htmlspecialchars($h['notes']) . "</div>";
}
echo "\n</div>\n";
}
?>
</div>
</div>
<?php
}
} catch (Exception $ex) {
echo "<div class=\"col\"><p class=\"text-danger\">" . $ex->getMessage() . "</p></div>";
}
?>
</div>
</div>
<div class="card-body">
<p>Look up another machine:</p>
<form method="GET">
<input type="hidden" name="page" value="info" />
<input type="text" name="serial" class="form-control" placeholder="Machine ID Number" required />
<button type="submit" class="btn btn-primary btn-block mt-2">Get PC Info</button>
</form>
</div>
</div>
</div>
</div>