<!--#include file="conn.asp"-->
<!--#include file="inc/cookies_check.asp"-->
<!--#include file="../include/lebi_config.asp"-->
<%
'*****************************************
'* 软件名称 乐彼网上开店软件(56770 EShop)
'* 软件开发 http://www.56770.com
'* 版权所有 http://www.56770.com
'* 文件名称 Admin_product_pic.asp
'* 最后更新 2012-06-05 by 56770.kingdge
'*****************************************
include "lang/"& LangFilePath &"/lang_sys.inc"
include "lang/"& LangFilePath &"/lang_menu.inc"
include "lang/"& LangFilePath &"/lang_product.inc"
LB_Head()
Response.Write("<style>BODY {BACKGROUND: #fff}</style>")
Select Case Request("action")
	   Case "del" : del()
	   Case "save" : save()
	   Case Else
		    list()
End Select

Sub del
        If OnlyRead = 1 Then OnlyReadMessage()
        on error resume next
        admin_flag=",2.3,"
        if Eshop_Lebi_name="" or instr(","&Eshop_Lebi_flag&",",admin_flag)=0 then
	            adminflag()
        Else
				del_id= Replace(safereplace(Trim(request("d_id"))),"，",",")
				If Right(del_id,1) = "," Then del_id = Left(del_id,Len(del_id)-1)
                if del_id="" then
                        response.write"<SCRIPT language=JavaScript>alert('"& Lang_sys(41) &"');javascript:history.go(-1)</SCRIPT>"
                        response.end
                end If
				id = CheckNum(request("id"),0)
				Set rs = server.CreateObject("adodb.recordset")
				rs.open "select cpic from [Lebi_Product] where id = "& id &"",conn,1,3
				cpic = rs(0)
                For d = 0 To UBound(Split(del_id,","))
                        filepath_pic="../"& PicPath &"/"& Split(del_id,",")(d)
                        path_pic=server.MapPath(filepath_pic)
                        set objfso = server.createobject("scripting.FileSystemObject")
                        If objfso.FileExists(path_pic) then
                                objfso.DeleteFile(path_pic)
				        End If
						cpic = Replace(cpic,"@@"& Split(del_id,",")(d),"")
				Next 
				set objfso = Nothing
				rs(0) = cpic
				rs.update 
				rs.close : Set rs = Nothing 
        		Response.Write("<script>window.parent.document.getElementById('cpic').value='"& cpic &"';parent.$('#windownbg').remove();parent.$('#windown-box').fadeOut('slow',function(){parent.$(this).remove();});</script>")
        End If
End Sub

Sub save()
        admin_flag=",2.2,"
        if Eshop_Lebi_name="" or instr(","&Eshop_Lebi_flag&",",admin_flag)=0 then
	            adminflag()
        Else
				pic = safereplace(request("pic"))
				id = CheckNum(request("id"),0)
				conn.execute("update [Lebi_Product] set cpic = '"& pic &"' where id = "& id &"")
        		Response.Write("<script>window.parent.document.getElementById('cpic').value='"& pic &"';parent.$('#windownbg').remove();parent.$('#windown-box').fadeOut('slow',function(){parent.$(this).remove();});</script>")
        End If
End Sub

Sub list()
admin_flag=",2.2,"
if Eshop_Lebi_name="" or instr(","&Eshop_Lebi_flag&",",admin_flag)=0 then
	    adminflag()
End If
id = CheckNum(request("id"),0)
Set rs = conn.execute("select cpic from [Lebi_Product] where id = "& id &"")
cpic = rs(0)
rs.close : Set rs = Nothing 
%>
<script type="text/javascript" src="inc/js/jquery.dragsort-0.4.min.js"></script>
<script type="text/javascript">
$("ul:first").dragsort();
function tosave()
{   
	var str="";
    var pic = document.getElementsByName("pic");
    var id = document.getElementById("id").value;
	for(k=0;k<pic.length;k++){
		str+="@@"+pic[k].value;
	}
    location="?action=save&pic="+str+"&id="+id;  
}
function todel()
{   
   var i = 0;
   var chkArr = document.getElementsByTagName("input"); 
   var id = document.getElementById("id").value;
   var param = "";   
   for (i=0;i<chkArr.length;i++)   
   if (chkArr[i].checked)   
   param+=chkArr[i].value +",";  
   if (param.length == 0)
   {
       alert("<%=Lang_sys(41)%>");
   }else{
       if(window.confirm("<%=Lang_sys(64)%>")){
           location="?action=del&d_id="+param+"&id="+id;  
       }else return;
   }
}
</script>
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" id="classtable" class="managepic">
<thead>
<form action="?action=del" method="post">
<tr>
<td height="30" class="listhead" align="left">
<input type="image" name="Submit" title=" <%=Lang_sys(1)%> " onclick="location.href='javascript:tosave();';return false;" src="lang/<%=LangFilePath%>/images/bt_app.gif" align="absmiddle">
<input type="image" name="Submit" title=" <%=Lang_sys(15)%> " onclick="location.href='javascript:todel();';return false;" src="lang/<%=LangFilePath%>/images/bt_delete.gif" align="absmiddle">
<input type="hidden" name="id" id="id" value="<%=id%>">
</td>
</tr>
</thead>
<tr>
<td>
<ul id="listpic">
<%
If Left(cpic,2) <> "@@" And Trim(cpic) <> "" Then cpic = "@@"& cpic
For i = 1 To UBound(Split(cpic,"@@"))
%>
<li title="<%=Lang_Product(227)%>"><span class="pic"><img src='../<%= PicPath %>/<%=Split(cpic,"@@")(i)%>'></span><span class="checkbox"><input type="checkbox" name="d_id" value="<%=Split(cpic,"@@")(i)%>"><input type="hidden" name="pic" value="<%=Split(cpic,"@@")(i)%>"></span></li>
<%
Next 
%>
</ul>
<input name="listpicSortOrder" id="listpicSortOrder" type="hidden" />
</td>
</tr>
</form>
</table>
<script type="text/javascript">
$("#listpic").dragsort({ dragSelector: "span", dragBetween: true, dragEnd: saveOrder, placeHolderTemplate: "<li class='placeHolder'><div></div></li>" });
function saveOrder() {
	var data = $("#listpic li").map(function() { return $(this).children().html(); }).get();
	$("input[name=listpicSortOrder]").val(data.join("|"));
};
tdshow("classtable");
</script>
<%
end Sub
%>