diff --git a/web/zm_funcs.php b/web/zm_funcs.php index 82738ef68..faa68fac8 100644 --- a/web/zm_funcs.php +++ b/web/zm_funcs.php @@ -421,4 +421,170 @@ function reScale( $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 .= ''."\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 .= ''."\n"; + } + if ( isset($$obracket_name) ) + { + $filter_query .= "&$obracket_name=".$$obracket_name; + $filter_sql .= str_repeat( "(", $$obracket_name ); + $filter_fields .= ''."\n"; + } + if ( isset($$attr_name) ) + { + $filter_query .= "&$attr_name=".$$attr_name; + $filter_fields .= ''."\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 .= ''."\n"; + $filter_query .= "&$value_name=".urlencode($$value_name); + $filter_fields .= ''."\n"; + } + if ( isset($$cbracket_name) ) + { + $filter_query .= "&$cbracket_name=".$$cbracket_name; + $filter_sql .= str_repeat( ")", $$cbracket_name ); + $filter_fields .= ''."\n"; + } + } + $filter_sql = " and ( $filter_sql )"; +} ?> diff --git a/web/zm_html_view_event.php b/web/zm_html_view_event.php index e19f440a2..4df0dd79e 100644 --- a/web/zm_html_view_event.php +++ b/web/zm_html_view_event.php @@ -40,29 +40,40 @@ else $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 ) die( mysql_error() ); $event = mysql_fetch_assoc( $result ); -if ( empty($mid) ) -{ - $mid = 0; -} -else -{ - $mid_sql .= " and MonitorId = '$mid'"; -} +parseSort(); +parseFilter(); -$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 ) 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 ) 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 ) ) $rate = RATE_SCALE; @@ -118,7 +129,6 @@ function newWindow(Url,Name,Width,Height)
- disabled>
@@ -127,7 +137,6 @@ function newWindow(Url,Name,Width,Height)
- @@ -138,8 +147,8 @@ Learn Pref:  - + :    :
@@ -149,22 +158,22 @@ Learn Pref: '."\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 .= ''."\n"; - } - if ( isset($$obracket_name) ) - { - $filter_query .= "&$obracket_name=".$$obracket_name; - $filter_sql .= str_repeat( "(", $$obracket_name ); - $filter_fields .= ''."\n"; - } - if ( isset($$attr_name) ) - { - $filter_query .= "&$attr_name=".$$attr_name; - $filter_fields .= ''."\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; - } +parseSort(); +parseFilter(); - $filter_query .= "&$op_name=".urlencode($$op_name); - $filter_fields .= ''."\n"; - $filter_query .= "&$value_name=".urlencode($$value_name); - $filter_fields .= ''."\n"; - } - if ( isset($$cbracket_name) ) - { - $filter_query .= "&$cbracket_name=".$$cbracket_name; - $filter_sql .= str_repeat( ")", $$cbracket_name ); - $filter_fields .= ''."\n"; - } -} if ( $filter_sql ) { - $count_sql .= " and ( $filter_sql )"; - $events_sql .= " and ( $filter_sql )"; + $count_sql .= $filter_sql; + $events_sql .= $filter_sql; } $events_sql .= " order by $sort_column $sort_order"; if ( $page ) @@ -270,7 +122,7 @@ if ( isset($filter) ) ?> //opener.location.reload(true); filterWindow( '?view=filter&page=', 'zmFilter' ); -location.replace( '?view=events&page=' ); +location.replace( '?view=&page=' ); @@ -339,7 +191,7 @@ else foreach ( $new_pages as $new_page ) { ?> -  +  - +   - + - - - - - - - - - - + + + + + + + + + + Mark > - - + + diff --git a/web/zm_html_view_watchevents.php b/web/zm_html_view_watchevents.php index 7b3a6a7e5..98e0adb5f 100644 --- a/web/zm_html_view_watchevents.php +++ b/web/zm_html_view_watchevents.php @@ -23,38 +23,9 @@ if ( !canView( 'Events' ) ) $view = "error"; return; } -if ( empty($sort_field) ) -{ - $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; + +parseSort(); + if ( ZM_WEB_REFRESH_METHOD == "http" ) 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 @@ -160,8 +131,8 @@ while( $event = mysql_fetch_assoc( $result ) ) { ?> - - + + /