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

use lib '/app/tools/rps/lib';
use RPS::Mechanical::UK::McpsLicenseForm;

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

use RPS::Command;
use RPS::CommandLog;
use base 'RPS::Command';

sub cmd  { return 'show_mcps_license'; }
sub area { return 'uk_mech'; }

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

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

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

    # We mostly want to use the product ids to reference mcps licenses.
    # But just in case we only have the mcps license id, we'll look up the 
    # product id here based on that.
	my $productID = $self->getParam('ProductID');
	my $mcpsLicenseID = $self->getParam('McpsLicenseID');
	
	if ($mcpsLicenseID && !$productID)
	{	    
	    my $mcpsLicense = RPS::DB::Item::McpsLicense->Lookup(mcps_license_id => $mcpsLicenseID);
	    $productID = $mcpsLicense->product_id;
	}	
	
	my $form;
	
	if($productID)
	{
		$form = RPS::Mechanical::UK::McpsLicenseForm->new(productID => $productID);
        RPS::CommandLog::Log($self, $productID);
	}

	$self->{xml}{Form} = $form;

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

	return $response;
}


1;
