form_header = $form_header; $this->form_action = $form_action; $this->form_id = $form_id; $this->form_width = $form_width; $this->action_url = $action_url; $this->action_label = $action_label; $this->session_var = $session_var; $this->item_rows = $item_rows; if ($this->action_url != '' && $this->action_label == '') { $this->action_label = __('Add'); } /* default filter */ $this->default_filter = array( 'rows' => array( 'row1' => array( 'filter' => array( 'friendly_name' => __('Search'), 'filter' => FILTER_DEFAULT, 'placeholder' => __('Enter a search term'), 'size' => '30', 'default' => '', 'pageset' => true, 'max_length' => '120' ), 'rows' => array( 'friendly_name' => __('Rows'), 'filter' => FILTER_VALIDATE_INT, 'method' => 'drop_array', 'default' => '-1', 'pageset' => true, 'array' => $this->item_rows ), 'go' => array( 'display' => __('Go'), 'title' => __('Apply filter to table'), 'method' => 'submit', ), 'clear' => array( 'display' => __('Clear'), 'title' => __('Reset filter to default values'), 'method' => 'button', ) ) ), 'sort' => array( 'sort_column' => 'name', 'sort_direction' => 'ASC' ) ); } public function __destruct() { return true; } public function set_filter_row($array, $index = false) { if ($index === false) { $this->filter_array['rows'][] = $array; } else { $this->filter_array['rows'][$index] = $array; } } public function get_filter_row($index) { if ($index === false ) { return false; } elseif (array_key_exists($index, $this->filter_array['rows'])) { return $this->filter_array['rows'][$index]; } else { return false; } } public function set_filter_array($array) { $this->filter_array = $array; } public function get_filter() { return $this->filter_array; } public function set_sort_array($sort_column, $sort_direction) { $this->filter_array['sort'] = array( 'sort_column' => $sort_column, 'sort_direction' => $sort_direction ); } public function filter_render() { /* setup filter variables */ sanitize_filter_variables(); /* render the filter in the page */ create_filter(); /* create javascript to operate of the filter */ create_javascript(); return true; } private function create_filter() { if (!cacti_sizeof($this->filter_array)) { $this->filter_array = $this->default_filter; } html_start_box($this->form_header, $this->form_width, true, '3', 'center', $this->action_url, $this->action_label); if (isset($this->form_array['rows'])) { print "
\n"; foreach($this->form_array['rows'] as $index => $row) { print "
\n"; print "
\n"; foreach($row as $field_name => $field_array) { switch($field_array['method']) { case 'button': print "
\n"; print "title) ? " title='" . html_escape($field_array->title, ENT_QUOTES, 'UTF-8'):'') . "'>"; print "
\n"; break; case 'submit': print "
\n"; print "title) ? " title='" . html_escape($field_array->title):'') . "'>"; print "
\n"; break; case 'timespan': print "
" . __('Presets') . "
\n"; break; default: if (isset($field_array['friendly_name'])) { print "
" . $field_array['friendly_name'] . "
\n"; } print "
\n"; draw_edit_control($field_name, $field_array); print "
\n"; } } print "
\n"; print "
\n"; } print "
\n"; } html_end_box(true, true); } private function create_javascript() { $applyFilter = '"' . $this->form_action; $clearFilter = $applyFilter; if (strpos('?', $applyFilter) === false) { $separator = '?'; } else { $separator = '&'; } $applyFilter .= $separator . 'header=false'; $clearFilter .= $separator . 'header=false&clear=true"'; $changeChain = ''; $separator = "\"+\"&"; if (isset($this->form_array['rows'])) { foreach($this->form_array['rows'] as $index => $row) { foreach($row as $field_name => $field_array) { switch($field_array['method']) { case 'button': case 'submit': break; case 'checkbox': $applyFilter .= $separator . $field_name . "=\"+\"$(\'#" . $field_name . "').is(':checked')"; break; case 'textbox': case 'drop_array': case 'drop_files': case 'drop_sql': case 'drop_callback': case 'drop_multi': case 'drop_color': case 'drop_tree': if ($field_array['method'] != 'textbox') { $changeChain .= ($changeChain != '' ? ', ':'') . '#' . $field_name; } $applyFilter .= $separator . $field_name . "=\"+\"$(\'#" . $field_name . "').val()"; break; default: } } } $applyFilter .= '";'; } ?> form_array['rows'])) { foreach($this->form_array['rows'] as $index => $row) { foreach($row as $field_name => $field_array) { switch($field_array['method']) { case 'button': case 'submit': break; default: $filters[$field_name]['filter'] = $field_array['filter']; if (isset($field_array['filter_options'])) { $filters[$field_name]['options'] = $field_array['filter_options']; } if (isset($field_array['pageset'])) { $filters[$field_name]['pageset'] = $field_array['pageset']; } if (isset($field_array['default'])) { $filters[$field_name]['default'] = $field_array['default']; } else { $filters[$field_name]['default'] = ''; } break; } } } } if (isset($this->form_array['sort'])) { $filters['sort_column']['filter'] = FILTER_CALLBACK; $filters['sort_column']['options'] = array('options' => 'sanitize_search_string'); $filters['sort_column']['default'] = $this->form_array['sort']['sort_column']; $filters['sort_direction']['filter'] = FILTER_CALLBACK; $filters['sort_direction']['options'] = array('options' => 'sanitize_search_string'); $filters['sort_direction']['default'] = $this->form_array['sort']['sort_direction']; } validate_store_request_vars($filters, $this->session_var); } }