diff --git a/application/config/migration.php b/application/config/migration.php index 49ca7587..7fbf6167 100644 --- a/application/config/migration.php +++ b/application/config/migration.php @@ -21,7 +21,7 @@ $config['migration_enabled'] = TRUE; | be upgraded / downgraded to. | */ -$config['migration_version'] = 63; +$config['migration_version'] = 64; /* |-------------------------------------------------------------------------- diff --git a/application/controllers/Qso.php b/application/controllers/Qso.php index 9bf03a7a..9beb2d50 100755 --- a/application/controllers/Qso.php +++ b/application/controllers/Qso.php @@ -13,21 +13,21 @@ class QSO extends CI_Controller { { parent::__construct(); $this->lang->load('qso'); - + $this->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() { - + $this->load->model('cat'); $this->load->model('stations'); $this->load->model('logbook_model'); $this->load->model('user_model'); $this->load->model('modes'); if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); } - + $data['active_station_profile'] = $this->stations->find_active(); $data['notice'] = false; $data['stations'] = $this->stations->all(); @@ -36,7 +36,7 @@ class QSO extends CI_Controller { $data['dxcc'] = $this->logbook_model->fetchDxcc(); $data['iota'] = $this->logbook_model->fetchIota(); $data['modes'] = $this->modes->active(); - + $this->load->library('form_validation'); @@ -58,7 +58,7 @@ class QSO extends CI_Controller { // $this->logbook_model->add(); //change to create_qso function as add and create_qso duplicate functionality $this->logbook_model->create_qso(); - + // Store Basic QSO Info for reuse // Put data in an array first, then call set_userdata once. // This solves the problem of CI dumping out the session @@ -83,7 +83,7 @@ class QSO extends CI_Controller { 'transmit_power' => $this->input->post('transmit_power') ); // ]; - + setcookie("radio", $qso_data['radio'], time()+3600*24*99); setcookie("station_profile_id", $qso_data['station_profile_id'], time()+3600*24*99); @@ -93,13 +93,13 @@ class QSO extends CI_Controller { if($this->input->post('sat_name')) { $this->session->set_userdata('prop_mode', 'SAT'); } - + // Get last 5 qsos $data['query'] = $this->logbook_model->last_custom('5'); - + // Set Any Notice Messages $data['notice'] = "QSO Added"; - + // Load view to create another contact $data['page_title'] = "Add QSO"; @@ -116,15 +116,15 @@ class QSO extends CI_Controller { $this->load->model('logbook_model'); $this->logbook_model->create_qso(); } - + function edit() { - + $this->load->model('logbook_model'); $this->load->model('user_model'); $this->load->model('modes'); if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); } $query = $this->logbook_model->qso_info($this->uri->segment(3)); - + $this->load->library('form_validation'); $this->form_validation->set_rules('time_on', 'Start Date', 'required'); @@ -135,7 +135,7 @@ class QSO extends CI_Controller { $data['dxcc'] = $this->logbook_model->fetchDxcc(); $data['iota'] = $this->logbook_model->fetchIota(); $data['modes'] = $this->modes->all(); - + if ($this->form_validation->run() == FALSE) { $this->load->view('qso/edit', $data); @@ -180,7 +180,7 @@ class QSO extends CI_Controller { $this->logbook_model->edit(); } - + function qsl_rcvd($id, $method) { $this->load->model('logbook_model'); $this->load->model('user_model'); @@ -215,13 +215,13 @@ class QSO extends CI_Controller { echo json_encode(array('message' => 'OK')); } } - + /* Delete QSO */ function delete($id) { $this->load->model('logbook_model'); - + $this->logbook_model->delete($id); - + $this->session->set_flashdata('notice', 'QSO Deleted Successfully'); $data['message_title'] = "Deleted"; $data['message_contents'] = "QSO Deleted Successfully"; @@ -245,12 +245,12 @@ class QSO extends CI_Controller { echo json_encode(array('message' => 'OK')); return; } - - + + function band_to_freq($band, $mode) { - + $this->load->library('frequency'); - + echo $this->frequency->convent_band($band, $mode); } @@ -352,4 +352,29 @@ class QSO extends CI_Controller { header('Content-Type: application/json'); echo json_encode($json); } + + public function get_sota_info() { + $sota = xss_clean($this->input->post('sota')); + $url = 'https://api2.sota.org.uk/api/summits/' . $sota; + + // Let's use cURL instead of file_get_contents + // begin script + $ch = curl_init(); + + // basic curl options for all requests + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_HEADER, 0); + + // use the URL we built + curl_setopt($ch, CURLOPT_URL, $url); + + $input = curl_exec($ch); + $chi = curl_getinfo($ch); + + // Close cURL handle + curl_close($ch); + + header('Content-Type: application/json'); + echo $input; + } } diff --git a/application/controllers/User.php b/application/controllers/User.php index 13a4a883..cc4e68c7 100644 --- a/application/controllers/User.php +++ b/application/controllers/User.php @@ -20,7 +20,7 @@ class User extends CI_Controller { function add() { $this->load->model('user_model'); if(!$this->user_model->authorize(99)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); } - + $this->load->library('form_validation'); $this->form_validation->set_rules('user_name', 'Username', 'required'); @@ -55,6 +55,7 @@ class User extends CI_Controller { $data['user_timezone'] = $this->input->post('user_timezone'); $data['user_measurement_base'] = $this->input->post('user_measurement_base'); $data['user_stylesheet'] = $this->input->post('user_stylesheet'); + $data['user_sota_lookup'] = $this->input->post('user_sota_lookup'); $this->load->view('user/add', $data); } else { $this->load->view('user/add', $data); @@ -63,7 +64,7 @@ class User extends CI_Controller { } else { - switch($this->user_model->add($this->input->post('user_name'), $this->input->post('user_password'), $this->input->post('user_email'), $this->input->post('user_type'), $this->input->post('user_firstname'), $this->input->post('user_lastname'), $this->input->post('user_callsign'), $this->input->post('user_locator'), $this->input->post('user_timezone'), $this->input->post('user_measurement_base'), $this->input->post('user_date_format'), $this->input->post('user_stylesheet'))) { + switch($this->user_model->add($this->input->post('user_name'), $this->input->post('user_password'), $this->input->post('user_email'), $this->input->post('user_type'), $this->input->post('user_firstname'), $this->input->post('user_lastname'), $this->input->post('user_callsign'), $this->input->post('user_locator'), $this->input->post('user_timezone'), $this->input->post('user_measurement_base'), $this->input->post('user_date_format'), $this->input->post('user_stylesheet'), $this->input->post('user_sota_lookup'))) { // Check for errors case EUSERNAMEEXISTS: $data['username_error'] = 'Username '.$this->input->post('user_name').' already in use!'; @@ -93,6 +94,7 @@ class User extends CI_Controller { $data['user_locator'] = $this->input->post('user_locator'); $data['user_measurement_base'] = $this->input->post('user_measurement_base'); $data['user_stylesheet'] = $this->input->post('user_stylesheet'); + $data['user_sota_lookup'] = $this->input->post('user_sota_lookup'); $this->load->view('user/add', $data); $this->load->view('interface_assets/footer'); } @@ -102,7 +104,7 @@ class User extends CI_Controller { $this->load->model('user_model'); if((!$this->user_model->authorize(99)) && ($this->session->userdata('user_id') != $this->uri->segment(3))) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); } $query = $this->user_model->get_by_id($this->uri->segment(3)); - + $this->load->library('form_validation'); $this->form_validation->set_rules('user_name', 'Username', 'required|xss_clean'); @@ -206,7 +208,7 @@ class User extends CI_Controller { } else { $data['user_clublog_name'] = $q->user_clublog_name; } - + if($this->input->post('user_clublog_password')) { $data['user_clublog_password'] = $this->input->post('user_clublog_password', true); } else { @@ -218,13 +220,13 @@ class User extends CI_Controller { } else { $data['user_lotw_password'] = $q->user_lotw_password; } - + if($this->input->post('user_eqsl_name')) { $data['user_eqsl_name'] = $this->input->post('user_eqsl_name', true); } else { $data['user_eqsl_name'] = $q->user_eqsl_name; } - + if($this->input->post('user_eqsl_password')) { $data['user_eqsl_password'] = $this->input->post('user_eqsl_password', true); } else { @@ -248,7 +250,13 @@ class User extends CI_Controller { } else { $data['user_stylesheet'] = $q->user_stylesheet; } - + + if($this->input->post('user_sota_lookup')) { + $data['user_sota_lookup'] = $this->input->post('user_sota_lookup', true); + } else { + $data['user_sota_lookup'] = $q->user_sota_lookup; + } + $this->load->view('user/edit', $data); $this->load->view('interface_assets/footer'); } @@ -290,6 +298,7 @@ class User extends CI_Controller { $data['user_locator'] = $this->input->post('user_locator', true); $data['user_timezone'] = $this->input->post('user_timezone', true); $data['user_stylesheet'] = $this->input->post('user_stylesheet'); + $data['user_sota_lookup'] = $this->input->post('user_sota_lookup'); $this->load->view('user/edit'); $this->load->view('interface_assets/footer'); } @@ -347,8 +356,8 @@ class User extends CI_Controller { function login() { // Check our version and run any migrations $this->load->library('Migration'); - $this->migration->current(); - + $this->migration->current(); + $this->load->model('user_model'); $query = $this->user_model->get($this->input->post('user_name', true)); diff --git a/application/migrations/064_add_user_sota_lookup.php b/application/migrations/064_add_user_sota_lookup.php new file mode 100644 index 00000000..5a050e22 --- /dev/null +++ b/application/migrations/064_add_user_sota_lookup.php @@ -0,0 +1,25 @@ +dbforge->add_column('users', $fields); + } + + public function down() + { + $this->dbforge->drop_column('users', 'user_sota_lookup'); + } +} diff --git a/application/models/User_model.php b/application/models/User_model.php index cb77e588..f27e2f4f 100644 --- a/application/models/User_model.php +++ b/application/models/User_model.php @@ -5,7 +5,7 @@ * This model implements user authentication and authorization * */ - + // Uses 'phpass' from http://www.openwall.com/phpass/ to implement password hashing // TODO migration away from this? @@ -28,7 +28,7 @@ class User_Model extends CI_Model { $this->db->where('user_name', $clean_username); $r = $this->db->get($this->config->item('auth_table')); return $r; - } + } // FUNCTION: object get_by_id($id) // Retrieve a user by user ID @@ -96,7 +96,7 @@ class User_Model extends CI_Model { // FUNCTION: bool add($username, $password, $email, $type) // Add a user - function add($username, $password, $email, $type, $firstname, $lastname, $callsign, $locator, $timezone, $measurement, $user_date_format, $user_stylesheet) { + function add($username, $password, $email, $type, $firstname, $lastname, $callsign, $locator, $timezone, $measurement, $user_date_format, $user_stylesheet, $user_sota_lookup) { // Check that the user isn't already used if(!$this->exists($username)) { $data = array( @@ -112,6 +112,7 @@ class User_Model extends CI_Model { 'user_measurement_base' => xss_clean($measurement), 'user_date_format' => xss_clean($user_date_format), 'user_stylesheet' => xss_clean($user_stylesheet), + 'user_sota_lookup' => xss_clean($user_sota_lookup), ); // Check the password is valid @@ -153,13 +154,14 @@ class User_Model extends CI_Model { 'user_measurement_base' => xss_clean($fields['user_measurement_base']), 'user_date_format' => xss_clean($fields['user_date_format']), 'user_stylesheet' => xss_clean($fields['user_stylesheet']), + 'user_sota_lookup' => xss_clean($fields['user_sota_lookup']), ); - + // Check to see if the user is allowed to change user levels if($this->session->userdata('user_type') == 99) { $data['user_type'] = $fields['user_type']; } - + // Check to see if username is used already if($this->exists($fields['user_name']) && $this->get($fields['user_name'])->row()->user_id != $fields['id']) { return EUSERNAMEEXISTS; @@ -168,7 +170,7 @@ class User_Model extends CI_Model { if($this->exists_by_email($fields['user_email']) && $this->get_by_email($fields['user_email'])->row()->user_id != $fields['id']) { return EEMAILEXISTS; } - + // Hash password if($fields['user_password'] != NULL) { @@ -187,12 +189,12 @@ class User_Model extends CI_Model { { $data['user_clublog_password'] = $fields['user_clublog_password']; } - + if($fields['user_eqsl_password'] != NULL) { $data['user_eqsl_password'] = $fields['user_eqsl_password']; } - + // Update the user $this->db->where('user_id', $fields['id']); $this->db->update($this->config->item('auth_table'), $data); @@ -202,7 +204,7 @@ class User_Model extends CI_Model { } } else { return EFORBIDDEN; - } + } } // FUNCTION: bool delete() @@ -234,15 +236,15 @@ class User_Model extends CI_Model { // Nothing is returned - it can be assumed that if this is called, the user's // login session *will* be cleared, no matter what state it is in function clear_session() { - + $this->session->sess_destroy(); } - + // FUNCTION: void update_session() // Updates a user's login session after they've logged in // TODO: This should return bool TRUE/FALSE or 0/1 function update_session($id) { - + $u = $this->get_by_id($id); $userdata = array( @@ -260,6 +262,7 @@ class User_Model extends CI_Model { 'user_measurement_base' => $u->row()->user_measurement_base, 'user_date_format' => $u->row()->user_date_format, 'user_stylesheet' => $u->row()->user_stylesheet, + 'user_sota_lookup' => $u->row()->user_sota_lookup, ); $this->session->set_userdata($userdata); @@ -362,7 +365,7 @@ class User_Model extends CI_Model { // Will return '0' in the event of problems with the // hashing function private function _hash($password) { - $hash = password_hash($password, PASSWORD_DEFAULT); + $hash = password_hash($password, PASSWORD_DEFAULT); if(strlen($hash) < 20) { return EPASSWORDINVALID; @@ -370,7 +373,7 @@ class User_Model extends CI_Model { return $hash; } } - + } ?> diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index b075c5dc..ba6f6817 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -319,201 +319,7 @@ $(document).on('keypress',function(e) { uri->segment(1) == "qso") { ?> - + - diff --git a/application/views/user/add.php b/application/views/user/add.php index a90f2714..428e6660 100644 --- a/application/views/user/add.php +++ b/application/views/user/add.php @@ -28,7 +28,7 @@
".$callsign_error."
"; } ?> - +
@@ -75,9 +75,9 @@
-
@@ -92,7 +92,7 @@ - + Select how you would like dates shown when logged into your account.
@@ -120,6 +120,15 @@ +
+ + +
If this is set, name and gridsquare is fetched from the API and filled in location and locator.
+
+ diff --git a/application/views/user/edit.php b/application/views/user/edit.php index 3d651d7d..4b325c78 100644 --- a/application/views/user/edit.php +++ b/application/views/user/edit.php @@ -26,7 +26,7 @@ load->helper('form'); ?> - +
uri->segment(3); ?>" name="users" autocomplete="off">
@@ -66,7 +66,7 @@
- + session->userdata('user_type') == 99) { ?> - config->item('auth_level'); echo $l[$user_type]; }?> @@ -234,9 +234,9 @@ ".$eqslpassword_error."
"; } else { ?>
Leave blank to keep existing password
-
+
- + @@ -267,7 +267,31 @@ + +
+
+ +
+
+
+ Summits On The Air +
+
+
+ + +
If this is set, name and gridsquare is fetched from the API and filled in location and locator.
+
+ +
+
+
+ +

diff --git a/assets/js/sections/qso.js b/assets/js/sections/qso.js new file mode 100644 index 00000000..891214db --- /dev/null +++ b/assets/js/sections/qso.js @@ -0,0 +1,611 @@ +$( document ).ready(function() { + + $('#input_usa_state').change(function(){ + var state = $("#input_usa_state option:selected").text(); + if (state != "") { + $("#stationCntyInput").prop('disabled', false); + + $('#stationCntyInput').selectize({ + maxItems: 1, + closeAfterSelect: true, + loadThrottle: 250, + valueField: 'name', + labelField: 'name', + searchField: 'name', + options: [], + create: false, + load: function(query, callback) { + var state = $("#input_usa_state option:selected").text(); + + if (!query || state == "") return callback(); + $.ajax({ + url: base_url+'index.php/qso/get_county', + type: 'GET', + dataType: 'json', + data: { + query: query, + state: state, + }, + error: function() { + callback(); + }, + success: function(res) { + callback(res); + } + }); + } + }); + + } else { + $("#stationCntyInput").prop('disabled', true); + //$('#stationCntyInput')[0].selectize.destroy(); + $("#stationCntyInput").val(""); + } + }); + + $('#sota_ref').selectize({ + maxItems: 1, + closeAfterSelect: true, + loadThrottle: 250, + valueField: 'name', + labelField: 'name', + searchField: 'name', + options: [], + create: false, + load: function(query, callback) { + if (!query || query.length < 3) return callback(); // Only trigger if 3 or more characters are entered + $.ajax({ + url: base_url+'index.php/qso/get_sota', + type: 'GET', + dataType: 'json', + data: { + query: query, + }, + error: function() { + callback(); + }, + success: function(res) { + callback(res); + } + }); + } + }); + + $('#darc_dok').selectize({ + maxItems: 1, + closeAfterSelect: true, + loadThrottle: 250, + valueField: 'name', + labelField: 'name', + searchField: 'name', + options: [], + create: false, + load: function(query, callback) { + if (!query) return callback(); // Only trigger if at least 1 character is entered + $.ajax({ + url: base_url+'index.php/qso/get_dok', + type: 'GET', + dataType: 'json', + data: { + query: query, + }, + error: function() { + callback(); + }, + success: function(res) { + callback(res); + } + }); + } + }); + + /* + Populate the Satellite Names Field on the QSO Panel + */ + $.getJSON(base_url+"assets/json/satellite_data.json", function( data ) { + + // Build the options array + var items = []; + $.each( data, function( key, val ) { + items.push( + '' + ); + }); + + // Add to the datalist + $('.satellite_names_list').append(items.join( "" )); + }); + +}); + +var selected_sat; +var selected_sat_mode; + +$(document).on('change', 'input', function(){ + var optionslist = $('.satellite_modes_list')[0].options; + var value = $(this).val(); + for (var x=0;x' + key1 + ''); + }); + } + }); + + // Add to the datalist + $('.satellite_modes_list').append(sat_modes.join( "" )); + + }); + } + } +}); + +function changebadge(entityname) { + if($("#sat_name" ).val() != "") { + $.getJSON('logbook/jsonlookupdxcc/' + convert_case(entityname) + '/SAT/0/0', function(result) + { + + $('#callsign_info').removeClass("badge-secondary"); + $('#callsign_info').removeClass("badge-success"); + $('#callsign_info').removeClass("badge-danger"); + $('#callsign_info').attr('title', ''); + + if (result.workedBefore) + { + $('#callsign_info').addClass("badge-success"); + $('#callsign_info').attr('title', 'DXCC was already worked in the past on this band and mode!'); + } + else + { + $('#callsign_info').addClass("badge-danger"); + $('#callsign_info').attr('title', 'New DXCC, not worked on this band and mode!'); + } + }) + } else { + $.getJSON('logbook/jsonlookupdxcc/' + convert_case(entityname) + '/0/' + $("#band").val() +'/' + $("#mode").val(), function(result) + { + // Reset CSS values before updating + $('#callsign_info').removeClass("badge-secondary"); + $('#callsign_info').removeClass("badge-success"); + $('#callsign_info').removeClass("badge-danger"); + $('#callsign_info').attr('title', ''); + + if (result.workedBefore) + { + $('#callsign_info').addClass("badge-success"); + $('#callsign_info').attr('title', 'DXCC was already worked in the past on this band and mode!'); + } + else + { + $('#callsign_info').addClass("badge-danger"); + $('#callsign_info').attr('title', 'New DXCC, not worked on this band and mode!'); + } + }) + } +} + +/* Function: reset_fields is used to reset the fields on the QSO page */ +function reset_fields() { + + $('#locator_info').text(""); + $('#country').val(""); + $('#lotw_info').text(""); + $('#dxcc_id').val(""); + $('#cqz').val(""); + $('#name').val(""); + $('#qth').val(""); + $('#locator').val(""); + $('#iota_ref').val(""); + $("#locator").removeClass("workedGrid"); + $("#locator").removeClass("newGrid"); + $("#callsign").removeClass("workedGrid"); + $("#callsign").removeClass("newGrid"); + $('#callsign_info').removeClass("badge-secondary"); + $('#callsign_info').removeClass("badge-success"); + $('#callsign_info').removeClass("badge-danger"); + $('#qsl_via').val(""); + $('#callsign_info').text(""); + $('#input_usa_state').val(""); + $('#qso-last-table').show(); + $('#partial_view').hide(); + + mymap.setView([51.505, -0.09], 13); + mymap.removeLayer(markers); + $('.callsign-suggest').hide(); +} + +$("#callsign").focusout(function() { + + if ($(this).val().length >= 3) { + /* Find and populate DXCC */ + $('.callsign-suggest').hide(); + + if($("#sat_name").val() != ""){ + var sat_type = "SAT"; + var json_band = "0"; + var json_mode = "0"; + } else { + var sat_type = "0"; + var json_band = $("#band").val(); + var json_mode = $("#mode").val(); + } + + var find_callsign = $(this).val().toUpperCase(); + + find_callsign.replace(/\//g, "-"); + + // Replace / in a callsign with - to stop urls breaking + $.getJSON('logbook/json/' + find_callsign.replace(/\//g, "-") + '/' + sat_type + '/' + json_band + '/' + json_mode, function(result) + { + //$('#country').val(result); lotw_info + if(result.dxcc.entity != undefined) { + $('#country').val(convert_case(result.dxcc.entity)); + $('#callsign_info').text(convert_case(result.dxcc.entity)); + + if($("#sat_name" ).val() != "") { + //logbook/jsonlookupgrid/io77/SAT/0/0 + $.getJSON('logbook/jsonlookupcallsign/' + find_callsign.replace(/\//g, "-") + '/SAT/0/0', function(result) + { + // Reset CSS values before updating + $('#callsign').removeClass("workedGrid"); + $('#callsign').removeClass("newGrid"); + $('#callsign').attr('title', ''); + + if (result.workedBefore) + { + $('#callsign').addClass("workedGrid"); + $('#callsign').attr('title', 'Callsign was already worked in the past on this band and mode!'); + } + else + { + $('#callsign').addClass("newGrid"); + $('#callsign').attr('title', 'New Callsign!'); + } + }) + } else { + $.getJSON('logbook/jsonlookupcallsign/' + find_callsign.replace(/\//g, "-") + '/0/' + $("#band").val() +'/' + $("#mode").val(), function(result) + { + // Reset CSS values before updating + $('#callsign').removeClass("workedGrid"); + $('#callsign').removeClass("newGrid"); + $('#callsign').attr('title', ''); + + if (result.workedBefore) + { + $('#callsign').addClass("workedGrid"); + $('#callsign').attr('title', 'Callsign was already worked in the past on this band and mode!'); + } + else + { + $('#callsign').addClass("newGrid"); + $('#callsign').attr('title', 'New Callsign!'); + } + }) + } + + changebadge(result.dxcc.entity); + } + + if(result.lotw_member == "active") { + $('#lotw_info').text("LoTW"); + } + + $('#dxcc_id').val(result.dxcc.adif); + $('#cqz').val(result.dxcc.cqz); + $('#ituz').val(result.dxcc.ituz); + + + var redIcon = L.icon({ + iconUrl: icon_dot_url, + iconSize: [18, 18], // size of the icon + }); + + // Set Map to Lat/Long + markers.clearLayers(); + mymap.setZoom(8); + if (typeof result.latlng !== "undefined" && result.latlng !== false) { + var marker = L.marker([result.latlng[0], result.latlng[1]], {icon: redIcon}); + mymap.panTo([result.latlng[0], result.latlng[1]]); + } else { + var marker = L.marker([result.dxcc.lat, result.dxcc.long], {icon: redIcon}); + mymap.panTo([result.dxcc.lat, result.dxcc.long]); + } + + markers.addLayer(marker).addTo(mymap); + + + /* Find Locator if the field is empty */ + if($('#locator').val() == "") { + $('#locator').val(result.callsign_qra); + $('#locator_info').html(result.bearing); + + if (result.callsign_qra != "") + { + if (result.workedBefore) + { + $('#locator').addClass("workedGrid"); + $('#locator').attr('title', 'Grid was already worked in the past'); + } + else + { + $('#locator').addClass("newGrid"); + $('#locator').attr('title', 'New grid!'); + } + } + else + { + $('#locator').removeClass("workedGrid"); + $('#locator').removeClass("newGrid"); + $('#locator').attr('title', ''); + } + + } + + /* Find Operators Name */ + if($('#qsl_via').val() == "") { + $('#qsl_via').val(result.qsl_manager); + } + + /* Find Operators Name */ + if($('#name').val() == "") { + $('#name').val(result.callsign_name); + } + + if($('#qth').val() == "") { + $('#qth').val(result.callsign_qth); + } + + /* + * Update state with returned value + */ + if($("#input_usa_state").val() == "") { + $("#input_usa_state").val(result.callsign_state).trigger('change'); + } + + + if($('#iota_ref').val() == "") { + $('#iota_ref').val(result.callsign_iota); + } + // Hide the last QSO table + $('#qso-last-table').hide(); + $('#partial_view').show(); + /* display past QSOs */ + $('#partial_view').html(result.partial); + }); + } else { + /* Reset fields ... */ + $('#callsign_info').text(""); + $('#locator_info').text(""); + $('#country').val(""); + $('#dxcc_id').val(""); + $('#cqz').val(""); + $('#name').val(""); + $('#qth').val(""); + $('#locator').val(""); + $('#iota_ref').val(""); + $("#locator").removeClass("workedGrid"); + $("#locator").removeClass("newGrid"); + $("#callsign").removeClass("workedGrid"); + $("#callsign").removeClass("newGrid"); + $('#callsign_info').removeClass("badge-secondary"); + $('#callsign_info').removeClass("badge-success"); + $('#callsign_info').removeClass("badge-danger"); + $('#input_usa_state').val(""); + } +}) + +// Only set the frequency when not set by userdata/PHP. +if ($('#frequency').val() == "") +{ + $.get('qso/band_to_freq/' + $('#band').val() + '/' + $('.mode').val(), function(result) { + $('#frequency').val(result); + $('#frequency_rx').val(""); + }); +} + +/* on mode change */ +$('.mode').change(function() { + $.get('qso/band_to_freq/' + $('#band').val() + '/' + $('.mode').val(), function(result) { + $('#frequency').val(result); + $('#frequency_rx').val(""); + }); +}); + +/* Calculate Frequency */ +/* on band change */ +$('#band').change(function() { + $.get('qso/band_to_freq/' + $(this).val() + '/' + $('.mode').val(), function(result) { + $('#frequency').val(result); + $('#frequency_rx').val(""); + }); +}); + +/* On Key up Calculate Bearing and Distance */ +$("#locator").keyup(function(){ + if ($(this).val()) { + var qra_input = $(this).val(); + + var qra_lookup = qra_input.substring(0, 4); + + if(qra_lookup.length >= 4) { + + // Check Log if satname is provided + if($("#sat_name" ).val() != "") { + + //logbook/jsonlookupgrid/io77/SAT/0/0 + + $.getJSON('logbook/jsonlookupgrid/' + qra_lookup.toUpperCase() + '/SAT/0/0', function(result) + { + // Reset CSS values before updating + $('#locator').removeClass("workedGrid"); + $('#locator').removeClass("newGrid"); + $('#locator').attr('title', ''); + + if (result.workedBefore) + { + $('#locator').addClass("workedGrid"); + $('#locator').attr('title', 'Grid was already worked in the past'); + } + else + { + $('#locator').addClass("newGrid"); + $('#locator').attr('title', 'New grid!'); + } + }) + } else { + $.getJSON('logbook/jsonlookupgrid/' + qra_lookup.toUpperCase() + '/0/' + $("#band").val() +'/' + $("#mode").val(), function(result) + { + // Reset CSS values before updating + $('#locator').removeClass("workedGrid"); + $('#locator').removeClass("newGrid"); + $('#locator').attr('title', ''); + + if (result.workedBefore) + { + $('#locator').addClass("workedGrid"); + $('#locator').attr('title', 'Grid was already worked in the past'); + } + else + { + $('#locator').addClass("newGrid"); + $('#locator').attr('title', 'New grid!'); + } + }) + } + } + + if(qra_input.length >= 4 && $(this).val().length > 0) { + $.getJSON('logbook/qralatlngjson/' + $(this).val(), function(result) + { + // Set Map to Lat/Long + markers.clearLayers(); + if (typeof result !== "undefined") { + var redIcon = L.icon({ + iconUrl: icon_dot_url, + iconSize: [18, 18], // size of the icon + }); + + var marker = L.marker([result[0], result[1]], {icon: redIcon}); + mymap.setZoom(8); + mymap.panTo([result[0], result[1]]); + } + markers.addLayer(marker).addTo(mymap); + }) + + $('#locator_info').load("logbook/searchbearing/" + $(this).val()).fadeIn("slow"); + } + } +}); + +// Change report based on mode +$('.mode').change(function(){ + setRst($('.mode') .val()); +}); + +function convert_case(str) { + var lower = str.toLowerCase(); + return lower.replace(/(^| )(\w)/g, function(x) { + return x.toUpperCase(); + }); +} + +$('#dxcc_id').on('change', function() { + $.getJSON('logbook/jsonentity/' + $(this).val(), function (result) { + if (result.dxcc.name != undefined) { + + $('#country').val(convert_case(result.dxcc.name)); + $('#cqz').val(convert_case(result.dxcc.cqz)); + + $('#callsign_info').removeClass("badge-secondary"); + $('#callsign_info').removeClass("badge-success"); + $('#callsign_info').removeClass("badge-danger"); + $('#callsign_info').attr('title', ''); + $('#callsign_info').text(convert_case(result.dxcc.name)); + + changebadge(result.dxcc.name); + + // Set Map to Lat/Long it locator is not empty + if($('#locator').val() == "") { + var redIcon = L.icon({ + iconUrl: icon_dot_url, + iconSize: [18, 18], // size of the icon + }); + + markers.clearLayers(); + var marker = L.marker([result.dxcc.lat, result.dxcc.long], {icon: redIcon}); + mymap.setZoom(8); + mymap.panTo([result.dxcc.lat, result.dxcc.long]); + markers.addLayer(marker).addTo(mymap); + } + } + }); +}); + +//Spacebar moves to the name field when you're entering a callsign +//Similar to contesting ux, good for pileups. +$("#callsign").on("keypress", function(e) { + if (e.which == 32){ + $("#name").focus(); + return false; //Eliminate space char + } +}); + +// On Key up check and suggest callsigns +$("#callsign").keyup(function() { + if ($(this).val().length >= 3) { + $('.callsign-suggest').show(); + $.get('lookup/scp/' + $(this).val().toUpperCase(), function(result) { + $('.callsign-suggestions').text(result); + }); + } +});