=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.branchcode AS branchcodesuggestedby,
U2.surname AS surnamemanagedby,
U2.firstname AS firstnamemanagedby,
U2.borrowernumber AS borrnummanagedby
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){
+ 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;
} 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,
U2.surname AS surnamemanagedby,
U2.firstname AS firstnamemanagedby,
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} % 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 ='')";
+ }
+ }
+
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
my $sth;
if (C4::Context->preference("IndependantBranches")){
my $userenv = C4::Context->userenv;
- if ($userenv->{flags} == 1){
+ if ($userenv->{flags} % 2 == 1){
my $query = qq |
SELECT count(*)
FROM suggestions
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);
+ if ($title) {
+ 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);
+ }
}
=head2 ModStatus
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;
}
}