<!--#include file="user_top.asp"-->
<!--#include file="inc/class_blog.asp"-->
<script src="inc/function.js" type="text/javascript"></script>
<script>
function chkmove(){
	var mid=read_checkbox('id');
	if (mid==''){
		alert("请选择要移动的相片");
		return false;
	}else{
		document.getElementById('moveid').value=mid;
		return true;
	}
}

</script>
</head>
<body style="overflow-x:hidden;" class="user_iframe">

<%
Dim ssql,i,lPage,lAll,lPages,iPage,sGuide
iPage =15
Dim rs, sql, action
Dim id, cmd, Keyword, sField,subjectid
Keyword = Trim(request("keyword"))
If Keyword <> "" Then
    Keyword = oblog.filt_badstr(Keyword)
End If
sField = Trim(request("Field"))
cmd = Trim(request("cmd"))
action = Trim(request("action"))
id = oblog.filt_badstr(Trim(request("id")))
subjectid=Trim(request("subjectid"))
If cmd = "" Then
    cmd = 0
Else
    cmd = Int(cmd)
End If
If subjectid = "" Then
    subjectid = 0
Else
    subjectid = Int(subjectid)
End If
G_P_FileName = "user_photo.asp?cmd=" & cmd & "&page="
'此处组织纪录集
 ssql = "userid,file_name,file_path,file_size,fileid,file_readme,file_ext,isphoto,logid"
    sGuide = "当前类型:<font color=red><b>"
    Select Case cmd
        Case 0
            sql="select "&ssql&" from [oblog_upfile] where userid="&oblog.l_uid&" and isphoto=1 order by fileid desc"
            sGuide = sGuide & "所有相片"
        Case 1
            sql="select "&ssql&" from [oblog_upfile] where userid="&oblog.l_uid&" and isphoto=1 and userClassId="&subjectid&" order by fileid desc"
            sGuide = sGuide & "分类图片"
        Case Else
    End Select
    Set rs = Server.CreateObject("Adodb.RecordSet")
   rs.open sql, conn, 1, 3
   lAll=INT(rs.recordcount)
	'分页
	If Request("page") = "" Or Request("page") ="0" then
		lPage = 1
	Else
		lPage = Int(Request("page"))
	End If
	
	'设置缓存大小 = 每页需显示的记录数目
	rs.CacheSize = iPage
	rs.PageSize = iPage
	If lAll>0 Then
		rs.movefirst		
		lPages = rs.PageCount
		If lPage>lPages Then lPage=lPages
		rs.AbsolutePage = lPage
	End If
'在后面进行实际的内容显示
%>	
<ul id="user_page_top">
	<li id="p7"><a href="#" onClick="CheckAll(myform,1)">全部选择</a></li>
	<li id="p8"><a href="#" onClick="CheckAll(myform,0)">全部取消</a></li>
	<li id="p4"><a href="#" onclick="if (chk_idBatch(myform,'删除选中的文件吗?')==true) {document.myform.submit();}">文件删除</a></li>
	<li id="p3"><a href="#" onClick="return doMenu('swin3');">移动分类</a></li>
</ul>
<div id="showpage">
<%If lAll>0 Then Response.Write MakeMiniPageBar(lAll,iPage,lPage,G_P_FileName)%>
</div>
<div id="list">
   <div class="list_left">
   	<%
   Dim freesize, maxsize,maxsize1,thisPercent
		maxsize1 = oblog.l_Group(24,0)
		If maxsize1>0 Then
			maxsize = oblog.showsize(maxsize1 * 1024)
			freesize = oblog.showsize(Int(maxsize1*1024 - oblog.l_uUpUsed))
				thisPercent=oblog.l_uUpUsed/(maxsize1*1024)*100
		Elseif maxsize1=0 Then
			maxsize = "不限"
			freesize = "不限"
			thisPercent=0
		Elseif maxsize1=-1 Then
			maxsize = 0
			freesize = 0
			thisPercent=100
		End If
