+
+sub ModStatus {
+ my ($suggestionid,$status,$managedby,$biblionumber,$reason) = @_;
+ my $dbh = C4::Context->dbh;
+ my $sth;
+ if ($managedby>0) {
+ if ($biblionumber) {
+ my $query = qq|
+ UPDATE suggestions
+ SET status=?,managedby=?,biblionumber=?,reason=?
+ WHERE suggestionid=?
+ |;
+ $sth = $dbh->prepare($query);
+ $sth->execute($status,$managedby,$biblionumber,$reason,$suggestionid);
+ } else {
+ my $query = qq|
+ UPDATE suggestions
+ SET status=?,managedby=?,reason=?
+ WHERE suggestionid=?
+ |;
+ $sth = $dbh->prepare($query);
+ $sth->execute($status,$managedby,$reason,$suggestionid);
+ }
+ } else {
+ if ($biblionumber) {
+ my $query = qq|
+ UPDATE suggestions
+ SET status=?,biblionumber=?,reason=?
+ WHERE suggestionid=?
+ |;
+ $sth = $dbh->prepare($query);
+ $sth->execute($status,$biblionumber,$reason,$suggestionid);
+ }
+ else {
+ my $query = qq|
+ UPDATE suggestions
+ SET status=?,reason=?
+ WHERE suggestionid=?
+ |;
+ $sth = $dbh->prepare($query);
+ $sth->execute($status,$reason,$suggestionid);
+ }
+ }
+ # check mail sending.
+ my $queryMail = "
+ SELECT suggestions.*,
+ boby.surname AS bysurname,
+ boby.firstname AS byfirstname,
+ boby.email AS byemail,
+ lib.surname AS libsurname,
+ lib.firstname AS libfirstname,
+ lib.email AS libemail
+ FROM suggestions
+ LEFT JOIN borrowers AS boby ON boby.borrowernumber=suggestedby
+ LEFT JOIN borrowers AS lib ON lib.borrowernumber=managedby
+ WHERE suggestionid=?
+ ";
+ $sth = $dbh->prepare($queryMail);
+ $sth->execute($suggestionid);
+ my $emailinfo = $sth->fetchrow_hashref;
+ my $template = gettemplate("suggestion/mail_suggestion_$status.tmpl", "intranet", CGI->new());
+
+ $template->param(
+ byemail => $emailinfo->{byemail},
+ libemail => $emailinfo->{libemail},
+ status => $emailinfo->{status},
+ title => $emailinfo->{title},
+ author =>$emailinfo->{author},
+ libsurname => $emailinfo->{libsurname},
+ libfirstname => $emailinfo->{libfirstname},
+ byfirstname => $emailinfo->{byfirstname},
+ bysurname => $emailinfo->{bysurname},
+ reason => $emailinfo->{reason}
+ );
+ my %mail = (
+ To => $emailinfo->{byemail},
+ From => $emailinfo->{libemail},
+ Subject => 'Koha suggestion',
+ Message => "".$template->output,
+ 'Content-Type' => 'text/plain; charset="utf8"',
+ );
+ sendmail(%mail);
+}
+
+=head2 ConnectSuggestionAndBiblio
+
+&ConnectSuggestionAndBiblio($suggestionid,$biblionumber)
+
+connect a suggestion to an existing biblio
+
+=cut
+
+sub ConnectSuggestionAndBiblio {
+ my ($suggestionid,$biblionumber) = @_;
+ my $dbh=C4::Context->dbh;
+ my $query = "
+ UPDATE suggestions
+ SET biblionumber=?
+ WHERE suggestionid=?
+ ";
+ my $sth = $dbh->prepare($query);
+ $sth->execute($biblionumber,$suggestionid);
+}
+
+=head2 DelSuggestion
+
+&DelSuggestion($borrowernumber,$suggestionid)
+
+Delete a suggestion. A borrower can delete a suggestion only if he is its owner.
+
+=cut
+
+sub DelSuggestion {
+ my ($borrowernumber,$suggestionid,$type) = @_;
+ my $dbh = C4::Context->dbh;
+ # check that the suggestion comes from the suggestor
+ my $query = "
+ SELECT suggestedby
+ FROM suggestions
+ WHERE suggestionid=?
+ ";
+ my $sth = $dbh->prepare($query);
+ $sth->execute($suggestionid);
+ my ($suggestedby) = $sth->fetchrow;
+ if ($type eq "intranet" || $suggestedby eq $borrowernumber ) {
+ my $queryDelete = "
+ DELETE FROM suggestions
+ WHERE suggestionid=?
+ ";
+ $sth = $dbh->prepare($queryDelete);
+ my $suggestiondeleted=$sth->execute($suggestionid);
+ return $suggestiondeleted;
+ }
+}
+
+1;
+__END__
+
+
+=head1 AUTHOR
+
+Koha Developement team <info@koha.org>
+
+=cut
+