opac.css - button background fix for input.icon
[koha.git] / C4 / Review.pm
1 package C4::Review;
2
3 # Copyright 2000-2002 Katipo Communications
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA  02111-1307 USA
19
20 use strict;
21 use C4::Context;
22
23 use vars qw($VERSION @ISA @EXPORT);
24
25 BEGIN {
26         # set the version for version checking
27         $VERSION = 3.00;
28         require Exporter;
29         @ISA    = qw(Exporter);
30         @EXPORT = qw(getreview savereview updatereview numberofreviews
31                 getreviews getallreviews approvereview deletereview);
32 }
33
34 =head1 NAME
35
36 C4::Review - Perl Module containing routines for dealing with reviews of items
37
38 =head1 SYNOPSIS
39
40   use C4::Review;
41
42   my $review=getreview($biblionumber,$borrowernumber);
43   savereview($biblionumber,$borrowernumber,$review);
44   updatereview($biblionumber,$borrowernumber,$review);
45   my $count=numberofreviews($biblionumber);
46   my $reviews=getreviews($biblionumber);
47   my $reviews=getallreviews($status);
48
49 =head1 DESCRIPTION
50
51 Review.pm provides many routines for manipulating reviews.
52
53 =head1 FUNCTIONS
54
55 =head2 getreview
56
57   $review = getreview($biblionumber,$borrowernumber);
58
59 Takes a borrowernumber and a biblionumber and returns the review of that biblio
60
61 =cut
62
63 sub getreview {
64     my ( $biblionumber, $borrowernumber ) = @_;
65     my $dbh   = C4::Context->dbh;
66     my $query =
67       "SELECT * FROM reviews WHERE biblionumber=? and borrowernumber=?";
68     my $sth = $dbh->prepare($query);
69     $sth->execute( $biblionumber, $borrowernumber );
70     my $review = $sth->fetchrow_hashref();
71     $sth->finish();
72     return $review;
73 }
74
75 sub savereview {
76     my ( $biblionumber, $borrowernumber, $review ) = @_;
77     my $dbh   = C4::Context->dbh;
78     my $query = "INSERT INTO reviews (borrowernumber,biblionumber,
79         review,approved,datereviewed) VALUES 
80   (?,?,?,0,now())";
81     my $sth = $dbh->prepare($query);
82     $sth->execute( $borrowernumber, $biblionumber, $review);
83     $sth->finish();
84 }
85
86 sub updatereview {
87     my ( $biblionumber, $borrowernumber, $review ) = @_;
88     my $dbh   = C4::Context->dbh;
89     my $query = "UPDATE reviews SET review=?,datereviewed=now(),approved=0  WHERE borrowernumber=? and biblionumber=?";
90     my $sth = $dbh->prepare($query);
91     $sth->execute( $review, $borrowernumber, $biblionumber );
92     $sth->finish();
93 }
94
95 sub numberofreviews {
96     my ($biblionumber) = @_;
97     my $dbh            = C4::Context->dbh;
98     my $query          =
99       "SELECT count(*) FROM reviews WHERE biblionumber=? and approved=?";
100     my $sth = $dbh->prepare($query);
101     $sth->execute( $biblionumber, 1 );
102     my $count = $sth->fetchrow_hashref;
103
104     $sth->finish();
105     return ( $count->{'count(*)'} );
106 }
107
108 sub getreviews {
109     my ( $biblionumber, $approved ) = @_;
110     my $dbh   = C4::Context->dbh;
111     my $query =
112 "SELECT * FROM reviews WHERE biblionumber=? and approved=? order by datereviewed desc";
113     my $sth = $dbh->prepare($query) || warn $dbh->err_str;
114     $sth->execute( $biblionumber, $approved );
115     my @results;
116     while ( my $data = $sth->fetchrow_hashref() ) {
117         push @results, $data;
118     }
119     $sth->finish();
120     return ( \@results );
121 }
122
123 sub getallreviews {
124     my ($status) = @_;
125     my $dbh      = C4::Context->dbh;
126     my $query    =
127       "SELECT * FROM reviews WHERE approved=? order by datereviewed desc";
128     my $sth = $dbh->prepare($query);
129     $sth->execute($status);
130     my @results;
131     while ( my $data = $sth->fetchrow_hashref() ) {
132         push @results, $data;
133     }
134     $sth->finish();
135     return ( \@results );
136 }
137
138 =head2 approvereview
139
140   approvereview($reviewid);
141
142 Takes a reviewid and marks that review approved
143
144 =cut
145
146 sub approvereview {
147     my ($reviewid) = @_;
148     my $dbh        = C4::Context->dbh();
149     my $query      = "UPDATE reviews
150                SET approved=?
151                WHERE reviewid=?";
152     my $sth = $dbh->prepare($query);
153     $sth->execute( 1, $reviewid );
154     $sth->finish();
155 }
156
157 =head2 deletereview
158
159   deletereview($reviewid);
160
161 Takes a reviewid and deletes it
162
163 =cut
164
165 sub deletereview {
166     my ($reviewid) = @_;
167     my $dbh        = C4::Context->dbh();
168     my $query      = "DELETE FROM reviews
169                WHERE reviewid=?";
170     my $sth = $dbh->prepare($query);
171     $sth->execute($reviewid);
172     $sth->finish();
173 }
174
175 1;
176 __END__
177
178 =head1 AUTHOR
179
180 Koha Team
181
182 =cut