From f0aae6b97b0b0cb03a9e40ee72ff49d97fc63469 Mon Sep 17 00:00:00 2001
From: phl0
Date: Fri, 3 May 2024 10:18:38 +0200
Subject: [PATCH] Use JSON data for hams.at list
---
application/controllers/Hamsat.php | 113 +++++++++++++++++-
application/views/components/hamsat/table.php | 19 +--
application/views/hamsat/index.php | 37 +++++-
3 files changed, 153 insertions(+), 16 deletions(-)
diff --git a/application/controllers/Hamsat.php b/application/controllers/Hamsat.php
index 769a614b9..7ea016140 100644
--- a/application/controllers/Hamsat.php
+++ b/application/controllers/Hamsat.php
@@ -13,11 +13,112 @@ class Hamsat extends CI_Controller {
if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); }
}
- public function index() {
- // Load public view
- $data['page_title'] = "Hamsat - Satellite Roving";
- $this->load->view('interface_assets/header', $data);
- $this->load->view('/hamsat/index');
- $this->load->view('interface_assets/footer');
+ public function index() {
+ $data['scripts'] = [
+ 'assets/js/sections/hamsat.js?' . filemtime(realpath(__DIR__ . "/../../assets/js/sections/hamsat.js")),
+ ];
+
+ $hkey_opt=$this->user_options_model->get_options('hamsat',array('option_name'=>'hamsat_key','option_key'=>'workable'))->result();
+ if (count($hkey_opt)>0) {
+ $data['user_hamsat_workable_only'] = $hkey_opt[0]->option_value;
+ } else {
+ $data['user_hamsat_workable_only'] = 0;
+ }
+
+ // Load public view
+ $data['page_title'] = "Hamsat - Satellite Roving";
+ $this->load->view('interface_assets/header', $data);
+ $this->load->view('/hamsat/index');
+ $this->load->view('interface_assets/footer');
+ }
+
+ public function activations() {
+ $this->load->model("user_options_model");
+ $this->load->model("logbooks_model");
+ $logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
+ $this->load->model('logbook_model');
+ $hkey_opt=$this->user_options_model->get_options('hamsat',array('option_name'=>'hamsat_key','option_key'=>'api'))->result();
+ if (count($hkey_opt)>0) {
+ $data['user_hamsat_key'] = $hkey_opt[0]->option_value;
+ } else {
+ $data['user_hamsat_key']='';
+ }
+ $this->load->model('stations');
+ $my_gridsquare = strtoupper($this->stations->find_gridsquare());
+
+ // 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');
+ }
+ $url = 'https://hams.at/api/alerts/upcoming';
+ if ($data['user_hamsat_key'] ?? '' != '') {
+ $options = array(
+ 'http' => array(
+ 'method' => 'GET',
+ 'header' => "Authorization: Bearer ".$data['user_hamsat_key']."\r\n"
+ )
+ );
+ $context = stream_context_create($options);
+ $json = file_get_contents($url, false, $context);
+ } else {
+ $json = file_get_contents($url);
+ }
+ $hkey_opt=$this->user_options_model->get_options('hamsat',array('option_name'=>'hamsat_key','option_key'=>'workable'))->result();
+ if (count($hkey_opt)>0) {
+ $data['user_hamsat_workable_only'] = $hkey_opt[0]->option_value;
+ } else {
+ $data['user_hamsat_workable_only'] = 0;
+ }
+
+ $decoded_json = json_decode($json);
+ for ($i=0; $i < count($decoded_json->data); $i++) {
+ $aos_at = strtotime($decoded_json->data[$i]->aos_at);
+ $los_at = strtotime($decoded_json->data[$i]->los_at);
+ $decoded_json->data[$i]->aos_at_date = date($custom_date_format, $aos_at);
+ $decoded_json->data[$i]->aos_to_los = date("H:i:s", $aos_at).' - '.date("H:i:s", $los_at);
+
+ if ($this->logbook_model->check_if_callsign_worked_in_logbook($decoded_json->data[$i]->callsign, $logbooks_locations_array, "SAT")) {
+ $decoded_json->data[$i]->callsign_wkd = 1;
+ } else {
+ $decoded_json->data[$i]->callsign_wkd = 0;
+ }
+ $modeclass = '';
+ if ($decoded_json->data[$i]->mode == 'SSB' || $decoded_json->data[$i]->mode== 'CW') {
+ $modeclass = 'hamsatBgLin';
+ } else if ($decoded_json->data[$i]->mode == 'Data') {
+ $modeclass = 'hamsatBgData';
+ } else if ($decoded_json->data[$i]->mode == 'FM') {
+ $modeclass = 'hamsatBgFm';
+ }
+ $decoded_json->data[$i]->mode_class = $modeclass;
+ for($j = 0; $j < count($decoded_json->data[$i]->grids); $j++) {
+ $worked = $this->logbook_model->check_if_grid_worked_in_logbook($decoded_json->data[$i]->grids[$j], null, "SAT");
+ if ($worked->num_rows() != 0) {
+ $decoded_json->data[$i]->grids_wkd[$j] = 1;
+ } else {
+ $decoded_json->data[$i]->grids_wkd[$j] = 0;
+ }
+ }
+
+ $workable_start_at = strtotime($decoded_json->data[$i]->workable_start_at);
+ $workable_end_at = strtotime($decoded_json->data[$i]->workable_end_at);
+ $decoded_json->data[$i]->workable_from_to = date("H:i", $workable_start_at).' - '.date("H:i", $workable_end_at);
+
+ $decoded_json->data[$i]->sked = 'TEST';
+ if (strtoupper($decoded_json->data[$i]->satellite->name) == 'GREENCUBE') {
+ $decoded_json->data[$i]->sat_export_name = 'IO-117';
+ } else {
+ $decoded_json->data[$i]->sat_export_name = $decoded_json->data[$i]->satellite->name;
+ }
+ $decoded_json->data[$i]->my_gridsquare = $my_gridsquare;
+
+ }
+
+ header('Content-Type: application/json');
+ echo(json_encode($decoded_json->data));
}
}
diff --git a/application/views/components/hamsat/table.php b/application/views/components/hamsat/table.php
index cc20e3094..0b9344ecd 100644
--- a/application/views/components/hamsat/table.php
+++ b/application/views/components/hamsat/table.php
@@ -8,6 +8,7 @@
echo " All passes shown.";
}?>
+ Show All Passes
Private feed key empty. Please set the feed key in your profile.
@@ -43,7 +44,7 @@
session->userdata('user_date_format')) {
// If Logged in and session exists
@@ -52,12 +53,12 @@
// Get Default date format from /config/wavelog.php
$custom_date_format = $this->config->item('qso_date_format');
}
-
+
?>
-
+
-
+
@@ -96,13 +97,13 @@
} else if ($rove['mode'] == 'FM') {
$modeclass = 'hamsatBgFm';
}
-
+
?>
">= $rove['satellite']['name'] ?>
-
-
+
+
-
-
+
+
-
+
+ Hamsat - Satellite Rovers
+ This data is from https://hams.at/ .
+
+
+ Show All Passes
+
+
+
+ Private feed key empty. Please set the feed key in your profile.
+
+
+
+
+
+
+ Date
+ Time
+ Callsign
+ Comment
+ Satellite
+ Mode
+ Gridsquare(s)
+ Workable
+
+
+
+
+
+
+
+