<!--#include file="../Include/Head.asp"-->
<%
Server.ScriptTimeOut=5000
%>
<style>
.clearmsg{ width:80%; float:left; margin-left:10px; font-size:14px; color:red; line-height:35px;}
.tips{width:100%; float:left; margin-top:10px; padding-left:10px; line-height:24px; color:#666;}
</style>

	<div class="place">
    <span>位置：</span>
    <ul class="placeul">
    <li><a href="../Main/Right.asp">首页</a></li>
    <li><a href="Clear.asp">系统清理</a></li>
    </ul>
    </div>
    
    <div class="formbody">
    
    <div class="tools">  
    	<ul class="toolbar">
        <li class="s1"><a href="?Clear=Photo">清理无效图片</a></li>
        <li class="s1"><a href="?Clear=Files">清理无效文件</a></li>
        <li class="s1"><a href="?Clear=Data">数据库无效记录清理</a></li>
        <li class="s1"><a href="?Clear=Alc">清除缓存</a></li>
        </ul>
    </div>
    
    <%
	'call DelFile("/01web/Upload/Product/01.jpg")
	Action=request_QueryString("Clear")
	Select Case Action
		Case "":Call Default()
		Case "Photo":Call ClearPhoto()
		Case "Files":Call ClearFiles()
		Case "Data":Call ClearData()
		Case "Alc":Call ClearAlc()
	End Select
	
	Sub Default()
		response.Write "<div class=clearmsg>提示：若空间图片文件较多，则页面反应时间可能过久，请耐心等待！</div>"
	End Sub
	Sub ClearPhoto()
		'1-Article  2-Banner  3-Image  4-Links  5-Product  6-SysSet  7-Others
		ClearPhoto_Do(Server.MapPath("../../Upload/Article/")) 
		ClearPhoto_Do(Server.MapPath("../../Upload/Banner/"))
		'ClearPhoto_Do(Server.MapPath("../../Upload/Image/"))
		ClearPhoto_Do(Server.MapPath("../../Upload/Links/"))
		ClearPhoto_Do(Server.MapPath("../../Upload/Product/"))
		ClearPhoto_Do(Server.MapPath("../../Upload/SysSet/"))
		'ClearPhoto_Do(Server.MapPath("../../Upload/Others/"))
		response.Write "<div class=clearmsg>提示：无效图片清理成功！</div>"
	End Sub
	Sub ClearFiles()
		ClearFiles_Do(Server.MapPath("../../Upload/")) '调用遍历函数
		response.Write "<div class=clearmsg>提示：无效文件清理成功！</div>"
	End Sub
	Sub ClearData()
		conn.execute "delete from [Jin_Article] Where Title=''"
		conn.execute "delete from [Jin_Flash] Where Title=''"
		conn.execute "delete from [Jin_Photos] Where Title=''"
		conn.execute "delete from [Jin_Jobs] Where Position=''"
		conn.execute "delete from [Jin_Links] Where Title=''"
		conn.execute "delete from [Jin_Page] Where Title=''"
		conn.execute "delete from [Jin_Resume] Where rName=''"
		response.Write "<div class=clearmsg>提示：无效数据库记录清理成功！</div>"
	End Sub
	Sub ClearAlc()
	Application.Contents.RemoveAll()
	response.Write "<div class=clearmsg>提示：缓存对象更新完毕！</div>"
	End Sub
	%>
    
    <div class="tips">
    无效图片/文件：空间文件夹中存在的但数据库无记录的图片/文件。<br />
    无效数据库记录：某些关键字段为空的数据记录。<br />
    </div>
    
<%
'清理图片=========
'FFFF:  1-Article  2-Banner  3-Image  4-Links  5-Product  6-SysSet  7-Others
Function ClearPhoto_Do(Path) '遍历递归搜索所有文件
	If Instr(Path,"Article")>0 Then FFFF=1
	If Instr(Path,"Banner")>0 Then FFFF=2
	If Instr(Path,"Image")>0 Then FFFF=3
	If Instr(Path,"Links")>0 Then FFFF=4
	If Instr(Path,"Product")>0 Then FFFF=5
	If Instr(Path,"SysSet")>0 Then FFFF=6
	If Instr(Path,"Others")>0 Then FFFF=7
	Dim Fso,ObjFolder,ObjFile 'Fso对象,子目录对象,文件对象
	Set Fso=Server.CreateObject("scripting.filesystemObject") '创建FSO读写对象
	
	For Each ObjFile in Fso.GetFolder(Path).Files '读取当前目录下的文件
		'Response.Write Path & "\" & ObjFile.Name & " - Size:" & ObjFile.Size & " Bytes<BR>" & Vbcrlf
		'仅获取图片文件
		If getExt(objFile.name)="gif" or getExt(objFile.name)="bmp" or getExt(objFile.name)="png" or getExt(objFile.name)="jpg" or getExt(objFile.name)="jpeg" Then  
		'Response.Write  ObjFile.Name &"<BR>" & Vbcrlf
			'数据库对比
			If Instr(ObjFile.Name,Web_EndFlag)=0 Then	'略缩图不清理
				Select case FFFF
					Case 1
						If (IsPicInTb(ObjFile.Name,"Jin_Article","Pic")=false and IsPicInTb(ObjFile.Name,"Jin_Article","Content")=false and IsPicInTb(ObjFile.Name,"Jin_Page","PageBg")=false and IsPicInTb(ObjFile.Name,"Jin_Page","Pic")=false and IsPicInTb(ObjFile.Name,"Jin_Page","Pic_a")=false) then
						Response.Write  web_root & sub_str(Path & "/" & ObjFile.Name,"Upload")&"已被删除。<br>"
						Response.Flush
						DelFile( web_root & sub_str(Path & "/" & ObjFile.Name,"Upload") )
						End If
					Case 2
						If (IsPicInTb(ObjFile.Name,"Jin_Flash","Pic")=false) then
						Response.Write  web_root & sub_str(Path & "/" & ObjFile.Name,"Upload")&"已被删除。<br>"
						Response.Flush
						DelFile( web_root & sub_str(Path & "/" & ObjFile.Name,"Upload") )
						End If
					Case 3
					Case 4
						If (IsPicInTb(ObjFile.Name,"Jin_Links","Logo")=false) then
						Response.Write  web_root & sub_str(Path & "/" & ObjFile.Name,"Upload")&"已被删除。<br>"
						Response.Flush
						DelFile( web_root & sub_str(Path & "/" & ObjFile.Name,"Upload") )
						End If
					Case 5
						If (IsPicInTb(ObjFile.Name,"Jin_Photos","Pic")=false and IsPicInTb(ObjFile.Name,"Jin_Photos","Pic_a")=false and IsPicInTb(ObjFile.Name,"Jin_Photos","Content")=false and IsPicInTb(ObjFile.Name,"Jin_Photos","Content_a")=false) then
						Response.Write  web_root & sub_str(Path & "/" & ObjFile.Name,"Upload")&"已被删除。<br>"
						Response.Flush
						DelFile( web_root & sub_str(Path & "/" & ObjFile.Name,"Upload") )
						End If
					Case 6
						If (IsPicInTb(ObjFile.Name,"Jin_Config","Web_Logo")=false and IsPicInTb_a(ObjFile.Name,"Jin_Class","Content")=false and IsPicInTb_a(ObjFile.Name,"Jin_Class","Pic")=false) then
						Response.Write  web_root & sub_str(Path & "/" & ObjFile.Name,"Upload")&"已被删除。<br>"
						Response.Flush
						DelFile( web_root & sub_str(Path & "/" & ObjFile.Name,"Upload") )
						End If
				End Select
			End If
		End If
	Next
	
	'For Each ObjFolder In Fso.GetFolder(Path).SubFoldeRs '读取子目录
	'	ClearPhoto_Do(Path & "\" & ObjFolder.Name) '调用递归搜索子目录完整路径
	'Next
End Function
'清理文件=========
Function ClearFiles_Do(Path) '遍历递归搜索所有文件
	Dim Fso,ObjFolder,ObjFile 'Fso对象,子目录对象,文件对象
	Set Fso=Server.CreateObject("scripting.filesystemObject") '创建FSO读写对象
	
	For Each ObjFile in Fso.GetFolder(Path).Files '读取当前目录下的文件
		If getExt(objFile.name)="doc" or getExt(objFile.name)="docx" or getExt(objFile.name)="xls" or getExt(objFile.name)="xlsx" or getExt(objFile.name)="ppt" or getExt(objFile.name)="pptx" or getExt(objFile.name)="pdf" or getExt(objFile.name)="txt" or getExt(objFile.name)="rar" or getExt(objFile.name)="zip" or getExt(objFile.name)="tar" or getExt(objFile.name)="7z" or getExt(objFile.name)="swf" or getExt(objFile.name)="flv" Then  
			'数据库对比
			If ( IsPicInTb(ObjFile.Name,"Jin_Article","Content")=false and IsPicInTb(ObjFile.Name,"Jin_Photos","Content")=false and IsPicInTb(ObjFile.Name,"Jin_Page","Content")=false) then
			Response.Write  web_root & sub_str(Path & "/" & ObjFile.Name,"Upload")&"已被删除。<br>"
			Response.Flush
			DelFile( web_root & sub_str(Path & "/" & ObjFile.Name,"Upload") )
			End If
		End If
	Next
	
	For Each ObjFolder In Fso.GetFolder(Path).SubFoldeRs '读取子目录
		ClearFiles_Do(Path & "\" & ObjFolder.Name) '调用递归搜索子目录完整路径
	Next
End Function
'ClearPhoto_Do(Server.MapPath("../../Upload/Image/")) '清理无效图片

%>
    </div>


<%
'Response.Write "<br><br><br>页面执行时间：" & FormatNumber((Timer()-startime)*1000,3) & "毫秒"
'///////获取文件类型 
Function getExt(str) 
getExt = Lcase(Right(str,Len(str)-InstrRev(str,"."))) 
End Function 

'///////判断图片在表中是否存在
Function IsPicInTb(pic,tb,zd)
	Set Rs_pic=server.CreateObject("adodb.recordSet")
	Sql_pic="select "&zd&",SysID from "&tb&" where "&zd&" like '%"&pic&"%' order by SysID desc"
	Rs_pic.open Sql_pic,conn,1,1
	If(Rs_pic.eof and Rs_pic.bof)then : IsPicInTb=false : else : IsPicInTb=true : End If
	Rs_pic.close : Set Rs_pic=nothing
End Function
'专门针对Jin_Class
Function IsPicInTb_a(pic,tb,zd)
	Set Rs_pic=server.CreateObject("adodb.recordSet")
	Sql_pic="select "&zd&",ID from "&tb&" where "&zd&" like '%"&pic&"%' order by ID desc"
	Rs_pic.open Sql_pic,conn,1,1
	If(Rs_pic.eof and Rs_pic.bof)then : IsPicInTb_a=false : else : IsPicInTb_a=true : End If
	Rs_pic.close : Set Rs_pic=nothing
End Function

'///////删除文件代码
'DelFile("/Upload/Image/201501/16113611.jpg")
Function DelFile(FileName)
	Dim getPath
	getPath="/"
	SET Fsoa=Server.CreateObject("Scripting.FileSystemObject")
	getPath=Replace(getPath&FileName,"//","/")
	if Fsoa.FileExists(Server.MapPath(getPath))=True then
	Fsoa.DeleteFile Server.mappath(getPath)
	End if
	Set Fsoa=Nothing
End Function

 '遍历递归搜索所有文件
'BianLia(Server.MapPath("../../Upload")) '调用遍历函数
Function BianLia(Path)
	Dim Fso,ObjFolder,ObjFile 'Fso对象,子目录对象,文件对象
	Set Fso=Server.CreateObject("scripting.filesystemObject") '创建FSO读写对象
	
	For Each ObjFile in Fso.GetFolder(Path).Files '读取当前目录下的文件
		'Response.Write Path & "\" & ObjFile.Name & " - Size:" & ObjFile.Size & " Bytes<BR>" & Vbcrlf
		'仅获取图片文件
		If getExt(objFile.name)="gIf" or getExt(objFile.name)="bmp" or getExt(objFile.name)="png" or getExt(objFile.name)="jpg" or getExt(objFile.name)="jpeg" Then  
		Response.Write Path & "\" & ObjFile.Name &"<BR>" & Vbcrlf
		End If
	Next
	
	For Each ObjFolder In Fso.GetFolder(Path).SubFoldeRs '读取子目录
		BianLia(Path & "\" & ObjFolder.Name) '调用递归搜索子目录完整路径
	Next
End Function
%>

<%Call BackFoot()%>