<!--#include file="../include/config.asp"-->
<!--#include file="../include/common.asp"-->
<!--#include file="../include/lib.asp"-->
<%
	ef=false
	if not ef then
	If session("agentusername")<>"" Then
		uName=session("agentusername")
		isAgent=true
		TempID="Temp_Agent"
	Else
		Response.Redirect "/Login.asp":rEnd
	end if
	end If
	If session("agentusername")<>apiUser Then
	echo "没有权限!"
	rEnd
	End If
	set lib= New libClass
	arrTemplete=lib.splitTemp("Temp_Agent")
	set lib= Nothing
	echo arrTemplete(0)
openConn
set newsApi=new NewsContent
select case Rq("ac")
case "add":newsApi.add_News
case "save":newsApi.save_News
case "del":newsApi.del_News
case else:newsApi.list_News
End select


set newsApi=Nothing


closeConn

	'echo Html
	echo arrTemplete(1)
	if ef then
	Response.Redirect "e.asp?e="&ec
	end if
Class NewsContent	
Public Sub add_News()
newsid=Rq("newsid")
if isNum(newsid) Then
set rs=Conn.ExeCute("select * from news where id="&newsID)
if not(rs.eof and rs.bof) Then
dat=Rs("dat")
select case Rs("t")
	case "网站公告":isgg=" selected"
	case "技术文章":isjs=" selected"
	case "最新促销":iscx=" selected"
	case "常见问题":iswt=" selected"
	case "VPS帮助":isvps=" selected"
	case "虚拟主机帮助":ishost=" selected"
	case "数据库帮助":issql=" selected"
end select
newstitle=Rs("title")
newscontent2=Rs("content")
ELse
dat=now()
End If
set rs=Nothing

Else
dat=now()
End If
echo "<form name=""newsform1"" id=""newsform1"" method=""post"" action=""?ac=save&newsid="&newsid&"""><table width=""100%"" border=""0"" cellspacing=""0"" cellpadding=""0"">" & vbcrlf & _
"  <tr>" & vbcrlf & _
"    <td width=""50"" height=""30"" align=""center"">标题</td>" & vbcrlf & _
"    <td><input type=""text"" name=""news_title"" id=""news_title"" style=""width:100%"" value="""&newstitle&"""></td>" & vbcrlf & _
"  </tr>" & vbcrlf & _
"  <tr>" & vbcrlf & _
"    <td height=""30"" align=""center"">分类</td>" & vbcrlf & _
"    <td><select name=""news_t"" id=""news_t"">" & vbcrlf & _
"      <option value=""网站公告"""&isgg&">网站公告</option>" & vbcrlf & _
"      <option value=""技术文章"""&isjs&">技术文章</option>" & vbcrlf & _
"      <option value=""最新促销"""&iscx&">最新促销</option>" & vbcrlf & _
"      <option value=""常见问题"""&iswt&">常见问题</option>" & vbcrlf & _
"      <option value=""VPS帮助"""&isvps&">VPS帮助</option>" & vbcrlf & _
"      <option value=""虚拟主机帮助"""&ishost&">虚拟主机帮助</option>" & vbcrlf & _
"      <option value=""数据库帮助"""&issql&">数据库帮助</option>" & vbcrlf & _
"    </select></td>" & vbcrlf & _
"  </tr>" & vbcrlf & _
"  <tr>" & vbcrlf & _
"    <td width=""50"" height=""30"" align=""center"">时间</td>" & vbcrlf & _
"    <td><input type=""text"" name=""news_dat"" id=""news_dat"" style=""width:100%"" value="""&dat&"""></td>" & vbcrlf & _
"  </tr>" & vbcrlf & _
"  <tr>" & vbcrlf & _
"    <td width=""50"" height=""30"" align=""center"">内容</td>" & vbcrlf & _
"    <td><script charset=""gbk"" src=""../kindeditor/kindeditor-min.js""></script><script>var editor;" & vbcrlf & _
"KindEditor.ready(function(K) {" & vbcrlf & _
"	editor = K.create('textarea[name=""news_content""]', {" & vbcrlf & _
"		resizeType: 1," & vbcrlf & _
"		allowPreviewEmoticons: false," & vbcrlf & _
"		allowFileManager: true," & vbcrlf & _
"		allowImageUpload: true," & vbcrlf & _
"		cssPath: '../kindeditor/plugins/code/prettify.css'," & vbcrlf & _
"		uploadJson: '../kindeditor/asp/upload_json.asp'," & vbcrlf & _
"		fileManagerJson: '../kindeditor/asp/file_manager_json.asp'," & vbcrlf & _
"		items: ['source', 'clearhtml', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', 'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist', 'insertunorderedlist', '|', 'emoticons', 'image', 'flash', 'media', 'link', 'baidumap']," & vbcrlf & _
"		afterChange: function() {" & vbcrlf & _
"			K('.word_count1').html(this.count())" & vbcrlf & _
"		}" & vbcrlf & _
"	})" & vbcrlf & _
"});</script><textarea name=""news_content"" id=""news_content""  style=""width:100%;height:300px;visibility:hidden;display: none;"">"&newscontent2&"</textarea></td>" & vbcrlf & _
"  </tr>" & vbcrlf & _
"  <tr>" & vbcrlf & _
"    <td width=""50"" height=""30"" align=""center"">&nbsp;</td>" & vbcrlf & _
"    <td>" & vbcrlf & _
"      <input type=""submit"" name=""button"" id=""button"" value=""提交"">" & vbcrlf & _
"    </td>" & vbcrlf & _
"  </tr>" & vbcrlf & _
"</table>" & vbcrlf & _
"</form>"	
	
	End Sub
Public Sub list_news()
	
sqlStr=""
if Rq("t")<>"" Then sqlStr=sqlStr & " and t like '"&Rq("t")&"'"
if Rq("title")<>"" Then sqlStr=sqlStr & " and title like '%"&Rq("title")&"%'"

sql="select * From news where 1=1 "&sqlStr&" Order by dat desc"

Set Rs=server.createObject("ADODB.Recordset")
Rs.Open sql,Conn,1,1
	if Not(Rs.Eof And Rs.Bof) Then
echo "<form name=""form1"" method=""get"" action=""?"">  <select name=""t"" id=""t"">  "
echo "   <option value="""">全部文章</option>   <option value=""网站公告"">网站公告</option>" & vbcrlf & _
"      <option value=""技术文章"">技术文章</option>" & vbcrlf & _
"      <option value=""最新促销"">最新促销</option>" & vbcrlf & _
"      <option value=""常见问题"">常见问题</option>" & vbcrlf & _
"      <option value=""VPS帮助"">VPS帮助</option>" & vbcrlf & _
"      <option value=""虚拟主机帮助"">虚拟主机帮助</option>" & vbcrlf & _
"      <option value=""数据库帮助"">数据库帮助</option>"
echo "</select>  <input type=""text"" name=""title"" id=""title"">  <input type=""submit"" name=""button"" id=""button"" value=""搜索"">  <input type=""button"" name=""button2"" id=""button2"" value=""发布新文章"" onClick=""top.location.href='?ac=add';""></form>"
echo "<br><br><table width=""100%"" border=""1"" cellspacing=""0"" cellpadding=""0"">" & vbcrlf & _
"  <tr>" & vbcrlf & _
"    <td height=""30"" align=""center""><strong>编号</strong></td>" & vbcrlf & _
"    <td align=""center""><strong>标题</strong></td>" & vbcrlf & _
"    <td align=""center""><strong>分类</strong></td>" & vbcrlf & _
"    <td align=""center""><strong>日期</strong></td>" & vbcrlf & _
"    <td align=""center""><strong>点击数</strong></td>" & vbcrlf & _
"    <td align=""center""><strong>操作</strong></td>" & vbcrlf & _
"  </tr>"
	
		Rs.pagesize=20
		Rs.AbsolutePage=toPage()
		intPage=lastnextpage(Rs.pagecount,Rs.recordcount)
		ii=1
		do while not rs.Eof
		
