diff --git a/action.php b/action.php index 122dddf..9f79d52 100644 --- a/action.php +++ b/action.php @@ -39,6 +39,7 @@ switch ($VARS['action']) { $machine = new Machine($VARS['id']); + $machine->setType($VARS["type"]); $machine->setModel($VARS['model']); $machine->setClientID($VARS['client']); $machine->setOS($VARS['os']); diff --git a/database.mwb b/database.mwb index d1bf12b..ba250e8 100644 Binary files a/database.mwb and b/database.mwb differ diff --git a/langs/en/titles.json b/langs/en/titles.json index fc170dd..65dbb15 100644 --- a/langs/en/titles.json +++ b/langs/en/titles.json @@ -4,5 +4,6 @@ "Machines": "Machines", "Clients": "Clients", "Machine Info": "Machine Info", + "Device Info": "Device Info", "Tracking Info": "Tracking Info" } diff --git a/lib/Client.lib.php b/lib/Client.lib.php index be98587..3e552e7 100644 --- a/lib/Client.lib.php +++ b/lib/Client.lib.php @@ -150,7 +150,7 @@ class Client implements JsonSerializable { } if ($this->exists) { - $client = NinjaClient::find($id); + $client = NinjaClient::find($this->id); $client->name = $this->getName(); } else { $client = new NinjaClient($this->getEmail(), '', '', $this->getName()); diff --git a/lib/Machine.lib.php b/lib/Machine.lib.php index 826de86..3eb0073 100644 --- a/lib/Machine.lib.php +++ b/lib/Machine.lib.php @@ -7,6 +7,9 @@ class Machine implements JsonSerializable { private $machineid = ""; + private $icon = "fas fa-desktop"; + private $typeid = 14; + private $typelabel = "Machine"; private $machine = []; private $events = []; private $components = []; @@ -17,7 +20,11 @@ class Machine implements JsonSerializable { $this->machineid = $machineid; if (Machine::exists($machineid)) { $this->exists = true; - $this->machine = $database->get('machines', ['model', 'condition', 'price', 'os', 'serial', 'manufacturer', 'clientid', 'privatenotes', 'publicnotes'], ['machineid' => $machineid]); + $this->machine = $database->get('machines', ['type', 'model', 'condition', 'price', 'os', 'serial', 'manufacturer', 'clientid', 'privatenotes', 'publicnotes'], ['machineid' => $machineid]); + $typeinfo = $database->get("machine_types", ["machinetypeid (id)", "typename (label)", "icon"], ["machinetypeid" => $this->machine["type"]]); + $this->icon = $typeinfo["icon"]; + $this->typeid = $typeinfo["id"]; + $this->typelabel = $typeinfo["label"]; $events = $database->select('events', 'historyid', ['machineid' => $machineid, "ORDER" => ["date" => "DESC"]]); foreach ($events as $e) { $this->events[] = new Event($e); @@ -35,6 +42,11 @@ class Machine implements JsonSerializable { return [ "status" => "OK", "id" => $this->machineid, + "icon" => $this->icon, + "type" => [ + "id" => $this->typeid, + "label" => $this->typelabel + ], "info" => $this->machine, "events" => $this->events, "components" => $this->components, @@ -132,6 +144,18 @@ class Machine implements JsonSerializable { return ""; } + public function getType(): int { + return $this->typeid; + } + + public function getTypeLabel(): string { + return $this->typelabel; + } + + public function getIcon(): string { + return $this->icon; + } + public function getModel(): string { if (!empty($this->machine["model"])) { return $this->machine["model"]; @@ -196,6 +220,16 @@ class Machine implements JsonSerializable { $this->machine["clientid"] = $id; } + public function setType(int $typeid) { + global $database; + $this->typeid = $typeid; + $this->machine["type"] = $typeid; + + $typeinfo = $database->get("machine_types", ["machinetypeid (id)", "typename (label)", "icon"], ["machinetypeid" => $typeid]); + $this->icon = $typeinfo["icon"]; + $this->typelabel = $typeinfo["label"]; + } + public function setModel(string $model) { $this->machine["model"] = $model; } diff --git a/pages/editmachine.php b/pages/editmachine.php index 5a180b7..6274e59 100644 --- a/pages/editmachine.php +++ b/pages/editmachine.php @@ -23,7 +23,7 @@ if (!empty($_GET['arg']) && Machine::exists($_GET['arg'])) { } if ($editing) { - $form = new FormBuilder("Edit Machine #" . $machine->getID(), "fas fa-desktop", "action.php", "POST"); + $form = new FormBuilder("Edit " . $machine->getTypeLabel() . " #" . $machine->getID(), "fas fa-desktop", "action.php", "POST"); } else { $form = new FormBuilder("Add Machine", "fas fa-desktop", "action.php", "POST"); } @@ -39,12 +39,19 @@ $clients = [ foreach (Clients::getAll() as $c) { $clients[$c->getID()] = $c->getName(); } +$typelist = [ + "" => "" +]; +foreach ($database->select("machine_types", ["machinetypeid (id)", "typename (name)"]) as $t) { + $typelist[$t["id"]] = $t["name"]; +} if ($editing) { $form->addHiddenInput("id", $machine->getID()); } else { $form->addInput("id", $machine->getID(), "text", true, null, null, "Machine ID", "fas fa-desktop", 4, 1, 20); } +$form->addInput("type", $machine->getType(), "select", true, null, $typelist, "Machine Type", "fas fa-desktop"); $form->addInput("client", $machine->getClientID(), "select", false, null, $clients, "Client", "fas fa-user"); $form->addInput("model", $machine->getModel(), "text", false, null, null, "Model", "fas fa-hashtag", 4, 0, 200); $form->addInput("os", $machine->getOS(), "text", false, null, null, "OS/Software", "fas fa-hdd", 4, 0, 200); diff --git a/pages/printlabel.php b/pages/printlabel.php index 74e5863..f07b65b 100644 --- a/pages/printlabel.php +++ b/pages/printlabel.php @@ -45,7 +45,7 @@ $pdfurl = "./print/print.php?labeltype=$labeltype&id=$machineid";
No machine with ID could be found.
No device with ID could be found.
- Look up another machine: + Look up another device: