X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=suggestion%2Fsuggestion.pl;h=9811cc86045b83d78ad60d1875dee5dd522fdf63;hb=63e871dd401c33f288202358639bf098af596148;hp=c455e3f7864548b12b169adb7f2e42a045d385f4;hpb=8802bbf5fe6c0b35ad4d6e00293eb102a48b92b4;p=koha.git diff --git a/suggestion/suggestion.pl b/suggestion/suggestion.pl index c455e3f786..9811cc8604 100755 --- a/suggestion/suggestion.pl +++ b/suggestion/suggestion.pl @@ -31,29 +31,31 @@ use C4::Debug; sub Init{ my $suggestion= shift @_; - foreach my $date qw(createdon managedon){ + 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}) ); } - $suggestion->{'acceptedon'}=(($suggestion->{'acceptedon'} eq "0000-00-00" ||$suggestion->{'acceptedon'} eq "")? + foreach my $date qw(rejecteddate accepteddate){ + $suggestion->{$date}=(($suggestion->{$date} eq "0000-00-00" ||$suggestion->{$date} eq "")? "": - format_date($suggestion->{'acceptedon'}) + format_date($suggestion->{$date}) ); - $suggestion->{'managedby'}=C4::Context->userenv->{"id"} unless ($suggestion->{'managedby'}); - $suggestion->{'createdby'}=C4::Context->userenv->{"id"} unless ($suggestion->{'createdby'}); + } + $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'}); } 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/){ my $borr=C4::Members::GetMember(borrowernumber=>$criteriumvalue); - return "" unless $borr; + return "" unless $borr; # warn '$borr : ',Data::Dumper::Dumper($borr); return $$borr{firstname}.", ".$$borr{surname}; } @@ -71,9 +73,9 @@ my $tabcode = $input->param('tabcode'); # filter informations which are not suggestion related. my $suggestion_ref = $input->Vars; -delete $$suggestion_ref{$_} foreach qw; +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')); + delete $$suggestion_ref{$_} if (!$$suggestion_ref{$_} && ($op eq 'else' || $op eq 'change')); } my ( $template, $borrowernumber, $cookie ) = get_template_and_user( { @@ -89,18 +91,18 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( ## if ($op =~/save/i){ if ($$suggestion_ref{'suggestionid'}>0){ - &ModSuggestion($suggestion_ref); + &ModSuggestion($suggestion_ref); } else { ###FIXME:Search here if suggestion already exists. my $suggestions_loop = SearchSuggestion( $suggestion_ref ); - if (@$suggestions_loop>=1){ - #some suggestion are answering the request Donot Add - } - else { - ## Adding some informations related to suggestion - &NewSuggestion($suggestion_ref); + if (@$suggestions_loop>=1){ + #some suggestion are answering the request Donot Add + } + else { + ## Adding some informations related to suggestion + &NewSuggestion($suggestion_ref); } # empty fields, to avoid filter in "SearchSuggestion" } @@ -120,9 +122,12 @@ elsif ($op=~/edit/) { } elsif ($op eq "change" ) { 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->{number}; + 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}; } if ( my $reason = $$suggestion_ref{"reason$tabcode"}){ if ( $reason eq "other" ) { @@ -135,8 +140,8 @@ elsif ($op eq "change" ) { delete $$suggestion_ref{$_} unless ($$suggestion_ref{$_}); } foreach my $suggestionid (@editsuggestions) { - next unless $suggestionid; - $$suggestion_ref{'suggestionid'}=$suggestionid; + next unless $suggestionid; + $$suggestion_ref{'suggestionid'}=$suggestionid; &ModSuggestion($suggestion_ref); } $op = 'else'; @@ -149,19 +154,20 @@ elsif ($op eq "change" ) { if ($op=~/else/) { $op='else'; - $displayby||="STATUS"; + $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 $date qw(createdon managedon acceptedon){ + foreach my $date qw(suggesteddate manageddate accepteddate){ if ($_->{$date} ne "0000-00-00" && $_->{$date} ne "" ){ $_->{$date}=format_date($_->{$date}) ; } else { @@ -174,27 +180,32 @@ 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 "", + "displayby"=> $displayby, + "notabs"=> $displayby eq "", suggestions => \@allsuggestions, - reasonsloop => $reasonsloop, ); } -foreach my $element qw{ - 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}; - warn $presentation_string; - $template->param($element."information"=>$presentation_string); - } +foreach my $element qw(managedby suggestedby){ +# $debug || warn $$suggestion_ref{$element}; + if ($$suggestion_ref{$element}){ + my $member=GetMember(borrowernumber=>$$suggestion_ref{$element}); + $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( %$suggestion_ref, @@ -209,36 +220,36 @@ $template->param( #branch display management my $onlymine=C4::Context->preference('IndependantBranches') && - C4::Context->userenv && - C4::Context->userenv->{flags}!=1 && - C4::Context->userenv->{branch}; + C4::Context->userenv && + C4::Context->userenv->{flags}!=1 && + C4::Context->userenv->{branch}; my $branches = GetBranches($onlymine); my @branchloop; foreach my $thisbranch ( sort {$branches->{$a}->{'branchname'} cmp $branches->{$b}->{'branchname'}} keys %$branches ) { - my %row = ( + my %row = ( value => $thisbranch, branchname => $branches->{$thisbranch}->{'branchname'}, selected => ($branches->{$thisbranch}->{'branchcode'} eq $branchfilter) - ||($branches->{$thisbranch}->{'branchcode'} eq $$suggestion_ref{'branchcode'}) + ||($branches->{$thisbranch}->{'branchcode'} eq $$suggestion_ref{'branchcode'}) ); push @branchloop, \%row; } $branchfilter=C4::Context->userenv->{'branch'} if ($onlymine && !$branchfilter); $template->param( branchloop => \@branchloop, - branchfilter => $branchfilter); + branchfilter => $branchfilter); # the index parameter is different for item-level itemtypes my $supportlist=GetSupportList(); foreach my $support(@$supportlist){ $$support{'selected'}= $$support{'code'} eq $$suggestion_ref{'itemtype'}; - if ($$support{'imageurl'}){ - $$support{'imageurl'}= getitemtypeimagelocation( 'intranet', $$support{'imageurl'} ); - } - else { - delete $$support{'imageurl'} - } + if ($$support{'imageurl'}){ + $$support{'imageurl'}= getitemtypeimagelocation( 'intranet', $$support{'imageurl'} ); + } + else { + delete $$support{'imageurl'} + } } $template->param(itemtypeloop=>$supportlist); @@ -247,7 +258,7 @@ my $searchbudgets={ budget_branchcode=>$branchfilter} if $branchfilter; my $budgets = GetBudgets($searchbudgets); foreach (@$budgets){ - $_->{'selected'}=1 if ($$suggestion_ref{'budget_id'} && $_{'budget_id'} eq $$suggestion_ref{'budget_id'}) + $_->{'selected'}=1 if ($$suggestion_ref{'budget_id'} && $_{'budget_id'} eq $$suggestion_ref{'budget_id'}) }; $template->param( budgetsloop => $budgets); @@ -257,11 +268,11 @@ foreach my $field qw(managedby acceptedby suggestedby STATUS){ 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; + { 'code'=>$$_{'value'}, + 'desc'=>GetCriteriumDesc($$_{'value'},$field), + 'selected'=> $$_{'value'} eq $$suggestion_ref{$field} + } + } @$values_list; $hashlists{lc($field)."_loop"}=\@codes_list; } $template->param(%hashlists);