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

(-)a/C4/ImportExportFramework.pm (-30 / +62 lines)
Lines 684-694 sub ImportFramework Link Here
684
                    # Process both tables
684
                    # Process both tables
685
                    my $numDeleted = 0;
685
                    my $numDeleted = 0;
686
                    my $numDeletedAux = 0;
686
                    my $numDeletedAux = 0;
687
                    if (($numDeletedAux = _import_table($dbh, $table, $frameworkcode, $dom, ['frameworkcode', 'tagfield'], $extension, $frameworktype)) >= 0) {
687
                    if ($frameworktype eq "authority"){
688
                        $numDeleted += $numDeletedAux if ($numDeletedAux > 0);
688
                        if (($numDeletedAux = _import_table($dbh, $table, $frameworkcode, $dom, ['authtypecode', 'tagfield'], $extension, $frameworktype)) >= 0) {
689
                        if (($numDeletedAux = _import_table($dbh, $subtable, $frameworkcode, $dom, ['frameworkcode', 'tagfield', 'tagsubfield'], $extension, $frameworktype)) >= 0) {
690
                            $numDeleted += $numDeletedAux if ($numDeletedAux > 0);
689
                            $numDeleted += $numDeletedAux if ($numDeletedAux > 0);
691
                            $ok = ($numDeleted > 0)?$numDeleted:0;
690
                            if (($numDeletedAux = _import_table($dbh, $subtable, $frameworkcode, $dom, ['authtypecode', 'tagfield', 'tagsubfield'], $extension, $frameworktype)) >= 0) {
691
                                $numDeleted += $numDeletedAux if ($numDeletedAux > 0);
692
                                $ok = ($numDeleted > 0)?$numDeleted:0;
693
                            }
694
                        }
695
                    } else {
696
                        if (($numDeletedAux = _import_table($dbh, $table, $frameworkcode, $dom, ['frameworkcode', 'tagfield'], $extension, $frameworktype)) >= 0) {
697
                            $numDeleted += $numDeletedAux if ($numDeletedAux > 0);
698
                            if (($numDeletedAux = _import_table($dbh, $subtable, $frameworkcode, $dom, ['frameworkcode', 'tagfield', 'tagsubfield'], $extension, $frameworktype)) >= 0) {
699
                                $numDeleted += $numDeletedAux if ($numDeletedAux > 0);
700
                                $ok = ($numDeleted > 0)?$numDeleted:0;
701
                            }
692
                        }
702
                        }
693
                    }
703
                    }
694
                } else {
704
                } else {
Lines 841-851 sub _import_table Link Here
841
                push @fieldsName, $hashRef->{Field};
851
                push @fieldsName, $hashRef->{Field};
842
            }
852
            }
843
        };
853
        };
844
        $ok = _import_table_csv($dbh, $table, $frameworkcode, $dom, $PKArray, \%fields2Delete, \@fieldsName);
854
        $ok = _import_table_csv($dbh, $table, $frameworkcode, $dom, $PKArray, \%fields2Delete, \@fieldsName, $frameworktype);
845
    } elsif ($format eq 'ods') {
855
    } elsif ($format eq 'ods') {
846
        $ok = _import_table_ods($dbh, $table, $frameworkcode, $dom, $PKArray, \%fields2Delete);
856
        $ok = _import_table_ods($dbh, $table, $frameworkcode, $dom, $PKArray, \%fields2Delete, $frameworktype);
847
    } else {
857
    } else {
848
        $ok = _import_table_excel($dbh, $table, $frameworkcode, $dom, $PKArray, \%fields2Delete);
858
        $ok = _import_table_excel($dbh, $table, $frameworkcode, $dom, $PKArray, \%fields2Delete, $frameworktype);
849
    }
859
    }
