Reworked DXCC award. Changed look a bit, and added form for selection.

Setting of start/end in dxcc_entities was fixed as well. This is needed to be able to select/deselect deleted entites.
pull/426/head
AndreasK79 2020-03-03 12:39:45 +01:00
rodzic 0628e3bdb3
commit e8941cf17d
4 zmienionych plików z 473 dodań i 36 usunięć

Wyświetl plik

@ -76,17 +76,64 @@ class Awards extends CI_Controller {
}
public function dxcc () {
//echo "Needs Developed";
$this->load->model('dxcc');
$data['dxcc'] = $this->dxcc->show_stats();
$data['worked_bands'] = $this->dxcc->get_worked_bands();
$data['worked_bands'] = $this->dxcc->get_worked_bands(); // Used in the view for band select
if ($this->input->post('band') != NULL) { // Band is not set when page first loads.
if ($this->input->post('band') == 'All') { // Did the user specify a band? If not, use all bands
$bands = $data['worked_bands'];
}
else {
$bands[] = $this->input->post('band');
}
}
else {
$bands = $data['worked_bands'];
}
$data['bands'] = $bands; // Used for displaying selected band(s) in the table in the view
if($this->input->method() === 'post') {
$postdata['lotw'] = $this->input->post('lotw');
$postdata['qsl'] = $this->input->post('qsl');
$postdata['worked'] = $this->input->post('worked');
$postdata['confirmed'] = $this->input->post('confirmed');
$postdata['notworked'] = $this->input->post('notworked');
$postdata['deleted'] = $this->input->post('deleted');
$postdata['Africa'] = $this->input->post('Africa');
$postdata['Asia'] = $this->input->post('Asia');
$postdata['Europe'] = $this->input->post('Europe');
$postdata['NorthAmerica'] = $this->input->post('NorthAmerica');
$postdata['SouthAmerica'] = $this->input->post('SouthAmerica');
$postdata['Oceania'] = $this->input->post('Oceania');
$postdata['Antarctica'] = $this->input->post('Antarctica');
$postdata['band'] = $this->input->post('band');
}
else { // Setting default values at first load of page
$postdata['lotw'] = 1;
$postdata['qsl'] = 1;
$postdata['worked'] = 1;
$postdata['confirmed'] = 1;
$postdata['notworked'] = 1;
$postdata['deleted'] = 1;
$postdata['Africa'] = 1;
$postdata['Asia'] = 1;
$postdata['Europe'] = 1;
$postdata['NorthAmerica'] = 1;
$postdata['SouthAmerica'] = 1;
$postdata['Oceania'] = 1;
$postdata['Antarctica'] = 1;
$postdata['band'] = 'All';
}
$dxcclist = $this->dxcc->fetchdxcc($postdata);
$data['dxcc_array'] = $this->dxcc->get_dxcc_array($dxcclist, $bands, $postdata);
// Render Page
$data['page_title'] = "Awards - DXCC";
$this->load->view('interface_assets/header', $data);
$this->load->view('awards/dxcc/index');
$this->load->view('interface_assets/footer');
}
public function dxcc_details(){

Wyświetl plik

@ -31,8 +31,8 @@ class Update extends CI_Controller {
$count = 0;
foreach ($xml_data->entities->entity as $entity) {
$startinfo = strtotime($record->start);
$endinfo = strtotime($record->end);
$startinfo = strtotime($entity->start);
$endinfo = strtotime($entity->end);
$start_date = ($startinfo) ? date('Y-m-d H:i:s',$startinfo) : null;
$end_date = ($endinfo) ? date('Y-m-d H:i:s',$endinfo) : null;

Wyświetl plik

@ -172,5 +172,289 @@ class DXCC extends CI_Model {
$this->db->order_by('name', 'ASC');
return $this->db->get('dxcc_entities');
}
function get_dxcc_array($dxccArray, $bands, $postdata) {
$CI =& get_instance();
$CI->load->model('Stations');
$station_id = $CI->Stations->find_active();
foreach ($bands as $band) { // Looping through bands and entities to generate the array needed for display
foreach ($dxccArray as $dxcc) {
$dxccMatrix[$dxcc->adif]['name'] = $dxcc->name;
$dxccMatrix[$dxcc->adif]['Dxccprefix'] = $dxcc->prefix;
$dxccMatrix[$dxcc->adif]['Deleted'] = isset($dxcc->Enddate) ? "<div class='alert-danger'>Y</div>" : '';
$dxccMatrix[$dxcc->adif][$band] = '-';
}
// If worked is checked, we add worked entities to the array
if ($postdata['worked'] != NULL) {
$workedDXCC = $this->getDxccBandWorked($station_id, $band, $postdata);
foreach ($workedDXCC as $wdxcc) {
$dxccMatrix[$wdxcc->dxcc][$band] = '<div class="alert-danger"><a href=\'dxcc_details?Country="'.$wdxcc->name.'"&Band="'. $band . '"\'>W</a></div>';;
}
}
// If confirmed is checked, we add confirmed entities to the array
if ($postdata['confirmed'] != NULL) {
$confirmedDXCC = $this->getDxccBandConfirmed($station_id, $band, $postdata);
foreach ($confirmedDXCC as $cdxcc) {
$dxccMatrix[$cdxcc->dxcc][$band] = '<div class="alert-success"><a href=\'dxcc_details?Country="'.$cdxcc->name.'"&Band="'. $band . '"\'>C</a></div>';;
}
}
}
// We want to remove the worked dxcc's in the list, since we do not want to display them
if ($postdata['worked'] == NULL) {
$workedDxcc = $this->getDxccWorked($station_id, $postdata);
foreach ($workedDxcc as $wdxcc) {
if (array_key_exists($wdxcc->dxcc, $dxccMatrix)) {
unset($dxccMatrix[$wdxcc->dxcc]);
}
}
}
// We want to remove the confirmed dxcc's in the list, since we do not want to display them
if ($postdata['confirmed'] == NULL) {
$confirmedDxcc = $this->getDxccConfirmed($station_id, $postdata);
foreach ($confirmedDxcc as $cdxcc) {
if (array_key_exists($cdxcc->dxcc, $dxccMatrix)) {
unset($dxccMatrix[$cdxcc->dxcc]);
}
}
}
if ($dxccMatrix) {
return $dxccMatrix;
}
else {
return 0;
}
}
function getDxccBandConfirmed($station_id, $band, $postdata) {
$sql = "select adif as dxcc, name from dxcc_entities
join (
select col_dxcc from table_hrd_contacts_v01 thcv
where station_id = " . $station_id .
" and col_dxcc > 0";
if ($band == 'SAT') {
$sql .= " and col_prop_mode ='" . $band . "'";
}
else {
$sql .= " and col_band ='" . $band . "'";
}
$sql .= $this->addQslToQuery($postdata);
$sql .= " group by col_dxcc
) x on dxcc_entities.adif = x.col_dxcc";
if ($postdata['deleted'] == NULL) {
$sql .= " and dxcc_entities.end is null";
}
$sql .= $this->addContinentsToQuery($postdata);
$query = $this->db->query($sql);
return $query->result();
}
function getDxccBandWorked($station_id, $band, $postdata) {
$sql = "select adif as dxcc, name from dxcc_entities
join (
select col_dxcc from table_hrd_contacts_v01 thcv
where station_id = " . $station_id .
" and col_dxcc > 0";
if ($band == 'SAT') {
$sql .= " and col_prop_mode ='" . $band . "'";
}
else {
$sql .= " and col_band ='" . $band . "'";
}
$sql .= " group by col_dxcc
) x on dxcc_entities.adif = x.col_dxcc";;
if ($postdata['deleted'] == NULL) {
$sql .= " and dxcc_entities.end is null";
}
$sql .= $this->addContinentsToQuery($postdata);
$query = $this->db->query($sql);
return $query->result();
}
function fetchDxcc($postdata) {
$CI =& get_instance();
$CI->load->model('Stations');
$station_id = $CI->Stations->find_active();
$sql = "select adif, prefix, name, date(end) Enddate, date(start) Startdate
from dxcc_entities";
if ($postdata['notworked'] == NULL) {
$sql .= " join (select col_dxcc from table_hrd_contacts_v01 where station_id = $station_id";
if ($postdata['band'] != 'All') {
if ($postdata['band'] == 'SAT') {
$sql .= " and col_prop_mode ='" . $postdata['band'] . "'";
}
else {
$sql .= " and col_band ='" . $postdata['band'] . "'";
}
}
$sql .= ' group by col_dxcc) x on dxcc_entities.adif = x.col_dxcc';
}
$sql .= " where 1 = 1";
if ($postdata['deleted'] == NULL) {
$sql .= " and end is null";
}
$sql .= $this->addContinentsToQuery($postdata);
$sql .= ' order by prefix';
$query = $this->db->query($sql);
return $query->result();
}
function getDxccWorked($station_id, $postdata) {
$sql = "SELECT adif as dxcc FROM dxcc_entities
join (
select col_dxcc
from table_hrd_contacts_v01 thcv
where station_id = " . $station_id .
" and col_dxcc > 0";
if ($postdata['band'] != 'All') {
if ($postdata['band'] == 'SAT') {
$sql .= " and col_prop_mode ='" . $postdata['band'] . "'";
}
else {
$sql .= " and col_band ='" . $postdata['band'] . "'";
}
}
$sql .= " and not exists (select 1 from table_hrd_contacts_v01 where station_id = $station_id and col_dxcc = thcv.col_dxcc";
if ($postdata['band'] != 'All') {
if ($postdata['band'] == 'SAT') {
$sql .= " and col_prop_mode ='" . $postdata['band'] . "'";
}
else {
$sql .= " and col_band ='" . $postdata['band'] . "'";
}
}
$sql .= $this->addQslToQuery($postdata);
$sql .= ')';
$sql .= " group by col_dxcc
) ll on dxcc_entities.adif = ll.col_dxcc
where 1=1";
if ($postdata['deleted'] == 'false') {
$sql .= " and dxcc_entities.end is null";
}
$sql .= $this->addContinentsToQuery($postdata);
$query = $this->db->query($sql);
return $query->result();
}
function getDxccConfirmed($station_id, $postdata) {
$sql = "SELECT adif as dxcc FROM dxcc_entities
join (
select col_dxcc
from table_hrd_contacts_v01 thcv
where station_id = ". $station_id .
" and col_dxcc > 0";
if ($postdata['band'] != 'All') {
if ($postdata['band'] == 'SAT') {
$sql .= " and col_prop_mode ='" . $postdata['band'] . "'";
}
else {
$sql .= " and col_band ='" . $postdata['band'] . "'";
}
}
$sql .= $this->addQslToQuery($postdata);
$sql .= " group by col_dxcc
) ll on dxcc_entities.adif = ll.col_dxcc
where 1=1";
if ($postdata['deleted'] == 'false') {
$sql .= " and dxcc_entities.end is null";
}
$sql .= $this->addContinentsToQuery($postdata);
$query = $this->db->query($sql);
return $query->result();
}
// Made function instead of repeating this several times
function addQslToQuery($postdata) {
$sql = '';
if ($postdata['lotw'] != NULL and $postdata['qsl'] == NULL) {
$sql .= " and col_lotw_qsl_rcvd = 'Y'";
}
if ($postdata['qsl'] != NULL and $postdata['lotw'] == NULL) {
$sql .= " and col_qsl_rcvd = 'Y'";
}
if ($postdata['qsl'] != NULL && $postdata['lotw'] != NULL) {
$sql .= " and (col_qsl_rcvd = 'Y' or col_lotw_qsl_rcvd = 'Y')";
}
return $sql;
}
// Made function instead of repeating this several times
function addContinentsToQuery($postdata) {
$sql = '';
if ($postdata['Africa'] == NULL) {
$sql .= " and cont <> 'AF'";
}
if ($postdata['Europe'] == NULL) {
$sql .= " and cont <> 'EU'";
}
if ($postdata['Asia'] == NULL) {
$sql .= " and cont <> 'AS'";
}
if ($postdata['SouthAmerica'] == NULL) {
$sql .= " and cont <> 'SA'";
}
if ($postdata['NorthAmerica'] == NULL) {
$sql .= " and cont <> 'NA'";
}
if ($postdata['Oceania'] == NULL) {
$sql .= " and cont <> 'OC'";
}
if ($postdata['Antarctica'] == NULL) {
$sql .= " and cont <> 'AN'";
}
return $sql;
}
}
?>

Wyświetl plik

@ -5,36 +5,142 @@
<!-- Sub Nav for Awards -->
<?php $this->load->view("awards/nav_bar")?>
<table class="table table-striped table-hover">
<thead>
<tr>
<td style="width:225px">Country (<?php echo count($dxcc)?>)</td>
<?php
foreach ($worked_bands as $slot) {
echo " <td>$slot</td>\n";
}
?>
</tr>
</thead>
<tbody>
<?php
foreach($dxcc as $country=>$val){
print("<tr><td>$country</td>");
foreach($val as $band=>$count){
if (in_array($band, $worked_bands)) {
if ($count == 0){
print("<td>&nbsp;</td>");
}else{
printf("<td><a href='dxcc_details?Country=\"%s\"&Band=\"%s\"'>%d</a></td>", str_replace("&", "%26", $country), $band, $count);
}
}
}
print("</tr>");
}
<form class="form" action="<?php echo site_url('awards/dxcc'); ?>" method="post" enctype="multipart/form-data">
<fieldset>
?>
</tbody>
<!-- Multiple Checkboxes (inline) -->
<div class="form-group row">
<div class="col-md-2 control-label" for="checkboxes">Deleted dxcc</div>
<div class="col-md-10">
<div class="form-check-inline">
<input class="form-check-input" type="checkbox" name="includedeleted" id="includedeleted" value="1" checked="1">
<label class="form-check-label" for="includedeleted">Include Deleted</label>
</div>
</div>
</div>
</table>
<!-- Multiple Checkboxes (inline) -->
<div class="form-group row">
<div class="col-md-2" for="checkboxes">Worked / confirmed</div>
<div class="col-md-10">
<div class="form-check-inline">
<input class="form-check-input" type="checkbox" name="worked" id="worked" value="1" checked="1">
<label class="form-check-label" for="worked">Show worked</label>
</div>
<div class="form-check-inline">
<input class="form-check-input" type="checkbox" name="confirmed" id="confirmed" value="1" checked="1">
<label class="form-check-label" for="confirmed">Show confirmed</label>
</div>
<div class="form-check-inline">
<input class="form-check-input" type="checkbox" name="notworked" id="notworked" value="1" checked="1">
<label class="form-check-label" for="notworked">Show not worked</label>
</div>
</div>
</div>
<div class="form-group row">
<div class="col-md-2">QSL / LoTW</div>
<div class="col-md-10">
<div class="form-check-inline">
<input class="form-check-input" type="checkbox" name="qsl" value="1" checked="1" id="qsl">
<label class="form-check-label" for="qsl">QSL</label>
</div>
<div class="form-check-inline">
<input class="form-check-input" type="checkbox" name="lotw" value="1" checked="1" id="lotw">
<label class="form-check-label" for="lotw">LoTW</label>
</div>
</div>
</div>
<div class="form-group row">
<div class="col-md-2">Continents</div>
<div class="col-md-10">
<div class="form-check-inline">
<input class="form-check-input" type="checkbox" name="Antarctica" id="Antarctica" value="1" checked="1">
<label class="form-check-label" for="Antarctica">Antarctica</label>
</div>
<div class="form-check-inline">
<input class="form-check-input" type="checkbox" name="Africa" id="Africa" value="1" checked="1">
<label class="form-check-label" for="Africa">Africa</label>
</div>
<div class="form-check-inline">
<input class="form-check-input" type="checkbox" name="Asia" id="Asia" value="1" checked="1">
<label class="form-check-label" for="Asia">Asia</label>
</div>
<div class="form-check-inline">
<input class="form-check-input" type="checkbox" name="Europe" id="Europe" value="1" checked="1">
<label class="form-check-label" for="Europe">Europe</label>
</div>
<div class="form-check-inline">
<input class="form-check-input" type="checkbox" name="NorthAmerica" id="NorthAmerica" value="1" checked="1">
<label class="form-check-label" for="NorthAmerica">North America</label>
</div>
<div class="form-check-inline">
<input class="form-check-input" type="checkbox" name="SouthAmerica" id="SouthAmerica" value="1" checked="1">
<label class="form-check-label" for="SouthAmerica">South America</label>
</div>
<div class="form-check-inline">
<input class="form-check-input" type="checkbox" name="Oceania" id="Oceania" value="1" checked="1">
<label class="form-check-label" for="Oceania">Oceania</label>
</div>
</div>
</div>
<!-- Select Basic -->
<div class="form-group row">
<label class="col-md-2 control-label" for="band">Band</label>
<div class="col-md-2">
<select id="band2" name="band" class="form-control">
<option value="All" selected>Every band</option>
<?php foreach($worked_bands as $band) {
echo '<option value="' . $band . '">' . $band . '</option>';
} ?>
</select>
</div>
</div>
<!-- Button (Double) -->
<div class="form-group row">
<label class="col-md-2 control-label" for="button1id"></label>
<div class="col-md-10">
<button id="button2id" type="reset" name="button2id" class="btn btn-danger">Reset</button>
<button id="button1id" type="submit" name="button1id" class="btn btn-success btn-primary">Show</button>
</div>
</div>
</fieldset>
</form>
<?php
$i = 1;
if ($dxcc_array) {
echo '
<table class="table table-bordered table-hover table-striped table-condensed text-center">
<thead>
<tr>
<td>#</td>
<td>DXCCName</td>
<td>Prefix</td>
<td>Deleted</td>';
foreach($bands as $band) {
echo '<td>' . $band . '</td>';
}
echo '</tr>
</thead>
<tbody>';
foreach ($dxcc_array as $dxcc => $value) { // Fills the table with the data
echo '<tr>
<td>'. $i++ .'</td>';
foreach ($value as $key) {
echo '<td style="text-align: center">' . $key . '</td>';
}
echo '</tr>';
}
echo '</tfoot></table></div>';
}
else {
echo '<div class="alert alert-danger" role="alert"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>Nothing found!</div>';
}
?>
</div>