|
Lines 25-37
use CGI;
Link Here
|
| 25 |
|
25 |
|
| 26 |
use C4::Auth; |
26 |
use C4::Auth; |
| 27 |
use C4::Output; |
27 |
use C4::Output; |
| 28 |
use C4::Biblio; |
28 |
#use C4::Biblio; |
| 29 |
use C4::Context; |
29 |
use C4::Context; |
| 30 |
use C4::Breeding; |
30 |
use C4::Breeding; |
| 31 |
use C4::Koha; |
31 |
use C4::Koha; |
| 32 |
use C4::Charset; |
32 |
#use C4::Charset; |
| 33 |
use C4::Bookseller qw/ GetBookSellerFromId /; |
33 |
use C4::Bookseller qw/ GetBookSellerFromId /; |
| 34 |
use ZOOM; |
34 |
#use ZOOM; |
| 35 |
|
35 |
|
| 36 |
my $input = new CGI; |
36 |
my $input = new CGI; |
| 37 |
my ( $template, $loggedinuser, $cookie ) = get_template_and_user( |
37 |
my ( $template, $loggedinuser, $cookie ) = get_template_and_user( |
|
Lines 47-56
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
Link Here
|
| 47 |
|
47 |
|
| 48 |
|
48 |
|
| 49 |
my $dbh = C4::Context->dbh; |
49 |
my $dbh = C4::Context->dbh; |
| 50 |
my $error = $input->param('error'); |
50 |
my $biblionumber = $input->param('biblionumber')||0; |
| 51 |
my $biblionumber = $input->param('biblionumber'); |
51 |
my $frameworkcode = $input->param('frameworkcode')||''; |
| 52 |
$biblionumber = 0 unless $biblionumber; |
|
|
| 53 |
my $frameworkcode = $input->param('frameworkcode'); |
| 54 |
my $title = $input->param('title'); |
52 |
my $title = $input->param('title'); |
| 55 |
my $author = $input->param('author'); |
53 |
my $author = $input->param('author'); |
| 56 |
my $isbn = $input->param('isbn'); |
54 |
my $isbn = $input->param('isbn'); |
|
Lines 60-99
my $lccall = $input->param('lccall');
Link Here
|
| 60 |
my $subject = $input->param('subject'); |
58 |
my $subject = $input->param('subject'); |
| 61 |
my $dewey = $input->param('dewey'); |
59 |
my $dewey = $input->param('dewey'); |
| 62 |
my $controlnumber = $input->param('controlnumber'); |
60 |
my $controlnumber = $input->param('controlnumber'); |
| 63 |
my $op = $input->param('op'); |
61 |
my $op = $input->param('op')||''; |
| 64 |
my $booksellerid = $input->param('booksellerid'); |
62 |
my $booksellerid = $input->param('booksellerid'); |
| 65 |
my $basketno = $input->param('basketno'); |
63 |
my $basketno = $input->param('basketno'); |
| 66 |
|
64 |
|
| 67 |
my $page = $input->param('current_page') || 1; |
65 |
my $page = $input->param('current_page') || 1; |
| 68 |
$page = $input->param('goto_page') if $input->param('changepage_goto'); |
66 |
$page = $input->param('goto_page') if $input->param('changepage_goto'); |
| 69 |
my $show_next = 0; |
|
|
| 70 |
my $total_pages = 0; |
| 71 |
|
| 72 |
my $noconnection; |
| 73 |
my $attr = ''; |
| 74 |
my $term; |
| 75 |
my $host; |
| 76 |
my $server; |
| 77 |
my $database; |
| 78 |
my $port; |
| 79 |
my $marcdata; |
| 80 |
my @encoding; |
| 81 |
my @results; |
| 82 |
my $count; |
| 83 |
my $toggle; |
| 84 |
my $record; |
| 85 |
my $oldbiblio; |
| 86 |
my $errmsg; |
| 87 |
my @serverhost; |
| 88 |
my @servername; |
| 89 |
my @breeding_loop = (); |
| 90 |
my $random = $input->param('random'); |
| 91 |
unless ($random) |
| 92 |
{ # this var is not useful anymore just kept to keep rel2_2 compatibility |
| 93 |
$random = rand(1000000000); |
| 94 |
} |
| 95 |
|
| 96 |
my $DEBUG = $ENV{DEBUG} || 0; # if set to 1, many debug message are send on syslog. |
| 97 |
|
67 |
|
| 98 |
# get framework list |
68 |
# get framework list |
| 99 |
my $frameworks = getframeworks; |
69 |
my $frameworks = getframeworks; |
|
Lines 114-136
$template->param( frameworkcode => $frameworkcode,
Link Here
|
| 114 |
frameworkcodeloop => \@frameworkcodeloop, |
84 |
frameworkcodeloop => \@frameworkcodeloop, |
| 115 |
booksellerid => $booksellerid, |
85 |
booksellerid => $booksellerid, |
| 116 |
basketno => $basketno, |
86 |
basketno => $basketno, |
| 117 |
name => $vendor->{'name'} |
87 |
name => $vendor->{'name'}, |
|
|
88 |
isbn => $isbn, |
| 89 |
issn => $issn, |
| 90 |
lccn => $lccn, |
| 91 |
lccall => $lccall, |
| 92 |
title => $title, |
| 93 |
author => $author, |
| 94 |
controlnumber=> $controlnumber, |
| 95 |
biblionumber => $biblionumber, |
| 96 |
dewey => $dewey, |
| 97 |
subject => $subject, |
| 118 |
); |
98 |
); |
| 119 |
|
99 |
|
| 120 |
|
|
|
| 121 |
$template->param( |
| 122 |
isbn => $isbn, |
| 123 |
issn => $issn, |
| 124 |
lccn => $lccn, |
| 125 |
lccall => $lccall, |
| 126 |
title => $title, |
| 127 |
author => $author, |
| 128 |
controlnumber=> $controlnumber, |
| 129 |
biblionumber => $biblionumber, |
| 130 |
dewey => $dewey, |
| 131 |
subject => $subject, |
| 132 |
); |
| 133 |
|
| 134 |
if ( $op ne "do_search" ) { |
100 |
if ( $op ne "do_search" ) { |
| 135 |
my $sth = $dbh->prepare("select id,host,name,checked from z3950servers order by host"); |
101 |
my $sth = $dbh->prepare("select id,host,name,checked from z3950servers order by host"); |
| 136 |
$sth->execute(); |
102 |
$sth->execute(); |
|
Lines 143-356
if ( $op ne "do_search" ) {
Link Here
|
| 143 |
exit; |
109 |
exit; |
| 144 |
} |
110 |
} |
| 145 |
|
111 |
|
| 146 |
my @id = $input->param('id'); |
112 |
my @id = $input->param('id'); |
| 147 |
|
113 |
if (@id==0) { |
| 148 |
if ( not @id ) { |
114 |
$template->param( emptyserverlist => 1 ); |
| 149 |
# empty server list -> report and exit |
115 |
output_html_with_http_headers $input, $cookie, $template->output; |
| 150 |
$template->param( emptyserverlist => 1 ); |
116 |
exit; |
| 151 |
output_html_with_http_headers $input, $cookie, $template->output; |
|
|
| 152 |
exit; |
| 153 |
} |
| 154 |
|
| 155 |
my @oConnection; |
| 156 |
my @oResult; |
| 157 |
my @errconn; |
| 158 |
my $s = 0; |
| 159 |
my $query; |
| 160 |
my $nterms; |
| 161 |
if ($isbn) { |
| 162 |
$term=$isbn; |
| 163 |
$query .= " \@attr 1=7 \@attr 5=1 \"$term\" "; |
| 164 |
$nterms++; |
| 165 |
} |
| 166 |
if ($issn) { |
| 167 |
$term=$issn; |
| 168 |
$query .= " \@attr 1=8 \@attr 5=1 \"$term\" "; |
| 169 |
$nterms++; |
| 170 |
} |
| 171 |
if ($title) { |
| 172 |
utf8::decode($title); |
| 173 |
$query .= " \@attr 1=4 \"$title\" "; |
| 174 |
$nterms++; |
| 175 |
} |
| 176 |
if ($author) { |
| 177 |
utf8::decode($author); |
| 178 |
$query .= " \@attr 1=1003 \"$author\" "; |
| 179 |
$nterms++; |
| 180 |
} |
| 181 |
if ($dewey) { |
| 182 |
$query .= " \@attr 1=16 \"$dewey\" "; |
| 183 |
$nterms++; |
| 184 |
} |
| 185 |
if ($subject) { |
| 186 |
utf8::decode($subject); |
| 187 |
$query .= " \@attr 1=21 \"$subject\" "; |
| 188 |
$nterms++; |
| 189 |
} |
| 190 |
if ($lccn) { |
| 191 |
$query .= " \@attr 1=9 $lccn "; |
| 192 |
$nterms++; |
| 193 |
} |
| 194 |
if ($lccall) { |
| 195 |
$query .= " \@attr 1=16 \@attr 2=3 \@attr 3=1 \@attr 4=1 \@attr 5=1 \@attr 6=1 \"$lccall\" "; |
| 196 |
$nterms++; |
| 197 |
} |
| 198 |
if ($controlnumber) { |
| 199 |
$query .= " \@attr 1=12 \"$controlnumber\" "; |
| 200 |
$nterms++; |
| 201 |
} |
| 202 |
for my $i (1..$nterms-1) { |
| 203 |
$query = "\@and " . $query; |
| 204 |
} |
117 |
} |
| 205 |
warn "query ".$query if $DEBUG; |
|
|
| 206 |
|
| 207 |
foreach my $servid (@id) { |
| 208 |
my $sth = $dbh->prepare("select * from z3950servers where id=?"); |
| 209 |
$sth->execute($servid); |
| 210 |
while ( $server = $sth->fetchrow_hashref ) { |
| 211 |
warn "serverinfo ".join(':',%$server) if $DEBUG; |
| 212 |
my $option1 = new ZOOM::Options(); |
| 213 |
$option1->option( 'async' => 1 ); |
| 214 |
$option1->option( 'elementSetName', 'F' ); |
| 215 |
$option1->option( 'databaseName', $server->{db} ); |
| 216 |
$option1->option( 'user', $server->{userid} ) if $server->{userid}; |
| 217 |
$option1->option( 'password', $server->{password} ) |
| 218 |
if $server->{password}; |
| 219 |
$option1->option( 'preferredRecordSyntax', $server->{syntax} ); |
| 220 |
$oConnection[$s] = create ZOOM::Connection($option1) |
| 221 |
|| $DEBUG |
| 222 |
&& warn( "" . $oConnection[$s]->errmsg() ); |
| 223 |
warn( "server data", $server->{name}, $server->{port} ) if $DEBUG; |
| 224 |
$oConnection[$s]->connect( $server->{host}, $server->{port} ) |
| 225 |
|| $DEBUG |
| 226 |
&& warn( "" . $oConnection[$s]->errmsg() ); |
| 227 |
$serverhost[$s] = $server->{host}; |
| 228 |
$servername[$s] = $server->{name}; |
| 229 |
$encoding[$s] = ($server->{encoding}?$server->{encoding}:"iso-5426"); |
| 230 |
$s++; |
| 231 |
} ## while fetch |
| 232 |
} # foreach |
| 233 |
my $nremaining = $s; |
| 234 |
my $firstresult = 1; |
| 235 |
|
118 |
|
| 236 |
for ( my $z = 0 ; $z < $s ; $z++ ) { |
119 |
my $pars= { |
| 237 |
warn "doing the search" if $DEBUG; |
120 |
random => $input->param('random') || rand(1000000000), |
| 238 |
$oResult[$z] = $oConnection[$z]->search_pqf($query) |
121 |
biblionumber => $biblionumber, |
| 239 |
|| $DEBUG |
122 |
page => $page, |
| 240 |
&& warn( "somthing went wrong: " . $oConnection[$s]->errmsg() ); |
123 |
id => \@id, |
| 241 |
|
124 |
isbn => $isbn, |
| 242 |
# $oResult[$z] = $oConnection[$z]->search_pqf($query); |
125 |
title => $title, |
| 243 |
} |
126 |
author => $author, |
| 244 |
|
127 |
dewey => $dewey, |
| 245 |
warn "# nremaining = $nremaining\n" if $DEBUG; |
128 |
subject => $subject, |
| 246 |
|
129 |
lccall => $lccall, |
| 247 |
while ( $nremaining-- ) { |
130 |
controlnumber => $controlnumber, |
| 248 |
|
131 |
stdid => 0, |
| 249 |
my $k; |
132 |
srchany => 0, |
| 250 |
my $event; |
133 |
}; |
| 251 |
while ( ( $k = ZOOM::event( \@oConnection ) ) != 0 ) { |
134 |
Z3950Search($pars, $template); |
| 252 |
$event = $oConnection[ $k - 1 ]->last_event(); |
|
|
| 253 |
warn( "connection ", $k - 1, ": event $event (", |
| 254 |
ZOOM::event_str($event), ")\n" ) |
| 255 |
if $DEBUG; |
| 256 |
last if $event == ZOOM::Event::ZEND; |
| 257 |
} |
| 258 |
|
| 259 |
if ( $k != 0 ) { |
| 260 |
$k--; |
| 261 |
warn "event from $k server = ",$serverhost[$k] if $DEBUG; |
| 262 |
my ( $error, $errmsg, $addinfo, $diagset ) = |
| 263 |
$oConnection[$k]->error_x(); |
| 264 |
if ($error) { |
| 265 |
if ($error =~ m/^(10000|10007)$/ ) { |
| 266 |
push(@errconn, {'server' => $serverhost[$k]}); |
| 267 |
} |
| 268 |
$DEBUG and warn "$k $serverhost[$k] error $query: $errmsg ($error) $addinfo\n"; |
| 269 |
} |
| 270 |
else { |
| 271 |
my $numresults = $oResult[$k]->size(); |
| 272 |
warn "numresults = $numresults" if $DEBUG; |
| 273 |
my $i; |
| 274 |
my $result = ''; |
| 275 |
if ( $numresults > 0 and $numresults >= (($page-1)*20)) { |
| 276 |
$show_next = 1 if $numresults >= ($page*20); |
| 277 |
$total_pages = int($numresults/20)+1 if $total_pages < ($numresults/20); |
| 278 |
for ($i = ($page-1)*20; $i < (($numresults < ($page*20)) ? $numresults : ($page*20)); $i++) { |
| 279 |
my $rec = $oResult[$k]->record($i); |
| 280 |
if ($rec) { |
| 281 |
my $marcrecord; |
| 282 |
$marcdata = $rec->raw(); |
| 283 |
|
| 284 |
my ($charset_result, $charset_errors); |
| 285 |
($marcrecord, $charset_result, $charset_errors) = |
| 286 |
MarcToUTF8Record($marcdata, C4::Context->preference('marcflavour'), $encoding[$k]); |
| 287 |
####WARNING records coming from Z3950 clients are in various character sets MARC8,UTF8,UNIMARC etc |
| 288 |
## In HEAD i change everything to UTF-8 |
| 289 |
# In rel2_2 i am not sure what encoding is so no character conversion is done here |
| 290 |
##Add necessary encoding changes to here -TG |
| 291 |
|
| 292 |
# Normalize the record so it doesn't have separated diacritics |
| 293 |
SetUTF8Flag($marcrecord); |
| 294 |
|
| 295 |
my $oldbiblio = TransformMarcToKoha( $dbh, $marcrecord, "" ); |
| 296 |
$oldbiblio->{isbn} =~ s/ |-|\.//g if $oldbiblio->{isbn}; |
| 297 |
# pad | and ( with spaces to allow line breaks in the HTML |
| 298 |
$oldbiblio->{isbn} =~ s/\|/ \| /g if $oldbiblio->{isbn}; |
| 299 |
$oldbiblio->{isbn} =~ s/\(/ \(/g if $oldbiblio->{isbn}; |
| 300 |
|
| 301 |
$oldbiblio->{issn} =~ s/ |-|\.//g if $oldbiblio->{issn}; |
| 302 |
# pad | and ( with spaces to allow line breaks in the HTML |
| 303 |
$oldbiblio->{issn} =~ s/\|/ \| /g if $oldbiblio->{issn}; |
| 304 |
$oldbiblio->{issn} =~ s/\(/ \(/g if $oldbiblio->{issn}; |
| 305 |
my ( |
| 306 |
$notmarcrecord, $alreadyindb, $alreadyinfarm, |
| 307 |
$imported, $breedingid |
| 308 |
) |
| 309 |
= ImportBreeding( $marcdata, 2, $serverhost[$k], $encoding[$k], $random, 'z3950' ); |
| 310 |
my %row_data; |
| 311 |
$row_data{server} = $servername[$k]; |
| 312 |
$row_data{isbn} = $oldbiblio->{isbn}; |
| 313 |
$row_data{lccn} = $oldbiblio->{lccn}; |
| 314 |
$row_data{title} = $oldbiblio->{title}; |
| 315 |
$row_data{author} = $oldbiblio->{author}; |
| 316 |
$row_data{breedingid} = $breedingid; |
| 317 |
$row_data{biblionumber} = $biblionumber; |
| 318 |
push( @breeding_loop, \%row_data ); |
| 319 |
|
| 320 |
} else { |
| 321 |
push(@breeding_loop,{'server'=>$servername[$k],'title'=>join(': ',$oConnection[$k]->error_x()),'breedingid'=>-1,'biblionumber'=>-1}); |
| 322 |
} # $rec |
| 323 |
} # upto 5 results |
| 324 |
} #$numresults |
| 325 |
} |
| 326 |
} # if $k !=0 |
| 327 |
my $numberpending = $nremaining - 1; |
| 328 |
|
| 329 |
my @servers = (); |
| 330 |
foreach my $id (@id) { |
| 331 |
push(@servers,{id => $id}); |
| 332 |
} |
| 333 |
|
| 334 |
$template->param( |
| 335 |
breeding_loop => \@breeding_loop, |
| 336 |
server => $servername[$k], |
| 337 |
numberpending => $numberpending, |
| 338 |
current_page => $page, |
| 339 |
servers => \@servers, |
| 340 |
total_pages => $total_pages, |
| 341 |
); |
| 342 |
$template->param(show_nextbutton=>1) if $show_next; |
| 343 |
$template->param(show_prevbutton=>1) if $page != 1; |
| 344 |
|
| 345 |
# print $template->output if $firstresult !=1; |
| 346 |
$firstresult++; |
| 347 |
|
| 348 |
} # while nremaining |
| 349 |
|
| 350 |
$template->param( |
| 351 |
breeding_loop => \@breeding_loop, |
| 352 |
#server => $servername[$k], |
| 353 |
numberpending => $nremaining > 0 ? $nremaining : 0, |
| 354 |
errconn => \@errconn |
| 355 |
); |
| 356 |
output_html_with_http_headers $input, $cookie, $template->output; |
135 |
output_html_with_http_headers $input, $cookie, $template->output; |