<!-- #Include File="../Include/Skin.asp" -->
<!-- #Include File="../Include/Cls_IpSys.asp" -->
<!-- #Include File="../Include/Cls_UbbCode.asp" -->
<!-- #Include file="../Include/Cls_PageCute.asp" -->
<%
'=======================================================
' 欢迎使用《阿赛大型门户网站系统V3.0》，简称“AsaiMHV3”
' 技术支持、商业版咨询、官方唯一指定联系QQ“4941172”
' 官方网站：http://77ya.com      程序负责人：阿赛
'=======================================================

dim re_id,rid,ruser,rurl,errs,rtit,Word_Bad,dim_bad

re_id=Cls.Code_ID("re_id")
rid=Cls.Code_ID("rid")
ChannelIDs=Cls.Code_ID("ChannelIDs")
ruser=Cls.Code_Query("ruser")
rurl=Cls.Code_Query("rurl")
rtit=Cls.Code_Query("rtit")
Word_Bad=Cls.Web_AdsFilter
dim_bad=split(Word_Bad,"|")
if not ChkName(ruser) then ruser=""
if Cls.Is_Null(rurl)="" then rurl="./"

select case action
case "delete"
  tit="删除所有评论"
case "del"
  tit="删除一条评论"
case "list"
  tit= rtit&" - 所有评论列表"
case "reply"
  tit="回复评论"
case else
  tit="发表评论"
end select
call DoWebHead(0,2)
Cls.LoadTemplate(0)
Response.write Cls.ReHtml(ShowWebHead(1),1)
select case action
case "delete"
  call Review_Delete()
case "del"
  call Review_Del()
case "list"
  call Review_List()
case "reply"
  call Review_Reply()
case else
  call Review_Main()
end select
Response.write Cls.ReHtml(ShowWebEnd(1),1)
Call DoWebEnd()

sub Review_Delete()
	call Review_load(0,0)
	if errs<>"" then
		call Review_Err(0)
		exit sub
	End If
	sql="delete from AsaiMHReview where ChannelIDs="&ChannelIDs&" and re_id="&re_id
	call Cls.exec(sql,0)
	if ChannelIDs=10 Then Call Cls.Exec("update AsaiMHblogdata set reply=0 where id="&re_id,0)
	Response.Write vbcrlf&Cls.js_put("alert(""已成功删除（id："&re_id&"）的所有评论内容！\n\n点击返回..."");location.href='"&rurl&"';",1)
End Sub

sub Review_Del()
	call Review_load(1,0)
	if errs<>"" then
		call Review_Err(0)
		exit sub
	End If
	sql="delete from AsaiMHReview where ChannelIDs="&ChannelIDs&" and re_id="&re_id&" and rid="&rid
	call Cls.exec(sql,0)
	if ChannelIDs=10 Then Call Cls.Exec("update AsaiMHblogdata set reply=reply-1 where id="&re_id,0)
	Response.Write vbcrlf&Cls.js_put("alert(""已成功删除了一条评论（id："&re_id&"，rid："&rid&"）内容！\n\n点击返回..."");location.href='"&rurl&"';",1)
End Sub

sub Review_List()
	call Review_load(0,0)
	if errs<>"" then
		call Review_Err(0)
		exit sub
	End If
	dim isadmin,ri,rusername,remail,rtype,rtim,retim,reword,pageurl,reip,rword,RScore
	isadmin=false
	if int(login_modep)=1 or int(login_modep)=2 then isadmin=true
	pageurl="?action="&action&"&ChannelIDs="&ChannelIDs&"&re_id="&re_id&"&"
