<%@ codepage ="936" %>
<!--#include file="../login/0.asp"-->
<!--#include file="../../mycartconn/conn.asp" -->
<!--#include file="../../mycartconn/Function.asp"-->
<%
dim action
action = server.htmlencode(request("action"))
moliheid = request("moliheid")
cate=request("cate")

If action="tui" Then  '推荐
	conn.execute("update A_slide set tui=1,flag=1 where id="&CLng(moliheid)&"")
	response.redirect "index.asp?action=manage&page="&request("page")&"&lx="&request("lx")&"&key="&request("key")&"&cate="&cate&"&orders="&request("orders")&""
End If

If action="tui_f" Then  '反推荐
	conn.execute("update A_slide set tui=0 where id="&CLng(moliheid)&"")
	response.redirect "index.asp?action=manage&page="&request("page")&"&lx="&request("lx")&"&key="&request("key")&"&cate="&cate&"&orders="&request("orders")&""
End If

If action="shen" Then  '审核
	conn.execute("update A_slide set flag=1 where id="&CLng(moliheid)&"")
	response.redirect "index.asp?action=manage&page="&request("page")&"&lx="&request("lx")&"&key="&request("key")&"&cate="&cate&"&orders="&request("orders")&""
End if

If action="shen_f" Then  '反审核
	conn.execute("update A_slide set flag=0 where id="&CLng(moliheid)&"")
	response.redirect "index.asp?action=manage&page="&request("page")&"&lx="&request("lx")&"&key="&request("key")&"&cate="&cate&"&orders="&request("orders")&""
End If

