3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA 02111-1307 USA
21 use C4
::Auth
; # get_template_and_user
24 use C4
::Koha
; #GetItemTypes
28 use C4
::Dates
qw(format_date);
33 my $suggestion= shift @_;
34 foreach my $date qw(createdon managedon){
35 $suggestion->{$date}=(($suggestion->{$date} eq "0000-00-00" ||$suggestion->{$date} eq "")?
36 $suggestion->{$date}=C4
::Dates
->today:
37 format_date
($suggestion->{$date})
40 $suggestion->{'acceptedon'}=(($suggestion->{'acceptedon'} eq "0000-00-00" ||$suggestion->{'acceptedon'} eq "")?
42 format_date
($suggestion->{'acceptedon'})
44 $suggestion->{'managedby'}=C4
::Context
->userenv->{"id"} unless ($suggestion->{'managedby'});
45 $suggestion->{'createdby'}=C4
::Context
->userenv->{"id"} unless ($suggestion->{'createdby'});
46 $suggestion->{'branchcode'}=C4
::Context
->userenv->{"branch"} unless ($suggestion->{'branchcode'});
50 my ($criteriumvalue,$displayby)=@_;
51 return ($criteriumvalue eq 'ASKED'?
"pending":lc $criteriumvalue) if ($displayby =~/status/i);
52 return (GetBranchName
($criteriumvalue)) if ($displayby =~/branchcode/);
53 return (GetSupportName
($criteriumvalue)) if ($displayby =~/itemtype/);
54 if ($displayby =~/managedby/||$displayby =~/acceptedby/){
55 my $borr=C4
::Members
::GetMember
(borrowernumber
=>$criteriumvalue);
56 return "" unless $borr;
57 # warn '$borr : ',Data::Dumper::Dumper($borr);
58 return $$borr{firstname
}.", ".$$borr{surname
};
63 my $suggestedbyme = (defined $input->param('suggestedbyme')?
$input->param('suggestedbyme'):1);
64 my $op = $input->param('op')||'else';
65 my @editsuggestions = $input->param('edit_field');
66 my $branchfilter = $input->param('branchcode');
67 my $suggestedby = $input->param('suggestedby');
68 my $managedby = $input->param('managedby');
69 my $displayby = $input->param('displayby');
70 my $tabcode = $input->param('tabcode');
72 # filter informations which are not suggestion related.
73 my $suggestion_ref = $input->Vars;
74 delete $$suggestion_ref{$_} foreach qw
<suggestedbyme op displayby tabcode edit_field
>;
75 foreach (keys %$suggestion_ref){
76 delete $$suggestion_ref{$_} if (!$$suggestion_ref{$_} && ($op eq 'else' || $op eq 'change'));
78 my ( $template, $borrowernumber, $cookie ) = get_template_and_user
(
80 template_name
=> "suggestion/suggestion.tmpl",
83 flagsrequired
=> { catalogue
=> 1 },
87 #########################################
91 if ($$suggestion_ref{'suggestionid'}>0){
92 &ModSuggestion
($suggestion_ref);
95 ###FIXME:Search here if suggestion already exists.
96 my $suggestions_loop =
97 SearchSuggestion
( $suggestion_ref );
98 if (@
$suggestions_loop>=1){
99 #some suggestion are answering the request Donot Add
102 ## Adding some informations related to suggestion
103 &NewSuggestion
($suggestion_ref);
105 # empty fields, to avoid filter in "SearchSuggestion"
107 map{delete $$suggestion_ref{$_}} keys %$suggestion_ref;
112 Init
($suggestion_ref);
115 elsif ($op=~/edit/) {
117 $suggestion_ref=&GetSuggestion
($$suggestion_ref{'suggestionid'});
118 Init
($suggestion_ref);
121 elsif ($op eq "change" ) {
122 if ($$suggestion_ref{"STATUS"}){
123 my $tmpstatus=($$suggestion_ref{"STATUS"} eq "ACCEPTED"?
"accepted":"managed");
124 $$suggestion_ref{"$tmpstatus"."on"}=C4
::Dates
->today;
125 $$suggestion_ref{"$tmpstatus"."by"}=C4
::Context
->userenv->{number
};
127 if ( my $reason = $$suggestion_ref{"reason$tabcode"}){
128 if ( $reason eq "other" ) {
129 $reason = $$suggestion_ref{"other_reason$tabcode"};
131 $$suggestion_ref{'reason'}=$reason;
133 delete $$suggestion_ref{$_} foreach ("reason$tabcode", "other_reason$tabcode");
134 foreach (keys %$suggestion_ref){
135 delete $$suggestion_ref{$_} unless ($$suggestion_ref{$_});
137 foreach my $suggestionid (@editsuggestions) {
138 next unless $suggestionid;
139 $$suggestion_ref{'suggestionid'}=$suggestionid;
140 &ModSuggestion
($suggestion_ref);
143 }elsif ($op eq "delete" ) {
144 foreach my $delete_field (@editsuggestions) {
145 &DelSuggestion
( $borrowernumber, $delete_field,'intranet' );
152 $displayby||="STATUS";
153 my $criteria_list=GetDistinctValues
("suggestions.".$displayby);
155 foreach my $criteriumvalue (map{$$_{'value'}} @
$criteria_list){
156 my $definedvalue = defined $$suggestion_ref{$displayby} && $$suggestion_ref{$displayby} ne "";
158 next if ($definedvalue && $$suggestion_ref{$displayby} ne $criteriumvalue);
159 $$suggestion_ref{$displayby}=$criteriumvalue;
160 warn $$suggestion_ref{$displayby}."=$criteriumvalue; $displayby";
162 my $suggestions = &SearchSuggestion
($suggestion_ref);
163 foreach (@
$suggestions){
164 foreach my $date qw(createdon managedon acceptedon){
165 if ($_->{$date} ne "0000-00-00" && $_->{$date} ne "" ){
166 $_->{$date}=format_date
($_->{$date}) ;
172 push @allsuggestions,{
173 "suggestiontype"=>$criteriumvalue||"suggest",
174 "suggestiontypelabel"=>GetCriteriumDesc
($criteriumvalue,$displayby)||"",
175 "suggestionscount"=>scalar(@
$suggestions),
176 'suggestions_loop'=>$suggestions,
179 delete $$suggestion_ref{$displayby} unless $definedvalue;
181 my $reasonsloop = GetAuthorisedValues
("SUGGEST");
183 "displayby"=> $displayby,
184 "notabs"=> $displayby eq "",
185 suggestions
=> \
@allsuggestions,
186 reasonsloop
=> $reasonsloop,
190 foreach my $element qw
<managedby createdby suggestedby rejectedby
>{
191 warn $$suggestion_ref{$element};
192 if ($$suggestion_ref{$element}){
193 my $member=GetMember
(borrowernumber
=>$$suggestion_ref{$element});
194 my $presentation_string=$$member{firstname
}." ".$$member{surname
}." ".GetBranchName
($$member{branchcode
})." ".$$member{description
}." ".$$member{category_type
};
195 warn $presentation_string;
196 $template->param($element."information"=>$presentation_string);
202 dateformat
=> C4
::Context
->preference("dateformat"),
208 ## Initializing selection lists
210 #branch display management
211 my $onlymine=C4
::Context
->preference('IndependantBranches') &&
212 C4
::Context
->userenv &&
213 C4
::Context
->userenv->{flags
}!=1 &&
214 C4
::Context
->userenv->{branch
};
215 my $branches = GetBranches
($onlymine);
218 foreach my $thisbranch ( sort {$branches->{$a}->{'branchname'} cmp $branches->{$b}->{'branchname'}} keys %$branches ) {
220 value
=> $thisbranch,
221 branchname
=> $branches->{$thisbranch}->{'branchname'},
222 selected
=> ($branches->{$thisbranch}->{'branchcode'} eq $branchfilter)
223 ||($branches->{$thisbranch}->{'branchcode'} eq $$suggestion_ref{'branchcode'})
225 push @branchloop, \
%row;
227 $branchfilter=C4
::Context
->userenv->{'branch'} if ($onlymine && !$branchfilter);
229 $template->param( branchloop
=> \
@branchloop,
230 branchfilter
=> $branchfilter);
232 # the index parameter is different for item-level itemtypes
233 my $supportlist=GetSupportList
();
234 foreach my $support(@
$supportlist){
235 $$support{'selected'}= $$support{'code'} eq $$suggestion_ref{'itemtype'};
236 if ($$support{'imageurl'}){
237 $$support{'imageurl'}= getitemtypeimagelocation
( 'intranet', $$support{'imageurl'} );
240 delete $$support{'imageurl'}
243 $template->param(itemtypeloop
=>$supportlist);
246 my $searchbudgets={ budget_branchcode
=>$branchfilter} if $branchfilter;
247 my $budgets = GetBudgets
($searchbudgets);
250 $_->{'selected'}=1 if ($$suggestion_ref{'budget_id'} && $_{'budget_id'} eq $$suggestion_ref{'budget_id'})
253 $template->param( budgetsloop
=> $budgets);
256 foreach my $field qw(managedby acceptedby suggestedby STATUS){
258 $values_list=GetDistinctValues
("suggestions.".$field) ;
259 my @codes_list = map{
260 { 'code'=>$$_{'value'},
261 'desc'=>GetCriteriumDesc
($$_{'value'},$field),
262 'selected'=> $$_{'value'} eq $$suggestion_ref{$field}
265 $hashlists{lc($field)."_loop"}=\
@codes_list;
267 $template->param(%hashlists);
269 output_html_with_http_headers
$input, $cookie, $template->output;