99a0d3f58766254abd01d24b1cfcc7f865d56a03
[srvgit] / 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;
22 use C4::Output;
23 use C4::Context;
24 use C4::Biblio;
25 use Koha::Biblios;
26 use Koha::Patrons;
27 use Koha::Reviews;
28
29 my $query = CGI->new;
30 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
31     {
32         template_name   => "reviews/reviewswaiting.tt",
33         query           => $query,
34         type            => "intranet",
35         flagsrequired   => { tools => 'moderate_comments' },
36     }
37 );
38
39 my $op       = $query->param('op') || '';
40 my $status   = $query->param('status') || 0;
41 my $reviewid = $query->param('reviewid');
42 my $page     = $query->param('page') || 1;
43 my $count    = C4::Context->preference('numSearchResults') || 20;
44 my $total    = Koha::Reviews->search_limited({ approved => $status })->count;
45
46 if ( $op eq 'approve' ) {
47     my $review = Koha::Reviews->find( $reviewid );
48     $review->approve if $review;
49 }
50 elsif ( $op eq 'unapprove' ) {
51     my $review = Koha::Reviews->find( $reviewid );
52     $review->unapprove if $review;
53 }
54 elsif ( $op eq 'delete' ) {
55     my $review = Koha::Reviews->find( $reviewid );
56     $review->delete if $review;
57 }
58
59 my $reviews = Koha::Reviews->search_limited(
60     { approved => $status },
61     {
62         rows => $count,
63         page => $page,
64         order_by => { -desc => 'datereviewed' },
65     }
66 )->unblessed;
67
68 for my $review ( @$reviews ) {
69     my $biblio         = Koha::Biblios->find( $review->{biblionumber} );
70     # setting some borrower info into this hash
71     $review->{bibliotitle} = $biblio->title;
72
73     my $borrowernumber = $review->{borrowernumber};
74     my $patron = Koha::Patrons->find( $borrowernumber);
75     if ( $patron ) {
76         $review->{patron} = $patron;
77     }
78 }
79
80 my $url = "/cgi-bin/koha/reviews/reviewswaiting.pl?status=$status";
81
82 $template->param(
83     status => $status,
84     reviews => $reviews,
85     pagination_bar => pagination_bar( $url, ( int( $total / $count ) ) + ( ( $total % $count ) > 0 ? 1 : 0 ), $page, "page" )
86 );
87
88 output_html_with_http_headers $query, $cookie, $template->output;