X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=admin%2Fimport_export_framework.pl;h=735915d49fd50b266aba0fad25f720750d79c6a2;hb=9d6d641d1f8b77271800f43bc027b651f9aea52b;hp=555eec5e017e4633f99127a87282f429db02dddb;hpb=03d4ed2468bb9ab97b1f7b7d9e29507dc815a8b3;p=srvgit diff --git a/admin/import_export_framework.pl b/admin/import_export_framework.pl index 555eec5e01..735915d49f 100755 --- a/admin/import_export_framework.pl +++ b/admin/import_export_framework.pl @@ -4,27 +4,26 @@ # # This file is part of Koha. # -# Koha is free software; you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation; either version 2 of the License, or (at your option) any later -# version. +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. # -# Koha is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License along -# with Koha; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . -use strict; -use warnings; -use CGI; +use Modern::Perl; +use CGI qw ( -utf8 ); use CGI::Cookie; use C4::Context; -use C4::Auth qw/check_cookie_auth/; -use C4::ImportExportFramework; +use C4::Auth qw( check_cookie_auth ); +use C4::ImportExportFramework qw( createODS ExportFramework ImportFramework ); my %cookies = CGI::Cookie->fetch(); my $authenticated = 0; @@ -32,58 +31,55 @@ my ($auth_status, $sessionID); if (exists $cookies{'CGISESSID'}) { ($auth_status, $sessionID) = check_cookie_auth( $cookies{'CGISESSID'}->value, - { parameters => 'parameters_remaining_permissions' }, + { parameters => 'manage_marc_frameworks' }, ); } if ($auth_status eq 'ok') { $authenticated = 1; } -my $input = new CGI; +my $input = CGI->new; unless ($authenticated) { print $input->header(-type => 'text/plain', -status => '403 Forbidden'); exit 0; } -my $frameworkcode = $input->param('frameworkcode') || ''; +my $framework_name = $input->param('frameworkcode') || 'default'; +my $frameworkcode = ($framework_name eq 'default') ? q{} : $framework_name; my $action = $input->param('action') || 'export'; ## Exporting if ($action eq 'export' && $input->request_method() eq 'GET') { my $strXml = ''; - my $format = $input->param('type_export_' . $frameworkcode); + my $format = $input->param('type_export_' . $framework_name); ExportFramework($frameworkcode, \$strXml, $format); + if ($format eq 'csv') { # CSV file - print $input->header(-type => 'application/vnd.ms-excel', -attachment => 'export_' . $frameworkcode . '.csv'); - print $strXml; - } elsif ($format eq 'sql') { - # SQL file - print $input->header(-type => 'text/plain', -attachment => 'export_' . $frameworkcode . '.sql'); - print $strXml; - } elsif ($format eq 'excel') { - # Excel-xml file - print $input->header(-type => 'application/excel', -attachment => 'export_' . $frameworkcode . '.xml'); + + # Correctly set the encoding to output plain text in UTF-8 + binmode(STDOUT,':encoding(UTF-8)'); + print $input->header(-type => 'application/vnd.ms-excel', -attachment => 'export_' . $framework_name . '.csv'); print $strXml; } else { # ODS file my $strODS = ''; createODS($strXml, 'en', \$strODS); - print $input->header(-type => 'application/vnd.oasis.opendocument.spreadsheet', -attachment => 'export_' . $frameworkcode . '.ods'); + print $input->header(-type => 'application/vnd.oasis.opendocument.spreadsheet', -attachment => 'export_' . $framework_name . '.ods'); print $strODS; } ## Importing } elsif ($input->request_method() eq 'POST') { my $ok = -1; - my $fieldname = 'file_import_' . $frameworkcode; + my $fieldname = 'file_import_' . $framework_name; my $filename = $input->param($fieldname); # upload the input file - if ($filename && $filename =~ /\.(csv|ods|xml|sql)$/i) { + if ($filename && $filename =~ /\.(csv|ods)$/i) { my $extension = $1; my $uploadFd = $input->upload($fieldname); if ($uploadFd && !$input->cgi_error) { - my $tmpfilename = $input->tmpFileName($input->param($fieldname)); + my $tmpfilename = $input->tmpFileName(scalar $input->param($fieldname)); $filename = $tmpfilename . '.' . $extension; # rename the tmp file with the extension $ok = ImportFramework($filename, $frameworkcode, 1) if (rename($tmpfilename, $filename)); }