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

dim v_wid,v_hei,sqlvn,rsvn,vtype
v_wid=400
v_hei=300
Index_Url="vote"
call AMH_master(0,0)
Call AMH_Header(1)
%>
<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&v=0'>添加新<%Response.Write tit_fir%></a></td>
  </tr>
  </table>
</td></tr>
</table>
<%
call AMH_table(1)
select case action
case "handle"
  call AsaiMHChk_Handle()
case "edit"
  call AsaiMHChk_Edit()
case "add"
  call AsaiMHChk_Add()
case "view"
  call AsaiMHChk_View()
case else
  call AsaiMHChk_Main()
end select
Call AMH_Ender(tit)
sub AsaiMHChk_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 Cls.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 Cls.exec("delete from "&Data_Name&" where vid="&hid,0)
        Dim TmpCls
			  Set TmpCls = New Cls_FileSystem
          Call TmpCls.Del_File(Cls.Web_Dir &"Style/Data_Vote_"&hid&".js")
			  Set TmpCls = Nothing
      end if
    next
  end select
  erase hdim
  action=""
  call AMH_event(sel_type&" "&(hnum+1)&"条（"&tit_fir&"）记录")
  call AMH_msg("已成功（"&sel_type&"）操作了"&(hnum+1)&"条记录！","?",1)
end sub
sub AsaiMHChk_View()
  dim nid,vote_type,vname,vurl,tcolor,vtype,counter,eid,nname,nvurl,ntcolor,ntype,ncounter,fvname,fvurl,ftcolor,fvtype,fcounter
  dim tempjs,filetype,file_name
  eid=trim(request.querystring("eid"))
  if not isnumeric(eid) then eid=0
  fvname=Cls.Code_Admin("vname",1,200)
  fvurl=Cls.Code_Admin("vurl",1,100)
  fvtype=0
  if cstr(trim(request.form("vtype")))="2" then fvtype=2
  fcounter=trim(request.form("counter"))
  if not isnumeric(fcounter) then fcounter=0
  ftcolor=trim(request.form("tcolor"))
    if len(ftcolor)<>6 then tcolor=""
  vote_type=0
  'call AMH_td(tit_fir&"浏览")
%>
  <tr class=fm1 style="HEIGHT: 22px" align=middle>
  <td width='6%'>序号</td>
  <td width='40%'><%Response.Write tit_fir%>名称</td>
  <td width='40%'><%Response.Write tit_fir%>相关连接</td>
  <td width='14%'>操作</td>
  </tr>
<%
  i=0
  sql="select * from "&Data_Name&" where vid="&id&" order by id"
  set rs=Cls.exec(sql,1)
  if rs.eof then
    rs.close
    call AMH_msg(tit_fir&"（ID："&id&"）不存在！","?",1)
    exit sub
  end if
  select case AsaiMHMod
  case "add_item"
    call Cls.exec("insert into "&Data_Name&"(vid,vtype,vname,vurl,tcolor,counter) values("&id&",1,'"&fvname&"','"&fvurl&"','"&ftcolor&"',0)",0)
    rs.close
    set rs=Cls.exec(sql,1)
  case "del_item"
    call Cls.exec("delete from "&Data_Name&" where vtype=1 and id="&eid,0)
    rs.close
    set rs=Cls.exec(sql,1)
  end select
  do while not rs.eof
    nid=rs("id")
    vname=rs("vname")
    vtype=rs("vtype")
    vurl=rs("vurl")
	tcolor=rs("tcolor")
    counter=rs("counter")
    if i=0 then
      vote_type=vtype
      if AsaiMHMod="edit" and int(eid)=int(nid) then
        nname=vname
        ntype=vtype
		nvurl=vurl
		ntcolor=tcolor
        if Cls.chk() then
          if fvname<>"" then
            call Cls.exec("update "&Data_Name&" set vname='"&fvname&"',vurl='"&fvurl&"',tcolor='"&ftcolor&"',vtype="&fvtype&" where id="&eid,0)
            vname=fvname
            vurl=fvurl
            vtype=fvtype
            nname=""
            nvurl=""
			ntcolor=""
          end if
        end if
      end if
      if AsaiMHMod="js" and vurl="" then
      	tempjs=tempjs&vbcrlf&"document.write(""<li><font color=#"&tcolor&">"&Cls.Code_Js(vname,0)&"</font></li>"");"
      else
      	tempjs=tempjs&vbcrlf&"document.write(""<li><a href='"&vurl&"'><font color=#"&tcolor&">"&Cls.Code_Js(vname,0)&"</font></a></li>"");"
      end if
