<!--#include file="function.asp"-->
<%
checkLogin()

header("文章管理 &gt; 文章列表")
select case Request.QueryString("action")
case "new"
	call new_()
case "submit"

	a_id=request.Form("a_id")
	ac_id=request.Form("ac_id")
	a_title=request.Form("a_title")
	a_url=request.Form("a_url")
	a_content=request.Form("a_content")
	a_recommend=request.Form("a_recommend")
	a_date=request.Form("a_date")
	
	if ac_id="" then
	p3t ErrMsg("请选择文章分类")
	elseif a_title="" then
	p3t ErrMsg("请输入文章标题")
	elseif a_content="" then
	p3t ErrMsg("请输入文章内容")
	end if
	
	set rs=server.CreateObject("adodb.recordset")
	rs.open "select * from p3t_article where a_id="&a_id,conn,1,3
	if rs.eof and rs.bof then
	rs.addnew
	end if
	rs("ac_id")=ac_id
	rs("a_title")=a_title
	rs("a_url")=a_url
	rs("a_content")=a_content
	rs("a_recommend")=a_recommend
	rs("a_date")=a_date
	rs.update
	rs.close
	set rs=nothing
	
	p3t "<script>alert('操作成功');parent.location.href='?';</script>"
	p3t_end
	
case "del"
	
	a_id=request.QueryString("a_id")
	if a_id="" then a_id=request.QueryString("val")
	conn.execute("delete from p3t_article where a_id in ("&a_id&")")	
	p3t "<script>parent.location.reload();</script>"
	p3t_end
	
case else
	call main_()
end select
footer()

sub main_()
ac_id=request.QueryString("ac_id")
if ac_id="" or isnumeric(ac_id)=false then ac_id=0
%>
<script type="text/javascript" src="images/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
	$("table tr").hover(function(){
		$(this).addClass("hover");
	},function(){
		$(this).removeClass("hover");
	});
});
function checkAll(){
	$("table input:checkbox").each(function(){
		this.checked = !this.checked; 
	});
}
function edit(){
	var val = $("table input:checkbox:checked").map(function(data){return this.value}).get().join(",");
	if (val == "")
		alert("请至少选择一条信息");
	else if (val.split(",").length > 1)
		alert("请选择一条信息");
	else
		location.href = "?action=new&val=" + val;
}
function del(){
	var val = $("table input:checkbox:checked").map(function(data){return this.value}).get().join(",");
	if (val == "")
		alert("请至少选择一条信息");
	else
		if(confirm("您确定要删除这 " + val.split(",").length + " 条信息吗？"))yukiiak.location.href = "?action=del&val=" + val;
}
</script>
<div class="main_ctrl">
	<p><a>操作选项：</a>
    <a href="?action=new"><img src="images/btn_add.gif" />添加</a> |
    <a href="javascript:edit()"><img src="images/btn_edit.gif" />编辑</a> |
    <a href="javascript:del()"><img src="images/btn_del.gif" />删除</a>
    </p>
</div>
<div class="main_body">
	<div class="subtitle">
    	选择文章分类：
        <select onchange="location.href='?ac_id='+this.value;">
        	<option value="0"<%if 0=int(ac_id) then p3t "selected"%>>全部文章</option>
        <%
		set rs=conn.execute("select * from p3t_article_category where ac_id_parent=0 order by ac_order asc,ac_id asc")
		do while not rs.eof
		%>
        	<option value="0"><%=rs("ac_title")%></option>
			<%
            set rs_ac=conn.execute("select * from p3t_article_category where ac_id_parent="&rs("ac_id")&" order by ac_order asc,ac_id asc")
            do while not rs_ac.eof
            %>
                <option value="<%=rs_ac("ac_id")%>"<%if rs_ac("ac_id")=int(ac_id) then p3t "selected"%>>├ <%=rs_ac("ac_title")%></option>
            <%
            rs_ac.movenext
            loop
            set rs_ac=nothing
            %>
        <%
		rs.movenext
		loop
		set rs=nothing
		%>
        </select>
    </div>
	<table cellspacing="1">
      <tr>
        <th width="20"><input type="checkbox" onclick="checkAll()" title="全选/反选" /></th>
        <th width="100">文章分类</th>
        <th width="200">文章标题</th>
        <th>文章链接</th>
        <th width="100">添加时间</th>
        <th width="100">基本操作</th>
      </tr>
