function get_specimen($institutionCode, $collectionCode, $catalogNumber, &$item) { $id = find_specimen($institutionCode, $collectionCode, $catalogNumber); if ($id == 0) { $s = new DiGIRProvider(''); //echo "$institutionCode, $collectionCode, $catalogNumber\n"; // Some collections don't have a collection code, // or need other fixes switch ($institutionCode) { case 'SAMA': $collectionCode = ''; break; case 'KUNHM': $institutionCode = 'KU'; break; default: break; } $data = $s->Get2($institutionCode, $collectionCode, $catalogNumber); //print_r($data); if (isset($data->record)) { foreach ($data->record as $d) { $d = $s->post_process($d); // We may have to reverse extract collection code /* $d->institutionCode = $institutionCode; $d->collectionCode = $collectionCode; $d->catalogNumber = $catalogNumber; */ $cCode = $d->collectionCode; if ($cCode == '') { if (preg_match('/(.*):(?<collectionCode>.*):(.*)/', $d->guid, $matches)) { $d->collectionCode = $matches['collectionCode']; } switch ($institutionCode) { case 'CAS': if ($collectionCode == 'Herps') { $d->collectionCode = $collectionCode; if (preg_match('/CAS::(?<id>\\d+)/', $d->guid, $m)) { $d->guid = 'CAS:Herps:' . $m['id']; } } break; default: break; } } else { // We have a collection code, but we might need to fix it... switch ($institutionCode) { case 'CAS': if ($d->collectionCode == 'ORN') { $d->collectionCode = 'Birds'; } break; case 'KU': if ($d->collectionCode == 'KUH') { $d->collectionCode = 'Herps'; } break; default: break; } } $bci = $s->GetBci($d->institutionCode, $d->collectionCode, $d->catalogNumber); if ($bci != '') { $d->bci = $bci; } //print_r($d); $id = store_specimen($d); $item = $d; } } } else { $json = retrieve_specimen_json($id); $item = json_decode($json); } return $id; }
case 'rdf': $format = $_GET['format']; break; default: $format = 'html'; break; } } //$id = '0100367'; $state = 404; // not found if ($id != '') { $guid = 'antweb:casent' . $id; $specimen_id = find_specimen_from_guid($guid); if ($specimen_id != 0) { $json = retrieve_specimen_json($specimen_id); $item = json_decode($json); $state = 200; } else { $url = 'http://www.antweb.org/tapirlink/www/tapir.php/antweb?op=search&start=0&limit=1&template=http://bioguid.info/tapir/dwc_catalog_number.xml&name=casent' . $id; $xml = get($url); if ($xml != '') { $xp = new XsltProcessor(); $xsl = new DomDocument(); $xsl->load('xsl/tapir2json.xsl'); $xp->importStylesheet($xsl); $xml_doc = new DOMDocument(); $xml_doc->loadXML($xml); $json = $xp->transformToXML($xml_doc); //echo $json; $json = str_replace("\n\"", "\"", $json);