From dfdac2ed705cbceabc1c4c6a5e8616102fb4fb03 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 7 Sep 2018 16:31:11 -0400 Subject: [PATCH] make find and find_one functions consistent across Objects --- web/ajax/add_monitors.php | 4 +- web/ajax/log.php | 4 +- web/includes/Control.php | 33 ++++-- web/includes/Event.php | 21 +++- web/includes/Filter.php | 68 ++++++++++--- web/includes/Group.php | 71 ++++++++----- web/includes/Monitor.php | 43 ++++++-- web/includes/Server.php | 102 ++++++++----------- web/includes/Storage.php | 64 +++++++----- web/skins/classic/includes/functions.php | 4 +- web/skins/classic/views/_monitor_filters.php | 28 ++--- web/skins/classic/views/add_monitors.php | 14 +-- web/skins/classic/views/events.php | 78 ++++++++------ web/skins/classic/views/group.php | 27 ++--- web/skins/classic/views/groups.php | 20 ++-- web/skins/classic/views/monitors.php | 45 ++++---- web/skins/classic/views/options.php | 46 ++++----- 17 files changed, 402 insertions(+), 270 deletions(-) diff --git a/web/ajax/add_monitors.php b/web/ajax/add_monitors.php index c5664f06b..69ce0332f 100644 --- a/web/ajax/add_monitors.php +++ b/web/ajax/add_monitors.php @@ -93,7 +93,7 @@ Info("Testing connection to " . $url_bits['host'].':'.$port); foreach ( $available_streams as &$stream ) { # check for existence in db. $stream['url'] = unparse_url( $stream, array('path'=>'/','query'=>'action=stream') ); - $monitors = Monitor::find_all( array('Path'=>$stream['url']) ); + $monitors = Monitor::find( array('Path'=>$stream['url']) ); if ( count($monitors) ) { Info("Found monitors matching " . $stream['url'] ); $stream['Monitor'] = $monitors[0]; @@ -135,7 +135,7 @@ if ( canEdit( 'Monitors' ) ) { if ( 0 ) { // Shortcut test - $monitors = Monitor::find_all( array( 'Path'=>$_REQUEST['url'] ) ); + $monitors = Monitor::find( array('Path'=>$_REQUEST['url']) ); if ( count( $monitors ) ) { Info("Monitor found for " . $_REQUEST['url']); $url_bits['url'] = $_REQUEST['url']; diff --git a/web/ajax/log.php b/web/ajax/log.php index 375b53a05..59595d216 100644 --- a/web/ajax/log.php +++ b/web/ajax/log.php @@ -33,7 +33,7 @@ switch ( $_REQUEST['task'] ) { if ( !canView('System') ) ajaxError('Insufficient permissions to view log entries'); - $servers = Server::find_all(); + $servers = Server::find(); $servers_by_Id = array(); # There is probably a better way to do this. foreach ( $servers as $server ) { @@ -153,7 +153,7 @@ switch ( $_REQUEST['task'] ) { } $sortOrder = (isset($_POST['sortOrder']) and $_POST['sortOrder']) == 'asc' ? 'asc':'desc'; - $servers = Server::find_all(); + $servers = Server::find(); $servers_by_Id = array(); # There is probably a better way to do this. foreach ( $servers as $server ) { diff --git a/web/includes/Control.php b/web/includes/Control.php index 74beeca05..fcb35ac63 100644 --- a/web/includes/Control.php +++ b/web/includes/Control.php @@ -166,8 +166,7 @@ private $defaults = array( } } } - public static function find_all( $parameters = null, $options = null ) { - $filters = array(); + public static function find( $parameters = null, $options = null ) { $sql = 'SELECT * FROM Controls '; $values = array(); @@ -189,15 +188,37 @@ private $defaults = array( } $sql .= implode(' AND ', $fields ); } - if ( $options and isset($options['order']) ) { - $sql .= ' ORDER BY ' . $options['order']; + 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 ' . $limit; + } else { + $backTrace = debug_backtrace(); + $file = $backTrace[1]['file']; + $line = $backTrace[1]['line']; + Error("Invalid value for limit($limit) passed to Control::find from $file:$line"); + return; + } + } } + $controls = array(); $result = dbQuery($sql, $values); $results = $result->fetchALL(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Control'); foreach ( $results as $row => $obj ) { - $filters[] = $obj; + $controls[] = $obj; } - return $filters; + return $controls; + } + + public static function find_one( $parameters = array() ) { + $results = Control::find( $parameters, array('limit'=>1) ); + if ( ! sizeof($results) ) { + return; + } + return $results[0]; } public function save( $new_values = null ) { diff --git a/web/includes/Event.php b/web/includes/Event.php index d7ce25dc4..2bb05bf5d 100644 --- a/web/includes/Event.php +++ b/web/includes/Event.php @@ -486,7 +486,7 @@ class Event { isset($event_cache[$parameters['Id']]) ) { return $event_cache[$parameters['Id']]; } - $results = Event::find_all( $parameters, $options ); + $results = Event::find( $parameters, $options ); if ( count($results) > 1 ) { Error("Event Returned more than 1"); return $results[0]; @@ -497,7 +497,7 @@ class Event { } } - public static function find_all( $parameters = null, $options = null ) { + public static function find( $parameters = null, $options = null ) { $filters = array(); $sql = 'SELECT * FROM Events '; $values = array(); @@ -520,8 +520,21 @@ class Event { } $sql .= implode(' AND ', $fields ); } - if ( $options and isset($options['order']) ) { - $sql .= ' ORDER BY ' . $options['order']; + 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 ' . $limit; + } else { + $backTrace = debug_backtrace(); + $file = $backTrace[1]['file']; + $line = $backTrace[1]['line']; + Error("Invalid value for limit($limit) passed to Event::find from $file:$line"); + return; + } + } } $result = dbQuery($sql, $values); $results = $result->fetchALL(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Event'); diff --git a/web/includes/Filter.php b/web/includes/Filter.php index 721302edb..f65399320 100644 --- a/web/includes/Filter.php +++ b/web/includes/Filter.php @@ -26,12 +26,12 @@ public $defaults = array( public function __construct( $IdOrRow=NULL ) { $row = NULL; if ( $IdOrRow ) { - if ( is_integer( $IdOrRow ) or is_numeric( $IdOrRow ) ) { - $row = dbFetchOne( 'SELECT * FROM Filters WHERE Id=?', NULL, array( $IdOrRow ) ); + if ( is_integer($IdOrRow) or is_numeric($IdOrRow) ) { + $row = dbFetchOne('SELECT * FROM Filters WHERE Id=?', NULL, array($IdOrRow)); if ( ! $row ) { - Error('Unable to load Filter record for Id=' . $IdOrRow ); + Error('Unable to load Filter record for Id=' . $IdOrRow); } - } elseif ( is_array( $IdOrRow ) ) { + } elseif ( is_array($IdOrRow) ) { $row = $IdOrRow; } else { $backTrace = debug_backtrace(); @@ -47,8 +47,8 @@ public $defaults = array( foreach ($row as $k => $v) { $this->{$k} = $v; } - if ( array_key_exists( 'Query', $this ) and $this->{'Query'} ) { - $this->{'Query'} = jsonDecode( $this->{'Query'} ); + if ( array_key_exists('Query', $this) and $this->{'Query'} ) { + $this->{'Query'} = jsonDecode($this->{'Query'}); } else { $this->{'Query'} = array(); } @@ -111,18 +111,62 @@ public $defaults = array( return $this->defaults{'limit'}; } - public static function find_all() { + public static function find( $parameters = null, $options = null ) { $filters = array(); - $result = dbQuery( 'SELECT * FROM Filters ORDER BY Name'); - $results = $result->fetchALL(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Filter' ); + $sql = 'SELECT * FROM Filters '; + $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 ' . $limit; + } else { + $backTrace = debug_backtrace(); + $file = $backTrace[1]['file']; + $line = $backTrace[1]['line']; + Error("Invalid value for limit($limit) passed to Filter::find from $file:$line"); + return; + } + } + } + $result = dbQuery($sql, $values); + $results = $result->fetchALL(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Filter'); foreach ( $results as $row => $obj ) { $filters[] = $obj; } return $filters; - } + } # end find() + + public static function find_one( $parameters = array() ) { + $results = Filter::find($parameters, array('limit'=>1)); + if ( ! sizeof($results) ) { + return; + } + return $results[0]; + } # end find_one() public function delete() { - dbQuery( 'DELETE FROM Filters WHERE Id = ?', array($this->{'Id'}) ); + dbQuery('DELETE FROM Filters WHERE Id = ?', array($this->{'Id'})); } # end function delete() public function set( $data ) { @@ -141,8 +185,6 @@ public $defaults = array( } } } - - } # end class ?> diff --git a/web/includes/Group.php b/web/includes/Group.php index 441eff70e..4cbdaa83b 100644 --- a/web/includes/Group.php +++ b/web/includes/Group.php @@ -58,27 +58,7 @@ class Group { } } - public static function find_one($parameters = null, $options = null) { - global $group_cache; - if ( - ( count($parameters) == 1 ) and - isset($parameters['Id']) and - isset($group_cache[$parameters['Id']]) ) { - return $group_cache[$parameters['Id']]; - } - $results = Group::find_all($parameters, $options); - if ( count($results) > 1 ) { - Error("Group::find_one Returned more than 1"); - return $results[0]; - } else if ( count($results) ) { - return $results[0]; - } else { - return null; - } - } - - public static function find_all( $parameters = null ) { - $filters = array(); + public static function find( $parameters = null, $options = null ) { $sql = 'SELECT * FROM Groups '; $values = array(); @@ -90,22 +70,57 @@ class Group { $fields[] = $field.' IS NULL'; } else if ( is_array( $value ) ) { $func = function(){return '?';}; - $fields[] = $field.' IN ('.implode(',', array_map( $func, $value ) ). ')'; + $fields[] = $field.' IN ('.implode(',', array_map($func, $value)). ')'; $values += $value; } else { $fields[] = $field.'=?'; $values[] = $value; } } - $sql .= implode(' AND ', $fields ); - } - $sql .= ' ORDER BY Name'; + $sql .= implode(' AND ', $fields); + } # end if 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 ' . $limit; + } else { + $backTrace = debug_backtrace(); + $file = $backTrace[1]['file']; + $line = $backTrace[1]['line']; + Error("Invalid value for limit($limit) passed to Group::find from $file:$line"); + return; + } + } + } # end if options + $groups = array(); $result = dbQuery($sql, $values); $results = $result->fetchALL(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Group'); foreach ( $results as $row => $obj ) { - $filters[] = $obj; + $groups[] = $obj; + } + return $groups; + } # end find() + + public static function find_one($parameters = null, $options = null) { + global $group_cache; + if ( + ( count($parameters) == 1 ) and + isset($parameters['Id']) and + isset($group_cache[$parameters['Id']]) ) { + return $group_cache[$parameters['Id']]; + } + $results = Group::find($parameters, $options); + if ( count($results) > 1 ) { + Error("Group::find_one Returned more than 1"); + return $results[0]; + } else if ( count($results) ) { + return $results[0]; + } else { + return null; } - return $filters; } public function delete() { @@ -182,7 +197,7 @@ class Group { public static function get_dropdown_options() { $Groups = array(); - foreach ( Group::find_all( ) as $Group ) { + foreach ( Group::find( ) as $Group ) { $Groups[$Group->Id()] = $Group; } diff --git a/web/includes/Monitor.php b/web/includes/Monitor.php index efa530c0a..19aaf920b 100644 --- a/web/includes/Monitor.php +++ b/web/includes/Monitor.php @@ -278,8 +278,7 @@ private $control_fields = array( } # end if method_exists } # end foreach $data as $k=>$v } - public static function find_all( $parameters = null, $options = null ) { - $filters = array(); + public static function find( $parameters = null, $options = null ) { $sql = 'SELECT * FROM Monitors '; $values = array(); @@ -289,9 +288,9 @@ private $control_fields = array( foreach ( $parameters as $field => $value ) { if ( $value == null ) { $fields[] = $field.' IS NULL'; - } else if ( is_array( $value ) ) { + } else if ( is_array($value) ) { $func = function(){return '?';}; - $fields[] = $field.' IN ('.implode(',', array_map( $func, $value ) ). ')'; + $fields[] = $field.' IN ('.implode(',', array_map($func, $value)). ')'; $values += $value; } else { @@ -299,18 +298,40 @@ private $control_fields = array( $values[] = $value; } } - $sql .= implode(' AND ', $fields ); + $sql .= implode(' AND ', $fields); } - if ( $options and isset($options['order']) ) { - $sql .= ' ORDER BY ' . $options['order']; + 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 ' . $limit; + } else { + $backTrace = debug_backtrace(); + $file = $backTrace[1]['file']; + $line = $backTrace[1]['line']; + Error("Invalid value for limit($limit) passed to Control::find from $file:$line"); + return; + } + } } + $monitors = array(); $result = dbQuery($sql, $values); $results = $result->fetchALL(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Monitor'); foreach ( $results as $row => $obj ) { - $filters[] = $obj; + $monitors[] = $obj; } - return $filters; - } + return $monitors; + } # end find + + public static function find_one( $parameters = array() ) { + $results = Monitor::find( $parameters, array('limit'=>1) ); + if ( ! sizeof($results) ) { + return; + } + return $results[0]; + } # end find_one public function save($new_values = null) { @@ -509,5 +530,7 @@ private $control_fields = array( } return $source; } // end function Source + + } // end class Monitor ?> diff --git a/web/includes/Server.php b/web/includes/Server.php index 591563b52..f9a82c9bb 100644 --- a/web/includes/Server.php +++ b/web/includes/Server.php @@ -13,12 +13,12 @@ class Server { public function __construct( $IdOrRow = NULL ) { $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 ); + 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 ) ) { + } elseif ( is_array($IdOrRow) ) { $row = $IdOrRow; } } # end if isset($IdOrRow) @@ -31,39 +31,6 @@ class Server { $this->{'Hostname'} = ''; } } - public static function find_all( $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 and isset($options['order']) ) { - $sql .= ' ORDER BY ' . $options['order']; - } - $result = dbQuery($sql, $values); - $results = $result->fetchALL(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Server'); - foreach ( $results as $row => $obj ) { - $filters[] = $obj; - } - return $filters; - } public function Url() { if ( $this->Id() ) { @@ -96,26 +63,45 @@ class Server { } } } - - public static function find( $parameters = array(), $limit = NULL ) { - $sql = 'SELECT * FROM Servers'; + public static function find( $parameters = null, $options = null ) { + $filters = array(); + $sql = 'SELECT * FROM Servers '; $values = array(); - if ( sizeof($parameters) ) { - $sql .= ' WHERE ' . implode( ' AND ', array_map( - function($v){ return $v.'=?'; }, - array_keys( $parameters ) - ) ); - $values = array_values( $parameters ); + + 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 ' . $limit; + } else { + $backTrace = debug_backtrace(); + $file = $backTrace[1]['file']; + $line = $backTrace[1]['line']; + Error("Invalid value for limit($limit) passed to Server::find from $file:$line"); + return; + } + } } - if ( is_integer( $limit ) or ctype_digit( $limit ) ) { - $sql .= ' LIMIT ' . $limit; - } else { - $backTrace = debug_backtrace(); - $file = $backTrace[1]['file']; - $line = $backTrace[1]['line']; - Error("Invalid value for limit($limit) passed to Server::find from $file:$line"); - return; - } $results = dbFetchAll( $sql, NULL, $values ); if ( $results ) { return array_map( function($id){ return new Server($id); }, $results ); @@ -123,8 +109,8 @@ class Server { } public static function find_one( $parameters = array() ) { - $results = Server::find( $parameters, 1 ); - if ( ! sizeof( $results ) ) { + $results = Server::find( $parameters, array('limit'=>1) ); + if ( ! sizeof($results) ) { return; } return $results[0]; diff --git a/web/includes/Storage.php b/web/includes/Storage.php index 70f2f831d..bdd4bdf26 100644 --- a/web/includes/Storage.php +++ b/web/includes/Storage.php @@ -40,7 +40,6 @@ class Storage { $this->{'Path'} = ZM_DIR_EVENTS; } return $this->{'Path'}; - } return $this->{'Name'}; } @@ -53,19 +52,19 @@ class Storage { return $this->{'Name'}; } - public function __call( $fn, array $args= NULL){ - if ( count( $args ) ) { + public function __call( $fn, array $args= NULL ) { + if ( count($args) ) { $this->{$fn} = $args[0]; } - if ( array_key_exists( $fn, $this ) ) { + if ( array_key_exists($fn, $this) ) return $this->{$fn}; - $backTrace = debug_backtrace(); - $file = $backTrace[1]['file']; - $line = $backTrace[1]['line']; - Warning( "Unknown function call Storage->$fn from $file:$line" ); - } + $backTrace = debug_backtrace(); + $file = $backTrace[1]['file']; + $line = $backTrace[1]['line']; + Warning("Unknown function call Storage->$fn from $file:$line"); } + public static function find_one( $parameters = null, $options = null ) { global $storage_cache; if ( @@ -74,7 +73,7 @@ class Storage { isset($storage_cache[$parameters['Id']]) ) { return $storage_cache[$parameters['Id']]; } - $results = Storage::find_all( $parameters, $options ); + $results = Storage::find($parameters, $options); if ( count($results) > 1 ) { Error("Storage Returned more than 1"); return $results[0]; @@ -84,8 +83,7 @@ class Storage { return null; } } - public static function find_all( $parameters = null, $options = null ) { - $filters = array(); + public static function find( $parameters = null, $options = null ) { $sql = 'SELECT * FROM Storage '; $values = array(); @@ -95,7 +93,7 @@ class Storage { foreach ( $parameters as $field => $value ) { if ( $value == null ) { $fields[] = $field.' IS NULL'; - } else if ( is_array( $value ) ) { + } else if ( is_array($value) ) { $func = function(){return '?';}; $fields[] = $field.' IN ('.implode(',', array_map($func, $value)). ')'; $values += $value; @@ -106,32 +104,47 @@ class Storage { } } $sql .= implode(' AND ', $fields); - } - if ( $options and isset($options['order']) ) { - $sql .= ' ORDER BY ' . $options['order']; - } + } # end if parameters + if ( $options ) { + if ( isset($options['order']) ) { + $sql .= ' ORDER BY ' . $options['order']; + } # end if options + if ( isset($options['limit']) ) { + if ( is_integer($options['limit']) or ctype_digit($options['limit']) ) { + $sql .= ' LIMIT ' . $limit; + } else { + $backTrace = debug_backtrace(); + $file = $backTrace[1]['file']; + $line = $backTrace[1]['line']; + Error("Invalid value for limit($limit) passed to Control::find from $file:$line"); + return; + } + } # end if limit + } # end if options + $storage_areas = array(); $result = dbQuery($sql, $values); if ( $result ) { $results = $result->fetchALL(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Storage'); foreach ( $results as $row => $obj ) { - $filters[] = $obj; + $storage_areas[] = $obj; } } - return $filters; - } + return $storage_areas; + } # end find() + public function disk_usage_percent() { $path = $this->Path(); if ( ! $path ) { - Warning("Storage::disk_usage_percent: path is empty"); + Warning('Storage::disk_usage_percent: path is empty'); return 0; - } else if ( ! file_exists( $path ) ) { + } else if ( ! file_exists($path) ) { Warning("Storage::disk_usage_percent: path $path does not exist"); return 0; } $total = $this->disk_total_space(); if ( ! $total ) { - Error("disk_total_space returned false for " . $path ); + Error('disk_total_space returned false for ' . $path ); return 0; } $used = $this->disk_used_space(); @@ -139,6 +152,7 @@ class Storage { //Logger::Debug("Used $usage = round( ( $used / $total ) * 100 )"); return $usage; } + public function disk_total_space() { if ( !array_key_exists('disk_total_space', $this) ) { $path = $this->Path(); @@ -175,8 +189,8 @@ class Storage { if ( (! array_key_exists('DiskSpace', $this)) or (!$this->{'DiskSpace'}) ) { $used = dbFetchOne('SELECT SUM(DiskSpace) AS DiskSpace FROM Events WHERE StorageId=? AND DiskSpace IS NOT NULL', 'DiskSpace', array($this->Id()) ); - foreach ( Event::find_all( array('StorageId'=>$this->Id(), 'DiskSpace'=>null) ) as $Event ) { - $Event->Storage( $this ); // Prevent further db hit + foreach ( Event::find(array('StorageId'=>$this->Id(), 'DiskSpace'=>null)) as $Event ) { + $Event->Storage($this); // Prevent further db hit $used += $Event->DiskSpace(); } $this->{'DiskSpace'} = $used; diff --git a/web/skins/classic/includes/functions.php b/web/skins/classic/includes/functions.php index 66243daf3..f85d863c9 100644 --- a/web/skins/classic/includes/functions.php +++ b/web/skins/classic/includes/functions.php @@ -329,7 +329,7 @@ if ($reload == 'reload') ob_start(); ?>
  • : Path()] = $area; @@ -350,7 +350,7 @@ if ($reload == 'reload') ob_start(); return ''.$S->Name() . ': ' . $S->disk_usage_percent().'%' . ''; }; #$func = function($S){ return ''.$S->Name() . ': ' . $S->disk_usage_percent().'%' . ''; }; if ( count($storage_areas) >= 4 ) - $storage_areas = Storage::find_all( array('ServerId'=>null) ); + $storage_areas = Storage::find( array('ServerId'=>null) ); if ( count($storage_areas) < 4 ) echo implode( ', ', array_map ( $func, $storage_areas ) ); echo ' ' . ZM_PATH_MAP .': '. getDiskPercent(ZM_PATH_MAP).'%'; diff --git a/web/skins/classic/views/_monitor_filters.php b/web/skins/classic/views/_monitor_filters.php index c0c6021d2..357c6e7d1 100644 --- a/web/skins/classic/views/_monitor_filters.php +++ b/web/skins/classic/views/_monitor_filters.php @@ -18,26 +18,26 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. // -$servers = Server::find_all(null, array('order'=>'lower(Name)')); +$servers = Server::find(null, array('order'=>'lower(Name)')); $ServersById = array(); foreach ( $servers as $S ) { $ServersById[$S->Id()] = $S; } session_start(); foreach ( array('Group','Function','ServerId','StorageId','Status','MonitorId','MonitorName','Source') as $var ) { - if ( isset( $_REQUEST[$var] ) ) { + if ( isset($_REQUEST[$var]) ) { if ( $_REQUEST[$var] != '' ) { $_SESSION[$var] = $_REQUEST[$var]; } else { - unset( $_SESSION[$var] ); + unset($_SESSION[$var]); } - } else if ( isset( $_REQUEST['filtering'] ) ) { - unset( $_SESSION[$var] ); + } else if ( isset($_REQUEST['filtering']) ) { + unset($_SESSION[$var]); } } session_write_close(); -$storage_areas = Storage::find_all(); +$storage_areas = Storage::find(); $StorageById = array(); foreach ( $storage_areas as $S ) { $StorageById[$S->Id()] = $S; @@ -50,7 +50,7 @@ $html = '; $GroupsById = array(); -foreach ( Group::find_all() as $G ) { +foreach ( Group::find() as $G ) { $GroupsById[$G->Id()] = $G; } @@ -78,17 +78,17 @@ if ( $groupSql ) foreach ( array('ServerId','StorageId','Status','Function') as $filter ) { if ( isset($_SESSION[$filter]) ) { if ( is_array($_SESSION[$filter]) ) { - $conditions[] = $filter . ' IN ('.implode(',', array_map(function(){return '?';}, $_SESSION[$filter] ) ). ')'; - $values = array_merge( $values, $_SESSION[$filter] ); + $conditions[] = $filter . ' IN ('.implode(',', array_map(function(){return '?';}, $_SESSION[$filter])). ')'; + $values = array_merge($values, $_SESSION[$filter]); } else { $conditions[] = $filter . '=?'; $values[] = $_SESSION[$filter]; } } } # end foreach filter -if ( ! empty( $user['MonitorIds'] ) ) { - $ids = explode(',', $user['MonitorIds'] ); - $conditions[] = 'M.Id IN ('.implode(',',array_map( function(){return '?';}, $ids) ).')'; +if ( ! empty($user['MonitorIds']) ) { + $ids = explode(',', $user['MonitorIds']); + $conditions[] = 'M.Id IN ('.implode(',',array_map(function(){return '?';}, $ids)).')'; $values += $ids; } @@ -115,7 +115,7 @@ $html .= ''; if ( count($ServersById) > 1 ) { $html .= ''; - $html .= htmlSelect( 'ServerId[]', $ServersById, + $html .= htmlSelect('ServerId[]', $ServersById, (isset($_SESSION['ServerId'])?$_SESSION['ServerId']:''), array( 'onchange'=>'this.form.submit();', @@ -129,7 +129,7 @@ if ( count($ServersById) > 1 ) { if ( count($StorageById) > 1 ) { $html .= ''; - $html .= htmlSelect( 'StorageId[]',$StorageById, + $html .= htmlSelect('StorageId[]', $StorageById, (isset($_SESSION['StorageId'])?$_SESSION['StorageId']:''), array( 'onchange'=>'this.form.submit();', diff --git a/web/skins/classic/views/add_monitors.php b/web/skins/classic/views/add_monitors.php index f73a22864..98eb87b16 100644 --- a/web/skins/classic/views/add_monitors.php +++ b/web/skins/classic/views/add_monitors.php @@ -44,11 +44,11 @@ xhtmlHeaders(__FILE__, translate('AddMonitors'));
    Enter by IP or URL -

    -Simply enter the ip address or full url to the stream. -It will be probed for available streams, or checked to see if it has already been entered. -If streams are found, they will be listed in the results column. Click Add to add them. -

    +

    + Simply enter the ip address or full url to the stream. + It will be probed for available streams, or checked to see if it has already been entered. + If streams are found, they will be listed in the results column. Click Add to add them. +

    @@ -80,7 +80,7 @@ If streams are found, they will be listed in the results column. Click Add to ad ?> Id()] = $S; @@ -92,7 +92,7 @@ If streams are found, they will be listed in the results column. Click Add to ad Id()] = $S; diff --git a/web/skins/classic/views/events.php b/web/skins/classic/views/events.php index eb5ccb14d..50409cf16 100644 --- a/web/skins/classic/views/events.php +++ b/web/skins/classic/views/events.php @@ -83,7 +83,7 @@ if ( $_POST ) { exit(); } -$storage_areas = Storage::find_all(); +$storage_areas = Storage::find(); $StorageById = array(); foreach ( $storage_areas as $S ) { $StorageById[$S->Id()] = $S; @@ -94,7 +94,7 @@ xhtmlHeaders(__FILE__, translate('Events') ); ?>
    - + diff --git a/web/skins/classic/views/group.php b/web/skins/classic/views/group.php index 5a4446544..d765e445f 100644 --- a/web/skins/classic/views/group.php +++ b/web/skins/classic/views/group.php @@ -18,18 +18,18 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. // -if ( !canEdit( 'Groups' ) ) { +if ( !canEdit('Groups') ) { $view = 'error'; return; } if ( !empty($_REQUEST['gid']) ) { - $newGroup = new Group( $_REQUEST['gid'] ); + $newGroup = new Group($_REQUEST['gid']); } else { $newGroup = new Group(); } -xhtmlHeaders( __FILE__, translate('Group').' - '.$newGroup->Name() ); +xhtmlHeaders(__FILE__, translate('Group').' - '.$newGroup->Name()); ?>
    @@ -52,7 +52,7 @@ xhtmlHeaders( __FILE__, translate('Group').' - '.$newGroup->Name() ); Id()] = $Group; } @@ -76,7 +76,7 @@ function get_children($Group) { $kids = array(); if ( isset( $children[$Group->Id()] ) ) { - $kids += array_map( 'get_Id', $children[$Group->Id()] ); + $kids += array_map('get_Id', $children[$Group->Id()]); foreach ( $children[$Group->Id()] as $G ) { foreach ( get_children($G) as $id ) { $kids[] = $id; @@ -89,13 +89,12 @@ function get_children($Group) { $kids = get_children($newGroup); if ( $newGroup->Id() ) $kids[] = $newGroup->Id(); -$sql = 'SELECT Id,Name from Groups'.(count($kids)?' WHERE Id NOT IN ('.implode(',',array_map(function(){return '?';}, $kids )).')' : '').' ORDER BY Name'; +$sql = 'SELECT Id,Name from Groups'.(count($kids)?' WHERE Id NOT IN ('.implode(',',array_map(function(){return '?';}, $kids)).')' : '').' ORDER BY Name'; $options = array(''=>'None'); -foreach ( dbFetchAll( $sql, null, $kids ) as $option ) { - - $options[$option['Id']] = str_repeat('  ', $Groups[$option['Id']]->depth() ) . $option['Name']; +foreach ( dbFetchAll($sql, null, $kids) as $option ) { + $options[$option['Id']] = str_repeat('  ', $Groups[$option['Id']]->depth()) . $option['Name']; } -echo htmlSelect( 'newGroup[ParentId]', $options, $newGroup->ParentId(), array('onchange'=>'configureButtons(this);' )); +echo htmlSelect('newGroup[ParentId]', $options, $newGroup->ParentId(), array('onchange'=>'configureButtons(this);')); ?> @@ -104,10 +103,10 @@ echo htmlSelect( 'newGroup[ParentId]', $options, $newGroup->ParentId(), array('o Id() ? '' : ' disabled="disabled"'?>/> +
    diff --git a/web/skins/classic/views/groups.php b/web/skins/classic/views/groups.php index ecf85b3c1..fb383026d 100644 --- a/web/skins/classic/views/groups.php +++ b/web/skins/classic/views/groups.php @@ -28,7 +28,7 @@ $group_id = 0; $max_depth = 0; $Groups = array(); -foreach ( Group::find_all( ) as $Group ) { +foreach ( Group::find( ) as $Group ) { $Groups[$Group->Id()] = $Group; } @@ -41,7 +41,7 @@ foreach ( $Groups as $id=>$Group ) { if ( $max_depth < $Group->depth() ) $max_depth = $Group->depth(); } -xhtmlHeaders(__FILE__, translate('Groups') ); +xhtmlHeaders(__FILE__, translate('Groups')); ?>
    @@ -64,33 +64,37 @@ function group_line( $Group ) { global $children; global $max_depth; $html = ''; - $html .= str_repeat( ' ', $Group->depth() ); + $html .= str_repeat(' ', $Group->depth()); $html .= ''; if ( canEdit('Groups') ) { $html .= ''. validHtmlStr($Group->Id() . ' ' . $Group->Name()).''; } else { $html .= validHtmlStr($Group->Name()); } - $html .= ''. monitorIdsToNames( $Group->MonitorIds(), 30 ).' + $html .= ''. monitorIdsToNames($Group->MonitorIds(), 30).' '; if ( isset( $children[$Group->Id()] ) ) { foreach ( $children[$Group->Id()] as $G ) { - $html .= group_line( $G ); + $html .= group_line($G); } } return $html; } if ( isset( $children[null] ) ) foreach ( $children[null] as $Group ) - echo group_line( $Group ); + echo group_line($Group); ?>
    - /> - + +
    diff --git a/web/skins/classic/views/monitors.php b/web/skins/classic/views/monitors.php index 4c35a0f8f..ff57a4edf 100644 --- a/web/skins/classic/views/monitors.php +++ b/web/skins/classic/views/monitors.php @@ -18,25 +18,24 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. // -if ( !canEdit( 'Monitors' ) ) { +if ( !canEdit('Monitors') ) { $view = 'error'; return; } -$monitors = Monitor::find_all( array('Id' => $_REQUEST['mids'] ) ); +$monitors = Monitor::find(array('Id' => $_REQUEST['mids'])); $monitor = $monitors[0]; -$servers = Server::find_all(); +$servers = Server::find(); $ServersById = array(); foreach ( $servers as $S ) { $ServersById[$S->Id()] = $S; } -$storage_areas = Storage::find_all(); +$storage_areas = Storage::find(); $StorageById = array(); foreach ( $storage_areas as $S ) { $StorageById[$S->Id()] = $S; } - $focusWindow = true; xhtmlHeaders(__FILE__, translate('Function')); @@ -48,7 +47,7 @@ xhtmlHeaders(__FILE__, translate('Function'));
    The following monitors will have these settings update when you click Save:

    - ', array_map( function($m){return $m->Id().' ' .$m->Name();}, $monitors ) ); ?> + ', array_map(function($m){return $m->Id().' ' .$m->Name();}, $monitors)); ?>
    @@ -56,31 +55,31 @@ The following monitors will have these settings update when you click Save:
    Id().'"/>'; - }, $monitors ) + }, $monitors) ); if ( count($ServersById) > 0 ) { ?> -

    -'None')+$ServersById, $monitor->ServerId() ); ?> -

    +

    + 'None')+$ServersById, $monitor->ServerId()); ?> +

    0 ) { + } + if ( count($StorageById) > 0 ) { ?> -

    -'All')+$StorageById, $monitor->StorageId() ); ?> -

    +

    + 'All')+$StorageById, $monitor->StorageId()); ?> +

    Function() ); + $options = array(); + foreach ( getEnumValues('Monitors', 'Function') as $opt ) { + $options[$opt] = translate('Fn'.$opt); + } + echo htmlSelect('newMonitor[Function]', $options, $monitor->Function()); ?>

    @@ -89,7 +88,7 @@ echo htmlSelect( 'newMonitor[Function]', $options, $monitor->Function() );

    - +
    diff --git a/web/skins/classic/views/options.php b/web/skins/classic/views/options.php index 2a17cf0b9..37d7c75c4 100644 --- a/web/skins/classic/views/options.php +++ b/web/skins/classic/views/options.php @@ -18,12 +18,12 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. // -if ( !canView( 'System' ) ) { +if ( !canView('System') ) { $view = 'error'; return; } -$canEdit = canEdit( 'System' ); +$canEdit = canEdit('System'); $tabs = array(); $tabs['skins'] = translate('Display'); @@ -50,10 +50,10 @@ else $focusWindow = true; -xhtmlHeaders( __FILE__, translate('Options') ); +xhtmlHeaders(__FILE__, translate('Options')); # Have to do this stuff up here before including header.php because fof the cookie setting -$skin_options = array_map( 'basename', glob('skins/*',GLOB_ONLYDIR) ); +$skin_options = array_map('basename', glob('skins/*',GLOB_ONLYDIR)); if ( $tab == 'skins' ) { $current_skin = $_COOKIE['zmSkin']; $reload = false; @@ -75,7 +75,7 @@ if ( $tab == 'skins' ) { ?> - +
    -
    +
    '.$dir.''; } ?> @@ -136,7 +136,7 @@ foreach( array_map( 'basename', glob('skins/'.$current_skin.'/css/*',GLOB_ONLYDI - +
    @@ -155,17 +155,17 @@ foreach( array_map( 'basename', glob('skins/'.$current_skin.'/css/*',GLOB_ONLYDI "/> -
    +
    @@ -270,15 +270,15 @@ foreach( array_map( 'basename', glob('skins/'.$current_skin.'/css/*',GLOB_ONLYDI -'lower(Name)') ) as $Storage ) { ?> +'lower(Name)') ) as $Storage ) { ?> - - - - + + + + + echo makePopupLink('?view=storage&id='.$Storage->Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Name()), $canEdit ) ?> @@ -400,6 +400,4 @@ foreach( array_map( 'basename', glob('skins/'.$current_skin.'/css/*',GLOB_ONLYDI - - - +
    Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Id()), $canEdit ) ?>Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Name()), $canEdit ) ?>Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Path()), $canEdit ) ?>Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Type()), $canEdit ) ?>Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Scheme()), $canEdit ) ?>Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Name()), $canEdit ) ?>Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Path()), $canEdit ) ?>Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Type()), $canEdit ) ?>Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Scheme()), $canEdit ) ?> Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Name()), $canEdit ) ?> disk_used_space()) . ' of ' . human_filesize($Storage->disk_total_space()) ?> disabled="disabled"/>