diff --git a/web/includes/Filter.php b/web/includes/Filter.php index 27fcc2ebc..593f46ad8 100644 --- a/web/includes/Filter.php +++ b/web/includes/Filter.php @@ -51,6 +51,8 @@ class Filter extends ZM_Object { if ($term->valid()) { if (!$this->_sql and $term->cnj) unset($term->cnj); $this->_sql .= $term->sql(); + } else { + Debug("Term is not valid " . $term->to_string()); } } # end foreach term } @@ -174,7 +176,6 @@ class Filter extends ZM_Object { } } - if ($this->{'Query'} and isset($this->{'Query'}['terms']) and count($this->{'Query'}['terms'])) { unset($this->{'Query'}['terms'][0]['cnj']); } @@ -959,18 +960,20 @@ class Filter extends ZM_Object { #$html .= ($i == 0) ? '' : htmlSelect("filter[Query][terms][$i][cnj]", $conjunctionTypes, $term['cnj']).PHP_EOL; $html .= ($i == 0) ? '' : html_input("filter[Query][terms][$i][cnj]", 'hidden', $term['cnj']).PHP_EOL; - $html .= ''; if ( isset($term['attr']) ) { + $html .= ''; + $html .= html_input("filter[Query][terms][$i][attr]", 'hidden', $term['attr']); + $html .= html_input("filter[Query][terms][$i][op]", 'hidden', '=').PHP_EOL; if ( $term['attr'] == 'Archived' ) { - $html .= html_input("filter[Query][terms]['.$i.'][op]", 'hidden', '=').PHP_EOL; $html .= htmlSelect("filter[Query][terms][$i][val]", $archiveTypes, $term['val']).PHP_EOL; } else if ( $term['attr'] == 'DateTime' || $term['attr'] == 'StartDateTime' || $term['attr'] == 'EndDateTime') { $html .= ''. $term['op'].''.PHP_EOL; #$html .= ''.htmlSelect("filter[Query][terms][$i][op]", $opTypes, $term['op']).''.PHP_EOL; $html .= ''.PHP_EOL; } else if ( $term['attr'] == 'Date' || $term['attr'] == 'StartDate' || $term['attr'] == 'EndDate' ) { - $html .= ''.htmlSelect("filter[Query][terms][$i][op]", $opTypes, $term['op']).''.PHP_EOL; - $html .= ''.PHP_EOL; + $html .= ''. $term['op'].''.PHP_EOL; + #$html .= ''.htmlSelect("filter[Query][terms][$i][op]", $opTypes, $term['op']).''.PHP_EOL; + $html .= ''.PHP_EOL; } else if ( $term['attr'] == 'StartTime' || $term['attr'] == 'EndTime' ) { $html .= ''.htmlSelect("filter[Query][terms][$i][op]", $opTypes, $term['op']).''.PHP_EOL; $html .= ''.PHP_EOL; diff --git a/web/includes/FilterTerm.php b/web/includes/FilterTerm.php index 121f5f626..8315020ab 100644 --- a/web/includes/FilterTerm.php +++ b/web/includes/FilterTerm.php @@ -32,7 +32,8 @@ class FilterTerm { $this->index = $index; if ($term) { - $this->attr = $term['attr']; + Debug(print_r($term, true)); + $this->attr = isset($term['attr']) ? $term['attr'] : ''; $this->op = $term['op']; $this->val = $term['val']; if ( isset($term['cnj']) ) { @@ -64,7 +65,7 @@ class FilterTerm { } } else { Warning("No term in FilterTerm constructor"); - Warning(print_r(debug_backtrace(), true)); + #Warning(print_r(debug_backtrace(), true)); } } # end function __construct @@ -72,7 +73,7 @@ class FilterTerm { public function sql_values() { $values = array(); if ( !isset($this->val) ) { - Logger::Warning('No value in term'.$this->attr); + Warning('No value in term'.$this->attr); return $values; } @@ -206,6 +207,9 @@ class FilterTerm { /* Some terms don't have related SQL */ public function sql() { + if (!$this->attr) { + return ''; + } $sql = ''; if ( isset($this->cnj) ) { @@ -507,6 +511,8 @@ class FilterTerm { public function valid() { switch ($this->attr) { + case 'EndDate' : + case 'StartDate' : case 'EndDateTime' : case 'StartDateTime' : if (!$this->val) @@ -520,6 +526,9 @@ class FilterTerm { } return true; } + public function to_string() { + return print_r($this, true); + } } # end class FilterTerm ?> diff --git a/web/includes/functions.php b/web/includes/functions.php index 493dafacc..8d50a61ae 100644 --- a/web/includes/functions.php +++ b/web/includes/functions.php @@ -2221,11 +2221,14 @@ function array_recursive_diff($aArray1, $aArray2) { function html_input($name, $type='text', $value='', $options=array()) { $html = '$name, 'value'=>$value, 'type'=>$type])) as $k) { + $options = array_merge($options, ['name'=>$name, 'value'=>$value, 'type'=>$type]); + + foreach (array_keys($options) as $k) { $attributes[] = $k.'="'.$options[$k].'"'; } $html .= join(' ', $attributes); $html .= '/>'; + return $html; } function html_radio($name, $values, $selected=null, $options=array(), $attrs=array()) { diff --git a/web/skins/classic/views/events.php b/web/skins/classic/views/events.php index 7d3cd60da..15163f370 100644 --- a/web/skins/classic/views/events.php +++ b/web/skins/classic/views/events.php @@ -38,8 +38,8 @@ $filter = isset($_REQUEST['filter_id']) ? new ZM\Filter($_REQUEST['filter_id']) if ( isset($_REQUEST['filter'])) { $filter->set($_REQUEST['filter']); } else if (!$filter->Id()) { - $filter->addTerm(array('cnj'=>'and', 'attr'=>'StartDateTime', 'op'=> '>=', 'val'=>'')); - $filter->addTerm(array('cnj'=>'and', 'attr'=>'EndDateTime', 'op'=> '<=', 'val'=>'')); + $filter->addTerm(array('cnj'=>'and', 'attr'=>'StartDate', 'op'=> '=', 'val'=>'')); + #$filter->addTerm(array('cnj'=>'and', 'attr'=>'StartDateTime', 'op'=> '<=', 'val'=>'')); $filter->addTerm(array('cnj'=>'and', 'attr'=>'Monitor', 'op'=> '=', 'val'=>'')); } diff --git a/web/skins/classic/views/js/events.js b/web/skins/classic/views/js/events.js index 18ca712cc..774b5434a 100644 --- a/web/skins/classic/views/js/events.js +++ b/web/skins/classic/views/js/events.js @@ -40,7 +40,6 @@ function ajaxRequest(params) { delete params.data.filter; } $j('#fieldsTable input').each(function(index) { - console.log(this); const el = $j(this); params.data[el.attr('name')] = el.val(); }); @@ -411,6 +410,9 @@ function initPage() { if (el.hasClass('datetimepicker')) { el.datetimepicker({timeFormat: "HH:mm:ss", dateFormat: "yy-mm-dd", maxDate: 0, constrainInput: false}); } + if (el.hasClass('datepicker')) { + el.datepicker({dateFormat: "yy-mm-dd", maxDate: 0, constrainInput: false}) + } }); table.bootstrapTable('resetSearch'); @@ -419,10 +421,19 @@ function initPage() { } function filterEvents() { + filterQuery = ''; + $j('#fieldsTable input').each(function(index) { + const el = $j(this); + filterQuery += '&'+encodeURIComponent(el.attr('name'))+'='+encodeURIComponent(el.val()); + }); + $j('#fieldsTable select').each(function(index) { + const el = $j(this); + filterQuery += '&'+encodeURIComponent(el.attr('name'))+'='+encodeURIComponent(el.val()); + }); + console.log(filterQuery); table.bootstrapTable('refresh'); } - $j(document).ready(function() { initPage(); }); diff --git a/web/skins/classic/views/options.php b/web/skins/classic/views/options.php index d2583585e..9b9db9a03 100644 --- a/web/skins/classic/views/options.php +++ b/web/skins/classic/views/options.php @@ -43,6 +43,7 @@ $tabs['highband'] = translate('HighBW'); $tabs['medband'] = translate('MediumBW'); $tabs['lowband'] = translate('LowBW'); $tabs['users'] = translate('Users'); +$tabs['groups'] = translate('Groups'); $tabs['control'] = translate('Control'); $tabs['privacy'] = translate('Privacy'); $tabs['MQTT'] = translate('MQTT'); @@ -200,6 +201,14 @@ foreach (array_map('basename', glob('skins/'.$skin.'/css/*', GLOB_ONLYDIR)) as $ } // Have to do this header('Location: '.$redirect); +} else if ($tab == 'groups') { + if (canView('Groups')) { + $redirect = '?view=groups'; + } else { + $redirect = '?view=error'; + } + // Have to do this + header('Location: '.$redirect); } else if ($tab == 'servers') { ?>