This commit is contained in:
Isaac Connor 2017-06-02 12:12:41 -04:00
parent 5228b9d008
commit 352ea6b6ae
1 changed files with 74 additions and 93 deletions

View File

@ -18,34 +18,31 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
if ( !canView( 'Events' ) )
{
$view = "error";
return;
if ( !canView( 'Events' ) ) {
$view = 'error';
return;
}
$selectName = "filterName";
$selectName = 'filterName';
$filterNames = array( ''=>translate('ChooseFilter') );
foreach ( dbFetchAll( "select * from Filters order by Name" ) as $row )
{
$filterNames[$row['Name']] = $row['Name'];
if ( $row['Background'] )
$filterNames[$row['Name']] .= "*";
if ( !empty($_REQUEST['reload']) && isset($_REQUEST['filterName']) && $_REQUEST['filterName'] == $row['Name'] )
$dbFilter = $row;
foreach ( dbFetchAll( 'select * from Filters order by Name' ) as $row ) {
$filterNames[$row['Name']] = $row['Name'];
if ( $row['Background'] )
$filterNames[$row['Name']] .= '*';
if ( !empty($_REQUEST['reload']) && isset($_REQUEST['filterName']) && $_REQUEST['filterName'] == $row['Name'] )
$dbFilter = $row;
}
$backgroundStr = "";
if ( isset($dbFilter) )
{
if ( $dbFilter['Background'] )
$backgroundStr = '['.strtolower(translate('Background')).']';
$_REQUEST['filter'] = jsonDecode( $dbFilter['Query'] );
$_REQUEST['sort_field'] = isset($_REQUEST['filter']['sort_field'])?$_REQUEST['filter']['sort_field']:"DateTime";
$_REQUEST['sort_asc'] = isset($_REQUEST['filter']['sort_asc'])?$_REQUEST['filter']['sort_asc']:"1";
$_REQUEST['limit'] = isset($_REQUEST['filter']['limit'])?$_REQUEST['filter']['limit']:"";
unset( $_REQUEST['filter']['sort_field'] );
unset( $_REQUEST['filter']['sort_asc'] );
unset( $_REQUEST['filter']['limit'] );
$backgroundStr = '';
if ( isset($dbFilter) ) {
if ( $dbFilter['Background'] )
$backgroundStr = '['.strtolower(translate('Background')).']';
$_REQUEST['filter'] = jsonDecode( $dbFilter['Query'] );
$_REQUEST['sort_field'] = isset($_REQUEST['filter']['sort_field'])?$_REQUEST['filter']['sort_field']:"DateTime";
$_REQUEST['sort_asc'] = isset($_REQUEST['filter']['sort_asc'])?$_REQUEST['filter']['sort_asc']:"1";
$_REQUEST['limit'] = isset($_REQUEST['filter']['limit'])?$_REQUEST['filter']['limit']:"";
unset( $_REQUEST['filter']['sort_field'] );
unset( $_REQUEST['filter']['sort_asc'] );
unset( $_REQUEST['filter']['limit'] );
}
# reload is set when the dropdown is changed.
@ -64,16 +61,14 @@ if ( isset( $_REQUEST['reload'] ) and ! $_REQUEST['reload'] ) {
$conjunctionTypes = array(
'and' => translate('ConjAnd'),
'or' => translate('ConjOr')
);
);
$obracketTypes = array();
$cbracketTypes = array();
if ( isset($_REQUEST['filter']['terms']) )
{
for ( $i = 0; $i <= count($_REQUEST['filter']['terms'])-2; $i++ )
{
$obracketTypes[$i] = str_repeat( "(", $i );
$cbracketTypes[$i] = str_repeat( ")", $i );
}
if ( isset($_REQUEST['filter']['terms']) ) {
for ( $i = 0; $i <= count($_REQUEST['filter']['terms'])-2; $i++ ) {
$obracketTypes[$i] = str_repeat( "(", $i );
$cbracketTypes[$i] = str_repeat( ")", $i );
}
}
$attrTypes = array(
@ -98,7 +93,7 @@ $attrTypes = array(
'DiskBlocks' => translate('AttrDiskBlocks'),
'SystemLoad' => translate('AttrSystemLoad'),
'ServerId' => translate('AttrServer'),
);
);
$opTypes = array(
'=' => translate('OpEq'),
'!=' => translate('OpNe'),
@ -110,15 +105,14 @@ $opTypes = array(
'!~' => translate('OpNotMatches'),
'=[]' => translate('OpIn'),
'![]' => translate('OpNotIn'),
);
);
$archiveTypes = array(
'0' => translate('ArchUnarchived'),
'1' => translate('ArchArchived')
);
);
$weekdays = array();
for ( $i = 0; $i < 7; $i++ )
{
$weekdays[$i] = strftime( "%A", mktime( 12, 0, 0, 1, $i+1, 2001 ) );
for ( $i = 0; $i < 7; $i++ ) {
$weekdays[$i] = strftime( '%A', mktime( 12, 0, 0, 1, $i+1, 2001 ) );
}
$sort_fields = array(
'Id' => translate('AttrId'),
@ -133,13 +127,12 @@ $sort_fields = array(
'TotScore' => translate('AttrTotalScore'),
'AvgScore' => translate('AttrAvgScore'),
'MaxScore' => translate('AttrMaxScore'),
);
);
$sort_dirns = array(
'1' => translate('SortAsc'),
'0' => translate('SortDesc')
);
if ( empty($_REQUEST['sort_field']) )
{
);
if ( empty($_REQUEST['sort_field']) ) {
$_REQUEST['sort_field'] = ZM_WEB_EVENT_SORT_FIELD;
$_REQUEST['sort_asc'] = (ZM_WEB_EVENT_SORT_ORDER == "asc");
}
@ -174,105 +167,93 @@ xhtmlHeaders(__FILE__, translate('EventFilter') );
<table id="fieldsTable" class="filterTable" cellspacing="0">
<tbody>
<?php
for ( $i = 0; isset($_REQUEST['filter']) && $i < count($_REQUEST['filter']['terms']); $i++ )
{
for ( $i = 0; isset($_REQUEST['filter']) && $i < count($_REQUEST['filter']['terms']); $i++ ) {
?>
<tr>
<?php
if ( $i == 0 )
{
if ( $i == 0 ) {
?>
<td>&nbsp;</td>
<?php
}
else
{
} else {
?>
<td><?php echo buildSelect( "filter[terms][$i][cnj]", $conjunctionTypes ); ?></td>
<?php
}
}
?>
<td><?php if ( count($_REQUEST['filter']['terms']) > 2 ) { echo buildSelect( "filter[terms][$i][obr]", $obracketTypes ); } else { ?>&nbsp;<?php } ?></td>
<td><?php echo buildSelect( "filter[terms][$i][attr]", $attrTypes, "clearValue( this, $i ); submitToFilter( this, 0 );" ); ?></td>
<?php
if ( isset($_REQUEST['filter']['terms'][$i]['attr']) )
{
if ( $_REQUEST['filter']['terms'][$i]['attr'] == "Archived" )
{
if ( isset($_REQUEST['filter']['terms'][$i]['attr']) ) {
if ( $_REQUEST['filter']['terms'][$i]['attr'] == 'Archived' ) {
?>
<td><?php echo translate('OpEq') ?><input type="hidden" name="filter[terms][<?php echo $i ?>][op]" value="="/></td>
<td><?php echo buildSelect( "filter[terms][$i][val]", $archiveTypes ); ?></td>
<?php
}
elseif ( $_REQUEST['filter']['terms'][$i]['attr'] == "DateTime" )
{
} elseif ( $_REQUEST['filter']['terms'][$i]['attr'] == 'DateTime' ) {
?>
<td><?php echo buildSelect( "filter[terms][$i][op]", $opTypes ); ?></td>
<td><input name="filter[terms][<?php echo $i ?>][val]" id="filter[terms][<?php echo $i ?>][val]" value="<?php echo isset($_REQUEST['filter']['terms'][$i]['val'])?validHtmlStr($_REQUEST['filter']['terms'][$i]['val']):'' ?>"/><?php if ( $hasCal ) { ?><script type="text/javascript">Calendar.setup( { inputField: "filter[terms][<?php echo $i ?>][val]", ifFormat: "%Y-%m-%d %H:%M", showsTime: true, timeFormat: "24", showOthers: true, weekNumbers: false });</script><?php } ?></td>
<td>
<input name="filter[terms][<?php echo $i ?>][val]" id="filter[terms][<?php echo $i ?>][val]" value="<?php echo isset($_REQUEST['filter']['terms'][$i]['val'])?validHtmlStr($_REQUEST['filter']['terms'][$i]['val']):'' ?>"/>
<?php if ( $hasCal ) { ?>
<script type="text/javascript">Calendar.setup( { inputField: "filter[terms][<?php echo $i ?>][val]", ifFormat: "%Y-%m-%d %H:%M", showsTime: true, timeFormat: "24", showOthers: true, weekNumbers: false });</script>
<?php } ?>
</td>
<?php
}
elseif ( $_REQUEST['filter']['terms'][$i]['attr'] == "Date" )
{
} elseif ( $_REQUEST['filter']['terms'][$i]['attr'] == 'Date' ) {
?>
<td><?php echo buildSelect( "filter[terms][$i][op]", $opTypes ); ?></td>
<td><input name="filter[terms][<?php echo $i ?>][val]" id="filter[terms][<?php echo $i ?>][val]" value="<?php echo isset($_REQUEST['filter']['terms'][$i]['val'])?validHtmlStr($_REQUEST['filter']['terms'][$i]['val']):'' ?>"/><?php if ( $hasCal ) { ?><script type="text/javascript">Calendar.setup( { inputField: "filter[terms][<?php echo $i ?>][val]", ifFormat: "%Y-%m-%d", showOthers: true, weekNumbers: false });</script><?php } ?></td>
<td>
<input name="filter[terms][<?php echo $i ?>][val]" id="filter[terms][<?php echo $i ?>][val]" value="<?php echo isset($_REQUEST['filter']['terms'][$i]['val'])?validHtmlStr($_REQUEST['filter']['terms'][$i]['val']):'' ?>"/>
<?php if ( $hasCal ) { ?>
<script type="text/javascript">Calendar.setup( { inputField: "filter[terms][<?php echo $i ?>][val]", ifFormat: "%Y-%m-%d", showOthers: true, weekNumbers: false });</script>
<?php } ?>
</td>
<?php
}
elseif ( $_REQUEST['filter']['terms'][$i]['attr'] == "Weekday" )
{
} elseif ( $_REQUEST['filter']['terms'][$i]['attr'] == 'Weekday' ) {
?>
<td><?php echo buildSelect( "filter[terms][$i][op]", $opTypes ); ?></td>
<td><?php echo buildSelect( "filter[terms][$i][val]", $weekdays ); ?></td>
<?php
} elseif ( false && $_REQUEST['filter']['terms'][$i]['attr'] == 'MonitorName' ) {
$monitors = array();
foreach ( dbFetchAll( "select Id,Name from Monitors order by Sequence asc" ) as $monitor ) {
if ( visibleMonitor( $monitor['Id'] ) ) {
$monitors[$monitor['Name']] = $monitor['Name'];
}
elseif ( false && $_REQUEST['filter']['terms'][$i]['attr'] == "MonitorName" )
{
$monitors = array();
foreach ( dbFetchAll( "select Id,Name from Monitors order by Sequence asc" ) as $monitor )
{
if ( visibleMonitor( $monitor['Id'] ) )
{
$monitors[$monitor['Name']] = $monitor['Name'];
}
}
}
?>
<td><?php echo buildSelect( "filter[terms][$i][op]", $opTypes ); ?></td>
<td><?php echo buildSelect( "filter[terms][$i][val]", $monitors ); ?></td>
<?php
}
elseif ( $_REQUEST['filter']['terms'][$i]['attr'] == "ServerId" )
{
$servers = array();
$servers['ZM_SERVER_ID'] = 'Current Server';
foreach ( dbFetchAll( "SELECT Id,Name FROM Servers ORDER BY lower(Name) ASC" ) as $server ) {
$servers[$server['Id']] = $server['Name'];
}
} elseif ( $_REQUEST['filter']['terms'][$i]['attr'] == 'ServerId' ) {
$servers = array();
$servers['ZM_SERVER_ID'] = 'Current Server';
foreach ( dbFetchAll( 'SELECT Id,Name FROM Servers ORDER BY lower(Name) ASC' ) as $server ) {
$servers[$server['Id']] = $server['Name'];
}
?>
<td><?php echo buildSelect( "filter[terms][$i][op]", $opTypes ); ?></td>
<td><?php echo buildSelect( "filter[terms][$i][val]", $servers ); ?></td>
<?php
}
else
{
} else {
?>
<td><?php echo buildSelect( "filter[terms][$i][op]", $opTypes ); ?></td>
<td><input name="filter[terms][<?php echo $i ?>][val]" value="<?php echo $_REQUEST['filter']['terms'][$i]['val'] ?>"/></td>
<?php
}
}
else
{
} else {
?>
<td><?php echo buildSelect( "filter[terms][$i][op]", $opTypes ); ?></td>
<td><input name="filter[terms][<?php echo $i ?>][val]" value="<?php echo isset($_REQUEST['filter']['terms'][$i]['val'])?$_REQUEST['filter']['terms'][$i]['val']:'' ?>"/></td>
<?php
}
}
?>
<td><?php if ( count($_REQUEST['filter']['terms']) > 2 ) { echo buildSelect( "filter[terms][$i][cbr]", $cbracketTypes ); } else { ?>&nbsp;<?php } ?></td>
<td><input type="button" onclick="addTerm( this, <?php echo $i+1 ?> )" value="+"/><?php if ( $_REQUEST['filter']['terms'] > 1 ) { ?><input type="button" onclick="delTerm( this, <?php echo $i ?> )" value="-"/><?php } ?></td>
</tr>
<?php
}
} # end foreach filter
?>
</tbody>
</table>
@ -346,9 +327,9 @@ if ( ZM_OPT_MESSAGE )
<input type="button" name="executeButton" id="executeButton" value="<?php echo translate('Execute') ?>" onclick="executeFilter( this );"/>
<?php if ( canEdit( 'Events' ) ) { ?>
<input type="button" value="<?php echo translate('Save') ?>" onclick="saveFilter( this );"/>
<?php } ?>
<?php if ( canEdit( 'Events' ) && isset($dbFilter) && $dbFilter['Name'] ) { ?>
<?php if ( isset($dbFilter) && $dbFilter['Name'] ) { ?>
<input type="button" value="<?php echo translate('Delete') ?>" onclick="deleteFilter( this, '<?php echo $dbFilter['Name'] ?>' );"/>
<?php } ?>
<?php } ?>
<input type="button" value="<?php echo translate('Reset') ?>" onclick="submitToFilter( this, 1 );"/>
</div>