diff --git a/application/controllers/Oqrs.php b/application/controllers/Oqrs.php index 46fde176..f7830889 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'); @@ -159,11 +160,13 @@ class Oqrs extends CI_Controller { } $data['callsign'] = $this->security->xss_clean($postdata['callsign']); + $data['usermessage'] = $this->security->xss_clean($postdata['message']); $message = $this->load->view('email/oqrs_request', $data, TRUE); $this->email->from('noreply@cloudlog.co.uk', 'Cloudlog'); $this->email->to($email); + $this->email->reply_to($this->security->xss_clean($postdata['email']), strtoupper($data['callsign'])); $this->email->subject('Cloudlog OQRS from ' . strtoupper($data['callsign'])); $this->email->message($message); @@ -182,4 +185,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..0cc87564 100644 --- a/application/models/Oqrs_model.php +++ b/application/models/Oqrs_model.php @@ -50,7 +50,7 @@ class Oqrs_model extends CI_Model { $callsign = $this->security->xss_clean($callsign); $sql = 'select lower(col_mode) col_mode, coalesce(col_submode, "") col_submode, col_band from ' . $this->config->item('table_name') . ' where station_id = ' . $station_id . ' and col_call ="' . $callsign . '" and col_prop_mode != "SAT"'; - $sql .= ' union select lower(col_mode) col_mode, coalesce(col_submode, "") col_submode, "SAT" col_band from ' . $this->config->item('table_name') . ' where station_id = ' . $station_id . ' and col_call ="' . $callsign . '" and col_prop_mode = "SAT"'; + $sql .= ' union all select lower(col_mode) col_mode, coalesce(col_submode, "") col_submode, "SAT" col_band from ' . $this->config->item('table_name') . ' where station_id = ' . $station_id . ' and col_call ="' . $callsign . '" and col_prop_mode = "SAT"'; $query = $this->db->query($sql); @@ -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,57 @@ 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 ($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']; + } - if ($query->num_rows() > 0) { - return true; + $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'); + } + + public function oqrs_requests($location_list) { + if ($location_list != "") { + $sql = 'SELECT COUNT(*) AS number FROM oqrs JOIN station_profile ON oqrs.station_id = station_profile.station_id WHERE oqrs.station_id IN ('.$location_list.') AND status < 2'; + $query = $this->db->query($sql); + $row = $query->row(); + return $row->number; } else { - return false; + return 0; } } } diff --git a/application/views/email/oqrs_request.php b/application/views/email/oqrs_request.php index 1518fc85..c35ec6cc 100644 --- a/application/views/email/oqrs_request.php +++ b/application/views/email/oqrs_request.php @@ -1,8 +1,14 @@ Hi, -You got an OQRS request from . +You got an OQRS request from . + +The user entered the following message: + + + + Please log into your Cloudlog and process it. Regards, -Cloudlog. \ No newline at end of file +Cloudlog. diff --git a/application/views/interface_assets/header.php b/application/views/interface_assets/header.php index 6263f796..22b125ad 100644 --- a/application/views/interface_assets/header.php +++ b/application/views/interface_assets/header.php @@ -229,7 +229,18 @@ - OQRS Requests +load->model('oqrs_model'); +$CI->load->model('logbooks_model'); +$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); +if ($logbooks_locations_array) { + $location_list = "'".implode("','",$logbooks_locations_array)."'"; +} else { + $location_list = null; +} +?> + OQRS Requests oqrs_model->oqrs_requests($location_list) > 0) { echo "".$CI->oqrs_model->oqrs_requests($location_list).""; } ?> Print Requested QSLs 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..683429dd 100644 --- a/assets/js/sections/oqrs.js +++ b/assets/js/sections/oqrs.js @@ -34,7 +34,7 @@ function searchOqrs() { $.ajax({ url: base_url+'index.php/oqrs/get_qsos', type: 'post', - data: {'station_id': $("#station").val(), 'callsign': $("#oqrssearch").val()}, + data: {'station_id': $("#station").val(), 'callsign': $("#oqrssearch").val().toUpperCase()}, success: function (data) { $(".searchinfo").append(data); } @@ -45,7 +45,7 @@ function notInLog() { $.ajax({ url: base_url + 'index.php/oqrs/not_in_log', type: 'post', - data: {'station_id': $("#station").val(), 'callsign': $("#oqrssearch").val()}, + data: {'station_id': $("#station").val(), 'callsign': $("#oqrssearch").val().toUpperCase()}, success: function(html) { $(".searchinfo").html(html); } @@ -79,7 +79,7 @@ function saveNotInLogRequest() { url: base_url+'index.php/oqrs/save_not_in_log', type: 'post', data: { 'station_id': $("#station").val(), - 'callsign': $("#oqrssearch").val(), + 'callsign': $("#oqrssearch").val().toUpperCase(), 'email': $("#emailInput").val(), 'message': $("#messageInput").val(), 'qsos': qsos @@ -115,7 +115,7 @@ function requestOqrs() { $.ajax({ url: base_url + 'index.php/oqrs/request_form', type: 'post', - data: {'station_id': $("#station").val(), 'callsign': $("#oqrssearch").val()}, + data: {'station_id': $("#station").val(), 'callsign': $("#oqrssearch").val().toUpperCase()}, success: function(html) { $(".searchinfo").html(html); $('.result-table').DataTable({ @@ -158,8 +158,8 @@ function submitOqrsRequest() { $.ajax({ url: base_url+'index.php/oqrs/save_oqrs_request', type: 'post', - data: { 'station_id': $("#station").val(), - 'callsign': $("#oqrssearch").val(), + data: { 'station_id': $("#station").val(), + 'callsign': $("#oqrssearch").val().toUpperCase(), 'email': $("#emailInput").val(), 'message': $("#messageInput").val(), 'qsos': qsos, @@ -175,28 +175,6 @@ function submitOqrsRequest() { } } -function deleteOqrsLine(id) { - BootstrapDialog.confirm({ - title: 'DANGER', - message: 'Warning! Are you sure you want to delete this OQRS request?', - type: BootstrapDialog.TYPE_DANGER, - closable: true, - draggable: true, - btnOKClass: 'btn-danger', - callback: function (result) { - $.ajax({ - url: base_url+'index.php/oqrs/delete_oqrs_line', - type: 'post', - data: { 'id': id, - }, - success: function (data) { - $(".oqrsid_"+id).remove(); - } - }); - } - }); -} - function searchLog(callsign) { $.ajax({ url: base_url + 'index.php/oqrs/search_log', @@ -228,10 +206,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({ @@ -254,14 +232,229 @@ function searchLogTimeDate(id) { }); } -function markOqrsLineAsDone(id) { - $.ajax({ - url: base_url+'index.php/oqrs/mark_oqrs_line_as_done', - type: 'post', - data: { 'id': id, - }, - success: function (data) { - $(".oqrsid_"+id).remove(); - } - }); +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('oqrsID') + $.ajax({ + url: base_url + 'index.php/oqrs/delete_oqrs_line', + type: 'post', + data: {'id': id + }, + success: function(data) { + var row = $("#oqrsID_" + 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 mark OQRS request(s) as done?' , + 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('oqrsID') + $.ajax({ + url: base_url + 'index.php/oqrs/mark_oqrs_line_as_done', + type: 'post', + data: {'id': id + }, + success: function(data) { + $('#searchForm').submit(); + } + }); + $('#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); +} +