#------------------------------------------------------------
# Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved
# $Id$
#------------------------------------------------------------
package RPS::Display::Command::Show;

use lib '/app/tools/common/lib';
use RSApache::Response::XSLT;

use lib '/app/tools/rps/lib';
use RPS::Command;
use base 'RPS::Command';

sub cmd  { return "show"; }
sub area { return "display"; }

sub execute
{
	my ($self) = @_;

	# Give any inherited methods the first crack at this.
	# (This checks for login and basic access permissions).
	#
	my $response = $self->SUPER::execute();
	return $response if $response;

    my $page = $self->getParam("p") || 'index';
    my $subDir = $self->getParam("d");

    # !!! jpk - I don't actually understand what is going on here.
    # I am afraid that this violates my architecture.
    #

	my $template = '/app/tools/rps/templates/static';
	if($subDir)
	{
		# let's be careful about this
		#
		$subDir =~ s/\W//g;
		$template .= '/'.$subDir;
	}
	# let's be careful about this
	#
	$page =~ s/\W//g;
	$template .= '/'.$page.'.xsl';

	# let's make sure this file exists
	#
	if(!-e $template)
	{
		# Sorry, you can't be here...
		#
		$self->addMessageXML(type => "error", code => kMsgAccessDenied);
		return RSApache::Response::XSLT->new($self->{xml}, RPS::Command::kAccessDeniedTemplate);
	}
	else
	{
		$response = RSApache::Response::XSLT->new($self->{xml}, $template);
		return $response;
	}
}


1;
