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 index c942a79c..7f684dff 100644 --- a/application/logs/index.html +++ b/application/logs/index.html @@ -7,4 +7,4 @@

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 2c03dbc3..0cde9626 100644 --- a/application/models/logbook_model.php +++ b/application/models/logbook_model.php @@ -966,6 +966,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