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
27 # use C4::Interface::CGI::Output;
28 use vars qw($VERSION @ISA @EXPORT);
30 # set the version for version checking
35 C4::Accounts - Functions for dealing with Koha authorities
43 The functions in this module deal with the suggestions :
45 * in librarian interface
47 A suggestion is done in the OPAC. It has the status "ASKED"
48 When a librarian manages the suggestion, he can set the status to "REJECTED" or "ORDERED".
49 When a book is ordered and arrived in the library, the status becomes "AVAILABLE"
50 All suggestions of a borrower by the borrower itself.
51 Suggestions done by other can be seen when not "AVAILABLE"
60 @EXPORT = qw( &newsuggestion
68 =item SearchSuggestion
70 (\@array) = &SearchSuggestion($user)
72 searches for a suggestion
74 C<$user> is the user code (used as suggestor filter)
77 C<\@array> : the suggestions found. Array of hash.
78 Note the status is stored twice :
80 * as parameter ( for example ASKED => 1, or REJECTED => 1) . This is for template & translation purposes.
83 sub searchsuggestion {
84 my ($user,$author,$title,$publishercode,$status,$suggestedbyme)=@_;
85 my $dbh = C4::Context->dbh;
86 my $query="Select suggestions.*,
87 U1.surname as surnamesuggestedby,U1.firstname as firstnamesuggestedby,
88 U2.surname as surnamemanagedby,U2.firstname as firstnamemanagedby
90 left join borrowers as U1 on suggestedby=U1.borrowernumber
91 left join borrowers as U2 on managedby=U2.borrowernumber
95 push @sql_params,"%".$author."%";
96 $query .= " and author like ?";
99 push @sql_params,"%".$title."%";
100 $query .= " and suggestions.title like ?";
102 if ($publishercode) {
103 push @sql_params,"%".$publishercode."%";
104 $query .= " and publishercode like ?";
107 push @sql_params,$status;
108 $query .= " and status=?";
110 if ($suggestedbyme) {
111 push @sql_params,$user;
112 $query .= " and suggestedby=?";
114 $query .= " and managedby is NULL";
116 my $sth=$dbh->prepare($query);
117 $sth->execute(@sql_params);
119 my $even=1; # the even variable is used to set even / odd lines, for highlighting
120 while (my $data=$sth->fetchrow_hashref){
121 $data->{$data->{STATUS}} = 1;
128 push(@results,$data);
134 my ($borrowernumber,$title,$author,$publishercode,$note,$copyrightdate,$volumedesc,$publicationyear,$place,$isbn,$biblionumber) = @_;
135 my $dbh = C4::Context->dbh;
136 my $sth = $dbh->prepare("insert into suggestions (status,suggestedby,title,author,publishercode,note,copyrightdate,volumedesc,publicationyear,place,isbn,biblionumber) values ('ASKED',?,?,?,?,?,?,?,?,?,?,?)");
137 $sth->execute($borrowernumber,$title,$author,$publishercode,$note,$copyrightdate,$volumedesc,$publicationyear,$place,$isbn,$biblionumber);
141 my ($suggestionid) = @_;
142 my $dbh = C4::Context->dbh;
143 my $sth = $dbh->prepare("select * from suggestions where suggestionid=?");
144 $sth->execute($suggestionid);
145 return($sth->fetchrow_hashref);
149 my ($borrowernumber,$suggestionid) = @_;
150 my $dbh = C4::Context->dbh;
151 # check that the suggestion comes from the suggestor
152 my $sth = $dbh->prepare("select suggestedby from suggestions where suggestionid=?");
153 $sth->execute($suggestionid);
154 my ($suggestedby) = $sth->fetchrow;
155 if ($suggestedby eq $borrowernumber) {
156 $sth = $dbh->prepare("delete from suggestions where suggestionid=?");
157 $sth->execute($suggestionid);
161 sub countsuggestion {
163 my $dbh = C4::Context->dbh;
164 my $sth = $dbh->prepare("select count(*) from suggestions where status=?");
165 $sth->execute($status);
166 my ($result) = $sth->fetchrow;
171 my ($suggestionid,$status,$managedby) = @_;
172 my $dbh = C4::Context->dbh;
175 $sth = $dbh->prepare("update suggestions set status=?,managedby=? where suggestionid=?");
176 $sth->execute($status,$managedby,$suggestionid);
178 $sth = $dbh->prepare("update suggestions set status=? where suggestionid=?");
179 $sth->execute($status,$suggestionid);
182 # check mail sending.
183 $sth = $dbh->prepare("select suggestions.*,
184 boby.surname as bysurname, boby.firstname as byfirstname, boby.emailaddress as byemail,
185 lib.surname as libsurname,lib.firstname as libfirstname,lib.emailaddress as libemail
186 from suggestions left join borrowers as boby on boby.borrowernumber=suggestedby left join borrowers as lib on lib.borrowernumber=managedby where suggestionid=?");
187 $sth->execute($suggestionid);
188 my $emailinfo = $sth->fetchrow_hashref;
189 my $template = gettemplate("suggestion/mail_suggestion_$status.tmpl","intranet");
191 # authnotrequired => 1,
193 $template->param(byemail => $emailinfo->{byemail},
194 libemail => $emailinfo->{libemail},
195 status => $emailinfo->{status},
196 title => $emailinfo->{title},
197 author =>$emailinfo->{author},
198 libsurname => $emailinfo->{libsurname},
199 libfirstname => $emailinfo->{libfirstname},
200 byfirstname => $emailinfo->{byfirstname},
201 bysurname => $emailinfo->{bysurname},
203 warn "mailing => ".$template->output;
204 # warn "sending email to $emailinfo->{byemail} from $emailinfo->{libemail} to notice new status $emailinfo->{status} for $emailinfo->{title} / $emailinfo->{author}";