Fixed event sorting and general parameter passing.

git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@940 e3e1d417-86f3-4887-817a-d78f3d33393f
This commit is contained in:
stan 2004-03-10 14:23:22 +00:00
parent 58e1445c71
commit 4db97fa8a9
4 changed files with 231 additions and 233 deletions

View File

@ -421,4 +421,170 @@ function reScale( $dimension, $scale=SCALE_SCALE )
return( (int)(($dimension*$scale)/SCALE_SCALE) ); return( (int)(($dimension*$scale)/SCALE_SCALE) );
} }
function parseSort()
{
global $sort_field, $sort_asc; // Inputs
global $sort_query, $sort_column, $sort_order; // Outputs
if ( !isset($sort_field) )
{
$sort_field = "StartTime";
$sort_asc = false;
}
switch( $sort_field )
{
case 'Id' :
$sort_column = "E.Id";
break;
case 'MonitorName' :
$sort_column = "M.Name";
break;
case 'Name' :
$sort_column = "E.Name";
break;
case 'StartTime' :
$sort_column = "E.StartTime";
break;
case 'Secs' :
$sort_column = "E.Length";
break;
case 'Frames' :
$sort_column = "E.Frames";
break;
case 'AlarmFrames' :
$sort_column = "E.AlarmFrames";
break;
case 'TotScore' :
$sort_column = "E.TotScore";
break;
case 'AvgScore' :
$sort_column = "E.AvgScore";
break;
case 'MaxScore' :
$sort_column = "E.MaxScore";
break;
default:
$sort_column = "E.StartTime";
break;
}
$sort_order = $sort_asc?"asc":"desc";
if ( !$sort_asc ) $sort_asc = 0;
$sort_query = "&sort_field=$sort_field&sort_asc=$sort_asc";
}
function parseFilter()
{
global $filter_query, $filter_sql, $filter_fields;
$filter_query = '';
$filter_sql = '';
$filter_fields = '';
global $trms;
if ( $trms )
{
$filter_query .= "&trms=$trms";
$filter_fields .= '<input type="hidden" name="trms" value="'.$trms.'">'."\n";
}
for ( $i = 1; $i <= $trms; $i++ )
{
$conjunction_name = "cnj$i";
$obracket_name = "obr$i";
$cbracket_name = "cbr$i";
$attr_name = "attr$i";
$op_name = "op$i";
$value_name = "val$i";
global $$conjunction_name, $$obracket_name, $$cbracket_name, $$attr_name, $$op_name, $$value_name;
if ( isset($$conjunction_name) )
{
$filter_query .= "&$conjunction_name=".$$conjunction_name;
$filter_sql .= " ".$$conjunction_name." ";
$filter_fields .= '<input type="hidden" name="'.$conjunction_name.'" value="'.$$conjunction_name.'">'."\n";
}
if ( isset($$obracket_name) )
{
$filter_query .= "&$obracket_name=".$$obracket_name;
$filter_sql .= str_repeat( "(", $$obracket_name );
$filter_fields .= '<input type="hidden" name="'.$obracket_name.'" value="'.$$obracket_name.'">'."\n";
}
if ( isset($$attr_name) )
{
$filter_query .= "&$attr_name=".$$attr_name;
$filter_fields .= '<input type="hidden" name="'.$attr_name.'" value="'.$$attr_name.'">'."\n";
$value = $$value_name;
switch ( $$attr_name )
{
case 'MonitorName':
$filter_sql .= 'M.'.preg_replace( '/^Monitor/', '', $$attr_name );
break;
case 'DateTime':
$value = strftime( "%Y-%m-%d %H:%M:%S", strtotime( $$value_name ) );
$filter_sql .= "E.StartTime";
break;
case 'Date':
$value = "to_days( '".strftime( "%Y-%m-%d %H:%M:%S", strtotime( $$value_name ) )."' )";
$filter_sql .= "to_days( E.StartTime )";
break;
case 'Time':
$value = "extract( hour_second from '".strftime( "%Y-%m-%d %H:%M:%S", strtotime( $$value_name ) )."' )";
$filter_sql .= "extract( hour_second from E.StartTime )";
break;
case 'Weekday':
$value = "weekday( '".strftime( "%Y-%m-%d %H:%M:%S", strtotime( $$value_name ) )."' )";
$filter_sql .= "weekday( E.StartTime )";
break;
case 'MonitorId':
case 'Length':
case 'Frames':
case 'AlarmFrames':
case 'TotScore':
case 'AvgScore':
case 'MaxScore':
$filter_sql .= "E.".$$attr_name;
break;
case 'Archived':
$filter_sql .= "E.Archived = ".$$value_name;
break;
}
switch ( $$op_name )
{
case '=' :
case '!=' :
case '>=' :
case '>' :
case '<' :
case '<=' :
$filter_sql .= " ".$$op_name." '$value'";
break;
case '=~' :
$filter_sql .= " regexp '$value'";
break;
case '!~' :
$filter_sql .= " not regexp '$value'";
break;
case '=[]' :
$filter_sql .= " in ('".join( "','", preg_split( '/["\'\s]*,["\'\s]*/', $value ) )."')";
break;
case '![]' :
$filter_sql .= " not in ('".join( "','", preg_split( '/["\'\s]*,["\'\s]*/', $value ) )."')";
break;
}
$filter_query .= "&$op_name=".urlencode($$op_name);
$filter_fields .= '<input type="hidden" name="'.$op_name.'" value="'.$$op_name.'">'."\n";
$filter_query .= "&$value_name=".urlencode($$value_name);
$filter_fields .= '<input type="hidden" name="'.$value_name.'" value="'.$$value_name.'">'."\n";
}
if ( isset($$cbracket_name) )
{
$filter_query .= "&$cbracket_name=".$$cbracket_name;
$filter_sql .= str_repeat( ")", $$cbracket_name );
$filter_fields .= '<input type="hidden" name="'.$cbracket_name.'" value="'.$$cbracket_name.'">'."\n";
}
}
$filter_sql = " and ( $filter_sql )";
}
?> ?>

View File

