'."\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 'MonitorId': case 'MonitorName': $filter_sql .= $$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 '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"; } } if ( $filter_sql ) { $count_sql .= " and ( $filter_sql )"; $events_sql .= " and ( $filter_sql )"; } $events_sql .= " order by $sort_column $sort_order"; if ( $page ) { $events_sql .= " limit ".(($page-1)*EVENT_HEADER_LINES).", ".EVENT_HEADER_LINES; } ?>