850
    if ($ok) {
860
    if ($ok) {
851
        if (($ok = scalar(keys %fields2Delete)) > 0) {
861
        if (($ok = scalar(keys %fields2Delete)) > 0) {
Lines 896-902 sub _processRow_DB Link Here
896
# Process the rows of a worksheet and insert/update them in a mysql table.
906
# Process the rows of a worksheet and insert/update them in a mysql table.
897
sub _processRows_Table
907
sub _processRows_Table
898
{
908
{
899
    my ($dbh, $frameworkcode, $nodeR, $table, $PKArray, $format, $fields2Delete) = @_;
909
    my ($dbh, $frameworkcode, $nodeR, $table, $PKArray, $format, $fields2Delete, $frameworktype) = @_;
900
910
901
    my $query;
911
    my $query;
902
    my @fields = ();
912
    my @fields = ();
Lines 922-928 sub _processRows_Table Link Here
922
                chop($updateStr) if ($updateStr);
932
                chop($updateStr) if ($updateStr);
923
            } else {
933
            } else {
924
                # Get data from row
934
                # Get data from row
925
                my ($dataFields, $dataFieldsR) = _getDataFields($frameworkcode, $nodeR, \@fields, $format);
935
                my ($dataFields, $dataFieldsR) = _getDataFields($frameworkcode, $nodeR, \@fields, $format, $frameworktype);
926
                if (scalar(@fields) == scalar(@$dataFieldsR)) {
936
                if (scalar(@fields) == scalar(@$dataFieldsR)) {
927
                    $ok = _processRow_DB($dbh, $table, $fields, $dataStr, $updateStr, $dataFieldsR, $dataFields, $PKArray, \@fieldsPK, $fields2Delete);
937
                    $ok = _processRow_DB($dbh, $table, $fields, $dataStr, $updateStr, $dataFieldsR, $dataFields, $PKArray, \@fieldsPK, $fields2Delete);
928
                } else {
938
                } else {
Lines 942-949 sub _processRows_Table Link Here
942
# Import worksheet from the csv file to the mysql table
952
# Import worksheet from the csv file to the mysql table
943
sub _import_table_csv
953
sub _import_table_csv
944
{
954
{
945
    my ($dbh, $table, $frameworkcode, $dom, $PKArray, $fields2Delete, $fields) = @_;
955
    my ($dbh, $table, $frameworkcode, $dom, $PKArray, $fields2Delete, $fields, $frameworktype) = @_;
946
947
    my $row = '';
956
    my $row = '';
948
    my $partialRow = '';
957
    my $partialRow = '';
949
    my $numFields = @$fields;
958
    my $numFields = @$fields;
Lines 992-1008 sub _import_table_csv Link Here
992
                for my $value (@arrData) {
1001
                for my $value (@arrData) {
993
                    if ( grep { $_ == $j } @empty_indexes ) {
1002
                    if ( grep { $_ == $j } @empty_indexes ) {
994
                        # empty field
1003
                        # empty field
995
                    } elsif ($fields->[$j] eq 'frameworkcode' && $value ne $frameworkcode) {
1004
                    } elsif ($frameworktype eq "authority"){
996
                        $dataFields{$fields->[$j]} = $frameworkcode;
1005
                        if ($fields->[$j] eq 'authtypecode' && $value ne $frameworkcode) {
997
                        push @values, $frameworkcode;
1006
                            $dataFields{$fields->[$j]} = $frameworkcode;
998
                    } elsif ($fields->[$j] eq 'isurl' && defined $value && $value eq q{}) {
1007
                            push @values, $frameworkcode;
999
                        $dataFields{$fields->[$j]} = undef;
1008
                        } elsif ($fields->[$j] eq 'isurl' && defined $value && $value eq q{}) {
1000
                        push @values, undef;
1009
                            $dataFields{$fields->[$j]} = undef;
1010
                            push @values, undef;
1011
                        } else {
1012
                            $dataFields{$fields->[$j]} = $value;
1013
                            push @values, $value;
1014
                        }
1015
                        $j++
1001
                    } else {
1016
                    } else {
1002
                        $dataFields{$fields->[$j]} = $value;
1017
                        if ($fields->[$j] eq 'frameworkcode' && $value ne $frameworkcode) {
1003
                        push @values, $value;
1018
                            $dataFields{$fields->[$j]} = $frameworkcode;
1019
                            push @values, $frameworkcode;
1020
                        } elsif ($fields->[$j] eq 'isurl' && defined $value && $value eq q{}) {
1021
                            $dataFields{$fields->[$j]} = undef;
1022
                            push @values, undef;
1023
                        } else {
1024
                            $dataFields{$fields->[$j]} = $value;
1025
                            push @values, $value;
1026
                        }
1027
                        $j++
1004
                    }
1028
                    }
1005
                    $j++
1006
                }
1029
                }
1007
                $ok = _processRow_DB($dbh, $table, $fieldsStr, $dataStr, $updateStr, \@values, \%dataFields, $PKArray, \@fieldsPK, $fields2Delete);
1030
                $ok = _processRow_DB($dbh, $table, $fieldsStr, $dataStr, $updateStr, \@values, \%dataFields, $PKArray, \@fieldsPK, $fields2Delete);
1008
            }
1031
            }
Lines 1017-1023 sub _import_table_csv Link Here
1017
# Import worksheet from the ods content.xml file to the mysql table
1040
# Import worksheet from the ods content.xml file to the mysql table
1018
sub _import_table_ods
1041
sub _import_table_ods
1019
{
1042
{
1020
    my ($dbh, $table, $frameworkcode, $dom, $PKArray, $fields2Delete) = @_;
1043
    my ($dbh, $table, $frameworkcode, $dom, $PKArray, $fields2Delete, $frameworktype) = @_;
1021
1044
1022
    my $xc = XML::LibXML::XPathContext->new($dom);
1045
    my $xc = XML::LibXML::XPathContext->new($dom);
1023
    $xc->registerNs('xmlns:office','urn:oasis:names:tc:opendocument:xmlns:office:1.0');
1046
    $xc->registerNs('xmlns:office','urn:oasis:names:tc:opendocument:xmlns:office:1.0');
Lines 1027-1033 sub _import_table_ods Link Here
1027
    @nodes = $xc->findnodes('//table:table[@table:name="' . $table . '"]');
1050
    @nodes = $xc->findnodes('//table:table[@table:name="' . $table . '"]');
1028
    if (@nodes == 1 && $nodes[0]->hasChildNodes()) {
1051
    if (@nodes == 1 && $nodes[0]->hasChildNodes()) {
1029
        my $nodeR = $nodes[0]->firstChild;
1052
        my $nodeR = $nodes[0]->firstChild;
1030
        return _processRows_Table($dbh, $frameworkcode, $nodeR, $table, $PKArray, 'ods', $fields2Delete);
1053
        return _processRows_Table($dbh, $frameworkcode, $nodeR, $table, $PKArray, 'ods', $fields2Delete, $frameworktype);
1031
    } else {
1054
    } else {
1032
        Koha::Logger->get->warn("Error _import_table_ods there's not worksheet for $table");
1055
        Koha::Logger->get->warn("Error _import_table_ods there's not worksheet for $table");
1033
    }
1056
    }
Lines 1038-1044 sub _import_table_ods Link Here
1038
# Import worksheet from the excel-xml file to the mysql table
1061
# Import worksheet from the excel-xml file to the mysql table
1039
sub _import_table_excel
1062
sub _import_table_excel
1040
{
1063
{
1041
    my ($dbh, $table, $frameworkcode, $dom, $PKArray, $fields2Delete) = @_;
1064
    my ($dbh, $table, $frameworkcode, $dom, $PKArray, $fields2Delete, $frameworktype) = @_;
1042
1065
1043
    my $xc = XML::LibXML::XPathContext->new($dom);
1066
    my $xc = XML::LibXML::XPathContext->new($dom);
1044
    $xc->registerNs('xmlns','urn:schemas-microsoft-com:office:spreadsheet');
1067
    $xc->registerNs('xmlns','urn:schemas-microsoft-com:office:spreadsheet');
Lines 1051-1057 sub _import_table_excel Link Here
1051
            my @nodesT = $nodes[$i]->getElementsByTagNameNS('urn:schemas-microsoft-com:office:spreadsheet', 'Table');
1074
            my @nodesT = $nodes[$i]->getElementsByTagNameNS('urn:schemas-microsoft-com:office:spreadsheet', 'Table');
1052
            if (@nodesT == 1 && $nodesT[0]->hasChildNodes()) {
1075
            if (@nodesT == 1 && $nodesT[0]->hasChildNodes()) {
1053
                my $nodeR = $nodesT[0]->firstChild;
1076
                my $nodeR = $nodesT[0]->firstChild;
1054
                return _processRows_Table($dbh, $frameworkcode, $nodeR, $table, $PKArray, undef, $fields2Delete);
1077
                return _processRows_Table($dbh, $frameworkcode, $nodeR, $table, $PKArray, undef, $fields2Delete, $frameworktype);
1055
            }
1078
            }
1056
        }
1079
        }
1057
    } else {
1080
    } else {
Lines 1088-1094 sub _getDataNodeODS Link Here
1088
# Get the data from a row of a spreadsheet
1111
# Get the data from a row of a spreadsheet
1089
sub _getDataFields
1112
sub _getDataFields
1090
{
1113
{
1091
    my ($frameworkcode, $node, $fields, $format) = @_;
1114
    my ($frameworkcode, $node, $fields, $format, $frameworktype) = @_;
1092
1115
1093
    my $dataFields = {};
1116
    my $dataFields = {};
1094
    my @dataFieldsA = ();
1117
    my @dataFieldsA = ();
Lines 1115-1125 sub _getDataFields Link Here
1115
            if ($ok) {
1138
            if ($ok) {
1116
                $data //= '';
1139
                $data //= '';
1117
                $data = '' if ($data eq '#');
1140
                $data = '' if ($data eq '#');
1118
                if ( $fields->[$i] eq 'frameworkcode' ) {
1141
                if ($frameworktype eq "authority") {
1119
                    $data = $frameworkcode;
1142
                    if ( $fields->[$i] eq 'authtypecode' ) {
1120
                }
1143
                        $data = $frameworkcode;
1121
                elsif ( $fields->[$i] eq 'isurl' ) {
1144
                    }
1122
                    $data = undef if defined $data && $data eq q{};
1145
                    elsif ( $fields->[$i] eq 'isurl' ) {
1146
                        $data = undef if defined $data && $data eq q{};
1147
                    }
1148
                } else {
1149
                    if ( $fields->[$i] eq 'frameworkcode' ) {
1150
                        $data = $frameworkcode;
1151
                    }
1152
                    elsif ( $fields->[$i] eq 'isurl' ) {
1153
                        $data = undef if defined $data && $data eq q{};
1154
                    }
1123
                }
1155
                }
1124
                $dataFields->{$fields->[$i]} = $data;
1156
                $dataFields->{$fields->[$i]} = $data;
1125
                push @dataFieldsA, $data;
1157
                push @dataFieldsA, $data;
(-)a/admin/import_export_authtype.pl (-10 / +4 lines)
Lines 17-33 Link Here
17
# You should have received a copy of the GNU General Public License
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>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
20
use Modern::Perl;
21
use strict;
22
use warnings;
23
use CGI qw ( -utf8 );
21
use CGI qw ( -utf8 );
24
use CGI::Cookie;
22
use CGI::Cookie;
25
use C4::Context;
23
use C4::Context;
26
use C4::Auth qw/check_cookie_auth/;
24
use C4::Auth qw/check_cookie_auth/;
27
use C4::ImportExportFramework;
25
use C4::ImportExportFramework qw( ExportFramework ImportFramework );
28
26
29
my %cookies = CGI::Cookie->fetch();
27
my %cookies = CGI::Cookie->fetch();
30
my $authenticated = 0;
31
my ($auth_status, $sessionID);
28
my ($auth_status, $sessionID);
32
if (exists $cookies{'CGISESSID'}) {
29
if (exists $cookies{'CGISESSID'}) {
33
    ($auth_status, $sessionID) = check_cookie_auth(
30
    ($auth_status, $sessionID) = check_cookie_auth(
Lines 35-47 if (exists $cookies{'CGISESSID'}) { Link Here
35
        { parameters => 'parameters_remaining_permissions' },
32
        { parameters => 'parameters_remaining_permissions' },
36
    );
33
    );
37
}
34
}
38
if ($auth_status eq 'ok') {
39
    $authenticated = 1;
40
}
41
35
42
my $input = new CGI;
36
my $input = new CGI;
43
37
44
unless ($authenticated) {
38
unless ($auth_status eq 'ok') {
45
    print $input->header(-type => 'text/plain', -status => '403 Forbidden');
39
    print $input->header(-type => 'text/plain', -status => '403 Forbidden');
46
    exit 0;
40
    exit 0;
47
}
41
}
Lines 88-94 if ($action eq 'export' && $input->request_method() eq 'GET') { Link Here
88
        my $extension = $1;
82
        my $extension = $1;
89
        my $uploadFd = $input->upload($fieldname);
83
        my $uploadFd = $input->upload($fieldname);
90
        if ($uploadFd && !$input->cgi_error) {
84
        if ($uploadFd && !$input->cgi_error) {
91
            my $tmpfilename = $input->tmpFileName($input->param($fieldname));
85
            my $tmpfilename = $input->tmpFileName(scalar $input->param($fieldname));
92
            $filename = $tmpfilename . '.' . $extension; # rename the tmp file with the extension
86
            $filename = $tmpfilename . '.' . $extension; # rename the tmp file with the extension
93
            $ok = ImportFramework($filename, $authtypecode, 1, 'authority') if (rename($tmpfilename, $filename));
87
            $ok = ImportFramework($filename, $authtypecode, 1, 'authority') if (rename($tmpfilename, $filename));
94
        }
88
        }
(-)a/admin/import_export_framework.pl (-7 / +1 lines)
Lines 17-23 Link Here
17
# You should have received a copy of the GNU General Public License
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>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
21
use Modern::Perl;
20
use Modern::Perl;
22
use CGI qw ( -utf8 );
21
use CGI qw ( -utf8 );
23
use CGI::Cookie;
22
use CGI::Cookie;
Lines 26-32 use C4::Auth qw( check_cookie_auth ); Link Here
26
use C4::ImportExportFramework qw( createODS ExportFramework ImportFramework );
25
use C4::ImportExportFramework qw( createODS ExportFramework ImportFramework );
27
26
28
my %cookies = CGI::Cookie->fetch();
27
my %cookies = CGI::Cookie->fetch();
29
my $authenticated = 0;
30
my ($auth_status);
28
my ($auth_status);
31
if (exists $cookies{'CGISESSID'}) {
29
if (exists $cookies{'CGISESSID'}) {
32
    ($auth_status, undef) = check_cookie_auth(
30
    ($auth_status, undef) = check_cookie_auth(
Lines 34-46 if (exists $cookies{'CGISESSID'}) { Link Here
34
        { parameters => 'manage_marc_frameworks' },
32
        { parameters => 'manage_marc_frameworks' },
35
    );
33
    );
36
}
34
}
37
if ($auth_status eq 'ok') {
38
    $authenticated = 1;
39
}
40
35
41
my $input = CGI->new;
36
my $input = CGI->new;
42
37
43
unless ($authenticated) {
38
unless ($auth_status eq 'ok') {
44
    print $input->header(-type => 'text/plain', -status => '403 Forbidden');
39
    print $input->header(-type => 'text/plain', -status => '403 Forbidden');
45
    exit 0;
40
    exit 0;
46
}
41
}
47
- 

Return to bug 13952