-# my @page_numbers;
-# my $pages = ceil($hits / $results_per_page);
-# my $previous_page_offset = $offset - $results_per_page unless ($offset - $results_per_page <0);
-# my $next_page_offset = $offset + $results_per_page;
-# for (my $j=1; $j<=$pages;$j++) {
-# my $this_offset = (($j*$results_per_page)-$results_per_page);
-# my $this_page_number = $j;
-# my $highlight = 1 if ($this_page_number == $current_page_number);
-# if ($this_page_number <= $pages) {
-# push @page_numbers, { offset => $this_offset, pg => $this_page_number, highlight => $highlight, sort_by => join " ",@sort_by };
-# }
-# }
-# $template->param(PAGE_NUMBERS => \@page_numbers,
-# previous_page_offset => $previous_page_offset,
-# next_page_offset => $next_page_offset) unless $pages < 2;
- my $link="/cgi-bin/koha/catalogue/search.pl?q=$query_search_desc&";
- foreach my $sort (@sort_by){
- $link.="&sort_by=".$sort."&";
- }
- $template->param(
- pagination_bar => pagination_bar(
- $link,
- getnbpages($hits, $results_per_page),
- $page,
- 'page'
- ),
- );
- }
- } # end of the if local
- else {
- # check if it's a z3950 or opensearch source
- my $zed3950 = 0; # FIXME :: Hardcoded value.
- if ($zed3950) {
- my @inner_sup_results_array;
- for my $sup_record ( @{$results_hashref->{$server}->{"RECORDS"}} ) {
- my $marc_record_object = MARC::Record->new_from_usmarc($sup_record);
- my $control_number = $marc_record_object->field('010')->subfield('a') if $marc_record_object->field('010');
- $control_number =~ s/^ //g;
- my $link = "http://catalog.loc.gov/cgi-bin/Pwebrecon.cgi?SAB1=".$control_number."&BOOL1=all+of+these&FLD1=LC+Control+Number+LCCN+%28K010%29+%28K010%29&GRP1=AND+with+next+set&SAB2=&BOOL2=all+of+these&FLD2=Keyword+Anywhere+%28GKEY%29+%28GKEY%29&PID=6211&SEQ=20060816121838&CNT=25&HIST=1";
- my $title = $marc_record_object->title();
- push @inner_sup_results_array, {
- 'title' => $title,
- 'link' => $link,
- };
+ ## FIXME: add a global function for this, it's better than the current global one
+ ## Build the page numbers on the bottom of the page
+ my @page_numbers;
+ # total number of pages there will be
+ my $pages = ceil($hits / $results_per_page);
+ # default page number
+ my $current_page_number = 1;
+ $current_page_number = ($offset / $results_per_page + 1) if $offset;
+ my $previous_page_offset = $offset - $results_per_page unless ($offset - $results_per_page <0);
+ my $next_page_offset = $offset + $results_per_page;
+ # If we're within the first 10 pages, keep it simple
+ #warn "current page:".$current_page_number;
+ if ($current_page_number < 10) {
+ # just show the first 10 pages
+ # Loop through the pages
+ my $pages_to_show = 10;
+ $pages_to_show = $pages if $pages<10;
+ for (my $i=1; $i<=$pages_to_show;$i++) {
+ # the offset for this page
+ my $this_offset = (($i*$results_per_page)-$results_per_page);
+ # the page number for this page
+ my $this_page_number = $i;
+ # it should only be highlighted if it's the current page
+ my $highlight = 1 if ($this_page_number == $current_page_number);
+ # put it in the array
+ push @page_numbers, { offset => $this_offset, pg => $this_page_number, highlight => $highlight, sort_by => join " ",@sort_by };
+
+ }
+