|
Lines 23-29
use strict;
Link Here
|
| 23 |
use warnings; |
23 |
use warnings; |
| 24 |
|
24 |
|
| 25 |
use CGI; |
25 |
use CGI; |
| 26 |
use C4::Auth; |
26 |
use C4::Auth qw(:DEFAULT get_session); |
| 27 |
use C4::Branch; |
27 |
use C4::Branch; |
| 28 |
use C4::Koha; |
28 |
use C4::Koha; |
| 29 |
use C4::Serials; #uses getsubscriptionfrom biblionumber |
29 |
use C4::Serials; #uses getsubscriptionfrom biblionumber |
|
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 $session = get_session($query->cookie("CGISESSID")); |
| 71 |
my %paging = (previous => {}, next => {}); |
| 72 |
if ($session->param('busc')) { |
| 73 |
use C4::Search; |
| 74 |
|
| 75 |
# Rebuild the string to store on session |
| 76 |
sub rebuildBuscParam |
| 77 |
{ |
| 78 |
my $arrParamsBusc = shift; |
| 79 |
|
| 80 |
my $pasarParams = ''; |
| 81 |
my $j = 0; |
| 82 |
for (keys %$arrParamsBusc) { |
| 83 |
if ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|total|offset|offsetSearch|next|previous|count|expand|scan)/) { |
| 84 |
if (defined($arrParamsBusc->{$_})) { |
| 85 |
$pasarParams .= '&' if ($j); |
| 86 |
$pasarParams .= $_ . '=' . $arrParamsBusc->{$_}; |
| 87 |
$j++; |
| 88 |
} |
| 89 |
} else { |
| 90 |
for my $value (@{$arrParamsBusc->{$_}}) { |
| 91 |
$pasarParams .= '&' if ($j); |
| 92 |
$pasarParams .= $_ . '=' . $value; |
| 93 |
$j++; |
| 94 |
} |
| 95 |
} |
| 96 |
} |
| 97 |
return $pasarParams; |
| 98 |
}#rebuildBuscParam |
| 99 |
|
| 100 |
# Search given the current values from the busc param |
| 101 |
sub searchAgain |
| 102 |
{ |
| 103 |
my ($arrParamsBusc, $offset, $results_per_page) = @_; |
| 104 |
|
| 105 |
my $expanded_facet = $arrParamsBusc->{'expand'}; |
| 106 |
my $branches = GetBranches(); |
| 107 |
my @servers; |
| 108 |
@servers = @{$arrParamsBusc->{'server'}} if $arrParamsBusc->{'server'}; |
| 109 |
@servers = ("biblioserver") unless (@servers); |
| 110 |
my $default_sort_by = C4::Context->preference('OPACdefaultSortField')."_".C4::Context->preference('OPACdefaultSortOrder') if (C4::Context->preference('OPACdefaultSortField') && C4::Context->preference('OPACdefaultSortOrder')); |
| 111 |
my @sort_by = @{$arrParamsBusc->{'sort_by'}} if $arrParamsBusc->{'sort_by'}; |
| 112 |
$sort_by[0] = $default_sort_by if !$sort_by[0] && defined($default_sort_by); |
| 113 |
my ($error, $results_hashref, $facets); |
| 114 |
eval { |
| 115 |
($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'}); |
| 116 |
}; |
| 117 |
my $hits; |
| 118 |
my @newresults; |
| 119 |
for (my $i=0;$i<@servers;$i++) { |
| 120 |
my $server = $servers[$i]; |
| 121 |
$hits = $results_hashref->{$server}->{"hits"}; |
| 122 |
@newresults = searchResults('opac', '', $hits, $results_per_page, $offset, $arrParamsBusc->{'scan'}, @{$results_hashref->{$server}->{"RECORDS"}},, C4::Context->preference('hidelostitems')); |
| 123 |
} |
| 124 |
return \@newresults; |
| 125 |
}#searchAgain |
| 126 |
|
| 127 |
# Build the current list of biblionumbers in this search |
| 128 |
sub buildListBiblios |
| 129 |
{ |
| 130 |
my ($newresultsRef, $results_per_page) = @_; |
| 131 |
|
| 132 |
my $listBiblios = ''; |
| 133 |
my $j = 0; |
| 134 |
foreach (@$newresultsRef) { |
| 135 |
my $bibnum = ($_->{biblionumber})?$_->{biblionumber}:0; |
| 136 |
$listBiblios .= $bibnum . ','; |
| 137 |
$j++; |
| 138 |
last if ($j == $results_per_page); |
| 139 |
} |
| 140 |
chop $listBiblios if ($listBiblios =~ /,$/); |
| 141 |
return $listBiblios; |
| 142 |
}#buildListBiblios |
| 143 |
|
| 144 |
my $busc = $session->param("busc"); |
| 145 |
my @arrBusc = split(/\&(?:amp;)?/, $busc); |
| 146 |
my ($key, $value); |
| 147 |
my %arrParamsBusc = (); |
| 148 |
for (@arrBusc) { |
| 149 |
($key, $value) = split(/=/, $_, 2); |
| 150 |
if ($key =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|offset|offsetSearch|count|expand|scan)/) { |
| 151 |
$arrParamsBusc{$key} = $value; |
| 152 |
} else { |
| 153 |
unless (exists($arrParamsBusc{$key})) { |
| 154 |
$arrParamsBusc{$key} = []; |
| 155 |
} |
| 156 |
push @{$arrParamsBusc{$key}}, $value; |
| 157 |
} |
| 158 |
} |
| 159 |
my $searchAgain = 0; |
| 160 |
my $count = C4::Context->preference('OPACnumSearchResults') || 20; |
| 161 |
my $results_per_page = ($arrParamsBusc{'count'} && $arrParamsBusc{'count'} =~ /^[0-9]+?/)?$arrParamsBusc{'count'}:$count; |
| 162 |
$arrParamsBusc{'count'} = $results_per_page; |
| 163 |
my $offset = ($arrParamsBusc{'offset'} && $arrParamsBusc{'offset'} =~ /^[0-9]+?/)?$arrParamsBusc{'offset'}:0; |
| 164 |
# The value OPACnumSearchResults has changed and the search has to be rebuild |
| 165 |
if ($count != $results_per_page) { |
| 166 |
if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) { |
| 167 |
my $indexBiblio = 0; |
| 168 |
my @arrBibliosAux = split(',', $arrParamsBusc{'listBiblios'}); |
| 169 |
for (@arrBibliosAux) { |
| 170 |
last if ($_ == $biblionumber); |
| 171 |
$indexBiblio++; |
| 172 |
} |
| 173 |
$indexBiblio += $offset; |
| 174 |
$offset = int($indexBiblio / $count) * $count; |
| 175 |
$arrParamsBusc{'offset'} = $offset; |
| 176 |
} |
| 177 |
$arrParamsBusc{'count'} = $count; |
| 178 |
$results_per_page = $count; |
| 179 |
my $newresultsRef = searchAgain(\%arrParamsBusc, $offset, $results_per_page); |
| 180 |
$arrParamsBusc{'listBiblios'} = buildListBiblios($newresultsRef, $results_per_page); |
| 181 |
delete $arrParamsBusc{'previous'} if (exists($arrParamsBusc{'previous'})); |
| 182 |
delete $arrParamsBusc{'next'} if (exists($arrParamsBusc{'next'})); |
| 183 |
delete $arrParamsBusc{'offsetSearch'} if (exists($arrParamsBusc{'offsetSearch'})); |
| 184 |
delete $arrParamsBusc{'newlistBiblios'} if (exists($arrParamsBusc{'newlistBiblios'})); |
| 185 |
my $newbusc = rebuildBuscParam(\%arrParamsBusc); |
| 186 |
$session->param("busc" => $newbusc); |
| 187 |
@arrBusc = split(/\&(?:amp;)?/, $newbusc); |
| 188 |
} else { |
| 189 |
my $modifyListBiblios = 0; |
| 190 |
# We come from a previous click |
| 191 |
if (exists($arrParamsBusc{'previous'})) { |
| 192 |
$modifyListBiblios = 1 if ($biblionumber == $arrParamsBusc{'previous'}); |
| 193 |
delete $arrParamsBusc{'previous'}; |
| 194 |
} elsif (exists($arrParamsBusc{'next'})) { # We come from a next click |
| 195 |
$modifyListBiblios = 2 if ($biblionumber == $arrParamsBusc{'next'}); |
| 196 |
delete $arrParamsBusc{'next'}; |
| 197 |
} |
| 198 |
if ($modifyListBiblios) { |
| 199 |
if (exists($arrParamsBusc{'newlistBiblios'})) { |
| 200 |
my $listBibliosAux = $arrParamsBusc{'listBiblios'}; |
| 201 |
$arrParamsBusc{'listBiblios'} = $arrParamsBusc{'newlistBiblios'}; |
| 202 |
my @arrAux = split(',', $listBibliosAux); |
| 203 |
$arrParamsBusc{'newlistBiblios'} = $listBibliosAux; |
| 204 |
if ($modifyListBiblios == 1) { |
| 205 |
$arrParamsBusc{'next'} = $arrAux[0]; |
| 206 |
$paging{'next'}->{biblionumber} = $arrAux[0]; |
| 207 |
}else { |
| 208 |
$arrParamsBusc{'previous'} = $arrAux[$#arrAux]; |
| 209 |
$paging{'previous'}->{biblionumber} = $arrAux[$#arrAux]; |
| 210 |
} |
| 211 |
} else { |
| 212 |
delete $arrParamsBusc{'listBiblios'}; |
| 213 |
} |
| 214 |
my $offsetAux = $arrParamsBusc{'offset'}; |
| 215 |
$arrParamsBusc{'offset'} = $arrParamsBusc{'offsetSearch'}; |
| 216 |
$arrParamsBusc{'offsetSearch'} = $offsetAux; |
| 217 |
$offset = $arrParamsBusc{'offset'}; |
| 218 |
my $newbusc = rebuildBuscParam(\%arrParamsBusc); |
| 219 |
$session->param("busc" => $newbusc); |
| 220 |
@arrBusc = split(/\&(?:amp;)?/, $newbusc); |
| 221 |
} |
| 222 |
} |
| 223 |
my $buscParam = ''; |
| 224 |
my $j = 0; |
| 225 |
# Rebuild the query for the button "back to results" |
| 226 |
for (@arrBusc) { |
| 227 |
unless ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|count|offsetSearch)/) { |
| 228 |
$buscParam .= '&' unless ($j == 0); |
| 229 |
$buscParam .= $_; |
| 230 |
$j++; |
| 231 |
} |
| 232 |
} |
| 233 |
$template->param('busc' => $buscParam); |
| 234 |
my $offsetSearch; |
| 235 |
my @arrBiblios; |
| 236 |
# We are inside the list of biblios and we don't have to search |
| 237 |
if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) { |
| 238 |
@arrBiblios = split(',', $arrParamsBusc{'listBiblios'}); |
| 239 |
if (@arrBiblios) { |
| 240 |
# We are at the first item of the list |
| 241 |
if ($arrBiblios[0] == $biblionumber) { |
| 242 |
if (@arrBiblios > 1) { |
| 243 |
for (my $j = 1; $j < @arrBiblios; $j++) { |
| 244 |
next unless ($arrBiblios[$j]); |
| 245 |
$paging{'next'}->{biblionumber} = $arrBiblios[$j]; |
| 246 |
last; |
| 247 |
} |
| 248 |
} |
| 249 |
# search again if we are not at the first searching list |
| 250 |
if ($offset && !$arrParamsBusc{'previous'}) { |
| 251 |
$searchAgain = 1; |
| 252 |
$offsetSearch = $offset - $results_per_page; |
| 253 |
} |
| 254 |
# we are at the last item of the list |
| 255 |
} elsif ($arrBiblios[$#arrBiblios] == $biblionumber) { |
| 256 |
for (my $j = $#arrBiblios - 1; $j >= 0; $j--) { |
| 257 |
next unless ($arrBiblios[$j]); |
| 258 |
$paging{'previous'}->{biblionumber} = $arrBiblios[$j]; |
| 259 |
last; |
| 260 |
} |
| 261 |
if (!$offset) { |
| 262 |
# search again if we are at the first list and there is more results |
| 263 |
$searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} != @arrBiblios); |
| 264 |
} else { |
| 265 |
# search again if we aren't at the first list and there is more results |
| 266 |
$searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} > ($offset + @arrBiblios)); |
| 267 |
} |
| 268 |
$offsetSearch = $offset + $results_per_page if ($searchAgain); |
| 269 |
} else { |
| 270 |
for (my $j = 1; $j < $#arrBiblios; $j++) { |
| 271 |
if ($arrBiblios[$j] == $biblionumber) { |
| 272 |
for (my $z = $j - 1; $z >= 0; $z--) { |
| 273 |
next unless ($arrBiblios[$z]); |
| 274 |
$paging{'previous'}->{biblionumber} = $arrBiblios[$z]; |
| 275 |
last; |
| 276 |
} |
| 277 |
for (my $z = $j + 1; $z < @arrBiblios; $z++) { |
| 278 |
next unless ($arrBiblios[$z]); |
| 279 |
$paging{'next'}->{biblionumber} = $arrBiblios[$z]; |
| 280 |
last; |
| 281 |
} |
| 282 |
last; |
| 283 |
} |
| 284 |
} |
| 285 |
} |
| 286 |
} |
| 287 |
$offsetSearch = 0 if (defined($offsetSearch) && $offsetSearch < 0); |
| 288 |
} |
| 289 |
if ($searchAgain) { |
| 290 |
my $newresultsRef = searchAgain(\%arrParamsBusc, $offsetSearch, $results_per_page); |
| 291 |
my @newresults = @$newresultsRef; |
| 292 |
# build the new listBiblios |
| 293 |
my $listBiblios = buildListBiblios(\@newresults, $results_per_page); |
| 294 |
unless (exists($arrParamsBusc{'listBiblios'})) { |
| 295 |
$arrParamsBusc{'listBiblios'} = $listBiblios; |
| 296 |
@arrBiblios = split(',', $arrParamsBusc{'listBiblios'}); |
| 297 |
} else { |
| 298 |
$arrParamsBusc{'newlistBiblios'} = $listBiblios; |
| 299 |
} |
| 300 |
# From the new list we build again the next and previous result |
| 301 |
if (@arrBiblios) { |
| 302 |
if ($arrBiblios[0] == $biblionumber) { |
| 303 |
for (my $j = $#newresults; $j >= 0; $j--) { |
| 304 |
next unless ($newresults[$j]); |
| 305 |
$paging{'previous'}->{biblionumber} = $newresults[$j]->{biblionumber}; |
| 306 |
$arrParamsBusc{'previous'} = $paging{'previous'}->{biblionumber}; |
| 307 |
$arrParamsBusc{'offsetSearch'} = $offsetSearch; |
| 308 |
last; |
| 309 |
} |
| 310 |
} elsif ($arrBiblios[$#arrBiblios] == $biblionumber) { |
| 311 |
for (my $j = 0; $j < @newresults; $j++) { |
| 312 |
next unless ($newresults[$j]); |
| 313 |
$paging{'next'}->{biblionumber} = $newresults[$j]->{biblionumber}; |
| 314 |
$arrParamsBusc{'next'} = $paging{'next'}->{biblionumber}; |
| 315 |
$arrParamsBusc{'offsetSearch'} = $offsetSearch; |
| 316 |
last; |
| 317 |
} |
| 318 |
} |
| 319 |
} |
| 320 |
# build new busc param |
| 321 |
my $newbusc = rebuildBuscParam(\%arrParamsBusc); |
| 322 |
$session->param("busc" => $newbusc); |
| 323 |
} |
| 324 |
my ($previous, $next, $dataBiblioPaging); |
| 325 |
# Previous biblio |
| 326 |
if ($paging{'previous'}->{biblionumber}) { |
| 327 |
$previous = 'opac-detail.pl?biblionumber=' . $paging{'previous'}->{biblionumber}; |
| 328 |
$dataBiblioPaging = GetBiblioData($paging{'previous'}->{biblionumber}); |
| 329 |
$template->param('previousTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging); |
| 330 |
} |
| 331 |
# Next biblio |
| 332 |
if ($paging{'next'}->{biblionumber}) { |
| 333 |
$next = 'opac-detail.pl?biblionumber=' . $paging{'next'}->{biblionumber}; |
| 334 |
$dataBiblioPaging = GetBiblioData($paging{'next'}->{biblionumber}); |
| 335 |
$template->param('nextTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging); |
| 336 |
} |
| 337 |
$template->param('previous' => $previous, 'next' => $next); |
| 338 |
# Partial list of biblio results |
| 339 |
my @listResults; |
| 340 |
for (my $j = 0; $j < @arrBiblios; $j++) { |
| 341 |
next unless ($arrBiblios[$j]); |
| 342 |
$dataBiblioPaging = GetBiblioData($arrBiblios[$j]) if ($arrBiblios[$j] != $biblionumber); |
| 343 |
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]}; |
| 344 |
} |
| 345 |
$template->param('listResults' => \@listResults) if (@listResults); |
| 346 |
$template->param('indexPag' => 1 + $offset, 'totalPag' => $arrParamsBusc{'total'}, 'indexPagEnd' => scalar(@arrBiblios) + $offset); |
| 347 |
} |
| 348 |
|
| 349 |
|
| 350 |
|
| 69 |
$template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') ); |
351 |
$template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') ); |
| 70 |
$template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) ); |
352 |
$template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) ); |
| 71 |
|
353 |
|