From 92e315d6936778e1da75ace5738ccea0b5bf5cf2 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Mon, 13 May 2002 23:21:04 +0000 Subject: [PATCH] Added the wobject superclass. --- lib/WebGUI.pm | 113 +++++++++++++++++++++++++------------------------- 1 file changed, 56 insertions(+), 57 deletions(-) diff --git a/lib/WebGUI.pm b/lib/WebGUI.pm index f72c8d886..16121ba9d 100644 --- a/lib/WebGUI.pm +++ b/lib/WebGUI.pm @@ -15,6 +15,7 @@ use strict qw(vars subs); use Tie::CPHash; use Tie::IxHash; use WebGUI::ErrorHandler; +use WebGUI::Icon; use WebGUI::International; use WebGUI::Operation; use WebGUI::Privilege; @@ -28,18 +29,16 @@ use WebGUI::Utility; #------------------------------------------------------------------- sub _displayAdminBar { - my ($widgetName, $key, %hash2, $miscSelect, $adminSelect, $clipboardSelect, - $widget, @widgetArray, %hash, $output, $contentSelect); + my (%hash2, $miscSelect, $adminSelect, $clipboardSelect, + %hash, $output, $contentSelect, $key); tie %hash, "Tie::IxHash"; tie %hash2, "Tie::IxHash"; #--content adder - @widgetArray = @_; $hash{WebGUI::URL::page()} = WebGUI::International::get(1); $hash{WebGUI::URL::page('op=addPage')} = WebGUI::International::get(2); $hash{WebGUI::URL::page('op=selectPackageToDeploy')} = WebGUI::International::get(376); - foreach $widget (@widgetArray) { - $widgetName = "WebGUI::Widget::".$widget."::widgetName"; - $hash2{WebGUI::URL::page('func=add&widget='.$widget)} = &$widgetName; + foreach $key (keys %{$session{wobject}}) { + $hash2{WebGUI::URL::page('func=edit&wid=new&namespace='.$key)} = $session{wobject}{$key}; } %hash2 = sortHash(%hash2); %hash = (%hash, %hash2); @@ -51,7 +50,7 @@ sub _displayAdminBar { foreach $key (keys %hash) { $hash2{WebGUI::URL::page('op=pastePage&pageId='.$key)} = $hash{$key}; } - %hash = WebGUI::SQL->buildHash("select widgetId,title from widget where pageId=2 order by title"); + %hash = WebGUI::SQL->buildHash("select wobjectId,title from wobject where pageId=2 order by title"); foreach $key (keys %hash) { $hash2{WebGUI::URL::page('func=paste&wid='.$key)} = $hash{$key}; } @@ -122,36 +121,14 @@ sub _displayAdminBar { return $output; } -#------------------------------------------------------------------- -sub _loadWidgets { - my ($widgetDir, @files, $file, $use, @widget, $i); - if ($^O =~ /Win/i) { - $widgetDir = "\\lib\\WebGUI\\Widget"; - } else { - $widgetDir = "/lib/WebGUI/Widget"; - } - opendir (DIR,$session{config}{webguiRoot}.$widgetDir) or WebGUI::ErrorHandler::fatalError("Can't open widget directory!"); - @files = readdir(DIR); - foreach $file (@files) { - if ($file =~ /(.*?)\.pm$/) { - $widget[$i] = $1; - $use = "use WebGUI::Widget::".$widget[$i]; - eval($use); - $i++; - } - } - closedir(DIR); - return @widget; -} - #------------------------------------------------------------------- sub page { - my ($debug, %contentHash, $cmd, $pageEdit, $widgetPage, $widgetType, $functionOutput, @availableWidgets, @widgetList, $sth, $httpHeader, $header, $footer, $content, $operationOutput, $adminBar); + my ($debug, %contentHash, $w, $cmd, $pageEdit, $wobject, $wobjectOutput, $extra, + $sth, $httpHeader, $header, $footer, $content, $operationOutput, $adminBar, %hash); WebGUI::Session::open($_[0],$_[1]); # For some reason we have to pre-cache the templates when running under mod_perl # so that's what we're doing with this next command. WebGUI::Template::loadTemplates(); - @availableWidgets = _loadWidgets(); if ($session{form}{debug}==1 && WebGUI::Privilege::isInGroup(3)) { $debug = ''; while (my ($section, $hash) = each %session) { @@ -171,44 +148,66 @@ sub page { $cmd = "WebGUI::Operation::www_".$session{form}{op}; $operationOutput = &$cmd(); } - if (exists $session{form}{func}) { - if (exists $session{form}{widget}) { - $widgetType = $session{form}{widget}; - $widgetPage = $session{page}{pageId}; + if (exists $session{form}{func} && exists $session{form}{wid}) { + if ($session{form}{wid} eq "new") { + $wobject = {wobjectId=>$session{form}{wid},namespace=>$session{form}{namespace},pageId=>$session{page}{pageId}}; } else { - ($widgetType,$widgetPage) = WebGUI::SQL->quickArray("select namespace,pageId from widget where widgetId='$session{form}{wid}'"); + $wobject = WebGUI::SQL->quickHashRef("select * from wobject where wobject.wobjectId=".$session{form}{wid}); + $extra = WebGUI::SQL->quickHashRef("select * from ${$wobject}{namespace} where wobjectId=${$wobject}{wobjectId}"); + tie %hash, 'Tie::CPHash'; + %hash = (%{$wobject},%{$extra}); + $wobject = \%hash; } - if ($widgetType ne "") { - if ($widgetPage != $session{page}{pageId} && $widgetPage != 2) { - $functionOutput = WebGUI::International::get(417); - WebGUI::ErrorHandler::warn($session{user}{username}." [".$session{user}{userId}."] attempted to access widget [".$session{form}{wid}."] on page '".$session{page}{title}."' [".$session{page}{pageId}."]."); - } else { - $cmd = "WebGUI::Widget::".$widgetType."::www_".$session{form}{func}; - $functionOutput = &$cmd(); - } - } else { - $functionOutput = WebGUI::International::get(381); - } + if (${$wobject}{pageId} != $session{page}{pageId} && ${$wobject}{pageId} != 2) { + $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 { + $cmd = "WebGUI::Wobject::".${$wobject}{namespace}; + $w = $cmd->new($wobject); + $cmd = "www_".$session{form}{func}; + $wobjectOutput = $w->$cmd; + } + # $wobjectOutput = WebGUI::International::get(381); # bad error } if ($operationOutput ne "") { $contentHash{A} = $operationOutput; $content = WebGUI::Template::Default::generate(\%contentHash); - } elsif ($functionOutput ne "") { - $contentHash{A} = $functionOutput; + } elsif ($wobjectOutput ne "") { + $contentHash{A} = $wobjectOutput; $content = WebGUI::Template::Default::generate(\%contentHash); } else { if (WebGUI::Privilege::canViewPage()) { if ($session{var}{adminOn}) { - $pageEdit = '
Page Settings:Edit PageCut PageDelete PageMove Page UpMove Page Down'."\n\n"; + $pageEdit = "\n
" + .pageIcon() + .editIcon('op=editPage') + .moveUpIcon('op=movePageUp') + .moveDownIcon('op=movePageDown') + .cutIcon('op=cutPage') + .deleteIcon('op=deletePage') + ."\n"; } - $sth = WebGUI::SQL->read("select widgetId, namespace, templatePosition from widget where pageId=".$session{page}{pageId}." order by sequenceNumber, widgetId"); - while (@widgetList = $sth->array) { + $sth = WebGUI::SQL->read("select * from wobject where pageId=$session{page}{pageId} order by sequenceNumber, wobjectId"); + while ($wobject = $sth->hashRef) { if ($session{var}{adminOn}) { - $contentHash{$widgetList[2]} .= '
EditCutCopyDeleteMove UpMove DownMove to TopMove to Bottom
'; + $contentHash{${$wobject}{templatePosition}} .= "\n
" + .editIcon('func=edit&wid='.${$wobject}{wobjectId}) + .moveUpIcon('func=moveUp&wid='.${$wobject}{wobjectId}) + .moveDownIcon('func=moveDown&wid='.${$wobject}{wobjectId}) + .moveTopIcon('func=moveTop&wid='.${$wobject}{wobjectId}) + .moveBottomIcon('func=moveBottom&wid='.${$wobject}{wobjectId}) + .copyIcon('func=copy&wid='.${$wobject}{wobjectId}) + .cutIcon('func=cut&wid='.${$wobject}{wobjectId}) + .deleteIcon('func=delete&wid='.${$wobject}{wobjectId}) + .'
'; } - $cmd = "WebGUI::Widget::".$widgetList[1]."::www_view"; - $contentHash{$widgetList[2]} .= ''. - &$cmd($widgetList[0])."

\n\n"; + $extra = WebGUI::SQL->quickHashRef("select * from ${$wobject}{namespace} where wobjectId=${$wobject}{wobjectId}"); + tie %hash, 'Tie::CPHash'; + %hash = (%{$wobject},%{$extra}); + $wobject = \%hash; + $cmd = "WebGUI::Wobject::".${$wobject}{namespace}; + $w = $cmd->new($wobject); + $contentHash{${$wobject}{templatePosition}} .= ''.$w->www_view."

\n\n"; } $sth->finish; $cmd = "use WebGUI::Template::".$session{page}{template}; @@ -221,7 +220,7 @@ sub page { } } if ($session{var}{adminOn}) { - $adminBar = _displayAdminBar(@availableWidgets); + $adminBar = _displayAdminBar(); } if ($session{header}{redirect} ne "") { return $session{header}{redirect};