<!-- #include file="include/onlogin.asp" -->
<!-- #INCLUDE FILE="include/conn.asp" -->
<%
dim nsort,sql2,rs2,del_temp,data_name,cid,sid,nid,ncid,nsid,id,left_types,now_id,nummer,sqladd,page,rssum,thepages,viewpage,pageurl,csid
tit=vbcrlf & "<a href='?'>电影头条</a> | " & _
    vbcrlf & "<a href='?action=add'>发布新闻</a> | " & _
    vbcrlf & "<a href='admin_nsort.asp?nsort=news'>新闻分类</a> | " & _
    "<a href='?action=js'>JS 生成</a>"
response.write header(12,tit)
pageurl="?action="&action&"&":nsort="news":data_name="news":sqladd="":nummer=15
call admin_cid_sid()

if trim(request("del_ok"))="ok" then
  response.write del_select(trim(request.form("del_id")))
end if

id=trim(request.querystring("id"))
if (action="hidden" or action="istop") and isnumeric(id) then
  sql="select "&action&" from "&data_name&" where id="&id
  set rs=conn.execute(sql)
  if not(rs.eof and rs.bof) then
    if rs(action)=true then
      sql="update "&data_name&" set "&action&"=0 where id="&id
    else
      sql="update "&data_name&" set "&action&"=1 where id="&id
    end if
    conn.execute(sql)
  end if
  rs.close:action=""
end if

select case action
case "add"
  titt="发布新闻"
case "edit"
  titt="编辑新闻"
case else
  titt="电影头条"
end select
response.write admin_bar(titt,1,"99%")
select case action
case "add"
  call news_add()
case "edit"
  if not(isnumeric(id)) then
    call news_main()
  else
    set rs=server.createobject("adodb.recordset")
    sql="select * from "&data_name&" where id="&id
    rs.open sql,conn,1,3
    call news_edit()
  end if
case "js"
  call fso_js()
case else
  call news_main()
end select
response.write admin_bar("",2,"99%")
call close_conn()
'response.write ender()

sub fso_js()
  dim filetype,file_name,sql,rs,topic
  file_name="style/news_fpic.js"
  filetype=fso_fpic("",12,180,88)
  call create_file(file_name,filetype)
  response.write "<script language=javascript>alert(""生成 JS 成功！"");location.href='?';</script>"
end sub

function fso_fpic(fsql,t_num,w_num,tt)
  dim atb,topic,temp1,rs,sql,nid,sk_class
  atb=" target=_blank":sk_class="end"
  sql="select top 1 id,topic,comto,word,pic,tim from news where hidden=1 and istop=1 and ispic=1"&fsql&" order by id desc"
  set rs=conn.execute(sql)
  if not(rs.eof and rs.bof) then
    nid=rs("id"):topic=rs("topic")
    fso_fpic="document.write (""<table border=0 width='100%'>"");" & _
	  vbcrlf&"document.write (""<tr align=center><td width='32%'>"");" & _
	  vbcrlf&"document.write (""  <table border=0>"");" & _
	  vbcrlf&"document.write (""  <tr><td align=center><img src='"&objv7.web_var(web_upload,1)&rs("pic")&"' border=0 title='"&code_fso(objv7.code_html(rs("topic"),1,0),1)&"' width="&objv7.web_var(web_num,7)&" height="&objv7.web_var(web_num,8)&"></td></tr>"");" & _
	  vbcrlf&"document.write (""  <tr><td height=25 align=center><a href='news_view.asp?id="&nid&"' target=_blank>"&code_fso(objv7.code_html(rs("topic"),1,t_num),1)&"</a></td></tr>"");" & _
	  vbcrlf&"document.write (""  </table>"");" & _
	  vbcrlf&"document.write (""</td><td width='68%'>"");" & _
	  vbcrlf&"document.write (""  <table border=0 width='100%' height='100%'>"");" & _
	  vbcrlf&"document.write (""  <tr><td class=htd><a href='news_view.asp?id="&nid&"' target=_blank>"&code_fso(objv7.code_html(rs("word"),1,w_num),1)&"</a></td></tr>"");" & _
	  vbcrlf&"document.write (""  <tr><td height=25 class=gray align=right>（"&objv7.time_type(rs("tim"),tt)&"&nbsp;摘自:"&code_fso(rs("comto"),1)&"）&nbsp;</td></tr>"");" & _
	  vbcrlf&"document.write (""  </table>"");" & _
	  vbcrlf&"document.write (""</td></tr></table>"");"
  end if
  rs.close:set rs=nothing
