home *** CD-ROM | disk | FTP | other *** search
/ bombers.k12.ar.us / bombers.k12.ar.us.tar / bombers.k12.ar.us / survey_unconfigured / ReorderItem.asp < prev    next >
Text File  |  2006-10-25  |  4KB  |  101 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 allows the user to reorder the items 
  7. '                     in a 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. <%
  24.     Dim strSQL1
  25.     Dim strSQL2
  26.     Dim conReorder
  27.     Dim lngSurveyID
  28.     Dim lngLibraryID
  29.     Dim lngItemID
  30.     Dim strDirection
  31.     Dim lngOrderNumber
  32.     Dim flgLibrary
  33.     
  34.     'Initialization
  35.     Set conReorder = Server.CreateObject("ADODB.Connection")
  36.     conReorder.Open SURVEY_APP_CONNECTION
  37.     lngOrderNumber = Request.Form("OrderNumber")
  38.     lngItemID = Request.Form("ItemID")
  39.     strDirection = Request.Form("Direction")
  40.     If Len(Request.Form("SurveyID")) > 0 Then
  41.         lngSurveyID = Request.Form("SurveyID")
  42.         flgLibrary = False
  43.     Else
  44.         lngLibraryID = Request.Form("LibraryID")
  45.         flgLibrary = True
  46.     End If
  47.  
  48.     'Set up two SQL statements, one to move each of the two items
  49.     If strDirection = "Down" Then
  50.         'strSQL1 moves the following item up 1; strSQL2 moves the item clicked on down 1.  Note that moving an item
  51.         'up means decreasing its order number (counter-intuitive)
  52.         If flgLibrary = True Then
  53.             strSQL1 = "UPDATE sur_library_to_item_mapping SET order_number = " & lngOrderNumber & _
  54.                         " WHERE library_id = " & lngLibraryID & _
  55.                         " AND order_number = " & lngOrderNumber + 1
  56.             strSQL2 = "UPDATE sur_library_to_item_mapping SET order_number = " & lngOrderNumber + 1 & _
  57.                         " WHERE library_id = " & lngLibraryID & _
  58.                         " AND item_id = " & lngItemID
  59.         Else
  60.             strSQL1 = "UPDATE sur_survey_to_item_mapping SET order_number = " & lngOrderNumber & _
  61.                         " WHERE survey_id = " & lngSurveyID & _
  62.                         " AND order_number = " & lngOrderNumber + 1
  63.             strSQL2 = "UPDATE sur_survey_to_item_mapping SET order_number = " & lngOrderNumber + 1 & _
  64.                         " WHERE survey_id = " & lngSurveyID & _
  65.                         " AND item_id = " & lngItemID
  66.         End If
  67.     Else 'Direction equals "Up"
  68.         'strSQL1 moves the previous item down 1; strSQL2 moves the item clicked on up 1.  Note that moving an item
  69.         'down means increasing its order number (counter-intuitive)
  70.         If flgLibrary = True Then
  71.             strSQL1 = "UPDATE sur_library_to_item_mapping SET order_number = " & lngOrderNumber & _
  72.                         " WHERE library_id = " & lngLibraryID & _
  73.                         " AND order_number = " & lngOrderNumber - 1
  74.             strSQL2 = "UPDATE sur_library_to_item_mapping SET order_number = " & lngOrderNumber - 1 & _
  75.                         " WHERE library_id = " & lngLibraryID & _
  76.                         " AND item_id = " & lngItemID
  77.         Else
  78.             strSQL1 = "UPDATE sur_survey_to_item_mapping SET order_number = " & lngOrderNumber & _
  79.                         " WHERE survey_id = " & lngSurveyID & _
  80.                         " AND order_number = " & lngOrderNumber - 1
  81.             strSQL2 = "UPDATE sur_survey_to_item_mapping SET order_number = " & lngOrderNumber - 1 & _
  82.                         " WHERE survey_id = " & lngSurveyID & _
  83.                         " AND item_id = " & lngItemID
  84.         End If
  85.     End If
  86.  
  87.     'Execute SQL to actually move the ordering in the mapping table
  88.     conReorder.Execute strSQL1, , adCmdText
  89.     conReorder.Execute strSQL2, , adCmdText
  90.  
  91.     'Clean up
  92.     conReorder.Close
  93.     Set conReorder = Nothing
  94.  
  95.     'Redirect to the modify survey page for the survey or the modify library page for the library
  96.     If flgLibrary = True Then
  97.         Response.Redirect "ModifyLibrary.asp?LibraryID=" & lngLibraryID
  98.     Else
  99.         Response.Redirect "ModifySurvey.asp?SurveyID=" & lngSurveyID
  100.     End If
  101. %>