<html><head><title>Online quiz update: 2548-02-24</title></head>
<body bgcolor="#ddffff"><font face="microsoft sans serif" size=0><ul>
<%
dim totscore, totrec, totquiz, programname, connect, rs, sql, scolor, i, qchoose, qprocess, chk, ip, fromquiz, datetimestart, datetimestop, masterpassword, cntsid, itmp, j, found, rannumcal
masterpassword = "thaiall"
programname = "quizrannum.asp"
totquiz = 20
totscore = 0
redim ran(totquiz)
qrannum = request.form("rannum") + request.querystring("rannum")
qchoose = request.form("tbl") + request.querystring("tbl")
qprocess = request.form("process") + request.querystring("process")
qip = request.form("ip") + request.querystring("ip")
qdatetimestart = request.form("datetimestart") + request.querystring("datetimestart")
qdatetimestop = now()
qmasterpassword = request.form("masterpassword") + request.querystring("masterpassword")
if len(qchoose) < 2 then qchoose = "math101"
if len(qprocess) < 2 then qprocess = "show"
set connect = server.createobject("ADODB.Connection")
' ==========
' It have many method to open file. Some method does not work.
' connect.open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("quizans.mdb"))
' connect.open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("\yourdir\db\quizans.mdb"))
' connect.open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=d:\thaiall.com\allthai.quiz\quizans.mdb")
connect.open "provider=microsoft.jet.oledb.4.0; data source=" & Server.MapPath("quizans.mdb")
' ==========
set rs=server.createobject("ADODB.recordset")
sql = "select * from " + qchoose + "ans where sid ='" + request.form("sid") + "'"
rs.open sql,connect,1,3
cntsid = rs.recordcount
sql = "select * from student where sid='" & request.form("sid") &"'"
sql = sql & " and pass ='" & request.form("pass") &"'"
rs.close
rs.open sql,connect,1,3
totrec = rs.recordcount
if totrec = 0 or masterpassword <> qmasterpassword then
response.write("Incorrect student id or password")
response.end
end if
rannumcal = 123456
for j = 1 to len(qrannum)
rannumcal = ( rannumcal * 2 ) + asc(mid(qrannum,j,1)) * j
next
randomize
i = 1
do while i <= totquiz
rannumcal = rannumcal - cint(mid(rannumcal,3,3)) - i
itmp = rannumcal mod totquiz
found = 0
for j = 1 to i - 1
if ran(j) = itmp then found = 1
next
if found = 0 then
ran(i) = itmp
i = i + 1
end if
loop
response.write("Student id : " & request.form("sid"))
response.write("<br>Random number : " & qrannum)
response.write("<br>Student name : " & rs("sname"))
response.write("<br>Subject : " & request.form("tbl"))
response.write("<br>IP : " & qip)
response.write("<br>Can save this exam : ")
if cntsid > 0 then
response.write("No")
else
response.write("Yes")
end if
response.write("<br>Start : " & qdatetimestart)
sql = "select * from " + qchoose + " order by qid"
rs.close
set rs=server.createobject("ADODB.recordset")
rs.open sql,connect,1,3
totrec = rs.recordcount
if qprocess = "show" then
rs.close
set rs = connect.execute(sql)
response.write("<form method=post action=" & programname & ">")
response.write("<input name=masterpassword type=hidden value=" & request.form("masterpassword") &">")
response.write("<input name=sid type=hidden value=" & request.form("sid") &">")
response.write("<input name=pass type=hidden value=" & request.form("pass") &">")
response.write("<input name=ip type=hidden value=" & qip &">")
response.write("<input name=datetimestart type=hidden value='" & qdatetimestart &"'>")
response.write("<input name=fromquiz type=hidden value=" & programname &">")
response.write("<input name=tbl type=hidden value=" & qchoose &">")
response.write("<input name=process type=hidden value=check>")
i = 1
do while i <= totquiz
rs.movefirst
rs.move ran(i)
itmp = ran(i) + 1
response.write("<hr><b>"&i& "." &rs("ques")&"</b> [ "&rs("qid") &_
" ]<br><input type=hidden name=gqid" & itmp & " value=" &rs("qid") &">"&_
"<input type=hidden name=gans" & itmp & " value=" &rs("ans") &">"&_
"<input type=radio name=c"&itmp&" value=1 checked>a. "&rs("c1")&"<br>"&_
"<input type=radio name=c"&itmp&" value=2>b. "&rs("c2")&"<br>"&_
"<input type=radio name=c"&itmp&" value=3>c. "&rs("c3")&"<br>"&_
"<input type=radio name=c"&itmp&" value=4>d. "&rs("c4")&"<br>"&_
"<input type=radio name=c"&itmp&" value=5>e. "&rs("c5")&"<br>")
i = i + 1
loop
response.write( "<input type=submit name=submit value=SendAns>" )
response.write( "<input type=reset name=reset value=Reset></form>" )
else
response.write("<br>Stop : " & qdatetimestop)
i = 1
' for i = 1 to totquiz
rs.MoveFirst
do while Not rs.eof and i <= totquiz
' if request.form("gqid" & i) = rs("qid") then
g_qid = request.form("gqid" & i)
g_ans = request.form("gans" & i)
g_c = request.form("c" & i)
response.write( "<hr>"& i & "." & rs("ques") & rs("qid") &"<br>")
if g_qid = rs("qid") then
if g_ans = 1 then chk="/" else chk="X" end if
response.write("<font face=fixedsys>" & chk & "</font> a. "& rs("c1") &"<br>")
if g_ans = 2 then chk="/" else chk="X" end if
response.write("<font face=fixedsys>" & chk & "</font> b. "& rs("c2") &"<br>")
if g_ans = 3 then chk="/" else chk="X" end if
response.write("<font face=fixedsys>" & chk & "</font> c. "& rs("c3") &"<br>")
if g_ans = 4 then chk="/" else chk="X" end if
response.write("<font face=fixedsys>" & chk & "</font> d. "& rs("c4") &"<br>")
if g_ans = 5 then chk="/" else chk="X" end if
response.write("<font face=fixedsys>" & chk & "</font> e. "& rs("c5") &"<br>")
if g_ans = g_c then
response.write("<font color=blue>Right.</font>")
totscore = totscore + 1
else
response.write("<font color=red>Wrong. Try again. [" & g_c & "]</font>")
end if
end if
' end if
rs.movenext
i = i + 1
loop
' next
response.write("<hr>Total score : " & totscore)
' บรรทัดข้างล่างนี้จะทำให้แสดงคะแนน และหยุดให้ดูเพียง 15 วินาที แล้วกลับไปที่หน้า default.asp อีกครั้ง
response.write("<meta http-equiv='refresh' content='15;URL=default.asp'> ")
if cntsid = 0 then
sql = "insert into " + qchoose + "ans(sid,score,ip,datetimestart,datetimestop,scriptname,q01,q02,q03,q04,q05,q06,q07,q08,q09,q10,q11,q12,q13,q14,q15,q16,q17,q18,q19,q20)values('"
sql = sql & request.form("sid") & "'," & totscore & ",'" & qip & "','" & qdatetimestart & "','" & qdatetimestop & "','" & programname & "','"
for i = 1 to (totquiz - 1)
' sql = sql & request.form("gans" & i) & "','"
sql = sql & request.form("c" & i) & "','"
next
' sql = sql & request.form("gans" & totquiz) & "')"
sql = sql & request.form("c" & totquiz) & "')"
connect.execute(sql)
response.write("<br>Save : ok")
else
response.write("<br>Save : error<br>Can not duplicate")
end if
end if
connect.close
set rs = nothing
set connect = nothing
%>
</ul></body></html>
จำนวน : 160 บรรทัด