Add automatic event on machine creation for easier sorting, add deletemachine action
This commit is contained in:
parent
f3429366c9
commit
9c96652c6a
12
action.php
12
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")) {
|
||||
|
BIN
database.mwb
BIN
database.mwb
Binary file not shown.
@ -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."
|
||||
}
|
||||
|
@ -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"
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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'];
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
?>
|
||||
|
@ -150,7 +150,9 @@ $machine = new Machine($machineid);
|
||||
foreach ($history as $h) {
|
||||
echo "<div class=\"list-group-item\">\n";
|
||||
echo "<b>" . $h->getName() . "</b> on " . date($SETTINGS["datetime_format"], strtotime($h->getDate())) . "<br />\n";
|
||||
echo "<b>Technician:</b> " . htmlspecialchars((new User($h->getTechUID()))->getName()) . "<br />\n";
|
||||
if (!empty($h->getTechUID())) {
|
||||
echo "<b>Technician:</b> " . htmlspecialchars((new User($h->getTechUID()))->getName()) . "<br />\n";
|
||||
}
|
||||
if (!empty($h->getPublicNotes())) {
|
||||
echo "<div><b>Public Notes:</b><br /><div class=\"ml-3\">" . str_replace("\n", "\n<br>", htmlspecialchars($h->getPublicNotes())) . "</div></div>";
|
||||
}
|
||||
|
@ -276,8 +276,12 @@ if (isset($_GET["backgroundcolor"]) && !empty($_GET["backgroundcolor"]) && preg_
|
||||
|
||||
<?php
|
||||
$history = $machine->getEvents();
|
||||
$events = [];
|
||||
foreach ($history as $h) {
|
||||
$events[] = $h;
|
||||
}
|
||||
|
||||
if (count($history) > 0) {
|
||||
if (count($events) > 0) {
|
||||
?>
|
||||
<div class="col-sm-6 mb-3">
|
||||
<h6>Events:</h6>
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user