diff --git a/action.php b/action.php index 9f79d52..d90214e 100644 --- a/action.php +++ b/action.php @@ -53,6 +53,18 @@ switch ($VARS['action']) { $machine->save(); returnToSender("machine_saved", $machine->getID()); + case "deletemachine": + $user = new User($_SESSION['uid']); + if (!$user->hasPermission("MACHINEMANAGER_DELETE")) { + returnToSender("no_permission"); + die(); + } + + $machine = new Machine($VARS['id']); + $machine->setDeleted(true); + $machine->save(); + + returnToSender("machine_deleted"); case "editcomponent": $user = new User($_SESSION['uid']); if (!$user->hasPermission("MACHINEMANAGER_EDIT")) { diff --git a/database.mwb b/database.mwb index 71c7d85..5e7e03b 100644 Binary files a/database.mwb and b/database.mwb differ diff --git a/langs/en/messages.json b/langs/en/messages.json index d34aeaf..17aa86e 100644 --- a/langs/en/messages.json +++ b/langs/en/messages.json @@ -4,5 +4,6 @@ "Event logged!": "Event logged!", "Client saved!": "Client saved!", "Client must be edited in Invoice Ninja.": "Client must be edited in Invoice Ninja.", - "That ID does not exist in the system.": "That ID does not exist in the system." + "That ID does not exist in the system.": "That ID does not exist in the system.", + "Machine deleted.": "Machine deleted." } diff --git a/langs/messages.php b/langs/messages.php index 0563225..7180d06 100644 --- a/langs/messages.php +++ b/langs/messages.php @@ -41,6 +41,10 @@ define("MESSAGES", [ "string" => "Client must be edited in Invoice Ninja.", "type" => "danger" ], + "machine_deleted" => [ + "string" => "Machine deleted.", + "type" => "success" + ], "404_error" => [ "string" => "page not found", "type" => "info" diff --git a/lib/Machine.lib.php b/lib/Machine.lib.php index f4f8e5d..0183c2b 100644 --- a/lib/Machine.lib.php +++ b/lib/Machine.lib.php @@ -20,7 +20,7 @@ class Machine implements JsonSerializable { $this->machineid = $machineid; if (Machine::exists($machineid)) { $this->exists = true; - $this->machine = $database->get('machines', ['type [Int]', 'model', 'condition [Number]', 'price [Number]', 'os', 'serial', 'manufacturer', 'clientid [Int]', 'privatenotes', 'publicnotes'], ['machineid' => $machineid]); + $this->machine = $database->get('machines', ['type [Int]', 'model', 'condition [Number]', 'price [Number]', 'os', 'serial', 'manufacturer', 'clientid [Int]', 'privatenotes', 'publicnotes', 'deleted [Bool]'], ['machineid' => $machineid]); $typeinfo = $database->get("machine_types", ["machinetypeid (id) [Int]", "typename (label)", "icon"], ["machinetypeid" => $this->machine["type"]]); $this->icon = $typeinfo["icon"]; $this->typeid = $typeinfo["id"]; @@ -130,6 +130,8 @@ class Machine implements JsonSerializable { $data["machineid"] = $this->machineid; $database->insert("machines", $data); $this->exists = true; + // Insert event for machine creation + Event::create($data["machineid"], date("Y-m-d H:i:s"), 99); } } @@ -273,6 +275,14 @@ class Machine implements JsonSerializable { return $this->components; } + public function setDeleted(bool $deleted = true) { + $this->machine["deleted"] = $deleted; + } + + public function isDeleted(): bool { + return $this->machine["deleted"] == true; + } + public function addEvent(string $date, int $event, string $techuid = "", string $publicnotes = "", string $privatenotes = "") { $evt = Event::create($this->machineid, $date, $event, $techuid, $publicnotes, $privatenotes); diff --git a/pages/addevent.php b/pages/addevent.php index 7dad845..e2d5818 100644 --- a/pages/addevent.php +++ b/pages/addevent.php @@ -31,6 +31,10 @@ $form->addHiddenInput("machine", htmlspecialchars($_GET['id'])); $events = $database->select("event_types", ['eventid', 'eventname']); $eventselect = ["" => ""]; foreach ($events as $e) { + // Skip automatic-only/internal events + if ($e['eventid'] > 99) { + continue; + } $eventselect[$e['eventid']] = $e['eventname']; } diff --git a/pages/machines.php b/pages/machines.php index d746bb3..288320c 100644 --- a/pages/machines.php +++ b/pages/machines.php @@ -19,11 +19,11 @@ $machines = $database->query("SELECT machines.machineid, machines.clientid, mach FROM machines LEFT OUTER JOIN events ON events.machineid = machines.machineid LEFT OUTER JOIN event_types ON event_types.eventid = events.eventid -WHERE date=(SELECT MAX(s2.date) +WHERE (date=(SELECT MAX(s2.date) FROM events s2 WHERE machines.machineid = s2.machineid ) -OR NOT EXISTS (SELECT * FROM events WHERE events.machineid = machines.machineid)")->fetchAll(); +OR NOT EXISTS (SELECT * FROM events WHERE events.machineid = machines.machineid)) AND deleted = 0")->fetchAll(); $clients = Clients::getAll(); ?> diff --git a/pages/viewmachine.php b/pages/viewmachine.php index 07daea4..5177422 100644 --- a/pages/viewmachine.php +++ b/pages/viewmachine.php @@ -150,7 +150,9 @@ $machine = new Machine($machineid); foreach ($history as $h) { echo "