예제 #1
0
 public function deleteSpecies($tid)
 {
     if (is_numeric($tid)) {
         $sql = 'UPDATE taxa t SET t.SecurityStatus = 0 WHERE (t.tid = ' . $tid . ')';
         //echo $sql;
         $this->con->query($sql);
         //Update specimen records
         $sql2 = 'UPDATE omoccurrences o INNER JOIN taxstatus ts1 ON o.tidinterpreted = ts1.tid ' . 'INNER JOIN taxstatus ts2 ON ts1.tidaccepted = ts2.tidaccepted ' . 'INNER JOIN taxa t ON ts2.tid = t.tid ' . 'SET o.LocalitySecurity = 0 ' . 'WHERE (t.tid = ' . $tid . ')';
         //echo $sql2; exit;
         $this->con->query($sql2);
         $occurUtil = new OccurrenceUtilities();
         $occurUtil->protectGloballyRareSpecies();
     }
 }
 public function getComments($collid, $start, $limit, $tsStart, $tsEnd, $uid, $rs)
 {
     $retArr = array();
     if ($collid) {
         $sqlBase = 'FROM omoccurcomments c INNER JOIN omoccurrences o ON c.occid = o.occid ' . 'WHERE o.collid = ' . $collid;
         if ($uid) {
             $sqlBase .= ' AND uid = ' . $uid;
         }
         if (is_numeric($rs)) {
             $sqlBase .= ' AND reviewstatus = ' . $rs;
         }
         if ($tsStart) {
             $tsStartStr = OccurrenceUtilities::formatDate($tsStart);
             if ($tsStartStr) {
                 $sqlBase .= ' AND initialtimestamp >= ' . $tsStartStr;
             }
         }
         if ($tsEnd) {
             $tsEndStr = OccurrenceUtilities::formatDate($tsEnd);
             if ($tsEndStr) {
                 $sqlBase .= ' AND initialtimestamp < ' . $tsEndStr;
             }
         }
         //Get count
         $sqlCnt = 'SELECT count(c.comid) as cnt ' . $sqlBase;
         $rsCnt = $this->conn->query($sqlCnt);
         while ($rCnt = $rsCnt->fetch_object()) {
             $retArr['cnt'] = $rCnt->cnt;
         }
         $rsCnt->free();
         //Get records
         $sql = 'SELECT c.comid, c.occid, c.comment, c.uid, c.reviewstatus, c.parentcomid, c.initialtimestamp ' . $sqlBase . ' ORDER BY initialtimestamp DESC LIMIT ' . $start . ',' . $limit;
         //echo $sql; exit;
         $rs = $this->conn->query($sql);
         while ($r = $rs->fetch_object()) {
             $retArr[$r->comid]['str'] = $r->comment;
             $retArr[$r->comid]['occid'] = $r->occid;
             $retArr[$r->comid]['uid'] = $r->uid;
             $retArr[$r->comid]['rs'] = $r->reviewstatus;
             $retArr[$r->comid]['ts'] = $r->initialtimestamp;
         }
         $rs->free();
     }
     return $retArr;
 }
예제 #3
0
 private function DateFromOneLine($Field, $L, $Partial = false)
 {
     //Checks several formats
     $RomanMonths = array("I" => "Jan", "II" => "Feb", "III" => "Mar", "IV" => "Apr", "V" => "May", "VI" => "Jun", "VII" => "Jul", "VIII" => "Aug", "IX" => "Sep", "X" => "Oct", "XI" => "Nov", "XII" => "Dec");
     $match = array();
     $RealVDate = "";
     $VDate = "";
     $TempString = $this->LabelLines[$L];
     //Reformat expressions like:  "23 de abril de 1956" to "23 abril 1956"
     $TempString = preg_replace("((\\d{1,2})\\sde\\s({$this->PregMonths})[\\sde]{0,3}\\s(\\d{2,4}))", "\$1 \$2 \$5", $TempString);
     //echo "Getting date from {$this->LabelLines[$L]}<br>";
     if ($Partial) {
         $Preg = "(\\b{$this->PregMonths}\\s*(\\b[0-9]{1,4}\\b))i";
     } else {
         $Preg = "((\\b[0-9]{1,4}\\b)\\s*{$this->PregMonths}[.,]*\\s*(\\b[0-9]{1,4}\\b))i";
     }
     $Found = preg_match($Preg, $TempString, $match);
     if ($Found !== 1) {
         //Format April 21, 1929
         $Preg = "({$this->PregMonths}[.\\s]*(\\b[0-9]{1,4}\\b)[.,]*\\s*(\\b[0-9]{1,4}\\b)\\s*)i";
         $Found = preg_match($Preg, $TempString, $match);
         if ($Found) {
             $VDate = $match[2] . " " . $match[3] . ", " . $match[4];
             $RealVDate = $match[0];
         }
     }
     if ($Found !== 1) {
         //Format April, 1929
         $Preg = "({$this->PregMonths}[.,]?\\s*(\\b[0-9]{1,4}\\b)\\s*)i";
         $Found = preg_match($Preg, $TempString, $match);
     }
     if ($Found !== 0) {
         if ($VDate == "") {
             $VDate = $match[0];
             $RealVDate = $VDate;
         }
     }
     if ($Found == 0) {
         //Roman numeral for month
         $Preg = "(([0-9]+[ ./-]{1,2})([IVX]+)([ ./-]{1,2}[0-9]+))i";
         $Found = preg_match($Preg, $TempString, $match);
         if ($Found > 0) {
             $Month = $RomanMonths[strtoupper($match[2])];
             $VDate = trim($match[1], " .-") . "-" . $Month . "-" . trim($match[3], " .-");
             $RealVDate = $match[0];
         }
     }
     if ($Found == 0) {
         //Day-AlphaMonth-Year
         $Preg = "(([0-9]+[ ./-]{1,2}){$this->PregMonths}([ ./-]{1,2}[0-9]{2,4}))i";
         $Found = preg_match($Preg, $TempString, $match);
         if ($Found > 0) {
             //$this->printr($match,"Day-Month-Year");
             $VDate = trim(str_replace("-", " ", $match[0]));
             $RealVDate = $match[0];
         }
     }
     if ($Found == 0) {
         // day-month-year all numeric
         //echo "Checking $TempString: <br>";
         $Preg = "(\\b([0-9]{1,2})[ ./-]+([0-9]{1,2})[ ./-]+([0-9]{2,4})\\b)";
         $Found = preg_match($Preg, $TempString, $match);
         if ($Found !== 0) {
             //echo "Found {$match[0]}<br>";
             $VDate = $match[0];
             $RealVDate = $VDate;
         }
     }
     if ($Found == 0) {
         $Preg = "(\\b(19[0-9]{2,2}|20[01][0-9])\\b)";
         $Found = preg_match($Preg, $TempString, $match);
         if ($Found !== 0) {
             //echo "Found {$match[0]}<br>";
             $VDate = $match[0];
             $RealVDate = $VDate;
         }
     }
     if ($Found !== 0) {
         $FrenchMonths = array("janvier", "febrier", "mars", "avril", "mai", "juin", "juillet", "aout", "septembre", "octobre", "novembre", "decembre");
         $VDate = str_replace($FrenchMonths, $RomanMonths, $VDate);
         //Converts french dates to English (Using the same Roman Numeral conversion array)
         $OU = new OccurrenceUtilities();
         $FormattedDate = $OU->formatDate($VDate);
         if ($FormattedDate != "") {
             $FoundYear = preg_match("((\\d{4,4})\\-)", $FormattedDate, $match);
             //$this->printr($match,"FormattedDate");
             if ($match[1] > 2020 || $match[1] < 1700) {
                 return false;
             }
             $this->AddToResults($Field, $FormattedDate, $L);
             if ($RealVDate != "") {
                 $VDate = $RealVDate;
             }
             $this->LabelLines[$L] = str_replace($VDate, "", $this->LabelLines[$L]);
             if ($Field == "eventDate") {
                 $this->AddToResults("verbatimEventDate", $VDate, $L);
             }
             $this->RemoveStartWords($L, $Field);
             return true;
         }
     }
     return;
 }
