<%
sub headAdminCollect(title)%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><%=title%> - 苹果MacCMS</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<link rel="stylesheet" type="text/css" href="../../images/admin.css" />
<link rel="stylesheet" type="text/css" href="../../images/default/easyui.css" />
<link rel="stylesheet" type="text/css" href="../../images/icon.css" />
<script type="text/javascript" src="../../js/jquery.js"></script>
<script type="text/javascript" src="../../js/jquery.validate.js"></script>
<script type="text/javascript" src="../../js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../../js/adm/admin.js"></script>
</head>
<body>
<%end sub

'sType= 0分类1地区2语言
Function ChangeId(sName,sType,PID)
	dim sql,TempArray,i,arrCount
	sql = "Select c_id,c_name,c_toid,c_type,c_pid From tbl_change where c_type="&sType&" and c_name='"&sName&"' "
	TempArray = CJDB.DB(sql,"arr")
	if isArray(TempArray) then arrCount=ubound(TempArray,2) else arrCount=-1
	ChangeId = 0
	for i=0 to arrCount
		if TempArray(4,i) = 0 or TempArray(4,i) = clng(pid) then
			ChangeId = TempArray(2,i)
			exit for
		end if
	next
End Function

Sub makeProjectOptionSelected(id,sep,aid,flag)
	dim sql,rs,strSelected,strstrSpan
	if isnull(id) then id = 0
	sql= "select p_id,p_name from tbl_"&flag&"_project order by p_id asc"
	set rs=CJDB.db(sql,"rs1")
	do while not rs.eof 
		if clng(id)<>0 then strstrSpan=strstrSpan&sep
		if clng(aid)=clng(rs("p_id")) then strSelected=" selected" else strSelected=""
		writeA  "<option value='"&rs("p_id")&"' "&strSelected&">"&strstrSpan&"&nbsp;|—"&rs("p_name")&"</option>"
		rs.movenext
	loop
	if strstrSpan <>""  then strstrSpan = left(strstrSpan,len(strstrSpan)-len(sep))
	CJDB.c(rs)
End Sub


