diff --git a/application/config/migration.php b/application/config/migration.php index 2fe2273e..23406e21 100644 --- a/application/config/migration.php +++ b/application/config/migration.php @@ -22,7 +22,7 @@ $config['migration_enabled'] = TRUE; | */ -$config['migration_version'] = 155; +$config['migration_version'] = 156; /* |-------------------------------------------------------------------------- diff --git a/application/controllers/Awards.php b/application/controllers/Awards.php index 7d6ae7de..3f845ec5 100644 --- a/application/controllers/Awards.php +++ b/application/controllers/Awards.php @@ -167,6 +167,80 @@ class Awards extends CI_Controller { $this->load->view('interface_assets/footer'); } + public function waja () { + $footerData = []; + $footerData['scripts'] = [ + 'assets/js/sections/wajamap.js?' . filemtime(realpath(__DIR__ . "/../../assets/js/sections/wajamap.js")) + ]; + + $this->load->model('waja'); + $this->load->model('modes'); + $this->load->model('bands'); + + $data['worked_bands'] = $this->bands->get_worked_bands('waja'); + $data['modes'] = $this->modes->active(); + + 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->security->xss_clean($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['qsl'] = $this->security->xss_clean($this->input->post('qsl')); + $postdata['lotw'] = $this->security->xss_clean($this->input->post('lotw')); + $postdata['eqsl'] = $this->security->xss_clean($this->input->post('eqsl')); + $postdata['worked'] = $this->security->xss_clean($this->input->post('worked')); + $postdata['confirmed'] = $this->security->xss_clean($this->input->post('confirmed')); + $postdata['notworked'] = $this->security->xss_clean($this->input->post('notworked')); + $postdata['includedeleted'] = $this->security->xss_clean($this->input->post('includedeleted')); + $postdata['Africa'] = $this->security->xss_clean($this->input->post('Africa')); + $postdata['Asia'] = $this->security->xss_clean($this->input->post('Asia')); + $postdata['Europe'] = $this->security->xss_clean($this->input->post('Europe')); + $postdata['NorthAmerica'] = $this->security->xss_clean($this->input->post('NorthAmerica')); + $postdata['SouthAmerica'] = $this->security->xss_clean($this->input->post('SouthAmerica')); + $postdata['Oceania'] = $this->security->xss_clean($this->input->post('Oceania')); + $postdata['Antarctica'] = $this->security->xss_clean($this->input->post('Antarctica')); + $postdata['band'] = $this->security->xss_clean($this->input->post('band')); + $postdata['mode'] = $this->security->xss_clean($this->input->post('mode')); + } + else { // Setting default values at first load of page + $postdata['qsl'] = 1; + $postdata['lotw'] = 1; + $postdata['eqsl'] = 0; + $postdata['worked'] = 1; + $postdata['confirmed'] = 1; + $postdata['notworked'] = 1; + $postdata['includedeleted'] = 0; + $postdata['Africa'] = 1; + $postdata['Asia'] = 1; + $postdata['Europe'] = 1; + $postdata['NorthAmerica'] = 1; + $postdata['SouthAmerica'] = 1; + $postdata['Oceania'] = 1; + $postdata['Antarctica'] = 1; + $postdata['band'] = 'All'; + $postdata['mode'] = 'All'; + } + + $data['waja_array'] = $this->waja->get_waja_array($bands, $postdata); + $data['waja_summary'] = $this->waja->get_waja_summary($bands, $postdata); + + // Render Page + $data['page_title'] = "Awards - WAJA"; + $this->load->view('interface_assets/header', $data); + $this->load->view('awards/waja/index'); + $this->load->view('interface_assets/footer'); + } + public function vucc() { $this->load->model('vucc'); $this->load->model('bands'); diff --git a/application/language/bulgarian/menu_lang.php b/application/language/bulgarian/menu_lang.php index 805cdfb2..83e76c8b 100644 --- a/application/language/bulgarian/menu_lang.php +++ b/application/language/bulgarian/menu_lang.php @@ -1,93 +1,94 @@ -db->field_exists('waja', 'bandxuser')) { + $this->dbforge->add_column('bandxuser', $fields); + } + } + + public function down() + { + if ($this->db->field_exists('waja', 'bandxuser')) { + $this->dbforge->drop_column('bandxuser', 'waja'); + } + } +} diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index c7ee44fa..dd0bd5e2 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -386,6 +386,10 @@ class Logbook_model extends CI_Model { case 'DOK': $this->db->where('COL_DARC_DOK', $searchphrase); break; + case 'WAJA': + $this->db->where('COL_STATE', $searchphrase); + $this->db->where_in('COL_DXCC', ['339']); + break; case 'QSLRDATE': $this->db->where('date(COL_QSLRDATE)=date(SYSDATE())'); break; @@ -584,7 +588,7 @@ class Logbook_model extends CI_Model { $this->mark_clublog_qsos_sent($last_id); } } - + $result = ''; $result = $this->exists_hrdlog_code($data['station_id']); // Push qso to hrdlog if code is set, and realtime upload is enabled, and we're not importing an adif-file @@ -738,7 +742,7 @@ class Logbook_model extends CI_Model { } else { $returner['status']=$response; } - curl_close ($request); + curl_close ($request); return ($returner); } diff --git a/application/models/Waja.php b/application/models/Waja.php new file mode 100644 index 00000000..a5829e45 --- /dev/null +++ b/application/models/Waja.php @@ -0,0 +1,402 @@ + 'Hokkaido', + '02' => 'Aomori', + '03' => 'Iwate', + '04' => 'Akita', + '05' => 'Yamagata', + '06' => 'Miyagi', + '07' => 'Fukushima', + '08' => 'Niigata', + '09' => 'Nagano', + '10' => 'Tokyo', + '11' => 'Kanagawa', + '12' => 'Chiba', + '13' => 'Saitama', + '14' => 'Ibaraki', + '15' => 'Tochigi', + '16' => 'Gunma', + '17' => 'Yamanashi', + '18' => 'Shizuoka', + '19' => 'Gifu', + '20' => 'Aichi', + '21' => 'Mie', + '22' => 'Kyoto', + '23' => 'Shiga', + '24' => 'Nara', + '25' => 'Osaka', + '26' => 'Wakayama', + '27' => 'Hyogo', + '28' => 'Toyama', + '29' => 'Fukui', + '30' => 'Ishikawa', + '31' => 'Okayama', + '32' => 'Shimane', + '33' => 'Yamaguchi', + '34' => 'Tottori', + '35' => 'Hiroshima', + '36' => 'Kagawa', + '37' => 'Tokushima', + '38' => 'Ehime', + '39' => 'Kochi', + '40' => 'Fukuoka', + '41' => 'Saga', + '42' => 'Nagasaki', + '43' => 'Kumamoto', + '44' => 'Oita', + '45' => 'Miyazaki', + '46' => 'Kagoshima', + '47' => 'Okinawa'); + + public $prefectureString = '01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47'; + + function get_waja_array($bands, $postdata) { + $CI =& get_instance(); + $CI->load->model('logbooks_model'); + $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); + + if (!$logbooks_locations_array) { + return null; + } + + $location_list = "'".implode("','",$logbooks_locations_array)."'"; + + $wajaArray = explode(',', $this->prefectureString); + + $prefectures = array(); // Used for keeping track of which states that are not worked + + $qsl = ""; + if ($postdata['confirmed'] != NULL) { + if ($postdata['qsl'] != NULL ) { + $qsl .= "Q"; + } + if ($postdata['lotw'] != NULL ) { + $qsl .= "L"; + } + if ($postdata['eqsl'] != NULL ) { + $qsl .= "E"; + } + } + + foreach ($wajaArray as $state) { // Generating array for use in the table + $prefectures[$state]['count'] = 0; // Inits each state's count + } + + + foreach ($bands as $band) { + foreach ($wajaArray as $state) { // Generating array for use in the table + $bandWaja[$state]['Number'] = $state; + $bandWaja[$state]['Prefecture'] = $this->jaPrefectures[$state]; + $bandWaja[$state][$band] = '-'; // Sets all to dash to indicate no result + } + + if ($postdata['worked'] != NULL) { + $wajaBand = $this->getWajaWorked($location_list, $band, $postdata); + foreach ($wajaBand as $line) { + $bandWaja[$line->col_state][$band] = '
col_state . '","' . $band . '","'. $postdata['mode'] . '","WAJA", "")\'>W
'; + $prefectures[$line->col_state]['count']++; + } + } + if ($postdata['confirmed'] != NULL) { + $wajaBand = $this->getWajaConfirmed($location_list, $band, $postdata); + foreach ($wajaBand as $line) { + $bandWaja[$line->col_state][$band] = '
col_state . '","' . $band . '","'. $postdata['mode'] . '","WAJA", "'.$qsl.'")\'>C
'; + $prefectures[$line->col_state]['count']++; + } + } + } + + // We want to remove the worked states in the list, since we do not want to display them + if ($postdata['worked'] == NULL) { + $wajaBand = $this->getWajaWorked($location_list, $postdata['band'], $postdata); + foreach ($wajaBand as $line) { + unset($bandWaja[$line->col_state]); + } + } + + // We want to remove the confirmed states in the list, since we do not want to display them + if ($postdata['confirmed'] == NULL) { + $wasBand = $this->getWajaConfirmed($location_list, $postdata['band'], $postdata); + foreach ($wasBand as $line) { + unset($bandWaja[$line->col_state]); + } + } + + if ($postdata['notworked'] == NULL) { + foreach ($wajaArray as $state) { + if ($prefectures[$state]['count'] == 0) { + unset($bandWaja[$state]); + }; + } + } + + if (isset($bandWaja)) { + return $bandWaja; + } + else { + return 0; + } + } + + function getWajaBandConfirmed($location_list, $band, $postdata) { + $sql = "select adif as waja, name from dxcc_entities + join ( + select col_dxcc from ".$this->config->item('table_name')." thcv + where station_id in (" . $location_list . + ") and col_dxcc > 0"; + + $sql .= $this->addBandToQuery($band); + + if ($postdata['mode'] != 'All') { + $sql .= " and (col_mode = '" . $postdata['mode'] . "' or col_submode = '" . $postdata['mode'] . "')"; + } + + $sql .= $this->addQslToQuery($postdata); + + $sql .= " group by col_dxcc + ) x on dxcc_entities.adif = x.col_dxcc"; + + if ($postdata['includedeleted'] == NULL) { + $sql .= " and dxcc_entities.end is null"; + } + + $sql .= $this->addContinentsToQuery($postdata); + + $query = $this->db->query($sql); + + return $query->result(); + } + + function getWajaBandWorked($location_list, $band, $postdata) { + $sql = "select adif as waja, name from dxcc_entities + join ( + select col_dxcc from ".$this->config->item('table_name')." thcv + where station_id in (" . $location_list . + ") and col_dxcc > 0"; + + $sql .= $this->addBandToQuery($band); + + if ($postdata['mode'] != 'All') { + $sql .= " and (col_mode = '" . $postdata['mode'] . "' or col_submode = '" . $postdata['mode'] . "')"; + } + + $sql .= " group by col_dxcc + ) x on dxcc_entities.adif = x.col_dxcc";; + + if ($postdata['includedeleted'] == NULL) { + $sql .= " and dxcc_entities.end is null"; + } + + $sql .= $this->addContinentsToQuery($postdata); + + $query = $this->db->query($sql); + + return $query->result(); + } + + function addBandToQuery($band) { + $sql = ''; + if ($band != 'All') { + if ($band == 'SAT') { + $sql .= " and col_prop_mode ='" . $band . "'"; + } else { + $sql .= " and col_prop_mode !='SAT'"; + $sql .= " and col_band ='" . $band . "'"; + } + } + return $sql; + } + + /* + * Function returns all worked, but not confirmed states + * $postdata contains data from the form, in this case Lotw or QSL are used + */ + function getWajaWorked($location_list, $band, $postdata) { + $sql = "SELECT distinct col_state FROM " . $this->config->item('table_name') . " thcv + where station_id in (" . $location_list . ")"; + + if ($postdata['mode'] != 'All') { + $sql .= " and (col_mode = '" . $postdata['mode'] . "' or col_submode = '" . $postdata['mode'] . "')"; + } + + $sql .= $this->addStateToQuery(); + + $sql .= $this->addBandToQuery($band); + + $sql .= " and not exists (select 1 from ". $this->config->item('table_name') . + " where station_id in (". $location_list . ")" . + " and col_state = thcv.col_state"; + + if ($postdata['mode'] != 'All') { + $sql .= " and (col_mode = '" . $postdata['mode'] . "' or col_submode = '" . $postdata['mode'] . "')"; + } + + $sql .= $this->addBandToQuery($band); + + $sql .= $this->addQslToQuery($postdata); + + $sql .= $this->addStateToQuery(); + + $sql .= ")"; + + $query = $this->db->query($sql); + + return $query->result(); + } + + /* + * Function returns all confirmed states on given band and on LoTW or QSL + * $postdata contains data from the form, in this case Lotw or QSL are used + */ + function getWajaConfirmed($location_list, $band, $postdata) { + $sql = "SELECT distinct col_state FROM " . $this->config->item('table_name') . " thcv + where station_id in (" . $location_list . ")"; + + if ($postdata['mode'] != 'All') { + $sql .= " and (col_mode = '" . $postdata['mode'] . "' or col_submode = '" . $postdata['mode'] . "')"; + } + + $sql .= $this->addStateToQuery(); + + $sql .= $this->addBandToQuery($band); + + $sql .= $this->addQslToQuery($postdata); + + $query = $this->db->query($sql); + + return $query->result(); + } + + + // Made function instead of repeating this several times + function addQslToQuery($postdata) { + $sql = ''; + $qsl = array(); + if ($postdata['lotw'] != NULL || $postdata['qsl'] != NULL || $postdata['eqsl'] != NULL) { + $sql .= ' and ('; + if ($postdata['qsl'] != NULL) { + array_push($qsl, "col_qsl_rcvd = 'Y'"); + } + if ($postdata['lotw'] != NULL) { + array_push($qsl, "col_lotw_qsl_rcvd = 'Y'"); + } + if ($postdata['eqsl'] != NULL) { + array_push($qsl, "col_eqsl_qsl_rcvd = 'Y'"); + } + $sql .= implode(' or ', $qsl); + $sql .= ')'; + } + return $sql; + } + + /* + * Function gets worked and confirmed summary on each band on the active stationprofile + */ + function get_waja_summary($bands, $postdata) + { + $CI =& get_instance(); + $CI->load->model('logbooks_model'); + $logbooks_locations_array = $CI->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); + + if (!$logbooks_locations_array) { + return null; + } + + $location_list = "'".implode("','",$logbooks_locations_array)."'"; + + foreach ($bands as $band) { + $worked = $this->getSummaryByBand($band, $postdata, $location_list); + $confirmed = $this->getSummaryByBandConfirmed($band, $postdata, $location_list); + $wajaSummary['worked'][$band] = $worked[0]->count; + $wajaSummary['confirmed'][$band] = $confirmed[0]->count; + } + + $workedTotal = $this->getSummaryByBand($postdata['band'], $postdata, $location_list); + $confirmedTotal = $this->getSummaryByBandConfirmed($postdata['band'], $postdata, $location_list); + + $wajaSummary['worked']['Total'] = $workedTotal[0]->count; + $wajaSummary['confirmed']['Total'] = $confirmedTotal[0]->count; + + return $wajaSummary; + } + + function getSummaryByBand($band, $postdata, $location_list) + { + $sql = "SELECT count(distinct thcv.col_state) as count FROM " . $this->config->item('table_name') . " thcv"; + + $sql .= " where station_id in (" . $location_list . ")"; + + if ($band == 'SAT') { + $sql .= " and thcv.col_prop_mode ='" . $band . "'"; + } else if ($band == 'All') { + $this->load->model('bands'); + + $bandslots = $this->bands->get_worked_bands('was'); + + $bandslots_list = "'".implode("','",$bandslots)."'"; + + $sql .= " and thcv.col_band in (" . $bandslots_list . ")" . + " and thcv.col_prop_mode !='SAT'"; + } else { + $sql .= " and thcv.col_prop_mode !='SAT'"; + $sql .= " and thcv.col_band ='" . $band . "'"; + } + + if ($postdata['mode'] != 'All') { + $sql .= " and (col_mode = '" . $postdata['mode'] . "' or col_submode = '" . $postdata['mode'] . "')"; + } + + $sql .= $this->addStateToQuery(); + + $query = $this->db->query($sql); + + return $query->result(); + } + + function getSummaryByBandConfirmed($band, $postdata, $location_list) + { + $sql = "SELECT count(distinct thcv.col_state) as count FROM " . $this->config->item('table_name') . " thcv"; + + $sql .= " where station_id in (" . $location_list . ")"; + + if ($band == 'SAT') { + $sql .= " and thcv.col_prop_mode ='" . $band . "'"; + } else if ($band == 'All') { + $this->load->model('bands'); + + $bandslots = $this->bands->get_worked_bands('was'); + + $bandslots_list = "'".implode("','",$bandslots)."'"; + + $sql .= " and thcv.col_band in (" . $bandslots_list . ")" . + " and thcv.col_prop_mode !='SAT'"; + } else { + $sql .= " and thcv.col_prop_mode !='SAT'"; + $sql .= " and thcv.col_band ='" . $band . "'"; + } + + if ($postdata['mode'] != 'All') { + $sql .= " and (col_mode = '" . $postdata['mode'] . "' or col_submode = '" . $postdata['mode'] . "')"; + } + + $sql .= $this->addQslToQuery($postdata); + + $sql .= $this->addStateToQuery(); + + $query = $this->db->query($sql); + + return $query->result(); + } + + + function addStateToQuery() { + $sql = ''; + $sql .= " and COL_DXCC in ('339')"; + $sql .= " and COL_STATE in ($this->prefectureString)"; + return $sql; + } +} +?> diff --git a/application/views/awards/waja/index.php b/application/views/awards/waja/index.php new file mode 100644 index 00000000..a9feb370 --- /dev/null +++ b/application/views/awards/waja/index.php @@ -0,0 +1,206 @@ + + +
+ +
+
+

