diff --git a/application/config/autoload.php b/application/config/autoload.php index 3b47ec9d..137ca8f3 100644 --- a/application/config/autoload.php +++ b/application/config/autoload.php @@ -106,6 +106,7 @@ $autoload['language'] = array( 'notes', 'qslcard', 'qso', + 'gridsquares' ); /* diff --git a/application/controllers/Gridmap.php b/application/controllers/Gridmap.php new file mode 100644 index 00000000..d4e32e6a --- /dev/null +++ b/application/controllers/Gridmap.php @@ -0,0 +1,178 @@ +load->model('bands'); + $this->load->model('gridmap_model'); + + $data['modes'] = $this->gridmap_model->get_worked_modes(); + $data['bands'] = $this->bands->get_worked_bands(); + $data['sats_available'] = $this->bands->get_worked_sats(); + + $data['layer'] = $this->optionslib->get_option('option_map_tile_server'); + + $data['attribution'] = $this->optionslib->get_option('option_map_tile_server_copyright'); + + $data['gridsquares_gridsquares'] = lang('gridsquares_gridsquares'); + $data['gridsquares_gridsquares_confirmed'] = lang('gridsquares_gridsquares_confirmed'); + $data['gridsquares_gridsquares_not_confirmed'] = lang('gridsquares_gridsquares_not_confirmed'); + $data['gridsquares_gridsquares_total_worked'] = lang('gridsquares_gridsquares_total_worked'); + + $footerData = []; + $footerData['scripts'] = [ + 'assets/js/leaflet/L.MaidenheadColouredGridMap.js', + 'assets/js/sections/gridmap.js?' + ]; + + $this->load->view('interface_assets/header', $data); + $this->load->view('gridmap/index'); + $this->load->view('interface_assets/footer', $footerData); + } + + public function getGridsjs() { + $band = $this->security->xss_clean($this->input->post('band')); + $mode = $this->security->xss_clean($this->input->post('mode')); + $qsl = $this->security->xss_clean($this->input->post('qsl')); + $lotw = $this->security->xss_clean($this->input->post('lotw')); + $eqsl = $this->security->xss_clean($this->input->post('eqsl')); + $sat = $this->security->xss_clean($this->input->post('sat')); + $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(); + + $grid_2char = ""; + $grid_4char = ""; + $grid_6char = ""; + + $grid_2char_confirmed = ""; + $grid_4char_confirmed = ""; + $grid_6char_confirmed = ""; + + $query = $this->gridmap_model->get_band_confirmed($band, $mode, $qsl, $lotw, $eqsl, $sat); + + 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')) { + $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 ($this->config->item('map_6digit_grids')) { + 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, $qsl, $lotw, $eqsl, $sat); + + 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')) { + $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 ($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($band, $mode, $qsl, $lotw, $eqsl, $sat); + + 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, $qsl, $lotw, $eqsl, $sat); + + 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); + } +} \ No newline at end of file diff --git a/application/language/english/gridsquares_lang.php b/application/language/english/gridsquares_lang.php index 8600088b..ac6c15c3 100644 --- a/application/language/english/gridsquares_lang.php +++ b/application/language/english/gridsquares_lang.php @@ -2,8 +2,6 @@ defined('BASEPATH') OR exit('No direct script access allowed'); - - $lang['gridsquares_gridsquare_map'] = 'Gridsquare map'; $lang['gridsquares_confirmed_is_green'] = 'Confirmed is Green'; @@ -14,3 +12,15 @@ $lang['gridsquares_this_map_does_not_include_satellite_internet_or_repeater_qsos $lang['gridsquares_grid_squares'] = 'grid square'; $lang['gridsquares_total_count'] = 'Total count'; + +$lang['gridsquares_band'] = 'Band'; +$lang['gridsquares_mode'] = 'Mode'; +$lang['gridsquares_sat'] = 'Satellite'; +$lang['gridsquares_confirmation'] = 'Confirmation'; + +$lang['gridsquares_button_plot'] = 'Plot'; + +$lang['gridsquares_gridsquares'] = 'Gridsquares'; +$lang['gridsquares_gridsquares_confirmed'] = 'Gridsquares confirmed'; +$lang['gridsquares_gridsquares_not_confirmed'] = 'Gridsquares not confirmed'; +$lang['gridsquares_gridsquares_total_worked'] = 'Total gridsquares worked'; \ No newline at end of file diff --git a/application/language/english/menu_lang.php b/application/language/english/menu_lang.php index 26487b7e..eb3911e7 100644 --- a/application/language/english/menu_lang.php +++ b/application/language/english/menu_lang.php @@ -21,6 +21,7 @@ $lang['menu_notes'] = 'Notes'; $lang['menu_analytics'] = 'Analytics'; $lang['menu_statistics'] = 'Statistics'; $lang['menu_gridsquares'] = 'Gridsquares'; +$lang['menu_gridmap'] = 'Gridmap'; $lang['menu_activated_gridsquares'] = 'Activated Gridsquares'; $lang['menu_gridsquare_activators'] = 'Gridsquare Activators'; $lang['menu_distances_worked'] = 'Distances Worked'; diff --git a/application/language/german/gridsquares_lang.php b/application/language/german/gridsquares_lang.php index 6b4ff343..0bf2b037 100644 --- a/application/language/german/gridsquares_lang.php +++ b/application/language/german/gridsquares_lang.php @@ -12,3 +12,15 @@ $lang['gridsquares_this_map_does_not_include_satellite_internet_or_repeater_qsos $lang['gridsquares_grid_squares'] = 'Planquadrate'; $lang['gridsquares_total_count'] = 'Summe'; + +$lang['gridsquares_band'] = 'Band'; +$lang['gridsquares_mode'] = 'Mode'; +$lang['gridsquares_sat'] = 'Satellit'; +$lang['gridsquares_confirmation'] = 'Bestätigung'; + +$lang['gridsquares_button_plot'] = 'Kartieren'; + +$lang['gridsquares_gridsquares'] = 'Planquadrate'; +$lang['gridsquares_gridsquares_confirmed'] = 'Planquadrate bestätigt'; +$lang['gridsquares_gridsquares_not_confirmed'] = 'Planquadrate nicht bestätigt'; +$lang['gridsquares_gridsquares_total_worked'] = 'Summe gearbeiteter Planquadrate'; diff --git a/application/language/german/menu_lang.php b/application/language/german/menu_lang.php index ec5efa13..ba75892b 100644 --- a/application/language/german/menu_lang.php +++ b/application/language/german/menu_lang.php @@ -21,6 +21,7 @@ $lang['menu_notes'] = 'Notizen'; $lang['menu_analytics'] = 'Analysen'; $lang['menu_statistics'] = 'Statistik'; $lang['menu_gridsquares'] = 'Planquadrate'; +$lang['menu_gridmap'] = 'Planquadratkarte'; $lang['menu_activated_gridsquares'] = 'Aktivierte Planquadrate'; $lang['menu_gridsquare_activators'] = 'Planquadrat-Aktivierer'; $lang['menu_distances_worked'] = 'Gearbeitete Entfernungen'; diff --git a/application/models/Gridmap_model.php b/application/models/Gridmap_model.php new file mode 100644 index 00000000..fd44b0bd --- /dev/null +++ b/application/models/Gridmap_model.php @@ -0,0 +1,226 @@ +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; + } + + $location_list = "'".implode("','",$logbooks_locations_array)."'"; + + $sql = 'SELECT distinct substring(COL_GRIDSQUARE,1,6) as GRID_SQUARES, COL_BAND FROM ' + .$this->config->item('table_name') + .' WHERE station_id in (' + .$location_list.') AND COL_GRIDSQUARE != ""'; + + if ($band != 'All') { + if ($band == 'SAT') { + $sql .= " and col_prop_mode ='" . $band . "'"; + if ($sat != 'All') { + $sql .= " and col_sat_name ='" . $sat . "'"; + } + } + else { + $sql .= " and col_prop_mode !='SAT'"; + $sql .= " and col_band ='" . $band . "'"; + } + } + + if ($mode != 'All') { + $sql .= " and (col_mode ='" . $mode . "' or col_submode ='" . $mode . "')"; + } + + $sql .= $this->addQslToQuery($qsl, $lotw, $eqsl); + + return $this->db->query($sql); + } + + function get_band($band, $mode, $qsl, $lotw, $eqsl, $sat) { + $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; + } + + $location_list = "'".implode("','",$logbooks_locations_array)."'"; + + $sql = 'SELECT distinct substring(COL_GRIDSQUARE,1,6) as GRID_SQUARES, COL_BAND FROM ' + .$this->config->item('table_name') + .' WHERE station_id in (' + .$location_list.') AND COL_GRIDSQUARE != ""'; + + if ($band != 'All') { + if ($band == 'SAT') { + $sql .= " and col_prop_mode ='" . $band . "'"; + if ($sat != 'All') { + $sql .= " and col_sat_name ='" . $sat . "'"; + } + } + else { + $sql .= " and col_prop_mode !='SAT'"; + $sql .= " and col_band ='" . $band . "'"; + } + } + + if ($mode != 'All') { + $sql .= " and (col_mode ='" . $mode . "' or col_submode ='" . $mode . "')"; + } + + return $this->db->query($sql); + } + + function get_band_worked_vucc_squares($band, $mode, $qsl, $lotw, $eqsl, $sat) { + $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; + } + + $location_list = "'".implode("','",$logbooks_locations_array)."'"; + + $sql = 'SELECT distinct COL_VUCC_GRIDS, COL_BAND FROM ' + .$this->config->item('table_name') + .' WHERE station_id in (' + .$location_list.') AND COL_VUCC_GRIDS != ""'; + + if ($band != 'All') { + if ($band == 'SAT') { + $sql .= " and col_prop_mode ='" . $band . "'"; + if ($sat != 'All') { + $sql .= " and col_sat_name ='" . $sat . "'"; + } + } + else { + $sql .= " and col_prop_mode !='SAT'"; + $sql .= " and col_band ='" . $band . "'"; + } + } + + if ($mode != 'All') { + $sql .= " and (col_mode ='" . $mode . "' or col_submode ='" . $mode . "')"; + } + + return $this->db->query($sql); + } + + function get_band_confirmed_vucc_squares($band, $mode, $qsl, $lotw, $eqsl, $sat) { + $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; + } + + $location_list = "'".implode("','",$logbooks_locations_array)."'"; + + $sql = 'SELECT distinct COL_VUCC_GRIDS, COL_BAND FROM ' + .$this->config->item('table_name') + .' WHERE station_id in (' + .$location_list.') AND COL_VUCC_GRIDS != ""'; + + if ($band != 'All') { + if ($band == 'SAT') { + $sql .= " and col_prop_mode ='" . $band . "'"; + if ($sat != 'All') { + $sql .= " and col_sat_name ='" . $sat . "'"; + } + } + else { + $sql .= " and col_prop_mode !='SAT'"; + $sql .= " and col_band ='" . $band . "'"; + } + } + + if ($mode != 'All') { + $sql .= " and (col_mode ='" . $mode . "' or col_submode ='" . $mode . "')"; + } + + $sql .= $this->addQslToQuery($qsl, $lotw, $eqsl); + + return $this->db->query($sql); + } + + // Adds confirmation to query + function addQslToQuery($qsl, $lotw, $eqsl) { + $sql = ''; + if ($lotw == "true" && $qsl == "false" && $eqsl == "false") { + $sql .= " and col_lotw_qsl_rcvd = 'Y'"; + } + + if ($qsl == "true" && $lotw == "false" && $eqsl == "false") { + $sql .= " and col_qsl_rcvd = 'Y'"; + } + + if ($eqsl == "true" && $lotw == "false" && $qsl == "false") { + $sql .= " and col_eqsl_qsl_rcvd = 'Y'"; + } + + if ($lotw == "true" && $qsl == "true" && $eqsl == "false") { + $sql .= " and (col_lotw_qsl_rcvd = 'Y' or col_qsl_rcvd = 'Y')"; + } + + if ($qsl == "true" && $lotw == "false" && $eqsl == "true") { + $sql .= " and (col_qsl_rcvd = 'Y' or col_eqsl_qsl_rcvd = 'Y')"; + } + + if ($eqsl == "true" && $lotw == "true" && $qsl == "false") { + $sql .= " and (col_eqsl_qsl_rcvd = 'Y' or col_lotw_qsl_rcvd = 'Y')"; + } + + if ($qsl == "true" && $lotw == "true" && $eqsl == "true") { + $sql .= " and (col_qsl_rcvd = 'Y' or col_lotw_qsl_rcvd = 'Y' or col_eqsl_qsl_rcvd = 'Y')"; + } + + if ($qsl == "false" && $lotw == "false" && $eqsl == "false") { + $sql .= " and (col_qsl_rcvd != 'Y' and col_lotw_qsl_rcvd != 'Y' and col_eqsl_qsl_rcvd != 'Y')"; + } + return $sql; + } + + /* + * Get's the worked modes from the log + */ + function get_worked_modes() { + $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; + } + + $location_list = "'".implode("','",$logbooks_locations_array)."'"; + + // get all worked modes from database + $data = $this->db->query( + "SELECT distinct LOWER(`COL_MODE`) as `COL_MODE` FROM `" . $this->config->item('table_name') . "` WHERE station_id in (" . $location_list . ") order by COL_MODE ASC" + ); + $results = array(); + foreach ($data->result() as $row) { + array_push($results, $row->COL_MODE); + } + + $data = $this->db->query( + "SELECT distinct LOWER(`COL_SUBMODE`) as `COL_SUBMODE` FROM `" . $this->config->item('table_name') . "` WHERE station_id in (" . $location_list . ") and coalesce(COL_SUBMODE, '') <> '' order by COL_SUBMODE ASC" + ); + foreach ($data->result() as $row) { + if (!in_array($row, $results)) { + array_push($results, $row->COL_SUBMODE); + } + } + + asort($results); + + return $results; + } +} \ No newline at end of file diff --git a/application/views/gridmap/index.php b/application/views/gridmap/index.php new file mode 100644 index 00000000..93a2cdeb --- /dev/null +++ b/application/views/gridmap/index.php @@ -0,0 +1,107 @@ + + + +