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
28 # use C4::Interface::CGI::Output;
29 use vars qw($VERSION @ISA @EXPORT);
31 # set the version for version checking
36 C4::Accounts - Functions for dealing with Koha authorities
44 The functions in this module deal with the suggestions :
46 * in librarian interface
48 A suggestion is done in the OPAC. It has the status "ASKED"
49 When a librarian manages the suggestion, he can set the status to "REJECTED" or "ORDERED".
50 When a book is ordered and arrived in the library, the status becomes "AVAILABLE"
51 All suggestions of a borrower by the borrower itself.
52 Suggestions done by other can be seen when not "AVAILABLE"
61 @EXPORT = qw( &newsuggestion
69 =item SearchSuggestion
71 (\@array) = &SearchSuggestion($user)
73 searches for a suggestion
75 C<$user> is the user code (used as suggestor filter)
78 C<\@array> : the suggestions found. Array of hash.
79 Note the status is stored twice :
81 * as parameter ( for example ASKED => 1, or REJECTED => 1) . This is for template & translation purposes.
84 sub searchsuggestion {
85 my ($user,$author,$title,$publishercode,$status,$suggestedbyme)=@_;
86 my $dbh = C4::Context->dbh;
87 my $query="Select suggestions.*,
88 U1.surname as surnamesuggestedby,U1.firstname as firstnamesuggestedby,
89 U2.surname as surnamemanagedby,U2.firstname as firstnamemanagedby
91 left join borrowers as U1 on suggestedby=U1.borrowernumber
92 left join borrowers as U2 on managedby=U2.borrowernumber
96 push @sql_params,"%".$author."%";
97 $query .= " and author like ?";
100 push @sql_params,"%".$title."%";
101 $query .= " and suggestions.title like ?";
103 if ($publishercode) {
104 push @sql_params,"%".$publishercode."%";
105 $query .= " and publishercode like ?";
108 push @sql_params,$status;
109 $query .= " and status=?";
111 if ($suggestedbyme) {
112 if ($suggestedbyme eq -1) {
114 push @sql_params,$user;
115 $query .= " and suggestedby=?";
118 $query .= " and managedby is NULL";
120 my $sth=$dbh->prepare($query);
121 $sth->execute(@sql_params);
123 my $even=1; # the even variable is used to set even / odd lines, for highlighting
124 while (my $data=$sth->fetchrow_hashref){
125 $data->{$data->{STATUS}} = 1;
132 push(@results,$data);
138 my ($borrowernumber,$title,$author,$publishercode,$note,$copyrightdate,$volumedesc,$publicationyear,$place,$isbn,$biblionumber) = @_;
139 my $dbh = C4::Context->dbh;
140 my $sth = $dbh->prepare("insert into suggestions (status,suggestedby,title,author,publishercode,note,copyrightdate,volumedesc,publicationyear,place,isbn,biblionumber) values ('ASKED',?,?,?,?,?,?,?,?,?,?,?)");
141 $sth->execute($borrowernumber,$title,$author,$publishercode,$note,$copyrightdate,$volumedesc,$publicationyear,$place,$isbn,$biblionumber);
145 my ($suggestionid) = @_;
146 my $dbh = C4::Context->dbh;
147 my $sth = $dbh->prepare("select * from suggestions where suggestionid=?");
148 $sth->execute($suggestionid);
149 return($sth->fetchrow_hashref);
153 my ($borrowernumber,$suggestionid) = @_;
154 my $dbh = C4::Context->dbh;
155 # check that the suggestion comes from the suggestor
156 my $sth = $dbh->prepare("select suggestedby from suggestions where suggestionid=?");
157 $sth->execute($suggestionid);
158 my ($suggestedby) = $sth->fetchrow;
159 if ($suggestedby eq $borrowernumber) {
160 $sth = $dbh->prepare("delete from suggestions where suggestionid=?");
161 $sth->execute($suggestionid);
165 sub countsuggestion {
167 my $dbh = C4::Context->dbh;
169 if (C4::Context->preference("IndependantBranches")){
170 my $userenv = C4::Context->userenv;
171 warn "IndependantBranches : Count Suggestions : ".$userenv->{branch};
172 $sth = $dbh->prepare("select count(*) from suggestions,borrowers where status=? and borrowers.borrowernumber=suggestions.suggestedby and (borrowers.branchcode='' or borrowers.branchcode =?)");
173 $sth->execute($status,$userenv->{branch});
175 $sth = $dbh->prepare("select count(*) from suggestions where status=?");
176 $sth->execute($status);
178 my ($result) = $sth->fetchrow;
183 my ($suggestionid,$status,$managedby) = @_;
184 my $dbh = C4::Context->dbh;
187 $sth = $dbh->prepare("update suggestions set status=?,managedby=? where suggestionid=?");
188 $sth->execute($status,$managedby,$suggestionid);
190 $sth = $dbh->prepare("update suggestions set status=? where suggestionid=?");
191 $sth->execute($status,$suggestionid);
194 # check mail sending.
195 $sth = $dbh->prepare("select suggestions.*,
196 boby.surname as bysurname, boby.firstname as byfirstname, boby.emailaddress as byemail,
197 lib.surname as libsurname,lib.firstname as libfirstname,lib.emailaddress as libemail
198 from suggestions left join borrowers as boby on boby.borrowernumber=suggestedby left join borrowers as lib on lib.borrowernumber=managedby where suggestionid=?");
199 $sth->execute($suggestionid);
200 my $emailinfo = $sth->fetchrow_hashref;
201 my $template = gettemplate("suggestion/mail_suggestion_$status.tmpl","intranet");
203 # authnotrequired => 1,
205 $template->param(byemail => $emailinfo->{byemail},
206 libemail => $emailinfo->{libemail},
207 status => $emailinfo->{status},
208 title => $emailinfo->{title},
209 author =>$emailinfo->{author},
210 libsurname => $emailinfo->{libsurname},
211 libfirstname => $emailinfo->{libfirstname},
212 byfirstname => $emailinfo->{byfirstname},
213 bysurname => $emailinfo->{bysurname},
215 my %mail = ( To => $emailinfo->{byemail},
216 From => $emailinfo->{libemail},
217 Subject => 'Koha suggestion',
218 Message => "".$template->output
221 # warn "sending email to $emailinfo->{byemail} from $emailinfo->{libemail} to notice new status $emailinfo->{status} for $emailinfo->{title} / $emailinfo->{author}";