<?php

include_once( PLOG_CLASS_PATH."class/summary/action/summaryaction.class.php" );
include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
include_once( PLOG_CLASS_PATH."class/summary/view/summarycachedview.class.php" );
include_once( PLOG_CLASS_PATH."class/config/config.class.php" );

/**
 * Base action that all register actions should extend
 * @package summary
 * @subpackage action
 */
class RegisterAction extends SummaryAction
{
    var $userName;
    var $userPassword;
    var $userFullName;
    var $userEmail;
    var $blogName;
    var $blogCategoryId;
    var $blogLocale;
    var $templateId;
    var $blogDomain;

    function RegisterAction( $actionInfo, $request )
    {
        $this->SummaryAction( $actionInfo, $request );
        $this->registerValidators();

		$tf = new Textfilter();
        $this->blogName = $tf->filterAllHTML( $this->_request->getValue( "blogName" ));
        $this->blogDomain = $tf->filterAllHTML( $this->_request->getValue( "blogDomain" ));
        $this->blogCategoryId = $this->_request->getValue( "blogCategoryId" );
        $this->blogLocale = $this->_request->getValue( "blogLocale" );
        $this->userName = $tf->filterAllHTML($this->_request->getValue( "userName" ));
        $this->userPassword = $tf->filterAllHTML($this->_request->getValue( "userPassword" ));
        $this->userEmail = $tf->filterAllHTML($this->_request->getValue( "userEmail" ));
		$this->userFullName = $tf->filterAllHTML($this->_request->getValue( "userFullName" ));
		
		// there has to be a better place to check this, but I can't think of it now... Killing
		// the script without returning to the controller probably isn't a good idea, but it's
		// the quickest right now!
		$config =& Config::getConfig();
		if( $config->getValue( "summary_disable_registration" )) {
			include_once( PLOG_CLASS_PATH."class/summary/view/summarymessageview.class.php" );
			$this->_view = new SummaryMessageView();
			$this->_view->setErrorMessage( $this->_locale->tr("error_registration_disabled"));			
			die($this->_view->render());
		}		
    }
	
	function validationErrorProcessing()
	{
		parent::validationErrorProcessing();
		$this->setValues();
	}

    /**
     * make these values tranferred until the last register step, if there are validation error happened.
     */
	function registerValidators()
	{
        $this->registerField( "userName" );
        $this->registerField( "userFullName" );
        $this->registerField( "userPassword" );
        $this->registerField( "userEmail" );
        $this->registerField( "blogName" );
        $this->registerField( "blogCategoryId" );
        $this->registerField( "blogDomain" );
        $this->registerField( "blogLocale" );
        $this->registerField( "templateId" );
	}

    /**
     * make these values tranferred until the last register step
     */
    function setValues()
	{
        $this->_view->setValue( "userName", $this->userName );
        $this->_view->setValue( "userFullName", $this->userFullName );
        $this->_view->setValue( "userPassword", $this->userPassword );
        $this->_view->setValue( "userEmail", $this->userEmail );
        $this->_view->setValue( "blogName", $this->blogName );
        $this->_view->setValue( "blogCategoryId", $this->blogCategoryId );
        $this->_view->setValue( "blogDomain", $this->blogDomain );
        $this->_view->setValue( "blogLocale", $this->blogLocale );
        $this->_view->setValue( "templateId", $this->templateId );
    }
}
?>
