Attribute VB_Name = "GuestBook" Option Explicit DefInt A-Z ' GuestBook 1.0 ' Copyright (c) 1995 Greyware Automation Products ' You may use or modify this code to create your own guest book ' ' Parms: ' bookfile=file (required) ' relative path to guestbook datafile; extension must be .book ' ' op=operation (required) ' show displays the guestbook ' add adds record to guestbook ' sign displays form for signing the guestbook ' ' bookname=name (optional) ' if provided, displays give guestbook a display name ' ' ' startwith=## (optional; used with op=show) ' if provided, first record number displayed ' ' howmany=## (optional; used with op=show) ' if provided, number of records to display per page ' ' background=file (optional) ' relative path to file ' Examples: ' ' 1. Display the guest book, starting with most recent record: ' View the GuestBook ' ' 2. Display form for signing guestbook: ' Sign the GuestBook ' ' 3. Display 10 records from guestbook, starting with record 17 ' View 10 Records from the GuestBook ' ' 4. Use /graphics/mybackground.jpg as the guestbook background ' (Len(Fixed) - 300) Then Comments = Left(Comments, Len(Fixed) - 300) End If ' Cat up basic user information UserInfo = Caller + " called from " + cgiGetEnv("remote_addr") + " with " + cgiGetEnv("http_user_agent") UserInfo = UserInfo + "
" + CRLF + "Guest Book signed on " + Format$(Now, "dddd, dd mmmm yyyy") + " at " + Format$(Now, "h:mm:ss AM/PM") If Caller = "" Then tmp = "

You left off your name!

" tmp = tmp + "
" + CRLF tmp = tmp + "Sorry, but you must include your name to sign the Guest Book. " tmp = tmp + "Use your browser's " + Q("back") + " button to try again." cgiErrExit tmp Else Out "" + Caller + " Added to Guest Book" Out "

Thank you, " + FName + "!

" Out "Your entry has been added to the " + BookName + "Guest Book
" tmp = "

" + Caller + "

" + CRLF If Len(Comments) Then tmp = tmp + "
" + Q(Comments) + "

" + CRLF If Len(Email) Then tmp = tmp + "

Send mail to " + FName + "

" + CRLF If Len(HomePage) Then tmp = tmp + "
Visit " + FName + "'s Home Page

" + CRLF tmp = tmp + "
" + UserInfo + "
" + CRLF + "
" + CRLF RecNum = fileAddRecord(tmp) Select Case RecNum Case 0 cgiErrExit "Could not open " + GuestBook + "." Case Else Out "Record " + Format(RecNum) + " added to Guest Book:" + CRLF + tmp End Select End If End Sub ' ' This routine builds & displays a form for signing the guest book ' Sub BookMakeForm() Dim tmp As String Out "Sign the Guest Book" Out "

Sign the " + BookName + "Guest Book

" Out "" Out "
" Out "Fill in the form below, then click the OK button to sign the Guest Book. If you don't want " Out "to sign, click your browser's " + Q("back") + " button to exit." ' get the path to cgishell.exe + \ + this executable tmp = PathToURL("\" + cgiGetEnv("SCRIPT_NAME") + cgiGetEnv("PATH_INFO") + "?") Out "
" Out "" Out "" If Len(Background) Then Out "" If Len(BookName) Then Out "" Out "
"
    Out "         Your Name "
    Out "Your Email Address   jblow@somewhere.cool"
    Out "    Your Home Page   http://www.somewhere.cool/~jblow/"
    Out "
" Out "General Comments -- say something about yourself or this site
" Out "

