<!--#include file="../../fy.Function.asp"-->
<!--#include file="../../../fy_inc/cls_pageview.asp"-->
<!doctype html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>投票管理</title>
<link rel="stylesheet" type="text/css" href="../../css/base.css">
<link rel="stylesheet" type="text/css" href="../../css/content.css">
<script type="text/javascript" src="../../../fy_inc/js/jquery.js"></script>
<script src="../../js/base.js"></script>
</head>
<body>
<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" class="Ainput" name="VoteTitles" value="选项'+i+'" size="40"> 投票数<input type="text" class="Ainput" name="VoteNums" value="0" size="10"><br><br>';
	  window.upid.innerHTML=str;
	  }

$(function(){
 	$.nextshow = function(dom) {
		$(dom).click(function(){
			var $nexttr = $(this).parent("tr").next("tr");
			if($nexttr.is(":hidden")){
				$nexttr.show();
			}else{
				$nexttr.hide();
			}
		});
	};
	$.nextshow('td.look');
 });


</script> 

<div class="content"> 
<div class="breadnav">当前位置：<a href="#">后台首页</a> >> 模型管理</div>
    <div class="opers">
    	<a href="?Action=add" class="btn<%If request("Action")="add" Then echo " btn_primary" %>">新建投票</a>
    	<a href="?" class="btn <%If request("Action")="" Then echo " btn_primary" %>">查看投票</a>
	
    </div> 

<% 
	If Not fycms.fycms_QXYZ(0,"vote","") Then   Call fycms.Alert("对不起，你没有操作权限！","") 
