| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Logbook_model extends CI_Model { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-15 00:01:51 +08:00
										 |  |  |   /* Add QSO to Logbook */ | 
					
						
							| 
									
										
										
										
											2016-02-13 00:31:29 +08:00
										 |  |  |   function create_qso() { | 
					
						
							|  |  |  |     // Join date+time
 | 
					
						
							|  |  |  |     $datetime = date("Y-m-d",strtotime($this->input->post('start_date')))." ". $this->input->post('start_time'); | 
					
						
							|  |  |  |     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"; | 
					
						
							| 
									
										
										
										
											2020-11-17 16:47:57 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Contest exchange, need to separate between serial and other type of exchange
 | 
					
						
							| 
									
										
										
										
											2021-08-13 18:47:17 +08:00
										 |  |  |     if($this->input->post('exchangetype')) { | 
					
						
							| 
									
										
										
										
											2021-11-01 00:11:46 +08:00
										 |  |  |       $srx_string = $this->input->post('exch_recv') == '' ? null : $this->input->post('exch_recv'); | 
					
						
							|  |  |  |       $stx_string = $this->input->post('exch_sent') == '' ? null : $this->input->post('exch_sent'); | 
					
						
							|  |  |  |       $srx = $this->input->post('exch_serial_r') == '' ? null : $this->input->post('exch_serial_r'); | 
					
						
							|  |  |  |       $stx = $this->input->post('exch_serial_s') == '' ? null : $this->input->post('exch_serial_s'); | 
					
						
							| 
									
										
										
										
											2020-11-17 16:47:57 +08:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2021-11-01 00:11:46 +08:00
										 |  |  |       $srx_string = null; | 
					
						
							|  |  |  |       $stx_string = null; | 
					
						
							|  |  |  |       $srx = null; | 
					
						
							|  |  |  |       $stx = null; | 
					
						
							| 
									
										
										
										
											2020-11-17 16:47:57 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-02-13 00:31:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-19 06:27:47 +08:00
										 |  |  |     if($this->input->post('contestname')) { | 
					
						
							|  |  |  |         $contestid = $this->input->post('contestname'); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         $contestid = null; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-13 00:31:29 +08:00
										 |  |  |     if($this->session->userdata('user_locator')){ | 
					
						
							|  |  |  |         $locator = $this->session->userdata('user_locator'); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         $locator = $this->config->item('locator'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-14 20:20:53 +08:00
										 |  |  |     if($this->input->post('transmit_power')) { | 
					
						
							|  |  |  |         $tx_power = $this->input->post('transmit_power'); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         $tx_power = null; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-19 23:05:47 +08: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 23:18:31 +08:00
										 |  |  |       if (empty($dxcc[2])) { | 
					
						
							|  |  |  |         $cqz = null; | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         $cqz = $dxcc[2]; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-08-19 23:05:47 +08:00
										 |  |  |     } else { | 
					
						
							|  |  |  |       $cqz = $this->input->post('cqz'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if($this->input->post('dxcc_id') == "") { | 
					
						
							| 
									
										
										
										
											2021-02-09 04:46:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-19 23:05:47 +08:00
										 |  |  |       $dxcc = $this->check_dxcc_table(strtoupper(trim($this->input->post('callsign'))), $datetime); | 
					
						
							| 
									
										
										
										
											2019-08-27 23:18:31 +08:00
										 |  |  |       if (empty($dxcc[0])) { | 
					
						
							|  |  |  |         $dxcc_id = null; | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |        $dxcc_id = $dxcc[0]; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-19 23:05:47 +08:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2020-04-13 16:34:02 +08:00
										 |  |  |         $dxcc_id = $this->input->post('dxcc_id'); | 
					
						
							| 
									
										
										
										
											2019-08-19 23:05:47 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-24 06:06:08 +08:00
										 |  |  |     $mode = $this->get_main_mode_if_submode($this->input->post('mode')); | 
					
						
							|  |  |  |     if ($mode == null) { | 
					
						
							|  |  |  |         $mode = $this->input->post('mode'); | 
					
						
							|  |  |  |         $submode = null; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         $submode = $this->input->post('mode'); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-03-09 21:36:51 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if($this->input->post('county') && $this->input->post('usa_state')) { | 
					
						
							|  |  |  |       $clean_county_input = trim($this->input->post('usa_state')) . "," . trim($this->input->post('county')); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       $clean_county_input = null; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-16 22:03:54 +08:00
										 |  |  |     if($this->input->post('copyexchangetodok')) { | 
					
						
							| 
									
										
										
										
											2022-03-17 01:16:24 +08:00
										 |  |  |       $darc_dok = $this->input->post('exch_recv'); | 
					
						
							| 
									
										
										
										
											2021-10-16 22:03:54 +08:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2022-03-17 01:16:24 +08:00
										 |  |  |       $darc_dok = $this->input->post('darc_dok'); | 
					
						
							| 
									
										
										
										
											2021-10-16 22:03:54 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-21 02:30:50 +08:00
										 |  |  |     if ($this->input->post('qsl_sent')) { | 
					
						
							|  |  |  |         $qsl_sent = $this->input->post('qsl_sent'); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         $qsl_sent = 'N'; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ($this->input->post('qsl_recv')) { | 
					
						
							|  |  |  |         $qsl_recv = $this->input->post('qsl_recv'); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         $qsl_recv = 'N'; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ($qsl_sent == 'N') { | 
					
						
							|  |  |  |         $qslsdate = null; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         $qslsdate = date('Y-m-d H:i:s'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ($qsl_recv == 'N') { | 
					
						
							|  |  |  |         $qslrdate = null; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         $qslrdate = date('Y-m-d H:i:s'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-13 00:31:29 +08: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'), | 
					
						
							| 
									
										
										
										
											2020-12-26 22:07:00 +08:00
										 |  |  |             'COL_BAND_RX' => $this->input->post('band_rx'), | 
					
						
							| 
									
										
										
										
											2019-02-26 07:43:14 +08:00
										 |  |  |             'COL_FREQ' => $this->parse_frequency($this->input->post('freq_display')), | 
					
						
							| 
									
										
										
										
											2020-05-24 06:06:08 +08:00
										 |  |  |             'COL_MODE' => $mode, | 
					
						
							|  |  |  |             'COL_SUBMODE' => $submode, | 
					
						
							| 
									
										
										
										
											2016-02-13 00:31:29 +08:00
										 |  |  |             '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 23:05:47 +08:00
										 |  |  |             'COL_COUNTRY' => $country, | 
					
						
							| 
									
										
										
										
											2022-01-21 02:30:50 +08:00
										 |  |  |             'COL_QSLSDATE' => $qslsdate, | 
					
						
							|  |  |  |             'COL_QSLRDATE' => $qslrdate, | 
					
						
							|  |  |  |             'COL_QSL_SENT' => $qsl_sent, | 
					
						
							|  |  |  |             'COL_QSL_RCVD' => $qsl_recv, | 
					
						
							| 
									
										
										
										
											2016-02-13 00:31:29 +08:00
										 |  |  |             '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'), | 
					
						
							| 
									
										
										
										
											2022-03-17 01:21:46 +08:00
										 |  |  |             'COL_QSLMSG' => $this->input->post('qslmsg'), | 
					
						
							| 
									
										
										
										
											2016-02-13 00:31:29 +08:00
										 |  |  |             '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-26 07:43:14 +08:00
										 |  |  |             'COL_FREQ_RX' => $this->parse_frequency($this->input->post('freq_display_rx')), | 
					
						
							| 
									
										
										
										
											2016-02-13 00:31:29 +08:00
										 |  |  |             'COL_ANT_AZ' => null, | 
					
						
							|  |  |  |             'COL_ANT_EL' => null, | 
					
						
							|  |  |  |             'COL_A_INDEX' => null, | 
					
						
							|  |  |  |             'COL_AGE' => null, | 
					
						
							|  |  |  |             'COL_TEN_TEN' => null, | 
					
						
							| 
									
										
										
										
											2020-04-14 20:20:53 +08:00
										 |  |  |             'COL_TX_PWR' => $tx_power, | 
					
						
							| 
									
										
										
										
											2020-11-17 16:47:57 +08:00
										 |  |  |             'COL_STX' => $stx, | 
					
						
							|  |  |  |             'COL_SRX' => $srx, | 
					
						
							|  |  |  |             'COL_STX_STRING' => $stx_string, | 
					
						
							|  |  |  |             'COL_SRX_STRING' => $srx_string, | 
					
						
							| 
									
										
										
										
											2020-12-19 06:27:47 +08:00
										 |  |  |             'COL_CONTEST_ID' => $contestid, | 
					
						
							| 
									
										
										
										
											2016-02-13 00:31:29 +08:00
										 |  |  |             '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 23:05:47 +08:00
										 |  |  |             'COL_DXCC' => $dxcc_id, | 
					
						
							|  |  |  |             'COL_CQZ' => $cqz, | 
					
						
							| 
									
										
										
										
											2020-03-06 02:27:11 +08:00
										 |  |  |             'COL_STATE' => trim($this->input->post('usa_state')), | 
					
						
							| 
									
										
										
										
											2021-03-09 21:36:51 +08:00
										 |  |  |             'COL_CNTY' => $clean_county_input, | 
					
						
							| 
									
										
										
										
											2019-06-14 01:35:14 +08:00
										 |  |  |             'COL_SOTA_REF' => trim($this->input->post('sota_ref')), | 
					
						
							| 
									
										
										
										
											2020-11-17 05:08:32 +08:00
										 |  |  |             'COL_SIG' => trim($this->input->post('sig')), | 
					
						
							|  |  |  |             'COL_SIG_INFO' => trim($this->input->post('sig_info')), | 
					
						
							| 
									
										
										
										
											2022-03-17 01:16:24 +08:00
										 |  |  |             'COL_DARC_DOK' => trim($darc_dok), | 
					
						
							| 
									
										
										
										
											2021-08-13 18:47:17 +08:00
										 |  |  | 			'COL_NOTES' => $this->input->post('notes'), | 
					
						
							| 
									
										
										
										
											2016-02-13 00:31:29 +08:00
										 |  |  |     ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-24 01:30:17 +08: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-02 03:14:25 +08:00
										 |  |  |     // If station profile has been provided fill in the fields
 | 
					
						
							| 
									
										
										
										
											2019-09-24 01:30:17 +08:00
										 |  |  |     if($station_id != "0") { | 
					
						
							|  |  |  |       $station = $this->check_station($station_id); | 
					
						
							| 
									
										
										
										
											2019-09-25 05:05:27 +08:00
										 |  |  |         $data['station_id'] = $station_id; | 
					
						
							| 
									
										
										
										
											2019-01-02 03:14:25 +08: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'])); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-08 03:10:27 +08:00
										 |  |  |     if ($this->exists_qrz_api_key($station_id)) { | 
					
						
							| 
									
										
										
										
											2020-08-29 19:50:22 +08:00
										 |  |  |         $data['COL_QRZCOM_QSO_UPLOAD_STATUS'] = 'N'; | 
					
						
							| 
									
										
										
										
											2020-05-08 03:10:27 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-02 03:14:25 +08:00
										 |  |  |       $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'])); | 
					
						
							| 
									
										
										
										
											2021-02-09 04:46:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-02 03:14:25 +08:00
										 |  |  |       $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 23:43:21 +08: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 21:55:16 +08: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-16 01:02:17 +08: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'; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-11 17:49:33 +08:00
										 |  |  |     $this->add_qso($data, $skipexport = false); | 
					
						
							| 
									
										
										
										
											2016-02-13 00:31:29 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-09-07 00:27:27 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-02 03:14:25 +08:00
										 |  |  |   public function check_station($id){ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-09 04:46:53 +08:00
										 |  |  |     $this->db->where('station_id', $id); | 
					
						
							| 
									
										
										
										
											2019-01-02 03:14:25 +08:00
										 |  |  |     $query = $this->db->get('station_profile'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ($query->num_rows() > 0) { | 
					
						
							|  |  |  |       $row = $query->row_array(); | 
					
						
							|  |  |  |         return($row); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-07-24 20:31:16 +08:00
										 |  |  | 	/* | 
					
						
							|  |  |  | 	 * Used to fetch QSOs from the logbook in the awards | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function qso_details($searchphrase, $band, $mode, $type){ | 
					
						
							|  |  |  | 		$CI =& get_instance(); | 
					
						
							| 
									
										
										
										
											2021-09-09 04:07:00 +08:00
										 |  |  | 		$CI->load->model('logbooks_model'); | 
					
						
							|  |  |  | 		$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							| 
									
										
										
										
											2021-07-24 20:31:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-03 00:14:04 +08:00
										 |  |  | 		$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id'); | 
					
						
							| 
									
										
										
										
											2021-07-24 20:31:16 +08:00
										 |  |  | 		switch ($type) { | 
					
						
							|  |  |  | 			case 'DXCC': | 
					
						
							|  |  |  | 				$this->db->where('COL_COUNTRY', $searchphrase); | 
					
						
							|  |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2021-07-29 16:38:27 +08:00
										 |  |  | 			case 'DXCC2': | 
					
						
							|  |  |  | 				$this->db->where('COL_DXCC', $searchphrase); | 
					
						
							|  |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2021-07-24 20:31:16 +08:00
										 |  |  | 			case 'IOTA': | 
					
						
							|  |  |  | 				$this->db->where('COL_IOTA', $searchphrase); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case 'VUCC': | 
					
						
							|  |  |  | 				$this->db->where("(COL_GRIDSQUARE like '%" . $searchphrase . "%' OR COL_VUCC_GRIDS like'%" . $searchphrase ."%')"); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case 'CQZone': | 
					
						
							|  |  |  | 				$this->db->where('COL_CQZ', $searchphrase); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case 'WAS': | 
					
						
							|  |  |  | 				$this->db->where('COL_STATE', $searchphrase); | 
					
						
							|  |  |  | 				$this->db->where_in('COL_DXCC', ['291', '6', '110']); | 
					
						
							|  |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2021-07-29 16:38:27 +08:00
										 |  |  | 			case 'SOTA': | 
					
						
							|  |  |  | 				$this->db->where('COL_SOTA_REF', $searchphrase); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case 'WWFF': | 
					
						
							|  |  |  | 				$this->db->where('COL_SIG', 'WWFF'); | 
					
						
							|  |  |  | 				$this->db->where('COL_SIG_INFO', $searchphrase); | 
					
						
							|  |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2021-07-24 20:31:16 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-01-02 03:14:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-03 00:14:04 +08:00
										 |  |  |     $this->db->where_in($this->config->item('table_name').'.station_id', $logbooks_locations_array); | 
					
						
							| 
									
										
										
										
											2019-12-04 01:36:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-24 20:31:16 +08:00
										 |  |  | 		if ($band != 'All') { | 
					
						
							|  |  |  | 			if($band != "SAT") { | 
					
						
							|  |  |  | 				$this->db->where('COL_PROP_MODE !=', 'SAT'); | 
					
						
							|  |  |  | 				$this->db->where('COL_BAND', $band); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				$this->db->where('COL_PROP_MODE', "SAT"); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-03-07 18:39:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-24 20:31:16 +08:00
										 |  |  | 		if ($mode != 'All') { | 
					
						
							|  |  |  | 			$this->db->where("(COL_MODE='" . $mode . "' OR COL_SUBMODE='" . $mode ."')"); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2022-01-14 18:59:04 +08:00
										 |  |  | 		$this->db->order_by("COL_TIME_ON", "desc"); | 
					
						
							| 
									
										
										
										
											2020-03-07 18:39:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-24 20:31:16 +08:00
										 |  |  | 		return $this->db->get($this->config->item('table_name')); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-02-09 04:46:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-17 00:17:17 +08:00
										 |  |  | 	public function activated_grids_qso_details($searchphrase, $band, $mode){ | 
					
						
							|  |  |  | 		$CI =& get_instance(); | 
					
						
							|  |  |  | 		$CI->load->model('logbooks_model'); | 
					
						
							|  |  |  | 		$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-01 01:11:21 +08:00
										 |  |  | 		$sql =  'SELECT COL_SOTA_REF, COL_OPERATOR, COL_IOTA, COL_VUCC_GRIDS, COL_STATE, COL_GRIDSQUARE, COL_PRIMARY_KEY, COL_CALL, COL_TIME_ON, COL_BAND, COL_SAT_NAME, COL_MODE, COL_SUBMODE, COL_RST_SENT, '; | 
					
						
							| 
									
										
										
										
											2022-02-28 17:30:51 +08:00
										 |  |  | 		$sql .= 'COL_RST_RCVD, COL_STX, COL_SRX, COL_STX_STRING, COL_SRX_STRING, COL_COUNTRY, COL_QSL_SENT, COL_QSL_SENT_VIA, '; | 
					
						
							|  |  |  | 		$sql .= 'COL_QSLSDATE, COL_QSL_RCVD, COL_QSL_RCVD_VIA, COL_QSLRDATE, COL_EQSL_QSL_SENT, COL_EQSL_QSLSDATE, COL_EQSL_QSLRDATE, '; | 
					
						
							| 
									
										
										
										
											2022-03-02 23:14:02 +08:00
										 |  |  | 		$sql .= 'COL_EQSL_QSL_RCVD, COL_LOTW_QSL_SENT, COL_LOTW_QSLSDATE, COL_LOTW_QSL_RCVD, COL_LOTW_QSLRDATE, COL_CONTEST_ID, station_gridsquare '; | 
					
						
							|  |  |  | 		$sql .= 'FROM '.$this->config->item('table_name').' JOIN `station_profile` ON station_profile.station_id = '.$this->config->item('table_name').'.station_id '; | 
					
						
							|  |  |  | 		$sql .= 'WHERE '.$this->config->item('table_name').'.station_id IN (SELECT station_id from station_profile '; | 
					
						
							| 
									
										
										
										
											2022-02-28 17:30:51 +08:00
										 |  |  | 		$sql .= 'WHERE station_gridsquare LIKE "%'.$searchphrase.'%") '; | 
					
						
							| 
									
										
										
										
											2022-02-17 00:17:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-24 20:31:16 +08:00
										 |  |  | 		if ($band != 'All') { | 
					
						
							|  |  |  | 			if($band != "SAT") { | 
					
						
							| 
									
										
										
										
											2022-02-28 17:30:51 +08:00
										 |  |  | 				$sql .= 'AND COL_PROP_MODE != "SAT" AND '; | 
					
						
							|  |  |  | 				$sql .= 'COL_BAND = "'.$band.'" '; | 
					
						
							| 
									
										
										
										
											2021-07-24 20:31:16 +08:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2022-02-28 17:30:51 +08:00
										 |  |  | 				$sql .= 'AND COL_PROP_MODE = "SAT"'; | 
					
						
							| 
									
										
										
										
											2021-07-24 20:31:16 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-03-07 18:39:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-24 20:31:16 +08:00
										 |  |  | 		if ($mode != 'All') { | 
					
						
							| 
									
										
										
										
											2022-02-28 17:30:51 +08:00
										 |  |  | 			$sql .= ' AND COL_MODE = "'.$mode.'" OR COL_SUBMODE="'.$mode.'"'; | 
					
						
							| 
									
										
										
										
											2021-07-24 20:31:16 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2022-02-28 17:30:51 +08:00
										 |  |  | 		$sql .= ' ORDER BY COL_TIME_ON DESC LIMIT 500'; | 
					
						
							| 
									
										
										
										
											2020-03-07 18:39:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-28 17:30:51 +08:00
										 |  |  | 		return $this->db->query($sql); | 
					
						
							| 
									
										
										
										
											2021-07-24 20:31:16 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-02-09 04:46:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-15 21:18:49 +08:00
										 |  |  |     public function vucc_qso_details($gridsquare, $band) { | 
					
						
							| 
									
										
										
										
											2021-09-10 04:53:25 +08:00
										 |  |  | 		$CI =& get_instance(); | 
					
						
							|  |  |  | 		$CI->load->model('logbooks_model'); | 
					
						
							|  |  |  | 		$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$location_list = "'".implode("','",$logbooks_locations_array)."'"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-25 21:59:03 +08:00
										 |  |  |         $sql = "select * from " . $this->config->item('table_name') . | 
					
						
							| 
									
										
										
										
											2021-09-10 04:53:25 +08:00
										 |  |  |                 " where station_id in (" . $location_list . ")" . | 
					
						
							| 
									
										
										
										
											2020-10-25 21:59:03 +08:00
										 |  |  |                 " and (col_gridsquare like '" . $gridsquare. "%'
 | 
					
						
							|  |  |  |                     or col_vucc_grids like '%" . $gridsquare. "%')";
 | 
					
						
							| 
									
										
										
										
											2020-03-15 21:18:49 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if ($band != 'All') { | 
					
						
							|  |  |  |             if ($band == 'SAT') { | 
					
						
							|  |  |  |                 $sql .= " and col_prop_mode ='" . $band . "'"; | 
					
						
							|  |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2020-03-17 21:39:34 +08:00
										 |  |  |                 $sql .= " and col_prop_mode !='SAT'"; | 
					
						
							| 
									
										
										
										
											2020-03-15 21:18:49 +08:00
										 |  |  |                 $sql .= " and col_band ='" . $band . "'"; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this->db->query($sql); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-03-07 18:39:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-23 18:25:16 +08:00
										 |  |  |     public function timeline_qso_details($querystring, $band, $mode, $type){ | 
					
						
							| 
									
										
										
										
											2021-09-10 17:59:41 +08:00
										 |  |  | 		$CI =& get_instance(); | 
					
						
							|  |  |  | 		$CI->load->model('logbooks_model'); | 
					
						
							|  |  |  | 		$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							| 
									
										
										
										
											2020-04-28 16:53:11 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-17 03:59:22 +08:00
										 |  |  | 		$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-28 16:53:11 +08:00
										 |  |  |         if ($band != 'All') { | 
					
						
							|  |  |  |             if ($band == 'SAT') { | 
					
						
							|  |  |  |                 $this->db->where('col_prop_mode', $band); | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 $this->db->where('COL_PROP_MODE !=', 'SAT'); | 
					
						
							|  |  |  |                 $this->db->where('col_band', $band); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-23 18:25:16 +08:00
										 |  |  |         if ($mode != 'All') { | 
					
						
							|  |  |  |             $this->db->where('col_mode', $mode); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-17 03:59:22 +08:00
										 |  |  |         $this->db->where_in('station_profile.station_id', $logbooks_locations_array); | 
					
						
							| 
									
										
										
										
											2020-10-23 18:25:16 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         switch($type) { | 
					
						
							|  |  |  |             case 'dxcc': $this->db->where('COL_DXCC', $querystring); break; | 
					
						
							|  |  |  |             case 'was':  $this->db->where('COL_STATE', $querystring); break; | 
					
						
							|  |  |  |             case 'iota': $this->db->where('COL_IOTA', $querystring); break; | 
					
						
							|  |  |  |             case 'waz':  $this->db->where('COL_CQZ', $querystring); break; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-04-28 16:53:11 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $this->db->get($this->config->item('table_name')); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-23 00:41:03 +08:00
										 |  |  |     public function activator_details($call, $band, $leogeo){ | 
					
						
							|  |  |  | 		$CI =& get_instance(); | 
					
						
							|  |  |  | 		$CI->load->model('logbooks_model'); | 
					
						
							|  |  |  | 		$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-01 16:38:54 +08:00
										 |  |  |       $this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id'); | 
					
						
							| 
									
										
										
										
											2022-03-23 00:41:03 +08:00
										 |  |  |         $this->db->where('COL_CALL', $call); | 
					
						
							|  |  |  |         if ($band != 'All') { | 
					
						
							|  |  |  |             if ($band == 'SAT') { | 
					
						
							|  |  |  |                 $this->db->where('col_prop_mode', $band); | 
					
						
							|  |  |  |                 switch ($leogeo) { | 
					
						
							|  |  |  |                 case 'leo' :  $this->db->where('COL_SAT_NAME !=', 'QO-100'); | 
					
						
							|  |  |  |                               break; | 
					
						
							|  |  |  |                 case 'geo':   $this->db->where('COL_SAT_NAME', 'QO-100'); | 
					
						
							|  |  |  |                               break; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 $this->db->where('COL_PROP_MODE !=', 'SAT'); | 
					
						
							|  |  |  |                 $this->db->where('col_band', $band); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-01 16:38:54 +08:00
										 |  |  |         $this->db->where_in('station_profile.station_id', $logbooks_locations_array); | 
					
						
							| 
									
										
										
										
											2022-03-23 00:41:03 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $this->db->get($this->config->item('table_name')); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-15 18:53:32 +08:00
										 |  |  |   public function get_callsigns($callsign){ | 
					
						
							|  |  |  |     $this->db->select('COL_CALL'); | 
					
						
							|  |  |  |     $this->db->distinct(); | 
					
						
							|  |  |  |     $this->db->like('COL_CALL', $callsign); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-11 23:42:18 +08:00
										 |  |  |     return $this->db->get($this->config->item('table_name')); | 
					
						
							| 
									
										
										
										
											2019-08-15 18:53:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-11 17:49:33 +08:00
										 |  |  |   function add_qso($data, $skipexport = false) { | 
					
						
							| 
									
										
										
										
											2019-06-15 19:45:29 +08: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']); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-21 21:25:02 +08:00
										 |  |  |     // Add QSO to database
 | 
					
						
							|  |  |  |     $this->db->insert($this->config->item('table_name'), $data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $last_id = $this->db->insert_id(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-28 20:53:38 +08:00
										 |  |  |     // No point in fetching qrz api key and qrzrealtime setting if we're skipping the export
 | 
					
						
							|  |  |  | 	if (!$skipexport) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$result = $this->exists_qrz_api_key($data['station_id']); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Push qso to qrz if apikey is set, and realtime upload is enabled, and we're not importing an adif-file
 | 
					
						
							|  |  |  | 		if (isset($result->qrzapikey) && $result->qrzrealtime == 1) { | 
					
						
							|  |  |  | 			$CI =& get_instance(); | 
					
						
							|  |  |  | 			$CI->load->library('AdifHelper'); | 
					
						
							|  |  |  | 			$qso = $this->get_qso($last_id)->result(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			$adif = $CI->adifhelper->getAdifLine($qso[0]); | 
					
						
							|  |  |  | 			$result = $this->push_qso_to_qrz($result->qrzapikey, $adif); | 
					
						
							|  |  |  | 			if ($result['status'] == 'OK') { | 
					
						
							|  |  |  | 				$this->mark_qrz_qsos_sent($last_id); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-05-07 23:35:58 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-13 01:11:29 +08:00
										 |  |  |   /* | 
					
						
							|  |  |  |    * Function checks if a QRZ API Key exists in the table with the given station id | 
					
						
							|  |  |  |   */ | 
					
						
							| 
									
										
										
										
											2020-05-07 23:35:58 +08:00
										 |  |  |   function exists_qrz_api_key($station_id) { | 
					
						
							| 
									
										
										
										
											2020-11-18 18:50:15 +08:00
										 |  |  |       $sql = 'select qrzapikey, qrzrealtime from station_profile | 
					
						
							| 
									
										
										
										
											2022-04-01 22:17:05 +08:00
										 |  |  |             where station_id = ' . $station_id; | 
					
						
							| 
									
										
										
										
											2020-05-07 23:35:58 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       $query = $this->db->query($sql); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       $result = $query->row(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if ($result) { | 
					
						
							| 
									
										
										
										
											2020-11-18 18:50:15 +08:00
										 |  |  |           return $result; | 
					
						
							| 
									
										
										
										
											2020-05-07 23:35:58 +08:00
										 |  |  |       } | 
					
						
							|  |  |  |       else { | 
					
						
							|  |  |  |           return false; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-13 01:11:29 +08:00
										 |  |  |   /* | 
					
						
							|  |  |  |    * Function uploads a QSO to QRZ with the API given. | 
					
						
							|  |  |  |    * $adif contains a line with the QSO in the ADIF format. QSO ends with an <eor> | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2020-06-05 03:56:32 +08:00
										 |  |  |   function push_qso_to_qrz($apikey, $adif, $replaceoption = false) { | 
					
						
							| 
									
										
										
										
											2020-05-07 23:35:58 +08:00
										 |  |  |       $url = 'http://logbook.qrz.com/api'; // TODO: Move this to database
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       $post_data['KEY'] = $apikey; | 
					
						
							|  |  |  |       $post_data['ACTION'] = 'INSERT'; | 
					
						
							|  |  |  |       $post_data['ADIF'] = $adif; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-05 03:56:32 +08:00
										 |  |  |       if ($replaceoption) { | 
					
						
							|  |  |  |           $post_data['OPTION'] = 'REPLACE'; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-07 23:35:58 +08:00
										 |  |  |       $ch = curl_init( $url ); | 
					
						
							|  |  |  |       curl_setopt( $ch, CURLOPT_POST, true); | 
					
						
							|  |  |  |       curl_setopt( $ch, CURLOPT_POSTFIELDS, $post_data); | 
					
						
							|  |  |  |       curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1); | 
					
						
							|  |  |  |       curl_setopt( $ch, CURLOPT_HEADER, 0); | 
					
						
							|  |  |  |       curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-08 03:10:27 +08:00
										 |  |  |       $content = curl_exec($ch); | 
					
						
							|  |  |  |       if ($content){ | 
					
						
							| 
									
										
										
										
											2020-06-05 03:56:32 +08:00
										 |  |  |           if (stristr($content,'RESULT=OK') || stristr($content,'RESULT=REPLACE')) { | 
					
						
							| 
									
										
										
										
											2020-08-08 14:47:02 +08:00
										 |  |  |               $result['status'] = 'OK'; | 
					
						
							|  |  |  |               return $result; | 
					
						
							| 
									
										
										
										
											2020-05-08 03:10:27 +08:00
										 |  |  |           } | 
					
						
							|  |  |  |           else { | 
					
						
							| 
									
										
										
										
											2020-08-08 14:47:02 +08:00
										 |  |  |               $result['status'] = 'error'; | 
					
						
							|  |  |  |               $result['message'] = $content; | 
					
						
							|  |  |  |               return $result; | 
					
						
							| 
									
										
										
										
											2020-05-08 03:10:27 +08:00
										 |  |  |           } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       if(curl_errno($ch)){ | 
					
						
							| 
									
										
										
										
											2020-08-08 14:47:02 +08:00
										 |  |  |           $result['status'] = 'error'; | 
					
						
							|  |  |  |           $result['message'] = 'Curl error: '. curl_errno($ch); | 
					
						
							|  |  |  |           return $result; | 
					
						
							| 
									
										
										
										
											2020-05-08 03:10:27 +08:00
										 |  |  |       } | 
					
						
							|  |  |  |       curl_close($ch); | 
					
						
							| 
									
										
										
										
											2020-05-07 23:35:58 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-13 01:11:29 +08:00
										 |  |  |   /* | 
					
						
							|  |  |  |    * Function marks QSOs as uploaded to QRZ. | 
					
						
							|  |  |  |    * $primarykey is the unique id for that QSO in the logbook | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |     function mark_qrz_qsos_sent($primarykey) { | 
					
						
							|  |  |  |         $data = array( | 
					
						
							|  |  |  |          'COL_QRZCOM_QSO_UPLOAD_DATE' => date("Y-m-d H:i:s", strtotime("now")), | 
					
						
							|  |  |  |          'COL_QRZCOM_QSO_UPLOAD_STATUS' => 'Y', | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->db->where('COL_PRIMARY_KEY', $primarykey); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->db->update($this->config->item('table_name'), $data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-15 00:01:51 +08:00
										 |  |  |   /* Edit QSO */ | 
					
						
							|  |  |  |   function edit() { | 
					
						
							| 
									
										
										
										
											2022-01-21 02:30:50 +08:00
										 |  |  |     $qso = $this->get_qso($this->input->post('id'))->row(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-24 06:06:08 +08:00
										 |  |  |     $entity = $this->get_entity($this->input->post('dxcc_id')); | 
					
						
							| 
									
										
										
										
											2021-10-31 17:17:14 +08:00
										 |  |  |     $stationId = $this->input->post('station_profile'); | 
					
						
							| 
									
										
										
										
											2020-05-24 06:06:08 +08:00
										 |  |  |     $country = $entity['name']; | 
					
						
							| 
									
										
										
										
											2020-04-17 18:38:01 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-31 17:25:35 +08:00
										 |  |  |     // be sure that station belongs to user
 | 
					
						
							|  |  |  |     $CI =& get_instance(); | 
					
						
							|  |  |  |     $CI->load->model('Stations'); | 
					
						
							|  |  |  |     if (!$CI->Stations->check_station_is_accessible($stationId)) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-24 06:06:08 +08:00
										 |  |  |     $mode = $this->get_main_mode_if_submode($this->input->post('mode')); | 
					
						
							|  |  |  |     if ($mode == null) { | 
					
						
							|  |  |  |         $mode = $this->input->post('mode'); | 
					
						
							|  |  |  |         $submode = null; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         $submode = $this->input->post('mode'); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-11-20 00:17:34 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if($this->input->post('transmit_power')) { | 
					
						
							|  |  |  |       $txpower = $this->input->post('transmit_power'); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       $txpower = null; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-09-19 00:46:34 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if($this->input->post('stx')) { | 
					
						
							|  |  |  |       $stx_string = $this->input->post('stx'); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       $stx_string = null; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if($this->input->post('srx')) { | 
					
						
							|  |  |  |       $srx_string = $this->input->post('srx'); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       $srx_string = null; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-20 02:01:32 +08:00
										 |  |  | 	if (stristr($this->input->post('usa_county'), ',')) { | 
					
						
							|  |  |  | 		$uscounty = $this->input->post('usa_county'); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		$uscounty = $this->input->post('usa_state') .",".$this->input->post('usa_county'); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-21 02:30:50 +08:00
										 |  |  |     if ($this->input->post('qsl_sent')) { | 
					
						
							|  |  |  |         $qsl_sent = $this->input->post('qsl_sent'); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         $qsl_sent = 'N'; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ($this->input->post('qsl_recv')) { | 
					
						
							|  |  |  |         $qsl_recv = $this->input->post('qsl_recv'); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         $qsl_recv = 'N'; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ($qsl_sent == 'N') { | 
					
						
							|  |  |  |         $qslsdate = null; | 
					
						
							|  |  |  |     } elseif (!$qso->COL_QSLSDATE || $qso->COL_QSL_SENT != $qsl_sent) { | 
					
						
							|  |  |  |         $qslsdate = date('Y-m-d H:i:s'); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         $qslsdate = $qso->COL_QSLSDATE; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ($qsl_recv == 'N') { | 
					
						
							|  |  |  |         $qslrdate = null; | 
					
						
							|  |  |  |     } elseif (!$qso->COL_QSLRDATE || $qso->COL_QSL_RECV != $qsl_recv) { | 
					
						
							|  |  |  |         $qslrdate = date('Y-m-d H:i:s'); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         $qslrdate = $qso->COL_QSLRDATE; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-15 00:01:51 +08:00
										 |  |  |     $data = array( | 
					
						
							|  |  |  |        'COL_TIME_ON' => $this->input->post('time_on'), | 
					
						
							|  |  |  |        'COL_TIME_OFF' => $this->input->post('time_off'), | 
					
						
							| 
									
										
										
										
											2013-02-16 22:48:27 +08:00
										 |  |  |        'COL_CALL' => strtoupper(trim($this->input->post('callsign'))), | 
					
						
							| 
									
										
										
										
											2012-11-15 00:01:51 +08:00
										 |  |  |        'COL_BAND' => $this->input->post('band'), | 
					
						
							| 
									
										
										
										
											2020-10-19 04:43:59 +08:00
										 |  |  |        'COL_BAND_RX' => $this->input->post('band_rx'), | 
					
						
							| 
									
										
										
										
											2019-02-26 07:43:14 +08:00
										 |  |  |        'COL_FREQ' => $this->parse_frequency($this->input->post('freq')), | 
					
						
							| 
									
										
										
										
											2020-05-24 06:06:08 +08:00
										 |  |  |        'COL_MODE' => $mode, | 
					
						
							|  |  |  |        'COL_SUBMODE' => $submode, | 
					
						
							| 
									
										
										
										
											2012-11-15 00:01:51 +08:00
										 |  |  |        'COL_RST_RCVD' => $this->input->post('rst_recv'), | 
					
						
							|  |  |  |        'COL_RST_SENT' => $this->input->post('rst_sent'), | 
					
						
							| 
									
										
										
										
											2013-02-16 22:48:27 +08:00
										 |  |  |        'COL_GRIDSQUARE' => strtoupper(trim($this->input->post('locator'))), | 
					
						
							| 
									
										
										
										
											2018-12-31 23:43:21 +08:00
										 |  |  |        'COL_VUCC_GRIDS' => strtoupper(trim($this->input->post('vucc_grids'))), | 
					
						
							| 
									
										
										
										
											2012-11-15 00:01:51 +08:00
										 |  |  |        'COL_COMMENT' => $this->input->post('comment'), | 
					
						
							|  |  |  |        'COL_NAME' => $this->input->post('name'), | 
					
						
							| 
									
										
										
										
											2020-04-17 18:38:01 +08:00
										 |  |  |        'COL_COUNTRY' => $country, | 
					
						
							|  |  |  |        'COL_DXCC'=> $this->input->post('dxcc_id'), | 
					
						
							|  |  |  |        'COL_CQZ' => $this->input->post('cqz'), | 
					
						
							| 
									
										
										
										
											2012-11-15 00:01:51 +08:00
										 |  |  |        'COL_SAT_NAME' => $this->input->post('sat_name'), | 
					
						
							|  |  |  |        'COL_SAT_MODE' => $this->input->post('sat_mode'), | 
					
						
							| 
									
										
										
										
											2020-06-04 03:49:36 +08:00
										 |  |  |        'COL_NOTES' => $this->input->post('notes'), | 
					
						
							| 
									
										
										
										
											2022-01-21 02:30:50 +08:00
										 |  |  |        'COL_QSLSDATE' => $qslsdate, | 
					
						
							|  |  |  |        'COL_QSLRDATE' => $qslrdate, | 
					
						
							|  |  |  |        'COL_QSL_SENT' => $qsl_sent, | 
					
						
							|  |  |  |        'COL_QSL_RCVD' => $qsl_recv, | 
					
						
							| 
									
										
										
										
											2012-11-15 00:01:51 +08:00
										 |  |  |        'COL_QSL_SENT_VIA' => $this->input->post('qsl_sent_method'), | 
					
						
							|  |  |  |        'COL_QSL_RCVD_VIA' => $this->input->post('qsl_recv_method'), | 
					
						
							| 
									
										
										
										
											2013-02-12 08:55:11 +08:00
										 |  |  |        'COL_EQSL_QSL_SENT' => $this->input->post('eqsl_sent'), | 
					
						
							|  |  |  |        'COL_EQSL_QSL_RCVD' => $this->input->post('eqsl_recv'), | 
					
						
							| 
									
										
										
										
											2022-03-17 17:48:01 +08:00
										 |  |  |        'COL_QSLMSG' => $this->input->post('qslmsg'), | 
					
						
							| 
									
										
										
										
											2013-02-12 08:55:11 +08:00
										 |  |  |        'COL_LOTW_QSL_SENT' => $this->input->post('lotw_sent'), | 
					
						
							|  |  |  |        'COL_LOTW_QSL_RCVD' => $this->input->post('lotw_recv'), | 
					
						
							| 
									
										
										
										
											2012-11-15 00:01:51 +08:00
										 |  |  |        'COL_IOTA' => $this->input->post('iota_ref'), | 
					
						
							| 
									
										
										
										
											2019-06-14 01:35:14 +08:00
										 |  |  |        'COL_SOTA_REF' => $this->input->post('sota_ref'), | 
					
						
							| 
									
										
										
										
											2020-11-20 00:17:34 +08:00
										 |  |  |        'COL_TX_PWR' => $txpower, | 
					
						
							| 
									
										
										
										
											2020-11-18 05:29:06 +08:00
										 |  |  |        'COL_SIG' => $this->input->post('sig'), | 
					
						
							|  |  |  |        'COL_SIG_INFO' => $this->input->post('sig_info'), | 
					
						
							| 
									
										
										
										
											2019-06-25 15:07:42 +08:00
										 |  |  |        'COL_DARC_DOK' => $this->input->post('darc_dok'), | 
					
						
							| 
									
										
										
										
											2012-11-15 00:01:51 +08:00
										 |  |  |        'COL_QTH' => $this->input->post('qth'), | 
					
						
							| 
									
										
										
										
											2016-01-10 09:09:54 +08:00
										 |  |  |        'COL_PROP_MODE' => $this->input->post('prop_mode'), | 
					
						
							| 
									
										
										
										
											2019-02-26 07:43:14 +08:00
										 |  |  |        'COL_FREQ_RX' => $this->parse_frequency($this->input->post('freq_display_rx')), | 
					
						
							| 
									
										
										
										
											2012-11-15 00:01:51 +08:00
										 |  |  |        'COL_STX_STRING' => $this->input->post('stx_string'), | 
					
						
							| 
									
										
										
										
											2019-06-13 21:34:31 +08:00
										 |  |  |        'COL_SRX_STRING' => $this->input->post('srx_string'), | 
					
						
							| 
									
										
										
										
											2022-03-17 17:48:01 +08:00
										 |  |  |        'COL_STX' => $stx_string, | 
					
						
							|  |  |  |        'COL_SRX' => $srx_string, | 
					
						
							|  |  |  |        'COL_CONTEST_ID' => $this->input->post('contest_name'), | 
					
						
							| 
									
										
										
										
											2019-06-30 23:41:03 +08:00
										 |  |  |        'COL_QSL_VIA' => $this->input->post('qsl_via_callsign'), | 
					
						
							| 
									
										
										
										
											2021-10-31 17:17:14 +08:00
										 |  |  |        'station_id' => $stationId, | 
					
						
							| 
									
										
										
										
											2019-10-06 23:08:11 +08:00
										 |  |  |        'COL_OPERATOR' => $this->input->post('operator_callsign'), | 
					
						
							| 
									
										
										
										
											2021-01-31 22:27:56 +08:00
										 |  |  |        'COL_STATE' =>$this->input->post('usa_state'), | 
					
						
							| 
									
										
										
										
											2021-09-20 02:01:32 +08:00
										 |  |  |        'COL_CNTY' => $uscounty | 
					
						
							| 
									
										
										
										
											2012-11-15 00:01:51 +08:00
										 |  |  |     ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-08 03:10:27 +08:00
										 |  |  |     if ($this->exists_qrz_api_key($data['station_id'])) { | 
					
						
							|  |  |  |         $data['COL_QRZCOM_QSO_UPLOAD_STATUS'] = 'M'; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-15 00:01:51 +08:00
										 |  |  |     $this->db->where('COL_PRIMARY_KEY', $this->input->post('id')); | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  |     $this->db->update($this->config->item('table_name'), $data); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-15 00:01:51 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-16 02:20:20 +08:00
										 |  |  |   /* QSL received */ | 
					
						
							|  |  |  |   function qsl_rcvd() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $data = array( | 
					
						
							| 
									
										
										
										
											2022-01-21 02:30:50 +08:00
										 |  |  |        'COL_QSLRDATE' => date('Y-m-d H:i:s'), | 
					
						
							| 
									
										
										
										
											2019-06-16 02:20:20 +08:00
										 |  |  |        '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-15 00:01:51 +08:00
										 |  |  |   /* Return last 10 QSOs */ | 
					
						
							|  |  |  |   function last_ten() { | 
					
						
							| 
									
										
										
										
											2021-11-15 00:50:11 +08:00
										 |  |  |     $CI =& get_instance(); | 
					
						
							|  |  |  |     $CI->load->model('logbooks_model'); | 
					
						
							|  |  |  |     $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-24 14:51:30 +08:00
										 |  |  |     $this->db->select('COL_CALL, COL_BAND, COL_TIME_ON, COL_RST_RCVD, COL_RST_SENT, COL_MODE, COL_SUBMODE, COL_NAME, COL_COUNTRY, COL_PRIMARY_KEY, COL_SAT_NAME'); | 
					
						
							| 
									
										
										
										
											2021-11-15 00:50:11 +08:00
										 |  |  |     $this->db->where_in('station_id', $logbooks_locations_array); | 
					
						
							| 
									
										
										
										
											2012-11-15 00:01:51 +08:00
										 |  |  |     $this->db->order_by("COL_TIME_ON", "desc"); | 
					
						
							|  |  |  |     $this->db->limit(10); | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-15 00:01:51 +08:00
										 |  |  |     return $this->db->get($this->config->item('table_name')); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-15 00:01:51 +08:00
										 |  |  |   /* Show custom number of qsos */ | 
					
						
							|  |  |  |   function last_custom($num) { | 
					
						
							| 
									
										
										
										
											2021-11-15 00:50:11 +08:00
										 |  |  |     $CI =& get_instance(); | 
					
						
							|  |  |  |     $CI->load->model('logbooks_model'); | 
					
						
							|  |  |  |     $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-15 06:48:39 +08:00
										 |  |  |     if(!empty($logbooks_locations_array)) { | 
					
						
							|  |  |  |       $this->db->select('COL_CALL, COL_BAND, COL_TIME_ON, COL_RST_RCVD, COL_RST_SENT, COL_MODE, COL_SUBMODE, COL_NAME, COL_COUNTRY, COL_PRIMARY_KEY, COL_SAT_NAME'); | 
					
						
							|  |  |  |       $this->db->where_in('station_id', $logbooks_locations_array); | 
					
						
							|  |  |  |       $this->db->order_by("COL_TIME_ON", "desc"); | 
					
						
							|  |  |  |       $this->db->limit($num); | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-15 06:48:39 +08:00
										 |  |  |       return $this->db->get($this->config->item('table_name')); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       return false; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-11-15 00:01:51 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-07 06:58:26 +08:00
										 |  |  |   /* | 
					
						
							|  |  |  |   * | 
					
						
							|  |  |  |   * Function: call_lookup_result | 
					
						
							|  |  |  |   * | 
					
						
							|  |  |  |   * Usage: Callsign lookup data for the QSO panel and API/callsign_lookup | 
					
						
							|  |  |  |   * | 
					
						
							|  |  |  |   */ | 
					
						
							|  |  |  |   function call_lookup_result($callsign) { | 
					
						
							| 
									
										
										
										
											2020-04-07 07:07:17 +08:00
										 |  |  |     $this->db->select('COL_CALL, COL_NAME, COL_QSL_VIA, COL_GRIDSQUARE, COL_QTH, COL_IOTA, COL_TIME_ON, COL_STATE, COL_CNTY'); | 
					
						
							| 
									
										
										
										
											2020-04-07 06:58:26 +08:00
										 |  |  |     $this->db->where('COL_CALL', $callsign); | 
					
						
							|  |  |  |     $where = "COL_NAME != \"\""; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $this->db->where($where); | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-07 06:58:26 +08:00
										 |  |  |     $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(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return $data; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* Callsign QRA */ | 
					
						
							| 
									
										
										
										
											2019-02-26 21:19:52 +08: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 18:15:05 +08: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; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-08 20:40:07 +08:00
										 |  |  |     function call_state($callsign) { | 
					
						
							|  |  |  |         $this->db->select('COL_CALL, COL_STATE'); | 
					
						
							|  |  |  |         $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_state = $data->COL_STATE; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $qsl_state; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-26 21:19:52 +08: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-15 00:01:51 +08:00
										 |  |  |   /* Return QSO Info */ | 
					
						
							|  |  |  |   function qso_info($id) { | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  |     $this->db->where('COL_PRIMARY_KEY', $id); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-15 00:01:51 +08:00
										 |  |  |     return $this->db->get($this->config->item('table_name')); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-11-16 03:38:17 +08:00
										 |  |  |    | 
					
						
							|  |  |  |    | 
					
						
							| 
									
										
										
										
											2022-01-21 02:30:50 +08:00
										 |  |  |   // Set Paper to received
 | 
					
						
							| 
									
										
										
										
											2021-02-09 04:46:53 +08:00
										 |  |  |   function paperqsl_update($qso_id, $method) { | 
					
						
							| 
									
										
										
										
											2021-11-16 03:38:17 +08:00
										 |  |  |        | 
					
						
							|  |  |  |       $data = array( | 
					
						
							| 
									
										
										
										
											2022-01-21 02:30:50 +08:00
										 |  |  |           'COL_QSLRDATE' => date('Y-m-d H:i:s'), | 
					
						
							| 
									
										
										
										
											2021-11-16 03:38:17 +08:00
										 |  |  |           '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); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-02-09 04:46:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-16 22:29:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-16 03:38:17 +08:00
										 |  |  |   // Set Paper to sent
 | 
					
						
							|  |  |  |   function paperqsl_update_sent($qso_id, $method) { | 
					
						
							|  |  |  |        | 
					
						
							|  |  |  |       $data = array( | 
					
						
							| 
									
										
										
										
											2022-01-21 02:30:50 +08:00
										 |  |  |           'COL_QSLSDATE' => date('Y-m-d H:i:s'), | 
					
						
							| 
									
										
										
										
											2021-11-16 03:38:17 +08:00
										 |  |  |           'COL_QSL_SENT' => 'Y', | 
					
						
							|  |  |  |           'COL_QSL_SENT_VIA' => $method | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |        | 
					
						
							|  |  |  |       $this->db->where('COL_PRIMARY_KEY', $qso_id); | 
					
						
							|  |  |  |        | 
					
						
							|  |  |  |       $this->db->update($this->config->item('table_name'), $data); | 
					
						
							| 
									
										
										
										
											2019-06-16 22:29:31 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-22 23:20:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-11 23:05:49 +08:00
										 |  |  |   // Set Paper to requested
 | 
					
						
							|  |  |  |   function paperqsl_requested($qso_id, $method) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $data = array( | 
					
						
							| 
									
										
										
										
											2022-01-21 02:30:50 +08:00
										 |  |  |          'COL_QSLSDATE' => date('Y-m-d H:i:s'), | 
					
						
							| 
									
										
										
										
											2021-06-11 23:05:49 +08:00
										 |  |  |          'COL_QSL_SENT' => 'R' | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $this->db->where('COL_PRIMARY_KEY', $qso_id); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $this->db->update($this->config->item('table_name'), $data); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-11 23:14:34 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   function paperqsl_ignore($qso_id, $method) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $data = array( | 
					
						
							| 
									
										
										
										
											2022-01-21 02:30:50 +08:00
										 |  |  |          'COL_QSLSDATE' => date('Y-m-d H:i:s'), | 
					
						
							| 
									
										
										
										
											2021-06-11 23:14:34 +08:00
										 |  |  |          'COL_QSL_SENT' => 'I' | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $this->db->where('COL_PRIMARY_KEY', $qso_id); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $this->db->update($this->config->item('table_name'), $data); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-22 23:16:49 +08:00
										 |  |  |   function get_qsos_for_printing($station_id2 = null) { | 
					
						
							| 
									
										
										
										
											2021-07-22 23:20:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-28 05:04:49 +08:00
										 |  |  | 	$CI =& get_instance(); | 
					
						
							|  |  |  |     $CI->load->model('Stations'); | 
					
						
							|  |  |  |     $station_id = $CI->Stations->find_active(); | 
					
						
							| 
									
										
										
										
											2021-02-09 04:46:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-22 23:16:49 +08:00
										 |  |  |     $sql = 'SELECT | 
					
						
							|  |  |  | 				STATION_CALLSIGN, | 
					
						
							|  |  |  | 				COL_PRIMARY_KEY, | 
					
						
							|  |  |  | 				COL_CALL, | 
					
						
							|  |  |  | 				COL_QSL_VIA, | 
					
						
							|  |  |  | 				COL_TIME_ON, | 
					
						
							|  |  |  | 				COL_MODE, | 
					
						
							|  |  |  | 				COL_SUBMODE, | 
					
						
							|  |  |  | 				COL_FREQ, | 
					
						
							|  |  |  | 				UPPER(COL_BAND) as COL_BAND, | 
					
						
							|  |  |  | 				COL_RST_SENT, | 
					
						
							|  |  |  | 				COL_SAT_NAME, | 
					
						
							|  |  |  | 				COL_SAT_MODE, | 
					
						
							|  |  |  | 				COL_QSL_RCVD, | 
					
						
							|  |  |  | 				COL_COMMENT, | 
					
						
							| 
									
										
										
										
											2021-08-25 02:10:07 +08:00
										 |  |  | 				(select adif from dxcc_prefixes where  (CASE WHEN COL_QSL_VIA != \'\' THEN COL_QSL_VIA ELSE COL_CALL END) like concat(dxcc_prefixes.`call`,\'%\') order by end limit 1) as ADIF, | 
					
						
							|  |  |  | 				(select entity from dxcc_prefixes where  (CASE WHEN COL_QSL_VIA != \'\' THEN COL_QSL_VIA ELSE COL_CALL END) like concat(dxcc_prefixes.`call`,\'%\') order by end limit 1) as ENTITY, | 
					
						
							|  |  |  |        			(CASE WHEN COL_QSL_VIA != \'\' THEN COL_QSL_VIA ELSE COL_CALL END) AS COL_ROUTING | 
					
						
							|  |  |  | 			FROM '.$this->config->item('table_name').' thcv | 
					
						
							|  |  |  | 				join station_profile on thcv.station_id = station_profile.station_id | 
					
						
							|  |  |  | 			WHERE | 
					
						
							|  |  |  | 				COL_QSL_SENT in (\'R\', \'Q\')'; | 
					
						
							| 
									
										
										
										
											2021-07-22 23:16:49 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if ($station_id2 == NULL) { | 
					
						
							| 
									
										
										
										
											2021-08-25 02:10:07 +08:00
										 |  |  |     	$sql .= ' and thcv.station_id = ' . $station_id; | 
					
						
							|  |  |  | 	} else if ($station_id2 != 'All') { | 
					
						
							|  |  |  | 		$sql .= ' and thcv.station_id = ' . $station_id2; | 
					
						
							| 
									
										
										
										
											2021-07-22 23:16:49 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-18 05:30:20 +08:00
										 |  |  | 	// always filter user. this ensures that even if the station_id is from another user no inaccesible QSOs will be returned
 | 
					
						
							|  |  |  | 	$sql .= ' and station_profile.user_id = ' . $this->session->userdata('user_id'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-25 02:10:07 +08:00
										 |  |  | 	$sql .= ' ORDER BY ADIF, COL_ROUTING'; | 
					
						
							| 
									
										
										
										
											2021-07-22 23:16:49 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     $query = $this->db->query($sql); | 
					
						
							| 
									
										
										
										
											2019-08-29 03:13:24 +08:00
										 |  |  |     return $query; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-06-16 22:29:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-18 22:19:05 +08:00
										 |  |  |   function get_qsos($num, $offset, $StationLocationsArray = null) { | 
					
						
							| 
									
										
										
										
											2022-02-18 21:30:26 +08:00
										 |  |  |     if($StationLocationsArray == null) { | 
					
						
							|  |  |  |       $CI =& get_instance(); | 
					
						
							|  |  |  |       $CI->load->model('logbooks_model'); | 
					
						
							|  |  |  |       $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       $logbooks_locations_array = $StationLocationsArray; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-10-17 17:25:01 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-05 23:52:42 +08: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_SUBMODE, '.$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.*');
 | 
					
						
							| 
									
										
										
										
											2019-09-25 05:54:37 +08:00
										 |  |  |     $this->db->from($this->config->item('table_name')); | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-25 06:10:59 +08:00
										 |  |  |     $this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id'); | 
					
						
							| 
									
										
										
										
											2021-10-17 17:25:01 +08:00
										 |  |  |     $this->db->where_in('station_profile.station_id', $logbooks_locations_array); | 
					
						
							| 
									
										
										
										
											2019-09-25 05:54:37 +08:00
										 |  |  |     $this->db->order_by(''.$this->config->item('table_name').'.COL_TIME_ON', "desc"); | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-25 05:54:37 +08:00
										 |  |  |     $this->db->limit($num); | 
					
						
							|  |  |  |     $this->db->offset($offset); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return $this->db->get(); | 
					
						
							| 
									
										
										
										
											2012-11-15 00:01:51 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-25 06:10:59 +08: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 20:05:28 +08:00
										 |  |  |   function get_clublog_qsos($station_id){ | 
					
						
							| 
									
										
										
										
											2020-11-24 02:52:30 +08:00
										 |  |  |     $this->db->where($this->config->item('table_name').'.station_id', $station_id); | 
					
						
							| 
									
										
										
										
											2019-06-19 23:57:33 +08:00
										 |  |  |     $this->db->where("COL_CLUBLOG_QSO_UPLOAD_STATUS", null); | 
					
						
							| 
									
										
										
										
											2019-06-20 22:26:36 +08:00
										 |  |  |     $this->db->or_where("COL_CLUBLOG_QSO_UPLOAD_STATUS", ""); | 
					
						
							| 
									
										
										
										
											2019-06-19 21:48:06 +08:00
										 |  |  |     $this->db->or_where("COL_CLUBLOG_QSO_UPLOAD_STATUS", "N"); | 
					
						
							| 
									
										
										
										
											2020-11-24 02:52:30 +08:00
										 |  |  |     $this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id'); | 
					
						
							| 
									
										
										
										
											2019-06-19 21:48:06 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     $query = $this->db->get($this->config->item('table_name')); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return $query; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-13 01:11:29 +08:00
										 |  |  |     /* | 
					
						
							|  |  |  |      * Function returns the QSOs from the logbook, which have not been either marked as uploaded to qrz, or has been modified with an edit | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     function get_qrz_qsos($station_id){ | 
					
						
							| 
									
										
										
										
											2020-11-21 21:25:02 +08:00
										 |  |  |         $sql = 'select * from ' . $this->config->item('table_name') . ' thcv ' . | 
					
						
							|  |  |  |             ' join station_profile on thcv.station_id = station_profile.station_id' . | 
					
						
							|  |  |  |             ' where thcv.station_id = ' . $station_id . | 
					
						
							| 
									
										
										
										
											2020-05-21 01:43:13 +08:00
										 |  |  |             ' and (COL_QRZCOM_QSO_UPLOAD_STATUS is NULL | 
					
						
							| 
									
										
										
										
											2020-05-13 01:11:29 +08:00
										 |  |  |             or COL_QRZCOM_QSO_UPLOAD_STATUS = "" | 
					
						
							|  |  |  |             or COL_QRZCOM_QSO_UPLOAD_STATUS = "M" | 
					
						
							|  |  |  |             or COL_QRZCOM_QSO_UPLOAD_STATUS = "N")'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $query = $this->db->query($sql); | 
					
						
							| 
									
										
										
										
											2020-11-21 21:25:02 +08:00
										 |  |  |         return $query; | 
					
						
							| 
									
										
										
										
											2020-05-13 01:11:29 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-11-21 21:25:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-13 01:11:29 +08:00
										 |  |  |     /* | 
					
						
							|  |  |  |      * Function returns all the station_id's with QRZ API Key's | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     function get_station_id_with_qrz_api() { | 
					
						
							| 
									
										
										
										
											2021-11-26 03:43:31 +08:00
										 |  |  |         $sql = 'select station_id, qrzapikey from station_profile | 
					
						
							| 
									
										
										
										
											2020-05-13 01:11:29 +08:00
										 |  |  |             where coalesce(qrzapikey, "") <> ""'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $query = $this->db->query($sql); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-26 03:43:31 +08:00
										 |  |  |         $result = $query->result(); | 
					
						
							| 
									
										
										
										
											2020-05-13 01:11:29 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if ($result) { | 
					
						
							|  |  |  |             return $result; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |             return null; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-17 22:20:32 +08:00
										 |  |  |   function get_last_qsos($num, $StationLocationsArray = null) { | 
					
						
							| 
									
										
										
										
											2019-09-26 19:49:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-17 22:20:32 +08:00
										 |  |  |     if($StationLocationsArray == null) { | 
					
						
							|  |  |  |       $CI =& get_instance(); | 
					
						
							|  |  |  |       $CI->load->model('logbooks_model'); | 
					
						
							|  |  |  |       $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       $logbooks_locations_array = $StationLocationsArray; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-09-26 19:49:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-07 03:53:36 +08:00
										 |  |  |     if ($logbooks_locations_array) { | 
					
						
							|  |  |  |       //$this->db->select('COL_CALL, COL_BAND, COL_TIME_ON, COL_RST_RCVD, COL_RST_SENT, COL_MODE, COL_SUBMODE, COL_NAME, COL_COUNTRY, COL_PRIMARY_KEY, COL_SAT_NAME, COL_STX_STRING, COL_SRX_STRING, COL_IOTA, COL_STATE, COL_GRIDSQUARE');
 | 
					
						
							| 
									
										
										
										
											2022-02-22 05:53:09 +08:00
										 |  |  |       $this->db->where_in($this->config->item('table_name').'.station_id', $logbooks_locations_array); | 
					
						
							|  |  |  |       $this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id'); | 
					
						
							| 
									
										
										
										
											2021-11-07 03:53:36 +08:00
										 |  |  |       $this->db->order_by("COL_TIME_ON", "desc"); | 
					
						
							|  |  |  |       $this->db->limit($num); | 
					
						
							|  |  |  |       $query = $this->db->get($this->config->item('table_name')); | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |       return $query; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       return null; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-15 00:01:51 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-09-30 21:45:04 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-06 20:21:35 +08:00
										 |  |  |     /* Get all QSOs with a valid grid for use in the KML export */ | 
					
						
							|  |  |  |     function kml_get_all_qsos($band, $mode, $dxcc, $cqz, $propagation, $fromdate, $todate) { | 
					
						
							| 
									
										
										
										
											2021-11-16 02:59:26 +08:00
										 |  |  |         $CI =& get_instance(); | 
					
						
							|  |  |  |         $CI->load->model('logbooks_model'); | 
					
						
							|  |  |  |         $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-24 14:51:30 +08:00
										 |  |  |         $this->db->select('COL_CALL, COL_BAND, COL_TIME_ON, COL_RST_RCVD, COL_RST_SENT, COL_MODE, COL_SUBMODE, COL_NAME, COL_COUNTRY, COL_PRIMARY_KEY, COL_SAT_NAME, COL_GRIDSQUARE'); | 
					
						
							| 
									
										
										
										
											2021-11-16 02:59:26 +08:00
										 |  |  |         $this->db->where_in('station_id', $logbooks_locations_array); | 
					
						
							| 
									
										
										
										
											2021-11-12 19:45:33 +08:00
										 |  |  |         $this->db->where("coalesce(COL_GRIDSQUARE, '') <> ''"); | 
					
						
							| 
									
										
										
										
											2020-12-06 20:21:35 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if ($band != 'All') { | 
					
						
							|  |  |  |             if ($band == 'SAT') { | 
					
						
							|  |  |  |                 $this->db->where('COL_PROP_MODE = \'' . $band . '\''); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else { | 
					
						
							|  |  |  |                 $this->db->where('COL_PROP_MODE != \'SAT\''); | 
					
						
							|  |  |  |                 $this->db->where('COL_BAND = \'' . $band .'\''); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if ($mode != 'All') { | 
					
						
							|  |  |  |             $this->db->where('COL_MODE = \'' . $mode . '\''); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if ($dxcc != 'All') { | 
					
						
							|  |  |  |             $this->db->where('COL_DXCC = ' . $dxcc); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if ($cqz != 'All') { | 
					
						
							|  |  |  |             $this->db->where('COL_CQZ = ' . $cqz); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if ($propagation != 'All') { | 
					
						
							|  |  |  |             $this->db->where('COL_PROP_MODE = ' . $propagation); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // If date is set, we format the date and add it to the where-statement
 | 
					
						
							|  |  |  |         if ($fromdate != "") { | 
					
						
							|  |  |  |             $from = DateTime::createFromFormat('d/m/Y', $fromdate); | 
					
						
							|  |  |  |             $from = $from->format('Y-m-d'); | 
					
						
							|  |  |  |             $this->db->where("date(".$this->config->item('table_name').".COL_TIME_ON) >= '".$from."'"); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if ($todate != "") { | 
					
						
							|  |  |  |             $to = DateTime::createFromFormat('d/m/Y', $todate); | 
					
						
							|  |  |  |             $to = $to->format('Y-m-d'); | 
					
						
							|  |  |  |             $this->db->where("date(".$this->config->item('table_name').".COL_TIME_ON) <= '".$to."'"); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-30 23:50:12 +08:00
										 |  |  |         $query = $this->db->get($this->config->item('table_name')); | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-30 23:50:12 +08:00
										 |  |  |         return $query; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-30 21:45:04 +08:00
										 |  |  |     function get_date_qsos($date) { | 
					
						
							| 
									
										
										
										
											2020-05-24 14:51:30 +08:00
										 |  |  |         $this->db->select('COL_CALL, COL_BAND, COL_TIME_ON, COL_RST_RCVD, COL_RST_SENT, COL_MODE, COL_SUBMODE, COL_NAME, COL_COUNTRY, COL_PRIMARY_KEY, COL_SAT_NAME'); | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  |         $this->db->order_by("COL_TIME_ON", "desc"); | 
					
						
							| 
									
										
										
										
											2011-09-30 21:45:04 +08: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-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-30 21:45:04 +08:00
										 |  |  |         return $query; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08: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 19:42:19 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     $CI =& get_instance(); | 
					
						
							| 
									
										
										
										
											2021-09-08 20:32:53 +08:00
										 |  |  |     $CI->load->model('logbooks_model'); | 
					
						
							|  |  |  |     $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-15 01:46:09 +08:00
										 |  |  |     if (!$logbooks_locations_array) { | 
					
						
							|  |  |  |       return null; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-09-08 20:32:53 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     $this->db->select('DATE_FORMAT(COL_TIME_ON, \'%Y\') as \'year\',COUNT(COL_PRIMARY_KEY) as \'total\'', FALSE); | 
					
						
							|  |  |  |     $this->db->where_in('station_id', $logbooks_locations_array); | 
					
						
							|  |  |  |     $this->db->group_by('DATE_FORMAT(COL_TIME_ON, \'%Y\')'); | 
					
						
							|  |  |  |     $this->db->order_by('year', 'ASC'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $query = $this->db->get($this->config->item('table_name')); | 
					
						
							| 
									
										
										
										
											2019-09-26 19:42:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08:00
										 |  |  |     return $query; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-30 21:45:04 +08:00
										 |  |  |     /* Return total number of qsos */ | 
					
						
							| 
									
										
										
										
											2022-02-17 22:20:32 +08:00
										 |  |  |     function total_qsos($StationLocationsArray = null) { | 
					
						
							|  |  |  |       if($StationLocationsArray == null) { | 
					
						
							|  |  |  |         $CI =& get_instance(); | 
					
						
							|  |  |  |         $CI->load->model('logbooks_model'); | 
					
						
							|  |  |  |         $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         $logbooks_locations_array = $StationLocationsArray; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-09-26 19:42:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-07 03:53:36 +08:00
										 |  |  |       if ($logbooks_locations_array) { | 
					
						
							|  |  |  |         $this->db->select('COUNT( * ) as count', FALSE); | 
					
						
							|  |  |  |         $this->db->where_in('station_id', $logbooks_locations_array); | 
					
						
							|  |  |  |         $query = $this->db->get($this->config->item('table_name')); | 
					
						
							| 
									
										
										
										
											2011-06-17 20:52:00 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if ($query->num_rows() > 0) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2021-11-07 03:53:36 +08:00
										 |  |  |           foreach ($query->result() as $row) | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |             return $row->count; | 
					
						
							|  |  |  |           } | 
					
						
							| 
									
										
										
										
											2011-06-17 20:52:00 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-11-07 03:53:36 +08:00
										 |  |  |       } else { | 
					
						
							|  |  |  |         return null; | 
					
						
							| 
									
										
										
										
											2021-09-08 20:32:53 +08:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2011-06-17 20:52:00 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-30 21:45:04 +08:00
										 |  |  |     /* Return number of QSOs had today */ | 
					
						
							| 
									
										
										
										
											2022-02-17 22:20:32 +08:00
										 |  |  |     function todays_qsos($StationLocationsArray = null) { | 
					
						
							|  |  |  |       if($StationLocationsArray == null) { | 
					
						
							|  |  |  |         $CI =& get_instance(); | 
					
						
							|  |  |  |         $CI->load->model('logbooks_model'); | 
					
						
							|  |  |  |         $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         $logbooks_locations_array = $StationLocationsArray; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-07 03:53:36 +08:00
										 |  |  |       if ($logbooks_locations_array) { | 
					
						
							| 
									
										
										
										
											2011-06-17 20:52:00 +08:00
										 |  |  |         $morning = date('Y-m-d 00:00:00'); | 
					
						
							|  |  |  |         $night = date('Y-m-d 23:59:59'); | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-07 03:53:36 +08:00
										 |  |  |         $this->db->select('COUNT( * ) as count', FALSE); | 
					
						
							|  |  |  |         $this->db->where_in('station_id', $logbooks_locations_array); | 
					
						
							|  |  |  |         $this->db->where('COL_TIME_ON >=', $morning); | 
					
						
							|  |  |  |         $this->db->where('COL_TIME_ON <=', $night); | 
					
						
							|  |  |  |         $query = $this->db->get($this->config->item('table_name')); | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-17 20:52:00 +08:00
										 |  |  |         if ($query->num_rows() > 0) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2021-11-07 03:53:36 +08:00
										 |  |  |           foreach ($query->result() as $row) | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |             return $row->count; | 
					
						
							|  |  |  |           } | 
					
						
							| 
									
										
										
										
											2011-06-17 20:52:00 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-11-07 03:53:36 +08:00
										 |  |  |       } else { | 
					
						
							|  |  |  |         return null; | 
					
						
							| 
									
										
										
										
											2021-09-08 20:32:53 +08:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2021-11-07 03:53:36 +08:00
										 |  |  |       | 
					
						
							| 
									
										
										
										
											2011-06-17 20:52:00 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-30 21:45:04 +08:00
										 |  |  |     /* Return QSOs over a period of days */ | 
					
						
							| 
									
										
										
										
											2011-09-22 05:17:24 +08:00
										 |  |  |     function map_week_qsos($start, $end) { | 
					
						
							| 
									
										
										
										
											2019-09-26 19:49:50 +08:00
										 |  |  |         $CI =& get_instance(); | 
					
						
							| 
									
										
										
										
											2021-09-28 18:21:12 +08:00
										 |  |  |         $CI->load->model('logbooks_model'); | 
					
						
							|  |  |  |         $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-22 05:17:24 +08:00
										 |  |  |         $this->db->where("COL_TIME_ON BETWEEN '".$start."' AND '".$end."'"); | 
					
						
							| 
									
										
										
										
											2021-09-28 18:21:12 +08:00
										 |  |  |         $this->db->where_in('station_id', $logbooks_locations_array); | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  |         $this->db->order_by("COL_TIME_ON", "ASC"); | 
					
						
							| 
									
										
										
										
											2011-09-22 05:17:24 +08:00
										 |  |  |         $query = $this->db->get($this->config->item('table_name')); | 
					
						
							| 
									
										
										
										
											2011-08-24 00:12:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $query; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-09-30 21:45:04 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-14 18:37:06 +08:00
										 |  |  |     /* used to return custom qsos requires start, end date plus a band */ | 
					
						
							|  |  |  |     function map_custom_qsos($start, $end, $band) { | 
					
						
							| 
									
										
										
										
											2021-09-18 23:59:19 +08:00
										 |  |  | 		$CI =& get_instance(); | 
					
						
							|  |  |  | 		$CI->load->model('logbooks_model'); | 
					
						
							|  |  |  | 		$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							| 
									
										
										
										
											2021-07-14 18:37:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-15 00:17:20 +08:00
										 |  |  |     if (!$logbooks_locations_array) { | 
					
						
							|  |  |  |       return null; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-14 18:37:06 +08:00
										 |  |  |       $this->db->where("COL_TIME_ON BETWEEN '".$start."' AND '".$end."'"); | 
					
						
							| 
									
										
										
										
											2021-09-18 23:59:19 +08:00
										 |  |  |       $this->db->where_in("station_id", $logbooks_locations_array); | 
					
						
							| 
									
										
										
										
											2021-07-14 18:37:06 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       if($band != "All" && $band != "SAT") { | 
					
						
							|  |  |  |         $this->db->where("COL_BAND", $band); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if ($band == "SAT") { | 
					
						
							|  |  |  |         $this->db->where("COL_PROP_MODE", "SAT"); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       $this->db->order_by("COL_TIME_ON", "ASC"); | 
					
						
							|  |  |  |       $query = $this->db->get($this->config->item('table_name')); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       return $query; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-30 21:45:04 +08:00
										 |  |  |     /* Returns QSOs for the date sent eg 2011-09-30 */ | 
					
						
							|  |  |  |     function map_day($date) { | 
					
						
							| 
									
										
										
										
											2019-09-26 19:49:50 +08:00
										 |  |  |         $CI =& get_instance(); | 
					
						
							| 
									
										
										
										
											2021-09-28 18:21:12 +08:00
										 |  |  |         $CI->load->model('logbooks_model'); | 
					
						
							|  |  |  |         $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-30 21:45:04 +08:00
										 |  |  |         $start = $date." 00:00:00"; | 
					
						
							|  |  |  |         $end = $date." 23:59:59"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->db->where("COL_TIME_ON BETWEEN '".$start."' AND '".$end."'"); | 
					
						
							| 
									
										
										
										
											2021-09-28 18:21:12 +08:00
										 |  |  |         $this->db->where_in('station_id', $logbooks_locations_array); | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  |         $this->db->order_by("COL_TIME_ON", "ASC"); | 
					
						
							| 
									
										
										
										
											2011-09-30 21:45:04 +08:00
										 |  |  |         $query = $this->db->get($this->config->item('table_name')); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $query; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-30 21:45:04 +08:00
										 |  |  |     // Return QSOs made during the current month
 | 
					
						
							| 
									
										
										
										
											2022-02-17 22:20:32 +08:00
										 |  |  |     function month_qsos($StationLocationsArray = null) { | 
					
						
							|  |  |  |       if($StationLocationsArray == null) {  | 
					
						
							|  |  |  |         $CI =& get_instance(); | 
					
						
							|  |  |  |         $CI->load->model('logbooks_model'); | 
					
						
							|  |  |  |         $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         $logbooks_locations_array = $StationLocationsArray; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-09-26 19:42:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-07 03:53:36 +08:00
										 |  |  |       if ($logbooks_locations_array) { | 
					
						
							| 
									
										
										
										
											2019-09-26 19:42:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-17 20:52:00 +08:00
										 |  |  |         $morning = date('Y-m-01 00:00:00'); | 
					
						
							| 
									
										
										
										
											2020-03-31 22:27:29 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $date = new DateTime('now'); | 
					
						
							|  |  |  |         $date->modify('last day of this month'); | 
					
						
							| 
									
										
										
										
											2021-02-09 04:46:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-31 22:27:29 +08:00
										 |  |  |         $night = $date->format('Y-m-d')." 23:59:59"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-08 20:32:53 +08:00
										 |  |  |         $this->db->select('COUNT( * ) as count', FALSE); | 
					
						
							|  |  |  |         $this->db->where_in('station_id', $logbooks_locations_array); | 
					
						
							|  |  |  |         $this->db->where('COL_TIME_ON >=', $morning); | 
					
						
							|  |  |  |         $this->db->where('COL_TIME_ON <=', $night); | 
					
						
							|  |  |  |         $query = $this->db->get($this->config->item('table_name')); | 
					
						
							| 
									
										
										
										
											2011-06-17 20:52:00 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if ($query->num_rows() > 0) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             foreach ($query->result() as $row) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                  return $row->count; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-11-07 03:53:36 +08:00
										 |  |  |       } else { | 
					
						
							|  |  |  |         return null; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2011-06-17 20:52:00 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-08 00:32:12 +08:00
										 |  |  |     /* Return QSOs for the year for the active profile */ | 
					
						
							|  |  |  |     function map_all_qsos_for_active_station_profile() { | 
					
						
							|  |  |  |       $CI =& get_instance(); | 
					
						
							|  |  |  |       $CI->load->model('Stations'); | 
					
						
							|  |  |  |       $station_id = $CI->Stations->find_active(); | 
					
						
							| 
									
										
										
										
											2021-02-09 04:46:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-08 00:32:12 +08:00
										 |  |  |       $this->db->where("station_id", $station_id); | 
					
						
							|  |  |  |       $this->db->order_by("COL_TIME_ON", "ASC"); | 
					
						
							|  |  |  |       $query = $this->db->get($this->config->item('table_name')); | 
					
						
							| 
									
										
										
										
											2021-02-09 04:46:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-08 00:32:12 +08:00
										 |  |  |       return $query; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-02-09 04:46:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-08 00:32:12 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-30 21:45:04 +08:00
										 |  |  |     /* Return QSOs made during the current Year */ | 
					
						
							| 
									
										
										
										
											2022-02-17 22:20:32 +08:00
										 |  |  |     function year_qsos($StationLocationsArray = null) { | 
					
						
							| 
									
										
										
										
											2011-06-17 20:52:00 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-17 22:20:32 +08:00
										 |  |  |       if($StationLocationsArray == null) { | 
					
						
							|  |  |  |         $CI =& get_instance(); | 
					
						
							|  |  |  |         $CI->load->model('logbooks_model'); | 
					
						
							|  |  |  |         $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         $logbooks_locations_array = $StationLocationsArray; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-09-26 19:42:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-07 03:53:36 +08:00
										 |  |  |       if ($logbooks_locations_array) { | 
					
						
							| 
									
										
										
										
											2019-09-26 19:42:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-17 20:52:00 +08:00
										 |  |  |         $morning = date('Y-01-01 00:00:00'); | 
					
						
							|  |  |  |         $night = date('Y-12-31 23:59:59'); | 
					
						
							| 
									
										
										
										
											2021-09-08 20:32:53 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $this->db->select('COUNT( * ) as count', FALSE); | 
					
						
							|  |  |  |         $this->db->where_in('station_id', $logbooks_locations_array); | 
					
						
							|  |  |  |         $this->db->where('COL_TIME_ON >=', $morning); | 
					
						
							|  |  |  |         $this->db->where('COL_TIME_ON <=', $night); | 
					
						
							|  |  |  |         $query = $this->db->get($this->config->item('table_name')); | 
					
						
							| 
									
										
										
										
											2011-06-17 20:52:00 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if ($query->num_rows() > 0) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             foreach ($query->result() as $row) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                  return $row->count; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-11-07 03:53:36 +08:00
										 |  |  |       } else { | 
					
						
							|  |  |  |         return null; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2011-06-17 20:52:00 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-30 21:45:04 +08:00
										 |  |  |     /* Return total amount of SSB QSOs logged */ | 
					
						
							| 
									
										
										
										
											2011-06-17 20:52:00 +08:00
										 |  |  |     function total_ssb() { | 
					
						
							| 
									
										
										
										
											2019-09-26 19:42:19 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       $CI =& get_instance(); | 
					
						
							| 
									
										
										
										
											2021-09-08 20:32:53 +08:00
										 |  |  |       $CI->load->model('logbooks_model'); | 
					
						
							|  |  |  |       $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							| 
									
										
										
										
											2019-09-26 19:42:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-15 01:46:09 +08:00
										 |  |  |       if (!$logbooks_locations_array) { | 
					
						
							|  |  |  |         return null; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-08 20:32:53 +08:00
										 |  |  |       $this->db->select('COUNT( * ) as count', FALSE); | 
					
						
							|  |  |  |       $this->db->where_in('station_id', $logbooks_locations_array); | 
					
						
							|  |  |  |       $this->db->where('COL_MODE', 'SSB'); | 
					
						
							|  |  |  |       $this->db->or_where('COL_MODE', 'LSB'); | 
					
						
							|  |  |  |       $this->db->or_where('COL_MODE', 'USB'); | 
					
						
							| 
									
										
										
										
											2019-09-26 19:42:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-08 20:32:53 +08:00
										 |  |  |       $query = $this->db->get($this->config->item('table_name')); | 
					
						
							| 
									
										
										
										
											2011-06-17 20:52:00 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if ($query->num_rows() > 0) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             foreach ($query->result() as $row) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                  return $row->count; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-09-30 21:45:04 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |    /* Return total number of satellite QSOs */ | 
					
						
							| 
									
										
										
										
											2011-07-25 06:33:08 +08:00
										 |  |  |    function total_sat() { | 
					
						
							| 
									
										
										
										
											2019-09-26 19:42:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-08 20:32:53 +08:00
										 |  |  |       $CI =& get_instance(); | 
					
						
							|  |  |  |       $CI->load->model('logbooks_model'); | 
					
						
							|  |  |  |       $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							| 
									
										
										
										
											2019-09-26 19:42:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-15 01:46:09 +08:00
										 |  |  |       if (!$logbooks_locations_array) { | 
					
						
							|  |  |  |         return null; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-08 20:32:53 +08:00
										 |  |  |       $this->db->select('COL_SAT_NAME, COUNT( * ) as count', FALSE); | 
					
						
							|  |  |  |       $this->db->where_in('station_id', $logbooks_locations_array); | 
					
						
							| 
									
										
										
										
											2021-11-18 04:48:44 +08:00
										 |  |  |       $this->db->where('COL_SAT_NAME is not null'); | 
					
						
							|  |  |  |       $this->db->where('COL_SAT_NAME !=', ''); | 
					
						
							| 
									
										
										
										
											2021-09-08 20:32:53 +08:00
										 |  |  |       $this->db->group_by('COL_SAT_NAME'); | 
					
						
							|  |  |  |       $query = $this->db->get($this->config->item('table_name')); | 
					
						
							| 
									
										
										
										
											2011-07-25 06:33:08 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $query; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-30 21:45:04 +08:00
										 |  |  |     /* Return total number of CW QSOs */ | 
					
						
							| 
									
										
										
										
											2011-06-17 20:52:00 +08:00
										 |  |  |     function total_cw() { | 
					
						
							| 
									
										
										
										
											2019-09-26 19:42:19 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       $CI =& get_instance(); | 
					
						
							| 
									
										
										
										
											2021-09-08 20:32:53 +08:00
										 |  |  |       $CI->load->model('logbooks_model'); | 
					
						
							|  |  |  |       $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							| 
									
										
										
										
											2019-09-26 19:42:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-15 01:46:09 +08:00
										 |  |  |       if (!$logbooks_locations_array) { | 
					
						
							|  |  |  |         return null; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-08 20:32:53 +08:00
										 |  |  |       $this->db->select('COUNT( * ) as count', FALSE); | 
					
						
							|  |  |  |       $this->db->where_in('station_id', $logbooks_locations_array); | 
					
						
							|  |  |  |       $this->db->where('COL_MODE', 'CW'); | 
					
						
							|  |  |  |       $query = $this->db->get($this->config->item('table_name')); | 
					
						
							| 
									
										
										
										
											2011-06-17 20:52:00 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if ($query->num_rows() > 0) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             foreach ($query->result() as $row) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                  return $row->count; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-30 21:45:04 +08:00
										 |  |  |     /* Return total number of FM QSOs */ | 
					
						
							| 
									
										
										
										
											2011-06-17 20:52:00 +08:00
										 |  |  |     function total_fm() { | 
					
						
							| 
									
										
										
										
											2019-09-26 19:42:19 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       $CI =& get_instance(); | 
					
						
							| 
									
										
										
										
											2021-09-08 20:32:53 +08:00
										 |  |  |       $CI->load->model('logbooks_model'); | 
					
						
							|  |  |  |       $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							| 
									
										
										
										
											2019-09-26 19:42:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-15 01:46:09 +08:00
										 |  |  |       if (!$logbooks_locations_array) { | 
					
						
							|  |  |  |         return null; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-08 20:32:53 +08:00
										 |  |  |       $this->db->select('COUNT( * ) as count', FALSE); | 
					
						
							|  |  |  |       $this->db->where_in('station_id', $logbooks_locations_array); | 
					
						
							|  |  |  |       $this->db->where('COL_MODE', 'FM'); | 
					
						
							|  |  |  |       $query = $this->db->get($this->config->item('table_name')); | 
					
						
							| 
									
										
										
										
											2011-06-17 20:52:00 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if ($query->num_rows() > 0) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             foreach ($query->result() as $row) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                  return $row->count; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-30 21:45:04 +08:00
										 |  |  |     /* Return total number of Digital QSOs */ | 
					
						
							| 
									
										
										
										
											2011-06-17 20:52:00 +08:00
										 |  |  |     function total_digi() { | 
					
						
							| 
									
										
										
										
											2019-09-26 19:42:19 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       $CI =& get_instance(); | 
					
						
							| 
									
										
										
										
											2021-09-08 20:32:53 +08:00
										 |  |  |       $CI->load->model('logbooks_model'); | 
					
						
							|  |  |  |       $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-15 01:46:09 +08:00
										 |  |  |       if (!$logbooks_locations_array) { | 
					
						
							|  |  |  |         return null; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-08 20:32:53 +08:00
										 |  |  |       $this->db->select('COUNT( * ) as count', FALSE); | 
					
						
							|  |  |  |       $this->db->where_in('station_id', $logbooks_locations_array); | 
					
						
							|  |  |  |       $this->db->where('COL_MODE !=', 'SSB'); | 
					
						
							|  |  |  |       $this->db->where('COL_MODE !=', 'LSB'); | 
					
						
							|  |  |  |       $this->db->where('COL_MODE !=', 'USB'); | 
					
						
							|  |  |  |       $this->db->where('COL_MODE !=', 'CW'); | 
					
						
							|  |  |  |       $this->db->where('COL_MODE !=', 'FM'); | 
					
						
							|  |  |  |       $this->db->where('COL_MODE !=', 'AM'); | 
					
						
							| 
									
										
										
										
											2019-09-26 19:42:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-08 20:32:53 +08:00
										 |  |  |       $query = $this->db->get($this->config->item('table_name')); | 
					
						
							| 
									
										
										
										
											2011-06-17 20:52:00 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if ($query->num_rows() > 0) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             foreach ($query->result() as $row) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                  return $row->count; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-22 01:44:10 +08: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 21:45:04 +08:00
										 |  |  |     /* Return total number of QSOs per band */ | 
					
						
							| 
									
										
										
										
											2011-06-17 20:52:00 +08:00
										 |  |  |    function total_bands() { | 
					
						
							| 
									
										
										
										
											2021-09-08 20:32:53 +08:00
										 |  |  |       $CI =& get_instance(); | 
					
						
							|  |  |  |       $CI->load->model('logbooks_model'); | 
					
						
							|  |  |  |       $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							| 
									
										
										
										
											2019-09-26 19:42:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-15 01:46:09 +08:00
										 |  |  |       if (!$logbooks_locations_array) { | 
					
						
							|  |  |  |         return null; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-08 20:32:53 +08:00
										 |  |  |       $this->db->select('DISTINCT (COL_BAND) AS band, count( * ) AS count', FALSE); | 
					
						
							|  |  |  |       $this->db->where_in('station_id', $logbooks_locations_array); | 
					
						
							|  |  |  |       $this->db->group_by('band'); | 
					
						
							|  |  |  |       $this->db->order_by('count', 'DESC'); | 
					
						
							| 
									
										
										
										
											2019-09-26 19:42:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-08 20:32:53 +08:00
										 |  |  |       $query = $this->db->get($this->config->item('table_name')); | 
					
						
							| 
									
										
										
										
											2011-06-17 20:52:00 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-08 20:32:53 +08:00
										 |  |  |       return $query; | 
					
						
							| 
									
										
										
										
											2011-06-17 20:52:00 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-17 22:20:32 +08:00
										 |  |  |     function get_QSLStats($StationLocationsArray = null) { | 
					
						
							|  |  |  |            | 
					
						
							|  |  |  |       if($StationLocationsArray == null) { | 
					
						
							|  |  |  |         $CI =& get_instance(); | 
					
						
							|  |  |  |         $CI->load->model('logbooks_model'); | 
					
						
							|  |  |  |         $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         $logbooks_locations_array = $StationLocationsArray; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if(!empty($logbooks_locations_array)) { | 
					
						
							|  |  |  |         $this->db->select(' | 
					
						
							|  |  |  |           COUNT(IF(COL_QSL_SENT="Y",COL_QSL_SENT,null)) as QSL_Sent, | 
					
						
							|  |  |  |           COUNT(IF(COL_QSL_RCVD="Y",COL_QSL_RCVD,null)) as QSL_Received, | 
					
						
							|  |  |  |           COUNT(IF(COL_QSL_SENT IN("Q", "R") ,COL_QSL_SENT,null)) as QSL_Requested, | 
					
						
							|  |  |  |           COUNT(IF(COL_EQSL_QSL_SENT="Y",COL_EQSL_QSL_SENT,null)) as eQSL_Sent, | 
					
						
							|  |  |  |           COUNT(IF(COL_EQSL_QSL_RCVD="Y",COL_EQSL_QSL_RCVD,null)) as eQSL_Received, | 
					
						
							|  |  |  |           COUNT(IF(COL_LOTW_QSL_SENT="Y",COL_LOTW_QSL_SENT,null)) as LoTW_Sent, | 
					
						
							|  |  |  |           COUNT(IF(COL_LOTW_QSL_RCVD="Y",COL_LOTW_QSL_RCVD,null)) as LoTW_Received | 
					
						
							|  |  |  |         '); | 
					
						
							|  |  |  |         $this->db->where_in('station_id', $logbooks_locations_array); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if ($query = $this->db->get($this->config->item('table_name'))) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           $this->db->last_query(); | 
					
						
							|  |  |  |             foreach ($query->result() as $row) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                     $QSLBreakdown['QSL_Sent'] = $row->QSL_Sent; | 
					
						
							|  |  |  |                     $QSLBreakdown['QSL_Received'] =  $row->QSL_Received; | 
					
						
							|  |  |  |                     $QSLBreakdown['QSL_Requested'] =  $row->QSL_Requested; | 
					
						
							|  |  |  |                     $QSLBreakdown['eQSL_Sent'] =  $row->eQSL_Sent; | 
					
						
							|  |  |  |                     $QSLBreakdown['eQSL_Received'] =  $row->eQSL_Received; | 
					
						
							|  |  |  |                     $QSLBreakdown['LoTW_Sent'] =  $row->LoTW_Sent; | 
					
						
							|  |  |  |                     $QSLBreakdown['LoTW_Received'] =  $row->LoTW_Received; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             return $QSLBreakdown; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2022-02-18 21:30:26 +08:00
										 |  |  |             $QSLBreakdown['QSL_Sent'] = 0; | 
					
						
							|  |  |  |             $QSLBreakdown['QSL_Received'] =  0; | 
					
						
							|  |  |  |             $QSLBreakdown['QSL_Requested'] =  0; | 
					
						
							|  |  |  |             $QSLBreakdown['eQSL_Sent'] =  0; | 
					
						
							|  |  |  |             $QSLBreakdown['eQSL_Received'] =  0; | 
					
						
							|  |  |  |             $QSLBreakdown['LoTW_Sent'] =  0; | 
					
						
							|  |  |  |             $QSLBreakdown['LoTW_Received'] = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             return $QSLBreakdown; | 
					
						
							| 
									
										
										
										
											2022-02-17 22:20:32 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |       } else { | 
					
						
							| 
									
										
										
										
											2022-02-18 21:30:26 +08:00
										 |  |  |             $QSLBreakdown['QSL_Sent'] = 0; | 
					
						
							|  |  |  |             $QSLBreakdown['QSL_Received'] =  0; | 
					
						
							|  |  |  |             $QSLBreakdown['QSL_Requested'] =  0; | 
					
						
							|  |  |  |             $QSLBreakdown['eQSL_Sent'] =  0; | 
					
						
							|  |  |  |             $QSLBreakdown['eQSL_Received'] =  0; | 
					
						
							|  |  |  |             $QSLBreakdown['LoTW_Sent'] =  0; | 
					
						
							|  |  |  |             $QSLBreakdown['LoTW_Received'] = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             return $QSLBreakdown; | 
					
						
							| 
									
										
										
										
											2022-02-17 22:20:32 +08:00
										 |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-30 21:45:04 +08:00
										 |  |  |     /* Return total number of QSL Cards sent */ | 
					
						
							| 
									
										
										
										
											2011-09-22 05:17:24 +08:00
										 |  |  |     function total_qsl_sent() { | 
					
						
							| 
									
										
										
										
											2019-09-26 19:49:50 +08:00
										 |  |  |       $CI =& get_instance(); | 
					
						
							| 
									
										
										
										
											2021-11-14 19:45:17 +08:00
										 |  |  |       $CI->load->model('logbooks_model'); | 
					
						
							|  |  |  |       $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							| 
									
										
										
										
											2019-09-26 19:49:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-14 21:10:18 +08:00
										 |  |  |       if(!empty($logbooks_locations_array)) { | 
					
						
							|  |  |  |         $this->db->select('count(COL_QSL_SENT) AS count'); | 
					
						
							|  |  |  |         $this->db->where_in('station_id', $logbooks_locations_array); | 
					
						
							|  |  |  |         $this->db->where('COL_QSL_SENT =', 'Y'); | 
					
						
							| 
									
										
										
										
											2011-09-22 05:17:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-14 21:10:18 +08:00
										 |  |  |         $query = $this->db->get($this->config->item('table_name')); | 
					
						
							| 
									
										
										
										
											2011-09-22 05:17:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $row = $query->row(); | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-23 03:58:58 +08:00
										 |  |  |         if($row == null) { | 
					
						
							|  |  |  |             return 0; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             return $row->count; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-11-14 19:45:17 +08:00
										 |  |  |       } else { | 
					
						
							| 
									
										
										
										
											2021-11-14 21:10:18 +08:00
										 |  |  |         return 0; | 
					
						
							| 
									
										
										
										
											2021-11-14 19:45:17 +08:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2011-09-23 03:58:58 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-11 14:18:19 +08:00
										 |  |  |     /* Return total number of QSL Cards requested for printing - that means "requested" or "queued" */ | 
					
						
							| 
									
										
										
										
											2011-09-23 03:58:58 +08:00
										 |  |  |     function total_qsl_requested() { | 
					
						
							| 
									
										
										
										
											2019-09-26 19:49:50 +08:00
										 |  |  |       $CI =& get_instance(); | 
					
						
							| 
									
										
										
										
											2021-11-14 19:45:17 +08:00
										 |  |  |       $CI->load->model('logbooks_model'); | 
					
						
							|  |  |  |       $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							| 
									
										
										
										
											2019-09-26 19:49:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-14 21:10:18 +08:00
										 |  |  |       if(!empty($logbooks_locations_array)) { | 
					
						
							|  |  |  |         $this->db->select('count(COL_QSL_SENT) AS count'); | 
					
						
							|  |  |  |         $this->db->where_in('station_id', $logbooks_locations_array); | 
					
						
							|  |  |  |         $this->db->where_in('COL_QSL_SENT', array('Q', 'R')); | 
					
						
							| 
									
										
										
										
											2019-09-26 19:49:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-14 21:10:18 +08:00
										 |  |  |         $query = $this->db->get($this->config->item('table_name')); | 
					
						
							| 
									
										
										
										
											2011-09-23 03:58:58 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $row = $query->row(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-22 05:17:24 +08:00
										 |  |  |         if($row == null) { | 
					
						
							|  |  |  |             return 0; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             return $row->count; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-11-14 19:45:17 +08:00
										 |  |  |       } else { | 
					
						
							| 
									
										
										
										
											2021-11-14 21:10:18 +08:00
										 |  |  |         return 0; | 
					
						
							| 
									
										
										
										
											2021-11-14 19:45:17 +08:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2011-09-22 05:17:24 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-30 21:45:04 +08:00
										 |  |  |     /* Return total number of QSL Cards received */ | 
					
						
							| 
									
										
										
										
											2011-09-22 05:17:24 +08:00
										 |  |  |     function total_qsl_recv() { | 
					
						
							| 
									
										
										
										
											2019-09-26 19:49:50 +08:00
										 |  |  |       $CI =& get_instance(); | 
					
						
							| 
									
										
										
										
											2021-11-14 19:45:17 +08:00
										 |  |  |       $CI->load->model('logbooks_model'); | 
					
						
							|  |  |  |       $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							| 
									
										
										
										
											2019-09-26 19:49:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-14 21:10:18 +08:00
										 |  |  |       if(!empty($logbooks_locations_array)) { | 
					
						
							|  |  |  |         $this->db->select('count(COL_QSL_RCVD) AS count'); | 
					
						
							|  |  |  |         $this->db->where_in('station_id', $logbooks_locations_array); | 
					
						
							|  |  |  |         $this->db->where('COL_QSL_RCVD =', 'Y'); | 
					
						
							| 
									
										
										
										
											2019-09-26 19:49:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-14 21:10:18 +08:00
										 |  |  |         $query = $this->db->get($this->config->item('table_name')); | 
					
						
							| 
									
										
										
										
											2011-09-22 05:17:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $row = $query->row(); | 
					
						
							| 
									
										
										
										
											2021-11-14 21:10:18 +08:00
										 |  |  |    | 
					
						
							| 
									
										
										
										
											2011-09-22 05:17:24 +08:00
										 |  |  |         if($row == null) { | 
					
						
							|  |  |  |             return 0; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             return $row->count; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-11-14 19:45:17 +08:00
										 |  |  |       } else { | 
					
						
							| 
									
										
										
										
											2021-11-14 21:10:18 +08:00
										 |  |  |         return 0; | 
					
						
							| 
									
										
										
										
											2021-11-14 19:45:17 +08:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2011-09-22 05:17:24 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-20 05:34:58 +08:00
										 |  |  |     /* Return total number of eQSL Cards sent */ | 
					
						
							|  |  |  |     function total_eqsl_sent() { | 
					
						
							|  |  |  |         $CI =& get_instance(); | 
					
						
							|  |  |  |         $CI->load->model('logbooks_model'); | 
					
						
							|  |  |  |         $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if(!empty($logbooks_locations_array)) { | 
					
						
							|  |  |  |             $this->db->select('count(COL_EQSL_QSL_SENT) AS count'); | 
					
						
							|  |  |  |             $this->db->where_in('station_id', $logbooks_locations_array); | 
					
						
							|  |  |  |             $this->db->where('COL_EQSL_QSL_SENT =', 'Y'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $query = $this->db->get($this->config->item('table_name')); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $row = $query->row(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if($row == null) { | 
					
						
							|  |  |  |                 return 0; | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 return $row->count; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             return 0; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Return total number of eQSL Cards received */ | 
					
						
							|  |  |  |     function total_eqsl_recv() { | 
					
						
							|  |  |  |         $CI =& get_instance(); | 
					
						
							|  |  |  |         $CI->load->model('logbooks_model'); | 
					
						
							|  |  |  |         $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if(!empty($logbooks_locations_array)) { | 
					
						
							|  |  |  |             $this->db->select('count(COL_EQSL_QSL_RCVD) AS count'); | 
					
						
							|  |  |  |             $this->db->where_in('station_id', $logbooks_locations_array); | 
					
						
							|  |  |  |             $this->db->where('COL_EQSL_QSL_RCVD =', 'Y'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $query = $this->db->get($this->config->item('table_name')); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $row = $query->row(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if($row == null) { | 
					
						
							|  |  |  |                 return 0; | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 return $row->count; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             return 0; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Return total number of LotW sent */ | 
					
						
							|  |  |  |     function total_lotw_sent() { | 
					
						
							|  |  |  |         $CI =& get_instance(); | 
					
						
							|  |  |  |         $CI->load->model('logbooks_model'); | 
					
						
							|  |  |  |         $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if(!empty($logbooks_locations_array)) { | 
					
						
							|  |  |  |             $this->db->select('count(COL_LOTW_QSL_SENT) AS count'); | 
					
						
							|  |  |  |             $this->db->where_in('station_id', $logbooks_locations_array); | 
					
						
							|  |  |  |             $this->db->where('COL_LOTW_QSL_SENT =', 'Y'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $query = $this->db->get($this->config->item('table_name')); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $row = $query->row(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if($row == null) { | 
					
						
							|  |  |  |                 return 0; | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 return $row->count; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             return 0; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Return total number of LotW received */ | 
					
						
							|  |  |  |     function total_lotw_recv() { | 
					
						
							|  |  |  |         $CI =& get_instance(); | 
					
						
							|  |  |  |         $CI->load->model('logbooks_model'); | 
					
						
							|  |  |  |         $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if(!empty($logbooks_locations_array)) { | 
					
						
							|  |  |  |             $this->db->select('count(COL_LOTW_QSL_RCVD) AS count'); | 
					
						
							|  |  |  |             $this->db->where_in('station_id', $logbooks_locations_array); | 
					
						
							|  |  |  |             $this->db->where('COL_LOTW_QSL_RCVD =', 'Y'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $query = $this->db->get($this->config->item('table_name')); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $row = $query->row(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if($row == null) { | 
					
						
							|  |  |  |                 return 0; | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 return $row->count; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             return 0; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-17 02:02:54 +08:00
										 |  |  |     /* Return total number of countries worked */ | 
					
						
							|  |  |  |     function total_countries() { | 
					
						
							| 
									
										
										
										
											2021-11-14 19:45:17 +08:00
										 |  |  |         $CI =& get_instance(); | 
					
						
							|  |  |  |         $CI->load->model('logbooks_model'); | 
					
						
							|  |  |  |         $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							| 
									
										
										
										
											2020-10-17 02:02:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-14 21:10:18 +08:00
										 |  |  |         if(!empty($logbooks_locations_array)) { | 
					
						
							|  |  |  |           $this->db->select('DISTINCT (COL_COUNTRY)'); | 
					
						
							|  |  |  |           $this->db->where_in('station_id', $logbooks_locations_array); | 
					
						
							|  |  |  |           $this->db->where('COL_COUNTRY !=', 'Invalid'); | 
					
						
							|  |  |  |           $this->db->where('COL_DXCC >', '0'); | 
					
						
							|  |  |  |           $query = $this->db->get($this->config->item('table_name')); | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |           return $query->num_rows(); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |           return 0; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-10-17 02:02:54 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Return total number of countries worked */ | 
					
						
							| 
									
										
										
										
											2022-02-17 22:20:32 +08:00
										 |  |  |     function total_countries_current($StationLocationsArray = null) { | 
					
						
							|  |  |  |       if($StationLocationsArray == null) { | 
					
						
							| 
									
										
										
										
											2020-10-17 02:02:54 +08:00
										 |  |  |         $CI =& get_instance(); | 
					
						
							| 
									
										
										
										
											2021-11-14 19:45:17 +08:00
										 |  |  |         $CI->load->model('logbooks_model'); | 
					
						
							|  |  |  |         $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							| 
									
										
										
										
											2022-02-17 22:20:32 +08:00
										 |  |  |       } else { | 
					
						
							|  |  |  |         $logbooks_locations_array = $StationLocationsArray; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-10-17 02:02:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-14 21:10:18 +08:00
										 |  |  |         if(!empty($logbooks_locations_array)) { | 
					
						
							|  |  |  |           $this->db->select('DISTINCT ('.$this->config->item('table_name').'.COL_COUNTRY)'); | 
					
						
							|  |  |  |           $this->db->join('dxcc_entities', 'dxcc_entities.adif = '.$this->config->item('table_name').'.col_dxcc'); | 
					
						
							|  |  |  |           $this->db->where_in($this->config->item('table_name').'.station_id', $logbooks_locations_array); | 
					
						
							|  |  |  |           $this->db->where($this->config->item('table_name').'.COL_COUNTRY !=', 'Invalid'); | 
					
						
							|  |  |  |           $this->db->where('dxcc_entities.end is null'); | 
					
						
							|  |  |  |           $query = $this->db->get($this->config->item('table_name')); | 
					
						
							| 
									
										
										
										
											2011-09-22 05:17:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-14 21:10:18 +08:00
										 |  |  |           return $query->num_rows(); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |           return 0; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2011-09-22 05:17:24 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-06-17 20:52:00 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-17 19:58:09 +08:00
										 |  |  |         /* Return total number of countries confirmed with along with qsl types confirmed */ | 
					
						
							|  |  |  |         function total_countries_confirmed($StationLocationsArray = null) { | 
					
						
							|  |  |  |            | 
					
						
							|  |  |  |           if($StationLocationsArray == null) { | 
					
						
							|  |  |  |             $CI =& get_instance(); | 
					
						
							|  |  |  |             $CI->load->model('logbooks_model'); | 
					
						
							|  |  |  |             $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							|  |  |  |           } else { | 
					
						
							| 
									
										
										
										
											2022-02-17 22:20:32 +08:00
										 |  |  |             $logbooks_locations_array = $StationLocationsArray; | 
					
						
							| 
									
										
										
										
											2022-02-17 19:58:09 +08:00
										 |  |  |           } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           if(!empty($logbooks_locations_array)) { | 
					
						
							|  |  |  |             $this->db->select('COUNT(DISTINCT COL_COUNTRY) as Countries_Worked, | 
					
						
							|  |  |  |             COUNT(DISTINCT IF(COL_QSL_RCVD = "Y", COL_COUNTRY, NULL)) as Countries_Worked_QSL, | 
					
						
							|  |  |  |             COUNT(DISTINCT IF(COL_EQSL_QSL_RCVD = "Y", COL_COUNTRY, NULL)) as Countries_Worked_EQSL,   | 
					
						
							|  |  |  |             COUNT(DISTINCT IF(COL_LOTW_QSL_RCVD = "Y", COL_COUNTRY, NULL)) as Countries_Worked_LOTW'); | 
					
						
							|  |  |  |             $this->db->where_in('station_id', $logbooks_locations_array); | 
					
						
							|  |  |  |             $this->db->where('COL_COUNTRY !=', 'Invalid'); | 
					
						
							|  |  |  |             $this->db->where('COL_DXCC >', '0'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if ($query = $this->db->get($this->config->item('table_name'))) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 foreach ($query->result() as $row) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                         $CountriesBreakdown['Countries_Worked'] = $row->Countries_Worked; | 
					
						
							|  |  |  |                         $CountriesBreakdown['Countries_Worked_QSL'] =  $row->Countries_Worked_QSL; | 
					
						
							|  |  |  |                         $CountriesBreakdown['Countries_Worked_EQSL'] =  $row->Countries_Worked_EQSL; | 
					
						
							|  |  |  |                         $CountriesBreakdown['Countries_Worked_LOTW'] =  $row->Countries_Worked_LOTW; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 return $CountriesBreakdown; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							| 
									
										
										
										
											2022-02-18 21:30:26 +08:00
										 |  |  |               $CountriesBreakdown['Countries_Worked'] = 0; | 
					
						
							|  |  |  |               $CountriesBreakdown['Countries_Worked_QSL'] = 0; | 
					
						
							|  |  |  |               $CountriesBreakdown['Countries_Worked_EQSL'] = 0; | 
					
						
							|  |  |  |               $CountriesBreakdown['Countries_Worked_LOTW'] = 0; | 
					
						
							|  |  |  |               return $CountriesBreakdown; | 
					
						
							| 
									
										
										
										
											2022-02-17 19:58:09 +08:00
										 |  |  |             } | 
					
						
							|  |  |  |           } else { | 
					
						
							| 
									
										
										
										
											2022-02-18 21:30:26 +08:00
										 |  |  |               $CountriesBreakdown['Countries_Worked'] = 0; | 
					
						
							|  |  |  |               $CountriesBreakdown['Countries_Worked_QSL'] = 0; | 
					
						
							|  |  |  |               $CountriesBreakdown['Countries_Worked_EQSL'] = 0; | 
					
						
							|  |  |  |               $CountriesBreakdown['Countries_Worked_LOTW'] = 0; | 
					
						
							|  |  |  |               return $CountriesBreakdown; | 
					
						
							| 
									
										
										
										
											2022-02-17 19:58:09 +08:00
										 |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-17 02:02:54 +08:00
										 |  |  |     /* Return total number of countries confirmed with paper QSL */ | 
					
						
							|  |  |  |     function total_countries_confirmed_paper() { | 
					
						
							| 
									
										
										
										
											2019-12-08 06:32:41 +08:00
										 |  |  |       $CI =& get_instance(); | 
					
						
							| 
									
										
										
										
											2021-11-14 19:45:17 +08:00
										 |  |  |       $CI->load->model('logbooks_model'); | 
					
						
							|  |  |  |       $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							| 
									
										
										
										
											2020-10-17 02:11:45 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-14 21:10:18 +08:00
										 |  |  |       if(!empty($logbooks_locations_array)) { | 
					
						
							|  |  |  |         $this->db->select('DISTINCT (COL_COUNTRY)'); | 
					
						
							|  |  |  |         $this->db->where_in('station_id', $logbooks_locations_array); | 
					
						
							|  |  |  |         $this->db->where('COL_COUNTRY !=', 'Invalid'); | 
					
						
							|  |  |  |         $this->db->where('COL_DXCC >', '0'); | 
					
						
							|  |  |  |         $this->db->where('COL_QSL_RCVD =', 'Y'); | 
					
						
							|  |  |  |         $query = $this->db->get($this->config->item('table_name')); | 
					
						
							| 
									
										
										
										
											2019-12-08 06:32:41 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $query->num_rows(); | 
					
						
							| 
									
										
										
										
											2021-11-14 21:10:18 +08:00
										 |  |  |       } else { | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-12-08 06:32:41 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-17 02:02:54 +08:00
										 |  |  |     /* Return total number of countries confirmed with eQSL */ | 
					
						
							|  |  |  |     function total_countries_confirmed_eqsl() { | 
					
						
							| 
									
										
										
										
											2019-12-12 05:50:21 +08:00
										 |  |  |       $CI =& get_instance(); | 
					
						
							| 
									
										
										
										
											2021-11-14 19:45:17 +08:00
										 |  |  |       $CI->load->model('logbooks_model'); | 
					
						
							|  |  |  |       $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							| 
									
										
										
										
											2020-10-17 02:11:45 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-14 21:10:18 +08:00
										 |  |  |       if(!empty($logbooks_locations_array)) { | 
					
						
							|  |  |  |         $this->db->select('DISTINCT (COL_COUNTRY)'); | 
					
						
							|  |  |  |         $this->db->where_in('station_id', $logbooks_locations_array); | 
					
						
							|  |  |  |         $this->db->where('COL_COUNTRY !=', 'Invalid'); | 
					
						
							|  |  |  |         $this->db->where('COL_DXCC >', '0'); | 
					
						
							|  |  |  |         $this->db->where('COL_EQSL_QSL_RCVD =', 'Y'); | 
					
						
							|  |  |  |         $query = $this->db->get($this->config->item('table_name')); | 
					
						
							| 
									
										
										
										
											2019-12-12 05:50:21 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $query->num_rows(); | 
					
						
							| 
									
										
										
										
											2021-11-14 21:10:18 +08:00
										 |  |  |       } else { | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-12-12 05:50:21 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-17 02:02:54 +08:00
										 |  |  |     /* Return total number of countries confirmed with LoTW */ | 
					
						
							|  |  |  |     function total_countries_confirmed_lotw() { | 
					
						
							| 
									
										
										
										
											2019-12-12 05:50:21 +08:00
										 |  |  |       $CI =& get_instance(); | 
					
						
							| 
									
										
										
										
											2021-11-14 19:45:17 +08:00
										 |  |  |       $CI->load->model('logbooks_model'); | 
					
						
							|  |  |  |       $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							| 
									
										
										
										
											2020-10-17 02:11:45 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-14 21:10:18 +08:00
										 |  |  |       if(!empty($logbooks_locations_array)) { | 
					
						
							|  |  |  |         $this->db->select('DISTINCT (COL_COUNTRY)'); | 
					
						
							|  |  |  |         $this->db->where_in('station_id', $logbooks_locations_array); | 
					
						
							|  |  |  |         $this->db->where('COL_COUNTRY !=', 'Invalid'); | 
					
						
							|  |  |  |         $this->db->where('COL_DXCC >', '0'); | 
					
						
							|  |  |  |         $this->db->where('COL_LOTW_QSL_RCVD =', 'Y'); | 
					
						
							|  |  |  |         $query = $this->db->get($this->config->item('table_name')); | 
					
						
							| 
									
										
										
										
											2019-12-12 05:50:21 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $query->num_rows(); | 
					
						
							| 
									
										
										
										
											2021-11-14 21:10:18 +08:00
										 |  |  |       } else { | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-12-12 05:50:21 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-15 00:01:51 +08:00
										 |  |  |   function api_search_query($query) { | 
					
						
							|  |  |  |     $time_start = microtime(true); | 
					
						
							|  |  |  |     $results = $this->db->query($query); | 
					
						
							| 
									
										
										
										
											2012-01-04 07:30:53 +08:00
										 |  |  |     if(!$results) { | 
					
						
							|  |  |  |       return array('query' => $query, 'error' => $this->db->_error_number(), 'time' => 0); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-11-15 00:01:51 +08:00
										 |  |  |     $time_end = microtime(true); | 
					
						
							|  |  |  |     $time = round($time_end - $time_start, 4); | 
					
						
							| 
									
										
										
										
											2011-08-18 01:15:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-15 00:01:51 +08:00
										 |  |  |     return array('query' => $query, 'results' => $results, 'time' => $time); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-09-30 23:51:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-15 00:01:51 +08:00
										 |  |  |   function api_insert_query($query) { | 
					
						
							|  |  |  |     $time_start = microtime(true); | 
					
						
							|  |  |  |     $results = $this->db->insert($this->config->item('table_name'), $query); | 
					
						
							| 
									
										
										
										
											2012-01-04 07:30:53 +08:00
										 |  |  |     if(!$results) { | 
					
						
							|  |  |  |       return array('query' => $query, 'error' => $this->db->_error_number(), 'time' => 0); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-11-15 00:01:51 +08:00
										 |  |  |     $time_end = microtime(true); | 
					
						
							|  |  |  |     $time = round($time_end - $time_start, 4); | 
					
						
							| 
									
										
										
										
											2011-09-30 23:51:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-15 00:01:51 +08:00
										 |  |  |     return array('query' => $this->db->queries[2], 'result_string' => $results, 'time' => $time); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-09-30 23:51:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-30 21:45:04 +08:00
										 |  |  |     /* Delete QSO based on the QSO ID */ | 
					
						
							| 
									
										
										
										
											2011-08-28 21:51:57 +08:00
										 |  |  |     function delete($id) { | 
					
						
							|  |  |  |         $this->db->where('COL_PRIMARY_KEY', $id); | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  |         $this->db->delete($this->config->item('table_name')); | 
					
						
							| 
									
										
										
										
											2011-08-28 21:51:57 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08:00
										 |  |  |   /* Used to check if the qso is already in the database */ | 
					
						
							| 
									
										
										
										
											2019-12-04 23:16:56 +08:00
										 |  |  |   function import_check($datetime, $callsign, $band) { | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08: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-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08:00
										 |  |  |     $query = $this->db->get($this->config->item('table_name')); | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08:00
										 |  |  |     if ($query->num_rows() > 0) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       return "Found"; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       return "No Match"; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-28 06:49:54 +08:00
										 |  |  |   function lotw_update($datetime, $callsign, $band, $qsl_date, $qsl_status, $state, $qsl_gridsquare) { | 
					
						
							| 
									
										
										
										
											2021-02-09 04:46:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-28 06:49:54 +08:00
										 |  |  | 	$data = array( | 
					
						
							|  |  |  |       'COL_LOTW_QSLRDATE' => $qsl_date, | 
					
						
							|  |  |  |       'COL_LOTW_QSL_RCVD' => $qsl_status, | 
					
						
							|  |  |  |       'COL_LOTW_QSL_SENT' => 'Y' | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  | 	if($state != "") { | 
					
						
							|  |  |  |       $data['COL_STATE'] = $state; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-02-17 00:41:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08: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-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08:00
										 |  |  |     $this->db->update($this->config->item('table_name'), $data); | 
					
						
							| 
									
										
										
										
											2021-07-28 06:49:54 +08:00
										 |  |  | 	unset($data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if($qsl_gridsquare != "") { | 
					
						
							|  |  |  |       $data = array( | 
					
						
							|  |  |  |         'COL_GRIDSQUARE' => $qsl_gridsquare | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |       $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); | 
					
						
							| 
									
										
										
										
											2021-09-19 00:21:48 +08:00
										 |  |  | 	  $this->db->group_start(); | 
					
						
							|  |  |  | 	  $this->db->where('COL_VUCC_GRIDS'); | 
					
						
							|  |  |  | 	  $this->db->or_where('COL_VUCC_GRIDS', ''); | 
					
						
							|  |  |  | 	  $this->db->group_end(); | 
					
						
							| 
									
										
										
										
											2021-07-28 06:49:54 +08:00
										 |  |  |       if(strlen($qsl_gridsquare) > 4) { | 
					
						
							|  |  |  |         $this->db->group_start(); | 
					
						
							|  |  |  |         $this->db->where('COL_GRIDSQUARE', ""); | 
					
						
							|  |  |  |         $this->db->or_where('COL_GRIDSQUARE', substr($qsl_gridsquare, 0, 4)); | 
					
						
							|  |  |  |         if(strlen($qsl_gridsquare) > 6) { | 
					
						
							|  |  |  |           $this->db->or_where('COL_GRIDSQUARE', substr($qsl_gridsquare, 0, 6)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         $this->db->group_end(); | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         $this->db->where('COL_GRIDSQUARE', ""); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       $this->db->update($this->config->item('table_name'), $data); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08:00
										 |  |  |     return "Updated"; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08: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-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08:00
										 |  |  |       $query = $this->db->get($this->config->item('table_name')); | 
					
						
							|  |  |  |       $row = $query->row(); | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-19 00:50:19 +08:00
										 |  |  |       if (isset($row)) { | 
					
						
							|  |  |  |         return $row->COL_LOTW_QSLRDATE; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       return '1900-01-01 00:00:00.000'; | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-11-20 06:28:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | //////////////////////////////
 | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08: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( | 
					
						
							| 
									
										
										
										
											2022-01-21 02:30:50 +08:00
										 |  |  |          'COL_EQSL_QSLRDATE' => date('Y-m-d H:i:s'), // eQSL doesn't give us a date, so let's use current
 | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08:00
										 |  |  |          '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( | 
					
						
							| 
									
										
										
										
											2022-01-21 02:30:50 +08:00
										 |  |  |          'COL_EQSL_QSLSDATE' => date('Y-m-d H:i:s'), // eQSL doesn't give us a date, so let's use current
 | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08:00
										 |  |  |          '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(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-17 23:19:13 +08:00
										 |  |  |       if (isset($row->COL_EQSL_QSLRDATE)){ | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08:00
										 |  |  |           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 23:43:35 +08:00
										 |  |  |             return '1970/01/01'; | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08: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() { | 
					
						
							| 
									
										
										
										
											2022-03-17 03:22:40 +08: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_SUBMODE, '.$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->config->item('table_name').'.COL_SAT_NAME, '.$this->config->item('table_name').'.COL_SAT_MODE, '.$this->config->item('table_name').'.COL_QSLMSG'); | 
					
						
							| 
									
										
										
										
											2019-10-04 18:32:29 +08:00
										 |  |  |       $this->db->from('station_profile'); | 
					
						
							| 
									
										
										
										
											2019-10-08 05:11:51 +08:00
										 |  |  |       $this->db->join($this->config->item('table_name'),'station_profile.station_id = '.$this->config->item('table_name').'.station_id AND station_profile.eqslqthnickname != ""','left'); | 
					
						
							| 
									
										
										
										
											2020-12-11 00:50:54 +08:00
										 |  |  |       $this->db->where($this->config->item('table_name').'.COL_CALL !=', ''); | 
					
						
							| 
									
										
										
										
											2019-10-07 04:26:14 +08:00
										 |  |  |       $this->db->where($this->config->item('table_name').'.COL_EQSL_QSL_SENT !=', 'Y'); | 
					
						
							|  |  |  |       $this->db->where($this->config->item('table_name').'.COL_EQSL_QSL_SENT !=', 'I'); | 
					
						
							| 
									
										
										
										
											2019-10-06 22:40:33 +08:00
										 |  |  |       $this->db->or_where(array($this->config->item('table_name').'.COL_EQSL_QSL_SENT' => NULL)); | 
					
						
							| 
									
										
										
										
											2019-10-04 18:32:29 +08:00
										 |  |  |       return $this->db->get(); | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-11 17:49:33 +08:00
										 |  |  |     /* | 
					
						
							|  |  |  |      * $skipDuplicate - used in ADIF import to skip duplicate checking when importing QSOs | 
					
						
							|  |  |  |      * $markLoTW - used in ADIF import to mark QSOs as exported to LoTW when importing QSOs | 
					
						
							|  |  |  |      * $dxccAdif - used in ADIF import to determine if DXCC From ADIF is used, or if Cloudlog should try to guess | 
					
						
							| 
									
										
										
										
											2020-12-24 17:53:29 +08:00
										 |  |  |      * $markQrz - used in ADIF import to mark QSOs as exported to QRZ Logbook when importing QSOs | 
					
						
							| 
									
										
										
										
											2020-12-11 17:49:33 +08:00
										 |  |  |      * $skipexport - used in ADIF import to skip the realtime upload to QRZ Logbook when importing QSOs from ADIF | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2022-01-25 00:13:25 +08:00
										 |  |  | 	function import($record, $station_id = "0", $skipDuplicate = false, $markLotw = false, $dxccAdif = false, $markQrz = false, $skipexport = false, $operatorName = false, $apicall = false) { | 
					
						
							| 
									
										
										
										
											2021-11-16 02:46:20 +08:00
										 |  |  |         // be sure that station belongs to user
 | 
					
						
							|  |  |  |         $CI =& get_instance(); | 
					
						
							|  |  |  |         $CI->load->model('Stations'); | 
					
						
							| 
									
										
										
										
											2022-01-25 00:13:25 +08:00
										 |  |  |         if (!$CI->Stations->check_station_is_accessible($station_id) && $apicall == false ) { | 
					
						
							| 
									
										
										
										
											2021-11-16 02:46:20 +08:00
										 |  |  |             return 'Station not accessible<br>'; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-17 23:24:16 +08:00
										 |  |  |         $CI =& get_instance(); | 
					
						
							|  |  |  |         $CI->load->library('frequency'); | 
					
						
							| 
									
										
										
										
											2019-10-22 00:41:21 +08:00
										 |  |  |         $my_error = ""; | 
					
						
							| 
									
										
										
										
											2020-04-26 05:04:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-20 06:28:05 +08:00
										 |  |  |         // Join date+time
 | 
					
						
							| 
									
										
										
										
											2021-01-18 19:19:57 +08:00
										 |  |  |         $time_on = date('Y-m-d', strtotime($record['qso_date'])) ." ".date('H:i:s', strtotime($record['time_on'])); | 
					
						
							| 
									
										
										
										
											2021-02-09 04:46:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-20 23:12:40 +08:00
										 |  |  |         if (isset($record['time_off'])) { | 
					
						
							| 
									
										
										
										
											2022-02-07 04:51:39 +08:00
										 |  |  |             if (isset($record['date_off'])) { | 
					
						
							|  |  |  |                 // date_off and time_off set
 | 
					
						
							|  |  |  |                 $time_off = date('Y-m-d', strtotime($record['date_off'])) . ' ' . date('H:i:s', strtotime($record['time_off'])); | 
					
						
							|  |  |  |             } elseif (strtotime($record['time_off']) < strtotime($record['time_on'])) { | 
					
						
							|  |  |  |                 // date_off is not set, QSO ends next day
 | 
					
						
							|  |  |  |                 $time_off = date('Y-m-d', strtotime($record['qso_date'] . ' + 1 day')) . ' ' . date('H:i:s', strtotime($record['time_off'])); | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 // date_off is not set, QSO ends same day
 | 
					
						
							|  |  |  |                 $time_off = date('Y-m-d', strtotime($record['qso_date'])) . ' ' . date('H:i:s', strtotime($record['time_off'])); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2011-11-20 23:12:40 +08:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2022-02-07 04:51:39 +08:00
										 |  |  |             // date_off and time_off not set, QSO end == QSO start
 | 
					
						
							|  |  |  |             $time_off = $time_on; | 
					
						
							| 
									
										
										
										
											2011-11-20 23:12:40 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-01 01:07:27 +08:00
										 |  |  |         // Store Freq
 | 
					
						
							| 
									
										
										
										
											2016-01-18 20:31:41 +08:00
										 |  |  |         // Check if 'freq' is defined in the import?
 | 
					
						
							| 
									
										
										
										
											2020-09-04 22:38:49 +08:00
										 |  |  |         if (isset($record['freq'])){ // record[freq] in MHz
 | 
					
						
							|  |  |  |           $freq = floatval($record['freq']) * 1E6; // store in Hz
 | 
					
						
							| 
									
										
										
										
											2011-11-20 06:28:05 +08:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2020-09-04 22:38:49 +08:00
										 |  |  |           $freq = 0; | 
					
						
							| 
									
										
										
										
											2011-11-20 06:28:05 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-30 06:08:24 +08:00
										 |  |  |         // Check for RX Freq
 | 
					
						
							|  |  |  |         // Check if 'freq' is defined in the import?
 | 
					
						
							| 
									
										
										
										
											2020-09-04 22:38:49 +08:00
										 |  |  |         if (isset($record['freq_rx'])){ // record[freq] in MHz
 | 
					
						
							|  |  |  |           $freqRX = floatval($record['freq_rx']) * 1E6; // store in Hz
 | 
					
						
							| 
									
										
										
										
											2019-06-30 06:08:24 +08:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2020-09-04 22:38:49 +08:00
										 |  |  |           $freqRX = NULL; | 
					
						
							| 
									
										
										
										
											2019-06-30 06:08:24 +08:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-29 01:43:45 +08:00
										 |  |  |         // DXCC id
 | 
					
						
							| 
									
										
										
										
											2019-06-15 19:45:29 +08:00
										 |  |  |         if (isset($record['call'])){ | 
					
						
							| 
									
										
										
										
											2020-04-05 20:23:43 +08:00
										 |  |  |           if ($dxccAdif != NULL) { | 
					
						
							|  |  |  |               if (isset($record['dxcc'])) { | 
					
						
							| 
									
										
										
										
											2020-04-13 16:34:02 +08:00
										 |  |  |                   $entity = $this->get_entity($record['dxcc']); | 
					
						
							|  |  |  |                   $dxcc = array($record['dxcc'], $entity['name']); | 
					
						
							| 
									
										
										
										
											2020-04-05 20:23:43 +08:00
										 |  |  |               } else { | 
					
						
							| 
									
										
										
										
											2020-11-15 04:40:22 +08:00
										 |  |  |                   $dxcc = $this->check_dxcc_table($record['call'], $time_off); | 
					
						
							| 
									
										
										
										
											2020-04-05 20:23:43 +08:00
										 |  |  |               } | 
					
						
							|  |  |  |           } else { | 
					
						
							|  |  |  |             $dxcc = $this->check_dxcc_table($record['call'], $time_off); | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         $dxcc = NULL; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2016-02-29 01:43:45 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-01 01:07:27 +08:00
										 |  |  |         // Store or find country name
 | 
					
						
							| 
									
										
										
										
											2011-11-20 06:28:05 +08:00
										 |  |  |         if(isset($record['country'])) { | 
					
						
							|  |  |  |             $country = $record['country']; | 
					
						
							|  |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2020-11-13 21:02:17 +08:00
										 |  |  |             if (isset($dxcc[1])) { | 
					
						
							|  |  |  |                 $country = ucwords(strtolower($dxcc[1])); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2011-11-20 06:28:05 +08:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-01 01:07:27 +08:00
										 |  |  |         // RST recevied
 | 
					
						
							| 
									
										
										
										
											2011-12-22 08:30:44 +08:00
										 |  |  |         if(isset($record['rst_rcvd'])) { | 
					
						
							|  |  |  |                 $rst_rx = $record['rst_rcvd']; | 
					
						
							|  |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2019-06-30 00:24:13 +08:00
										 |  |  |                 $rst_rx = "59"; | 
					
						
							| 
									
										
										
										
											2011-12-22 08:30:44 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-01 01:07:27 +08:00
										 |  |  |         // RST Sent
 | 
					
						
							|  |  |  |         if(isset($record['rst_sent'])) { | 
					
						
							| 
									
										
										
										
											2011-12-22 08:30:44 +08:00
										 |  |  |                 $rst_tx = $record['rst_sent']; | 
					
						
							|  |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2019-06-30 00:24:13 +08:00
										 |  |  |                 $rst_tx = "59"; | 
					
						
							| 
									
										
										
										
											2011-12-22 08:30:44 +08:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-01 01:55:21 +08:00
										 |  |  |         // Store Band
 | 
					
						
							| 
									
										
										
										
											2012-11-01 01:07:27 +08:00
										 |  |  |         if(isset($record['band'])) { | 
					
						
							| 
									
										
										
										
											2020-08-31 03:59:02 +08:00
										 |  |  |                 $band = strtolower($record['band']); | 
					
						
							| 
									
										
										
										
											2012-11-01 01:07:27 +08:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2019-06-30 00:24:13 +08:00
										 |  |  |             if (isset($record['freq'])){ | 
					
						
							| 
									
										
										
										
											2019-06-30 06:08:24 +08:00
										 |  |  |               if($freq != "0") { | 
					
						
							|  |  |  |                 $band = $CI->frequency->GetBand($freq); | 
					
						
							|  |  |  |               } | 
					
						
							| 
									
										
										
										
											2019-06-30 00:24:13 +08:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2012-11-01 01:07:27 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08:00
										 |  |  |         if(isset($record['band_rx'])) { | 
					
						
							| 
									
										
										
										
											2021-01-12 00:15:37 +08:00
										 |  |  |                 $band_rx = strtolower($record['band_rx']); | 
					
						
							| 
									
										
										
										
											2015-07-27 01:57:43 +08:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2019-06-30 06:08:24 +08:00
										 |  |  |                 if (isset($record['freq_rx'])){ | 
					
						
							|  |  |  |                   if($freq != "0") { | 
					
						
							|  |  |  |                     $band_rx = $CI->frequency->GetBand($freqRX); | 
					
						
							|  |  |  |                   } | 
					
						
							| 
									
										
										
										
											2019-05-17 05:07:05 +08:00
										 |  |  |                 } else { | 
					
						
							|  |  |  |                   $band_rx = ""; | 
					
						
							| 
									
										
										
										
											2019-05-16 15:31:30 +08:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2016-02-14 20:48:55 +08:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-26 05:04:36 +08:00
										 |  |  |         if(isset($record['cqz'])) { | 
					
						
							|  |  |  |           $cq_zone = $record['cqz']; | 
					
						
							| 
									
										
										
										
											2019-05-17 05:49:43 +08:00
										 |  |  |         } elseif(isset($dxcc[2])) { | 
					
						
							|  |  |  |           $cq_zone = $dxcc[2]; | 
					
						
							|  |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2019-06-15 19:45:29 +08:00
										 |  |  |           $cq_zone = NULL; | 
					
						
							| 
									
										
										
										
											2019-05-17 05:49:43 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2014-09-26 06:09:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-21 22:00:37 +08:00
										 |  |  |         // Sanitise lat input to make sure its 11 chars
 | 
					
						
							|  |  |  |         if (isset($record['lat'])){ | 
					
						
							|  |  |  |             $input_lat = mb_strimwidth($record['lat'], 0, 11); | 
					
						
							|  |  |  |         }else{ | 
					
						
							|  |  |  |             $input_lat = NULL; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Sanitise lon input to make sure its 11 chars
 | 
					
						
							|  |  |  |         if (isset($record['lon'])){ | 
					
						
							|  |  |  |             $input_lon = mb_strimwidth($record['lon'], 0, 11); | 
					
						
							|  |  |  |         }else{ | 
					
						
							|  |  |  |             $input_lon = NULL; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Sanitise my_lat input to make sure its 11 chars
 | 
					
						
							|  |  |  |         if (isset($record['my_lat'])){ | 
					
						
							|  |  |  |             $input_my_lat = mb_strimwidth($record['my_lat'], 0, 11); | 
					
						
							|  |  |  |         }else{ | 
					
						
							|  |  |  |             $input_my_lat = NULL; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Sanitise my_lon input to make sure its 11 chars
 | 
					
						
							|  |  |  |         if (isset($record['my_lon'])){ | 
					
						
							|  |  |  |             $input_my_lon = mb_strimwidth($record['my_lon'], 0, 11); | 
					
						
							|  |  |  |         }else{ | 
					
						
							|  |  |  |             $input_my_lon = NULL; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Sanitise TX_POWER
 | 
					
						
							| 
									
										
										
										
											2020-04-26 05:04:36 +08:00
										 |  |  |         if (isset($record['tx_pwr'])){ | 
					
						
							| 
									
										
										
										
											2020-08-11 05:44:49 +08:00
										 |  |  |             $tx_pwr = filter_var($record['tx_pwr'],FILTER_VALIDATE_FLOAT); | 
					
						
							| 
									
										
										
										
											2019-10-14 18:46:58 +08:00
										 |  |  |         }else{ | 
					
						
							|  |  |  |             $tx_pwr = NULL; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-16 23:06:59 +08:00
										 |  |  |         // Sanitise RX Power
 | 
					
						
							|  |  |  |         if (isset($record['rx_pwr'])){ | 
					
						
							|  |  |  |           // Check if RX_PWR is "K" which N1MM+ uses to indicate 1000W
 | 
					
						
							|  |  |  |           if($record['rx_pwr'] == "K") { | 
					
						
							|  |  |  |             $rx_pwr = 1000; | 
					
						
							|  |  |  |           } else { | 
					
						
							|  |  |  |             $rx_pwr = filter_var($record['rx_pwr'],FILTER_VALIDATE_FLOAT); | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         }else{ | 
					
						
							|  |  |  |           $rx_pwr = NULL; | 
					
						
							|  |  |  |          } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-21 22:26:25 +08:00
										 |  |  |         if (isset($record['a_index'])){ | 
					
						
							|  |  |  |             $input_a_index = filter_var($record['a_index'],FILTER_SANITIZE_NUMBER_INT); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $input_a_index = NULL; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (isset($record['age'])){ | 
					
						
							|  |  |  |             $input_age = filter_var($record['age'],FILTER_SANITIZE_NUMBER_INT); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $input_age = NULL; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (isset($record['ant_az'])){ | 
					
						
							|  |  |  |             $input_ant_az = filter_var($record['ant_az'],FILTER_SANITIZE_NUMBER_INT); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $input_ant_az = NULL; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (isset($record['ant_el'])){ | 
					
						
							|  |  |  |             $input_ant_el = filter_var($record['ant_el'],FILTER_SANITIZE_NUMBER_INT); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $input_ant_el = NULL; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (isset($record['ant_path'])){ | 
					
						
							|  |  |  |             $input_ant_path = mb_strimwidth($record['ant_path'], 0, 1); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $input_ant_path = NULL; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-22 00:41:21 +08:00
										 |  |  |         /* | 
					
						
							|  |  |  |           Validate QSL Fields | 
					
						
							|  |  |  |          qslrdate, qslsdate | 
					
						
							|  |  |  |         */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (isset($record['qslrdate'])){ | 
					
						
							|  |  |  |             if(validateADIFDate($record['qslrdate']) == true){ | 
					
						
							|  |  |  |               $input_qslrdate = $record['qslrdate']; | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |               $input_qslrdate = NULL; | 
					
						
							|  |  |  |               $my_error .= "Error QSO: Date: ".$time_on." Callsign: ".$record['call']." the qslrdate is invalid (YYYYMMDD): ".$record['qslrdate']."<br>"; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $input_qslrdate = NULL; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (isset($record['qslsdate'])){ | 
					
						
							|  |  |  |             if(validateADIFDate($record['qslsdate']) == true){ | 
					
						
							|  |  |  |               $input_qslsdate = $record['qslsdate']; | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |               $input_qslsdate = NULL; | 
					
						
							|  |  |  |               $my_error .= "Error QSO: Date: ".$time_on." Callsign: ".$record['call']." the qslsdate is invalid (YYYYMMDD): ".$record['qslsdate']."<br>"; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2019-10-22 00:47:38 +08:00
										 |  |  |             $input_qslsdate = NULL; | 
					
						
							| 
									
										
										
										
											2019-10-22 00:41:21 +08:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (isset($record['qsl_rcvd'])){ | 
					
						
							|  |  |  |             $input_qsl_rcvd = mb_strimwidth($record['qsl_rcvd'], 0, 1); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $input_qsl_rcvd = "N"; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (isset($record['qsl_rcvd_via'])){ | 
					
						
							|  |  |  |             $input_qsl_rcvd_via = mb_strimwidth($record['qsl_rcvd_via'], 0, 1); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $input_qsl_rcvd_via = ""; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (isset($record['qsl_sent'])){ | 
					
						
							|  |  |  |             $input_qsl_sent = mb_strimwidth($record['qsl_sent'], 0, 1); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $input_qsl_sent = "N"; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (isset($record['qsl_sent_via'])){ | 
					
						
							|  |  |  |             $input_qsl_sent_via = mb_strimwidth($record['qsl_sent_via'], 0, 1); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $input_qsl_sent_via = ""; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /* | 
					
						
							|  |  |  |           Validate LOTW Fields | 
					
						
							|  |  |  |         */ | 
					
						
							|  |  |  |         if (isset($record['lotw_qsl_rcvd'])){ | 
					
						
							|  |  |  |             $input_lotw_qsl_rcvd = mb_strimwidth($record['lotw_qsl_rcvd'], 0, 1); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $input_lotw_qsl_rcvd = ""; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (isset($record['lotw_qsl_sent'])){ | 
					
						
							| 
									
										
										
										
											2020-04-05 20:23:43 +08:00
										 |  |  |           $input_lotw_qsl_sent = mb_strimwidth($record['lotw_qsl_sent'], 0, 1); | 
					
						
							|  |  |  |       } else if ($markLotw != NULL) { | 
					
						
							|  |  |  |           $input_lotw_qsl_sent = "Y"; | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |           $input_lotw_qsl_sent = ""; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-10-22 00:41:21 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (isset($record['lotw_qslrdate'])){ | 
					
						
							|  |  |  |             if(validateADIFDate($record['lotw_qslrdate']) == true){ | 
					
						
							|  |  |  |               $input_lotw_qslrdate = $record['lotw_qslrdate']; | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |               $input_lotw_qslrdate = NULL; | 
					
						
							|  |  |  |               $my_error .= "Error QSO: Date: ".$time_on." Callsign: ".$record['call']." the lotw_qslrdate is invalid (YYYYMMDD): ".$record['lotw_qslrdate']."<br>"; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $input_lotw_qslrdate = NULL; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (isset($record['lotw_qslsdate'])){ | 
					
						
							|  |  |  |             if(validateADIFDate($record['lotw_qslsdate']) == true){ | 
					
						
							|  |  |  |               $input_lotw_qslsdate = $record['lotw_qslsdate']; | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |               $input_lotw_qslsdate = NULL; | 
					
						
							|  |  |  |               $my_error .= "Error QSO: Date: ".$time_on." Callsign: ".$record['call']." the lotw_qslsdate is invalid (YYYYMMDD): ".$record['lotw_qslsdate']."<br>"; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2020-04-05 20:23:43 +08:00
										 |  |  |         } else if ($markLotw != NULL) { | 
					
						
							|  |  |  |             $input_lotw_qslsdate = $date = date("Y-m-d H:i:s", strtotime("now")); | 
					
						
							| 
									
										
										
										
											2019-10-22 00:41:21 +08:00
										 |  |  |         } else { | 
					
						
							|  |  |  |             $input_lotw_qslsdate = NULL; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-05 20:23:43 +08:00
										 |  |  |         if (isset($record['mode'])) { | 
					
						
							| 
									
										
										
										
											2020-06-01 13:56:16 +08:00
										 |  |  |             $input_mode = $record['mode']; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $input_mode = ''; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $mode = $this->get_main_mode_if_submode($input_mode); | 
					
						
							|  |  |  |         if ($mode == null) { | 
					
						
							|  |  |  |             $submode = null; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $submode = $input_mode; | 
					
						
							|  |  |  |             $input_mode = $mode; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (empty($submode)) { | 
					
						
							|  |  |  |             $input_submode = (!empty($record['submode'])) ? $record['submode'] : ''; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $input_submode = $submode; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-04-05 20:23:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-05 03:22:15 +08:00
										 |  |  |         // Get active station_id from station profile if one hasn't been provided
 | 
					
						
							| 
									
										
										
										
											2019-12-04 23:16:56 +08:00
										 |  |  |         if($station_id == "" || $station_id == "0") { | 
					
						
							|  |  |  |           $CI =& get_instance(); | 
					
						
							|  |  |  |           $CI->load->model('Stations'); | 
					
						
							|  |  |  |           $station_id = $CI->Stations->find_active(); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-02-09 04:46:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-05 03:22:15 +08:00
										 |  |  |         // Check if QSO is already in the database
 | 
					
						
							| 
									
										
										
										
											2020-04-05 20:23:43 +08:00
										 |  |  |         if ($skipDuplicate != NULL) { | 
					
						
							|  |  |  |             $skip = false; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             if (isset($record['call'])){ | 
					
						
							|  |  |  |                 $this->db->where('COL_CALL', $record['call']); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             $this->db->where('COL_TIME_ON', $time_on); | 
					
						
							|  |  |  |             $this->db->where('COL_BAND', $band); | 
					
						
							|  |  |  |             $this->db->where('COL_MODE', $input_mode); | 
					
						
							|  |  |  |             $this->db->where('station_id', $station_id); | 
					
						
							|  |  |  |             $check = $this->db->get($this->config->item('table_name')); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             // If dupe is not found, set variable to add QSO
 | 
					
						
							|  |  |  |             if ($check->num_rows() <= 0) { | 
					
						
							|  |  |  |                 $skip = false; | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 $skip = true; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2019-06-15 19:45:29 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-04-05 20:23:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-02 01:52:13 +08:00
										 |  |  |         if ($operatorName != false) { | 
					
						
							|  |  |  | 			$operatorName = $this->session->userdata('user_callsign'); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			$operatorName = (!empty($record['operator'])) ? $record['operator'] : ''; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-04 21:52:00 +08:00
										 |  |  |         // If user checked to mark QSOs as uploaded to QRZ Logbook, or else we try to find info in ADIF import.
 | 
					
						
							|  |  |  |         if ($markQrz != null) { | 
					
						
							|  |  |  |             $input_qrzcom_qso_upload_status = 'Y'; | 
					
						
							|  |  |  |             $input_qrzcom_qso_upload_date = $date = date("Y-m-d H:i:s", strtotime("now")); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |             $input_qrzcom_qso_upload_date = (!empty($record['qrzcom_qso_upload_date'])) ? $record['qrzcom_qso_upload_date'] : null; | 
					
						
							|  |  |  |             $input_qrzcom_qso_upload_status = (!empty($record['qrzcom_qso_upload_status'])) ? $record['qrzcom_qso_upload_status'] : ''; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-05 20:23:43 +08:00
										 |  |  |         if (!$skip) | 
					
						
							| 
									
										
										
										
											2011-11-20 06:28:05 +08:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08:00
										 |  |  |             // Create array with QSO Data use ?:
 | 
					
						
							| 
									
										
										
										
											2011-11-20 06:28:05 +08:00
										 |  |  |             $data = array( | 
					
						
							| 
									
										
										
										
											2019-10-21 22:26:25 +08:00
										 |  |  |                 'COL_A_INDEX' => $input_a_index, | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08:00
										 |  |  |                 'COL_ADDRESS' => (!empty($record['address'])) ? $record['address'] : '', | 
					
						
							|  |  |  |                 'COL_ADDRESS_INTL' => (!empty($record['address_intl'])) ? $record['address_intl'] : '', | 
					
						
							| 
									
										
										
										
											2019-10-21 22:26:25 +08:00
										 |  |  |                 'COL_AGE' => $input_age, | 
					
						
							|  |  |  |                 'COL_ANT_AZ' => $input_ant_az, | 
					
						
							|  |  |  |                 'COL_ANT_EL' => $input_ant_el, | 
					
						
							|  |  |  |                 'COL_ANT_PATH' => $input_ant_path, | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08:00
										 |  |  |                 '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-12 07:21:10 +08: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 20:05:41 +08: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-17 06:01:57 +08:00
										 |  |  |                 'COL_COUNTRY' => $country, | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08:00
										 |  |  |                 'COL_COUNTRY_INTL' => (!empty($record['country_intl'])) ? $record['country_intl'] : '', | 
					
						
							| 
									
										
										
										
											2019-05-17 05:49:43 +08:00
										 |  |  |                 'COL_CQZ' => $cq_zone, | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08: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-12 07:21:10 +08:00
										 |  |  |                 'COL_DISTANCE' => (!empty($record['distance'])) ? $record['distance'] : null, | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08:00
										 |  |  |                 'COL_DXCC' => $dxcc[0], | 
					
						
							|  |  |  |                 'COL_EMAIL' => (!empty($record['email'])) ? $record['email'] : '', | 
					
						
							|  |  |  |                 'COL_EQ_CALL' => (!empty($record['eq_call'])) ? $record['eq_call'] : '', | 
					
						
							| 
									
										
										
										
											2019-05-12 07:21:10 +08: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 20:05:41 +08:00
										 |  |  |                 'COL_EQSL_STATUS' => (!empty($record['eqsl_status'])) ? $record['eqsl_status'] : '', | 
					
						
							| 
									
										
										
										
											2019-05-17 09:00:06 +08: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 20:05:41 +08:00
										 |  |  |                 'COL_FREQ' => $freq, | 
					
						
							| 
									
										
										
										
											2019-06-30 06:08:24 +08:00
										 |  |  |                 'COL_FREQ_RX' => (!empty($record['freq_rx'])) ? $freqRX : null, | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08:00
										 |  |  |                 'COL_GRIDSQUARE' => (!empty($record['gridsquare'])) ? $record['gridsquare'] : '', | 
					
						
							| 
									
										
										
										
											2019-05-17 09:00:06 +08: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 20:05:41 +08: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 09:00:06 +08:00
										 |  |  |                 'COL_ITUZ' => (!empty($record['ituz'])) ? $record['ituz'] : null, | 
					
						
							|  |  |  |                 'COL_K_INDEX' => (!empty($record['k_index'])) ? $record['k_index'] : null, | 
					
						
							| 
									
										
										
										
											2019-10-21 22:00:37 +08:00
										 |  |  |                 'COL_LAT' => $input_lat, | 
					
						
							|  |  |  |                 'COL_LON' => $input_lon, | 
					
						
							| 
									
										
										
										
											2019-10-22 00:41:21 +08:00
										 |  |  |                 'COL_LOTW_QSL_RCVD' => $input_lotw_qsl_rcvd, | 
					
						
							|  |  |  |                 'COL_LOTW_QSL_SENT' => $input_lotw_qsl_sent, | 
					
						
							|  |  |  |                 'COL_LOTW_QSLRDATE' => $input_lotw_qslrdate, | 
					
						
							|  |  |  |                 'COL_LOTW_QSLSDATE' => $input_lotw_qslsdate, | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08:00
										 |  |  |                 'COL_LOTW_STATUS' => (!empty($record['lotw_status'])) ? $record['lotw_status'] : '', | 
					
						
							| 
									
										
										
										
											2019-05-17 09:00:06 +08:00
										 |  |  |                 'COL_MAX_BURSTS' => (!empty($record['max_bursts'])) ? $record['max_bursts'] : null, | 
					
						
							| 
									
										
										
										
											2020-04-05 20:23:43 +08:00
										 |  |  |                 'COL_MODE' => $input_mode, | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08:00
										 |  |  |                 '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 09:00:06 +08: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 20:05:41 +08: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 09:00:06 +08:00
										 |  |  |                 'COL_MY_ITU_ZONE' => (!empty($record['my_itu_zone'])) ? $record['my_itu_zone'] : null, | 
					
						
							| 
									
										
										
										
											2019-10-21 22:00:37 +08:00
										 |  |  |                 'COL_MY_LAT' => $input_my_lat, | 
					
						
							|  |  |  |                 'COL_MY_LON' => $input_my_lon, | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08: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 09:00:06 +08:00
										 |  |  |                 'COL_NR_BURSTS' => (!empty($record['nr_bursts'])) ? $record['nr_bursts'] : null, | 
					
						
							|  |  |  |                 'COL_NR_PINGS' => (!empty($record['nr_pings'])) ? $record['nr_pings'] : null, | 
					
						
							| 
									
										
										
										
											2021-05-02 01:52:13 +08:00
										 |  |  |                 'COL_OPERATOR' => $operatorName, | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08:00
										 |  |  |                 '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'] : '', | 
					
						
							| 
									
										
										
										
											2020-12-04 21:52:00 +08:00
										 |  |  |                 'COL_QRZCOM_QSO_UPLOAD_DATE' => $input_qrzcom_qso_upload_date, | 
					
						
							|  |  |  |                 'COL_QRZCOM_QSO_UPLOAD_STATUS' => $input_qrzcom_qso_upload_status, | 
					
						
							| 
									
										
										
										
											2019-10-22 00:41:21 +08:00
										 |  |  |                 'COL_QSL_RCVD' => $input_qsl_rcvd, | 
					
						
							|  |  |  |                 'COL_QSL_RCVD_VIA' => $input_qsl_rcvd_via, | 
					
						
							|  |  |  |                 'COL_QSL_SENT' => $input_qsl_sent, | 
					
						
							|  |  |  |                 'COL_QSL_SENT_VIA' => $input_qsl_sent_via, | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08:00
										 |  |  |                 'COL_QSL_VIA' => (!empty($record['qsl_via'])) ? $record['qsl_via'] : '', | 
					
						
							|  |  |  |                 'COL_QSLMSG' => (!empty($record['qslmsg'])) ? $record['qslmsg'] : '', | 
					
						
							| 
									
										
										
										
											2019-10-22 00:41:21 +08:00
										 |  |  |                 'COL_QSLRDATE' => $input_qslrdate, | 
					
						
							|  |  |  |                 'COL_QSLSDATE' => $input_qslsdate, | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08:00
										 |  |  |                 'COL_QSO_COMPLETE' => (!empty($record['qso_complete'])) ? $record['qso_complete'] : '', | 
					
						
							| 
									
										
										
										
											2019-05-17 09:00:06 +08: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, | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08: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, | 
					
						
							| 
									
										
										
										
											2022-03-16 23:06:59 +08:00
										 |  |  |                 'COL_RX_PWR' => $rx_pwr, | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08:00
										 |  |  |                 'COL_SAT_MODE' => (!empty($record['sat_mode'])) ? $record['sat_mode'] : '', | 
					
						
							|  |  |  |                 'COL_SAT_NAME' => (!empty($record['sat_name'])) ? $record['sat_name'] : '', | 
					
						
							| 
									
										
										
										
											2019-05-17 09:00:06 +08:00
										 |  |  |                 'COL_SFI' => (!empty($record['sfi'])) ? $record['sfi'] : null, | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08: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 09:00:06 +08:00
										 |  |  |                 'COL_SRX' => (!empty($record['srx'])) ? $record['srx'] : null, | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08:00
										 |  |  |                 'COL_SRX_STRING' => (!empty($record['srx_string'])) ? $record['srx_string'] : '', | 
					
						
							| 
									
										
										
										
											2020-08-11 05:03:38 +08:00
										 |  |  |                 'COL_STATE' => (!empty($record['state'])) ? strtoupper($record['state']) : '', | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08:00
										 |  |  |                 'COL_STATION_CALLSIGN' => (!empty($record['station_callsign'])) ? $record['station_callsign'] : '', | 
					
						
							| 
									
										
										
										
											2019-05-17 09:00:06 +08:00
										 |  |  |                 'COL_STX' => (!empty($record['stx'])) ? $record['stx'] : null, | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08:00
										 |  |  |                 'COL_STX_STRING' => (!empty($record['stx_string'])) ? $record['stx_string'] : '', | 
					
						
							| 
									
										
										
										
											2020-06-01 13:56:16 +08:00
										 |  |  |                 'COL_SUBMODE' => $input_submode, | 
					
						
							| 
									
										
										
										
											2019-05-17 09:00:06 +08:00
										 |  |  |                 'COL_SWL' => (!empty($record['swl'])) ? $record['swl'] : null, | 
					
						
							|  |  |  |                 'COL_TEN_TEN' => (!empty($record['ten_ten'])) ? $record['ten_ten'] : null, | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08:00
										 |  |  |                 'COL_TIME_ON' => $time_on, | 
					
						
							|  |  |  |                 'COL_TIME_OFF' => $time_off, | 
					
						
							| 
									
										
										
										
											2019-10-14 18:46:58 +08:00
										 |  |  |                 'COL_TX_PWR' => (!empty($tx_pwr)) ? $tx_pwr : null, | 
					
						
							| 
									
										
										
										
											2018-12-31 20:05:41 +08: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-20 06:28:05 +08:00
										 |  |  |             ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-05 03:22:15 +08:00
										 |  |  |             // Collect field information from the station profile table thats required for the QSO.
 | 
					
						
							| 
									
										
										
										
											2019-08-20 05:25:50 +08: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-24 01:30:17 +08:00
										 |  |  |                     $data['station_id'] = $station_id; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-20 05:25:50 +08: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-24 01:30:17 +08:00
										 |  |  |                     $data['COL_MY_CITY'] = trim($row['station_city']); | 
					
						
							| 
									
										
										
										
											2019-08-20 05:25:50 +08:00
										 |  |  |                     $data['COL_MY_IOTA'] = strtoupper(trim($row['station_iota'])); | 
					
						
							|  |  |  |                     $data['COL_MY_SOTA_REF'] = strtoupper(trim($row['station_sota'])); | 
					
						
							| 
									
										
										
										
											2021-02-09 04:46:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-20 05:25:50 +08:00
										 |  |  |                     $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'])); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-05 03:22:15 +08:00
										 |  |  |             // Save QSO
 | 
					
						
							| 
									
										
										
										
											2020-12-11 17:49:33 +08:00
										 |  |  |             $this->add_qso($data, $skipexport); | 
					
						
							| 
									
										
										
										
											2019-12-05 03:22:15 +08:00
										 |  |  |         } else { | 
					
						
							|  |  |  |           $my_error .= "Date/Time: ".$time_on." Callsign: ".$record['call']." Band: ".$band."  Duplicate<br>"; | 
					
						
							| 
									
										
										
										
											2011-11-20 06:28:05 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-10-22 00:41:21 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $my_error; | 
					
						
							| 
									
										
										
										
											2011-11-20 06:28:05 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-24 06:06:08 +08:00
										 |  |  |     function get_main_mode_if_submode($mode) { | 
					
						
							|  |  |  | 		$this->db->select('mode'); | 
					
						
							|  |  |  |         $this->db->where('submode', $mode); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $query = $this->db->get('adif_modes'); | 
					
						
							|  |  |  |         if ($query->num_rows() > 0){ | 
					
						
							|  |  |  |             $row = $query->row_array(); | 
					
						
							|  |  |  |             return $row['mode']; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             return null; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-02-22 16:09:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-29 01:43:45 +08:00
										 |  |  |     /* | 
					
						
							|  |  |  |      * Check the dxxc_prefixes table and return (dxcc, country) | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-04-13 23:16:07 +08:00
										 |  |  |     public function check_dxcc_table($call, $date){ | 
					
						
							| 
									
										
										
										
											2016-02-22 16:09:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-18 18:21:57 +08:00
										 |  |  | 		$dxcc_exceptions = $this->db->select('`entity`, `adif`, `cqz`') | 
					
						
							| 
									
										
										
										
											2020-06-13 09:11:42 +08:00
										 |  |  |              ->where('call', $call) | 
					
						
							|  |  |  |              ->where('(start <= ', $date) | 
					
						
							|  |  |  |              ->or_where('start is null)', NULL, false) | 
					
						
							|  |  |  |              ->where('(end >= ', $date) | 
					
						
							|  |  |  |              ->or_where('end is null)', NULL, false) | 
					
						
							|  |  |  |              ->get('dxcc_exceptions'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-18 18:21:57 +08:00
										 |  |  | 		if ($dxcc_exceptions->num_rows() > 0){ | 
					
						
							|  |  |  | 			$row = $dxcc_exceptions->row_array(); | 
					
						
							|  |  |  | 			return array($row['adif'], $row['entity'], $row['cqz']); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (preg_match('/(^KG4)[A-Z09]{3,}/', $call)) { 	// KG4/ and KG4 5 char calls are Guantanamo Bay. If 6 char, it is USA
 | 
					
						
							|  |  |  | 			$call = "K"; | 
					
						
							| 
									
										
										
										
											2021-07-30 15:06:53 +08:00
										 |  |  | 		} elseif (preg_match_all('/^((\d|[A-Z])+\/)?((\d|[A-Z]){3,})(\/(\d|[A-Z])+)?(\/(\d|[A-Z])+)?$/', $call, $matches)) { | 
					
						
							|  |  |  | 			if ($matches[5][0] == '/MM') { | 
					
						
							|  |  |  | 				$row['adif'] = 0; | 
					
						
							|  |  |  | 				$row['entity'] = 'None'; | 
					
						
							|  |  |  | 				$row['cqz'] = 0; | 
					
						
							|  |  |  | 				return array($row['adif'], $row['entity'], $row['cqz']); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  |     	} | 
					
						
							| 
									
										
										
										
											2021-07-18 18:21:57 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		$len = strlen($call); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// query the table, removing a character from the right until a match
 | 
					
						
							|  |  |  | 		for ($i = $len; $i > 0; $i--){ | 
					
						
							| 
									
										
										
										
											2016-02-22 16:09:50 +08:00
										 |  |  |             //printf("searching for %s\n", substr($call, 0, $i));
 | 
					
						
							| 
									
										
										
										
											2016-04-13 23:16:07 +08:00
										 |  |  |             $dxcc_result = $this->db->select('`call`, `entity`, `adif`, `cqz`') | 
					
						
							| 
									
										
										
										
											2016-02-24 06:00:35 +08:00
										 |  |  |                                     ->where('call', substr($call, 0, $i)) | 
					
						
							|  |  |  |                                     ->where('(start <= ', $date) | 
					
						
							| 
									
										
										
										
											2019-05-17 09:00:06 +08:00
										 |  |  |                                     ->or_where("start is null)", NULL, false) | 
					
						
							| 
									
										
										
										
											2016-02-24 06:00:35 +08:00
										 |  |  |                                     ->where('(end >= ', $date) | 
					
						
							| 
									
										
										
										
											2019-05-17 09:00:06 +08:00
										 |  |  |                                     ->or_where("end is null)", NULL, false) | 
					
						
							| 
									
										
										
										
											2016-02-24 06:00:35 +08:00
										 |  |  |                                     ->get('dxcc_prefixes'); | 
					
						
							| 
									
										
										
										
											2016-02-22 16:09:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-24 06:00:35 +08: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 16:09:50 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |             if ($dxcc_result->num_rows() > 0){ | 
					
						
							|  |  |  |                 $row = $dxcc_result->row_array(); | 
					
						
							| 
									
										
										
										
											2016-04-13 23:16:07 +08:00
										 |  |  |                 return array($row['adif'], $row['entity'], $row['cqz']); | 
					
						
							| 
									
										
										
										
											2016-02-22 16:09:50 +08:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return array("Not Found", "Not Found"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-14 07:14:39 +08:00
										 |  |  |     public function dxcc_lookup($call, $date){ | 
					
						
							| 
									
										
										
										
											2021-02-09 04:46:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-18 18:21:57 +08:00
										 |  |  | 		$dxcc_exceptions = $this->db->select('`entity`, `adif`, `cqz`') | 
					
						
							|  |  |  | 				->where('call', $call) | 
					
						
							|  |  |  | 				->where('(start <= CURDATE()') | 
					
						
							| 
									
										
										
										
											2021-10-10 03:34:09 +08:00
										 |  |  | 				->or_where('start is null)', NULL, false) | 
					
						
							|  |  |  | 				->where('(end >= CURDATE()') | 
					
						
							| 
									
										
										
										
											2021-07-18 18:21:57 +08:00
										 |  |  | 				->or_where('end is null)', NULL, false) | 
					
						
							|  |  |  | 				->get('dxcc_exceptions'); | 
					
						
							| 
									
										
										
										
											2020-06-13 09:11:42 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-18 18:21:57 +08:00
										 |  |  | 			if ($dxcc_exceptions->num_rows() > 0){ | 
					
						
							|  |  |  | 				$row = $dxcc_exceptions->row_array(); | 
					
						
							|  |  |  | 				return $row; | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if (preg_match('/(^KG4)[A-Z09]{3,}/', $call)) { 	// KG4/ and KG4 5 char calls are Guantanamo Bay. If 6 char, it is USA
 | 
					
						
							|  |  |  | 					$call = "K"; | 
					
						
							| 
									
										
										
										
											2021-07-30 15:06:53 +08:00
										 |  |  | 				} elseif (preg_match_all('/^((\d|[A-Z])+\/)?((\d|[A-Z]){3,})(\/(\d|[A-Z])+)?(\/(\d|[A-Z])+)?$/', $call, $matches)) { | 
					
						
							|  |  |  | 					if ($matches[5][0] == '/MM') { | 
					
						
							|  |  |  | 						$row['adif'] = 0; | 
					
						
							|  |  |  | 						$row['entity'] = 'None'; | 
					
						
							|  |  |  | 						$row['cqz'] = 0; | 
					
						
							|  |  |  | 						$row['long'] = '0'; | 
					
						
							|  |  |  | 						$row['lat'] = '0'; | 
					
						
							|  |  |  | 						return $row; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  |     			} | 
					
						
							| 
									
										
										
										
											2021-07-18 18:21:57 +08: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));
 | 
					
						
							|  |  |  | 					$dxcc_result = $this->db->select('*') | 
					
						
							|  |  |  | 										  ->where('call', substr($call, 0, $i)) | 
					
						
							|  |  |  | 										  ->where('(start <= ', $date) | 
					
						
							|  |  |  | 										  ->or_where("start is null)", NULL, false) | 
					
						
							|  |  |  | 										  ->where('(end >= ', $date) | 
					
						
							|  |  |  | 										  ->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-14 07:14:39 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return array("Not Found", "Not Found"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-05 20:23:43 +08:00
										 |  |  |     public function get_entity($dxcc){ | 
					
						
							| 
									
										
										
										
											2020-11-19 06:18:58 +08:00
										 |  |  |       $sql = "select name, cqz, lat, 'long' from dxcc_entities where adif = " . $dxcc; | 
					
						
							| 
									
										
										
										
											2020-04-05 20:23:43 +08:00
										 |  |  |       $query = $this->db->query($sql); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if ($query->result() > 0){ | 
					
						
							|  |  |  |           $row = $query->row_array(); | 
					
						
							| 
									
										
										
										
											2020-04-13 16:34:02 +08:00
										 |  |  |           return $row; | 
					
						
							| 
									
										
										
										
											2020-04-05 20:23:43 +08:00
										 |  |  |       } | 
					
						
							|  |  |  |       return ''; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-28 22:09:08 +08:00
										 |  |  |     /* | 
					
						
							| 
									
										
										
										
											2021-02-09 04:46:53 +08:00
										 |  |  |      * Same as check_dxcc_table, but the functionality is in | 
					
						
							| 
									
										
										
										
											2016-02-28 22:09:08 +08:00
										 |  |  |      * a stored procedure which we call | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function check_dxcc_stored_proc($call, $date){ | 
					
						
							| 
									
										
										
										
											2016-04-13 23:16:07 +08: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 22:09:08 +08:00
										 |  |  |         $d = $res->result_array(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Should only be one result.
 | 
					
						
							| 
									
										
										
										
											2021-02-09 04:46:53 +08:00
										 |  |  |         // NOTE: might cause unexpected data if there's an
 | 
					
						
							| 
									
										
										
										
											2016-02-28 22:09:08 +08:00
										 |  |  |         // error with clublog.org data.
 | 
					
						
							|  |  |  |         return $d[0]; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-24 06:00:35 +08:00
										 |  |  |     public function check_missing_dxcc_id($all){ | 
					
						
							| 
									
										
										
										
											2016-02-22 16:09:50 +08:00
										 |  |  |         // get all records with no COL_DXCC
 | 
					
						
							| 
									
										
										
										
											2016-02-24 06:00:35 +08: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 16:09:50 +08: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-24 06:00:35 +08: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 22:09:08 +08:00
										 |  |  |                 // Manual call
 | 
					
						
							| 
									
										
										
										
											2016-02-24 06:00:35 +08:00
										 |  |  |                 $d = $this->check_dxcc_table($row['COL_CALL'], $qso_date); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-28 22:09:08 +08:00
										 |  |  |                 // Stored procedure call
 | 
					
						
							|  |  |  |                 //$d = $this->check_dxcc_stored_proc($row["COL_CALL"], $qso_date);
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-22 16:09:50 +08:00
										 |  |  |                 if ($d[0] != 'Not Found'){ | 
					
						
							|  |  |  |                     $sql = sprintf("update %s set COL_COUNTRY = '%s', COL_DXCC='%s' where COL_PRIMARY_KEY=%d", | 
					
						
							| 
									
										
										
										
											2016-02-24 06:00:35 +08:00
										 |  |  |                                     $this->config->item('table_name'), addslashes(ucwords(strtolower($d[1]))), $d[0], $row['COL_PRIMARY_KEY']); | 
					
						
							| 
									
										
										
										
											2016-02-22 16:09:50 +08:00
										 |  |  |                     $this->db->query($sql); | 
					
						
							|  |  |  |                     //print($sql."\n");
 | 
					
						
							| 
									
										
										
										
											2016-02-24 06:00:35 +08:00
										 |  |  |                     printf("Updating %s to %s and %s\n<br/>", $row['COL_PRIMARY_KEY'], ucwords(strtolower($d[1])), $d[0]); | 
					
						
							| 
									
										
										
										
											2016-02-22 16:09:50 +08:00
										 |  |  |                     $count++; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         $this->db->trans_complete(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         print("$count updated\n"); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-05-02 01:52:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-31 09:12:55 +08:00
										 |  |  | 	public function check_missing_grid_id($all){ | 
					
						
							|  |  |  |         // get all records with no COL_GRIDSQUARE
 | 
					
						
							|  |  |  |         $this->db->select("COL_PRIMARY_KEY, COL_CALL, COL_TIME_ON, COL_TIME_OFF"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // check which to update - records with no Gridsquare or all records
 | 
					
						
							|  |  |  |         $this->db->where("COL_GRIDSQUARE is NULL or COL_GRIDSQUARE = ''"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-31 22:41:11 +08:00
										 |  |  |         $where = "(COL_GRIDSQUARE is NULL or COL_GRIDSQUARE = '') AND (COL_VUCC_GRIDS is NULL or COL_VUCC_GRIDS = '')"; | 
					
						
							|  |  |  |         $this->db->where($where); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-31 09:12:55 +08:00
										 |  |  |         $r = $this->db->get($this->config->item('table_name')); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $count = 0; | 
					
						
							|  |  |  |         $this->db->trans_start(); | 
					
						
							|  |  |  |         if ($r->num_rows() > 0){ | 
					
						
							|  |  |  |             foreach($r->result_array() as $row){ | 
					
						
							|  |  |  | 		          $callsign = $row['COL_CALL']; | 
					
						
							|  |  |  |               if ($this->config->item('callbook') == "qrz" && $this->config->item('qrz_username') != null && $this->config->item('qrz_password') != null) | 
					
						
							|  |  |  |               { | 
					
						
							|  |  |  |                   // Lookup using QRZ
 | 
					
						
							|  |  |  |                   $this->load->library('qrz'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                   if(!$this->session->userdata('qrz_session_key')) { | 
					
						
							|  |  |  |                       $qrz_session_key = $this->qrz->session($this->config->item('qrz_username'), $this->config->item('qrz_password')); | 
					
						
							|  |  |  |                       $this->session->set_userdata('qrz_session_key', $qrz_session_key); | 
					
						
							|  |  |  |                   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                   $callbook = $this->qrz->search($callsign, $this->session->userdata('qrz_session_key')); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |               if ($this->config->item('callbook') == "hamqth" && $this->config->item('hamqth_username') != null && $this->config->item('hamqth_password') != null) | 
					
						
							|  |  |  |               { | 
					
						
							|  |  |  |                   // Load the HamQTH library
 | 
					
						
							|  |  |  |                   $this->load->library('hamqth'); | 
					
						
							| 
									
										
										
										
											2019-09-24 00:29:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-31 09:12:55 +08:00
										 |  |  |                   if(!$this->session->userdata('hamqth_session_key')) { | 
					
						
							|  |  |  |                       $hamqth_session_key = $this->hamqth->session($this->config->item('hamqth_username'), $this->config->item('hamqth_password')); | 
					
						
							|  |  |  |                       $this->session->set_userdata('hamqth_session_key', $hamqth_session_key); | 
					
						
							|  |  |  |                   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                   $callbook = $this->hamqth->search($callsign, $this->session->userdata('hamqth_session_key')); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                   // If HamQTH session has expired, start a new session and retry the search.
 | 
					
						
							|  |  |  |                   if($callbook['error'] == "Session does not exist or expired") { | 
					
						
							|  |  |  |                       $hamqth_session_key = $this->hamqth->session($this->config->item('hamqth_username'), $this->config->item('hamqth_password')); | 
					
						
							|  |  |  |                       $this->session->set_userdata('hamqth_session_key', $hamqth_session_key); | 
					
						
							|  |  |  |                       $callbook = $this->hamqth->search($callsign, $this->session->userdata('hamqth_session_key')); | 
					
						
							|  |  |  |                   } | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |               if (isset($callbook)) | 
					
						
							|  |  |  |               { | 
					
						
							|  |  |  |                   $return['callsign_qra'] = $callbook['gridsquare']; | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |               if ($return['callsign_qra'] != ''){ | 
					
						
							|  |  |  |                   $sql = sprintf("update %s set COL_GRIDSQUARE = '%s' where COL_PRIMARY_KEY=%d", | 
					
						
							|  |  |  |                                   $this->config->item('table_name'), $return['callsign_qra'], $row['COL_PRIMARY_KEY']); | 
					
						
							|  |  |  |                   $this->db->query($sql); | 
					
						
							|  |  |  |                   printf("Updating %s to %s\n<br/>", $row['COL_PRIMARY_KEY'], $return['callsign_qra']); | 
					
						
							|  |  |  |                   $count++; | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         $this->db->trans_complete(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         print("$count updated\n"); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-02-09 04:46:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-24 00:29:22 +08:00
										 |  |  |     public function check_for_station_id() { | 
					
						
							| 
									
										
										
										
											2019-10-03 19:56:25 +08:00
										 |  |  |       $this->db->where('station_id =', 'NULL'); | 
					
						
							| 
									
										
										
										
											2019-09-24 00:29:22 +08:00
										 |  |  |       $query = $this->db->get($this->config->item('table_name')); | 
					
						
							|  |  |  |       if($query->num_rows() >= 1) { | 
					
						
							|  |  |  |         return 1; | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         return 0; | 
					
						
							| 
									
										
										
										
											2021-02-09 04:46:53 +08:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-09-24 00:29:22 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-12 03:38:00 +08:00
										 |  |  |     public function loadCallBook($callsign, $use_fullname=false) | 
					
						
							| 
									
										
										
										
											2020-11-11 11:13:25 +08:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-11-11 22:17:08 +08:00
										 |  |  |         $callbook = null; | 
					
						
							|  |  |  |         try { | 
					
						
							|  |  |  |             if ($this->config->item('callbook') == "qrz" && $this->config->item('qrz_username') != null && $this->config->item('qrz_password') != null) { | 
					
						
							|  |  |  |                 // Lookup using QRZ
 | 
					
						
							|  |  |  |                 $this->load->library('qrz'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 if (!$this->session->userdata('qrz_session_key')) { | 
					
						
							|  |  |  |                     $qrz_session_key = $this->qrz->session($this->config->item('qrz_username'), $this->config->item('qrz_password')); | 
					
						
							|  |  |  |                     $this->session->set_userdata('qrz_session_key', $qrz_session_key); | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2020-11-11 11:13:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-12 01:18:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-12 03:38:00 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 $callbook = $this->qrz->search($callsign, $this->session->userdata('qrz_session_key'), $use_fullname); | 
					
						
							| 
									
										
										
										
											2020-11-13 23:57:48 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 // if we got nothing, it's probably because our session key is invalid, try again
 | 
					
						
							|  |  |  |                 if (!isset($callbook['callsign'])) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     $qrz_session_key = $this->qrz->session($this->config->item('qrz_username'), $this->config->item('qrz_password')); | 
					
						
							|  |  |  |                     $this->session->set_userdata('qrz_session_key', $qrz_session_key); | 
					
						
							|  |  |  |                     $callbook = $this->qrz->search($callsign, $this->session->userdata('qrz_session_key'), $use_fullname); | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2020-11-11 11:13:25 +08:00
										 |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-11 22:17:08 +08:00
										 |  |  |             if ($this->config->item('callbook') == "hamqth" && $this->config->item('hamqth_username') != null && $this->config->item('hamqth_password') != null) { | 
					
						
							|  |  |  |                 // Load the HamQTH library
 | 
					
						
							|  |  |  |                 $this->load->library('hamqth'); | 
					
						
							| 
									
										
										
										
											2020-11-11 11:13:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-11 22:17:08 +08:00
										 |  |  |                 if (!$this->session->userdata('hamqth_session_key')) { | 
					
						
							|  |  |  |                     $hamqth_session_key = $this->hamqth->session($this->config->item('hamqth_username'), $this->config->item('hamqth_password')); | 
					
						
							|  |  |  |                     $this->session->set_userdata('hamqth_session_key', $hamqth_session_key); | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2020-11-11 11:13:25 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 $callbook = $this->hamqth->search($callsign, $this->session->userdata('hamqth_session_key')); | 
					
						
							| 
									
										
										
										
											2020-11-11 22:17:08 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 // If HamQTH session has expired, start a new session and retry the search.
 | 
					
						
							|  |  |  |                 if ($callbook['error'] == "Session does not exist or expired") { | 
					
						
							|  |  |  |                     $hamqth_session_key = $this->hamqth->session($this->config->item('hamqth_username'), $this->config->item('hamqth_password')); | 
					
						
							|  |  |  |                     $this->session->set_userdata('hamqth_session_key', $hamqth_session_key); | 
					
						
							|  |  |  |                     $callbook = $this->hamqth->search($callsign, $this->session->userdata('hamqth_session_key')); | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2020-11-11 11:13:25 +08:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2020-11-11 22:17:08 +08:00
										 |  |  |         } finally { | 
					
						
							|  |  |  |             return $callbook; | 
					
						
							| 
									
										
										
										
											2020-11-11 11:13:25 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-10-03 19:56:25 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     public function update_all_station_ids() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       $data = array( | 
					
						
							|  |  |  |         'station_id' => '1', | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       $this->db->where(array('station_id' => NULL)); | 
					
						
							| 
									
										
										
										
											2021-02-09 04:46:53 +08:00
										 |  |  |       return $this->db->update($this->config->item('table_name'), $data); | 
					
						
							| 
									
										
										
										
											2019-10-03 19:56:25 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-26 07:43:14 +08:00
										 |  |  |     public function parse_frequency($frequency) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       if (is_int($frequency)) | 
					
						
							| 
									
										
										
										
											2021-02-09 04:46:53 +08:00
										 |  |  |         return $frequency; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-26 07:43:14 +08:00
										 |  |  |       if (is_string($frequency)) | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         $frequency = strtoupper($frequency); | 
					
						
							|  |  |  |         $frequency = str_replace(" ", "", $frequency); | 
					
						
							| 
									
										
										
										
											2021-02-09 04:46:53 +08:00
										 |  |  |         $frequency = str_replace("HZ", "", $frequency); | 
					
						
							| 
									
										
										
										
											2019-02-26 07:43:14 +08:00
										 |  |  |         $frequency = str_replace(["K", "M", "G", "T"], ["E3", "E6", "E9", "E12"], $frequency); | 
					
						
							| 
									
										
										
										
											2021-02-09 04:46:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-26 07:43:14 +08:00
										 |  |  |         // this double conversion will take a string like "3700e3" and convert it into 3700000
 | 
					
						
							|  |  |  |         return (int)(float) $frequency; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2021-02-09 04:46:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-26 07:43:14 +08:00
										 |  |  |       return 0; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-04-13 16:34:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-01 19:29:02 +08:00
										 |  |  |     /* | 
					
						
							|  |  |  |      * This function returns the the whole list of dxcc_entities used in various places | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2020-04-13 16:34:02 +08:00
										 |  |  |     function fetchDxcc() { | 
					
						
							|  |  |  |         $sql = "select adif, prefix, name, date(end) Enddate, date(start) Startdate from dxcc_entities"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $sql .= ' order by prefix'; | 
					
						
							|  |  |  |         $query = $this->db->query($sql); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $query->result(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-04-13 20:37:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-01 19:29:02 +08:00
										 |  |  |     /* | 
					
						
							|  |  |  |      * This function returns the whole list of iotas used in various places | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2020-04-13 20:37:09 +08:00
										 |  |  |     function fetchIota() { | 
					
						
							|  |  |  |         $sql = "select tag, name from iota"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $sql .= ' order by tag'; | 
					
						
							|  |  |  |         $query = $this->db->query($sql); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $query->result(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-05-01 19:29:02 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* | 
					
						
							|  |  |  |      * This function tries to locate the correct station_id used for importing QSOs from the downloaded LoTWreport | 
					
						
							|  |  |  |      * $station_callsign is the call listed for the qso in lotwreport | 
					
						
							|  |  |  |      * $my_gridsquare is the gridsquare listed for the qso in lotwreport | 
					
						
							|  |  |  |      * Returns station_id if found | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     function find_correct_station_id($station_callsign, $my_gridsquare) { | 
					
						
							|  |  |  |         $sql = 'select station_id from station_profile | 
					
						
							|  |  |  |             where station_callsign = "' . $station_callsign . '" and station_gridsquare like "%' . substr($my_gridsquare,0, 4) . '%"'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $query = $this->db->query($sql); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $result = $query->row(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if ($result) { | 
					
						
							|  |  |  |             return $result->station_id; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |             return null; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-02-09 04:46:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-02 18:22:08 +08:00
										 |  |  |   function get_lotw_qsos_to_upload($station_id, $start_date, $end_date) { | 
					
						
							| 
									
										
										
										
											2020-08-26 00:50:52 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-20 06:55:58 +08:00
										 |  |  |     $this->db->select('COL_PRIMARY_KEY,COL_CALL, COL_BAND, COL_BAND_RX, COL_TIME_ON, COL_RST_RCVD, COL_RST_SENT, COL_MODE, COL_SUBMODE, COL_FREQ, COL_FREQ_RX, COL_GRIDSQUARE, COL_SAT_NAME, COL_PROP_MODE, COL_LOTW_QSL_SENT, station_id'); | 
					
						
							| 
									
										
										
										
											2020-08-26 00:50:52 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-02 18:22:08 +08:00
										 |  |  |     $this->db->where("station_id", $station_id); | 
					
						
							| 
									
										
										
										
											2020-08-27 04:04:17 +08:00
										 |  |  |     $this->db->where('COL_LOTW_QSL_SENT !=', "Y"); | 
					
						
							|  |  |  |     $this->db->where('COL_PROP_MODE !=', "INTERNET"); | 
					
						
							| 
									
										
										
										
											2020-09-02 18:22:08 +08:00
										 |  |  |     $this->db->where('COL_TIME_ON >=', $start_date); | 
					
						
							|  |  |  |     $this->db->where('COL_TIME_ON <=', $end_date); | 
					
						
							| 
									
										
										
										
											2020-08-26 00:50:52 +08:00
										 |  |  |     $this->db->order_by("COL_TIME_ON", "desc"); | 
					
						
							| 
									
										
										
										
											2020-09-02 18:22:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-26 00:50:52 +08:00
										 |  |  |     $query = $this->db->get($this->config->item('table_name')); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return $query; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-27 04:04:17 +08:00
										 |  |  |   function mark_lotw_sent($qso_id) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       $data = array( | 
					
						
							|  |  |  |            'COL_LOTW_QSLSDATE' => date("Y-m-d H:i:s"), | 
					
						
							|  |  |  |            'COL_LOTW_QSL_SENT' => 'Y', | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $this->db->where('COL_PRIMARY_KEY', $qso_id); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $this->db->update($this->config->item('table_name'), $data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return "Updated"; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-02-07 22:22:03 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     function county_qso_details($state, $county) { | 
					
						
							| 
									
										
										
										
											2021-09-10 04:43:29 +08:00
										 |  |  | 		$CI =& get_instance(); | 
					
						
							|  |  |  | 		$CI->load->model('logbooks_model'); | 
					
						
							|  |  |  | 		$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); | 
					
						
							| 
									
										
										
										
											2021-02-07 22:22:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-10 04:43:29 +08:00
										 |  |  |         $this->db->where_in('station_id', $logbooks_locations_array); | 
					
						
							| 
									
										
										
										
											2021-02-07 22:22:03 +08:00
										 |  |  |         $this->db->where('COL_STATE', $state); | 
					
						
							|  |  |  |         $this->db->where('COL_CNTY', $county); | 
					
						
							|  |  |  |         $this->db->where('COL_PROP_MODE !=', 'SAT'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this->db->get($this->config->item('table_name')); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-15 00:50:11 +08:00
										 |  |  |     public function check_qso_is_accessible($id) { | 
					
						
							|  |  |  |         // check if qso belongs to user
 | 
					
						
							|  |  |  |         $this->db->select($this->config->item('table_name').'.COL_PRIMARY_KEY'); | 
					
						
							|  |  |  |         $this->db->join('station_profile', $this->config->item('table_name').'.station_id = station_profile.station_id'); | 
					
						
							|  |  |  |         $this->db->where('station_profile.user_id', $this->session->userdata('user_id')); | 
					
						
							|  |  |  |         $this->db->where($this->config->item('table_name').'.COL_PRIMARY_KEY', $id); | 
					
						
							|  |  |  |         $query = $this->db->get($this->config->item('table_name')); | 
					
						
							|  |  |  |         if ($query->num_rows() == 1) { | 
					
						
							|  |  |  |             return true; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-25 23:24:01 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-22 00:41:21 +08:00
										 |  |  | function validateADIFDate($date, $format = 'Ymd') | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   $d = DateTime::createFromFormat($format, $date); | 
					
						
							|  |  |  |   return $d && $d->format($format) == $date; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-11-11 11:13:25 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-28 20:53:38 +08:00
										 |  |  | ?>
 |