3 # Copyright Biblibre 2007
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
36 use Koha
::SearchEngine
;
37 use Koha
::SearchEngine
::Search
;
39 sub plugin_parameters
{
40 my ( $dbh, $record, $tagslib, $i, $tabloop ) = @_;
44 sub plugin_javascript
{
45 my ( $dbh, $record, $tagslib, $field_number, $tabloop ) = @_;
46 my $function_name = $field_number;
48 <script type='text/javascript'>
49 function Clic$function_name(i) {
50 defaultvalue=document.getElementById(\"$field_number\").value;
51 window.open(\"/cgi-bin/koha/cataloguing/plugin_launcher.pl?plugin_name=unimarc_field_4XX.pl&index=\" + i + \"&result=\"+defaultvalue,\"unimarc_field_4\"+i+\"\",'width=900,height=700,toolbar=false,scrollbars=yes');
57 return ( $function_name, $res );
63 # -- op could be equals to
70 my $dbh = C4
::Context
->dbh;
72 my $op = $query->param('op');
73 my $type = $query->param('type');
74 my $startfrom = $query->param('startfrom');
75 $startfrom = 0 if ( !defined $startfrom );
76 my ( $template, $loggedinuser, $cookie );
79 if ( $op eq "fillinput" ) {
80 my $biblionumber = $query->param('biblionumber');
81 my $index = $query->param('index');
85 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
88 "cataloguing/value_builder/unimarc_field_4XX.tt",
92 flagsrequired
=> { editcatalogue
=> '*' },
98 $marcrecord = GetMarcBiblio
({ biblionumber
=> $biblionumber });
100 my $subfield_value_9 = $biblionumber;
101 my $subfield_value_0;
102 $subfield_value_0 = $marcrecord->field('001')->data
103 if $marcrecord->field('001');
104 my $subfield_value_a;
105 if ( $marcrecord->field('700') ) {
106 $subfield_value_a = $marcrecord->field('700')->subfield("a");
107 $subfield_value_a .= ", " . $marcrecord->subfield( '700', "b" )
108 if $marcrecord->subfield( '700', 'b' );
109 $subfield_value_a .= " " . $marcrecord->subfield( '700', "d" )
110 if $marcrecord->subfield( '700', 'd' );
112 " (" . $marcrecord->subfield( '700', 'c' )
113 if $marcrecord->subfield( '700', 'c' );
114 $subfield_value_a .= " ; "
115 if $marcrecord->subfield( '700', 'c' )
116 and $marcrecord->subfield( '700', 'f' );
117 $subfield_value_a .= " ("
118 if ( $marcrecord->subfield( '700', 'f' )
119 and not( $marcrecord->subfield( '700', 'c' ) ) );
120 $subfield_value_a .= $marcrecord->subfield( '700', 'f' )
121 if ( $marcrecord->subfield( '700', 'f' ) );
122 $subfield_value_a .= ")"
123 if ( $marcrecord->subfield( '700', 'f' )
124 or $marcrecord->subfield( '700', 'c' ) );
126 elsif ( $marcrecord->field('702') ) {
127 $subfield_value_a = $marcrecord->subfield( '702', 'a' );
128 $subfield_value_a .= ", " . $marcrecord->subfield( '702', 'b' )
129 if $marcrecord->subfield( '702', 'b' );
130 $subfield_value_a .= " " . $marcrecord->subfield( '702', 'd' )
131 if $marcrecord->subfield( '702', 'd' );
133 " (" . $marcrecord->subfield( '702', 'c' )
134 if $marcrecord->subfield( '702', 'c' );
135 $subfield_value_a .= " ; "
136 if $marcrecord->subfield( '702', 'c' )
137 and $marcrecord->subfield( '702', 'f' );
138 $subfield_value_a .= " ("
139 if $marcrecord->subfield( '702', 'f' )
140 and not $marcrecord->subfield( '702', 'c' );
141 $subfield_value_a .= $marcrecord->subfield( '702', 'f' )
142 if $marcrecord->subfield( '702', 'f' );
143 $subfield_value_a .= ")"
144 if $marcrecord->subfield( '702', 'f' )
145 or $marcrecord->subfield( '702', 'c' );
147 elsif ( $marcrecord->field('710') ) {
148 $subfield_value_a = $marcrecord->subfield( '710', 'd' ) . " "
149 if $marcrecord->subfield( '710', 'd' );
150 $subfield_value_a .= $marcrecord->subfield( '710', 'a' )
151 if $marcrecord->subfield( '710', 'a' );
152 $subfield_value_a .= ", " . $marcrecord->subfield( '710', 'b' )
153 if $marcrecord->subfield('710');
155 " (" . $marcrecord->subfield( '710', 'f' ) . " - "
156 if $marcrecord->subfield( '710', 'f' );
157 $subfield_value_a .= " ("
158 if $marcrecord->subfield( '710', 'e' )
159 and not $marcrecord->subfield( '710', 'f' );
160 $subfield_value_a .= $marcrecord->subfield( '710', 'e' )
161 if $marcrecord->subfield( '710', 'e' );
162 $subfield_value_a .= ")"
163 if $marcrecord->subfield( '710', 'e' )
164 or $marcrecord->subfield( '710', 'f' );
166 elsif ( $marcrecord->field('701') ) {
167 $subfield_value_a = $marcrecord->subfield( '701', 'a' );
168 $subfield_value_a .= ", " . $marcrecord->subfield( '701', 'b' )
169 if $marcrecord->subfield( '701', 'b' );
170 $subfield_value_a .= " " . $marcrecord->subfield( '701', 'd', )
171 if $marcrecord->subfield( '701', 'd' );
173 " (" . $marcrecord->subfield( '701', 'c' ) . " - "
174 if $marcrecord->subfield( '701', 'c' );
175 $subfield_value_a .= " ("
176 if $marcrecord->subfield( '701', 'f' )
177 and not( $marcrecord->subfield( '701', 'c' ) );
178 $subfield_value_a .= $marcrecord->subfield( '701', 'f' )
179 if $marcrecord->subfield( '701', 'f' );
180 $subfield_value_a .= ")"
181 if $marcrecord->subfield( '701', 'f' )
182 or $marcrecord->subfield( '701', 'c' );
184 elsif ( $marcrecord->field('712') ) {
185 $subfield_value_a = $marcrecord->subfield( '712', 'd' ) . " "
186 if $marcrecord->subfield( '712', 'd' );
187 $subfield_value_a .= $marcrecord->subfield( '712', 'a' )
188 if $marcrecord->subfield( '712', 'a' );
189 $subfield_value_a .= ", " . $marcrecord->subfield( '712', 'b' )
190 if $marcrecord->subfield( '712', 'b' );
192 " (" . $marcrecord->subfield( '712', 'f' ) . " - "
193 if $marcrecord->subfield( '712', 'f' );
194 $subfield_value_a .= " ("
195 if $marcrecord->subfield( '712', "e" )
196 and not $marcrecord->subfield( '712', 'f' );
197 $subfield_value_a .= $marcrecord->subfield( '712', 'e' )
198 if $marcrecord->subfield( '712', 'e' );
199 $subfield_value_a .= ")"
200 if $marcrecord->subfield( '712', 'e' )
201 or $marcrecord->subfield( '712', 'f' );
203 elsif ( $marcrecord->field('200') ) {
204 $subfield_value_a = $marcrecord->subfield( '200', 'f' );
206 my $subfield_value_c;
207 my $subfield_value_d;
208 my $subfield_value_e;
209 $subfield_value_c = $marcrecord->field('210')->subfield("a")
210 if ( $marcrecord->field('210') );
211 $subfield_value_d = $marcrecord->field('210')->subfield("d")
212 if ( $marcrecord->field('210') );
213 $subfield_value_e = $marcrecord->field('205')->subfield("a")
214 if ( $marcrecord->field('205') );
216 my $subfield_value_h;
217 if ( ( $marcrecord->field('200') )
218 && ( $marcrecord->field('200')->subfield("h") ) )
220 $subfield_value_h = $marcrecord->field('200')->subfield("h");
222 elsif (( $marcrecord->field('225') )
223 && ( $marcrecord->field('225')->subfield("h") ) )
225 $subfield_value_h = $marcrecord->field('225')->subfield("h");
227 elsif (( $marcrecord->field('500') )
228 && ( $marcrecord->field('500')->subfield("h") ) )
230 $subfield_value_h = $marcrecord->field('500')->subfield("h");
233 my $subfield_value_i;
234 if ( ( $marcrecord->field('200') )
235 && ( $marcrecord->field('200')->subfield("i") ) )
237 $subfield_value_i = $marcrecord->field('200')->subfield("i");
239 elsif (( $marcrecord->field('225') )
240 && ( $marcrecord->field('225')->subfield("i") ) )
242 $subfield_value_i = $marcrecord->field('225')->subfield("i");
244 elsif (( $marcrecord->field('500') )
245 && ( $marcrecord->field('500')->subfield("i") ) )
247 $subfield_value_i = $marcrecord->field('500')->subfield("i");
250 my $subfield_value_l;
251 $subfield_value_l = $marcrecord->field('200')->subfield("d")
252 if ( $marcrecord->field('200') );
254 my $subfield_value_n;
255 $subfield_value_n = $marcrecord->field('210')->subfield("c")
256 if ( $marcrecord->field('210') );
258 my $subfield_value_o;
259 $subfield_value_o = $marcrecord->field('200')->subfield("e")
260 if ( $marcrecord->field('200') );
262 my $subfield_value_p;
263 $subfield_value_p = $marcrecord->field('215')->subfield("a")
264 if ( $marcrecord->field('215') );
266 my $subfield_value_t;
267 if ( ( $marcrecord->field('200') )
268 && ( $marcrecord->field('200')->subfield("a") ) )
270 $subfield_value_t = $marcrecord->field('200')->subfield("a");
272 elsif (( $marcrecord->field('225') )
273 && ( $marcrecord->field('225')->subfield("a") ) )
275 $subfield_value_t = $marcrecord->field('225')->subfield("a");
277 elsif (( $marcrecord->field('500') )
278 && ( $marcrecord->field('500')->subfield("a") ) )
280 $subfield_value_t = $marcrecord->field('500')->subfield("a");
283 my $subfield_value_u;
284 if ( $marcrecord->field('856') ) {
285 $subfield_value_u = $marcrecord->field('856')->subfield("u");
288 my $subfield_value_v;
289 if ( ( $marcrecord->field('225') )
290 && ( $marcrecord->field('225')->subfield("v") ) )
292 $subfield_value_v = $marcrecord->field('225')->subfield("v");
294 elsif (( $marcrecord->field('200') )
295 && ( $marcrecord->field('200')->subfield("h") ) )
297 $subfield_value_v = $marcrecord->field('200')->subfield("h");
299 my $subfield_value_x;
301 $marcrecord->field('011')
302 and not( ( $marcrecord->field('011')->subfield("y") )
303 or ( $marcrecord->field('011')->subfield("z") ) ) ) {
304 $subfield_value_x = $marcrecord->field('011')->subfield("a");
306 my $subfield_value_y;
307 if ( $marcrecord->field('013') ) {
308 $subfield_value_y = $marcrecord->field('013')->subfield("a");
310 if ( $marcrecord->field('010') ) {
311 $subfield_value_y = $marcrecord->field('010')->subfield("a");
314 $subfield_value_9 =~ s/'/\\'/g;
315 $subfield_value_0 =~ s/'/\\'/g;
316 $subfield_value_a =~ s/'/\\'/g;
317 $subfield_value_c =~ s/'/\\'/g;
318 $subfield_value_d =~ s/'/\\'/g;
319 $subfield_value_e =~ s/'/\\'/g;
320 $subfield_value_h =~ s/'/\\'/g;
321 $subfield_value_i =~ s/'/\\'/g;
322 $subfield_value_l =~ s/'/\\'/g;
323 $subfield_value_n =~ s/'/\\'/g;
324 $subfield_value_o =~ s/'/\\'/g;
325 $subfield_value_p =~ s/'/\\'/g;
326 $subfield_value_t =~ s/'/\\'/g;
327 $subfield_value_u =~ s/'/\\'/g;
328 $subfield_value_v =~ s/'/\\'/g;
329 $subfield_value_x =~ s/'/\\'/g;
330 $subfield_value_y =~ s/'/\\'/g;
333 index => scalar $query->param('index') . "",
334 biblionumber
=> $biblionumber ?
$biblionumber : "",
335 subfield_value_9
=> "$subfield_value_9",
336 subfield_value_0
=> "$subfield_value_0",
337 subfield_value_a
=> "$subfield_value_a",
338 subfield_value_c
=> "$subfield_value_c",
339 subfield_value_d
=> "$subfield_value_d",
340 subfield_value_e
=> "$subfield_value_e",
341 subfield_value_h
=> "$subfield_value_h",
342 subfield_value_i
=> "$subfield_value_i",
343 subfield_value_l
=> "$subfield_value_l",
344 subfield_value_n
=> "$subfield_value_n",
345 subfield_value_o
=> "$subfield_value_o",
346 subfield_value_p
=> "$subfield_value_p",
347 subfield_value_t
=> "$subfield_value_t",
348 subfield_value_u
=> "$subfield_value_u",
349 subfield_value_v
=> "$subfield_value_v",
350 subfield_value_x
=> "$subfield_value_x",
351 subfield_value_y
=> "$subfield_value_y",
353 ###############################################################
355 elsif ( $op eq "do_search" ) {
356 my $search = $query->param('search');
357 my $itype = $query->param('itype');
358 my $startfrom = $query->param('startfrom');
359 my $resultsperpage = $query->param('resultsperpage') || 20;
362 $QParser = C4
::Context
->queryparser if (C4
::Context
->preference('UseQueryParser'));
369 $search = 'kw:'.$search." $op mc-itemtype:".$itype if $itype;
370 my $searcher = Koha
::SearchEngine
::Search
->new({index => $Koha::SearchEngine
::BIBLIOS_INDEX
});
371 my ( $errors, $results, $total_hits ) = $searcher->simple_search_compat($search, $startfrom * $resultsperpage, $resultsperpage );
372 if (defined $errors ) {
375 my $total = @
{$results};
377 # warn " biblio count : ".$total;
379 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
382 "cataloguing/value_builder/unimarc_field_4XX.tt",
385 authnotrequired
=> 0,
390 # multi page display gestion
392 my $displayprev = $startfrom;
394 if( ( $total_hits - ( ( $startfrom + 1 ) * ($resultsperpage) ) ) > 0 ) {
398 my @field_data = ($search);
401 $i < $resultsperpage ;
405 my $record = C4
::Search
::new_record_from_zebra
( 'biblioserver', $results->[$i] );
407 my $rechash = TransformMarcToKoha
( $record );
408 if ( my $f = $record->field('200') ) {
409 $rechash->{fulltitle
} =
410 join(', ', map { $_->[1] } grep { $_->[0] =~ /[aehi]/ } $f->subfields() );
413 $rechash->{fulltitle
} = $rechash->{title
};
417 if ( $rechash->{itemnumber
} ) {
420 while ( index( $rechash->{itemnumber
}, '|', $pos ) > 0 ) {
422 $pos = index( $rechash->{itemnumber
}, '|', $pos ) + 1;
424 $rechash->{totitem
} = $countitems;
425 my @holdingbranches = split /\|/, $rechash->{holdingbranch
};
426 my @itemcallnumbers = split /\|/, $rechash->{itemcallnumber
};
428 for ( my $i = 0 ; $i < @holdingbranches ; $i++ ) {
430 $holdingbranches[$i] . " ( " . $itemcallnumbers[$i] . " ) |";
433 $rechash->{CN
} = $CN;
434 push @arrayresults, $rechash;
437 # for(my $i = 0 ; $i <= $#marclist ; $i++)
439 # push @field_data, { term => "marclist", val=>$marclist[$i] };
440 # push @field_data, { term => "and_or", val=>$and_or[$i] };
441 # push @field_data, { term => "excluding", val=>$excluding[$i] };
442 # push @field_data, { term => "operator", val=>$operator[$i] };
443 # push @field_data, { term => "value", val=>$value[$i] };
448 if ( $total > $resultsperpage ) {
449 for ( my $i = 1 ; $i < $total / $resultsperpage + 1 ; $i++ ) {
452 ( $startfrom == ( $i - 1 ) ) && ( $highlight = 1 );
456 highlight
=> $highlight,
457 searchdata
=> \
@field_data,
458 startfrom
=> ( $i - 1 )
464 my $from = $startfrom * $resultsperpage + 1;
467 if ( $total_hits < $from + $resultsperpage ) {
470 $to = $from + $resultsperpage ;
473 'BiblioDefaultView' . C4
::Context
->preference('BiblioDefaultView');
474 # my $link="/cgi-bin/koha/cataloguing/value_builder/unimarc4XX.pl?op=do_search&q=$search_desc&resultsperpage=$resultsperpage&startfrom=$startfrom&search=$search";
475 # foreach my $sort (@sort_by){
476 # $link.="&sort_by=".$sort."&";
479 # pagination_bar => pagination_bar(
481 # getnbpages($hits, $results_per_page),
487 result
=> \
@arrayresults,
488 index => scalar $query->param('index') . "",
489 startfrom
=> $startfrom,
490 displaynext
=> $displaynext,
491 displayprev
=> $displayprev,
492 resultsperpage
=> $resultsperpage,
494 startfromnext
=> $startfrom + 1,
495 startfromprev
=> $startfrom - 1,
496 searchdata
=> \
@field_data,
497 total
=> $total_hits,
500 numbers
=> \
@numbers,
508 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
511 "cataloguing/value_builder/unimarc_field_4XX.tt",
514 authnotrequired
=> 0,
518 my @itemtypes = Koha
::ItemTypes
->search;
520 $template->param( #classlist => $classlist,
521 itypeloop
=> \
@itemtypes,
522 index => scalar $query->param('index'),
526 output_html_with_http_headers
$query, $cookie, $template->output;