package Lion;

// import Lion.util.* ;

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

/**
<pre>
Description:
	LionPage extends the CSpPage class.  Overloaded methods can be referenced back
	to the ancestor class by inserting "super.onWhateverMethodIsCalled();" within 
	the studio-generated descendant method onWhateverMethodIsCalled().

	Note that any methods not coded in the individual pages will be handled by the
	appropriate method (ie. method of the same name) in the LionPage class. Methods
	such as onbtHelpWebEvent () may be handled entirely at the LionPage level.

Created By:
	VELA/JG	1997.02.13 

Methods:
	callHelpPage	 	-- 	Displays help from current page.
	callPreviousPage	-- 	Returns to the previous page.
	saveCurrentPage		-- 	Stores the name of the current page into a session variable.
	callErrorPage		--	Calls the error page.
	showError		-- 	Display passed error on Error Page.	
	makeDynamicBetwenJoin --  adds join criteria to DataObject using BETWEEN_INT_OPERATOR.					
	makeDynamicJoin		-- adds join criteria to a DataObject.
	makeDynamicQBE		-- adds QBE criteria to a DataObject.
    addCriteriaString    -- adds Clause(like OR) to Where Clause that already uses makeDynamicJoin

Change History: 

By		Date		Description
-----------------------------------------------------------------------------
VELA/JG	1997.02.18	Added methods CallErrorPage, ShowError, SaveCurrentPage,
		CallHelpPage, CallPreviousPage.  Removed redundant methods.

VELA/KC	1997.02.19	Added constants for username, password fields on pgLogin.

VELA/KC	1997.02.20	Moved constants to interface LionInterface.

VELA/KC	1997.03.06	Added makeDynamicQBE

TracyS  1997.03.26  Added makeDynamicBetweenJoin

TracyS 1997.03.26  Added AddCriteriaString - Adds For Example OR Criteria to the Where Clause with no dynamic criteria added

IsabelK 1997.07.21 Modified AddCriteriaString to get Dynamic Criteria added before new criteria is added


IsabelK 1997.12.01 Added to onbtLogOutWebEvent - removeSessionID
				   which removes all information associated with the EndUser
				   who intitiated the web event 

IsabelK 1997.12.03  Changed callPreviousPage to use load(false) rather than load()
					load (false) will not clear the static text fields on the page

IsabelK 1997.12.16 Moved to pgLogOut.java  - removeSessionID
				   which removes all information associated with the EndUser
				   who intitiated the web event 
</pre>
*/
public class LionPage extends CSpPage implements LionInterface
{

	/**		callHelpPage dynamically builds the query to be passed to the Help page.  
	*	The name of the current page is stored in SO_RETURN, and the Help page
	*	is called.
	*/
	protected int callHelpPage() {		
		try {
			// ** Define method variables.
			CSpPage	vHelpPage	= 	CSpider.getPage ( HELP_PAGE ) ;
			CSpSelect	vHelpQuery	=	( CSpSelect ) CSpider.getDataObject ( DO_HELP ) ;
			String	vPageName	=	this.getName () ;
			
		// ** Copy the name of the current page into a session object, so the user can get back to this
		//	page after reading help.
            CSpider.putSessionObject(SO_RETURN,new CSpString (vPageName));

		// ** Set dynamic SQL WHERE clause to select help for the appropriate module
		vHelpQuery.clearDynamicCriteria () ;
		vHelpQuery.addDynamicCriterion ( DO_HELP_MODULEID, CSpCriteriaSQLObject.EQUAL_TO_STR_OPERATOR,
		( CSpValue ) new CSpString ( vPageName )  
		) ;			
			
		// ** Call the Help Page.
		vHelpPage.load () ;

		// ** If an exception occurs, log an error (to be replaced by generic error call).			
		} catch ( NullPointerException ex ) {
			CSpLog.exception ( this, "Null reference to Help Page.", ex ) ;	
		}

		return (PROCEED_WITH_BUILTIN_HANDLING);
	}



