<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="admin.asp"-->
<!--#include file="../inc/conn.asp"-->
<!--#include file="../inc/function.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>新闻管理</title>
<link href="style/style.css" rel="stylesheet" type="text/css" />
<script language="javascript" src="style/js.js"></script>
<%if request("add")=1 or request("add")=2 then%>
<script charset="utf-8" src="../inc/editor/kindeditor.js"></script>
<script charset="utf-8" src="../inc/editor/lang/zh_CN.js"></script>
<script type="text/javascript" src="style/js.js"></script>
<script type="text/javascript">
var editor;
  KindEditor.ready(function(K) {
  editor = K.create('textarea[name="content"]', {
  allowFileManager : true
  });
});

function addItem(pic)//添加到下拉列表
{ 
 var optionObj = document.createElement("OPTION");
 var addpic="<img src='/"+ pic +"' id='aa' />"
 document.getElementById('piclist').options.add(optionObj);
 optionObj.innerText = pic;
 optionObj.value = pic;
}
</script>
<%end if%>
</head>

<body id="page">
<h2 class="title">新闻管理</h2>
<%
'//发布新闻
if request("action")=1 then
isnice=request("isnice")
istop=request("istop")
ispass=request("ispass")
adddate=request("adddate")
if isnice="" then isnice=0
if istop="" then istop=0
if ispass="" then ispass=0
if adddate="" then adddate=now()
if request("pic")<>"" then
ispic=1
else
ispic=0
end if
set rs=server.CreateObject("adodb.recordset")
sql="select * from cw_news"
rs.open sql,conn,1,3
rs.addnew
rs("title")=request("title")
rs("content")=request("content")
rs("classid")=request("classid")
rs("tags")=replace(request("tags"),"，",",")
rs("jj")=left(cw_nohtml(request("content")),200)
rs("adddate")=adddate
rs("isnice")=isnice
rs("istop")=istop
rs("ispass")=ispass
rs("ispic")=ispic
rs("pic")=request("pic")
rs("froms")=request("froms")
rs("author")=request("author")
rs.update
id=rs("id")
rs.close
set rs=nothing
'对Tags进行处理
tags=request("tags")
tags=replace(tags,"，",",")
tag=split(tags,",")
for i=0 to ubound(tag)
  call Tags_Add(tag(i))'//添加Tags
next
if ispass=1 then
  call c_index()'生成首页
  qid=cw_class("followid","cw_news_class",request("classid"))
  if qid=0 then
    call c_list(request("classid"),"1",0,"cw_news_class")
  else
    call c_list(request("classid"),"1",0,"cw_news_class")
	gid=cw_class("followid","cw_news_class",qid)
	if gid=0 then
	   call c_list(qid,"1",0,"cw_news_class")
	else
	   call c_list(qid,"1",0,"cw_news_class")
	   call c_list(gid,"1",0,"cw_news_class")
	end if
  end if
  call c_show(id,2,"1",0,"cw_news")'生成信息
end if
response.Write("<script>var url='cw_news.asp?add=1'; setTimeout('location.href=(url)',2000)</script>")
response.End()
end if
'//修改
if request("action")=2 then
isnice=request("isnice")
istop=request("istop")
ispass=request("ispass")
adddate=request("adddate")
if isnice="" then isnice=0
if istop="" then istop=0
if ispass="" then ispass=0
if adddate="" then adddate=now()
if request("pic")<>"" then
ispic=1
else
ispic=0
end if
set rs=server.CreateObject("adodb.recordset")
sql="select * from cw_news where id="&request("id")&""
rs.open sql,conn,1,3
rs("title")=request("title")
rs("content")=request("content")
rs("classid")=request("classid")
rs("tags")=replace(request("tags"),"，",",")
rs("jj")=left(cw_nohtml(request("content")),200)
rs("adddate")=adddate
rs("isnice")=isnice
rs("istop")=istop
rs("ispass")=ispass
rs("ispic")=ispic
rs("pic")=request("pic")
rs("froms")=request("froms")
rs("author")=request("author")
rs.update
rs.close
set rs=nothing
'对Tags进行处理
tags=request("tags")
tags=replace(tags,"，",",")
tag=split(tags,",")
for i=0 to ubound(tag)
   call Tags_Update(tag(i))'//添加Tags
