home *** CD-ROM | disk | FTP | other *** search
/ bombers.k12.ar.us / bombers.k12.ar.us.tar / bombers.k12.ar.us / survey_unconfigured / IPAddressListAction.asp < prev    next >
Text File  |  2006-10-25  |  6KB  |  160 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 saves all IP address ranges.
  7. '
  8. '   COPYRIGHT NOTICE                                
  9. '
  10. '   See attached Software License Agreement
  11. '
  12. '   (c) Copyright 2002 - 2006 by ClassApps.com.  All rights reserved.
  13. '***********************************************************************
  14. %>
  15. <!--#Include File="Include/Config_inc.asp"-->
  16. <!--#Include File="Include/Utility_inc.asp"-->
  17. <!--#Include File="Include/adovbs_inc.asp"-->
  18. <!--#Include File="Include/ID_inc.asp"-->
  19. <!--#Include File="Include/CurrentUser_inc.asp"-->
  20. <!--#Include File="Include/SurveySecurity_inc.asp"-->
  21. <!--#Include File="Include/Constants_inc.asp"-->
  22. <!--#Include File="Include/Collection_inc.asp"-->
  23. <%
  24.     Dim strSQL
  25.     Dim conIPAddress
  26.     Dim rsIPAddressList
  27.     Dim lngSurveyID
  28.     Dim lngIPAddressID
  29.     Dim strRedirectPage
  30.     Dim strIPAddressFirst
  31.     Dim strIPAddressSecond
  32.         
  33.     'Initialization
  34.     Set rsIPAddressList = Server.CreateObject("ADODB.Recordset")
  35.     Set conIPAddress = Server.CreateObject("ADODB.Connection")
  36.     conIPAddress.Open SURVEY_APP_CONNECTION
  37.     lngSurveyID = Request.Form("SurveyID")
  38.  
  39.     'If the user clicked the "Delete" button, delete the IP address
  40.     If Request.Form("ActionAfterSave") = SUR_IP_ADDRESS_ACTION_DELETE Then
  41.         DeleteIPAddress Request.Form("IPAddressID")
  42.     End If
  43.  
  44.     'Select a list of all of the IP address ID's for this user for this survey
  45.     strSQL = "SELECT ip_address_id " & _
  46.              "FROM sur_ip_address " & _
  47.              "WHERE survey_id = " & lngSurveyID & _
  48.              " ORDER BY ip_address_first, ip_address_second"
  49.     rsIPAddressList.Open ConvertSQL(strSQL), SURVEY_APP_CONNECTION, adOpenForwardOnly, adLockReadOnly, adCmdText
  50.  
  51.     'Make sure that there are items for this survey
  52.     If Not rsIPAddressList.EOF Then
  53.         rsIPAddressList.MoveFirst
  54.  
  55.         'Loop through the IP Address and save each one
  56.         Do While Not rsIPAddressList.EOF
  57.             'Preserve the current IP address ID in a variable because it is used many times in this section
  58.             lngIPAddressID = rsIPAddressList("ip_address_id")
  59.  
  60.             'Initialize the variables for each update
  61.             strIPAddressFirst = Request.Form("txtIPAddressFirst" & CStr(lngIPAddressID))
  62.             strIPAddressSecond = Request.Form("txtIPAddressSecond" & CStr(lngIPAddressID))
  63.  
  64.             'Update the IP address
  65.             strSQL = "UPDATE sur_ip_address SET " & _
  66.                      "ip_address_first = " & SQLEncode(strIPAddressFirst) & ", " & _
  67.                      "ip_address_second = " & SQLEncode(strIPAddressSecond) & _
  68.                      " WHERE ip_address_id = " & lngIPAddressID
  69.             conIPAddress.Execute ConvertSQL(strSQL), , adCmdText
  70.  
  71.             'Move to the next IP address
  72.             rsIPAddressList.MoveNext
  73.         Loop
  74.     End If
  75.  
  76.     'Clean up
  77.     rsIPAddressList.Close
  78.     conIPAddress.Close
  79.     Set rsIPAddressList = Nothing
  80.     Set conIPAddress = Nothing
  81.  
  82.     'If the user clicked the "Insert New" button, add a new IP address
  83.     If Request.Form("ActionAfterSave") = SUR_IP_ADDRESS_ACTION_INSERT Then
  84.         InsertIPAddress lngSurveyID
  85.         strRedirectPage = "IPAddressList"
  86.     ElseIf Request.Form("ActionAfterSave") = SUR_IP_ADDRESS_ACTION_DELETE Then
  87.         'If the user clicked the "Delete" button, redirect back to the list of IP Address
  88.         strRedirectPage = "IPAddressList"
  89.     Else
  90.         strRedirectPage = "Survey"
  91.     End If    
  92.  
  93.     'Redirect back to the appropriate page    
  94.     Response.Redirect strRedirectPage & ".asp?SurveyID=" & lngSurveyID & "&SurveyName=" & Request.Form("SurveyName")
  95.  
  96. '*****************************************************************************************
  97. ' Name:         DeleteIPAddress
  98. ' Purpose:      Deletes an existing IP address range
  99. '                
  100. ' Arguments:    lngIPAddressID -- The ID of the IP address range to delete
  101. '
  102. ' Notes:        
  103. '*****************************************************************************************
  104. Sub DeleteIPAddress(lngIPAddressID)
  105.  
  106.     Dim strSQL
  107.     Dim conDelete
  108.     
  109.     'Initialization
  110.     Set conDelete = Server.CreateObject("ADODB.Connection")
  111.     conDelete.Open SURVEY_APP_CONNECTION
  112.     
  113.     'Delete the IP address from the IP address table (SUR_IP_ADDRESS)
  114.     strSQL = "DELETE FROM sur_ip_address " & _
  115.              "WHERE ip_address_id = " & lngIPAddressID
  116.     conDelete.Execute ConvertSQL(strSQL), , adCmdText
  117.  
  118.     'Clean up
  119.     conDelete.Close
  120.     Set conDelete = Nothing
  121.  
  122. End Sub
  123.  
  124. '*****************************************************************************************
  125. ' Name:         InsertIPAddress
  126. ' Purpose:      Inserts a new IP address range for the specified survey
  127. '                
  128. ' Arguments:    lngSurveyID -- The ID of the survey that should have a new IP address range added to it
  129. '
  130. ' Notes:        Note that this routine writes the new IP address to the database, and
  131. '                sets all of the default values.
  132. '*****************************************************************************************
  133. Sub InsertIPAddress(lngSurveyID)
  134.  
  135.     Dim strSQL
  136.     Dim conInsertIPAddress
  137.     Dim lngIPAddressID
  138.         
  139.     'Initialization
  140.     Set conInsertIPAddress = Server.CreateObject("ADODB.Connection")
  141.     conInsertIPAddress.Open SURVEY_APP_CONNECTION
  142.  
  143.     'Get the ID for a new IP address
  144.     lngIPAddressID = ID_GetNextAvailableID("SurveyGenerationIPAddress")
  145.  
  146.     'Insert the new IP address into the database
  147.     strSQL = "INSERT INTO sur_ip_address(ip_address_id, survey_id, ip_address_first, ip_address_second) " & _
  148.                 "VALUES(" & _
  149.                 lngIPAddressID & ", " & _
  150.                 lngSurveyID & ", " & _
  151.                 "'1.1.1.1', '255.255.255.255')"
  152.     conInsertIPAddress.Execute ConvertSQL(strSQL), , adCmdText
  153.  
  154.     'Clean up
  155.     conInsertIPAddress.Close
  156.     Set conInsertIPAddress = Nothing
  157.  
  158. End Sub
  159.  
  160. %>