db->select('DISTINCT dxcc_entities.name AS COL_COUNTRY, COL_DXCC, COUNT(*) as qso_count', FALSE); $this->db->from($this->config->item('table_name')); $this->db->join('station_profile', 'station_profile.station_id = ' . $this->config->item('table_name') . '.station_id'); $this->db->join('dxcc_entities', 'dxcc_entities.adif = ' . $this->config->item('table_name') . '.COL_DXCC'); $this->db->where('station_profile.user_id', $this->session->userdata('user_id')); $this->db->where("LENGTH(COL_GRIDSQUARE) >=", 6); // At least 6 chars $this->db->group_by('COL_COUNTRY, COL_DXCC'); $this->db->order_by('COL_COUNTRY'); $query = $this->db->get(); return $query->result_array(); } /** * Get available station profiles for the user */ public function get_station_profiles() { $this->db->select('station_profile.station_id, station_profile.station_profile_name', FALSE); $this->db->from($this->config->item('table_name')); $this->db->join('station_profile', 'station_profile.station_id = ' . $this->config->item('table_name') . '.station_id'); $this->db->where('station_profile.user_id', $this->session->userdata('user_id')); $this->db->group_by('station_profile.station_id, station_profile.station_profile_name'); $this->db->order_by('station_profile.station_profile_name'); $query = $this->db->get(); return $query->result_array(); } /** * Get QSOs for a specific country with 6+ character grids */ public function get_qsos_by_country($country, $station_id = null) { if (!$this->load->is_loaded('Qra')) { $this->load->library('Qra'); } if (!$this->load->is_loaded('DxccFlag')) { $this->load->library('DxccFlag'); } $this->db->select('COL_PRIMARY_KEY, COL_CALL, COL_GRIDSQUARE, COL_COUNTRY, COL_DXCC, COL_MODE, COL_BAND, COL_TIME_ON, COL_RST_SENT, COL_RST_RCVD, station_profile.station_profile_name', FALSE); $this->db->from($this->config->item('table_name')); $this->db->join('station_profile', 'station_profile.station_id = ' . $this->config->item('table_name') . '.station_id'); $this->db->where('station_profile.user_id', $this->session->userdata('user_id')); $this->db->where('COL_COUNTRY', $country); // Add station filter if specified if ($station_id !== null && $station_id !== '') { $this->db->where('station_profile.station_id', $station_id); } $this->db->where("LENGTH(COL_GRIDSQUARE) >=", 6); // At least 6 chars $this->db->order_by('COL_TIME_ON', 'DESC'); $query = $this->db->get(); $qsos = $query->result_array(); // Process QSOs and convert gridsquares to coordinates $result = []; foreach ($qsos as $qso) { $gridsquare = strtoupper(trim($qso['COL_GRIDSQUARE'])); // Only include QSOs with 6+ character grids if (strlen($gridsquare) >= 6) { $coords = $this->qra->qra2latlong($gridsquare); if ($coords !== false && is_array($coords) && count($coords) >= 2) { $result[] = [ 'call' => $qso['COL_CALL'], 'gridsquare' => $gridsquare, 'country' => $qso['COL_COUNTRY'], 'dxcc' => $qso['COL_DXCC'], 'mode' => $qso['COL_MODE'], 'band' => $qso['COL_BAND'], 'time_on' => $qso['COL_TIME_ON'], 'rst_sent' => $qso['COL_RST_SENT'], 'rst_rcvd' => $qso['COL_RST_RCVD'], 'lat' => $coords[0], 'lng' => $coords[1], 'profile' => $qso['station_profile_name'], 'popup' => $this->createContentMessageDx($qso) ]; } } } return $result; } /** * Generate HTML content for QSO popup display */ public function createContentMessageDx($qso) { $table = ''; // Callsign with flag $table .= ''; $table .= ''; $table .= ''; // Date/Time $table .= ''; $table .= ''; $datetime = date('Y-m-d H:i', strtotime($qso['COL_TIME_ON'])); $table .= ''; $table .= ''; // Band/Satellite $table .= ''; if (!empty($qso['COL_SAT_NAME'])) { $table .= ''; $table .= ''; } else { $table .= ''; $table .= ''; } $table .= ''; // Mode $table .= ''; $table .= ''; $table .= ''; $table .= ''; // Gridsquare if (!empty($qso['COL_GRIDSQUARE'])) { $table .= ''; $table .= ''; $table .= ''; $table .= ''; } // Distance (if available) if (isset($qso['distance'])) { $table .= ''; $table .= ''; $table .= ''; $table .= ''; } // Bearing (if available) if (isset($qso['bearing'])) { $table .= ''; $table .= ''; $table .= ''; $table .= ''; } // Station Profile if (!empty($qso['station_profile_name'])) { $table .= ''; $table .= ''; $table .= ''; $table .= ''; } $table .= '
'; if (!empty($qso['COL_DXCC'])) { $dxccFlag = $this->dxccflag->get($qso['COL_DXCC']); $table .= '
' . htmlspecialchars($dxccFlag) . '
'; } // Replace zeros with Ø in callsign $callsign = str_replace('0', 'Ø', $qso['COL_CALL']); $table .= '' . htmlspecialchars($callsign) . '
'; $table .= '
Date/Time' . htmlspecialchars($datetime) . '
BandSAT ' . htmlspecialchars($qso['COL_SAT_NAME']); if (!empty($qso['COL_SAT_MODE'])) { $table .= ' (' . htmlspecialchars($qso['COL_SAT_MODE']) . ')'; } $table .= 'Band' . htmlspecialchars($qso['COL_BAND']) . '
Mode' . htmlspecialchars($qso['COL_MODE']) . '
Gridsquare' . htmlspecialchars($qso['COL_GRIDSQUARE']) . '
Distance' . htmlspecialchars($qso['distance']) . '
Bearing' . htmlspecialchars($qso['bearing']) . '
Station' . htmlspecialchars($qso['station_profile_name']) . '
'; return $table; } }