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", false, null, null, "Tested Date", "fas fa-calendar"); $form->addInput("time", $time, "time", false, 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("manufacturer", $component->getManufacturer(), "text", false, null, null, "Manufacturer", "fas fa-industry", 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", 6, 0, 10000); $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"); $form->generate();