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 1014-1026 sub _import_table_csv Link Here
1014
                    my $j = 0;
1023
                    my $j = 0;
1015
                    my %dataFields = ();
1024
                    my %dataFields = ();
1016
                    for (@arrData) {
1025
                    for (@arrData) {
1017
                        if ($fields->[$j] eq 'frameworkcode' && $_ ne $frameworkcode) {
1026
                        if ($frameworktype eq "authority"){
1018
                            $dataFields{$fields->[$j]} = $frameworkcode;
1027
                            if ($fields->[$j] eq 'authtypecode' && $_ ne $frameworkcode) {
1019
                            $arrData[$j] = $frameworkcode;
1028
                                $dataFields{$fields->[$j]} = $frameworkcode;
1029
                                $arrData[$j] = $frameworkcode;
1030
                            } else {
1031
                                $dataFields{$fields->[$j]} = $_;
1032
                            }
1033
                            $j++
1020
                        } else {
1034
                        } else {
1021
                            $dataFields{$fields->[$j]} = $_;
1035
                            if ($fields->[$j] eq 'frameworkcode' && $_ ne $frameworkcode) {
1036
                                $dataFields{$fields->[$j]} = $frameworkcode;
1037
                                $arrData[$j] = $frameworkcode;
1038
                            } else {
1039
                                $dataFields{$fields->[$j]} = $_;
1040
                            }
1041
                            $j++
1022
                        }
1042
                        }
1023
                        $j++
1024
                    }
1043
                    }
1025
                    $ok = _processRow_DB($dbh, $db_scheme, $table, $fieldsStr, $dataStr, $updateStr, \@arrData, \%dataFields, $PKArray, \@fieldsPK, $fields2Delete);
1044
                    $ok = _processRow_DB($dbh, $db_scheme, $table, $fieldsStr, $dataStr, $updateStr, \@arrData, \%dataFields, $PKArray, \@fieldsPK, $fields2Delete);
1026
                }
1045
                }
Lines 1037-1043 sub _import_table_csv Link Here
1037
# Import worksheet from the ods content.xml file to the mysql table
1056
# Import worksheet from the ods content.xml file to the mysql table
1038
sub _import_table_ods
1057
sub _import_table_ods
1039
{
1058
{
1040
    my ($dbh, $table, $frameworkcode, $dom, $PKArray, $fields2Delete) = @_;
1059
    my ($dbh, $table, $frameworkcode, $dom, $PKArray, $fields2Delete, $frameworktype) = @_;
1041
1060
1042
    my $xc = XML::LibXML::XPathContext->new($dom);
1061
    my $xc = XML::LibXML::XPathContext->new($dom);
1043
    $xc->registerNs('xmlns:office','urn:oasis:names:tc:opendocument:xmlns:office:1.0');
1062
    $xc->registerNs('xmlns:office','urn:oasis:names:tc:opendocument:xmlns:office:1.0');
Lines 1047-1053 sub _import_table_ods Link Here
1047
    @nodes = $xc->findnodes('//table:table[@table:name="' . $table . '"]');
1066
    @nodes = $xc->findnodes('//table:table[@table:name="' . $table . '"]');
1048
    if (@nodes == 1 && $nodes[0]->hasChildNodes()) {
1067
    if (@nodes == 1 && $nodes[0]->hasChildNodes()) {
1049
        my $nodeR = $nodes[0]->firstChild;
1068
        my $nodeR = $nodes[0]->firstChild;
1050
        return _processRows_Table($dbh, $frameworkcode, $nodeR, $table, $PKArray, 'ods', $fields2Delete);
1069
        return _processRows_Table($dbh, $frameworkcode, $nodeR, $table, $PKArray, 'ods', $fields2Delete, $frameworktype);
1051
    } else {
1070
    } else {
1052
        $debug and warn "Error _import_table_ods there's not worksheet for $table\n";
1071
        $debug and warn "Error _import_table_ods there's not worksheet for $table\n";
1053
    }
1072
    }
Lines 1058-1064 sub _import_table_ods Link Here
1058
# Import worksheet from the excel-xml file to the mysql table
1077
# Import worksheet from the excel-xml file to the mysql table
1059
sub _import_table_excel
1078
sub _import_table_excel
1060
{
1079
{
1061
    my ($dbh, $table, $frameworkcode, $dom, $PKArray, $fields2Delete) = @_;
1080
    my ($dbh, $table, $frameworkcode, $dom, $PKArray, $fields2Delete, $frameworktype) = @_;
1062
1081
1063
    my $xc = XML::LibXML::XPathContext->new($dom);
1082
    my $xc = XML::LibXML::XPathContext->new($dom);
1064
    $xc->registerNs('xmlns','urn:schemas-microsoft-com:office:spreadsheet');
1083
    $xc->registerNs('xmlns','urn:schemas-microsoft-com:office:spreadsheet');
Lines 1071-1077 sub _import_table_excel Link Here
1071
            my @nodesT = $nodes[$i]->getElementsByTagNameNS('urn:schemas-microsoft-com:office:spreadsheet', 'Table');
1090
            my @nodesT = $nodes[$i]->getElementsByTagNameNS('urn:schemas-microsoft-com:office:spreadsheet', 'Table');
1072
            if (@nodesT == 1 && $nodesT[0]->hasChildNodes()) {
1091
            if (@nodesT == 1 && $nodesT[0]->hasChildNodes()) {
1073
                my $nodeR = $nodesT[0]->firstChild;
1092
                my $nodeR = $nodesT[0]->firstChild;
1074
                return _processRows_Table($dbh, $frameworkcode, $nodeR, $table, $PKArray, undef, $fields2Delete);
1093
                return _processRows_Table($dbh, $frameworkcode, $nodeR, $table, $PKArray, undef, $fields2Delete, $frameworktype);
1075
            }
1094
            }
1076
        }
1095
        }
1077
    } else {
1096
    } else {
Lines 1108-1114 sub _getDataNodeODS Link Here
1108
# Get the data from a row of a spreadsheet
1127
# Get the data from a row of a spreadsheet
1109
sub _getDataFields
1128
sub _getDataFields
1110
{
1129
{
1111
    my ($frameworkcode, $node, $fields, $format) = @_;
1130
    my ($frameworkcode, $node, $fields, $format, $frameworktype) = @_;
1112
1131
1113
    my $dataFields = {};
1132
    my $dataFields = {};
1114
    my @dataFieldsA = ();
1133
    my @dataFieldsA = ();
Lines 1135-1140 sub _getDataFields Link Here
1135
            if ($ok) {
1154
            if ($ok) {
1136
                $data = '' if ($data eq '#');
1155
                $data = '' if ($data eq '#');
1137
                $data = $frameworkcode if ($fields->[$i] eq 'frameworkcode');
1156
                $data = $frameworkcode if ($fields->[$i] eq 'frameworkcode');
1157
                if ($frameworktype eq "authority") {
1158
                    $data = $frameworkcode if ($fields->[$i] eq 'authtypecode');
1159
                }
1138
                $dataFields->{$fields->[$i]} = $data;
1160
                $dataFields->{$fields->[$i]} = $data;
1139
                push @dataFieldsA, $data;
1161
                push @dataFieldsA, $data;
1140
                $i++;
1162
                $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 = new CGI;
36
my $input = new CGI;
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