#!/usr/bin/perl
# This file is part of Koha.
+# Copyright 2006-2010 BibLibre
+
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
-# You should have received a copy of the GNU General Public License along with
-# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
-# Suite 330, Boston, MA 02111-1307 USA
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use strict;
#use warnings; FIXME - Bug 2505
sub Init{
my $suggestion= shift @_;
- foreach my $date qw(suggesteddate manageddate){
- $suggestion->{$date}=(($suggestion->{$date} eq "0000-00-00" ||$suggestion->{$date} eq "")?
- $suggestion->{$date}=C4::Dates->today:
- format_date($suggestion->{$date})
- );
- }
- foreach my $date qw(rejecteddate accepteddate){
+ # "Managed by" is used only when a suggestion is being edited (not when created)
+ if ($suggestion->{'suggesteddate'} eq "0000-00-00" ||$suggestion->{'suggesteddate'} eq "") {
+ # new suggestion
+ $suggestion->{'suggesteddate'} = C4::Dates->today;
+ $suggestion->{'suggestedby'} = C4::Context->userenv->{"number"} unless ($suggestion->{'suggestedby'});
+ }
+ else {
+ # editing of an existing suggestion
+ $suggestion->{'manageddate'} = C4::Dates->today;
+ $suggestion->{'managedby'} = C4::Context->userenv->{"number"} unless ($suggestion->{'managedby'});
+ # suggesteddate, when coming from the DB, needs to be formated
+ $suggestion->{'suggesteddate'} = format_date($suggestion->{'suggesteddate'});
+ }
+ foreach my $date ( qw(rejecteddate accepteddate) ){
$suggestion->{$date}=(($suggestion->{$date} eq "0000-00-00" ||$suggestion->{$date} eq "")?
"":
format_date($suggestion->{$date})
);
- }
- $suggestion->{'managedby'}=C4::Context->userenv->{"number"} unless ($suggestion->{'managedby'});
- $suggestion->{'createdby'}=C4::Context->userenv->{"number"} unless ($suggestion->{'createdby'});
+ }
$suggestion->{'branchcode'}=C4::Context->userenv->{"branch"} unless ($suggestion->{'branchcode'});
}
return ($criteriumvalue eq 'ASKED'?"Pending":ucfirst(lc( $criteriumvalue))) if ($displayby =~/status/i);
return (GetBranchName($criteriumvalue)) if ($displayby =~/branchcode/);
return (GetSupportName($criteriumvalue)) if ($displayby =~/itemtype/);
- if ($displayby =~/managedby/||$displayby =~/acceptedby/){
+ if ($displayby =~/suggestedby/||$displayby =~/managedby/||$displayby =~/acceptedby/){
my $borr=C4::Members::GetMember(borrowernumber=>$criteriumvalue);
return "" unless $borr;
- return $$borr{firstname} . ", " . $$borr{surname};
+ return $$borr{surname} . ", " . $$borr{firstname};
}
if ( $displayby =~ /budgetid/) {
my $budget = GetBudget($criteriumvalue);
my $suggestedbyme = (defined $input->param('suggestedbyme')? $input->param('suggestedbyme'):1);
my $op = $input->param('op')||'else';
my @editsuggestions = $input->param('edit_field');
-my $branchfilter = $input->param('branchcode');
-my $suggestedby = $input->param('suggestedby');
-my $managedby = $input->param('managedby');
-my $displayby = $input->param('displayby');
-my $tabcode = $input->param('tabcode');
+my $suggestedby = $input->param('suggestedby');
+my $returnsuggestedby = $input->param('returnsuggestedby');
+my $returnsuggested = $input->param('returnsuggested');
+my $managedby = $input->param('managedby');
+my $displayby = $input->param('displayby') || '';
+my $branchfilter = ($displayby ne "branchcode") ? $input->param('branchcode') : '';
+my $tabcode = $input->param('tabcode');
# filter informations which are not suggestion related.
my $suggestion_ref = $input->Vars;
+
delete $$suggestion_ref{$_} foreach qw( suggestedbyme op displayby tabcode edit_field );
foreach (keys %$suggestion_ref){
delete $$suggestion_ref{$_} if (!$$suggestion_ref{$_} && ($op eq 'else' || $op eq 'change'));
#########################################
## Operations
##
-if ($op =~/save/i){
- if ($$suggestion_ref{'suggestionid'}>0){
- &ModSuggestion($suggestion_ref);
- }
- else {
+if ( $op =~ /save/i ) {
+ if ( $$suggestion_ref{"STATUS"} ) {
+ if ( my $tmpstatus = lc( $$suggestion_ref{"STATUS"} ) =~ /ACCEPTED|REJECTED/i ) {
+ $$suggestion_ref{ lc( $$suggestion_ref{"STATUS"}) . "date" } = C4::Dates->today;
+ $$suggestion_ref{ lc( $$suggestion_ref{"STATUS"}) . "by" } = C4::Context->userenv->{number};
+ }
+ $$suggestion_ref{"manageddate"} = C4::Dates->today;
+ $$suggestion_ref{"managedby"} = C4::Context->userenv->{number};
+ }
+ if ( $$suggestion_ref{'suggestionid'} > 0 ) {
+ &ModSuggestion($suggestion_ref);
+ } else {
###FIXME:Search here if suggestion already exists.
my $suggestions_loop =
SearchSuggestion( $suggestion_ref );
$op ='save';
}
elsif ($op eq "change" ) {
+ # set accepted/rejected/managed informations if applicable
+ # ie= if the librarian has choosen some action on the suggestions
+ if ($$suggestion_ref{"STATUS"} eq "ACCEPTED"){
+ $$suggestion_ref{"accepteddate"}=C4::Dates->today;
+ $$suggestion_ref{"acceptedby"}=C4::Context->userenv->{number};
+ } elsif ($$suggestion_ref{"STATUS"} eq "REJECTED"){
+ $$suggestion_ref{"rejecteddate"}=C4::Dates->today;
+ $$suggestion_ref{"rejectedby"}=C4::Context->userenv->{number};
+ }
if ($$suggestion_ref{"STATUS"}){
- if (my $tmpstatus=lc($$suggestion_ref{"STATUS"}) =~/ACCEPTED|REJECTED/i){
- $$suggestion_ref{"$tmpstatus"."date"}=C4::Dates->today;
- $$suggestion_ref{"$tmpstatus"."by"}=C4::Context->userenv->{number};
- }
$$suggestion_ref{"manageddate"}=C4::Dates->today;
$$suggestion_ref{"managedby"}=C4::Context->userenv->{number};
}
}
$op = 'else';
}
+elsif ( $op eq 'show' ) {
+ $suggestion_ref=&GetSuggestion($$suggestion_ref{'suggestionid'});
+ $$suggestion_ref{branchname} = GetBranchName $$suggestion_ref{branchcode};
+ my $budget = GetBudget $$suggestion_ref{budgetid};
+ $$suggestion_ref{budgetname} = $$budget{budget_name};
+ Init($suggestion_ref);
+}
if ($op=~/else/) {
$op='else';
$displayby||="STATUS";
+ delete $$suggestion_ref{'branchcode'} if($displayby eq "branchcode");
my $criteria_list=GetDistinctValues("suggestions.".$displayby);
my @allsuggestions;
my $reasonsloop = GetAuthorisedValues("SUGGEST");
- foreach my $criteriumvalue (map{$$_{'value'}} @$criteria_list){
+ foreach my $criteriumvalue ( map { $$_{'value'} } @$criteria_list ) {
+ # By default, display suggestions from current working branch
+ if(not defined $branchfilter) {
+ $$suggestion_ref{'branchcode'} = C4::Context->userenv->{'branch'};
+ }
my $definedvalue = defined $$suggestion_ref{$displayby} && $$suggestion_ref{$displayby} ne "";
-
- next if ($definedvalue && $$suggestion_ref{$displayby} ne $criteriumvalue);
- $$suggestion_ref{$displayby}=$criteriumvalue;
-# warn $$suggestion_ref{$displayby}."=$criteriumvalue; $displayby";
-
+
+ next if ( $definedvalue && $$suggestion_ref{$displayby} ne $criteriumvalue );
+ $$suggestion_ref{$displayby} = $criteriumvalue;
+
my $suggestions = &SearchSuggestion($suggestion_ref);
- foreach my $suggestion (@$suggestions){
- $suggestion->{budget_name}=GetBudget($suggestion->{budgetid})->{budget_name} if $suggestion->{budgetid};
- foreach my $date qw(suggesteddate manageddate accepteddate){
+ foreach my $suggestion (@$suggestions) {
+ $suggestion->{budget_name} = GetBudget( $suggestion->{budgetid} )->{budget_name} if $suggestion->{budgetid};
+ foreach my $date qw(suggesteddate manageddate accepteddate) {
+ if ($suggestion->{$date} and $suggestion->{$date} ne "0000-00-00" && $suggestion->{$date} ne "" ) {
+ $suggestion->{$date} = format_date( $suggestion->{$date} );
+ } else {
+ $suggestion->{$date} = "";
+ }
+ }
+ foreach my $date ( qw(suggesteddate manageddate accepteddate) ){
if ($suggestion->{$date} ne "0000-00-00" && $suggestion->{$date} ne "" ){
$suggestion->{$date}=format_date($suggestion->{$date}) ;
} else {
);
}
-foreach my $element qw(managedby suggestedby){
+foreach my $element ( qw(managedby suggestedby acceptedby) ) {
# $debug || warn $$suggestion_ref{$element};
if ($$suggestion_ref{$element}){
my $member=GetMember(borrowernumber=>$$suggestion_ref{$element});
"op" =>$op,
);
+if(defined($returnsuggested) and $returnsuggested ne "noone")
+{
+ print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=".$returnsuggested."#suggestions");
+}
####################
## Initializing selection lists
my %row = (
value => $thisbranch,
branchname => $branches->{$thisbranch}->{'branchname'},
- selected => ($branches->{$thisbranch}->{'branchcode'} eq $branchfilter)
- ||($branches->{$thisbranch}->{'branchcode'} eq $$suggestion_ref{'branchcode'})
+ selected => ($branchfilter and $branches->{$thisbranch}->{'branchcode'} eq $branchfilter ) || ( $$suggestion_ref{'branchcode'} and $branches->{$thisbranch}->{'branchcode'} eq $$suggestion_ref{'branchcode'} )
);
push @branchloop, \%row;
}
branchfilter => $branchfilter);
# the index parameter is different for item-level itemtypes
-my $supportlist=GetSupportList();
-foreach my $support(@$supportlist){
- $$support{'selected'}= $$support{'itemtype'} eq $$suggestion_ref{'itemtype'};
- if ($$support{'imageurl'}){
- $$support{'imageurl'}= getitemtypeimagelocation( 'intranet', $$support{'imageurl'} );
- }
- else {
- delete $$support{'imageurl'}
+my $supportlist = GetSupportList();
+
+foreach my $support (@$supportlist) {
+ $$support{'selected'} = (defined $$suggestion_ref{'itemtype'})
+ ? $$support{'itemtype'} eq $$suggestion_ref{'itemtype'}
+ : 0;
+ if ( $$support{'imageurl'} ) {
+ $$support{'imageurl'} = getitemtypeimagelocation( 'intranet', $$support{'imageurl'} );
+ } else {
+ delete $$support{'imageurl'};
}
}
$template->param(itemtypeloop=>$supportlist);
+$template->param( returnsuggestedby => $returnsuggestedby );
my $patron_reason_loop = GetAuthorisedValues("OPAC_SUG",$$suggestion_ref{'patronreason'});
$template->param(patron_reason_loop=>$patron_reason_loop);
#Budgets management
-my $searchbudgets={ budget_branchcode=>$branchfilter} if $branchfilter;
-my $budgets = GetBudgets($searchbudgets);
+my $budgets = [];
+if ($branchfilter) {
+ my $searchbudgets = { budget_branchcode => $branchfilter };
+ $budgets = GetBudgets($searchbudgets);
+} else {
+ $budgets = GetBudgets(undef);
+}
-foreach my $budget (@$budgets){
+foreach my $budget ( @{$budgets} ) {
+## Please see file perltidy.ERR
$budget->{'selected'}=1 if ($$suggestion_ref{'budgetid'} && $budget->{'budget_id'} eq $$suggestion_ref{'budgetid'})
};
$template->param( budgetsloop => $budgets);
+$template->param( "statusselected_$$suggestion_ref{'STATUS'}" =>1) if ($$suggestion_ref{'STATUS'});
# get currencies and rates
my @rates = GetCurrencies();
my $count = scalar @rates;
+my $active_currency = GetCurrency();
+my $selected_currency;
+if ($$suggestion_ref{'currency'}) {
+ $selected_currency = $$suggestion_ref{'currency'};
+}
+else {
+ $selected_currency = $active_currency->{currency};
+}
my @loop_currency = ();
for ( my $i = 0 ; $i < $count ; $i++ ) {
my %line;
$line{currcode} = $rates[$i]->{'currency'};
$line{rate} = $rates[$i]->{'rate'};
- $line{selected} = 1 if ($$suggestion_ref{'currency'} && $line{'currcode'} eq $$suggestion_ref{'currency'});
+ $line{selected} = 1 if ($line{'currcode'} eq $selected_currency);
push @loop_currency, \%line;
}
);
my %hashlists;
-foreach my $field qw(managedby acceptedby suggestedby budgetid STATUS) {
+foreach my $field ( qw(managedby acceptedby suggestedby budgetid) ) {
my $values_list;
- $values_list=GetDistinctValues("suggestions.".$field) ;
- my @codes_list = map{
- { 'code'=>$$_{'value'},
- 'desc'=>GetCriteriumDesc($$_{'value'},$field),
- 'selected'=> $$_{'value'} eq $$suggestion_ref{$field}
- }
- } @$values_list;
- $hashlists{lc($field)."_loop"}=\@codes_list;
+ $values_list = GetDistinctValues( "suggestions." . $field );
+ my @codes_list = map {
+ { 'code' => $$_{'value'},
+ 'desc' => GetCriteriumDesc( $$_{'value'}, $field ),
+ 'selected' => ($$suggestion_ref{$field}) ? $$_{'value'} eq $$suggestion_ref{$field} : 0,
+ }
+ } @$values_list;
+ $hashlists{ lc($field) . "_loop" } = \@codes_list;
}
$template->param(%hashlists);
$template->param(DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),);