2011-04-25 15:24:01 +00:00
< ? php
class Logbook_model extends CI_Model {
2016-02-12 16:31:29 +00:00
function __construct ()
{
// Call the Model constructor
parent :: __construct ();
}
2011-04-25 15:24:01 +00:00
2012-11-14 16:01:51 +00:00
/* Add QSO to Logbook */
2016-02-12 16:31:29 +00:00
function create_qso () {
// Join date+time
$datetime = date ( " Y-m-d " , strtotime ( $this -> input -> post ( 'start_date' ))) . " " . $this -> input -> post ( 'start_time' );
2019-08-19 16:07:32 +00:00
2016-02-12 16:31:29 +00:00
if ( $this -> input -> post ( 'prop_mode' ) != null ) {
$prop_mode = $this -> input -> post ( 'prop_mode' );
} else {
$prop_mode = " " ;
}
if ( $this -> input -> post ( 'sat_name' )) {
$prop_mode = " SAT " ;
}
if ( $this -> session -> userdata ( 'user_locator' )){
$locator = $this -> session -> userdata ( 'user_locator' );
} else {
$locator = $this -> config -> item ( 'locator' );
}
2019-08-19 15:05:47 +00:00
if ( $this -> input -> post ( 'country' ) == " " ) {
$dxcc = $this -> check_dxcc_table ( strtoupper ( trim ( $this -> input -> post ( 'callsign' ))), $datetime );
$country = ucwords ( strtolower ( $dxcc [ 1 ]));
} else {
$country = $this -> input -> post ( 'country' );
}
if ( $this -> input -> post ( 'cqz' ) == " " ) {
$dxcc = $this -> check_dxcc_table ( strtoupper ( trim ( $this -> input -> post ( 'callsign' ))), $datetime );
2019-08-27 15:18:31 +00:00
if ( empty ( $dxcc [ 2 ])) {
$cqz = null ;
} else {
$cqz = $dxcc [ 2 ];
}
2019-08-19 15:05:47 +00:00
} else {
$cqz = $this -> input -> post ( 'cqz' );
}
if ( $this -> input -> post ( 'dxcc_id' ) == " " ) {
2019-08-27 15:18:31 +00:00
2019-08-19 15:05:47 +00:00
$dxcc = $this -> check_dxcc_table ( strtoupper ( trim ( $this -> input -> post ( 'callsign' ))), $datetime );
2019-08-27 15:18:31 +00:00
if ( empty ( $dxcc [ 0 ])) {
$dxcc_id = null ;
} else {
$dxcc_id = $dxcc [ 0 ];
}
2019-08-19 15:05:47 +00:00
} else {
$dxcc_id = $this -> input -> post ( 'dxcc_id' );
}
2016-02-12 16:31:29 +00:00
// Create array with QSO Data
$data = array (
'COL_TIME_ON' => $datetime ,
'COL_TIME_OFF' => $datetime ,
'COL_CALL' => strtoupper ( trim ( $this -> input -> post ( 'callsign' ))),
'COL_BAND' => $this -> input -> post ( 'band' ),
2019-02-25 23:43:14 +00:00
'COL_FREQ' => $this -> parse_frequency ( $this -> input -> post ( 'freq_display' )),
2016-02-12 16:31:29 +00:00
'COL_MODE' => $this -> input -> post ( 'mode' ),
'COL_RST_RCVD' => $this -> input -> post ( 'rst_recv' ),
'COL_RST_SENT' => $this -> input -> post ( 'rst_sent' ),
'COL_NAME' => $this -> input -> post ( 'name' ),
'COL_COMMENT' => $this -> input -> post ( 'comment' ),
'COL_SAT_NAME' => strtoupper ( $this -> input -> post ( 'sat_name' )),
'COL_SAT_MODE' => strtoupper ( $this -> input -> post ( 'sat_mode' )),
2019-08-19 15:05:47 +00:00
'COL_COUNTRY' => $country ,
2016-02-12 16:31:29 +00:00
'COL_QSLSDATE' => date ( 'Y-m-d' ),
'COL_QSLRDATE' => date ( 'Y-m-d' ),
'COL_QSL_SENT' => $this -> input -> post ( 'qsl_sent' ),
'COL_QSL_RCVD' => $this -> input -> post ( 'qsl_recv' ),
'COL_QSL_SENT_VIA' => $this -> input -> post ( 'qsl_sent_method' ),
'COL_QSL_RCVD_VIA' => $this -> input -> post ( 'qsl_recv_method' ),
'COL_QSL_VIA' => $this -> input -> post ( 'qsl_via' ),
'COL_OPERATOR' => $this -> session -> userdata ( 'user_callsign' ),
'COL_QTH' => $this -> input -> post ( 'qth' ),
'COL_PROP_MODE' => $prop_mode ,
'COL_IOTA' => trim ( $this -> input -> post ( 'iota_ref' )),
'COL_DISTANCE' => " 0 " ,
2019-02-25 23:43:14 +00:00
'COL_FREQ_RX' => $this -> parse_frequency ( $this -> input -> post ( 'freq_display_rx' )),
2016-02-12 16:31:29 +00:00
'COL_BAND_RX' => null ,
'COL_ANT_AZ' => null ,
'COL_ANT_EL' => null ,
'COL_A_INDEX' => null ,
'COL_AGE' => null ,
'COL_TEN_TEN' => null ,
'COL_TX_PWR' => null ,
'COL_STX' => null ,
'COL_SRX' => null ,
'COL_NR_BURSTS' => null ,
'COL_NR_PINGS' => null ,
'COL_MAX_BURSTS' => null ,
'COL_K_INDEX' => null ,
'COL_SFI' => null ,
'COL_RX_PWR' => null ,
'COL_LAT' => null ,
'COL_LON' => null ,
2019-08-19 15:05:47 +00:00
'COL_DXCC' => $dxcc_id ,
'COL_CQZ' => $cqz ,
2019-06-13 17:35:14 +00:00
'COL_SOTA_REF' => trim ( $this -> input -> post ( 'sota_ref' )),
2019-08-19 15:05:47 +00:00
'COL_DARC_DOK' => trim ( $this -> input -> post ( 'darc_dok' )),
2016-02-12 16:31:29 +00:00
);
2019-09-23 17:30:17 +00:00
$station_id = $this -> input -> post ( 'station_profile' );
if ( $station_id == " " || $station_id == " 0 " ) {
$CI =& get_instance ();
$CI -> load -> model ( 'Stations' );
$station_id = $CI -> Stations -> find_active ();
}
2019-01-01 19:14:25 +00:00
// If station profile has been provided fill in the fields
2019-09-23 17:30:17 +00:00
if ( $station_id != " 0 " ) {
$station = $this -> check_station ( $station_id );
2019-09-24 21:05:27 +00:00
$data [ 'station_id' ] = $station_id ;
2019-01-01 19:14:25 +00:00
if ( strpos ( trim ( $station [ 'station_gridsquare' ]), ',' ) !== false ) {
$data [ 'COL_MY_VUCC_GRIDS' ] = strtoupper ( trim ( $station [ 'station_gridsquare' ]));
} else {
$data [ 'COL_MY_GRIDSQUARE' ] = strtoupper ( trim ( $station [ 'station_gridsquare' ]));
}
$data [ 'COL_MY_CITY' ] = strtoupper ( trim ( $station [ 'station_city' ]));
$data [ 'COL_MY_IOTA' ] = strtoupper ( trim ( $station [ 'station_iota' ]));
$data [ 'COL_MY_SOTA_REF' ] = strtoupper ( trim ( $station [ 'station_sota' ]));
$data [ 'COL_STATION_CALLSIGN' ] = strtoupper ( trim ( $station [ 'station_callsign' ]));
$data [ 'COL_MY_DXCC' ] = strtoupper ( trim ( $station [ 'station_dxcc' ]));
$data [ 'COL_MY_COUNTRY' ] = strtoupper ( trim ( $station [ 'station_country' ]));
$data [ 'COL_MY_CNTY' ] = strtoupper ( trim ( $station [ 'station_cnty' ]));
$data [ 'COL_MY_CQ_ZONE' ] = strtoupper ( trim ( $station [ 'station_cq' ]));
$data [ 'COL_MY_ITU_ZONE' ] = strtoupper ( trim ( $station [ 'station_itu' ]));
}
// Decide whether its single gridsquare or a multi which makes it vucc_grids
2018-12-31 15:43:21 +00:00
if ( strpos ( trim ( $this -> input -> post ( 'locator' )), ',' ) !== false ) {
$data [ 'COL_VUCC_GRIDS' ] = strtoupper ( trim ( $this -> input -> post ( 'locator' )));
} else {
$data [ 'COL_GRIDSQUARE' ] = strtoupper ( trim ( $this -> input -> post ( 'locator' )));
}
2016-02-13 13:55:16 +00:00
// if eQSL username set, default SENT & RCVD to 'N' else leave as null
if ( $this -> session -> userdata ( 'user_eqsl_name' )){
$data [ 'COL_EQSL_QSL_SENT' ] = 'N' ;
$data [ 'COL_EQSL_QSL_RCVD' ] = 'N' ;
}
2018-12-15 17:02:17 +00:00
// if LoTW username set, default SENT & RCVD to 'N' else leave as null
if ( $this -> session -> userdata ( 'user_lotw_name' )){
$data [ 'COL_LOTW_QSL_SENT' ] = 'N' ;
$data [ 'COL_LOTW_QSL_RCVD' ] = 'N' ;
}
2016-02-12 16:31:29 +00:00
$this -> add_qso ( $data );
}
2012-09-06 16:27:27 +00:00
2019-01-01 19:14:25 +00:00
public function check_station ( $id ){
$this -> db -> where ( 'station_id' , $id );
$query = $this -> db -> get ( 'station_profile' );
if ( $query -> num_rows () > 0 ) {
$row = $query -> row_array ();
return ( $row );
}
}
2019-08-15 10:53:32 +00:00
public function get_callsigns ( $callsign ){
$this -> db -> select ( 'COL_CALL' );
$this -> db -> distinct ();
$this -> db -> like ( 'COL_CALL' , $callsign );
$query = $this -> db -> get ( $this -> config -> item ( 'table_name' ));
$result = " " ;
foreach ( $query -> result () as $row )
{
$result = $result . " " . $row -> COL_CALL ;
}
return $result ;
}
2012-11-14 16:01:51 +00:00
function add_qso ( $data ) {
2019-06-15 11:45:29 +00:00
if ( $data [ 'COL_DXCC' ] == " Not Found " ){
$data [ 'COL_DXCC' ] = NULL ;
}
if ( ! is_null ( $data [ 'COL_RX_PWR' ])) {
$data [ 'COL_RX_PWR' ] = str_replace ( " W " , " " , $data [ 'COL_RX_PWR' ]);
}
2012-11-14 16:01:51 +00:00
// Add QSO to database
$this -> db -> insert ( $this -> config -> item ( 'table_name' ), $data );
}
2014-09-25 22:09:44 +00:00
2012-11-14 16:01:51 +00:00
/* Edit QSO */
function edit () {
2014-09-25 22:09:44 +00:00
2012-11-14 16:01:51 +00:00
$data = array (
'COL_TIME_ON' => $this -> input -> post ( 'time_on' ),
'COL_TIME_OFF' => $this -> input -> post ( 'time_off' ),
2013-02-16 14:48:27 +00:00
'COL_CALL' => strtoupper ( trim ( $this -> input -> post ( 'callsign' ))),
2012-11-14 16:01:51 +00:00
'COL_BAND' => $this -> input -> post ( 'band' ),
2019-02-25 23:43:14 +00:00
'COL_FREQ' => $this -> parse_frequency ( $this -> input -> post ( 'freq' )),
2012-11-14 16:01:51 +00:00
'COL_MODE' => $this -> input -> post ( 'mode' ),
'COL_RST_RCVD' => $this -> input -> post ( 'rst_recv' ),
'COL_RST_SENT' => $this -> input -> post ( 'rst_sent' ),
2013-02-16 14:48:27 +00:00
'COL_GRIDSQUARE' => strtoupper ( trim ( $this -> input -> post ( 'locator' ))),
2018-12-31 15:43:21 +00:00
'COL_VUCC_GRIDS' => strtoupper ( trim ( $this -> input -> post ( 'vucc_grids' ))),
2012-11-14 16:01:51 +00:00
'COL_COMMENT' => $this -> input -> post ( 'comment' ),
'COL_NAME' => $this -> input -> post ( 'name' ),
2013-02-16 14:48:27 +00:00
'COL_COUNTRY' => $this -> input -> post ( 'country' ),
2012-11-14 16:01:51 +00:00
'COL_SAT_NAME' => $this -> input -> post ( 'sat_name' ),
'COL_SAT_MODE' => $this -> input -> post ( 'sat_mode' ),
'COL_QSLSDATE' => date ( 'Y-m-d' ),
'COL_QSLRDATE' => date ( 'Y-m-d' ),
'COL_QSL_SENT' => $this -> input -> post ( 'qsl_sent' ),
'COL_QSL_RCVD' => $this -> input -> post ( 'qsl_recv' ),
'COL_QSL_SENT_VIA' => $this -> input -> post ( 'qsl_sent_method' ),
'COL_QSL_RCVD_VIA' => $this -> input -> post ( 'qsl_recv_method' ),
2013-02-12 00:55:11 +00:00
'COL_EQSL_QSL_SENT' => $this -> input -> post ( 'eqsl_sent' ),
'COL_EQSL_QSL_RCVD' => $this -> input -> post ( 'eqsl_recv' ),
'COL_LOTW_QSL_SENT' => $this -> input -> post ( 'lotw_sent' ),
'COL_LOTW_QSL_RCVD' => $this -> input -> post ( 'lotw_recv' ),
2012-11-14 16:01:51 +00:00
'COL_IOTA' => $this -> input -> post ( 'iota_ref' ),
2019-06-13 17:35:14 +00:00
'COL_SOTA_REF' => $this -> input -> post ( 'sota_ref' ),
2019-06-25 07:07:42 +00:00
'COL_DARC_DOK' => $this -> input -> post ( 'darc_dok' ),
2012-11-14 16:01:51 +00:00
'COL_QTH' => $this -> input -> post ( 'qth' ),
2016-01-10 01:09:54 +00:00
'COL_PROP_MODE' => $this -> input -> post ( 'prop_mode' ),
2019-02-25 23:43:14 +00:00
'COL_FREQ_RX' => $this -> parse_frequency ( $this -> input -> post ( 'freq_display_rx' )),
2012-11-14 16:01:51 +00:00
'COL_STX_STRING' => $this -> input -> post ( 'stx_string' ),
2019-06-13 13:34:31 +00:00
'COL_SRX_STRING' => $this -> input -> post ( 'srx_string' ),
2019-06-30 15:41:03 +00:00
'COL_QSL_VIA' => $this -> input -> post ( 'qsl_via_callsign' ),
2019-10-06 15:00:01 +00:00
'station_id' => $this -> input -> post ( 'station_profile' ),
2019-10-06 15:08:11 +00:00
'COL_OPERATOR' => $this -> input -> post ( 'operator_callsign' ),
2012-11-14 16:01:51 +00:00
);
$this -> db -> where ( 'COL_PRIMARY_KEY' , $this -> input -> post ( 'id' ));
2014-09-25 22:09:44 +00:00
$this -> db -> update ( $this -> config -> item ( 'table_name' ), $data );
2012-11-14 16:01:51 +00:00
}
2019-06-15 18:20:20 +00:00
/* QSL received */
function qsl_rcvd () {
$data = array (
'COL_QSLRDATE' => date ( 'Y-m-d' ),
'COL_QSL_RCVD' => " Y "
);
$this -> db -> where ( 'COL_PRIMARY_KEY' , $this -> input -> post ( 'id' ));
$this -> db -> update ( $this -> config -> item ( 'table_name' ), $data );
}
2012-11-14 16:01:51 +00:00
/* Return last 10 QSOs */
function last_ten () {
$this -> db -> select ( 'COL_CALL, COL_BAND, COL_TIME_ON, COL_RST_RCVD, COL_RST_SENT, COL_MODE, COL_NAME, COL_COUNTRY, COL_PRIMARY_KEY, COL_SAT_NAME' );
$this -> db -> order_by ( " COL_TIME_ON " , " desc " );
$this -> db -> limit ( 10 );
2014-09-25 22:09:44 +00:00
2012-11-14 16:01:51 +00:00
return $this -> db -> get ( $this -> config -> item ( 'table_name' ));
}
2014-09-25 22:09:44 +00:00
2012-11-14 16:01:51 +00:00
/* Show custom number of qsos */
function last_custom ( $num ) {
$this -> db -> select ( 'COL_CALL, COL_BAND, COL_TIME_ON, COL_RST_RCVD, COL_RST_SENT, COL_MODE, COL_NAME, COL_COUNTRY, COL_PRIMARY_KEY, COL_SAT_NAME' );
$this -> db -> order_by ( " COL_TIME_ON " , " desc " );
$this -> db -> limit ( $num );
2014-09-25 22:09:44 +00:00
2012-11-14 16:01:51 +00:00
return $this -> db -> get ( $this -> config -> item ( 'table_name' ));
}
2014-09-25 22:09:44 +00:00
2011-07-24 22:33:08 +00:00
/* Callsign QRA */
2014-09-25 22:09:44 +00:00
2019-02-26 13:19:52 +00:00
function call_qra ( $callsign ) {
$this -> db -> select ( 'COL_CALL, COL_GRIDSQUARE, COL_TIME_ON' );
$this -> db -> where ( 'COL_CALL' , $callsign );
$where = " COL_GRIDSQUARE != \" \" " ;
$this -> db -> where ( $where );
$this -> db -> order_by ( " COL_TIME_ON " , " desc " );
$this -> db -> limit ( 1 );
$query = $this -> db -> get ( $this -> config -> item ( 'table_name' ));
$callsign = " " ;
if ( $query -> num_rows () > 0 )
{
$data = $query -> row ();
$callsign = strtoupper ( $data -> COL_GRIDSQUARE );
}
return $callsign ;
}
function call_name ( $callsign ) {
$this -> db -> select ( 'COL_CALL, COL_NAME, COL_TIME_ON' );
$this -> db -> where ( 'COL_CALL' , $callsign );
$where = " COL_NAME != \" \" " ;
$this -> db -> where ( $where );
$this -> db -> order_by ( " COL_TIME_ON " , " desc " );
$this -> db -> limit ( 1 );
$query = $this -> db -> get ( $this -> config -> item ( 'table_name' ));
$name = " " ;
if ( $query -> num_rows () > 0 )
{
$data = $query -> row ();
$name = $data -> COL_NAME ;
}
return $name ;
}
2019-06-17 10:15:05 +00:00
function call_qslvia ( $callsign ) {
$this -> db -> select ( 'COL_CALL, COL_QSL_VIA, COL_TIME_ON' );
$this -> db -> where ( 'COL_CALL' , $callsign );
$where = " COL_NAME != \" \" " ;
$this -> db -> where ( $where );
$this -> db -> order_by ( " COL_TIME_ON " , " desc " );
$this -> db -> limit ( 1 );
$query = $this -> db -> get ( $this -> config -> item ( 'table_name' ));
$name = " " ;
if ( $query -> num_rows () > 0 )
{
$data = $query -> row ();
$qsl_via = $data -> COL_QSL_VIA ;
}
return $qsl_via ;
}
2019-02-26 13:19:52 +00:00
function call_qth ( $callsign ) {
$this -> db -> select ( 'COL_CALL, COL_QTH, COL_TIME_ON' );
$this -> db -> where ( 'COL_CALL' , $callsign );
$where = " COL_QTH != \" \" " ;
$this -> db -> where ( $where );
$this -> db -> order_by ( " COL_TIME_ON " , " desc " );
$this -> db -> limit ( 1 );
$query = $this -> db -> get ( $this -> config -> item ( 'table_name' ));
$name = " " ;
if ( $query -> num_rows () > 0 )
{
$data = $query -> row ();
$name = $data -> COL_QTH ;
}
return $name ;
}
function call_iota ( $callsign ) {
$this -> db -> select ( 'COL_CALL, COL_IOTA, COL_TIME_ON' );
$this -> db -> where ( 'COL_CALL' , $callsign );
$where = " COL_IOTA != \" \" " ;
$this -> db -> where ( $where );
$this -> db -> order_by ( " COL_TIME_ON " , " desc " );
$this -> db -> limit ( 1 );
$query = $this -> db -> get ( $this -> config -> item ( 'table_name' ));
$name = " " ;
if ( $query -> num_rows () > 0 )
{
$data = $query -> row ();
$name = $data -> COL_IOTA ;
}
return $name ;
}
2012-11-14 16:01:51 +00:00
/* Return QSO Info */
function qso_info ( $id ) {
2014-09-25 22:09:44 +00:00
$this -> db -> where ( 'COL_PRIMARY_KEY' , $id );
2012-11-14 16:01:51 +00:00
return $this -> db -> get ( $this -> config -> item ( 'table_name' ));
}
2014-09-25 22:09:44 +00:00
2012-11-14 16:01:51 +00:00
2019-06-16 14:29:31 +00:00
// Set Paper to recived
2019-09-27 21:04:49 +00:00
function paperqsl_update ( $qso_id , $method ) {
2019-06-16 14:29:31 +00:00
$data = array (
'COL_QSLRDATE' => date ( 'Y-m-d' ),
'COL_QSL_RCVD' => 'Y' ,
'COL_QSL_RCVD_VIA' => $method
);
$this -> db -> where ( 'COL_PRIMARY_KEY' , $qso_id );
$this -> db -> update ( $this -> config -> item ( 'table_name' ), $data );
}
2019-08-28 19:13:24 +00:00
function get_qsos_for_printing () {
2019-09-27 21:04:49 +00:00
$CI =& get_instance ();
$CI -> load -> model ( 'Stations' );
$station_id = $CI -> Stations -> find_active ();
2019-09-28 15:35:57 +00:00
$query = $this -> db -> query ( ' SELECT
STATION_CALLSIGN ,
COL_PRIMARY_KEY ,
COL_CALL ,
COL_QSL_VIA ,
COL_TIME_ON ,
COL_MODE ,
COL_FREQ ,
UPPER ( COL_BAND ) as COL_BAND ,
COL_RST_SENT ,
COL_SAT_NAME ,
COL_SAT_MODE ,
COL_QSL_RCVD ,
( CASE WHEN COL_QSL_VIA != \ ' \ ' THEN COL_QSL_VIA ELSE COL_CALL END ) AS COL_ROUTING ,
ADIF ,
ENTITY
FROM '.$this->config->item(' table_name ').' , dxcc_prefixes , station_profile
WHERE
COL_QSL_SENT LIKE \ ' R\ '
and ( CASE WHEN COL_QSL_VIA != \ ' \ ' THEN COL_QSL_VIA ELSE COL_CALL END ) like CONCAT ( dxcc_prefixes . call , \ ' % \ ' )
and ( end is null or end > now ())
and '.$this->config->item(' table_name ').' . station_id = '.$station_id.'
and '.$this->config->item(' table_name ').' . station_id = station_profile . station_id
ORDER BY adif , col_routing ' );
2019-08-28 19:13:24 +00:00
return $query ;
}
2019-06-16 14:29:31 +00:00
2012-11-14 16:01:51 +00:00
function get_qsos ( $num , $offset ) {
2019-09-24 21:54:37 +00:00
$this -> db -> select ( '' . $this -> config -> item ( 'table_name' ) . '.COL_CALL, ' . $this -> config -> item ( 'table_name' ) . '.COL_BAND, ' . $this -> config -> item ( 'table_name' ) . '.COL_TIME_ON, ' . $this -> config -> item ( 'table_name' ) . '.COL_RST_RCVD, ' . $this -> config -> item ( 'table_name' ) . '.COL_RST_SENT, ' . $this -> config -> item ( 'table_name' ) . '.COL_MODE, ' . $this -> config -> item ( 'table_name' ) . '.COL_NAME, ' . $this -> config -> item ( 'table_name' ) . '.COL_COUNTRY, ' . $this -> config -> item ( 'table_name' ) . '.COL_PRIMARY_KEY, ' . $this -> config -> item ( 'table_name' ) . '.COL_SAT_NAME, ' . $this -> config -> item ( 'table_name' ) . '.COL_GRIDSQUARE, ' . $this -> config -> item ( 'table_name' ) . '.COL_QSL_RCVD, ' . $this -> config -> item ( 'table_name' ) . '.COL_EQSL_QSL_RCVD, ' . $this -> config -> item ( 'table_name' ) . '.COL_EQSL_QSL_SENT, ' . $this -> config -> item ( 'table_name' ) . '.COL_QSL_SENT, ' . $this -> config -> item ( 'table_name' ) . '.COL_STX, ' . $this -> config -> item ( 'table_name' ) . '.COL_STX_STRING, ' . $this -> config -> item ( 'table_name' ) . '.COL_SRX, ' . $this -> config -> item ( 'table_name' ) . '.COL_SRX_STRING, ' . $this -> config -> item ( 'table_name' ) . '.COL_LOTW_QSL_SENT, ' . $this -> config -> item ( 'table_name' ) . '.COL_LOTW_QSL_RCVD, ' . $this -> config -> item ( 'table_name' ) . '.COL_VUCC_GRIDS, station_profile.*' );
$this -> db -> from ( $this -> config -> item ( 'table_name' ));
2014-09-25 22:09:44 +00:00
2019-09-24 22:10:59 +00:00
$this -> db -> join ( 'station_profile' , 'station_profile.station_id = ' . $this -> config -> item ( 'table_name' ) . '.station_id' );
2019-09-24 21:54:37 +00:00
$this -> db -> order_by ( '' . $this -> config -> item ( 'table_name' ) . '.COL_TIME_ON' , " desc " );
2014-09-25 22:09:44 +00:00
2019-09-24 21:54:37 +00:00
$this -> db -> limit ( $num );
$this -> db -> offset ( $offset );
return $this -> db -> get ();
2012-11-14 16:01:51 +00:00
}
2014-09-25 22:09:44 +00:00
2019-09-24 22:10:59 +00:00
function get_qso ( $id ) {
$this -> db -> select ( '' . $this -> config -> item ( 'table_name' ) . '.*, station_profile.*' );
$this -> db -> from ( $this -> config -> item ( 'table_name' ));
$this -> db -> join ( 'station_profile' , 'station_profile.station_id = ' . $this -> config -> item ( 'table_name' ) . '.station_id' );
$this -> db -> where ( 'COL_PRIMARY_KEY' , $id );
return $this -> db -> get ();
}
2019-09-26 12:05:28 +00:00
function get_clublog_qsos ( $station_id ){
$this -> db -> where ( 'station_id' , $station_id );
2019-06-19 15:57:33 +00:00
$this -> db -> where ( " COL_CLUBLOG_QSO_UPLOAD_STATUS " , null );
2019-06-20 14:26:36 +00:00
$this -> db -> or_where ( " COL_CLUBLOG_QSO_UPLOAD_STATUS " , " " );
2019-06-19 13:48:06 +00:00
$this -> db -> or_where ( " COL_CLUBLOG_QSO_UPLOAD_STATUS " , " N " );
$query = $this -> db -> get ( $this -> config -> item ( 'table_name' ));
return $query ;
}
2012-11-14 16:01:51 +00:00
function get_last_qsos ( $num ) {
2019-09-26 11:49:50 +00:00
$CI =& get_instance ();
$CI -> load -> model ( 'Stations' );
$station_id = $CI -> Stations -> find_active ();
2012-11-14 16:01:51 +00:00
$this -> db -> select ( 'COL_CALL, COL_BAND, COL_TIME_ON, COL_RST_RCVD, COL_RST_SENT, COL_MODE, COL_NAME, COL_COUNTRY, COL_PRIMARY_KEY, COL_SAT_NAME, COL_STX_STRING, COL_SRX_STRING' );
2019-09-26 11:49:50 +00:00
$this -> db -> where ( " station_id " , $station_id );
2014-09-25 22:09:44 +00:00
$this -> db -> order_by ( " COL_TIME_ON " , " desc " );
2012-11-14 16:01:51 +00:00
$this -> db -> limit ( $num );
$query = $this -> db -> get ( $this -> config -> item ( 'table_name' ));
2014-09-25 22:09:44 +00:00
2012-11-14 16:01:51 +00:00
return $query ;
}
2011-09-30 13:45:04 +00:00
2011-09-30 15:50:12 +00:00
/* Get All QSOs with a Valid Grid */
function kml_get_all_qsos () {
$this -> db -> select ( 'COL_CALL, COL_BAND, COL_TIME_ON, COL_RST_RCVD, COL_RST_SENT, COL_MODE, COL_NAME, COL_COUNTRY, COL_PRIMARY_KEY, COL_SAT_NAME, COL_GRIDSQUARE' );
$this -> db -> where ( 'COL_GRIDSQUARE != \'null\'' );
$query = $this -> db -> get ( $this -> config -> item ( 'table_name' ));
2014-09-25 22:09:44 +00:00
2011-09-30 15:50:12 +00:00
return $query ;
}
2011-09-30 13:45:04 +00:00
function get_date_qsos ( $date ) {
$this -> db -> select ( 'COL_CALL, COL_BAND, COL_TIME_ON, COL_RST_RCVD, COL_RST_SENT, COL_MODE, COL_NAME, COL_COUNTRY, COL_PRIMARY_KEY, COL_SAT_NAME' );
2014-09-25 22:09:44 +00:00
$this -> db -> order_by ( " COL_TIME_ON " , " desc " );
2011-09-30 13:45:04 +00:00
$start = $date . " 00:00:00 " ;
$end = $date . " 23:59:59 " ;
$this -> db -> where ( " COL_TIME_ON BETWEEN ' " . $start . " ' AND ' " . $end . " ' " );
$query = $this -> db -> get ( $this -> config -> item ( 'table_name' ));
2014-09-25 22:09:44 +00:00
2011-09-30 13:45:04 +00:00
return $query ;
}
2014-09-25 22:09:44 +00:00
2018-12-31 12:05:41 +00:00
function get_todays_qsos () {
$morning = date ( 'Y-m-d 00:00:00' );
$night = date ( 'Y-m-d 23:59:59' );
$query = $this -> db -> query ( 'SELECT * FROM ' . $this -> config -> item ( 'table_name' ) . ' WHERE COL_TIME_ON between \'' . $morning . '\' AND \'' . $night . '\'' );
return $query ;
}
function totals_year () {
2019-09-26 11:42:19 +00:00
$CI =& get_instance ();
$CI -> load -> model ( 'Stations' );
$station_id = $CI -> Stations -> find_active ();
2018-12-31 12:05:41 +00:00
$query = $this -> db -> query ( '
SELECT DATE_FORMAT ( COL_TIME_ON , \ ' % Y\ ' ) as \ ' year\ ' ,
COUNT ( COL_PRIMARY_KEY ) as \ ' total\ '
FROM '.$this->config->item(' table_name ').'
2019-09-26 11:42:19 +00:00
WHERE station_id = '.$station_id.'
2018-12-31 12:05:41 +00:00
GROUP BY DATE_FORMAT ( COL_TIME_ON , \ ' % Y\ ' )
' );
return $query ;
}
2014-09-25 22:09:44 +00:00
2011-09-30 13:45:04 +00:00
/* Return total number of qsos */
2011-06-17 12:52:00 +00:00
function total_qsos () {
2019-09-26 11:42:19 +00:00
$CI =& get_instance ();
$CI -> load -> model ( 'Stations' );
$station_id = $CI -> Stations -> find_active ();
$query = $this -> db -> query ( 'SELECT COUNT( * ) as count FROM ' . $this -> config -> item ( 'table_name' ) . ' WHERE station_id = ' . $station_id . '' );
2011-06-17 12:52:00 +00:00
if ( $query -> num_rows () > 0 )
{
foreach ( $query -> result () as $row )
{
return $row -> count ;
}
}
}
2014-09-25 22:09:44 +00:00
2011-09-30 13:45:04 +00:00
/* Return number of QSOs had today */
2011-06-17 12:52:00 +00:00
function todays_qsos () {
2019-09-26 11:42:19 +00:00
$CI =& get_instance ();
$CI -> load -> model ( 'Stations' );
$station_id = $CI -> Stations -> find_active ();
2014-09-25 22:09:44 +00:00
2011-06-17 12:52:00 +00:00
$morning = date ( 'Y-m-d 00:00:00' );
$night = date ( 'Y-m-d 23:59:59' );
2019-09-26 11:42:19 +00:00
$query = $this -> db -> query ( 'SELECT COUNT( * ) as count FROM ' . $this -> config -> item ( 'table_name' ) . ' WHERE station_id = ' . $station_id . ' AND COL_TIME_ON between \'' . $morning . '\' AND \'' . $night . '\'' );
2014-09-25 22:09:44 +00:00
2011-06-17 12:52:00 +00:00
if ( $query -> num_rows () > 0 )
{
foreach ( $query -> result () as $row )
{
return $row -> count ;
}
}
}
2014-09-25 22:09:44 +00:00
2011-09-30 13:45:04 +00:00
/* Return QSOs over a period of days */
2011-09-21 21:17:24 +00:00
function map_week_qsos ( $start , $end ) {
2019-09-26 11:49:50 +00:00
$CI =& get_instance ();
$CI -> load -> model ( 'Stations' );
$station_id = $CI -> Stations -> find_active ();
2014-09-25 22:09:44 +00:00
2011-09-21 21:17:24 +00:00
$this -> db -> where ( " COL_TIME_ON BETWEEN ' " . $start . " ' AND ' " . $end . " ' " );
2019-09-26 11:49:50 +00:00
$this -> db -> where ( " station_id " , $station_id );
2014-09-25 22:09:44 +00:00
$this -> db -> order_by ( " COL_TIME_ON " , " ASC " );
2011-09-21 21:17:24 +00:00
$query = $this -> db -> get ( $this -> config -> item ( 'table_name' ));
2011-08-23 16:12:47 +00:00
return $query ;
}
2011-09-30 13:45:04 +00:00
/* Returns QSOs for the date sent eg 2011-09-30 */
function map_day ( $date ) {
2019-09-26 11:49:50 +00:00
$CI =& get_instance ();
$CI -> load -> model ( 'Stations' );
$station_id = $CI -> Stations -> find_active ();
2014-09-25 22:09:44 +00:00
2011-09-30 13:45:04 +00:00
$start = $date . " 00:00:00 " ;
$end = $date . " 23:59:59 " ;
$this -> db -> where ( " COL_TIME_ON BETWEEN ' " . $start . " ' AND ' " . $end . " ' " );
2019-09-26 11:49:50 +00:00
$this -> db -> where ( " station_id " , $station_id );
2014-09-25 22:09:44 +00:00
$this -> db -> order_by ( " COL_TIME_ON " , " ASC " );
2011-09-30 13:45:04 +00:00
$query = $this -> db -> get ( $this -> config -> item ( 'table_name' ));
return $query ;
}
2014-09-25 22:09:44 +00:00
2011-09-30 13:45:04 +00:00
// Return QSOs made during the current month
2011-06-17 12:52:00 +00:00
function month_qsos () {
2019-09-26 11:42:19 +00:00
$CI =& get_instance ();
$CI -> load -> model ( 'Stations' );
$station_id = $CI -> Stations -> find_active ();
2011-06-17 12:52:00 +00:00
$morning = date ( 'Y-m-01 00:00:00' );
$night = date ( 'Y-m-30 23:59:59' );
2019-09-26 11:42:19 +00:00
$query = $this -> db -> query ( 'SELECT COUNT( * ) as count FROM ' . $this -> config -> item ( 'table_name' ) . ' WHERE station_id = ' . $station_id . ' AND COL_TIME_ON between \'' . $morning . '\' AND \'' . $night . '\'' );
2011-06-17 12:52:00 +00:00
if ( $query -> num_rows () > 0 )
{
foreach ( $query -> result () as $row )
{
return $row -> count ;
}
}
}
2014-09-25 22:09:44 +00:00
2011-09-30 13:45:04 +00:00
/* Return QSOs made during the current Year */
2011-06-17 12:52:00 +00:00
function year_qsos () {
2019-09-26 11:42:19 +00:00
$CI =& get_instance ();
$CI -> load -> model ( 'Stations' );
$station_id = $CI -> Stations -> find_active ();
2011-06-17 12:52:00 +00:00
$morning = date ( 'Y-01-01 00:00:00' );
$night = date ( 'Y-12-31 23:59:59' );
2019-09-26 11:42:19 +00:00
$query = $this -> db -> query ( 'SELECT COUNT( * ) as count FROM ' . $this -> config -> item ( 'table_name' ) . ' WHERE station_id = ' . $station_id . ' AND COL_TIME_ON between \'' . $morning . '\' AND \'' . $night . '\'' );
2011-06-17 12:52:00 +00:00
if ( $query -> num_rows () > 0 )
{
foreach ( $query -> result () as $row )
{
return $row -> count ;
}
}
}
2014-09-25 22:09:44 +00:00
2011-09-30 13:45:04 +00:00
/* Return total amount of SSB QSOs logged */
2011-06-17 12:52:00 +00:00
function total_ssb () {
2019-09-26 11:42:19 +00:00
$CI =& get_instance ();
$CI -> load -> model ( 'Stations' );
$station_id = $CI -> Stations -> find_active ();
$query = $this -> db -> query ( 'SELECT COUNT( * ) as count FROM ' . $this -> config -> item ( 'table_name' ) . ' WHERE station_id = ' . $station_id . ' AND COL_MODE = \'SSB\' OR COL_MODE = \'LSB\' OR COL_MODE = \'USB\'' );
2011-06-17 12:52:00 +00:00
if ( $query -> num_rows () > 0 )
{
foreach ( $query -> result () as $row )
{
return $row -> count ;
}
}
}
2011-09-30 13:45:04 +00:00
/* Return total number of satellite QSOs */
2011-07-24 22:33:08 +00:00
function total_sat () {
2019-09-26 11:42:19 +00:00
$CI =& get_instance ();
$CI -> load -> model ( 'Stations' );
$station_id = $CI -> Stations -> find_active ();
$query = $this -> db -> query ( 'SELECT COL_SAT_NAME, COUNT( * ) as count FROM ' . $this -> config -> item ( 'table_name' ) . ' WHERE station_id = ' . $station_id . ' AND COL_SAT_NAME != \'null\' GROUP BY COL_SAT_NAME' );
2011-07-24 22:33:08 +00:00
return $query ;
}
2014-09-25 22:09:44 +00:00
2011-09-30 13:45:04 +00:00
/* Return total number of CW QSOs */
2011-06-17 12:52:00 +00:00
function total_cw () {
2019-09-26 11:42:19 +00:00
$CI =& get_instance ();
$CI -> load -> model ( 'Stations' );
$station_id = $CI -> Stations -> find_active ();
$query = $this -> db -> query ( 'SELECT COUNT( * ) as count FROM ' . $this -> config -> item ( 'table_name' ) . ' WHERE station_id = ' . $station_id . ' AND COL_MODE = \'CW\' ' );
2011-06-17 12:52:00 +00:00
if ( $query -> num_rows () > 0 )
{
foreach ( $query -> result () as $row )
{
return $row -> count ;
}
}
}
2014-09-25 22:09:44 +00:00
2011-09-30 13:45:04 +00:00
/* Return total number of FM QSOs */
2011-06-17 12:52:00 +00:00
function total_fm () {
2019-09-26 11:42:19 +00:00
$CI =& get_instance ();
$CI -> load -> model ( 'Stations' );
$station_id = $CI -> Stations -> find_active ();
$query = $this -> db -> query ( 'SELECT COUNT( * ) as count FROM ' . $this -> config -> item ( 'table_name' ) . ' WHERE station_id = ' . $station_id . ' AND COL_MODE = \'FM\'' );
2011-06-17 12:52:00 +00:00
if ( $query -> num_rows () > 0 )
{
foreach ( $query -> result () as $row )
{
return $row -> count ;
}
}
}
2011-09-30 13:45:04 +00:00
/* Return total number of Digital QSOs */
2011-06-17 12:52:00 +00:00
function total_digi () {
2019-09-26 11:42:19 +00:00
$CI =& get_instance ();
$CI -> load -> model ( 'Stations' );
$station_id = $CI -> Stations -> find_active ();
$query = $this -> db -> query ( 'SELECT COUNT( * ) as count FROM ' . $this -> config -> item ( 'table_name' ) . ' WHERE station_id = ' . $station_id . ' AND COL_MODE != \'SSB\' AND COL_MODE != \'LSB\' AND COL_MODE != \'USB\' AND COL_MODE != \'CW\' AND COL_MODE != \'FM\' AND COL_MODE != \'AM\'' );
2011-06-17 12:52:00 +00:00
if ( $query -> num_rows () > 0 )
{
foreach ( $query -> result () as $row )
{
return $row -> count ;
}
}
}
2014-09-25 22:09:44 +00:00
2017-04-21 17:44:10 +00:00
/* Return the list of modes in the logbook */
function get_modes (){
$query = $this -> db -> query ( 'select distinct(COL_MODE) from ' . $this -> config -> item ( 'table_name' ) . ' order by COL_MODE' );
return $query ;
}
2011-09-30 13:45:04 +00:00
/* Return total number of QSOs per band */
2011-06-17 12:52:00 +00:00
function total_bands () {
2019-09-26 11:42:19 +00:00
$CI =& get_instance ();
$CI -> load -> model ( 'Stations' );
$station_id = $CI -> Stations -> find_active ();
$query = $this -> db -> query ( 'SELECT DISTINCT (COL_BAND) AS band, count( * ) AS count FROM ' . $this -> config -> item ( 'table_name' ) . ' WHERE station_id = ' . $station_id . ' GROUP BY band ORDER BY count DESC' );
2011-06-17 12:52:00 +00:00
return $query ;
}
2014-09-25 22:09:44 +00:00
2011-09-30 13:45:04 +00:00
/* Return total number of QSL Cards sent */
2011-09-21 21:17:24 +00:00
function total_qsl_sent () {
2019-09-26 11:49:50 +00:00
$CI =& get_instance ();
$CI -> load -> model ( 'Stations' );
$station_id = $CI -> Stations -> find_active ();
$query = $this -> db -> query ( 'SELECT DISTINCT (COL_QSL_SENT) AS band, count(COL_QSL_SENT) AS count FROM ' . $this -> config -> item ( 'table_name' ) . ' WHERE station_id = ' . $station_id . ' AND COL_QSL_SENT = "Y" GROUP BY band' );
2011-09-21 21:17:24 +00:00
$row = $query -> row ();
2014-09-25 22:09:44 +00:00
2011-09-22 19:58:58 +00:00
if ( $row == null ) {
return 0 ;
} else {
return $row -> count ;
}
}
2014-09-25 22:09:44 +00:00
2011-09-30 13:45:04 +00:00
/* Return total number of QSL Cards requested */
2011-09-22 19:58:58 +00:00
function total_qsl_requested () {
2019-09-26 11:49:50 +00:00
$CI =& get_instance ();
$CI -> load -> model ( 'Stations' );
$station_id = $CI -> Stations -> find_active ();
$query = $this -> db -> query ( 'SELECT DISTINCT (COL_QSL_SENT) AS band, count(COL_QSL_SENT) AS count FROM ' . $this -> config -> item ( 'table_name' ) . ' WHERE station_id = ' . $station_id . ' AND COL_QSL_SENT = "R" GROUP BY band' );
2011-09-22 19:58:58 +00:00
$row = $query -> row ();
2011-09-21 21:17:24 +00:00
if ( $row == null ) {
return 0 ;
} else {
return $row -> count ;
}
}
2014-09-25 22:09:44 +00:00
2011-09-30 13:45:04 +00:00
/* Return total number of QSL Cards received */
2011-09-21 21:17:24 +00:00
function total_qsl_recv () {
2019-09-26 11:49:50 +00:00
$CI =& get_instance ();
$CI -> load -> model ( 'Stations' );
$station_id = $CI -> Stations -> find_active ();
$query = $this -> db -> query ( 'SELECT DISTINCT (COL_QSL_RCVD) AS band, count(COL_QSL_RCVD) AS count FROM ' . $this -> config -> item ( 'table_name' ) . ' WHERE station_id = ' . $station_id . ' AND COL_QSL_RCVD = "Y" GROUP BY band' );
2011-09-21 21:17:24 +00:00
$row = $query -> row ();
if ( $row == null ) {
return 0 ;
} else {
return $row -> count ;
}
}
2014-09-25 22:09:44 +00:00
2011-09-30 13:45:04 +00:00
/* Return total number of countrys worked */
2011-09-21 21:17:24 +00:00
function total_countrys () {
2019-09-26 11:49:50 +00:00
$CI =& get_instance ();
$CI -> load -> model ( 'Stations' );
$station_id = $CI -> Stations -> find_active ();
$query = $this -> db -> query ( 'SELECT DISTINCT (COL_COUNTRY) FROM ' . $this -> config -> item ( 'table_name' ) . ' WHERE station_id = ' . $station_id . '' );
2011-09-21 21:17:24 +00:00
return $query -> num_rows ();
}
2011-06-17 12:52:00 +00:00
2012-11-14 16:01:51 +00:00
function api_search_query ( $query ) {
$time_start = microtime ( true );
$results = $this -> db -> query ( $query );
2012-01-03 23:30:53 +00:00
if ( ! $results ) {
return array ( 'query' => $query , 'error' => $this -> db -> _error_number (), 'time' => 0 );
}
2012-11-14 16:01:51 +00:00
$time_end = microtime ( true );
$time = round ( $time_end - $time_start , 4 );
2011-08-17 17:15:09 +00:00
2012-11-14 16:01:51 +00:00
return array ( 'query' => $query , 'results' => $results , 'time' => $time );
}
2011-09-30 15:51:35 +00:00
2012-11-14 16:01:51 +00:00
function api_insert_query ( $query ) {
$time_start = microtime ( true );
$results = $this -> db -> insert ( $this -> config -> item ( 'table_name' ), $query );
2012-01-03 23:30:53 +00:00
if ( ! $results ) {
return array ( 'query' => $query , 'error' => $this -> db -> _error_number (), 'time' => 0 );
}
2012-11-14 16:01:51 +00:00
$time_end = microtime ( true );
$time = round ( $time_end - $time_start , 4 );
2011-09-30 15:51:35 +00:00
2012-11-14 16:01:51 +00:00
return array ( 'query' => $this -> db -> queries [ 2 ], 'result_string' => $results , 'time' => $time );
}
2011-09-30 15:51:35 +00:00
2011-09-30 13:45:04 +00:00
/* Delete QSO based on the QSO ID */
2011-08-28 13:51:57 +00:00
function delete ( $id ) {
$this -> db -> where ( 'COL_PRIMARY_KEY' , $id );
2014-09-25 22:09:44 +00:00
$this -> db -> delete ( $this -> config -> item ( 'table_name' ));
2011-08-28 13:51:57 +00:00
}
2014-09-25 22:09:44 +00:00
2018-12-31 12:05:41 +00:00
/* Used to check if the qso is already in the database */
2013-02-16 16:41:40 +00:00
function import_check ( $datetime , $callsign , $band ) {
2014-09-25 22:09:44 +00:00
2018-12-31 12:05:41 +00:00
$this -> db -> select ( 'COL_TIME_ON, COL_CALL, COL_BAND' );
$this -> db -> where ( 'COL_TIME_ON >= DATE_ADD(DATE_FORMAT("' . $datetime . '", \'%Y-%m-%d %H:%i\' ), INTERVAL -15 MINUTE )' );
$this -> db -> where ( 'COL_TIME_ON <= DATE_ADD(DATE_FORMAT("' . $datetime . '", \'%Y-%m-%d %H:%i\' ), INTERVAL 15 MINUTE )' );
$this -> db -> where ( 'COL_CALL' , $callsign );
$this -> db -> where ( 'COL_BAND' , $band );
2014-09-25 22:09:44 +00:00
2018-12-31 12:05:41 +00:00
$query = $this -> db -> get ( $this -> config -> item ( 'table_name' ));
2014-09-25 22:09:44 +00:00
2018-12-31 12:05:41 +00:00
if ( $query -> num_rows () > 0 )
{
return " Found " ;
} else {
return " No Match " ;
}
}
2014-09-25 22:09:44 +00:00
2018-12-31 12:05:41 +00:00
function lotw_update ( $datetime , $callsign , $band , $qsl_date , $qsl_status ) {
$data = array (
'COL_LOTW_QSLRDATE' => $qsl_date ,
'COL_LOTW_QSL_RCVD' => $qsl_status ,
'COL_LOTW_QSL_SENT' => 'Y'
);
2013-02-16 16:41:40 +00:00
2018-12-31 12:05:41 +00:00
$this -> db -> where ( 'date_format(COL_TIME_ON, \'%Y-%m-%d %H:%i\') = "' . $datetime . '"' );
$this -> db -> where ( 'COL_CALL' , $callsign );
$this -> db -> where ( 'COL_BAND' , $band );
2014-09-25 22:09:44 +00:00
2018-12-31 12:05:41 +00:00
$this -> db -> update ( $this -> config -> item ( 'table_name' ), $data );
2014-09-25 22:09:44 +00:00
2018-12-31 12:05:41 +00:00
return " Updated " ;
}
2014-09-25 22:09:44 +00:00
2018-12-31 12:05:41 +00:00
function lotw_last_qsl_date () {
$this -> db -> select ( 'COL_LOTW_QSLRDATE' );
$this -> db -> where ( 'COL_LOTW_QSLRDATE IS NOT NULL' );
$this -> db -> order_by ( " COL_LOTW_QSLRDATE " , " desc " );
$this -> db -> limit ( 1 );
2014-09-25 22:09:44 +00:00
2018-12-31 12:05:41 +00:00
$query = $this -> db -> get ( $this -> config -> item ( 'table_name' ));
$row = $query -> row ();
2014-09-25 22:09:44 +00:00
2018-12-31 12:05:41 +00:00
return $row -> COL_LOTW_QSLRDATE ;
}
2011-11-19 22:28:05 +00:00
2014-09-25 22:09:44 +00:00
//////////////////////////////
2018-12-31 12:05:41 +00:00
// Update a QSO with eQSL QSL info
// We could also probably use this use this: http://eqsl.cc/qslcard/VerifyQSO.txt
// http://www.eqsl.cc/qslcard/ImportADIF.txt
function eqsl_update ( $datetime , $callsign , $band , $qsl_status ) {
$data = array (
'COL_EQSL_QSLRDATE' => date ( 'Y-m-d' ), // eQSL doesn't give us a date, so let's use current
'COL_EQSL_QSL_RCVD' => $qsl_status
);
$this -> db -> where ( 'COL_TIME_ON >= DATE_ADD(DATE_FORMAT("' . $datetime . '", \'%Y-%m-%d %H:%i\' ), INTERVAL -15 MINUTE )' );
$this -> db -> where ( 'COL_TIME_ON <= DATE_ADD(DATE_FORMAT("' . $datetime . '", \'%Y-%m-%d %H:%i\' ), INTERVAL 15 MINUTE )' );
$this -> db -> where ( 'COL_CALL' , $callsign );
$this -> db -> where ( 'COL_BAND' , $band );
$this -> db -> update ( $this -> config -> item ( 'table_name' ), $data );
return " Updated " ;
}
// Mark the QSO as sent to eQSL
function eqsl_mark_sent ( $primarykey ) {
$data = array (
'COL_EQSL_QSLSDATE' => date ( 'Y-m-d' ), // eQSL doesn't give us a date, so let's use current
'COL_EQSL_QSL_SENT' => 'Y' ,
);
$this -> db -> where ( 'COL_PRIMARY_KEY' , $primarykey );
$this -> db -> update ( $this -> config -> item ( 'table_name' ), $data );
return " eQSL Sent " ;
}
// Get the last date we received an eQSL
function eqsl_last_qsl_rcvd_date () {
$this -> db -> select ( " DATE_FORMAT(COL_EQSL_QSLRDATE,'%Y%m%d') AS COL_EQSL_QSLRDATE " , FALSE );
$this -> db -> where ( 'COL_EQSL_QSLRDATE IS NOT NULL' );
$this -> db -> order_by ( " COL_EQSL_QSLRDATE " , " desc " );
$this -> db -> limit ( 1 );
$query = $this -> db -> get ( $this -> config -> item ( 'table_name' ));
$row = $query -> row ();
if ( isset ( $row -> COL_EQSL_QSLDATE )){
return $row -> COL_EQSL_QSLRDATE ;
} else {
// No previous date (first time import has run?), so choose UNIX EPOCH!
// Note: date is yyyy/mm/dd format
2016-01-26 15:43:35 +00:00
return '1970/01/01' ;
2018-12-31 12:05:41 +00:00
}
}
// Determine if we've already received an eQSL for this QSO
function eqsl_dupe_check ( $datetime , $callsign , $band , $qsl_status ) {
$this -> db -> select ( 'COL_EQSL_QSLRDATE' );
$this -> db -> where ( 'COL_TIME_ON >= DATE_ADD(DATE_FORMAT("' . $datetime . '", \'%Y-%m-%d %H:%i\' ), INTERVAL -15 MINUTE )' );
$this -> db -> where ( 'COL_TIME_ON <= DATE_ADD(DATE_FORMAT("' . $datetime . '", \'%Y-%m-%d %H:%i\' ), INTERVAL 15 MINUTE )' );
$this -> db -> where ( 'COL_CALL' , $callsign );
$this -> db -> where ( 'COL_BAND' , $band );
$this -> db -> where ( 'COL_EQSL_QSL_RCVD' , $qsl_status );
$this -> db -> limit ( 1 );
$query = $this -> db -> get ( $this -> config -> item ( 'table_name' ));
$row = $query -> row ();
if ( $row != null )
{
return true ;
}
else
{
return false ;
}
}
// Show all QSOs we need to send to eQSL
function eqsl_not_yet_sent () {
2019-10-04 10:32:29 +00:00
$this -> db -> select ( 'station_profile.*, ' . $this -> config -> item ( 'table_name' ) . '.COL_PRIMARY_KEY, ' . $this -> config -> item ( 'table_name' ) . '.COL_TIME_ON, ' . $this -> config -> item ( 'table_name' ) . '.COL_CALL, ' . $this -> config -> item ( 'table_name' ) . '.COL_MODE, ' . $this -> config -> item ( 'table_name' ) . '.COL_BAND, ' . $this -> config -> item ( 'table_name' ) . '.COL_COMMENT, ' . $this -> config -> item ( 'table_name' ) . '.COL_RST_SENT, ' . $this -> config -> item ( 'table_name' ) . '.COL_PROP_MODE' );
$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' );
$this -> db -> where ( 'station_profile.eqslqthnickname !=' , '' );
2019-10-06 14:40:33 +00:00
$this -> db -> or_where ( $this -> config -> item ( 'table_name' ) . '.COL_EQSL_QSL_SENT !=' , 'Y' );
$this -> db -> or_where ( $this -> config -> item ( 'table_name' ) . '.COL_EQSL_QSL_SENT !=' , 'I' );
$this -> db -> or_where ( array ( $this -> config -> item ( 'table_name' ) . '.COL_EQSL_QSL_SENT' => NULL ));
2019-10-04 10:32:29 +00:00
return $this -> db -> get ();
2018-12-31 12:05:41 +00:00
}
2014-09-25 22:09:44 +00:00
2019-08-19 21:25:50 +00:00
function import ( $record , $station_id = " 0 " ) {
2013-08-17 15:24:16 +00:00
$CI =& get_instance ();
$CI -> load -> library ( 'frequency' );
2019-06-30 22:29:58 +00:00
2019-08-19 21:25:50 +00:00
2011-11-19 22:28:05 +00:00
// Join date+time
2018-12-31 12:05:41 +00:00
2011-11-19 22:28:05 +00:00
$time_on = date ( 'Y-m-d' , strtotime ( $record [ 'qso_date' ])) . " " . date ( 'H:i' , strtotime ( $record [ 'time_on' ]));
2011-11-20 15:12:40 +00:00
if ( isset ( $record [ 'time_off' ])) {
$time_off = date ( 'Y-m-d' , strtotime ( $record [ 'qso_date' ])) . " " . date ( 'H:i' , strtotime ( $record [ 'time_off' ]));
} else {
2014-09-25 22:09:44 +00:00
$time_off = date ( 'Y-m-d' , strtotime ( $record [ 'qso_date' ])) . " " . date ( 'H:i' , strtotime ( $record [ 'time_on' ]));
2011-11-20 15:12:40 +00:00
}
2014-09-25 22:09:44 +00:00
2012-10-31 17:07:27 +00:00
// Store Freq
2016-01-18 12:31:41 +00:00
// Check if 'freq' is defined in the import?
if ( isset ( $record [ 'freq' ])){
$cleanfreq = preg_replace ( '#\W#' , '' , $record [ 'freq' ]);
$freqlng = strlen ( $cleanfreq );
} else {
$freqlng = 0 ;
}
2019-05-16 07:31:30 +00:00
2014-09-25 22:09:44 +00:00
if ( isset ( $record [ 'freq' ]) && $freqlng < 7 ) {
2011-11-20 15:12:40 +00:00
$cleansedstring = preg_replace ( '#\W#' , '' , $record [ 'freq' ]);
2019-08-19 20:50:07 +00:00
$freq = $cleansedstring . " 0 " ;
2014-09-25 22:09:44 +00:00
} elseif ( $freqlng >= 7 ) {
$cleansedstring = preg_replace ( '#\W#' , '' , $record [ 'freq' ]);
$freq = $cleansedstring ;
2011-11-19 22:28:05 +00:00
} else {
$freq = " 0 " ;
}
2014-09-25 22:09:44 +00:00
2019-06-29 22:08:24 +00:00
// Check for RX Freq
// Check if 'freq' is defined in the import?
if ( isset ( $record [ 'freq_rx' ])){
$cleanfreqRX = preg_replace ( '#\W#' , '' , $record [ 'freq_rx' ]);
$freqlngRX = strlen ( $cleanfreqRX );
} else {
$freqlngRX = 0 ;
}
if ( isset ( $record [ 'freq_rx' ]) && $freqlngRX < 7 ) {
$cleansedstringRX = preg_replace ( '#\W#' , '' , $record [ 'freq_rx' ]);
2019-08-19 20:50:07 +00:00
$freqRX = $cleansedstringRX . " 0 " ;
2019-06-29 22:08:24 +00:00
} elseif ( $freqlngRX >= 7 ) {
$cleansedstringRX = preg_replace ( '#\W#' , '' , $record [ 'freq_rx' ]);
$freqRX = $cleansedstringRX ;
} else {
$freqRX = NULL ;
}
2016-02-28 17:43:45 +00:00
// DXCC id
2019-06-15 11:45:29 +00:00
if ( isset ( $record [ 'call' ])){
$dxcc = $this -> check_dxcc_table ( $record [ 'call' ], $time_off );
} else {
$dxcc = NULL ;
}
2016-02-28 17:43:45 +00:00
2012-10-31 17:07:27 +00:00
// Store or find country name
2011-11-19 22:28:05 +00:00
if ( isset ( $record [ 'country' ])) {
$country = $record [ 'country' ];
} else {
2016-02-28 17:43:45 +00:00
$country = ucwords ( strtolower ( $dxcc [ 1 ]));
2011-11-19 22:28:05 +00:00
}
2016-02-28 17:43:45 +00:00
2012-10-31 17:07:27 +00:00
// RST recevied
2011-12-22 00:30:44 +00:00
if ( isset ( $record [ 'rst_rcvd' ])) {
$rst_rx = $record [ 'rst_rcvd' ];
} else {
2019-06-29 16:24:13 +00:00
$rst_rx = " 59 " ;
2011-12-22 00:30:44 +00:00
}
2014-09-25 22:09:44 +00:00
2012-10-31 17:07:27 +00:00
// RST Sent
if ( isset ( $record [ 'rst_sent' ])) {
2011-12-22 00:30:44 +00:00
$rst_tx = $record [ 'rst_sent' ];
} else {
2019-06-29 16:24:13 +00:00
$rst_tx = " 59 " ;
2011-12-22 00:30:44 +00:00
}
2012-10-31 17:55:21 +00:00
// Store Band
2012-10-31 17:07:27 +00:00
if ( isset ( $record [ 'band' ])) {
$band = $record [ 'band' ];
} else {
2019-06-29 16:24:13 +00:00
if ( isset ( $record [ 'freq' ])){
2019-06-29 22:08:24 +00:00
if ( $freq != " 0 " ) {
$band = $CI -> frequency -> GetBand ( $freq );
}
2019-06-29 16:24:13 +00:00
}
2012-10-31 17:07:27 +00:00
}
2014-09-25 22:09:44 +00:00
2018-12-31 12:05:41 +00:00
if ( isset ( $record [ 'band_rx' ])) {
$band_rx = $record [ 'band_rx' ];
2015-07-26 17:57:43 +00:00
} else {
2019-06-29 22:08:24 +00:00
if ( isset ( $record [ 'freq_rx' ])){
if ( $freq != " 0 " ) {
$band_rx = $CI -> frequency -> GetBand ( $freqRX );
}
2019-05-16 21:07:05 +00:00
} else {
$band_rx = " " ;
2019-05-16 07:31:30 +00:00
}
2016-02-14 12:48:55 +00:00
}
2019-05-16 21:49:43 +00:00
if ( isset ( $record [ 'CQZ' ])) {
$cq_zone = $record [ 'CQZ' ];
} elseif ( isset ( $dxcc [ 2 ])) {
$cq_zone = $dxcc [ 2 ];
} else {
2019-06-15 11:45:29 +00:00
//$cq_zone = "";
$cq_zone = NULL ;
2019-05-16 21:49:43 +00:00
}
2014-09-25 22:09:44 +00:00
2019-06-15 11:45:29 +00:00
if ( isset ( $record [ 'call' ])){
$this -> db -> where ( 'COL_CALL' , $record [ 'call' ]);
}
2011-11-19 22:28:05 +00:00
$this -> db -> where ( 'COL_TIME_ON' , $time_on );
$check = $this -> db -> get ( $this -> config -> item ( 'table_name' ));
2018-12-31 12:05:41 +00:00
2011-11-19 22:28:05 +00:00
if ( $check -> num_rows () <= 0 )
{
2018-12-31 12:05:41 +00:00
// Create array with QSO Data use ?:
2011-11-19 22:28:05 +00:00
$data = array (
2019-05-11 23:21:10 +00:00
'COL_A_INDEX' => ( ! empty ( $record [ 'a_index' ])) ? $record [ 'a_index' ] : null ,
2018-12-31 12:05:41 +00:00
'COL_ADDRESS' => ( ! empty ( $record [ 'address' ])) ? $record [ 'address' ] : '' ,
'COL_ADDRESS_INTL' => ( ! empty ( $record [ 'address_intl' ])) ? $record [ 'address_intl' ] : '' ,
2019-05-11 23:21:10 +00:00
'COL_AGE' => ( ! empty ( $record [ 'age' ])) ? $record [ 'age' ] : null ,
'COL_ANT_AZ' => ( ! empty ( $record [ 'ant_az' ])) ? $record [ 'ant_az' ] : null ,
'COL_ANT_EL' => ( ! empty ( $record [ 'ant_el' ])) ? $record [ 'ant_el' ] : null ,
2018-12-31 12:05:41 +00:00
'COL_ANT_PATH' => ( ! empty ( $record [ 'ant_path' ])) ? $record [ 'ant_path' ] : '' ,
'COL_ARRL_SECT' => ( ! empty ( $record [ 'arrl_sect' ])) ? $record [ 'arrl_sect' ] : '' ,
'COL_AWARD_GRANTED' => ( ! empty ( $record [ 'award_granted' ])) ? $record [ 'award_granted' ] : '' ,
'COL_AWARD_SUMMITED' => ( ! empty ( $record [ 'award_submitted' ])) ? $record [ 'award_submitted' ] : '' ,
'COL_BAND' => $band ,
'COL_BAND_RX' => $band_rx ,
'COL_BIOGRAPHY' => ( ! empty ( $record [ 'biography' ])) ? $record [ 'biography' ] : '' ,
'COL_CALL' => ( ! empty ( $record [ 'call' ])) ? strtoupper ( $record [ 'call' ]) : '' ,
'COL_CHECK' => ( ! empty ( $record [ 'check' ])) ? $record [ 'check' ] : '' ,
'COL_CLASS' => ( ! empty ( $record [ 'class' ])) ? $record [ 'class' ] : '' ,
2019-05-11 23:21:10 +00:00
'COL_CLUBLOG_QSO_UPLOAD_DATE' => ( ! empty ( $record [ 'clublog_qso_upload_date' ])) ? $record [ 'clublog_qso_upload_date' ] : null ,
'COL_CLUBLOG_QSO_UPLOAD_STATUS' => ( ! empty ( $record [ 'clublog_qso_upload_status' ])) ? $record [ 'clublog_qso_upload_status' ] : null ,
2018-12-31 12:05:41 +00:00
'COL_CNTY' => ( ! empty ( $record [ 'cnty' ])) ? $record [ 'cnty' ] : '' ,
'COL_COMMENT' => ( ! empty ( $record [ 'comment' ])) ? $record [ 'comment' ] : '' ,
'COL_COMMENT_INTL' => ( ! empty ( $record [ 'comment_intl' ])) ? $record [ 'comment_intl' ] : '' ,
'COL_CONT' => ( ! empty ( $record [ 'cont' ])) ? $record [ 'cont' ] : '' ,
'COL_CONTACTED_OP' => ( ! empty ( $record [ 'contacted_op' ])) ? $record [ 'contacted_op' ] : '' ,
'COL_CONTEST_ID' => ( ! empty ( $record [ 'contest_id' ])) ? $record [ 'contest_id' ] : '' ,
2019-05-16 22:01:57 +00:00
'COL_COUNTRY' => $country ,
2018-12-31 12:05:41 +00:00
'COL_COUNTRY_INTL' => ( ! empty ( $record [ 'country_intl' ])) ? $record [ 'country_intl' ] : '' ,
2019-05-16 21:49:43 +00:00
'COL_CQZ' => $cq_zone ,
2018-12-31 12:05:41 +00:00
'COL_CREDIT_GRANTED' => ( ! empty ( $record [ 'credit_granted' ])) ? $record [ 'credit_granted' ] : '' ,
'COL_CREDIT_SUBMITTED' => ( ! empty ( $record [ 'credit_submitted' ])) ? $record [ 'credit_submitted' ] : '' ,
'COL_DARC_DOK' => ( ! empty ( $record [ 'darc_dok' ])) ? $record [ 'darc_dok' ] : '' ,
2019-05-11 23:21:10 +00:00
'COL_DISTANCE' => ( ! empty ( $record [ 'distance' ])) ? $record [ 'distance' ] : null ,
2018-12-31 12:05:41 +00:00
'COL_DXCC' => $dxcc [ 0 ],
'COL_EMAIL' => ( ! empty ( $record [ 'email' ])) ? $record [ 'email' ] : '' ,
'COL_EQ_CALL' => ( ! empty ( $record [ 'eq_call' ])) ? $record [ 'eq_call' ] : '' ,
2019-05-11 23:21:10 +00:00
'COL_EQSL_QSL_RCVD' => ( ! empty ( $record [ 'eqsl_qsl_rcvd' ])) ? $record [ 'eqsl_qsl_rcvd' ] : null ,
'COL_EQSL_QSL_SENT' => ( ! empty ( $record [ 'eqsl_qsl_sent' ])) ? $record [ 'eqsl_qsl_sent' ] : null ,
'COL_EQSL_QSLRDATE' => ( ! empty ( $record [ 'eqsl_qslrdate' ])) ? $record [ 'eqsl_qslrdate' ] : null ,
'COL_EQSL_QSLSDATE' => ( ! empty ( $record [ 'eqsl_qslsdate' ])) ? $record [ 'eqsl_qslsdate' ] : null ,
2018-12-31 12:05:41 +00:00
'COL_EQSL_STATUS' => ( ! empty ( $record [ 'eqsl_status' ])) ? $record [ 'eqsl_status' ] : '' ,
2019-05-17 01:00:06 +00:00
'COL_FISTS' => ( ! empty ( $record [ 'fists' ])) ? $record [ 'fists' ] : null ,
'COL_FISTS_CC' => ( ! empty ( $record [ 'fists_cc' ])) ? $record [ 'fists_cc' ] : null ,
'COL_FORCE_INIT' => ( ! empty ( $record [ 'force_init' ])) ? $record [ 'force_init' ] : null ,
2018-12-31 12:05:41 +00:00
'COL_FREQ' => $freq ,
2019-06-29 22:08:24 +00:00
'COL_FREQ_RX' => ( ! empty ( $record [ 'freq_rx' ])) ? $freqRX : null ,
2018-12-31 12:05:41 +00:00
'COL_GRIDSQUARE' => ( ! empty ( $record [ 'gridsquare' ])) ? $record [ 'gridsquare' ] : '' ,
2019-05-17 01:00:06 +00:00
'COL_HEADING' => ( ! empty ( $record [ 'heading' ])) ? $record [ 'heading' ] : null ,
'COL_HRDLOG_QSO_UPLOAD_DATE' => ( ! empty ( $record [ 'hrdlog_qso_upload_date' ])) ? $record [ 'hrdlog_qso_upload_date' ] : null ,
2018-12-31 12:05:41 +00:00
'COL_HRDLOG_QSO_UPLOAD_STATUS' => ( ! empty ( $record [ 'hrdlog_qso_upload_status' ])) ? $record [ 'hrdlog_qso_upload_status' ] : '' ,
'COL_IOTA' => ( ! empty ( $record [ 'iota' ])) ? $record [ 'iota' ] : '' ,
2019-05-17 01:00:06 +00:00
'COL_ITUZ' => ( ! empty ( $record [ 'ituz' ])) ? $record [ 'ituz' ] : null ,
'COL_K_INDEX' => ( ! empty ( $record [ 'k_index' ])) ? $record [ 'k_index' ] : null ,
'COL_LAT' => ( ! empty ( $record [ 'lat' ])) ? $record [ 'lat' ] : null ,
'COL_LON' => ( ! empty ( $record [ 'lon' ])) ? $record [ 'lon' ] : null ,
2018-12-31 12:05:41 +00:00
'COL_LOTW_QSL_RCVD' => ( ! empty ( $record [ 'lotw_qsl_rcvd' ])) ? $record [ 'lotw_qsl_rcvd' ] : '' ,
'COL_LOTW_QSL_SENT' => ( ! empty ( $record [ 'lotw_qsl_sent' ])) ? $record [ 'lotw_qsl_sent' ] : '' ,
2019-05-17 01:00:06 +00:00
'COL_LOTW_QSLRDATE' => ( ! empty ( $record [ 'lotw_qslrdate' ])) ? $record [ 'lotw_qslrdate' ] : null ,
'COL_LOTW_QSLSDATE' => ( ! empty ( $record [ 'lotw_qslsdate' ])) ? $record [ 'lotw_qslsdate' ] : null ,
2018-12-31 12:05:41 +00:00
'COL_LOTW_STATUS' => ( ! empty ( $record [ 'lotw_status' ])) ? $record [ 'lotw_status' ] : '' ,
2019-05-17 01:00:06 +00:00
'COL_MAX_BURSTS' => ( ! empty ( $record [ 'max_bursts' ])) ? $record [ 'max_bursts' ] : null ,
2018-12-31 12:05:41 +00:00
'COL_MODE' => ( ! empty ( $record [ 'mode' ])) ? $record [ 'mode' ] : '' ,
'COL_MS_SHOWER' => ( ! empty ( $record [ 'ms_shower' ])) ? $record [ 'ms_shower' ] : '' ,
'COL_MY_ANTENNA' => ( ! empty ( $record [ 'my_antenna' ])) ? $record [ 'my_antenna' ] : '' ,
'COL_MY_ANTENNA_INTL' => ( ! empty ( $record [ 'my_antenna_intl' ])) ? $record [ 'my_antenna_intl' ] : '' ,
'COL_MY_CITY' => ( ! empty ( $record [ 'my_city' ])) ? $record [ 'my_city' ] : '' ,
'COL_MY_CITY_INTL' => ( ! empty ( $record [ 'my_city_intl' ])) ? $record [ 'my_city_intl' ] : '' ,
'COL_MY_CNTY' => ( ! empty ( $record [ 'my_cnty' ])) ? $record [ 'my_cnty' ] : '' ,
'COL_MY_COUNTRY' => ( ! empty ( $record [ 'my_country' ])) ? $record [ 'my_country' ] : '' ,
2019-05-17 01:00:06 +00:00
'COL_MY_COUNTRY_INTL' => ( ! empty ( $record [ 'my_country_intl' ])) ? $record [ 'my_country_intl' ] : null ,
'COL_MY_CQ_ZONE' => ( ! empty ( $record [ 'my_dxcc' ])) ? $record [ 'my_dxcc' ] : null ,
'COL_MY_DXCC' => ( ! empty ( $record [ 'my_dxcc' ])) ? $record [ 'my_dxcc' ] : null ,
'COL_MY_FISTS' => ( ! empty ( $record [ 'my_fists' ])) ? $record [ 'my_fists' ] : null ,
2018-12-31 12:05:41 +00:00
'COL_MY_GRIDSQUARE' => ( ! empty ( $record [ 'my_gridsquare' ])) ? $record [ 'my_gridsquare' ] : '' ,
'COL_MY_IOTA' => ( ! empty ( $record [ 'my_iota' ])) ? $record [ 'my_iota' ] : '' ,
'COL_MY_IOTA_ISLAND_ID' => ( ! empty ( $record [ 'my_iota_island_id' ])) ? $record [ 'my_iota_island_id' ] : '' ,
2019-05-17 01:00:06 +00:00
'COL_MY_ITU_ZONE' => ( ! empty ( $record [ 'my_itu_zone' ])) ? $record [ 'my_itu_zone' ] : null ,
'COL_MY_LAT' => ( ! empty ( $record [ 'my_lat' ])) ? $record [ 'my_lat' ] : null ,
'COL_MY_LON' => ( ! empty ( $record [ 'my_lon' ])) ? $record [ 'my_lon' ] : null ,
2018-12-31 12:05:41 +00:00
'COL_MY_NAME' => ( ! empty ( $record [ 'my_name' ])) ? $record [ 'my_name' ] : '' ,
'COL_MY_NAME_INTL' => ( ! empty ( $record [ 'my_name_intl' ])) ? $record [ 'my_name_intl' ] : '' ,
'COL_MY_POSTAL_CODE' => ( ! empty ( $record [ 'my_postal_code' ])) ? $record [ 'my_postal_code' ] : '' ,
'COL_MY_POSTCODE_INTL' => ( ! empty ( $record [ 'my_postcode_intl' ])) ? $record [ 'my_postcode_intl' ] : '' ,
'COL_MY_RIG' => ( ! empty ( $record [ 'my_rig' ])) ? $record [ 'my_rig' ] : '' ,
'COL_MY_RIG_INTL' => ( ! empty ( $record [ 'my_rig_intl' ])) ? $record [ 'my_rig_intl' ] : '' ,
'COL_MY_SIG' => ( ! empty ( $record [ 'my_sig' ])) ? $record [ 'my_sig' ] : '' ,
'COL_MY_SIG_INFO' => ( ! empty ( $record [ 'my_sig_info' ])) ? $record [ 'my_sig_info' ] : '' ,
'COL_MY_SIG_INFO_INTL' => ( ! empty ( $record [ 'my_sig_info_intl' ])) ? $record [ 'my_sig_info_intl' ] : '' ,
'COL_MY_SIG_INTL' => ( ! empty ( $record [ 'my_sig_intl' ])) ? $record [ 'my_sig_intl' ] : '' ,
'COL_MY_SOTA_REF' => ( ! empty ( $record [ 'my_sota_ref' ])) ? $record [ 'my_sota_ref' ] : '' ,
'COL_MY_STATE' => ( ! empty ( $record [ 'my_state' ])) ? $record [ 'my_state' ] : '' ,
'COL_MY_STREET' => ( ! empty ( $record [ 'my_street' ])) ? $record [ 'my_street' ] : '' ,
'COL_MY_STREET_INTL' => ( ! empty ( $record [ 'my_street_intl' ])) ? $record [ 'my_street_intl' ] : '' ,
'COL_MY_USACA_COUNTIES' => ( ! empty ( $record [ 'my_usaca_counties' ])) ? $record [ 'my_usaca_counties' ] : '' ,
'COL_MY_VUCC_GRIDS' => ( ! empty ( $record [ 'my_vucc_grids' ])) ? $record [ 'my_vucc_grids' ] : '' ,
'COL_NAME' => ( ! empty ( $record [ 'name' ])) ? $record [ 'name' ] : '' ,
'COL_NAME_INTL' => ( ! empty ( $record [ 'name_intl' ])) ? $record [ 'name_intl' ] : '' ,
'COL_NOTES' => ( ! empty ( $record [ 'notes' ])) ? $record [ 'notes' ] : '' ,
'COL_NOTES_INTL' => ( ! empty ( $record [ 'notes_intl' ])) ? $record [ 'notes_intl' ] : '' ,
2019-05-17 01:00:06 +00:00
'COL_NR_BURSTS' => ( ! empty ( $record [ 'nr_bursts' ])) ? $record [ 'nr_bursts' ] : null ,
'COL_NR_PINGS' => ( ! empty ( $record [ 'nr_pings' ])) ? $record [ 'nr_pings' ] : null ,
2018-12-31 12:05:41 +00:00
'COL_OPERATOR' => ( ! empty ( $record [ 'operator' ])) ? $record [ 'operator' ] : '' ,
'COL_OWNER_CALLSIGN' => ( ! empty ( $record [ 'owner_callsign' ])) ? $record [ 'owner_callsign' ] : '' ,
'COL_PFX' => ( ! empty ( $record [ 'pfx' ])) ? $record [ 'pfx' ] : '' ,
'COL_PRECEDENCE' => ( ! empty ( $record [ 'precedence' ])) ? $record [ 'precedence' ] : '' ,
'COL_PROP_MODE' => ( ! empty ( $record [ 'prop_mode' ])) ? $record [ 'prop_mode' ] : '' ,
'COL_PUBLIC_KEY' => ( ! empty ( $record [ 'public_key' ])) ? $record [ 'public_key' ] : '' ,
2019-05-17 01:00:06 +00:00
'COL_QRZCOM_QSO_UPLOAD_DATE' => ( ! empty ( $record [ 'qrzcom_qso_upload_date' ])) ? $record [ 'qrzcom_qso_upload_date' ] : null ,
2018-12-31 12:05:41 +00:00
'COL_QRZCOM_QSO_UPLOAD_STATUS' => ( ! empty ( $record [ 'qrzcom_qso_upload_status' ])) ? $record [ 'qrzcom_qso_upload_status' ] : '' ,
'COL_QSL_RCVD' => ( ! empty ( $record [ 'qsl_rcvd' ])) ? $record [ 'qsl_rcvd' ] : '' ,
'COL_QSL_RCVD_VIA' => ( ! empty ( $record [ 'qsl_rcvd_via' ])) ? $record [ 'qsl_rcvd_via' ] : '' ,
'COL_QSL_SENT' => ( ! empty ( $record [ 'qsl_sent' ])) ? $record [ 'qsl_sent' ] : '' ,
'COL_QSL_SENT_VIA' => ( ! empty ( $record [ 'qsl_sent_via' ])) ? $record [ 'qsl_sent_via' ] : '' ,
'COL_QSL_VIA' => ( ! empty ( $record [ 'qsl_via' ])) ? $record [ 'qsl_via' ] : '' ,
'COL_QSLMSG' => ( ! empty ( $record [ 'qslmsg' ])) ? $record [ 'qslmsg' ] : '' ,
2019-05-17 01:00:06 +00:00
'COL_QSLRDATE' => ( ! empty ( $record [ 'qslrdate' ])) ? $record [ 'qslrdate' ] : null ,
'COL_QSLSDATE' => ( ! empty ( $record [ 'qslsdate' ])) ? $record [ 'qslsdate' ] : null ,
2018-12-31 12:05:41 +00:00
'COL_QSO_COMPLETE' => ( ! empty ( $record [ 'qso_complete' ])) ? $record [ 'qso_complete' ] : '' ,
2019-05-17 01:00:06 +00:00
'COL_QSO_DATE' => ( ! empty ( $record [ 'qso_date' ])) ? $record [ 'qso_date' ] : null ,
'COL_QSO_DATE_OFF' => ( ! empty ( $record [ 'qso_date_off' ])) ? $record [ 'qso_date_off' ] : null ,
'COL_QSO_RANDOM' => ( ! empty ( $record [ 'qso_random' ])) ? $record [ 'qso_random' ] : null ,
2018-12-31 12:05:41 +00:00
'COL_QTH' => ( ! empty ( $record [ 'qth' ])) ? $record [ 'qth' ] : '' ,
'COL_QTH_INTL' => ( ! empty ( $record [ 'qth_intl' ])) ? $record [ 'qth_intl' ] : '' ,
'COL_REGION' => ( ! empty ( $record [ 'region' ])) ? $record [ 'region' ] : '' ,
'COL_RIG' => ( ! empty ( $record [ 'rig' ])) ? $record [ 'rig' ] : '' ,
'COL_RIG_INTL' => ( ! empty ( $record [ 'rig_intl' ])) ? $record [ 'rig_intl' ] : '' ,
'COL_RST_RCVD' => $rst_rx ,
'COL_RST_SENT' => $rst_tx ,
2019-05-17 01:00:06 +00:00
'COL_RX_PWR' => ( ! empty ( $record [ 'rx_pwr' ])) ? $record [ 'rx_pwr' ] : null ,
2018-12-31 12:05:41 +00:00
'COL_SAT_MODE' => ( ! empty ( $record [ 'sat_mode' ])) ? $record [ 'sat_mode' ] : '' ,
'COL_SAT_NAME' => ( ! empty ( $record [ 'sat_name' ])) ? $record [ 'sat_name' ] : '' ,
2019-05-17 01:00:06 +00:00
'COL_SFI' => ( ! empty ( $record [ 'sfi' ])) ? $record [ 'sfi' ] : null ,
2018-12-31 12:05:41 +00:00
'COL_SIG' => ( ! empty ( $record [ 'sig' ])) ? $record [ 'sig' ] : '' ,
'COL_SIG_INFO' => ( ! empty ( $record [ 'sig_info' ])) ? $record [ 'sig_info' ] : '' ,
'COL_SIG_INFO_INTL' => ( ! empty ( $record [ 'sig_info_intl' ])) ? $record [ 'sig_info_intl' ] : '' ,
'COL_SIG_INTL' => ( ! empty ( $record [ 'sig_intl' ])) ? $record [ 'sig_intl' ] : '' ,
'COL_SILENT_KEY' => ( ! empty ( $record [ 'silent_key' ])) ? $record [ 'silent_key' ] : '' ,
'COL_SKCC' => ( ! empty ( $record [ 'skcc' ])) ? $record [ 'skcc' ] : '' ,
'COL_SOTA_REF' => ( ! empty ( $record [ 'sota_ref' ])) ? $record [ 'sota_ref' ] : '' ,
2019-05-17 01:00:06 +00:00
'COL_SRX' => ( ! empty ( $record [ 'srx' ])) ? $record [ 'srx' ] : null ,
2018-12-31 12:05:41 +00:00
'COL_SRX_STRING' => ( ! empty ( $record [ 'srx_string' ])) ? $record [ 'srx_string' ] : '' ,
'COL_STATE' => ( ! empty ( $record [ 'state' ])) ? $record [ 'state' ] : '' ,
'COL_STATION_CALLSIGN' => ( ! empty ( $record [ 'station_callsign' ])) ? $record [ 'station_callsign' ] : '' ,
2019-05-17 01:00:06 +00:00
'COL_STX' => ( ! empty ( $record [ 'stx' ])) ? $record [ 'stx' ] : null ,
2018-12-31 12:05:41 +00:00
'COL_STX_STRING' => ( ! empty ( $record [ 'stx_string' ])) ? $record [ 'stx_string' ] : '' ,
'COL_SUBMODE' => ( ! empty ( $record [ 'submode' ])) ? $record [ 'submode' ] : '' ,
2019-05-17 01:00:06 +00:00
'COL_SWL' => ( ! empty ( $record [ 'swl' ])) ? $record [ 'swl' ] : null ,
'COL_TEN_TEN' => ( ! empty ( $record [ 'ten_ten' ])) ? $record [ 'ten_ten' ] : null ,
2018-12-31 12:05:41 +00:00
'COL_TIME_ON' => $time_on ,
'COL_TIME_OFF' => $time_off ,
2019-05-17 01:00:06 +00:00
'COL_TX_PWR' => ( ! empty ( $record [ 'tx_pwr' ])) ? $record [ 'tx_pwr' ] : null ,
2018-12-31 12:05:41 +00:00
'COL_UKSMG' => ( ! empty ( $record [ 'uksmg' ])) ? $record [ 'uksmg' ] : '' ,
'COL_USACA_COUNTIES' => ( ! empty ( $record [ 'usaca_counties' ])) ? $record [ 'usaca_counties' ] : '' ,
'COL_VUCC_GRIDS' => (( ! empty ( $record [ 'vucc_grids' ]))) ? $record [ 'vucc_grids' ] : '' ,
'COL_WEB' => ( ! empty ( $record [ 'web' ])) ? $record [ 'web' ] : ''
2011-11-19 22:28:05 +00:00
);
2019-09-23 17:30:17 +00:00
if ( $station_id == " " || $station_id == " 0 " ) {
$CI =& get_instance ();
$CI -> load -> model ( 'Stations' );
$station_id = $CI -> Stations -> find_active ();
}
2019-08-19 21:25:50 +00:00
if ( $station_id != " 0 " ) {
$station_result = $this -> db -> where ( 'station_id' , $station_id )
-> get ( 'station_profile' );
if ( $station_result -> num_rows () > 0 ){
2019-09-23 17:30:17 +00:00
$data [ 'station_id' ] = $station_id ;
2019-08-19 21:25:50 +00:00
$row = $station_result -> row_array ();
if ( strpos ( trim ( $row [ 'station_gridsquare' ]), ',' ) !== false ) {
$data [ 'COL_MY_VUCC_GRIDS' ] = strtoupper ( trim ( $row [ 'station_gridsquare' ]));
} else {
$data [ 'COL_MY_GRIDSQUARE' ] = strtoupper ( trim ( $row [ 'station_gridsquare' ]));
}
2019-09-23 17:30:17 +00:00
$data [ 'COL_MY_CITY' ] = trim ( $row [ 'station_city' ]);
2019-08-19 21:25:50 +00:00
$data [ 'COL_MY_IOTA' ] = strtoupper ( trim ( $row [ 'station_iota' ]));
$data [ 'COL_MY_SOTA_REF' ] = strtoupper ( trim ( $row [ 'station_sota' ]));
$data [ 'COL_STATION_CALLSIGN' ] = strtoupper ( trim ( $row [ 'station_callsign' ]));
$data [ 'COL_MY_DXCC' ] = strtoupper ( trim ( $row [ 'station_dxcc' ]));
$data [ 'COL_MY_COUNTRY' ] = strtoupper ( trim ( $row [ 'station_country' ]));
$data [ 'COL_MY_CNTY' ] = strtoupper ( trim ( $row [ 'station_cnty' ]));
$data [ 'COL_MY_CQ_ZONE' ] = strtoupper ( trim ( $row [ 'station_cq' ]));
$data [ 'COL_MY_ITU_ZONE' ] = strtoupper ( trim ( $row [ 'station_itu' ]));
}
}
2016-02-13 13:55:16 +00:00
2011-11-19 22:28:05 +00:00
$this -> add_qso ( $data );
2018-12-31 12:05:41 +00:00
2011-11-19 22:28:05 +00:00
}
}
2016-02-22 08:09:50 +00:00
2016-02-28 17:43:45 +00:00
/*
* Check the dxxc_prefixes table and return ( dxcc , country )
*/
2016-04-13 15:16:07 +00:00
public function check_dxcc_table ( $call , $date ){
2016-02-22 08:09:50 +00:00
$len = strlen ( $call );
// query the table, removing a character from the right until a match
for ( $i = $len ; $i > 0 ; $i -- ){
//printf("searching for %s\n", substr($call, 0, $i));
2016-04-13 15:16:07 +00:00
$dxcc_result = $this -> db -> select ( '`call`, `entity`, `adif`, `cqz`' )
2016-02-23 22:00:35 +00:00
-> where ( 'call' , substr ( $call , 0 , $i ))
-> where ( '(start <= ' , $date )
2019-05-17 01:00:06 +00:00
-> or_where ( " start = '0000-00-00' " , NULL , false )
-> or_where ( " start is null) " , NULL , false )
2016-02-23 22:00:35 +00:00
-> where ( '(end >= ' , $date )
2019-05-17 01:00:06 +00:00
-> or_where ( " end = '0000-00-00' " , NULL , false )
-> or_where ( " end is null) " , NULL , false )
2016-02-23 22:00:35 +00:00
-> get ( 'dxcc_prefixes' );
2016-02-22 08:09:50 +00:00
2016-02-23 22:00:35 +00:00
//$dxcc_result = $this->db->query("select `call`, `entity`, `adif` from dxcc_prefixes where `call` = '".substr($call, 0, $i) ."'");
//print $this->db->last_query();
2016-02-22 08:09:50 +00:00
if ( $dxcc_result -> num_rows () > 0 ){
$row = $dxcc_result -> row_array ();
2016-04-13 15:16:07 +00:00
return array ( $row [ 'adif' ], $row [ 'entity' ], $row [ 'cqz' ]);
2016-02-22 08:09:50 +00:00
}
}
return array ( " Not Found " , " Not Found " );
}
2019-06-13 23:14:39 +00:00
public function dxcc_lookup ( $call , $date ){
$len = strlen ( $call );
2019-08-16 17:21:11 +00:00
$this -> db -> where ( 'call' , $call );
$this -> db -> where ( 'CURDATE() between start and end' );
2019-06-13 23:14:39 +00:00
2019-08-16 17:21:11 +00:00
$query = $this -> db -> get ( 'dxcc_exceptions' );
if ( $query -> num_rows () > 0 ){
$row = $query -> row_array ();
2019-06-13 23:14:39 +00:00
return $row ;
2019-08-16 17:21:11 +00:00
} else {
// query the table, removing a character from the right until a match
for ( $i = $len ; $i > 0 ; $i -- ){
//printf("searching for %s\n", substr($call, 0, $i));
$dxcc_result = $this -> db -> select ( '*' )
-> where ( 'call' , substr ( $call , 0 , $i ))
-> where ( '(start <= ' , $date )
-> or_where ( " start = '0000-00-00' " , NULL , false )
-> or_where ( " start is null) " , NULL , false )
-> where ( '(end >= ' , $date )
-> or_where ( " end = '0000-00-00' " , NULL , false )
-> or_where ( " end is null) " , NULL , false )
-> get ( 'dxcc_prefixes' );
//$dxcc_result = $this->db->query("select `call`, `entity`, `adif` from dxcc_prefixes where `call` = '".substr($call, 0, $i) ."'");
//print $this->db->last_query();
if ( $dxcc_result -> num_rows () > 0 ){
$row = $dxcc_result -> row_array ();
return $row ;
}
}
2019-06-13 23:14:39 +00:00
}
return array ( " Not Found " , " Not Found " );
}
2016-02-28 14:09:08 +00:00
/*
* Same as check_dxcc_table , but the functionality is in
* a stored procedure which we call
*/
public function check_dxcc_stored_proc ( $call , $date ){
2016-04-13 15:16:07 +00:00
$this -> db -> query ( " call find_country(' " . $call . " ',' " . $date . " ', @country, @adif, @cqz) " );
$res = $this -> db -> query ( " select @country as country, @adif as adif, @cqz as cqz " );
2016-02-28 14:09:08 +00:00
$d = $res -> result_array ();
// Should only be one result.
// NOTE: might cause unexpected data if there's an
// error with clublog.org data.
return $d [ 0 ];
}
2016-02-23 22:00:35 +00:00
public function check_missing_dxcc_id ( $all ){
2016-02-22 08:09:50 +00:00
// get all records with no COL_DXCC
2016-02-23 22:00:35 +00:00
$this -> db -> select ( " COL_PRIMARY_KEY, COL_CALL, COL_TIME_ON, COL_TIME_OFF " );
// check which to update - records with no dxcc or all records
if ( ! isset ( $all )){
$this -> db -> where ( " COL_DXCC is NULL " );
}
2016-02-22 08:09:50 +00:00
$r = $this -> db -> get ( $this -> config -> item ( 'table_name' ));
$count = 0 ;
$this -> db -> trans_start ();
//query dxcc_prefixes
if ( $r -> num_rows () > 0 ){
foreach ( $r -> result_array () as $row ){
2016-02-23 22:00:35 +00:00
$qso_date = $row [ 'COL_TIME_OFF' ] == '' ? $row [ 'COL_TIME_ON' ] : $row [ 'COL_TIME_ON' ];
$qso_date = strftime ( " %Y-%m-%d " , strtotime ( $qso_date ));
2016-02-28 14:09:08 +00:00
// Manual call
2016-02-23 22:00:35 +00:00
$d = $this -> check_dxcc_table ( $row [ 'COL_CALL' ], $qso_date );
2016-02-28 14:09:08 +00:00
// Stored procedure call
//$d = $this->check_dxcc_stored_proc($row["COL_CALL"], $qso_date);
2016-02-22 08:09:50 +00:00
if ( $d [ 0 ] != 'Not Found' ){
$sql = sprintf ( " update %s set COL_COUNTRY = '%s', COL_DXCC='%s' where COL_PRIMARY_KEY=%d " ,
2016-02-23 22:00:35 +00:00
$this -> config -> item ( 'table_name' ), addslashes ( ucwords ( strtolower ( $d [ 1 ]))), $d [ 0 ], $row [ 'COL_PRIMARY_KEY' ]);
2016-02-22 08:09:50 +00:00
$this -> db -> query ( $sql );
//print($sql."\n");
2016-02-23 22:00:35 +00:00
printf ( " Updating %s to %s and %s \n <br/> " , $row [ 'COL_PRIMARY_KEY' ], ucwords ( strtolower ( $d [ 1 ])), $d [ 0 ]);
2016-02-22 08:09:50 +00:00
$count ++ ;
}
}
}
$this -> db -> trans_complete ();
print ( " $count updated \n " );
}
2019-09-23 16:29:22 +00:00
2019-10-03 11:56:25 +00:00
2019-09-23 16:29:22 +00:00
public function check_for_station_id () {
2019-10-03 11:56:25 +00:00
$this -> db -> where ( 'station_id =' , 'NULL' );
2019-09-23 16:29:22 +00:00
$query = $this -> db -> get ( $this -> config -> item ( 'table_name' ));
if ( $query -> num_rows () >= 1 ) {
return 1 ;
} else {
return 0 ;
}
}
2019-10-03 11:56:25 +00:00
public function update_all_station_ids () {
$data = array (
'station_id' => '1' ,
);
$this -> db -> where ( array ( 'station_id' => NULL ));
return $this -> db -> update ( $this -> config -> item ( 'table_name' ), $data );
}
2019-02-25 23:43:14 +00:00
public function parse_frequency ( $frequency )
{
if ( is_int ( $frequency ))
return $frequency ;
if ( is_string ( $frequency ))
{
$frequency = strtoupper ( $frequency );
$frequency = str_replace ( " " , " " , $frequency );
$frequency = str_replace ( " HZ " , " " , $frequency );
$frequency = str_replace ([ " K " , " M " , " G " , " T " ], [ " E3 " , " E6 " , " E9 " , " E12 " ], $frequency );
// this double conversion will take a string like "3700e3" and convert it into 3700000
return ( int )( float ) $frequency ;
}
return 0 ;
}
2011-04-25 15:24:01 +00:00
}
2019-05-11 23:21:10 +00:00
?>