just another cleanup commit, don't mind me...

git-svn-id: http://www.observium.org/svn/observer/trunk@1885 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Tom Laermans
2011-03-16 18:28:52 +00:00
parent 372ada594e
commit 2afb522333
15 changed files with 215 additions and 197 deletions
+45 -36
View File
@@ -1,49 +1,58 @@
<?php
# enable/disable ports/interfaces on devices.
#
$device_id=intval($_POST['device']);
$device_id = intval($_POST['device']);
$rows_updated = 0;
foreach ($_POST as $key => $val) {
if (strncmp($key,"oldval_",7) == 0) {
foreach ($_POST as $key => $val)
{
if (strncmp($key,"oldval_",7) == 0)
{
# Interface identifier passed as part of the field name
# Interface identifier passed as part of the field name
#
$interface_id = intval(substr($key,7));
$interface_id = intval(substr($key,7));
$oldval = intval($val) ? 1 : 0;
$newval = $_POST['ignore_'.$interface_id] ? 1 : 0;
$oldval = intval($val) ? 1 : 0;
$newval = $_POST['ignore_'.$interface_id] ? 1 : 0;
# As checkboxes are not posted when unset - we effectively need to do a diff to work
# out a set->unset case.
#
if ($oldval == $newval)
continue;
if (!mysql_query('UPDATE `ports` SET `ignore`='.$newval.' WHERE `device_id`='.$device_id.' AND `interface_id`='.$interface_id))
$n = -1;
else
$n = mysql_affected_rows();
# As checkboxes are not posted when unset - we effectively need to do a diff to work
# out a set->unset case.
if ($n <0) {
$rows_updated = -1;
break;
};
$rows_updated += $n;
};
};
if ($oldval == $newval)
{
continue;
}
if (!mysql_query('UPDATE `ports` SET `ignore`='.$newval.' WHERE `device_id`='.$device_id.' AND `interface_id`='.$interface_id))
{
$n = -1;
}
else
{
$n = mysql_affected_rows();
}
if($rows_updated > 0) {
$update_message = $rows_updated . " Device record updated.";
$updated = 1;
} elseif ($rows_updated = '-1') {
$update_message = "Device record unchanged. No update necessary.";
$updated = -1;
} else {
$update_message = "Device record update error.";
$updated = 0;
if ($n <0)
{
$rows_updated = -1;
break;
}
$rows_updated += $n;
}
}
?>
if ($rows_updated > 0)
{
$update_message = $rows_updated . " Device record updated.";
$updated = 1;
} elseif ($rows_updated = '-1') {
$update_message = "Device record unchanged. No update necessary.";
$updated = -1;
} else {
$update_message = "Device record update error.";
$updated = 0;
}
?>