You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
3.2 KiB
PHP
85 lines
3.2 KiB
PHP
<?php
|
|
|
|
/*
|
|
* 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/.
|
|
*/
|
|
|
|
redirectIfNotLoggedIn();
|
|
$user = new User($_SESSION['uid']);
|
|
if (!$user->hasPermission("MACHINEMANAGER_EDIT")) {
|
|
header("Location: ./app.php?msg=no_permission");
|
|
die();
|
|
}
|
|
|
|
$editing = false;
|
|
|
|
if (!empty($VARS["arg"]) && Component::exists($VARS["arg"])) {
|
|
$editing = true;
|
|
$component = new Component($VARS["arg"]);
|
|
$machine = new Machine($component->getMachineID());
|
|
} else if (!empty($VARS["id"]) && Component::exists($VARS["id"])) {
|
|
$editing = true;
|
|
$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();
|
|
$component->setMachineID($machine->getID());
|
|
}
|
|
|
|
if ($editing) {
|
|
$form = new FormBuilder("Edit Component #" . $component->getID(), "fas fa-memory", "action.php", "POST");
|
|
} else {
|
|
$form = new FormBuilder("Add Component", "fas fa-memory", "action.php", "POST");
|
|
}
|
|
|
|
$form->setID("editmachine");
|
|
|
|
$form->addHiddenInput("action", "editcomponent");
|
|
$form->addHiddenInput("source", "viewmachine");
|
|
|
|
$types = [
|
|
"" => ""
|
|
];
|
|
foreach (Component::getTypes() as $k => $v) {
|
|
$types[$k] = $v;
|
|
}
|
|
|
|
if ($editing) {
|
|
$form->addHiddenInput("id", $component->getID());
|
|
} else {
|
|
$form->addInput("id", $component->getID(), "text", true, null, null, "Component ID", "fas fa-memory", 4, 1, 20);
|
|
}
|
|
|
|
$form->addHiddenInput("machine", $machine->getID());
|
|
|
|
$date = date('Y-m-d');
|
|
$time = date('H:i');
|
|
if (!empty($component->getTestedDate())) {
|
|
$date = date("Y-m-d", strtotime($component->getTestedDate()));
|
|
$time = date("H:i:s", strtotime($component->getTestedDate()));
|
|
}
|
|
$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", true, null, null, "Tested Date", "fas fa-calendar");
|
|
$form->addInput("time", $time, "time", true, null, null, "Tested Time", "fas fa-clock");
|
|
$form->addInput("capacity", $component->getCapacity(), "text", false, null, null, "Capacity", "fas fa-database", 4, 0, 200);
|
|
$form->addInput("model", $component->getModel(), "text", false, null, null, "Model", "fas fa-hashtag", 4, 0, 200);
|
|
$form->addInput("price", $component->getPrice(), "number", false, null, null, "Price", "fas fa-money-bill-wave");
|
|
$form->addInput("privatenotes", $component->getPrivateNotes(), "textarea", false, null, null, "Private Notes", "fas fa-comment-dots");
|
|
$form->addInput("publicnotes", $component->getPublicNotes(), "textarea", false, null, null, "Public Notes", "far fa-comment-dots");
|
|
|
|
$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");
|
|
|
|
$form->generate();
|