diff --git a/application/controllers/Callstats.php b/application/controllers/Callstats.php new file mode 100644 index 000000000..67d264654 --- /dev/null +++ b/application/controllers/Callstats.php @@ -0,0 +1,122 @@ +load->model('user_model'); + if (!$this->user_model->authorize(2)) { + $this->session->set_flashdata('error', __("You're not allowed to do that!")); + redirect('dashboard'); + } + } + + public function index() + { + $data['page_title'] = __("Callsign statistics"); + + $this->load->model('bands'); + $this->load->model('Callstats_model'); + + if ($this->input->post('band') != NULL) { // Band is not set when page first loads. + $band = $this->input->post('band'); + } else { + $band = 'All'; + } + + if ($this->input->post('mode') != NULL) { // Mode is not set when page first loads. + $mode = $this->input->post('mode'); + } else { + $mode = 'All'; + } + + if ($this->input->post('propagation') != NULL) { // Propagation is not set when page first loads. + $propagation = $this->input->post('propagation'); + } else { + $propagation = 'All'; + } + + if ($this->input->post('mincount') != NULL) { // mincount is not set when page first loads. + $mincount = $this->input->post('mincount'); + } else { + $mincount = 2; + } + + if ($this->input->post('leogeo') != NULL) { // orbit is not set when page first loads. + $orbit = $this->input->post('leogeo'); + } else { + $orbit = 'both'; + } + + + if ($this->input->post('sat') != NULL) { // Sat is not set when page first loads. + $sat = $this->input->post('sat'); + } else { + $sat = 'All'; + } + + $data['sats'] = $this->bands->get_worked_sats(); + $data['worked_bands'] = $this->bands->get_worked_bands(); + $data['worked_modes'] = $this->Callstats_model->get_worked_modes(); + $data['mincount'] = $mincount; + $data['maxactivatedgrids'] = $this->Callstats_model->get_max_qsos(); + $data['orbit'] = $orbit; + $data['activators_array'] = $this->Callstats_model->get_activators($band, $mode, $propagation, $mincount, $orbit, $sat); + $data['bandselect'] = $band; + $data['modeselect'] = $mode; + $data['satselect'] = $sat; + $data['propagationselect'] = $propagation; + $data['user_default_band'] = $this->session->userdata('user_default_band'); + + $footerData = []; + $footerData['scripts'] = [ + 'assets/js/sections/callstats.js?' . filemtime(realpath(__DIR__ . "/../../assets/js/sections/callstats.js")), + ]; + + $this->load->view('interface_assets/header', $data); + $this->load->view('callstats/index'); + $this->load->view('interface_assets/footer', $footerData); + } + + /* + * Used to fetch QSOs from the table + */ + public function qso_details_callstats() { + $this->load->model('callstats_model'); + + $searchphrase = str_replace('"', "", $this->security->xss_clean($this->input->post("Searchphrase"))); + $band = str_replace('"', "", $this->security->xss_clean($this->input->post("Band"))); + $mode = str_replace('"', "", $this->security->xss_clean($this->input->post("Mode"))); + $sat = str_replace('"', "", $this->security->xss_clean($this->input->post("Sat"))); + $orbit = str_replace('"', "", $this->security->xss_clean($this->input->post("Orbit"))); + $propagation = str_replace('"', "", $this->security->xss_clean($this->input->post("Propagation")) ?? ''); + $data['results'] = $this->callstats_model->qso_details($searchphrase, $band, $mode, $sat, $orbit, $propagation); + + // Render Page + $data['page_title'] = __("Log View"); + $data['filter'] = $searchphrase.__(" and band ").$band . __(" and mode ").$mode . __(" and satellite ").$sat . __(" and orbit ").$orbit . __(" and propagation ").$propagation; + if ($band == 'SAT') { + if ($sat != 'All' && $sat != null) { + $data['filter'] .= __(" and sat ").$sat; + } + if ($orbit != 'All' && $orbit != null) { + $data['filter'] .= __(" and orbit type ").$orbit; + } + } + if ($propagation != '' && $propagation != null) { + $data['filter'] .= __(" and propagation ").$propagation; + } + if ($mode != null && strtolower($mode) != 'all') { + $data['filter'] .= __(" and mode ").$mode; + } + if (!empty($qsltype)) { + $data['filter'] .= __(" and ").implode('/', $qsltype); + } + $this->load->view('awards/details', $data); + } + +} diff --git a/application/models/Callstats_model.php b/application/models/Callstats_model.php new file mode 100644 index 000000000..614515ee8 --- /dev/null +++ b/application/models/Callstats_model.php @@ -0,0 +1,189 @@ +load->model('logbooks_model'); + $this->logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); + } + + function get_activators($band, $mode, $propagation, $mincount, $leogeo, $sat) { + + if ($mincount == '' || $mincount == 0 || !is_numeric($mincount)) { + $mincount = 2; + } + + if (!$this->logbooks_locations_array) { + return null; + } + + $location_list = "'" . implode("','", $this->logbooks_locations_array) . "'"; + $binding = array(); + + $sql = "select + `col_call` as `call`, + COUNT(*) as `count` + from " . $this->config->item('table_name') . " + where station_id in (" . $location_list . ")"; + if ($band != 'All') { + $binding[] = $band; + if ($band == 'SAT') { + switch ($leogeo) { + case 'both': + $sql .= " and col_prop_mode = ?"; + break; + case 'leo': + $sql .= " and col_prop_mode = ?"; + $sql .= " and col_sat_name != 'QO-100'"; + break; + case 'geo': + $sql .= " and col_prop_mode = ?"; + $sql .= " and col_sat_name = 'QO-100'"; + break; + default: + $sql .= " and col_prop_mode = ?"; + break; + } + } else { + $sql .= " and col_prop_mode != 'SAT'"; + $sql .= " and COL_BAND = ?"; + } + } + + if (($propagation ?? 'All') != 'All') { + $this->db->where("COL_PROP_MODE = ?"); + $binding[] = $propagation; + } + + if ($mode != 'All') { + $sql .= " and (col_mode = ? or col_submode = ?)"; + $binding[] = $mode; + $binding[] = $mode; + } + + $sql .= " + group by `col_call` + having `count` >= ? + order by `count` desc"; + + $binding[] = $mincount; + + $query = $this->db->query($sql, $binding); + + return $query->result(); + + } + + function get_max_qsos() { + + if (!$this->logbooks_locations_array) { + return array(); + } + + $location_list = "'" . implode("','", $this->logbooks_locations_array) . "'"; + + $sql = "select max(count) as count from ( + select count(*) count, col_call + from " . $this->config->item('table_name') . " + where station_id in (" . $location_list . ") + group by col_call + order by count(*) desc + ) as x;"; + + $data = $this->db->query($sql); + foreach ($data->result() as $row) { + $max = $row->count; + } + + return ($max ?? 0); + } + + function get_worked_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->order_by('col_mode, col_submode', 'ASC'); + + $query = $this->db->get($this->config->item('table_name')); + + foreach($query->result() as $mode){ + if ($mode->col_submode == null || $mode->col_submode == "") { + array_push($modes, $mode->col_mode); + } else { + array_push($modes, $mode->col_submode); + } + } + + return $modes; + } + + /* + * Used to fetch QSOs from the table + */ + public function qso_details($searchphrase, $band, $mode, $sat, $orbit, $propagation) { + $this->load->model('logbooks_model'); + $logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); + + $this->db->select($this->config->item('table_name').'.*, `station_profile`.*, `dxcc_entities`.*, `lotw_users`.*, `satellite.displayname` AS sat_displayname'); + $this->db->join('station_profile', 'station_profile.station_id = ' . $this->config->item('table_name') . '.station_id'); + $this->db->join('dxcc_entities', 'dxcc_entities.adif = ' . $this->config->item('table_name') . '.COL_DXCC', 'left outer'); + $this->db->join('lotw_users', 'lotw_users.callsign = ' . $this->config->item('table_name') . '.col_call', 'left outer'); + + if (isset($sat) || strtoupper($band) == 'ALL' || $band == 'SAT') { + $this->db->join('satellite', 'satellite.name = ' . $this->config->item('table_name') . '.col_sat_name', 'left outer'); + } + + $this->db->where('COL_CALL', $searchphrase); + + $this->db->where_in($this->config->item('table_name') . '.station_id', $logbooks_locations_array); + + if (strtolower($band) != 'all') { + if ($band != "SAT") { + $this->db->where('COL_PROP_MODE !=', 'SAT'); + $this->db->where('COL_BAND', $band); + } else { + $this->db->where('COL_PROP_MODE', "SAT"); + } + } + + if ($orbit != 'both') { + $this->db->where('orbit', $orbit); + } + + if ($propagation != 'All') { + if ($propagation == 'None') { + $this->db->where('COL_PROP_MODE', ''); + } else if ($propagation == 'NoSAT') { + $this->db->where('COL_PROP_MODE !=', 'SAT'); + } else { + $this->db->where('COL_PROP_MODE', $propagation); + } + } + + if ($mode != 'All') { + $this->db->group_start(); + $this->db->where("COL_MODE", $mode); + $this->db->or_where("COL_SUBMODE", $mode); + $this->db->group_end(); + } + + if ($sat != 'All') { + $this->db->where("COL_SAT_NAME", $sat); + } + + $this->db->order_by("COL_TIME_ON", "desc"); + $this->db->order_by("COL_PRIMARY_KEY", "desc"); + + $this->db->limit(500); + + return $this->db->get($this->config->item('table_name')); + } +} diff --git a/application/views/callstats/index.php b/application/views/callstats/index.php new file mode 100644 index 000000000..db80b8205 --- /dev/null +++ b/application/views/callstats/index.php @@ -0,0 +1,167 @@ +
+

+ +
+ +
+ +
+ +
+ + + + + + + + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + session->userdata('user_date_format')) { + // If Logged in and session exists + $custom_date_format = $this->session->userdata('user_date_format'); + } else { + // Get Default date format from /config/wavelog.php + $custom_date_format = $this->config->item('qso_date_format'); + } + ?> + ' . __("Nothing found!") . '
'; + } + ?> + + + + + + + + # + ' . __("Callsign") . ' + ' . __("#QSOs") . ' + ' . __("Show QSO's") . ' + + + '; + + $activators = array(); + foreach ($activators_array as $line) { + $call = $line->call; + $count = $line->count; + array_push($activators, array($count, $call)); + } + arsort($activators); + foreach ($activators as $line) { + echo ' + ' . $i++ . ' + ' . $line[1] . ' + ' . $line[0] . ' + + '; + } + echo ''; +} diff --git a/application/views/interface_assets/header.php b/application/views/interface_assets/header.php index 95d356834..0142022fb 100644 --- a/application/views/interface_assets/header.php +++ b/application/views/interface_assets/header.php @@ -161,6 +161,8 @@
  • + +
  • + session->userdata('user_type') === '99') { ?> @@ -591,7 +593,7 @@ - +