2022-02-12 10:45:06 +00:00
|
|
|
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
/*
|
|
|
|
|
|
|
|
Data lookup functions used within Cloudlog
|
|
|
|
|
|
|
|
*/
|
|
|
|
class Qrbcalc extends CI_Controller {
|
|
|
|
|
2022-02-13 17:08:55 +00:00
|
|
|
function __construct() {
|
2022-02-12 10:45:06 +00:00
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->load->model('user_model');
|
|
|
|
if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); }
|
|
|
|
}
|
|
|
|
|
2022-02-13 17:08:55 +00:00
|
|
|
public function index() {
|
|
|
|
$data['page_title'] = "QRB Calculator";
|
2022-02-15 19:28:37 +00:00
|
|
|
|
|
|
|
$this->load->model('stations');
|
|
|
|
$data['station_locator'] = $this->stations->find_gridsquare();
|
2022-02-15 21:17:37 +00:00
|
|
|
|
2022-02-12 10:45:06 +00:00
|
|
|
$this->load->view('qrbcalc/index', $data);
|
|
|
|
}
|
2022-02-13 17:08:55 +00:00
|
|
|
|
|
|
|
public function calculate() {
|
|
|
|
$locator1 = $this->input->post("locator1");
|
|
|
|
$locator2 = $this->input->post("locator2");
|
|
|
|
|
|
|
|
if ($this->session->userdata('user_measurement_base') == NULL) {
|
|
|
|
$measurement_base = $this->config->item('measurement_base');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$measurement_base = $this->session->userdata('user_measurement_base');
|
|
|
|
}
|
|
|
|
|
2022-02-15 19:28:37 +00:00
|
|
|
switch ($measurement_base) {
|
|
|
|
case 'M':
|
|
|
|
$var_dist = " miles";
|
|
|
|
break;
|
|
|
|
case 'N':
|
|
|
|
$var_dist = " nautic miles";
|
|
|
|
break;
|
|
|
|
case 'K':
|
|
|
|
$var_dist = " kilometers";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-02-13 17:08:55 +00:00
|
|
|
$this->load->library('Qra');
|
|
|
|
|
|
|
|
$data['result'] = $this->qra->bearing($locator1, $locator2, $measurement_base);
|
2022-02-15 19:28:37 +00:00
|
|
|
$data['distance'] = $this->qra->distance($locator1, $locator2, $measurement_base) . $var_dist;
|
2022-02-16 13:57:07 +00:00
|
|
|
$data['bearing'] = $this->qra->get_bearing($locator1, $locator2) . "º";
|
2022-02-15 21:17:37 +00:00
|
|
|
$latlng1 = $this->qra->qra2latlong($locator1);
|
|
|
|
$latlng2 = $this->qra->qra2latlong($locator2);
|
|
|
|
$latlng1[0] = number_format((float)$latlng1[0], 3, '.', '');;
|
|
|
|
$latlng1[1] = number_format((float)$latlng1[1], 3, '.', '');;
|
|
|
|
$latlng2[0] = number_format((float)$latlng2[0], 3, '.', '');;
|
|
|
|
$latlng2[1] = number_format((float)$latlng2[1], 3, '.', '');;
|
|
|
|
|
|
|
|
$data['latlng1'] = $latlng1;
|
|
|
|
$data['latlng2'] = $latlng2;
|
2022-02-13 17:08:55 +00:00
|
|
|
header('Content-Type: application/json');
|
|
|
|
echo json_encode($data);
|
|
|
|
}
|
2022-02-16 13:57:07 +00:00
|
|
|
}
|