Bug 14868: Swagger2-driven Permission checking
[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 strict;
19 use warnings;
20
21 use CGI qw ( -utf8 );
22 use C4::Auth;
23 use C4::Output;
24 use C4::Context;
25 use C4::Review;
26 use C4::Members;
27 use C4::Biblio;
28
29 my $query = new CGI;
30 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
31     {
32         template_name   => "reviews/reviewswaiting.tt",
33         query           => $query,
34         type            => "intranet",
35         authnotrequired => 0,
36         flagsrequired   => { tools => 'moderate_comments' },
37         debug           => 1,
38     }
39 );
40
41 my $op       = $query->param('op') || '';
42 my $status   = $query->param('status') || 0;
43 my $reviewid = $query->param('reviewid');
44 my $page     = $query->param('page') || 1;
45 my $count    = C4::Context->preference('numSearchResults') || 20;
46 my $offset   = ($page-1) * $count;
47 my $total    = numberofreviews($status);
48
49 if ( $op eq 'approve' ) {
50     approvereview($reviewid);
51 }
52 elsif ( $op eq 'unapprove' ) {
53     unapprovereview($reviewid);
54 }
55 elsif ( $op eq 'delete' ) {
56     deletereview($reviewid);
57 }
58
59 my $reviews = getallreviews($status,$offset,$count);
60
61 foreach ( @$reviews ) {
62     my $borrowernumber = $_->{borrowernumber};
63     my $borrowerData   = GetMember('borrowernumber' => $borrowernumber);
64     my $biblioData     = GetBiblioData($_->{biblionumber});
65     # setting some borrower info into this hash
66     $_->{bibliotitle} = $biblioData->{'title'};
67     $_->{surname}     = $borrowerData->{'surname'};
68     $_->{firstname}   = $borrowerData->{'firstname'};
69 }
70
71 my $url = "/cgi-bin/koha/reviews/reviewswaiting.pl?status=$status";
72
73 $template->param(
74     status => $status,
75     reviews => $reviews,
76     pagination_bar => pagination_bar( $url, ( int( $total / $count ) ) + ( ( $total % $count ) > 0 ? 1 : 0 ), $page, "page" )
77 );
78
79 output_html_with_http_headers $query, $cookie, $template->output;