<!-- #include file="include/admin_onlogin.asp" -->
<%
dim v_wid,v_hei
v_wid=400
v_hei=300
index_url="vote"
call admin_master(0,0)
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=10></td>
  <td><a href='?action=add'>添加新<%response.write tit_fir%></a></td>
  </tr>
  </table>
</td></tr>
</table>
<%
call admin_table(1,1)

select case action
case "handle"
  call joekoe_chk_handle()
case "edit"
  call joekoe_chk_edit()
case "add"
  call joekoe_chk_add()
case "view"
  call joekoe_chk_view()
case else
  call joekoe_chk_main()
end select

call admin_ender(1)

sub joekoe_chk_handle()
  dim sel_type,seltype,sel_id,hdim,hnum,hid,hi,htype,hintegral
  htype=1
  sel_type=trim(request.form("sel_type"))
  select case sel_type
  case "删除"
    seltype="delete"
  case else
    sel_type=""
    seltype=""
  end select
  if joekoe_cms.post_chk()=false or seltype="" then exit sub
  hintegral=mp_integral()
  sel_id=trim(request.form("sel_id"))
  sel_id=replace(sel_id," ","")
  hdim=split(sel_id,",")
  hnum=ubound(hdim)
  select case seltype
  case "delete"
    for hi=0 to hnum
      hid=hdim(hi)
      if isnumeric(hid) then
        call joekoe_cms.exec("delete from "&data_name&" where vid="&hid,0)
        call del_file("../style/data_vote_"&hid&".js",0)
      end if
    next
  end select
  erase hdim
  action=""
  call admin_event(sel_type&" "&(hnum+1)&"条（"&tit_fir&"）记录",0,0)
  call admin_msg("已成功（"&sel_type&"）操作了"&(hnum+1)&"条记录！","?",1)
end sub

sub joekoe_chk_view()
  dim nid,vote_type,vname,vtype,counter,eid,nname,ntype,ncounter,fvname,fvtype,fcounter
  dim tempjs,filetype,file_name
  eid=trim(request.querystring("eid"))
  if not isnumeric(eid) then eid=0
  fvname=code_admin("vname",1,200)
  fvtype=0
  if cstr(trim(request.form("vtype")))="2" then fvtype=2
  fcounter=trim(request.form("counter"))
  if not isnumeric(fcounter) then fcounter=0
  vote_type=0
  call admin_td(tit_fir&"浏览")
%>
<tr align=center><td colspan=2>
  <table cellspacing=1 cellpadding=3 class=table0>
  <tr align=center>
  <td class=td width='6%'>序号</td>
  <td class=td width='80%'><%response.write tit_fir%>名称</td>
  <td class=td width='14%'>操作</td>
  </tr>
<%
  i=0
  sql="select * from "&data_name&" where vid="&id&" order by id"
  set rs=joekoe_cms.exec(sql,1)
  if rs.eof then
    rs.close
    call admin_msg(tit_fir&"（ID："&id&"）不存在！","?",1)
    exit sub
  end if
  select case jk_mod
  case "add_item"
    call joekoe_cms.exec("insert into "&data_name&"(vid,vtype,vname,counter) values("&id&",1,'"&fvname&"',0)",0)
    rs.close
    set rs=joekoe_cms.exec(sql,1)
  case "del_item"
    call joekoe_cms.exec("delete from "&data_name&" where vtype=1 and id="&eid,0)
    rs.close
    set rs=joekoe_cms.exec(sql,1)
  end select
  do while not rs.eof
    nid=rs("id")
    vname=rs("vname")
    vtype=rs("vtype")
    counter=rs("counter")
    if i=0 then
      vote_type=vtype
      if jk_mod="edit" and int(eid)=int(nid) then
        nname=vname
        ntype=vtype
        if joekoe_cms.chk() then
          if fvname<>"" then
            call joekoe_cms.exec("update "&data_name&" set vname='"&fvname&"',vtype="&fvtype&" where id="&eid,0)
            vname=fvname
            vtype=fvtype
            nname=""
          end if
        end if
      end if
      if jk_mod="js" then tempjs=tempjs&vbcrlf&"document.write(""<tr><td align=center height=25>"&joekoe_cms.code_js(vname,0)&"</td></tr>"");"
%>
  <tr class=tr1>
  <td colspan=2>&nbsp;<a href='?action=view&id=<%response.write id%>'><%response.write vname%></a>（ID：<%response.write id%>，<font class=blue><%
      if int(vtype)=0 then
        response.write "单选项"
      else
        response.write "多选项"
      end if
