2011-09-21 14:30:01 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
class adif_data extends CI_Model {
|
|
|
|
|
|
2023-05-01 15:25:30 +02:00
|
|
|
function export_all($api_key = null) {
|
2023-05-01 21:23:30 +02:00
|
|
|
$CI =& get_instance();
|
|
|
|
|
$CI->load->model('logbooks_model');
|
2023-05-01 15:25:30 +02:00
|
|
|
if ($api_key != null) {
|
|
|
|
|
$CI->load->model('api_model');
|
|
|
|
|
if (strpos($this->api_model->access($api_key), 'r') !== false) {
|
|
|
|
|
$this->api_model->update_last_used($api_key);
|
|
|
|
|
$user_id = $this->api_model->key_userid($api_key);
|
2023-05-30 21:03:39 +02:00
|
|
|
$logbooks_locations_array = $this->list_station_locations($user_id);
|
2023-05-01 15:25:30 +02:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-26 12:35:11 +02:00
|
|
|
$this->db->select($this->config->item('table_name').'.*, station_profile.*, dxcc_entities.name as station_country');
|
2026-03-23 22:43:44 +00:00
|
|
|
$this->db->select("TRIM(COALESCE(NULLIF(CONCAT_WS(' ', users.user_firstname, users.user_lastname), ''), users.user_name, '')) as export_my_name", false);
|
2020-11-23 19:52:30 +01:00
|
|
|
$this->db->order_by("COL_TIME_ON", "ASC");
|
|
|
|
|
$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id');
|
2026-03-23 22:43:44 +00:00
|
|
|
$this->db->join($this->config->item('auth_table').' users', 'station_profile.user_id = users.user_id', 'left');
|
2023-05-01 15:25:30 +02:00
|
|
|
$this->db->where_in('station_profile.station_id', $logbooks_locations_array);
|
2023-04-26 12:35:11 +02:00
|
|
|
$this->db->join('dxcc_entities', 'station_profile.station_dxcc = dxcc_entities.adif');
|
2011-09-21 14:30:01 +01:00
|
|
|
$query = $this->db->get($this->config->item('table_name'));
|
2020-04-08 14:53:20 +01:00
|
|
|
|
2011-09-21 14:30:01 +01:00
|
|
|
return $query;
|
|
|
|
|
}
|
2019-04-08 15:36:23 +01:00
|
|
|
|
2023-05-30 21:03:39 +02:00
|
|
|
function list_station_locations($user_id) {
|
|
|
|
|
$this->db->where('user_id', $user_id);
|
|
|
|
|
$query = $this->db->get('station_profile');
|
|
|
|
|
|
|
|
|
|
if ($query->num_rows() == 0) {
|
|
|
|
|
return array();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$locations_array = array();
|
|
|
|
|
foreach ($query->result() as $row) {
|
|
|
|
|
array_push($locations_array, $row->station_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $locations_array;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-22 17:16:49 +02:00
|
|
|
function export_printrequested($station_id = NULL) {
|
2019-09-24 23:42:01 +01:00
|
|
|
$this->load->model('stations');
|
|
|
|
|
$active_station_id = $this->stations->find_active();
|
|
|
|
|
|
2023-04-25 00:13:49 +02:00
|
|
|
$this->db->select($this->config->item('table_name').'.*, station_profile.*, dxcc_entities.name as station_country');
|
2026-03-23 22:43:44 +00:00
|
|
|
$this->db->select("TRIM(COALESCE(NULLIF(CONCAT_WS(' ', users.user_firstname, users.user_lastname), ''), users.user_name, '')) as export_my_name", false);
|
2023-04-25 00:13:49 +02:00
|
|
|
|
2021-07-22 17:16:49 +02:00
|
|
|
if ($station_id == NULL) {
|
|
|
|
|
$this->db->where($this->config->item('table_name').'.station_id', $active_station_id);
|
2021-08-24 20:10:07 +02:00
|
|
|
} else if ($station_id != 'All') {
|
2021-07-22 17:16:49 +02:00
|
|
|
$this->db->where($this->config->item('table_name').'.station_id', $station_id);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-20 21:22:52 +01:00
|
|
|
$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id');
|
2026-03-23 22:43:44 +00:00
|
|
|
$this->db->join($this->config->item('auth_table').' users', 'station_profile.user_id = users.user_id', 'left');
|
2023-04-25 00:13:49 +02:00
|
|
|
$this->db->join('dxcc_entities', 'station_profile.station_dxcc = dxcc_entities.adif');
|
2021-11-17 22:30:20 +01:00
|
|
|
// always filter user. this ensures that even if the station_id is from another user no inaccesible QSOs will be returned
|
|
|
|
|
$this->db->where('station_profile.user_id', $this->session->userdata('user_id'));
|
2020-05-25 23:05:21 +02:00
|
|
|
$this->db->where_in('COL_QSL_SENT', array('R', 'Q'));
|
2020-12-20 21:22:52 +01:00
|
|
|
$this->db->order_by("COL_TIME_ON", "ASC");
|
2019-08-28 21:13:24 +02:00
|
|
|
$query = $this->db->get($this->config->item('table_name'));
|
2020-12-20 21:22:52 +01:00
|
|
|
|
2019-08-28 21:13:24 +02:00
|
|
|
return $query;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-08 15:47:03 +01:00
|
|
|
function sat_all() {
|
2019-09-24 23:42:01 +01:00
|
|
|
$this->load->model('stations');
|
|
|
|
|
$active_station_id = $this->stations->find_active();
|
|
|
|
|
|
2023-04-25 00:13:49 +02:00
|
|
|
$this->db->select(''.$this->config->item('table_name').'.*, station_profile.*, dxcc_entities.name as station_country');
|
2026-03-23 22:43:44 +00:00
|
|
|
$this->db->select("TRIM(COALESCE(NULLIF(CONCAT_WS(' ', users.user_firstname, users.user_lastname), ''), users.user_name, '')) as export_my_name", false);
|
2020-04-08 15:00:48 +01:00
|
|
|
$this->db->from($this->config->item('table_name'));
|
|
|
|
|
$this->db->where($this->config->item('table_name').'.station_id', $active_station_id);
|
|
|
|
|
$this->db->where($this->config->item('table_name').'.COL_PROP_MODE', 'SAT');
|
|
|
|
|
|
|
|
|
|
$this->db->order_by($this->config->item('table_name').".COL_TIME_ON", "ASC");
|
|
|
|
|
|
|
|
|
|
$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id');
|
2026-03-23 22:43:44 +00:00
|
|
|
$this->db->join($this->config->item('auth_table').' users', 'station_profile.user_id = users.user_id', 'left');
|
2023-04-28 15:14:59 +02:00
|
|
|
$this->db->join('dxcc_entities', 'station_profile.station_dxcc = dxcc_entities.adif', 'left outer');
|
2020-04-08 15:00:48 +01:00
|
|
|
|
|
|
|
|
return $this->db->get();
|
2019-04-08 15:36:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function satellte_lotw() {
|
2019-09-24 23:42:01 +01:00
|
|
|
$this->load->model('stations');
|
|
|
|
|
$active_station_id = $this->stations->find_active();
|
|
|
|
|
|
2023-04-25 00:13:49 +02:00
|
|
|
$this->db->select(''.$this->config->item('table_name').'.*, station_profile.*, dxcc_entities.name as station_country');
|
2026-03-23 22:43:44 +00:00
|
|
|
$this->db->select("TRIM(COALESCE(NULLIF(CONCAT_WS(' ', users.user_firstname, users.user_lastname), ''), users.user_name, '')) as export_my_name", false);
|
2020-04-08 15:00:48 +01:00
|
|
|
$this->db->from($this->config->item('table_name'));
|
|
|
|
|
$this->db->where($this->config->item('table_name').'.station_id', $active_station_id);
|
|
|
|
|
$this->db->where($this->config->item('table_name').'.COL_PROP_MODE', 'SAT');
|
2019-04-08 15:36:23 +01:00
|
|
|
|
2023-04-21 00:03:18 +02:00
|
|
|
$where = $this->config->item('table_name').".COL_LOTW_QSLRDATE IS NOT NULL";
|
2019-04-08 15:36:23 +01:00
|
|
|
$this->db->where($where);
|
|
|
|
|
|
2020-04-08 15:00:48 +01:00
|
|
|
$this->db->order_by($this->config->item('table_name').".COL_TIME_ON", "ASC");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id');
|
2026-03-23 22:43:44 +00:00
|
|
|
$this->db->join($this->config->item('auth_table').' users', 'station_profile.user_id = users.user_id', 'left');
|
2023-04-28 15:14:59 +02:00
|
|
|
$this->db->join('dxcc_entities', 'station_profile.station_dxcc = dxcc_entities.adif', 'left outer');
|
2020-04-08 15:00:48 +01:00
|
|
|
|
|
|
|
|
return $this->db->get();
|
2019-04-08 15:36:23 +01:00
|
|
|
}
|
2020-04-08 14:47:25 +01:00
|
|
|
|
2021-03-08 20:20:05 +01:00
|
|
|
function export_custom($from, $to, $station_id, $exportLotw = false) {
|
2021-11-15 19:46:20 +01:00
|
|
|
// be sure that station belongs to user
|
|
|
|
|
$CI =& get_instance();
|
|
|
|
|
$CI->load->model('Stations');
|
|
|
|
|
if (!$CI->Stations->check_station_is_accessible($station_id)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-25 00:13:49 +02:00
|
|
|
$this->db->select(''.$this->config->item('table_name').'.*, station_profile.*, dxcc_entities.name as station_country');
|
2026-03-23 22:43:44 +00:00
|
|
|
$this->db->select("TRIM(COALESCE(NULLIF(CONCAT_WS(' ', users.user_firstname, users.user_lastname), ''), users.user_name, '')) as export_my_name", false);
|
2020-04-08 14:47:25 +01:00
|
|
|
$this->db->from($this->config->item('table_name'));
|
2021-03-08 20:20:05 +01:00
|
|
|
$this->db->where($this->config->item('table_name').'.station_id', $station_id);
|
2020-02-07 14:17:05 +01:00
|
|
|
|
|
|
|
|
// If date is set, we format the date and add it to the where-statement
|
2022-12-23 12:55:58 +00:00
|
|
|
if ($from) {
|
Sanitize and escape query inputs in models
Sanitize location lists and escape query parameters across multiple models to prevent SQL injection and fix query formatting. Changes include: converting location arrays to comma-separated integer lists (array_map('intval')) instead of quoted implode, adding escape_str for band/mode/sat, adding a sanitize_location_list helper and early-return checks in CQ, escaping band lists, and updating Adif_data date where clauses to use $this->db->escape(..., NULL, FALSE). Files modified: Accumulate_model, Activated_gridmap_model, Adif_data, Cq, and Gridmap_model.
2026-06-24 22:19:35 +01:00
|
|
|
$this->db->where('DATE('.$this->config->item('table_name').'.COL_TIME_ON) >= '.$this->db->escape($from), NULL, FALSE);
|
2020-02-07 14:17:05 +01:00
|
|
|
}
|
2022-12-23 12:55:58 +00:00
|
|
|
if ($to) {
|
Sanitize and escape query inputs in models
Sanitize location lists and escape query parameters across multiple models to prevent SQL injection and fix query formatting. Changes include: converting location arrays to comma-separated integer lists (array_map('intval')) instead of quoted implode, adding escape_str for band/mode/sat, adding a sanitize_location_list helper and early-return checks in CQ, escaping band lists, and updating Adif_data date where clauses to use $this->db->escape(..., NULL, FALSE). Files modified: Accumulate_model, Activated_gridmap_model, Adif_data, Cq, and Gridmap_model.
2026-06-24 22:19:35 +01:00
|
|
|
$this->db->where('DATE('.$this->config->item('table_name').'.COL_TIME_ON) <= '.$this->db->escape($to), NULL, FALSE);
|
2020-02-07 14:17:05 +01:00
|
|
|
}
|
2020-06-23 09:22:37 +02:00
|
|
|
if ($exportLotw) {
|
2022-09-03 07:27:58 +02:00
|
|
|
$this->db->group_start();
|
2020-06-23 09:22:37 +02:00
|
|
|
$this->db->where($this->config->item('table_name').".COL_LOTW_QSL_SENT != 'Y'");
|
2022-09-02 14:11:13 +02:00
|
|
|
$this->db->or_where($this->config->item('table_name').".COL_LOTW_QSL_SENT", NULL);
|
|
|
|
|
$this->db->group_end();
|
2020-06-23 09:22:37 +02:00
|
|
|
}
|
|
|
|
|
|
2020-04-08 14:47:25 +01:00
|
|
|
$this->db->order_by($this->config->item('table_name').".COL_TIME_ON", "ASC");
|
2011-09-21 14:30:01 +01:00
|
|
|
|
2020-04-08 14:47:25 +01:00
|
|
|
$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id');
|
2026-03-23 22:43:44 +00:00
|
|
|
$this->db->join($this->config->item('auth_table').' users', 'station_profile.user_id = users.user_id', 'left');
|
2023-04-28 15:14:59 +02:00
|
|
|
$this->db->join('dxcc_entities', 'station_profile.station_dxcc = dxcc_entities.adif', 'left outer');
|
2020-04-08 14:47:25 +01:00
|
|
|
|
|
|
|
|
return $this->db->get();
|
2011-09-21 14:30:01 +01:00
|
|
|
}
|
2021-03-08 20:20:05 +01:00
|
|
|
|
2013-03-04 22:57:29 -06:00
|
|
|
function export_lotw() {
|
2019-09-24 23:42:01 +01:00
|
|
|
$this->load->model('stations');
|
|
|
|
|
$active_station_id = $this->stations->find_active();
|
2020-04-08 14:53:20 +01:00
|
|
|
|
2021-03-08 20:20:05 +01:00
|
|
|
|
2023-04-25 00:13:49 +02:00
|
|
|
$this->db->select(''.$this->config->item('table_name').'.*, station_profile.*, dxcc_entities.name as station_country');
|
2026-03-23 22:43:44 +00:00
|
|
|
$this->db->select("TRIM(COALESCE(NULLIF(CONCAT_WS(' ', users.user_firstname, users.user_lastname), ''), users.user_name, '')) as export_my_name", false);
|
2020-04-08 14:53:20 +01:00
|
|
|
$this->db->from($this->config->item('table_name'));
|
|
|
|
|
$this->db->where($this->config->item('table_name').'.station_id', $active_station_id);
|
2022-09-03 07:27:58 +02:00
|
|
|
$this->db->group_start();
|
2020-04-08 14:53:20 +01:00
|
|
|
$this->db->where($this->config->item('table_name').".COL_LOTW_QSL_SENT != 'Y'");
|
2022-09-02 14:11:13 +02:00
|
|
|
$this->db->or_where($this->config->item('table_name').".COL_LOTW_QSL_SENT", NULL);
|
|
|
|
|
$this->db->group_end();
|
2020-04-08 14:53:20 +01:00
|
|
|
|
|
|
|
|
$this->db->order_by($this->config->item('table_name').".COL_TIME_ON", "ASC");
|
|
|
|
|
|
|
|
|
|
$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id');
|
2026-03-23 22:43:44 +00:00
|
|
|
$this->db->join($this->config->item('auth_table').' users', 'station_profile.user_id = users.user_id', 'left');
|
2023-04-28 15:14:59 +02:00
|
|
|
$this->db->join('dxcc_entities', 'station_profile.station_dxcc = dxcc_entities.adif', 'left outer');
|
2020-04-08 14:53:20 +01:00
|
|
|
|
|
|
|
|
return $this->db->get();
|
2013-03-04 22:57:29 -06:00
|
|
|
}
|
2021-03-08 20:20:05 +01:00
|
|
|
|
2013-03-06 23:31:19 -06:00
|
|
|
function mark_lotw_sent($id) {
|
|
|
|
|
$data = array(
|
|
|
|
|
'COL_LOTW_QSL_SENT' => 'Y'
|
|
|
|
|
);
|
2021-03-08 20:20:05 +01:00
|
|
|
|
2020-04-01 08:43:08 +02:00
|
|
|
$this->db->set('COL_LOTW_QSLSDATE', 'now()', FALSE);
|
2013-03-06 23:31:19 -06:00
|
|
|
$this->db->where('COL_PRIMARY_KEY', $id);
|
2021-03-08 20:20:05 +01:00
|
|
|
$this->db->update($this->config->item('table_name'), $data);
|
2013-03-06 23:31:19 -06:00
|
|
|
}
|
2021-03-20 11:24:13 +01:00
|
|
|
|
|
|
|
|
function sig_all($type) {
|
2021-09-09 22:29:59 +02: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-03-20 11:24:13 +01:00
|
|
|
|
2026-03-23 22:43:44 +00:00
|
|
|
$this->db->select(''.$this->config->item('table_name').'.*, station_profile.*, dxcc_entities.name as station_country');
|
|
|
|
|
$this->db->select("TRIM(COALESCE(NULLIF(CONCAT_WS(' ', users.user_firstname, users.user_lastname), ''), users.user_name, '')) as export_my_name", false);
|
2021-03-20 11:24:13 +01:00
|
|
|
$this->db->from($this->config->item('table_name'));
|
2021-09-09 22:29:59 +02:00
|
|
|
$this->db->where_in($this->config->item('table_name').'.station_id', $logbooks_locations_array);
|
2021-03-20 11:24:13 +01:00
|
|
|
$this->db->where($this->config->item('table_name').'.COL_SIG', $type);
|
|
|
|
|
|
|
|
|
|
$this->db->order_by($this->config->item('table_name').".COL_TIME_ON", "ASC");
|
|
|
|
|
|
|
|
|
|
$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id');
|
2026-03-23 22:43:44 +00:00
|
|
|
$this->db->join($this->config->item('auth_table').' users', 'station_profile.user_id = users.user_id', 'left');
|
2023-04-28 15:14:59 +02:00
|
|
|
$this->db->join('dxcc_entities', 'station_profile.station_dxcc = dxcc_entities.adif', 'left outer');
|
2021-03-20 11:24:13 +01:00
|
|
|
|
|
|
|
|
return $this->db->get();
|
|
|
|
|
}
|
2011-09-21 14:30:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|