2024-02-09 11:05:28 +01:00
< ? php if ( ! defined ( 'BASEPATH' )) exit ( 'No direct script access allowed' );
2019-01-01 19:14:25 +00:00
/*
2019-05-14 11:25:57 +01:00
Handles Displaying of information for station tools .
2019-01-01 19:14:25 +00:00
*/
2024-02-09 11:05:28 +01:00
class Station extends CI_Controller
{
2019-01-01 19:14:25 +00:00
2025-12-08 09:39:08 +00:00
function __construct () {
2019-01-08 22:54:29 +00:00
parent :: __construct ();
$this -> load -> helper ( array ( 'form' , 'url' ));
2025-12-08 09:39:08 +00:00
if (( $this -> router -> method == 'stationProfileCoords' ) && $this -> user_model -> authorize ( 2 ) && (( clubaccess_check ( 3 ) || clubaccess_check ( 6 )))) { return ; } // Allow Clubmembers and Clubmembers ADIF to access list_locations
if ( ! $this -> user_model -> authorize ( 2 ) || ! clubaccess_check ( 9 )) {
$this -> session -> set_flashdata ( 'error' , __ ( " You're not allowed to do that! " ));
redirect ( 'dashboard' );
2024-02-09 11:05:28 +01:00
}
2019-01-08 22:54:29 +00:00
}
2024-02-09 11:05:28 +01: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 23:47:39 +02: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' );
2024-10-09 07:51:49 +00:00
$this -> form_validation -> set_rules ( 'dxcc' , 'DXCC' , 'required' );
2025-05-02 14:10:46 +02:00
$this -> form_validation -> set_rules ( 'gridsquare' , 'Locator' , 'callback_check_locator' );
2019-01-01 19:14:25 +00:00
2024-02-09 11:05:28 +01:00
if ( $this -> form_validation -> run () == FALSE ) {
2024-06-06 21:32:42 +02:00
$data [ 'page_title' ] = __ ( " Create Station Location " );
2025-05-04 09:30:23 +02:00
$data [ 'station_profile_name' ] = $this -> input -> post ( 'station_profile_name' );
2025-11-14 17:45:20 +01:00
$data [ 'station_callsign' ] = str_replace ( 'Ø' , '0' , ( $this -> input -> post ( 'station_callsign' ) ? ? '' ));
2025-05-04 09:30:23 +02:00
$data [ 'station_power' ] = $this -> input -> post ( 'station_power' );
2026-08-09 08:56:53 +00:00
$data [ 'dxcc' ] = $this -> input -> post ( 'dxcc' ) ? ? $this -> input -> get ( 'dxcc' );
2025-05-04 09:30:23 +02:00
$data [ 'city' ] = $this -> input -> post ( 'city' );
2026-08-09 08:56:53 +00:00
$data [ 'station_state' ] = $this -> input -> post ( 'station_state' ) ? ? $this -> input -> get ( 'station_state' );
2025-05-04 09:30:23 +02:00
$data [ 'station_cnty' ] = $this -> input -> post ( 'station_cnty' );
2026-08-09 08:56:53 +00:00
$data [ 'station_cq' ] = $this -> input -> post ( 'station_cq' ) ? ? $this -> input -> get ( 'station_cq' );
$data [ 'station_itu' ] = $this -> input -> post ( 'station_itu' ) ? ? $this -> input -> get ( 'station_itu' );
2026-08-07 08:12:32 +02:00
$data [ 'gridsquare' ] = $this -> input -> post ( 'gridsquare' ) ? ? $this -> input -> get ( 'gridsquare' );
2026-08-10 05:21:43 +00:00
$data [ 'iota' ] = $this -> input -> post ( 'iota' ) ? ? $this -> input -> get ( 'iota' );
2026-08-09 08:56:53 +00:00
$data [ 'sota' ] = $this -> input -> post ( 'sota' ) ? ? $this -> input -> get ( 'sota' );
$data [ 'wwff' ] = $this -> input -> post ( 'wwff' ) ? ? $this -> input -> get ( 'wwff' );
$data [ 'pota' ] = $this -> input -> post ( 'pota' ) ? ? $this -> input -> get ( 'pota' );
2025-05-04 09:30:23 +02:00
$data [ 'sig' ] = $this -> input -> post ( 'sig' );
$data [ 'sig_info' ] = $this -> input -> post ( 'sig_info' );
$data [ 'eqslnickname' ] = $this -> input -> post ( 'eqslnickname' );
$data [ 'eqsl_default_qslmsg' ] = $this -> input -> post ( 'eqsl_default_qslmsg' );
$data [ 'clublogignore' ] = $this -> input -> post ( 'clublogignore' );
$data [ 'clublogrealtime' ] = $this -> input -> post ( 'clublogrealtime' );
$data [ 'hrdlog_username' ] = $this -> input -> post ( 'hrdlog_username' );
$data [ 'hrdlog_code' ] = $this -> input -> post ( 'hrdlog_code' );
$data [ 'hrdlogrealtime' ] = $this -> input -> post ( 'hrdlogrealtime' );
$data [ 'qrzapikey' ] = $this -> input -> post ( 'qrzapikey' );
$data [ 'qrzrealtime' ] = $this -> input -> post ( 'qrzrealtime' );
$data [ 'webadifapikey' ] = $this -> input -> post ( 'webadifapikey' );
$data [ 'webadifrealtime' ] = $this -> input -> post ( 'webadifrealtime' );
$data [ 'oqrs' ] = $this -> input -> post ( 'oqrs' );
$data [ 'oqrsemail' ] = $this -> input -> post ( 'oqrsemail' );
$data [ 'oqrstext' ] = $this -> input -> post ( 'oqrstext' );
2026-03-16 11:32:57 +01:00
$data [ 'csrf_token' ] = $this -> paths -> csrf_generate ( $this -> router -> class . '_' . $this -> router -> method );
2019-01-09 15:18:46 +00:00
$this -> load -> view ( 'interface_assets/header' , $data );
2026-03-16 11:32:57 +01:00
$this -> load -> view ( 'station_profile/create' );
2019-01-09 15:18:46 +00:00
$this -> load -> view ( 'interface_assets/footer' );
2024-02-09 11:05:28 +01:00
} else {
2026-03-16 11:32:57 +01:00
if ( ! $this -> paths -> csrf_verify ( $this -> router -> class . '_' . $this -> router -> method )) {
2026-03-16 08:41:50 +00:00
$this -> session -> set_flashdata ( 'error' , __ ( " Invalid security token " ));
redirect ( 'station/create' );
return ;
}
2024-03-03 21:52:51 +01:00
$this -> stations -> add ();
redirect ( 'stationsetup' );
2019-01-01 19:14:25 +00:00
}
}
2024-10-31 10:26:59 +01:00
public function edit ( $id ) {
$id = $this -> security -> xss_clean ( $id );
2023-07-30 09:05:51 +00:00
$this -> load -> model ( 'stations' );
if ( $this -> stations -> check_station_is_accessible ( $id )) {
$data = $this -> load_station_for_editing ( $id );
2024-06-06 21:32:42 +02:00
$data [ 'page_title' ] = __ ( " Edit Station Location: " ) . $data [ 'my_station_profile' ] -> station_profile_name ;
2022-08-17 08:16:44 +02:00
2024-10-09 07:51:49 +00:00
$this -> form_validation -> set_rules ( 'dxcc' , 'DXCC' , 'required' );
2025-05-02 14:10:46 +02:00
$this -> form_validation -> set_rules ( 'gridsquare' , 'Locator' , 'callback_check_locator' );
2023-07-30 09:05:51 +00:00
if ( $this -> form_validation -> run () == FALSE ) {
2026-03-16 11:32:57 +01:00
$data [ 'csrf_token' ] = $this -> paths -> csrf_generate ( $this -> router -> class . '_' . $this -> router -> method );
2023-07-30 09:05:51 +00:00
$this -> load -> view ( 'interface_assets/header' , $data );
2026-03-16 11:34:45 +01:00
$this -> load -> view ( 'station_profile/edit' );
2023-07-30 09:05:51 +00:00
$this -> load -> view ( 'interface_assets/footer' );
} else {
2026-03-16 11:32:57 +01:00
if ( ! $this -> paths -> csrf_verify ( $this -> router -> class . '_' . $this -> router -> method )) {
2026-03-16 08:41:50 +00:00
$this -> session -> set_flashdata ( 'error' , __ ( " Invalid security token " ));
redirect ( 'station/edit/' . $id );
return ;
}
2024-03-03 21:52:51 +01:00
if ( $this -> stations -> edit ()) {
2024-06-06 21:32:42 +02:00
$data [ 'notice' ] = __ ( " Station Location " ) . $this -> security -> xss_clean ( $this -> input -> post ( 'station_profile_name' , true )) . " Updated " ;
2023-11-29 14:17:58 +01:00
}
2024-11-11 20:33:17 +01:00
// Also clean up static map images
2024-10-31 10:26:59 +01:00
if ( ! $this -> load -> is_loaded ( 'staticmap_model' )) {
$this -> load -> model ( 'staticmap_model' );
}
$this -> staticmap_model -> remove_static_map_image ( $id );
2024-03-03 21:52:51 +01:00
redirect ( 'stationsetup' );
2023-07-30 09:05:51 +00:00
}
} else {
2024-03-03 21:52:51 +01:00
redirect ( 'stationsetup' );
2022-08-17 08:16:44 +02:00
}
}
2024-10-31 10:26:59 +01:00
public function copy ( $id ) {
$id = $this -> security -> xss_clean ( $id );
2023-07-30 09:05:51 +00:00
$this -> load -> model ( 'stations' );
if ( $this -> stations -> check_station_is_accessible ( $id )) {
$data = $this -> load_station_for_editing ( $id );
2024-06-08 11:01:59 +02:00
$data [ 'page_title' ] = __ ( " Duplicate Station Location: " ) . " { $data [ 'my_station_profile' ] -> station_profile_name } " ;
2023-07-30 09:05:51 +00:00
// 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 = '' ;
2025-05-07 16:42:27 +02:00
$this -> form_validation -> set_rules ( 'gridsquare' , 'Locator' , 'callback_check_locator' );
2023-07-30 09:05:51 +00:00
2024-02-09 11:05:28 +01:00
if ( $this -> form_validation -> run () == FALSE ) {
2023-07-30 09:05:51 +00:00
$this -> load -> view ( 'interface_assets/header' , $data );
$this -> load -> view ( 'station_profile/edit' );
$this -> load -> view ( 'interface_assets/footer' );
2024-02-09 11:05:28 +01:00
} else {
2023-07-30 09:05:51 +00:00
$this -> stations -> add ();
2024-03-03 21:52:51 +01:00
redirect ( 'stationsetup' );
2023-07-30 09:05:51 +00:00
}
} else {
2024-03-03 21:52:51 +01:00
redirect ( 'stationsetup' );
2022-08-17 08:16:44 +02:00
}
}
2024-10-31 10:26:59 +01:00
public function edit_favourite ( $id ) {
$id = $this -> security -> xss_clean ( $id );
2024-03-03 21:52:51 +01:00
$this -> load -> model ( 'stations' );
$this -> stations -> edit_favourite ( $id );
redirect ( 'stationsetup' );
2024-02-09 11:05:28 +01:00
}
2024-10-31 10:26:59 +01:00
function load_station_for_editing ( $id ) : array {
$id = $this -> security -> xss_clean ( $id );
2019-10-03 22:18:14 +01:00
$this -> load -> library ( 'form_validation' );
$this -> load -> model ( 'stations' );
$this -> load -> model ( 'dxcc' );
2022-08-17 08:16:44 +02:00
$this -> load -> model ( 'logbook_model' );
2020-10-06 23:47:39 +02:00
2022-08-17 08:16:44 +02:00
$data [ 'iota_list' ] = $this -> logbook_model -> fetchIota ();
2019-10-03 22:18:14 +01:00
2019-10-05 19:16:05 +01:00
$item_id_clean = $this -> security -> xss_clean ( $id );
2024-03-03 21:52:51 +01:00
$data [ 'my_station_profile' ] = $this -> stations -> profile_full ( $item_id_clean );
2019-10-03 22:18:14 +01:00
2022-08-17 08:16:44 +02:00
$data [ 'dxcc_list' ] = $this -> dxcc -> list ();
2019-10-03 22:18:14 +01:00
$this -> form_validation -> set_rules ( 'station_profile_name' , 'Station Profile Name' , 'required' );
2022-08-17 08:16:44 +02:00
return $data ;
2019-01-01 19:14:25 +00:00
}
2021-08-23 15:50:19 +01:00
2024-10-31 10:26:59 +01:00
function reassign_profile ( $id ) {
$id = $this -> security -> xss_clean ( $id );
2024-02-07 17:29:32 +00:00
// $id is the profile that needs reassigned to QSOs // ONLY Admin can do that!
2019-09-23 17:29:22 +01:00
$this -> load -> model ( 'stations' );
2024-02-07 17:29:32 +00:00
if ( $this -> user_model -> authorize ( 99 )) {
$this -> stations -> reassign ( $id );
}
2022-08-17 08:16:44 +02:00
2019-09-23 17:29:22 +01:00
//$this->stations->logbook_session_data();
2024-03-03 21:52:51 +01:00
redirect ( 'stationsetup' );
2019-09-23 17:29:22 +01:00
}
2024-10-31 10:26:59 +01:00
function set_active ( $current , $new , $is_ajax = null ) {
$current = $this -> security -> xss_clean ( $current );
$new = $this -> security -> xss_clean ( $new );
2019-09-23 17:29:22 +01:00
$this -> load -> model ( 'stations' );
$this -> stations -> set_active ( $current , $new );
2024-03-03 21:52:51 +01:00
2024-02-09 11:05:28 +01:00
if ( $is_ajax != null ) {
return ;
}
2024-03-03 21:52:51 +01:00
redirect ( 'stationsetup' );
2019-09-23 17:29:22 +01:00
}
2024-10-31 10:26:59 +01:00
public function delete ( $id ) {
$id = $this -> security -> xss_clean ( $id );
2019-01-01 19:14:25 +00:00
$this -> load -> model ( 'stations' );
2023-07-30 09:05:51 +00:00
if ( $this -> stations -> check_station_is_accessible ( $id )) {
$this -> stations -> delete ( $id );
}
2024-03-03 21:52:51 +01:00
redirect ( 'stationsetup' );
2019-01-01 19:14:25 +00:00
}
2024-10-31 10:26:59 +01:00
public function deletelog ( $id ) {
$id = $this -> security -> xss_clean ( $id );
2024-02-09 11:05:28 +01:00
$this -> load -> model ( 'stations' );
if ( $this -> stations -> check_station_is_accessible ( $id )) {
$this -> stations -> deletelog ( $id );
}
2024-03-03 21:52:51 +01:00
redirect ( 'stationsetup' );
2023-07-30 09:05:51 +00:00
}
2020-02-07 14:54:49 +01:00
2025-02-25 20:14:52 +01:00
public function stationProfileCoords ( $id ) {
$id = $this -> security -> xss_clean ( $id );
$this -> load -> model ( 'stations' );
if ( $this -> stations -> check_station_is_accessible ( $id )) {
$coords = $this -> stations -> lookupProfileCoords ( $id );
print json_encode ( $coords );
}
}
2025-05-02 14:10:46 +02:00
function check_locator ( $grid = '' ) {
2026-07-15 13:38:03 +02:00
if ( $grid == '' ) {
return true ;
}
2025-05-02 14:10:46 +02:00
$this -> load -> library ( 'Qra' );
if ( $this -> qra -> validate_grid ( $grid )) {
return true ;
} else {
2025-05-02 14:26:16 +02:00
$this -> form_validation -> set_message ( 'check_locator' , sprintf ( __ ( " Please check value for grid locator (%s) " ), strtoupper ( $grid )));
2025-05-02 14:10:46 +02:00
return false ;
}
}
2022-08-17 08:16:44 +02:00
}