%></font>）</td>
  <td align=center><a href='?action=view&id=<%response.write id%>&jk_mod=edit&eid=<%response.write nid%>'>编辑</a>&nbsp;&nbsp;<a href='?action=view&id=<%response.write id%>&jk_mod=js&eid=<%response.write nid%>' onclick="javascript:return click_return('对此<%response.write tit_fir%>进行JS数据更新',0);" class=red alt='对此<%response.write tit_fir%>进行JS数据更新'>更新</a></td>
  </tr>
<%
    else
      if jk_mod="edit_item" and int(eid)=int(nid) then
        nname=vname
        ncounter=counter
        if joekoe_cms.chk() then
          if fvname<>"" then
            call joekoe_cms.exec("update "&data_name&" set vname='"&fvname&"',counter="&fcounter&" where id="&eid,0)
            vname=fvname
            counter=fcounter
            nname=""
          end if
        end if
      end if
      if jk_mod="js" then
        tempjs=tempjs&vbcrlf&"document.write(""<tr><td><input type="
        if cstr(vote_type)="0" then
          tempjs=tempjs&"radio"
        else
          tempjs=tempjs&"checkbox"
        end if
        tempjs=tempjs&" name=vote_id value='"&nid&"'>"&joekoe_cms.code_js(vname,0)&"</td></tr>"");"
      end if
%>
  <tr align=center>
  <td><%response.write i%></td>
  <td align=left><%response.write vname%>&nbsp;<font class=blue><%response.write counter%></font></td>
  <td><a href='?action=view&id=<%response.write id%>&jk_mod=edit_item&eid=<%response.write nid%>'>编辑</a>&nbsp;&nbsp;<a href='?action=view&id=<%response.write id%>&jk_mod=del_item&eid=<%response.write nid%>' onclick="javascript:return click_return('删除<%response.write tit_fir%>项目（<%response.write vname%>）',0);">删除</a></td>
  </tr>
<%
    end if
    rs.movenext
    i=i+1
  loop
  rs.close
%>
  <tr class=tr1><td colspan=3 align=center>
<%
  if nname<>"" then
    select case jk_mod
    case "edit"
%>
    <table border=0>
    <form action='?action=view&id=<%response.write id%>&jk_mod=edit&eid=<%response.write eid%>' method=post>
    <input type=hidden name=chk value='yes'>
    <tr class=tr1>
    <td>编辑标题名称：</td>
    <td><input type=text name=vname value='<%response.write nname%>' size=30 maxlength=200></td>
    <td><select name=vtype>
<option value='0'<%if cstr(ntype)="0" then response.write " selected"%>>单选项</option>
<option value='2'<%if cstr(ntype)="2" then response.write " selected"%>>多选项</option>
</select></td>
    <td>&nbsp;&nbsp;<input type=submit value='提交修改'></td>
    </tr>
    </form>
    </table>
<%
    case "edit_item"
%>
    <table border=0>
    <form action='?action=view&id=<%response.write id%>&jk_mod=edit_item&eid=<%response.write eid%>' method=post>
    <input type=hidden name=chk value='yes'>
    <tr class=tr1>
    <td>编辑项目名称：</td>
    <td><input type=text name=vname value='<%response.write nname%>' size=30 maxlength=200></td>
    <td>票数：</td>
    <td><input type=text name=counter value='<%response.write ncounter%>' size=5 maxlength=10></td>
    <td>&nbsp;&nbsp;<input type=submit value='提交修改'></td>
    </tr>
    </form>
    </table>
<%
    end select
  else
%>
    <table border=0>
    <form action='?action=view&jk_mod=add_item&id=<%response.write id%>' method=post>
    <input type=hidden name=chk value='yes'>
    <tr class=tr1>
    <td>新的项目名称：</td>
    <td><input type=text name=vname size=20 maxlength=200></td>
    <td>&nbsp;&nbsp;<input type=submit value='点击添加'></td>
    </tr>
    </form>
    </table>
<% end if %>
  </td></tr>
  </table>
</td></tr>
<%
  if jk_mod="js" then
    tempjs=vbcrlf&"document.write(""<table border=0 cellspacing=0 cellpadding=2>"");" & _
	   vbcrlf&"document.write(""<form action='vote.asp?action=ballot&vid="&id&"' method=post target='vote_view'>"");" & _
	   tempjs & _
	   vbcrlf&"document.write(""<tr><td align=center height=25><input onclick=\""javascript:open_win('','vote_view',"&v_wid&","&v_hei&",'no');\"" type=submit value='投一票'>&nbsp;&nbsp;<input type=button onclick=\""javascript:open_win('vote.asp?action=view&vid="&id&"','vote_view',"&v_wid&","&v_hei&",'no');\"" value='查看结果'></td></tr>"");" & _
  	   vbcrlf&"document.write(""</form></table>"");"
    file_name="../style/data_vote_"&id&".js"
    call create_file(file_name,tempjs)
    response.write "<script language=javascript>alert(""已成功对此"&tit_fir&"进行JS数据更新！"");</script>"
  end if