Function DefiniteUrl(Byval PrimitiveUrl,Byval ConsultUrl)
	Dim ConTemp,PriTemp,Pi,Ci,PriArray,ConArray
	If PrimitiveUrl="" or ConsultUrl="" or PrimitiveUrl="$False$" or ConsultUrl="$False$" Then
		DefiniteUrl=False : Exit Function
	End If
	If Left(Lcase(ConsultUrl),7)<>"http://" Then ConsultUrl= "http://" & ConsultUrl
	
	ConsultUrl=replace(ConsultUrl,"\","/") : ConsultUrl=replace(ConsultUrl,"://",":\\")
	PrimitiveUrl=replace(PrimitiveUrl,"\","/")
	
	If Right(ConsultUrl,1)<>"/" Then
		If Instr(ConsultUrl,"/")>0 Then
			
			If Instr(Right(ConsultUrl,Len(ConsultUrl)-InstrRev(ConsultUrl,"/")),".")>0 or Instr(Right(ConsultUrl,Len(ConsultUrl)-InstrRev(ConsultUrl,"/")),"?") then
			Else
				ConsultUrl=ConsultUrl & "/"
			End If
		Else
			ConsultUrl=ConsultUrl & "/"
		End If
	End If
	
	
	ConArray=Split(ConsultUrl,"/")
	If Left(LCase(PrimitiveUrl),7) = "http://" then
		DefiniteUrl=replaceStr(PrimitiveUrl,"://",":\\")
	ElseIf Left(PrimitiveUrl,1) = "/" Then
		DefiniteUrl=ConArray(0) & PrimitiveUrl
	ElseIf Left(PrimitiveUrl,2)="./" Then
		PrimitiveUrl=Right(PrimitiveUrl,Len(PrimitiveUrl)-2)
		If Right(ConsultUrl,1)="/" Then 
			DefiniteUrl=ConsultUrl & PrimitiveUrl
		Else
			DefiniteUrl=Left(ConsultUrl,InstrRev(ConsultUrl,"/")) & PrimitiveUrl
		End If
	ElseIf Left(PrimitiveUrl,3)="../" then
		Do While Left(PrimitiveUrl,3)="../"
			PrimitiveUrl=Right(PrimitiveUrl,Len(PrimitiveUrl)-3)
			Pi=Pi+1
		Loop 
		For Ci=0 to (Ubound(ConArray)-1-Pi)
			If DefiniteUrl<>"" Then
				DefiniteUrl=DefiniteUrl & "/" & ConArray(Ci)
			Else
				DefiniteUrl=ConArray(Ci)
			End If
		Next
		DefiniteUrl= DefiniteUrl & "/" & PrimitiveUrl
	Else
	
	
	
	If Instr(PrimitiveUrl,"/")>0 Then
		PriArray=Split(PrimitiveUrl,"/")
		If Instr(PriArray(0),".")>0 or Instr(PriArray(0),"?")>0  Then
			If Right(PrimitiveUrl,1)="/" Then
				DefiniteUrl="http:\\" & PrimitiveUrl
			Else 
				If Instr(PriArray(Ubound(PriArray)-1),".")>0 Then DefiniteUrl="http:\\" & PrimitiveUrl else DefiniteUrl="http:\\" & PrimitiveUrl & "/"
			End If 
		Else
			If Right(ConsultUrl,1)="/" Then 
				DefiniteUrl=ConsultUrl & PrimitiveUrl
			Else
				DefiniteUrl=Left(ConsultUrl,InstrRev(ConsultUrl,"/")) & PrimitiveUrl
			End If
		End If
	Else
		If Instr(PrimitiveUrl,".")>0 or Instr(PrimitiveUrl,"?")>0 Then
			If Right(ConsultUrl,1)="/" Then
			If right(LCase(PrimitiveUrl),3)=".cn" or right(LCase(PrimitiveUrl),3)="com" or right(LCase(PrimitiveUrl),3)="net" or right(LCase(PrimitiveUrl),3)="org" Then
			DefiniteUrl="http:\\" & PrimitiveUrl & "/"
			Else
			DefiniteUrl=ConsultUrl & PrimitiveUrl
			End If
		Else
			If right(LCase(PrimitiveUrl),3)=".cn" or right(LCase(PrimitiveUrl),3)="com" or right(LCase(PrimitiveUrl),3)="net" or right(LCase(PrimitiveUrl),3)="org" Then
				DefiniteUrl="http:\\" & PrimitiveUrl & "/"
			Else
				DefiniteUrl=Left(ConsultUrl,InstrRev(ConsultUrl,"/")) & "/" & PrimitiveUrl
			End If
		End If
		Else
			If Right(ConsultUrl,1)="/" Then
				DefiniteUrl=ConsultUrl & PrimitiveUrl & "/"
			Else
				DefiniteUrl=Left(ConsultUrl,InstrRev(ConsultUrl,"/")) & "/" & PrimitiveUrl & "/"
			End If 
		End If
	End If
	End If
	If Left(DefiniteUrl,1)="/" then DefiniteUrl=Right(DefiniteUrl,Len(DefiniteUrl)-1)
		
	If DefiniteUrl<>"" Then
		DefiniteUrl=replaceStr(DefiniteUrl,"//","/") : DefiniteUrl=replaceStr(DefiniteUrl,":\\","://")
	Else
		DefiniteUrl=False
	End If
End Function

Function FilterScript(Content,P_Script)
	dim arr,i,rc
	Dim colReg : Set colReg=new RegExp : colReg.IgnoreCase =true :   colReg.Global=True
	If (P_Script and 1)>0 Then Content=ScriptHtml(Content,"iframe",1,colReg)
	If (P_Script and 2)>0 Then Content=ScriptHtml(Content,"object",2,colReg)
	If (P_Script and 4)>0 Then Content=ScriptHtml(Content,"script",2,colReg)
	If (P_Script and 8)>0 Then Content=ScriptHtml(Content,"div",3,colReg)
	If (P_Script and 16)>0 Then Content=ScriptHtml(Content,"class",1,colReg)
	If (P_Script and 32)>0 Then Content=ScriptHtml(Content,"table",3,colReg)
	If (P_Script and 64)>0 Then Content=ScriptHtml(Content,"span",3,colReg)
	If (P_Script and 128)>0 Then Content=ScriptHtml(Content,"img",3,colReg)
	If (P_Script and 256)>0 Then Content=ScriptHtml(Content,"font",3,colReg)
	If (P_Script and 512)>0 Then Content=ScriptHtml(Content,"a",4,colReg)
	If (P_Script and 1024)>0 Then Content=ScriptHtml(Content,"tr",3,colReg)
	If (P_Script and 2048)>0 Then Content=ScriptHtml(Content,"td",3,colReg)
	If (P_Script and 4096)>0 Then Content=htmlFilter(Content)
	
	rc=false
	Content = replaceStr(Content,"&nbsp;"," ")
	Content = replaceStr(Content,"'","''")
	Content = replaceStr(Content,chr(10),"")
	Content = replaceStr(Content,chr(13)," ")
	
	arr = split(content," ") : Content=""
	for i=0 to ubound(arr)
		if not isN(arr(i)) then
			if rc then Content = Content & " "
			Content = Content & arr(i)
			rc=true
		end if
	next
	set arr =nothing
	
	Content = trim(Content)
	FilterScript=Content
	Set colReg=Nothing
End Function

Function ScriptHtml(Byval ConStr,TagName,FType,colReg)
    Select Case FType
    Case 1
       colReg.Pattern="<" & TagName & "([^>])*>"
       ConStr=colReg.replace(ConStr,"")
    Case 2
       colReg.Pattern="<" & TagName & "([^>])*>.*?</" & TagName & "([^>])*>"
       ConStr=colReg.replace(ConStr,"") 
	Case 3
       colReg.Pattern="<" & TagName & "([\s\S]*?)([^>])*>"
       ConStr=colReg.replace(ConStr,"")
       colReg.Pattern="</" & TagName & "([\s\S]*?)([^>])*>"
       ConStr=colReg.replace(ConStr,"")
    Case 4
       colReg.Pattern="<" & TagName & "([\s\S]*?)([^>])*>"
       ConStr=colReg.replace(ConStr," ")
       colReg.Pattern="</" & TagName & "([\s\S]*?)([^>])*>"
       ConStr=colReg.replace(ConStr," ")
    End Select
    ConStr = replace(ConStr,chr(9)," ")
    ConStr = replace(ConStr,chr(10),"")
    ScriptHtml= Trim(ConStr)
End Function


Function SpecialLink(ByVal sLink,ByVal fLink,ByVal rLink)
	Dim t1,t2,i,count,j
	t1=split(fLink,"[变量]") : t2=split(rLink,"[变量]")
	if ( UBound(t1) <1 ) or ( UBound(t1)<> UBound(t2) )then
		SpecialLink=sLink
	else
		dim Reg,matches,Match,rule,tmpval
		Set Reg = New Regexp
		Reg.Global = True
		Reg.IgnoreCase = True
		rule = Join(t1,"([\w\W]+)")
		Reg.Pattern = rule
		Set matches = Reg.Execute(sLink)
		Set Reg = Nothing
		count = matches.count
		For Each Match In matches
			for j=1 to Match.SubMatches.count-1
				if(ubound(t2)>=j) then
					tmpval =  Match.SubMatches(j)
					tmpval = replaceStr(tmpval,"(","")
					SpecialLink = SpecialLink &t2(j-1) & tmpval
					if ( j= Match.SubMatches.count-1) then SpecialLink=SpecialLink& t2(ubound(t2))
				end if
			next
			exit for
		next
		set matches=nothing
	end if
End Function

function regCollect(Byval str,Byval Pattern)
	Dim RegExT
	IF IsN(str) Then Alert "导入出错！"
	Set RegExT= New RegExp
	RegExT.Pattern=Pattern 
	RegExT.IgnoreCase = True
	RegExT.Global = True
	Set regCollect= RegExT.Execute(str)
end function

function replaceFilters(byval strContent,byval projectID,byval sobject)
	dim TempArray,sql,FilterStr,arrCount,i
	sql = "select f_type,f_content,f_rep,f_strstart,f_strend from tbl_filters where f_flag=true and (f_pid=0 or f_pid="&projectID&") and (f_object=0 or f_object="&sobject&")"
	TempArray = cjdb.DB(sql,"arr")
	if isArray(TempArray) then arrCount=ubound(TempArray,2) else arrCount=-1
	for i=0 to arrCount
		if TempArray(0,i) = 1 then 
			strContent = replaceStr(strContent,TempArray(1,i),TempArray(2,i))
		else
			FilterStr = getBody(strContent,TempArray(3,i),TempArray(4,i))
			if FilterStr <> false then
			strContent = replaceStr(strContent,TempArray(3,i),"")
			strContent = replaceStr(strContent,TempArray(4,i),"")
		    strContent = replaceStr(strContent,FilterStr,TempArray(2,i))
		    end if
		end if
	next
	replaceFilters = strContent
end function

sub clearsession
	session("strListCode")=""
	session("strListCodeCut")=""
	session("strViewCode")=""
	session("linkarrcode")=""
end sub

sub clearSessionart
	session("strListCodeart")=""
	session("strListCodeCutart")=""
	session("strViewCodeart")=""
	session("linkarrcodeart")=""
end sub

Function checkFieldCJ(fieldName,tableName)
	dim flag,sql,rsObj,i,ExeResultNum : flag=False : sql="select * from "&tableName 
	set rsObj = CJDB.db (sql,"rs1")
	for i = 0 to rsObj.Fields.Count - 1 
		if rsObj.Fields(i).Name=fieldName then 
			flag=True : Exit For 
		else 
			flag=False 
		end if 
	next 
	checkFieldCJ=flag 
End Function
%>