Bug 11401: QA followup
[koha.git] / rotating_collections / editCollections.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
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
8 # version.
9 #
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.
13 #
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
17 #
18
19 use Modern::Perl;
20
21 use CGI;
22
23 use C4::Output;
24 use C4::Auth;
25 use C4::Context;
26
27 use C4::RotatingCollections;
28
29 my $query = new CGI;
30
31 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
32     {
33         template_name   => "rotating_collections/editCollections.tt",
34         query           => $query,
35         type            => "intranet",
36         authnotrequired => 0,
37         flagsrequired   => { tools => 'rotating_collections' },
38         debug           => 1,
39     }
40 );
41
42 my $action = $query->param('action');
43 $template->param( action => $action );
44
45 # Create new Collection
46 if ( $action eq 'create' ) {
47     my $title       = $query->param('title');
48     my $description = $query->param('description');
49
50     my ( $createdSuccessfully, $errorCode, $errorMessage ) =
51       CreateCollection( $title, $description );
52
53     $template->param(
54         previousActionCreate => 1,
55         createdTitle         => $title,
56     );
57
58     if ($createdSuccessfully) {
59         $template->param( createSuccess => 1 );
60     }
61     else {
62         $template->param( createFailure  => 1 );
63         $template->param( failureMessage => $errorMessage );
64     }
65 }
66
67 ## Delete a club or service
68 elsif ( $action eq 'delete' ) {
69     my $colId = $query->param('colId');
70     my ( $success, $errorCode, $errorMessage ) = DeleteCollection($colId);
71
72     $template->param( previousActionDelete => 1 );
73     if ($success) {
74         $template->param( deleteSuccess => 1 );
75     }
76     else {
77         $template->param( deleteFailure  => 1 );
78         $template->param( failureMessage => $errorMessage );
79     }
80 }
81
82 ## Edit a club or service: grab data, put in form.
83 elsif ( $action eq 'edit' ) {
84     my ( $colId, $colTitle, $colDesc, $colBranchcode ) = GetCollection( $query->param('colId') );
85
86     $template->param(
87         previousActionEdit => 1,
88         editColId          => $colId,
89         editColTitle       => $colTitle,
90         editColDescription => $colDesc,
91     );
92 }
93
94 # Update a Club or Service
95 elsif ( $action eq 'update' ) {
96     my $colId       = $query->param('colId');
97     my $title       = $query->param('title');
98     my $description = $query->param('description');
99
100     my ( $createdSuccessfully, $errorCode, $errorMessage ) =
101       UpdateCollection( $colId, $title, $description );
102
103     $template->param(
104         previousActionUpdate => 1,
105         updatedTitle         => $title,
106     );
107
108     if ($createdSuccessfully) {
109         $template->param( updateSuccess => 1 );
110     }
111     else {
112         $template->param( updateFailure  => 1 );
113         $template->param( failureMessage => $errorMessage );
114     }
115 }
116
117 output_html_with_http_headers $query, $cookie, $template->output;