diff --git a/C4/Letters.pm b/C4/Letters.pm
index 6d33b3f7fe..535e87d363 100644
--- a/C4/Letters.pm
+++ b/C4/Letters.pm
@@ -486,6 +486,7 @@ sub parseletter_sth {
($table eq 'reserves' ) ? "SELECT * FROM $table WHERE borrowernumber = ? and biblionumber = ?" :
($table eq 'borrowers' ) ? "SELECT * FROM $table WHERE borrowernumber = ?" :
($table eq 'branches' ) ? "SELECT * FROM $table WHERE branchcode = ?" :
+ ($table eq 'suggestions' ) ? "SELECT * FROM $table WHERE borrowernumber = ? and biblionumber = ?" :
($table eq 'aqbooksellers') ? "SELECT * FROM $table WHERE id = ?" : undef ;
unless ($query) {
warn "ERROR: No parseletter_sth query for table '$table'";
diff --git a/C4/Suggestions.pm b/C4/Suggestions.pm
index 491739c1f9..b31772f0ee 100644
--- a/C4/Suggestions.pm
+++ b/C4/Suggestions.pm
@@ -20,11 +20,14 @@ package C4::Suggestions;
use strict;
use CGI;
-use Mail::Sendmail;
use C4::Context;
use C4::Output;
use C4::Dates qw(format_date);
+use C4::SQLHelper qw(:all);
+use C4::Debug;
+use C4::Letters;
+use List::MoreUtils qw(any);
use vars qw($VERSION @ISA @EXPORT);
BEGIN {
@@ -39,7 +42,7 @@ BEGIN {
&GetSuggestionByStatus
&DelSuggestion
&CountSuggestion
- &ModStatus
+ &ModSuggestion
&ConnectSuggestionAndBiblio
&GetSuggestionFromBiblionumber
);
@@ -72,7 +75,7 @@ Suggestions done by other borrowers can be seen when not "AVAILABLE"
=head2 SearchSuggestion
-(\@array) = &SearchSuggestion($user,$author,$title,$publishercode,$status,$suggestedbyme,$branchcode)
+(\@array) = &SearchSuggestion($suggestionhashref_to_search)
searches for a suggestion
@@ -85,9 +88,10 @@ Note the status is stored twice :
=cut
sub SearchSuggestion {
- my ($user,$author,$title,$publishercode,$status,$suggestedbyme,$branchcode)=@_;
+ my ($suggestion)=@_;
my $dbh = C4::Context->dbh;
- my $query = "
+ my @sql_params;
+ my @query =(q{
SELECT suggestions.*,
U1.branchcode AS branchcodesuggestedby,
B1.branchname AS branchnamesuggestedby,
@@ -107,62 +111,44 @@ sub SearchSuggestion {
LEFT JOIN categories AS C1 ON C1.categorycode = U1.categorycode
LEFT JOIN branches AS B1 ON B1.branchcode = U1.branchcode
LEFT JOIN branches AS B2 ON B2.branchcode = U2.branchcode
- WHERE 1=1 ";
+ WHERE status NOT IN ('CLAIMED')
+ } , map {
+ if ( my $s = $$suggestion{$_} ) {
+ push @sql_params,'%'.$s.'%';
+ " and suggestions.$_ like ? ";
+ } else { () }
+ } qw( title author isbn publishercode collectiontitle )
+ );
- my @sql_params;
- if ($author) {
- push @sql_params,"%".$author."%";
- $query .= " and author like ?";
+ my $userenv = C4::Context->userenv;
+ if (C4::Context->preference('IndependantBranches')) {
+ if ($userenv) {
+ if (($userenv->{flags} % 2) != 1 && !$$suggestion{branchcode}){
+ push @sql_params,$$userenv{branch};
+ push @query,q{ and (branchcode = ? or branchcode ='')};
+ }
+ }
}
- if ($title) {
- push @sql_params,"%".$title."%";
- $query .= " and suggestions.title like ?";
+
+ foreach my $field (grep { my $fieldname=$_;
+ any {$fieldname eq $_ } qw<
+ status branchcode itemtype suggestedby managedby acceptedby
+ bookfundid biblionumber
+ >} keys %$suggestion
+ ) {
+ if ($$suggestion{$field}){
+ push @sql_params,$$suggestion{$field};
+ push @query, " and suggestions.$field=?";
+ }
+ else {
+ push @query, " and (suggestions.$field='' OR suggestions.$field IS NULL)";
+ }
}
- if ($publishercode) {
- push @sql_params,"%".$publishercode."%";
- $query .= " and publishercode like ?";
- }
- if (C4::Context->preference("IndependantBranches") || $branchcode) {
- my $userenv = C4::Context->userenv;
- if ($userenv) {
- unless ($userenv->{flags} % 2 == 1){
- push @sql_params,$userenv->{branch};
- $query .= " and (U1.branchcode = ? or U1.branchcode ='')";
- }
- }
- if ($branchcode) {
- push @sql_params,$branchcode;
- $query .= " and (U1.branchcode = ? or U1.branchcode ='')";
- }
- }
- if ($status) {
- push @sql_params,$status;
- $query .= " and status=?";
- }
- if ($suggestedbyme) {
- unless ($suggestedbyme eq -1) {
- push @sql_params,$user;
- $query .= " and suggestedby=?";
- }
- } else {
- $query .= " and managedby is NULL";
- }
- my $sth=$dbh->prepare($query);
+
+ $debug && warn "@query";
+ my $sth=$dbh->prepare("@query");
$sth->execute(@sql_params);
- my @results;
- my $even=1; # the even variable is used to set even / odd lines, for highlighting
- while (my $data=$sth->fetchrow_hashref){
- $data->{$data->{STATUS}} = 1;
- if ($even) {
- $even=0;
- $data->{even}=1;
- } else {
- $even=1;
- }
-# $data->{date} = format_date($data->{date});
- push(@results,$data);
- }
- return (\@results);
+ return ($sth->fetchall_arrayref({}));
}
=head2 GetSuggestion
@@ -234,8 +220,8 @@ sub GetSuggestionByStatus {
U1.firstname AS firstnamesuggestedby,
U1.branchcode AS branchcodesuggestedby,
B1.branchname AS branchnamesuggestedby,
- U1.borrowernumber AS borrnumsuggestedby,
- U1.categorycode AS categorycodesuggestedby,
+ U1.borrowernumber AS borrnumsuggestedby,
+ U1.categorycode AS categorycodesuggestedby,
C1.description AS categorydescriptionsuggestedby,
U2.surname AS surnamemanagedby,
U2.firstname AS firstnamemanagedby,
@@ -265,7 +251,6 @@ sub GetSuggestionByStatus {
my $results;
$results= $sth->fetchall_arrayref({});
-# map{$_->{date} = format_date($_->{date})} @$results;
return $results;
}
@@ -335,117 +320,47 @@ sub CountSuggestion {
=head2 NewSuggestion
-&NewSuggestion($borrowernumber,$title,$author,$publishercode,$note,$copyrightdate,$volumedesc,$publicationyear,$place,$isbn,$biblionumber)
+&NewSuggestion($suggestion)
Insert a new suggestion on database with value given on input arg.
=cut
sub NewSuggestion {
- my ($borrowernumber,$title,$author,$publishercode,$note,$copyrightdate,$volumedesc,$publicationyear,$place,$isbn,$biblionumber,$reason) = @_;
- my $dbh = C4::Context->dbh;
- my $query = qq |
- INSERT INTO suggestions
- (status,suggestedby,title,author,publishercode,note,copyrightdate,
- volumedesc,publicationyear,place,isbn,biblionumber,reason)
- VALUES ('ASKED',?,?,?,?,?,?,?,?,?,?,?,?)
- |;
- my $sth = $dbh->prepare($query);
- $sth->execute($borrowernumber,$title,$author,$publishercode,$note,$copyrightdate,$volumedesc,$publicationyear,$place,$isbn,$biblionumber,$reason);
+ my ($suggestion) = @_;
+ return InsertInTable("suggestions",$suggestion);
}
-=head2 ModStatus
+=head2 ModSuggestion
-&ModStatus($suggestionid,$status,$managedby,$biblionumber)
+&ModSuggestion($suggestion)
-Modify the status (status can be 'ASKED', 'ACCEPTED', 'REJECTED', 'ORDERED')
-and send a mail to notify the user that did the suggestion.
+Modify the suggestion according to the hash passed by ref.
+The hash HAS to contain suggestionid
+Data not defined is not updated unless it is a note or sort1
+Send a mail to notify the user that did the suggestion.
-Note that there is no function to modify a suggestion : only the status can be modified, thus the name of the function.
+Note that there is no function to modify a suggestion.
=cut
-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);
+sub ModSuggestion {
+ my ($suggestion)=@_;
+ my $status_update_table=UpdateInTable("suggestions", $suggestion);
+ # check mail sending.
+ if ($$suggestion{STATUS}){
+ my $letter=C4::Letters::getletter('suggestions',$$suggestion{STATUS});
+ if ($letter){
+ my $enqueued = C4::Letters::EnqueueLetter({
+ letter=>$letter,
+ borrowernumber=>$$suggestion{suggestedby},
+ suggestionid=>$$suggestion{suggestionid},
+ msg_transport_type=>'email'
+ });
+ if (!$enqueued){warn "can't enqueue letter $letter";}
}
}
- # 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);
+ return $status_update_table;
}
=head2 ConnectSuggestionAndBiblio
diff --git a/acqui/acqui-home.pl b/acqui/acqui-home.pl
index 339885d370..22ee900b16 100755
--- a/acqui/acqui-home.pl
+++ b/acqui/acqui-home.pl
@@ -111,7 +111,7 @@ for ( my $i = 0 ; $i < $count ; $i++ ) {
# suggestions
my $status = $query->param('status') || "ASKED";
my $suggestion = CountSuggestion($status);
-my $suggestions_loop = &SearchSuggestion( '', '', '', '', $status, '' );
+my $suggestions_loop = &SearchSuggestion( {status=> $status} );
$template->param(
classlist => $classlist,
diff --git a/acqui/newordersuggestion.pl b/acqui/newordersuggestion.pl
index e56e52197d..7d53bc2635 100755
--- a/acqui/newordersuggestion.pl
+++ b/acqui/newordersuggestion.pl
@@ -126,8 +126,12 @@ if ( $op eq 'connectDuplicate' ) {
# getting all suggestions.
my $suggestions_loop =
- &SearchSuggestion( $borrowernumber, $author, $title, $publishercode,'ACCEPTED',
- -1 );
+ &SearchSuggestion(
+ { suggestedby => $borrowernumber,
+ author => $author,
+ title => $title,
+ publishercode => $publishercode,
+ status => 'ACCEPTED'});
my $vendor = GetBookSellerFromId($supplierid);
$template->param(
suggestions_loop => $suggestions_loop,
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tmpl
new file mode 100755
index 0000000000..1784a29b9e
--- /dev/null
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/suggestion.tmpl
@@ -0,0 +1,283 @@
+
Koha Online Catalog ›
+Edit purchase suggestion #Enter a new purchase suggestionSuggestions
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-suggestions.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/opac-suggestions.tmpl
index aaba1eb130..b14bf764c1 100644
--- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-suggestions.tmpl
+++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-suggestions.tmpl
@@ -63,10 +63,20 @@ $.tablesorter.addParser({
+
+
+
+
+
-
+
@@ -101,8 +111,8 @@ $.tablesorter.addParser({