<!-- #include file="include/skin.asp" -->
<!-- #include file="include/jk_pagecute.asp" -->
<!-- #include file="include/jk_page_cute.asp" -->
<!-- #include file="include/jk_email.asp" -->
<!-- #include file="include/jk_msort.asp" -->
<%
page_power="1.2.3.4.5"
call web_head(2,2,0,0,0)
dim rsort,re_id,rid,ruser,rurl,errs,nummer,nums,rssum,page,viewpage,thepages
nummer=dim_num(26)
nums=nummer
rssum=0
rsort=trim(request.querystring("rsort"))
re_id=trim(request.querystring("re_id"))
rid=trim(request.querystring("rid"))
ruser=trim(request.querystring("ruser"))
rurl=trim(request.querystring("rurl"))
if not joekoe_cms.int_true(re_id) then re_id=0
if not joekoe_cms.int_true(rid) then rid=0
if not symbol_name(ruser) then ruser=""
if var_null(rurl)="" then rurl="./"

select case action
case "delete"
  tit="删除所有评论"
case "del"
  tit="删除一条评论"
case "list"
  tit="所有评论列表"
case "reply"
  tit="回复评论"
case else
  tit="发表评论"
end select

call web_head(0,2,4,0,0)
call msort_start(2)
if not msort_true(rsort) then rsort=""
errs=""

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

call msort_end()
call web_end(0,1)

