From b52f0b0eb3810fa6718d15b4e7b1a3a73e6759a9 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Fri, 26 Jun 2020 21:09:21 -0600 Subject: [PATCH] Calculate check digit for machine/component ID, warn public users of typos --- lib/CheckDigit.lib.php | 48 ++++++++++++++++++++++++++++++++++++++++++ lib/Component.lib.php | 9 ++++++-- lib/Machine.lib.php | 9 ++++++-- public/index.php | 31 ++++++++++++++++++++++++++- 4 files changed, 92 insertions(+), 5 deletions(-) create mode 100644 lib/CheckDigit.lib.php diff --git a/lib/CheckDigit.lib.php b/lib/CheckDigit.lib.php new file mode 100644 index 0000000..b30d515 --- /dev/null +++ b/lib/CheckDigit.lib.php @@ -0,0 +1,48 @@ += 68100000 && $id <= 68199999) { + $id = ("$id" . CheckDigit::S10($id)) * 1; + } } while ($database->has('components', ['compid' => $id]) || $database->has('machines', ['machineid' => $id])); return $id; diff --git a/lib/Machine.lib.php b/lib/Machine.lib.php index 35e6e9b..9cc1296 100644 --- a/lib/Machine.lib.php +++ b/lib/Machine.lib.php @@ -281,17 +281,22 @@ class Machine implements JsonSerializable { /** * Generate a random ID number that is not in use. - * Default: 680[1-3]###### + * Default: 680#####[check digit] * @global $database * @param int $min Optional minimum number. * @param int $max Optional maximum number. * @return int */ - public static function generateId(int $min = 680100000, int $max = 680399999): int { + public static function generateId(int $min = 68010000, int $max = 68099999): int { global $database; do { $id = random_int($min, $max); + + // If default gen add check digit + if ($id >= 68010000 && $id <= 68039999) { + $id = ("$id" . CheckDigit::S10($id)) * 1; + } } while ($database->has('machines', ['machineid' => $id]) || $database->has('components', ['compid' => $id])); return $id; diff --git a/public/index.php b/public/index.php index 47e7538..dca2225 100644 --- a/public/index.php +++ b/public/index.php @@ -36,7 +36,36 @@ if (isset($_GET["backgroundcolor"]) && !empty($_GET["backgroundcolor"]) && preg_
col-12 col-md-8col-12"> +
+

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

+
+ +

is not valid. Please try re-typing it.

+ + +

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

+
+ + +
+ +
+
+