2022-12-18 16:49:54 +01:00
< ? php
2024-01-17 14:20:10 +00:00
use Wavelog\QSLManager\QSO ;
2022-12-18 16:49:54 +01:00
class Logbookadvanced_model extends CI_Model {
2023-08-18 20:02:47 +02:00
2024-05-24 11:25:44 +02:00
private $logbooks_locations_array ;
public function __construct ()
{
$this -> load -> model ( 'logbooks_model' );
$this -> logbooks_locations_array = $this -> logbooks_model -> list_logbook_relationships ( $this -> session -> userdata ( 'active_station_logbook' ));
}
2023-08-18 20:02:47 +02:00
public function searchDb ( $searchCriteria ) {
2022-12-18 16:49:54 +01:00
$conditions = [];
$binding = [ $searchCriteria [ 'user_id' ]];
2023-10-19 04:56:45 +00:00
if (( isset ( $searchCriteria [ 'dupes' ])) && ( $searchCriteria [ 'dupes' ] !== '' )) {
2023-11-23 20:43:45 +01:00
$id_sql = " select GROUP_CONCAT(col_primary_key separator ',') as qsoids, COL_CALL, COL_MODE, COL_SUBMODE, station_callsign, COL_SAT_NAME, COL_BAND, min(col_time_on) Mintime, max(col_time_on) Maxtime from " . $this -> config -> item ( 'table_name' ) . "
2024-06-28 14:55:52 +02:00
join station_profile on " . $this->config ->item('table_name') . " . station_id = station_profile . station_id where station_profile . user_id = ?
2024-02-28 10:38:32 +01:00
group by col_call , col_mode , COL_SUBMODE , STATION_CALLSIGN , col_band , COL_SAT_NAME having count ( * ) > 1 and timediff ( maxtime , mintime ) < 1500 " ;
2023-10-17 10:14:10 +00:00
$id_query = $this -> db -> query ( $id_sql , $searchCriteria [ 'user_id' ]);
2023-11-23 20:43:45 +01:00
$ids2fetch = '' ;
2023-10-17 10:14:10 +00:00
foreach ( $id_query -> result () as $id ) {
2023-11-23 20:43:45 +01:00
$ids2fetch .= ',' . $id -> qsoids ;
2023-10-17 10:14:10 +00:00
}
2023-11-23 20:43:45 +01:00
$ids2fetch = ltrim ( $ids2fetch , ',' );
2023-10-17 12:23:40 +00:00
if ( $ids2fetch ? ? '' !== '' ) {
2023-10-17 10:14:10 +00:00
$conditions [] = " qsos.COL_PRIMARY_KEY in ( " . $ids2fetch . " ) " ;
2023-10-17 12:23:40 +00:00
} else {
$conditions [] = " 1=0 " ;
2023-10-17 10:14:10 +00:00
}
}
2024-08-29 12:49:14 +02:00
if (( isset ( $searchCriteria [ 'invalid' ])) && ( $searchCriteria [ 'invalid' ] !== '' )) {
$id_sql = "
select GROUP_CONCAT ( col_primary_key separator ',' ) as qsoids from (
select col_primary_key from " . $this->config ->item('table_name') . "
join station_profile on " . $this->config ->item('table_name') . " . station_id = station_profile . station_id
where station_profile . user_id = ?
2024-11-29 09:27:46 +01:00
and ( coalesce ( col_mode , '' ) = '' or col_mode = '0' )
2024-08-29 12:49:14 +02:00
union all
select col_primary_key from " . $this->config ->item('table_name') . "
join station_profile on " . $this->config ->item('table_name') . " . station_id = station_profile . station_id
where station_profile . user_id = ?
and coalesce ( col_band , '' ) = ''
union all
select col_primary_key from " . $this->config ->item('table_name') . "
join station_profile on " . $this->config ->item('table_name') . " . station_id = station_profile . station_id
where station_profile . user_id = ?
and coalesce ( col_call , '' ) = ''
union all
select col_primary_key from " . $this->config ->item('table_name') . "
join station_profile on " . $this->config ->item('table_name') . " . station_id = station_profile . station_id
where station_profile . user_id = ?
and ( col_time_on is null or cast ( col_time_on as date ) = '1970-01-01' )
2024-09-05 10:17:32 +02:00
union all
select col_primary_key from " . $this->config ->item('table_name') . "
join station_profile on " . $this->config ->item('table_name') . " . station_id = station_profile . station_id
where station_profile . user_id = ?
and coalesce ( col_cont , '' ) <> ''
and col_cont NOT IN ( 'AF' , 'AN' , 'AS' , 'EU' , 'NA' , 'OC' , 'SA' )
2024-08-29 12:49:14 +02:00
) as x " ;
2024-09-05 10:17:32 +02:00
$id_query = $this -> db -> query ( $id_sql , [ $searchCriteria [ 'user_id' ], $searchCriteria [ 'user_id' ], $searchCriteria [ 'user_id' ], $searchCriteria [ 'user_id' ], $searchCriteria [ 'user_id' ]]);
2024-08-29 12:49:14 +02:00
$ids2fetch = '' ;
foreach ( $id_query -> result () as $id ) {
$ids2fetch .= ',' . $id -> qsoids ;
}
$ids2fetch = ltrim ( $ids2fetch , ',' );
if ( $ids2fetch ? ? '' !== '' ) {
$conditions [] = " qsos.COL_PRIMARY_KEY in ( " . $ids2fetch . " ) " ;
} else {
$conditions [] = " 1=0 " ;
}
}
2022-12-18 16:49:54 +01:00
if ( $searchCriteria [ 'dateFrom' ] !== '' ) {
2023-11-17 17:24:24 +01:00
$from = $searchCriteria [ 'dateFrom' ];
2022-12-18 16:49:54 +01:00
$conditions [] = " date(COL_TIME_ON) >= ? " ;
$binding [] = $from ;
}
if ( $searchCriteria [ 'dateTo' ] !== '' ) {
2023-11-17 17:24:24 +01:00
$to = $searchCriteria [ 'dateTo' ];
2022-12-18 16:49:54 +01:00
$conditions [] = " date(COL_TIME_ON) <= ? " ;
$binding [] = $to ;
}
2024-01-25 11:02:13 +01:00
if ( $searchCriteria [ 'de' ] !== 'All' ) {
2024-09-06 10:07:00 +02:00
if ( $searchCriteria [ 'de' ] == '' ) {
$stationids = 'null' ;
} else {
$stationids = implode ( ',' , $searchCriteria [ 'de' ]);
}
2024-06-28 14:55:52 +02:00
$conditions [] = " qsos.station_id in ( " . $stationids . " ) " ;
2022-12-18 16:49:54 +01:00
}
2024-11-18 17:22:52 +01:00
if ( $searchCriteria [ 'dx' ] !== '*' ) {
2022-12-18 16:49:54 +01:00
$conditions [] = " COL_CALL LIKE ? " ;
$binding [] = '%' . trim ( $searchCriteria [ 'dx' ]) . '%' ;
}
2024-11-18 17:22:52 +01:00
if ( $searchCriteria [ 'dx' ] == '' ) {
$conditions [] = " coalesce(COL_CALL, '') = '' " ;
}
2022-12-18 16:49:54 +01:00
if ( $searchCriteria [ 'mode' ] !== '' ) {
2022-12-27 18:56:04 +01:00
$conditions [] = " (COL_MODE = ? or COL_SUBMODE = ?) " ;
$binding [] = $searchCriteria [ 'mode' ];
$binding [] = $searchCriteria [ 'mode' ];
2022-12-18 16:49:54 +01:00
}
if ( $searchCriteria [ 'band' ] !== '' ) {
2022-12-21 10:49:23 +01:00
if ( $searchCriteria [ 'band' ] != " SAT " ) {
$conditions [] = " COL_BAND = ? and COL_PROP_MODE != 'SAT' " ;
$binding [] = trim ( $searchCriteria [ 'band' ]);
} else {
$conditions [] = " COL_PROP_MODE = 'SAT' " ;
2023-05-01 08:58:13 +02:00
if ( $searchCriteria [ 'sats' ] !== 'All' ) {
$conditions [] = " COL_SAT_NAME = ? " ;
$binding [] = trim ( $searchCriteria [ 'sats' ]);
}
2022-12-21 10:49:23 +01:00
}
2022-12-18 16:49:54 +01:00
}
2024-04-10 01:06:47 +02:00
if ( $searchCriteria [ 'orbits' ] !== 'All' && $searchCriteria [ 'orbits' ] !== '' ) {
$conditions [] = " orbit = ? " ;
$binding [] = $searchCriteria [ 'orbits' ];
}
2022-12-18 16:49:54 +01:00
if ( $searchCriteria [ 'qslSent' ] !== '' ) {
2023-07-29 18:11:38 +02:00
$condition = " COL_QSL_SENT = ? " ;
if ( $searchCriteria [ 'qslSent' ] == 'N' ) {
$condition = '(' . $condition ;
$condition .= " OR COL_QSL_SENT IS NULL OR COL_QSL_SENT = '') " ;
}
$conditions [] = $condition ;
2022-12-18 16:49:54 +01:00
$binding [] = $searchCriteria [ 'qslSent' ];
}
if ( $searchCriteria [ 'qslReceived' ] !== '' ) {
2023-07-29 18:11:38 +02:00
$condition = " COL_QSL_RCVD = ? " ;
if ( $searchCriteria [ 'qslReceived' ] == 'N' ) {
$condition = '(' . $condition ;
$condition .= " OR COL_QSL_RCVD IS NULL OR COL_QSL_RCVD = '') " ;
}
$conditions [] = $condition ;
2022-12-18 16:49:54 +01:00
$binding [] = $searchCriteria [ 'qslReceived' ];
}
2023-10-04 10:46:34 +02:00
2023-10-04 09:27:28 +02:00
if ( $searchCriteria [ 'qslSentMethod' ] !== '' ) {
2023-10-04 13:40:43 +02:00
$condition = " COL_QSL_SENT_VIA = ? " ;
2023-10-04 01:28:11 +02:00
$conditions [] = $condition ;
2023-10-04 13:40:43 +02:00
$binding [] = $searchCriteria [ 'qslSentMethod' ];
2023-10-04 09:27:28 +02:00
}
2023-10-04 10:46:34 +02:00
2023-10-04 09:27:28 +02:00
if ( $searchCriteria [ 'qslReceivedMethod' ] !== '' ) {
2023-10-04 16:01:45 +02:00
$condition = " COL_QSL_RCVD_VIA = ? " ;
2023-10-04 09:27:28 +02:00
$conditions [] = $condition ;
2023-10-04 13:40:43 +02:00
$binding [] = $searchCriteria [ 'qslReceivedMethod' ];
2023-10-04 01:28:11 +02:00
}
2023-10-04 10:46:34 +02:00
2023-06-29 18:59:12 +02:00
if ( $searchCriteria [ 'lotwSent' ] !== '' ) {
2023-07-29 18:11:38 +02:00
$condition = " COL_LOTW_QSL_SENT = ? " ;
if ( $searchCriteria [ 'lotwSent' ] == 'N' ) {
$condition = '(' . $condition ;
$condition .= " OR COL_LOTW_QSL_SENT IS NULL OR COL_LOTW_QSL_SENT = '') " ;
}
$conditions [] = $condition ;
2023-06-29 18:59:12 +02:00
$binding [] = $searchCriteria [ 'lotwSent' ];
}
if ( $searchCriteria [ 'lotwReceived' ] !== '' ) {
2023-07-29 18:11:38 +02:00
$condition = " COL_LOTW_QSL_RCVD = ? " ;
if ( $searchCriteria [ 'lotwReceived' ] == 'N' ) {
$condition = '(' . $condition ;
$condition .= " OR COL_LOTW_QSL_RCVD IS NULL OR COL_LOTW_QSL_RCVD = '') " ;
}
$conditions [] = $condition ;
2023-06-29 18:59:12 +02:00
$binding [] = $searchCriteria [ 'lotwReceived' ];
}
2024-07-02 17:46:06 +00:00
if ( $searchCriteria [ 'clublogSent' ] !== '' ) {
$condition = " COL_CLUBLOG_QSO_UPLOAD_STATUS = ? " ;
if ( $searchCriteria [ 'clublogSent' ] == 'N' ) {
$condition = '(' . $condition ;
2024-09-23 10:53:37 +00:00
$condition .= " OR COL_CLUBLOG_QSO_UPLOAD_STATUS IS NULL OR COL_CLUBLOG_QSO_UPLOAD_STATUS = '') " ;
2024-07-02 17:46:06 +00:00
}
$conditions [] = $condition ;
$binding [] = $searchCriteria [ 'clublogSent' ];
}
if ( $searchCriteria [ 'clublogReceived' ] !== '' ) {
$condition = " COL_CLUBLOG_QSO_DOWNLOAD_STATUS = ? " ;
if ( $searchCriteria [ 'clublogReceived' ] == 'N' ) {
$condition = '(' . $condition ;
$condition .= " OR COL_CLUBLOG_QSO_DOWNLOAD_STATUS IS NULL OR COL_CLUBLOG_QSO_DOWNLOAD_STATUS = '') " ;
}
$conditions [] = $condition ;
$binding [] = $searchCriteria [ 'clublogReceived' ];
}
2023-06-29 18:59:12 +02:00
if ( $searchCriteria [ 'eqslSent' ] !== '' ) {
2023-08-14 04:03:46 +00:00
$condition = " COL_EQSL_QSL_SENT = ? " ;
2023-07-29 18:11:38 +02:00
if ( $searchCriteria [ 'eqslSent' ] == 'N' ) {
$condition = '(' . $condition ;
2023-08-14 04:03:46 +00:00
$condition .= " OR COL_EQSL_QSL_SENT IS NULL OR COL_EQSL_QSL_SENT = '') " ;
2023-07-29 18:11:38 +02:00
}
$conditions [] = $condition ;
2023-06-29 18:59:12 +02:00
$binding [] = $searchCriteria [ 'eqslSent' ];
}
if ( $searchCriteria [ 'eqslReceived' ] !== '' ) {
2023-08-14 04:03:46 +00:00
$condition = " COL_EQSL_QSL_RCVD = ? " ;
2023-07-29 18:11:38 +02:00
if ( $searchCriteria [ 'eqslReceived' ] == 'N' ) {
$condition = '(' . $condition ;
2023-08-14 04:03:46 +00:00
$condition .= " OR COL_EQSL_QSL_RCVD IS NULL OR COL_EQSL_QSL_RCVD = '') " ;
2023-07-29 18:11:38 +02:00
}
$conditions [] = $condition ;
2023-06-29 18:59:12 +02:00
$binding [] = $searchCriteria [ 'eqslReceived' ];
}
2022-12-18 16:49:54 +01:00
if ( $searchCriteria [ 'iota' ] !== '' ) {
$conditions [] = " COL_IOTA = ? " ;
$binding [] = $searchCriteria [ 'iota' ];
}
2024-10-10 06:10:10 +00:00
if (( $searchCriteria [ 'dxcc' ] ? ? '' ) !== '' ) {
2022-12-18 16:49:54 +01:00
$conditions [] = " COL_DXCC = ? " ;
$binding [] = $searchCriteria [ 'dxcc' ];
}
2024-11-18 17:22:52 +01:00
if ( $searchCriteria [ 'state' ] !== '*' ) {
2022-12-18 16:49:54 +01:00
$conditions [] = " COL_STATE = ? " ;
$binding [] = $searchCriteria [ 'state' ];
}
2024-11-18 17:22:52 +01:00
if ( $searchCriteria [ 'state' ] == '' ) {
$conditions [] = " coalesce(COL_STATE, '') = '' " ;
}
2022-12-18 16:49:54 +01:00
2023-07-05 09:29:13 +02:00
if ( $searchCriteria [ 'cqzone' ] !== '' ) {
$conditions [] = " COL_CQZ = ? " ;
$binding [] = $searchCriteria [ 'cqzone' ];
}
2024-04-28 09:23:21 +02:00
if ( $searchCriteria [ 'ituzone' ] !== '' ) {
$conditions [] = " COL_ITUZ = ? " ;
$binding [] = $searchCriteria [ 'ituzone' ];
}
2024-11-18 17:22:52 +01:00
if ( $searchCriteria [ 'qslvia' ] !== '*' ) {
2023-07-07 10:03:52 +02:00
$conditions [] = " COL_QSL_VIA like ? " ;
$binding [] = $searchCriteria [ 'qslvia' ] . '%' ;
}
2024-11-18 17:22:52 +01:00
if ( $searchCriteria [ 'qslvia' ] == '' ) {
$conditions [] = " coalesce(COL_QSL_VIA, '') = '' " ;
}
if ( $searchCriteria [ 'sota' ] !== '*' ) {
2023-07-07 10:03:52 +02:00
$conditions [] = " COL_SOTA_REF like ? " ;
$binding [] = $searchCriteria [ 'sota' ] . '%' ;
}
2024-11-18 17:22:52 +01:00
if ( $searchCriteria [ 'sota' ] == '' ) {
$conditions [] = " coalesce(COL_SOTA_REF, '') = '' " ;
}
2023-07-07 10:03:52 +02:00
2024-11-18 17:22:52 +01:00
if ( $searchCriteria [ 'pota' ] !== '*' ) {
2023-07-07 10:03:52 +02:00
$conditions [] = " COL_POTA_REF like ? " ;
$binding [] = $searchCriteria [ 'pota' ] . '%' ;
}
2024-11-18 17:22:52 +01:00
if ( $searchCriteria [ 'pota' ] == '' ) {
$conditions [] = " coalesce(COL_POTA_REF, '') = '' " ;
}
2023-07-07 10:03:52 +02:00
2024-11-18 17:22:52 +01:00
if ( $searchCriteria [ 'wwff' ] !== '*' ) {
2023-07-07 10:03:52 +02:00
$conditions [] = " COL_WWFF_REF like ? " ;
$binding [] = $searchCriteria [ 'wwff' ] . '%' ;
}
2024-11-18 17:22:52 +01:00
if ( $searchCriteria [ 'wwff' ] == '' ) {
$conditions [] = " coalesce(COL_WWFF_REF, '') = '' " ;
}
2023-07-07 10:03:52 +02:00
2024-11-18 17:22:52 +01:00
if ( $searchCriteria [ 'operator' ] !== '*' ) {
2023-12-04 13:21:59 +00:00
$conditions [] = " COL_OPERATOR like ? " ;
$binding [] = $searchCriteria [ 'operator' ] . '%' ;
}
2024-11-18 17:22:52 +01:00
if ( $searchCriteria [ 'operator' ] == '' ) {
$conditions [] = " coalesce(COL_OPERATOR, '') = '' " ;
}
2023-12-04 13:21:59 +00:00
2024-11-18 17:22:52 +01:00
if ( $searchCriteria [ 'gridsquare' ] !== '*' ) {
2022-12-18 16:49:54 +01:00
$conditions [] = " (COL_GRIDSQUARE like ? or COL_VUCC_GRIDS like ?) " ;
$binding [] = '%' . $searchCriteria [ 'gridsquare' ] . '%' ;
$binding [] = '%' . $searchCriteria [ 'gridsquare' ] . '%' ;
}
2024-11-18 17:22:52 +01:00
if ( $searchCriteria [ 'gridsquare' ] == '' ) {
$conditions [] = " (coalesce(COL_GRIDSQUARE, '') = '' and coalesce(COL_VUCC_GRIDS, '') = '') " ;
2024-06-28 21:17:05 +02:00
}
2024-11-18 17:22:52 +01:00
if (( $searchCriteria [ 'propmode' ] ? ? '' ) == 'None' ) {
$conditions [] = " (trim(COL_PROP_MODE) = '' OR COL_PROP_MODE is null) " ;
} elseif ( $searchCriteria [ 'propmode' ] !== '' ) {
$conditions [] = " COL_PROP_MODE = ? " ;
$binding [] = $searchCriteria [ 'propmode' ];
if ( $searchCriteria [ 'propmode' ] == " SAT " ) {
if ( $searchCriteria [ 'sats' ] !== 'All' ) {
$conditions [] = " COL_SAT_NAME = ? " ;
$binding [] = trim ( $searchCriteria [ 'sats' ]);
}
}
}
if ( $searchCriteria [ 'contest' ] !== '*' ) {
2024-06-28 21:17:05 +02:00
$conditions [] = " COL_CONTEST_ID like ? " ;
$binding [] = '%' . $searchCriteria [ 'contest' ] . '%' ;
}
2023-05-01 08:58:13 +02:00
2024-11-18 17:22:52 +01:00
if ( $searchCriteria [ 'contest' ] == '' ) {
$conditions [] = " coalesce(COL_CONTEST_ID, '') = '' " ;
}
2024-09-05 10:17:32 +02:00
if ( $searchCriteria [ 'continent' ] !== '' ) {
if ( $searchCriteria [ 'continent' ] == 'invalid' ) {
$conditions [] = " COL_CONT NOT IN ('AF', 'AN', 'AS', 'EU', 'NA', 'OC', 'SA') " ;
$conditions [] = " coalesce(COL_CONT, '') <> '' " ;
} else if ( $searchCriteria [ 'continent' ] == 'blank' ) {
$conditions [] = " coalesce(COL_CONT, '') = '' " ;
}
else {
$conditions [] = " COL_CONT = ? " ;
$binding [] = $searchCriteria [ 'continent' ];
}
}
2023-08-21 14:18:05 +02:00
if (( $searchCriteria [ 'ids' ] ? ? '' ) !== '' ) {
$conditions [] = " qsos.COL_PRIMARY_KEY in ( " . implode ( " , " , $searchCriteria [ 'ids' ]) . " ) " ;
}
2022-12-18 16:49:54 +01:00
$where = trim ( implode ( " AND " , $conditions ));
if ( $where != " " ) {
$where = " AND $where " ;
}
2024-05-08 10:49:13 +02:00
$limit = '' ;
if ( $searchCriteria [ 'qsoresults' ] != 'All' ) {
$limit = 'limit ' . $searchCriteria [ 'qsoresults' ];
}
2022-12-18 16:49:54 +01:00
2023-08-11 19:13:13 +02:00
$where2 = '' ;
if ( $searchCriteria [ 'qslimages' ] !== '' ) {
if ( $searchCriteria [ 'qslimages' ] == 'Y' ) {
2024-05-20 14:53:09 +02:00
$where2 .= ' and exists(select 1 from qsl_images where qsoid = qsos.COL_PRIMARY_KEY)' ;
2023-08-11 19:13:13 +02:00
}
if ( $searchCriteria [ 'qslimages' ] == 'N' ) {
2024-05-20 14:53:09 +02:00
$where2 .= ' and not exists(select 1 from qsl_images where qsoid = qsos.COL_PRIMARY_KEY)' ;
2023-08-11 19:13:13 +02:00
}
}
2022-12-18 16:49:54 +01:00
$sql = "
2024-07-13 22:05:07 +02:00
SELECT qsos .* , dxcc_entities .* , lotw_users .* , station_profile .* , satellite .* , dxcc_entities . name as dxccname , mydxcc . name AS station_country , exists ( select 1 from qsl_images where qsoid = qsos . COL_PRIMARY_KEY ) as qslcount , coalesce ( contest . name , qsos . col_contest_id ) as contestname
2022-12-18 16:49:54 +01:00
FROM " . $this->config ->item('table_name') . " qsos
INNER JOIN station_profile ON qsos . station_id = station_profile . station_id
2024-04-10 01:06:47 +02:00
LEFT OUTER JOIN satellite ON qsos . COL_SAT_NAME = satellite . name
2024-05-20 14:41:08 +02:00
LEFT OUTER JOIN dxcc_entities ON qsos . col_dxcc = dxcc_entities . adif
left outer join dxcc_entities mydxcc on qsos . col_my_dxcc = mydxcc . adif
LEFT OUTER JOIN lotw_users ON qsos . col_call = lotw_users . callsign
LEFT OUTER JOIN contest ON qsos . col_contest_id = contest . adifname
2022-12-18 16:49:54 +01:00
WHERE station_profile . user_id = ?
$where
2023-08-11 19:13:13 +02:00
$where2
2023-01-26 00:57:38 +01:00
ORDER BY qsos . COL_TIME_ON desc , qsos . COL_PRIMARY_KEY desc
2024-05-08 10:49:13 +02:00
$limit
2022-12-18 16:49:54 +01:00
" ;
2024-05-07 18:22:52 +02:00
return $this -> db -> query ( $sql , $binding );
2022-12-18 16:49:54 +01:00
2024-05-07 18:22:52 +02:00
}
public function getSearchResult ( $searchCriteria ) {
return $this -> searchDb ( $searchCriteria );
}
public function getSearchResultArray ( $searchCriteria ) {
$result = $this -> searchDb ( $searchCriteria );
return $result -> result ( 'array' );
2023-08-18 20:02:47 +02:00
}
/*
* @ param array $searchCriteria
* @ return array
*/
public function searchQsos ( $searchCriteria ) : array {
2024-05-07 18:22:52 +02:00
$results = $this -> getSearchResultArray ( $searchCriteria );
2023-08-18 20:02:47 +02:00
2022-12-18 16:49:54 +01:00
$qsos = [];
foreach ( $results as $data ) {
$qsos [] = new QSO ( $data );
}
2023-07-07 10:03:52 +02:00
2023-08-18 20:02:47 +02:00
return $qsos ;
2022-12-18 16:49:54 +01:00
}
2023-05-02 13:46:23 +02:00
public function getQsosForAdif ( $ids , $user_id , $sortorder = null ) : object {
2022-12-18 16:49:54 +01:00
$binding = [ $user_id ];
$conditions [] = " COL_PRIMARY_KEY in ? " ;
$binding [] = json_decode ( $ids , true );
$where = trim ( implode ( " AND " , $conditions ));
if ( $where != " " ) {
$where = " AND $where " ;
}
2023-05-02 20:53:29 +02:00
$order = $this -> getSortorder ( $sortorder );
2023-05-02 13:46:23 +02:00
2022-12-18 16:49:54 +01:00
$sql = "
2024-11-18 15:57:33 +01:00
SELECT qsos .* , lotw_users .* , station_profile .* , dxcc_entities . name AS station_country , dxcc_entities . adif as adif , d2 . name as dxccname , exists ( select 1 from qsl_images where qsoid = qsos . COL_PRIMARY_KEY ) as qslcount , coalesce ( contest . name , qsos . col_contest_id ) as contestname
2022-12-18 16:49:54 +01:00
FROM " . $this->config ->item('table_name') . " qsos
INNER JOIN station_profile ON qsos . station_id = station_profile . station_id
2023-04-28 15:14:59 +02:00
LEFT OUTER JOIN dxcc_entities ON qsos . COL_MY_DXCC = dxcc_entities . adif
2023-06-28 09:17:48 +02:00
LEFT OUTER JOIN dxcc_entities d2 ON qsos . COL_DXCC = d2 . adif
2023-06-28 08:27:44 +02:00
LEFT OUTER JOIN lotw_users ON qsos . col_call = lotw_users . callsign
2024-05-22 20:26:33 +02:00
LEFT OUTER JOIN contest ON qsos . col_contest_id = contest . adifname
2022-12-18 16:49:54 +01:00
WHERE station_profile . user_id = ?
$where
2023-05-01 12:35:24 +02:00
$order
2022-12-18 16:49:54 +01:00
" ;
return $this -> db -> query ( $sql , $binding );
}
2023-05-02 20:53:29 +02:00
public function getSortOrder ( $sortorder ) {
if ( $sortorder == null ) {
return 'ORDER BY qsos.COL_TIME_ON desc' ;
} else {
$sortorder = explode ( ',' , $sortorder );
if ( $this -> session -> userdata ( 'user_lotw_name' ) != " " && $this -> session -> userdata ( 'user_eqsl_name' ) != " " ){
switch ( $sortorder [ 0 ]) {
case 1 : return 'ORDER BY qsos.COL_TIME_ON ' . $sortorder [ 1 ];
case 2 : return 'ORDER BY station_profile.station_callsign ' . $sortorder [ 1 ];
case 3 : return 'ORDER BY qsos.COL_CALL ' . $sortorder [ 1 ];
case 4 : return 'ORDER BY qsos.COL_MODE' . $sortorder [ 1 ] . ', qsos.COL_SUBMODE ' . $sortorder [ 1 ];
case 7 : return 'ORDER BY qsos.COL_BAND ' . $sortorder [ 1 ] . ', qsos.COL_SAT_NAME ' . $sortorder [ 1 ];
case 16 : return 'ORDER BY qsos.COL_COUNTRY ' . $sortorder [ 1 ];
case 17 : return 'ORDER BY qso.COL_STATE ' . $sortorder [ 1 ];
case 18 : return 'ORDER BY qsos.COL_CQZ ' . $sortorder [ 1 ];
case 19 : return 'ORDER BY qsos.COL_IOTA ' . $sortorder [ 1 ];
default : return 'ORDER BY qsos.COL_TIME_ON desc' ;
}
}
else if (( $this -> session -> userdata ( 'user_eqsl_name' ) != " " && $this -> session -> userdata ( 'user_lotw_name' ) == " " ) || ( $this -> session -> userdata ( 'user_eqsl_name' ) == " " && $this -> session -> userdata ( 'user_lotw_name' ) != " " )) {
switch ( $sortorder [ 0 ]) {
case 1 : return 'ORDER BY qsos.COL_TIME_ON ' . $sortorder [ 1 ];
case 2 : return 'ORDER BY station_profile.station_callsign ' . $sortorder [ 1 ];
case 3 : return 'ORDER BY qsos.COL_CALL ' . $sortorder [ 1 ];
case 4 : return 'ORDER BY qsos.COL_MODE' . $sortorder [ 1 ] . ', qsos.COL_SUBMODE ' . $sortorder [ 1 ];
case 7 : return 'ORDER BY qsos.COL_BAND ' . $sortorder [ 1 ] . ', qsos.COL_SAT_NAME ' . $sortorder [ 1 ];
case 15 : return 'ORDER BY qsos.COL_COUNTRY ' . $sortorder [ 1 ];
case 16 : return 'ORDER BY qso.COL_STATE ' . $sortorder [ 1 ];
case 17 : return 'ORDER BY qsos.COL_CQZ ' . $sortorder [ 1 ];
case 18 : return 'ORDER BY qsos.COL_IOTA ' . $sortorder [ 1 ];
default : return 'ORDER BY qsos.COL_TIME_ON desc' ;
}
}
else if ( $this -> session -> userdata ( 'user_eqsl_name' ) == " " && $this -> session -> userdata ( 'user_lotw_name' ) == " " ){
switch ( $sortorder [ 0 ]) {
case 1 : return 'ORDER BY qsos.COL_TIME_ON ' . $sortorder [ 1 ];
case 2 : return 'ORDER BY station_profile.station_callsign ' . $sortorder [ 1 ];
case 3 : return 'ORDER BY qsos.COL_CALL ' . $sortorder [ 1 ];
case 4 : return 'ORDER BY qsos.COL_MODE' . $sortorder [ 1 ] . ', qsos.COL_SUBMODE ' . $sortorder [ 1 ];
case 7 : return 'ORDER BY qsos.COL_BAND ' . $sortorder [ 1 ] . ', qsos.COL_SAT_NAME ' . $sortorder [ 1 ];
case 14 : return 'ORDER BY qsos.COL_COUNTRY ' . $sortorder [ 1 ];
case 15 : return 'ORDER BY qso.COL_STATE ' . $sortorder [ 1 ];
case 16 : return 'ORDER BY qsos.COL_CQZ ' . $sortorder [ 1 ];
case 17 : return 'ORDER BY qsos.COL_IOTA ' . $sortorder [ 1 ];
default : return 'ORDER BY qsos.COL_TIME_ON desc' ;
}
}
}
}
2023-12-14 07:44:36 +00:00
public function updateQsl ( $ids , $user_id , $method , $sent ) {
$this -> load -> model ( 'user_model' );
2022-12-18 16:49:54 +01:00
2023-12-14 07:44:36 +00:00
if ( ! $this -> user_model -> authorize ( 2 )) {
return array ( 'message' => 'Error' );
} else {
2024-12-02 11:01:41 +00:00
$sql = " UPDATE " . $this -> config -> item ( 'table_name' ) . "
2024-12-23 14:43:01 +01:00
SET
2024-12-02 11:01:41 +00:00
COL_QSLRDATE = CURRENT_TIMESTAMP ,
COL_QSL_SENT = ? ,
COL_QSL_SENT_VIA = ? ,
2024-12-23 14:43:01 +01:00
COL_QRZCOM_QSO_UPLOAD_STATUS = CASE
2024-12-02 11:01:41 +00:00
WHEN COL_QRZCOM_QSO_UPLOAD_STATUS IN ( 'Y' , 'I' ) THEN 'M'
ELSE COL_QRZCOM_QSO_UPLOAD_STATUS
END
WHERE COL_PRIMARY_KEY IN ( " .implode(',',json_decode( $ids , true)). " ) " ;
$binding [] = $sent ;
$binding [] = $method ;
$this -> db -> query ( $sql , $binding );
2023-07-07 10:03:52 +02:00
2023-12-14 07:44:36 +00:00
return array ( 'message' => 'OK' );
}
}
2022-12-20 22:23:22 +01:00
2023-06-28 08:27:44 +02:00
public function updateQslReceived ( $ids , $user_id , $method , $sent ) {
2024-12-02 11:01:41 +00:00
$this -> load -> model ( 'user_model' );
if ( ! $this -> user_model -> authorize ( 2 )) {
return array ( 'message' => 'Error' );
} else {
$sql = " UPDATE " . $this -> config -> item ( 'table_name' ) . "
2024-12-23 14:43:01 +01:00
SET
2024-12-02 11:01:41 +00:00
COL_QSLRDATE = CURRENT_TIMESTAMP ,
COL_QSL_RCVD = ? ,
COL_QSL_RCVD_VIA = ? ,
2024-12-23 14:43:01 +01:00
COL_QRZCOM_QSO_UPLOAD_STATUS = CASE
2024-12-02 11:01:41 +00:00
WHEN COL_QRZCOM_QSO_UPLOAD_STATUS IN ( 'Y' , 'I' ) THEN 'M'
ELSE COL_QRZCOM_QSO_UPLOAD_STATUS
END
WHERE COL_PRIMARY_KEY IN ( " .implode(',',json_decode( $ids , true)). " ) " ;
$binding [] = $sent ;
$binding [] = $method ;
$this -> db -> query ( $sql , $binding );
return array ( 'message' => 'OK' );
}
2024-12-02 07:48:38 +00:00
}
2023-06-28 08:27:44 +02:00
2022-12-20 22:23:22 +01:00
public function updateQsoWithCallbookInfo ( $qsoID , $qso , $callbook ) {
$updatedData = array ();
2024-09-16 10:30:40 +02:00
$updated = false ;
2022-12-20 22:23:22 +01:00
if ( ! empty ( $callbook [ 'name' ]) && empty ( $qso [ 'COL_NAME' ])) {
$updatedData [ 'COL_NAME' ] = $callbook [ 'name' ];
2024-09-16 10:30:40 +02:00
$updated = true ;
2022-12-20 22:23:22 +01:00
}
if ( ! empty ( $callbook [ 'gridsquare' ]) && empty ( $qso [ 'COL_GRIDSQUARE' ]) && empty ( $qso [ 'COL_VUCC_GRIDS' ] )) {
if ( strpos ( trim ( $callbook [ 'gridsquare' ]), ',' ) === false ) {
$updatedData [ 'COL_GRIDSQUARE' ] = strtoupper ( trim ( $callbook [ 'gridsquare' ]));
} else {
$updatedData [ 'COL_VUCC_GRIDS' ] = strtoupper ( trim ( $callbook [ 'gridsquare' ]));
}
2024-09-16 10:30:40 +02:00
$updated = true ;
2022-12-20 22:23:22 +01:00
}
if ( ! empty ( $callbook [ 'city' ]) && empty ( $qso [ 'COL_QTH' ])) {
$updatedData [ 'COL_QTH' ] = $callbook [ 'city' ];
2024-09-16 10:30:40 +02:00
$updated = true ;
2022-12-20 22:23:22 +01:00
}
if ( ! empty ( $callbook [ 'lat' ]) && empty ( $qso [ 'COL_LAT' ])) {
2024-05-23 06:54:21 +00:00
$updatedData [ 'COL_LAT' ] = substr (( $callbook [ 'lat' ] ? ? '' ), 0 , 11 );
2024-09-16 10:30:40 +02:00
$updated = true ;
2022-12-20 22:23:22 +01:00
}
if ( ! empty ( $callbook [ 'long' ]) && empty ( $qso [ 'COL_LON' ])) {
2024-05-23 06:54:21 +00:00
$updatedData [ 'COL_LON' ] = substr (( $callbook [ 'long' ] ? ? '' ), 0 , 11 );
2024-09-16 10:30:40 +02:00
$updated = true ;
2022-12-20 22:23:22 +01:00
}
if ( ! empty ( $callbook [ 'iota' ]) && empty ( $qso [ 'COL_IOTA' ])) {
$updatedData [ 'COL_IOTA' ] = $callbook [ 'iota' ];
2024-09-16 10:30:40 +02:00
$updated = true ;
2022-12-20 22:23:22 +01:00
}
if ( ! empty ( $callbook [ 'state' ]) && empty ( $qso [ 'COL_STATE' ])) {
$updatedData [ 'COL_STATE' ] = $callbook [ 'state' ];
2024-09-16 10:30:40 +02:00
$updated = true ;
2022-12-20 22:23:22 +01:00
}
2024-02-19 09:18:20 +01:00
if ( ! empty ( $callbook [ 'us_county' ]) && empty ( $qso [ 'COL_CNTY' ])) {
$updatedData [ 'COL_CNTY' ] = $callbook [ 'state' ] . ',' . $callbook [ 'us_county' ];
2024-09-16 10:30:40 +02:00
$updated = true ;
2022-12-20 22:23:22 +01:00
}
if ( ! empty ( $callbook [ 'qslmgr' ]) && empty ( $qso [ 'COL_QSL_VIA' ])) {
$updatedData [ 'COL_QSL_VIA' ] = $callbook [ 'qslmgr' ];
2024-09-16 10:30:40 +02:00
$updated = true ;
2022-12-20 22:23:22 +01:00
}
2024-08-27 09:39:57 +02:00
if ( ! empty ( $callbook [ 'ituz' ]) && empty ( $qso [ 'COL_ITUZ' ])) {
$updatedData [ 'COL_ITUZ' ] = $callbook [ 'ituz' ];
2024-09-16 10:30:40 +02:00
$updated = true ;
2024-08-27 09:39:57 +02:00
}
2024-11-13 12:09:15 +01:00
if ( empty ( $qso [ 'COL_CONT' ])) {
2024-11-13 12:07:53 +01:00
$updatedData [ 'COL_CONT' ] = $this -> logbook_model -> getContinent ( $callbook [ 'dxcc' ]);
$updated = true ;
}
2022-12-20 22:23:22 +01:00
2024-09-15 20:36:22 +00:00
//Also set QRZ.com status to modified
2024-09-16 10:30:40 +02:00
if ( $updated == true && $qso [ 'COL_QRZCOM_QSO_UPLOAD_STATUS' ] == 'Y' ) {
2024-09-15 20:36:22 +00:00
$updatedData [ 'COL_QRZCOM_QSO_UPLOAD_STATUS' ] = 'M' ;
}
2022-12-20 22:23:22 +01:00
if ( count ( $updatedData ) > 0 ) {
$this -> db -> where ( 'COL_PRIMARY_KEY' , $qsoID );
$this -> db -> update ( $this -> config -> item ( 'table_name' ), $updatedData );
return true ;
}
return false ;
}
2022-12-27 18:56:04 +01:00
function get_modes () {
2024-05-24 11:25:44 +02:00
if ( ! $this -> logbooks_locations_array ) {
2022-12-27 18:56:04 +01:00
return null ;
}
$modes = array ();
2023-07-07 10:03:52 +02:00
2022-12-27 18:56:04 +01:00
$this -> db -> select ( 'distinct col_mode, coalesce(col_submode, "") col_submode' , FALSE );
2024-05-24 11:25:44 +02:00
$this -> db -> where_in ( 'station_id' , $this -> logbooks_locations_array );
2022-12-27 18:56:04 +01:00
$this -> db -> order_by ( 'col_mode, col_submode' , 'ASC' );
$query = $this -> db -> get ( $this -> config -> item ( 'table_name' ));
2023-07-07 10:03:52 +02:00
2022-12-27 18:56:04 +01:00
foreach ( $query -> result () as $mode ){
if ( $mode -> col_submode == null || $mode -> col_submode == " " ) {
array_push ( $modes , $mode -> col_mode );
} else {
2024-11-18 09:47:36 +01:00
array_push ( $modes , $mode -> col_submode );
2022-12-27 18:56:04 +01:00
}
}
return $modes ;
}
2023-08-11 19:13:13 +02:00
function getQslsForQsoIds ( $ids ) {
$this -> db -> select ( '*' );
$this -> db -> from ( $this -> config -> item ( 'table_name' ));
$this -> db -> join ( 'qsl_images' , 'qsl_images.qsoid = ' . $this -> config -> item ( 'table_name' ) . '.col_primary_key' );
$this -> db -> where_in ( 'qsoid' , $ids );
2024-05-24 11:25:44 +02:00
$this -> db -> where_in ( 'station_id' , $this -> logbooks_locations_array );
2023-08-11 19:13:13 +02:00
$this -> db -> order_by ( " id " , " desc " );
return $this -> db -> get () -> result ();
}
2024-02-16 13:52:20 +01:00
2025-01-14 09:22:08 +01:00
function saveEditedQsos ( $ids , $column , $value , $value2 , $value3 , $value4 ) {
2024-10-14 18:38:05 +02:00
$skipqrzupdate = false ;
2024-02-16 13:52:20 +01:00
switch ( $column ) {
case " cqz " : $column = 'COL_CQZ' ; break ;
2024-04-28 09:23:21 +02:00
case " ituz " : $column = 'COL_ITUZ' ; break ;
2024-02-16 13:52:20 +01:00
case " dxcc " : $column = 'COL_DXCC' ; break ;
case " iota " : $column = 'COL_IOTA' ; break ;
2024-02-20 15:24:49 +01:00
case " state " : $column = 'COL_STATE' ; break ;
2024-02-16 13:52:20 +01:00
case " propagation " : $column = 'COL_PROP_MODE' ; break ;
2024-02-19 19:05:09 +01:00
case " station " : $column = 'station_id' ; break ;
case " operator " : $column = 'COL_OPERATOR' ; break ;
case " comment " : $column = 'COL_COMMENT' ; break ;
case " band " : $column = 'COL_BAND' ; break ;
case " mode " : $column = 'COL_MODE' ; break ;
case " date " : $column = 'COL_TIME_ON' ; break ;
case " pota " : $column = 'COL_POTA_REF' ; break ;
case " sota " : $column = 'COL_SOTA_REF' ; break ;
case " wwff " : $column = 'COL_WWFF_REF' ; break ;
case " gridsquare " : $column = 'COL_GRIDSQUARE' ; break ;
case " qslvia " : $column = 'COL_QSL_VIA' ; break ;
case " satellite " : $column = 'COL_SAT_NAME' ; break ;
2024-07-02 09:41:59 +02:00
case " contest " : $column = 'COL_CONTEST_ID' ; break ;
2024-07-26 09:55:26 +02:00
case " lotwsent " : $column = 'COL_LOTW_QSL_SENT' ; break ;
case " lotwreceived " : $column = 'COL_LOTW_QSL_RCVD' ; break ;
2024-08-03 15:00:35 +02:00
case " qslmsg " : $column = 'COL_QSLMSG' ; break ;
2024-09-05 11:35:21 +02:00
case " continent " : $column = 'COL_CONT' ; break ;
2024-10-14 18:38:05 +02:00
case " qrzsent " : $column = 'COL_QRZCOM_QSO_UPLOAD_STATUS' ; break ;
case " qrzreceived " : $column = 'COL_QRZCOM_QSO_DOWNLOAD_STATUS' ; break ;
2024-11-18 08:34:51 +00:00
case " eqslsent " : $column = 'COL_EQSL_QSL_SENT' ; break ;
case " eqslreceived " : $column = 'COL_EQSL_QSL_RCVD' ; break ;
2024-11-01 20:44:40 +01:00
case " stationpower " : $column = 'COL_TX_PWR' ; break ;
2025-01-07 18:53:38 +01:00
case " clublogsent " : $column = 'COL_CLUBLOG_QSO_UPLOAD_STATUS' ; break ;
case " clublogreceived " : $column = 'COL_CLUBLOG_QSO_DOWNLOAD_STATUS' ; break ;
2024-02-16 13:52:20 +01:00
default : return ;
}
2024-02-18 09:41:54 +01:00
$this -> db -> trans_start ();
2024-02-16 13:52:20 +01:00
2024-02-19 19:05:09 +01:00
if ( $column == 'station_id' ) {
$this -> load -> model ( 'stations' );
// Need to copy over from station profile to my_columns
$station_profile = $this -> stations -> profile_clean ( $value );
$stationid = $value ;
$stationCallsign = $station_profile -> station_callsign ;
$iotaRef = $station_profile -> station_iota ? ? '' ;
$sotaRef = $station_profile -> station_sota ? ? '' ;
$wwffRef = $station_profile -> station_wwff ? ? '' ;
$potaRef = $station_profile -> station_pota ? ? '' ;
$sig = $station_profile -> station_sig ? ? '' ;
$sigInfo = $station_profile -> station_sig_info ? ? '' ;
$sql = " UPDATE " . $this -> config -> item ( 'table_name' ) . " JOIN station_profile ON " . $this -> config -> item ( 'table_name' ) . " .station_id = station_profile.station_id " .
2024-02-20 09:40:32 +01:00
" SET " . $this -> config -> item ( 'table_name' ) . " .STATION_ID = ? " .
" , " . $this -> config -> item ( 'table_name' ) . " .COL_MY_IOTA = ? " .
" , " . $this -> config -> item ( 'table_name' ) . " .COL_MY_SOTA_REF = ? " .
" , " . $this -> config -> item ( 'table_name' ) . " .COL_MY_WWFF_REF = ? " .
" , " . $this -> config -> item ( 'table_name' ) . " .COL_MY_POTA_REF = ? " .
" , " . $this -> config -> item ( 'table_name' ) . " .COL_MY_SIG = ? " .
" , " . $this -> config -> item ( 'table_name' ) . " .COL_MY_SIG_INFO = ? " .
" , " . $this -> config -> item ( 'table_name' ) . " .COL_STATION_CALLSIGN = ? " .
2024-02-19 19:05:09 +01:00
" WHERE " . $this -> config -> item ( 'table_name' ) . " .col_primary_key in ? and station_profile.user_id = ? " ;
$query = $this -> db -> query ( $sql , array ( $stationid , $iotaRef , $sotaRef , $wwffRef , $potaRef , $sig , $sigInfo , $stationCallsign , json_decode ( $ids , true ), $this -> session -> userdata ( 'user_id' )));
} else if ( $column == 'COL_BAND' ) {
2025-01-14 11:34:34 +01:00
if ( $value == '' ) return ;
2024-02-19 19:05:09 +01:00
$bandrx = $value2 == '' ? '' : $value2 ;
$sql = " UPDATE " . $this -> config -> item ( 'table_name' ) . " JOIN station_profile ON " . $this -> config -> item ( 'table_name' ) . " .station_id = station_profile.station_id " .
" SET " . $this -> config -> item ( 'table_name' ) . " .COL_BAND = ? " .
" , " . $this -> config -> item ( 'table_name' ) . " .COL_BAND_RX = ? " .
" , " . $this -> config -> item ( 'table_name' ) . " .COL_FREQ = ? " .
" , " . $this -> config -> item ( 'table_name' ) . " .COL_FREQ_RX = ? " .
" WHERE " . $this -> config -> item ( 'table_name' ) . " .col_primary_key in ? and station_profile.user_id = ? " ;
2024-02-20 13:41:30 +01:00
$frequencyBand = $this -> frequency -> defaultFrequencies [ $value ][ 'CW' ];
$frequencyBandRx = $bandrx == '' ? null : $this -> frequency -> defaultFrequencies [ $bandrx ][ 'CW' ];
$query = $this -> db -> query ( $sql , array ( $value , $value2 , $frequencyBand , $frequencyBandRx , json_decode ( $ids , true ), $this -> session -> userdata ( 'user_id' )));
2024-02-19 19:05:09 +01:00
} else if ( $column == 'COL_GRIDSQUARE' ) {
2024-07-15 05:59:47 +02:00
if ( ! $this -> load -> is_loaded ( 'Qra' )) {
$this -> load -> library ( 'Qra' );
}
2024-02-20 16:06:52 +00:00
$latlng = $this -> qra -> qra2latlong ( trim ( xss_clean ( $value ) ? ? '' ));
if ( $latlng [ 1 ] ? ? '--' != '--' ) {
if ( strpos ( trim ( xss_clean ( $value ) ? ? '' ), ',' ) !== false ) {
$grid_value = null ;
$vucc_value = strtoupper ( preg_replace ( '/\s+/' , '' , xss_clean ( $value ) ? ? '' ));
} else {
$vucc_value = null ;
$grid_value = strtoupper ( trim ( xss_clean ( $value ) ? ? '' ));
}
2024-02-19 19:05:09 +01:00
2024-02-20 16:06:52 +00:00
$sql = " UPDATE " . $this -> config -> item ( 'table_name' ) . " JOIN station_profile ON " . $this -> config -> item ( 'table_name' ) . " .station_id = station_profile.station_id " .
" SET " . $this -> config -> item ( 'table_name' ) . " .COL_GRIDSQUARE = ? " .
2025-01-14 11:34:34 +01:00
" , " . $this -> config -> item ( 'table_name' ) . " .COL_VUCC_GRIDS = ? " .
2024-02-20 16:06:52 +00:00
" WHERE " . $this -> config -> item ( 'table_name' ) . " .col_primary_key in ? and station_profile.user_id = ? " ;
2024-02-19 19:05:09 +01:00
2024-02-20 16:06:52 +00:00
$query = $this -> db -> query ( $sql , array ( $grid_value , $vucc_value , json_decode ( $ids , true ), $this -> session -> userdata ( 'user_id' )));
}
2024-02-19 19:05:09 +01:00
} else if ( $column == 'COL_MODE' ) {
$this -> load -> model ( 'logbook_model' );
$mode = $this -> logbook_model -> get_main_mode_if_submode ( $value );
if ( $mode == null ) {
$col_mode = $value ;
$col_submode = null ;
} else {
$col_mode = $mode ;
$col_submode = $value ;
}
$sql = " UPDATE " . $this -> config -> item ( 'table_name' ) . " JOIN station_profile ON " . $this -> config -> item ( 'table_name' ) . " .station_id = station_profile.station_id " .
" SET " . $this -> config -> item ( 'table_name' ) . " .COL_MODE = ? " .
" , " . $this -> config -> item ( 'table_name' ) . " .COL_SUBMODE = ? " .
" WHERE " . $this -> config -> item ( 'table_name' ) . " .col_primary_key in ? and station_profile.user_id = ? " ;
$query = $this -> db -> query ( $sql , array ( $col_mode , $col_submode , json_decode ( $ids , true ), $this -> session -> userdata ( 'user_id' )));
} else if ( $column == 'COL_QSL_VIA' ) {
$sql = " UPDATE " . $this -> config -> item ( 'table_name' ) . " JOIN station_profile ON " . $this -> config -> item ( 'table_name' ) . " .station_id = station_profile.station_id " .
" SET " . $this -> config -> item ( 'table_name' ) . " .COL_QSL_VIA = ? " .
2024-02-20 16:06:52 +00:00
" WHERE " . $this -> config -> item ( 'table_name' ) . " .col_primary_key in ? and station_profile.user_id = ? " ;
2024-02-19 19:05:09 +01:00
$query = $this -> db -> query ( $sql , array ( $value , json_decode ( $ids , true ), $this -> session -> userdata ( 'user_id' )));
} else if ( $column == 'COL_TIME_ON' ) {
2024-02-19 19:48:34 +01:00
$sql = " UPDATE " . $this -> config -> item ( 'table_name' ) . " JOIN station_profile ON " . $this -> config -> item ( 'table_name' ) . " .station_id = station_profile.station_id " .
" SET " . $this -> config -> item ( 'table_name' ) . " .col_time_on = TIMESTAMP(CONCAT(DATE_FORMAT(?, '%Y-%m-%d'), ' ', cast(col_time_on as time))) " .
" WHERE " . $this -> config -> item ( 'table_name' ) . " .col_primary_key in ? and station_profile.user_id = ? " ;
$query = $this -> db -> query ( $sql , array ( $value , json_decode ( $ids , true ), $this -> session -> userdata ( 'user_id' )));
2024-02-19 19:05:09 +01:00
} else if ( $column == 'COL_SAT_NAME' ) {
2025-01-14 09:22:08 +01:00
$bindings = [];
2024-02-19 19:05:09 +01:00
$propmode = $value == '' ? '' : 'SAT' ;
2024-02-20 17:12:46 +00:00
$satmode = $value2 ? ? '' ;
2025-01-14 09:22:08 +01:00
$bandtx = $value3 == '' ? '' : $value3 ;
$bandrx = $value4 == '' ? '' : $value4 ;
$bindings [] = $value ;
$bindings [] = $propmode ;
2024-02-19 19:05:09 +01:00
$sql = " UPDATE " . $this -> config -> item ( 'table_name' ) . " JOIN station_profile ON " . $this -> config -> item ( 'table_name' ) . " .station_id = station_profile.station_id " .
" SET " . $this -> config -> item ( 'table_name' ) . " .COL_SAT_NAME = ? " .
2025-01-14 09:22:08 +01:00
" , " . $this -> config -> item ( 'table_name' ) . " .COL_PROP_MODE = ? " ;
if ( $satmode != '' ) {
$sql .= " , " . $this -> config -> item ( 'table_name' ) . " .COL_SAT_MODE = ? " ;
$bindings [] = $satmode ;
}
if ( $bandtx != '' ) {
$sql .= " , " . $this -> config -> item ( 'table_name' ) . " .COL_BAND = ? " ;
$bindings [] = $bandtx ;
$frequencyBand = $this -> frequency -> defaultFrequencies [ $bandtx ][ 'CW' ];
$sql .= " , " . $this -> config -> item ( 'table_name' ) . " .COL_FREQ = ? " ;
$bindings [] = $frequencyBand ;
}
if ( $bandrx != '' ) {
$sql .= " , " . $this -> config -> item ( 'table_name' ) . " .COL_BAND_RX = ? " ;
$bindings [] = $bandrx ;
$frequencyBandRx = $bandrx == '' ? null : $this -> frequency -> defaultFrequencies [ $bandrx ][ 'CW' ];
$sql .= " , " . $this -> config -> item ( 'table_name' ) . " .COL_FREQ_RX = ? " ;
$bindings [] = $frequencyBandRx ;
}
$sql .= " WHERE " . $this -> config -> item ( 'table_name' ) . " .col_primary_key in ? and station_profile.user_id = ? " ;
$bindings [] = json_decode ( $ids , true );
$bindings [] = $this -> session -> userdata ( 'user_id' );
2024-02-19 19:05:09 +01:00
2025-01-14 09:22:08 +01:00
$query = $this -> db -> query ( $sql , $bindings );
2024-07-26 09:55:26 +02:00
} else if ( $column == 'COL_LOTW_QSL_SENT' ) {
$sql = " UPDATE " . $this -> config -> item ( 'table_name' ) . " JOIN station_profile ON " . $this -> config -> item ( 'table_name' ) . " .station_id = station_profile.station_id " .
" SET " . $this -> config -> item ( 'table_name' ) . " .COL_LOTW_QSL_SENT = ?, " . $this -> config -> item ( 'table_name' ) . " .COL_LOTW_QSLSDATE = now() " .
" WHERE " . $this -> config -> item ( 'table_name' ) . " .col_primary_key in ? and station_profile.user_id = ? " ;
$query = $this -> db -> query ( $sql , array ( $value , json_decode ( $ids , true ), $this -> session -> userdata ( 'user_id' )));
} else if ( $column == 'COL_LOTW_QSL_RCVD' ) {
$sql = " UPDATE " . $this -> config -> item ( 'table_name' ) . " JOIN station_profile ON " . $this -> config -> item ( 'table_name' ) . " .station_id = station_profile.station_id " .
" SET " . $this -> config -> item ( 'table_name' ) . " .COL_LOTW_QSL_RCVD = ?, " . $this -> config -> item ( 'table_name' ) . " .COL_LOTW_QSLRDATE = now() " .
" WHERE " . $this -> config -> item ( 'table_name' ) . " .col_primary_key in ? and station_profile.user_id = ? " ;
2024-08-03 15:00:35 +02:00
$query = $this -> db -> query ( $sql , array ( $value , json_decode ( $ids , true ), $this -> session -> userdata ( 'user_id' )));
2024-10-14 18:38:05 +02:00
} else if ( $column == 'COL_QRZCOM_QSO_UPLOAD_STATUS' ) {
$skipqrzupdate = true ;
$sql = " UPDATE " . $this -> config -> item ( 'table_name' ) . " JOIN station_profile ON " . $this -> config -> item ( 'table_name' ) . " .station_id = station_profile.station_id " .
" SET " . $this -> config -> item ( 'table_name' ) . " .COL_QRZCOM_QSO_UPLOAD_STATUS = ?, " . $this -> config -> item ( 'table_name' ) . " .COL_QRZCOM_QSO_UPLOAD_DATE = now() " .
" WHERE " . $this -> config -> item ( 'table_name' ) . " .col_primary_key in ? and station_profile.user_id = ? " ;
$query = $this -> db -> query ( $sql , array ( $value , json_decode ( $ids , true ), $this -> session -> userdata ( 'user_id' )));
} else if ( $column == 'COL_QRZCOM_QSO_DOWNLOAD_STATUS' ) {
$skipqrzupdate = true ;
$sql = " UPDATE " . $this -> config -> item ( 'table_name' ) . " JOIN station_profile ON " . $this -> config -> item ( 'table_name' ) . " .station_id = station_profile.station_id " .
" SET " . $this -> config -> item ( 'table_name' ) . " .COL_QRZCOM_QSO_DOWNLOAD_STATUS = ?, " . $this -> config -> item ( 'table_name' ) . " .COL_QRZCOM_QSO_DOWNLOAD_DATE = now() " .
" WHERE " . $this -> config -> item ( 'table_name' ) . " .col_primary_key in ? and station_profile.user_id = ? " ;
$query = $this -> db -> query ( $sql , array ( $value , json_decode ( $ids , true ), $this -> session -> userdata ( 'user_id' )));
2024-11-18 08:34:51 +00:00
} else if ( $column == 'COL_EQSL_QSL_SENT' ) {
$skipqrzupdate = true ;
$sql = " UPDATE " . $this -> config -> item ( 'table_name' ) . " JOIN station_profile ON " . $this -> config -> item ( 'table_name' ) . " .station_id = station_profile.station_id " .
" SET " . $this -> config -> item ( 'table_name' ) . " .COL_EQSL_QSL_SENT = ?, " . $this -> config -> item ( 'table_name' ) . " .COL_EQSL_QSLSDATE = now() " .
" WHERE " . $this -> config -> item ( 'table_name' ) . " .col_primary_key in ? and station_profile.user_id = ? " ;
$query = $this -> db -> query ( $sql , array ( $value , json_decode ( $ids , true ), $this -> session -> userdata ( 'user_id' )));
} else if ( $column == 'COL_EQSL_QSL_RCVD' ) {
$skipqrzupdate = true ;
$sql = " UPDATE " . $this -> config -> item ( 'table_name' ) . " JOIN station_profile ON " . $this -> config -> item ( 'table_name' ) . " .station_id = station_profile.station_id " .
" SET " . $this -> config -> item ( 'table_name' ) . " .COL_EQSL_QSL_RCVD = ?, " . $this -> config -> item ( 'table_name' ) . " .COL_EQSL_QSLRDATE = now() " .
" WHERE " . $this -> config -> item ( 'table_name' ) . " .col_primary_key in ? and station_profile.user_id = ? " ;
2025-01-07 18:53:38 +01:00
$query = $this -> db -> query ( $sql , array ( $value , json_decode ( $ids , true ), $this -> session -> userdata ( 'user_id' )));
} else if ( $column == 'COL_CLUBLOG_QSO_DOWNLOAD_STATUS' ) {
$skipqrzupdate = true ;
$sql = " UPDATE " . $this -> config -> item ( 'table_name' ) . " JOIN station_profile ON " . $this -> config -> item ( 'table_name' ) . " .station_id = station_profile.station_id " .
" SET " . $this -> config -> item ( 'table_name' ) . " .COL_CLUBLOG_QSO_DOWNLOAD_STATUS = ?, " . $this -> config -> item ( 'table_name' ) . " .COL_CLUBLOG_QSO_DOWNLOAD_DATE = now() " .
" WHERE " . $this -> config -> item ( 'table_name' ) . " .col_primary_key in ? and station_profile.user_id = ? " ;
$query = $this -> db -> query ( $sql , array ( $value , json_decode ( $ids , true ), $this -> session -> userdata ( 'user_id' )));
} else if ( $column == 'COL_CLUBLOG_QSO_UPLOAD_STATUS' ) {
$skipqrzupdate = true ;
$sql = " UPDATE " . $this -> config -> item ( 'table_name' ) . " JOIN station_profile ON " . $this -> config -> item ( 'table_name' ) . " .station_id = station_profile.station_id " .
" SET " . $this -> config -> item ( 'table_name' ) . " .COL_CLUBLOG_QSO_UPLOAD_STATUS = ?, " . $this -> config -> item ( 'table_name' ) . " .COL_CLUBLOG_QSO_UPLOAD_DATE = now() " .
" WHERE " . $this -> config -> item ( 'table_name' ) . " .col_primary_key in ? and station_profile.user_id = ? " ;
2024-11-18 08:34:51 +00:00
$query = $this -> db -> query ( $sql , array ( $value , json_decode ( $ids , true ), $this -> session -> userdata ( 'user_id' )));
2024-08-03 15:00:35 +02:00
} else if ( $column == 'COL_QSLMSG' ) {
$sql = " UPDATE " . $this -> config -> item ( 'table_name' ) . " JOIN station_profile ON " . $this -> config -> item ( 'table_name' ) . " .station_id = station_profile.station_id " .
" SET " . $this -> config -> item ( 'table_name' ) . " .COL_QSLMSG = ? " .
" WHERE " . $this -> config -> item ( 'table_name' ) . " .col_primary_key in ? and station_profile.user_id = ? " ;
2024-09-05 11:35:21 +02:00
$query = $this -> db -> query ( $sql , array ( $value , json_decode ( $ids , true ), $this -> session -> userdata ( 'user_id' )));
} else if ( $column == 'COL_CONT' ) {
$sql = " UPDATE " . $this -> config -> item ( 'table_name' ) . " JOIN station_profile ON " . $this -> config -> item ( 'table_name' ) . " .station_id = station_profile.station_id " .
" SET " . $this -> config -> item ( 'table_name' ) . " .COL_CONT = ? " .
" WHERE " . $this -> config -> item ( 'table_name' ) . " .col_primary_key in ? and station_profile.user_id = ? " ;
2024-07-26 09:55:26 +02:00
$query = $this -> db -> query ( $sql , array ( $value , json_decode ( $ids , true ), $this -> session -> userdata ( 'user_id' )));
2024-11-01 20:44:40 +01:00
} else if ( $column == 'COL_TX_PWR' ) {
$sql = " UPDATE " . $this -> config -> item ( 'table_name' ) . " JOIN station_profile ON " . $this -> config -> item ( 'table_name' ) . " .station_id = station_profile.station_id " .
" SET " . $this -> config -> item ( 'table_name' ) . " .COL_TX_PWR = ? " .
" WHERE " . $this -> config -> item ( 'table_name' ) . " .col_primary_key in ? and station_profile.user_id = ? " ;
$query = $this -> db -> query ( $sql , array ( $value , json_decode ( $ids , true ), $this -> session -> userdata ( 'user_id' )));
2024-12-23 14:43:01 +01:00
} else if ( $column == 'COL_REGION' ) {
$sql = " UPDATE " . $this -> config -> item ( 'table_name' ) . " JOIN station_profile ON " . $this -> config -> item ( 'table_name' ) . " .station_id = station_profile.station_id " .
" SET " . $this -> config -> item ( 'table_name' ) . " .COL_REGION = ? " .
" WHERE " . $this -> config -> item ( 'table_name' ) . " .col_primary_key in ? and station_profile.user_id = ? " ;
$query = $this -> db -> query ( $sql , array ( $value , json_decode ( $ids , true ), $this -> session -> userdata ( 'user_id' )));
} else {
2024-02-19 19:05:09 +01:00
$sql = " UPDATE " . $this -> config -> item ( 'table_name' ) . " JOIN station_profile ON " . $this -> config -> item ( 'table_name' ) . " .station_id = station_profile.station_id SET " . $this -> config -> item ( 'table_name' ) . " . " . $column . " = ? WHERE " . $this -> config -> item ( 'table_name' ) . " .col_primary_key in ? and station_profile.user_id = ? " ;
$query = $this -> db -> query ( $sql , array ( $value , json_decode ( $ids , true ), $this -> session -> userdata ( 'user_id' )));
}
2024-10-14 18:38:05 +02:00
if ( ! $skipqrzupdate ) {
$sql = " UPDATE " . $this -> config -> item ( 'table_name' ) . " JOIN station_profile ON " . $this -> config -> item ( 'table_name' ) . " .station_id = station_profile.station_id SET " . $this -> config -> item ( 'table_name' ) . " .COL_QRZCOM_QSO_UPLOAD_STATUS = 'M' WHERE " . $this -> config -> item ( 'table_name' ) . " .col_primary_key in ? and station_profile.user_id = ? and col_qrzcom_qso_upload_status = 'Y' " ;
$query = $this -> db -> query ( $sql , array ( json_decode ( $ids , true ), $this -> session -> userdata ( 'user_id' )));
2024-09-16 10:39:38 +02:00
}
2024-02-18 09:41:54 +01:00
$this -> db -> trans_complete ();
2024-02-16 13:52:20 +01:00
return array ( 'message' => 'OK' );
}
2024-02-18 20:19:45 +01:00
function deleteQsos ( $ids ) {
$this -> db -> trans_start ();
$sql = " delete from " . $this -> config -> item ( 'table_name' ) . " WHERE col_primary_key in ? and station_id in (select station_id from station_profile where user_id = ?) " ;
$query = $this -> db -> query ( $sql , array ( json_decode ( $ids , true ), $this -> session -> userdata ( 'user_id' )));
$this -> db -> trans_complete ();
}
2024-02-20 15:24:49 +01:00
function getPrimarySubdivisonsDxccs () {
$sql = " select distinct primary_subdivisions.adif, dxcc_entities.name, dxcc_entities.prefix
from primary_subdivisions
join dxcc_entities on primary_subdivisions . adif = dxcc_entities . adif
order by prefix " ;
$query = $this -> db -> query ( $sql );
return $query -> result ();
}
function getSubdivisons ( $dxccid ) {
$sql = " select * from primary_subdivisions where adif = ? order by subdivision " ;
$query = $this -> db -> query ( $sql , array ( $dxccid ));
return $query -> result ();
}
2023-10-04 14:46:18 +02:00
}