sub review_delete()
  call review_load(0,0)
  if errs<>"" then
    call review_err(0)
    exit sub
  end if
  sql="delete from review where rsort='"&rsort&"' and re_id="&re_id
  call joekoe_cms.exec(sql,0)
  response.write vbcrlf&joekoe_cms.js_put("alert(""已成功删除（n_sort："&rsort&"，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 review where rsort='"&rsort&"' and re_id="&re_id&" and rid="&rid
  call joekoe_cms.exec(sql,0)
  response.write vbcrlf&joekoe_cms.js_put("alert(""已成功删除了一条评论（n_sort："&rsort&"，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,bgs,rusername,remail,rtype,rtim,retim,reword,pageurl,rip
  isadmin=false
  if int(login_modep)=1 then isadmin=true
  pageurl="?action="&action&"&rsort="&rsort&"&re_id="&re_id&"&"
%>
<table cellspacing=1 cellpadding=4 class=table>
<tr><td class=td0 colspan=2>&nbsp;<%response.write img_skin("m_")&tit%></td></tr>
<%
  sql="select count(rid) from review where rsort='"&rsort&"' and re_id="&re_id
  set rs=joekoe_cms.exec(sql,1)
  if not rs.eof then rssum=rs(0)
  rs.close
  call format_pagecute()
  sql="select top "&nummer*viewpage&" * from review where rsort='"&rsort&"' and re_id="&re_id&" order by rid desc"
  call joekoe_cms.exec("",-1)
  rs.open sql,conn,1,1
  if int(viewpage)>1 then rs.move (viewpage-1)*nummer
  if int(viewpage*nummer)>int(rssum) then nums=nummer-(viewpage*nummer-rssum)
  for i=1 to nums
    bgs=""
    if (ri+1) mod 2=0 then bgs="_td"
    rusername=rs("rusername")
    remail=rs("remail")
    rtype=rs("rtype")
    rtim=rs("rtim")
    retim=rs("retim")
    reword=rs("reword")
    rip=rs("rip")
    if var_null(remail)<>"" then remail="<a href='mailto:"&remail&"'><img src='"&joekoe_cms.web_dir_skin&"small/email.gif' border=0 align=absmiddle alt='"&rusername&" 的电子邮件："&remail&"'></a>"
    if rtype=1 then rusername=format_user_name(rusername,0,"")
    rtim="<font class=tims alt='"&joekoe_cms.time_type(rtim,2)&"'>"&joekoe_cms.time_type(rtim,4)&"</font>"
%>
<tr class=bg<%response.write bgs%>><td>
  <table border=0 cellspacing=0 cellpadding=2 width='100%' class=tf>
  <tr><td class=bw><%response.write img_skin("h_review")
    response.write rtim&"&nbsp;&nbsp;"&rusername&"&nbsp;&nbsp;"&remail
    if login_username=ruser and login_mode<>"" or isadmin then
      response.write "&nbsp;&nbsp;"&review_page("review.asp?action=reply&rsort="&rsort&"&re_id="&re_id&"&rid="&rs("rid")&"&rurl="&server.urlencode(rurl))
    end if
    if isadmin then
       response.write "&nbsp;&nbsp;<a href='review.asp?action=del&rsort="&rsort&"&re_id="&re_id&"&rid="&rs("rid")&"&rurl="&server.urlencode("?"&trim(request.querystring()))&"' onclick=""javascript:return click_return('删除这条评论内容',0);""><img src='skin/"&joekoe_cms.web_skin&"/small/del.gif' border=0 align=absmiddle alt='删除这条评论'></a>&nbsp;&nbsp;<img src='"&joekoe_cms.web_dir_skin&"small/ip.gif' align=absMiddle alt='"&rip&"' border=0>"
    end if
%></td></tr>
  <tr><td class=bw><font class=blue><b>评：</b></font><%response.write joekoe_cms.code_html(rs("rword"),2,0)%></td></tr>
<%
    if var_null(reword)<>"" then
      response.write "  <tr><td class=bw><font class=red2><b>回：</b></font>"&joekoe_cms.code_html(reword,2,0)&"</td></tr>"
    end if
%>
  </table>
</td></tr>
<%
    rs.movenext
    ri=ri+1
  next
  rs.close
  
  

%>
<tr class=bg_tds height=30><td>共有<font class=red><%response.write rssum%></font>条评论&nbsp;页次：<font class=red><%response.write viewpage&"</font>/<font class=red>"&thepages%></font>&nbsp;分页：<% response.write jk_pagecute(nummer,thepages,viewpage,pageurl,3,"#ff0000") %></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='skin/"&joekoe_cms.web_skin&"/small/reply.gif' border=0 align=absmiddle alt='回复这条评论'></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 review where rsort='"&rsort&"' and re_id="&re_id&" and rid="&rid
  call joekoe_cms.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
  if joekoe_cms.chk() then
    reword=joekoe_cms.code_form(request.form("reword"))
    if reword="" then errs=errs&"+回复评论的内容不能为空！"
    if errs<>"" then
      rs.close
      call review_err(1)
      exit sub
    end if
    reword=left(reword,250)
    rs("reword")=reword
    rs("retim")=joekoe_cms.now_time
    rs.update
    rs.close
    response.write vbcrlf&joekoe_cms.js_put("alert(""成功回复了一条评论！\n\n点击返回……"");opener.window.location.reload();window.close();",1)
    exit sub
  end if
  remail=rs("remail")
%>
<table cellspacing=1 cellpadding=4 class=table>
<tr><td class=td0 colspan=2>&nbsp;<%response.write img_skin("m_")&tit%></td></tr>
<tr class=bg_td>
<td width='20%'>评论姓名：</td>
<td width='80%'><%
    if rs("rtype")=1 then
      response.write rs("rusername")
    else
      response.write rs("rusername")
    end if
    if var_null(remail)<>"" then response.write "&nbsp;&nbsp;E-mail："&remail
%></td></tr>
<tr class=bg_td><td>发表时间：</td><td><%response.write joekoe_cms.time_type(rs("rtim"),88)%></td></tr>
<tr class=bg_td valign=top>
<td height=70>评论内容：</td>
<td>
  <table border=0 cellspacing=0 cellpadding=0 width='100%' class=tf>
  <tr><td class=bw><%response.write joekoe_cms.code_html(rs("rword"),2,0)%></td></tr>
  </table>
</td></tr>
<form action='?action=reply&<%response.write "rsort="&server.urlencode(rsort)&"&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=bg_td><td valign=top><br>回复内容：<br><br><=250字</td><td><textarea name=reword rows=6 cols=55><%response.write rs("reword")%></textarea></td></tr>
<tr class=bg_td><td colspan=2 height=30 align=center><input type=submit value='回复评论'>　　<input type=reset value='重新填写'>　　<input type=button value='关闭窗口' onclick="javascript:self.close();"></td></tr>
</form>
</table>
<%
  rs.close
  call web_copy()
end sub

sub review_main()
  dim rusername,remail,rword,rip
  rusername=trim(request.form("rusername"))
  remail=trim(request.form("remail"))
  rword=joekoe_cms.code_form(request.form("rword"))
  rip=user_ip
  call review_load(0,0)
  if not symbol_name(rusername) then errs=errs&"+评论者的姓名不能为空！"
  if remail<>"" and not email_ok(remail,50) then errs=errs&"+评论者的Email格式不对！"
  if rword="" then errs=errs&"+评论的内容不能为空！"
  if errs<>"" then
    call review_err(1)
    exit sub
  end if
  rword=left(rword,250)
  sql="insert into review(username,rsort,re_id,rusername,remail,rword,rtim,rip,rtype) " & _
      "values('"&ruser&"','"&rsort&"',"&re_id&",'"&rusername&"','"&remail&"','"&rword&"','"&joekoe_cms.now_time&"','"&rip&"',"
  if rusername=login_username then
    sql=sql&"1"
  else
    sql=sql&"0"
  end if
  sql=sql&")"
  call joekoe_cms.exec(sql,0)
    call joekoe_cms.exec("insert into user_mail(accept_u,send_u,topic,word,tim,types,isread) values('"&web_dim(3)&"','"&rusername&"','评论管理中有新评论！','评论管理中有新评论,请管理员查阅！','"&joekoe_cms.now_time&"',1,0)",0)
  response.write vbcrlf&joekoe_cms.js_put("alert(""您成功的发表了一条评论！\n\n谢谢您的参与！点击返回..."");location.href='"&rurl&"';",1)
end sub

sub review_load(t1,t2)
  if rsort="" then errs=errs&"+评论的类型好像错了？！"
  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&"+评论的参数有非法值！"
end sub

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

%>