<!--#include file="admin_start.asp"-->

<%
dim id
dim ids
dim n_ids

id=request("id")
ids=request("ids")
ids=replace(ids," ","")
n_ids=""
set im=MySys.image
Set fso = CreateObject("Scripting.FileSystemObject")

if not MySys.check.isInteger(id) and request("action")="edit" then
MySys.error.info="请选择您要操作的项目！"
MySys.error.location="back"
MySys.error.err()
end if

select case request("action")
case "delete"

	if ids="" then
		MySys.error.info="请选择你要删除的商品！"
		MySys.error.location="back"
		MySys.error.err()
	end if		

	conn.execute("delete from jins_goods_pic_list where goods_id in ("&ids&") ")
	conn.execute("delete from jins_goods_price where goods_id in ("&ids&") ")
	
	set rs_t=conn.execute("select goods_id from jins_goods_list where goods_id in ("&ids&") ")
	do while not rs_t.eof
		if fso.FolderExists(server.mappath("../GOODSPIC/"&rs_t("goods_id"))) then fso.deletefolder server.mappath("../GOODSPIC/"&rs_t("goods_id")),true
	rs_t.movenext
	loop

	conn.execute("delete from jins_goods_list where goods_id in ("&ids&") ")
	
	MySys.error.info="删除商品成功！"
	MySys.error.location="back"
	MySys.error.suc()
	
