diff --git a/application/controllers/Cabrillo.php b/application/controllers/Cabrillo.php new file mode 100644 index 00000000..4d02e015 --- /dev/null +++ b/application/controllers/Cabrillo.php @@ -0,0 +1,124 @@ +load->model('user_model'); + if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); } + } + + public function index() { + $data['page_title'] = "Export Cabrillo"; + + $this->load->model('Contesting_model'); + $this->load->model('stations'); + + $data['station_profile'] = $this->stations->all_of_user(); + $active_station_id = $this->stations->find_active(); + $station_profile = $this->stations->profile($active_station_id); + + $data['active_station_info'] = $station_profile->row(); + + $footerData = []; + $footerData['scripts'] = [ + 'assets/js/sections/cabrillo.js' + ]; + + $this->load->view('interface_assets/header', $data); + $this->load->view('cabrillo/index'); + $this->load->view('interface_assets/footer', $footerData); + } + + public function getContests() { + $this->load->model('Contesting_model'); + + $station_id = $this->security->xss_clean($this->input->post('station_id')); + $year = $this->security->xss_clean($this->input->post('year')); + $result = $this->Contesting_model->get_logged_contests($station_id, $year); + + header('Content-Type: application/json'); + echo json_encode($result); + } + + public function getYears() { + $this->load->model('Contesting_model'); + $station_id = $this->security->xss_clean($this->input->post('station_id')); + + $result = $this->Contesting_model->get_logged_years($station_id); + + header('Content-Type: application/json'); + echo json_encode($result); + } + + public function getContestDates() { + $this->load->model('Contesting_model'); + $station_id = $this->security->xss_clean($this->input->post('station_id')); + $year = $this->security->xss_clean($this->input->post('year')); + $contestid = $this->security->xss_clean($this->input->post('contestid')); + + $result = $this->Contesting_model->get_contest_dates($station_id, $year, $contestid); + + header('Content-Type: application/json'); + echo json_encode($result); + } + + public function export() { + // Set memory limit to unlimited to allow heavy usage + ini_set('memory_limit', '-1'); + $this->load->model('Contesting_model'); + + $this->load->model('stations'); + + $this->load->model('user_model'); + + $station_id = $this->security->xss_clean($this->input->post('station_id')); + $contest_id = $this->security->xss_clean($this->input->post('contestid')); + + $from = $this->security->xss_clean($this->input->post('contestdatesfrom')); + $to = $this->security->xss_clean($this->input->post('contestdatesto')); + + $station = $this->stations->profile($station_id); + + $station = $station->row(); + + $userinfo = $this->user_model->get_by_id($this->session->userdata('user_id')); + + $userinfo = $userinfo->row(); + + $data['qsos'] = $this->Contesting_model->export_custom($from, $to, $contest_id, $station_id); + + $data['contest_id'] = $contest_id; + $data['callsign'] = $station->station_callsign; + $data['claimed_score'] = ''; + $data['categoryoperator'] = $this->security->xss_clean($this->input->post('categoryoperator')); + $data['categoryassisted'] = $this->security->xss_clean($this->input->post('categoryassisted')); + $data['categoryband'] = $this->security->xss_clean($this->input->post('categoryband')); + $data['categorymode'] = $this->security->xss_clean($this->input->post('categorymode')); + $data['categorypower'] = $this->security->xss_clean($this->input->post('categorypower')); + $data['categorystation'] = $this->security->xss_clean($this->input->post('categorystation')); + $data['categorytransmitter'] = $this->security->xss_clean($this->input->post('categorytransmitter')); + $data['categoryoverlay'] = $this->security->xss_clean($this->input->post('categoryoverlay')); + $data['operators'] = $this->security->xss_clean($this->input->post('operators')); + $data['club'] = $this->security->xss_clean($this->input->post('club')); + $data['name'] = $userinfo->user_firstname . ' ' . $userinfo->user_lastname; + $data['email'] = $userinfo->user_email; + $data['address'] = $this->security->xss_clean($this->input->post('address')); + $data['addresscity'] = $this->security->xss_clean($this->input->post('addresscity')); + $data['addressstateprovince'] = $this->security->xss_clean($this->input->post('addressstateprovince')); + $data['addresspostalcode'] = $this->security->xss_clean($this->input->post('addresspostalcode')); + $data['addresscountry'] = $this->security->xss_clean($this->input->post('addresscountry')); + $data['soapbox'] = $this->security->xss_clean($this->input->post('soapbox')); + $data['gridlocator'] = $station->station_gridsquare; + + $this->load->view('cabrillo/export', $data); + } +} \ No newline at end of file diff --git a/application/libraries/Cabrilloformat.php b/application/libraries/Cabrilloformat.php new file mode 100644 index 00000000..46339a21 --- /dev/null +++ b/application/libraries/Cabrilloformat.php @@ -0,0 +1,142 @@ +COL_FREQ, 0, -3); + if ($freq > 30000) { + if ($freq > 250000000) { + $freq = "LIGHT"; + } + if ($freq >= 241000000 && $freq <= 250000000 ) { + $freq = "241G"; + } + if ($freq >= 134000000 && $freq <= 141000000 ) { + $freq = "134G"; + } + if ($freq >= 122250000 && $freq <= 123000000 ) { + $freq = "122G"; + } + if ($freq >= 75500000 && $freq <= 81500000 ) { + $freq = "75G"; + } + if ($freq >= 47000000 && $freq <= 47200000 ) { + $freq = "47G"; + } + if ($freq >= 24000000 && $freq <= 24250000 ) { + $freq = "24G"; + } + if ($freq >= 10000000 && $freq <= 10500000 ) { + $freq = "10G"; + } + if ($freq >= 5650000 && $freq <= 5850000 ) { + $freq = "5.7G"; + } + if ($freq >= 3400000 && $freq <= 3475000 ) { + $freq = "3.4G"; + } + if ($freq >= 2320000 && $freq <= 2450000 ) { + $freq = "2.4G"; + } + if ($freq >= 1240000 && $freq <= 1300000 ) { + $freq = "1.2G"; + } + if ($freq >= 902000 && $freq <= 928000 ) { + $freq = "902"; + } + if ($freq >= 430000 && $freq <= 440000 ) { + $freq = "432"; + } + if ($freq >= 222000 && $freq <= 225000 ) { + $freq = "222"; + } + if ($freq >= 144000 && $freq <= 146000 ) { + $freq = "144"; + } + if ($freq >= 70150 && $freq <= 70210 ) { + $freq = "70"; + } + if ($freq >= 50000 && $freq <= 52000 ) { + $freq = "50"; + } + } + + if($qso->COL_MODE == "SSB") { + $mode = "PH"; + } elseif($qso->COL_MODE == "RTTY") { + $mode = "RY"; + } else { + $mode = $qso->COL_MODE; + } + + $time = substr($qso->COL_TIME_ON, 0, -3); + + $time = str_replace(":","",$time); + + if ($qso->COL_STX_STRING != "") { + + if($qso->COL_SRX_STRING != "") { + $rx_string = $qso->COL_SRX_STRING; + } else { + $rx_string = "--"; + } + + return "QSO: ".sprintf("%6s", $freq)." ".$mode." ".$time." ".sprintf("%-13s", $qso->station_callsign)." ".sprintf("%3s", $qso->COL_RST_SENT)." ".sprintf("%-6s", sprintf("%03d", $qso->COL_STX))." ".$qso->COL_STX_STRING . " " .sprintf("%-13s", $qso->COL_CALL)." ".sprintf("%3s", $qso->COL_RST_RCVD)." ".sprintf("%-6s", sprintf("%03d", $qso->COL_SRX))." " . $rx_string . " 0\n"; + } else { + + return "QSO: ".sprintf("%6s", $freq)." ".$mode." ".$time." ".sprintf("%-13s", $qso->station_callsign)." ".sprintf("%3s", $qso->COL_RST_SENT)." ".sprintf("%-6s", sprintf("%03d", $qso->COL_STX))." ".sprintf("%-13s", $qso->COL_CALL)." ".sprintf("%3s", $qso->COL_RST_RCVD)." ".sprintf("%-6s", sprintf("%03d", $qso->COL_SRX))." 0\n"; + } + + } +} diff --git a/application/models/Contesting_model.php b/application/models/Contesting_model.php index b668b564..7bd89215 100644 --- a/application/models/Contesting_model.php +++ b/application/models/Contesting_model.php @@ -235,4 +235,87 @@ class Contesting_model extends CI_Model { } return; } + + function export_custom($from, $to, $contest_id, $station_id) { + $this->db->select(''.$this->config->item('table_name').'.*, station_profile.*'); + $this->db->from($this->config->item('table_name')); + $this->db->where($this->config->item('table_name').'.station_id', $station_id); + + // If date is set, we format the date and add it to the where-statement + if ($from != 0) { + $from = DateTime::createFromFormat('Y-m-d', $from); + $from = $from->format('Y-m-d'); + $this->db->where("date(".$this->config->item('table_name').".COL_TIME_ON) >= '".$from."'"); + } + if ($to != 0) { + $to = DateTime::createFromFormat('Y-m-d', $to); + $to = $to->format('Y-m-d'); + $this->db->where("date(".$this->config->item('table_name').".COL_TIME_ON) <= '".$to."'"); + } + + $this->db->where($this->config->item('table_name').'.COL_CONTEST_ID', $contest_id); + + $this->db->order_by($this->config->item('table_name').".COL_TIME_ON", "ASC"); + + $this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id'); + + return $this->db->get(); + } + + function get_logged_contests2() { + $CI =& get_instance(); + $CI->load->model('Stations'); + $station_id = $CI->Stations->find_active(); + + $sql = "select col_contest_id, min(date(col_time_on)) mindate, max(date(col_time_on)) maxdate, year(col_time_on) year, month(col_time_on) month + from " . $this->config->item('table_name') . " + where coalesce(COL_CONTEST_ID, '') <> '' + and station_id =" . $station_id; + + $sql .= " group by COL_CONTEST_ID , year(col_time_on), month(col_time_on) order by year(col_time_on) desc"; + + $data = $this->db->query($sql); + + return ($data->result()); + } + + function get_logged_years($station_id) { + + $sql = "select distinct year(col_time_on) year + from " . $this->config->item('table_name') . " + where coalesce(COL_CONTEST_ID, '') <> '' + and station_id =" . $station_id; + + $sql .= " order by year(col_time_on) desc"; + + $data = $this->db->query($sql); + + return $data->result(); + } + + function get_logged_contests($station_id, $year) { + $sql = "select distinct col_contest_id + from " . $this->config->item('table_name') . " + where coalesce(COL_CONTEST_ID, '') <> '' + and station_id =" . $station_id . + " and year(col_time_on) ='" . $year . "'"; + + $sql .= " order by COL_CONTEST_ID asc"; + + $data = $this->db->query($sql); + + return $data->result(); + } + + function get_contest_dates($station_id, $year, $contestid) { + $sql = "select distinct (date(col_time_on)) date + from " . $this->config->item('table_name') . " + where coalesce(COL_CONTEST_ID, '') <> '' + and station_id =" . $station_id . + " and year(col_time_on) ='" . $year . "' and col_contest_id ='" . $contestid . "'"; + + $data = $this->db->query($sql); + + return $data->result(); + } } diff --git a/application/views/cabrillo/export.php b/application/views/cabrillo/export.php new file mode 100644 index 00000000..5b189564 --- /dev/null +++ b/application/views/cabrillo/export.php @@ -0,0 +1,14 @@ +load->library('Cabrilloformat'); + +echo $CI->cabrilloformat->header($contest_id, $callsign, $claimed_score, + $operators, $club, $name, $address, $addresscity, $addressstateprovince, $addresspostalcode, $addresscountry, $soapbox, $gridlocator, + $categoryoverlay, $categorytransmitter, $categorystation, $categorypower, $categorymode, $categoryband, $categoryassisted, $categoryoperator, $email); +foreach ($qsos->result() as $row) { + echo $CI->cabrilloformat->qso($row); +} +echo $CI->cabrilloformat->footer(); \ No newline at end of file diff --git a/application/views/cabrillo/index.php b/application/views/cabrillo/index.php new file mode 100644 index 00000000..38824bc7 --- /dev/null +++ b/application/views/cabrillo/index.php @@ -0,0 +1,185 @@ +
+ +
+ +

+ +
+
+ Export a contest to a Cabrillo log +
+
+ + '; + + + if ($station_profile) { ?> + +
+
+
Select Station Location:
+ + +
+ +
+
+
+
+
+
+ + + + + + + + + + + + + + + + + +
+ + + +
+
+
\ No newline at end of file diff --git a/application/views/interface_assets/header.php b/application/views/interface_assets/header.php index 61168f31..71fb725a 100644 --- a/application/views/interface_assets/header.php +++ b/application/views/interface_assets/header.php @@ -230,6 +230,8 @@ SOTA CSV Export + Cabrillo Export + 0) { + $(".contestyear").append('
Select year:
' + + '' + + ' '); + + $.each(data, function(key, value) { + $('#year') + .append($("") + .attr("value",value.year) + .text(value.year)); + }); + } else { + $(".contestyear").append("No contests were found for this station location!"); + } + } + }); +} + +function loadContests() { + $(".contestname").empty(); + $(".contestdates").empty(); + $.ajax({ + url: base_url+'index.php/cabrillo/getContests', + type: 'post', + data: {'year': $("#year").val(), + 'station_id': $("#station_id").val() + }, + success: function (data) { + $(".contestname").append('
Select contest:
' + + '' + + ' '); + + $.each(data, function(key, value) { + $('#contestid') + .append($("") + .attr("value",value.col_contest_id) + .text(value.col_contest_id)); + }); + } + }); +} + +function loadContestDates() { + $(".contestdates").empty(); + $.ajax({ + url: base_url+'index.php/cabrillo/getContestDates', + type: 'post', + data: {'year': $("#year").val(), + 'contestid': $("#contestid").val(), + 'station_id': $("#station_id").val()}, + success: function (data) { + $(".contestdates").append('
Select date range:
' + + '' + + '' + + ' '); + + $.each(data, function(key, value) { + $('#contestdatesfrom') + .append($("") + .attr("value", value.date) + .text(value.date)); + }); + + + $.each(data, function(key, value) { + $('#contestdatesto') + .append($("") + .attr("value", value.date) + .text(value.date)); + }); + } + }); +} + +function addAdditionalInfo() { + $(".additionalinfo").removeAttr("hidden"); +} \ No newline at end of file