diff --git a/web/includes/Filter.php b/web/includes/Filter.php index 3835b0ccb..fa7c41bff 100644 --- a/web/includes/Filter.php +++ b/web/includes/Filter.php @@ -167,6 +167,7 @@ class Filter extends ZM_Object { } # end if local or remote } # end foreach erver } # end function control + public function execute() { $command = ZM_PATH_BIN.'/zmfilter.pl --filter_id='.escapeshellarg($this->Id()); $result = exec($command, $output, $status); diff --git a/web/includes/Frame.php b/web/includes/Frame.php index 470cc8ffc..f472a38e6 100644 --- a/web/includes/Frame.php +++ b/web/includes/Frame.php @@ -1,33 +1,19 @@ $v) { - $this->{$k} = $v; - } - } else { - Error("No row for Frame " . $IdOrRow ); - } - } # end if isset($IdOrRow) - } // end function __construct + public static function find( $parameters = array(), $options = array() ) { + return ZM_Object::_find(get_class(), $parameters, $options); + } + + public static function find_one( $parameters = array(), $options = array() ) { + return ZM_Object::_find_one(get_class(), $parameters, $options); + } public function Storage() { return $this->Event()->Storage(); @@ -36,66 +22,11 @@ class Frame { public function Event() { return new Event( $this->{'EventId'} ); } - public function __call( $fn, array $args){ - if ( count( $args ) ) { - $this->{$fn} = $args[0]; - } - if ( array_key_exists( $fn, $this ) ) { - return $this->{$fn}; - - $backTrace = debug_backtrace(); - $file = $backTrace[1]['file']; - $line = $backTrace[1]['line']; - Warning( "Unknown function call Frame->$fn from $file:$line" ); - } - } public function getImageSrc( $show='capture' ) { return '?view=image&fid='.$this->{'FrameId'}.'&eid='.$this->{'EventId'}.'&show='.$show; #return '?view=image&fid='.$this->{'Id'}.'&show='.$show.'&filename='.$this->Event()->MonitorId().'_'.$this->{'EventId'}.'_'.$this->{'FrameId'}.'.jpg'; } // end function getImageSrc - public static function find( $parameters = array(), $options = NULL ) { - $sql = 'SELECT * FROM Frames'; - $values = array(); - if ( sizeof($parameters) ) { - $sql .= ' WHERE ' . implode( ' AND ', array_map( - function($v){ return $v.'=?'; }, - array_keys( $parameters ) - ) ); - $values = array_values( $parameters ); - } - if ( $options ) { - if ( isset($options['order']) ) { - $sql .= ' ORDER BY ' . $options['order']; - } - if ( isset($options['limit']) ) { - if ( is_integer($options['limit']) or ctype_digit($options['limit']) ) { - $sql .= ' LIMIT ' . $options['limit']; - } else { - $backTrace = debug_backtrace(); - $file = $backTrace[1]['file']; - $line = $backTrace[1]['line']; - Error("Invalid value for limit(".$options['limit'].") passed to Frame::find from $file:$line"); - return array(); - } - } - } - - $results = dbFetchAll($sql, NULL, $values); - if ( $results ) { - return array_map( function($id){ return new Frame($id); }, $results ); - } - return array(); - } - - public static function find_one( $parameters = array(), $options = null ) { - $options['limit'] = 1; - $results = Frame::find($parameters, $options); - if ( ! sizeof($results) ) { - return; - } - return $results[0]; - } -} # end class +} # end class Frame ?> diff --git a/web/includes/Server.php b/web/includes/Server.php index 2f9d038a9..f4d2fa3cd 100644 --- a/web/includes/Server.php +++ b/web/includes/Server.php @@ -1,12 +1,13 @@ null, 'Name' => '', 'Protocol' => '', @@ -21,28 +22,12 @@ class Server { 'zmeventnotification' => 0, ); - public function __construct($IdOrRow = NULL) { - global $server_cache; - $row = NULL; - if ( $IdOrRow ) { - if ( is_integer($IdOrRow) or ctype_digit($IdOrRow) ) { - $row = dbFetchOne('SELECT * FROM Servers WHERE Id=?', NULL, array($IdOrRow)); - if ( !$row ) { - Error('Unable to load Server record for Id='.$IdOrRow); - } - } elseif ( is_array($IdOrRow) ) { - $row = $IdOrRow; - } - } # end if isset($IdOrRow) - if ( $row ) { - foreach ($row as $k => $v) { - $this->{$k} = $v; - } - $server_cache[$row['Id']] = $this; - } else { - # Set defaults - foreach ( $this->defaults as $k => $v ) $this->{$k} = $v; - } + public static function find( $parameters = array(), $options = array() ) { + return ZM_Object::_find(get_class(), $parameters, $options); + } + + public static function find_one( $parameters = array(), $options = array() ) { + return ZM_Object::_find_one(get_class(), $parameters, $options); } public function Hostname( $new = null ) { @@ -144,98 +129,5 @@ class Server { } return '/zm/api'; } - - public function __call($fn, array $args){ - if ( count($args) ) { - $this->{$fn} = $args[0]; - } - if ( array_key_exists($fn, $this) ) { - return $this->{$fn}; - } else { - if ( array_key_exists($fn, $this->defaults) ) { - return $this->defaults{$fn}; - } else { - $backTrace = debug_backtrace(); - $file = $backTrace[1]['file']; - $line = $backTrace[1]['line']; - Warning("Unknown function call Server->$fn from $file:$line"); - } - } - } - public static function find( $parameters = null, $options = null ) { - $filters = array(); - $sql = 'SELECT * FROM Servers '; - $values = array(); - - if ( $parameters ) { - $fields = array(); - $sql .= 'WHERE '; - foreach ( $parameters as $field => $value ) { - if ( $value == null ) { - $fields[] = $field.' IS NULL'; - } else if ( is_array( $value ) ) { - $func = function(){return '?';}; - $fields[] = $field.' IN ('.implode(',', array_map( $func, $value ) ). ')'; - $values += $value; - - } else { - $fields[] = $field.'=?'; - $values[] = $value; - } - } - $sql .= implode(' AND ', $fields ); - } - if ( $options ) { - if ( isset($options['order']) ) { - $sql .= ' ORDER BY ' . $options['order']; - } - if ( isset($options['limit']) ) { - if ( is_integer($options['limit']) or ctype_digit($options['limit']) ) { - $sql .= ' LIMIT ' . $options['limit']; - } else { - $backTrace = debug_backtrace(); - $file = $backTrace[1]['file']; - $line = $backTrace[1]['line']; - Error("Invalid value for limit(".$options['limit'].") passed to Server::find from $file:$line"); - return array(); - } - } - } - $results = dbFetchAll( $sql, NULL, $values ); - if ( $results ) { - return array_map(function($id){ return new Server($id); }, $results); - } - return array(); - } - - public static function find_one( $parameters = array() ) { - global $server_cache; - if ( - ( count($parameters) == 1 ) and - isset($parameters['Id']) and - isset($server_cache[$parameters['Id']]) ) { - return $server_cache[$parameters['Id']]; - } - $results = Server::find( $parameters, array('limit'=>1) ); - if ( ! sizeof($results) ) { - return; - } - return $results[0]; - } - - public function to_json() { - $json = array(); - foreach ($this->defaults as $key => $value) { - if ( is_callable(array($this, $key)) ) { - $json[$key] = $this->$key(); - } else if ( array_key_exists($key, $this) ) { - $json[$key] = $this->{$key}; - } else { - $json[$key] = $this->defaults{$key}; - } - } - return json_encode($json); - } - } # end class Server ?>