Add('Invalid action: '. $_POST['action']); } break; case 'exec-sadd': $subnet_id = sanitize($_POST['subnet_id']); $sql = "INSERT INTO subnetvlan (subnet_id, vlan_id) VALUES (?, ?)"; $sth = $dbh->prepare($sql); $sth->execute([$subnet_id, $id]); $action = ACT_VIEW; break; case 'exec-sdel': $subnet_id = sanitize($_POST['subnet_id']); $sth = $dbh->prepare("DELETE FROM subnetvlan WHERE subnet_id=? AND vlan_id=?"); $sth->execute([$subnet_id, $id]); $g_message->Add('Removed link to subnet'); $action = ACT_VIEW; break; case 'insert': $vlan_name = sanitize($_POST['vlan_name']); $vlan_number = sanitize($_POST['vlan_number']); $vlan_info = sanitize($_POST['vlan_info']); $vlan_color = sanitize($_POST['vlan_color']); $sql = "INSERT INTO vlan (vlan_name, vlan_number, vlan_color, vlan_info) VALUES (?, ?, ?, ?)"; $sth = $dbh->prepare($sql); $sth->execute([$vlan_name, $vlan_number, $vlan_color, $vlan_info]); $id = $dbh->lastInsertId(); $action = ACT_VIEW; break; case 'update': $vlan_name = sanitize($_POST['vlan_name']); $vlan_number = sanitize($_POST['vlan_number']); $vlan_info = sanitize($_POST['vlan_info']); $vlan_color = sanitize($_POST['vlan_color']); $sql = "UPDATE vlan SET vlan_name=?, vlan_number=?, vlan_color=?, vlan_info=? WHERE vlan_id=?"; $sth = $dbh->prepare($sql); $sth->execute([$vlan_name, $vlan_number, $vlan_color, $vlan_info, $id]); $action = ACT_VIEW; break; case 'delete': $sth = $dbh->prepare("DELETE FROM vlan WHERE vlan_id=?"); $sth->execute([$id]); $g_message->Add(_("VLAN deleted.")); $action = ACT_DEFAULT; break; default: $g_error->Add(submit_error($submit)); $valid = FALSE; } // ========== ACTIONS END ===================================================== $smarty->assign("scripts", 'jscolor.js'); include("header.php"); if ($action == ACT_DEFAULT): // ========== VARIANT: default behavior ======================================= $sql = "SELECT vlan_id AS id, vlan_number AS number, vlan_name AS name, vlan_color AS color, LEFT(vlan_info, 60) AS info FROM vlan ORDER BY vlan_number"; $sth = $dbh->query($sql); $smarty->assign("vlans", $sth->fetchAll()); $smarty->display("vlan.tpl"); elseif ($action == ACT_ADD): // ========== VARIANT: add record ============================================= $smarty->display("vlanadd.tpl"); elseif ($action == ACT_VIEW): // ========== VARIANT: view single record ===================================== // vlan $sql = "SELECT vlan_id AS id, vlan_name AS name, vlan_number AS number, vlan_info AS info, vlan_color AS color FROM vlan WHERE vlan_id=?"; $sth = $dbh->prepare($sql); $sth->execute([$id]); $smarty->assign("vlan", $sth->fetch(PDO::FETCH_OBJ)); // subnets $sql = "SELECT s.subnet_id, s.subnet_address, s.subnet_mask, s.subnet_info FROM subnet AS s LEFT JOIN subnetvlan AS v USING (subnet_id) WHERE v.vlan_id=? ORDER BY INET_ATON(s.subnet_address)"; $sth = $dbh->prepare($sql); $sth->execute([$id]); $smarty->assign("subnets", $sth->fetchAll()); $smarty->display("vlanview.tpl"); elseif ($action == ACT_EDIT): // ========== VARIANT: edit single record ===================================== $sql = "SELECT vlan_id AS id, vlan_name AS name, vlan_number AS number, vlan_color AS color, vlan_info AS info FROM vlan WHERE vlan_id=?"; $sth = $dbh->prepare($sql); $sth->execute([$id]); $smarty->assign("vlan", $sth->fetch(PDO::FETCH_OBJ)); $smarty->display("vlanedit.tpl"); elseif ($action == ACT_DELETE): // ========== VARIANT: delete record ========================================== $sql = "SELECT vlan_id AS id, vlan_name AS name, vlan_number AS number FROM vlan WHERE vlan_id=?"; $sth = $dbh->prepare($sql); $sth->execute([$id]); $smarty->assign("vlan", $sth->fetch(PDO::FETCH_OBJ)); $smarty->display("vlandel.tpl"); elseif ($action == ACT_SUBNET_EDIT): // ========== VARIANT: subnet to vlan ========================================= $sql = "SELECT vlan_id AS id, vlan_name AS name, vlan_number AS number FROM vlan WHERE vlan_id=?"; $sth = $dbh->prepare($sql); $sth->execute([$id]); $smarty->assign("vlan", $sth->fetch(PDO::FETCH_OBJ)); $smarty->display("vlansubnetedit.tpl"); elseif ($action == ACT_SUBNET_ADD): // ========== VARIANT: subnet to vlan ========================================= $sql = "SELECT vlan_id AS id, vlan_name AS name, vlan_number AS number FROM vlan WHERE vlan_id=?"; $sth = $dbh->prepare($sql); $sth->execute([$id]); $smarty->assign("vlan", $sth->fetch(PDO::FETCH_OBJ)); // possible subnets to add to vlan // - exclude already assingned subnets from selection $sql = "SELECT subnet_id, subnet_address, subnet_mask FROM subnet WHERE subnet_id NOT IN (SELECT subnet_id FROM subnetvlan WHERE vlan_id=?) ORDER BY INET_ATON(subnet_address)"; $sth = $dbh->prepare($sql); $sth->execute([$id]); $subnets = $sth->fetchAll(); foreach ($subnets as $subnet) { $subnet_options[$subnet['subnet_id']] = $subnet['subnet_address'].'/'.$subnet['subnet_mask']; } $smarty->assign("subnet_options", $subnet_options); $smarty->display("vlansubnetadd.tpl"); elseif ($action == ACT_SUBNET_DEL): // ========== VARIANT: subnet to vlan ========================================= $sql = "SELECT vlan_id AS id, vlan_name AS name, vlan_number AS number FROM vlan WHERE vlan_id=?"; $sth = $dbh->prepare($sql); $sth->execute([$id]); $smarty->assign("vlan", $sth->fetch(PDO::FETCH_OBJ)); // TODO only linked subnets! $smarty->assign("subnet_options", db_get_options_subnet()); $smarty->display("vlansubnetdel.tpl"); else: // ========== ERROR UNKNOWN VARIANT =========================================== echo "
Unknown function call: Please report to system development!
\n"; endif; // $action == ... // ========== END OF VARIANTS ================================================= $smarty->display('footer.tpl');