end function

sub news_edit()
  dim rs3,sql3,topic,comto,istop,word,ispic,pic,keyes
  if trim(request.querystring("edit"))="chk" then
    topic=code_admin(request.form("topic"))
    csid=trim(request.form("c_id"))
    comto=code_admin(request.form("comto"))
    keyes=code_admin(request.form("keyes"))
    istop=trim(request.form("istop"))
    word=request.form("word")
    ispic=trim(request.form("ispic"))
    pic=trim(request.form("pic"))
    if cs_nd(csid)<>"yes" then
      response.write "<font class=time>请选择新闻类型！</font><br><br>"&go_back
    elseif len(topic)<1 or len(word)<10 then
      response.write "<font class=time>新闻标题和内容不能为空！</font><br><br>"&go_back
    else
      call chk_cid_sid()
      rs("c_id")=cid
      rs("s_id")=sid
      rs("cod")=cod_type()
      if trim(request.form("username_my"))="yes" then rs("username")=login_username
      rs("topic")=topic
      rs("comto")=comto
      rs("keyes")=keyes
      rs("word")=word
      if istop="yes" then
        rs("istop")=true
      else
        rs("istop")=false
      end if
      if ispic="yes" then
        rs("ispic")=true
      else
        rs("ispic")=false
      end if
      if trim(request.form("hidden"))="yes" then
        rs("hidden")=false
      else
        rs("hidden")=true
      end if
      rs("pic")=pic
      if isnumeric(trim(request.form("counter"))) then rs("counter")=trim(request.form("counter"))
      rs.update
      rs.close:set rs=nothing
      call upload_note(data_name,id)
      response.write "<font class=time>已成功修改了一篇新闻！</font><br><br><a href='?c_id="&cid&"&s_id="&sid&"'>点击返回</a><br><br>"
    end if
  else
%><table width='100%' border=0 align=center cellpadding=2 cellspacing=1>
<form name='add_frm' action='<%response.write pageurl%>c_id=<%response.write cid%>&s_id=<%response.write sid%>&id=<%response.write id%>&edit=chk' method=post>
<input type=hidden name=upid value=''>
  <tr class=tdbg-dark><td width='15%' align=center>新闻标题：</td><td width='85%'><input type=text size=70 name=topic value='<%response.write rs("topic")%>' maxlength=100><%=redx%></td></tr>
  <tr class=tdbg-dark><td align=center>新闻类型：</td><td><%call chk_csid(nsort,cid,sid)%>&nbsp;&nbsp;&nbsp;出处：<input type=text size=20 name=comto value='<%response.write rs("comto")%>' maxlength=10>&nbsp;&nbsp;&nbsp;<input type=checkbox name=username_my value='yes'>&nbsp;<font alt='发布人：<%response.write rs("username")%>'>修改发布人为我</font></td></tr>
<%
    pic=rs("pic"):ispic=pic
    if Instr(ispic,"/")>0 then ispic=right(ispic,len(ispic)-Instr(ispic,"/"))
    if Instr(ispic,".")>0 then ispic=left(ispic,Instr(ispic,".")-1)
    if len(ispic)<1 then ispic="n"&objv7.upload_time(now_time)
