<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%option explicit%>
<!--#include file="../Conn.asp"-->
<!--#include file="../HSK_Cls/HSK.CommonCls.asp"-->
<!--#include file="../HSK_Cls/HSK.Label.BaseFunCls.asp"-->
<!--#include file="../HSK_Cls/HSK.AdministratorCls.asp"-->
<!--#include file="../HSK_Cls/HSK.UpFileCls.asp"-->
<!--#include file="Include/Session.asp"-->
<%

Dim KSCls
Set KSCls = New Admin_EnterPrise
KSCls.HSK_Run()
Set KSCls = Nothing

Class Admin_EnterPrise
        Private KS,Param,KSCls,subjectID
		Private Action,i,strClass,RS,SQL,maxperpage,CurrentPage,totalPut,TotalPageNum
        Private Sub Class_Initialize()
		  Set KS=New PublicCls
		  Set KSCls=New ManageCls
		End Sub
        Private Sub Class_Terminate()
		 Call CloseConn()
		 Set KS=Nothing
		End Sub

		Public Sub HSK_Run()
		 With Response
		   	 If Not KS.ReturnPowerResult(0, "M530002") Then          '检查是权限
					 Call KS.ReturnErr(1, "")
					 .End
			 End If
			  .Write "<html>"
			  .Write"<head>"
			  .Write"<meta http-equiv=""Content-Type"" content=""text/html; charset=gb2312"">"
			  .Write"<link href=""Include/Admin_Style.CSS"" rel=""stylesheet"" type=""text/css"">"
			  .Write "<script src=""../HSK_JS/Common.js"" language=""JavaScript""></script>"
			  .Write "<script src=""../HSK_JS/jquery.js"" language=""JavaScript""></script>"
			  .Write "<script src='../HSK_JS/HSK.box.js'></script>"
			  .Write"</head>"
			  .Write"<body leftmargin=""0"" topmargin=""0"" marginwidth=""0"" marginheight=""0"">"
			  If KS.G("action")<>"ShowUser" Then
			  .Write "<ul id='menu_top'>"
			  .Write "<li class='parent' onclick=""location.href='GroupBuy.asp';""><span class=child onmouseover=""this.parentNode.className='parent_border'"" onMouseOut=""this.parentNode.className='parent'""><img src='images/ico/a.gif' border='0' align='absmiddle'>团购管理</span></li>"
			  .Write "<li class='parent' onclick=""location.href='GroupBuyInt.asp';""><span class=child onmouseover=""this.parentNode.className='parent_border'"" onMouseOut=""this.parentNode.className='parent'""><img src='images/ico/move.gif' border='0' align='absmiddle'>兴趣活动分类管理</span></li>"
			  .Write "<li style='margin-left:30px;margin-top:10px'><strong>查看方式:</strong><a href=""GroupBuy.asp"">所有团购</a> <a href=""GroupBuy.asp?flag=1"">进行中的团购</a>  <a href=""GroupBuy.asp?flag=2"">已结束的团购</a> <a href=""GroupBuy.asp?flag=3"">已锁定的团购</a></li>"
             End If
			  .Write "</ul>"
		End With
		
		
		maxperpage = 30 '###每页显示数
		If Not IsNumeric(Request("page")) And Len(Request("page")) <> 0 Then
			Response.Write ("错误的系统参数!请输入整数")
			Response.End
		End If
		If Not IsEmpty(Request("page")) And Len(Request("page")) <> 0 Then
			CurrentPage = CInt(Request("page"))
		Else
			CurrentPage = 1
		End If
		If CInt(CurrentPage) = 0 Then CurrentPage = 1
		SubjectID=KS.ChkCLng(KS.S("SubjectID"))
		Param=" where 1=1"
		If KS.G("KeyWord")<>"" Then
		   Param= Param & " and Item like '%" & KS.G("KeyWord") & "%'"
		End If

		totalPut = Conn.Execute("Select Count(id) From KS_GroupBuyInt " & Param)(0)
		TotalPageNum = CInt(totalPut / maxperpage)  '得到总页数
		If TotalPageNum < totalPut / maxperpage Then TotalPageNum = TotalPageNum + 1
		If CurrentPage < 1 Then CurrentPage = 1
		If CurrentPage > TotalPageNum Then CurrentPage = TotalPageNum
		Select Case KS.G("action")
		 Case "ShowUser" Call ShowUser()
		 Case "Add","Edit" Call ItemManage()
		 Case "EditSave" Call DoSave()
		 Case "Del"  Call BMDel()
		 Case "lock"  Call BMLock()
		 Case "unlock"  Call BMUnLock()
		 Case Else
		  Call showmain
		End Select
