Use JSON data for hams.at list

This commit is contained in:
phl0
2024-05-03 10:18:38 +02:00
parent 7a28b9eafc
commit f0aae6b97b
3 changed files with 153 additions and 16 deletions

View File

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

View File

@@ -8,6 +8,7 @@
echo " All passes shown.";
}?>
</p>
<button type="button" onclick="loadHamsAt();" class="btn btn-info btn-sm">Show All Passes</button>
<?php if ($user_hamsat_workable_only && $user_hamsat_key == '') { ?>
<div class="alert alert-warning" role="warning">
Private feed key empty. Please set the feed key in your profile.
@@ -43,7 +44,7 @@
<tr>
<td>
<?php
// Get Date format
if ($this->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');
}
?>
<?php $timestamp = strtotime($rove['aos_at']);
echo date($custom_date_format, $timestamp); ?>
</td>
<td>
<?php echo date("H:i:s", $timestamp)." - ".date("H:i:s", strtotime($rove['los_at'])); ?>
@@ -96,13 +97,13 @@
} else if ($rove['mode'] == 'FM') {
$modeclass = 'hamsatBgFm';
}
?>
<td><span data-bs-toggle="tooltip" title="<?php if ($rove['mhz'] != '') { printf("%.3f", $rove['mhz']); echo " ".$direction ?? ''; } ?>"><?= $rove['satellite']['name'] ?></span></td>
<td><span title="<?php echo $rove['mode']; ?>" class="badge <?php echo $modeclass; ?>"><?php echo $rove['mode']; ?></span></td>
<td>
<?php
// Load the logbook model and call check_if_grid_worked_in_logbook
foreach ($rove['grids'] as $grid) {
@@ -114,8 +115,8 @@
}
}
?>
</td>
<td>
<?php

View File

@@ -1,3 +1,38 @@
<div class="container">
<div id="hamsat_display" hx-get="<?php echo site_url('components'); ?>" hx-trigger="load, every 60s"></div>
<br>
<h2>Hamsat - Satellite Rovers</h2>
<p>This data is from <a target="_blank" href="https://hams.at/">https://hams.at/</a>.
<?php if ($user_hamsat_workable_only) {
echo " Only workable passes shown.";
} else {
echo " All passes shown.";
}?>
</p>
<button type="button" onclick="loadHamsAt();" class="btn btn-info btn-sm">Show All Passes</button>
<p>
<?php if ($user_hamsat_workable_only && $user_hamsat_key == '') { ?>
<div class="alert alert-warning" role="warning">
Private feed key empty. Please set the feed key in your profile.
</div>
<?php } else { ?>
<!-- <table style="width:100%" class="table-sm table table-hover table-striped table-condensed text-center" id="activationsList">-->
<table style="width:100%" class="table table-hover table-striped table-condensed text-center" id="activationsList">
<thead>
<tr>
<th>Date</th>
<th>Time</th>
<th>Callsign</th>
<th>Comment</th>
<th>Satellite</th>
<th>Mode</th>
<th>Gridsquare(s)</th>
<th>Workable</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<?php } ?>
</div>