Added new Database Link tool, updated SQL Report to use database links
This commit is contained in:
parent
e814dd106c
commit
2fda426415
7 changed files with 331 additions and 5 deletions
104
lib/WebGUI/DatabaseLink.pm
Normal file
104
lib/WebGUI/DatabaseLink.pm
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
package WebGUI::DatabaseLink;
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2003 Plain Black LLC.
|
||||
-------------------------------------------------------------------
|
||||
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
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
use strict;
|
||||
use Tie::CPHash;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::SQL;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::DatabaseLink
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This package contains utility methods for WebGUI's database link system.
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
use WebGUI::DatabaseLink;
|
||||
%links = WebGUI::DatabaseLink::getHash();
|
||||
%databaseLink = WebGUI::DatabaseLink::get($databaseLinkId);
|
||||
%using = WebGUI::Databaselink::whatIsUsing($databaseLinkId);
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
These subroutines are available from this package:
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
=head2 getHash ( )
|
||||
|
||||
Returns a hash containing all database links. The format is:
|
||||
databaseLinkId => title
|
||||
|
||||
=cut
|
||||
|
||||
sub getHash {
|
||||
return WebGUI::SQL->buildHash("select databaseLinkId, title from databaseLink order by title");
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
=head2 get ( databaseLinkId )
|
||||
|
||||
Returns a hash containing a single database link.
|
||||
|
||||
=over
|
||||
|
||||
=item databaseLinkId
|
||||
|
||||
A valid databaseLinkId
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub get {
|
||||
return WebGUI::SQL->quickHash("select * from databaseLink where databaseLinkId=".$_[0]);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
=head2 whatIsUsing ( databaseLinkId )
|
||||
|
||||
Returns an array of hashrefs containing wobjects which use a database link.
|
||||
|
||||
=over
|
||||
|
||||
=item databaseLinkId
|
||||
|
||||
A valid databaseLinkId
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub whatIsUsing {
|
||||
my $sql = 'select wobject.wobjectId, wobject.title, page.menuTitle, page.urlizedTitle from wobject, SQLReport, page '.
|
||||
'where SQLReport.databaseLinkId = '.$_[0].' and SQLReport.wobjectId = wobject.wobjectId '.
|
||||
'and wobject.pageId = page.pageId';
|
||||
my $sth = WebGUI::SQL->read($sql);
|
||||
my @using;
|
||||
while (my $data = $sth->hashRef()) {
|
||||
push @using, $data;
|
||||
}
|
||||
$sth->finish;
|
||||
return @using;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
|
@ -105,7 +105,8 @@ sub process {
|
|||
WebGUI::URL::page('op=listGroups')=>WebGUI::International::get(5),
|
||||
WebGUI::URL::page('op=manageSettings')=>WebGUI::International::get(4),
|
||||
WebGUI::URL::page('op=listUsers')=>WebGUI::International::get(7),
|
||||
WebGUI::URL::page('op=viewStatistics')=>WebGUI::International::get(144)
|
||||
WebGUI::URL::page('op=viewStatistics')=>WebGUI::International::get(144),
|
||||
WebGUI::URL::page('op=listDatabaseLinks')=>WebGUI::International::get(981),
|
||||
);
|
||||
} elsif (WebGUI::Privilege::isInGroup(11)) {
|
||||
%hash = (
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ use WebGUI::Operation::Account;
|
|||
use WebGUI::Operation::Admin;
|
||||
use WebGUI::Operation::Clipboard;
|
||||
use WebGUI::Operation::Collateral;
|
||||
use WebGUI::Operation::DatabaseLink;
|
||||
use WebGUI::Operation::Group;
|
||||
use WebGUI::Operation::Help;
|
||||
use WebGUI::Operation::International;
|
||||
|
|
|
|||
144
lib/WebGUI/Operation/DatabaseLink.pm
Normal file
144
lib/WebGUI/Operation/DatabaseLink.pm
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
package WebGUI::Operation::DatabaseLink;
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# WebGUI is Copyright 2001-2003 Plain Black LLC.
|
||||
#-------------------------------------------------------------------
|
||||
# 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 Exporter;
|
||||
use strict;
|
||||
use Tie::CPHash;
|
||||
use WebGUI::DatabaseLink;
|
||||
use WebGUI::Icon;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Operation::Shared;
|
||||
use WebGUI::Paginator;
|
||||
use WebGUI::Privilege;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::SQL;
|
||||
use WebGUI::URL;
|
||||
|
||||
our @ISA = qw(Exporter);
|
||||
our @EXPORT = qw(&www_copyDatabaseLink &www_deleteDatabaseLink &www_deleteDatabaseLinkConfirm
|
||||
&www_editDatabaseLink &www_editDatabaseLinkSave &www_listDatabaseLinks);
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub _submenu {
|
||||
my (%menu);
|
||||
tie %menu, 'Tie::IxHash';
|
||||
$menu{WebGUI::URL::page('op=editDatabaseLink&dlid=new')} = WebGUI::International::get(982);
|
||||
if (($session{form}{op} eq "editDatabaseLink" && $session{form}{dlid} ne "new") || $session{form}{op} eq "deleteDatabaseLink") {
|
||||
$menu{WebGUI::URL::page('op=editDatabaseLink&dlid='.$session{form}{dlid})} = WebGUI::International::get(983);
|
||||
$menu{WebGUI::URL::page('op=copyDatabaseLink&dlid='.$session{form}{dlid})} = WebGUI::International::get(984);
|
||||
$menu{WebGUI::URL::page('op=deleteDatabaseLink&dlid='.$session{form}{dlid})} = WebGUI::International::get(985);
|
||||
$menu{WebGUI::URL::page('op=listDatabaseLinks')} = WebGUI::International::get(986);
|
||||
}
|
||||
return menuWrapper($_[0],\%menu);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_copyDatabaseLink {
|
||||
return WebGUI::Privilege::insufficient unless (WebGUI::Privilege::isInGroup(3));
|
||||
my (%db);
|
||||
tie %db, 'Tie::CPHash';
|
||||
%db = WebGUI::SQL->quickHash("select * from databaseLink where databaseLinkId=$session{form}{dlid}");
|
||||
WebGUI::SQL->write("insert into databaseLink (databaseLinkId,title,DSN,username,identifier) values (".getNextId("databaseLinkId").",
|
||||
".quote('Copy of '.$db{title}).", ".quote($db{DSN}).", ".quote($db{username}).", ".quote($db{identifier}).")");
|
||||
return www_listDatabaseLinks();
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_deleteDatabaseLink {
|
||||
return WebGUI::Privilege::insufficient unless (WebGUI::Privilege::isInGroup(3));
|
||||
my ($output);
|
||||
$output .= helpIcon(70);
|
||||
$output .= '<h1>'.WebGUI::International::get(987).'</h1>';
|
||||
$output .= WebGUI::International::get(988).'<p>';
|
||||
foreach my $using (WebGUI::DatabaseLink::whatIsUsing($session{form}{dlid})) {
|
||||
$output .= '<li>'.WebGUI::International::get(1,'SQL Report').' <a href="'.WebGUI::URL::page('func=edit&wid='.$using->{wobjectId},$using->{urlizedTitle}).'">'
|
||||
.$using->{title}.'</a> '.WebGUI::International::get(989).' <a href="'.WebGUI::URL::gateway($using->{urlizedTitle}).'">'.$using->{menuTitle}.'</a>.</li>';
|
||||
}
|
||||
$output .= '<p><div align="center"><a href="'.
|
||||
WebGUI::URL::page('op=deleteDatabaseLinkConfirm&dlid='.$session{form}{dlid})
|
||||
.'">'.WebGUI::International::get(44).'</a>';
|
||||
$output .= ' <a href="'.WebGUI::URL::page('op=listDatabaseLinks').
|
||||
'">'.WebGUI::International::get(45).'</a></div>';
|
||||
return _submenu($output);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_deleteDatabaseLinkConfirm {
|
||||
return WebGUI::Privilege::insufficient unless (WebGUI::Privilege::isInGroup(3));
|
||||
WebGUI::SQL->write("delete from databaseLink where databaseLinkId=".$session{form}{dlid});
|
||||
return www_listDatabaseLinks();
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_editDatabaseLink {
|
||||
return WebGUI::Privilege::insufficient unless (WebGUI::Privilege::isInGroup(3));
|
||||
my ($output, %db, $f);
|
||||
tie %db, 'Tie::CPHash';
|
||||
if ($session{form}{dlid} eq "new") {
|
||||
|
||||
} else {
|
||||
%db = WebGUI::SQL->quickHash("select * from databaseLink where databaseLinkId=$session{form}{dlid}");
|
||||
}
|
||||
$output .= helpIcon(69);
|
||||
$output .= '<h1>'.WebGUI::International::get(990).'</h1>';
|
||||
$f = WebGUI::HTMLForm->new;
|
||||
$f->hidden("op","editDatabaseLinkSave");
|
||||
$f->hidden("dlid",$session{form}{dlid});
|
||||
$f->readOnly($session{form}{dlid},WebGUI::International::get(991));
|
||||
$f->text("title",WebGUI::International::get(992),$db{title});
|
||||
$f->text("DSN",WebGUI::International::get(993),$db{DSN});
|
||||
$f->text("username",WebGUI::International::get(994),$db{username});
|
||||
$f->text("identifier",WebGUI::International::get(995),$db{identifier});
|
||||
$f->submit;
|
||||
$output .= $f->print;
|
||||
return _submenu($output);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_editDatabaseLinkSave {
|
||||
return WebGUI::Privilege::insufficient unless (WebGUI::Privilege::isInGroup(3));
|
||||
if ($session{form}{dlid} eq "new") {
|
||||
$session{form}{dlid} = getNextId("databaseLinkId");
|
||||
WebGUI::SQL->write("insert into databaseLink (databaseLinkId) values ($session{form}{dlid})");
|
||||
}
|
||||
WebGUI::SQL->write("update databaseLink set title=".quote($session{form}{title}).", DSN=".quote($session{form}{DSN}).",
|
||||
username=".quote($session{form}{username}).", identifier=".quote($session{form}{identifier})." where databaseLinkId=".$session{form}{dlid});
|
||||
return www_listDatabaseLinks();
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_listDatabaseLinks {
|
||||
return WebGUI::Privilege::adminOnly() unless(WebGUI::Privilege::isInGroup(3));
|
||||
my ($output, $p, $sth, %data, @row, $i);
|
||||
$output = helpIcon(68);
|
||||
$output .= '<h1>'.WebGUI::International::get(996).'</h1>';
|
||||
$sth = WebGUI::SQL->read("select * from databaseLink order by title");
|
||||
while (%data = $sth->hash) {
|
||||
$row[$i] = '<tr><td valign="top" class="tableData">'
|
||||
.deleteIcon('op=deleteDatabaseLink&dlid='.$data{databaseLinkId})
|
||||
.editIcon('op=editDatabaseLink&dlid='.$data{databaseLinkId})
|
||||
.copyIcon('op=copyDatabaseLink&dlid='.$data{databaseLinkId})
|
||||
.'</td>';
|
||||
$row[$i] .= '<td valign="top" class="tableData">'.$data{title}.'</td></tr>';
|
||||
$i++;
|
||||
}
|
||||
$sth->finish;
|
||||
$p = WebGUI::Paginator->new(WebGUI::URL::page('op=listDatabaseLinks'),\@row);
|
||||
$output .= '<table border=1 cellpadding=3 cellspacing=0 align="center">';
|
||||
$output .= $p->getPage;
|
||||
$output .= '</table>';
|
||||
$output .= $p->getBarTraditional;
|
||||
return _submenu($output);
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
|
@ -11,6 +11,7 @@ package WebGUI::Wobject::SQLReport;
|
|||
#-------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
use WebGUI::DatabaseLink;
|
||||
use WebGUI::ErrorHandler;
|
||||
use WebGUI::HTMLForm;
|
||||
use WebGUI::Icon;
|
||||
|
|
@ -42,6 +43,7 @@ sub new {
|
|||
-extendedProperties=>{
|
||||
template=>{},
|
||||
dbQuery=>{},
|
||||
databaseLinkId=>{},
|
||||
DSN=>{
|
||||
defaultValue=>$session{config}{dsn}
|
||||
},
|
||||
|
|
@ -95,8 +97,21 @@ sub www_edit {
|
|||
-name=>"template",
|
||||
-label=>WebGUI::International::get(3,$_[0]->get("namespace")),
|
||||
-value=>$_[0]->getValue("template")
|
||||
);
|
||||
$privileges->text(
|
||||
);
|
||||
$privileges->selectList(
|
||||
-name=>"databaseLinkId",
|
||||
-options=>{
|
||||
""=>WebGUI::International::get(19,$_[0]->get("namespace")),
|
||||
WebGUI::DatabaseLink::getHash(),
|
||||
},
|
||||
-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")
|
||||
|
|
@ -133,20 +148,34 @@ sub www_edit {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_view {
|
||||
my ($dsn, $query, @row, $i, $rownum, $p, $ouch, $output, $sth, $dbh, @result, @template, $temp, $col, $errorMessage, $url);
|
||||
my ($dsn, $username, $identifier, $query, @row, $i, $rownum, $p, $ouch, $output, $sth, $dbh, @result, @template, $temp, $col, $errorMessage, $url);
|
||||
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"));
|
||||
|
||||
# pull database link info if selected
|
||||
if ($_[0]->get("databaseLinkId")) {
|
||||
my %databaseLink = WebGUI::DatabaseLink::get($_[0]->get("databaseLinkId"));
|
||||
# failsafe check in case the link gets deleted
|
||||
if ($databaseLink{DSN}) {
|
||||
$dsn = $databaseLink{DSN};
|
||||
$username = $databaseLink{username};
|
||||
$identifier = $databaseLink{identifier};
|
||||
}
|
||||
}
|
||||
|
||||
if ($dsn eq $session{config}{dsn}) {
|
||||
$dbh = $session{dbh};
|
||||
} elsif ($dsn =~ /\DBI\:\w+\:\w+/) {
|
||||
eval{$dbh = DBI->connect($dsn,$_[0]->get("username"),$_[0]->get("identifier"))};
|
||||
eval{$dbh = DBI->connect($dsn,$username,$identifier)};
|
||||
if ($@) {
|
||||
WebGUI::ErrorHandler::warn("SQL Report [".$_[0]->get("wobjectId")."] ".$@);
|
||||
undef $dbh;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue