<!-- #include file="include/admin_onlogin.asp" -->
<!-- #include file="include/jk_email.asp" -->
<!-- #include file="include/jk_md5.asp" -->
<%
dim power,pro,tit_name,pro_name,sql_pro,dim_tmp,now_ymd,base_power
power=trim(request.querystring("power"))
pro=trim(request.querystring("pro"))
now_ymd=joekoe_cms.time_type(joekoe_cms.now_time,4)
base_power=format_power2(ubound(dim_user)+1,1)
select case pro
case "hidden"
  pro_name="待审核"
  sql_pro="hidden=0"
case "estate"
  pro_name="计时"
  sql_pro="estate=1"
case "abate"
  pro_name="过期"
  sql_pro="abate=1"
case else
  pro=""
  sql_pro=""
end select
index_url="user"
call admin_master(0,0)
tit_name=ntit
call admin_header(0,0)
%>
<tr><td align=center colspan=2 height=30>
  <table border=0>
  <tr>
  <td><a href='?'><%response.write tit%></a></td>
  <td width=5></td>
  <td><a href='?power=<%response.write power%>&pro=estate'<%if pro="estate" then response.write " class=red"%>>计时<%response.write tit_fir%></a></td>
  <td width=5></td>
  <td><a href='?power=<%response.write power%>&pro=abate'<%if pro="abate" then response.write " class=red"%>>过期<%response.write tit_fir%></a></td>
  <td class=gray>[<a href='?action=abates' onclick="javascript:return click_return('更新所有过期<%response.write tit_fir%>',0);">更新</a>]</td>
  <td width=5></td>
  <td><a href='?power=<%response.write power%>&pro=hidden'<%if pro="hidden" then response.write " class=red"%>>待审核<%response.write tit_fir%></a></td>
  <td class=gray>[<a href='?action=hiddens' onclick="javascript:return click_return('审核所有未审核<%response.write tit_fir%>',0);">审核</a>]</td>
  <td width=5></td>
  <td>
    <table border=0>
    <form action='?' method=get>
    <input type=hidden name=jk_mod value='search'>
    <tr>
    <td><%response.write tit_fir%>搜索：</td>
    <td><input type=text name=keyword value='<%response.write trim(request.querystring("keyword"))%>' size=10 maxlength=20></td>
    <td><select name=sea_type>
<option value='username'<%if trim(request.querystring("sea_type"))="username" then response.write " selected"%>>按用户名</option>
<option value='email'<%if trim(request.querystring("sea_type"))="email" then response.write " selected"%>>按邮件</option>
<option value='nname'<%if trim(request.querystring("sea_type"))="nname" then response.write " selected"%>>按头衔</option>
</select></td>
    <td><input type=submit value='搜索'></td>
    </tr>
    </form>
    </table>
  </td>
  </tr>
  </table>
</td></tr>
<tr><td align=center colspan=2>
  <table border=0>
  <tr>
  <td><%response.write tit_fir%>类型：</td>
<% call joekoe_user_sort() %>
  <td width=10></td>
  <td><a href='?pro=<%response.write pro%>'><b>所有用户</b></a></td>
  </tr>
  </table>
</td></tr>
</table>
<%
if action="handle" then
  if not chk() then action=""
end if

select case action
case "abates"
  call joekoe_chk_abates()
case "hiddens"
  call joekoe_chk_hiddens()
case "handle"
  call joekoe_chk_handle()
case "edit"
  call admin_table(1,1)
  call joekoe_chk_edit()
case else
  call admin_table(1,0)
  call joekoe_chk_main()
end select

if isarray(dim_tmp) then erase dim_tmp
call admin_ender(1)

sub joekoe_chk_abates()
  sql="update user_data set abate=1 where estate=1 and otim<#"&now_ymd&"#"
  call joekoe_cms.exec(sql,0)
  call admin_event("更新所有过期"&tit_fir,0,0)
  call admin_msg("已成功更新了所有过期"&tit_fir&"！","?",1)
end sub

