Basic QO-100 Dx Club API integration
这个提交包含在:
父节点
363cda94bc
当前提交
c962a972a8
共有 6 个文件被更改,包括 222 次插入 和 62 次删除
|
|
@ -21,7 +21,7 @@ $config['migration_enabled'] = TRUE;
|
||||||
| be upgraded / downgraded to.
|
| be upgraded / downgraded to.
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
$config['migration_version'] = 114;
|
$config['migration_version'] = 115;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||||
|
|
||||||
|
class Migration_add_webadif_api_export extends CI_Migration {
|
||||||
|
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
$fields = array(
|
||||||
|
'webadifapikey varchar(50) DEFAULT NULL',
|
||||||
|
'webadifapiurl varchar(256) DEFAULT NULL',
|
||||||
|
'webadifrealtime bool DEFAULT FALSE',
|
||||||
|
);
|
||||||
|
$this->dbforge->add_column('station_profile', $fields);
|
||||||
|
|
||||||
|
$fields = array(
|
||||||
|
"webadif_upload_date datetime DEFAULT NULL",
|
||||||
|
"webadif_upload_status varchar(1) DEFAULT 'N'",
|
||||||
|
);
|
||||||
|
$this->dbforge->add_column($this->config->item('table_name'), $fields);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
$this->dbforge->drop_column('station_profile', 'webadifapikey');
|
||||||
|
$this->dbforge->drop_column('station_profile', 'webadifapiurl');
|
||||||
|
$this->dbforge->drop_column('station_profile', 'webadifrealtime');
|
||||||
|
$this->dbforge->drop_column($this->config->item('table_name'), 'webadif_upload_date');
|
||||||
|
$this->dbforge->drop_column($this->config->item('table_name'), 'webadif_upload_status');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -481,6 +481,25 @@ class Logbook_model extends CI_Model {
|
||||||
$this->mark_qrz_qsos_sent($last_id);
|
$this->mark_qrz_qsos_sent($last_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$result = $this->exists_webadif_api_key($data['station_id']);
|
||||||
|
// Push qso to webadif if apikey is set, and realtime upload is enabled, and we're not importing an adif-file
|
||||||
|
if (isset($result->webadifapikey) && $result->webadifrealtime == 1) {
|
||||||
|
$CI =& get_instance();
|
||||||
|
$CI->load->library('AdifHelper');
|
||||||
|
$qso = $this->get_qso($last_id)->result();
|
||||||
|
|
||||||
|
$adif = $CI->adifhelper->getAdifLine($qso[0]);
|
||||||
|
$result = $this->push_qso_to_webadif(
|
||||||
|
$result->webadifapiurl,
|
||||||
|
$result->webadifapikey,
|
||||||
|
$adif
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($result) {
|
||||||
|
$this->mark_webadif_qsos_sent($last_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -503,6 +522,25 @@ class Logbook_model extends CI_Model {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Function checks if a WebADIF API Key exists in the table with the given station id
|
||||||
|
*/
|
||||||
|
function exists_webadif_api_key($station_id) {
|
||||||
|
$sql = 'select webadifapikey, webadifapiurl, webadifrealtime from station_profile
|
||||||
|
where station_id = ' . $station_id;
|
||||||
|
|
||||||
|
$query = $this->db->query($sql);
|
||||||
|
|
||||||
|
$result = $query->row();
|
||||||
|
|
||||||
|
if ($result) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Function uploads a QSO to QRZ with the API given.
|
* Function uploads a QSO to QRZ with the API given.
|
||||||
* $adif contains a line with the QSO in the ADIF format. QSO ends with an <EOR>
|
* $adif contains a line with the QSO in the ADIF format. QSO ends with an <EOR>
|
||||||
|
|
@ -545,6 +583,36 @@ class Logbook_model extends CI_Model {
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Function uploads a QSO to WebADIF consumer with the API given.
|
||||||
|
* $adif contains a line with the QSO in the ADIF format.
|
||||||
|
*/
|
||||||
|
function push_qso_to_webadif($url, $apikey, $adif) : bool{
|
||||||
|
|
||||||
|
$headers = array(
|
||||||
|
'Content-Type: text/plain',
|
||||||
|
'X-API-Key: ' . $apikey
|
||||||
|
);
|
||||||
|
|
||||||
|
if (substr($url, -1) !== "/") {
|
||||||
|
$url .= "/";
|
||||||
|
}
|
||||||
|
|
||||||
|
$ch = curl_init( $url . "qso");
|
||||||
|
curl_setopt( $ch, CURLOPT_POST, true);
|
||||||
|
curl_setopt( $ch, CURLOPT_POSTFIELDS, (string)$adif);
|
||||||
|
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
|
||||||
|
curl_setopt( $ch, CURLOPT_HEADER, 0);
|
||||||
|
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
|
||||||
|
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
|
||||||
|
$content = curl_exec($ch); // TODO: better error handling
|
||||||
|
$errors = curl_error($ch);
|
||||||
|
$response = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
|
curl_close($ch);
|
||||||
|
return $response === 200;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Function marks QSOs as uploaded to QRZ.
|
* Function marks QSOs as uploaded to QRZ.
|
||||||
* $primarykey is the unique id for that QSO in the logbook
|
* $primarykey is the unique id for that QSO in the logbook
|
||||||
|
|
@ -562,6 +630,24 @@ class Logbook_model extends CI_Model {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Function marks QSOs as uploaded to WebADIF.
|
||||||
|
* $primarykey is the unique id for that QSO in the logbook
|
||||||
|
*/
|
||||||
|
function mark_webadif_qsos_sent($primarykey)
|
||||||
|
{
|
||||||
|
$data = array(
|
||||||
|
'webadif_upload_date' => date("Y-m-d H:i:s", strtotime("now")),
|
||||||
|
'webadif_upload_status' => 'Y',
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->db->where('COL_PRIMARY_KEY', $primarykey);
|
||||||
|
|
||||||
|
$this->db->update($this->config->item('table_name'), $data);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
function upload_amsat_status($data) {
|
function upload_amsat_status($data) {
|
||||||
$sat_name = '';
|
$sat_name = '';
|
||||||
if ($data['COL_SAT_NAME'] == 'AO-7') {
|
if ($data['COL_SAT_NAME'] == 'AO-7') {
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,9 @@ class Stations extends CI_Model {
|
||||||
'oqrs' => xss_clean($this->input->post('oqrs', true)),
|
'oqrs' => xss_clean($this->input->post('oqrs', true)),
|
||||||
'oqrs_email' => xss_clean($this->input->post('oqrsemail', true)),
|
'oqrs_email' => xss_clean($this->input->post('oqrsemail', true)),
|
||||||
'oqrs_text' => xss_clean($this->input->post('oqrstext', true)),
|
'oqrs_text' => xss_clean($this->input->post('oqrstext', true)),
|
||||||
|
'webadifapikey' => xss_clean($this->input->post('webadifapikey', true)),
|
||||||
|
'webadifapiurl' => 'https://qo100dx.club/api',
|
||||||
|
'webadifrealtime' => xss_clean($this->input->post('webadifrealtime', true)),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Insert Records
|
// Insert Records
|
||||||
|
|
@ -111,6 +114,9 @@ class Stations extends CI_Model {
|
||||||
'oqrs' => xss_clean($this->input->post('oqrs', true)),
|
'oqrs' => xss_clean($this->input->post('oqrs', true)),
|
||||||
'oqrs_email' => xss_clean($this->input->post('oqrsemail', true)),
|
'oqrs_email' => xss_clean($this->input->post('oqrsemail', true)),
|
||||||
'oqrs_text' => xss_clean($this->input->post('oqrstext', true)),
|
'oqrs_text' => xss_clean($this->input->post('oqrstext', true)),
|
||||||
|
'webadifapikey' => xss_clean($this->input->post('webadifapikey', true)),
|
||||||
|
'webadifapiurl' => 'https://qo100dx.club/api',
|
||||||
|
'webadifrealtime' => xss_clean($this->input->post('webadifrealtime', true)),
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->db->where('user_id', $this->session->userdata('user_id'));
|
$this->db->where('user_id', $this->session->userdata('user_id'));
|
||||||
|
|
|
||||||
|
|
@ -241,6 +241,21 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-row">
|
||||||
|
<div class="form-group col-sm-6">
|
||||||
|
<label for="webadifApiKey"> QO-100 Dx Club API Key </label>
|
||||||
|
<input type="text" class="form-control" name="webadifapikey" id="webadifApiKey" aria-describedby="webadifApiKeyHelp">
|
||||||
|
<small id="webadifApiKeyHelp" class="form-text text-muted">Create your API key on <a href="https://qo100dx.club" target="_blank">your QO-100 Dx Club's profile page</a></small>
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-sm-6">
|
||||||
|
<label for="webadifrealtime">QO-100 Dx Club Realtime Upload</label>
|
||||||
|
<select class="custom-select" id="webadifrealtime" name="webadifrealtime">
|
||||||
|
<option value="1">Yes</option>
|
||||||
|
<option value="0" selected>No</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="oqrs">OQRS Enabled</label>
|
<label for="oqrs">OQRS Enabled</label>
|
||||||
<select class="custom-select" id="oqrs" name="oqrs">
|
<select class="custom-select" id="oqrs" name="oqrs">
|
||||||
|
|
|
||||||
|
|
@ -356,6 +356,27 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md">
|
||||||
|
<div class="card">
|
||||||
|
<h5 class="card-header">QO-100 Dx Club</h5>
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="webadifApiKey">QO-100 Dx Club API Key</label>
|
||||||
|
<input type="text" class="form-control" name="webadifapikey" id="webadifApiKey" aria-describedby="webadifApiKeyHelp" value="<?php if(set_value('webadifapikey') != "") { echo set_value('webadifapikey'); } else { echo $my_station_profile->webadifapikey; } ?>">
|
||||||
|
<small id="webadifApiKeyHelp" class="form-text text-muted">Create your API key on <a href="https://qo100dx.club" target="_blank">your QO-100 Dx Club's profile page</a></small>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="webadifrealtime">QO-100 Dx Club Realtime Upload</label>
|
||||||
|
<select class="custom-select" id="webadifrealtime" name="webadifrealtime">
|
||||||
|
<option value="1" <?php if ($my_station_profile->webadifrealtime == 1) { echo " selected =\"selected\""; } ?>>Yes</option>
|
||||||
|
<option value="0" <?php if ($my_station_profile->webadifrealtime == 0) { echo " selected =\"selected\""; } ?>>No</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md">
|
<div class="col-md">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
|
|
|
||||||
正在加载…
在新工单中引用