next
if ispass=1 then
  call c_index()'生成首页
  qid=cw_class("followid","cw_news_class",request("classid"))
  if qid=0 then
    call c_list(request("classid"),"1",0,"cw_news_class")
  else
    call c_list(request("classid"),"1",0,"cw_news_class")
	gid=cw_class("followid","cw_news_class",qid)
	if gid=0 then
	   call c_list(qid,"1",0,"cw_news_class")
	else
	   call c_list(qid,"1",0,"cw_news_class")
	   call c_list(gid,"1",0,"cw_news_class")
	end if
  end if
  call c_show(request("id"),2,"1",0,"cw_news")
end if
response.Write("<script>var url='cw_news.asp'; setTimeout('location.href=(url)',2000)</script>")
response.End()
end if

'//批量操作
if request("action")=3 then
 select case request("sub")
   case 1
     conn.execute("update cw_news set isnice=1 where id in("&request("id")&")")
   case 2
     conn.execute("update cw_news set istop=1 where id in("&request("id")&")")
   case 3
     conn.execute("update cw_news set ispass=1 where id in("&request("id")&")")
   case 4
     conn.execute("update cw_news set isnice=0 where id in("&request("id")&")")
   case 5
     conn.execute("update cw_news set istop=0 where id in("&request("id")&")") 
   case 6
     conn.execute("update cw_news set ispass=0 where id in("&request("id")&")")
   case 9
     set dl=server.CreateObject("adodb.recordset")
	 dlq="select * from cw_news where id in("&request("id")&")"
	 dl.open dlq,conn,1,3
	 if not dl.eof then
	 do while not dl.eof
	 '//删除新闻中的图片
	 pic=Get_ImgSrc(dl("content"),1)
	 picf=split(pic,",")
	 for i=0 to ubound(picf)
	   if picf(i)<>"" then cw_del(picf(i))
	 next
	 '//删除静态文件
	 html=cf_root&cw_class("html","cw_news_class",dl("classid"))&dl("id")&".html"
	 if html<>"" then cw_del(html)	 
	 dl.delete
	 dl.movenext
	 loop
	 dl.close
	 set dl=nothing
	end if
   case 10
      call c_show(request("id"),2,"1",0,"cw_news")
      response.Write("<script>var url='cw_news.asp'; setTimeout('location.href=(url)',2000)</script>")
      response.End()
   end select
   response.Redirect"cw_news.asp"
end if

'//Tags_Add
function Tags_Add(tags)
set rs2=server.CreateObject("adodb.recordset")
sql="select * from cw_tags where title='"&tags&"'"
rs2.open sql,conn,1,3
if rs2.recordcount>0 then
  rs2("tcount")=rs2("tcount")+1
else
  rs2.addnew
  rs2("title")=tags  
end if
rs2.update
rs2.close
set rs2=nothing
end function
'//Tags_Update
function Tags_Update(tags)
set rs1=server.CreateObject("adodb.recordset")
sql="select * from cw_tags where title='"&tags&"'"
rs1.open sql,conn,1,3
if rs1.recordcount=0 then
  rs1.addnew
  rs1("title")=tags
  rs1.update
