ASNMTAP
view release on metacpan or search on metacpan
applications/htmlroot/cgi-bin/admin/reports.pl view on Meta::CPAN
#!/usr/bin/env perl
# ---------------------------------------------------------------------------------------------------------
# © Copyright 2003-2011 Alex Peeters [alex.peeters@citap.be]
# ---------------------------------------------------------------------------------------------------------
# 2011/mm/dd, v3.002.003, reports.pl for ASNMTAP::Asnmtap::Applications::CGI
# ---------------------------------------------------------------------------------------------------------
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 CGI;
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
use ASNMTAP::Asnmtap::Applications::CGI v3.002.003;
use ASNMTAP::Asnmtap::Applications::CGI qw(:APPLICATIONS :CGI :ADMIN :DBREADWRITE :DBTABLES);
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
use vars qw($PROGNAME);
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$PROGNAME = "reports.pl";
my $prgtext = "Reports";
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.
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# URL Access Parameters
my $cgi = new CGI;
my $pagedir = (defined $cgi->param('pagedir')) ? $cgi->param('pagedir') : '<NIHIL>'; $pagedir =~ s/\+/ /g;
my $pageset = (defined $cgi->param('pageset')) ? $cgi->param('pageset') : 'admin'; $pageset =~ s/\+/ /g;
my $debug = (defined $cgi->param('debug')) ? $cgi->param('debug') : 'F';
my $pageNo = (defined $cgi->param('pageNo')) ? $cgi->param('pageNo') : 1;
my $pageOffset = (defined $cgi->param('pageOffset')) ? $cgi->param('pageOffset') : 0;
my $orderBy = (defined $cgi->param('orderBy')) ? $cgi->param('orderBy') : 'reportTitle';
my $action = (defined $cgi->param('action')) ? $cgi->param('action') : 'listView';
my $CcatalogID = (defined $cgi->param('catalogID')) ? $cgi->param('catalogID') : $CATALOGID;
my $CcatalogIDreload = (defined $cgi->param('catalogIDreload')) ? $cgi->param('catalogIDreload') : 0;
my $Cid = (defined $cgi->param('id')) ? $cgi->param('id') : 'new';
my $CuKey = (defined $cgi->param('uKey')) ? $cgi->param('uKey') : 'none';
my $CreportTitle = (defined $cgi->param('reportTitle')) ? $cgi->param('reportTitle') : '';
my $Cperiode = (defined $cgi->param('periode')) ? $cgi->param('periode') : 'none';
my $CtimeperiodID = (defined $cgi->param('timeperiodID')) ? $cgi->param('timeperiodID') : 'none';
my $Cstatus = (defined $cgi->param('status')) ? $cgi->param('status') : 'off';
my $CerrorDetails = (defined $cgi->param('errorDetails')) ? $cgi->param('errorDetails') : 'off';
my $Cbar = (defined $cgi->param('bar')) ? $cgi->param('bar') : 'off';
my $ChourlyAverage = (defined $cgi->param('hourlyAverage')) ? $cgi->param('hourlyAverage') : 'off';
my $CdailyAverage = (defined $cgi->param('dailyAverage')) ? $cgi->param('dailyAverage') : 'off';
my $CshowDetails = (defined $cgi->param('showDetails')) ? $cgi->param('showDetails') : 'off';
my $CshowComments = (defined $cgi->param('showComments')) ? $cgi->param('showComments') : 'off';
my $CshowPerfdata = (defined $cgi->param('showPerfdata')) ? $cgi->param('showPerfdata') : 'off';
my $CshowTop20SlowTests = (defined $cgi->param('showTop20SlowTests')) ? $cgi->param('showTop20SlowTests') : 'off';
my $CprinterFriendlyOutput = (defined $cgi->param('printerFriendlyOutput')) ? $cgi->param('printerFriendlyOutput') : 'off';
my $CformatOutput = (defined $cgi->param('formatOutput')) ? $cgi->param('formatOutput') : 'none';
my $CuserPassword = (defined $cgi->param('userPassword')) ? $cgi->param('userPassword') : '';
my $Cactivated = (defined $cgi->param('activated')) ? $cgi->param('activated') : 'off';
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
my $htmlTitle = $APPLICATION;
# Init parameters
my ($rv, $dbh, $sth, $sql, $header, $numberRecordsIntoQuery, $nextAction, $formDisabledAll, $formDisabledPrimaryKey, $submitButton, $uKeySelect);
# User Session and Access Control
my ($sessionID, $iconAdd, $iconDelete, $iconDetails, $iconEdit, $iconQuery, $iconTable, $errorUserAccessControl, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, $subTitle) = user_session_and_access_control (1, 'admin', $c...
# Serialize the URL Access Parameters into a string
my $urlAccessParameters = "pagedir=$pagedir&pageset=$pageset&debug=$debug&CGISESSID=$sessionID&pageNo=$pageNo&pageOffset=$pageOffset&orderBy=$orderBy&action=$action&catalogID=$CcatalogID&catalogIDreload=$CcatalogIDreload&id=$Cid&uKey=$CuKey&reportTit...
# Debug information
print "<pre>pagedir : $pagedir<br>pageset : $pageset<br>debug : $debug<br>CGISESSID : $sessionID<br>page no : $pageNo<br>page offset : $pageOffset<br>order by : $orderBy<br>action : $action<br>catalog ID ...
if ( defined $sessionID and ! defined $errorUserAccessControl ) {
my ($catalogIDSelect, $matchingReports, $navigationBar);
my $urlWithAccessParameters = $ENV{SCRIPT_NAME} . "?pagedir=$pagedir&pageset=$pageset&debug=$debug&CGISESSID=$sessionID&pageNo=$pageNo&pageOffset=$pageOffset&catalogID=$CcatalogID";
# open connection to database and query data
$rv = 1;
$dbh = DBI->connect("dbi:mysql:$DATABASE:$SERVERNAMEREADWRITE:$SERVERPORTREADWRITE", "$SERVERUSERREADWRITE", "$SERVERPASSREADWRITE" ) or $rv = error_trap_DBI(*STDOUT, "Cannot connect to the database", $debug, $pagedir, $pageset, $htmlTitle, $subTit...
if ($dbh and $rv) {
$formDisabledAll = ''; $formDisabledPrimaryKey = "disabled";
if ($action eq 'duplicateView' or $action eq 'insertView') {
$htmlTitle = "Insert Report";
$submitButton = "Insert";
$nextAction = "insert" if ($rv);
$CcatalogID = $CATALOGID if ($action eq 'insertView');
} elsif ($action eq 'insert') {
$htmlTitle = "Check if Report $Cid from $CcatalogID exist before to insert";
$sql = "select id from $SERVERTABLREPORTS WHERE catalogID='$CcatalogID' and id='$Cid'";
($rv, $numberRecordsIntoQuery) = do_action_DBI ($rv, $dbh, $sql, $pagedir, $pageset, $htmlTitle, $subTitle, $sessionID, $debug);
if ( $numberRecordsIntoQuery ) {
$htmlTitle = "Report $Cid from $CcatalogID exist already";
$nextAction = "insertView";
} else {
$htmlTitle = "Report $Cid from $CcatalogID inserted";
my $dummyStatus = ($Cstatus eq 'on') ? 1 : 0;
my $dummyErrorDetails = ($CerrorDetails eq 'on') ? 1 : 0;
my $dummyBar = ($Cbar eq 'on') ? 1 : 0;
my $dummyHourlyAverage = ($ChourlyAverage eq 'on') ? 1 : 0;
my $dummyDailyAverage = ($CdailyAverage eq 'on') ? 1 : 0;
my $dummyShowDetails = ($CshowDetails eq 'on') ? 1 : 0;
my $dummyShowComments = ($CshowComments eq 'on') ? 1 : 0;
my $dummyShowPerfdata = ($CshowPerfdata eq 'on') ? 1 : 0;
my $dummyShowTop20SlowTests = ($CshowTop20SlowTests eq 'on') ? 1 : 0;
my $dummyPrinterFriendlyOutput = ($CprinterFriendlyOutput eq 'on') ? 1 : 0;
my $dummyActivated = ($Cactivated eq 'on') ? 1 : 0;
$sql = 'INSERT INTO ' .$SERVERTABLREPORTS. ' SET catalogID="' .$CcatalogID. '", uKey="' .$CuKey. '", reportTitle="' .$CreportTitle. '", periode="' .$Cperiode. '", timeperiodID="' .$CtimeperiodID. '", status="' .$dummyStatus. '", errorDetails=...
$dbh->do ( $sql ) or $rv = error_trap_DBI(*STDOUT, "Cannot dbh->do: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID);
$nextAction = "listView" if ($rv);
}
} elsif ($action eq 'deleteView') {
$formDisabledAll = "disabled";
$htmlTitle = "Delete Report $Cid from $CcatalogID";
$submitButton = "Delete";
$nextAction = "delete" if ($rv);
} elsif ($action eq 'delete') {
$sql = "select id, $SERVERTABLREPORTS.uKey from $SERVERTABLREPORTS, $SERVERTABLREPORTSPRFDT where $SERVERTABLREPORTS.catalogID = '$CcatalogID' and id = '$Cid' and $SERVERTABLREPORTS.catalogID = $SERVERTABLREPORTSPRFDT.catalogID and $SERVERTABLR...
($rv, $matchingReports) = check_record_exist ($rv, $dbh, $sql, 'Reports from ' .$CcatalogID, 'ID', 'uKey', $matchingReports, $pagedir, $pageset, $htmlTitle, $subTitle, $sessionID, $debug);
if ($matchingReports eq '') {
$sql = 'DELETE FROM ' .$SERVERTABLREPORTS. ' WHERE catalogID="' .$CcatalogID. '" and id="' .$Cid. '"';
$dbh->do ( $sql ) or $rv = error_trap_DBI(*STDOUT, "Cannot dbh->do: $sql", $debug, $pagedir, $pageset, $htmlTitle, $subTitle, 3600, '', $sessionID);
$nextAction = "listView" if ($rv);
$htmlTitle = "Report $Cid from $CcatalogID deleted";
} else {
$htmlTitle = "Report $Cid from $CcatalogID not deleted, still used by";
( run in 0.410 second using v1.01-cache-2.11-cpan-39bf76dae61 )