%@ Language="VBSCRIPT" %>
<%
dim data ' this will carry the Date
dim name ' here we will have the nickname
dim message ' this is the variable that will carry with the sent message
dim error ' i use this variable to control if theres errors
dim asn ' with this I will control the bad language used on the chat
Dim DB_Path
error = "" ' lets start the error, with no error
data = now() ' the Date will be equal with the today date
name = left(request.form("name"),20) ' we only accept nicknames with 20 or less letters
message = request.form("message") ' we get the message from the form field message
asn = InStr(1, message, "f**k", 1) + InStr(1, message, "c*nt", 1) + InStr(1, message, "sh*t", 1)
if request.querystring("name2") = "" then ' this is how i see if the person is new in the chat
psw = 0
end if
if name = "" then ' if theres no nickname, then it will be Guest
name = ""
error = " PLEASE ENTER A VALID NAME..."
end if
if name = "guest" then ' if theres no nickname, then it will be Guest
name = ""
error = " PLEASE ENTER A VALID NAME..."
end if
if name = "Guest" then ' if theres no nickname, then it will be Guest
name = ""
error = " PLEASE ENTER A VALID NAME..."
end if
if (message = "" or message = " ") and Request.querystring("vezes") = "1" then ' this is how I validate the message, it can't be empty
message = ""
error = " PLEASE ENTER A VALID MESSAGE..."
end if
if CInt(asn) > 0 then ' if asn is a number bigger than 0 then there bust be some bad language at the message
error = " Please no bad language..." ' this will be the error message
message=""
end if
if (message <> "" And messagec <> message)and(name <>"") then ' messagec controls if the user don't send equal messages
Set Conn = Server.CreateObject("ADODB.Connection")
DB_Path = Request.ServerVariables("APPL_PHYSICAL_PATH") & "fpdb/famchat.mdb"
conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DB_Path & ";" ' i named my DSN with chatdb, you can use any, but don't forget to change it here too
Set rs = Server.CreateObject("ADODB.Recordset") ' create the record set
SQLStmt = "SELECT * FROM chatmain" ' select everything from the chatmain table
rs.Open SQLstmt,Conn,1,2
rs.AddNew ' lets add a new message to the DB
rs("nick") = name ' put the nickname
rs("message") = message ' the message
session("messagec") = message ' don't forget this, so you will late control if they are equal
rs("data") = now ' date and time
rs.Update
rs.close
Set FileStreamObject = CreateObject("Scripting.FileSystemObject") ' this is how you create the scripting object
Set writeStream = FileStreamObject.CreateTextFile(Server.MapPath("top.htm"), True) ' here you set the name of the file that will be created
Set rs2 = Server.CreateObject("ADODB.Recordset") ' i've opened a new recordset because I had some problems with the other rs
SQLStmt = "SELECT * FROM chatmain ORDER BY id DESC"
rs2.Open SQLstmt,Conn,1,2
writeStream.WriteLine "" ' this is the command that writes to the file
writeStream.WriteLine "
" ' as you see i am creating an html file
writeStream.WriteLine "" ' this is the refresh that will ensure that the file is updated to the user of the chat
writeStream.WriteLine ""
writeStream.WriteLine ""
writeStream.WriteLine ""
writeStream.WriteLine ""
writeStream.WriteLine ""
writeStream.WriteLine "
"
writeStream.WriteLine ""
writeStream.WriteLine ""
writeStream.WriteLine "" & Application("ActiveUsers") & " Elrick Family Chat WebPage "
count = 0 ' I use this counter to ensure that won't be no more than 60 messages at the same time
Do while not rs2.eof and count < 200 ' like I said the control of the messages, and the control of the end of the data
' here I will write the data that was written in the DB, so everyone that access
' to the top.htm will see the messages, simulating a real chat program
writeStream.WriteLine ""
writeStream.WriteLine "| " & rs2("data") & " | "
writeStream.WriteLine " " & rs2("nick") & " | "
writeStream.WriteLine " " & rs2("message") & " | "
writeStream.WriteLine " "
count = count + 1
rs2.movenext
loop
writeStream.WriteLine " "
writeStream.WriteLine " | "
writeStream.WriteLine "
"
writeStream.WriteLine "
"
writeStream.WriteLine "
"
writeStream.WriteLine ""
writeStream.WriteLine ""
writeStream.WriteLine ""
WriteStream.Close ' USE THE SAME CLOSE METHOD TO ALL THE OBJECTS THAT YOU USE
rs2.Close
session("messagec") = "0"
end if
%>
<% if session("come") <> "true" then ' this is the way I use to see if it is the first or second come from the user
' if it is not true so it is the first come, i will
' put the focus on the nickname, else, I clean the message
' and put the focus on the message. %>
<%else%>
<%end if
session("passou") = "true"
%>