<%
Option Explicit
Response.Expires = -1000
%>
<!--#INCLUDE file="constants.asp" -->
<%
'======================================================================
' This ASP script en database has been made by Martijn ten Napel
' homepage: http://www.noipo.org
' This script is freeware and you can twist and turn it to your liking.
'======================================================================

Dim objConn
Dim objRecordSet
Dim strID
Dim strSQL

'catches the blogid given in the URI to this page. If not present, the id will be 0 (for errortrapping)
if request("id") = "" then
	strID = "0"
else
	strID = cstr(request("id"))
end if

'using the standard Microsoft ADO components to open databases. Has to be present on server (MS MDAC)
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath(LOCATION))

strSQL = "SELECT volgnr, author, date, email, homepage, comment FROM COMMENTS WHERE refernr ='" & strID & "' ORDER BY volgnr DESC"

Set objRecordSet = objConn.Execute(strSQL)
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
	<title><% response.write TITLEPAGE %></title>
	<meta name="MSSmartTagsPreventParsing" content="TRUE">
	<style type="text/css" media="all">
		@import "comments.css";
	</style>
</head>

<body>
<div id="content">
<div id="title">
<h1><% response.write TITLEPAGE %></h1>
</div>
<div id="comments">
<%
if cstr(request("message")) <> "" then
	response.write "<p class=""message"">" & cstr(request("message")) & "</p>"
end if

'Some explanation:
'If the homepage field contains a value, the authorname will be a link to the homepage.
'If the homepage fiels is empty, but the e-mail field is filled, the authorname will be a mailto link.
'If neither field is filled, the name is displayed as text.

if (objRecordSet.BOF And objRecordSet.EOF) then
	response.write "<p>[no comments yet]</p>"
elseif strID = 0 then
	response.write "<p>[no comments yet]</p>"
else
	Do While NOT objRecordSet.EOF 
	response.write "<p class=""commenttext"">"
	response.write objRecordSet("comment").Value & "</p>" & vbCRLF & "<p class=""smaller"">"
	if len(objRecordSet("homepage").Value) > 1 then
		response.write "<a href=""" & objRecordSet("homepage").Value & """ target=""_top"">" & objRecordSet("author").Value & "</a>"
	elseif  len(objRecordSet("email").Value) > 1 then
		response.write "<a href=""mailto:" & objRecordSet("email").Value & """>" & objRecordSet("author").Value & "</a>"
	else
		response.write objRecordSet("author").Value
	end if
	response.write " on " & FormatDateTime(objRecordSet("date").Value,1) & " at " & FormatDateTime(objRecordSet("date").Value,4) & "</p>" & vbCRLF

	objRecordSet.MoveNext
	Loop
end if

objConn.Close
Set objRecordSet = Nothing
Set objConn = Nothing

%>
</div>
<div id="newcomment">
<form action="db_action.asp" method="post" name="formComment">

<p>your name:<br>
<input type="text" name="author" maxlength="50" size="22" value="<% = session("author") %>"></p>
<p>your e-mail address:<br>
<input type="text" name="email" maxlength="50" size="22" value="<% = session("email") %>"></p>
<p>your homepage:<br>
<input type="text" name="homepage" maxlength="100" size="22" value="<% 
	if session("homepage") = "" then 
		response.write "http://"
	else 
		response.write session("homepage")
	end if %>"></p>
<p>comment:<br>
<textarea cols="40" rows="10" name="comment"><% response.write session("comment") %></textarea></p>
<p><input type="submit" name="cmdSubmit" value="Add your comment" onclick="return CheckFields();"></p>
<input type="hidden" name="id" value="<% = strID %>">
</form>
</div>
</div>
<!-- this script checks if there are entries in the required fields -->
<script language="JavaScript" type="text/javascript">
<!--
	function CheckFields() {
		if (document.formComment.author.value.length < 1 ) {
				alert ("<% response.write ADDNAME %>");
				document.formComment.author.focus();
				return false;
				}
		if (document.formComment.comment.value.length < 1 ) {
			alert ("<% response.write ADDCOMMENT %>");
				document.formComment.comment.focus();
				return false;
			}
			else {
				return true;
			}
	}
//-->
</script>
</body>
</html>