From 3af795264d2f74ebdd1931f7c9b06fd13b483f12 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Tue, 10 Oct 2017 10:38:13 -0400 Subject: [PATCH] add actual disk space as a mouseover in nav bar --- web/includes/Event.php | 35 +++++++++++++++++++++++ web/includes/Group.php | 11 ++++++- web/includes/Storage.php | 20 ++++++++++++- web/includes/actions.php | 26 +++++++++-------- web/skins/classic/includes/functions.php | 6 ++-- web/skins/classic/views/group.php | 5 +--- web/skins/classic/views/groups.php | 11 ++++--- web/skins/classic/views/montage.php | 4 +-- web/skins/classic/views/montagereview.php | 2 +- 9 files changed, 90 insertions(+), 30 deletions(-) diff --git a/web/includes/Event.php b/web/includes/Event.php index 6facdfc1c..8b80d1040 100644 --- a/web/includes/Event.php +++ b/web/includes/Event.php @@ -320,6 +320,41 @@ class Event { return( $imageData ); } + public static function find_all( $parameters = null, $options = null ) { + $filters = array(); + $sql = 'SELECT * FROM Events '; + $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, 'Event'); + foreach ( $results as $row => $obj ) { + $filters[] = $obj; + } + return $filters; + } + + } # end class ?> diff --git a/web/includes/Group.php b/web/includes/Group.php index 5e00545dc..48c5e00f6 100644 --- a/web/includes/Group.php +++ b/web/includes/Group.php @@ -87,7 +87,15 @@ public $defaults = array( } public function delete() { - dbQuery( 'DELETE FROM Groups WHERE Id = ?', array($this->{'Id'}) ); + if ( array_key_exists( 'Id', $this ) ) { + dbQuery( 'DELETE FROM Groups WHERE Id = ?', array($this->{'Id'}) ); + if ( isset($_COOKIE['zmGroup']) ) { + if ( $this->{'Id'} == $_COOKIE['zmGroup'] ) { + unset( $_COOKIE['zmGroup'] ); + setcookie( 'zmGroup', '', time()-3600*24*2 ); + } + } + } } # end function delete() public function set( $data ) { @@ -172,5 +180,6 @@ public $defaults = array( } return $groupSql; } # end public static function get_group_sql( $group_id ) + } # end class Group ?> diff --git a/web/includes/Storage.php b/web/includes/Storage.php index 940653404..3e5feef93 100644 --- a/web/includes/Storage.php +++ b/web/includes/Storage.php @@ -73,7 +73,7 @@ class Storage { return 0; } - $total = disk_total_space( $path ); + $total = $this->disk_total_space(); if ( ! $total ) { Error("disk_total_space returned false for " . $path ); return 0; @@ -85,5 +85,23 @@ class Storage { $usage = round(($total - $free) / $total * 100); return $usage; } + public function disk_total_space() { + if ( ! array_key_exists( 'disk_total_space', $this ) ) { + $this->{'disk_total_space'} = disk_total_space( $this->Path() ); + } + return $this->{'disk_total_space'}; + } + public function disk_used_space() { + # This isn't a function like this in php, so we have to add up the space used in each event. + if ( ! array_key_exists( 'disk_used_space', $this ) ) { + $used = 0; + foreach ( Event::find_all( array( 'StorageId'=>$this->Id() ) ) as $Event ) { + $used += $Event->DiskSpace(); + } + + $this->{'disk_used_space'} = $used; + } + return $this->{'disk_used_space'}; + } } ?> diff --git a/web/includes/actions.php b/web/includes/actions.php index 901ec2801..3dec82bc7 100644 --- a/web/includes/actions.php +++ b/web/includes/actions.php @@ -602,10 +602,10 @@ Warning("Addterm"); } // Group edit actions +# Should probably verify that each monitor id is a valid monitor, that we have access to. However at the moment, you have to have System permissions to do this if ( canEdit( 'Groups' ) ) { if ( $action == 'group' ) { -# Should probably verfy that each monitor id is a valid monitor, that we have access to. HOwever at the moment, you have to have System permissions to do this - $monitors = empty( $_POST['newGroup']['MonitorIds'] ) ? '' : implode(',', $_POST['newGroup']['MonitorIds'] ); + $monitors = empty( $_POST['newGroup']['MonitorIds'] ) ? '' : implode(',', $_POST['newGroup']['MonitorIds']); if ( !empty($_POST['gid']) ) { dbQuery( 'UPDATE Groups SET Name=?, ParentId=?, MonitorIds=? WHERE Id=?', array($_POST['newGroup']['Name'], ( $_POST['newGroup']['ParentId'] == '' ? null : $_POST['newGroup']['ParentId'] ), $monitors, $_POST['gid']) ); @@ -614,18 +614,20 @@ Warning("Addterm"); array( $_POST['newGroup']['Name'], ( $_POST['newGroup']['ParentId'] == '' ? null : $_POST['newGroup']['ParentId'] ), $monitors ) ); } $view = 'none'; - } - if ( !empty($_REQUEST['gid']) && $action == 'delete' ) { - dbQuery( 'DELETE FROM Groups WHERE Id = ?', array($_REQUEST['gid']) ); - if ( isset($_COOKIE['zmGroup']) ) { - if ( $_REQUEST['gid'] == $_COOKIE['zmGroup'] ) { - unset( $_COOKIE['zmGroup'] ); - setcookie( 'zmGroup', '', time()-3600*24*2 ); - $refreshParent = true; + } else if ( $action == 'delete' ) { + if ( !empty($_REQUEST['gid']) ) { + if ( is_array( $_REQUEST['gid'] ) ) { + foreach( $_REQUEST['gid'] as $gid ) { + $Group = new Group( $gid ); + $Group->delete(); + } + } else { + $Group = new Group( $_REQUEST['gid'] ); + $Group->delete(); } } - } - $refreshParent = true; + $refreshParent = true; + } # end if action } // end if can edit groups // System edit actions diff --git a/web/skins/classic/includes/functions.php b/web/skins/classic/includes/functions.php index 50d0a7d6c..bf85f3ada 100644 --- a/web/skins/classic/includes/functions.php +++ b/web/skins/classic/includes/functions.php @@ -165,7 +165,7 @@ function getNavBarHTML() { $running = daemonCheck(); $status = $running?translate('Running'):translate('Stopped'); global $user; - global $bwArray; + global $bandwidth_options; global $view; ?>