Logic for showing tabs according to club/permission level

This commit is contained in:
int2001
2025-11-30 09:13:22 +00:00
parent ea951121f1
commit d1b81f9845
2 changed files with 173 additions and 48 deletions

View File

@@ -4,13 +4,75 @@ class adif extends CI_Controller {
/* Controls ADIF Import/Export Functions */
function __construct()
{
private $allowed_tabs = [];
private $tab_method_mapping = [
'import' => ['import'],
'export' => ['export_custom', 'exportall', 'exportsat', 'exportsatlotw'],
'lotw' => ['lotw', 'mark_lotw', 'export_lotw'],
'dcl' => ['dcl'],
'pota' => ['pota'],
'cbr' => []
];
function __construct() {
parent::__construct();
$this->load->helper(array('form', 'url'));
$this->load->model('user_model');
if(!$this->user_model->authorize(2) || !clubaccess_check(6)) { $this->session->set_flashdata('error', __("You're not allowed to do that!")); redirect('dashboard'); }
if(!$this->user_model->authorize(2) || (!clubaccess_check(6) && !clubaccess_check(9))) { $this->session->set_flashdata('error', __("You're not allowed to do that!")); redirect('dashboard'); }
$this->determine_allowed_tabs();
$this->check_tab_access();
}
private function determine_allowed_tabs() {
if (clubaccess_check(6) && !clubaccess_check(9)) {
// Only ClubMember Plus and NOT ClubOfficer
$this->allowed_tabs = ['import', 'export'];
} else {
// Default: show all tabs (backward compatible)
$this->allowed_tabs = ['import', 'export', 'lotw', 'dcl', 'pota', 'cbr'];
}
}
private function check_tab_access() {
// Get current method using CI's built-in method
$current_method = $this->router->method;
// Skip access check for some common methods
$skip_methods = ['index', '__construct', 'determine_allowed_tabs', 'check_tab_access', 'get_allowed_tabs', 'test'];
if (in_array($current_method, $skip_methods)) {
return;
}
// Find which tab(s) this method belongs to
$required_tabs = [];
foreach ($this->tab_method_mapping as $tab => $methods) {
if (in_array($current_method, $methods)) {
$required_tabs[] = $tab;
}
}
// Check if user has access to required tabs
foreach ($required_tabs as $tab) {
if (!in_array($tab, $this->allowed_tabs)) {
$this->session->set_flashdata('error', __("You're not allowed to access this functionality!"));
redirect('adif');
}
}
}
private function get_allowed_tabs() {
return $this->allowed_tabs;
}
private function require_tab_access($required_tab) {
if (!in_array($required_tab, $this->allowed_tabs)) {
$this->session->set_flashdata('error', __("You're not allowed to access this functionality!"));
redirect('adif');
}
}
public function test() {
@@ -24,8 +86,7 @@ class adif extends CI_Controller {
}
// Export all QSO Data in ASC Order of Date.
public function exportall()
{
public function exportall() {
// Set memory limit to unlimited to allow heavy usage
ini_set('memory_limit', '-1');
@@ -38,8 +99,7 @@ class adif extends CI_Controller {
// Export all QSO Data in ASC Order of Date.
public function exportsat()
{
public function exportsat() {
// Set memory limit to unlimited to allow heavy usage
ini_set('memory_limit', '-1');
@@ -51,8 +111,7 @@ class adif extends CI_Controller {
}
// Export all QSO Data in ASC Order of Date.
public function exportsatlotw()
{
public function exportsatlotw() {
// Set memory limit to unlimited to allow heavy usage
ini_set('memory_limit', '-1');
@@ -64,6 +123,9 @@ class adif extends CI_Controller {
}
public function export_custom() {
// Check if user has access to export tab
$this->require_tab_access('export');
// Set memory limit to unlimited to allow heavy usage
ini_set('memory_limit', '-1');
@@ -92,6 +154,9 @@ class adif extends CI_Controller {
}
public function mark_lotw() {
// Check if user has access to lotw tab
$this->require_tab_access('lotw');
// Set memory limit to unlimited to allow heavy usage
ini_set('memory_limit', '-1');
@@ -108,8 +173,10 @@ class adif extends CI_Controller {
$this->load->view('adif/mark_lotw', $data);
}
public function export_lotw()
{
public function export_lotw() {
// Check if user has access to lotw tab
$this->require_tab_access('lotw');
// Set memory limit to unlimited to allow heavy usage
ini_set('memory_limit', '-1');
@@ -148,12 +215,18 @@ class adif extends CI_Controller {
$data['active_station_info'] = $station_profile->row();
$data['active_station_id'] = $active_station_id;
// Pass allowed tabs to view
$data['allowed_tabs'] = $this->get_allowed_tabs();
$this->load->view('interface_assets/header', $data);
$this->load->view('adif/import');
$this->load->view('adif/import', $data);
$this->load->view('interface_assets/footer');
}
public function import() {
// Check if user has access to import tab
$this->require_tab_access('import');
$this->load->model('stations');
$data['station_profile'] = $this->stations->all_of_user();
@@ -165,6 +238,9 @@ class adif extends CI_Controller {
$data['page_title'] = __("ADIF Import");
$data['tab'] = "adif";
// Pass allowed tabs to view
$data['allowed_tabs'] = $this->get_allowed_tabs();
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'adi|ADI|adif|ADIF|zip';
@@ -313,12 +389,18 @@ class adif extends CI_Controller {
}
public function dcl() {
// Check if user has access to dcl tab
$this->require_tab_access('dcl');
$this->load->model('stations');
$data['station_profile'] = $this->stations->all_of_user();
$data['page_title'] = __("DCL Import");
$data['tab'] = "dcl";
// Pass allowed tabs to view
$data['allowed_tabs'] = $this->get_allowed_tabs();
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'adi|ADI|adif|ADIF';
@@ -382,12 +464,18 @@ class adif extends CI_Controller {
}
public function pota() {
// Check if user has access to pota tab
$this->require_tab_access('pota');
$this->load->model('stations');
$data['station_profile'] = $this->stations->all_of_user();
$data['page_title'] = __("POTA Import");
$data['tab'] = "potab";
// Pass allowed tabs to view
$data['allowed_tabs'] = $this->get_allowed_tabs();
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'adi|ADI|adif|ADIF';

View File

@@ -11,58 +11,84 @@
<div class="card">
<div class="card-header">
<ul class="nav nav-tabs card-header-tabs pull-right" role="tablist">
<?php
// Define all available tabs
$all_tabs = ['import', 'export', 'lotw', 'dcl', 'pota', 'cbr'];
// Use allowed_tabs if set, otherwise show all tabs
$tabs_to_show = isset($allowed_tabs) ? $allowed_tabs : $all_tabs;
?>
<?php if (in_array('import', $tabs_to_show)): ?>
<li class="nav-item">
<a class="nav-link <?php if ($showtab == '' || $showtab == 'adif') {
echo 'active';
} ?>" id="import-tab" data-bs-toggle="tab" href="#import" role="tab" aria-controls="import" aria-selected="<?php if ($showtab == '' || $showtab == 'adif') {
echo 'true';
} else {
echo 'false';
} ?>"><?= __("ADIF Import") ?></a>
echo 'active';
} ?>" id="import-tab" data-bs-toggle="tab" href="#import" role="tab" aria-controls="import" aria-selected="<?php if ($showtab == '' || $showtab == 'adif') {
echo 'true';
} else {
echo 'false';
} ?>"><?= __("ADIF Import") ?></a>
</li>
<?php endif; ?>
<?php if (in_array('export', $tabs_to_show)): ?>
<li class="nav-item">
<a class="nav-link" id="export-tab" data-bs-toggle="tab" href="#export" role="tab" aria-controls="export" aria-selected="false"><?= __("ADIF Export") ?></a>
</li>
<?php endif; ?>
<?php if (in_array('lotw', $tabs_to_show)): ?>
<li class="nav-item">
<a class="nav-link" id="lotw-tab" data-bs-toggle="tab" href="#lotw" role="tab" aria-controls="lotw" aria-selected="false"><?= __("Logbook of the World") ?></a>
</li>
<?php endif; ?>
<?php if (in_array('dcl', $tabs_to_show)): ?>
<li class="nav-item">
<a class="nav-link <?php if ($showtab == 'dcl') {
echo 'active';
} ?>" id="dcl-tab" data-bs-toggle="tab" href="#dcl" role="tab" aria-controls="dcl" aria-selected="<?php if ($showtab == 'dcl') {
echo 'true';
} else {
echo 'false';
} ?>"><?= __("DARC DCL") ?></a>
echo 'active';
} ?>" id="dcl-tab" data-bs-toggle="tab" href="#dcl" role="tab" aria-controls="dcl" aria-selected="<?php if ($showtab == 'dcl') {
echo 'true';
} else {
echo 'false';
} ?>"><?= __("DARC DCL") ?></a>
</li>
<?php endif; ?>
<?php if (in_array('pota', $tabs_to_show)): ?>
<li class="nav-item">
<a class="nav-link <?php if ($showtab == 'potab') {
echo 'active';
} ?>" id="potab-tab" data-bs-toggle="tab" href="#potab" role="tab" aria-controls="potab" aria-selected="<?php if ($showtab == 'potab') {
echo 'true';
} else {
echo 'false';
} ?>"><?= __("POTA") ?></a>
echo 'active';
} ?>" id="potab-tab" data-bs-toggle="tab" href="#potab" role="tab" aria-controls="potab" aria-selected="<?php if ($showtab == 'potab') {
echo 'true';
} else {
echo 'false';
} ?>"><?= __("POTA") ?></a>
</li>
<?php endif; ?>
<?php if (in_array('cbr', $tabs_to_show)): ?>
<li class="nav-item">
<a class="nav-link <?php if ($showtab == 'cbr') {
echo 'active';
} ?>" id="cbr-tab" data-bs-toggle="tab" href="#cbr" role="tab" aria-controls="cbr" aria-selected="<?php if ($showtab == 'cbr') {
echo 'true';
} else {
echo 'false';
} ?>"><?= __("CBR Import") ?></a>
echo 'active';
} ?>" id="cbr-tab" data-bs-toggle="tab" href="#cbr" role="tab" aria-controls="cbr" aria-selected="<?php if ($showtab == 'cbr') {
echo 'true';
} else {
echo 'false';
} ?>"><?= __("CBR Import") ?></a>
</li>
<?php endif; ?>
</ul>
</div>
<div class="card-body">
<div class="tab-content">
<?php if (in_array('import', $tabs_to_show)): ?>
<div class="tab-pane <?php if ($showtab == '' || $showtab == 'adif') {
echo 'active';
} else {
echo 'fade';
} ?>" id="import" role="tabpanel" aria-labelledby="import-tab">
echo 'active';
} else {
echo 'fade';
} ?>" id="import" role="tabpanel" aria-labelledby="import-tab">
<?php if (isset($error) && ($showtab == '' || $showtab == 'adif')) { ?>
<div class="alert alert-danger" role="alert">
@@ -221,7 +247,9 @@
<button id="prepare_sub" class="btn btn-sm btn-primary mb-2 ld-ext-right" value="Upload"><?= __("Upload") ?><div class="ld ld-ring ld-spin"></div></button>
</form>
</div>
<?php endif; ?>
<?php if (in_array('export', $tabs_to_show)): ?>
<div class="tab-pane fade" id="export" role="tabpanel" aria-labelledby="export-tab">
<form class="form" action="<?php echo site_url('adif/export_custom'); ?>" method="post" enctype="multipart/form-data">
@@ -298,7 +326,9 @@
<p><a href="<?php echo site_url('adif/exportsatlotw'); ?>" title="Export All Satellite QSOs Confirmed on LoTW" target="_blank" class="btn btn-sm btn-primary"><?= __("Export All Satellite QSOs Confirmed on LoTW") ?></a></p>
</div>
<?php endif; ?>
<?php if (in_array('lotw', $tabs_to_show)): ?>
<div class="tab-pane fade" id="lotw" role="tabpanel" aria-labelledby="lotw-tab">
<form class="form" action="<?php echo site_url('adif/mark_lotw'); ?>" method="post" enctype="multipart/form-data">
<select name="station_profile" class="form-select mb-2 me-sm-2 w-50 w-lg-100">
@@ -318,12 +348,14 @@
<button type="button" class="btn btn-sm btn-primary" id="markExportedToLotw" value="Export"><?= __("Mark QSOs as exported to LoTW") ?></button>
</form>
</div>
<?php endif; ?>
<?php if (in_array('dcl', $tabs_to_show)): ?>
<div class="tab-pane <?php if ($showtab == 'dcl') {
echo 'active';
} else {
echo 'fade';
} ?>" id="dcl" role="tabpanel" aria-labelledby="dcl-tab">
echo 'active';
} else {
echo 'fade';
} ?>" id="dcl" role="tabpanel" aria-labelledby="dcl-tab">
<?php if (isset($error) && $showtab == 'dcl') { ?>
<div class="alert alert-danger" role="alert">
<?php echo $error; ?>
@@ -364,12 +396,14 @@
<button type="submit" class="btn btn-sm btn-primary mb-2" value="Upload"><?= __("Upload") ?></button>
</form>
</div>
<?php endif; ?>
<?php if (in_array('pota', $tabs_to_show)): ?>
<div class="tab-pane <?php if ($showtab == 'potab') {
echo 'active';
} else {
echo 'fade';
} ?>" id="potab" role="tabpanel" aria-labelledby="potab-tab">
echo 'active';
} else {
echo 'fade';
} ?>" id="potab" role="tabpanel" aria-labelledby="potab-tab">
<?php if (isset($error) && $showtab == 'potab') { ?>
<div class="alert alert-danger" role="alert">
<?php echo $error; ?>
@@ -384,7 +418,9 @@
<button type="submit" class="btn btn-sm btn-primary mb-2" value="Upload"><?= __("Upload") ?></button>
</form>
</div>
<?php endif; ?>
<?php if (in_array('cbr', $tabs_to_show)): ?>
<div class="tab-pane <?php if ($showtab == 'cbr') {
echo 'active';
} else {
@@ -426,6 +462,7 @@
<button type="submit" class="btn btn-sm btn-primary mb-2" value="Upload"><?= __("Upload") ?></button>
</form>
</div>
<?php endif; ?>
</div>
</div>
</div>