<html><head><title>ข้อสอบสุ่ม จากบางส่วน: 2549-01-23 (have 20, ran 5)</title></head>
<body bgcolor="#ffffdd"><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
masterpassword = "thaiall"
programname = "quizran2.asp"
totquiz = 20 ' quiz have 20 questions
totselect = 5 ' random only 5 questions
totscore = 0
redim ran(totquiz)
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
randomize
i = 1
do while i <= totquiz
itmp = int(rnd * 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>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 <= totselect
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
rs.MoveFirst
do while Not rs.eof and i <= totquiz
g_qid = request.form("gqid" & i)
g_ans = request.form("gans" & i)
g_c = request.form("c" & i)
if g_qid = rs("qid") then
response.write( "<hr>"& i & "." & rs("ques") & " [" & rs("qid") &"]<br>")
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
i = i + 1
rs.MoveNext
loop
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)
if (len(request.form("c" & i)) = 0) then
sql = sql & " ','"
else
sql = sql & request.form("c" & i) & "','"
end if
next
if (len(request.form("c" & totquiz)) = 0) then
sql = sql & " ')"
else
sql = sql & request.form("c" & totquiz) & "')"
end if
response.write(sql)
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>
จำนวน : 157 บรรทัด