diff --git a/action.php b/action.php index d90214e..0b4d549 100644 --- a/action.php +++ b/action.php @@ -72,13 +72,15 @@ switch ($VARS['action']) { die(); } - if (!Machine::exists($VARS['machine'])) { - returnToSender("invalid_parameters"); - } - $component = new Component($VARS['id']); - $component->setMachineID($VARS['machine']); + if (!empty($VARS["machine"])) { + if (!Machine::exists($VARS['machine'])) { + returnToSender("invalid_parameters"); + } + $component->setMachineID($VARS['machine']); + } + $component->setSerial($VARS['serial']); $component->setTypeID($VARS['type']); if (!empty($VARS['date'])) { diff --git a/database.mwb b/database.mwb index 5e7e03b..4553fc8 100644 Binary files a/database.mwb and b/database.mwb differ diff --git a/langs/en/actions.json b/langs/en/actions.json index 5007c91..0bc9f01 100644 --- a/langs/en/actions.json +++ b/langs/en/actions.json @@ -8,5 +8,7 @@ "Add Client": "Add Client", "Print": "Print", "Print Labels": "Print Labels", - "Go to machine": "Go to machine" + "Go to machine": "Go to machine", + "Attach": "Attach", + "Attach Existing": "Attach Existing" } diff --git a/langs/en/labels.json b/langs/en/labels.json index 04fb2c3..1742298 100644 --- a/langs/en/labels.json +++ b/langs/en/labels.json @@ -2,5 +2,7 @@ "Public Notes": "Public Notes", "Private Notes": "Private Notes", "Machine ID": "Machine ID", - "Back": "Back" + "Back": "Back", + "Components": "Components" + } \ No newline at end of file diff --git a/pages.php b/pages.php index a7c7280..cea53cd 100644 --- a/pages.php +++ b/pages.php @@ -25,6 +25,19 @@ define("PAGES", [ "static/js/machines.js" ] ], + "components" => [ + "title" => "Components", + "navbar" => true, + "icon" => "fas fa-memory", + "styles" => [ + "static/css/datatables.min.css", + "static/css/tables.css" + ], + "scripts" => [ + "static/js/datatables.min.js", + "static/js/components.js" + ] + ], "clients" => [ "title" => "Clients", "navbar" => (empty($SETTINGS['apis']['invoiceninja']['token']) ? true : false), diff --git a/pages/components.php b/pages/components.php new file mode 100644 index 0000000..20b91fe --- /dev/null +++ b/pages/components.php @@ -0,0 +1,90 @@ +hasPermission("MACHINEMANAGER_VIEW")) { + header("Location: ./app.php?msg=no_permission"); + die(); +} + +$writeaccess = $user->hasPermission("MACHINEMANAGER_EDIT"); + +$components = $database->select("components", ["compid", "serial", "machineid", "model", "manufacturer", "capacity"]); + +$attachto = false; +if (!empty($VARS["attachto"]) && Machine::exists($VARS["attachto"])) { + $attachto = $VARS["attachto"]; +} +?> + +
+ + get("Add Component"); ?> + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
get('Actions'); ?> get('ID'); ?> get('Machine ID'); ?> get('Model'); ?> get('Serial'); ?> get('Capacity'); ?>
+ + get("Attach"); ?> + + get("Edit"); ?> + + + +
get('Actions'); ?> get('ID'); ?> get('Client'); ?> get('OS/Software'); ?> get('Model'); ?> get('Last Event'); ?> get('Serial'); ?>
\ No newline at end of file diff --git a/pages/editcomponent.php b/pages/editcomponent.php index 81762da..13e4516 100644 --- a/pages/editcomponent.php +++ b/pages/editcomponent.php @@ -24,15 +24,12 @@ if (!empty($VARS["arg"]) && Component::exists($VARS["arg"])) { $component = new Component($VARS["id"]); $machine = new Machine($component->getMachineID()); } else { - if (!empty($VARS['machine']) && Machine::exists($VARS['machine'])) { - $machine = new Machine($VARS['machine']); - } else { - header("Location: ./app.php?msg=invalid_parameters"); - die(); - } - - $editing = false; $component = Component::create(); + $editing = false; +} + +if (!empty($VARS['machine']) && Machine::exists($VARS['machine'])) { + $machine = new Machine($VARS['machine']); $component->setMachineID($machine->getID()); } @@ -45,7 +42,6 @@ if ($editing) { $form->setID("editmachine"); $form->addHiddenInput("action", "editcomponent"); -$form->addHiddenInput("source", "viewmachine"); $types = [ "" => "" @@ -60,7 +56,11 @@ if ($editing) { $form->addInput("id", $component->getID(), "text", true, null, null, "Component ID", "fas fa-memory", 4, 1, 20); } -$form->addHiddenInput("machine", $machine->getID()); +if (!is_null($machine)) { + $form->addHiddenInput("source", "viewmachine"); +} else { + $form->addHiddenInput("source", "components"); +} $date = date('Y-m-d'); $time = date('H:i'); @@ -68,6 +68,7 @@ if (!empty($component->getTestedDate())) { $date = date("Y-m-d", strtotime($component->getTestedDate())); $time = date("H:i:s", strtotime($component->getTestedDate())); } +$form->addInput("machine", (is_null($machine) ? "" : $machine->getID()), "text", false, null, null, "Machine ID", "fas fa-desktop", 4, 0, 200); $form->addInput("serial", $component->getSerial(), "text", false, null, null, "Serial", "fas fa-barcode", 4, 0, 200); $form->addInput("type", $component->getTypeID(), "select", false, null, $types, "Type", "fas fa-list"); $form->addInput("date", $date, "date", false, null, null, "Tested Date", "fas fa-calendar"); @@ -80,6 +81,10 @@ $form->addInput("privatenotes", $component->getPrivateNotes(), "textarea", false $form->addInput("publicnotes", $component->getPublicNotes(), "textarea", false, null, null, "Public Notes", "far fa-comment-dots", 6, 0, 10000); $form->addButton("Save", "fas fa-save", null, "submit", "savebtn"); -$form->addButton("Back", "fas fa-arrow-left", "./app.php?page=viewmachine&id=" . $machine->getID(), "", null, null, "", "btn btn-info ml-2"); +if (!is_null($machine)) { + $form->addButton("Back", "fas fa-arrow-left", "./app.php?page=viewmachine&id=" . $machine->getID(), "", null, null, "", "btn btn-info ml-2"); +} else { + $form->addButton("Back", "fas fa-arrow-left", "./app.php?page=components", "", null, null, "", "btn btn-info ml-2"); +} $form->generate(); diff --git a/pages/viewmachine.php b/pages/viewmachine.php index 5177422..219aa36 100644 --- a/pages/viewmachine.php +++ b/pages/viewmachine.php @@ -33,7 +33,15 @@ $machine = new Machine($machineid);
get("Edit"); ?> get("Add Event"); ?> - get("Add Component"); ?> +
+ get("Add Component"); ?> + + +
get("Print Labels"); ?> get("Back"); ?>
diff --git a/static/js/components.js b/static/js/components.js new file mode 100644 index 0000000..9d56774 --- /dev/null +++ b/static/js/components.js @@ -0,0 +1,34 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +$('#componenttable').DataTable({ + responsive: { + details: { + display: $.fn.dataTable.Responsive.display.modal({ + header: function (row) { + var data = row.data(); + return " " + data[2]; + } + }), + renderer: $.fn.dataTable.Responsive.renderer.tableAll({ + tableClass: 'table' + }), + type: "column" + } + }, + columnDefs: [ + { + targets: 0, + className: 'control', + orderable: false + }, + { + targets: 1, + orderable: false + } + ], + order: [ + [6, 'desc'] + ] +}); \ No newline at end of file diff --git a/update.sql b/update.sql index 001adcc..d4f173f 100644 --- a/update.sql +++ b/update.sql @@ -195,3 +195,35 @@ 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; + + +-- MySQL Workbench Synchronization +-- Generated: 2020-07-15 18:11 +-- Model: New Model +-- Version: 1.0 +-- Project: Name of the project +-- Author: Skylar Ittner + +SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; +SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; +SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES'; + +ALTER TABLE `machinemanager`.`components` +DROP FOREIGN KEY `fk_components_machines1`; + +ALTER TABLE `machinemanager`.`components` +CHANGE COLUMN `machineid` `machineid` VARCHAR(20) NULL DEFAULT NULL , +DROP PRIMARY KEY, +ADD PRIMARY KEY (`compid`); + +ALTER TABLE `machinemanager`.`components` +ADD CONSTRAINT `fk_components_machines1` + FOREIGN KEY (`machineid`) + REFERENCES `machinemanager`.`machines` (`machineid`) + ON DELETE NO ACTION + ON UPDATE NO ACTION; + + +SET SQL_MODE=@OLD_SQL_MODE; +SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; +SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;