3 # Copyright 2000-2002 Katipo Communications
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.tmpl",
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', 'f' )
123 and not( $marcrecord->subfield( '700', 'c' ) ) );
124 $subfield_value_a .= $marcrecord->subfield( '700', 'f' )
125 if ( $marcrecord->subfield( '700', 'f' ) );
126 $subfield_value_a .= ")"
127 if ( $marcrecord->subfield( '701', 'f' )
128 or $marcrecord->subfield( '701', 'c' ) );
130 elsif ( $marcrecord->field('702') ) {
131 $subfield_value_a = $marcrecord->subfield( '702', 'a' );
132 $subfield_value_a .= ", " . $marcrecord->subfield( '702', 'b' )
133 if $marcrecord->subfield( '702', 'b' );
134 $subfield_value_a .= " " . $marcrecord->subfield( '702', 'd' )
135 if $marcrecord->subfield( '702', 'd' );
137 " (" . $marcrecord->subfield( '702', 'c' ) . "; "
138 if $marcrecord->subfield( '702', 'c' );
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->field( '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 = $marcrecord->field('210')->subfield("a")
208 if ( $marcrecord->field('210') );
209 my $subfield_value_d = $marcrecord->field('210')->subfield("d")
210 if ( $marcrecord->field('210') );
212 my $subfield_value_e = $marcrecord->field('205')->subfield("a")
213 if ( $marcrecord->field('205') );
215 my $subfield_value_h;
216 if ( ( $marcrecord->field('200') )
217 && ( $marcrecord->field('200')->subfield("h") ) )
219 $subfield_value_h = $marcrecord->field('200')->subfield("h");
221 elsif (( $marcrecord->field('225') )
222 && ( $marcrecord->field('225')->subfield("h") ) )
224 $subfield_value_h = $marcrecord->field('225')->subfield("h");
226 elsif (( $marcrecord->field('500') )
227 && ( $marcrecord->field('500')->subfield("h") ) )
229 $subfield_value_h = $marcrecord->field('500')->subfield("h");
232 my $subfield_value_i;
233 if ( ( $marcrecord->field('200') )
234 && ( $marcrecord->field('200')->subfield("i") ) )
236 $subfield_value_i = $marcrecord->field('200')->subfield("i");
238 elsif (( $marcrecord->field('225') )
239 && ( $marcrecord->field('225')->subfield("i") ) )
241 $subfield_value_i = $marcrecord->field('225')->subfield("i");
243 elsif (( $marcrecord->field('500') )
244 && ( $marcrecord->field('500')->subfield("i") ) )
246 $subfield_value_i = $marcrecord->field('500')->subfield("i");
249 my $subfield_value_p = $marcrecord->field('215')->subfield("a")
250 if ( $marcrecord->field('215') );
252 my $subfield_value_t;
253 if ( ( $marcrecord->field('200') )
254 && ( $marcrecord->field('200')->subfield("a") ) )
256 $subfield_value_t = $marcrecord->field('200')->subfield("a");
258 elsif (( $marcrecord->field('225') )
259 && ( $marcrecord->field('225')->subfield("a") ) )
261 $subfield_value_t = $marcrecord->field('225')->subfield("a");
263 elsif (( $marcrecord->field('500') )
264 && ( $marcrecord->field('500')->subfield("a") ) )
266 $subfield_value_t = $marcrecord->field('500')->subfield("a");
269 my $subfield_value_u = $marcrecord->field('856')->subfield("u")
270 if ( $marcrecord->field('856') );
272 my $subfield_value_v;
273 if ( ( $marcrecord->field('225') )
274 && ( $marcrecord->field('225')->subfield("v") ) )
276 $subfield_value_v = $marcrecord->field('225')->subfield("v");
278 elsif (( $marcrecord->field('200') )
279 && ( $marcrecord->field('200')->subfield("h") ) )
281 $subfield_value_v = $marcrecord->field('200')->subfield("h");
283 my $subfield_value_x = $marcrecord->field('011')->subfield("a")
285 $marcrecord->field('011')
286 and not( ( $marcrecord->field('011')->subfield("y") )
287 or ( $marcrecord->field('011')->subfield("z") ) )
289 my $subfield_value_y = $marcrecord->field('013')->subfield("a")
290 if ( $marcrecord->field('013') );
291 if ( $marcrecord->field('010') ) {
292 $subfield_value_y = $marcrecord->field('010')->subfield("a");
295 $subfield_value_9 =~ s/'/\\'/g;
296 $subfield_value_0 =~ s/'/\\'/g;
297 $subfield_value_a =~ s/'/\\'/g;
298 $subfield_value_c =~ s/'/\\'/g;
299 $subfield_value_d =~ s/'/\\'/g;
300 $subfield_value_e =~ s/'/\\'/g;
301 $subfield_value_h =~ s/'/\\'/g;
302 $subfield_value_i =~ s/'/\\'/g;
303 $subfield_value_p =~ s/'/\\'/g;
304 $subfield_value_t =~ s/'/\\'/g;
305 $subfield_value_u =~ s/'/\\'/g;
306 $subfield_value_v =~ s/'/\\'/g;
307 $subfield_value_x =~ s/'/\\'/g;
308 $subfield_value_y =~ s/'/\\'/g;
311 index => $query->param('index') . "",
312 biblionumber
=> $biblionumber ?
$biblionumber : "",
313 subfield_value_9
=> "$subfield_value_9",
314 subfield_value_0
=> "$subfield_value_0",
315 subfield_value_a
=> "$subfield_value_a",
316 subfield_value_c
=> "$subfield_value_c",
317 subfield_value_d
=> "$subfield_value_d",
318 subfield_value_e
=> "$subfield_value_e",
319 subfield_value_h
=> "$subfield_value_h",
320 subfield_value_i
=> "$subfield_value_i",
321 subfield_value_p
=> "$subfield_value_p",
322 subfield_value_t
=> "$subfield_value_t",
323 subfield_value_u
=> "$subfield_value_u",
324 subfield_value_v
=> "$subfield_value_v",
325 subfield_value_x
=> "$subfield_value_x",
326 subfield_value_y
=> "$subfield_value_y",
328 ###############################################################
330 elsif ( $op eq "do_search" ) {
331 my $search = $query->param('search');
332 my $itype = $query->param('itype');
333 my $startfrom = $query->param('startfrom');
334 my $resultsperpage = $query->param('resultsperpage') || 20;
336 $search = 'kw,wrdl='.$search.' and mc-itemtype='.$itype if $itype;
337 my ( $errors, $results, $total_hits ) = SimpleSearch
($search, $startfrom * $resultsperpage, $resultsperpage );
338 my $total = scalar(@
$results);
340 # warn " biblio count : ".$total;
342 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
345 "cataloguing/value_builder/unimarc_field_4XX.tmpl",
348 authnotrequired
=> 1,
353 # multi page display gestion
355 my $displayprev = $startfrom;
357 if( ( $total_hits - ( ( $startfrom + 1 ) * ($resultsperpage) ) ) > 0 ) {
361 my @field_data = ($search);
364 $i < $resultsperpage ;
368 my $record = MARC
::Record
::new_from_usmarc
( $results->[$i] );
369 my $rechash = TransformMarcToKoha
( $dbh, $record );
371 my $countitems = 1 if ( $rechash->{itemnumber
} );
372 while ( index( $rechash->{itemnumber
}, '|', $pos ) > 0 ) {
374 $pos = index( $rechash->{itemnumber
}, '|', $pos ) + 1;
376 $rechash->{totitem
} = $countitems;
377 my @holdingbranches = split /\|/, $rechash->{holdingbranch
};
378 my @itemcallnumbers = split /\|/, $rechash->{itemcallnumber
};
380 for ( my $i = 0 ; $i < @holdingbranches ; $i++ ) {
382 $holdingbranches[$i] . " ( " . $itemcallnumbers[$i] . " ) |";
385 $rechash->{CN
} = $CN;
386 push @arrayresults, $rechash;
389 # for(my $i = 0 ; $i <= $#marclist ; $i++)
391 # push @field_data, { term => "marclist", val=>$marclist[$i] };
392 # push @field_data, { term => "and_or", val=>$and_or[$i] };
393 # push @field_data, { term => "excluding", val=>$excluding[$i] };
394 # push @field_data, { term => "operator", val=>$operator[$i] };
395 # push @field_data, { term => "value", val=>$value[$i] };
400 if ( $total > $resultsperpage ) {
401 for ( my $i = 1 ; $i < $total / $resultsperpage + 1 ; $i++ ) {
404 ( $startfrom == ( $i - 1 ) ) && ( $highlight = 1 );
408 highlight
=> $highlight,
409 searchdata
=> \
@field_data,
410 startfrom
=> ( $i - 1 )
416 my $from = $startfrom * $resultsperpage + 1;
419 if ( $total_hits < $from + $resultsperpage ) {
422 $to = $from + $resultsperpage ;
425 'BiblioDefaultView' . C4
::Context
->preference('BiblioDefaultView');
426 # my $link="/cgi-bin/koha/cataloguing/value_builder/unimarc4XX.pl?op=do_search&q=$search_desc&resultsperpage=$resultsperpage&startfrom=$startfrom&search=$search";
427 # foreach my $sort (@sort_by){
428 # $link.="&sort_by=".$sort."&";
431 # pagination_bar => pagination_bar(
433 # getnbpages($hits, $results_per_page),
439 result
=> \
@arrayresults,
440 index => $query->param('index') . "",
441 startfrom
=> $startfrom,
442 displaynext
=> $displaynext,
443 displayprev
=> $displayprev,
444 resultsperpage
=> $resultsperpage,
446 startfromnext
=> $startfrom + 1,
447 startfromprev
=> $startfrom - 1,
448 searchdata
=> \
@field_data,
449 total
=> $total_hits,
452 numbers
=> \
@numbers,
460 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
463 "cataloguing/value_builder/unimarc_field_4XX.tmpl",
466 authnotrequired
=> 1,
472 "Select itemtype,description from itemtypes order by description");
478 while ( my ( $value, $lib ) = $sth->fetchrow_array ) {
479 push @itemtype, $value;
480 $itemtypes{$value} = $lib;
483 my $CGIitemtype = CGI
::scrolling_list
(
485 -values => \
@itemtype,
486 -labels
=> \
%itemtypes,
495 my $branches = GetBranches
;
496 push @select_branch, "";
497 $select_branches{''} = "";
498 foreach my $thisbranch ( keys %$branches ) {
499 push @select_branch, $branches->{$thisbranch}->{'branchcode'};
500 $select_branches{ $branches->{$thisbranch}->{'branchcode'} } =
501 $branches->{$thisbranch}->{'branchname'};
503 my $CGIbranch = CGI
::scrolling_list
(
505 -values => \
@select_branch,
506 -labels
=> \
%select_branches,
514 "select distinctrow left(publishercode,45) from biblioitems order by publishercode"
519 while ( my ($value) = $req->fetchrow ) {
520 push @select, $value;
522 my $CGIpublisher = CGI
::scrolling_list
(
530 # my $sth=$dbh->prepare("select description,itemtype from itemtypes order by description");
532 # while (my ($description,$itemtype) = $sth->fetchrow) {
533 # $classlist.="<option value=\"$itemtype\">$description</option>\n";
537 my @itemtypes = C4
::ItemType
->all;
539 $template->param( #classlist => $classlist,
540 CGIitemtype
=> $CGIitemtype,
541 CGIbranch
=> $CGIbranch,
542 CGIPublisher
=> $CGIpublisher,
543 itypeloop
=> \
@itemtypes,
544 index => $query->param('index'),
548 output_html_with_http_headers
$query, $cookie, $template->output;