diff --git a/web/includes/actions/function.php b/web/includes/actions/function.php index 00e4e21f7..adf85de38 100644 --- a/web/includes/actions/function.php +++ b/web/includes/actions/function.php @@ -31,20 +31,21 @@ if ( !canEdit('Monitors', $mid) ) { } if ( $action == 'function' ) { - $monitor = dbFetchOne('SELECT * FROM Monitors WHERE Id=?', NULL, array($mid)); + $monitor = new ZM\Monitor($mid); + if ( !$monitor ) { + ZM\Error("Monitor not found with Id=$mid"); + return; + } $newFunction = validStr($_REQUEST['newFunction']); # Because we use a checkbox, it won't get passed in the request. So not being in _REQUEST means 0 $newEnabled = ( !isset($_REQUEST['newEnabled']) or $_REQUEST['newEnabled'] != '1' ) ? '0' : '1'; - $oldFunction = $monitor['Function']; - $oldEnabled = $monitor['Enabled']; + $oldFunction = $monitor->Function(); + $oldEnabled = $monitor->Enabled(); if ( $newFunction != $oldFunction || $newEnabled != $oldEnabled ) { - dbQuery('UPDATE Monitors SET `Function`=?, `Enabled`=? WHERE `Id`=?', - array($newFunction, $newEnabled, $mid)); + $monitor->save(array('Function'=>$newFunction, 'Enabled'=>$newEnabled)); - $monitor['Function'] = $newFunction; - $monitor['Enabled'] = $newEnabled; - if ( daemonCheck() && ($monitor['Type'] != 'WebSite') ) { + if ( daemonCheck() && ($monitor->Type() != 'WebSite') ) { zmaControl($monitor, 'stop'); zmcControl($monitor, ($newFunction != 'None') ? 'restart' : 'stop'); if ( $newFunction != 'None' && $newFunction != 'NoDect' )