%>
<table cellspacing=1 cellpadding=4 class=rv_tablew>
<tr><td class=rv_td colspan=2>&nbsp;<%Response.Write img_skin("h_")&tit%></td></tr>
<%
	Dim obj_page
	set obj_page=New Cls_PageCute
	obj_page.nummer=Format_Mid_Num(12)
	obj_page.pageurl=pageurl
	obj_page.page_tit="评论"
	obj_page.page_unit="条"
	obj_page.v_id="rid"
	Call obj_page.p_init("*","AsaiMHReview","ChannelIDs="&ChannelIDs&" and re_id="&re_id,"rid desc")
	sql=obj_page.sql_count
	set rs=Cls.exec(sql,1)
	obj_page.rssum=rs(0)
	rs.close
	call obj_page.p_main("*","AsaiMHReview","ChannelIDs="&ChannelIDs&" and re_id="&re_id,"rid desc")
	for i=1 to obj_page.page_num
	rusername=rs("rusername")
	remail=rs("remail")
	rtype=rs("rtype")
	rtim=rs("rtim")
	retim=rs("retim")
	'rword=rs("rword")
	rword=Ubb.Ubbcode(rs("rword"))
	'reword=rs("reword")
	reword=Ubb.Ubbcode(rs("reword"))
	RScore=rs("RScore")
	reip=ip_types(rs("rip"))
	if rs("ChannelIDs")=10 and rusername=login_username then isadmin=true
	if Cls.Is_Null(remail)<>"" then remail="<a href='mailto:"&remail&"'><img src='"&Cls.Web_SkinDir&"sys/email.gif' border=0 align=absmiddle title='"&rusername&" 的电子邮件："&remail&"'></a>"
	if rtype=1 then rusername=format_user_name(rusername,0,"")
	rtim="<font class=tims>"&Cls.time_type(rtim,1)&"</font>"
%>
<tr class=rv_tr><td>
  <table border=0 cellspacing=1 cellpadding=1 width='100%' class=tf>
  <tr><td width='60%'>
<%
	Response.Write img_skin("h_review")
	Response.Write "&nbsp;"&rusername&"&nbsp;<font class=Gys>["&reip&"] 认为：</font>"
%>
</td><td align=right width='*'>
<%
	Response.Write remail
	if login_username=ruser and login_mode<>"" or isadmin then
		Response.Write "&nbsp;&nbsp;"&Review_page(""&Cls.Web_Dir&"Common/Review.asp?action=reply&ChannelIDs="&ChannelIDs&"&re_id="&re_id&"&rid="&rs("rid")&"&rurl="&server.urlencode(rurl))
	End If
	if isadmin then
		Response.Write "&nbsp;&nbsp;<a href='"&Cls.Web_Dir&"Common/Review.asp?action=del&ChannelIDs="&ChannelIDs&"&re_id="&re_id&"&rid="&rs("rid")&"&rurl="&server.urlencode("?"&trim(request.querystring()))&"' onclick=""javascript:return click_return('删除这条评论内容',0);""><img src='"&Cls.Web_SkinDir&"sys/del.gif' border=0 align=absmiddle title='删除这条评论'></a>"
	End If
	Response.Write "&nbsp;&nbsp;"&rtim
%>
</td></tr>
  <tr><td colspan=2><font class=blue><b>评：</b></font>[<font class=red><%Response.Write rs("RScore")%></font>分]<%Response.Write Cls.code_html(rword,2,0)%></td></tr>
<%
	if Cls.Is_Null(reword)<>"" then
		Response.Write "  <tr><td colspan=2><font class=red2><b>回：</b></font>"&Cls.code_html(reword,2,0)&"</td></tr>"
	End If
%>
  </table>
</td></tr>
<tr class=rv_trline><td></td></tr>
<%
	rs.movenext
	ri=ri+1
	next
	rs.close
%>
<tr class=rv_trp height=30>
<td>
  <table border=0 cellspacing=0 cellpadding=1>
  <tr class=tr1>
  <td><%Response.Write obj_page.page_var%></td>
  <td width=5></td>
  <td>分页：</td>
  <td><%response.write obj_page.page_cute%></td>
  <td width=5></td>
  <%response.write obj_page.page_shortcut%>
  </tr>
  </table>
