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

(-)a/C4/ImportExportFramework.pm (-21 / +43 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 916-922 sub _processRow_DB Link Here
916
# Process the rows of a worksheet and insert/update them in a mysql table.
926
# Process the rows of a worksheet and insert/update them in a mysql table.
917
sub _processRows_Table
927
sub _processRows_Table
918
{
928
{
919
    my ($dbh, $frameworkcode, $nodeR, $table, $PKArray, $format, $fields2Delete) = @_;
929
    my ($dbh, $frameworkcode, $nodeR, $table, $PKArray, $format, $fields2Delete, $frameworktype) = @_;
920
930
921
    my $query;
931
    my $query;
922
    my @fields = ();
932
    my @fields = ();
Lines 943-949 sub _processRows_Table Link Here
943
                chop($updateStr) if ($updateStr);
953
                chop($updateStr) if ($updateStr);
944
            } else {
954
            } else {
945
                # Get data from row
955
                # Get data from row
946
                my ($dataFields, $dataFieldsR) = _getDataFields($frameworkcode, $nodeR, \@fields, $format);
956
                my ($dataFields, $dataFieldsR) = _getDataFields($frameworkcode, $nodeR, \@fields, $format, $frameworktype);
947
                if (scalar(@fields) == scalar(@$dataFieldsR)) {
957
                if (scalar(@fields) == scalar(@$dataFieldsR)) {
948
                    $ok = _processRow_DB($dbh, $db_scheme, $table, $fields, $dataStr, $updateStr, $dataFieldsR, $dataFields, $PKArray, \@fieldsPK, $fields2Delete);
958
                    $ok = _processRow_DB($dbh, $db_scheme, $table, $fields, $dataStr, $updateStr, $dataFieldsR, $dataFields, $PKArray, \@fieldsPK, $fields2Delete);
949
                }
959
                }
Lines 961-968 sub _processRows_Table Link Here
961
# Import worksheet from the csv file to the mysql table
971
# Import worksheet from the csv file to the mysql table
962
sub _import_table_csv
972
sub _import_table_csv
963
{
973
{
964
    my ($dbh, $table, $frameworkcode, $dom, $PKArray, $fields2Delete, $fields) = @_;
974
    my ($dbh, $table, $frameworkcode, $dom, $PKArray, $fields2Delete, $fields, $frameworktype) = @_;
965
966
    my $row = '';
975
    my $row = '';
967
    my $partialRow = '';
976
    my $partialRow = '';
968
    my $numFields = @$fields;
977
    my $numFields = @$fields;
Lines 1018-1030 sub _import_table_csv Link Here
1018
                    my $j = 0;
1027
                    my $j = 0;
1019
                    my %dataFields = ();
1028
                    my %dataFields = ();
1020
                    for (@arrData) {
1029
                    for (@arrData) {
1021
                        if ($fields->[$j] eq 'frameworkcode' && $_ ne $frameworkcode) {
1030
                        if ($frameworktype eq "authority"){
1022
                            $dataFields{$fields->[$j]} = $frameworkcode;
1031
                            if ($fields->[$j] eq 'authtypecode' && $_ ne $frameworkcode) {
1023
                            $arrData[$j] = $frameworkcode;
1032
                                $dataFields{$fields->[$j]} = $frameworkcode;
1033
                                $arrData[$j] = $frameworkcode;
1034
                            } else {
1035
                                $dataFields{$fields->[$j]} = $_;
1036
                            }
1037
                            $j++
1024
                        } else {
1038
                        } else {
1025
                            $dataFields{$fields->[$j]} = $_;
1039
                            if ($fields->[$j] eq 'frameworkcode' && $_ ne $frameworkcode) {
1040
                                $dataFields{$fields->[$j]} = $frameworkcode;
1041
                                $arrData[$j] = $frameworkcode;
1042
                            } else {
1043
                                $dataFields{$fields->[$j]} = $_;
1044
                            }
1045
                            $j++
1026
                        }
1046
                        }
1027
                        $j++
1028
                    }
1047
                    }
1029
                    $ok = _processRow_DB($dbh, $db_scheme, $table, $fieldsStr, $dataStr, $updateStr, \@arrData, \%dataFields, $PKArray, \@fieldsPK, $fields2Delete);
1048
                    $ok = _processRow_DB($dbh, $db_scheme, $table, $fieldsStr, $dataStr, $updateStr, \@arrData, \%dataFields, $PKArray, \@fieldsPK, $fields2Delete);
1030
                }
1049
                }
Lines 1041-1047 sub _import_table_csv Link Here
1041
# Import worksheet from the ods content.xml file to the mysql table
1060
# Import worksheet from the ods content.xml file to the mysql table
1042
sub _import_table_ods
1061
sub _import_table_ods
1043
{
1062
{
1044
    my ($dbh, $table, $frameworkcode, $dom, $PKArray, $fields2Delete) = @_;
1063
    my ($dbh, $table, $frameworkcode, $dom, $PKArray, $fields2Delete, $frameworktype) = @_;
1045
1064
1046
    my $xc = XML::LibXML::XPathContext->new($dom);
1065
    my $xc = XML::LibXML::XPathContext->new($dom);
1047
    $xc->registerNs('xmlns:office','urn:oasis:names:tc:opendocument:xmlns:office:1.0');
1066
    $xc->registerNs('xmlns:office','urn:oasis:names:tc:opendocument:xmlns:office:1.0');
Lines 1051-1057 sub _import_table_ods Link Here
1051
    @nodes = $xc->findnodes('//table:table[@table:name="' . $table . '"]');
1070
    @nodes = $xc->findnodes('//table:table[@table:name="' . $table . '"]');
1052
    if (@nodes == 1 && $nodes[0]->hasChildNodes()) {
1071
    if (@nodes == 1 && $nodes[0]->hasChildNodes()) {
1053
        my $nodeR = $nodes[0]->firstChild;
1072
        my $nodeR = $nodes[0]->firstChild;
1054
        return _processRows_Table($dbh, $frameworkcode, $nodeR, $table, $PKArray, 'ods', $fields2Delete);
1073
        return _processRows_Table($dbh, $frameworkcode, $nodeR, $table, $PKArray, 'ods', $fields2Delete, $frameworktype);
1055
    } else {
1074
    } else {
1056
        $debug and warn "Error _import_table_ods there's not worksheet for $table\n";
1075
        $debug and warn "Error _import_table_ods there's not worksheet for $table\n";
1057
    }
1076
    }
Lines 1062-1068 sub _import_table_ods Link Here
1062
# Import worksheet from the excel-xml file to the mysql table
1081
# Import worksheet from the excel-xml file to the mysql table
1063
sub _import_table_excel
1082
sub _import_table_excel
1064
{
1083
{
1065
    my ($dbh, $table, $frameworkcode, $dom, $PKArray, $fields2Delete) = @_;
1084
    my ($dbh, $table, $frameworkcode, $dom, $PKArray, $fields2Delete, $frameworktype) = @_;
1066
1085
1067
    my $xc = XML::LibXML::XPathContext->new($dom);
1086
    my $xc = XML::LibXML::XPathContext->new($dom);
1068
    $xc->registerNs('xmlns','urn:schemas-microsoft-com:office:spreadsheet');
1087
    $xc->registerNs('xmlns','urn:schemas-microsoft-com:office:spreadsheet');
Lines 1075-1081 sub _import_table_excel Link Here
1075
            my @nodesT = $nodes[$i]->getElementsByTagNameNS('urn:schemas-microsoft-com:office:spreadsheet', 'Table');
1094
            my @nodesT = $nodes[$i]->getElementsByTagNameNS('urn:schemas-microsoft-com:office:spreadsheet', 'Table');
1076
            if (@nodesT == 1 && $nodesT[0]->hasChildNodes()) {
1095
            if (@nodesT == 1 && $nodesT[0]->hasChildNodes()) {
1077
                my $nodeR = $nodesT[0]->firstChild;
1096
                my $nodeR = $nodesT[0]->firstChild;
1078
                return _processRows_Table($dbh, $frameworkcode, $nodeR, $table, $PKArray, undef, $fields2Delete);
1097
                return _processRows_Table($dbh, $frameworkcode, $nodeR, $table, $PKArray, undef, $fields2Delete, $frameworktype);
1079
            }
1098
            }
1080
        }
1099
        }
1081
    } else {
1100
    } else {
Lines 1112-1118 sub _getDataNodeODS Link Here
1112
# Get the data from a row of a spreadsheet
1131
# Get the data from a row of a spreadsheet
1113
sub _getDataFields
1132
sub _getDataFields
1114
{
1133
{
1115
    my ($frameworkcode, $node, $fields, $format) = @_;
1134
    my ($frameworkcode, $node, $fields, $format, $frameworktype) = @_;
1116
1135
1117
    my $dataFields = {};
1136
    my $dataFields = {};
1118
    my @dataFieldsA = ();
1137
    my @dataFieldsA = ();
Lines 1139-1144 sub _getDataFields Link Here
1139
            if ($ok) {
1158
            if ($ok) {
1140
                $data = '' if ($data eq '#');
1159
                $data = '' if ($data eq '#');
1141
                $data = $frameworkcode if ($fields->[$i] eq 'frameworkcode');
1160
                $data = $frameworkcode if ($fields->[$i] eq 'frameworkcode');
1161
                if ($frameworktype eq "authority") {
1162
                    $data = $frameworkcode if ($fields->[$i] eq 'authtypecode');
1163
                }
1142
                $dataFields->{$fields->[$i]} = $data;
1164
                $dataFields->{$fields->[$i]} = $data;
1143
                push @dataFieldsA, $data;
1165
                push @dataFieldsA, $data;
1144
                $i++;
1166
                $i++;
(-)a/admin/import_export_authtype.pl (-9 / +3 lines)
Lines 17-25 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;
Lines 27-33 use C4::Auth qw/check_cookie_auth/; Link Here
27
use C4::ImportExportFramework;
25
use C4::ImportExportFramework;
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;
25
use C4::ImportExportFramework;
27
26
28
my %cookies = CGI::Cookie->fetch();
27
my %cookies = CGI::Cookie->fetch();
29
my $authenticated = 0;
30
my ($auth_status, $sessionID);
28
my ($auth_status, $sessionID);
31
if (exists $cookies{'CGISESSID'}) {
29
if (exists $cookies{'CGISESSID'}) {
32
    ($auth_status, $sessionID) = check_cookie_auth(
30
    ($auth_status, $sessionID) = 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