" Out "
" End Sub ' ' This routine displays entries from the guestbook, plus provides ' a navigation bar for browsing through the rest of the book ' Sub BookShow(StartWith As Long, HowMany As Long) Dim hFile As Long ' file handle Dim x As Integer ' generic Dim tmp As String ' temp string Dim TotRecords As Long ' total count of existing records Dim FirstEntry As Long ' first entry to read Dim LastEntry As Long ' last entry to read Dim ThisEntry As Long ' counter Dim NavBar As String ' navigation If HowMany = 0 Then HowMany = 5 ' default number of entries to show at a time If HowMany < 1 Then HowMany = 1 If HowMany > 999 Then HowMany = 999 On Error GoTo BookShowError hFile = FreeFile Open GuestBook For Random Access Read Shared As #hFile Len = Len(Fixed) TotRecords = LOF(hFile) \ Len(Fixed) Out "Guest Book" Out "

" + BookName + "Guest Book

" Out "" If TotRecords = 0 Then Out "No one has signed the Guest Book yet! Won't you please be the first?" Out "" Exit Sub End If If StartWith <> 0 Then ' if startwith specified FirstEntry = StartWith If FirstEntry > TotRecords Then FirstEntry = TotRecords Else FirstEntry = TotRecords End If LastEntry = FirstEntry - (HowMany - 1) If LastEntry < 1 Then LastEntry = 1 Out "

Records " + Format$(FirstEntry) + " through " + Format$(LastEntry) + "

" tmp = cgiGetEnv("HTTP_REFERER") x = InStr(8, tmp, "\") If x Then tmp = Left(tmp, x) NavBar = "Back to Main Page " ' get the path to cgishell.exe + \ + this executable + ? tmp = "\" + cgiGetEnv("SCRIPT_NAME") + cgiGetEnv("PATH_INFO") + "?" ' add the operation tmp = tmp + "op=show" ' add the bookfile parm tmp = tmp + "&bookfile=" + GuestBook ' add the bookname parm If Len(BookName) Then tmp = tmp + "&bookname=" + Trim(BookName) ' add the background parm If Len(Background) Then tmp = tmp + "&background=" + cgiGetEnv("background") tmp = tmp + "&howmany=" + Format$(HowMany) tmp = tmp + "&startwith=" ' we'll add the startwith parm below tmp = PathToURL(tmp) If FirstEntry > HowMany Then NavBar = NavBar + "Look at Older Records " End If If FirstEntry < TotRecords Then NavBar = NavBar + "Look at Newer Records " End If NavBar = "

" + NavBar + "

" Out NavBar ' read file backwards (firstentry = most recent record) For ThisEntry = FirstEntry To LastEntry Step -1 Get #hFile, ThisEntry, Fixed Out Trim(Fixed) Next ThisEntry Close #hFile Out NavBar Out "" Exit Sub BookShowError: tmp = "Error reading Guest Book: " + Error$ On Error GoTo 0 Resume BookShowFatalExit BookShowFatalExit: cgiErrExit tmp End Sub ' ' This is the entry point for the GuestBook program ' Sub Main() On Error Resume Next ' initialize the CGI environment cgiStartup If CGIShellBas_Version > cgiGetEnv("CGIShell_Version") Then cgiErrExit "This program requires CGIShell version " + CGIShellBas_Version + " or higher." End If ' find out the guestbook filename GuestBook = cgiGetEnv("bookfile") ' get the name of the guestbook file BookName = cgiGetEnv("bookname") ' get name of guestbook Background = cgiGetEnv("background") ' body background to use ' ensure guestbook filename is valid If Right(LCase(GuestBook), 5) <> ".book" Then cgiErrExit "Guest Book filename is invalid; the extension must be " + Q(".book") End If If Len(BookName) Then BookName = BookName + " " If Len(Background) Then Out "" Select Case LCase(cgiGetEnv("op")) Case "show": BookShow Val(cgiGetEnv("startwith")), Val(cgiGetEnv("howmany")) Case "add": BookAddRecord Case "sign": BookMakeForm Case Else: cgiErrExit "Unknown operation; must be 'show' 'add' or 'sign'" End Select ' shutdown & exit cgiShutdown End Sub