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']);
$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 =====================================

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

@ -1,15 +1,25 @@
<form method="POST" action="subnet.php">
{if $action eq constant('ACT_EDIT')}
<input type="hidden" name="id" value="{$subnet->id}">
{/if}
<table class="title">
<tr>
<td class="header">
<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}
{/if}
</td>
<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>
<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>
</tr>
</table>
@ -28,7 +38,7 @@
{$lang_subnet_subnetaddress}
</td>
<td class="value">
<input type="text" name="subnet_address" value="{$subnet->address}">
<input type="text" name="subnet_address" value="{$subnet->address}" autofocus>
</td>
</tr>
<tr>
@ -36,7 +46,7 @@
{$lang_subnet_mask}
</td>
<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>
</tr>
<tr>
@ -81,4 +91,25 @@
</tr>
</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>