sub joekoe_chk_hiddens()
  sql="update user_data set hidden=1,tmp='' where hidden=0 and len(tmp)=32"
  call joekoe_cms.exec(sql,0)
  call admin_event("审核所有未审核"&tit_fir,0,0)
  call admin_msg("已成功审核了所有过期"&tit_fir&"！","?",1)
end sub

sub joekoe_chk_handle()
  dim sel_type,seltype,sel_id,hdim,hnum,htype,hintegral
  htype=1
  sel_type=trim(request.form("sel_type"))
  select case sel_type
  case "审核","待审核"
    seltype="hidden"
    if sel_type="待审核" then htype=0
  case "计时","取消计时"
    seltype="estate"
    if sel_type="取消计时" then htype=0
  case "过期","取消过期"
    seltype="abate"
    if sel_type="取消过期" then htype=0
  case "锁定","取消锁定"
    seltype="lock"
    if sel_type="取消锁定" then htype=0
  case "删除"
    seltype="delete"
  case else
    sel_type=""
    seltype=""
  end select
  if sel_type="" or seltype="" then
    call admin_msg("您在提交用户操作时出现非法的数据！","?",0)
    exit sub
  end if
  hintegral=mp_integral()
  sel_id=trim(request.form("sel_id"))
  sel_id=replace(sel_id," ","")
  hdim=split(sel_id,",")
  hnum=ubound(hdim)
  for i=0 to hnum
    id=hdim(i)
    if isnumeric(id) then
      select case seltype
      case "delete"
        call user_del(id)
      case "lock"
        sql="update "&data_name&" set popedom=left(popedom,40)+'"&htype&"'+right(popedom,9) where id="&id
        conn.execute(sql)
      case else
        sql="update "&data_name&" set "&seltype&"="&htype&" where id="&id
        conn.execute(sql)
      end select
    end if
  next
  erase hdim
  call admin_event(sel_type&" "&(hnum+1)&"条（"&tit_fir&"）记录",0,0)
  call admin_msg("已成功（"&sel_type&"）操作了"&(hnum+1)&"条"&tit_fir&"记录！","?",1)
end sub

sub user_del(uid)
  dim uuser,ubc,num_topic,num_data
  sql="select top 1 username,bbs_counter from user_data where id="&uid
  set rs=joekoe_cms.exec(sql,1)
  if rs.eof then
    rs.close
    exit sub
  end if
  uuser=rs(0)
  ubc=rs(1)
  rs.close
  if int(ubc)>0 then
    call joekoe_cms.exec("delete from bbs_data where reply_id in (select id from bbs_topic where userid="&uid&")",0)
    call joekoe_cms.exec("delete from bbs_topic where userid="&uid,0)
    call joekoe_cms.exec("update bbs_topic set re_counter=re_counter-1 where id in (select reply_id from bbs_data where userid="&uid&")",0)
    call joekoe_cms.exec("delete from bbs_data where userid="&uid,0)
  end if
  call joekoe_cms.exec("delete from jk_group where username='"&uuser&"'",0)
  call joekoe_cms.exec("delete from user_bookmark where username='"&uuser&"'",0)
  call joekoe_cms.exec("delete from user_friend where username1='"&uuser&"' or username2='"&uuser&"'",0)
  call joekoe_cms.exec("delete from user_mail where send_u='"&uuser&"' or accept_u='"&uuser&"'",0)
  'call joekoe_cms.exec("delete from music_fav where username='"&uuser&"'",0)
  call joekoe_cms.exec("delete from user_data where username='"&uuser&"'",0)
end sub

