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
37 use Koha
::SearchEngine
;
38 use Koha
::SearchEngine
::Search
;
40 sub plugin_parameters
{
41 my ( $dbh, $record, $tagslib, $i, $tabloop ) = @_;
45 sub plugin_javascript
{
46 my ( $dbh, $record, $tagslib, $field_number, $tabloop ) = @_;
47 my $function_name = $field_number;
49 <script type='text/javascript'>
50 function Clic$function_name(i) {
51 defaultvalue=document.getElementById(\"$field_number\").value;
52 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');
58 return ( $function_name, $res );
64 # -- op could be equals to
71 my $dbh = C4
::Context
->dbh;
73 my $op = $query->param('op');
74 my $type = $query->param('type');
75 my $startfrom = $query->param('startfrom');
76 $startfrom = 0 if ( !defined $startfrom );
77 my ( $template, $loggedinuser, $cookie );
80 if ( $op eq "fillinput" ) {
81 my $biblionumber = $query->param('biblionumber');
82 my $index = $query->param('index');
86 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
89 "cataloguing/value_builder/unimarc_field_4XX.tt",
93 flagsrequired
=> { editcatalogue
=> '*' },
99 $marcrecord = GetMarcBiblio
({ biblionumber
=> $biblionumber });
101 my $subfield_value_9 = $biblionumber;
102 my $subfield_value_0;
103 $subfield_value_0 = $marcrecord->field('001')->data
104 if $marcrecord->field('001');
105 my $subfield_value_a;
106 if ( $marcrecord->field('700') ) {
107 $subfield_value_a = $marcrecord->field('700')->subfield("a");
108 $subfield_value_a .= ", " . $marcrecord->subfield( '700', "b" )
109 if $marcrecord->subfield( '700', 'b' );
110 $subfield_value_a .= " " . $marcrecord->subfield( '700', "d" )
111 if $marcrecord->subfield( '700', 'd' );
113 " (" . $marcrecord->subfield( '700', 'c' )
114 if $marcrecord->subfield( '700', 'c' );
115 $subfield_value_a .= " ; "
116 if $marcrecord->subfield( '700', 'c' )
117 and $marcrecord->subfield( '700', 'f' );
118 $subfield_value_a .= " ("
119 if ( $marcrecord->subfield( '700', 'f' )
120 and not( $marcrecord->subfield( '700', 'c' ) ) );
121 $subfield_value_a .= $marcrecord->subfield( '700', 'f' )
122 if ( $marcrecord->subfield( '700', 'f' ) );
123 $subfield_value_a .= ")"
124 if ( $marcrecord->subfield( '700', 'f' )
125 or $marcrecord->subfield( '700', 'c' ) );
127 elsif ( $marcrecord->field('702') ) {
128 $subfield_value_a = $marcrecord->subfield( '702', 'a' );
129 $subfield_value_a .= ", " . $marcrecord->subfield( '702', 'b' )
130 if $marcrecord->subfield( '702', 'b' );
131 $subfield_value_a .= " " . $marcrecord->subfield( '702', 'd' )
132 if $marcrecord->subfield( '702', 'd' );
134 " (" . $marcrecord->subfield( '702', 'c' )
135 if $marcrecord->subfield( '702', 'c' );
136 $subfield_value_a .= " ; "
137 if $marcrecord->subfield( '702', 'c' )
138 and $marcrecord->subfield( '702', 'f' );
139 $subfield_value_a .= " ("
140 if $marcrecord->subfield( '702', 'f' )
141 and not $marcrecord->subfield( '702', 'c' );
142 $subfield_value_a .= $marcrecord->subfield( '702', 'f' )
143 if $marcrecord->subfield( '702', 'f' );
144 $subfield_value_a .= ")"
145 if $marcrecord->subfield( '702', 'f' )
146 or $marcrecord->subfield( '702', 'c' );
148 elsif ( $marcrecord->field('710') ) {
149 $subfield_value_a = $marcrecord->subfield( '710', 'd' ) . " "
150 if $marcrecord->subfield( '710', 'd' );
151 $subfield_value_a .= $marcrecord->subfield( '710', 'a' )
152 if $marcrecord->subfield( '710', 'a' );
153 $subfield_value_a .= ", " . $marcrecord->subfield( '710', 'b' )
154 if $marcrecord->subfield('710');
156 " (" . $marcrecord->subfield( '710', 'f' ) . " - "
157 if $marcrecord->subfield( '710', 'f' );
158 $subfield_value_a .= " ("
159 if $marcrecord->subfield( '710', 'e' )
160 and not $marcrecord->subfield( '710', 'f' );
161 $subfield_value_a .= $marcrecord->subfield( '710', 'e' )
162 if $marcrecord->subfield( '710', 'e' );
163 $subfield_value_a .= ")"
164 if $marcrecord->subfield( '710', 'e' )
165 or $marcrecord->subfield( '710', 'f' );
167 elsif ( $marcrecord->field('701') ) {
168 $subfield_value_a = $marcrecord->subfield( '701', 'a' );
169 $subfield_value_a .= ", " . $marcrecord->subfield( '701', 'b' )
170 if $marcrecord->subfield( '701', 'b' );
171 $subfield_value_a .= " " . $marcrecord->subfield( '701', 'd', )
172 if $marcrecord->subfield( '701', 'd' );
174 " (" . $marcrecord->subfield( '701', 'c' ) . " - "
175 if $marcrecord->subfield( '701', 'c' );
176 $subfield_value_a .= " ("
177 if $marcrecord->subfield( '701', 'f' )
178 and not( $marcrecord->subfield( '701', 'c' ) );
179 $subfield_value_a .= $marcrecord->subfield( '701', 'f' )
180 if $marcrecord->subfield( '701', 'f' );
181 $subfield_value_a .= ")"
182 if $marcrecord->subfield( '701', 'f' )
183 or $marcrecord->subfield( '701', 'c' );
185 elsif ( $marcrecord->field('712') ) {
186 $subfield_value_a = $marcrecord->subfield( '712', 'd' ) . " "
187 if $marcrecord->subfield( '712', 'd' );
188 $subfield_value_a .= $marcrecord->subfield( '712', 'a' )
189 if $marcrecord->subfield( '712', 'a' );
190 $subfield_value_a .= ", " . $marcrecord->subfield( '712', 'b' )
191 if $marcrecord->subfield( '712', 'b' );
193 " (" . $marcrecord->subfield( '712', 'f' ) . " - "
194 if $marcrecord->subfield( '712', 'f' );
195 $subfield_value_a .= " ("
196 if $marcrecord->subfield( '712', "e" )
197 and not $marcrecord->subfield( '712', 'f' );
198 $subfield_value_a .= $marcrecord->subfield( '712', 'e' )
199 if $marcrecord->subfield( '712', 'e' );
200 $subfield_value_a .= ")"
201 if $marcrecord->subfield( '712', 'e' )
202 or $marcrecord->subfield( '712', 'f' );
204 elsif ( $marcrecord->field('200') ) {
205 $subfield_value_a = $marcrecord->subfield( '200', 'f' );
207 my $subfield_value_c;
208 my $subfield_value_d;
209 my $subfield_value_e;
210 $subfield_value_c = $marcrecord->field('210')->subfield("a")
211 if ( $marcrecord->field('210') );
212 $subfield_value_d = $marcrecord->field('210')->subfield("d")
213 if ( $marcrecord->field('210') );
214 $subfield_value_e = $marcrecord->field('205')->subfield("a")
215 if ( $marcrecord->field('205') );
217 my $subfield_value_h;
218 if ( ( $marcrecord->field('200') )
219 && ( $marcrecord->field('200')->subfield("h") ) )
221 $subfield_value_h = $marcrecord->field('200')->subfield("h");
223 elsif (( $marcrecord->field('225') )
224 && ( $marcrecord->field('225')->subfield("h") ) )
226 $subfield_value_h = $marcrecord->field('225')->subfield("h");
228 elsif (( $marcrecord->field('500') )
229 && ( $marcrecord->field('500')->subfield("h") ) )
231 $subfield_value_h = $marcrecord->field('500')->subfield("h");
234 my $subfield_value_i;
235 if ( ( $marcrecord->field('200') )
236 && ( $marcrecord->field('200')->subfield("i") ) )
238 $subfield_value_i = $marcrecord->field('200')->subfield("i");
240 elsif (( $marcrecord->field('225') )
241 && ( $marcrecord->field('225')->subfield("i") ) )
243 $subfield_value_i = $marcrecord->field('225')->subfield("i");
245 elsif (( $marcrecord->field('500') )
246 && ( $marcrecord->field('500')->subfield("i") ) )
248 $subfield_value_i = $marcrecord->field('500')->subfield("i");
251 my $subfield_value_l;
252 $subfield_value_l = $marcrecord->field('200')->subfield("d")
253 if ( $marcrecord->field('200') );
255 my $subfield_value_n;
256 $subfield_value_n = $marcrecord->field('210')->subfield("c")
257 if ( $marcrecord->field('210') );
259 my $subfield_value_o;
260 $subfield_value_o = $marcrecord->field('200')->subfield("e")
261 if ( $marcrecord->field('200') );
263 my $subfield_value_p;
264 $subfield_value_p = $marcrecord->field('215')->subfield("a")
265 if ( $marcrecord->field('215') );
267 my $subfield_value_t;
268 if ( ( $marcrecord->field('200') )
269 && ( $marcrecord->field('200')->subfield("a") ) )
271 $subfield_value_t = $marcrecord->field('200')->subfield("a");
273 elsif (( $marcrecord->field('225') )
274 && ( $marcrecord->field('225')->subfield("a") ) )
276 $subfield_value_t = $marcrecord->field('225')->subfield("a");
278 elsif (( $marcrecord->field('500') )
279 && ( $marcrecord->field('500')->subfield("a") ) )
281 $subfield_value_t = $marcrecord->field('500')->subfield("a");
284 my $subfield_value_u;
285 if ( $marcrecord->field('856') ) {
286 $subfield_value_u = $marcrecord->field('856')->subfield("u");
289 my $subfield_value_v;
290 if ( ( $marcrecord->field('225') )
291 && ( $marcrecord->field('225')->subfield("v") ) )
293 $subfield_value_v = $marcrecord->field('225')->subfield("v");
295 elsif (( $marcrecord->field('200') )
296 && ( $marcrecord->field('200')->subfield("h") ) )
298 $subfield_value_v = $marcrecord->field('200')->subfield("h");
300 my $subfield_value_x;
302 $marcrecord->field('011')
303 and not( ( $marcrecord->field('011')->subfield("y") )
304 or ( $marcrecord->field('011')->subfield("z") ) ) ) {
305 $subfield_value_x = $marcrecord->field('011')->subfield("a");
307 my $subfield_value_y;
308 if ( $marcrecord->field('013') ) {
309 $subfield_value_y = $marcrecord->field('013')->subfield("a");
311 if ( $marcrecord->field('010') ) {
312 $subfield_value_y = $marcrecord->field('010')->subfield("a");
315 $subfield_value_9 =~ s/'/\\'/g;
316 $subfield_value_0 =~ s/'/\\'/g;
317 $subfield_value_a =~ s/'/\\'/g;
318 $subfield_value_c =~ s/'/\\'/g;
319 $subfield_value_d =~ s/'/\\'/g;
320 $subfield_value_e =~ s/'/\\'/g;
321 $subfield_value_h =~ s/'/\\'/g;
322 $subfield_value_i =~ s/'/\\'/g;
323 $subfield_value_l =~ s/'/\\'/g;
324 $subfield_value_n =~ s/'/\\'/g;
325 $subfield_value_o =~ s/'/\\'/g;
326 $subfield_value_p =~ s/'/\\'/g;
327 $subfield_value_t =~ s/'/\\'/g;
328 $subfield_value_u =~ s/'/\\'/g;
329 $subfield_value_v =~ s/'/\\'/g;
330 $subfield_value_x =~ s/'/\\'/g;
331 $subfield_value_y =~ s/'/\\'/g;
334 index => scalar $query->param('index') . "",
335 biblionumber
=> $biblionumber ?
$biblionumber : "",
336 subfield_value_9
=> "$subfield_value_9",
337 subfield_value_0
=> "$subfield_value_0",
338 subfield_value_a
=> "$subfield_value_a",
339 subfield_value_c
=> "$subfield_value_c",
340 subfield_value_d
=> "$subfield_value_d",
341 subfield_value_e
=> "$subfield_value_e",
342 subfield_value_h
=> "$subfield_value_h",
343 subfield_value_i
=> "$subfield_value_i",
344 subfield_value_l
=> "$subfield_value_l",
345 subfield_value_n
=> "$subfield_value_n",
346 subfield_value_o
=> "$subfield_value_o",
347 subfield_value_p
=> "$subfield_value_p",
348 subfield_value_t
=> "$subfield_value_t",
349 subfield_value_u
=> "$subfield_value_u",
350 subfield_value_v
=> "$subfield_value_v",
351 subfield_value_x
=> "$subfield_value_x",
352 subfield_value_y
=> "$subfield_value_y",
354 ###############################################################
356 elsif ( $op eq "do_search" ) {
357 my $search = $query->param('search');
358 my $itype = $query->param('itype');
359 my $startfrom = $query->param('startfrom');
360 my $resultsperpage = $query->param('resultsperpage') || 20;
363 $QParser = C4
::Context
->queryparser if (C4
::Context
->preference('UseQueryParser'));
370 $search = 'kw:'.$search." $op mc-itemtype:".$itype if $itype;
371 my $searcher = Koha
::SearchEngine
::Search
->new({index => $Koha::SearchEngine
::BIBLIOS_INDEX
});
372 my ( $errors, $results, $total_hits ) = $searcher->simple_search_compat($search, $startfrom * $resultsperpage, $resultsperpage );
373 if (defined $errors ) {
376 my $total = @
{$results};
378 # warn " biblio count : ".$total;
380 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
383 "cataloguing/value_builder/unimarc_field_4XX.tt",
386 authnotrequired
=> 0,
391 # multi page display gestion
393 my $displayprev = $startfrom;
395 if( ( $total_hits - ( ( $startfrom + 1 ) * ($resultsperpage) ) ) > 0 ) {
399 my @field_data = ($search);
402 $i < $total && $i < $resultsperpage ;
406 my $record = C4
::Search
::new_record_from_zebra
( 'biblioserver', $results->[$i] );
408 my $rechash = TransformMarcToKoha
( $record );
409 if ( my $f = $record->field('200') ) {
410 $rechash->{fulltitle
} =
411 join(', ', map { $_->[1] } grep { $_->[0] =~ /[aehi]/ } $f->subfields() );
414 $rechash->{fulltitle
} = $rechash->{title
};
418 if ( $rechash->{itemnumber
} ) {
421 while ( index( $rechash->{itemnumber
}, '|', $pos ) > 0 ) {
423 $pos = index( $rechash->{itemnumber
}, '|', $pos ) + 1;
425 $rechash->{totitem
} = $countitems;
426 my @holdingbranches = split /\|/, $rechash->{holdingbranch
};
427 my @itemcallnumbers = split /\|/, $rechash->{itemcallnumber
};
429 for ( my $i = 0 ; $i < @holdingbranches ; $i++ ) {
431 $holdingbranches[$i] . " ( " . $itemcallnumbers[$i] . " ) |";
434 $rechash->{CN
} = $CN;
435 push @arrayresults, $rechash;
438 # for(my $i = 0 ; $i <= $#marclist ; $i++)
440 # push @field_data, { term => "marclist", val=>$marclist[$i] };
441 # push @field_data, { term => "and_or", val=>$and_or[$i] };
442 # push @field_data, { term => "excluding", val=>$excluding[$i] };
443 # push @field_data, { term => "operator", val=>$operator[$i] };
444 # push @field_data, { term => "value", val=>$value[$i] };
449 if ( $total > $resultsperpage ) {
450 for ( my $i = 1 ; $i < $total / $resultsperpage + 1 ; $i++ ) {
453 ( $startfrom == ( $i - 1 ) ) && ( $highlight = 1 );
457 highlight
=> $highlight,
458 searchdata
=> \
@field_data,
459 startfrom
=> ( $i - 1 )
465 my $from = $startfrom * $resultsperpage + 1;
468 if ( $total_hits < $from + $resultsperpage ) {
471 $to = $from + $resultsperpage ;
474 'BiblioDefaultView' . C4
::Context
->preference('BiblioDefaultView');
475 # my $link="/cgi-bin/koha/cataloguing/value_builder/unimarc4XX.pl?op=do_search&q=$search_desc&resultsperpage=$resultsperpage&startfrom=$startfrom&search=$search";
476 # foreach my $sort (@sort_by){
477 # $link.="&sort_by=".$sort."&";
480 # pagination_bar => pagination_bar(
482 # getnbpages($hits, $results_per_page),
488 result
=> \
@arrayresults,
489 index => scalar $query->param('index') . "",
490 startfrom
=> $startfrom,
491 displaynext
=> $displaynext,
492 displayprev
=> $displayprev,
493 resultsperpage
=> $resultsperpage,
495 startfromnext
=> $startfrom + 1,
496 startfromprev
=> $startfrom - 1,
497 searchdata
=> \
@field_data,
498 total
=> $total_hits,
501 numbers
=> \
@numbers,
509 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
512 "cataloguing/value_builder/unimarc_field_4XX.tt",
515 authnotrequired
=> 0,
519 my @itemtypes = Koha
::ItemTypes
->search;
521 $template->param( #classlist => $classlist,
522 itypeloop
=> \
@itemtypes,
523 index => scalar $query->param('index'),
527 output_html_with_http_headers
$query, $cookie, $template->output;