dim Action,ID,ShowErr
	Action = Request("Action")
	ID = Request("ID")
	Select Case Action
			case "add"
				call add()
			Case "edit" 
				Call edit()
			Case "addsave"
				Call addsave()
			Case "editsave"
				Call editsave()
			Case "del"
				Call del()
			Case Else
				Call Main()
	End Select
	
	Sub Del()
		Conn.Execute ("Delete from Vote_fy Where ID=" & ChkNumeric(Request.QueryString("ID")))		
		Conn.Execute ("Delete from Vote_fy Where rootID=" & ChkNumeric(Request.QueryString("ID")))		
		Set conn=nothing
		Call fycms.ActErr("删除成功","Sys_fy/vote/Index.asp","")
 		Response.End
    End Sub
	Sub addsave()
	Dim Rs,content,title,VoteStart,Voteend,i,dd,rs1,cid
	
		VoteStart= fycms.s("VoteStart")
		Voteend= fycms.s("Voteend")
		 IF Not IsDate(VoteStart) Then VoteStart=date
		 IF Not IsDate(Voteend) Then Voteend=date+10
		dd=DateDiff("d",VoteStart,Voteend)
		if (cint(dd)-1<0) then
			Call fycms.ActErr("错误,投票结束时间不能早于开始时间","Sys_fy/vote/Index.asp","")
 			response.end
		end if
 		Set Rs=Server.CreateObject("Adodb.RecordSet")
		Rs.Open "Select * from Vote_fy",Conn,1,3
		Rs.addnew
		Rs("title")= fycms.s("titles")
		Rs("VoteStart")= VoteStart
		Rs("Voteend")= Voteend
		Rs("rootid")= 0
		Rs("rootid")= 0
 		Rs("VoteType")=ChkNumeric(request("VoteType"))
		Rs("isLock")=ChkNumeric(request("isLock"))
  		Rs.update
		Rs.Close
		set rs1=fycms.actexe("select id from Vote_fy  order by id desc")	
		if not rs1.eof then cid=rs1("id")
				
		dim VoteTitles,VoteNums
		VoteTitles = Split(Replace(fycms.s("VoteTitles") , " ", ""),",")
  	    VoteNums = Split(Replace(fycms.s("VoteNums") , " ", ""),",")
 		For I = LBound(VoteTitles) To UBound(VoteTitles)


				Set Rs=Server.CreateObject("Adodb.RecordSet")
				Rs.Open "Select * from Vote_fy",Conn,1,3
				Rs.addnew
				Rs("title")= VoteTitles(i)
				Rs("VoteType")=ChkNumeric(request("VoteType"))
				Rs("isLock")=ChkNumeric(request("isLock"))
				Rs("VoteNum")= ChkNumeric(VoteNums(I))
				Rs("rootid")=CID
				Rs.update
 		next 
 		Set Rs=Nothing
		Call fycms.ActErr("操作成功","Sys_fy/vote/Index.asp","")
 		Response.End
	End Sub	


	Sub editsave()
	Dim DiyPath,Rs,content,title,sql,VoteType,isLock,VoteNum,VoteStart,Voteend,i,dd
		VoteStart= fycms.s("VoteStart")
		Voteend= fycms.s("Voteend")
		 IF Not IsDate(VoteStart) Then VoteStart=date
		 IF Not IsDate(Voteend) Then Voteend=date+10
		dd=DateDiff("d",VoteStart,Voteend)
		if (cint(dd)-1<0) then
			Call fycms.ActErr("错误投票结束时间不能早于开始时间","Sys_fy/vote/Index.asp","1")
 			response.end
		end if
  	    SQL = "Select * From Vote_fy Where ID="&ChkNumeric(request("CID"))
		Set Rs=Server.CreateObject("Adodb.RecordSet")
		Rs.Open SQL,Conn,1,3
		Rs("title")= fycms.s("titles")
		Rs("VoteStart")= VoteStart
		Rs("Voteend")= Voteend
		Rs("VoteType")=ChkNumeric(request("VoteType"))
		Rs("isLock")=ChkNumeric(request("isLock"))
 	    Rs.update:Rs.Close
	
		ID = Split(fycms.s("ID"),",")
		title = Split(Replace(fycms.s("title") , " ", ""),",")
		VoteNum = Split(Replace(fycms.s("VoteNum") , " ", ""),",")
 	    For I = LBound(ID) To UBound(ID)
 			SQL = "Select * From Vote_fy Where ID="&ID(I)
			if title(I)="" then  
 				Conn.execute("Delete from Vote_fy  Where id= "&ID(I))
			else 
				Set Rs=Server.CreateObject("Adodb.RecordSet")
				Rs.Open SQL,Conn,1,3
				Rs("title")= title(I)
				Rs("VoteType")=ChkNumeric(request("VoteType"))
				Rs("isLock")=ChkNumeric(request("isLock"))
				Rs("VoteNum")= ChkNumeric(VoteNum(I))
				Rs.update
			end if
    	Next 
		dim VoteTitles,VoteNums
		VoteTitles = Split(Replace(fycms.s("VoteTitles") , " ", ""),",")
  	    VoteNums = Split(Replace(fycms.s("VoteNums") , " ", ""),",")
 		For I = LBound(VoteTitles) To UBound(VoteTitles)


				Set Rs=Server.CreateObject("Adodb.RecordSet")
				Rs.Open "Select * from Vote_fy",Conn,1,3
				Rs.addnew
				Rs("title")= VoteTitles(i)
				Rs("VoteType")=ChkNumeric(request("VoteType"))
				Rs("isLock")=ChkNumeric(request("isLock"))
				Rs("VoteNum")= ChkNumeric(VoteNums(I))
				Rs("rootid")= ChkNumeric(request("CID"))
				Rs.update
	
 		
		next 
		Call fycms.ActErr("修改成功","Sys_fy/vote/Index.asp","")
 		Response.End
	End Sub	

	sub Main()
	Dim ShowErr
	ConnectionDatabase
	Dim strLocalUrl
	strLocalUrl = request.ServerVariables("SCRIPT_NAME")
	Dim intPageNow
	intPageNow = request.QueryString("page")
	Dim intPageSize, strPageInfo
	intPageSize = 20
 	Dim arrinfo, i
	Dim sql, sqlCount,Sqls,ChannelID
	sql = "SELECT [ID],[title],[VoteType],[isLock],[VoteStart],[Voteend]" & _
		" FROM [Vote_fy] where rootid=0 " & _
		"ORDER BY [ID] DESC"
	sqlCount = "SELECT Count([ID])" & _
			" FROM [Vote_fy]   where rootid=0 "
		Dim clsRecordInfo
		Set clsRecordInfo = New Cls_PageView
			clsRecordInfo.intRecordCount = 2816
			clsRecordInfo.strSqlCount = sqlCount
			clsRecordInfo.strSql = sql
			clsRecordInfo.intPageSize = intPageSize
			clsRecordInfo.intPageNow = intPageNow
			clsRecordInfo.strPageUrl = strLocalUrl
			clsRecordInfo.strPageVar = "page"

		clsRecordInfo.objConn = Conn		
		arrinfo = clsRecordInfo.arrinfo
		strPageInfo = clsRecordInfo.strPageInfo
		Set clsRecordInfo = nothing
	 %>
 <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <thead>
      <tr>
      <th>ID</th>
	  <th>投票主题</th>
	  <th>投 票 数</th>
	  <th>投票类型</th>
	  <th>调用代码</th>
	  <th>开始时间</th>
	  <th>结束时间</th>
	  <th>常规管理操作</th>
	  </tr>
    </thead>


	 <%
		Dim bgColor
		If IsArray(arrinfo) Then
			For i = 0 to UBound(arrinfo, 2)
	%>
    <tr>
      <td align="center"  ><%= arrinfo(0,i) %></td>
      <td align="center"  ><%= arrinfo(1,i) %></td>
      <td align="center"  >	 </td>
      <td align="center"  ><%if  arrinfo(2,i)="0" then 
	  	echo "单选"
	  else
	  	echo "多选"
 	  end if  %></td>
      <td align="center" class="look">查看</td>
      <td align="center"  ><%= arrinfo(4,i) %></td>
      <td align="center"  ><%= arrinfo(5,i) %></td>
      <td  align="center" >
      
       <% if  arrinfo(3,i)="0" then 
	  	echo "<font color=green>正常</font>"
	  else
	  	echo "<font color=red>锁定</font>"
 	  end if   %>
     ┆ 
      <a href="?Action=edit&ID=<%= arrinfo(0,i) %>">编辑&nbsp;</a>┆
	 <a href="?Action=del&ID=<%= arrinfo(0,i) %> " onClick="return confirm('确认删除吗?此操作不可恢复!')">删除</a></td>
    </tr>
	
