diff --git a/application/controllers/Adif.php b/application/controllers/Adif.php index 64750fc58..ce2cca170 100644 --- a/application/controllers/Adif.php +++ b/application/controllers/Adif.php @@ -158,10 +158,9 @@ class adif extends CI_Controller { public function import() { $this->load->model('stations'); $data['station_profile'] = $this->stations->all_of_user(); - log_message("debug","Started ADIF Import"); - $active_station_id = $this->stations->find_active(); - $station_profile = $this->stations->profile($active_station_id); + $active_station_id = $this->stations->find_active(); + $station_profile = $this->stations->profile($active_station_id); $data['active_station_info'] = $station_profile->row(); @@ -169,13 +168,14 @@ class adif extends CI_Controller { $data['tab'] = "adif"; $config['upload_path'] = './uploads/'; - $config['allowed_types'] = 'adi|ADI|adif|ADIF'; + $config['allowed_types'] = 'adi|ADI|adif|ADIF|zip'; + log_message("Error","ADIF Start"); + session_write_close(); $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); @@ -183,43 +183,71 @@ class adif extends CI_Controller { $this->load->view('interface_assets/footer'); } else { if ($this->stations->check_station_is_accessible($this->input->post('station_profile'))) { - $data = array('upload_data' => $this->upload->data()); + $stopnow=false; + $fdata = 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'); + $f_elements=explode(".",$fdata['upload_data']['file_name']); + if (strtolower($f_elements[count($f_elements)-1])=='zip') { + $f_adif = preg_replace('/\\.zip$/', '', $fdata['upload_data']['file_name']); + $p_adif = preg_replace('/^(.*)(_)(\S{2,4})$/', '$1.$3', $f_adif); // Bug in CodeIgniter. Destroys Filename if there is more than one dot. + if (preg_match("/.*\.adi.?$/",strtolower($p_adif))) { // Check if adi? inside zip + $zip = new ZipArchive; + if ($zip->open('./uploads/'.$fdata['upload_data']['file_name'])) { + $zip->extractTo("./uploads/",array($p_adif)); + $zip->close(); + } + unlink('./uploads/'.$fdata['upload_data']['file_name']); + } else { + unlink('./uploads/'.$fdata['upload_data']['file_name']); + $data['error'] = "Unsupported Filetype"; + $stopnow=true; + } + } else { + $p_adif=$fdata['upload_data']['file_name']; + } + if (!($stopnow)) { - $this->adif_parser->load_from_file('./uploads/'.$data['upload_data']['file_name']); - unlink('./uploads/'.$data['upload_data']['file_name']); - $data['upload_data']=''; // free memory + $this->load->library('adif_parser'); - $this->adif_parser->initialize(); - $custom_errors = ""; - $alladif=[]; - while($record = $this->adif_parser->get_record()) - { - if(count($record) == 0) { - break; + $this->adif_parser->load_from_file('./uploads/'.$p_adif); + unlink('./uploads/'.$p_adif); + $fdata['upload_data']=''; // free memory + + $this->adif_parser->initialize(); + $custom_errors = ""; + $alladif=[]; + while($record = $this->adif_parser->get_record()) + { + if(count($record) == 0) { + break; + }; + array_push($alladif,$record); }; - array_push($alladif,$record); - }; - $record=''; // free memory - $custom_errors = $this->logbook_model->import_bulk($alladif, $this->input->post('station_profile'), $this->input->post('skipDuplicate'), $this->input->post('markClublog'),$this->input->post('markLotw'), $this->input->post('dxccAdif'), $this->input->post('markQrz'), $this->input->post('markHrd'), true, $this->input->post('operatorName'), false, $this->input->post('skipStationCheck')); + $record=''; // free memory + $custom_errors = $this->logbook_model->import_bulk($alladif, $this->input->post('station_profile'), $this->input->post('skipDuplicate'), $this->input->post('markClublog'),$this->input->post('markLotw'), $this->input->post('dxccAdif'), $this->input->post('markQrz'), $this->input->post('markHrd'), true, $this->input->post('operatorName'), false, $this->input->post('skipStationCheck')); + } else { // Failure, if no ADIF inside ZIP + $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'); + return; + } } else { $custom_errors='Station Profile not valid for User'; } + log_message("Error","ADIF End"); $data['adif_errors'] = $custom_errors; $data['skip_dupes'] = $this->input->post('skipDuplicate'); - log_message("debug","Finished ADIF Import"); $data['page_title'] = "ADIF Imported"; $this->load->view('interface_assets/header', $data); $this->load->view('adif/import_success'); $this->load->view('interface_assets/footer'); - } } diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index 09d5889c1..95bbb1666 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -3238,7 +3238,7 @@ function lotw_last_qsl_date($user_id) { if ($dxccAdif != NULL) { if (isset($record['dxcc'])) { $entity = $this->get_entity($record['dxcc']); - $dxcc = array($record['dxcc'], $entity['name']); + $dxcc = array($record['dxcc'] ?? '', $entity['name'] ?? ''); } else { $dxcc = $this->check_dxcc_table($record['call'], $time_off); } diff --git a/application/views/adif/import.php b/application/views/adif/import.php index 2de271658..8c1a3c397 100644 --- a/application/views/adif/import.php +++ b/application/views/adif/import.php @@ -55,7 +55,7 @@
B.
- @@ -265,4 +265,4 @@ - \ No newline at end of file + diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index b5c271f95..09b178ee1 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -139,6 +139,7 @@ if($this->session->userdata('user_id') != null) { uri->segment(1) == "adif" ) { ?> + uri->segment(1) == "notes" && ($this->uri->segment(2) == "add" || $this->uri->segment(2) == "edit") ) { ?> diff --git a/assets/js/jszip.min.js b/assets/js/jszip.min.js new file mode 100644 index 000000000..ff4cfd5e8 --- /dev/null +++ b/assets/js/jszip.min.js @@ -0,0 +1,13 @@ +/*! + +JSZip v3.10.1 - A JavaScript class for generating and reading zip files +>>=y=v>>>24,p-=y,!(16&(y=v>>>16&255))){if(0==(64&y)){v=_[(65535&v)+(d&(1<