2019-01-01 19:14:25 +00:00
|
|
|
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
|
|
|
|
/*
|
2019-05-14 10:25:57 +00:00
|
|
|
Handles Displaying of information for station tools.
|
2019-01-01 19:14:25 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
class Station extends CI_Controller {
|
|
|
|
|
2019-01-08 22:54:29 +00:00
|
|
|
function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
$this->load->helper(array('form', 'url'));
|
|
|
|
|
|
|
|
$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'); }
|
|
|
|
}
|
|
|
|
|
2019-01-01 19:14:25 +00:00
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
$this->load->model('stations');
|
2019-09-23 16:29:22 +00:00
|
|
|
$this->load->model('Logbook_model');
|
2023-08-01 08:21:17 +00:00
|
|
|
$this->load->model('user_model');
|
|
|
|
|
|
|
|
$data['is_admin'] = ($this->user_model->authorize(99));
|
2019-09-23 16:29:22 +00:00
|
|
|
|
2019-09-24 23:38:13 +00:00
|
|
|
$data['stations'] = $this->stations->all_with_count();
|
2019-09-23 16:29:22 +00:00
|
|
|
$data['current_active'] = $this->stations->find_active();
|
|
|
|
$data['is_there_qsos_with_no_station_id'] = $this->Logbook_model->check_for_station_id();
|
2019-01-01 19:14:25 +00:00
|
|
|
|
|
|
|
// Render Page
|
2023-10-12 18:21:05 +00:00
|
|
|
$data['page_title'] = lang('station_location');
|
2019-01-09 15:18:46 +00:00
|
|
|
$this->load->view('interface_assets/header', $data);
|
2019-01-01 19:14:25 +00:00
|
|
|
$this->load->view('station_profile/index');
|
2019-01-09 15:18:46 +00:00
|
|
|
$this->load->view('interface_assets/footer');
|
2019-01-01 19:14:25 +00:00
|
|
|
}
|
|
|
|
|
2023-07-30 09:05:51 +00:00
|
|
|
public function create() {
|
2019-01-01 19:14:25 +00:00
|
|
|
$this->load->model('stations');
|
|
|
|
$this->load->model('dxcc');
|
|
|
|
$data['dxcc_list'] = $this->dxcc->list();
|
|
|
|
|
2023-07-30 09:05:51 +00:00
|
|
|
$this->load->model('logbook_model');
|
|
|
|
$data['iota_list'] = $this->logbook_model->fetchIota();
|
2020-10-06 21:47:39 +00:00
|
|
|
|
2019-01-01 19:14:25 +00:00
|
|
|
$this->load->library('form_validation');
|
|
|
|
|
|
|
|
$this->form_validation->set_rules('station_profile_name', 'Station Profile Name', 'required');
|
|
|
|
|
|
|
|
if ($this->form_validation->run() == FALSE)
|
|
|
|
{
|
2023-10-12 18:21:05 +00:00
|
|
|
$data['page_title'] = lang('station_location_create_header');
|
2019-01-09 15:18:46 +00:00
|
|
|
$this->load->view('interface_assets/header', $data);
|
2019-01-01 19:14:25 +00:00
|
|
|
$this->load->view('station_profile/create');
|
2019-01-09 15:18:46 +00:00
|
|
|
$this->load->view('interface_assets/footer');
|
2019-01-01 19:14:25 +00:00
|
|
|
}
|
|
|
|
else
|
2022-08-17 06:16:44 +00:00
|
|
|
{
|
2019-01-01 19:14:25 +00:00
|
|
|
$this->stations->add();
|
2022-08-17 06:16:44 +00:00
|
|
|
|
2019-01-01 19:14:25 +00:00
|
|
|
redirect('station');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-30 09:05:51 +00:00
|
|
|
public function edit($id) {
|
|
|
|
$this->load->model('stations');
|
|
|
|
if ($this->stations->check_station_is_accessible($id)) {
|
|
|
|
$data = $this->load_station_for_editing($id);
|
2023-10-12 18:21:05 +00:00
|
|
|
$data['page_title'] = lang('station_location_edit') . $data['my_station_profile']->station_profile_name;
|
2022-08-17 06:16:44 +00:00
|
|
|
|
2023-07-30 09:05:51 +00:00
|
|
|
if ($this->form_validation->run() == FALSE) {
|
|
|
|
$this->load->view('interface_assets/header', $data);
|
|
|
|
$this->load->view('station_profile/edit');
|
|
|
|
$this->load->view('interface_assets/footer');
|
|
|
|
} else {
|
|
|
|
$this->stations->edit();
|
2022-08-17 06:16:44 +00:00
|
|
|
|
2023-10-12 18:21:05 +00:00
|
|
|
$data['notice'] = lang('station_location') . $this->security->xss_clean($this->input->post('station_profile_name', true)) . " Updated";
|
2022-08-17 06:16:44 +00:00
|
|
|
|
2023-07-30 09:05:51 +00:00
|
|
|
redirect('station');
|
|
|
|
}
|
|
|
|
} else {
|
2022-08-17 06:16:44 +00:00
|
|
|
redirect('station');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-30 09:05:51 +00:00
|
|
|
public function copy($id) {
|
|
|
|
$this->load->model('stations');
|
|
|
|
if ($this->stations->check_station_is_accessible($id)) {
|
|
|
|
$data = $this->load_station_for_editing($id);
|
|
|
|
$data['page_title'] = "Duplicate Station Location: {$data['my_station_profile']->station_profile_name}";
|
|
|
|
|
|
|
|
// we NULLify station_id and station_profile_name to make sure we are creating a new station
|
|
|
|
$data['copy_from'] = $data['my_station_profile']->station_id;
|
|
|
|
$data['my_station_profile']->station_id = NULL;
|
|
|
|
$data['my_station_profile']->station_profile_name = '';
|
|
|
|
|
|
|
|
if ($this->form_validation->run() == FALSE)
|
|
|
|
{
|
|
|
|
$this->load->view('interface_assets/header', $data);
|
|
|
|
$this->load->view('station_profile/edit');
|
|
|
|
$this->load->view('interface_assets/footer');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->stations->add();
|
|
|
|
|
|
|
|
redirect('station');
|
|
|
|
}
|
|
|
|
} else {
|
2022-08-17 06:16:44 +00:00
|
|
|
redirect('station');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-30 09:05:51 +00:00
|
|
|
function load_station_for_editing($id): array {
|
2019-10-03 21:18:14 +00:00
|
|
|
$this->load->library('form_validation');
|
|
|
|
|
|
|
|
$this->load->model('stations');
|
|
|
|
$this->load->model('dxcc');
|
2022-08-17 06:16:44 +00:00
|
|
|
$this->load->model('logbook_model');
|
2020-10-06 21:47:39 +00:00
|
|
|
|
2022-08-17 06:16:44 +00:00
|
|
|
$data['iota_list'] = $this->logbook_model->fetchIota();
|
2019-10-03 21:18:14 +00:00
|
|
|
|
2019-10-05 18:16:05 +00:00
|
|
|
$item_id_clean = $this->security->xss_clean($id);
|
|
|
|
|
|
|
|
$station_profile_query = $this->stations->profile($item_id_clean);
|
2019-10-03 21:18:14 +00:00
|
|
|
|
|
|
|
$data['my_station_profile'] = $station_profile_query->row();
|
|
|
|
|
2022-08-17 06:16:44 +00:00
|
|
|
$data['dxcc_list'] = $this->dxcc->list();
|
2019-10-03 21:18:14 +00:00
|
|
|
|
|
|
|
$this->form_validation->set_rules('station_profile_name', 'Station Profile Name', 'required');
|
|
|
|
|
2022-08-17 06:16:44 +00:00
|
|
|
return $data;
|
2019-01-01 19:14:25 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 14:50:19 +00:00
|
|
|
// This function allows a user to claim ownership of a station location
|
|
|
|
function claim_user($id) {
|
|
|
|
// $id is the profile id
|
|
|
|
$this->load->model('stations');
|
|
|
|
$this->stations->claim_user($id);
|
2022-10-01 12:21:50 +00:00
|
|
|
|
2021-08-23 14:50:19 +00:00
|
|
|
redirect('station');
|
|
|
|
}
|
|
|
|
|
2019-09-23 16:29:22 +00:00
|
|
|
function reassign_profile($id) {
|
|
|
|
// $id is the profile that needs reassigned to QSOs
|
|
|
|
$this->load->model('stations');
|
|
|
|
$this->stations->reassign($id);
|
2022-08-17 06:16:44 +00:00
|
|
|
|
2019-09-23 16:29:22 +00:00
|
|
|
//$this->stations->logbook_session_data();
|
2019-09-23 17:36:17 +00:00
|
|
|
redirect('station');
|
2019-09-23 16:29:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function set_active($current, $new) {
|
|
|
|
$this->load->model('stations');
|
|
|
|
$this->stations->set_active($current, $new);
|
2022-08-17 06:16:44 +00:00
|
|
|
|
2019-09-23 16:29:22 +00:00
|
|
|
//$this->stations->logbook_session_data();
|
|
|
|
redirect('station');
|
|
|
|
}
|
|
|
|
|
2019-01-01 19:14:25 +00:00
|
|
|
public function delete($id) {
|
|
|
|
$this->load->model('stations');
|
2023-07-30 09:05:51 +00:00
|
|
|
if ($this->stations->check_station_is_accessible($id)) {
|
|
|
|
$this->stations->delete($id);
|
|
|
|
}
|
2019-01-01 19:14:25 +00:00
|
|
|
redirect('station');
|
|
|
|
}
|
|
|
|
|
2023-08-01 08:21:17 +00:00
|
|
|
public function deletelog($id) {
|
2020-02-07 13:54:49 +00:00
|
|
|
$this->load->model('stations');
|
2023-07-30 09:05:51 +00:00
|
|
|
if ($this->stations->check_station_is_accessible($id)) {
|
|
|
|
$this->stations->deletelog($id);
|
|
|
|
}
|
2020-02-07 13:54:49 +00:00
|
|
|
redirect('station');
|
|
|
|
}
|
|
|
|
|
2021-01-24 14:29:29 +00:00
|
|
|
/*
|
|
|
|
* 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);
|
2021-12-27 19:24:00 +00:00
|
|
|
// Limit to 300 as to not slowdown browser too much
|
|
|
|
if (count($json) <= 300) {
|
2021-01-24 14:29:29 +00:00
|
|
|
$json[] = ["name"=>$county[1]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
echo json_encode($json);
|
|
|
|
}
|
|
|
|
|
2022-08-17 06:16:44 +00:00
|
|
|
}
|