End Sub

Private Sub showmain()
%>
<table width="100%" border="0" align="center" cellspacing="0" cellpadding="0">
 <tr>
   <td></td>
   <td style="font-size:14px;text-align:right;font-weight:Bold;padding-right:20px"><img src="images/qs.gif" align="absmiddle">
<a href="#" onclick="javascript:window.parent.frames['BottomFrame'].location.href='Split.asp?OpStr='+escape('团购系统 >> <font color=red>添加兴趣</font>')+'&ButtonSymbol=GOSave';location.href='GroupBuyInt.asp?action=Add&subjectid=<%=SubjectID%>'">添加兴趣</a></td>
 </tr>
</table>
<script>
  function note(items)
	{     
	onscrolls=false;
    new KesionPopup().PopupCenterIframe("查看对"+items+"感兴趣的用户","?Action=ShowUser&item="+items,580,280,'auto')
	 }
</script>

<table width="100%" border="0" align="center" cellspacing="0" cellpadding="0">
<tr height="25" align="center" class='sort'>
	<td width='5%' nowrap>选择</th>
	<td nowrap>分类名称</th>
	<td nowrap>关注人数</th>
	<td nowrap>操作</th>
	<td width='5%' nowrap>选择</th>
	<td nowrap>分类名称</th>
	<td nowrap>关注人数</th>
	<td nowrap>操作</th>
</tr>
<%
	Set Rs = Server.CreateObject("ADODB.Recordset")
	SQL = "select ID,Item from KS_GroupBuyInt " & Param & " Order By OrderID asc,id desc"
	If DataBaseType = 1 Then
		If CurrentPage > 100 Then
			Rs.Open SQL, Conn, 1, 1
		Else
			Set Rs = Conn.Execute(SQL)
		End If
	Else
		Rs.Open SQL, Conn, 1, 1
	End If
	If Rs.bof And Rs.EOF Then
		Response.Write "<tr><td height=""25"" align=center bgcolor=""#ffffff"" colspan=7>没有添加任何兴趣！</td></tr>"
	Else
		If TotalPageNum > 1 then Rs.Move (CurrentPage - 1) * maxperpage
		Dim i,n,k
		Dim SQLs:SQLs=RS.GetRows(-1)
		RS.Close:Set RS=Nothing
%>
<form name=selform method=post action=?action=Del>
<%
    n=0
	For I=0 To Ubound(SQLs,2)
		
%>
<tr height="25" class='list' onMouseOver="this.className='listmouseover'" onMouseOut="this.className='list'">
    <%For K=1 To 2%>
	<td align="center" class="splittd"><input type=checkbox name=ID value='<%=SQLs(0,n)%>'>
	
	</td>
	<td class="splittd"><%=n+1%>、<%=SQLs(1,n)%></td>
	<td class="splittd" align="center">
	<span style="color:red;font-weight:Bold">
	<%
	 Response.Write LFCls.GetSingleFieldValue("Select count(id) From KS_GroupBuyBM Where interest Like '%" & SQLs(1,n) & "%'")
	%>
	</span>
	
	(<a href="#" onclick="note('<%=SQLs(1,n)%>');">查看</a>)</td>


	<td align="center" class="splittd"><a href="?action=Edit&ID=<%=SQLs(0,n)%>&SubjectID=<%=SubjectID%>"  onclick="window.parent.frames['BottomFrame'].location.href='Split.asp?OpStr='+escape('团购系统 >> <font color=red>修改报名信息</font>')+'&ButtonSymbol=GOSave';">改</a> <a href="?Action=Del&ID=<%=SQLs(0,n)%>&SubjectID=<%=SubjectID%>" onclick="return(confirm('确定删除该报名吗？'));">删</a> 
	</td>
  <%
   n=n+1
   If N>Ubound(SQLs,2) Then Exit For
  Next
  %>
</tr>
<%
      If N>Ubound(SQLs,2) Then Exit For
 Next
End If
%>
<tr>
	<td class='list' onMouseOver="this.className='listmouseover'" onMouseOut="this.className='list'" height='25' colspan=11>
	&nbsp;&nbsp;<input id="chkAll" onClick="CheckAll(this.form)" type="checkbox" value="checkbox"  name="chkAll">全选
	<input class=Button type="submit" name="Submit2" value=" 删除选中的兴趣 " onclick="{if(confirm('此操作不可逆，确定要删除选中的记录吗?')){this.document.selform.submit();return true;}return false;}">
	
		<input type="button" class="button" value="打印本页" onclick='window.print()'>

	</td>