%>
  <tr class=tr1>
  <td colspan=2>&nbsp;<a href='?action=view&id=<%Response.Write id%>'><font color=#<%Response.Write tcolor%>><%Response.Write vname%></font></a>（ID：<%Response.Write id%>，<font class=blue><%
      if int(vtype)=0 then
        Response.Write "单选项"
      else
        Response.Write "多选项"
      end if
%></font>）&nbsp;&nbsp;<a href='?action=view&id=<%response.write id%>&AsaiMHMod=js&eid=<%response.write nid%>' onclick="javascript:return click_return('对此<%response.write tit_fir%>进行JS数据更新',0);" class=red alt='对此<%response.write tit_fir%>进行JS数据更新'>调查JS数据更新</a></td>
  <td align=left><%Response.Write vurl%></td>
  <td align=center><a href='?action=view&id=<%response.write id%>&AsaiMHMod=edit&eid=<%response.write nid%>'>编辑标题</a></td>
  </tr>
<%
    else
      if AsaiMHMod="edit_item" and int(eid)=int(nid) then
        nname=vname
		nvurl=vurl
		ntcolor=tcolor
        ncounter=counter
        if Cls.chk() then
          if fvname<>"" then
            call Cls.exec("update "&Data_Name&" set vname='"&fvname&"',vurl='"&fvurl&"',tcolor='"&ftcolor&"',counter="&fcounter&" where id="&eid,0)
            vname=fvname
            vurl=fvurl
			tcolor=ftcolor
            counter=fcounter
            nname=""
			nvurl=""
			ntcolor=""
          end if
        end if
      end if
      if AsaiMHMod="js" then
        tempjs=tempjs&vbcrlf&"document.write(""<li><input type="
        if cstr(vote_type)="0" then
          tempjs=tempjs&"radio"
        else
          tempjs=tempjs&"checkbox"
        end if
        if vurl<>"" then
        tempjs=tempjs&" name=vote_id value='"&nid&"'><a href='"&vurl&"'><font color=#"&tcolor&">"&Cls.Code_Js(vname,0)&"</font></a></li>"");"
         else
        tempjs=tempjs&" name=vote_id value='"&nid&"'><font color=#"&tcolor&">"&Cls.Code_Js(vname,0)&"</font></li>"");"
        end if
     end if
%>
  <tr class=tr align=center>
  <td><%Response.Write i%></td>
  <td align=left><font color=#<%Response.Write tcolor%>><%Response.Write vname%></font>&nbsp;<font class=blue><%Response.Write counter%></font></td>
  <td align=left><%Response.Write vurl%></td>
  <td><a href='?action=view&id=<%Response.Write id%>&AsaiMHMod=edit_item&eid=<%Response.Write nid%>'>编辑</a>&nbsp;&nbsp;<a href='?action=view&id=<%Response.Write id%>&AsaiMHMod=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=4 align=center>
<%
  if nname<>"" then
    select case AsaiMHMod
    case "edit"
%>
    <form action='?action=view&id=<%Response.Write id%>&AsaiMHMod=edit&eid=<%Response.Write eid%>' method=post>
    <input type=hidden name=chk value='yes'>
    <table cellspacing=1 cellpadding=4 class=table>
    <tr>
    <td width='20%'>编辑<%Response.Write tit_fir%>标题名称：</td>
	<td><input type=text name=vname value='<%Response.Write nname%>' size=25 maxlength=200><%Response.write ShowColor("tcolor",ntcolor)%></td>
	</tr>
    <tr>
	<td><%Response.Write tit_fir%>相关连接：</td>
	<td><input type=text name=vurl value='<%Response.Write nvurl%>' size=30 maxlength=100></td>
	</tr>
    <tr>
    <td><%Response.Write tit_fir%>选项</td>
	<td><input type=radio name=vtype value='0'<%if cstr(ntype)="0" then Response.Write " checked" %>>&nbsp;单选项&nbsp;&nbsp;&nbsp;<input type=radio name=vtype value='2'<%if cstr(ntype)="2" then Response.Write " checked" %>>&nbsp;多选项</td>
	</tr>
    <tr>
    <td colspan=2 align=center><input type=submit value='提交修改' class=btn>　　<input type=reset value='重新填写' class=btn></td>
    </tr>
    </form>
    </table>