+
+ + +
+
+ +
+
Worked / Confirmed
+
+
+ input->post('worked') || $this->input->method() !== 'post') echo ' checked="checked"'; ?> > + +
+
+ input->post('confirmed') || $this->input->method() !== 'post') echo ' checked="checked"'; ?> > + +
+
+ input->post('notworked') || $this->input->method() !== 'post') echo ' checked="checked"'; ?> > + +
+
+
+ +
+
QSL Type
+
+
+ input->post('qsl') || $this->input->method() !== 'post') echo ' checked="checked"'; ?> > + +
+
+ input->post('lotw') || $this->input->method() !== 'post') echo ' checked="checked"'; ?> > + +
+
+ input->post('eqsl')) echo ' checked="checked"'; ?> > + +
+
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ + +
+
+ +
+
+ + +
+ +
+
+
+ +
+ +
+ +
+ + + + + Number + Prefecture'; + + foreach($bands as $band) { + echo '' . $band . ''; + } + echo ' + + '; + foreach ($waja_array as $dxcc => $value) { // Fills the table with the data + echo ''; + foreach ($value as $name => $key) { + echo '' . $key . ''; + } + echo ''; + } + echo ' +

Summary

+ + + + '; + + foreach($bands as $band) { + echo ''; + } + echo ' + + + + + '; + + foreach ($waja_summary['worked'] as $dxcc) { // Fills the table with the data + echo ''; + } + + echo ' + '; + foreach ($waja_summary['confirmed'] as $dxcc) { // Fills the table with the data + echo ''; + } + + echo ' +
' . $band . 'Total
Total worked' . $dxcc . '
Total confirmed' . $dxcc . '
+
'; + + } + else { + echo ''; + } + ?> +
+
+ diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index 9c8c5fcb..d013da67 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -12,7 +12,7 @@ @@ -761,7 +761,7 @@ function showActivatorsMap(call, count, grids) { uri->segment(1) == "" || $this->uri->segment(1) == "dashboard" ) { ?> - + +uri->segment(2) == "waja") { ?> + + + uri->segment(2) == "vucc_band") { ?>