3 # Copyright 2010-2011 MASmedios.com y Ministerio de Cultura
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
24 use C4::Auth qw( check_cookie_auth );
25 use C4::ImportExportFramework qw( createODS ExportFramework ImportFramework );
27 my %cookies = CGI::Cookie->fetch();
29 if (exists $cookies{'CGISESSID'}) {
30 ($auth_status, undef) = check_cookie_auth(
31 $cookies{'CGISESSID'}->value,
32 { parameters => 'manage_marc_frameworks' },
38 unless ($auth_status eq 'ok') {
39 print $input->header(-type => 'text/plain', -status => '403 Forbidden');
43 my $framework_name = $input->param('frameworkcode') || 'default';
44 my $frameworkcode = ($framework_name eq 'default') ? q{} : $framework_name;
45 my $action = $input->param('action') || 'export';
48 if ($action eq 'export' && $input->request_method() eq 'GET') {
50 my $format = $input->param('type_export_' . $frameworkcode);
51 if ($frameworkcode eq 'default') {
52 ExportFramework('', \$strXml, $format, 'biblio');
54 ExportFramework($frameworkcode, \$strXml, $format, 'biblio');
57 if ($format eq 'csv') {
60 # Correctly set the encoding to output plain text in UTF-8
61 binmode(STDOUT,':encoding(UTF-8)');
62 print $input->header(-type => 'application/vnd.ms-excel', -attachment => 'export_' . $framework_name . '.csv');
67 createODS($strXml, 'en', \$strODS);
68 print $input->header(-type => 'application/vnd.oasis.opendocument.spreadsheet', -attachment => 'export_' . $framework_name . '.ods');
72 } elsif ($input->request_method() eq 'POST') {
74 my $fieldname = 'file_import_' . $framework_name;
75 my $filename = $input->param($fieldname);
76 # upload the input file
77 if ($filename && $filename =~ /\.(csv|ods)$/i) {
79 my $uploadFd = $input->upload($fieldname);
80 if ($uploadFd && !$input->cgi_error) {
81 my $tmpfilename = $input->tmpFileName(scalar $input->param($fieldname));
82 $filename = $tmpfilename . '.' . $extension; # rename the tmp file with the extension
83 $ok = ImportFramework($filename, $frameworkcode, 1, 'biblio') if (rename($tmpfilename, $filename));
86 if ($ok >= 0) { # If everything went ok go to the framework marc structure
87 print $input->redirect( -location => '/cgi-bin/koha/admin/marctagstructure.pl?frameworkcode=' . $frameworkcode);
89 # If something failed go to the list of frameworks and show message
90 print $input->redirect( -location => '/cgi-bin/koha/admin/biblio_framework.pl?error_import_export=' . $frameworkcode);