diff --git a/db/zm_create.sql.in b/db/zm_create.sql.in index fe05585e4..a73bc524d 100644 --- a/db/zm_create.sql.in +++ b/db/zm_create.sql.in @@ -256,7 +256,7 @@ FOR EACH ROW END IF; END IF; END; - +// DELIMITER ; DROP TABLE IF EXISTS `Events_Day`; diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Event.pm b/scripts/ZoneMinder/lib/ZoneMinder/Event.pm index 0eb9e2763..56ecfa249 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Event.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Event.pm @@ -470,7 +470,7 @@ sub DiskSpace { $_[0]{DiskSpace} = $size; Debug("DiskSpace for event $_[0]{Id} at $_[0]{Path} Updated to $size bytes"); } else { - Warning("DiskSpace: Event does not exist at $_[0]{Path}:" . $Event->to_string() ); + Warning("DiskSpace: Event does not exist at $_[0]{Path}:" . $_[0]->to_string() ); } } # end if ! defined DiskSpace return $_[0]{DiskSpace}; diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm b/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm index 2d00a7781..38c56c40c 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Logger.pm @@ -714,6 +714,9 @@ sub error { sub Fatal( @ ) { fetch()->logPrint( FATAL, @_ ); + if ( $SIG{TERM} ne 'DEFAULT' ) { + $SIG{TERM}(); + } exit( -1 ); } diff --git a/scripts/zmaudit.pl.in b/scripts/zmaudit.pl.in index b0fd7697b..761c07da2 100644 --- a/scripts/zmaudit.pl.in +++ b/scripts/zmaudit.pl.in @@ -159,14 +159,14 @@ MAIN: while( $loop ) { while ( ! ( $dbh and $dbh->ping() ) ) { $dbh = zmDbConnect(); if ( ! $dbh ) { + Error('Unable to connect to database'); if ( $continuous ) { - Error('Unable to connect to database'); # if we are running continuously, then just skip to the next # interval, otherwise we are a one off run, so wait a second and # retry until someone kills us. sleep( $Config{ZM_AUDIT_CHECK_INTERVAL} ); } else { - Fatal('Unable to connect to database'); + Term(); } # end if } # end if } # end while can't connect to the db @@ -175,13 +175,15 @@ MAIN: while( $loop ) { if ( defined $storage_id ) { @Storage_Areas = ZoneMinder::Storage->find( Id=>$storage_id ); if ( !@Storage_Areas ) { - Fatal("No Storage Area found with Id $storage_id"); + Error("No Storage Area found with Id $storage_id"); + Term(); } Info("Auditing Storage Area $Storage_Areas[0]{Id} $Storage_Areas[0]{Name} at $Storage_Areas[0]{Path}"); } elsif ( $Config{ZM_SERVER_ID} ) { @Storage_Areas = ZoneMinder::Storage->find( ServerId => $Config{ZM_SERVER_ID} ); if ( ! @Storage_Areas ) { - Fatal("No Storage Area found with ServerId =" . $Config{ZM_SERVER_ID}); + Error("No Storage Area found with ServerId =" . $Config{ZM_SERVER_ID}); + Term(); } Info("Auditing All Storage Areas on Server " . $Storage_Areas[0]->Server()->Name()); } else { @@ -465,10 +467,10 @@ MAIN: while( $loop ) { } # end if exists in filesystem } # end if ! in fs_events } # foreach db_event - } else { - my $Monitor = new ZoneMinder::Monitor( $db_monitor ); - my $Storage = $Monitor->Storage(); - aud_print( "Database monitor '$db_monitor' does not exist in filesystem, should have been at ".$Storage->Path().'/'.$Monitor->Id()."\n" ); + #} else { + #my $Monitor = new ZoneMinder::Monitor( $db_monitor ); + #my $Storage = $Monitor->Storage(); + #aud_print( "Database monitor '$db_monitor' does not exist in filesystem, should have been at ".$Storage->Path().'/'.$Monitor->Id()."\n" ); #if ( confirm() ) #{ # We don't actually do this in case it's new @@ -478,48 +480,62 @@ MAIN: while( $loop ) { #} } } # end foreach db_monitor - redo MAIN if ( $cleaned ); + if ( $cleaned ) { + Debug("Have done some cleaning, restarting."); + redo MAIN; + } # Remove orphaned events (with no monitor) $cleaned = 0; + Debug("Checking for Orphaned Events"); my $selectOrphanedEventsSql = 'SELECT Events.Id, Events.Name FROM Events LEFT JOIN Monitors ON (Events.MonitorId = Monitors.Id) WHERE isnull(Monitors.Id)'; my $selectOrphanedEventsSth = $dbh->prepare_cached( $selectOrphanedEventsSql ) - or Fatal( "Can't prepare '$selectOrphanedEventsSql': ".$dbh->errstr() ); + or Error( "Can't prepare '$selectOrphanedEventsSql': ".$dbh->errstr() ); $res = $selectOrphanedEventsSth->execute() - or Fatal( "Can't execute: ".$selectOrphanedEventsSth->errstr() ); + or Error( "Can't execute: ".$selectOrphanedEventsSth->errstr() ); while( my $event = $selectOrphanedEventsSth->fetchrow_hashref() ) { aud_print( "Found orphaned event with no monitor '$event->{Id}'" ); if ( confirm() ) { - $res = $deleteEventSth->execute( $event->{Id} ) - or Fatal( "Can't execute: ".$deleteEventSth->errstr() ); - $cleaned = 1; + if ( $res = $deleteEventSth->execute( $event->{Id} ) ) { + $cleaned = 1; + } else { + Error( "Can't execute: ".$deleteEventSth->errstr() ); + } } } - redo MAIN if ( $cleaned ); + redo MAIN if $cleaned; # Remove empty events (with no frames) $cleaned = 0; + Debug("Checking for Events with no Frames"); my $selectEmptyEventsSql = 'SELECT E.Id AS Id, E.StartTime, F.EventId FROM Events as E LEFT JOIN Frames as F ON (E.Id = F.EventId) WHERE isnull(F.EventId) AND now() - interval '.$Config{ZM_AUDIT_MIN_AGE}.' second > E.StartTime'; - my $selectEmptyEventsSth = $dbh->prepare_cached( $selectEmptyEventsSql ) - or Fatal( "Can't prepare '$selectEmptyEventsSql': ".$dbh->errstr() ); - $res = $selectEmptyEventsSth->execute() - or Fatal( "Can't execute: ".$selectEmptyEventsSth->errstr() ); - while( my $event = $selectEmptyEventsSth->fetchrow_hashref() ) { - aud_print( "Found empty event with no frame records '$event->{Id}' at $$event{StartTime}" ); - if ( confirm() ) { - $res = $deleteEventSth->execute( $event->{Id} ) - or Fatal( "Can't execute: ".$deleteEventSth->errstr() ); - $cleaned = 1; + if ( my $selectEmptyEventsSth = $dbh->prepare_cached( $selectEmptyEventsSql ) ) { + if ( $res = $selectEmptyEventsSth->execute() ) { + while( my $event = $selectEmptyEventsSth->fetchrow_hashref() ) { + aud_print( "Found empty event with no frame records '$event->{Id}' at $$event{StartTime}" ); + if ( confirm() ) { + if ( $res = $deleteEventSth->execute( $event->{Id} ) ) { + $cleaned = 1; + } else { + Error( "Can't execute: ".$deleteEventSth->errstr() ); + } + } + } # end foreach row + } else { + Error( "Can't execute: ".$selectEmptyEventsSth->errstr() ); } + } else { + Error( "Can't prepare '$selectEmptyEventsSql': ".$dbh->errstr() ); } - redo MAIN if ( $cleaned ); + redo MAIN if $cleaned; # Remove orphaned frame records $cleaned = 0; + Debug("Checking for Orphaned Frames"); my $selectOrphanedFramesSql = 'SELECT DISTINCT EventId FROM Frames WHERE EventId NOT IN (SELECT Id FROM Events)'; my $selectOrphanedFramesSth = $dbh->prepare_cached( $selectOrphanedFramesSql ) @@ -534,10 +550,11 @@ MAIN: while( $loop ) { $cleaned = 1; } } - redo MAIN if ( $cleaned ); + redo MAIN if $cleaned; # Remove orphaned stats records $cleaned = 0; + Debug("Checking for Orphaned Stats"); my $selectOrphanedStatsSql = 'SELECT DISTINCT EventId FROM Stats WHERE EventId NOT IN (SELECT Id FROM Events)'; my $selectOrphanedStatsSth = $dbh->prepare_cached( $selectOrphanedStatsSql ) @@ -571,11 +588,15 @@ MAIN: while( $loop ) { #; 'SELECT *, unix_timestamp(StartTime) AS TimeStamp FROM Events WHERE EndTime IS NULL AND StartTime < (now() - interval '.$Config{ZM_AUDIT_MIN_AGE}.' second)'; - my $selectFrameDataSql = 'SELECT max(TimeStamp) as EndTime, unix_timestamp(max(TimeStamp)) AS EndTimeStamp, max(FrameId) as Frames, - count(if(Score>0,1,NULL)) as AlarmFrames, - sum(Score) as TotScore, - max(Score) as MaxScore - FROM Frames WHERE EventId=?'; + my $selectFrameDataSql = ' +SELECT + max(TimeStamp) as EndTime, + unix_timestamp(max(TimeStamp)) AS EndTimeStamp, + max(FrameId) as Frames, + count(if(Score>0,1,NULL)) as AlarmFrames, + sum(Score) as TotScore, + max(Score) as MaxScore +FROM Frames WHERE EventId=?'; my $selectFrameDataSth = $dbh->prepare_cached($selectFrameDataSql) or Fatal( "Can't prepare '$selectFrameDataSql': ".$dbh->errstr() ); @@ -664,6 +685,11 @@ MAIN: while( $loop ) { } } else { # Time of record + + # 7 days is invalid. We need to remove the s + if ( $Config{ZM_LOG_DATABASE_LIMIT} =~ /^(.*)s$/ ) { + $Config{ZM_LOG_DATABASE_LIMIT} = $1; + } my $deleteLogByTimeSql = 'DELETE low_priority FROM Logs WHERE TimeKey < unix_timestamp(now() - interval '.$Config{ZM_LOG_DATABASE_LIMIT}.')'; diff --git a/src/zmc.cpp b/src/zmc.cpp index 4caebb7c0..c278a002c 100644 --- a/src/zmc.cpp +++ b/src/zmc.cpp @@ -222,14 +222,6 @@ int main(int argc, char *argv[]) { } Info("Starting Capture version %s", ZM_VERSION); - static char sql[ZM_SQL_SML_BUFSIZ]; - for ( int i = 0; i < n_monitors; i ++ ) { - snprintf( sql, sizeof(sql), "REPLACE INTO Monitor_Status (MonitorId, Status) VALUES ('%d','Running')", monitors[i]->Id() ); - if ( mysql_query( &dbconn, sql ) ) { - Error( "Can't run query: %s", mysql_error( &dbconn ) ); - } - } - zmSetDefaultTermHandler(); zmSetDefaultDieHandler(); @@ -242,9 +234,15 @@ int main(int argc, char *argv[]) { int result = 0; while( ! zm_terminate ) { result = 0; + static char sql[ZM_SQL_SML_BUFSIZ]; for ( int i = 0; i < n_monitors; i ++ ) { time_t now = (time_t)time(NULL); monitors[i]->setStartupTime(now); + + snprintf( sql, sizeof(sql), "REPLACE INTO Monitor_Status (MonitorId, Status) VALUES ('%d','Running')", monitors[i]->Id() ); + if ( mysql_query( &dbconn, sql ) ) { + Error( "Can't run query: %s", mysql_error( &dbconn ) ); + } } // Outer primary loop, handles connection to camera if ( monitors[0]->PrimeCapture() < 0 ) { @@ -252,7 +250,6 @@ int main(int argc, char *argv[]) { sleep(10); continue; } - static char sql[ZM_SQL_SML_BUFSIZ]; for ( int i = 0; i < n_monitors; i ++ ) { snprintf( sql, sizeof(sql), "REPLACE INTO Monitor_Status (MonitorId, Status) VALUES ('%d','Connected')", monitors[i]->Id() ); if ( mysql_query( &dbconn, sql ) ) { @@ -374,6 +371,15 @@ int main(int argc, char *argv[]) { delete [] analysis_threads; sleep(10); } // end while ! zm_terminate outer connection loop + + for ( int i = 0; i < n_monitors; i++ ) { + static char sql[ZM_SQL_SML_BUFSIZ]; + snprintf( sql, sizeof(sql), "REPLACE INTO Monitor_Status (MonitorId, Status) VALUES ('%d','NotRunning')", monitors[i]->Id() ); + if ( mysql_query( &dbconn, sql ) ) { + Error( "Can't run query: %s", mysql_error( &dbconn ) ); + } + delete monitors[i]; + } delete [] monitors; Image::Deinitialise(); diff --git a/web/includes/Server.php b/web/includes/Server.php index aa93f309c..d76984598 100644 --- a/web/includes/Server.php +++ b/web/includes/Server.php @@ -69,6 +69,7 @@ class Server { if ( $this->Id() ) { return ZM_BASE_PROTOCOL . '://'. $this->Hostname(); } else { + return ZM_BASE_PROTOCOL . '://'. $_SERVER['SERVER_NAME']; return ''; } } diff --git a/web/includes/database.php b/web/includes/database.php index 250e5fce8..f11f50d04 100644 --- a/web/includes/database.php +++ b/web/includes/database.php @@ -132,7 +132,13 @@ function dbQuery( $sql, $params=NULL ) { return NULL; } } else { - $result = $dbConn->query( $sql ); + if ( defined('ZM_DB_DEBUG') ) { + if ( $params ) + Warning("SQL: $sql" . implode(',',$params) ); + else + Warning("SQL: $sql:" ); + } + $result = $dbConn->query($sql); } if ( defined('ZM_DB_DEBUG') ) { if ( $params ) diff --git a/web/skins/classic/css/base/skin.css b/web/skins/classic/css/base/skin.css index e86264989..6983d3715 100644 --- a/web/skins/classic/css/base/skin.css +++ b/web/skins/classic/css/base/skin.css @@ -84,7 +84,7 @@ a:hover { } label { - margin-right: 4px; + margin: 0 4px; } input,textarea,select,button,.btn-primary { @@ -474,6 +474,7 @@ input[type=submit], cursor: pointer; text-decoration: none; display: inline-block; + text-align: center; } button:hover, diff --git a/web/skins/classic/css/base/views/console.css b/web/skins/classic/css/base/views/console.css index db84313d0..88d022683 100644 --- a/web/skins/classic/css/base/views/console.css +++ b/web/skins/classic/css/base/views/console.css @@ -70,12 +70,11 @@ } #consoleTable th,td { - height: 16px; text-align: left; } #consoleTable .colMark { - width: 62px; + width: 52px; text-align: center; } @@ -86,6 +85,10 @@ #consoleTable .colZones { text-align: right; } +#consoleTable .colFunction { + width: 120px; + text-align: center; +} #consoleTable .colLeftButtons { text-align: left; diff --git a/web/skins/classic/css/base/views/montagereview.css b/web/skins/classic/css/base/views/montagereview.css index 4fb55a337..63ce22bd7 100644 --- a/web/skins/classic/css/base/views/montagereview.css +++ b/web/skins/classic/css/base/views/montagereview.css @@ -53,3 +53,6 @@ input[type=range]::-ms-tooltip { #downloadVideo { margin-left: 5px; } +#minTime, #maxTime { +margin: 0 4px; +} diff --git a/web/skins/classic/includes/functions.php b/web/skins/classic/includes/functions.php index 66db14579..e2bf1f549 100644 --- a/web/skins/classic/includes/functions.php +++ b/web/skins/classic/includes/functions.php @@ -147,7 +147,6 @@ echo output_link_if_exists( array( - Logger::NOLOG ) { if ( ! ZM_RUN_AUDIT ) { # zmaudit can clean the logs, but if we aren't running it, then we should clecan them regularly - dbQuery("DELETE FROM Logs WHERE TimeKey < NOW()-to_days('".ZM_LOG_DATABASE_LIMIT."')"); + dbQuery('DELETE FROM Logs WHERE TimeKey < unix_timestamp( NOW() - interval '.ZM_LOG_DATABASE_LIMIT.')'); } echo makePopupLink( '?view=log', 'zmLog', 'log', ''.translate('Log').'' ); } diff --git a/web/skins/classic/views/_monitor_filters.php b/web/skins/classic/views/_monitor_filters.php index 6c9e3f799..72c31f410 100644 --- a/web/skins/classic/views/_monitor_filters.php +++ b/web/skins/classic/views/_monitor_filters.php @@ -43,54 +43,97 @@ foreach ( $storage_areas as $S ) { $StorageById[$S->Id()] = $S; } -?> +$html = +'
- - +'; + $groupSql = ''; - if ( Group::find_all() ) { ?> - - - - - -'; + # This will end up with the group_id of the deepest selection + $group_id = isset($_SESSION['Group']) ? $_SESSION['Group'] : null; + $html .= Group::get_group_dropdown(); + $groupSql = Group::get_group_sql($group_id); + $html .= ''; +} $selected_monitor_ids = isset($_SESSION['MonitorId']) ? $_SESSION['MonitorId'] : array(); if ( ! is_array( $selected_monitor_ids ) ) { Warning("Turning selected_monitor_ids into an array $selected_monitor_ids"); - $selected_monitor_ids = array( $selected_monitor_ids ); + $selected_monitor_ids = array($selected_monitor_ids); } - $conditions = array(); - $values = array(); +$conditions = array(); +$values = array(); - if ( $groupSql ) - $conditions[] = $groupSql; - foreach ( array('ServerId','StorageId','Status') as $filter ) { - if ( isset($_SESSION[$filter]) ) { - if ( is_array($_SESSION[$filter]) ) { - $conditions[] = $filter . ' IN ('.implode(',', array_map(function(){return '?';}, $_SESSION[$filter] ) ). ')'; - $values += $_SESSION[$filter]; +if ( $groupSql ) + $conditions[] = $groupSql; +foreach ( array('ServerId','StorageId','Status') 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] ); } else { - $conditions[] = $filter . '=?'; + $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) ).')'; - $values += $ids; } +} # end foreach filter +if ( ! empty( $user['MonitorIds'] ) ) { + $ids = explode(',', $user['MonitorIds'] ); + $conditions[] = 'M.Id IN ('.implode(',',array_map( function(){return '?';}, $ids) ).')'; + $values += $ids; +} - $sql = 'SELECT *,S.Status AS Status, S.CaptureFPS AS CaptureFPS FROM Monitors AS M LEFT JOIN Monitor_Status AS S ON MonitorId=Id ' . ( count($conditions) ? ' WHERE ' . implode(' AND ', $conditions ) : '' ).' ORDER BY Sequence ASC'; - $monitors = dbFetchAll( $sql, null, $values ); +if ( count($ServersById) > 1 ) { + $html .= ''; + $html .= htmlSelect( 'ServerId[]', $ServersById, + (isset($_SESSION['ServerId'])?$_SESSION['ServerId']:''), + array( + 'onchange'=>'this.form.submit();', + 'class'=>'chosen', + 'multiple'=>'multiple', + 'data-placeholder'=>'All', + ) + ); + $html .= ''; +} # end if have Servers + +if ( count($StorageById) > 1 ) { + $html .= ''; + $html .= htmlSelect( 'StorageId[]',$StorageById, + (isset($_SESSION['StorageId'])?$_SESSION['StorageId']:''), + array( + 'onchange'=>'this.form.submit();', + 'class'=>'chosen', + 'multiple'=>'multiple', + 'data-placeholder'=>'All', + ) ); + $html .= ''; +} # end if have Storage Areas +$html .= ''; +$status_options = array( + 'Connected' => translate('Connected'), + 'Unknown' => translate('Unknown'), + 'NotRunning' => translate('NotRunning'), + 'Running' => translate('Running'), + ); +$html .= htmlSelect( 'Status[]', $status_options, + ( isset($_SESSION['Status']) ? $_SESSION['Status'] : '' ), + array( + 'onchange'=>'this.form.submit();', + 'class'=>'chosen', + 'multiple'=>'multiple', + 'data-placeholder'=>'All' + ) ); + $html .= ''; + + $sql = 'SELECT *,S.Status AS Status, S.CaptureFPS AS CaptureFPS, S.AnalysisFPS AS AnalysisFPS + FROM Monitors AS M LEFT JOIN Monitor_Status AS S ON MonitorId=Id ' . + ( count($conditions) ? ' WHERE ' . implode(' AND ', $conditions) : '' ).' ORDER BY Sequence ASC'; + $monitors = dbFetchAll($sql, null, $values); $displayMonitors = array(); $monitors_dropdown = array(); @@ -99,10 +142,10 @@ if ( ! is_array( $selected_monitor_ids ) ) { $found_selected_monitor = false; for ( $i = 0; $i < count($monitors); $i++ ) { - if ( !visibleMonitor( $monitors[$i]['Id'] ) ) { + if ( !visibleMonitor($monitors[$i]['Id']) ) { continue; } - if ( in_array( $monitors[$i]['Id'], $selected_monitor_ids ) ) { + if ( in_array($monitors[$i]['Id'], $selected_monitor_ids) ) { $found_selected_monitor = true; } } // end foreach monitor @@ -112,13 +155,13 @@ if ( ! is_array( $selected_monitor_ids ) ) { } // end if a monitor was specified for ( $i = 0; $i < count($monitors); $i++ ) { - if ( !visibleMonitor( $monitors[$i]['Id'] ) ) { - Warning("Monitor " . $monitors[$i]['Id'] . ' is not visible' ); + if ( !visibleMonitor($monitors[$i]['Id']) ) { + Warning('Monitor '.$monitors[$i]['Id'].' is not visible'); continue; } $monitors_dropdown[$monitors[$i]['Id']] = $monitors[$i]['Name']; - if ( count($selected_monitor_ids) and ! in_array( $monitors[$i]['Id'], $selected_monitor_ids ) ) { + if ( count($selected_monitor_ids) and ! in_array($monitors[$i]['Id'], $selected_monitor_ids) ) { continue; } if ( isset($_SESSION['StatusFilter']) ) { @@ -128,64 +171,17 @@ if ( ! is_array( $selected_monitor_ids ) ) { } $displayMonitors[] = $monitors[$i]; } - echo htmlSelect( 'MonitorId[]', $monitors_dropdown, $selected_monitor_ids, + $html .= ''; + $html .= htmlSelect( 'MonitorId[]', $monitors_dropdown, $selected_monitor_ids, array( 'onchange'=>'this.form.submit();', 'class'=>'chosen', 'multiple'=>'multiple', 'data-placeholder'=>'All', ) ); +# Repurpose this variable to be the list of MonitorIds as a result of all the filtering +$selected_monitor_ids = array_map(function($monitor_row){return $monitor_row['Id'];}, $displayMonitors); + $html .= ''; + echo $html; ?> - - 1 ) { -?> - -'this.form.submit();', - 'class'=>'chosen', - 'multiple'=>'multiple', - 'data-placeholder'=>'All', - ) - ); -?> - - 1 ) { ?> - -'this.form.submit();', - 'class'=>'chosen', - 'multiple'=>'multiple', - 'data-placeholder'=>'All', - ) ); -?> - - - - translate('Unknown'), - 'NotRunning' => translate('NotRunning'), - 'Running' => translate('Running'), - ); -echo htmlSelect( 'Status[]', $status_options, - ( isset($_SESSION['Status']) ? $_SESSION['Status'] : '' ), - array( - 'onchange'=>'this.form.submit();', - 'class'=>'chosen', - 'multiple'=>'multiple', - 'data-placeholder'=>'All' - ) ); -?> -
diff --git a/web/skins/classic/views/console.php b/web/skins/classic/views/console.php index 0687c4088..2dea894a4 100644 --- a/web/skins/classic/views/console.php +++ b/web/skins/classic/views/console.php @@ -113,7 +113,6 @@ for ( $i = 0; $i < count($displayMonitors); $i++ ) { if ( $maxWidth < $scaleWidth ) $maxWidth = $scaleWidth; if ( $maxHeight < $scaleHeight ) $maxHeight = $scaleHeight; } - $monitor['zmc'] = zmcStatus( $monitor ); $zoneCount += $monitor['ZoneCount']; $counts = array(); @@ -184,33 +183,41 @@ for( $monitor_i = 0; $monitor_i < count($displayMonitors); $monitor_i += 1 ) { ?> >>>>>> storageareas } if ( $monitor['Function'] == 'None' ) $fclass = 'errorText'; - //elseif ( $monitor['Function'] == 'Monitor' ) - // $fclass = 'warnText'; else $fclass = 'infoText'; if ( !$monitor['Enabled'] ) $fclass .= ' disabledText'; $scale = max( reScale( SCALE_BASE, $monitor['DefaultScale'], ZM_WEB_DEFAULT_SCALE ), SCALE_BASE ); -?> - - ' : '>') . $monitor['Id'] ?> + ' : '>') . $monitor['Id'] ?> - ' : '>') . $monitor['Name'] ?> + ' : '>') . $monitor['Name'] ?>
'.translate('Fn'.$monitor['Function']).( empty($monitor['Enabled']) ? ', disabled' : '' ) .'', canEdit( 'Monitors' ) ) ?>
'. makePopupLink( '?view=monitor&mid='.$monitor['Id'], 'zmMonitor'.$monitor['Id'], 'monitor', ''.$source.'', canEdit( 'Monitors' ) ).''; + echo ''. makePopupLink( '?view=monitor&mid='.$monitor['Id'], 'zmMonitor'.$monitor['Id'], 'monitor', ''.$source.'', canEdit( 'Monitors' ) ).''; if ( $show_storage_areas ) { ?> - Name(); } ?> + Name(); } ?> var currentScale=; -var liveMode=; +var liveMode=; var fitMode=; var currentSpeed=; // slider scale, which is only for replay and relative to real time var speedIndex=; @@ -33,16 +33,16 @@ var eventFrames = []; // this is going to presume all frames equal du // Because we might not have time as the criteria, figure out the min/max time when we run the query if ( ! $maxTimeSecs ) -$maxTimeSecs = time(); + $maxTimeSecs = time(); if ( ! $minTimeSecs ) -$minTimeSecs = strtotime('2010-01-01 01:01:01'); + $minTimeSecs = strtotime('2010-01-01 01:01:01'); // This builds the list of events that are eligible from this range $index = 0; $anyAlarms = false; -if ( ! $initialModeIsLive ) { +if ( ! $liveMode ) { $result = dbQuery( $eventsSql ); if ( ! $result ) { Fatal('SQL-ERR'); @@ -51,14 +51,17 @@ if ( ! $initialModeIsLive ) { while( $event = $result->fetch( PDO::FETCH_ASSOC ) ) { - if ( $minTimeSecs > $event['StartTimeSecs'] ) $minTimeSecs = $event['StartTimeSecs']; - if ( $maxTimeSecs < $event['CalcEndTimeSecs'] ) $maxTimeSecs = $event['CalcEndTimeSecs']; + $StartTimeSecs = strtotime($event['StartTime']); + $EndTimeSecs = strtotime($event['EndTime']); + + if ( $minTimeSecs > $StartTimeSecs ) $minTimeSecs = $StartTimeSecs; + if ( $maxTimeSecs < $EndTimeSecs ) $maxTimeSecs = $EndTimeSecs; echo " eMonId[$index]=" . $event['MonitorId'] . "; eStorageId[$index]=".$event['StorageId'] . "; eId[$index]=" . $event['Id'] . "; -eStartSecs[$index]=" . $event['StartTimeSecs'] . "; -eEndSecs[$index]=" . $event['CalcEndTimeSecs'] . "; +eStartSecs[$index]=" . $StartTimeSecs . "; +eEndSecs[$index]=" . $EndTimeSecs . "; eventFrames[$index]=" . $event['Frames'] . "; "; diff --git a/web/skins/classic/views/montagereview.php b/web/skins/classic/views/montagereview.php index a4384667a..1299473ad 100644 --- a/web/skins/classic/views/montagereview.php +++ b/web/skins/classic/views/montagereview.php @@ -49,7 +49,7 @@ // change the playback slider to 0 and then it does not try to play at the same time it is scrubbing. // -if ( !canView( 'Events' ) ) { +if ( !canView('Events') ) { $view = 'error'; return; } @@ -68,9 +68,10 @@ if (isset($_REQUEST['minTime']) && isset($_REQUEST['maxTime']) && count($display ) ), ); - if (count($selected_monitor_ids) ) { + if ( count($selected_monitor_ids) ) { $filter['Query']['terms'][] = (array('attr' => 'MonitorId', 'op' => 'IN', 'val' => implode(',',$selected_monitor_ids), 'cnj' => 'and')); } else if ( ( $group_id != 0 || isset($_SESSION['ServerFilter']) || isset($_SESSION['StorageFilter']) || isset($_SESSION['StatusFilter']) ) ) { +# this should be redundant for ($i=0; $i < count($displayMonitors); $i++) { if ($i == '0') { $filter['Query']['terms'][] = array('attr' => 'MonitorId', 'op' => '=', 'val' => $displayMonitors[$i]['Id'], 'cnj' => 'and', 'obr' => '1'); @@ -94,14 +95,14 @@ if (isset($_REQUEST['minTime']) && isset($_REQUEST['maxTime']) && count($display // Note we round up just a bit on the end time as otherwise you get gaps, like 59.78 to 00 in the next second, which can give blank frames when moved through slowly. $eventsSql = ' - SELECT E.Id,E.Name,E.StorageId,UNIX_TIMESTAMP(E.StartTime) AS StartTimeSecs, - CASE WHEN E.EndTime IS NULL THEN (SELECT UNIX_TIMESTAMP(DATE_ADD(E.StartTime, Interval max(Delta)+0.5 Second)) FROM Frames F WHERE F.EventId=E.Id) - ELSE UNIX_TIMESTAMP(E.EndTime) - END AS CalcEndTimeSecs, E.Length, - CASE WHEN E.Frames IS NULL THEN (Select count(*) FROM Frames F WHERE F.EventId=E.Id) ELSE E.Frames END AS Frames,E.MaxScore,E.Cause,E.Notes,E.Archived,E.MonitorId + SELECT E.Id,E.Name,E.StorageId,E.StartTime AS StartTime, + CASE WHEN E.EndTime IS NULL THEN (SELECT NOW()) ELSE E.EndTime END AS EndTime, + E.Length, + CASE WHEN E.Frames IS NULL THEN (SELECT COUNT(*) FROM Frames F WHERE F.EventId=E.Id) ELSE E.Frames END AS Frames, + E.MaxScore,E.Cause,E.Notes,E.Archived,E.MonitorId FROM Events AS E - INNER JOIN Monitors AS M ON (E.MonitorId = M.Id) - WHERE NOT isnull(E.Frames) AND NOT isnull(StartTime)'; + WHERE NOT isnull(E.Frames) +'; // select E.Id,E.Name,UNIX_TIMESTAMP(E.StartTime) as StartTimeSecs,UNIX_TIMESTAMP(max(DATE_ADD(E.StartTime, Interval Delta+0.5 Second))) as CalcEndTimeSecs, E.Length,max(F.FrameId) as Frames,E.MaxScore,E.Cause,E.Notes,E.Archived,E.MonitorId // from Events as E @@ -114,17 +115,18 @@ $frameSql = ' SELECT E.Id AS eId, E.MonitorId, UNIX_TIMESTAMP(DATE_ADD(E.StartTime, Interval Delta Second)) AS TimeStampSecs, max(F.Score) AS Score FROM Events AS E INNER JOIN Frames AS F ON (F.EventId = E.Id) - WHERE NOT isnull(StartTime) AND F.Score>0'; + WHERE F.Score>0 +'; // This program only calls itself with the time range involved -- it does all monitors (the user can see, in the called group) all the time -if ( ! empty( $user['MonitorIds'] ) ) { - $eventsSql .= ' AND M.Id IN ('.$user['MonitorIds'].')'; +if ( ! empty($user['MonitorIds']) ) { + $eventsSql .= ' AND E.MonitorId IN ('.$user['MonitorIds'].')'; $frameSql .= ' AND E.MonitorId IN ('.$user['MonitorIds'].')'; } if ( count($selected_monitor_ids) ) { $monitor_ids_sql = ' IN (' . implode(',',$selected_monitor_ids).')'; - $eventsSql .= ' AND M.Id '.$monitor_ids_sql; + $eventsSql .= ' AND E.MonitorId '.$monitor_ids_sql; $frameSql .= ' AND E.MonitorId '.$monitor_ids_sql; } @@ -135,9 +137,8 @@ if ( count($selected_monitor_ids) ) { if ( !isset($_REQUEST['minTime']) && !isset($_REQUEST['maxTime']) ) { $time = time(); - $maxTime = strftime("%FT%T",$time); - $minTime = strftime("%FT%T",$time - 3600); - Logger::Debug("Defaulting to $minTime to $maxTime"); + $maxTime = strftime('%FT%T',$time); + $minTime = strftime('%FT%T',$time - 3600); } if ( isset($_REQUEST['minTime']) ) $minTime = validHtmlStr($_REQUEST['minTime']); @@ -162,7 +163,7 @@ if ( isset($_REQUEST['scale']) ) else $defaultScale = 1; -$speeds=[0, 0.1, 0.25, 0.5, 0.75, 1.0, 1.5, 2, 3, 5, 10, 20, 50]; +$speeds = [0, 0.1, 0.25, 0.5, 0.75, 1.0, 1.5, 2, 3, 5, 10, 20, 50]; if ( isset($_REQUEST['speed']) ) $defaultSpeed = validHtmlStr($_REQUEST['speed']); @@ -180,21 +181,21 @@ for ( $i = 0; $i < count($speeds); $i++ ) { if ( isset($_REQUEST['current']) ) $defaultCurrentTime = validHtmlStr($_REQUEST['current']); -$initialModeIsLive = 1; +$liveMode = 1; // default to live if ( isset($_REQUEST['live']) && $_REQUEST['live']=='0' ) - $initialModeIsLive=0; + $liveMode=0; $initialDisplayInterval = 1000; if ( isset($_REQUEST['displayinterval']) ) $initialDisplayInterval = validHtmlStr($_REQUEST['displayinterval']); -$eventsSql .= ' GROUP BY E.Id,E.Name,E.StartTime,E.Length,E.Frames,E.MaxScore,E.Cause,E.Notes,E.Archived,E.MonitorId'; +#$eventsSql .= ' GROUP BY E.Id,E.Name,E.StartTime,E.Length,E.Frames,E.MaxScore,E.Cause,E.Notes,E.Archived,E.MonitorId'; if ( isset($minTime) && isset($maxTime) ) { $minTimeSecs = strtotime($minTime); $maxTimeSecs = strtotime($maxTime); Logger::Debug("Min/max time secs: $minTimeSecs $maxTimeSecs"); - $eventsSql .= " HAVING CalcEndTimeSecs > '" . $minTimeSecs . "' AND StartTimeSecs < '" . $maxTimeSecs . "'"; + $eventsSql .= " AND EndTime > '" . $minTime . "' AND StartTime < '" . $maxTime . "'"; $frameSql .= " AND TimeStamp > '" . $minTime . "' AND TimeStamp < '" . $maxTime . "'"; } $frameSql .= ' GROUP BY E.Id, E.MonitorId, F.TimeStamp, F.Delta ORDER BY E.MonitorId, F.TimeStamp ASC'; @@ -213,9 +214,9 @@ xhtmlHeaders(__FILE__, translate('MontageReview') ); ?>
- -
- + + + + +