<?php

	include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
	include_once( PLOG_CLASS_PATH."plugins/jupload/class/view/pluginjuploadconfigview.class.php" );	
		
	/**
	 * updates the plugin configuration
	 */
	class PluginJUploadUpdateConfigAction extends AdminAction
	{
		var $_pluginEnabled;
		var $_maxFilesPerRequest;
		
		function PluginJUploadUpdateConfigAction( $actionInfo, $request )
		{
			$this->AdminAction( $actionInfo, $request );
		}
		
		function validate()
		{
            $this->_pluginEnabled = $this->_request->getValue( "pluginEnabled" );
            $this->_pluginEnabled = ($this->_pluginEnabled != "" );			
            $this->_maxFilesPerRequest = $this->_request->getValue( "maxFilesPerRequest" );
            if( $this->_maxFilesPerRequest <= 0  || $this->_maxFilesPerRequest>5 || !ctype_digit($this->_maxFilesPerRequest) ) {
                $this->_view = new PluginJUploadConfigView( $this->_blogInfo );
                $this->_view->setErrorMessage( $this->_locale->tr("jupload_error_maxfilesperrequest"));
                $this->setCommonData();

                return false;
            }
			return true;
		}
		        
		function perform()
		{
            // // update the plugin configurations to blog setting
			$config =& Config::getConfig();
            $config->setValue( "plugin_jupload_enabled", $this->_pluginEnabled );
            $config->setValue( "plugin_jupload_maxfilesperrequest", $this->_maxFilesPerRequest );
		
            if( !$config->save() ) {
                $this->_view = new PluginJUploadConfigView( $this->_blogInfo );
                $this->_view->setErrorMessage( $this->_locale->tr("error_updating_settings"));
                $this->setCommonData();

                return false;
            }
			
			// if everything went ok...
            $this->_session->setValue( "blogInfo", $this->_blogInfo );
            $this->saveSession();

			$this->_view = new PluginJUploadConfigView( $this->_blogInfo );
			$this->_view->setSuccessMessage( $this->_locale->tr("jupload_settings_saved_ok"));
			$this->setCommonData();
			
			// clear the cache
			CacheControl::resetBlogCache( $this->_blogInfo->getId());				
            
            return true;		
		}
	}
?>