From d1e11455e4eca2972858ebc8c1bf326460320a3b Mon Sep 17 00:00:00 2001 From: HB9HIL Date: Fri, 9 Feb 2024 11:05:28 +0100 Subject: [PATCH] quickswitch feature --- application/controllers/Station.php | 160 ++++++++++-------- application/controllers/User.php | 25 +-- application/views/interface_assets/footer.php | 21 ++- application/views/interface_assets/header.php | 43 +++-- application/views/station_profile/index.php | 25 ++- application/views/user/edit.php | 13 ++ 6 files changed, 190 insertions(+), 97 deletions(-) diff --git a/application/controllers/Station.php b/application/controllers/Station.php index e23b55f4b..5c8b5d6a8 100644 --- a/application/controllers/Station.php +++ b/application/controllers/Station.php @@ -1,10 +1,11 @@ -load->helper(array('form', 'url')); $this->load->model('user_model'); - if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); } + if (!$this->user_model->authorize(2)) { + $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); + redirect('dashboard'); + } } public function index() @@ -34,7 +38,8 @@ class Station extends CI_Controller { $this->load->view('interface_assets/footer'); } - public function create() { + public function create() + { $this->load->model('stations'); $this->load->model('dxcc'); $data['dxcc_list'] = $this->dxcc->list(); @@ -46,28 +51,26 @@ class Station extends CI_Controller { $this->form_validation->set_rules('station_profile_name', 'Station Profile Name', 'required'); - if ($this->form_validation->run() == FALSE) - { + if ($this->form_validation->run() == FALSE) { $data['page_title'] = lang('station_location_create_header'); $this->load->view('interface_assets/header', $data); $this->load->view('station_profile/create'); $this->load->view('interface_assets/footer'); - } - else - { + } else { if (($station_id = $this->stations->add()) !== false) { // [eQSL default msg] ADD to user options (option_type='eqsl_default_qslmsg'; option_name='key_station_id'; option_key=station_id; option_value=value) // $eqsl_default_qslmsg = xss_clean($this->input->post('eqsl_default_qslmsg', true)); if (!empty(trim($eqsl_default_qslmsg))) { $this->load->model('user_options_model'); - $this->user_options_model->set_option('eqsl_default_qslmsg','key_station_id',array($station_id=>$eqsl_default_qslmsg)); + $this->user_options_model->set_option('eqsl_default_qslmsg', 'key_station_id', array($station_id => $eqsl_default_qslmsg)); } } redirect('station'); } } - public function edit($id) { + public function edit($id) + { $this->load->model('stations'); if ($this->stations->check_station_is_accessible($id)) { $data = $this->load_station_for_editing($id); @@ -76,8 +79,8 @@ class Station extends CI_Controller { if ($this->form_validation->run() == FALSE) { // [eQSL default msg] GET from user options (option_type='eqsl_default_qslmsg'; option_name='key_station_id'; option_key=station_id) // $this->load->model('user_options_model'); - $options_object = $this->user_options_model->get_options('eqsl_default_qslmsg',array('option_name'=>'key_station_id','option_key'=>$id))->result(); - $data['eqsl_default_qslmsg'] = (isset($options_object[0]->option_value))?$options_object[0]->option_value:''; + $options_object = $this->user_options_model->get_options('eqsl_default_qslmsg', array('option_name' => 'key_station_id', 'option_key' => $id))->result(); + $data['eqsl_default_qslmsg'] = (isset($options_object[0]->option_value)) ? $options_object[0]->option_value : ''; $this->load->view('interface_assets/header', $data); $this->load->view('station_profile/edit'); @@ -88,10 +91,10 @@ class Station extends CI_Controller { $eqsl_default_qslmsg = xss_clean($this->input->post('eqsl_default_qslmsg', true)); $this->load->model('user_options_model'); if (!empty(trim($eqsl_default_qslmsg))) { - $this->user_options_model->set_option('eqsl_default_qslmsg','key_station_id',array($id=>$eqsl_default_qslmsg)); + $this->user_options_model->set_option('eqsl_default_qslmsg', 'key_station_id', array($id => $eqsl_default_qslmsg)); } else { - $this->user_options_model->del_option('eqsl_default_qslmsg','key_station_id',array('option_key'=>$id)); - } + $this->user_options_model->del_option('eqsl_default_qslmsg', 'key_station_id', array('option_key' => $id)); + } } $data['notice'] = lang('station_location') . $this->security->xss_clean($this->input->post('station_profile_name', true)) . " Updated"; @@ -103,7 +106,8 @@ class Station extends CI_Controller { } } - public function copy($id) { + public function copy($id) + { $this->load->model('stations'); if ($this->stations->check_station_is_accessible($id)) { $data = $this->load_station_for_editing($id); @@ -114,14 +118,11 @@ class Station extends CI_Controller { $data['my_station_profile']->station_id = NULL; $data['my_station_profile']->station_profile_name = ''; - if ($this->form_validation->run() == FALSE) - { + if ($this->form_validation->run() == FALSE) { $this->load->view('interface_assets/header', $data); $this->load->view('station_profile/edit'); $this->load->view('interface_assets/footer'); - } - else - { + } else { $this->stations->add(); redirect('station'); @@ -131,7 +132,19 @@ class Station extends CI_Controller { } } - function load_station_for_editing($id): array { + public function edit_favorite($id) + { + $is_favorite = $this->user_options_model->get_options('station_location', array('option_name'=>'is_favorite', 'option_key'=>$id))->row()->option_value ?? 'false'; + if ($is_favorite == 'true') { + $this->user_options_model->del_option('station_location', 'is_favorite', array('option_key'=>$id)); + } else if ($is_favorite == 'false') { + $this->user_options_model->set_option('station_location', 'is_favorite', array($id=>'true')); + } + redirect('station'); + } + + function load_station_for_editing($id): array + { $this->load->library('form_validation'); $this->load->model('stations'); @@ -154,7 +167,8 @@ class Station extends CI_Controller { } - function reassign_profile($id) { + function reassign_profile($id) + { // $id is the profile that needs reassigned to QSOs // ONLY Admin can do that! $this->load->model('stations'); if ($this->user_model->authorize(99)) { @@ -165,78 +179,86 @@ class Station extends CI_Controller { redirect('station'); } - function set_active($current, $new) { + function set_active($current, $new, $is_ajax = null) + { $this->load->model('stations'); $this->stations->set_active($current, $new); - - //$this->stations->logbook_session_data(); + + if ($is_ajax != null) { + return; + } + redirect('station'); } - public function delete($id) { + public function delete($id) + { $this->load->model('stations'); if ($this->stations->check_station_is_accessible($id)) { $this->stations->delete($id); // [eQSL default msg] DELETE user options // $this->load->model('user_options_model'); - $this->user_options_model->del_option('eqsl_default_qslmsg','key_station_id',array('option_key'=>$id)); + $this->user_options_model->del_option('eqsl_default_qslmsg', 'key_station_id', array('option_key' => $id)); } redirect('station'); } - public function deletelog($id) { - $this->load->model('stations'); - if ($this->stations->check_station_is_accessible($id)) { - $this->stations->deletelog($id); + public function deletelog($id) + { + $this->load->model('stations'); + if ($this->stations->check_station_is_accessible($id)) { + $this->stations->deletelog($id); + } + redirect('station'); } - redirect('station'); - } - /* + /* * Function is used for autocompletion of Counties in the station profile form */ - public function get_county() { - $json = []; + public function get_county() + { + $json = []; - if(!empty($this->input->get("query"))) { - $query = isset($_GET['query']) ? $_GET['query'] : FALSE; - $county = $this->input->get("state"); + if (!empty($this->input->get("query"))) { + $query = isset($_GET['query']) ? $_GET['query'] : FALSE; + $county = $this->input->get("state"); - $file = 'assets/json/US_counties.csv'; + $file = 'assets/json/US_counties.csv'; - if (is_readable($file)) { - $lines = file($file, FILE_IGNORE_NEW_LINES); - $input = preg_quote($county, '~'); - $reg = '~^'. $input .'(.*)$~'; - $result = preg_grep($reg, $lines); - $json = []; - $i = 0; - foreach ($result as &$value) { - $county = explode(',', $value); - // Limit to 300 as to not slowdown browser too much - if (count($json) <= 300) { - $json[] = ["name"=>$county[1]]; - } - } - } - } + if (is_readable($file)) { + $lines = file($file, FILE_IGNORE_NEW_LINES); + $input = preg_quote($county, '~'); + $reg = '~^' . $input . '(.*)$~'; + $result = preg_grep($reg, $lines); + $json = []; + $i = 0; + foreach ($result as &$value) { + $county = explode(',', $value); + // Limit to 300 as to not slowdown browser too much + if (count($json) <= 300) { + $json[] = ["name" => $county[1]]; + } + } + } + } - header('Content-Type: application/json'); - echo json_encode($json); - } + header('Content-Type: application/json'); + echo json_encode($json); + } - // [eQSL default msg] Function return options from this station (but can be general use) // - public function get_options() { + // [eQSL default msg] Function return options from this station (but can be general use) // + public function get_options() + { $return_json = array(); $option_type = $this->input->post('option_type'); $option_name = $this->input->post('option_name'); $option_key = $this->input->post('option_key'); - if (!empty($option_type) && !empty($option_name) && ($option_key>0)) { + if (!empty($option_type) && !empty($option_name) && ($option_key > 0)) { $this->load->model('user_options_model'); - $options_object = $this->user_options_model->get_options($option_type,array('option_name'=>$option_name,'option_key'=>$option_key))->result(); - $return_json[$option_type] = (isset($options_object[0]->option_value))?$options_object[0]->option_value:''; + $options_object = $this->user_options_model->get_options($option_type, array('option_name' => $option_name, 'option_key' => $option_key))->result(); + $return_json[$option_type] = (isset($options_object[0]->option_value)) ? $options_object[0]->option_value : ''; } - header('Content-Type: application/json'); - echo json_encode($return_json); - } + header('Content-Type: application/json'); + echo json_encode($return_json); + } } diff --git a/application/controllers/User.php b/application/controllers/User.php index 2a5840f49..5d5442bac 100644 --- a/application/controllers/User.php +++ b/application/controllers/User.php @@ -492,7 +492,6 @@ class User extends CI_Controller { } // [MAP Custom] GET user options // - $this->load->model('user_options_model'); $options_object = $this->user_options_model->get_options('map_custom')->result(); if (count($options_object)>0) { foreach ($options_object as $row) { @@ -522,6 +521,8 @@ class User extends CI_Controller { 'station'=>array('0', 'fas fa-home', 'fas fa-broadcast-tower', 'fas fa-user', 'fas fa-dot-circle' ), 'qso'=>array('fas fa-broadcast-tower', 'fas fa-user', 'fas fa-dot-circle' ), 'qsoconfirm'=>array('0', 'fas fa-broadcast-tower', 'fas fa-user', 'fas fa-dot-circle', 'fas fa-check-circle' )); + + $data['user_locations_quickswitch'] = ($this->user_options_model->get_options('header_menu', array('option_name'=>'locations_quickswitch'))->row()->option_value ?? 'false'); $this->load->view('interface_assets/header', $data); $this->load->view('user/edit', $data); @@ -559,7 +560,6 @@ class User extends CI_Controller { $data_options['user_map_'.$icon.'_icon'] = xss_clean($this->input->post('user_map_'.$icon.'_icon', true)); $data_options['user_map_'.$icon.'_color'] = xss_clean($this->input->post('user_map_'.$icon.'_color', true)); } - $this->load->model('user_options_model'); if (!empty($data_options['user_map_qso_icon'])) { foreach ($array_icon as $icon) { $json = json_encode(array('icon'=>$data_options['user_map_'.$icon.'_icon'], 'color'=>$data_options['user_map_'.$icon.'_color'])); @@ -570,7 +570,7 @@ class User extends CI_Controller { $this->user_options_model->del_option('map_custom','icon'); $this->user_options_model->del_option('map_custom','gridsquare'); } - + $this->user_options_model->set_option('header_menu', 'locations_quickswitch', array('boolean'=>xss_clean($this->input->post('user_locations_quickswitch', true)))); $this->session->set_flashdata('success', lang('account_user').' '.$this->input->post('user_name', true).' '.lang('account_word_edited')); redirect('user/edit/'.$this->uri->segment(3)); } else { @@ -612,6 +612,7 @@ class User extends CI_Controller { $data['user_qso_end_times'] = $this->input->post('user_qso_end_times'); $data['user_quicklog'] = $this->input->post('user_quicklog'); $data['user_quicklog_enter'] = $this->input->post('user_quicklog_enter'); + $data['user_locations_quickswitch'] = $this->input->post('user_locations_quickswitch', true); $data['language'] = $this->input->post('language'); $data['user_winkey'] = $this->input->post('user_winkey'); $this->load->view('user/edit'); @@ -623,15 +624,15 @@ class User extends CI_Controller { $this->load->model('user_model'); if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); } $query = $this->user_model->get_by_id($this->session->userdata('user_id')); - $q = $query->row(); - $data['page_title'] = "Profile"; - $data['user_name'] = $q->user_name; - $data['user_type'] = $q->user_type; - $data['user_email'] = $q->user_email; - $data['user_firstname'] = $q->user_firstname; - $data['user_lastname'] = $q->user_lastname; - $data['user_callsign'] = $q->user_callsign; - $data['user_locator'] = $q->user_locator; + $q = $query->row(); + $data['page_title'] = "Profile"; + $data['user_name'] = $q->user_name; + $data['user_type'] = $q->user_type; + $data['user_email'] = $q->user_email; + $data['user_firstname'] = $q->user_firstname; + $data['user_lastname'] = $q->user_lastname; + $data['user_callsign'] = $q->user_callsign; + $data['user_locator'] = $q->user_locator; $this->load->view('interface_assets/header', $data); $this->load->view('user/profile'); diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index 958961eb3..8d6b03dbc 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -92,6 +92,24 @@ if($this->session->userdata('user_id') != null) { + + uri->segment(1) == "oqrs") { ?> @@ -977,9 +995,6 @@ $($('#callsign')).on('keypress',function(e) { load->model('stations'); $active_station_id = $this->stations->find_active(); $station_profile = $this->stations->profile($active_station_id); $active_station_info = $station_profile->row(); diff --git a/application/views/interface_assets/header.php b/application/views/interface_assets/header.php index 5bb282630..407aa36aa 100644 --- a/application/views/interface_assets/header.php +++ b/application/views/interface_assets/header.php @@ -293,11 +293,37 @@