add actual disk space as a mouseover in nav bar

pull/2077/head
Isaac Connor 2017-10-10 10:38:13 -04:00
parent 8da7d845b4
commit 3af795264d
9 changed files with 90 additions and 30 deletions

View File

@ -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
?>

View File

@ -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
?>

View File

@ -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'};
}
}
?>

View File

@ -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

View File

@ -165,7 +165,7 @@ function getNavBarHTML() {
$running = daemonCheck();
$status = $running?translate('Running'):translate('Stopped');
global $user;
global $bwArray;
global $bandwidth_options;
global $view;
?>
<noscript>
@ -230,7 +230,7 @@ ZoneMinder requires Javascript. Please enable Javascript in your browser for thi
</div> <!-- End .container-fluid -->
<div class="container-fluid">
<div class="pull-left">
<?php echo makePopupLink( '?view=bandwidth', 'zmBandwidth', 'bandwidth', $bwArray[$_COOKIE['zmBandwidth']] . ' ' . translate('BandwidthHead'), ($user && $user['MaxBandwidth'] != 'low' ) ) ?>
<?php echo makePopupLink( '?view=bandwidth', 'zmBandwidth', 'bandwidth', $bandwidth_options[$_COOKIE['zmBandwidth']] . ' ' . translate('BandwidthHead'), ($user && $user['MaxBandwidth'] != 'low' ) ) ?>
</div>
<div class="pull-right">
<?php echo makePopupLink( '?view=version', 'zmVersion', 'version', '<span class="'.$versionClass.'">v'.ZM_VERSION.'</span>', canEdit( 'System' ) ) ?>
@ -256,7 +256,7 @@ ZoneMinder requires Javascript. Please enable Javascript in your browser for thi
if ( ! isset($storage_paths[ZM_DIR_EVENTS]) ) {
array_push( $storage_areas, new Storage() );
}
$func = function($S){ return $S->Name() . ': ' . $S->disk_usage_percent().'%'; };
$func = function($S){ return '<span title="'.human_filesize($S->disk_used_space()) . ' of ' . human_filesize($S->disk_total_space()).'">'.$S->Name() . ': ' . $S->disk_usage_percent().'%' . '</span>'; };
echo implode( ', ', array_map ( $func, $storage_areas ) );
echo ' ' . ZM_PATH_MAP .': '. getDiskPercent(ZM_PATH_MAP).'%';
?></li>

View File

@ -88,11 +88,8 @@ function get_children($Group) {
$kids = get_children($newGroup);
$kids[] = $newGroup->Id();
function get_question_marks() {
return '?';
}
$options = array(''=>'None');
foreach ( dbFetchAll( 'SELECT Id,Name from Groups WHERE Id NOT IN ('.implode(',',array_map('get_question_marks', $kids )).') ORDER BY Name', null, $kids ) as $option ) {
foreach ( dbFetchAll( 'SELECT Id,Name from Groups WHERE Id NOT IN ('.implode(',',array_map(function(){return '?';}, $kids )).') ORDER BY Name', null, $kids ) as $option ) {
$options[$option['Id']] = $option['Name'];
}
echo htmlSelect( 'newGroup[ParentId]', $options, $newGroup->ParentId(), array('onchange'=>'configureButtons(this);' ));

View File

@ -23,11 +23,10 @@ if ( !canView( 'Groups' ) ) {
return;
}
# This will end up with the group_id of the deepest selection
# This will end up with the group_id of the deepest selection
$group_id = 0;
$max_depth = 0;
$Groups = array();
foreach ( Group::find_all( ) as $Group ) {
$Groups[$Group->Id()] = $Group;
@ -42,7 +41,6 @@ foreach ( $Groups as $id=>$Group ) {
if ( $max_depth < $Group->depth() )
$max_depth = $Group->depth();
}
Warning("Max depth $max_depth");
xhtmlHeaders(__FILE__, translate('Groups') );
?>
<body>
@ -75,7 +73,7 @@ function group_line( $Group ) {
$html .= validHtmlStr($Group->Name());
}
$html .= '</td><td class="colIds">'. monitorIdsToNames( $Group->MonitorIds(), 30 ).'</td>
<td class="colSelect"><input type="checkbox" name="gid" value="'. $Group->Id() .'" onclick="configureButtons(this);"/></td>
<td class="colSelect"><input type="checkbox" name="gid[]" value="'. $Group->Id() .'" onclick="configureButtons(this);"/></td>
</tr>
';
if ( isset( $children[$Group->Id()] ) ) {
@ -85,8 +83,9 @@ function group_line( $Group ) {
}
return $html;
}
foreach ( $children[null] as $Group )
echo group_line( $Group );
if ( isset( $children[null] ) )
foreach ( $children[null] as $Group )
echo group_line( $Group );
?>
</tbody>
</table>

View File

@ -102,9 +102,9 @@ $monitors = array();
$monitors_dropdown = array( '' => 'All' );
$sql = "SELECT * FROM Monitors WHERE Function != 'None'";
if ( $groupSql ) { $sql .= ' AND ' . $groupSql; };
if ( $monitor_id ) { $sql .= ' AND Id=?'.$monitor_id; };
if ( $monitor_id ) { $sql .= ' AND Id='.$monitor_id; };
$sql .= 'ORDER BY Sequence';
$sql .= ' ORDER BY Sequence';
foreach( dbFetchAll( $sql ) as $row ) {
if ( !visibleMonitor( $row['Id'] ) ) {
continue;

View File

@ -114,7 +114,7 @@ if ( ! empty( $user['MonitorIds'] ) ) {
$frameSql .= ' AND E.MonitorId IN ('.$user['MonitorIds'].')';
}
if ( $monitor_id ) {
$monitorSql .= ' AND Id='.$monitor_id;
$monitorsSql .= ' AND Id='.$monitor_id;
$eventsSql .= ' AND M.Id='.$monitor_id;
$frameSql .= ' AND E.MonitorId='.$monitor_id;
}