/** <pre>
	Description:	Lion.java contains Project object for the Lion application.
				Originally generated by NetDyanmics Studio.

	Created By:		VELA/JG	1997.02.13 

	Methods:		

	Change History: 

 	By		Date		Description
	------------------------------------------------------------
	Vela/KC	97.03.05	Added newline features to debugMessage.
	
	IK/SLGA 97.12.01    Added Code in onSessionTimeOutEvent to
						inform user that his/her session has expired
						Load Login Page

	IK/SLGA 97.12.02    In onSessionTimeOutEvent return (STOP_PROCESSING)

	IK/SLGA 97.12.15    In onSessionTimeOutEvent remove Session Objects
						SO_USER_ID and SO_USER_PASSWORD 
	IK/SLGA 97.12.16   	Commented In onSessionTimeOutEvent remove Session Objects
						SO_USER_ID and SO_USER_PASSWORD 
	
	IK/SLGA 97.12.16    In onSessionTimeOutEvent return(PROCEED_WITH_BUILTIN_HANDLING)
						instead of return(STOP_PROCESSING)
						so that Web Process in not terminated in new session

	IK/SLGA 97.12.18    In onSessionTimeOutEvent
					    loaded pgSessionTimeOut to indicate session has timed out.

</pre>
*/


package Lion;

import spider.* ;
import spider.util.* ;
import spider.session.* ;
import spider.database.*;
import spider.visual.*;
import spider.html.*;
import spider.access.*;

import spider.event.*;

//[[SPIDER_CLASS BEGIN
/**	Lion provides application-level functionality for the LION system. */
public class Lion extends CSpProject implements LionInterface
//]]SPIDER_CLASS END
{

	//*********************************** Start of class methods ************************************

	private static	boolean	 _DEBUG = false ;

	/** sets the global debug flag */
	public static void setDebug ( boolean pDebug ) {
		 _DEBUG =pDebug;
	}

	/** sets the global debug flag to true. */
	public static void debugOn ( ) {
		setDebug ( true ) ;
	}

	/** sets the global debug flag to false. */
	public static void debugOff ( ) {
		setDebug ( false ) ;
	}

	/** returns the global debug flag */
	public static boolean debugStatus () {
		return ( _DEBUG );
	}

	/** Logs a message to the bottom of the page, if the debug flag is set to true.  Does nothing otherwise. */
	public static void debugMessage  ( String	theMessage )  {
		if ( _DEBUG )	{
			CSpHtml.sendMessage ( CSpider.getOutputStream (), CSpHtml.descape ( "<br>" ) + theMessage + CSpHtml.descape ( "<br>" ) );
		}
	}

	/** Logs a message to the bottom of the page, if the debug flag is set to true.  Does nothing otherwise.
		Default is new line for each message, can be overridden using optional newLine=false.*/
	public static void debugMessage  ( String	theMessage, boolean newLine )  {
		if ( _DEBUG )	{
			if ( newLine == false ) {
				CSpHtml.sendMessage ( CSpider.getOutputStream (), theMessage );
			} else {
				debugMessage ( theMessage ) ;
			}
		}
	}



	//*********************************** End of class methods ************************************


	//[[SPIDER_EVENTS BEGIN
	
	//[[SPIDER_EVENT<onAfterInitEvent ()>
	protected int onAfterInitEvent ()
	{
		debugOn () ;
		return (PROCEED_WITH_BUILTIN_HANDLING);
	}
	//]]SPIDER_EVENT<onAfterInitEvent ()>

	//[[SPIDER_EVENT<onSecurityCheckFailedEvent (int failureType, CSpPage currPage)>
	protected int onSecurityCheckFailedEvent (int failureType, CSpPage currPage)
	{
		CSpUserProfile myUserProfile = CSpider.getUserProfile();
		String nl = "----" ; 	// newline character for HTML messages - not currently working.  KC 1997.02.27
		String myNextPage = currPage.getName () ;
		String message = "" ;
		if ( debugStatus () ) {
			message = "Lion.onSecurityCheckFailedEvent" + nl +
			"myUserProfile.securityObjectActivated :" +  ( ( myUserProfile.securityObjectActivated () == true ) ? "true" : "false" ) + nl +
			"myUserProfile.getUserPrivileges :" +  myUserProfile.getUserPrivileges().stringValue () + nl +
			"myUserProfile.getDbUserLogin :" +  myUserProfile.getDbUserLogin().stringValue () ;
		}

		switch ( failureType ) {
		case  SECURITY_OBJECT_ACTIVATION_FAILURE_TYPE :
			message =  "Unable to check privileges. You have either accessed a page without logging in, or your privileges" ;
			message +=  " do not allow you to access that page.  You must login." ;
			myNextPage = LOGIN_PAGE ;
		break ;

		case ACTIVE_SECURITY_OBJECT_PRIV_FAILURE_TYPE :
			message =  "Sorry.  You don't have privileges to use this page." ; 
			myNextPage = MAIN_PAGE ;
		break ;

		case NEW_SECURITY_CHECK_PRIV_FAILURE_TYPE :
			message +=  "NEW_SECURITY_CHECK_PRIV_FAILURE_TYPE"  ; 
		break ;

		case SESSION_CONTINUITY_FAILURE_TYPE :
			message +=  nl + "SESSION_CONTINUITY_FAILURE_TYPE " ; 
		break ;

		case PARENT_IS_NOT_A_PROJECT_FAILURE_TYPE :
			message +=  nl + "PARENT_IS_NOT_A_PROJECT_FAILURE_TYPE "  ;
		break  ;

		case DEFAULT_SESSION_TIMEOUT :
			message +=  nl + "DEFAULT_SESSION_TIMEOUT " ;
		break ;
		}


		 ((LionPage) currPage).callErrorPage ( message , myNextPage ) ;

		return (STOP_PROCESSING);
	}
	//]]SPIDER_EVENT<onSecurityCheckFailedEvent (int failureType, CSpPage currPage)>

	//[[SPIDER_EVENT<onSessionTimeoutEvent (CSpSessionId problematicSessionId)>
	public int onSessionTimeoutEvent (CSpSessionId problematicSessionId)
	{
		CSpPage currPage = CSpider.getPage("pgSessionTimeOut");
		currPage.load();
		return (STOP_PROCESSING);
	}
	//]]SPIDER_EVENT<onSessionTimeoutEvent (CSpSessionId problematicSessionId)>

	//]]SPIDER_EVENTS END
}

