');
+ $(".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('