diff --git a/application/config/mimes.php b/application/config/mimes.php
index 8065794f..efd4dc78 100644
--- a/application/config/mimes.php
+++ b/application/config/mimes.php
@@ -98,7 +98,9 @@ $mimes = array( 'hqx' => 'application/mac-binhex40',
'word' => array('application/msword', 'application/octet-stream'),
'xl' => 'application/excel',
'eml' => 'message/rfc822',
- 'json' => array('application/json', 'text/json')
+ 'json' => array('application/json', 'text/json'),
+ 'adi' => 'application/octet-stream',
+ 'ADI' => 'application/octet-stream',
);
diff --git a/application/controllers/adif.php b/application/controllers/adif.php
index 02dd85d7..dfa4085d 100644
--- a/application/controllers/adif.php
+++ b/application/controllers/adif.php
@@ -4,6 +4,12 @@ class adif extends CI_Controller {
/* Controls ADIF Import/Export Functions */
+ function __construct()
+ {
+ parent::__construct();
+ $this->load->helper(array('form', 'url'));
+ }
+
/* Shows Export Views */
public function export() {
@@ -38,10 +44,98 @@ class adif extends CI_Controller {
$this->load->view('adif/data/exportall', $data);
-
}
-
+ public function import() {
+ $data['page_title'] = "ADIF Import";
+
+ $config['upload_path'] = './uploads/';
+ $config['allowed_types'] = 'adi|ADI';
+
+ $this->load->library('upload', $config);
+
+ if ( ! $this->upload->do_upload())
+ {
+ $data['error'] = $this->upload->display_errors();
+
+ $this->load->view('layout/header', $data);
+ $this->load->view('adif/import');
+ $this->load->view('layout/footer');
+ }
+ else
+ {
+
+ $data = array('upload_data' => $this->upload->data());
+
+ ini_set('memory_limit', '-1');
+ set_time_limit(0);
+
+ $this->load->model('logbook_model');
+
+ $this->load->library('adif_parser');
+
+ $this->adif_parser->load_from_file('./uploads/'.$data['upload_data']['file_name']);
+
+ $this->adif_parser->initialize();
+
+ while($record = $this->adif_parser->get_record())
+ {
+ if(count($record) == 0)
+ {
+ break;
+ };
+
+ //echo date('Y-m-d', strtotime($record['qso_date']))."
";
+ //echo date('H:m', strtotime($record['time_on']))."
";
+
+ $this->logbook_model->import($record);
+
+ //echo $record["call"]."
";
+ //print_r($record);
+ };
+
+ unlink('./uploads/'.$data['upload_data']['file_name']);
+
+ $data['page_title'] = "ADIF Imported";
+ $this->load->view('layout/header', $data);
+ $this->load->view('adif/import_success');
+ $this->load->view('layout/footer');
+
+ }
+ }
+
+
+ function test() {
+ // Set memory limit to unlimited to allow heavy usage
+ ini_set('memory_limit', '-1');
+ set_time_limit(0);
+
+ $this->load->model('logbook_model');
+
+ $this->load->library('adif_parser');
+
+ $this->adif_parser->load_from_file('./uploads/2e0sql.ADI');
+
+ $this->adif_parser->initialize();
+
+ while($record = $this->adif_parser->get_record())
+ {
+ if(count($record) == 0)
+ {
+ break;
+ };
+
+ //echo date('Y-m-d', strtotime($record['qso_date']))."
";
+ //echo date('H:m', strtotime($record['time_on']))."
";
+
+ $this->logbook_model->import($record);
+
+ //echo $record["call"]."
";
+ //print_r($record);
+ };
+
+ }
+
}
/* End of file welcome.php */
diff --git a/application/models/logbook_model.php b/application/models/logbook_model.php
index d3623edf..ec60a8e9 100644
--- a/application/models/logbook_model.php
+++ b/application/models/logbook_model.php
@@ -432,6 +432,105 @@ class Logbook_model extends CI_Model {
$this->db->where('COL_PRIMARY_KEY', $id);
$this->db->delete($this->config->item('table_name'));
}
+
+ function import($record) {
+ // Join date+time
+ //$datetime = date('Y-m-d') ." ". $this->input->post('start_time');
+ //$myDate = date('Y-m-d', $record['qso_date']);
+ $time_on = date('Y-m-d', strtotime($record['qso_date'])) ." ".date('H:i', strtotime($record['time_on']));
+ $time_off = date('Y-m-d', strtotime($record['qso_date'])) ." ".date('H:i', strtotime($record['time_off']));
+
+
+ if(isset($record['freq'])) {
+ $freq = $record['freq'];
+ } else {
+ $freq = "0";
+ }
+ if(isset($record['name'])) {
+ $name = $record['name'];
+ } else {
+ $name = "";
+ }
+ if(isset($record['comment'])) {
+ $comment = $record['comment'];
+ } else {
+ $comment = "";
+ }
+
+ if(isset($record['sat_name'])) {
+ $sat_name = $record['sat_name'];
+ } else {
+ $sat_name = "";
+ }
+
+ if(isset($record['sat_mode'])) {
+ $sat_mode = $record['sat_mode'];
+ } else {
+ $sat_mode = "";
+ }
+
+ if(isset($record['gridsquare'])) {
+ $gridsquare = $record['gridsquare'];
+ } else {
+ $gridsquare = "";
+ }
+
+ if(isset($record['country'])) {
+ $country = $record['country'];
+ } else {
+
+ $country = "";
+
+ }
+
+ if(isset($record['qth'])) {
+ $qth = $record['qth'];
+ } else {
+ $qth = "";
+ }
+
+ if(isset($record['prop_mode'])) {
+ $prop_mode = $record['prop_mode'];
+ } else {
+ $prop_mode = "";
+ }
+
+
+ $this->db->where('COL_CALL', $record['call']);
+ $this->db->where('COL_TIME_ON', $time_on);
+ $check = $this->db->get($this->config->item('table_name'));
+
+ if ($check->num_rows() <= 0)
+ {
+ // Create array with QSO Data
+ $data = array(
+ 'COL_TIME_ON' => $time_on,
+ 'COL_TIME_OFF' => $time_off,
+ 'COL_CALL' => strtoupper($record['call']),
+ 'COL_BAND' => $record['band'],
+ 'COL_FREQ' => $freq,
+ 'COL_MODE' => $record['mode'],
+ 'COL_RST_RCVD' => $record['rst_rcvd'],
+ 'COL_RST_SENT' => $record['rst_sent'],
+ 'COL_NAME' => $name,
+ 'COL_COMMENT' => $comment,
+ 'COL_SAT_NAME' => $sat_name,
+ 'COL_SAT_MODE' => $sat_mode,
+ 'COL_GRIDSQUARE' => $gridsquare,
+ 'COL_COUNTRY' => $country,
+ 'COL_QTH' =>$qth,
+ 'COL_PROP_MODE' => $prop_mode,
+ 'COL_DISTANCE' => 0,
+ 'COL_FREQ_RX' => 0,
+ 'COL_BAND_RX' => 0,
+ 'COL_ANT_AZ' => 0,
+ 'COL_ANT_EL' => 0,
+ );
+
+ $this->add_qso($data);
+ }
+ }
+
}
?>
diff --git a/application/views/layout/header.php b/application/views/layout/header.php
index 4ad491ef..8361b3ce 100644
--- a/application/views/layout/header.php
+++ b/application/views/layout/header.php
@@ -53,6 +53,7 @@
The page you are looking at is being generated dynamically by CodeIgniter.
- -If you would like to edit this page you'll find it located at:
-application/views/welcome_message.php
-
-The corresponding controller for this page is found at:
-application/controllers/welcome.php
-
-If you are exploring CodeIgniter for the very first time, you should start by reading the User Guide.
- - -
Page rendered in {elapsed_time} seconds