<!--#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"
sdcms_head
%>

<div class="sdcms_notice"><span>管理操作：</span><a href="?action=add">添加广告</a>　┊　<a href="?">广告管理</a>　┊　<a href="sdcms_ad_group.asp">广告组管理</a></div>
<br>
<ul id="sdcms_sub_title">
	<li class="sub"><%=title%></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 "pass":pass
case else:main
end select
closedb
sub main
%>
  <table border="0" align="center" cellpadding="3" cellspacing="1" class="table_b" id="tagContent0">
    <tr>
      <td width="30" class="title_bg">ID</td>
      <td class="title_bg">网站广告</td>
      <td class="title_bg">类别</td>
	  <td class="title_bg">日期</td>
	  <td class="title_bg">状态</td>
      <td class="title_bg">管理</td>
    </tr>
	<%
	sql="select id,title,url,ispic,adddate,"
	if Is_sql=0 then
		sql=sql&"(iif(ispass=0,'<span>未审</span>','已审'))"
	else
		sql=sql&"(case ispass when 0 then '<span>未审</span>'else '已审' end)"
	end if
	sql=sql&" from "&sd_table&"  order by id desc"

	set rs=conn.execute(sql)
	while not rs.eof
	%>
    <tr onmouseover=this.bgColor='#EBFFDC'; onmouseout=this.bgColor='#ffffff';  bgcolor='#ffffff'>
      <td align="center" class="tdbg"><%=rs(0)%></td>
	  <td><%=rs(1)%></td>
	  <td align="center" class="tdbg"><%
	  select case rs(3)
	  case "0":echo "文字广告"
	  case "1":echo "图片广告"
	  case "2":echo "动画广告"
	  end select
	   %></td>
	   <td align="center"><%=rs(4)%></td>
	   <td align="center" class="tdbg"><%=rs(5)%></td>
      <td align="center"><input type="button"  class="bnt01" value="调用" onClick="location.href='?action=getcode&id=<%=rs(0)%>';"> <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
	wend%>
  </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="50"></td>
    </tr>
	<tr class="tdbg">
      <td align="center">广告类别：</td>
      <td>
	  <input name='t2' type='radio' onClick=$('flag').style.display='none';$('gids').style.display='none';this.form.t3.disabled=true;$('flash').style.display='block';this.form.t1.disabled=false;  value='0' checked>文字广告 
	  <input name='t2' type='radio' onClick=$('flag').style.display='block';$('gids').style.display='block';this.form.t3.disabled=false;$('flash').style.display='block';this.form.t1.disabled=false; value='1'>图片广告
	  <input name='t2' type='radio' onClick=$('flag').style.display='block';$('gids').style.display='none';this.form.t3.disabled=false;$('flash').style.display='none';this.form.t1.disabled=true; value='2' >Flash广告</td>
    </tr>
    <tr class="tdbg dis" id='flag'>
      <td align="center">广告文件：</td>
      <td><input name="t3" type="text" class="input" disabled="disabled" id="t3" size="50"> <span>暂不支持远程文件</span>
	  长：<input name="t5" type="text" class="input"  maxlength="4" size="3" onKeyUp="value=value.replace(/[^\d]/g,'');"  onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''));"> 宽：<input name="t6" type="text" class="input"  maxlength="4" size="3" onKeyUp="value=value.replace(/[^\d]/g,'');"  onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''));">	  
	  <br><%admin_upfile 2,"40%","30",0%>
	  </td>
    </tr>
	 <tr class="tdbg dis" id="gids" >
      <td align="center">广 告 组：      </td>
      <td><select name="t7" >
	    <option value="0">不使用广告组</option>
		<%
		set rs1=conn.execute("select id,title from sd_ad_group order by id desc")
		while not rs1.eof
		%>
		<option value="<%=rs1(0)%>"><%=rs1(1)%></option>
		<%rs1.movenext
		wend%>
	    </select></td>
    </tr>
	<tr class="tdbg" id="flash">
      <td align="center">连接网址：      </td>
      <td><input name="t1" type="text" class="input" id="t1" size="50">
       <span>不支持相对路径</span></td>
    </tr>
	<tr class="tdbg">
      <td align="center">是否验证：      </td>
      <td><input name="t4" type="radio" value="0">未验证 <input name="t4" type="radio" value="1" checked>已验证 </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 edit
