<!--#include file="../inc/config.asp"-->
<!--#include file="../inc/conn.asp"-->
<!-- #include file="inc/Session.asp" -->
<!-- #include file="inc/checkrole.asp" -->
<HTML>
<HEAD>
<TITLE>添加广告</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<style>
body,td,input,textarea {font-size:9pt}
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
.style1 {
	color: #FFFFFF;
	font-weight: bold;
}
</style>
<script language="JavaScript" src="../js/PublicJS.js"></script>
</HEAD>
<BODY>
<%
'''''''''''''''''''''''''''''''''''''''''''''''
call checkPrevilege(Session("Name"),"p14")
'''''''''''''''''''''''''''''''''''''''''''''''
%>
<table width="100%"  border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><iframe src="right_top.htm" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" height="30" width="100%"></iframe></td>
  </tr>
</table>
<%
dim act,catalogid,title,adType,photo,imgW,imgH,linkUrl,content,expiretime,effectId
act=request.QueryString("act")
if(act="add") then
	if isnumeric(request.Form("catalogid")) then
		catalogid=Clng(request.Form("catalogid"))
	else
		response.Write("<script>alert('类别不能为空！');history.back();</script>")
	end if
	title=trim(request.Form("title"))
	if(isnull(title) or len(title)<1) then
		response.Write("<script>alert('广告标题不能为空！');history.back();</script>")
		response.End()
	end if
	adType=Cint(request.Form("adType"))
	if(isnull(adType) or not isnumeric(adType)) then
		response.Write("<script>alert('广告类型不能为空！');history.back();</script>")
		response.End()
	end if
	expiretime=request.Form("expiretime")
	if(isnull(expiretime) or not isdate(expiretime)) then
		response.Write("<script>alert('请填写正确的过期日期！');history.back();</script>")
		response.End()
	else
		expiretime=Cdate(expiretime)
	end if
	effectId=Cint(request.Form("effectId"))
	linkUrl=trim(Request.Form("linkUrl"))
	if(adType=0) then		
		content=trim(Request.Form("content"))
		if(isnull(content) or len(content)<1) then
			response.Write("<script>alert('广告内容不能为空！');history.back();</script>")
			response.End()
		end if
	elseif(adType=1) then
		photo=trim(Request.Form("photo"))
		if not isempty(request.Form("imgW")) then 
			imgW=request.Form("imgW")
		end if
		if not isempty(request.Form("imgH")) then 
			imgH=request.Form("imgH")
		end if	
		
		if(isnull(photo) or len(photo)<1) then
			response.Write("<script>alert('图片地址不能为空！');history.back();</script>")
			response.End()
		end if
		if(isnull(imgW) or len(imgW)<1) then
			response.Write("<script>alert('图片宽度不能为空！');history.back();</script>")
			response.End()
		end if
		if(isnull(imgH) or len(imgH)<1) then
			response.Write("<script>alert('图片高度不能为空！');history.back();</script>")
			response.End()
		end if
		if(isnull(linkUrl) or len(linkUrl)<1) then
			response.Write("<script>alert('图片链接地址不能为空！');history.back();</script>")
			response.End()
		end if
	elseif(adType=2) then
		photo=trim(Request.Form("photo"))
		if not isempty(request.Form("imgW")) then 
			imgW=request.Form("imgW")
		end if
		if not isempty(request.Form("imgH")) then 
			imgH=request.Form("imgH")
		end if	
		if(isnull(photo) or len(photo)<1) then
			response.Write("<script>alert('flash地址不能为空！');history.back();</script>")
			response.End()
		end if
		if(isnull(imgW) or len(imgW)<1) then
			response.Write("<script>alert('flash宽度不能为空！');history.back();</script>")
			response.End()
		end if
		if(isnull(imgH) or len(imgH)<1) then
			response.Write("<script>alert('flash高度不能为空！');history.back();</script>")
			response.End()
		end if
	end if
	
	
	'''''''''''''''''''''''''''''''''添加到库''''''''''''''''''''''''''''
	set rs=server.createobject("adodb.recordset")
	sql="select top 1 * from ad where 1=0 order by id desc "
	rs.open sql,conn,3,3
	rs.addnew
	rs("catalogId")=catalogid
	rs("title")=title
	rs("content")=content
	rs("adType")=adType
	rs("photo")=photo
	rs("linkUrl")=linkUrl
	rs("imgW")=imgW
	rs("imgH")=imgH
	rs("expiretime")=expiretime
	rs("moditime")=now
	rs("effectId")=effectId
	rs("hits")=0
	rs("adStatus")=1
	rs.update
	rs.close
	set rs=nothing
	''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
	response.Write("<p align=""center"">成功添加广告~!</p>")
	response.Write("<p align=""center""><br><a href=""ad_add.asp"">继续添加-></a></p>")
else
%>
<FORM method="POST" name="form1" action="ad_add.asp?act=add" style="margin:0 0 0 0;">
  <TABLE width="100%" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#666666">
<TR bgcolor="#FF9900">
  <TD height="22" colspan="2"><div align="center" class="style1">添加广告</div></TD>
  </TR>
