diff --git a/application/controllers/Search.php b/application/controllers/Search.php index 3ef1f1f6..2a0fc3cc 100644 --- a/application/controllers/Search.php +++ b/application/controllers/Search.php @@ -50,262 +50,275 @@ class Search extends CI_Controller { } function json_result() { - if(isset($_POST['search'])) { - $json = $_POST['search']; - - $search_items = json_decode($json, true); - - $search_type = ""; - - foreach($search_items as $key=>$value){ - - - if($value == "AND") { - $search_type = "AND"; - } - if ($value == "OR") { - $search_type = "OR"; - } - - if(is_array($value)) { - foreach($value as $values) - { - - if(isset($values['rules'])) { - if($values['condition'] == "AND") { - $this->db->group_start(); - } else { - $this->db->or_group_start(); - } - foreach($values['rules'] as $group_value) - { - if($group_value['operator'] == "equal") { - if($values['condition'] == "AND") { - $this->db->where($group_value['field'], $group_value['value']); - } else { - $this->db->or_where($group_value['field'], $group_value['value']); - } - } - - if($group_value['operator'] == "not_equal") { - if($values['condition'] == "AND") { - $this->db->where($group_value['field'].' !=', $group_value['value']); - } else { - $this->db->or_where($group_value['field'].' !=', $group_value['value']); - } - } - - if($group_value['operator'] == "begins_with") { - if($values['condition'] == "AND") { - $this->db->where($group_value['field'].' like ', $group_value['value']."%"); - } else { - $this->db->or_where($group_value['field'].' like ', $group_value['value']."%"); - } - } - - if($group_value['operator'] == "contains") { - if($values['condition'] == "AND") { - $this->db->where($group_value['field'].' like ', "%".$group_value['value']."%"); - } else { - $this->db->or_where($group_value['field'].' like ', "%".$group_value['value']."%"); - } - } - - if($group_value['operator'] == "ends_with") { - if($values['condition'] == "AND") { - $this->db->where($group_value['field'].' like ', "%".$group_value['value']); - } else { - $this->db->or_where($group_value['field'].' like ', "%".$group_value['value']); - } - } - - if($group_value['operator'] == "is_empty") { - if($values['condition'] == "AND") { - $this->db->where($group_value['field'], "''"); - } else { - $this->db->or_where($group_value['field'], "''"); - } - } - - if($group_value['operator'] == "is_not_empty") { - if($values['condition'] == "AND") { - $this->db->where($group_value['field'].' !=', "''"); - } else { - $this->db->or_where($group_value['field'].' !=', "''"); - } - } - - if($group_value['operator'] == "is_null") { - if($values['condition'] == "AND") { - $this->db->where($group_value['field'].' is ', NULL); - } else { - $this->db->or_where($group_value['field'].' is ', NULL); - } - } - - if($group_value['operator'] == "is_not_null") { - if($values['condition'] == "AND") { - $this->db->where($group_value['field'].' is not ', NULL); - } else { - $this->db->or_where($group_value['field'].' is not ', NULL); - } - } - - - if($group_value['operator'] == "less") { - if($values['condition'] == "AND") { - $this->db->where($group_value['field'].' <', $group_value['value']); - } else { - $this->db->or_where($group_value['field'].' <', $group_value['value']); - } - } - - if($group_value['operator'] == "less_or_equal") { - if($values['condition'] == "AND") { - $this->db->where($group_value['field'].' <=', $group_value['value']); - } else { - $this->db->or_where($group_value['field'].' <=', $group_value['value']); - } - } - - if($group_value['operator'] == "greater") { - if($values['condition'] == "AND") { - $this->db->where($group_value['field'].' >', $group_value['value']); - } else { - $this->db->or_where($group_value['field'].' >', $group_value['value']); - } - } - - if($group_value['operator'] == "greater_or_equal") { - if($values['condition'] == "AND") { - $this->db->where($group_value['field'].' >=', $group_value['value']); - } else { - $this->db->or_where($group_value['field'].' >=', $group_value['value']); - } - } - - } - $this->db->group_end(); - } else { - //print_r($values['field']); - if(isset($values['operator'])) { - - } - if($values['operator'] == "equal") { - if($search_type == "AND") { - $this->db->where($values['field'], $values['value']); - } else { - $this->db->or_where($values['field'], $values['value']); - } - } - - if($values['operator'] == "not_equal") { - if($search_type == "AND") { - $this->db->where($values['field'].' !=', $values['value']); - } else { - $this->db->or_where($values['field'].' !=', $values['value']); - } - } - - if($values['operator'] == "begins_with") { - if($search_type == "AND") { - $this->db->where($values['field'].' like ', $values['value']."%"); - } else { - $this->db->or_where($values['field'].' like ', $values['value']."%"); - } - } - - if($values['operator'] == "contains") { - if($search_type == "AND") { - $this->db->where($values['field'].' like ', "%".$values['value']."%"); - } else { - $this->db->or_where($values['field'].' like ', "%".$values['value']."%"); - } - } - - if($values['operator'] == "ends_with") { - if($search_type == "AND") { - $this->db->where($values['field'].' like ', "%".$values['value']); - } else { - $this->db->or_where($values['field'].' like ', "%".$values['value']); - } - } - - if($values['operator'] == "is_empty") { - if($search_type == "AND") { - $this->db->where($values['field'], ""); - } else { - $this->db->or_where($values['field'], ""); - } - } - - if($values['operator'] == "is_not_empty") { - if($search_type == "AND") { - $this->db->where($values['field'].' !=', ""); - } else { - $this->db->or_where($values['field'].' !=', ""); - } - } - - if($values['operator'] == "is_null") { - if($search_type == "AND") { - $this->db->where($values['field'].' is ', NULL); - } else { - $this->db->or_where($values['field'].' is ', NULL); - } - } - - if($values['operator'] == "is_not_null") { - if($search_type == "AND") { - $this->db->where($values['field'].' is not ', NULL); - } else { - $this->db->or_where($values['field'].' is not ', NULL); - } - } - - if($values['operator'] == "less") { - if($search_type == "AND") { - $this->db->where($values['field'].' <', $values['value']); - } else { - $this->db->or_where($values['field'].' <', $values['value']); - } - } - - if($values['operator'] == "less_or_equal") { - if($search_type == "AND") { - $this->db->where($values['field'].' <=', $values['value']); - } else { - $this->db->or_where($values['field'].' <=', $values['value']); - } - } - - if($values['operator'] == "greater") { - if($search_type == "AND") { - $this->db->where($values['field'].' >', $values['value']); - } else { - $this->db->or_where($values['field'].' >', $values['value']); - } - } - - if($values['operator'] == "greater_or_equal") { - if($search_type == "AND") { - $this->db->where($values['field'].' >=', $values['value']); - } else { - $this->db->or_where($values['field'].' >=', $values['value']); - } - } - } - - } - } - } - $this->db->order_by('COL_TIME_ON', 'DESC'); - $query = $this->db->get($this->config->item('table_name')); - echo json_encode($query->result_array()); - } else { + $result = $this->fetchQueryResult($_POST['search']); + echo json_encode($result->result_array()); + } else { echo "Noooooooob"; } - } + + function export_to_adif() { + if(isset($_POST['search'])) { + $data['qsos'] = $this->fetchQueryResult($_POST['search']); + + $this->load->view('adif/data/exportall', $data); + } else { + echo "Noooooooob"; + } + } + + function fetchQueryResult($json) { + + $search_items = json_decode($json, true); + + $search_type = ""; + + foreach($search_items as $key=>$value){ + + + if($value == "AND") { + $search_type = "AND"; + } + if ($value == "OR") { + $search_type = "OR"; + } + + if(is_array($value)) { + foreach($value as $values) + { + + if(isset($values['rules'])) { + if($values['condition'] == "AND") { + $this->db->group_start(); + } else { + $this->db->or_group_start(); + } + foreach($values['rules'] as $group_value) + { + if($group_value['operator'] == "equal") { + if($values['condition'] == "AND") { + $this->db->where($group_value['field'], $group_value['value']); + } else { + $this->db->or_where($group_value['field'], $group_value['value']); + } + } + + if($group_value['operator'] == "not_equal") { + if($values['condition'] == "AND") { + $this->db->where($group_value['field'].' !=', $group_value['value']); + } else { + $this->db->or_where($group_value['field'].' !=', $group_value['value']); + } + } + + if($group_value['operator'] == "begins_with") { + if($values['condition'] == "AND") { + $this->db->where($group_value['field'].' like ', $group_value['value']."%"); + } else { + $this->db->or_where($group_value['field'].' like ', $group_value['value']."%"); + } + } + + if($group_value['operator'] == "contains") { + if($values['condition'] == "AND") { + $this->db->where($group_value['field'].' like ', "%".$group_value['value']."%"); + } else { + $this->db->or_where($group_value['field'].' like ', "%".$group_value['value']."%"); + } + } + + if($group_value['operator'] == "ends_with") { + if($values['condition'] == "AND") { + $this->db->where($group_value['field'].' like ', "%".$group_value['value']); + } else { + $this->db->or_where($group_value['field'].' like ', "%".$group_value['value']); + } + } + + if($group_value['operator'] == "is_empty") { + if($values['condition'] == "AND") { + $this->db->where($group_value['field'], "''"); + } else { + $this->db->or_where($group_value['field'], "''"); + } + } + + if($group_value['operator'] == "is_not_empty") { + if($values['condition'] == "AND") { + $this->db->where($group_value['field'].' !=', "''"); + } else { + $this->db->or_where($group_value['field'].' !=', "''"); + } + } + + if($group_value['operator'] == "is_null") { + if($values['condition'] == "AND") { + $this->db->where($group_value['field'].' is ', NULL); + } else { + $this->db->or_where($group_value['field'].' is ', NULL); + } + } + + if($group_value['operator'] == "is_not_null") { + if($values['condition'] == "AND") { + $this->db->where($group_value['field'].' is not ', NULL); + } else { + $this->db->or_where($group_value['field'].' is not ', NULL); + } + } + + + if($group_value['operator'] == "less") { + if($values['condition'] == "AND") { + $this->db->where($group_value['field'].' <', $group_value['value']); + } else { + $this->db->or_where($group_value['field'].' <', $group_value['value']); + } + } + + if($group_value['operator'] == "less_or_equal") { + if($values['condition'] == "AND") { + $this->db->where($group_value['field'].' <=', $group_value['value']); + } else { + $this->db->or_where($group_value['field'].' <=', $group_value['value']); + } + } + + if($group_value['operator'] == "greater") { + if($values['condition'] == "AND") { + $this->db->where($group_value['field'].' >', $group_value['value']); + } else { + $this->db->or_where($group_value['field'].' >', $group_value['value']); + } + } + + if($group_value['operator'] == "greater_or_equal") { + if($values['condition'] == "AND") { + $this->db->where($group_value['field'].' >=', $group_value['value']); + } else { + $this->db->or_where($group_value['field'].' >=', $group_value['value']); + } + } + + } + $this->db->group_end(); + } else { + //print_r($values['field']); + if(isset($values['operator'])) { + + } + if($values['operator'] == "equal") { + if($search_type == "AND") { + $this->db->where($values['field'], $values['value']); + } else { + $this->db->or_where($values['field'], $values['value']); + } + } + + if($values['operator'] == "not_equal") { + if($search_type == "AND") { + $this->db->where($values['field'].' !=', $values['value']); + } else { + $this->db->or_where($values['field'].' !=', $values['value']); + } + } + + if($values['operator'] == "begins_with") { + if($search_type == "AND") { + $this->db->where($values['field'].' like ', $values['value']."%"); + } else { + $this->db->or_where($values['field'].' like ', $values['value']."%"); + } + } + + if($values['operator'] == "contains") { + if($search_type == "AND") { + $this->db->where($values['field'].' like ', "%".$values['value']."%"); + } else { + $this->db->or_where($values['field'].' like ', "%".$values['value']."%"); + } + } + + if($values['operator'] == "ends_with") { + if($search_type == "AND") { + $this->db->where($values['field'].' like ', "%".$values['value']); + } else { + $this->db->or_where($values['field'].' like ', "%".$values['value']); + } + } + + if($values['operator'] == "is_empty") { + if($search_type == "AND") { + $this->db->where($values['field'], ""); + } else { + $this->db->or_where($values['field'], ""); + } + } + + if($values['operator'] == "is_not_empty") { + if($search_type == "AND") { + $this->db->where($values['field'].' !=', ""); + } else { + $this->db->or_where($values['field'].' !=', ""); + } + } + + if($values['operator'] == "is_null") { + if($search_type == "AND") { + $this->db->where($values['field'].' is ', NULL); + } else { + $this->db->or_where($values['field'].' is ', NULL); + } + } + + if($values['operator'] == "is_not_null") { + if($search_type == "AND") { + $this->db->where($values['field'].' is not ', NULL); + } else { + $this->db->or_where($values['field'].' is not ', NULL); + } + } + + if($values['operator'] == "less") { + if($search_type == "AND") { + $this->db->where($values['field'].' <', $values['value']); + } else { + $this->db->or_where($values['field'].' <', $values['value']); + } + } + + if($values['operator'] == "less_or_equal") { + if($search_type == "AND") { + $this->db->where($values['field'].' <=', $values['value']); + } else { + $this->db->or_where($values['field'].' <=', $values['value']); + } + } + + if($values['operator'] == "greater") { + if($search_type == "AND") { + $this->db->where($values['field'].' >', $values['value']); + } else { + $this->db->or_where($values['field'].' >', $values['value']); + } + } + + if($values['operator'] == "greater_or_equal") { + if($search_type == "AND") { + $this->db->where($values['field'].' >=', $values['value']); + } else { + $this->db->or_where($values['field'].' >=', $values['value']); + } + } + } + + } + } + } + $this->db->order_by('COL_TIME_ON', 'DESC'); + $this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id'); + $query = $this->db->get($this->config->item('table_name')); + return $query; + } } diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index 07e6fb53..431c3dea 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -85,6 +85,41 @@ $(".search-results-box").hide(); ] }); + +$("#btn-export").on("click", function(){ + + var result = $('#builder').queryBuilder('getRules'); + if (!$.isEmptyObject(result)) { + // Data to post + data = { + search: JSON.stringify(result, null, 2), temp: "testvar" + }; + + xhttp = new XMLHttpRequest(); + xhttp.onreadystatechange = function() { + var a; + if (xhttp.readyState === 4 && xhttp.status === 200) { + // Trick for making downloadable link + a = document.createElement('a'); + a.href = window.URL.createObjectURL(xhttp.response); + // Give filename you wish to download + a.download = "advanced_search_export.adi"; + a.style.display = 'none'; + document.body.appendChild(a); + a.click(); + } + }; + // Post data to URL which handles post request + xhttp.open("POST", "", true); + xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + // You should set responseType as blob for binary responses + xhttp.responseType = 'blob'; + xhttp.send("search=" + JSON.stringify(result, null, 2)); + } + + +}); + $('#btn-get').on('click', function() { var result = $('#builder').queryBuilder('getRules'); if (!$.isEmptyObject(result)) { diff --git a/application/views/search/filter.php b/application/views/search/filter.php index 13ec4388..7601414d 100644 --- a/application/views/search/filter.php +++ b/application/views/search/filter.php @@ -27,11 +27,13 @@
- +

+ +

Info You can find out how to use the search filter functions in the wiki.