From c8b0e48bcd88ed2075cb2473bbe3903a31999559 Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Wed, 17 Mar 2021 18:23:01 +0100 Subject: [PATCH] [Quick lookup] WWFF added. Did some refactoring to simplify code, and make it easier to add queries. --- application/controllers/Lookup.php | 22 ++-- application/models/Lookup_model.php | 109 ++++++++---------- application/views/interface_assets/footer.php | 9 +- application/views/lookup/index.php | 1 + 4 files changed, 62 insertions(+), 79 deletions(-) diff --git a/application/controllers/Lookup.php b/application/controllers/Lookup.php index be72c9c4..e2247d16 100644 --- a/application/controllers/Lookup.php +++ b/application/controllers/Lookup.php @@ -31,18 +31,22 @@ class Lookup extends CI_Controller { $CI->load->model('Stations'); $station_id = $CI->Stations->find_active(); - $type = xss_clean($this->input->post('type')); - $dxcc = xss_clean($this->input->post('dxcc')); - $was = xss_clean($this->input->post('was')); - $cqz = xss_clean($this->input->post('cqz')); - $sota = xss_clean($this->input->post('sota')); - $grid = xss_clean($this->input->post('grid')); - $iota = xss_clean($this->input->post('iota')); - $this->load->model('lookup_model'); $data['bands'] = $this->lookup_model->get_Worked_Bands($station_id); - $data['result'] = $this->lookup_model->getSearchResult($station_id, $type, $dxcc, $was, $cqz, $sota, $grid, $iota, $data['bands']); + + $queryinfo['type'] = xss_clean($this->input->post('type')); + $queryinfo['dxcc'] = xss_clean($this->input->post('dxcc')); + $queryinfo['was'] = xss_clean($this->input->post('was')); + $queryinfo['sota'] = xss_clean($this->input->post('sota')); + $queryinfo['grid'] = xss_clean($this->input->post('grid')); + $queryinfo['iota'] = xss_clean($this->input->post('iota')); + $queryinfo['cqz'] = xss_clean($this->input->post('cqz')); + $queryinfo['wwff'] = xss_clean($this->input->post('wwff')); + $queryinfo['station_id'] = $station_id; + $queryinfo['bands'] = $data['bands']; + + $data['result'] = $this->lookup_model->getSearchResult($queryinfo); $this->load->view('lookup/result', $data); } diff --git a/application/models/Lookup_model.php b/application/models/Lookup_model.php index 5e88b5ed..28d0e239 100644 --- a/application/models/Lookup_model.php +++ b/application/models/Lookup_model.php @@ -7,28 +7,28 @@ class Lookup_model extends CI_Model{ parent::__construct(); } - function getSearchResult($station_id, $type, $dxcc, $was, $cqz, $sota, $grid, $iota, $bands){ - $modes = $this->get_worked_modes($station_id); + function getSearchResult($queryinfo){ + $modes = $this->get_worked_modes($queryinfo['station_id']); - return $this->getResultFromDatabase($station_id, $type, $dxcc, $was, $cqz, $sota, $grid, $iota, $modes, $bands); + return $this->getResultFromDatabase($queryinfo, $modes); } - function getResultFromDatabase($station_id, $type, $dxcc, $was, $cqz, $sota, $grid, $iota, $modes, $bands) { + function getResultFromDatabase($queryinfo, $modes) { // Creating an empty array with all the bands and modes from the database foreach ($modes as $mode) { - foreach ($bands as $band) { + foreach ($queryinfo['bands'] as $band) { $resultArray[$mode][$band] = '-'; } } // Populating array with worked band/mode combinations - $worked = $this->getQueryData($station_id, $type, $dxcc, $was, $cqz, $sota, $grid, $iota,'worked'); + $worked = $this->getQueryData($queryinfo, 'worked'); foreach ($worked as $w) { $resultArray[$w->col_mode][$w->col_band] = 'W'; } // Populating array with confirmed band/mode combinations - $confirmed = $this->getQueryData($station_id, $type, $dxcc, $was, $cqz, $sota, $grid, $iota,'confirmed'); + $confirmed = $this->getQueryData($queryinfo, 'confirmed'); foreach ($confirmed as $c) { $resultArray[$c->col_mode][$c->col_band] = 'C'; } @@ -39,102 +39,85 @@ class Lookup_model extends CI_Model{ /* * Builds query depending on what we are searching for */ - function getQueryData($station_id, $type, $dxcc, $was, $cqz, $sota, $grid, $iota, $confirmedtype) { + function getQueryData($queryinfo, $confirmedtype) { // If user inputs longer grid than 4 chars, we use only the first 4 - if (strlen($grid) > 4) { - $fixedgrid = substr($grid, 0, 4); + if (strlen($queryinfo['grid']) > 4) { + $fixedgrid = substr($queryinfo['grid'], 0, 4); } else { - $fixedgrid = $grid; + $fixedgrid = $queryinfo['grid']; } + $sqlquerytypestring = ''; + + switch ($queryinfo['type']) { + case 'dxcc': $sqlquerytypestring .= " and col_dxcc = " . $queryinfo['dxcc']; break; + case 'iota': $sqlquerytypestring .= " and col_iota = '" . $queryinfo['iota'] . "'"; break; + case 'grid': $sqlquerytypestring .= " and (col_gridsquare like '%" . $fixedgrid . "%' or col_vucc_grids like '%" . $fixedgrid . "%')" ; break; + case 'cqz': $sqlquerytypestring .= " and col_cqz = " . $queryinfo['cqz']; break; + case 'was': $sqlquerytypestring .= " and col_state = '" . $queryinfo['was'] . "' and COL_DXCC in ('291', '6', '110')";; break; + case 'sota': $sqlquerytypestring .= " and col_sota_ref = '" . $queryinfo['sota'] . "'"; break; + case 'wwff': $sqlquerytypestring .= " and col_sig = 'WWFF' and col_sig_info = '" . $queryinfo['wwff'] . "'"; break; + default: break; + } + + $sqlqueryconfirmationstring = ''; + + if ($confirmedtype == 'confirmed') { + $sqlqueryconfirmationstring .= " and (col_qsl_rcvd = 'Y' or col_lotw_qsl_rcvd = 'Y')"; + } + + // Fetching info for all modes and bands except satellite $sql = "SELECT distinct col_band, lower(col_mode) as col_mode FROM " . $this->config->item('table_name') . " thcv"; - $sql .= " where station_id = " . $station_id; + $sql .= " where station_id = " . $queryinfo['station_id']; $sql .= " and coalesce(col_submode, '') = ''"; $sql .= " and col_prop_mode != 'SAT'"; - switch ($type) { - case 'dxcc': $sql .= " and col_dxcc = " . $dxcc; break; - case 'iota': $sql .= " and col_iota = '" . $iota . "'"; break; - case 'grid': $sql .= " and (col_gridsquare like '%" . $fixedgrid . "%' or col_vucc_grids like '%" . $fixedgrid . "%')" ; break; - case 'cqz': $sql .= " and col_cqz = " . $cqz; break; - case 'was': $sql .= " and col_state = '" . $was . "' and COL_DXCC in ('291', '6', '110')";; break; - case 'sota': $sql .= " and col_sota_ref = '" . $sota . "'"; break; - default: break; - } + $sql .= $sqlquerytypestring; - if ($confirmedtype == 'confirmed') { - $sql .= " and (col_qsl_rcvd = 'Y' or col_lotw_qsl_rcvd = 'Y')"; - } + $sql .= $sqlqueryconfirmationstring; + // Fetching info for all sub_modes and bands except satellite $sql .= " union SELECT distinct col_band, lower(col_submode) as col_mode FROM " . $this->config->item('table_name') . " thcv"; - $sql .= " where station_id = " . $station_id; + $sql .= " where station_id = " . $queryinfo['station_id']; $sql .= " and coalesce(col_submode, '') <> ''"; $sql .= " and col_prop_mode != 'SAT'"; - switch ($type) { - case 'dxcc': $sql .= " and col_dxcc = " . $dxcc; break; - case 'iota': $sql .= " and col_iota = '" . $iota . "'"; break; - case 'grid': $sql .= " and (col_gridsquare like '%" . $fixedgrid . "%' or col_vucc_grids like '%" . $fixedgrid . "%')" ; break; - case 'cqz': $sql .= " and col_cqz = " . $cqz; break; - case 'was': $sql .= " and col_state = '" . $was . "' and COL_DXCC in ('291', '6', '110')";; break; - case 'sota': $sql .= " and col_sota_ref = '" . $sota . "'"; break; - default: break; - } + $sql .= $sqlquerytypestring; - if ($confirmedtype == 'confirmed') { - $sql .= " and (col_qsl_rcvd = 'Y' or col_lotw_qsl_rcvd = 'Y')"; - } + $sql .= $sqlqueryconfirmationstring; + // Fetching info for all modes on satellite $sql .= " union SELECT distinct 'SAT' col_band, lower(col_mode) as col_mode FROM " . $this->config->item('table_name') . " thcv"; - $sql .= " where station_id = " . $station_id; + $sql .= " where station_id = " . $queryinfo['station_id']; $sql .= " and coalesce(col_submode, '') = ''"; $sql .= " and col_prop_mode = 'SAT'"; - switch ($type) { - case 'dxcc': $sql .= " and col_dxcc = " . $dxcc; break; - case 'iota': $sql .= " and col_iota = '" . $iota . "'"; break; - case 'grid': $sql .= " and (col_gridsquare like '%" . $fixedgrid . "%' or col_vucc_grids like '%" . $fixedgrid . "%')" ; break; - case 'cqz': $sql .= " and col_cqz = " . $cqz; break; - case 'was': $sql .= " and col_state = '" . $was . "' and COL_DXCC in ('291', '6', '110')";; break; - case 'sota': $sql .= " and col_sota_ref = '" . $sota . "'"; break; - default: break; - } + $sql .= $sqlquerytypestring; - if ($confirmedtype == 'confirmed') { - $sql .= " and (col_qsl_rcvd = 'Y' or col_lotw_qsl_rcvd = 'Y')"; - } + $sql .= $sqlqueryconfirmationstring; + // Fetching info for all sub_modes on satellite $sql .= " union SELECT distinct 'SAT' col_band, lower(col_submode) as col_mode FROM " . $this->config->item('table_name') . " thcv"; - $sql .= " where station_id = " . $station_id; + $sql .= " where station_id = " . $queryinfo['station_id']; $sql .= " and coalesce(col_submode, '') <> ''"; $sql .= " and col_prop_mode = 'SAT'"; - switch ($type) { - case 'dxcc': $sql .= " and col_dxcc = " . $dxcc; break; - case 'iota': $sql .= " and col_iota = '" . $iota . "'"; break; - case 'grid': $sql .= " and (col_gridsquare like '%" . $fixedgrid . "%' or col_vucc_grids like '%" . $fixedgrid . "%')" ; break; - case 'cqz': $sql .= " and col_cqz = " . $cqz; break; - case 'was': $sql .= " and col_state = '" . $was . "' and COL_DXCC in ('291', '6', '110')";; break; - case 'sota': $sql .= " and col_sota_ref= '" . $sota . "'"; break; - default: break; - } + $sql .= $sqlquerytypestring; - if ($confirmedtype == 'confirmed') { - $sql .= " and (col_qsl_rcvd = 'Y' or col_lotw_qsl_rcvd = 'Y')"; - } + $sql .= $sqlqueryconfirmationstring; $query = $this->db->query($sql); diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index d6976f84..a25cf581 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -176,13 +176,7 @@ function spawnLookupModal() { $('#quicklookupcqz').hide(); $('#quicklookupwas').hide(); $('#quicklookuptext').hide(); - } else if (type == "grid") { - $('#quicklookuptext').show(); - $('#quicklookupiota').hide(); - $('#quicklookupdxcc').hide(); - $('#quicklookupcqz').hide(); - $('#quicklookupwas').hide(); - } else if (type == "sota") { + } else if (type == "grid" || type == "sota" || type == "wwff") { $('#quicklookuptext').show(); $('#quicklookupiota').hide(); $('#quicklookupdxcc').hide(); @@ -229,6 +223,7 @@ function getLookupResult() { cqz: $('#quicklookupcqz').val(), iota: $('#quicklookupiota').val(), sota: $('#quicklookuptext').val(), + wwff: $('#quicklookuptext').val(), }, success: function (html) { $('#lookupresulttable').html(html); diff --git a/application/views/lookup/index.php b/application/views/lookup/index.php index 2e6e4d46..995ef6c6 100644 --- a/application/views/lookup/index.php +++ b/application/views/lookup/index.php @@ -6,6 +6,7 @@ +