View | Details | Raw Unified | Return to bug 13952
Collapse All | Expand All

(-)a/C4/ImportExportFramework.pm (-22 / +43 lines)
Lines 193-199 Functions for handling import/export. Link Here
193
193
194
=head2 ExportFramework
194
=head2 ExportFramework
195
195
196
Export all the information of a Framework to an excel "xml" file or OpenDocument SpreadSheet "ods" file.
196
Export all the information of a MARC or Authority Type Framework to an excel "xml" file, comma separated values "csv" file or OpenDocument SpreadSheet "ods" file.
197
197
198
return :
198
return :
199
succes
199
succes
Lines 202-208 succes Link Here
202
202
203
sub ExportFramework
203
sub ExportFramework
204
{
204
{
205
    my ($frameworkcode, $xmlStrRef, $mode) = @_;
205
    my ($frameworkcode, $xmlStrRef, $mode, $frameworktype) = @_;
206
206
207
    my $dbh = C4::Context->dbh;
207
    my $dbh = C4::Context->dbh;
208
    if ($dbh) {
208
    if ($dbh) {
Lines 229-236 sub ExportFramework Link Here
229
            }
229
            }
230
        }
230
        }
231
231
232
        if (_export_table('marc_tag_structure', $dbh, ($mode eq 'csv')?$xmlStrRef:$dom, ($mode eq 'ods')?$elementSS:$root, $frameworkcode, $mode)) {
232
        my $table = 'marc_tag_structure';
233
            if (_export_table('marc_subfield_structure', $dbh, ($mode eq 'csv')?$xmlStrRef:$dom, ($mode eq 'ods')?$elementSS:$root, $frameworkcode, $mode)) {
233
        my $subtable = 'marc_subfield_structure';
234
        if ($frameworktype eq "authority") {
235
            $table = 'auth_tag_structure';
236
            $subtable = 'auth_subfield_structure';
237
        }
238
239
        if (_export_table($table, $dbh, ($mode eq 'csv')?$xmlStrRef:$dom, ($mode eq 'ods')?$elementSS:$root, $frameworkcode, $mode, $frameworktype)) {
240
            if (_export_table($subtable, $dbh, ($mode eq 'csv')?$xmlStrRef:$dom, ($mode eq 'ods')?$elementSS:$root, $frameworkcode, $mode, $frameworktype)) {
234
                $$xmlStrRef = $dom->toString(1) if ($mode eq 'ods' || $mode eq 'excel');
241
                $$xmlStrRef = $dom->toString(1) if ($mode eq 'ods' || $mode eq 'excel');
235
                return 1;
242
                return 1;
236
            }
243
            }
Lines 245-264 sub ExportFramework Link Here
245
# Export all the data from a mysql table to an spreadsheet.
252
# Export all the data from a mysql table to an spreadsheet.
246
sub _export_table
253
sub _export_table
247
{
254
{
248
    my ($table, $dbh, $dom, $root, $frameworkcode, $mode) = @_;
255
    my ($table, $dbh, $dom, $root, $frameworkcode, $mode, $frameworktype) = @_;
249
    if ($mode eq 'csv') {
256
    if ($mode eq 'csv') {
250
        _export_table_csv($table, $dbh, $dom, $root, $frameworkcode);
257
        _export_table_csv($table, $dbh, $dom, $root, $frameworkcode, $frameworktype);
251
    } elsif ($mode eq 'ods') {
258
    } elsif ($mode eq 'ods') {
252
        _export_table_ods($table, $dbh, $dom, $root, $frameworkcode);
259
        _export_table_ods($table, $dbh, $dom, $root, $frameworkcode, $frameworktype);
253
    } else {
260
    } else {
254
        _export_table_excel($table, $dbh, $dom, $root, $frameworkcode);
261
        _export_table_excel($table, $dbh, $dom, $root, $frameworkcode, $frameworktype);
255
    }
262
    }
256
}
263
}
257
264
258
# Export the mysql table to an csv file
265
# Export the mysql table to an csv file
259
sub _export_table_csv
266
sub _export_table_csv
260
{
267
{
261
    my ($table, $dbh, $strCSV, $root, $frameworkcode) = @_;
268
    my ($table, $dbh, $strCSV, $root, $frameworkcode, $frameworktype) = @_;
262
269
263
    eval {
270
    eval {
264
        # First row with the name of the columns
271
        # First row with the name of the columns
Lines 274-279 sub _export_table_csv Link Here
274
        $$strCSV .= chr(10);
281
        $$strCSV .= chr(10);
275
        # Populate rows with the data from mysql
282
        # Populate rows with the data from mysql
276
        $query = 'SELECT * FROM ' . $table . ' WHERE frameworkcode=?';
283
        $query = 'SELECT * FROM ' . $table . ' WHERE frameworkcode=?';
284
        if ($frameworktype eq "authority") {
285
            $query = 'SELECT * FROM ' . $table . ' WHERE authtypecode=?';
286
        }
277
        $sth = $dbh->prepare($query);
287
        $sth = $dbh->prepare($query);
278
        $sth->execute($frameworkcode);
288
        $sth->execute($frameworkcode);
279
        my $data;
289
        my $data;
Lines 306-312 sub _export_table_csv Link Here
306
# Export the mysql table to an ods file
316
# Export the mysql table to an ods file
307
sub _export_table_ods
317
sub _export_table_ods
308
{
318
{
309
    my ($table, $dbh, $dom, $root, $frameworkcode) = @_;
319
    my ($table, $dbh, $dom, $root, $frameworkcode, $frameworktype) = @_;
310
320
311
    eval {
321
    eval {
312
        my $elementTable = $dom->createElement('table:table');
322
        my $elementTable = $dom->createElement('table:table');
Lines 335-340 sub _export_table_ods Link Here
335
        }
345
        }
336
        # Populate rows with the data from mysql
346
        # Populate rows with the data from mysql
337
        $query = 'SELECT * FROM ' . $table . ' WHERE frameworkcode=?';
347
        $query = 'SELECT * FROM ' . $table . ' WHERE frameworkcode=?';
348
        if ($frameworktype eq "authority") {
349
            $query = 'SELECT * FROM ' . $table . ' WHERE authtypecode=?';
350
        }
338
        $sth = $dbh->prepare($query);
351
        $sth = $dbh->prepare($query);
339
        $sth->execute($frameworkcode);
352
        $sth->execute($frameworkcode);
340
        my $data;
353
        my $data;
Lines 372-378 sub _export_table_ods Link Here
372
# Export the mysql table to an excel-xml (openoffice/libreoffice compatible) file
385
# Export the mysql table to an excel-xml (openoffice/libreoffice compatible) file
373
sub _export_table_excel
386
sub _export_table_excel
374
{
387
{
375
    my ($table, $dbh, $dom, $root, $frameworkcode) = @_;
388
    my ($table, $dbh, $dom, $root, $frameworkcode, $frameworktype) = @_;
376
389
377
    eval {
390
    eval {
378
        my $elementWS = $dom->createElement('Worksheet');
391
        my $elementWS = $dom->createElement('Worksheet');
Lines 402-407 sub _export_table_excel Link Here
402
        }
415
        }
403
        # Populate rows with the data from mysql
416
        # Populate rows with the data from mysql
404
        $query = 'SELECT * FROM ' . $table . ' WHERE frameworkcode=?';
417
        $query = 'SELECT * FROM ' . $table . ' WHERE frameworkcode=?';
418
        if ($frameworktype eq "authority") {
419
            $query = 'SELECT * FROM ' . $table . ' WHERE authtypecode=?';
420
        }
405
        $sth = $dbh->prepare($query);
421
        $sth = $dbh->prepare($query);
406
        $sth->execute($frameworkcode);
422
        $sth->execute($frameworkcode);
407
        my $data;
423
        my $data;
Lines 433-444 sub _export_table_excel Link Here
433
    return 1;
449
    return 1;
434
}#_export_table_excel
450
}#_export_table_excel
435
451
436
437
438
439
440
441
442
# Format chars problematics to a correct format for xml.
452
# Format chars problematics to a correct format for xml.
443
sub _parseContent2Xml
453
sub _parseContent2Xml
444
{
454
{
Lines 623-629 sub _getMeta Link Here
623
633
624
=head2 ImportFramework
634
=head2 ImportFramework
625
635
626
Import all the information of a Framework from a excel-xml/ods file.
636
Import all the information of a MARC or Authority Type Framework from a excel-xml/ods file.
627
637
628
return :
638
return :
629
success
639
success
Lines 632-638 success Link Here
632
642
633
sub ImportFramework
643
sub ImportFramework
634
{
644
{
635
    my ($filename, $frameworkcode, $deleteFilename) = @_;
645
    my ($filename, $frameworkcode, $deleteFilename, $frameworktype) = @_;
636
646
637
    my $tempdir;
647
    my $tempdir;
638
    my $ok = -1;
648
    my $ok = -1;
Lines 662-674 sub ImportFramework Link Here
662
                    # They are text files, so open it to read
672
                    # They are text files, so open it to read
663
                    open($dom, '<', $filename);
673
                    open($dom, '<', $filename);
664
                }
674
                }
675
676
                my $table = 'marc_tag_structure';
677
                my $subtable = 'marc_subfield_structure';
678
                if ($frameworktype eq "authority") {
679
                    $table = 'auth_tag_structure';
680
                    $subtable = 'auth_subfield_structure';
681
                }
682
665
                if ($dom) {
683
                if ($dom) {
666
                    # Process both tables
684
                    # Process both tables
667
                    my $numDeleted = 0;
685
                    my $numDeleted = 0;
668
                    my $numDeletedAux = 0;
686
                    my $numDeletedAux = 0;
669
                    if (($numDeletedAux = _import_table($dbh, 'marc_tag_structure', $frameworkcode, $dom, ['frameworkcode', 'tagfield'], $extension)) >= 0) {
687
                    if (($numDeletedAux = _import_table($dbh, $table, $frameworkcode, $dom, ['frameworkcode', 'tagfield'], $extension, $frameworktype)) >= 0) {
670
                        $numDeleted += $numDeletedAux if ($numDeletedAux > 0);
688
                        $numDeleted += $numDeletedAux if ($numDeletedAux > 0);
671
                        if (($numDeletedAux = _import_table($dbh, 'marc_subfield_structure', $frameworkcode, $dom, ['frameworkcode', 'tagfield', 'tagsubfield'], $extension)) >= 0) {
689
                        if (($numDeletedAux = _import_table($dbh, $subtable, $frameworkcode, $dom, ['frameworkcode', 'tagfield', 'tagsubfield'], $extension, $frameworktype)) >= 0) {
672
                            $numDeleted += $numDeletedAux if ($numDeletedAux > 0);
690
                            $numDeleted += $numDeletedAux if ($numDeletedAux > 0);
673
                            $ok = ($numDeleted > 0)?$numDeleted:0;
691
                            $ok = ($numDeleted > 0)?$numDeleted:0;
674
                        }
692
                        }
Lines 789-795 sub _check_validity_worksheet Link Here
789
# Import the data from an excel-xml/ods to mysql tables.
807
# Import the data from an excel-xml/ods to mysql tables.
790
sub _import_table
808
sub _import_table
791
{
809
{
792
    my ($dbh, $table, $frameworkcode, $dom, $PKArray, $format) = @_;
810
    my ($dbh, $table, $frameworkcode, $dom, $PKArray, $format, $frameworktype) = @_;
793
    my %fields2Delete;
811
    my %fields2Delete;
794
    my $query;
812
    my $query;
795
    my @fields;
813
    my @fields;
Lines 798-803 sub _import_table Link Here
798
        @fields = @$PKArray;
816
        @fields = @$PKArray;
799
        shift @fields;
817
        shift @fields;
800
        $query = 'SELECT ' . join(',', @fields) . ' FROM ' . $table . ' WHERE frameworkcode=?';
818
        $query = 'SELECT ' . join(',', @fields) . ' FROM ' . $table . ' WHERE frameworkcode=?';
819
        if ($frameworktype eq "authority") {
820
            $query = 'SELECT ' . join(',', @fields) . ' FROM ' . $table . ' WHERE authtypecode=?';
821
        }
801
        my $sth = $dbh->prepare($query);
822
        my $sth = $dbh->prepare($query);
802
        $sth->execute($frameworkcode);
823
        $sth->execute($frameworkcode);
803
        my $field;
824
        my $field;
(-)a/admin/import_export_authtype.pl (+102 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2016 Aleisha Amohia <aleisha@catalyst.net.nz>
4
#
5
# This file is part of Koha.
6
#
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.
11
#
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.
16
#
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>.
19
20
21
use strict;
22
use warnings;
23
use CGI qw ( -utf8 );
24
use CGI::Cookie;
25
use C4::Context;
26
use C4::Auth qw/check_cookie_auth/;
27
use C4::ImportExportFramework;
28
29
my %cookies = CGI::Cookie->fetch();
30
my $authenticated = 0;
31
my ($auth_status, $sessionID);
32
if (exists $cookies{'CGISESSID'}) {
33
    ($auth_status, $sessionID) = check_cookie_auth(
34
        $cookies{'CGISESSID'}->value,
35
        { parameters => 'parameters_remaining_permissions' },
36
    );
37
}
38
if ($auth_status eq 'ok') {
39
    $authenticated = 1;
40
}
41
42
my $input = new CGI;
43
44
unless ($authenticated) {
45
    print $input->header(-type => 'text/plain', -status => '403 Forbidden');
46
    exit 0;
47
}
48
49
my $authtypecode = $input->param('authtypecode') || 'default';
50
my $action = $input->param('action') || 'export';
51
52
## Exporting
53
if ($action eq 'export' && $input->request_method() eq 'GET') {
54
    my $strXml = '';
55
    my $format = $input->param('type_export_' . $authtypecode);
56
    if ($authtypecode eq 'default') {
57
        $format = $input->param('type_export_');
58
        ExportFramework('', \$strXml, $format, 'authority');
59
    } else {
60
        ExportFramework($authtypecode, \$strXml, $format, 'authority');
61
    }
62
63
    if ($format eq 'csv') {
64
        # CSV file
65
66
        # Correctly set the encoding to output plain text in UTF-8
67
        binmode(STDOUT,':encoding(UTF-8)');
68
        print $input->header(-type => 'application/vnd.ms-excel', -attachment => 'export_' . $authtypecode . '.csv');
69
        print $strXml;
70
    } elsif ($format eq 'excel') {
71
        # Excel-xml file
72
        print $input->header(-type => 'application/excel', -attachment => 'export_' . $authtypecode . '.xml');
73
        print $strXml;
74
    } else {
75
        # ODS file
76
        my $strODS = '';
77
        createODS($strXml, 'en', \$strODS);
78
        print $input->header(-type => 'application/vnd.oasis.opendocument.spreadsheet', -attachment => 'export_' . $authtypecode . '.ods');
79
        print $strODS;
80
    }
81
## Importing
82
} elsif ($input->request_method() eq 'POST') {
83
    my $ok = -1;
84
    my $fieldname = 'file_import_' . $authtypecode;
85
    my $filename = $input->param($fieldname);
86
    # upload the input file
87
    if ($filename && $filename =~ /\.(csv|ods|xml)$/i) {
88
        my $extension = $1;
89
        my $uploadFd = $input->upload($fieldname);
90
        if ($uploadFd && !$input->cgi_error) {
91
            my $tmpfilename = $input->tmpFileName($input->param($fieldname));
92
            $filename = $tmpfilename . '.' . $extension; # rename the tmp file with the extension
93
            $ok = ImportFramework($filename, $authtypecode, 1, 'authority') if (rename($tmpfilename, $filename));
94
        }
95
    }
96
    if ($ok >= 0) { # If everything went ok go to the authority type marc structure
97
        print $input->redirect( -location => '/cgi-bin/koha/admin/auth_tag_structure.pl?authtypecode=' . $authtypecode);
98
    } else {
99
        # If something failed go to the list of authority types and show message
100
        print $input->redirect( -location => '/cgi-bin/koha/admin/authtypes.pl?error_import_export=' . $authtypecode);
101
    }
102
}
(-)a/admin/import_export_framework.pl (-3 / +7 lines)
Lines 52-59 my $action = $input->param('action') || 'export'; Link Here
52
## Exporting
52
## Exporting
53
if ($action eq 'export' && $input->request_method() eq 'GET') {
53
if ($action eq 'export' && $input->request_method() eq 'GET') {
54
    my $strXml = '';
54
    my $strXml = '';
55
    my $format = $input->param('type_export_' . $framework_name);
55
    my $format = $input->param('type_export_' . $frameworkcode);
56
    ExportFramework($frameworkcode, \$strXml, $format);
56
    if ($frameworkcode eq 'default') {
57
        ExportFramework('', \$strXml, $format, 'biblio');
58
    } else {
59
        ExportFramework($frameworkcode, \$strXml, $format, 'biblio');
60
    }
57
61
58
    if ($format eq 'csv') {
62
    if ($format eq 'csv') {
59
        # CSV file
63
        # CSV file
Lines 85-91 if ($action eq 'export' && $input->request_method() eq 'GET') { Link Here
85
        if ($uploadFd && !$input->cgi_error) {
89
        if ($uploadFd && !$input->cgi_error) {
86
            my $tmpfilename = $input->tmpFileName(scalar $input->param($fieldname));
90
            my $tmpfilename = $input->tmpFileName(scalar $input->param($fieldname));
87
            $filename = $tmpfilename . '.' . $extension; # rename the tmp file with the extension
91
            $filename = $tmpfilename . '.' . $extension; # rename the tmp file with the extension
88
            $ok = ImportFramework($filename, $frameworkcode, 1) if (rename($tmpfilename, $filename));
92
            $ok = ImportFramework($filename, $frameworkcode, 1, 'biblio') if (rename($tmpfilename, $filename));
89
        }
93
        }
90
    }
94
    }
91
    if ($ok >= 0) { # If everything went ok go to the framework marc structure
95
    if ($ok >= 0) { # If everything went ok go to the framework marc structure
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authtypes.tt (-10 / +131 lines)
Lines 150-164 Link Here
150
                <td>[% authority_type.summary | html %]</td>
150
                <td>[% authority_type.summary | html %]</td>
151
                <td>[% authority_type.auth_tag_to_report | html %]</td>
151
                <td>[% authority_type.auth_tag_to_report | html %]</td>
152
                <td>
152
                <td>
153
                  <div class="dropdown">
153
                    <div class="dropdown">
154
                    <a class="btn btn-default btn-xs dropdown-toggle" id="authtypeactions[% authority_type.authtypecode | html %]" role="button" data-toggle="dropdown" href="#">
154
                        <a class="btn btn-default btn-xs dropdown-toggle" id="authtypeactions[% authority_type.authtypecode | html %]" role="button" data-toggle="dropdown" href="#">
155
                      Actions <b class="caret"></b></a>
155
                        Actions <b class="caret"></b></a>
156
                    <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="authtypeactions[% authority_type.authtypecode | html %]">
156
                        <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="authtypeactions[% authority_type.authtypecode | html %]">
157
                      <li><a href="auth_tag_structure.pl?authtypecode=[% authority_type.authtypecode | uri %]" class="button parameters"><i class="fa fa-eye"></i> MARC structure</a></li>
157
                            <li><a href="auth_tag_structure.pl?authtypecode=[% authority_type.authtypecode | uri %]" class="button parameters"><i class="fa fa-eye"></i> MARC structure</a></li>
158
                      <li><a href="/cgi-bin/koha/admin/authtypes.pl?op=add_form&amp;authtypecode=[% authority_type.authtypecode | uri %]"><i class="fa fa-pencil"></i> Edit</a></li>
158
                            <li><a href="/cgi-bin/koha/admin/authtypes.pl?op=add_form&amp;authtypecode=[% authority_type.authtypecode | uri %]"><i class="fa fa-pencil"></i> Edit</a></li>
159
                      [% IF authority_type.authtypecode %]<li><a href="/cgi-bin/koha/admin/authtypes.pl?op=delete_confirm&amp;authtypecode=[% authority_type.authtypecode | uri %]"><i class="fa fa-trash"></i> Delete</a></li>[% END %]
159
                            [% IF authority_type.authtypecode %]<li><a href="/cgi-bin/koha/admin/authtypes.pl?op=delete_confirm&amp;authtypecode=[% authority_type.authtypecode | uri %]"><i class="fa fa-trash"></i> Delete</a></li>[% END %]
160
                    </ul>
160
                            <!-- Button to trigger modal -->
161
                  </div>
161
                            <li><a href="#" data-toggle="modal" data-target="#exportModal_[% authority_type.authtypecode %][% loop.count %]" title="Export authority type (fields, subfields) to a spreadsheet file (.csv, .xml, .ods)"><i class="fa fa-upload"></i> Export</a></li>
162
                            <!-- Button to trigger modal -->
163
                            <li><a href="#" data-toggle="modal" data-target="#importModal_[% authority_type.authtypecode %][% loop.count %]" title="Import authority type (fields, subfields) from a spreadsheet file (.csv, .xml, .ods)"><i class="fa fa-download"></i> Import</a></li>
164
                        </ul>
165
166
                        <!-- Modal for export -->
167
                        <div class="modal" id="exportModal_[% authority_type.authtypecode %][% loop.count %]" tabindex="-1" role="dialog" aria-labelledby="exportLabelexportModal_[% authority_type.authtypecode %][% loop.count %]" aria-hidden="true">
168
                        <div class="modal-dialog">
169
                        <div class="modal-content">
170
                        <div class="modal-header">
171
                            <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
172
                            <h3 id="exportLabelexportModal_[% authority_type.authtypecode %][% loop.count %]">Export [% authority_type.authtypetext %] authority type</h3>
173
                        </div>
174
                        <form action="import_export_authtype.pl" name="form_[% authority_type.authtypecode %]" method="get" target="_blank" class="form_export">
175
                            <div class="modal-body">
176
                                <fieldset>
177
                                    <input type="hidden" name="authtypecode" value="[% authority_type.authtypecode %]" />
178
                                    <p><label for="csv_type_export_[% authority_type.authtypecode %][% loop.count %]"><input type="radio" name="type_export_[% authority_type.authtypecode %]" value="csv" id="csv_type_export_[% authority_type.authtypecode %][% loop.count %]" checked="checked" /> Export to CSV spreadsheet</label></p>
179
                                    <p><label for="xml_type_export_[% authority_type.authtypecode %][% loop.count %]"><input type="radio" name="type_export_[% authority_type.authtypecode %]" value="excel" id="xml_type_export_[% authority_type.authtypecode %][% loop.count %]" /> Export to Excel with XML format, compatible with OpenOffice/LibreOffice as well</label></p>
180
                                    <p><label for="ods_type_export_[% authority_type.authtypecode %][% loop.count %]"><input type="radio" name="type_export_[% authority_type.authtypecode %]" value="ods" id="ods_type_export_[% authority_type.authtypecode %][% loop.count %]" /> Export to OpenDocument spreadsheet format</label></p>
181
                                </fieldset>
182
                            </div>
183
                            <div class="modal-footer">
184
                                <button type="submit" class="btn btn-default">Export</button>
185
                                <button class="btn btn-link" data-dismiss="modal" aria-hidden="true">Cancel</button>
186
                            </div>
187
                        </form>
188
                        </div>
189
                        </div>
190
                        </div>
191
192
                        <!-- Modal for import -->
193
                        <div class="modal" id="importModal_[% authority_type.authtypecode %][% loop.count %]" tabindex="-1" role="dialog" aria-labelledby="importLabelexportModal_[% authority_type.authtypecode %][% loop.count %]" aria-hidden="true">
194
                            <div class="modal-dialog">
195
                            <div class="modal-content">
196
                            <div class="modal-header">
197
                                <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
198
                                <h3 id="importLabelexportModal_[% authority_type.authtypecode %][% loop.count %]">Import [% authority_type.authtypecode %] authority type (fields and subfields) from a spreadsheet file (.csv, .xml, .ods)</h3>
199
                            </div>
200
                            <form action="/cgi-bin/koha/admin/import_export_authtype.pl" name="form_i_[% authority_type.authtypecode %]" id="form_i_[% authority_type.authtypecode %]" method="post" enctype="multipart/form-data" class="form_import">
201
                                <div class="modal-body">
202
                                    <input type="hidden" name="authtypecode" value="[% authority_type.authtypecode %]" />
203
                                    <input type="hidden" name="action" value="import" />
204
                                    <p><label for="file_import_[% authority_type.authtypecode %]">Upload file:</label> <input type="file" name="file_import_[% authority_type.authtypecode %]" id="file_import_[% authority_type.authtypecode %]" class="input_import" /></p>
205
                                    <div id="importing_[% authority_type.authtypecode %]" style="display:none" class="importing"><img src="[% interface %]/[% theme %]/img/loading-small.gif" alt="" /><span class="importing_msg"></span></div>
206
                                </div>
207
                                <div class="modal-footer">
208
                                    <button type="submit" class="btn btn-default">Import</button>
209
                                    <button class="btn btn-link" data-dismiss="modal" aria-hidden="true">Close</button>
210
                                </div>
211
                            </form>
212
                            </div>
213
                            </div>
214
                        </div>
215
                    </div>
162
                </td>
216
                </td>
163
            </tr>
217
            </tr>
164
        [% END %]
218
        [% END %]
Lines 180-195 Link Here
180
    [% INCLUDE 'datatables.inc' %]
234
    [% INCLUDE 'datatables.inc' %]
181
    [% Asset.js("js/admin-menu.js") | $raw %]
235
    [% Asset.js("js/admin-menu.js") | $raw %]
182
    <script>
236
    <script>
237
        var importing = false;
238
183
        $(document).ready(function() {
239
        $(document).ready(function() {
184
            $("#authtypes").dataTable($.extend(true, {}, dataTablesDefaults, {
240
            $("#authtypes").dataTable($.extend(true, {}, dataTablesDefaults, {
185
                "aoColumnDefs": [
241
                "aoColumnDefs": [
186
                    { "aTargets": [ -1 ], "bSortable": false, "bSearchable": false },
242
                    { "aTargets": [ -1 ], "bSortable": false, "bSearchable": false },
243
                    { "aTargets": [ 0, 1 ], "sType": "natural" },
187
                ],
244
                ],
245
                "bSort": true,
188
                "sPaginationType": "four_button"
246
                "sPaginationType": "four_button"
189
            }));
247
            }));
190
            $("#authtypecode").on("blur",function(){
248
            $("#authtypecode").on("blur",function(){
191
                toUC(this);
249
                toUC(this);
192
            });
250
            });
251
252
            $("body").css("cursor", "auto");
253
            $('.import_export_options').hide();
254
            $('a.import_export_fw').click(function() {
255
                if (!importing) {
256
                    $('.import_export_options').hide();
257
                    $(this).next().show('slide');
258
                }
259
                return false;
260
            });
261
262
            $('.import_export_close').click(function() {
263
                if (!importing) {
264
                    $('.import_export_options').fadeOut('fast');
265
                    $("body").css("cursor", "auto");
266
                    return false;
267
                }
268
            });
269
            $('.input_import').val("");
270
271
            var matches = new RegExp("\\?error_import_export=(.+)$").exec(window.location.search);
272
            if (matches && matches.length > 1) {
273
                alert(_("Error importing the authority type %s").format(decodeURIComponent(matches[1])));
274
            }
275
276
            $('input.input_import').change( function() {
277
                var filename = $(this).val();
278
                if ( ! /(?:\.csv|\.ods|\.xml)$/.test(filename)) {
279
                    $(this).css("background-color","yellow");
280
                    alert(_("Please select a CSV (.csv), ODS (.ods) or XML (.xml) spreadsheet file."));
281
                    $(this).val("");
282
                    $(this).css("background-color","white");
283
                }
284
            });
285
            $('form.form_export').submit(function() {
286
                $('.modal').modal("hide");
287
                return true;
288
            });
289
            $('form.form_import').submit(function() {
290
                var id = $(this).attr('id');
291
                var obj = $('#' + id + ' input:file');
292
                if (/(?:\.csv|\.ods|\.xml)$/.test(obj.val())) {
293
                    if (confirm(_("Do you really want to import the authority type fields and subfields? This will overwrite the current configuration. For safety reasons please use the export option to make a backup"))) {
294
                        var authtypecode = $('#' + id + ' input:hidden[name=authtypecode]').val();
295
                        $('#importing_' + authtypecode).find("span").html(_("Importing to authority type: %s. Importing from file: %s").format("<strong>" + authtypecode + "</strong>", "<i>" + obj.val().replace(new RegExp("^.+[/\\\\]"),"") + "</i>"));
296
                        if (navigator.userAgent.toLowerCase().indexOf('msie') != -1) {
297
                            var timestamp = new Date().getTime();
298
                            $('#importing_' + authtypecode).find("img").attr('src', '[% interface %]/[% theme %]/img/loading-small.gif' + '?' +timestamp);
299
                        }
300
                        $('#importing_' + authtypecode).css('display', 'block');
301
                        if (navigator.userAgent.toLowerCase().indexOf('firefox') == -1) $("body").css("cursor", "progress");
302
                        importing = true;
303
                        $(".modal-footer,.closebtn").hide();
304
                        return true;
305
                    } else {
306
                        return false;
307
                    }
308
                }
309
                obj.css("background-color","yellow");
310
                alert(_("Please select a CSV (.csv), ODS (.ods) or XML (.xml) spreadsheet file."));
311
                obj.val("");
312
                obj.css("background-color","white");
313
                return false;
314
            });
193
        });
315
        });
194
    </script>
316
    </script>
195
[% END %]
317
[% END %]
196
- 

Return to bug 13952