Bug 30585: Fix library options on table settings for course_reserves_table
[koha.git] / admin / oai_sets.pl
1 #!/usr/bin/perl
2
3 # Copyright 2011 BibLibre SARL
4 # This file is part of Koha.
5 #
6 # Koha is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # Koha is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with Koha; if not, see <http://www.gnu.org/licenses>.
18
19 =head1 NAME
20
21 oai_sets.pl
22
23 =head1 DESCRIPTION
24
25 Admin page to describe OAI SETs
26
27 =cut
28
29 use Modern::Perl;
30
31 use CGI qw ( -utf8 );
32 use C4::Auth qw( get_template_and_user );
33 use C4::Output qw( output_html_with_http_headers );
34 use C4::OAI::Sets qw( AddOAISet DelOAISet GetOAISet GetOAISets ModOAISet );
35
36
37 my $input = CGI->new;
38 my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( {
39     template_name   => 'admin/oai_sets.tt',
40     query           => $input,
41     type            => 'intranet',
42     flagsrequired   => { 'parameters' => 'manage_oai_sets' },
43 } );
44
45 my $op = $input->param('op');
46
47 if($op && $op eq "new") {
48     $template->param( op_new => 1 );
49 } elsif($op && $op eq "savenew") {
50     my $spec = $input->param('spec');
51     my $name = $input->param('name');
52     my @descriptions = $input->multi_param('description');
53     AddOAISet({
54         spec => $spec,
55         name => $name,
56         descriptions => \@descriptions
57     });
58 } elsif($op && $op eq "mod") {
59     my $id = $input->param('id');
60     my $set = GetOAISet($id);
61     $template->param(
62         op_mod => 1,
63         id => $set->{'id'},
64         spec => $set->{'spec'},
65         name => $set->{'name'},
66         descriptions => [ map { {description => $_} } @{ $set->{'descriptions'} } ],
67     );
68 } elsif($op && $op eq "savemod") {
69     my $id = $input->param('id');
70     my $spec = $input->param('spec');
71     my $name = $input->param('name');
72     my @descriptions = $input->multi_param('description');
73     ModOAISet({
74         id => $id,
75         spec => $spec,
76         name => $name,
77         descriptions => \@descriptions
78     });
79 } elsif($op && $op eq "del") {
80     my $id = $input->param('id');
81     DelOAISet($id);
82 }
83
84 my $OAISets = GetOAISets;
85 my @sets_loop;
86 foreach(@$OAISets) {
87     push @sets_loop, {
88         id => $_->{'id'},
89         spec => $_->{'spec'},
90         name => $_->{'name'},
91         descriptions => [ map { {description => $_} } @{ $_->{'descriptions'} } ]
92     };
93 }
94
95 $template->param(
96     sets_loop => \@sets_loop,
97 );
98
99 output_html_with_http_headers $input, $cookie, $template->output;