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>.
22 #use warnings; FIXME - Bug 2505
34 use C4
::Branch
; # GetBranches
38 use Koha
::SearchEngine
;
39 use Koha
::SearchEngine
::Search
;
41 sub plugin_parameters
{
42 my ( $dbh, $record, $tagslib, $i, $tabloop ) = @_;
46 sub plugin_javascript
{
47 my ( $dbh, $record, $tagslib, $field_number, $tabloop ) = @_;
48 my $function_name = $field_number;
50 <script type='text/javascript'>
51 function Clic$function_name(i) {
52 defaultvalue=document.getElementById(\"$field_number\").value;
53 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');
59 return ( $function_name, $res );
65 # -- op could be equals to
72 my $dbh = C4
::Context
->dbh;
74 my $op = $query->param('op');
75 my $type = $query->param('type');
76 my $startfrom = $query->param('startfrom');
77 $startfrom = 0 if ( !defined $startfrom );
78 my ( $template, $loggedinuser, $cookie );
81 if ( $op eq "fillinput" ) {
82 my $biblionumber = $query->param('biblionumber');
83 my $index = $query->param('index');
87 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
90 "cataloguing/value_builder/unimarc_field_4XX.tt",
94 flagsrequired
=> { editcatalogue
=> '*' },
100 $marcrecord = GetMarcBiblio
($biblionumber);
102 my $subfield_value_9 = $biblionumber;
103 my $subfield_value_0;
104 $subfield_value_0 = $marcrecord->field('001')->data
105 if $marcrecord->field('001');
106 my $subfield_value_a;
107 if ( $marcrecord->field('700') ) {
108 $subfield_value_a = $marcrecord->field('700')->subfield("a");
109 $subfield_value_a .= ", " . $marcrecord->subfield( '700', "b" )
110 if $marcrecord->subfield( '700', 'b' );
111 $subfield_value_a .= " " . $marcrecord->subfield( '700', "d" )
112 if $marcrecord->subfield( '700', 'd' );
114 " (" . $marcrecord->subfield( '700', 'c' )
115 if $marcrecord->subfield( '700', 'c' );
116 $subfield_value_a .= " ; "
117 if $marcrecord->subfield( '700', 'c' )
118 and $marcrecord->subfield( '700', 'f' );
119 $subfield_value_a .= " ("
120 if ( $marcrecord->subfield( '700', 'f' )
121 and not( $marcrecord->subfield( '700', 'c' ) ) );
122 $subfield_value_a .= $marcrecord->subfield( '700', 'f' )
123 if ( $marcrecord->subfield( '700', 'f' ) );
124 $subfield_value_a .= ")"
125 if ( $marcrecord->subfield( '700', 'f' )
126 or $marcrecord->subfield( '700', 'c' ) );
128 elsif ( $marcrecord->field('702') ) {
129 $subfield_value_a = $marcrecord->subfield( '702', 'a' );
130 $subfield_value_a .= ", " . $marcrecord->subfield( '702', 'b' )
131 if $marcrecord->subfield( '702', 'b' );
132 $subfield_value_a .= " " . $marcrecord->subfield( '702', 'd' )
133 if $marcrecord->subfield( '702', 'd' );
135 " (" . $marcrecord->subfield( '702', 'c' )
136 if $marcrecord->subfield( '702', 'c' );
137 $subfield_value_a .= " ; "
138 if $marcrecord->subfield( '702', 'c' )
139 and $marcrecord->subfield( '702', 'f' );
140 $subfield_value_a .= " ("
141 if $marcrecord->subfield( '702', 'f' )
142 and not $marcrecord->subfield( '702', 'c' );
143 $subfield_value_a .= $marcrecord->subfield( '702', 'f' )
144 if $marcrecord->subfield( '702', 'f' );
145 $subfield_value_a .= ")"
146 if $marcrecord->subfield( '702', 'f' )
147 or $marcrecord->subfield( '702', 'c' );
149 elsif ( $marcrecord->field('710') ) {
150 $subfield_value_a = $marcrecord->subfield( '710', 'd' ) . " "
151 if $marcrecord->subfield( '710', 'd' );
152 $subfield_value_a .= $marcrecord->subfield( '710', 'a' )
153 if $marcrecord->subfield( '710', 'a' );
154 $subfield_value_a .= ", " . $marcrecord->subfield( '710', 'b' )
155 if $marcrecord->subfield('710');
157 " (" . $marcrecord->subfield( '710', 'f' ) . " - "
158 if $marcrecord->subfield( '710', 'f' );
159 $subfield_value_a .= " ("
160 if $marcrecord->subfield( '710', 'e' )
161 and not $marcrecord->subfield( '710', 'f' );
162 $subfield_value_a .= $marcrecord->subfield( '710', 'e' )
163 if $marcrecord->subfield( '710', 'e' );
164 $subfield_value_a .= ")"
165 if $marcrecord->subfield( '710', 'e' )
166 or $marcrecord->subfield( '710', 'f' );
168 elsif ( $marcrecord->field('701') ) {
169 $subfield_value_a = $marcrecord->subfield( '701', 'a' );
170 $subfield_value_a .= ", " . $marcrecord->subfield( '701', 'b' )
171 if $marcrecord->subfield( '701', 'b' );
172 $subfield_value_a .= " " . $marcrecord->subfield( '701', 'd', )
173 if $marcrecord->subfield( '701', 'd' );
175 " (" . $marcrecord->subfield( '701', 'c' ) . " - "
176 if $marcrecord->subfield( '701', 'c' );
177 $subfield_value_a .= " ("
178 if $marcrecord->subfield( '701', 'f' )
179 and not( $marcrecord->subfield( '701', 'c' ) );
180 $subfield_value_a .= $marcrecord->subfield( '701', 'f' )
181 if $marcrecord->subfield( '701', 'f' );
182 $subfield_value_a .= ")"
183 if $marcrecord->subfield( '701', 'f' )
184 or $marcrecord->subfield( '701', 'c' );
186 elsif ( $marcrecord->field('712') ) {
187 $subfield_value_a = $marcrecord->subfield( '712', 'd' ) . " "
188 if $marcrecord->subfield( '712', 'd' );
189 $subfield_value_a .= $marcrecord->subfield( '712', 'a' )
190 if $marcrecord->subfield( '712', 'a' );
191 $subfield_value_a .= ", " . $marcrecord->subfield( '712', 'b' )
192 if $marcrecord->subfield( '712', 'b' );
194 " (" . $marcrecord->subfield( '712', 'f' ) . " - "
195 if $marcrecord->subfield( '712', 'f' );
196 $subfield_value_a .= " ("
197 if $marcrecord->subfield( '712', "e" )
198 and not $marcrecord->subfield( '712', 'f' );
199 $subfield_value_a .= $marcrecord->subfield( '712', 'e' )
200 if $marcrecord->subfield( '712', 'e' );
201 $subfield_value_a .= ")"
202 if $marcrecord->subfield( '712', 'e' )
203 or $marcrecord->subfield( '712', 'f' );
205 elsif ( $marcrecord->field('200') ) {
206 $subfield_value_a = $marcrecord->subfield( '200', 'f' );
208 my $subfield_value_c;
209 my $subfield_value_d;
210 my $subfield_value_e;
211 $subfield_value_c = $marcrecord->field('210')->subfield("a")
212 if ( $marcrecord->field('210') );
213 $subfield_value_d = $marcrecord->field('210')->subfield("d")
214 if ( $marcrecord->field('210') );
215 $subfield_value_e = $marcrecord->field('205')->subfield("a")
216 if ( $marcrecord->field('205') );
218 my $subfield_value_h;
219 if ( ( $marcrecord->field('200') )
220 && ( $marcrecord->field('200')->subfield("h") ) )
222 $subfield_value_h = $marcrecord->field('200')->subfield("h");
224 elsif (( $marcrecord->field('225') )
225 && ( $marcrecord->field('225')->subfield("h") ) )
227 $subfield_value_h = $marcrecord->field('225')->subfield("h");
229 elsif (( $marcrecord->field('500') )
230 && ( $marcrecord->field('500')->subfield("h") ) )
232 $subfield_value_h = $marcrecord->field('500')->subfield("h");
235 my $subfield_value_i;
236 if ( ( $marcrecord->field('200') )
237 && ( $marcrecord->field('200')->subfield("i") ) )
239 $subfield_value_i = $marcrecord->field('200')->subfield("i");
241 elsif (( $marcrecord->field('225') )
242 && ( $marcrecord->field('225')->subfield("i") ) )
244 $subfield_value_i = $marcrecord->field('225')->subfield("i");
246 elsif (( $marcrecord->field('500') )
247 && ( $marcrecord->field('500')->subfield("i") ) )
249 $subfield_value_i = $marcrecord->field('500')->subfield("i");
252 my $subfield_value_l;
253 $subfield_value_l = $marcrecord->field('200')->subfield("d")
254 if ( $marcrecord->field('200') );
256 my $subfield_value_n;
257 $subfield_value_n = $marcrecord->field('210')->subfield("c")
258 if ( $marcrecord->field('210') );
260 my $subfield_value_o;
261 $subfield_value_o = $marcrecord->field('200')->subfield("e")
262 if ( $marcrecord->field('200') );
264 my $subfield_value_p;
265 $subfield_value_p = $marcrecord->field('215')->subfield("a")
266 if ( $marcrecord->field('215') );
268 my $subfield_value_t;
269 if ( ( $marcrecord->field('200') )
270 && ( $marcrecord->field('200')->subfield("a") ) )
272 $subfield_value_t = $marcrecord->field('200')->subfield("a");
274 elsif (( $marcrecord->field('225') )
275 && ( $marcrecord->field('225')->subfield("a") ) )
277 $subfield_value_t = $marcrecord->field('225')->subfield("a");
279 elsif (( $marcrecord->field('500') )
280 && ( $marcrecord->field('500')->subfield("a") ) )
282 $subfield_value_t = $marcrecord->field('500')->subfield("a");
285 my $subfield_value_u;
286 if ( $marcrecord->field('856') ) {
287 $subfield_value_u = $marcrecord->field('856')->subfield("u");
290 my $subfield_value_v;
291 if ( ( $marcrecord->field('225') )
292 && ( $marcrecord->field('225')->subfield("v") ) )
294 $subfield_value_v = $marcrecord->field('225')->subfield("v");
296 elsif (( $marcrecord->field('200') )
297 && ( $marcrecord->field('200')->subfield("h") ) )
299 $subfield_value_v = $marcrecord->field('200')->subfield("h");
301 my $subfield_value_x;
303 $marcrecord->field('011')
304 and not( ( $marcrecord->field('011')->subfield("y") )
305 or ( $marcrecord->field('011')->subfield("z") ) ) ) {
306 $subfield_value_x = $marcrecord->field('011')->subfield("a");
308 my $subfield_value_y;
309 if ( $marcrecord->field('013') ) {
310 $subfield_value_y = $marcrecord->field('013')->subfield("a");
312 if ( $marcrecord->field('010') ) {
313 $subfield_value_y = $marcrecord->field('010')->subfield("a");
316 $subfield_value_9 =~ s/'/\\'/g;
317 $subfield_value_0 =~ s/'/\\'/g;
318 $subfield_value_a =~ s/'/\\'/g;
319 $subfield_value_c =~ s/'/\\'/g;
320 $subfield_value_d =~ s/'/\\'/g;
321 $subfield_value_e =~ s/'/\\'/g;
322 $subfield_value_h =~ s/'/\\'/g;
323 $subfield_value_i =~ s/'/\\'/g;
324 $subfield_value_l =~ s/'/\\'/g;
325 $subfield_value_n =~ s/'/\\'/g;
326 $subfield_value_o =~ s/'/\\'/g;
327 $subfield_value_p =~ s/'/\\'/g;
328 $subfield_value_t =~ s/'/\\'/g;
329 $subfield_value_u =~ s/'/\\'/g;
330 $subfield_value_v =~ s/'/\\'/g;
331 $subfield_value_x =~ s/'/\\'/g;
332 $subfield_value_y =~ s/'/\\'/g;
335 index => scalar $query->param('index') . "",
336 biblionumber
=> $biblionumber ?
$biblionumber : "",
337 subfield_value_9
=> "$subfield_value_9",
338 subfield_value_0
=> "$subfield_value_0",
339 subfield_value_a
=> "$subfield_value_a",
340 subfield_value_c
=> "$subfield_value_c",
341 subfield_value_d
=> "$subfield_value_d",
342 subfield_value_e
=> "$subfield_value_e",
343 subfield_value_h
=> "$subfield_value_h",
344 subfield_value_i
=> "$subfield_value_i",
345 subfield_value_l
=> "$subfield_value_l",
346 subfield_value_n
=> "$subfield_value_n",
347 subfield_value_o
=> "$subfield_value_o",
348 subfield_value_p
=> "$subfield_value_p",
349 subfield_value_t
=> "$subfield_value_t",
350 subfield_value_u
=> "$subfield_value_u",
351 subfield_value_v
=> "$subfield_value_v",
352 subfield_value_x
=> "$subfield_value_x",
353 subfield_value_y
=> "$subfield_value_y",
355 ###############################################################
357 elsif ( $op eq "do_search" ) {
358 my $search = $query->param('search');
359 my $itype = $query->param('itype');
360 my $startfrom = $query->param('startfrom');
361 my $resultsperpage = $query->param('resultsperpage') || 20;
364 $QParser = C4
::Context
->queryparser if (C4
::Context
->preference('UseQueryParser'));
371 $search = 'kw:'.$search." $op mc-itemtype:".$itype if $itype;
372 my $searcher = Koha
::SearchEngine
::Search
->new({index => $Koha::SearchEngine
::BIBLIOS_INDEX
});
373 my ( $errors, $results, $total_hits ) = $searcher->simple_search_compat($search, $startfrom * $resultsperpage, $resultsperpage );
374 if (defined $errors ) {
377 my $total = @
{$results};
379 # warn " biblio count : ".$total;
381 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
384 "cataloguing/value_builder/unimarc_field_4XX.tt",
387 authnotrequired
=> 0,
392 # multi page display gestion
394 my $displayprev = $startfrom;
396 if( ( $total_hits - ( ( $startfrom + 1 ) * ($resultsperpage) ) ) > 0 ) {
400 my @field_data = ($search);
403 $i < $resultsperpage ;
407 my $record = C4
::Search
::new_record_from_zebra
( 'biblioserver', $results->[$i] );
409 my $rechash = TransformMarcToKoha
( $record );
410 if ( my $f = $record->field('200') ) {
411 $rechash->{fulltitle
} =
412 join(', ', map { $_->[1] } grep { $_->[0] =~ /[aehi]/ } $f->subfields() );
415 $rechash->{fulltitle
} = $rechash->{title
};
419 if ( $rechash->{itemnumber
} ) {
422 while ( index( $rechash->{itemnumber
}, '|', $pos ) > 0 ) {
424 $pos = index( $rechash->{itemnumber
}, '|', $pos ) + 1;
426 $rechash->{totitem
} = $countitems;
427 my @holdingbranches = split /\|/, $rechash->{holdingbranch
};
428 my @itemcallnumbers = split /\|/, $rechash->{itemcallnumber
};
430 for ( my $i = 0 ; $i < @holdingbranches ; $i++ ) {
432 $holdingbranches[$i] . " ( " . $itemcallnumbers[$i] . " ) |";
435 $rechash->{CN
} = $CN;
436 push @arrayresults, $rechash;
439 # for(my $i = 0 ; $i <= $#marclist ; $i++)
441 # push @field_data, { term => "marclist", val=>$marclist[$i] };
442 # push @field_data, { term => "and_or", val=>$and_or[$i] };
443 # push @field_data, { term => "excluding", val=>$excluding[$i] };
444 # push @field_data, { term => "operator", val=>$operator[$i] };
445 # push @field_data, { term => "value", val=>$value[$i] };
450 if ( $total > $resultsperpage ) {
451 for ( my $i = 1 ; $i < $total / $resultsperpage + 1 ; $i++ ) {
454 ( $startfrom == ( $i - 1 ) ) && ( $highlight = 1 );
458 highlight
=> $highlight,
459 searchdata
=> \
@field_data,
460 startfrom
=> ( $i - 1 )
466 my $from = $startfrom * $resultsperpage + 1;
469 if ( $total_hits < $from + $resultsperpage ) {
472 $to = $from + $resultsperpage ;
475 'BiblioDefaultView' . C4
::Context
->preference('BiblioDefaultView');
476 # my $link="/cgi-bin/koha/cataloguing/value_builder/unimarc4XX.pl?op=do_search&q=$search_desc&resultsperpage=$resultsperpage&startfrom=$startfrom&search=$search";
477 # foreach my $sort (@sort_by){
478 # $link.="&sort_by=".$sort."&";
481 # pagination_bar => pagination_bar(
483 # getnbpages($hits, $results_per_page),
489 result
=> \
@arrayresults,
490 index => scalar $query->param('index') . "",
491 startfrom
=> $startfrom,
492 displaynext
=> $displaynext,
493 displayprev
=> $displayprev,
494 resultsperpage
=> $resultsperpage,
496 startfromnext
=> $startfrom + 1,
497 startfromprev
=> $startfrom - 1,
498 searchdata
=> \
@field_data,
499 total
=> $total_hits,
502 numbers
=> \
@numbers,
510 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
513 "cataloguing/value_builder/unimarc_field_4XX.tt",
516 authnotrequired
=> 0,
520 my @itemtypes = Koha
::ItemTypes
->search;
522 $template->param( #classlist => $classlist,
523 itypeloop
=> \
@itemtypes,
524 index => scalar $query->param('index'),
528 output_html_with_http_headers
$query, $cookie, $template->output;