Web| Vote II. Creation and maintenance of investigation projects
Author: Cactus Studio
In this section we describe the implementation of the survey project creation and maintenance functions.
The starting page for creating and maintaining a survey project is startup.html, which is responsible for setting the frame structure used by pages such as Pollmaker.asp and itemmaker.asp (three frames from top to bottom). The blank.html referenced by the start page is used only to specify the background color, and startmsg.html provides a hint that appears at the bottom of the frame at startup.
Both pollmaker.asp and itemmaker.asp contain ASP scripts that run on the server, as well as (and create) browser scripts to support client actions. Scripts running on the server are written in VBScript, while client-side scripting is JavaScript, which makes it possible to run both Netscape Navigator and IE.
Pollmaker.asp obtains the name of the survey project that has been defined by looking up the msysobjects system table of the poll database. Therefore, the ASP application must have permission to read the table. The setting in ACCESS97 is to select the menu "Tools/Options" to set the system objects visible, and then set them under "Tools/security/user and group permissions." Poll.mdb has set this permission in the code attached to this article. If the survey system is to be implemented on a different RDBMS, this part of the code must be rewritten to fit the system table structure on the target database.
To display the names of these defined survey items to a drop-down list box, you first need to remove the "S_" prefix from the table name of the S_ table and then format the strings as a < option> string for the < select> element:
< select Name= "Pollname" >
< OPTION value= "Startpoll" Selected>new POLL
<%
' Get the name of the survey project that is currently defined
Set objconn = Server.CreateObject ("ADODB. Connection ")
objConn.Open "Poll"
Set objRS = _
objConn.Execute ("SELECT Name from Msysobjects" & _
"WHERE type=1 and name like ' s_% ' ORDER by Name"
Do as Not objrs.eof
Pollname = Mid (objRS ("Name"), 3)
Response.Write ("< OPTION value=" "" & Pollname & "" > "& Pollname)
Objrs.movenext
Loop
%>
</select>
Itemmaker downloads all the definition information for the specified survey project to the browser-side JavaScript array to enable quick editing and creation of the problem. All problem-editing operations are done in the browser by modifying two JavaScript arrays, and only clicking the Save button can write the results to the database.
Itemmaker.asp first sets the Response.Buffer to true so that the HTML output is buffered on the server until the page is completed, which makes it possible for itemmaker.asp to exit without downloading those JavaScript functions when an error occurs or when performing a non editing function. At the beginning of Sub Main, the program determines whether to create a new survey item or to delete a survey item or survey result by examining the form variable optype. All three of these operations are done within itemmaker.asp, that is, all password-protected features are implemented within the same script, which allows passwords to be accessed only in one place throughout the system. All three of these operations need to dynamically generate and execute SQL statements. Either the script execution error or the specified operation succeeds, the Response.Redirect statement is invoked to reload the pollmaker.asp, and a description string is passed to it:
<%
Dim Pollname
Dim Password
Dim objconn
Dim objRS
Pollname = Request ("Pollname")
Password = UCase (Request ("Password"))
Optype = Request ("optype") ' requires itemmaker.asp to perform actions
sname = "[S_" & Pollname & "]"
Aname = "[A_" & Pollname & "]"
Rname = "[R_" & Pollname & "]"
Call Main
Sub Main
If Password < > "Webpoll" Then ' like password error return pollmaker.asp and prompt
Response.Redirect "Pollmaker.asp?" msg= password error, please try again. "
Exit Sub ' return from itemmaker.asp
End If
If optype = "edit" Then ' editing or creating a survey item
If pollname = "Startpoll" Then
If not Newpoll () Then ' user does not give the name of the survey item
Response.Redirect "Pollmaker.asp?" msg= Please enter the name of the survey project.
Exit Sub
End If
sname = "[S_" & Pollname & "]"
Aname = "[A_" & Pollname & "]"
Rname = "[R_" & Pollname & "]"
End If
ElseIf optype = "Delresp" Then ' Delete the results of a survey project
If pollname = "Startpoll" Then
Response.Redirect "Pollmaker.asp?" msg= Please enter the name of the survey project.
Exit Sub
End If
Set objconn = Server.CreateObject ("ADODB. Connection ")
objConn.Open "Poll"
Set objRS = Server.CreateObject ("ADODB. Recordset ")
objConn.Execute "DELETE from" & Rname
Response.Redirect "Pollmaker.asp?" Msg= has deleted the voting results for the specified survey item.
ElseIf optype = "Delpoll" Then ' deletes the entire survey project
If pollname = "Startpoll" Then
Response.Redirect "Pollmaker.asp?" Msg= Cannot delete new survey item "
Exit Sub
End If
Set objconn = Server.CreateObject ("ADODB. Connection ")
objConn.Open "Poll"
Set objRS = Server.CreateObject ("ADODB. Recordset ")
objConn.Execute "DROP TABLE" & sname
objConn.Execute "DROP TABLE" & Aname
objConn.Execute "DROP TABLE" & Rname
Response.Redirect "Pollmaker.asp?" Msg= has deleted the specified survey item. "
End If
%>
When you run the Itemmaker.asp Edit Survey project, the program extracts the survey items defined in the poll database and their problem definition data initialization array stemarray[] and ansarray[]. These strings used for initialization are "escaped" processing (that is, calling the Escape () function) at write time, thereby avoiding problems that may result from embedded quotes or other control characters, which are restored (Initpoll () function) before using these arrays: