kopia lustrzana https://github.com/magicbug/Cloudlog
Stored Proc for DXCC info
rodzic
3459a81098
commit
35363f2374
|
@ -21,7 +21,7 @@ $config['migration_enabled'] = TRUE;
|
||||||
| be upgraded / downgraded to.
|
| be upgraded / downgraded to.
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
$config['migration_version'] = 12;
|
$config['migration_version'] = 13;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -351,6 +351,19 @@ class Logbook extends CI_Controller {
|
||||||
echo $json;
|
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 */
|
/* return station bearing */
|
||||||
function bearing() {
|
function bearing() {
|
||||||
$this->load->library('Qra');
|
$this->load->library('Qra');
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>403 Forbidden</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
<p>Directory access is forbidden.</p>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||||
|
|
||||||
|
class Migration_add_dxcc_stored_proc extends CI_Migration {
|
||||||
|
|
||||||
|
public function up(){
|
||||||
|
$res = $this->db->query("drop procedure if exists `find_country`");
|
||||||
|
if (!$res){
|
||||||
|
print ("Error dropping stored proc");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = <<<EOF
|
||||||
|
CREATE PROCEDURE `find_country`(
|
||||||
|
IN callsign varchar(10),
|
||||||
|
IN qso_date date,
|
||||||
|
OUT country varchar(255),
|
||||||
|
OUT dxcc_id int)
|
||||||
|
begin
|
||||||
|
declare calllen int default 0;
|
||||||
|
set calllen = char_length(callsign);
|
||||||
|
L1: while calllen >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`");
|
||||||
|
}
|
||||||
|
}
|
|
@ -967,6 +967,21 @@ class Logbook_model extends CI_Model {
|
||||||
return array("Not Found", "Not Found");
|
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){
|
public function check_missing_dxcc_id($all){
|
||||||
// get all records with no COL_DXCC
|
// get all records with no COL_DXCC
|
||||||
$this->db->select("COL_PRIMARY_KEY, COL_CALL, COL_TIME_ON, COL_TIME_OFF");
|
$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 = $row['COL_TIME_OFF']=='' ? $row['COL_TIME_ON'] : $row['COL_TIME_ON'];
|
||||||
$qso_date = strftime("%Y-%m-%d", strtotime($qso_date));
|
$qso_date = strftime("%Y-%m-%d", strtotime($qso_date));
|
||||||
|
|
||||||
|
// Manual call
|
||||||
$d = $this->check_dxcc_table($row['COL_CALL'], $qso_date);
|
$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'){
|
if ($d[0] != 'Not Found'){
|
||||||
$sql = sprintf("update %s set COL_COUNTRY = '%s', COL_DXCC='%s' where COL_PRIMARY_KEY=%d",
|
$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']);
|
$this->config->item('table_name'), addslashes(ucwords(strtolower($d[1]))), $d[0], $row['COL_PRIMARY_KEY']);
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
Status:</br>
|
Status:</br>
|
||||||
</div>
|
</div>
|
||||||
<br/>
|
<br/>
|
||||||
<a href="update/check_missing_dxcc">Check missing DXCC/Countries values</a>
|
<a href="check_missing_dxcc">Check missing DXCC/Countries values</a>
|
||||||
<a href="update/check_missing_dxcc/all">[Re-Check ALL]</a>
|
<a href="check_missing_dxcc/all">[Re-Check ALL]</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
Ładowanie…
Reference in New Issue