mirror of
https://github.com/wavelog/wavelog.git
synced 2026-03-22 10:24:14 +00:00
Refactored to user_options_table
This commit is contained in:
@@ -22,7 +22,7 @@ $config['migration_enabled'] = TRUE;
|
||||
|
|
||||
*/
|
||||
|
||||
$config['migration_version'] = 186;
|
||||
$config['migration_version'] = 185;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 //
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Class Migration_amsat_status_upload_option
|
||||
*
|
||||
* Creates a boolean column with option to allow for activating uploading
|
||||
* a status info to https://amsat.org/status
|
||||
*/
|
||||
|
||||
class Migration_user_hamsat_workable_option extends CI_Migration {
|
||||
|
||||
public function up()
|
||||
{
|
||||
if (!$this->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');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
<br>
|
||||
<h2>Hamsat - Satellite Rovers</h2>
|
||||
<p>This data is from <a target="_blank" href="https://hams.at/">https://hams.at/</a>.
|
||||
<?php if ($workable_only) {
|
||||
<?php if ($user_hamsat_workable_only) {
|
||||
echo " Only workable passes shown.";
|
||||
} else {
|
||||
echo " All passes shown.";
|
||||
}?>
|
||||
</p>
|
||||
<?php if ($workable_only && $this->session->userdata('user_hamsat_key') == '') { ?>
|
||||
<?php if ($user_hamsat_workable_only && $user_hamsat_key == '') { ?>
|
||||
<div class="alert alert-warning" role="warning">
|
||||
Private feed key empty. Please set the feed key in your profile.
|
||||
</div>
|
||||
@@ -35,7 +35,7 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($rovedata['data'] as $rove) :
|
||||
if ($workable_only) {
|
||||
if ($user_hamsat_workable_only) {
|
||||
if (!$rove['is_workable']) {
|
||||
continue;
|
||||
}
|
||||
@@ -119,7 +119,7 @@
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
if ($this->session->userdata('user_hamsat_key') != '') {
|
||||
if ($user_hamsat_key != '') {
|
||||
if ($rove['is_workable']) {
|
||||
echo date("H:i", strtotime($rove['workable_start_at']))." - ".date("H:i", strtotime($rove['workable_end_at']));
|
||||
} else {
|
||||
@@ -141,7 +141,7 @@
|
||||
?>
|
||||
<td>
|
||||
<?php
|
||||
if ($rove['is_workable'] || $this->session->userdata('user_hamsat_key') == '') { ?>
|
||||
if ($rove['is_workable'] || $user_hamsat_key == '') { ?>
|
||||
<a href="https://sat.fg8oj.com/sked.php?s%5B%5D=<?php echo $sat; ?>&l=<?php echo strtoupper($gridsquare); ?>&el1=0&l2=<?php echo $rove['grids'][0]; ?>&el2=0&duration=1&start=0&OK=Search" target="_blank">Sked</a>
|
||||
<?php } ?>
|
||||
</td>
|
||||
|
||||
Reference in New Issue
Block a user