ug 7561: Fast cataloging - Allow add/edit items and delete record
[koha.git] / cataloguing / value_builder / unimarc_field_4XX.pl
blob3cacb51f5d71b9f548df4fa249b8b15c7643cd91
1 #!/usr/bin/perl
3 # Copyright Biblibre 2007
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 use strict;
22 #use warnings; FIXME - Bug 2505
24 use CGI qw ( -utf8 );
25 use C4::Output;
26 use C4::Context;
27 use C4::Search;
28 use C4::Auth;
29 use C4::Output;
31 use C4::Biblio;
32 use C4::Koha;
33 use MARC::Record;
34 use C4::Branch; # GetBranches
35 use C4::ItemType;
37 sub plugin_parameters {
38 my ( $dbh, $record, $tagslib, $i, $tabloop ) = @_;
39 return "";
42 sub plugin_javascript {
43 my ( $dbh, $record, $tagslib, $field_number, $tabloop ) = @_;
44 my $function_name = $field_number;
45 my $res = "
46 <script type='text/javascript'>
47 function Focus$function_name(subfield_managed) {
48 return 1;
51 function Blur$function_name(subfield_managed) {
52 return 1;
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');
60 </script>
63 return ( $function_name, $res );
66 # sub plugin
68 # input arg :
69 # -- op could be equals to
70 # * fillinput :
71 # * do_search :
74 sub plugin {
75 my ($input) = @_;
76 my $dbh = C4::Context->dbh;
77 my $query = new CGI;
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 );
83 my $resultsperpage;
84 my $searchdesc;
86 if ( $op eq "fillinput" ) {
87 my $biblionumber = $query->param('biblionumber');
88 my $index = $query->param('index');
89 my $marcrecord;
91 # open template
92 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
94 template_name =>
95 "cataloguing/value_builder/unimarc_field_4XX.tt",
96 query => $query,
97 type => "intranet",
98 authnotrequired => 0,
99 flagsrequired => { editcatalogue => '*' },
100 debug => 1,
104 #get marc record
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' );
118 $subfield_value_a .=
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' );
139 $subfield_value_a .=
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');
161 $subfield_value_a .=
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' );
179 $subfield_value_a .=
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' );
198 $subfield_value_a .=
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_p;
258 $subfield_value_p = $marcrecord->field('215')->subfield("a")
259 if ( $marcrecord->field('215') );
261 my $subfield_value_t;
262 if ( ( $marcrecord->field('200') )
263 && ( $marcrecord->field('200')->subfield("a") ) )
265 $subfield_value_t = $marcrecord->field('200')->subfield("a");
267 elsif (( $marcrecord->field('225') )
268 && ( $marcrecord->field('225')->subfield("a") ) )
270 $subfield_value_t = $marcrecord->field('225')->subfield("a");
272 elsif (( $marcrecord->field('500') )
273 && ( $marcrecord->field('500')->subfield("a") ) )
275 $subfield_value_t = $marcrecord->field('500')->subfield("a");
278 my $subfield_value_u;
279 if ( $marcrecord->field('856') ) {
280 $subfield_value_u = $marcrecord->field('856')->subfield("u");
283 my $subfield_value_v;
284 if ( ( $marcrecord->field('225') )
285 && ( $marcrecord->field('225')->subfield("v") ) )
287 $subfield_value_v = $marcrecord->field('225')->subfield("v");
289 elsif (( $marcrecord->field('200') )
290 && ( $marcrecord->field('200')->subfield("h") ) )
292 $subfield_value_v = $marcrecord->field('200')->subfield("h");
294 my $subfield_value_x;
295 if (
296 $marcrecord->field('011')
297 and not( ( $marcrecord->field('011')->subfield("y") )
298 or ( $marcrecord->field('011')->subfield("z") ) ) ) {
299 $subfield_value_x = $marcrecord->field('011')->subfield("a");
301 my $subfield_value_y;
302 if ( $marcrecord->field('013') ) {
303 $subfield_value_y = $marcrecord->field('013')->subfield("a");
305 if ( $marcrecord->field('010') ) {
306 $subfield_value_y = $marcrecord->field('010')->subfield("a");
308 # escape the 's
309 $subfield_value_9 =~ s/'/\\'/g;
310 $subfield_value_0 =~ s/'/\\'/g;
311 $subfield_value_a =~ s/'/\\'/g;
312 $subfield_value_c =~ s/'/\\'/g;
313 $subfield_value_d =~ s/'/\\'/g;
314 $subfield_value_e =~ s/'/\\'/g;
315 $subfield_value_h =~ s/'/\\'/g;
316 $subfield_value_i =~ s/'/\\'/g;
317 $subfield_value_p =~ s/'/\\'/g;
318 $subfield_value_t =~ s/'/\\'/g;
319 $subfield_value_u =~ s/'/\\'/g;
320 $subfield_value_v =~ s/'/\\'/g;
321 $subfield_value_x =~ s/'/\\'/g;
322 $subfield_value_y =~ s/'/\\'/g;
323 $template->param(
324 fillinput => 1,
325 index => $query->param('index') . "",
326 biblionumber => $biblionumber ? $biblionumber : "",
327 subfield_value_9 => "$subfield_value_9",
328 subfield_value_0 => "$subfield_value_0",
329 subfield_value_a => "$subfield_value_a",
330 subfield_value_c => "$subfield_value_c",
331 subfield_value_d => "$subfield_value_d",
332 subfield_value_e => "$subfield_value_e",
333 subfield_value_h => "$subfield_value_h",
334 subfield_value_i => "$subfield_value_i",
335 subfield_value_p => "$subfield_value_p",
336 subfield_value_t => "$subfield_value_t",
337 subfield_value_u => "$subfield_value_u",
338 subfield_value_v => "$subfield_value_v",
339 subfield_value_x => "$subfield_value_x",
340 subfield_value_y => "$subfield_value_y",
342 ###############################################################
344 elsif ( $op eq "do_search" ) {
345 my $search = $query->param('search');
346 my $itype = $query->param('itype');
347 my $startfrom = $query->param('startfrom');
348 my $resultsperpage = $query->param('resultsperpage') || 20;
349 my $orderby;
350 my $QParser;
351 $QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser'));
352 my $op;
353 if ($QParser) {
354 $op = '&&';
355 } else {
356 $op = 'and';
358 $search = 'kw:'.$search." $op mc-itemtype:".$itype if $itype;
359 my ( $errors, $results, $total_hits ) = SimpleSearch($search, $startfrom * $resultsperpage, $resultsperpage );
360 if (defined $errors ) {
361 $results = [];
363 my $total = @{$results};
365 # warn " biblio count : ".$total;
367 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
369 template_name =>
370 "cataloguing/value_builder/unimarc_field_4XX.tt",
371 query => $query,
372 type => 'intranet',
373 authnotrequired => 0,
374 debug => 1,
378 # multi page display gestion
379 my $displaynext = 0;
380 my $displayprev = $startfrom;
382 if( ( $total_hits - ( ( $startfrom + 1 ) * ($resultsperpage) ) ) > 0 ) {
383 $displaynext = 1;
385 my @arrayresults;
386 my @field_data = ($search);
387 for (
388 my $i = 0 ;
389 $i < $resultsperpage ;
390 $i++
393 my $record = C4::Search::new_record_from_zebra( 'biblioserver', $results->[$i] );
394 my $rechash = TransformMarcToKoha( $dbh, $record );
395 my $pos;
396 my $countitems;
397 if ( $rechash->{itemnumber} ) {
398 $countitems=1;
400 while ( index( $rechash->{itemnumber}, '|', $pos ) > 0 ) {
401 $countitems += 1;
402 $pos = index( $rechash->{itemnumber}, '|', $pos ) + 1;
404 $rechash->{totitem} = $countitems;
405 my @holdingbranches = split /\|/, $rechash->{holdingbranch};
406 my @itemcallnumbers = split /\|/, $rechash->{itemcallnumber};
407 my $CN;
408 for ( my $i = 0 ; $i < @holdingbranches ; $i++ ) {
409 $CN .=
410 $holdingbranches[$i] . " ( " . $itemcallnumbers[$i] . " ) |";
412 $CN =~ s/ \|$//;
413 $rechash->{CN} = $CN;
414 push @arrayresults, $rechash;
417 # for(my $i = 0 ; $i <= $#marclist ; $i++)
419 # push @field_data, { term => "marclist", val=>$marclist[$i] };
420 # push @field_data, { term => "and_or", val=>$and_or[$i] };
421 # push @field_data, { term => "excluding", val=>$excluding[$i] };
422 # push @field_data, { term => "operator", val=>$operator[$i] };
423 # push @field_data, { term => "value", val=>$value[$i] };
426 my @numbers = ();
428 if ( $total > $resultsperpage ) {
429 for ( my $i = 1 ; $i < $total / $resultsperpage + 1 ; $i++ ) {
430 if ( $i < 16 ) {
431 my $highlight = 0;
432 ( $startfrom == ( $i - 1 ) ) && ( $highlight = 1 );
433 push @numbers,
435 number => $i,
436 highlight => $highlight,
437 searchdata => \@field_data,
438 startfrom => ( $i - 1 )
444 my $from = $startfrom * $resultsperpage + 1;
445 my $to;
447 if ( $total_hits < $from + $resultsperpage ) {
448 $to = $total_hits;
449 }else{
450 $to = $from + $resultsperpage ;
452 my $defaultview =
453 'BiblioDefaultView' . C4::Context->preference('BiblioDefaultView');
454 # my $link="/cgi-bin/koha/cataloguing/value_builder/unimarc4XX.pl?op=do_search&q=$search_desc&resultsperpage=$resultsperpage&startfrom=$startfrom&search=$search";
455 # foreach my $sort (@sort_by){
456 # $link.="&sort_by=".$sort."&";
458 # $template->param(
459 # pagination_bar => pagination_bar(
460 # $link,
461 # getnbpages($hits, $results_per_page),
462 # $page,
463 # 'page'
464 # ),
465 # );
466 $template->param(
467 result => \@arrayresults,
468 index => $query->param('index') . "",
469 startfrom => $startfrom,
470 displaynext => $displaynext,
471 displayprev => $displayprev,
472 resultsperpage => $resultsperpage,
473 orderby => $orderby,
474 startfromnext => $startfrom + 1,
475 startfromprev => $startfrom - 1,
476 searchdata => \@field_data,
477 total => $total_hits,
478 from => $from,
479 to => $to,
480 numbers => \@numbers,
481 search => $search,
482 $defaultview => 1,
483 Search => 0
487 else {
488 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
490 template_name =>
491 "cataloguing/value_builder/unimarc_field_4XX.tt",
492 query => $query,
493 type => "intranet",
494 authnotrequired => 0,
498 my @itemtypes = C4::ItemType->all;
500 $template->param( #classlist => $classlist,
501 itypeloop => \@itemtypes,
502 index => $query->param('index'),
503 Search => 1,
506 output_html_with_http_headers $query, $cookie, $template->output;