	/** callPreviousPage returns to the previous page (previously stored in the SO_RETURN session variable. */
	protected int callPreviousPage()
	{
    	try { 
	    	CSpValue  _vPreviousPage = (CSpValue)
    	    CSpider.getSessionObject( SO_RETURN );
			CSpPage	vReturnPage = CSpider.getPage ( _vPreviousPage.stringValue() ) ;
			//vReturnPage.load () ;
			// IK/SLGA 97.12.03 Use load(false) so that static text fields on
			// criteria page hold value after a find
			
			vReturnPage.load(false);
				
			return ( PROCEED_WITH_BUILTIN_HANDLING ) ;
		} 

	// ** If an error occurs, log an exception. To be replaced by call to generic routine.
	catch ( NullPointerException ex ) 
		{
		CSpLog.exception ( this, "Null reference to last page.", ex ) ; 
    		}
	return (PROCEED_WITH_BUILTIN_HANDLING);
	}
	
	//]]SPIDER_EVENT<callPreviousPage>

	/**	SaveCurrentPage loads the name of the current page into a session object, for later retrival.
	 This method DOES NOT call a page. */
	//[[SPIDER_EVENT<saveCurrentPage>
	protected int saveCurrentPage()
	{		
		try {
			saveCurrentPage ( this.getName () ) ;

		// ** If an exception occurs, log an error (to be replaced by generic error call).			
		} catch ( NullPointerException ex ) {
			CSpLog.exception ( this, "Error storing return page session object.", ex ) ;	
		}

		return (PROCEED_WITH_BUILTIN_HANDLING);
	}


	/*	Created by VELA/KC - 1997.02.27
		overloaded to allow programmer to specify the pageName to be saved
	*/
	protected int saveCurrentPage ( String vPageName)
	{		
		try {
//Lion.debugMessage ( "saveCurrentPage(): this.getName () ="+vPageName);			
		// ** Copy the name of the current page into a session object, so the user can get back to this
		//	page.
            CSpider.putSessionObject(SO_RETURN, ( CSpValue ) new CSpString (vPageName));

		// ** If an exception occurs, log an error (to be replaced by generic error call).			
		} catch ( NullPointerException ex ) {
			CSpLog.exception ( this, "Error storing return page session object.", ex ) ;	
		}

		return (PROCEED_WITH_BUILTIN_HANDLING);
	}

	protected int saveCurrentPage ( CSpPage pPage)
	{		
		try {
			saveCurrentPage ( pPage. getName ( ) )	;
	// ** If an exception occurs, log an error (to be replaced by generic error call).			
		} catch ( NullPointerException ex ) {
			CSpLog.exception ( this, "Error storing return page session object.", ex ) ;	
		}
		return (PROCEED_WITH_BUILTIN_HANDLING);
	}

	private int loadErrorPage( String pErrorText )
	{		
		try {
		// ** Define method variables.
			CSpPage	vErrorPage	= 	CSpider.getPage ( ERROR_PAGE ) ;
			if ( pErrorText.equals ( null ) ) {
				 pErrorText	=	"No error text passed.";
			}			

            CSpider.putSessionObject(SO_ERROR_TEXT, new CSpString (pErrorText));
			
		// ** Call the Error Page.
		vErrorPage.load () ;

		// ** If an exception occurs, log an error (to be replaced by generic error call).			
		} catch ( NullPointerException ex ) {
			CSpLog.exception ( this, "Null reference to Error Page.", ex ) ;	
		}

		return (PROCEED_WITH_BUILTIN_HANDLING);
	}
    
	protected int callErrorPage( String pErrorText )
	{		
		try {
		// ** Save name of current page. 
		saveCurrentPage ( ) ;
		loadErrorPage ( pErrorText ) ;

		// ** If an exception occurs, log an error (to be replaced by generic error call).			
		} catch ( NullPointerException ex ) {
			CSpLog.exception ( this, "Null reference to Error Page.", ex ) ;	
		}

		return (PROCEED_WITH_BUILTIN_HANDLING);
	}
    
	protected int callErrorPage( String pErrorText, CSpPage pReturnPage )
	{		
		try {
		// ** Save name of current page. 
		saveCurrentPage( pReturnPage );
		// ** load the error page
		loadErrorPage ( pErrorText ) ;

		// ** If an exception occurs, log an error (to be replaced by generic error call).			
		} catch ( NullPointerException ex ) {
			CSpLog.exception ( this, "Null reference to Error Page.", ex ) ;	
		}

		return (PROCEED_WITH_BUILTIN_HANDLING);
	}
    
