%
Sub TemplateFormatMail (rsOrder, rsitems, merchant, customer)
'*********************************************************
' Version 6.50
' Sends mail to customer and merchnat via templates
' Now Uses Customer_Template
' Merchant_Template
' March 20, 2004 add SMS
' format of each record is
' name, email address, template
' test Person,abc@def.com,tmp_merchantemail.txt
' Or for sms
' test Person,abc@def.com,tmp_merchantemail.txt,smsservice
'******************************************************************
Body=""
Dim Textarray(500)
Dim TextCount
dim Filename
dim i
Dim CR
'CR="
"
filename=getconfig("XMerchantEmail")
SetupEmailformat filename,merchantemailformat
setsess "emailformat",ucase(merchantemailformat)
'Merchant
ShopTemplateArray Filename, rsOrder, TextArray, TextCount
Merchant=""
CR=GetMailCR
for i = 0 to Textcount-1
Merchant= Merchant & TextArray(i) & CR
next
Merchant=Removehtml(Merchant, CR)
'debugwrite merchant
' Customer
filename=getconfig("XCustomerEmail")
SetupEmailformat filename,customeremailformat
setsess "emailformat",ucase(customeremailformat)
ShopTemplateArray Filename, rsOrder, TextArray, TextCount
Customer=""
for i = 0 to Textcount-1
Customer= Customer & TextArray(i) & CR
next
Customer=Removehtml(Customer,CR)
If getconfig("xemaillist")<>"" Then
HandleEmailList
end if
'debugwrite Customer
end sub
'
Sub HandleEmailList
'************************************************************************
' read mailing list into an array maillist
' parse to get name, emailaddress and template
' process the template
' mail to this person
'***********************************************************************
dim i,j
dim words(10)
dim wordcount
dim delimiter
delimiter=","
dim inrecord
dim firstchar
Dim templateFile
Dim OtherPerson
dim CR, emailformat
dim mailname, mailaddress, temparray(100)
dim smsservice, smsfrom, smsphone
ShopReadEntireFile getconfig("xemaillist"), maillist,maillistcount, temparray
If maillistcount=0 then exit sub
for i=0 to maillistcount
inrecord=maillist(i)
firstchar=left(inrecord,1)
if firstchar="*" or firstchar="'" then
else
ParseRecord inrecord, words, wordcount, delimiter
templatefile=words(2)
smsservice=words(3)
if templatefile<>"" then
SetupEmailformat templatefile,emailformat
setsess "emailformat",ucase(emailformat)
if emailformat="HTML" then
CR=""
else
CR=GetMailCR
end if
ShopTemplateArray templatefile, rsOrder, TextArray, TextCount
OtherPerson=""
for j = 0 to Textcount-1
OtherPerson= OtherPerson & TextArray(j) & CR
next
If emailformat<>"HTML" then
OtherPerson=replace(OtherPerson,"
", CR)
end if
mailname=words(0)
mailaddress=words(1)
if getconfig("xDebug")="Yes" then
Debugwrite mailname & " " & mailaddress & " " & TextCount
debugwrite OtherPerson
end if
If SmsService="" then
mailPerson mailname, mailaddress, getconfig("xemailname"), getconfig("xemail"), getconfig("xemailsubject"), OtherPerson,"No"
else
smsfrom=getconfig("xemailname")
smsphone=words(1) ' phone number
If getconfig("xdebug")="Yes" then
debugwrite "Email list sending sms to " & smsphone & " text=" & otherperson
end if
sendsms smsservice,smsfrom,smsphone,otherperson
end if
end if
end if
next
end sub
Sub ParseRecord (record,words,wordcount,delimiter)
Dim pos
Dim recordl
Dim bytex
Dim temprec
Dim maxwords
Dim i
maxwords = 10
temprec = record
Dim maxentries
pos = 1
wordcount = 0
' make sure word array is null
maxentries = UBound(words)
For i = 0 To maxentries - 1
words(i) = ""
Next
recordl = Len(temprec)
' first eliminate leading blanks
Do
bytex = Mid(temprec, pos, 1)
While bytex = " " And pos <= recordl
pos = pos + 1
bytex = Mid(temprec, pos, 1)
Wend
' copy word into word array
While bytex <> delimiter And pos <= recordl
words(wordcount) = words(wordcount) & bytex
pos = pos + 1
bytex = Mid(temprec, pos, 1)
Wend
wordcount = wordcount + 1
pos = pos + 1
If wordcount > maxentries Then Exit Sub
Loop Until pos > recordl
End Sub
Sub FormatOtherMail (Filename, RS, Result)
' Use mail on any recordset or table.
' Returns Result
Dim Textarray(500)
Dim TextCount
dim i
dim emailformat
Dim CR
SetupEmailformat filename,emailformat
setsess "emailformat",ucase(emailformat)
CR=GetMailCR
ShopTemplateArray Filename, RS, TextArray, TextCount
Result=""
for i = 0 to Textcount-1
Result= Result & TextArray(i) & CR
next
if emailformat<>"HTML" then
Result=replace(Result,"
", CR)
end if
end sub
'
Function Removehtml(itemname, CR)
dim workrecord, firstchar, morefields, pos, endpos, length
dim token
If ucase(Getsess("emailformat"))="HTML" then
Removehtml=itemname
exit function
end if
workrecord=replace(itemname,"
",CR)
If getconfig("xemailremovehtml")<>"Yes" then
Removehtml=workrecord
exit function
end if
pos=1
morefields = True
Do While morefields = True
pos=1
pos = InStr(pos, workrecord, "<")
If pos > 0 Then
endpos = InStr(pos, workrecord, ">")
If endpos=0 then
morefields=false
else
length = endpos - pos + 1
token = Mid(workrecord, pos, length)
workrecord=replace(workrecord,token,"")
end if
else
morefields=false
end if
loop
Removehtml=workrecord
end function
Sub Setupemailformat (filename, emailformat)
dim temp
emailformat="TEXT"
If ucase(getconfig("XEmailFormat"))<>"HTML" then exit sub
temp=right(filename,3)
if ucase(temp)="TXT" then
emailformat="TEXT"
else
emailformat="HTML"
end if
end sub
%>