end if
rs1.close
set rs1=nothing
end function
%>
<table width="99%" border="0" align="center" class="nav">
  <tr>
    <td height="20">&nbsp;网站后台管理 &gt;&gt; <a href="cw_news.asp">新闻管理</a>&nbsp;&nbsp;&nbsp;&nbsp;【<a href="cw_news.asp?add=1" style="color:#FF0000">发布新闻</a>】</td>
	<td align="right"><form action="cw_news.asp" method="post" name="form" onsubmit="if(this.key.value==''){this.key.focus();return false}">信息搜索
          <select name="lei" id="lei">
            <option value="1" <%if request("lei")=1 then%>selected="selected"<%end if%>>标题</option>
            <option value="2" <%if request("lei")=2 then%>selected="selected"<%end if%>>用户名</option>
            <option value="3" <%if request("lei")=3 then%>selected="selected"<%end if%>>信息ID</option>
          </select>
          <input name="key" type="text" id="key" size="18" maxlength="50" style="height:18px; line-height:18px" value="<%=request("key")%>" />
        <input type="submit" name="Submit2" value="搜索" /></form></td>
  </tr>
</table>
	<%if request("add")="" then%>
	<form action="cw_news.asp?action=3" method="post" name="form">
	<table width="99%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">
      <tr>
        <td width="3%" height="20" align="center" bgcolor="#F0F3F5">&nbsp;</td>
        <td width="42%" align="center" bgcolor="#F0F3F5">标题</td>
        <td width="6%" align="center" bgcolor="#F0F3F5">缩略图</td>
		<td width="9%" align="center" bgcolor="#F0F3F5">用户</td>
        <td width="9%" align="center" bgcolor="#F0F3F5">分类</td>
	<td width="16%" align="center" bgcolor="#F0F3F5">状态</td>
        <td width="14%" align="center" bgcolor="#F0F3F5">管理</td>
      </tr>
    <%
	   lei=request("lei")
	   key=trim(request("key"))
	   userid=cw_userid(key)
	   select case lei
	     case 1
		   sql="select * from cw_news where title like '%"&key&"%' order by id desc"
		 case 2
		   sql="select * from cw_news where userid="&userid&" order by id desc"
		 case 3
		   sql="select * from cw_news where id="&cint(key)&" order by id desc"
		 case else
		   sql="select * from cw_news order by id desc"
	   end select
		set rs1=server.CreateObject("adodb.recordset")
		rs1.open sql,conn,1,1
		if not rs1.eof then
		         page_count=10
  				 if Request("page")="" or Request("page")="0" then
   				  page=1
  				 else
    				 page=cint(Request("page"))
  				 End if 
					 totalcount=rs1.RecordCount
   				  totalpage=int(totalcount/page_count+(page_count-1)/page_count)
  				 if page>totalpage then page=totalpage
  				 if rs1.EOF then    
   				  else
   				  for i = 1 to (page-1)*page_count
    				   rs1.MoveNext
   				  Next
   				  if page<totalpage then
    				   psize=page_count
   				  else
   				    psize=totalcount-(page-1)*page_count
   				  End if
   				  for i = 1 to psize
 url=cf_root&cw_class("html","cw_news_class",rs1("classid"))&rs1("id")&".html"
		%>
      <tr>
        <td height="14" align="center" bgcolor="#FFFFFF"><input type="checkbox" name="id" id="id" value="<%=rs1("id")%>" /></td>
        <td bgcolor="#FFFFFF">&nbsp;<a href="<%=url%>" target="_blank"><%=rs1("title")%></a></td>
        <td align="center" bgcolor="#FFFFFF"><%if rs1("pic")<>"" then%>是<%else%><font color="#CCCCCC">否</font><%end if%></td>
		<td align="center" bgcolor="#FFFFFF"><%if rs1("userid")=0 then%>Admin<%else%><%=cw_class("user","cw_user",rs1("userid"))%><%end if%></td>
        <td align="center" bgcolor="#FFFFFF" ><%=cw_class("title","cw_news_class",rs1("classid"))%></td>
        <td align="center" bgcolor="#FFFFFF" >
		<%if rs1("isnice")=1 then%><a href="cw_news.asp?action=3&sub=4&id=<%=rs1("id")%>" class="action">己推荐</a><%else%><a href="cw_news.asp?action=3&sub=1&id=<%=rs1("id")%>">未推荐</a><%end if%>&nbsp;
		<%if rs1("istop")=1 then%><a href="cw_news.asp?action=3&sub=5&id=<%=rs1("id")%>" class="action">己置顶</a><%else%><a href="cw_news.asp?action=3&sub=2&id=<%=rs1("id")%>">未置顶</a><%end if%>&nbsp;
		<%if rs1("ispass")=1 then%><a href="cw_news.asp?action=3&sub=6&id=<%=rs1("id")%>" class="action">己审核</a><%else%><a href="cw_news.asp?action=3&sub=3&id=<%=rs1("id")%>">未审核</a><%end if%>		</td>
		<td align="center" bgcolor="#FFFFFF" ><a <%if rs1("ispass")=1 then%>href="cw_news.asp?action=3&sub=10&id=<%=rs1("id")%>"<%end if%>>生成</a> | <a href="cw_news.asp?add=2&id=<%=rs1("id")%>">编辑</a> | <a href="cw_news.asp?sub=9&id=<%=rs1("id")%>&action=3" onclick="return confirm('你确定要删除？')">删除</a></td>
      </tr>
	      <%
		 rs1.MoveNext
 		next
		end if
		end if
		rs1.close
		set rs1=nothing
		%>
      <tr >
        <td height="20" colspan="7" align="center" bgcolor="#FFFFFF">
		<div style="float:left">
		<input name="button" type="button" onclick="qxbox(this.form.id)" value="全 选" />
        &nbsp;&nbsp;
        <input name="button" type="button"  onclick="fxbox(this.form.id)" value="反 选" />
        &nbsp;&nbsp;
        <select name="sub" id="sub">
          <option value="">请选择操作</option>
		  <option value="1">设为推荐</option>
		  <option value="2">设为置顶</option>
		  <option value="3">通过审核</option>
		  <optgroup label="&nbsp;&nbsp;"></optgroup>
		  <option value="4">取消推荐</option>
		  <option value="5">取消置顶</option>
		  <option value="6">取消审核</option>
		  <optgroup label="&nbsp;&nbsp;"></optgroup>
		  <option value="10">批量生成</option>
		  <optgroup label="&nbsp;&nbsp;"></optgroup>
		   <option value="9">删除信息</option>
        </select>
        <input type="submit" name="Submit" value="批量执行操作" onclick="return confirm('你确定要执行？')" />
		</div>
		<!--#include file="../inc/page.asp"-->		</td>
      </tr>
    </table>
	</form>
	<%end if%>
	<%if request("add")=2 then%>
	<%
