// a. save new dataset and provider as External; Display = InstitutionCode CollectionCode // b. get record directly via ABCD to save it // 3. if not BioCASE -> // a. save dataset as External without provider information; Display = InstitutionCode CollectionCode // User can change name of dataset etc. afterwards // b. get record from GBIF if(isset($Unit) and $Unit != "") { foreach($Unit as $index => $SingleRecord) { $UnitID = $_POST['formUnitID'][$index]; $CollCode = $_POST['formSourceID'][$index]; $InstCode = $_POST['formSourceInstitutionID'][$index]; $ID_Cache = $_POST['formID_Cache'][$index]; $DatasetKey = $_POST['formDatasetKey'][$index]; $Protocol = $_POST['formProtocol'][$index]; if(isset($_POST['formID_Dataset'][$index])) { $ID_Dataset = $_POST['formID_Dataset'][$index]; } if(isset($_POST['formEndpoint'][$index])) { $Endpoint = $_POST['formEndpoint'][$index]; } // only BioCASE providers if($Endpoint != "") { $inf = parse_url($Endpoint); $host = $inf['host']; $path = $inf['path']; if (isset($inf['query'])) $path .= '?'.$inf['query']; if (isset($inf['port'])) $port = $inf['port']; else $port = 80; if($Endpoint) { error_reporting(E_ALL ^ E_WARNING ^ E_NOTICE); $fp = @fsockopen($host, $port, $errno, $error, 5); if(!$fp or !$host) { echo "Connection to provider failed! "; $TestEndpoint = "false"; } else { $file = $Endpoint; $dom = new DOMDocument(); $dom->Load($file); $Schema = $dom->getElementsByTagName('SupportedSchemas'); foreach ($Schema as $Schema) { $ABCD = $Schema->getAttribute('namespace'); if($ABCD == "http://www.tdwg.org/schemas/abcd/2.06") { if(!isset($formID_Dataset) or $formID_Dataset == "") { $sqlprovider = "INSERT INTO provider (Provider, FK_Schema, Created_Who) VALUES ('$Endpoint','2','$log')"; $resultprovider = mysqli_query($GLOBALS["___mysqli_ston"], $sqlprovider); $IDProvider=((is_null($___mysqli_res = mysqli_insert_id($GLOBALS["___mysqli_ston"]))) ? false : $___mysqli_res); $Display = $InstCode." ".$CollCode; $sqldataset = "INSERT INTO dataset (FK_Provider, Display, Internal_External, DatasetKey_GBIF, Protocol, InstitutionCode, Created_Who) VALUES ('$IDProvider', '$Display', '2', '$DatasetKey', '$Protocol', '$InstCode', '$log')"; $resultdataset = mysqli_query($GLOBALS["___mysqli_ston"], $sqldataset); $ID_Dataset = ((is_null($___mysqli_res = mysqli_insert_id($GLOBALS["___mysqli_ston"]))) ? false : $___mysqli_res); ###############################################Error dataset########################################### if(!$resultdataset) { $msg = $sqldataset."\n"; $msg .= "####Error dataset###"; if($debug == '1') echo $msg; trigger_error($msg, E_USER_ERROR); include ("../config/Errorreport.php"); $error = "true"; } ######################################################################################################### } $file = $Endpoint."&query=".urlencode('
search
http://www.tdwg.org/schemas/abcd/2.06 http://www.tdwg.org/schemas/abcd/2.06 '); $file .= urlencode($UnitID); $file .= urlencode(''); $file .= urlencode($InstCode); $file .= urlencode(''); $file .= urlencode($CollCode); $file .= urlencode('false
'); $dom = new DOMDocument(); $dom->Load($file); include ("Save_ABCD2.06.php"); } } //foreach ($Schema as $Schema) }} } // if($Endpoint != "") if($Endpoint == "" or $TestEndpoint == "false") { // if($Endpoint = "") -> not a BioCASE provider or BioCASE provider not available if(!isset($formID_Dataset) or $formID_Dataset == "") { $Display = $InstCode." ".$CollCode; $sqldataset = "INSERT INTO dataset (FK_Provider, Display, Internal_External, DatasetKey_GBIF, Protocol, InstitutionCode, Created_Who) VALUES (NULL, '$Display', '2', '$DatasetKey', '$Protocol', '$InstCode', '$log')"; $resultdataset = mysqli_query($GLOBALS["___mysqli_ston"], $sqldataset); $ID_Dataset = ((is_null($___mysqli_res = mysqli_insert_id($GLOBALS["___mysqli_ston"]))) ? false : $___mysqli_res); ###############################################Error dataset########################################### if(!$resultdataset) { $msg = $sqldataset."\n"; $msg .= "####Error dataset###"; if($debug == '1') echo $msg; trigger_error($msg, E_USER_ERROR); include ("../config/Errorreport.php"); $error = "true"; } ######################################################################################################### } $GBIF_query = 'http://api.gbif.org/v0.9/occurrence/search?'; if(isset($UnitID)) { $GBIF_query .= 'catalogNumber='.$UnitID.'&'; } if(isset($InstCode)) { $GBIF_query .= 'institutionCode='.$InstCode.'&'; } if(isset($CollCode)) { $GBIF_query .= 'collectionCode='.$CollCode; } //echo $GBIF_query."
"; $jsonfile = file_get_contents($GBIF_query); $json_array = json_decode($jsonfile, true); foreach ($json_array as $key1 => $list1) { if($key1 == "results") { $CountRecords = count($list1); } 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; } $sqlUnitID = addslashes($list1[$i]["catalogNumber"]); $sqlSourceName = addslashes($list1[$i]["collectionCode"]); $sqlSourceInstitutionCode = addslashes($list1[$i]["institutionCode"]); $sqlUnitGUID = addslashes($list1[$i]["occurrenceID"]); $sqlCollectorsNo = addslashes($list1[$i]["recordNumber"]); $sqlPersonName = addslashes($list1[$i]["recordedBy"]); $sqlCollectionDate = addslashes($list1[$i]["eventDate"]); $sqlLocality = addslashes($list1[$i]["locality"]); $sqlCountryName = addslashes($list1[$i]["country"]); $sqlISO2 = addslashes($list1[$i]["countryCode"]); $sqlLongitude = addslashes($list1[$i]["decimalLongitude"]); $sqlLatitude = addslashes($list1[$i]["decimalLatitude"]); $sqlNameAuthorYearString = addslashes($list1[$i]["scientificName"]); $sqlHigherTaxon = addslashes($list1[$i]["family"]); $sqlHigherTaxonRank = 'familia'; $sqlGenus = addslashes($list1[$i]["genus"]); $sqlFirstEpithet = addslashes($list1[$i]["specificEpithet"]); $sqlSecondEpithet = addslashes($list1[$i]["infraspecificEpithet"]); $sqlRank = addslashes($list1[$i]["taxonRank"]); $sqlPreferredIdentificationFlag = '1'; $sqlTypeStatus = addslashes($list1[$i]["typeStatus"]); } //for($i=0; $i < $CountRecords; $i++) } //foreach ($json_array as $key1 => $list1) } // if($Endpoint = "") -> not a BioCASE provider } //foreach($Unit as $index => $SingleRecord) } //if(isset($Unit)) ?>