<!--#include file="sdcms_check.asp"-->
<%
set sdcms=new Sdcms_Admin
sdcms.Check_admin
sdcms.Check_lever 9
set sdcms=nothing
select case action
case "add":title="添加广告组"
case "edit":title="修改广告组"
case "getcode":title="调用广告组"
case else:stype=1:title="广告组管理"
end select
sd_table="sd_ad_group"
sdcms_head
%>

<div class="sdcms_notice"><span>管理操作：</span><a href="?action=add">添加广告组</a>　┊　<a href="sdcms_ad_group.asp">广告组管理</a>　┊　<a href="sdcms_ad.asp">广告管理</a></div>
<br>
<ul id="sdcms_sub_title">
	<li class="sub"><a href="javascript:void(0)" onClick="selectTag('tagContent0',this)"><%=title%></a></li>
</ul>
<div id="sdcms_right_b">
<%
select case action
case "add":add
case "edit":edit
case "save":save
case "del":del
case "getcode":getcode
case else:main
end select
closedb
sub main
%>
<table border="0" align="center" cellpadding="3" cellspacing="1" class="table_b">
    <tr>
      <td width="50" class="title_bg">ID</td>
      <td class="title_bg">名称</td>
      <td class="title_bg">日期</td>
      <td class="title_bg">管理</td>
    </tr>
	<%
	page=request.querystring("page")
	if page="" or not isnumeric(page) then
	page=1
	end if
	pages = 20
	set rs=server.CreateObject("adodb.recordset")
	sql="select id,title,adddate from "&sd_table&" order by id desc"
	rs.open sql,conn,1,1	
	if rs.eof then
	echo "<tr><td colspan=4 class=tdbg>没有广告组，<a href=?action=add>现在添加</a></td></tr>"
	else
	rs.pagesize = pages
	maxpagecount=rs.pagecount
	rs.absolutepage = page 
	rcount1=0
	pagestart=page-5
	pageend=page+5
	if pagestart<1 then
	pagestart=1
	end if
	if pageend>maxpagecount then
	pageend=maxpagecount
	end if
	rcount=rs.RecordCount
	do while not rs.eof and rcount1 <rs.pagesize  
	%>
    <tr onmouseover=this.bgColor='#EBFFDC'; onmouseout=this.bgColor='#ffffff';  bgcolor='#ffffff'>
	 <%for i=0 to 2%>
      <td <%if i<>1 then%>align="center"<%end if%>><%=rs(i)%></td>
      <%next%>
      <td align="center"><input type="button"  class="bnt01" onClick="location.href='?action=getcode&id=<%=rs(0)%>';" value="调用" > <input type="button" onClick="location.href='?action=edit&id=<%=rs(0)%>';" class="bnt01" value="编辑"> <input type="button"  onClick="if(confirm('真的要删除?不可恢复!'))location.href='?action=del&id=<%=rs(0)%>';return false;" class="bnt01" value="删除"></td>
    </tr>
	<%
	rs.movenext
	rcount1=rcount1+1
	loop
	end if
	if rcount>0 then       
	%>
	<tr>
      <td colspan="6" class="tdbg" >
	  <span class="right">转到第
		 <select onChange="location.href='?page='+this.value+''">
		 <%for i=1 to maxpagecount%>
		 <option value="<%=i%>" <%if clng(page)=clng(i) then echo "selected" end if%>><%=i%></option>
		 <%next%>
		 </select>页</span>
<%
if page<>"1" then
echo "<a href=?page="&page-1&">上一页</a> "
else
echo "上一页 "
end if
for i=pagestart to pageend
if i=0 then 
i=1
end if
if i=clng(page) then
str="<font color=red><b>"&i&"</b></font>"
else
str=i
end if
strurl="[<a href=?page="&i&">"&str&"</a>]"
echo strurl
next
if page=maxpagecount then
echo " 下一页"
elseif  page<>""&maxpagecount&"" then
echo " <a href=?page="&page+1&"&stype="&stype&"&classid="&classid&">下一页</a>"
else
echo " 下一页"
end if
echo " 页次:"&page&"/"&maxpagecount&" 页   每页: "&pages&" 条  总数: "&rcount&" 条"
%>
</td>
    </tr>
	<%end if%>
  </table>
