<!--#include file="../inc/Common.asp"-->
<!--#include file="../FCKeditor/fckeditor.asp" -->
<%
'新闻公告管理
'版本：1.0
'作者：Lone
'日期：2009-2-16


Const MaxPerPage = 20
Dim Action
Dim CurrentPage, AllRecords, ShowPageList
Dim Rs, SQL, thisFileName
CurrentPage = 0 : AllRecords = 0
ShowPageList = False
Action = Trim(Request("ac"))
thisFileName = Lone.FileName
Lone.ChkAdmin(0)

%>
<html>
<head>
<title>Qvod Video Management System V <%=SYS_VERSION%></title>
<meta http-equiv="Content-Type" content="text/html;charset=gbk" />
<link type="text/css" rel="stylesheet" href="../images/skin.css" />
<script language="javascript" type="text/javascript" src="../js/admin.js"></script>
<script language="javascript" type="text/javascript" src="../js/dialog.js"></script>
<script language="javascript" src="../js/movie.js"></script>
<script language="javascript" src="../js/ajax.js"></script>
</head>
<body>
<%
	Select Case LCase(Action)
	Case "add","edit" : Setting
	Case "save" : SaveSetting
	Case "manage" : Manage
	Case Else : Main

	End Select
Set Lone = Nothing
%>
</body>
</html>
<% 

Sub Manage
	Dim News_ID, DoWhat, Page
	News_Id = Trim(Request("id"))
	DoWhat = LCase(Trim(Request("do")))
	strFilter = Trim(Request("filter"))

	If News_ID="" And DoWhat<>"passall" Then MsgBox "请选择要执行操作的影片。", "back", ""
	Select Case DoWhat
	Case "delete"
		Delete
	Case "passed"
		Lone.Execute("Update [" & DBFirstName & "_News] Set News_Passed=1 Where News_ID IN (" & News_Id & ")")
	Case "unpassed"
		Lone.Execute("Update [" & DBFirstName & "_News] Set News_Passed=0 Where News_ID IN (" & News_Id & ")")
	Case "best"
		Lone.Execute("Update [" & DBFirstName & "_News] Set News_Best=1 Where News_ID IN (" & News_Id & ")")
	Case "unbest"
		Lone.Execute("Update [" & DBFirstName & "_News] Set News_Best=0 Where News_ID IN (" & News_Id & ")")
	Case "hot"
		Lone.Execute("Update [" & DBFirstName & "_News] Set News_Hot=1 Where News_ID IN (" & News_Id & ")")
	Case "unhot"
		Lone.Execute("Update [" & DBFirstName & "_News] Set News_Hot=0 Where News_ID IN (" & News_Id & ")")
	Case "passall"
		Lone.Execute("Update [" & DBFirstName & "_News] Set News_Passed=1 ")
	Case "html"

	Case Else
	
	End Select 

	Response.Redirect(Lone.FileName & "?" & strFilter)
End Sub

Sub Delete()
	Dim News_Id, Rs, Fs, MapPath
	News_Id = Trim(Request("id"))
	Set Rs = Server.CreateObject("ADODB.Recordset")
	Set FS = Server.CreateObject(Lone_FSO)

	Rs.Open "Select * From ["&DBFirstName&"_News] Where News_Id IN (" & News_Id & ")", Conn, 1, 3
	Do While Not Rs.EOF
		If Lone.Setup("Run")<>"3" And ChkIsNull(Rs("News_OutURL"))="" Then 
			FileURL = Rs("News_URL")
			If Right(FileURL, 1)="/" Then FileURL = FileURL & Lone.IndexFileName
			If chkIsNull(FileURL)<>"" Then
				MapPath = Server.MapPath(FileURL)
				If FS.FileExists(MapPath) Then
					FS.DeleteFile MapPath, True
				End If
			End If
		End If 
		Rs.Delete
		Rs.MoveNext
	Loop
	Rs.Close
	Set FS = Nothing
	Set Rs = Nothing
End Sub 



Sub Setting()
Dim News_ID, News_Name, News_SubTitle, News_Author, News_Image, News_From, News_DateTime, News_Content
Dim News_Passed, News_Best, News_Hot, News_OutURL, UpdateFlag
Dim PageTitle, strFilter

