From 223ba0ca218f9d587b13a2cc0f41ce4546205f09 Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Sat, 25 Sep 2021 17:40:15 +0200 Subject: [PATCH 1/8] [Advanced search] You can now save a query for re-use. --- application/controllers/Search.php | 81 ++++- application/models/Search_filter.php | 11 +- application/views/interface_assets/footer.php | 211 ++++++++++--- application/views/search/filter.php | 51 ++-- .../views/search/search_result_ajax.php | 282 ++++++++++++++++++ application/views/search/stored_queries.php | 27 ++ 6 files changed, 598 insertions(+), 65 deletions(-) create mode 100644 application/views/search/search_result_ajax.php create mode 100644 application/views/search/stored_queries.php diff --git a/application/controllers/Search.php b/application/controllers/Search.php index 2a0fc3cc..2bf9946b 100644 --- a/application/controllers/Search.php +++ b/application/controllers/Search.php @@ -32,6 +32,7 @@ class Search extends CI_Controller { $this->load->model('Search_filter'); $data['get_table_names'] = $this->Search_filter->get_table_columns(); + $data['stored_queries'] = $this->Search_filter->get_stored_queries(); //print_r($this->Search_filter->get_table_columns()); @@ -51,16 +52,31 @@ class Search extends CI_Controller { function json_result() { if(isset($_POST['search'])) { - $result = $this->fetchQueryResult($_POST['search']); + $result = $this->fetchQueryResult($_POST['search'], false); echo json_encode($result->result_array()); } else { echo "Noooooooob"; } } + function get_stored_queries() { + $this->load->model('Search_filter'); + $data['result'] = $this->Search_filter->get_stored_queries(); + $this->load->view('search/stored_queries', $data); + } + + function search_result() { + if(isset($_POST['search'])) { + $data['results'] = $this->fetchQueryResult($_POST['search'], false); + $this->load->view('search/search_result_ajax', $data); + } else { + echo "Noooooooob"; + } + } + function export_to_adif() { if(isset($_POST['search'])) { - $data['qsos'] = $this->fetchQueryResult($_POST['search']); + $data['qsos'] = $this->fetchQueryResult($_POST['search'], false); $this->load->view('adif/data/exportall', $data); } else { @@ -68,7 +84,58 @@ class Search extends CI_Controller { } } - function fetchQueryResult($json) { + function export_stored_query_to_adif() { + $this->db->where('id', xss_clean($this->input->post('id'))); + $sql = $this->db->get('queries')->result(); + + $data['qsos'] = $this->db->query($sql[0]->query); + $this->load->view('adif/data/exportall', $data); + } + + function run_query() { + $this->db->where('id', xss_clean($this->input->post('id'))); + $sql = $this->db->get('queries')->result(); + + $data['results'] = $this->db->query($sql[0]->query); + + $this->load->view('search/search_result_ajax', $data); + } + + function save_query() { + if(isset($_POST['search'])) { + $query = $this->fetchQueryResult($_POST['search'], true); + + $data = array( + 'userid' => xss_clean($this->session->userdata('user_id')), + 'query' => $query, + 'description' => xss_clean($_POST['description']) + ); + + $this->db->insert('queries', $data); + + } else { + echo "Noooooooob"; + } + } + + function delete_query() { + $id = xss_clean($this->input->post('id')); + $this->load->model('search_filter'); + $this->search_filter->delete_query($id); + } + + function edit_query() { + $data = array( + 'cat' => xss_clean($this->input->post('category')), + 'title' => xss_clean($this->input->post('title')), + 'note' => xss_clean($this->input->post('content')) + ); + + $this->db->where('id', xss_clean($this->input->post('id'))); + $this->db->update('notes', $data); + } + + function fetchQueryResult($json, $returnquery) { $search_items = json_decode($json, true); @@ -316,9 +383,15 @@ class Search extends CI_Controller { } } } + $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')); + + if ($returnquery) { + $query = $this->db->get_compiled_select($this->config->item('table_name')); + } else { + $query = $this->db->get($this->config->item('table_name')); + } return $query; } } diff --git a/application/models/Search_filter.php b/application/models/Search_filter.php index c215c780..d6d4c835 100644 --- a/application/models/Search_filter.php +++ b/application/models/Search_filter.php @@ -13,6 +13,15 @@ class Search_filter extends CI_Model { return $query; } + function get_stored_queries() { + $this->db->where('userid', $this->session->userdata('user_id')); + return $this->db->get('queries')->result(); + } + + function delete_query($id) { + $this->db->delete('queries', array('id' => xss_clean($id), 'userid' =>$this->session->userdata('user_id'))); + } + } -?> \ No newline at end of file +?> diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index 431c3dea..da1924e3 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -86,15 +86,9 @@ $(".search-results-box").hide(); }); -$("#btn-export").on("click", function(){ - +function export_search_result(){ 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; @@ -116,45 +110,186 @@ $("#btn-export").on("click", function(){ xhttp.responseType = 'blob'; xhttp.send("search=" + JSON.stringify(result, null, 2)); } +} +function export_stored_query(id){ + 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("id=" + id); +} +$('#btn-save').on('click', function() { + var resultquery = $('#builder').queryBuilder('getRules'); + if (!$.isEmptyObject(resultquery)) { + let message = 'Description: ' + + BootstrapDialog.confirm({ + title: 'Query description', + size: BootstrapDialog.SIZE_NORMAL, + cssClass: 'description-dialog', + closable: true, + nl2br: false, + message: message, + btnCancelLabel: 'Cancel', + btnOKLabel: 'Save', + callback: function(result) { + if(result) { + $.post( "", { search: JSON.stringify(resultquery, null, 2), description: $(".getqueryname").val() }) + .done(function( data ) { + alert('Query saved!'); + }); + } + }, + }); + + } + else{ + alert('Make a query first'); + } }); - $('#btn-get').on('click', function() { - var result = $('#builder').queryBuilder('getRules'); - if (!$.isEmptyObject(result)) { - //alert(JSON.stringify(result, null, 2)); +function run_query() { + $(".runbutton").addClass('running'); + $(".runbutton").prop('disabled', true); + let id = $('#querydropdown').val(); + $.post( "", { id: id}) + .done(function( data ) { - $.post( "", { search: JSON.stringify(result, null, 2), temp: "testvar" }) - .done(function( data ) { - //console.log(data) - //alert( "Data Loaded: " + data ); - $('.qso').remove(); - $(".search-results-box").show(); + $('.exportbutton').html(''); + $('.card-body.result').empty(); + $(".search-results-box").show(); - $.each(JSON.parse(data), function(i, item) { + $('.card-body.result').append(data); + $('.table').DataTable({ + "pageLength": 25, + responsive: false, + ordering: false, + "scrollY": "400px", + "scrollCollapse": true, + "paging": false, + "scrollX": true, + dom: 'Bfrtip', + buttons: [ + 'csv' + ] + }); + // change color of csv-button if dark mode is chosen + if (isDarkModeTheme()) { + $(".buttons-csv").css("color", "white"); + } + $(".runbutton").removeClass('running'); + $(".runbutton").prop('disabled', false); + }); +} - var band = ""; - if(item.COL_SAT_NAME != "") { - band = item.COL_SAT_NAME; - } else { - band = item.COL_BAND; - } - var callsign = '' + item.COL_CALL + ''; - if (item.COL_SUBMODE == '' || item.COL_SUBMODE == null) { - $('#results').append('' + item.COL_TIME_ON + '' + callsign + '' + item.COL_MODE + '' + item.COL_RST_SENT + '' + item.COL_RST_RCVD + '' + band + '' + item.COL_COUNTRY + ''); - } - else { - $('#results').append('' + item.COL_TIME_ON + '' + callsign + '' + item.COL_SUBMODE + '' + item.COL_RST_SENT + '' + item.COL_RST_RCVD + '' + band + '' + item.COL_COUNTRY + ''); - } - }); +function delete_stored_query(id) { + BootstrapDialog.confirm({ + title: 'DANGER', + message: 'Warning! Are you sure you want delete this stored query?' , + type: BootstrapDialog.TYPE_DANGER, + closable: true, + draggable: true, + btnOKClass: 'btn-danger', + callback: function(result) { + if(result) { + $.ajax({ + url: base_url + 'index.php/search/delete_query', + type: 'post', + data: {'id': id + }, + success: function(data) { + $(".bootstrap-dialog-message").prepend('
×The stored query has been deleted!
'); + $("#query_" + id).remove(); // removes qso from table in dialog + } + }); + } + } + }); +} - }); - } - else{ - //console.log("invalid object :"); - } - }); +function edit_stored_query(id) { + +} + +$('#btn-edit').on('click', function() { + $.ajax({ + url: base_url + 'index.php/search/get_stored_queries', + type: 'post', + success: function (html) { + BootstrapDialog.show({ + title: 'Stored Queries', + size: BootstrapDialog.SIZE_WIDE, + cssClass: 'queries-dialog', + nl2br: false, + message: html, + buttons: [{ + label: 'Close', + action: function (dialogItself) { + dialogItself.close(); + } + }] + }); + } + }); +}); + +$('#btn-get').on('click', function() { + var result = $('#builder').queryBuilder('getRules'); + if (!$.isEmptyObject(result)) { + $(".searchbutton").addClass('running'); + $(".searchbutton").prop('disabled', true); + + $.post( "", { search: JSON.stringify(result, null, 2), temp: "testvar" }) + .done(function( data ) { + $('.exportbutton').html(''); + + $('.card-body.result').empty(); + $(".search-results-box").show(); + + $('.card-body.result').append(data); + $('.table').DataTable({ + "pageLength": 25, + responsive: false, + ordering: false, + "scrollY": "400px", + "scrollCollapse": true, + "paging": false, + "scrollX": true, + dom: 'Bfrtip', + buttons: [ + 'csv' + ] + }); + // change color of csv-button if dark mode is chosen + if (isDarkModeTheme()) { + $(".buttons-csv").css("color", "white"); + } + $(".searchbutton").removeClass('running'); + $(".searchbutton").prop('disabled', false); + $("#btn-save").show(); + }); + } + else{ + alert('Make a query first'); + } +}); $('#btn-set').on('click', function() { //$('#builder').queryBuilder('setRules', rules_basic); diff --git a/application/views/search/filter.php b/application/views/search/filter.php index 7601414d..46aae717 100644 --- a/application/views/search/filter.php +++ b/application/views/search/filter.php @@ -29,14 +29,36 @@

- + - - - +

+

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

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

@@ -47,24 +69,9 @@
- Search Results + Search Results:
-
- -
- - - - - - - - - - - -
Date/TimeCallModeSentRecv'dBandCountry
-
+
diff --git a/application/views/search/search_result_ajax.php b/application/views/search/search_result_ajax.php new file mode 100644 index 00000000..1d20cc77 --- /dev/null +++ b/application/views/search/search_result_ajax.php @@ -0,0 +1,282 @@ +
+ + + + + config->item('use_auth') && ($this->session->userdata('user_type') >= 2)) || $this->config->item('use_auth') === FALSE || ($this->config->item('show_time'))) { ?> + + + +'; + switch($this->session->userdata('user_column1')==""?'Mode':$this->session->userdata('user_column1')) { + case 'Mode': echo $this->lang->line('gen_hamradio_mode'); break; + case 'RSTS': echo $this->lang->line('gen_hamradio_rsts'); break; + case 'RSTR': echo $this->lang->line('gen_hamradio_rstr'); break; + case 'Country': echo $this->lang->line('general_word_country'); break; + case 'IOTA': echo $this->lang->line('gen_hamradio_iota'); break; + case 'SOTA': echo $this->lang->line('gen_hamradio_sota'); break; + case 'State': echo $this->lang->line('gen_hamradio_state'); break; + case 'Grid': echo $this->lang->line('gen_hamradio_gridsquare'); break; + case 'Band': echo $this->lang->line('gen_hamradio_band'); break; + } + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + + if(($this->config->item('use_auth')) && ($this->session->userdata('user_type') >= 2)) { ?> + + session->userdata('user_eqsl_name') != "") { ?> + + + session->userdata('user_lotw_name') != "") { ?> + + + + + config->item('use_auth')) && ($this->session->userdata('user_type') >= 2)) { ?> + + + + + + result() as $row) { ?> + + session->userdata('user_date_format')) { + // If Logged in and session exists + $custom_date_format = $this->session->userdata('user_date_format'); + } else { + // Get Default date format from /config/cloudlog.php + $custom_date_format = $this->config->item('qso_date_format'); + } + ?> + COL_PRIMARY_KEY .'">'; ?> + + config->item('use_auth') && ($this->session->userdata('user_type') >= 2)) || $this->config->item('use_auth') === FALSE || ($this->config->item('show_time'))) { ?> + + + + session->userdata('user_column1')==""?'Mode':$this->session->userdata('user_column1')) { + case 'Mode': echo ''; + switch($this->session->userdata('user_column2')==""?'RSTS':$this->session->userdata('user_column2')) { + case 'Mode': echo ''; + + switch($this->session->userdata('user_column3')==""?'RSTR':$this->session->userdata('user_column3')) { + case 'Mode': echo ''; + switch($this->session->userdata('user_column4')==""?'Band':$this->session->userdata('user_column4')) { + case 'Mode': echo ''; + switch($this->session->userdata('user_column5')==""?'Country':$this->session->userdata('user_column5')) { + case 'Mode': echo ''; + if(($this->config->item('use_auth')) && ($this->session->userdata('user_type') >= 2)) { ?> + + + session->userdata('user_eqsl_name') != ""){ ?> + + + + session->userdata('user_lotw_name') != "") { ?> + + + + + + station_callsign)) { ?> + + + + config->item('use_auth')) && ($this->session->userdata('user_type') >= 2)) { ?> + + + + + +
lang->line('general_word_date'); ?>lang->line('general_word_time'); ?>lang->line('gen_hamradio_call'); ?>'; + switch($this->session->userdata('user_column2')==""?'RSTS':$this->session->userdata('user_column2')) { + case 'Mode': echo $this->lang->line('gen_hamradio_mode'); break; + case 'RSTS': echo $this->lang->line('gen_hamradio_rsts'); break; + case 'RSTR': echo $this->lang->line('gen_hamradio_rstr'); break; + case 'Country': echo $this->lang->line('general_word_country'); break; + case 'IOTA': echo $this->lang->line('gen_hamradio_iota'); break; + case 'State': echo $this->lang->line('gen_hamradio_state'); break; + case 'SOTA': echo $this->lang->line('gen_hamradio_sota'); break; + case 'Grid': echo $this->lang->line('gen_hamradio_gridsquare'); break; + case 'Band': echo $this->lang->line('gen_hamradio_band'); break; + } + echo ''; + switch($this->session->userdata('user_column3')==""?'RSTR':$this->session->userdata('user_column3')) { + case 'Mode': echo $this->lang->line('gen_hamradio_mode'); break; + case 'RSTS': echo $this->lang->line('gen_hamradio_rsts'); break; + case 'RSTR': echo $this->lang->line('gen_hamradio_rstr'); break; + case 'Country': echo $this->lang->line('general_word_country'); break; + case 'IOTA': echo $this->lang->line('gen_hamradio_iota'); break; + case 'SOTA': echo $this->lang->line('gen_hamradio_sota'); break; + case 'State': echo $this->lang->line('gen_hamradio_state'); break; + case 'Grid': echo $this->lang->line('gen_hamradio_gridsquare'); break; + case 'Band': echo $this->lang->line('gen_hamradio_band'); break; + } + echo ''; + switch($this->session->userdata('user_column4')==""?'Band':$this->session->userdata('user_column4')) { + case 'Mode': echo $this->lang->line('gen_hamradio_mode'); break; + case 'RSTS': echo $this->lang->line('gen_hamradio_rsts'); break; + case 'RSTR': echo $this->lang->line('gen_hamradio_rstr'); break; + case 'Country': echo $this->lang->line('general_word_country'); break; + case 'IOTA': echo $this->lang->line('gen_hamradio_iota'); break; + case 'SOTA': echo $this->lang->line('gen_hamradio_sota'); break; + case 'State': echo $this->lang->line('gen_hamradio_state'); break; + case 'Grid': echo $this->lang->line('gen_hamradio_gridsquare'); break; + case 'Band': echo $this->lang->line('gen_hamradio_band'); break; + } + echo ''; + switch($this->session->userdata('user_column5')==""?'Country':$this->session->userdata('user_column5')) { + case 'Mode': echo $this->lang->line('gen_hamradio_mode'); break; + case 'RSTS': echo $this->lang->line('gen_hamradio_rsts'); break; + case 'RSTR': echo $this->lang->line('gen_hamradio_rstr'); break; + case 'Country': echo $this->lang->line('general_word_country'); break; + case 'IOTA': echo $this->lang->line('gen_hamradio_iota'); break; + case 'SOTA': echo $this->lang->line('gen_hamradio_sota'); break; + case 'State': echo $this->lang->line('gen_hamradio_state'); break; + case 'Grid': echo $this->lang->line('gen_hamradio_gridsquare'); break; + case 'Band': echo $this->lang->line('gen_hamradio_band'); break; + } + echo 'QSLeQSLLoTWlang->line('gen_hamradio_station'); ?>
COL_TIME_ON); echo date($custom_date_format, $timestamp); ?>COL_TIME_ON); echo date('H:i', $timestamp); ?> + COL_CALL)); ?> + '; echo $row->COL_SUBMODE==null?$row->COL_MODE:$row->COL_SUBMODE; break; + case 'RSTS': echo '' . $row->COL_RST_SENT; if ($row->COL_STX) { echo '' . $row->COL_STX . '';}if ($row->COL_STX_STRING) { echo '' . $row->COL_STX_STRING . '';}; break; + case 'RSTR': echo '' . $row->COL_RST_RCVD; if ($row->COL_SRX) { echo '' . $row->COL_SRX . '';}if ($row->COL_SRX_STRING) { echo '' . $row->COL_SRX_STRING . '';}; break; + case 'Country': echo '' . ucwords(strtolower(($row->COL_COUNTRY)));; break; + case 'IOTA': echo '' . ($row->COL_IOTA); break; + case 'SOTA': echo '' . ($row->COL_SOTA_REF); break; + case 'Grid': echo ''; echo strlen($row->COL_GRIDSQUARE)==0?$row->COL_VUCC_GRIDS:$row->COL_GRIDSQUARE; break; + case 'Band': echo ''; if($row->COL_SAT_NAME != null) { echo $row->COL_SAT_NAME; } else { echo strtolower($row->COL_BAND); }; break; + case 'State': echo '' . ($row->COL_STATE); break; + } + echo ''; echo $row->COL_SUBMODE==null?$row->COL_MODE:$row->COL_SUBMODE; break; + case 'RSTS': echo '' . $row->COL_RST_SENT; if ($row->COL_STX) { echo '' . $row->COL_STX . '';}if ($row->COL_STX_STRING) { echo '' . $row->COL_STX_STRING . '';}; break; + case 'RSTR': echo '' . $row->COL_RST_RCVD; if ($row->COL_SRX) { echo '' . $row->COL_SRX . '';}if ($row->COL_SRX_STRING) { echo '' . $row->COL_SRX_STRING . '';}; break; + case 'Country': echo '' . ucwords(strtolower(($row->COL_COUNTRY)));; break; + case 'IOTA': echo '' . ($row->COL_IOTA); break; + case 'SOTA': echo '' . ($row->COL_SOTA_REF); break; + case 'Grid': echo ''; echo strlen($row->COL_GRIDSQUARE)==0?$row->COL_VUCC_GRIDS:$row->COL_GRIDSQUARE; break; + case 'Band': echo ''; if($row->COL_SAT_NAME != null) { echo $row->COL_SAT_NAME; } else { echo strtolower($row->COL_BAND); }; break; + case 'State': echo '' . ($row->COL_STATE); break; + } + echo ''; echo $row->COL_SUBMODE==null?$row->COL_MODE:$row->COL_SUBMODE; break; + case 'RSTS': echo '' . $row->COL_RST_SENT; if ($row->COL_STX) { echo '' . $row->COL_STX . '';}if ($row->COL_STX_STRING) { echo '' . $row->COL_STX_STRING . '';}; break; + case 'RSTR': echo '' . $row->COL_RST_RCVD; if ($row->COL_SRX) { echo '' . $row->COL_SRX . '';}if ($row->COL_SRX_STRING) { echo '' . $row->COL_SRX_STRING . '';}; break; + case 'Country': echo '' . ucwords(strtolower(($row->COL_COUNTRY)));; break; + case 'IOTA': echo '' . ($row->COL_IOTA); break; + case 'SOTA': echo '' . ($row->COL_SOTA_REF); break; + case 'Grid': echo ''; echo strlen($row->COL_GRIDSQUARE)==0?$row->COL_VUCC_GRIDS:$row->COL_GRIDSQUARE; break; + case 'Band': echo ''; if($row->COL_SAT_NAME != null) { echo $row->COL_SAT_NAME; } else { echo strtolower($row->COL_BAND); }; break; + case 'State': echo '' . ($row->COL_STATE); break; + } + echo ''; echo $row->COL_SUBMODE==null?$row->COL_MODE:$row->COL_SUBMODE; break; + case 'RSTS': echo '' . $row->COL_RST_SENT; if ($row->COL_STX) { echo '' . $row->COL_STX . '';}if ($row->COL_STX_STRING) { echo '' . $row->COL_STX_STRING . '';}; break; + case 'RSTR': echo '' . $row->COL_RST_RCVD; if ($row->COL_SRX) { echo '' . $row->COL_SRX . '';}if ($row->COL_SRX_STRING) { echo '' . $row->COL_SRX_STRING . '';}; break; + case 'Country': echo '' . ucwords(strtolower(($row->COL_COUNTRY)));; break; + case 'IOTA': echo '' . ($row->COL_IOTA); break; + case 'SOTA': echo '' . ($row->COL_SOTA_REF); break; + case 'Grid': echo ''; echo strlen($row->COL_GRIDSQUARE)==0?$row->COL_VUCC_GRIDS:$row->COL_GRIDSQUARE; break; + case 'Band': echo ''; if($row->COL_SAT_NAME != null) { echo $row->COL_SAT_NAME; } else { echo strtolower($row->COL_BAND); }; break; + case 'State': echo '' . ($row->COL_STATE); break; + } + echo ''; echo $row->COL_SUBMODE==null?$row->COL_MODE:$row->COL_SUBMODE; break; + case 'RSTS': echo '' . $row->COL_RST_SENT; if ($row->COL_STX) { echo '' . $row->COL_STX . '';}if ($row->COL_STX_STRING) { echo '' . $row->COL_STX_STRING . '';}; break; + case 'RSTR': echo '' . $row->COL_RST_RCVD; if ($row->COL_SRX) { echo '' . $row->COL_SRX . '';}if ($row->COL_SRX_STRING) { echo '' . $row->COL_SRX_STRING . '';}; break; + case 'Country': echo '' . ucwords(strtolower(($row->COL_COUNTRY)));; break; + case 'IOTA': echo '' . ($row->COL_IOTA); break; + case 'SOTA': echo '' . ($row->COL_SOTA_REF); break; + case 'Grid': echo ''; echo strlen($row->COL_GRIDSQUARE)==0?$row->COL_VUCC_GRIDS:$row->COL_GRIDSQUARE; break; + case 'Band': echo ''; if($row->COL_SAT_NAME != null) { echo $row->COL_SAT_NAME; } else { echo strtolower($row->COL_BAND); }; break; + case 'State': echo '' . ($row->COL_STATE); break; + } + echo ' + ">▲ + ">▼ + + + + COL_EQSL_QSL_RCVD =='Y') { ?> + COL_PRIMARY_KEY); ?>" data-fancybox="images" data-width="528" data-height="336">▼ + + ▼ + + + + COL_LOTW_QSL_SENT != ''){ ?> + + + + + station_callsign; ?> + +
+ +
diff --git a/application/views/search/stored_queries.php b/application/views/search/stored_queries.php new file mode 100644 index 00000000..a0de4018 --- /dev/null +++ b/application/views/search/stored_queries.php @@ -0,0 +1,27 @@ + + + + + + + + + + + + + id . '">'; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + ?> + +
#DescriptionQuery
' . $i++ . '' . $q->description . '' . $q->query . 'Edit'; + echo 'Delete
From d71ba5a0c68864fc4c857e61eb60a23770f69725 Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Sat, 25 Sep 2021 17:46:08 +0200 Subject: [PATCH 2/8] [Advanced search] When deleting a query, it will be removed from the dropdown. --- application/views/interface_assets/footer.php | 3 ++- application/views/search/filter.php | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index da1924e3..ee5a1e68 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -216,7 +216,8 @@ function delete_stored_query(id) { }, success: function(data) { $(".bootstrap-dialog-message").prepend('
×The stored query has been deleted!
'); - $("#query_" + id).remove(); // removes qso from table in dialog + $("#query_" + id).remove(); // removes query from table in dialog + $("#querydropdown option[value='"+id+"']").remove(); // removes query from dropdown } }); } diff --git a/application/views/search/filter.php b/application/views/search/filter.php index 46aae717..7b3446a8 100644 --- a/application/views/search/filter.php +++ b/application/views/search/filter.php @@ -41,9 +41,9 @@
- +
- id . '">'. $q->description . ''."\n"; From 0717fa74ff990bac4de84840eb572612c1758e1e Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Sat, 25 Sep 2021 18:08:31 +0200 Subject: [PATCH 3/8] [Advanced search] When saving a query, we add this to the dropdown. --- application/controllers/Search.php | 15 ++++----------- application/views/interface_assets/footer.php | 1 + 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/application/controllers/Search.php b/application/controllers/Search.php index 2bf9946b..7aa2ef79 100644 --- a/application/controllers/Search.php +++ b/application/controllers/Search.php @@ -54,9 +54,7 @@ class Search extends CI_Controller { if(isset($_POST['search'])) { $result = $this->fetchQueryResult($_POST['search'], false); echo json_encode($result->result_array()); - } else { - echo "Noooooooob"; - } + } } function get_stored_queries() { @@ -69,18 +67,13 @@ class Search extends CI_Controller { if(isset($_POST['search'])) { $data['results'] = $this->fetchQueryResult($_POST['search'], false); $this->load->view('search/search_result_ajax', $data); - } else { - echo "Noooooooob"; } } function export_to_adif() { if(isset($_POST['search'])) { $data['qsos'] = $this->fetchQueryResult($_POST['search'], false); - $this->load->view('adif/data/exportall', $data); - } else { - echo "Noooooooob"; } } @@ -112,9 +105,9 @@ class Search extends CI_Controller { ); $this->db->insert('queries', $data); - - } else { - echo "Noooooooob"; + $last_id = $this->db->insert_id(); + header('Content-Type: application/json'); + echo json_encode(array('id' => $last_id, 'description' => xss_clean($_POST['description']))); } } diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index ee5a1e68..c7ca1b12 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -154,6 +154,7 @@ $('#btn-save').on('click', function() { $.post( "", { search: JSON.stringify(resultquery, null, 2), description: $(".getqueryname").val() }) .done(function( data ) { alert('Query saved!'); + $('#querydropdown').append( new Option(data.description, data.id) ); // We add the saved query to the dropdown }); } }, From 17170433e098683ac7df7c8bcc4ed6969b17ff8b Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Sat, 25 Sep 2021 19:49:28 +0200 Subject: [PATCH 4/8] [Advanced search] Only run a query which contains select, but not delete or update. Done for safety precautions. --- application/controllers/Search.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/application/controllers/Search.php b/application/controllers/Search.php index 7aa2ef79..b7d1b0d3 100644 --- a/application/controllers/Search.php +++ b/application/controllers/Search.php @@ -88,10 +88,13 @@ class Search extends CI_Controller { function run_query() { $this->db->where('id', xss_clean($this->input->post('id'))); $sql = $this->db->get('queries')->result(); + $sql = $sql[0]->query; - $data['results'] = $this->db->query($sql[0]->query); + if (stristr($sql, 'select', ) && !stristr($sql, 'delete') && !stristr($sql, 'update')) { + $data['results'] = $this->db->query($sql); - $this->load->view('search/search_result_ajax', $data); + $this->load->view('search/search_result_ajax', $data); + } } function save_query() { From 97b5b1b2c81a2ad568159308f06ac4b87775846b Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Sat, 25 Sep 2021 20:06:14 +0200 Subject: [PATCH 5/8] [Advanced search] Polished things up a bit by using alert and dialog to convey messages. --- application/views/interface_assets/footer.php | 76 +++++++++++++------ application/views/search/filter.php | 6 +- 2 files changed, 56 insertions(+), 26 deletions(-) diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index c7ca1b12..476fab7e 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -113,26 +113,26 @@ function export_search_result(){ } function export_stored_query(id){ - 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("id=" + id); + 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("id=" + id); } $('#btn-save').on('click', function() { @@ -153,7 +153,8 @@ $('#btn-save').on('click', function() { if(result) { $.post( "", { search: JSON.stringify(resultquery, null, 2), description: $(".getqueryname").val() }) .done(function( data ) { - alert('Query saved!'); + $(".alert").remove(); + $(".card-body.main").append('
×Your query has been saved!
'); $('#querydropdown').append( new Option(data.description, data.id) ); // We add the saved query to the dropdown }); } @@ -162,11 +163,25 @@ $('#btn-save').on('click', function() { } else{ - alert('Make a query first'); + BootstrapDialog.show({ + title: 'Stored Queries', + type: BootstrapDialog.TYPE_WARNING, + size: BootstrapDialog.SIZE_NORMAL, + cssClass: 'queries-dialog', + nl2br: false, + message: 'You need to make a query before you search!', + buttons: [{ + label: 'Close', + action: function (dialogItself) { + dialogItself.close(); + } + }] + }); } }); function run_query() { + $(".alert").remove(); $(".runbutton").addClass('running'); $(".runbutton").prop('disabled', true); let id = $('#querydropdown').val(); @@ -231,6 +246,7 @@ function edit_stored_query(id) { } $('#btn-edit').on('click', function() { + $(".alert").remove(); $.ajax({ url: base_url + 'index.php/search/get_stored_queries', type: 'post', @@ -253,6 +269,7 @@ $('#btn-edit').on('click', function() { }); $('#btn-get').on('click', function() { + $(".alert").remove(); var result = $('#builder').queryBuilder('getRules'); if (!$.isEmptyObject(result)) { $(".searchbutton").addClass('running'); @@ -289,7 +306,20 @@ $('#btn-get').on('click', function() { }); } else{ - alert('Make a query first'); + BootstrapDialog.show({ + title: 'Stored Queries', + type: BootstrapDialog.TYPE_WARNING, + size: BootstrapDialog.SIZE_NORMAL, + cssClass: 'queries-dialog', + nl2br: false, + message: 'You need to make a query before you search!', + buttons: [{ + label: 'Close', + action: function (dialogItself) { + dialogItself.close(); + } + }] + }); } }); diff --git a/application/views/search/filter.php b/application/views/search/filter.php index 7b3446a8..9b654175 100644 --- a/application/views/search/filter.php +++ b/application/views/search/filter.php @@ -24,7 +24,7 @@
-
+
@@ -41,8 +41,8 @@
- -
+ +