ASNMTAP

 view release on metacpan or  search on metacpan

applications/bin/generateReports.pl  view on Meta::CPAN

#!/usr/bin/env perl
# ---------------------------------------------------------------------------------------------------------
# © Copyright 2003-2011 Alex Peeters [alex.peeters@citap.be]
# ---------------------------------------------------------------------------------------------------------
# 2011/mm/dd, v3.002.003, generateReports.pl for ASNMTAP::Applications
# ---------------------------------------------------------------------------------------------------------

use strict;
use warnings;           # Must be used in test mode only. This reduces a little process speed
#use diagnostics;       # Must be used in test mode only. This reduces a lot of process speed

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

BEGIN { if ( $ENV{ASNMTAP_PERL5LIB} ) { eval 'use lib ( "$ENV{ASNMTAP_PERL5LIB}" )'; } }

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

use DBI;
use Date::Calc qw(Add_Delta_Days Day_of_Week Days_in_Month Week_of_Year);
use Time::Local;
use Getopt::Long;

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

use ASNMTAP::Asnmtap::Applications v3.002.003;
use ASNMTAP::Asnmtap::Applications qw(:APPLICATIONS &call_system

                                      $CATALOGID
                                      $REPORTDIR
                                      $RESULTSPATH
                                      $REMOTE_HOST $HTTPSURL
                                      $HTMLTOPDFPRG $HTMLTOPDFOPTNS
                                      &create_header &create_footer
                                      &init_email_report &send_email_report &encode_html_entities
                                      &DBI_error_trap
                                      &LOG_init_log4perl

                                      $DATABASE $SERVERNAMEREADONLY $SERVERPORTREADONLY $SERVERUSERREADONLY $SERVERPASSREADONLY
                                      $SERVERTABLENVIRONMENT $SERVERTABLPLUGINS $SERVERTABLREPORTS);

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

use vars qw($opt_y $opt_m $opt_d $opt_a $opt_u  $opt_V $opt_h $opt_D $PROGNAME);

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

$PROGNAME       = "generateReports.pl";
my $prgtext     = "Generate Reports for the '$APPLICATION'";
my $version     = do { my @r = (q$Revision: 3.002.003$ =~ /\d+/g); sprintf "%d."."%03d" x $#r, @r }; # must be all on one line or MakeMaker will get confused.

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

my $debug       = 0;                                            # default
my $daysAfter   = 3;                                            # default

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

my ($currentYear, $currentMonth, $currentDay) = ( ((localtime)[5] + 1900), ((localtime)[4] + 1), (localtime)[3] );

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

sub print_help ();
sub print_usage ();

Getopt::Long::Configure('bundling');

GetOptions (
  "y:s" => \$opt_y, "year:s"        => \$opt_y,
  "m:s" => \$opt_m, "month:s"       => \$opt_m,
  "d:s" => \$opt_d, "day:s"         => \$opt_d,
  "a:s" => \$opt_a, "daysAfter:s"   => \$opt_a,
  "u:s" => \$opt_u, "ukey:s"        => \$opt_u,
  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  "D:s" => \$opt_D, "debug:s"       => \$opt_D,
  "V"   => \$opt_V, "version"       => \$opt_V,
  "h"   => \$opt_h, "help"          => \$opt_h
);

if ($opt_V) { print_revision($PROGNAME, $version); exit $ERRORS{OK}; }
if ($opt_h) { print_help(); exit $ERRORS{OK}; }

if ($opt_D) {
  if ($opt_D eq 'F' || $opt_D eq 'T' || $opt_D eq 'L') {
    $debug = 0 if ($opt_D eq 'F');
    $debug = 1 if ($opt_D eq 'T');
    $debug = 2 if ($opt_D eq 'L');
  } else {
    usage("Invalid debug: $opt_D\n");
  }
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

if ($opt_a) {
  if ($opt_a =~ /^[0-9]+$/) {
    $daysAfter = $opt_a;
  } elsif ($opt_a =~ /^F$/) {
    $daysAfter = 0;
  } else {
    usage("Invalid days after: $opt_a\n");
  }
}

my $uKeySqlWhere = (defined $opt_u) ? $SERVERTABLREPORTS.'.uKey = "' .$opt_u .'" AND' : '';

if ($opt_y) {
  if ($opt_y =~ /^20\d\d$/) {
    $currentYear = $opt_y;
  } else {
    usage("Invalid current year: $opt_y\n");
  }
}

if ($opt_m) {

applications/bin/generateReports.pl  view on Meta::CPAN

    }

    $dbh->disconnect or $rv = DBI_error_trap(*EMAILREPORT, "Sorry, the database was unable to add your entry.", \$logger, $debug);
    my $teller = 0;
    $emailMessage .= "\n";

    foreach my $command (@commands) {
      if ($HTMLTOPDFPRG eq 'HTMLDOC') {
        $ENV{HTMLDOC_NOCGI} = 1;
        select(STDOUT);  $| = 1;
      }

      my ($status, $stdout, $stderr) = call_system ("$command", $debug);

      unless ( $status == 0 and $stdout eq '' and $stderr eq '' ) {
        $emailMessage .= $pdfFilenames[$teller]. " generation failed\n";
        $emailMessage .= "call_system: command: $command, status: $status, stdout: $stdout, stderr: $stderr\n" if ( $debug );
      } else {
        $emailMessage .= $pdfFilenames[$teller]. " generated\n";
      }

      $teller++;
    }

    if ( $debug ) { print $emailMessage; } else { print EMAILREPORT $emailMessage; }
  }
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

my ($rc) = send_email_report (*EMAILREPORT, $emailReport, $rvOpen, $prgtext, $debug);
exit;

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

sub create_dir {
  my ($directory) = @_;

  unless ( -e "$directory" ) {                        # create $directory
    my ($status, $stdout, $stderr) = call_system ("mkdir $directory", $debug);

    if (!$status and ($stdout ne '' or $stderr ne '')) {
      my $error = "  > create_dir: mkdir $directory: status: $status, stdout: $stdout, stderr: $stderr\n";
      if ( $debug ) { print $error; } else { print EMAILREPORT $error; }
    }
  }
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

sub print_usage () {
  print "Usage: $PROGNAME [-y <year>] [-m <month>] [-d <day>] [-a <days after>] [-u <uKey>] [-D <debug>] [-V version] [-h help]\n";
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

sub print_help () {
  print_revision($PROGNAME, $version);
  print "ASNMTAP Generate Reports for the '$APPLICATION'

-y, --year=<year> (default: current year)
-m, --month=<month> (default: current month)
-d, --day=<day> (default: current day)
-a, --daysAfter=<days after|F(alse)> (default: 3)
-u, --uKey=<uKey plugin> (default: all plugins)
-D, --debug=F|T|L
   F(alse)  : screendebugging off (default)
   T(true)  : normal screendebugging on
   L(ong)   : long screendebugging on
-V, --version
-h, --help

Send email to $SENDEMAILTO if you have questions regarding
use of this software. To submit patches or suggest improvements, send
email to $SENDEMAILTO

";
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



( run in 0.604 second using v1.01-cache-2.11-cpan-39bf76dae61 )