	protected int callErrorPage( String pErrorText, String pReturnPage )
	{		
		try {
		// ** Save name of current page. 
		saveCurrentPage( pReturnPage );
		// ** load the error page
		loadErrorPage ( pErrorText ) ;

		// ** If an exception occurs, log an error (to be replaced by generic error call).			
		} catch ( NullPointerException ex ) {
			CSpLog.exception ( this, "Null reference to Error Page.", ex ) ;	
		}

		return (PROCEED_WITH_BUILTIN_HANDLING);
	}
    
	protected int putString (String vPassedString)
	{
        CSpider.putSessionObject(SO_TEXT,new CSpString (vPassedString));		
		return (PROCEED_WITH_BUILTIN_HANDLING);
	}

    //** End of modified code. VELA/JG 1997.02.18

	
	//** Begin modified code. VELA/JG 1997.02.20
	/**	onValidationFailureEvent generates error messages based on the failure type,
	 *	then calls the error page and displays the error.  
	 */
	//[[SPIDER_EVENT<onValidationFailureEvent (int vFailureType, CSpVisual visualObject)>
	protected int onValidationFailureEvent (int vFailureType, CSpVisual visualObject)

	{
		String vFailString = null;
		String vValueString = null;
		//try
		//{
			CSpFormatField vFormatField = (CSpFormatField) visualObject;
			switch (vFailureType)
			{
				case CSpValidator.FAILED_VALUE_IS_REQUIRED :
					vFailString = "is a required field";
					break;
				case CSpValidator.FAILED_NOT_ACCORDING_TO_MASK :
					vFailString = "is not in the correct format.";
					break;
				case CSpValidator.FAILED_NOT_MATCHING_REGULAR_EXPRESSION :
					vFailString = "is not in the correct format.";
					break;
				case CSpValidator.FAILED_NOT_NUMERIC :
					vFailString = "is not a number.";
					break;
				case CSpValidator.FAILED_NOT_IN_SET_OF_VALUES :
					vFailString = "is not an allowed value.";
					break;
				case CSpValidator.FAILED_NOT_IN_RANGE :
					vFailString = "is not within the allowed value range.";
					break;
				case CSpValidator.FAILED_NOT_CURRENCY :
					vFailString = "is not a valid currency amount.";
					break;
				case CSpValidator.FAILED_NOT_DATE_TIME :
					vFailString = "is not a valid date/time.";
					break;
				case CSpValidator.FAILED_DUE_TO_AN_EXCEPTION :
					vFailString = "caused an unexpected exception.";
					break;
				
			}
			
			CSpValue vCurrentValue = vFormatField.getValue();
			if (vCurrentValue instanceof CSpVector)
			{
				int vValidatedRecordIndex = vFormatField.getValidatedRecordIndex ();
				vValueString = 	"|" +
							((CSpVector) vCurrentValue).get (vValidatedRecordIndex) +
							"| (Record #" + (vValidatedRecordIndex + 1) + ")";
			}
			else
			{	
				vValueString = "|" + vCurrentValue + "|";
			}
		//catch (Exception ex)
		//{
		//	vValueString	= "Unknown value";
		//	vFailString 	= ", unknown failure.";
		//}

		// ** Build error string and pass it to the error page.
		String vBuildErrorStr 	= this.getName() + ": An error occurred validating " +
								CSpUtil.formatName (visualObject, false) + ". " +
								vValueString + " " + vFailString;
		
		// ** Call the error page, passing the built string. 
		callErrorPage ( vBuildErrorStr );
				
		return (STOP_PROCESSING);
	}
	//]]SPIDER_EVENT<onValidationFailureEvent (int vFailureType, CSpVisual visualObject)>

	//[[SPIDER_EVENT<onbtPreviousPageWebEvent>
	public int onbtBackWebEvent( String args[] )
	{
		// **	Start custom code.	VELA/JG	1997.02.13
		//		Return to previous page when "Go Back..." is pressed (retrieves page name 
		//		from SO_RETURN).
        callPreviousPage();
		// ** 	End custom code.	VELA/JG	1997.02.13
		return (PROCEED_WITH_BUILTIN_HANDLING);
	}
	//]]SPIDER_EVENT<onbtPreviousPageWebEvent>

