package WebGUI; #------------------------------------------------------------------- # 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 qw(vars subs); use Tie::IxHash; use WebGUI::Operation; use WebGUI::Privilege; use WebGUI::Session; use WebGUI::SQL; use WebGUI::Style; #------------------------------------------------------------------- sub _displayAdminBar { my ($widgetName, $key, %hash2, $miscSelect, $adminSelect, $clipboardSelect, $widget, @widgetArray, %hash, $output, $contentSelect); tie %hash, "Tie::IxHash"; tie %hash2, "Tie::IxHash"; #--content adder @widgetArray = @_; $hash2{$session{page}{url}} = "Add content..."; $hash2{$session{page}{url}.'?op=addPage'} = 'Page'; foreach $widget (@widgetArray) { $widgetName = "WebGUI::Widget::".$widget."::widgetName"; $hash2{$session{page}{url}.'?func=add&widget='.$widget} = &$widgetName; } $contentSelect = WebGUI::Form::selectList("contentSelect",\%hash2,"","","","goContent()"); #--clipboard paster %hash2 = ( $session{page}{url}=> "Paste from clipboard..." ); %hash = WebGUI::SQL->buildHash("select pageId,title from page where parentId=2 order by title",$session{dbh}); foreach $key (keys %hash) { $hash2{$session{page}{url}.'?op=pastePage&pageId='.$key} = $hash{$key}; } %hash = WebGUI::SQL->buildHash("select widgetId,title from widget where pageId=2 order by title",$session{dbh}); foreach $key (keys %hash) { $hash2{$session{page}{url}.'?func=paste&wid='.$key} = $hash{$key}; } $clipboardSelect = WebGUI::Form::selectList("clipboardSelect",\%hash2,"","","","goClipboard()"); #--admin functions %hash = (); if (WebGUI::Privilege::isInGroup(3,$session{user}{userId})) { %hash = ( $session{page}{url}.'?op=editSettings'=>'Edit Settings', $session{page}{url}.'?op=listGroups'=>'Manage Groups', $session{page}{url}.'?op=listStyles'=>'Manage Styles', $session{page}{url}.'?op=listUsers'=>'Manage Users', $session{env}{SCRIPT_NAME}.'/clipboard'=>'View Clipboard', $session{env}{SCRIPT_NAME}.'/trash'=>'View Trash' ); } %hash = ( $session{page}{url}=>'Admin...', $session{page}{url}.'?op=switchOffAdmin'=>'Turn Admin Off', $session{page}{url}.'?op=viewHelpIndex'=>'View Help Index', $session{page}{url}.'?op=viewPendingSubmissions'=>'View Pending Submissions', %hash ); $adminSelect = WebGUI::Form::selectList("adminSelect",\%hash,"","","","goAdmin()"); #--output admin bar $output = '
'.$contentSelect.'
'.$clipboardSelect.'
'.$adminSelect.'
'; return $output; } #------------------------------------------------------------------- sub _loadWidgets { my (@files, $file, $use, @widget, $i); opendir (DIR,"../lib/WebGUI/Widget") or die "Can't get widget directory!\n"; @files = readdir(DIR); foreach $file (@files) { unless ($file eq "." || $file eq "..") { $file =~ s/\.pm//; $widget[$i] = $file; $use = "use WebGUI::Widget::".$widget[$i]; eval($use); $i++; } } closedir(DIR); return @widget; } #------------------------------------------------------------------- sub page { my ($preContent, $postContent, $widgetType, $function, $functionOutput, $widget, @availableWidgets, @widgetList, $sth, $httpHeader, $header, $footer, $content, $operationOutput, $operation, $adminBar); WebGUI::Session::open(); $preContent = '
'; $postContent = '
'; @availableWidgets = _loadWidgets(); if (exists $session{form}{op}) { $operation = "WebGUI::Operation::www_".$session{form}{op}; $operationOutput = &$operation(); } if (exists $session{form}{func}) { if (exists $session{form}{widget}) { $widgetType = $session{form}{widget}; } else { ($widgetType) = WebGUI::SQL->quickArray("select widgetType from widget where widgetId='$session{form}{wid}'",$session{dbh}); } $function = "WebGUI::Widget::".$widgetType."::www_".$session{form}{func}; $functionOutput = &$function(); } if ($operationOutput ne "") { $content = $operationOutput; } elsif ($functionOutput ne "") { $content = $functionOutput; } else { #if (WebGUI::Privilege::canViewPage($session{page}{pageId})) { if (WebGUI::Privilege::canViewPage()) { if ($session{var}{adminOn}) { $content .= ''; } $sth = WebGUI::SQL->read("select widgetId, widgetType from widget where pageId=".$session{page}{pageId}." order by sequenceNumber, widgetId",$session{dbh}); while (@widgetList = $sth->array) { if ($session{var}{adminOn}) { $content .= '

'; } $widget = "WebGUI::Widget::".$widgetList[1]."::www_view"; $content .= &$widget($widgetList[0])."

"; } $sth->finish; } else { $content = '

Permission Denied!

You do not have sufficient privileges to access this page. '; } } if ($session{var}{adminOn}) { $adminBar = _displayAdminBar(@availableWidgets); } $httpHeader = WebGUI::Session::httpHeader(); ($header, $footer) = WebGUI::Style::getStyle(); WebGUI::Session::close(); return $httpHeader.$adminBar.$header.$preContent.$content.$postContent.$footer; } 1;