%>

   <form name="myform1" method="post" action="user_photo.asp">
   <select size=1 name='subjectid' onChange='javascript:submit()'>
<%
dim substr,rst
Response.Write "<option value=''>请选择相片分类</option>"
Set rst = oblog.Execute("select subjectid,subjectname from oblog_subject where userid=" & oblog.l_uId & " And subjecttype=1")
While Not rst.EOF
    substr=substr&"<option value="&rst(0)&">"&rst(1)&"</option>"
    rst.Movenext
Wend
Response.Write (substr)
Response.Write "<option value=0>未分类</option>"
set rst=nothing
%>
    </select>
	<input type="hidden" value="1" name="cmd" />
    </form>
	<br />
	<img align=absmiddle src='images/touming.gif' border="1" width='10' height='10' style='background:#cccccc;'>&nbsp;已用空间:<%=oblog.showsize(oblog.l_uUpUsed)%><br />
	<img align=absmiddle src='images/touming.gif' border="1" width='10' height='10' style='background:#ffffff;'>&nbsp;可用空间:<%=freesize%><br />
	<TABLE class="user_space_table" cellSpacing="0" cellPadding="0" width="120" align="center">
  <TBODY>
  <TR>
    <TD class="user_space_used" width="<%=thisPercent%>%" height="12"></TD>
    <TD width="100%"></TD></TR></TBODY></TABLE>
    <p><%=sGuide & "</b></font>"%></p>
</div>
<div class="list_right">
<%
Select Case action
    Case "modifyphoto"
    	Call modify
    Case "savemodify"
    	Call savemodify
    Case "delfile"
    	Call delfile
	case "movephoto"
		call movephoto()
    Case Else
    	Call main()
End Select
Set rs = Nothing
%>
    </div>

<div id="swin1" style="display:none;position:absolute;top:41px;left:10px;z-index:100;"></div>
<div id="swin2" style="display:none;position:absolute;top:41px;left:10px;z-index:100;"></div>
<div id="swin3" style="display:none;position:absolute;top:41px;left:290px;z-index:100;">
<form name="movesub" aciton="user_photo.asp" onSubmit="return chkmove();" method="post">
	<table class='win_table' align='center' border='0' cellpadding='0' cellspacing='1'>
		<tr>
			<td align='center' class='win_table_top'>将选定的相片移动到分类</td>
		</tr>
		<tr>
			<td>
			
			目标分类：<select size="1" name='movesubjectid' >
			<%=substr%>
			</select>
			</td>
		</tr>
		<tr>
			<td class="win_table_end">
			<input type="hidden" name="moveid" value=""/>
			<input type="hidden" name="action" value="movephoto"/>
			<input type="submit" value=" 移动 ">　<input type="button" onClick="return doMenu('swin4');" value=" 关闭 " title="关闭" /> </td>
		</tr>
	</table>
</form>
</div>
<div id="swin4" style="display:none;position:absolute;top:41px;left:10px;z-index:100;"></div>
<div id="swin5" style="display:none;position:absolute;top:41px;left:10px;z-index:100;"></div>
<iframe id="DivShim" scrolling="no" frameborder="0" style="position:absolute;top:0px; left:0px;display:none">
</iframe>
</body>
</html>
<%
Sub main()
    Dim ext
    %>
    <form name="myform" method="post" action="user_photo.asp?action=delfile" onSubmit="return confirm('确定要删除选定的文件吗？');">
    <%
    i=0
    Do while not rs.eof
        ext=rs("file_ext")%>
    <div class="filepic">
    	<div class="fileimg"><a href='<%=rs("file_path")%>' target=_blank>
    		<%	response.Write showfilepic(rs("file_ext"),rs("file_path"),OB_IIF(rs("isphoto"),0))%></a></div>
    <span class="en"><%=oblog.showsize(rs("file_size"))%></span><br />
    <a href="user_files.asp?action=delfile&id=<%=rs("fileid")%>" onclick="return confirm('确定要删除这个文件吗？');">删除</a>
    <br /><input name='id' type='checkbox' id="id" value='<%=cstr(rs("fileid"))%>'><span class="en"><%="<a href="&rs("file_path")&" target=_blank>"&rs("file_name")&"</a>"%></span>
    </div>