if Action="edit" then
	News_ID = Cint(Request.QueryString("id"))
	strFilter = Trim(Request.QueryString("filter"))
	Set Rs = Lone.Execute("select * From ["&DBFirstName&"_News] Where News_ID=" & News_ID)
	If Rs.EOF Then
		MsgBox "没有这条数据", "back",""
	End If 
	News_Name = Rs("News_Name")
	News_Author = Rs("News_Author")
	News_Image = Rs("News_Image")
	News_From = Rs("News_From")
	News_DateTime = Rs("News_DateTime")
	News_SubTitle = Rs("News_SubTitle")	
	News_Introduction = Rs("News_Content")
	News_OutURL = Rs("News_OutURL")
	News_Passed = Rs("News_Passed")
	News_Best = Rs("News_Best")
	News_Hot = Rs("News_Hot")
	PageTitle = "编辑新闻《" & News_Name & "》"
	Rs.Close
	Set Rs = Nothing
Else
	News_Passed = 1
	News_Best = 0
	News_Hot = 0
	News_DateTime = Now()
	News_Introduction = "暂无介绍"
	PageTitle = "发布新闻公告"
	strFilter = ""
End if
	
%>
<div style="height: 100%">
<form name="frmMovie" method="post" action="<%=Lone.FileName%>" onsubmit="return checkForm(this);">
<input type="hidden" name="ac" value="save" />
<input type="hidden" name="News_ID" id="News_ID" value="<%=News_ID%>" />
<input type="hidden" name="filter" value="<%=Server.HTMLEncode(strFilter)%>" />
<table width="100%" border="0" cellspacing="1" cellpadding="2" class="border">
	<tr>
	  <th colspan="4" align="center"><span class="right"><a href="javascript:history.back();">返回&gt;&gt;</a>&nbsp;&nbsp;</span><%=PageTitle%></th>
    </tr>
	<tr>
	  <td width="13%" align="center">新闻标题：</td>
	  <td width="40%">
      <input name="News_Name" type="text" class="input" id="News_Name" size="45" value="<%=Lone.iHTMLEncode(News_Name)%>" />
      <span id="loadingStatus"></span></td>
	  <td width="13%" align="center">副 标 题：</td>
	  <td width="34%"><input name="News_SubTitle" type="text" class="input" id="News_SubTitle" size="40" value="<%= Lone.iHTMLEncode(News_SubTitle) %>" /></td>
  </tr>
	<tr>
	  <td align="center">新闻作者：</td>
	  <td><input name="News_Author" type="text" class="input" id="News_Author" size="30" value="<%= Lone.iHTMLEncode(News_Author) %>" /> </td>
	  <td align="center">新闻来源：</td>
	  <td><input name="News_From" type="text" class="input" id="News_From" size="30" value="<%= Lone.iHTMLEncode(News_From) %>" />
      </td>
  </tr>
	<tr>
	  <td align="center">新闻图片：</td>
	  <td><input name="News_Image" type="text" class="input" id="News_Image" size="30" value="<%= News_Image %>" /> <a href="javascript:;" title="上传本地图片" onclick="CreateWindow(300, 125, 'upload.asp', '上传图片', 'News_Image');">上传</a> <a href="javascript:;" title="将远程图片保存到服务器" onclick="Collect('News_Image');">采集</a> <a href="javascript:viewImage('News_Image');">预览</a></td>
	  <td align="center">新闻属性：</td>
	  <td>
      <input type="checkbox" name="News_Passed" id="News_Passed"<% If News_Passed=1 Then Response.Write(" checked") %> value="1" /><label for="News_Passed">通过审核</label>
      <input type="checkbox" name="News_Best" id="News_Best"<% If News_Best=1 Then Response.Write(" checked") %>  value="1" /><label for="News_Best">推荐新闻</label> 
      <input type="checkbox" name="News_Hot" id="News_Hot"<% If News_Hot=1 Then Response.Write(" checked") %>  value="1" /><label for="News_Hot">热点新闻</label></td>
  </tr>
	<tr>
	  <td align="center">外部连接：</td>
	  <td><input name="News_OutURL" type="text" class="input" id="News_OutURL" size="45" value="<%=Lone.iHTMLEncode(News_OutURL)%>" />
      </td>
	  <td align="center">发布时间：</td>
	  <td><input name="News_DateTime" type="text" class="input" id="News_DateTime" size="30" value="<%= News_DateTime %>" />
      <% If Action="edit" then %>
      <input type="checkbox" name="UpdateFlag" id="<%= News_DateTime %>" value="1" onclick="$('News_DateTime').value=(this.checked==true)?'<%=Now()%>':this.id;"  /><label for="UpdateFlag">更新</label>
      <% End If %></td>
  </tr>
	<tr>
	  <td align="center">详细内容：</td>
	  <td colspan="3"><%
		  Dim oFCKeditor
		  Set oFCKeditor = New FCKeditor
		  oFCKeditor.BasePath = "../fckeditor/"
		  oFCKeditor.ToolbarSet = "QVMS"
		  oFCKeditor.Width = "100%"
		  oFCKeditor.Height = "300"
		  oFCKeditor.Value = News_Introduction
		  oFCKeditor.Create "News_Introduction"
	  %></td>
  </tr>
 </table>
 

