From a8be39f0f1f2fb8658461c575fb1b3fa75c2c32f Mon Sep 17 00:00:00 2001 From: Andreas Kristiansen <6977712+AndreasK79@users.noreply.github.com> Date: Thu, 3 Apr 2025 11:24:17 +0200 Subject: [PATCH] [Sat TLE] Manual upload --- application/controllers/Satellite.php | 39 +++++++ application/models/Satellite_model.php | 29 ++++- application/views/satellite/index.php | 4 +- application/views/satellite/tleinfo.php | 13 +++ assets/js/sections/satellite.js | 147 ++++++++++++++++++++++++ 5 files changed, 229 insertions(+), 3 deletions(-) create mode 100644 application/views/satellite/tleinfo.php diff --git a/application/controllers/Satellite.php b/application/controllers/Satellite.php index dcd12e7ac..9c795660e 100644 --- a/application/controllers/Satellite.php +++ b/application/controllers/Satellite.php @@ -547,4 +547,43 @@ class Satellite extends CI_Controller { $this->load->view('satellite/satinfo', $data); } + + public function editTleDialog() { + if($this->session->userdata('user_date_format')) { + // If Logged in and session exists + $custom_date_format = $this->session->userdata('user_date_format'); + } else { + // Get Default date format from /config/wavelog.php + $custom_date_format = $this->config->item('qso_date_format'); + } + + $data['custom_date_format'] = $custom_date_format; + + $id = $this->security->xss_clean($this->input->post('id', true)); + $this->load->model('satellite_model'); + + $data['satinfo'] = $this->satellite_model->getsatellite($id)->result(); + $data['tleinfo'] = $this->satellite_model->get_tle($data['satinfo'][0]->name); + + $this->load->view('satellite/tleinfo', $data); + } + + public function deleteTle() { + if(!$this->user_model->authorize(99)) { $this->session->set_flashdata('error', __("You're not allowed to do that!")); redirect('dashboard'); } + + $id = $this->input->post('id', true); + $this->load->model('satellite_model'); + + $data['satinfo'] = $this->satellite_model->deleteTle($id); + } + + public function saveTle() { + if(!$this->user_model->authorize(99)) { $this->session->set_flashdata('error', __("You're not allowed to do that!")); redirect('dashboard'); } + + $id = $this->input->post('id', true); + $tle = $this->input->post('tle', true); + $this->load->model('satellite_model'); + + $this->satellite_model->saveTle($id, $tle); + } } diff --git a/application/models/Satellite_model.php b/application/models/Satellite_model.php index 1adb85a86..899ce0ad7 100644 --- a/application/models/Satellite_model.php +++ b/application/models/Satellite_model.php @@ -62,6 +62,33 @@ class Satellite_model extends CI_Model { $this->db->delete('satellite', array('id' => $clean_id)); } + + function deleteTle($id) { + // Delete TLE + $this->db->delete('tle', array('satelliteid' => $id)); + } + + function saveTle($id, $tle) { + $tlelines = explode("\n", trim($tle)); // Trim to remove extra spaces or newlines + $lineCount = count($tlelines); + + if ($lineCount === 3) { + $tleline1 = trim($tlelines[1]); // First data line + $tleline2 = trim($tlelines[2]); // Second data line + } else { + $tleline1 = trim($tlelines[0]); + $tleline2 = trim($tlelines[1]); + } + + $data = array( + 'satelliteid' => $id, + 'tle' => $tleline1 . "\n" . $tleline2, + ); + $this->db->insert('tle', $data); + $insert_id = $this->db->insert_id(); + return $insert_id; + } + function deleteSatMode($id) { // Clean ID $clean_id = $this->security->xss_clean($id); @@ -162,7 +189,7 @@ class Satellite_model extends CI_Model { } function get_tle($sat) { - $this->db->select('satellite.name AS satellite, tle.tle'); + $this->db->select('satellite.name AS satellite, tle.tle, tle.updated'); $this->db->join('tle', 'satellite.id = tle.satelliteid'); $this->db->where('name', $sat); $query = $this->db->get('satellite'); diff --git a/application/views/satellite/index.php b/application/views/satellite/index.php index 107a75211..c08e3610d 100644 --- a/application/views/satellite/index.php +++ b/application/views/satellite/index.php @@ -83,9 +83,9 @@ ?> '; if ($sat->updated != null) { - echo 'updated)) . '">'.__("Yes").''; + echo ''; } else { - echo ''.__("No").''; + echo ''; } echo ''; diff --git a/application/views/satellite/tleinfo.php b/application/views/satellite/tleinfo.php new file mode 100644 index 000000000..2140672cb --- /dev/null +++ b/application/views/satellite/tleinfo.php @@ -0,0 +1,13 @@ + + +
' . $tleinfo->tle . ''; + echo ''; + } else { + echo 'No TLE information found for ' . $satinfo[0]->name; + echo '