home *** CD-ROM | disk | FTP | other *** search
/ bombers.k12.ar.us / bombers.k12.ar.us.tar / bombers.k12.ar.us / survey / CreateSurveyAction.asp < prev    next >
Text File  |  2006-11-29  |  25KB  |  548 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 creates a new survey either from scratch or by
  7. '                      copying an existing survey.
  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/Utility_inc.asp"-->
  18. <!--#Include File="Include/adovbs_inc.asp"-->
  19. <!--#Include File="Include/ID_inc.asp"-->
  20. <!--#Include File="Include/CurrentUser_inc.asp"-->
  21. <!--#Include File="Include/SurveySecurity_inc.asp"-->
  22. <!--#Include File="Include/Constants_inc.asp"-->
  23. <!--#Include File="Include/Collection_inc.asp"-->
  24. <%
  25.  
  26.  
  27.     'If the user does not have "Create" or "Admin" permission, redirect them to the access denied page.
  28.     If lngUserSecurityLevel <> SUR_SECURITY_LEVEL_CREATE And lngUserSecurityLevel <> SUR_SECURITY_LEVEL_ADMIN Then
  29.         Response.Redirect "AccessDenied.asp?Reason=" & SUR_ACCESS_DENIED_NOT_ADMIN_SECURITY_LEVEL
  30.     End If
  31.  
  32.     Dim strSQL
  33.     Dim conNewSurvey
  34.     Dim lngOriginalSurveyID
  35.     Dim lngNewSurveyID
  36.     Dim rsOriginalSurvey
  37.     Dim strStartDate
  38.     Dim strEndDate
  39.     Dim lngTempID
  40.     Dim lngMinimumNumberResponses
  41.     Dim lngMaximumNumberResponses
  42.     Dim lngRowTextWidth
  43.     Dim lngAnswerTotal
  44.     Dim strOldToNewItemIDs
  45.     Dim strOldToNewAnswerIDs
  46.     Dim lngNewItemID
  47.     Dim lngNewAnswerID
  48.     Dim strOwners
  49.     Dim strMinimumValue
  50.     Dim strMaximumValue
  51.     Dim strItemText
  52.     Dim strItemSubText
  53.     Dim strItemAlias
  54.     Dim vaItemIDs
  55.     Dim i
  56.     Dim lngAnswerValue
  57.  
  58.     'Initialization
  59.     Set rsOriginalSurvey = Server.CreateObject("ADODB.Recordset")
  60.     Set conNewSurvey = Server.CreateObject("ADODB.Connection")
  61.     '***SB 5/30/2006
  62.     '3 minutes
  63.     conNewSurvey.CommandTimeout = 180
  64.     conNewSurvey.connectionTimeout = 180
  65.     server.ScriptTimeout = 180
  66.     conNewSurvey.Open SURVEY_APP_CONNECTION
  67.     lngNewSurveyID = ID_GetNextAvailableID("SurveyGenerationSurvey")
  68.  
  69.     If CLng(Request.Form("optType")) = SUR_CREATE_SURVEY_FROM_SCRATCH Then
  70.         'This section creates a new survey from scratch
  71.  
  72.         'Initialize the start and end dates
  73.  
  74.  
  75. '***SB 6/22/2006
  76.             If SUR_DATABASE_TYPE = "SQLServer" Then
  77.                 strEndDate = "(DATEADD([day], 30, GETDATE()))"
  78.                 strStartDate = "GETDATE()"
  79.             End If
  80.             If SUR_DATABASE_TYPE = "MSAccess" Then
  81.                 strEndDate = "(NOW + 30)"
  82.                 strStartDate = "(NOW)"
  83.  
  84.             End If
  85.             If SUR_DATABASE_TYPE = "MySQL" Then
  86.                 strEndDate = "(DATE_ADD(CURRENT_DATE, INTERVAL 30 DAY))"
  87.                 strStartDate = "(CURRENT_DATE)"
  88.             End If
  89.             If strStartDate = "" Then
  90.                 strStartDate = CustomDateFormatInsert(Date())
  91.                 strEndDate = CustomDateFormatInsert(DateAdd("m", 1, Date()))
  92.             End If
  93.  
  94.         'Create a new survey using all of the default values
  95.         strSQL = "INSERT INTO sur_survey(survey_id, title, template_id, closed_date, " & _
  96.                  "created_date, launched_date, start_date, end_date, maximum_responses_for_survey, response_count, " & _
  97.                  "completion_action, survey_complete_message, survey_complete_display_close, " & _
  98.                  "survey_complete_display_continue, survey_complete_display_reports, survey_language, status, report_sharing_enabled_yn, " & _
  99.                  "report_security, page_numbering_format, question_numbering_format, owners, respondent_access_level, " & _
  100.                  "survey_complete_redirect_url, response_email_addresses, admin_email_address, highlight_responses_yn, " & _
  101.                  "maximum_responses_per_user, modify_survey_within_days, back_button_display, cancel_button_display, " & _
  102.                  "cancel_button_redirect_url) " & _
  103.                  "VALUES(" & lngNewSurveyID & ", " & _
  104.                  SQLEncode(Request.Form("txtTitle")) & ", " & _
  105.                  SUR_DEFAULT_TEMPLATE_ID & ", " & _
  106.                  "Null, " & strStartDate & ", Null, " & _
  107.                  strStartDate & ", " & _
  108.                  strEndDate & ", " & _
  109.                  SUR_UNLIMITED_RESPONSES & ", 0, " & _
  110.                  SQLEncode(SUR_DEFAULT_COMPLETION_ACTION) & ", " & _
  111.                  "'Thank you for taking the survey!', " & _
  112.                  SQLEncode(SUR_DEFAULT_SURVEY_COMPLETE_DISPLAY_CLOSE) & ", " & _
  113.                  SQLEncode(SUR_DEFAULT_SURVEY_COMPLETE_DISPLAY_CONTINUE) & ", " & _
  114.                  SQLEncode(SUR_DEFAULT_SURVEY_COMPLETE_DISPLAY_REPORTS) & ", " & _
  115.                  SQLEncode(SUR_DEFAULT_SURVEY_LANGUAGE) & ", " & _
  116.                  SQLEncode(SUR_STATUS_DESIGN) & ", " & _
  117.                  SQLEncode(SUR_BOOLEAN_NEGATIVE) & ", " & _
  118.                  SQLEncode(SUR_REPORT_SECURITY_OWNERS_ONLY) & ", " & _
  119.                  SQLEncode(SUR_PAGE_NUMBERING_DISPLAY_PROGRESS_BAR) & ", " & _
  120.                  SQLEncode(SUR_QUESTION_NUMBERING_ENTIRE_SURVEY) & ", " & _
  121.                  SQLEncode(GetUserName()) & ", " & _
  122.                  SUR_RESPONDENT_ACCESS_LEVEL_MULTIPLE_ANONYMOUS & ", " & _
  123.                  "'', " & _
  124.                  "'', " & _
  125.                  SQLEncode(GetUserEmailAddress()) & ", " & _
  126.                  SQLEncode(SUR_BOOLEAN_NEGATIVE) & ", " & _
  127.                  SUR_UNLIMITED_RESPONSES & ", " & _
  128.                  "30, " & _
  129.                  SQLEncode(SUR_DEFAULT_BACK_BUTTON) & ", " & _
  130.                  SQLEncode(SUR_DEFAULT_CANCEL_BUTTON) & ", " & _
  131.                  "'')"
  132.         conNewSurvey.Execute ConvertSQL(strSQL), , adCmdText
  133.     Else 'SUR_CREATE_SURVEY_FROM_EXISTING
  134.         lngOriginalSurveyID = Request.Form("cboSurvey")
  135.  
  136.         '1.  Copy all of the data from the survey table (SUR_SURVEY)
  137.         strSQL = "SELECT survey_id, title, template_id, closed_date, created_date, launched_date, report_sharing_enabled_yn, " & _
  138.                     "start_date, end_date, maximum_responses_for_survey, response_count, completion_action, " & _
  139.                     "survey_language, status, report_security, page_numbering_format, question_numbering_format, " & _
  140.                     "respondent_access_level, survey_complete_redirect_url, highlight_responses_yn, admin_email_address, " & _
  141.                     "maximum_responses_per_user, modify_survey_within_days, back_button_display, cancel_button_display, " & _
  142.                     "survey_complete_display_close, survey_complete_display_continue, survey_complete_display_reports, " & _
  143.                     "cancel_button_redirect_url, response_email_addresses, survey_complete_message, owners " & _
  144.                     "FROM sur_survey WHERE survey_id = " & lngOriginalSurveyID
  145.         rsOriginalSurvey.Open ConvertSQL(strSQL), SURVEY_APP_CONNECTION, adOpenForwardOnly, adLockReadOnly, adCmdText
  146.         rsOriginalSurvey.MoveFirst
  147.  
  148.         'Create values needed for the insert
  149.  
  150. '***SB 6/22/2006
  151.             If SUR_DATABASE_TYPE = "SQLServer" Then
  152.                 strEndDate = "(DATEADD([day], 30, GETDATE()))"
  153.                 strStartDate = "GETDATE()"
  154.             End If
  155.             If SUR_DATABASE_TYPE = "MSAccess" Then
  156.                 strEndDate = "(NOW + 30)"
  157.                 strStartDate = "(NOW)"
  158.  
  159.             End If
  160.             If SUR_DATABASE_TYPE = "MySQL" Then
  161.                 strEndDate = "(DATE_ADD(CURRENT_DATE, INTERVAL 30 DAY))"
  162.                 strStartDate = "(CURRENT_DATE)"
  163.             End If
  164.             If strStartDate = "" Then
  165.                 strStartDate = CustomDateFormatInsert(Date())
  166.                 strEndDate = CustomDateFormatInsert(DateAdd("m", 1, Date()))
  167.             End If
  168.  
  169. '**SB end
  170.  
  171.         'The only way that the current user's name could not be in the list of owners is if the user is an admin.  In that
  172.         'case, add the user's name to the list of owners.
  173.         strOwners = rsOriginalSurvey("owners")
  174.         If IsUserSurveyOwner(lngOriginalSurveyID) = False Then
  175.             strOwners = strOwners & ";" & GetUsername()
  176.         End If
  177.  
  178.         '1.  Insert all of the data from the survey table (SUR_SURVEY)
  179.         strSQL = "INSERT INTO sur_survey(survey_id, title, template_id, closed_date, created_date, launched_date, " & _
  180.                     "report_sharing_enabled_yn, start_date, end_date, maximum_responses_for_survey, response_count, completion_action, " & _
  181.                     "survey_complete_message, survey_language, status, report_security, page_numbering_format, question_numbering_format, " & _
  182.                     "owners, respondent_access_level, survey_complete_redirect_url, response_email_addresses, " & _
  183.                     "admin_email_address, maximum_responses_per_user, modify_survey_within_days, " & _
  184.                     "survey_complete_display_close, survey_complete_display_continue, survey_complete_display_reports, " & _
  185.                     "back_button_display, cancel_button_display, cancel_button_redirect_url, highlight_responses_yn) " & _
  186.                     "VALUES(" & lngNewSurveyID & ", " & SQLEncode(Request.Form("txtTitle")) & ", " & _
  187.                     rsOriginalSurvey("template_id") & ", " & _
  188.                     "Null, " & strStartDate & ", Null, " & _
  189.                     SQLEncode(rsOriginalSurvey("report_sharing_enabled_yn")) & ", " & _
  190.                     strStartDate & ", " & _
  191.                     strEndDate & ", " & _
  192.                     rsOriginalSurvey("maximum_responses_for_survey") & ", 0, " & _
  193.                     SQLEncode(rsOriginalSurvey("completion_action")) & ", " & _
  194.                     SQLEncode(rsOriginalSurvey("survey_complete_message")) & ", " & _
  195.                     SQLEncode(rsOriginalSurvey("survey_language")) & ", " & _
  196.                     SQLEncode(SUR_STATUS_DESIGN) & ", " & _
  197.                     SQLEncode(rsOriginalSurvey("report_security")) & ", " & _
  198.                     SQLEncode(rsOriginalSurvey("page_numbering_format")) & ", " & _
  199.                     SQLEncode(rsOriginalSurvey("question_numbering_format")) & ", " & _
  200.                     SQLEncode(strOwners) & ", " & _
  201.                     rsOriginalSurvey("respondent_access_level") & ", " & _
  202.                     SQLEncode(rsOriginalSurvey("survey_complete_redirect_url")) & ", " & _
  203.                     SQLEncode(rsOriginalSurvey("response_email_addresses")) & ", " & _
  204.                     SQLEncode(rsOriginalSurvey("admin_email_address")) & ", " & _
  205.                     rsOriginalSurvey("maximum_responses_per_user") & ", " & _
  206.                     rsOriginalSurvey("modify_survey_within_days") & ", " & _
  207.                     SQLEncode(rsOriginalSurvey("survey_complete_display_close")) & ", " & _
  208.                     SQLEncode(rsOriginalSurvey("survey_complete_display_continue")) & ", " & _
  209.                     SQLEncode(rsOriginalSurvey("survey_complete_display_reports")) & ", " & _
  210.                     SQLEncode(rsOriginalSurvey("back_button_display")) & ", " & _
  211.                     SQLEncode(rsOriginalSurvey("cancel_button_display")) & ", " & _
  212.                     SQLEncode(rsOriginalSurvey("cancel_button_redirect_url")) & ", " & _
  213.                     SQLEncode(rsOriginalSurvey("highlight_responses_yn")) & ")"
  214.         rsOriginalSurvey.Close
  215.         conNewSurvey.Execute ConvertSQL(strSQL), , adCmdText
  216.  
  217.         '2.  Copy all of the data from the item table (SUR_ITEM)
  218.         strSQL = "SELECT * FROM sur_item WHERE item_id IN (" & _
  219.                  ConvertSQLInClause("SELECT item_id " & _
  220.                     "FROM sur_survey_to_item_mapping WHERE survey_id = " & lngOriginalSurveyID, "item_id") & ")"
  221.         rsOriginalSurvey.Open ConvertSQL(strSQL), SURVEY_APP_CONNECTION, adOpenForwardOnly, adLockReadOnly, adCmdText
  222.  
  223.         'Make sure that there are items for this survey
  224.         If Not rsOriginalSurvey.EOF Then
  225.             rsOriginalSurvey.MoveFirst
  226.  
  227.             'Build the SQL statements to insert the new records into the SUR_ITEM table
  228.             Do While Not rsOriginalSurvey.EOF
  229.  
  230.                 'Create values needed for the insert
  231.                 lngMinimumNumberResponses = rsOriginalSurvey("minimum_number_responses")
  232.                 If IsNull(lngMinimumNumberResponses) = True Then
  233.                     lngMinimumNumberResponses = "Null"
  234.                 End If
  235.                 lngMaximumNumberResponses = rsOriginalSurvey("maximum_number_responses")
  236.                 If IsNull(lngMaximumNumberResponses) = True Then
  237.                     lngMaximumNumberResponses = "Null"
  238.                 End If
  239.                 lngRowTextWidth = rsOriginalSurvey("row_text_width")
  240.                 If IsNull(lngRowTextWidth) = True Then
  241.                     lngRowTextWidth= "Null"
  242.                 End If
  243.                 lngAnswerTotal = rsOriginalSurvey("answer_total")
  244.                 If IsNull(lngAnswerTotal) = True Or Len(lngAnswerTotal) = 0 Then
  245.                     lngAnswerTotal = "Null"
  246.                 End If
  247.                 strItemAlias = rsOriginalSurvey("item_alias")
  248.                 If IsNull(strItemAlias) = True Or Len(strItemAlias) = 0 Then
  249.                     strItemAlias = ""
  250.                 End If
  251.  
  252.                 'Create the new ID for the new item
  253.                 lngTempID = ID_GetNextAvailableID("SurveyGenerationItem")
  254.  
  255.                 'Create dictionary of old item ID's to new item ID's
  256.                 strOldToNewItemIDs = strOldToNewItemIDs & rsOriginalSurvey("item_id") & ";" & lngTempID & ";"
  257.  
  258.                 strSQL = "INSERT INTO sur_item(item_id, item_type_id, item_text, item_sub_text, item_alias, required_yn, " & _
  259.                             "random_answer_order_yn, email_address_yn, other_yn, other_text, minimum_value, maximum_value, answer_total, " & _
  260.                             "minimum_number_responses, maximum_number_responses, row_text_width, display_format, image_path, " & _
  261.                             "image_width, image_height, image_alignment, default_value, database_sql, database_dsn, " & _
  262.                             "subitem_count) VALUES(" & _
  263.                             lngTempID & ", " & _
  264.                             rsOriginalSurvey("item_type_id") & ", " & _
  265.                             SQLEncode(rsOriginalSurvey("item_text")) & ", " & _
  266.                             SQLEncode(rsOriginalSurvey("item_sub_text")) & ", " & _
  267.                             SQLEncode(strItemAlias) & ", " & _
  268.                             SQLEncode(rsOriginalSurvey("required_yn")) & ", " & _
  269.                             SQLEncode(rsOriginalSurvey("random_answer_order_yn")) & ", " & _
  270.                             SQLEncode(rsOriginalSurvey("email_address_yn")) & ", " & _
  271.                             SQLEncode(rsOriginalSurvey("other_yn")) & ", " & _
  272.                             SQLEncode(rsOriginalSurvey("other_text")) & ", "
  273.                 'For minimum and maximum values, make sure that Null is not used
  274.                 If IsNull(rsOriginalSurvey("minimum_value")) = True Then
  275.                     strSQL = strSQL & "'', "
  276.                 Else
  277.                     strSQL = strSQL & SQLEncode(rsOriginalSurvey("minimum_value")) & ", "
  278.                 End If
  279.                 If IsNull(rsOriginalSurvey("maximum_value")) = True Then
  280.                     strSQL = strSQL & "'', "
  281.                 Else
  282.                     strSQL = strSQL & SQLEncode(rsOriginalSurvey("maximum_value")) & ", "
  283.                 End If
  284.                 strSQL = strSQL & lngAnswerTotal & ", " & _
  285.                             lngMinimumNumberResponses & ", " & _
  286.                             lngMaximumNumberResponses & ", " & _
  287.                             lngRowTextWidth & ", " & _
  288.                             SQLEncode(rsOriginalSurvey("display_format")) & ", " & _
  289.                             SQLEncode(rsOriginalSurvey("image_path")) & ", " & _
  290.                             SQLEncode(rsOriginalSurvey("image_width")) & ", "
  291.                 'For image height, make sure that Null is not used
  292.                 If IsNull(rsOriginalSurvey("image_height")) = True Then
  293.                     strSQL = strSQL & "'', "
  294.                 Else
  295.                     strSQL = strSQL & SQLEncode(rsOriginalSurvey("image_height")) & ", "
  296.                 End If
  297.                 strSQL = strSQL & SQLEncode(rsOriginalSurvey("image_alignment")) & ", " & _
  298.                             SQLEncode(rsOriginalSurvey("default_value")) & ", " & _
  299.                             SQLEncode(rsOriginalSurvey("database_sql")) & ", " & _
  300.                             SQLEncode(rsOriginalSurvey("database_dsn")) & ", "
  301.                 If IsNull(rsOriginalSurvey("subitem_count")) = True Then
  302.                     strSQL = strSQL & "Null"
  303.                 Else
  304.                     strSQL = strSQL & SQLEncode(rsOriginalSurvey("subitem_count"))
  305.                 End If
  306.                 strSQL = strSQL & ")"
  307.  
  308.                 conNewSurvey.Execute ConvertSQL(strSQL), , adCmdText
  309.                 rsOriginalSurvey.MoveNext
  310.             Loop
  311.         End If
  312.         rsOriginalSurvey.Close
  313.  
  314.         '3.  Copy all of the data from the item answer table (SUR_ITEM_ANSWER)
  315.         strSQL = "SELECT * FROM sur_item_answer WHERE item_id IN (" & _
  316.                  ConvertSQLInClause("SELECT item_id " & _
  317.                     "FROM sur_survey_to_item_mapping WHERE survey_id = " & lngOriginalSurveyID, "item_id") & ")"
  318.         rsOriginalSurvey.Open ConvertSQL(strSQL), SURVEY_APP_CONNECTION, adOpenForwardOnly, adLockReadOnly, adCmdText
  319.  
  320.         'Make sure that there are item answers for this survey
  321.         If Not rsOriginalSurvey.EOF Then
  322.             rsOriginalSurvey.MoveFirst
  323.  
  324.             'Build the SQL statements to insert the new records into the SUR_ITEM_ANSWER table
  325.             Do While Not rsOriginalSurvey.EOF
  326.                 'Get the new item ID from the collection that maps old item ID's to new item ID's
  327.                 lngNewItemID = GetValueFromCollection(strOldToNewItemIDs, CStr(rsOriginalSurvey("item_id")))
  328.  
  329.                 'Create the new answer ID for the new answer
  330.                 lngTempID = ID_GetNextAvailableID("SurveyGenerationAnswer")
  331.  
  332.                 'Create dictionary of old item ID's to new item ID's
  333.                 strOldToNewAnswerIDs = strOldToNewAnswerIDs & rsOriginalSurvey("answer_id") & ";" & lngTempID & ";"
  334.  
  335.                 'Get the answer value
  336.                 If IsNull(rsOriginalSurvey("answer_value")) = True Then
  337.                     lngAnswerValue = "Null"
  338.                 Else
  339.                     lngAnswerValue = rsOriginalSurvey("answer_value")
  340.                 End If
  341.  
  342.                 strSQL = "INSERT INTO sur_item_answer(item_id, answer_id, answer_text, answer_value, order_number, " & _
  343.                             "default_yn) VALUES(" & _
  344.                             lngNewItemID & ", " & _
  345.                             lngTempID & ", " & _
  346.                             SQLEncode(rsOriginalSurvey("answer_text")) & ", " & _
  347.                             lngAnswerValue & ", " & _
  348.                             rsOriginalSurvey("order_number") & ", " & _
  349.                             SQLEncode(rsOriginalSurvey("default_yn")) & ")"
  350.                 conNewSurvey.Execute ConvertSQL(strSQL), , adCmdText
  351.                 rsOriginalSurvey.MoveNext
  352.             Loop
  353.         End If
  354.         rsOriginalSurvey.Close
  355.  
  356.         '4.  Copy all of the data from the mapping table (SUR_SURVEY_TO_ITEM_MAPPING)
  357.         strSQL = "SELECT * FROM sur_survey_to_item_mapping WHERE survey_id = " & lngOriginalSurveyID
  358.         rsOriginalSurvey.Open ConvertSQL(strSQL), SURVEY_APP_CONNECTION, adOpenForwardOnly, adLockReadOnly, adCmdText
  359.  
  360.         'Make sure that there are items in the mapping table for this survey
  361.         If Not rsOriginalSurvey.EOF Then
  362.             rsOriginalSurvey.MoveFirst
  363.  
  364.             'Build the SQL statements to insert the new records into the SUR_SURVEY_TO_ITEM_MAPPING table
  365.             Do While Not rsOriginalSurvey.EOF
  366.                 'Get the new item ID from the collection that maps old item ID's to new item ID's
  367.                 lngNewItemID = GetValueFromCollection(strOldToNewItemIDs, CStr(rsOriginalSurvey("item_id")))
  368.                 strSQL = "INSERT INTO sur_survey_to_item_mapping(survey_id, item_id, order_number, page_number) VALUES(" & _
  369.                             lngNewSurveyId & ", " & _
  370.                             lngNewItemID & ", " & _
  371.                             rsOriginalSurvey("order_number") & ", " & _
  372.                             rsOriginalSurvey("page_number") & ")"
  373.                 conNewSurvey.Execute ConvertSQL(strSQL), , adCmdText
  374.                 rsOriginalSurvey.MoveNext
  375.             Loop
  376.         End If
  377.         rsOriginalSurvey.Close
  378.  
  379.         '5.  Copy all of the data from the page condition table (SUR_PAGE_CONDITION)
  380.         strSQL = "SELECT * FROM sur_page_condition WHERE survey_id = " & lngOriginalSurveyID
  381.         rsOriginalSurvey.Open ConvertSQL(strSQL), SURVEY_APP_CONNECTION, adOpenForwardOnly, adLockReadOnly, adCmdText
  382.  
  383.         'Make sure that there are page conditions for this survey
  384.         If Not rsOriginalSurvey.EOF Then
  385.             rsOriginalSurvey.MoveFirst
  386.  
  387.             'Build the SQL statements to insert the new records into the SUR_PAGE_CONDITION table
  388.             Do While Not rsOriginalSurvey.EOF
  389.                 'Generate a new value for the page_condition_id column
  390.                 lngTempID = ID_GetNextAvailableID("SurveyGenerationPageConditionID")
  391.  
  392.                 'Get the new item ID from the collection that maps old item ID's to new item ID's
  393.                 lngNewItemID = GetValueFromCollection(strOldToNewItemIDs, CStr(rsOriginalSurvey("dependent_item_id")))
  394.  
  395.                 'Get the new answer ID.  If the old answer ID equals SUR_ANSWER_ID_NULL then use SUR_ANSWER_ID_NULL.
  396.                 'Otherwise, get the answer from the collection that maps old answer ID's to new answer ID's
  397.  
  398.                 If CStr(rsOriginalSurvey("answer_id")) = CStr(SUR_ANSWER_ID_NULL) Then
  399.                     lngNewAnswerID = SUR_ANSWER_ID_NULL
  400.                 Else
  401.                     lngNewAnswerID = GetValueFromCollection(strOldToNewAnswerIDs, CStr(rsOriginalSurvey("answer_id")))
  402.                 End If
  403.  
  404.                 strSQL = "INSERT INTO sur_page_condition(page_condition_id, survey_id, page_number, dependent_item_id, " & _
  405.                             "group_number, operator_id, answer_id, answer_text) VALUES(" & _
  406.                             lngTempID & ", " & _
  407.                             lngNewSurveyID & ", " & _
  408.                             rsOriginalSurvey("page_number") & ", " & _
  409.                             lngNewItemID & ", " & _
  410.                             rsOriginalSurvey("group_number") & ", " & _
  411.                             rsOriginalSurvey("operator_id") & ", " & _
  412.                             lngNewAnswerID & ", " & _
  413.                             SQLEncode(rsOriginalSurvey("answer_text")) & ")"
  414.                 conNewSurvey.Execute ConvertSQL(strSQL), , adCmdText
  415.                 rsOriginalSurvey.MoveNext
  416.             Loop
  417.         End If
  418.         rsOriginalSurvey.Close
  419.  
  420.         '6.  Copy all of the data from the subitem table (SUR_SUBITEM)
  421.  
  422. 'SB 6/13/2006 fix for sql locking issue
  423. if SUR_DATABASE_TYPE = "SQLServer" then
  424.         strSQL = "SELECT * FROM sur_subitem (NOLOCK) WHERE item_id IN (" & _
  425.                  ConvertSQLInClause("SELECT item_id " & _
  426.                     "FROM sur_survey_to_item_mapping WHERE survey_id = " & lngOriginalSurveyID, "item_id") & ")"
  427. else
  428.         strSQL = "SELECT * FROM sur_subitem WHERE item_id IN (" & _
  429.                  ConvertSQLInClause("SELECT item_id " & _
  430.                     "FROM sur_survey_to_item_mapping WHERE survey_id = " & lngOriginalSurveyID, "item_id") & ")"
  431. end if
  432.  
  433.         rsOriginalSurvey.Open ConvertSQL(strSQL), SURVEY_APP_CONNECTION, adOpenForwardOnly, adLockReadOnly, adCmdText
  434.  
  435.         'Make sure that there are subitems for this survey
  436.         If Not rsOriginalSurvey.EOF Then
  437.             rsOriginalSurvey.MoveFirst
  438.             'Build the SQL statements to insert the new records into the SUR_SUBITEM table
  439.             Do While Not rsOriginalSurvey.EOF
  440.                 'Get the new item ID from the collection that maps old item ID's to new item ID's
  441.                 lngNewItemID = GetValueFromCollection(strOldToNewItemIDs, CStr(rsOriginalSurvey("item_id")))
  442.  
  443.                 'Create the new answer ID for the new answer
  444.                 lngTempID = ID_GetNextAvailableID("SurveyGenerationSubitem")
  445.  
  446.                 strSQL = "INSERT INTO sur_subitem(subitem_id, item_id, subitem_text, order_number) " & _
  447.                             "VALUES(" & _
  448.                             lngTempID & ", " & _
  449.                             lngNewItemID & ", " & _
  450.                             SQLEncode(rsOriginalSurvey("subitem_text")) & ", " & _
  451.                             rsOriginalSurvey("order_number") & ") "
  452.  
  453.                 conNewSurvey.Execute ConvertSQL(strSQL), , adCmdText
  454.                 rsOriginalSurvey.MoveNext
  455.             Loop
  456.         End If
  457.         rsOriginalSurvey.Close
  458.  
  459.  
  460.         '7.  Copy all of the data from the page property table (SUR_PAGE)
  461.         strSQL = "SELECT * FROM sur_page WHERE survey_id = " & lngOriginalSurveyID
  462.         rsOriginalSurvey.Open ConvertSQL(strSQL), SURVEY_APP_CONNECTION, adOpenForwardOnly, adLockReadOnly, adCmdText
  463.  
  464.         'Make sure that there are page property entries for this survey
  465.         If Not rsOriginalSurvey.EOF Then
  466.             rsOriginalSurvey.MoveFirst
  467.  
  468.             'Build the SQL statements to insert the new records into the SUR_PAGE table
  469.             Do While Not rsOriginalSurvey.EOF
  470.                 strSQL = "INSERT INTO sur_page(survey_id, page_number, page_title, page_introduction) " & _
  471.                             "VALUES(" & _
  472.                             lngNewSurveyID & ", " & _
  473.                             rsOriginalSurvey("page_number") & ", " & _
  474.                             SQLEncode(rsOriginalSurvey("page_title")) & ", " & _
  475.                             SQLEncode(rsOriginalSurvey("page_introduction")) & ")"
  476.                 conNewSurvey.Execute ConvertSQL(strSQL), , adCmdText
  477.                 rsOriginalSurvey.MoveNext
  478.             Loop
  479.         End If
  480.         rsOriginalSurvey.Close
  481.  
  482.         '8.  If there are any pipes in the items, update them to use the new item ID's
  483.         strSQL = "SELECT item_id, item_sub_text, item_text " & _
  484.                  "FROM sur_item " & _
  485.                  "WHERE item_id IN (" & _
  486.                  ConvertSQLInClause("SELECT item_id FROM sur_survey_to_item_mapping WHERE survey_id = " & lngNewSurveyID, "item_id") & ")"
  487.         Set rsOriginalSurvey = conNewSurvey.Execute(ConvertSQL(strSQL), , adCmdText)
  488.         If Not rsOriginalSurvey.EOF Then
  489.             rsOriginalSurvey.MoveFirst
  490.             Do While Not rsOriginalSurvey.EOF
  491.                 strItemText = rsOriginalSurvey("item_text")
  492.                 strItemSubText = rsOriginalSurvey("item_sub_text")
  493.  
  494.                 'Create an array of all the pairs of new and old item ID's
  495.                 vaItemIDs = Split(strOldToNewItemIDs, ";")
  496.  
  497.                 'Iterate through the item ID's.  If any of the old item ID's are found as pipes in the item text or item
  498.                 'sub text, update the text to use the new item ID
  499.                 For i = 0 To UBound(vaItemIDs) Step 2
  500.                     'If there is a pipe, update it
  501.                     If InStr(strItemText, "###" & vaItemIDs(i) & "###") > 0 Or InStr(strItemSubText, "###" & vaItemIDs(i) & "###") > 0 Then
  502.                         strItemText = Replace(strItemText, "###" & vaItemIDs(i) & "###", "###" & vaItemIDs(i + 1) & "###")
  503.                         strItemSubText = Replace(strItemSubText, "###" & vaItemIDs(i) & "###", "###" & vaItemIDs(i + 1) & "###")
  504.                         strSQL = "UPDATE sur_item " & _
  505.                                  "SET item_text = " & SQLEncode(strItemText) & ", " & _
  506.                                  "item_sub_text = " & SQLEncode(strItemSubText) & _
  507.                                  " WHERE item_id = " & rsOriginalSurvey("item_id")
  508.                         conNewSurvey.Execute ConvertSQL(strSQL), , adCmdText
  509.                     End If
  510.                 Next
  511.                 rsOriginalSurvey.MoveNext
  512.             Loop
  513.         End If
  514.         rsOriginalSurvey.Close
  515.  
  516.         '9.  Copy all of the data from the hidden fields table (SUR_HIDDEN_FIELD)
  517.         strSQL = "SELECT * FROM sur_hidden_field WHERE survey_id = " & lngOriginalSurveyID
  518.         rsOriginalSurvey.Open ConvertSQL(strSQL), SURVEY_APP_CONNECTION, adOpenForwardOnly, adLockReadOnly, adCmdText
  519.  
  520.         'Make sure that there are hidden fields before copying
  521.         If Not rsOriginalSurvey.EOF Then
  522.             rsOriginalSurvey.MoveFirst
  523.  
  524.             'Build the SQL statements to insert the new records into the SUR_HIDDEN_FIELD table
  525.             Do While Not rsOriginalSurvey.EOF
  526.                 strSQL = "INSERT INTO sur_hidden_field(hidden_field_id, survey_id, order_number, hidden_field_type, " & _
  527.                             "hidden_field_key, hidden_field_display_name) VALUES(" & _
  528.                             ID_GetNextAvailableID("SurveyGenerationHiddenField") & ", " & _
  529.                             lngNewSurveyID & ", " & _
  530.                             rsOriginalSurvey("order_number") & ", " & _
  531.                             SQLEncode(rsOriginalSurvey("hidden_field_type")) & ", " & _
  532.                             SQLEncode(rsOriginalSurvey("hidden_field_key")) & ", " & _
  533.                             SQLEncode(rsOriginalSurvey("hidden_field_display_name")) & ")"
  534.                 conNewSurvey.Execute ConvertSQL(strSQL), , adCmdText
  535.                 rsOriginalSurvey.MoveNext
  536.             Loop
  537.         End If
  538.         rsOriginalSurvey.Close
  539.  
  540.     End If
  541.  
  542.     'Clean up
  543.     conNewSurvey.Close
  544.     Set conNewSurvey = Nothing
  545.  
  546.     'Redirect to the modify survey page for the survey just created
  547.     Response.Redirect "ModifySurvey.asp?SurveyID=" & lngNewSurveyID
  548. %>