<tr id="daima<%=i%>" style="display:none;"><td colspan="9" align="center">
	<input type="text" class="Ainput" size="80" value="<script language='javascript' src='<%=fycms.actsys %>Plus/Vote/TypeVote.asp?ID=<%=arrinfo(0,i)%>'></script>"> 
	请将此段代码加到要显示投票的位置，该位置将显示该项投票内容
</td></tr>	
	<% 
	Next
	End If
	%>
  
    <tr >
      <td height="25" colspan="9" align="center" ><%= strPageInfo%></td>
    </tr>
   
   
   </table>

  <% end sub
  sub add()
 
   %>
  
<table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="table">
<form name="form1" method="post" action="Index.asp?Action=addsave">  <tr>
       <th class="bg_tr" colspan=2 height=25>修改投票项目</th>
 </tr>
     <tr>
       <td width="170" height="25" align="right"><strong>项目标题</strong><b>：</b></td>
       <td class="tl"><input name="titles" type="text" class="Ainput" size="40" value="选项1"></td>
     </tr>
     <tr>
       <td height="25" align="right"><strong>投票方式</strong><b>：</b></td>
       <td class="tl">   
        <input title="设置单选投票" type="radio" name="VoteType" id="VoteType1" value="0"   ><label for="VoteType1">单选</label>
      &nbsp;&nbsp;
    <input title="设置多选投票" type="radio" name="VoteType" id="VoteType2" value="1"  Checked ><label for="VoteType2">多选</label> </td>
</td>
     </tr>
     <tr>
       <td height="25" align="right"><strong>是否锁定</strong><b>：</b></td>
       <td class="tl"> <label for="isLock1"><input type="radio" name="isLock"  id="isLock1" value="0"   Checked>否</label>
     <label for="isLock2"><input type="radio" name="isLock"  id="isLock2"  value="1"   >是</label></td>
     </tr>
     <tr>
       <td height="25" align="right"><strong>投票时间</strong><b>：</b></td>
       <td class="tl">&nbsp;开始于
         <input onClick="WdatePicker()"  size=10  type="text" class="Ainput"   name="VoteStart" id="VoteStart" value="<%= date() %>"/>
         结束于
         <input onClick="WdatePicker()"  size=10 type="text" class="Ainput"    name="VoteEnd" id="VoteEnd" value="<%= date()+10 %>"/></td>
     </tr>
     
     
     
     <tr>
       <td height="25" align="right"> <strong>再加几项</strong><b>：</b>&nbsp; </td>
     <td class="tl"><input type="text" class="Ainput" name="votecount" size="4"  onBlur="setid();" value="4"> 
       <input type="button" name="button" id="button" class="btn btn_primary"  value="增加" onClick="setid()">如果要删除某项.可以将该选项内容留空           </tr>
     <tr align="center" valign="middle">
       <td height="122" align="right" valign="top"><br>
         <strong>选项名称</strong><b>：</b>&nbsp; </td>
       <td align="left" id="upid"  class="tl"></td>
     </tr>
    
     
     <tr>
       <td  class="tl" colspan="2"><input type=button onclick=CheckForm() class="btn btn_primary"  name=Submit1 value="  保存  " />
&nbsp;&nbsp;&nbsp;&nbsp;
<input name="Submit2" type="reset" class="btn btn_primary" value="  重置  "></td>
    </tr>
