<?php

    include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
    include_once( PLOG_CLASS_PATH."class/view/admin/adminerrorview.class.php" );
    include_once( PLOG_CLASS_PATH."class/view/admin/adminmessageview.class.php" );

    include_once( PLOG_CLASS_PATH."plugins/shoutbox/class/dao/shoutbox.class.php" );
    
    /**
     * updates the plugin configuration
     */
    class PluginShoutboxUpdateConfigAction extends AdminAction
    {
    
        var $_pluginEnabled;
        var $_Shoutboxet;
        
        function PluginShoutboxUpdateConfigAction( $actionInfo, $request )
        {
            $this->AdminAction( $actionInfo, $request );
        }
  
        function validate()
		{
            $this->_pluginEnabled = $this->_request->getValue( "pluginEnabled" );
            $this->_pluginEnabled = ($this->_pluginEnabled != "" );
            $this->_Shoutboxet = $this->_request->getValue( "setId" );
            if( $Shoutboxet == "" )
                $Shoutboxet = DEFAULT_SMILEY_SET;
			
			return true;
        }


        function perform()
        {
            $endMessage = "Configuration successfully updated.";
            $backLink = "<br><br><a href='admin.php?op=shoutbox'>Back to the shoutbox</a><br>" .
                        "<a href='admin.php?op=shoutboxConfig'>Back to the shoutbox config page</a><br>";
        
            // and check which smiley set we should be using, or if none, then the default one
            $blogSettings = $this->_blogInfo->getSettings();


            if(strlen($this->_request->getValue('mail_alert')) > 0)
                $blogSettings->setValue( "plugin_shoutbox_mail_alert", 1);
            else
                $blogSettings->setValue( "plugin_shoutbox_mail_alert", 0);
            
            $blogSettings->setValue( "plugin_shoutbox_max_length", $this->_request->getValue('max_length'));
            $blogSettings->setValue( "plugin_shoutbox_shouts_per_view", $this->_request->getValue('shouts_per_view'));
            
            $blogSettings->setValue( "plugin_shoutbox_default_nick", $this->_request->getValue('default_nick'));
            $blogSettings->setValue( "plugin_shoutbox_default_shout", $this->_request->getValue('default_shout'));
            
            $blogSettings->setValue( "plugin_shoutbox_protected_nicks", $this->_request->getValue('protected_nicks'));
            $blogSettings->setValue( "plugin_shoutbox_protection_password", $this->_request->getValue('protection_password'));
            
            $this->_blogInfo->setSettings( $blogSettings );
        
            // save the blogs settings
            $blogs = new Blogs();
            if( !$blogs->updateBlog( $this->_blogInfo->getId(), $this->_blogInfo )) {
                $this->_view = new AdminErrorView( $this->_blogInfo );
                $this->_view->setValue( "message", "An error occurred! " . $backLink);
                $this->setCommonData();

                return false;
            }
            
            // if everything went ok...
            $this->_blogInfo->setSettings( $blogSettings );
            $this->_session->setValue( "blogInfo", $this->_blogInfo );
            $this->saveSession();
            
            $this->_view = new AdminMessageView( $this->_blogInfo );
            $this->_view->setMessage($endMessage . $backLink);
            $this->setCommonData();

            return true;
        }
    }
?>