<%
Function Base10(strValue)
	Dim BASE32_DIGITS, limit, looper, e, d, v, calcValue

	BASE32_DIGITS = "23456789ABCDEFGHJKLMNPQRSTUVWXYZ"
	limit = Left(BASE32_DIGITS, 32)
	calcValue = UCase(strValue)
	e = Len(calcValue)
	For looper = 1 To e
		e = e - 1
		d = InStr(limit, Mid(calcValue, looper, 1)) - 1
		If d >= 0 Then
			v = v + ((32 ^ e) * d)
		Else
			Exit For
		End If
	Next
	Err.Clear
	On Error Resume Next
	Base10 = CLng(v)
	If Err Then
		Base10 = 0
	End If
	On Error GoTo 0
End Function

Function Base32(lngValue)
	Dim BASE32_DIGITS, i, calcValue, sOut, v, d

	'Converts a value from Base 10 to Base 32
	BASE32_DIGITS = "23456789ABCDEFGHJKLMNPQRSTUVWXYZ"
	calcValue = Abs(lngValue)
	i = 0
	While (32 ^ i) <= calcValue
		i = i + 1
	Wend
	If i Then i = i - 1

	While i >= 0
		v = 32 ^ i
		d = calcValue \ v
		calcValue = calcValue - (v * d)
		sOut = sOut & Mid(BASE32_DIGITS, d + 1, 1)
		i = i - 1
	Wend

	If Len(sOut) Then
		Base32 = sOut
	Else
		Base32 = 0
	End If
End Function

Function FirstLast(Nm)
	Dim tmpVar
	tmpVar = Trim(Nm)
	If Len(tmpVar) = 0 Then
		FirstLast = " "
		Exit Function
	End If
	If InStr(tmpVar, ",") Then
		tmpVar = Trim(Mid(tmpVar, InStr(tmpVar, ",") + 1)) & " " & Trim(Left(tmpVar, InStr(tmpVar, ",") - 1))
	End If
	tmpVar = Trim(tmpVar)
	If Len(tmpVar) Then
		If Instr(tmpVar, "@") = 0 Then
			tmpVar = Chr(Asc(tmpVar) And Not 32) & Mid(tmpVar, 2)
		End If
		tmpVar = Trim(tmpVar)
		If Instr(tmpVar, " ") > 0 Then
			'caps
			tmpVar = Left(tmpVar, InStr(tmpVar, " ")) & Chr(Asc(Mid(tmpVar, InStr(tmpVar, " ") + 1)) And Not 32) & Mid(tmpVar, InStr(tmpVar, " ") + 2)
		End If
	End If
	FirstLast = tmpVar
End Function

Response.Buffer = True
Response.Expiresabsolute = Now() - 1
Response.Expires = -1
Response.Clear %>

<!-- #include file="inc/get-portal-info.asp" -->

<% PublishDate = Now
BuildDate = WeekdayName(Weekday(PublishDate),true) & ", " & Day(PublishDate) & " " & MonthName(Month(PublishDate), True) & " " & Year(PublishDate) & " " & right("0" & hour(PublishDate),2) & ":" & right("0" & minute(PublishDate), 2) & ":" & right("0" & second(PublishDate), 2) & " GMT"

MeetingID = Request.QueryString("MeetingID")
If len(MeetingID) = 0 Then Response.End
MeetingID = Base10(MeetingID)

Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open "Provider=SQLOLEDB; Driver={SQL Server}; Server=172.16.1.206; Database=VOICE; UID=Bluetrain; PWD=bluetrain.202"
Set oRs = Server.CreateObject("ADODB.Recordset")
sql = "SELECT Meetings.*, Currency.Code AS CurrencyCode, Personal.Organization as Organization, Personal.Name AS HostName, Personal1.Name AS InstructorName FROM Meetings LEFT OUTER JOIN Personal ON Meetings.AccountLink = Personal.UniqueCounter LEFT OUTER JOIN Currency ON Meetings.CurrencyLink = Currency.UniqueCounter LEFT OUTER JOIN Personal Personal1 ON Meetings.InstructorLink = Personal1.UniqueCounter WHERE (Meetings.Approved = 1) AND (Meetings.RSSApproved = 1) AND (Meetings.PublicFlag = 1) AND (Meetings.UnlistedFlag = 0) AND (Meetings.RSSFlag = 1) and (MeetingID = " & MeetingID & ")"
oRs.Open sql, oConn, 0, 1