</form></table>  
<script language="javascript">
setid();
</script>
<%   end sub 
  
  
  
	sub edit()
	Dim Rs,title,frmAction,VoteType,isLock,VoteNum
	
  		Set Rs=Conn.Execute("Select * from Vote_fy Where ID=" & ID)
			if Rs.Bof And Rs.EOF then
				 echo "不存在！"
				Exit Sub
			End IF	
  	 
  %> 
<table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="table">
<form name="form1" method="post" action="Index.asp?Action=editsave&CID=<%=ID  %>">  <tr>
       <th class="bg_tr" colspan=2 height=25>修改投票项目</th>
     </tr>
     <tr>
       <td width="170" height="25" align="right"><strong>项目标题</strong><b>：</b></td>
       <td  class="tl"><input name="titles" type="text" class="Ainput" size="40" value="<%= rs("title") %>"></td>
     </tr>
     <tr>
       <td height="25" align="right"><strong>投票方式</strong><b>：</b></td>
       <td class="tl">   
        <input title="设置单选投票" type="radio" name="VoteType" id="VoteType1" value="0"   <% if rs("VoteType")="0" then echo "Checked" %>><label for="VoteType1">单选</label>
       
    <input title="设置多选投票" type="radio" name="VoteType" id="VoteType2" value="1"  <% if rs("VoteType")="1" then echo "Checked" %> ><label for="VoteType2">多选</label> </td>
</td>
     </tr>
     <tr>
       <td height="25" align="right"><strong>是否锁定</strong><b>：</b></td>
       <td  class="tl"> <label for="isLock1"><input type="radio" name="isLock"  id="isLock1" value="0"   <% if rs("isLock")="0" then echo "Checked" %>>否</label>
    
    <label for="isLock2"><input type="radio" name="isLock"  id="isLock2"  value="1"   <% if rs("isLock")="1" then echo "Checked" %>>是</label></td>
     </tr>
     <tr>
       <td height="25" align="right"><strong>投票时间</strong><b>：</b></td>
       <td class="tl">&nbsp;开始于
         <input onClick="WdatePicker()" size=10   type="text" class="Ainput"  name="VoteStart" id="VoteStart" value="<%=rs("VoteStart")  %>"/>
         结束于
         <input onClick="WdatePicker()"  size=10  type="text" class="Ainput"   name="VoteEnd" id="VoteEnd" value="<%=rs("VoteEnd")  %>"/></td>
     </tr>
     
     
     <%
	  dim rs1,k:k=1
 	  set rs1=conn.execute("select * from Vote_fy where rootid="&ID)
	  if not rs1.eof then
	  do while not rs1.eof
	  %>
     <tr>
       <td  align="right"><b>投票选项<%= k %>：</b></td>
       <td  class="tl"><INPUT TYPE="hidden" name="ID" value="<%=rs1("ID")%>">
       <input type="text" class="Ainput" name="title" size="20" value="<%=rs1("title")%>">
         投票数：
         <input type="text" class="Ainput" name="VoteNum" size="10" value="<%=rs1("VoteNum")%>"> ID：<%=rs1("id")%></td>
     </tr>
 <%	k=k+1
	  rs1.movenext
	  loop
	  end if
	  rs1.close
	  set rs1=nothing
	  %>
     <tr>
       <td height="25" align="right"> <strong>再加几项</strong><b>：</b>&nbsp; </td>
     <td  class="tl"><input type="text" class="Ainput" name="votecount" size="4"  onBlur="setid();" value="1"> 
       <input type="button" name="button" id="button" class="btn btn_primary"  value="增加" onClick="setid()">如果要删除某项.可以将该选项内容留空           </tr>
     <tr align="center" valign="middle">
       <td height="122" align="right" valign="top"><br>
         <strong>选项名称</strong><b>：</b>&nbsp; </td>
       <td align="left" id="upid"  class="tl"></td>
     </tr>
     <tr>
       <td   colspan="2"  class="tl"><input type=button onclick=CheckForm() class="btn btn_primary"  name=Submit1 value="保存" />
 
<input name="Submit2" type="reset" class="btn btn_primary" value="重置"></td>
     </tr>
</form></table> 
  
 

 
 
 
	<%end sub
CloseConn %>
<script language="javascript">
 	
function CheckForm()
{ var form=document.form1;
	 if (form.title.value=='')
		{ alert("请输入投票名称!");   
		  form.title.focus();    
		   return false;
		} 
 	    form.submit();
        return true;
	}</script> 
</div>
</body>
</html>