set rr=server.CreateObject("adodb.recordset")
rq="select * from cw_news where id="&request("id")&""
rr.open rq,conn,1,1
%>
<table width="99%" border="0" cellpadding="0" cellspacing="0">
<form method="post" name="form1" action="cw_news.asp?action=2" onsubmit="return check_news(this)">  
  <tr>
    <td width="100" height="20" align="right">信息标题：</td>
    <td><input name="title" type="text" id="title" value="<%=rr("title")%>" size="60" /></td>
  </tr>
  <tr>
    <td height="20" align="right">所属分类：</td>
    <td><select name="classid" id="classid">
      <%
	set rf=server.CreateObject("adodb.recordset")
	rfq="select * from cw_news_class where followid=0 order by ordnum asc,id asc"
	rf.open rfq,conn,1,1
	if not rf.eof then
	do while not rf.eof 
	set rs=server.CreateObject("adodb.recordset")
	rsq="select * from cw_news_class where followid="&rf("id")&" order by ordnum asc,id asc"
	rs.open rsq,conn,1,1	
	if rs.recordcount>0 then
	%>
      <optgroup label="<%=rf("title")%>" style="color:#FF0000"></optgroup>
      <%
	else
	%>
      <option value="<%=rf("id")%>" <%if rr("classid")=rf("id") then%>selected="selected"<%end if%>>&nbsp;&nbsp;<%=rf("title")%></option>
      <%
	end if
	if not rs.eof then
	do while not rs.eof
	set rq=server.CreateObject("adodb.recordset")
	rqq="select * from cw_news_class where followid="&rs("id")&" order by ordnum asc,id asc"
	rq.open rqq,conn,1,1	
	if rq.recordcount>0 then
	%>
      <optgroup label="<%=rs("title")%>" style="color:#FF0000"></optgroup>
      <%else%>
      <option value="<%=rs("id")%>" <%if rr("classid")=rs("id") then%>selected="selected"<%end if%>>&nbsp;&nbsp;<%=rs("title")%></option>
      <%
	end if
	if not rq.eof then
	do while not rq.eof
	%>
      <option value="<%=rq("id")%>" <%if rr("classid")=rq("id") then%>selected="selected"<%end if%>>&nbsp;&nbsp;&nbsp;&nbsp;<%=rq("title")%></option>
      <%
		rq.movenext
		loop
		end if
		rq.close
		set rq=nothing	
	rs.movenext
	loop
	end if
	rs.close
	set rs=nothing
	  rf.movenext
	  loop
	  end if
	  rf.close
	  set rf=nothing
	  %>
    </select>      &nbsp;&nbsp;&nbsp;&nbsp;      
      <input name="isnice" type="checkbox" id="isnice" value="1" <%if rr("isnice")=1 then%>checked="checked"<%end if%> /> 推荐      
      <input name="istop" type="checkbox" id="istop" value="1" <%if rr("istop")=1 then%>checked="checked"<%end if%> /> 置顶
      <input name="ispass" type="checkbox" id="ispass" value="1" <%if rr("ispass")=1 then%>checked="checked"<%end if%> />审核</td>
  </tr>
  <tr>
    <td height="20" align="right">关键词：</td>
    <td><input name="tags" type="text" id="tags" value="<%=rr("tags")%>" size="60" /> *多个标签用","豆号隔开</td>
  </tr>
  <tr>
    <td height="20" align="right">信息来源：</td>
    <td><input name="froms" type="text" id="froms" value="<%=rr("froms")%>" size="20" />
      &nbsp;&nbsp;&nbsp;&nbsp;
    作者：