%>  <tr class=tdbg-dark><td align=center>关 键 字：</td><td><input type=text size=20 name=keyes value='<%response.write rs("keyes")%>' maxlength=20>&nbsp;&nbsp;&nbsp;推荐：<input type=checkbox name=istop<%if rs("istop")=true then response.write " checked"%> value='yes'>&nbsp;选为推荐显示&nbsp;&nbsp;&nbsp;隐藏：<input type=checkbox name=hidden<%if rs("hidden")=false then response.write " checked"%> value='yes'>&nbsp;选为隐藏显示</td></tr>
<%call html_edit(rs("cod"),"add_frm","word")%>
  <tr class=tdbg-dark><td align=center valign=top><br>新闻内容：</td><td><textarea name=word rows=15 cols=70><%response.write rs("word")%></textarea></td></tr>
  <tr class=tdbg-dark><td align=center>图片新闻：</td><td><input type=checkbox name=ispic<%if rs("ispic")=true then response.write " checked"%> value='yes'>&nbsp;选为图片新闻&nbsp;&nbsp;&nbsp;图片：<input type=test name=pic value='<%response.write pic%>' size=30 maxlength=100>&nbsp;&nbsp;&nbsp;<a href='upload.asp?uppath=news&upname=<%response.write ispic%>&uptext=pic' target=upload_frame>上传图片</a>&nbsp;&nbsp;<a href='upload.asp?uppath=news&upname=n&uptext=word' target=upload_frame>上传至内容</a></td></tr>
  <tr class=tdbg-dark><td align=center>上传图片：</td><td><iframe frameborder=0 name=upload_frame width='100%' height=30 scrolling=no src='upload.asp?uppath=news&upname=<%response.write ispic%>&uptext=pic'></iframe></td></tr>
  <tr class=tdbg-dark><td colspan=2 align=center height=25><input type=submit value=' 修 改 新 闻 '></td></tr>
</form></table><%
  end if
end sub

sub news_add()
  if trim(request.querystring("add"))="chk" then
    dim topic,comto,istop,word,ispic,pic,keyes
    topic=code_admin(request.form("topic"))
    csid=trim(request.form("c_id"))
    comto=code_admin(request.form("comto"))
    keyes=code_admin(request.form("keyes"))
    istop=trim(request.form("istop"))
    word=request.form("word")
    ispic=trim(request.form("ispic"))
    pic=trim(request.form("pic"))
    if cs_nd(csid)<>"yes" then
      response.write "<font class=time>请选择新闻类型！</font><br><br>"&go_back
    elseif len(topic)<1 or len(word)<10 then
      response.write "<font class=time>新闻标题和内容不能为空！</font><br><br>"&go_back
    else
      call chk_cid_sid()
      set rs=server.createobject("adodb.recordset")
      sql="select * from "&data_name
      rs.open sql,conn,1,3
      rs.addnew
      rs("c_id")=cid
      rs("s_id")=sid
      rs("cod")=cod_type()
      rs("username")=login_username
      rs("hidden")=true
      rs("topic")=topic
      rs("comto")=comto
      rs("keyes")=keyes
      rs("word")=word
      if istop="yes" then
        rs("istop")=true
      else
        rs("istop")=false
      end if
      if ispic="yes" then
        rs("ispic")=true
      else
        rs("ispic")=false
      end if
      rs("pic")=pic
      rs("tim")=now_time
      rs("counter")=0
      rs.update
      rs.close:set rs=nothing
      call upload_note(data_name,first_id(data_name))
      response.write "<font class=time>已成功发布了一篇新闻！</font><br><br><a href='?c_id="&cid&"&s_id="&sid&"'>点击返回</a><br><br>"
    end if
  else
%><table width='100%' border=0 align=center cellpadding=2 cellspacing=1>
<form name='add_frm' action='<%response.write pageurl%>add=chk' method=post>
<input type=hidden name=upid value=''>
  <tr class=tdbg-dark><td width='15%' align=center>新闻标题：</td><td width='85%'><input type=text size=70 name=topic maxlength=100><%=redx%></td></tr>
  <tr class=tdbg-dark><td align=center>新闻类型：</td><td><%call chk_csid(nsort,cid,sid)%>&nbsp;&nbsp;&nbsp;&nbsp;出处：<input type=text size=30 name=comto maxlength=10></td></tr>
  <tr class=tdbg-dark><td align=center>关 键 字：</td><td><input type=text size=20 name=keyes maxlength=20>&nbsp;&nbsp;&nbsp;&nbsp;推荐：<input type=checkbox name=istop value='yes'>&nbsp;选上为新闻首页显示</td></tr>
<%call html_edit(1,"add_frm","word")%>
  <tr class=tdbg-dark><td valign=top align=center><br>新闻内容：</td><td><textarea name=word rows=15 cols=70></textarea></td></tr>
