diff --git a/application/controllers/Api.php b/application/controllers/Api.php index ebad93112..191fdafaa 100644 --- a/application/controllers/Api.php +++ b/application/controllers/Api.php @@ -364,6 +364,13 @@ class API extends CI_Controller { $band = null; } + // If $obj['cnfm'] exists + if(isset($obj['cnfm'])) { + $cnfm = $obj['cnfm']; + } else { + $cnfm = null; + } + $this->load->model('logbooks_model'); if($this->logbooks_model->public_slug_exists($logbook_slug)) { @@ -388,15 +395,24 @@ class API extends CI_Controller { // Search Logbook for callsign $this->load->model('logbook_model'); - $result = $this->logbook_model->check_if_grid_worked_in_logbook($grid, $logbooks_locations_array, $band); - + $query = $this->logbook_model->check_if_grid_worked_in_logbook($grid, $logbooks_locations_array, $band, $cnfm); http_response_code(201); - if($result > 0) - { + if ($query->num_rows() == 0) { + echo json_encode(['gridsquare' => strtoupper($grid), 'result' => 'Not Found']); + } else if ($cnfm == null) { echo json_encode(['gridsquare' => strtoupper($grid), 'result' => 'Found']); } else { - echo json_encode(['gridsquare' => strtoupper($grid), 'result' => 'Not Found']); + $arr = []; + foreach($query->result() as $line) { + $arr[] = $line->gridorcnfm; + } + if (in_array('Y', $arr)) { + echo json_encode(['gridsquare' => strtoupper($grid), 'result' => 'Confirmed']); + } else { + echo json_encode(['gridsquare' => strtoupper($grid), 'result' => 'Worked']); + } } + } else { // Logbook not found http_response_code(404); diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index ad0626076..7654393ed 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -2136,7 +2136,7 @@ function check_if_callsign_worked_in_logbook($callsign, $StationLocationsArray = } - function check_if_grid_worked_in_logbook($grid, $StationLocationsArray = null, $band = null) { + function check_if_grid_worked_in_logbook($grid, $StationLocationsArray = null, $band = null, $cnfm = null) { if($StationLocationsArray == null) { $this->load->model('logbooks_model'); @@ -2145,7 +2145,25 @@ function check_if_callsign_worked_in_logbook($callsign, $StationLocationsArray = $logbooks_locations_array = $StationLocationsArray; } - $this->db->select('COL_GRIDSQUARE'); + switch($cnfm) { + case 'qsl': + $this->db->select('COL_QSL_RCVD as gridorcnfm'); + $this->db->group_by('COL_QSL_RCVD'); + break; + case 'lotw': + $this->db->select('COL_LOTW_QSL_RCVD as gridorcnfm'); + $this->db->group_by('COL_LOTW_QSL_RCVD'); + break; + case 'eqsl': + $this->db->select('COL_EQSL_QSL_RCVD as gridorcnfm'); + $this->db->group_by('COL_EQSL_QSL_RCVD'); + break; + default: + $this->db->select('SUBSTR(COL_GRIDSQUARE,1 ,4) as gridorcnfm'); + $this->db->group_by('gridorcnfm'); + break; + } + $this->db->order_by('gridorcnfm'); $this->db->where_in('station_id', $logbooks_locations_array); $this->db->group_start(); $this->db->like('COL_GRIDSQUARE', $grid); @@ -2158,11 +2176,10 @@ function check_if_callsign_worked_in_logbook($callsign, $StationLocationsArray = // Where col_sat_name is not empty $this->db->where('COL_SAT_NAME !=', ''); } - $this->db->limit('2'); $query = $this->db->get($this->config->item('table_name')); - return $query->num_rows(); + return $query; }