diff --git a/application/config/migration.php b/application/config/migration.php
index 574240d66..c52d5d72d 100644
--- a/application/config/migration.php
+++ b/application/config/migration.php
@@ -22,7 +22,7 @@ $config['migration_enabled'] = TRUE;
|
*/
-$config['migration_version'] = 186;
+$config['migration_version'] = 185;
/*
|--------------------------------------------------------------------------
diff --git a/application/controllers/Components.php b/application/controllers/Components.php
index c5401ec6f..63d807188 100644
--- a/application/controllers/Components.php
+++ b/application/controllers/Components.php
@@ -13,28 +13,39 @@ class Components extends CI_Controller {
if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); }
}
- public function index() {
- $this->load->model('stations');
- $url = 'https://hams.at/api/alerts/upcoming';
- $hamsat_key = '';
- if ($this->session->userdata('user_hamsat_key') != '') {
- $hamsat_key = $this->session->userdata('user_hamsat_key');
- $options = array(
- 'http' => array(
- 'method' => 'GET',
- 'header' => "Authorization: Bearer ".$hamsat_key."\r\n"
- )
- );
- $context = stream_context_create($options);
- $json = file_get_contents($url, false, $context);
- } else {
- $json = file_get_contents($url);
- }
- $data['rovedata'] = json_decode($json, true);
- $data['workable_only'] = $this->session->userdata('user_hamsat_workable_only');
- $data['gridsquare'] = strtoupper($this->stations->find_gridsquare());
+ public function index() {
+ $this->load->model("user_options_model");
+ $hkey_opt=$this->user_options_model->get_options('hamsat',array('option_name'=>'hamsat_key','option_key'=>'api'))->result();
+ if (count($hkey_opt)>0) {
+ $data['user_hamsat_key'] = $hkey_opt[0]->option_value;
+ } else {
+ $data['user_hamsat_key']='';
+ }
+ $url = 'https://hams.at/api/alerts/upcoming';
+ if ($data['user_hamsat_key'] ?? '' != '') {
+ $options = array(
+ 'http' => array(
+ 'method' => 'GET',
+ 'header' => "Authorization: Bearer ".$data['user_hamsat_key']."\r\n"
+ )
+ );
+ $context = stream_context_create($options);
+ $json = file_get_contents($url, false, $context);
+ } else {
+ $json = file_get_contents($url);
+ }
+ $hkey_opt=$this->user_options_model->get_options('hamsat',array('option_name'=>'hamsat_key','option_key'=>'workable'))->result();
+ if (count($hkey_opt)>0) {
+ $data['user_hamsat_workable_only'] = $hkey_opt[0]->option_value;
+ } else {
+ $data['user_hamsat_workable_only'] = 0;
+ }
- // load view
- $this->load->view('components/hamsat/table', $data);
- }
+ $this->load->model('stations');
+ $data['rovedata'] = json_decode($json, true);
+ $data['gridsquare'] = strtoupper($this->stations->find_gridsquare());
+
+ // load view
+ $this->load->view('components/hamsat/table', $data);
+ }
}
diff --git a/application/controllers/User.php b/application/controllers/User.php
index 1f517cea6..4b99291cc 100644
--- a/application/controllers/User.php
+++ b/application/controllers/User.php
@@ -498,13 +498,21 @@ class User extends CI_Controller {
if($this->input->post('user_hamsat_key', true)) {
$data['user_hamsat_key'] = $this->input->post('user_hamsat_key', true);
} else {
- $data['user_hamsat_key'] = $q->hamsat_key;
+ $hkey_opt=$this->user_options_model->get_options('hamsat',array('option_name'=>'hamsat_key','option_key'=>'api'))->result();
+ if (count($hkey_opt)>0) {
+ $data['user_hamsat_key'] = $hkey_opt[0]->option_value;
+ } else {
+ $data['user_hamsat_key'] = '';
+ }
}
if($this->input->post('user_hamsat_workable_only')) {
$data['user_hamsat_workable_only'] = $this->input->post('user_hamsat_workable_only', false);
} else {
- $data['user_hamsat_workable_only'] = $q->hamsat_workable_only;
+ $hkey_opt=$this->user_options_model->get_options('hamsat',array('option_name'=>'hamsat_key','option_key'=>'workable'))->result();
+ if (count($hkey_opt)>0) {
+ $data['user_hamsat_workable_only'] = $hkey_opt[0]->option_value;
+ }
}
// [MAP Custom] GET user options //
diff --git a/application/migrations/186_user_hamsat_workable_option.php b/application/migrations/186_user_hamsat_workable_option.php
deleted file mode 100644
index bba5e8298..000000000
--- a/application/migrations/186_user_hamsat_workable_option.php
+++ /dev/null
@@ -1,39 +0,0 @@
-db->field_exists('hamsat_key', 'users')) {
- $fields = array(
- 'hamsat_key VARCHAR(36) DEFAULT ""',
- );
- $this->dbforge->add_column('users', $fields);
- }
- if (!$this->db->field_exists('hamsat_workable_only', 'users')) {
- $fields = array(
- 'hamsat_workable_only BOOLEAN DEFAULT FALSE',
- );
- $this->dbforge->add_column('users', $fields);
- }
- }
-
- public function down()
- {
- if ($this->db->field_exists('hamsat_key', 'users')) {
- $this->dbforge->drop_column('users', 'hamsat_key');
- }
- if ($this->db->field_exists('hamsat_workable_only', 'users')) {
- $this->dbforge->drop_column('users', 'hamsat_workable_only');
- }
- }
-}
diff --git a/application/models/User_model.php b/application/models/User_model.php
index c260a8c0d..2639bc8cd 100644
--- a/application/models/User_model.php
+++ b/application/models/User_model.php
@@ -185,9 +185,7 @@ class User_Model extends CI_Model {
'user_qso_end_times' => xss_clean($user_qso_end_times),
'user_quicklog' => xss_clean($user_quicklog),
'user_quicklog_enter' => xss_clean($user_quicklog_enter),
- 'language' => xss_clean($language),
- 'hamsat_key' => xss_clean($user_hamsat_key),
- 'hamsat_workable_only' => xss_clean($user_hamsat_workable_only),
+ 'language' => xss_clean($language)
);
// Check the password is valid
@@ -210,6 +208,8 @@ class User_Model extends CI_Model {
$this->db->query("insert into user_options (user_id, option_type, option_name, option_key, option_value) values (" . $insert_id . ", 'map_custom','icon','qsoconfirm','{\"icon\":\"fas fa-dot-circle\",\"color\":\"#00ff00\"}');");
$this->db->query("insert into user_options (user_id, option_type, option_name, option_key, option_value) values (" . $insert_id . ", 'map_custom','icon','station','{\"icon\":\"fas fa-broadcast-tower\",\"color\":\"#0000ff\"}');");
$this->db->query("insert into user_options (user_id, option_type, option_name, option_key, option_value) values (" . $insert_id . ", 'map_custom','gridsquare','show','0');");
+ $this->db->query("insert into user_options (user_id, option_type, option_name, option_key, option_value) values (" . $insert_id . ", 'hamsat','hamsat_key','api','".xss_clean($user_hamsat_key)."');");
+ $this->db->query("insert into user_options (user_id, option_type, option_name, option_key, option_value) values (" . $insert_id . ", 'hamsat','hamsat_key','workable','".xss_clean($user_hamsat_workable_only)."');");
return OK;
} else {
@@ -259,10 +259,11 @@ class User_Model extends CI_Model {
'user_quicklog_enter' => xss_clean($fields['user_quicklog_enter']),
'language' => xss_clean($fields['language']),
'winkey' => xss_clean($fields['user_winkey']),
- 'hamsat_key' => xss_clean($fields['user_hamsat_key']),
- 'hamsat_workable_only' => xss_clean($fields['user_hamsat_workable_only']),
);
+ $this->db->query("replace into user_options (user_id, option_type, option_name, option_key, option_value) values (" . $fields['id'] . ", 'hamsat','hamsat_key','api','".xss_clean($fields['user_hamsat_key'])."');");
+ $this->db->query("replace into user_options (user_id, option_type, option_name, option_key, option_value) values (" . $fields['id'] . ", 'hamsat','hamsat_key','workable','".xss_clean($fields['user_hamsat_workable_only'])."');");
+
// Check to see if the user is allowed to change user levels
if($this->session->userdata('user_type') == 99) {
$data['user_type'] = $fields['user_type'];
@@ -319,6 +320,7 @@ class User_Model extends CI_Model {
if($this->exists_by_id($user_id)) {
$this->db->query("DELETE FROM ".$this->config->item('auth_table')." WHERE user_id = '".$user_id."'");
+ $this->db->query("delete from user_options where user_id=?",$user_id);
return 1;
} else {
@@ -391,9 +393,7 @@ class User_Model extends CI_Model {
'active_station_logbook' => $u->row()->active_station_logbook,
'language' => isset($u->row()->language) ? $u->row()->language: 'english',
'isWinkeyEnabled' => $u->row()->winkey,
- 'hasQrzKey' => $this->hasQrzKey($u->row()->user_id),
- 'user_hamsat_key' => $u->row()->hamsat_key,
- 'user_hamsat_workable_only' => isset($u->row()->hamsat_workable_only) ? $u->row()->hamsat_workable_only: 0,
+ 'hasQrzKey' => $this->hasQrzKey($u->row()->user_id)
);
$this->session->set_userdata($userdata);
diff --git a/application/models/User_options_model.php b/application/models/User_options_model.php
index f5cff23ef..1c4cacd53 100644
--- a/application/models/User_options_model.php
+++ b/application/models/User_options_model.php
@@ -33,8 +33,10 @@ class User_options_model extends CI_Model {
}
}
- public function get_options($option_type, $option_array=null) {
- $uid=$this->session->userdata('user_id');
+ public function get_options($option_type, $option_array=null, $uid=null) {
+ if ($uid ?? '' == '') {
+ $uid=$this->session->userdata('user_id');
+ }
$sql_more = "";
$array_sql_value = array($uid, $option_type);
if (is_array($option_array)) {
diff --git a/application/views/components/hamsat/table.php b/application/views/components/hamsat/table.php
index 629ad339a..8238d644a 100644
--- a/application/views/components/hamsat/table.php
+++ b/application/views/components/hamsat/table.php
@@ -2,13 +2,13 @@
This data is from https://hams.at/. -
- session->userdata('user_hamsat_key') == '') { ?> +