koha-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Koha-cvs] koha/z3950 search.pl


From: Joshua Ferraro
Subject: [Koha-cvs] koha/z3950 search.pl
Date: Mon, 26 Feb 2007 13:34:22 +0000

CVSROOT:        /sources/koha
Module name:    koha
Changes by:     Joshua Ferraro <kados>  07/02/26 13:34:22

Modified files:
        z3950          : search.pl 

Log message:
        reverting to previous version

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/z3950/search.pl?cvsroot=koha&r1=1.7&r2=1.8

Patches:
Index: search.pl
===================================================================
RCS file: /sources/koha/koha/z3950/search.pl,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- search.pl   1 Sep 2006 23:01:33 -0000       1.7
+++ search.pl   26 Feb 2007 13:34:22 -0000      1.8
@@ -1,5 +1,5 @@
 #!/usr/bin/perl
-
+# This is a completely new Z3950 clients search using async ZOOM -TG 02/11/06
 # Copyright 2000-2002 Katipo Communications
 #
 # This file is part of Koha.
@@ -26,15 +26,15 @@
 use C4::Biblio;
 use C4::Context;
 use C4::Breeding;
-use MARC::File::USMARC;
+use C4::Koha;
 use ZOOM;
-use Encode;;
 
 my $input = new CGI;
 my $dbh = C4::Context->dbh;
 my $error = $input->param('error');
-my $oldbiblionumber=$input->param('oldbiblionumber');
-$oldbiblionumber=0 unless $oldbiblionumber;
+my $biblionumber=$input->param('oldbiblionumber');
+$biblionumber=0 unless $biblionumber;
+my $frameworkcode=$input->param('frameworkcode');
 my $title = $input->param('title');
 my $author = $input->param('author');
 my $isbn = $input->param('isbn');
@@ -50,60 +50,68 @@
 my $database;
 my $port;
 my $marcdata;
-my $encoding=C4::Context->preference("marcflavour");
+my @encoding;
 my @results;
 my $count;
 my $toggle;
-my @breeding_loop = ();
 my $record;
 my $oldbiblio;
 my $dbh = C4::Context->dbh;
 my $errmsg;
 my @serverloop=();
 my @serverhost;
-unless ($random) { # if random is a parameter => we're just waiting for the 
search to end, it's a refresh.
-$random =rand(1000000000);
-}
-
+my @breeding_loop = ();
 
