Skip to content

Commit

Permalink
[#14882151 followup] additional Z39.50 tweaks:
Browse files Browse the repository at this point in the history
- general Ajax fix for IE: send no cache HTTP header
- general widgets tweak: removed search button, which wasn't
  easily aligned across browsers; prettify width of page
  jumper input box; send user to page 1 upon positive search
  results upon hitting [ENTER] (no redirect if paging or
  sorting even if we have search matches)
- Z39.50 Servers Administration: commented out Rank; select
  MARC21/USMARC by default on ADD; put magnifying glass icon
  on non-Yahoo button
- Z39.50 Search: commented out button for adding new MARC;
  force sorting of errors to the bottom; allow skipping nonMarc
  such as errors; allow open search results in modal
- modify query of C4::Session::Defaults::Items to not clash with
  Z39.50 usage
- dupecheck unique Target Name for both ADD and EDIT
- confirmation msg before target server delete
- fix crushed text in hostname:port view for patron selected targets
- one more case of no data: all errors
  • Loading branch information
ctfliblime authored and hgq committed Sep 12, 2011
1 parent 3996af7 commit f4278f7
Show file tree
Hide file tree
Showing 8 changed files with 387 additions and 242 deletions.
14 changes: 8 additions & 6 deletions C4/Members.pm
Expand Up @@ -325,12 +325,14 @@ sub GetMemberZ3950Servers {
if ($borrowernumber) {
if ($full) {
$data = C4::Context->dbh->selectall_arrayref('
SELECT z.*,(z.id=?) as isCGP, (z.id=b.id and b.borrowernumber=?) as uSel
FROM z3950servers z
LEFT JOIN borrower_z3950servers b ON z.id=b.id
WHERE z.id <> 0
GROUP BY z.id
ORDER BY isCGP DESC, z.name', {Slice => {}}, $cgpid, $borrowernumber) // [];
SELECT z.*,(z.id=?) as isCGP FROM z3950servers z
ORDER BY isCGP DESC, z.name',{Slice=>{}},$cgpid) // [];
my $sth = C4::Context->dbh->prepare('SELECT id FROM borrower_z3950servers WHERE borrowernumber=?');
$sth->execute($borrowernumber);
my $bor = $sth->fetchall_arrayref() // [];
foreach(@$data) {
$$_{uSel} = ($$_{id} ~~ @$bor)? 1:0;
}
}
else {
$data = C4::Context->dbh->selectall_arrayref('
Expand Down
6 changes: 4 additions & 2 deletions C4/Session/Defaults/Items.pm
Expand Up @@ -119,7 +119,8 @@ sub load {
my $branchcode = C4::Context->userenv->{'branch'};

my $dbh = C4::Context->dbh;
my $sql = "SELECT * FROM session_defaults WHERE branchcode = ? AND name = ?";
my $sql = "SELECT * FROM session_defaults WHERE branchcode = ? AND name = ?
AND `key` LIKE 'session_default_%'";
my $sth = $dbh->prepare( $sql );
$sth->execute( $branchcode, $name );

Expand Down Expand Up @@ -179,7 +180,8 @@ sub getSavedDefaultsList {
$branchcode = '%' if ( $flags->{'superlibrarian'} && !$params{'branchcode'} );

my $dbh = C4::Context->dbh;
my $sql = "SELECT DISTINCT( name ) FROM session_defaults WHERE branchcode LIKE ? ORDER BY name";
my $sql = "SELECT DISTINCT( name ) FROM session_defaults WHERE branchcode LIKE ?
AND `key` LIKE 'session_default_%' ORDER BY name";
my $sth = $dbh->prepare( $sql );
$sth->execute( $branchcode );

Expand Down
72 changes: 40 additions & 32 deletions C4/Z3950.pm
Expand Up @@ -406,7 +406,6 @@ sub doSearch {
['srchany' ,0, 1016 ],
);
foreach(@q) {
warn "$$_[0]=$g{$$_[0]}-----------\n";
next unless $g{$$_[0]};
if ($$_[1]==1){ $g{$$_[0]} = utf8::decode($g{$$_[0]}) }
elsif ($$_[1]==2){ $g{$$_[0]} =~ s/ /\^/g; }
Expand All @@ -421,7 +420,6 @@ warn "$$_[0]=$g{$$_[0]}-----------\n";
for my $i(1..$nterms-1) { $query = "\@and " . $query; }
=cut

warn "query=$query---------------------\n";
my $dbh = C4::Context->dbh;
TARGET: {
foreach my $servid (@id) {
Expand All @@ -435,6 +433,7 @@ warn "query=$query---------------------\n";
$option1->option('user', $server->{userid} ) if $server->{userid};
$option1->option('password', $server->{password}) if $server->{password};
$option1->option('preferredRecordSyntax', $server->{syntax});
$option1->option('presentChunk',$g{maxper});
$oConnection[$s] = create ZOOM::Connection($option1)
|| $DEBUG
&& warn( "" . $oConnection[$s]->errmsg() );
Expand All @@ -449,8 +448,7 @@ warn "query=$query---------------------\n";
if($msg =~ /^No error/) { }
else {
$servers[$s]{_err} = 1;
push @out, { 'error' => "Connection error: $msg, $servers[$s]{host}" };
last TARGET;
push @out, _searchErr($servers[$s],"Connection error: $msg");
}
$s++;
} ## while fetch
Expand All @@ -459,10 +457,12 @@ warn "query=$query---------------------\n";
} # eof TARGET

for ( my $z = 0 ; $z < $s ; $z++ ) {
warn "doing the search on $servers[$z]{host}" if $DEBUG;
$oResult[$z] = $oConnection[$z]->search_pqf($query)
|| $DEBUG
&& warn( "somthing went wrong: " . $oConnection[$s]->errmsg() );
warn "doing the search on $servers[$z]{host}" if $DEBUG;
unless($oResult[$z] = $oConnection[$z]->search_pqf($query)) {
warn( "somthing went wrong: " . $oConnection[$s]->errmsg() ) if $DEBUG;
$servers[$z]{_err} = 1;
push @out, _searchErr($servers[$z],$oConnection[$s]->errmsg());
}

# $oResult[$z] = $oConnection[$z]->search_pqf($query);
}
Expand All @@ -473,25 +473,24 @@ warn "query=$query---------------------\n";
my $etime = time + $g{maxwait};
while ( ( $k = ZOOM::event( \@oConnection ) ) != 0 ) {
my $z = $k - 1;
next if $servers[$z]{_err};
my ( $error, $errmsg, $addinfo, $diagset ) = $oConnection[$z]->error_x();
if ($error) {
if ($error =~ m/^(10000|10007)$/ ) {
push @out, {'error' => "$servers[$z]{host}: $error"};
push @out, _searchErr($servers[$z],"Error: $error: $errmsg");
next;
}
$DEBUG and warn "$z $servers[$z]{host} error $query: $errmsg ($error) $addinfo\n";
next;
}

$event = $oConnection[$z]->last_event();
my $msg = ZOOM::event_str($event);
last SEARCH if @out == $g{maxrecs};
last SEARCH if @out >= $g{maxrecs};
last SEARCH if time > $etime;

warn "host $z: $servers[$z]{host} event: $event ($msg)\n";
if ($event == ZOOM::Event::RECV_APDU) { # last if $msg ~~ 'end';
my $numresults = $oResult[$z]->size();
$servers[$z]{numresults} = $numresults;
warn "numresults at conn $z,$servers[$z]{host}=$numresults--\n";
my $i;
my $result = '';
if ( $numresults > 0 ) {
Expand All @@ -516,27 +515,26 @@ warn "query=$query---------------------\n";
$notmarcrecord, $alreadyindb, $alreadyinfarm,
$imported, $breedingid
) = C4::Breeding::ImportBreeding( $marcdata, 2, $servers[$z]{host}, $servers[$z]{encoding}, $g{random}, 'z3950' );
push @out, {
server => $servers[$z]{name},
serverid => $servers[$z]{id},
isbn => $oldbiblio->{isbn},
lccn => $oldbiblio->{lccn},
title => $oldbiblio->{title},
author => $oldbiblio->{author},
date => $oldbiblio->{copyrightdate},
edition => $oldbiblio->{editionstatement},
breedingid => $breedingid,
biblionumber => $g{biblionumber},
};
if ($breedingid) {
push @out, {
server => $servers[$z]{name},
serverid => $servers[$z]{id},
isbn => $oldbiblio->{isbn},
lccn => $oldbiblio->{lccn},
title => $oldbiblio->{title},
author => $oldbiblio->{author},
date => $oldbiblio->{copyrightdate},
edition => $oldbiblio->{editionstatement},
breedingid => $breedingid,
biblionumber => $g{biblionumber},
};
}
else {
push @out, _searchErr($servers[$z],'Could not transform Marc to Koha');
}
}
else {
push @out,{
'error' => join(': ',$oConnection[$z]->error_x()),
'server' => $servers[$z]{name},
'title' => join(': ',$oConnection[$z]->error_x()),
'breedingid' => -1,
'biblionumber' => -1
};
push @out, _searchErr($servers[$z],join(': ',$oConnection[$z]->error_x()));
} # $rec
}
} #$numresults
Expand All @@ -548,6 +546,16 @@ warn "query=$query---------------------\n";
return \@out;
}

sub _searchErr {
my($srv,$msg) = @_;
return {
'serverid' => $$srv{id},
'server' => $$srv{name},
'error' => "$$srv{host}: $msg",
'breedingid' => -1,
'biblionumber' => -1,
};
}
1;
__END__
94 changes: 50 additions & 44 deletions Koha/Squatting/Z3950.pm
Expand Up @@ -96,28 +96,34 @@ use Carp;
sub Connect { # test a connection to a z3950 server
my($self,$id) = @_;
$self->{_raw} = 1;
my $maxwait = $self->input->{maxwait} || 10; # ignore zero
my($srv);
if ($id) { $srv = ShowOne($self, $id) }
else { $srv = $self->input }
my $ops = new ZOOM::Options();
$ops->option('async' => 0);
#$ops->option('async' => 1); # this gets stuck on the first result
$ops->option('elementSetName', 'F');
$ops->option('databaseName',$$srv{dbname});
$ops->option('user',$$srv{userid});
$ops->option('password',$$srv{password});
$ops->option('preferredRecordSyntax',$$srv{syntax});
$ops->option('timeout',$maxwait);
my $conn = create ZOOM::Connection($ops);
try {$conn->connect($$srv{host},$$srv{port}); }
catch {};
$conn->connect($$srv{host},$$srv{port});
my $errmsg = $conn->errmsg();
warn "---------------- connect $$srv{host} errmsg=$errmsg--\n";
$conn->destroy();
warn "---------------- connect $$srv{name} $$srv{host} errmsg=$errmsg--\n";

## for ajax async queue
my %out = ();
if ($errmsg =~ /^No error/) {
$self->v->{out} = {ok=>1};
$out{ok} = 1;
}
else {
$self->v->{out} = {err=>$errmsg};
$out{ok} = 0;
$out{err} = $errmsg;
}
return $self->render('_dat',_SetContentType($self));
return _dat_out($self, \%out);
}

sub ShowMemberTargets { #
Expand Down Expand Up @@ -197,7 +203,7 @@ warn "---------------- connect $$srv{host} errmsg=$errmsg--\n";

sub SaveMemberOps {
my($self,$borrowernumber) = @_;
my @f = qw(maxrecs maxper maxwait async zcnt limit);
my @f = qw(maxrecs maxper maxwait async zcnt skippy limit);
my %ops;
foreach(@f) { $ops{$_} = $self->input->{$_} }
if (my $ok = C4::Session::Any::save(
Expand Down Expand Up @@ -281,46 +287,46 @@ warn "---------------- connect $$srv{host} errmsg=$errmsg--\n";
use Rose::DB::Object::Helpers qw(as_tree as_json);
use JSON qw(to_json);

sub RenderJson {
sub RenderJson {
my($self,$v) = @_;
return to_json($v->{out});
}
sub RenderRdbAsJson {
my ($self, $v) = @_;
return as_json($v->{out});
}
}
sub RenderRdbAsJson {
my ($self, $v) = @_;
return as_json($v->{out});
}

sub RenderRdbSetAsJson {
my ($self, $v) = @_;
my @out;
if ((ref($v->{out}) ~~ 'ARRAY') && !$self->{_raw}) {
for my $r (@{$v->{out}}) {
my $t = as_tree($r->db_obj);
$t->{uri} = R('ShowOne', $t->{id});
push @out, $t;
}
}
else {
@out = ($v->{out});
}
return to_json(\@out);
}
sub RenderRdbSetAsJson {
my ($self, $v) = @_;
my @out;
if ((ref($v->{out}) ~~ 'ARRAY') && !$self->{_raw}) {
for my $r (@{$v->{out}}) {
my $t = as_tree($r->db_obj);
$t->{uri} = R('ShowOne', $t->{id});
push @out, $t;
}
}
else {
@out = ($v->{out});
}
return to_json(\@out);
}

our @V = (
V('text/html',
_ => sub {'Not yet supported'},
403 => sub {'Permission denied'},
404 => sub {'File not found'},
202 => sub {'Connection succesful'},
204 => sub {'No data'},
deleted => sub {q()},
),
V('application/json',
_ => \&RenderRdbAsJson,
_dat => \&RenderJson,
_rdb_objset => \&RenderRdbSetAsJson,
),
);
our @V = (
V('text/html',
_ => sub {'Not yet supported'},
403 => sub {'Permission denied'},
404 => sub {'File not found'},
202 => sub {'Connection succesful'},
204 => sub {'No data'},
deleted => sub {q()},
),
V('application/json',
_ => \&RenderRdbAsJson,
_dat => \&RenderJson,
_rdb_objset => \&RenderRdbSetAsJson,
),
);
}

1;
49 changes: 49 additions & 0 deletions app-gpo.psgi
@@ -0,0 +1,49 @@
#!/usr/bin/env perl

use Koha;
use Plack::App::CGIBin;
use Plack::Builder;
use Koha::Plack::Util;

my $root = $ENV{KOHA_BASE} // '.';
my $app = Plack::App::CGIBin->new(root => $root)->to_app;

sub is_staff {
my $hostname = Koha::Plack::Util::GetCanonicalHostname(shift);
if ($ENV{KOHA_STAFF}) { return 1 } # for VPN with only IP
return $hostname =~ /-staff\./;
}

use Koha::Squatting::Reserve 'On::PSGI';
use Koha::Squatting::Z3950 'On::PSGI';
Koha::Squatting::Reserve->init;
Koha::Squatting::Z3950->init;


builder {
enable_if { $_[0]->{REMOTE_ADDR} eq '127.0.0.1' }
'Plack::Middleware::ReverseProxy';

enable 'Deflater';
enable 'HTTPExceptions';
enable 'MethodOverride';

enable 'Static', path => qr{^/opac-tmpl/}, root => "$root/koha-tmpl/";
enable 'Static', path => qr{^/intranet-tmpl/}, root => "$root/koha-tmpl/";

enable 'Status', path => qr{/C4/|/Koha/|/misc/|/t/|/xt/|/etc/}, status => 404;
enable 'Rewrite', rules => sub {
my $env = shift;
return 302 if (is_staff($env) && s{^/$}{/cgi-bin/koha/mainpage.pl});
return 302 if (!is_staff($env) && s{^/$}{/cgi-bin/koha/opac-main.pl});
if (!is_staff($env)) { s{^/cgi-bin/koha/}{/cgi-bin/koha/opac/}}
return;
};
enable 'Header', unset => ['Status'];
enable '+Koha::Plack::Localize';
mount '/reserves/' => sub {Koha::Squatting::Reserve->psgi(shift)};
mount '/z3950/' => sub {Koha::Squatting::Z3950->psgi(shift)};
mount '/cgi-bin/koha/' => $app;
};

0 comments on commit f4278f7

Please sign in to comment.