Fixed and improved subnet add/edit

master
Thomas Hooge 2 years ago
parent 303c22160d
commit 05e85db3a7
  1. 31
      subnet.php
  2. 19
      tpl/subnetadd.tpl
  3. 37
      tpl/subnetedit.tpl

@ -102,19 +102,21 @@ switch ($submit = form_get_action()) {
$info = sanitize($_POST['subnet_info']); $info = sanitize($_POST['subnet_info']);
$dhcp_start = sanitize($_POST['dhcp_start']); $dhcp_start = sanitize($_POST['dhcp_start']);
$dhcp_end = sanitize($_POST['dhcp_end']); $dhcp_end = sanitize($_POST['dhcp_end']);
$ntp_server = sanitize($_POST['ntp_server']);
$sql = "INSERT INTO subnet ( $sql = "INSERT INTO subnet (
subnet_address, subnet_mask, subnet_info, subnet_address, subnet_mask, subnet_info,
subnet_dhcp_start, subnet_dhcp_end subnet_dhcp_start, subnet_dhcp_end, ntp_server
) VALUES ( ) VALUES (
:address, :mask, :info, :address, :mask, :info,
:dhcp_start, :dhcp_end :dhcp_start, :dhcp_end, :ntp_server
)"; )";
$sth = $dbh->prepare($sql); $sth = $dbh->prepare($sql);
$sth->bindValue(':address', $address, PDO::PARAM_STR); $sth->bindValue(':address', $address, PDO::PARAM_STR);
$sth->bindValue(':mask', $mask, PDO::PARAM_INT); $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_start', $dhcp_start, PDO::PARAM_STR);
$sth->bindValue(':dhcp_end', $dhcp_end, 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(); $sth->execute();
$id = $dbh->lastInsertId(); $id = $dbh->lastInsertId();
// vlan if selected // vlan if selected
@ -128,13 +130,13 @@ switch ($submit = form_get_action()) {
break; break;
case 'update': case 'update':
$subnet_address= sanitize($_POST['subnet_address']); $address= sanitize($_POST['subnet_address']);
$subnet_proto_vers = sanitize($_POST['subnet_proto_vers']); $proto_vers = sanitize($_POST['subnet_proto_vers']);
$subnet_mask = sanitize($_POST['subnet_mask']); $mask = sanitize($_POST['subnet_mask']);
$subnet_dhcpstart = sanitize($_POST['subnet_dhcpstart']); $dhcp_start = sanitize($_POST['dhcp_start']);
$subnet_dhcpend = sanitize($_POST['subnet_dhcpend']); $dhcp_end = sanitize($_POST['dhcp_end']);
$subnet_ntp_server = sanitize($_POST['subnet_ntp_server']); $ntp_server = sanitize($_POST['ntp_server']);
$subnet_info = sanitize($_POST['subnet_info']); $info = sanitize($_POST['subnet_info']);
$sql = "UPDATE subnet SET $sql = "UPDATE subnet SET
subnet_address=?, subnet_mask=?, subnet_dhcp_start=?, subnet_address=?, subnet_mask=?, subnet_dhcp_start=?,
@ -142,9 +144,9 @@ switch ($submit = form_get_action()) {
ntp_server=? ntp_server=?
WHERE subnet_id=?"; WHERE subnet_id=?";
$sth = $dbh->prepare($sql); $sth = $dbh->prepare($sql);
$sth->execute([$subnet_address, $subnet_mask, $subnet_dhcpstart, $sth->execute([$address, $mask, $dhcp_start,
$subnet_dhcpend, $subnet_info, $subnet_proto_vers, $dhcp_end, $info, $proto_vers,
$subnet_ntp_server, $id]); $ntp_server, $id]);
$action = ACT_VIEW; $action = ACT_VIEW;
break; break;
@ -176,6 +178,7 @@ switch ($submit = form_get_action()) {
$g_error->Add(submit_error($submit)); $g_error->Add(submit_error($submit));
$valid = FALSE; $valid = FALSE;
} }
$smarty->assign("action", $action);
// ========== ACTIONS END ===================================================== // ========== 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_id", $vlan_id);
$smarty->assign("vlan_options", db_get_options_vlan($lang['lang_option_none'])); $smarty->assign("vlan_options", db_get_options_vlan($lang['lang_option_none']));
$smarty->display("subnetadd.tpl"); $smarty->display("subnetedit.tpl");
elseif ($action == ACT_VIEW): elseif ($action == ACT_VIEW):
// ========== VARIANT: view single record ===================================== // ========== VARIANT: view single record =====================================

@ -37,16 +37,31 @@
<input type="text" name="subnet_mask" size="2">&nbsp;(8-30) <input type="text" name="subnet_mask" size="2">&nbsp;(8-30)
</td> </td>
</tr> </tr>
<tr>
<td class="label">
{$lang_proto_vers}
</td>
<td class="value">
<input type="text" name="subnet_proto_vers" size="2">
</td>
</tr>
<tr> <tr>
<td class="label"> <td class="label">
{$lang_subnet_dhcp} {$lang_subnet_dhcp}
</td> </td>
<td class="value"> <td class="value">
<input type="text" name="subnet_dhcp_start"> - <input type="text" name="subnet_dhcp_start" size="15"> -
<input type="text" name="subnet_dhcp_end"> <input type="text" name="subnet_dhcp_end" size="15">
</td> </td>
</tr> </tr>
<tr> <tr>
<td class="label">
NTP Server
</td>
<td class="value">
<input type="text" name="ntp_server" size="45">
</td>
</tr><tr>
<td class="label"> <td class="label">
{$lang_subnet_info} {$lang_subnet_info}
</td> </td>

@ -1,15 +1,25 @@
<form method="POST" action="subnet.php"> <form method="POST" action="subnet.php">
{if $action eq constant('ACT_EDIT')}
<input type="hidden" name="id" value="{$subnet->id}"> <input type="hidden" name="id" value="{$subnet->id}">
{/if}
<table class="title"> <table class="title">
<tr> <tr>
<td class="header"> <td class="header">
<img class="icon" src="images/plugin.png" alt="" /> <img class="icon" src="images/plugin.png" alt="" />
{if $action eq constant('ACT_ADD')}
{$lang_subnet_add}
{else}
{$lang_subnet_edit} : {$subnet->address}/{$subnet->mask} {$lang_subnet_edit} : {$subnet->address}/{$subnet->mask}
{/if}
</td> </td>
<td align="right"> <td align="right">
<a href="#" onClick="history.go(-1)"><img src="images/rewind.png" alt="{$lang_cancel}"{if $suser_tooltips} title="{$lang_cancel}"{/if}></a> <a href="#" onClick="history.go(-1)"><img src="images/rewind.png" alt="{$lang_cancel}"{if $suser_tooltips} title="{$lang_cancel}"{/if}></a>
<input type="image" src="images/save.png" alt="{$lang_submit}"{if $suser_tooltips} title="{$lang_submit}"{/if}> {if $action eq constant('ACT_ADD')}
<input type="image" name="submit[insert]" src="images/save.png" alt="{$lang_submit}"{if $suser_tooltips} title="{$lang_submit}"{/if}>
{else}
<input type="image" name="submit[update]" src="images/save.png" alt="{$lang_submit}"{if $suser_tooltips} title="{$lang_submit}"{/if}>
{/if}
</td> </td>
</tr> </tr>
</table> </table>
@ -28,7 +38,7 @@
{$lang_subnet_subnetaddress} {$lang_subnet_subnetaddress}
</td> </td>
<td class="value"> <td class="value">
<input type="text" name="subnet_address" value="{$subnet->address}"> <input type="text" name="subnet_address" value="{$subnet->address}" autofocus>
</td> </td>
</tr> </tr>
<tr> <tr>
@ -36,7 +46,7 @@
{$lang_subnet_mask} {$lang_subnet_mask}
</td> </td>
<td class="value"> <td class="value">
<input type="text" name="subnet_mask" size="2" value="{$subnet->mask}"> <input type="text" name="subnet_mask" size="2" value="{$subnet->mask}">&nbsp;(8-30)
</td> </td>
</tr> </tr>
<tr> <tr>
@ -81,4 +91,25 @@
</tr> </tr>
</table> </table>
{if $action eq constant('ACT_ADD')}
<table class="info">
<tr>
<td class="header">
{$lang_vlan}
</td>
<td class="header_right">
&nbsp;
</td>
</tr>
<tr>
<td class="label">
{$lang_vlan}
</td>
<td class="value">
{html_options name=vlan_id options=$vlan_options}
</td>
</tr>
</table>
{/if}
</form> </form>