Skip to content

Commit

Permalink
Merge pull request #65 from wavelog/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
m0urs authored Dec 12, 2024
2 parents ba9dc0d + ab7ef0a commit 212b15f
Show file tree
Hide file tree
Showing 61 changed files with 15,437 additions and 11,151 deletions.
2 changes: 1 addition & 1 deletion application/config/migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
|
*/

$config['migration_version'] = 229;
$config['migration_version'] = 230;

/*
|--------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion application/controllers/Debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public function index() {
$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");

Expand Down Expand Up @@ -224,7 +225,7 @@ public function selfupdate() {

// Show success message
$this->session->set_flashdata('success', __("Wavelog was updated successfully!"));

} catch (\Throwable $th) {
log_message("Error","Error at selfupdating");
}
Expand Down
1 change: 1 addition & 0 deletions application/controllers/Lotw.php
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ function lotw_download($sync_user_id = null) {
foreach ($query->result() as $user) {
if ( ($sync_user_id != null) && ($sync_user_id != $user->user_id) ) { continue; }
$station_ids=$this->Stations->all_station_ids_of_user($user->user_id);
if ($station_ids == '') { continue; } // User has no Station-ID! next one

// Validate that LoTW credentials are not empty
// TODO: We don't actually see the error message
Expand Down
94 changes: 94 additions & 0 deletions application/controllers/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,100 @@ function sendTestMail() {
redirect('/options/email');
}

// function used to display the /maptiles url in global options
function maptiles() {
$data['page_title'] = __("Wavelog Options");
$data['sub_heading'] = __("Maptiles Server");

$data['maptile_server_url'] = $this->optionslib->get_option('map_tile_server') ?? 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
$data['maptile_server_url_dark'] = $this->optionslib->get_option('map_tile_server_dark') ?? 'https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png';
$data['subdomain_system'] = $this->optionslib->get_option('map_tile_subdomains') ?? 'abc';
$map_tile_server_copyright = $this->optionslib->get_option('map_tile_server_copyright') ?? 'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a>';
preg_match('/<a href="([^"]+)">([^<]+)<\/a>/', $map_tile_server_copyright, $matches);
$data['copyright_url'] = $matches[1] ?? 'https://www.openstreetmap.org/';
$data['copyright_text'] = $matches[2] ?? 'OpenStreetMap';

$this->load->view('interface_assets/header', $data);
$this->load->view('options/maptiles');
$this->load->view('interface_assets/footer');
}

// Handles saving the Maptiles options to the options system.
function maptiles_save() {

$data['page_title'] = __("Wavelog Options");
$data['sub_heading'] = __("Maptiles Server");

$this->load->helper(array('form', 'url'));

$this->load->library('form_validation');

$this->form_validation->set_rules('maptile_server_url', 'URL of Maptile Server', 'required');
$this->form_validation->set_rules('maptile_server_url_dark', 'URL of Dark Maptile Server', 'required');
$this->form_validation->set_rules('subdomain_system', 'Subdomains for Loadbalancing', 'required');
$this->form_validation->set_rules('copyright_url', 'URL for Copyright', 'required');
$this->form_validation->set_rules('copyright_text', 'Text for Copyright', 'required');

if ($this->form_validation->run() == FALSE) {

$this->maptiles();

} else {
$saved = false;
if ($this->input->post('reset_defaults') == '1') {
$map_tile_server_copyright = 'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a>';
$saved = $this->optionslib->update('map_tile_server', 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', 'yes');
$saved = $this->optionslib->update('map_tile_server_dark', 'https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png', 'yes');
$saved = $this->optionslib->update('map_tile_subdomains', 'abc', 'yes');
} else {
$map_tile_server_copyright = 'Map data &copy; <a href="' . $this->input->post('copyright_url', true) . '">' . $this->input->post('copyright_text', true) . '</a>';
$saved = $this->optionslib->update('map_tile_server', $this->input->post('maptile_server_url', true), 'yes');
$saved = $this->optionslib->update('map_tile_server_dark', $this->input->post('maptile_server_url_dark', true), 'yes');
$saved = $this->optionslib->update('map_tile_subdomains', $this->input->post('subdomain_system', true), 'yes');
}
$saved = $this->optionslib->update('map_tile_server_copyright', $map_tile_server_copyright, 'yes');

// Also clean up static map images
if (!$this->load->is_loaded('staticmap_model')) {
$this->load->model('staticmap_model');
}
if (!$this->load->is_loaded('stations')) {
$this->load->model('stations');
}
$station_ids = explode(',',$this->stations->all_station_ids_of_user());
foreach ($station_ids as $station_id) {
$this->staticmap_model->remove_static_map_image($station_id);
log_message('debug', 'Removed static map image for station ID ' . $station_id);
}
// also remove the tilecache
$cachepath = $this->config->item('cache_path') == '' ? APPPATH . 'cache/' : $this->config->item('cache_path');
$cacheDir = $cachepath . "tilecache/";
$tilecache_warning = false;
if (function_usable('exec')) {
try {
if (is_dir($cacheDir)) {
exec('rm -rf ' . $cacheDir);
}
} catch (\Throwable $th) {
$tilecache_warning = true;
}
} else {
$tilecache_warning = true;
}
if ($tilecache_warning) {
$this->session->set_flashdata('warning', sprintf(__("Maptile cache could not be removed. Delete the folder manually. Path: %s"), str_replace(FCPATH, '', $cacheDir)));
log_message('debug', 'Maptile cache could not be removed. Delete the folder manually. Path: ' . str_replace(FCPATH, '', $cacheDir));
}
if($saved == true) {
$this->session->set_flashdata('success', __("Maptile Options saved!"));
} else {
$this->session->set_flashdata('error', __("Maptile Options could not be saved!"));
log_message('error', 'Maptile Options could not be saved!');
}
redirect('/options/maptiles');
}
}

// function used to display the /version_dialog url
function version_dialog() {

Expand Down
134 changes: 119 additions & 15 deletions application/controllers/Satellite.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ public function index()

$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")),
Expand Down Expand Up @@ -224,12 +234,32 @@ public function pass() {
$this->load->view('interface_assets/footer', $footerData);
}

public function searchpasses() {
public function searchPasses() {
if(!$this->user_model->authorize(3)) { $this->session->set_flashdata('error', __("You're not allowed to do that!")); redirect('dashboard'); }

try {
$result = $this->get_tle_for_predict();
$this->calcpass($result);
$tle = $this->get_tle_for_predict();
$yourgrid = $this->security->xss_clean($this->input->post('yourgrid'));
$altitude = $this->security->xss_clean($this->input->post('altitude'));
$date = $this->security->xss_clean($this->input->post('date'));
$minelevation = $this->security->xss_clean($this->input->post('minelevation'));
$timezone = $this->security->xss_clean($this->input->post('timezone'));
$data = $this->calcPass($tle, $yourgrid, $altitude, $date, $minelevation, $timezone);

$this->load->view('satellite/passtable', $data);
}
catch (Exception $e) {
header("Content-type: application/json");
echo json_encode(['ok' => 'Error', 'message' => $e->getMessage() . $e->getCode()]);
}
}

public function searchSkedPasses() {
if(!$this->user_model->authorize(3)) { $this->session->set_flashdata('error', __("You're not allowed to do that!")); redirect('dashboard'); }

try {
$tle = $this->get_tle_for_predict();
$this->calcSkedPass($tle);
}
catch (Exception $e) {
header("Content-type: application/json");
Expand All @@ -245,7 +275,7 @@ public function get_tle_for_predict() {
return $this->satellite_model->get_tle($sat);
}

function calcpass($sat_tle) {
function calcPass($sat_tle, $yourgrid, $altitude, $date, $minelevation, $timezone) {
if(!$this->user_model->authorize(3)) { $this->session->set_flashdata('error', __("You're not allowed to do that!")); redirect('dashboard'); }

require_once "./src/predict/Predict.php";
Expand All @@ -257,9 +287,9 @@ function calcpass($sat_tle) {
// The observer or groundstation is called QTH in ham radio terms
$predict = new Predict();
$qth = new Predict_QTH();
$qth->alt = $this->security->xss_clean($this->input->post('altitude')); // Altitude in meters
$qth->alt = $altitude; // Altitude in meters

$strQRA = $this->security->xss_clean($this->input->post('yourgrid'));
$strQRA = $yourgrid;

if ((strlen($strQRA) % 2 == 0) && (strlen($strQRA) <= 10)) { // Check if QRA is EVEN (the % 2 does that) and smaller/equal 8
$strQRA = strtoupper($strQRA);
Expand All @@ -275,7 +305,7 @@ function calcpass($sat_tle) {
if(!$this->load->is_loaded('Qra')) {
$this->load->library('Qra');
}
$homecoordinates = $this->qra->qra2latlong($this->security->xss_clean($this->input->post('yourgrid')));
$homecoordinates = $this->qra->qra2latlong($yourgrid);

$qth->lat = $homecoordinates[0];
$qth->lon = $homecoordinates[1];
Expand All @@ -285,11 +315,11 @@ function calcpass($sat_tle) {
$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($date); // get the current time as Julian Date (daynum)

// You can modify some preferences in Predict(), the defaults are below
//
$predict->minEle = intval($this->security->xss_clean($this->input->post('minelevation'))); // Minimum elevation for a pass
$predict->minEle = intval($minelevation); // Minimum elevation for a pass
$predict->timeRes = 1; // Pass details: time resolution in seconds
$predict->numEntries = 20; // Pass details: number of entries per pass
// $predict->threshold = -6; // Twilight threshold (sun must be at this lat or lower)
Expand All @@ -298,8 +328,6 @@ function calcpass($sat_tle) {
$results = $predict->get_passes($sat, $qth, $now, 1);
$filtered = $predict->filterVisiblePasses($results);

$zone = $this->security->xss_clean($this->input->post('timezone'));

// Get Date format
if ($this->session->userdata('user_date_format')) {
// If Logged in and session exists
Expand All @@ -309,11 +337,87 @@ function calcpass($sat_tle) {
$custom_date_format = $this->config->item('qso_date_format');
}

$format = $custom_date_format . ' H:i:s';
$data['format'] = $custom_date_format . ' H:i:s';

$data['filtered'] = $filtered;
$data['zone'] = $zone;
$data['format'] = $format;
$this->load->view('satellite/passtable', $data);
$data['zone'] = $timezone;

return $data;

}

function calcSkedPass($tle) {
if(!$this->user_model->authorize(3)) { $this->session->set_flashdata('error', __("You're not allowed to do that!")); redirect('dashboard'); }

$yourgrid = $this->security->xss_clean($this->input->post('yourgrid'));
$altitude = $this->security->xss_clean($this->input->post('altitude'));
$date = $this->security->xss_clean($this->input->post('date'));
$minelevation = $this->security->xss_clean($this->input->post('minelevation'));
$timezone = $this->security->xss_clean($this->input->post('timezone'));

$homePass = $this->calcPass($tle, $yourgrid, $altitude, $date, $minelevation, $timezone);

$skedgrid = $this->security->xss_clean($this->input->post('skedgrid'));
$minskedelevation = $this->security->xss_clean($this->input->post('minskedelevation'));

$skedPass = $this->calcPass($tle, $skedgrid, 0, $date, $minskedelevation, $timezone);

// Get Date format
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['format'] = $custom_date_format . ' H:i:s';

$data['overlaps'] = $this->findOverlaps($homePass, $skedPass);
$data['zone'] = $timezone;
$data['yourgrid'] = $yourgrid;
$data['skedgrid'] = $skedgrid;
$data['date'] = $date;
$data['custom_date_format'] = $custom_date_format;

$this->load->view('satellite/skedtable', $data);
}

function findOverlaps($homePass, $skedPass) {
$overlaps = []; // Store overlapping passes

foreach ($homePass['filtered'] as $pass1) {
foreach ($skedPass['filtered'] as $pass2) {
if ($this->checkOverlap($pass1, $pass2)) {
$overlaps[] = [
'grid1' => $pass1,
'grid2' => $pass2
];
}
}
}

return $overlaps;
}

function checkOverlap($pass1, $pass2) {
// Calculate the overlap condition
$start = max($pass1->visible_aos, $pass2->visible_aos); // Latest start time
$end = min($pass1->visible_los, $pass2->visible_los); // Earliest end time

return $start <= $end; // True if intervals overlap
}

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);
}
}
Loading

0 comments on commit 212b15f

Please sign in to comment.