|
Lines 194-200
Functions for handling import/export.
Link Here
|
| 194 |
|
194 |
|
| 195 |
=head2 ExportFramework |
195 |
=head2 ExportFramework |
| 196 |
|
196 |
|
| 197 |
Export all the information of a Framework to an excel "xml" file or OpenDocument SpreadSheet "ods" file. |
197 |
Export all the information of a MARC or Authority Type Framework to an excel "xml" file, comma separated values "csv" file or OpenDocument SpreadSheet "ods" file. |
| 198 |
|
198 |
|
| 199 |
return : |
199 |
return : |
| 200 |
succes |
200 |
succes |
|
Lines 203-209
succes
Link Here
|
| 203 |
|
203 |
|
| 204 |
sub ExportFramework |
204 |
sub ExportFramework |
| 205 |
{ |
205 |
{ |
| 206 |
my ($frameworkcode, $xmlStrRef, $mode) = @_; |
206 |
my ($frameworkcode, $xmlStrRef, $mode, $frameworktype) = @_; |
| 207 |
|
207 |
|
| 208 |
my $dbh = C4::Context->dbh; |
208 |
my $dbh = C4::Context->dbh; |
| 209 |
if ($dbh) { |
209 |
if ($dbh) { |
|
Lines 230-237
sub ExportFramework
Link Here
|
| 230 |
} |
230 |
} |
| 231 |
} |
231 |
} |
| 232 |
|
232 |
|
| 233 |
if (_export_table('marc_tag_structure', $dbh, ($mode eq 'csv')?$xmlStrRef:$dom, ($mode eq 'ods')?$elementSS:$root, $frameworkcode, $mode)) { |
233 |
my $table = 'marc_tag_structure'; |
| 234 |
if (_export_table('marc_subfield_structure', $dbh, ($mode eq 'csv')?$xmlStrRef:$dom, ($mode eq 'ods')?$elementSS:$root, $frameworkcode, $mode)) { |
234 |
my $subtable = 'marc_subfield_structure'; |
|
|
235 |
if ($frameworktype && $frameworktype eq "authority") { |
| 236 |
$table = 'auth_tag_structure'; |
| 237 |
$subtable = 'auth_subfield_structure'; |
| 238 |
} |
| 239 |
|
| 240 |
if (_export_table($table, $dbh, ($mode eq 'csv')?$xmlStrRef:$dom, ($mode eq 'ods')?$elementSS:$root, $frameworkcode, $mode, $frameworktype)) { |
| 241 |
if (_export_table($subtable, $dbh, ($mode eq 'csv')?$xmlStrRef:$dom, ($mode eq 'ods')?$elementSS:$root, $frameworkcode, $mode, $frameworktype)) { |
| 235 |
$$xmlStrRef = $dom->toString(1) if ($mode eq 'ods' || $mode eq 'excel'); |
242 |
$$xmlStrRef = $dom->toString(1) if ($mode eq 'ods' || $mode eq 'excel'); |
| 236 |
return 1; |
243 |
return 1; |
| 237 |
} |
244 |
} |
|
Lines 246-265
sub ExportFramework
Link Here
|
| 246 |
# Export all the data from a mysql table to an spreadsheet. |
253 |
# Export all the data from a mysql table to an spreadsheet. |
| 247 |
sub _export_table |
254 |
sub _export_table |
| 248 |
{ |
255 |
{ |
| 249 |
my ($table, $dbh, $dom, $root, $frameworkcode, $mode) = @_; |
256 |
my ($table, $dbh, $dom, $root, $frameworkcode, $mode, $frameworktype) = @_; |
| 250 |
if ($mode eq 'csv') { |
257 |
if ($mode eq 'csv') { |
| 251 |
_export_table_csv($table, $dbh, $dom, $root, $frameworkcode); |
258 |
_export_table_csv($table, $dbh, $dom, $root, $frameworkcode, $frameworktype); |
| 252 |
} elsif ($mode eq 'ods') { |
259 |
} elsif ($mode eq 'ods') { |
| 253 |
_export_table_ods($table, $dbh, $dom, $root, $frameworkcode); |
260 |
_export_table_ods($table, $dbh, $dom, $root, $frameworkcode, $frameworktype); |
| 254 |
} else { |
261 |
} else { |
| 255 |
_export_table_excel($table, $dbh, $dom, $root, $frameworkcode); |
262 |
_export_table_excel($table, $dbh, $dom, $root, $frameworkcode, $frameworktype); |
| 256 |
} |
263 |
} |
| 257 |
} |
264 |
} |
| 258 |
|
265 |
|
| 259 |
# Export the mysql table to an csv file |
266 |
# Export the mysql table to an csv file |
| 260 |
sub _export_table_csv |
267 |
sub _export_table_csv |
| 261 |
{ |
268 |
{ |
| 262 |
my ($table, $dbh, $strCSV, $root, $frameworkcode) = @_; |
269 |
my ($table, $dbh, $strCSV, $root, $frameworkcode, $frameworktype) = @_; |
| 263 |
|
270 |
|
| 264 |
eval { |
271 |
eval { |
| 265 |
# First row with the name of the columns |
272 |
# First row with the name of the columns |
|
Lines 275-280
sub _export_table_csv
Link Here
|
| 275 |
$$strCSV .= chr(10); |
282 |
$$strCSV .= chr(10); |
| 276 |
# Populate rows with the data from mysql |
283 |
# Populate rows with the data from mysql |
| 277 |
$query = 'SELECT * FROM ' . $table . ' WHERE frameworkcode=?'; |
284 |
$query = 'SELECT * FROM ' . $table . ' WHERE frameworkcode=?'; |
|
|
285 |
if ($frameworktype eq "authority") { |
| 286 |
$query = 'SELECT * FROM ' . $table . ' WHERE authtypecode=?'; |
| 287 |
} |
| 278 |
$sth = $dbh->prepare($query); |
288 |
$sth = $dbh->prepare($query); |
| 279 |
$sth->execute($frameworkcode); |
289 |
$sth->execute($frameworkcode); |
| 280 |
my $data; |
290 |
my $data; |
|
Lines 306-312
sub _export_table_csv
Link Here
|
| 306 |
# Export the mysql table to an ods file |
316 |
# Export the mysql table to an ods file |
| 307 |
sub _export_table_ods |
317 |
sub _export_table_ods |
| 308 |
{ |
318 |
{ |
| 309 |
my ($table, $dbh, $dom, $root, $frameworkcode) = @_; |
319 |
my ($table, $dbh, $dom, $root, $frameworkcode, $frameworktype) = @_; |
| 310 |
|
320 |
|
| 311 |
eval { |
321 |
eval { |
| 312 |
my $elementTable = $dom->createElement('table:table'); |
322 |
my $elementTable = $dom->createElement('table:table'); |
|
Lines 335-340
sub _export_table_ods
Link Here
|
| 335 |
} |
345 |
} |
| 336 |
# Populate rows with the data from mysql |
346 |
# Populate rows with the data from mysql |
| 337 |
$query = 'SELECT * FROM ' . $table . ' WHERE frameworkcode=?'; |
347 |
$query = 'SELECT * FROM ' . $table . ' WHERE frameworkcode=?'; |
|
|
348 |
if ($frameworktype eq "authority") { |
| 349 |
$query = 'SELECT * FROM ' . $table . ' WHERE authtypecode=?'; |
| 350 |
} |
| 338 |
$sth = $dbh->prepare($query); |
351 |
$sth = $dbh->prepare($query); |
| 339 |
$sth->execute($frameworkcode); |
352 |
$sth->execute($frameworkcode); |
| 340 |
my $data; |
353 |
my $data; |
|
Lines 370-376
sub _export_table_ods
Link Here
|
| 370 |
# Export the mysql table to an excel-xml (openoffice/libreoffice compatible) file |
383 |
# Export the mysql table to an excel-xml (openoffice/libreoffice compatible) file |
| 371 |
sub _export_table_excel |
384 |
sub _export_table_excel |
| 372 |
{ |
385 |
{ |
| 373 |
my ($table, $dbh, $dom, $root, $frameworkcode) = @_; |
386 |
my ($table, $dbh, $dom, $root, $frameworkcode, $frameworktype) = @_; |
| 374 |
|
387 |
|
| 375 |
eval { |
388 |
eval { |
| 376 |
my $elementWS = $dom->createElement('Worksheet'); |
389 |
my $elementWS = $dom->createElement('Worksheet'); |
|
Lines 400-405
sub _export_table_excel
Link Here
|
| 400 |
} |
413 |
} |
| 401 |
# Populate rows with the data from mysql |
414 |
# Populate rows with the data from mysql |
| 402 |
$query = 'SELECT * FROM ' . $table . ' WHERE frameworkcode=?'; |
415 |
$query = 'SELECT * FROM ' . $table . ' WHERE frameworkcode=?'; |
|
|
416 |
if ($frameworktype eq "authority") { |
| 417 |
$query = 'SELECT * FROM ' . $table . ' WHERE authtypecode=?'; |
| 418 |
} |
| 403 |
$sth = $dbh->prepare($query); |
419 |
$sth = $dbh->prepare($query); |
| 404 |
$sth->execute($frameworkcode); |
420 |
$sth->execute($frameworkcode); |
| 405 |
my $data; |
421 |
my $data; |
|
Lines 429-440
sub _export_table_excel
Link Here
|
| 429 |
return 1; |
445 |
return 1; |
| 430 |
}#_export_table_excel |
446 |
}#_export_table_excel |
| 431 |
|
447 |
|
| 432 |
|
|
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
# Format chars problematics to a correct format for xml. |
448 |
# Format chars problematics to a correct format for xml. |
| 439 |
sub _parseContent2Xml |
449 |
sub _parseContent2Xml |
| 440 |
{ |
450 |
{ |
|
Lines 619-625
sub _getMeta
Link Here
|
| 619 |
|
629 |
|
| 620 |
=head2 ImportFramework |
630 |
=head2 ImportFramework |
| 621 |
|
631 |
|
| 622 |
Import all the information of a Framework from a excel-xml/ods file. |
632 |
Import all the information of a MARC or Authority Type Framework from a excel-xml/ods file. |
| 623 |
|
633 |
|
| 624 |
return : |
634 |
return : |
| 625 |
success |
635 |
success |
|
Lines 628-634
success
Link Here
|
| 628 |
|
638 |
|
| 629 |
sub ImportFramework |
639 |
sub ImportFramework |
| 630 |
{ |
640 |
{ |
| 631 |
my ($filename, $frameworkcode, $deleteFilename) = @_; |
641 |
my ($filename, $frameworkcode, $deleteFilename, $frameworktype) = @_; |
| 632 |
|
642 |
|
| 633 |
my $tempdir; |
643 |
my $tempdir; |
| 634 |
my $ok = -1; |
644 |
my $ok = -1; |
|
Lines 658-670
sub ImportFramework
Link Here
|
| 658 |
# They are text files, so open it to read |
668 |
# They are text files, so open it to read |
| 659 |
open($dom, '<', $filename); |
669 |
open($dom, '<', $filename); |
| 660 |
} |
670 |
} |
|
|
671 |
|
| 672 |
my $table = 'marc_tag_structure'; |
| 673 |
my $subtable = 'marc_subfield_structure'; |
| 674 |
if ($frameworktype && $frameworktype eq "authority") { |
| 675 |
$table = 'auth_tag_structure'; |
| 676 |
$subtable = 'auth_subfield_structure'; |
| 677 |
} |
| 678 |
|
| 661 |
if ($dom) { |
679 |
if ($dom) { |
| 662 |
# Process both tables |
680 |
# Process both tables |
| 663 |
my $numDeleted = 0; |
681 |
my $numDeleted = 0; |
| 664 |
my $numDeletedAux = 0; |
682 |
my $numDeletedAux = 0; |
| 665 |
if (($numDeletedAux = _import_table($dbh, 'marc_tag_structure', $frameworkcode, $dom, ['frameworkcode', 'tagfield'], $extension)) >= 0) { |
683 |
if (($numDeletedAux = _import_table($dbh, $table, $frameworkcode, $dom, ['frameworkcode', 'tagfield'], $extension, $frameworktype)) >= 0) { |
| 666 |
$numDeleted += $numDeletedAux if ($numDeletedAux > 0); |
684 |
$numDeleted += $numDeletedAux if ($numDeletedAux > 0); |
| 667 |
if (($numDeletedAux = _import_table($dbh, 'marc_subfield_structure', $frameworkcode, $dom, ['frameworkcode', 'tagfield', 'tagsubfield'], $extension)) >= 0) { |
685 |
if (($numDeletedAux = _import_table($dbh, $subtable, $frameworkcode, $dom, ['frameworkcode', 'tagfield', 'tagsubfield'], $extension, $frameworktype)) >= 0) { |
| 668 |
$numDeleted += $numDeletedAux if ($numDeletedAux > 0); |
686 |
$numDeleted += $numDeletedAux if ($numDeletedAux > 0); |
| 669 |
$ok = ($numDeleted > 0)?$numDeleted:0; |
687 |
$ok = ($numDeleted > 0)?$numDeleted:0; |
| 670 |
} |
688 |
} |
|
Lines 785-791
sub _check_validity_worksheet
Link Here
|
| 785 |
# Import the data from an excel-xml/ods to mysql tables. |
803 |
# Import the data from an excel-xml/ods to mysql tables. |
| 786 |
sub _import_table |
804 |
sub _import_table |
| 787 |
{ |
805 |
{ |
| 788 |
my ($dbh, $table, $frameworkcode, $dom, $PKArray, $format) = @_; |
806 |
my ($dbh, $table, $frameworkcode, $dom, $PKArray, $format, $frameworktype) = @_; |
| 789 |
my %fields2Delete; |
807 |
my %fields2Delete; |
| 790 |
my $query; |
808 |
my $query; |
| 791 |
my @fields; |
809 |
my @fields; |
|
Lines 794-799
sub _import_table
Link Here
|
| 794 |
@fields = @$PKArray; |
812 |
@fields = @$PKArray; |
| 795 |
shift @fields; |
813 |
shift @fields; |
| 796 |
$query = 'SELECT ' . join(',', @fields) . ' FROM ' . $table . ' WHERE frameworkcode=?'; |
814 |
$query = 'SELECT ' . join(',', @fields) . ' FROM ' . $table . ' WHERE frameworkcode=?'; |
|
|
815 |
if ($frameworktype eq "authority") { |
| 816 |
$query = 'SELECT ' . join(',', @fields) . ' FROM ' . $table . ' WHERE authtypecode=?'; |
| 817 |
} |
| 797 |
my $sth = $dbh->prepare($query); |
818 |
my $sth = $dbh->prepare($query); |
| 798 |
$sth->execute($frameworkcode); |
819 |
$sth->execute($frameworkcode); |
| 799 |
my $field; |
820 |
my $field; |