Merge remote-tracking branch 'origin/new/bug_6880'
[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 under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
8 # version.
9 #
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA  02111-1307 USA
17
18 use strict;
19 use warnings;
20
21 use CGI;
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.tmpl",
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 $offset   = $query->param('offset') || 0;
45 my $count    = C4::Context->preference('numSearchResults') || 20;
46 my $total    = numberofreviews($status);
47
48 if ( $op eq 'approve' ) {
49     approvereview($reviewid);
50 }
51 elsif ( $op eq 'unapprove' ) {
52     unapprovereview($reviewid);
53 }
54 elsif ( $op eq 'delete' ) {
55     deletereview($reviewid);
56 }
57
58 my $reviews = getallreviews($status,$offset,$count);
59
60 foreach ( @$reviews ) {
61     my $borrowernumber = $_->{borrowernumber};
62     my $borrowerData   = GetMember('borrowernumber' => $borrowernumber);
63     my $biblioData     = GetBiblioData($_->{biblionumber});
64     # setting some borrower info into this hash
65     $_->{bibliotitle} = $biblioData->{'title'};
66     $_->{surname}     = $borrowerData->{'surname'};
67     $_->{firstname}   = $borrowerData->{'firstname'};
68 }
69
70 my $url = "/cgi-bin/koha/reviews/reviewswaiting.pl?status=$status";
71
72 $template->param(
73     status => $status,
74     reviews => $reviews,
75     pagination_bar => pagination_bar( $url, ( int( $total / $count ) ) + ( ( $total % $count ) > 0 ? 1 : 0 ), $offset, "offset" )
76 );
77
78 output_html_with_http_headers $query, $cookie, $template->output;