</td>
</tr>
</table>
<%
	call web_copy()
End Sub

function Review_page(t1)
	dim a
	a="<a href='javascript:;' onclick=""javascript:open_win('"&t1&"','Review_page',500,305,'no');""><img src='"&Cls.Web_SkinDir&"sys/reply.gif' border=0 align=absmiddle title='回复这条评论'></a>"
	Review_page=a
End Function

sub Review_Reply()
	call Review_load(1,0)
	if errs<>"" then
		call Review_Err(0)
		exit sub
	End If
	sql="select top 1 * from AsaiMHReview where ChannelIDs="&ChannelIDs&" and re_id="&re_id&" and rid="&rid
	call Cls.exec("",-1)
	rs.open sql,conn,1,3
	if rs.eof then
		rs.close
		errs=errs&"+评论的ＩＤ不存在！"
		call Review_Err(0)
		exit sub
	End If
	dim remail,reword,rword
	if Cls.chk() then
		reword=Cls.Code_Var(request.form("reword"))
		if reword="" then errs=errs&"+回复评论的 内容 不能为空！"
		for i=0 to ubound(dim_bad)
			if instr(reword,dim_bad(i))>0 or instr(reword,dim_bad(i))>0 then
				errs=errs&"+回复评论的内容含有 违禁 字符！"
			end if
		next
		if errs<>"" then
			rs.close
			call Review_Err(1)
			exit sub
		End If
		reword=left(reword,250)
		rs("reword")=reword
		rs("retim")=Cls.now_time
		rs.update
		rs.close
		Response.Write vbcrlf&Cls.js_put("alert(""成功回复了一条评论！\n\n点击返回……"");opener.window.location.reload();window.close();",1)
		exit sub
	End If
	remail=rs("remail")
	rword=Ubb.Ubbcode(rs("rword"))
	rword=Replace(rword,"<br />","")
%>
<table cellspacing=1 cellpadding=4 class=rv_tablew>
<tr><td class=rv_td colspan=2>&nbsp;<%Response.Write img_skin("h_")&tit%></td></tr>
<tr class=rv_tr>
<td width='20%'>评论姓名：</td>
<td width='80%'>
<%
	if rs("rtype")=1 then
		Response.Write rs("rusername")
	else
		Response.Write rs("rusername")
	End If
	if Cls.Is_Null(remail)<>"" then Response.Write "&nbsp;&nbsp;E-mail："&remail
%>
</td></tr>
<tr  class=rv_tr><td>发表时间：</td><td><%Response.Write Cls.time_type(rs("rtim"),88)%></td></tr>
<tr class=rv_tr valign=top>
<td height=70>评论内容：</td>
<td>
  <table border=0 cellspacing=0 cellpadding=0 width='100%' class=tf>
  <tr><td class=bw><%Response.Write Cls.code_html(rword,2,0)%></td></tr>
  </table>
</td></tr>
<form action='?action=reply&<%Response.Write "ChannelIDs="&ChannelIDs&"&re_id="&re_id&"&rid="&rid&"&rurl="&server.urlencode(rurl)%>' method=post onsubmit="javascript:frm_submitonce(this);">
<input type=hidden name=chk value='yes'>
<tr class=rv_tr ><td valign=top><br />回复内容：<br /><br /><=250字</td><td><textarea class=txtarea name=reword rows=6 cols=55><%Response.Write rs("reword")%></textarea></td></tr>
<tr class=rv_trb ><td colspan=2 height=30 align=center><input type=submit class=btn value='回复评论'>　　<input type=reset class=btn value='重新填写'>　　<input type=button class=btn value='关闭窗口' onclick="javascript:self.close();"></td></tr>
</form>
</table>
<%
	rs.close
	call web_copy()
End Sub

