<?php

	lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
	lt_include( PLOG_CLASS_PATH."plugins/extrafields/class/view/pluginextrafieldsconfigview.class.php" );

		
	/**
	 * updates the plugin configuration
	 */
	class PluginExtraFieldsUpdateConfigAction extends AdminAction
	{
		var $_value;
		
		function PluginExtraFieldsUpdateConfigAction( $actionInfo, $request )
		{
			$this->AdminAction( $actionInfo, $request );
			
			$this->requirePermission( "manage_plugins" );			
		}
		
		function validate()
		{
            $this->_value = $this->_request->getValue( "value" );
			return true;
		}
		        
		function perform()
		{
            // // update the plugin configurations to blog setting
			$blogSettings = $this->_blogInfo->getSettings();
            $blogSettings->setValue( "plugin_extrafields_value", $this->_value );
            $this->_blogInfo->setSettings( $blogSettings ); 
		
			// save the blogs settings
			$blogs = new Blogs();
            if( !$blogs->updateBlog( $this->_blogInfo )) {
                $this->_view = new PluginExtraFieldsConfigView( $this->_blogInfo );
                $this->_view->setErrorMessage( $this->_locale->tr("error_updating_settings"));
                $this->setCommonData();

                return false;
            }
			
			// if everything went ok...
            $this->_blogInfo->setSettings( $blogSettings );
            $this->_session->setValue( "blogInfo", $this->_blogInfo );
            $this->saveSession();
			
			$this->_view = new PluginExtraFieldsConfigView( $this->_blogInfo );
			$this->_view->setSuccessMessage( $this->_locale->tr("blog_settings_updated_ok"));
			$this->setCommonData();
			
			// clear the cache
			CacheControl::resetBlogCache( $this->_blogInfo->getId());
            
            return true;
		}
	}
?>