2019-01-01 19:14:25 +00:00
< ? php
class Stations extends CI_Model {
2024-05-26 05:13:11 +00:00
public function __construct () {
}
2019-09-25 00:38:13 +01:00
function all_with_count () {
2024-07-07 19:05:10 +02:00
$this -> db -> select ( 'station_profile.*, dxcc_entities.name as station_country, dxcc_entities.end as dxcc_end, count(' . $this -> config -> item ( 'table_name' ) . '.station_id) as qso_total, exists(select 1 from station_logbooks_relationship where station_location_id = station_profile.station_id and station_logbook_id = ' . ( $this -> session -> userdata ( 'active_station_logbook' ) ? ? 0 ) . ') as linked' );
2019-09-24 22:19:49 +01:00
$this -> db -> from ( 'station_profile' );
$this -> db -> join ( $this -> config -> item ( 'table_name' ), 'station_profile.station_id = ' . $this -> config -> item ( 'table_name' ) . '.station_id' , 'left' );
2023-04-28 15:14:59 +02:00
$this -> db -> join ( 'dxcc_entities' , 'station_profile.station_dxcc = dxcc_entities.adif' , 'left outer' );
2024-07-02 08:12:07 +02:00
$this -> db -> group_by ( 'station_profile.station_id' );
2021-08-23 15:50:19 +01:00
$this -> db -> where ( 'station_profile.user_id' , $this -> session -> userdata ( 'user_id' ));
2021-10-20 21:26:35 +02:00
$this -> db -> or_where ( 'station_profile.user_id =' , NULL );
2024-07-07 19:05:10 +02:00
return $this -> db -> get ();
2019-01-01 19:14:25 +00:00
}
2021-09-29 22:02:08 +01:00
// Returns ALL station profiles regardless of user logged in
// This is also used by LoTW sync so must not be changed.
2019-09-25 00:38:13 +01:00
function all () {
2023-04-25 22:03:13 +02:00
$this -> db -> select ( 'station_profile.*, dxcc_entities.name as station_country' );
$this -> db -> from ( 'station_profile' );
2023-04-28 15:14:59 +02:00
$this -> db -> join ( 'dxcc_entities' , 'station_profile.station_dxcc = dxcc_entities.adif' , 'left outer' );
2023-04-25 22:03:13 +02:00
return $this -> db -> get ();
2019-09-25 00:38:13 +01:00
}
2023-07-05 14:16:53 +00:00
function all_of_user ( $userid = null ) {
2023-11-24 16:15:01 +01:00
if ( $userid == null ) {
2023-07-05 14:16:53 +00:00
$userid = $this -> session -> userdata ( 'user_id' ); // Fallback to session-uid, if userid is omitted
}
2023-04-26 22:39:09 +02:00
$this -> db -> select ( 'station_profile.*, dxcc_entities.name as station_country, dxcc_entities.end as dxcc_end' );
2023-07-05 14:16:53 +00:00
$this -> db -> where ( 'user_id' , $userid );
2023-04-28 15:14:59 +02:00
$this -> db -> join ( 'dxcc_entities' , 'station_profile.station_dxcc = dxcc_entities.adif' , 'left outer' );
2021-10-31 09:56:45 +01:00
return $this -> db -> get ( 'station_profile' );
}
2024-09-12 13:41:16 +00:00
function all_station_ids_of_user ( $userid = null ) {
if ( $userid == null ) {
$userid = $this -> session -> userdata ( 'user_id' ); // Fallback to session-uid, if userid is omitted
}
$this -> db -> select ( 'station_profile.station_id' );
$this -> db -> where ( 'user_id' , $userid );
$query = $this -> db -> get ( 'station_profile' );
2024-09-12 15:50:50 +02:00
$a_station_ids = array ();
2024-09-12 13:41:16 +00:00
if ( $query -> num_rows () > 0 ){
foreach ( $query -> result () as $row ) {
array_push ( $a_station_ids , $row -> station_id );
}
$station_ids = implode ( ', ' , $a_station_ids );
return $station_ids ;
} else {
return '' ;
}
}
2023-11-24 16:15:01 +01:00
function callsigns_of_user ( $userid = null ) {
if ( $userid == null ) {
$userid = $this -> session -> userdata ( 'user_id' ); // Fallback to session-uid, if userid is omitted
}
$this -> db -> select ( 'distinct(station_profile.station_callsign) as callsign' );
$this -> db -> where ( 'user_id' , $userid );
return $this -> db -> get ( 'station_profile' );
}
2019-08-19 22:25:50 +01:00
function profile ( $id ) {
2019-10-05 19:16:05 +01:00
// Clean ID
$clean_id = $this -> security -> xss_clean ( $id );
2020-12-07 16:32:12 +00:00
$this -> db -> where ( 'station_id' , $clean_id );
return $this -> db -> get ( 'station_profile' );
}
2024-03-03 21:52:51 +01:00
function profile_full ( $id ) {
// Should refactor all calls for profile to profile_full, since it contains also those eqsl-default-msg
$clean_id = $this -> security -> xss_clean ( $id );
$this -> db -> where ( 'station_id' , $clean_id );
$row = $this -> db -> get ( 'station_profile' ) -> row ();
$options_object = $this -> user_options_model -> get_options ( 'eqsl_default_qslmsg' , array ( 'option_name' => 'key_station_id' , 'option_key' => $id )) -> result ();
$row -> eqsl_default_qslmsg = $options_object [ 0 ] -> option_value ? ? '' ;
return $row ;
}
2020-12-07 16:32:12 +00:00
function profile_clean ( $id ) {
// Clean ID
$clean_id = $this -> security -> xss_clean ( $id );
2019-10-05 19:16:05 +01:00
$this -> db -> where ( 'station_id' , $clean_id );
2020-12-07 16:32:12 +00:00
$query = $this -> db -> get ( 'station_profile' );
$row = $query -> row ();
return $row ;
2019-08-19 22:25:50 +01:00
}
2020-09-15 22:49:05 +01:00
/*
* Function : add
* Adds post material into the station profile table .
*/
2019-01-01 19:14:25 +00:00
function add () {
2021-12-04 17:14:57 +01:00
// check if user has no active station profile yet
$station_active = null ;
if ( $this -> find_active () === '0' ) {
$station_active = 1 ;
}
2023-06-15 13:22:13 +01:00
// Check if the state is Canada and get the correct state
if ( $this -> input -> post ( 'dxcc' ) == 1 && $this -> input -> post ( 'station_ca_state' ) != " " ) {
2024-02-24 08:05:50 +01:00
$state = xss_clean ( $this -> input -> post ( 'station_ca_state' , true ));
2023-06-15 13:22:13 +01:00
} else {
2024-02-24 08:05:50 +01:00
$state = xss_clean ( $this -> input -> post ( 'station_state' , true ));
2023-06-15 13:22:13 +01:00
}
2024-02-23 15:48:55 +01:00
// Check if DXCC is USA, Alaska or Hawaii. If not true, we clear the County field due to complex adif specs
if (( $this -> input -> post ( 'dxcc' ) == 291 || $this -> input -> post ( 'dxcc' ) == 006 || $this -> input -> post ( 'dxcc' ) == 110 ) && $this -> input -> post ( 'station_cnty' ) != " " ) {
2024-02-24 08:05:50 +01:00
$county = xss_clean ( $this -> input -> post ( 'station_cnty' , true ));
2024-02-23 15:48:55 +01:00
} else {
$county = '' ;
}
2020-09-15 22:49:05 +01:00
// Create data array with field values
2019-01-01 19:14:25 +00:00
$data = array (
2021-11-15 19:54:01 +01:00
'user_id' => $this -> session -> userdata ( 'user_id' ),
2021-12-04 17:14:57 +01:00
'station_active' => $station_active ,
2019-10-05 22:02:28 +01:00
'station_profile_name' => xss_clean ( $this -> input -> post ( 'station_profile_name' , true )),
'station_gridsquare' => xss_clean ( strtoupper ( $this -> input -> post ( 'gridsquare' , true ))),
'station_city' => xss_clean ( $this -> input -> post ( 'city' , true )),
'station_iota' => xss_clean ( strtoupper ( $this -> input -> post ( 'iota' , true ))),
'station_sota' => xss_clean ( strtoupper ( $this -> input -> post ( 'sota' , true ))),
2022-08-17 14:33:15 +02:00
'station_wwff' => xss_clean ( strtoupper ( $this -> input -> post ( 'wwff' , true ))),
2022-10-05 17:05:53 +02:00
'station_pota' => xss_clean ( strtoupper ( $this -> input -> post ( 'pota' , true ))),
2020-11-08 10:19:47 +01:00
'station_sig' => xss_clean ( strtoupper ( $this -> input -> post ( 'sig' , true ))),
'station_sig_info' => xss_clean ( strtoupper ( $this -> input -> post ( 'sig_info' , true ))),
2024-08-26 15:41:48 +02:00
'station_callsign' => xss_clean ( strtoupper ( $this -> input -> post ( 'station_callsign' , true ))),
2023-04-28 14:04:59 +02:00
'station_power' => is_numeric ( xss_clean ( $this -> input -> post ( 'station_power' , true ))) ? xss_clean ( $this -> input -> post ( 'station_power' , true )) : NULL ,
2019-10-05 22:02:28 +01:00
'station_dxcc' => xss_clean ( $this -> input -> post ( 'dxcc' , true )),
2024-02-23 15:48:55 +01:00
'station_cnty' => $county ,
2019-10-05 22:02:28 +01:00
'station_cq' => xss_clean ( $this -> input -> post ( 'station_cq' , true )),
'station_itu' => xss_clean ( $this -> input -> post ( 'station_itu' , true )),
2023-06-15 13:22:13 +01:00
'state' => $state ,
2023-07-07 11:33:15 +00:00
'eqslqthnickname' => xss_clean ( $this -> input -> post ( 'eqslnickname' , true )),
2023-12-15 23:04:34 +01:00
'hrdlog_username' => xss_clean ( $this -> input -> post ( 'hrdlog_username' , true )),
2023-07-07 11:33:15 +00:00
'hrdlog_code' => xss_clean ( $this -> input -> post ( 'hrdlog_code' , true )),
'hrdlogrealtime' => xss_clean ( $this -> input -> post ( 'hrdlogrealtime' , true )),
2024-04-21 16:43:25 +02:00
'clublogignore' => xss_clean ( $this -> input -> post ( 'clublogignore' , true )),
2023-11-27 14:28:22 +00:00
'clublogrealtime' => xss_clean ( $this -> input -> post ( 'clublogrealtime' , true )),
2023-07-07 11:33:15 +00:00
'qrzapikey' => xss_clean ( $this -> input -> post ( 'qrzapikey' , true )),
'qrzrealtime' => xss_clean ( $this -> input -> post ( 'qrzrealtime' , true )),
2024-06-15 00:28:44 +02:00
'oqrs' => xss_clean ( $this -> input -> post ( 'oqrs' , true ) ? ? '0' ),
'oqrs_email' => xss_clean ( $this -> input -> post ( 'oqrsemail' , true ) ? ? '0' ),
2022-11-15 18:29:33 +01:00
'oqrs_text' => xss_clean ( $this -> input -> post ( 'oqrstext' , true )),
2023-03-16 18:58:48 +00:00
'webadifapikey' => xss_clean ( $this -> input -> post ( 'webadifapikey' , true )),
'webadifapiurl' => 'https://qo100dx.club/api' ,
'webadifrealtime' => xss_clean ( $this -> input -> post ( 'webadifrealtime' , true )),
2019-01-01 19:14:25 +00:00
);
2023-11-29 14:17:58 +01:00
// Insert Records & return insert id //
2024-03-03 21:52:51 +01:00
if ( $this -> db -> insert ( 'station_profile' , $data )) {
$new_station_id = $this -> db -> insert_id ();
$eqsl_default_qslmsg = xss_clean ( $this -> input -> post ( 'eqsl_default_qslmsg' , true ));
if ( ! empty ( trim ( $eqsl_default_qslmsg ))) {
$this -> user_options_model -> set_option ( 'eqsl_default_qslmsg' , 'key_station_id' , array ( $new_station_id => $eqsl_default_qslmsg ));
2023-11-29 14:17:58 +01:00
}
2024-03-03 21:52:51 +01:00
return $new_station_id ;
} else {
return 0 ;
2023-11-29 14:17:58 +01:00
}
2019-01-01 19:14:25 +00:00
}
function edit () {
2023-06-15 13:14:10 +01:00
2023-06-15 13:22:13 +01:00
// Check if the state is Canada and get the correct state
2023-06-15 13:14:10 +01:00
if ( $this -> input -> post ( 'dxcc' ) == 1 && $this -> input -> post ( 'station_ca_state' ) != " " ) {
2024-02-24 08:05:50 +01:00
$state = xss_clean ( $this -> input -> post ( 'station_ca_state' , true ));
2023-06-15 13:14:10 +01:00
} else {
2024-02-24 08:05:50 +01:00
$state = xss_clean ( $this -> input -> post ( 'station_state' , true ));
2023-06-15 13:14:10 +01:00
}
2023-06-15 13:22:13 +01:00
2024-02-23 15:48:55 +01:00
// Check if DXCC is USA, Alaska or Hawaii. If not true, we clear the County field due to complex adif specs
if (( $this -> input -> post ( 'dxcc' ) == 291 || $this -> input -> post ( 'dxcc' ) == 006 || $this -> input -> post ( 'dxcc' ) == 110 ) && $this -> input -> post ( 'station_cnty' ) != " " ) {
2024-02-24 08:05:50 +01:00
$county = xss_clean ( $this -> input -> post ( 'station_cnty' , true ));
2024-02-23 15:48:55 +01:00
} else {
$county = '' ;
}
2019-01-01 19:14:25 +00:00
$data = array (
2019-10-05 22:02:28 +01:00
'station_profile_name' => xss_clean ( $this -> input -> post ( 'station_profile_name' , true )),
2024-08-26 15:41:48 +02:00
'station_gridsquare' => xss_clean ( strtoupper ( $this -> input -> post ( 'gridsquare' , true ))),
2019-10-05 22:02:28 +01:00
'station_city' => xss_clean ( $this -> input -> post ( 'city' , true )),
2024-08-26 15:41:48 +02:00
'station_iota' => xss_clean ( strtoupper ( $this -> input -> post ( 'iota' , true ))),
'station_sota' => xss_clean ( strtoupper ( $this -> input -> post ( 'sota' , true ))),
'station_wwff' => xss_clean ( strtoupper ( $this -> input -> post ( 'wwff' , true ))),
'station_pota' => xss_clean ( strtoupper ( $this -> input -> post ( 'pota' , true ))),
'station_sig' => xss_clean ( strtoupper ( $this -> input -> post ( 'sig' , true ))),
'station_sig_info' => xss_clean ( strtoupper ( $this -> input -> post ( 'sig_info' , true ))),
'station_callsign' => xss_clean ( strtoupper ( $this -> input -> post ( 'station_callsign' , true ))),
2023-04-28 14:04:59 +02:00
'station_power' => is_numeric ( xss_clean ( $this -> input -> post ( 'station_power' , true ))) ? xss_clean ( $this -> input -> post ( 'station_power' , true )) : NULL ,
2019-10-05 22:02:28 +01:00
'station_dxcc' => xss_clean ( $this -> input -> post ( 'dxcc' , true )),
2024-02-23 15:48:55 +01:00
'station_cnty' => $county ,
2019-10-05 22:02:28 +01:00
'station_cq' => xss_clean ( $this -> input -> post ( 'station_cq' , true )),
'station_itu' => xss_clean ( $this -> input -> post ( 'station_itu' , true )),
2023-06-15 13:14:10 +01:00
'state' => $state ,
2019-10-05 22:02:28 +01:00
'eqslqthnickname' => xss_clean ( $this -> input -> post ( 'eqslnickname' , true )),
2023-12-15 23:04:34 +01:00
'hrdlog_username' => xss_clean ( $this -> input -> post ( 'hrdlog_username' , true )),
2023-07-07 11:33:15 +00:00
'hrdlog_code' => xss_clean ( $this -> input -> post ( 'hrdlog_code' , true )),
'hrdlogrealtime' => xss_clean ( $this -> input -> post ( 'hrdlogrealtime' , true )),
2024-04-21 16:43:25 +02:00
'clublogignore' => xss_clean ( $this -> input -> post ( 'clublogignore' , true )),
2023-11-27 14:28:22 +00:00
'clublogrealtime' => xss_clean ( $this -> input -> post ( 'clublogrealtime' , true )),
2023-07-07 11:33:15 +00:00
'qrzapikey' => xss_clean ( $this -> input -> post ( 'qrzapikey' , true )),
'qrzrealtime' => xss_clean ( $this -> input -> post ( 'qrzrealtime' , true )),
2024-06-15 00:28:44 +02:00
'oqrs' => xss_clean ( $this -> input -> post ( 'oqrs' , true ) ? ? '0' ),
'oqrs_email' => xss_clean ( $this -> input -> post ( 'oqrsemail' , true ) ? ? '0' ),
2022-11-15 18:29:33 +01:00
'oqrs_text' => xss_clean ( $this -> input -> post ( 'oqrstext' , true )),
2023-03-16 18:58:48 +00:00
'webadifapikey' => xss_clean ( $this -> input -> post ( 'webadifapikey' , true )),
'webadifapiurl' => 'https://qo100dx.club/api' ,
'webadifrealtime' => xss_clean ( $this -> input -> post ( 'webadifrealtime' , true )),
2019-01-01 19:14:25 +00:00
);
2021-10-31 10:17:14 +01:00
$this -> db -> where ( 'user_id' , $this -> session -> userdata ( 'user_id' ));
2019-10-05 22:02:28 +01:00
$this -> db -> where ( 'station_id' , xss_clean ( $this -> input -> post ( 'station_id' , true )));
2023-03-16 18:58:48 +00:00
$this -> db -> update ( 'station_profile' , $data );
2024-03-03 21:52:51 +01:00
$eqsl_default_qslmsg = xss_clean ( $this -> input -> post ( 'eqsl_default_qslmsg' , true ) ? ? '' );
$this -> user_options_model -> set_option ( 'eqsl_default_qslmsg' , 'key_station_id' , array ( xss_clean ( $this -> input -> post ( 'station_id' , true )) => $eqsl_default_qslmsg ));
2019-01-01 19:14:25 +00:00
}
2024-04-03 08:22:06 +00:00
function delete ( $id , $force = false , $user_id = null ) {
2019-10-05 19:16:05 +01:00
// Clean ID
$clean_id = $this -> security -> xss_clean ( $id );
2021-12-04 17:14:57 +01:00
// do not delete active station
2024-04-02 16:53:28 +00:00
if (( ! ( $force )) && ( $clean_id === $this -> find_active ())) {
2021-12-04 17:14:57 +01:00
return ;
}
2024-04-02 16:53:28 +00:00
# Del options for that station_id
2024-03-03 21:52:51 +01:00
$this -> user_options_model -> del_option ( 'eqsl_default_qslmsg' , 'key_station_id' , array ( 'option_key' => $id ));
2021-12-04 17:14:57 +01:00
2024-04-02 16:53:28 +00:00
// Delete Contents of log for that station_id
2024-04-03 08:22:06 +00:00
$this -> deletelog ( $clean_id , $user_id );
2019-12-03 19:16:40 +00:00
2024-04-02 16:53:28 +00:00
// Delete Station Profile, links, contests and oqrs-requests
$this -> db -> query ( " DELETE c FROM contest_session c WHERE c.station_id =? " , $clean_id );
$this -> db -> query ( " DELETE FROM oqrs WHERE station_id = ? " , $clean_id );
$this -> db -> query ( " DELETE FROM station_logbooks_relationship WHERE station_location_id = ? " , $clean_id );
2023-03-16 18:58:48 +00:00
$this -> db -> delete ( 'station_profile' , array ( 'station_id' => $clean_id ));
2019-01-01 19:14:25 +00:00
}
2024-04-03 08:22:06 +00:00
function deletelog ( $id , $user_id = null ) {
2024-04-02 16:53:28 +00:00
// Clean ID
$clean_id = $this -> security -> xss_clean ( $id );
2024-04-03 08:22:06 +00:00
$this -> load -> model ( 'qsl_model' );
$this -> load -> model ( 'eqsl_images' );
2024-04-02 16:53:28 +00:00
2024-04-03 08:22:06 +00:00
$qsos = $this -> db -> query ( " select COL_PRIMARY_KEY as id from " . $this -> config -> item ( 'table_name' ) . " where station_id=? " , $clean_id );
foreach ( $qsos -> result () as $qso ) {
$this -> qsl_model -> del_image_for_qso ( $qso -> id , $user_id );
$this -> eqsl_images -> del_image ( $qso -> id , $user_id );
}
2024-04-02 16:53:28 +00:00
// Delete QSOs
$this -> db -> query ( " DELETE FROM " . $this -> config -> item ( 'table_name' ) . " WHERE station_id = ? " , $clean_id );
2024-10-31 10:26:59 +01:00
// Also clean up static map images
if ( ! $this -> load -> is_loaded ( 'staticmap_model' )) {
$this -> load -> model ( 'staticmap_model' );
}
$this -> staticmap_model -> remove_static_map_image ( $clean_id );
2024-04-02 16:53:28 +00:00
}
2020-02-07 14:54:49 +01:00
2019-09-23 17:29:22 +01:00
function set_active ( $current , $new ) {
2019-10-05 19:16:05 +01:00
// Clean inputs
$clean_current = $this -> security -> xss_clean ( $current );
$clean_new = $this -> security -> xss_clean ( $new );
2021-10-31 09:56:45 +01:00
// be sure that stations belong to user
2021-10-31 10:17:14 +01:00
if ( $clean_current != 0 ) {
if ( ! $this -> check_station_is_accessible ( $clean_current )) {
return ;
}
2021-10-31 09:56:45 +01:00
}
2021-10-31 10:17:14 +01:00
if ( ! $this -> check_station_is_accessible ( $clean_new )) {
2021-10-31 09:56:45 +01:00
return ;
}
// Deselect current default
2019-09-23 17:29:22 +01:00
$current_default = array (
2021-10-31 09:56:45 +01:00
'station_active' => null ,
2019-09-23 17:29:22 +01:00
);
2021-10-31 09:56:45 +01:00
$this -> db -> where ( 'user_id' , $this -> session -> userdata ( 'user_id' ));
2019-09-23 17:29:22 +01:00
$this -> db -> update ( 'station_profile' , $current_default );
2021-10-31 09:56:45 +01:00
2023-03-16 18:58:48 +00:00
// Deselect current default
2019-09-23 17:29:22 +01:00
$newdefault = array (
'station_active' => 1 ,
);
2021-10-31 09:56:45 +01:00
$this -> db -> where ( 'user_id' , $this -> session -> userdata ( 'user_id' ));
2019-10-05 19:16:05 +01:00
$this -> db -> where ( 'station_id' , $clean_new );
2019-09-23 17:29:22 +01:00
$this -> db -> update ( 'station_profile' , $newdefault );
2021-10-31 09:56:45 +01:00
}
2024-03-03 21:52:51 +01:00
function edit_favourite ( $id ) {
$cleanid = $this -> security -> xss_clean ( $id );
$is_favorite = $this -> user_options_model -> get_options ( 'station_location' , array ( 'option_name' => 'is_favorite' , 'option_key' => $cleanid )) -> row () -> option_value ? ? 'false' ;
if ( $is_favorite == 'true' ) {
$this -> user_options_model -> del_option ( 'station_location' , 'is_favorite' , array ( 'option_key' => $cleanid ));
} else if ( $is_favorite == 'false' ) {
$this -> user_options_model -> set_option ( 'station_location' , 'is_favorite' , array ( $cleanid => 'true' ));
}
}
2021-10-31 09:56:45 +01:00
public function find_active () {
$this -> db -> where ( 'user_id' , $this -> session -> userdata ( 'user_id' ));
$this -> db -> where ( 'station_active' , 1 );
$query = $this -> db -> get ( 'station_profile' );
2019-09-23 17:29:22 +01:00
2021-10-31 09:56:45 +01:00
if ( $query -> num_rows () >= 1 ) {
foreach ( $query -> result () as $row )
2019-09-23 17:29:22 +01:00
{
return $row -> station_id ;
}
2021-10-31 09:56:45 +01:00
} else {
2019-09-23 17:29:22 +01:00
return " 0 " ;
}
2020-02-18 10:49:27 +01:00
}
2023-03-16 18:58:48 +00:00
2024-01-29 12:41:06 +00:00
public function gridsquare_from_station ( $station_id ) {
$this -> db -> where ( 'station_id' , $station_id );
$query = $this -> db -> get ( 'station_profile' );
if ( $query -> num_rows () >= 1 ) {
2024-01-29 12:46:05 +00:00
foreach ( $query -> result () as $row ) {
2024-01-29 12:41:06 +00:00
return $row -> station_gridsquare ;
}
} else {
2024-01-29 12:46:05 +00:00
return null ;
2024-01-29 12:41:06 +00:00
}
}
2020-02-18 10:49:27 +01:00
public function find_gridsquare () {
2021-10-31 09:56:45 +01:00
$this -> db -> where ( 'user_id' , $this -> session -> userdata ( 'user_id' ));
$this -> db -> where ( 'station_active' , 1 );
$query = $this -> db -> get ( 'station_profile' );
if ( $query -> num_rows () >= 1 ) {
foreach ( $query -> result () as $row )
2020-02-18 10:49:27 +01:00
{
return $row -> station_gridsquare ;
}
2021-10-31 09:56:45 +01:00
} else {
2020-02-18 10:49:27 +01:00
return " 0 " ;
}
2021-10-31 09:56:45 +01:00
}
2019-09-23 17:29:22 +01:00
2022-05-02 12:38:55 +02:00
public function find_name () {
$this -> db -> where ( 'user_id' , $this -> session -> userdata ( 'user_id' ));
$this -> db -> where ( 'station_active' , 1 );
$query = $this -> db -> get ( 'station_profile' );
if ( $query -> num_rows () >= 1 ) {
foreach ( $query -> result () as $row )
{
return $row -> station_profile_name ;
}
} else {
return " 0 " ;
}
}
2019-09-23 17:29:22 +01:00
public function reassign ( $id ) {
2024-02-07 17:29:32 +00:00
// DANGEROUS Function. Do not let any User without Admin call this one!!
2019-10-05 19:16:05 +01:00
// Clean ID
$clean_id = $this -> security -> xss_clean ( $id );
2023-04-25 00:13:49 +02:00
$this -> db -> select ( 'station_profile.*, dxcc_entities.name as station_country' );
$this -> db -> where ( 'station_id' , $clean_id );
2023-04-28 15:14:59 +02:00
$this -> db -> join ( 'dxcc_entities' , 'station_profile.station_dxcc = dxcc_entities.adif' , 'left outer' );
2019-09-23 17:29:22 +01:00
$query = $this -> db -> get ( 'station_profile' );
$row = $query -> row ();
//print_r($row);
$data = array (
'station_id' => $id ,
);
$this -> db -> where ( 'COL_STATION_CALLSIGN' , $row -> station_callsign );
2023-03-16 18:58:48 +00:00
2019-09-23 17:29:22 +01:00
if ( $row -> station_iota != " " ) {
2019-09-23 18:35:56 +01:00
$this -> db -> where ( 'COL_MY_IOTA' , $row -> station_iota );
2019-09-23 17:29:22 +01:00
}
if ( $row -> station_sota != " " ) {
$this -> db -> where ( 'COL_MY_SOTA_REF' , $row -> station_sota );
}
2022-08-17 14:33:15 +02:00
if ( $row -> station_wwff != " " ) {
$this -> db -> where ( 'COL_MY_WWFF_REF' , $row -> station_wwff );
}
2022-10-05 17:05:53 +02:00
if ( $row -> station_pota != " " ) {
$this -> db -> where ( 'COL_MY_POTA_REF' , $row -> station_pota );
}
2020-11-08 21:46:57 +01:00
if ( $row -> station_sig != " " ) {
$this -> db -> where ( 'COL_MY_SIG' , $row -> station_sig );
}
if ( $row -> station_sig_info != " " ) {
$this -> db -> where ( 'COL_MY_SIG_INFO' , $row -> station_sig_info );
}
2019-09-23 17:29:22 +01:00
$this -> db -> where ( 'COL_MY_COUNTRY' , $row -> station_country );
if ( strpos ( $row -> station_gridsquare , ',' ) !== false ) {
$this -> db -> where ( 'COL_MY_VUCC_GRIDS' , $row -> station_gridsquare );
} else {
$this -> db -> where ( 'COL_MY_GRIDSQUARE' , $row -> station_gridsquare );
}
$this -> db -> update ( $this -> config -> item ( 'table_name' ), $data );
$str = $this -> db -> last_query ();
}
function profile_exists () {
$query = $this -> db -> get ( 'station_profile' );
if ( $query -> num_rows () >= 1 ) {
return 1 ;
} else {
return 0 ;
2023-03-16 18:58:48 +00:00
}
2019-09-23 17:29:22 +01:00
}
2023-07-07 11:33:15 +00:00
function stations_with_hrdlog_code () {
2023-12-16 07:48:19 +01:00
$sql = " SELECT station_profile.station_id, station_profile.station_profile_name, station_profile.station_callsign, modc.modcount, notc.notcount, totc.totcount
FROM station_profile
LEFT OUTER JOIN (
SELECT count ( * ) modcount , station_id
FROM " . $this->config ->item('table_name') .
" WHERE COL_HRDLOG_QSO_UPLOAD_STATUS = 'M'
2023-07-07 11:33:15 +00:00
group by station_id
) as modc on station_profile . station_id = modc . station_id
2023-12-16 07:48:19 +01:00
LEFT OUTER JOIN (
SELECT count ( * ) notcount , station_id
FROM " . $this->config ->item('table_name') .
" WHERE (coalesce(COL_HRDLOG_QSO_UPLOAD_STATUS, '') = ''
2023-07-07 11:33:15 +00:00
or COL_HRDLOG_QSO_UPLOAD_STATUS = 'N' )
group by station_id
) as notc on station_profile . station_id = notc . station_id
2023-12-16 07:48:19 +01:00
LEFT OUTER JOIN (
SELECT count ( * ) totcount , station_id
FROM " . $this->config ->item('table_name') .
" WHERE COL_HRDLOG_QSO_UPLOAD_STATUS = 'Y'
2023-07-07 11:33:15 +00:00
group by station_id
) as totc on station_profile . station_id = totc . station_id
2023-12-16 07:48:19 +01:00
WHERE coalesce ( station_profile . hrdlog_code , '' ) <> '' AND coalesce ( station_profile . hrdlog_username , '' ) <> ''
AND station_profile . user_id = " . $this->session ->userdata('user_id');
2023-07-07 11:33:15 +00:00
$query = $this -> db -> query ( $sql );
return $query ;
}
2019-09-23 17:29:22 +01:00
2020-05-20 19:43:13 +02:00
function stations_with_qrz_api_key () {
2024-09-12 15:54:37 +00:00
$bindings = [];
$sql = " SELECT station_profile.station_id, station_profile.station_profile_name, station_profile.station_callsign, modc.modcount, notc.notcount, totc.totcount
FROM station_profile
LEFT OUTER JOIN (
SELECT count ( * ) modcount , station_id
FROM " . $this->config ->item('table_name') .
" WHERE COL_QRZCOM_QSO_UPLOAD_STATUS = 'M'
group by station_id
) as modc on station_profile . station_id = modc . station_id
LEFT OUTER JOIN (
SELECT count ( * ) notcount , station_id
FROM " . $this->config ->item('table_name') .
" WHERE (coalesce(COL_QRZCOM_QSO_UPLOAD_STATUS, '') = ''
or COL_QRZCOM_QSO_UPLOAD_STATUS = 'N' )
group by station_id
) as notc on station_profile . station_id = notc . station_id
LEFT OUTER JOIN (
SELECT count ( * ) totcount , station_id
FROM " . $this->config ->item('table_name') .
" WHERE COL_QRZCOM_QSO_UPLOAD_STATUS = 'Y'
group by station_id
) as totc on station_profile . station_id = totc . station_id
WHERE coalesce ( station_profile . qrzapikey , '' ) <> ''
AND station_profile . user_id = ? " ;
$bindings [] = $this -> session -> userdata ( 'user_id' );
$query = $this -> db -> query ( $sql , $bindings );
return $query ;
2020-05-20 19:43:13 +02:00
}
2023-03-17 17:54:35 +00:00
function stations_with_webadif_api_key () {
2024-09-12 15:54:37 +00:00
$bindings = [];
2023-03-17 17:54:35 +00:00
$sql = "
SELECT station_profile . station_id , station_profile . station_profile_name , station_profile . station_callsign , notc . c notcount , totc . c totcount
FROM station_profile
2023-06-29 22:05:04 +02:00
LEFT OUTER JOIN (
2023-03-17 17:54:35 +00:00
SELECT qsos . station_id , COUNT ( qsos . COL_PRIMARY_KEY ) c
FROM % s qsos
LEFT JOIN webadif ON qsos . COL_PRIMARY_KEY = webadif . qso_id
2023-03-27 15:03:11 +01:00
WHERE webadif . qso_id IS NULL AND qsos . COL_SAT_NAME = 'QO-100'
2023-03-17 17:54:35 +00:00
GROUP BY qsos . station_id
2023-03-19 10:49:58 +00:00
) notc ON station_profile . station_id = notc . station_id
2023-06-29 22:05:04 +02:00
LEFT JOIN (
2023-03-17 17:54:35 +00:00
SELECT qsos . station_id , COUNT ( qsos . COL_PRIMARY_KEY ) c
FROM % s qsos
2023-03-27 15:03:11 +01:00
WHERE qsos . COL_SAT_NAME = 'QO-100'
2023-03-17 17:54:35 +00:00
GROUP BY qsos . station_id
2023-03-19 10:49:58 +00:00
) totc ON station_profile . station_id = totc . station_id
2023-03-17 17:54:35 +00:00
WHERE COALESCE ( station_profile . webadifapikey , '' ) <> ''
AND COALESCE ( station_profile . webadifapiurl , '' ) <> ''
2024-09-12 15:54:37 +00:00
AND station_profile . user_id = ?
2023-03-17 17:54:35 +00:00
" ;
2024-09-12 15:54:37 +00:00
$bindings [] = $this -> session -> userdata ( 'user_id' );
2023-03-17 17:54:35 +00:00
$sql = sprintf (
$sql ,
$this -> config -> item ( 'table_name' ),
2024-09-12 15:54:37 +00:00
$this -> config -> item ( 'table_name' )
2023-03-17 17:54:35 +00:00
);
2024-09-12 15:54:37 +00:00
return $this -> db -> query ( $sql , $bindings );
2023-03-17 17:54:35 +00:00
}
2020-09-15 22:49:05 +01:00
/*
* Function : are_eqsl_nicks_defined
* Description : Returns number of station profiles with eqslnicknames
*/
function are_eqsl_nicks_defined () {
$this -> db -> select ( 'eqslqthnickname' );
$this -> db -> where ( 'eqslqthnickname IS NOT NULL' );
$this -> db -> where ( 'eqslqthnickname !=' , '' );
$this -> db -> from ( 'station_profile' );
$query = $this -> db -> get ();
return $query -> num_rows ();
}
2021-10-31 10:17:14 +01:00
public function check_station_is_accessible ( $id ) {
// check if station belongs to user
2021-11-14 17:50:11 +01:00
$this -> db -> select ( 'station_id' );
2021-10-31 10:17:14 +01:00
$this -> db -> where ( 'user_id' , $this -> session -> userdata ( 'user_id' ));
$this -> db -> where ( 'station_id' , $id );
$query = $this -> db -> get ( 'station_profile' );
if ( $query -> num_rows () == 1 ) {
return true ;
}
return false ;
}
2023-04-27 23:02:57 +02:00
public function get_station_power ( $id ) {
$this -> db -> select ( 'station_power' );
$this -> db -> where ( 'user_id' , $this -> session -> userdata ( 'user_id' ));
$this -> db -> where ( 'station_id' , $id );
$query = $this -> db -> get ( 'station_profile' );
if ( $query -> num_rows () >= 1 ) {
foreach ( $query -> result () as $row )
{
return $row -> station_power ;
}
} else {
return null ;
}
}
2023-06-15 08:12:57 +02:00
public function check_station_against_user ( $stationid , $userid ) {
$this -> db -> select ( 'station_id' );
$this -> db -> where ( 'user_id' , $userid );
2023-06-15 09:26:17 +02:00
$this -> db -> where ( 'station_id' , $stationid );
2023-06-15 08:12:57 +02:00
$query = $this -> db -> get ( 'station_profile' );
if ( $query -> num_rows () == 1 ) {
return true ;
}
return false ;
}
2023-09-06 00:02:07 +02:00
public function check_station_against_callsign ( $stationid , $callsign ) {
$this -> db -> select ( 'station_id' );
$this -> db -> where ( 'station_callsign' , $callsign );
$this -> db -> where ( 'station_id' , $stationid );
$query = $this -> db -> get ( 'station_profile' );
if ( $query -> num_rows () == 1 ) {
return true ;
}
return false ;
}
2023-11-30 18:11:22 +01:00
2023-12-12 07:40:12 +01:00
// [MAP Custom] get array for json structure (for map) about info's station //
public function get_station_array_for_map () {
2023-11-30 18:11:22 +01:00
$_jsonresult = array ();
list ( $station_lat , $station_lng ) = array ( 0 , 0 );
$station_active = $this -> profile ( $this -> find_active ()) -> row ();
if ( ! empty ( $station_active )) { list ( $station_lat , $station_lng ) = $this -> qra -> qra2latlong ( $station_active -> station_gridsquare ); }
if (( $station_lat != 0 ) && ( $station_lng != 0 )) { $_jsonresult = array ( 'lat' => $station_lat , 'lng' => $station_lng , 'html' => $station_active -> station_gridsquare , 'label' => $station_active -> station_profile_name , 'icon' => 'stationIcon' ); }
2023-12-12 07:40:12 +01:00
return ( count ( $_jsonresult ) > 0 ) ? ( array ( 'station' => $_jsonresult )) : array ();
2023-11-30 18:11:22 +01:00
}
2019-01-01 19:14:25 +00:00
}
2022-05-02 12:38:55 +02:00
?>