<%
end sub
sub add
check_info
%>
<table width="98%" border="0" align="center" cellpadding="3" cellspacing="1">
  <form name="add" method="post" action="?action=save&act=add" onSubmit='return checkadd()'>
    <tr>
      <td width="9%" align="center" class="tdbg">名 称：      </td>
      <td width="91%" class="tdbg"><input name="t0" type="text" class="input" id="t0" size="40"><img id="fa" alt="方案" style="position:absolute;margin-left:120px;display:none;"></td>
    </tr>
    <tr class="tdbg">
    <tr class="tdbg">
      <td align="center">配 置：</td>
      <td>长：
        <input name="t1" type="text" class="input" id="t1" size="4" maxlength="3" onKeyUp="value=value.replace(/[^\d]/g,'');"    onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''));">
        宽：
        <input name="t2" type="text" class="input" id="t2" size="4" maxlength="3" onKeyUp="value=value.replace(/[^\d]/g,'');"   onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''));">
        标题长度：
        <input name="t3" type="text" class="input" id="t3" onKeyUp="value=value.replace(/[^\d]/g,'');" size="4" maxlength="2"  onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''));"> 
        <span>为0时不显示标题</span></td>
    </tr>
	
	<tr class="tdbg">
      <td align="center">方 案：</td>
      <td>
      <select name="t4" onChange="javascript:document.images.fa.src=this.value;fa.style.display='block';">
        <option value="../plug/ad/00.jpg">不使用方案</option>
		<%for i=1 to 2%>
        <option value="../plug/ad/0<%=i%>.jpg">方案<%=i%></option>
		<%next%>
      </select>
      </td>
    </tr>
    
   
    <tr class="tdbg">
	  <td>&nbsp;</td>
      <td><input name="Submit" type="submit" class="bnt" value="添 加">
        <input name="Submit2" type="button" onClick="history.go(-1)" class="bnt" value="返 回"></td>
    </tr>
	</form>
  </table>
<%
end sub

sub save
t0=trim(request("t0"))
t1=trim(request("t1"))
t2=trim(request("t2"))
t3=trim(request("t3"))
t4=trim(request("t4"))
if t3="" or not isnumeric(t3) then t3=0

set rs=server.CreateObject("adodb.recordset")
sql="select title,ad_w,ad_h,ad_l,ad_p,classid,id from "&sd_table&""
if act="save" then 
 sql=sql&" where id="&id&""
end if
rs.open sql,conn,1,3

if act="add" then 
  rs.addnew
else
  rs.update
end if
rs(0)=left(t0,50)
rs(1)=left(t1,3)
rs(2)=left(t2,3)
rs(3)=left(t3,2)
rs(4)=t4
rs(5)=right(replace(t4,".jpg",""),1)
rs.update
id=rs(6)
remove_app("ad_group"&id)
response.Redirect("?")
end sub