</tr>
</form>
<tr>
	<td  colspan=17 align=right>
	<%
	 Call KSCLS.ShowPage(totalPut, MaxPerPage, "GroupBuyInt.asp", True, "个", CurrentPage, KS.QueryParam("page"))
	%></td>
</tr>
</table>
<div>
<form action="GroupBuyInt.asp" name="myform" method="get">
   <input type="hidden" value="<%=SubjectID%>" name="subjectid">
   <div style="border:1px dashed #cccccc;margin:3px;padding:4px">
      &nbsp;<strong>快速搜索=></strong>
	 &nbsp;关键字:<input type="text" class='textbox' name="keyword">&nbsp;
	 
	 <!--条件:
	 <select name="condition">
	  <option value=1>按名称</option>
	 </select>
	 -->
	  &nbsp;<input type="submit" value="开始搜索" class="button" name="s1">
    </div>
</form>
</div>
<%
End Sub

Sub ItemManage()
Dim Item,AddDate,Mobile,Acceptsms,Interest,Status,Subjectid,OrderID
Dim ID:ID=KS.ChkClng(KS.G("ID"))
If KS.G("Action")="Edit" Then
    Dim RS:Set RS=server.createobject("adodb.recordset")
	RS.Open "Select * From KS_GroupBuyInt Where ID=" & ID,conn,1,1
	 If RS.Eof And RS.Bof Then
	  RS.Close:Set RS=Nothing
	  Response.Write "<script>alert('参数传递出错！');history.back();</script>"
	  Response.End
	 Else
	   Item=RS("Item")
	   Subjectid=RS("Subjectid")
	   OrderID=RS("OrderID")
	 End If
	 RS.Close:Set RS=Nothing
Else
  AddDate=Now
  Status=1
  Subjectid=KS.ChkClng(KS.G("Subjectid"))
  OrderID=KS.ChkClng(LFCls.GetSingleFieldValue("Select Max(OrderID) From KS_GroupBuyInt"))+1
End If
%>
<script>
function CheckForm()
{
	if ($('#Item').val()=='')
	{
	 alert('请输入兴趣分类名称!');
	 $("#Item").focus();
	 return false;
	}
document.myform.submit();
}
</script>
 <br>
 <div style="height:30px;text-align:center;font-weight:Bold">
 <%If ID=0 Then
    response.write "添加兴趣分类"
   else
    response.write "修改兴趣分类"
   end if
 %>
 </div>
<table width="80%" border="0" align="center" cellpadding="1" cellspacing="1" class="ctable">
 <form name="myform" action="?action=EditSave" method="post">
   <input type="hidden" value="<%=ID%>" name="id">
   <input type="hidden" value="<%=request.servervariables("http_referer")%>" name="comeurl">
          <tr class="tdbg" onMouseOver="this.className='tdbgmouseover'" onMouseOut="this.className='tdbg'">
            <td  width='160' height='30' align='right' class='clefttitle'><strong>兴趣名称：</strong></td>
            <td height='30' colspan="2">&nbsp;<input type='text' name='Item' id='Item' value='<%=Item%>' size="40"> <font color=red>*</font></td>
          </tr> 
          <tr class="tdbg" onMouseOver="this.className='tdbgmouseover'" onMouseOut="this.className='tdbg'">
            <td  width='160' height='30' align='right' class='clefttitle'><strong>所属团购主题：</strong></td>
            <td height='30' colspan="2">&nbsp;<select name="SubjectID">
			<option value="0">---不指定(通用)---</option>
			<%
			 Set RS=Conn.Execute("Select ID,Subject From KS_GroupBuy Order BY ID Desc")
			 Do While Not RS.Eof 
			  If (RS(0)=SubjectID) Then
			   Response.Write "<option value=" & RS(0) & " selected>" & RS(1) & "</option>"
			  Else
			   Response.Write "<option value=" & RS(0) & ">" & RS(1) & "</option>"
			  End If
			  RS.MoveNext
			 Loop
			 RS.Close:Set RS=Nothing
			%>
			</select>			</td>
          </tr>
          <tr class="tdbg" onMouseOver="this.className='tdbgmouseover'" onMouseOut="this.className='tdbg'">
            <td height='30' align='right' class='clefttitle'><strong>排列顺序号:</strong></td>
            <td height='30' colspan="2"> &nbsp;<input type='text' name='OrderID' value='<%=OrderID%>' size="8" /> (从小->大)</td>
          </tr> 
