Lines 66-71
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
Link Here
|
66 |
|
66 |
|
67 |
my $biblionumber = $query->param('biblionumber') || $query->param('bib'); |
67 |
my $biblionumber = $query->param('biblionumber') || $query->param('bib'); |
68 |
|
68 |
|
|
|
69 |
# We look for the busc param to build the simple paging from the search |
70 |
my %paging = (previous => {}, next => {}); |
71 |
if ($query->param('busc')) { |
72 |
use Compress::Zlib; |
73 |
use MIME::Base64; |
74 |
use URI::Escape; |
75 |
use C4::Search; |
76 |
|
77 |
# Rebuild the encrypted busc param |
78 |
sub rebuildBuscParam |
79 |
{ |
80 |
my $arrParamsBusc = shift; |
81 |
|
82 |
my $pasarParams = ''; |
83 |
my $j = 0; |
84 |
for (keys %$arrParamsBusc) { |
85 |
if ($_ =~ /^(?:query|listBiblios|query_type|simple_query|total|offset|offsetPrev|count|expand|scan)/) { |
86 |
if (defined($arrParamsBusc->{$_})) { |
87 |
$pasarParams .= '&' if ($j); |
88 |
$pasarParams .= $_ . '=' . $arrParamsBusc->{$_}; |
89 |
$j++; |
90 |
} |
91 |
} else { |
92 |
for my $value (@{$arrParamsBusc->{$_}}) { |
93 |
$pasarParams .= '&' if ($j); |
94 |
$pasarParams .= $_ . '=' . $value; |
95 |
$j++; |
96 |
} |
97 |
} |
98 |
} |
99 |
my $pasarParamsEnc = compress($pasarParams, Z_BEST_COMPRESSION); |
100 |
$pasarParamsEnc = encode_base64($pasarParamsEnc); |
101 |
$pasarParamsEnc = uri_escape($pasarParamsEnc); |
102 |
return $pasarParamsEnc; |
103 |
}#rebuildBuscParam |
104 |
|
105 |
my $busc = uri_unescape($query->param("busc")); |
106 |
my $buscOrig = uri_escape($busc); |
107 |
$busc = decode_base64($busc); |
108 |
$busc = uncompress($busc); |
109 |
my $buscParam = ''; |
110 |
my $j = 0; |
111 |
# Rebuild the query for the button "back to results" |
112 |
for (split(/\&(?:amp;)?/, $busc)) { |
113 |
unless ($_ =~ /^(?:query|listBiblios|query_type|simple_query|total|offsetPrev)/) { |
114 |
$buscParam .= '&' unless ($j == 0); |
115 |
$buscParam .= $_; |
116 |
$j++; |
117 |
} |
118 |
} |
119 |
$template->param('busc' => $buscParam); |
120 |
my ($key, $value); |
121 |
my %arrParamsBusc = (); |
122 |
for (split(/\&(?:amp;)?/, $busc)) { |
123 |
($key, $value) = split(/=/, $_, 2); |
124 |
if ($key =~ /^(?:query|listBiblios|query_type|simple_query|total|offset|offsetPrev|count|expand|scan)/) { |
125 |
$arrParamsBusc{$key} = $value; |
126 |
} else { |
127 |
unless (exists($arrParamsBusc{$key})) { |
128 |
$arrParamsBusc{$key} = []; |
129 |
} |
130 |
push @{$arrParamsBusc{$key}}, $value; |
131 |
} |
132 |
} |
133 |
my $searchAgain = 0; |
134 |
my $count = C4::Context->preference('OPACnumSearchResults') || 20; |
135 |
my $results_per_page = ($arrParamsBusc{'count'} && $arrParamsBusc{'count'} =~ /^[0-9]+?/)?$arrParamsBusc{'count'}:$count; |
136 |
my $offset = ($arrParamsBusc{'offset'} && $arrParamsBusc{'offset'} =~ /^[0-9]+?/)?$arrParamsBusc{'offset'}:0; |
137 |
my $offsetSearch; |
138 |
my @arrBiblios; |
139 |
# We are inside the list of biblios and we don't have to search |
140 |
if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) { |
141 |
@arrBiblios = split(',', $arrParamsBusc{'listBiblios'}); |
142 |
if (@arrBiblios) { |
143 |
# We are at the first item of the block |
144 |
if ($arrBiblios[0] == $biblionumber) { |
145 |
if (@arrBiblios > 1) { |
146 |
for (my $j = 1; $j < @arrBiblios; $j++) { |
147 |
next unless ($arrBiblios[$j]); |
148 |
$paging{'next'}->{biblionumber} = $arrBiblios[$j]; |
149 |
last; |
150 |
} |
151 |
} |
152 |
# search again if we are not at the first searching block |
153 |
if ($offset) { |
154 |
$searchAgain = 1; |
155 |
$offsetSearch = $offset - $results_per_page; |
156 |
} |
157 |
# we are at the last item of the block |
158 |
} elsif ($arrBiblios[$#arrBiblios] == $biblionumber) { |
159 |
for (my $j = $#arrBiblios - 1; $j >= 0; $j--) { |
160 |
next unless ($arrBiblios[$j]); |
161 |
$paging{'previous'}->{biblionumber} = $arrBiblios[$j]; |
162 |
last; |
163 |
} |
164 |
if (!$offset) { |
165 |
# search again if we are at the first block and there is more results |
166 |
$searchAgain = 1 if ($arrParamsBusc{'total'} != @arrBiblios); |
167 |
} else { |
168 |
# search again if we aren't at the first block and there is more results |
169 |
$searchAgain = 1 if ($arrParamsBusc{'total'} > ($offset + @arrBiblios)); |
170 |
} |
171 |
$offsetSearch = $offset + $results_per_page if ($searchAgain); |
172 |
} else { |
173 |
for (my $j = 1; $j < $#arrBiblios; $j++) { |
174 |
if ($arrBiblios[$j] == $biblionumber) { |
175 |
for (my $z = $j - 1; $z >= 0; $z--) { |
176 |
next unless ($arrBiblios[$z]); |
177 |
$paging{'previous'}->{biblionumber} = $arrBiblios[$z]; |
178 |
last; |
179 |
} |
180 |
for (my $z = $j + 1; $z < @arrBiblios; $z++) { |
181 |
next unless ($arrBiblios[$z]); |
182 |
$paging{'next'}->{biblionumber} = $arrBiblios[$z]; |
183 |
last; |
184 |
} |
185 |
last; |
186 |
} |
187 |
} |
188 |
} |
189 |
} |
190 |
$offsetSearch = 0 if (defined($offsetSearch) && $offsetSearch < 0); |
191 |
unless ($searchAgain) { |
192 |
$paging{'previous'}->{busc} = $buscOrig if ($paging{'previous'}->{biblionumber}); |
193 |
$paging{'next'}->{busc} = $buscOrig if ($paging{'next'}->{biblionumber}); |
194 |
} else { |
195 |
if ($paging{'previous'}->{biblionumber}) { |
196 |
$paging{'previous'}->{busc} = $buscOrig; |
197 |
} |
198 |
if ($paging{'next'}->{biblionumber}) { |
199 |
$paging{'next'}->{busc} = $buscOrig; |
200 |
} |
201 |
if (!$paging{'previous'}->{biblionumber}) { |
202 |
$arrParamsBusc{'offsetPrev'} = $offset; |
203 |
$arrParamsBusc{'offset'} = $offsetSearch; |
204 |
delete $arrParamsBusc{'listBiblios'}; |
205 |
$paging{'previous'}->{busc} = rebuildBuscParam(\%arrParamsBusc); |
206 |
} elsif (!$paging{'next'}->{biblionumber} && $arrParamsBusc{'total'} > ($offset + @arrBiblios)) { |
207 |
$arrParamsBusc{'offsetPrev'} = $offset; |
208 |
$arrParamsBusc{'offset'} = $offsetSearch; |
209 |
delete $arrParamsBusc{'listBiblios'}; |
210 |
$paging{'next'}->{busc} = rebuildBuscParam(\%arrParamsBusc); |
211 |
} |
212 |
} |
213 |
} else { # We have to search |
214 |
my $expanded_facet = $arrParamsBusc{'expand'}; |
215 |
my $branches = GetBranches(); |
216 |
my @servers; |
217 |
@servers = @{$arrParamsBusc{'server'}} if $arrParamsBusc{'server'}; |
218 |
@servers = ("biblioserver") unless (@servers); |
219 |
my $default_sort_by = C4::Context->preference('OPACdefaultSortField')."_".C4::Context->preference('OPACdefaultSortOrder') if (C4::Context->preference('OPACdefaultSortField') && C4::Context->preference('OPACdefaultSortOrder')); |
220 |
my @sort_by = @{$arrParamsBusc{'sort_by'}} if $arrParamsBusc{'sort_by'}; |
221 |
$sort_by[0] = $default_sort_by if !$sort_by[0] && defined($default_sort_by); |
222 |
my ($error, $results_hashref, $facets); |
223 |
eval { |
224 |
($error, $results_hashref, $facets) = getRecords($arrParamsBusc{'query'},$arrParamsBusc{'simple_query'},\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,$branches,$arrParamsBusc{'query_type'},$arrParamsBusc{'scan'}); |
225 |
}; |
226 |
my $hits; |
227 |
my @newresults; |
228 |
for (my $i=0;$i<@servers;$i++) { |
229 |
my $server = $servers[$i]; |
230 |
$hits = $results_hashref->{$server}->{"hits"}; |
231 |
@newresults = searchResults('opac', '', $hits, $results_per_page, $offset, $arrParamsBusc{'scan'}, @{$results_hashref->{$server}->{"RECORDS"}},, C4::Context->preference('hidelostitems')); |
232 |
} |
233 |
# build the new listBiblios |
234 |
my $listBiblios = ''; |
235 |
my $j = 0; |
236 |
# add new list param |
237 |
foreach (@newresults) { |
238 |
my $bibnum = ($_->{biblionumber})?$_->{biblionumber}:0; |
239 |
$listBiblios .= $bibnum . ','; |
240 |
$j++; |
241 |
last if ($j == $results_per_page); |
242 |
} |
243 |
chop $listBiblios if ($listBiblios =~ /,$/); |
244 |
$arrParamsBusc{'listBiblios'} = $listBiblios; |
245 |
@arrBiblios = split(',', $arrParamsBusc{'listBiblios'}); |
246 |
if (@arrBiblios && !$biblionumber) { |
247 |
if (defined($arrParamsBusc{'offsetPrev'})) { |
248 |
$biblionumber = ($offset > $arrParamsBusc{'offsetPrev'})?$arrBiblios[0]:$arrBiblios[$#arrBiblios]; |
249 |
} else { |
250 |
$biblionumber = $arrBiblios[0]; |
251 |
} |
252 |
} |
253 |
# From the new list we build again the next and previous result |
254 |
if (@arrBiblios) { |
255 |
if ($arrBiblios[$#arrBiblios] == $biblionumber) { |
256 |
for (my $j = 0; $j < @newresults; $j++) { |
257 |
next unless ($newresults[$j]); |
258 |
$paging{'previous'}->{biblionumber} = $newresults[$j]->{biblionumber}; |
259 |
last; |
260 |
} |
261 |
} elsif ($arrBiblios[0] == $biblionumber) { |
262 |
for (my $j = $#newresults; $j >= 0; $j--) { |
263 |
next unless ($newresults[$j]); |
264 |
$paging{'next'}->{biblionumber} = $newresults[$j]->{biblionumber}; |
265 |
last; |
266 |
} |
267 |
} |
268 |
} |
269 |
# build new busc param |
270 |
$buscOrig = rebuildBuscParam(\%arrParamsBusc); |
271 |
if ($paging{'next'}->{biblionumber}) { |
272 |
$paging{'next'}->{busc} = $buscOrig; |
273 |
} |
274 |
if ($paging{'previous'}->{biblionumber}) { |
275 |
$paging{'previous'}->{busc} = $buscOrig; |
276 |
} |
277 |
if (!$paging{'previous'}->{biblionumber}) { |
278 |
$arrParamsBusc{'offset'} = $arrParamsBusc{'offsetPrev'}; |
279 |
$arrParamsBusc{'offsetPrev'} = $offset; |
280 |
delete $arrParamsBusc{'listBiblios'}; |
281 |
$paging{'previous'}->{busc} = rebuildBuscParam(\%arrParamsBusc); |
282 |
} elsif (!$paging{'next'}->{biblionumber} && $arrParamsBusc{'total'} > ($offset + @arrBiblios)) { |
283 |
$arrParamsBusc{'offset'} = $arrParamsBusc{'offsetPrev'}; |
284 |
$arrParamsBusc{'offsetPrev'} = $offset; |
285 |
delete $arrParamsBusc{'listBiblios'}; |
286 |
$paging{'next'}->{busc} = rebuildBuscParam(\%arrParamsBusc); |
287 |
} |
288 |
} |
289 |
|
290 |
# Previous biblio |
291 |
my $previous = 'opac-detail.pl?' . (($paging{'previous'}->{biblionumber})?'biblionumber=' . $paging{'previous'}->{biblionumber} . '&':'') . 'busc=' . $paging{'previous'}->{busc} if ($paging{'previous'}->{busc}); |
292 |
my $dataBiblioPaging = GetBiblioData($paging{'previous'}->{biblionumber}); |
293 |
if ($dataBiblioPaging) { |
294 |
$template->param('previousTitle' => $dataBiblioPaging->{'title'}); |
295 |
} |
296 |
# Next biblio |
297 |
my $next = 'opac-detail.pl?' . (($paging{'next'}->{biblionumber})?'biblionumber=' . $paging{'next'}->{biblionumber} . '&':'') . 'busc=' . $paging{'next'}->{busc} if ($paging{'next'}->{busc}); |
298 |
$dataBiblioPaging = GetBiblioData($paging{'next'}->{biblionumber}); |
299 |
if ($dataBiblioPaging) { |
300 |
$template->param('nextTitle' => $dataBiblioPaging->{'title'}); |
301 |
} |
302 |
$template->param('previous' => $previous, 'next' => $next); |
303 |
# Partial list of biblio results |
304 |
my @listResults; |
305 |
for (my $j = 0; $j < @arrBiblios; $j++) { |
306 |
next unless ($arrBiblios[$j]); |
307 |
$dataBiblioPaging = GetBiblioData($arrBiblios[$j]) if ($arrBiblios[$j] != $biblionumber); |
308 |
push @listResults, {index => $j + 1 + $offset, biblionumber => $arrBiblios[$j], title => ($arrBiblios[$j] == $biblionumber)?'':$dataBiblioPaging->{title}, author => ($arrBiblios[$j] != $biblionumber && $dataBiblioPaging->{author})?$dataBiblioPaging->{author}:'', url => ($arrBiblios[$j] == $biblionumber)?'':'opac-detail.pl?biblionumber=' . $arrBiblios[$j] . '&busc=' . $buscOrig}; |
309 |
} |
310 |
$template->param('listResults' => \@listResults) if (@listResults); |
311 |
} |
312 |
|
313 |
|
314 |
|
69 |
$template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') ); |
315 |
$template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') ); |
70 |
$template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) ); |
316 |
$template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) ); |
71 |
|
317 |
|