Allow lookup by serial number
This commit is contained in:
parent
a39f28b445
commit
2cf5183f14
@ -35,6 +35,31 @@ class Machine {
|
|||||||
return $database->has('machines', ['machineid' => $id]);
|
return $database->has('machines', ['machineid' => $id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a given serial number can identify exactly one machine.
|
||||||
|
* @global $database $database
|
||||||
|
* @param type $serial
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function serialExists(string $serial): bool {
|
||||||
|
global $database;
|
||||||
|
return $database->has('machines', ['serial' => $serial]) && $database->count('machines', ['serial' => $serial]) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a serial into a machine ID.
|
||||||
|
* @global $database $database
|
||||||
|
* @param string $serial
|
||||||
|
* @return string|bool machine ID if found, otherwise false.
|
||||||
|
*/
|
||||||
|
public static function getIDFromSerial(string $serial) {
|
||||||
|
global $database;
|
||||||
|
if (Machine::serialExists($serial)) {
|
||||||
|
return $database->get('machines', 'machineid', ['serial' => $serial]) . "";
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public function save() {
|
public function save() {
|
||||||
global $database;
|
global $database;
|
||||||
if ($this->exists) {
|
if ($this->exists) {
|
||||||
|
@ -23,7 +23,7 @@ require_once __DIR__ . "/../lib/required_public.php";
|
|||||||
<div class="row justify-content-center">
|
<div class="row justify-content-center">
|
||||||
<div class="col-12 col-md-8">
|
<div class="col-12 col-md-8">
|
||||||
<?php
|
<?php
|
||||||
if (empty($_GET["id"]) || !Machine::exists($_GET["id"])) {
|
if (empty($_GET["id"]) || (!Machine::exists($_GET["id"]) && !Machine::serialExists($_GET["id"]))) {
|
||||||
?>
|
?>
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<h3 class="card-header d-flex">
|
<h3 class="card-header d-flex">
|
||||||
@ -33,7 +33,7 @@ require_once __DIR__ . "/../lib/required_public.php";
|
|||||||
</h3>
|
</h3>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<?php
|
<?php
|
||||||
if (!empty($_GET["id"]) && !Machine::exists($_GET["id"])) {
|
if (!empty($_GET["id"])) {
|
||||||
?>
|
?>
|
||||||
<p class="text-danger">No machine with ID <code><?php echo htmlspecialchars($_GET['id']); ?></code> could be found.</p>
|
<p class="text-danger">No machine with ID <code><?php echo htmlspecialchars($_GET['id']); ?></code> could be found.</p>
|
||||||
<?php
|
<?php
|
||||||
@ -50,7 +50,11 @@ require_once __DIR__ . "/../lib/required_public.php";
|
|||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
} else {
|
} else {
|
||||||
|
if (Machine::exists($_GET["id"])) {
|
||||||
$machine = new Machine($_GET['id']);
|
$machine = new Machine($_GET['id']);
|
||||||
|
} else {
|
||||||
|
$machine = new Machine(Machine::getIDFromSerial($_GET['id']));
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<h3 class="card-header d-flex">
|
<h3 class="card-header d-flex">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user