[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Koha-cvs] koha/C4 Export.pm [rel_2_2]
From: |
Mason James |
Subject: |
[Koha-cvs] koha/C4 Export.pm [rel_2_2] |
Date: |
Mon, 15 Jan 2007 21:07:58 +0000 |
CVSROOT: /sources/koha
Module name: koha
Branch: rel_2_2
Changes by: Mason James <sushi> 07/01/15 21:07:58
Added files:
C4 : Export.pm
Log message:
new module with export/dumping routines.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Export.pm?cvsroot=koha&only_with_tag=rel_2_2&rev=1.1.2.1
Patches:
Index: Export.pm
===================================================================
RCS file: Export.pm
diff -N Export.pm
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ Export.pm 15 Jan 2007 21:07:58 -0000 1.1.2.1
@@ -0,0 +1,78 @@
+#!/usr/bin/perl -w
+
+package C4::Export;
+
+use strict;
+use C4::Context;
+use HTML::Template;
+require Exporter;
+use C4::Database;
+use C4::Interface::CGI::Output;
+use CGI;
+use Text::CSV_XS;
+use XML::Simple;
+
+use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
+
+$VERSION = 0.01;
+
address@hidden = qw(Exporter);
+
address@hidden = qw(
+ &export_bibs_by_date_to_file
+);
+
+sub export_bibs_by_date_to_file {
+ $DB::single = 1;
+
+ my ( $start_date, $end_date, $format, $filename ) = @_;
+ my $query = new CGI;
+ my $dbh = C4::Context->dbh;
+ my $sth = $dbh->prepare(
+ "select * from biblio, biblioitems, items, marc_biblio
+ where (datecreated >= ? and datecreated <= ?)
+ and (biblio.biblionumber = biblioitems.biblionumber)
+ and (biblioitems.biblioitemnumber = items.biblioitemnumber)
+ and (marc_biblio.biblionumber = biblio.biblionumber) limit 2"
+ );
+ $sth->execute( $start_date, $end_date );
+
+ if ( $format eq 'csv' ) {
+ print $query->header( -attachment => "$filename" );
+ my $csv = Text::CSV_XS->new(
+ {
+ 'quote_char' => '"',
+ 'escape_char' => '"',
+ 'sep_char' => ',',
+ 'binary' => 1
+ }
+ );
+
+ my $first;
+ while ( my $rec = $sth->fetchrow_hashref ) {
+ if ( !$first ) {
+ my @cols = keys(%$rec);
+ $csv->combine(@cols);
+ my $string = $csv->string;
+ print $string, "\n";
+ $first = 1;
+ }
+ my @fields = values(%$rec);
+ $csv->combine(@fields);
+ my $string = $csv->string;
+ print $string, "\n";
+ }
+ }
+ elsif ( $format eq 'xml' ) {
+ print $query->header(
+ -attachment => "$filename",
+ -type => 'text/xml'
+ );
+ while ( my $rec = $sth->fetchrow_hashref ) {
+ my $xml = XMLout( $rec, AttrIndent => 1, XMLDecl => 1 );
+ print $xml, "\n";
+ }
+ }
+}
+
+1;
- [Koha-cvs] koha/C4 Export.pm [rel_2_2],
Mason James <=