BUGFIX : encoding problem & security problem
[koha_fer] / tools / export.pl
index c540c64..d90d7fc 100755 (executable)
 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 # Suite 330, Boston, MA  02111-1307 USA
 
-# $Id$
 
 use strict;
 require Exporter;
 use C4::Auth;
-use C4::Interface::CGI::Output;
 use C4::Output;  # contains gettemplate
 use C4::Biblio;  # GetMarcBiblio GetXmlBiblio
 use CGI;
@@ -30,13 +28,29 @@ use C4::Branch;  # GetBranches
 
 my $query = new CGI;
 my $op=$query->param("op");
+my $filename=$query->param("filename");
 my $dbh=C4::Context->dbh;
 my $marcflavour = C4::Context->preference("marcflavour");
 
-if ($op eq "export") {
+my ($template, $loggedinuser, $cookie)
+    = get_template_and_user
+    (
+        {
+            template_name => "tools/export.tmpl",
+            query => $query,
+            type => "intranet",
+            authnotrequired => 0,
+            flagsrequired => {tools => 1},
+            debug => 1,
+            }
+    );
 
-    print $query->header('Content-Type: text/marc');
-    
+if ($op eq "export") {
+    binmode(STDOUT,":utf8");
+       print $query->header(   -type => 'application/octet-stream', 
+                            -charset => 'utf-8',
+                            -attachment=>$filename);
+     
     my $StartingBiblionumber  = $query->param("StartingBiblionumber");
     my $EndingBiblionumber    = $query->param("EndingBiblionumber");
     my $output_format         = $query->param("output_format");
@@ -89,7 +103,7 @@ if ($op eq "export") {
         if ( $dont_export_items ) {
             # now, find where the itemnumber is stored & extract only the item
             my ( $itemnumberfield, $itemnumbersubfield ) =
-                GetMarcFromKohaField( $dbh, 'items.itemnumber', '' );
+                GetMarcFromKohaField( 'items.itemnumber', '' );
 
             # and delete it.
             foreach ($record->field($itemnumberfield)){
@@ -115,7 +129,7 @@ if ($op eq "export") {
             print $record->as_xml_record($marcflavour);
         }
         else {
-            print $record->as_formatted
+            print $record->as_usmarc()
         }
     }
     exit;
@@ -156,11 +170,10 @@ else {
             query => $query,
             type => "intranet",
             authnotrequired => 0,
-            flagsrequired => {tools => 1},
+            flagsrequired => {tools => 'export_catalog'},
             debug => 1,
          }
     );
-    
     $template->param(
         branchloop   => \@branchloop,
         itemtypeloop => \@itemtypesloop