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
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.
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_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;
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");
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;
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;
351 $QParser = C4
::Context
->queryparser if (C4
::Context
->preference('UseQueryParser'));
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 ) {
363 my $total = @
{$results};
365 # warn " biblio count : ".$total;
367 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
370 "cataloguing/value_builder/unimarc_field_4XX.tt",
373 authnotrequired
=> 0,
378 # multi page display gestion
380 my $displayprev = $startfrom;
382 if( ( $total_hits - ( ( $startfrom + 1 ) * ($resultsperpage) ) ) > 0 ) {
386 my @field_data = ($search);
389 $i < $resultsperpage ;
393 my $record = C4
::Search
::new_record_from_zebra
( 'biblioserver', $results->[$i] );
394 my $rechash = TransformMarcToKoha
( $dbh, $record );
397 if ( $rechash->{itemnumber
} ) {
400 while ( index( $rechash->{itemnumber
}, '|', $pos ) > 0 ) {
402 $pos = index( $rechash->{itemnumber
}, '|', $pos ) + 1;
404 $rechash->{totitem
} = $countitems;
405 my @holdingbranches = split /\|/, $rechash->{holdingbranch
};
406 my @itemcallnumbers = split /\|/, $rechash->{itemcallnumber
};
408 for ( my $i = 0 ; $i < @holdingbranches ; $i++ ) {
410 $holdingbranches[$i] . " ( " . $itemcallnumbers[$i] . " ) |";
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] };
428 if ( $total > $resultsperpage ) {
429 for ( my $i = 1 ; $i < $total / $resultsperpage + 1 ; $i++ ) {
432 ( $startfrom == ( $i - 1 ) ) && ( $highlight = 1 );
436 highlight
=> $highlight,
437 searchdata
=> \
@field_data,
438 startfrom
=> ( $i - 1 )
444 my $from = $startfrom * $resultsperpage + 1;
447 if ( $total_hits < $from + $resultsperpage ) {
450 $to = $from + $resultsperpage ;
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."&";
459 # pagination_bar => pagination_bar(
461 # getnbpages($hits, $results_per_page),
467 result
=> \
@arrayresults,
468 index => $query->param('index') . "",
469 startfrom
=> $startfrom,
470 displaynext
=> $displaynext,
471 displayprev
=> $displayprev,
472 resultsperpage
=> $resultsperpage,
474 startfromnext
=> $startfrom + 1,
475 startfromprev
=> $startfrom - 1,
476 searchdata
=> \
@field_data,
477 total
=> $total_hits,
480 numbers
=> \
@numbers,
488 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
491 "cataloguing/value_builder/unimarc_field_4XX.tt",
494 authnotrequired
=> 0,
498 my @itemtypes = C4
::ItemType
->all;
500 $template->param( #classlist => $classlist,
501 itypeloop
=> \
@itemtypes,
502 index => $query->param('index'),
506 output_html_with_http_headers
$query, $cookie, $template->output;