Bug 27748: Encoding problem in link to OverDrive results
[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;
24 use C4::Auth;
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         debug           => 1,
38     }
39 );
40
41 my $action = $query->param('action');
42 $template->param( action => $action );
43
44 # Create new Collection
45 if ( $action eq 'create' ) {
46     my $title       = $query->param('title');
47     my $description = $query->param('description');
48
49     my ( $createdSuccessfully, $errorCode, $errorMessage ) =
50       CreateCollection( $title, $description );
51
52     $template->param(
53         previousActionCreate => 1,
54         createdTitle         => $title,
55     );
56
57     if ($createdSuccessfully) {
58         $template->param( createSuccess => 1 );
59     }
60     else {
61         $template->param( createFailure  => 1 );
62         $template->param( failureMessage => $errorMessage );
63     }
64 }
65
66 ## Delete a club or service
67 elsif ( $action eq 'delete' ) {
68     my $colId = $query->param('colId');
69     my ( $success, $errorCode, $errorMessage ) = DeleteCollection($colId);
70
71     $template->param( previousActionDelete => 1 );
72     if ($success) {
73         $template->param( deleteSuccess => 1 );
74     }
75     else {
76         $template->param( deleteFailure  => 1 );
77         $template->param( failureMessage => $errorMessage );
78     }
79 }
80
81 ## Edit a club or service: grab data, put in form.
82 elsif ( $action eq 'edit' ) {
83     my ( $colId, $colTitle, $colDesc, $colBranchcode ) = GetCollection( $query->param('colId') );
84
85     $template->param(
86         previousActionEdit => 1,
87         editColId          => $colId,
88         editColTitle       => $colTitle,
89         editColDescription => $colDesc,
90     );
91 }
92
93 # Update a Club or Service
94 elsif ( $action eq 'update' ) {
95     my $colId       = $query->param('colId');
96     my $title       = $query->param('title');
97     my $description = $query->param('description');
98
99     my ( $createdSuccessfully, $errorCode, $errorMessage ) =
100       UpdateCollection( $colId, $title, $description );
101
102     $template->param(
103         previousActionUpdate => 1,
104         updatedTitle         => $title,
105     );
106
107     if ($createdSuccessfully) {
108         $template->param( updateSuccess => 1 );
109     }
110     else {
111         $template->param( updateFailure  => 1 );
112         $template->param( failureMessage => $errorMessage );
113     }
114 }
115
116 output_html_with_http_headers $query, $cookie, $template->output;