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

header("基本信息 &gt; 网站广告设置")
select case Request.QueryString("action")
case "new"
	call new_()
case "submit"

	a_id=request.Form("a_id")
	a_title=request.Form("a_title")
	a_picurl=request.Form("a_picurl")
	a_url=request.Form("a_url")
	a_type=request.Form("a_type")
	a_order=request.Form("a_order")
	
	if a_title="" then
	response.Write ErrMsg("请输入广告标题")
	elseif a_type="" then
	response.Write ErrMsg("请选择广告类型")
	elseif a_order<>"" and isnumeric(a_order)=false then
	response.Write ErrMsg("排序必须为数字")
	end if
	
	if a_order="" then a_order=a_id
	
	set rs=server.CreateObject("adodb.recordset")
	rs.open "select * from p3t_advertisement where a_id="&a_id,conn,1,3
	if rs.eof and rs.bof then
	rs.addnew
	end if
	rs("a_title")=a_title
	rs("a_picurl")=a_picurl
	rs("a_url")=a_url
	rs("a_type")=a_type
	rs("a_order")=a_order
	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_advertisement where a_id in ("&a_id&")")	
	p3t "<script>parent.location.reload();</script>"
	p3t_end
	
case else
	call main_()
end select
footer()

sub main_()
%>
<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">
	<table cellspacing="1">
      <tr>
        <th width="20"><input type="checkbox" onclick="checkAll()" title="全选/反选" /></th>
        <th width="300">广告标题</th>
        <th>广告URL</th>
        <th width="100">广告类型</th>
        <th width="100">排序</th>
        <th width="100">基本操作</th>
      </tr>
<%
set rs=server.createobject("adodb.recordset")
sql="select * from p3t_advertisement order by a_type asc,a_order asc,a_id asc"
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,"?")
do while not rs.eof
%>
      <tr>
        <td class="center"><input name="a_id" type="checkbox" value="<%=rs("a_id")%>" /></td>
        <td><%=rs("a_title")%></td>
        <td><%=rs("a_url")%></td>
        <td class="center"><%=typeTitle(rs("a_type"))%></td>
        <td class="center"><%=rs("a_order")%></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_advertisement where a_id="&a_id)
if not rs.eof then
a_title=rs("a_title")
a_picurl=rs("a_picurl")
a_url=rs("a_url")
a_type=rs("a_type")
a_order=rs("a_order")
end if
set rs=nothing
end if
%>
<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><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_picurl" class="input" size="40" value="<%=a_picurl%>" /><br><iframe border=0 frameborder=0 framespacing=0 height=22 width=300 marginheight=0 marginwidth=0 noresize scrolling=no src="upload.asp?action=a_picurl" vspale="0"></iframe></td>
      </tr>
      <tr>
        <td class="right">广告URL</td>
        <td><input type="text" name="a_url" class="input" size="40" value="<%=a_url%>" /></td>
      </tr>
      <tr>
        <td class="right">广告类型</td>
        <td>
        <select name="a_type" id="a_type">
            <option value="" style="color:#999;">请选择类型</option>
            <option value="1">首页幻灯片</option>
            <option value="2">首页播放滚动</option>
            <option value="3">产品推荐图片</option>
        </select>
        <script type="text/javascript">document.getElementById("a_type").value="<%=a_type%>";</script>
        </td>
      </tr>
      <tr>
        <td class="right">排序</td>
        <td><input type="text" name="a_order" class="input" size="5" value="<%=a_order%>" /></td>
      </tr>
      <tr>
        <td class="right">图片备注</td>
        <td>
			首页幻灯片：图片大小(709 x 359)<br />
            首页播放滚动：图片大小(200 x 150)<br />
            产品推荐图片：图片大小(173 x 129)
        </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

function typeTitle(type_id)
dim tmp
	select case type_id
	case "1"
		tmp="首页幻灯片"
	case "2"
		tmp="首页播放滚动"
	case "3"
		tmp="产品推荐图片"
	case else
		tmp="未知"
	end select
typeTitle=tmp
end function
%>