<% ' Copyright (C) 1998-2005 Cyberstrong Internet Services, Inc. All Rights Reserved ' ' This file has been seeded with unique information at point of sale and ' is traceable to its purchaser. ' ' Your license agreement forbids the removal of this notice. ' ' eMailOrder() - Email copy of order in plain text ... ' Dim TextBodyNotify1, TextBodyNotify2, TextBodyCustomer Public Function EMailOrder(ByVal OrderID, ByVal EMailType) Dim rstOrders, rstOrderDetails, rstCustomer Dim ErrorMsg, txtPaymentMethod, txtShippingMethod, iShipping, iTax1, iTax2, iSubTotal Dim objMail, FromAddress, ToAddress, Subject, Trace, SQL Dim arySurvey, iSurvey, Address, AddressList, AdminFolderName Dim pAdvTax, ws Const DemoEMailAddr = "Doe@NoMailHere.com" Trace = False Set ws = New clsWS ' "Write String" class TextBodyNotify1 = ReadFile("\custom\email\notify1.txt") TextBodyNotify2 = ReadFile("\custom\email\notify2.txt") TextBodyCustomer = ReadFile("\custom\email\customer.txt") ' Get admin folder name from user exit ... AdminFolderName = "admin" ' Default ... Call UserExit(usrGetAdminFolderName, 0, 0, 0, 0, AdminFolderName) ' Create record sets from global connection object ... SQL = "SELECT * FROM Orders WHERE OrderId = " & OrderID set rstOrders = Server.CreateObject("ADODB.Recordset") rstOrders.Open SQL, Conn, adOpenKeyset, adLockOptimistic If (Not rstOrders.EOF) Then SQL = "select * from OrderDetails where OrderID = " & rstOrders("OrderId") & " Order By OrderDetailID" set rstOrderDetails = Server.CreateObject("ADODB.Recordset") rstOrderDetails.Open SQL, Conn, adOpenKeyset, adLockOptimistic SQL = "select * from Customers where CustomerID = " & rstOrders("CustomerID") set rstCustomer = Server.CreateObject("ADODB.Recordset") rstCustomer.Open SQL, Conn, adOpenKeyset, adLockOptimistic txtPaymentMethod = rstOrders("PaymentMethodDescription") txtShippingMethod = rstOrders("ShippingMethodDescription") & _ IIF(cstDisplayTransitTime And (Not strIsEmpty(rstOrders("TransitTime"))), " (" & Trim(rstOrders("TransitTime")) & ")", "") Else Call Log (0, "eOrder(): Cannot retrieve order " & OrderID & " from database. eMail not sent") Exit Function End If ' Substitue for variables in template.. Call SubTemplate("CatalogName", cstCatalogName) Call SubTemplate("HomeURL", cstHomeURL) Call SubTemplate("OrderNo", cstOrderStartNo + OrderID) Call SubTemplate("OrderDate", OurFormatDateTime(rstOrders("OrderDate"), "%MM/%DD/%YYYY")) Call SubTemplate("ShippingInfo", txtShippingMethod) Call SubTemplate("ViewOrderLink", SecureURL("50Finish.asp?OrderID=" & rstOrders("OrderId") + cstOrderStartNo & "&Password=" & rstOrders("Password"))) Call SubTemplate("LoginLink", NonSecureURL(AdminFolderName & "/mLogin.asp")) ws.Clear() ws(rstCustomer("ContactFirstName")) & " " & Trim(rstCustomer("ContactLastName")) ws(rstCustomer("CompanyName")) ws(rstCustomer("Organization")) ws(rstCustomer("BillingAddress1")) ws(rstCustomer("BillingAddress2")) ws(rstCustomer("City")) ws(rstCustomer("StateOrProvince")) ws(rstCustomer("PostalCode")) ws(rstCustomer("Country")) Call SubTemplate("BillToAddress", ws.Gets()) Call SubTemplate("BillToTelephone", rstCustomer("PhoneNumber")) Call SubTemplate("BillToEmail", rstCustomer("EmailAddress")) ws.Clear() ws(rstOrders("ShipContactFirstName")) & " " & Trim(rstOrders("ShipContactLastName")) ws(rstOrders("ShipCompanyName")) ws(rstOrders("ShipOrganization")) ws(rstOrders("ShipAddress1")) ws(rstOrders("ShipAddress2")) ws(rstOrders("ShipCity")) ws(rstOrders("ShipStateOrProvince")) ws(rstOrders("ShipPostalCode")) ws(rstOrders("ShipCountry")) Call SubTemplate("ShipToAddress", IIF(strIsEmpty(ws.Gets()), "N/A", ws.Gets())) Call SubTemplate("ShipToTelephone", rstCustomer("ShipPhoneNumber")) ws.Clear() ws("Payment Method: " & rstOrders("PaymentMethodDescription")) If (Trim(rstOrders("CreditCardNumber")) <> "") Then ws("Card No: " & GreekCCNum(Crypt(rstOrders("CreditCardNumber"), cstEncryptionKey, "dec"), "f")) ws("Card Holder: " & rstOrders("CardholdersName")) ws("Card Expires: " & Crypt(rstOrders("CreditCardExpDate"), cstEncryptionKey, "dec")) End If If (cstPONumberEnabled) Then ws("PO No: " & rstOrders("PurchaseOrderNumber")) End If Call SubTemplate("PaymentInfo", ws.Gets()) ws.Clear() arySurvey = GetParms(cstSurveyQuestions) For iSurvey = 0 To UBound(arySurvey) ws(StripHTML(arySurvey(iSurvey))) ws("  " & rstOrders("Survey" & (iSurvey + 1))) Next Call SubTemplate("SurveyAnswers", Replace(ws.Gets(), " ", " ")) ' Defeats ws() trim Call SubTemplate("CustomerNotes", Replace(rstOrders("Notes"),"~", vbCrLf)) ' Order details... iSubtotal = 0 : ws.Clear() Do While Not rstOrderDetails.EOF ws(rstOrderDetails("ProductName")) ws("Product Code: " & rstOrderDetails("ProductCode")) ws(rstOrderDetails("Options")) ws("Qty: " & rstOrderDetails("Quantity") & " @ " & _ OurFormatCurrency(rstOrderDetails("UnitPrice")) & " = " & _ OurFormatCurrency(rstOrderDetails("TotalPrice")) & vbCrLF) iSubTotal = iSubtotal + rstOrderDetails("TotalPrice") rstOrderDetails.MoveNext Loop Call SubTemplate("OrderDetails", ws.Gets()) ' Order totals ... ws.Clear() iSubTotal = IIF(iSubTotal < 0, 0, iSubTotal) ws(FixedField(10, "R", OurFormatCurrency(iSubTotal)) & " Sub Total") ' Sales tax, when applicable ... If (Not cstHideSalesTax) Then iTax1 = IIF(isNullOrZero(rstOrders("SalesTax1")), 0, rstOrders("SalesTax1")) iTax2 = IIF(isNullOrZero(rstOrders("SalesTax2")), 0, rstOrders("SalesTax2")) If (isInstalled("Feature:Advanced Tax")) Then ' Advanced tax processing ... Set pAdvTax = FeatureInstalled("Feature:Advanced Tax") If (pAdvTax.Tax1InUse) Then ws(FixedField(10, "R", Cstr(OurFormatCurrency(iTax1))) & " " & GetParmToken(cstSalesTaxName, 1, "Sales Tax 1")) End If If (pAdvTax.Tax2InUse) Then ws(FixedField(10, "R", Cstr(OurFormatCurrency(iTax2))) & " " & GetParmToken(cstSalesTaxName, 2, "Sales Tax 2")) End If Else ' Standard tax processing ... ws(FixedField(10, "R", Cstr(OurFormatCurrency(iTax1))) & " Sales Tax") End If Else iTax1 = 0 iTax2 = 0 End If ' Shipping charge, when applicable ... iShipping = rstOrders("FreightCharge") ws(FixedField(10, "R", IIF(rstOrders("FreeShipping") = "Yes", "Free!", OurFormatCurrency(CStr(iShipping)))) & " Shipping") ' Grand total ... ws(FixedField(10, "R", CStr(OurFormatCurrency(iSubTotal + iShipping + iTax1 + iTax2))) & " Order Total") Call SubTemplate("OrderTotals", ws.Gets()) ' Download link... ws.Clear() If (Not strIsEmpty(rstOrders("DownloadFolderLink"))) Then ws(rstOrders("DownloadFolderLink")) If (cstDownloadDeleteDays > 0) Then ws("(Valid for " & cstDownloadDeleteDays & " days from date of purchase)") End If Else ws("This order contains no downloadable items.") End If Call SubTemplate("DownloadFolderLink", ws.Gets()) If (Trace) Then wl("
")
		wl("========== Notify 1 ==========")
		wl(TextBodyNotify1)
		wl("========== Notify 2 ==========")
		wl(TextBodyNotify2)
		wl("========== Customer ==========")
		wl(TextBodyCustomer)
		wl("
") Exit Function End If ' Send the e-mail... If (EMailType = "Customer") Then If (Trim((rstCustomer("EmailAddress")) <> "") AND _ Trim((rstCustomer("EmailAddress")) <> DemoEmailAddr)) Then FromAddress = cstFromEmailAddress Subject = GetSubjectLine(cstCustomerEMailSubjectLine, OrderID) ' Unsupported feature: Send CC of receipt to address list separated by commas ... AddressList = Split(rstCustomer("EmailAddress") & ",", ",") For Each Address in AddressList If (Trim(Address) <> "") Then ToAddress = Address Call SendEMail(FromAddress, ToAddress, Subject, TextBodyCustomer) End If Next End If End If If (EMailType = "Vendor") Then AddressList = Split(cstNotifyAddress1 & ",", ",") Subject = GetSubjectLine(cstNotify1EMailSubjectLine, OrderID) For Each Address in AddressList If (Trim(Address) <> "") Then FromAddress = cstFromEmailAddress ToAddress = Address Call SendEMail(FromAddress, ToAddress, Subject, TextBodyNotify1) End If Next AddressList = Split(cstNotifyAddress2 & ",", ",") Subject = GetSubjectLine(cstNotify2EMailSubjectLine, OrderID) For Each Address in AddressList If (Trim(Address) <> "") Then FromAddress = cstFromEmailAddress ToAddress = Address Call SendEMail(FromAddress, ToAddress, Subject, TextBodyNotify2) End If Next End If ' Clean up ... rstOrders.Close rstOrderDetails.Close rstCustomer.Close set rstOrders = Nothing set rstOrderDetails = Nothing set rstCustomer = Nothing End Function ' Local support functions ... Private Sub SubTemplate(ByVal argVariable, argValue) Dim Value ' Remove trailing CrLfs when present... Value = ReplaceRegEx(argValue, "[" & vbCrLf & "]*$", "", "") TextBodyNotify1 = Replace(TextBodyNotify1, "$(" & argVariable & ")", Value) TextBodyNotify2 = Replace(TextBodyNotify2, "$(" & argVariable & ")", Value) TextBodyCustomer = Replace(TextBodyCustomer, "$(" & argVariable & ")", Value) End Sub ' GetSubjectLine() - Build subject line with user subs... Private Function GetSubjectLine(ByVal argTemplate, ByVal argOrderID) GetSubjectLine = argTemplate GetSubjectLine = Replace(GetSubjectLine, "$(CatalogName)", cstCatalogName) GetSubjectLine = Replace(GetSubjectLine, "$(OrderNo)", cstOrderStartNo + argOrderID) End Function ' Format text in fixed field width ... Private Function FixedField(ByVal Width, ByVal Justify, ByVal Text) Select Case True Case Width < Len(Text) Select Case True Case Justify = "L" FixedField = Left(Text, Width) Case Justify = "R" FixedField = Right(Text, Width) Case Else End Select Case Width = Len(Text) FixedField = Text Case Width > Len(Text) Select Case True Case Justify = "L" FixedField = Text & String(Width - Len(Text), " ") Case Justify = "R" FixedField = String(Width - Len(Text), " ") & Text Case Else End Select End Select End Function %>