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

(-)a/C4/ImportExportFramework.pm (-21 / +43 lines)
Lines 680-690 sub ImportFramework Link Here
680
                    # Process both tables
680
                    # Process both tables
681
                    my $numDeleted = 0;
681
                    my $numDeleted = 0;
682
                    my $numDeletedAux = 0;
682
                    my $numDeletedAux = 0;
683
                    if (($numDeletedAux = _import_table($dbh, $table, $frameworkcode, $dom, ['frameworkcode', 'tagfield'], $extension, $frameworktype)) >= 0) {
683
                    if ($frameworktype eq "authority"){
684
                        $numDeleted += $numDeletedAux if ($numDeletedAux > 0);
684
                        if (($numDeletedAux = _import_table($dbh, $table, $frameworkcode, $dom, ['authtypecode', 'tagfield'], $extension, $frameworktype)) >= 0) {
685
                        if (($numDeletedAux = _import_table($dbh, $subtable, $frameworkcode, $dom, ['frameworkcode', 'tagfield', 'tagsubfield'], $extension, $frameworktype)) >= 0) {
686
                            $numDeleted += $numDeletedAux if ($numDeletedAux > 0);
685
                            $numDeleted += $numDeletedAux if ($numDeletedAux > 0);
687
                            $ok = ($numDeleted > 0)?$numDeleted:0;
686
                            if (($numDeletedAux = _import_table($dbh, $subtable, $frameworkcode, $dom, ['authtypecode', 'tagfield', 'tagsubfield'], $extension, $frameworktype)) >= 0) {
687
                                $numDeleted += $numDeletedAux if ($numDeletedAux > 0);
688
                                $ok = ($numDeleted > 0)?$numDeleted:0;
689
                            }
690
                        }
691
                    } else {
692
                        if (($numDeletedAux = _import_table($dbh, $table, $frameworkcode, $dom, ['frameworkcode', 'tagfield'], $extension, $frameworktype)) >= 0) {
693
                            $numDeleted += $numDeletedAux if ($numDeletedAux > 0);
694
                            if (($numDeletedAux = _import_table($dbh, $subtable, $frameworkcode, $dom, ['frameworkcode', 'tagfield', 'tagsubfield'], $extension, $frameworktype)) >= 0) {
695
                                $numDeleted += $numDeletedAux if ($numDeletedAux > 0);
696
                                $ok = ($numDeleted > 0)?$numDeleted:0;
697
                            }
688
                        }
698
                        }
689
                    }
699
                    }
690
                } else {
700
                } else {
Lines 837-847 sub _import_table Link Here
837
                push @fieldsName, $hashRef->{Field};
847
                push @fieldsName, $hashRef->{Field};
838
            }
848
            }
839
        };
849
        };
840
        $ok = _import_table_csv($dbh, $table, $frameworkcode, $dom, $PKArray, \%fields2Delete, \@fieldsName);
850
        $ok = _import_table_csv($dbh, $table, $frameworkcode, $dom, $PKArray, \%fields2Delete, \@fieldsName, $frameworktype);
841
    } elsif ($format eq 'ods') {
851
    } elsif ($format eq 'ods') {
842
        $ok = _import_table_ods($dbh, $table, $frameworkcode, $dom, $PKArray, \%fields2Delete);
852
        $ok = _import_table_ods($dbh, $table, $frameworkcode, $dom, $PKArray, \%fields2Delete, $frameworktype);
843
    } else {
853
    } else {
844
        $ok = _import_table_excel($dbh, $table, $frameworkcode, $dom, $PKArray, \%fields2Delete);
854
        $ok = _import_table_excel($dbh, $table, $frameworkcode, $dom, $PKArray, \%fields2Delete, $frameworktype);
845
    }
855
    }
