<!--#include file="../include/hf_conn.asp"-->
<!--#include file="checkadmin.asp"-->
<script language=javascript src=../include/mouse_on_title.js></script>
<%call checkmanage("09")%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="manage.css" type="text/css">
<script language="JavaScript" type="text/JavaScript">
function CheckAll(form)  {
  for (var i=0;i<form.elements.length;i++)    {
    var e = form.elements[i];
    if (e.name != 'chkall')  e.checked = form.chkall.checked; 
   }
  }
</script>
</head>
<BODY background="../images/admin/back.gif">
         
<%
action=request("action")
if action="" then
%>

<table width="98%" border="1" cellpadding="3" bordercolor="#333333" style="border-collapse: collapse;" style="word-break:break-all">

<tr class=backs><td class=td height=18 colspan=3>编辑常见问题</td></tr>

              <form name=Newslist action="help2.asp" method=post>
                <tr bgcolor="#003366" style="vertical-align: top"> 
                  <td align=center width=5%>选</td>
                  <td align=center width=20%>类别</td>
                  <td align=center>问题</td>
                </tr>
<%
dim rs,msg_per_page
dim sql
msg_per_page = 20 '定义每页显示记录条数

set rs=Server.CreateObject("ADODB.recordset")
sql="select * from faq order by Class asc,addtime asc"

rs.cursorlocation = 3 		'使用客户端游标，可以使效率提高
rs.pagesize = msg_per_page 	'定义分页记录集每页显示记录数
rs.open sql,conn,1,1 

if not (rs.eof and rs.bof) then 	'检测记录集是否为空
	totalrec = RS.RecordCount 	'总记录数
	if rs.recordcount mod msg_per_page = 0 then 	'计算总页数
	n = rs.recordcount\msg_per_page 'n:总页数
	else 
	n = rs.recordcount\msg_per_page+1 
	end if 

	currentpage = request("page") 		'当前页
	If currentpage <> "" then
		currentpage = clng(currentpage)
		if currentpage < 1 then currentpage = 1
	else
		currentpage = 1
	End if 
	if currentpage*msg_per_page > totalrec and not((currentpage-1)*msg_per_page < totalrec) then currentPage=1
	rs.absolutepage = currentpage 		'设置指针指向某页开头
	rowcount = rs.pagesize 			'设置每一页的数据记录数

	dim i
	dim k

if rs.eof and rs.bof then
	response.write "<script language='javascript'>"
	response.write "alert('没有添加问题，单击“确定”开始添加！');"
	response.write "location.href='help2.asp?action=add_faq';"
	response.write "</script>"
	response.end
end if
Do while not rs.eof and rowcount>0
%>
	<tr>
	<td class=b><input type='checkbox' value='<%=Cstr(rs("id"))%>' name=faqid></td>
	<td><%=rs("Class")%></td>
	<td><a href="help2.asp?action=modify_faq&faqid=<%=rs("id")%>"><%=lleft(rs("Query"),66)%></a></td></tr>
<%
	rowcount=rowcount-1
	rs.movenext
	if rs.eof then exit do
loop	

end if

rs.close
conn.close
set rs=nothing
set conn=nothing
%>
	<tr>
	<td colspan=3 class=b> <input type='checkbox' name=chkall onclick='CheckAll(this.form)'>全选 
	<input type="submit" name="action" value="删除" onClick="{if(confirm('该操作不可恢复！\n\n确定删除选定的问答？')){this.document.Newslist.submit();return true;}return false;}"> 
	<input type="button" name="action2" onClick="javascript:location.href='help2.asp?action=add_faq';" value="添加"> 
	</td>
	</tr>
	</form>
	</table>

<%call listPages()    

end if


if action="add_faq" then
  call add_faq()
end if

if action="删除" then
  delid=request("id")
  call del_faq()
end if

if action="modify_faq" then
  id=request("id")
  call modify_faq()
end if%>

</body>
</html>


<%
'分页
sub listPages() 
if n <= 1 then exit sub 
%>
<%if currentpage = 1 then%>
<font color=darkgray>首页</font>
<%else%> 
<a href="<%=request.ServerVariables("script_name")%>?page=1">首页</a>
<a href="<%=request.ServerVariables("script_name")%>?page=<%=currentpage-1%>">前页</a>
<%end if%>
<%if currentpage = n then%> 
<font color=darkgray>后页</font>
<%else%> 
<a href="<%=request.ServerVariables("script_name")%>?page=<%=currentpage+1%>">下页</a>
<a href="<%=request.ServerVariables("script_name")%>?page=<%=n%>">末页</a>
<%end if%>
 第<%=currentpage%>页 共<%=n%>页  
<%end sub


