#------------------------------------------------------------
# Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved
# $Id$
#------------------------------------------------------------
package RPS::Catalog::Command::Entry;
use strict;
use warnings;

use lib '/app/tools/rps/lib';
use Common::FormObject;
use RPS::Catalog::Album;
use RPS::Catalog::ArtistList;
use RPS::LabelList;
use RPS::Command;
use base 'RPS::Command';

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

sub cmd  { return 'entry'; }
sub area { return 'catalog'; }

use constant kTemplate => "/app/tools/rps/templates/catalog.xsl";

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

	my $response = $self->SUPER::execute();
	return $response if $response;

	my $albumID = $self->getParam('AlbumID');

	$self->{xml}{Album} = RPS::Catalog::Album->new(albumID => $albumID);
	$self->{xml}{ArtistList} = RPS::Catalog::ArtistList->new();
	$self->{xml}{LabelList} = RPS::LabelList->new();

	if ($self->getParam('submit'))
	{
		if ($self->{xml}{Album}->assignCGIParams('Album', $self->getParams())
		 && $self->{xml}{Album}->validate())
		{
			$self->{xml}{Album}->save();
			$self->addMessageXML(type => "success", code => Common::FormObject::kSuccessFormSubmit);
		}
		else
		{
			$self->{xml}{Album}->setError(Common::FormObject::kErrFormSubmit);
		}
	}

	$response = RSApache::Response::XML->new($self->{xml}, kTemplate);
	return $response;
}



1;
