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",
81 flagsrequired => { editcatalogue => '*' },
87 $marcrecord = GetMarcBiblio({ biblionumber => $biblionumber });
89 my $subfield_value_9 = $biblionumber;
90 my $subfield_value_0 = $biblionumber;
92 #my $subfield_value_0;
93 #$subfield_value_0 = $marcrecord->field('001')->data
94 # if $marcrecord->field('001');
96 if ( $marcrecord->field('001') ) {
97 $subfield_value_w = $marcrecord->field('001')->data;
99 $subfield_value_w = $biblionumber;
102 my $subfield_value_a;
103 my $subfield_value_c;
104 my $subfield_value_d;
105 my $subfield_value_e;
107 my $subfield_value_h;
109 my $subfield_value_i;
111 my $subfield_value_p;
113 my $subfield_value_t;
114 if ( $marcrecord->field('245') ) {
115 $subfield_value_t = $marcrecord->title();
118 my $subfield_value_u;
119 my $subfield_value_v;
120 my $subfield_value_x;
121 my $subfield_value_y;
122 my $subfield_value_z;
124 $subfield_value_x = $marcrecord->field('022')->subfield("a")
125 if ( $marcrecord->field('022') );
126 $subfield_value_z = $marcrecord->field('020')->subfield("a")
127 if ( $marcrecord->field('020') );
130 $subfield_value_9 =~ s/'/\\'/g;
131 $subfield_value_0 =~ s/'/\\'/g;
132 $subfield_value_a =~ s/'/\\'/g;
133 $subfield_value_c =~ s/'/\\'/g;
134 $subfield_value_d =~ s/'/\\'/g;
135 $subfield_value_e =~ s/'/\\'/g;
136 $subfield_value_h =~ s/'/\\'/g;
137 $subfield_value_i =~ s/'/\\'/g;
138 $subfield_value_p =~ s/'/\\'/g;
139 $subfield_value_t =~ s/'/\\'/g;
140 $subfield_value_u =~ s/'/\\'/g;
141 $subfield_value_v =~ s/'/\\'/g;
142 $subfield_value_w =~ s/'/\\'/g;
143 $subfield_value_x =~ s/'/\\'/g;
144 $subfield_value_y =~ s/'/\\'/g;
145 $subfield_value_z =~ s/'/\\'/g;
148 index => scalar $query->param('index') . "",
149 biblionumber => $biblionumber ? $biblionumber : "",
150 subfield_value_9 => "$subfield_value_9",
151 subfield_value_0 => "$subfield_value_0",
152 subfield_value_a => "$subfield_value_a",
153 subfield_value_c => "$subfield_value_c",
154 subfield_value_d => "$subfield_value_d",
155 subfield_value_e => "$subfield_value_e",
156 subfield_value_h => "$subfield_value_h",
157 subfield_value_i => "$subfield_value_i",
158 subfield_value_p => "$subfield_value_p",
159 subfield_value_t => "$subfield_value_t",
160 subfield_value_u => "$subfield_value_u",
161 subfield_value_v => "$subfield_value_v",
162 subfield_value_w => "$subfield_value_w",
163 subfield_value_x => "$subfield_value_x",
164 subfield_value_y => "$subfield_value_y",
165 subfield_value_z => "$subfield_value_z",
167 ###############################################################
168 } elsif ( $op eq "do_search" ) {
169 my $search = $query->param('search');
170 my $itype = $query->param('itype');
171 my $startfrom = $query->param('startfrom');
172 my $resultsperpage = $query->param('resultsperpage') || 20;
176 my $searcher = Koha::SearchEngine::Search->new(
177 { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
178 $search = 'kw:' . $search . " $op mc-itemtype:" . $itype if $itype;
179 my ( $errors, $results, $total_hits ) =
180 $searcher->simple_search_compat( $search,
181 $startfrom * $resultsperpage,
183 if ( defined $errors ) {
186 my $total = @{$results};
188 # warn " biblio count : ".$total;
190 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
191 { template_name => "cataloguing/value_builder/marc21_linking_section.tt",
198 # multi page display gestion
200 my $displayprev = $startfrom;
202 if ( ( $total_hits - ( ( $startfrom + 1 ) * ($resultsperpage) ) ) > 0 ) {
206 my @field_data = ($search);
207 for ( my $i = 0 ; $i < $total && $i < $resultsperpage ; $i++ ) {
208 my $record = C4::Search::new_record_from_zebra( 'biblioserver', $results->[$i] );
209 my $rechash = TransformMarcToKoha( $record );
211 my $countitems = $rechash->{itembumber} ? 1 : 0;
212 while ( index( $rechash->{itemnumber}, '|', $pos ) > 0 ) {
214 $pos = index( $rechash->{itemnumber}, '|', $pos ) + 1;
216 $rechash->{totitem} = $countitems;
217 my @holdingbranches = split /\|/, $rechash->{holdingbranch};
218 my @itemcallnumbers = split /\|/, $rechash->{itemcallnumber};
220 for ( my $i = 0 ; $i < @holdingbranches ; $i++ ) {
221 $CN .= $holdingbranches[$i] . " ( " . $itemcallnumbers[$i] . " ) |";
224 $rechash->{CN} = $CN;
225 push @arrayresults, $rechash;
228 # for(my $i = 0 ; $i <= $#marclist ; $i++)
230 # push @field_data, { term => "marclist", val=>$marclist[$i] };
231 # push @field_data, { term => "and_or", val=>$and_or[$i] };
232 # push @field_data, { term => "excluding", val=>$excluding[$i] };
233 # push @field_data, { term => "operator", val=>$operator[$i] };
234 # push @field_data, { term => "value", val=>$value[$i] };
239 if ( $total > $resultsperpage ) {
240 for ( my $i = 1 ; $i < $total / $resultsperpage + 1 ; $i++ ) {
243 ( $startfrom == ( $i - 1 ) ) && ( $highlight = 1 );
246 highlight => $highlight,
247 searchdata => \@field_data,
248 startfrom => ( $i - 1 )
254 my $from = $startfrom * $resultsperpage + 1;
257 if ( $total_hits < $from + $resultsperpage ) {
260 $to = $from + $resultsperpage;
262 my $defaultview = 'BiblioDefaultView' . C4::Context->preference('BiblioDefaultView');
264 # my $link="/cgi-bin/koha/cataloguing/value_builder/unimarc4XX.pl?op=do_search&q=$search_desc&resultsperpage=$resultsperpage&startfrom=$startfrom&search=$search";
265 # foreach my $sort (@sort_by){
266 # $link.="&sort_by=".$sort."&";
269 # pagination_bar => pagination_bar(
271 # getnbpages($hits, $results_per_page),
277 result => \@arrayresults,
278 index => scalar $query->param('index') . "",
279 startfrom => $startfrom,
280 displaynext => $displaynext,
281 displayprev => $displayprev,
282 resultsperpage => $resultsperpage,
284 startfromnext => $startfrom + 1,
285 startfromprev => $startfrom - 1,
286 searchdata => \@field_data,
287 total => $total_hits,
290 numbers => \@numbers,
297 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
298 { template_name => "cataloguing/value_builder/marc21_linking_section.tt",
304 my @itemtypes = Koha::ItemTypes->search;
307 itypeloop => \@itemtypes,
308 index => scalar $query->param('index'),
312 output_html_with_http_headers $query, $cookie, $template->output;
315 return { builder => $builder, launcher => $launcher };