#include <origin.h>
#include <GetNBox.h>
#include <xfutils.h>
//put additional include files here
////////////////////////
// modification log
// CPY 9/25/07 BETTER_ERR_MSG_FOR_INVALID_LICENSE
////////////////////////

#include <..\originlab\fu_utils.h>
/// Hong 08/23/08 v8.0688 FIX_RUNTIME_ERROR_WHEN_LIST_FDF
#ifdef _FOR_SMART_LOADING_ONLY
#include <..\originlab\nlsf_utils.h>
#endif //_FOR_SMART_LOADING_ONLY
/// end FIX_RUNTIME_ERROR_WHEN_LIST_FDF
//put your own support static functions here

typedef BOOL (*FUNC_HWND)(HWND hParent = NULL);



void groupmgr()
{
	
	//------ CPY 9/25/07 BETTER_ERR_MSG_FOR_INVALID_LICENSE
	if(okutil_set_group_server(NULL) ==GSERR_ILLEGAL)
	{
		warning_msg_box(XFWARN_GROUP_CANNOT_USE, true);
		return;
	}
	//------
	
	string strServerName;
	if ( !okutil_is_group_server(NULL, &strServerName) )
	{
		int nErrCode = XFERR_NEED_WORK_ON_GROUP_SERVER;
		if ( strServerName.IsEmpty() )			
			nErrCode = XFERR_GROUP_SERVER_FAIL_SETUP;
			
		///-----Kit 10/22/2010 CLEANUP_XFS_ERROR_CODE
		//warning_msg_box(nErrCode, strServerName, 1, false, 'E', false);
		XF_THROW_EX2(nErrCode, strServerName, 1);
		///-----End CLEANUP_XFS_ERROR_CODE
	}
	else
	{
		string strPath = "OriginLab\\GroupFolderManager.c";
		FUNC_HWND pfn = Project.FindFunction("OpenGroupFolderManager", strPath);
		if (pfn)
			pfn();
	}
}

//nGetNDialog = 0,1,2, corresponding to the XF GetN dropdown, 0 = dialog is not used
//you can change nRet to be one of XFEVT_PROCEED (defualt), XFEVT_ABORT, XFEVT_PROCEED_NO_DLG or XFEVT_PROCEED_WITH_DLG(when nGetNDialog = 0)
//nGetNDialog = -1 when Ok on GetN dialog to allow handler to preocess <auto> etc variables
//dwCntrl is combination of bits
//LTXF_FROM_GUI_MENU, LTXF_FROM_GUI_PROMPT, LTXF_FROM_AUTO_UPDATE, LTXF_FROM_FUNCTION, LTXF_THEME_USED, LTXF_CHANGE_PARAM
void groupmgr_before_execute(TreeNode& trGetN, int nGetNDialog, int& nRet, int dwCntrl)
{
	/// Hong 08/10/07 v8.0679 CLEAN_ERROR_MSG_CODE
	//if(!_is_group_server(true))
	//string strServerName;
	//if ( !okutil_is_group_server(NULL, &strServerName) )
	//{
		//int nErrCode = XFERR_NEED_WORK_ON_GROUP_SERVER;
		//if ( strServerName.IsEmpty() )			
			//nErrCode = XFERR_GROUP_SERVER_FAIL_SETUP;
			//
		//warning_msg_box(nErrCode, strServerName, 1, false, 'E', false);
	//
	///// end CLEAN_ERROR_MSG_CODE
		//nRet = XFEVT_ABORT;
	//}
	//else
	//{	
		//string strFileName = trGetN.fname.strVal;
		//if(0 == nGetNDialog && is_empty_or_unassigned(strFileName))
		//{
			//string strUserFolder = GetAppPath();
			//int nFilesRet = get_open_box_by_file_group(strFileName, "All Files (*.*)*.*", "Select Files For Sharing", true, false, strUserFolder);
			//
		//
			//if ( 0 == nFilesRet )
			//{
				//nRet = XFEVT_ABORT;
				//return;
			//}
			//trGetN.fname.strVal = strFileName;
		//}
	//}
	//string strServerName;
	//if ( !okutil_is_group_server(NULL, &strServerName) )
	//{
		//int nErrCode = XFERR_NEED_WORK_ON_GROUP_SERVER;
		//if ( strServerName.IsEmpty() )			
			//nErrCode = XFERR_GROUP_SERVER_FAIL_SETUP;
			//
		//warning_msg_box(nErrCode, strServerName, 1, false, 'E', false);
	//
		//nRet = XFEVT_ABORT;
	//}
	//else
	//{
		//string strPath = "OriginLab\\GroupFolderManager.c";
		//FUNC_HWND pfn = Project.FindFunction("OpenGroupFolderManager", strPath);
		//if (pfn)
			//pfn();
	//}
	
}
