<!--#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>

</HEAD>
<BODY>
<%
'''''''''''''''''''''''''''''''''''''''''''''''
call checkPrevilege(Session("Name"),"p14")
'''''''''''''''''''''''''''''''''''''''''''''''
'获得大类
dim id,first,classid
if not isempty(request("id")) then 
	id=request("id")
else 
	response.Write("没有记录")
	response.End()
end if
set rs=server.createobject("adodb.recordset")
	sql="select adType,photo,linkUrl,imgW,imgH,catalogId,content,title,moditime from ad where id="&id&" order by id desc "
	rs.open sql,conn,3,1
	if rs.eof or rs.bof then
		response.Write("没有找到记录")
		response.End()
	else
		adArr=rs.GetRows()
	end if
	rs.close
	set rs=nothing
dim i
classid=Cint(request("classid"))
set rs=server.CreateObject("adodb.recordset")
sql="select * from catalogs where parentid="&classid&" order by id asc"
rs.open sql,conn,3,1
if not rs.eof then
	first=rs.GetRows()
	if(ubound(first,2)<0) then
	response.Write("暂时没有分类")
	end if
else
	response.Write("暂时没有分类,请先添加分类!")
	response.End()
end if
rs.close
set rs=nothing
Function getcatalogs(parentid,str)
	Dim Sql,rstemp,TemptempStr,tempStr	
	tempStr=str&"&nbsp;"
	sql="select * from catalogs where parentid="&parentid
	Set rstemp = Conn.Execute(Sql)
	do while Not rstemp.Eof
		if(adArr(5,0)=rstemp("id")) then
			seleStr=" selected"
		else
			seleStr=""
		end if
		getcatalogs = getcatalogs &"<option value="&rstemp("id")&seleStr&">│"&tempStr&"└"&rstemp("title")&"</option>"&Chr(10)
		getcatalogs = getcatalogs & getcatalogs(rstemp("id"),tempStr)
		rstemp.MoveNext
	loop
	rstemp.close
	Set rstemp = Nothing
End Function
%>
<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
act=request.QueryString("act")
if(act="mod") then
	catalogid=cint(request.Form("catalogid"))	
	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
	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	
		linkUrl=trim(Request.Form("linkUrl"))
		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 id="&id&" order by id desc "
	rs.open sql,conn,3,3	
	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("moditime")=now
	rs.update
	rs.close
	set rs=nothing
	''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
	response.Write("成功修改广告~!")
	response.Write("<br><a href=""#"" onClick=""javascript:history.go(-2);"">继续修改-></a>&nbsp;&nbsp;<a href=""ad_add.asp"">添加新广告-></a>")
else	
%>
<FORM method="POST" name="form1" action="ad_mod.asp?act=mod" 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" >
  <option value="0">所有</option>
  	<%
	dim seleStr
  	for i=0 to ubound(first,2)
		if(adArr(5,0)=first(0,i)) then
			seleStr=" selected"
		else
			seleStr=""
		end if
		response.Write("<option value="&first(0,i)&seleStr&">├"&first(2,i)&"</option>"&Chr(10))	
    	response.Write(getcatalogs(first(0,i),""))		
	next	
	%>
        
    </select></TD>
</TR>
<TR bgcolor="#F5F5F5">
  <TD><div align="center">标题名称：</div></TD>
  <TD><input name="title" type="text" id="title" size="60" value="<%=adArr(7,0)%>"></TD>
</TR>
<TR bgcolor="#F5F5F5">
  <TD><div align="center">广告类型：</div></TD>
  <TD><input name="adType" type="radio" onClick="chanText()" value="0" <%if(adArr(0,0)=0) then response.Write("checked")%>>
    文字
      <input name="adType" type="radio" value="1" onClick="chanImg()" <%if(adArr(0,0)=1) then response.Write("checked")%>>
图片
<input name="adType" type="radio" value="2" onClick="chanFlash()" <%if(adArr(0,0)=2) then response.Write("checked")%>> 
Flash</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" readonly="true" value="<%=adArr(1,0)%>">
    <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" value="<%=adArr(3,0)%>">
  </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" value="<%=adArr(4,0)%>">
  </div>
</TR>
<TR bgcolor="#F5F5F5" id="objLink">
  <TD><div align="center">图片链接：</div></TD>
  <TD><div align="left">
    <input name="linkUrl" type="text" id="linkUrl" size="60" value="<%=adArr(2,0)%>">
  </div>
</TR>
<TR bgcolor="#F5F5F5" style="display:none; " id="textContent">
	<TD><div align="center">广告内容：</div></TD>
	<TD>		
		<textarea rows="12" name="content" cols="70"><%=adArr(6,0)%></textarea>		
</TR>
<TR bgcolor="#F5F5F5">
	<TD align=right>&nbsp;	  </TD>
    <TD align=right><div align="left">
	<input type="hidden" name="id" value="<%=id%>">
        <input type=submit name=b1 value="提 交">&nbsp;&nbsp;
        <input type=reset name=b2 value="重 填">       
    </div></TD>
</TR>
</TABLE>
</FORM>
<%
	dim chanStr
	if(adArr(0,0)=0) then 
		chanStr="chanText();"
	elseif(adArr(0,0)=1) then 
		chanStr="chanImg();"
	elseif(adArr(0,0)=2) then 
		chanStr="chanFlash();"
	end if
end if
%>
<script>
function chanText()
{
	document.getElementById("objUrl").style.display='none';
	document.getElementById("objWidth").style.display='none';
	document.getElementById("objHeight").style.display='none';
	document.getElementById("objLink").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("objLink").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("objLink").style.display='none';
	document.getElementById("textContent").style.display='none';
}
<%=chanStr%>
</script>
<iframe src="ad_getjs.asp?id=<%=id%>" width="0" height="0"></iframe>
</BODY>
</HTML>
<%
call connclose()
%>