mirror of
https://github.com/wavelog/wavelog.git
synced 2026-03-22 10:24:14 +00:00
[Sat TLE] Manual upload
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -83,9 +83,9 @@
|
||||
?>
|
||||
<?php echo '<td style="text-align: center; vertical-align: middle;">';
|
||||
if ($sat->updated != null) {
|
||||
echo '<span class="badge bg-success" data-bs-toggle="tooltip" title="Last TLE updated was ' . date($custom_date_format . " H:i", strtotime($sat->updated)) . '">'.__("Yes").'</span>';
|
||||
echo '<button class="btn btn-sm btn-success" onclick="editTle(' . $sat->id . ');" data-bs-toggle="tooltip" title="Last TLE updated was ' . date($custom_date_format . " H:i", strtotime($sat->updated)) . '">'.__("Yes").'</i></button>';
|
||||
} else {
|
||||
echo '<span class="badge bg-danger">'.__("No").'</span>';
|
||||
echo '<button class="btn btn-sm btn-danger" onclick="editTle(' . $sat->id . ');">'.__("No").'</button>';
|
||||
}
|
||||
|
||||
echo '</td>';
|
||||
|
||||
13
application/views/satellite/tleinfo.php
Normal file
13
application/views/satellite/tleinfo.php
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
|
||||
<div class="tleinfo">
|
||||
<?php
|
||||
if ($tleinfo) {
|
||||
echo 'TLE information for ' . $satinfo[0]->name . ' (last updated: ' . date($custom_date_format . " H:i", strtotime($tleinfo->updated)) . ')' ;
|
||||
echo '<br /><br /><pre>' . $tleinfo->tle . '</pre>';
|
||||
echo '<button class="btn btn-sm btn-danger deletetlebutton" onclick="deleteTle(' . $satinfo[0]->id . ');">'.__("Delete TLE"). '</button>';
|
||||
} else {
|
||||
echo 'No TLE information found for ' . $satinfo[0]->name;
|
||||
echo '<br /><br /><button class="btn btn-sm btn-success addtlebutton" onclick="addTle(' . $satinfo[0]->id . ');">'.__("Add TLE"). '</button>';
|
||||
} ?>
|
||||
</div>
|
||||
@@ -30,6 +30,153 @@ $(document).ready(function () {
|
||||
return $("<textarea/>").text(out).html();
|
||||
}
|
||||
|
||||
function editTle(id) {
|
||||
$.ajax({
|
||||
url: base_url + 'index.php/satellite/editTleDialog',
|
||||
type: 'post',
|
||||
data: {
|
||||
'id': id
|
||||
},
|
||||
success: function (html) {
|
||||
BootstrapDialog.show({
|
||||
title: 'Edit satellite TLE',
|
||||
size: BootstrapDialog.SIZE_NORMAL,
|
||||
cssClass: 'create-band-dialog',
|
||||
nl2br: false,
|
||||
message: html,
|
||||
buttons: [{
|
||||
label: lang_admin_close,
|
||||
action: function (dialogItself) {
|
||||
dialogItself.close();
|
||||
location.reload();
|
||||
}
|
||||
}]
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function saveTle(id) {
|
||||
$('.alert').remove();
|
||||
var tle = document.getElementById('tle-input-' + id).value.trim();
|
||||
var validation = validateTLE(tle);
|
||||
|
||||
if (validation !== true) {
|
||||
$(".bootstrap-dialog-message").prepend('<div class="alert alert-danger">TLE Validation Failed: ' + validation + '</div>');
|
||||
return;
|
||||
}
|
||||
console.log("Saving TLE:", tle);
|
||||
$.ajax({
|
||||
url: base_url + 'index.php/satellite/saveTle',
|
||||
type: 'post',
|
||||
data: {
|
||||
'id': id,
|
||||
'tle': tle
|
||||
},
|
||||
success: function (html) {
|
||||
$(".bootstrap-dialog-message").prepend('<div class="alert alert-success">TLE saved.</div>');
|
||||
$(".tleinfo").remove();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function tleChecksum(line) {
|
||||
let sum = 0;
|
||||
|
||||
// Process only the first 68 characters
|
||||
for (let i = 0; i < 68; i++) {
|
||||
let char = line[i];
|
||||
if (!isNaN(char) && char !== ' ') {
|
||||
sum += parseInt(char);
|
||||
} else if (char === '-') {
|
||||
sum += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Convert last character (checksum) to an integer
|
||||
let expectedChecksum = parseInt(line[68]);
|
||||
return sum % 10 === expectedChecksum;
|
||||
}
|
||||
|
||||
function validateTLE(tle) {
|
||||
const lines = tle.trim().split("\n");
|
||||
|
||||
// Must have either 2 or 3 lines
|
||||
if (lines.length < 2 || lines.length > 3) {
|
||||
return "Invalid TLE format: Must have 2 or 3 lines.";
|
||||
}
|
||||
|
||||
let line1, line2, line3;
|
||||
|
||||
if (lines.length === 3) {
|
||||
line1 = lines[0].trim(); // Name (optional)
|
||||
line2 = lines[1].trim(); // First data line
|
||||
line3 = lines[2].trim(); // Second data line
|
||||
} else {
|
||||
line1 = null; // No name
|
||||
line2 = lines[0].trim();
|
||||
line3 = lines[1].trim();
|
||||
}
|
||||
|
||||
// Check if the first data line starts with '1' and has 69 characters
|
||||
if (!line2.startsWith('1') || line2.length !== 69) {
|
||||
return "Invalid Line 1: Must start with '1' and be 69 characters long.";
|
||||
}
|
||||
|
||||
// Check if the second data line starts with '2' and has 69 characters
|
||||
if (!line3.startsWith('2') || line3.length !== 69) {
|
||||
return "Invalid Line 2: Must start with '2' and be 69 characters long.";
|
||||
}
|
||||
|
||||
// Validate checksum
|
||||
if (!tleChecksum(line2)) {
|
||||
return "Checksum error on Line 1.";
|
||||
}
|
||||
if (!tleChecksum(line3)) {
|
||||
return "Checksum error on Line 2.";
|
||||
}
|
||||
|
||||
return true; // Valid TLE
|
||||
}
|
||||
|
||||
function deleteTle(id) {
|
||||
BootstrapDialog.confirm({
|
||||
title: "DANGER",
|
||||
message: "Warning! Are you sure you want to delete TLE for this satellite?",
|
||||
type: BootstrapDialog.TYPE_DANGER,
|
||||
closable: true,
|
||||
draggable: true,
|
||||
btnOKClass: 'btn-danger',
|
||||
callback: function(result) {
|
||||
if (result) {
|
||||
$.ajax({
|
||||
url: base_url + 'index.php/satellite/deleteTle',
|
||||
type: 'post',
|
||||
data: {
|
||||
'id': id
|
||||
},
|
||||
success: function(data) {
|
||||
$(".bootstrap-dialog-message").prepend('<div class="alert alert-danger">The TLE has been deleted!</div>');
|
||||
$(".tleinfo").remove();
|
||||
},
|
||||
error: function() {
|
||||
$(".bootstrap-dialog-message").prepend('<div class="alert alert-danger">The TLE could not be deleted. Please try again!</div>');
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function addTle(id) {
|
||||
$(".addtlebutton").remove();
|
||||
$(".tleinfo").append(
|
||||
'<div class="tle-input-group">' +
|
||||
'<textarea type="text" class="form-control tle-input" id="tle-input-' + id + '" placeholder="Paste TLE here..." rows="5"></textarea>' +
|
||||
'<br /><button class="btn btn-sm btn-primary savetlebutton" onclick="saveTle(' + id + ');">Save TLE</button>' +
|
||||
'</div>'
|
||||
);
|
||||
}
|
||||
|
||||
function createSatelliteDialog() {
|
||||
$.ajax({
|
||||
|
||||
Reference in New Issue
Block a user