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

use lib '/app/tools/rps/lib';
use RPS::DB::Item::AlbumContract;
use RPS::Catalog::Command::Show;
use base 'RSApache::Command::XMLCommand';

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

sub cmd  { return 'make_cc'; }
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 $albumContractID = $self->getParam('AlbumContractID');

    # The DB interface will do the right thing.
    #
    RPS::DB::Item::AlbumContract->SetAsControlledComp( $albumID, $albumContractID );

    # 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::kTabLicenses,
    );

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

1;
