HVAC-Talk
 
<% Dim strScriptFilename, intCountSubsc strScriptFilename = Request.ServerVariables("SCRIPT_NAME") %>
<% if Request.Form("action") = "subscribe" then if Trim(Request.Form("email")) <> "" then intCountSubsc = Subscribe(Trim(Request.Form("email")), Trim(Request.Form("name"))) if intCountSubsc = "00" OR intCountSubsc = "11" then Response.Write "" & Request.Form("email") & " has been successfully subscribed to the newsletter.

Click here to go back to HVAC-Talk" elseif intCountSubsc = "10" then Response.Write "" & Request.Form("email") & " is already a subscriber to the newsletter.

Click here to go back to HVAC-Talk" elseif intCountSubsc = "-1" then response.write "We were unable to subscribe you as this time. Please try again later." elseif intCountSubsc = "-2" then response.write "We were unable to subscribe you. Please check your email address and try again." end if else Response.Redirect(strScriptFilename) end if end if %> <%if Request.Form("action") = "" then%> View Current Newsletters <%end if%>
<% objConn.Close Set objConn = nothing %> <% ' ====================================================================== Function Subscribe(strEmail, strName) ' 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=sub&p=puserell57&r=hvac&format=2&list_id=3085&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 @EMAIL VARCHAR(250), @NAME VARCHAR(250), @COUNTINVALID INT, @COUNTVALID INT " &_ "SET @EMAIL = '" & strEmail & "'; " &_ "SET @NAME = '" & strName & "'; " &_ "SELECT @COUNTINVALID = COUNT(SUBSCRIPTION_ID) FROM NEWSLETTER_EMAIL_SUBSCRIPTION " &_ "WHERE SITE_ID = 1006 AND NEWSLETTER_ID = 100 AND VALID = 0 AND EMAIL = @EMAIL " &_ "IF @COUNTINVALID > 0 " &_ "BEGIN " &_ "UPDATE NEWSLETTER_EMAIL_SUBSCRIPTION " &_ "SET VALID = 1, SUBSCRIBEDATE = CURRENT_TIMESTAMP, UPDATEDDATE = CURRENT_TIMESTAMP " &_ "WHERE SITE_ID = 1006 AND NEWSLETTER_ID = 100 AND VALID = 0 AND EMAIL = @EMAIL; " &_ "END " &_ "SELECT @COUNTVALID = COUNT(SUBSCRIPTION_ID) FROM NEWSLETTER_EMAIL_SUBSCRIPTION " &_ "WHERE SITE_ID = 1006 AND NEWSLETTER_ID = 100 AND VALID = 1 AND EMAIL = @EMAIL; " &_ "IF @COUNTINVALID = 0 AND @COUNTVALID = 0 " &_ "BEGIN " &_ "INSERT INTO NEWSLETTER_EMAIL_SUBSCRIPTION (SITE_ID, NEWSLETTER_ID, EMAIL, NAME, VALID, EMAIL_FORMAT, SUBSCRIBEDATE, DATESTART, CREATEDDATE) " &_ "VALUES ( 1006, 100, @EMAIL, @NAME, 1, 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); " &_ "END " &_ "SELECT @COUNTVALID AS COUNTVALID, @COUNTINVALID AS COUNTINVALID" objCommand.CommandType = adCmdText Set objRS = objCommand.Execute Set objCommand = Nothing intResult = objRS("COUNTVALID") & objRS("COUNTINVALID") objRS.Close Set objRS = Nothing ' bad connection elseif wcStatus <> "200" then intResult = "-1" ' some type of failure else intResult = "-2" end if Subscribe = intResult End Function ' ====================================================================== %>