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

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

use lib '/app/tools/common/lib';
use Common::FormObject;
use RSApache::Response::XML;
use RSApache::Response::XSLT;
use RSApache::Response::Redirect;

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

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

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

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


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


    # We don't really need to use the form object here. We're not setting any form properties.
    # So I am going to use the AlbumContract class in a more direct manner.
    #
    my $albumContract = RPS::Catalog::AlbumContract->new(albumID => $albumID, artistContractID => $artistContractID);
	if ($albumContract && $albumContract->validate())
	{
		$albumContract->save();

        # !!! Not sure what, if any, messages are appropriate here.
        # None, perhaps.
        #
	}


    # We've moved away from the page, so we'll have to do a redirect to get the
    # page to refresh.   We'll pass in a hint to the command to ask it to select
    # the contracts tab.
    #
    my $command= RPS::Catalog::Command::Show->new
    (
        AlbumID => $albumID, 
        tab => RPS::Catalog::Command::Show::kTabContracts,
    );

	return RSApache::Response::Redirect->new($command->getRedirect());
}



1;
