From 00cae77655489bbd245f80fc5d12c7c742e37d2f Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Thu, 22 Dec 2011 00:30:44 +0000 Subject: [PATCH] Updates to ADIF importing to add 59 to RST fields if there missing --- application/libraries/adif_parser.php | 99 +++++++++++++++++++++++++-- application/models/logbook_model.php | 17 ++++- 2 files changed, 110 insertions(+), 6 deletions(-) diff --git a/application/libraries/adif_parser.php b/application/libraries/adif_parser.php index b9bf531f..fbf711ae 100644 --- a/application/libraries/adif_parser.php +++ b/application/libraries/adif_parser.php @@ -1,5 +1,4 @@ { @@ -32,6 +31,76 @@ class ADIF_Parser echo "Error: Adif_Parser Already Initialized or No in ADIF File"; return 0; }; + + + //get headers + + $this->i = 0; + $in_tag = false; + $tag = ""; + $value_length = ""; + $value = ""; + + while($this->i < $pos) + { + //skip comments + if($this->data[$this->i] == "#") + { + while($this->i < $pos) + { + if($this->data[$this->i] == "\n") + { + break; + } + + $this->i++; + } + }else{ + //find the beginning of a tag + if($this->data[$this->i] == "<") + { + $this->i++; + //record the key + while($this->data[$this->i] < $pos && $this->data[$this->i] != ':') + { + $tag = $tag.$this->data[$this->i]; + $this->i++; + } + + $this->i++; //iterate past the : + + //find out how long the value is + + while($this->data[$this->i] < $pos && $this->data[$this->i] != '>') + { + $value_length = $value_length.$this->data[$this->i]; + $this->i++; + } + + $this->i++; //iterate past the > + + $len = (int)$value_length; + //copy the value into the buffer + while($len > 0 && $this->i < $pos) + { + $value = $value.$this->data[$this->i]; + $len--; + $this->i++; + }; + + $this->headers[strtolower(trim($tag))] = $value; //convert it to lowercase and trim it in case of \r + //clear all of our variables + $tag = ""; + $value_length = ""; + $value = ""; + + } + } + + $this->i++; + + }; + $this->i = $pos+5; //iterate past the if($this->i >= strlen($this->data)) //is this the end of the file? { @@ -82,16 +151,27 @@ class ADIF_Parser $a++; }; }; - $a++; //iterate over the > $len = (int)$len_str; while($len > 0) { + $a++; $value = $value.$record[$a]; $len--; - $a++; }; $return[strtolower($tag_name)] = $value; }; + //skip comments + if($record[$a] == "#") + { + while($a < strlen($record)) + { + if($record[$a] == "\n") + { + break; + } + $a++; + } + } }; return $return; } @@ -113,5 +193,16 @@ class ADIF_Parser $this->i = $end+5; return $this->record_to_array($record); //process and return output } + + public function get_header($key) + { + if(array_key_exists(strtolower($key), $this->headers)) + { + return $this->headers[strtolower($key)]; + }else{ + return NULL; + } + } + } ?> \ No newline at end of file diff --git a/application/models/logbook_model.php b/application/models/logbook_model.php index 4ca90f00..6dcb4690 100644 --- a/application/models/logbook_model.php +++ b/application/models/logbook_model.php @@ -512,6 +512,19 @@ class Logbook_model extends CI_Model { } + if(isset($record['rst_rcvd'])) { + $rst_rx = $record['rst_rcvd']; + } else { + $rst_rx = "59" ; + } + + if(isset($record['rst_sent'])) { + $rst_tx = $record['rst_sent']; + } else { + $rst_tx = "59" ; + } + + $this->db->where('COL_CALL', $record['call']); $this->db->where('COL_TIME_ON', $time_on); $check = $this->db->get($this->config->item('table_name')); @@ -526,8 +539,8 @@ class Logbook_model extends CI_Model { 'COL_BAND' => $record['band'], 'COL_FREQ' => $freq, 'COL_MODE' => $record['mode'], - 'COL_RST_RCVD' => $record['rst_rcvd'], - 'COL_RST_SENT' => $record['rst_sent'], + 'COL_RST_RCVD' => $rst_rx, + 'COL_RST_SENT' => $rst_tx, 'COL_NAME' => $name, 'COL_COMMENT' => $comment, 'COL_SAT_NAME' => $sat_name,