<!--#include virtual = "/common/lib/dbcon.asp" -->
<!--#include virtual = "/common/lib/func.asp" -->
<% 
dim cprCon
set cprCon = Server.CreateObject("ADODB.Connection")
cprCon.Open "Driver={MySQL ODBC 8.0 Unicode Driver}; Server=175.126.77.226; Database=home_cprknuh_201512; Uid=cpr;Pwd=cprknuh;"
if cprCon.errors.count = 0 then
  response.write "Connected Successfully!"
end if


sql = "SELECT s_num, s_yy, s_mm, s_type, s_phone FROM sms_send WHERE (s_result='' or s_result='-2') order by s_num"
Set sms_rs = cprCon.Execute(sql)
If sms_rs.bof Or sms_rs.eof Then
	sms_data1 = Null
Else
	sms_data1 = sms_rs.getrows
End If
Set sms_rs = Nothing
'-------------------개인주소록 리스트 끝-----------------------


'이틀전꺼 결과값 없는거는 실패처리
sql = "UPDATE sms_send SET s_result='2' WHERE s_senddate < date_add(curdate(), interval -2 day) and s_result='' "
cprCon.execute sql

If Not(IsNull(sms_data1)) Then
	For i = 0 To UBound(sms_data1, 2)

		s_num		= Replace(sms_data1(0,i)," ","")
		s_yy			= Replace(sms_data1(1,i)," ","")
		s_mm		= Replace(sms_data1(2,i)," ","")
		s_type		= Replace(sms_data1(3,i)," ","")
		s_phone	= Replace(sms_data1(4,i)," ","")

		s_type		= UCase(s_type)

		'월별 테이블에서 조회..
		If s_type = "VMS" Then

			'월별
			y_month = Mid(s_yy, 3, 4)&Right( "0" & s_mm, 2)
			If y_month = "" Then ' 없으면 초기화
				y_month = Mid(getDateFm(Now(), 6), 3, 4)
			End If
			'월별 테이블에서 조회..
			sql = " SELECT JOB_ID FROM SDK_VMS_REPORT_"&y_month&" WHERE USER_ID='cprknuh' and RESERVED2='"&s_num&"' AND dest_info like'%"& s_phone &"%' "
			Set Rs = Dbcon.Execute (sql)
			If rs.eof Then
			Else
				sql = " SELECT TCS_RESULT FROM SDK_VMS_REPORT_DETAIL_"&y_month&" WHERE USER_ID='cprknuh' and JOB_ID='"&Rs("JOB_ID")&"' AND RESULT not in(0,1) "
				Set Rs_R = Dbcon.Execute (sql)
				If Rs_R.eof Then
				Else
				result = Rs_R("TCS_RESULT")

				'결과값 업데이트 
				sql = " UPDATE sms_send SET s_result='"&result&"' WHERE s_num='"&s_num&"' "
				cprCon.execute sql
				End If 
				Rs_R.close : Set Rs_R = Nothing
			End If
			rs.close : Set rs = Nothing

		ElseIf s_type = "LMS" Then
			'월별
			y_month = Mid(s_yy, 3, 4)&Right( "0" & s_mm, 2)
			If y_month = "" Then ' 없으면 초기화
				y_month = Mid(getDateFm(Now(), 6), 3, 4)
			End If
			'월별 테이블에서 조회..
			sql = " SELECT JOB_ID FROM SDK_MMS_REPORT_"&y_month&" WHERE USER_ID='cprknuh' and RESERVED1='situation' and RESERVED2='"&s_num&"' AND dest_info like'%"& s_phone &"%' "
			Set Rs = Dbcon.Execute (sql)
			If rs.eof Then
			Else
				sql = " SELECT TCS_RESULT FROM SDK_MMS_REPORT_DETAIL_"&y_month&" WHERE USER_ID='cprknuh' and JOB_ID='"&Rs("JOB_ID")&"' "
				Set Rs_R = Dbcon.Execute (sql)
				If Rs_R.eof Then
				Else
				result = Rs_R("TCS_RESULT")

				'결과값 업데이트 
				sql = " UPDATE sms_send SET s_result='"&result&"' WHERE s_num='"&s_num&"' "
				cprCon.execute sql
				End If 
				Rs_R.close : Set Rs_R = Nothing
			End If
			rs.close : Set rs = Nothing

		Else
			'월별
			y_month = s_yy&Right( "0" & s_mm, 2)
			If y_month = "" Then ' 없으면 초기화
				y_month = getDateFm(Now(), 6)
			End If

			sql = " SELECT TRAN_RSLT FROM em_log_"&y_month&" WHERE TRAN_ID='cprknuh' and TRAN_ETC2='"&s_num&"' "
			Set Rs = Dbcon.Execute (sql)
			If rs.eof Then
			Else
				'결과값 업데이트 
				sql = " UPDATE sms_send SET s_result='"&Rs("TRAN_RSLT")&"' where s_num='"&s_num&"' "
				cprCon.execute sql
			End If
			rs.close : Set rs = Nothing
		End If 
	Next
End If

cprCon.close
set cprCon = Nothing
%>