diff --git a/application/config/migration.php b/application/config/migration.php index 71ecf7ba..aabac391 100644 --- a/application/config/migration.php +++ b/application/config/migration.php @@ -21,7 +21,7 @@ $config['migration_enabled'] = TRUE; | be upgraded / downgraded to. | */ -$config['migration_version'] = 6; +$config['migration_version'] = 10; /* diff --git a/application/controllers/update.php b/application/controllers/update.php index decb6473..5a086b7e 100644 --- a/application/controllers/update.php +++ b/application/controllers/update.php @@ -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 "

Prefix List

"; - - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - - 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 ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; + // 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 "
PrefixCountry NameDXCC Expire Date
".$callsign->call."".ucwords(strtolower($callsign->entity))."".$end_date."".$callsign->deleted."
"; - - // empty table - $this->dxcc->empty_table("dxccexceptions"); - - echo "

Exceptions

"; - - echo "
"; - - foreach ($xml_data->exceptions as $exceptions) { - foreach ($exceptions->exception as $callsign) { - - echo ""; - echo ""; - echo ""; - echo ""; + $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 "
".$callsign->call."".$callsign->entity."
"; - + if ($done != "Downloading file"){ + // Check that everything is done? + if ($done == ""){ + $done = "Updating..."; + } + $html = $done."
"; + $html .= "Dxcc Entities: ".$this->db->count_all('dxcc_entities')."
"; + $html .= "Dxcc Exceptions: ".$this->db->count_all('dxcc_exceptions')."
"; + $html .= "Dxcc Prefixes: ".$this->db->count_all('dxcc_prefixes')."
"; + }else{ + $html = $done."....
"; + } + + 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 { } } } -?> \ No newline at end of file +?> diff --git a/application/migrations/008_add_dxcc_entities.php b/application/migrations/008_add_dxcc_entities.php new file mode 100644 index 00000000..41cabb74 --- /dev/null +++ b/application/migrations/008_add_dxcc_entities.php @@ -0,0 +1,52 @@ +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'); + } +} diff --git a/application/migrations/009_add_dxcc_exceptions.php b/application/migrations/009_add_dxcc_exceptions.php new file mode 100644 index 00000000..ff87512a --- /dev/null +++ b/application/migrations/009_add_dxcc_exceptions.php @@ -0,0 +1,53 @@ +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'); + } +} diff --git a/application/migrations/010_add_dxcc_prefixes.php b/application/migrations/010_add_dxcc_prefixes.php new file mode 100644 index 00000000..bfa4225d --- /dev/null +++ b/application/migrations/010_add_dxcc_prefixes.php @@ -0,0 +1,45 @@ +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'); + } +} diff --git a/application/models/dxcc_entities.php b/application/models/dxcc_entities.php new file mode 100644 index 00000000..c4e5d944 --- /dev/null +++ b/application/models/dxcc_entities.php @@ -0,0 +1,30 @@ +db->empty_table($table); + } + + +} diff --git a/application/models/dxcc_exceptions.php b/application/models/dxcc_exceptions.php new file mode 100644 index 00000000..164426d6 --- /dev/null +++ b/application/models/dxcc_exceptions.php @@ -0,0 +1,31 @@ +db->empty_table($table); + } + + +} \ No newline at end of file diff --git a/application/models/dxcc_prefixes.php b/application/models/dxcc_prefixes.php new file mode 100644 index 00000000..99a021b6 --- /dev/null +++ b/application/models/dxcc_prefixes.php @@ -0,0 +1,29 @@ +db->empty_table($table); + } + + +} diff --git a/application/views/awards/dxcc/details.php b/application/views/awards/dxcc/details.php new file mode 100644 index 00000000..13b8e263 --- /dev/null +++ b/application/views/awards/dxcc/details.php @@ -0,0 +1,40 @@ + + + + + + + + + +
+ +

Logbook

+ +

Filtering on

+ + load->view('view_log/partial/log') ?> \ No newline at end of file diff --git a/application/views/update/index.php b/application/views/update/index.php new file mode 100644 index 00000000..4ceb9de3 --- /dev/null +++ b/application/views/update/index.php @@ -0,0 +1,37 @@ +
+

+ + + + +
+ Status:
+
+
+ + +