Refactored, no more redirects. Improved error messaging system
This commit is contained in:
93
vlan.php
93
vlan.php
@@ -13,6 +13,12 @@ if (isset($_REQUEST['id'])) {
|
||||
$id = (int) $_REQUEST['id'] or $id = 0;
|
||||
}
|
||||
|
||||
// ========== ADDITIONAL ACTION DEFINITIONS ===================================
|
||||
|
||||
define ('ACT_SUBNET_EDIT', 100);
|
||||
define ('ACT_SUBNET_ADD', 101);
|
||||
define ('ACT_SUBNET_DEL', 102);
|
||||
|
||||
// ========== ACTIONS START ===================================================
|
||||
switch ($submit = form_get_action()) {
|
||||
|
||||
@@ -23,6 +29,37 @@ switch ($submit = form_get_action()) {
|
||||
case 'edit': $action = ACT_EDIT; break;
|
||||
case 'del': $action = ACT_DELETE; break;
|
||||
|
||||
// Subnet
|
||||
case 'sedit': $action = ACT_SUBNET_EDIT; break;
|
||||
case 'sadd': $action = ACT_SUBNET_ADD; break;
|
||||
case 'sdel': $action = ACT_SUBNET_DEL; break;
|
||||
|
||||
case 'exec-sedit':
|
||||
if ($_POST['action'] == 'vlansubnetadd') {
|
||||
$action = ACT_SUBNET_ADD;
|
||||
} elseif ($_POST['action'] == 'vlansubnetdel') {
|
||||
$action = ACT_SUBNET_DEL;
|
||||
} else {
|
||||
$g_warning->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']);
|
||||
@@ -30,7 +67,7 @@ switch ($submit = form_get_action()) {
|
||||
$vlan_color = sanitize($_POST['vlan_color']);
|
||||
|
||||
$sql = "INSERT INTO vlan (vlan_name, vlan_number, vlan_color, vlan_info)
|
||||
VALUE (?, ?, ?, ?)";
|
||||
VALUES (?, ?, ?, ?)";
|
||||
$sth = $dbh->prepare($sql);
|
||||
$sth->execute([$vlan_name, $vlan_number, $vlan_color, $vlan_info]);
|
||||
|
||||
@@ -132,6 +169,60 @@ $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 ===========================================
|
||||
|
||||
|
||||
Reference in New Issue
Block a user