case else

	if request("action")="add" then
	    sql="select * from jins_goods_list "
	else
	    sql="select * from jins_goods_list  where goods_id="&id&" "
	end if
	
	rs.open sql,conn,1,3
	
	'/////////////////////////////////////////////检测
	
	if request("action")="add" then
	    rs.addnew
		MySys.error.info="商品添加成功！"
	    MySys.error.location="admin/admin_goods_list.asp?order_name=goods_addtime&order_action=desc&s_n=6,sort_id,0&sort_id="&request("sort_id")
	else
		MySys.error.info="商品编辑成功！"
	    MySys.error.location="back"
	end if

	if request("action")="edit" and rs.eof then
		MySys.error.info="您选择的商品不存在！"
		MySys.error.location="back"
		MySys.error.err()
	end if
	
	if conn.execute("select sort_id from jins_goods_sort where sort_id="&request("sort_id")&" ").eof and request("sort_id")>0  then
		MySys.error.info="您选择的商品分类不存在！"
		MySys.error.location="back"
		MySys.error.err()
	end if

	if request("sort_id")="" or request("goods_name")="" or request("goods_open")=""  then 	
		MySys.error.info="请完整填写相关项目！"
		MySys.error.location="back"
		MySys.error.err()
	end if
	
	'////////////////////////////////////////////////////////////////////
	'/////价格
	set rss=server.createobject("adodb.recordset")
	rss.open "select * from jins_goods_price ",conn,1,3
	rss.addnew
	rss("price_addtime")=now()
	rss("goods_id")=id
	set rs_t=conn.execute("select sort_name from jins_customer_sort ")
	do while not rs_t.eof 
	   
	   if MySys.check.DbNameSearch("jins_goods_list","goods_price_"&rs_t("sort_name")) then 
	      if request("goods_price_"&rs_t("sort_name"))<>"" then 
		      rs("goods_price_"&rs_t("sort_name"))=request("goods_price_"&rs_t("sort_name"))
		  else 
		      rs("goods_price_"&rs_t("sort_name"))=0
		  end if
	   end if
		  '/////
	   if request("goods_price_mart")<>"" then rss("price_mart")=request("goods_price_mart") else rss("price_mart")=0
	   if MySys.check.DbNameSearch("jins_goods_price","price_"&rs_t("sort_name")) then 
	      if request("goods_price_"&rs_t("sort_name"))<>"" then 
		      rss("price_"&rs_t("sort_name"))=request("goods_price_"&rs_t("sort_name"))
		  else 
		      rss("price_"&rs_t("sort_name"))=0
		  end if
	   end if
	   
	rs_t.movenext
	loop
	set rs_t=nothing
	
	rss.update
	'rss.close
	'set rss=nothing

	'////商品自定义属性
	if request("n_goods_property")<>"" then
		for iii=0 to request("n_goods_property")
		   s=trim(request("goods_property_"&iii))
		   s=replace(s,",","&")
		   if iii=0 then  rs("goods_property")=s else rs("goods_property")=rs("goods_property")&","&s
		next
	end if
	'/////普通项
	rs("sort_id")=int(request("sort_id"))
	if request("goods_price_mart")<>"" then rs("goods_price_mart")=request("goods_price_mart")
	if request("goods_name")<>"" then rs("goods_name")=trim(request("goods_name"))
	if request("goods_open")<>"" then rs("goods_open")=int(request("goods_open"))	
	if request("goods_unit_deliver")<>"" then rs("goods_unit_deliver")=int(request("goods_unit_deliver"))
	if request("goods_commend")<>"" then rs("goods_commend")=int(request("goods_commend"))	
	if request("goods_special")<>"" then rs("goods_special")=int(request("goods_special"))	
	if request("goods_new")<>"" then rs("goods_new")=int(request("goods_new"))	

	if request("goods_publishtime_year")<>"" then 
		goods_publishtime=trim(request("goods_publishtime_year"))
		if request("goods_publishtime_month")<>"" then 
			goods_publishtime=goods_publishtime&"-"&trim(request("goods_publishtime_month"))
			if request("goods_publishtime_day")<>"" then goods_publishtime=goods_publishtime&"-"&trim(request("goods_publishtime_day"))
		end if
	end if
	rs("goods_publishtime")=goods_publishtime

	rs("goods_unit")=trim(request("goods_unit"))	
	rs("goods_standards")=trim(request("goods_standards"))	
	rs("goods_content")=trim(request("goods_content"))	
	if request("goods_stocks")<>"" then rs("goods_stocks")=int(request("goods_stocks"))	
	if request("goods_rebate")<>"" then rs("goods_rebate")=request("goods_rebate")	
	if request("goods_reward")<>"" then rs("goods_reward")=request("goods_reward")
	
	if request("action")="edit" then
	
		'////////////图片处理
		if rs("goods_pic")<>"" then 
			if request("goods_pic")<>split(rs("goods_pic"),"|")(0) then 
				 if fso.FileExists(server.mappath("../"&split(rs("goods_pic"),"|")(0))) then fso.deletefile server.mappath("../"&split(rs("goods_pic"),"|")(0)),true
			end if
		end if
		
		if rs("goods_picture")<>"" then 
			if request("goods_picture")<>split(rs("goods_picture"),"|")(0) then
			   if fso.FileExists(server.mappath("../"&split(rs("goods_picture"),"|")(0))) then fso.deletefile server.mappath("../"&split(rs("goods_picture"),"|")(0)),true
			end if
		end if
		
		rs("goods_pic")=""
		if request("goods_pic")<>"" then
			ims=im.showimage(server.mappath("../"&request("goods_pic")),90,90)
			rs("goods_pic")=trim(request("goods_pic"))&"|"&ims(0)&"|"&ims(1)
		end if
		
		rs("goods_picture")=""
		if request("goods_picture")<>"" then
			ims=im.showimage(server.mappath("../"&request("goods_picture")),200,200)
			rs("goods_picture")=trim(request("goods_picture"))&"|"&ims(0)&"|"&ims(1)
		end if
		'////////////图片处理end
		
		rs("goods_addtime")=trim(request("goods_addtime"))	
		rs("goods_sellnum")=request("goods_sellnum")	
		rs("goods_clicknum")=request("goods_clicknum")
		
	end if

	rs.update
	
	if request("action")="add" then
	
		'////////////图片处理
		if request("goods_pic")<>"" then
		    if fso.FileExists(server.mappath("../"&request("goods_pic"))) then
		        filename=server.mappath("../"&replace(request("goods_pic"),"$_TEMP_$",rs("goods_id")))
				MySys.check.MakeNewsDir(filename)
				'response.write filename&"<br>"
				fso.copyfile server.mappath("../"&request("goods_pic")),filename
				fso.deletefile server.mappath("../"&request("goods_pic")),true
				
			    ims=im.showimage(filename,90,90)
				
			    rs("goods_pic")=replace(request("goods_pic"),"$_TEMP_$",rs("goods_id"))&"|"&ims(0)&"|"&ims(1)
			end if
		end if
		
		if request("goods_picture")<>"" then
		    if fso.FileExists(server.mappath("../"&request("goods_picture"))) then
		        filename=server.mappath("../"&replace(request("goods_picture"),"$_TEMP_$",rs("goods_id")))
				MySys.check.MakeNewsDir(filename)
				'response.write filename
				fso.copyfile server.mappath("../"&request("goods_picture")),filename
				fso.deletefile server.mappath("../"&request("goods_picture")),true
				
			    ims=im.showimage(filename,90,90)
				
			    rs("goods_picture")=replace(request("goods_picture"),"$_TEMP_$",rs("goods_id"))&"|"&ims(0)&"|"&ims(1)
			end if
		end if
		'response.end

		'////////////图片处理end
		rs("goods_addtime")=now()	
		rs("goods_sellnum")=0	
		rs("goods_clicknum")=0
		
	    rs.update
		rss("goods_id")=rs("goods_id")
        rss.update
	end if
	
	rs.close
	rss.close
	set rss=nothing
	
	Session("FB_EM_1_ACC_uppath")=""

	MySys.error.suc()

	'/////////////////////////////////////////////
end select
set im=nothing
Set fso = nothing

%>
<!--#include file="admin_end.asp"-->
