braces,whitespace

This commit is contained in:
Isaac Connor 2017-05-25 14:26:49 -04:00
parent 9cbafde1ac
commit 043d722651
1 changed files with 85 additions and 112 deletions

View File

@ -77,8 +77,8 @@ $run_state = dbFetchOne('select Name from States where IsActive = 1', 'Name' );
$group = NULL; $group = NULL;
if ( ! empty($_COOKIE['zmGroup']) ) { if ( ! empty($_COOKIE['zmGroup']) ) {
if ( $group = dbFetchOne( 'select * from Groups where Id = ?', NULL, array($_COOKIE['zmGroup'])) ) if ( $group = dbFetchOne( 'select * from Groups where Id = ?', NULL, array($_COOKIE['zmGroup'])) )
$groupIds = array_flip(explode( ',', $group['MonitorIds'] )); $groupIds = array_flip(explode( ',', $group['MonitorIds'] ));
} }
noCacheHeaders(); noCacheHeaders();
@ -91,69 +91,60 @@ $maxSequence = 1;
$seqIdList = array(); $seqIdList = array();
$monitors = dbFetchAll( "select * from Monitors order by Sequence asc" ); $monitors = dbFetchAll( "select * from Monitors order by Sequence asc" );
$displayMonitors = array(); $displayMonitors = array();
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 ( $group && !empty($groupIds) && !array_key_exists( $monitors[$i]['Id'], $groupIds ) ) {
} continue;
if ( $group && !empty($groupIds) && !array_key_exists( $monitors[$i]['Id'], $groupIds ) ) }
{ $monitors[$i]['Show'] = true;
continue; if ( empty($minSequence) || ($monitors[$i]['Sequence'] < $minSequence) ) {
} $minSequence = $monitors[$i]['Sequence'];
$monitors[$i]['Show'] = true; }
if ( empty($minSequence) || ($monitors[$i]['Sequence'] < $minSequence) ) if ( $monitors[$i]['Sequence'] > $maxSequence ) {
{ $maxSequence = $monitors[$i]['Sequence'];
$minSequence = $monitors[$i]['Sequence']; }
} $monitors[$i]['zmc'] = zmcStatus( $monitors[$i] );
if ( $monitors[$i]['Sequence'] > $maxSequence ) $monitors[$i]['zma'] = zmaStatus( $monitors[$i] );
{ $monitors[$i]['ZoneCount'] = dbFetchOne( 'select count(Id) as ZoneCount from Zones where MonitorId = ?', 'ZoneCount', array($monitors[$i]['Id']) );
$maxSequence = $monitors[$i]['Sequence']; $counts = array();
} for ( $j = 0; $j < count($eventCounts); $j++ ) {
$monitors[$i]['zmc'] = zmcStatus( $monitors[$i] ); $filter = addFilterTerm( $eventCounts[$j]['filter'], count($eventCounts[$j]['filter']['terms']), array( "cnj" => "and", "attr" => "MonitorId", "op" => "=", "val" => $monitors[$i]['Id'] ) );
$monitors[$i]['zma'] = zmaStatus( $monitors[$i] ); parseFilter( $filter );
$monitors[$i]['ZoneCount'] = dbFetchOne( 'select count(Id) as ZoneCount from Zones where MonitorId = ?', 'ZoneCount', array($monitors[$i]['Id']) ); $counts[] = "count(if(1".$filter['sql'].",1,NULL)) as EventCount$j";
$counts = array(); $monitors[$i]['eventCounts'][$j]['filter'] = $filter;
for ( $j = 0; $j < count($eventCounts); $j++ ) }
{ $sql = "select ".join($counts,", ")." from Events as E where MonitorId = ?";
$filter = addFilterTerm( $eventCounts[$j]['filter'], count($eventCounts[$j]['filter']['terms']), array( "cnj" => "and", "attr" => "MonitorId", "op" => "=", "val" => $monitors[$i]['Id'] ) ); $counts = dbFetchOne( $sql, NULL, array($monitors[$i]['Id']) );
parseFilter( $filter ); if ( $monitors[$i]['Function'] != 'None' ) {
$counts[] = "count(if(1".$filter['sql'].",1,NULL)) as EventCount$j"; $cycleCount++;
$monitors[$i]['eventCounts'][$j]['filter'] = $filter; $scaleWidth = reScale( $monitors[$i]['Width'], $monitors[$i]['DefaultScale'], ZM_WEB_DEFAULT_SCALE );
} $scaleHeight = reScale( $monitors[$i]['Height'], $monitors[$i]['DefaultScale'], ZM_WEB_DEFAULT_SCALE );
$sql = "select ".join($counts,", ")." from Events as E where MonitorId = ?"; if ( $maxWidth < $scaleWidth ) $maxWidth = $scaleWidth;
$counts = dbFetchOne( $sql, NULL, array($monitors[$i]['Id']) ); if ( $maxHeight < $scaleHeight ) $maxHeight = $scaleHeight;
if ( $monitors[$i]['Function'] != 'None' ) }
{ if ( $counts ) $monitors[$i] = array_merge( $monitors[$i], $counts );
$cycleCount++; $seqIdList[] = $monitors[$i]['Id'];
$scaleWidth = reScale( $monitors[$i]['Width'], $monitors[$i]['DefaultScale'], ZM_WEB_DEFAULT_SCALE ); $displayMonitors[] = $monitors[$i];
$scaleHeight = reScale( $monitors[$i]['Height'], $monitors[$i]['DefaultScale'], ZM_WEB_DEFAULT_SCALE );
if ( $maxWidth < $scaleWidth ) $maxWidth = $scaleWidth;
if ( $maxHeight < $scaleHeight ) $maxHeight = $scaleHeight;
}
if ( $counts ) $monitors[$i] = array_merge( $monitors[$i], $counts );
$seqIdList[] = $monitors[$i]['Id'];
$displayMonitors[] = $monitors[$i];
} }
$lastId = 0; $lastId = 0;
$seqIdUpList = array(); $seqIdUpList = array();
foreach ( $seqIdList as $seqId ) foreach ( $seqIdList as $seqId ) {
{ if ( !empty($lastId) )
if ( !empty($lastId) ) $seqIdUpList[$seqId] = $lastId;
$seqIdUpList[$seqId] = $lastId; else
else $seqIdUpList[$seqId] = $seqId;
$seqIdUpList[$seqId] = $seqId; $lastId = $seqId;
$lastId = $seqId;
} }
$lastId = 0; $lastId = 0;
$seqIdDownList = array(); $seqIdDownList = array();
foreach ( array_reverse($seqIdList) as $seqId ) foreach ( array_reverse($seqIdList) as $seqId ) {
{ if ( !empty($lastId) )
if ( !empty($lastId) ) $seqIdDownList[$seqId] = $lastId;
$seqIdDownList[$seqId] = $lastId; else
else $seqIdDownList[$seqId] = $seqId;
$seqIdDownList[$seqId] = $seqId; $lastId = $seqId;
$lastId = $seqId;
} }
$cycleWidth = $maxWidth; $cycleWidth = $maxWidth;
@ -163,18 +154,15 @@ $eventsView = ZM_WEB_EVENTS_VIEW;
$eventsWindow = 'zm'.ucfirst(ZM_WEB_EVENTS_VIEW); $eventsWindow = 'zm'.ucfirst(ZM_WEB_EVENTS_VIEW);
$eventCount = 0; $eventCount = 0;
for ( $i = 0; $i < count($eventCounts); $i++ ) for ( $i = 0; $i < count($eventCounts); $i++ ) {
{ $eventCounts[$i]['total'] = 0;
$eventCounts[$i]['total'] = 0;
} }
$zoneCount = 0; $zoneCount = 0;
foreach( $displayMonitors as $monitor ) foreach( $displayMonitors as $monitor ) {
{ for ( $i = 0; $i < count($eventCounts); $i++ ) {
for ( $i = 0; $i < count($eventCounts); $i++ ) $eventCounts[$i]['total'] += $monitor['EventCount'.$i];
{ }
$eventCounts[$i]['total'] += $monitor['EventCount'.$i]; $zoneCount += $monitor['ZoneCount'];
}
$zoneCount += $monitor['ZoneCount'];
} }
$seqUpFile = getSkinFile( 'graphics/seq-u.png' ); $seqUpFile = getSkinFile( 'graphics/seq-u.png' );
@ -201,42 +189,34 @@ xhtmlHeaders( __FILE__, translate('Console') );
<h3 id="development"><center><?php echo ZM_WEB_CONSOLE_BANNER ?></center></h3> <h3 id="development"><center><?php echo ZM_WEB_CONSOLE_BANNER ?></center></h3>
<div id="monitorSummary"><?php echo makePopupLink( '?view=groups', 'zmGroups', 'groups', sprintf( $CLANG['MonitorCount'], count($displayMonitors), zmVlang( $VLANG['Monitor'], count($displayMonitors) ) ).($group?' ('.$group['Name'].')':''), canView( 'Groups' ) ); ?></div> <div id="monitorSummary"><?php echo makePopupLink( '?view=groups', 'zmGroups', 'groups', sprintf( $CLANG['MonitorCount'], count($displayMonitors), zmVlang( $VLANG['Monitor'], count($displayMonitors) ) ).($group?' ('.$group['Name'].')':''), canView( 'Groups' ) ); ?></div>
<?php <?php
if ( ZM_OPT_X10 && canView( 'Devices' ) ) if ( ZM_OPT_X10 && canView( 'Devices' ) ) {
{
?> ?>
<div id="devices"><?php echo makePopupLink( '?view=devices', 'zmDevices', 'devices', translate('Devices') ) ?></div> <div id="devices"><?php echo makePopupLink( '?view=devices', 'zmDevices', 'devices', translate('Devices') ) ?></div>
<?php <?php
} }
if ( canView( 'System' ) ) if ( canView( 'System' ) ) {
{
?> ?>
<div id="options"><?php echo makePopupLink( '?view=options', 'zmOptions', 'options', translate('Options') ) ?><?php if ( logToDatabase() > Logger::NOLOG ) { ?> / <?php echo makePopupLink( '?view=log', 'zmLog', 'log', '<span class="'.logState().'">'.translate('Log').'</span>' ) ?><?php } ?></div> <div id="options"><?php echo makePopupLink( '?view=options', 'zmOptions', 'options', translate('Options') ) ?><?php if ( logToDatabase() > Logger::NOLOG ) { ?> / <?php echo makePopupLink( '?view=log', 'zmLog', 'log', '<span class="'.logState().'">'.translate('Log').'</span>' ) ?><?php } ?></div>
<?php <?php
} }
if ( canView( 'Stream' ) && $cycleCount > 1 ) if ( canView( 'Stream' ) && $cycleCount > 1 ) {
{
$cycleGroup = isset($_COOKIE['zmGroup'])?$_COOKIE['zmGroup']:0; $cycleGroup = isset($_COOKIE['zmGroup'])?$_COOKIE['zmGroup']:0;
?> ?>
<div id="cycleMontage"> <div id="cycleMontage">
<?php echo makePopupLink( '?view=cycle&amp;group='.$cycleGroup, 'zmCycle'.$cycleGroup, array( 'cycle', $cycleWidth, $cycleHeight ), translate('Cycle'), $running ) ?>&nbsp;/&nbsp; <?php echo makePopupLink( '?view=cycle&amp;group='.$cycleGroup, 'zmCycle'.$cycleGroup, array( 'cycle', $cycleWidth, $cycleHeight ), translate('Cycle'), $running ) ?>&nbsp;/&nbsp;
<?php echo makePopupLink( '?view=montage&amp;group='.$cycleGroup, 'zmMontage'.$cycleGroup, 'montage', translate('Montage'), $running ) ?>&nbsp;/&nbsp; <?php echo makePopupLink( '?view=montage&amp;group='.$cycleGroup, 'zmMontage'.$cycleGroup, 'montage', translate('Montage'), $running ) ?>&nbsp;/&nbsp;
<?php echo makePopupLink( '?view=montagereview&amp;group='.$cycleGroup, 'zmMontage'.$cycleGroup, 'montagereview', translate('Montage Review'), $running ) ?> <?php echo makePopupLink( '?view=montagereview&amp;group='.$cycleGroup, 'zmMontage'.$cycleGroup, 'montagereview', translate('Montage Review'), $running ) ?>
</div> </div>
<?php <?php
} } else {
else
{
?> ?>
<?php <?php
} }
?> ?>
<h3 id="loginBandwidth"><?php <h3 id="loginBandwidth"><?php
if ( ZM_OPT_USE_AUTH ) if ( ZM_OPT_USE_AUTH ) {
{
?><?php echo translate('LoggedInAs') ?> <?php echo makePopupLink( '?view=logout', 'zmLogout', 'logout', $user['Username'], (ZM_AUTH_TYPE == "builtin") ) ?>, <?php echo strtolower( translate('ConfiguredFor') ) ?><?php ?><?php echo translate('LoggedInAs') ?> <?php echo makePopupLink( '?view=logout', 'zmLogout', 'logout', $user['Username'], (ZM_AUTH_TYPE == "builtin") ) ?>, <?php echo strtolower( translate('ConfiguredFor') ) ?><?php
} } else {
else
{
?><?php echo translate('ConfiguredFor') ?><?php ?><?php echo translate('ConfiguredFor') ?><?php
} }
?>&nbsp;<?php echo makePopupLink( '?view=bandwidth', 'zmBandwidth', 'bandwidth', $bwArray[$_COOKIE['zmBandwidth']], ($user && $user['MaxBandwidth'] != 'low' ) ) ?> <?php echo translate('BandwidthHead') ?></h3> ?>&nbsp;<?php echo makePopupLink( '?view=bandwidth', 'zmBandwidth', 'bandwidth', $bwArray[$_COOKIE['zmBandwidth']], ($user && $user['MaxBandwidth'] != 'low' ) ) ?> <?php echo translate('BandwidthHead') ?></h3>
@ -255,8 +235,7 @@ else
<?php } ?> <?php } ?>
<th class="colSource"><?php echo translate('Source') ?></th> <th class="colSource"><?php echo translate('Source') ?></th>
<?php <?php
for ( $i = 0; $i < count($eventCounts); $i++ ) for ( $i = 0; $i < count($eventCounts); $i++ ) {
{
?> ?>
<th class="colEvents"><?php echo $eventCounts[$i]['title'] ?></th> <th class="colEvents"><?php echo $eventCounts[$i]['title'] ?></th>
<?php <?php
@ -264,8 +243,7 @@ for ( $i = 0; $i < count($eventCounts); $i++ )
?> ?>
<th class="colZones"><?php echo translate('Zones') ?></th> <th class="colZones"><?php echo translate('Zones') ?></th>
<?php <?php
if ( canEdit('Monitors') ) if ( canEdit('Monitors') ) {
{
?> ?>
<th class="colOrder"><?php echo translate('Order') ?></th> <th class="colOrder"><?php echo translate('Order') ?></th>
<?php <?php
@ -278,14 +256,13 @@ if ( canEdit('Monitors') )
<tr> <tr>
<td class="colLeftButtons" colspan="<?php echo $left_columns ?>"> <td class="colLeftButtons" colspan="<?php echo $left_columns ?>">
<input type="button" value="<?php echo translate('Refresh') ?>" onclick="location.reload(true);"/> <input type="button" value="<?php echo translate('Refresh') ?>" onclick="location.reload(true);"/>
<input type="button" name="addBtn" value="<?php echo translate('AddNewMonitor') ?>" onclick="addMonitor( this )"/> <input type="button" name="addBtn" value="<?php echo translate('AddNewMonitor') ?>" onclick="addMonitor( this )"/>
<!-- <?php echo makePopupButton( '?view=monitor', 'zmMonitor0', 'monitor', translate('AddNewMonitor'), (canEdit( 'Monitors' ) && !$user['MonitorIds']) ) ?> --> <!-- <?php echo makePopupButton( '?view=monitor', 'zmMonitor0', 'monitor', translate('AddNewMonitor'), (canEdit( 'Monitors' ) && !$user['MonitorIds']) ) ?> -->
<?php echo makePopupButton( '?view=filter&amp;filter[terms][0][attr]=DateTime&amp;filter[terms][0][op]=%3c&amp;filter[terms][0][val]=now', 'zmFilter', 'filter', translate('Filters'), canView( 'Events' ) ) ?> <?php echo makePopupButton( '?view=filter&amp;filter[terms][0][attr]=DateTime&amp;filter[terms][0][op]=%3c&amp;filter[terms][0][val]=now', 'zmFilter', 'filter', translate('Filters'), canView( 'Events' ) ) ?>
</td> </td>
<?php <?php
for ( $i = 0; $i < count($eventCounts); $i++ ) for ( $i = 0; $i < count($eventCounts); $i++ ) {
{ parseFilter( $eventCounts[$i]['filter'] );
parseFilter( $eventCounts[$i]['filter'] );
?> ?>
<td class="colEvents"><?php echo makePopupLink( '?view='.$eventsView.'&amp;page=1'.$eventCounts[$i]['filter']['query'], $eventsWindow, $eventsView, $eventCounts[$i]['total'], canView( 'Events' ) ) ?></td> <td class="colEvents"><?php echo makePopupLink( '?view='.$eventsView.'&amp;page=1'.$eventCounts[$i]['filter']['query'], $eventsWindow, $eventsView, $eventCounts[$i]['total'], canView( 'Events' ) ) ?></td>
<?php <?php
@ -297,29 +274,27 @@ for ( $i = 0; $i < count($eventCounts); $i++ )
</tfoot> </tfoot>
<tbody> <tbody>
<?php <?php
foreach( $displayMonitors as $monitor ) foreach( $displayMonitors as $monitor ) {
{
?> ?>
<tr> <tr>
<?php <?php
if ( !$monitor['zmc'] ) if ( !$monitor['zmc'] ) {
$dclass = "errorText"; $dclass = "errorText";
else } else {
{
// https://github.com/ZoneMinder/ZoneMinder/issues/1082 // https://github.com/ZoneMinder/ZoneMinder/issues/1082
if ( !$monitor['zma'] && $monitor['Function']!='Monitor' ) if ( !$monitor['zma'] && $monitor['Function']!='Monitor' )
$dclass = "warnText"; $dclass = "warnText";
else else
$dclass = "infoText"; $dclass = "infoText";
} }
if ( $monitor['Function'] == 'None' ) if ( $monitor['Function'] == 'None' )
$fclass = "errorText"; $fclass = "errorText";
//elseif ( $monitor['Function'] == 'Monitor' ) //elseif ( $monitor['Function'] == 'Monitor' )
// $fclass = "warnText"; // $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 );
?> ?>
<?php if ( ZM_WEB_ID_ON_CONSOLE ) { ?> <?php if ( ZM_WEB_ID_ON_CONSOLE ) { ?>
@ -343,7 +318,7 @@ echo $Server->Name();
$domain = parse_url( $monitor['Path'], PHP_URL_HOST ); $domain = parse_url( $monitor['Path'], PHP_URL_HOST );
$shortpath = $domain ? $domain : preg_replace( '/^.*\//', '', $monitor['Path'] ); $shortpath = $domain ? $domain : preg_replace( '/^.*\//', '', $monitor['Path'] );
if ( $shortpath == '' ) { if ( $shortpath == '' ) {
$shortpath = 'Monitor ' . $monitor['Id']; $shortpath = 'Monitor ' . $monitor['Id'];
} }
?> ?>
<td class="colSource"><?php echo makePopupLink( '?view=monitor&amp;mid='.$monitor['Id'], 'zmMonitor'.$monitor['Id'], 'monitor', '<span class="'.$dclass.'">'.$shortpath.'</span>', canEdit( 'Monitors' ) ) ?></td> <td class="colSource"><?php echo makePopupLink( '?view=monitor&amp;mid='.$monitor['Id'], 'zmMonitor'.$monitor['Id'], 'monitor', '<span class="'.$dclass.'">'.$shortpath.'</span>', canEdit( 'Monitors' ) ) ?></td>
@ -353,8 +328,7 @@ echo $Server->Name();
<td class="colSource">&nbsp;</td> <td class="colSource">&nbsp;</td>
<?php } ?> <?php } ?>
<?php <?php
for ( $i = 0; $i < count($eventCounts); $i++ ) for ( $i = 0; $i < count($eventCounts); $i++ ) {
{
?> ?>
<td class="colEvents"><?php echo makePopupLink( '?view='.$eventsView.'&amp;page=1'.$monitor['eventCounts'][$i]['filter']['query'], $eventsWindow, $eventsView, $monitor['EventCount'.$i], canView( 'Events' ) ) ?></td> <td class="colEvents"><?php echo makePopupLink( '?view='.$eventsView.'&amp;page=1'.$monitor['eventCounts'][$i]['filter']['query'], $eventsWindow, $eventsView, $monitor['EventCount'.$i], canView( 'Events' ) ) ?></td>
<?php <?php
@ -362,8 +336,7 @@ echo $Server->Name();
?> ?>
<td class="colZones"><?php echo makePopupLink( '?view=zones&amp;mid='.$monitor['Id'], 'zmZones', array( 'zones', $monitor['Width'], $monitor['Height'] ), $monitor['ZoneCount'], $running && canView( 'Monitors' ) ) ?></td> <td class="colZones"><?php echo makePopupLink( '?view=zones&amp;mid='.$monitor['Id'], 'zmZones', array( 'zones', $monitor['Width'], $monitor['Height'] ), $monitor['ZoneCount'], $running && canView( 'Monitors' ) ) ?></td>
<?php <?php
if ( canEdit('Monitors') ) if ( canEdit('Monitors') ) {
{
?> ?>
<td class="colOrder"><?php echo makeLink( '?view='.$view.'&amp;action=sequence&amp;mid='.$monitor['Id'].'&amp;smid='.$seqIdUpList[$monitor['Id']], '<img src="'.$seqUpFile.'" alt="Up"/>', $monitor['Sequence']>$minSequence ) ?><?php echo makeLink( '?view='.$view.'&amp;action=sequence&amp;mid='.$monitor['Id'].'&amp;smid='.$seqIdDownList[$monitor['Id']], '<img src="'.$seqDownFile.'" alt="Down"/>', $monitor['Sequence']<$maxSequence ) ?></td> <td class="colOrder"><?php echo makeLink( '?view='.$view.'&amp;action=sequence&amp;mid='.$monitor['Id'].'&amp;smid='.$seqIdUpList[$monitor['Id']], '<img src="'.$seqUpFile.'" alt="Up"/>', $monitor['Sequence']>$minSequence ) ?><?php echo makeLink( '?view='.$view.'&amp;action=sequence&amp;mid='.$monitor['Id'].'&amp;smid='.$seqIdDownList[$monitor['Id']], '<img src="'.$seqDownFile.'" alt="Down"/>', $monitor['Sequence']<$maxSequence ) ?></td>
<?php <?php