<!--#include file="../../conn/conn.asp"-->
<!--#include file="../../Inc/Commoncode.asp" -->
<!--#include file="../checkvalid.asp"-->
<%
If Not FRAdminLevel(703) Then
	Call ErrorMsg()
End If
%>
<%
addr0=request.servervariables("server_name")
addr1=request.servervariables("url")
addr1=replace(addr1,"daima.asp","")
addr="http://"&addr0&addr1
%>
<%
Response.Expires = 0 
Response.CacheControl = "no-cache" 
Response.ExpiresAbsolute = Now() - 1 
Dim Action
JOB_VoteTitle=request.Form("JOB_VoteTitle")
JOB_VoteStart=request.Form("JOB_VoteStart")
JOB_VoteEnd=request.Form("JOB_VoteEnd")
JOB_VoteStyle=request.Form("JOB_VoteStyle")
JOB_Voteing=request.Form("JOB_Voteing")
JOB_VoteColor=request.Form("JOB_VoteColor")
JOB_VotesTitle=request.Form("JOB_VotesTitle")
JOB_VotesTitless=request.Form("JOB_VotesTitless")
JOB_VoteColorss=request.Form("JOB_VoteColorss")
id=request("id")
daimaid=request("daimaid")
Voteid=request("Voteid")
%>
<html>
<head>
<title>投票管理</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="../css/style<%=sk%>.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../inc/input.js"></script>
<style type="text/css">
<!--
.STYLE2 {color: #FF0000}
-->
</style>
</head>
<script>
function show(id)
{
	if(document.all(id).style.display=='none')
{
	document.all(id).style.display='block';
}
else
{
	document.all(id).style.display='none';
}
}
</script>
<body>
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="tableBorder">
  <tr>
    <th height="25">调查投票管理</th>
  </tr>
  <tr>
    <td height=25 style="border-bottom:1px #cccccc solid"><b>　<span class="style1">管理选项：</span></b><a href="admin_VoteIndex.asp">管理首页</a> | <a href="admin_VoteIndex.asp?Action=Add">添加新项目</a> |&nbsp;[<a href="javascript:location.reload()">刷新页面</a>]</td>
  </tr>
</table>
<%Action=trim(Request("Action"))
Select Case Action
	Case "Add"
		Call ShowData()
	Case "Modify"
		Call ModifyData()
	Case "ModifyData"
		Call ModifyDataSave()
	Case "SaveData"
		Call SaveData()
	Case "Del"
		Call Del()
	Case "VoteDel"
		Call VoteDel()
	Case "ShowVote"
		Call ShowVote()
	Case Else
		Call main()
End Select

if FoundErr=True then
	call Show_Err()
end if

Conn.Close
Set Conn=Nothing
%>
<!--#include file="../inc/copy.asp" -->
<%Sub ShowData()%>
<script type="text/javascript" src="../../Js/Calendar.js"></script>
<script language="javascript">
function setid()
	  {
		str='<br>';
	  if(!window.form1.votecount.value)
	   window.form1.votecount.value=1;
	  for(i=1;i<=window.form1.votecount.value;i++)
		 str+='&nbsp;<input type="text" name="JOB_VotesTitle" value="选项'+i+'" size="40"> 结果图形颜色:<select name="JOB_VoteColor"><option style="background-color:red;color:red" value="red" selected>默认</option><option style="background-color:000000;color:000000" value="000000">黑色</option><option style="background-color:0088FF;color:0088FF" value="0088FF">海蓝</option><option style="background-color:0000FF;color:0000FF" value="0000FF">亮蓝</option><option style="background-color:000088;color:000088" value="000088">深蓝</option><option style="background-color:888800;color:888800" value="888800">黄绿</option><option style="background-color:008888;color:008888" value="008888">蓝绿</option><option style="background-color:008800;color:008800" value="008800">橄榄</option><option style="background-color:8888FF;color:8888FF" value="8888FF">淡紫</option><option style="background-color:AA00CC;color:AA00CC" value="AA00CC">紫色</option><option style="background-color:8800FF;color:8800FF" value="8800FF">蓝紫</option><option style="background-color:888888;color:888888" value="888888">灰色</option><option style="background-color:CCAA00;color:CCAA00" value="CCAA00">土黄</option><option style="background-color:FF8800;color:FF8800" value="FF8800">金黄</option><option style="background-color:CC3366;color:CC3366" value="CC3366">暗红</option><option style="background-color:FF00FF;color:FF00FF" value="FF00FF">紫红</option><option style="background-color:3366CC;color:3366CC" value="3366CC">蓝黑</option></select><br><br>';
	  window.upid.innerHTML=str;
	  }
</script>
<table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" class="tableBorder mt6">
<form name="form1" action="admin_VoteIndex.asp?action=SaveData" method="post">
<input name="key" type="hidden" value="0">
<tr>
    <th class="tableHeaderText" colspan=2 height=25>添加新项目</th>
</tr>
<tr>
  <td width="138" height="25" align="right">项目标题&nbsp;</td>
  <td width="801">&nbsp;<input name="JOB_VoteTitle" type="text" size="40"></td>
</tr>
<tr>
  <td height="25" align="right">投票方式&nbsp; </td>
  <td><input name="JOB_VoteStyle" type="radio" class="checkbox" value="radio" checked>
      单选
      <input name="JOB_VoteStyle" type="radio" class="checkbox" value="checkbox">
      多选</td>
</tr>
<tr>
  <td height="25" align="right">投票状态&nbsp; </td>
  <td><input name="JOB_Voteing" type="radio" class="checkbox" value="1" checked>
      开&nbsp;&nbsp;
      <input name="JOB_Voteing" type="radio" class="checkbox" value="0">
      关</td>
</tr>
<tr>
  <td height="25" align="right">投票时间&nbsp; </td>
  <td>&nbsp;开始于 <input onClick="ShowCalendar(this.id)" onFocus="ShowCalendar(this.id)" size=10  readonly="" name="JOB_VoteStart" id="JOB_VoteStart" value=""/> 结束于 <input onClick="ShowCalendar(this.id)" onFocus="ShowCalendar(this.id)" size=10  readonly="" name="JOB_VoteEnd" id="JOB_VoteEnd" value=""/></td>
</tr>
<tr>
  <td height="25" align="right">选项个数&nbsp; </td>
  <td>&nbsp;<input type="text" name="votecount" size="4" class="tx" onBlur="setid();" value="4">
</td>
</tr>
    <tr align="center" valign="middle"> 
		<td height="122" align="right" valign="top"><br>
	    选项名称&nbsp; </td>
      <td align="left" id="upid" height="122"><input type="text" name="JOB_VotesTitle" size="20"></td>      
    </tr>
<tr><td height="25" align="center" colspan="2"><input name="Submit" type="submit" class="inputs" value=" 添 加 "></td></tr>
</form>
</table>
<script language="javascript">
setid();
</script>
<%end sub%>
<%Sub Main()%>
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" bordercolorlight="#cccccc" bordercolordark="#FFFFFF" class="tableBorder mt6">
<tr>
  <th colspan="12">管理调查投票项目</th>
</tr>
<tr align=center>
<td width="7%">调用代码</td>
<td width="22%" height="25"><strong>投票主题</strong></td>
<td width="10%"><strong>显示投票项</strong></td>
<td width="13%"><strong>开始时间</strong></td>
<td width="13%"><strong>结束时间</strong></td>
<td width="11%"><strong>投票方式</strong></td>
<td width="11%"><strong>是否投票中</strong></td>
<td width="13%"><strong>编辑</strong></td>
</tr>
<%set rs=Server.CreateObject("Adodb.Recordset")
sql="select * from JOB_Vote where JOB_VoteClass=0 order by JOB_Voteid"
rs.open sql,conn,1,1
for i=1 to rs.recordcount
%>
<tr align=center>
  <td height="25" align="center" onClick=show("daima<%=i%>") style="cursor:pointer;" title="查看代码">查看</td>
  <td height="25" align="left">&nbsp;<a href="Admin_VoteIndex.asp?action=ShowVote&id=<%=rs("JOB_Voteid")%>" title="查看投票结果"><%=rs("JOB_VoteTitle")%></a></td>
  <td height="25" onClick=show("<%=rs("JOB_Voteid")%>") style="cursor:pointer;" title="显示该投票项内容">显示投票项</td>
  <td align="center"><%=rs("JOB_VoteStart")%></td>
  <td align="center"><%=rs("JOB_VoteEnd")%></td>
  <td align="center"><% if rs("JOB_VoteStyle")="radio" then %>单选投票<%else%>多选投票<%end if%></td>
  <td align="center"><%if rs("JOB_Voteing")=1 then%>投票进行中<%else%>投票不进行<%end if%></td>
  <td align="center"><a href="Admin_VoteIndex.asp?action=Modify&id=<%=rs("JOB_Voteid")%>" title="修改该投票项目信息">修改</a> <a href="Admin_VoteIndex.asp?action=Del&id=<%=rs("JOB_Voteid")%>">删除</a></td>
</tr>

<tr style="display:none;" id="<%=rs("JOB_Voteid")%>">
  <td height="25" colspan="8" align="left">
<table width="99%" border="0" align="center" cellpadding="0" cellspacing="0">
<%
	sql1="select * from JOB_Vote where JOB_VoteClass="&rs("JOB_Voteid")
	set rs2=Server.CreateObject("ADODB.RecordSet")
	rs2.open sql1,conn,1,1
	n=0
	do while not rs2.eof
%>
  <tr>
    <td width="59%">&nbsp;<%=rs2("JOB_VoteTitle")%></td>
	<td width="28%" align="center">已投票数:<%=rs2("JOB_VoteCount")%></td>
	<td width="13%" align="center"><a href="Admin_VoteIndex.asp?action=VoteDel&Voteid=<%=rs2("JOB_Voteid")%>" title="删除该投票选项">删除该选项</a></td>
  </tr>
<%
	rs2.movenext
	loop
	rs2.close
	set rs2=nothing
%>
</table>
</td>
</tr>
<tr id="daima<%=i%>" style="display:none;"><td colspan="8" align="center">
	<input type="text" size="80" value="<script language='javascript' src='/Vote/ShowVote.asp?JOB_Voteid=<%=rs("JOB_Voteid")%>'></script>"><br>
	请将此段代码加到要显示投票的位置，该位置将显示该项投票内容
</td></tr>
<%
rs.movenext
next
%>
</table>
<%
rs.close
set rs=nothing
end sub%>
<%
Sub ModifyData()
if id="" or IsNumeric(id)=false then
	FoundErr=True
	ErrMsg=ErrMsg & "<br><li>参数错误！</li>"
	exit sub
else
set rs=Server.CreateObject("Adodb.Recordset")
sql="select * from JOB_Vote where JOB_Voteid="&id
rs.open sql,conn,1,1
if not (rs.bof and rs.eof) then
%>
<script type="text/javascript" src="../../Js/Calendar.js"></script>
<script language="javascript">
function setid()
	  {
		str='<br>';
	  if(!window.form1.votecount.value)
	   window.form1.votecount.value=1;
	  for(i=1;i<=window.form1.votecount.value;i++)
		 str+='<input type="text" name="JOB_VotesTitless" value="选项'+i+'" size="40"> 图形颜色:<select name="JOB_VoteColorss"><option style="background-color:red;color:red" value="red" selected>默认</option><option style="background-color:000000;color:000000" value="000000">黑色</option><option style="background-color:0088FF;color:0088FF" value="0088FF">海蓝</option><option style="background-color:0000FF;color:0000FF" value="0000FF">亮蓝</option><option style="background-color:000088;color:000088" value="000088">深蓝</option><option style="background-color:888800;color:888800" value="888800">黄绿</option><option style="background-color:008888;color:008888" value="008888">蓝绿</option><option style="background-color:008800;color:008800" value="008800">橄榄</option><option style="background-color:8888FF;color:8888FF" value="8888FF">淡紫</option><option style="background-color:AA00CC;color:AA00CC" value="AA00CC">紫色</option><option style="background-color:8800FF;color:8800FF" value="8800FF">蓝紫</option><option style="background-color:888888;color:888888" value="888888">灰色</option><option style="background-color:CCAA00;color:CCAA00" value="CCAA00">土黄</option><option style="background-color:FF8800;color:FF8800" value="FF8800">金黄</option><option style="background-color:CC3366;color:CC3366" value="CC3366">暗红</option><option style="background-color:FF00FF;color:FF00FF" value="FF00FF">紫红</option><option style="background-color:3366CC;color:3366CC" value="3366CC">蓝黑</option></select><br><br>';
	  window.upid.innerHTML=str;
	  }
</script>
<table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" class="tableBorder">
  <form name="form1" action="admin_VoteIndex.asp?action=ModifyData&id=<%=id%>" method="post">
    <input name="key2" type="hidden" value="0">
    <tr>
      <th class="tableHeaderText" colspan=2 height=25>修改投票项目</th>
    </tr>
    <tr>
      <td width="138" height="25" align="right">项目标题&nbsp;</td>
      <td width="801">&nbsp;
          <input name="JOB_VoteTitle" type="text" size="40" value="<%=rs("JOB_VoteTitle")%>"></td>
    </tr>
    <tr>
      <td height="25" align="right">投票方式&nbsp; </td>
      <td><input name="JOB_VoteStyle" type="radio" class="checkbox" value="radio" <% if rs("JOB_VoteStyle")="radio" then %> checked<%end if%>>
        单选
        <input name="JOB_VoteStyle" type="radio" class="checkbox" value="checkbox" <% if rs("JOB_VoteStyle")="checkbox" then %> checked<%end if%>>
        多选</td>
    </tr>
    <tr>
      <td height="25" align="right">投票状态&nbsp; </td>
      <td><input name="JOB_Voteing" type="radio" class="checkbox" value="1" <% if rs("JOB_Voteing")="1" then %> checked<%end if%>>
        开&nbsp;&nbsp;
        <input name="JOB_Voteing" type="radio" class="checkbox" value="0" <% if rs("JOB_Voteing")="0" then %> checked<%end if%>>
        关</td>
    </tr>
    <tr>
      <td height="25" align="right">投票时间&nbsp; </td>
      <td>&nbsp;开始于
        <input onClick="ShowCalendar(this.id)" onFocus="ShowCalendar(this.id)" size=10  readonly="" name="JOB_VoteStart" id="JOB_VoteStart" value="<%=rs("JOB_VoteStart")%>"/>
        结束于
        <input onClick="ShowCalendar(this.id)" onFocus="ShowCalendar(this.id)" size=10  readonly="" name="JOB_VoteEnd" id="JOB_VoteEnd" value="<%=rs("JOB_VoteEnd")%>"/></td>
    </tr>
    <tr align="center" valign="middle">
      <td height="122" align="right" valign="top"><br>
        选项名称&nbsp; </td>
      <td align="left" id="upids" height="122">
	  <%
	  dim sql1,rs1,k
	  set rs1=conn.execute("select * from JOB_Vote where JOB_VoteClass="&id)
	  if not (rs1.bof and rs1.eof) then
	  do while not rs1.eof
	  %>
	  <br><INPUT TYPE="hidden" name="JOB_Voteid" value="<%=rs1("JOB_Voteid")%>"><input type="text" name="JOB_VotesTitle" value="<%=rs1("JOB_VoteTitle")%>" size="40"> 图形颜色:<select name="JOB_VoteColor"><option style="background-color:<%=rs1("JOB_VoteColor")%>;color:<%=rs1("JOB_VoteColor")%>" value="<%=rs1("JOB_VoteColor")%>" selected>默认</option><option style="background-color:000000;color:000000" value="000000">黑色</option><option style="background-color:0088FF;color:0088FF" value="0088FF">海蓝</option><option style="background-color:0000FF;color:0000FF" value="0000FF">亮蓝</option><option style="background-color:000088;color:000088" value="000088">深蓝</option><option style="background-color:888800;color:888800" value="888800">黄绿</option><option style="background-color:008888;color:008888" value="008888">蓝绿</option><option style="background-color:008800;color:008800" value="008800">橄榄</option><option style="background-color:8888FF;color:8888FF" value="8888FF">淡紫</option><option style="background-color:AA00CC;color:AA00CC" value="AA00CC">紫色</option><option style="background-color:8800FF;color:8800FF" value="8800FF">蓝紫</option><option style="background-color:888888;color:888888" value="888888">灰色</option><option style="background-color:CCAA00;color:CCAA00" value="CCAA00">土黄</option><option style="background-color:FF8800;color:FF8800" value="FF8800">金黄</option><option style="background-color:CC3366;color:CC3366" value="CC3366">暗红</option><option style="background-color:FF00FF;color:FF00FF" value="FF00FF">紫红</option><option style="background-color:3366CC;color:3366CC" value="3366CC">蓝黑</option></select><br>
	  <%
	  rs1.movenext
	  loop
	  end if
	  rs1.close
	  set rs1=nothing
	  %>
	  <br>
	  </td>
    </tr>
	<tr>
  <td height="25" align="right">再加几项&nbsp; </td>
  <td><input type="text" name="votecount" size="4" class="tx" onBlur="setid();" value="0">
  </tr>
	<tr align="center" valign="middle">
      <td height="122" align="right" valign="top"><br>
        选项名称&nbsp; </td>
      <td align="left" id="upid" height="122"></td>
    </tr>
    <tr>
      <td height="25" align="center" colspan="2"><input name="Submit2" type="submit" class="inputs" value=" 修 改 "></td>
    </tr>
  </form>
</table>
<%
end if
end if
End Sub%>
<%Sub ShowVote()
	if id="" or IsNumeric(id)=false then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>参数错误！</li>"
		exit sub
	else
		set rs=Server.CreateObject("Adodb.Recordset")
		sql="select * from JOB_Vote where JOB_Voteid="&id
		rs.open sql,conn,1,1
	if not (rs.bof and rs.eof) then
		JOB_Voteid=rs("JOB_Voteid")
		JOB_VoteTitle=rs("JOB_VoteTitle")
	end if
		sql1="select * from JOB_Vote where JOB_VoteClass="&JOB_Voteid&" order by JOB_Voteid"
		set rs1=Conn.execute(sql1)
		if not(rs1.bof and rs1.eof) then
			totalcount=0
			Do while not rs1.eof
				totalcount=totalcount+rs1("JOB_VoteCount")
				rs1.movenext
			loop
			totalren=totalcount
			if totalcount=0 then
				totalcount=1
			end if

%>
<table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" style="margin:2px 0;">
  <tr>
    <td colspan="3" align="center"><%=JOB_VoteTitle%></td>
  </tr>
  <%
  	rs1.movefirst
   Do while not rs1.eof
  %>
  <tr>
    <td width="35%">&nbsp;投票选项: <%=rs1("JOB_VoteTitle")%></td>
	<%h=clng((rs1("JOB_VoteCount")*300)/totalcount)%>
    <td width="45%" valign="middle" align="left"><hr width="<%=h%>" color="<%=rs1("JOB_VoteColor")%>" style="height:10px;">
			
		
	</td>
    <td width="20%"> <span class="STYLE2"><%=rs1("JOB_VoteCount")%></span> 票(<%=FormatNumber((rs1("JOB_VoteCount")*100)/totalcount,2)%>%)</td>
  </tr>
  <%
  	rs1.movenext
	loop
	end if
  %>
  <tr>
    <td colspan="3" align="right" style=" padding-right:20px;">共有<%=totalren%>人投票</td>
  </tr>
</table>
<%
end if
End Sub%>
<%
sub SaveData()
	if JOB_VoteStart="" or JOB_VoteEnd="" or JOB_VoteTitle="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>信息输入不完整，请重新输入.</li>"
		exit sub
	end if
	dd=DateDiff("d",JOB_VoteStart,JOB_VoteEnd)
	if (cint(dd)-1<0) then		
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>投票结束时间不能早于开始时间</li>"
		exit sub
	end if
	set rs11=Server.CreateObject("ADODB.RecordSet")
	'先把投票项目相关信息写入到数据表中
	sql="Insert into JOB_Vote(JOB_VoteTitle,JOB_VoteStart,JOB_VoteEnd,JOB_VoteStyle,JOB_Voteing) values('"&JOB_VoteTitle&"','"&JOB_VoteStart&"','"&JOB_VoteEnd&"','"&JOB_VoteStyle&"','"&JOB_Voteing&"')"
	conn.execute sql
	sql1="select * from JOB_Vote where JOB_VoteTitle='"&JOB_VoteTitle&"' and JOB_VoteClass=0"
	rs11.open sql1,conn,1,1
		JOB_VoteClassid=rs11("JOB_Voteid")
	rs11.close
	
	JOB_VotesTitles=split(JOB_VotesTitle,",")
	JOB_VoteColors=split(JOB_VoteColor,",")
	for i=0 to ubound(JOB_VotesTitles)
		conn.execute("Insert into JOB_Vote(JOB_VoteTitle,JOB_VoteColor,JOB_VoteClass) values('"&Trim(JOB_VotesTitles(i))&"','"&Trim(JOB_VoteColors(i))&"','"&JOB_VoteClassid&"')")
	next
	response.Redirect "Admin_VoteIndex.asp"
end sub
%>
<%
sub ModifyDataSave()
	if JOB_VoteStart="" or JOB_VoteEnd="" or JOB_VoteTitle="" then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>信息输入不完整，请重新输入.</li>"
		exit sub
	end if
	dd=DateDiff("d",JOB_VoteStart,JOB_VoteEnd)
	if (cint(dd)-1<0) then		
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>投票结束时间不能早于开始时间</li>"
		exit sub
	end if
	'先修改投票项目信息
	sql="update JOB_Vote set JOB_VoteTitle='"&JOB_VoteTitle&"',JOB_VoteStart='"&JOB_VoteStart&"',JOB_VoteEnd='"&JOB_VoteEnd&"',JOB_VoteStyle='"&JOB_VoteStyle&"',JOB_Voteing='"&JOB_Voteing&"' where JOB_Voteid="&id
	conn.execute(sql)
	'更新投票选项的信息
	for j=1 to request.Form("JOB_Voteid").count
		if Trim(request("JOB_VotesTitle")(j))<>"" then
			sql="update JOB_Vote set JOB_VoteTitle='"&Trim(request("JOB_VotesTitle")(j))&"',JOB_VoteColor='"&request("JOB_VoteColor")(j)&"' where JOB_Voteid="&Trim(request("JOB_Voteid")(j))
			conn.execute(sql)
		end if
	next	
	'如果有新添加选项的就执行以下语句
	if JOB_VotesTitless<>"" then
		JOB_VotesTitlesss=split(JOB_VotesTitless,",")
		JOB_VoteColorsss=split(JOB_VoteColorss,",")
		for j=0 to ubound(JOB_VotesTitlesss)
			conn.execute("Insert into JOB_Vote(JOB_VoteTitle,JOB_VoteColor,JOB_VoteClass) values('"&Trim(JOB_VotesTitlesss(j))&"','"&Trim(JOB_VoteColorsss(j))&"','"&id&"')")
		next
	end if
	response.Redirect "Admin_VoteIndex.asp"
end sub
%>
<%
Sub Del()
if id<>"" then
	'删除该投票主题的选项
	conn.execute("delete from JOB_Vote where JOB_VoteClass="&id)
	'删除该投票主题
	conn.execute("delete from JOB_Vote where JOB_Voteid="&id)
	response.redirect "admin_VoteIndex.asp"
	Response.end()
end if
End Sub
%>
<%
Sub VoteDel()
if Voteid<>"" then
	'删除投票选项
	conn.execute("delete from JOB_Vote where JOB_Voteid="&Voteid)
	response.redirect "admin_VoteIndex.asp"
	Response.end()
end if
End Sub
%>
</body>
</html>