<%
set rs=server.createobject("adodb.recordset")
if ac_id<>0 then
sql="select * from p3t_article where ac_id="&ac_id&" order by a_id desc"
else
sql="select * from p3t_article order by a_id desc"
end if
rs.open sql,conn,1,1
if rs.eof then 
p3t "<tr><td class=""center"" colspan=""10"">暂无信息</td></tr>"
else
PageSize=10
NowPage=Request.QueryString("Page")
If NowPage="" Then:NowPage=1:Else:NowPage=Int(NowPage):End If
rs.PageSize=PageSize
rs.AbsolutePage=NowPage
i=0:PageList=0
'分页
pages=getPages(rs,NowPage,PageSize,PageList,"?ac_id="&ac_id)
do while not rs.eof
%>
      <tr>
        <td class="center"><input name="a_id" type="checkbox" value="<%=rs("a_id")%>" /></td>
        <td class="center"><%=connExecute("select ac_title from p3t_article_category where ac_id="&rs("ac_id"),0)%></td>
        <td><%=rs("a_title")%><%if rs("a_recommend")=1 then p3t " [推荐]"%></td>
        <td><%=rs("a_url")%></td>
        <td class="center"><%=formatDate(rs("a_date"),3)%></td>
        <td class="center">
        	<a href="?action=new&a_id=<%=rs("a_id")%>">编辑</a> |
            <a href="javascript:;" onclick="if(confirm('您确定要删除这条信息吗？'))yukiiak.location.href = '?action=del&a_id=<%=rs("a_id")%>';">删除</a>
        </td>
      </tr>
<%
i=i+1
if i=PageSize Then Exit Do  
rs.movenext
LOOP
end if
rs.close
set rs=nothing
%>
    </table>
    <div class="pager"><%=pages%></div>
</div>
<%
end sub
sub new_()
a_id=request.QueryString("a_id")
if a_id="" then a_id=request.QueryString("val")
if a_id="" or isnumeric(a_id)=false then a_id=0
if a_id<>0 then
set rs=conn.execute("select * from p3t_article where a_id="&a_id)
if not rs.eof then
ac_id=rs("ac_id")
a_title=rs("a_title")
a_recommend=rs("a_recommend")
a_url=rs("a_url")
a_content=rs("a_content")
a_date=rs("a_date")
end if
set rs=nothing
end if
if a_date="" then a_date=date()
%>
<script type="text/javascript" src="images/calendar.js"></script>
<div class="main_ctrl">
	<p><a>操作选项：</a>
    <a href="javascript:history.back()"><img src="images/btn_list.gif" />返回列表</a>
    </p>
</div>
<div class="main_body">
	<table cellspacing="1">
    <form name="form1" action="?action=submit" method="post" target="yukiiak">
      <tr>
        <th colspan="2" class="left"><%if a_id=0 then p3t "新建" else p3t "编辑ID："&a_id%></th>
      </tr>
      <tr>
        <td width="100" class="right">产品分类</td>
        <td>
        <select name="ac_id" id="ac_id" onchange="if(this.value==0)this.value='';">
        <option value="" style="color:#999">请选择分类..</option>
        <%
        set rs=conn.execute("select * from p3t_article_category where ac_id_parent=0 order by ac_order asc,ac_id asc")
        do while not rs.eof
        %>
        <option value="0"><%=rs("ac_title")%></option>
			<%
            set rs_ac=conn.execute("select * from p3t_article_category where ac_id_parent="&rs("ac_id")&" order by ac_order asc,ac_id asc")
            do while not rs_ac.eof
            %>
            <option value="<%=rs_ac("ac_id")%>">├ <%=rs_ac("ac_title")%></option>
            <%
            rs_ac.movenext
            loop
            set rs_ac=nothing
            %>
        <%
        rs.movenext
        loop
        set rs=nothing
        %>
        </select>
        <script>document.getElementById("ac_id").value='<%=ac_id%>';</script>
        </td>
      </tr>
      <tr>
        <td class="right">文章标题</td>
        <td><input type="text" name="a_title" class="input" size="40" value="<%=a_title%>" /></td>
      </tr>
      <tr>
        <td class="right">外部链接</td>
        <td><input type="text" name="a_url" class="input" size="40" value="<%=a_url%>" /></td>
      </tr>
      <tr>
        <td class="right">文章内容</td>
        <td><textarea name="a_content" style="display:none"><%=a_content%></textarea>
        <iframe id="a_content" src="../ewebedit/ewebeditor.asp?id=a_content&style=standard1" frameborder="0" scrolling="no" width="555" height="350"></iframe></td>
      </tr>
      <tr>
        <td class="right">是否推荐</td>
        <td><label><input type="checkbox" name="a_recommend" value="1"<%if a_recommend=1 then p3t " checked"%> />推荐</label></td>
      </tr>
      <tr>
        <td class="right">发布时间</td>
        <td><input type="text" name="a_date" class="input" size="10" value="<%=formatdate(a_date,2)%>" onfocus="calendar()" /></td>
      </tr>
      <tr>
        <td></td>
        <td>
			<input name="a_id" type="hidden" value="<%=a_id%>">
        	<input type="submit" name="submit" class="button" value=" 提 交 " />
        </td>
      </tr>
    </form>
    </table>
</div>
<%
end sub
%>