diff --git a/action.php b/action.php index 0b4d549..97d9e62 100644 --- a/action.php +++ b/action.php @@ -101,6 +101,9 @@ switch ($VARS['action']) { $component->save(); + if (empty($VARS["machine"])) { + returnToSender("component_saved"); + } returnToSender("component_saved", $component->getMachineID()); case "addevent": $user = new User($_SESSION['uid']); diff --git a/pages/editcomponent.php b/pages/editcomponent.php index 68a1075..e005a94 100644 --- a/pages/editcomponent.php +++ b/pages/editcomponent.php @@ -20,16 +20,18 @@ $machine = null; 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 { $component = Component::create(); $editing = false; } +if ($editing && !empty($component->getMachineID())) { + $machine = new Machine($component->getMachineID()); +} + if (!empty($VARS['machine']) && Machine::exists($VARS['machine'])) { $machine = new Machine($VARS['machine']); $component->setMachineID($machine->getID()); @@ -41,7 +43,7 @@ if ($editing) { $form = new FormBuilder("Add Component", "fas fa-memory", "action.php", "POST"); } -$form->setID("editmachine"); +$form->setID("editcomponent"); $form->addHiddenInput("action", "editcomponent"); @@ -58,7 +60,7 @@ if ($editing) { $form->addInput("id", $component->getID(), "text", true, null, null, "Component ID", "fas fa-memory", 4, 1, 20); } -if (!is_null($machine)) { +if (!empty($machine)) { $form->addHiddenInput("source", "viewmachine"); } else { $form->addHiddenInput("source", "components");