<!--#include file="../../Conn.asp" -->
<!--#include file="../../Comm/Site_Class.asp" -->
<%
PagePath = "../../"

Set Qsite = New Site_Class

Qsite.SiteConfig_Master()
%>
<!--#include file="../Check_Login.asp" -->
<%
Qsite.Check_AdminFlag(arrAdminFlag(5 , 2))

Dim Rs,i,j,arrRs
Dim ThisYear,selYear,selMonth,selDay
Dim AdId,Keyword,AdTypeId,Page
Dim AdType,AdName,ComName,Contact,AdUrl,AdPicUrl,AdPause,AdWz,AdNote
Dim ValidityDate,ValidityYear,ValidityMonth,ValidityDay,AddDate
Dim strDate,strYear,strMonth,strDay

Set Rs = server.createobject("ADODB.Recordset")

If Request.Form <> "" Then
	AdId = Qsite.chgStr(Trim(Request.Form("AdId")))
	Keyword = Qsite.chgStr(Trim(Request.Form("Keyword")))
	AdTypeId = Qsite.chgStr(Trim(Request.Form("AdTypeId")))
	Page = Qsite.chgStr(Trim(Request.Form("Page")))
	
	AdType = Qsite.chgStr(Trim(Request.Form("AdType")))
	AdName = Qsite.chgStr(Trim(Request.Form("AdName")))
	ComName = Qsite.chgStr(Trim(Request.Form("ComName")))
	Contact = Qsite.chgStr(Trim(Request.Form("Contact")))
	AdUrl = Qsite.chgStr(Trim(Request.Form("AdUrl")))
	AdPicUrl = Qsite.chgStr(Trim(Request.Form("AdPicUrl")))
	ValidityYear = Qsite.chgStr(Trim(Request.Form("ValidityYear")))
	ValidityMonth = Qsite.chgStr(Trim(Request.Form("ValidityMonth")))
	ValidityDay = Qsite.chgStr(Trim(Request.Form("ValidityDay")))
	AdPause = Qsite.chgStr(Trim(Request.Form("AdPause")))
	AdWz = Qsite.chgStr(Trim(Request.Form("AdWz")))
	AdNote = Qsite.chgStr(Trim(Request.Form("AdNote")))
	
	If AdId = "" Or IsNull(AdId) Or Not IsNumeric(AdId) Then AdId = 0
	If Page = "" Or IsNull(Page) Or Not IsNumeric(Page) Then Page = 1
	
	If AdType = "" Or IsNull(AdType) Then
		Qsite.ShowMsg "请选择广告类型" , ""
	End If
	If AdName = "" Or IsNull(AdName) Then
		Qsite.ShowMsg "请输入广告名称" , ""
	End If
	If ComName = "" Or IsNull(ComName) Then
		Qsite.ShowMsg "请输入客户名称" , ""
	End If
	If Contact = "" Or IsNull(Contact) Then
		Qsite.ShowMsg "请输入联系方式" , ""
	End If
	If AdPicUrl = "" Or IsNull(AdPicUrl) Or AdPicUrl = "Ad_Img/" Then
		Qsite.ShowMsg "请输入图片/Flash地址，或上传图片/Flash" , ""
	End If
	
	strDate = Date()
	strYear = Year(strDate)
	strMonth = Month(strDate)
	strDay = Day(strDate)
	If ValidityYear < strYear Then
		Qsite.ShowMsg "截止日期不能是过去时间" , ""
	End If
	If ValidityYear = strYear And ValidityMonth < strMonth Then
		Qsite.ShowMsg "截止日期不能是过去时间" , ""
	End If
	If ValidityYear = strYear And ValidityMonth = strMonth And ValidityDay < strDay Then
		Qsite.ShowMsg "截止日期不能是过去时间" , ""
	End If
	ValidityDate = ValidityYear & "-" & ValidityMonth & "-" & ValidityDay
	If Not IsDate(ValidityDate) Then
		Qsite.ShowMsg "请选择正确的时间" , ""
	End If
	
	If AdPause <> "1" Then AdPause = "0"
	If AdWz = "" Or IsNull(AdWz) Then	
		Qsite.ShowMsg "请选择广告投放位置" , ""
	End If
	AdWz = Replace(AdWz , " " , "")
	If InStr(AdWz , ",") > 0 Then
		AdWz = "|" & Replace(AdWz , "," , "|") & "|"
	Else
		AdWz = "|" & AdWz & "|"
	End If
	
	Conn.Execute("update AdTbl set AdType = '"& AdType &"' , AdName = '"& AdName &"' , ComName = '"& ComName &"' , Contact = '"& Contact &"' , AdUrl = '"& AdUrl &"' , AdPicUrl = '"& AdPicUrl &"' , ValidityDate = '"& ValidityDate &"' , AdPause = '"& AdPause &"' , AdWz = '"& AdWz &"' , AdNote = '"& AdNote &"' where AdId = "& AdId)
	
	Qsite.ShowMsg "广告修改成功" , "Ad_List.asp?Keyword="& Keyword &"&AdTypeId="& AdTypeId &"&page="& Page
	
