File: D:/web/homefly/vsadmin/inc/incaffil.asp
<%
'This code is copyright (c) Internet Business Solutions SL, all rights reserved.
'The contents of this file are protect under law as the intellectual property
'of Internet Business Solutions SL. Any use, reproduction, disclosure or copying
'of any kind without the express and written permission of Internet Business
'Solutions SL is forbidden.
'Author: Vince Reid, vince@virtualred.net
if Session("loggedon") <> "virtualstore" then response.end
Dim sSQL,rs,cnn,success,showaccount,addsuccess,useEuro,alldata,index,netnav,allcountries,rowcounter,sd,ed,errmsg
Dim affilName,affilPW,affilAddress,affilCity,affilState,affilZip,affilCountry,affilEmail,affilInform,smonth,saveLCID
addsuccess = true
success = true
showaccount = true
function atb(size)
if netnav then
atb = CInt(size / 2 + 1)
else
atb = size
end if
end function
Set rs = Server.CreateObject("ADODB.RecordSet")
Set cnn=Server.CreateObject("ADODB.Connection")
cnn.open sDSN
sSQL = "SELECT countryLCID, countryCurrency, adminDelUncompleted FROM admin INNER JOIN countries ON admin.adminCountry=countries.countryID WHERE adminID=1"
rs.Open sSQL,cnn,0,1
if Int(rs("countryLCID"))<>0 then Session.LCID = Int(rs("countryLCID"))
useEuro=(rs("countryCurrency")="EUR")
rs.Close
saveLCID = session.LCID
if request.form("editaction")="modify" then
sSQL = "UPDATE affiliates SET affilPW='"&replace(trim(request.form("affilPW")),"'","''") & "'," & _
"affilEmail='"&replace(trim(request.form("Email")),"'","''") & "'," & _
"affilName='"&replace(trim(request.form("Name")),"'","''") & "'," & _
"affilAddress='"&replace(trim(request.form("Address")),"'","''") & "'," & _
"affilCity='"&replace(trim(request.form("City")),"'","''") & "'," & _
"affilState='"&replace(trim(request.form("State")),"'","''") & "'," & _
"affilCountry='"&replace(trim(request.form("Country")),"'","''") & "'," & _
"affilZip='"&replace(trim(request.form("Zip")),"'","''") & "',"
if trim(request.form("Inform"))="ON" then
sSQL = sSQL & "affilInform=1 "
else
sSQL = sSQL & "affilInform=0 "
end if
sSQL = sSQL & "WHERE affilID='" & replace(trim(request.form("affilID")),"'","''") & "'"
cnn.Execute(sSQL)
elseif request.form("editaction")="delete" then
sSQL = "DELETE FROM affiliates WHERE affilID='" & replace(trim(request.form("affilID")),"'","''") & "'"
cnn.Execute(sSQL)
end if
if Trim(request.querystring("id"))<>"" then
sSQL = "SELECT affilName,affilPW,affilAddress,affilCity,affilState,affilZip,affilCountry,affilEmail,affilInform FROM affiliates WHERE affilID='"&Trim(request.querystring("id"))&"'"
rs.Open sSQL,cnn,0,1
if NOT rs.EOF then
affilName = rs("affilName")
affilPW = rs("affilPW")
affilAddress = rs("affilAddress")
affilCity = rs("affilCity")
affilState = rs("affilState")
affilZip = rs("affilZip")
affilCountry = rs("affilCountry")
affilEmail = rs("affilEmail")
affilInform = Int(rs("affilInform"))=1
end if
rs.Close
%>
<script Language="JavaScript">
<!--
function checkform(frm)
{
if(frm.affilid.value=="")
{
alert("Please enter a value in the field \"Affiliate ID\".");
frm.affilid.focus();
return (false);
}
var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var checkStr = frm.affilid.value;
var allValid = true;
for (i = 0; i < checkStr.length; i++)
{
ch = checkStr.charAt(i);
for (j = 0; j < checkOK.length; j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
}
if (!allValid)
{
alert("Please enter only alphanumeric characters with no spaces in the \"Affiliate ID\" field.");
frm.affilid.focus();
return (false);
}
if(frm.affilpw.value=="")
{
alert("Please enter a value in the field \"Password\".");
frm.affilpw.focus();
return (false);
}
if(frm.name.value=="")
{
alert("Please enter a value in the field \"Name\".");
frm.name.focus();
return (false);
}
if(frm.email.value=="")
{
alert("Please enter a value in the field \"Email\".");
frm.email.focus();
return (false);
}
if(frm.address.value=="")
{
alert("Please enter a value in the field \"Address\".");
frm.address.focus();
return (false);
}
if(frm.city.value=="")
{
alert("Please enter a value in the field \"City\".");
frm.city.focus();
return (false);
}
if(frm.state.value=="")
{
alert("Please enter a value in the field \"State\".");
frm.state.focus();
return (false);
}
if(frm.zip.value=="")
{
alert("Please enter a value in the field \"Zip\".");
frm.zip.focus();
return (false);
}
return (true);
}
//-->
</script>
<table border="0" cellspacing="0" cellpadding="0" width="100%" bgcolor="" align="center">
<tr>
<td width="100%">
<form method="POST" action="adminaffil.asp" onSubmit="return checkform(this)">
<table width="100%" border="0" cellspacing="0" cellpadding="3" bgcolor="">
<tr>
<td width="100%" align="center" colspan="4"><b>Affiliate Details Admin.</b></td>
</tr>
<% if NOT addsuccess then %>
<tr>
<td width="100%" align="center" colspan="4"><b><font color='#FF0000'>I'm sorry, that affiliate ID is already in use. Please choose another.</font></b></td>
</tr>
<% end if %>
<tr>
<td width="25%" align="right"><b><font color='#FF0000'>*</font>Affiliate ID:</b></td>
<td width="25%" align="left"><%=Trim(request.querystring("id"))%>
<input type="hidden" name="affilid" size="<%=atb(20)%>" value="<%=Trim(request.querystring("id"))%>">
<input type="hidden" name="editaction" value="modify"></td>
<td width="25%" align="right"><b><font color='#FF0000'>*</font>Password:</b></td>
<td width="25%" align="left"><input type="text" name="affilpw" size="<%=atb(20)%>" value="<%=affilPW%>"></td>
</tr>
<tr>
<td width="25%" align="right"><b><font color='#FF0000'>*</font>Name:</b></td>
<td width="25%" align="left"><input type="text" name="name" size="<%=atb(20)%>" value="<%=affilName%>"></td>
<td width="25%" align="right"><b><font color='#FF0000'>*</font>Email:</b></td>
<td width="25%" align="left"><input type="text" name="email" size="<%=atb(25)%>" value="<%=affilEmail%>"></td>
</tr>
<tr>
<td width="25%" align="right"><b><font color='#FF0000'>*</font>Address:</b></td>
<td width="25%" align="left"><input type="text" name="address" size="<%=atb(20)%>" value="<%=affilAddress%>"></td>
<td width="25%" align="right"><b><font color='#FF0000'>*</font>City:</b></td>
<td width="25%" align="left"><input type="text" name="city" size="<%=atb(20)%>" value="<%=affilCity%>"></td>
</tr>
<tr>
<td width="25%" align="right"><b><font color='#FF0000'>*</font>State:</b></td>
<td width="25%" align="left"><input type="text" name="state" size="<%=atb(20)%>" value="<%=affilState%>"></td>
<td width="25%" align="right"><b><font color='#FF0000'>*</font>Country:</b></td>
<td width="25%" align="left"><select name="country" size="1">
<%
Sub show_countries(tcountry)
if NOT IsArray(allcountries) then
sSQL = "SELECT countryName FROM countries ORDER BY countryOrder DESC, countryName"
rs.Open sSQL,cnn,0,1
allcountries=rs.getrows
rs.Close
end if
for rowcounter=0 to UBOUND(allcountries,2)
response.write "<option value='"&allcountries(0,rowcounter)&"'"
if tcountry=allcountries(0,rowcounter) then
response.write " selected"
end if
response.write ">"&allcountries(0,rowcounter)&"</option>"&vbCrLf
next
End Sub
show_countries(affilCountry)
%>
</select>
</td>
</tr>
<tr>
<td width="25%" align="right"><b><font color='#FF0000'>*</font>Zip:</b></td>
<td width="25%" align="left"><input type="text" name="zip" size="<%=atb(10)%>" value="<%=affilZip%>"></td>
<td width="25%" align="right"><b>Inform me:</b></td>
<td width="25%" align="left"><input type="checkbox" name="inform" value="ON" <% if affilInform then response.write "checked"%>></td>
</tr>
<tr>
<td width="100%" colspan="4">
<font size="1"><ul><li>Please note. By checking the "inform me" option, the affiliate will receive an email notification every time their affiliate link generates a sale.</li></ul></font>
</td>
</tr>
<tr>
<td width="50%" align="center" colspan="4"><input type="submit" value="Submit"> <input type="reset" value="Reset"> </td>
</tr>
</table>
</form>
</td>
</tr>
</table>
<%
else
session.LCID = 1033
if Request("sd") = "" then
sd=DateSerial(DatePart("yyyy",Date()),DatePart("m",Date()),1)
else
sd=Request("sd")
end if
if Request("ed") = "" then
ed=Date()
else
ed=Request("ed")
end if
on error resume next
sd = DateValue(sd)
ed = Datevalue(ed)
if err.number <> 0 then
sd = DateSerial(DatePart("yyyy",Date()),DatePart("m",Date()),1)
ed = Date()
success=false
errmsg="One of your date values was invalid."
end if
on error goto 0
tdt = DateValue(sd)
tdt2 = DateValue(ed)+1
sSQL = "SELECT affilID, affilName, affilPW, affilEmail, (SELECT Sum(ordTotal) FROM orders WHERE ordAffiliate=affilID AND ordDate BETWEEN "&datedelim&DatePart("m",tdt) & "/" & DatePart("d",tdt) & "/" & DatePart("yyyy",tdt)&datedelim&" AND "&datedelim&DatePart("m",tdt2) & "/" & DatePart("d",tdt2) & "/" & DatePart("yyyy",tdt2)&datedelim&") FROM affiliates ORDER BY affilID"
rs.Open sSQL,cnn,0,1
if NOT rs.EOF then alldata=rs.GetRows()
rs.Close
session.LCID = saveLCID
%>
<script language="JavaScript">
<!--
function delrec(id) {
cmsg = "Sure you want to delete this record?\n"
if (confirm(cmsg)) {
document.mainform.affilID.value = id;
document.mainform.editaction.value = "delete";
document.mainform.submit();
}
}
// -->
</script>
<table border="0" cellspacing="0" cellpadding="0" width="100%" bgcolor="" align="center">
<tr>
<td width="100%">
<table width="100%" border="0" cellspacing="0" cellpadding="3" bgcolor="">
<tr>
<td width="100%" align="center" colspan="5"><b>Affiliate Partners Program Admin.</b><br> </td>
</tr>
<form method="POST" action="adminaffil.asp">
<tr>
<td width="100%" colspan="5" align="center"><% if NOT success then response.write "<p><font color='#FF0000'>"&errmsg&"</font></p>" %><br><b>Affiliate sales between:</b> <input type="text" size="<%=atb(9)%>" name="sd" value="<%=sd%>"> <b>and:</b> <input type="text" size="<%=atb(9)%>" name="ed" value="<%=ed%>"> <input type="submit" value="Go"><br> </td>
</tr>
</form>
<form method="POST" action="adminaffil.asp">
<tr>
<td width="100%" colspan="5" align="center"><p><b>Show Affiliate Sales From:</b> <select name="sd" size="1"><%
For rowcounter=0 to Day(Date())-1
response.write "<option value='"&Date()-rowcounter&"'"
if Date()-rowcounter=sd then response.write " selected"
response.write ">"&Date()-rowcounter&"</option>"&vbCrLf
smonth=Date()-rowcounter
Next
For rowcounter=1 to 4
response.write "<option value='"&DateAdd("m",0-rowcounter,smonth)&"'"
if DateAdd("m",0-rowcounter,smonth)=sd then response.write " selected"
response.write ">"&DateAdd("m",0-rowcounter,smonth)&"</option>"&vbCrLf
Next
%></select> <b>To:</b> <select name="ed" size="1"><%
For rowcounter=0 to Day(Date())-1
response.write "<option value='"&Date()-rowcounter&"'"
if Date()-rowcounter=ed then response.write " selected"
response.write ">"&Date()-rowcounter&"</option>"&vbCrLf
smonth=Date()-rowcounter
Next
For rowcounter=1 to 4
response.write "<option value='"&DateAdd("m",0-rowcounter,smonth)&"'"
if DateAdd("m",0-rowcounter,smonth)=ed then response.write " selected"
response.write ">"&DateAdd("m",0-rowcounter,smonth)&"</option>"&vbCrLf
Next
%></select> <input type="submit" value="Go"><br> </p></td>
</tr>
</form>
<form name="mainform" method="POST" action="adminaffil.asp">
<tr>
<td><b>ID</b></td>
<td><b>Name</b></td>
<td><b>Email</b></td>
<td align="right"><b>Total Sales</b></td>
<td align="center"><b>Delete</b></td>
</tr>
<input type="hidden" name="affilID" value="xxx">
<input type="hidden" name="editaction" value="xxx">
<%
if NOT IsArray(alldata) then
%>
<tr>
<td width="100%" align="center" colspan="5"><br> <br><b>No affiliates registered.</b><br> </td>
</tr>
<%
else
for index=0 to UBOUND(alldata,2) %>
<tr>
<td><a href="adminaffil.asp?id=<%=alldata(0,index)%>"><b><%=alldata(0,index)%></b></a></td>
<td><%=alldata(1,index)%></td>
<td><a href="mailto:<%=alldata(3,index)%>">Email Affiliate</a></td>
<td align=right><%if NOT IsNumeric(alldata(4,index)) then response.write "-" else response.write FormatEuroCurrency(alldata(4,index))%></td>
<td align="center"><input type=button name=delete value="Delete" onClick="delrec('<%=replace(alldata(0,index),"'","\'")%>')"></td>
</tr>
<%
next
end if
%>
</form>
</table>
</td>
</tr>
</table>
<%
end if
%>