package WebGUI::Widget::SQLReport;
#-------------------------------------------------------------------
# WebGUI is Copyright 2001 Plain Black Software.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use strict;
use WebGUI::ErrorHandler;
use WebGUI::Macro;
use WebGUI::Privilege;
use WebGUI::Session;
use WebGUI::SQL;
use WebGUI::Utility;
use WebGUI::Widget;
#-------------------------------------------------------------------
sub purge {
WebGUI::SQL->write("delete from SQLReport where widgetId=$_[0]",$_[1]);
purgeWidget($_[0],$_[1]);
}
#-------------------------------------------------------------------
sub widgetName {
return "SQL Report";
}
#-------------------------------------------------------------------
sub www_add {
my ($output);
if (WebGUI::Privilege::canEditPage()) {
$output = '
';
$output .= '
';
$output .= ''; } @template = split(/\^\-/,$data{template}); $output .= $template[0]; if ($data{DSN} =~ /\DBI\:\w+\:\w+/) { $dbh = DBI->connect($data{DSN},$data{username},$data{identifier}); } else { $output .= 'Error: The DSN specified is of an improper format.
'; WebGUI::ErrorHandler::warn("SQLReport [$widgetId] The DSN specified is of an improper format."); } if (defined $dbh) { if ($data{dbQuery} =~ /select/i) { $sth = WebGUI::SQL->read($data{dbQuery},$dbh); } else { $output .= 'Error: The SQL query is improperly formatted.
';
WebGUI::ErrorHandler::warn("SQLReport [$widgetId] The SQL query is improperly formatted.");
}
if (defined $sth) {
while (@result = $sth->array) {
$temp = $template[1];
$temp =~ s/\^(\d)/$result[$1]/g;
if ($data{convertCarriageReturns}) {
$temp =~ s/\n/\
/g;
}
$output .= $temp;
}
$sth->finish;
} else {
$output .= 'Error: There was a problem with the query.
'; WebGUI::ErrorHandler::warn("SQLReport [$widgetId] There was a problem with the query."); } $dbh->disconnect(); } else { $output .= 'Error: Could not connect to remote database.
'; WebGUI::ErrorHandler::warn("SQLReport [$widgetId] Could not connect to remote database."); } $output .= $template[2]; } if ($data{processMacros} == 1) { $output = WebGUI::Macro::process($output); } return $output; } 1;