From 8761d52bb78cac742b7f5e93b9a694649a593102 Mon Sep 17 00:00:00 2001 From: Corby Krick Date: Fri, 22 Feb 2013 18:30:33 -0600 Subject: [PATCH] Submitting LoTW fetch on the import form will download a file from LoTW and stick it in the uploads directory. Working on building the LoTW report download link. --- application/controllers/lotw.php | 68 +++++++++++++++++--------------- 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/application/controllers/lotw.php b/application/controllers/lotw.php index ffe5de6c..0e0a8a5e 100644 --- a/application/controllers/lotw.php +++ b/application/controllers/lotw.php @@ -19,44 +19,51 @@ class Lotw extends CI_Controller { $config['allowed_types'] = 'adi|ADI'; $this->load->library('upload', $config); - - if ( ! $this->upload->do_upload()) + if ($this->input->post('lotwimport') == 'fetch') { + // Probably need something like + // $this->load->library('arrl_lotw'); + // $this->arrl_lotw->fetch_report(someargs) + // Then dump that file into the uploads directory + // Then continue on with the below code using the file that + // got fetched instead of the uploaded one. + // $xml = file_get_contents("http://www.example.com/file.xml"); + // http://us.php.net/manual/en/function.file.php + + $file = $config['upload_path'] . 'lotwreport_download.adi'; + + file_put_contents($file, file_get_contents("https://p1k.arrl.org/lotwuser/lotwreport.adi?login=______&password=______&qso_query=1")); + - $data['error'] = $this->upload->display_errors(); - - $this->load->view('layout/header', $data); - $this->load->view('lotw/import'); - $this->load->view('layout/footer'); } else { - if ($this->input->post('lotwimport') == 'fetch') + if ( ! $this->upload->do_upload()) { - // Probably need something like - // $this->load->library('arrl_lotw'); - // $this->arrl_lotw->fetch_report(someargs) - // Then dump that file into the uploads directory - // Then continue on with the below code using the file that - // got fetched instead of the uploaded one. + + $data['error'] = $this->upload->display_errors(); + + $this->load->view('layout/header', $data); + $this->load->view('lotw/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(); - + $table = ""; - + while($record = $this->adif_parser->get_record()) { if(count($record) == 0) @@ -64,7 +71,7 @@ class Lotw extends CI_Controller { break; }; - + //echo date('Y-m-d', strtotime($record['qso_date']))."
"; //echo date('H:m', strtotime($record['time_on']))."
"; @@ -73,9 +80,9 @@ class Lotw extends CI_Controller { //echo $record["call"]."
"; //print_r($record->); - + $time_on = date('Y-m-d', strtotime($record['qso_date'])) ." ".date('H:i', strtotime($record['time_on'])); - + $qsl_date = date('Y-m-d', strtotime($record['qslrdate'])) ." ".date('H:i', strtotime($record['qslrdate'])); if (isset($record['time_off'])) { @@ -83,10 +90,10 @@ class Lotw extends CI_Controller { } else { $time_off = date('Y-m-d', strtotime($record['qso_date'])) ." ".date('H:i', strtotime($record['time_on'])); } - + $status = $this->logbook_model->import_check($time_on, $record['call'], $record['band']); $lotw_status = $this->logbook_model->lotw_update($time_on, $record['call'], $record['band'], $qsl_date, $record['qsl_rcvd']); - + $table .= ""; $table .= ""; $table .= ""; @@ -97,21 +104,18 @@ class Lotw extends CI_Controller { $table .= ""; $table .= ""; }; - + $table .= "
".$time_on."".$record['call']."LoTW Record: ".$lotw_status."
"; unlink('./uploads/'.$data['upload_data']['file_name']); $data['lotw_table'] = $table; - + $data['page_title'] = "LoTW ADIF Information"; $this->load->view('layout/header', $data); $this->load->view('lotw/analysis'); $this->load->view('layout/footer'); } - } - } - - -} \ No newline at end of file + } // end function +} // end class \ No newline at end of file