3 # Converted to new plugin style (Bug 13437)
5 # Copyright Biblibre 2007 - CILEA 2011
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # Koha is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with Koha; if not, see <http://www.gnu.org/licenses>.
37 use Koha
::SearchEngine
;
38 use Koha
::SearchEngine
::Search
;
42 my $function_name = $params->{id
};
44 <script type='text/javascript'>
45 function Click$function_name(event) {
46 defaultvalue=document.getElementById(event.data.id).value;
47 window.open(\"/cgi-bin/koha/cataloguing/plugin_launcher.pl?plugin_name=marc21_linking_section.pl&index=\" + event.data.id + \"&result=\"+defaultvalue, 'tag_editor', 'width=900,height=700,toolbar=false,scrollbars=yes');
58 my $query = $params->{cgi
};
59 my $dbh = C4
::Context
->dbh;
60 my $op = $query->param('op');
61 # -- op could be equal to
65 my $type = $query->param('type');
66 my $startfrom = $query->param('startfrom');
67 $startfrom = 0 if ( !defined $startfrom );
68 my ( $template, $loggedinuser, $cookie );
71 if ( $op eq "fillinput" ) {
72 my $biblionumber = $query->param('biblionumber');
73 my $index = $query->param('index');
77 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
78 { template_name
=> "cataloguing/value_builder/marc21_linking_section.tt",
82 flagsrequired
=> { editcatalogue
=> '*' },
88 $marcrecord = GetMarcBiblio
({ biblionumber
=> $biblionumber });
90 my $subfield_value_9 = $biblionumber;
91 my $subfield_value_0 = $biblionumber;
93 #my $subfield_value_0;
94 #$subfield_value_0 = $marcrecord->field('001')->data
95 # if $marcrecord->field('001');
97 if ( $marcrecord->field('001') ) {
98 $subfield_value_w = $marcrecord->field('001')->data;
100 $subfield_value_w = $biblionumber;
103 my $subfield_value_a;
104 my $subfield_value_c;
105 my $subfield_value_d;
106 my $subfield_value_e;
108 my $subfield_value_h;
110 my $subfield_value_i;
112 my $subfield_value_p;
114 my $subfield_value_t;
115 if ( $marcrecord->field('245') ) {
116 $subfield_value_t = $marcrecord->title();
119 my $subfield_value_u;
120 my $subfield_value_v;
121 my $subfield_value_x;
122 my $subfield_value_y;
123 my $subfield_value_z;
125 $subfield_value_x = $marcrecord->field('022')->subfield("a")
126 if ( $marcrecord->field('022') );
127 $subfield_value_z = $marcrecord->field('020')->subfield("a")
128 if ( $marcrecord->field('020') );
131 $subfield_value_9 =~ s/'/\\'/g;
132 $subfield_value_0 =~ s/'/\\'/g;
133 $subfield_value_a =~ s/'/\\'/g;
134 $subfield_value_c =~ s/'/\\'/g;
135 $subfield_value_d =~ s/'/\\'/g;
136 $subfield_value_e =~ s/'/\\'/g;
137 $subfield_value_h =~ s/'/\\'/g;
138 $subfield_value_i =~ s/'/\\'/g;
139 $subfield_value_p =~ s/'/\\'/g;
140 $subfield_value_t =~ s/'/\\'/g;
141 $subfield_value_u =~ s/'/\\'/g;
142 $subfield_value_v =~ s/'/\\'/g;
143 $subfield_value_w =~ s/'/\\'/g;
144 $subfield_value_x =~ s/'/\\'/g;
145 $subfield_value_y =~ s/'/\\'/g;
146 $subfield_value_z =~ s/'/\\'/g;
149 index => scalar $query->param('index') . "",
150 biblionumber
=> $biblionumber ?
$biblionumber : "",
151 subfield_value_9
=> "$subfield_value_9",
152 subfield_value_0
=> "$subfield_value_0",
153 subfield_value_a
=> "$subfield_value_a",
154 subfield_value_c
=> "$subfield_value_c",
155 subfield_value_d
=> "$subfield_value_d",
156 subfield_value_e
=> "$subfield_value_e",
157 subfield_value_h
=> "$subfield_value_h",
158 subfield_value_i
=> "$subfield_value_i",
159 subfield_value_p
=> "$subfield_value_p",
160 subfield_value_t
=> "$subfield_value_t",
161 subfield_value_u
=> "$subfield_value_u",
162 subfield_value_v
=> "$subfield_value_v",
163 subfield_value_w
=> "$subfield_value_w",
164 subfield_value_x
=> "$subfield_value_x",
165 subfield_value_y
=> "$subfield_value_y",
166 subfield_value_z
=> "$subfield_value_z",
168 ###############################################################
169 } elsif ( $op eq "do_search" ) {
170 my $search = $query->param('search');
171 my $itype = $query->param('itype');
172 my $startfrom = $query->param('startfrom');
173 my $resultsperpage = $query->param('resultsperpage') || 20;
176 $QParser = C4
::Context
->queryparser if ( C4
::Context
->preference('UseQueryParser') );
184 my $searcher = Koha
::SearchEngine
::Search
->new(
185 { index => $Koha::SearchEngine
::BIBLIOS_INDEX
} );
186 $search = 'kw:' . $search . " $op mc-itemtype:" . $itype if $itype;
187 my ( $errors, $results, $total_hits ) =
188 $searcher->simple_search_compat( $search,
189 $startfrom * $resultsperpage,
191 if ( defined $errors ) {
194 my $total = @
{$results};
196 # warn " biblio count : ".$total;
198 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
199 { template_name
=> "cataloguing/value_builder/marc21_linking_section.tt",
202 authnotrequired
=> 0,
207 # multi page display gestion
209 my $displayprev = $startfrom;
211 if ( ( $total_hits - ( ( $startfrom + 1 ) * ($resultsperpage) ) ) > 0 ) {
215 my @field_data = ($search);
216 for ( my $i = 0 ; $i < $resultsperpage ; $i++ ) {
217 my $record = C4
::Search
::new_record_from_zebra
( 'biblioserver', $results->[$i] );
218 my $rechash = TransformMarcToKoha
( $record );
220 my $countitems = $rechash->{itembumber
} ?
1 : 0;
221 while ( index( $rechash->{itemnumber
}, '|', $pos ) > 0 ) {
223 $pos = index( $rechash->{itemnumber
}, '|', $pos ) + 1;
225 $rechash->{totitem
} = $countitems;
226 my @holdingbranches = split /\|/, $rechash->{holdingbranch
};
227 my @itemcallnumbers = split /\|/, $rechash->{itemcallnumber
};
229 for ( my $i = 0 ; $i < @holdingbranches ; $i++ ) {
230 $CN .= $holdingbranches[$i] . " ( " . $itemcallnumbers[$i] . " ) |";
233 $rechash->{CN
} = $CN;
234 push @arrayresults, $rechash;
237 # for(my $i = 0 ; $i <= $#marclist ; $i++)
239 # push @field_data, { term => "marclist", val=>$marclist[$i] };
240 # push @field_data, { term => "and_or", val=>$and_or[$i] };
241 # push @field_data, { term => "excluding", val=>$excluding[$i] };
242 # push @field_data, { term => "operator", val=>$operator[$i] };
243 # push @field_data, { term => "value", val=>$value[$i] };
248 if ( $total > $resultsperpage ) {
249 for ( my $i = 1 ; $i < $total / $resultsperpage + 1 ; $i++ ) {
252 ( $startfrom == ( $i - 1 ) ) && ( $highlight = 1 );
255 highlight
=> $highlight,
256 searchdata
=> \
@field_data,
257 startfrom
=> ( $i - 1 )
263 my $from = $startfrom * $resultsperpage + 1;
266 if ( $total_hits < $from + $resultsperpage ) {
269 $to = $from + $resultsperpage;
271 my $defaultview = 'BiblioDefaultView' . C4
::Context
->preference('BiblioDefaultView');
273 # my $link="/cgi-bin/koha/cataloguing/value_builder/unimarc4XX.pl?op=do_search&q=$search_desc&resultsperpage=$resultsperpage&startfrom=$startfrom&search=$search";
274 # foreach my $sort (@sort_by){
275 # $link.="&sort_by=".$sort."&";
278 # pagination_bar => pagination_bar(
280 # getnbpages($hits, $results_per_page),
286 result
=> \
@arrayresults,
287 index => scalar $query->param('index') . "",
288 startfrom
=> $startfrom,
289 displaynext
=> $displaynext,
290 displayprev
=> $displayprev,
291 resultsperpage
=> $resultsperpage,
293 startfromnext
=> $startfrom + 1,
294 startfromprev
=> $startfrom - 1,
295 searchdata
=> \
@field_data,
296 total
=> $total_hits,
299 numbers
=> \
@numbers,
306 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
307 { template_name
=> "cataloguing/value_builder/marc21_linking_section.tt",
310 authnotrequired
=> 0,
314 my @itemtypes = Koha
::ItemTypes
->search;
317 itypeloop
=> \
@itemtypes,
318 index => scalar $query->param('index'),
322 output_html_with_http_headers
$query, $cookie, $template->output;
325 return { builder
=> $builder, launcher
=> $launcher };