diff --git a/application/config/migration.php b/application/config/migration.php
index 947334c3..993f1dc4 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'] = 12;
+$config['migration_version'] = 13;
/*
diff --git a/application/controllers/logbook.php b/application/controllers/logbook.php
index 477d8fbc..6965aa1a 100644
--- a/application/controllers/logbook.php
+++ b/application/controllers/logbook.php
@@ -351,6 +351,19 @@ class Logbook extends CI_Controller {
echo $json;
}
+ /*
+ * Provide a dxcc search, returning results json encoded
+ */
+ function local_find_dxcc($call = "", $date = "") {
+ $this->load->model("logbook_model");
+ if ($date == ''){
+ $date = date("Y-m-d");
+ }
+ $ans = $this->logbook_model->check_dxcc_stored_proc($call, $date);
+ print json_encode($ans);
+ }
+
+
/* return station bearing */
function bearing() {
$this->load->library('Qra');
diff --git a/application/logs/index.html b/application/logs/index.html
deleted file mode 100644
index 7f684dff..00000000
--- a/application/logs/index.html
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
- 403 Forbidden
-
-
-
-Directory access is forbidden.
-
-
-
diff --git a/application/migrations/013_add_dxcc_stored_proc.php b/application/migrations/013_add_dxcc_stored_proc.php
new file mode 100644
index 00000000..e490719d
--- /dev/null
+++ b/application/migrations/013_add_dxcc_stored_proc.php
@@ -0,0 +1,46 @@
+db->query("drop procedure if exists `find_country`");
+ if (!$res){
+ print ("Error dropping stored proc");
+ exit(0);
+ }
+
+ $sql = <<0 do
+ select `entity`, `adif` into country, dxcc_id
+ from dxcc_prefixes
+ where `call`= substring(callsign, 1, calllen)
+ and (`start` <= qso_date or `start`='0000-00-00')
+ and (`end` >= qso_date or `end`='0000-00-00');
+ if (FOUND_ROWS() >0) THEN
+ LEAVE L1;
+ else
+ set calllen = calllen - 1;
+ end IF;
+ end WHILE;
+end
+EOF;
+
+ $res = $this->db->query($sql);
+ if (!$res){
+ print ("Error setting stored proc");
+ exit(0);
+ }
+ }
+
+ public function down(){
+ $this->db->query("drop procedure if exists `find_country`");
+ }
+}
diff --git a/application/models/logbook_model.php b/application/models/logbook_model.php
index 3a628f35..ae715d72 100644
--- a/application/models/logbook_model.php
+++ b/application/models/logbook_model.php
@@ -967,6 +967,21 @@ class Logbook_model extends CI_Model {
return array("Not Found", "Not Found");
}
+ /*
+ * Same as check_dxcc_table, but the functionality is in
+ * a stored procedure which we call
+ */
+ public function check_dxcc_stored_proc($call, $date){
+ $this->db->query("call find_country('".$call."','".$date."', @country, @adif)");
+ $res = $this->db->query("select @country as country, @adif as adif");
+ $d = $res->result_array();
+
+ // Should only be one result.
+ // NOTE: might cause unexpected data if there's an
+ // error with clublog.org data.
+ return $d[0];
+ }
+
public function check_missing_dxcc_id($all){
// get all records with no COL_DXCC
$this->db->select("COL_PRIMARY_KEY, COL_CALL, COL_TIME_ON, COL_TIME_OFF");
@@ -986,8 +1001,12 @@ class Logbook_model extends CI_Model {
$qso_date = $row['COL_TIME_OFF']=='' ? $row['COL_TIME_ON'] : $row['COL_TIME_ON'];
$qso_date = strftime("%Y-%m-%d", strtotime($qso_date));
+ // Manual call
$d = $this->check_dxcc_table($row['COL_CALL'], $qso_date);
+ // Stored procedure call
+ //$d = $this->check_dxcc_stored_proc($row["COL_CALL"], $qso_date);
+
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'), addslashes(ucwords(strtolower($d[1]))), $d[0], $row['COL_PRIMARY_KEY']);
diff --git a/application/views/update/index.php b/application/views/update/index.php
index f8a64a7f..25be3943 100644
--- a/application/views/update/index.php
+++ b/application/views/update/index.php
@@ -8,8 +8,8 @@
Status:
- Check missing DXCC/Countries values
- [Re-Check ALL]
+ Check missing DXCC/Countries values
+ [Re-Check ALL]