End If

AdId = Qsite.chgStr(Trim(Request.QueryString("AdId")))
Keyword = Qsite.chgStr(Trim(Request.QueryString("Keyword")))
AdTypeId = Qsite.chgStr(Trim(Request.QueryString("AdTypeId")))
Page = Qsite.chgStr(Trim(Request.QueryString("Page")))

If AdId = "" Or IsNull(AdId) Or Not IsNumeric(AdId) Then AdId = 0
If Page = "" Or IsNull(Page) Or Not IsNumeric(Page) Then Page = 1

Rs.Open "select * from AdTbl where AdId = "& AdId , Conn , 1 , 1
If Rs.Eof Then
	AdType = ""
	AdName = ""
	ComName = ""
	Contact = ""
	AdUrl = ""
	AdPicUrl = ""
	ValidityDate = ""
	AdPause = ""
	AdWz = ""
	AdNote = ""
	AddDate = ""
Else
	AdType = Rs("AdType")
	AdName = Rs("AdName")
	ComName = Rs("ComName")
	Contact = Rs("Contact")
	AdUrl = Rs("AdUrl")
	AdPicUrl = Rs("AdPicUrl")
	ValidityDate = Rs("ValidityDate")
	AdPause = Rs("AdPause")
	AdWz = Rs("AdWz")
	AdNote = Rs("AdNote")
	AddDate = Rs("AddDate")
End If
Rs.Close


If IsDate(ValidityDate) Then
	SelYear = Year(ValidityDate)
	selMonth = Month(ValidityDate)
	selDay = Day(ValidityDate)
End If

ThisYear = Year(Date())

Rs.Open "select * from AdTypeTbl order by AdTypeId asc" , Conn , 1 , 1
If Not Rs.Eof Then
	arrRs = Rs.GetRows(-1)
End If
Rs.Close
Set Rs = Nothing

If Not IsArray(arrRs) Then
	ReDim arrRs(5 , 17)
	For i = 0 To 17
		arrRs(0 , i) = i
		For j = 1 To 5
			arrRs(j , i) = 0
		Next
	Next
End If
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>广告管理</title>
<link href="../skins/css/main.css" rel="stylesheet" type="text/css">
<script language="javascript">
function CheckForm()
{
	if(PosForm.AdType[0].checked == false && PosForm.AdType[1].checked == false)
	{
		alert("请选择广告类型");
		return false;
	}
	if(PosForm.AdName.value == "")
	{
		alert("请输入广告名称");
		PosForm.AdName.focus();
		return false;
	}
	if(PosForm.ComName.value == "")
	{
		alert("请输入客户名称");
		PosForm.ComName.focus();
		return false;
	}
	if(PosForm.Contact.value == "")
	{
		alert("请输入联系方式");
		PosForm.Contact.focus();
		return false;
	}
	if(PosForm.AdPicUrl.value == "")
	{
		alert("请输入图片/Flash地址，或上传图片/Flash");
		PosForm.AdPicUrl.focus();
		return false;
	}
	var adwz = document.getElementsByName("AdWz");
	var adwzsel = false;
	for(var i = 0; i < adwz.length; i++)
	{
		if(adwz[i].checked == true)
		{
			adwzsel = true;
			break;
		}
	}
	if(!adwzsel)
	{
		alert("请选择广告投放的位置");
		return false;
	}
	return true;
}

