Bug 29144: Adjust libraries form
[koha-ffzg.git] / admin / import_export_authtype.pl
index f31e402..e12bcc7 100755 (executable)
@@ -22,7 +22,7 @@ use CGI qw ( -utf8 );
 use CGI::Cookie;
 use C4::Context;
 use C4::Auth qw/check_cookie_auth/;
-use C4::ImportExportFramework qw( ExportFramework ImportFramework );
+use C4::ImportExportFramework qw( ExportFramework ImportFramework createODS );
 
 my %cookies = CGI::Cookie->fetch();
 my ($auth_status, $sessionID);
@@ -33,7 +33,7 @@ if (exists $cookies{'CGISESSID'}) {
     );
 }
 
-my $input = new CGI;
+my $input = CGI->new;
 
 unless ($auth_status eq 'ok') {
     print $input->header(-type => 'text/plain', -status => '403 Forbidden');
@@ -61,10 +61,6 @@ if ($action eq 'export' && $input->request_method() eq 'GET') {
         binmode(STDOUT,':encoding(UTF-8)');
         print $input->header(-type => 'application/vnd.ms-excel', -attachment => 'export_' . $authtypecode . '.csv');
         print $strXml;
-    } elsif ($format eq 'excel') {
-        # Excel-xml file
-        print $input->header(-type => 'application/excel', -attachment => 'export_' . $authtypecode . '.xml');
-        print $strXml;
     } else {
         # ODS file
         my $strODS = '';
@@ -76,19 +72,30 @@ if ($action eq 'export' && $input->request_method() eq 'GET') {
 } elsif ($input->request_method() eq 'POST') {
     my $ok = -1;
     my $fieldname = 'file_import_' . $authtypecode;
+    if ($authtypecode eq 'default'){
+        $fieldname = 'file_import_';
+    }
     my $filename = $input->param($fieldname);
     # upload the input file
-    if ($filename && $filename =~ /\.(csv|ods|xml)$/i) {
+    if ($filename && $filename =~ /\.(csv|ods)$/i) {
         my $extension = $1;
         my $uploadFd = $input->upload($fieldname);
         if ($uploadFd && !$input->cgi_error) {
             my $tmpfilename = $input->tmpFileName(scalar $input->param($fieldname));
             $filename = $tmpfilename . '.' . $extension; # rename the tmp file with the extension
-            $ok = ImportFramework($filename, $authtypecode, 1, 'authority') if (rename($tmpfilename, $filename));
+            if ($authtypecode eq 'default') {
+                $ok = ImportFramework($filename, '', 1, 'authority') if (rename($tmpfilename, $filename));
+            } else {
+                $ok = ImportFramework($filename, $authtypecode, 1, 'authority') if (rename($tmpfilename, $filename));
+            }
         }
     }
     if ($ok >= 0) { # If everything went ok go to the authority type marc structure
-        print $input->redirect( -location => '/cgi-bin/koha/admin/auth_tag_structure.pl?authtypecode=' . $authtypecode);
+        if ($authtypecode eq 'default'){
+            print $input->redirect( -location => '/cgi-bin/koha/admin/auth_tag_structure.pl?authtypecode=');
+        } else {
+            print $input->redirect( -location => '/cgi-bin/koha/admin/auth_tag_structure.pl?authtypecode=' . $authtypecode);
+        }
     } else {
         # If something failed go to the list of authority types and show message
         print $input->redirect( -location => '/cgi-bin/koha/admin/authtypes.pl?error_import_export=' . $authtypecode);