[Advanced Logbook] Query fix for getting band/mode/sat to the dropdowns

This commit is contained in:
Andreas Kristiansen
2025-01-24 15:55:20 +01:00
parent 40d1e9ac44
commit 7c25462647
5 changed files with 133 additions and 70 deletions

View File

@@ -7,9 +7,10 @@ class Continents extends CI_Controller {
$this->load->model('user_model');
$this->load->model('bands');
$this->load->model('logbookadvanced_model');
$this->load->model('gridmap_model');
$data['bands'] = $this->bands->get_worked_bands();
$data['modes'] = $this->logbookadvanced_model->get_modes();
$data['modes'] = $this->gridmap_model->get_worked_modes();
if(!$this->user_model->authorize($this->config->item('auth_mode'))) {
if($this->user_model->validate_session()) {
@@ -18,7 +19,7 @@ class Continents extends CI_Controller {
} else {
redirect('user/login');
}
}
}
// Render User Interface
// Set Page Title
@@ -29,7 +30,7 @@ class Continents extends CI_Controller {
$this->load->view('continents/index');
$this->load->view('interface_assets/footer');
}
public function get_continents() {

View File

@@ -53,14 +53,14 @@ class Logbookadvanced extends CI_Controller {
$pageData['modes'] = $this->logbookadvanced_model->get_modes();
$pageData['dxccarray'] = $this->logbook_model->fetchDxcc();
$pageData['iotaarray'] = $this->logbook_model->fetchIota();
$pageData['sats'] = $this->bands->get_worked_sats();
$pageData['sats'] = $this->logbookadvanced_model->get_worked_sats();
$pageData['orbits'] = $this->bands->get_worked_orbits();
$pageData['station_profile'] = $this->stations->all_of_user();
$pageData['active_station_info'] = $station_profile->row();
$pageData['homegrid'] = explode(',', $this->stations->find_gridsquare());
$pageData['active_station_id'] = $active_station_id;
$pageData['bands'] = $this->bands->get_worked_bands();
$pageData['bands'] = $this->logbookadvanced_model->get_worked_bands();
// Get Date format
if($this->session->userdata('user_date_format')) {

View File

@@ -596,14 +596,12 @@ class Logbookadvanced_model extends CI_Model {
}
function get_modes() {
if (!$this->logbooks_locations_array) {
return null;
}
$modes = array();
$this->db->select('distinct col_mode, coalesce(col_submode, "") col_submode', FALSE);
$this->db->where_in('station_id', $this->logbooks_locations_array);
$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id');
$this->db->where('station_profile.user_id', $this->session->userdata('user_id'));
$this->db->order_by('col_mode, col_submode', 'ASC');
$query = $this->db->get($this->config->item('table_name'));
@@ -619,6 +617,57 @@ class Logbookadvanced_model extends CI_Model {
return $modes;
}
function get_worked_bands() {
// get all worked slots from database
$sql = "SELECT distinct LOWER(`COL_BAND`) as `COL_BAND` FROM `".$this->config->item('table_name')."` thcv
JOIN station_profile on thcv.station_id = station_profile.station_id WHERE station_profile.user_id = ? AND COL_PROP_MODE != \"SAT\" ORDER BY col_band";
$data = $this->db->query($sql, array($this->session->userdata('user_id')));
$worked_slots = array();
foreach($data->result() as $row){
array_push($worked_slots, $row->COL_BAND);
}
$sql = "SELECT distinct LOWER(`COL_PROP_MODE`) as `COL_PROP_MODE` FROM `".$this->config->item('table_name')."` thcv
JOIN station_profile on thcv.station_id = station_profile.station_id WHERE station_profile.user_id = ? AND COL_PROP_MODE = \"SAT\"";
$SAT_data = $this->db->query($sql, array($this->session->userdata('user_id')));
foreach($SAT_data->result() as $row){
array_push($worked_slots, strtoupper($row->COL_PROP_MODE));
}
usort(
$worked_slots,
function($b, $a) {
sscanf($a, '%f%s', $ac, $ar);
sscanf($b, '%f%s', $bc, $br);
if ($ar == $br) {
return ($ac < $bc) ? -1 : 1;
}
return ($ar < $br) ? -1 : 1;
}
);
return $worked_slots;
}
function get_worked_sats() {
// get all worked sats from database
$sql = "SELECT distinct col_sat_name FROM ".$this->config->item('table_name')." thcv
JOIN station_profile on thcv.station_id = station_profile.station_id WHERE station_profile.user_id = ? and coalesce(col_sat_name, '') <> '' ORDER BY col_sat_name";
$data = $this->db->query($sql, array($this->session->userdata('user_id')));
$worked_sats = array();
foreach($data->result() as $row){
array_push($worked_sats, $row->col_sat_name);
}
return $worked_sats;
}
function getQslsForQsoIds($ids) {
$this->db->select('*');
$this->db->from($this->config->item('table_name'));

View File

@@ -40,7 +40,7 @@
<select id="mode" name="mode" class="form-select form-select-sm">
<option value=""><?= __("All"); ?></option>
<?php foreach($modes as $modeId => $mode){ ?>
<option value="<?php echo htmlspecialchars($mode);?>"><?php echo htmlspecialchars($mode);?></option>
<option value="<?php echo htmlspecialchars(strtoupper($mode));?>"><?php echo htmlspecialchars(strtoupper($mode));?></option>
<?php } ?>
</select>
</div>
@@ -67,4 +67,4 @@
</table>
</div>
</div>
</div>
</div>

View File

@@ -813,9 +813,18 @@ $(document).ready(function () {
action: function (dialogItself) {
$('#optionButton').prop("disabled", false);
$('#closeButton').prop("disabled", true);
saveOptions();
dialogItself.close();
location.reload();
saveOptions().then(() => {
dialogItself.close();
location.reload();
}).catch(error => {
BootstrapDialog.alert({
title: 'Error',
message: 'An error occurred while saving options: ' + error,
type: BootstrapDialog.TYPE_DANGER, // Sets the dialog style to "danger"
closable: true,
buttonLabel: 'Close'
});
});
}
},
{
@@ -1263,61 +1272,65 @@ function printlabel() {
function saveOptions() {
$('#saveButton').prop("disabled", true);
$('#closeButton').prop("disabled", true);
$.ajax({
url: base_url + 'index.php/logbookadvanced/setUserOptions',
type: 'post',
data: {
datetime: $('input[name="datetime"]').is(':checked') ? true : false,
de: $('input[name="de"]').is(':checked') ? true : false,
dx: $('input[name="dx"]').is(':checked') ? true : false,
mode: $('input[name="mode"]').is(':checked') ? true : false,
rsts: $('input[name="rsts"]').is(':checked') ? true : false,
rstr: $('input[name="rstr"]').is(':checked') ? true : false,
band: $('input[name="band"]').is(':checked') ? true : false,
myrefs: $('input[name="myrefs"]').is(':checked') ? true : false,
name: $('input[name="name"]').is(':checked') ? true : false,
qslvia: $('input[name="qslvia"]').is(':checked') ? true : false,
qsl: $('input[name="qsl"]').is(':checked') ? true : false,
clublog: $('input[name="clublog"]').is(':checked') ? true : false,
lotw: $('input[name="lotw"]').is(':checked') ? true : false,
eqsl: $('input[name="eqsl"]').is(':checked') ? true : false,
qslmsgs: $('input[name="qslmsgs"]').is(':checked') ? true : false,
qslmsgr: $('input[name="qslmsgr"]').is(':checked') ? true : false,
dxcc: $('input[name="dxcc"]').is(':checked') ? true : false,
state: $('input[name="state"]').is(':checked') ? true : false,
cqzone: $('input[name="cqzone"]').is(':checked') ? true : false,
ituzone: $('input[name="ituzone"]').is(':checked') ? true : false,
iota: $('input[name="iota"]').is(':checked') ? true : false,
pota: $('input[name="pota"]').is(':checked') ? true : false,
operator: $('input[name="operator"]').is(':checked') ? true : false,
comment: $('input[name="comment"]').is(':checked') ? true : false,
propagation: $('input[name="propagation"]').is(':checked') ? true : false,
contest: $('input[name="contest"]').is(':checked') ? true : false,
gridsquare: $('input[name="gridsquare"]').is(':checked') ? true : false,
sota: $('input[name="sota"]').is(':checked') ? true : false,
dok: $('input[name="dok"]').is(':checked') ? true : false,
wwff: $('input[name="wwff"]').is(':checked') ? true : false,
sig: $('input[name="sig"]').is(':checked') ? true : false,
region: $('input[name="region"]').is(':checked') ? true : false,
continent: $('input[name="continent"]').is(':checked') ? true : false,
distance: $('input[name="distance"]').is(':checked') ? true : false,
antennaazimuth: $('input[name="antennaazimuth"]').is(':checked') ? true : false,
antennaelevation: $('input[name="antennaelevation"]').is(':checked') ? true : false,
qrz: $('input[name="qrz"]').is(':checked') ? true : false,
profilename: $('input[name="profilename"]').is(':checked') ? true : false,
stationpower: $('input[name="stationpower"]').is(':checked') ? true : false,
gridsquare_layer: $('input[name="gridsquareoverlay"]').is(':checked') ? true : false,
path_lines: $('input[name="pathlines"]').is(':checked') ? true : false,
cqzone_layer: $('input[name="cqzones"]').is(':checked') ? true : false,
ituzone_layer: $('input[name="ituzones"]').is(':checked') ? true : false,
nightshadow_layer: $('input[name="nightshadow"]').is(':checked') ? true : false,
},
success: function(data) {
$('#saveButton').prop("disabled", false);
$('#closeButton').prop("disabled", false);
},
error: function() {
$('#saveButton').prop("disabled", false);
},
return new Promise((resolve, reject) => {
$.ajax({
url: base_url + 'index.php/logbookadvanced/setUserOptions',
type: 'post',
data: {
datetime: $('input[name="datetime"]').is(':checked') ? true : false,
de: $('input[name="de"]').is(':checked') ? true : false,
dx: $('input[name="dx"]').is(':checked') ? true : false,
mode: $('input[name="mode"]').is(':checked') ? true : false,
rsts: $('input[name="rsts"]').is(':checked') ? true : false,
rstr: $('input[name="rstr"]').is(':checked') ? true : false,
band: $('input[name="band"]').is(':checked') ? true : false,
myrefs: $('input[name="myrefs"]').is(':checked') ? true : false,
name: $('input[name="name"]').is(':checked') ? true : false,
qslvia: $('input[name="qslvia"]').is(':checked') ? true : false,
qsl: $('input[name="qsl"]').is(':checked') ? true : false,
clublog: $('input[name="clublog"]').is(':checked') ? true : false,
lotw: $('input[name="lotw"]').is(':checked') ? true : false,
eqsl: $('input[name="eqsl"]').is(':checked') ? true : false,
qslmsgs: $('input[name="qslmsgs"]').is(':checked') ? true : false,
qslmsgr: $('input[name="qslmsgr"]').is(':checked') ? true : false,
dxcc: $('input[name="dxcc"]').is(':checked') ? true : false,
state: $('input[name="state"]').is(':checked') ? true : false,
cqzone: $('input[name="cqzone"]').is(':checked') ? true : false,
ituzone: $('input[name="ituzone"]').is(':checked') ? true : false,
iota: $('input[name="iota"]').is(':checked') ? true : false,
pota: $('input[name="pota"]').is(':checked') ? true : false,
operator: $('input[name="operator"]').is(':checked') ? true : false,
comment: $('input[name="comment"]').is(':checked') ? true : false,
propagation: $('input[name="propagation"]').is(':checked') ? true : false,
contest: $('input[name="contest"]').is(':checked') ? true : false,
gridsquare: $('input[name="gridsquare"]').is(':checked') ? true : false,
sota: $('input[name="sota"]').is(':checked') ? true : false,
dok: $('input[name="dok"]').is(':checked') ? true : false,
wwff: $('input[name="wwff"]').is(':checked') ? true : false,
sig: $('input[name="sig"]').is(':checked') ? true : false,
region: $('input[name="region"]').is(':checked') ? true : false,
continent: $('input[name="continent"]').is(':checked') ? true : false,
distance: $('input[name="distance"]').is(':checked') ? true : false,
antennaazimuth: $('input[name="antennaazimuth"]').is(':checked') ? true : false,
antennaelevation: $('input[name="antennaelevation"]').is(':checked') ? true : false,
qrz: $('input[name="qrz"]').is(':checked') ? true : false,
profilename: $('input[name="profilename"]').is(':checked') ? true : false,
stationpower: $('input[name="stationpower"]').is(':checked') ? true : false,
gridsquare_layer: $('input[name="gridsquareoverlay"]').is(':checked') ? true : false,
path_lines: $('input[name="pathlines"]').is(':checked') ? true : false,
cqzone_layer: $('input[name="cqzones"]').is(':checked') ? true : false,
ituzone_layer: $('input[name="ituzones"]').is(':checked') ? true : false,
nightshadow_layer: $('input[name="nightshadow"]').is(':checked') ? true : false,
},
success: function(data) {
$('#saveButton').prop("disabled", false);
$('#closeButton').prop("disabled", false);
resolve(data);
},
error: function(error) {
$('#saveButton').prop("disabled", false);
reject(error);
},
});
});
}