[Koha-patches] [PATCH 49/78] add order line through z3950 search
paul.poulain at biblibre.com
paul.poulain at biblibre.com
Thu May 28 18:32:59 CEST 2009
From: Paul Poulain <paul.poulain at biblibre.com>
---
acqui/z3950_search.pl | 297 ++++++++++++++++++++
.../prog/en/modules/acqui/z3950_search.tmpl | 141 +++++++++
2 files changed, 438 insertions(+), 0 deletions(-)
create mode 100755 acqui/z3950_search.pl
create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/acqui/z3950_search.tmpl
diff --git a/acqui/z3950_search.pl b/acqui/z3950_search.pl
new file mode 100755
index 0000000..c5d598b
--- /dev/null
+++ b/acqui/z3950_search.pl
@@ -0,0 +1,297 @@
+#!/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.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# 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
+
+use warnings;
+use strict;
+use CGI;
+
+use C4::Auth;
+use C4::Output;
+use C4::Biblio;
+use C4::Context;
+use C4::Breeding;
+use C4::Koha;
+use C4::Charset;
+use ZOOM;
+
+my $input = new CGI;
+my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
+ {
+ template_name => "acqui/z3950_search.tmpl",
+ query => $input,
+ type => "intranet",
+ authnotrequired => 1,
+ flagsrequired => { acquisition => 'order_manage' },
+ debug => 1,
+ }
+);
+
+my $dbh = C4::Context->dbh;
+my $error = $input->param('error');
+my $biblionumber = $input->param('biblionumber');
+$biblionumber = 0 unless $biblionumber;
+my $frameworkcode = $input->param('frameworkcode');
+warn($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 $op = $input->param('op');
+my $booksellerid = $input->param('booksellerid');
+my $basketno = $input->param('basketno');
+my $noconnection;
+my $numberpending;
+my $attr = '';
+my $term;
+my $host;
+my $server;
+my $database;
+my $port;
+my $marcdata;
+my @encoding;
+my @results;
+my $count;
+my $toggle;
+my $record;
+my $oldbiblio;
+my $errmsg;
+my @serverhost;
+my @servername;
+my @breeding_loop = ();
+my $random = $input->param('random');
+unless ($random)
+{ # this var is not useful anymore just kept to keep rel2_2 compatibility
+ $random = rand(1000000000);
+}
+
+my $DEBUG = 0; # if set to 1, many debug message are send on syslog.
+
+# get framework list
+my $frameworks = getframeworks;
+my @frameworkcodeloop;
+foreach my $thisframeworkcode ( keys %$frameworks ) {
+ my %row = (
+ value => $thisframeworkcode,
+ frameworktext => $frameworks->{$thisframeworkcode}->{'frameworktext'},
+ );
+ if ( %row->{'value'} eq $frameworkcode){
+ %row->{'active'} = 'true';
+ }
+ push @frameworkcodeloop, \%row;
+}
+
+$template->param( frameworkcode => $frameworkcode,
+ frameworkcodeloop => \@frameworkcodeloop,
+ booksellerid => $booksellerid,
+ basketno => $basketno);
+
+
+if ( $op ne "do_search" ) {
+ my $sth = $dbh->prepare("select id,host,name,checked from z3950servers order by host");
+ $sth->execute();
+ my $serverloop = $sth->fetchall_arrayref( {} );
+ $template->param(
+ isbn => $isbn,
+ issn => $issn,
+ lccn => $lccn,
+ title => $title,
+ author => $author,
+ serverloop => $serverloop,
+ opsearch => "search",
+ biblionumber => $biblionumber,
+ );
+ output_html_with_http_headers $input, $cookie, $template->output;
+}
+else {
+ my @id = $input->param('id');
+ my @oConnection;
+ my @oResult;
+ my $s = 0;
+ my $query;
+ my $nterms;
+ if ($isbn || $issn) {
+ $term=$isbn if ($isbn);
+ $term=$issn if ($issn);
+ $query .= " \@or \@attr 1=8 \"$term\" \@attr 1=7 \"$term\" ";
+ $nterms++;
+ }
+ if ($title) {
+ utf8::decode($title);
+ $query .= " \@attr 1=4 \"$title\" ";
+ $nterms++;
+ }
+ if ($author) {
+ utf8::decode($author);
+ $query .= " \@attr 1=1003 \"$author\" ";
+ $nterms++;
+ }
+ if ($dewey) {
+ $query .= " \@attr 1=16 \"$dewey\" ";
+ $nterms++;
+ }
+ if ($subject) {
+ utf8::decode($subject);
+ $query .= " \@attr 1=21 \"$subject\" ";
+ $nterms++;
+ }
+ if ($lccn) {
+ $query .= " \@attr 1=9 $lccn ";
+ $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=?");
+ $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} );
+ $oConnection[$s] = create ZOOM::Connection($option1)
+ || $DEBUG
+ && warn( "" . $oConnection[$s]->errmsg() );
+ warn( "server data", $server->{name}, $server->{port} ) if $DEBUG;
+ $oConnection[$s]->connect( $server->{host}, $server->{port} )
+ || $DEBUG
+ && warn( "" . $oConnection[$s]->errmsg() );
+ $serverhost[$s] = $server->{host};
+ $servername[$s] = $server->{name};
+ $encoding[$s] = ($server->{encoding}?$server->{encoding}:"iso-5426");
+ $s++;
+ } ## while fetch
+ } # foreach
+ my $nremaining = $s;
+ my $firstresult = 1;
+
+ for ( my $z = 0 ; $z < $s ; $z++ ) {
+ 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);
+ }
+
+sub displayresults {
+ my $k;
+ my $event;
+ while ( ( $k = ZOOM::event( \@oConnection ) ) != 0 ) {
+ $event = $oConnection[ $k - 1 ]->last_event();
+ warn( "connection ", $k - 1, ": event $event (",
+ ZOOM::event_str($event), ")\n" )
+ if $DEBUG;
+ last if $event == ZOOM::Event::ZEND;
+ }
+
+ if ( $k != 0 ) {
+ $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"
+ if $DEBUG;
+
+ }
+ else {
+ my $numresults = $oResult[$k]->size();
+ my $i;
+ my $result = '';
+ if ( $numresults > 0 ) {
+ for (
+ $i = 0 ;
+ $i < ( ( $numresults < 20 ) ? ($numresults) : (20) ) ;
+ $i++
+ )
+ {
+ my $rec = $oResult[$k]->record($i);
+ if ($rec) {
+ my $marcrecord;
+ $marcdata = $rec->raw();
+
+ my ($charset_result, $charset_errors);
+ ($marcrecord, $charset_result, $charset_errors) =
+ MarcToUTF8Record($marcdata, C4::Context->preference('marcflavour'), $encoding[$k]);
+####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 = TransformMarcToKoha( $dbh, $marcrecord, "" );
+ $oldbiblio->{isbn} =~ s/ |-|\.//g,
+ $oldbiblio->{issn} =~ s/ |-|\.//g,
+ 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{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});
+ } # $rec
+ } # upto 5 results
+ } #$numresults
+ }
+ } # if $k !=0
+ $numberpending = $nremaining - 1;
+ $template->param(
+ breeding_loop => \@breeding_loop,
+ server => $servername[$k],
+ numberpending => $numberpending,
+ );
+
+ output_html_with_http_headers $input, $cookie, $template->output if $numberpending == 0;
+
+ # print $template->output if $firstresult !=1;
+ $firstresult++;
+}
+displayresults();
+if ( --$nremaining > 0 ) {
+ displayresults();
+ }
+} ## if op=search
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/z3950_search.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/z3950_search.tmpl
new file mode 100644
index 0000000..c923b4f
--- /dev/null
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/z3950_search.tmpl
@@ -0,0 +1,141 @@
+<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
+<title>Koha › Acquisitions › Z39.50 Search Results</title>
+<!-- TMPL_INCLUDE NAME="greybox.inc" -->
+<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
+<script type="text/javascript" src="<!-- TMPL_VAR name="themelang" -->/lib/jquery/plugins/jquery.checkboxes.pack.js"></script>
+<script type="text/javascript" src="<!-- TMPL_VAR name="themelang" -->/lib/jquery/plugins/jquery.tablesorter.min.js"></script>
+<script type="text/javascript">
+//<![CDATA[
+$.tablesorter.addParser({
+ id: 'articles',
+ is: function(s) {return false; },
+ format: function(s) { return s.toLowerCase().replace(/^(the|an|a) /,''); },
+ type: 'text'
+});
+
+ $(document).ready(function(){
+ $("#CheckAll").click(function(){
+ $(".checkboxed").checkCheckboxes();
+ return false;
+ });
+ $("#CheckNone").click(function(){
+ $(".checkboxed").unCheckCheckboxes();
+ return false;
+ });
+ $("#resultst").tablesorter({
+ sortList: [[1,0]],
+ headers: { 0: {sorter:false}, 1: { sorter: 'articles' },5: { sorter: false },6: { sorter: false }}
+ });
+});
+//]]>
+</script>
+ <style type="text/css">
+ #custom-doc { width:54.92em;*width:53.55em;min-width:720px; margin:auto; text-align:left; }
+ </style>
+</head>
+<body>
+<!-- TMPL_INCLUDE NAME="header.inc" -->
+<!-- TMPL_INCLUDE NAME="acquisitions-search.inc" -->
+
+<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> › <a href="/cgi-bin/koha/acqui/acqui-home.pl">Acquisitions</a> › order from z3950 search</div>
+<div id="custom-doc" class="yui-t7">
+ <div id="bd">
+ <!-- TMPL_IF name="opsearch" -->
+<h2>Z39.50 Search Points</h2>
+ <form method="post" action="z3950_search.pl" name="f" class="checkboxed">
+ <input type="hidden" name="op" id="op" value="do_search" />
+ <div class="yui-g">
+ <div class="yui-u first">
+ <fieldset class="rows">
+ <ol><li><label for="title">Title: </label> <input type="text" id="title" name="title" value="<!-- TMPL_VAR NAME="title" -->" /></li>
+ <li><label for="isbn">ISBN/ISSN: </label> <input type="text" id="isbn" name="isbn" value="<!-- TMPL_VAR NAME="isbn" -->" /></li>
+ <li><label for="lccall">LC Call Number: </label> <input type="text" id="lccall" name="lccall" value="" /></li></ol>
+ </fieldset>
+ </div>
+ <div class="yui-u">
+ <fieldset class="rows"> <ol><li><label for="author">Author: </label> <input type="text" id="author" name="author" value="<!-- TMPL_VAR NAME="author" -->" /><!-- <label for="Keyword">Keyword</label> <input type="text" name="keyword" value="" /> --></li>
+ <li> <label for="subject">Subject Heading: </label> <input type="text" id="subject" name="subject" value="" /></li>
+ <li><label for="dewey">Dewey: </label> <input type="text" id="dewey" name="dewey" value="" /></li></ol></fieldset>
+ <fieldset class="rows" >
+ <ol>
+ <li>
+ <label for="frameworkcode" >Select used MARC framework:</label>
+ <select id="frameworkcode" name="frameworkcode" >
+ <option value="">Default</option>
+ <!-- TMPL_LOOP name="frameworkcodeloop" -->
+ <!-- TMPL_IF name="active" -->
+ <option value="<!-- TMPL_VAR name="value" -->" selected="selected" ><!-- TMPL_VAR name="frameworktext"--></option>
+ <!-- TMPL_ELSE -->
+ <option value="<!-- TMPL_VAR name="value" -->" ><!-- TMPL_VAR name="frameworktext"--></option>
+ <!-- /TMPL_IF -->
+ <!-- /TMPL_LOOP -->
+ </select>
+ </li>
+ </ol>
+ </fieldset>
+ <input type="hidden" name="biblionumber" value="<!-- TMPL_VAR NAME="biblionumber" -->" />
+ <input type="hidden" name="basketno" value="<!-- TMPL_VAR name="basketno" -->" />
+ <input type="hidden" name="booksellerid" value="<!-- TMPL_VAR name="booksellerid" -->" />
+ </div>
+</div>
+<div class="yui-g">
+<h2>Search targets <span style="display: inline; font-size: 70%; padding-left: 1em;"><span class="checkall"><a id="CheckAll" href="#">Select All</a></span><span class="clearall"><a id="CheckNone" href="#">Clear All</a></span></span></h2>
+
+ <!-- TMPL_LOOP name="serverloop" -->
+ <p>
+ <!-- TMPL_IF name="checked" -->
+ <input type="checkbox" name="id" id="z3950_<!-- TMPL_VAR NAME="id" -->" value="<!-- TMPL_VAR NAME="id" -->" checked="checked" />
+ <!-- TMPL_ELSE -->
+ <input type="checkbox" name="id" id="z3950_<!-- TMPL_VAR NAME="id" -->" value="<!-- TMPL_VAR NAME="id" -->" />
+ <!-- /TMPL_IF -->
+ <label for="z3950_<!-- TMPL_VAR NAME="id" -->"><!-- TMPL_VAR NAME="name" --> [<!-- TMPL_VAR NAME="host" -->]</label>
+
+ </p>
+ <!-- /TMPL_LOOP -->
+ <fieldset class="action"><input type="submit" class="submit" value="Search" onclick="cursor :'wait'"/> <a class="cancel close" href="#">Cancel</a></fieldset>
+ </form>
+
+
+<!-- TMPL_ELSE -->
+ <h2>Results</h2>
+ <!-- TMPL_IF name="breeding_loop" -->
+ <table id="resultst">
+<thead> <tr>
+ <th>Server</th>
+ <th>Title</th>
+ <th>Author</th>
+ <th>ISBN</th>
+ <th>LCCN</th>
+ <th colspan="2">Preview</th>
+ <th> </th>
+ </tr></thead>
+ <tbody><!-- TMPL_LOOP name="breeding_loop" -->
+ <!-- TMPL_IF NAME="breedingid" -->
+
+ <!-- TMPL_IF NAME="toggle" --><tr class="highlight"><!-- TMPL_ELSE --><tr><!-- /TMPL_IF -->
+ <td><!-- TMPL_VAR name="server" --></td>
+ <td><!-- TMPL_VAR NAME="title" --></td>
+ <td><!-- TMPL_VAR NAME="author" --></td>
+ <td><!-- TMPL_VAR NAME="isbn" --></td>
+ <td><!-- TMPL_VAR NAME="lccn" --></td>
+ <td><a href="/cgi-bin/koha/catalogue/showmarc.pl?importid=<!-- TMPL_VAR NAME="breedingid" -->" title="MARC" rel="gb_page_center[600,500]">MARC</a></td><td><a href="/cgi-bin/koha/catalogue/showmarc.pl?viewas=card&importid=<!-- TMPL_VAR NAME="breedingid" -->" title="MARC" rel="gb_page_center[600,500]">Card</a></td>
+ <td><a href="/cgi-bin/koha/acqui/neworderempty.pl?frameworkcode=<!-- TMPL_VAR name="frameworkcode" -->&breedingid=<!-- TMPL_VAR NAME="breedingid" -->&booksellerid=<!-- TMPL_VAR name="booksellerid" -->&basketno=<!-- TMPL_VAR name="basketno" -->">Order</a></td>
+
+ </tr>
+ <!-- /TMPL_IF -->
+ <!-- /TMPL_LOOP --></tbody>
+</table>
+ <!-- TMPL_ELSE -->
+ <p>Nothing found. <a href="javascript: history.back()">Try another search</a>.</p>
+ <!-- /TMPL_IF -->
+
+
+<!-- /TMPL_IF -->
+
+ </div>
+</div>
+<!-- TMPL_IF name="numberpending" --><h3 align="center">Still <!-- TMPL_VAR NAME="numberpending" --> servers to search</h3><!-- /TMPL_IF -->
+
+</body>
+</html>
+
--
1.6.0.4
More information about the Koha-patches
mailing list