echo "  <tr>" & vbcrlf & _
"    <td height=""30"" align=""center"">"&Rs("id")&"</td>" & vbcrlf & _
"    <td>&nbsp;"&Left(Rs("title"),30)&"</td>" & vbcrlf & _
"    <td>&nbsp;"&Rs("t")&"</td>" & vbcrlf & _
"    <td>&nbsp;"&Rs("dat")&"</td>" & vbcrlf & _
"    <td>&nbsp;"&Rs("hits")&"</td>" & vbcrlf & _
"    <td>&nbsp;<a href=""?ac=add&newsid="&Rs("id")&""">编辑</a> <a href=""?ac=del&newsid="&Rs("id")&""">删除</a></td>" & vbcrlf & _
"  </tr>"		
		
		ii=ii+1
		if ii-20>0 Then exit do		
		Rs.MoveNext
		Loop
		echo "</table><br>" & intPage
	Else
		echo "暂时没有文章，<a href='news.asp?ac=add'>点此发布文章</a>!"
	End If
Rs.Close
Set Rs=Nothing	
	
	End Sub
	Public Sub save_News
	
	titleNews=Rq("news_title")
	titleDat=Rq("news_Dat")
	titleType=Rq("news_t")
	titleContent=Request.Form("news_content")
	if titleNews<>"" and titleContent<>"" and titleType<>"" Then
		if not isDate(titleDat) Then titleDat=now()
		newsID=Rq("newsID")
		if not isNum(newsID) Then newsID=0
		Set Rs=server.createObject("ADODB.Recordset")
		sql="select * from news where id=" & newsID
		rs.open sql,conn,3,3
		if rs.eof and rs.bof Then
			rs.addnew
		end if
			rs("title")=titleNews
			rs("content")=titleContent
			rs("dat")=titleDat
			rs("t")=titleType
			rs.update
			rs.close
			set rs=nothing
			echo "<script>alert('编辑文章成功!');window.location.href='news.asp';;</script>"
	Else
		echo "<script>alert('请输入标题或者内容');history.back();</script>"
	End If
	End Sub
	Public Sub del_News
	
	newsID=Rq("newsid")
	Conn.ExeCute("delete * from news where id=" & newsID)
			echo "<script>alert('删除文章成功!');window.location.href='news.asp';;</script>"
	
	End Sub	
End Class
%>
