<?php

	include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
	include_once( PLOG_CLASS_PATH."class/view/admin/adminplugintemplatedview.class.php" );
	include_once( PLOG_CLASS_PATH."plugins/emailencryption/class/view/adminemailencryptionview.class.php" );

	class AdminUpdateEmailEncryptionAction extends AdminAction
	{
		var $_pluginEnabled;

		function AdminUpdateEmailEncryptionAction($actionInfo, $request)
		{
			$this->AdminAction($actionInfo, $request);
		}

		function validate()
		{
			$this->_pluginEnabled = $this->_request->getValue("pluginEnabled");
			$this->_pluginEnabled = ($this->_pluginEnabled != "" );

			return true;
		}

		function perform()
		{
			$blogSettings = $this->_blogInfo->getSettings();

			$blogSettings->setValue("emailencryption_plugin_enabled", $this->_pluginEnabled);

			$this->_blogInfo->setSettings($blogSettings);

			$blogs = new Blogs();

			if( !$blogs->updateBlog( $this->_blogInfo ))
			{
				$this->_view = new AdminEmailEncryptionView( $this->_blogInfo );
				$this->_view->setErrorMessage( $this->_locale->tr("error_updating_settings"));

				$this->setCommonData();

				return false;
			}

			$this->_blogInfo->setSettings($blogSettings);
			$this->_session->setValue("blogInfo", $this->_blogInfo);

			$this->saveSession();

			$this->_view = new AdminEmailEncryptionView($this->_blogInfo);
			$this->_view->setSuccessMessage($this->_locale->tr("emailencryption_settings_saved_ok"));

			$this->setCommonData();

			CacheControl::resetBlogCache($this->_blogInfo->getId());

			return true;
		}
	}
?>