<div class="submit" style="margin-top:10px; ">
	<input type="submit" name="submit" value="保存新闻" />
</div>
</form>
</div>
<% End Sub %>

<% Sub Main 
Dim StrFilter
dim show, classid, Key

show = trim(request.QueryString("show"))
classid = trim(request.QueryString("cid"))
Key = trim(request.QueryString("k"))
SQL = "select News_ID, News_Name, News_DateTime, News_Passed, News_Best, News_Hot, News_URL, News_OutURL From [" &DBFirstName& "_News] Where News_ID>0 "

select case show
case "1" : SQL = SQL & "And News_Passed=0 "
case "2" : SQL = SQL & "And News_Passed=1 "
case "3" : SQL = SQL & "And News_Best=1 "
case "4" : SQL = SQL & "And News_Hot=1 "
end select 

If Key<>"" Then SQL = SQL & "And News_Name Like '%" & checkStr(Key) &"%' "

SQl = SQl & "Order By News_DateTime Desc"
Set Rs = Server.CreateObject("ADODB.RecordSet")
rs.open sql,conn,1,1
If Not Rs.EOF Then
	CurrentPage = Trim(Request("Page"))
	rs.PageSize = MaxPerPage
	If CurrentPage="" Or IsNumeric(CurrentPage)=False Then CurrentPage=1 Else CurrentPage=CInt(CurrentPage)
	If CurrentPage<1 Then CurrentPage=1
	If CurrentPage>rs.PageCount Then CurrentPage=rs.PageCount
	AllRecords = rs.RecordCount
	rs.absolutePage = CurrentPage
	session("page")=CurrentPage
	If rs.PageCount>1 Then ShowPageList=True
End If

StrFilter = "page=" & CurrentPage
If show<>"" Then 
	strFilter = strFilter & "&show=" & show
	thisFileName = JoinChar(thisFileName) & "show=" & show
End If 

If Key<>"" Then 
	strFilter = strFilter & "&k=" & Key
	thisFileName = JoinChar(thisFileName) & "k=" & Server.URLEncode(Key)
End If


%>
<form name="frmSearch" method="get" action="<%=Lone.FileName%>">
<% If ShowPageList Then %>
<span class="right" style="margin-top:6px;"><%Call showpage(thisFileName,AllRecords,maxperpage,True,False, "条") %>&nbsp;</span>
<% End If %>
	<input type="button" name="button" value="发布新闻" class="btn" onclick="location.href='?ac=add'" />
	<a href="?show=3">推荐新闻</a> 
	<a href="?show=4">热点新闻</a>
	<input type="text" size="14" name="k" value="<%=Lone.iHTMLEncode(Key)%>" class="input" />
	<input type="submit" name="submit" value="搜索" class="btn" />

</form>
<form name="movlist" method="post" action="<%=Lone.FileName%>">
<input type="hidden" name="filter" value="<%=Server.HTMLEncode(StrFilter)%>" />
<input type="hidden" name="ac" value="manage" />
<input type="hidden" name="do" id="DoWhat" value="html" />
<table width="100%" border="0" cellspacing="1" cellpadding="0" class="border" style="margin: 6px 0;">
	<tr>
		<th align="left"><input type="checkbox" name="chkAll" id="chkAll" onclick="CheckAll(this.form)" />名称</th>
		<th width="6%">生成</th>
		<th width="15%">属性</th>
		<th width="15%">发布时间</th>    
		<th width="15%">操作</th>
	</tr>
<% 

for i=1 to MaxPerpage
	if rs.eof then exit For
