From c9ff2eb900fd75c5482733861e1d0de43b16cb38 Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Sat, 19 Nov 2011 22:30:19 +0000 Subject: [PATCH] Added ADIF Features --- application/libraries/adif_parser.php | 115 ++++++++++++++++++++++ application/views/adif/import.php | 16 +++ application/views/adif/import_success.php | 6 ++ 3 files changed, 137 insertions(+) create mode 100644 application/libraries/adif_parser.php create mode 100644 application/views/adif/import.php create mode 100644 application/views/adif/import_success.php diff --git a/application/libraries/adif_parser.php b/application/libraries/adif_parser.php new file mode 100644 index 00000000..6352a369 --- /dev/null +++ b/application/libraries/adif_parser.php @@ -0,0 +1,115 @@ + + { + $pos = stripos($this->data, ""); + if($pos == false) //did we find the end of headers? + { + echo "Error: Adif_Parser Already Initialized or No in ADIF File"; + return 0; + }; + $this->i = $pos+5; //iterate past the + if($this->i >= strlen($this->data)) //is this the end of the file? + { + echo "Error: ADIF File Does Not Contain Any QSOs"; + return 0; + }; + return 1; + } + + public function feed($input_data) //allows the parser to be fed a string + { + $this->data = $input_data; + } + + public function load_from_file($fname) //allows the user to accept a filename as input + { + $this->data = file_get_contents($fname); + } + + //the following function does the processing of the array into its key and value pairs + public function record_to_array($record) + { + $return = array(); + for($a = 0; $a < strlen($record); $a++) + { + if($record[$a] == '<') //find the start of the tag + { + $tag_name = ""; + $value = ""; + $len_str = ""; + $len = 0; + $a++; //go past the < + while($record[$a] != ':') //get the tag + { + $tag_name = $tag_name.$record[$a]; //append this char to the tag name + $a++; + }; + $a++; //iterate past the colon + while($record[$a] != '>' && $record[$a] != ':') + { + $len_str = $len_str.$record[$a]; + $a++; + }; + if($record[$a] == ':') + { + while($record[$a] != '>') + { + $a++; + }; + }; + $a++; //iterate over the > + $len = (int)$len_str; + while($len > 0) + { + $value = $value.$record[$a]; + $len--; + $a++; + }; + $return[strtolower($tag_name)] = $value; + }; + }; + return $return; + } + + + //finds the next record in the file + public function get_record() + { + if($this->i >= strlen($this->data)) + { + return array(); //return nothing + }; + $end = stripos($this->data, "", $this->i); + if($end == false) //is this the end? + { + return array(); //return nothing + }; + $record = substr($this->data, $this->i, $end-$this->i); + $this->i = $end+5; + return $this->record_to_array($record); //process and return output + } +} +?> \ No newline at end of file diff --git a/application/views/adif/import.php b/application/views/adif/import.php new file mode 100644 index 00000000..58f62df5 --- /dev/null +++ b/application/views/adif/import.php @@ -0,0 +1,16 @@ +
+

+ + + + + + + +

+ + + + + +
diff --git a/application/views/adif/import_success.php b/application/views/adif/import_success.php new file mode 100644 index 00000000..7db3d229 --- /dev/null +++ b/application/views/adif/import_success.php @@ -0,0 +1,6 @@ +
+

ADIF Imported

+ +

The ADIF File has been imported, and any dupes skipped.

+ +