sub edit
set rs=conn.execute("select id,title,ad_w,ad_h,ad_l,ad_p,classid from "&sd_table&" where id="&id&"")
if rs.eof then
echo "请勿非法提交参数":Died
end if
check_info
%>
<table width="98%" border="0" align="center" cellpadding="3" cellspacing="1">
  <form name="add" method="post" action="?action=save&act=save&id=<%=rs(0)%>" onSubmit='return checkadd()'>
    <tr>
      <td width="9%" align="center" class="tdbg">名 称：      </td>
      <td width="91%" class="tdbg"><input name="t0" value="<%=rs(1)%>" type="text" class="input" id="t0" size="40"><img src="../plug/ad/0<%=rs(6)%>.jpg" id="fa" alt="方案" style="position:absolute;margin-left:120px;<%if rs(6)=0 then%>display:none;<%end if%>"></td>
    </tr>
    <tr class="tdbg">
    <tr class="tdbg">
      <td align="center">配 置：</td>
      <td>长：
        <input name="t1" type="text" class="input" value="<%=rs(2)%>" id="t1" size="4" maxlength="3" onKeyUp="value=value.replace(/[^\d]/g,'');"    onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''));">
        宽：
        <input name="t2" type="text" class="input" value="<%=rs(3)%>" id="t2" size="4" maxlength="3" onKeyUp="value=value.replace(/[^\d]/g,'');"   onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''));">
        标题长度：
        <input name="t3" type="text" class="input" value="<%=rs(4)%>" id="t3" onKeyUp="value=value.replace(/[^\d]/g,'');" size="4" maxlength="2"  onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''));"> 
        <span>为0时不显示标题</span></td>
    </tr>
	
	<tr class="tdbg">
      <td align="center">方 案：</td>
      <td>
      <select name="t4" onChange="javascript:document.images.fa.src=this.value;fa.style.display='block';">
        <option value="../plug/ad/00.jpg" <%=w_select(rs(6),0)%>>不使用方案</option>
		<%for i=1 to 2%>
        <option value="../plug/ad/0<%=i%>.jpg" <%=w_select(rs(6),i)%>>方案<%=i%></option>
		<%next%>
      </select>
      </td>
    </tr>  
    <tr class="tdbg">
	  <td>&nbsp;</td>
      <td><input name="Submit" type="submit" class="bnt" value="保 存">
        <input name="Submit2" type="button" onClick="history.go(-1)" class="bnt" value="返 回"></td>
    </tr>
	</form>
  </table>
<%
end sub
sub getcode
set rs=conn.execute("select id from "&sd_table&" where id="&id&"")
if rs.eof then
echo "请勿非法提交参数":Died
end if
%>
<table width="98%" border="0" align="center" cellpadding="3" cellspacing="1">
    <tr>
      <td width="9%" align="center" class="tdbg">选择： </td>
      <td width="91%" class="tdbg"><img id="fa" alt="方案" style="position:absolute;margin-left:120px;display:none;">
      <input name="c" type="radio" value="0" checked >
      首页      </td>
    </tr>
    <tr class="tdbg">
    <tr class="tdbg">
      <td align="center">代码：</td>
      <td><textarea name="get_c" rows="6" class="inputs">{sdcms:ad_group(<%=id%>)}</textarea></td>
    </tr>
    <tr class="tdbg">
      <td>&nbsp;</td>
      <td><input name="Submit22" type="button"   class="bnt" value="复制" onClick="CopyUrl(get_c);">
          <input name="Submit22" type="button" onClick="history.go(-1)" class="bnt" value="返 回"></td>
    </tr>
</table>
<%
end sub
sub del
	conn.execute("delete from "&sd_table&" where id="&id&"")
	response.Redirect("?") 
end sub
sub check_info
with response
.write("	<script>")
.write("	function checkadd()")
.write("	{")
.write("	if (document.add.t0.value=='')")
.write("	{")
.write("	alert('名称不能为空');")
.write("	document.add.t0.focus();")
.write("	return false")
.write("	}")
.write("	if (document.add.t1.value=='')")
.write("	{")
.write("	alert('长不能为空');")
.write("	document.add.t1.focus();")
.write("	return false")
.write("	}")
.write("	if (document.add.t2.value=='')")
.write("	{")
.write("	alert('宽不能为空');")
.write("	document.add.t2.focus();")
.write("	return false")
.write("	}")
'.write("	if (document.add.t3.value=='')")
'.write("	{")
'.write("	alert('标题长度不能为空');")
'.write("	document.add.t3.focus();")
'.write("	return false")
'.write("	}")
.write("	}")
.write("	</script>")
end with
end sub
%>   
</div>
</body>
</html>