<%
dim sid,subid,subs,subject,segment,nums

urlParam = "functions.asp?action="&action&LOGINPROPAGATEGET
id = Request("id")
subaction = Request("subaction")
title = Request("title")
if trim(Request("iPage")) <> "" then
	iCurrentPage = clng(request("iPage"))
else
	iCurrentPage = 1
end if
if subaction = "add" then
	sql = "insert into bs_ballot(subject,postTime) values('请输入文字',getDate())"
	conn.Execute(sql)
	sql = "select max(id) from bs_ballot"
	rs.Open sql,conn,1,1
	if not rs.Eof then
		pid = rs(0)
	end if
	rs.Close
elseif subaction = "modify" then
	idList = split(trim(replace(Request("SID")," ","")),",")
	for i=0 to ubound(idList)
		sql = "update bs_ballot set status="& Request("status"& idList(i)) &" where id="& idList(i)
		conn.Execute(sql)
	next
elseif subaction = "delSelect" then
	idList = split(trim(Request("SID")),",")
	for i=0 to ubound(idList)
		conn.Execute("delete from bs_ballotSystem where pid="& idList(i))
		conn.Execute("delete from bs_ballot where id="& idList(i))
	next
	errorMsg = errorMsg &" 删除投置系统 成功！"
elseif subaction = " 添加观点，看法 " then
	sql = "insert into bs_ballotSystem(title,pid) values('"& trim(title) &"',"& id &")"
	if trim(title) = "" then
		errorMsg = errorMsg &" 添加观点，看法 不能为空<br>"
	else
		conn.Execute(sql)
	end if
elseif subaction = " 删除观点，看法 " then
	conn.Execute("delete from bs_ballotSystem where id="& id)
	errorMsg = errorMsg &" 删除观点，看法 成功！"
elseif subaction = " 删除此事件投置系统 " then
	conn.Execute("delete from bs_ballotSystem where pid="& id)
	conn.Execute("delete from bs_ballot where id="& pid)
	errorMsg = errorMsg &" 删除投置系统 成功！"
	pid = 0
elseif subaction = " 修改 " then
	subject = Request("subject")
	sql = "update bs_ballot set subject='"& subject &"' where id="& id
	conn.Execute(sql)

	subid = split(request("subid"),",")
	nums = split(request("nums"),",")
	subs = split(request("subs"),",")
	for i=0 to ubound(subid)
		sql = "update bs_ballotSystem set nums='"& trim(nums(i)) &"',title='"& trim(subs(i)) &"' where id="& trim(subid(i))
		conn.Execute(sql)
	next
	errorMsg = errorMsg &" 修改投置系统 成功！"
end if

if errorMsg <> "" then
	DisplayMessage errorMsg,True
end if
if id = 0 then
%>
<table width="100%" border="1" cellspacing="0" cellpadding="0" bordercolorlight="#CCE0CF" bordercolordark="#FFFFFF">
  <form name="listForm" action="functions.asp" method="post">
  <input type="hidden" name="action" value="<%=action%>">
  <input type="hidden" name="subaction" value="">
  <input type="hidden" name="LOGINID" value="<%=LOGINID%>">
  <input type="hidden" name="iPage" value="<%=iCurrentPage%>">
  <tr class="ListTableHeader">
    <td nowrap background="images/TableHeaderBg.gif" width="24" align="center"><input type="checkBox" name="checkAll" value="on" OnClick="OnCheckAll(this.form)"></td>
    <td nowrap background="images/TableHeaderBg.gif" align="center">投票标题</td>
    <td nowrap background="images/TableHeaderBg.gif" width="56" align="center">状态</td>
    <td nowrap background="images/TableHeaderBg.gif" width="131" align="center">发布时间</td>
    <td nowrap background="images/TableHeaderBg.gif" width="48" align="center">操作</td>
  </tr>
<%
i = 0
sql = "select id,subject,postTime,status from bs_ballot"
rs.Open sql,conn,1,1
rs.PageSize = iRowsPerPage
iMaxRowCount = rs.RecordCount
if iCurrentPage > rs.PageCount then
	iCurrentPage = rs.PageCount
end if

if not (rs.Eof and rs.Bof) then
	if iCurrentPage <> 1 then
		if (iCurrentPage - 1) * iRowsPerPage < rs.RecordCount then
			rs.Move (iCurrentPage - 1) * iRowsPerPage
		end if
	end if
	if rs.recordcount mod iRowsPerPage = 0 then
		iMaxPage = rs.RecordCount \ iRowsPerPage
	else
		iMaxPage = rs.RecordCount \ iRowsPerPage+1
	end if
	do while not rs.Eof and i < iRowsPerPage
%>
  <tr class="InputTableRow" id="Row<%=rs("id")%>" onclick="javascript:setRowFocus(this,false,<%=rs("id")%>)">
    <td nowrap align="center"><input type="checkBox" name="SID" value="<%=rs("id")%>"></td>
	<td>&nbsp;<%=rs("subject")%></td>
    <td nowrap>
      <select name="status<% =rs("id") %>" class="ButtonSelect">
