home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
bombers.k12.ar.us
/
bombers.k12.ar.us.tar
/
bombers.k12.ar.us
/
survey_unconfigured
/
DeletePage.asp
< prev
next >
Wrap
Text File
|
2006-10-25
|
6KB
|
131 lines
<!--#Include File="Include/Top_inc.asp"-->
<%
'***********************************************************************
' Application: SelectSurveyASP Advanced v8.1.11
' Author: Aaron Baril for ClassApps.com
' Page Description: This page deletes a page from a survey. Deleting a page
' deletes all items associated with the page, and re-orders
' all other pages in the same survey.
'
' 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"-->
<%
'In order to delete a page, the user must be the survey owner or an admin
If IsUserOwnerOrAdmin(Request.QueryString("SurveyID")) = False Then
Response.Redirect "AccessDenied.asp?SurveyID=" & Request.QueryString("SurveyID") & "&Reason=" & SUR_ACCESS_DENIED_NOT_OWNER
End If
'Do not allow a user to delete a page in a survey that already has responses. Instead, redirect the user back
'to the modify survey page
If HasResponses(Request.QueryString("SurveyID")) = True Then
Response.Redirect "ModifySurvey.asp?SurveyID=" & Request.QueryString("SurveyID")
End If
Dim strSQL
Dim conDelete
Dim rsItemCount
Dim lngPageNumber
Dim lngOrderNumber
Dim lngSurveyID
Dim rsOrderNumber
Dim lngItemCount
'Initialization
Set conDelete = Server.CreateObject("ADODB.Connection")
Set rsItemCount = Server.CreateObject("ADODB.Recordset")
conDelete.Open SURVEY_APP_CONNECTION
lngPageNumber = Request.QueryString("PageNumber")
lngSurveyID = Request.QueryString("SurveyID")
'Get the number of items on the page 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
'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
'Delete all the answers for items on the specified page from the SUR_ITEM_ANSWER table
strSQL = "DELETE FROM sur_item_answer " & _
"WHERE item_id IN (" & _
ConvertSQLInClause("SELECT item_id FROM sur_survey_to_item_mapping " & _
"WHERE survey_id = " & lngSurveyID & " AND page_number = " & lngPageNumber, "item_id") & _
")"
conDelete.Execute ConvertSQL(strSQL), , adCmdText
'Delete all the items for this page from the item table (SUR_ITEM)
strSQL = "DELETE FROM sur_item " & _
"WHERE item_id IN (" & _
ConvertSQLInClause("SELECT item_id FROM sur_survey_to_item_mapping " & _
"WHERE survey_id = " & lngSurveyID & " AND page_number = " & lngPageNumber, "item_id") & _
")"
conDelete.Execute ConvertSQL(strSQL), , adCmdText
'Delete all the entries for items on this page from the mapping table (SUR_SURVEY_TO_ITEM_MAPPING)
strSQL = "DELETE FROM sur_survey_to_item_mapping " & _
"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 order_number = order_number - " & lngItemCount & _
" WHERE survey_id = " & lngSurveyID & _
" AND page_number > " & lngPageNumber
conDelete.Execute ConvertSQL(strSQL), , adCmdText
'Move all the pages after the page just deleted up one position in the mapping table (SUR_SURVEY_TO_ITEM_MAPPING)
strSQL = "UPDATE sur_survey_to_item_mapping " & _
"SET page_number = page_number - 1 " & _
"WHERE survey_id = " & lngSurveyID & _
" AND page_number > " & lngPageNumber
conDelete.Execute ConvertSQL(strSQL), , adCmdText
'Clean up
conDelete.Close
Set conDelete = Nothing
'Redirect to the modify survey page for the survey.
Response.Redirect "ModifySurvey.asp?SurveyID=" & lngSurveyID
%>