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
37 sub plugin_parameters
{
38 my ( $dbh, $record, $tagslib, $i, $tabloop ) = @_;
42 sub plugin_javascript
{
43 my ( $dbh, $record, $tagslib, $field_number, $tabloop ) = @_;
44 my $function_name = $field_number;
46 <script type='text/javascript'>
47 function Focus$function_name(subfield_managed) {
51 function Blur$function_name(subfield_managed) {
55 function Clic$function_name(i) {
56 defaultvalue=document.getElementById(\"$field_number\").value;
57 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');
63 return ( $function_name, $res );
69 # -- op could be equals to
76 my $dbh = C4
::Context
->dbh;
78 my $op = $query->param('op');
79 my $type = $query->param('type');
80 my $startfrom = $query->param('startfrom');
81 $startfrom = 0 if ( !defined $startfrom );
82 my ( $template, $loggedinuser, $cookie );
86 if ( $op eq "fillinput" ) {
87 my $biblionumber = $query->param('biblionumber');
88 my $index = $query->param('index');
92 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
95 "cataloguing/value_builder/unimarc_field_4XX.tt",
99 flagsrequired
=> { editcatalogue
=> '*' },
105 $marcrecord = GetMarcBiblio
($biblionumber);
107 my $subfield_value_9 = $biblionumber;
108 my $subfield_value_0;
109 $subfield_value_0 = $marcrecord->field('001')->data
110 if $marcrecord->field('001');
111 my $subfield_value_a;
112 if ( $marcrecord->field('700') ) {
113 $subfield_value_a = $marcrecord->field('700')->subfield("a");
114 $subfield_value_a .= ", " . $marcrecord->subfield( '700', "b" )
115 if $marcrecord->subfield( '700', 'b' );
116 $subfield_value_a .= " " . $marcrecord->subfield( '700', "d" )
117 if $marcrecord->subfield( '700', 'd' );
119 " (" . $marcrecord->subfield( '700', 'c' )
120 if $marcrecord->subfield( '700', 'c' );
121 $subfield_value_a .= " ; "
122 if $marcrecord->subfield( '700', 'c' )
123 and $marcrecord->subfield( '700', 'f' );
124 $subfield_value_a .= " ("
125 if ( $marcrecord->subfield( '700', 'f' )
126 and not( $marcrecord->subfield( '700', 'c' ) ) );
127 $subfield_value_a .= $marcrecord->subfield( '700', 'f' )
128 if ( $marcrecord->subfield( '700', 'f' ) );
129 $subfield_value_a .= ")"
130 if ( $marcrecord->subfield( '700', 'f' )
131 or $marcrecord->subfield( '700', 'c' ) );
133 elsif ( $marcrecord->field('702') ) {
134 $subfield_value_a = $marcrecord->subfield( '702', 'a' );
135 $subfield_value_a .= ", " . $marcrecord->subfield( '702', 'b' )
136 if $marcrecord->subfield( '702', 'b' );
137 $subfield_value_a .= " " . $marcrecord->subfield( '702', 'd' )
138 if $marcrecord->subfield( '702', 'd' );
140 " (" . $marcrecord->subfield( '702', 'c' )
141 if $marcrecord->subfield( '702', 'c' );
142 $subfield_value_a .= " ; "
143 if $marcrecord->subfield( '702', 'c' )
144 and $marcrecord->subfield( '702', 'f' );
145 $subfield_value_a .= " ("
146 if $marcrecord->subfield( '702', 'f' )
147 and not $marcrecord->subfield( '702', 'c' );
148 $subfield_value_a .= $marcrecord->subfield( '702', 'f' )
149 if $marcrecord->subfield( '702', 'f' );
150 $subfield_value_a .= ")"
151 if $marcrecord->subfield( '702', 'f' )
152 or $marcrecord->subfield( '702', 'c' );
154 elsif ( $marcrecord->field('710') ) {
155 $subfield_value_a = $marcrecord->subfield( '710', 'd' ) . " "
156 if $marcrecord->subfield( '710', 'd' );
157 $subfield_value_a .= $marcrecord->subfield( '710', 'a' )
158 if $marcrecord->subfield( '710', 'a' );
159 $subfield_value_a .= ", " . $marcrecord->subfield( '710', 'b' )
160 if $marcrecord->subfield('710');
162 " (" . $marcrecord->subfield( '710', 'f' ) . " - "
163 if $marcrecord->subfield( '710', 'f' );
164 $subfield_value_a .= " ("
165 if $marcrecord->subfield( '710', 'e' )
166 and not $marcrecord->subfield( '710', 'f' );
167 $subfield_value_a .= $marcrecord->subfield( '710', 'e' )
168 if $marcrecord->subfield( '710', 'e' );
169 $subfield_value_a .= ")"
170 if $marcrecord->subfield( '710', 'e' )
171 or $marcrecord->subfield( '710', 'f' );
173 elsif ( $marcrecord->field('701') ) {
174 $subfield_value_a = $marcrecord->subfield( '701', 'a' );
175 $subfield_value_a .= ", " . $marcrecord->subfield( '701', 'b' )
176 if $marcrecord->subfield( '701', 'b' );
177 $subfield_value_a .= " " . $marcrecord->subfield( '701', 'd', )
178 if $marcrecord->subfield( '701', 'd' );
180 " (" . $marcrecord->subfield( '701', 'c' ) . " - "
181 if $marcrecord->subfield( '701', 'c' );
182 $subfield_value_a .= " ("
183 if $marcrecord->subfield( '701', 'f' )
184 and not( $marcrecord->subfield( '701', 'c' ) );
185 $subfield_value_a .= $marcrecord->subfield( '701', 'f' )
186 if $marcrecord->subfield( '701', 'f' );
187 $subfield_value_a .= ")"
188 if $marcrecord->subfield( '701', 'f' )
189 or $marcrecord->subfield( '701', 'c' );
191 elsif ( $marcrecord->field('712') ) {
192 $subfield_value_a = $marcrecord->subfield( '712', 'd' ) . " "
193 if $marcrecord->subfield( '712', 'd' );
194 $subfield_value_a .= $marcrecord->subfield( '712', 'a' )
195 if $marcrecord->subfield( '712', 'a' );
196 $subfield_value_a .= ", " . $marcrecord->subfield( '712', 'b' )
197 if $marcrecord->subfield( '712', 'b' );
199 " (" . $marcrecord->subfield( '712', 'f' ) . " - "
200 if $marcrecord->subfield( '712', 'f' );
201 $subfield_value_a .= " ("
202 if $marcrecord->subfield( '712', "e" )
203 and not $marcrecord->subfield( '712', 'f' );
204 $subfield_value_a .= $marcrecord->subfield( '712', 'e' )
205 if $marcrecord->subfield( '712', 'e' );
206 $subfield_value_a .= ")"
207 if $marcrecord->subfield( '712', 'e' )
208 or $marcrecord->subfield( '712', 'f' );
210 elsif ( $marcrecord->field('200') ) {
211 $subfield_value_a = $marcrecord->subfield( '200', 'f' );
213 my $subfield_value_c;
214 my $subfield_value_d;
215 my $subfield_value_e;
216 $subfield_value_c = $marcrecord->field('210')->subfield("a")
217 if ( $marcrecord->field('210') );
218 $subfield_value_d = $marcrecord->field('210')->subfield("d")
219 if ( $marcrecord->field('210') );
220 $subfield_value_e = $marcrecord->field('205')->subfield("a")
221 if ( $marcrecord->field('205') );
223 my $subfield_value_h;
224 if ( ( $marcrecord->field('200') )
225 && ( $marcrecord->field('200')->subfield("h") ) )
227 $subfield_value_h = $marcrecord->field('200')->subfield("h");
229 elsif (( $marcrecord->field('225') )
230 && ( $marcrecord->field('225')->subfield("h") ) )
232 $subfield_value_h = $marcrecord->field('225')->subfield("h");
234 elsif (( $marcrecord->field('500') )
235 && ( $marcrecord->field('500')->subfield("h") ) )
237 $subfield_value_h = $marcrecord->field('500')->subfield("h");
240 my $subfield_value_i;
241 if ( ( $marcrecord->field('200') )
242 && ( $marcrecord->field('200')->subfield("i") ) )
244 $subfield_value_i = $marcrecord->field('200')->subfield("i");
246 elsif (( $marcrecord->field('225') )
247 && ( $marcrecord->field('225')->subfield("i") ) )
249 $subfield_value_i = $marcrecord->field('225')->subfield("i");
251 elsif (( $marcrecord->field('500') )
252 && ( $marcrecord->field('500')->subfield("i") ) )
254 $subfield_value_i = $marcrecord->field('500')->subfield("i");
257 my $subfield_value_l;
258 $subfield_value_l = $marcrecord->field('200')->subfield("d")
259 if ( $marcrecord->field('200') );
261 my $subfield_value_n;
262 $subfield_value_n = $marcrecord->field('210')->subfield("c")
263 if ( $marcrecord->field('210') );
265 my $subfield_value_o;
266 $subfield_value_o = $marcrecord->field('200')->subfield("e")
267 if ( $marcrecord->field('200') );
269 my $subfield_value_p;
270 $subfield_value_p = $marcrecord->field('215')->subfield("a")
271 if ( $marcrecord->field('215') );
273 my $subfield_value_t;
274 if ( ( $marcrecord->field('200') )
275 && ( $marcrecord->field('200')->subfield("a") ) )
277 $subfield_value_t = $marcrecord->field('200')->subfield("a");
279 elsif (( $marcrecord->field('225') )
280 && ( $marcrecord->field('225')->subfield("a") ) )
282 $subfield_value_t = $marcrecord->field('225')->subfield("a");
284 elsif (( $marcrecord->field('500') )
285 && ( $marcrecord->field('500')->subfield("a") ) )
287 $subfield_value_t = $marcrecord->field('500')->subfield("a");
290 my $subfield_value_u;
291 if ( $marcrecord->field('856') ) {
292 $subfield_value_u = $marcrecord->field('856')->subfield("u");
295 my $subfield_value_v;
296 if ( ( $marcrecord->field('225') )
297 && ( $marcrecord->field('225')->subfield("v") ) )
299 $subfield_value_v = $marcrecord->field('225')->subfield("v");
301 elsif (( $marcrecord->field('200') )
302 && ( $marcrecord->field('200')->subfield("h") ) )
304 $subfield_value_v = $marcrecord->field('200')->subfield("h");
306 my $subfield_value_x;
308 $marcrecord->field('011')
309 and not( ( $marcrecord->field('011')->subfield("y") )
310 or ( $marcrecord->field('011')->subfield("z") ) ) ) {
311 $subfield_value_x = $marcrecord->field('011')->subfield("a");
313 my $subfield_value_y;
314 if ( $marcrecord->field('013') ) {
315 $subfield_value_y = $marcrecord->field('013')->subfield("a");
317 if ( $marcrecord->field('010') ) {
318 $subfield_value_y = $marcrecord->field('010')->subfield("a");
321 $subfield_value_9 =~ s/'/\\'/g;
322 $subfield_value_0 =~ s/'/\\'/g;
323 $subfield_value_a =~ s/'/\\'/g;
324 $subfield_value_c =~ s/'/\\'/g;
325 $subfield_value_d =~ s/'/\\'/g;
326 $subfield_value_e =~ s/'/\\'/g;
327 $subfield_value_h =~ s/'/\\'/g;
328 $subfield_value_i =~ s/'/\\'/g;
329 $subfield_value_l =~ s/'/\\'/g;
330 $subfield_value_n =~ s/'/\\'/g;
331 $subfield_value_o =~ s/'/\\'/g;
332 $subfield_value_p =~ s/'/\\'/g;
333 $subfield_value_t =~ s/'/\\'/g;
334 $subfield_value_u =~ s/'/\\'/g;
335 $subfield_value_v =~ s/'/\\'/g;
336 $subfield_value_x =~ s/'/\\'/g;
337 $subfield_value_y =~ s/'/\\'/g;
340 index => $query->param('index') . "",
341 biblionumber
=> $biblionumber ?
$biblionumber : "",
342 subfield_value_9
=> "$subfield_value_9",
343 subfield_value_0
=> "$subfield_value_0",
344 subfield_value_a
=> "$subfield_value_a",
345 subfield_value_c
=> "$subfield_value_c",
346 subfield_value_d
=> "$subfield_value_d",
347 subfield_value_e
=> "$subfield_value_e",
348 subfield_value_h
=> "$subfield_value_h",
349 subfield_value_i
=> "$subfield_value_i",
350 subfield_value_l
=> "$subfield_value_l",
351 subfield_value_n
=> "$subfield_value_n",
352 subfield_value_o
=> "$subfield_value_o",
353 subfield_value_p
=> "$subfield_value_p",
354 subfield_value_t
=> "$subfield_value_t",
355 subfield_value_u
=> "$subfield_value_u",
356 subfield_value_v
=> "$subfield_value_v",
357 subfield_value_x
=> "$subfield_value_x",
358 subfield_value_y
=> "$subfield_value_y",
360 ###############################################################
362 elsif ( $op eq "do_search" ) {
363 my $search = $query->param('search');
364 my $itype = $query->param('itype');
365 my $startfrom = $query->param('startfrom');
366 my $resultsperpage = $query->param('resultsperpage') || 20;
369 $QParser = C4
::Context
->queryparser if (C4
::Context
->preference('UseQueryParser'));
376 $search = 'kw:'.$search." $op mc-itemtype:".$itype if $itype;
377 my ( $errors, $results, $total_hits ) = SimpleSearch
($search, $startfrom * $resultsperpage, $resultsperpage );
378 if (defined $errors ) {
381 my $total = @
{$results};
383 # warn " biblio count : ".$total;
385 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
388 "cataloguing/value_builder/unimarc_field_4XX.tt",
391 authnotrequired
=> 0,
396 # multi page display gestion
398 my $displayprev = $startfrom;
400 if( ( $total_hits - ( ( $startfrom + 1 ) * ($resultsperpage) ) ) > 0 ) {
404 my @field_data = ($search);
407 $i < $resultsperpage ;
411 my $record = C4
::Search
::new_record_from_zebra
( 'biblioserver', $results->[$i] );
412 my $rechash = TransformMarcToKoha
( $dbh, $record );
415 if ( $rechash->{itemnumber
} ) {
418 while ( index( $rechash->{itemnumber
}, '|', $pos ) > 0 ) {
420 $pos = index( $rechash->{itemnumber
}, '|', $pos ) + 1;
422 $rechash->{totitem
} = $countitems;
423 my @holdingbranches = split /\|/, $rechash->{holdingbranch
};
424 my @itemcallnumbers = split /\|/, $rechash->{itemcallnumber
};
426 for ( my $i = 0 ; $i < @holdingbranches ; $i++ ) {
428 $holdingbranches[$i] . " ( " . $itemcallnumbers[$i] . " ) |";
431 $rechash->{CN
} = $CN;
432 push @arrayresults, $rechash;
435 # for(my $i = 0 ; $i <= $#marclist ; $i++)
437 # push @field_data, { term => "marclist", val=>$marclist[$i] };
438 # push @field_data, { term => "and_or", val=>$and_or[$i] };
439 # push @field_data, { term => "excluding", val=>$excluding[$i] };
440 # push @field_data, { term => "operator", val=>$operator[$i] };
441 # push @field_data, { term => "value", val=>$value[$i] };
446 if ( $total > $resultsperpage ) {
447 for ( my $i = 1 ; $i < $total / $resultsperpage + 1 ; $i++ ) {
450 ( $startfrom == ( $i - 1 ) ) && ( $highlight = 1 );
454 highlight
=> $highlight,
455 searchdata
=> \
@field_data,
456 startfrom
=> ( $i - 1 )
462 my $from = $startfrom * $resultsperpage + 1;
465 if ( $total_hits < $from + $resultsperpage ) {
468 $to = $from + $resultsperpage ;
471 'BiblioDefaultView' . C4
::Context
->preference('BiblioDefaultView');
472 # my $link="/cgi-bin/koha/cataloguing/value_builder/unimarc4XX.pl?op=do_search&q=$search_desc&resultsperpage=$resultsperpage&startfrom=$startfrom&search=$search";
473 # foreach my $sort (@sort_by){
474 # $link.="&sort_by=".$sort."&";
477 # pagination_bar => pagination_bar(
479 # getnbpages($hits, $results_per_page),
485 result
=> \
@arrayresults,
486 index => $query->param('index') . "",
487 startfrom
=> $startfrom,
488 displaynext
=> $displaynext,
489 displayprev
=> $displayprev,
490 resultsperpage
=> $resultsperpage,
492 startfromnext
=> $startfrom + 1,
493 startfromprev
=> $startfrom - 1,
494 searchdata
=> \
@field_data,
495 total
=> $total_hits,
498 numbers
=> \
@numbers,
506 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
509 "cataloguing/value_builder/unimarc_field_4XX.tt",
512 authnotrequired
=> 0,
516 my @itemtypes = C4
::ItemType
->all;
518 $template->param( #classlist => $classlist,
519 itypeloop
=> \
@itemtypes,
520 index => $query->param('index'),
524 output_html_with_http_headers
$query, $cookie, $template->output;