Exemple #1
0
 if (preg_match('/^CAS-SU /', $code)) {
     $go = true;
     $code = str_replace('CAS-SU ', 'CAS ', $code);
 }
 if ($go) {
     $url = 'http://iphylo.org/~rpage/phyloinformatics/services/get_gbif_occurrence.php?code=' . rawurlencode($code);
     echo $url . "\n";
     $json = get($url);
     //echo $json;
     $hits = json_decode($json);
     print_r($hits);
     // score match
     $hit = 0;
     foreach ($hits->occurrences as $occurrenceID => $occurrence) {
         // cache
         store_specimen($occurrence);
         if (in_array($occurrence->class, $expanded)) {
             echo $occurrence->class . "\n";
             $hit = $occurrenceID;
         }
     }
     if ($hit != 0) {
         echo "===hit===\n";
         echo $specimen->code . "\n";
         print_r($hits->occurrences->{$hit});
         // Update Database
         $sql = "UPDATE rdmp_reference_specimen_joiner SET occurrenceID=" . $hits->occurrences->{$hit}->occurrenceID . " WHERE reference_id=" . $reference_id . " AND code=" . $db->qstr($specimen->code);
         echo $sql . "\n";
         $result = $db->Execute($sql);
         if ($result == false) {
             die("failed [" . __FILE__ . ":" . __LINE__ . "]: " . $sql);
Exemple #2
0
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;
}
Exemple #3
0
            $xml_doc = new DOMDocument();
            $xml_doc->loadXML($xml);
            $json = $xp->transformToXML($xml_doc);
            //echo $json;
            $json = str_replace("\n\"", "\"", $json);
            $data = json_decode($json);
            //print_r($data);
            if (isset($data->status)) {
                if ($data->status == 'ok') {
                    $state = 200;
                    $data->record[0]->bci = 'urn:lsid:biocol.org:col:35143';
                    $data->record[0]->title = 'CASENT' . $id;
                }
            }
            if ($state == 200) {
                store_specimen($data->record[0]);
                $item = $data->record[0];
            }
        }
    }
}
switch ($state) {
    case 404:
        ob_start();
        header('HTTP/1.1 404 Not Found');
        header('Status: 404 Not Found');
        $_SERVER['REDIRECT_STATUS'] = 404;
        break;
    case 400:
        ob_start();
        header('HTTP/1.0 400');