kopia lustrzana https://github.com/magicbug/Cloudlog
Add filtering support to public gridsquare maps
Co-authored-by: magicbug <84308+magicbug@users.noreply.github.com>copilot/fix-3325
rodzic
081b2d5ee4
commit
251fe3cc35
|
@ -20,6 +20,9 @@ class Visitor extends CI_Controller {
|
|||
elseif($method == "satellites") {
|
||||
$this->satellites($method);
|
||||
}
|
||||
elseif($method == "getGridsjs") {
|
||||
$this->getGridsjs();
|
||||
}
|
||||
elseif($method == "search") {
|
||||
$this->search($method);
|
||||
}
|
||||
|
@ -226,36 +229,75 @@ class Visitor extends CI_Controller {
|
|||
|
||||
$this->load->model('gridmap_model');
|
||||
|
||||
$data['page_title'] = "Satellite Gridsquare Map";
|
||||
$data['page_title'] = "Public Gridsquare Map";
|
||||
|
||||
// Get available bands for this logbook
|
||||
$location_list = "'".implode("','",$logbooks_locations_array)."'";
|
||||
|
||||
// Get bands (excluding satellites)
|
||||
$bands_query = $this->db->query(
|
||||
"SELECT distinct LOWER(`COL_BAND`) as `COL_BAND` FROM `".$this->config->item('table_name')."` WHERE station_id in (" . $location_list . ") AND COL_PROP_MODE != \"SAT\" ORDER BY COL_BAND"
|
||||
);
|
||||
$bands = array();
|
||||
foreach($bands_query->result() as $row){
|
||||
array_push($bands, strtoupper($row->COL_BAND));
|
||||
}
|
||||
|
||||
// Check if satellites exist and add SAT band
|
||||
$sat_query = $this->db->query(
|
||||
"SELECT distinct LOWER(`COL_PROP_MODE`) as `COL_PROP_MODE` FROM `".$this->config->item('table_name')."` WHERE station_id in (" . $location_list . ") AND COL_PROP_MODE = \"SAT\""
|
||||
);
|
||||
if ($sat_query->num_rows() > 0) {
|
||||
array_push($bands, 'SAT');
|
||||
}
|
||||
|
||||
// Get available satellites
|
||||
$sats_query = $this->db->query(
|
||||
"SELECT distinct col_sat_name FROM ".$this->config->item('table_name')." WHERE station_id in (" . $location_list . ") and coalesce(col_sat_name, '') <> '' ORDER BY col_sat_name"
|
||||
);
|
||||
$sats_available = array();
|
||||
foreach($sats_query->result() as $row){
|
||||
array_push($sats_available, $row->col_sat_name);
|
||||
}
|
||||
|
||||
// Get available modes
|
||||
$modes_query = $this->db->query(
|
||||
"SELECT distinct col_mode FROM ".$this->config->item('table_name')." WHERE station_id in (" . $location_list . ") and coalesce(col_mode, '') <> '' and col_mode <> 'SSB' ORDER BY col_mode"
|
||||
);
|
||||
$modes = array();
|
||||
foreach($modes_query->result() as $row){
|
||||
$modes[] = (object) ['mode' => $row->col_mode, 'submode' => ''];
|
||||
}
|
||||
|
||||
$data['bands'] = $bands;
|
||||
$data['sats_available'] = $sats_available;
|
||||
$data['modes'] = $modes;
|
||||
|
||||
// Set default values for visitor (no user preferences)
|
||||
$data['user_default_band'] = 'All';
|
||||
$data['user_default_confirmation'] = '';
|
||||
|
||||
|
||||
// Generate initial grid data (default to showing all bands)
|
||||
$default_band = 'All';
|
||||
$default_mode = 'All';
|
||||
$default_sat = 'All';
|
||||
|
||||
$array_grid_2char = array();
|
||||
$array_grid_4char = array();
|
||||
$array_grid_6char = array();
|
||||
|
||||
|
||||
$array_confirmed_grid_2char = array();
|
||||
$array_confirmed_grid_4char = array();
|
||||
$array_confirmed_grid_6char = array();
|
||||
|
||||
$grid_2char = "";
|
||||
$grid_4char = "";
|
||||
$grid_6char = "";
|
||||
|
||||
$grid_2char_confirmed = "";
|
||||
$grid_4char_confirmed = "";
|
||||
$grid_6char_confirmed = "";
|
||||
|
||||
|
||||
// Get Confirmed LoTW & Paper Squares (non VUCC)
|
||||
$query = $this->gridmap_model->get_band_confirmed('SAT', 'All', 'true', 'true', 'false', 'false', 'All', $logbooks_locations_array);
|
||||
|
||||
// Get initial data for "All" bands
|
||||
$query = $this->gridmap_model->get_band_confirmed($default_band, $default_mode, 'false', 'false', 'false', 'false', $default_sat, $logbooks_locations_array);
|
||||
|
||||
if ($query && $query->num_rows() > 0)
|
||||
{
|
||||
foreach ($query->result() as $row)
|
||||
{
|
||||
|
||||
$grid_2char_confirmed = strtoupper(substr($row->GRID_SQUARES,0,2));
|
||||
$grid_4char_confirmed = strtoupper(substr($row->GRID_SQUARES,0,4));
|
||||
if ($this->config->item('map_6digit_grids')) {
|
||||
|
@ -267,30 +309,25 @@ class Visitor extends CI_Controller {
|
|||
array_push($array_confirmed_grid_2char, $grid_2char_confirmed);
|
||||
}
|
||||
|
||||
|
||||
if(!in_array($grid_4char_confirmed, $array_confirmed_grid_4char)){
|
||||
array_push($array_confirmed_grid_4char, $grid_4char_confirmed);
|
||||
}
|
||||
|
||||
|
||||
if ($this->config->item('map_6digit_grids')) {
|
||||
if(!in_array($grid_6char_confirmed, $array_confirmed_grid_6char)){
|
||||
array_push($array_confirmed_grid_6char, $grid_6char_confirmed);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Get worked squares
|
||||
$query = $this->gridmap_model->get_band('SAT', 'All', 'false', 'true', 'false', 'false', 'All', $logbooks_locations_array);
|
||||
// Get worked squares (all bands by default)
|
||||
$query = $this->gridmap_model->get_band($default_band, $default_mode, 'false', 'false', 'false', 'false', $default_sat, $logbooks_locations_array);
|
||||
|
||||
if ($query && $query->num_rows() > 0)
|
||||
{
|
||||
foreach ($query->result() as $row)
|
||||
{
|
||||
|
||||
$grid_two = strtoupper(substr($row->GRID_SQUARES,0,2));
|
||||
$grid_four = strtoupper(substr($row->GRID_SQUARES,0,4));
|
||||
if ($this->config->item('map_6digit_grids')) {
|
||||
|
@ -302,29 +339,25 @@ class Visitor extends CI_Controller {
|
|||
array_push($array_grid_2char, $grid_two);
|
||||
}
|
||||
|
||||
|
||||
if(!in_array($grid_four, $array_grid_4char)){
|
||||
array_push($array_grid_4char, $grid_four);
|
||||
}
|
||||
|
||||
|
||||
if ($this->config->item('map_6digit_grids')) {
|
||||
if(!in_array($grid_six, $array_grid_6char)){
|
||||
array_push($array_grid_6char, $grid_six);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$query_vucc = $this->gridmap_model->get_band_worked_vucc_squares('SAT', 'All', 'false', 'true', 'false', 'false', 'All', $logbooks_locations_array);
|
||||
// Get VUCC squares (worked)
|
||||
$query_vucc = $this->gridmap_model->get_band_worked_vucc_squares($default_band, $default_mode, 'false', 'false', 'false', 'false', $default_sat, $logbooks_locations_array);
|
||||
|
||||
if ($query && $query_vucc->num_rows() > 0)
|
||||
if ($query_vucc && $query_vucc->num_rows() > 0)
|
||||
{
|
||||
foreach ($query_vucc->result() as $row)
|
||||
{
|
||||
|
||||
$grids = explode(",", $row->COL_VUCC_GRIDS);
|
||||
|
||||
foreach($grids as $key) {
|
||||
|
@ -336,7 +369,6 @@ class Visitor extends CI_Controller {
|
|||
array_push($array_grid_2char, $grid_two);
|
||||
}
|
||||
|
||||
|
||||
if(!in_array($grid_four, $array_grid_4char)){
|
||||
array_push($array_grid_4char, $grid_four);
|
||||
}
|
||||
|
@ -344,14 +376,13 @@ class Visitor extends CI_Controller {
|
|||
}
|
||||
}
|
||||
|
||||
// Confirmed Squares
|
||||
$query_vucc = $this->gridmap_model->get_band_confirmed_vucc_squares('SAT', 'All', 'true', 'true', 'false', 'false', 'All', $logbooks_locations_array);
|
||||
// Confirmed VUCC Squares
|
||||
$query_vucc = $this->gridmap_model->get_band_confirmed_vucc_squares($default_band, $default_mode, 'false', 'false', 'false', 'false', $default_sat, $logbooks_locations_array);
|
||||
|
||||
if ($query && $query_vucc->num_rows() > 0)
|
||||
if ($query_vucc && $query_vucc->num_rows() > 0)
|
||||
{
|
||||
foreach ($query_vucc->result() as $row)
|
||||
{
|
||||
|
||||
$grids = explode(",", $row->COL_VUCC_GRIDS);
|
||||
|
||||
foreach($grids as $key) {
|
||||
|
@ -363,7 +394,6 @@ class Visitor extends CI_Controller {
|
|||
array_push($array_confirmed_grid_2char, $grid_2char_confirmed);
|
||||
}
|
||||
|
||||
|
||||
if(!in_array($grid_4char_confirmed, $array_confirmed_grid_4char)){
|
||||
array_push($array_confirmed_grid_4char, $grid_4char_confirmed);
|
||||
}
|
||||
|
@ -450,4 +480,159 @@ class Visitor extends CI_Controller {
|
|||
}
|
||||
}
|
||||
|
||||
public function getGridsjs()
|
||||
{
|
||||
$slug = $this->security->xss_clean($this->input->post('slug'));
|
||||
$band = $this->security->xss_clean($this->input->post('band'));
|
||||
$mode = $this->security->xss_clean($this->input->post('mode'));
|
||||
$sat = $this->security->xss_clean($this->input->post('sat'));
|
||||
|
||||
if (!$slug) {
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(array('error' => 'No slug provided'));
|
||||
return;
|
||||
}
|
||||
|
||||
$this->load->model('logbooks_model');
|
||||
if(!$this->logbooks_model->public_slug_exists($slug)) {
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(array('error' => 'Invalid slug'));
|
||||
return;
|
||||
}
|
||||
|
||||
$logbook_id = $this->logbooks_model->public_slug_exists_logbook_id($slug);
|
||||
if($logbook_id == false) {
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(array('error' => 'Invalid logbook'));
|
||||
return;
|
||||
}
|
||||
|
||||
// Get associated station locations for mysql queries
|
||||
$logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($logbook_id);
|
||||
|
||||
if (!$logbooks_locations_array) {
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(array('error' => 'No station locations'));
|
||||
return;
|
||||
}
|
||||
|
||||
$this->load->model('gridmap_model');
|
||||
|
||||
$array_grid_2char = array();
|
||||
$array_grid_4char = array();
|
||||
$array_grid_6char = array();
|
||||
|
||||
$array_grid_2char_confirmed = array();
|
||||
$array_grid_4char_confirmed = array();
|
||||
$array_grid_6char_confirmed = array();
|
||||
|
||||
// For public visitor, we don't show QSL confirmations, so set all to false
|
||||
$query = $this->gridmap_model->get_band_confirmed($band, $mode, 'false', 'false', 'false', 'false', $sat, $logbooks_locations_array);
|
||||
|
||||
if ($query && $query->num_rows() > 0) {
|
||||
foreach ($query->result() as $row) {
|
||||
$grid_2char_confirmed = strtoupper(substr($row->GRID_SQUARES,0,2));
|
||||
$grid_4char_confirmed = strtoupper(substr($row->GRID_SQUARES,0,4));
|
||||
$grid_6char_confirmed = strtoupper(substr($row->GRID_SQUARES,0,6));
|
||||
|
||||
// Check if 2 Char is in array
|
||||
if(!in_array($grid_2char_confirmed, $array_grid_2char_confirmed)){
|
||||
array_push($array_grid_2char_confirmed, $grid_2char_confirmed);
|
||||
}
|
||||
|
||||
if(!in_array($grid_4char_confirmed, $array_grid_4char_confirmed)){
|
||||
array_push($array_grid_4char_confirmed, $grid_4char_confirmed);
|
||||
}
|
||||
|
||||
if(!in_array($grid_6char_confirmed, $array_grid_6char_confirmed)){
|
||||
array_push($array_grid_6char_confirmed, $grid_6char_confirmed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$query = $this->gridmap_model->get_band($band, $mode, 'false', 'false', 'false', 'false', $sat, $logbooks_locations_array);
|
||||
|
||||
if ($query && $query->num_rows() > 0) {
|
||||
foreach ($query->result() as $row) {
|
||||
|
||||
$grid_two = strtoupper(substr($row->GRID_SQUARES,0,2));
|
||||
$grid_four = strtoupper(substr($row->GRID_SQUARES,0,4));
|
||||
$grid_six = strtoupper(substr($row->GRID_SQUARES,0,6));
|
||||
|
||||
// Check if 2 Char is in array
|
||||
if(!in_array($grid_two, $array_grid_2char)){
|
||||
array_push($array_grid_2char, $grid_two);
|
||||
}
|
||||
|
||||
if(!in_array($grid_four, $array_grid_4char)){
|
||||
array_push($array_grid_4char, $grid_four);
|
||||
}
|
||||
|
||||
if(!in_array($grid_six, $array_grid_6char)){
|
||||
array_push($array_grid_6char, $grid_six);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
$query_vucc = $this->gridmap_model->get_band_worked_vucc_squares($band, $mode, 'false', 'false', 'false', 'false', $sat, $logbooks_locations_array);
|
||||
|
||||
if ($query_vucc && $query_vucc->num_rows() > 0) {
|
||||
foreach ($query_vucc->result() as $row) {
|
||||
|
||||
$grids = explode(",", $row->COL_VUCC_GRIDS);
|
||||
|
||||
foreach($grids as $key) {
|
||||
$grid_two = strtoupper(substr($key,0,2));
|
||||
$grid_four = strtoupper(substr($key,0,4));
|
||||
|
||||
// Check if 2 Char is in array
|
||||
if(!in_array($grid_two, $array_grid_2char)){
|
||||
array_push($array_grid_2char, $grid_two);
|
||||
}
|
||||
|
||||
|
||||
if(!in_array($grid_four, $array_grid_4char)){
|
||||
array_push($array_grid_4char, $grid_four);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// // Confirmed Squares
|
||||
$query_vucc = $this->gridmap_model->get_band_confirmed_vucc_squares($band, $mode, 'false', 'false', 'false', 'false', $sat, $logbooks_locations_array);
|
||||
|
||||
if ($query_vucc && $query_vucc->num_rows() > 0) {
|
||||
foreach ($query_vucc->result() as $row) {
|
||||
|
||||
$grids = explode(",", $row->COL_VUCC_GRIDS);
|
||||
|
||||
foreach($grids as $key) {
|
||||
$grid_2char_confirmed = strtoupper(substr($key,0,2));
|
||||
$grid_4char_confirmed = strtoupper(substr($key,0,4));
|
||||
|
||||
// Check if 2 Char is in array
|
||||
if(!in_array($grid_2char_confirmed, $array_grid_2char_confirmed)){
|
||||
array_push($array_grid_2char_confirmed, $grid_2char_confirmed);
|
||||
}
|
||||
|
||||
|
||||
if(!in_array($grid_4char_confirmed, $array_grid_4char_confirmed)){
|
||||
array_push($array_grid_4char_confirmed, $grid_4char_confirmed);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$data['grid_2char_confirmed'] = ($array_grid_2char_confirmed);
|
||||
$data['grid_4char_confirmed'] = ($array_grid_4char_confirmed);
|
||||
$data['grid_6char_confirmed'] = ($array_grid_6char_confirmed);
|
||||
|
||||
$data['grid_2char'] = ($array_grid_2char);
|
||||
$data['grid_4char'] = ($array_grid_4char);
|
||||
$data['grid_6char'] = ($array_grid_6char);
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($data);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -41,6 +41,16 @@ function gridPlot(form, visitor=true) {
|
|||
ajax_url = site_url + '/gridmap/getGridsjs';
|
||||
}
|
||||
|
||||
// If visitor context, get the slug from the URL and use visitor endpoint
|
||||
if (visitor === true) {
|
||||
var pathParts = window.location.pathname.split('/');
|
||||
var slugIndex = pathParts.indexOf('satellites');
|
||||
if (slugIndex !== -1 && pathParts[slugIndex + 1]) {
|
||||
var slug = pathParts[slugIndex + 1];
|
||||
ajax_url = site_url + '/visitor/getGridsjs';
|
||||
}
|
||||
}
|
||||
|
||||
if (visitor != true) {
|
||||
$.ajax({
|
||||
url: ajax_url,
|
||||
|
@ -73,7 +83,42 @@ function gridPlot(form, visitor=true) {
|
|||
},
|
||||
});
|
||||
} else {
|
||||
plot(visitor, grid_two, grid_four, grid_six, grid_two_confirmed, grid_four_confirmed, grid_six_confirmed);
|
||||
// Visitor context - use AJAX to get filtered data
|
||||
var pathParts = window.location.pathname.split('/');
|
||||
var slugIndex = pathParts.indexOf('satellites');
|
||||
if (slugIndex !== -1 && pathParts[slugIndex + 1]) {
|
||||
var slug = pathParts[slugIndex + 1];
|
||||
$.ajax({
|
||||
url: ajax_url,
|
||||
type: 'post',
|
||||
data: {
|
||||
slug: slug,
|
||||
band: $("#band").val(),
|
||||
mode: $("#mode").val(),
|
||||
sat: $("#sats").val(),
|
||||
},
|
||||
success: function (data) {
|
||||
console.log(data);
|
||||
$('.cohidden').show();
|
||||
$(".ld-ext-right-plot").removeClass('running');
|
||||
$(".ld-ext-right-plot").prop('disabled', false);
|
||||
$('#plot').prop("disabled", false);
|
||||
grid_two = data.grid_2char;
|
||||
grid_four = data.grid_4char;
|
||||
grid_six = data.grid_6char;
|
||||
grid_two_confirmed = data.grid_2char_confirmed;
|
||||
grid_four_confirmed = data.grid_4char_confirmed;
|
||||
grid_six_confirmed = data.grid_6char_confirmed;
|
||||
plot(visitor, grid_two, grid_four, grid_six, grid_two_confirmed, grid_four_confirmed, grid_six_confirmed);
|
||||
},
|
||||
error: function (data) {
|
||||
console.error('Error loading visitor grid data:', data);
|
||||
},
|
||||
});
|
||||
} else {
|
||||
// Fallback: use predefined grid data if available
|
||||
plot(visitor, grid_two, grid_four, grid_six, grid_two_confirmed, grid_four_confirmed, grid_six_confirmed);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue