2020-02-18 10:49:27 +01:00
< ? php
if ( ! defined ( 'BASEPATH' )) exit ( 'No direct script access allowed' );
class Distances_model extends CI_Model
{
2021-01-30 23:25:13 +01:00
2023-08-27 06:30:47 +00:00
function get_distances ( $postdata , $measurement_base ) {
2024-08-25 15:34:09 +02:00
$clean_postdata = $this -> security -> xss_clean ( $postdata );
2024-08-25 15:27:59 +02:00
$this -> load -> model ( 'logbooks_model' );
$logbooks_locations_array = $this -> logbooks_model -> list_logbook_relationships ( $this -> session -> userdata ( 'active_station_logbook' ));
2021-09-12 16:46:16 +02:00
2026-03-18 09:00:48 +01:00
if ( $logbooks_locations_array [ 0 ] === - 1 ) {
2023-08-27 06:30:47 +00:00
header ( 'Content-Type: application/json' );
echo json_encode ( array ( 'Error' => 'No QSOs found to plot.' ));
return ;
}
2021-11-14 17:57:33 +01:00
2021-09-12 16:46:16 +02:00
$result = array ();
2026-08-13 08:48:29 +02:00
$station_grid_found = 0 ;
2021-09-12 16:46:16 +02:00
foreach ( $logbooks_locations_array as $station_id ) {
$station_gridsquare = $this -> find_gridsquare ( $station_id );
2022-01-10 18:24:39 +01:00
if ( $station_gridsquare != null ) {
2026-08-13 08:48:29 +02:00
$station_grid_found = 1 ;
2021-09-12 16:46:16 +02:00
$gridsquare = explode ( ',' , $station_gridsquare ); // We need to convert to an array, since a user can enter several gridsquares
2026-05-07 13:09:36 +00:00
$table = $this -> config -> item ( 'table_name' );
$sql = "
2026-08-06 04:53:38 +00:00
SELECT COL_PRIMARY_KEY , COL_DISTANCE , COL_ANT_PATH , COL_ANT_AZ , COL_PROP_MODE , col_call callsign , col_gridsquare grid
2026-05-07 13:09:36 +00:00
FROM $table
LEFT OUTER JOIN satellite
ON $table . COL_PROP_MODE = 'SAT'
AND ( $table . COL_SAT_NAME = satellite . name
OR ( satellite . displayname != '' AND $table . COL_SAT_NAME = satellite . displayname ))
WHERE LENGTH ( col_gridsquare ) > 0 AND station_id = ?
" ;
$params = array ( $station_id );
2021-09-12 16:46:16 +02:00
2024-08-25 15:34:09 +02:00
if ( $clean_postdata [ 'band' ] != 'All' ) {
if ( $clean_postdata [ 'band' ] == 'sat' ) {
2026-05-07 13:09:36 +00:00
$sql .= " AND col_prop_mode = ? " ;
$params [] = $clean_postdata [ 'band' ];
2024-08-25 15:34:09 +02:00
if ( $clean_postdata [ 'sat' ] != 'All' ) {
2026-05-07 13:09:36 +00:00
$sql .= " AND col_sat_name = ? " ;
$params [] = $clean_postdata [ 'sat' ];
2024-06-26 14:51:20 +02:00
}
}
else {
2026-05-07 13:09:36 +00:00
$sql .= " AND col_band = ? " ;
$params [] = $clean_postdata [ 'band' ];
2021-09-12 16:46:16 +02:00
}
}
2022-01-16 17:44:53 +01:00
2024-08-25 15:34:09 +02:00
if ( $clean_postdata [ 'orbit' ] != 'All' ) {
2026-05-07 13:09:36 +00:00
$sql .= " AND satellite.orbit = ? " ;
$params [] = $clean_postdata [ 'orbit' ];
2024-04-12 13:29:53 +02:00
}
2024-09-04 09:47:51 +02:00
if ( $clean_postdata [ 'propagation' ] == 'NoSAT' ) { // All without SAT
2026-05-07 13:09:36 +00:00
$sql .= " AND col_prop_mode != 'SAT' " ;
2024-09-04 09:47:51 +02:00
} elseif ( $clean_postdata [ 'propagation' ] == 'None' ) { // Empty Propmode
2026-05-07 13:09:36 +00:00
$sql .= " AND (TRIM(col_prop_mode) = '' OR col_prop_mode IS NULL) " ;
2024-09-04 09:47:51 +02:00
} elseif ( $clean_postdata [ 'propagation' ] == 'All' ) { // Dont care for propmode
; // No Prop-Filter
} else { // Propmode set, take care of it
2026-05-07 13:09:36 +00:00
$sql .= " AND col_prop_mode = ? " ;
$params [] = $clean_postdata [ 'propagation' ];
2024-09-04 09:47:51 +02:00
}
2026-08-12 16:51:04 +02:00
if ( ! empty ( $clean_postdata [ 'mode' ]) && $clean_postdata [ 'mode' ] != 'All' ) {
$sql .= " AND (col_mode = ? OR col_submode = ?) " ;
$params [] = $clean_postdata [ 'mode' ];
$params [] = $clean_postdata [ 'mode' ];
}
2026-05-07 13:09:36 +00:00
$queryresult = $this -> db -> query ( $sql , $params );
2021-09-12 16:46:16 +02:00
2023-08-27 06:30:47 +00:00
if ( $queryresult -> result_array ()) {
$temp = $this -> plot ( $queryresult -> result_array (), $gridsquare , $measurement_base );
2023-07-16 18:10:11 +02:00
2023-08-27 06:30:47 +00:00
$result = $this -> mergeresult ( $result , $temp );
2022-10-05 14:31:33 +01:00
2023-08-27 06:30:47 +00:00
}
2021-09-12 16:46:16 +02:00
}
2022-10-05 14:31:33 +01:00
2021-09-12 16:46:16 +02:00
}
if ( $result ) {
header ( 'Content-Type: application/json' );
echo json_encode ( $result );
}
else {
2026-08-13 08:48:29 +02:00
if ( $station_grid_found == 0 ) {
header ( 'Content-Type: application/json' );
echo json_encode ( array ( 'Error' => 'No station gridsquare(s) found in active logbook. Please check.' ));
} else {
header ( 'Content-Type: application/json' );
echo json_encode ( array ( 'Error' => 'No QSOs found to plot.' ));
}
2021-09-12 16:46:16 +02:00
}
2023-08-27 06:30:47 +00:00
}
2020-02-18 10:49:27 +01:00
2021-09-12 16:46:16 +02:00
/*
* We merge the result from several station_id ' s . They can have different gridsquares , so we need to use the correct gridsquare to calculate the correct distance .
*/
2023-08-27 06:30:47 +00:00
function mergeresult ( $result , $add ) {
if ( sizeof ( $result ) > 0 ) {
2021-09-12 16:46:16 +02:00
if ( $result [ 'qrb' ][ 'Distance' ] < $add [ 'qrb' ][ 'Distance' ]) {
$result [ 'qrb' ][ 'Distance' ] = $add [ 'qrb' ][ 'Distance' ];
$result [ 'qrb' ][ 'Grid' ] = $add [ 'qrb' ][ 'Grid' ];
$result [ 'qrb' ][ 'Callsign' ] = $add [ 'qrb' ][ 'Callsign' ];
}
$result [ 'qrb' ][ 'Qsos' ] += $add [ 'qrb' ][ 'Qsos' ];
for ( $i = 0 ; $i <= 399 ; $i ++ ) {
2023-07-16 18:10:11 +02:00
2023-08-27 06:30:47 +00:00
if ( isset ( $result [ 'qsodata' ][ $i ][ 'count' ])) {
$result [ 'qsodata' ][ $i ][ 'count' ] += $add [ 'qsodata' ][ $i ][ 'count' ];
}
if ( isset ( $result [ 'qsodata' ][ $i ][ 'callcount' ])) {
if ( $result [ 'qsodata' ][ $i ][ 'callcount' ] < 5 && $add [ 'qsodata' ][ $i ][ 'callcount' ] > 0 ) {
$calls = explode ( ',' , $add [ 'qsodata' ][ $i ][ 'calls' ]);
foreach ( $calls as $c ) {
if ( $result [ 'qsodata' ][ $i ][ 'callcount' ] < 5 ) {
if ( $result [ 'qsodata' ][ $i ][ 'callcount' ] > 0 ) {
$result [ 'qsodata' ][ $i ][ 'calls' ] .= ', ' ;
}
$result [ 'qsodata' ][ $i ][ 'calls' ] .= $c ;
$result [ 'qsodata' ][ $i ][ 'callcount' ] ++ ;
}
}
}
}
2021-09-12 16:46:16 +02:00
}
return $result ;
}
2023-08-27 06:30:47 +00:00
return $add ;
2021-09-12 16:46:16 +02:00
}
/*
* Fetches the gridsquare from the station_id
*/
function find_gridsquare ( $station_id ) {
$this -> db -> where ( 'station_id' , $station_id );
2022-01-10 18:24:39 +01:00
2023-08-27 06:30:47 +00:00
$result = $this -> db -> get ( 'station_profile' ) -> row_array ();
2022-01-10 18:24:39 +01:00
2023-08-27 06:30:47 +00:00
if ( $result ) {
return $result [ 'station_gridsquare' ];
}
2022-01-10 18:24:39 +01:00
return null ;
2021-09-12 16:46:16 +02:00
}
2026-08-12 16:51:04 +02:00
/*
* Returns every mode / submode worked in the active logbook , lowercased and
* sorted . Used to populate the mode filter dropdown .
*/
function get_worked_modes () {
$this -> load -> model ( 'logbooks_model' );
$logbooks_locations_array = $this -> logbooks_model -> list_logbook_relationships ( $this -> session -> userdata ( 'active_station_logbook' ));
if ( $logbooks_locations_array [ 0 ] === - 1 ) {
return array ();
}
$location_list = " ' " . implode ( " ',' " , $logbooks_locations_array ) . " ' " ;
// get all worked modes from database
$data = $this -> db -> query (
" SELECT distinct LOWER(`COL_MODE`) as `COL_MODE` FROM ` " . $this -> config -> item ( 'table_name' ) . " ` WHERE station_id in ( " . $location_list . " ) order by COL_MODE ASC "
);
$results = array ();
foreach ( $data -> result () as $row ) {
array_push ( $results , $row -> COL_MODE );
}
$data = $this -> db -> query (
" SELECT distinct LOWER(`COL_SUBMODE`) as `COL_SUBMODE` FROM ` " . $this -> config -> item ( 'table_name' ) . " ` WHERE station_id in ( " . $location_list . " ) and coalesce(COL_SUBMODE, '') <> '' order by COL_SUBMODE ASC "
);
foreach ( $data -> result () as $row ) {
if ( ! in_array ( $row , $results )) {
array_push ( $results , $row -> COL_SUBMODE );
}
}
asort ( $results );
return $results ;
}
2020-02-18 10:49:27 +01:00
// This functions takes query result from the database and extracts grids from the qso,
// then calculates distance between homelocator and locator given in qso.
// It builds an array, which has 50km intervals, then inputs each length into the correct spot
// The function returns a json-encoded array.
2023-08-27 05:37:16 +00:00
function plot ( $qsoArray , $gridsquare , $measurement_base ) {
2024-07-15 05:59:47 +02:00
if ( ! $this -> load -> is_loaded ( 'Qra' )) {
$this -> load -> library ( 'Qra' );
}
2023-08-27 05:37:16 +00:00
$stationgrid = strtoupper ( $gridsquare [ 0 ]); // We use only the first entered gridsquare from the active profile
if ( strlen ( $stationgrid ) == 4 ) $stationgrid .= 'MM' ; // adding center of grid if only 4 digits are specified
switch ( $measurement_base ) {
case 'M' :
$unit = " mi " ;
2026-03-06 17:48:14 +01:00
$dist = '26000' ;
2023-08-27 05:37:16 +00:00
break ;
case 'K' :
$unit = " km " ;
2026-03-06 17:48:14 +01:00
$dist = '40050' ;
2023-08-27 05:37:16 +00:00
break ;
case 'N' :
$unit = " nmi " ;
2026-03-06 17:48:14 +01:00
$dist = '22000' ;
2023-08-27 05:37:16 +00:00
break ;
default :
$unit = " km " ;
2026-03-06 17:48:14 +01:00
$dist = '40050' ;
2023-08-27 05:37:16 +00:00
}
2020-11-20 11:55:55 +01:00
2023-08-27 05:37:16 +00:00
if ( ! $this -> valid_locator ( $stationgrid )) {
header ( 'Content-Type: application/json' );
2025-05-02 11:43:32 +02:00
echo json_encode ( array ( 'Error' => 'Error. There is a problem with the gridsquare (' . $stationgrid . ') set in your profile!' ));
2023-08-27 05:37:16 +00:00
exit ;
} else {
2026-03-06 16:08:49 +00:00
// Build the chart buckets in 50-unit steps up to the max chart distance ($dist).
// Each bucket covers a 50-unit range, e.g. in km mode:
// $dataarray[0] => "0km - 50km"
// $dataarray[1] => "50km - 100km"
// ...
2026-03-06 17:48:14 +01:00
// till 40050 (longpath)
2023-08-27 05:37:16 +00:00
$j = 0 ;
for ( $i = 0 ; $j < $dist ; $i ++ ) {
$dataarray [ $i ][ 'dist' ] = $j . $unit . ' - ' . ( $j + 50 ) . $unit ;
$dataarray [ $i ][ 'count' ] = 0 ;
$dataarray [ $i ][ 'calls' ] = '' ;
$dataarray [ $i ][ 'callcount' ] = 0 ;
$j += 50 ;
}
$qrb = array ( // Used for storing the QSO with the longest QRB
'Callsign' => '' ,
'Grid' => '' ,
'Distance' => '' ,
2024-02-04 16:36:56 +00:00
'Qsos' => 0 ,
2023-08-27 05:37:16 +00:00
'Grids' => ''
);
foreach ( $qsoArray as $qso ) {
$qrb [ 'Qsos' ] ++ ; // Counts up number of qsos
2024-11-21 15:26:35 +01:00
$bearingdistance = $this -> qra -> distance ( $stationgrid , $qso [ 'grid' ], $measurement_base , $qso [ 'COL_ANT_PATH' ]);
$bearingdistance_km = $this -> qra -> distance ( $stationgrid , $qso [ 'grid' ], 'K' , $qso [ 'COL_ANT_PATH' ]);
2026-08-06 04:53:38 +00:00
2026-08-06 08:50:34 +00:00
$updatedata = $this -> geodata_update ( $stationgrid , $qso , false , $bearingdistance_km );
2026-08-06 04:53:38 +00:00
if ( ! empty ( $updatedata )) {
2024-02-04 21:49:36 +01:00
$this -> db -> where ( 'COL_PRIMARY_KEY' , $qso [ 'COL_PRIMARY_KEY' ]);
2026-08-06 04:53:38 +00:00
$this -> db -> update ( $this -> config -> item ( 'table_name' ), $updatedata );
2023-08-27 05:37:16 +00:00
}
$arrayplacement = ( int )( $bearingdistance / 50 ); // Resolution is 50, calculates where to put result in array
if ( $bearingdistance > $qrb [ 'Distance' ]) { // Saves the longest QSO
$qrb [ 'Distance' ] = $bearingdistance ;
$qrb [ 'Callsign' ] = $qso [ 'callsign' ];
$qrb [ 'Grid' ] = $qso [ 'grid' ];
}
2026-03-06 16:08:49 +00:00
if ( ! isset ( $dataarray [ $arrayplacement ])) { // QSO distance exceeds chart range, skip plotting
continue ;
}
2023-08-27 05:37:16 +00:00
$dataarray [ $arrayplacement ][ 'count' ] ++ ; // Used for counting total qsos plotted
if ( $dataarray [ $arrayplacement ][ 'callcount' ] < 5 ) { // Used for tooltip in graph, set limit to 5 calls shown
if ( $dataarray [ $arrayplacement ][ 'callcount' ] > 0 ) {
$dataarray [ $arrayplacement ][ 'calls' ] .= ', ' ;
}
$dataarray [ $arrayplacement ][ 'calls' ] .= $qso [ 'callsign' ];
$dataarray [ $arrayplacement ][ 'callcount' ] ++ ;
}
}
2021-09-12 16:46:16 +02:00
$data [ 'ok' ] = 'OK' ;
$data [ 'qrb' ] = $qrb ;
$data [ 'qsodata' ] = $dataarray ;
$data [ 'unit' ] = $unit ;
2023-08-27 05:37:16 +00:00
return $data ;
}
}
2020-02-18 10:49:27 +01:00
2026-08-06 08:50:34 +00:00
/*
* Works out which geodata - columns of a single QSO need writing .
* Input : $stationgrid gridsquare of the station_profile ( uppercase , at least 6 chars )
* $qso row containing COL_DISTANCE , COL_ANT_PATH , COL_ANT_AZ , COL_PROP_MODE and grid
* $only_if_empty true : only fill a missing distance ( Antenna Analytics repairs gaps only )
* false : also refresh a stale distance ( Distances Worked recalculates )
* $distance_km already calculated distance in km , saves recalculating it
* Returns : array of columns to update , empty if there is nothing to do
*/
private function geodata_update ( $stationgrid , $qso , $only_if_empty = false , $distance_km = null ) {
if ( ! $this -> load -> is_loaded ( 'Qra' )) {
$this -> load -> library ( 'Qra' );
}
if ( $distance_km === null ) {
$distance_km = $this -> qra -> distance ( $stationgrid , $qso [ 'grid' ], 'K' , $qso [ 'COL_ANT_PATH' ]);
}
$updatedata = array ();
$distance_missing = ( $qso [ 'COL_DISTANCE' ] === null || $qso [ 'COL_DISTANCE' ] === '' );
if ( $only_if_empty ? $distance_missing : ( $distance_km != $qso [ 'COL_DISTANCE' ])) {
$updatedata [ 'COL_DISTANCE' ] = $distance_km ;
}
$is_shortwave = trim (( string ) $qso [ 'COL_PROP_MODE' ]) === '' ; // only plain HF/VHF+ terrestrial QSOs -- SAT, EME, MS, etc. don't follow the great-circle bearing
if ( $is_shortwave && ( $qso [ 'COL_ANT_AZ' ] === null || $qso [ 'COL_ANT_AZ' ] === '' )) { // only fill if empty -- never overwrite a user/ADIF-supplied value
$bearing = $this -> qra -> get_bearing ( $stationgrid , $qso [ 'grid' ], $qso [ 'COL_ANT_PATH' ]);
if ( $bearing !== false ) { // unparsable qso-grid: leave the column NULL rather than stamping it with 0 (= due north)
$updatedata [ 'COL_ANT_AZ' ] = $bearing ;
}
}
return $updatedata ;
}
/*
* Fills distance and bearing for QSOs of the active logbook which are still missing them .
* Called when opening a page which reads those columns ( e . g . Antenna Analytics ), so a log
* imported without ANT_AZ / DISTANCE gets repaired without having to visit Distances Worked .
* Only gaps are filled , existing values are never touched .
*/
public function backfill_missing_geodata () {
$this -> load -> model ( 'logbooks_model' );
$logbooks_locations_array = $this -> logbooks_model -> list_logbook_relationships ( $this -> session -> userdata ( 'active_station_logbook' ));
if ( $logbooks_locations_array [ 0 ] === - 1 ) {
return ;
}
$table = $this -> config -> item ( 'table_name' );
foreach ( $logbooks_locations_array as $station_id ) {
$station_gridsquare = $this -> find_gridsquare ( $station_id );
if ( $station_gridsquare == null ) {
continue ;
}
$gridsquare = explode ( ',' , $station_gridsquare ); // A user can enter several gridsquares
$stationgrid = strtoupper ( trim ( $gridsquare [ 0 ])); // We use only the first entered gridsquare from the active profile
if ( strlen ( $stationgrid ) == 4 ) $stationgrid .= 'MM' ; // adding center of grid if only 4 digits are specified
if ( ! $this -> valid_locator ( $stationgrid )) { // Broken profile-grid: skip this station, this runs while rendering a page
continue ;
}
$sql = "
SELECT COL_PRIMARY_KEY , COL_DISTANCE , COL_ANT_PATH , COL_ANT_AZ , COL_PROP_MODE , col_gridsquare grid
FROM $table
WHERE LENGTH ( col_gridsquare ) > 0
AND station_id = ?
AND (
COL_DISTANCE IS NULL
OR ( COL_ANT_AZ IS NULL AND ( COL_PROP_MODE IS NULL OR TRIM ( COL_PROP_MODE ) = '' ))
)
" ;
$qsoArray = $this -> db -> query ( $sql , array ( $station_id )) -> result_array ();
if ( ! $qsoArray ) {
continue ;
}
$this -> db -> trans_start ();
foreach ( $qsoArray as $qso ) {
$updatedata = $this -> geodata_update ( $stationgrid , $qso , true );
if ( ! empty ( $updatedata )) {
$this -> db -> where ( 'COL_PRIMARY_KEY' , $qso [ 'COL_PRIMARY_KEY' ]);
$this -> db -> update ( $table , $updatedata );
}
}
$this -> db -> trans_complete ();
}
}
2020-02-18 10:49:27 +01:00
/*
* Checks the validity of the locator
* Input : locator
* Returns : bool
*/
2023-08-27 06:30:47 +00:00
function valid_locator ( $loc ) {
2024-02-04 21:49:36 +01:00
$loc = strtoupper ( $loc );
if ( strlen ( $loc ) == 4 ) $loc .= " LL " ; // Only 4 Chars? Fill with center "LL" as only A-R allowed
if ( strlen ( $loc ) == 6 ) $loc .= " 55 " ; // Only 6 Chars? Fill with center "55"
if ( strlen ( $loc ) == 8 ) $loc .= " LL " ; // Only 8 Chars? Fill with center "LL" as only A-R allowed
if ( preg_match ( '/^[A-R]{2}[0-9]{2}[A-X]{2}[0-9]{2}[A-X]{2}$/' , $loc )) {
2023-08-27 06:30:47 +00:00
return true ;
}
else {
return false ;
}
}
2023-07-16 18:10:11 +02:00
2024-02-04 21:49:36 +01:00
/*
2023-07-16 18:10:11 +02:00
* Used to fetch QSOs from the logbook in the awards
*/
2026-08-12 16:51:04 +02:00
public function qso_details ( $distance , $band , $sat , $propagation , $mode = 'All' ){
2023-07-16 18:10:11 +02:00
$distarray = $this -> getdistparams ( $distance );
2024-08-25 15:27:59 +02:00
$this -> load -> model ( 'logbooks_model' );
$logbooks_locations_array = $this -> logbooks_model -> list_logbook_relationships ( $this -> session -> userdata ( 'active_station_logbook' ));
2023-07-16 18:10:11 +02:00
2026-05-07 13:09:36 +00:00
$table = $this -> config -> item ( 'table_name' );
$sql = "
SELECT dxcc_entities . adif , lotw_users . callsign , COL_BAND , COL_CALL , COL_CLUBLOG_QSO_DOWNLOAD_DATE ,
COL_CLUBLOG_QSO_DOWNLOAD_STATUS , COL_CLUBLOG_QSO_UPLOAD_DATE , COL_CLUBLOG_QSO_UPLOAD_STATUS , COL_CONTEST_ID , COL_DISTANCE ,
COL_EQSL_QSL_RCVD , COL_EQSL_QSLRDATE , COL_EQSL_QSLSDATE , COL_EQSL_QSL_SENT , COL_FREQ , COL_GRIDSQUARE , COL_IOTA , COL_LOTW_QSL_RCVD ,
COL_LOTW_QSLRDATE , COL_LOTW_QSLSDATE , COL_LOTW_QSL_SENT , COL_MODE , COL_NAME , COL_OPERATOR , COL_POTA_REF , COL_PRIMARY_KEY ,
COL_QRZCOM_QSO_DOWNLOAD_DATE , COL_QRZCOM_QSO_DOWNLOAD_STATUS , COL_QRZCOM_QSO_UPLOAD_DATE , COL_QRZCOM_QSO_UPLOAD_STATUS ,
COL_QSL_RCVD , COL_QSL_RCVD_VIA , COL_QSLRDATE , COL_QSLSDATE , COL_QSL_SENT , COL_QSL_SENT_VIA , COL_QSL_VIA , COL_RST_RCVD ,
COL_RST_SENT , COL_SAT_NAME , COL_SOTA_REF , COL_SRX , COL_SRX_STRING , COL_STATE , COL_STX , COL_STX_STRING , COL_SUBMODE , COL_TIME_ON ,
2026-05-08 17:28:23 +02:00
COL_VUCC_GRIDS , COL_WWFF_REF , COL_PROP_MODE , COL_DCL_QSLRDATE , COL_DCL_QSLSDATE , COL_DCL_QSL_SENT , COL_DCL_QSL_RCVD ,
dxcc_entities . end , lotw_users . lastupload , dxcc_entities . name , satellite . displayname AS sat_displayname ,
2026-05-07 13:09:36 +00:00
station_profile . station_callsign , station_profile . station_gridsquare , station_profile . station_profile_name
FROM $table
INNER JOIN station_profile ON station_profile . station_id = $table . station_id
LEFT OUTER JOIN dxcc_entities ON dxcc_entities . adif = $table . COL_DXCC
LEFT OUTER JOIN lotw_users ON lotw_users . callsign = $table . col_call
LEFT OUTER JOIN satellite
ON $table . COL_PROP_MODE = 'SAT'
AND ( $table . COL_SAT_NAME = satellite . name
OR ( satellite . displayname != '' AND $table . COL_SAT_NAME = satellite . displayname ))
WHERE COL_DISTANCE >= ? AND COL_DISTANCE <= ? AND LENGTH ( col_gridsquare ) > 0
" ;
$params = array ( $distarray [ 0 ], $distarray [ 1 ]);
$placeholders = '' ;
foreach ( $logbooks_locations_array as $idx => $station_id ) {
$placeholders .= $idx > 0 ? ',?' : '?' ;
$params [] = $station_id ;
}
$sql .= " AND $table .station_id IN ( $placeholders ) " ;
2023-07-16 18:10:11 +02:00
if ( $band != 'All' ) {
if ( $band != " sat " ) {
2026-05-07 13:09:36 +00:00
$sql .= " AND (COL_PROP_MODE != 'SAT' OR COL_PROP_MODE IS NULL) " ;
$sql .= " AND COL_BAND = ? " ;
$params [] = $band ;
2023-07-16 18:10:11 +02:00
} else {
2026-05-07 13:09:36 +00:00
$sql .= " AND COL_PROP_MODE = 'SAT' " ;
2023-07-16 18:10:11 +02:00
if ( $sat != 'All' ) {
2026-05-07 13:09:36 +00:00
$sql .= " AND COL_SAT_NAME = ? " ;
$params [] = $sat ;
2023-07-16 18:10:11 +02:00
}
}
}
2024-09-04 09:47:51 +02:00
if ( $propagation == 'NoSAT' ) { // All without SAT
2026-05-07 13:09:36 +00:00
$sql .= " AND col_prop_mode != 'SAT' " ;
2024-09-04 09:47:51 +02:00
} elseif ( $propagation == 'None' ) { // Empty Propmode
2026-05-07 13:09:36 +00:00
$sql .= " AND (TRIM(col_prop_mode) = '' OR col_prop_mode IS NULL) " ;
2024-09-04 09:47:51 +02:00
} elseif ( $propagation == 'All' ) { // Dont care for propmode
; // No Prop-Filter
} else { // Propmode set, take care of it
2026-05-07 13:09:36 +00:00
$sql .= " AND col_prop_mode = ? " ;
$params [] = $propagation ;
2024-09-04 09:47:51 +02:00
}
2023-07-16 18:10:11 +02:00
2026-08-12 16:51:04 +02:00
if ( $mode != 'All' && $mode != '' ) {
$sql .= " AND (col_mode = ? OR col_submode = ?) " ;
$params [] = $mode ;
$params [] = $mode ;
}
2026-05-07 13:09:36 +00:00
$sql .= " ORDER BY COL_TIME_ON DESC " ;
return $this -> db -> query ( $sql , $params );
2023-07-16 18:10:11 +02:00
}
function getdistparams ( $distance ) {
$temp = explode ( '-' , $distance );
$regex = '[a-zA-Z]+' ;
2023-08-27 06:30:47 +00:00
preg_match ( " % { $regex } %i " , $temp [ 0 ], $unit );
2023-07-16 18:10:11 +02:00
$result = [];
$result [ 0 ] = filter_var ( $temp [ 0 ], FILTER_SANITIZE_NUMBER_INT );
$result [ 1 ] = filter_var ( $temp [ 1 ], FILTER_SANITIZE_NUMBER_INT );
if ( $unit [ 0 ] == 'mi' ) {
$result [ 0 ] *= 1.609344 ;
$result [ 1 ] *= 1.609344 ;
}
if ( $unit [ 0 ] == 'nmi' ) {
$result [ 0 ] *= 1.852 ;
$result [ 1 ] *= 1.852 ;
}
return $result ;
}
2021-09-12 16:46:16 +02:00
}