diff --git a/application/controllers/Dashboard.php b/application/controllers/Dashboard.php index 08e793a78..e74ceda30 100644 --- a/application/controllers/Dashboard.php +++ b/application/controllers/Dashboard.php @@ -2,7 +2,8 @@ class Dashboard extends CI_Controller { - const LAST_QSOS_COUNT = 18; // max number of most recent qsos to be displayed on a dashboard + const DEFAULT_QSOS_COUNT = 20; + const MAX_QSOS_COUNT_LIMIT = 50; public function index() { @@ -116,10 +117,20 @@ class Dashboard extends CI_Controller { $data['qrz_sent_today'] = $QSLStatsBreakdownArray['QRZ_Sent_today']; $data['qrz_rcvd_today'] = $QSLStatsBreakdownArray['QRZ_Received_today']; - $data['last_qsos_list'] = $this->logbook_model->get_last_qsos( - Dashboard::LAST_QSOS_COUNT, - $logbooks_locations_array, - ); + // Determine last (recent) QSO count to be fetched + $last_qso_count_opt = $this->user_options_model->get_options( + 'dashboard', + array('option_name' => 'last_qso_count', 'option_key' => 'count'), + $this->uri->segment(3) + )->result(); + if (count($last_qso_count_opt) > 0) { + // value found in user options - use it + $last_qso_count = $last_qso_count_opt[0]->option_value; + } else { + // value not found in user options - use default value + $last_qso_count = \Dashboard::DEFAULT_QSOS_COUNT; + } + $data['last_qsos_list'] = $this->logbook_model->get_last_qsos($last_qso_count, $logbooks_locations_array); $data['vucc'] = $this->vucc->fetchVuccSummary(); $data['vuccSAT'] = $this->vucc->fetchVuccSummary('SAT'); diff --git a/application/controllers/User.php b/application/controllers/User.php index af67c9b24..f9613085b 100644 --- a/application/controllers/User.php +++ b/application/controllers/User.php @@ -1,5 +1,7 @@ user_model->timezones(); + // Max value to be present in the "dashboard last QSO count" selectbox + $data['dashboard_last_qso_count_limit'] = \Dashboard::MAX_QSOS_COUNT_LIMIT; + if ($this->form_validation->run() == FALSE) { - $data['page_title'] = __("Edit User"); + // Prepare data and render the user options view + $data['page_title'] = __("Edit User"); // TODO this line will be pulled out as it is duplicated in both branches of if statement $q = $query->row(); @@ -752,10 +758,29 @@ class User extends CI_Controller { $data['user_locations_quickswitch'] = ($this->user_options_model->get_options('header_menu', array('option_name'=>'locations_quickswitch'), $this->uri->segment(3))->row()->option_value ?? 'false'); $data['user_utc_headermenu'] = ($this->user_options_model->get_options('header_menu', array('option_name'=>'utc_headermenu'), $this->uri->segment(3))->row()->option_value ?? 'false'); + if($this->input->post('user_dashboard_last_qso_count', true)) { + $data['user_dashboard_last_qso_count'] = $this->input->post('user_dashboard_last_qso_count', true); + } else { + // Determine last (recent) QSO count to preselect into the selectbox + $last_qso_count_opt = $this->user_options_model->get_options( + 'dashboard', + array('option_name' => 'last_qso_count', 'option_key' => 'count'), + $this->uri->segment(3) + )->result(); + if (count($last_qso_count_opt) > 0) { + // value found in user options - use it + $data['user_dashboard_last_qso_count'] = $last_qso_count_opt[0]->option_value; + } else { + // value not found in user options - use default value + $data['user_dashboard_last_qso_count'] = \Dashboard::DEFAULT_QSOS_COUNT; + } + } + $this->load->view('interface_assets/header', $data); $this->load->view('user/edit', $data); $this->load->view('interface_assets/footer', $footerData); } else { + // Data was submitted for saving - save updated options in DB unset($data); switch($this->user_model->edit($this->input->post())) { // Check for errors @@ -847,6 +872,7 @@ class User extends CI_Controller { $data['user_winkey'] = $this->input->post('user_winkey'); $data['user_hamsat_key'] = $this->input->post('user_hamsat_key'); $data['user_hamsat_workable_only'] = $this->input->post('user_hamsat_workable_only'); + $data['user_dashboard_last_qso_count'] = $this->input->post('user_dashboard_last_qso_count', true); $this->load->view('user/edit'); $this->load->view('interface_assets/footer'); } diff --git a/application/models/User_model.php b/application/models/User_model.php index 23aa6df9b..ce8d82e0c 100644 --- a/application/models/User_model.php +++ b/application/models/User_model.php @@ -1,5 +1,7 @@ xss_clean($fields['user_winkey']), ); + // Hard limit for last (recent) QSO count setting + $dashboard_last_qso_count = xss_clean($fields['user_dashboard_last_qso_count']); + $dashboard_last_qso_count = $dashboard_last_qso_count > \Dashboard::MAX_QSOS_COUNT_LIMIT ? \Dashboard::MAX_QSOS_COUNT_LIMIT : $dashboard_last_qso_count; + $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'])."');"); $this->db->query("replace into user_options (user_id, option_type, option_name, option_key, option_value) values (" . $fields['id'] . ", 'qso_tab','iota','show',".(xss_clean($fields['user_iota_to_qso_tab'] ?? 'off') == "on" ? 1 : 0).");"); @@ -333,6 +339,7 @@ class User_Model extends CI_Model { $this->db->query("replace into user_options (user_id, option_type, option_name, option_key, option_value) values (" . $fields['id'] . ", 'qso_tab','pota','show',".(xss_clean($fields['user_pota_to_qso_tab'] ?? 'off') == "on" ? 1 : 0).");"); $this->db->query("replace into user_options (user_id, option_type, option_name, option_key, option_value) values (" . $fields['id'] . ", 'qso_tab','sig','show',".(xss_clean($fields['user_sig_to_qso_tab'] ?? 'off') == "on" ? 1 : 0).");"); $this->db->query("replace into user_options (user_id, option_type, option_name, option_key, option_value) values (" . $fields['id'] . ", 'qso_tab','dok','show',".(xss_clean($fields['user_dok_to_qso_tab'] ?? 'off') == "on" ? 1 : 0).");"); + $this->db->query("replace into user_options (user_id, option_type, option_name, option_key, option_value) values (" . $fields['id'] . ", 'dashboard','last_qso_count','count','".$dashboard_last_qso_count."');"); // Check to see if the user is allowed to change user levels if($this->session->userdata('user_type') == 99) { diff --git a/application/views/dashboard/index.php b/application/views/dashboard/index.php index fc61de844..4bd5a2bcb 100644 --- a/application/views/dashboard/index.php +++ b/application/views/dashboard/index.php @@ -271,7 +271,22 @@ function getDistance($distance) { - + user_options_model->get_options( + 'dashboard', + array('option_name' => 'last_qso_count', 'option_key' => 'count'), + $this->uri->segment(3) + )->result(); + if (count($last_qso_count_opt) > 0) { + // value found in user options - use it + $last_qso_count = $last_qso_count_opt[0]->option_value; + } else { + // value not found in user options - use default value + $last_qso_count = \Dashboard::DEFAULT_QSOS_COUNT; + } + ?> + diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index 82f7f72c3..6079305f9 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -831,7 +831,22 @@ function showActivatorsMap(call, count, grids) { var grid = "No"; - + user_options_model->get_options( + 'dashboard', + array('option_name' => 'last_qso_count', 'option_key' => 'count'), + $this->uri->segment(3) + )->result(); + if (count($last_qso_count_opt) > 0) { + // value found in user options - use it + $last_qso_count = $last_qso_count_opt[0]->option_value; + } else { + // value not found in user options - use default value + $last_qso_count = \Dashboard::DEFAULT_QSOS_COUNT; + } + ?> + initmap(grid,'map',{'dataPost':{'nb_qso': dashboard_qso_count}});