<%

' ============================================
' 错误返回处理
' ============================================
Sub GoError(str)
	Response.Write "<script language=javascript>alert('" & str & "\n\n系统将自动返回前一页面...');history.back();</script>"
	Response.End
End Sub
'取字串的前n个字符
function gotTopic(str,strlen)
	dim l,t,c, i
	l=len(str)
	t=0
	for i=1 to l
	c=Abs(Asc(Mid(str,i,1)))
	if c>255 then
	t=t+2
	else
	t=t+1
	end if
	if t>=strlen then
	gotTopic=left(str,i)&".."
	exit for
	else
	gotTopic=str
	end if
	next
end function
' ============================================
' 得到安全字符串,在查询中或有必要强行替换的表单中使用
' ============================================
Function GetSafeStr(str)
	GetSafeStr = Replace(Replace(Replace(Trim(str), "'", ""), Chr(34), ""), ";", "")
End Function

' ============================================
' 文件操作函数，调用如下
'filepath=server.mappath("../a.txt")
'call creatfile(filepath,"12345")
' ============================================

 '创建文件
sub creatfile(filePath,nr)
	Set fs=Server.CreateObject("Scripting.FileSystemObject")
	on error resume next  
		Set fout = fs.CreateTextFile(filePath,true) 
		fout.WriteLine nr 
		fout.close 
	set fs=nothing
end sub 


'读取文件
function getfile(filepath)
 	Set fs = CreateObject("Scripting.FileSystemObject") 
 	on error resume next 
     	 set f = fs.OpenTextFile(filepath, 1, True) 
         rdfile=f.ReadAll() 
         getfile=rdfile 
	 	 f.Close 
 	set fs=nothing 
end function 

'文件的删除
sub delfile(filePath) 
 	set fs=server.CreateObject("Scripting.FileSystemObject") 
 	 On Error Resume Next
	 if fs.FileExists(filePath) then
		fs.DeleteFile(filePath)
	 end if
	 Set fs = Nothing
end sub 

' ============================================
'ewebeditor的删除文件函数
' ============================================

Sub DoDelFile(sPathFile)
	On Error Resume Next
	Dim oFSO
	Set oFSO = Server.CreateObject("Scripting.FileSystemObject")
	oFSO.DeleteFile(Server.MapPath(sPathFile))
	Set oFSO = Nothing
End Sub

function getdata(classid,n,m)
	
	sql="select top "&n&" id,title from article where ClassID="& classid &" order by id desc"
	set getrs=server.createobject("adodb.recordset")
	getrs.open sql,conn,1,1
	if getrs.bof then
		str= "暂时还没有信息！"
	else
		str= str & "<ul>" & vbCrLf
		do while not getrs.eof
			jstitle=replace(getrs("title"),chr(32),"")
			jstoptitle=gotTopic(jstitle,m)
			url="article.asp?id=" & getrs("id")
			
			str= str & "<li>·<a title="&chr(34)&jstitle&chr(34)&" href="&chr(34)_
			&url&chr(34)&" target ="&chr(34)&"_blank"&chr(34)&">"&jstoptitle&"</a></li>" & vbCrLf
			getrs.movenext
		 loop 
		 str= str & "</ul>" & vbCrLf
	end if
	getrs.close   
	set getrs=nothing 
	getdata=str
end function

%>