<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%Session.Contents("ons")="news"%>
<!--#include file="conn.asp" -->
<!--#include file="inc/const.asp" -->
<!--#include file="top.asp"-->
<!--#include file="cheack.asp"-->
<script src="My97DatePicker/WdatePicker.js" type="text/javascript"></script>
<div id="manages_content">
  <div id="manages_main">
    <h2 id="ttop">信息管理</h2>
<%
dim action
action=request.querystring("action")  
   select case action
      case "add"
         call add()
      case "edit"
         call edit()
	  case "add_save"
	     call add_save()
	  case "edit_save"
		 call edit_save()
	  Case "batch"
	     Call batch(request.form("action"))
      case else
         call main()
   end select
	  
sub main()
sqlstr="where 1=1 "
pa="?"
if trim(request("type"))<>"" and isnumeric(request("type")) then
	sqlstr=sqlstr&" and typ="&request("type")
	pa=pa&"type="&request("type")&"&"
end if

set rs=server.createobject("adodb.recordset")
sql="select * from news "&sqlstr&" order by id desc"
rs.open sql,conn,1,1 
%>
<script language=javascript>
function CheckAll(form1)  {
  for (var i=0;i<form1.elements.length;i++)    {
    var e = form1.elements[i];
    if (e.name != 'chkall')       e.checked = form1.chkall.checked; 
   }
  }
</script>
    <table cellspacing=0 cellpadding=0 border=0 width="96%" align="center" class="abg2">
      <form name="form1" method="post" action="news.asp?action=batch">
        <tbody>
          <tr>
            <td><table cellspacing=1 cellpadding=5 width="100%" border=0 bgcolor="#FFFFFF">
                <tbody>
                  <tr>
                    <td height=24 colspan="4" class="title2">&nbsp;&nbsp;<a href="news.asp?action=add" class="green">添加信息</a></td>
                  </tr>
                  <tr>
                    <td width="73%" height=24 class="td0" style="padding-left:10px;">标题</td>
                    <td width="14%" height=24 align="center" class="td0">类型</td>
                    <td width="7%" height=24 align="center" class="td0">编辑</td>
                    <td width="6%" height=24 align="center" class="td0">选择</td>
                  </tr>
                  <%
	pagesize=20			  
	Count=Rs.RecordCount
    Dim Css
    Page=Request.QueryString("Page")
    If Page="" Or Page<1 Then 
        Page=1
    Else
        Page=Cint(Page)
    End If 
	I=0
	If Count Mod Cint(PageSize)=0 Then
	    PageCount= Count \ Cint(PageSize)
	Else
	    PageCount= Count \ Cint(PageSize)+1
  	End If

  	If Not (Rs.Bof And Rs.Eof) Then
	   Rs.Movefirst
	   If Page > PageCount Then Page = PageCount
	   If Page<1 Then Page=1
	      Rs.Move (Page-1) * Cint(PageSize)
  	      Do While Not Rs.Eof And I<PageSize
	         I=I+1      
             ID=Rs("ID")
%>
                  <tr class="hover">
                    <td class="td1" style="padding-left:10px;"><a href="news.asp?action=edit&id=<%=rs("id")%>" class="zi"><%=rs("title")%></a></td>
                    <td class="td1" align="center">
                    <%
					select case rs("typ")
					case "1" response.Write "公告"
					case "2" response.Write "新闻媒体"
					case "3" response.Write "上方公告"
					end select
					%>
                    </td>
                    <td class="td1" align="center"><a href="news.asp?action=edit&id=<%=rs("id")%>"><img src="images/edit.gif" border="0" /></a></td>
                    <td class="td1" align="center">
                      <input type="checkbox" name="id" value="<%=id%>">
                    </td>
                  </tr>
                  <%
Rs.Movenext
Loop
End if%>
                  <tr>
                    <td height="24" colspan="4" align="center" class="td1">
					     <%=MultiPage(count,PageSize,Page,pa)%></td>
                  </tr>
                  <tr class="td1">
                    <td height="29" colspan="4" class="td1" align="right"><input type="checkbox" name="chkall" id="chkall" value="on" onClick="CheckAll(this.form)">
                      <label for="chkall">全选</label>                   
                      <input name="Submit" type="submit" class="but" id="Submit" value="批量删除" onClick="{if(confirm('确认删除? ')){return true;}return false;}"></td>
                  </tr>
                </tbody>
              </table></td>
          </tr>
        </tbody>
      </form>
    </table>
    <%
end sub

sub add()
%>
    <table cellspacing=1 cellpadding=0 width="96%" border=0 align="center" class="abg">
      <tbody>
        <tr>
          <td><table cellspacing=1 cellpadding=0 width="100%" border=0>
              <tbody>
                <tr>
                  <td height=22 class="title2" align="center">发布信息</td>
                </tr>
                <tr align="center">
                  <td align="center" valign="top"><form name="myform" method="post" action="news.asp?action=add_save" onSubmit="return CheckForm();">
                      <table width="100%" border="0" cellspacing="1" cellpadding="5" align="center">
                     
                        <tr class="td5">
                          <td width="15%" height="20" align="center">信息类型</td>
                          <td width="85%" align="left">
                          <select name="typ">
                          <option value="1">公告</option>
                          <option value="2">媒体报道</option>
						  <option value="3">上方公告</option>
                          </select>
                          </td>
                        </tr>
                        
                        <tr class="td5">
                          <td height="20" align="center">信息标题</td>
                          <td align="left"><input type="text" name="title" size="40" class="inp hover" maxlength="200"></td>
                        </tr>
                        
                        <tr class="td5">
                          <td height="20" align="center">信息内容</td>
                          <td align="left">
                          <textarea id="content" name="content" cols="20" rows="2" class="ckeditor">&nbsp;</textarea> 
