webgui/lib/WebGUI/Operation/Trash.pm
2003-01-05 18:32:19 +00:00

81 lines
2.8 KiB
Perl

package WebGUI::Operation::Trash;
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2003 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 Exporter;
use strict qw(vars subs);
use Tie::CPHash;
use WebGUI::Icon;
use WebGUI::Privilege;
use WebGUI::Session;
use WebGUI::SQL;
use WebGUI::URL;
our @ISA = qw(Exporter);
our @EXPORT = qw(&www_purgeTrash &www_purgeTrashConfirm);
#-------------------------------------------------------------------
sub _purgeWobjects {
my (%properties, $base, $extended, $b, $wobjectId, $namespace, $w, $cmd);
tie %properties, 'Tie::CPHash';
$b = WebGUI::SQL->read("select * from wobject where pageId=$_[0]");
while ($base = $b->hashRef) {
$extended = WebGUI::SQL->quickHashRef("select * from ".$base->{namespace}."
where wobjectId=".$base->{wobjectId});
%properties = (%{$base}, %{$extended});
$cmd = "WebGUI::Wobject::".$properties{namespace};
$w = $cmd->new(\%properties);
$w->purge;
}
$b->finish;
}
#-------------------------------------------------------------------
sub _recursePageTree {
my ($a, $pageId);
$a = WebGUI::SQL->read("select pageId from page where parentId=$_[0]");
while (($pageId) = $a->array) {
_recursePageTree($pageId);
_purgeWobjects($pageId);
WebGUI::SQL->write("delete from page where pageId=$pageId");
}
$a->finish;
}
#-------------------------------------------------------------------
sub www_purgeTrash {
my ($output);
if (WebGUI::Privilege::isInGroup(3)) {
$output = helpIcon(46);
$output .= '<h1>'.WebGUI::International::get(42).'</h1>';
$output .= WebGUI::International::get(162).'<p>';
$output .= '<div align="center"><a href="'.WebGUI::URL::page('op=purgeTrashConfirm').
'">'.WebGUI::International::get(44).'</a>';
$output .= '&nbsp;&nbsp;&nbsp;&nbsp;<a href="'.WebGUI::URL::page().'">'.
WebGUI::International::get(45).'</a></div>';
return $output;
} else {
return WebGUI::Privilege::adminOnly();
}
}
#-------------------------------------------------------------------
sub www_purgeTrashConfirm {
if (WebGUI::Privilege::isInGroup(3)) {
_recursePageTree(3);
_purgeWobjects(3);
return "";
} else {
return WebGUI::Privilege::adminOnly();
}
}
1;