<!-- #include file=../../inc/BBSsetup.asp -->
<!-- #include file=../../inc/Board_popfun.asp -->
<!--#include file="wxzfunction.asp"-->
<%
dim CurItem,ItemName,rsvisual
dim FixType,FixDays,CurType
dim fixfee,CurDate,SendMsg,SucFlag,FixPeriod
Dim FixFee0,FixFee1,New0,New1

WPD_html
WPD_Getconfig
WPD_ScriptSrc(WPD_pluspath&"visual/wxzmain.js")
WPD_checkplususer
WPD_isshowtop=0
WPD_stats="翻新商品"
%>
<!--#include file="z_Visual_const.asp"-->
<%
if not WPD_founduser or WPD_membername=""  then
	SendMsg=SendMsg+"<br>"+"<li>您还没有<a href=login.asp>登录论坛</a>，不能使用个人形象设计功能。如果您还没有<a href=reg.asp>注册</a>，请先<a href=reg.asp>注册</a>！"
	WPD_founderr=true
end if
if isnull(request("itemid")) or request("itemid")="" then
	SendMsg=SendMsg+"<br>"+"<li>没有指定商品编号！"
	WPD_founderr=true
else
	CurItem=WPD_checkstr(request("itemid"))
	if not isnumeric(curitem) then
		SendMsg=SendMsg+"<br>"+"<li>提交的数据有错误！"
		WPD_founderr=true
	end if
end if

if request("action")="fix" then
	if isnull(Request("fixtype")) or Request("fixtype")="" then
		SendMsg=SendMsg+"<br>"+"<li>翻新方式不可为空！"
		WPD_founderr=true
	else
		FixType=WPD_checkstr(Request("fixtype"))
		if not WPD_isInteger(FixType) then
			SendMsg=SendMsg+"<br>"+"<li>翻新方式必须是整数！"
			WPD_founderr=true
		end if
		if cint(FixType)<>0 then FixType=1 else FixType=0
	end if
	if FixType=1 then
		if isnull(Request("fixdays")) or Request("fixdays")="" then
			SendMsg=SendMsg+"<br>"+"<li>翻新天数不可为空！"
			WPD_founderr=true
		else
			FixDays=WPD_checkstr(Request("fixdays"))
			if not WPD_isInteger(FixDays) then
				SendMsg=SendMsg+"<br>"+"<li>翻新天数必须是整数！"
				WPD_founderr=true
			end if
			if clng(FixDays)<=0 or clng(FixDays)>100 then
				SendMsg=SendMsg+"<br>"+"<li>翻新天数必须大于0并小于100！"
				WPD_founderr=true
			end if
			FixDays=clng(FixDays)
		end if
	end if
end if
if WPD_founderr then
	WPD_header "虚拟形象","visual","index.asp"
	call fix_Msg()