@ -40,29 +40,40 @@ else
$mid_sql = ''; $mid_sql = '';
} }
$result = mysql_query( "select E.*,M.Name as MonitorName,M.Width,M.Height from Events as E inner join Monitors as M on E.MonitorId = M.Id where E.Id = '$eid'$mid_sql" ); $sql = "select E.*,M.Name as MonitorName,M.Width,M.Height from Events as E inner join Monitors as M on E.MonitorId = M.Id where E.Id = '$eid'$mid_sql";
$result = mysql_query( $sql );
if ( !$result ) if ( !$result )
die( mysql_error() ); die( mysql_error() );
$event = mysql_fetch_assoc( $result ); $event = mysql_fetch_assoc( $result );
if ( empty($mid) ) parseSort();
{ parseFilter();
$mid = 0;
}
else
{
$mid_sql .= " and MonitorId = '$mid'";
}
$result = mysql_query( "select * from Events where Id < '$eid'$mid_sql order by Id desc limit 0,1" ); $sql = "select * from Events as E where $sort_column ".($sort_order=='asc'?'<=':'>=')." '".$event[$sort_field]."'$filter_sql$mid_sql order by $sort_column ".($sort_order=='asc'?'desc':'asc');
$result = mysql_query( $sql );
if ( !$result ) if ( !$result )
die( mysql_error() ); die( mysql_error() );
$prev_event = mysql_fetch_assoc( $result ); while ( $row = mysql_fetch_assoc( $result ) )
{
if ( $row[Id] == $eid )
{
$prev_event = mysql_fetch_assoc( $result );
break;
}
}
$result = mysql_query( "select * from Events where Id > '$eid'$mid_sql order by Id asc limit 0,1" ); $sql = "select * from Events as E where $sort_column ".($sort_order=='asc'?'>=':'<=')." '".$event[$sort_field]."'$filter_sql$mid_sql order by $sort_column $sort_order";
$result = mysql_query( $sql );
if ( !$result ) if ( !$result )
die( mysql_error() ); die( mysql_error() );
$next_event = mysql_fetch_assoc( $result ); while ( $row = mysql_fetch_assoc( $result ) )
{
if ( $row[Id] == $eid )
{
$next_event = mysql_fetch_assoc( $result );
break;
}
}
if ( !isset( $rate ) ) if ( !isset( $rate ) )
$rate = RATE_SCALE; $rate = RATE_SCALE;
@ -118,7 +129,6 @@ function newWindow(Url,Name,Width,Height)
<form name="rename_form" method="get" action="<?= $PHP_SELF ?>"> <form name="rename_form" method="get" action="<?= $PHP_SELF ?>">
<input type="hidden" name="view" value="<?= $view ?>"> <input type="hidden" name="view" value="<?= $view ?>">
<input type="hidden" name="action" value="rename"> <input type="hidden" name="action" value="rename">
<input type="hidden" name="mid" value="<?= $mid ?>">
<input type="hidden" name="eid" value="<?= $eid ?>"> <input type="hidden" name="eid" value="<?= $eid ?>">
<input type="text" size="16" name="event_name" value="<?= $event['Name'] ?>" class="form"> <input type="text" size="16" name="event_name" value="<?= $event['Name'] ?>" class="form">
<input type="submit" value="<?= $zmSlangRename ?>" class="form"<?php if ( !canEdit( 'Events' ) ) { ?> disabled<?php } ?>></form></td> <input type="submit" value="<?= $zmSlangRename ?>" class="form"<?php if ( !canEdit( 'Events' ) ) { ?> disabled<?php } ?>></form></td>
@ -127,7 +137,6 @@ function newWindow(Url,Name,Width,Height)
<form name="learn_form" method="get" action="<?= $PHP_SELF ?>"> <form name="learn_form" method="get" action="<?= $PHP_SELF ?>">
<input type="hidden" name="view" value="<?= $view ?>"> <input type="hidden" name="view" value="<?= $view ?>">
<input type="hidden" name="action" value="learn"> <input type="hidden" name="action" value="learn">
<input type="hidden" name="mid" value="<?= $mid ?>">
<input type="hidden" name="eid" value="<?= $eid ?>"> <input type="hidden" name="eid" value="<?= $eid ?>">
<input type="hidden" name="mark_eid" value="<?= $eid ?>"> <input type="hidden" name="mark_eid" value="<?= $eid ?>">
<?php if ( LEARN_MODE ) { ?> <?php if ( LEARN_MODE ) { ?>
@ -138,8 +147,8 @@ Learn Pref:&nbsp;<select name="learn_state" class="form" onChange="learn_form.su
<td colspan="3" align="right" class="text"> <td colspan="3" align="right" class="text">
<form name="view_form" method="get" action="<?= $PHP_SELF ?>"> <form name="view_form" method="get" action="<?= $PHP_SELF ?>">
<input type="hidden" name="view" value="<?= $view ?>"> <input type="hidden" name="view" value="<?= $view ?>">
<input type="hidden" name="mid" value="<?= $mid ?>">
<input type="hidden" name="eid" value="<?= $eid ?>"> <input type="hidden" name="eid" value="<?= $eid ?>">
<?= $filter_fields ?>
<?= $zmSlangRate ?>: <?= buildSelect( "rate", $rates, "document.view_form.submit();" ); ?>&nbsp;&nbsp; <?= $zmSlangRate ?>: <?= buildSelect( "rate", $rates, "document.view_form.submit();" ); ?>&nbsp;&nbsp;
<?= $zmSlangScale ?>: <?= buildSelect( "scale", $scales, "document.view_form.submit();" ); ?> <?= $zmSlangScale ?>: <?= buildSelect( "scale", $scales, "document.view_form.submit();" ); ?>
</form> </form>
@ -149,22 +158,22 @@ Learn Pref:&nbsp;<select name="learn_state" class="form" onChange="learn_form.su
<?php if ( $mode == "stream" ) { ?> <?php if ( $mode == "stream" ) { ?>
<td align="center" class="text"><a href="javascript: refreshWindow();"><?= $zmSlangReplay ?></a></td> <td align="center" class="text"><a href="javascript: refreshWindow();"><?= $zmSlangReplay ?></a></td>
<?php } elseif ( $paged && !empty($page) ) { ?> <?php } elseif ( $paged && !empty($page) ) { ?>
<td align="center" class="text"><a href="<?= $PHP_SELF ?>?view=event&mode=still&mid=<?= $mid ?>&eid=<?= $eid ?>&page=0"><?= $zmSlangAll ?></a></td> <td align="center" class="text"><a href="<?= $PHP_SELF ?>?view=event&mode=still&eid=<?= $eid ?><?= $filter_query ?><?= $sort_query ?>&page=0"><?= $zmSlangAll ?></a></td>
<?php } elseif ( $paged && empty($page) ) { ?> <?php } elseif ( $paged && empty($page) ) { ?>
<td align="center" class="text"><a href="<?= $PHP_SELF ?>?view=event&mode=still&mid=<?= $mid ?>&eid=<?= $eid ?>&page=1"><?= $zmSlangPaged ?></a></td> <td align="center" class="text"><a href="<?= $PHP_SELF ?>?view=event&mode=still&eid=<?= $eid ?><?= $filter_query ?><?= $sort_query ?>&page=1"><?= $zmSlangPaged ?></a></td>
<?php } else { ?> <?php } else { ?>
<td align="center" class="text">&nbsp;</td> <td align="center" class="text">&nbsp;</td>
<?php } ?> <?php } ?>
<td align="center" class="text"><?php if ( canEdit( 'Events' ) ) { ?><a href="<?= $PHP_SELF ?>?view=none&action=delete&mid=<?= $mid ?>&mark_eid=<?= $eid ?>"><?= $zmSlangDelete ?></a><?php } else { ?>&nbsp;<?php } ?></td> <td align="center" class="text"><?php if ( canEdit( 'Events' ) ) { ?><a href="<?= $PHP_SELF ?>?view=none&action=delete&mark_eid=<?= $eid ?>"><?= $zmSlangDelete ?></a><?php } else { ?>&nbsp;<?php } ?></td>
<?php if ( $event['Archived'] ) { ?> <?php if ( $event['Archived'] ) { ?>
<td align="center" class="text"><?php if ( canEdit( 'Events' ) ) { ?><a href="<?= $PHP_SELF ?>?view=<?= $view ?>&action=unarchive&mid=<?= $mid ?>&eid=<?= $eid ?>"><?= $zmSlangUnarchive ?></a><?php } else { ?>&nbsp;<?php } ?></td> <td align="center" class="text"><?php if ( canEdit( 'Events' ) ) { ?><a href="<?= $PHP_SELF ?>?view=<?= $view ?>&action=unarchive&eid=<?= $eid ?>"><?= $zmSlangUnarchive ?></a><?php } else { ?>&nbsp;<?php } ?></td>
<?php } else { ?> <?php } else { ?>
<td align="center" class="text"><?php if ( canEdit( 'Events' ) ) { ?><a href="<?= $PHP_SELF ?>?view=<?= $view ?>&action=archive&mid=<?= $mid ?>&eid=<?= $eid ?>"><?= $zmSlangArchive ?></a><?php } else { ?>&nbsp;<?php } ?></td> <td align="center" class="text"><?php if ( canEdit( 'Events' ) ) { ?><a href="<?= $PHP_SELF ?>?view=<?= $view ?>&action=archive&eid=<?= $eid ?>"><?= $zmSlangArchive ?></a><?php } else { ?>&nbsp;<?php } ?></td>
<?php } ?> <?php } ?>
<?php if ( $mode == "stream" ) { ?> <?php if ( $mode == "stream" ) { ?>
<td align="center" class="text"><a href="<?= $PHP_SELF ?>?view=event&mode=still&mid=<?= $mid ?>&eid=<?= $eid ?>&page=1"><?= $zmSlangStills ?></a></td> <td align="center" class="text"><a href="<?= $PHP_SELF ?>?view=event&mode=still&eid=<?= $eid ?><?= $filter_query ?><?= $sort_query ?>&page=1"><?= $zmSlangStills ?></a></td>
<?php } elseif ( canStream() ) { ?> <?php } elseif ( canStream() ) { ?>
<td align="center" class="text"><a href="<?= $PHP_SELF ?>?view=event&mode=stream&mid=<?= $mid ?>&eid=<?= $eid ?>"><?= $zmSlangStream ?></a></td> <td align="center" class="text"><a href="<?= $PHP_SELF ?>?view=event&mode=stream&eid=<?= $eid ?><?= $filter_query ?><?= $sort_query ?>"><?= $zmSlangStream ?></a></td>
<?php } else { ?> <?php } else { ?>
<td align="center" class="text">&nbsp;</td> <td align="center" class="text">&nbsp;</td>
<?php } ?> <?php } ?>
@ -211,7 +220,7 @@ if ( $mode == "still" && $paged && !empty($page) )
foreach ( $new_pages as $new_page ) foreach ( $new_pages as $new_page )
{ {
?> ?>
<a href="<?= $PHP_SELF ?>?view=event&mode=still&mid=<?= $mid ?>&eid=<?= $eid ?>&page=<?= $new_page ?>"><?= $new_page ?></a>&nbsp; <a href="<?= $PHP_SELF ?>?view=event&mode=still&eid=<?= $eid ?><?= $filter_query ?><?= $sort_query ?>&page=<?= $new_page ?>"><?= $new_page ?></a>&nbsp;
<?php <?php
} }
} }
@ -239,7 +248,7 @@ if ( $mode == "still" && $paged && !empty($page) )
foreach ( $new_pages as $new_page ) foreach ( $new_pages as $new_page )
{ {
?> ?>
&nbsp;<a href="<?= $PHP_SELF ?>?view=event&mode=still&mid=<?= $mid ?>&eid=<?= $eid ?>&page=<?= $new_page ?>"><?= $new_page ?></a> &nbsp;<a href="<?= $PHP_SELF ?>?view=event&mode=still&eid=<?= $eid ?><?= $filter_query ?><?= $sort_query ?>&page=<?= $new_page ?>"><?= $new_page ?></a>
<?php <?php
} }
} }
@ -394,7 +403,7 @@ else
$alarm_frame = $alarm_frames[$frame_id]; $alarm_frame = $alarm_frames[$frame_id];
$img_class = $alarm_frame?"alarm":"normal"; $img_class = $alarm_frame?"alarm":"normal";
?> ?>
<td align="center" width="88"><a href="javascript: newWindow( '<?= $PHP_SELF ?>?view=frame&eid=<?= $eid ?>&fid=<?= $frame_id ?>', 'zmImage', <?= $event['Width']+$jws['image']['w'] ?>, <?= $event['Height']+$jws['image']['h'] ?> );"><img src="<?= $thumb_image ?>" width="<?= $thumb_width ?>" height="<? echo $thumb_height ?>" class="<?= $img_class ?>" alt="<?= $frame_id ?>/<?= $alarm_frame?$alarm_frame['Score']:0 ?>"></a></td> <td align="center" width="88"><a href="javascript: newWindow( '<?= $PHP_SELF ?>?view=frame&eid=<?= $eid ?>&fid=<?= $frame_id ?>', 'zmImage', <?= $event['Width']+$jws['image']['w'] ?>, <?= $event['Height']+$jws['image']['h'] ?> );"><img src="<?= $thumb_image ?>" width="<?= $thumb_width ?>" height="<?= $thumb_height ?>" class="<?= $img_class ?>" alt="<?= $frame_id ?>/<?= $alarm_frame?$alarm_frame['Score']:0 ?>"></a></td>
<?php <?php
flush(); flush();
if ( !(++$count % 4) ) if ( !(++$count % 4) )
@ -413,10 +422,10 @@ else
?> ?>
<tr> <tr>
<td colspan="6"><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr> <td colspan="6"><table width="100%" cellpadding="0" cellspacing="0" border="0"><tr>
<td width="25%" align="center" class="text"><?php if ( $prev_event ) { ?><a href="<?= $PHP_SELF ?>?view=<?= $view ?>&mode=<?= $mode ?>&mid=<?= $mid ?>&eid=<?= $prev_event['Id'] ?>&page=<?= $page ?>"><?= $zmSlangPrev ?></a><?php } else { ?>&nbsp;<?php } ?></td> <td width="25%" align="center" class="text"><?php if ( $prev_event ) { ?><a href="<?= $PHP_SELF ?>?view=<?= $view ?>&mode=<?= $mode ?>&eid=<?= $prev_event['Id'] ?><?= $filter_query ?><?= $sort_query ?>&page=<?= $page ?>"><?= $zmSlangPrev ?></a><?php } else { ?>&nbsp;<?php } ?></td>
<td width="25%" align="center" class="text"><?php if ( canEdit( 'Events' ) && $prev_event ) { ?><a href="<?= $PHP_SELF ?>?view=<?= $view ?>&mode=<?= $mode ?>&mid=<?= $mid ?>&eid=<?= $prev_event['Id'] ?>&action=delete&mid=<?= $mid ?>&mark_eid=<?= $eid ?>&page=<?= $page ?>"><?= $zmSlangDeleteAndPrev ?></a><?php } else { ?>&nbsp;<?php } ?></td> <td width="25%" align="center" class="text"><?php if ( canEdit( 'Events' ) && $prev_event ) { ?><a href="<?= $PHP_SELF ?>?view=<?= $view ?>&mode=<?= $mode ?>&eid=<?= $prev_event['Id'] ?><?= $filter_query ?><?= $sort_query ?>&action=delete&mark_eid=<?= $eid ?>&page=<?= $page ?>"><?= $zmSlangDeleteAndPrev ?></a><?php } else { ?>&nbsp;<?php } ?></td>
<td width="25%" align="center" class="text"><?php if ( canEdit( 'Events' ) && $next_event ) { ?><a href="<?= $PHP_SELF ?>?view=<?= $view ?>&mode=<?= $mode ?>&mid=<?= $mid ?>&eid=<?= $next_event['Id'] ?>&action=delete&mid=<?= $mid ?>&mark_eid=<?= $eid ?>&page=<?= $page ?>"><?= $zmSlangDeleteAndNext ?></a><?php } else { ?>&nbsp;<?php } ?></td> <td width="25%" align="center" class="text"><?php if ( canEdit( 'Events' ) && $next_event ) { ?><a href="<?= $PHP_SELF ?>?view=<?= $view ?>&mode=<?= $mode ?>&eid=<?= $next_event['Id'] ?><?= $filter_query ?><?= $sort_query ?>&action=delete&mark_eid=<?= $eid ?>&page=<?= $page ?>"><?= $zmSlangDeleteAndNext ?></a><?php } else { ?>&nbsp;<?php } ?></td>
<td width="25%" align="center" class="text"><?php if ( $next_event ) { ?><a href="<?= $PHP_SELF ?>?view=<?= $view ?>&mode=<?= $mode ?>&mid=<?= $mid ?>&eid=<?= $next_event['Id'] ?>&page=<?= $page ?>"><?= $zmSlangNext ?></a><?php } else { ?>&nbsp;<?php } ?></td> <td width="25%" align="center" class="text"><?php if ( $next_event ) { ?><a href="<?= $PHP_SELF ?>?view=<?= $view ?>&mode=<?= $mode ?>&eid=<?= $next_event['Id'] ?><?= $filter_query ?><?= $sort_query ?>&page=<?= $page ?>"><?= $zmSlangNext ?></a><?php } else { ?>&nbsp;<?php } ?></td>
</tr></table></td> </tr></table></td>
</tr> </tr>
</table> </table>