sub joekoe_chk_edit()
  sql="select top 1 id,username,nname,password,passwd,email,bbs_counter,counter,integral,emoney,remark,face,power,tim,hidden,popedom,estate,abate,otim from user_data where id="&id
  call joekoe_cms.exec("",-1)
  rs.open sql,conn,1,3
  if rs.eof then
    rs.close
    call admin_msg("您要编辑的用户ID（"&id&"）不存在！","?",1)
    exit sub
  end if
  dim username,nname,password,passwd,email,bbs_counter,remark,face,counter,integral,emoney,power,hidden,popedom,estate,abate,otim,p41,p42,p_left,p_right
  dim f_counter,f_integral,f_emoney,f_power,f_otim,t_counter,t_integral,t_emoney,t_power,t_otim
  t_counter=false
  t_integral=false
  t_emoney=false
  t_power=false
  t_otim=false
  username=rs("username")
  password=rs("password")
  passwd=rs("passwd")
  f_counter=rs("counter")
  f_integral=rs("integral")
  f_emoney=rs("emoney")
  f_power=rs("power")
  f_otim=joekoe_cms.time_type(rs("otim"),4)
  popedom=rs("popedom")
  if format_power(f_power,2)=1 then
    if username=web_dim(3) then
      if login_username<>username then
        call admin_msg("您没有编辑的超级管理员的权限！","?pro="&pro&"&power="&power,1)
        exit sub
      end if
    else
      if login_username=username then
        call admin_msg("您没有编辑的自身信息的权限！","?pro="&pro&"&power="&power,1)
        exit sub
      end if
    end if
  end if
  if len(popedom)<>50 then popedom="00000000000000000000000000000000000000000000000000"
  call admin_td("编辑用户（"&username&"）信息")
  if chk() then
    email=code_admin("email",1,50)
    if email_ok(email,50)=false then
      call admin_error(tit_fir&"的 电子邮件（"&email&"） 为空或不符合规则！")
      rs.close
      exit sub
    end if
    bbs_counter=trim(request.form("bbs_counter"))
    if joekoe_cms.int_true(bbs_counter)=false then bbs_counter=0
    counter=trim(request.form("counter"))
    if joekoe_cms.int_true(counter)=false then counter=0
    integral=trim(request.form("integral"))
    if joekoe_cms.int_true(integral)=false then integral=0
    emoney=trim(request.form("emoney"))
    if joekoe_cms.int_true(emoney)=false then emoneyr=0
    power=format_power(code_admin("power",1,10),0)
    remark=joekoe_cms.code_form(trim(request.form("remark")))
    face=joekoe_cms.code_form(trim(request.form("face")))
    if power="" then
      power=base_power
    end if
    hidden=false
    if cstr(code_admin("hidden",1,1))="1" then hidden=true
    estate=0
    if cstr(code_admin("estate",1,1))="1" then estate=1
    abate=false
    if cstr(code_admin("abate",1,1))="1" then abate=true
    otim=trim(request.form("otim"))
    if not(isdate(otim)) or instr(otim,"-")=0 or instr(otim,":")>0 then
      call admin_error(tit_fir&"的 过期时间（"&otim&"） 为空或不符合规则！")
      rs.close
      exit sub
    end if
    otim=joekoe_cms.time_type(otim,4)
    p41=0
    if cstr(code_admin("p41",1,1))="1" then p41=1
    p42=0
    if cstr(code_admin("p42",1,1))="1" then p42=1
    p_left=left(popedom,40)
    p_right=right(popedom,8)
    popedom=cstr(p_left)&cstr(p41)&cstr(p42)&cstr(p_right)
    
    rs("nname")=code_admin("nname",1,20)
    if symbol_ok(code_admin("password",1,20))=true and code_admin("password",1,20)<>password then
      rs("password")=jk_md5(code_admin("password",1,20),"short")
    end if
    if symbol_ok(code_admin("passwd",1,20))=true and code_admin("passwd",1,20)<>passwd then
      rs("passwd")=jk_md5(code_admin("passwd",1,20),"short")
    end if
    rs("email")=email
    rs("bbs_counter")=bbs_counter
    if cstr(f_counter)<>cstr(counter) then
      rs("counter")=counter
      t_counter=true
    end if
    if cstr(f_integral)<>cstr(integral) then
      rs("integral")=integral
      t_integral=true
    end if
    if cstr(f_emoney)<>cstr(emoney) then
      rs("emoney")=emoney
      t_emoney=true
    end if
    if cstr(f_power)<>cstr(power) then
      rs("power")=power
      t_power=true
    end if
    rs("remark")=remark
    rs("face")=face
    rs("hidden")=hidden
    rs("popedom")=popedom
    rs("estate")=estate
    rs("abate")=abate
    if cstr(f_otim)<>cstr(otim) then
      rs("otim")=otim
      t_otim=true
    end if
    rs.update
    rs.close
    call admin_event("编辑"&tit_fir&"（"&username&"）的信息",0,0)
    if t_counter then call admin_event("编辑"&tit_fir&"（"&username&"）系数为："&counter&"，原："&f_counter,0,0)
    if t_integral then call admin_event("编辑"&tit_fir&"（"&username&"）积分为："&integral&"，原："&f_integral,0,0)
    if t_emoney then call admin_event("编辑"&tit_fir&"（"&username&"）货币为："&emoney&"，原："&f_emoney,0,0)
    if t_power then call admin_event("编辑"&tit_fir&"（"&username&"）类型为："&power&"，原："&f_power,0,0)
    if t_otim then call admin_event("编辑"&tit_fir&"（"&username&"）过期时间为："&otim&"，原："&f_otim,0,0)
    call admin_msg("您已成功编辑了"&tit_fir&"（"&username&"）的信息！","?pro="&pro&"&power="&power,0)
    exit sub
  end if
  call form_first()
  power=rs("power")
  hidden=rs("hidden")
  estate=rs("estate")
  abate=rs("abate")
  otim=joekoe_cms.time_type(rs("otim"),4)
  p41=joekoe_cms.popedom_p(popedom,41)
  p42=joekoe_cms.popedom_p(popedom,42)
