migrating SQL reports

This commit is contained in:
JT Smith 2003-12-10 23:35:41 +00:00
parent 10f3b3578d
commit adef55be5f
11 changed files with 344 additions and 137 deletions

View file

@ -67,4 +67,8 @@ WebGUI::Form::dateTime() and WebGUI::HTMLForm->dateTime() no longer have
because there is only one field to represent both the date and the time,
unlike before.
5.2 Database Links
The database links API was changed in 6.0. The getHash function was removed and
replaced with a getList function that returns a hash reference.

File diff suppressed because one or more lines are too long

View file

@ -323,6 +323,98 @@ WebGUI::SQL->write("delete from incrementer where incrementerId='LinkList_linkId
#--------------------------------------------
print "\tUpdating SQL Reports.\n" unless ($quiet);
my %dblink;
$dblink{$session{config}{dsn}} = (
id=>0,
user=>$session{config}{dbuser}
);
my $sth = WebGUI::SQL->read("select DSN, databaseLinkId, username, identifier, wobjectId from SQLReport");
while (my $data = $sth->hashRef) {
my $id = undef;
next if ($data->{databaseLinkId} > 0);
foreach my $dsn (keys %dblink) {
if ($dsn eq $data->{dsn} && $dblink{$dsn}{user} eq $data->{username}) {
$id = $dblink{$dsn}{id};
last;
}
}
unless (defined $id) {
$id = getNextId("databaseLinkId");
my $title = $data->{username}.'@'.$data->{DSN};
WebGUI::SQL->write("insert into databaseLink (databaseLinkId, title, DSN, username, identifier) values ($id, ".quote($title).",
".quote($data->{DSN}).", ".quote($data->{username}).", ".quote($data->{identifier}).")");
$dblink{$data->{DSN}} = (
id=>$id,
user=>$data->{username}
);
}
WebGUI::SQL->write("update SQLReport set databaseLinkId=".$id." where wobjectId=".$data->{wobjectId});
}
$sth->finish;
WebGUI::SQL->write("alter table SQLReport drop column DSN");
WebGUI::SQL->write("alter table SQLReport drop column username");
WebGUI::SQL->write("alter table SQLReport drop column identifier");
use WebGUI::DatabaseLink;
my $templateId;
my $a = WebGUI::SQL->read("select a.databaseLinkId, a.dbQuery, a.template, a.wobjectId, b.title from SQLReport a
left join wobject b on a.wobjectId=b.wobjectId");
while (my $data = $a->hashRef) {
my $db = WebGUI::DatabaseLink->new($data->{databaseLinkId});
if ($data->{template} ne "") {
($templateId) = WebGUI::SQL->quickArray("select max(templateId) from template where namespace='SQLReport'");
if ($templateId > 999) {
$templateId++;
} else {
$templateId = 1000;
}
my $b = WebGUI::SQL->unconditionalRead($data->{dbQuery},$db->dbh);
my @template = split(/\^\-\;/,$data->{template});
my $final = '<tmpl_if displayTitle>
<h1><tmpl_var title></h1>
</tmpl_if>
<tmpl_if description>
<tmpl_var description><p />
</tmpl_if>
<tmpl_if debugMode>
<ul>
<tmpl_loop debug_loop>
<li><tmpl_var debug.output></li>
</tmpl_loop>
</ul>
</tmpl_if>
'.$template[0].'
<tmpl_loop rows_loop> ';
my $i;
foreach my $col ($b->getColumnNames) {
my $replacement = '<tmpl_var row.field.'.$col.'.value>';
$template[1] =~ s/\^$i\;/$replacement/g;
$i++;
}
$template[1] =~ s/\^rownum\;/\<tmpl_var row\.number\>/g;
$final .= $template[1].'
</tmpl_loop>
'.$template[2].'
<tmpl_if multiplePages>
<div class="pagination">
<tmpl_var previousPage> <tmpl_var pageList> <tmpl_var nextPage>
</div>
</tmpl_if>';
WebGUI::SQL->write("insert into template (templateId, name, template, namespace) values ($templateId,
".quote($data->{title}).",".quote($final).",'SQLReport')");
} else {
$templateId = 1;
}
WebGUI::SQL->write("insert into wobject set templateId=$templateId where wobjectId=".$data->{wobjectId});
}
$a->finish;
WebGUI::SQL->write("alter table SQLReport drop column template");
#--------------------------------------------
print "\tUpdating config file.\n" unless ($quiet);
my $pathToConfig = '../../etc/'.$configFile;

View file

@ -175,4 +175,14 @@ INSERT INTO template VALUES (2,'Horizontal Login Box','<div class=\"loginBox\">\
INSERT INTO template VALUES (2,'DHTML Admin Bar','<script language=\"JavaScript1.2\" src=\"^Extras;/coolmenus/coolmenus4.js\">\n/*****************************************************************************\nCopyright (c) 2001 Thomas Brattli (webmaster@dhtmlcentral.com)\n \nDHTML coolMenus - Get it at coolmenus.dhtmlcentral.com\nVersion 4.0_beta\nThis script can be used freely as long as all copyright messages are\nintact.\n \nExtra info - Coolmenus reference/help - Extra links to help files ****\nCSS help: http://192.168.1.31/projects/coolmenus/reference.asp?m=37\nGeneral: http://coolmenus.dhtmlcentral.com/reference.asp?m=35\nMenu properties: http://coolmenus.dhtmlcentral.com/properties.asp?m=47\nLevel properties: http://coolmenus.dhtmlcentral.com/properties.asp?m=48\nBackground bar properties: http://coolmenus.dhtmlcentral.com/properties.asp?m=49\nItem properties: http://coolmenus.dhtmlcentral.com/properties.asp?m=50\n******************************************************************************/\n</script>\n<style type=\"text/css\">\n \n.adminBarTop,.adminBarTopOver,.adminBarSub,.adminBarSubOver{position:absolute; overflow:hidden; width:130; height:25; cursor:pointer; cursor:hand}\n.adminBarTop,.adminBarTopOver{padding:4px; font-size:12px; font-weight:bold}\n.adminBarTop{color:white; }\n.adminBarTopOver,.adminBarSubOver{color:#EC4300;}\n.adminBarSub,.adminBarSubOver{padding:2px; font-size:11px; font-weight:bold}\n.adminBarSub{color: white; background-color: #666666; layer-background-color: #666666;}\n.adminBarSubOver,.adminBarSubOver,.adminBarBorder,.adminBarBkg{layer-background-color: black; background-color: black;}\n.adminBarBorder{position:absolute; visibility:hidden; z-index:300}\n.adminBarBkg{position:absolute; width:10; height:10; visibility:hidden; }\n</style>\n\n<script language=\"JavaScript1.2\">\nadminBar=new makeCM(\"adminBar\"); \n\n//menu properties\nadminBar.resizeCheck=1; \nadminBar.rows=1; \nadminBar.onlineRoot=\"\"; \nadminBar.pxBetween =0;\nadminBar.fillImg=\"^Extras/spacer.gif\"; \nadminBar.fromTop=0; \nadminBar.fromLeft=50; \nadminBar.wait=300; \nadminBar.zIndex=10000;\nadminBar.menuPlacement=\"left\";\n\n//background bar properties\nadminBar.useBar=1; \nadminBar.barWidth=\"100%\"; \nadminBar.barHeight=\"menu\"; \nadminBar.barX=0;\nadminBar.barY=\"menu\"; \nadminBar.barClass=\"adminBarBkg\";\nadminBar.barBorderX=0; \nadminBar.barBorderY=0;\n\nadminBar.level[0]=new cm_makeLevel(150,20,\"adminBarTop\",\"adminBarTopOver\",1,1,\"adminBarBorder\",0,\"bottom\",0,0,0,0,0);\nadminBar.level[1]=new cm_makeLevel(150,18,\"adminBarSub\",\"adminBarSubOver\",1,1,\"adminBarBorder\",0,\"right\",0,0,\"menu_arrow.gif\",10,10);\n\n\nadminBar.makeMenu(\'addcontent\',\'\',\'<tmpl_var addcontent.label>\',\'\');\n<tmpl_loop addcontent_loop> \n adminBar.makeMenu(\'addcontent<tmpl_var addcontent.count>\',\'addcontent\',\'<tmpl_var addcontent.label>\',\'<tmpl_var addcontent.url>\');\n</tmpl_loop>\n\nadminBar.makeMenu(\'clipboard\',\'\',\'<tmpl_var clipboard.label>\',\'\');\n<tmpl_loop clipboard_loop> \n adminBar.makeMenu(\'clipboard<tmpl_var clipboard.count>\',\'clipboard\',\'<tmpl_var clipboard.label>\',\'<tmpl_var clipboard.url>\');\n</tmpl_loop>\n\nadminBar.makeMenu(\'admin\',\'\',\'<tmpl_var admin.label>\',\'\');\n<tmpl_loop admin_loop> \n adminBar.makeMenu(\'admin<tmpl_var admin.count>\',\'admin\',\'<tmpl_var admin.label>\',\'<tmpl_var admin.url>\');\n</tmpl_loop>\n \nadminBar.construct()\n</script>\n<br />\n','Macro/AdminBar');
INSERT INTO template VALUES (1,'Default Admin Bar',' <script language=\"JavaScript\" type=\"text/javascript\"> <!--\n function goContent(){\n location = document.content.contentSelect.options[document.content.contentSelect.selectedIndex].value\n }\n function goAdmin(){\n location = document.admin.adminSelect.options[document.admin.adminSelect.selectedIndex].value\n }\n function goClipboard(){\n location = document.clipboard.clipboardSelect.options[document.clipboard.clipboardSelect.selectedIndex].value\n }\n //--> </script>\n \n<div class=\"adminBar\">\n<table class=\"adminBar\" width=\"100%\" cellpadding=\"3\" cellspacing=\"0\" border=\"0\">\n <tr>\n <form name=\"content\"> <td>\n <select name=\"contentSelect\" onChange=\"goContent()\">\n <option value=\"\"><tmpl_var addcontent.label></option>\n <tmpl_loop addcontent_loop>\n <option value=\"<tmpl_var addcontent.url>\"><tmpl_var addcontent.label></option>\n </tmpl_loop>\n </select>\n </td> </form>\n <form name=\"clipboard\"> <td align=\"center\">\n <select name=\"clipboardSelect\" onChange=\"goClipboard()\">\n <option value=\"\"><tmpl_var clipboard.label></option>\n <tmpl_loop clipboard_loop>\n <option value=\"<tmpl_var clipboard.url>\"><tmpl_var clipboard.label></option>\n </tmpl_loop>\n </select>\n </td> </form>\n <form name=\"admin\"> <td align=\"center\">\n <select name=\"adminSelect\" onChange=\"goAdmin()\">\n <option value=\"\"><tmpl_var admin.label></option>\n <tmpl_loop admin_loop>\n <option value=\"<tmpl_var admin.url>\"><tmpl_var admin.label></option>\n </tmpl_loop>\n </select>\n </td> </form>\n </tr>\n</table>\n</div>\n','Macro/AdminBar');
delete from international where internationalId=34 and namespace='WebGUI';
delete from international where internationalId=19 and namespace='SQLReport';
delete from international where internationalId=21 and namespace='SQLReport';
delete from international where internationalId=5 and namespace='SQLReport';
delete from international where internationalId=6 and namespace='SQLReport';
delete from international where internationalId=7 and namespace='SQLReport';
delete from international where internationalId=9 and namespace='SQLReport';
update international set internationalId=1075, namespace='WebGUI' where internationalId=20 and namespace='SQLReport';
insert into international (internationalId,languageId,namespace,message,lastUpdated,context) values (1076,1,'WebGUI','WebGUI Database', 1070899134,'A label indicating the the user will be selecting the default WebGUI database.');
alter table SQLReport change column databaseLinkId databaseLinkId int not null default 0;
INSERT INTO template VALUES (1,'Default SQL Report','<tmpl_if displayTitle>\n <h1><tmpl_var title></h1>\n</tmpl_if>\n\n<tmpl_if description>\n <tmpl_var description><p />\n</tmpl_if>\n\n<tmpl_if debugMode>\n <ul>\n <tmpl_loop debug_loop>\n <li><tmpl_var debug.output></li>\n </tmpl_loop>\n </ul>\n</tmpl_if>\n\n<table width=\"100%\">\n<tr>\n <tmpl_loop columns_loop>\n <td class=\"tableHeader\"><tmpl_var column.name></td>\n </tmpl_loop>\n</tr>\n<tmpl_loop rows_loop>\n <tr>\n <tmpl_loop row.field_loop>\n <td class=\"tableData\"><tmpl_var field.value></td>\n </tmpl_loop>\n </tr>\n</tmpl_loop>\n</table>\n\n<tmpl_if multiplePages>\n <div class=\"pagination\">\n <tmpl_var previousPage> <tmpl_var pageList> <tmpl_var nextPage>\n </div>\n</tmpl_if>','SQLReport');

View file

@ -17,6 +17,7 @@ package WebGUI::DatabaseLink;
use strict;
use Tie::CPHash;
use WebGUI::International;
use WebGUI::Session;
use WebGUI::SQL;
@ -31,7 +32,7 @@ This package contains utility methods for WebGUI's database link system.
=head1 SYNOPSIS
use WebGUI::DatabaseLink;
%links = WebGUI::DatabaseLink::getHash();
$hashRef = WebGUI::DatabaseLink::getList();
%databaseLink = WebGUI::DatabaseLink::get($databaseLinkId);
%using = WebGUI::Databaselink::whatIsUsing($databaseLinkId);
@ -46,15 +47,17 @@ These subroutines are available from this package:
=cut
#-------------------------------------------------------------------
=head2 getHash ( )
=head2 getList ( )
Returns a hash containing all database links. The format is:
Returns a hash reference containing all database links. The format is:
databaseLinkId => title
=cut
sub getHash {
return WebGUI::SQL->buildHash("select databaseLinkId, title from databaseLink order by title");
sub getList {
my $list = WebGUI::SQL->buildHashRef("select databaseLinkId, title from databaseLink order by title");
$list->{'0'} = WebGUI::International::get(1076);
return $list;
}
#-------------------------------------------------------------------
@ -127,7 +130,7 @@ sub disconnect {
$class = shift;
$value = shift;
if (defined $class->{_dbh}) {
$class->{_dbh}->disconnect() unless ($class->{_databaseLink}{DSN} eq $session{config}{dsn});
$class->{_dbh}->disconnect() unless ($class->{_databaseLink}{databaseLinkId} == 0);
}
}
@ -151,7 +154,7 @@ sub dbh {
$dsn = $class->{_databaseLink}{DSN};
$username = $class->{_databaseLink}{username};
$identifier = $class->{_databaseLink}{identifier};
if ($dsn eq $session{config}{dsn}) {
if ($class->{databaseLinkId} == 0) {
$class->{_dbh} = $session{dbh};
return $session{dbh};
} elsif ($dsn =~ /\DBI\:\w+\:\w+/i) {
@ -191,7 +194,17 @@ sub new {
$class = shift;
$databaseLinkId = shift;
unless ($databaseLinkId eq "") {
%databaseLink = WebGUI::SQL->quickHash("select * from databaseLink where databaseLinkId='$databaseLinkId'");
if ($databaseLinkId == 0) {
%databaseLink = (
databaseLinkId=>0,
DSN=>$session{config}{dsn},
username=>$session{config}{dbuser},
identifier=>$session{config}{dpass},
title=>"WebGUI Database"
);
} else {
%databaseLink = WebGUI::SQL->quickHash("select * from databaseLink where databaseLinkId='$databaseLinkId'");
}
}
bless {_databaseLinkId => $databaseLinkId, _databaseLink => \%databaseLink }, $class;
}

View file

@ -250,7 +250,7 @@ Returns an HTML formatted message with the audit messages for display during deb
sub showAudit {
my $audit = getAudit();
$audit =~ s/\n/\<br\>/g;
$audit =~ s/\n/\<br\>\n/g;
return '<div style="background-color: #ffffdd;color: #000000;">'.$audit.'</div>';
}
@ -281,7 +281,7 @@ Returns an HTML formatted message with the security messages for display during
sub showSecurity {
my $security = getSecurity();
$security =~ s/\n/\<br\>/g;
$security =~ s/\n/\<br\>\n/g;
return '<div style="background-color: #800000;color: #ffffff;">'.$security.'</div>';
}
@ -296,7 +296,7 @@ Returns an HTML formatted list of the session variables for display during debug
sub showSessionVars {
my $data = getSessionVars();
$data =~ s/\n/\<br\>/g;
$data =~ s/\n/\<br\>\n/g;
return '<div style="background-color: #ffffff; color: #000000; font-size: 10pt; font-family: helvetica;">'.$data.'</div>';
}
@ -311,7 +311,7 @@ Returns an HTML formatted message for displaying the stack trace during debug op
sub showStackTrace {
my $st = getStackTrace();
$st =~ s/\n/\<br\>/g;
$st =~ s/\n/\<br\>\n/g;
return $st;
}
@ -326,7 +326,7 @@ Returns HTML formatted warnings for display during debug operations.
sub showWarnings {
my $warning = getWarnings();
$warning =~ s/\n/\<br\>/g;
$warning =~ s/\n/\<br\>\n/g;
return '<div style="background-color: #ffdddd;color: #000000;">'.$warning.'</div>';
}

View file

@ -39,6 +39,7 @@ Base forms package. Eliminates some of the normal code work that goes along with
$html = WebGUI::Form::checkList({name=>"dayOfWeek", options=>\%days});
$html = WebGUI::Form::combo({name=>"fruit",options=>\%fruit});
$html = WebGUI::Form::contentType({name=>"contentType");
$html = WebGUI::Form::databaseLink();
$html = WebGUI::Form::date({name=>"endDate", value=>$endDate});
$html = WebGUI::Form::dateTime({name=>"begin", value=>$begin});
$html = WebGUI::Form::email({name=>"emailAddress"});
@ -319,6 +320,43 @@ sub contentType {
extras=>$_[0]->{extras}
});
}
#-------------------------------------------------------------------
=head2 databaseLink ( hashRef )
Returns a select list of database links.
=over
=item name
The name field for this form element. Defaults to "databaseLinkId".
=item value
The unique identifier for the selected template. Defaults to "0", which is the WebGUI database.
=back
=cut
sub databaseLink {
my $value = $_[0]->{value} || 1;
my $name = $_[0]->{name} || "databaseLinkId";
return selectList({
name=>$name,
options=>WebGUI::DatabaseLink::getList(),
value=>[$value]
});
}
#-------------------------------------------------------------------
=head2 date ( hashRef )

View file

@ -487,6 +487,81 @@ sub contentType {
}
$self->{_data} .= $output;
}
#-------------------------------------------------------------------
=head2 date ( [name , value, label, afterEdit, extras, uiLevel ] )
Adds a database link select list to the form.
=over
=item name
The name of this form element.
=item value
The default value for this form element.
=item label
The left column label for this form row. Defaults to "Database Link".
=item afterEdit
A URL that will be acted upon after editing a database link. Typically there is a link next to the select list that reads "Edit this database link" and this is the URL to go to after editing is complete.
=item extras
If you want to add anything special to this form element like javascript actions, or stylesheet information, you'd add it in here as follows:
'onChange="this.form.submit()"'
=item uiLevel
The UI level for this field. See the WebGUI developer's site for details. Defaults to "5".
=back
=cut
sub databaseLink {
my ($output, $subtext);
my ($self, @p) = @_;
my ($name, $value, $label, $afterEdit, $extras, $uiLevel) =
rearrange([qw(name value label afterEdit extras uiLevel)], @p);
if (_uiLevelChecksOut($uiLevel)) {
$label = $label || WebGUI::International::get(1075);
if (WebGUI::Privilege::isInGroup(3)) {
#disabled until we can resolve the "new" wobject problem
#if ($afterEdit) {
# $subtext = '<a href="'.WebGUI::URL::page("op=editDatabaseLink&lid=".$value
# ."&afterEdit="
# .WebGUI::URL::escape($afterEdit)).'">'.WebGUI::International::get(0).'</a> / ';
#}
$subtext .= '<a href="'.WebGUI::URL::page("op=listDatabaseLinks").'">'
.WebGUI::International::get(981).'</a>';
}
$output = WebGUI::Form::databaseLink({
"name"=>$name,
"value"=>$value,
"extras"=>$extras
});
$output .= _subtext($subtext);
$output = $self->_tableFormRow($label,$output);
} else {
$output = WebGUI::Form::hidden({
"name"=>$name,
"value"=>$value
});
}
$self->{_data} .= $output;
}
#-------------------------------------------------------------------
=head2 date ( name [ label, value, extras, subtext, size, noDate, uiLevel ] )

View file

@ -126,6 +126,8 @@ sub www_listDatabaseLinks {
$output = helpIcon(68);
$output .= '<h1>'.WebGUI::International::get(996).'</h1>';
$sth = WebGUI::SQL->read("select * from databaseLink order by title");
$row[$i] = '<tr><td valign="top" class="tableData"></td><td valign="top" class="tableData">'.WebGUI::International::get(1076).'</td></tr>';
$i++;
while (%data = $sth->hash) {
$row[$i] = '<tr><td valign="top" class="tableData">'
.deleteIcon('op=deleteDatabaseLink&dlid='.$data{databaseLinkId})

View file

@ -46,6 +46,7 @@ Package that paginates rows of arbitrary data for display on the web.
$integer = $p->getPageNumber;
$html = $p->getPageLinks;
$html = $p->getPreviousPageLink;
$integer = $p->getRowCount;
=head1 METHODS
@ -419,6 +420,19 @@ sub getPreviousPageLink {
}
#-------------------------------------------------------------------
=head2 getRowCount ( )
Returns a count of the total number of rows in the paginator.
=cut
sub getRowCount {
return $_[0]->{_totalRows};
}
#-------------------------------------------------------------------
=head2 new ( currentURL, rowArrayRef [, paginateAfter, pageNumber, formVar ] )
@ -459,12 +473,13 @@ sub new {
$rowsPerPage = $_[3] || 25;
$formVar = $_[5] || "pn";
$pn = $_[4] || $session{form}{$formVar} || 1;
bless {_url => $currentURL, _rpp => $rowsPerPage, _rowRef => $rowRef, _formVar => $formVar, _pn => $pn}, $class;
my $totalRows = $#{$rowRef};
bless {_url => $currentURL, _rpp => $rowsPerPage, _totalRows=>$totalRows , _rowRef => $rowRef, _formVar => $formVar, _pn => $pn}, $class;
}
#-------------------------------------------------------------------
=head2 setDataByQuery ( query [, dbh ] )
=head2 setDataByQuery ( query [, dbh, unconditional ] )
Retrieves a data set from a database and replaces whatever data set was passed in through the constructor.
@ -480,17 +495,27 @@ An SQL query that will retrieve a data set.
A DBI-style database handler. Defaults to the WebGUI site handler.
=item unconditional
A boolean indicating that the query should be read unconditionally. Defaults to "0". If set to "1" and the unconditional read results in an error, the error will be returned by this method.
=back
=cut
sub setDataByQuery {
my ($sth, $pageCount, $rowCount, $dbh, $sql, $self, @row, $data);
($self, $sql, $dbh) = @_;
my ($sth, $rowCount, @row);
my ($self, $sql, $dbh, $unconditional) = @_;
$dbh ||= $session{dbh};
$sth = WebGUI::SQL->read($sql);
$pageCount = 1;
while ($data = $sth->hashRef) {
if ($unconditional) {
$sth = WebGUI::SQL->unconditionalRead($sql,$dbh);
return $sth->errorMessage if ($sth->errorCode > 0);
} else {
$sth = WebGUI::SQL->read($sql,$dbh);
}
$self->{_totalRows} = $sth->rows;
my $pageCount = 1;
while (my $data = $sth->hashRef) {
$rowCount++;
if ($rowCount/$self->{_rpp} > $pageCount) {
$pageCount++;
@ -503,6 +528,7 @@ sub setDataByQuery {
}
$sth->finish;
$self->{_rowRef} = \@row;
return "";
}
1;

View file

@ -46,13 +46,6 @@ sub new {
databaseLinkId=>{
defaultValue=>0
},
DSN=>{
defaultValue=>$session{config}{dsn}
},
username=>{
defaultValue=>$session{config}{dbuser}
},
identifier=>{},
convertCarriageReturns=>{
defaultValue=>0
},
@ -100,34 +93,8 @@ sub www_edit {
-label=>WebGUI::International::get(3,$_[0]->get("namespace")),
-value=>$_[0]->getValue("template")
);
my %databaseLinkOptions;
tie %databaseLinkOptions, 'Tie::IxHash',
"0"=>WebGUI::International::get(19,$_[0]->get("namespace")),
WebGUI::DatabaseLink::getHash();
$privileges->selectList(
-name=>"databaseLinkId",
-options=>\%databaseLinkOptions,
-label=>WebGUI::International::get(20,$_[0]->get("namespace")),
-value=>[$_[0]->getValue("databaseLinkId")],
-subtext=>(WebGUI::Privilege::isInGroup(3)) ? '<a href="'.WebGUI::URL::page("op=listDatabaseLinks").'">'.WebGUI::International::get(981).'</a>' : ""
);
$privileges->readOnly(
-value=>WebGUI::International::get(21,$_[0]->get("namespace")),
);
$privileges->text(
-name=>"DSN",
-label=>WebGUI::International::get(5,$_[0]->get("namespace")),
-value=>$_[0]->getValue("DSN")
);
$privileges->text(
-name=>"username",
-label=>WebGUI::International::get(6,$_[0]->get("namespace")),
-value=>$_[0]->getValue("username")
);
$privileges->password(
-name=>"identifier",
-label=>WebGUI::International::get(7,$_[0]->get("namespace")),
-value=>$_[0]->getValue("identifier")
$privileges->databaseLink(
-value=>$_[0]->getValue("databaseLinkId")
);
$layout->integer(
-name=>"paginateAfter",
@ -151,105 +118,85 @@ sub www_edit {
#-------------------------------------------------------------------
sub www_view {
my ($dsn, $username, $identifier, $dbLink, $query, @row, $i, $rownum, $p, $ouch, $output, $sth, $dbh, @result, @template, $temp, $col, $errorMessage, $url);
my ($query, %var, @debug);
if ($_[0]->get("preprocessMacros")) {
$query = WebGUI::Macro::process($_[0]->get("dbQuery"));
} else {
$query = $_[0]->get("dbQuery");
}
$dsn = $_[0]->get("DSN");
$username = $_[0]->get("username");
$identifier = $_[0]->get("identifier");
$output = $_[0]->displayTitle;
$output .= $_[0]->description;
$output .= WebGUI::International::get(17,$_[0]->get("namespace"))." ".$query."<p>" if ($_[0]->get("debugMode"));
# connect to external database if used
if ($_[0]->get("databaseLinkId")) {
$dbLink = WebGUI::DatabaseLink->new($_[0]->get("databaseLinkId"));
$dbh = $dbLink->dbh;
} else {
if ($dsn eq $session{config}{dsn}) {
$dbh = $session{dbh};
} elsif ($dsn =~ /\DBI\:\w+\:\w+/i) {
eval{$dbh = DBI->connect($dsn,$username,$identifier)};
if ($@) {
WebGUI::ErrorHandler::warn("SQL Report [".$_[0]->get("wobjectId")."] ".$@);
undef $dbh;
}
} else {
$output .= WebGUI::International::get(9,$_[0]->get("namespace")).'<p>' if ($_[0]->get("debugMode"));
WebGUI::ErrorHandler::warn("SQLReport [".$_[0]->get("wobjectId")."] The DSN specified is of an improper format.");
}
}
push(@debug,{'debug.output'=>WebGUI::International::get(17,$_[0]->get("namespace")).$query});
my $dbLink = WebGUI::DatabaseLink->new($_[0]->get("databaseLinkId"));
my $dbh = $dbLink->dbh;
if (defined $dbh) {
if ($query =~ /^select/i || $query =~ /^show/i || $query =~ /^describe/i) {
$sth = WebGUI::SQL->unconditionalRead($query,$dbh);
unless ($sth->errorCode < 1) {
$errorMessage = $sth->errorMessage;
$output .= WebGUI::International::get(11,$_[0]->get("namespace")).' : '.$errorMessage.'<p>' if ($_[0]->get("debugMode"));
WebGUI::ErrorHandler::warn("There was a problem with the query: ".$errorMessage);
my $url = WebGUI::URL::page('&wid='.$_[0]->get("wobjectId").'&func=view');
foreach (keys %{$session{form}}) {
unless ($_ eq "pn" || $_ eq "wid" || $_ eq "func") {
$url = WebGUI::URL::append($url, WebGUI::URL::escape($_)
.'='.WebGUI::URL::escape($session{form}{$_}));
}
}
my $p = WebGUI::Paginator->new($url,[],$_[0]->get("paginateAfter"));
my $error = $p->setDataByQuery($query,$dbh,1);
if ($error ne "") {
WebGUI::ErrorHandler::warn("There was a problem with the query: ".$error);
push(@debug,{'debug.output'=>WebGUI::International::get(11,$_[0]->get("namespace"))." ".$error});
} else {
if ($_[0]->get("template") ne "") {
@template = split(/\^\-\;/,$_[0]->get("template"));
} else {
$i = 0;
$template[0] = '<table width="100%"><tr>';
$template[1] = '<tr>';
foreach $col ($sth->getColumnNames) {
$template[0] .= '<td class="tableHeader">'.$col.'</td>';
$template[1] .= '<td class="tableData">^'.$i.';</td>';
$i++;
}
$template[0] .= '</tr>';
$template[1] .= '</tr>';
$template[2] = '</table>';
$i = 0;
}
$output .= $template[0];
while (@result = $sth->array) {
$temp = $template[1];
$temp =~ s/\^(\d*)\;/$result[$1]/g; # Shouldn't this be \d+ ?
$rownum = $i + 1;
$temp =~ s/\^rownum\;/$rownum/g;
if ($_[0]->get("convertCarriageReturns")) {
$temp =~ s/\n/\<br\>/g;
}
$row[$i] = $temp;
$i++;
}
if ($sth->rows < 1) {
$output .= $template[2];
$output .= WebGUI::International::get(18,$_[0]->get("namespace")).'<p>';
} else {
$url = WebGUI::URL::page('&wid='.$_[0]->get("wobjectId").'&func=view');
foreach (keys %{$session{form}}) {
unless ($_ eq "pn" || $_ eq "wid" || $_ eq "func") {
$url = WebGUI::URL::append($url, WebGUI::URL::escape($_)
.'='.WebGUI::URL::escape($session{form}{$_}));
my $first = 1;
my @columns;
my @rows;
my $rownum = 1;
my $rowdata = $p->getPageData;
foreach my $data (@$rowdata) {
my %row;
my $colnum = 1;
my @fields;
foreach my $name (keys %{$data}) {
if ($first) {
push(@columns,{
'column.number'=>$colnum,
'column.name'=>$name
});
}
push(@fields,{
'field.number'=>$colnum,
'field.name'=>$name,
'field.value'=>$data->{$name}
});
$colnum++;
$row{'row.field.'.$name.'.value'} = $data->{$name};
}
$p = WebGUI::Paginator->new($url,\@row,$_[0]->get("paginateAfter"));
$output .= $p->getPage($session{form}{pn});
$output .= $template[2];
$output .= $p->getBar($session{form}{pn});
$row{'row.number'} = $rownum;
$row{'row.field_loop'} = \@fields;
push(@rows,\%row);
$first = 0;
$rownum++;
}
$sth->finish;
$var{columns_loop} = \@columns;
$var{rows_loop} = \@rows;
$var{'rows.count'} = $p->getRowCount;
$var{'rows.count.isZero'} = ($p->getRowCount < 1);
$var{'rows.count.isZero.label'} = WebGUI::International::get(18,$_[0]->get("namespace"));
$var{firstPage} = $p->getFirstPageLink;
$var{lastPage} = $p->getLastPageLink;
$var{nextPage} = $p->getNextPageLink;
$var{pageList} = $p->getPageLinks;
$var{previousPage} = $p->getPreviousPageLink;
$var{multiplePages} = ($p->getNumberOfPages > 1);
$var{numberOfPages} = $p->getNumberOfPages;
$var{pageNumber} = $p->getPageNumber;
}
} else {
$output .= WebGUI::International::get(10,$_[0]->get("namespace")).'<p>' if ($_[0]->get("debugMode"));
push(@debug,{'debug.output'=>WebGUI::International::get(10,$_[0]->get("namespace"))});
WebGUI::ErrorHandler::warn("SQLReport [".$_[0]->get("wobjectId")."] The SQL query is improperly formatted.");
}
if ($dbLink) {
$dbLink->disconnect;
} else {
$dbh->disconnect() unless ($dsn eq $session{config}{dsn});
}
$dbLink->disconnect;
} else {
$output .= WebGUI::International::get(12,$_[0]->get("namespace")).'<p>' if ($_[0]->get("debugMode"));
push(@debug,{'debug.output'=>WebGUI::International::get(12,$_[0]->get("namespace"))});
WebGUI::ErrorHandler::warn("SQLReport [".$_[0]->get("wobjectId")."] Could not connect to database.");
}
return $output;
$var{'debug_loop'} = \@debug;
return $_[0]->processTemplate($_[0]->get("templateId"),\%var);
}