# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307 USA
-# $Id$
use strict;
-require Exporter;
+use CGI;
+use Mail::Sendmail;
+
use C4::Context;
use C4::Output;
-use C4::Date;
-use Mail::Sendmail;
+use C4::Dates qw(format_date);
use vars qw($VERSION @ISA @EXPORT);
-# set the version for version checking
-$VERSION = do { my @v = '$Revision$' =~ /\d+/g;
- shift(@v) . "." . join("_", map {sprintf "%03d", $_ } @v); };
+BEGIN {
+ # set the version for version checking
+ $VERSION = 3.01;
+ require Exporter;
+ @ISA = qw(Exporter);
+ @EXPORT = qw(
+ &NewSuggestion
+ &SearchSuggestion
+ &GetSuggestion
+ &GetSuggestionByStatus
+ &DelSuggestion
+ &CountSuggestion
+ &ModStatus
+ &ConnectSuggestionAndBiblio
+ &GetSuggestionFromBiblionumber
+ );
+}
=head1 NAME
=head1 FUNCTIONS
-=cut
-
-@ISA = qw(Exporter);
-@EXPORT = qw(
- &NewSuggestion
- &SearchSuggestion
- &GetSuggestion
- &GetSuggestionByStatus
- &DelSuggestion
- &CountSuggestion
- &ModStatus
- &ConnectSuggestionAndBiblio
- &GetSuggestionFromBiblionumber
- );
-
=head2 SearchSuggestion
-(\@array) = &SearchSuggestion($user,$author,$title,$publishercode,$status,$suggestedbyme)
+(\@array) = &SearchSuggestion($user,$author,$title,$publishercode,$status,$suggestedbyme,$branchcode)
searches for a suggestion
=cut
sub SearchSuggestion {
- my ($user,$author,$title,$publishercode,$status,$suggestedbyme)=@_;
+ my ($user,$author,$title,$publishercode,$status,$suggestedbyme,$branchcode)=@_;
my $dbh = C4::Context->dbh;
my $query = "
SELECT suggestions.*,
+ U1.branchcode AS branchcodesuggestedby,
U1.surname AS surnamesuggestedby,
U1.firstname AS firstnamesuggestedby,
+ U1.borrowernumber AS borrnumsuggestedby,
+ U1.categorycode AS categorycodesuggestedby,
+ U2.branchcode AS branchcodemanagedby,
U2.surname AS surnamemanagedby,
- U2.firstname AS firstnamemanagedby
+ U2.firstname AS firstnamemanagedby,
+ U2.borrowernumber AS borrnummanagedby
FROM suggestions
LEFT JOIN borrowers AS U1 ON suggestedby=U1.borrowernumber
LEFT JOIN borrowers AS U2 ON managedby=U2.borrowernumber
push @sql_params,"%".$publishercode."%";
$query .= " and publishercode like ?";
}
- if (C4::Context->preference("IndependantBranches")) {
+ if (C4::Context->preference("IndependantBranches") || $branchcode) {
my $userenv = C4::Context->userenv;
if ($userenv) {
unless ($userenv->{flags} == 1){
$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;
} else {
$even=1;
}
+# $data->{date} = format_date($data->{date});
push(@results,$data);
}
return (\@results);
=head2 GetSuggestionByStatus
-$suggestions = &GetSuggestionByStatus($status)
+$suggestions = &GetSuggestionByStatus($status,[$branchcode])
Get a suggestion from it's status
sub GetSuggestionByStatus {
my $status = shift;
+ my $branchcode = shift;
my $dbh = C4::Context->dbh;
- my $query = "SELECT suggestions.*,
+ my @sql_params=($status);
+ my $query = qq(SELECT suggestions.*,
U1.surname AS surnamesuggestedby,
U1.firstname AS firstnamesuggestedby,
+ U1.branchcode AS branchcodesuggestedby,
+ U1.borrowernumber AS borrnumsuggestedby,
+ U1.categorycode AS categorycodesuggestedby,
U2.surname AS surnamemanagedby,
- U2.firstname AS firstnamemanagedby
+ U2.firstname AS firstnamemanagedby,
+ U2.borrowernumber AS borrnummanagedby
FROM suggestions
LEFT JOIN borrowers AS U1 ON suggestedby=U1.borrowernumber
LEFT JOIN borrowers AS U2 ON managedby=U2.borrowernumber
- WHERE status = ?
- ";
+ WHERE status = ?);
+ if (C4::Context->preference("IndependantBranches") || $branchcode) {
+ my $userenv = C4::Context->userenv;
+ if ($userenv) {
+ unless ($userenv->{flags} == 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 ='')";
+ }
+ }
+
my $sth = $dbh->prepare($query);
- $sth->execute($status);
+ $sth->execute(@sql_params);
- my @results;
- while(my $data = $sth->fetchrow_hashref){
- $data->{date} = format_date($data->{date});
- push @results,$data;
- }
- return \@results;
+ my $results;
+ $results= $sth->fetchall_arrayref({});
+# map{$_->{date} = format_date($_->{date})} @$results;
+ return $results;
}
=head2 CountSuggestion
else {
my $query = qq |
SELECT count(*)
- FROM suggestions,borrowers
+ FROM suggestions LEFT JOIN borrowers ON borrowers.borrowernumber=suggestions.suggestedby
WHERE status=?
- AND borrowers.borrowernumber=suggestions.suggestedby
AND (borrowers.branchcode='' OR borrowers.branchcode =?)
|;
$sth = $dbh->prepare($query);
$sth = $dbh->prepare($queryMail);
$sth->execute($suggestionid);
my $emailinfo = $sth->fetchrow_hashref;
- my $template = gettemplate("suggestion/mail_suggestion_$status.tmpl","intranet");
+ my $template = gettemplate("suggestion/mail_suggestion_$status.tmpl", "intranet", CGI->new());
$template->param(
byemail => $emailinfo->{byemail},
To => $emailinfo->{byemail},
From => $emailinfo->{libemail},
Subject => 'Koha suggestion',
- Message => "".$template->output
+ Message => "".$template->output,
+ 'Content-Type' => 'text/plain; charset="utf8"',
);
sendmail(%mail);
}
=cut
sub DelSuggestion {
- my ($borrowernumber,$suggestionid) = @_;
+ my ($borrowernumber,$suggestionid,$type) = @_;
my $dbh = C4::Context->dbh;
# check that the suggestion comes from the suggestor
my $query = "
my $sth = $dbh->prepare($query);
$sth->execute($suggestionid);
my ($suggestedby) = $sth->fetchrow;
- if ($suggestedby eq $borrowernumber) {
+ if ($type eq "intranet" || $suggestedby eq $borrowernumber ) {
my $queryDelete = "
DELETE FROM suggestions
WHERE suggestionid=?
";
$sth = $dbh->prepare($queryDelete);
- $sth->execute($suggestionid);
+ my $suggestiondeleted=$sth->execute($suggestionid);
+ return $suggestiondeleted;
}
}