<%
    case "edit_item"
%>
    <form action='?action=view&id=<%Response.Write id%>&AsaiMHMod=edit_item&eid=<%Response.Write eid%>' method=post>
    <input type=hidden name=chk value='yes'>
    <table cellspacing=1 cellpadding=4 class=table>
    <tr>
    <td width='20%'>编辑项目名称：</td>
    <td><input type=text name=vname value='<%Response.Write nname%>' size=25 maxlength=200><%Response.write ShowColor("tcolor",ntcolor)%></td>
    </tr>
	<tr>
	<td>项目相关连接：</td>
	<td><input type=text name=vurl value='<%Response.Write nvurl%>' size=30 maxlength=100></td>
    </tr>
	<tr>
    <td>项目票数：</td>
    <td><input type=text name=counter value='<%Response.Write ncounter%>' size=5 maxlength=10></td>
    </tr>	
    <tr>
    <td colspan=2 align=center><input type=submit value='提交修改' class=btn>　　<input type=reset value='重新填写' class=btn></td>
    </tr>
    </form>
    </table>
<%
    end select
  else
%>
    <form action='?action=view&AsaiMHMod=add_item&id=<%Response.Write id%>' method=post>
    <input type=hidden name=chk value='yes'>
    <table cellspacing=1 cellpadding=4 class=table>
    <tr>
    <td width='20%'>新的项目名称：</td>
    <td><input type=text name=vname size=20 maxlength=200><%Response.write ShowColor("tcolor",ntcolor)%></td>
    </tr>	
    <tr>
	<td>项目相关连接：</td>
	<td><input type=text name=vurl value='<%Response.Write nvurl%>' size=30 maxlength=100></td>
    </tr>	
    <tr>
    <td colspan=2 align=center><input type=submit value='点击添加' class=btn>　　<input type=reset value='重新填写' class=btn></td>
    </tr>
    </form>
    </table>
<% end if %>
  </td></tr>
  </table>
</td></tr>
<%
  if AsaiMHMod="js" then
    tempjs=vbcrlf&"document.write(""<div align=center><ul>"");" & _
	   vbcrlf&"document.write(""<form action='"&cls.web_dir&"Common/Vote.asp?action=ballot&vid="&id&"' method=post target='vote_view'>"");" & _
	   tempjs & _
	   vbcrlf&"document.write(""<li><input class=btn onclick=\""javascript:open_win('','vote_view',"&v_wid&","&v_hei&",'no');\"" type=submit value='投 票'>&nbsp;&nbsp;&nbsp;<input class=btn type=button onclick=\""javascript:open_win('"&cls.web_dir&"Common/Vote.asp?action=view&vid="&id&"','vote_view',"&v_wid&","&v_hei&",'no');\"" value='查 看'></li>"");" & _
  	   vbcrlf&"document.write(""</form></ul></div>"");"
    file_name=Cls.Web_Dir &"Style/Data_Vote_"&id&".js"
    Dim TmpCls
	  Set TmpCls = New Cls_FileSystem
      Call TmpCls.create_file(file_name,tempjs)
	  Set TmpCls = Nothing
    Response.Write "<script language=javascript>alert(""已成功对此"&tit_fir&"进行JS数据更新！"");</script>"
  end if
end sub
sub AsaiMHChk_Main()
  dim vid,n,vurl,tcolor,vname
  'call AMH_td(tit)
%>
  <form name=sel_form action='?AsaiMHMod=<%Response.Write AsaiMHMod%>&action=handle' method=post>
  <tr align=center>
  <td class=td width='7%'><%Response.Write tit_fir%>ID</td>
  <td class=td width='33%'><%Response.Write tit_fir%>列表名称</td>
  <td class=td width='30%'><%Response.Write tit_fir%>相关连接</td>
  <td class=td width='25%'><%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>
<%
  n=0
  sql_add=" where counter=0"
  sql="select * from "&Data_Name&sql_add&" order by id"
  set rs=Cls.exec(sql,1)
  do while not rs.eof
    id=rs("id")
    vid=rs("vid")
    vtype=rs("vtype")
	tcolor=rs("tcolor")
	vname=rs("vname")
	if Cls.Is_Null(tcolor)<>"" then
      vname="<font color=#"&tcolor&">"&vname&"</font>"
    End If