<?php

date_default_timezone_set('America/Phoenix');
require_once '../../config/symbini.php';
require_once $serverRoot . '/classes/OccurrenceUtilities.php';
$assocHandler = new OccurrenceUtilities();
$assocHandler->buildAssociatedTaxaIndex(1);
예제 #5
0
 private function formatDate($inDate)
 {
     $retDate = OccurrenceUtilities::formatDate($inDate);
     return $retDate;
 }
예제 #6
0
 public static function parseVerbatimCoordinates($inStr, $target = '')
 {
     $retArr = array();
     if (strpos($inStr, ' to ')) {
         return $retArr;
     }
     if (strpos($inStr, ' betw ')) {
         return $retArr;
     }
     //Get rid of curly quotes
     $search = array("’", "‘", "`", "”", "“");
     $replace = array("'", "'", "'", '"', '"');
     $inStr = str_replace($search, $replace, $inStr);
     //Try to parse lat/lng
     $latDeg = 'null';
     $latMin = 0;
     $latSec = 0;
     $latNS = 'N';
     $lngDeg = 'null';
     $lngMin = 0;
     $lngSec = 0;
     $lngEW = 'W';
     //Grab lat deg and min
     if (!$target || $target == 'LL') {
         if (preg_match('/([\\sNSns]{0,1})(-?\\d{1,2}\\.{1}\\d+)\\D{0,1}\\s{0,1}([NSns]{0,1})\\D{0,1}([\\sEWew]{1})(-?\\d{1,4}\\.{1}\\d+)\\D{0,1}\\s{0,1}([EWew]{0,1})\\D*/', $inStr, $m)) {
             //Decimal degree format
             $retArr['lat'] = $m[2];
             $retArr['lng'] = $m[5];
             $latDir = $m[3];
             if (!$latDir && $m[1]) {
                 $latDir = trim($m[1]);
             }
             if ($retArr['lat'] > 0 && $latDir && ($latDir == 'S' || $latDir == 's')) {
                 $retArr['lat'] = -1 * $retArr['lat'];
             }
             $lngDir = $m[6];
             if (!$lngDir && $m[4]) {
                 $lngDir = trim($m[4]);
             }
             if ($retArr['lng'] > 0 && $latDir && ($lngDir == 'W' || $lngDir == 'w')) {
                 $retArr['lng'] = -1 * $retArr['lng'];
             }
         } elseif (preg_match('/(\\d{1,2})\\D{1,3}\\s{0,2}(\\d{1,2}\\.{0,1}\\d*)[\'m]{1}(.*)/i', $inStr, $m)) {
             //DMS format
             $latDeg = $m[1];
             $latMin = $m[2];
             $leftOver = str_replace("''", '"', trim($m[3]));
             //Grab lat NS and lng EW
             if (stripos($inStr, 'N') === false && strpos($inStr, 'S') !== false) {
                 $latNS = 'S';
             }
             if (stripos($inStr, 'W') === false && stripos($inStr, 'E') !== false) {
                 $lngEW = 'E';
             }
             //Grab lat sec
             if (preg_match('/^(\\d{1,2}\\.{0,1}\\d*)["s]{1}(.*)/i', $leftOver, $m)) {
                 $latSec = $m[1];
                 if (count($m) > 2) {
                     $leftOver = trim($m[2]);
                 }
             }
             //Grab lng deg and min
             if (preg_match('/(\\d{1,3})\\D{1,3}\\s{0,2}(\\d{1,2}\\.{0,1}\\d*)[\'m]{1}(.*)/i', $leftOver, $m)) {
                 $lngDeg = $m[1];
                 $lngMin = $m[2];
                 $leftOver = trim($m[3]);
                 //Grab lng sec
                 if (preg_match('/^(\\d{1,2}\\.{0,1}\\d*)["s]{1}(.*)/i', $leftOver, $m)) {
                     $lngSec = $m[1];
                     if (count($m) > 2) {
                         $leftOver = trim($m[2]);
                     }
                 }
                 if (is_numeric($latDeg) && is_numeric($latMin) && is_numeric($lngDeg) && is_numeric($lngMin)) {
                     if ($latDeg < 90 && $latMin < 60 && $lngDeg < 180 && $lngMin < 60) {
                         $latDec = $latDeg + $latMin / 60 + $latSec / 3600;
                         $lngDec = $lngDeg + $lngMin / 60 + $lngSec / 3600;
                         if ($latNS == 'S') {
                             $latDec = -$latDec;
                         }
                         if ($lngEW == 'W') {
                             $lngDec = -$lngDec;
                         }
                         $retArr['lat'] = round($latDec, 6);
                         $retArr['lng'] = round($lngDec, 6);
                     }
                 }
             }
         }
     }
     if (!$target && !$retArr || $target == 'UTM') {
         //UTM parsing
         $d = '';
         if (preg_match('/NAD\\s*27/i', $inStr)) {
             $d = 'NAD27';
         }
         if (preg_match('/\\D*(\\d{1,2}\\D{0,1})\\s+(\\d{6,7})E\\s+(\\d{7})N/i', $inStr, $m)) {
             $z = $m[1];
             $e = $m[2];
             $n = $m[3];
             if ($n && $e && $z) {
                 $llArr = OccurrenceUtilities::convertUtmToLL($e, $n, $z, $d);
                 if (isset($llArr['lat'])) {
                     $retArr['lat'] = $llArr['lat'];
                 }
                 if (isset($llArr['lng'])) {
                     $retArr['lng'] = $llArr['lng'];
                 }
             }
         } elseif (preg_match('/UTM/', $inStr) || preg_match('/\\d{1,2}[\\D\\s]+\\d{6,7}[\\D\\s]+\\d{6,7}/', $inStr)) {
             //UTM
             $z = '';
             $e = '';
             $n = '';
             if (preg_match('/^(\\d{1,2}\\D{0,1})[\\s\\D]+/', $inStr, $m)) {
                 $z = $m[1];
             }
             if (!$z && preg_match('/[\\s\\D]+(\\d{1,2}\\D{0,1})$/', $inStr, $m)) {
                 $z = $m[1];
             }
             if (!$z && preg_match('/[\\s\\D]+(\\d{1,2}\\D{0,1})[\\s\\D]+/', $inStr, $m)) {
                 $z = $m[1];
             }
             if ($z) {
                 if (preg_match('/(\\d{6,7})E{1}[\\D\\s]+(\\d{7})N{1}/i', $inStr, $m)) {
                     $e = $m[1];
                     $n = $m[2];
                 } elseif (preg_match('/E{1}(\\d{6,7})[\\D\\s]+N{1}(\\d{7})/i', $inStr, $m)) {
                     $e = $m[1];
                     $n = $m[2];
                 } elseif (preg_match('/(\\d{7})N{1}[\\D\\s]+(\\d{6,7})E{1}/i', $inStr, $m)) {
                     $e = $m[2];
                     $n = $m[1];
                 } elseif (preg_match('/N{1}(\\d{7})[\\D\\s]+E{1}(\\d{6,7})/i', $inStr, $m)) {
                     $e = $m[2];
                     $n = $m[1];
                 } elseif (preg_match('/(\\d{6})[\\D\\s]+(\\d{7})/', $inStr, $m)) {
                     $e = $m[1];
                     $n = $m[2];
                 } elseif (preg_match('/(\\d{7})[\\D\\s]+(\\d{6})/', $inStr, $m)) {
                     $e = $m[2];
                     $n = $m[1];
                 }
                 if ($e && $n) {
                     $llArr = OccurrenceUtilities::convertUtmToLL($e, $n, $z, $d);
                     if (isset($llArr['lat'])) {
                         $retArr['lat'] = $llArr['lat'];
                     }
                     if (isset($llArr['lng'])) {
                         $retArr['lng'] = $llArr['lng'];
                     }
                 }
             }
         }
     }
     //Clean
     if ($retArr) {
         if ($retArr['lat'] < -90 || $retArr['lat'] > 90) {
             return;
         }
         if ($retArr['lng'] < -180 || $retArr['lng'] > 180) {
             return;
         }
     }
     return $retArr;
 }
