diff --git a/application/controllers/Oqrs.php b/application/controllers/Oqrs.php index 46fde176..3500ad1d 100644 --- a/application/controllers/Oqrs.php +++ b/application/controllers/Oqrs.php @@ -91,6 +91,7 @@ class Oqrs extends CI_Controller { $this->load->model('oqrs_model'); $data['result'] = $this->oqrs_model->getOqrsRequests($location_list); + $data['stations'] = $this->oqrs_model->get_oqrs_stations(); $this->load->view('interface_assets/header', $data); $this->load->view('oqrs/showrequests'); @@ -182,4 +183,21 @@ class Oqrs extends CI_Controller { $this->oqrs_model->mark_oqrs_line_as_done($id); } + + public function search() { + $this->load->model('oqrs_model'); + + $searchCriteria = array( + 'user_id' => (int)$this->session->userdata('user_id'), + 'de' => xss_clean($this->input->post('de')), + 'dx' => xss_clean($this->input->post('dx')), + 'status' => xss_clean($this->input->post('status')), + 'oqrsResults' => xss_clean($this->input->post('oqrsResults')), + ); + + $qsos = $this->oqrs_model->searchOqrs($searchCriteria); + + header("Content-Type: application/json"); + print json_encode($qsos); + } } diff --git a/application/models/Oqrs_model.php b/application/models/Oqrs_model.php index 7736b1e5..553f026d 100644 --- a/application/models/Oqrs_model.php +++ b/application/models/Oqrs_model.php @@ -84,7 +84,7 @@ class Oqrs_model extends CI_Model { } function getOqrsRequests($location_list) { - $sql = 'select * from oqrs join station_profile on oqrs.station_id = station_profile.station_id where oqrs.station_id in (' . $location_list . ') and oqrs.status < 2'; + $sql = 'select * from oqrs join station_profile on oqrs.station_id = station_profile.station_id where oqrs.station_id in (' . $location_list . ')'; $query = $this->db->query($sql); @@ -251,15 +251,46 @@ class Oqrs_model extends CI_Model { return ''; } - function getOqrsStationsFromSlug($logbook_id) { - $sql = 'SELECT station_callsign FROM `station_logbooks_relationship` JOIN `station_profile` ON station_logbooks_relationship.station_location_id = station_profile.station_id WHERE station_profile.oqrs = 1 AND station_logbook_id = '.$logbook_id.';'; + /* + * @param array $searchCriteria + * @return array + */ + public function searchOqrs($searchCriteria) : array { + $conditions = []; + $binding = [$searchCriteria['user_id']]; - $query = $this->db->query($sql); - - if ($query->num_rows() > 0) { - return true; - } else { - return false; + if ($searchCriteria['de'] !== '') { + $conditions[] = "station_profile.STATION_CALLSIGN = ?"; + $binding[] = trim($searchCriteria['de']); } + if ($searchCriteria['dx'] !== '') { + $conditions[] = "oqrs.requestcallsign LIKE ?"; + $binding[] = '%' . trim($searchCriteria['dx']) . '%'; + } + if ($searchCriteria['status'] !== '') { + $conditions[] = "oqrs.status = ?"; + $binding[] = $searchCriteria['status']; + } + + $where = trim(implode(" AND ", $conditions)); + if ($where != "") { + $where = "AND $where"; + } + + $limit = $searchCriteria['oqrsResults']; + + $sql = " + SELECT * + FROM oqrs + INNER JOIN station_profile ON oqrs.station_id=station_profile.station_id + WHERE station_profile.user_id = ? + $where + ORDER BY oqrs.id + LIMIT $limit + "; + + $data = $this->db->query($sql, $binding); + + return $data->result('array'); } -} +} \ No newline at end of file diff --git a/application/views/oqrs/showrequests.php b/application/views/oqrs/showrequests.php index cdd18674..583ae530 100644 --- a/application/views/oqrs/showrequests.php +++ b/application/views/oqrs/showrequests.php @@ -1,126 +1,123 @@ -
-
-

- 0) { - $station_id = ''; - $tablebody = ''; - $requester = ''; - $first = true; - $second = true; - foreach ($result as $qso) { - if ($station_id != $qso->station_id) { - if (!$first) { - write_table($tablebody); - $tablebody = ''; - echo '

'; - } - insert_station_data($qso); - $first = false; - } - if ($requester != $qso->requestcallsign) { - if (!$second) { - write_table($tablebody); - } - $second = false; - insert_requester($qso); - write_table_header(); - $tablebody = ''; - } - $tablebody .= insert_qso_data($qso); - - $requester = $qso->requestcallsign; - $station_id = $qso->station_id; - } - write_table($tablebody); - echo '
'; - } else { - echo 'No OQRS requests were found at this time.'; - } - ?> - - - - -
-
- Station id: station_id; ?> - Station callsign: station_callsign; ?> - Profile Name: station_profile_name; ?> - Country: station_country; ?> - Gridsquare: station_gridsquare; ?> -
-
- -OQRS Request: - +
+

+ session->flashdata('message')) { ?> + +
+

session->flashdata('message'); ?>

+
+ +
+
" method="post"> +
+
+ + +
+
+ + +
+ +
+ + +
+
+ + +
+
+
+ + +
+
+ +
+
+
+ With selected : + + + +
+
+
- - - - - - - - - - - - - - + + + + + + + + + + + + + + - -
RequesterTime of requestE-mailNoteQSL route
requestcallsign ?>requesttime ?>email ?>note ?>qslroute; ?>
Time of requestQSO DateQSO TimeBandModeRequest callsignStation callsignE-mailNoteQSL routeCheck logStatus
- id.'"> - ' . $qso->date . ' - ' . $qso->time . ' - ' . $qso->band . ' - ' . $qso->mode . ' - - - - - - '; - return $tablebody; -} - -function write_table_header() { - ?> - - - - - - - - - - - - + id.'" oqrsid="'.$qso->id.'">'; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + }*/ + ?> -
DateTime (UTC)BandModeCheck logMark as doneDelete
'. $qso->requesttime .''. $qso->date .''. $qso->time .''. $qso->band .''. $qso->mode .''. $qso->requestcallsign .''. $qso->station_callsign .''. $qso->email .''. $qso->note .''; echo_qsl_method($qso->qslroute); echo ' + + '; echo_status($qso->status); echo '
- \ No newline at end of file diff --git a/assets/js/sections/oqrs.js b/assets/js/sections/oqrs.js index 42fc1004..cc98e80d 100644 --- a/assets/js/sections/oqrs.js +++ b/assets/js/sections/oqrs.js @@ -228,10 +228,10 @@ function searchLogTimeDate(id) { $.ajax({ url: base_url + 'index.php/oqrs/search_log_time_date', type: 'post', - data: {'time': $('.oqrsid_'+id+ ' td:nth-child(2)').text(), - 'date': $('.oqrsid_'+id+ ' td:nth-child(1)').text(), - 'band': $('.oqrsid_'+id+ ' td:nth-child(3)').text(), - 'mode': $('.oqrsid_'+id+ ' td:nth-child(4)').text() + data: {'time': $('#oqrsID_'+id+ ' td:nth-child(4)').text(), + 'date': $('#oqrsID_'+id+ ' td:nth-child(3)').text(), + 'band': $('#oqrsID_'+id+ ' td:nth-child(5)').text(), + 'mode': $('#oqrsID_'+id+ ' td:nth-child(6)').text() }, success: function(html) { BootstrapDialog.show({ @@ -265,3 +265,230 @@ function markOqrsLineAsDone(id) { } }); } +function loadOqrsTable(rows) { + var uninitialized = $('.oqrstable').filter(function() { + return !$.fn.DataTable.fnIsDataTable(this); + }); + + uninitialized.each(function() { + $(this).DataTable({ + searching: false, + responsive: false, + ordering: true, + "scrollY": window.innerHeight - $('#searchForm').innerHeight() - 250, + "scrollCollapse": true, + "paging": false, + "scrollX": true, + "order": [ 0, 'asc' ], + 'white-space': 'nowrap', + }); + }); + + var table = $('.oqrstable').DataTable(); + + table.clear(); + + for (i = 0; i < rows.length; i++) { + let qso = rows[i]; + + var data = [ + '
', + qso.requesttime, + qso.date, + qso.time, + qso.band, + qso.mode, + qso.requestcallsign, + qso.station_callsign, + qso.email, + qso.note, + echo_qsl_method(qso.qslroute), + echo_searchlog_button(qso.requestcallsign, qso.id), + echo_status(qso.status), + ]; + + let createdRow = table.row.add(data).index(); + table.rows(createdRow).nodes().to$().data('oqrsID', qso.id); + table.row(createdRow).node().id = 'oqrsID_' + qso.id; + } + table.columns.adjust().draw(); +} + +function echo_status(status) { + switch(status.toUpperCase()) { + case '0': return 'Open request'; break; + case '1': return 'Not in log request'; break; + case '2': return 'Request done'; break; + default: return ''; + } +} +function echo_qsl_method(method) { + switch(method.toUpperCase()) { + case 'B': return 'Bureau'; break; + case 'D': return 'Direct'; break; + case 'E': return 'Electronic'; break; + default: return ''; + } +} + +function echo_searchlog_button(callsign, id) { + return ' ' + + ''; +} + +$(document).ready(function () { + + $('#searchForm').submit(function (e) { + $('#searchButton').prop("disabled", true); + + $.ajax({ + url: this.action, + type: 'post', + data: { + de: this.de.value, + dx: this.dx.value, + status: this.status.value, + oqrsResults: this.oqrsResults.value + }, + dataType: 'json', + success: function (data) { + $('#searchButton').prop("disabled", false); + loadOqrsTable(data); + }, + error: function (data) { + $('#searchButton').prop("disabled", false); + BootstrapDialog.alert({ + title: 'ERROR', + message: 'An error ocurred while making the request', + type: BootstrapDialog.TYPE_DANGER, + closable: false, + draggable: false, + callback: function (result) { + } + }); + }, + }); + return false; + }); + + $('.oqrstable').on('click', 'input[type="checkbox"]', function() { + if ($(this).is(":checked")) { + $(this).closest('tr').addClass('alert-success'); + } else { + $(this).closest('tr').removeClass('alert-success'); + } + }); + + $('#deleteOqrs').click(function (event) { + var elements = $('.oqrstable tbody input:checked'); + var nElements = elements.length; + if (nElements == 0) { + return; + } + + $('#deleteOqrs').prop("disabled", true); + + var table = $('.oqrstable').DataTable(); + + BootstrapDialog.confirm({ + title: 'DANGER', + message: 'Warning! Are you sure you want to delete the marked OQRS request(s)?' , + type: BootstrapDialog.TYPE_DANGER, + closable: true, + draggable: true, + btnOKClass: 'btn-danger', + callback: function(result) { + if(result) { + elements.each(function() { + let id = $(this).first().closest('tr').data('qsoID') + $.ajax({ + url: base_url + 'index.php/oqrs/delete_ajax', + type: 'post', + data: {'id': id + }, + success: function(data) { + var row = $("#qsoID_" + id); + table.row(row).remove().draw(false); + } + }); + $('#deleteOqrs').prop("disabled", false); + }) + } + } + }); + }); + + $('#markOqrs').click(function (event) { + var elements = $('.oqrstable tbody input:checked'); + var nElements = elements.length; + if (nElements == 0) { + return; + } + + $('#markOqrs').prop("disabled", true); + + var table = $('.oqrstable').DataTable(); + + BootstrapDialog.confirm({ + title: 'DANGER', + message: 'Warning! Are you sure you want to delete the marked OQRS request(s)?' , + type: BootstrapDialog.TYPE_DANGER, + closable: true, + draggable: true, + btnOKClass: 'btn-danger', + callback: function(result) { + if(result) { + elements.each(function() { + let id = $(this).first().closest('tr').data('qsoID') + $.ajax({ + url: base_url + 'index.php/oqrs/mark_ajax', + type: 'post', + data: {'id': id + }, + success: function(data) { + var row = $("#qsoID_" + id); + table.row(row).remove().draw(false); + } + }); + $('#markOqrs').prop("disabled", false); + }) + } + } + }); + }); + + + $('#checkBoxAll').change(function (event) { + if (this.checked) { + $('.oqrstable tbody tr').each(function (i) { + selectQsoID($(this).data('oqrsID')) + }); + } else { + $('.oqrstable tbody tr').each(function (i) { + unselectQsoID($(this).data('oqrsID')) + }); + } + }); + + $('#searchForm').submit(); + + $('#searchForm').on('reset', function(e) { + setTimeout(function() { + $('#searchForm').submit(); + }); + }); +}); + +function selectQsoID(qsoID) { + var element = $("#oqrsID_" + qsoID); + element.find("input[type=checkbox]").prop("checked", true); + element.addClass('alert-success'); +} + +function unselectQsoID(qsoID) { + var element = $("#oqrsID_" + qsoID); + element.find("input[type=checkbox]").prop("checked", false); + element.removeClass('alert-success'); + $('#checkBoxAll').prop("checked", false); +} +