[Visitor] Adds ability to see worked satellite squares

/visitor/satellites/<slug>
pull/1443/head
Peter Goodhall 2022-03-24 18:31:14 +00:00
rodzic 3d1c37dca2
commit be55278ce3
3 zmienionych plików z 389 dodań i 40 usunięć

Wyświetl plik

@ -14,6 +14,9 @@ class Visitor extends CI_Controller {
elseif($method == "map") {
$this->map($method);
}
elseif($method == "satellites") {
$this->satellites($method);
}
else {
$this->index($method);
}
@ -177,4 +180,197 @@ class Visitor extends CI_Controller {
echo "}";
}
public function satellites()
{
$slug = $this->security->xss_clean($this->uri->segment(3));
$this->load->model('logbooks_model');
if($this->logbooks_model->public_slug_exists($slug)) {
// Load the public view
if($logbook_id = $this->logbooks_model->public_slug_exists_logbook_id($slug) != false)
{
// Get associated station locations for mysql queries
$logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($logbook_id);
} else {
log_message('error', $slug.' has no associated station locations');
show_404('Unknown Public Page.');
}
}
$this->load->model('gridsquares_model');
$data['page_title'] = "Satellite Gridsquare Map";
$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->gridsquares_model->get_confirmed_sat_squares($logbooks_locations_array);
if ($query && $query->num_rows() > 0)
{
foreach ($query->result() as $row)
{
$grid_2char_confirmed = strtoupper(substr($row->SAT_SQUARE,0,2));
$grid_4char_confirmed = strtoupper(substr($row->SAT_SQUARE,0,4));
if ($this->config->item('map_6digit_grids')) {
$grid_6char_confirmed = strtoupper(substr($row->SAT_SQUARE,0,6));
}
// Check if 2 Char is in array
if(!in_array($grid_2char_confirmed, $array_confirmed_grid_2char)){
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->gridsquares_model->get_worked_sat_squares($logbooks_locations_array);
if ($query && $query->num_rows() > 0)
{
foreach ($query->result() as $row)
{
$grid_two = strtoupper(substr($row->SAT_SQUARE,0,2));
$grid_four = strtoupper(substr($row->SAT_SQUARE,0,4));
if ($this->config->item('map_6digit_grids')) {
$grid_six = strtoupper(substr($row->SAT_SQUARE,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 ($this->config->item('map_6digit_grids')) {
if(!in_array($grid_six, $array_grid_6char)){
array_push($array_grid_6char, $grid_six);
}
}
}
}
$query_vucc = $this->gridsquares_model->get_worked_sat_vucc_squares($logbooks_locations_array);
if ($query && $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->gridsquares_model->get_confirmed_sat_vucc_squares($logbooks_locations_array);
if ($query && $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_confirmed_grid_2char)){
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);
}
}
}
}
function js_str($s)
{
return '"' . addcslashes($s, "\0..\37\"\\") . '"';
}
function js_array($array)
{
$temp = array_map('js_str', $array);
return '[' . implode(',', $temp) . ']';
}
$data['grid_2char_confirmed'] = js_array($array_confirmed_grid_2char);
$data['grid_4char_confirmed'] = js_array($array_confirmed_grid_4char);
$data['grid_6char_confirmed'] = js_array($array_confirmed_grid_6char);
$data['grid_2char'] = js_array($array_grid_2char);
$data['grid_4char'] = js_array($array_grid_4char);
$data['grid_6char'] = js_array($array_grid_6char);
$this->load->view('visitor/layout/header', $data);
$this->load->view('gridsquares/index');
$this->load->view('visitor/layout/footer');
}
}

Wyświetl plik

@ -2,13 +2,13 @@
class Gridsquares_model extends CI_Model {
function get_worked_sat_squares() {
$CI =& get_instance();
$CI->load->model('logbooks_model');
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
if (!$logbooks_locations_array) {
return null;
function get_worked_sat_squares($StationLocationsArray = null) {
if($StationLocationsArray == null) {
$CI =& get_instance();
$CI->load->model('logbooks_model');
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
} else {
$logbooks_locations_array = $StationLocationsArray;
}
$this->db->select('distinct substring(COL_GRIDSQUARE,1,6) as SAT_SQUARE, COL_SAT_NAME', FALSE);
@ -19,10 +19,14 @@ class Gridsquares_model extends CI_Model {
return $this->db->get($this->config->item('table_name'));
}
function get_confirmed_sat_squares() {
$CI =& get_instance();
$CI->load->model('logbooks_model');
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
function get_confirmed_sat_squares($StationLocationsArray = null) {
if($StationLocationsArray == null) {
$CI =& get_instance();
$CI->load->model('logbooks_model');
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
} else {
$logbooks_locations_array = $StationLocationsArray;
}
if (!$logbooks_locations_array) {
return null;
@ -38,10 +42,14 @@ class Gridsquares_model extends CI_Model {
}
function get_confirmed_sat_vucc_squares() {
$CI =& get_instance();
$CI->load->model('logbooks_model');
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
function get_confirmed_sat_vucc_squares($StationLocationsArray = null) {
if($StationLocationsArray == null) {
$CI =& get_instance();
$CI->load->model('logbooks_model');
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
} else {
$logbooks_locations_array = $StationLocationsArray;
}
if (!$logbooks_locations_array) {
return null;
@ -56,10 +64,14 @@ class Gridsquares_model extends CI_Model {
return $this->db->query($sql);
}
function get_worked_sat_vucc_squares() {
$CI =& get_instance();
$CI->load->model('logbooks_model');
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
function get_worked_sat_vucc_squares($StationLocationsArray = null) {
if($StationLocationsArray == null) {
$CI =& get_instance();
$CI->load->model('logbooks_model');
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
} else {
$logbooks_locations_array = $StationLocationsArray;
}
if (!$logbooks_locations_array) {
return null;
@ -72,10 +84,14 @@ class Gridsquares_model extends CI_Model {
return $this->db->get($this->config->item('table_name'));
}
function get_band($band) {
$CI =& get_instance();
$CI->load->model('logbooks_model');
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
function get_band($band, $StationLocationsArray = null) {
if($StationLocationsArray == null) {
$CI =& get_instance();
$CI->load->model('logbooks_model');
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
} else {
$logbooks_locations_array = $StationLocationsArray;
}
if (!$logbooks_locations_array) {
return null;
@ -97,11 +113,15 @@ class Gridsquares_model extends CI_Model {
return $this->db->get($this->config->item('table_name'));
}
function get_band_confirmed($band) {
$CI =& get_instance();
$CI->load->model('logbooks_model');
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
function get_band_confirmed($band, $StationLocationsArray = null) {
if($StationLocationsArray == null) {
$CI =& get_instance();
$CI->load->model('logbooks_model');
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
} else {
$logbooks_locations_array = $StationLocationsArray;
}
if (!$logbooks_locations_array) {
return null;
}
@ -127,11 +147,14 @@ class Gridsquares_model extends CI_Model {
return $this->db->query($sql);
}
function search_band($band, $gridsquare) {
$CI =& get_instance();
$CI->load->model('logbooks_model');
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
function search_band($band, $gridsquare, $StationLocationsArray = null) {
if($StationLocationsArray == null) {
$CI =& get_instance();
$CI->load->model('logbooks_model');
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
} else {
$logbooks_locations_array = $StationLocationsArray;
}
$location_list = "'".implode("','",$logbooks_locations_array)."'";
$sql = 'SELECT COL_CALL, COL_TIME_ON, COL_BAND, COL_MODE, COL_GRIDSQUARE, COL_VUCC_GRIDS FROM '
@ -155,11 +178,14 @@ class Gridsquares_model extends CI_Model {
return json_encode($result->result());
}
function search_sat($gridsquare) {
$CI =& get_instance();
$CI->load->model('logbooks_model');
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
function search_sat($gridsquare, $StationLocationsArray = null) {
if($StationLocationsArray == null) {
$CI =& get_instance();
$CI->load->model('logbooks_model');
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
} else {
$logbooks_locations_array = $StationLocationsArray;
}
$location_list = "'".implode("','",$logbooks_locations_array)."'";
$sql = 'SELECT COL_CALL, COL_TIME_ON, COL_BAND, COL_MODE, COL_SAT_NAME, COL_GRIDSQUARE, COL_VUCC_GRIDS FROM ' .

Wyświetl plik

@ -1,3 +1,5 @@
<?php echo $this->uri->segment(2); ?>
<!-- General JS Files used across Cloudlog -->
<script src="<?php echo base_url(); ?>assets/js/jquery-3.3.1.min.js"></script>
<script src="<?php echo base_url(); ?>assets/js/popper.min.js"></script>
@ -29,15 +31,17 @@
$('[data-toggle="tooltip"]').tooltip()
});
<?php if($qra == "set") { ?>
<?php if(isset($qra) && $qra == "set") { ?>
var q_lat = <?php echo $qra_lat; ?>;
var q_lng = <?php echo $qra_lng; ?>;
<?php } else { ?>
var q_lat = 40.313043;
var q_lng = -32.695312;
<?php } ?>
<?php if(isset($slug)) { ?>
var qso_loc = '<?php echo site_url('visitor/map/'.$slug);?>';
<?php } ?>
var q_zoom = 3;
$(document).ready(function(){
@ -50,6 +54,129 @@
initmap(grid);
});
</script>
<?php if ($this->uri->segment(2) == "satellites") { ?>
<script type="text/javascript" src="<?php echo base_url();?>assets/js/leaflet/L.MaidenheadColoured.js"></script>
<script>
var layer = L.tileLayer('<?php echo $this->optionslib->get_option('option_map_tile_server');?>', {
maxZoom: 18,
attribution: '<?php echo $this->optionslib->get_option('option_map_tile_server_copyright');?>',
id: 'mapbox.streets'
});
var map = L.map('gridsquare_map', {
layers: [layer],
center: [19, 0],
zoom: 2
});
var printer = L.easyPrint({
tileLayer: layer,
sizeModes: ['Current'],
filename: 'myMap',
exportOnly: true,
hideControlContainer: true
}).addTo(map);
var grid_two = <?php echo $grid_2char; ?>;
var grid_four = <?php echo $grid_4char; ?>;
var grid_six = <?php echo $grid_6char; ?>;
var grid_two_confirmed = <?php echo $grid_2char_confirmed; ?>;
var grid_four_confirmed = <?php echo $grid_4char_confirmed; ?>;
var grid_six_confirmed = <?php echo $grid_6char_confirmed; ?>;
var maidenhead = L.maidenhead().addTo(map);
map.on('click', onMapClick);
function onMapClick(event) {
var LatLng = event.latlng;
var lat = LatLng.lat;
var lng = LatLng.lng;
var locator = LatLng2Loc(lat,lng, 10);
var loc_4char = locator.substring(0, 4);
console.log(loc_4char);
console.log(map.getZoom());
if(map.getZoom() > 2) {
<?php if ($this->session->userdata('user_callsign')) { ?>
var band = '';
var search_type = "<?php echo $this->uri->segment(2); ?>";
if(search_type == "satellites") {
band = 'SAT';
} else {
band = "<?php echo $this->uri->segment(3); ?>";
}
$(".modal-body").empty();
$.ajax({
url: base_url + 'index.php/awards/qso_details_ajax',
type: 'post',
data: {
'Searchphrase': loc_4char,
'Band': band,
'Mode': 'All',
'Type': 'VUCC'
},
success: function (html) {
$(".modal-body").html(html);
$(".modal-body table").addClass('table-sm');
$(".modal-body h5").empty();
var count = $('.table tr').length;
count = count - 1;
$('#qso_count').text(count);
if (count > 1) {
$('#gt1_qso').text("s");
} else {
$('#gt1_qso').text("");
}
if (count > 0) {
$('#square_number').text(loc_4char);
$('#exampleModal').modal('show');
$('[data-toggle="tooltip"]').tooltip({ boundary: 'window' });
}
}
});
<?php } ?>
}
};
<?php if ($this->uri->segment(1) == "gridsquares" && $this->uri->segment(2) == "band") { ?>
var bands_available = <?php echo $bands_available; ?>;
$('#gridsquare_bands').append('<option value="All">All</option>')
$.each(bands_available, function(key, value) {
$('#gridsquare_bands')
.append($("<option></option>")
.attr("value",value)
.text(value));
});
var num = "<?php echo $this->uri->segment(3);?>";
$("#gridsquare_bands option").each(function(){
if($(this).val()==num){ // EDITED THIS LINE
$(this).attr("selected","selected");
}
});
$(function(){
// bind change event to select
$('#gridsquare_bands').on('change', function () {
var url = $(this).val(); // get selected value
if (url) { // require a URL
window.location = "<?php echo site_url('gridsquares/band/');?>" + url
}
return false;
});
});
<?php } ?>
<?php } ?>
</script>
</body>
</html>