diff --git a/application/controllers/Statistics.php b/application/controllers/Statistics.php index 6864d9670..698bfdd0e 100644 --- a/application/controllers/Statistics.php +++ b/application/controllers/Statistics.php @@ -120,7 +120,7 @@ class Statistics extends CI_Controller { //get year if present $yr = xss_clean($this->input->post('yr')) ?? 'All'; - + //load stats $total_operators = $this->logbook_model->total_operators($yr); @@ -307,4 +307,35 @@ class Statistics extends CI_Controller { $this->load->view('statistics/details', $data); } + + public function initials() { + $this->load->model('stats'); + $this->load->model('bands'); + + $data['modes'] = $this->stats->get_eme_modes(); + + $data['worked_bands'] = $this->bands->get_worked_bands_eme(); + + // Set Page Title + $data['page_title'] = __("EME Initials"); + + $footerData = []; + $footerData['scripts'] = [ + 'assets/js/sections/initials.js?' . filemtime(realpath(__DIR__ . "/../../assets/js/sections/initials.js")), + ]; + + // Load Views + $this->load->view('interface_assets/header', $data); + $this->load->view('statistics/initials'); + $this->load->view('interface_assets/footer', $footerData); + } + + public function getInitials() { + $band = xss_clean($this->input->post('band')); + $mode = xss_clean($this->input->post('mode')); + + $this->load->model('stats'); + $data['intials_array'] = $this->stats->getInitialsFromDb($band, $mode); + $this->load->view('statistics/initialresult', $data); + } } diff --git a/application/models/Bands.php b/application/models/Bands.php index cead11235..e7eabca48 100644 --- a/application/models/Bands.php +++ b/application/models/Bands.php @@ -391,6 +391,25 @@ class Bands extends CI_Model { return $worked_slots; } + + function get_worked_bands_eme() { + if (!$this->logbooks_locations_array) { + return array(); + } + + $location_list = "'".implode("','",$this->logbooks_locations_array)."'"; + + // get all worked slots from database + $data = $this->db->query( + "SELECT distinct LOWER(`COL_BAND`) as `COL_BAND` FROM `".$this->config->item('table_name')."` WHERE station_id in (" . $location_list . ") AND COL_PROP_MODE = 'EME'" + ); + $worked_slots = array(); + foreach($data->result() as $row){ + array_push($worked_slots, $row->COL_BAND); + } + + return $worked_slots; + } } ?> diff --git a/application/models/Stats.php b/application/models/Stats.php index 81b79db58..0cb47dc1e 100644 --- a/application/models/Stats.php +++ b/application/models/Stats.php @@ -918,6 +918,96 @@ return $this->db->get($this->config->item('table_name')); } + + public function getInitialsFromDb($band, $mode) { + $binding = []; + + $this->load->model('logbooks_model'); + $logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); + + if (!$logbooks_locations_array) { + return null; + } + + $sql = "select thcv.col_call, thcv.col_time_on, thcv.col_band, thcv.col_mode, thcv.col_submode, thcv.col_primary_key, thcv.col_vucc_grids, thcv.col_gridsquare FROM ". $this->config->item('table_name') . " thcv"; + + $sql .= " join (SELECT col_call, min(col_time_on) firstworked, col_band, min(col_primary_key) qsoid FROM ".$this->config->item('table_name'); + + $sql .= " where station_id in (" . implode(',',$logbooks_locations_array) . ") and col_prop_mode ='EME'"; + + if ($mode != 'All') { + $sql .= " and (col_mode = ? or col_submode = ?)"; + $binding[] = $mode; + $binding[] = $mode; + } + + if ($band != 'All') { + $sql .= " and col_band = ?"; + $binding[] = $band; + } + + $sql .= " group by col_call, col_band order by firstworked) x on thcv.col_primary_key = x.qsoid"; + + $result = $this->db->query($sql, $binding); + + return $result->result(); + } + + public function getInitialsFromDb2($band, $mode) { + $binding = []; + + $this->load->model('logbooks_model'); + $logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); + + if (!$logbooks_locations_array) { + return null; + } + + $sql = "SELECT col_call, min(col_time_on) firstworked, col_band, min(col_primary_key) qsoid FROM ".$this->config->item('table_name'); + + $sql .= " where station_id in (" . implode(',',$logbooks_locations_array) . ") and col_prop_mode ='EME'"; + + if ($mode != 'All') { + $sql .= " and (col_mode = ? or col_submode = ?)"; + $binding[] = $mode; + $binding[] = $mode; + } + + if ($band != 'All') { + $sql .= " and col_band = ?"; + $binding[] = $band; + } + + $sql .= " group by col_call, col_band order by firstworked"; + + $result = $this->db->query($sql, $binding); + + return $result->result(); + } + + function get_eme_modes() { + + $modes = array(); + + $this->db->select('distinct col_mode, coalesce(col_submode, "") col_submode', FALSE); + $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->where($this->config->item('table_name').'.col_prop_mode', 'EME'); + $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; + } + } ?> diff --git a/application/views/interface_assets/header.php b/application/views/interface_assets/header.php index 7c0b42091..15368caee 100644 --- a/application/views/interface_assets/header.php +++ b/application/views/interface_assets/header.php @@ -164,6 +164,8 @@
  • + +