<%
		for j=1 to ubound(newsStatus)-1
			Response.Write "      <option value="""& j &""""
			if rs("status") = j then
				Response.Write " selected"
			end if
			Response.Write ">"& newsStatus(j) &"</option>"& vbCrLf
		next
%>
      </select>
    </td>
    <td nowrap align="center">&nbsp;<%=rs("postTime")%></td>
    <td nowrap align="center"><span class="OperateIcon" onclick="javascript:setRowFocus(Row<%=rs("id")%>,false,<%=rs("id")%>);edit('vote',<%=rs("id")%>)" title="修改"><img src="images/IconEdit.gif" border="0" width="16" height="16" alt="修改"></span>&nbsp;<span class="OperateIcon" onclick="javascript:setRowFocus(Row<%=rs("id")%>,false,<%=rs("id")%>);del('vote','<%=rs("id")%>','您正要删除【<%=rs("subject")%>】。\n本操作将删除该记录。请确认！')" title="删除"><img src="images/IconDelete.gif" border="0" width="16" height="16" alt="删除"></span></td>
  </tr>
<%
		if bFirst = false then
%>
  <script LANGUAGE="javascript">
  <!--
	setRowFocus(Row<%=rs("id")%>,true,<%=rs("id")%>);
  //-->
  </script>
<%
			bFirst = true
		end if
		rs.MoveNext
		i = i + 1
	loop
end if
%>
  </form>
</table>
<!-- #include file="pageRobot.inc.asp" //-->
<%
else
	dim sumRecord

	sumRecord = 0
	sql = "select count(*) from bs_ballotSystem where pid="& id
	rs.Open sql,conn,1,1
	if not rs.Eof then
		sumRecord = rs(0)
	end if
	rs.Close

	sql = "update bs_ballot set segment="& sumRecord &" where id="& id
    conn.Execute(sql)
%>
<table align="center" width="100%" cellspacing="1" border="0">
  <tr class="ListTableHeader">
    <td colspan="2" background="images/TableHeaderBg.gif">投票主题，事件－－输入此栏的文字标题说明</td>
  </tr>
<%
	sql = "select subject,segment,id from bs_ballot where id="& id &" order by id"
	rs.Open sql,conn,1,1
	if not rs.Eof then
		subject = rs("subject")
		segment = rs("segment")
		id = rs("id")
	end if
	rs.Close
%>
  <form action="<%=urlParam%>" method="post">
  <tr bgcolor="#EEEEEE">
    <td colspan="2" align="center">
      <textarea name="subject" cols="140" rows="3" class="DetailTextArea"><%=subject%></textarea>
    </td>
  </tr>
  <tr class="ListTableHeader">
    <td align="center" background="images/TableHeaderBg.gif">观点，看法</font></td>
    <td align="center" background="images/TableHeaderBg.gif">投票结果</td>
  </tr>
<%
	sql = "select id,title,nums from bs_ballotSystem where pid="& id &" order by id asc"
	rs.Open sql,conn,1,1
	do while not rs.Eof
%>
  <tr class="InputTableRow">
    <td align="center">
      <input type="hidden" name="subid" value="<%=rs("id")%>" class="ButtonEdit">
      <input type="text" name="subs" value="<%=rs("title")%>" size="112" class="ButtonEdit">
    </td>
    <td align="center">
      <input type="text" name="nums" value="<%=rs("nums")%>" size="8" class="ButtonEdit">
    </td>
  </tr>
<%
		rs.MoveNext
	loop
	rs.Close
%>
  <tr class="InputTableRow">
    <td colspan="2" align="center">
      <input type="hidden" name="id" value="<%=id%>">
      <input type="submit" name="subaction" value=" 修改 " class="ButtonReply">
    </td>
  </tr>
  </form>
  <tr class="ListTableHeader">
    <td colspan="2" background="images/TableHeaderBg.gif">添加观点，看法</td>
  </tr>
  <tr class="InputTableRow" bgcolor="#EEEEEE">
  <form action="<%=urlParam%>" method="post">
	<td colspan="2" align="center" height="30">
      <input type="text" name="title" value="" size="96" class="ButtonEdit">
      <input type="hidden" name="id" value="<%=id%>">
      <input type="submit" name="subaction" value=" 添加观点，看法 " class="ButtonReply">
    </td>
  </form>
  </tr>
  <tr class="ListTableHeader">
    <td colspan="2" background="images/TableHeaderBg.gif">删除观点，看法</td>
  </tr>
  <tr class="InputTableRow">
  <form action="<%=urlParam%>" method="post">
    <td width="50%" align="center" colspan="2">
      <select name="id" class="ButtonSelect">
<%
	sql = "select id,title from bs_ballotSystem where pid="& id &" order by pid asc"
	rs.Open sql,conn,1,1
	do while not rs.Eof
		response.write "        <option value="""& rs("id") &""">"& rs("title") &vbCrLf
		rs.MoveNext
	loop
	rs.Close
%>
      </select>
      <input type="hidden" name="id" value="<%=id%>">
      <input type="submit" name="subaction" value=" 删除观点，看法 " onClick="return confirm('您确定要删除吗？');" class="ButtonReply">
    </td>
  </form>
  </tr>
  <tr class="ListTableHeader">
    <td colspan="2" background="images/TableHeaderBg.gif">删除此事件投置系统</td>
  </tr>
  <tr class="MainPageBar">
  <form action="<%=urlParam%>" method="post">
	<td width="50%" align="center" colspan="2">
      <input type="hidden" name="id" value="<%=id%>">
      <input type="submit" name="subaction" value=" 删除此事件投置系统 " onClick="return confirm('您确定要删除吗？');" class="ButtonReply">
    </td>
  </form>
  </tr>
  <tr>
    <td colspan="2">
  	  <hr size="1" noshade>
    </td>
  </tr>
</table>
<%
end if
%>