X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=cataloguing%2Fz3950_search.pl;h=a44b5ea50c67e50c0108f7def69975042426bd3b;hb=a29a5df175f4112302de71456d4f21d0dd7f48cf;hp=08b45d306fce9360510b3dbb30bd72cbcf096184;hpb=16fef8ba3e18c12347f35ff24a43c20d7ee53a8c;p=koha_fer diff --git a/cataloguing/z3950_search.pl b/cataloguing/z3950_search.pl index 08b45d306f..a44b5ea50c 100755 --- a/cataloguing/z3950_search.pl +++ b/cataloguing/z3950_search.pl @@ -14,11 +14,12 @@ # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR # A PARTICULAR PURPOSE. See the GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License along with -# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place, -# Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. use strict; +#use warnings; FIXME - Bug 2505 use CGI; use C4::Auth; @@ -32,20 +33,22 @@ use ZOOM; my $input = new CGI; my $dbh = C4::Context->dbh; -my $error = $input->param('error'); -my $biblionumber = $input->param('biblionumber'); -$biblionumber = 0 unless $biblionumber; +my $error = $input->param('error'); +my $biblionumber = $input->param('biblionumber') || 0; my $frameworkcode = $input->param('frameworkcode'); my $title = $input->param('title'); my $author = $input->param('author'); my $isbn = $input->param('isbn'); my $issn = $input->param('issn'); my $lccn = $input->param('lccn'); -my $subject= $input->param('subject'); -my $dewey = $input->param('dewey'); -my $random = $input->param('random'); +my $lccall = $input->param('lccall'); +my $subject = $input->param('subject'); +my $dewey = $input->param('dewey'); +my $controlnumber = $input->param('controlnumber'); +my $stdid = $input->param('stdid'); +my $srchany = $input->param('srchany'); +my $random = $input->param('random') || rand(1000000000); # this var is not useful anymore just kept for rel2_2 compatibility my $op = $input->param('op'); -my $noconnection; my $numberpending; my $attr = ''; my $term; @@ -57,7 +60,6 @@ my $marcdata; my @encoding; my @results; my $count; -my $toggle; my $record; my $oldbiblio; my $errmsg; @@ -68,34 +70,31 @@ my @breeding_loop = (); my $DEBUG = 0; # if set to 1, many debug message are send on syslog. -unless ($random) -{ # this var is not useful anymore just kept to keep rel2_2 compatibility - $random = rand(1000000000); -} - -my ( $template, $loggedinuser, $cookie ) = get_template_and_user( - { +my ( $template, $loggedinuser, $cookie ) = get_template_and_user({ template_name => "cataloguing/z3950_search.tmpl", query => $input, type => "intranet", authnotrequired => 1, flagsrequired => { catalogue => 1 }, debug => 1, - } -); +}); $template->param( frameworkcode => $frameworkcode, ); if ( $op ne "do_search" ) { - my $sth = $dbh->prepare("select id,host,name,checked from z3950servers order by host"); + my $sth = $dbh->prepare("SELECT id,host,name,checked FROM z3950servers ORDER BY rank, name"); $sth->execute(); my $serverloop = $sth->fetchall_arrayref( {} ); $template->param( isbn => $isbn, issn => $issn, lccn => $lccn, + lccall => $lccall, title => $title, author => $author, + controlnumber=> $controlnumber, + stdid => $stdid, + srchany => $srchany, serverloop => $serverloop, opsearch => "search", biblionumber => $biblionumber, @@ -104,11 +103,19 @@ if ( $op ne "do_search" ) { } else { my @id = $input->param('id'); + + if ( not defined @id ) { + # empty server list -> report and exit + $template->param( emptyserverlist => 1 ); + output_html_with_http_headers $input, $cookie, $template->output; + exit; + } + my @oConnection; my @oResult; my @errconn; my $s = 0; - my $query; + my $query = ''; my $nterms; if ($isbn || $issn) { $term=$isbn if ($isbn); @@ -139,25 +146,40 @@ else { $query .= " \@attr 1=9 $lccn "; $nterms++; } + if ($lccall) { + $query .= " \@attr 1=16 \@attr 2=3 \@attr 3=1 \@attr 4=1 \@attr 5=1 \@attr 6=1 \"$lccall\" "; + $nterms++; + } + if ($controlnumber) { + $query .= " \@attr 1=12 \"$controlnumber\" "; + $nterms++; + } + if ($stdid) { + $query .= " \@attr 1=1007 \"$stdid\" "; + $nterms++; + } + if ($srchany) { + $query .= " \@attr 1=1016 \"$srchany\" "; + $nterms++; + } for my $i (1..$nterms-1) { $query = "\@and " . $query; } warn "query ".$query if $DEBUG; foreach my $servid (@id) { - my $sth = $dbh->prepare("select * from z3950servers where id=?"); + my $sth = $dbh->prepare("SELECT * FROM z3950servers WHERE id=? ORDER BY rank, name"); $sth->execute($servid); while ( $server = $sth->fetchrow_hashref ) { warn "serverinfo ".join(':',%$server) if $DEBUG; - my $noconnection = 0; my $option1 = new ZOOM::Options(); - $option1->option( 'async' => 1 ); - $option1->option( 'elementSetName', 'F' ); - $option1->option( 'databaseName', $server->{db} ); - $option1->option( 'user', $server->{userid} ) if $server->{userid}; - $option1->option( 'password', $server->{password} ) - if $server->{password}; - $option1->option( 'preferredRecordSyntax', $server->{syntax} ); + $option1->option('async' => 1); + $option1->option('elementSetName', 'F'); + $option1->option('databaseName', $server->{db}); + $option1->option('user', $server->{userid} ) if $server->{userid}; + $option1->option('password', $server->{password}) if $server->{password}; + $option1->option('preferredRecordSyntax', $server->{syntax}); + $option1->option( 'timeout', $server->{timeout} ) if ($server->{timeout}); $oConnection[$s] = create ZOOM::Connection($option1) || $DEBUG && warn( "" . $oConnection[$s]->errmsg() ); @@ -201,23 +223,16 @@ warn "query ".$query if $DEBUG; $oConnection[$k]->error_x(); if ($error) { if ($error =~ m/^(10000|10007)$/ ) { - push(@errconn, {'server' => $serverhost[$k]}); + push(@errconn, {'server' => $serverhost[$k], 'error' => $error}); } - warn "$k $serverhost[$k] error $query: $errmsg ($error) $addinfo\n" - if $DEBUG; - + $DEBUG and warn "$k $serverhost[$k] error $query: $errmsg ($error) $addinfo\n"; } else { my $numresults = $oResult[$k]->size(); my $i; my $result = ''; if ( $numresults > 0 ) { - for ( - $i = 0 ; - $i < ( ( $numresults < 20 ) ? ($numresults) : (20) ) ; - $i++ - ) - { + for ($i = 0; $i < (($numresults < 20) ? $numresults : 20); $i++) { my $rec = $oResult[$k]->record($i); if ($rec) { my $marcrecord; @@ -231,34 +246,36 @@ warn "query ".$query if $DEBUG; # 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 = TransformMarcToKoha( $dbh, $marcrecord, "" ); - $oldbiblio->{isbn} =~ s/ |-|\.//g, - $oldbiblio->{issn} =~ s/ |-|\.//g, + $oldbiblio->{isbn} =~ s/ |-|\.//g if $oldbiblio->{isbn}; + # pad | and ( with spaces to allow line breaks in the HTML + $oldbiblio->{isbn} =~ s/\|/ \| /g if $oldbiblio->{isbn}; + $oldbiblio->{isbn} =~ s/\(/ \(/g if $oldbiblio->{isbn}; + + $oldbiblio->{issn} =~ s/ |-|\.//g if $oldbiblio->{issn}; + # pad | and ( with spaces to allow line breaks in the HTML + $oldbiblio->{issn} =~ s/\|/ \| /g if $oldbiblio->{issn}; + $oldbiblio->{issn} =~ s/\(/ \(/g if $oldbiblio->{issn}; my ( $notmarcrecord, $alreadyindb, $alreadyinfarm, $imported, $breedingid ) = ImportBreeding( $marcdata, 2, $serverhost[$k], $encoding[$k], $random, 'z3950' ); my %row_data; - if ( $i % 2 ) { - $toggle = 1; - } - else { - $toggle = 0; - } - $row_data{toggle} = $toggle; $row_data{server} = $servername[$k]; $row_data{isbn} = $oldbiblio->{isbn}; $row_data{lccn} = $oldbiblio->{lccn}; $row_data{title} = $oldbiblio->{title}; $row_data{author} = $oldbiblio->{author}; + $row_data{date} = $oldbiblio->{copyrightdate}; + $row_data{edition} = $oldbiblio->{editionstatement}; $row_data{breedingid} = $breedingid; $row_data{biblionumber} = $biblionumber; push( @breeding_loop, \%row_data ); } else { - push(@breeding_loop,{'toggle'=>($i % 2)?1:0,'server'=>$servername[$k],'title'=>join(': ',$oConnection[$k]->error_x()),'breedingid'=>-1,'biblionumber'=>-1}); + push(@breeding_loop,{'server'=>$servername[$k],'title'=>join(': ',$oConnection[$k]->error_x()),'breedingid'=>-1,'biblionumber'=>-1}); } # $rec - } # upto 5 results + } } #$numresults } } # if $k !=0