%>
<form name=user_frm action='?action=edit&pro=<%response.write pro%>&power=<%response.write power%>&id=<%response.write id%>' method=post>
<input type=hidden name=chk value='yes'>
<tr>
<td width='20%'>用户名称：</td>
<td width='20%'><input type=text value='<%response.write username%>' size=20 disabled>&nbsp;不可更改</td>
</tr>
<input type=hidden name=password2 value='<%response.write password%>'>
<input type=hidden name=passwd2 value='<%response.write passwd%>'>
<tr><td>用户密码：</td><td><input type=text name=password value='<%response.write password%>' size=25 maxlength=20></td></tr>
<tr><td>密码钥匙：</td><td><input type=text name=passwd value='<%response.write passwd%>' size=25 maxlength=20></td></tr>
<tr><td>用户头衔：</td><td><input type=text name=nname value='<%response.write rs("nname")%>' size=25 maxlength=20></td></tr>
<tr><td>电子邮件：</td><td><input type=text name=email value='<%response.write rs("email")%>' size=30 maxlength=50></td></tr>
<tr><td>用户系数：</td><td><input type=text name=counter value='<%response.write rs("counter")%>' size=15 maxlength=10>&nbsp;0-10</td></tr>
<tr><td>论坛发贴：</td><td><input type=text name=bbs_counter value='<%response.write rs("bbs_counter")%>' size=15 maxlength=10>&nbsp;贴</td></tr>
<tr><td>用户积分：</td><td><input type=text name=integral value='<%response.write rs("integral")%>' size=15 maxlength=10>&nbsp;分</td></tr>
<tr><td>用户货币：</td><td><input type=text name=emoney value='<%response.write rs("emoney")%>' size=15 maxlength=10>&nbsp;<%response.write web_dim(9)%></td></tr>
<tr><td>用户头像：</td><td><input type=text name=face value='<%response.write rs("face")%>' size=25 maxlength=30></td></tr>
<tr><td>用户签名：</td><td><textarea name=remark rows=10 cols=65><%response.write rs("remark")%></textarea></td>
<tr><td>用户类型：</td><td><select name=power size=1><%
  for i=0 to ubound(dim_user)
    dim_tmp=split(dim_user(i),":")
    response.write vbcrlf&"<option value='"&dim_tmp(0)&"'"
    if power=dim_tmp(0) then response.write " selected"
    response.write ">"&dim_tmp(1)&"（"&dim_tmp(0)&"，系数："&dim_tmp(2)&"）</option>"
  next