function UploadAdPic()
{
	window.open('Upload_AdPic.asp','Upload','width=380px,height=90px,left=300,top=300');
} 
</script>
</head>

<body>
<form name="PosForm" method="post" action="Ad_Edit.asp" style="margin:0" onSubmit="return CheckForm();">
	<table width="100%" border="0" cellspacing="1" cellpadding="5">
		<tr>
			<td height="25" colspan="2" class="td_title">广告修改</td>
		</tr>
		<tr>
			<td width="18%" height="23" class="td_content">广告类型：</td>
			<td width="82%" height="23" class="td_content"><input name="AdType" type="radio" value="0" <%If AdType = "0" Then Response.Write("checked")%>>
				图片 
				<input type="radio" name="AdType" value="1" <%If AdType = "1" Then Response.Write("checked")%>>
				Flash
				<input name="AdId" type="hidden" id="AdId" value="<%=AdId%>">
				<input name="Keyword" type="hidden" id="Keyword" value="<%=Keyword%>">
				<input name="AdTypeId" type="hidden" id="AdTypeId" value="<%=AdTypeId%>">
				<input name="Page" type="hidden" id="Page" value="<%=Page%>"></td>
		</tr>
		<tr>
			<td height="23" class="td_content">广告名称：</td>
			<td height="23" class="td_content"><input name="AdName" type="text" class="input_1" id="AdName" size="60" value="<%=AdName%>"></td>
		</tr>
		<tr>
			<td height="23" class="td_content">客户名称：</td>
			<td height="23" class="td_content"><input name="ComName" type="text" class="input_1" id="ComName" value="<%=ComName%>" size="60"></td>
		</tr>
		<tr>
			<td height="23" class="td_content">联系方式：</td>
			<td height="23" class="td_content"><input name="Contact" type="text" class="input_1" id="Contact" value="<%=Contact%>" size="60"></td>
		</tr>
		<tr>
			<td height="23" class="td_content">链接地址：</td>
			<td height="23" class="td_content"><input name="AdUrl" type="text" class="input_1" id="AdUrl" value="<%=AdUrl%>" size="60">
			(没有链接请留空或保持默认值)</td>
		</tr>
		<tr>
			<td height="23" class="td_content">图片/Flash地址：</td>
			<td height="23" class="td_content"><input name="AdPicUrl" type="text" class="input_1" id="AdPicUrl" value="<%=AdPicUrl%>" size="60">
			<input name="Btn" type="button" class="input_1" id="Btn" value="上传图片/Flash" onClick="UploadAdPic();"></td>
		</tr>
		<tr>
			<td height="23" class="td_content">广告有效期：</td>
			<td height="23" class="td_content"><select name="ValidityYear" class="input_1" id="ValidityYear">
												<%
												For i = ThisYear To ThisYear + 10
													Response.Write("<option value="""& i &""" ")
													If Cint(i) = Cint(selYear) Then Response.Write(" selected")
													Response.Write(">"& i &"</option>")
												Next
												%>
											</select>
												年
												<select name="ValidityMonth" class="input_1" id="ValidityMonth">
													<%
													For i = 1 To 12
														Response.Write("<option value="""& i &""" ")
														If Cint(i) = Cint(selMonth) Then Response.Write(" selected")
														Response.Write(">"& i &"</option>")
													Next
													%>
												</select>
												月
												 <select name="ValidityDay" class="input_1" id="ValidityDay">
												 	<%
													For i = 1 To 31
														Response.Write("<option value="""& i &""" ")
														If Cint(i) = Cint(selDay) Then Response.Write(" selected")
														Response.Write(">"& i &"</option>")
													Next
													%>
												</select>
												 日</td>
		</tr>
		<tr>
			<td height="23" class="td_content">暂停广告展示：</td>
			<td height="23" class="td_content"><input name="AdPause" type="checkbox" id="AdPause" value="1" <%If AdPause = "1" Then Response.Write("checked")%>></td>
		</tr>
		<tr>
			<td height="23" class="td_content">广告位置：<br>
				(同一广告可以投放在多个页面相同规格的广告位上，如果规格不同，会出现图片变形的情况)</td>
			<td height="23" class="td_content" style="line-height:20px;">顶部：
				<input name="AdWz" type="checkbox" id="AdWz" value="<%=arrRs(0 , 0)%>" <%If InStr(AdWz , "|" & arrRs(0 , 0) & "|") > 0 Then Response.Write("checked")%>><%=arrRs(1 , 0)%>(<%=arrRs(3 , 0)%>)
				<input name="AdWz" type="checkbox" id="AdWz" value="<%=arrRs(0 , 2)%>" <%If InStr(AdWz , "|" & arrRs(0 , 2) & "|") > 0 Then Response.Write("checked")%>><%=arrRs(1 , 2)%>(<%=arrRs(3 , 2)%>)
				<br>
				首页：
				<input name="AdWz" type="checkbox" id="AdWz" value="<%=arrRs(0 , 3)%>" <%If InStr(AdWz , "|" & arrRs(0 , 3) & "|") > 0 Then Response.Write("checked")%>><%=arrRs(1 , 3)%>(<%=arrRs(3 , 3)%>)
				<input name="AdWz" type="checkbox" id="AdWz" value="<%=arrRs(0 , 4)%>" <%If InStr(AdWz , "|" & arrRs(0 , 4) & "|") > 0 Then Response.Write("checked")%>><%=arrRs(1 , 4)%>(<%=arrRs(3 , 4)%>)
				<input name="AdWz" type="checkbox" id="AdWz" value="<%=arrRs(0 , 6)%>" <%If InStr(AdWz , "|" & arrRs(0 , 6) & "|") > 0 Then Response.Write("checked")%>><%=arrRs(1 , 6)%>(<%=arrRs(3 , 6)%>)
				<br>
				招聘：
				<input name="AdWz" type="checkbox" id="AdWz" value="<%=arrRs(0 , 7)%>" <%If InStr(AdWz , "|" & arrRs(0 , 7) & "|") > 0 Then Response.Write("checked")%>><%=arrRs(1 , 7)%>(<%=arrRs(3 , 7)%>)
				<input name="AdWz" type="checkbox" id="AdWz" value="<%=arrRs(0 , 8)%>" <%If InStr(AdWz , "|" & arrRs(0 , 8) & "|") > 0 Then Response.Write("checked")%>><%=arrRs(1 , 8)%>(<%=arrRs(3 , 8)%>)
				<br>
				简历：
				<input name="AdWz" type="checkbox" id="AdWz" value="<%=arrRs(0 , 9)%>" <%If InStr(AdWz , "|" & arrRs(0 , 9) & "|") > 0 Then Response.Write("checked")%>><%=arrRs(1 , 9)%>(<%=arrRs(3 , 9)%>)
				<input name="AdWz" type="checkbox" id="AdWz" value="<%=arrRs(0 , 10)%>" <%If InStr(AdWz , "|" & arrRs(0 , 10) & "|") > 0 Then Response.Write("checked")%>><%=arrRs(1 , 10)%>(<%=arrRs(3 , 10)%>)
				</td>
		</tr>
		<tr>
			<td height="23" class="td_content">备注：</td>
			<td height="23" class="td_content"><textarea name="AdNote" cols="60" rows="8" class="input_1" id="AdNote"><%=AdNote%></textarea></td>
		</tr>
		<tr>
			<td height="23" class="td_content">&nbsp;</td>
			<td height="23" class="td_content"><input name="Submit" type="submit" class="input_1" value=" 修  改 "> &nbsp;
			<input name="Submit" type="reset" class="input_1" value=" 重  置 "> &nbsp;
			<input name="Submit" type="button" class="input_1" value=" 返  回 " onClick="javascript:history.back();"></td>
		</tr>
	</table>
</form>
</body>
</html>
