<% Option Explicit %>
<!--#include file="../config.asp"-->
<!--#include file="../common.asp"-->
<!--#include file="main.asp"-->
<%
	Dim rs, CID, SiteTitle, SiteURL, VisitsLeft, Approved, EGold, BatchNumber


	Command = Request.Form("Command")
	CID		= Str2Num(Request("CID"))

	OpenConnection

	If Command = "Save" Then
		Set rs = DBC.Execute("SELECT * FROM Campaigns WHERE CID = " & CID)

		If rs.EOF Then
			DBC.Execute("INSERT INTO Campaigns (SiteTitle, SiteURL, VisitsLeft, EGold, BatchNumber, Approved) " & _
				"VALUES (" &	EscapeSQLData(Request.Form("SiteTitle"))	& ", " & _
						EscapeSQLData(Request.Form("SiteURL"))	& ", " & _
						Request.Form("VisitsLeft")			& ", " & _
						Str2Num(Request.Form("EGold"))		& ", " & _
						Str2Num(Request.Form("BatchNumber"))	& ", " & _
						Str2Num(Request.Form("Approved"))		& ")")
		Else
			DBC.Execute("UPDATE Campaigns SET " & _
				"SiteTitle		= " & EscapeSQLData(Request.Form("SiteTitle"))	& ", " & _
				"SiteURL		= " & EscapeSQLData(Request.Form("SiteURL"))	& ", " & _
				"VisitsLeft		= " & Request.Form("VisitsLeft")		& ", " & _
				"EGold		= " & Str2Num(Request.Form("EGold"))		& ", " & _
				"BatchNumber	= " & Request.Form("BatchNumber")		& ",  " & _
				"Approved	= " & Str2Num(Request.Form("Approved"))			& "  " & _
				"WHERE CID = " & CID)
		End If

		Response.Redirect "link_list.asp"
	End If



	PageHeader

	If Not Session("IsAdminLogin") Then
		PageLogin
		Response.End
	End If

	AdminPageBegin "Add Link"
	Edit
	AdminPageEnd


	Sub Edit()
		Set rs = DBC.Execute("SELECT * FROM Campaigns WHERE CID = " & CID)

		If rs.EOF Then
			SiteTitle		= ""
			SiteURL		= ""
			VisitsLeft		= 0
			Approved		= 0
			EGold		= 0
			BatchNumber	= 0
		Else
			SiteTitle		= rs("SiteTitle")
			SiteURL		= rs("SiteURL")
			VisitsLeft		= rs("VisitsLeft")
			Approved		= rs("Approved")
			EGold		= rs("EGold")
			BatchNumber	= rs("BatchNumber")
		End If
%>
		<script language=JavaScript>
		<!--
		function Validate()
		{
			if (document.F.SiteTitle.value.length == 0)
			{
				alert("Please enter link's title.");
				document.F.SiteTitle.focus();
				return false;
			}

			if (document.F.SiteURL.value.length == 0)
			{
				alert("Please enter link's url.");
				document.F.SiteURL.focus();
				return false;
			}

			return true;
		}
		//-->
		</script>

		<form name=F action="link_edit.asp" method=post onsubmit="return Validate()">
		<input type=hidden name=CID value="<%= CID %>">
		<table border=0 align=center bgcolor=black cellspacing=1 cellpadding=3>
		<tr>
			<td colspan=2 class=SelectedParent align=center>
				Link information
			</td>
		</tr>
		<tr class=Odd>
			<td>Site's Title</td>
			<td>
				<input name=SiteTitle value="<%= SiteTitle %>" size=50 maxlength=50 class=ClientText>
			</td>
		</tr>
		<tr class=Odd>
			<td>Site's URL</td>
			<td>
				<input name=SiteURL value="<%= SiteURL %>" size=50 maxlength=120 class=ClientText>
			</td>
		</tr>
		<tr class=Odd>
			<td>Visits Left</td>
			<td>
				<input name=VisitsLeft value="<%= VisitsLeft %>" size=15 maxlength=6 class=ClientText>
			</td>
		</tr>
		<tr class=Odd>
			<td>Advertiser's e-gold</td>
			<td>
				<input name=EGold value="<%= EGold %>" size=15 maxlength=7 class=ClientText>
			</td>
		</tr>
		<tr class=Odd>
			<td>Batch Number</td>
			<td>
				<input name=BatchNumber value="<%= BatchNumber %>" size=15 maxlength=12 class=ClientText>
			</td>
		</tr>
		<tr class=Odd>
			<td>Approved</td>
			<td>
				<input type=checkbox name=Approved value=1 <%= IIf(Approved, "checked", "") %> class=ClientText>
			</td>
		</tr>
		<tr>
			<td colspan=2 bgcolor=white align=center>
				<input type=submit name=Command value=Save style="width:200">
			</td>
		</tr>
		</table>
		</form>
<%
	End Sub
%>