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;
//
DELIMITER ;
DROP TABLE IF EXISTS `Events_Day`;

View File

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

View File

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

View File

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

View File

@ -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();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -147,7 +147,6 @@ echo output_link_if_exists( array(
<?php
} else if ( $view == 'watch' ) {
?>
<link href="<?php echo cache_bust($viewCssFileExtra) ?>" rel="stylesheet">
<?php
}
if ( $skinJsPhpFile ) {
@ -249,7 +248,7 @@ function getNavBarHTML($reload = null) {
if ( logToDatabase() > 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', '<span class="'.logState().'">'.translate('Log').'</span>' );
}

View File

@ -43,54 +43,97 @@ foreach ( $storage_areas as $S ) {
$StorageById[$S->Id()] = $S;
}
?>
$html =
'
<div class="controlHeader">
<input type="hidden" name="filtering" value="" />
<?php
<input type="hidden" name="filtering" value=""/>
';
$groupSql = '';
if ( Group::find_all() ) { ?>
<span id="groupControl"><label><?php echo translate('Group') ?>:</label>
<?php
# This will end up with the group_id of the deepest selection
$group_id = isset($_SESSION['Group']) ? $_SESSION['Group'] : null;
echo Group::get_group_dropdown();
$groupSql = Group::get_group_sql( $group_id );
?>
</span>
<?php } ?>
<span id="monitorControl"><label><?php echo translate('Monitor') ?>:</label>
<?php
if ( Group::find_all() ) {
$html .= '<span id="groupControl"><label>'. translate('Group') .':</label>';
# 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 .= '</span>';
}
$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 .= '<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();
$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 .= '<span id="monitorControl"><label>'.translate('Monitor').':</label>';
$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 .= '</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>

View File

@ -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 ) {
?>
<tr id="<?php echo 'monitor_id-'.$monitor['Id'] ?>" title="<?php echo $monitor['Id'] ?>">
<?php
if ( !$monitor['zmc'] ) {
$dclass = 'errorText';
if ( (!$monitor['Status']) or ($monitor['Status'] == 'NotRunning') ) {
$source_class = 'errorText';
} else {
<<<<<<< HEAD
// https://github.com/ZoneMinder/ZoneMinder/issues/1082
//if ( a'] && $monitor['Function']!='Monitor' )
//$dclass = 'warnText';
//else
$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' )
$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 );
?>
<?php
$stream_available = canView('Stream') && $monitor['CaptureFPS'] && $monitor['Function'] != 'None';
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
}
?>
<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">
<?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
@ -255,10 +262,10 @@ for( $monitor_i = 0; $monitor_i < count($displayMonitors); $monitor_i += 1 ) {
if ( $source == '' ) {
$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 ) {
?>
<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
}

View File

@ -14,7 +14,13 @@ function getProbeResponse( respObj, respText ) {
if ( respObj.Streams && respObj.Streams.length ) {
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);
}
} // end function getProbeResponse
@ -58,7 +64,8 @@ function addMonitor(url) {
var Stream = ProbeResults[url];
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 );
for ( i in Monitor ) {
if ( ! Monitor[i] )
@ -67,7 +74,7 @@ function addMonitor(url) {
Monitor[i]='';
popup_url += '&newMonitor['+i+']='+Monitor[i];
}
createPopup( popup_url, 'zmMonitor0', 'monitor' );
createPopup( popup_url, 'zmMonitor'+mid, 'monitor' );
}
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";
$('SpeedDiv').style.display="none";
$('timelinediv').style.display="none";
$('live').innerHTML="History";
$('liveButton').innerHTML="History";
$('zoomin').style.display="none";
$('zoomout').style.display="none";
$('panleft').style.display="none";
@ -354,7 +354,7 @@ function redrawScreen() {
$('SpeedDiv').style.display="inline";
$('SpeedDiv').style.display="inline-flex";
$('timelinediv').style.display=null;
$('live').innerHTML="Live";
$('liveButton').innerHTML="Live";
$('zoomin').style.display="inline";
$('zoomin').style.display="inline-flex";
$('zoomout').style.display="inline";
@ -483,7 +483,10 @@ function setSpeed( speed_index ) {
function setLive(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());
if ( minTime.isAfter(maxTime) ) {
maxTime_element.parent().addClass('has-error');
console.log("maxTime is less than mintime");
return; // Don't reload because we have invalid datetime filter.
} else {
console.log("maxTime is greater than mintime");
maxTime_element.parent().removeClass('has-error');
}

View File

@ -7,7 +7,7 @@ echo $offset . '; // ' . floor($offset / 3600) . ' hours ';
?>
var currentScale=<?php echo $defaultScale?>;
var liveMode=<?php echo $initialModeIsLive?>;
var liveMode=<?php echo $liveMode?>;
var fitMode=<?php echo $fitMode?>;
var currentSpeed=<?php echo $speeds[$speedIndex]?>; // slider scale, which is only for replay and relative to real time
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
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'] . ";
";

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.
//
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') );
?>
<body>
<div id="page">
<?php echo getNavBarHTML() ?>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="get">
<input type="hidden" name="view" value="montagereview"/>
<?php echo getNavBarHTML() ?>
<form id="montagereview_form" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="get">
<input type="hidden" name="view" value="montagereview"/>
<div id="header">
<?php echo $filter_bar ?>
<div id="DateTimeDiv">
@ -233,17 +234,17 @@ xhtmlHeaders(__FILE__, translate('MontageReview') );
<span id="speedslideroutput"><?php echo $speeds[$speedIndex] ?> fps</span>
</div>
<div id="ButtonsDiv">
<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="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="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="live" onclick="setLive(1-liveMode);"><?php echo translate('Live') ?></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="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="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="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="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
if (count($displayMonitors) != 0) {
if ( (!$liveMode) and (count($displayMonitors) != 0) ) {
?>
<button type="button" id="downloadVideo" onclick="click_download();"><?php echo translate('Download Video') ?></button>
<?php
@ -258,6 +259,8 @@ if (count($displayMonitors) != 0) {
</div>
</div>
</div>
<input type="hidden" name="fit" value="<?php echo $fitMode ?>"/>
<input type="hidden" name="live" value="<?php echo $liveMode ?>"/>
</form>
<div id="monitors">
<?php