#! /usr/bin/perl -w
# vim:syntax=perl
use strict;

use lib '/usr/local/share/perl5';

use Getopt::Long;
use Lire::Config;
use Lire::Program qw( :msg tempfile $PROG $LR_SUPERSERVICE $LR_ID );
use Lire::ReportParser::ExcelWriter;

my %opts = ('target-user'  => $ENV{LR_TARGET_USER} || 'sysadmin',
	     userlevel	    => $ENV{LR_USERLEVEL} || 'normal',
	   );
GetOptions( \%opts, "userlevel=s", "target-user=s" ) && @ARGV == 0
  or lr_err( "Usage $PROG [--userlevel normal|advanced] [--target-user sysadmin|manager] < report.xml" );

lr_err( "wrong value for target-user: $opts{'target-user'} (must be either 'sysadmin' or 'manager' )" )
  unless $opts{'target-user'} =~ /^(sysadmin|manager)$/;

lr_err( "wrong value for userlevel: $opts{userlevel} (must be either 'normal' or 'advanced' )" )
  unless $opts{userlevel} =~ /^(normal|advanced)$/;

my $parser = new Lire::ReportParser::ExcelWriter( %opts );
eval {
    $parser->parse(\*STDIN);
};
lr_err( $@ ) if $@;
lr_info( "parsing xml finished" );

exit 0;

__END__

=pod

=head1 NAME

lr_xml2xls - generate a Excel 95 spreadsheet from a raw xml report

=head1 SYNOPSIS
B<lr_xml2xls> [--target-user sysadmin|manager] [--userlevel normal|advanced] < report.xml

=head1 DESCRIPTION

This script uses the Spreadsheet::WriteExcel CPAN module to convert a
Lire XML report into a Excel95 spreadsheet. This spreadsheet file
format should work in all version of Excel(tm). It is also supported
by Gnumeric and OpenOffice.

It reads a XML report on STDIN and outputs a Excel95 spreadsheet on
STDOUT. Since this is a binary format, we suggests you use file
redirection!

=head1 SEE ALSO

lr_log2report(1), lr_xml2report(1), lr_xml2mail(1)

=head1 VERSION

$Id: lr_xml2xls.in,v 1.3 2002/08/17 01:56:17 flacoste Exp $

=head1 COPYRIGHT

Copyright (C) 2000-2002 Stichting LogReport Foundation LogReport@LogReport.org

This file is part of Lire.

Lire is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

=head1 AUTHOR

Francis J. Lacoste

=cut

# Local Variables:
# mode: cperl
# End:
