<!--#include file="../conn.asp"-->
<!--#include file="admin_check.asp"-->
<!--#include file="../inc/function.asp"-->
<!--#include file="../inc/class_upload.asp"-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>管理页面</title>
<link id="maincss" rel="stylesheet" href="images/css/admin_style_<%= AdminSkin %>.css" type="text/css" media="all" />
<script language="javascript">
        function Change(n,a,l,i)
		  {
         document.location.href='?mstep='+ n +'&act='+ a +'&listn='+ l +'&ClassId='+ i
          }
		  
	function modify(bb,aa,cname,id)
		{
			if(bb.innerText==cname)
			{
			bb.innerHTML="<form action=?act=modify&classid="+id+" method=post><input name=classname type=text size=20 value="+cname+"> &nbsp;<input name=Submit type=submit value=修改名称></form>";
			aa.innerHTML="<font color=red><b>取消</b></font>"
			}
			else
			{
			bb.innerHTML="<a href=?ClassId="+id+">"+cname+"</a>";
			aa.innerHTML="修改"
		}
	}
</script>
<style type="text/css">
<!--
#star {
	background-image: url(Images/icons.gif);
	background-position: 0px 80px;
	height: 16px;
	width: 16px;
	margin-right: 6px;
	margin-left: 6px;
}
ul {
	margin: 0px;
	padding: 0px;
}
li {
	margin: 0px;
	padding: 0px;
}
-->
</style>
</head>
<body leftmargin="0" bottommargin="0" rightmargin="0" topmargin="5" marginheight="0" marginwidth="0" bgcolor="#DDEEFF">
<% 
Call chkFlag(2)

Response.Buffer = True 
Response.Expires = -1
Response.ExpiresAbsolute = Now() - 1 
Response.Expires = 0 
Response.CacheControl = "no-cache"
dim act,esnum,tempName,tempID
act=Trim(Request.QueryString("act"))
esnum=Trim(Request.QueryString("ClassId"))
   if esnum="" then
      esnum=0 
   end if
   
opendb
Dim ClassD
Set ClassD = Server.CreateObject("KwAsk.myClass")
	set ClassD.myConn =conn
	ClassD.myPredb =predb
	ClassD.MyesNum=esnum

if act<>"" then
	application.Lock()
	Application("IndexClass")=""
	Application("myClassxml")=""
	application.UnLock()
end if	
select case act
  case "addlist"
      call ClassD.addlist()
  case "modify"
      call modify()
  case "down"
      call ClassD.movedown()
  case "up"
      call ClassD.moveup()
  case "boforedel"
      call Boforedel()
  case "del"
      call ClassD.del()
  case "saveupfileF"
      call savestrong()
  case "shutstrong"
      call shutstrong()
  case "strong"
      call strong()
  case else
     call show()
end select
set ClassD.myConn =nothing
Set ClassD = nothing
closedb
Sub modify()
  Dim rs, sql, ClassId, ClassName
  ClassId = Trim(Request.QueryString("classid"))
  ClassName = Trim(Request.Form("classname"))
    If ClassName = "" Then
      Call SendMsg("分类名称不能为空！")
      Response.End
    End If
    Set rs = Server.CreateObject("adodb.recordset")
    sql = "select * from " & predb & "Class where Classid=" & ClassId
    rs.open sql, conn, 1, 3
    rs("Classname") = ClassName
    rs.Update
    rs.Close
    Set rs = Nothing
    Response.Write ("<script>history.go(-1);</script>")
End Sub

Sub shutstrong()
  dim classid
  classid=Trim(Request.QueryString("classid"))
  Conn.execute("update "&predb&"class set isb=0 where classid="&classid)
	
    Call SendMsg("取消推荐成功")
    Response.Write("<script>setTimeout(""location.href='?'"",2000)</script>")
End Sub