예제 #7
0
 public static function convertUtmToLL($e, $n, $z, $d)
 {
     return OccurrenceUtilities::convertUtmToLL($e, $n, $z, $d);
 }
예제 #8
0
 private function cleanHouse($collList)
 {
     $this->logOrEcho('Updating collection statistics...', 1);
     $occurUtil = new OccurrenceUtilities();
     $this->logOrEcho('General cleaning...', 2);
     $collString = implode(',', $collList);
     if (!$occurUtil->generalOccurrenceCleaning($collString)) {
         $errorArr = $occurUtil->getErrorArr();
         foreach ($errorArr as $errorStr) {
             $this->logOrEcho($errorStr, 1);
         }
     }
     $this->logOrEcho('Protecting sensitive species...', 2);
     if (!$occurUtil->protectRareSpecies()) {
         $errorArr = $occurUtil->getErrorArr();
         foreach ($errorArr as $errorStr) {
             $this->logOrEcho($errorStr, 1);
         }
     }
     if ($collList) {
         $this->logOrEcho('Updating collection statistics...', 2);
         foreach ($collList as $collid) {
             if (!$occurUtil->updateCollectionStats($collid)) {
                 $errorArr = $occurUtil->getErrorArr();
                 foreach ($errorArr as $errorStr) {
                     $this->logOrEcho($errorStr, 1);
                 }
             }
         }
     }
     $this->logOrEcho('Populating global unique identifiers (GUIDs) for all records...', 2);
     $uuidManager = new UuidFactory();
     $uuidManager->setSilent(1);
     $uuidManager->populateGuids();
 }
 private function updateCollectionStats()
 {
     if ($this->dbMetadata) {
         //Do some more cleaning of the data after it haas been indexed in the omoccurrences table
         $occurUtil = new OccurrenceUtilities();
         $this->logOrEcho('Cleaning house...');
         if (!$occurUtil->generalOccurrenceCleaning()) {
             $errorArr = $occurUtil->getErrorArr();
             foreach ($errorArr as $errorStr) {
                 $this->logOrEcho($errorStr, 1);
             }
         }
         $this->logOrEcho('Protecting sensitive species...');
         if (!$occurUtil->protectRareSpecies()) {
             $errorArr = $occurUtil->getErrorArr();
             foreach ($errorArr as $errorStr) {
                 $this->logOrEcho($errorStr, 1);
             }
         }
         $this->logOrEcho('Updating statistics...');
         foreach ($this->collProcessedArr as $collid) {
             if (!$occurUtil->updateCollectionStats($collid)) {
                 $errorArr = $occurUtil->getErrorArr();
                 foreach ($errorArr as $errorStr) {
                     $this->logOrEcho($errorStr, 1);
                 }
             }
         }
         $this->logOrEcho('Populating global unique identifiers (GUIDs) for all records...');
         $uuidManager = new UuidFactory();
         $uuidManager->setSilent(1);
         $uuidManager->populateGuids();
     }
     $this->logOrEcho("Stats update completed");
 }
예제 #10
0
 public function setDwcArr($dwcObj)
 {
     $recArr = json_decode($dwcObj, true);
     if ($recArr) {
         $recArr = array_change_key_case($recArr);
         //Translate fields
         foreach ($this->fieldTranslation as $otherName => $symbName) {
             if (array_key_exists($otherName, $recArr) && !array_key_exists($symbName, $recArr)) {
                 $recArr[$symbName] = $recArr[$otherName];
                 unset($recArr[$otherName]);
             }
         }
         //Filter out unapproved fields
         $recArr = array_intersect_key($recArr, array_flip($this->approvedFields));
         $this->dwcArr = OccurrenceUtilities::occurrenceArrayCleaning($recArr);
         if ($this->dwcArr) {
             return true;
         }
     }
     return false;
 }
 public function batchUpdateStatistics($collId)
 {
     echo 'Updating collection statistics...';
     echo '<ul>';
     //echo '<li>General cleaning in preparation for collecting stats... </li>';
     flush();
     ob_flush();
     $occurUtil = new OccurrenceUtilities();
     //$occurUtil->generalOccurrenceCleaning();
     $sql = 'SELECT collid, collectionname FROM omcollections WHERE collid IN(' . $collId . ') ';
     //echo $sql;
     $rs = $this->conn->query($sql);
     while ($r = $rs->fetch_object()) {
         echo '<li style="margin-left:15px;">Cleaning statistics for: ' . $r->collectionname . '</li>';
         flush();
         ob_flush();
         $occurUtil->updateCollectionStats($r->collid, true);
     }
     $rs->free();
     echo '<li>Statistics update complete!</li>';
     echo '</ul>';
     flush();
     ob_flush();
 }
