Merge branch 'storageareas' into zma_to_thread

This commit is contained in:
Isaac Connor 2018-02-12 17:16:33 -05:00
commit a82e17ff4b
17 changed files with 273 additions and 201 deletions

View File

@ -256,7 +256,7 @@ FOR EACH ROW
END IF; END IF;
END IF; END IF;
END; END;
//
DELIMITER ; DELIMITER ;
DROP TABLE IF EXISTS `Events_Day`; DROP TABLE IF EXISTS `Events_Day`;

View File

@ -470,7 +470,7 @@ sub DiskSpace {
$_[0]{DiskSpace} = $size; $_[0]{DiskSpace} = $size;
Debug("DiskSpace for event $_[0]{Id} at $_[0]{Path} Updated to $size bytes"); Debug("DiskSpace for event $_[0]{Id} at $_[0]{Path} Updated to $size bytes");
} else { } 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 } # end if ! defined DiskSpace
return $_[0]{DiskSpace}; return $_[0]{DiskSpace};

View File

@ -714,6 +714,9 @@ sub error {
sub Fatal( @ ) { sub Fatal( @ ) {
fetch()->logPrint( FATAL, @_ ); fetch()->logPrint( FATAL, @_ );
if ( $SIG{TERM} ne 'DEFAULT' ) {
$SIG{TERM}();
}
exit( -1 ); exit( -1 );
} }

View File

@ -159,14 +159,14 @@ MAIN: while( $loop ) {
while ( ! ( $dbh and $dbh->ping() ) ) { while ( ! ( $dbh and $dbh->ping() ) ) {
$dbh = zmDbConnect(); $dbh = zmDbConnect();
if ( ! $dbh ) { if ( ! $dbh ) {
Error('Unable to connect to database');
if ( $continuous ) { if ( $continuous ) {
Error('Unable to connect to database');
# if we are running continuously, then just skip to the next # if we are running continuously, then just skip to the next
# interval, otherwise we are a one off run, so wait a second and # interval, otherwise we are a one off run, so wait a second and
# retry until someone kills us. # retry until someone kills us.
sleep( $Config{ZM_AUDIT_CHECK_INTERVAL} ); sleep( $Config{ZM_AUDIT_CHECK_INTERVAL} );
} else { } else {
Fatal('Unable to connect to database'); Term();
} # end if } # end if
} # end if } # end if
} # end while can't connect to the db } # end while can't connect to the db
@ -175,13 +175,15 @@ MAIN: while( $loop ) {
if ( defined $storage_id ) { if ( defined $storage_id ) {
@Storage_Areas = ZoneMinder::Storage->find( Id=>$storage_id ); @Storage_Areas = ZoneMinder::Storage->find( Id=>$storage_id );
if ( !@Storage_Areas ) { 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}"); Info("Auditing Storage Area $Storage_Areas[0]{Id} $Storage_Areas[0]{Name} at $Storage_Areas[0]{Path}");
} elsif ( $Config{ZM_SERVER_ID} ) { } elsif ( $Config{ZM_SERVER_ID} ) {
@Storage_Areas = ZoneMinder::Storage->find( ServerId => $Config{ZM_SERVER_ID} ); @Storage_Areas = ZoneMinder::Storage->find( ServerId => $Config{ZM_SERVER_ID} );
if ( ! @Storage_Areas ) { 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()); Info("Auditing All Storage Areas on Server " . $Storage_Areas[0]->Server()->Name());
} else { } else {
@ -465,10 +467,10 @@ MAIN: while( $loop ) {
} # end if exists in filesystem } # end if exists in filesystem
} # end if ! in fs_events } # end if ! in fs_events
} # foreach db_event } # foreach db_event
} else { #} else {
my $Monitor = new ZoneMinder::Monitor( $db_monitor ); #my $Monitor = new ZoneMinder::Monitor( $db_monitor );
my $Storage = $Monitor->Storage(); #my $Storage = $Monitor->Storage();
aud_print( "Database monitor '$db_monitor' does not exist in filesystem, should have been at ".$Storage->Path().'/'.$Monitor->Id()."\n" ); #aud_print( "Database monitor '$db_monitor' does not exist in filesystem, should have been at ".$Storage->Path().'/'.$Monitor->Id()."\n" );
#if ( confirm() ) #if ( confirm() )
#{ #{
# We don't actually do this in case it's new # We don't actually do this in case it's new
@ -478,48 +480,62 @@ MAIN: while( $loop ) {
#} #}
} }
} # end foreach db_monitor } # end foreach db_monitor
redo MAIN if ( $cleaned ); if ( $cleaned ) {
Debug("Have done some cleaning, restarting.");
redo MAIN;
}
# Remove orphaned events (with no monitor) # Remove orphaned events (with no monitor)
$cleaned = 0; $cleaned = 0;
Debug("Checking for Orphaned Events");
my $selectOrphanedEventsSql = 'SELECT Events.Id, Events.Name my $selectOrphanedEventsSql = 'SELECT Events.Id, Events.Name
FROM Events LEFT JOIN Monitors ON (Events.MonitorId = Monitors.Id) FROM Events LEFT JOIN Monitors ON (Events.MonitorId = Monitors.Id)
WHERE isnull(Monitors.Id)'; WHERE isnull(Monitors.Id)';
my $selectOrphanedEventsSth = $dbh->prepare_cached( $selectOrphanedEventsSql ) 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() $res = $selectOrphanedEventsSth->execute()
or Fatal( "Can't execute: ".$selectOrphanedEventsSth->errstr() ); or Error( "Can't execute: ".$selectOrphanedEventsSth->errstr() );
while( my $event = $selectOrphanedEventsSth->fetchrow_hashref() ) { while( my $event = $selectOrphanedEventsSth->fetchrow_hashref() ) {
aud_print( "Found orphaned event with no monitor '$event->{Id}'" ); aud_print( "Found orphaned event with no monitor '$event->{Id}'" );
if ( confirm() ) { if ( confirm() ) {
$res = $deleteEventSth->execute( $event->{Id} ) if ( $res = $deleteEventSth->execute( $event->{Id} ) ) {
or Fatal( "Can't execute: ".$deleteEventSth->errstr() ); $cleaned = 1;
$cleaned = 1; } else {
Error( "Can't execute: ".$deleteEventSth->errstr() );
}
} }
} }
redo MAIN if ( $cleaned ); redo MAIN if $cleaned;
# Remove empty events (with no frames) # Remove empty events (with no frames)
$cleaned = 0; $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) 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'; WHERE isnull(F.EventId) AND now() - interval '.$Config{ZM_AUDIT_MIN_AGE}.' second > E.StartTime';
my $selectEmptyEventsSth = $dbh->prepare_cached( $selectEmptyEventsSql ) if ( my $selectEmptyEventsSth = $dbh->prepare_cached( $selectEmptyEventsSql ) ) {
or Fatal( "Can't prepare '$selectEmptyEventsSql': ".$dbh->errstr() ); if ( $res = $selectEmptyEventsSth->execute() ) {
$res = $selectEmptyEventsSth->execute() while( my $event = $selectEmptyEventsSth->fetchrow_hashref() ) {
or Fatal( "Can't execute: ".$selectEmptyEventsSth->errstr() ); aud_print( "Found empty event with no frame records '$event->{Id}' at $$event{StartTime}" );
while( my $event = $selectEmptyEventsSth->fetchrow_hashref() ) { if ( confirm() ) {
aud_print( "Found empty event with no frame records '$event->{Id}' at $$event{StartTime}" ); if ( $res = $deleteEventSth->execute( $event->{Id} ) ) {
if ( confirm() ) { $cleaned = 1;
$res = $deleteEventSth->execute( $event->{Id} ) } else {
or Fatal( "Can't execute: ".$deleteEventSth->errstr() ); Error( "Can't execute: ".$deleteEventSth->errstr() );
$cleaned = 1; }
}
} # 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 # Remove orphaned frame records
$cleaned = 0; $cleaned = 0;
Debug("Checking for Orphaned Frames");
my $selectOrphanedFramesSql = 'SELECT DISTINCT EventId FROM Frames my $selectOrphanedFramesSql = 'SELECT DISTINCT EventId FROM Frames
WHERE EventId NOT IN (SELECT Id FROM Events)'; WHERE EventId NOT IN (SELECT Id FROM Events)';
my $selectOrphanedFramesSth = $dbh->prepare_cached( $selectOrphanedFramesSql ) my $selectOrphanedFramesSth = $dbh->prepare_cached( $selectOrphanedFramesSql )
@ -534,10 +550,11 @@ MAIN: while( $loop ) {
$cleaned = 1; $cleaned = 1;
} }
} }
redo MAIN if ( $cleaned ); redo MAIN if $cleaned;
# Remove orphaned stats records # Remove orphaned stats records
$cleaned = 0; $cleaned = 0;
Debug("Checking for Orphaned Stats");
my $selectOrphanedStatsSql = 'SELECT DISTINCT EventId FROM Stats my $selectOrphanedStatsSql = 'SELECT DISTINCT EventId FROM Stats
WHERE EventId NOT IN (SELECT Id FROM Events)'; WHERE EventId NOT IN (SELECT Id FROM Events)';
my $selectOrphanedStatsSth = $dbh->prepare_cached( $selectOrphanedStatsSql ) 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)'; '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, my $selectFrameDataSql = '
count(if(Score>0,1,NULL)) as AlarmFrames, SELECT
sum(Score) as TotScore, max(TimeStamp) as EndTime,
max(Score) as MaxScore unix_timestamp(max(TimeStamp)) AS EndTimeStamp,
FROM Frames WHERE EventId=?'; 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) my $selectFrameDataSth = $dbh->prepare_cached($selectFrameDataSql)
or Fatal( "Can't prepare '$selectFrameDataSql': ".$dbh->errstr() ); or Fatal( "Can't prepare '$selectFrameDataSql': ".$dbh->errstr() );
@ -664,6 +685,11 @@ MAIN: while( $loop ) {
} }
} else { } else {
# Time of record # 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 = my $deleteLogByTimeSql =
'DELETE low_priority FROM Logs 'DELETE low_priority FROM Logs
WHERE TimeKey < unix_timestamp(now() - interval '.$Config{ZM_LOG_DATABASE_LIMIT}.')'; WHERE TimeKey < unix_timestamp(now() - interval '.$Config{ZM_LOG_DATABASE_LIMIT}.')';

View File

@ -222,14 +222,6 @@ int main(int argc, char *argv[]) {
} }
Info("Starting Capture version %s", ZM_VERSION); 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(); zmSetDefaultTermHandler();
zmSetDefaultDieHandler(); zmSetDefaultDieHandler();
@ -242,9 +234,15 @@ int main(int argc, char *argv[]) {
int result = 0; int result = 0;
while( ! zm_terminate ) { while( ! zm_terminate ) {
result = 0; result = 0;
static char sql[ZM_SQL_SML_BUFSIZ];
for ( int i = 0; i < n_monitors; i ++ ) { for ( int i = 0; i < n_monitors; i ++ ) {
time_t now = (time_t)time(NULL); time_t now = (time_t)time(NULL);
monitors[i]->setStartupTime(now); 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 // Outer primary loop, handles connection to camera
if ( monitors[0]->PrimeCapture() < 0 ) { if ( monitors[0]->PrimeCapture() < 0 ) {
@ -252,7 +250,6 @@ int main(int argc, char *argv[]) {
sleep(10); sleep(10);
continue; continue;
} }
static char sql[ZM_SQL_SML_BUFSIZ];
for ( int i = 0; i < n_monitors; i ++ ) { for ( int i = 0; i < n_monitors; i ++ ) {
snprintf( sql, sizeof(sql), "REPLACE INTO Monitor_Status (MonitorId, Status) VALUES ('%d','Connected')", monitors[i]->Id() ); snprintf( sql, sizeof(sql), "REPLACE INTO Monitor_Status (MonitorId, Status) VALUES ('%d','Connected')", monitors[i]->Id() );
if ( mysql_query( &dbconn, sql ) ) { if ( mysql_query( &dbconn, sql ) ) {
@ -374,6 +371,15 @@ int main(int argc, char *argv[]) {
delete [] analysis_threads; delete [] analysis_threads;
sleep(10); sleep(10);
} // end while ! zm_terminate outer connection loop } // 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; delete [] monitors;
Image::Deinitialise(); Image::Deinitialise();

View File

@ -69,6 +69,7 @@ class Server {
if ( $this->Id() ) { if ( $this->Id() ) {
return ZM_BASE_PROTOCOL . '://'. $this->Hostname(); return ZM_BASE_PROTOCOL . '://'. $this->Hostname();
} else { } else {
return ZM_BASE_PROTOCOL . '://'. $_SERVER['SERVER_NAME'];
return ''; return '';
} }
} }

View File

@ -132,7 +132,13 @@ function dbQuery( $sql, $params=NULL ) {
return NULL; return NULL;
} }
} else { } 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 ( defined('ZM_DB_DEBUG') ) {
if ( $params ) if ( $params )

View File

@ -84,7 +84,7 @@ a:hover {
} }
label { label {
margin-right: 4px; margin: 0 4px;
} }
input,textarea,select,button,.btn-primary { input,textarea,select,button,.btn-primary {
@ -474,6 +474,7 @@ input[type=submit],
cursor: pointer; cursor: pointer;
text-decoration: none; text-decoration: none;
display: inline-block; display: inline-block;
text-align: center;
} }
button:hover, button:hover,

View File

@ -70,12 +70,11 @@
} }
#consoleTable th,td { #consoleTable th,td {
height: 16px;
text-align: left; text-align: left;
} }
#consoleTable .colMark { #consoleTable .colMark {
width: 62px; width: 52px;
text-align: center; text-align: center;
} }
@ -86,6 +85,10 @@
#consoleTable .colZones { #consoleTable .colZones {
text-align: right; text-align: right;
} }
#consoleTable .colFunction {
width: 120px;
text-align: center;
}
#consoleTable .colLeftButtons { #consoleTable .colLeftButtons {
text-align: left; text-align: left;

