From 05e85db3a7e2c501676f3c50e3304525e13006e5 Mon Sep 17 00:00:00 2001 From: Thomas Hooge Date: Wed, 15 Mar 2023 07:43:46 +0100 Subject: [PATCH] Fixed and improved subnet add/edit --- subnet.php | 31 +++++++++++++++++-------------- tpl/subnetadd.tpl | 19 +++++++++++++++++-- tpl/subnetedit.tpl | 37 ++++++++++++++++++++++++++++++++++--- 3 files changed, 68 insertions(+), 19 deletions(-) diff --git a/subnet.php b/subnet.php index 741d9d6..9e61111 100644 --- a/subnet.php +++ b/subnet.php @@ -102,19 +102,21 @@ switch ($submit = form_get_action()) { $info = sanitize($_POST['subnet_info']); $dhcp_start = sanitize($_POST['dhcp_start']); $dhcp_end = sanitize($_POST['dhcp_end']); + $ntp_server = sanitize($_POST['ntp_server']); $sql = "INSERT INTO subnet ( subnet_address, subnet_mask, subnet_info, - subnet_dhcp_start, subnet_dhcp_end + subnet_dhcp_start, subnet_dhcp_end, ntp_server ) VALUES ( :address, :mask, :info, - :dhcp_start, :dhcp_end + :dhcp_start, :dhcp_end, :ntp_server )"; $sth = $dbh->prepare($sql); $sth->bindValue(':address', $address, PDO::PARAM_STR); $sth->bindValue(':mask', $mask, PDO::PARAM_INT); - $sth->bindValue(':info', $info, PDO::PARAM_STR); $sth->bindValue(':dhcp_start', $dhcp_start, PDO::PARAM_STR); $sth->bindValue(':dhcp_end', $dhcp_end, PDO::PARAM_STR); + $sth->bindValue(':ntp_server', $ntp_server, PDO::PARAM_STR); + $sth->bindValue(':info', $info, PDO::PARAM_STR); $sth->execute(); $id = $dbh->lastInsertId(); // vlan if selected @@ -128,13 +130,13 @@ switch ($submit = form_get_action()) { break; case 'update': - $subnet_address= sanitize($_POST['subnet_address']); - $subnet_proto_vers = sanitize($_POST['subnet_proto_vers']); - $subnet_mask = sanitize($_POST['subnet_mask']); - $subnet_dhcpstart = sanitize($_POST['subnet_dhcpstart']); - $subnet_dhcpend = sanitize($_POST['subnet_dhcpend']); - $subnet_ntp_server = sanitize($_POST['subnet_ntp_server']); - $subnet_info = sanitize($_POST['subnet_info']); + $address= sanitize($_POST['subnet_address']); + $proto_vers = sanitize($_POST['subnet_proto_vers']); + $mask = sanitize($_POST['subnet_mask']); + $dhcp_start = sanitize($_POST['dhcp_start']); + $dhcp_end = sanitize($_POST['dhcp_end']); + $ntp_server = sanitize($_POST['ntp_server']); + $info = sanitize($_POST['subnet_info']); $sql = "UPDATE subnet SET subnet_address=?, subnet_mask=?, subnet_dhcp_start=?, @@ -142,9 +144,9 @@ switch ($submit = form_get_action()) { ntp_server=? WHERE subnet_id=?"; $sth = $dbh->prepare($sql); - $sth->execute([$subnet_address, $subnet_mask, $subnet_dhcpstart, - $subnet_dhcpend, $subnet_info, $subnet_proto_vers, - $subnet_ntp_server, $id]); + $sth->execute([$address, $mask, $dhcp_start, + $dhcp_end, $info, $proto_vers, + $ntp_server, $id]); $action = ACT_VIEW; break; @@ -176,6 +178,7 @@ switch ($submit = form_get_action()) { $g_error->Add(submit_error($submit)); $valid = FALSE; } +$smarty->assign("action", $action); // ========== ACTIONS END ===================================================== @@ -205,7 +208,7 @@ if((isset($_GET['vlan_id'])) ? $vlan_id = sanitize($_GET['vlan_id']) : $vlan_id $smarty->assign("vlan_id", $vlan_id); $smarty->assign("vlan_options", db_get_options_vlan($lang['lang_option_none'])); -$smarty->display("subnetadd.tpl"); +$smarty->display("subnetedit.tpl"); elseif ($action == ACT_VIEW): // ========== VARIANT: view single record ===================================== diff --git a/tpl/subnetadd.tpl b/tpl/subnetadd.tpl index 0a2bb79..09905a3 100644 --- a/tpl/subnetadd.tpl +++ b/tpl/subnetadd.tpl @@ -37,16 +37,31 @@  (8-30) + + + {$lang_proto_vers} + + + + + {$lang_subnet_dhcp} - - - + - + + + NTP Server + + + + + {$lang_subnet_info} diff --git a/tpl/subnetedit.tpl b/tpl/subnetedit.tpl index ca63cbe..abb9673 100644 --- a/tpl/subnetedit.tpl +++ b/tpl/subnetedit.tpl @@ -1,15 +1,25 @@
+{if $action eq constant('ACT_EDIT')} +{/if}
+{if $action eq constant('ACT_ADD')} + {$lang_subnet_add} +{else} {$lang_subnet_edit} : {$subnet->address}/{$subnet->mask} +{/if} {$lang_cancel} - +{if $action eq constant('ACT_ADD')} + +{else} + +{/if}
@@ -28,7 +38,7 @@ {$lang_subnet_subnetaddress} - + @@ -36,7 +46,7 @@ {$lang_subnet_mask} - +  (8-30) @@ -81,4 +91,25 @@ +{if $action eq constant('ACT_ADD')} + + + + + + + + + +
+ {$lang_vlan} + +   +
+ {$lang_vlan} + + {html_options name=vlan_id options=$vlan_options} +
+{/if} +