%>
	<tr onmouseover="this.className='on'" onmouseout="this.className=''">
		<td><input type="checkbox" name="id" value="<%=Rs("News_ID")%>" /><a href="?ac=edit&id=<%=Rs("News_ID")%>&filter=<%= Server.URLEncode(StrFilter) %>"><%= Rs("News_Name") %></a></td>
		<td align="center">
<%If Lone.Setup("Run") = "3" Then %>
		<% If Rs("News_Passed")=1 Then %>
            <a href="/?news_<%=Rs("News_ID")%>" target="_blank">预览</a>
        <% Else %>
			-
		<% End If %>
<% Else %>
		<% If chkIsNull(Rs("News_OutURL"))<>"" Then %>
			<a href="<%=Rs("News_OutURL")%>" target="_blank">链接</a>
        <% Else %>
			<% If chkIsNull(Rs("News_URL"))="" Then %>
				<img src="../images/html_no.gif" align="absmiddle" />
			<% Else %>
				<a href="<%=Rs("News_URL")%>" target="_blank"><img src="../images/html_ok.gif" align="absmiddle" border="0" /></a>
			<% End If %>
        <% End If %>
<% End If %>
        </td>
		<td align="center"><% 
		if Rs("News_Passed")=1 Then Response.Write("<a href='?ac=manage&do=unpassed&id="&Rs("News_ID")&"&filter="&Server.URLEncode(StrFilter)&"' title='取消审核'><font color=green>已审</font></a> ") else Response.Write("<a href='?ac=manage&do=passed&id="&Rs("News_ID")&"&filter="&Server.URLEncode(StrFilter)&"' title='通过审核'><font color=red>未审</font></a> ")
		if Rs("News_Best")=1 Then Response.Write("<a href='?ac=manage&do=unbest&id="&Rs("News_ID")&"&filter="&Server.URLEncode(StrFilter)&"' title='取消推荐'><font color=blue>荐</font></a> ")
		if Rs("News_Hot")=1 Then Response.Write("<a href='?ac=manage&do=unhot&id="&Rs("News_ID")&"&filter="&Server.URLEncode(StrFilter)&"' title='取消热点'><font color=#ff6600>热</font></a> ")			
		 %></td>
		<td align="center"><% 
		If isdate(Rs("News_DateTime")) Then
			Response.Write FormatDateTime(Rs("News_DateTime"), 2)
		End If
		%></td>	      	
		<td align="center">
			
			<a href="?ac=edit&id=<%=Rs("News_ID")%>&filter=<%= Server.URLEncode(StrFilter) %>">修改</a> | 
			<a href="?ac=manage&do=delete&id=<%=Rs("News_ID")%>&filter=<%= Server.URLEncode(StrFilter) %>" onclick="return confirm('确定要删除这个影片？')">删除</a>
		</td>
	</tr>
<%
rs.MoveNext
Next
Rs.Close
Set Rs = Nothing
%>
</table>

<div>
	<input type="button" value="通过审核" class="btn" onclick="$('DoWhat').value='passed'; this.form.submit();" />
	<input type="button" value="取消审核" class="btn" onclick="$('DoWhat').value='unpassed'; this.form.submit();" />
	<input type="button" value="全部审核" class="btn" onclick="$('DoWhat').value='passall';  this.form.submit();" />
	<input type="button" value="设为推荐" class="btn" onclick="$('DoWhat').value='best'; this.form.submit();" />
	<input type="button" value="取消推荐" class="btn" onclick="$('DoWhat').value='unbest'; this.form.submit();" />
	<input type="button" value="设为热点" class="btn" onclick="$('DoWhat').value='hot'; this.form.submit();" />
	<input type="button" value="取消热点" class="btn" onclick="$('DoWhat').value='unhot'; this.form.submit();" />
	<input type="button" value="批量删除" class="btn" onclick="if(confirm('确定要删除选中的数据？')){$('DoWhat').value='delete'; this.form.submit();}" />
</div>
</form>

<% If ShowPageList Then %>
<div id="PageHolder" align="center"><%Call showpage(thisFileName,AllRecords,maxperpage,True,True, "条") %></div>
<% End If %>
<% End Sub %>


