<?php

	include_once( PLOG_CLASS_PATH."class/action/admin/siteadminaction.class.php" );
	include_once( PLOG_CLASS_PATH."class/view/admin/admintemplatedview.class.php" );
	include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
	include_once( PLOG_CLASS_PATH."class/dao/commentscommon.class.php" );
	include_once( PLOG_CLASS_PATH."class/dao/users.class.php" );

    /**
     * \ingroup Action
     * @private
     *
     * Action that shows a form to change the settings of the current blog.
     */
    class AdminCleanupAction extends SiteAdminAction
	{
		var $_message;
		var $_op;

		function AdminCleanupAction( $actionInfo, $request )
		{
			$this->SiteAdminAction( $actionInfo, $request );

			// since we've got two submit buttons in that form, we need to decide what to do
			// depending on which button was clicked
			if( $this->_request->getValue( "purgePosts" ))
				$this->_op = "cleanupPosts";
			elseif( $this->_request->getValue( "purgeSpam" ))
				$this->_op = "cleanupSpam";
			elseif( $this->_request->getValue( "purgeUsers" ))
				$this->_op = "cleanupUsers";
			elseif( $this->_request->getValue( "purgeBlogs" ))
				$this->_op = "cleanupBlogs";				

			$this->_message = "";
		}

		/**
		 * cleans up posts. Returns true if successful or false otherwise
		 */
		function cleanupPosts()
		{
        	$articles = new Articles();
			$articles->purgePosts();

			$this->_message = $this->_locale->tr("posts_purged_ok");

			return true;
		}

		/**
		 * cleans up users. Returns true if successful or false otherwise
		 */		
		function cleanupUsers()
		{
	    	$users = new Users();
			$users->purgeUsers();

			$this->_message = $this->_locale->tr("users_purged_ok");

			return true;
		}		
		//-- End: Conan 20-05-2005 Add option to remove user permanently -->

		//-- Start: Conan 25-05-2005 Add option to remove Blog marked as disabled -->
		/**
		 * cleans up blogs. Returns true if successful or false otherwise
		 */
		
		function cleanupBlogs()
		{
	    	$blogs = new Blogs();
			$blogs->purgeBlogs();

			$this->_message = $this->_locale->tr("blogs_purged_ok");

			return true;
		}

		/**
		 * cleans up spam comments. Returns true if successful or false otheriwse
		 */
		function cleanupComments()
		{
			$comments = new CommentsCommon();
			$comments->purgeSpamComments();

            $this->_message = $this->_locale->tr("spam_comments_purged_ok");

			return true;
		}

		function perform()
		{
			$result = false;
			
			// decide what we're going to do...
			if( $this->_op == "cleanupSpam" ) {
				$result = $this->cleanupComments();
			}
			elseif( $this->_op == "cleanupPosts" ) {
				$result = $this->cleanupPosts();
			}
			elseif( $this->_op == "cleanupUsers" ) {
				include_once( PLOG_CLASS_PATH."class/template/cachecontrol.class.php" );
				$result = $this->cleanupUsers();
				CacheControl::resetSummaryCache();
			}
			elseif( $this->_op == "cleanupBlogs" ) {
				include_once( PLOG_CLASS_PATH."class/template/cachecontrol.class.php" );
				$result = $this->cleanupBlogs();
				CacheControl::resetSummaryCache();
			}

			// create the view and see if there was a success message
			$this->_view = new AdminTemplatedView( $this->_blogInfo, "cleanup" );
			if( $result ) 
				$this->_view->setSuccessMessage( $this->_message );

			$this->setCommonData();

			return true;
		}
	}
?>