move get_county function to lookup

This commit is contained in:
HB9HIL
2024-03-07 09:47:49 +01:00
parent e6492c5d8d
commit fa3fbeebda
3 changed files with 36 additions and 73 deletions

View File

@@ -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);
}
}

View File

@@ -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');

View File

@@ -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);
}
}