2d5aa50883b8a2c6b96999f38afe8a98e5553da0
[srvgit] / 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;
33 use C4::Output;
34 use C4::OAI::Sets;
35
36 use Data::Dumper;
37
38 my $input = CGI->new;
39 my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( {
40     template_name   => 'admin/oai_sets.tt',
41     query           => $input,
42     type            => 'intranet',
43     flagsrequired   => { 'parameters' => 'manage_oai_sets' },
44 } );
45
46 my $op = $input->param('op');
47
48 if($op && $op eq "new") {
49     $template->param( op_new => 1 );
50 } elsif($op && $op eq "savenew") {
51     my $spec = $input->param('spec');
52     my $name = $input->param('name');
53     my @descriptions = $input->multi_param('description');
54     AddOAISet({
55         spec => $spec,
56         name => $name,
57         descriptions => \@descriptions
58     });
59 } elsif($op && $op eq "mod") {
60     my $id = $input->param('id');
61     my $set = GetOAISet($id);
62     $template->param(
63         op_mod => 1,
64         id => $set->{'id'},
65         spec => $set->{'spec'},
66         name => $set->{'name'},
67         descriptions => [ map { {description => $_} } @{ $set->{'descriptions'} } ],
68     );
69 } elsif($op && $op eq "savemod") {
70     my $id = $input->param('id');
71     my $spec = $input->param('spec');
72     my $name = $input->param('name');
73     my @descriptions = $input->multi_param('description');
74     ModOAISet({
75         id => $id,
76         spec => $spec,
77         name => $name,
78         descriptions => \@descriptions
79     });
80 } elsif($op && $op eq "del") {
81     my $id = $input->param('id');
82     DelOAISet($id);
83 }
84
85 my $OAISets = GetOAISets;
86 my @sets_loop;
87 foreach(@$OAISets) {
88     push @sets_loop, {
89         id => $_->{'id'},
90         spec => $_->{'spec'},
91         name => $_->{'name'},
92         descriptions => [ map { {description => $_} } @{ $_->{'descriptions'} } ]
93     };
94 }
95
96 $template->param(
97     sets_loop => \@sets_loop,
98 );
99
100 output_html_with_http_headers $input, $cookie, $template->output;