#------------------------------------------------------------
# Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved
# $Id$
#------------------------------------------------------------
package Corp::Press::Release;
use strict;
use warnings;

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

sub cmd  { return 'release'; }
sub area { return 'press'; }

use constant kTemplatePath => "/app/tools/corp/templates/press/";


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

	my $response = $self->SUPER::execute();
	return $response if $response;
	
	my $releaseID = $self->getParam("ReleaseID");
	$releaseID .= ".xsl";
	
	# Let's make an array of all of the valid template names.
	#
	my $dir = kTemplatePath;
	opendir DIR, $dir or die "cannot open dir $dir: $!";
	my @fileNames = readdir DIR;
	closedir DIR;
	
	# Now let's see if the releaseID (+.xsl) matches any of them.
	#
	my $match = 0;
	foreach (@fileNames) {$match = 1 if $_ eq $releaseID;}
	
	my $template;
	
	if ($match == 1) 
	{	# Found a match, let's display the press release
		$template = kTemplatePath.$releaseID;
	}
	else 
	{ # No match, so back to the main press release page for you.
		$template = kTemplatePath."main.xsl";
	}
	$response = RSApache::Response::XSLT->new($self->{xml}, $template);
	return $response;
}



1;
