#---------------------------------------------------------------
# ____                   _ _         ____  _                    
#|  _ \ ___  _   _  __ _| | |_ _   _/ ___|| |__   __ _ _ __ ___ 
#| |_) / _ \| | | |/ _` | | __| | | \___ \| '_ \ / _` | '__/ _ \
#|  _ < (_) | |_| | (_| | | |_| |_| |___) | | | | (_| | | |  __/
#|_| \_\___/ \__, |\__,_|_|\__|\__, |____/|_| |_|\__,_|_|  \___|
#            |___/             |___/                            
#
# Copyright (C) 2008 RoyaltyShare, Inc.      All Rights Reserved
#--------------------------------------------------------------- 
package RPS::License::Command::BaseCrossedAccountEdit;

use strict;
use warnings;
use Data::Dumper;

use lib '/app/tools/rps/lib';
use RPS::Catalog::Command::Search;

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

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

sub cmd  { return 'crossed_account'; }


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

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

	my $trackLicenseID = $self->getParam('TrackLicenseID');
	my $form;


	if($trackLicenseID)
	{
		$form = $self->_form()->new(trackLicenseID => $trackLicenseID);
	}
	else
	{
		my $command = RPS::Catalog::Command::Search->new();
		return RSApache::Response::Redirect->new($command->getRedirect());
	}

	if ($self->getParam('formSubmit'))
	{
		if ($form->assignCGIParams('Form', $self->getParams()) && $form->validate())
		{
			$form->save();

			# Redirect to the Show command.
			#
			my $command;
			my $successMessage = RPS::Message->new(type => "success", code => Common::FormObject::kSuccessFormSubmit);
			my %showParams = (
				TrackLicenseID => $form->trackLicenseID(),
				msg => $successMessage->toString(),
			);
			$command = $self->_command()->new(%showParams);
			return RSApache::Response::Redirect->new($command->getRedirect());
		}
		else
		{
			$form->setError(Common::FormObject::kErrFormSubmit);
			$self->addMessageXML(type => "error", code => Common::FormObject::kErrFormSubmit);
		}
	}

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

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

	return $response;
}


1;
