[Dashboard] User option for banner

This commit is contained in:
Andreas Kristiansen
2025-04-28 11:46:28 +02:00
parent 90f4c0a214
commit 58373b9f52
7 changed files with 67 additions and 52 deletions

View File

@@ -13,18 +13,18 @@ class Dashboard extends CI_Controller {
// Database connections
$this->load->model('logbook_model');
// LoTW infos
$this->load->model('Lotw_model');
$current_date = date('Y-m-d H:i:s');
$data['lotw_cert_expired'] = $this->Lotw_model->lotw_cert_expired($this->session->userdata('user_id'), $current_date);
$data['lotw_cert_expiring'] = $this->Lotw_model->lotw_cert_expiring($this->session->userdata('user_id'), $current_date);
$this->load->model('logbooks_model');
$logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook'));
if (($logbooks_locations_array[0]>-1) && (!(in_array($this->stations->find_active(),$logbooks_locations_array)))) {
$data['active_not_linked']=true;
} else {
@@ -73,6 +73,12 @@ class Dashboard extends CI_Controller {
$data['dashboard_map'] = 'N';
}
if (($this->session->userdata('user_dashboard_banner') ?? '') != '') {
$data['dashboard_banner'] = $this->session->userdata('user_dashboard_banner') ?? 'Y';
} else {
$data['dashboard_banner'] = 'N';
}
$data['user_map_custom'] = $this->optionslib->get_map_custom();
$this->load->model('cat');

View File

@@ -75,14 +75,6 @@ class Options extends CI_Controller {
$this->session->set_flashdata('success', __("Options saved"));
}
// Update dashboard banner within the options system
$dasboard_banner_update_status = $this->optionslib->update('dashboard_banner', $this->input->post('dashboardBanner'), 'yes');
// If dashboard banner update is complete set a flashsession with a success note
if($dasboard_banner_update_status == TRUE) {
$this->session->set_flashdata('success', __("Options saved"));
}
// Update logbook map within the options system
$logbook_map_update_status = $this->optionslib->update('logbook_map', $this->input->post('logbookMap'), 'yes');
@@ -524,7 +516,7 @@ class Options extends CI_Controller {
if($version_dialog_mode_update == TRUE) {
$this->session->set_flashdata('success1', __("Version Info Mode changed to")." "."'".$this->input->post('version_dialog_mode')."'");
}
if ($this->input->post('version_dialog_mode') == "both" || $this->input->post('version_dialog_mode') == "custom_text" ) {
if ($this->input->post('version_dialog_mode') == "both" || $this->input->post('version_dialog_mode') == "custom_text" ) {
$version_dialog_custom_text_update = $this->optionslib->update('version_dialog_text', $this->input->post('version_dialog_custom_text'), 'yes');
if($version_dialog_custom_text_update == TRUE) {
$this->session->set_flashdata('success2', __("Version Info Custom Text saved!"));

View File

@@ -202,6 +202,7 @@ class User extends CI_Controller {
$data['user_timezone'] = $this->input->post('user_timezone');
$data['user_measurement_base'] = $this->input->post('user_measurement_base') ?? 'K';
$data['user_dashboard_map'] = $this->input->post('user_dashboard_map') ?? 'Y';
$data['user_dashboard_banner'] = $this->input->post('user_dashboard_banner') ?? 'Y';
$data['user_stylesheet'] = $this->input->post('user_stylesheet');
$data['user_qth_lookup'] = $this->input->post('user_qth_lookup');
$data['user_sota_lookup'] = $this->input->post('user_sota_lookup');
@@ -289,6 +290,7 @@ class User extends CI_Controller {
$this->input->post('on_air_widget_display_last_seen'),
$this->input->post('on_air_widget_show_only_most_recent_radio'),
$this->input->post('qso_widget_display_qso_time'),
$this->input->post('user_dashboard_banner') ?? 'Y',
$this->input->post('clubstation') == '1' ? true : false
)) {
// Check for errors
@@ -320,6 +322,7 @@ class User extends CI_Controller {
$data['user_locator'] = $this->input->post('user_locator');
$data['user_measurement_base'] = $this->input->post('user_measurement_base');
$data['user_dashboard_map'] = $this->input->post('user_dashboard_map') ?? 'Y';
$data['user_dashboard_banner'] = $this->input->post('user_dashboard_banner') ?? 'Y';
$data['user_stylesheet'] = $this->input->post('user_stylesheet');
$data['user_qth_lookup'] = $this->input->post('user_qth_lookup');
$data['user_sota_lookup'] = $this->input->post('user_sota_lookup');
@@ -684,6 +687,15 @@ class User extends CI_Controller {
}
}
if($this->input->post('user_dashboard_banner')) {
$data['user_dashboard_banner'] = $this->input->post('user_dashboard_banner', false);
} else {
$dkey_opt=$this->user_options_model->get_options('dashboard',array('option_name'=>'show_dashboard_banner','option_key'=>'boolean'), $this->uri->segment(3))->result();
if (count($dkey_opt)>0) {
$data['user_dashboard_banner'] = $dkey_opt[0]->option_value;
}
}
if($this->input->post('user_hamsat_workable_only')) {
$data['user_hamsat_workable_only'] = $this->input->post('user_hamsat_workable_only', false);
} else {
@@ -793,7 +805,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
// Data was submitted for saving - save updated options in DB
unset($data);
switch($this->user_model->edit($this->input->post())) {
// Check for errors
@@ -1094,7 +1106,7 @@ class User extends CI_Controller {
}
$this->user_model->set_last_seen($data['user']->user_id);
redirect('dashboard');
} else if ($login_attempt === 2) {
$this->session->set_flashdata('warning', __("You can't login to a clubstation directly. Use your personal account instead."));
redirect('user/login');
@@ -1125,19 +1137,19 @@ class User extends CI_Controller {
}
$this->user_model->clear_session();
if ($custom_message != null && is_array($custom_message)) {
$this->input->set_cookie('tmp_msg', json_encode([$custom_message[0], $custom_message[1]]), 10, '');
} else {
$this->input->set_cookie('tmp_msg', json_encode(['notice', sprintf(__("User %s logged out."), $user_name)]), 10, '');
}
redirect('user/login');
}
/**
* First Login Wizard
*
*
* Form Data to create the first station location
*/
function firstlogin_wizard_form() {
@@ -1465,7 +1477,7 @@ class User extends CI_Controller {
redirect('dashboard');
}
// is the source user still logged in?
// is the source user still logged in?
// We fetch the source user from database to also make sure the user exists. We could use source_uid directly, but this is more secure
if ($this->session->userdata('user_id') != $this->user_model->get_by_id($source_uid)->row()->user_id) {
$this->session->set_flashdata('error', __("You can't impersonate another user while you're not logged in as the source user"));
@@ -1509,7 +1521,7 @@ class User extends CI_Controller {
} else {
if(!$source_user || !$this->user_model->authorize(99)) {
$this->session->set_flashdata('error', __("You're not allowed to do that!"));
redirect('dashboard');
redirect('dashboard');
} else {
$custom_sessiondata['p_level'] = 99; // if the user is an admin he also should have full rights in the clubstations
}
@@ -1525,8 +1537,8 @@ class User extends CI_Controller {
// TODO: Find a solution for sessiondata 'radio', so a user would be able to use e.g. his own radio while impersonating another user
// Due the fact that the user is now impersonating another user, he can't use his default radio anymore
$this->session->set_userdata('source_uid', $source_uid);
$this->user_model->update_session($target_uid, null, true, $custom_sessiondata);
$this->user_model->update_session($target_uid, null, true, $custom_sessiondata);
// Redirect to the dashboard, the user should now be logged in as the other user
redirect('dashboard');
}

View File

@@ -180,7 +180,7 @@ class User_Model extends CI_Model {
// if there is a space it's probably a firstname + lastname search
if (strpos($query, ' ') !== false) {
$parts = explode(' ', $query, 2);
$this->db->group_start();
$this->db->like('user_firstname', $parts[0]);
$this->db->or_like('user_lastname', $parts[0]);
@@ -205,7 +205,7 @@ class User_Model extends CI_Model {
// FUNCTION: bool add($username, $password, $email, $type)
// Add a user
// !!!!!!!!!!!!!!!!
// !! IMPORTANT NOTICE: Please inform DJ7NT and/or DF2ET when adding/removing/changing parameters here.
// !! IMPORTANT NOTICE: Please inform DJ7NT and/or DF2ET when adding/removing/changing parameters here.
// !!!!!!!!!!!!!!!!
function add($username, $password, $email, $type, $firstname, $lastname, $callsign, $locator, $timezone,
$measurement, $dashboard_map, $user_date_format, $user_stylesheet, $user_qth_lookup, $user_sota_lookup, $user_wwff_lookup,
@@ -216,7 +216,7 @@ class User_Model extends CI_Model {
$user_wwff_to_qso_tab, $user_pota_to_qso_tab, $user_sig_to_qso_tab, $user_dok_to_qso_tab,
$user_lotw_name, $user_lotw_password, $user_eqsl_name, $user_eqsl_password, $user_clublog_name, $user_clublog_password,
$user_winkey, $on_air_widget_enabled, $on_air_widget_display_last_seen, $on_air_widget_show_only_most_recent_radio,
$qso_widget_display_qso_time, $clubstation = 0) {
$qso_widget_display_qso_time, $dashboard_banner, $clubstation = 0) {
// Check that the user isn't already used
if(!$this->exists($username)) {
$data = array(
@@ -299,6 +299,7 @@ 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 . ", 'qso_tab','sig','show',".(xss_clean($user_sig_to_qso_tab ?? 'off') == "on" ? 1 : 0).");");
$this->db->query("insert into user_options (user_id, option_type, option_name, option_key, option_value) values (" . $insert_id . ", 'qso_tab','dok','show',".(xss_clean($user_dok_to_qso_tab ?? 'off') == "on" ? 1 : 0).");");
$this->db->query("insert into user_options (user_id, option_type, option_name, option_key, option_value) values (" . $insert_id . ", 'dashboard','show_map','boolean','".xss_clean($dashboard_map ?? 'Y')."');");
$this->db->query("insert into user_options (user_id, option_type, option_name, option_key, option_value) values (" . $insert_id . ", 'dashboard','show_dashboard_banner','boolean','".xss_clean($dashboard_banner ?? 'Y')."');");
$this->db->query("insert into user_options (user_id, option_type, option_name, option_key, option_value) values (" . $insert_id . ", 'widget','on_air','enabled','".(xss_clean($on_air_widget_enabled ?? 'false'))."');");
$this->db->query("insert into user_options (user_id, option_type, option_name, option_key, option_value) values (" . $insert_id . ", 'widget','on_air','display_last_seen','".(xss_clean($on_air_widget_display_last_seen ?? 'false'))."');");
$this->db->query("insert into user_options (user_id, option_type, option_name, option_key, option_value) values (" . $insert_id . ", 'widget','on_air','display_only_most_recent_radio','".(xss_clean($on_air_widget_show_only_most_recent_radio ?? 'true'))."');");
@@ -375,9 +376,11 @@ 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'] . ", 'dashboard','last_qso_count','count','".$dashboard_last_qso_count."');");
$this->db->query("replace into user_options (user_id, option_type, option_name, option_key, option_value) values (" . $fields['id'] . ", 'qso_tab','last_qso_count','count','".$qso_page_last_qso_count."');");
$this->db->query("replace into user_options (user_id, option_type, option_name, option_key, option_value) values (" . $fields['id'] . ", 'dashboard','show_map','boolean','".xss_clean($fields['user_dashboard_map'] ?? 'Y')."');");
$this->db->query("replace into user_options (user_id, option_type, option_name, option_key, option_value) values (" . $fields['id'] . ", 'dashboard','show_dashboard_banner','boolean','".xss_clean($fields['user_dashboard_banner'] ?? 'Y')."');");
$this->session->set_userdata('dashboard_last_qso_count', $dashboard_last_qso_count);
$this->session->set_userdata('qso_page_last_qso_count', $qso_page_last_qso_count);
$this->session->set_userdata('qso_page_last_qso_count', $qso_page_last_qso_count);
$this->session->set_userdata('user_dashboard_map',xss_clean($fields['user_dashboard_map'] ?? 'Y'));
$this->session->set_userdata('user_dashboard_banner',xss_clean($fields['user_dashboard_banner'] ?? 'Y'));
// Check to see if the user is allowed to change user levels
if($this->session->userdata('user_type') == 99) {
@@ -534,6 +537,7 @@ class User_Model extends CI_Model {
'station_profile_id' => $this->session->userdata('station_profile_id') ?? '',
'user_measurement_base' => $u->row()->user_measurement_base,
'user_dashboard_map' => ((($this->session->userdata('user_dashboard_map') ?? 'Y') == 'Y') ? $this->user_options_model->get_options('dashboard', array('option_name' => 'show_map', 'option_key' => 'boolean'))->row()->option_value ?? 'Y' : $this->session->userdata('user_dashboard_map')),
'user_dashboard_banner' => ((($this->session->userdata('user_dashboard_banner') ?? 'Y') == 'Y') ? $this->user_options_model->get_options('dashboard', array('option_name' => 'show_dashboard_banner', 'option_key' => 'boolean'))->row()->option_value ?? 'Y' : $this->session->userdata('user_dashboard_banner')),
'user_date_format' => $u->row()->user_date_format,
'user_stylesheet' => $u->row()->user_stylesheet,
'user_qth_lookup' => isset($u->row()->user_qth_lookup) ? $u->row()->user_qth_lookup : 0,
@@ -733,9 +737,9 @@ class User_Model extends CI_Model {
$qsocount_join = "";
if (!($this->config->item('disable_user_stats') ?? false)) {
$qsocount_select = ", COALESCE(lc.qsocount, 0) AS qsocount, lc.lastqso";
$qsocount_join =
$qsocount_join =
" LEFT JOIN (
SELECT sp.user_id,
SELECT sp.user_id,
COUNT(l.col_primary_key) AS qsocount,
MAX(l.COL_TIME_ON) AS lastqso
FROM station_profile sp
@@ -743,7 +747,7 @@ class User_Model extends CI_Model {
GROUP BY sp.user_id
) lc ON lc.user_id = u.user_id";
}
$sql = "SELECT
$sql = "SELECT
u.user_id,
u.user_name,
u.user_firstname,
@@ -944,23 +948,23 @@ class User_Model extends CI_Model {
function convert($user_id, $clubstation) {
$sql = "UPDATE users SET clubstation = ? WHERE user_id = ?;";
$this->db->trans_start();
if (!$this->db->query($sql, [$clubstation, $user_id])) {
$this->db->trans_rollback();
return false;
}
// Remove all club permissions in case there is a club with this user id
$delete_sql = "DELETE FROM club_permissions WHERE club_id = ?;";
if (!$this->db->query($delete_sql, [$user_id])) {
$this->db->trans_rollback();
return false;
}
$this->db->trans_complete();
return $this->db->trans_status();
}
@@ -971,13 +975,13 @@ class User_Model extends CI_Model {
}
try {
$this->db->query("INSERT INTO station_logbooks (user_id, logbook_name, modified, public_slug, public_search)
$this->db->query("INSERT INTO station_logbooks (user_id, logbook_name, modified, public_slug, public_search)
VALUES (?, 'Home Logbook', NULL, NULL, 0)", [$stationdata['user_id']]
);
$station_logbooks_insert_id = $this->db->insert_id();
$this->db->query("UPDATE users
SET active_station_logbook = ?
$this->db->query("UPDATE users
SET active_station_logbook = ?
WHERE user_id = ?", [$station_logbooks_insert_id, $stationdata['user_id']]
);
@@ -989,7 +993,7 @@ class User_Model extends CI_Model {
station_sig, station_sig_info, qrzrealtime, user_id, station_wwff, station_pota, oqrs, oqrs_text, oqrs_email,
webadifapikey, webadifapiurl, webadifrealtime, clublogignore, clublogrealtime, hrdlogrealtime, hrdlog_code, hrdlog_username
) VALUES (
?, ?, '', '', '', ?, NULL, ?, '', ?, ?, 1, '', '', '', '', '', '', 0, ?, '', '', 0, '', 0, '',
?, ?, '', '', '', ?, NULL, ?, '', ?, ?, 1, '', '', '', '', '', '', 0, ?, '', '', 0, '', 0, '',
'https://qo100dx.club/api', 0, 0, 0, 0, '', ''
)", [
$stationdata['station_name'],
@@ -1003,7 +1007,7 @@ class User_Model extends CI_Model {
);
$station_profile_insert_id = $this->db->insert_id();
$this->db->query("INSERT INTO station_logbooks_relationship (station_logbook_id, station_location_id, modified)
$this->db->query("INSERT INTO station_logbooks_relationship (station_logbook_id, station_location_id, modified)
VALUES (?, ?, NULL)", [$station_logbooks_insert_id, $station_profile_insert_id]
);

View File

@@ -159,7 +159,7 @@ function getDistance($distance) {
</div>
<?php } ?>
<?php if($this->optionslib->get_option('dashboard_banner') != "false" && $this->session->userdata('clubstation') == 0) { ?>
<?php if($dashboard_banner != "false" && $this->session->userdata('clubstation') == 0) { ?>
<?php if($todays_qsos >= 1) { ?>
<div class="alert alert-success" role="alert" style="margin-top: 1rem;">
<?= sprintf(

View File

@@ -50,22 +50,13 @@
</select>
<small id="themeHelp" class="form-text text-muted"><?= __("Global Theme Choice, this is used when users arent logged in."); ?></small>
</div>
<select class="form-select" id="globalSearch" name="globalSearch" style="display: none;">
<option value='true' <?php if($this->optionslib->get_option('global_search') == "true") { echo "selected=\"selected\""; } ?>><?= __("Enabled"); ?></option>
<option value='false' <?php if($this->optionslib->get_option('global_search') == "false") { echo "selected=\"selected\""; } ?>><?= __("Disabled"); ?></option>
</select>
<div class="mb-3">
<label for="dashboardBanner"><?= __("Dashboard Notification Banner"); ?></label>
<select class="form-select" id="dashboardBanner" name="dashboardBanner" aria-describedby="dashboardBannerHelp" required>
<option value='true' <?php if($this->optionslib->get_option('dashboard_banner') == "true") { echo "selected=\"selected\""; } ?>><?= __("Enabled"); ?></option>
<option value='false' <?php if($this->optionslib->get_option('dashboard_banner') == "false") { echo "selected=\"selected\""; } ?>><?= __("Disabled"); ?></option>
</select>
<small id="dashboardBannerHelp" class="form-text text-muted"><?= __("This allows to disable the global notification banner on the dashboard."); ?></small>
</div>
<div class="mb-3">
<label for="logbookMap"><?= __("Logbook Map"); ?></label>
<select class="form-select" id="logbookMap" name="logbookMap" aria-describedby="logbookMapHelp" required>

View File

@@ -237,6 +237,16 @@
</select>
<small id="user_dashboard_map_Help" class="form-text text-muted"><?= __("Choose whether to show map on dashboard or not"); ?></small>
</div>
<div class="mb-3">
<label for="user_dashboard_banner"><?= __("Dashboard Notification Banner"); ?></label>
<?php if(!isset($user_dashboard_banner)) { $user_dashboard_banner='Y'; }?>
<select class="form-select" id="user_dashboard_banner" name="user_dashboard_banner" aria-describedby="user_dashboard_banner_Help" required>
<option value='true' <?php if($user_dashboard_banner == "true") { echo "selected=\"selected\""; } ?>><?= __("Enabled"); ?></option>
<option value='false' <?php if($user_dashboard_banner == "false") { echo "selected=\"selected\""; } ?>><?= __("Disabled"); ?></option>
</select>
<small id="user_dashboard_banner_Help" class="form-text text-muted"><?= __("This allows to disable the global notification banner on the dashboard."); ?></small>
</div>
</div>
</div>
</div>
@@ -864,7 +874,7 @@
<small class="form-text text-muted">
<?= sprintf(__("Note: In order to use this widget, you need to have at least one CAT radio configured and working.")); ?>
<?php if (isset($on_air_widget_url)) {
// when adding user, the $on_air_widget_url url is not yet availalable, hence the if condition here
// when adding user, the $on_air_widget_url url is not yet availalable, hence the if condition here
print("<br>");
printf(__("When enabled, widget will be available at %s."), "<a href='$on_air_widget_url' target='_blank'>$on_air_widget_url</a>");
} ?>