sub Review_Main()
	dim rusername,remail,rword,isscore,RScore,sscore
	rusername=trim(request.form("rusername"))
	remail=trim(request.form("remail"))
  	rword=Cls.Code_Var(request.form("rword"))
    isscore=trim(request.form("isscore"))
    RScore=cint(request.form("RScore"))
    sscore=cint(request.form("sscore"))
	call Review_load(0,0)
	if not ChkName(rusername) then errs=errs&"+评论者的 姓名 不能为空！"
	if Cls.Is_Email(remail,50)=false then errs=errs&"+评论者的 E-mail 为空或不符合邮件规则！"
	if rword="" then errs=errs&"+评论的内容不能为空！"
	for i=0 to ubound(dim_bad)
		if instr(rword,dim_bad(i))>0 or instr(rword,dim_bad(i))>0 then
			errs=errs&"+评论的内容含有 违禁 字符！"
		end if
	next
	if errs<>"" then
		call Review_Err(1)
		exit sub
	End If
    if isscore="yes" and RScore<>"" then
       sql="select RScore from "&Data_Name&" where id="&re_id&""
       set rs=Cls.exec(sql,1)
       RScore=rs(0)
       if RScore="" or isnumeric(sscore)=false then sscore=0
       rs.close
       sscore=sscore+RScore
       sql="update "&Data_Name&" set RScore="&sscore&" where id="&re_id&""
     call Cls.exec(sql,0)
    end if
	rword=left(rword,250)
	if RScore="" or isnumeric(RScore)=false then RScore=0
	sql="insert into AsaiMHReview(username,ChannelIDs,re_id,rusername,remail,rword,rtim,RScore,rtype,rip) " & _
		"values('"&ruser&"',"&ChannelIDs&","&re_id&",'"&rusername&"','"&remail&"','"&rword&"','"&Cls.now_time&"','"&RScore&"',"
	if Is_LoginTrue and rusername=login_username then
		sql=sql&"1"
	else
		sql=sql&"0"
	End If
	sql=sql&",'"&Cls.ip_sys(0)&"')"
	call Cls.exec(sql,0)
	if ChannelIDs=10 Then 
		Call Cls.Exec("update AsaiMHblogdata set reply=reply+1,retim='"&Cls.now_time&"' where id="&re_id,0)
	end if
	Response.Write vbcrlf&Cls.js_put("alert(""您成功的发表了一条评论！\n\n谢谢您的参与！点击返回..."");location.href='"&rurl&"';",1)
End Sub

sub Review_load(t1,t2)
	if int(re_id)<1 then errs=errs&"+评论的类型ＩＤ出错！"
	if t1=1 and int(rid)<1 then errs=errs&"+评论的ＩＤ不能为空！"
	if t2=1 and ruser="" then errs=errs&"+评论的参数有非法值！"
	if action="del" or action="reply" then
		if int(login_modep)<>1 then
			if ChannelIDs=10 then
				sql="Select UserName From AsaiMHReview Where Rid="&rid
				set rs=cls.exec(sql,1)
				if rs("username") <> login_username or  Is_LoginTrue=false then errs=errs&"+没有权限！"
				rs.close
			else
				errs=errs&"+没有权限！"
			end if
		end if
	end if
	if action="delete" and int(login_modep)<>1 then  errs=errs&"+没有权限！"
End Sub

sub Review_Err(retype)
	errs=replace(errs,"+","\n☉ ")
	Response.Write vbcrlf&Cls.js_put("alert(""您提交的表单出现了如下错误：\n"&errs&"\n\n点击返回看看哪里忘记写了…"");",1)
	select case retype
	case 0
		Response.Write vbcrlf&Cls.js_put("self.close();",1)
	case 1
		Response.Write vbcrlf&Cls.js_put("history.back(-1);",1)
	case 2
		Response.Write vbcrlf&Cls.js_put("location.href='"&rurl&"';",1)
	end select
End Sub
%>
