<%
'	************************************************************************
'	* ASP-Nuke: Free web portal in ASP                                     *
'	************************************************************************
'	* Copyright (c) 2002-2003 by Gaetan Bouveret (webmaster@asp-nuke.net)  *
'	* http://www.asp-nuke.net                                              *
'	*                                                                      *
'	* This program is free software. You can redistribute it and/or modify *
'	* it under the terms of the GNU General Public License as published by *
'	* the Free Software Foundation; either version 2 of the License, or    *
'	* (at your option) any later version.                                  *
'	*                                                                      *
'	* News-inc.asp file modified by InKey @ LinkUps.Org                    *
'	*                                                                      *
'	************************************************************************
%>
<%
Function CalcWords(ByVal sText)
	Dim tTemp, result
	CalcWords=0
	IF IsNull(sText) THEN EXIT FUNCTION

	tTemp = sText&""
	tTemp = Trim(HTML2Flat(tTemp))
	tTemp = replace(tTemp,vbNewLine," ")
	DO WHILE instr(tTemp, "  ")>0
		tTemp = replace(tTemp,"  ", " ")
	LOOP
	tTemp = Split(tTemp, " ")

	If IsArray(tTemp) Then 
		result = Ubound(tTemp) + 1
	Else
		result = 0
	End If
	CalcWords = result
