Merge remote-tracking branch 'origin/new/bug_5604'
[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 use strict;
19 #use warnings; FIXME - Bug 2505
20 require Exporter;
21
22 use CGI;
23
24 use C4::Output;
25 use C4::Auth;
26 use C4::Context;
27
28 use C4::RotatingCollections;
29
30 my $query = new CGI;
31 my ($template, $loggedinuser, $cookie)
32     = get_template_and_user({template_name => "rotating_collections/editCollections.tmpl",
33                              query => $query,
34                              type => "intranet",
35                              authnotrequired => 0,
36                              flagsrequired => {parameters => 1},
37                              debug => 1,
38                              });
39
40 # Create new Collection
41 if ( $query->param('action') eq 'create' ) {
42   my $title = $query->param('title');
43   my $description = $query->param('description');
44                             
45   my ( $createdSuccessfully, $errorCode, $errorMessage ) = CreateCollection( $title, $description );
46                               
47   $template->param(
48     previousActionCreate => 1,
49     createdTitle => $title,
50   );
51                                           
52   if ( $createdSuccessfully ) {
53     $template->param( createSuccess => 1 );
54   } else {
55     $template->param( createFailure => 1 );
56     $template->param( failureMessage => $errorMessage );
57   }                                                        
58 }
59
60 ## Delete a club or service
61 elsif ( $query->param('action') eq 'delete' ) {
62   my $colId = $query->param('colId');
63   my ( $success, $errorCode, $errorMessage ) = DeleteCollection( $colId );
64     
65   $template->param( previousActionDelete => 1 );
66   if ( $success ) {
67     $template->param( deleteSuccess => 1 );
68   } else {
69     $template->param( deleteFailure => 1 );
70     $template->param( failureMessage => $errorMessage );
71   }
72 }
73
74 ## Edit a club or service: grab data, put in form.
75 elsif ( $query->param('action') eq 'edit' ) {
76   my $colId = $query->param('colId');
77   my ( $colId, $colTitle, $colDesc, $colBranchcode ) = GetCollection( $colId );
78
79   $template->param(
80       previousActionEdit => 1,
81       editColId => $colId,
82       editColTitle => $colTitle,
83       editColDescription => $colDesc,
84   );
85 }
86
87 # Update a Club or Service
88 elsif ( $query->param('action') eq 'update' ) {
89   my $colId = $query->param('colId');
90   my $title = $query->param('title');
91   my $description = $query->param('description');
92                             
93   my ( $createdSuccessfully, $errorCode, $errorMessage ) 
94     = UpdateCollection( $colId, $title, $description );
95                               
96   $template->param(
97     previousActionUpdate => 1,
98     updatedTitle => $title,
99   );
100                                           
101   if ( $createdSuccessfully ) {
102     $template->param( updateSuccess => 1 );
103   } else {
104     $template->param( updateFailure => 1 );
105     $template->param( failureMessage => $errorMessage );
106   }                                                        
107 }
108                                                         
109 my $collections = GetCollections();
110
111 $template->param(
112                 intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
113                 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
114                 IntranetNav => C4::Context->preference("IntranetNav"),
115                 
116                 collectionsLoop => $collections,
117                 );
118
119 output_html_with_http_headers $query, $cookie, $template->output;