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 @@