<%
Class CCAPI_TypeUnion

	Private p_localtypeid,p_uniontypeid
	
	Private p_unionindex,p_relationstr
	
	Private regxobj,macthesobj
	
	Public Property Get relationstr
		relationstr=p_relationstr
	End Property 

	Public Property Let relationstr(str_relation)
		if str_relation="" or isnull(str_relation)=true then
			call alertMsg(lang_nullerror,"")
		else
			p_relationstr=str_relation
		end if
	End Property 

	Private Sub Class_Initialize
		
	End Sub
	
	Private Sub Class_Terminate
		p_localtypeid=""
		p_uniontypeid=""
		p_unionindex=""
		p_relationstr=""
		set regxobj=nothing
		set macthesobj=nothing
	End Sub

	Public Function validateNumber(para)
		dim i
		for  i=0 to ubound(split(para,","))
			if isnumeric(split(para,",")(i))=false then
				validateNumber=false
				Exit Function
			end if
		next
		validateNumber=true
	End Function

	Public Function addRelationStr(localid,unionid)
		dim unionstr
		unionstr="<"&localid&">|<"&unionid&">"
		if isnull(p_relationstr)=true or p_relationstr="" then
			p_relationstr=""""&unionstr&""""
		else
			p_relationstr=p_relationstr&","""&unionstr&""""
		end if
	End Function
	
	
	Public Function  getLocalTypeList()
		dim dvbbs_rs,bbstypearray,i,j
		redim getarray(3,1)
		set dvbbs_rs=Dvbbs.iCreateObject("adodb.recordset")
		dvbbs_rs.open "select boardid,boardtype,board_setting from dv_board",conn,1,1
		bbstypearray=dvbbs_rs.getrows()
		dvbbs_rs.close
		set dvbbs_rs=nothing
		j=0
		for i=0 to ubound(bbstypearray,2)
			if split(bbstypearray(2,i),",")(43)=0 then
				redim preserve getarray(3,j)
				getarray(0,j)=bbstypearray(0,i)
				getarray(1,j)=bbstypearray(1,i)
				getarray(2,j)=bbstypearray(2,i)
				j=j+1
			end if
		next
		getLocalTypeList=getarray
	End Function
	
	
	Public Function saveRelationFile()
		 dim configstr
		 configstr="<"&"%"&chr(13)&chr(10)&"dim relation_config_array"&chr(13)&chr(10)&"relation_config_array=array("&p_relationstr&")"&chr(13)&chr(10)&"%"&">"
		 call createHtml("configs/relation_config.asp",configstr)
		 alertMsg lang_relation_array(0),category 
	End Function
	
	Private Function initialRegx(patternstr,str)
		set regxobj=New RegExp
		regxobj.Pattern=patternstr
		regxobj.IgnoreCase=True
		regxobj.Global=True
		set macthesobj=regxobj.Execute(str)
	End Function
	
	Public 	Function  isExistRelation(unionid)
		dim i,j,unionidstr,localid,unionidarray
		for i=0 to ubound(relation_config_array)
			initialRegx  "<(\d*)>\|<(.*)>",relation_config_array(i)
			localid=macthesobj(0).SubMatches(0)
			unionidstr=macthesobj(0).SubMatches(1)
			unionidarray=split(unionidstr,",")
			for j=0 to ubound(unionidarray)
				if cint(unionidarray(j))=cint(unionid) then
					isExistRelation=localid
					Exit Function
				else
					isExistRelation=false
				end if
			next
		next
	End Function 
	
	
	Public 	Function  getAllRelationUnionId()
		dim i,j,unionidstr,singleunionid
		for i=0 to ubound(relation_config_array)
			initialRegx  "<\d*>\|<(.*)>",relation_config_array(i)
			singleunionid=macthesobj(0).SubMatches(0)
			if i=0 then
				unionidstr=singleunionid
			else
				unionidstr=unionidstr&","&singleunionid
			end if
		next
		getAllRelationUnionId=unionidstr	
	End Function
	
	
	Public 	Function  getUnionIdByLocalId(localidstr)
		dim i,unionidstr,localid
		for i=0 to ubound(relation_config_array)
			initialRegx  "<(\d*)>\|<(.*)>",relation_config_array(i)
			localid=macthesobj(0).SubMatches(0)
			unionidstr=macthesobj(0).SubMatches(1)
			if trim(localid)=trim(localidstr) then
				getUnionIdByLocalId=unionidstr
			end if
		next	
	End Function
End Class

%>