@@ -, +, @@ --- C4/ImportExportFramework.pm | 64 +++++++++++++++++++++++++++------------- admin/import_export_authtype.pl | 12 ++------ admin/import_export_framework.pl | 7 +---- 3 files changed, 47 insertions(+), 36 deletions(-) --- a/C4/ImportExportFramework.pm +++ a/C4/ImportExportFramework.pm @@ -680,11 +680,21 @@ sub ImportFramework # Process both tables my $numDeleted = 0; my $numDeletedAux = 0; - if (($numDeletedAux = _import_table($dbh, $table, $frameworkcode, $dom, ['frameworkcode', 'tagfield'], $extension, $frameworktype)) >= 0) { - $numDeleted += $numDeletedAux if ($numDeletedAux > 0); - if (($numDeletedAux = _import_table($dbh, $subtable, $frameworkcode, $dom, ['frameworkcode', 'tagfield', 'tagsubfield'], $extension, $frameworktype)) >= 0) { + if ($frameworktype eq "authority"){ + if (($numDeletedAux = _import_table($dbh, $table, $frameworkcode, $dom, ['authtypecode', 'tagfield'], $extension, $frameworktype)) >= 0) { $numDeleted += $numDeletedAux if ($numDeletedAux > 0); - $ok = ($numDeleted > 0)?$numDeleted:0; + if (($numDeletedAux = _import_table($dbh, $subtable, $frameworkcode, $dom, ['authtypecode', 'tagfield', 'tagsubfield'], $extension, $frameworktype)) >= 0) { + $numDeleted += $numDeletedAux if ($numDeletedAux > 0); + $ok = ($numDeleted > 0)?$numDeleted:0; + } + } + } else { + if (($numDeletedAux = _import_table($dbh, $table, $frameworkcode, $dom, ['frameworkcode', 'tagfield'], $extension, $frameworktype)) >= 0) { + $numDeleted += $numDeletedAux if ($numDeletedAux > 0); + if (($numDeletedAux = _import_table($dbh, $subtable, $frameworkcode, $dom, ['frameworkcode', 'tagfield', 'tagsubfield'], $extension, $frameworktype)) >= 0) { + $numDeleted += $numDeletedAux if ($numDeletedAux > 0); + $ok = ($numDeleted > 0)?$numDeleted:0; + } } } } else { @@ -837,11 +847,11 @@ sub _import_table push @fieldsName, $hashRef->{Field}; } }; - $ok = _import_table_csv($dbh, $table, $frameworkcode, $dom, $PKArray, \%fields2Delete, \@fieldsName); + $ok = _import_table_csv($dbh, $table, $frameworkcode, $dom, $PKArray, \%fields2Delete, \@fieldsName, $frameworktype); } elsif ($format eq 'ods') { - $ok = _import_table_ods($dbh, $table, $frameworkcode, $dom, $PKArray, \%fields2Delete); + $ok = _import_table_ods($dbh, $table, $frameworkcode, $dom, $PKArray, \%fields2Delete, $frameworktype); } else { - $ok = _import_table_excel($dbh, $table, $frameworkcode, $dom, $PKArray, \%fields2Delete); + $ok = _import_table_excel($dbh, $table, $frameworkcode, $dom, $PKArray, \%fields2Delete, $frameworktype); } if ($ok) { if (($ok = scalar(keys %fields2Delete)) > 0) { @@ -912,7 +922,7 @@ sub _processRow_DB # Process the rows of a worksheet and insert/update them in a mysql table. sub _processRows_Table { - my ($dbh, $frameworkcode, $nodeR, $table, $PKArray, $format, $fields2Delete) = @_; + my ($dbh, $frameworkcode, $nodeR, $table, $PKArray, $format, $fields2Delete, $frameworktype) = @_; my $query; my @fields = (); @@ -939,7 +949,7 @@ sub _processRows_Table chop($updateStr) if ($updateStr); } else { # Get data from row - my ($dataFields, $dataFieldsR) = _getDataFields($frameworkcode, $nodeR, \@fields, $format); + my ($dataFields, $dataFieldsR) = _getDataFields($frameworkcode, $nodeR, \@fields, $format, $frameworktype); if (scalar(@fields) == scalar(@$dataFieldsR)) { $ok = _processRow_DB($dbh, $db_scheme, $table, $fields, $dataStr, $updateStr, $dataFieldsR, $dataFields, $PKArray, \@fieldsPK, $fields2Delete); } @@ -957,8 +967,7 @@ sub _processRows_Table # Import worksheet from the csv file to the mysql table sub _import_table_csv { - my ($dbh, $table, $frameworkcode, $dom, $PKArray, $fields2Delete, $fields) = @_; - + my ($dbh, $table, $frameworkcode, $dom, $PKArray, $fields2Delete, $fields, $frameworktype) = @_; my $row = ''; my $partialRow = ''; my $numFields = @$fields; @@ -1014,13 +1023,23 @@ sub _import_table_csv my $j = 0; my %dataFields = (); for (@arrData) { - if ($fields->[$j] eq 'frameworkcode' && $_ ne $frameworkcode) { - $dataFields{$fields->[$j]} = $frameworkcode; - $arrData[$j] = $frameworkcode; + if ($frameworktype eq "authority"){ + if ($fields->[$j] eq 'authtypecode' && $_ ne $frameworkcode) { + $dataFields{$fields->[$j]} = $frameworkcode; + $arrData[$j] = $frameworkcode; + } else { + $dataFields{$fields->[$j]} = $_; + } + $j++ } else { - $dataFields{$fields->[$j]} = $_; + if ($fields->[$j] eq 'frameworkcode' && $_ ne $frameworkcode) { + $dataFields{$fields->[$j]} = $frameworkcode; + $arrData[$j] = $frameworkcode; + } else { + $dataFields{$fields->[$j]} = $_; + } + $j++ } - $j++ } $ok = _processRow_DB($dbh, $db_scheme, $table, $fieldsStr, $dataStr, $updateStr, \@arrData, \%dataFields, $PKArray, \@fieldsPK, $fields2Delete); } @@ -1037,7 +1056,7 @@ sub _import_table_csv # Import worksheet from the ods content.xml file to the mysql table sub _import_table_ods { - my ($dbh, $table, $frameworkcode, $dom, $PKArray, $fields2Delete) = @_; + my ($dbh, $table, $frameworkcode, $dom, $PKArray, $fields2Delete, $frameworktype) = @_; my $xc = XML::LibXML::XPathContext->new($dom); $xc->registerNs('xmlns:office','urn:oasis:names:tc:opendocument:xmlns:office:1.0'); @@ -1047,7 +1066,7 @@ sub _import_table_ods @nodes = $xc->findnodes('//table:table[@table:name="' . $table . '"]'); if (@nodes == 1 && $nodes[0]->hasChildNodes()) { my $nodeR = $nodes[0]->firstChild; - return _processRows_Table($dbh, $frameworkcode, $nodeR, $table, $PKArray, 'ods', $fields2Delete); + return _processRows_Table($dbh, $frameworkcode, $nodeR, $table, $PKArray, 'ods', $fields2Delete, $frameworktype); } else { $debug and warn "Error _import_table_ods there's not worksheet for $table\n"; } @@ -1058,7 +1077,7 @@ sub _import_table_ods # Import worksheet from the excel-xml file to the mysql table sub _import_table_excel { - my ($dbh, $table, $frameworkcode, $dom, $PKArray, $fields2Delete) = @_; + my ($dbh, $table, $frameworkcode, $dom, $PKArray, $fields2Delete, $frameworktype) = @_; my $xc = XML::LibXML::XPathContext->new($dom); $xc->registerNs('xmlns','urn:schemas-microsoft-com:office:spreadsheet'); @@ -1071,7 +1090,7 @@ sub _import_table_excel my @nodesT = $nodes[$i]->getElementsByTagNameNS('urn:schemas-microsoft-com:office:spreadsheet', 'Table'); if (@nodesT == 1 && $nodesT[0]->hasChildNodes()) { my $nodeR = $nodesT[0]->firstChild; - return _processRows_Table($dbh, $frameworkcode, $nodeR, $table, $PKArray, undef, $fields2Delete); + return _processRows_Table($dbh, $frameworkcode, $nodeR, $table, $PKArray, undef, $fields2Delete, $frameworktype); } } } else { @@ -1108,7 +1127,7 @@ sub _getDataNodeODS # Get the data from a row of a spreadsheet sub _getDataFields { - my ($frameworkcode, $node, $fields, $format) = @_; + my ($frameworkcode, $node, $fields, $format, $frameworktype) = @_; my $dataFields = {}; my @dataFieldsA = (); @@ -1135,6 +1154,9 @@ sub _getDataFields if ($ok) { $data = '' if ($data eq '#'); $data = $frameworkcode if ($fields->[$i] eq 'frameworkcode'); + if ($frameworktype eq "authority") { + $data = $frameworkcode if ($fields->[$i] eq 'authtypecode'); + } $dataFields->{$fields->[$i]} = $data; push @dataFieldsA, $data; $i++; --- a/admin/import_export_authtype.pl +++ a/admin/import_export_authtype.pl @@ -17,9 +17,7 @@ # You should have received a copy of the GNU General Public License # along with Koha; if not, see . - -use strict; -use warnings; +use Modern::Perl; use CGI qw ( -utf8 ); use CGI::Cookie; use C4::Context; @@ -27,7 +25,6 @@ use C4::Auth qw/check_cookie_auth/; use C4::ImportExportFramework; my %cookies = CGI::Cookie->fetch(); -my $authenticated = 0; my ($auth_status, $sessionID); if (exists $cookies{'CGISESSID'}) { ($auth_status, $sessionID) = check_cookie_auth( @@ -35,13 +32,10 @@ if (exists $cookies{'CGISESSID'}) { { parameters => 'parameters_remaining_permissions' }, ); } -if ($auth_status eq 'ok') { - $authenticated = 1; -} my $input = new CGI; -unless ($authenticated) { +unless ($auth_status eq 'ok') { print $input->header(-type => 'text/plain', -status => '403 Forbidden'); exit 0; } @@ -88,7 +82,7 @@ if ($action eq 'export' && $input->request_method() eq 'GET') { my $extension = $1; my $uploadFd = $input->upload($fieldname); if ($uploadFd && !$input->cgi_error) { - my $tmpfilename = $input->tmpFileName($input->param($fieldname)); + my $tmpfilename = $input->tmpFileName(scalar $input->param($fieldname)); $filename = $tmpfilename . '.' . $extension; # rename the tmp file with the extension $ok = ImportFramework($filename, $authtypecode, 1, 'authority') if (rename($tmpfilename, $filename)); } --- a/admin/import_export_framework.pl +++ a/admin/import_export_framework.pl @@ -17,7 +17,6 @@ # You should have received a copy of the GNU General Public License # along with Koha; if not, see . - use Modern::Perl; use CGI qw ( -utf8 ); use CGI::Cookie; @@ -26,7 +25,6 @@ use C4::Auth qw/check_cookie_auth/; use C4::ImportExportFramework; my %cookies = CGI::Cookie->fetch(); -my $authenticated = 0; my ($auth_status, $sessionID); if (exists $cookies{'CGISESSID'}) { ($auth_status, $sessionID) = check_cookie_auth( @@ -34,13 +32,10 @@ if (exists $cookies{'CGISESSID'}) { { parameters => 'manage_marc_frameworks' }, ); } -if ($auth_status eq 'ok') { - $authenticated = 1; -} my $input = new CGI; -unless ($authenticated) { +unless ($auth_status eq 'ok') { print $input->header(-type => 'text/plain', -status => '403 Forbidden'); exit 0; } --