Sub savestrong()
  Dim UpFile,sSavePath,UstrFtyp,ufl,pSavePath  
  Dim rs,sql,classid,counts,bstr,check,UpFiles
  
	sSavePath ="../UploadFile/"&Year(date())&Right("0"&Month(date()),2)&"/"
    pSavePath=replace(sSavePath,"../UploadFile/","")
	Dim oFSO,oFile
	oFile=server.MapPath(sSavePath)
	Set oFSO = server.CreateObject("Scripting.FileSystemObject")
	if oFSO.FolderExists(oFile)=false then
	   oFSO.CreateFolder(oFile)
	end if
	Set oFSO = Nothing
	
	set UpFile = New UpLoadClass
	UpFile.AutoSave = 2
	UpFile.MaxSize =  Int(200 * 1024) '# (1024*1024=1M) SESSION里的单位为KB
	UpFile.FileType = "gif/jpg/png/bmp/jpeg"
	UpFile.SavePath = sSavePath
	UpFile.Open()
	If UpFile.Save("upfile",0) Then
	    UstrFtyp=Ucase(UpFile.strFtyp)
		IF UstrFtyp="TEXT/PLAIN" Then
		Response.Write "<div style=""padding:6px"">注意：请上传正确文件！</div>"
		Response.End()
		End IF
	Else
		Select Case UpFile.Form("upfile_Err")
		Case -1 : Response.Write ""  '允许不上传文件
		Case 1 : Response.Write "文件大小超出限制，请返回重新上传":Response.End()
		Case 2 : Response.Write "不允许上传的文件类型，请返回重新上传":Response.End()
		Case 3 : Response.Write "文件大小超出限制并且是不允许上传的文件类型，请返回重新上传":Response.End()
		Case Else : Response.Write "未知错误，请返回重新上传":Response.End()
		End Select
	End If


  classid=Trim(Request.QueryString("classid"))
  Bstr=UpFile.Form("bstr")
  check=UpFile.Form("check")
  upfiles=UpFile.Form("upfile")
  Set UpFile=nothing
  
  IF bstr="" Then
     Call SendMsg("请填写推荐说明")
     Response.Write("<script>setTimeout(""history.go(-1)"",2000)</script>")
	 Response.End()
  End IF
  
	Set rs= Server.CreateObject("adodb.recordset")
	sql="select isB,Btime,Bask,Bstr,upfile from "&predb&"Class where Classid="&ClassID
	rs.open sql,conn,1,3
	rs("isB")=1
	rs("Btime")=now()
	rs("Bask")=check
	rs("Bstr")=bstr
	
  IF upfiles="" and( rs("upfile")="" or isnull(rs("upfile")) ) Then
     Call SendMsg("请上传推荐图片")
     Response.Write("<script>setTimeout(""history.go(-1)"",2000)</script>")
	 Response.End()
  End IF
	
  IF upfiles<>"" Then
      Dim Fso
      Set FSO = server.CreateObject("Scripting.FileSystemObject")
	    IF FSO.FileExists(Server.mappath("../UploadFile/"&rs("upfile"))) Then
           FSO.DeleteFile server.MapPath("../UploadFile/"&rs("upfile")),True
	    End IF
      Set FSO = Nothing
      rs("upfile")=pSavePath&upfiles
  End IF	
	rs.update
	rs.close
	set rs=nothing
	
    Call SendMsg("分类推荐成功")
    Response.Write("<script>setTimeout(""location.href='?'"",2000)</script>")
End Sub

Sub Strong()
dim classid,rs,classname,bask,bstr,Checked,upfile
classid=Trim(Request.QueryString("classid"))
set rs=conn.execute("select classname,bask,bstr,upfile from "&predb&"class where classid="&classid)
classname=rs("classname")
bask=","&rs("bask")&","
bstr=rs("bstr")
upfile=rs("upfile")
set rs=nothing
%>
<table class="tableBorder" cellspacing="1" cellpadding="2" width="96%" align="center" border="0">
  <tr>
	<th height="25" colspan="2" align="left"><span id="star"></span> <%= classname %></th>
  </tr>
  <form method="post" action="?act=saveupfileF&classid=<%= classid %>" enctype="multipart/form-data">
  <tr>
    <td align="right" class="TableRow1"><strong>推荐简要说明：</strong></td>
    <td class="TableRow1"><input name="bstr" type="text" id="bstr" size="68" maxlength="150" value="<%= bstr %>"></td>
  </tr>
  <tr>
    <td align="right" class="TableRow1"><strong>推荐图片：</strong></td>
    <td class="TableRow1"><input type="file" name="upfile"><% If upfile<>"" and isnull(upfile)=false Then %> <a href="../UploadFile/<%= upfile %>" target="_blank">查看已上传文件</a><% End If %></td>
  </tr>
  <tr>
    <td width="20%" align="right" class="TableRow1"><strong>选择相关问题：</strong><br><font color="#999999">(建议选择并只选 2 条)</font></td>
    <td width="80%" class="TableRow1">
    <ul>
