* Getting specimen data from GBIF wie web service *

* Access for all users except guests * @author Gabriele Droege, DNA Bank Network * @version 2.0 * @package Input * @copyright Copyright © 2011 DNA Bank Network http://www.dnabank-network.org
The contents of this file are subject to the Mozilla Public License Version 1.1 * @filesource * @license http://www.mozilla.org/MPL/ MPL */ /** * calling GBIF API depending on parameters * get protocol (DARWINCORE_ARCHIVE or BIOCASE), Tapir and Digir currently ignored (only a few datasets) * check if record already in system (connected to other samples), if so -> get ID_Cache * DwC-record: get datasetKey -> check if already listed in DNA Module datasets, if so -> get ID_Dataset, if not wait until saving the reocord * saving sample and DwC-record (other script (input/Save_GBIF.php) -> get full specimen record from GBIF webservice, insert new dataset into table:dataset (Display = institutionCode, External_Internal = 1 (can be changed later by user)) * BioCASE-record: get datasetKey and endpoint url -> check if one of these already listed in DNA Module datasets, if so -> get ID_Dataset and provider.Provider, if not wait until saving the reocord * saving sample and BioCASE-record (other script, first get ABCD version, than get original record from BioCASE-provider (mostly input/Save_ABCD2.06php) -> update dataset or insert into table.dataset) */ if($ID_Dataset == '2' or $Protocol == 'DWC_ARCHIVE' or $Protocol == 'TAPIR') { $GBIF_query = 'http://api.gbif.org/v1/occurrence/search?'; if(isset($SpecimenNumber)) { $GBIF_query .= 'catalogNumber='.$SpecimenNumber.'&'; } if(isset($InstCode)) { $GBIF_query .= 'institutionCode='.$InstCode.'&'; } if(isset($CollCode)) { $GBIF_query .= 'collectionCode='.$CollCode.'&'; } if(isset($Taxon)) { $GBIF_query .= 'scientificName='.$Taxon.'&'; } if(isset($CollYear)) { $GBIF_query .= 'year='.$CollYear.'&'; } if(isset($CollNo)) { $GBIF_query .= 'recordNumber='.$CollNo.'&'; } $GBIF_query .= 'limit=50'; //echo $GBIF_query."
"; $jsonfile = file_get_contents($GBIF_query); // get endpoint : http://api.gbif.org/v0.9/dataset/85714c48-f762-11e1-a439-00145eb45e9a/endpoint // GUID is datasetKey from Occurrence record $json_array = json_decode($jsonfile, true); foreach ($json_array as $key1 => $list1) { if($key1 == "results") { $CountRecords = count($list1); if($_GET['sqlType'] != "Detail") { echo "".$CountRecords." records found (limit 50).";} if($CountRecords == "0") { echo " Please check your search keys.";} } for($i=0; $i < $CountRecords; $i++) { // Scan through inner loop echo ''; $UnitCount = $i+1; // check if occurence already in DNA Module $sqlTest = "SELECT ID_Cache FROM cachecollection WHERE UnitID_Specimen = '".$list1[$i]["catalogNumber"]."' AND CollectionCode_Specimen = '".$list1[$i]["collectionCode"]."' AND InstitutionCode_Specimen = '".$list1[$i]["institutionCode"]."'"; $resultTest = mysqli_query($GLOBALS["___mysqli_ston"], $sqlTest); $countTest = mysqli_num_rows($resultTest); if($countTest > 0) { while($row = mysqli_fetch_object($resultTest)) $ID_Cache = $row->ID_Cache; } echo '

'; if($_GET['sqlType'] != "Detail") { echo $UnitCount." Record details"; } else { echo "Specimen details"; } if($CountRecords > 1) { echo ' (select)'; } else { echo ''; } echo '
'; $DatasetKey = $list1[$i]["datasetKey"]; if($list1[$i]["protocol"] == "BIOCASE") { $Endpoint_Query = 'http://api.gbif.org/v0.9/dataset/'.$DatasetKey.'/endpoint'; $jsonEndpoint = file_get_contents($Endpoint_Query); $json_array_Endpoint = json_decode($jsonEndpoint, true); foreach ($json_array_Endpoint as $keyE1 => $listE1) { $Endpoint = $listE1["url"]; } } // if($list1[$i]["protocol"] == "BIOCASE") $sqlDatasetKey = "SELECT dataset.ID_Dataset, provider.ID_Provider FROM dataset LEFT JOIN provider on dataset.FK_Provider = provider.ID_Provider WHERE dataset.DatasetKey_GBIF = '$DatasetKey' OR provider.Provider = '$Endpoint'"; $resultDatasetKey = mysqli_query($GLOBALS["___mysqli_ston"], $sqlDatasetKey); $num_rows = mysqli_num_rows($resultDatasetKey); if($num_rows > 0) { while($row = mysqli_fetch_object($resultDatasetKey)) { $ID_Dataset = $row->ID_Dataset; } echo ''; } echo ''; echo ''; if($Endpoint != "") { echo ''; } echo 'Preferred Taxon Name: '; if(isset($list1[$i]["genus"])) { echo $list1[$i]["species"]; } else { echo $list1[$i]["scientificName"]; } echo '
Catalog No: '.$list1[$i]["catalogNumber"].'
Record Basis: '.$list1[$i]["basisOfRecord"].'
'; if(isset($list1[$i]["occurrenceID"])) { echo 'Unit GUID: '.$list1[$i]["occurrenceID"].''; } echo '
Institution Code: '.$list1[$i]["institutionCode"].'
Collection Code: '.$list1[$i]["collectionCode"].'
'; echo '

Identification(s):

'; echo '
Name: '.$list1[$i]["scientificName"].''; echo '
Identifier: '.$list1[$i]["identifiedBy"].'
Taxonomy: '.$list1[$i]["family"].' (familia)
'; echo '

Collection Info:

Collector(s): '.$list1[$i]["recordedBy"].'
'; if(isset($list1[$i]["recordNumber"])) { echo 'Field/Collector\'s number: '.$list1[$i]["recordNumber"].'
'; } echo 'Collection Date: '; if(isset($list1[$i]["eventDate"])) { echo $list1[$i]["eventDate"]; } else { if(isset($list1[$i]["verbatimEventDate"])) { echo $list1[$i]["verbatimEventDate"]; } } echo '
Locality Other info
Country: '.$list1[$i]["country"].' ('.$list1[$i]["countryCode"].')
Locality: '.$list1[$i]["locality"].''; if(isset($list1[$i]["decimalLatitude"])) { echo '
Coordinates (Lat|Lon): '.$list1[$i]["decimalLatitude"].' | '.$list1[$i]["decimalLongitude"].''; } echo '
'; if(isset($list1[$i]["elevation"])) { echo 'Altitude: '.$list1[$i]["elevation"].' m
'; } echo '
'; } } //foreach ($json_array as $key1 => $list1) } ?>