View File

@ -32,54 +32,6 @@ while( $row = mysql_fetch_assoc( $result ) )
$monitors[$row[Id]] = $row; $monitors[$row[Id]] = $row;
} }
if ( !isset($sort_parms) )
{
$sort_parms = "";
}
if ( !isset($sort_field) )
{
$sort_field = "Time";
$sort_asc = false;
}
switch( $sort_field )
{
case 'Id' :
$sort_column = "E.Id";
break;
case 'MonitorName' :
$sort_column = "M.Name";
break;
case 'Name' :
$sort_column = "E.Name";
break;
case 'Time' :
$sort_column = "E.StartTime";
break;
case 'Secs' :
$sort_column = "E.Length";
break;
case 'Frames' :
$sort_column = "E.Frames";
break;
case 'AlarmFrames' :
$sort_column = "E.AlarmFrames";
break;
case 'TotScore' :
$sort_column = "E.TotScore";
break;
case 'AvgScore' :
$sort_column = "E.AvgScore";
break;
case 'MaxScore' :
$sort_column = "E.MaxScore";
break;
default:
$sort_column = "E.StartTime";
break;
}
$sort_order = $sort_asc?"asc":"desc";
if ( !$sort_asc ) $sort_asc = 0;
$count_sql = "select count(E.Id) as EventCount from Monitors as M inner join Events as E on (M.Id = E.MonitorId) where"; $count_sql = "select count(E.Id) as EventCount from Monitors as M inner join Events as E on (M.Id = E.MonitorId) where";
$events_sql = "select E.Id,E.MonitorId,M.Name As MonitorName,E.Name,E.StartTime,E.Length,E.Frames,E.AlarmFrames,E.TotScore,E.AvgScore,E.MaxScore,E.Archived,E.LearnState from Monitors as M inner join Events as E on (M.Id = E.MonitorId) where"; $events_sql = "select E.Id,E.MonitorId,M.Name As MonitorName,E.Name,E.StartTime,E.Length,E.Frames,E.AlarmFrames,E.TotScore,E.AvgScore,E.MaxScore,E.Archived,E.LearnState from Monitors as M inner join Events as E on (M.Id = E.MonitorId) where";
if ( $user['MonitorIds'] ) if ( $user['MonitorIds'] )
@ -92,114 +44,14 @@ else
$count_sql .= " 1"; $count_sql .= " 1";
$events_sql .= " 1"; $events_sql .= " 1";
} }
$filter_query = '';
$filter_sql = '';
$filter_fields = '';
if ( $trms )
{
$filter_query .= "&trms=$trms";
$filter_fields .= '<input type="hidden" name="trms" value="'.$trms.'">'."\n";
}
for ( $i = 1; $i <= $trms; $i++ )
{
$conjunction_name = "cnj$i";
$obracket_name = "obr$i";
$cbracket_name = "cbr$i";
$attr_name = "attr$i";
$op_name = "op$i";
$value_name = "val$i";
if ( isset($$conjunction_name) )
{
$filter_query .= "&$conjunction_name=".$$conjunction_name;
$filter_sql .= " ".$$conjunction_name." ";
$filter_fields .= '<input type="hidden" name="'.$conjunction_name.'" value="'.$$conjunction_name.'">'."\n";
}
if ( isset($$obracket_name) )
{
$filter_query .= "&$obracket_name=".$$obracket_name;
$filter_sql .= str_repeat( "(", $$obracket_name );
$filter_fields .= '<input type="hidden" name="'.$obracket_name.'" value="'.$$obracket_name.'">'."\n";
}
if ( isset($$attr_name) )
{
$filter_query .= "&$attr_name=".$$attr_name;
$filter_fields .= '<input type="hidden" name="'.$attr_name.'" value="'.$$attr_name.'">'."\n";
$value = $$value_name;
switch ( $$attr_name )
{
case 'MonitorName':
$filter_sql .= 'M.'.preg_replace( '/^Monitor/', '', $$attr_name );
break;
case 'DateTime':
$value = strftime( "%Y-%m-%d %H:%M:%S", strtotime( $$value_name ) );
$filter_sql .= "E.StartTime";
break;
case 'Date':
$value = "to_days( '".strftime( "%Y-%m-%d %H:%M:%S", strtotime( $$value_name ) )."' )";
$filter_sql .= "to_days( E.StartTime )";
break;
case 'Time':
$value = "extract( hour_second from '".strftime( "%Y-%m-%d %H:%M:%S", strtotime( $$value_name ) )."' )";
$filter_sql .= "extract( hour_second from E.StartTime )";
break;
case 'Weekday':
$value = "weekday( '".strftime( "%Y-%m-%d %H:%M:%S", strtotime( $$value_name ) )."' )";
$filter_sql .= "weekday( E.StartTime )";
break;
case 'MonitorId':
case 'Length':
case 'Frames':
case 'AlarmFrames':
case 'TotScore':
case 'AvgScore':
case 'MaxScore':
$filter_sql .= "E.".$$attr_name;
break;
case 'Archived':
$filter_sql .= "E.Archived = ".$$value_name;
break;
}
switch ( $$op_name ) parseSort();
{ parseFilter();
case '=' :
case '!=' :
case '>=' :
case '>' :
case '<' :
case '<=' :
$filter_sql .= " ".$$op_name." '$value'";
break;
case '=~' :
$filter_sql .= " regexp '$value'";
break;
case '!~' :
$filter_sql .= " not regexp '$value'";
break;
case '=[]' :
$filter_sql .= " in ('".join( "','", preg_split( '/["\'\s]*,["\'\s]*/', $value ) )."')";
break;
case '![]' :
$filter_sql .= " not in ('".join( "','", preg_split( '/["\'\s]*,["\'\s]*/', $value ) )."')";
break;
}
$filter_query .= "&$op_name=".urlencode($$op_name);
$filter_fields .= '<input type="hidden" name="'.$op_name.'" value="'.$$op_name.'">'."\n";
$filter_query .= "&$value_name=".urlencode($$value_name);
$filter_fields .= '<input type="hidden" name="'.$value_name.'" value="'.$$value_name.'">'."\n";
}
if ( isset($$cbracket_name) )
{
$filter_query .= "&$cbracket_name=".$$cbracket_name;
$filter_sql .= str_repeat( ")", $$cbracket_name );
$filter_fields .= '<input type="hidden" name="'.$cbracket_name.'" value="'.$$cbracket_name.'">'."\n";
}
}
if ( $filter_sql ) if ( $filter_sql )
{ {
$count_sql .= " and ( $filter_sql )"; $count_sql .= $filter_sql;
$events_sql .= " and ( $filter_sql )"; $events_sql .= $filter_sql;
} }
$events_sql .= " order by $sort_column $sort_order"; $events_sql .= " order by $sort_column $sort_order";
if ( $page ) if ( $page )
@ -270,7 +122,7 @@ if ( isset($filter) )
?> ?>
//opener.location.reload(true); //opener.location.reload(true);
filterWindow( '<?= $PHP_SELF ?>?view=filter&page=<?= $page ?><?= $filter_query ?>', 'zmFilter' ); filterWindow( '<?= $PHP_SELF ?>?view=filter&page=<?= $page ?><?= $filter_query ?>', 'zmFilter' );
location.replace( '<?= $PHP_SELF ?>?view=events&page=<?= $page ?><?= $filter_query ?>' ); location.replace( '<?= $PHP_SELF ?>?view=<?= $view ?>&page=<?= $page ?><?= $filter_query ?>' );
</script> </script>
</head> </head>
</html> </html>
@ -339,7 +191,7 @@ else
foreach ( $new_pages as $new_page ) foreach ( $new_pages as $new_page )
{ {
?> ?>
<a href="<?= $PHP_SELF ?>?view=events&page=<?= $new_page ?>&<?= $filter_query ?><?= $sort_parms ?>&sort_field=<?= $sort_field ?>&sort_asc=<?= $sort_asc ?>"><?= $new_page ?></a>&nbsp; <a href="<?= $PHP_SELF ?>?view=<?= $view ?>&page=<?= $new_page ?><?= $filter_query ?><?= $sort_query ?>"><?= $new_page ?></a>&nbsp;
<?php <?php
} }
} }
@ -367,20 +219,20 @@ else
foreach ( $new_pages as $new_page ) foreach ( $new_pages as $new_page )
{ {
?> ?>
&nbsp;<a href="<?= $PHP_SELF ?>?view=events&page=<?= $new_page ?>&<?= $filter_query ?><?= $sort_parms ?>&sort_field=<?= $sort_field ?>&sort_asc=<?= $sort_asc ?>"><?= $new_page ?></a> &nbsp;<a href="<?= $PHP_SELF ?>?view=<?= $view ?>&page=<?= $new_page ?><?= $filter_query ?><?= $sort_query ?>"><?= $new_page ?></a>
<?php <?php
} }
} }
?> ?>
</td> </td>
<td align="right" class="text" width="10%"><a href="<?= $PHP_SELF ?>?view=events&page=0&<?= $filter_query ?><?= $sort_parms ?>&sort_field=<?= $sort_field ?>&sort_asc=<?= $sort_asc ?>"><?= $zmSlangViewAll ?></a></td> <td align="right" class="text" width="10%"><a href="<?= $PHP_SELF ?>?view=<?= $view ?>&page=0<?= $filter_query ?><?= $sort_query ?>"><?= $zmSlangViewAll ?></a></td>
<?php <?php
} }
else else
{ {
?> ?>
<td align="center" class="text" width="60%">&nbsp;</td> <td align="center" class="text" width="60%">&nbsp;</td>
<td align="center" class="text" width="10%"><a href="<?= $PHP_SELF ?>?view=events&page=1&<?= $filter_query ?><?= $sort_parms ?>&sort_field=<?= $sort_field ?>&sort_asc=<?= $sort_asc ?>"><?= $zmSlangViewPaged ?></a></td> <td align="center" class="text" width="10%"><a href="<?= $PHP_SELF ?>?view=<?= $view ?>&page=1&<?= $filter_query ?><?= $sort_query ?>"><?= $zmSlangViewPaged ?></a></td>
<?php <?php
} }
} }
@ -406,16 +258,16 @@ else
{ {
?> ?>
<tr align="center" bgcolor="#FFFFFF"> <tr align="center" bgcolor="#FFFFFF">
<td class="text"><a href="<?= $PHP_SELF ?>?view=events&page=1&<?= $filter_query ?><?= $sort_parms ?>&sort_field=Id&sort_asc=<?= $sort_field == 'Id'?!$sort_asc:0 ?>"><?= $zmSlangId ?><?php if ( $sort_field == "Id" ) if ( $sort_asc ) echo "(^)"; else echo "(v)"; ?></a></td> <td class="text"><a href="<?= $PHP_SELF ?>?view=<?= $view ?>&page=1&<?= $filter_query ?>&sort_field=Id&sort_asc=<?= $sort_field == 'Id'?!$sort_asc:0 ?>"><?= $zmSlangId ?><?php if ( $sort_field == "Id" ) if ( $sort_asc ) echo "(^)"; else echo "(v)"; ?></a></td>
<td class="text"><a href="<?= $PHP_SELF ?>?view=events&page=1&<?= $filter_query ?><?= $sort_parms ?>&sort_field=Name&sort_asc=<?= $sort_field == 'Name'?!$sort_asc:0 ?>"><?= $zmSlangName ?><?php if ( $sort_field == "Name" ) if ( $sort_asc ) echo "(^)"; else echo "(v)"; ?></a></td> <td class="text"><a href="<?= $PHP_SELF ?>?view=<?= $view ?>&page=1&<?= $filter_query ?>&sort_field=Name&sort_asc=<?= $sort_field == 'Name'?!$sort_asc:0 ?>"><?= $zmSlangName ?><?php if ( $sort_field == "Name" ) if ( $sort_asc ) echo "(^)"; else echo "(v)"; ?></a></td>
<td class="text"><a href="<?= $PHP_SELF ?>?view=events&page=1&<?= $filter_query ?><?= $sort_parms ?>&sort_field=MonitorName&sort_asc=<?= $sort_field == 'MonitorName'?!$sort_asc:0 ?>"><?= $zmSlangMonitor ?><?php if ( $sort_field == "MonitorName" ) if ( $sort_asc ) echo "(^)"; else echo "(v)"; ?></a></td> <td class="text"><a href="<?= $PHP_SELF ?>?view=<?= $view ?>&page=1&<?= $filter_query ?>&sort_field=MonitorName&sort_asc=<?= $sort_field == 'MonitorName'?!$sort_asc:0 ?>"><?= $zmSlangMonitor ?><?php if ( $sort_field == "MonitorName" ) if ( $sort_asc ) echo "(^)"; else echo "(v)"; ?></a></td>
<td class="text"><a href="<?= $PHP_SELF ?>?view=events&page=1&<?= $filter_query ?><?= $sort_parms ?>&sort_field=Time&sort_asc=<?= $sort_field == 'Time'?!$sort_asc:0 ?>"><?= $zmSlangTime ?><?php if ( $sort_field == "Time" ) if ( $sort_asc ) echo "(^)"; else echo "(v)"; ?></a></td> <td class="text"><a href="<?= $PHP_SELF ?>?view=<?= $view ?>&page=1&<?= $filter_query ?>&sort_field=StartTime&sort_asc=<?= $sort_field == 'StartTime'?!$sort_asc:0 ?>"><?= $zmSlangTime ?><?php if ( $sort_field == "StartTime" ) if ( $sort_asc ) echo "(^)"; else echo "(v)"; ?></a></td>
<td class="text"><a href="<?= $PHP_SELF ?>?view=events&page=1&<?= $filter_query ?><?= $sort_parms ?>&sort_field=Secs&sort_asc=<?= $sort_field == 'Secs'?!$sort_asc:0 ?>"><?= $zmSlangDuration ?><?php if ( $sort_field == "Secs" ) if ( $sort_asc ) echo "(^)"; else echo "(v)"; ?></a></td> <td class="text"><a href="<?= $PHP_SELF ?>?view=<?= $view ?>&page=1&<?= $filter_query ?>&sort_field=Secs&sort_asc=<?= $sort_field == 'Secs'?!$sort_asc:0 ?>"><?= $zmSlangDuration ?><?php if ( $sort_field == "Secs" ) if ( $sort_asc ) echo "(^)"; else echo "(v)"; ?></a></td>
<td class="text"><a href="<?= $PHP_SELF ?>?view=events&page=1&<?= $filter_query ?><?= $sort_parms ?>&sort_field=Frames&sort_asc=<?= $sort_field == 'Frames'?!$sort_asc:0 ?>"><?= $zmSlangFrames ?><?php if ( $sort_field == "Frames" ) if ( $sort_asc ) echo "(^)"; else echo "(v)"; ?></a></td> <td class="text"><a href="<?= $PHP_SELF ?>?view=<?= $view ?>&page=1&<?= $filter_query ?>&sort_field=Frames&sort_asc=<?= $sort_field == 'Frames'?!$sort_asc:0 ?>"><?= $zmSlangFrames ?><?php if ( $sort_field == "Frames" ) if ( $sort_asc ) echo "(^)"; else echo "(v)"; ?></a></td>
<td class="text"><a href="<?= $PHP_SELF ?>?view=events&page=1&<?= $filter_query ?><?= $sort_parms ?>&sort_field=AlarmFrames&sort_asc=<?= $sort_field == 'AlarmFrames'?!$sort_asc:0 ?>"><?= $zmSlangAlarmBrFrames ?><?php if ( $sort_field == "AlarmFrames" ) if ( $sort_asc ) echo "(^)"; else echo "(v)"; ?></a></td> <td class="text"><a href="<?= $PHP_SELF ?>?view=<?= $view ?>&page=1&<?= $filter_query ?>&sort_field=AlarmFrames&sort_asc=<?= $sort_field == 'AlarmFrames'?!$sort_asc:0 ?>"><?= $zmSlangAlarmBrFrames ?><?php if ( $sort_field == "AlarmFrames" ) if ( $sort_asc ) echo "(^)"; else echo "(v)"; ?></a></td>
<td class="text"><a href="<?= $PHP_SELF ?>?view=events&page=1&<?= $filter_query ?><?= $sort_parms ?>&sort_field=TotScore&sort_asc=<?= $sort_field == 'TotScore'?!$sort_asc:0 ?>"><?= $zmSlangTotalBrScore ?><?php if ( $sort_field == "TotScore" ) if ( $sort_asc ) echo "(^)"; else echo "(v)"; ?></a></td> <td class="text"><a href="<?= $PHP_SELF ?>?view=<?= $view ?>&page=1&<?= $filter_query ?>&sort_field=TotScore&sort_asc=<?= $sort_field == 'TotScore'?!$sort_asc:0 ?>"><?= $zmSlangTotalBrScore ?><?php if ( $sort_field == "TotScore" ) if ( $sort_asc ) echo "(^)"; else echo "(v)"; ?></a></td>
<td class="text"><a href="<?= $PHP_SELF ?>?view=events&page=1&<?= $filter_query ?><?= $sort_parms ?>&sort_field=AvgScore&sort_asc=<?= $sort_field == 'AvgScore'?!$sort_asc:0 ?>"><?= $zmSlangAvgBrScore ?><?php if ( $sort_field == "AvgScore" ) if ( $sort_asc ) echo "(^)"; else echo "(v)"; ?></a></td> <td class="text"><a href="<?= $PHP_SELF ?>?view=<?= $view ?>&page=1&<?= $filter_query ?>&sort_field=AvgScore&sort_asc=<?= $sort_field == 'AvgScore'?!$sort_asc:0 ?>"><?= $zmSlangAvgBrScore ?><?php if ( $sort_field == "AvgScore" ) if ( $sort_asc ) echo "(^)"; else echo "(v)"; ?></a></td>
<td class="text"><a href="<?= $PHP_SELF ?>?view=events&page=1&<?= $filter_query ?><?= $sort_parms ?>&sort_field=MaxScore&sort_asc=<?= $sort_field == 'MaxScore'?!$sort_asc:0 ?>"><?= $zmSlangMaxBrScore ?><?php if ( $sort_field == "MaxScore" ) if ( $sort_asc ) echo "(^)"; else echo "(v)"; ?></a></td> <td class="text"><a href="<?= $PHP_SELF ?>?view=<?= $view ?>&page=1&<?= $filter_query ?>&sort_field=MaxScore&sort_asc=<?= $sort_field == 'MaxScore'?!$sort_asc:0 ?>"><?= $zmSlangMaxBrScore ?><?php if ( $sort_field == "MaxScore" ) if ( $sort_asc ) echo "(^)"; else echo "(v)"; ?></a></td>
<td class="text">Mark</td> <td class="text">Mark</td>
</tr> </tr>
<?php <?php
@ -428,8 +280,8 @@ else
unset( $bgcolor ); unset( $bgcolor );
?> ?>
<tr<?= ' bgcolor="'.(isset($bgcolor)?$bgcolor:"#FFFFFF").'"' ?> > <tr<?= ' bgcolor="'.(isset($bgcolor)?$bgcolor:"#FFFFFF").'"' ?> >
<td align="center" class="text"><a href="javascript: eventWindow( '<?= $PHP_SELF ?>?view=event&eid=<?= $event['Id'] ?>&page=1', 'zmEvent', <?= $monitors[$event['MonitorId']]['Width']+$jws['event']['w'] ?>, <?= $monitors[$event['MonitorId']]['Height']+$jws['event']['h'] ?> );"><?= $event['Id'] ?><?php if ( $event['Archived'] ) echo "*" ?></a></td> <td align="center" class="text"><a href="javascript: eventWindow( '<?= $PHP_SELF ?>?view=event&eid=<?= $event['Id'] ?><?= $filter_query ?><?= $sort_query ?>&page=1', 'zmEvent', <?= $monitors[$event['MonitorId']]['Width']+$jws['event']['w'] ?>, <?= $monitors[$event['MonitorId']]['Height']+$jws['event']['h'] ?> );"><?= $event['Id'] ?><?php if ( $event['Archived'] ) echo "*" ?></a></td>
<td align="center" class="text"><a href="javascript: eventWindow( '<?= $PHP_SELF ?>?view=event&eid=<?= $event['Id'] ?>&page=1', 'zmEvent', <?= $monitors[$event['MonitorId']]['Width']+$jws['event']['w'] ?>, <?= $monitors[$event['MonitorId']]['Height']+$jws['event']['h'] ?> );"><?= $event['Name'] ?><?php if ( $event['Archived'] ) echo "*" ?></a></td> <td align="center" class="text"><a href="javascript: eventWindow( '<?= $PHP_SELF ?>?view=event&eid=<?= $event['Id'] ?><?= $filter_query ?><?= $sort_query ?>&page=1', 'zmEvent', <?= $monitors[$event['MonitorId']]['Width']+$jws['event']['w'] ?>, <?= $monitors[$event['MonitorId']]['Height']+$jws['event']['h'] ?> );"><?= $event['Name'] ?><?php if ( $event['Archived'] ) echo "*" ?></a></td>
<td align="center" class="text"><?= $event['MonitorName'] ?></td> <td align="center" class="text"><?= $event['MonitorName'] ?></td>
<td align="center" class="text"><?= strftime( "%m/%d %H:%M:%S", strtotime($event['StartTime']) ) ?></td> <td align="center" class="text"><?= strftime( "%m/%d %H:%M:%S", strtotime($event['StartTime']) ) ?></td>
<td align="center" class="text"><?= $event['Length'] ?></td> <td align="center" class="text"><?= $event['Length'] ?></td>

View File

@ -23,38 +23,9 @@ if ( !canView( 'Events' ) )
$view = "error"; $view = "error";
return; return;
} }
if ( empty($sort_field) )
{ parseSort();
$sort_field = "Time";
$sort_asc = false;
}
switch( $sort_field )
{
case 'Id' :
$sort_column = "E.Id";
break;
case 'Name' :
$sort_column = "E.Name";
break;
case 'Time' :
$sort_column = "E.StartTime";
break;
case 'Secs' :
$sort_column = "E.Length";
break;
case 'Frames' :
$sort_column = "E.Frames";
break;
case 'Score' :
$sort_column = "E.AvgScore";
break;
default:
$sort_column = "E.StartTime";
break;
}
$sort_order = $sort_asc?"asc":"desc";
if ( !$sort_asc )
$sort_asc = 0;
if ( ZM_WEB_REFRESH_METHOD == "http" ) if ( ZM_WEB_REFRESH_METHOD == "http" )
header("Refresh: ".REFRESH_EVENTS."; URL=$PHP_SELF?view=watchevents&mid=$mid&max_events=".MAX_EVENTS ); header("Refresh: ".REFRESH_EVENTS."; URL=$PHP_SELF?view=watchevents&mid=$mid&max_events=".MAX_EVENTS );
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
@ -160,8 +131,8 @@ while( $event = mysql_fetch_assoc( $result ) )
{ {
?> ?>
<tr bgcolor="#FFFFFF"> <tr bgcolor="#FFFFFF">
<td align="center" class="text"><a href="javascript: eventWindow( '<?= $PHP_SELF ?>?view=event&mid=<?= $mid ?>&eid=<?= $event['Id'] ?>&page=1', 'zmEvent' );"><?= $event['Id'] ?></a></td> <td align="center" class="text"><a href="javascript: eventWindow( '<?= $PHP_SELF ?>?view=event&eid=<?= $event['Id'] ?>&trms=1&attr1=MonitorId&op1=%3d&val1=&page=1', 'zmEvent' );"><?= $event['Id'] ?></a></td>
<td align="center" class="text"><a href="javascript: eventWindow( '<?= $PHP_SELF ?>?view=event&mid=<?= $mid ?>&eid=<?= $event['Id'] ?>&page=1', 'zmEvent' );"><?= $event['Name'] ?></a></td> <td align="center" class="text"><a href="javascript: eventWindow( '<?= $PHP_SELF ?>?view=event&eid=<?= $event['Id'] ?>&trms=1&attr1=MonitorId&op1=%3d&val1=&page=1', 'zmEvent' );"><?= $event['Name'] ?></a></td>
<td align="center" class="text"><?= strftime( "%m/%d %H:%M:%S", strtotime($event['StartTime']) ) ?></td> <td align="center" class="text"><?= strftime( "%m/%d %H:%M:%S", strtotime($event['StartTime']) ) ?></td>
<td align="center" class="text"><?= $event['Length'] ?></td> <td align="center" class="text"><?= $event['Length'] ?></td>
<td align="center" class="text"><a href="javascript: newWindow( '<?= $PHP_SELF ?>?view=frames&eid=<?= $event['Id'] ?>', 'zmFrames', <?= $jws['frames']['w'] ?>, <?= $jws['frames']['h'] ?> );"><?= $event['Frames'] ?>/<?= $event['AlarmFrames'] ?></a></td> <td align="center" class="text"><a href="javascript: newWindow( '<?= $PHP_SELF ?>?view=frames&eid=<?= $event['Id'] ?>', 'zmFrames', <?= $jws['frames']['w'] ?>, <?= $jws['frames']['h'] ?> );"><?= $event['Frames'] ?>/<?= $event['AlarmFrames'] ?></a></td>