'open database and retrieve most recent enrollable events
FirstTime = True

Response.ContentType = "application/rss+xml"
Response.Write "<?xml version=""1.0"" encoding=""iso-8859-1"" ?>" & vbCrLf
Response.Write "<rss version=""2.0"" xmlns:atom=""http://www.w3.org/2005/Atom"">" & vbCrLf
Response.Write "<channel>" & vbCrLf
Response.Write "<title>" & Company & " Meetings and Events</title>" & vbCrLf
Response.Write "    <link>http://" & SubDomain & ".mybluetrain.com/webattend/list-scheduled-meetings.asp</link>" & vbCrLf
Response.Write "    <description>Live web meetings, events and courses at " & Company & ".</description>" & vbCrLf
Response.Write "    <language>en-us</language>" & vbCrLf
Response.Write "    <copyright>Copyright " & Year(Now) & " - " & CoName & "</copyright>" & vbCrLf
Response.Write "    <lastBuildDate>" & BuildDate & "</lastBuildDate>" & vbCrLf
Response.Write "    <ttl>720</ttl>" & vbCrLf
Response.Write "    <atom:link href=""http://" & SubDomain & ".mybluetrain.com/webattend/meeting.xml?MeetingID=" &  Request.QueryString("MeetingID") & """ rel=""self"" type=""application/rss+xml"" />" & vbCrLF

While not oRs.EOF
	
	Summary = trim(oRs.Fields("Summary").value)
	Summary = Replace(Summary, "&amp;", "&")
	Summary = Replace(Summary, "&", "&amp;")
	Summary = Replace(Summary, chr(34), "&quot;")
	Summary = Replace(Summary, "<", "&lt;")
	Summary = Replace(Summary, ">", "&gt;")
	Summary = Replace(Summary, vbCrLf, "  ")

	If len(Summary) = 0 Or oRs.Fields("SummaryPrivacy").value = 1 Then
		Summary = "The meeting organizer did not provide a summary decription."
	End If
	PriceFlag = oRs.Fields("PriceFlag").value
	
	EnrollmentFlag = oRs.Fields("EnrollmentFlag").value
	EnrollmentPrice = oRs.Fields("EnrollmentFee").value
	EnrollmentCurrencyCode = trim(oRs.Fields("CurrencyCode").value)
	
	OrgName = trim(oRs.Fields("Organization").value)
	
	itemTitle = OrgName
	If len(itemTitle) Then
		itemTitle = itemTitle & " - "
	End If
	If instr(lcase(trim(oRs.Fields("MeetingTitle").value)), lcase(itemTitle)) = 0 Then
		itemTitle = itemTitle & trim(oRs.Fields("MeetingTitle").value)
	Else
		itemTitle = trim(oRs.Fields("MeetingTitle").value)
	End If
	itemTitle = Replace(itemTitle, "& ", "&amp; ")
	
	Duration = oRs.Fields("Duration").value
	
	ClassSessions = oRs.Fields("ClassSessions").value
	ClassHours = oRs.Fields("TotalClassHours").value

	Select Case oRs.Fields("InstructorLink").value
		Case 0
			HostName = FirstLast(trim(oRs.Fields("HostName").value))
		Case Else
			HostName = FirstLast(trim(oRs.Fields("InstructorName").value))
	End Select
	Comment = "Meeting Host: &lt;a href=&quot;http://" & SubDomain & ".mybluetrain.com/webattend/list-scheduled-meetings.asp?MeetingID=" & Base32(oRs.Fields("MeetingID").value) & "&quot;&gt;" & HostName & "&lt;/a&gt;&lt;br&gt;"
	Comment = Comment & "Category: " & trim(oRs.Fields("Category").value)
	If ClassSessions > 1 Then
		Comment = Comment & "&lt;br&gt;" & "Session Duration: "
	Else
		Comment = Comment & "&lt;br&gt;" & "Meeting Duration: "
	End If
	If Duration = 0 Then
		Comment = Comment & " probably 60 minutes (undefined)" & "&lt;br&gt;" 
	Else
		Comment = Comment & Duration & " minutes" & "&lt;br&gt;" 
	End If
	If ClassSessions > 1 Then
		Comment = Comment & "Sessions: " & ClassSessions & "&lt;br&gt;" 
		If ClassHours > 0 Then
			Comment = Comment & "Total Hours: " & ClassHours / 100 & " hours" & "&lt;br&gt;" 
		End If
	End IF
	If PriceFlag Then
		If EnrollmentFlag Then
			Comment = Comment & "Cost: " & EnrollmentPrice & " " & EnrollmentCurrencyCode & "&lt;br&gt;" 
		Else
			Comment = Comment & "Cost: Free" & "&lt;br&gt;" 
		End If
	Else
		Comment = Comment & "Cost: Free" & "&lt;br&gt;" 
	End If
	If EnrollmentFlag = False Then
		If len(trim(oRs.Fields("Password").value)) = 0 Then
			If oRs.Fields("UnlistedFlag").value = False Then
				Comment = Comment & "Meeting Type: Public Meeting" & "&lt;br&gt;" 
			End If
		End If
	Else
		Comment = Comment & "Enrollment Required - &lt;a href=&quot;http://" & SubDomain & ".mybluetrain.com/webattend/list-scheduled-meetings.asp?MeetingID=" & Base32(oRs.Fields("MeetingID").value) & "&quot;&gt;Register Now&lt;/a&gt;&lt;br&gt;"
	End If
	Comment = Comment & "Date: " & formatDateTime(oRs.Fields("MeetingDateTime"),0) & " GMT 0"  & "&lt;br&gt;" & "&lt;br&gt;"
	If isNull(oRs.Fields("PublishDate").value) Then
		PublishDate = Now
		BuildDate = WeekdayName(Weekday(PublishDate),true) & ", " & Day(PublishDate) & " " & MonthName(Month(PublishDate), True) & " " & Year(PublishDate) & " " & right("0" & hour(PublishDate),2) & ":" & right("0" & minute(PublishDate), 2) & ":" & right("0" & second(PublishDate), 2) & " GMT"
	Else
		PublishDate = oRs.Fields("PublishDate").value
		BuildDate = WeekdayName(Weekday(PublishDate),true) & ", " & Day(PublishDate) & " " & MonthName(Month(PublishDate), True) & " " & Year(PublishDate) & " " & right("0" & hour(PublishDate),2) & ":" & right("0" & minute(PublishDate), 2) & ":" & right("0" & second(PublishDate), 2) & " GMT"
	End If

	Response.Write "    <item>" & vbCrLf
	Response.Write "        <title>" & itemTitle & "</title>" & vbCrLf
	Response.Write "        <description>" & Comment & Summary & "</description>" & vbCrLf
	Response.Write "        <pubDate>" & BuildDate & "</pubDate>" & vbCrLf
	Response.Write "        <link>http://" & SubDomain & ".mybluetrain.com/webattend/list-scheduled-meetings.asp?MeetingID=" & Base32(oRs.Fields("MeetingID").value) & "</link>" & vbCrLf
	Response.Write "        <guid isPermaLink=""true"">http://" & SubDomain & ".mybluetrain.com/webattend/list-scheduled-meetings.asp?MeetingID=" & Base32(oRs.Fields("MeetingID").value) & "</guid>" & vbCrLf
	Response.Write "        <category>" & trim(oRs.Fields("Category").value) & "</category>" & vbCrLf
	If len(OrgName) Then
		HostName = HostName & " - " & OrgName
	End If
	Response.Write "        <author>noreply@mybluetrain.com (" & HostName & ")</author>" & vbCrLf
	Response.Write "    </item>" & vbCrLf
	oRs.MoveNext
Wend
oRs.Close
Set oRs = Nothing
oConn.Close
Set oConn = Nothing

Response.Write "</channel>" & vbCrLf
Response.Write "</rss>" & vbCrLf %>