</form>	   
		  </table>
		 
 
<%
End Sub

Sub DoSave()

       Dim ID:ID=KS.ChkClng(KS.G("id"))
	   Dim Item:Item=KS.LoseHtml(KS.G("Item"))
	   Dim SubjectID:SubjectID=KS.ChkClng(KS.G("SubjectID"))
	   Dim OrderID:OrderID=KS.ChkClng(KS.G("OrderID"))

		
	        If Item="" Then Response.Write "<script>alert('兴趣分类名称输入!');history.back();</script>":response.end

            If Not Conn.Execute("Select * From KS_GroupBuyInt Where Item='" & Item & "' And ID<>" & ID).Eof Then
			 Call KS.AlertHistory("对不起,该兴趣分类名称已存在!",-1)
			 Exit SUb
			End If

            Dim RS: Set RS=Server.CreateObject("Adodb.RecordSet")
			
			  RS.Open "Select * From KS_GroupBuyInt Where ID=" & ID,Conn,1,3
			  If RS.Eof And RS.Bof Then
			     RS.AddNEW
			  End If
			     RS("Item")=Item
				 RS("SubjectID")=SubjectID
				 RS("OrderID")=OrderID
		 		 RS.Update
			     RS.Close
				 Set RS=Nothing
				 
				 If ID=0 Then
				  Response.Write "<script>if (confirm('兴趣分类添加成功,继续添加吗?')){location.href='?action=Add&Subjectid=" & SubjectId& "';}else{parent.frames['BottomFrame'].location.href='Split.asp?ButtonSymbol=Disabled&OpStr=" & Server.URLEncode("团购系统 >> <font color=red>兴趣分类管理</font>") & "';location.href='GroupBuyInt.asp?subjectid=" & subjectid & "';}</script>"
				 Else
				 
				  Response.Write "<script>alert('兴趣分类修改成功！');parent.frames['BottomFrame'].location.href='Split.asp?ButtonSymbol=Disabled&OpStr=" & Server.URLEncode("团购系统 >> <font color=red>兴趣分类管理</font>") & "';location.href='"& KS.G("ComeUrl") & "';</script>"
				 End If

EnD Sub

'删除
Sub BMDel()
 Dim ID:ID=KS.G("ID")
 Dim UserName,DefaultTemplateID
 If ID="" Then Response.Write "<script>alert('对不起，您没有选择!');history.back();</script>":response.end
 Conn.execute("Delete From KS_GroupBuyInt Where id In("& id & ")")
 Response.Write "<script>alert('删除成功！');location.href='" & Request.servervariables("http_referer") & "';</script>"
End Sub


'锁定
Sub BMLock()
 Dim ID:ID=KS.G("ID")
 If ID="" Then Response.Write "<script>alert('对不起，您没有选择!');history.back();</script>":response.end
 Conn.execute("Update KS_GroupBuyInt Set Status=0 Where id In("& id & ")")
 Response.Write "<script>location.href='" & Request.servervariables("http_referer") & "';</script>"
End Sub
'解锁
Sub BMUnLock()
 Dim ID:ID=KS.G("ID")
 If ID="" Then Response.Write "<script>alert('对不起，您没有选择!');history.back();</script>":response.end
 Conn.execute("Update KS_GroupBuyInt Set Status=1 Where id In("& id & ")")
 Response.Write "<script>location.href='" & Request.servervariables("http_referer") & "';</script>"
End Sub

Sub ShowUser()
 Response.Write "<style>" & vbcrlf
 Response.Write ".l{margin-left:10px;margin-top:10px;width:600px;}"
 response.write ".l li{width:200px;float:left}"
 response.write "</style>"
 Dim Item:Item=KS.G("Item")
 Dim n:n=1
 Dim RS:Set RS=Server.CreateObject("ADODB.RECORDSET")
 RS.Open "Select RealName,Mobile From KS_GroupBuyBM Where Interest Like '%" & Item & "%'",conn,1,1
   Response.Write "<div class='l'>"
   If RS.Eof And RS.Bof Then
     Response.Write "对不起，没有用户对<font color=red>" & item & "</font>感兴趣!"
   Else
	 Do While Not RS.Eof
	   Response.Write "<li>" & N & "、<font color=#ff6600>" & RS(0) & "</font>(联系方式:" & RS(1) & ")</li>"
	   n=n+1
	   RS.MoveNext
	 Loop
   End If
	   Response.Write "</div>"
 RS.Close:Set RS=Nothing
End Sub
End Class
%> 
