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
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
30 use C4
::Members qw
/GetMember/;
33 use POSIX
qw(ceil floor 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 = floor
( $offset / $results_per_page ) + 1;
43 if ($format eq "rss") {
44 $template_name = "opac-showreviews-rss.tt";
46 $template_name = "opac-showreviews.tt",
49 my ( $template, $borrowernumber, $cookie ) = &get_template_and_user
(
51 template_name
=> $template_name,
54 authnotrequired
=> ( C4
::Context
->preference("OpacPublic") ?
1 : 0 ),
59 my $lastbuilddate = dt_from_string
;
60 my $lastbuilddate_output = $lastbuilddate->strftime("%a, %d %b %Y %H:%M:%S %z");
63 timestamp
=> $lastbuilddate_output
67 my $libravatar_enabled = 0;
68 if ( C4
::Context
->preference('ShowReviewer') and C4
::Context
->preference('ShowReviewerPhoto')) {
70 require Libravatar
::URL
;
71 Libravatar
::URL
->import();
74 $libravatar_enabled = 1;
78 my $reviews = Koha
::Reviews
->search(
81 rows
=> $results_per_page,
83 order_by
=> { -desc
=> 'datereviewed' },
86 my $marcflavour = C4
::Context
->preference("marcflavour");
87 my $hits = Koha
::Reviews
->search({ approved
=> 1 })->count;
89 my $latest_comment_date;
90 for my $result (@
$reviews){
91 my $biblionumber = $result->{biblionumber
};
92 my $bib = &GetBiblioData
($biblionumber);
93 my $record = GetMarcBiblio
($biblionumber);
94 my $frameworkcode = GetFrameworkCode
($biblionumber);
95 my ( $borr ) = GetMember
( borrowernumber
=> $result->{borrowernumber
} );
96 $result->{normalized_upc
} = GetNormalizedUPC
($record,$marcflavour);
97 $result->{normalized_ean
} = GetNormalizedEAN
($record,$marcflavour);
98 $result->{normalized_oclc
} = GetNormalizedOCLCNumber
($record,$marcflavour);
99 $result->{normalized_isbn
} = GetNormalizedISBN
(undef,$record,$marcflavour);
100 $result->{title
} = $bib->{'title'};
101 $result->{subtitle
} = GetRecordValue
('subtitle', $record, $frameworkcode);
102 $result->{author
} = $bib->{'author'};
103 $result->{place
} = $bib->{'place'};
104 $result->{publishercode
} = $bib->{'publishercode'};
105 $result->{copyrightdate
} = $bib->{'copyrightdate'};
106 $result->{pages
} = $bib->{'pages'};
107 $result->{size
} = $bib->{'size'};
108 $result->{notes
} = $bib->{'notes'};
109 $result->{timestamp
} = $bib->{'timestamp'};
110 $result->{borrtitle
} = $borr->{'title'};
111 $result->{firstname
} = $borr->{'firstname'};
112 $result->{surname
} = $borr->{'surname'};
113 $result->{userid
} = $borr->{'userid'};
114 if ($libravatar_enabled and $borr->{'email'}) {
115 $result->{avatarurl
} = libravatar_url
(email
=> $borr->{'email'}, size
=> 40, https
=> $ENV{HTTPS
});
118 if ($result->{borrowernumber
} eq $borrowernumber) {
119 $result->{your_comment
} = 1;
122 if($format eq "rss"){
123 my $rsstimestamp = eval { dt_from_string
( $result->{datereviewed
} ); };
124 $rsstimestamp = dt_from_string
unless ( $rsstimestamp ); #default to today if something went wrong
125 my $rsstimestamp_output = $rsstimestamp->strftime("%a, %d %b %Y %H:%M:%S %z");
126 $result->{timestamp
} = $rsstimestamp_output;
129 ## Build the page numbers on the bottom of the page
131 my $previous_page_first;
132 my $previous_page_offset;
133 # total number of pages there will be
134 my $pages = ceil
($hits / $results_per_page);
135 # default page number
136 my $current_page_number = 1;
137 $current_page_number = ($offset / $results_per_page + 1) if $offset;
138 if($offset - $results_per_page == 0){
139 $previous_page_first = 1;
140 } elsif ($offset - $results_per_page > 0){
141 $previous_page_offset = $offset - $results_per_page;
143 my $next_page_offset = $offset + $results_per_page;
144 # If we're within the first 10 pages, keep it simple
145 if ($current_page_number < 10) {
146 # just show the first 10 pages
147 # Loop through the pages
148 my $pages_to_show = 10;
149 $pages_to_show = $pages if $pages<10;
150 for ($i=1; $i<=$pages_to_show;$i++) {
151 # the offset for this page
152 my $this_offset = (($i*$results_per_page)-$results_per_page);
153 # the page number for this page
154 my $this_page_number = $i;
155 # it should only be highlighted if it's the current page
157 $highlight = 1 if ($this_page_number == $current_page_number);
158 # put it in the array
159 push @page_numbers, { offset
=> $this_offset, pg
=> $this_page_number, highlight
=> $highlight };
164 # now, show twenty pages, with the current one smack in the middle
166 for ($i=$current_page_number; $i<=($current_page_number + 20 );$i++) {
167 my $this_offset = ((($i-9)*$results_per_page)-$results_per_page);
168 my $this_page_number = $i-9;
170 $highlight = 1 if ($this_page_number == $current_page_number);
171 if ($this_page_number <= $pages) {
172 push @page_numbers, { offset
=> $this_offset, pg
=> $this_page_number, highlight
=> $highlight };
176 $template->param( PAGE_NUMBERS
=> \
@page_numbers,
177 previous_page_first
=> $previous_page_first,
178 previous_page_offset
=> $previous_page_offset) unless $pages < 2;
179 $template->param(next_page_offset
=> $next_page_offset) unless $pages eq $current_page_number;
183 results_per_page
=> $results_per_page,
186 output_html_with_http_headers
$query, $cookie, $template->output;