From 9752bf7858bd47fe4841a769119cc46790185d59 Mon Sep 17 00:00:00 2001 From: Andy Date: Mon, 22 Feb 2016 08:09:50 +0000 Subject: [PATCH] Check existing log entries against the new DXCC/Country list --- application/controllers/update.php | 6 +++ application/logs/index.html | 10 ----- application/models/logbook_model.php | 47 ++++++++++++++++++++++ application/views/update/index.php | 5 +++ application/views/view_log/partial/log.php | 2 +- 5 files changed, 59 insertions(+), 11 deletions(-) delete mode 100644 application/logs/index.html diff --git a/application/controllers/update.php b/application/controllers/update.php index 5a086b7e..17c5d53d 100644 --- a/application/controllers/update.php +++ b/application/controllers/update.php @@ -206,6 +206,12 @@ class Update extends CI_Controller { } } + public function check_missing_dxcc(){ + $this->load->model('logbook_model'); + $this->logbook_model->check_missing_dxcc_id(); + + } + public function lotw_users() { // Load Database connectors $this->load->model('lotw'); diff --git a/application/logs/index.html b/application/logs/index.html deleted file mode 100644 index c942a79c..00000000 --- a/application/logs/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - 403 Forbidden - - - -

Directory access is forbidden.

- - - \ No newline at end of file diff --git a/application/models/logbook_model.php b/application/models/logbook_model.php index 0f0e2710..b37afa37 100644 --- a/application/models/logbook_model.php +++ b/application/models/logbook_model.php @@ -940,6 +940,53 @@ class Logbook_model extends CI_Model { } } + + private function check_dxcc_table($call){ + global $con; + $len = strlen($call); + + // query the table, removing a character from the right until a match + for ($i = $len; $i > 0; $i--){ + //printf("searching for %s\n", substr($call, 0, $i)); + $dxcc_result = $this->db->query("select `call`, `entity`, `adif` from dxcc_prefixes where `call` = '".substr($call, 0, $i) ."'"); + + + if ($dxcc_result->num_rows() > 0){ + $row = $dxcc_result->row_array(); + return array($row['adif'], $row['entity']); + } + } + + return array("Not Found", "Not Found"); + } + + public function check_missing_dxcc_id(){ + // get all records with no COL_DXCC + $this->db->select("COL_PRIMARY_KEY, COL_CALL"); + $this->db->where("COL_DXCC is NULL"); + $r = $this->db->get($this->config->item('table_name')); + + $count = 0; + $this->db->trans_start(); + //query dxcc_prefixes + if ($r->num_rows() > 0){ + foreach($r->result_array() as $row){ + $d = $this->check_dxcc_table($row['COL_CALL']); + if ($d[0] != 'Not Found'){ + $sql = sprintf("update %s set COL_COUNTRY = '%s', COL_DXCC='%s' where COL_PRIMARY_KEY=%d", + $this->config->item('table_name'), $d[1], $d[0], $row['COL_PRIMARY_KEY']); + $this->db->query($sql); + //print($sql."\n"); + printf("Updating %s to %s and %s\n
", $row['COL_PRIMARY_KEY'], $d[1], $d[0]); + $count++; + } + } + } + $this->db->trans_complete(); + + print("$count updated\n"); + } + } ?> diff --git a/application/views/update/index.php b/application/views/update/index.php index 4ceb9de3..d1c06992 100644 --- a/application/views/update/index.php +++ b/application/views/update/index.php @@ -7,6 +7,8 @@
Status:
+
+ Check missing DXCC/Countries values