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 "
\n"; echo "" . $h->getName() . " on " . date($SETTINGS["datetime_format"], strtotime($h->getDate())) . "
\n"; - echo "Technician: " . htmlspecialchars((new User($h->getTechUID()))->getName()) . "
\n"; + if (!empty($h->getTechUID())) { + echo "Technician: " . htmlspecialchars((new User($h->getTechUID()))->getName()) . "
\n"; + } if (!empty($h->getPublicNotes())) { echo "
Public Notes:
" . str_replace("\n", "\n
", htmlspecialchars($h->getPublicNotes())) . "
"; } diff --git a/public/index.php b/public/index.php index 9cda17e..5d81521 100644 --- a/public/index.php +++ b/public/index.php @@ -276,8 +276,12 @@ if (isset($_GET["backgroundcolor"]) && !empty($_GET["backgroundcolor"]) && preg_ getEvents(); + $events = []; + foreach ($history as $h) { + $events[] = $h; + } - if (count($history) > 0) { + if (count($events) > 0) { ?>
Events:
diff --git a/update.sql b/update.sql index e279c5d..001adcc 100644 --- a/update.sql +++ b/update.sql @@ -186,6 +186,12 @@ ADD CONSTRAINT `fk_machines_machine_types1` ON UPDATE NO ACTION; +INSERT INTO `event_types` (`eventid`,`eventname`) VALUES (99, 'Device ID Generated'); + +ALTER TABLE `machines` +ADD COLUMN `deleted` TINYINT(1) NOT NULL DEFAULT 0 AFTER `publicnotes`; + + SET SQL_MODE=@OLD_SQL_MODE; SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;