diff --git a/application/controllers/Gridmap.php b/application/controllers/Gridmap.php new file mode 100644 index 00000000..ed433705 --- /dev/null +++ b/application/controllers/Gridmap.php @@ -0,0 +1,307 @@ +load->model('bands'); + $this->load->model('gridmap_model'); + + $data['modes'] = $this->gridmap_model->get_worked_modes(); + + $data['bands'] = $this->bands->get_worked_bands(); + + $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 getGrids() { + $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')); + $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); + + 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); + + 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); + + 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->gridmap_model->get_band_confirmed_vucc_squares($band, $mode, $qsl, $lotw, $eqsl); + + 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_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); + } + + 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')); + $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); + + 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); + + 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); + + 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->gridmap_model->get_band_confirmed_vucc_squares($band, $mode, $qsl, $lotw, $eqsl); + + 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_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/models/Gridmap_model.php b/application/models/Gridmap_model.php new file mode 100644 index 00000000..f2001814 --- /dev/null +++ b/application/models/Gridmap_model.php @@ -0,0 +1,214 @@ +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 . "'"; + } + 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) { + $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 . "'"; + } + 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) { + $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 . "'"; + } + 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->get($this->config->item('table_name')); + } + + function get_band_confirmed_vucc_squares($band, $mode, $qsl, $lotw, $eqsl) { + $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 . "'"; + } + 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..264c4c6d --- /dev/null +++ b/application/views/gridmap/index.php @@ -0,0 +1,56 @@ +