<%ispic="n"&objv7.upload_time(now_time)%>
  <tr class=tdbg-dark><td align=center>图片新闻：</td><td><input type=checkbox name=ispic value='yes'>&nbsp;&nbsp;&nbsp;&nbsp;图片：<input type=test name=pic size=30 maxlength=100>&nbsp;&nbsp;&nbsp;<a href='upload.asp?uppath=news&upname=<%response.write ispic%>&uptext=pic' target=upload_frame>上传图片</a>&nbsp;&nbsp;<a href='upload.asp?uppath=news&upname=n&uptext=word' target=upload_frame>上传至内容</a></td></tr>
  <tr class=tdbg-dark><td align=center>上传图片：</td><td><iframe frameborder=0 name=upload_frame width='100%' height=30 scrolling=no src='upload.asp?uppath=news&upname=<%response.write ispic%>&uptext=pic'></iframe></td></tr>
  <tr class=tdbg-dark><td colspan=2 align=center height=25><input type=submit value=' 添 加 新 闻 '></td></tr>
</form></table><%
  end if
end sub

sub news_main()
%>
<script language=javascript src='style/admin_del.js'></script>
<table border=0 width='100%' cellpadding=0>
  <tr valign=top height='100%'>
    <td width='15%' class=tdbg-dark><br><%call left_sort("","")%></td>
    <td width='85%' align=center>
<table width='100%' border=0 align=center cellpadding=2 cellspacing=1>
<form name=del_form action='<%=pageurl%>del_ok=ok' method=post>
<tr class=tdbg-dark><td width='6%'></td><td width='81%'></td><td width='13%'></td></tr>
<%
  call sql_cid_sid()
  sql="select id,c_id,s_id,topic,istop,hidden from "&data_name&sqladd&" order by id desc"
  set rs=server.createobject("adodb.recordset")
  rs.open sql,conn,1,1
  if rs.eof and rs.bof then
    rssum=0
  else
    rssum=rs.recordcount
  end if
  call format_pagecute()
  del_temp=nummer
  if rssum=0 then del_temp=0
  if int(page)=int(thepages) then
    del_temp=rssum-nummer*(thepages-1)
  end if
%>
<tr class=tdbg-tree><td colspan=3 align=center height=25>
现有<font class=time><%response.write rssum%></font>篇新闻　<%response.write "<a href='?action=add&c_id="&cid&"&s_id="&sid&"'>添加新闻</a>"%>
　<input type=checkbox name=del_all value=1 onClick=selectall('<%response.write del_temp%>')> 选中所有　<input type=submit value='删除所选' onclick=""return suredel('<%response.write del_temp%>');"">
</td></tr>
<%
  if int(viewpage)<>1 then
    rs.move (viewpage-1)*nummer
  end if
  for i=1 to nummer
    if rs.eof then exit for
    now_id=rs("id"):ncid=rs("c_id"):nsid=rs("s_id")
    response.write news_center()
    rs.movenext
  next
  rs.close:set rs=nothing
%></form>
<tr class=tdbg-dark><td colspan=3 height=25>页次：<font class=time><%response.write viewpage%></font>/<font class=time><%response.write thepages%></font>
分页：<%response.write objv7.jk_pagecute(nummer,thepages,viewpage,pageurl,5,"#ff0000")%>
</td></tr>
</table>
    </td>
  </tr>
</table>
<%
end sub

function news_center()
  news_center=VbCrLf & "<tr class=tdbg-dark>" & _
		 VbCrLf & "<td>" & i+(viewpage-1)*nummer & ". </td><td>" & _
		 VbCrLf & "<a href='?action=edit&c_id="&ncid&"&s_id="&nsid&"&id=" & now_id & "'>" & objv7.cuted(rs("topic"),30) & "</a>" & _
		 "</td><td align=right><a href='?action=hidden&c_id="&cid&"&s_id="&sid&"&id="&now_id&"&page="&viewpage&"'>"
  if rs("hidden")=true then
    news_center=news_center&"显"
  else
    news_center=news_center&"<font class=time>隐</font>"
  end if
  news_center=news_center&"</a> <a href='?action=istop&c_id="&cid&"&s_id="&sid&"&id="&now_id&"&page="&viewpage&"'>"
  if rs("istop")=true then
    news_center=news_center&"<font class=time>是</font>"
  else
    news_center=news_center&"否"
  end if
  news_center=news_center&"</a><input type=checkbox name=del_id value='"&now_id&"'></td></tr>"
end function
%>