View File

@ -53,3 +53,6 @@ input[type=range]::-ms-tooltip {
#downloadVideo { #downloadVideo {
margin-left: 5px; margin-left: 5px;
} }
#minTime, #maxTime {
margin: 0 4px;
}

View File

@ -147,7 +147,6 @@ echo output_link_if_exists( array(
<?php <?php
} else if ( $view == 'watch' ) { } else if ( $view == 'watch' ) {
?> ?>
<link href="<?php echo cache_bust($viewCssFileExtra) ?>" rel="stylesheet">
<?php <?php
} }
if ( $skinJsPhpFile ) { if ( $skinJsPhpFile ) {
@ -249,7 +248,7 @@ function getNavBarHTML($reload = null) {
if ( logToDatabase() > Logger::NOLOG ) { if ( logToDatabase() > Logger::NOLOG ) {
if ( ! ZM_RUN_AUDIT ) { if ( ! ZM_RUN_AUDIT ) {
# zmaudit can clean the logs, but if we aren't running it, then we should clecan them regularly # 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', '<span class="'.logState().'">'.translate('Log').'</span>' ); echo makePopupLink( '?view=log', 'zmLog', 'log', '<span class="'.logState().'">'.translate('Log').'</span>' );
} }

View File

@ -43,54 +43,97 @@ foreach ( $storage_areas as $S ) {
$StorageById[$S->Id()] = $S; $StorageById[$S->Id()] = $S;
} }
?> $html =
'
<div class="controlHeader"> <div class="controlHeader">
<input type="hidden" name="filtering" value="" /> <input type="hidden" name="filtering" value=""/>
<?php ';
$groupSql = ''; $groupSql = '';
if ( Group::find_all() ) { ?> if ( Group::find_all() ) {
<span id="groupControl"><label><?php echo translate('Group') ?>:</label> $html .= '<span id="groupControl"><label>'. translate('Group') .':</label>';
<?php # 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 = isset($_SESSION['Group']) ? $_SESSION['Group'] : null;
$group_id = isset($_SESSION['Group']) ? $_SESSION['Group'] : null; $html .= Group::get_group_dropdown();
echo Group::get_group_dropdown(); $groupSql = Group::get_group_sql($group_id);
$groupSql = Group::get_group_sql( $group_id ); $html .= '</span>';
?> }
</span>
<?php } ?>
<span id="monitorControl"><label><?php echo translate('Monitor') ?>:</label>
<?php
$selected_monitor_ids = isset($_SESSION['MonitorId']) ? $_SESSION['MonitorId'] : array(); $selected_monitor_ids = isset($_SESSION['MonitorId']) ? $_SESSION['MonitorId'] : array();
if ( ! is_array( $selected_monitor_ids ) ) { if ( ! is_array( $selected_monitor_ids ) ) {
Warning("Turning selected_monitor_ids into an 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(); $conditions = array();
$values = array(); $values = array();
if ( $groupSql ) if ( $groupSql )
$conditions[] = $groupSql; $conditions[] = $groupSql;
foreach ( array('ServerId','StorageId','Status') as $filter ) { foreach ( array('ServerId','StorageId','Status') as $filter ) {
if ( isset($_SESSION[$filter]) ) { if ( isset($_SESSION[$filter]) ) {
if ( is_array($_SESSION[$filter]) ) { if ( is_array($_SESSION[$filter]) ) {
$conditions[] = $filter . ' IN ('.implode(',', array_map(function(){return '?';}, $_SESSION[$filter] ) ). ')'; $conditions[] = $filter . ' IN ('.implode(',', array_map(function(){return '?';}, $_SESSION[$filter] ) ). ')';
$values += $_SESSION[$filter]; $values = array_merge( $values, $_SESSION[$filter] );
} else { } else {
$conditions[] = $filter . '=?'; $conditions[] = $filter . '=?';
$values[] = $_SESSION[$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'; if ( count($ServersById) > 1 ) {
$monitors = dbFetchAll( $sql, null, $values ); $html .= '<span class="ServerFilter"><label>'. translate('Server').':</label>';
$html .= htmlSelect( 'ServerId[]', $ServersById,
(isset($_SESSION['ServerId'])?$_SESSION['ServerId']:''),
array(
'onchange'=>'this.form.submit();',
'class'=>'chosen',
'multiple'=>'multiple',
'data-placeholder'=>'All',
)
);
$html .= '</span>';
} # end if have Servers
if ( count($StorageById) > 1 ) {
$html .= '<span class="StorageFilter"><label>'.translate('Storage').':</label>';
$html .= htmlSelect( 'StorageId[]',$StorageById,
(isset($_SESSION['StorageId'])?$_SESSION['StorageId']:''),
array(
'onchange'=>'this.form.submit();',
'class'=>'chosen',
'multiple'=>'multiple',
'data-placeholder'=>'All',
) );
$html .= '</span>';
} # end if have Storage Areas
$html .= '<span class="StatusFilter"><label>'. translate('Status') . ':</label>';
$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 .= '</span>';
$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(); $displayMonitors = array();
$monitors_dropdown = array(); $monitors_dropdown = array();
@ -99,10 +142,10 @@ if ( ! is_array( $selected_monitor_ids ) ) {
$found_selected_monitor = false; $found_selected_monitor = false;
for ( $i = 0; $i < count($monitors); $i++ ) { for ( $i = 0; $i < count($monitors); $i++ ) {
if ( !visibleMonitor( $monitors[$i]['Id'] ) ) { if ( !visibleMonitor($monitors[$i]['Id']) ) {
continue; continue;
} }
if ( in_array( $monitors[$i]['Id'], $selected_monitor_ids ) ) { if ( in_array($monitors[$i]['Id'], $selected_monitor_ids) ) {
$found_selected_monitor = true; $found_selected_monitor = true;
} }
} // end foreach monitor } // end foreach monitor
@ -112,13 +155,13 @@ if ( ! is_array( $selected_monitor_ids ) ) {
} // end if a monitor was specified } // end if a monitor was specified
for ( $i = 0; $i < count($monitors); $i++ ) { for ( $i = 0; $i < count($monitors); $i++ ) {
if ( !visibleMonitor( $monitors[$i]['Id'] ) ) { if ( !visibleMonitor($monitors[$i]['Id']) ) {
Warning("Monitor " . $monitors[$i]['Id'] . ' is not visible' ); Warning('Monitor '.$monitors[$i]['Id'].' is not visible');
continue; continue;
} }
$monitors_dropdown[$monitors[$i]['Id']] = $monitors[$i]['Name']; $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; continue;
} }
if ( isset($_SESSION['StatusFilter']) ) { if ( isset($_SESSION['StatusFilter']) ) {
@ -128,64 +171,17 @@ if ( ! is_array( $selected_monitor_ids ) ) {
} }
$displayMonitors[] = $monitors[$i]; $displayMonitors[] = $monitors[$i];
} }
echo htmlSelect( 'MonitorId[]', $monitors_dropdown, $selected_monitor_ids, $html .= '<span id="monitorControl"><label>'.translate('Monitor').':</label>';
$html .= htmlSelect( 'MonitorId[]', $monitors_dropdown, $selected_monitor_ids,
array( array(
'onchange'=>'this.form.submit();', 'onchange'=>'this.form.submit();',
'class'=>'chosen', 'class'=>'chosen',
'multiple'=>'multiple', 'multiple'=>'multiple',
'data-placeholder'=>'All', '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 .= '</span>';
echo $html;
?> ?>
</span>
<?php
if ( count($ServersById) > 1 ) {
?>
<span class="ServerFilter"><label><?php echo translate('Server')?>:</label>
<?php
echo htmlSelect( 'ServerId[]', $ServersById,
(isset($_SESSION['ServerId'])?$_SESSION['ServerId']:''),
array(
'onchange'=>'this.form.submit();',
'class'=>'chosen',
'multiple'=>'multiple',
'data-placeholder'=>'All',
)
);
?>
</span>
<?php
}
if ( count($StorageById) > 1 ) { ?>
<span class="StorageFilter"><label><?php echo translate('Storage')?>:</label>
<?php
echo htmlSelect( 'StorageId[]',$StorageById,
(isset($_SESSION['StorageId'])?$_SESSION['StorageId']:''),
array(
'onchange'=>'this.form.submit();',
'class'=>'chosen',
'multiple'=>'multiple',
'data-placeholder'=>'All',
) );
?>
</span>
<?php
}
?>
<span class="StatusFilter"><label><?php echo translate('Status')?>:</label>
<?php
$status_options = array(
'Unknown' => 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'
) );
?>
</span>
</div> </div>

View File

@ -113,7 +113,6 @@ for ( $i = 0; $i < count($displayMonitors); $i++ ) {
if ( $maxWidth < $scaleWidth ) $maxWidth = $scaleWidth; if ( $maxWidth < $scaleWidth ) $maxWidth = $scaleWidth;
if ( $maxHeight < $scaleHeight ) $maxHeight = $scaleHeight; if ( $maxHeight < $scaleHeight ) $maxHeight = $scaleHeight;
} }
$monitor['zmc'] = zmcStatus( $monitor );
$zoneCount += $monitor['ZoneCount']; $zoneCount += $monitor['ZoneCount'];
$counts = array(); $counts = array();
@ -184,33 +183,41 @@ for( $monitor_i = 0; $monitor_i < count($displayMonitors); $monitor_i += 1 ) {
?> ?>
<tr id="<?php echo 'monitor_id-'.$monitor['Id'] ?>" title="<?php echo $monitor['Id'] ?>"> <tr id="<?php echo 'monitor_id-'.$monitor['Id'] ?>" title="<?php echo $monitor['Id'] ?>">
<?php <?php
if ( !$monitor['zmc'] ) { if ( (!$monitor['Status']) or ($monitor['Status'] == 'NotRunning') ) {
$dclass = 'errorText'; $source_class = 'errorText';
} else { } else {
<<<<<<< HEAD
// https://github.com/ZoneMinder/ZoneMinder/issues/1082 // https://github.com/ZoneMinder/ZoneMinder/issues/1082
//if ( a'] && $monitor['Function']!='Monitor' ) //if ( a'] && $monitor['Function']!='Monitor' )
//$dclass = 'warnText'; //$dclass = 'warnText';
//else //else
$dclass = 'infoText'; $dclass = 'infoText';
=======
if ( (!$monitor['CaptureFPS']) ) {
$source_class = 'errorText';
} else if ( (!$monitor['AnalysisFPS']) && ($monitor['Function']!='Monitor') && ($monitor['Function'] != 'Nodect') ) {
$source_class = 'warnText';
} else {
$source_class = 'infoText';
}
>>>>>>> storageareas
} }
if ( $monitor['Function'] == 'None' ) if ( $monitor['Function'] == 'None' )
$fclass = 'errorText'; $fclass = 'errorText';
//elseif ( $monitor['Function'] == 'Monitor' )
// $fclass = 'warnText';
else else
$fclass = 'infoText'; $fclass = 'infoText';
if ( !$monitor['Enabled'] ) if ( !$monitor['Enabled'] )
$fclass .= ' disabledText'; $fclass .= ' disabledText';
$scale = max( reScale( SCALE_BASE, $monitor['DefaultScale'], ZM_WEB_DEFAULT_SCALE ), SCALE_BASE ); $scale = max( reScale( SCALE_BASE, $monitor['DefaultScale'], ZM_WEB_DEFAULT_SCALE ), SCALE_BASE );
?> $stream_available = canView('Stream') && $monitor['CaptureFPS'] && $monitor['Function'] != 'None';
<?php
if ( ZM_WEB_ID_ON_CONSOLE ) { if ( ZM_WEB_ID_ON_CONSOLE ) {
?> ?>
<td class="colId"><a <?php echo (canView('Stream') && $running && $monitor['Function'] != 'None' ? 'href="?view=watch&amp;mid='.$monitor['Id'].'">' : '>') . $monitor['Id'] ?></a></td> <td class="colId"><a <?php echo ($stream_available ? 'href="?view=watch&amp;mid='.$monitor['Id'].'">' : '>') . $monitor['Id'] ?></a></td>
<?php <?php
} }
?> ?>
<td class="colName"><a <?php echo (canView('Stream') && $monitor['Function'] != 'None' ? 'href="?view=watch&amp;mid='.$monitor['Id'].'">' : '>') . $monitor['Name'] ?></a></td> <td class="colName"><a <?php echo ($stream_available ? 'href="?view=watch&amp;mid='.$monitor['Id'].'">' : '>') . $monitor['Name'] ?></a><br/><?php echo $monitor['Status'] ?></td>
<td class="colFunction"> <td class="colFunction">
<?php echo makePopupLink( '?view=function&amp;mid='.$monitor['Id'], 'zmFunction', 'function', '<span class="'.$fclass.'">'.translate('Fn'.$monitor['Function']).( empty($monitor['Enabled']) ? ', disabled' : '' ) .'</span>', canEdit( 'Monitors' ) ) ?><br/> <?php echo makePopupLink( '?view=function&amp;mid='.$monitor['Id'], 'zmFunction', 'function', '<span class="'.$fclass.'">'.translate('Fn'.$monitor['Function']).( empty($monitor['Enabled']) ? ', disabled' : '' ) .'</span>', canEdit( 'Monitors' ) ) ?><br/>
<?php <?php
@ -255,10 +262,10 @@ for( $monitor_i = 0; $monitor_i < count($displayMonitors); $monitor_i += 1 ) {
if ( $source == '' ) { if ( $source == '' ) {
$source = 'Monitor ' . $monitor['Id']; $source = 'Monitor ' . $monitor['Id'];
} }
echo '<td class="colSource">'. makePopupLink( '?view=monitor&amp;mid='.$monitor['Id'], 'zmMonitor'.$monitor['Id'], 'monitor', '<span class="'.$dclass.'">'.$source.'</span>', canEdit( 'Monitors' ) ).'</td>'; echo '<td class="colSource">'. makePopupLink( '?view=monitor&amp;mid='.$monitor['Id'], 'zmMonitor'.$monitor['Id'], 'monitor', '<span class="'.$source_class.'">'.$source.'</span>', canEdit( 'Monitors' ) ).'</td>';
if ( $show_storage_areas ) { if ( $show_storage_areas ) {
?> ?>
<td class="colStorage"><?php if ( isset( $StorageById[ $monitor['StorageId'] ] ) ) { echo $StorageById[ $monitor['StorageId'] ]->Name(); } ?></td> <td class="colStorage"><?php if ( isset($StorageById[$monitor['StorageId']]) ) { echo $StorageById[ $monitor['StorageId'] ]->Name(); } ?></td>
<?php <?php
} }

View File

@ -14,7 +14,13 @@ function getProbeResponse( respObj, respText ) {
if ( respObj.Streams && respObj.Streams.length ) { if ( respObj.Streams && respObj.Streams.length ) {
parseStreams( respObj.Streams ); parseStreams( respObj.Streams );
//} else { } else {
var results_div = $j('#results')[0];
if ( ! results_div ) {
console.log("No results div found.");
return;
}
results_div.innerHTML = 'No streams found.';
//console.log("No streams: " + respText); //console.log("No streams: " + respText);
} }
} // end function getProbeResponse } // end function getProbeResponse
@ -58,7 +64,8 @@ function addMonitor(url) {
var Stream = ProbeResults[url]; var Stream = ProbeResults[url];
var Monitor = Stream.Monitor; var Monitor = Stream.Monitor;
popup_url = '?view=monitor&newMonitor[Path]='+url; var mid = Monitor.Id ? Monitor.Id : '';
popup_url = '?view=monitor&mid='+mid+'&newMonitor[Path]='+url;
keys = Object.keys( Monitor ); keys = Object.keys( Monitor );
for ( i in Monitor ) { for ( i in Monitor ) {
if ( ! Monitor[i] ) if ( ! Monitor[i] )
@ -67,7 +74,7 @@ function addMonitor(url) {
Monitor[i]=''; Monitor[i]='';
popup_url += '&newMonitor['+i+']='+Monitor[i]; popup_url += '&newMonitor['+i+']='+Monitor[i];
} }
createPopup( popup_url, 'zmMonitor0', 'monitor' ); createPopup( popup_url, 'zmMonitor'+mid, 'monitor' );
} }
function import_csv( form ) { function import_csv( form ) {
@ -87,3 +94,10 @@ function import_csv( form ) {
} }
}); });
} }
function initPage() {
url = $j('#Url')[0];
if ( url.value ) {
probe(url);
}
}
window.addEvent( 'domready', initPage );

View File

@ -340,7 +340,7 @@ function redrawScreen() {
$('DateTimeDiv').style.display="none"; $('DateTimeDiv').style.display="none";
$('SpeedDiv').style.display="none"; $('SpeedDiv').style.display="none";
$('timelinediv').style.display="none"; $('timelinediv').style.display="none";
$('live').innerHTML="History"; $('liveButton').innerHTML="History";
$('zoomin').style.display="none"; $('zoomin').style.display="none";
$('zoomout').style.display="none"; $('zoomout').style.display="none";
$('panleft').style.display="none"; $('panleft').style.display="none";
@ -354,7 +354,7 @@ function redrawScreen() {
$('SpeedDiv').style.display="inline"; $('SpeedDiv').style.display="inline";
$('SpeedDiv').style.display="inline-flex"; $('SpeedDiv').style.display="inline-flex";
$('timelinediv').style.display=null; $('timelinediv').style.display=null;
$('live').innerHTML="Live"; $('liveButton').innerHTML="Live";
$('zoomin').style.display="inline"; $('zoomin').style.display="inline";
$('zoomin').style.display="inline-flex"; $('zoomin').style.display="inline-flex";
$('zoomout').style.display="inline"; $('zoomout').style.display="inline";
@ -483,7 +483,10 @@ function setSpeed( speed_index ) {
function setLive(value) { function setLive(value) {
liveMode = value; liveMode = value;
changeDateTime(); var form = $j('#montagereview_form')[0];
form.elements['live'].value = value;
form.submit();
return false;
} }
@ -743,10 +746,8 @@ function changeDateTime(e) {
var maxTime = moment(maxTime_element.val()); var maxTime = moment(maxTime_element.val());
if ( minTime.isAfter(maxTime) ) { if ( minTime.isAfter(maxTime) ) {
maxTime_element.parent().addClass('has-error'); maxTime_element.parent().addClass('has-error');
console.log("maxTime is less than mintime");
return; // Don't reload because we have invalid datetime filter. return; // Don't reload because we have invalid datetime filter.
} else { } else {
console.log("maxTime is greater than mintime");
maxTime_element.parent().removeClass('has-error'); maxTime_element.parent().removeClass('has-error');
} }

View File

@ -7,7 +7,7 @@ echo $offset . '; // ' . floor($offset / 3600) . ' hours ';
?> ?>
var currentScale=<?php echo $defaultScale?>; var currentScale=<?php echo $defaultScale?>;
var liveMode=<?php echo $initialModeIsLive?>; var liveMode=<?php echo $liveMode?>;
var fitMode=<?php echo $fitMode?>; var fitMode=<?php echo $fitMode?>;
var currentSpeed=<?php echo $speeds[$speedIndex]?>; // slider scale, which is only for replay and relative to real time var currentSpeed=<?php echo $speeds[$speedIndex]?>; // slider scale, which is only for replay and relative to real time
var speedIndex=<?php echo $speedIndex?>; var speedIndex=<?php echo $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 // Because we might not have time as the criteria, figure out the min/max time when we run the query
if ( ! $maxTimeSecs ) if ( ! $maxTimeSecs )
$maxTimeSecs = time(); $maxTimeSecs = time();
if ( ! $minTimeSecs ) 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 // This builds the list of events that are eligible from this range
$index = 0; $index = 0;
$anyAlarms = false; $anyAlarms = false;
if ( ! $initialModeIsLive ) { if ( ! $liveMode ) {
$result = dbQuery( $eventsSql ); $result = dbQuery( $eventsSql );
if ( ! $result ) { if ( ! $result ) {
Fatal('SQL-ERR'); Fatal('SQL-ERR');
@ -51,14 +51,17 @@ if ( ! $initialModeIsLive ) {
while( $event = $result->fetch( PDO::FETCH_ASSOC ) ) { while( $event = $result->fetch( PDO::FETCH_ASSOC ) ) {
if ( $minTimeSecs > $event['StartTimeSecs'] ) $minTimeSecs = $event['StartTimeSecs']; $StartTimeSecs = strtotime($event['StartTime']);
if ( $maxTimeSecs < $event['CalcEndTimeSecs'] ) $maxTimeSecs = $event['CalcEndTimeSecs']; $EndTimeSecs = strtotime($event['EndTime']);
if ( $minTimeSecs > $StartTimeSecs ) $minTimeSecs = $StartTimeSecs;
if ( $maxTimeSecs < $EndTimeSecs ) $maxTimeSecs = $EndTimeSecs;
echo " echo "
eMonId[$index]=" . $event['MonitorId'] . "; eMonId[$index]=" . $event['MonitorId'] . ";
eStorageId[$index]=".$event['StorageId'] . "; eStorageId[$index]=".$event['StorageId'] . ";
eId[$index]=" . $event['Id'] . "; eId[$index]=" . $event['Id'] . ";
eStartSecs[$index]=" . $event['StartTimeSecs'] . "; eStartSecs[$index]=" . $StartTimeSecs . ";
eEndSecs[$index]=" . $event['CalcEndTimeSecs'] . "; eEndSecs[$index]=" . $EndTimeSecs . ";
eventFrames[$index]=" . $event['Frames'] . "; eventFrames[$index]=" . $event['Frames'] . ";
"; ";

View File

@ -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. // 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'; $view = 'error';
return; 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')); $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']) ) ) { } 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++) { for ($i=0; $i < count($displayMonitors); $i++) {
if ($i == '0') { if ($i == '0') {
$filter['Query']['terms'][] = array('attr' => 'MonitorId', 'op' => '=', 'val' => $displayMonitors[$i]['Id'], 'cnj' => 'and', 'obr' => '1'); $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. // 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 = ' $eventsSql = '
SELECT E.Id,E.Name,E.StorageId,UNIX_TIMESTAMP(E.StartTime) AS StartTimeSecs, SELECT E.Id,E.Name,E.StorageId,E.StartTime AS StartTime,
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) CASE WHEN E.EndTime IS NULL THEN (SELECT NOW()) ELSE E.EndTime END AS EndTime,
ELSE UNIX_TIMESTAMP(E.EndTime) E.Length,
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,
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 E.MaxScore,E.Cause,E.Notes,E.Archived,E.MonitorId
FROM Events AS E FROM Events AS E
INNER JOIN Monitors AS M ON (E.MonitorId = M.Id) WHERE NOT isnull(E.Frames)
WHERE NOT isnull(E.Frames) AND NOT isnull(StartTime)'; ';
// 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 // 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 // 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 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 FROM Events AS E
INNER JOIN Frames AS F ON (F.EventId = E.Id) 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 // 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'] ) ) { if ( ! empty($user['MonitorIds']) ) {
$eventsSql .= ' AND M.Id IN ('.$user['MonitorIds'].')'; $eventsSql .= ' AND E.MonitorId IN ('.$user['MonitorIds'].')';
$frameSql .= ' AND E.MonitorId IN ('.$user['MonitorIds'].')'; $frameSql .= ' AND E.MonitorId IN ('.$user['MonitorIds'].')';
} }
if ( count($selected_monitor_ids) ) { if ( count($selected_monitor_ids) ) {
$monitor_ids_sql = ' IN (' . implode(',',$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; $frameSql .= ' AND E.MonitorId '.$monitor_ids_sql;
} }
@ -135,9 +137,8 @@ if ( count($selected_monitor_ids) ) {
if ( !isset($_REQUEST['minTime']) && !isset($_REQUEST['maxTime']) ) { if ( !isset($_REQUEST['minTime']) && !isset($_REQUEST['maxTime']) ) {
$time = time(); $time = time();
$maxTime = strftime("%FT%T",$time); $maxTime = strftime('%FT%T',$time);
$minTime = strftime("%FT%T",$time - 3600); $minTime = strftime('%FT%T',$time - 3600);
Logger::Debug("Defaulting to $minTime to $maxTime");
} }
if ( isset($_REQUEST['minTime']) ) if ( isset($_REQUEST['minTime']) )
$minTime = validHtmlStr($_REQUEST['minTime']); $minTime = validHtmlStr($_REQUEST['minTime']);
@ -162,7 +163,7 @@ if ( isset($_REQUEST['scale']) )
else else
$defaultScale = 1; $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']) ) if ( isset($_REQUEST['speed']) )
$defaultSpeed = validHtmlStr($_REQUEST['speed']); $defaultSpeed = validHtmlStr($_REQUEST['speed']);
@ -180,21 +181,21 @@ for ( $i = 0; $i < count($speeds); $i++ ) {
if ( isset($_REQUEST['current']) ) if ( isset($_REQUEST['current']) )
$defaultCurrentTime = validHtmlStr($_REQUEST['current']); $defaultCurrentTime = validHtmlStr($_REQUEST['current']);
$initialModeIsLive = 1; $liveMode = 1; // default to live
if ( isset($_REQUEST['live']) && $_REQUEST['live']=='0' ) if ( isset($_REQUEST['live']) && $_REQUEST['live']=='0' )
$initialModeIsLive=0; $liveMode=0;
$initialDisplayInterval = 1000; $initialDisplayInterval = 1000;
if ( isset($_REQUEST['displayinterval']) ) if ( isset($_REQUEST['displayinterval']) )
$initialDisplayInterval = validHtmlStr($_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) ) { if ( isset($minTime) && isset($maxTime) ) {
$minTimeSecs = strtotime($minTime); $minTimeSecs = strtotime($minTime);
$maxTimeSecs = strtotime($maxTime); $maxTimeSecs = strtotime($maxTime);
Logger::Debug("Min/max time secs: $minTimeSecs $maxTimeSecs"); 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 .= " AND TimeStamp > '" . $minTime . "' AND TimeStamp < '" . $maxTime . "'";
} }
$frameSql .= ' GROUP BY E.Id, E.MonitorId, F.TimeStamp, F.Delta ORDER BY E.MonitorId, F.TimeStamp ASC'; $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') );
?> ?>
<body> <body>
<div id="page"> <div id="page">
<?php echo getNavBarHTML() ?> <?php echo getNavBarHTML() ?>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="get"> <form id="montagereview_form" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="get">
<input type="hidden" name="view" value="montagereview"/> <input type="hidden" name="view" value="montagereview"/>
<div id="header"> <div id="header">
<?php echo $filter_bar ?> <?php echo $filter_bar ?>
<div id="DateTimeDiv"> <div id="DateTimeDiv">
@ -233,17 +234,17 @@ xhtmlHeaders(__FILE__, translate('MontageReview') );
<span id="speedslideroutput"><?php echo $speeds[$speedIndex] ?> fps</span> <span id="speedslideroutput"><?php echo $speeds[$speedIndex] ?> fps</span>
</div> </div>
<div id="ButtonsDiv"> <div id="ButtonsDiv">
<button type="button" id="panleft" onclick="click_panleft();" >&lt; <?php echo translate('Pan') ?></button> <button type="button" id="panleft" onclick="click_panleft();" >&lt; <?php echo translate('Pan') ?></button>
<button type="button" id="zoomin" onclick="click_zoomin();" ><?php echo translate('In +') ?></button> <button type="button" id="zoomin" onclick="click_zoomin();" ><?php echo translate('In +') ?></button>
<button type="button" id="zoomout" onclick="click_zoomout();" ><?php echo translate('Out -') ?></button> <button type="button" id="zoomout" onclick="click_zoomout();" ><?php echo translate('Out -') ?></button>
<button type="button" id="lasteight" onclick="click_lastEight();" ><?php echo translate('8 Hour') ?></button> <button type="button" id="lasteight" onclick="click_lastEight();" ><?php echo translate('8 Hour') ?></button>
<button type="button" id="lasthour" onclick="click_lastHour();" ><?php echo translate('1 Hour') ?></button> <button type="button" id="lasthour" onclick="click_lastHour();" ><?php echo translate('1 Hour') ?></button>
<button type="button" id="allof" onclick="click_all_events();" ><?php echo translate('All Events') ?></button> <button type="button" id="allof" onclick="click_all_events();" ><?php echo translate('All Events') ?></button>
<button type="button" id="live" onclick="setLive(1-liveMode);"><?php echo translate('Live') ?></button> <button type="button" id="liveButton" onclick="setLive(1-liveMode); console.log('live');return false;"><?php echo translate('Live') ?></button>
<button type="button" id="fit" onclick="setFit(1-fitMode);" ><?php echo translate('Fit') ?></button> <button type="button" id="fit" onclick="setFit(1-fitMode);" ><?php echo translate('Fit') ?></button>
<button type="button" id="panright" onclick="click_panright();" ><?php echo translate('Pan') ?> &gt;</button> <button type="button" id="panright" onclick="click_panright();" ><?php echo translate('Pan') ?> &gt;</button>
<?php <?php
if (count($displayMonitors) != 0) { if ( (!$liveMode) and (count($displayMonitors) != 0) ) {
?> ?>
<button type="button" id="downloadVideo" onclick="click_download();"><?php echo translate('Download Video') ?></button> <button type="button" id="downloadVideo" onclick="click_download();"><?php echo translate('Download Video') ?></button>
<?php <?php
@ -258,6 +259,8 @@ if (count($displayMonitors) != 0) {
</div> </div>
</div> </div>
</div> </div>
<input type="hidden" name="fit" value="<?php echo $fitMode ?>"/>
<input type="hidden" name="live" value="<?php echo $liveMode ?>"/>
</form> </form>
<div id="monitors"> <div id="monitors">
<?php <?php