A guestbook |
Try online | Examples |
A long awaited example, this guestbook is very simple and
most of the code has to do with displaying the HTML page.
Note there's no 'break' statement in the case 5 block, and that's
on purpose. This illustrates why you need break statements, ie,
to be able to omit them if required.
sub Init
_DPath = "c:/temp/aptilis/" $
_Base = "http://localhost/aptilis/" $
_ScriptURL = "http://localhost/cgi-bin/aptilis.exe" $
_ScriptPath = "f:/aptilis/scripts/guestbook_example.e.txt" $
_admin = "teebo@glaine.net" $
setSMTPServer("smtp.ntlworld.com")
end Init
sub purify(m)
m = replace(m$, "\r", "") $
m = replace(m$, "<", "<") $
m = replace(m$, ">", ">") $
m = replace(m$, "\n", "<BR>") $
m = replace(m$, "\"", "'") $
return m$
end purify
sub main
Init()
print("Content-type: text/html\n\n")
print("<HTML>\n<HEAD>\n")
print("\t<TITLE>Aptilis guestbook</TITLE>\n")
print("\t<BASE href=\"", _Base$, "\">\n")
print("</HEAD>\n\n")
print("<BODY bgcolor=\"#FFFFFF\">\n\n")
print("<FONT face=\"arial,helvetica\" color=\"#0000D0\">")
print("<FONT size=+2><CENTER>\n\n")
// Change title here
print("This is the Aptilis guestbook!<BR><I>Feel free to add your comments!</I><BR>\n")
print("<FONT size=-1>(Scroll down to the bottom to post a comment)</FONT><BR>\n")
print("</CENTER></FONT><HR>\n\n")
select c
case 5
// Save post
name = purify(name$) $
email = purify(email$) $
comment = purify(comment$) $
t = int(getTime()) $
rec = makeRecord(t$, email$, name$, comment$) $
appendRecord(_DPath + "guestbook-data.dat" $, rec$)
if len(_admin$) > 0
sendmail(_admin$, _admin$, "Aptilis Test Guestbook", comment + "\n\n" + name$, email$)
end if
case 2
// And Display the contents
n = loadDataBase(db[], _DPath + "guestbook-data.dat" $)
// Simple way to print out the last message in first
reverseArray(db[])
for i=0 to n - 1
getAllFields(fls[], db[i]$)
if len(fls[1]$) > 0
eml1 = "<A href=\"mailto:" + fls[1] + "\">" $
eml2 = "</A>" $
else
eml1 = "" $
eml2 = "" $
end if
fillLocalTimeArray(dt[], fls[0])
date = int(dt[3]) + "/" + int(dt[4] + 1) + "/" + int(dt[5]) $
print("\"", fls[3]$, "\"<BR><BR>")
print(eml1$, "<B>", fls[2]$, "</B>", eml2$, " (", date$, ")")
print("\n\n<HR>\n")
end for
print("<FORM action=\"", _ScriptURL$, "\" method=\"POST\">\n")
print("<INPUT type=\"hidden\" name=\"file\" value=\"", _ScriptPath$, "\">\n")
print("<INPUT type=\"hidden\" name=\"c\" value=\"5\">\n")
print("<TABLE>\n")
print("<TR><TD valign=top><FONT face=\"arial,helvetica\">Your name:</FONT></TD>")
print("<TD valign=top><INPUT type=\"text\" name=\"name\" size=40></TD></TR>\n")
print("<TR><TD valign=top><FONT face=\"arial,helvetica\">Your e-mail address:</FONT></TD>")
print("<TD valign=top><INPUT type=\"text\" name=\"email\" size=40><BR></TD></TR>\n")
print("<TR><TD valign=top><FONT face=\"arial,helvetica\">Your comments:</FONT></TD>")
print("<TD><TEXTAREA name=\"comment\" rows=5 cols=40 wrap></TEXTAREA></TD></TR>\n")
print("<TR><TD></TD><TD valign=top><INPUT type=\"submit\" value=\"send\"></TD></TR>\n")
print("</TABLE>\n")
print("</FORM>")
break
end select
print("</FONT></BODY></HTML>\n")
end main
Here's the HTML that would call the guestbook directly. Note that you do not
necessarily need a target.
<A href="/cgi-bin/aptilis.exe?file=/home/scripts/guestbook.e.txt&c=2" target=_blank>Try this guestbook.</A>