X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=suggestion%2Fsuggestion.pl;h=d00b6322ef27c5e59692591c83957ff6677889d7;hb=5d413a7a9b8a3873e85905d35388767d02e26e8a;hp=859c0dd749963d87e29f60f274dd4dff05dad412;hpb=73de4a2e3f39f22d7049d224f516d4f26ac00560;p=koha_gimpoz diff --git a/suggestion/suggestion.pl b/suggestion/suggestion.pl index 859c0dd749..d00b6322ef 100755 --- a/suggestion/suggestion.pl +++ b/suggestion/suggestion.pl @@ -1,6 +1,8 @@ #!/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 @@ -11,11 +13,12 @@ # 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 require Exporter; use CGI; use C4::Auth; # get_template_and_user @@ -50,15 +53,19 @@ sub Init{ sub GetCriteriumDesc{ my ($criteriumvalue,$displayby)=@_; - return ($criteriumvalue eq 'ASKED'?"pending":lc $criteriumvalue) if ($displayby =~/status/i); + 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; -# warn '$borr : ',Data::Dumper::Dumper($borr); - return $$borr{firstname}.", ".$$borr{surname}; - } + return $$borr{firstname} . ", " . $$borr{surname}; + } + if ( $displayby =~ /budgetid/) { + my $budget = GetBudget($criteriumvalue); + return "" unless $budget; + return $$budget{budget_name}; + } } my $input = CGI->new; @@ -67,12 +74,15 @@ my $op = $input->param('op')||'else'; my @editsuggestions = $input->param('edit_field'); my $branchfilter = $input->param('branchcode'); my $suggestedby = $input->param('suggestedby'); +my $returnsuggested = $input->param('returnsuggested'); +my $returnsuggestedby = $input->param('returnsuggestedby'); my $managedby = $input->param('managedby'); my $displayby = $input->param('displayby'); 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')); @@ -89,11 +99,18 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( ######################################### ## 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 ); @@ -121,28 +138,16 @@ elsif ($op=~/edit/) { $op ='save'; } elsif ($op eq "change" ) { -<<<<<<< HEAD:suggestion/suggestion.pl - if ($$suggestion_ref{"STATUS"}){ - my $tmpstatus=($$suggestion_ref{"STATUS"} eq "ACCEPTED"?"accepted":"managed"); - $$suggestion_ref{"$tmpstatus"."on"}=C4::Dates->today; - $$suggestion_ref{"$tmpstatus"."by"}=C4::Context->userenv->{id}; + # 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 ( my $reason = $$suggestion_ref{"reason$tabcode"}){ - if ( $reason eq "other" ) { - $reason = $$suggestion_ref{"other_reason$tabcode"}; - } - $$suggestion_ref{'reason'}=$reason; - } - delete $$suggestion_ref{$_} foreach ("reason$tabcode", "other_reason$tabcode"); - foreach (keys %$suggestion_ref){ - delete $$suggestion_ref{$_} unless ($$suggestion_ref{$_}); - } -======= 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}; } @@ -156,7 +161,6 @@ elsif ($op eq "change" ) { foreach (keys %$suggestion_ref){ delete $$suggestion_ref{$_} unless ($$suggestion_ref{$_}); } ->>>>>>> Date management update Suggestions:suggestion/suggestion.pl foreach my $suggestionid (@editsuggestions) { next unless $suggestionid; $$suggestion_ref{'suggestionid'}=$suggestionid; @@ -175,20 +179,25 @@ if ($op=~/else/) { $displayby||="STATUS"; my $criteria_list=GetDistinctValues("suggestions.".$displayby); my @allsuggestions; + my $reasonsloop = GetAuthorisedValues("SUGGEST"); foreach my $criteriumvalue (map{$$_{'value'}} @$criteria_list){ 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"; +# warn $$suggestion_ref{$displayby}."=$criteriumvalue; $displayby"; my $suggestions = &SearchSuggestion($suggestion_ref); - foreach (@$suggestions){ + foreach my $suggestion (@$suggestions){ + if($suggestion->{budgetid}) { + my $budget = GetBudget($suggestion->{budgetid}); + $suggestion->{budget_name}=$budget->{budget_name} if $budget; + } foreach my $date qw(suggesteddate manageddate accepteddate){ - if ($_->{$date} ne "0000-00-00" && $_->{$date} ne "" ){ - $_->{$date}=format_date($_->{$date}) ; + if ($suggestion->{$date} ne "0000-00-00" && $suggestion->{$date} ne "" ){ + $suggestion->{$date}=format_date($suggestion->{$date}) ; } else { - $_->{$date}="" ; + $suggestion->{$date}="" ; } } } @@ -197,26 +206,31 @@ if ($op=~/else/) { "suggestiontypelabel"=>GetCriteriumDesc($criteriumvalue,$displayby)||"", "suggestionscount"=>scalar(@$suggestions), 'suggestions_loop'=>$suggestions, + 'reasonsloop' => $reasonsloop, }; delete $$suggestion_ref{$displayby} unless $definedvalue; } - my $reasonsloop = GetAuthorisedValues("SUGGEST"); + $template->param( "displayby"=> $displayby, "notabs"=> $displayby eq "", suggestions => \@allsuggestions, - reasonsloop => $reasonsloop, ); } -foreach my $element qw(managedby suggestedby){ - $debug || warn $$suggestion_ref{$element}; +foreach my $element qw(managedby suggestedby acceptedby) { +# $debug || warn $$suggestion_ref{$element}; if ($$suggestion_ref{$element}){ my $member=GetMember(borrowernumber=>$$suggestion_ref{$element}); - my $presentation_string=$$member{firstname}." ".$$member{surname}." ".GetBranchName($$member{branchcode})." ".$$member{description}." ".$$member{category_type}; - $debug || warn $presentation_string; - $template->param($element."information"=>$presentation_string); + $template->param( + $element."_borrowernumber"=>$$member{borrowernumber}, + $element."_firstname"=>$$member{firstname}, + $element."_surname"=>$$member{surname}, + $element."_branchcode"=>$$member{branchcode}, + $element."_description"=>$$member{description}, + $element."_category_type"=>$$member{category_type} + ); } } $template->param( @@ -226,6 +240,10 @@ $template->param( "op" =>$op, ); +if(defined($returnsuggested) and $returnsuggested ne "noone") +{ + print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=".$returnsuggested."#suggestions"); +} #################### ## Initializing selection lists @@ -255,7 +273,7 @@ $template->param( branchloop => \@branchloop, # the index parameter is different for item-level itemtypes my $supportlist=GetSupportList(); foreach my $support(@$supportlist){ - $$support{'selected'}= $$support{'code'} eq $$suggestion_ref{'itemtype'}; + $$support{'selected'}= $$support{'itemtype'} eq $$suggestion_ref{'itemtype'}; if ($$support{'imageurl'}){ $$support{'imageurl'}= getitemtypeimagelocation( 'intranet', $$support{'imageurl'} ); } @@ -264,19 +282,50 @@ foreach my $support(@$supportlist){ } } $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 (@$budgets){ - $_->{'selected'}=1 if ($$suggestion_ref{'budget_id'} && $_{'budget_id'} eq $$suggestion_ref{'budget_id'}) +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); + +# get currencies and rates +my @rates = GetCurrencies(); +my $count = scalar @rates; -my %hashlists; -foreach my $field qw(managedby acceptedby suggestedby STATUS){ +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'}); + push @loop_currency, \%line; +} + +$template->param(loop_currency => \@loop_currency); + +$template->param( + price => sprintf("%.2f", $$suggestion_ref{'price'}||0), + total => sprintf("%.2f", $$suggestion_ref{'total'}||0), +); + +my %hashlists; +foreach my $field qw(managedby acceptedby suggestedby budgetid) { my $values_list; $values_list=GetDistinctValues("suggestions.".$field) ; my @codes_list = map{ @@ -288,5 +337,5 @@ foreach my $field qw(managedby acceptedby suggestedby STATUS){ $hashlists{lc($field)."_loop"}=\@codes_list; } $template->param(%hashlists); - +$template->param(DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),); output_html_with_http_headers $input, $cookie, $template->output;