writing charset explicitly.
[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 # $Id$
21
22 =head1 NAME
23
24 acceptorreject.pl
25
26 =head1 DESCRIPTION
27
28 this script modify the status of a subscription to ACCEPTED or to REJECTED
29
30 =head1 PARAMETERS
31
32 =over 4
33
34 =item title
35
36 =item author
37
38 =item note
39
40 =item copyrightdate
41
42 =item publishercode
43
44 =item volumedesc
45
46 =item publicationyear
47
48 =item place
49
50 =item isbn
51
52 =item status
53
54 =item suggestedbyme
55
56 =item op
57
58 op can be :
59  * aorr_confirm : to confirm accept or reject
60  * delete_confirm : to confirm the deletion
61  * accepted : to display only accepted. 
62  
63 =back
64
65
66 =cut
67
68 use strict;
69 require Exporter;
70 use CGI;
71
72 use C4::Auth;    # get_template_and_user
73 use C4::Output;
74 use C4::Suggestions;
75 use C4::Koha;    # GetAuthorisedValue
76
77 my $input           = new CGI;
78 my $title           = $input->param('title');
79 my $author          = $input->param('author');
80 my $note            = $input->param('note');
81 my $copyrightdate   = $input->param('copyrightdate');
82 my $publishercode   = $input->param('publishercode');
83 my $volumedesc      = $input->param('volumedesc');
84 my $publicationyear = $input->param('publicationyear');
85 my $place           = $input->param('place');
86 my $isbn            = $input->param('isbn');
87 my $status          = $input->param('status');
88 my $suggestedbyme   = $input->param('suggestedbyme');
89 my $op              = $input->param('op') || "aorr_confirm";
90
91 my $dbh = C4::Context->dbh;
92 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
93     {
94         template_name   => "suggestion/acceptorreject.tmpl",
95         type            => "intranet",
96         query           => $input,
97         authnotrequired => 1,
98         flagsrequired   => { catalogue => 1 },
99     }
100 );
101
102 my $suggestions;
103
104 if ( $op eq "aorr_confirm" ) {
105     my @suggestionlist = $input->param("aorr");
106
107     foreach my $suggestion (@suggestionlist) {
108         if ( $suggestion =~ /(A|R)(.*)/ ) {
109             my ( $newstatus, $suggestionid ) = ( $1, $2 );
110             $newstatus = "REJECTED" if $newstatus eq "R";
111             $newstatus = "ACCEPTED" if $newstatus eq "A";
112             my $reason = $input->param( "reason" . $suggestionid );
113             if ( $reason eq "other" ) {
114                 $reason = $input->param( "other-reason" . $suggestionid );
115             }
116             ModStatus( $suggestionid, $newstatus, $loggedinuser, '', $reason );
117         }
118     }
119     $op = "else";
120     $suggestions = &SearchSuggestion( "", "", "", "", 'ASKED', "" );
121 }
122
123 if ( $op eq "delete_confirm" ) {
124     my @delete_field = $input->param("delete_field");
125     foreach my $delete_field (@delete_field) {
126         &DelSuggestion( $loggedinuser, $delete_field );
127     }
128     $op = 'else';
129     $suggestions = &SearchSuggestion( "", "", "", "", 'ASKED', "" );
130 }
131
132 if ( $op eq "accepted" ) {
133     $suggestions = &GetSuggestionByStatus('ACCEPTED');
134     $template->param(done => 1);
135 }
136
137 if ( $op eq "rejected" ) {
138     $suggestions = &GetSuggestionByStatus('REJECTED');
139     $template->param(done => 1);
140 }
141
142 my $reasonsloop = GetAuthorisedValues("SUGGEST");
143 my @suggestions_loop;
144 foreach my $suggestion (@$suggestions) {
145     $suggestion->{'reasonsloop'} = $reasonsloop;
146     push @suggestions_loop, $suggestion;
147 }
148
149 $template->param(
150     suggestions_loop        => \@suggestions_loop,
151     "op_$op"                => 1,
152     intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
153     intranetstylesheet => C4::Context->preference("intranetstylesheet"),
154     IntranetNav        => C4::Context->preference("IntranetNav"),
155 );
156
157 output_html_with_http_headers $input, $cookie, $template->output;