%>
  <tr align=center>
  <td><%response.write vid%></td>
  <td align=left><a href='?action=view&id=<%response.write vid%>'><%response.write vname%></a></td>
  <td align=left><a href='?action=view&id=<%response.write vid%>'><%response.write rs("vurl")%></a></td>
  <td><a href='?action=add&vd=<%response.write vid%>&vt=<%response.write vtype%>&tit=<%response.write vname%>' class=red>添加投票项</a>&nbsp;&nbsp;<a href='?action=view&id=<%response.write vid%>&AsaiMHMod=edit&eid=<%response.write id%>'>编辑</a>&nbsp;&nbsp;<a href='?action=view&id=<%response.write vid%>'>查看</a>&nbsp;&nbsp;<a href='?action=view&id=<%response.write vid%>&AsaiMHMod=js&eid=<%response.write id%>' onclick="javascript:return click_return('对此<%response.write tit_fir%>进行JS数据更新',0);" class=red alt='对此<%response.write tit_fir%>进行JS数据更新'>更新JS</a></td>
  <td><input type=checkbox name=sel_id value='<%response.write vid%>'></td>
  </tr>
<%
    rs.movenext
    n=n+1
  loop
  rs.close
%>
  <tr class=tr1><td colspan=5>
    <table border=0 width='100%'>
    <tr class=tr1>
    <td>现有<font class=red><%response.write n%></font>个<%response.write tit_fir%></td>
    <td align=right>
<select name=sel_type size=1>
<option value='删除'>删除</option>
</select>
<input type=submit value='操作' onclick="return sel_click(this.form);" class=btn></td>
    </tr>
    </table>
  </td></tr>
  </form>
  </table>
</td></tr>
<%
end sub
sub AsaiMHChk_Add()
  dim Max_ID,vid,vname,vurl,vtype,tcolor
  call AMH_td("添加"&tit_fir)
  if chk() then
    vid=Cls.Code_Admin("vid",1,20)
    vname=Cls.Code_Admin("vname",1,200)
    vurl=Cls.Code_Admin("vurl",1,100)
    tcolor=trim(request.form("tcolor"))
	 if len(tcolor)<>6 then tcolor=""
    vtype=Cls.Code_Admin("vtype",1,20)
    if cstr(vtype)<>"2" then vtype=0
    if not Cls.Is_Int(vid) then
      call AMH_error(tit_fir&"ID 只能为整数，且不能为空！")
      exit sub
    end if
    if vname="" then
      call AMH_error(tit_fir&"名称 不能为空！")
      exit sub
    end if
'    sql="select top 1 id from "&Data_Name&" where vid="&vid
'    set rs=Cls.exec(sql,1)
'    if not rs.eof then
'      rs.close
'      call AMH_error(tit_fir&"ID 已存在！此值为不可重复数值。")
'      exit sub
'    end if
'    rs.close
	if request("ax")="1" then
    call Cls.exec("insert into "&Data_Name&"(vid,vtype,vname,vurl,tColor,counter) values("&vid&","&vtype&",'"&vname&"','"&vurl&"','"&tColor&"',0)",1)
	else
    call Cls.exec("insert into "&Data_Name&"(vid,vtype,vname,vurl,tColor,counter) values("&vid&","&vtype&",'"&vname&"','"&vurl&"','"&tColor&"',0)",0)
	end if
    call AMH_msg("成功添加一项新的"&tit_fir,"?",1)
    exit sub
  end if
  call form_first()
  Max_ID=1
  sql="select max(vid) from "&Data_Name
  set rs=Cls.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'>
<%if request("vd")<>"" then%>
<tr>
<td><%Response.Write tit_fir%>名称：</td>
<td><strong><%=left(request("tit"),60)%></strong><input type=hidden name=vid value='<%=int(request("vd"))%>'><input type=hidden name=ax value='1'></td>
</tr>
<%else%>
<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>
<%end if%>
<tr>
<td><%Response.Write tit_fir%>名称：</td>
<td><input type=text name=vname value='' size=30 maxlength=200><%Response.write ShowColor("Tcolor","")%></td>
</tr>
<tr>
<td><%Response.Write tit_fir%>相关联接：</td>
<td><input type=text name=vurl value='' size=50 maxlength=100></td>
</tr>
<%if request("vd")<>"" then%>
<input type=hidden name=vtype value='<%=int(request("vt"))%>'>
<%else%>
<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><%end if%>
<%
call submit_add()
end sub
%>
