<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="admin.asp"-->
<!--#include file="../inc/conn.asp"-->
<!--#include file="../inc/function.asp"-->
<%
if request("action")=2 then
set rs=server.CreateObject("adodb.recordset")
rsq="select * from cw_ad"
rs.open rsq,conn,1,3
rs.addnew
rs("title")=request("title")
rs("type")=request("type")
rs("link")=request("link")
rs("pic")=request("pic")
rs("code")=request("code")
rs("content")=request("content")
rs("width")=request("width")
rs("height")=request("height")
rs.update
rs.close
set rs=nothing
set conn=nothing
response.Write("<script>alert('广告添加成功!'); location.href='cw_ad.asp'</script>")
response.End()
end if

if request("action")=3 then
set rs=server.CreateObject("adodb.recordset")
rsq="select * from cw_ad where id="&request("id")&""
rs.open rsq,conn,1,3
pic=trim(rs("pic"))
rs("title")=request("title")
rs("type")=request("type")
rs("link")=request("link")
rs("pic")=request("pic")
rs("code")=request("code")
rs("content")=request("content")
rs("width")=request("width")
rs("height")=request("height")
rs.update
rs.close
set rs=nothing
set conn=nothing
if pic<>request("pic") then
  cw_del(cf_root&pic)
end if
response.Write("<script>alert('广告修改成功!'); location.href='cw_ad.asp'</script>")
response.End()
end if

if request("action")=4 then
  set rs=server.CreateObject("adodb.recordset")
  sql="select * from cw_ad where id="&request("id")&""
  rs.open sql,conn,1,3
  types=rs("type")
  pic=trim(rs("pic"))
  rs.delete
  rs.close
  set rs=nothing
  if types=0 or types=2 then'广告是图片或者FLASH的话删除
     if pic<>"" then cw_del(cf_root&pic)
  end if
  response.Write("<script>alert('广告删除成功!'); location.href='cw_ad.asp'</script>")
  response.End()
end if
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>广告管理</title>
<link href="style/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function check_ad(fr)
{
  if (fr.title.value=="")
  {
    alert('名称不能为空!');
	fr.title.focus();
	return false
  }
  if(document.getElementById('a1').style.display=="inline")
  {
     if(fr.pic.value=="")
	 {
	   alert('图片地址不能为空！');
	   fr.pic.focus();
	   return false
	 }
  }
  if(document.getElementById('a3').style.display=="inline")
  {
    if(fr.code.value=="")
	{
	  alert('广告代码不能为空！');
	  return false
	}
  }
  return true
}
function checkad(ad)
{
  if(ad==0)
  {    
     document.getElementById('a1').style.display="inline";
	 document.getElementById('a2').style.display="inline";
	 document.getElementById('a3').style.display="none";
	 document.getElementById('a4').style.display="inline";
	 document.getElementById('a5').style.display="inline";
  }
  if(ad==1)
  {
     document.getElementById('a1').style.display="none";
	 document.getElementById('a2').style.display="none";
	 document.getElementById('a3').style.display="inline";
	 document.getElementById('a4').style.display="none";
	 document.getElementById('a5').style.display="none";
  }
  if(ad==2)
  {
     document.getElementById('a1').style.display="inline";
	 document.getElementById('a2').style.display="inline";
	 document.getElementById('a3').style.display="none";
	 document.getElementById('a4').style.display="none";
	 document.getElementById('a5').style.display="inline";
  }
}
  
function Copy(id)
{  
   var txt="<scr"+"ipt src='{cw:webroot}plug/ad.asp?id="+id+"'></scr"+"ipt>";
   var i=0 ;
   window.clipboardData.setData('text', txt);
   if(window.clipboardData.getData('text')=='')
   {  
       if(i==1){  
                alert("复制失败，请手动Ctrl+C快捷键复制！");  
            }else{  
                alert("复制失败，请重新复制！");  
                i = 1;  
            }  
        }else{  
             alert("复制成功！");  
        }  
    }  
</script>
</head>

<body id="page">
<h2 class="title">广告管理</h2>
<table width="99%" border="0" align="center" class="nav">
  <tr>
    <td height="20">&nbsp;网站后台管理 &gt;&gt; <a href="cw_ad.asp">广告管理</a>&nbsp;&nbsp;&nbsp;&nbsp;【<a href="cw_ad.asp?add=1" style="color:#FF0000">添加广告</a>】</td>
  </tr>
