diff --git a/application/config/migration.php b/application/config/migration.php index 70bc112e..51eebc64 100644 --- a/application/config/migration.php +++ b/application/config/migration.php @@ -22,7 +22,7 @@ $config['migration_enabled'] = TRUE; | */ -$config['migration_version'] = 137; +$config['migration_version'] = 138; /* |-------------------------------------------------------------------------- diff --git a/application/controllers/User_options.php b/application/controllers/User_options.php new file mode 100755 index 00000000..3aa337de --- /dev/null +++ b/application/controllers/User_options.php @@ -0,0 +1,52 @@ +load->model('user_model'); + $this->load->model('user_options_model'); + if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); } + } + + public function add_edit_fav() { + $obj = json_decode(file_get_contents("php://input"), true); + foreach($obj as $option_key => $option_value) { + $obj[$option_key]=$this->security->xss_clean($option_value); + } + if ($obj['sat_name'] ?? '' != '') { + $option_name=$obj['sat_name'].'/'.$obj['mode']; + } else { + $option_name=$obj['band'].'/'.$obj['mode']; + } + $this->user_options_model->set_option('Favourite',$option_name, $obj); + $jsonout['success']=1; + header('Content-Type: application/json'); + echo json_encode($jsonout); + } + + public function get_fav() { + $result=$this->user_options_model->get_options('Favourite'); + $jsonout=[]; + foreach($result->result() as $options) { + $jsonout[$options->option_name][$options->option_key]=$options->option_value; + } + header('Content-Type: application/json'); + echo json_encode($jsonout); + } + + public function del_fav() { + $result=$this->user_options_model->get_options('Favourite'); + $obj = json_decode(file_get_contents("php://input"), true); + if ($obj['option_name'] ?? '' != '') { + $option_name=$this->security->xss_clean($obj['option_name']); + $this->user_options_model->del_option('Favourite',$option_name); + } + $jsonout['success']=1; + header('Content-Type: application/json'); + echo json_encode($jsonout); + } +} + + +?> diff --git a/application/language/english/qso_lang.php b/application/language/english/qso_lang.php index 3b27929f..c8acea22 100644 --- a/application/language/english/qso_lang.php +++ b/application/language/english/qso_lang.php @@ -32,3 +32,4 @@ $lang['qso_btn_edit_qso'] = 'Edit QSO'; // QSO Details $lang['qso_details'] = 'QSO Details'; +$lang['fav_add'] = 'Add Band/Mode to Favs'; diff --git a/application/language/german/qso_lang.php b/application/language/german/qso_lang.php index 0f1b0949..d7dfd357 100644 --- a/application/language/german/qso_lang.php +++ b/application/language/german/qso_lang.php @@ -32,3 +32,5 @@ $lang['qso_btn_edit_qso'] = 'Editiere QSO'; // QSO Details $lang['qso_details'] = 'QSO Details'; + +$lang['fav_add'] = 'Band/Mode zu Favoriten hinzufügen'; diff --git a/application/migrations/138_user_options_table.php b/application/migrations/138_user_options_table.php new file mode 100644 index 00000000..8961d37d --- /dev/null +++ b/application/migrations/138_user_options_table.php @@ -0,0 +1,19 @@ +db->table_exists('user_options')) { + $this->db->query("CREATE TABLE `user_options` ( `user_id` int(11) NOT NULL, `option_type` varchar(45) NOT NULL, `option_name` varchar(45) NOT NULL, `option_key` varchar(45) NOT NULL, `option_value` varchar(45) DEFAULT NULL, PRIMARY KEY (`user_id`,`option_type`,`option_key`,`option_name`))"); + } + + } + + public function down(){ + if ($this->db->table_exists('user_options')) { + $this->dbforge->drop_table('user_options'); + } + } +} diff --git a/application/models/User_options_model.php b/application/models/User_options_model.php new file mode 100644 index 00000000..9a383338 --- /dev/null +++ b/application/models/User_options_model.php @@ -0,0 +1,33 @@ +db->where('user_id', $this->session->userdata('user_id')); + $this->db->where('option_type', $option_type); + return $this->db->get('user_options'); + } + + public function set_option($option_type, $option_name, $option_array) { + $uid=$this->session->userdata('user_id'); + $sql='insert into user_options (user_id,option_type,option_name,option_key,option_value) values (?,?,?,?,?) ON DUPLICATE KEY UPDATE option_value=?'; + foreach($option_array as $option_key => $option_value) { + $query = $this->db->query($sql, array($uid, $option_type, $option_name, $option_key, $option_value, $option_value)); + } + } + + public function get_options($option_type) { + $uid=$this->session->userdata('user_id'); + $sql='select option_name,option_key,option_value from user_options where user_id=? and option_type=?'; + return $this->db->query($sql, array($uid, $option_type)); + } + + public function del_option($option_type, $option_name) { + $uid=$this->session->userdata('user_id'); + $sql='delete from user_options where user_id=? and option_type=? and option_name=?'; + return $this->db->query($sql, array($uid, $option_type,$option_name)); + } + +} + +?> diff --git a/application/views/qso/index.php b/application/views/qso/index.php index 4a8ac031..a977cc9b 100755 --- a/application/views/qso/index.php +++ b/application/views/qso/index.php @@ -34,7 +34,17 @@