当前提交
b7dd32259b
共有 10 个文件被更改,包括 452 次插入 和 131 次删除
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -5,4 +5,4 @@
|
|||
/uploads/*.tq8
|
||||
/uploads/*.TQ8
|
||||
/install/*
|
||||
/updates/*
|
||||
/updates/*
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ $config['migration_enabled'] = TRUE;
|
|||
| be upgraded / downgraded to.
|
||||
|
|
||||
*/
|
||||
$config['migration_version'] = 6;
|
||||
$config['migration_version'] = 10;
|
||||
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -7,23 +7,146 @@ class Update extends CI_Controller {
|
|||
dxcc - imports the latest clublog cty.xml data
|
||||
lotw_users - imports lotw users
|
||||
*/
|
||||
|
||||
|
||||
public function index()
|
||||
{
|
||||
// Create frontend pages.
|
||||
$data['page_title'] = "Updates";
|
||||
$this->load->view('layout/header', $data);
|
||||
$this->load->view('update/index');
|
||||
$this->load->view('layout/footer');
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Load the dxcc entities
|
||||
*/
|
||||
public function dxcc_entities() {
|
||||
// Load Database connectors
|
||||
$this->load->model('dxcc_entities');
|
||||
|
||||
// Load the cty file
|
||||
$xml_data = simplexml_load_file("updates/cty.xml");
|
||||
|
||||
//$xml_data->entities->entity->count();
|
||||
|
||||
$count = 0;
|
||||
foreach ($xml_data->entities->entity as $entity) {
|
||||
$endinfo = strtotime($entity->end);
|
||||
|
||||
$end_date = ($endinfo) ? date('Y-m-d H:i:s',$endinfo) : "";
|
||||
|
||||
if(!$entity->cqz) {
|
||||
$data = array(
|
||||
'prefix' => (string) $entity->call,
|
||||
'name' => (string) $entity->entity,
|
||||
);
|
||||
} else {
|
||||
$data = array(
|
||||
'adif' => (int) $entity->adif,
|
||||
'name' => (string) $entity->name,
|
||||
'prefix' => (string) $entity->prefix,
|
||||
'cqz' => (int) $entity->cqz,
|
||||
'cont' => (string) $entity->cont,
|
||||
'long' => (float) $entity->long,
|
||||
'lat' => (float) $entity->lat,
|
||||
'end' => $end_date,
|
||||
);
|
||||
}
|
||||
|
||||
$this->db->insert('dxcc_entities', $data);
|
||||
$count += 1;
|
||||
if ($count % 10 == 0)
|
||||
$this->update_status();
|
||||
}
|
||||
|
||||
$this->update_status();
|
||||
return $count;
|
||||
}
|
||||
|
||||
/*
|
||||
* Load the dxcc exceptions
|
||||
*/
|
||||
public function dxcc_exceptions() {
|
||||
// Load Database connectors
|
||||
$this->load->model('dxcc_exceptions');
|
||||
// Load the cty file
|
||||
$xml_data = simplexml_load_file("updates/cty.xml");
|
||||
|
||||
$count = 0;
|
||||
foreach ($xml_data->exceptions->exception as $record) {
|
||||
$startinfo = strtotime($record->start);
|
||||
$endinfo = strtotime($record->end);
|
||||
|
||||
$start_date = ($startinfo) ? date('Y-m-d H:i:s',$startinfo) : "";
|
||||
$end_date = ($endinfo) ? date('Y-m-d H:i:s',$endinfo) : "";
|
||||
|
||||
$data = array(
|
||||
'record' => (int) $record->attributes()->record,
|
||||
'call' => (string) $record->call,
|
||||
'entity' => (string) $record->entity,
|
||||
'adif' => (int) $record->adif,
|
||||
'cqz' => (int) $record->cqz,
|
||||
'cont' => (string) $record->cont,
|
||||
'long' => (float) $record->long,
|
||||
'lat' => (float) $record->lat,
|
||||
'start' => $start_date,
|
||||
'end' => $end_date,
|
||||
);
|
||||
|
||||
$this->db->insert('dxcc_exceptions', $data);
|
||||
$count += 1;
|
||||
if ($count % 10 == 0)
|
||||
$this->update_status();
|
||||
}
|
||||
|
||||
$this->update_status();
|
||||
return $count;
|
||||
}
|
||||
|
||||
/*
|
||||
* Load the dxcc prefixes
|
||||
*/
|
||||
public function dxcc_prefixes() {
|
||||
// Load Database connectors
|
||||
$this->load->model('dxcc_prefixes');
|
||||
// Load the cty file
|
||||
$xml_data = simplexml_load_file("updates/cty.xml");
|
||||
|
||||
$count = 0;
|
||||
foreach ($xml_data->prefixes->prefix as $record) {
|
||||
$data = array(
|
||||
'record' => (int) $record->attributes()->record,
|
||||
'call' => (string) $record->call,
|
||||
'entity' => (string) $record->entity,
|
||||
'adif' => (int) $record->adif,
|
||||
'cqz' => (int) $record->cqz,
|
||||
'cont' => (string) $record->cont,
|
||||
'long' => (float) $record->long,
|
||||
'lat' => (float) $record->lat,
|
||||
);
|
||||
|
||||
$this->db->insert('dxcc_prefixes', $data);
|
||||
$count += 1;
|
||||
if ($count % 10 == 0)
|
||||
$this->update_status();
|
||||
}
|
||||
|
||||
//print("$count prefixes processed");
|
||||
$this->update_status();
|
||||
return $count;
|
||||
}
|
||||
|
||||
// Updates the DXCC & Exceptions from the Clublog Cty.xml file.
|
||||
public function dxcc() {
|
||||
$this->update_status("Downloading file");
|
||||
|
||||
// give it 5 minutes...
|
||||
set_time_limit(600);
|
||||
|
||||
// Load Migration data if any.
|
||||
$this->load->library('migration');
|
||||
$this->fix_migrations();
|
||||
$this->migration->latest();
|
||||
|
||||
if ( ! $this->migration->latest())
|
||||
{
|
||||
show_error($this->migration->error_string());
|
||||
}
|
||||
|
||||
// Download latest file.
|
||||
$url = "https://secure.clublog.org/cty.php?api=a11c3235cd74b88212ce726857056939d52372bd";
|
||||
|
||||
|
|
@ -36,130 +159,51 @@ class Update extends CI_Controller {
|
|||
|
||||
file_put_contents('./updates/cty.xml', $data);
|
||||
|
||||
// Set timeout to unlimited
|
||||
set_time_limit(0);
|
||||
|
||||
// Load Database connectors
|
||||
$this->load->model('dxcc');
|
||||
// Clear the tables, ready for new data
|
||||
$this->db->empty_table("dxcc_entities");
|
||||
$this->db->empty_table("dxcc_exceptions");
|
||||
$this->db->empty_table("dxcc_prefixes");
|
||||
$this->update_status();
|
||||
|
||||
// Load the cty file
|
||||
$xml_data = simplexml_load_file("updates/cty.xml");
|
||||
|
||||
$this->dxcc->empty_table("dxcc");
|
||||
|
||||
echo "<h2>Prefix List</h2>";
|
||||
|
||||
echo "<table>";
|
||||
echo "<tr>";
|
||||
echo "<td>Prefix</td>";
|
||||
echo "<td>Country Name</td>";
|
||||
echo "<td>DXCC Expire Date</td>";
|
||||
echo "</tr>";
|
||||
|
||||
foreach ($xml_data->prefixes as $prefixs) {
|
||||
foreach ($prefixs->prefix as $callsign) {
|
||||
$endinfo = strtotime($callsign->end);
|
||||
|
||||
if($endinfo) {
|
||||
$end_date = date('Y-m-d H:i:s',$endinfo);
|
||||
} else {
|
||||
$end_date = "";
|
||||
}
|
||||
|
||||
if(!$callsign->cqz) {
|
||||
$data = array(
|
||||
'prefix' => (string) $callsign->call,
|
||||
'name' => (string) $callsign->entity,
|
||||
);
|
||||
} else {
|
||||
$data = array(
|
||||
'prefix' => (string) $callsign->call,
|
||||
'name' => (string) $callsign->entity,
|
||||
'cqz' => (string) $callsign->cqz,
|
||||
'ituz' => (string) $callsign->ituz,
|
||||
'cont' => (string) $callsign->cont,
|
||||
'long' => (string) $callsign->long,
|
||||
'lat' => (string) $callsign->lat,
|
||||
'end_date' => $end_date,
|
||||
);
|
||||
}
|
||||
|
||||
echo "<tr>";
|
||||
echo "<td>".$callsign->call."</td>";
|
||||
echo "<td>".ucwords(strtolower($callsign->entity))."</td>";
|
||||
echo "<td>".$end_date."</td>";
|
||||
echo "<td>".$callsign->deleted."</td>";
|
||||
echo "</tr>";
|
||||
// Parse the three sections of the file and update the tables
|
||||
$this->db->trans_start();
|
||||
$this->dxcc_entities();
|
||||
$this->dxcc_exceptions();
|
||||
$this->dxcc_prefixes();
|
||||
$this->db->trans_complete();
|
||||
|
||||
$this->db->insert('dxcc', $data);
|
||||
}
|
||||
}
|
||||
echo "<table>";
|
||||
|
||||
// empty table
|
||||
$this->dxcc->empty_table("dxccexceptions");
|
||||
|
||||
echo "<h2>Exceptions</h2>";
|
||||
|
||||
echo "<table>";
|
||||
|
||||
foreach ($xml_data->exceptions as $exceptions) {
|
||||
foreach ($exceptions->exception as $callsign) {
|
||||
|
||||
echo "<tr>";
|
||||
echo "<td>".$callsign->call."</td>";
|
||||
echo "<td>".$callsign->entity."</td>";
|
||||
echo "</tr>";
|
||||
$this->update_status("DONE");
|
||||
}
|
||||
|
||||
|
||||
if(!$callsign->start) {
|
||||
$data = array(
|
||||
'prefix' => (string) $callsign->call,
|
||||
'name' => (string) $callsign->entity,
|
||||
'cqz' => (string) $callsign->cqz,
|
||||
'ituz' => (string) $callsign->ituz,
|
||||
'cont' => (string) $callsign->cont,
|
||||
'long' => (string) $callsign->long,
|
||||
'lat' => (string) $callsign->lat
|
||||
);
|
||||
} else {
|
||||
|
||||
$startinfo = strtotime($callsign->start);
|
||||
|
||||
if($startinfo) {
|
||||
$start = date('Y-m-d H:i:s',$startinfo);
|
||||
} else {
|
||||
$start = "";
|
||||
}
|
||||
|
||||
$endinfo = strtotime($callsign->end);
|
||||
|
||||
if($endinfo) {
|
||||
$end = date('Y-m-d H:i:s',$endinfo);
|
||||
} else {
|
||||
$end = "";
|
||||
}
|
||||
|
||||
$data = array(
|
||||
'prefix' => (string) $callsign->call,
|
||||
'name' => (string) $callsign->entity,
|
||||
'cqz' => (string) $callsign->cqz,
|
||||
'ituz' => (string) $callsign->ituz,
|
||||
'cont' => (string) $callsign->cont,
|
||||
'long' => (string) $callsign->long,
|
||||
'lat' => (string) $callsign->lat,
|
||||
'start' => $start,
|
||||
'end' => $end
|
||||
);
|
||||
}
|
||||
public function update_status($done=""){
|
||||
|
||||
$this->db->insert('dxccexceptions', $data);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
echo "<table>";
|
||||
|
||||
if ($done != "Downloading file"){
|
||||
// Check that everything is done?
|
||||
if ($done == ""){
|
||||
$done = "Updating...";
|
||||
}
|
||||
$html = $done."<br/>";
|
||||
$html .= "Dxcc Entities: ".$this->db->count_all('dxcc_entities')."<br/>";
|
||||
$html .= "Dxcc Exceptions: ".$this->db->count_all('dxcc_exceptions')."<br/>";
|
||||
$html .= "Dxcc Prefixes: ".$this->db->count_all('dxcc_prefixes')."<br/>";
|
||||
}else{
|
||||
$html = $done."....<br/>";
|
||||
}
|
||||
|
||||
file_put_contents('./updates/status.html', $html);
|
||||
}
|
||||
|
||||
|
||||
private function fix_migrations(){
|
||||
$res = $this->db->query("select version from migrations");
|
||||
if ($res->num_rows() >0){
|
||||
$row = $res->row();
|
||||
$version = $row->version;
|
||||
|
||||
if ($version < 7){
|
||||
$this->db->query("update migrations set version=7");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function lotw_users() {
|
||||
|
|
@ -183,4 +227,4 @@ class Update extends CI_Controller {
|
|||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,52 @@
|
|||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Migration_add_dxcc_entities extends CI_Migration {
|
||||
|
||||
public function up(){
|
||||
$this->dbforge->add_field(array(
|
||||
'adif' => array(
|
||||
'type' => 'smallint',
|
||||
'Null' => FALSE
|
||||
),
|
||||
'name' => array(
|
||||
'type' => 'varchar(150)',
|
||||
'null' => TRUE
|
||||
),
|
||||
'prefix' => array(
|
||||
'type' => 'varchar(10)',
|
||||
'null' => FALSE
|
||||
),
|
||||
'cqz' => array(
|
||||
'type' => 'smallint',
|
||||
'null' => FALSE
|
||||
),
|
||||
'ituz' => array(
|
||||
'type' => 'smallint',
|
||||
'null' => FALSE
|
||||
),
|
||||
'cont' => array(
|
||||
'type' => 'varchar(5)',
|
||||
'null' => FALSE
|
||||
),
|
||||
'long' => array(
|
||||
'type' => 'float',
|
||||
'null' => FALSE
|
||||
),
|
||||
'lat' => array(
|
||||
'type' => 'float',
|
||||
'null' => FALSE
|
||||
),
|
||||
'end' => array(
|
||||
'type' => 'date',
|
||||
'null' => TRUE
|
||||
)
|
||||
));
|
||||
|
||||
$this->dbforge->add_key('adif', TRUE);
|
||||
$this->dbforge->create_table('dxcc_entities');
|
||||
}
|
||||
|
||||
public function down(){
|
||||
$this->dbforge->drop_table('dxcc_entities');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Migration_add_dxcc_exceptions extends CI_Migration {
|
||||
|
||||
public function up(){
|
||||
$this->dbforge->add_field(array(
|
||||
'record' => array(
|
||||
'type' => 'int',
|
||||
'Null' => FALSE
|
||||
),
|
||||
'call' => array(
|
||||
'type' => 'varchar(10)',
|
||||
'null' => TRUE
|
||||
),
|
||||
'entity' => array(
|
||||
'type' => 'varchar(255)',
|
||||
'null' => FALSE
|
||||
),
|
||||
'adif' => array(
|
||||
'type' => 'smallint',
|
||||
'null' => FALSE
|
||||
),
|
||||
'cqz' => array(
|
||||
'type' => 'smallint',
|
||||
'null' => FALSE
|
||||
),
|
||||
'cont' => array(
|
||||
'type' => 'varchar(5)',
|
||||
),
|
||||
'long' => array(
|
||||
'type' => 'float',
|
||||
),
|
||||
'lat' => array(
|
||||
'type' => 'float',
|
||||
),
|
||||
'start' => array(
|
||||
'type' => 'date',
|
||||
'null' => TRUE
|
||||
),
|
||||
'end' => array(
|
||||
'type' => 'date',
|
||||
'null' => TRUE
|
||||
)
|
||||
));
|
||||
|
||||
$this->dbforge->add_key('record', TRUE);
|
||||
$this->dbforge->create_table('dxcc_exceptions');
|
||||
}
|
||||
|
||||
public function down(){
|
||||
$this->dbforge->drop_table('dxcc_exceptions');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Migration_add_dxcc_prefixes extends CI_Migration {
|
||||
|
||||
public function up(){
|
||||
$this->dbforge->add_field(array(
|
||||
'record' => array(
|
||||
'type' => 'int',
|
||||
'Null' => FALSE
|
||||
),
|
||||
'call' => array(
|
||||
'type' => 'varchar(10)',
|
||||
'null' => TRUE
|
||||
),
|
||||
'entity' => array(
|
||||
'type' => 'varchar(255)',
|
||||
'null' => FALSE
|
||||
),
|
||||
'adif' => array(
|
||||
'type' => 'smallint',
|
||||
'null' => FALSE
|
||||
),
|
||||
'cqz' => array(
|
||||
'type' => 'smallint',
|
||||
'null' => FALSE
|
||||
),
|
||||
'cont' => array(
|
||||
'type' => 'varchar(5)',
|
||||
),
|
||||
'long' => array(
|
||||
'type' => 'float',
|
||||
),
|
||||
'lat' => array(
|
||||
'type' => 'float',
|
||||
),
|
||||
));
|
||||
|
||||
$this->dbforge->add_key('record', TRUE);
|
||||
$this->dbforge->create_table('dxcc_prefixes');
|
||||
}
|
||||
|
||||
public function down(){
|
||||
$this->dbforge->drop_table('dxcc_prefixes');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
class DXCC_Entities extends CI_Model {
|
||||
/*
|
||||
CREATE TABLE IF NOT EXISTS `dxcc_entities` (
|
||||
`adif` smallint NOT NULL,
|
||||
`name` varchar(150) DEFAULT NULL,
|
||||
`prefix` varchar(10) NOT NULL,
|
||||
`cqz` smallint NOT NULL,
|
||||
`ituz` smallint NOT NULL,
|
||||
`cont` varchar(5) NOT NULL,
|
||||
`long` float NOT NULL,
|
||||
`lat` float NOT NULL,
|
||||
`end` date DEFAULT NULL,
|
||||
PRIMARY KEY (`adif`),
|
||||
KEY `adif` (`adif`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
||||
*/
|
||||
function __construct(){
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
function empty_table($table){
|
||||
$this->db->empty_table($table);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
class DXCC_Exceptions extends CI_Model {
|
||||
/*
|
||||
CREATE TABLE IF NOT EXISTS `dxcc_exceptions` (
|
||||
`record` int NOT NULL,
|
||||
`call` varchar(10) NOT NULL,
|
||||
`entity` varchar(255) NOT NULL,
|
||||
`adif` smallint NOT NULL,
|
||||
`cqz` smallint NOT NULL,
|
||||
`cont` varchar(5),
|
||||
`long` float,
|
||||
`lat` float,
|
||||
`start` datetime,
|
||||
`end` datetime,
|
||||
PRIMARY KEY (`record`),
|
||||
KEY `record` (`record`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
||||
*/
|
||||
function __construct(){
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
function empty_table($table){
|
||||
$this->db->empty_table($table);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
class DXCC_Prefixes extends CI_Model {
|
||||
/*
|
||||
CREATE TABLE IF NOT EXISTS `dxcc_prefixes` (
|
||||
`record` int NOT NULL,
|
||||
`call` varchar(10) NOT NULL,
|
||||
`entity` varchar(255) NOT NULL,
|
||||
`adif` smallint NOT NULL,
|
||||
`cqz` smallint NOT NULL,
|
||||
`cont` varchar(5),
|
||||
`long` float,
|
||||
`lat` float,
|
||||
PRIMARY KEY (`record`),
|
||||
KEY `record` (`record`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
||||
*/
|
||||
function __construct(){
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
function empty_table($table){
|
||||
$this->db->empty_table($table);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
<div id="container">
|
||||
<h2><?php echo $page_title; ?></h2>
|
||||
|
||||
|
||||
<input type="submit" id="btn_update_dxcc" value="Update Dxcc" />
|
||||
|
||||
<div id="dxcc_update_status">
|
||||
Status:</br>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
#dxcc_update_status{
|
||||
display: None;
|
||||
}
|
||||
|
||||
</style>
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
$('#btn_update_dxcc').bind('click', function(){
|
||||
$('#dxcc_update_status').show();
|
||||
$.ajax({url:"update/dxcc"});
|
||||
setTimeout(update_stats,5000);
|
||||
});
|
||||
function update_stats(){
|
||||
$('#dxcc_update_status').load('<?php echo base_url()?>updates/status.html', function(val){
|
||||
$('#dxcc_update_staus').html(val);
|
||||
|
||||
if ((val === null) || (val.substring(0,4) !="DONE")){
|
||||
setTimeout(update_stats, 5000);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
</script>
|
||||
正在加载…
在新工单中引用