<%
    set rs=conn.execute("select top 30 askid,title from "&predb&"ask a inner join "&predb&"class b on a.sclass=b.classid where classid="&classid&" or ','+ParentStr+',' like '%,"&classid&",%' order by askid desc")
	IF not(rs.bof And rs.eof) Then
		do while not rs.eof
		IF instr(bask,","&rs("askid")&",")>0 Then Checked="checked" Else Checked=""
		   Response.Write("<li><input name=""check"" type=""checkbox"" "&Checked&" value="""&rs("askid")&"""> <a target=""_blank"" href=""../ask.asp?id="&rs("askid")&""">"&rs("title")&"</a></li>")
		rs.movenext
		loop
	Else
	    Response.Write("<li>暂无相关…</li>")
	End IF
	rs.close
	set rs=nothing
%>
</ul>    </td>
  </tr>
  <tr>
    <td align="right" class="TableRow1">&nbsp;</td>
    <td class="TableRow1"><input type="submit" name="button9" id="button9" value="确认推荐">
      &nbsp; <input type="button" name="button10" id="button10" value="返回管理" onClick="location.href='?'">
      &nbsp; <input type="button" name="button10" id="button10" value="取消推荐" onClick="location.href='?act=shutstrong&classid=<%= classid %>'">      </td>
  </tr>
  </form>
</table>
<%
end sub

Sub Boforedel()
	dim classid,rs,classname,askID,ansID,commentsID,AllPic
	classid=Trim(Request.QueryString("classid"))
	if classid<>"" then
	set rs=conn.execute("select classname from "&predb&"class where classid="&classid)
	classname=rs(0)
	set rs=nothing
	end if
	
	Call ClassD.DelClass(classid)
	tempID=ClassD.tempID
	tempName=ClassD.tempName
	
	tempID=tempID&classid
	askID=ClassD.DelAskId(TempID)
	if askid<>"" then askid=left(askid,len(askid)-1) else askid=0
	ansID=ClassD.DelansId(askID)
	
	if ansID<>"" then ansID=left(ansID,len(ansID)-1) else ansid=0
	AllPic=ClassD.DelPic(askid,ansid)
	commentsID=ClassD.DelcommentsId(askID,ansid)
	
	if commentsID<>"" then commentsID=left(commentsID,len(commentsID)-1)
	
    
	
%>
<table style="word-break:break-all;" class="tableBorder" cellspacing="1" cellpadding="2" width="96%" align="center" border="0">
<tr>
		<th height="25" align="left">删除分类操作</th>
  </tr>
	<tr>
		<td class="BodyTitle" height="23" align="left"></td>
	</tr>
  <tr>
    <td class="TableRow2"><font color="red"><strong>警告</strong>：删除分类将删除子分类以及所属问答，请确定无误后再删除，强烈建议操作前请备份数据库。</font><br/>
      <b>说明：</b><br/>
   &nbsp; 1、首先将删除本分类以及全部子级分类，再删除所属分类下属问题，同时删除问题的相应回答，生成文件一并删除，谨慎！<br/>
   &nbsp; 2、删除操作无可恢复，请确认无误再行操作！<br/>   </td>
  </tr>
  <tr>
    <td class="TableRow1"><strong>您要删除的主分类：</strong><font color="#FF0000"><b><%= classname %></b></font></td>
  </tr>
  <tr>
    <td class="TableRow2"><strong>其对应的子分类有：</strong><br>
      <%= TempName %></td>
  </tr>
  <tr>
    <td class="TableRow1"><strong>所属的问题有：</strong><br><%= AskId %></td>
  </tr>
  <tr>
    <td class="TableRow2"><strong>所属的回答有：</strong><br><%= ansId %></td>
  </tr>
  <tr>
    <td class="TableRow1"><strong>所属的评价有：</strong><br><%= commentsID %></td>
  </tr>
  <tr>
    <td class="TableRow1"><strong>删除的图片有：</strong><br><%= AllPic %></td>
  </tr>
  <form action="?act=del" method="post">

  <tr>
    <td align="center" class="TableRow1"><input type="button" name="button4" id="button4" onClick="history.go(-1)" value="返回上一页">
      &nbsp;
      <input name="delClass" type="hidden" value="<%= tempID %>">
      <input name="delAsk" type="hidden" value="<%= askID %>">
      <input name="delans" type="hidden" value="<%= ansID %>">
      <input name="delComments" type="hidden" value="<%= CommentsID %>">
      <input name="delPic" type="hidden" value="<%= AllPic %>">
      &nbsp; 
    <input type="submit" name="button5" id="button5" value="确认删除"></td>
  </tr>
  </form>
</table>
<%
End Sub
sub show()
%>
<table class="tableBorder" cellspacing="1" cellpadding="2" width="96%" align="center" border="0">
<tr>
		<th height="25" colspan="3" align="left">问答分类设置</th>
  </tr>
	<tr>
		<td class="BodyTitle" colspan="3" height="23" align="left"></td>
	</tr>
  <tr>
    <td class="TableRow2" colspan="3"><font color="red"><strong>警告</strong>：删除分类将删除子分类以及所属问答，请确定无误后再删除，强烈建议操作前请备份数据库。</font><br/>
      <b>说明：</b><br/>
   &nbsp; 1、首先将删除本分类以及全部子级分类，再删除所属分类下属问题，同时删除问题的相应回答，生成文件一并删除，谨慎！<br/>
   &nbsp; 2、删除操作无可恢复，请确认无误再行操作！<br/>
   </td>
  </tr>
  <tr>
    <td height="30" colspan="3" class="TableRow1">
	 <font color="#008800"><strong>分类路径：</strong></font> <a href="?">分类首页</a><% Call ClassD.PostList(esnum) %>
	</td>
  </tr>
  <tr>
    <td class="TableRow2" colspan="2" align="center"><strong>分类名称</strong></td>
    <td class="TableRow2" width="362" align="center"><strong>管理选项</strong></td>
  </tr>
  <% 
  dim rs,sql,i,p,row
  set rs= Server.CreateObject("adodb.recordset")
  rs.cursorlocation=3
  sql="select * from "&predb&"Class where esNum="&esnum&" order by esPai asc"
  rs.open sql,conn,1,1
  if rs.bof and rs.eof then
  %>
  <tr>
    <td colspan="2" align="center"  class="TableRow1">暂无分类，请添加</td>
    <td class="TableRow1">&nbsp;</td>
  </tr>
  <% else 
  do while not rs.eof
  i=i+1
  if i mod 2=0 then
     row=2
  else
     row=1
  end if
  %>
    <tr>
    <td class="TableRow<%= row %>" width="59" height="18" align="center"><%= i %></td>
    <td class="TableRow<%= row %>" width="242" align="center" id="bb<%= rs("ClassId") %>"><a href="?ClassId=<%= rs("ClassId") %>"><%= rs("ClassName") %></a></td>
    <td class="TableRow<%= row %>" align="center">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td align="center" bgcolor="#FFFF99"><a href="?ClassId=<%= rs("ClassId") %>">添加下级</a></td>
    <td width="25%" align="center" bgcolor="#CCFFFF">
	<%if i>1 then%>
	<select onChange="Change(value,'up','<%= esnum %>','<%= rs("ClassId") %>');">
	 <option value="">上移</option>
	<% for p=1 to i-1 %>
	  <option value="<%= p %>"><%= p %></option>
	 <% next %> 
	</select>
	<% end if %></td>
    <td width="25%" align="center" bgcolor="#CCCCFF">
	<%if i<rs.recordcount then%>
	<select onChange="Change(value,'down','<%= esnum %>','<%= rs("ClassId") %>');">
	<option value="">下移</option>
	  <% for p=1 to rs.recordcount-i %>
	  <option value="<%= p %>"><%= p %></option>
	  <%next%>
	</select>
	<% end if %>	</td>
    <td width="118" align="center" bgcolor="#FFCCFF"><span id="aa<%= rs("ClassId") %>" style="cursor:hand" onClick="modify(bb<%= rs("ClassId") %>,aa<%= rs("ClassId") %>,'<%= rs("classname") %>',<%= rs("ClassId") %>);">修改</span>&nbsp; <% If rs("isB")=1 Then %><a href="?act=strong&classid=<%= rs("ClassId") %>"><font color="#FF0000" title="<%= rs("Btime") %>">已荐</font></a><% Else %><a href="?act=strong&classid=<%= rs("ClassId") %>">推荐</a><% End If %>&nbsp; <a href="?act=boforedel&classid=<%= rs("ClassId") %>">删除?</a></td>
  </tr>
</table>	</td>
  </tr>
  <% 
  rs.movenext
  loop
  end if 
  rs.close
  set rs=nothing
  %>
  <form action="?act=addlist&ClassId=<%= esNum %>" method="post">
  <tr>
    <td class="TableRow2" colspan="2" align="center">添加分类：<input name="ClassName" type="text" id="ClassName" size="36" /></td>
    <td class="TableRow2"><input type="submit" name="Submit" value=" 提 交 " /></td>
  </tr>
  </form>
</table>
<%
end sub
%>
<br>
</body>
</html>