846
    if ($ok) {
856
    if ($ok) {
847
        if (($ok = scalar(keys %fields2Delete)) > 0) {
857
        if (($ok = scalar(keys %fields2Delete)) > 0) {
Lines 912-918 sub _processRow_DB Link Here
912
# Process the rows of a worksheet and insert/update them in a mysql table.
922
# Process the rows of a worksheet and insert/update them in a mysql table.
913
sub _processRows_Table
923
sub _processRows_Table
914
{
924
{
915
    my ($dbh, $frameworkcode, $nodeR, $table, $PKArray, $format, $fields2Delete) = @_;
925
    my ($dbh, $frameworkcode, $nodeR, $table, $PKArray, $format, $fields2Delete, $frameworktype) = @_;
916
926
917
    my $query;
927
    my $query;
918
    my @fields = ();
928
    my @fields = ();
Lines 939-945 sub _processRows_Table Link Here
939
                chop($updateStr) if ($updateStr);
949
                chop($updateStr) if ($updateStr);
940
            } else {
950
            } else {
941
                # Get data from row
951
                # Get data from row
942
                my ($dataFields, $dataFieldsR) = _getDataFields($frameworkcode, $nodeR, \@fields, $format);
952
                my ($dataFields, $dataFieldsR) = _getDataFields($frameworkcode, $nodeR, \@fields, $format, $frameworktype);
943
                if (scalar(@fields) == scalar(@$dataFieldsR)) {
953
                if (scalar(@fields) == scalar(@$dataFieldsR)) {
944
                    $ok = _processRow_DB($dbh, $db_scheme, $table, $fields, $dataStr, $updateStr, $dataFieldsR, $dataFields, $PKArray, \@fieldsPK, $fields2Delete);
954
                    $ok = _processRow_DB($dbh, $db_scheme, $table, $fields, $dataStr, $updateStr, $dataFieldsR, $dataFields, $PKArray, \@fieldsPK, $fields2Delete);
945
                }
955
                }
Lines 957-964 sub _processRows_Table Link Here
957
# Import worksheet from the csv file to the mysql table
967
# Import worksheet from the csv file to the mysql table
958
sub _import_table_csv
968
sub _import_table_csv
959
{
969
{
960
    my ($dbh, $table, $frameworkcode, $dom, $PKArray, $fields2Delete, $fields) = @_;
970
    my ($dbh, $table, $frameworkcode, $dom, $PKArray, $fields2Delete, $fields, $frameworktype) = @_;
961
962
    my $row = '';
971
    my $row = '';
963
    my $partialRow = '';
972
    my $partialRow = '';
964
    my $numFields = @$fields;
973
    my $numFields = @$fields;
Lines 1022-1034 sub _import_table_csv Link Here
1022
                        my $j = 0;
1031
                        my $j = 0;
1023
                        my %dataFields = ();
1032
                        my %dataFields = ();
1024
                        for (@arrData) {
1033
                        for (@arrData) {
1025
                            if ($fields->[$j] eq 'frameworkcode' && $_ ne $frameworkcode) {
1034
                            if ($frameworktype eq "authority"){
1026
                                $dataFields{$fields->[$j]} = $frameworkcode;
1035
                                if ($fields->[$j] eq 'authtypecode' && $_ ne $frameworkcode) {
1027
                                $arrData[$j] = $frameworkcode;
1036
                                    $dataFields{$fields->[$j]} = $frameworkcode;
1037
                                    $arrData[$j] = $frameworkcode;
1038
                                } else {
1039
                                    $dataFields{$fields->[$j]} = $_;
1040
                                }
1041
                                $j++
1028
                            } else {
1042
                            } else {
1029
                                $dataFields{$fields->[$j]} = $_;
1043
                                if ($fields->[$j] eq 'frameworkcode' && $_ ne $frameworkcode) {
1044
                                    $dataFields{$fields->[$j]} = $frameworkcode;
1045
                                    $arrData[$j] = $frameworkcode;
1046
                                } else {
1047
                                    $dataFields{$fields->[$j]} = $_;
1048
                                }
1049
                                $j++
1030
                            }
1050
                            }
1031
                            $j++
1032
                        }
1051
                        }
1033
                        $ok = _processRow_DB($dbh, $db_scheme, $table, $fieldsStr, $dataStr, $updateStr, \@arrData, \%dataFields, $PKArray, \@fieldsPK, $fields2Delete);
1052
                        $ok = _processRow_DB($dbh, $db_scheme, $table, $fieldsStr, $dataStr, $updateStr, \@arrData, \%dataFields, $PKArray, \@fieldsPK, $fields2Delete);
1034
                    }
1053
                    }
Lines 1046-1052 sub _import_table_csv Link Here
1046
# Import worksheet from the ods content.xml file to the mysql table
1065
# Import worksheet from the ods content.xml file to the mysql table
1047
sub _import_table_ods
1066
sub _import_table_ods
1048
{
1067
{
1049
    my ($dbh, $table, $frameworkcode, $dom, $PKArray, $fields2Delete) = @_;
1068
    my ($dbh, $table, $frameworkcode, $dom, $PKArray, $fields2Delete, $frameworktype) = @_;
1050
1069
1051
    my $xc = XML::LibXML::XPathContext->new($dom);
1070
    my $xc = XML::LibXML::XPathContext->new($dom);
1052
    $xc->registerNs('xmlns:office','urn:oasis:names:tc:opendocument:xmlns:office:1.0');
1071
    $xc->registerNs('xmlns:office','urn:oasis:names:tc:opendocument:xmlns:office:1.0');
Lines 1056-1062 sub _import_table_ods Link Here
1056
    @nodes = $xc->findnodes('//table:table[@table:name="' . $table . '"]');
1075
    @nodes = $xc->findnodes('//table:table[@table:name="' . $table . '"]');
1057
    if (@nodes == 1 && $nodes[0]->hasChildNodes()) {
1076
    if (@nodes == 1 && $nodes[0]->hasChildNodes()) {
1058
        my $nodeR = $nodes[0]->firstChild;
1077
        my $nodeR = $nodes[0]->firstChild;
1059
        return _processRows_Table($dbh, $frameworkcode, $nodeR, $table, $PKArray, 'ods', $fields2Delete);
1078
        return _processRows_Table($dbh, $frameworkcode, $nodeR, $table, $PKArray, 'ods', $fields2Delete, $frameworktype);
1060
    } else {
1079
    } else {
1061
        $debug and warn "Error _import_table_ods there's not worksheet for $table\n";
1080
        $debug and warn "Error _import_table_ods there's not worksheet for $table\n";
1062
    }
1081
    }
Lines 1067-1073 sub _import_table_ods Link Here
1067
# Import worksheet from the excel-xml file to the mysql table
1086
# Import worksheet from the excel-xml file to the mysql table
1068
sub _import_table_excel
1087
sub _import_table_excel
1069
{
1088
{
1070
    my ($dbh, $table, $frameworkcode, $dom, $PKArray, $fields2Delete) = @_;
1089
    my ($dbh, $table, $frameworkcode, $dom, $PKArray, $fields2Delete, $frameworktype) = @_;
1071
1090
1072
    my $xc = XML::LibXML::XPathContext->new($dom);
1091
    my $xc = XML::LibXML::XPathContext->new($dom);
1073
    $xc->registerNs('xmlns','urn:schemas-microsoft-com:office:spreadsheet');
1092
    $xc->registerNs('xmlns','urn:schemas-microsoft-com:office:spreadsheet');
Lines 1080-1086 sub _import_table_excel Link Here
1080
            my @nodesT = $nodes[$i]->getElementsByTagNameNS('urn:schemas-microsoft-com:office:spreadsheet', 'Table');
1099
            my @nodesT = $nodes[$i]->getElementsByTagNameNS('urn:schemas-microsoft-com:office:spreadsheet', 'Table');
1081
            if (@nodesT == 1 && $nodesT[0]->hasChildNodes()) {
1100
            if (@nodesT == 1 && $nodesT[0]->hasChildNodes()) {
1082
                my $nodeR = $nodesT[0]->firstChild;
1101
                my $nodeR = $nodesT[0]->firstChild;
1083
                return _processRows_Table($dbh, $frameworkcode, $nodeR, $table, $PKArray, undef, $fields2Delete);
1102
                return _processRows_Table($dbh, $frameworkcode, $nodeR, $table, $PKArray, undef, $fields2Delete, $frameworktype);
1084
            }
1103
            }
1085
        }
1104
        }
1086
    } else {
1105
    } else {
Lines 1117-1123 sub _getDataNodeODS Link Here
1117
# Get the data from a row of a spreadsheet
1136
# Get the data from a row of a spreadsheet
1118
sub _getDataFields
1137
sub _getDataFields
1119
{
1138
{
1120
    my ($frameworkcode, $node, $fields, $format) = @_;
1139
    my ($frameworkcode, $node, $fields, $format, $frameworktype) = @_;
1121
1140
1122
    my $dataFields = {};
1141
    my $dataFields = {};
1123
    my @dataFieldsA = ();
1142
    my @dataFieldsA = ();
Lines 1144-1149 sub _getDataFields Link Here
1144
            if ($ok) {
1163
            if ($ok) {
1145
                $data = '' if ($data eq '#');
1164
                $data = '' if ($data eq '#');
1146
                $data = $frameworkcode if ($fields->[$i] eq 'frameworkcode');
1165
                $data = $frameworkcode if ($fields->[$i] eq 'frameworkcode');
1166
                if ($frameworktype eq "authority") {
1167
                    $data = $frameworkcode if ($fields->[$i] eq 'authtypecode');
1168
                }
1147
                $dataFields->{$fields->[$i]} = $data;
1169
                $dataFields->{$fields->[$i]} = $data;
1148
                push @dataFieldsA, $data;
1170
                push @dataFieldsA, $data;
1149
                $i++;
1171
                $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 (-9 / +2 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
}
48
- 

Return to bug 13952