HVAC-Talk
 
<% Dim strScriptFilename, intCountSubsc strScriptFilename = Request.ServerVariables("SCRIPT_NAME") %>
<% if Request.Form("action") = "unsubscribe" then if Trim(Request.Form("email")) <> "" then intCountSubsc = Unsubscribe(Trim(Request.Form("email"))) if intCountSubsc > 0 then Response.Write "" & Request.Form("email") & " has been successfully removed from the newsletter mailing list.

Click here to go back to HVAC-Talk" elseif intCountSubsc = 0 then Response.Write "" & Request.Form("email") & " has already been removed or was not found in the newsletter mailing list.

Click here to go back to HVAC-Talk" elseif intCountSubsc = -1 then response.write "We were unable to unsubscribe you as this time. Please try again later." elseif intCountSubsc = -2 then response.write "We were unable to unsubscribe you. Please check your email address and try again." end if else Response.Redirect(strScriptFilename) end if end if %> <%if Request.Form("action") = "" then%> Read the Current Newsletter. <%end if%>
<% objConn.Close Set objConn = nothing %> <% ' ====================================================================== Function Unsubscribe(strEmail) ' Check Strings and prevent injection Dim arrVarNames, i arrVarNames = Array("strEmail") for i = 0 to ubound(arrVarNames) Execute(arrVarNames(i) & " = " & "replace(" & arrVarNames(i) & ",""'"",""''"")") Execute(arrVarNames(i) & " = " & "replace(" & arrVarNames(i) & ",vbCrLf,"""")") Execute(arrVarNames(i) & " = " & "Trim(" & arrVarNames(i) & ")") next ' WhatCounts Integration 'Create object Set objXML = CreateObject("MSXML2.ServerXMLHTTP") Dim url, info, intResult intResult = -1 info = "c=unsub&p=puserell57&r=hvac&format=2&list_id=3085&optout=0&data=email^" & strEmail url = "http://penton.whatcounts.com/bin/api_web" 'Load the url objXML.open "POST", url, False objXML.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" objXML.send info wcSource = objXML.responseText wcStatus = objXML.status ' clean up Set objXML = Nothing ' good subscription, so add to the database if wcStatus = "200" and left(wcSource,7) = "SUCCESS" then Dim objCommand, objRS Set objCommand = Server.CreateObject("ADODB.Command") objCommand.ActiveConnection = objConn objCommand.CommandText = "SET NOCOUNT ON; " &_ "DECLARE @COUNTSUBSCRIPTION INT; " &_ "SELECT @COUNTSUBSCRIPTION = COUNT(SUBSCRIPTION_ID) FROM NEWSLETTER_EMAIL_SUBSCRIPTION " &_ "WHERE SITE_ID = 1006 AND NEWSLETTER_ID = 100 AND VALID = 1 AND EMAIL = '" & strEmail & "'; " &_ "UPDATE NEWSLETTER_EMAIL_SUBSCRIPTION " &_ "SET VALID = 0, UNSUBSCRIBEDATE = CURRENT_TIMESTAMP, UPDATEDDATE = CURRENT_TIMESTAMP " &_ "WHERE SITE_ID = 1006 AND NEWSLETTER_ID = 100 AND VALID = 1 AND EMAIL = '" & strEmail & "'; " &_ "SELECT @COUNTSUBSCRIPTION AS SUBSCRIPTIONCOUNT" objCommand.CommandType = adCmdText Set objRS = objCommand.Execute Set objCommand = Nothing intResult = objRS("SUBSCRIPTIONCOUNT") objRS.Close Set objRS = Nothing ' bad connection elseif wcStatus <> "200" then intResult = "-1" ' some type of failure else intResult = "-2" end if Unsubscribe = intResult End Function ' ====================================================================== %>