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