From cabe79a664c29edc08be15484f1b2f7d5c0f8df1 Mon Sep 17 00:00:00 2001 From: Michael Bridak <49108421+mbridak@users.noreply.github.com> Date: Fri, 12 Jun 2020 18:11:42 -0700 Subject: [PATCH] Fix calls showing in the wrong dxcc region. Added checks to dxcc_exceptons. --- application/models/Logbook_model.php | 33 +++++++++++++++++++--------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/application/models/Logbook_model.php b/application/models/Logbook_model.php index c8b903b2..31bdb54c 100755 --- a/application/models/Logbook_model.php +++ b/application/models/Logbook_model.php @@ -1915,6 +1915,18 @@ class Logbook_model extends CI_Model { public function check_dxcc_table($call, $date){ $len = strlen($call); + $dxcc_exceptions = $this->db->select('`entity`, `adif`, `cqz`') + ->where('call', $call) + ->where('(start <= ', $date) + ->or_where('start is null)', NULL, false) + ->where('(end >= ', $date) + ->or_where('end is null)', NULL, false) + ->get('dxcc_exceptions'); + + if ($dxcc_exceptions->num_rows() > 0){ + $row = $dxcc_exceptions->row_array(); + return array($row['adif'], $row['entity'], $row['cqz']); + } // 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)); @@ -1940,18 +1952,19 @@ class Logbook_model extends CI_Model { public function dxcc_lookup($call, $date){ $len = strlen($call); - - $this->db->where('call', $call); - $this->db->where('CURDATE() between start and end'); - - $query = $this->db->get('dxcc_exceptions'); + + $dxcc_exceptions = $this->db->select('`entity`, `adif`, `cqz`') + ->where('call', $call) + ->where('(start <= CURDATE()') + ->or_where('start is null', NULL, false) + ->where('end >= CURDATE()') + ->or_where('end is null)', NULL, false) + ->get('dxcc_exceptions'); - if ($query->num_rows() > 0){ - - $row = $query->row_array(); - - return $row; + if ($dxcc_exceptions->num_rows() > 0){ + $row = $dxcc_exceptions->row_array(); + return $row; } else { // query the table, removing a character from the right until a match for ($i = $len; $i > 0; $i--){