	//[[SPIDER_EVENT<onbtHelpWebEvent>
	public int onbtHelpWebEvent( String args[] )
	{
		// ** 	Begin modified code.  VELA/JG 1997.02.18
		// 		Calls code in LionPage which loads the help page query, passes
		//		the name of the current page in a session variable, and calls pgHelp.
		callHelpPage();
		// ** 	End modified code.	VELA/JG 1997.02.18
		return (PROCEED_WITH_BUILTIN_HANDLING);
	}
	//]]SPIDER_EVENT<onbtHelpWebEvent>


	/*	Begin inserted code -  VELA/KC  1997.02.27
		The following events are designed to handle the standard NetDynamics builtins.
		This allows (requires?) the developer to cut the standard stub methods from each
		individual page and have them handled at the LionPage level.

		To use these functions, developers must:
		1)	Ensure that their builtin buttons are named with the exact name of the builtin.
				Note: NetDynamics tends to append '1' to the name of the builtin in the Button Wizard.
					  (ie. 'Prev' becomes 'Prev1', and 'onPrevWebEvent' becomes 'onPrev1WebEvent' )
		2)  Cut the standard 3-line public method out of the page.java file.
	*/
		

	//[[SPIDER_EVENT<onFirstWebEvent>
	public int onFirstWebEvent( String args[] )
	{
		int command = PROCEED_WITH_BUILTIN_HANDLING;
		command = doAction(args);
		return(command);
	}
	//]]SPIDER_EVENT<onFirstWebEvent>

	//[[SPIDER_EVENT<onNextWebEvent>
	public int onNextWebEvent( String args[] )
	{
		int command = PROCEED_WITH_BUILTIN_HANDLING;
		command = doAction(args);
		return(command);
	}
	//]]SPIDER_EVENT<onNextWebEvent>

	//[[SPIDER_EVENT<onPrevWebEvent>
	public int onPrevWebEvent( String args[] )
	{
		int command = PROCEED_WITH_BUILTIN_HANDLING;
		command = doAction(args);
		return(command);
	}
	//]]SPIDER_EVENT<onPrevWebEvent>

	//[[SPIDER_EVENT<onLastWebEvent>
	public int onLastWebEvent( String args[] )
	{
		int command = PROCEED_WITH_BUILTIN_HANDLING;
		command = doAction(args);
		return(command);
	}
	//]]SPIDER_EVENT<onLastWebEvent>

	//[[SPIDER_EVENT<onSelectWebEvent>
	public int onSelectWebEvent( String args[] )
	{
		int command = PROCEED_WITH_BUILTIN_HANDLING;
		command = doAction(args);
		return(command);
	}
	//]]SPIDER_EVENT<onSelectWebEvent>

	//[[SPIDER_EVENT<onInsertWebEvent>
	public int onInsertWebEvent( String args[] )
	{
		int command = PROCEED_WITH_BUILTIN_HANDLING;
		command = doAction(args);
		return(command);
	}
	//]]SPIDER_EVENT<onInsertWebEvent>

	//[[SPIDER_EVENT<onUpdateWebEvent>
	public int onUpdateWebEvent( String args[] )
	{
		int command = PROCEED_WITH_BUILTIN_HANDLING;
		command = doAction(args);
		return(command);
	}
	//]]SPIDER_EVENT<onUpdateWebEvent>

	//[[SPIDER_EVENT<onDeleteWebEvent>
	public int onDeleteWebEvent( String args[] )
	{
		int command = PROCEED_WITH_BUILTIN_HANDLING;
		command = doAction(args);
		return(command);
	}
	//]]SPIDER_EVENT<onDeleteWebEvent>

	//[[SPIDER_EVENT<onClearWebEvent>
	public int onClearWebEvent( String args[] )
	{
		int command = PROCEED_WITH_BUILTIN_HANDLING;
		command = doAction(args);
		return(command);
	}
	//]]SPIDER_EVENT<onClearWebEvent>

	//[[SPIDER_EVENT<onExecuteWebEvent>
	public int onExecuteWebEvent( String args[] )
	{
		int command = PROCEED_WITH_BUILTIN_HANDLING;
		command = doAction(args);
		return(command);
	}
	//]]SPIDER_EVENT<onExecuteWebEvent>

