home *** CD-ROM | disk | FTP | other *** search
/ bombers.k12.ar.us / bombers.k12.ar.us.tar / bombers.k12.ar.us / survey_unconfigured / TakeSurveyAction.asp < prev    next >
Text File  |  2006-06-27  |  40KB  |  796 lines

  1. <!--#Include File="Include/Top_inc.asp"-->
  2. <%
  3. '***********************************************************************
  4. '   Application: SelectSurveyASP Advanced v8.1.9
  5. '   Author: Aaron Baril for ClassApps.com
  6. '   Page Description: This page works with TakeSurvey.asp, and process
  7. '                     the survey once it has been submitted by a user.
  8. '
  9. '   COPYRIGHT NOTICE
  10. '
  11. '   See attached Software License Agreement
  12. '
  13. '   (c) Copyright 2002 - 2006 by ClassApps.com.  All rights reserved.
  14. '***********************************************************************
  15. %>
  16. <!--#Include File="Include/Config_inc.asp"-->
  17. <!--#Include File="Include/adovbs_inc.asp"-->
  18. <!--#Include File="Include/ID_inc.asp"-->
  19. <!--#Include File="Include/CurrentUser_inc.asp"-->
  20. <!--#Include File="Include/SurveySecurity_inc.asp"-->
  21. <!--#Include File="Include/Constants_inc.asp"-->
  22. <!--#Include File="Include/Collection_inc.asp"-->
  23. <!--#Include File="Include/Encryption_inc.asp"-->
  24. <!--#Include File="Include/SurveyUtility_inc.asp"-->
  25. <!--#Include File="Include/SurveyPageCondition_inc.asp"-->
  26. <!--#Include File="Include/Utility_inc.asp"-->
  27. <%
  28.     Dim strSQL
  29.     Dim conSurvey
  30.     Dim conUpdate
  31.     Dim conDelete
  32.     Dim rsItems
  33.     Dim rsAnswers
  34.     Dim rsSubItems
  35.     Dim rsPageConditions
  36.     Dim rsSurvey
  37.     Dim lngItemID
  38.     Dim lngResponseID
  39.     Dim lngEmailAddressID
  40.     Dim lngSurveyID
  41.     Dim lngAnonymousUserID
  42.     Dim strAnswerText
  43.     Dim strOtherText
  44.     Dim vaAnswers
  45.     Dim i
  46.     Dim flgExecuteSQL
  47.     Dim flgUpdatingSurvey
  48.     Dim flgInsertedResponse
  49.     Dim lngAnswerID
  50.     Dim lngActualPageNumber
  51.     Dim lngNextPageNumber
  52.     Dim lngDisplayPageNumber
  53.     Dim lngPageToDeleteAnswers
  54.     Dim lngTotalPageCount
  55.     Dim lngCurrentPageNumber
  56.     Dim strResponseStartDate
  57.     Dim strColumnsCollection
  58.     Dim lngColumnCount
  59.     Dim strEditValue
  60.     Dim rsHiddenFields
  61.     Dim strHiddenFieldValue
  62.     Dim arrNameValuePair
  63.     Dim arrQueryString
  64.     Dim flgHadAnswerableQuestions
  65.     Dim strItemIDValues
  66.  
  67.     'Initialization
  68.     Set conSurvey = Server.CreateObject("ADODB.Connection")
  69.     Set conUpdate = Server.CreateObject("ADODB.Connection")
  70.     Set conDelete = Server.CreateObject("ADODB.Connection")
  71.     Set rsItems = Server.CreateObject("ADODB.Recordset")
  72.     Set rsHiddenFields = Server.CreateObject("ADODB.Recordset")
  73.     Set rsAnswers = Server.CreateObject("ADODB.Recordset")
  74.     Set rsSubItems = Server.CreateObject("ADODB.Recordset")
  75.     Set rsPageConditions = Server.CreateObject("ADODB.Recordset")
  76.     Set rsSurvey = Server.CreateObject("ADODB.Recordset")
  77.     conSurvey.Open SURVEY_APP_CONNECTION
  78.     lngSurveyID = DecryptSurveyID(Request.Form("SurveyID"))
  79.     lngActualPageNumber = Request.Form("ActualPageNumber")
  80.     lngCurrentPageNumber = Request.Form("ActualPageNumber")
  81.     lngDisplayPageNumber = Request.Form("DisplayPageNumber")
  82.     lngColumnCount = 0
  83.  
  84.     '10/17/2005
  85.     Dim rsTmpAns
  86.     Dim tmpAnsSql
  87.     Set rsTmpAns = Server.CreateObject("ADODB.Recordset")
  88.  
  89.  
  90.  
  91.     'Record whether or not we are updating a survey
  92.     If Request.Form("hdnUpdatingSurvey") = "True" Then
  93.         flgUpdatingSurvey = True
  94.     Else
  95.         'Duplicate page submissions only matter on inserts.  When updating a survey (above), the extra submission still
  96.         'ends up being a correct update of the previous values.
  97.  
  98.         'If the correct value is in Session, this is not an update
  99.         If Session(SUR_UNIQUE_RESPONSE_IDENTIFIER) = CStr(lngSurveyID) & CStr(lngActualPageNumber) Then
  100.             flgUpdatingSurvey = False
  101.         Else
  102.             'The correct value is not in session, so make this an update, and use the response ID from session
  103.             If Len(Session(SUR_CURRENT_RESPONSE_ID)) = 0 Then
  104.                 flgUpdatingSurvey = False
  105.             Else
  106.                 flgUpdatingSurvey = True
  107.                 lngResponseID = Session(SUR_CURRENT_RESPONSE_ID)
  108.             End If
  109.         End If
  110.     End If
  111.  
  112.     'Clear out the value put into session for preventing duplicate responses
  113.     Session(SUR_UNIQUE_RESPONSE_IDENTIFIER) = ""
  114.  
  115.     'Get all the items for the survey
  116.     strSQL = "SELECT i.item_type_id As item_type_id, i.item_id As item_id " & _
  117.                 "FROM sur_item i, sur_survey_to_item_mapping m, sur_item_type it " & _
  118.                 "WHERE i.item_id = m.item_id " & _
  119.                 "AND m.page_number = " & lngActualPageNumber & _
  120.                 " AND it.item_type_id = i.item_type_id " & _
  121.                 "AND question_yn = " & SQLEncode(SUR_BOOLEAN_POSITIVE) & _
  122.                 " AND m.survey_id = " & lngSurveyID & _
  123.                 " ORDER BY m.order_number"
  124.     rsItems.Open ConvertSQL(strSQL), SURVEY_APP_CONNECTION, adOpenForwardOnly, adLockReadOnly, adCmdText
  125.  
  126.     'If this was a new response, insert a row into the SUR_RESPONSE table.  Otherwise, simply store the value of
  127.     'the previous response.  If there is a value in the ResponseID field, the entry has already been written to the
  128.     'SUR_RESPONSE table
  129.     If flgUpdatingSurvey = True Or Len(Request.Form("ResponseID")) > 0 Then
  130.         'If the response ID was set above while checking if the user clicked the back button, do not set it again.
  131.         If Len(lngResponseID) = 0 Then
  132.             lngResponseID = Request.Form("ResponseID")
  133.         End If
  134.  
  135.         'Track the fact that the user has responded to thiis page on this survey
  136.         Session(SUR_SESSION_TAKING_SURVEY & lngSurveyID) = Session(SUR_SESSION_TAKING_SURVEY & lngSurveyID) & "Page" & lngActualPageNumber & "||"
  137.     Else 'New survey
  138.         'If the survey is not in manual entry mode and the current user has already taken the survey
  139.         'and the survey does not allow multiple responses by a user, no more responses can be submitted.
  140.         If IsManualResponseEntryMode(lngSurveyID) = False And HasUserCompletedSurvey(lngSurveyID) = True And IsMultipleResponseSurvey(lngSurveyID) = False Then
  141.             Response.Redirect "AccessDenied.asp?SurveyID=" & lngSurveyID & "&Reason=" & SUR_ACCESS_DENIED_ALREADY_TAKEN
  142.         End If
  143.  
  144.         'The rsItems recordset only contains records if there were answerable questions on the previous page.  If
  145.         'there were no answerable questions on the previous page, do not record a response.
  146.         If Not rsItems.EOF Then
  147.             'Get ID for new response and create a response in the SUR_RESPONSE table
  148.             lngResponseID = ID_GetNextAvailableID("SurveyGenerationResponse")
  149.  
  150.             'If the user is not logged in, get their anonymous user ID.
  151.             If IsLoggedIn() = False Then
  152.                 lngAnonymousUserID = GetAnonymousUserID()
  153.             Else
  154.                 lngAnonymousUserID = "Null"
  155.             End If
  156.  
  157.             'Store the response ID in session in order to ensure that no page is submitted twice.
  158.             Session(SUR_CURRENT_RESPONSE_ID) = CStr(lngResponseID)
  159.  
  160.             'Track the survey and pages responded to in a Session variable
  161.             Session(SUR_SESSION_TAKING_SURVEY & lngSurveyID) = "||" & SUR_SESSION_TAKING_SURVEY & lngSurveyID & "||Page1||"
  162.  
  163.             'Set a cookie indicating that the user has taken the survey.  This cookie is based on the survey ID
  164.             Response.Cookies(SUR_APPLICATION_COOKIE)(SUR_COOKIE_SURVEY & Request.ServerVariables("REMOTE_ADDR") & lngSurveyID) = lngResponseID
  165.             Response.Cookies(SUR_APPLICATION_COOKIE).Expires = DateAdd("yyyy", 10, Date())
  166.  
  167.             'Record the email address ID in the database if there is one to associate with this suryey.
  168.             If Len(Request.Form("EmailAddressID")) > 0 Then
  169.                 lngEmailAddressID = Request.Form("EmailAddressID")
  170.  
  171.                 'Update the response count total
  172.                 strSQL = "UPDATE sur_email_message " & _
  173.                          "SET email_response_count = email_response_count + 1 " & _
  174.                          "WHERE email_message_id = " & Request.Form("EmailMessageID")
  175.                 conSurvey.Execute ConvertSQL(strSQL), , adCmdText
  176.  
  177.                 'Update the history of emails sent out to indicate that a response was recorded for this item
  178.                 strSQL = "UPDATE sur_email_sent_history " & _
  179.                          "SET response_date = GETDATE(), " & _
  180.                          "response_id = " & lngResponseID & ", " & _
  181.                          "current_status = " & SQLEncode(SUR_EMAIL_STATUS_RESPONDED) & _
  182.                          " WHERE url_unique_id = " & SQLEncode(Request.Form("EID"))
  183.                 conSurvey.Execute ConvertSQL(strSQL), , adCmdText
  184.  
  185.             Else
  186.                 lngEmailAddressID = "Null"
  187.             End If
  188.  
  189.             'If the response start datetime has any periods (.) in it, replace them with colons (:).  On a server with
  190.             'European datetime format, the time is often rendered with periods, as in 04.55.33
  191.  
  192.             strResponseStartDate = Request.Form("ResponseStartDate")
  193.  
  194.             strSQL = "INSERT INTO sur_response(response_id, survey_id, email_address_id, anonymous_id, username, " & _
  195.                         "response_start_date, ip_address, completed_yn) VALUES(" & _
  196.                         lngResponseID & ", " & lngSurveyID & ", " & _
  197.                         lngEmailAddressID & ", " & _
  198.                         lngAnonymousUserID & ", "
  199.             'If the response type is manual, do not record a username
  200.             If Request.Form("ResponseType") = SUR_RESPONSE_TYPE_MANUAL Then
  201.                 strSQL = strSQL & SQLEncode(SUR_USER_MANUAL) & ", "
  202.             Else
  203.                 strSQL = strSQL & SQLEncode(GetUsername()) & ", "
  204.             End If
  205. '**SB 6/22/2006
  206.             strSQL = strSQL & SQLEncode(CustomDateFormatDisplay(strResponseStartDate)) & ", " & SQLEncode(Request.ServerVariables("REMOTE_ADDR")) & _
  207.                         ", " & SQLEncode(SUR_BOOLEAN_NEGATIVE) & ")"
  208.  
  209.  
  210.             conSurvey.Execute ConvertSQL(strSQL), , adCmdText
  211.  
  212.  
  213.             'Record any hidden fields associated with the survey
  214.             strSQL = "SELECT hidden_field_id, hidden_field_type, hidden_field_key " & _
  215.                      "FROM sur_hidden_field " & _
  216.                      "WHERE survey_id = " & lngSurveyID & _
  217.                      " ORDER BY order_number"
  218.             Set rsHiddenFields = conSurvey.Execute(ConvertSQL(strSQL), , adCmdText)
  219.             If Not rsHiddenFields.EOF Then
  220.                 rsHiddenFields.MoveFirst
  221.                 Do While Not rsHiddenFields.EOF
  222.                     strHiddenFieldValue = ""
  223.                     Select Case rsHiddenFields("hidden_field_type")
  224.                         Case SUR_HIDDEN_FIELD_TYPE_COOKIE
  225.                             strHiddenFieldValue = Request.Cookies(rsHiddenFields("hidden_field_key"))
  226.                         Case SUR_HIDDEN_FIELD_TYPE_QUERYSTRING
  227.                             'Split the querystring to find the correct name/value pair
  228.                             arrQueryString = Split(Request.Form("PostedQueryString"), "&")
  229.                             For i = 0 To UBound(arrQueryString)
  230.                                 arrNameValuePair = Split(arrQueryString(i), "=")
  231.                                 If arrNameValuePair(0) = rsHiddenFields("hidden_field_key") Then
  232.                                     strHiddenFieldValue = arrNameValuePair(1)
  233.                                     Exit For
  234.                                 End If
  235.                             Next
  236.                         Case SUR_HIDDEN_FIELD_TYPE_SESSION
  237.                             strHiddenFieldValue = Session(rsHiddenFields("hidden_field_key"))
  238.                     End Select
  239.  
  240.                     'Insert the hidden field into the response
  241.                     strSQL = "INSERT INTO sur_response_hidden_field (hidden_field_id, response_id, answer_text) VALUES(" & _
  242.                              rsHiddenFields("hidden_field_id") & ", " & _
  243.                              lngResponseID & ", " & _
  244.                              SQLEncode(strHiddenFieldValue) & ")"
  245.                     conSurvey.Execute ConvertSQL(strSQL), , adCmdText
  246.  
  247.                     rsHiddenFields.MoveNext
  248.                 Loop
  249.             End If
  250.  
  251.             'Update the response count in the SUR_SURVEY table
  252.             strSQL = "UPDATE sur_survey SET response_count = response_count + 1 WHERE survey_id = " & lngSurveyID
  253.             conSurvey.Execute ConvertSQL(strSQL), , adCmdText
  254.  
  255.             flgHadAnswerableQuestions = True
  256.         Else
  257.             flgHadAnswerableQuestions = False
  258.         End If
  259.     End If
  260.  
  261.     'Make sure that the previous page had answerable questions
  262.     If Not rsItems.EOF Then
  263.         'Loop through all the items, extracting the response(s) for each question and inserting them into the database
  264.         rsItems.MoveFirst
  265.         Do While Not rsItems.EOF
  266.  
  267.             'Initialization
  268.             strAnswerText = SUR_ANSWER_TEXT_NULL
  269.             strOtherText = SUR_ANSWER_TEXT_NULL
  270.             flgExecuteSQL = True
  271.             lngItemID = rsItems("item_id")
  272.  
  273.             Select Case CLng(rsItems("item_type_id"))
  274.                 Case SUR_ITEM_HEADING, SUR_ITEM_IMAGE, SUR_ITEM_MESSAGE, SUR_ITEM_HTML, SUR_ITEM_HORIZONTAL_RULE:
  275.                     'No need to execute SQL since this is just a heading
  276.                     flgExecuteSQL = False
  277.                 Case SUR_ITEM_YES_NO, SUR_ITEM_TRUE_FALSE:
  278.                     lngAnswerID = SUR_ANSWER_ID_NULL
  279.                     strOtherText = SUR_ANSWER_TEXT_NULL
  280.  
  281.                     'If NONE is selected, then use the NULL value; otherwise, get the answer text
  282.                     If Request.Form("QID" & CStr(lngItemID)) = SUR_COMBO_NONE Then
  283.                         strAnswerText = SUR_ANSWER_TEXT_NULL
  284.                     Else
  285.                         'If no anwer was selected, use the NULL value; otherwise, get the answer text
  286.                         If Len(Trim(Request.Form("QID" & CStr(lngItemID)))) > 0 Then
  287.                             strAnswerText = Trim(Request.Form("QID" & CStr(lngItemID)))
  288.                         Else
  289.                             strAnswerText = SUR_ANSWER_TEXT_NULL
  290.                         End If
  291.                     End If
  292.                 Case SUR_ITEM_SINGLE_SELECT_DROPDOWN:
  293.                     'If NONE is selected, then use the NULL value; otherwise, get the answer text
  294.                     strAnswerText = SUR_ANSWER_TEXT_NULL
  295.                     If Request.Form("QID" & CStr(lngItemID)) = SUR_COMBO_NONE Then
  296.                         lngAnswerID = SUR_ANSWER_ID_NULL
  297.                     Else
  298.                         lngAnswerID = Request.Form("QID" & CStr(lngItemID))
  299.                     End If
  300.                     strOtherText = SUR_ANSWER_TEXT_NULL
  301.                 Case SUR_ITEM_SINGLE_SELECT_OPTIONS:
  302.                     'If no answer is specified, use the NULL value
  303.                     strAnswerText = SUR_ANSWER_TEXT_NULL
  304.                     If Len(Request.Form("QID" & CStr(lngItemID))) = 0 Then 'No answer specified
  305.                         lngAnswerID = SUR_ANSWER_ID_NULL
  306.                     Else
  307.                         'If the "OTHER" answer is selected, set the answer ID to NULL
  308.                         If Request.Form("QID" & CStr(lngItemID)) = SUR_ANSWER_OTHER Then
  309.                             lngAnswerID = SUR_ANSWER_ID_NULL
  310.                         Else
  311.                             lngAnswerID = Request.Form("QID" & CStr(lngItemID))
  312.                         End If
  313.                     End If
  314.  
  315.                     'See if the "OTHER" option was selected.
  316.                     If Request.Form("QID" & CStr(lngItemID)) = SUR_ANSWER_OTHER Then
  317.                         strAnswerText = SUR_ANSWER_TEXT_OTHER_SELECTED
  318.                         strOtherText = Trim(Request.Form("QID" & CStr(lngItemID) & "OTHERTEXT"))
  319.  
  320.                         'If no text was entered in the "Other" text box, use the null value
  321.                         If Len(strOtherText) = 0 Then
  322.                             strOtherText = SUR_ANSWER_TEXT_NULL
  323.                         End If
  324.                     End If
  325.                 Case SUR_ITEM_MATRIX_SINGLE_SELECT_OPTIONS, SUR_ITEM_MATRIX_RATING_SCALE:
  326.                     'Set a flag to indicate whether or not a row has been inserted for the option buttons.  It's possible not to
  327.                     'insert any data if the question is not required and the user does not enter any values.  For correctness and
  328.                     'consistency in the reporting, it's necessary to have an entry for "null" responses to the checkboxes
  329.                     flgInsertedResponse = False
  330.  
  331.                     'For updates, delete all of the previous answers before inserting the current set of answers.
  332.                     If flgUpdatingSurvey = True Then
  333.                         strSQL = "DELETE FROM sur_response_answer WHERE response_id = " & lngResponseID & " AND item_id = " & lngItemID
  334.                         conSurvey.Execute ConvertSQL(strSQL), , adCmdText
  335.                     End if
  336.  
  337.                     'Loop through each of the subitems and see if an option button was selected.  If so, insert an
  338.                     'entry into the database.
  339.                     strSQL = "SELECT subitem_id, subitem_text FROM sur_subitem WHERE item_id = " & lngItemID & " ORDER BY order_number"
  340.                     Set rsSubItems = conSurvey.Execute(ConvertSQL(strSQL), , adCmdText)
  341.  
  342.                     rsSubItems.MoveFirst
  343.                     Do While Not rsSubItems.EOF
  344.                         'If an answer was submitted for this item, insert a record into the database
  345.                         If Len(Trim(Request.Form("QID" & CStr(lngItemID) & "||SIID" & rsSubItems("subitem_id")))) > 0 Then
  346.                             'For matrix rating scale questions, record the numeric value as the answer text
  347.                             If CLng(rsItems("item_type_id")) = SUR_ITEM_MATRIX_RATING_SCALE Then
  348.                                 strAnswerText = Request.Form("QID" & CStr(lngItemID) & "||SIID" & rsSubItems("subitem_id"))
  349.                             Else 'For matrix option questions, there is no answer text to record
  350.                                 strAnswerText = SUR_ANSWER_TEXT_NULL
  351.                             End If
  352.  
  353.                             'Insert a record for each selected answer
  354.                             strSQL = "INSERT INTO sur_response_answer(response_id, item_id, subitem_id, answer_id, answer_text, other_text) VALUES(" & _
  355.                                         lngResponseID & ", " & lngItemID & ", " & rsSubItems("subitem_id") & ", " & _
  356.                                         Request.Form("QID" & CStr(lngItemID) & "||SIID" & rsSubItems("subitem_id")) & ", " & _
  357.                                         SQLEncode(strAnswerText) & ", " & _
  358.                                         SQLEncode(SUR_ANSWER_TEXT_NULL) & ")"
  359.                             conSurvey.Execute ConvertSQL(strSQL), , adCmdText
  360.                             flgInsertedResponse = True
  361.                         End If
  362.                         rsSubItems.MoveNext
  363.                     Loop
  364.                     rsSubItems.Close
  365.                     Set rsSubItems = Nothing
  366.  
  367.                     'If no value was selected for the option button, insert an answer with all null values, as explained above.
  368.                     If flgInsertedResponse = False Then
  369.                         strSQL = "INSERT INTO sur_response_answer(response_id, item_id, answer_id, answer_text, other_text) VALUES(" & _
  370.                                     lngResponseID & ", " & lngItemID & ", " & SUR_ANSWER_ID_NULL & ", " & _
  371.                                     SQLEncode(SUR_ANSWER_TEXT_NULL) & ", " & SQLEncode(SUR_ANSWER_TEXT_NULL) & ")"
  372.                         conSurvey.Execute ConvertSQL(strSQL), , adCmdText
  373.                     End If
  374.  
  375.                     'All SQL has already been executed, so do not allow any other SQL statements to execute for this item
  376.                     flgExecuteSQL = False
  377.                 Case SUR_ITEM_MATRIX_TEXT_BOXES:
  378.                     'Set a flag to indicate whether or not a row has been inserted for the textboxes.  It's possible not to
  379.                     'insert any data if the question is not required and the user does not enter any values.  For correctness and
  380.                     'consistency in the reporting, it's necessary to have an entry for "null" responses to the checkboxes
  381.                     flgInsertedResponse = False
  382.  
  383.                     'For updates, delete all of the previous answers before inserting the current set of answers.
  384.                     If flgUpdatingSurvey = True Then
  385.                         strSQL = "DELETE FROM sur_response_answer WHERE response_id = " & lngResponseID & " AND item_id = " & lngItemID
  386.                         conSurvey.Execute ConvertSQL(strSQL), , adCmdText
  387.                     End if
  388.  
  389.                     'Create recordsets for both the subitems (rows) and answers (columns).
  390.                     strSQL = "SELECT subitem_id, subitem_text FROM sur_subitem " & _
  391.                              "WHERE item_id = " & lngItemID & " ORDER BY order_number"
  392.                     Set rsSubItems = conSurvey.Execute(ConvertSQL(strSQL), , adCmdText)
  393.                     strSQL = "SELECT answer_id FROM sur_item_answer " & _
  394.                              "WHERE item_id = " & lngItemID & " ORDER BY order_number"
  395.                     Set rsAnswers = conSurvey.Execute(ConvertSQL(strSQL), , adCmdText)
  396.  
  397.                     'Loop through the answers recordset and create a collection.  Doing this allows us to create
  398.                     'the recordset forward-only, and to loop through it only once, which both improve performance.
  399.                     rsAnswers.MoveFirst
  400.                     Do While Not rsAnswers.EOF
  401.                         lngColumnCount = lngColumnCount + 1
  402.                         strColumnsCollection = strColumnsCollection & CStr(lngColumnCount) & ";" & rsAnswers("answer_id") & ";"
  403.                         rsAnswers.MoveNext
  404.                     Loop
  405.                     rsAnswers.Close
  406.                     Set rsAnswers = Nothing
  407.  
  408.                     'Loop through the subitems (rows), and within each loop, loop through the answers (columns) to extract
  409.                     'the value for each text box.
  410.                     rsSubItems.MoveFirst
  411.                     Do While Not rsSubItems.EOF
  412.                         'For each row, loop through each column, and extract the value from the control.
  413.                         For i = 1 To lngColumnCount
  414.                             'If an answer was submitted for this item, insert a record into the database
  415.                             If Len(Trim(Request.Form("QID" & lngItemID & "||SIID" & rsSubItems("subitem_id") & "||AID" & GetValueFromCollection(strColumnsCollection, CStr(i))))) > 0 Then
  416.                                 'Insert a record for each selected answer
  417.                                 strSQL = "INSERT INTO sur_response_answer(response_id, item_id, subitem_id, answer_id, answer_text, other_text) VALUES(" & _
  418.                                             lngResponseID & ", " & lngItemID & ", " & rsSubItems("subitem_id") & ", " & _
  419.                                             GetValueFromCollection(strColumnsCollection, CStr(i)) & ", " & _
  420.                                             SQLEncode(Request.Form("QID" & lngItemID & "||SIID" & rsSubItems("subitem_id") & "||AID" & GetValueFromCollection(strColumnsCollection, CStr(i)))) & ", " & _
  421.                                             SQLEncode(SUR_ANSWER_TEXT_NULL) & ")"
  422.                                 conSurvey.Execute ConvertSQL(strSQL), , adCmdText
  423.                                 flgInsertedResponse = True
  424.                             End If
  425.                         Next
  426.                         rsSubItems.MoveNext
  427.                     Loop
  428.                     rsSubItems.Close
  429.                     Set rsSubItems = Nothing
  430.  
  431.                     'If no value was selected for the option button, insert an answer with all null values, as explained above.
  432.                     If flgInsertedResponse = False Then
  433.                         strSQL = "INSERT INTO sur_response_answer(response_id, item_id, subitem_id, answer_id, answer_text, other_text) VALUES(" & _
  434.                                     lngResponseID & ", " & lngItemID & ", " & SUR_ANSWER_ID_NULL & ", " & SUR_ANSWER_ID_NULL & ", " & _
  435.                                     SQLEncode(SUR_ANSWER_TEXT_NULL) & ", " & SQLEncode(SUR_ANSWER_TEXT_NULL) & ")"
  436.                         conSurvey.Execute ConvertSQL(strSQL), , adCmdText
  437.                     End If
  438.  
  439.                     'All SQL has already been executed, so do not allow any other SQL statements to execute for this item
  440.                     flgExecuteSQL = False
  441.                 Case SUR_ITEM_MATRIX_MULTISELECT_CHECKBOXES:
  442.                     'Set a flag to indicate whether or not a row has been inserted for the checkboxes.  It's possible not to
  443.                     'insert any data if the question is not required and the user does not enter any values.  For correctness and
  444.                     'consistency in the reporting, it's necessary to have an entry for "null" responses to the checkboxes
  445.                     flgInsertedResponse = False
  446.  
  447.                     'For updates, delete all of the previous answers before inserting the current set of answers.
  448.                     If flgUpdatingSurvey = True Then
  449.                         strSQL = "DELETE FROM sur_response_answer WHERE response_id = " & lngResponseID & " AND item_id = " & lngItemID
  450.                         conSurvey.Execute ConvertSQL(strSQL), , adCmdText
  451.                     End if
  452.  
  453.                     'Create recordsets for both the subitems (rows) and answers (columns).
  454.                     strSQL = "SELECT subitem_id, subitem_text FROM sur_subitem " & _
  455.                              "WHERE item_id = " & lngItemID & " ORDER BY order_number"
  456.                     Set rsSubItems = conSurvey.Execute(ConvertSQL(strSQL), , adCmdText)
  457.                     strSQL = "SELECT answer_id FROM sur_item_answer " & _
  458.                              "WHERE item_id = " & lngItemID & " ORDER BY order_number"
  459.                     Set rsAnswers = conSurvey.Execute(ConvertSQL(strSQL), , adCmdText)
  460.  
  461.                     'Loop through the answers recordset and create a collection.  Doing this allows us to create
  462.                     'the recordset forward-only, and to loop through it only once, which both improve performance.
  463.                     rsAnswers.MoveFirst
  464.                     Do While Not rsAnswers.EOF
  465.                         lngColumnCount = lngColumnCount + 1
  466.                         strColumnsCollection = strColumnsCollection & CStr(lngColumnCount) & ";" & rsAnswers("answer_id") & ";"
  467.                         rsAnswers.MoveNext
  468.                     Loop
  469.                     rsAnswers.Close
  470.                     Set rsAnswers = Nothing
  471.  
  472.                     'Loop through the subitems (rows), and within each loop, loop through the answers (columns) to extract
  473.                     'the value for each checkbox.
  474.                     rsSubItems.MoveFirst
  475.                     Do While Not rsSubItems.EOF
  476.                         'For each row, loop through each column, and extract the value from the control.
  477.                         For i = 1 To lngColumnCount
  478.                             'If an answer was submitted for this item, insert a record into the database
  479.                             If Request.Form("QID" & lngItemID & "||SIID" & rsSubItems("subitem_id") & "||AID" & GetValueFromCollection(strColumnsCollection, CStr(i))) = "on" Then
  480.                                 'Insert a record for each selected answer
  481.                                 strSQL = "INSERT INTO sur_response_answer(response_id, item_id, subitem_id, answer_id, answer_text, other_text) VALUES(" & _
  482.                                             lngResponseID & ", " & lngItemID & ", " & rsSubItems("subitem_id") & ", " & _
  483.                                             GetValueFromCollection(strColumnsCollection, CStr(i)) & ", " & _
  484.                                             SQLEncode(SUR_ANSWER_TEXT_NULL) & ", " & _
  485.                                             SQLEncode(SUR_ANSWER_TEXT_NULL) & ")"
  486.                                 conSurvey.Execute ConvertSQL(strSQL), , adCmdText
  487.                                 flgInsertedResponse = True
  488.                             End If
  489.                         Next
  490.                         rsSubItems.MoveNext
  491.                     Loop
  492.                     rsSubItems.Close
  493.                     Set rsSubItems = Nothing
  494.  
  495.                     'If no value was selected for the option button, insert an answer with all null values, as explained above.
  496.                     If flgInsertedResponse = False Then
  497.                         strSQL = "INSERT INTO sur_response_answer(response_id, item_id, answer_id, answer_text, other_text) VALUES(" & _
  498.                                     lngResponseID & ", " & lngItemID & ", " & SUR_ANSWER_ID_NULL & ", " & _
  499.                                     SQLEncode(SUR_ANSWER_TEXT_NULL) & ", " & SQLEncode(SUR_ANSWER_TEXT_NULL) & ")"
  500.                         conSurvey.Execute ConvertSQL(strSQL), , adCmdText
  501.                     End If
  502.  
  503.                     'All SQL has already been executed, so do not allow any other SQL statements to execute for this item
  504.                     flgExecuteSQL = False
  505.                 Case SUR_ITEM_MULTISELECT_CHECKBOXES:
  506.                     'Set a flag to indicate whether or not a row has been inserted for the checkboxes.  It's possible not to
  507.                     'insert any data if the question is not required and the user does not select any values.  For correctness
  508.                     'and consistency in the reporting, it's necessary to have an entry for "null" responses to the checkboxes.
  509.                     flgInsertedResponse = False
  510.  
  511.                     'For updates, delete all of the previous answers before inserting the current set of answers.
  512.                     If flgUpdatingSurvey = True Then
  513.                         strSQL = "DELETE FROM sur_response_answer WHERE response_id = " & lngResponseID & " AND item_id = " & lngItemID
  514.                         conSurvey.Execute ConvertSQL(strSQL), , adCmdText
  515.                     End if
  516.  
  517.                     'Loop through each of the answers and see if it is checked in the form.  If so, insert an entry
  518.                     'into the database.
  519.                     strSQL = "SELECT answer_id FROM sur_item_answer " & _
  520.                                 "WHERE item_id = " & lngItemID & " ORDER BY order_number"
  521.                     Set rsAnswers = conSurvey.Execute(ConvertSQL(strSQL), , adCmdText)
  522.  
  523.                     rsAnswers.MoveFirst
  524.                     Do While Not rsAnswers.EOF
  525.                         If Request.Form("QID" & CStr(lngItemID) & "||CHECKBOX||" & rsAnswers("answer_id")) = "on" Then
  526.                             'Insert a record for each checked answer
  527.                             strSQL = "INSERT INTO sur_response_answer(response_id, item_id, answer_id, answer_text, other_text) VALUES(" & _
  528.                                         lngResponseID & ", " & lngItemID & ", " & rsAnswers("answer_id") & ", " & _
  529.                                         SQLEncode(SUR_ANSWER_TEXT_NULL) & ", " & SQLEncode(SUR_ANSWER_TEXT_NULL) & ")"
  530.                             conSurvey.Execute ConvertSQL(strSQL), , adCmdText
  531.                             flgInsertedResponse = True
  532.                         End If
  533.                         rsAnswers.MoveNext
  534.                     Loop
  535.                     rsAnswers.Close
  536.                     Set rsAnswers = Nothing
  537.  
  538.                     'See if the "OTHER" check box was checked, and if so, insert a record in the database.  Set the flag for
  539.                     'executing the SQL based on whether or not an "OTHER" value entered.
  540.                     lngAnswerID = SUR_ANSWER_ID_NULL
  541.                     If Request.Form("QID" & CStr(lngItemID) & "||OTHERCHECKBOX") = "on" Then
  542.                         'If the answer ID is "OTHER", insert NULL for the answer_id column, insert a value indicating that
  543.                         '"OTHER" was selected in the answer column, and insert the "OTHER" value in the other_text column
  544.                         strAnswerText = SUR_ANSWER_TEXT_OTHER_SELECTED
  545.                         strOtherText = Trim(Request.Form("QID" & CStr(lngItemID) & "OTHERTEXT"))
  546.  
  547.                         'If no text was entered in the "Other" text box, use the null value
  548.                         If Len(strOtherText) = 0 Then
  549.                             strOtherText = SUR_ANSWER_TEXT_NULL
  550.                         End If
  551.  
  552.                         'Insert a record for the "other" item
  553.                         strSQL = "INSERT INTO sur_response_answer(response_id, item_id, answer_id, answer_text, other_text) VALUES(" & _
  554.                                     lngResponseID & ", " & lngItemID & ", " & lngAnswerID & ", " & _
  555.                                     SQLEncode(strAnswerText) & ", " & SQLEncode(strOtherText) & ")"
  556.                         conSurvey.Execute ConvertSQL(strSQL), , adCmdText
  557.                         flgInsertedResponse = True
  558.                     End If
  559.  
  560.                     'If no value was entered for the checkboxes, insert an answer with all null values, as explained above.
  561.                     If flgInsertedResponse = False Then
  562.                         strSQL = "INSERT INTO sur_response_answer(response_id, item_id, answer_id, answer_text, other_text) VALUES(" & _
  563.                                     lngResponseID & ", " & lngItemID & ", " & SUR_ANSWER_ID_NULL & ", " & _
  564.                                     SQLEncode(SUR_ANSWER_TEXT_NULL) & ", " & SQLEncode(SUR_ANSWER_TEXT_NULL) & ")"
  565.                         conSurvey.Execute ConvertSQL(strSQL), , adCmdText
  566.                     End If
  567.  
  568.                     'All SQL has already been executed, so do not allow any other SQL statements to execute for this item
  569.                     flgExecuteSQL = False
  570.                 Case SUR_ITEM_RANKING, SUR_ITEM_CONSTANT_SUM, SUR_ITEM_OPEN_ENDED_ONE_OR_MORE_LINES:
  571.                     'Set a flag to indicate whether or not a row has been inserted for the ranking items.  It's possible not to
  572.                     'insert any data if the question is not required and the user does not enter any values.  For correctness and
  573.                     'consistency in the reporting, it's necessary to have an entry for "null" responses to the checkboxes
  574.                     flgInsertedResponse = False
  575.  
  576.                     'For updates, delete all of the previous answers before inserting the current set of answers.
  577.                     If flgUpdatingSurvey = True Then
  578.                         strSQL = "DELETE FROM sur_response_answer WHERE response_id = " & lngResponseID & " AND item_id = " & lngItemID
  579.                         conSurvey.Execute ConvertSQL(strSQL), , adCmdText
  580.                     End if
  581.  
  582.                     'Loop through each of the subitems and see if a value was entered in the form.  If so, insert an
  583.                     'entry into the database.
  584.                     strSQL = "SELECT subitem_id, subitem_text FROM sur_subitem WHERE item_id = " & lngItemID & " ORDER BY order_number"
  585.                     Set rsSubItems = conSurvey.Execute(ConvertSQL(strSQL), , adCmdText)
  586.  
  587.                     rsSubItems.MoveFirst
  588.                     Do While Not rsSubItems.EOF
  589.                         'If an answer was submitted for this item, insert a record into the database
  590.                         If Len(Trim(Request.Form("QID" & CStr(lngItemID) & "||SIID" & rsSubItems("subitem_id")))) > 0 Then
  591.                             'Insert a record for each checked answer
  592.                             strSQL = "INSERT INTO sur_response_answer(response_id, item_id, subitem_id, answer_id, answer_text, other_text) VALUES(" & _
  593.                                         lngResponseID & ", " & lngItemID & ", " & rsSubItems("subitem_id") & ", " & _
  594.                                         SUR_ANSWER_ID_NULL & ", " & _
  595.                                         SQLEncode(Request.Form("QID" & CStr(lngItemID) & "||SIID" & rsSubItems("subitem_id"))) & ", " & _
  596.                                         SQLEncode(SUR_ANSWER_TEXT_NULL) & ")"
  597.                             conSurvey.Execute ConvertSQL(strSQL), , adCmdText
  598.                             flgInsertedResponse = True
  599.                         End If
  600.                         rsSubItems.MoveNext
  601.                     Loop
  602.                     rsSubItems.Close
  603.                     Set rsSubItems = Nothing
  604.  
  605.                     'If no value was entered for the ranking options, insert an answer with all null values, as explained above.
  606.                     If flgInsertedResponse = False Then
  607.                         strSQL = "INSERT INTO sur_response_answer(response_id, item_id, answer_id, answer_text, other_text) VALUES(" & _
  608.                                     lngResponseID & ", " & lngItemID & ", " & SUR_ANSWER_ID_NULL & ", " & _
  609.                                     SQLEncode(SUR_ANSWER_TEXT_NULL) & ", " & SQLEncode(SUR_ANSWER_TEXT_NULL) & ")"
  610.                         conSurvey.Execute ConvertSQL(strSQL), , adCmdText
  611.                     End If
  612.  
  613.                     'All SQL has already been executed, so do not allow any other SQL statements to execute for this item
  614.                     flgExecuteSQL = False
  615.                 Case SUR_ITEM_OPEN_ENDED_ONE_LINE, SUR_ITEM_DATE, SUR_ITEM_NUMBER, SUR_ITEM_DATABASE_DROPDOWN:
  616.                     'Check to see if a value was supplied for this question, and set the answer text equal to the value if it was
  617.                     'supplied or to the NULL value if not supplied
  618.                     lngAnswerID = SUR_ANSWER_ID_NULL
  619.                     strOtherText = SUR_ANSWER_TEXT_NULL
  620.                     If Len(Trim(Request.Form("QID" & CStr(lngItemID)))) = 0 Then
  621.                         strAnswerText = SUR_ANSWER_TEXT_NULL
  622.                     Else
  623.                         strAnswerText = Trim(Request.Form("QID" & CStr(lngItemID)))
  624.                     End If
  625.                 Case SUR_ITEM_OPEN_ENDED_COMMENTS_BOX:
  626.                     'Check to see if a value was supplied for this question, and set the answer text equal to the value if it was
  627.                     'supplied or to the NULL value if not supplied
  628.                     lngAnswerID = SUR_ANSWER_ID_NULL
  629.                     strOtherText = SUR_ANSWER_TEXT_NULL
  630.                     If Len(Request.Form("QID" & CStr(lngItemID))) = 0 Then
  631.                         strAnswerText = SUR_ANSWER_TEXT_NULL
  632.                     Else
  633.                         strAnswerText = Trim(Request.Form("QID" & CStr(lngItemID)))
  634.                     End If
  635.             End Select
  636.  
  637.             'If everything is OK, save the answer
  638.  
  639. '---10/28/2005 for responses that are not deleted before insert, prevent multiple responses.
  640. 'If flgExecuteSQL = True Then
  641. '    'query to see if user already clicked done then the back button
  642. '    tmpAnsSql = "SELECT * FROM sur_response_answer WHERE response_id = " & lngResponseID & " AND item_id = " & lngItemID
  643. '    rsTmpAns.Open ConvertSQL(tmpAnsSql), SURVEY_APP_CONNECTION, adOpenForwardOnly, adLockReadOnly, adCmdText
  644. '    If rsTmpAns.EOF Then
  645. '        'do nothing
  646. '    Else
  647. '        If Session("SUR_COMPLETE") = lngResponseID then
  648. '            'user already hit done then back dont insert multiple responses for this response id
  649. '            flgExecuteSQL = False
  650. '        End If
  651. '    End If
  652. '    rsTmpAns.Close
  653. 'End If
  654.             If flgExecuteSQL = True Then
  655.                 'Either update the results from a previously taken survey or insert results for a first time survey
  656.  
  657. '10/17/2005 fixing multiple response issue w/multiple response surveys vs single response.
  658. '--the below prevents duplicate inserts for the same question for same responseid.
  659. '    tmpAnsSql = "SELECT * FROM sur_response_answer WHERE response_id = " & lngResponseID & " AND item_id = " & lngItemID
  660. '    rsTmpAns.Open ConvertSQL(tmpAnsSql), SURVEY_APP_CONNECTION, adOpenForwardOnly, adLockReadOnly, adCmdText
  661. '    If NOT rsTmpAns.EOF AND Session("SUR_COMPLETE") = lngResponseID then
  662. '        flgUpdatingSurvey = True
  663. '    End If
  664. '    rsTmpAns.Close
  665.  
  666.  
  667.                 If flgUpdatingSurvey = True Then
  668.  
  669.                     strSQL = "UPDATE sur_response_answer " & _
  670.                                 "SET answer_text = " & SQLEncode(strAnswerText) & ", " & _
  671.                                 "other_text = " & SQLEncode(strOtherText) & ", " & _
  672.                                 "answer_id = " & lngAnswerID & _
  673.                                 " WHERE response_id = " & lngResponseID & _
  674.                                 " AND item_id = " & lngItemID
  675.                 Else 'Inserting results for a new survey
  676.                     strSQL = "INSERT INTO sur_response_answer(response_id, item_id, answer_id, answer_text, other_text) VALUES(" & _
  677.                                 lngResponseID & ", " & lngItemID & ", " & lngAnswerID & ", " & _
  678.                                 SQLEncode(strAnswerText) & ", " & SQLEncode(strOtherText) & ")"
  679.                 End If
  680.                  conSurvey.Execute ConvertSQL(strSQL), , adCmdText
  681.             End If
  682.  
  683.             rsItems.MoveNext
  684.         Loop
  685.     End If 'If Not rsItems.EOF Then
  686.  
  687.     'Clean up
  688.     rsItems.Close
  689.     conSurvey.Close
  690.     Set rsItems = Nothing
  691.     Set conSurvey = Nothing
  692.  
  693.     'Preserve the current actual page number, plus one, as the first page to start deleting "dangling" answers,
  694.     'as described below.
  695.     lngPageToDeleteAnswers = lngActualPageNumber + 1
  696.  
  697.     'Get the next page to display.  If there is no response ID, then this was a first page with no answerable
  698.     'questions, so just add one to the current page
  699.     If Len(lngResponseID) = 0 Then
  700.         lngNextPageNumber = lngActualPageNumber + 1
  701.     Else
  702.         lngNextPageNumber = GetNextPageInSurvey(lngSurveyID, lngResponseID, lngActualPageNumber)
  703.     End If
  704.  
  705.     'If the user is updating a survey, delete responses for all pages between the page just executed and the page
  706.     'about to be displayed.  This is necessary for the odd case where page condition logic allows a user to answer
  707.     'a question, but when they update their survey, that question is not displayed the second time around because
  708.     'of a different answer to a question.
  709.     conDelete.Open SURVEY_APP_CONNECTION
  710.     If lngNextPageNumber = SUR_END_OF_SURVEY Then
  711.         'If there are no more pages to display, delete all of the answers on all of the remaining pages in the survey.
  712.         'Doing this will delete "dangling" responses on all of the remaining pages.
  713.  
  714.         'Begin by getting total page count, and setting the page number pointer to the next page.
  715.         lngTotalPageCount = GetPageCount(lngSurveyID)
  716.         lngCurrentPageNumber = lngCurrentPageNumber + 1
  717.  
  718.         'Loop through the remaining pages in the survey
  719.         Do While lngCurrentPageNumber <= lngTotalPageCount
  720.             'Delete all of the answers from sur_response_answer table for "dangling answers," as explained above.
  721.             strSQL = "DELETE FROM sur_response_answer " & _
  722.                      "WHERE response_id = " & lngResponseID & _
  723.                      " AND item_id IN (" & _
  724.                         ConvertSQLInClause("SELECT item_id " & _
  725.                         "FROM sur_survey_to_item_mapping " & _
  726.                         "WHERE page_number = " & lngCurrentPageNumber & _
  727.                         " AND survey_id = " & lngSurveyID, "item_id") & ")"
  728.             conDelete.Execute ConvertSQL(strSQL), , adCmdText
  729.             lngCurrentPageNumber = lngCurrentPageNumber + 1
  730.         Loop
  731.     Else
  732.         'Loop through the pages between the page just processed and the next page to be displayed.
  733.         Do While lngNextPageNumber > lngPageToDeleteAnswers
  734.             'Delete all of the answers from sur_response_answer table for "dangling answers," as explained above.
  735.             strSQL = "DELETE FROM sur_response_answer " & _
  736.                      "WHERE response_id = " & lngResponseID & _
  737.                      " AND item_id IN (" & _
  738.                         ConvertSQLInClause("SELECT item_id " & _
  739.                         "FROM sur_survey_to_item_mapping " & _
  740.                         "WHERE page_number = " & lngPageToDeleteAnswers & _
  741.                         " AND survey_id = " & lngSurveyID, "item_id") & ")"
  742.             conDelete.Execute ConvertSQL(strSQL), , adCmdText
  743.             lngPageToDeleteAnswers = lngPageToDeleteAnswers + 1
  744.         Loop
  745.     End If
  746.     conDelete.Close
  747.     Set conDelete = Nothing
  748.  
  749.     'If the survey is completed, update the response to indicate that it is complete
  750.     If lngNextPageNumber = SUR_END_OF_SURVEY Then
  751.         conUpdate.Open SURVEY_APP_CONNECTION
  752.         strSQL = "UPDATE sur_response " & _
  753.                     "SET completed_yn = " & SQLEncode(SUR_BOOLEAN_POSITIVE) & ", " & _
  754.                     "response_end_date = GETDATE() " & _
  755.                     "WHERE response_id = " & lngResponseID
  756.         conUpdate.Execute ConvertSQL(strSQL), , adCmdText
  757.         conUpdate.Close
  758.         Set conUpdate = Nothing
  759.     End If
  760.  
  761.     'Set a variable indicating whether or not the page is in edit mode (being done by a survey owner or an admin)
  762.     If Request.Form("AdminOrOwnerEditResponse") = SUR_BOOLEAN_POSITIVE_DISPLAY Then
  763.         strEditValue = SUR_BOOLEAN_POSITIVE_DISPLAY
  764.     Else
  765.         strEditValue = SUR_BOOLEAN_NEGATIVE_DISPLAY
  766.     End If
  767.  
  768.     '--9/29/2005: fix multiple answers for responseid bug
  769.     '--10/28/2005: move this after update/insert so saves last page
  770.     If Request.Form("DoneClicked") = 1 Then
  771.         Session("SUR_COMPLETE") = Request.Form("SurveyComplete")
  772.     End If
  773.  
  774.     'If this is the last page, redirect to the survey complete page.  If this is not the last page of the survey,
  775.     'redirect to the next page in the survey.
  776.     If lngNextPageNumber = SUR_END_OF_SURVEY Then
  777.         Response.Redirect "TakeSurveyActionComplete.asp?DisplayHeader=" & Request.QueryString("DisplayHeader") & "&SurveyID=" & EncryptSurveyID(lngSurveyID) & "&Edit=" & strEditValue & "&ResponseID=" & lngResponseID
  778.     Else
  779.         'If there were predefined answers tacked onto the querystring, add them to the querystring
  780.         If Len(Request.Form("ItemIDValues")) > 0 Then
  781.             strItemIDValues = "&" & Request.Form("ItemIDValues")
  782.         Else
  783.             strItemIDValues = ""
  784.         End If
  785.  
  786.         'Change the format of the URL in the case where a survey taken via an EID (email invitation) had no answerable
  787.         'questions on the first page.  This is necessary in order to track the response being from an email invitation
  788.         'on the second page of the survey.
  789.         If flgHadAnswerableQuestions = False And Len(Request.Form("EID")) > 0 Then
  790.             Response.Redirect "TakeSurvey.asp?SurveyID=" & EncryptSurveyID(lngSurveyID) & "&PreviousActualPageNumber=" & CStr(Request.Form("ActualPageNumber")) & "&PreviousDisplayPageNumber=" & CStr(Request.Form("DisplayPageNumber")) & "&PreviousQuestionNumber=" & Request.Form("DisplayPageNumber") & "&ActualPageNumber=" & CLng(lngNextPageNumber) & "&DisplayPageNumber=" & CLng(lngDisplayPageNumber) + 1 & "&ResponseID=" & lngResponseID & "&QuestionNumber=" & Request.Form("QuestionNumber") & "&Edit=" & strEditValue & "&DisplayHeader=" & Request.QueryString("DisplayHeader") & "&EID=" & Request.Form("EID") & strItemIDValues
  791.         Else
  792.             Response.Redirect "TakeSurvey.asp?SurveyID=" & EncryptSurveyID(lngSurveyID) & "&PreviousActualPageNumber=" & CStr(Request.Form("ActualPageNumber")) & "&PreviousDisplayPageNumber=" & CStr(Request.Form("DisplayPageNumber")) & "&PreviousQuestionNumber=" & Request.Form("DisplayPageNumber") & "&ActualPageNumber=" & CLng(lngNextPageNumber) & "&DisplayPageNumber=" & CLng(lngDisplayPageNumber) + 1 & "&ResponseID=" & lngResponseID & "&QuestionNumber=" & Request.Form("QuestionNumber") & "&Edit=" & strEditValue & "&DisplayHeader=" & Request.QueryString("DisplayHeader") & strItemIDValues
  793.         End If
  794.     End If
  795. %>
  796.