diff --git a/application/controllers/Stationsetup.php b/application/controllers/Stationsetup.php index 3ef2ee9b2..3098c5536 100644 --- a/application/controllers/Stationsetup.php +++ b/application/controllers/Stationsetup.php @@ -17,12 +17,13 @@ class Stationsetup extends CI_Controller { public function index() { $this->load->model('stations'); + $this->load->model('stationsetup_model'); $this->load->model('Logbook_model'); $this->load->model('logbooks_model'); $data['my_logbooks'] = $this->logbooks_model->show_all(); - $data['stations'] = $this->stations->all_with_count(); + $data['stations'] = $this->stationsetup_model->get_all_locations(); $data['current_active'] = $this->stations->find_active(); $data['is_there_qsos_with_no_station_id'] = $this->Logbook_model->check_for_station_id(); @@ -290,9 +291,10 @@ class Stationsetup extends CI_Controller { public function fetchLocations() { $this->load->model('stations'); + $this->load->model('stationsetup_model'); $this->load->model('Logbook_model'); - $result = $this->stations->all_with_count()->result(); + $result = $this->stationsetup_model->get_all_locations()->result(); $current_active = $this->stations->find_active(); $data['is_there_qsos_with_no_station_id'] = $this->Logbook_model->check_for_station_id(); @@ -313,11 +315,27 @@ class Stationsetup extends CI_Controller { $single->station_delete = $this->stationdelete2html($entry->station_id, $entry->station_profile_name, $entry->station_active); $single->station_favorite = $this->stationfavorite2html($entry->station_id, $quickswitch_enabled); $single->station_linked = $this->stationlinked2html($entry->linked); + $single->station_lastqso = $this->stationformattedlastqsodate2html($entry->lastqsodate); array_push($hres,$single); } echo json_encode($hres); } + private function stationformattedlastqsodate2html($lastqsodate) { + $CI =& get_instance(); + // Get Date format + if($CI->session->userdata('user_date_format')) { + // If Logged in and session exists + $custom_date_format = $CI->session->userdata('user_date_format'); + } else { + // Get Default date format from /config/wavelog.php + $custom_date_format = $CI->config->item('qso_date_format'); + } + if ($lastqsodate == null) return ''; + + return date($custom_date_format . " H:i", strtotime($lastqsodate ?? '1970-01-01 00:00:00')); + } + private function stationlinked2html($linked) { if ($linked == 1) { return ''; diff --git a/application/models/Stations.php b/application/models/Stations.php index 51ad58775..5e22bb106 100644 --- a/application/models/Stations.php +++ b/application/models/Stations.php @@ -5,18 +5,6 @@ class Stations extends CI_Model { public function __construct() { } - function all_with_count() { - $this->db->select('station_profile.*, dxcc_entities.name as station_country, dxcc_entities.end as dxcc_end, count('.$this->config->item('table_name').'.station_id) as qso_total, exists(select 1 from station_logbooks_relationship where station_location_id = station_profile.station_id and station_logbook_id = '.($this->session->userdata('active_station_logbook') ?? 0).') as linked'); - $this->db->from('station_profile'); - $this->db->join($this->config->item('table_name'),'station_profile.station_id = '.$this->config->item('table_name').'.station_id','left'); - $this->db->join('dxcc_entities','station_profile.station_dxcc = dxcc_entities.adif','left outer'); - $this->db->group_by('station_profile.station_id'); - $this->db->where('station_profile.user_id', $this->session->userdata('user_id')); - $this->db->or_where('station_profile.user_id =', NULL); - - return $this->db->get(); - } - // Returns ALL station profiles regardless of user logged in // This is also used by LoTW sync so must not be changed. function all() { @@ -49,7 +37,7 @@ class Stations extends CI_Model { foreach ($query->result() as $row) { array_push($a_station_ids, $row->station_id); } - $station_ids=implode(', ', $a_station_ids); + $station_ids=implode(', ', $a_station_ids); return $station_ids; } else { return ''; @@ -114,12 +102,12 @@ class Stations extends CI_Model { $state = xss_clean($this->input->post('station_state', true)); } - // Check if DXCC is USA, Alaska or Hawaii, RU, UR, and others with subareas. + // Check if DXCC is USA, Alaska or Hawaii, RU, UR, and others with subareas. // If not true, we clear the County field due to complex adif specs switch ($this->input->post('dxcc')) { case 6: case 110: - case 291: + case 291: case 15: case 54: case 61: @@ -196,12 +184,12 @@ class Stations extends CI_Model { $state = xss_clean($this->input->post('station_state', true)); } - // Check if DXCC is USA, Alaska or Hawaii, RU, UR, and others with subareas. + // Check if DXCC is USA, Alaska or Hawaii, RU, UR, and others with subareas. // If not true, we clear the County field due to complex adif specs switch ($this->input->post('dxcc')) { case 6: case 110: - case 291: + case 291: case 15: case 54: case 61: @@ -297,7 +285,7 @@ class Stations extends CI_Model { } // Delete QSOs $this->db->query("DELETE FROM ".$this->config->item('table_name')." WHERE station_id = ?",$clean_id); - + // Also clean up static map images if (!$this->load->is_loaded('staticmap_model')) { $this->load->model('staticmap_model'); diff --git a/application/models/Stationsetup_model.php b/application/models/Stationsetup_model.php index b488e3246..e612289d4 100644 --- a/application/models/Stationsetup_model.php +++ b/application/models/Stationsetup_model.php @@ -8,7 +8,7 @@ class Stationsetup_model extends CI_Model { if ($session) { $this->db->where('user_id', $this->session->userdata('user_id')); - } + } $this->db->where('logbook_id', $clean_id); return $this->db->get('station_logbooks'); } @@ -220,6 +220,18 @@ class Stationsetup_model extends CI_Model { return -1; } } + + function get_all_locations() { + $this->db->select('station_profile.*, dxcc_entities.name as station_country, dxcc_entities.end as dxcc_end, count('.$this->config->item('table_name').'.station_id) as qso_total, (select max(col_time_on) from '.$this->config->item('table_name').' where station_id = station_profile.station_id) lastqsodate, exists(select 1 from station_logbooks_relationship where station_location_id = station_profile.station_id and station_logbook_id = '.($this->session->userdata('active_station_logbook') ?? 0).') as linked'); + $this->db->from('station_profile'); + $this->db->join($this->config->item('table_name'),'station_profile.station_id = '.$this->config->item('table_name').'.station_id','left'); + $this->db->join('dxcc_entities','station_profile.station_dxcc = dxcc_entities.adif','left outer'); + $this->db->group_by('station_profile.station_id'); + $this->db->where('station_profile.user_id', $this->session->userdata('user_id')); + $this->db->or_where('station_profile.user_id =', NULL); + + return $this->db->get(); + } } ?> diff --git a/application/views/stationsetup/stationsetup.php b/application/views/stationsetup/stationsetup.php index 5e8e0441e..433f81f80 100644 --- a/application/views/stationsetup/stationsetup.php +++ b/application/views/stationsetup/stationsetup.php @@ -123,6 +123,7 @@