<%
Class AdminClassObj

	Private Sub Class_Initialize() 
		
	End Sub 
	
	Public Sub IsAdminLogin()
		SESSION("BLOG_ADMIN")=Empty
		Session("Blog_Admin_Name")=Empty
		IF REQUEST.FORM("action")="login" Then
			IF NOT CBlogObj.CodeIsTrue() Then
				Response.write"<script>alert('验证码错误');location.href='SysLogin.asp';</script>"
				Response.end
			End IF
			Dim Admin,PassWord
			Admin=CBlogObj.FormRequest("UserName")
			PassWord=calcMD5(CBlogObj.FormRequest("PassWord"))
			SET RS=CONN.EXECUTE("SELECT * FROM Tb_Admin WHERE Blog_Admin_Name='"&Admin&"'")
			IF RS.EOF THEN
				RS.CLOSE:SET RS=NOTHING
				Response.write"<script>alert('用户名或密码错误');location.href='SysLogin.asp';</script>"
				Response.end
			ELSE
				IF RS("Blog_Admin_pass")<>PassWord THEN
					RS.CLOSE:SET RS=NOTHING
					Response.write"<script>alert('用户名或密码错误');location.href='SysLogin.asp';</script>"
					Response.end
				Else
					RS.CLOSE:SET RS=NOTHING
					SESSION("BLOG_ADMIN")="BLOG_ADMIN_SESSION"
					Session("Blog_Admin_Name")=Admin
					RESPONSE.redirect "INDEX.ASP"
					Response.end
				END IF
			END IF
			RS.CLOSE:SET RS=NOTHING
		End IF
	End Sub
	

	Public Sub DelClassCode(Tb,CaheName)
		Dim ClassCode
		IF Request.Form("Act")="del" Then
			ClassCode=Request.Form("ClassCode")
			CONN.EXECUTE "delete from "& Tb &" where classcode like '"& ClassCode &"%'"
			CblogObj.DelCahe(CaheName & "|Class")
			CblogObj.GetHttpUrl ""
		End if
	End Sub

	Public Sub ClassAdd(tb,CaheName,Sys)
		IF request.form("ADD")="add" Then
			Dim classcode,codeq,x,y,w,classname,Code
			classname=replace(trim(request.form("classname")),"'","''")
			Code=replace(trim(request.form("BlogClass")),"'","''")
			if classname="" then
				conn.close:set conn=nothing
				response.write "<script language=JavaScript>" & chr(13) & "alert(' Error:项目名称不能为空! ');" & "history.back()" & "</script>"
				response.end
			end if
			codeq=len(code)+3
			set RS=Conn.Execute("select top 1 * from "& tb &" where len(classcode)="&codeq&" and classcode like '"&code&"%' order by classcode desc")
			if RS.eof and RS.bof then
				classcode=code&"100"
			else
				classcode=RS("classcode")
				x=len(classcode):y=mid(classcode,x-2):y=y+1:w=mid(classcode,1,x-3):classcode=w&y
			end if
			Dim ISDEF
			IF Request.form("DEF")="TRUE" THEN
				ISDEF=1
			Else
				ISDEF=0
			End IF
			IF TB="Tb_Sys_Class" Then
				Conn.Execute("insert into "& tb &" (classcode,classname,ISDEF) values('"&classcode&"','"&classname&"',"&ISDEF&")")
			Else
				Conn.Execute("insert into "& tb &" (classcode,classname) values('"&classcode&"','"&classname&"')")
			End IF
			RS.close:set RS=nothing
			CblogObj.DelCahe(CaheName & "|Class")
			Response.Write "<script language=JavaScript1.1>alert('增加分类成功!');" 
			Response.Write " document.location='"& Sys &"Class_Add.asp';</script>" 
			RESPONSE.END
		End IF
	End Sub
	


	Public Sub ClassList2(Tb,CaheName,Sys)
		Dim Spr,iii,jjj
		IF Not CblogObj.IsCaheEmpty(CaheName) Then
			Set rs=Conn.Execute ("select * FROM "& Tb &" ORDER BY CLASSCODE")
			SqlCount=SqlCount+1
			If Not rs.eof Then
				CblogObj.AddCahe CaheName,Rs.GetRows
			End If
			IF ISOBJECT(RS) Then Rs.Close:Set Rs=Nothing
		End If
		
		IF CblogObj.IsCaheArr(CaheName) Then
				For iii=0 to UBound(CblogObj.Cahe(CaheName),2)
					Spr=""
					For jjj=6 to len(CblogObj.Cahe(CaheName)(0,iii)) Step 3
						Spr=Spr&"┃   "
					Next
					Response.Write (" <input name=""classcode"" type=""radio"" value="&CblogObj.Cahe(CaheName)(0,iii)&">")
					Response.Write (Spr&"┣<a href="& Sys &"Class_update.asp?Id="&CblogObj.Cahe(CaheName)(0,iii)&">"&CblogObj.Cahe(CaheName)(1,iii)&"</a> ")
					Response.Write (CblogObj.Cahe(CaheName)(0,iii) & "<br>")
				Next
		End IF
	End Sub
	
	Public Sub ClassUpdate(tb,CaheName,Sys)
		IF Request.Form("Act")="Update" Then
			Dim ClassName,ID
			ID=CblogObj.FormRequest("ID")
			ClassName=CblogObj.FormRequest("ClassName")
			if ClassName="" then
				  response.write "<script language=JavaScript>" & chr(13) & "alert('Error:分类名不能为空!');" & "history.back()" & "</script>"
				  Response.End
			end if
			IF TB="Tb_Sys_Class" Then
				Dim ISDEF
				IF Request.form("DEF")="TRUE" THEN
					ISDEF=1
				Else
					ISDEF=0
				End IF
				CONN.EXECUTE ("UPDATE "& tb &" Set ClassName='"& ClassName &"',ISDef="& ISDEF &" Where ClassCode='"& ID &"'")
			Else
				CONN.EXECUTE ("UPDATE "& tb &" Set ClassName='"& ClassName &"' Where ClassCode='"& ID &"'")
			End IF
			CblogObj.DelCahe(CaheName & "|Class")
			CblogObj.GetHttpUrl Sys & "Class_List.asp"
		End IF
	End Sub
	
	Private Sub Class_Terminate()

	End Sub 
