home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
bombers.k12.ar.us
/
bombers.k12.ar.us.tar
/
bombers.k12.ar.us
/
survey_unconfigured
/
DeleteItem.asp
< prev
next >
Wrap
Text File
|
2006-10-25
|
7KB
|
172 lines
<!--#Include File="Include/Top_inc.asp"-->
<%
'***********************************************************************
' Application: SelectSurveyASP Advanced v8.1.11
' Author: Aaron Baril for ClassApps.com
' Page Description: This page deletes an item from a survey, and then
' redirects the user back to the modify survey screen.
'
' COPYRIGHT NOTICE
'
' See attached Software License Agreement
'
' (c) Copyright 2002 - 2006 by ClassApps.com. All rights reserved.
'***********************************************************************
%>
<!--#Include File="Include/Config_inc.asp"-->
<!--#Include File="Include/Utility_inc.asp"-->
<!--#Include File="Include/adovbs_inc.asp"-->
<!--#Include File="Include/CurrentUser_inc.asp"-->
<!--#Include File="Include/SurveySecurity_inc.asp"-->
<!--#Include File="Include/SurveyUtility_inc.asp"-->
<!--#Include File="Include/Constants_inc.asp"-->
<%
Dim strSQL
Dim conDelete
Dim lngItemID
Dim lngOrderNumber
Dim lngSurveyID
Dim lngLibraryID
Dim lngPageNumber
Dim rsOrderNumber
Dim rsItemCount
Dim lngItemCount
Dim flgLibrary
'Initialization
lngItemID = Request.QueryString("ItemID")
lngOrderNumber = Request.QueryString("OrderNumber")
Set conDelete = Server.CreateObject("ADODB.Connection")
Set rsItemCount = Server.CreateObject("ADODB.Recordset")
conDelete.Open SURVEY_APP_CONNECTION
'Check to see if this is an item for a survey or a library
If Len(Request.QueryString("SurveyID")) > 0 Then
lngSurveyID = Request.QueryString("SurveyID")
lngPageNumber = Request.QueryString("PageNumber")
flgLibrary = False
'In order to delete an item, the user must be the survey owner or an admin.
If IsUserOwnerOrAdmin(lngSurveyID) = False Then
Response.Redirect "AccessDenied.asp?SurveyID=" & lngSurveyID & "&Reason=" & SUR_ACCESS_DENIED_NOT_OWNER
End If
'Do not allow a user to delete an item from a survey that already has responses. Instead, redirect the user back
'to the modify survey page
If HasResponses(lngSurveyID) = True Then
Response.Redirect "ModifySurvey.asp?SurveyID=" & lngSurveyID
End If
'Get the number of items on the page that contains the item to be deleted
strSQL = "SELECT count(item_id) As ItemCount " & _
"FROM sur_survey_to_item_mapping " & _
"WHERE survey_id = " & lngSurveyID & _
" AND page_number = " & lngPageNumber
rsItemCount.Open ConvertSQL(strSQL), conDelete, adOpenForwardOnly, adLockReadOnly, adCmdText
rsItemCount.MoveFirst
lngItemCount = CLng(rsItemCount("ItemCount"))
rsItemCount.Close
Set rsItemCount = Nothing
'If the order number was not passed in on the URL, get it from the database.
If Len(Request.QueryString("OrderNumber")) = 0 Then
Set rsOrderNumber = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT order_number FROM sur_survey_to_item_mapping WHERE item_id = " & lngItemID & " AND survey_id = " & lngSurveyID
rsOrderNumber.Open ConvertSQL(strSQL), conDelete, adOpenDynamic, , adCmdText
rsOrderNumber.MoveFirst
lngOrderNumber = rsOrderNumber("order_number")
rsOrderNumber.Close
Set rsOrderNumber = Nothing
End If
Else 'Library
lngLibraryID = Request.QueryString("LibraryID")
flgLibrary = True
End If
'For surveys, if any page conditions were dependent on this item, delete those page conditions
If flgLibrary = False Then
strSQL = "DELETE FROM sur_page_condition WHERE dependent_item_id = " & lngItemID
conDelete.Execute ConvertSQL(strSQL), , adCmdText
End If
'Delete the item from the SUR_ITEM table
strSQL = "DELETE FROM sur_item WHERE item_id = " & lngItemID
conDelete.Execute ConvertSQL(strSQL), , adCmdText
'Delete all of the answer for the item from the item answer table (SUR_ITEM_ANSWER)
strSQL = "DELETE FROM sur_item_answer WHERE item_id = " & lngItemID
conDelete.Execute ConvertSQL(strSQL), , adCmdText
'Delete all of the row names for the item from the subitem table (SUR_SUBITEM)
strSQL = "DELETE FROM sur_subitem WHERE item_id = " & lngItemID
conDelete.Execute ConvertSQL(strSQL), , adCmdText
'Delete the entry for this item in the mapping table (SUR_SURVEY_TO_ITEM_MAPPING or SUR_LIBRARY_TO_ITEM_MAPPING)
If flgLibrary = True Then
strSQL = "DELETE FROM sur_library_to_item_mapping WHERE item_id = " & lngItemID & " AND library_id = " & lngLibraryID
Else
strSQL = "DELETE FROM sur_survey_to_item_mapping WHERE item_id = " & lngItemID & " AND survey_id = " & lngSurveyID
End If
conDelete.Execute ConvertSQL(strSQL), , adCmdText
'Move all the items below the one just deleted up one
If flgLibrary = True Then
strSQL = "UPDATE sur_library_to_item_mapping SET order_number = order_number - 1" & _
" WHERE library_id = " & lngLibraryID & _
" AND order_number > " & lngOrderNumber
Else
strSQL = "UPDATE sur_survey_to_item_mapping SET order_number = order_number - 1" & _
" WHERE survey_id = " & lngSurveyID & _
" AND order_number > " & lngOrderNumber
End If
conDelete.Execute ConvertSQL(strSQL), , adCmdText
'For surveys, if the item deleted was the only item on the page, move all of the other pages up one.
If flgLibrary = False Then
If lngItemCount = 1 Then
'Delete any page conditions for the page
strSQL = "DELETE from sur_page_condition " & _
"WHERE survey_id = " & lngSurveyID & _
" AND page_number = " & lngPageNumber
conDelete.Execute ConvertSQL(strSQL), , adCmdText
'Drop the page number for all page conditions for this survey that are greater than the page just deleted
strSQL = "UPDATE sur_page_condition " & _
"SET page_number = page_number - 1 " & _
"WHERE survey_id = " & lngSurveyID & _
" AND page_number > " & lngPageNumber
conDelete.Execute ConvertSQL(strSQL), , adCmdText
'Delete any page property entries
strSQL = "DELETE from sur_page " & _
"WHERE survey_id = " & lngSurveyID & _
" AND page_number = " & lngPageNumber
conDelete.Execute ConvertSQL(strSQL), , adCmdText
'Drop the page number for all page property entries for this survey that are greater than the page just deleted
strSQL = "UPDATE sur_page " & _
"SET page_number = page_number - 1 " & _
"WHERE survey_id = " & lngSurveyID & _
" AND page_number > " & lngPageNumber
conDelete.Execute ConvertSQL(strSQL), , adCmdText
'Move all the items below the ones on the page just deleted up. These items should be moved up the same number of
'positions as the number of items deleted
strSQL = "UPDATE sur_survey_to_item_mapping SET page_number = page_number - " & lngItemCount & _
" WHERE survey_id = " & lngSurveyID & _
" AND page_number > " & lngPageNumber
conDelete.Execute ConvertSQL(strSQL), , adCmdText
End If
End If
'Clean up
conDelete.Close
Set conDelete = Nothing
'Redirect to either the modify survey page for the survey or the modify library page for the library.
If flgLibrary = True Then
Response.Redirect "ModifyLibrary.asp?LibraryID=" & lngLibraryID
Else
Response.Redirect "ModifySurvey.asp?SurveyID=" & lngSurveyID
End If
%>