Back to the Source Listing 

<!--#include file="includes/FacConn.inc"-->

<%
'Developer: Angela Johnston
'Date: February 21, 2002
'
'addMiscCategory.asp - This page adds the information from editMiscCategory.asp to the faculty database.
'
'
'***************************************************************************************************************
'Included pages
' FacConn.inc - Checks whether the user has application priviledges
' formStyle.css - The style sheet for the Faculty Application
' adovbs.inc - A page usually included with ASP to make openning tables and running queries easier.
' It assigns names to numbers, so that you don't have to remember what each number means.
' footer.asp - Contains the menu that should be located at the bottom of the page
'
'QueryStrings (name - value)
' None
'
'Recordsets (name - value)
' rsUser - (FacConn.inc) contains the current user logged on to the intranet (tblUser)
' rsFac - contains the current faculty members information (tblFaculty)
' rsCat - contains all the miscellaneous categories for the current faculty member (tblMiscCategory)
' rsItems - contains all the miscellaneous data items for the current miscellaneous category (tblMiscData)
'
'Variables
' strSQL - (FacConn.inc) use to store the sql string for a query
' bAdmin - (FacConn.inc) boolean value, "True" if user is an Administrator, "False" if the user is not
' lngUserID - (FacConn.inc) the ID number for the current user
' strUserLogon - (FacConn.inc) the Logon Name for the current user
' intCount - keeps track of the number for the current data item.
' bNew - true if adding a new Category
' bNewItem - true if adding a new Item
'
'
'Form Fields
' Title - A text box that contains the title of the Category
' Information - A text box that allows the user to enter a new item under the current category
' Location - A text box that allows the user to enter a URL location for the item in the
' Information text box.
' Information1 - The first item under the current category
' Location1 - The URL location for the first item
' ...
' Information# - The last item under the current category
' Location# - The URL location for the last item under the current category
' Count - A hidden text box that contains the number of items already in the current category
'
'***************************************************************************************************************
%>
<%
Dim rsCat, rsFac, rsItems, lngCatID, lngFacID, intCount
Dim bNew, bNewItem
'If we need to delete an item
If Request("Remove") <> "" Then
Set rsItems = Server.CreateObject("ADODB.Recordset")
strSql = "SELECT * FROM tblMiscData WHERE fldMiscDataID = " & Request("fldMiscDataID") & ";"
rsItems.Open strSQL, fp_conn, adOpenDynamic, adLockOptimistic, adCmdText
If Not rsItems.EOF Then
rsItems.Delete
End If
rsItems.Close
 
'Go back to the Main form
Response.Redirect "editPage.asp"
End If
 
 
'Remove all of the items in the category along with the category itself
If Request("RemoveAll") <> "" Then
Set rsItems = Server.CreateObject("ADODB.Recordset")
strSql = "SELECT * FROM tblMiscData WHERE fldMiscCatID = " & Request("MiscCatID") & ";"
rsItems.Open strSQL, fp_conn, adOpenDynamic, adLockOptimistic, adCmdText
 
'Delete all of the items in the category
While Not rsItems.EOF
rsItems.Delete
rsItems.MoveNext
Wend
 
rsItems.Close
 
Set rsCat = Server.CreateObject("ADODB.Recordset")
strSql = "SELECT * FROM tblMiscCategory WHERE fldMiscCatID = " & Request("MiscCatID") & ";"
rsCat.Open strSQL, fp_conn, adOpenDynamic, adLockOptimistic, adCmdText
 
'Delete the Category
If Not rsCat.EOF Then
rsCat.Delete
End If
 
rsCat.Close
Else
'Get the Current Faculty ID
If bAdmin = "True" Then
lngFacID = Session("FacID")
Else
 
'Open a recordset containing the current faculty member using the variable lngUserID
Set rsFac = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM tblFaculty WHERE fldUserID = " & lngUserID & ";"
rsFac.Open strSQL, fp_conn, adOpenDynamic, adLockOptimistic, adCmdText
 
lngFacID = rsFac("fldFacID")
rsFac.Close
 
End If
'Open recordset containing all categories
Set rsCat = Server.CreateObject("ADODB.Recordset")
rsCat.Open "tblMiscCategory", fp_conn, adOpenDynamic, adLockOptimistic, adCmdTable
'If no MiscCatID was present then we are creating a new category
If Request("MiscCatID") = "" Then
'Add new category is true
bNew = True
'Create new category
rsCat.AddNew
Else
'Find the record for the selected category and store the Misc Category ID number
lngCatID = Request("MiscCatID")
rsCat.Filter = "fldMiscCatID = " & lngCatID
bNew = False
End If
'Update or create the category information
rsCat("fldFacID") = lngFacID
rsCat("fldMiscTitle") = Request.Form("Title")
 
rsCat.Update
rsCat.Close
'Get the Category ID for new categories only
If bNew Then
Set rsCat = Server.CreateObject("ADODB.Recordset")
rsCat.Open "tblMiscCategory", fp_conn
 
rsCat.Filter = "fldFacID =" & lngFacID
rsCat.Filter = "fldMiscTitle = '" & Request.Form("Title") & "'"
lngCatID = rsCat("fldMiscCatID")
 
rsCat.Close
 
End If
End If
 
'Update each item in the Category
'********************************
If Request.Form("Count") > "0" Then
'Open a recordset containing all items for the current MiscCategory
Set rsItems = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM tblMiscData WHERE fldMiscCatID = " & lngCatID & ";"
rsItems.Open strSQL, fp_conn, adOpenDynamic, adLockOptimistic, adCmdText
intCount = 0
'Check how many items in the Category there are
While Request.Form("Count") > intCount AND Not rsItems.EOF
intCount = intCount + 1
 
'Update the category information
rsItems("fldInformation") = Request.Form("Information" & intCount)
rsItems("fldLocation") = Request.Form("Location" & intCount)
 
rsItems.Update
rsItems.MoveNext
Wend
 
'Update and close the recordsets
 
rsItems.Close
End If
'Check whether we are also adding a new item to the category
'***********************************************************
If Request.Form("Information") <> "" Then
Set rsItems = Server.CreateObject("ADODB.Recordset")
rsItems.Open "tblMiscData", fp_conn, adOpenDynamic, adLockOptimistic, adCmdTable
 
'Create new item for the current category
rsItems.AddNew
 
'Update or create the category information
rsItems("fldMiscCatID") = lngCatID
rsItems("fldInformation") = Request.Form("Information")
rsItems("fldLocation") = Request.Form("Location")
'Update and close the table
rsItems.Update
rsItems.Close
 
If Request("Add") <> "" Then
'Go back to the Category edit form
Response.Redirect "editMiscCategory.asp?fldMiscCatID=" & lngCatID
End If
End If
 
'Go back to the Main Page form
Response.Redirect "editPage.asp"
 
%>