diff --git a/application/controllers/Station.php b/application/controllers/Station.php index 447e4352..c61a7ad6 100644 --- a/application/controllers/Station.php +++ b/application/controllers/Station.php @@ -18,7 +18,11 @@ class Station extends CI_Controller { public function index() { $this->load->model('stations'); + $this->load->model('Logbook_model'); + $data['stations'] = $this->stations->all(); + $data['current_active'] = $this->stations->find_active(); + $data['is_there_qsos_with_no_station_id'] = $this->Logbook_model->check_for_station_id(); // Render Page $data['page_title'] = "Station Profiles"; @@ -33,7 +37,6 @@ class Station extends CI_Controller { $this->load->model('dxcc'); $data['dxcc_list'] = $this->dxcc->list(); - $this->load->library('form_validation'); $this->form_validation->set_rules('station_profile_name', 'Station Profile Name', 'required'); @@ -58,6 +61,23 @@ class Station extends CI_Controller { } + function reassign_profile($id) { + // $id is the profile that needs reassigned to QSOs + $this->load->model('stations'); + $this->stations->reassign($id); + + //$this->stations->logbook_session_data(); + redirect('station'); + } + + function set_active($current, $new) { + $this->load->model('stations'); + $this->stations->set_active($current, $new); + + //$this->stations->logbook_session_data(); + redirect('station'); + } + public function delete($id) { $this->load->model('stations'); $this->stations->delete($id); diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index 35630adc..98992395 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -1371,6 +1371,17 @@ class Logbook_model extends CI_Model { print("$count updated\n"); } + + public function check_for_station_id() { + $this->db->where('station_id !=', ""); + $query = $this->db->get($this->config->item('table_name')); + if($query->num_rows() >= 1) { + return 1; + } else { + return 0; + } + } + public function parse_frequency($frequency) { if (is_int($frequency)) diff --git a/application/models/Stations.php b/application/models/Stations.php index 47a8e8f2..115a133b 100644 --- a/application/models/Stations.php +++ b/application/models/Stations.php @@ -59,6 +59,81 @@ class Stations extends CI_Model { $this->db->delete('station_profile', array('station_id' => $id)); } + function set_active($current, $new) { + // Deselect current default + $current_default = array( + 'station_active' => null, + ); + $this->db->where('station_id', $current); + $this->db->update('station_profile', $current_default); + + // Deselect current default + $newdefault = array( + 'station_active' => 1, + ); + $this->db->where('station_id', $new); + $this->db->update('station_profile', $newdefault); + } + + public function find_active() { + $this->db->where('station_active', 1); + $query = $this->db->get('station_profile'); + + if($query->num_rows() >= 1) { + foreach ($query->result() as $row) + { + return $row->station_id; + } + } else { + return "0"; + } + } + + public function reassign($id) { + $this->db->where('station_id', $id); + $query = $this->db->get('station_profile'); + + $row = $query->row(); + + //print_r($row); + + $data = array( + 'station_id' => $id, + ); + + $this->db->where('COL_STATION_CALLSIGN', $row->station_callsign); + + if($row->station_iota != "") { + $this->db->where('COL_MY_IOTA', $row->station_country); + } + + if($row->station_sota != "") { + $this->db->where('COL_MY_SOTA_REF', $row->station_sota); + } + + $this->db->where('COL_MY_COUNTRY', $row->station_country); + + if( strpos($row->station_gridsquare, ',') !== false ) { + $this->db->where('COL_MY_VUCC_GRIDS', $row->station_gridsquare); + } else { + $this->db->where('COL_MY_GRIDSQUARE', $row->station_gridsquare); + } + + $this->db->update($this->config->item('table_name'), $data); + + $str = $this->db->last_query(); + + } + + function profile_exists() { + $query = $this->db->get('station_profile'); + if($query->num_rows() >= 1) { + return 1; + } else { + return 0; + } + } + } ?> \ No newline at end of file diff --git a/application/views/station_profile/index.php b/application/views/station_profile/index.php index 89acfa6a..efd9b91b 100644 --- a/application/views/station_profile/index.php +++ b/application/views/station_profile/index.php @@ -13,46 +13,71 @@
-
Lets Explore Operating Locations
-

Station Profiles define locations of operating positions, useful for portable operating or using a friends QTH.

+

Station Profiles define locations of operating, useful for portable operating or using a friends QTH.

+

Within Cloudlog these act in a similar way to logbooks, a Station Profile keeps a set of QSOs together.

num_rows() > 0) { ?> + + + + + + + + + - + result() as $row) { ?> - + + - + - + +
Profile NameStation Callsign Country Gridsquare City IOTA SOTACnty CQ ITU
station_profile_name;?>station_profile_name;?> (#station_id;?>)station_callsign;?> station_country;?> station_gridsquare;?> station_city;?> station_iota;?> station_sota;?>station_cnty;?> station_cq;?> station_itu;?> + station_active != 1) { ?> + station_id; ?>" class="btn btn-outline-secondary btn-sm btn-sm" onclick="return confirm('Are you sure you want to make logbook station_profile_name; ?> the active logbook?');">Set Active + + Active Logbook + + + + Reassign + + station_id; ?>" class="btn btn-danger" onclick="return confirm('Are you sure you want delete QSO station_profile_name; ?>?');"> Delete
-

Create a Station Location

+

Create a Station Profile