</table>
	<%if request("add")="" then%>
	<table width="99%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">
      <tr>
        <td width="6%" align="center" bgcolor="#F0F3F5">ID</td>
        <td width="20%" align="center" bgcolor="#F0F3F5">广告名称</td>
        <td width="28%" align="center" bgcolor="#F0F3F5">链接地址</td>
        <td width="8%" align="center" bgcolor="#F0F3F5">广告类型</td>
		<td width="20%" align="center" bgcolor="#F0F3F5">广告备注</td>
        <td width="18%" align="center" bgcolor="#F0F3F5">管理</td>
      </tr>
    <%
		set rs1=server.CreateObject("adodb.recordset")
		sql="select * from cw_ad order by id desc"
		rs1.open sql,conn,1,1
		if not rs1.eof then
		         page_count=15
  				 if Request("page")="" or Request("page")="0" then
   				  page=1
  				 else
    				 page=cint(Request("page"))
  				 End if 
					 totalcount=rs1.RecordCount
   				  totalpage=int(totalcount/page_count+(page_count-1)/page_count)
  				 if page>totalpage then page=totalpage
  				 if rs1.EOF then    
   				  else
   				  for i = 1 to (page-1)*page_count
    				   rs1.MoveNext
   				  Next
   				  if page<totalpage then
    				   psize=page_count
   				  else
   				    psize=totalcount-(page-1)*page_count
   				  End if
   				  for i = 1 to psize
				  select case rs1("type")
				  case 0
				  jj="图片"
				  case 1
				  jj="代码"
				  case 2
				  jj="Flash"
				  end select
		%>
      <tr >
        <td align="center" bgcolor="#FFFFFF"><%=rs1("id")%></td>
        <td bgcolor="#FFFFFF">&nbsp;&nbsp;<%=rs1("title")%></td>
        <td bgcolor="#FFFFFF" ><a href="<%=rs1("link")%>" target="_blank"><%=rs1("link")%></a></td>
        <td align="center" bgcolor="#FFFFFF" ><%=jj%></td>
		<td align="center" bgcolor="#FFFFFF" ><%=rs1("content")%></td>
        <td align="center" bgcolor="#FFFFFF" ><a href="?" onclick="Copy('<%=rs1("id")%>')">复制代码</a> | <a href="cw_ad.asp?add=2&amp;id=<%=rs1("id")%>">编辑</a> | <a href="cw_ad.asp?id=<%=rs1("id")%>&amp;action=4" onclick="return confirm('你确定要删除？')">删除</a></td>
      </tr>
	      <%
		 rs1.MoveNext
 		next
		end if

		end if
		rs1.close
		set rs1=nothing
		%>
		   <tr >
        <td colspan="6" align="center" bgcolor="#FFFFFF">
		<div style="float:left">
		调用广告：&lt;script src=&quot;{cw:webroot}plug/ad.asp?id=1&quot;&gt;&lt;/script&gt;
		</div>
		<!--#include file="../inc/page.asp"-->
		</td>
        </tr>
    </table>
	<%end if%>
	<%if request("add")=1 then%>
      <table width="99%" border="0">
	  <form id="form1" name="form1" method="post" onsubmit="return check_ad(this)" action="cw_ad.asp?action=2">
        <tr>
          <td width="100" align="center">&nbsp;</td>
          <td><h3>添加广告</h3></td>
        </tr>
        <tr>
          <td align="right">广告名称：</td>
          <td width="997"><input name="title" type="text" id="title" size="40" maxlength="240" /></td>
        </tr>
        <tr>
          <td align="right">广告类型：</td>
          <td><input name="type" type="radio" value="0" checked="checked" onclick="checkad('0')" />
          图片
            <input type="radio" name="type" value="1"  onclick="checkad('1')"  />
          代码
          <input type="radio" name="type" value="2"  onclick="checkad('2')" />
          Flash</td>
        </tr>
        <tr id="a1">
          <td align="right">文件地址：</td>
          <td><input name="pic" type="text" id="pic" size="40" maxlength="240"/> 
          *可以输入网络地址或者上传 </td>
        </tr>
        <tr id="a2">
          <td align="right">上传文件：</td>
          <td><iframe src="../inc/upload.asp?lei=2&pid=pic" frameborder="0" width="400" height="25" scrolling="No"></iframe></td>
        </tr>
        <tr id="a5">
          <td align="right">广告大小：</td>
          <td><input name="width" type="text" id="width" size="10" maxlength="5" />
            宽度(PX)
              <input name="height" type="text" id="height" size="10" maxlength="5" />
            高度(PX)</td>
        </tr>
        <tr id="a3" style="display:none">
          <td align="right">广告代码：</td>
          <td><textarea name="code" cols="80" rows="12" id="code"></textarea></td>
        </tr>
        <tr id="a4">
          <td align="right">链接地址：</td>
          <td><input name="link" type="text" id="link" size="40" maxlength="240" />
          *广告图片的链接地址http://www.abc.com</td>
        </tr>
        <tr>
          <td align="right">广告备注：</td>
          <td><input name="content" type="text" id="content" size="40" maxlength="240" /></td>
        </tr>
        
        <tr>
          <td>&nbsp;</td>
          <td><input name="Submit" type="submit" class="btn" onclick="checkform()" value="添加广告" /></td>
        </tr>
		</form>
    </table>
	<%end if%>
	<%if request("add")=2 then%>
	<%
	if request("id")="" then
	  response.Write("<script>alert('参数错误!'); history.back();</script>")
	end if
	set rs=server.CreateObject("adodb.recordset")
	sql="select * from cw_ad where id="&request("id")&""
	rs.open sql,conn,1,1
	if not rs.eof then
	%>
	<table width="99%" border="0">
	  <form id="form1" name="form1" method="post" onsubmit="return check_ad(this)" action="cw_ad.asp?action=3">
        <tr>
          <td width="100" align="center">&nbsp;</td>
          <td><h3>添加广告</h3></td>
        </tr>
        <tr>
          <td align="right">广告名称：</td>
          <td width="997"><input name="title" type="text" id="title" size="40" maxlength="240" value="<%=rs("title")%>" /></td>
        </tr>
        <tr>
          <td align="right">广告类型：</td>
          <td><input name="type" type="radio" value="0" <%if rs("type")=0 then%>checked="checked"<%end if%> onclick="checkad('0')" />
          图片
            <input type="radio" name="type" value="1" <%if rs("type")=1 then%>checked="checked"<%end if%> onclick="checkad('1')"  />
          代码
		  <input type="radio" name="type" value="1" <%if rs("type")=2 then%>checked="checked"<%end if%> onclick="checkad('2')"  />
		  Flash</td>
        </tr>
        <tr id="a1">
          <td align="right">文件地址：</td>
          <td><input name="pic" type="text" id="pic" size="40" maxlength="240" value="<%=rs("pic")%>"/>
          *可以输入网络图片地址或者上传图 </td>
        </tr>
        <tr id="a2">
          <td align="right">上传文件：</td>
          <td><iframe src="../inc/upload.asp?lei=2&pid=pic" frameborder="0" width="400" height="25" scrolling="No"></iframe></td>
        </tr>
		<tr id="a5">
          <td align="right">广告大小：</td>
          <td><input name="width" type="text" id="width" value="<%=rs("width")%>" size="10" maxlength="5" />
            宽度(PX)
              <input name="height" type="text" id="height" value="<%=rs("height")%>" size="10" maxlength="5" />
            高度(PX)</td>
        </tr>
        <tr id="a3" style="display:none">
          <td align="right">广告代码：</td>
          <td><textarea name="code" cols="80" rows="12" id="code"><%=rs("code")%></textarea></td>
        </tr>
        <tr id="a4">
          <td align="right">链接地址：</td>
          <td><input name="link" type="text" id="link" size="40" maxlength="240" value="<%=rs("link")%>" />
*广告图片的链接地址http://www.abc.com</td>
        </tr>
        <tr>
          <td align="right">广告备注：</td>
          <td><input name="content" type="text" id="content" size="40" maxlength="240" value="<%=rs("content")%>" /></td>
        </tr>        
        <tr>
          <td>&nbsp;</td>
          <td><input name="Submit" type="submit" class="btn" onclick="checkform()" value="修改广告" />
          <input name="id" type="hidden" id="id" value="<%=rs("id")%>" /></td>
        </tr>
	  </form>
		<script type="text/javascript">window.onload=checkad('<%=rs("type")%>')</script>
    </table>
	<%
	end if
	rs.close
	set rs=nothing
	%>
	<%end if%>
</body>
</html>
