diff --git a/application/controllers/Options.php b/application/controllers/Options.php index 3140ef01..fd85444a 100644 --- a/application/controllers/Options.php +++ b/application/controllers/Options.php @@ -255,7 +255,7 @@ class Options extends CI_Controller { function oqrs() { $data['page_title'] = "Cloudlog Options"; - $data['sub_heading'] = "OQRS Global text"; + $data['sub_heading'] = "OQRS Options"; $this->load->view('interface_assets/header', $data); $this->load->view('options/oqrs'); @@ -265,7 +265,7 @@ class Options extends CI_Controller { function oqrs_save() { $data['page_title'] = "Cloudlog Options"; - $data['sub_heading'] = "OQRS Global text"; + $data['sub_heading'] = "OQRS Options"; $this->load->helper(array('form', 'url')); @@ -273,8 +273,10 @@ class Options extends CI_Controller { $global_oqrs_text = $this->optionslib->update('global_oqrs_text', $this->input->post('global_oqrs_text'), null); + $global_oqrs_text = $this->optionslib->update('groupedSearch', $this->input->post('groupedSearch'), null); + if($global_oqrs_text == TRUE) { - $this->session->set_flashdata('success', 'OQRS Global text has been saved.'); + $this->session->set_flashdata('success', 'OQRS options have been saved.'); } redirect('/options/oqrs'); diff --git a/application/controllers/Oqrs.php b/application/controllers/Oqrs.php index dfc379f6..51d8522c 100644 --- a/application/controllers/Oqrs.php +++ b/application/controllers/Oqrs.php @@ -22,7 +22,7 @@ class Oqrs extends CI_Controller { $data['stations'] = $this->oqrs_model->get_oqrs_stations(); $data['page_title'] = "Log Search & OQRS"; $data['global_oqrs_text'] = $this->optionslib->get_option('global_oqrs_text'); - + $data['groupedSearch'] = $this->optionslib->get_option('groupedSearch'); $this->load->view('visitor/layout/header', $data); $this->load->view('oqrs/index'); @@ -50,11 +50,19 @@ class Oqrs extends CI_Controller { $this->load->view('oqrs/result', $data); } + public function get_qsos_grouped() { + $this->load->model('oqrs_model'); + $data['result'] = $this->oqrs_model->getQueryDataGrouped($this->input->post('callsign')); + $data['callsign'] = $this->security->xss_clean($this->input->post('callsign')); + + $this->load->view('oqrs/request_grouped', $data); + } + public function not_in_log() { $data['page_title'] = "Log Search & OQRS"; $this->load->model('bands'); - $data['bands'] = $this->bands->get_worked_bands_oqrs($this->security->xss_clean($this->input->post('station_id'))); + // $data['bands'] = $this->bands->get_worked_bands_oqrs($this->security->xss_clean($this->input->post('station_id'))); $this->load->view('oqrs/notinlogform', $data); } @@ -103,8 +111,15 @@ class Oqrs extends CI_Controller { public function save_oqrs_request() { $postdata = $this->input->post(); $this->load->model('oqrs_model'); - $this->oqrs_model->save_oqrs_request($postdata); - $this->alert_oqrs_request($postdata); + $station_ids = $this->oqrs_model->save_oqrs_request($postdata); + $this->alert_oqrs_request($postdata, $station_ids); + } + + public function save_oqrs_request_grouped() { + $postdata = $this->input->post(); + $this->load->model('oqrs_model'); + $station_ids = $this->oqrs_model->save_oqrs_request_grouped($postdata); + $this->alert_oqrs_request($postdata, $station_ids); } public function delete_oqrs_line() { @@ -134,49 +149,51 @@ class Oqrs extends CI_Controller { $this->load->view('oqrs/qsolist', $data); } - public function alert_oqrs_request($postdata) { - $this->load->model('user_model'); - - $email = $this->user_model->get_email_address($this->session->userdata('user_id')); - - $this->load->model('oqrs_model'); - - $sendEmail = $this->oqrs_model->getOqrsEmailSetting($this->security->xss_clean($this->input->post('station_id'))); - - if($email != "" && $sendEmail == "1") { + public function alert_oqrs_request($postdata, $station_ids) { + foreach ($station_ids as $id) { + $this->load->model('user_model'); + + $email = $this->user_model->get_email_address($id); + + $this->load->model('oqrs_model'); - $this->load->library('email'); - - if($this->optionslib->get_option('emailProtocol') == "smtp") { - $config = Array( - 'protocol' => $this->optionslib->get_option('emailProtocol'), - 'smtp_host' => $this->optionslib->get_option('smtpHost'), - 'smtp_port' => $this->optionslib->get_option('smtpPort'), - 'smtp_user' => $this->optionslib->get_option('smtpUsername'), - 'smtp_pass' => $this->optionslib->get_option('smtpPassword'), - 'crlf' => "\r\n", - 'newline' => "\r\n" - ); - - $this->email->initialize($config); - } - - $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); - - if (! $this->email->send()) { - $this->session->set_flashdata('warning', 'Email settings are incorrect.'); - } else { - $this->session->set_flashdata('notice', 'Password Reset Processed.'); + $sendEmail = $this->oqrs_model->getOqrsEmailSetting($id); + + if($email != "" && $sendEmail == "1") { + + $this->load->library('email'); + + if($this->optionslib->get_option('emailProtocol') == "smtp") { + $config = Array( + 'protocol' => $this->optionslib->get_option('emailProtocol'), + 'smtp_host' => $this->optionslib->get_option('smtpHost'), + 'smtp_port' => $this->optionslib->get_option('smtpPort'), + 'smtp_user' => $this->optionslib->get_option('smtpUsername'), + 'smtp_pass' => $this->optionslib->get_option('smtpPassword'), + 'crlf' => "\r\n", + 'newline' => "\r\n" + ); + + $this->email->initialize($config); + } + + $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); + + if (! $this->email->send()) { + $this->session->set_flashdata('warning', 'Email settings are incorrect.'); + } else { + $this->session->set_flashdata('notice', 'Password Reset Processed.'); + } } } } diff --git a/application/models/Oqrs_model.php b/application/models/Oqrs_model.php index 6c800ea4..b2b7a70b 100644 --- a/application/models/Oqrs_model.php +++ b/application/models/Oqrs_model.php @@ -42,6 +42,18 @@ class Oqrs_model extends CI_Model { return $result; } + + function get_qsos_grouped($callsign){ + + // Populating array with worked band/mode combinations + $worked = $this->getQueryData($station_id, $callsign); + + $result['qsocount'] = count($worked); + $result['qsoarray'] = $resultArray; + + return $result; + } + /* * Builds query depending on what we are searching for */ @@ -57,6 +69,26 @@ class Oqrs_model extends CI_Model { return $query->result(); } + /* + * Builds query depending on what we are searching for + */ + function getQueryDataGrouped($callsign) { + $callsign = $this->security->xss_clean($callsign); + $sql = 'select lower(col_mode) col_mode, coalesce(col_submode, "") col_submode, col_band, station_callsign, station_profile_name, l.station_id from ' . $this->config->item('table_name') . ' as l join station_profile on l.station_id = station_profile.station_id where station_profile.oqrs = "1" and l.col_call ="' . $callsign . '" and l.col_prop_mode != "SAT"'; + + $sql .= ' union all select lower(col_mode) col_mode, coalesce(col_submode, "") col_submode, "SAT" col_band, station_callsign, station_profile_name, l.station_id from ' . + $this->config->item('table_name') . ' l' . + ' join station_profile on l.station_id = station_profile.station_id where station_profile.oqrs = "1" and col_call ="' . $callsign . '" and col_prop_mode = "SAT"'; + + $query = $this->db->query($sql); + + if ($query) { + return $query->result(); + } + + return; + } + /* * Get's the worked modes from the log */ @@ -92,6 +124,7 @@ class Oqrs_model extends CI_Model { } function save_oqrs_request($postdata) { + $station_ids = array(); $qsos = $postdata['qsos']; foreach($qsos as $qso) { $data = array( @@ -115,7 +148,45 @@ class Oqrs_model extends CI_Model { } $this->db->insert('oqrs', $data); + if(!in_array(xss_clean($postdata['station_id']), $station_ids)){ + array_push($station_ids, xss_clean($postdata['station_id'])); + } } + + return $station_ids; + } + + function save_oqrs_request_grouped($postdata) { + $station_ids = array(); + $qsos = $postdata['qsos']; + foreach($qsos as $qso) { + $data = array( + 'date' => xss_clean($qso[0]), + 'time' => xss_clean($qso[1]), + 'band' => xss_clean($qso[2]), + 'mode' => xss_clean($qso[3]), + 'requestcallsign' => xss_clean($postdata['callsign']), + 'station_id' => xss_clean($qso[4]), + 'note' => xss_clean($postdata['message']), + 'email' => xss_clean($postdata['email']), + 'qslroute' => xss_clean($postdata['qslroute']), + 'status' => '0', + ); + + $qsoid = $this->check_oqrs($data); + + if ($qsoid > 0) { + $data['status'] = '2'; + $data['qsoid'] = $qsoid; + } + + $this->db->insert('oqrs', $data); + + if(!in_array(xss_clean($qso[4]), $station_ids)){ + array_push($station_ids, xss_clean($qso[4])); + } + } + return $station_ids; } function delete_oqrs_line($id) { @@ -178,16 +249,15 @@ class Oqrs_model extends CI_Model { // Set Paper to requested function paperqsl_requested($qso_id, $method) { + $data = array( + 'COL_QSLSDATE' => date('Y-m-d H:i:s'), + 'COL_QSL_SENT' => 'R', + 'COL_QSL_SENT_VIA ' => $method + ); - $data = array( - 'COL_QSLSDATE' => date('Y-m-d H:i:s'), - 'COL_QSL_SENT' => 'R', - 'COL_QSL_SENT_VIA ' => $method - ); + $this->db->where('COL_PRIMARY_KEY', $qso_id); - $this->db->where('COL_PRIMARY_KEY', $qso_id); - - $this->db->update($this->config->item('table_name'), $data); + $this->db->update($this->config->item('table_name'), $data); } function search_log($callsign) { diff --git a/application/models/User_model.php b/application/models/User_model.php index c4a24fb5..5e6de8c8 100644 --- a/application/models/User_model.php +++ b/application/models/User_model.php @@ -76,8 +76,9 @@ class User_Model extends CI_Model { } } - function get_email_address($userid) { - $this->db->where('user_id', $userid); + function get_email_address($station_id) { + $this->db->where('station_id', $station_id); + $this->db->join('station_profile', 'station_profile.user_id = '.$this->config->item('auth_table').'.user_id'); $query = $this->db->get($this->config->item('auth_table')); $ret = $query->row(); diff --git a/application/views/options/oqrs.php b/application/views/options/oqrs.php index 56ea573b..9af9404a 100644 --- a/application/views/options/oqrs.php +++ b/application/views/options/oqrs.php @@ -35,9 +35,18 @@
- -

This text is an optional text that can be displayed on top of the OQRS page.

+ + This text is an optional text that can be displayed on top of the OQRS page. +
+ +
+ + + When this is on, all station locations with OQRS active, will be searched at once.
diff --git a/application/views/oqrs/index.php b/application/views/oqrs/index.php index 030853f8..18e8cda0 100644 --- a/application/views/oqrs/index.php +++ b/application/views/oqrs/index.php @@ -14,8 +14,15 @@ '; + echo '

'; } + if ($groupedSearch == 'on') { + echo 'This search will search in all station locations where OQRS is active.

+ + +
'; + echo '
'; + } else { echo '
'; if ($stations->result() != NULL) { ?> @@ -31,12 +38,14 @@
+ + else { + echo 'No stations found that are using Cloudlog OQRS.'; + } + } + ?>
diff --git a/application/views/oqrs/request_grouped.php b/application/views/oqrs/request_grouped.php new file mode 100644 index 00000000..7171f3f8 --- /dev/null +++ b/application/views/oqrs/request_grouped.php @@ -0,0 +1,68 @@ +
+ +The following QSO(s) were found. Please fill out the date and time and submit your request. + + + + + + + + + + + + + + station_id.'">'; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + ?> + +
#DateTime (UTC)BandModeCallsignName
'. $i++ .''. $qso->col_band .''; echo $qso->col_submode == null ? strtoupper($qso->col_mode) : strtoupper($qso->col_submode); echo ''. $qso->station_callsign .''. $qso->station_profile_name .'
+
+ +
+
+ +
+ +
+ + +
+ +
+ + +
+

+
+ + + Any extra information we need to know about? +
+ +
+ + + Your e-mail address where we can contact you +
+ + +
+'; +} + ?> \ No newline at end of file diff --git a/assets/js/sections/oqrs.js b/assets/js/sections/oqrs.js index a08c40bc..0506ae17 100644 --- a/assets/js/sections/oqrs.js +++ b/assets/js/sections/oqrs.js @@ -41,6 +41,18 @@ function searchOqrs() { }); } +function searchOqrsGrouped() { + $(".searchinfo").empty(); + $.ajax({ + url: base_url+'index.php/oqrs/get_qsos_grouped', + type: 'post', + data: {'callsign': $("#oqrssearch").val().toUpperCase()}, + success: function (data) { + $(".searchinfo").append(data); + } + }); +} + function notInLog() { $.ajax({ url: base_url + 'index.php/oqrs/not_in_log', @@ -206,6 +218,52 @@ function submitOqrsRequest() { } } +function submitOqrsRequestGrouped() { + $(".alertinfo").remove(); + if ($("#emailInput").val() == '') { + $(".searchinfo").prepend('

×You need to fill out an email address!
'); + } else { + const qsos = []; + $(".result-table tbody tr").each(function(i) { + var data = []; + var stationid = this.getAttribute('stationid');; + var datecell = $("#date", this).val(); + var timecell = $("#time", this).val(); + var bandcell = $("#band", this).text(); + var modecell = $("#mode", this).text(); + if (datecell != "" && timecell != "") { + data.push(datecell); + data.push(timecell); + data.push(bandcell); + data.push(modecell); + data.push(stationid); + qsos.push(data); + } + }); + + if (qsos.length === 0) { + $(".searchinfo").prepend('

×You need to fill the QSO information before submitting a request!
'); + } else { + $.ajax({ + url: base_url+'index.php/oqrs/save_oqrs_request_grouped', + type: 'post', + data: { + 'callsign': $("#oqrssearch").val().toUpperCase(), + 'email': $("#emailInput").val(), + 'message': $("#messageInput").val(), + 'qsos': qsos, + 'qslroute': $('input[name="qslroute"]:checked').val() + }, + success: function (data) { + $(".stationinfo").empty(); + $(".searchinfo").empty(); + $(".searchinfo").append('
×Your QSL request has been saved!
'); + } + }); + } + } +} + function searchLog(callsign) { $.ajax({ url: base_url + 'index.php/oqrs/search_log',