set rs=conn.execute("select id,title,ispic,pic,url,ispass,ad_w,ad_h,gid 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=<%=id%>" onSubmit='return checkadd()'>
    <tr>
      <td width="9%" align="center" class="tdbg">广告名称：      </td>
      <td width="91%" class="tdbg"><input name="t0" type="text" class="input" value="<%=rs(1)%>" id="t0" size="50"></td>
    </tr>
   
    <tr class="tdbg">
      <td align="center">广告类别：</td>
      <td>
	  <input name='t2' type='radio' onClick=$('flag').style.display='none';$('gids').style.display='none';this.form.t3.disabled=true;$('flash').style.display='block';this.form.t1.disabled=false;  value='0' <%=w_check(rs(2),0)%>>文字广告 
	  <input name='t2' type='radio' onClick=$('flag').style.display='block';$('gids').style.display='block';this.form.t3.disabled=false;$('flash').style.display='block';this.form.t1.disabled=false; value='1' <%=w_check(rs(2),1)%>>图片广告
	  <input name='t2' type='radio' onClick=$('flag').style.display='block';$('gids').style.display='none';this.form.t3.disabled=false;$('flash').style.display='none';this.form.t1.disabled=true; value='2' <%=w_check(rs(2),2)%>>Flash广告</td>
    </tr>
	  <tr class="tdbg <%if rs(2)=0 then%>dis<%end if%>" id='flag' >
      <td align="center">广告文件：</td>
      <td><input name="t3" type="text" value="<%=rs(3)%>" class="input" id="t3" size="50"  <%if rs(2)=0 then%>disabled<%end if%>>  <span>暂不支持远程文件</span>
	  长：<input name="t5" type="text" class="input" value="<%=rs(6)%>"  maxlength="4" size="3" onKeyUp="value=value.replace(/[^\d]/g,'');"  onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''));"> 宽：<input name="t6" type="text" class="input" value="<%=rs(7)%>"  maxlength="4" size="3" onKeyUp="value=value.replace(/[^\d]/g,'');"  onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''));"><br><%admin_upfile 2,"40%","30",0%></td>
    </tr>
	  <tr class="tdbg <%if rs(2)<>1 then%>dis<%end if%>" id="gids" >
      <td align="center">广 告 组：      </td>
      <td><select name="t7" >
	    <option value="0">不使用广告组</option>
		<%
		set rs1=conn.execute("select id,title from sd_ad_group order by id desc")
		while not rs1.eof
		%>
		<option value="<%=rs1(0)%>" <%=w_select(rs(8),rs1(0))%>><%=rs1(1)%></option>
		<%rs1.movenext
		wend%>
	    </select></td>
    </tr>
	 <tr class="tdbg <%if rs(2)=2  then%>dis<%end if%>" id="flash">
      <td align="center">连接地址：  </td>
      <td><input name="t1" type="text" class="input" value="<%=rs(4)%>" id="t1" size="50"  <%if rs(2)=2  then%>disabled="disabled"<%end if%>> <span>不支持相对路径</span></td>
    </tr>
	<tr class="tdbg">
      <td align="center">是否验证：      </td>
      <td><input name="t4" type="radio" value="0" <%=w_check(rs(5),0)%>>未验证 <input name="t4" type="radio" value="1" <%=w_check(rs(5),1)%>>已验证 </td>
    </tr>
    <tr class="tdbg">
	  <td>&nbsp;</td>
      <td><input name="Submit" type="submit" class="bnt" value="保 存">
        <input name="Submit22" 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 class="tdbg">
    <tr class="tdbg">
      <td align="center">代码：</td>
      <td><textarea name="get_c" rows="6" class="inputs">{sdcms:ads(<%=id%>)}</textarea></td>
    </tr>
    <tr class="tdbg">
      <td>&nbsp;</td>
      <td>
          <input  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 save

t0=trim(request("t0"))
t1=trim(request("t1"))
t2=trim(request("t2"))
t3=trim(request("t3"))
t4=trim(request("t4"))
t5=trim(request("t5"))
t6=trim(request("t6"))
t7=trim(request("t7"))
select case t2
case "0","1","2"
case else
t2=0
end select

select case t4
case "0","1"
case else
t4=0
end select

if t5="" or not isnumeric(t5) then t5=0
if t6="" or not isnumeric(t6) then t6=0

set rs=server.CreateObject("adodb.recordset")
sql="select title,url,ispic,pic,ispass,ad_w,ad_h,gid,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,255)
rs(1)=left(t1,255)
rs(2)=left(t2,255)
rs(3)=left(t3,255)
rs(4)=t4
if t2>0 then
rs(5)=left(t5,4)
rs(6)=left(t6,4)
end if
rs(7)=t7
rs.update
remove_app("ad"&rs(8))
if act="add" then
conn.execute("Insert into sd_log (sdcms_name,ip,content) values('"&sdcms_adminname&"','"&sdcms_adminip&"','添加广告："&rs(0)&"')")
else
conn.execute("Insert into sd_log (sdcms_name,ip,content) values('"&sdcms_adminname&"','"&sdcms_adminip&"','修改广告："&rs(0)&"')")
end if
remove_app("ad_group"&t7)
response.Redirect("?")

end sub
sub del
set sdcms_f=new sdcms_function
conn.execute("Insert into sd_log (sdcms_name,ip,content) values('"&sdcms_adminname&"','"&sdcms_adminip&"','删除广告："&sdcms_f.loadrecord("title",sd_table,id)&"')")
remove_app("ad"&id)
remove_app("ad_group"&sdcms_f.loadrecord("gid",sd_table,id))
  conn.execute("delete from "&sd_table&" where id="&id&"")
  response.Redirect("?") 
set sdcms_f=nothing
end sub

sub pass
  conn.execute("update   "&sd_table&" set ispass="&t&" 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.t3.disabled && document.add.t3.value=='')")
.write("	{")
.write("	alert('广告文件不能为空');")
.write("	document.add.t3.focus();")
.write("	return false")
.write("	}")
.write("	if (!document.add.t3.disabled && document.add.t5.value=='')")
.write("	{")
.write("	alert('长度不能为空');")
.write("	document.add.t5.focus();")
.write("	return false")
.write("	}")
.write("	if (!document.add.t3.disabled && document.add.t6.value=='')")
.write("	{")
.write("	alert('宽度不能为空');")
.write("	document.add.t6.focus();")
.write("	return false")
.write("	}")
.write("	if (!document.add.t1.disabled && document.add.t1.value=='')")
.write("	{")
.write("	alert('连接网址不能为空');")
.write("	document.add.t1.focus();")
.write("	return false")
.write("	}")
.write("	}")
.write("	</script>")
end with
end sub
%>  
</div>
</body>
</html>