-my ($template, $loggedinuser, $cookie);
-if ($op ne "do_search"){
+my $DEBUG = 0; # if set to 1, many debug message are send on syslog.
 
-my $sth=$dbh->prepare("select id,host,checked from z3950servers  order by 
host");
-$sth->execute();
-while ($server=$sth->fetchrow_hashref) {
-my %temploop;
-$temploop{server}=$server->{host};
-$temploop{id}=$server->{id};
-$temploop{checked}=$server->{checked};
-push (@serverloop, \%temploop);
+unless ($random) { # this var is not useful anymore just kept to keep rel2_2 
compatibility
+    $random =rand(1000000000);
 }
-($template, $loggedinuser, $cookie)
-= get_template_and_user({template_name => "z3950/searchresult.tmpl",
+
+my ($template, $loggedinuser, $cookie)= get_template_and_user({
+                template_name => "z3950/searchresult.tmpl",
                                query => $input,
                                type => "intranet",
                                authnotrequired => 1,
                                flagsrequired => {catalogue => 1},
                                debug => 1,
                                });
-$template->param(isbn=>$isbn, issn=>$issn,title=>$title,author=>$author,
+
+$template->param(
+        intranetcolorstylesheet => 
C4::Context->preference("intranetcolorstylesheet"),
+        intranetstylesheet => C4::Context->preference("intranetstylesheet"),
+        IntranetNav => C4::Context->preference("IntranetNav"),
+        frameworkcode => $frameworkcode,
+        );
+
+if ($op ne "do_search"){
+    my $sth=$dbh->prepare("select id,host,checked from z3950servers  order by 
host");
+    $sth->execute();
+    while ($server=$sth->fetchrow_hashref) {
+        my %temploop;
+        $temploop{server}=$server->{host};
+        $temploop{id}=$server->{id};
+        $temploop{checked}=$server->{checked};
+        push (@serverloop, \%temploop);
+    }
+    $template->param(isbn=>$isbn, issn=>$issn,title=>$title,author=>$author,
                                                serverloop => address@hidden,
                                                opsearch => "search",
-                                               oldbiblionumber => 
$oldbiblionumber,
+                        oldbiblionumber => $biblionumber,
                                                );
-output_html_with_http_headers $input, $cookie, $template->output;
-
+    output_html_with_http_headers $input, $cookie, $template->output;
 }else{
+    my @id=$input->param('id');
+    my @oConnection;
+    my @oResult;
+    my $s=0;
 
-my @id=$input->param('id');
-my @oConnection;
-my @oResult;
-my $s=0;
                                                        if ($isbn ne "/" || 
$issn ne "/") {
                                                                $attr='1=7';
-                                                       $term=$isbn if ($isbn 
ne"/");
-                                                       $term=$issn if ($issn 
ne"/");
-                                                       } elsif ($title ne"/") {
+#         warn "isbn : $isbn";
+        $term=$isbn if ($isbn ne "/");
+        $term=$issn if ($issn ne "/");
+    } elsif ($title ne "/") {
                                                                $attr='1=4 
@attr 4=1  ';
                                                        $term=$title;
                                                        } elsif ($author ne 
"/") {
@@ -111,56 +119,55 @@
                                                        $term=$author;
                                                        } 
 
-                                                       
-my $query="address@hidden $attr \"$term\"";    
-                       
-  foreach my $servid ( @id){
-  my $sth=$dbh->prepare("select name, port, db, host from z3950servers where 
id=?");
+    my $query="address@hidden $attr \"$term\"";        
+    warn "query ".$query if $DEBUG;
+    foreach my $servid (@id){
+        my $sth=$dbh->prepare("select * from z3950servers where id=?");
   $sth->execute($servid);
-
     while ($server=$sth->fetchrow_hashref) {
        my $noconnection=0;
-       #$numberpending=1;
-                                                       
        my $option1=new ZOOM::Options();
-       $option1->option(async=>1);
+            $option1->option('async'=>1);
        $option1->option('elementSetName', 'F');
        $option1->option('databaseName',$server->{db})  ;
-       $option1->option('preferredRecordSyntax', 'USMARC');
-        $oConnection[$s]=create ZOOM::Connection($option1);
-       $oConnection[$s]->connect($server->{name}, $server->{port});
+            $option1->option('user',$server->{userid}) if $server->{userid};
+            $option1->option('password',$server->{password})  if 
$server->{password};
+            $option1->option('preferredRecordSyntax', $server->{syntax});
+            $oConnection[$s]=create ZOOM::Connection($option1) || $DEBUG && 
warn ("something went wrong: ".$oConnection[$s]->errmsg());
+            warn ("server data",$server->{name}, $server->{port}) if $DEBUG;
+            $oConnection[$s]->connect($server->{host}, $server->{port}) || 
$DEBUG && warn ("something went wrong: ".$oConnection[$s]->errmsg());
        $serverhost[$s]=$server->{host};
+            $encoding[$s]=$server->{syntax};
        $s++;
     }## while fetch
-
   }# foreach
-my $nremaining = $s;
-my $firstresult=1;
+    my $nremaining = $s;
+    my $firstresult=1;
+
  for (my $z=0 ;$z<$s;$z++){
-$oResult[$z] = $oConnection[$z]->search_pqf($query);
+        warn "doing the search" if $DEBUG;
+        $oResult[$z] = $oConnection[$z]->search_pqf($query) || $DEBUG && warn 
("somthing went wrong: " . $oConnection[$s]->errmsg());
+#$oResult[$z] = $oConnection[$z]->search_pqf($query);
+    }
 
-}
 AGAIN:
  my $k;
-my $event;
+    my $event;
   while (($k = ZOOM::event(address@hidden)) != 0) {
        $event = $oConnection[$k-1]->last_event();
-# warn ("connection ", $k-1, ": event $event (", ZOOM::event_str($event), 
")\n");
+        warn ("connection ", $k-1, ": event $event (", 
ZOOM::event_str($event), ")\n") if $DEBUG;
        last if $event == ZOOM::Event::ZEND;
    }
-if ($k != 0) {
+
+    if ($k != 0) {
        $k--;
-#warn $serverhost[$k];
+        warn $serverhost[$k] if $DEBUG;
         my($error, $errmsg, $addinfo, $diagset) = $oConnection[$k]->error_x();
        if ($error) {
-
-       warn "$k $serverhost[$k] error $query: $errmsg ($error) $addinfo\n";
+            warn "$k $serverhost[$k] error $query: $errmsg ($error) 
$addinfo\n" if $DEBUG;
        goto MAYBE_AGAIN;
        }
-       
        my $numresults=$oResult[$k]->size() ;                                   
                        
-                                                                       
-
        my $i;
        my $result='';
        if ($numresults>0){
@@ -168,21 +175,17 @@
                        my $rec=$oResult[$k]->record($i);                       
                                                        
                        my $marcrecord;
                        $marcdata = $rec->raw();                                
                                                        
-                       $marcrecord = MARC::File::USMARC::decode($marcdata);
-                       
-                       my $marcxml=$marcrecord->as_xml_record($marcrecord);
-                       $marcxml=Encode::encode('utf8',$marcxml);
-                       #$marcxml=Encode::decode('utf8',$marcxml);
-                       my $xmlhash=XML_xml2hash_onerecord($marcxml);           
                                
-               my $oldbiblio = XMLmarc2koha_onerecord($dbh,$xmlhash,'biblios');
+                               $marcrecord = 
MARC::Record->new_from_usmarc($marcdata);#rec->raw();
+                #$marcrecord= FixEncoding($marcdata);
+####WARNING records coming from Z3950 clients are in various character sets 
MARC8,UTF8,UNIMARC etc
+## In HEAD i change everything to UTF-8
+# In rel2_2 i am not sure what encoding is so no character conversion is done 
here
+##Add necessary encoding changes to here -TG
+                my $oldbiblio = MARCmarc2koha($dbh,$marcrecord,"");
                                $oldbiblio->{isbn} =~ s/ |-|\.//g,
-                       $oldbiblio->{isbn} = substr($oldbiblio->{isbn},0,10);
                        $oldbiblio->{issn} =~ s/ |-|\.//g,
-                       $oldbiblio->{issn} = substr($oldbiblio->{issn},0,10);
-
-my 
($notmarcrecord,$alreadyindb,$alreadyinfarm,$imported,$bid)=ImportBreeding($marcdata,1,$serverhost[$k],$encoding,$random);
+                my 
($notmarcrecord,$alreadyindb,$alreadyinfarm,$imported,$breedingid)=ImportBreeding($marcdata,1,$serverhost[$k],$encoding[$k],$random);
                        my %row_data;
- @breeding_loop = ();
        if ($i % 2) {
                $toggle="#ffffcc";
        } else {
@@ -191,38 +194,26 @@
        $row_data{toggle} = $toggle;
        $row_data{server} = $serverhost[$k];
        $row_data{isbn} = $oldbiblio->{isbn};
-
        $row_data{title} =$oldbiblio->{title};
        $row_data{author} = $oldbiblio->{author};
-       $row_data{id} = $bid;
-       $row_data{oldbiblionumber}=$oldbiblionumber;
+                $row_data{id} = $breedingid;
+                $row_data{oldbiblionumber}=$biblionumber;
        push (@breeding_loop, \%row_data);
+            }# upto 5 results
 
-                                               
-}# $numresults
-}#for up to 5 results
-}# if $k !=0
-
-my ($template, $loggedinuser, $cookie)
-= get_template_and_user({template_name => "z3950/searchresult.tmpl",
-                               query => $input,
-                               type => "intranet",
-                               authnotrequired => 1,
-                               flagsrequired => {catalogue => 1},
-                               debug => 1,
-                               });
-$numberpending=$nremaining-1;
-$template->param(
-                                               breeding_loop => address@hidden,
-#                                               refresh=>($numberpending eq 0 
? "" : "search.pl?random=$random"),
+        }#$numresults
+    }# if $k !=0
+    $numberpending=$nremaining-1;
+    $template->param(breeding_loop => address@hidden, server=>$serverhost[$k],
                                                numberpending => $numberpending,
-#                                              oldbiblionumber => 
$oldbiblionumber,
                                                );
-output_html_with_http_headers $input, "", $template->output if $firstresult==1;
-$firstresult++;
-print  $template->output if $firstresult !=1;
-MAYBE_AGAIN:
-if (--$nremaining > 0) {
+    output_html_with_http_headers $input, $cookie, $template->output if 
$numberpending==0;
+
+#      print  $template->output  if $firstresult !=1;
+    $firstresult++;
+
+    MAYBE_AGAIN:
+        if (--$nremaining > 0) {
     goto AGAIN;
-}
+        }
 } ## if op=search




reply via email to

[Prev in Thread] Current Thread [Next in Thread]