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 = '

';
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;