1 package C4::Suggestions;
5 # Copyright 2000-2002 Katipo Communications
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License along with
19 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
20 # Suite 330, Boston, MA 02111-1307 USA
26 use vars qw($VERSION @ISA @EXPORT);
28 # set the version for version checking
33 C4::Accounts - Functions for dealing with Koha authorities
41 The functions in this module deal with the suggestions :
43 * in librarian interface
45 A suggestion is done in the OPAC. It has the status "ASKED"
46 When a librarian manages the suggestion, he can set the status to "REJECTED" or "ORDERED".
47 When a book is ordered and arrived in the library, the status becomes "AVAILABLE"
48 All suggestions of a borrower by the borrower itself.
49 Suggestions done by other can be seen when not "AVAILABLE"
58 @EXPORT = qw( &newsuggestion
63 =item SearchSuggestion
65 (\@array) = &SearchSuggestion($user)
67 searches for a suggestion
69 C<$user> is the user code (used as suggestor filter)
72 C<\@array> : the suggestions found. Array of hash.
73 Note the status is stored twice :
75 * as parameter ( for example ASKED => 1, or REJECTED => 1) . This is for template & translation purposes.
78 sub searchsuggestion {
79 my ($user,$author,$title,$publishercode,$status,$suggestedbyme)=@_;
80 my $dbh = C4::Context->dbh;
81 my $query="Select suggestions.*,
82 U1.surname as surnamesuggestedby,U1.firstname as firstnamesuggestedby,
83 U2.surname as surnamemanagedby,U2.firstname as firstnamemanagedby
84 from suggestions,borrowers as U1
85 left join borrowers as U2 on managedby=U2.borrowernumber
86 where suggestedby=U1.borrowernumber";
89 push @sql_params,"%".$author."%";
90 $query .= " and author like ?";
93 push @sql_params,"%".$title."%";
94 $query .= " and suggestions.title like ?";
97 push @sql_params,"%".$publishercode."%";
98 $query .= " and publishercode like ?";
101 push @sql_params,$status;
102 $query .= " and status=?";
104 if ($suggestedbyme) {
105 push @sql_params,$user;
106 $query .= " and suggestedby=?";
108 $query .= " and managedby is NULL";
110 my $sth=$dbh->prepare($query);
111 $sth->execute(@sql_params);
113 my $even=1; # the even variable is used to set even / odd lines, for highlighting
114 while (my $data=$sth->fetchrow_hashref){
115 $data->{$data->{status}} = 1;
122 push(@results,$data);
128 my ($borrowernumber,$title,$author,$publishercode,$note) = @_;
129 my $dbh = C4::Context->dbh;
130 my $sth = $dbh->prepare("insert into suggestions (suggestedby,title,author,publishercode,note) values (?,?,?,?,?)");
131 $sth->execute($borrowernumber,$title,$author,$publishercode,$note);
135 my ($borrowernumber,$suggestionnumber) = @_;
136 my $dbh = C4::Context->dbh;
137 # check that the suggestion comes from the suggestor
138 my $sth = $dbh->prepare("select suggestedby from suggestions where suggestionnumber=?");
139 $sth->execute($suggestionnumber);
140 my ($suggestedby) = $sth->fetchrow;
141 if ($suggestedby eq $borrowernumber) {
142 $sth = $dbh->prepare("delete from suggestions where suggestionnumber=?");
143 $sth->execute($suggestionnumber);