diff --git a/application/controllers/Awards.php b/application/controllers/Awards.php index 2a9009e7..7c59467f 100644 --- a/application/controllers/Awards.php +++ b/application/controllers/Awards.php @@ -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(){ diff --git a/application/controllers/Update.php b/application/controllers/Update.php index 2c7c8d75..57b78338 100644 --- a/application/controllers/Update.php +++ b/application/controllers/Update.php @@ -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; diff --git a/application/models/Dxcc.php b/application/models/Dxcc.php index 04cbd71b..202e009a 100644 --- a/application/models/Dxcc.php +++ b/application/models/Dxcc.php @@ -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) ? "
Y
" : ''; + $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] = '
name.'"&Band="'. $band . '"\'>W
';; + } + } + + // 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] = '
name.'"&Band="'. $band . '"\'>C
';; + } + } + } + + // 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; + } } ?> diff --git a/application/views/awards/dxcc/index.php b/application/views/awards/dxcc/index.php index fb76f035..eadf2616 100644 --- a/application/views/awards/dxcc/index.php +++ b/application/views/awards/dxcc/index.php @@ -5,36 +5,142 @@ load->view("awards/nav_bar")?> - - - - - - $slot\n"; - } - ?> - - - - $val){ - print(""); - foreach($val as $band=>$count){ - if (in_array($band, $worked_bands)) { - if ($count == 0){ - print(""); - }else{ - printf("", str_replace("&", "%26", $country), $band, $count); - } - } - } - print(""); - } + +
- ?> -
+ +
+
Deleted dxcc
+
+
+ + +
+
+
-
Country ()
$country %d
+ +
+
Worked / confirmed
+
+
+ + +
+
+ + +
+
+ + +
+
+
+ +
+
QSL / LoTW
+
+
+ + +
+
+ + +
+
+
+ +
+
Continents
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ + +
+ +
+ +
+
+ + +
+ +
+ + +
+
+ + + + + + + # + DXCCName + Prefix + Deleted'; + foreach($bands as $band) { + echo '' . $band . ''; + } + echo ' + + '; + foreach ($dxcc_array as $dxcc => $value) { // Fills the table with the data + echo ' + '. $i++ .''; + foreach ($value as $key) { + echo '' . $key . ''; + } + echo ''; + } + echo ''; + + } + else { + echo ''; + } +?>