From 5e9465a14a5dabb928d50d207475b1fd96247bbc Mon Sep 17 00:00:00 2001 From: Henri-Damien LAURENT Date: Tue, 15 Apr 2008 19:19:18 +0200 Subject: [PATCH] Accept or reject : Bug Fix and improvements. Improving workflow : A suggestion can be edited and status can be changed if mistaken as soon as it is not deleted or acquired. Adding dates display. Adding deletion of suggestions. Signed-off-by: Joshua Ferraro --- C4/Suggestions.pm | 53 ++-- .../en/modules/suggestion/acceptorreject.tmpl | 246 +++++++++++------- suggestion/acceptorreject.pl | 84 +++--- 3 files changed, 244 insertions(+), 139 deletions(-) diff --git a/C4/Suggestions.pm b/C4/Suggestions.pm index afb548d519..4250db06f7 100644 --- a/C4/Suggestions.pm +++ b/C4/Suggestions.pm @@ -72,7 +72,7 @@ Suggestions done by other borrowers can be seen when not "AVAILABLE" =head2 SearchSuggestion -(\@array) = &SearchSuggestion($user,$author,$title,$publishercode,$status,$suggestedbyme) +(\@array) = &SearchSuggestion($user,$author,$title,$publishercode,$status,$suggestedbyme,$branchcode) searches for a suggestion @@ -85,7 +85,7 @@ Note the status is stored twice : =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.*, @@ -113,7 +113,7 @@ sub SearchSuggestion { 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){ @@ -121,6 +121,10 @@ sub SearchSuggestion { $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; @@ -146,6 +150,7 @@ sub SearchSuggestion { } else { $even=1; } +# $data->{date} = format_date($data->{date}); push(@results,$data); } return (\@results); @@ -201,7 +206,7 @@ sub GetSuggestionFromBiblionumber { =head2 GetSuggestionByStatus -$suggestions = &GetSuggestionByStatus($status) +$suggestions = &GetSuggestionByStatus($status,[$branchcode]) Get a suggestion from it's status @@ -212,8 +217,10 @@ all the suggestion with C<$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.borrowernumber AS borrnumsuggestedby, @@ -223,17 +230,28 @@ sub GetSuggestionByStatus { 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 @@ -443,7 +461,7 @@ Delete a suggestion. A borrower can delete a suggestion only if he is its owner. =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 = " @@ -454,13 +472,14 @@ sub DelSuggestion { 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; } } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/acceptorreject.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/acceptorreject.tmpl index 69731721a9..e1a9c1db9b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/acceptorreject.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/suggestion/acceptorreject.tmpl @@ -1,9 +1,15 @@ -Koha › Acquisitions &rasquo; Suggestions Management +Koha › Acquisitions › Suggestions Management + + @@ -42,39 +95,69 @@

Suggestions

- -
+
Sorting...
+
Loading tab...
+
-
+ +
"> +
" method="post" action="/cgi-bin/koha/suggestion/acceptorreject.pl"> + + " > - - - - - - - + +
StatusReason
+ +
+ +
+ + - - + + + + + + + + + + + + + + + + + + - - - -
Suggestion Suggested by
DateReasonReason UpdateReasonAcceptRejectDelete
- + , by
+ © + ; Volume: + ; ISBN : ; Published by in in
+ + , + + + + + + +
"> - " name="reason"> @@ -89,87 +172,64 @@
- , by
- © - ; Volume: - ; ISBN : ; Published by in in
-
">,
-
-
- - No waiting suggestions to accept or reject. - - - - + + " name="" type="radio" value="ACCEPTED" disabled="disabled" /> - - - - - - - - - - - - -
ReasonSuggestionSuggested byDate
- - - - - , by - -
- - © - - - ; Volume: - - - ; ISBN : - - - ; Published by - - - in - - - in - -
- - - + + " name="" type="radio" value="ACCEPTED" /> +
- ">, + + " name="" type="radio" value="REJECTED" disabled="disabled" /> + + + " name="" type="radio" value="REJECTED" /> + + - + " name="" type="radio" value="delete" />
- + +
+
all"> + ">Mark all with this reason +
-

No suggestions have been - - accepted. - - rejected. -

- +
all"> + + all" name="other-reasonall" value="please note your reason here..." /> +
+
+
+ + + + No pending suggestions. + + + No accepted suggestions. + + + No rejected suggestions. + + +
+ + +
- + \ No newline at end of file diff --git a/suggestion/acceptorreject.pl b/suggestion/acceptorreject.pl index 704f2c5754..c1c7dd5149 100755 --- a/suggestion/acceptorreject.pl +++ b/suggestion/acceptorreject.pl @@ -72,6 +72,8 @@ use C4::Auth; # get_template_and_user use C4::Output; use C4::Suggestions; use C4::Koha; # GetAuthorisedValue +use C4::Dates qw(format_date); + my $input = new CGI; my $title = $input->param('title'); @@ -100,53 +102,77 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( my $suggestions; +my $branchcode; +my $userenv = C4::Context->userenv; +if ($userenv) { + unless ($userenv->{flags} == 1){ + $branchcode=$userenv->{branch}; + } +} + if ( $op eq "aorr_confirm" ) { - my @suggestionlist = $input->param("aorr"); - - foreach my $suggestion (@suggestionlist) { - if ( $suggestion =~ /(A|R)(.*)/ ) { - my ( $newstatus, $suggestionid ) = ( $1, $2 ); - $newstatus = "REJECTED" if $newstatus eq "R"; - $newstatus = "ACCEPTED" if $newstatus eq "A"; - my $reason = $input->param( "reason" . $suggestionid ); + my $parameters=$input->Vars; + my @deletelist; + my $suggestiontype=$parameters->{suggestiontype}; + foreach my $suggestionid (keys %$parameters){ + next unless $suggestionid=~/^\d+$/; + ## it is a suggestion + if ($parameters->{$suggestionid}=~/delete/i){ + push @deletelist,$suggestionid; + } + else { + ## it is not a deletion + ## Get the Reason + my $reason = $parameters->{"reason$suggestionid"}; + if ( $reason eq "other" ) { + $reason = $parameters->{"other-reason$suggestionid"}; + } + unless ($reason){ + $reason= $parameters->{"reason".$suggestiontype."all"}; if ( $reason eq "other" ) { - $reason = $input->param( "other-reason" . $suggestionid ); + $reason = $parameters->{"other-reason".$suggestiontype."all"}; } - ModStatus( $suggestionid, $newstatus, $loggedinuser, '', $reason ); + } + ModStatus( $suggestionid, $parameters->{$suggestionid}, $loggedinuser, '', $reason ); } } $op = "else"; - $suggestions = &SearchSuggestion( "", "", "", "", 'ASKED', "" ); + if (scalar(@deletelist)>0){ + my $params = "&delete_field=".join ("&delete_field=",@deletelist); + warn $params; + print $input->redirect("/cgi-bin/koha/suggestion/acceptorreject.pl?op=delete_confirm$params"); + } } if ( $op eq "delete_confirm" ) { my @delete_field = $input->param("delete_field"); foreach my $delete_field (@delete_field) { - &DelSuggestion( $loggedinuser, $delete_field ); + &DelSuggestion( $loggedinuser, $delete_field,"intranet" ); } $op = 'else'; - $suggestions = &SearchSuggestion( "", "", "", "", 'ASKED', "" ); -} - -if ( $op eq "accepted" ) { - $suggestions = &GetSuggestionByStatus('ACCEPTED'); - $template->param(done => 1); -} - -if ( $op eq "rejected" ) { - $suggestions = &GetSuggestionByStatus('REJECTED'); - $template->param(done => 1); } my $reasonsloop = GetAuthorisedValues("SUGGEST"); -my @suggestions_loop; -foreach my $suggestion (@$suggestions) { - $suggestion->{'reasonsloop'} = $reasonsloop; - push @suggestions_loop, $suggestion; -} +my $pending_suggestions = &SearchSuggestion( "", "", "", "", 'ASKED', "",$branchcode ); +map{$_->{'reasonsloop'}=$reasonsloop;$_->{'date'}=format_date($_->{'date'})} @$pending_suggestions; +my $accepted_suggestions = &GetSuggestionByStatus('ACCEPTED',$branchcode); +map{$_->{'reasonsloop'}=$reasonsloop;$_->{'date'}=format_date($_->{'date'})} @$accepted_suggestions; +my $rejected_suggestions = &GetSuggestionByStatus('REJECTED',$branchcode); +map{$_->{'reasonsloop'}=$reasonsloop;$_->{'date'}=format_date($_->{'date'})} @$rejected_suggestions; + +my @allsuggestions; +push @allsuggestions,{"suggestiontype"=>"accepted", + 'suggestions_loop'=>$accepted_suggestions, + 'reasonsloop' => $reasonsloop}; +push @allsuggestions,{"suggestiontype"=>"pending", + 'suggestions_loop'=>$pending_suggestions, + 'reasonsloop' => $reasonsloop}; +push @allsuggestions,{"suggestiontype"=>"rejected", + 'suggestions_loop'=>$rejected_suggestions, + 'reasonsloop' => $reasonsloop}; $template->param( - suggestions_loop => \@suggestions_loop, + suggestions => \@allsuggestions, "op_$op" => 1, ); -- 2.39.5