%
' ASPMaker functions for ASPMaker 5+
' (C)2006 e.World Technology Ltd.
' Common constants
Const EW_DATE_SEPARATOR = "."
Const EW_SMTPSERVER = "localhost"
Const EW_SMTPSERVER_PORT = 25
Const EW_SMTPSERVER_USERNAME = ""
Const EW_SMTPSERVER_PASSWORD = ""
'-------------------------------------------------------------------------------
' Functions for default date format
' ANamedFormat = 0-8, where 0-4 same as VBScript
' 5 = "yyyy.mm.dd"
' 6 = "mm.dd.yyyy"
' 7 = "dd.mm.yyyy"
' 8 = Short Date & " " & Short Time
Function EW_FormatDateTime(ADate, ANamedFormat)
If IsDate(ADate) Then
If ANamedFormat >= 0 And ANamedFormat <= 4 Then
EW_FormatDateTime = FormatDateTime(ADate, ANamedFormat)
ElseIf ANamedFormat = 5 Then
EW_FormatDateTime = Year(ADate) & EW_DATE_SEPARATOR & Month(ADate) & EW_DATE_SEPARATOR & Day(ADate)
ElseIf ANamedFormat = 6 Then
EW_FormatDateTime = Month(ADate) & EW_DATE_SEPARATOR & Day(ADate) & EW_DATE_SEPARATOR & Year(ADate)
ElseIf ANamedFormat = 7 Then
EW_FormatDateTime = Day(ADate) & EW_DATE_SEPARATOR & Month(ADate) & EW_DATE_SEPARATOR & Year(ADate)
ElseIf ANamedFormat = 8 Then
EW_FormatDateTime = FormatDateTime(ADate, 2)
If Hour(ADate) <> 0 Or Minute(ADate) <> 0 Or Second(ADate) <> 0 Then
EW_FormatDateTime = EW_FormatDateTime & " " & FormatDateTime(ADate, 4) & ":" & ewZeroPad(Second(ADate), 2)
End If
Else
EW_FormatDateTime = ADate
End If
Else
EW_FormatDateTime = ADate
End If
End Function
Function EW_UnFormatDateTime(ADate, ANamedFormat)
Dim arDateTime, arDate
ADate = Trim(ADate & "")
While Instr(ADate, " ") > 0
ADate = Replace(ADate, " ", " ")
Wend
arDateTime = Split(ADate, " ")
If UBound(arDateTime) < 0 Then
EW_UnFormatDateTime = ADate
Exit Function
End If
arDate = Split(arDateTime(0), EW_DATE_SEPARATOR)
If UBound(arDate) = 2 Then
If ANamedFormat = 6 Then
EW_UnFormatDateTime = arDate(2) & "/" & arDate(0) & "/" & arDate(1)
ElseIf ANamedFormat = 7 Then
EW_UnFormatDateTime = arDate(2) & "/" & arDate(1) & "/" & arDate(0)
Else ' ANamedFormat = 5 or other
EW_UnFormatDateTime = arDate(0) & "/" & arDate(1) & "/" & arDate(2)
End If
If UBound(arDateTime) > 0 Then
If IsDate(arDateTime(1)) Then ' Is time
EW_UnFormatDateTime = EW_UnFormatDateTime & " " & arDateTime(1)
End If
End If
Else
EW_UnFormatDateTime = ADate
End If
End Function
' Note: Object "conn" is required
Function ewExecuteScalar(SQL)
ewExecuteScalar = Null
If Trim(SQL&"") = "" Then Exit Function
Dim rs
Set rs = conn.Execute(SQL)
If Not rs.Eof Then ewExecuteScalar = rs(0)
rs.Close
Set rs = Nothing
End Function
'-------------------------------------------------------------------------------
' Function for debug
Sub Trace(aMsg)
On Error Resume Next
Dim fso, ts
Set fso = Server.Createobject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile(Server.MapPath("debug.txt"), 8, True)
ts.writeline(aMsg)
ts.Close
Set ts = Nothing
Set fso = Nothing
End Sub
%>
<%
' Function to Load Email Content from input file name
' - Content Loaded to the following variables
' - Subject: sEmailSubject
' - From: sEmailFrom
' - To: sEmailTo
' - Cc: sEmailCc
' - Bcc: sEmailBcc
' - Format: sEmailFormat
' - Content: sEmailContent
'
sEmailFrom = "": sEmailTo = "": sEmailCc = "": sEmailBcc = "": sEmailSubject = "": sEmailFormat = "": sEmailContent = ""
Sub LoadEmail(fn)
Dim sWrk, sHeader, arrHeader
Dim sName, sValue
Dim i, j
' Initialize
sEmailFrom = "": sEmailTo = "": sEmailCc = "": sEmailBcc = "": sEmailSubject = "": sEmailFormat = "": sEmailContent = ""
sWrk = LoadTxt(fn) ' Load text file content
If sWrk <> "" Then
' Locate Header & Mail Content
i = InStr(sWrk, vbCrLf&vbCrLf)
If i > 0 Then
sHeader = Mid(sWrk, 1, i)
sEmailContent = Mid(sWrk, i+4)
arrHeader = Split(sHeader, vbCrLf)
For j = 0 to UBound(arrHeader)
i = InStr(arrHeader(j), ":")
If i > 0 Then
sName = Trim(Mid(arrHeader(j), 1, i-1))
sValue = Trim(Mid(arrHeader(j), i+1))
Select Case LCase(sName)
Case "subject": sEmailSubject = sValue
Case "from": sEmailFrom = sValue
Case "to": sEmailTo = sValue
Case "cc": sEmailCc = sValue
Case "bcc": sEmailBcc = sValue
Case "format": sEmailFormat = sValue
End Select
End If
Next
End If
End If
End Sub
' Function to Load a Text File
Function LoadTxt(fn)
Dim fso, fobj
' Get text file content
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set fobj = fso.OpenTextFile(Server.MapPath(fn))
LoadTxt = fobj.ReadAll ' Read all Content
fobj.Close
Set fobj = Nothing
End Function
' Function to Send out Email
Sub Send_Email(sFrEmail, sToEmail, sCcEmail, sBccEmail, sSubject, sMail, sFormat)
Dim objMail, objConfig, sServerVersion, i, sIISVer
Dim sSmtpServer, iSmtpServerPort
sServerVersion = Request.ServerVariables("SERVER_SOFTWARE")
If InStr(sServerVersion, "Microsoft-IIS") > 0 Then
i = InStr(sServerVersion, "/")
If i > 0 Then
sIISVer = Trim(Mid(sServerVersion, i+1))
End If
End If
If sIISVer < "5.0" Then
' NT using CDONTS
Set objMail = Server.CreateObject("CDONTS.NewMail")
objMail.From = sFrEmail
objMail.To = Replace(sToEmail, ",", ";")
If sCcEmail <> "" Then
objMail.Cc = Replace(sCcEmail, ",", ";")
End If
If sBccEmail <> "" Then
objMail.Bcc = Replace(sBccEmail, ",", ";")
End If
If LCase(sFormat) = "html" Then
objMail.BodyFormat = 0 ' 0 means HTML format, 1 means text
objMail.MailFormat = 0 ' 0 means MIME, 1 means text
End If
objMail.Subject = sSubject
objMail.Body = sMail
objMail.Send
Set objMail = Nothing
Else
' 2000 / XP / 2003 using CDO
' Set up Mail
Set objMail = Server.CreateObject("CDO.Message")
sSmtpServer = EW_SMTPSERVER
iSmtpServerPort = EW_SMTPSERVER_PORT
If (sIISVer < "6.0") Or (sSmtpServer <> "" And LCase(sSmtpServer) <> "localhost") Then ' XP or not localhost
' Set up Configuration
Set objConfig = CreateObject("CDO.Configuration")
objConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 ' cdoSendUsingMethod = cdoSendUsingPort
objConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = sSmtpServer ' cdoSMTPServer
objConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = iSmtpServerPort ' cdoSMTPServerPort
If EW_SMTPSERVER_USERNAME <> "" And EW_SMTPSERVER_PASSWORD <> "" Then
objConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'cdoBasic (clear text)
objConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = EW_SMTPSERVER_USERNAME
objConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = EW_SMTPSERVER_PASSWORD
End If
objConfig.Fields.Update
Set objMail.Configuration = objConfig ' Use Configuration
End If
objMail.From = sFrEmail
objMail.To = Replace(sToEmail, ",", ";")
If sCcEmail <> "" Then
objMail.Cc = Replace(sCcEmail, ",", ";")
End If
If sBccEmail <> "" Then
objMail.Bcc = Replace(sBccEmail, ",", ";")
End If
If LCase(sFormat) = "html" Then
objMail.HtmlBody = sMail
Else
objMail.TextBody = sMail
End If
objMail.Subject = sSubject
objMail.Send
Set objMail = Nothing
Set objConfig = Nothing
End If
End Sub
%>
<%
' Function to generate Value Separator based on current row count
' rowcnt - zero based row count
'
Function ValueSeparator(rowcnt)
ValueSeparator = ", "
End Function
' Function to generate View Option Separator based on current row count (Multi-Select / CheckBox)
' rowcnt - zero based row count
'
Function ViewOptionSeparator(rowcnt)
ViewOptionSeparator = ", "
' Sample code to adjust 2 options per row
'If ((rowcnt + 1) Mod 2 = 0) Then ' 2 options per row
'ViewOptionSeparator = ViewOptionSeparator & "
"
'End If
End Function
' Function to render repeat column table
' rowcnt - zero based row count
'
Function RenderControl(totcnt, rowcnt, repeatcnt, rendertype)
Dim sWrk
sWrk = ""
' Render control start
If rendertype = 1 Then
If rowcnt = 0 Then sWrk = sWrk & "
| " ' Render control end ElseIf rendertype = 2 Then sWrk = sWrk & " | " If (rowcnt mod repeatcnt = repeatcnt -1) Then sWrk = sWrk & "" Next sWrk = sWrk & "" End If If rowcnt = totcnt Then sWrk = sWrk & " |