home *** CD-ROM | disk | FTP | other *** search
/ bombers.k12.ar.us / bombers.k12.ar.us.tar / bombers.k12.ar.us / survey_unconfigured / InsertFromLibraryAction.asp < prev    next >
Text File  |  2006-05-19  |  13KB  |  308 lines

  1. <!--#Include File="Include/Top_inc.asp"-->
  2. <%
  3. '***********************************************************************
  4. '   Application: SelectSurveyASP Advanced v8.1.7
  5. '   Author: Aaron Baril for ClassApps.com
  6. '   Page Description: This page works with InsertFromLibrary.asp, and processes the
  7. '                     form that allows users to create a new item by inserting
  8. '                      from a library.  After creating the new item, the
  9. '                      user is redirected to the modify survey page.
  10. '
  11. '   COPYRIGHT NOTICE
  12. '
  13. '   See attached Software License Agreement
  14. '
  15. '   (c) Copyright 2002 - 2006 by ClassApps.com.  All rights reserved.
  16. '***********************************************************************
  17. %>
  18. <!--#Include File="Include/Config_inc.asp"-->
  19. <!--#Include File="Include/Utility_inc.asp"-->
  20. <!--#Include File="Include/adovbs_inc.asp"-->
  21. <!--#Include File="Include/ID_inc.asp"-->
  22. <!--#Include File="Include/CurrentUser_inc.asp"-->
  23. <!--#Include File="Include/SurveySecurity_inc.asp"-->
  24. <!--#Include File="Include/SurveyUtility_inc.asp"-->
  25. <!--#Include File="Include/Constants_inc.asp"-->
  26. <%
  27.     Dim strSQL
  28.     Dim conItem
  29.     Dim rsOriginal
  30.     Dim lngNewItemID
  31.     Dim lngOriginalItemID
  32.     Dim lngSurveyID
  33.     Dim lngLibraryID
  34.     Dim lngPageNumber
  35.     Dim lngItemTypeID
  36.     Dim strMinimumValue
  37.     Dim strMaximumValue
  38.     Dim lngMinimumNumberResponses
  39.     Dim lngMaximumNumberResponses
  40.     Dim lngRowTextWidth
  41.     Dim lngMaximumLength
  42.     Dim lngAnswerTotal
  43.     Dim lngSubitemCount
  44.     Dim strImageHeight
  45.     Dim strItemAlias
  46.     Dim strOtherText
  47.     Dim strOtherDisplayType
  48.     Dim lngNewAnswerID
  49.     Dim lngNewSubitemID
  50.     Dim lngAnswerValue
  51.     Dim flgLibrary
  52.     Dim flgHasResponses
  53.  
  54.     'Initialization
  55.     lngLibraryID = Request.Form("cboLibrary")
  56.     flgHasResponses = HasResponses(lngSurveyID)
  57.     lngSurveyID = Request.Form("OriginalSurveyID")
  58.  
  59.     'Do not allow a user to insert an item in a survey that already has responses.  Instead, redirect the user back
  60.     'to the modify survey page
  61.     If flgHasResponses = True Then
  62.         Response.Redirect "ModifySurvey.asp?SurveyID=" & lngSurveyID
  63.     End If
  64.  
  65.     'Initialization
  66.     Set rsOriginal = Server.CreateObject("ADODB.Recordset")
  67.     Set conItem = Server.CreateObject("ADODB.Connection")
  68.     conItem.Open SURVEY_APP_CONNECTION
  69.  
  70.     'Get the item ID being copied.
  71.     lngOriginalItemID = Request.Form("cboItem")
  72.  
  73.     'Get ID for a new item
  74.     lngNewItemID = ID_GetNextAvailableID("SurveyGenerationItem")
  75.  
  76.     'Copy all of the data from the item table (SUR_ITEM)
  77.     strSQL = "SELECT * FROM sur_item WHERE item_id = " & lngOriginalItemID
  78.     rsOriginal.Open ConvertSQL(strSQL), SURVEY_APP_CONNECTION, adOpenForwardOnly, adLockReadOnly, adCmdText
  79.     rsOriginal.MoveFirst
  80.     lngItemTypeID = rsOriginal("item_type_id")
  81.     strOtherText = rsOriginal("other_text")
  82.     If IsNull(strOtherText) = True Then
  83.         strOtherText = ""
  84.     End If
  85.     strOtherDisplayType = rsOriginal("other_display_type")
  86.     If IsNull(strOtherDisplayType) = True Then
  87.         strOtherDisplayType = ""
  88.     End If
  89.  
  90.     If Len(rsOriginal("minimum_value")) = 0 Or IsNull(rsOriginal("minimum_value")) = True Then
  91.         strMinimumValue = ""
  92.     Else
  93.         strMinimumValue = rsOriginal("minimum_value")
  94.     End If
  95.  
  96.     If Len(rsOriginal("maximum_value")) = 0 Or IsNull(rsOriginal("maximum_value")) = True Then
  97.         strMaximumValue = ""
  98.     Else
  99.         strMaximumValue = rsOriginal("maximum_value")
  100.     End If
  101.  
  102.     If Len(rsOriginal("answer_total")) = 0 Or IsNull(rsOriginal("answer_total")) = True Then
  103.         lngAnswerTotal = "Null"
  104.     Else
  105.         lngAnswerTotal = rsOriginal("answer_total")
  106.     End If
  107.  
  108.     If Len(rsOriginal("subitem_count")) = 0 Or IsNull(rsOriginal("subitem_count")) = True Then
  109.         lngSubitemCount = "Null"
  110.     Else
  111.         lngSubitemCount = rsOriginal("subitem_count")
  112.     End If
  113.  
  114.     If Len(rsOriginal("minimum_number_responses")) = 0 Or IsNull(rsOriginal("minimum_number_responses")) = True Then
  115.         lngMinimumNumberResponses = "Null"
  116.     Else
  117.         lngMinimumNumberResponses = rsOriginal("minimum_number_responses")
  118.     End If
  119.  
  120.     If Len(rsOriginal("maximum_number_responses")) = 0 Or IsNull(rsOriginal("maximum_number_responses")) = True Then
  121.         lngMaximumNumberResponses = "Null"
  122.     Else
  123.         lngMaximumNumberResponses = rsOriginal("maximum_number_responses")
  124.     End If
  125.  
  126.     If Len(rsOriginal("row_text_width")) = 0 Or IsNull(rsOriginal("row_text_width")) = True Then
  127.         lngRowTextWidth = "Null"
  128.     Else
  129.         lngRowTextWidth = rsOriginal("row_text_width")
  130.     End If
  131.  
  132.     If Len(rsOriginal("maximum_length")) = 0 Or IsNull(rsOriginal("maximum_length")) = True Then
  133.         lngMaximumLength = "Null"
  134.     Else
  135.         lngMaximumLength = rsOriginal("maximum_length")
  136.     End If
  137.  
  138.     If Len(rsOriginal("image_height")) = 0 Or IsNull(rsOriginal("image_height")) = True Then
  139.         strImageHeight = ""
  140.     Else
  141.         strImageHeight = rsOriginal("image_height")
  142.     End If
  143.  
  144.     If Len(rsOriginal("item_alias")) = 0 Or IsNull(rsOriginal("item_alias")) = True Then
  145.         strItemAlias = ""
  146.     Else
  147.         strItemAlias = rsOriginal("item_alias")
  148.     End If
  149.  
  150.     'Create the item in the SUR_ITEM table
  151.     strSQL = "INSERT INTO sur_item(item_id, item_type_id, item_alias, required_yn, random_answer_order_yn, " & _
  152.                 "email_address_yn, other_yn, other_text, other_display_type, minimum_value, maximum_value, " & _
  153.                 "answer_total, minimum_number_responses, maximum_number_responses, row_text_width, maximum_length, " & _
  154.                 "display_format, image_path, image_width, image_height, image_alignment, default_value, " & _
  155.                 "database_dsn, subitem_count, item_sub_text, database_sql, item_text) VALUES(" & _
  156.                 lngNewItemID & ", " & _
  157.                 rsOriginal("item_type_id") & ", " & _
  158.                 SQLEncode(strItemAlias) & ", " & _
  159.                 SQLEncode(rsOriginal("required_yn")) & ", " & _
  160.                 SQLEncode(rsOriginal("random_answer_order_yn")) & ", " & _
  161.                 SQLEncode(rsOriginal("email_address_yn")) & ", " & _
  162.                 SQLEncode(rsOriginal("other_yn")) & ", " & _
  163.                 SQLEncode(strOtherText) & ", " & _
  164.                 SQLEncode(strOtherDisplayType) & ", " & _
  165.                 SQLEncode(strMinimumValue) & ", " & _
  166.                 SQLEncode(strMaximumValue) & ", " & _
  167.                 lngAnswerTotal & ", " & _
  168.                 lngMinimumNumberResponses & ", " & _
  169.                 lngMaximumNumberResponses & ", " & _
  170.                 lngRowTextWidth & ", " & _
  171.                 lngMaximumLength & ", " & _
  172.                 SQLEncode(rsOriginal("display_format")) & ", " & _
  173.                 SQLEncode(rsOriginal("image_path")) & ", " & _
  174.                 SQLEncode(rsOriginal("image_width")) & ", " & _
  175.                 SQLEncode(strImageHeight) & ", " & _
  176.                 SQLEncode(rsOriginal("image_alignment")) & ", " & _
  177.                 SQLEncode(rsOriginal("default_value")) & ", " & _
  178.                 SQLEncode(rsOriginal("database_dsn")) & ", " & _
  179.                 lngSubitemCount & ", " & _
  180.                 SQLEncode(rsOriginal("item_sub_text")) & ", " & _
  181.                 SQLEncode(rsOriginal("database_sql")) & ", " & _
  182.                 SQLEncode(rsOriginal("item_text")) & ")"
  183.     conItem.Execute ConvertSQL(strSQL), , adCmdText
  184.     rsOriginal.Close
  185.  
  186.     'Move all the other items down one, so that we can insert the new item in the right location.  Note that
  187.     'new items are always inserted AT the order number indicated, which means that all existing items
  188.     'with that order number or higher have to have their order numbers incremented by 1.
  189.     strSQL = "UPDATE sur_survey_to_item_mapping SET order_number = order_number + 1 WHERE order_number >= " & Request.Form("OrderNumber") & " AND survey_id = " & lngSurveyID
  190.     'End If
  191.     conItem.Execute ConvertSQL(strSQL), , adCmdText
  192.  
  193.     'If the "NewPage" form value is set to "Yes", then the new item should be inserted on a new page.  The new page
  194.     'number will be one greater than the page number passed in.  All pages after this page must be bumped down.
  195.     If Request.Form("NewPage") = "Yes" Then
  196.         strSQL = "UPDATE sur_survey_to_item_mapping " & _
  197.                     "SET page_number = page_number + 1 " & _
  198.                     "WHERE survey_id = " & lngSurveyID & _
  199.                     " AND page_number > " & Request.Form("PageNumber")
  200.         conItem.Execute ConvertSQL(strSQL), , adCmdText
  201.  
  202.         lngPageNumber = CLng(Request.Form("PageNumber")) + 1
  203.     Else
  204.         lngPageNumber = Request.Form("PageNumber")
  205.     End If
  206.  
  207.     'Insert an entry into the mapping table (either SUR_SURVEY_TO_ITEM_MAPPING or SUR_LIBRARY_TO_ITEM_MAPPING).
  208.     If flgLibrary = True Then
  209.         strSQL = "INSERT INTO sur_library_to_item_mapping(library_id, item_id, order_number) VALUES(" & _
  210.                     lngLibraryID & ", " & lngNewItemID & ", " & Request.Form("OrderNumber") & ")"
  211.     Else
  212.         strSQL = "INSERT INTO sur_survey_to_item_mapping(survey_id, item_id, order_number, page_number) VALUES(" & _
  213.                     lngSurveyID & ", " & lngNewItemID & ", " & Request.Form("OrderNumber") & ", " & lngPageNumber & ")"
  214.     End If
  215.     conItem.Execute ConvertSQL(strSQL), , adCmdText
  216.  
  217.     'If the item type contains multiple answers, record the answers in the database.
  218.     If CLng(lngItemTypeID) = SUR_ITEM_SINGLE_SELECT_DROPDOWN Or CLng(lngItemTypeID) = SUR_ITEM_MULTISELECT_CHECKBOXES Or CLng(lngItemTypeID) = SUR_ITEM_SINGLE_SELECT_OPTIONS Or CLng(lngItemTypeID) = SUR_ITEM_MATRIX_SINGLE_SELECT_OPTIONS Or CLng(lngItemTypeID) = SUR_ITEM_MATRIX_MULTISELECT_CHECKBOXES Or CLng(lngItemTypeID) = SUR_ITEM_MATRIX_TEXT_BOXES Then
  219.         'Copy all of the answers from the item table (SUR_ITEM_ANSWER)
  220.         strSQL = "SELECT * FROM sur_item_answer WHERE item_id = " & lngOriginalItemID
  221.         rsOriginal.Open ConvertSQL(strSQL), SURVEY_APP_CONNECTION, adOpenForwardOnly, adLockReadOnly, adCmdText
  222.         rsOriginal.MoveFirst
  223.  
  224.         'Loop through the answers, and insert each into the SUR_ITEM_ANSWER table as answers to the new question
  225.         Do While Not rsOriginal.EOF
  226.             'Get the next available answer ID
  227.             lngNewAnswerID = ID_GetNextAvailableID("SurveyGenerationAnswer")
  228.  
  229.             'Get the answer value
  230.             If IsNull(rsOriginal("answer_value")) = True Then
  231.                 lngAnswerValue = "Null"
  232.             Else
  233.                 lngAnswerValue = rsOriginal("answer_value")
  234.             End If
  235.  
  236.             strSQL = "INSERT INTO sur_item_answer(item_id, answer_id, answer_text, answer_value, order_number, " & _
  237.                         "default_yn) VALUES(" & _
  238.                         lngNewItemID & ", " & _
  239.                         lngNewAnswerID & ", " & _
  240.                         SQLEncode(rsOriginal("answer_text")) & ", " & _
  241.                         lngAnswerValue & ", " & _
  242.                         rsOriginal("order_number") & ", " & _
  243.                         SQLEncode(rsOriginal("default_yn")) & ")"
  244.             conItem.Execute ConvertSQL(strSQL), , adCmdText
  245.             rsOriginal.MoveNext
  246.         Loop
  247.  
  248.         'Clean up
  249.         rsOriginal.Close
  250.     End If
  251.  
  252.     'If the item type contains subitems, record the subitems in the database.
  253.     If CLng(lngItemTypeID) = SUR_ITEM_CONSTANT_SUM Or CLng(lngItemTypeID) = SUR_ITEM_RANKING Or CLng(lngItemTypeID) = SUR_ITEM_OPEN_ENDED_ONE_OR_MORE_LINES Or CLng(lngItemTypeID) = SUR_ITEM_MATRIX_SINGLE_SELECT_OPTIONS Or CLng(lngItemTypeID) = SUR_ITEM_MATRIX_RATING_SCALE Or CLng(lngItemTypeID) = SUR_ITEM_MATRIX_MULTISELECT_CHECKBOXES Or CLng(lngItemTypeID) = SUR_ITEM_MATRIX_TEXT_BOXES Then
  254.         'Copy all of subitems from the submitem table (SUR_SUBITEM)
  255.         strSQL = "SELECT * FROM sur_subitem WHERE item_id = " & lngOriginalItemID
  256.         rsOriginal.Open ConvertSQL(strSQL), SURVEY_APP_CONNECTION, adOpenForwardOnly, adLockReadOnly, adCmdText
  257.         rsOriginal.MoveFirst
  258.  
  259.         'Loop through the submitems, and insert each into the SUR_SUBITEM table as subitems for the new question
  260.         Do While Not rsOriginal.EOF
  261.             'Get the next available subitem ID
  262.             lngNewSubitemID = ID_GetNextAvailableID("SurveyGenerationSubitem")
  263.  
  264.             strSQL = "INSERT INTO sur_subitem(subitem_id, item_id, subitem_text, order_number) VALUES(" & _
  265.                         lngNewSubitemID & ", " & _
  266.                         lngNewItemID & ", " & _
  267.                         SQLEncode(rsOriginal("subitem_text")) & ", " & _
  268.                         rsOriginal("order_number") & ")"
  269.             conItem.Execute ConvertSQL(strSQL), , adCmdText
  270.             rsOriginal.MoveNext
  271.         Loop
  272.  
  273.         'Clean up
  274.         rsOriginal.Close
  275.     End If
  276.  
  277.     'Clean up
  278.     conItem.Close
  279.     Set conItem = Nothing
  280.     Set rsOriginal = Nothing
  281.  
  282.     'For libraries, redirect back to the modify library page
  283.     If flgLibrary = True Then
  284.         Response.Redirect "ModifyLibrary.asp?LibraryID=" & lngLibraryID & "&#ItemID" & lngNewItemID
  285.     Else
  286.         'If the item was created by copying from the ModifySurvey.asp page, redirect back to that page; otherwise,
  287.         'redirect to the new item so that it can be modified.
  288.         If Len(Request.Form("ReturnToModifySurvey")) > 0 Then
  289.             Response.Redirect "ModifySurvey.asp?SurveyID=" & lngSurveyID & "&#ItemID" & lngNewItemID
  290.         Else
  291. %>
  292.             <html>
  293.             <body onload="javascript:document.forms['frmItem'].submit();">
  294.                 <form name="frmItem" action="Item.asp" method="post">
  295.                     <input type="hidden" name="State" value="<%=SUR_STATE_EDIT%>">
  296.                     <input type="hidden" name="ItemID" value="<%=lngNewItemID%>">
  297.                     <input type="hidden" name="SurveyID" value="<%=lngSurveyID%>">
  298.                 </form>
  299.             </body>
  300.             </html>
  301. <%
  302.         End If
  303.     End If
  304.  
  305.     'Ensure that the web server returns the page
  306.     Response.Flush
  307. %>
  308.