예제 #12
0
 public function getHierarchyEntries($id, $includeSynonyms = true, $includeCommonNames = true, $includeParents = true)
 {
     //http://eol.org/api/docs/hierarchy_entries
     //http://eol.org/api/hierarchy_entries/1.0/52595368.json?common_names=true&synonyms=true&cache_ttl=
     $taxonArr = array();
     if ($id) {
         //Get taxonomy
         $url = 'http://eol.org/api/hierarchy_entries/1.0/' . $id . '.json?common_names=' . ($includeCommonNames ? 'true' : 'false') . '&synonyms=' . ($includeSynonyms ? 'true' : 'false');
         //echo $url; exit;
         if ($fh = fopen($url, 'r')) {
             $content = "";
             while ($line = fread($fh, 1024)) {
                 $content .= trim($line);
             }
             fclose($fh);
             //Process return
             $eolObj = json_decode($content);
             if ($eolObj->scientificName) {
                 $taxonArr = OccurrenceUtilities::parseScientificName($eolObj->scientificName);
                 $taxonArr['scientificName'] = $eolObj->scientificName;
                 $taxonArr['taxonRank'] = $eolObj->taxonRank;
                 if (isset($eolObj->nameAccordingTo)) {
                     $taxonArr['source'] = $eolObj->nameAccordingTo[0];
                 }
                 if (isset($eolObj->source)) {
                     $taxonArr['sourceURL'] = $eolObj->source;
                 }
                 //Add synonyms
                 if ($includeSynonyms) {
                     $synonyms = $eolObj->synonyms;
                     foreach ($synonyms as $synObj) {
                         $taxonArr['syns'][] = array('scientificName' => $synObj->scientificName, 'synreason' => $synObj->taxonomicStatus);
                     }
                 }
                 //Add vernaculars
                 if ($includeCommonNames) {
                     $vernacularNames = $eolObj->vernacularNames;
                     foreach ($vernacularNames as $vernObj) {
                         if (in_array($vernObj->language, $this->targetLanguages)) {
                             $taxonArr['verns'][] = array('language' => $vernObj->language, 'vernacularName' => $vernObj->vernacularName);
                         }
                     }
                 }
                 //Process ancestors
                 if ($eolObj->ancestors && $eolObj->parentNameUsageID) {
                     $ancArr = array_reverse((array) $eolObj->ancestors);
                     $parArr = $this->getParentArray($ancArr, $eolObj->parentNameUsageID);
                     if ($parArr) {
                         $taxonArr['parent'] = $parArr;
                     }
                 }
                 $taxonArr['id'] = $id;
             }
         } else {
             $this->errorStr = 'ERROR opening EOL hierarchy url: ' . $url;
         }
     } else {
         $this->errorStr = "Input ID is null";
         return false;
     }
     return $taxonArr;
 }
예제 #13
0
 public function parseSciName($scientificName, $rankId = 0)
 {
     //Converts scinetific name with author embedded into separate fields
     $retArr = array();
     $retArr = OccurrenceUtilities::parseScientificName($scientificName, $rankId);
     return $retArr;
 }
예제 #14
0
 private function getSqlFragments($recMap, $fieldMap)
 {
     $sqlFields = '';
     $sqlValues = '';
     foreach ($recMap as $symbField => $valueStr) {
         if (substr($symbField, 0, 8) != 'unmapped') {
             $sqlFields .= ',' . $symbField;
             $valueStr = $this->encodeString($valueStr);
             $valueStr = $this->cleanInStr($valueStr);
             //Load data
             $type = '';
             $size = 0;
             if (array_key_exists($symbField, $fieldMap)) {
                 if (array_key_exists('type', $fieldMap[$symbField])) {
                     $type = $fieldMap[$symbField]["type"];
                 }
                 if (array_key_exists('size', $fieldMap[$symbField])) {
                     $size = $fieldMap[$symbField]["size"];
                 }
             }
             switch ($type) {
                 case "numeric":
                     if (is_numeric($valueStr)) {
                         $sqlValues .= "," . $valueStr;
                     } elseif (is_numeric(str_replace(',', "", $valueStr))) {
                         $sqlValues .= "," . str_replace(',', "", $valueStr);
                     } else {
                         $sqlValues .= ",NULL";
                     }
                     break;
                 case "decimal":
                     if (strpos($valueStr, ',')) {
                         $sqlValues = str_replace(',', '', $valueStr);
                     }
                     if ($valueStr && $size && strpos($size, ',') !== false) {
                         $tok = explode(',', $size);
                         $m = $tok[0];
                         $d = $tok[1];
                         if ($m && $d) {
                             $dec = substr($valueStr, strpos($valueStr, '.'));
                             if (strlen($dec) > $d) {
                                 $valueStr = round($valueStr, $d);
                             }
                             $rawLen = strlen(str_replace(array('-', '.'), '', $valueStr));
                             if ($rawLen > $m) {
                                 if (strpos($valueStr, '.') !== false) {
                                     $decLen = strlen(substr($valueStr, strpos($valueStr, '.')));
                                     if ($decLen < $rawLen - $m) {
                                         $valueStr = '';
                                     } else {
                                         $valueStr = round($valueStr, $decLen - ($rawLen - $m));
                                     }
                                 } else {
                                     $valueStr = '';
                                 }
                             }
                         }
                     }
                     if (is_numeric($valueStr)) {
                         $sqlValues .= "," . $valueStr;
                     } else {
                         $sqlValues .= ",NULL";
                     }
                     break;
                 case "date":
                     $dateStr = OccurrenceUtilities::formatDate($valueStr);
                     if ($dateStr) {
                         $sqlValues .= ',"' . $dateStr . '"';
                     } else {
                         $sqlValues .= ",NULL";
                     }
                     break;
                 default:
                     //string
                     if ($size && strlen($valueStr) > $size) {
                         $valueStr = substr($valueStr, 0, $size);
                     }
                     if (substr($valueStr, -1) == "\\") {
                         $valueStr = rtrim($valueStr, "\\");
                     }
                     if ($valueStr) {
                         $sqlValues .= ',"' . $valueStr . '"';
                     } else {
                         $sqlValues .= ",NULL";
                     }
             }
         }
     }
     return array('fieldstr' => $sqlFields, 'valuestr' => $sqlValues);
 }
