Merge branch 'new/bug_5307' into kcmaster
[wip/koha-chris_n.git] / rotating_collections / editCollections.pl
1 #!/usr/bin/perl
2
3 use strict;
4 #use warnings; FIXME - Bug 2505
5 require Exporter;
6
7 use CGI;
8
9 use C4::Output;
10 use C4::Auth;
11 use C4::Context;
12
13 use C4::RotatingCollections;
14
15 my $query = new CGI;
16 my ($template, $loggedinuser, $cookie)
17     = get_template_and_user({template_name => "rotating_collections/editCollections.tmpl",
18                              query => $query,
19                              type => "intranet",
20                              authnotrequired => 1,
21                              flagsrequired => {parameters => 1},
22                              debug => 1,
23                              });
24
25 # Create new Collection
26 if ( $query->param('action') eq 'create' ) {
27   my $title = $query->param('title');
28   my $description = $query->param('description');
29                             
30   my ( $createdSuccessfully, $errorCode, $errorMessage ) = CreateCollection( $title, $description );
31                               
32   $template->param(
33     previousActionCreate => 1,
34     createdTitle => $title,
35   );
36                                           
37   if ( $createdSuccessfully ) {
38     $template->param( createSuccess => 1 );
39   } else {
40     $template->param( createFailure => 1 );
41     $template->param( failureMessage => $errorMessage );
42   }                                                        
43 }
44
45 ## Delete a club or service
46 elsif ( $query->param('action') eq 'delete' ) {
47   my $colId = $query->param('colId');
48   my ( $success, $errorCode, $errorMessage ) = DeleteCollection( $colId );
49     
50   $template->param( previousActionDelete => 1 );
51   if ( $success ) {
52     $template->param( deleteSuccess => 1 );
53   } else {
54     $template->param( deleteFailure => 1 );
55     $template->param( failureMessage => $errorMessage );
56   }
57 }
58
59 ## Edit a club or service: grab data, put in form.
60 elsif ( $query->param('action') eq 'edit' ) {
61   my $colId = $query->param('colId');
62   my ( $colId, $colTitle, $colDesc, $colBranchcode ) = GetCollection( $colId );
63
64   $template->param(
65       previousActionEdit => 1,
66       editColId => $colId,
67       editColTitle => $colTitle,
68       editColDescription => $colDesc,
69   );
70 }
71
72 # Update a Club or Service
73 elsif ( $query->param('action') eq 'update' ) {
74   my $colId = $query->param('colId');
75   my $title = $query->param('title');
76   my $description = $query->param('description');
77                             
78   my ( $createdSuccessfully, $errorCode, $errorMessage ) 
79     = UpdateCollection( $colId, $title, $description );
80                               
81   $template->param(
82     previousActionUpdate => 1,
83     updatedTitle => $title,
84   );
85                                           
86   if ( $createdSuccessfully ) {
87     $template->param( updateSuccess => 1 );
88   } else {
89     $template->param( updateFailure => 1 );
90     $template->param( failureMessage => $errorMessage );
91   }                                                        
92 }
93                                                         
94 my $collections = GetCollections();
95
96 $template->param(
97                 intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
98                 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
99                 IntranetNav => C4::Context->preference("IntranetNav"),
100                 
101                 collectionsLoop => $collections,
102                 );
103
104 output_html_with_http_headers $query, $cookie, $template->output;