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_javascript {
38 my ( $dbh, $record, $tagslib, $field_number, $tabloop ) = @_;
39 my $function_name = $field_number;
41 <script type='text/javascript'>
42 function Clic$function_name(i) {
43 defaultvalue=document.getElementById(\"$field_number\").value;
44 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');
50 return ( $function_name, $res );
56 # -- op could be equals to
63 my $dbh = C4::Context->dbh;
65 my $op = $query->param('op');
66 my $type = $query->param('type');
67 my $startfrom = $query->param('startfrom');
68 $startfrom = 0 if ( !defined $startfrom );
69 my ( $template, $loggedinuser, $cookie );
73 if ( $op eq "fillinput" ) {
74 my $biblionumber = $query->param('biblionumber');
75 my $index = $query->param('index');
79 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
82 "cataloguing/value_builder/unimarc_field_4XX.tt",
86 flagsrequired => { editcatalogue => '*' },
92 $marcrecord = GetMarcBiblio($biblionumber);
94 my $subfield_value_9 = $biblionumber;
96 $subfield_value_0 = $marcrecord->field('001')->data
97 if $marcrecord->field('001');
99 if ( $marcrecord->field('700') ) {
100 $subfield_value_a = $marcrecord->field('700')->subfield("a");
101 $subfield_value_a .= ", " . $marcrecord->subfield( '700', "b" )
102 if $marcrecord->subfield( '700', 'b' );
103 $subfield_value_a .= " " . $marcrecord->subfield( '700', "d" )
104 if $marcrecord->subfield( '700', 'd' );
106 " (" . $marcrecord->subfield( '700', 'c' )
107 if $marcrecord->subfield( '700', 'c' );
108 $subfield_value_a .= " ; "
109 if $marcrecord->subfield( '700', 'c' )
110 and $marcrecord->subfield( '700', 'f' );
111 $subfield_value_a .= " ("
112 if ( $marcrecord->subfield( '700', 'f' )
113 and not( $marcrecord->subfield( '700', 'c' ) ) );
114 $subfield_value_a .= $marcrecord->subfield( '700', 'f' )
115 if ( $marcrecord->subfield( '700', 'f' ) );
116 $subfield_value_a .= ")"
117 if ( $marcrecord->subfield( '700', 'f' )
118 or $marcrecord->subfield( '700', 'c' ) );
120 elsif ( $marcrecord->field('702') ) {
121 $subfield_value_a = $marcrecord->subfield( '702', 'a' );
122 $subfield_value_a .= ", " . $marcrecord->subfield( '702', 'b' )
123 if $marcrecord->subfield( '702', 'b' );
124 $subfield_value_a .= " " . $marcrecord->subfield( '702', 'd' )
125 if $marcrecord->subfield( '702', 'd' );
127 " (" . $marcrecord->subfield( '702', 'c' )
128 if $marcrecord->subfield( '702', 'c' );
129 $subfield_value_a .= " ; "
130 if $marcrecord->subfield( '702', 'c' )
131 and $marcrecord->subfield( '702', 'f' );
132 $subfield_value_a .= " ("
133 if $marcrecord->subfield( '702', 'f' )
134 and not $marcrecord->subfield( '702', 'c' );
135 $subfield_value_a .= $marcrecord->subfield( '702', 'f' )
136 if $marcrecord->subfield( '702', 'f' );
137 $subfield_value_a .= ")"
138 if $marcrecord->subfield( '702', 'f' )
139 or $marcrecord->subfield( '702', 'c' );
141 elsif ( $marcrecord->field('710') ) {
142 $subfield_value_a = $marcrecord->subfield( '710', 'd' ) . " "
143 if $marcrecord->subfield( '710', 'd' );
144 $subfield_value_a .= $marcrecord->subfield( '710', 'a' )
145 if $marcrecord->subfield( '710', 'a' );
146 $subfield_value_a .= ", " . $marcrecord->subfield( '710', 'b' )
147 if $marcrecord->subfield('710');
149 " (" . $marcrecord->subfield( '710', 'f' ) . " - "
150 if $marcrecord->subfield( '710', 'f' );
151 $subfield_value_a .= " ("
152 if $marcrecord->subfield( '710', 'e' )
153 and not $marcrecord->subfield( '710', 'f' );
154 $subfield_value_a .= $marcrecord->subfield( '710', 'e' )
155 if $marcrecord->subfield( '710', 'e' );
156 $subfield_value_a .= ")"
157 if $marcrecord->subfield( '710', 'e' )
158 or $marcrecord->subfield( '710', 'f' );
160 elsif ( $marcrecord->field('701') ) {
161 $subfield_value_a = $marcrecord->subfield( '701', 'a' );
162 $subfield_value_a .= ", " . $marcrecord->subfield( '701', 'b' )
163 if $marcrecord->subfield( '701', 'b' );
164 $subfield_value_a .= " " . $marcrecord->subfield( '701', 'd', )
165 if $marcrecord->subfield( '701', 'd' );
167 " (" . $marcrecord->subfield( '701', 'c' ) . " - "
168 if $marcrecord->subfield( '701', 'c' );
169 $subfield_value_a .= " ("
170 if $marcrecord->subfield( '701', 'f' )
171 and not( $marcrecord->subfield( '701', 'c' ) );
172 $subfield_value_a .= $marcrecord->subfield( '701', 'f' )
173 if $marcrecord->subfield( '701', 'f' );
174 $subfield_value_a .= ")"
175 if $marcrecord->subfield( '701', 'f' )
176 or $marcrecord->subfield( '701', 'c' );
178 elsif ( $marcrecord->field('712') ) {
179 $subfield_value_a = $marcrecord->subfield( '712', 'd' ) . " "
180 if $marcrecord->subfield( '712', 'd' );
181 $subfield_value_a .= $marcrecord->subfield( '712', 'a' )
182 if $marcrecord->subfield( '712', 'a' );
183 $subfield_value_a .= ", " . $marcrecord->subfield( '712', 'b' )
184 if $marcrecord->subfield( '712', 'b' );
186 " (" . $marcrecord->subfield( '712', 'f' ) . " - "
187 if $marcrecord->subfield( '712', 'f' );
188 $subfield_value_a .= " ("
189 if $marcrecord->subfield( '712', "e" )
190 and not $marcrecord->subfield( '712', 'f' );
191 $subfield_value_a .= $marcrecord->subfield( '712', 'e' )
192 if $marcrecord->subfield( '712', 'e' );
193 $subfield_value_a .= ")"
194 if $marcrecord->subfield( '712', 'e' )
195 or $marcrecord->subfield( '712', 'f' );
197 elsif ( $marcrecord->field('200') ) {
198 $subfield_value_a = $marcrecord->subfield( '200', 'f' );
200 my $subfield_value_c;
201 my $subfield_value_d;
202 my $subfield_value_e;
203 $subfield_value_c = $marcrecord->field('210')->subfield("a")
204 if ( $marcrecord->field('210') );
205 $subfield_value_d = $marcrecord->field('210')->subfield("d")
206 if ( $marcrecord->field('210') );
207 $subfield_value_e = $marcrecord->field('205')->subfield("a")
208 if ( $marcrecord->field('205') );
210 my $subfield_value_h;
211 if ( ( $marcrecord->field('200') )
212 && ( $marcrecord->field('200')->subfield("h") ) )
214 $subfield_value_h = $marcrecord->field('200')->subfield("h");
216 elsif (( $marcrecord->field('225') )
217 && ( $marcrecord->field('225')->subfield("h") ) )
219 $subfield_value_h = $marcrecord->field('225')->subfield("h");
221 elsif (( $marcrecord->field('500') )
222 && ( $marcrecord->field('500')->subfield("h") ) )
224 $subfield_value_h = $marcrecord->field('500')->subfield("h");
227 my $subfield_value_i;
228 if ( ( $marcrecord->field('200') )
229 && ( $marcrecord->field('200')->subfield("i") ) )
231 $subfield_value_i = $marcrecord->field('200')->subfield("i");
233 elsif (( $marcrecord->field('225') )
234 && ( $marcrecord->field('225')->subfield("i") ) )
236 $subfield_value_i = $marcrecord->field('225')->subfield("i");
238 elsif (( $marcrecord->field('500') )
239 && ( $marcrecord->field('500')->subfield("i") ) )
241 $subfield_value_i = $marcrecord->field('500')->subfield("i");
244 my $subfield_value_p;
245 $subfield_value_p = $marcrecord->field('215')->subfield("a")
246 if ( $marcrecord->field('215') );
248 my $subfield_value_t;
249 if ( ( $marcrecord->field('200') )
250 && ( $marcrecord->field('200')->subfield("a") ) )
252 $subfield_value_t = $marcrecord->field('200')->subfield("a");
254 elsif (( $marcrecord->field('225') )
255 && ( $marcrecord->field('225')->subfield("a") ) )
257 $subfield_value_t = $marcrecord->field('225')->subfield("a");
259 elsif (( $marcrecord->field('500') )
260 && ( $marcrecord->field('500')->subfield("a") ) )
262 $subfield_value_t = $marcrecord->field('500')->subfield("a");
265 my $subfield_value_u;
266 if ( $marcrecord->field('856') ) {
267 $subfield_value_u = $marcrecord->field('856')->subfield("u");
270 my $subfield_value_v;
271 if ( ( $marcrecord->field('225') )
272 && ( $marcrecord->field('225')->subfield("v") ) )
274 $subfield_value_v = $marcrecord->field('225')->subfield("v");
276 elsif (( $marcrecord->field('200') )
277 && ( $marcrecord->field('200')->subfield("h") ) )
279 $subfield_value_v = $marcrecord->field('200')->subfield("h");
281 my $subfield_value_x;
283 $marcrecord->field('011')
284 and not( ( $marcrecord->field('011')->subfield("y") )
285 or ( $marcrecord->field('011')->subfield("z") ) ) ) {
286 $subfield_value_x = $marcrecord->field('011')->subfield("a");
288 my $subfield_value_y;
289 if ( $marcrecord->field('013') ) {
290 $subfield_value_y = $marcrecord->field('013')->subfield("a");
292 if ( $marcrecord->field('010') ) {
293 $subfield_value_y = $marcrecord->field('010')->subfield("a");
296 $subfield_value_9 =~ s/'/\\'/g;
297 $subfield_value_0 =~ s/'/\\'/g;
298 $subfield_value_a =~ s/'/\\'/g;
299 $subfield_value_c =~ s/'/\\'/g;
300 $subfield_value_d =~ s/'/\\'/g;
301 $subfield_value_e =~ s/'/\\'/g;
302 $subfield_value_h =~ s/'/\\'/g;
303 $subfield_value_i =~ s/'/\\'/g;
304 $subfield_value_p =~ s/'/\\'/g;
305 $subfield_value_t =~ s/'/\\'/g;
306 $subfield_value_u =~ s/'/\\'/g;
307 $subfield_value_v =~ s/'/\\'/g;
308 $subfield_value_x =~ s/'/\\'/g;
309 $subfield_value_y =~ s/'/\\'/g;
312 index => $query->param('index') . "",
313 biblionumber => $biblionumber ? $biblionumber : "",
314 subfield_value_9 => "$subfield_value_9",
315 subfield_value_0 => "$subfield_value_0",
316 subfield_value_a => "$subfield_value_a",
317 subfield_value_c => "$subfield_value_c",
318 subfield_value_d => "$subfield_value_d",
319 subfield_value_e => "$subfield_value_e",
320 subfield_value_h => "$subfield_value_h",
321 subfield_value_i => "$subfield_value_i",
322 subfield_value_p => "$subfield_value_p",
323 subfield_value_t => "$subfield_value_t",
324 subfield_value_u => "$subfield_value_u",
325 subfield_value_v => "$subfield_value_v",
326 subfield_value_x => "$subfield_value_x",
327 subfield_value_y => "$subfield_value_y",
329 ###############################################################
331 elsif ( $op eq "do_search" ) {
332 my $search = $query->param('search');
333 my $itype = $query->param('itype');
334 my $startfrom = $query->param('startfrom');
335 my $resultsperpage = $query->param('resultsperpage') || 20;
338 $QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser'));
345 $search = 'kw:'.$search." $op mc-itemtype:".$itype if $itype;
346 my ( $errors, $results, $total_hits ) = SimpleSearch($search, $startfrom * $resultsperpage, $resultsperpage );
347 if (defined $errors ) {
350 my $total = @{$results};
352 # warn " biblio count : ".$total;
354 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
357 "cataloguing/value_builder/unimarc_field_4XX.tt",
360 authnotrequired => 0,
365 # multi page display gestion
367 my $displayprev = $startfrom;
369 if( ( $total_hits - ( ( $startfrom + 1 ) * ($resultsperpage) ) ) > 0 ) {
373 my @field_data = ($search);
376 $i < $resultsperpage ;
380 my $record = C4::Search::new_record_from_zebra( 'biblioserver', $results->[$i] );
381 my $rechash = TransformMarcToKoha( $dbh, $record );
384 if ( $rechash->{itemnumber} ) {
387 while ( index( $rechash->{itemnumber}, '|', $pos ) > 0 ) {
389 $pos = index( $rechash->{itemnumber}, '|', $pos ) + 1;
391 $rechash->{totitem} = $countitems;
392 my @holdingbranches = split /\|/, $rechash->{holdingbranch};
393 my @itemcallnumbers = split /\|/, $rechash->{itemcallnumber};
395 for ( my $i = 0 ; $i < @holdingbranches ; $i++ ) {
397 $holdingbranches[$i] . " ( " . $itemcallnumbers[$i] . " ) |";
400 $rechash->{CN} = $CN;
401 push @arrayresults, $rechash;
404 # for(my $i = 0 ; $i <= $#marclist ; $i++)
406 # push @field_data, { term => "marclist", val=>$marclist[$i] };
407 # push @field_data, { term => "and_or", val=>$and_or[$i] };
408 # push @field_data, { term => "excluding", val=>$excluding[$i] };
409 # push @field_data, { term => "operator", val=>$operator[$i] };
410 # push @field_data, { term => "value", val=>$value[$i] };
415 if ( $total > $resultsperpage ) {
416 for ( my $i = 1 ; $i < $total / $resultsperpage + 1 ; $i++ ) {
419 ( $startfrom == ( $i - 1 ) ) && ( $highlight = 1 );
423 highlight => $highlight,
424 searchdata => \@field_data,
425 startfrom => ( $i - 1 )
431 my $from = $startfrom * $resultsperpage + 1;
434 if ( $total_hits < $from + $resultsperpage ) {
437 $to = $from + $resultsperpage ;
440 'BiblioDefaultView' . C4::Context->preference('BiblioDefaultView');
441 # my $link="/cgi-bin/koha/cataloguing/value_builder/unimarc4XX.pl?op=do_search&q=$search_desc&resultsperpage=$resultsperpage&startfrom=$startfrom&search=$search";
442 # foreach my $sort (@sort_by){
443 # $link.="&sort_by=".$sort."&";
446 # pagination_bar => pagination_bar(
448 # getnbpages($hits, $results_per_page),
454 result => \@arrayresults,
455 index => $query->param('index') . "",
456 startfrom => $startfrom,
457 displaynext => $displaynext,
458 displayprev => $displayprev,
459 resultsperpage => $resultsperpage,
461 startfromnext => $startfrom + 1,
462 startfromprev => $startfrom - 1,
463 searchdata => \@field_data,
464 total => $total_hits,
467 numbers => \@numbers,
475 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
478 "cataloguing/value_builder/unimarc_field_4XX.tt",
481 authnotrequired => 0,
485 my @itemtypes = C4::ItemType->all;
487 $template->param( #classlist => $classlist,
488 itypeloop => \@itemtypes,
489 index => $query->param('index'),
493 output_html_with_http_headers $query, $cookie, $template->output;