%></select>（<%response.write power%>）</td></tr>
<tr><td>注册审核：</td><td><input type=radio name=hidden value='1'<%if hidden=true then response.write " checked"%>>&nbsp;正常&nbsp;&nbsp;<input type=radio name=hidden value='0'<%if hidden=false then response.write " checked"%>>&nbsp;未审核</td></tr>
<tr><td>是否计时：</td><td><input type=radio name=estate value='0'<%if int(estate)<>1 then response.write " checked"%>>&nbsp;普通&nbsp;&nbsp;<input type=radio name=estate value='1'<%if int(estate)=1 then response.write " checked"%>>&nbsp;计时</td></tr>
<tr><td>是否过期：</td><td><input type=radio name=abate value='0'<%if abate=false then response.write " checked"%>>&nbsp;普通&nbsp;<input type=radio name=abate value='1'<%if abate=true then response.write " checked"%>>&nbsp;过期</td></tr>
<tr><td>过期时间：</td><td><input type=text name=otim value='<%response.write otim%>' size=20 maxlength=10>&nbsp;格式：2003-12-25&nbsp;<a href='###' onclick="javascript:document.user_frm.otim.value='<%response.write now_ymd%>';">插入当前时间</a></td></tr>
<tr><td>是否锁定：</td><td><input type=radio name=p41 value='0'<%if int(p41)=0 then response.write " checked"%>>&nbsp;正常&nbsp;&nbsp;<input type=radio name=p41 value='1'<%if int(p41)<>0 then response.write " checked"%>>&nbsp;锁定</td></tr>
<tr><td>论坛屏蔽：</td><td><input type=radio name=p42 value='0'<%if int(p42)=0 then response.write " checked"%>>&nbsp;正常&nbsp;&nbsp;<input type=radio name=p42 value='1'<%if int(p42)<>0 then response.write " checked"%>>&nbsp;屏蔽</td></tr>
<%
  call submit_edit()
  rs.close
end sub

sub joekoe_chk_main()
  call form_first()
%>
<form name=sel_form action='?pro=&power=&action=handle' method=post>
<input type=hidden name=chk value='yes'>
<tr align=center>
<td class=td width='4%'>序号</td>
<td class=td width='14%'><%response.write tit_fir%>名称</td>
<td class=td width='10%'>注册时间</td>
<td class=td width='8%'>登录次数</td>
<td class=td width='10%'>注册IP</td>
<td class=td width='10%'>登录IP</td>
<td class=td width='5%'>类型</td>
<td class=td width='5%'>审核</td>
<td class=td width='4%'><%response.write web_dim(9)%></td>
<td class=td width='6%'>状态</td>
<td class=td width='10%'>过期时间</td>
<td class=td width='5%'>过期</td>
<td class=td width='5%'>锁定</td>
<td class=td width='5%'><input type=checkbox name=sel_all value='yes' onclick="javascript:select_all(this.form);"></td>
</tr>
<%
  dim id,username,n_power,n_powern,popedom,tim,estate,abate,otim,p_lock,keyword,n_nummer
  n_nummer=trim(request.querystring("nummer"))
  if not int_true(n_nummer) then n_nummer=0
  if int(n_nummer)<1 then n_nummer=0
  if int(n_nummer)>0 then
    nummer=n_nummer
    nums=nummer
    pageurl=pageurl&"nummer="&nummer&"&"
  end if
  if power<>"" then
    sql_add=" where power='"&power&"'"
    pageurl=pageurl&"power="&power&"&"
  end if
  if pro<>"" then
    if sql_add="" then
      sql_add=" where "&sql_pro
    else
      sql_add=sql_add&" and "&sql_pro
    end if
    pageurl=pageurl&"pro="&pro&"&"
  end if
  if jk_mod="search" then
    call format_search("username","username,email,nname",2,1)
  end if
  sql="select count(id) from "&data_name&sql_add
  set rs=joekoe_cms.exec(sql,1)
  rssum=rs(0)
  rs.close
  call format_pagecute()
  sql="select top "&nummer*viewpage&" id,username,nname,email,emoney,login_num,last_ip,l_ip,power,tim,hidden,popedom,estate,abate,otim from "&data_name&sql_add&" order by id 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
    id=rs("id")
    username=rs("username")
    n_power=rs("power")
    popedom=rs("popedom")
    tim=rs("tim")
    estate=rs("estate")
    abate=rs("abate")
    otim=rs("otim")
    n_powern=format_power(n_power,2)
    p_lock=joekoe_cms.popedom_p(popedom,41)
