home *** CD-ROM | disk | FTP | other *** search
/ bombers.k12.ar.us / bombers.k12.ar.us.tar / bombers.k12.ar.us / survey / DeletePage.asp < prev    next >
Text File  |  2006-11-29  |  6KB  |  131 lines

  1. <!--#Include File="Include/Top_inc.asp"-->
  2. <%
  3. '***********************************************************************
  4. '   Application: SelectSurveyASP Advanced v8.1.11
  5. '   Author: Aaron Baril for ClassApps.com
  6. '   Page Description: This page deletes a page from a survey.  Deleting a page
  7. '                      deletes all items associated with the page, and re-orders
  8. '                      all other pages in the same survey.
  9. '
  10. '   COPYRIGHT NOTICE                                
  11. '
  12. '   See attached Software License Agreement
  13. '
  14. '   (c) Copyright 2002 - 2006 by ClassApps.com.  All rights reserved.
  15. '***********************************************************************
  16. %>
  17. <!--#Include File="Include/Config_inc.asp"-->
  18. <!--#Include File="Include/Utility_inc.asp"-->
  19. <!--#Include File="Include/adovbs_inc.asp"-->
  20. <!--#Include File="Include/CurrentUser_inc.asp"-->
  21. <!--#Include File="Include/SurveySecurity_inc.asp"-->
  22. <!--#Include File="Include/SurveyUtility_inc.asp"-->
  23. <!--#Include File="Include/Constants_inc.asp"-->
  24. <%
  25.     'In order to delete a page, the user must be the survey owner or an admin
  26.     If IsUserOwnerOrAdmin(Request.QueryString("SurveyID")) = False Then
  27.         Response.Redirect "AccessDenied.asp?SurveyID=" & Request.QueryString("SurveyID") & "&Reason=" & SUR_ACCESS_DENIED_NOT_OWNER
  28.     End If
  29.  
  30.     'Do not allow a user to delete a page in a survey that already has responses.  Instead, redirect the user back
  31.     'to the modify survey page
  32.     If HasResponses(Request.QueryString("SurveyID")) = True Then
  33.         Response.Redirect "ModifySurvey.asp?SurveyID=" & Request.QueryString("SurveyID")
  34.     End If
  35.  
  36.     Dim strSQL
  37.     Dim conDelete
  38.     Dim rsItemCount
  39.     Dim lngPageNumber
  40.     Dim lngOrderNumber
  41.     Dim lngSurveyID
  42.     Dim rsOrderNumber
  43.     Dim lngItemCount
  44.     
  45.     'Initialization
  46.     Set conDelete = Server.CreateObject("ADODB.Connection")
  47.     Set rsItemCount = Server.CreateObject("ADODB.Recordset")
  48.     conDelete.Open SURVEY_APP_CONNECTION
  49.     lngPageNumber = Request.QueryString("PageNumber")
  50.     lngSurveyID = Request.QueryString("SurveyID")
  51.  
  52.     'Get the number of items on the page to be deleted
  53.     strSQL = "SELECT count(item_id) As ItemCount " & _
  54.                 "FROM sur_survey_to_item_mapping " & _
  55.                 "WHERE survey_id = " & lngSurveyID & _
  56.                 " AND page_number = " & lngPageNumber
  57.     rsItemCount.Open ConvertSQL(strSQL), conDelete, adOpenForwardOnly, adLockReadOnly, adCmdText
  58.     rsItemCount.MoveFirst
  59.     lngItemCount = CLng(rsItemCount("ItemCount"))
  60.     rsItemCount.Close
  61.     Set rsItemCount = Nothing
  62.  
  63.     'Delete any page conditions for the page
  64.     strSQL = "DELETE from sur_page_condition " & _
  65.                 "WHERE survey_id = " & lngSurveyID & _
  66.                 " AND page_number = " & lngPageNumber
  67.     conDelete.Execute ConvertSQL(strSQL), , adCmdText
  68.  
  69.     'Drop the page number for all page conditions for this survey that are greater than the page just deleted
  70.     strSQL = "UPDATE sur_page_condition " & _
  71.                 "SET page_number = page_number - 1 " & _
  72.                 "WHERE survey_id = " & lngSurveyID & _
  73.                 " AND page_number > " & lngPageNumber
  74.     conDelete.Execute ConvertSQL(strSQL), , adCmdText
  75.                     
  76.     'Delete any page property entries
  77.     strSQL = "DELETE from sur_page " & _
  78.                 "WHERE survey_id = " & lngSurveyID & _
  79.                 " AND page_number = " & lngPageNumber
  80.     conDelete.Execute ConvertSQL(strSQL), , adCmdText
  81.  
  82.     'Drop the page number for all page property entries for this survey that are greater than the page just deleted
  83.     strSQL = "UPDATE sur_page " & _
  84.                 "SET page_number = page_number - 1 " & _
  85.                 "WHERE survey_id = " & lngSurveyID & _
  86.                 " AND page_number > " & lngPageNumber
  87.     conDelete.Execute ConvertSQL(strSQL), , adCmdText
  88.                     
  89.     'Delete all the answers for items on the specified page from the SUR_ITEM_ANSWER table
  90.     strSQL = "DELETE FROM sur_item_answer " & _
  91.              "WHERE item_id IN (" & _
  92.              ConvertSQLInClause("SELECT item_id FROM sur_survey_to_item_mapping " & _
  93.                 "WHERE survey_id = " & lngSurveyID & " AND page_number = " & lngPageNumber, "item_id") & _
  94.              ")"
  95.     conDelete.Execute ConvertSQL(strSQL), , adCmdText
  96.  
  97.     'Delete all the items for this page from the item table (SUR_ITEM)
  98.     strSQL = "DELETE FROM sur_item " & _
  99.              "WHERE item_id IN (" & _
  100.              ConvertSQLInClause("SELECT item_id FROM sur_survey_to_item_mapping " & _
  101.                 "WHERE survey_id = " & lngSurveyID & " AND page_number = " & lngPageNumber, "item_id") & _
  102.              ")"
  103.     conDelete.Execute ConvertSQL(strSQL), , adCmdText
  104.  
  105.     'Delete all the entries for items on this page from the mapping table (SUR_SURVEY_TO_ITEM_MAPPING)
  106.     strSQL = "DELETE FROM sur_survey_to_item_mapping " & _
  107.                 "WHERE survey_id = " & lngSurveyID & _
  108.                 " AND page_number = " & lngPageNumber
  109.     conDelete.Execute ConvertSQL(strSQL), , adCmdText
  110.  
  111.     'Move all the items below the ones on the page just deleted up.  These items should be moved up the same number of 
  112.     'positions as the number of items deleted
  113.     strSQL = "UPDATE sur_survey_to_item_mapping SET order_number = order_number - " & lngItemCount & _
  114.                 " WHERE survey_id = " & lngSurveyID & _
  115.                 " AND page_number > " & lngPageNumber
  116.     conDelete.Execute ConvertSQL(strSQL), , adCmdText
  117.  
  118.     'Move all the pages after the page just deleted up one position in the mapping table (SUR_SURVEY_TO_ITEM_MAPPING)
  119.     strSQL = "UPDATE sur_survey_to_item_mapping " & _
  120.                 "SET page_number = page_number - 1 " & _
  121.                 "WHERE survey_id = " & lngSurveyID & _
  122.                 " AND page_number > " & lngPageNumber
  123.     conDelete.Execute ConvertSQL(strSQL), , adCmdText
  124.  
  125.     'Clean up
  126.     conDelete.Close
  127.     Set conDelete = Nothing
  128.  
  129.     'Redirect to the modify survey page for the survey.
  130.     Response.Redirect "ModifySurvey.asp?SurveyID=" & lngSurveyID
  131. %>