End Function

	' Display a news
	' IN  : iID (int) : news' id (table news, field nID)
	'     : bFull (boolean) : if news if fully displayed (header + text)
	'     : bCountIt (boolean) : if it's the first time user read it
	'     : bPrintIt (boolean) : If true, make EastPrintable News
	' OUT : -
	Sub DisplayNews(iID, bFull, bCountIt, bPrintIt)
		Dim oRs, oRs2, rSQL, sURL, tURL, tTemp, iNbWords, NewsDate, sHTML

	'	rSQL =	"SELECT nID, nTitle, nAuthor, nDate, nHeader, nText, nImage, nURL, nRead, nCategory, cTitle, cImage, vCode" & _
		rSQL =	"SELECT * FROM news, categories, versions" & _
				" WHERE nCategory=cID AND nVersion=vID AND nValid=True AND nID=" & SQLEncrypt(iID)

		Set oRs = DBRecordSet(oCnMain, rSQL)
		If Not oRs.EOF Then
			NewsDate = GMT2Local(StringToDate(oRs("nDate")))
			Response.Write "<a name=""news_" & oRs("nID") & """></a>" & vbCRLF

			If bPrintIt Then
				Response.Write "<table width=""100%"" border=0>" & vbCrLf
				Response.Write "<tr><td align=center>"
				Response.Write CodeMessage(oRs("nTitle"), True)
				Response.Write "</td></tr>" & vbCrLf
				Response.Write "<tr><td>" & vbCrLf
			Else
				AllowCollapsTable false
				CreateTopTable "news_" & oRs("nID"), CodeMessage(oRs("nTitle"), True) & IIF(oRs("nTagged")," | " & GetTranslation("LANG_POST_STICKED"),"")
			End IF

			response.write "<table border=""0"" width=""100%"" align=""center"" cellspacing=""0"" cellpadding=""0""><tr>"
			response.write "<td align=""center"" valign=""top"" class=""myTD"">" 
			if oRs("cImage")&"" <> "" Then
				response.write "<img src='" & TestImageExt(oRs("cImage")) & "' width='32' alt='" & oRs("cTitle")& "'>"
			End IF
			response.write "</td>" & vbCRLF
			response.write "<td width=""100%"" align=""left"" valign=""top"" class=""myTD"">" & vbCRLF
			response.write "<B>" & oRs("cTitle") & "</B>" & vbCRLF

			If DateDiff("d", NewsDate, LocalDate())<cInt(SysParmDef("News.NewDays", 5)) Then
				Response.Write " <span class='NewNews'>" & GetTranslation("LANG_NEWNEWS") & "</span>" & vbCRLF
			End if
			Response.Write "<BR>" & vbCrLf
			
			Response.Write "<span class=""small"">" & Replace(Replace(GetTranslation("LANG_POST_DATE_BY"), "%1%", _
							GetDateLitteralDDMMYYYYHHMMSS(GMT2Local(  StringToDate(oRs("nDate"))))), "%2%", _
							"<a href=""" & GLOBAL_SITE_PATH & GLOBAL_SITE_PROFILE_PAGE & "?id=" & Server.URLEncode(oRs("nAuthor")) & """>" & _
							oRs("nAuthor") & "</a>")
			If oRs("nURL") <> "" Then
				'sURL = Replace(oRs("nURL"), "http://", "",1,999,1)
				sURL = cStr(oRs("nURL")&"")
				rSQL = "SELECT uTitle FROM urls WHERE uURL LIKE '%" & SQLEncrypt(Replace(oRs("nURL"), "http://", "",1,-1,1)) & "%'"
				Set oRs2 = DBRecordSet(oCnMain, rSQL)
				Response.Write " | " & GetTranslation("LANG_SOURCE") & " : <a href=""" & _
						GLOBAL_SITE_PATH & GLOBAL_SITE_GOTOURL_PAGE & "?url=" & _
						Server.URLEncode(sURL) & """ target=""_blank"">"
				If Not oRs2.EOF Then
					Response.Write oRs2("uTitle")
				Else
					tURL = Split(Replace(oRs("nURL"), "http://", "",1,-1,1), "/")
					Response.Write tURL(0)
				End If
				Response.Write "</a>" & vbCRLF
			End If
			If Not bPrintIt Then
				Response.Write "| " & AddPopUpPrint(CATEGORY_TYPE_NEWS, iID, 0, true) & vbCrLf
				Response.Write "" & AddSend2Friend(GLOBAL_SITE_URL & GLOBAL_SITE_PATH & GLOBAL_SITE_NEWS_PAGE & "?id=" & iID, CodeMessage(oRs("nTitle"), True)) & vbCrLf
			End If

			Response.Write "<hr size=""1"" width=""100%"" color=""#D7DCE2""></span>" & vbCRLF
			Response.Write "</td>" & vbCRLF
			Response.Write "</tr>" & vbCRLF
			Response.Write "<tr>" & vbCRLF
			Response.Write "<td colspan=""2"" align=""left"" valign=""top"" class=""myTD"">" & vbCRLF
			Response.Write "<span class=""normal"">" & vbCRLF

			If oRs("nImage") <> "" Then 
				Response.Write "<img src='"
				If Left(LCase(oRs("nImage")), 7) <> "http://" Then Response.Write GLOBAL_SITE_IMAGES_NEWS_PATH 
				Response.Write oRs("nImage") & "' align='left' border='0'>" & vbCRLF
			End If

			Response.Write "" & CodeMsg(oRs("nHeader"), False) & vbCRLF '& "<BR>" 
			If bFull Then
				Response.Write "</td></tr>" & vbCRLF
				Response.Write "<tr>" & vbCRLF
				Response.Write "<td colspan=""2"" class=""myTD"">" & vbCRLF
				Response.Write "<span class=""normal"">" & vbCRLF
				Response.Write "<hr size=""1"" width=""100%"" color=""#D7DCE2"">" & vbCRLF
				Response.Write CodeMsg(oRs("nText"), False) & vbCRLF
				
				If bCountIt Then
					rSQL = "UPDATE news SET nRead=" & oRs("nRead")+1 & " WHERE nID=" & SQLEncrypt(iID)
					DBExecute oCnMain, rSQL
				End If
			End If
			response.write "</td></tr>" & vbCRLF
			response.write "</table>" & vbCRLF

			If bFull Then
				If bCountIt then
					sHTML = GetTranslation("LANG_READ") & " : " & oRs("nRead")+1
				Else
					sHTML = GetTranslation("LANG_READ") & " : " & oRs("nRead")
				End If
				If bPrintIt Then
					Response.Write "<center>" & sHTML & "</center>" & vbCrLf
					Response.Write "</td></tr></table>" & vbCrLf
				Else
					CreateBottomTable sHTML & " | <a href=""" & GLOBAL_SITE_PATH & "Default.asp"">" & GetTranslation("LANG_BACK") & "</a>"
				End If
			Else
				rSQL = "SELECT Count(cID) FROM Comments WHERE cItem=" & SQLEncrypt(iID) & " AND cType=" & CATEGORY_TYPE_NEWS & " AND cValid=True"
				Set oRs2 = DBRecordSet(oCnMain, rSQL)

			'	tTemp = Split(oRs("nText")&"")
			'	If IsArray(tTemp) Then 
			'		iNbWords = Ubound(tTemp) + 1
			'	Else
			'		iNbWords = 0
			'	End If
				iNbWords = CalcWords(oRs("nText"))

				Response.Write "<BR>" & vbCRLF
				Response.Write "<table class=""myTable"" align=""center"" width=""100%"">" & vbCRLF
				Response.Write "	<tr>" & vbCRLF
				Response.Write "		<td width=""33%"" align=""left"">" & vbCRLF
				If iNbWords = 0 Then
					Response.Write "			&nbsp;" & vbCRLF
				Else
					Response.Write "			<a href=""" & GLOBAL_SITE_PATH & GLOBAL_SITE_NEWS_PAGE & "?id=" & iID & """>" & vbCRLF
					Response.Write "			<B>" & GetTranslation("LANG_READ_MORE") & "</B></a>" & vbCRLF
					Response.Write "			<small> (" & Replace(GetTranslation("LANG_READ_MORE_WORDS"), "%1%", iNbWords) & ")</small>" & vbCRLF
				End IF
				Response.Write "		</td>" & vbCRLF
				response.write "		<td width=""33%"" align=""center"">"
			'	Response.Write ShowBullet(GLOBAL_SITE_THEMES_PATH & sTheme & "/comment.gif")
			'	response.write "<img src=""" & GLOBAL_SITE_THEMES_PATH & sTheme & "/comment.gif"" align=""absmiddle""border=""0"">"
				response.write "&nbsp;&nbsp;<a class=""small"" href=""" & GLOBAL_SITE_NEWS_PAGE & "?id=" & iID & """>" & GetTranslation("LANG_COMMENTS") & "</a><small> : " & oRs2(0) & "</small>"
			'	Response.Write "			" & AddPopUpPrint(CATEGORY_TYPE_NEWS, iID, 0, true) & vbCrLf
				Response.Write "		</td>" & vbCRLF
				response.write "		<td width=""33%"" align=""right"">" & vbCrLf
				Response.Write "			<small>" & GetTranslation("LANG_READ") & " : " & oRs("nRead") & "</small>"
				Response.Write "		</td>" & vbCrLf
				Response.Write "	</tr>" & vbCrLf
				Response.Write "</table>" & vbCRLF

				If bPrintIt Then
					Response.Write "</td></tr></table>" & vbCrLf
				Else
					CreateBottomTable ""
				End If
			End If
		Else
			CreateTable "News", GetTranslation("LANG_NEWS"), GetTranslation("LANG_EMPTY_SECTION"), ""
		End If

		Set oRs = Nothing
		Set oRs2 = Nothing
	End Sub

	' Display all current daily news for a special date
	' IN  : iID (int) : news' id (table news, field nID)
	'     : iCategory : news' category (table news, field nCategory)
	'     : bFull (boolean) : display all news (header + body) if true, just header if false
	' OUT : -
	Sub DisplayNewsDate(dDate, iCategory, bFull)
		Dim oRs, oRs2, rSQL, sURL, tURL, iNewsID

		rSQL =	"SELECT nID, nTitle, nAuthor, nDate, nHeader, nText, nImage, nURL, nRead, nCategory, cTitle, vCode" & _
				" FROM news, categories, versions" & _
				" WHERE nValid=True AND nCategory=cID AND nVersion=vID AND Left(nDate,8) LIKE '" & DateToString(dDate) & "%'"
		If sXMLVersion <> "" Then
			rSQL = rSQL & " AND (nVersion=" & iXMLVersion & " OR nVersion=0)"
		End If
		If iCategory <> "" and iCategory <> 0 Then rSQL = rSQL & " AND nCategory=" & SQLEncrypt(iCategory)

		Set oRs = DBRecordSet(oCnMain, rSQL)
		While Not oRs.EOF
			iNewsID = oRs("nID")
			Response.Write "	  <a name=""news_" & iNewsID & """></a>" & vbCRLF
			CreateTopTable "news_" & iNewsID, CodeMessage(oRs("nTitle"), False)
			Response.Write "<span class=""small"">" & Replace(Replace(GetTranslation("LANG_POST_DATE_BY"), _
							"%1%", GetDateLitteralDDMMYYYYHHMMSS(GMT2Local(StringToDate(oRs("nDate"))))), _
							"%2%", "<a href=""" & GLOBAL_SITE_PATH & GLOBAL_SITE_PROFILE_PAGE & "?id=" & Server.URLEncode(oRs("nAuthor")) & """>" & oRs("nAuthor") & "</a>")
			Response.Write " " & oRs("vCode") & " - <a href=""" & GLOBAL_SITE_NEWS_PAGE & "?cat=" & oRs("nCategory") & """>" & oRs("cTitle") & "</a>"
			If oRs("nURL") <> "" Then
				sURL = Replace(LCase(oRs("nURL")), "http://", "")
				rSQL = "SELECT uTitle FROM urls WHERE uURL LIKE '%" & SQLEncrypt(sURL) & "%'"
				Set oRs2 = DBRecordSet(oCnMain, rSQL)
				Response.Write "<br>" & GetTranslation("LANG_SOURCE") & " : <a href=""" & GLOBAL_SITE_PATH & GLOBAL_SITE_GOTOURL_PAGE & "?url=http://" & sURL & """ target=_blank>"
				If Not oRs2.EOF Then
					Response.Write oRs2("uTitle")
				Else
					tURL = Split(sURL, "/")
					Response.Write tURL(0)
				End If
				Response.Write "</a>" & vbCRLF
			End If
			Response.Write "</span><br><br>" & vbCRLF

			If oRs("nImage") <> "" Then 
				Response.Write "<img src="""
				If Left(LCase(oRs("nImage")), 7) <> "http://" Then Response.Write GLOBAL_SITE_IMAGES_NEWS_PATH 
				Response.Write oRs("nImage") & """ align=""left"" border=""0"">" & vbCRLF
			End If

			Response.Write CodeMessage(oRs("nHeader"), False) & vbCRLF
			If bFull Then
				Response.Write "<br><br>" & vbCRLF
				Response.Write CodeMessage(oRs("nText"), False) & vbCRLF
				
				rSQL = "UPDATE news SET nRead=" & oRs("nRead")+1 & " WHERE nID=" & iNewsID
				DBExecute oCnMain, rSQL
			End If
			rSQL = "SELECT Count(cID) FROM Comments WHERE cItem=" & iNewsID & " AND cType=" & CATEGORY_TYPE_NEWS & " AND cValid=True"
			Set oRs2 = DBRecordSet(oCnMain, rSQL)
			If bFull Then
				CreateBottomTable "<a href=""" & GLOBAL_SITE_NEWS_PAGE & "?id=" & iNewsID & """>" & GetTranslation("LANG_COMMENTS") & " : " & oRs2(0) & "</a> | " & GetTranslation("LANG_READ") & " : " & oRs("nRead")+1 & " | <a href=""" & "Default.asp"">" & GetTranslation("LANG_BACK") & "</a>" & vbCRLF
			Else
				CreateBottomTable "<a href=""" & GLOBAL_SITE_NEWS_PAGE & "?id=" & iNewsID & """>" & GetTranslation("LANG_COMMENTS") & " : " & oRs2(0) & "</a> | " & GetTranslation("LANG_READ") & " : " & oRs("nRead") & " | <a href=""" & GLOBAL_SITE_NEWS_PAGE & "?id=" & iNewsID & """>" & GetTranslation("LANG_READ_MORE") & "</a>" & vbCRLF
			End If
			
			oRs.MoveNext
		WEnd

		Set oRs = Nothing		
	End Sub

	' Display the top news (for one category)
	' IN  : iTop (int) : number of results wanted
	' IN  : iCategory (int) : category's wanted (0 if all)
	' OUT : -
	Sub DisplayTopNews(iTop, iCategory)
		Dim oRs, rSQL
		Dim titreNews, texteNews, dateNews

		rSQL =	"SELECT " & SQLtop(iTop) & " nID" & _
				" FROM news, versions" & _
				" WHERE nValid=True" & _
				" AND nVersion=vID" & _
				" AND (nDate<='" & DateTimeToString(GMTNow()) & "')" & _
				" AND ((nEndDate IS NULL) OR (nEndDate = '') OR (nEndDate>='" & DateTimeToString(GMTNow()) & "'))"
		If sXMLVersion <> "" Then rSQL = rSQL & " AND (nVersion=" & iXMLVersion & " OR nVersion=0)"
		If iCategory <> "" and iCategory <> 0 Then rSQL = rSQL & " AND (nCategory=" & SQLEncrypt(iCategory) & ")"
		rSQL = rSQL & " ORDER BY nTagged, nDate DESC"

		Set oRs = DBRecordSet(oCnMain, rSQL)
		If Not oRs.EOF Then
			While Not oRs.EOF
				DisplayNews oRs(0), False, False, False
				oRs.MoveNext
			WEnd
		End If

		Set oRs = Nothing		
	End Sub

	' Display the top news list (links to news)
	' IN  : iTop (int) : number of results wanted
	'     : iCategory (int) : news' category (table news, field nCategory)
	' OUT : -
	Sub DisplayTopNewsLinks(iTop, iCategory)
		Dim oRs, rSQL
		Dim titreNews, texteNews, dateNews, sCategory, sTitleCat, NewsDate

		If iCategory <> "" and iCategory <> 0 Then 
			sCategory = "?cat=" & iCategory
			rSQL = "SELECT cTitle FROM categories WHERE cID=" & iCategory
			Set oRs = DBRecordSet(oCnMain, rSQL)
			If Not oRs.EOF Then sTitleCat = " - " & oRs(0)
		End If

		rSQL =	"SELECT " & SQLtop(iTop) & " *" & _
				" FROM news" & _
				" WHERE nValid=TRUE AND nDate<='" & DateTimeToString(GMTNow()) & "'" & _
				" AND ((nEndDate IS NULL) OR (nEndDate = '') OR (nEndDate>='" & DateTimeToString(GMTNow()) & "'))"
		If sXMLVersion <> "" Then rSQL = rSQL & " AND (nVersion=" & iXMLVersion & " OR nVersion=0)"
		If sCategory <> "" Then rSQL = rSQL & " AND nCategory=" & iCategory
		rSQL = rSQL & " ORDER BY nTagged, nDate DESC"
	'	DebugPrint rSQL

		Set oRs = DBRecordSet(oCnMain, rSQL)

		CreateTopTable "TopNewsLinks", GetTranslation("LANG_TOP") & " " & iTop & " - " & GetTranslation("LANG_NEWS") & sTitleCat
		If Not oRs.EOF Then
			While Not oRs.EOF
				NewsDate = GMT2Local( StringToDate(oRs("nDate")))
				Response.Write "<a href='" & GLOBAL_SITE_NEWS_PAGE & sCategory & "#news_" & Left(oRs("nID"),8) & "'>" & CodeMessage(oRs("nTitle"), False) & "</a> " & vbCRLF
				If DateDiff("d", NewsDate, LocalDate())<cInt(SysParmDef("News.NewDays", 5)) then
				'	Response.Write " <span class=""pri""><B><font color=""red"">!" & GetTranslation("LANG_NEW") & "!</font></B></span><BR>" & vbCRLF
					Response.Write " <span class='NewNews'>" & GetTranslation("LANG_NEWNEWS") & "</span>" & vbCRLF
				End if
				Response.Write " <span class='small'>" & GetDateLitteralDDMMYYYY(GMT2Local( StringToDate(oRs("nDate")))) & "</span><BR>" & vbCRLF
				oRs.MoveNext
			WEnd
		Else
			Response.Write GetTranslation("LANG_EMPTY_SECTION")
		End If
		CreateBottomTable ""
		Set oRs = Nothing		
	End Sub


	' Display random old news list (links to news)
	' IN  : iTop (int) : number of results wanted
	'     : iCategory (int) : news' category (table news, field nCategory)
	' OUT : -
	Sub DisplayRandomNewsLinks(iTop, iCategory)
		Dim oRs, rSQL, tNewsArr, X
		Dim titreNews, texteNews, dateNews, sCategory, sTitleCat, NewsDate

		If Not IsNumeric(iTop) Then iTop = 0
		If iTop = 0 Then iTop = 1

		If iCategory <> "" and iCategory <> 0 Then 
			sCategory = "?cat=" & iCategory
			rSQL = "SELECT cTitle FROM categories WHERE cID=" & iCategory
			Set oRs = DBRecordSet(oCnMain, rSQL)
			If Not oRs.EOF Then sTitleCat = " - " & oRs(0)
		End If

		' Special SQL statement, only the Criteria in this one, 
		' as the MakeRandomTop uses the full table as result
		rSQL =	" nValid=TRUE AND nDate<='" & DateTimeToString(GMTNow()) & "'"
		If sXMLVersion <> "" Then rSQL = rSQL & " AND (nVersion=" & iXMLVersion & " OR nVersion=0)"
		If sCategory <> "" Then rSQL = rSQL & " AND nCategory=" & iCategory

		tNewsArr = MakeRandomTop(iTop, "news", "nID", rSQL)
		CreateTopTable "TopRandomNewsLinks", GetTranslation("LANG_RANDOM_NEWS") & sTitleCat
		If UBound(tNewsArr)=0 And tNewsArr(0)=0 Then
			Response.Write GetTranslation("LANG_EMPTY_SECTION") & vbCrLf
		Else
			rSQL =	"SELECT * FROM news WHERE nID IN (0,"
			For X = 0 To UBound(tNewsArr)
				If tNewsArr(X)<>0 Then
					If X>0 Then rSQL = rSQL & ","
					rSQL = rSQL & tNewsArr(X)
				End IF
			Next
			rSQL = rSQL & ")"
			DebugPrint rSQL
			Set oRs = DBRecordSet(oCnMain, rSQL)
			Do While NOT oRs.EOF
				NewsDate = GMT2Local(StringToDate(oRs("nDate")))
				Response.Write DebugWrite(oRs("nID")&":")
				Response.Write "<a href='" & GLOBAL_SITE_NEWS_PAGE & "?id=" & oRs("nID") & "'>" & CodeMessage(oRs("nTitle"), False) & "</a> " & vbCrLf
				If DateDiff("d", NewsDate, LocalDate())<cInt(SysParmDef("News.NewDays", 5)) then
					Response.Write " <span class='NewNews'>" & GetTranslation("LANG_NEWNEWS") & "</span>" & vbCrLf
				End if
				Response.Write " <span class='small'>" & GetDateLitteralDDMMYYYY(NewsDate) & "</span><BR>" & vbCrLf
				oRs.MoveNext
			Loop

		'	Response.Write "<hr>"
		'	For X = 0 To UBound(tNewsArr)
		'		If tNewsArr(X)<>0 Then
		'			rSQL =	"SELECT * FROM news WHERE nID=" & tNewsArr(X)
		'			Set oRs = DBRecordSet(oCnMain, rSQL)
		'			If Not oRs.EOF Then
		'				Response.Write oRs("nID")&":"
		'				NewsDate = GMT2Local(StringToDate(oRs("nDate")))
		'				Response.Write "<a href='" & GLOBAL_SITE_NEWS_PAGE & "?id=" & oRs("nID") & "'>" & CodeMessage(oRs("nTitle"), False) & "</a> " & vbCrLf
		'				If DateDiff("d", NewsDate, LocalDate())<cInt(SysParmDef("News.NewDays", 5)) then
		'					Response.Write " <span class='NewNews'>" & GetTranslation("LANG_NEWNEWS") & "</span>" & vbCrLf
		'				End if
		'				Response.Write " <span class='small'>" & GetDateLitteralDDMMYYYY(NewsDate) & "</span><BR>" & vbCrLf
		'			End If
		'		End If
		'	Next
		End IF
		CreateBottomTable ""
		
		Set oRs = Nothing		
	End Sub



	' Display the navigation bar for news (previous and next day)
	' IN  : dDate (datetime) : actual date
	'     : iCategory (int) : news' category (table news, field nCategory)
	' OUT : -
	Sub DisplayNewsNavigation(dDate, iCategory)
		Dim oRs, rSQL, jPrec, jSuiv, X, sCategory

		If iCategory <> "" and iCategory <> 0 Then sCategory = "&cat=" & iCategory

		rSQL = "SELECT " & SQLtop(1) & " nDate FROM news, versions WHERE nVersion=vID AND nDate <='" & DateToString(dDate) & "' AND nValid<>0"
		If sXMLVersion <> "" Then rSQL = rSQL & " AND (nVersion=" & iXMLVersion & " OR nVersion=0)"
		If sCategory <> "" Then rSQL = rSQL & " AND nCategory=" & iCategory
		rSQL = rSQL & " ORDER BY nDate DESC"
		
		Set oRs = DBRecordSet(oCnMain, rSQL)
		If Not oRs.EOF Then jPrec = Left(oRs(0), 8)

		rSQL = "SELECT " & SQLtop(1) & " nDate FROM news, versions WHERE nVersion=vID AND nDate>'" & DateToString(DateAdd("d", 1, dDate)) & "' AND nValid<>0"
		If sXMLVersion <> "" Then rSQL = rSQL & " AND vCode='" & sXMLVersion & "'"
		If sCategory <> "" Then rSQL = rSQL & " AND nCategory=" & iCategory
		rSQL = rSQL & " ORDER BY nDate"

		Set oRs = DBRecordSet(oCnMain, rSQL)
		If Not oRs.EOF Then jSuiv = Left(oRs(0), 8)
		
		If jPrec <> "" or jSuiv <> "" Then
			CreateTopTable "NewsNavigate", GetTranslation("LANG_OLD_NEWS")
			Response.Write "<table width=""100%"" cellspacing=""0"" cellpadding=""5"" border=""0"" align=""center"">" & vbCRLF
			Response.Write "  <tr>" & vbCRLF
			Response.Write "    <td width=""35%"" class=""small"">" & vbCRLF
			If jPrec <> "" Then
				Response.Write "      &lt;&lt; <a href=""" & GLOBAL_SITE_NEWS_PAGE & "?date=" & Server.URLEncode(jPrec) & sCategory & """>" & _
										GetTranslation("LANG_LAST_DAY") & "</a><br>" & _
										GetDateLitteralDDMMYYYY(StringToDate(jPrec)) & vbCRLF
			End If
			Response.Write "    </td>" & vbCRLF
			Response.Write "    <td width=""30%"" class=""small"" align=""center"" valign=""bottom"">" & GetDateLitteralDDMMYYYY(dDate) & "</td>" & vbCRLF
			Response.Write "    <td width=""35%"" class=""small"" align=""right"">" & vbCRLF
			If jSuiv <> "" Then
				Response.Write "      <a href=""" & GLOBAL_SITE_NEWS_PAGE & "?date=" & Server.URLEncode(jSuiv) & sCategory & """>" & _
									GetTranslation("LANG_NEXT_DAY") & "</a> &gt;&gt;<br>" & _
									GetDateLitteralDDMMYYYY(StringToDate(jSuiv)) & vbCRLF
			End If
			Response.Write "    </td>" & vbCRLF
			Response.Write "  </tr>" & vbCRLF
			Response.Write "</table>" & vbCRLF
			CreateBottomTable ""
		End If

		Set oRs = Nothing
	End Sub

	' Display all news' categories
	' IN  : iCategoryParent (int) : news' parent category id (table categories, field cParent)
	' OUT : -
	Sub DisplayNewsCategories(iCategoryParent)
		Dim oRs, oRs2, rSQL, iLine, iNum

		If iCategoryParent = "" Then iCategoryParent = 0

		If iCategoryParent <> 0 Then
			rSQL = "SELECT cId, cParent, cTitle, cDescription, cImage FROM categories WHERE cID=" & iCategoryParent
			Set oRs = DBRecordSet(oCnMain, rSQL)

			If Not oRs.EOF Then
				CreateTopTable "NewsCategory", CodeMessage(oRs("cTitle"), True)
				If oRs("cImage") <> "" Then
				'	Response.Write "<img src=""" & GLOBAL_SITE_PATH & "scripts/blank.gif"" style='filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=""" & Server.URLEncode (oRs("cImage") & "") & """, sizingMethod='scale')"" width=""32"" align=""left"">"
					Response.Write "<img src='" & Server.URLEncode(oRs("cImage")) & "' width='32' align='left'>"
				End If
				Response.Write CodeMessage(oRs("cDescription"), True)
				Response.Write "<br><br><a href=""" & GLOBAL_SITE_NEWS_PAGE & "?cat=" & oRs("cParent") & """>" & GetTranslation("LANG_BACK") & "</a>" & vbCRLF
				CreateBottomTable ""
			End If
		End If

		rSQL = "SELECT DISTINCT cId, cTitle FROM categories, news, versions WHERE cType=" & CATEGORY_TYPE_NEWS & " AND nVersion=vID AND nCategory=cID and cParent=" & iCategoryParent
		If sXMLVersion <> "" Then rSQL = rSQL & " AND (vCode='" & sXMLVersion & "' OR nVersion=0)"
		rSQL = rSQL & " ORDER BY cTitle"
		Set oRs = DBRecordSet(oCnMain, rSQL)

		If Not oRs.EOF Then
			If iCategoryParent = 0 Then
				CreateTopTable "SearchNewsCategories", GetTranslation("LANG_NEWS") & " - " & GetTranslation("LANG_CATEGORIES")
			Else
				CreateTopTable "SearchNewsCategories", GetTranslation("LANG_NEWS") & " - " & GetTranslation("LANG_SUB_CATEGORIES")
			End If
			Response.Write GLOBAL_SITE_SUBTABLE & vbCRLF
			iLine = 1
			iNum = 0

			While Not oRs.EOF
				If iNum mod 2 = 0 Then Response.Write "  <tr class=""tableline" & iLine & """>" & vbCRLF
			'	rSQL = "SELECT Count(nID) FROM news, versions WHERE nVersion=vID AND nValid=True AND nCategory=" & oRs("cID")
			'	If sXMLVersion <> "" Then rSQL = rSQL & " AND (nVersion=" & iXMLVersion & " OR nVersion=0)"
			'	Set oRs2 = DBRecordSet(oCnMain, rSQL)
				Response.Write "    <td width=""50%"">"
				Response.Write "<a href=""" & GLOBAL_SITE_NEWS_PAGE & "?cat=" & oRs("cID") & """>" & oRs("cTitle")
				Response.Write "</a>"
			'	Response.Write " (" & oRs2(0) & ")"
				Response.Write " (" & GetPopulationTable(oRs("cID"), "news", "nCategory", "nValid=True AND (nVersion=" & iXMLVersion & " OR nVersion=0)") & ")"
				Response.Write "</td>" & vbCRLF
				
				If iNum mod 2 = 1 Then 
					Response.Write "  </tr>" & vbCRLF
					iLine = 1 + ((iLine-1) XOR 1)
				End If

				iNum = iNum + 1
				oRs.MoveNext
			WEnd
			If iNum mod 2 = 1 Then 
				Response.Write "    <td>&nbsp;</td>" & vbCRLF
				Response.Write "  </tr>" & vbCRLF
			End If
			Response.Write "</table>" & vbCRLF
			CreateBottomTable ""
		End If

		Set oRs = Nothing
		Set oRs2 = Nothing
	End Sub

	' Display a line to let users post their news
	' IN  : iCat : news category
	' OUT : -
	Sub DisplayAddNews(iCat)
		If sPseudo <> "" Then
			CreateTable "AddMemberNews", "", "<a href=""" & GLOBAL_SITE_NEWS_PAGE & "?do=new&cat=" & iCat & """>" & GetTranslation("LANG_ADD") & " - " & GetTranslation("LANG_NEWS") & "</a>", ""
		End If
	End Sub

	' Edit news for members
	' IN  : sAuthor (string) : username
	'     : iCat : news category
	' OUT : -
	Sub EditMemberNews(sAuthor, iCat)
		Dim oRs, rSQL, X, idRole
		idRole = SysParmDef("News.Upload.Image.UserRole", ROLE_NEWS)
		If Not IsNumeric(idRole) Then idRole=ROLE_NEWS

		If iCat = 0 Then 
			iCat = DlookupM("cID", "categories", "cType=" & CATEGORY_TYPE_NEWS)
		End If

		If sAuthor <> "" Then

			rSQL = "SELECT cID, cTitle FROM categories WHERE cType=" & CATEGORY_TYPE_NEWS
			Set oRs = DBRecordSet(oCnMain, rSQL)

			If Not oRs.EOF Then
				CreateTopTable "EditionNews", GetTranslation("LANG_ADD") & " - " & GetTranslation("LANG_NEWS")
				Response.Write GLOBAL_SITE_SUBTABLE & vbCRLF
				Dim oForm
				Set oForm = New DesignForms
				With oForm
					.Open				"AddNews", "post", sUrlPage & "?cat=" & iCat
					.AddInputHidden		"Do", "add"
					.AddShowHeader		GetTranslation("LANG_FIELD"),		GetTranslation("LANG_VALUE")
					.Required
					.AddInput			GetTranslation("LANG_TITLE"),		"nTitle", "", 100, 50
					.NotRequired
					.AddTextHidden2		GetTranslation("LANG_AUTHOR"),		"nAuthor", sAuthor, sAuthor
					.AddTextHidden2		GetTranslation("LANG_DATE"),		"nDate", LocalNow(), GetDateLitteralDDMMYYYYHHMMSS(LocalNow())
					.AddTextbox			GetTranslation("LANG_HEADER"),		"nHeader", "", 50, 8, false
					.AddTextbox			GetTranslation("LANG_CONTENT"),		"nText", "", 50, 10, false
					If IsAuthorized(idRole) Then
						.AddUpload		GetTranslation("LANG_IMAGE"),		"nImage", "", 250, 50, "tn", ""
					Else
						.AddImage		GetTranslation("LANG_IMAGE"),		"nImage", "", 50
					End IF
					.AddInput			GetTranslation("LANG_URL"),			"nURL", "", 250, 50
					.AddCategory											"nCategory", iCat, CATEGORY_TYPE_NEWS, false
					.AddVersion												"nVersion", GetVersionID(sXMLVersion)
					.ConfirmSubmit
					.AlignRight
					.AddShowBottom	.AddSubmit(GetTranslation("LANG_SUBMIT"), "bSubmit")
					.Close
				End With
				Set oForm = Nothing
				Response.Write "</table>" & vbCrLf
				CreateBottomTable ""
			End If

			Set oRs = Nothing
		End If
	End Sub
	
	' Add a member's news (insert query)
	' IN  : sTitle (string) : news' title (table news, field nTitle)
	'     : dDate (datetime) : news' posting date (table news, field nDate)
	'     : sAuthor (string) : news' author (table news, field nAuthor)
	'     : sHeader (string) : news' header (table news, field nHeader)
	'     : sText (string) : news' content (table news, field nText)
	'     : sImage (string) : news' image path (table news, field nImage)
	'     : sURL (string) : news' source (table news, field nURL)
	'     : iCategory (int) : news' category (table news, field nCategory)
	'     : iVersion (int) : news' version (table news, field nVersion)
	' OUT : (boolean) : True if added
	Function AddMemberNews(sTitle, dDate, sAuthor, sHeader, sText, sImage, sURL, iCategory, iVersion)
		Dim rSQL, inRole, bValid
		inRole = SysParmDef("News.User.Valid.Role", ROLE_NEWS)
		If Not IsNumeric(inRole) Then inRole=ROLE_NEWS
		bValid = IIF(IsAuthorized(inRole),1,0)

		rSQL =	"INSERT INTO news" & _
				" ( nTitle, nDate, nAuthor, nHeader, [nText], nImage, nURL, nCategory, nVersion, nRead, nValid )" & _
				" VALUES" & _
				" ('" & SQLEncrypt(sTitle) & "'" & _
				", '" & DateTimeToString(Local2GMT(dDate)) & "'" & _
				", '" & SQLEncrypt(sAuthor) & "'" & _
				", '" & SQLEncrypt(sHeader) & "'" & _
				", '" & SQLEncrypt(sText) & "'" & _
				", '" & SQLEncrypt(sImage) & "'" & _
				", '" & SQLEncrypt(sURL) & "'" & _
				", " & SQLEncrypt(iCategory) & _
				", " & SQLEncrypt(iVersion) & _
				", 0" & _
				", " & cLng(bValid) & _
				")"
		DebugPrint "rSQL: " & rSQL & ""
		DBExecute oCnMain, rSQL
		AddMemberNews = True
	End Function


	' Get the last date of news from a specific date
	' IN  : dDate (datetime) : actual date
	' OUT : (datetime) : last known news date 
	Function GetLastNewsDate(dDate)
		Dim oRs, rSQL

		rSQL = "SELECT " & SQLtop(1) & " nDate FROM news, versions WHERE nVersion=vID AND nDate <= '" & DateToString(dDate) & " 23:59' AND nValid=TRUE"
		If sXMLVersion <> "" Then rSQL = rSQL & " AND (nVersion=" & iXMLVersion & " OR nVersion=0)"
		rSQL = rSQL & " ORDER BY nDate DESC"

		Set oRs = DBRecordSet(oCnMain, rSQL)
		
		If Not oRs.EOF Then 
			GetLastNewsDate = StringToDate(oRs(0))
		Else
			GetLastNewsDate = LocalDate
		End If

		Set oRs = Nothing
	End Function
	
	Sub DoNews()
		Dim iID
		
		iID = Request.QueryString("id")
		If iID <> "" Then
			If Request.Cookies(GLOBAL_UNIQ_ID  & "news_" & iID) = "" Then
				Response.Cookies(GLOBAL_UNIQ_ID  & "news_" & iID) = "read"
			Else
				Response.Cookies(GLOBAL_UNIQ_ID  & "news_" & iID) = "stop"
			End If
		End If
		

		If Request.Form("do") = "add" And Request.Form("nTitle") <> "" Then
		'	If Abs( DateDiff("m", LocalNow(), Session(GLOBAL_UNIQ_ID & "AddNews_" & sPseudo) ) ) < 15 Then
		'		Session(GLOBAL_UNIQ_ID & "AddNews_" & sPseudo)=false

				If AddMemberNews(	Request.Form("nTitle"), _
									Request.Form("nDate"), _
									Request.Form("nAuthor"), _
									Request.Form("nHeader"), _
									Request.Form("nText"), _
									Request.Form("nImage"), _
									Request.Form("nURL"), _
									Request.Form("nCategory"), _
									Request.Form("nVersion")) Then
					sInfoPage = GetTranslation("LANG_NEWS") & " - " & GetTranslation("LANG_ADD_SUCCESS")
				Else
					sInfoPage = GetTranslation("LANG_NEWS") & " - " & GetTranslation("LANG_ADD_ERROR")
				End If
		'	Else
		'		sInfoPage = GetTranslation("LANG_NEWS") & " - " & GetTranslation("LANG_TIMEOUT_ERROR")
		'	End If
		End If
	End Sub
	
	Sub DisplayNewsPage()
		Dim dDatePage, iCat, iNews

		iCat = RequestNum("cat")
		iNews = RequestNum("id")

		If iNews <> 0 Then
			If Request.Cookies(GLOBAL_UNIQ_ID  & "news_" & iNews) = "stop" Then
				DisplayNews iNews, True, False, False
			Else
				DisplayNews iNews, True, True, False
			End If
		ElseIf Request.QueryString("date") <> "" Then
			dDatePage = StringToDate(Request.QueryString("date"))
			DisplayNewsDate(dDatePage), iCat, False
			DisplayNewsNavigation dDatePage, iCat
		ElseIf Request.QueryString("do") = "new" Then
			EditMemberNews sPseudo, iCat
		Else
			DisplayNewsCategories(iCat)
			DisplayAddNews(iCat)
			DisplayTopNewsLinks GLOBAL_NEWS_LINKS_TOP, iCat
			DisplayTopNews GLOBAL_NEWS_LINKS_TOP, iCat
			DisplayNewsNavigation Date, iCat
		End If
	End Sub
%>