From eb2269ea52b2b6320aae9f7db3f966dad1f2ee3e Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Tue, 29 Oct 2019 17:42:23 -0400 Subject: [PATCH] improve zone saving testing for value before doing math --- web/includes/actions/zone.php | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/web/includes/actions/zone.php b/web/includes/actions/zone.php index b42aa4318..c0e4eabbb 100644 --- a/web/includes/actions/zone.php +++ b/web/includes/actions/zone.php @@ -21,7 +21,7 @@ // Monitor edit actions, require a monitor id and edit permissions for that monitor if ( !empty($_REQUEST['mid']) && canEdit('Monitors', $_REQUEST['mid']) ) { $mid = validInt($_REQUEST['mid']); - if ( $action == 'zone' && isset($_REQUEST['zid']) ) { + if ( ($action == 'zone') && isset($_REQUEST['zid']) ) { $zid = validInt($_REQUEST['zid']); $monitor = new ZM\Monitor($mid); @@ -32,17 +32,15 @@ if ( !empty($_REQUEST['mid']) && canEdit('Monitors', $_REQUEST['mid']) ) { } if ( $_REQUEST['newZone']['Units'] == 'Percent' ) { - $_REQUEST['newZone']['MinAlarmPixels'] = intval(($_REQUEST['newZone']['MinAlarmPixels']*$_REQUEST['newZone']['Area'])/100); - $_REQUEST['newZone']['MaxAlarmPixels'] = intval(($_REQUEST['newZone']['MaxAlarmPixels']*$_REQUEST['newZone']['Area'])/100); - if ( isset($_REQUEST['newZone']['MinFilterPixels']) ) - $_REQUEST['newZone']['MinFilterPixels'] = intval(($_REQUEST['newZone']['MinFilterPixels']*$_REQUEST['newZone']['Area'])/100); - if ( isset($_REQUEST['newZone']['MaxFilterPixels']) ) - $_REQUEST['newZone']['MaxFilterPixels'] = intval(($_REQUEST['newZone']['MaxFilterPixels']*$_REQUEST['newZone']['Area'])/100); - if ( isset($_REQUEST['newZone']['MinBlobPixels']) ) - $_REQUEST['newZone']['MinBlobPixels'] = intval(($_REQUEST['newZone']['MinBlobPixels']*$_REQUEST['newZone']['Area'])/100); - if ( isset($_REQUEST['newZone']['MaxBlobPixels']) ) - $_REQUEST['newZone']['MaxBlobPixels'] = intval(($_REQUEST['newZone']['MaxBlobPixels']*$_REQUEST['newZone']['Area'])/100); - } + foreach (array( + 'MinAlarmPixels','MaxAlarmPixels', + 'MinFilterPixels','MaxFilterPixels', + 'MinBlobPixels','MaxBlobPixels' + ) as $field ) { + if ( isset($_REQUEST['newZone'][$field]) and $_REQUEST['newZone'][$field] ) + $_REQUEST['newZone'][$field] = intval(($_REQUEST['newZone'][$field]*$_REQUEST['newZone']['Area'])/100); + } + } unset($_REQUEST['newZone']['Points']);