Adding support for LoTW export.

这个提交包含在:
Corby Krick 2013-03-06 23:33:39 -06:00
父节点 048891a69c
当前提交 f3ac92a305
共有 3 个文件被更改,包括 59 次插入28 次删除

查看文件

@ -118,7 +118,7 @@ class Lotw extends CI_Controller {
// TODO: We don't actually see the error message
if ($data['user_lotw_name'] == '' || $data['user_lotw_password'] == '')
{
$this->session->set_flashdata('warning', 'You have not defined your ARRL LoTW credentials!'); redirect('dashboard');
$this->session->set_flashdata('warning', 'You have not defined your ARRL LoTW credentials!'); redirect('lotw/import');
}
// Query the logbook to determine when the last LoTW confirmation was
@ -183,7 +183,6 @@ class Lotw extends CI_Controller {
}
else
{
$data = array('upload_data' => $this->upload->data());
// Figure out how we should be marking QSLs confirmed via LoTW
@ -191,23 +190,26 @@ class Lotw extends CI_Controller {
$q = $query->row();
$config['lotw_login_url'] = $q->lotw_login_url;
// Set some fields that we're going to need for ARRL login
$query = $this->user_model->get_by_id($this->session->userdata('user_id'));
$q = $query->row();
$config['user_lotw_name'] = $q->user_lotw_name;
$config['user_lotw_password'] = $q->user_lotw_password;
$fields['login'] = $q->user_lotw_name;
$fields['password'] = $q->user_lotw_password;
$fields['acct_sel'] = "";
if ($fields['login'] == '' || $fields['password'] == '')
{
$this->session->set_flashdata('warning', 'You have not defined your ARRL LoTW credentials!'); redirect('lotw/status');
}
// Curl stuff goes here
// First we need to get a cookie
// options
$LOGIN = $config['user_lotw_name'];
$PASSWORD = $config['user_lotw_password'];
$cookie_file_path = "./uploads/cookies.txt";
$LOGINURL = $config['lotw_login_url'];
$agent = "Mozilla/4.0 (compatible;)";
// begin script
$ch = curl_init();
@ -229,11 +231,7 @@ class Lotw extends CI_Controller {
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
// Set login URL
curl_setopt($ch, CURLOPT_URL, $LOGINURL);
$fields['login'] = $LOGIN;
$fields['password'] = $PASSWORD;
$fields['acct_sel'] = "";
curl_setopt($ch, CURLOPT_URL, $config['lotw_login_url']);
// set postfields using what we extracted from the form
$POSTFIELDS = http_build_query($fields);
@ -243,8 +241,12 @@ class Lotw extends CI_Controller {
curl_setopt($ch, CURLOPT_POSTFIELDS, $POSTFIELDS);
// perform login
// TODO: probably should look at result at some point to verify that our login worked.
$result = curl_exec($ch);
if (stristr($result, "Username/password incorrect"))
{
$this->session->set_flashdata('warning', 'Your ARRL username and/or password is incorrect.'); redirect('lotw/status');
}
// Now we need to use that cookie and upload the file
// change URL to upload destination URL
@ -256,25 +258,34 @@ class Lotw extends CI_Controller {
);
//Upload it
//TODO: Read the output
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfile);
$response = curl_exec($ch);
if (stristr($response, "accepted"))
{
$this->session->set_flashdata('lotw_status', 'accepted');
$data['page_title'] = "LoTW .TQ8 Sent";
}
elseif (stristr($response, "rejected"))
{
$this->session->set_flashdata('lotw_status', 'rejected');
$data['page_title'] = "LoTW .TQ8 Sent";
}
else
{
// If we're here, we didn't find what we're looking for in the ARRL response
// and LoTW is probably down or broken.
$this->session->set_flashdata('warning', 'Did not receive proper response from LoTW. Try again later.');
$data['page_title'] = "LoTW .TQ8 Not Sent";
}
// Now we need to clean up
unlink($cookie_file_path);
unlink('./uploads/'.$data['upload_data']['file_name']);
$data['page_title'] = "LoTW .TQ8 Sent";
$this->load->view('layout/header', $data);
//Perhaps return some sort of success page
$this->load->view('lotw/export');
$this->load->view('lotw/status');
$this->load->view('layout/footer');
}
}
} // end class

查看文件

@ -1,6 +1,11 @@
<div id="container">
<h2><?php echo $page_title; ?></h2>
<?php if($this->session->flashdata('warning')) { ?>
<div id="message" >
<?php echo $this->session->flashdata('warning'); ?>
</div>
<?php } ?>
<h4>Step 1</h4>
<a href="<?php echo site_url('adif/export_lotw'); ?>" title="Export LoTW" target="_blank">Export an ADIF</a> file of QSOs that have not been uploaded to LoTW.

查看文件

@ -0,0 +1,15 @@
<div id="container">
<h2><?php echo $page_title; ?></h2>
<?php if($this->session->flashdata('warning')) { ?>
<div id="message" >
<?php echo $this->session->flashdata('warning'); ?>
</div>
<?php } ?>
<?php if($this->session->flashdata('lotw_status')) { ?>
<div id="message" >
<?php echo $this->session->flashdata('lotw_status'); ?>
</div>
<?php } ?>
</div>