	//[[SPIDER_EVENT<onSearchWebEvent>
	public int onSearchWebEvent( String args[] )
	{
		int command = doQBE(args);
		if (command == PROCEED_WITH_BUILTIN_HANDLING)
		{
			command = doAction(args);
		}
		return(command);
	}
	//]]SPIDER_EVENT<onSearchWebEvent>

	//[[SPIDER_EVENT<onDrillDownWebEvent>
	public int onDrillDownWebEvent( String args[] )
	{
		int command = PROCEED_WITH_BUILTIN_HANDLING;
		command = doAction(args);
		return(command);
	}
	//]]SPIDER_EVENT<onDrillDownWebEvent>

	//[[SPIDER_EVENT<onbtHelpSearchWebEvent>
	public int onbtHelpSearchWebEvent( String args[] )
	{
		int command = PROCEED_WITH_BUILTIN_HANDLING;
		command = doAction(args);
		return(command);
	}
	//]]SPIDER_EVENT<onbtHelpSearchWebEvent>


	//[[SPIDER_EVENT<onbtHelpAddWebEvent>
	public int onbtHelpAddWebEvent( String args[] )
	{
		int command = PROCEED_WITH_BUILTIN_HANDLING;
		command = doAction(args);
		return(command);
	}
	//]]SPIDER_EVENT<onbtHelpAddWebEvent>

	//[[SPIDER_EVENT<onbtFirstWebEvent>
	public int onbtFirstWebEvent( String args[] )
	{
		return ( onFirstWebEvent ( args ) ) ;
	}
	//]]SPIDER_EVENT<onbtFirstWebEvent>

	//[[SPIDER_EVENT<onbtNextWebEvent>
	public int onbtNextWebEvent( String args[] )
	{
		return ( onNextWebEvent ( args ) ) ;
	}
	//]]SPIDER_EVENT<onbtNextWebEvent>

	//[[SPIDER_EVENT<onbtPrevWebEvent>
	public int onbtPrevWebEvent( String args[] )
	{
		return ( onPrevWebEvent ( args ) ) ;
	}
	//]]SPIDER_EVENT<onbtPrevWebEvent>

	//[[SPIDER_EVENT<onbtLastWebEvent>
	public int onbtLastWebEvent( String args[] )
	{
		return ( onLastWebEvent ( args ) ) ;
	}
	//]]SPIDER_EVENT<onbtLastWebEvent>



	/** 	makeDynamicJoin accepts the name of the data object to append the join
	 *	condition, the field to join, the value to join, and a clear flag where
	 *	"Y" clears all dynamic criteria before adding, and all other values keep
	 *	existing dynamic criteria.
	 */
	protected int makeDynamicJoin(String pDataObject, String pField, 
						String pValue, String pClearFlag)
	{
    	try { 
//		Lion.debugMessage("passed: "+ pDataObject + pField + pValue + pClearFlag);
		// Select the data object to manipulate.
		CSpSelect vDataObject =
		  (CSpSelect) CSpider.getDataObject ( pDataObject );
//		Lion.debugMessage ("got the dataobject");
		// Clear the dynamic criteria if flag set.
		if ( pClearFlag.equals("Y"))
		{ 
		vDataObject.clearDynamicCriteria ( CSpCriteriaSQLObject.JOIN_CRITERIA_TYPE );
		}

		// Add the join condition in the WHERE clause.
		vDataObject.addDynamicCriterion ( pField,
		  CSpCriteriaSQLObject.EQUAL_TO_STR_OPERATOR,
		  new CSpString ( pValue ));	
		return ( PROCEED_WITH_BUILTIN_HANDLING ) ;
		} 

	//	If an error occurs, log an exception. To be replaced by call to generic routine.
	catch ( NullPointerException ex ) 
		{
		CSpLog.exception ( this, "Error creating dynamic join.", ex ) ; 
    		}
	return (PROCEED_WITH_BUILTIN_HANDLING);
	}