<%
Sub SaveSetting
	Dim Rs
	Dim News_ID, News_Name, News_SubTitle, News_Author, News_Image, News_From, News_DateTime, News_Content
	Dim News_Passed, News_Best, News_Hot, News_OutURL, UpdateFlag
	Dim strFilter
	News_ID = Trim(Request.Form("News_ID"))
	News_Name = LoseHTML(Trim(Request.Form("News_Name")))
	News_Author = LoseHTML(Trim(Request.Form("News_Author")))
	News_SubTitle = LoseHTML(Trim(Request.Form("News_SubTitle")))
	News_Image = LoseHTML(Trim(Request.Form("News_Image")))
	News_DateTime = LoseHTML(Trim(Request.Form("News_DateTime")))
	UpdateFlag = LoseHTML(Trim(Request.Form("UpdateFlag")))
	News_OutURL = LoseHTML(Trim(Request.Form("News_OutURL")))
	News_Content = Trim(Request.Form("News_Introduction"))
	News_From = LoseHTML(Trim(Request.Form("News_From")))
	News_Passed = Trim(Request.Form("News_Passed"))
	News_Best = Trim(Request.Form("News_Best"))
	News_Hot = Trim(Request.Form("News_Hot"))
	strFilter = Trim(Request.Form("filter"))

	If News_Name="" Then MsgBox "新闻标题不能为空。", "back", "" : Exit Sub

	If Not isInteger(News_ID) Then News_ID=0 Else News_ID=CLng(News_ID)
	If News_Passed<>"1" Then News_Passed="0"
	If News_Best<>"1" Then News_Best="0"
	If News_Hot<>"1" Then News_Hot="0"
	If Not IsDate(News_UpdateTime) Then News_UpdateTime = Now()
	If UpdateFlag<>"1" Then UpdateFlag="0"
	If News_Content = "" Then
		News_Content = "暂无介绍"
	Else
		News_Content = ScriptHtml(News_Content, "script", 2)
		News_Content = ScriptHtml(News_Content, "iframe", 2)
	End If 

	Set Rs = Server.CreateObject("ADODB.Recordset")
	Rs.Open "Select * From [" & DBFirstName & "_News] Where News_ID=" & News_ID & "",Conn,1,3
	If Rs.EOF Then Rs.AddNew()
	Rs("News_Name") = NoWrap(News_Name)
	Rs("News_Author") = NoWrap(News_Author)
	Rs("News_Image") = NoWrap(News_Image)
	Rs("News_From") = NoWrap(News_From)
	If News_ID=0 Or UpdateFlag="1" Then Rs("News_DateTime") = News_DateTime
	Rs("News_OutURL") = NoWrap(News_OutURL)
	Rs("News_Content") = News_Content
	Rs("News_SubTitle") = NoWrap(News_SubTitle)
	Rs("News_Passed") = News_Passed
	Rs("News_Best") = News_Best
	Rs("News_Hot") = News_Hot
	If News_ID>0 Then News_URL = Rs("News_URL")
	Rs("News_URL") = ""
	Rs.Update
	Rs.Close
	Set Rs = Nothing

	If Lone.Setup("Run") = "3" Then Response.Redirect(Lone.FileName&"?"&strFilter)

	If News_Passed=1 And ChkIsNull(News_OutURL)="" Then
		If News_ID=0 Then
			News_ID = Lone.Execute("select max(News_ID) from [" & DBFirstName & "_News]")(0)
		End If
		localFileName = Lone.CreateFileName("/news/{$id}", News_ID)

		If Right(localFileName, 1)<>"/" Then
			localFileName = localFileName & "." & Lone.FileExt(CInt(Lone.Setup("Run")))
		End If
		Call Lone.CreateTemplateFile ("/skin/"&Lone.Setup("Skin")&"/news.html", "news", News_ID)
		Call Lone.SavePageContent (localFileName, "")
		Call Lone.DeleteTemplateFile
		Lone.Execute("Update [" & DBFirstName & "_News] Set News_URL='" & localFileName & "' Where News_ID="&News_ID)
	Else
		If News_ID>0 And ChkIsNull(News_URL)<>"" Then
			If Right(News_URL, 1)="/" Then News_URL = News_URL & Lone.IndexFileName
			MapPath = Server.MapPath(News_URL)
			Set FS = Server.CreateObject(Lone_FSO)
			If FS.FileExists(MapPath) Then
				FS.DeleteFile MapPath, True
			End If
			Set FS = Nothing
		End If 
	End If
	Response.Redirect(Lone.FileName&"?"&strFilter)

End Sub

%>