Bug 7295: More granular permissions for baskets
[koha.git] / tools / export.pl
index c7a8fd8..40c3b9b 100755 (executable)
 # Suite 330, Boston, MA  02111-1307 USA
 
 use Modern::Perl;
+use MARC::File::XML;
 use List::MoreUtils qw(uniq);
 use Getopt::Long;
 use CGI;
 use C4::Auth;
 use C4::AuthoritiesMarc;    # GetAuthority
-use C4::Biblio;             # GetMarcBiblio GetXmlBiblio
+use C4::Biblio;             # GetMarcBiblio
 use C4::Branch;             # GetBranches
 use C4::Csv;
 use C4::Koha;               # GetItemTypes
@@ -117,13 +118,13 @@ my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
 );
 
 my $limit_ind_branch =
-  (      C4::Context->preference('IndependantBranches')
+  (      C4::Context->preference('IndependentBranches')
       && C4::Context->userenv
       && !( C4::Context->userenv->{flags} & 1 )
       && C4::Context->userenv->{branch} ) ? 1 : 0;
 
 my $branch = $query->param("branch") || '';
-if (   C4::Context->preference("IndependantBranches")
+if (   C4::Context->preference("IndependentBranches")
     && C4::Context->userenv
     && !( C4::Context->userenv->{flags} & 1 ) )
 {
@@ -309,6 +310,7 @@ if ( $op eq "export" ) {
             } @{ $sth->fetchall_arrayref };
         }
 
+        my $xml_header_written = 0;
         for my $recordid ( uniq @recordids ) {
             if ($deleted_barcodes) {
                 my $q = "
@@ -374,19 +376,30 @@ if ( $op eq "export" ) {
                 }
                 RemoveAllNsb($record) if ($clean);
                 if ( $output_format eq "xml" ) {
-                    if ( $marcflavour eq 'UNIMARC' && $record_type eq 'auths' )
-                    {
-                        print $record->as_xml_record('UNIMARCAUTH');
-                    }
-                    else {
-                        print $record->as_xml_record($marcflavour);
+                    unless ($xml_header_written) {
+                        MARC::File::XML->default_record_format(
+                            (
+                                     $marcflavour eq 'UNIMARC'
+                                  && $record_type eq 'auths'
+                            ) ? 'UNIMARCAUTH' : $marcflavour
+                        );
+                        print MARC::File::XML::header();
+                        print "\n";
+                        $xml_header_written = 1;
                     }
+                    print MARC::File::XML::record($record);
+                    print "\n";
                 }
                 else {
                     print $record->as_usmarc();
                 }
             }
         }
+        if ($xml_header_written) {
+            print MARC::File::XML::footer();
+            print "\n";
+        }
+
         exit;
     }
     elsif ( $format eq "csv" ) {
@@ -466,7 +479,6 @@ else {
     $template->param(
         branchloop               => \@branchloop,
         itemtypeloop             => \@itemtypesloop,
-        DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
         authtypeloop             => \@authtypesloop,
         export_remove_fields     => C4::Context->preference("ExportRemoveFields"),
     );
@@ -506,7 +518,7 @@ sub construct_query {
             my $branch               = $params->{branch};
             my $start_callnumber     = $params->{start_callnumber};
             my $end_callnumber       = $params->{end_callnumber};
-            my $start_accession      = $params->{star_accession};
+            my $start_accession      = $params->{start_accession};
             my $end_accession        = $params->{end_accession};
             my $itemtype             = $params->{itemtype};
             my $items_filter =