diff --git a/application/controllers/Adif.php b/application/controllers/Adif.php index e3386fe02..014275b87 100644 --- a/application/controllers/Adif.php +++ b/application/controllers/Adif.php @@ -355,6 +355,74 @@ class adif extends CI_Controller { $this->load->view('interface_assets/footer'); } } + + public function pota() { + $this->load->model('stations'); + $data['station_profile'] = $this->stations->all_of_user(); + + $data['page_title'] = __("POTA Import"); + $data['tab'] = "potab"; + + $config['upload_path'] = './uploads/'; + $config['allowed_types'] = 'adi|ADI|adif|ADIF'; + + $this->load->library('upload', $config); + + if ( ! $this->upload->do_upload()) { + $data['error'] = $this->upload->display_errors(); + + $data['max_upload'] = ini_get('upload_max_filesize'); + + $this->load->view('interface_assets/header', $data); + $this->load->view('adif/import', $data); + $this->load->view('interface_assets/footer'); + } else { + $data = array('upload_data' => $this->upload->data()); + + ini_set('memory_limit', '-1'); + set_time_limit(0); + + $this->load->model('logbook_model'); + + if (!$this->load->is_loaded('adif_parser')) { + $this->load->library('adif_parser'); + } + + $this->adif_parser->load_from_file('./uploads/'.$data['upload_data']['file_name']); + + $this->adif_parser->initialize(); + $error_count = array(0, 0, 0); + $custom_errors = ""; + while($record = $this->adif_parser->get_record()) + { + if(count($record) == 0) { + break; + }; + + $pota_result = $this->logbook_model->update_pota($record); + if (!empty($pota_result)) { + switch ($pota_result[0]) { + case 0: + $error_count[0]++; + break; + case 1: + $error_count[1]++; + break; + case 2: + $custom_errors .= $pota_result[1]; + $error_count[2]++; + } + } + }; + unlink('./uploads/'.$data['upload_data']['file_name']); + $data['pota_error_count'] = $error_count; + $data['pota_errors'] = $custom_errors; + $data['page_title'] = __("POTA Data Imported"); + $this->load->view('interface_assets/header', $data); + $this->load->view('adif/pota_success'); + $this->load->view('interface_assets/footer'); + } + } } /* End of file adif.php */ diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index 06d92d2e3..807b69894 100644 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -4840,6 +4840,55 @@ class Logbook_model extends CI_Model { } } + function update_pota($record) { + $this->load->model('logbooks_model'); + $custom_date_format = $this->session->userdata('user_date_format'); + $logbooks_locations_array = $this->logbooks_model->list_logbook_relationships($this->session->userdata('active_station_logbook')); + + if (isset($record['call'])) { + $call = strtoupper($record['call']); + } else { + return array(3, 'Callsign not found'); + } + + // Join date+time + $time_on = date('Y-m-d', strtotime($record['qso_date'])) . " " . date('H:i', strtotime($record['time_on'])); + + // Store Band + if (isset($record['band'])) { + $band = strtolower($record['band']); + } else { + $band = ''; + } + + if (isset($record['mode'])) { + $mode = $record['mode']; + } else { + $mode = ''; + } + + if (isset($record['pota_ref'])) { + $pota_ref = $record['pota_ref']; + } else { + $pota_ref = ''; + } + + if ($pota_ref != '') { + $sql = "SELECT COL_PRIMARY_KEY, COL_POTA_REF FROM ".$this->config->item('table_name')." WHERE COL_CALL = ? AND COL_TIME_ON >= DATE_ADD(DATE_FORMAT(?, '%Y-%m-%d %H:%i' ), INTERVAL -15 MINUTE) AND COL_TIME_ON <= DATE_ADD(DATE_FORMAT(?, '%Y-%m-%d %H:%i' ), INTERVAL +15 MINUTE) AND UPPER(COL_BAND) = ? AND UPPER(COL_MODE) = ? AND station_id IN ?;"; + $check = $this->db->query($sql, array($call, $time_on, $time_on, strtoupper($band), strtoupper($mode), $logbooks_locations_array)); + if ($check->num_rows() != 1) { + return array(2, $result['message'] = "
= __("Important") ?> = ("This function can be used to import POTA references from POTA hunter log in ADIF format. It will only import references for existing QSOs. It will not import QSO data itself.") ?>
+ + += __("POTA references for existing QSOs has been updated.")?>
+ += __("There is different data for POTA references in your log compared to imported data or QSO data could not be matched")?>
+| = __("Date"); ?> | += __("Time"); ?> | += __("Call"); ?> | += __("Band"); ?> | += __("Mode"); ?> | += __("POTA REF in Log"); ?> | += __("POTA REF in ADIF"); ?> | += __("Status"); ?> | +