diff --git a/application/controllers/Lookup.php b/application/controllers/Lookup.php index 60079ac02..86e953614 100644 --- a/application/controllers/Lookup.php +++ b/application/controllers/Lookup.php @@ -131,24 +131,56 @@ class Lookup extends CI_Controller { public function get_state_list() { $this->load->library('subdivisions'); - + $dxcc = xss_clean($this->input->post('dxcc')); $states_result = $this->subdivisions->get_state_list($dxcc); $subdivision_name = $this->subdivisions->get_primary_subdivision_name($dxcc); - + if ($states_result->num_rows() > 0) { $states_array = $states_result->result_array(); - $result = array( + $result = array( 'status' => 'ok', 'subdivision_name' => $subdivision_name, 'data' => $states_array ); header('Content-Type: application/json'); - echo json_encode($result); + echo json_encode($result); } else { header('Content-Type: application/json'); echo json_encode(array('status' => 'No States for this DXCC in Database')); } } + + + public function get_county() { + $json = []; + + if(!empty($this->input->get("query"))) { + $county = $this->input->get("state"); + $cleanedcounty = explode('(', $county); + $cleanedcounty = trim($cleanedcounty[0]); + + $file = 'assets/json/US_counties.csv'; + + if (is_readable($file)) { + $lines = file($file, FILE_IGNORE_NEW_LINES); + $input = preg_quote($cleanedcounty, '~'); + $reg = '~^'. $input .'(.*)$~'; + $result = preg_grep($reg, $lines); + $json = []; + $i = 0; + foreach ($result as &$value) { + $county = explode(',', $value); + // Limit to 100 as to not slowdown browser too much + if (count($json) <= 100) { + $json[] = ["name"=>$county[1]]; + } + } + } + } + + header('Content-Type: application/json'); + echo json_encode($json); + } } diff --git a/application/controllers/Qso.php b/application/controllers/Qso.php index b197537bb..580e05223 100755 --- a/application/controllers/Qso.php +++ b/application/controllers/Qso.php @@ -500,41 +500,6 @@ class QSO extends CI_Controller { echo json_encode($json); } - /* - * Function is used for autocompletion of Counties in the station profile form - */ - public function get_county() { - $json = []; - - if(!empty($this->input->get("query"))) { - //$query = isset($_GET['query']) ? $_GET['query'] : FALSE; - $county = $this->input->get("state"); - $cleanedcounty = explode('(', $county); - $cleanedcounty = trim($cleanedcounty[0]); - - $file = 'assets/json/US_counties.csv'; - - if (is_readable($file)) { - $lines = file($file, FILE_IGNORE_NEW_LINES); - $input = preg_quote($cleanedcounty, '~'); - $reg = '~^'. $input .'(.*)$~'; - $result = preg_grep($reg, $lines); - $json = []; - $i = 0; - foreach ($result as &$value) { - $county = explode(',', $value); - // Limit to 100 as to not slowdown browser too much - if (count($json) <= 300) { - $json[] = ["name"=>$county[1]]; - } - } - } - } - - header('Content-Type: application/json'); - echo json_encode($json); - } - public function get_sota_info() { $this->load->library('sota'); diff --git a/application/controllers/Station.php b/application/controllers/Station.php index fd82eb55a..ef5ffcc1e 100644 --- a/application/controllers/Station.php +++ b/application/controllers/Station.php @@ -182,38 +182,4 @@ class Station extends CI_Controller redirect('stationsetup'); } - /* - * Function is used for autocompletion of Counties in the station profile form - */ - public function get_county() - { - $json = []; - - if (!empty($this->input->get("query"))) { - $query = isset($_GET['query']) ? $_GET['query'] : FALSE; - $county = $this->input->get("state"); - - $file = 'assets/json/US_counties.csv'; - - if (is_readable($file)) { - $lines = file($file, FILE_IGNORE_NEW_LINES); - $input = preg_quote($county, '~'); - $reg = '~^' . $input . '(.*)$~'; - $result = preg_grep($reg, $lines); - $json = []; - $i = 0; - foreach ($result as &$value) { - $county = explode(',', $value); - // Limit to 300 as to not slowdown browser too much - if (count($json) <= 300) { - $json[] = ["name" => $county[1]]; - } - } - } - } - - header('Content-Type: application/json'); - echo json_encode($json); - } - }