Bug 30477: Add new UNIMARC installer translation files
[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
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17 #
18
19 use Modern::Perl;
20
21 use CGI qw ( -utf8 );
22
23 use C4::Output qw( output_html_with_http_headers );
24 use C4::Auth qw( get_template_and_user );
25 use C4::Context;
26
27 use C4::RotatingCollections;
28
29 my $query = CGI->new;
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         flagsrequired   => { tools => 'rotating_collections' },
37     }
38 );
39
40 my $action = $query->param('action');
41 $template->param( action => $action );
42
43 # Create new Collection
44 if ( $action eq 'create' ) {
45     my $title       = $query->param('title');
46     my $description = $query->param('description');
47
48     my ( $createdSuccessfully, $errorCode, $errorMessage ) =
49       CreateCollection( $title, $description );
50
51     $template->param(
52         previousActionCreate => 1,
53         createdTitle         => $title,
54     );
55
56     if ($createdSuccessfully) {
57         $template->param( createSuccess => 1 );
58     }
59     else {
60         $template->param( createFailure  => 1 );
61         $template->param( failureMessage => $errorMessage );
62     }
63 }
64
65 ## Delete a club or service
66 elsif ( $action eq 'delete' ) {
67     my $colId = $query->param('colId');
68     my ( $success, $errorCode, $errorMessage ) = DeleteCollection($colId);
69
70     $template->param( previousActionDelete => 1 );
71     if ($success) {
72         $template->param( deleteSuccess => 1 );
73     }
74     else {
75         $template->param( deleteFailure  => 1 );
76         $template->param( failureMessage => $errorMessage );
77     }
78 }
79
80 ## Edit a club or service: grab data, put in form.
81 elsif ( $action eq 'edit' ) {
82     my ( $colId, $colTitle, $colDesc, $colBranchcode ) = GetCollection( $query->param('colId') );
83
84     $template->param(
85         previousActionEdit => 1,
86         editColId          => $colId,
87         editColTitle       => $colTitle,
88         editColDescription => $colDesc,
89     );
90 }
91
92 # Update a Club or Service
93 elsif ( $action eq 'update' ) {
94     my $colId       = $query->param('colId');
95     my $title       = $query->param('title');
96     my $description = $query->param('description');
97
98     my ( $createdSuccessfully, $errorCode, $errorMessage ) =
99       UpdateCollection( $colId, $title, $description );
100
101     $template->param(
102         previousActionUpdate => 1,
103         updatedTitle         => $title,
104     );
105
106     if ($createdSuccessfully) {
107         $template->param( updateSuccess => 1 );
108     }
109     else {
110         $template->param( updateFailure  => 1 );
111         $template->param( failureMessage => $errorMessage );
112     }
113 }
114
115 output_html_with_http_headers $query, $cookie, $template->output;