End Class

SUB PAGElist(PAGECOUNT,PAGE,PSIZE)
Dim j,pa,u,i
	IF pagecount<>0 then
		DIM PAGETEXT
		DIM MAXPAGE,QUERY,A,X,TEMP,PAGEROOT,PAGEFOOT,ACTION
		IF PAGECOUNT MOD PSIZE = 0 THEN
			MAXPAGE = PAGECOUNT \ PSIZE
		ELSE
			MAXPAGE = PAGECOUNT \ PSIZE+1
		END IF
		if MAXPAGE<>1 then
		ACTION = REQUEST.SERVERVARIABLES("SCRIPT_NAME")
		QUERY = Split(Request.ServerVariables("QUERY_STRING"), "&") 
		For Each x In QUERY
			A = Split(x, "=")
			If StrComp(A(0), "page", vbTextCompare) <> 0 Then
				TEMP = TEMP & A(0) & "=" & A(1) & "&"
			End If
		Next
		IF PAGE<5 then
			PAGETEXT=PAGETEXT & " <font face=webdings>9</font> "		
		ELSE		
			PAGETEXT=PAGETEXT & " <A HREF=" & action & "?" & temp & "Page=1 target=""_self"" title=Last Page><font face=webdings>9</font></A> "
		END IF
		PAGEROOT=page-4
		PAGEFOOT=page+5
		if page<5 or page="" then
			PAGEROOT=1
			PAGEFOOT=page+(10-page)
		end if
		if page<5 then
			PAGETEXT=PAGETEXT &" <font face=webdings>7</font> "
		else
			PAGETEXT=PAGETEXT &" <A HREF=" & action & "?" & temp & "Page=" & (page-10) & " target=""_self"" title=Previous 10><font face=webdings>7</font></A> "
		end if
		for j=PAGEROOT to PAGEFOOT
			if page=j then
				IF j=1 then
					pa="  <font color=#CCCCCC><strong>"&j&"</strong></font>"
				else
					pa=" | <font color=#CCCCCC><strong>"&j&"</strong></font>"
				end if
			else
				IF j=1 then
					pa=" <A HREF=" & action & "?" & temp & "Page=" & (j) & " target=""_self""> "&j&" </A>"
				else
					pa=" | <A HREF=" & action & "?" & temp & "Page=" & (j) & " target=""_self""> "&j&" </A>"
				end if
			end if
			
			PAGETEXT=PAGETEXT &pa
			if j=maxpage then 
			j=j+1
			exit for
			end if
		next
		u=10
		if maxpage-page<10 then
			u=maxpage-page
		end if
		if j-1=maxpage then
			PAGETEXT=PAGETEXT &" <font face=webdings>8</font> "
		else
			PAGETEXT=PAGETEXT &" <A HREF=" & action & "?" & temp & "Page=" & (page+u) & " target=""_self"" title=Next 10><font face=webdings>8</font></A> "
		end if
		if page>=maxpage then
			PAGETEXT=PAGETEXT & " <font face=webdings>:</font>" 
		else
			PAGETEXT=PAGETEXT & " <A HREF=" & action & "?" & temp & "Page=" & maxpage & " target=""_self"" title=First Page><font face=webdings>:</font></A> "			
		end if
		response.write(pagetext)
	END if
	End if		
End Sub


Dim AdminObj
Set AdminObj=New AdminClassObj
%>