<%
'on error resume next
'Variables assigned on start of document
'all leading and trailing blanks are removed
'and any single quotes are changed to &#39;
u_action=request.querystring("u_action")
u_title=replace(trim(request.form("u_title")),"'","&#39;")
u_body=replace(trim(request.form("u_body")),"'","&#39;")
u_author=replace(trim(request.form("u_author")),"'","&#39;")
u_log=request.querystring("u_log")
script_name=request.servervariables("script_name")
%>


<%
'Check to see if the user is adding an article
'if so, then display the input form
if u_action <> "add" then 

'if the user is not looking for the input field
'then they will be interacting with the db
'in one of three ways. 
'1. to insert a new article
'2. to view a specific observation
'3. to display recent headlines 
'The following select statement will adjust the
'sql according to which action is requested

select case u_action 
case "insert"

sql = "insert into articles (title,body,author)"
sql = sql & " values( '" & u_title & "' , '" & u_body & "' , '" & u_author & "' )" 

case "display"
sql="select * from articles where log = "&u_log


case else
sql="select * from articles order by date desc "
end select

accessdb="articles" 
cn="driver={Microsoft Access Driver (*.mdb)};"
cn=cn & "dbq=" & server.mappath(accessdb)
Set rs = Server.CreateObject("ADODB.Recordset")

rs.Open sql, cn
'if there are no observations found then
'redirect the user to the default view
'exceot if the user is adding an article
if u_action <> "insert" then
if rs.eof then
response.redirect script_name
end if
end if
'Start html output
%>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<title>Гостевая книга СПЭК!</title>
<base target="_self">
<link rel="stylesheet" type="text/css" href="style.css">

<body bgcolor="#FFFFFF">

<% 'Display successful addition of article to db
if u_action="insert" then %>
<font color="#001291" face="Arial" size="2"><b>
Ваша запись добавлена.</b><br>
<% else
'Display db output  %></font><div align="center">
  <center>
  <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber1">
    <tr>
      <td width="39%">
<font color="#001291" face="Arial" size="2"><img border="0" src="logo.jpg"></font></td>
      <td width="61%" align="center">&nbsp;</td>
    </tr>
  </table>
  </center>
</div>
<p>
<font color="#001291" face="Arial" size="2">
<% do while not rs.eof and counter < 6
' Change 6 to any number of Titles you want to display
counter=counter+1 %>
<% if u_action <> "display" then %> </font></p>
<div align="left">

<table border="1" width="100%" cellspacing="1" style="border-collapse: collapse" bordercolor="#C0C0C0" cellpadding="2" bordercolordark="#C6D7F7">
<td>
<a href="<%= script_name %>?u_action=display&u_log=<%= rs("log")%>"><%= rs("title") %></a><font face="Arial" size="1" color="#001291">
</font><font face="Arial" size="2" color="#001291"> <font size="1"> &nbsp;</td>
<%= rs("date") %><font face="Arial" size="2" color="#001291"> </font> </font>
</table>

</div>

<% else %>
<b><%= rs("title") %></b><b><font color="#001291" face="Arial" size="1"><br>
</font> 
<font color="#001291" face="Arial" size="2">
<br>
Автор</font></b><font color="#001291" face="Arial" size="2"><i> <%= rs("author") %> </i></font> 
<p>
<pre><font face="Arial" color="#001291"><%= rs("body") %>
</font></pre>
<% end if %>
<% 
rs.movenext
loop %>
<% end if
end if
 %>

<% if u_action="add" then
'if the user is adding a new article
'then display the form input fields  %>
<script Language="JavaScript">
<!-- 
function Blank_TextField_Validator(form)
{


if (form.u_title.value == "")
{
alert("Please fill in the title field.");
form.u_title.focus();
return (false);
}


if (form.u_body.value == "")
{
alert("Please fill in the body field.");
form.u_body.focus();
return (false);
}


if (form.u_author.value == "")
{
alert("Please fill in the author field.");
form.u_author.focus();
return (false);
}


return (true);
}

//-->
</script>
<form method="POST" action="<%= script_name %>?u_action=insert"  onsubmit="return Blank_TextField_Validator(this)" bgcolor="#C6D7F7" style="border-style:solid; border-width:0; font-family: Tahoma; background-color:#FFFFFF">
<div align="center">
  <center>
  <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber2">
    <tr>
      <td width="39%">
      <p align="left"><font face="Arial"><img border="0" src="dob_list.jpg"></font></td>
      <td width="61%">
      <p align="center">&nbsp;</td>
    </tr>
  </table>
  </center>
</div>
<font face="Arial">
<b>
<font color="#001291" size="2">
<br>
Заголовок</font></b><font size="2" color="#001291"><br>
</font>
</font>
<font color="#001291" face="Arial">
<input type="text" name="u_title" size="65"></font><p style="margin-top: 0">
<font face="Arial"><font color="#001291"><b><font size="2">Содержание</font></b></font><font size="2" color="#001291"><br>
</font>
</font>
<font color="#001291" face="Arial">
<textarea rows="8" name="u_body" cols="64"></textarea></font><p style="margin-top: 0; margin-bottom: 0">
<font face="Arial"><font color="#001291"><b><font size="2">Автор</font></b></font><font size="2" color="#001291"><br>
</font>
</font>
<font color="#001291" face="Arial">
<input type="text" name="u_author" size="65"><span lang="en-us">&nbsp;&nbsp;&nbsp;&nbsp;
</span>

<input type="submit" value="Добавить" style="font-weight: bold"></font><font size="2" face="Arial" color="#001291"> </font>
</form>
<% else
'if the user is doind anything other than adding an article
'display navigational hyperlinks %>
<p><font face="Arial" size="2"><a href="<%= script_name %>">
<font color="#001291">Посмотреть существующие записи</font></a><font color="#001291"><br>
</font>
<a href="<%= script_name %>?u_action=add"><font color="#001291">Добавить запись в
книгу</font></a><font color="#001291"> </font> </font>
<% end if %>