New XML API
[koha.git] / C4 / Z3950.pm
1 package C4::Z3950;
2
3 # $Id$
4
5 # Routines for handling Z39.50 lookups
6
7 # Koha library project  www.koha.org
8
9 # Licensed under the GPL
10
11
12 # Copyright 2000-2002 Katipo Communications
13 #
14 # This file is part of Koha.
15 #
16 # Koha is free software; you can redistribute it and/or modify it under the
17 # terms of the GNU General Public License as published by the Free Software
18 # Foundation; either version 2 of the License, or (at your option) any later
19 # version.
20 #
21 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
22 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
23 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
24 #
25 # You should have received a copy of the GNU General Public License along with
26 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
27 # Suite 330, Boston, MA  02111-1307 USA
28
29 use strict;
30
31 # standard or CPAN modules used
32
33 # Koha modules used
34 use C4::Context;
35 use C4::Input;
36 use C4::Biblio;
37
38 #------------------
39
40 require Exporter;
41
42 use vars qw($VERSION @ISA @EXPORT);
43
44 # set the version for version checking
45 $VERSION = 0.01;
46
47 =head1 NAME
48
49 C4::Z3950 - Functions dealing with Z39.50 queries
50
51 =head1 SYNOPSIS
52
53   use C4::Z3950;
54
55 =head1 DESCRIPTION
56
57 This module contains functions for looking up Z39.50 servers, and for
58 entering Z39.50 lookup requests.
59
60 =head1 FUNCTIONS
61
62 =over 2
63
64 =cut
65
66 @ISA = qw(Exporter);
67 @EXPORT = qw(
68         &getz3950servers
69         &z3950servername
70 );
71
72 #------------------------------------------------
73 =item getz3950servers
74
75   @servers= &getz3950servers(checked);
76
77 Returns the list of declared z3950 servers
78
79 C<$checked> should always be true (1) => returns only active servers.
80 If 0 => returns all servers
81
82 =cut
83 sub getz3950servers {
84         my ($checked) = @_;
85         my $dbh = C4::Context->dbh;
86         my $sth;
87         if ($checked) {
88                 $sth = $dbh->prepare("select * from z3950servers where checked=1");
89         } else {
90                 $sth = $dbh->prepare("select * from z3950servers");
91         }
92         my @result;
93         while ( my ($host, $port, $db, $userid, $password,$servername) = $sth->fetchrow ) {
94                 push @result, "$servername/$host\:$port/$db/$userid/$password";
95         } # while
96         return @result;
97 }
98
99 =item z3950servername
100
101   $name = &z3950servername($dbh, $server_id, $default_name);
102
103 Looks up a Z39.50 server by ID number, and returns its full name. If
104 the server is not found, returns C<$default_name>.
105
106 C<$server_id> is the Z39.50 server ID to look up.
107
108 C<$dbh> is ignored.
109
110 =cut
111 #'
112
113 sub z3950servername {
114         # inputs
115         my ($srvid,             # server id number
116                 $default,)=@_;
117         # return
118         my $longname;
119         #----
120
121         my $dbh = C4::Context->dbh;
122
123         my $sti=$dbh->prepare("select name from z3950servers where id=?");
124
125         $sti->execute($srvid);
126         if ( ! $sti->err ) {
127                 ($longname)=$sti->fetchrow;
128         }
129         if (! $longname) {
130                 $longname="$default";
131         }
132                 return $longname;
133 } # sub z3950servername
134
135 #---------------------------------------
136
137
138
139 1;
140 __END__
141
142 =back
143
144 =head1 AUTHOR
145
146 Koha Developement team <info@koha.org>
147
148 =cut
149
150 #--------------------------------------
151 ##No more deamon to start. Z3950 now handled by ZOOM asynch mode-TG
152 # $Log$
153 # Revision 1.12  2006/09/01 22:16:00  tgarip1957
154 # New XML API
155 # Event & Net::Z3950 dependency removed
156 # HTML::Template::Pro dependency added
157 #
158 # Revision 1.10  2003/10/01 15:08:14  tipaul
159 # fix fog bug #622 : processz3950queue fails
160 #
161 # Revision 1.9  2003/04/29 16:50:51  tipaul
162 # really proud of this commit :-)
163 # z3950 search and import seems to works fine.
164 # Let me explain how :
165 # * a "search z3950" button is added in the addbiblio template.
166 # * when clicked, a popup appears and z3950/search.pl is called
167 # * z3950/search.pl calls addz3950search in the DB
168 # * the z3950 daemon retrieve the records and stores them in z3950results AND in marc_breeding table.
169 # * as long as there as searches pending, the popup auto refresh every 2 seconds, and says how many searches are pending.
170 # * when the user clicks on a z3950 result => the parent popup is called with the requested biblio, and auto-filled
171 #
172 # Note :
173 # * character encoding support : (It's a nightmare...) In the z3950servers table, a "encoding" column has been added. You can put "UNIMARC" or "USMARC" in this column. Depending on this, the char_decode in C4::Biblio.pm replaces marc-char-encode by an iso 8859-1 encoding. Note that in the breeding import this value has been added too, for a better support.
174 # * the marc_breeding and z3950* tables have been modified : they have an encoding column and the random z3950 number is stored too for convenience => it's the key I use to list only requested biblios in the popup.
175 #
176 # Revision 1.8  2003/04/29 08:09:45  tipaul
177 # z3950 support is coming...
178 # * adding a syntax column in z3950 table = this column will say wether the z3950 must be called with PerferedRecordsyntax => USMARC or PerferedRecordsyntax => UNIMARC. I tried some french UNIMARC z3950 servers, and some only send USMARC, some only UNIMARC, some can answer with both.
179 # Note this is a 1st draft. More to follow (today ? I hope).
180 #
181 # Revision 1.7  2003/02/19 01:01:06  wolfpac444
182 # Removed the unecessary $dbh argument from being passed.
183 # Resolved a few minor FIXMEs.
184 #
185 # Revision 1.6  2002/10/13 08:30:53  arensb
186 # Deleted unused variables.
187 # Removed trailing whitespace.
188 #
189 # Revision 1.5  2002/10/13 06:13:23  arensb
190 # Removed bogus #! line (this isn't a script!)
191 # Removed unused global variables.
192 # Added POD.
193 # Added some explanatory comments.
194 # Added some FIXME comments.
195 #
196 # Revision 1.4  2002/10/11 12:35:35  arensb
197 # Replaced &requireDBI with C4::Context->dbh
198 #
199 # Revision 1.3  2002/08/14 18:12:52  tonnesen
200 # Added copyright statement to all .pl and .pm files
201 #
202 # Revision 1.2  2002/07/02 20:31:33  tonnesen
203 # module added from rel-1-2 branch
204 #
205 # Revision 1.1.2.5  2002/06/29 17:33:47  amillar
206 # Allow DEFAULT as input to addz3950search.
207 # Check for existence of pid file (cat crashed otherwise).
208 # Return error messages in addz3950search.
209 #
210 # Revision 1.1.2.4  2002/06/28 18:07:27  tonnesen
211 # marcimport.pl will print an error message if it can not signal the
212 # processz3950queue program.  The message contains instructions for starting the
213 # daemon.
214 #
215 # Revision 1.1.2.3  2002/06/28 17:45:39  tonnesen
216 # z3950queue now listens for a -HUP signal before processing the queue.  Z3950.pm
217 # sends the -HUP signal when queries are added to the queue.
218 #
219 # Revision 1.1.2.2  2002/06/26 20:54:31  tonnesen
220 # use warnings breaks on perl 5.005...
221 #
222 # Revision 1.1.2.1  2002/06/26 07:26:41  amillar
223 # New module for Z39.50 searching
224 #