<?xml version="1.0" encoding="iso-8859-1"?>

<rss version="0.91">
<channel>
<%
' Write out the Channel Title tag, Channel Title Link (URL)
' tag, Channel Description tag, Channel Language tag, Start
' Image Data tag, Image ALT Text tag, Image Location (URL) tag,
' Image Link (URL) tag and End Image Data tag.
' Change the information within these tags to suit your
' website.



%>


<%
' this function http://www.expertsforge.com/Web-Development/Tutorial-47.asp
' returns a date in the convert to format a normal Date into RFC-822 Format Date in ASP
' call function with document write for return_RFC822_Date("19/03/2003", "GMT") or
' return_RFC822_Date(Now(), "GMT")

Function return_RFC822_Date(myDate, offset)
	Dim myDay, myDays, myMonth, myYear
	Dim myHours, myMonths, mySeconds

	myDate = CDate(myDate)
	myDay = WeekdayName(Weekday(myDate),true)
	myDays = Day(myDate)
	myMonth = MonthName(Month(myDate), true)
	myYear = Year(myDate)
	myHours = zeroPad(Hour(myDate), 2)
	myMinutes = zeroPad(Minute(myDate), 2)
	mySeconds = zeroPad(Second(myDate), 2)
	
	return_RFC822_Date = myDay&", "& _
		myDays&" "& _
		myMonth&" "& _ 
		myYear&" "& _
		myHours&":"& _
		myMinutes&":"& _
		mySeconds&" "& _ 
		offset
End Function 
Function zeroPad(m, t)
	zeroPad = String(t-Len(m),"0")&m
End Function
%>
<!-- #include virtual="/webtools/publicfunctions/inc-functions.asp" -->
<title>UCLA Institute of the Environment and Sustainability News</title>
<link>http://www.environment.ucla.edu</link>
<description>Everything we do now matters.</description>
<language>en-us</language>
<image>
    <title>UCLA Institute of the Environment and Sustainability</title>
    <url>http://www.environment.ucla.edu/images/apple-itunes-icon.jpg</url>
    <link>http://www.environment.ucla.edu/</link>
    </image>

<%
' We are now ready to connect to the database and retrieve the
' last articles published. RSS 0.91 allows up to 15.

' Setup and open a connection to the database.
' You wll need to modify the database connection to
' reflect your database.

   
   Set objConn = Server.CreateObject ("ADODB.Connection")
   objConn.Open = ConnectionString
   

' Setup a RecordSet to store the results from our SQL Query.
   Set rssRS = Server.CreateObject("ADODB.Recordset")

' Execute some SQL against the Database and store the results
' in artRec.



SectionID = 1
if not isnumeric(SectionID) then SectionID  = null 
	If IsNumeric(SectionID) AND (NOT IsEmpty(SectionID)) Then
		SectionSQL = " AND tbl_ArticleInfo.Center_ID = " & SectionID
	End If


TypeID = 1
if not isnumeric(TypeID) then TypeID = null 

	If IsNumeric(TypeID) AND (NOT IsEmpty(TypeID)) Then
		TypeSQL = " AND tbl_ArticleInfo.Type_ID = " & TypeID
	End If





   set rssRS = objConn.execute("Select Top 15 tbl_ArticleInfo.Title, tbl_ArticleInfo.parent_ID, tbl_ArticleInfo.Abstract, tbl_ArticleInfo.PublishedOn, tbl_Articles.ArticleDate From tbl_ArticleInfo, tbl_Articles WHERE tbl_Articles.Article_ID = tbl_ArticleInfo.Article_ID AND PublishedOn <> '' AND PublishedOn Is Not Null AND PublishedOn <> '1/1/1900'" & SectionSQL & TypeSQL & " ORDER BY ArticleDate DESC")



  'set rssRS = objConn.execute("Select Top 25 Title, parent_ID, Abstract, PublishedOn From tbl_ArticleInfo WHERE PublishedOn <> '' AND PublishedOn Is Not Null AND PublishedOn <> '1/1/1900'" & SectionSQL & TypeSQL & " ORDER BY CreatedOn DESC, Title")

' Set a variable to 0, which will be used to count how many
' times we loop through the recordset.
   x=0

' Loop through the recordset to retrieve our rows of data.
   while not rssRS.eof

' In this example we only want the last 6 articles.
' Starting at 0 when x reaches 6 it will exit the loop.
   if x<15 then

' The next 5 lines simply write out the remaining chunks of XML
' to complete the RSS file.

' Remember if your query string contains "&" it must be written
' as "&amp;".
   response.write "<item>" & vbcrlf
   response.write "<title>" & rssRS("Title") &"</title>" & vbcrlf
   response.write "<description>"& Server.HTMLEncode(rssRS("Abstract")) & "</description>" & vbcrlf
   response.write "<link>http://www.environment.ucla.edu/news/article.asp?parentid="& rssRS("parent_ID") &"</link>" & vbcrlf
   'response.write "<pubDate>" & rssRS("PublishedOn") &"</pubDate>" & vbcrlf
   response.write "<pubDate>" & return_RFC822_Date(rssRS("PublishedOn"), "PDT") & "</pubDate>" & vbcrlf
   response.write "</item>" & vbcrlf

   end if

' Increment the counter by 1 eachtime the loop goes round
   x=x+1

' Loop
   rssRS.movenext
   wend

' Close the database connections and set the recordset equal to
' nothing
   set rssRS = nothing
   objConn.close
   set objConn = nothing
' Write out the End Channel Data tag and End RSS tag.
%>
</channel>
</rss>