Update filter view to use Filter::find

This commit is contained in:
Isaac Connor 2019-07-23 09:59:49 -04:00
parent 9b6dedb35d
commit 346933126d
1 changed files with 32 additions and 29 deletions

View File

@ -22,36 +22,35 @@ if ( !canView('Events') ) {
$view = 'error'; $view = 'error';
return; return;
} }
require_once 'includes/Filter.php'; require_once('includes/Object.php');
require_once('includes/Storage.php');
require_once('includes/Filter.php');
parseSort(); parseSort();
$filterNames = array( ''=>translate('ChooseFilter') ); $filterNames = array(''=>translate('ChooseFilter'));
$filter = NULL; $filter = NULL;
foreach ( dbFetchAll('SELECT * FROM Filters ORDER BY Name') as $row ) { foreach ( ZM\Filter::find(null,array('order'=>'lower(Name)')) as $Filter ) {
$filterNames[$row['Id']] = $row['Id'] . ' ' . $row['Name']; $filterNames[$Filter->Id()] = $Filter->Id() . ' ' . $Filter->Name();
if ( $row['Background'] ) if ( $Filter->Background() )
$filterNames[$row['Id']] .= '*'; $filterNames[$Filter->Id()] .= '*';
if ( $row['Concurrent'] ) if ( $Filter->Concurrent() )
$filterNames[$row['Id']] .= '&'; $filterNames[$Filter->Id()] .= '&';
if ( isset($_REQUEST['Id']) && $_REQUEST['Id'] == $row['Id'] ) { if ( isset($_REQUEST['Id']) && ($_REQUEST['Id'] == $Filter->Id()) ) {
$filter = new ZM\Filter($row); $filter = $Filter;
} }
} }
if ( ! $filter ) { if ( !$filter ) {
$filter = new ZM\Filter(); $filter = new ZM\Filter();
} }
if ( isset($_REQUEST['sort_field']) && isset($_REQUEST['filter']) ) { ZM\Logger::Debug("Query: " . $filter->Query_json());
$_REQUEST['filter']['Query']['sort_field'] = $_REQUEST['sort_field']; ZM\Logger::Debug("Query: " . print_r($filter->Query(), true));
$_REQUEST['filter']['Query']['sort_asc'] = $_REQUEST['sort_asc'];
$_REQUEST['filter']['Query']['limit'] = $_REQUEST['limit'];
}
if ( isset($_REQUEST['filter']) ) { if ( isset($_REQUEST['filter']) ) {
$filter->set($_REQUEST['filter']);
# Update our filter object with whatever changes we have made before saving # Update our filter object with whatever changes we have made before saving
#$filter->set($_REQUEST['filter']);
} }
$conjunctionTypes = getFilterQueryConjunctionTypes(); $conjunctionTypes = getFilterQueryConjunctionTypes();
@ -98,6 +97,7 @@ $attrTypes = array(
'DiskSpace' => translate('AttrDiskSpace'), 'DiskSpace' => translate('AttrDiskSpace'),
'SystemLoad' => translate('AttrSystemLoad'), 'SystemLoad' => translate('AttrSystemLoad'),
'StorageId' => translate('AttrStorageArea'), 'StorageId' => translate('AttrStorageArea'),
'SecondaryStorageId' => translate('AttrSecondaryStorageArea'),
'ServerId' => translate('AttrMonitorServer'), 'ServerId' => translate('AttrMonitorServer'),
'FilterServerId' => translate('AttrFilterServer'), 'FilterServerId' => translate('AttrFilterServer'),
'MonitorServerId' => translate('AttrMonitorServer'), 'MonitorServerId' => translate('AttrMonitorServer'),
@ -127,27 +127,24 @@ $archiveTypes = array(
$focusWindow = true; $focusWindow = true;
$storageareas = array('' => 'All'); $storageareas = array('' => 'All') + ZM\ZM_Object::Objects_Indexed_By_Id('ZM\Storage');
//$storageareas[0] = 'Default ' . ZM_DIR_EVENTS;
foreach ( dbFetchAll('SELECT Id,Name FROM Storage ORDER BY lower(Name) ASC') as $storage ) {
$storageareas[$storage['Id']] = $storage['Name'];
}
$weekdays = array(); $weekdays = array();
for ( $i = 0; $i < 7; $i++ ) { for ( $i = 0; $i < 7; $i++ ) {
$weekdays[$i] = strftime('%A', mktime(12, 0, 0, 1, $i+1, 2001)); $weekdays[$i] = strftime('%A', mktime(12, 0, 0, 1, $i+1, 2001));
} }
$states = array(); $states = array();
foreach ( dbFetchAll('SELECT Id, Name FROM States ORDER BY lower(Name) ASC') as $state_row ) { foreach ( dbFetchAll('SELECT `Id`, `Name` FROM `States` ORDER BY lower(`Name`) ASC') as $state_row ) {
$states[$state_row['Id']] = validHtmlStr($state_row['Name']); $states[$state_row['Id']] = validHtmlStr($state_row['Name']);
} }
$servers = array(); $servers = array();
$servers['ZM_SERVER_ID'] = 'Current Server'; $servers['ZM_SERVER_ID'] = 'Current Server';
$servers['NULL'] = 'No Server'; $servers['NULL'] = 'No Server';
foreach ( dbFetchAll('SELECT Id, Name FROM Servers ORDER BY lower(Name) ASC') as $server ) { foreach ( dbFetchAll('SELECT `Id`, `Name` FROM `Servers` ORDER BY lower(`Name`) ASC') as $server ) {
$servers[$server['Id']] = validHtmlStr($server['Name']); $servers[$server['Id']] = validHtmlStr($server['Name']);
} }
$monitors = array(); $monitors = array();
foreach ( dbFetchAll('SELECT Id, Name FROM Monitors ORDER BY Name ASC') as $monitor ) { foreach ( dbFetchAll('SELECT `Id`, `Name` FROM `Monitors` ORDER BY lower(`Name`) ASC') as $monitor ) {
if ( visibleMonitor($monitor['Id']) ) { if ( visibleMonitor($monitor['Id']) ) {
$monitors[$monitor['Name']] = validHtmlStr($monitor['Name']); $monitors[$monitor['Name']] = validHtmlStr($monitor['Name']);
} }
@ -391,7 +388,13 @@ if ( ZM_OPT_MESSAGE ) {
<label><?php echo translate('FilterDeleteEvents') ?></label> <label><?php echo translate('FilterDeleteEvents') ?></label>
<input type="checkbox" name="filter[AutoDelete]" value="1"<?php if ( $filter->AutoDelete() ) { ?> checked="checked"<?php } ?> data-on-click-this="updateButtons"/> <input type="checkbox" name="filter[AutoDelete]" value="1"<?php if ( $filter->AutoDelete() ) { ?> checked="checked"<?php } ?> data-on-click-this="updateButtons"/>
</p> </p>
<p><label><?php echo translate('FilterMoveEvents') ?></label> <p>
<label><?php echo translate('FilterCopyEvents') ?></label>
<input type="checkbox" name="filter[AutoCopy]" value="1"<?php if ( $filter->AutoCopy() ) { ?> checked="checked"<?php } ?> data-on-click-this="click_autocopy"/>
<?php echo htmlSelect('filter[AutoCopyTo]', $storageareas, $filter->AutoCopyTo(), $filter->AutoCopy() ? null : array('style'=>'display:none;')); ?>
</p>
<p>
<label><?php echo translate('FilterMoveEvents') ?></label>
<input type="checkbox" name="filter[AutoMove]" value="1"<?php if ( $filter->AutoMove() ) { ?> checked="checked"<?php } ?> data-on-click-this="click_automove"/> <input type="checkbox" name="filter[AutoMove]" value="1"<?php if ( $filter->AutoMove() ) { ?> checked="checked"<?php } ?> data-on-click-this="click_automove"/>
<?php echo htmlSelect('filter[AutoMoveTo]', $storageareas, $filter->AutoMoveTo(), $filter->AutoMove() ? null : array('style'=>'display:none;')); ?> <?php echo htmlSelect('filter[AutoMoveTo]', $storageareas, $filter->AutoMoveTo(), $filter->AutoMove() ? null : array('style'=>'display:none;')); ?>
</p> </p>