diff --git a/application/config/migration.php b/application/config/migration.php index a84fafcf..4a7774a3 100644 --- a/application/config/migration.php +++ b/application/config/migration.php @@ -22,7 +22,7 @@ $config['migration_enabled'] = TRUE; | */ -$config['migration_version'] = 152; +$config['migration_version'] = 153; /* |-------------------------------------------------------------------------- diff --git a/application/controllers/Components.php b/application/controllers/Components.php index 942dcbc3..7fc0e27a 100644 --- a/application/controllers/Components.php +++ b/application/controllers/Components.php @@ -14,11 +14,13 @@ class Components extends CI_Controller { } public function index() { + $this->load->model('stations'); $url = 'https://oscarwatch.org/scripts/hamsat_json.php'; $json = file_get_contents($url); $data['rovedata'] = json_decode($json, true); + $data['gridsquare'] = strtoupper($this->stations->find_gridsquare()); // load view $this->load->view('components/hamsat/table', $data); } -} \ No newline at end of file +} diff --git a/application/controllers/Debug.php b/application/controllers/Debug.php index 5d8d2a9c..1d60cbd5 100644 --- a/application/controllers/Debug.php +++ b/application/controllers/Debug.php @@ -52,9 +52,11 @@ class Debug extends CI_Controller { // Check if the subdirectories are writable (recursive check) $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)); foreach ($iterator as $item) { - if (!is_writable($item->getPathname())) { - return false; - } + if ($item->isDir() && basename($item->getPathName()) != '..') { + if (!is_writable($item->getRealPath())) { + return false; + } + } } return true; diff --git a/application/controllers/Logbook.php b/application/controllers/Logbook.php index f0ff8f12..3fa7c0f7 100644 --- a/application/controllers/Logbook.php +++ b/application/controllers/Logbook.php @@ -168,7 +168,7 @@ class Logbook extends CI_Controller { $return['confirmed'] = $this->confirmed_grid_before($return['callsign_qra'], $type, $band, $mode); if ($this->session->userdata('user_show_profile_image')) { - if (isset($callbook)) { + if (isset($callbook) && isset($callbook['image'])) { if ($callbook['image'] == "") { $return['image'] = "n/a"; } else { @@ -851,14 +851,40 @@ function worked_grid_before($gridsquare, $type, $band, $mode) $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); } - $data= $this->qrz->search($id, $this->session->userdata('qrz_session_key'), $this->config->item('use_fullname')); + $callsign['callsign'] = $this->qrz->search($id, $this->session->userdata('qrz_session_key'), $this->config->item('use_fullname')); - if (empty($data['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); - $data = $this->qrz->search($id, $this->session->userdata('qrz_session_key'), $this->config->item('use_fullname')); - } + if (empty($callsign['callsign']['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); + $callsign['callsign'] = $this->qrz->search($id, $this->session->userdata('qrz_session_key'), $this->config->item('use_fullname')); + } + } else 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'); + + 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); + } + + $callsign['callsign'] = $this->hamqth->search($id, $this->session->userdata('hamqth_session_key')); + + // If HamQTH session has expired, start a new session and retry the search. + if($callsign['callsign']['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); + $callsign['callsign'] = $this->hamqth->search($callsign, $this->session->userdata('hamqth_session_key')); + } + if (isset($data['callsign']['gridsquare'])) { + $CI = &get_instance(); + $CI->load->model('logbook_model'); + $callsign['grid_worked'] = $CI->logbook_model->check_if_grid_worked_in_logbook(strtoupper(substr($data['callsign']['gridsquare'],0,4)), 0, $this->session->userdata('user_default_band')); + } + if (isset($callsign['callsign']['error'])) { + $callsign['error'] = $callsign['callsign']['error']; + } + } else { + $callsign['error'] = 'Lookup not configured. Please review configuration.'; } // There's no hamli integration? Disabled for now. @@ -866,12 +892,20 @@ function worked_grid_before($gridsquare, $type, $band, $mode) // Lookup using hamli $this->load->library('hamli'); - $data['callsign'] = $this->hamli->callsign($id); + $callsign['callsign'] = $this->hamli->callsign($id); }*/ - $data['id'] = strtoupper($id); + if (isset($callsign['callsign']['gridsquare'])) { + $CI = &get_instance(); + $CI->load->model('logbook_model'); + $callsign['grid_worked'] = $CI->logbook_model->check_if_grid_worked_in_logbook(strtoupper(substr($callsign['callsign']['gridsquare'],0,4)), 0, $this->session->userdata('user_default_band')); + } + if (isset($callsign['callsign']['error'])) { + $callsign['error'] = $callsign['callsign']['error']; + } + $callsign['id'] = strtoupper($id); - return $this->load->view('search/result', $data, true); + return $this->load->view('search/result', $callsign, true); } } @@ -927,8 +961,33 @@ function worked_grid_before($gridsquare, $type, $band, $mode) if (isset($data['callsign']['error'])) { $data['error'] = $data['callsign']['error']; } + } else 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'); + + 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); + } + + $data['callsign'] = $this->hamqth->search($id, $this->session->userdata('hamqth_session_key')); + + // If HamQTH session has expired, start a new session and retry the search. + if($data['callsign']['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); + $data['callsign'] = $this->hamqth->search($callsign, $this->session->userdata('hamqth_session_key')); + } + if (isset($data['callsign']['gridsquare'])) { + $CI = &get_instance(); + $CI->load->model('logbook_model'); + $data['grid_worked'] = $CI->logbook_model->check_if_grid_worked_in_logbook(strtoupper(substr($data['callsign']['gridsquare'],0,4)), 0, $this->session->userdata('user_default_band')); + } + if (isset($data['callsign']['error'])) { + $data['error'] = $data['callsign']['error']; + } } else { - $data['error'] = 'No result (qrz not configured)'; + $data['error'] = 'Lookup not configured. Please review configuration.'; } /*else { // Lookup using hamli $this->load->library('hamli'); diff --git a/application/libraries/Curl.php b/application/libraries/Curl.php index 106df120..35a75524 100644 --- a/application/libraries/Curl.php +++ b/application/libraries/Curl.php @@ -27,7 +27,6 @@ class Curl { function __construct($url = '') { $this->_ci = & get_instance(); - log_message('debug', 'cURL Class Initialized'); if ( ! $this->is_enabled()) { @@ -369,4 +368,4 @@ class Curl { } /* End of file Curl.php */ -/* Location: ./application/libraries/Curl.php */ \ No newline at end of file +/* Location: ./application/libraries/Curl.php */ diff --git a/application/libraries/Hamqth.php b/application/libraries/Hamqth.php index f2646735..1b71449b 100644 --- a/application/libraries/Hamqth.php +++ b/application/libraries/Hamqth.php @@ -71,7 +71,7 @@ class Hamqth { // Create XML object $xml = simplexml_load_string($xml); - if (empty($xml)) return; + if (!empty($xml->session->error)) return $data['error'] = $xml->session->error; // Return Required Fields $data['callsign'] = (string)$xml->search->callsign; diff --git a/application/migrations/153_tag_2_5_2.php b/application/migrations/153_tag_2_5_2.php new file mode 100644 index 00000000..9be710c1 --- /dev/null +++ b/application/migrations/153_tag_2_5_2.php @@ -0,0 +1,24 @@ +db->where('option_name', 'version'); + $this->db->update('options', array('option_value' => '2.5.2')); + } + + public function down() + { + $this->db->where('option_name', 'version'); + $this->db->update('options', array('option_value' => '2.5.1')); + } +} \ No newline at end of file diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index fdeef86e..2e399f4e 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -433,8 +433,7 @@ class Logbook_model extends CI_Model { $this->db->limit(500); $result = $this->db->get($this->config->item('table_name')); - log_message('debug', 'SQL: '.$this->db->last_query()); - return $result; + return $result; //return $this->db->get($this->config->item('table_name')); } @@ -501,6 +500,7 @@ class Logbook_model extends CI_Model { $this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id'); $this->db->join('dxcc_entities', 'dxcc_entities.adif = '.$this->config->item('table_name').'.COL_DXCC', 'left outer'); + $this->db->join('lotw_users', 'lotw_users.callsign = '.$this->config->item('table_name').'.col_call', 'left outer'); $this->db->where('COL_CALL', $call); if ($band != 'All') { if ($band == 'SAT') { @@ -4083,6 +4083,7 @@ function check_if_callsign_worked_in_logbook($callsign, $StationLocationsArray = $this->db->where("((COL_DISTANCE is NULL) or (COL_DISTANCE = 0))"); $this->db->where("COL_GRIDSQUARE is NOT NULL"); $this->db->where("COL_GRIDSQUARE != ''"); + $this->db->where("COL_GRIDSQUARE != station_gridsquare"); $this->db->trans_start(); $query = $this->db->get($this->config->item('table_name')); @@ -4117,7 +4118,6 @@ function check_if_callsign_worked_in_logbook($callsign, $StationLocationsArray = $this->db->select('COL_PRIMARY_KEY, COL_TIME_ON, COL_CALL, COL_MODE, COL_BAND'); $this->db->where('station_id =', NULL); $query = $this->db->get($this->config->item('table_name')); - log_message('debug','SQL: '.$this->db->last_query()); if($query->num_rows() >= 1) { return $query->result(); } else { diff --git a/application/views/components/hamsat/table.php b/application/views/components/hamsat/table.php index e218916f..0792824d 100644 --- a/application/views/components/hamsat/table.php +++ b/application/views/components/hamsat/table.php @@ -17,6 +17,7 @@