From b710ccd388f9955f3619933235fada1dc9ce725d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Mel=C3=ADk?= Date: Wed, 29 Jan 2025 19:55:47 +0100 Subject: [PATCH 1/6] Add dashboard QSO count setting into the Edit user page --- application/views/user/edit.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/application/views/user/edit.php b/application/views/user/edit.php index 3e6b5c17d..bb45fab30 100644 --- a/application/views/user/edit.php +++ b/application/views/user/edit.php @@ -590,6 +590,23 @@ + +
+
+
+
+
+ + +
+
+
+
From c1272695518bdf5bfefa1d326d02df1d4e815eee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Mel=C3=ADk?= Date: Wed, 29 Jan 2025 20:00:27 +0100 Subject: [PATCH 2/6] Add comments --- application/controllers/User.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/application/controllers/User.php b/application/controllers/User.php index bb4021b47..1f5f62509 100644 --- a/application/controllers/User.php +++ b/application/controllers/User.php @@ -375,6 +375,7 @@ class User extends CI_Controller { if ($this->form_validation->run() == FALSE) { + // Prepare data and render the user options view $q = $query->row(); $data['id'] = $q->user_id; @@ -754,6 +755,7 @@ class User extends CI_Controller { $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 From 441165d3961e1dca98ff97db782eb7ee2fb20922 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Mel=C3=ADk?= Date: Wed, 29 Jan 2025 20:43:47 +0100 Subject: [PATCH 3/6] Save 'dashobard last qso count' setting when editing and adding user --- application/controllers/User.php | 25 +++++++++++++++++++++++++ application/models/User_model.php | 8 ++++++++ 2 files changed, 33 insertions(+) diff --git a/application/controllers/User.php b/application/controllers/User.php index 1f5f62509..e04b4469e 100644 --- a/application/controllers/User.php +++ b/application/controllers/User.php @@ -177,6 +177,10 @@ class User extends CI_Controller { $data['timezones'] = $this->user_model->timezones(); $data['user_language'] = 'english'; + // Values for the "dashboard last QSO count" selectbox + $data['dashboard_last_qso_count_limit'] = \User_Model::DASHBOARD_QSOS_COUNT_LIMIT; + $data['user_dashboard_last_qso_count'] = \User_Model::DASHBOARD_DEFAULT_QSOS_COUNT; + if ($this->form_validation->run() == FALSE) { $data['page_title'] = __("Add User"); $data['measurement_base'] = $this->config->item('measurement_base'); @@ -371,6 +375,9 @@ class User extends CI_Controller { // Get timezones $data['timezones'] = $this->user_model->timezones(); + // Max value to be present in the "dashboard last QSO count" selectbox + $data['dashboard_last_qso_count_limit'] = \User_Model::DASHBOARD_QSOS_COUNT_LIMIT; + $data['page_title'] = __("Edit User"); if ($this->form_validation->run() == FALSE) @@ -751,6 +758,23 @@ 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) { + $data['user_dashboard_last_qso_count'] = $last_qso_count_opt[0]->option_value; + } else { + $data['user_dashboard_last_qso_count'] = \User_Model::DASHBOARD_DEFAULT_QSOS_COUNT; + } + } + $this->load->view('interface_assets/header', $data); $this->load->view('user/edit', $data); $this->load->view('interface_assets/footer', $footerData); @@ -846,6 +870,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..d69366872 100644 --- a/application/models/User_model.php +++ b/application/models/User_model.php @@ -13,6 +13,9 @@ class User_Model extends CI_Model { + const DASHBOARD_DEFAULT_QSOS_COUNT = 20; // number of last QSOs used, if user has no value in settings yet + const DASHBOARD_QSOS_COUNT_LIMIT = 50; // hard limit for max number of QSOs shown on dashboard + // FUNCTION: object get($username) // Retrieve a user function get($username) { @@ -325,6 +328,10 @@ class User_Model extends CI_Model { 'winkey' => xss_clean($fields['user_winkey']), ); + // Hard limit safety check 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 > self::DASHBOARD_QSOS_COUNT_LIMIT ? self::DASHBOARD_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 +340,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) { From d6f975f011a6a717945d9c90b86a51ba47cbe346 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Mel=C3=ADk?= Date: Wed, 29 Jan 2025 21:07:28 +0100 Subject: [PATCH 4/6] HELP NEEDED - Cache dashboard last QSO setting to session --- application/models/User_model.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/application/models/User_model.php b/application/models/User_model.php index d69366872..e01671db5 100644 --- a/application/models/User_model.php +++ b/application/models/User_model.php @@ -524,6 +524,13 @@ class User_Model extends CI_Model { 'hasQrzKey' => $this->hasQrzKey($u->row()->user_id), 'impersonate' => $this->session->userdata('impersonate') ?? false, 'clubstation' => $u->row()->clubstation, + // TODO FIND THE BUG + // when user logs in, the $this->user_options_model->get_options is returning 0 rows for some reason. + // so the code falls back to DASHBOARD_DEFAULT_QSOS_COUNT, and this value gets saved into the session + // and used from now. In other words, the setting is not honored at all, since it was not returned from DB. + // Why is it returning 0 rows right after login, but subsequent calls to $this->user_options_model->get_options + // return the saved value with no problem? + 'dashboard_last_qso_count' => $this->session->userdata('dashboard_last_qso_count') ?? $this->user_options_model->get_options('dashboard', array('option_name' => 'last_qso_count', 'option_key' => 'count'))->row()->option_value ?? self::DASHBOARD_DEFAULT_QSOS_COUNT, 'source_uid' => $this->session->userdata('source_uid') ?? '' ); From f7302c341d1fb4e948ba1c6c918ced7b36bcce00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Mel=C3=ADk?= Date: Wed, 29 Jan 2025 21:09:05 +0100 Subject: [PATCH 5/6] Use session value for dashboard last qso count on map, qso list and ux hint --- application/controllers/Dashboard.php | 5 ++++- application/views/dashboard/index.php | 5 ++++- application/views/interface_assets/footer.php | 4 +++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/application/controllers/Dashboard.php b/application/controllers/Dashboard.php index 156012493..9482af9ab 100644 --- a/application/controllers/Dashboard.php +++ b/application/controllers/Dashboard.php @@ -114,7 +114,10 @@ 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('18', $logbooks_locations_array); + $data['last_qsos_list'] = $this->logbook_model->get_last_qsos( + $this->session->userdata('dashboard_last_qso_count'), + $logbooks_locations_array, + ); $data['vucc'] = $this->vucc->fetchVuccSummary(); $data['vuccSAT'] = $this->vucc->fetchVuccSummary('SAT'); diff --git a/application/views/dashboard/index.php b/application/views/dashboard/index.php index 873124931..0ed7132f2 100644 --- a/application/views/dashboard/index.php +++ b/application/views/dashboard/index.php @@ -214,7 +214,7 @@ function getDistance($distance) {
- +
@@ -270,6 +270,9 @@ function getDistance($distance) {
+ + session->userdata('dashboard_last_qso_count')) ?> +
diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index 1a0ce412e..e13fa675b 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -830,7 +830,9 @@ function showActivatorsMap(call, count, grids) { var grid = "No"; - initmap(grid,'map',{'dataPost':{'nb_qso':'18'}}); + + session->userdata('dashboard_last_qso_count')) ?> + initmap(grid,'map',{'dataPost':{'nb_qso': dashboard_qso_count}}); $('#firstLoginWizardModal').modal('show'); From 0f0af3f46671ff53bfacfc964aeb5eddf612fbb3 Mon Sep 17 00:00:00 2001 From: Fabian Berg Date: Thu, 30 Jan 2025 07:44:48 +0100 Subject: [PATCH 6/6] fixes (#4) --- application/config/constants.php | 3 +++ application/controllers/Dashboard.php | 3 ++- application/controllers/User.php | 24 ++++-------------------- application/models/User_model.php | 14 +++----------- application/views/dashboard/index.php | 2 +- 5 files changed, 13 insertions(+), 33 deletions(-) diff --git a/application/config/constants.php b/application/config/constants.php index ee1fded68..7eab3cd60 100644 --- a/application/config/constants.php +++ b/application/config/constants.php @@ -45,6 +45,9 @@ define('EFORBIDDEN', 'Forbidden'); define('OK', 'OK'); +define('DASHBOARD_DEFAULT_QSOS_COUNT', 20); +define('DASHBOARD_QSOS_COUNT_LIMIT', 50); + /* End of file constants.php */ /* Location: ./application/config/constants.php */ diff --git a/application/controllers/Dashboard.php b/application/controllers/Dashboard.php index 9482af9ab..d731ef1ba 100644 --- a/application/controllers/Dashboard.php +++ b/application/controllers/Dashboard.php @@ -114,8 +114,9 @@ class Dashboard extends CI_Controller { $data['qrz_sent_today'] = $QSLStatsBreakdownArray['QRZ_Sent_today']; $data['qrz_rcvd_today'] = $QSLStatsBreakdownArray['QRZ_Received_today']; + $last_qso_count = $this->session->userdata('dashboard_last_qso_count'); $data['last_qsos_list'] = $this->logbook_model->get_last_qsos( - $this->session->userdata('dashboard_last_qso_count'), + $last_qso_count == '' ? DASHBOARD_DEFAULT_QSOS_COUNT : $last_qso_count, $logbooks_locations_array, ); diff --git a/application/controllers/User.php b/application/controllers/User.php index e04b4469e..a6021582d 100644 --- a/application/controllers/User.php +++ b/application/controllers/User.php @@ -178,8 +178,8 @@ class User extends CI_Controller { $data['user_language'] = 'english'; // Values for the "dashboard last QSO count" selectbox - $data['dashboard_last_qso_count_limit'] = \User_Model::DASHBOARD_QSOS_COUNT_LIMIT; - $data['user_dashboard_last_qso_count'] = \User_Model::DASHBOARD_DEFAULT_QSOS_COUNT; + $data['dashboard_last_qso_count_limit'] = DASHBOARD_QSOS_COUNT_LIMIT; + $data['user_dashboard_last_qso_count'] = DASHBOARD_DEFAULT_QSOS_COUNT; if ($this->form_validation->run() == FALSE) { $data['page_title'] = __("Add User"); @@ -376,7 +376,7 @@ class User extends CI_Controller { $data['timezones'] = $this->user_model->timezones(); // Max value to be present in the "dashboard last QSO count" selectbox - $data['dashboard_last_qso_count_limit'] = \User_Model::DASHBOARD_QSOS_COUNT_LIMIT; + $data['dashboard_last_qso_count_limit'] = DASHBOARD_QSOS_COUNT_LIMIT; $data['page_title'] = __("Edit User"); @@ -757,23 +757,7 @@ 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) { - $data['user_dashboard_last_qso_count'] = $last_qso_count_opt[0]->option_value; - } else { - $data['user_dashboard_last_qso_count'] = \User_Model::DASHBOARD_DEFAULT_QSOS_COUNT; - } - } + $data['user_dashboard_last_qso_count'] = ($this->user_options_model->get_options('dashboard', array('option_name'=>'last_qso_count', 'option_key' => 'count'), $this->uri->segment(3))->row()->option_value ?? DASHBOARD_DEFAULT_QSOS_COUNT); $this->load->view('interface_assets/header', $data); $this->load->view('user/edit', $data); diff --git a/application/models/User_model.php b/application/models/User_model.php index e01671db5..11997cde5 100644 --- a/application/models/User_model.php +++ b/application/models/User_model.php @@ -13,9 +13,6 @@ class User_Model extends CI_Model { - const DASHBOARD_DEFAULT_QSOS_COUNT = 20; // number of last QSOs used, if user has no value in settings yet - const DASHBOARD_QSOS_COUNT_LIMIT = 50; // hard limit for max number of QSOs shown on dashboard - // FUNCTION: object get($username) // Retrieve a user function get($username) { @@ -330,7 +327,7 @@ class User_Model extends CI_Model { // Hard limit safety check 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 > self::DASHBOARD_QSOS_COUNT_LIMIT ? self::DASHBOARD_QSOS_COUNT_LIMIT : $dashboard_last_qso_count; + $dashboard_last_qso_count = $dashboard_last_qso_count > DASHBOARD_QSOS_COUNT_LIMIT ? DASHBOARD_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'])."');"); @@ -341,6 +338,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','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."');"); + $this->session->set_userdata('dashboard_last_qso_count', $dashboard_last_qso_count); // Check to see if the user is allowed to change user levels if($this->session->userdata('user_type') == 99) { @@ -524,13 +522,7 @@ class User_Model extends CI_Model { 'hasQrzKey' => $this->hasQrzKey($u->row()->user_id), 'impersonate' => $this->session->userdata('impersonate') ?? false, 'clubstation' => $u->row()->clubstation, - // TODO FIND THE BUG - // when user logs in, the $this->user_options_model->get_options is returning 0 rows for some reason. - // so the code falls back to DASHBOARD_DEFAULT_QSOS_COUNT, and this value gets saved into the session - // and used from now. In other words, the setting is not honored at all, since it was not returned from DB. - // Why is it returning 0 rows right after login, but subsequent calls to $this->user_options_model->get_options - // return the saved value with no problem? - 'dashboard_last_qso_count' => $this->session->userdata('dashboard_last_qso_count') ?? $this->user_options_model->get_options('dashboard', array('option_name' => 'last_qso_count', 'option_key' => 'count'))->row()->option_value ?? self::DASHBOARD_DEFAULT_QSOS_COUNT, + 'dashboard_last_qso_count' => ($this->session->userdata('dashboard_last_qso_count') ?? '') == '' ? ($this->user_options_model->get_options('dashboard', array('option_name' => 'last_qso_count', 'option_key' => 'count'))->row()->option_value ?? '') : $this->session->userdata('dashboard_last_qso_count'), 'source_uid' => $this->session->userdata('source_uid') ?? '' ); diff --git a/application/views/dashboard/index.php b/application/views/dashboard/index.php index 0ed7132f2..2e34bb847 100644 --- a/application/views/dashboard/index.php +++ b/application/views/dashboard/index.php @@ -271,7 +271,7 @@ function getDistance($distance) {
- session->userdata('dashboard_last_qso_count')) ?> + session->userdata('dashboard_last_qso_count'))), intval($this->session->userdata('dashboard_last_qso_count'))); ?>