Post by turbov21 on Feb 3, 2008 22:23:39 GMT -5
Sometime in between beta versions, I accidentally deleted the original guestbook database and wanted to wait until the final release before putting it back up. Finally, although missing it's old entries, GuestBook is back!
You will need my StrFunc.bas library to get it to work, though. Anyone who wants either is welcome to it. You can see it in action, by going to my Home server (in .sig).
Now, to get Bitter working again!
' GuestBook
' A simple GuestBook program
'''''
' Load this library
global #sf
run "StrFunc", #sf
'''''
' GLOBAL VARIABLES
global DataBaseName$, DataBasePath$, Dlimit$, ErrorMsg$
DataBaseName$ = "gbook1.db"
Dlimit$ = "-|-"
ErrorMsg$ = ""
' Checks to see if the guestbook database exists
Call CheckForDb DataBaseName$
cssclass ".errormsg", "{ border: #ff0000 2px solid; text-align: center; }"
cssclass ".posts", "{ border: #000000 1px dotted; margin-bottom: 5px; padding: 5px; }"
titlebar "GuestBook2"
[start]
' Clears the screen
cls
' Checks for an error
if ErrorMsg$ <> "" then gosub [ErrorMsg]
''' DISPLAY '''
' Starts the table
html "<table style=""width:100%;border:none;"">"
html "<tbody>"
html "<tr>"
html "<td style=""text-align:left;vertical-align:top;width:40%"">"
' The form
html "<p><b>Your Name:</b>"
textbox #yn, ""
html "</p>"
html "<p><b>Your Message:</b><br/>"
textarea #ym, ""
html "</p>"
link #add, "Add Message", [addnew]
print " ";
link #reset, "Reset", [start]
print ""
' Closes the first column
html "</td>"
html "<td style=""text-align:left;vertical-align:top;width:60%"">"
' Displays messages
html "<p>"
Call ListMessages DataBaseName$
html "</p>"
' Closes the second column and table
html "</td></tr></tbody></table>"
wait
' Adds a new message
[addnew]
yn$ = #yn contents$()
ym$ = #ym contents$()
if yn$ = "" then yn$ = "Anonymous Coward" else yn$ = yn$
if ym$ = "" then
ErrorMsg$ = "You have to leave a message!"
goto [start]
end if
Call AddMsg DataBaseName$ yn$ ym$
goto [start]
' Displays a generic error message
[ErrorMsg]
html "<div class=""errormsg""><p><b>ERROR:</b> " + ErrorMsg$ + "</p></div>"
ErrorMsg$ = ""
return
''' SUBROUTINES
' Lists out the entries
Sub ListMessages db$
sqliteconnect #msg, db$
query$ = "select * from guestbook order by pid desc limit 25"
#msg execute(query$)
while #msg hasanswer()
result$ = #msg nextrow$(Dlimit$)
Call BuildMsg result$
wend
#msg disconnect()
End Sub
sub BuildMsg text$
pid$ = #sf SplitStr$(Dlimit$, text$, 1)
name$ = #sf SplitStr$(Dlimit$, text$, 2)
msg$ = #sf SplitStr$(Dlimit$, text$, 3)
td$ = #sf SplitStr$(Dlimit$, text$, 4)
html "<div id=""Message" + pid$ + """ class=""posts"">"
html "<p><b>" + name$ + "</b> posted at " + td$ + "<br/><br/>" + msg$ + "</p>"
html "</div>"
end sub
' Inserts the new message into the database
Sub AddMsg db$ nam$ msg$
nam$ = #sf ReplaceStr$(nam$, "'", "'")
msg$ = #sf ReplaceStr$(msg$, "'", "'")
pdate$ = date$() + " - " + time$()
sqliteconnect #msg, db$
query$ = "insert into guestbook (userid, msg, pdate) values ('" + nam$ + "', '" + msg$ + "', '" + pdate$ + "')"
#msg execute(query$)
#msg disconnect()
End Sub
' Checks for the database, if it doesn't exist, it creates it
Sub CheckForDb db$
files #a, db$
if not(#a hasAnswer()) then
sqliteconnect #c, db$
sqla$ = "create table guestbook (pid integer primary key, userid char(50), msg test, pdate char(30))"
#c execute(sqla$)
#c disconnect()
end if
End Sub
You will need my StrFunc.bas library to get it to work, though. Anyone who wants either is welcome to it. You can see it in action, by going to my Home server (in .sig).
Now, to get Bitter working again!