<input name="author" type="text" id="author" value="<%=rr("author")%>" size="15" />&nbsp;&nbsp;&nbsp;&nbsp;
时间：
<input name="adddate" type="text" id="adddate" value="<%=rr("adddate")%>" /></td>
  </tr>
  <tr>
    <td height="20" align="right">信息内容：</td>
    <td><textarea id="content" name="content"  style="width:700px;height:400px;visibility:hidden;"><%=rr("content")%></textarea></td>
  </tr>
  <tr>
    <td height="20" align="right">缩 略 图：</td>
    <td><input name="pic" type="text" id="pic" value="<%=rr("pic")%>" size="40" readonly="" />
      <select name="piclist" id="piclist" onchange="document.getElementById('lpic').value=this.value">
      <option value="">请选择缩略图</option>
	  <%=Get_ImgSrc(rr("content"),0)%>
    </select></td>
  </tr>  
  <tr>
    <td height="20" align="right">上传缩略图：</td>
    <td><iframe src="../inc/upload.asp?lei=2&pid=pic" frameborder="0" width="400" height="25" scrolling="No"></iframe></td>
  </tr>
  <tr>
    <td height="20" align="right">&nbsp;</td>
    <td><input name="Submit3" type="submit" class="btn" value="修改新闻内容"  />
      <input name="id" type="hidden" id="id" value="<%=rr("id")%>" /></td>
  </tr>
  </form>
</table>
  <%
  rr.close
  set rr=nothing
  %>