<%
    i = i + 1
    If i >= iPage Then Exit Do
    rs.movenext
Loop
%>

    </form>
  </div>
<%
 rs.Close
    Set rs = Nothing
End Sub

function showfilepic(ext,filepath,isPhoto)
	Dim sReturn,sPhoto
	ext=lcase(ext)
	If InStr("jpg,gif,bmp,png,psd",ext) Then sReturn="<img src="""&filepath&""" width=64 height=64 alt=""相片文件""/>"
	showfilepic=sReturn
end function

Sub delfile()
    If id = "" Then
        oblog.adderrstr ("错误：请指定要删除的文件！")
        oblog.showusererr
        Exit Sub
    End If
    If InStr(id, ",") > 0 Then
        Dim n, i
        id = FilterIDs(id)
        n = Split(id, ",")
        For i = 0 To UBound(n)
            delonefile (n(i))
        Next
    Else
        delonefile (id)
    End If
    Set rs = Nothing
    oblog.showok "删除相片成功！", ""
End Sub

Sub delonefile(id)
    id = Int(id)
    Dim userid, filesize, filepath, fso, photofile, isphoto, imgsrc
    sql="select * from [oblog_upfile] where fileid=" & id&" and userid="&oblog.l_uid
    Set rs = Server.CreateObject("adodb.recordset")
    rs.open sql, conn, 1, 3
    If Not rs.EOF Then
        userid = rs("userid")
        filesize = Int(rs("file_size"))
        filepath = rs("file_path")
        photofile = rs("photofile")
        isphoto = rs("isphoto")
        rs.Delete
        rs.Update
        rs.Close
        oblog.execute("update [oblog_user] set user_upfiles_size=user_upfiles_size-"&filesize&" where userid="&userid)
        If filepath <> "" Then
            imgsrc = filepath
            Set fso = Server.CreateObject("Scripting.FileSystemObject")
            If InStr("jpg,bmp,gif,png,pcx", Right(imgsrc, 3)) > 0 Then
                imgsrc = Replace(imgsrc, Right(imgsrc, 3), "jpg")
                imgsrc = Replace(imgsrc, Right(imgsrc, Len(imgsrc) - InStrRev(imgsrc, "/")), "pre" & Right(imgsrc, Len(imgsrc) - InStrRev(imgsrc, "/")))
                If fso.FileExists(Server.MapPath(imgsrc)) Then
                    fso.DeleteFile Server.MapPath(imgsrc)
                End If
            End If
            If fso.FileExists(Server.MapPath(filepath)) Then
                fso.DeleteFile Server.MapPath(filepath)
            End If
            Set fso = Nothing
            End If
    Else
        rs.Close
    End If
    Set rs = Nothing
End Sub

sub movephoto()
	dim id,subjectid
	id=trim(request("moveid"))
    If id = "" Then
        oblog.adderrstr ("请指定要移动的相片")
        oblog.showusererr
        Exit Sub
    End If
    subjectid = Trim(request("movesubjectid"))
    If subjectid = "" Then
        oblog.adderrstr ("请指定要移动的目标分类")
        oblog.showusererr
        Exit Sub
    Else
        subjectid = Int(subjectid)
    End If
    If InStr(id, ",") > 0 Then
        id = FilterIDs(id)
        sql="Update [oblog_upfile] set userclassid="&subjectid&" where fileid in (" & id & ") and userid="&oblog.l_uid
    Else
        sql="Update [oblog_upfile] set userclassid="&subjectid&" where fileid=" & Int(id) &" and userid="&oblog.l_uid
    End If
    oblog.Execute sql
    Set rs = Nothing
    oblog.showok "移动到目标分类成功!", "user_photo.asp?cmd=1&subjectid="&subjectid

end sub
%>