%>
<tr align=center>
<td class=tims><a href='user_view.asp?username=<%response.write server.urlencode(username)%>' alt='浏览 <%response.write username%> 的个人信息' target=_blank><%response.write (viewpage-1)*nummer+i%></a></td>
<td align=left><a href='?action=edit&pro=<%response.write pro%>&power=<%response.write n_power%>&id=<%response.write id%>' alt='邮件：<%response.write rs("email")%><br>头衔：<%response.write rs("nname")%><br>点击编辑 <%response.write username%> 的个人信息'><%response.write username%></td>
<td><font class=tims alt='<%response.write joekoe_cms.time_type(tim,2)%>'><%response.write joekoe_cms.time_type(tim,4)%></td><td><font color="#FF0000"><%response.write rs("login_num")%></font>次</td><td><%response.write rs("l_ip")%></td><td><%response.write rs("last_ip")%></td>
<td><img border=0 src='../skin/<%response.write web_dim(7)%>/small/icon_<%response.write format_power(n_power,0)%>.gif' alt='<%response.write username%> 是 <%response.write format_power(n_power,1)%>'></td>
<td><%
    if rs("hidden") then
      response.write "正常"
    else
      response.write "<font class=red2>审核</font>"
    end if
%></td>
<td align=right class=red2><%response.write rs("emoney")%></td>
<td><%
    if int(estate)=1 then
      response.write "<font class=blue>计时</font>"
    else
      response.write "普通"
    end if
%></td>
<td class=tims><%
  if int(estate)=1 then
    if datediff("d",otim,now_ymd)>0 then
      response.write "<font class=red>"
    end if
  end if
  response.write joekoe_cms.time_type(otim,4)
%></td>
<td><%
    if abate then
      response.write "<font class=red>过期</font>"
    else
      response.write "正常"
    end if
%></td>
<td><%
    if int(p_lock)=1 then
      response.write "<font class=red2>锁定</font>"
    else
      response.write "正常"
    end if
%></td>
<td>
<%
   if int(n_powern)>2 then
     response.write "<input type=checkbox name=sel_id value='"&id&"'>"
   else
     response.write "<input type=checkbox name=sel_no disabled>"
   end if
%></td>
</tr>
<%
    rs.movenext
  next
  rs.close
%>
<tr class=tr1>
<td colspan=7>
现有<font class=red><%response.write rssum%></font>位<%response.write tit_fir%>，
页次：<font class=red><%response.write viewpage%></font>/<font class=red><%response.write thepages%></font>
分页：<%response.write jk_pagecute(nummer,thepages,viewpage,pageurl,5,"#ff0000")%>
</td>
<td colspan=4 align=center>
执行
<select name=sel_type size=1>
<option value='审核'>审核</option>
<option value='待审核'>待审核</option>
<option value='计时'>计时</option>
<option value='取消计时'>取消计时</option>
<option value='过期'>过期</option>
<option value='取消过期'>取消过期</option>
<option value='锁定'>锁定</option>
<option value='取消锁定'>取消锁定</option>
<option value='删除'>删除</option>
</select>
<input type=submit value='操作' onclick="return sel_click(this.form);">
</td>
</tr>
</form>
<tr><td colspan=11>建议：当您删除某一用户时请最好进行论坛数据修复以及网站数据更新这两项更新操作，以确保系统能正确的运行。</td></tr>
<%
end sub

sub joekoe_user_sort()
  dim dp
  dp=false
  for i=0 to ubound(dim_user)
    dim_tmp=split(dim_user(i),":")
    response.write vbcrlf&"  <td width=5></td>" & _
		   vbcrlf&"  <td><a href='?pro="&pro&"&power="&dim_tmp(0)&"'"
    if power=dim_tmp(0)then
      dp=true
      tit_name=dim_tmp(1)
      response.write " class=red"
    end if
    response.write ">"&dim_tmp(1)&"</a></td>"
  next
  if dp=false then
    power=""
  end if
end sub
%>