diff --git a/application/controllers/Contesting.php b/application/controllers/Contesting.php index bcb9f46e..a32765ff 100644 --- a/application/controllers/Contesting.php +++ b/application/controllers/Contesting.php @@ -150,4 +150,24 @@ class Contesting extends CI_Controller { echo json_encode(array('message' => 'OK')); return; } + + /* + * Function is used for dupe-checking in contestinglogging + */ + public function checkIfWorkedBefore() { + $call = $this->input->post('call'); + $band = $this->input->post('band'); + $mode = $this->input->post('mode'); + $contest = $this->input->post('contest'); + $qso = $this->input->post('qso'); + + $this->load->model('Contesting_model'); + $result = $this->Contesting_model->checkIfWorkedBefore($call, $band, $mode, $contest, $qso); + + header('Content-Type: application/json'); + if ($result->num_rows()) { + echo json_encode(array('message' => 'Worked before')); + } + return; + } } diff --git a/application/models/Contesting_model.php b/application/models/Contesting_model.php index b026e759..2486b7bd 100644 --- a/application/models/Contesting_model.php +++ b/application/models/Contesting_model.php @@ -142,4 +142,28 @@ class Contesting_model extends CI_Model { return true; } + + function checkIfWorkedBefore($call, $band, $mode, $contest, $qso) { + $CI =& get_instance(); + $CI->load->model('Stations'); + $station_id = $CI->Stations->find_active(); + + $qsoarray = explode(',', $qso); + + $date = DateTime::createFromFormat('d-m-Y H:i:s', $qsoarray[0]); + $date = $date->format('Y-m-d H:i:s'); + + $this->db->where('STATION_ID', $station_id); + $this->db->where('COL_CALL', xss_clean($call)); + $this->db->where("COL_BAND", xss_clean($band)); + $this->db->where("COL_CONTEST_ID", xss_clean($contest)); + $this->db->where("COL_TIME_ON >=", $date); + $this->db->group_start(); + $this->db->where("COL_MODE", xss_clean($mode)); + $this->db->or_where("COL_SUBMODE", xss_clean($mode)); + $this->db->group_end(); + $query = $this->db->get($this->config->item('table_name')); + + return $query; + } } diff --git a/application/views/contesting/index.php b/application/views/contesting/index.php index 599658ed..d875b0d0 100644 --- a/application/views/contesting/index.php +++ b/application/views/contesting/index.php @@ -113,6 +113,7 @@
+
diff --git a/assets/js/sections/contesting.js b/assets/js/sections/contesting.js index 8f6086d9..c6afd092 100644 --- a/assets/js/sections/contesting.js +++ b/assets/js/sections/contesting.js @@ -165,12 +165,33 @@ $("#callsign").keyup(function () { $('.callsign-suggestions').text(result); highlight(call.toUpperCase()); }); + checkIfWorkedBefore(); } else if (call.length <= 2) { $('.callsign-suggestions').text(""); } }); +function checkIfWorkedBefore() { + $('#callsign_info').text(""); + $.ajax({ + url: base_url + 'index.php/contesting/checkIfWorkedBefore', + type: 'post', + data: { + 'call': $("#callsign").val(), + 'mode': $("#mode").val(), + 'band': $("#band").val(), + 'contest': $("#contestname").val(), + 'qso': localStorage.getItem("qso") + }, + success: function (result) { + if (result.message == 'Worked before') { + $('#callsign_info').text("Worked before!"); + } + } + }); +} + function reset_log_fields() { $('#name').val(""); $('.callsign-suggestions').text(""); @@ -181,6 +202,7 @@ function reset_log_fields() { $('#exch_gridsquare_r').val(""); $("#callsign").focus(); setRst($("#mode").val()); + $('#callsign_info').text(""); } RegExp.escape = function (text) { @@ -218,6 +240,7 @@ $('#mode').change(function () { $('#frequency_rx').val(""); }); setRst($("#mode").val()); + checkIfWorkedBefore(); }); /* Calculate Frequency */ @@ -227,6 +250,7 @@ $('#band').change(function () { $('#frequency').val(result); $('#frequency_rx').val(""); }); + checkIfWorkedBefore(); }); $('#exchangetype').change(function () {