else
	set rs=server.createobject("adodb.recordset")
	sql="select top 1 * from visual_items where id="&CurItem
	rs.open sql,conn,1,1
	ItemName=rs("name")
	CurType=rs("type") mod 100
	if CurType>=5 then CurType=4
	set rsvisual=conn.execute("select top 1 new0,new1,period from visual_config")
	new0=rsvisual(0)
	new1=rsvisual(1)
	FixPeriod=rsvisual(2)
	rsvisual.close
	if rs("period")>0 then FixPeriod=rs("Period")
	if FixPeriod<=0 then FixPeriod=30
	if v_myvip<>1 then
		if request("action")="fix" then
			if FixType=0 then
				fixfee=rs("price1")*new0
			else
				fixfee=int(rs("price1")*new1*FixDays/100/FixPeriod+0.99)
			end if
		end if
		fixfee1=rs("price1")/FixPeriod*new1/100
		fixfee0=rs("price1")*new0
	else
		if request("action")="fix" then
			if FixType=0 then
				fixfee=rs("price2")*new0
			else
				fixfee=int(rs("price2")*new1*FixDays/100/FixPeriod+0.99)
			end if
		end if
		fixfee1=rs("price2")/FixPeriod*new1/100
		fixfee0=rs("price2")*new0
	end if
	rs.close
	CurDate=year(now())&"-"&month(now())&"-"&day(now())
	set rs=server.createobject("adodb.recordset")
	sql="select * from visual_myitems where itemid="&CurItem&" and username='"&WPD_membername&"'"
	rs.open sql,conn,1,1
	if rs.bof or rs.eof then
		SendMsg=SendMsg+"<br>"+"<li>您没有这个商品，不能翻新！"
		WPD_founderr=true
	elseif rs("period")=0 then
		SendMsg=SendMsg+"<br>"+"<li>您的这个商品已经是永远有效了，无须再次翻新！"
		WPD_founderr=true
	end if
	rs.close
	set rs=nothing
	if WPD_founderr then
		WPD_header "虚拟形象","visual","index.asp"
		call fix_Msg()
	else
		if request("action")="fix" then
			if WPD_mymoney<fixfee then
				sendmsg=sendmsg+"<br>"+"<li>翻新此商品需要现金 "&fixfee&" 元，您的现金("&WPD_mymoney&" 元)不足，无法翻新！"
				WPD_founderr=true
				WPD_header "虚拟形象","visual","index.asp"
			else
				dim myvisualsplit,TempSplit,CurPeriod
				myvisualsplit=split(v_myvisual,"|")
				set rs=server.createobject("adodb.recordset")
				rs.open "select top 1 * from visual_myitems where username='"&WPD_membername&"' and itemid="&curItem,conn,1,3
				if fixtype=0 then
					rs("period")=0
				else
					if rs("period")-datediff("d",rs("fixdate"),now())>0 then
						rs("period")=rs("period")-datediff("d",rs("fixdate"),now())+fixdays
					else
						rs("period")=fixdays
					end if
				end if
				rs("fixDate")=cdate(curdate)
				if rs("type")=0 then
					rs("type")=CurType
				end if
				rs.update
				rs.close
				set rs=nothing
				call WPD_cutmoney(FixFee,WPD_membername,WPD_bsmoney)
				SendMsg="<li>已经成功地翻新了《<font color=blue>"&itemName&"</font>》，花费了 <font color="&WPD_spcolor&">"&FixFee&"</font> 元！"
				WPD_header "虚拟形象","visual","index.asp"
				response.write "<script>"
				response.write "window.opener.document.execCommand('Refresh');"
				response.write "</script>"
			end if
			call fix_Msg()
		else
			WPD_header "虚拟形象","visual","index.asp"
			%>
			
			<table width="97%" border=0 cellspacing=1 cellpadding=5 align=center bgcolor=<%=DEF_BBS_DarkColor%> class=TBone>
			<form action="?" method=post name=fix>
			<input type=hidden name="action" value="fix">
				<tr bgcolor=<%=DEF_BBS_LightDarkColor%> align=center>
					<td class=TBHead colspan=3>翻新形象商品 -- <%=ItemName%></td>
				</tr>
				<tr bgcolor=<%=DEF_BBS_LightestColor%> class=TBBG9>
					<td  valign=middle><b>翻新方式：</b></td>
					<td  valign=middle><input type=radio name="fixtype" value="1" checked>&nbsp;增加有效期 <input type=text name="fixdays" value=10 size=10> 天</td>
         	<td rowspan=3  valign=middle baseName=images/img_visual_ET/blank.gif width="84" height="84" border="0" itemgender="" itemno=<%=CurItem%> layerno="" localpic=<%=LocalPic%> ImagePath="<%=PicPath%>" style="behavior:url(inc/z_show2.htc)"></td>
				</tr>
				<tr bgcolor=<%=DEF_BBS_LightestColor%> class=TBBG9>
					<td  valign=middle>&nbsp;</td>
					<td  valign=middle><input type=radio name="fixtype" value="0">&nbsp;翻新为永远有效</td>
				</tr>
				<tr bgcolor=<%=DEF_BBS_LightestColor%> class=TBBG9>
					<td  colspan=2><b>说明</b>：<br><font color=<%=WPD_spcolor%>>① 增加一天有效期的费用为：<%=formatnumber(fixfee1,2,-1)%> 元<br>② 翻新该商品为永远有效的费用为：<%=fixfee0%> 元</font><BR>③ 您所拥有的现金为：<%=WPD_mymoney%> 元</td>
				</tr>
				<tr bgcolor=<%=DEF_BBS_LightestColor%> class=TBBG9>
					<td  valign=middle colspan=3 align=center><input type=hidden name=itemid value=<%=CurItem%>><input type=Submit value="确定" name=Submit>&nbsp;<input type="button" name="close" value="关闭" onclick="window.close()"></td>
				</tr>
			</form>
			</table>
		<%end if
	end if
end if
WPD_footer()

sub fix_msg()%>
	<table width="97%" border=0 cellspacing=1 cellpadding=5 align=center bgcolor=<%=DEF_BBS_DarkColor%> class=TBone>
		<tr bgcolor=<%=DEF_BBS_LightDarkColor%> align=center>
			<td class=TBHead width="100%">翻新形象商品信息</td>
		</tr>
		<tr bgcolor=<%=DEF_BBS_LightestColor%> class=TBBG9>
			<td width="100%" ><b>操作结果：</b><br><%
				if WPD_founderr then
					response.write "<font color="&WPD_spcolor&">"
					response.write sendmsg
					response.write "</font>"
				else
					response.write sendmsg
				end if
			%></td>
		</tr>
		<tr bgcolor=<%=DEF_BBS_LightestColor%> class=TBBG9 align=center>
			<td width="100%" ><a href="javascript:window.close()">[关闭窗口]</a><%if request("action")="fix" and WPD_founderr then%>&nbsp;&nbsp;<a href="javascript:history.go(-1)">[返回上页]</a><%end if%></td>
		</tr>
	</table>
<%end sub%>