Followup Adding system preference XSLT*FileName
[koha.git] / opac / unapi
index a51f9fa..cd17881 100755 (executable)
@@ -12,15 +12,37 @@ use HTTP::Request::Common;
 my $cgi = new CGI;
 binmode(STDOUT, "utf8"); #output as utf8
 my $baseurl = C4::Context->preference('OPACBaseURL');
+warn "Warning: OPACBaseURL not set in system preferences" unless $baseurl;
 
 my $id = $cgi->param('id');
 my $format = $cgi->param('format');
 if ($id && $format) {
+
     # koha:isbn:0152018484
     if ($id =~ /isbn/) {
         $id =~ s/koha:isbn://;
-        my $url = "http://$baseurl:9998/biblios?version=1.1&operation=searchRetrieve&query=$id&startRecord=1&maximumRecords=20&recordSchema=$format";
-        my $content = get($url);
+
+        # two ways to do this, one via the SRU Zebra server (fast)
+        # FIXME - getting the SRU URL this way is purely guesswork
+        $baseurl =~ s/:\d+$//; # parse off OPAC port
+        my $url = "$baseurl:9998/biblios?version=1.1&operation=searchRetrieve&query=$id&startRecord=1&maximumRecords=20&recordSchema=$format";
+        my $content= get($url);
+
+        # the other via XSL parsing (not as fast)
+        unless ($content) {
+            
+        eval {
+            my $conn = C4::Context->Zconn('biblioserver');
+            $conn->option(preferredRecordSyntax => $format);
+            my $rs = $conn->search_pqf('@attr 1=7 '.$id);
+            my $n = $rs->size();
+            $content = $rs->record(0)->raw();
+        };
+        if ($@) {
+            print "Error ", $@->code(), ": ", $@->message(), "\n";
+        }
+
+        }
         print $cgi->header( -type =>'application/xml' );
         print $content;
     }