2013-02-16 16:41:40 +00:00
|
|
|
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
|
|
|
|
class Lotw extends CI_Controller {
|
|
|
|
|
|
|
|
/* Controls who can access the controller and its functions */
|
|
|
|
function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
$this->load->helper(array('form', 'url'));
|
|
|
|
|
|
|
|
$this->load->model('user_model');
|
|
|
|
if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); }
|
|
|
|
}
|
|
|
|
|
|
|
|
public function import() {
|
|
|
|
$data['page_title'] = "LoTW ADIF Import";
|
|
|
|
|
|
|
|
$config['upload_path'] = './uploads/';
|
|
|
|
$config['allowed_types'] = 'adi|ADI';
|
|
|
|
|
|
|
|
$this->load->library('upload', $config);
|
2013-02-23 00:30:33 +00:00
|
|
|
if ($this->input->post('lotwimport') == 'fetch')
|
2013-02-16 16:41:40 +00:00
|
|
|
{
|
2013-02-23 00:30:33 +00:00
|
|
|
// 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"));
|
|
|
|
|
2013-02-22 02:13:42 +00:00
|
|
|
|
2013-02-16 16:41:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-02-23 00:30:33 +00:00
|
|
|
if ( ! $this->upload->do_upload())
|
2013-02-22 02:19:58 +00:00
|
|
|
{
|
2013-02-23 00:30:33 +00:00
|
|
|
|
|
|
|
$data['error'] = $this->upload->display_errors();
|
|
|
|
|
|
|
|
$this->load->view('layout/header', $data);
|
|
|
|
$this->load->view('lotw/import');
|
|
|
|
$this->load->view('layout/footer');
|
2013-02-22 02:19:58 +00:00
|
|
|
}
|
|
|
|
else
|
2013-02-16 16:41:40 +00:00
|
|
|
{
|
2013-02-22 02:13:42 +00:00
|
|
|
$data = array('upload_data' => $this->upload->data());
|
2013-02-23 00:30:33 +00:00
|
|
|
|
2013-02-22 02:13:42 +00:00
|
|
|
ini_set('memory_limit', '-1');
|
|
|
|
set_time_limit(0);
|
2013-02-23 00:30:33 +00:00
|
|
|
|
2013-02-22 02:13:42 +00:00
|
|
|
$this->load->model('logbook_model');
|
2013-02-23 00:30:33 +00:00
|
|
|
|
2013-02-22 02:13:42 +00:00
|
|
|
$this->load->library('adif_parser');
|
|
|
|
|
|
|
|
$this->adif_parser->load_from_file('./uploads/'.$data['upload_data']['file_name']);
|
2013-02-23 00:30:33 +00:00
|
|
|
|
2013-02-22 02:13:42 +00:00
|
|
|
$this->adif_parser->initialize();
|
2013-02-23 00:30:33 +00:00
|
|
|
|
2013-02-22 02:13:42 +00:00
|
|
|
$table = "<table>";
|
2013-02-23 00:30:33 +00:00
|
|
|
|
2013-02-22 02:13:42 +00:00
|
|
|
while($record = $this->adif_parser->get_record())
|
2013-02-16 16:41:40 +00:00
|
|
|
{
|
2013-02-22 02:13:42 +00:00
|
|
|
if(count($record) == 0)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
};
|
2013-02-16 16:41:40 +00:00
|
|
|
|
2013-02-23 00:30:33 +00:00
|
|
|
|
2013-02-16 16:41:40 +00:00
|
|
|
|
2013-02-22 02:13:42 +00:00
|
|
|
//echo date('Y-m-d', strtotime($record['qso_date']))."<br>";
|
|
|
|
//echo date('H:m', strtotime($record['time_on']))."<br>";
|
2013-02-16 16:41:40 +00:00
|
|
|
|
2013-02-22 02:13:42 +00:00
|
|
|
//$this->logbook_model->import($record);
|
2013-02-16 16:41:40 +00:00
|
|
|
|
2013-02-22 02:13:42 +00:00
|
|
|
//echo $record["call"]."<br>";
|
|
|
|
//print_r($record->);
|
2013-02-23 00:30:33 +00:00
|
|
|
|
2013-02-22 02:13:42 +00:00
|
|
|
$time_on = date('Y-m-d', strtotime($record['qso_date'])) ." ".date('H:i', strtotime($record['time_on']));
|
2013-02-23 00:30:33 +00:00
|
|
|
|
2013-02-22 02:13:42 +00:00
|
|
|
$qsl_date = date('Y-m-d', strtotime($record['qslrdate'])) ." ".date('H:i', strtotime($record['qslrdate']));
|
2013-02-16 16:41:40 +00:00
|
|
|
|
2013-02-22 02:13:42 +00:00
|
|
|
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']));
|
|
|
|
}
|
2013-02-23 00:30:33 +00:00
|
|
|
|
2013-02-22 02:13:42 +00:00
|
|
|
$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']);
|
2013-02-23 00:30:33 +00:00
|
|
|
|
2013-02-22 02:13:42 +00:00
|
|
|
$table .= "<tr>";
|
|
|
|
$table .= "<td>".$time_on."</td>";
|
|
|
|
$table .= "<td>".$record['call']."</td>";
|
|
|
|
$table .= "<td>".$record['mode']."</td>";
|
|
|
|
$table .= "<td>".$record['qsl_rcvd']."</td>";
|
|
|
|
$table .= "<td>".$qsl_date."</td>";
|
|
|
|
$table .= "<td>QSO Record: ".$status."</td>";
|
|
|
|
$table .= "<td>LoTW Record: ".$lotw_status."</td>";
|
|
|
|
$table .= "<tr>";
|
|
|
|
};
|
2013-02-23 00:30:33 +00:00
|
|
|
|
2013-02-22 02:13:42 +00:00
|
|
|
$table .= "</table>";
|
2013-02-16 16:41:40 +00:00
|
|
|
|
2013-02-22 02:13:42 +00:00
|
|
|
unlink('./uploads/'.$data['upload_data']['file_name']);
|
2013-02-16 16:41:40 +00:00
|
|
|
|
2013-02-22 02:13:42 +00:00
|
|
|
$data['lotw_table'] = $table;
|
2013-02-23 00:30:33 +00:00
|
|
|
|
2013-02-22 02:13:42 +00:00
|
|
|
$data['page_title'] = "LoTW ADIF Information";
|
|
|
|
$this->load->view('layout/header', $data);
|
|
|
|
$this->load->view('lotw/analysis');
|
|
|
|
$this->load->view('layout/footer');
|
|
|
|
}
|
2013-02-16 16:41:40 +00:00
|
|
|
}
|
2013-02-23 00:30:33 +00:00
|
|
|
} // end function
|
|
|
|
} // end class
|