3 # Copyright 2000-2002 Katipo Communications
4 # Parts copyright 2010 Nelsonville Public Library
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA 02111-1307 USA
31 use C4
::Dates qw
/format_date/;
32 use C4
::Members qw
/GetMemberDetails/;
33 use POSIX
qw(ceil strftime);
37 my $format = $query->param("format") || '';
38 my $count = C4
::Context
->preference('OPACnumSearchResults') || 20;
39 my $results_per_page = $query->param('count') || $count;
40 my $offset = $query->param('offset') || 0;
41 my $page = $query->param('page') || 1;
42 $offset = ($page-1)*$results_per_page if $page>1;
44 if ($format eq "rss") {
45 $template_name = "opac-showreviews-rss.tmpl";
47 $template_name = "opac-showreviews.tmpl",
50 my ( $template, $borrowernumber, $cookie ) = &get_template_and_user
(
52 template_name
=> $template_name,
60 my $lastbuilddate = C4
::Dates
->new();
61 my $lastbuilddate_output = $lastbuilddate->output("rfc822");
64 timestamp
=> $lastbuilddate_output
68 my $reviews = getallreviews
(1,$offset,$results_per_page);
69 my $marcflavour = C4
::Context
->preference("marcflavour");
70 my $hits = numberofreviews
();
72 my $latest_comment_date;
73 for my $result (@
$reviews){
74 my $biblionumber = $result->{biblionumber
};
75 my $bib = &GetBiblioData
($biblionumber);
76 my $record = GetMarcBiblio
($biblionumber);
77 my $frameworkcode = GetFrameworkCode
($biblionumber);
78 my ( $borr ) = GetMemberDetails
( $result->{borrowernumber
} );
79 $result->{normalized_upc
} = GetNormalizedUPC
($record,$marcflavour);
80 $result->{normalized_ean
} = GetNormalizedEAN
($record,$marcflavour);
81 $result->{normalized_oclc
} = GetNormalizedOCLCNumber
($record,$marcflavour);
82 $result->{normalized_isbn
} = GetNormalizedISBN
(undef,$record,$marcflavour);
83 $result->{title
} = $bib->{'title'};
84 $result->{subtitle
} = GetRecordValue
('subtitle', $record, $frameworkcode);
85 $result->{author
} = $bib->{'author'};
86 $result->{place
} = $bib->{'place'};
87 $result->{publishercode
} = $bib->{'publishercode'};
88 $result->{copyrightdate
} = $bib->{'copyrightdate'};
89 $result->{pages
} = $bib->{'pages'};
90 $result->{size
} = $bib->{'size'};
91 $result->{notes
} = $bib->{'notes'};
92 $result->{timestamp
} = $bib->{'timestamp'};
93 $result->{firstname
} = $borr->{'firstname'};
94 $result->{surname
} = $borr->{'surname'};
95 if ($result->{borrowernumber
} eq $borrowernumber) {
96 $result->{your_comment
} = 1;
100 my $rsstimestamp = C4
::Dates
->new($result->{datereviewed
},"iso");
101 my $rsstimestamp_output = $rsstimestamp->output("rfc822");
102 $result->{timestamp
} = $rsstimestamp_output;
103 $result->{datereviewed
} = format_date
($result->{datereviewed
});
105 $result->{datereviewed
} = format_date
($result->{datereviewed
});
108 ## Build the page numbers on the bottom of the page
110 my $previous_page_first;
111 my $previous_page_offset;
112 # total number of pages there will be
113 my $pages = ceil
($hits / $results_per_page);
114 # default page number
115 my $current_page_number = 1;
116 $current_page_number = ($offset / $results_per_page + 1) if $offset;
117 if($offset - $results_per_page == 0){
118 $previous_page_first = 1;
119 } elsif ($offset - $results_per_page > 0){
120 $previous_page_offset = $offset - $results_per_page;
122 my $next_page_offset = $offset + $results_per_page;
123 # If we're within the first 10 pages, keep it simple
124 if ($current_page_number < 10) {
125 # just show the first 10 pages
126 # Loop through the pages
127 my $pages_to_show = 10;
128 $pages_to_show = $pages if $pages<10;
129 for ($i=1; $i<=$pages_to_show;$i++) {
130 # the offset for this page
131 my $this_offset = (($i*$results_per_page)-$results_per_page);
132 # the page number for this page
133 my $this_page_number = $i;
134 # it should only be highlighted if it's the current page
135 my $highlight = 1 if ($this_page_number == $current_page_number);
136 # put it in the array
137 push @page_numbers, { offset
=> $this_offset, pg
=> $this_page_number, highlight
=> $highlight };
142 # now, show twenty pages, with the current one smack in the middle
144 for ($i=$current_page_number; $i<=($current_page_number + 20 );$i++) {
145 my $this_offset = ((($i-9)*$results_per_page)-$results_per_page);
146 my $this_page_number = $i-9;
147 my $highlight = 1 if ($this_page_number == $current_page_number);
148 if ($this_page_number <= $pages) {
149 push @page_numbers, { offset
=> $this_offset, pg
=> $this_page_number, highlight
=> $highlight };
153 $template->param( PAGE_NUMBERS
=> \
@page_numbers,
154 previous_page_first
=> $previous_page_first,
155 previous_page_offset
=> $previous_page_offset) unless $pages < 2;
156 $template->param(next_page_offset
=> $next_page_offset) unless $pages eq $current_page_number;
162 output_html_with_http_headers
$query, $cookie, $template->output;