diff --git a/application/controllers/Qso.php b/application/controllers/Qso.php index 70650677..9d65d36d 100755 --- a/application/controllers/Qso.php +++ b/application/controllers/Qso.php @@ -244,4 +244,36 @@ class QSO extends CI_Controller { echo $this->frequency->convent_band($band, $mode); } + + /* + * Function is used for autocompletion of SOTA in the QSO entry form + */ + public function get_sota() { + $json = []; + + if(!empty($this->input->get("query"))) { + $query = isset($_GET['query']) ? $_GET['query'] : FALSE; + $sota = strtoupper($query); + + $file = 'assets/json/sota.txt'; + + if (is_readable($file)) { + $lines = file($file, FILE_IGNORE_NEW_LINES); + $input = preg_quote($sota, '~'); + $reg = '~^'. $input .'(.*)$~'; + $result = preg_grep($reg, $lines); + $json = []; + $i = 0; + foreach ($result as &$value) { + // Limit to 100 as to not slowdown browser too much + if (count($json) <= 100) { + $json[] = ["name"=>$value]; + } + } + } + } + + header('Content-Type: application/json'); + echo json_encode($json); + } } diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index 9d3056c3..d4be17e6 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -34,6 +34,7 @@ + uri->segment(1) == "search" && $this->uri->segment(2) == "filter") { ?> @@ -318,9 +319,38 @@ $(document).on('keypress',function(e) { uri->segment(1) == "qso") { ?> -