	/** 	makeDynamicBetweenJoin accepts the name of the data object to append the join
	 *	condition, the field to join, the value to join, and Max value, and a clear flag where
	 *	"Y" clears all dynamic criteria before adding, and all other values keep
	 *	existing dynamic criteria.  It uses the Between_int_operator for the statement.
	 */
	protected int makeDynamicBetweenJoin(String pDataObject, String pField, 
						CSpValue pValue, CSpValue pValueMax, String pClearFlag)
	{
    	try { 
		//Lion.debugMessage("passed: " + pDataObject + pField + pValue + pValueMax+ pClearFlag);
		// Select the data object to manipulate.
		CSpSelect vDataObject =
		  (CSpSelect) CSpider.getDataObject ( pDataObject );

		// Clear the dynamic criteria if flag set.
		if ( pClearFlag.equals("Y"))
		{ 
		vDataObject.clearDynamicCriteria ( CSpCriteriaSQLObject.JOIN_CRITERIA_TYPE );
		}

		// Add the join condition in the WHERE clause.
		vDataObject.addDynamicCriterion (CSpCriteriaSQLObject.JOIN_CRITERIA_TYPE, pField, CSpCriteriaSQLObject.BETWEEN_INT_OPERATOR, pValue , pValueMax);	
		return ( PROCEED_WITH_BUILTIN_HANDLING ) ;
		} 

	//	If an error occurs, log an exception. To be replaced by call to generic routine.
	catch ( NullPointerException ex ) 
		{
		CSpLog.exception ( this, "Error creating dynamic join.", ex ) ; 
    		}
	return (PROCEED_WITH_BUILTIN_HANDLING);
	}
	protected int makeDynamicStrJoin(String pDataObject, String pField, 
						String pValue, String pClearFlag)
	{
    	try { 
//		Lion.debugMessage("passed: "+ pDataObject + pField + pValue + pClearFlag);
		// Select the data object to manipulate.
		CSpSelect vDataObject =
		  (CSpSelect) CSpider.getDataObject ( pDataObject );
//		Lion.debugMessage ("got the dataobject");
		// Clear the dynamic criteria if flag set.
		if ( pClearFlag.equals("Y"))
		{ 
		vDataObject.clearDynamicCriteria ( CSpCriteriaSQLObject.JOIN_CRITERIA_TYPE );
		}

		// Add the join condition in the WHERE clause.
		vDataObject.addDynamicStrCriterion ( pField,  pValue );	
		return ( PROCEED_WITH_BUILTIN_HANDLING ) ;
		} 

	//	If an error occurs, log an exception. To be replaced by call to generic routine.
	catch ( NullPointerException ex ) 
		{
		CSpLog.exception ( this, "Error creating dynamic join.", ex ) ; 
    		}
	return (PROCEED_WITH_BUILTIN_HANDLING);
	}


	/** 	makeDynamicQBE adds dynamic QBE criteria to the passed data object.
It accepts the name of (or reference to) the data object, the field to compare, the value to compare,
 and a clear flag where true clears all dynamic criteria before adding, and all other values 
keep existing dynamic criteria.
	 */
	protected int makeDynamicQBE ( CSpSelect pDataObject, String pField, String pValue, boolean pClearFlag ) {
//Lion.debugMessage ( "call makeDynamicQBE: " + pDataObject.getName () +","+ pField +","+ pValue +","+ pClearFlag, false) ;
    	try { 
			// Clear the dynamic criteria if flag set.
			if ( pClearFlag ) { 
//				pDataObject.clearDynamicCriteria ( CSpCriteriaSQLObject.QBE_CRITERIA_TYPE );
				pDataObject.clearDynamicCriteria ( );
			}

			// Add the QBE condition in the WHERE clause.
			if ( pDataObject.addDynamicCriterion ( pField, CSpCriteriaSQLObject.EQUAL_TO_STR_OPERATOR, (CSpValue) new CSpString ( pValue ) ) ) {
				// Lion.debugMessage ( "addDynamicCriterion passed!!!" ) ;
			}
//Lion.debugMessage ( "makeDynamicQBE: newDynamicJoin: " + pDataObject.getDynamicCriteria ( CSpCriteriaSQLObject.JOIN_CRITERIA_TYPE ) ) ;
//Lion.debugMessage ( "makeDynamicQBE: newDynamicQBE: " + pDataObject.getDynamicCriteria ( CSpCriteriaSQLObject.QBE_CRITERIA_TYPE ) ) ;
//Lion.debugMessage ( "makeDynamicQBE: newDynamicDrillDown: " + pDataObject.getDynamicCriteria ( CSpCriteriaSQLObject.DRILL_DOWN_CRITERIA_TYPE ) ) ;
			return ( PROCEED_WITH_BUILTIN_HANDLING ) ;
		} 

		//	If an error occurs, log an exception. To be replaced by call to generic routine.
		catch ( NullPointerException ex ) {
//Lion.debugMessage ( "Error creating dynamic QBE." ) ;
			CSpLog.exception ( this, "Error creating dynamic QBE.", ex ) ; 
    	}

		return (PROCEED_WITH_BUILTIN_HANDLING);
	}


