summaryrefslogtreecommitdiffstats
path: root/modules-available/locations/pages/subnets.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2019-09-09 15:01:30 +0200
committerSimon Rettberg2019-09-09 15:01:30 +0200
commitff6778736478ac0622762b1599e5192ad89bc139 (patch)
tree1aed13e3e3a886bd979bda0780a28c60801e5886 /modules-available/locations/pages/subnets.inc.php
parent[dnbd3] Update translations (diff)
downloadslx-admin-ff6778736478ac0622762b1599e5192ad89bc139.tar.gz
slx-admin-ff6778736478ac0622762b1599e5192ad89bc139.tar.xz
slx-admin-ff6778736478ac0622762b1599e5192ad89bc139.zip
[locations] trim() subnet address fields, both empty == delete
Closes #3550
Diffstat (limited to 'modules-available/locations/pages/subnets.inc.php')
-rw-r--r--modules-available/locations/pages/subnets.inc.php20
1 files changed, 16 insertions, 4 deletions
diff --git a/modules-available/locations/pages/subnets.inc.php b/modules-available/locations/pages/subnets.inc.php
index 381023d2..fb1e1e80 100644
--- a/modules-available/locations/pages/subnets.inc.php
+++ b/modules-available/locations/pages/subnets.inc.php
@@ -15,7 +15,8 @@ class SubPage
private static function updateSubnets()
{
User::assertPermission('subnets.edit', NULL, '?do=locations');
- $count = 0;
+ $editCount = 0;
+ $deleteCount = 0;
$starts = Request::post('startaddr', false);
$ends = Request::post('endaddr', false);
$locs = Request::post('location', false);
@@ -29,7 +30,13 @@ class SubPage
if (!isset($ends[$subnetid]) || !isset($locs[$subnetid]))
continue;
$loc = (int)$locs[$subnetid];
- $end = $ends[$subnetid];
+ $start = trim($start);
+ $end = trim($ends[$subnetid]);
+ if (empty($start) && empty($end)) {
+ $ret = Database::exec('DELETE FROM subnet WHERE subnetid = :subnetid', compact('subnetid'));
+ $deleteCount += $ret;
+ continue;
+ }
if (!isset($existingLocs[$loc])) {
Message::addError('main.value-invalid', 'locationid', $loc);
continue;
@@ -39,11 +46,16 @@ class SubPage
continue;
list($startLong, $endLong) = $range;
if ($stmt->execute(compact('startLong', 'endLong', 'loc', 'subnetid'))) {
- $count += $stmt->rowCount();
+ $editCount += $stmt->rowCount();
}
}
AutoLocation::rebuildAll();
- Message::addSuccess('subnets-updated', $count);
+ if ($editCount > 0) {
+ Message::addSuccess('subnets-updated', $editCount);
+ }
+ if ($deleteCount > 0) {
+ Message::addSuccess('subnets-deleted', $deleteCount);
+ }
Util::redirect('?do=Locations');
}