'删除问题
sub del_faq()
	if request("faqid")="" or isnull(request("faqid")) then
	response.write "<script language='javascript'>"
	response.write "alert('您什么也没有选择，无法执行删除操作，单击“确定”返回！');"
	response.write "location.href='help2.asp';"			
	response.write "</script>"
	response.end
	end if

	conn.execute("delete from faq where Id in ("&request("faqid")&")")

	response.write "<script language='javascript'>"
	response.write "alert('所选问题已被删除，单击“确定”返回！');"
	response.write "location.href='help2.asp';"			
	response.write "</script>"
	response.end
end sub


'添加问题
sub add_faq()
'保存添加的问题
if  request("send")="ok" then
	if request.form("Query")="" or request.form("Answer")="" or request.form("Class")="" then
	response.write "<script language='javascript'>"
	response.write "alert('资料填写不完整或有错误，单击“确定”返回上一页！');"
	response.write "location.href='javascript:history.go(-1)';"
	response.write "</script>"
	response.end
	end if

	sql="select * from faq"
	set rs=server.createobject("adodb.recordset")
	rs.open sql,conn,1,3

	rs.addnew
	  	rs("Query")=trim(request.form("Query"))
	  	rs("Answer")=trim(request.form("Answer"))
	  	rs("Class")=trim(request.form("Class"))
	rs.update	
	  rs.close
	  conn.close
	  set rs=nothing
	  set conn=nothing
	response.write "<script language='javascript'>"
	response.write "alert('您已成功添加一条常见问题，单击“确定”返回！');"
	response.write "location.href='help2.asp';"			
	response.write "</script>"
	response.end
else
'添加
	%>

<table width="98%" border="1"  style="border-collapse: collapse; border-style: dotted; border-width: 0px"  bordercolor="#333333" cellspacing="0" cellpadding="2">
<tr class=backs><td class=td height=18 colspan=2>添加常见问题</td></tr>
<form name="add" method="post" action="help2.asp?action=add_faq">
    <tr><td width=20% align=center>问题：</td><td><input name="Query" type="text" size="40" maxlength="100"></td></tr>
    <tr><td width=20% align=center>类别：</td><td>
        <input name="Class" type="text" id="label6" size="20" maxlength="20"></td>
    </tr>
    <tr><td width=20% align=center>答案：</td><td>
        <textarea name="Answer" cols="50" rows="7" id="Answer" style="overflow:auto;"></textarea><br>支持html语法</td>
    </tr>
    <tr><td colspan=2><input type="submit" name="SubmitName" value="保存设置">
          <input name="send" type="hidden"  value="ok"></td></tr>
  </table>
</form>
<%
end if
end sub


'修改问题
sub modify_faq()
'保存修改结果
if request.form("send")="ok" then

	if request.form("Query")="" or request.form("Answer")="" or request.form("Class")="" then
	response.write "<script language='javascript'>"
	response.write "alert('资料填写不完整或有错误，单击“确定”返回上一页！');"
	response.write "location.href='javascript:history.go(-1)';"
	response.write "</script>"
	response.end
	end if

	  set rs=Server.CreateObject("adodb.recordset")
	  sql="select * from faq where id="&request("faqid")
	  rs.open sql,conn,1,3
	  	rs("Query")=trim(request.form("Query"))
	  	rs("Answer")=trim(request.form("Answer"))
	  	rs("Class")=trim(request.form("Class"))
		rs.update	
	  rs.close
	  conn.close
	  set rs=nothing
	  set conn=nothing
	response.write "<script language='javascript'>"
	response.write "alert('您已成功修改一条常见问题，单击“确定”返回！');"
	response.write "location.href='help2.asp';"			
	response.write "</script>"
	response.end
else
'修改
	  set rs=Server.CreateObject("ADODB.recordset")
	  sql="select * from faq where id="&request("faqid")
	  rs.open sql,conn,1,1
%>
<table width="98%" border="1"  style="border-collapse: collapse; border-style: dotted; border-width: 0px"  bordercolor="#333333" cellspacing="0" cellpadding="2">
<tr class=backs><td class=td height=18 colspan=2>编辑常见问题</td></tr>

	<form name="modify" method="post" action="help2.asp?action=modify_faq">
	<tr><td align=center width=20%>问题：</td><td><input name="Query" type="text" value="<%=rs("Query")%>" size="40" maxlength="100"></td>
	</tr>
	<tr><td align=center width=20%>类别：</td><td><input name="Class" type="text" id="label6" value="<%=rs("Class")%>" size="20" maxlength="20"></td>
	</tr>
	<tr><td align=center width=20%>答案：</td><td>
	<textarea name="Answer" cols="50" rows="7" id="Answer" style="overflow:auto;"><%=rs("Answer")%></textarea><br>支持html语法</td>
	</tr>
	<tr>
	<td colspan=2><input type="submit" name="SubmitName3" value="保存设置">
	<input name="send" type="hidden"  value="ok">
	<input name="faqid" type="hidden" value="<%=request("faqid")%>"></td>
	</tr>
	</form>
</table>
<%
  rs.close
  conn.close
  set rs=nothing
  set conn=nothing

end if
end sub%>