	protected int makeDynamicQBE ( CSpMultiSQL pDataObject, String pField, String pValue, boolean pClearFlag ) {
    	return ( 
			makeDynamicQBE ( ( CSpSelect ) pDataObject, pField, pValue, pClearFlag ) 
		);
	}


	protected int makeDynamicQBE ( String pDataObject, String pField, String pValue, boolean pClearFlag ) {
		// Select the data object to manipulate.
		CSpSelect vDataObject = (CSpSelect) CSpider.getDataObject ( pDataObject );

    	return ( makeDynamicQBE ( vDataObject, pField, pValue, pClearFlag ) );
	}


	/** Log the user out when logout button clicked */
	public int onbtLogoutWebEvent( String args[] )
	{
		return ( CSpider. getPage ( LOGOUT_PAGE ). load () ) ;
	}

	/** Go to the main page when "main page" button clicked */
	public int onMainMenuEvent( String args[] )
	{
		return ( CSpider. getPage ( MAIN_PAGE ). load () ) ;
	}


	/**	makePeriodJoin builds the join criteria for a WHERE clause to select 
	 *	data within a given period range.  Equivalent to (pseudocode):
	 *	WHERE	periodcolumnvalue >= StartPeriod
	 *	AND		periodcolumnvalue <= EndPeriod 
	 */
	protected int makePeriodJoin(String pDataObject, String pPeriodColumn,
						String pStartPeriod, String pEndPeriod, String pClearFlag )
	{
    	try { 
		// Select the data object to manipulate.
		CSpSelect vDataObject =
		  (CSpSelect) CSpider.getDataObject ( pDataObject );

		// Clear the dynamic criteria if flag set.
		if ( pClearFlag.equals("Y"))
		{ 
		vDataObject.clearDynamicCriteria (  CSpCriteriaSQLObject.JOIN_CRITERIA_TYPE );
		}

		// Add the join conditions in the WHERE clause.
		vDataObject.addDynamicCriterion ( pPeriodColumn,
		  CSpCriteriaSQLObject.GREATER_THAN_EQUAL_TO_INT_OPERATOR ,
		  new CSpString ( pStartPeriod ) );	

		vDataObject.addDynamicCriterion ( pPeriodColumn,
		  CSpCriteriaSQLObject.LESS_THAN_EQUAL_TO_INT_OPERATOR ,
		  new CSpString ( pEndPeriod ) );	
		return ( PROCEED_WITH_BUILTIN_HANDLING ) ;

		} 

	//	If an error occurs, pull up error page.
	catch ( NullPointerException ex ) 
		{
		callErrorPage( "Error creating dynamic join for period range.") ; 
    		}
	return (PROCEED_WITH_BUILTIN_HANDLING);
	}

	protected int addCriteriaString(String pDataObject, String pNewCriteria)
	{
       	try { 
			CSpSelect vDataObject =
			  (CSpSelect) CSpider.getDataObject ( pDataObject );
			
			// Get Dynamic Criteria
			String s = vDataObject.getDynamicCriteria();
		
			//Set Dynamic Criteria
			vDataObject.setDynamicCriteria ( CSpCriteriaSQLObject.JOIN_CRITERIA_TYPE, s + pNewCriteria);			

			}
	//	If an error occurs, pull up error page.
	catch ( NullPointerException ex ) 
		{
		callErrorPage( "Error creating dynamic join while setting dynamic criteria.") ; 
    	}
	return (PROCEED_WITH_BUILTIN_HANDLING);
	}

} 