If action="reset" Then  '重设首页图片

	function MakedownName()
	dim fname
	fname = now()
	fname = replace(fname,"-","")
	fname = replace(fname," ","") 
	fname = replace(fname,":","")
	fname = replace(fname,"PM","")
	fname = replace(fname,"AM","")
	fname = replace(fname,"上午","")
	fname = replace(fname,"下午","")
	fname = int(fname) + int((10-1+1)*Rnd + 1)
	MakedownName=fname
	end function 


	'生成文件夹子程序
	sub add_myfso (wjj)
		set myfso = Server.CreateObject("Scripting.FileSystemObject")
		If myfso.FolderExists(server.MapPath(wjj))=False Then
			myfso.CreateFolder server.MapPath(wjj)
		End If
		set myfso=nothing
	end Sub

	sql="select * from A_slide where id="&CLng(moliheid)&""
	Set rs= Server.CreateObject("ADODB.Recordset")
	rs.open sql,conn,1,3
	If Not (rs.bof And rs.eof) then

		slide_tmp_images = rs("slide_images")
		splitStr="{p}1"
		If InStr(slide_tmp_images,"{p}2")>0 Then splitStr="{p}2"
		If InStr(slide_tmp_images,"{p}3")>0 Then splitStr="{p}3"
		If InStr(slide_tmp_images,"{p}4")>0 Then splitStr="{p}4"

		If InStr(slide_tmp_images,splitStr)>0 Then
			Arrimgs=ubound(Split(slide_tmp_images,splitStr))
			DefPic=Split(slide_tmp_images,splitStr)(0)
			If InStr(DefPic,"{p}")>0 Then
				DefPic=Split(DefPic,"{p}")(1)
			Else
				response.write "抱歉！图片整理出错，请重新制作！<a href='javascript:history.go(-1);'>返回</a>"
				response.end
			End if
		Else
			response.write "抱歉！图片整理出错，请重新制作！<a href='javascript:history.go(-1);'>返回</a>"
			response.end
		End If

		If DefPic<>"" Then    '提取首张图片作为封面图


			If rs("DefPic")<>"" And rs("DefPic")<>"/upload/conver/demo_img_0.jpg" Then
				bh=Split(rs("DefPic"),"/")(3)
			Else
				bh=year(date) & right("00"&month(date),2) & right("00"&day(date),2)
			End If
			
			formPath="/upload/conver/"&bh
			call add_myfso(formPath)

			If InStr(LCase(DefPic),"http://localhost")>0 Then   '是本地图片
				PicPath=Replace(DefPic,"http://localhost","")
				temp1=split(PicPath,"/")
				picFilename=temp1(ubound(temp1))

				'缩图、水印
				ljj=Server.MapPath(PicPath)
				Set Jpeg = Server.CreateObject("Persits.Jpeg")
				Jpeg.Open (ljj)
				'开始变更所有文件扩展名为jpg
				xt=left(picFilename,len(picFilename)-4)
				xt=xt&".jpg"
				'结束文件名变更

				'开始判断哪边为长边，以长边进行缩放
				imgWidth=Jpeg.OriginalWidth
				imgHeight=Jpeg.OriginalHeight

				if imgHeight>imgWidth then 
					Jpeg.Width=120
					Jpeg.Height=Jpeg.OriginalHeight/(Jpeg.OriginalWidth/120)
				end if
				if imgWidth>=imgHeight then 
					Jpeg.Height=120
					Jpeg.Width=Jpeg.OriginalWidth/(Jpeg.OriginalHeight/120)
				end if
				'结束判断

				x=CInt((Jpeg.Width-120)/2)
				y=CInt((Jpeg.Height-120)/2)
				x1=x+120
				y1=y+90
				Jpeg.Canvas.Brush.Color = &HFFFFFF
				Jpeg.Sharpen 1, 125   '锐利处理
				Jpeg.Crop x,y,x1,y1   '切割处理
				Jpeg.Save (Server.MapPath(formPath) & "\" & xt)

				xt=formPath&"/"&xt

				Set Jpeg = Nothing
				
			Else					'是外部图片，则需要下载到本地
				url=DefPic
				fileExt=Right(DefPic,4)

				if int(instr(lcase(DefPic),".asp"))>0 or int(instr(lcase(DefPic),".asa"))>0 then
					response.write "抱歉！图片整理出错，请重新制作！<a href='javascript:history.go(-1);'>返回</a>"
					response.end
				end If
				If LCase(fileExt)<>".jpg" And LCase(fileExt)<>".gif" And LCase(fileExt)<>".png" And LCase(fileExt)<>".bmp" Then
					fileExt=".jpg"
				End if
				set xmlhttp=server.createobject("MSXML2.serverXMLHTTP")
				xmlhttp.open "GET",url,false
				xmlhttp.send()
				if err.number<>0 then err.Clear 
				if xmlhttp.readystate<>4 then
					xt="/upload/conver/demo_img_0.jpg"
				Else
					img=xmlhttp.ResponseBody
					set objAdostream=server.createobject("ADODB.Stream")
					objAdostream.Open()
					objAdostream.type=1
					objAdostream.Write(img)

					If rs("DefPic")<>"" And rs("DefPic")<>"/upload/conver/demo_img_0.jpg" Then
						FileName=Split(rs("DefPic"),"/")(4)
					Else
						FileName=MakedownName()&fileExt
					End If

					set myfso = Server.CreateObject("Scripting.FileSystemObject")
					if myfso.FileExists(server.mappath(formPath&"/"&FileName)) Then
						myfso.DeleteFile(server.mappath(formPath&"/"&FileName))
					End If
					if myfso.FileExists(server.mappath(formPath&"/"&FileName))=false then
						objAdostream.SaveToFile(server.mappath(formPath&"/"&FileName))
						objAdostream.SetEOS
						set objAdostream=nothing
					end if
					saveimg=formPath&"/"&FileName
				end if
				set xmlhttp=Nothing

				If saveimg<>"" then
					'缩图、水印
					ljj=Server.MapPath(saveimg)
					Set Jpeg = Server.CreateObject("Persits.Jpeg")
					Jpeg.Open (ljj)
					xt=FileName
					'结束文件名变更

					'开始判断哪边为长边，以长边进行缩放
					imgWidth=Jpeg.OriginalWidth
					imgHeight=Jpeg.OriginalHeight

					if imgHeight>imgWidth then 
						Jpeg.Width=120
						Jpeg.Height=Jpeg.OriginalHeight/(Jpeg.OriginalWidth/120)
					end if
					if imgWidth>=imgHeight then 
						Jpeg.Height=120
						Jpeg.Width=Jpeg.OriginalWidth/(Jpeg.OriginalHeight/130)
					end if
					'结束判断

					x=CInt((Jpeg.Width-120)/2)
					y=CInt((Jpeg.Height-120)/2)
					x1=x+120
					y1=y+90
					Jpeg.Canvas.Brush.Color = &HFFFFFF
					Jpeg.Sharpen 1, 125   '锐利处理
					Jpeg.Crop x,y,x1,y1   '切割处理
					Jpeg.Save (Server.MapPath(formPath) & "\" & xt)

					xt=formPath&"/"&xt
					Set Jpeg = Nothing
				End if
			End if
		Else
			response.write "抱歉！图片整理出错，请重新制作！<a href='javascript:history.go(-1);'>返回</a>"
			response.end
		End if
		rs("DefPic")=xt
		If saveimg<>"" Then rs("photoNum")=Arrimgs
		rs.update
	End If
	rs.close
	Set rs=Nothing
	response.redirect "index.asp?action=manage&page="&request("page")&"&lx="&request("lx")&"&key="&request("key")&"&cate="&cate&"&orders="&request("orders")&""
End If


If action="del" Then  '删除

	Function noOwner(nstr)
		If nstr<>"" then
			Set rst= Server.CreateObject("ADODB.Recordset")
			sqlt="select count(id) from A_slide where slide_images like '%"&nstr&"%'"
			rst.open sqlt,conn,1,1
			If Not (rst.bof And rst.eof) Then
				If CInt(rst(0))>1 Then 
					noOwner=False
				Else
					noOwner=true
				End if
			Else
				noOwner=true
			End if
		Else
			noOwner=false
		End if
	End Function

	sql="select * from A_slide where id="&CLng(moliheid)&""
	Set rs= Server.CreateObject("ADODB.Recordset")
	rs.open sql,conn,1,3
	If Not (rs.bof And rs.eof) Then

		DefPic = rs("DefPic")     '删除首图
		If DefPic<>"/upload/conver/demo_img_0.jpg" then
			Set fso = Server.CreateObject("Scripting.FileSystemObject")
			strRubbishFile=server.MapPath(DefPic)
			if fso.FileExists(strRubbishFile) then
				fso.DeleteFile(strRubbishFile)
			end if
			set fso=Nothing
		End if


		slide_tmp_images = rs("slide_images")     '删除内展示图
		splitStr="{p}1"
		If InStr(slide_tmp_images,"{p}2")>0 Then splitStr="{p}2"
		If InStr(slide_tmp_images,"{p}3")>0 Then splitStr="{p}3"
		If InStr(slide_tmp_images,"{p}4")>0 Then splitStr="{p}4"


		Arrimgs=Split(slide_tmp_images,splitStr)
		For i=0 To UBound(Arrimgs)-1
			If InStr(LCase(Arrimgs(i)),"http://localhost")>0 Then   '是本地图片
				If InStr(Arrimgs(i),"{p}")>0 Then
					PicPath=Split(Arrimgs(i),"{p}")(1)
					PicPath=Replace(PicPath,"http://localhost","")
				Else
					PicPath=Replace(Arrimgs(i),"http://localhost","")
				End If
				If PicPath<>"" And Not IsNull(PicPath) And PicPath<>"/upload/conver/demo_img_0.jpg"  Then
				  If noOwner(PicPath) then
					Set fso = Server.CreateObject("Scripting.FileSystemObject")
					strRubbishFile=server.MapPath(Replace(PicPath,"http://localhost",""))
					if fso.FileExists(strRubbishFile) then
						fso.DeleteFile(strRubbishFile)
					end if
					set fso=Nothing
				  End if
				End If
			End if
		next
	
		rs.delete
		rs.update

	End If
	rs.close
	Set rs=Nothing

	response.redirect "index.asp?action=manage&page="&request("page")&"&lx="&request("lx")&"&key="&request("key")&"&cate="&cate&"&orders="&request("orders")&""
End If


conn.close
Set conn=Nothing
%>
