From e7c06edec18f372f618e3f7bf9851b2c5dd8a0ff Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Sat, 19 Nov 2011 22:28:05 +0000 Subject: [PATCH] added adif --- application/config/mimes.php | 4 +- application/controllers/adif.php | 98 +++++++++++++++++++++++++- application/models/logbook_model.php | 99 +++++++++++++++++++++++++++ application/views/layout/header.php | 1 + application/views/welcome_message.php | 64 ----------------- license.txt | 51 -------------- 6 files changed, 199 insertions(+), 118 deletions(-) delete mode 100644 application/views/welcome_message.php delete mode 100644 license.txt 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 @@
  • Setup
  • Users
  • Backup
  • +
  • ADIF Import
  • ADIF Export
  • API
  • diff --git a/application/views/welcome_message.php b/application/views/welcome_message.php deleted file mode 100644 index ca68fc10..00000000 --- a/application/views/welcome_message.php +++ /dev/null @@ -1,64 +0,0 @@ - - - - - Welcome to CodeIgniter - - - - - -

    Welcome to CodeIgniter!

    - -

    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

    - - - \ No newline at end of file diff --git a/license.txt b/license.txt deleted file mode 100644 index 061cdb9d..00000000 --- a/license.txt +++ /dev/null @@ -1,51 +0,0 @@ -Copyright (c) 2008 - 2011, EllisLab, Inc. -All rights reserved. - -This license is a legal agreement between you and EllisLab Inc. for the use -of CodeIgniter Software (the "Software"). By obtaining the Software you -agree to comply with the terms and conditions of this license. - -PERMITTED USE -You are permitted to use, copy, modify, and distribute the Software and its -documentation, with or without modification, for any purpose, provided that -the following conditions are met: - -1. A copy of this license agreement must be included with the distribution. - -2. Redistributions of source code must retain the above copyright notice in - all source code files. - -3. Redistributions in binary form must reproduce the above copyright notice - in the documentation and/or other materials provided with the distribution. - -4. Any files that have been modified must carry notices stating the nature - of the change and the names of those who changed them. - -5. Products derived from the Software must include an acknowledgment that - they are derived from CodeIgniter in their documentation and/or other - materials provided with the distribution. - -6. Products derived from the Software may not be called "CodeIgniter", - nor may "CodeIgniter" appear in their name, without prior written - permission from EllisLab, Inc. - -INDEMNITY -You agree to indemnify and hold harmless the authors of the Software and -any contributors for any direct, indirect, incidental, or consequential -third-party claims, actions or suits, as well as any related expenses, -liabilities, damages, settlements or fees arising from your use or misuse -of the Software, or a violation of any terms of this license. - -DISCLAIMER OF WARRANTY -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR -IMPLIED, INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF QUALITY, PERFORMANCE, -NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. - -LIMITATIONS OF LIABILITY -YOU ASSUME ALL RISK ASSOCIATED WITH THE INSTALLATION AND USE OF THE SOFTWARE. -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS OF THE SOFTWARE BE LIABLE -FOR CLAIMS, DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF, OR IN CONNECTION -WITH THE SOFTWARE. LICENSE HOLDERS ARE SOLELY RESPONSIBLE FOR DETERMINING THE -APPROPRIATENESS OF USE AND ASSUME ALL RISKS ASSOCIATED WITH ITS USE, INCLUDING -BUT NOT LIMITED TO THE RISKS OF PROGRAM ERRORS, DAMAGE TO EQUIPMENT, LOSS OF -DATA OR SOFTWARE PROGRAMS, OR UNAVAILABILITY OR INTERRUPTION OF OPERATIONS.