<%end if%>
<%if request("add")=1 then%>
<table width="99%" border="0" cellpadding="0" cellspacing="0">
<form method="post" name="form1" action="cw_news.asp?action=1" onsubmit="return check_news(this)" id="form1">
  
  <tr>
    <td width="100" height="20" align="right">信息标题：</td>
    <td><input name="title" type="text" id="title" size="60" /></td>
  </tr>
  <tr>
    <td height="25" align="right">所属分类：</td>
    <td><select name="classid" id="classid">
      <%
	set rf=server.CreateObject("adodb.recordset")
	rfq="select * from cw_news_class where followid=0 order by ordnum asc,id asc"
	rf.open rfq,conn,1,1
	if not rf.eof then
	do while not rf.eof 

	set rs=server.CreateObject("adodb.recordset")
	rsq="select * from cw_news_class where followid="&rf("id")&" order by ordnum asc,id asc"
	rs.open rsq,conn,1,1
	
	if rs.recordcount>0 then
	%>
      <optgroup label="<%=rf("title")%>" style="color:#FF0000"></optgroup>
      <%
	else
	%>
      <option value="<%=rf("id")%>">&nbsp;&nbsp;<%=rf("title")%></option>
      <%
	end if
	if not rs.eof then
	do while not rs.eof
	set rq=server.CreateObject("adodb.recordset")
	rqq="select * from cw_news_class where followid="&rs("id")&" order by ordnum asc,id asc"
	rq.open rqq,conn,1,1	
	if rq.recordcount>0 then
	%>
      <optgroup label="<%=rs("title")%>" style="color:#FF0000"></optgroup>
      <%else%>
      <option value="<%=rs("id")%>">&nbsp;&nbsp;<%=rs("title")%></option>
      <%
	end if
	if not rq.eof then
	do while not rq.eof
	%>
      <option value="<%=rq("id")%>">&nbsp;&nbsp;&nbsp;&nbsp;<%=rq("title")%></option>
      <%
		rq.movenext
		loop
		end if
		rq.close
		set rq=nothing
	
	rs.movenext
	loop
	end if
	rs.close
	set rs=nothing

	  rf.movenext
	  loop
	  end if
	  rf.close
	  set rf=nothing
	  %>
    </select>      &nbsp;&nbsp;&nbsp;&nbsp;      
      <input name="isnice" type="checkbox" id="isnice" value="1" /> 推荐      
      <input name="istop" type="checkbox" id="istop" value="1" /> 置顶
      <input name="ispass" type="checkbox" id="ispass" value="1" checked="checked" />审核</td>
  </tr>
  <tr>
    <td height="20" align="right">关键词：</td>
    <td><input name="tags" type="text" id="tags" size="60" /> *多个标签用","豆号隔开</td>
  </tr>
  <tr>
    <td height="20" align="right">信息来源：</td>
    <td><input name="froms" type="text" id="froms" onclick="this.select()" size="20" />
    &nbsp;&nbsp;
    作者：
<input name="author" type="text" id="author" onclick="this.select()" size="15" /> 
&nbsp;&nbsp;时间：
<input name="adddate" type="text" id="adddate" value="<%=now()%>" /></td>
  </tr>
  <tr>
    <td height="20" align="right">信息内容：</td>
    <td><textarea id="content" name="content" style="width:700px;height:400px;visibility:hidden;"></textarea></td>
  </tr>
  <tr>
    <td height="20" align="right">缩 略 图：</td>
    <td><input name="pic" type="text" id="pic" size="40" readonly="" />
      <select name="piclist" id="piclist" onchange="document.getElementById('pic').value=this.value">
      <option value="">请选择缩略图</option>
    </select></td>
  </tr>
  <tr>
    <td height="20" align="right">上传缩略图：</td>
    <td><iframe src="../inc/upload.asp?lei=2&pid=pic&fid=form1" frameborder="0" width="400" height="25" scrolling="No"></iframe></td>
  </tr>
  <tr>
    <td height="20" align="right">&nbsp;</td>
    <td><input name="Submit32" type="submit" class="btn" value="发布新闻内容"  /></td>
  </tr>
  </form>
</table>
<%end if%>
<%
call closes()
%>
</body>
</html>
