Files
KON/Lib/func.asp
2026-08-07 12:53:18 +09:00

509 lines
16 KiB
Plaintext

<%
'=======================================================================
'업 무 명 : K-ON common
'모듈기능 : 공통 함수 정의
'파 일 명 : Func.asp
'작성일자 : 2020-08-24
'작 성 자 : 김홍완
'-----------------------------------------------------------------------
'변경일자 변경자 변동내역
'=======================================================================
'2020-08-24 김홍완 date_db(), date_time() 추가
'=======================================================================
'Response.Expires = -1
%>
<%
'//-- date_db(), date_time()
dim v_datetime, v_day, v_hour, v_minute, v_month, v_second, v_year, mLen, dLen
'###########################################################################################
'URL Redirect
'###########################################################################################
Function call_Url(url,msg)
Response.Write "<html xmlns='http://www.w3.org/1999/xhtml'>" & vbCRLF
Response.Write "<head>" & vbCrLF
Response.Write "<title>" & SurveyTitle & "</title>" & vbCrlf
Response.Write "<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />" & vbCrlf
Response.Write "</head>" & vbCrLF
Response.Write "<script language='javascript'>" & vbCrlf
Response.Write "<!--" & vbCrlf
if Trim(msg)<>"" Then
Response.Write " alert('" & trim(msg) & "');" & vbCrlf
end if
Response.Write " location.replace('" & trim(url) & "');" & vbCrlf
Response.Write "//-->" & vbCrlf
Response.Write "</script>" & vbCrlf
Response.Write "</html>"
End Function
Function LoadSkin(fnName)
Dim objStream
Set objStream = CreateObject("ADODB.Stream")
With objStream
.Charset = "utf-8"
.Type=2
.mode=3
.Open
.loadfromfile Server.Mappath(fnName)
LoadSkin=.readtext
.Close
End With
Set objStream = Nothing
End Function
'###########################################################################################
'메일 발송
'###########################################################################################
Function MailSend(FromStr,ToStr,Subject,BodyStr)
Dim objMail,iConf
Set objMail=server.CreateObject("CDO.Message")
Set iConf = objMail.Configuration
With iConf.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") =2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") =MAIL_SV
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") =25
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") =1
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") =MAIL_ID
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") =MAIL_PW
.Update
End with
objMail.To = ToStr
objMail.From = FromStr
objmail.Subject = Subject
objmail.htmlBody = BodyStr
objMail.BodyPart.Charset="utf-8"
objMail.Send
Set objMail = Nothing
End Function
'###########################################################################################
'CDO 메일 발송
'###########################################################################################
Function CMailSend(FromStr,ToStr,Subject,BodyStr)
Dim objMail,iConf
Set objMail=server.CreateObject("CDO.Message")
Set iConf = objMail.Configuration
With iConf.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="localhost"
.item("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "C:\inetpub\mailroot\pickup"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") =25
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 30
.Update
End with
objMail.To = ToStr
objMail.From = FromStr
objmail.Subject = Subject
objmail.htmlBody = BodyStr
objMail.BodyPart.Charset="utf-8"
objMail.Send
Set objMail = Nothing
End Function
'###########################################################################################
'랜덤 난수 발생
'###########################################################################################
Function RandomNum(start,limit)
Dim Val,MyValue
if Not IsNumeric(start) Or Not IsNumeric(limit) then
RandomNum = 0
Exit Function
end if
Randomize
MyValue = Int(limit * Rnd) + start
RandomNum=MyValue
End Function
'###########################################################################################
'에러 메일 발송
'###########################################################################################
Private Sub ErrorMail(er)
Dim ErrBody
ErrBody = LoadSkin("./SKIN/Error.htm")
ErrBody = Replace(ErrBody,"##PROJECTTITLE##",SURVEYTITLE)
ErrBody = Replace(ErrBody,"##PROJECTCODE##",PROJECTCODE)
ErrBody = Replace(ErrBody,"##PAGE##",Request.Form("PageName"))
ErrBody = Replace(ErrBody,"##ERKEY##",Request.Form("IDKey"))
ErrBody = Replace(ErrBody,"##CODE##",er.Description)
ErrBody = Replace(ErrBody,"##NUMBER##",er.Number)
MailSend "system@survey.kr","wmkim@trendmr.com;ehlee@trendmr.com;" & ERROREMAIL ,"Error Message",ErrBody
End Sub
'###########################################################################################
'makeItem
'###########################################################################################
'사용방법
'Call QuestionMultiCNT(VARS,CODES,QUESTION,3,2,HTMLSCRIPT,JSCRIPT)
'HTMLSCRIPT = Replace(HTMLSCRIPT,"[$_STITEM_$]",makeItem("Front_1_A.jpg,Front_1_B.jpg,Front_1_C.jpg,Front_1_D.jpg",getXValue("MQ1"),"LIKE"))
Function makeItem(IMAGES,SELNUM,TEXT)
Dim TableBody,ImageArray,tCount,Twidth
TableBody = ""
ImageArray = Split(IMAGES,",")
TWidth = FormatNumber(CDbl(100/(UBound(ImageArray)+1)),2)
TableBody = TableBody & "<table id='V_table' class='attab01' cellpadding='0' cellspacing='0' border='0'>" & vbCrLF
TableBody = TableBody & "<colgroup>" & vbCrLF
For tCount=0 To UBound(ImageArray)
TableBody = TableBody & " <col width="""&TWidth&"%""/>" & vbCrLF
Next
TableBody = TableBody & "</colgroup>" & vbCrLF
TableBody = TableBody & "<tr>" & vbCrLF
For tCount=0 To UBound(ImageArray)
TableBody = TableBody & "<th style='text-align:center;background:#fff;'>"&vbCrLF
TableBody = TableBody & " <img src=""./media/"&ImageArray(tCount)&""" alt=''/>"&vbCrLF
TableBody = TableBody & "</th>"&vbCrLF
Next
TableBody = TableBody & "</tr>" & vbCrLF
TableBody = TableBody & "<tr>" & vbCrLF
For tCount=0 To UBound(ImageArray)
TableBody = TableBody & "<td style='text-align:center;background:#fff;'>"&vbCrLF
If (tCount+1)=CInt(SELNUM) Then
TableBody = TableBody & " <b><font color='red'>" & TEXT & "</font></b>"&vbCrLF
Else
TableBody = TableBody & "&nbsp;" & vbCrLF
End IF
TableBody = TableBody & "</td>"&vbCrLF
Next
TableBody = TableBody & "</tr>" & vbCrLF
TableBody = TableBody & "</table>"&vbCrLF
makeItem = TableBody
End Function
Function makeItem2(IMAGES,SELNUM,TEXT,COL)
Dim TableBody,ImageArray,tCount,Twidth
Dim EStr,DStr,XStr,mxCOL,colCnt
mxCOL = CLng(COL)
colCnt=1
TableBody = ""
ImageArray = Split(IMAGES,",")
TWidth = FormatNumber(CDbl(100/CLng(COL)),2)
TableBody = TableBody & "<table id='V_table' class='attab01' cellpadding='0' cellspacing='0' border='0'>" & vbCrLF
TableBody = TableBody & "<colgroup>" & vbCrLF
For tCount=1 To CLng(COL)
TableBody = TableBody & " <col width="""&TWidth&"%""/>" & vbCrLF
Next
TableBody = TableBody & "</colgroup>" & vbCrLF
' TableBody = TableBody & "<tr>" & vbCrLF
DStr = ""
EStr = ""
For tCount=0 To UBound(ImageArray)
EStr = EStr & "<th style='text-align:center;background:#fff;'>"&vbCrLF
EStr = EStr & " <img src=""./media/"&ImageArray(tCount)&""" alt=''/>"&vbCrLF
EStr = EStr & "</th>"&vbCrLF
DStr = DStr & "<td style='text-align:center;background:#fff;'>"&vbCrLF
If (tCount+1)=CInt(SELNUM) Then
DStr = DStr & " <b><font color='red'>" & TEXT & "</font></b>"&vbCrLF
Else
DStr = DStr & "&nbsp;" & vbCrLF
End IF
DStr = DStr & "</td>"&vbCrLF
If colCnt=mxCOL Then
XSTR = XSTR & " <tr>" & vbCRLF
XSTR = XSTR & EStr
XSTR = XSTR & " </tr>" & vbCRLF
XSTR = XSTR & " <tr>" & vbCRLF
XSTR = XSTR & DStr
XSTR = XSTR & " </tr>" & vbCRLF
ESTR = ""
DSTR = ""
colCnt=1
Else
colCnt=colCnt+1
End If
Next
If ESTR<>"" AND DSTR<>"" Then
XSTR = XSTR & " <tr>" & vbCRLF
XSTR = XSTR & EStr & DSTR
XSTR = XSTR & " </tr>" & vbCRLF
End If
TableBody = TableBody & XStr
TableBody = TableBody & "<tr>" & vbCrLF
For tCount=0 To UBound(ImageArray)
Next
' TableBody = TableBody & "</tr>" & vbCrLF
TableBody = TableBody & "</table>"&vbCrLF
makeItem2 = TableBody
End Function
'##############################################################################
'#http:체크
'##############################################################################
Function checkHTTP(linkStr)
If Left(linkStr,7)="http://" Then
checkHTTP = linkStr
Else
checkHTTP = "http://" & linkStr
End If
End Function
'###########################################################################################
'DB 날짜 형식대로 ASP로 출력하기
'###########################################################################################
Function ConvertDBDate(dates)
Dim yy,mm,dd,hh,mi,se
yy = year(dates)
mm = right("0" & month(dates),2)
dd = right("0" & day(dates),2)
hh = right("0" & hour(dates),2)
mi = right("0" & minute(dates),2)
se = right("0" & second(dates),2)
ConvertDBDate = yy & "-" & mm & "-" & dd & " " & hh & ":" & mi & ":" & se
End Function
'###########################################################################################
'ADODB Recordset to CSV
'###########################################################################################
Sub Write_CSV_From_Recordset(RS)
'
' Export Recordset to CSV
' http://salman-w.blogspot.com/2009/07/export-recordset-data-to-csv-using.html
'
' This sub-routine Response.Writes the content of an ADODB.RECORDSET in CSV format
' The function closely follows the recommendations described in RFC 4180:
' Common Format and MIME Type for Comma-Separated Values (CSV) Files
' http://tools.ietf.org/html/rfc4180
'
' @RS: A reference to an open ADODB.RECORDSET object
'
if RS.EOF then
'
' There is no data to be written
'
exit sub
end if
dim RX
set RX = new RegExp
RX.Pattern = "\r|\n|,|"""
dim i
dim Field
dim Separator
'
' Writing the header row (header row contains field names)
'
Separator = ""
for i = 0 to RS.Fields.Count - 1
Field = RS.Fields(i).Name
if RX.Test(Field) then
'
' According to recommendations:
' - Fields that contain CR/LF, Comma or Double-quote should be enclosed in double-quotes
' - Double-quote itself must be escaped by preceeding with another double-quote
'
Field = """" & Replace(Field, """", """""") & """"
end if
Response.Write Separator & Field
Separator = ","
next
Response.Write vbNewLine
'
' Writing the data rows
'
do until RS.EOF
Separator = ""
for i = 0 to RS.Fields.Count - 1
'
' Note the concatenation with empty string below
' This assures that NULL values are converted to empty string
'
Field = RS.Fields(i).Value & ""
if RX.Test(Field) then
Field = """" & Replace(Field, """", """""") & """"
Field = Replace(Field,vbCrLF," ")
end If
If isNumeric(Field) Then
'Response.Write Separator & Chr(34) & "'" & Field & Chr(34)
Response.Write Separator & Chr(34) & Field & Chr(34)
Else
Response.Write Separator & Chr(34) & Field & Chr(34)
End IF
Separator = ","
next
Response.Write vbNewLine
RS.MoveNext
loop
End Sub
Function URLDecode(Expression)
Dim strSource, strTemp, strResult, strchr
Dim lngPos, AddNum, IFKor
strSource = Replace(Expression, "+", " ")
For lngPos = 1 To Len(strSource)
AddNum = 2
strTemp = Mid(strSource, lngPos, 1)
If strTemp = "%" Then
If lngPos + AddNum < Len(strSource) + 1 Then
strchr = CInt("&H" & Mid(strSource, lngPos + 1, AddNum))
If strchr > 130 Then
AddNum = 5
IFKor = Mid(strSource, lngPos + 1, AddNum)
IFKor = Replace(IFKor, "%", "")
strchr = CInt("&H" & IFKor )
End If
strResult = strResult & Chr(strchr)
lngPos = lngPos + AddNum
End If
Else
strResult = strResult & strTemp
End If
Next
URLDecode = strResult
End Function
'======================================================
' 사용할때,, getRefererPage 함수를 호출하면 이전 페이지 이름만 리턴합니다.
' Response.Write("refererValue : " & getRefererPage & "<br>")
'======================================================
Function getRefererPage
Dim refererValue, chkPos
' 호출한 페이지값을 받습니다.
refererValue = Request.ServerVariables("HTTP_REFERER")
' 호출한 페이지 값이 없을 경우
IF Len(refererValue) = 0 Then
getRefererPage = ""
Exit Function
End IF
' 문자열에서 마지막 '/'값의 위치를 찾습니다. Text비교
chkPos = InstrRev(refererValue, "/", -1, 1)
' 마지막 '/'값을 찾은 위치에서 마지막까지의 문자열만 추출합니다.
refererValue = Right( refererValue, Len(refererValue) - chkPos )
' 추출한 페이지이름을 리턴합니다.
getRefererPage = refererValue
End Function
'===========================================================================
'함수명 : date_db
'INPUT :
'기능설명 : System DATE -> yyyy-mm-dd
'===========================================================================
Function date_db()
v_year = year(now())
mLen = Len(month(now()))
If mLen <> 2 Then
v_month = "0" + Cstr(month(now()))
Else
v_month = Cstr(month(now()))
End If
dLen = Len(day(now()))
If dLen <> 2 Then
v_day = "0" + Cstr(day(now()))
Else
v_day = Cstr(day(now()))
End If
date_db = Cstr(v_year) + "-" + Cstr(v_month) + "-" + Cstr(v_day)
End Function
'===========================================================================
'함수명 : date_time
'INPUT :
'기능설명 : System DATE -> yyyymmddhhmmss
'===========================================================================
Function date_time()
v_year = year(date)
v_month = month(date)
if v_month < 10 then v_month = "0" & v_month
v_day = day(date)
if v_day < 10 then v_day = "0" & v_day
v_hour = hour(time)
if v_hour < 10 then v_hour = "0" & v_hour
v_minute = minute(time)
if v_minute < 10 then v_minute = "0" & v_minute
v_second = second(time)
if v_second < 10 then v_second = "0" & v_second
v_datetime = v_year&v_month&v_day&v_hour&v_minute&v_second
date_time = v_datetime
End Function
'===========================================================================
'함수명 : fncRequestVariables
'INPUT : Request명
'기능설명 :
'===========================================================================
function fncRequestVariables(varParam)
Dim p
p = ""
if ucase(varParam) = "REMOTE_ADDR" then '리모트 ip 가져와서리
p = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
if p = "" then
p = Request.ServerVariables("HTTP_CLIENT_IP")
if p = "" then '암것도 없으면 ......
p = Request.ServerVariables(varParam) 'REMOTE_ADDR 다시 받고
end if
else
'if p = "119.67.93.000" then
' p = "211.58.239.000"
'end if
end if
else
p = Request.ServerVariables(varParam) '나머지 서버 변수는 그냥사용
end if
fncRequestVariables = p
end function
%>