예제 #15
0
 public function uploadCsvList($hasHeader, $thesId)
 {
     set_time_limit(300);
     ini_set("max_input_time", 300);
     ini_set('auto_detect_line_endings', true);
     $successCnt = 0;
     $fh = fopen($_FILES['uploadfile']['tmp_name'], 'r') or die("Can't open file. File may be too large. Try uploading file in sections.");
     $headerArr = array();
     if ($hasHeader) {
         $headerData = fgetcsv($fh);
         foreach ($headerData as $k => $v) {
             $vStr = strtolower($v);
             $vStr = str_replace(array(" ", ".", "_"), "", $vStr);
             $vStr = str_replace(array("scientificnamewithauthor", "scientificname", "taxa", "species", "taxon"), "sciname", $vStr);
             $headerArr[$vStr] = $k;
         }
     } else {
         $headerArr["sciname"] = 0;
     }
     if (array_key_exists("sciname", $headerArr)) {
         $cnt = 0;
         ob_flush();
         flush();
         $taxUtil = new TaxonomyUtilities();
         while ($valueArr = fgetcsv($fh)) {
             $tid = 0;
             $rankId = 0;
             $sciName = "";
             $family = "";
             $sciNameStr = $this->cleanInStr($valueArr[$headerArr["sciname"]]);
             $noteStr = '';
             if ($sciNameStr) {
                 $sciNameArr = $taxUtil->parseSciName($sciNameStr);
                 //Check name is in taxa table and grab tid if it is
                 $sql = "";
                 if ($thesId && is_numeric($thesId)) {
                     $sql = 'SELECT t2.tid, ts.family, t2.rankid ' . 'FROM (taxa t INNER JOIN taxstatus ts ON t.tid = ts.tid) ' . 'INNER JOIN taxa t2 ON ts.tidaccepted = t2.tid ' . 'WHERE (ts.taxauthid = ' . $thesId . ') ';
                 } else {
                     $sql = 'SELECT t.tid, ts.family, t.rankid ' . 'FROM taxa t INNER JOIN taxstatus ts ON t.tid = ts.tid ' . 'WHERE ts.taxauthid = 1 ';
                 }
                 $cleanSciName = $this->encodeString($sciNameArr['sciname']);
                 $sql .= 'AND (t.sciname IN("' . $sciNameStr . '"' . ($cleanSciName ? ',"' . $cleanSciName . '"' : '') . '))';
                 $rs = $this->conn->query($sql);
                 if ($rs) {
                     if ($row = $rs->fetch_object()) {
                         $tid = $row->tid;
                         $family = $row->family;
                         $rankId = $row->rankid;
                     }
                     $rs->free();
                 }
                 //Load taxon into checklist
                 if ($tid) {
                     if ($rankId >= 180) {
                         $sqlInsert = '';
                         $sqlValues = '';
                         if (array_key_exists('family', $headerArr) && ($valueArr[$headerArr['family']] && strtolower($family) != strtolower($valueArr[$headerArr['family']]))) {
                             $sqlInsert .= ',familyoverride';
                             $sqlValues .= ',"' . $this->cleanInStr($valueArr[$headerArr['family']]) . '"';
                         }
                         if (array_key_exists('habitat', $headerArr) && $valueArr[$headerArr['habitat']]) {
                             $sqlInsert .= ',habitat';
                             $sqlValues .= ',"' . $this->cleanInStr($valueArr[$headerArr['habitat']]) . '"';
                         }
                         if (array_key_exists('abundance', $headerArr) && $valueArr[$headerArr['abundance']]) {
                             $sqlInsert .= ',abundance';
                             $sqlValues .= ',"' . $this->cleanInStr($valueArr[$headerArr['abundance']]) . '"';
                         }
                         if ($noteStr || array_key_exists('notes', $headerArr) && $valueArr[$headerArr['notes']]) {
                             if (array_key_exists('notes', $headerArr) && $valueArr[$headerArr['notes']]) {
                                 if ($noteStr) {
                                     $noteStr .= '; ';
                                 }
                                 $noteStr .= $valueArr[$headerArr['notes']];
                             }
                             $sqlInsert .= ',notes';
                             $sqlValues .= ',"' . $this->cleanInStr($noteStr) . '"';
                         }
                         $sql = 'INSERT INTO fmchklsttaxalink (tid,clid' . $sqlInsert . ') VALUES (' . $tid . ', ' . $this->clid . $sqlValues . ')';
                         //echo $sql;
                         if ($this->conn->query($sql)) {
                             $successCnt++;
                         } else {
                             $this->errorArr[] = $sciNameStr . " (TID = {$tid}) failed to load<br />Error msg: " . $this->conn->error;
                             //echo $sql."<br />";
                         }
                     } else {
                         $this->errorArr[] = $sciNameStr . " failed to load (taxon must be of genus, species, or infraspecific ranking)";
                     }
                 } else {
                     $this->problemTaxa[] = $cleanSciName;
                     //$statusStr = $sciNameStr." failed to load (misspelled or not yet in taxonomic thesaurus)";
                     //$failCnt++;
                 }
                 $cnt++;
                 if ($cnt % 500 == 0) {
                     echo '<li style="margin-left:10px;">' . $cnt . ' taxa loaded</li>';
                     ob_flush();
                     flush();
                 }
             }
         }
         fclose($fh);
         if ($cnt && $this->clMeta['type'] == 'rarespp') {
             $occUtil = new OccurrenceUtilities();
             $occUtil->protectStateRareSpecies();
         }
     } else {
         $this->errorStr = 'ERROR: unable to locate scientific name column';
     }
     return $successCnt;
 }