end sub

sub joekoe_chk_main()
  dim vid
  call admin_td(tit)
%>
<tr align=center><td colspan=2>
  <table cellspacing=1 cellpadding=3 class=table0>
  <form name=sel_form action='?jk_mod=<%response.write jk_mod%>&action=handle' method=post>
  <tr align=center>
  <td class=td width='10%'><%response.write tit_fir%>ID</td>
  <td class=td width='85%'><%response.write tit_fir%>列表名称</td>
  <td class=td width='5%'><input type=checkbox name=sel_all value='yes' onclick="javascript:select_all(this.form);"></td>
  </tr>
<%
  sql_add=" where vtype<>1"
  sql="select count(id) from "&data_name&sql_add
  set rs=conn.execute(sql)
  rssum=rs(0)
  rs.close
  call format_pagecute()
  sql="select top "&nummer*viewpage&" * from "&data_name&sql_add&" order by id"
  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")
    vid=rs("vid")
%>
  <tr align=center>
  <td><%response.write vid%></td>
  <td align=left><a href='?action=view&id=<%response.write vid%>'><%response.write rs("vname")%></a></td>
  <td><input type=checkbox name=sel_id value='<%response.write vid%>'></td>
  </tr>
<%
    rs.movenext
  next
  rs.close
%>
  <tr class=tr1><td colspan=3>
    <table border=0 width='100%'>
    <tr class=tr1>
    <td>现有<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 align=right>执行
<select name=sel_type size=1>
<option value='删除'>删除</option>
</select>
<input type=submit value='操作' onclick="return sel_click(this.form);"></td>
    </tr>
    </table>
  </td></tr>
  </form>
  </table>
</td></tr>
<tr>
<td>内部（ASP）调用方法：</td>
<td>&lt;script language=javascript src='style/data_vote_<font class=red>1</font>.js'&gt;&lt;/script&gt;</td>
</tr>
<tr>
<td>外部（HTML）调用方法：</td>
<td>&lt;script language=javascript src='vote.asp?id=<font class=red>1</font>&mcolor=<font class=red>ff0000</font>&bgcolor=<font class=red>ededed</font>'&gt;&lt;/script&gt;</td>
</tr>
<tr>
<td>使用说明：</td>
<td>1、第一个参数是要调用的调查ID；</td>
</tr>
<tr><td></td><td>3、第三个参数是调查标题显示颜色；（不要加“#”）</td></tr>
<tr><td></td><td>4、第四个参数是调查选择框背景色；（不要加“#”）</td></tr>
<%
end sub

sub joekoe_chk_add()
  dim max_id,vid,vname,vtype
  call admin_td("添加"&tit_fir)
  if chk() then
    vid=code_admin("vid",1,20)
    vname=code_admin("vname",1,200)
    vtype=code_admin("vtype",1,20)
    if cstr(vtype)<>"2" then vtype=0
    if not joekoe_cms.int_true(vid) then
      call admin_error(tit_fir&"ID 只能为整数，且不能为空！")
      exit sub
    end if
    if vname="" then
      call admin_error(tit_fir&"名称 不能为空！")
      exit sub
    end if
    sql="select top 1 id from "&data_name&" where vid="&vid
    set rs=joekoe_cms.exec(sql,1)
    if not rs.eof then
      rs.close
      call admin_error(tit_fir&"ID 已存在！此值为不可重复数值。")
      exit sub
    end if
    rs.close
    call joekoe_cms.exec("insert into "&data_name&"(vid,vtype,vname,counter) values("&vid&","&vtype&",'"&vname&"',0)",0)
    call admin_msg("成功添加一项新的"&tit_fir,"?",1)
    exit sub
  end if
  call form_first()
  max_id=1
  sql="select max(vid) from "&data_name
  set rs=joekoe_cms.exec(sql,1)
  if not rs.eof then
    max_id=rs(0)+1
  end if
  rs.close
%>
<form action='?action=add' method=post>
<input type=hidden name=chk value='yes'>
<tr>
<td><%response.write tit_fir%>ID：</td>
<td><input type=text name=vid value='<%response.write max_id%>' size=10 maxlength=10><%response.write redx%>不可重复</td>
</tr>
<tr>
<td><%response.write tit_fir%>名称：</td>
<td><input type=text name=vname value='' size=30 maxlength=200></td>
</tr>
<tr>
<td><%response.write tit_fir%>选项：</td>
<td><input type=radio name=vtype value='0' checked>&nbsp;单选项&nbsp;&nbsp;<input type=radio name=vtype value='2'>&nbsp;多选项</td>
</tr>
<%
  call submit_add()
end sub
%>