diff --git a/application/controllers/lotw.php b/application/controllers/lotw.php index 0e0a8a5e..a78ebae6 100644 --- a/application/controllers/lotw.php +++ b/application/controllers/lotw.php @@ -20,21 +20,92 @@ class Lotw extends CI_Controller { $this->load->library('upload', $config); 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")); + // Get credentials for LoTW + $query = $this->user_model->get_by_id($this->session->userdata('user_id')); + $q = $query->row(); + $data['user_lotw_name'] = $q->user_lotw_name; + $data['user_lotw_password'] = $q->user_lotw_password; + // TODO: Validate that LoTW credentials are not empty + // TODO: Query the logbook to determine when the last LoTW confirmation was + // TODO: Build the URL to download a report file that matches the format of one that a user would download themselves + // TODO: Consolidate code + // Build URL for LoTW report file + $lotw_url = "https://p1k.arrl.org/lotwuser/lotwreport.adi?"; + $lotw_url .= "login=" . $data['user_lotw_name']; + $lotw_url .= "&password=" . $data['user_lotw_password']; + $lotw_url .= "&qso_query=1"; + + file_put_contents($file, file_get_contents($lotw_url)); + + 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($file); + + $this->adif_parser->initialize(); + + $table = ""; + + 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->); + + $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'])) { + $time_off = date('Y-m-d', strtotime($record['qso_date'])) ." ".date('H:i', strtotime($record['time_off'])); + } 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 .= ""; + $table .= ""; + $table .= ""; + $table .= ""; + $table .= ""; + $table .= ""; + $table .= ""; + }; + + $table .= "
".$time_on."".$record['call']."".$record['mode']."".$record['qsl_rcvd']."".$qsl_date."QSO Record: ".$status."LoTW Record: ".$lotw_status."
"; + + unlink($file); + + $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'); } else {