예제 #16
0
 public static function occurrenceArrayCleaning($recMap)
 {
     //Trim all field values
     foreach ($recMap as $k => $v) {
         $recMap[$k] = trim($v);
     }
     //Date cleaning
     if (isset($recMap['eventdate']) && $recMap['eventdate']) {
         if (is_numeric($recMap['eventdate'])) {
             if ($recMap['eventdate'] > 2100 && $recMap['eventdate'] < 45000) {
                 //Date field was converted to Excel's numeric format (number of days since 01/01/1900)
                 $recMap['eventdate'] = date('Y-m-d', mktime(0, 0, 0, 1, $recMap['eventdate'] - 1, 1900));
             } elseif ($recMap['eventdate'] > 2200000 && $recMap['eventdate'] < 2500000) {
                 //Date is in the Gregorian format
                 $dArr = explode('/', jdtogregorian($recMap['eventdate']));
                 $recMap['eventdate'] = $dArr[2] . '-' . $dArr[0] . '-' . $dArr[1];
             } elseif ($recMap['eventdate'] > 19000000) {
                 //Format: 20120101 = 2012-01-01
                 $recMap['eventdate'] = substr($recMap['eventdate'], 0, 4) . '-' . substr($recMap['eventdate'], 4, 2) . '-' . substr($recMap['eventdate'], 6, 2);
             }
         } else {
             //Make sure event date is a valid format or drop into verbatimEventDate
             $dateStr = OccurrenceUtilities::formatDate($recMap['eventdate']);
             if ($dateStr) {
                 if ($recMap['eventdate'] != $dateStr && (!array_key_exists('verbatimeventdate', $recMap) || !$recMap['verbatimeventdate'])) {
                     $recMap['verbatimeventdate'] = $recMap['eventdate'];
                 }
                 $recMap['eventdate'] = $dateStr;
             } else {
                 if (!array_key_exists('verbatimeventdate', $recMap) || !$recMap['verbatimeventdate']) {
                     $recMap['verbatimeventdate'] = $recMap['eventdate'];
                 }
                 unset($recMap['eventdate']);
             }
         }
     }
     if (array_key_exists('latestdatecollected', $recMap) && $recMap['latestdatecollected'] && is_numeric($recMap['latestdatecollected'])) {
         if ($recMap['latestdatecollected'] > 2100 && $recMap['latestdatecollected'] < 45000) {
             //Date field was converted to Excel's numeric format (number of days since 01/01/1900)
             $recMap['latestdatecollected'] = date('Y-m-d', mktime(0, 0, 0, 1, $recMap['latestdatecollected'] - 1, 1900));
         } elseif ($recMap['latestdatecollected'] > 2200000 && $recMap['latestdatecollected'] < 2500000) {
             $dArr = explode('/', jdtogregorian($recMap['latestdatecollected']));
             $recMap['latestdatecollected'] = $dArr[2] . '-' . $dArr[0] . '-' . $dArr[1];
         } elseif ($recMap['latestdatecollected'] > 19000000) {
             $recMap['latestdatecollected'] = substr($recMap['latestdatecollected'], 0, 4) . '-' . substr($recMap['latestdatecollected'], 4, 2) . '-' . substr($recMap['latestdatecollected'], 6, 2);
         }
     }
     if (array_key_exists('verbatimeventdate', $recMap) && $recMap['verbatimeventdate'] && is_numeric($recMap['verbatimeventdate']) && $recMap['verbatimeventdate'] > 2100 && $recMap['verbatimeventdate'] < 45000) {
         //Date field was converted to Excel's numeric format (number of days since 01/01/1900)
         $recMap['verbatimeventdate'] = date('Y-m-d', mktime(0, 0, 0, 1, $recMap['verbatimeventdate'] - 1, 1900));
     }
     if (array_key_exists('dateidentified', $recMap) && $recMap['dateidentified'] && is_numeric($recMap['dateidentified']) && $recMap['dateidentified'] > 2100 && $recMap['dateidentified'] < 45000) {
         //Date field was converted to Excel's numeric format (number of days since 01/01/1900)
         $recMap['dateidentified'] = date('Y-m-d', mktime(0, 0, 0, 1, $recMap['dateidentified'] - 1, 1900));
     }
     //If month, day, or year are text, avoid SQL error by converting to numeric value
     if (array_key_exists('year', $recMap) || array_key_exists('month', $recMap) || array_key_exists('day', $recMap)) {
         $y = array_key_exists('year', $recMap) ? $recMap['year'] : '00';
         $m = array_key_exists('month', $recMap) ? $recMap['month'] : '00';
         $d = array_key_exists('day', $recMap) ? $recMap['day'] : '00';
         $vDate = trim($y . '-' . $m . '-' . $d, '- ');
         if (isset($recMap['day']) && !is_numeric($recMap['day'])) {
             if (!array_key_exists('verbatimeventdate', $recMap) || !$recMap['verbatimeventdate']) {
                 $recMap['verbatimeventdate'] = $vDate;
             }
             unset($recMap['day']);
             $d = '00';
         }
         if (isset($recMap['year']) && !is_numeric($recMap['year'])) {
             if (!array_key_exists('verbatimeventdate', $recMap) || !$recMap['verbatimeventdate']) {
                 $recMap['verbatimeventdate'] = $vDate;
             }
             unset($recMap['year']);
         }
         if (isset($recMap['month']) && $recMap['month'] && !is_numeric($recMap['month'])) {
             if (strlen($recMap['month']) > 2) {
                 $monAbbr = strtolower(substr($recMap['month'], 0, 3));
                 if (array_key_exists($monAbbr, OccurrenceUtilities::$monthNames)) {
                     $recMap['month'] = OccurrenceUtilities::$monthNames[$monAbbr];
                     $recMap['eventdate'] = OccurrenceUtilities::formatDate(trim($y . '-' . $recMap['month'] . '-' . ($d ? $d : '00'), '- '));
                 } else {
                     if (!array_key_exists('verbatimeventdate', $recMap) || !$recMap['verbatimeventdate']) {
                         $recMap['verbatimeventdate'] = $vDate;
                     }
                     unset($recMap['month']);
                 }
             } else {
                 if (!array_key_exists('verbatimeventdate', $recMap) || !$recMap['verbatimeventdate']) {
                     $recMap['verbatimeventdate'] = $vDate;
                 }
                 unset($recMap['month']);
             }
         }
         if ($vDate && (!array_key_exists('eventdate', $recMap) || !$recMap['eventdate'])) {
             $recMap['eventdate'] = OccurrenceUtilities::formatDate($vDate);
         }
     }
     //eventDate NULL && verbatimEventDate NOT NULL && year NOT NULL
     if ((!array_key_exists('eventdate', $recMap) || !$recMap['eventdate']) && array_key_exists('verbatimeventdate', $recMap) && $recMap['verbatimeventdate'] && (!array_key_exists('year', $recMap) || !$recMap['year'])) {
         $dateStr = OccurrenceUtilities::formatDate($recMap['verbatimeventdate']);
         if ($dateStr) {
             $recMap['eventdate'] = $dateStr;
         }
     }
     if (isset($recMap['recordnumberprefix']) && $recMap['recordnumberprefix'] || isset($recMap['recordnumbersuffix']) && $recMap['recordnumbersuffix']) {
         $recNumber = $recMap['recordnumber'];
         if (isset($recMap['recordnumberprefix']) && $recMap['recordnumberprefix']) {
             $recNumber = $recMap['recordnumberprefix'] . '-' . $recNumber;
         }
         if (isset($recMap['recordnumbersuffix']) && $recMap['recordnumbersuffix']) {
             if (is_numeric($recMap['recordnumbersuffix']) && $recMap['recordnumber']) {
                 $recNumber .= '-';
             }
             $recNumber .= $recMap['recordnumbersuffix'];
         }
         $recMap['recordnumber'] = $recNumber;
     }
     //If lat or long are not numeric, try to make them so
     if (array_key_exists('decimallatitude', $recMap) || array_key_exists('decimallongitude', $recMap)) {
         $latValue = array_key_exists('decimallatitude', $recMap) ? $recMap['decimallatitude'] : '';
         $lngValue = array_key_exists('decimallongitude', $recMap) ? $recMap['decimallongitude'] : '';
         if ($latValue && !is_numeric($latValue) || $lngValue && !is_numeric($lngValue)) {
             $llArr = OccurrenceUtilities::parseVerbatimCoordinates(trim($latValue . ' ' . $lngValue), 'LL');
             if (array_key_exists('lat', $llArr) && array_key_exists('lng', $llArr)) {
                 $recMap['decimallatitude'] = $llArr['lat'];
                 $recMap['decimallongitude'] = $llArr['lng'];
             } else {
                 unset($recMap['decimallatitude']);
                 unset($recMap['decimallongitude']);
             }
             $vcStr = '';
             if (array_key_exists('verbatimcoordinates', $recMap) && $recMap['verbatimcoordinates']) {
                 $vcStr .= $recMap['verbatimcoordinates'] . '; ';
             }
             $vcStr .= $latValue . ' ' . $lngValue;
             if (trim($vcStr)) {
                 $recMap['verbatimcoordinates'] = trim($vcStr);
             }
         }
     }
     //Transfer verbatim Lat/Long to verbatim coords
     if (isset($recMap['verbatimlatitude']) || isset($recMap['verbatimlongitude'])) {
         if (isset($recMap['verbatimlatitude']) && isset($recMap['verbatimlongitude'])) {
             if (!isset($recMap['decimallatitude']) || !isset($recMap['decimallongitude'])) {
                 if (is_numeric($recMap['verbatimlatitude']) && is_numeric($recMap['verbatimlongitude'])) {
                     if ($recMap['verbatimlatitude'] > -90 && $recMap['verbatimlatitude'] < 90 && $recMap['verbatimlongitude'] > -180 && $recMap['verbatimlongitude'] < 180) {
                         $recMap['decimallatitude'] = $recMap['verbatimlatitude'];
                         $recMap['decimallongitude'] = $recMap['verbatimlongitude'];
                     }
                 } else {
                     //Attempt to extract decimal lat/long
                     $coordArr = OccurrenceUtilities::parseVerbatimCoordinates($recMap['verbatimlatitude'] . ' ' . $recMap['verbatimlongitude'], 'LL');
                     if ($coordArr) {
                         if (array_key_exists('lat', $coordArr)) {
                             $recMap['decimallatitude'] = $coordArr['lat'];
                         }
                         if (array_key_exists('lng', $coordArr)) {
                             $recMap['decimallongitude'] = $coordArr['lng'];
                         }
                     }
                 }
             }
         }
         //Place into verbatim coord field
         $vCoord = isset($recMap['verbatimcoordinates']) ? $recMap['verbatimcoordinates'] : '';
         if ($vCoord) {
             $vCoord .= '; ';
         }
         if (stripos($vCoord, $recMap['verbatimlatitude']) === false && stripos($vCoord, $recMap['verbatimlongitude']) === false) {
             $recMap['verbatimcoordinates'] = $vCoord . $recMap['verbatimlatitude'] . ', ' . $recMap['verbatimlongitude'];
         }
     }
     //Transfer DMS to verbatim coords
     if (isset($recMap['latdeg']) && $recMap['latdeg'] && isset($recMap['lngdeg']) && $recMap['lngdeg']) {
         //Attempt to create decimal lat/long
         if (is_numeric($recMap['latdeg']) && is_numeric($recMap['lngdeg']) && (!isset($recMap['decimallatitude']) || !isset($recMap['decimallongitude']))) {
             $latDec = $recMap['latdeg'];
             if (isset($recMap['latmin']) && $recMap['latmin'] && is_numeric($recMap['latmin'])) {
                 $latDec += $recMap['latmin'] / 60;
             }
             if (isset($recMap['latsec']) && $recMap['latsec'] && is_numeric($recMap['latsec'])) {
                 $latDec += $recMap['latsec'] / 3600;
             }
             if (stripos($recMap['latns'], 's') === 0 && $latDec > 0) {
                 $latDec *= -1;
             }
             $lngDec = $recMap['lngdeg'];
             if (isset($recMap['lngmin']) && $recMap['lngmin'] && is_numeric($recMap['lngmin'])) {
                 $lngDec += $recMap['lngmin'] / 60;
             }
             if (isset($recMap['lngsec']) && $recMap['lngsec'] && is_numeric($recMap['lngsec'])) {
                 $lngDec += $recMap['lngsec'] / 3600;
             }
             if (stripos($recMap['lngew'], 'e') === 0) {
                 $lngDec *= -1;
             }
             $recMap['decimallatitude'] = round($latDec, 6);
             $recMap['decimallongitude'] = round($lngDec, 6);
         }
         //Place into verbatim coord field
         $vCoord = isset($recMap['verbatimcoordinates']) ? $recMap['verbatimcoordinates'] : '';
         if ($vCoord) {
             $vCoord .= '; ';
         }
         $vCoord .= $recMap['latdeg'] . '° ';
         if (isset($recMap['latmin']) && $recMap['latmin']) {
             $vCoord .= $recMap['latmin'] . 'm ';
         }
         if (isset($recMap['latsec']) && $recMap['latsec']) {
             $vCoord .= $recMap['latsec'] . 's ';
         }
         if (isset($recMap['latns'])) {
             $vCoord .= $recMap['latns'] . '; ';
         }
         $vCoord .= $recMap['lngdeg'] . '° ';
         if (isset($recMap['lngmin']) && $recMap['lngmin']) {
             $vCoord .= $recMap['lngmin'] . 'm ';
         }
         if (isset($recMap['lngsec']) && $recMap['lngsec']) {
             $vCoord .= $recMap['lngsec'] . 's ';
         }
         if (isset($recMap['lngew'])) {
             $vCoord .= $recMap['lngew'];
         }
         $recMap['verbatimcoordinates'] = $vCoord;
     }
     /*
     if(array_key_exists('verbatimcoordinates',$recMap) && $recMap['verbatimcoordinates'] && (!isset($recMap['decimallatitude']) || !isset($recMap['decimallongitude']))){
     $coordArr = OccurrenceUtilities::parseVerbatimCoordinates($recMap['verbatimcoordinates']);
     if($coordArr){
     if(array_key_exists('lat',$coordArr)) $recMap['decimallatitude'] = $coordArr['lat'];
     if(array_key_exists('lng',$coordArr)) $recMap['decimallongitude'] = $coordArr['lng'];
     }
     }
     */
     //Convert UTM to Lat/Long
     if (array_key_exists('utmnorthing', $recMap) && $recMap['utmnorthing'] || array_key_exists('utmeasting', $recMap) && $recMap['utmeasting']) {
         $no = array_key_exists('utmnorthing', $recMap) ? $recMap['utmnorthing'] : '';
         $ea = array_key_exists('utmeasting', $recMap) ? $recMap['utmeasting'] : '';
         $zo = array_key_exists('utmzoning', $recMap) ? $recMap['utmzoning'] : '';
         $da = array_key_exists('geodeticdatum', $recMap) ? $recMap['geodeticdatum'] : '';
         if (!isset($recMap['decimallatitude']) || !isset($recMap['decimallongitude'])) {
             if ($no && $ea && $zo) {
                 //Northing, easting, and zoning all had values
                 $llArr = OccurrenceUtilities::convertUtmToLL($ea, $no, $zo, $da);
                 if (isset($llArr['lat'])) {
                     $recMap['decimallatitude'] = $llArr['lat'];
                 }
                 if (isset($llArr['lng'])) {
                     $recMap['decimallongitude'] = $llArr['lng'];
                 }
             } else {
                 //UTM was a single field which was placed in UTM northing field within uploadspectemp table
                 $coordArr = OccurrenceUtilities::parseVerbatimCoordinates(trim($zo . ' ' . $ea . ' ' . $no), 'UTM');
                 if ($coordArr) {
                     if (array_key_exists('lat', $coordArr)) {
                         $recMap['decimallatitude'] = $coordArr['lat'];
                     }
                     if (array_key_exists('lng', $coordArr)) {
                         $recMap['decimallongitude'] = $coordArr['lng'];
                     }
                 }
             }
         }
         $vCoord = isset($recMap['verbatimcoordinates']) ? $recMap['verbatimcoordinates'] : '';
         if (!($no && strpos($vCoord, $no))) {
             $recMap['verbatimcoordinates'] = ($vCoord ? $vCoord . '; ' : '') . $zo . ' ' . $ea . 'E ' . $no . 'N';
         }
     }
     //Transfer TRS to verbatim coords
     if (isset($recMap['trstownship']) && $recMap['trstownship'] && isset($recMap['trsrange']) && $recMap['trsrange']) {
         $vCoord = isset($recMap['verbatimcoordinates']) ? $recMap['verbatimcoordinates'] : '';
         if ($vCoord) {
             $vCoord .= '; ';
         }
         $vCoord .= (stripos($recMap['trstownship'], 't') === false ? 'T' : '') . $recMap['trstownship'] . ' ';
         $vCoord .= (stripos($recMap['trsrange'], 'r') === false ? 'R' : '') . $recMap['trsrange'] . ' ';
         if (isset($recMap['trssection'])) {
             $vCoord .= (stripos($recMap['trssection'], 's') === false ? 'sec' : '') . $recMap['trssection'] . ' ';
         }
         if (isset($recMap['trssectiondetails'])) {
             $vCoord .= $recMap['trssectiondetails'];
         }
         $recMap['verbatimcoordinates'] = trim($vCoord);
     }
     //Check to see if evelation are valid numeric values
     if (isset($recMap['minimumelevationinmeters']) && $recMap['minimumelevationinmeters'] && !is_numeric($recMap['minimumelevationinmeters']) || isset($recMap['maximumelevationinmeters']) && $recMap['maximumelevationinmeters'] && !is_numeric($recMap['maximumelevationinmeters'])) {
         $vStr = isset($recMap['verbatimelevation']) ? $recMap['verbatimelevation'] : '';
         if (isset($recMap['minimumelevationinmeters']) && $recMap['minimumelevationinmeters']) {
             $vStr .= ($vStr ? '; ' : '') . $recMap['minimumelevationinmeters'];
         }
         if (isset($recMap['maximumelevationinmeters']) && $recMap['maximumelevationinmeters']) {
             $vStr .= '-' . $recMap['maximumelevationinmeters'];
         }
         $recMap['verbatimelevation'] = $vStr;
         $recMap['minimumelevationinmeters'] = '';
         $recMap['maximumelevationinmeters'] = '';
     }
     //Verbatim elevation
     if (array_key_exists('verbatimelevation', $recMap) && $recMap['verbatimelevation'] && (!array_key_exists('minimumelevationinmeters', $recMap) || !$recMap['minimumelevationinmeters'])) {
         $eArr = OccurrenceUtilities::parseVerbatimElevation($recMap['verbatimelevation']);
         if ($eArr) {
             if (array_key_exists('minelev', $eArr)) {
                 $recMap['minimumelevationinmeters'] = $eArr['minelev'];
                 if (array_key_exists('maxelev', $eArr)) {
                     $recMap['maximumelevationinmeters'] = $eArr['maxelev'];
                 }
             }
         }
     }
     //Deal with elevation when in two fields (number and units)
     if (isset($recMap['elevationnumber']) && $recMap['elevationnumber']) {
         $elevStr = $recMap['elevationnumber'] . $recMap['elevationunits'];
         //Try to extract meters
         $eArr = OccurrenceUtilities::parseVerbatimElevation($elevStr);
         if ($eArr) {
             if (array_key_exists('minelev', $eArr)) {
                 $recMap['minimumelevationinmeters'] = $eArr['minelev'];
                 if (array_key_exists('maxelev', $eArr)) {
                     $recMap['maximumelevationinmeters'] = $eArr['maxelev'];
                 }
             }
         }
         if (!$eArr || !stripos($elevStr, 'm')) {
             $vElev = isset($recMap['verbatimelevation']) ? $recMap['verbatimelevation'] : '';
             if ($vElev) {
                 $vElev .= '; ';
             }
             $recMap['verbatimelevation'] = $vElev . $elevStr;
         }
     }
     //Concatenate collectorfamilyname and collectorinitials into recordedby
     if (isset($recMap['collectorfamilyname']) && $recMap['collectorfamilyname'] && (!isset($recMap['recordedby']) || !$recMap['recordedby'])) {
         $recordedBy = $recMap['collectorfamilyname'];
         if (isset($recMap['collectorinitials']) && $recMap['collectorinitials']) {
             $recordedBy .= ', ' . $recMap['collectorinitials'];
         }
         $recMap['recordedby'] = $recordedBy;
         //Need to add code that maps to collector table
     }
     if (array_key_exists("specificepithet", $recMap)) {
         if ($recMap["specificepithet"] == 'sp.' || $recMap["specificepithet"] == 'sp') {
             $recMap["specificepithet"] = '';
         }
     }
     if (array_key_exists("taxonrank", $recMap)) {
         $tr = strtolower($recMap["taxonrank"]);
         if ($tr == 'species' || !$recMap["specificepithet"]) {
             $recMap["taxonrank"] = '';
         }
         if ($tr == 'subspecies') {
             $recMap["taxonrank"] = 'subsp.';
         }
         if ($tr == 'variety') {
             $recMap["taxonrank"] = 'var.';
         }
         if ($tr == 'forma') {
             $recMap["taxonrank"] = 'f.';
         }
     }
     //Populate sciname if null
     if (array_key_exists('sciname', $recMap) && $recMap['sciname']) {
         if (substr($recMap['sciname'], -4) == ' sp.') {
             $recMap['sciname'] = substr($recMap['sciname'], 0, -4);
         }
         if (substr($recMap['sciname'], -3) == ' sp') {
             $recMap['sciname'] = substr($recMap['sciname'], 0, -3);
         }
         $recMap['sciname'] = str_replace(array(' ssp. ', ' ssp '), ' subsp. ', $recMap['sciname']);
         $recMap['sciname'] = str_replace(' var ', ' var. ', $recMap['sciname']);
         $pattern = '/\\b(cf\\.|cf|aff\\.|aff)\\s{1}/';
         if (preg_match($pattern, $recMap['sciname'], $m)) {
             $recMap['identificationqualifier'] = $m[1];
             $recMap['sciname'] = preg_replace($pattern, '', $recMap['sciname']);
         }
     } else {
         if (array_key_exists("genus", $recMap)) {
             //Build sciname from individual units supplied by source
             $sciName = $recMap["genus"];
             if (array_key_exists("specificepithet", $recMap)) {
                 $sciName .= " " . $recMap["specificepithet"];
             }
             if (array_key_exists("taxonrank", $recMap)) {
                 $sciName .= " " . $recMap["taxonrank"];
             }
             if (array_key_exists("infraspecificepithet", $recMap)) {
                 $sciName .= " " . $recMap["infraspecificepithet"];
             }
             $recMap['sciname'] = trim($sciName);
         } elseif (array_key_exists('scientificname', $recMap)) {
             //Clean and parse scientific name
             $parsedArr = OccurrenceUtilities::parseScientificName($recMap['scientificname']);
             $scinameStr = '';
             if (array_key_exists('unitname1', $parsedArr)) {
                 $scinameStr = $parsedArr['unitname1'];
                 if (!array_key_exists('genus', $recMap) || $recMap['genus']) {
                     $recMap['genus'] = $parsedArr['unitname1'];
                 }
             }
             if (array_key_exists('unitname2', $parsedArr)) {
                 $scinameStr .= ' ' . $parsedArr['unitname2'];
                 if (!array_key_exists('specificepithet', $recMap) || !$recMap['specificepithet']) {
                     $recMap['specificepithet'] = $parsedArr['unitname2'];
                 }
             }
             if (array_key_exists('unitind3', $parsedArr)) {
                 $scinameStr .= ' ' . $parsedArr['unitind3'];
                 if (!array_key_exists('taxonrank', $recMap) || !$recMap['taxonrank']) {
                     $recMap['taxonrank'] = $parsedArr['unitind3'];
                 }
             }
             if (array_key_exists('unitname3', $parsedArr)) {
                 $scinameStr .= ' ' . $parsedArr['unitname3'];
                 if (!array_key_exists('infraspecificepithet', $recMap) || !$recMap['infraspecificepithet']) {
                     $recMap['infraspecificepithet'] = $parsedArr['unitname3'];
                 }
             }
             if (array_key_exists('author', $parsedArr)) {
                 if (!array_key_exists('scientificnameauthorship', $recMap) || !$recMap['scientificnameauthorship']) {
                     $recMap['scientificnameauthorship'] = $parsedArr['author'];
                 }
             }
             $recMap['sciname'] = trim($scinameStr);
         }
     }
     return $recMap;
 }