bug 2552: correct issue history display
[koha.git] / suggestion / acceptorreject.pl
1 #!/usr/bin/perl
2
3 # Copyright 2000-2002 Katipo Communications
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA  02111-1307 USA
19
20
21 =head1 NAME
22
23 acceptorreject.pl
24
25 =head1 DESCRIPTION
26
27 this script modify the status of a subscription to ACCEPTED or to REJECTED
28
29 =head1 PARAMETERS
30
31 =over 4
32
33 =item title
34
35 =item author
36
37 =item note
38
39 =item copyrightdate
40
41 =item publishercode
42
43 =item volumedesc
44
45 =item publicationyear
46
47 =item place
48
49 =item isbn
50
51 =item status
52
53 =item suggestedbyme
54
55 =item op
56
57 op can be :
58  * aorr_confirm : to confirm accept or reject
59  * delete_confirm : to confirm the deletion
60  * accepted : to display only accepted. 
61  
62 =back
63
64
65 =cut
66
67 use strict;
68 require Exporter;
69 use CGI;
70
71 use C4::Auth;    # get_template_and_user
72 use C4::Output;
73 use C4::Suggestions;
74 use C4::Koha;    # GetAuthorisedValue
75 use C4::Dates qw(format_date);
76
77
78 my $input           = new CGI;
79 my $title           = $input->param('title');
80 my $author          = $input->param('author');
81 my $note            = $input->param('note');
82 my $copyrightdate   = $input->param('copyrightdate');
83 my $publishercode   = $input->param('publishercode');
84 my $volumedesc      = $input->param('volumedesc');
85 my $publicationyear = $input->param('publicationyear');
86 my $place           = $input->param('place');
87 my $isbn            = $input->param('isbn');
88 my $status          = $input->param('status');
89 my $suggestedbyme   = $input->param('suggestedbyme');
90 my $op              = $input->param('op') || "aorr_confirm";
91
92 my $dbh = C4::Context->dbh;
93 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
94     {
95         template_name   => "suggestion/acceptorreject.tmpl",
96         type            => "intranet",
97         query           => $input,
98         authnotrequired => 1,
99         flagsrequired   => { catalogue => 1 },
100     }
101 );
102
103 my $suggestions;
104
105 my $branchcode;
106 my $userenv = C4::Context->userenv;
107 if ($userenv) {
108     unless ($userenv->{flags} == 1){
109         $branchcode=$userenv->{branch};
110     }
111 }
112
113 if ( $op eq "aorr_confirm" ) {
114     my $parameters=$input->Vars;
115     my @deletelist;
116     my $suggestiontype=$parameters->{suggestiontype};
117     foreach my $suggestionid (keys %$parameters){
118         next unless $suggestionid=~/^\d+$/;
119         ## it is a suggestion
120         if ($parameters->{$suggestionid}=~/delete/i){
121            push @deletelist,$suggestionid;    
122         }
123         else {        
124         ## it is not a deletion    
125             ## Get the Reason
126             my $reason = $parameters->{"reason$suggestionid"};
127             if ( $reason eq "other" ) {
128                 $reason = $parameters->{"other-reason$suggestionid"};
129             }
130             unless ($reason){
131                 $reason= $parameters->{"reason".$suggestiontype."all"};
132             if ( $reason eq "other" ) {
133                     $reason = $parameters->{"other-reason".$suggestiontype."all"};
134             }
135             }      
136             ModStatus( $suggestionid, $parameters->{$suggestionid}, $loggedinuser, '', $reason );
137         }
138     }
139     $op = "else";
140     if (scalar(@deletelist)>0){  
141         my $params = "&delete_field=".join ("&delete_field=",@deletelist);
142         warn $params;    
143         print $input->redirect("/cgi-bin/koha/suggestion/acceptorreject.pl?op=delete_confirm$params");
144     }  
145 }
146
147 if ( $op eq "delete_confirm" ) {
148     my @delete_field = $input->param("delete_field");
149     foreach my $delete_field (@delete_field) {
150         &DelSuggestion( $loggedinuser, $delete_field,"intranet" );
151     }
152     $op = 'else';
153 }
154
155 my $reasonsloop = GetAuthorisedValues("SUGGEST");
156 my $pending_suggestions = &SearchSuggestion( "", "", "", "", 'ASKED', "",$branchcode );
157 map{$_->{'reasonsloop'}=$reasonsloop;$_->{'date'}=format_date($_->{'date'})} @$pending_suggestions;
158 my $accepted_suggestions = &GetSuggestionByStatus('ACCEPTED',$branchcode);
159 map{$_->{'reasonsloop'}=$reasonsloop;$_->{'date'}=format_date($_->{'date'})} @$accepted_suggestions;
160 my $rejected_suggestions = &GetSuggestionByStatus('REJECTED',$branchcode);
161 map{$_->{'reasonsloop'}=$reasonsloop;$_->{'date'}=format_date($_->{'date'})} @$rejected_suggestions;
162
163 my @allsuggestions;
164 push @allsuggestions,{"suggestiontype"=>"accepted",
165                     'suggestions_loop'=>$accepted_suggestions,    
166                     'reasonsloop' => $reasonsloop};
167 push @allsuggestions,{"suggestiontype"=>"pending",
168                      'suggestions_loop'=>$pending_suggestions,
169                     'reasonsloop' => $reasonsloop};
170 push @allsuggestions,{"suggestiontype"=>"rejected",
171                      'suggestions_loop'=>$rejected_suggestions,
172                     'reasonsloop' => $reasonsloop};
173
174 $template->param(
175     suggestions       => \@allsuggestions,
176     "op_$op"                => 1,
177     dateformat    => C4::Context->preference("dateformat"),
178 );
179
180 output_html_with_http_headers $input, $cookie, $template->output;