#------------------------------------------------------------
# Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved
# $Id$
#------------------------------------------------------------
package Corp::Contact::Command::Edit;
use strict;
use warnings;

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

use lib '/app/tools/corp/lib';
use Corp::Contact::Form;

sub cmd  { return 'edit'; }
sub area { return 'contact'; }

use constant kTemplate => "/app/tools/corp/templates/contact/edit.xsl";


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

	my $response = $self->SUPER::execute();
	return $response if $response;
	
	my $path = "/app/data/corp";
	my $fileName = "contact.txt";

  # First let's make sure the directory exists.
  #
	if (! -e $path) {
 		mkdir($path) or die "Can't create $path:$!\n";
	}   

  my $FILE = $path."/".$fileName;
  if (! -e $FILE)
  {
      `touch $FILE`;
  }
  
  my $form = Corp::Contact::Form->new();  

  my $error;

  if ($self->getParam('formSubmit'))
  {
    if (   $form->assignCGIParams( 'Form', $self->getParams() )
        && $form->validate() )
    {
    	$form->save();
			$self->{xml}{Success} = 1; 	
    	
    }
    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}, kTemplate);

  return $response;
}




###
1;# All good handlers return true
###

