package WebGUI::Widget::SiteMap; #------------------------------------------------------------------- # 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; use WebGUI::Privilege; use WebGUI::Session; use WebGUI::SQL; use WebGUI::Utility; use WebGUI::Widget; #------------------------------------------------------------------- sub _traversePageTree { my ($sth, @data, $output, $depth, $i); for ($i=0;$i<=$_[1];$i++) { $depth .= "  "; } $sth = WebGUI::SQL->read("select urlizedTitle, title, pageId from page where parentId='$_[0]' order by sequenceNumber",$session{dbh}); while (@data = $sth->array) { if (WebGUI::Privilege::canViewPage($data[2])) { $output .= $depth.'· '.$data[1].'
'; $output .= _traversePageTree($data[2],$_[1]+1); } } $sth->finish; return $output; } #------------------------------------------------------------------- sub purge { WebGUI::SQL->write("delete from SiteMap where widgetId=$_[0]",$_[1]); purgeWidget($_[0],$_[1]); } #------------------------------------------------------------------- sub widgetName { return "Site Map"; } #------------------------------------------------------------------- sub www_add { my ($output); if (WebGUI::Privilege::canEditPage()) { $output = '

Add Site Map

'; $output .= WebGUI::Form::hidden("widget","SiteMap"); $output .= WebGUI::Form::hidden("func","addSave"); $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= '
Title'.WebGUI::Form::text("title",20,30,'Site Map').'
Display title?'.WebGUI::Form::checkbox("displayTitle",1).'
Description'.WebGUI::Form::textArea("description",'').'
Starting from this level?'.WebGUI::Form::checkbox("startAtThisLevel",1,1).'
Show only one level?'.WebGUI::Form::checkbox("showOnlyThisLevel",1,1).'
'.WebGUI::Form::submit("save").'
'; return $output; } else { return WebGUI::Privilege::insufficient(); } return $output; } #------------------------------------------------------------------- sub www_addSave { my ($widgetId, $displayTitle, $image, $attachment); if (WebGUI::Privilege::canEditPage()) { $widgetId = create(); WebGUI::SQL->write("insert into SiteMap set widgetId=$widgetId, startAtThisLevel='$session{form}{startAtThisLevel}', showOnlyThisLevel='$session{form}{showOnlyThisLevel}'",$session{dbh}); return ""; } else { return WebGUI::Privilege::insufficient(); } } #------------------------------------------------------------------- sub www_edit { my ($output, %data); if (WebGUI::Privilege::canEditPage()) { %data = WebGUI::SQL->quickHash("select * from widget,SiteMap where widget.widgetId=SiteMap.widgetId and widget.widgetId=$session{form}{wid}",$session{dbh}); $output = '

Edit Site Map

'; $output .= WebGUI::Form::hidden("wid",$session{form}{wid}); $output .= WebGUI::Form::hidden("func","editSave"); $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= '
Title'.WebGUI::Form::text("title",20,30,$data{title}).'
Display title?'.WebGUI::Form::checkbox("displayTitle",1,$data{displayTitle}).'
Description'.WebGUI::Form::textArea("description",$data{description}).'
Starting from this level?'.WebGUI::Form::checkbox("startAtThisLevel",1,$data{startAtThisLevel}).'
Show only one level?'.WebGUI::Form::checkbox("showOnlyThisLevel",1,$data{showOnlyThisLevel}).'
'.WebGUI::Form::submit("save").'
'; return $output; } else { return WebGUI::Privilege::insufficient(); } } #------------------------------------------------------------------- sub www_editSave { if (WebGUI::Privilege::canEditPage()) { update(); WebGUI::SQL->write("update SiteMap set startAtThisLevel='$session{form}{startAtThisLevel}', showOnlyThisLevel='$session{form}{showOnlyThisLevel}' where widgetId=$session{form}{wid}",$session{dbh}); return ""; } else { return WebGUI::Privilege::insufficient(); } } #------------------------------------------------------------------- sub www_view { my (%data, $output, $sth, @root, $parent); %data = WebGUI::SQL->quickHash("select * from widget,SiteMap where widget.widgetId=SiteMap.widgetId and widget.widgetId='$_[0]'",$session{dbh}); if (defined %data) { if ($data{displayTitle} eq 1) { $output = '

'.$data{title}.'

'; } $output .= $data{description}.'

'; if ($data{startAtThisLevel} eq 1) { $parent = $session{page}{pageId}; } else { $parent = 1; } $sth = WebGUI::SQL->read("select urlizedTitle, title, pageId from page where parentId='$parent' order by sequenceNumber",$session{dbh}); while (@root = $sth->array) { if (WebGUI::Privilege::canViewPage($root[2])) { $output .= '· '.$root[1].'
'; unless ($data{showOnlyThisLevel} eq 1) { $output .= _traversePageTree($root[2],1); } } } $sth->finish; } return $output; } 1;