diff --git a/application/config/migration.php b/application/config/migration.php
index f39a5837f..0e1107dd7 100644
--- a/application/config/migration.php
+++ b/application/config/migration.php
@@ -22,7 +22,7 @@ $config['migration_enabled'] = TRUE;
|
*/
-$config['migration_version'] = 229;
+$config['migration_version'] = 230;
/*
|--------------------------------------------------------------------------
diff --git a/application/controllers/Debug.php b/application/controllers/Debug.php
index 427a8f0d5..57ec55a31 100644
--- a/application/controllers/Debug.php
+++ b/application/controllers/Debug.php
@@ -102,6 +102,7 @@ class Debug extends CI_Controller
$data['scp_update'] = $this->cron_model->cron('update_update_clublog_scp')->row();
$data['sota_update'] = $this->cron_model->cron('update_update_sota')->row();
$data['wwff_update'] = $this->cron_model->cron('update_update_wwff')->row();
+ $data['tle_update'] = $this->cron_model->cron('update_update_tle')->row();
$data['page_title'] = __("Debug");
@@ -224,7 +225,7 @@ class Debug extends CI_Controller
// Show success message
$this->session->set_flashdata('success', __("Wavelog was updated successfully!"));
-
+
} catch (\Throwable $th) {
log_message("Error","Error at selfupdating");
}
diff --git a/application/controllers/Satellite.php b/application/controllers/Satellite.php
index 32d0979db..ab39acb7d 100644
--- a/application/controllers/Satellite.php
+++ b/application/controllers/Satellite.php
@@ -21,6 +21,16 @@ class Satellite extends CI_Controller {
$pageData['satellites'] = $this->satellite_model->get_all_satellites();
+ 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');
+ }
+
+ $pageData['custom_date_format'] = $custom_date_format;
+
$footerData = [];
$footerData['scripts'] = [
'assets/js/sections/satellite.js?' . filemtime(realpath(__DIR__ . "/../../assets/js/sections/satellite.js")),
@@ -285,7 +295,7 @@ class Satellite extends CI_Controller {
$tle = new Predict_TLE($sat_tle->satellite, $temp[0], $temp[1]); // Instantiate it
$sat = new Predict_Sat($tle); // Load up the satellite data
- $now = Predict_Time::get_current_daynum(); // get the current time as Julian Date (daynum)
+ $now = $this->get_daynum_from_date($this->security->xss_clean($this->input->post('date'))); // get the current time as Julian Date (daynum)
// You can modify some preferences in Predict(), the defaults are below
//
@@ -316,4 +326,17 @@ class Satellite extends CI_Controller {
$data['format'] = $format;
$this->load->view('satellite/passtable', $data);
}
+
+ public static function get_daynum_from_date($date) {
+ // Convert a Y-m-d date to a day number
+
+ // Convert date to Unix timestamp
+ $timestamp = strtotime($date);
+ if ($timestamp === false) {
+ throw new Exception("Invalid date format. Expected Y-m-d.");
+ }
+
+ // Calculate the day number
+ return Predict_Time::unix2daynum($timestamp, 0);
+ }
}
diff --git a/application/controllers/Update.php b/application/controllers/Update.php
index b3b3ef253..733f9a17e 100644
--- a/application/controllers/Update.php
+++ b/application/controllers/Update.php
@@ -390,65 +390,16 @@ class Update extends CI_Controller {
}
public function update_tle() {
- $mtime = microtime();
- $mtime = explode(" ",$mtime);
- $mtime = $mtime[1] + $mtime[0];
- $starttime = $mtime;
-
- $url = 'https://www.amsat.org/tle/dailytle.txt';
- $curl = curl_init($url);
-
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
-
- $response = curl_exec($curl);
-
- $count = 0;
-
- if ($response === false) {
- echo 'Error: ' . curl_error($curl);
- } else {
- $this->db->empty_table("tle");
- // Split the response into an array of lines
- $lines = explode("\n", $response);
-
- $satname = '';
- $tleline1 = '';
- $tleline2 = '';
- // Process each line
- for ($i = 0; $i < count($lines); $i += 3) {
- $count++;
- // Check if there are at least three lines remaining
- if (isset($lines[$i], $lines[$i + 1], $lines[$i + 2])) {
- // Get the three lines
- $satname = $lines[$i];
- $tleline1 = $lines[$i + 1];
- $tleline2 = $lines[$i + 2];
- $sql = "INSERT INTO tle (satelliteid, tle) select id, ? from satellite where name = ? or displayname = ?";
- $this->db->query($sql,array($tleline1."\n".$tleline2,$satname,$satname));
- }
- }
- }
-
- curl_close($curl);
-
- $mtime = microtime();
- $mtime = explode(" ",$mtime);
- $mtime = $mtime[1] + $mtime[0];
- $endtime = $mtime;
- $totaltime = ($endtime - $starttime);
- echo "This page was created in ".$totaltime." seconds
";
- echo "Records inserted: " . $count . "
";
- $datetime = new DateTime("now", new DateTimeZone('UTC'));
- $datetime = $datetime->format('Ymd h:i');
- $this->optionslib->update('tle_update', $datetime , 'no');
+ $this->load->model('Update_model');
+ $result = $this->Update_model->tle();
+ echo $result;
}
function version_check() {
// set the last run in cron table for the correct cron id
$this->load->model('cron_model');
$this->cron_model->set_last_run($this->router->class . '_' . $this->router->method);
-
+
$this->load->model('Update_model');
$this->Update_model->update_check();
}
diff --git a/application/migrations/230_tle_cron.php b/application/migrations/230_tle_cron.php
new file mode 100644
index 000000000..94d1e7b6d
--- /dev/null
+++ b/application/migrations/230_tle_cron.php
@@ -0,0 +1,50 @@
+db->table_exists('tle')) {
+ $this->db->query("DROP TABLE tle");
+ }
+ $this->db->query("CREATE TABLE `tle` (`id` int(6) unsigned NOT NULL AUTO_INCREMENT, `satelliteid` int(6) unsigned NOT NULL,
+ `tle` text DEFAULT NULL, `updated` timestamp NOT NULL DEFAULT current_timestamp(),
+ PRIMARY KEY (`satelliteid`), UNIQUE KEY `tle_unique_id` (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4");
+ $this->dbtry("ALTER TABLE tle ADD CONSTRAINT tle_satellite_FK FOREIGN KEY (satelliteid) REFERENCES satellite(id) ON DELETE CASCADE");
+ if ($this->chk4cron('update_update_tle') == 0) {
+ $data = array(
+ array(
+ 'id' => 'update_update_tle',
+ 'enabled' => '0',
+ 'status' => 'disabled',
+ 'description' => 'Update TLE for satellites',
+ 'function' => 'index.php/update/update_tle',
+ 'expression' => '45 4 * * *',
+ 'last_run' => null,
+ 'next_run' => null
+ ));
+ $this->db->insert_batch('cron', $data);
+ }
+
+ }
+
+ public function down() {
+ if ($this->chk4cron('update_tle') > 0) {
+ $this->db->query("delete from cron where id='update_update_tle'");
+ }
+ // No way back to tle-table
+ }
+
+ function chk4cron($cronkey) {
+ $query = $this->db->query("select count(id) as cid from cron where id=?",$cronkey);
+ $row = $query->row();
+ return $row->cid ?? 0;
+ }
+
+ function dbtry($what) {
+ try {
+ $this->db->query($what);
+ } catch (Exception $e) {
+ log_message("error", "Something gone wrong while altering FKs: ".$e." // Executing: ".$this->db->last_query());
+ }
+ }
+}
diff --git a/application/models/Satellite_model.php b/application/models/Satellite_model.php
index 503391419..7e2940d51 100644
--- a/application/models/Satellite_model.php
+++ b/application/models/Satellite_model.php
@@ -3,10 +3,11 @@
class Satellite_model extends CI_Model {
function get_all_satellites() {
- $sql = "select satellite.id, satellite.name as satname, group_concat(distinct satellitemode.name separator ', ') as modename, satellite.displayname, satellite.orbit, satellite.lotw as lotw
+ $sql = "select satellite.id, satellite.name as satname, group_concat(distinct satellitemode.name separator ', ') as modename, satellite.displayname, satellite.orbit, satellite.lotw as lotw, tle.updated
from satellite
left outer join satellitemode on satellite.id = satellitemode.satelliteid
- group by satellite.name, satellite.displayname, satellite.orbit, satellite.id";
+ left outer join tle on satellite.id = tle.satelliteid
+ group by satellite.name, satellite.displayname, satellite.orbit, satellite.id, tle.updated";
return $this->db->query($sql)->result();
}
diff --git a/application/models/Update_model.php b/application/models/Update_model.php
index 7b432932b..ad24d3335 100644
--- a/application/models/Update_model.php
+++ b/application/models/Update_model.php
@@ -306,4 +306,66 @@ class Update_model extends CI_Model {
}
}
}
+
+ function tle() {
+ // set the last run in cron table for the correct cron id
+ $this->load->model('cron_model');
+ $this->cron_model->set_last_run($this->router->class . '_' . $this->router->method);
+ $mtime = microtime();
+ $mtime = explode(" ",$mtime);
+ $mtime = $mtime[1] + $mtime[0];
+ $starttime = $mtime;
+
+ $url = 'https://www.amsat.org/tle/dailytle.txt';
+ $curl = curl_init($url);
+
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
+
+ $response = curl_exec($curl);
+
+ $count = 0;
+
+ if ($response === false) {
+ echo 'Error: ' . curl_error($curl);
+ } else {
+ // Split the response into an array of lines
+ $lines = explode("\n", $response);
+
+ $satname = '';
+ $tleline1 = '';
+ $tleline2 = '';
+ // Process each line
+ for ($i = 0; $i < count($lines); $i += 3) {
+ $count++;
+ // Check if there are at least three lines remaining
+ if (isset($lines[$i], $lines[$i + 1], $lines[$i + 2])) {
+ // Get the three lines
+ $satname = $lines[$i];
+ $tleline1 = $lines[$i + 1];
+ $tleline2 = $lines[$i + 2];
+ $sql = "
+ INSERT INTO tle (satelliteid, tle)
+ SELECT id, ?
+ FROM satellite
+ WHERE name = ? OR displayname = ?
+ ON DUPLICATE KEY UPDATE
+ tle = VALUES(tle), updated = now()
+ ";
+ $this->db->query($sql, array($tleline1 . "\n" . $tleline2, $satname, $satname));
+ }
+ }
+ }
+
+ curl_close($curl);
+
+ $mtime = microtime();
+ $mtime = explode(" ",$mtime);
+ $mtime = $mtime[1] + $mtime[0];
+ $endtime = $mtime;
+ $totaltime = ($endtime - $starttime);
+ echo "This page was created in ".$totaltime." seconds
";
+ echo "Records inserted: " . $count . "
";
+ }
+
}
diff --git a/application/views/debug/index.php b/application/views/debug/index.php
index 6a318b590..3f3d17018 100644
--- a/application/views/debug/index.php
+++ b/application/views/debug/index.php
@@ -549,6 +549,11 @@