<script type="text/javascript">
	CKEDITOR.replace('content');
</script>
						  </td>
                        </tr>
                        
                        <tr class="td5">
                          <td height="20" colspan="2" align="center"><input type="submit" value="发布" class=but>
                            <input type="reset" value="重置" class=but></td>
                        </tr>
                      </table>
                    </form></td>
                </tr>
              </tbody>
            </table></td>
        </tr>
      </tbody>
    </table>
    <%end sub
	  sub edit()
	  if trim(request("id"))<>"" and isnumeric(request("id")) then
		  dim id,title,content
		  sql="select id,title,content,typ,lng,addtime from news where id="&request("id")
		  set rs=conn.execute(sql)
		  id=rs(0)
		  title=rs(1)
		  if trim(rs(2))<>"" then
		  content=rs(2)
		  else
		  content="&nbsp;"
		  end if		  
		  typ=rs(3)
		  newslng=rs(4)
		  fbdate=rs(5)
		  rs.close
		  set rs=nothing
	  end if
	  %>
    <table cellspacing=1 cellpadding=0 width="96%" border=0 align="center" class="abg">
      <tbody>
        <tr>
          <td><table cellspacing=1 cellpadding=0 width="100%" border=0>
              <tbody>
                <tr>
                  <td height=22 class="title2" align="center">编辑信息</td>
                </tr>
                <tr align="center">
                  <td align="center" valign="top"><form name="myform" method="post" action="news.asp?action=edit_save&id=<%=id%>" onSubmit="return CheckForm();">
                      <table width="100%" border="0" cellspacing="1" cellpadding="5" align="center">
                    
                    	<tr class="td5">
                          <td width="15%" height="20" align="center">信息类型</td>
                          <td width="85%" align="left">
                          <select name="typ">
                          <option value="1" <%if typ=1 then response.Write "selected"%>>公告</option>
                          <option value="2" <%if typ=2 then response.Write "selected"%>>媒体报道</option>
                          </select>
                          </td>
                        </tr>
                        
                        <tr class="td5">
                          <td width="15%" height="20" align="center">信息标题</td>
                          <td width="85%"  align="left"><input type="text" name="title" size="40" class=inp value="<%=title%>" maxlength="200"></td>
                        </tr>
                        
                        <tr class="td5">
                          <td height="20" align="center">信息内容</td>
                          <td align="left">
						  <textarea id="content" name="content" cols="20" rows="2" class="ckeditor"><%=content%></textarea> 
<script type="text/javascript">
	CKEDITOR.replace('content');
</script>
                          </td>
                        </tr>
                    
                        <tr class="td5">
                          <td height="20" colspan="2" align="center"><input type="submit" value="提交" class=but>
                            <input type="reset" value="重置" class=but></td>
                        </tr>
                      </table>
                    </form></td>
                </tr>
              </tbody>
            </table></td>
        </tr>
      </tbody>
    </table>
    <%
	  end sub

sub batchdel()
   dim id
   if request.form("id").count>0 then
   else
   Response.Write("<script>alert('请选择删除记录');history.back(-1);</script>")
   Response.End()
   end if
   for i=1 to request.form("id").count
   id=request.form("id")(i)
   set rs=server.createobject("adodb.recordset")
   sql="select * from news where id="&id
   rs.open sql,conn,1,3   
   rs.delete
   rs.close
   set rs=nothing
   call addevent(session("userid"),"删除信息")
   next

   
   'response.redirect url
end sub

Sub batch(mode)
   Call batchdel()
   response.redirect url
End sub

sub add_save()
    set rs=server.createobject("adodb.recordset")
    sql="select * from news where (id is null)"
    rs.open sql,conn,1,3
    rs.addnew
	rs("typ")=request.form("typ")
	rs("title")=request.form("title")
	rs("content")=request.form("content")
	rs("addtime")=now()	
    rs.update
    rs.close
    set rs=nothing
	call addevent(session("userid"),"添加信息")
	call success()
end sub

sub edit_save()
    if trim(request("id"))<>"" and isnumeric(request("id")) then
	set rs=server.createobject("adodb.recordset")
    sql="select * from news where id="&request("id")
    rs.open sql,conn,1,3
	rs("typ")=request.form("typ")
    rs("title")=request.form("title")
	rs("content")=request.form("content")
    rs.update
    rs.close
    set rs=nothing
	call addevent(session("userid"),"编辑信息")
	call success()
	end if
end sub

sub success()
	  %>
    <table cellspacing=0 cellpadding=0 width="96%" border=0 align="center" class="abg">
      <tbody>
        <tr>
          <td><table cellspacing=1 cellpadding=0 width="100%" border=0 align="center">
              <tbody>
                <tr>
                  <td height=21 align="center" class="title2">操作结果</td>
                </tr>
                <tr>
                  <td height="50" valign="middle"><meta http-equiv=refresh content="3;URL=news.asp">
                    <a href="<%=url%>" class="green">继续添加</a><br>
                    <a href="news.asp" class="green">返回信息列表</a> <br></td>
                </tr>
              </tbody>
            </table></td>
        </tr>
      </tbody>
    </table>
    <%end sub %>
    <br>
    <div class="unflo"></div>
  </div>
</div>
<!--#include file="bottom.asp"-->