package WebGUI;
our $VERSION = "4.6.0";
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2002 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 strict qw(vars subs);
use Tie::CPHash;
use WebGUI::ErrorHandler;
use WebGUI::Icon;
use WebGUI::International;
use WebGUI::Operation;
use WebGUI::Privilege;
use WebGUI::Session;
use WebGUI::SQL;
use WebGUI::Style;
use WebGUI::Template;
use WebGUI::Utility;
#-------------------------------------------------------------------
sub page {
my ($debug, %contentHash, $w, $cmd, $pageEdit, $wobject, $wobjectOutput, $extra, $originalWobject, $proxyWobjectId,
$sth, $httpHeader, $header, $footer, $content, $operationOutput, $adminBar, %hash, $canEdit);
WebGUI::Session::open($_[0],$_[1]);
if (exists $session{form}{op}) {
$cmd = "WebGUI::Operation::www_".$session{form}{op};
$operationOutput = eval($cmd);
WebGUI::ErrorHandler::warn("Non-existent operation called: $session{form}{op}.") if($@);
}
if (exists $session{form}{func} && exists $session{form}{wid}) {
if ($session{form}{wid} eq "new") {
$wobject = {wobjectId=>"new",namespace=>$session{form}{namespace},pageId=>$session{page}{pageId}};
} else {
$wobject = WebGUI::SQL->quickHashRef("select * from wobject where wobjectId=".$session{form}{wid});
if (${$wobject}{namespace} eq "") {
WebGUI::ErrorHandler::warn("Wobject [$session{form}{wid}] appears to be missing or "
."corrupt, but was requested "
."by $session{user}{username} [$session{user}{userId}].");
$wobject = ();
} else {
$extra = WebGUI::SQL->quickHashRef("select * from ${$wobject}{namespace}
where wobjectId=${$wobject}{wobjectId}");
tie %hash, 'Tie::CPHash';
%hash = (%{$wobject},%{$extra});
$wobject = \%hash;
}
}
if ($wobject) {
if (${$wobject}{pageId} != $session{page}{pageId}) {
($proxyWobjectId) = WebGUI::SQL->quickArray("select wobject.wobjectId from wobject,WobjectProxy
where wobject.wobjectId=WobjectProxy.wobjectId
and wobject.pageId=".$session{page}{pageId}."
and WobjectProxy.proxiedWobjectId=".${$wobject}{wobjectId});
${$wobject}{_WobjectProxy} = $proxyWobjectId;
}
unless (${$wobject}{pageId} == $session{page}{pageId} || ${$wobject}{pageId} == 2 || ${$wobject}{_WobjectProxy} ne "") {
$wobjectOutput .= WebGUI::International::get(417);
WebGUI::ErrorHandler::warn($session{user}{username}." [".$session{user}{userId}
."] attempted to access wobject ["
.$session{form}{wid}."] on page '".$session{page}{title}."' ["
.$session{page}{pageId}."].");
} else {
if (WebGUI::Privilege::canViewPage()) {
$cmd = "WebGUI::Wobject::".${$wobject}{namespace};
$w = eval{$cmd->new($wobject)};
WebGUI::ErrorHandler::fatalError("Couldn't instanciate wojbect: ${$wobject}{namespace}. Root Cause: ".$@) if($@);
$cmd = "www_".$session{form}{func};
$wobjectOutput = eval{$w->$cmd};
WebGUI::ErrorHandler::fatalError("Web method doesn't exist in wojbect: ${$wobject}{namespace} / $session{form}{func}. Root Cause: ".$@) if($@);
} else {
$wobjectOutput = WebGUI::Privilege::noAccess();
}
}
}
}
if ($operationOutput ne "") {
$contentHash{0} = $operationOutput;
$content = WebGUI::Template::generate(\%contentHash,1);
} elsif ($wobjectOutput ne "") {
$contentHash{0} = $wobjectOutput;
$content = WebGUI::Template::generate(\%contentHash,1);
} elsif ($session{page}{redirectURL}) {
$session{header}{redirect} = WebGUI::Session::httpRedirect($session{page}{redirectURL})
} else {
if (WebGUI::Privilege::canViewPage()) {
if ($session{var}{adminOn}) {
$canEdit = WebGUI::Privilege::canEditPage();
if ($canEdit) {
$pageEdit = "\n
"
.pageIcon()
.deleteIcon('op=deletePage')
.editIcon('op=editPage')
.moveUpIcon('op=movePageUp')
.moveDownIcon('op=movePageDown')
.cutIcon('op=cutPage')
."\n";
}
}
$sth = WebGUI::SQL->read("select * from wobject where pageId=$session{page}{pageId} order by sequenceNumber, wobjectId");
while ($wobject = $sth->hashRef) {
if ($session{var}{adminOn} && $canEdit) {
$contentHash{${$wobject}{templatePosition}} .= "\n
| '.$section.'.'.$key.': | '.$value.' | '; } $debug .= '
|   |