Bug 17600: Standardize our EXPORT_OK
[koha.git] / reviews / reviewswaiting.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18 use Modern::Perl;
19
20 use CGI qw ( -utf8 );
21 use C4::Auth qw( get_template_and_user );
22 use C4::Output qw( pagination_bar output_html_with_http_headers );
23 use C4::Context;
24 use Koha::Biblios;
25 use Koha::Patrons;
26 use Koha::Reviews;
27
28 my $query = CGI->new;
29 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
30     {
31         template_name   => "reviews/reviewswaiting.tt",
32         query           => $query,
33         type            => "intranet",
34         flagsrequired   => { tools => 'moderate_comments' },
35     }
36 );
37
38 my $op       = $query->param('op') || '';
39 my $status   = $query->param('status') || 0;
40 my $reviewid = $query->param('reviewid');
41 my $page     = $query->param('page') || 1;
42 my $count    = C4::Context->preference('numSearchResults') || 20;
43 my $total    = Koha::Reviews->search_limited({ approved => $status })->count;
44
45 if ( $op eq 'approve' ) {
46     my $review = Koha::Reviews->find( $reviewid );
47     $review->approve if $review;
48 }
49 elsif ( $op eq 'unapprove' ) {
50     my $review = Koha::Reviews->find( $reviewid );
51     $review->unapprove if $review;
52 }
53 elsif ( $op eq 'delete' ) {
54     my $review = Koha::Reviews->find( $reviewid );
55     $review->delete if $review;
56 }
57
58 my $reviews = Koha::Reviews->search_limited(
59     { approved => $status },
60     {
61         rows => $count,
62         page => $page,
63         order_by => { -desc => 'datereviewed' },
64     }
65 )->unblessed;
66
67 for my $review ( @$reviews ) {
68     my $biblio         = Koha::Biblios->find( $review->{biblionumber} );
69     # setting some borrower info into this hash
70     $review->{bibliotitle} = $biblio->title;
71
72     my $borrowernumber = $review->{borrowernumber};
73     my $patron = Koha::Patrons->find( $borrowernumber);
74     if ( $patron ) {
75         $review->{patron} = $patron;
76     }
77 }
78
79 my $url = "/cgi-bin/koha/reviews/reviewswaiting.pl?status=$status";
80
81 $template->param(
82     status => $status,
83     reviews => $reviews,
84     pagination_bar => pagination_bar( $url, ( int( $total / $count ) ) + ( ( $total % $count ) > 0 ? 1 : 0 ), $page, "page" )
85 );
86
87 output_html_with_http_headers $query, $cookie, $template->output;