<TR bgcolor="#F5F5F5">
  <TD width="18%"><div align="center">所 属 类 别：</div></TD>
  <TD width="82%">
  <select name="catalogid" >
  	<%
	classid=Cint(request("classid"))
	set rs=server.CreateObject("adodb.recordset")
	sql="select id,title from catalogs where parentid="&classid&" order by id asc"
	rs.open sql,conn,3,1
	if not rs.eof then
		first=rs.GetRows()
	else
		response.Write("<option>点击右边＋号选择栏目</option>")
	end if
	rs.close
	set rs=nothing
	if(isarray(first)) then
  		for i=0 to ubound(first,2)
			response.Write("<option value="&first(0,i)&">├"&first(1,i)&"</option>"&Chr(10))	    	
		next	
	end if
%>
	%>	  	     
 </select>&nbsp;&nbsp;<a href="#" onClick="addParentOption();">＋</a></TD>
</TR>
<TR bgcolor="#F5F5F5">
  <TD><div align="center">标题名称：</div></TD>
  <TD><input name="title" type="text" id="title" size="60"></TD>
</TR>
<TR bgcolor="#F5F5F5">
  <TD><div align="center">广告类型：</div></TD>
  <TD><input name="adType" type="radio" onClick="chanText()" value="0" checked>
    文字
      <input name="adType" type="radio" value="1" onClick="chanImg()">
图片
<input name="adType" type="radio" value="2" onClick="chanFlash()"> 
Flash</TD>
</TR>
<TR bgcolor="#F5F5F5">
  <TD><div align="center">广告效果：</div></TD>
  <TD>
  <select name="effectId" id="effectId">
    <option value="0">无</option>
    <option value="1">对联广告</option>
    <option value="2">漂浮广告</option>
    <option value="3">右下角弹出广告</option>
  </select>
  </TD>
</TR>
<TR bgcolor="#F5F5F5" id="objUrl">
  <TD><div align="center">图片|Flash地址：</div></TD>
  <TD><div align="left">
    <input name="photo" type="text" id="photo" size="50">
    <input type="button" name="Button" value="上传->" onClick="javascript:document.form1.photo.value=window.showModalDialog('upimg.htm','','dialogHeight:130px;dialogWidth:410px;help:no;status:no;scroll:no')">
  </div></TR>
<TR bgcolor="#F5F5F5" id="objWidth">
  <TD><div align="center">图片|Flash宽度：</div></TD>
  <TD><div align="left">
    <input name="imgW" type="text" id="imgW" size="10">
  </div></TR>
<TR bgcolor="#F5F5F5" id="objHeight">
  <TD><div align="center">图片|Flash高度：</div></TD>
  <TD><div align="left">
    <input name="imgH" type="text" id="imgH" size="10">
  </div></TR>
<TR bgcolor="#F5F5F5" id="objLink">
  <TD><div align="center">链接URL：</div></TD>
  <TD><div align="left">
    <input name="linkUrl" type="text" id="linkUrl" size="60">
  </div></TR>
<TR bgcolor="#F5F5F5" style="display:none; " id="textContent">
	<TD><div align="center">广告内容：</div></TD>
	<TD>		
	<textarea rows="12" name="content" cols="70"></textarea></TR>
<TR bgcolor="#F5F5F5">
  <TD align=right><div align="center">过期日期：</div></TD>
  <TD align=right><div align="left">
    <input name="expiretime" type="text" id="expiretime" size="30" value="<%=dateadd("d",now,30)%>">
    <input name="sdaf" type="button" id="sdaf" onClick="OpenWindowAndSetValue('Inc/SelectDate.asp',280,120,window,document.form1.expiretime);document.form1.expiretime.focus();" value="选择日期">
  </div></TD>
</TR>
<TR bgcolor="#F5F5F5">
	<TD align=right>&nbsp;	  </TD>
    <TD align=right><div align="left"> 
        <input type=submit name=b1 value="提 交">&nbsp;&nbsp;
        <input type=reset name=b2 value="重 填">       
    </div></TD>
</TR>
</TABLE>
</FORM>
<script>
function chanText()
{
	document.getElementById("objUrl").style.display='none';
	document.getElementById("objWidth").style.display='none';
	document.getElementById("objHeight").style.display='none';
	document.getElementById("textContent").style.display='';
}
function chanImg()
{
	document.getElementById("objUrl").style.display='';
	document.getElementById("objWidth").style.display='';
	document.getElementById("objHeight").style.display='';
	document.getElementById("textContent").style.display='none';
}
function chanFlash()
{
	document.getElementById("objUrl").style.display='';
	document.getElementById("objWidth").style.display='';
	document.getElementById("objHeight").style.display='';
	document.getElementById("textContent").style.display='none';
}
chanText();
function addParentOption()
{
	var arr = showModalDialog("tree_container.asp", "", "dialogWidth:410px; dialogHeight:420px; status:0");
  	if (arr != null){  
   		document.form1.catalogid.options[0]=new Option(arr[1],arr[0]);
  	}
	
}
</script>
<%
end if
%>
</BODY>
</HTML>
<%
call connclose()
%>