%@ Language=VBScript %>
<% Response.Buffer = True %>
<%
If Validated() Then
SaveFac()
Set dbNVS = Nothing
Set dbConn = Nothing
Response.Clear
Response.Redirect "faculty_add.asp?confirm=yes"
Response.End
End If
%>
<%
Function Validated()%>
<%
On Error Resume Next
Validated = False
Dim strSQL, message
Dim rsFaculty
Set rsFaculty = Server.CreateObject("ADODB.Recordset")
GetFaculty rsFaculty
'USER ID************
If Trim(Request.Form("txtUserID")) = "" OR IsNull(Trim(Request.Form("txtUserID"))) Then
message = "You must supply an 6 character SNC Faculty ID #.
Please click the BACK button."
Response.Clear
Response.Redirect "error.asp?mess=" + Server.URLEncode(message)
Response.End
End If
If Len(Trim(Request.Form("txtUserID"))) < 5 Then
message = "The SNC Faculty ID # is 5-6 characters long.
Please click the BACK button to correct the error."
Response.Clear
Response.Redirect "error.asp?mess=" + Server.URLEncode(message)
Response.End
End If
If Not IsNumeric(Trim(Request.Form("txtUserID"))) Then
message = "The SNC Faculty ID # must be numeric.
Please click the BACK button to correct the error."
Response.Clear
Response.Redirect "error.asp?mess=" + Server.URLEncode(message)
Response.End
End If
'LOGIN************
If Trim(Request.Form("txtLogin")) = "" OR IsNull(Trim(Request.Form("txtLogin"))) Then
message = "You must supply a SNC Network Login Name.
Please click the BACK button."
Response.Clear
Response.Redirect "error.asp?mess=" + Server.URLEncode(message)
Response.End
End If
If Len(Trim(Request.Form("txtLogin"))) > 25 Then
message = "The SNC Network Login Name must be less than 25 characters long.
Please click the BACK button."
Response.Clear
Response.Redirect "error.asp?mess=" + Server.URLEncode(message)
Response.End
End If
'since the PASSWORD and USER_ID are the same, initially, we only need to validate one of them...
If Not rsFaculty.EOF Then
rsFaculty.MoveFirst
While Not rsFaculty.EOF
If Trim(Request.Form("txtUserID")) = rsFaculty.Fields("USER_ID").Value then
message = "The SNC ID # you have entered all ready exists in the database.
Please click the BACK button."
Response.Clear
Response.Redirect "error.asp?mess=" + Server.URLEncode(message)
Response.End
End If
If Trim(Request.Form("txtLogin")) = rsFaculty.Fields("LOGIN_ID").Value then
message = "The Network Login Id you have entered all ready exists in the database.
Please click the BACK button."
Response.Clear
Response.Redirect "error.asp?mess=" + Server.URLEncode(message)
Response.End
End If
rsFaculty.MoveNext
Wend
End If
dbNVS.Close
'FNAME************
If Trim(Request.Form("txtFName")) = "" OR IsNull(Trim(Request.Form("txtFName"))) Then
message = "You must supply a First Name.
Please click the BACK button."
Response.Clear
Response.Redirect "error.asp?mess=" + Server.URLEncode(message)
Response.End
End If
If Len(Trim(Request.Form("txtFName"))) > 20 Then
message = "The First Name must be less than 20 characters long.
Please click the BACK button."
Response.Clear
Response.Redirect "error.asp?mess=" + Server.URLEncode(message)
Response.End
End If
'LNAME************
If Trim(Request.Form("txtLName")) = "" OR IsNull(Trim(Request.Form("txtLName"))) Then
message = "You must supply a Last Name.
Please click the BACK button."
Response.Clear
Response.Redirect "error.asp?mess=" + Server.URLEncode(message)
Response.End
End If
If Len(Trim(Request.Form("txtLName"))) > 30 Then
message = "The Last Name must be less than 30 characters long.
Please click the BACK button."
Response.Clear
Response.Redirect "error.asp?mess=" + Server.URLEncode(message)
Response.End
End If
'EMAIL************ only length is checked b/c it is not a required field
If Len(Trim(Request.Form("txtEmail"))) > 50 Then
message = "The Email must be less than 50 characters long.
Please click the BACK button."
Response.Clear
Response.Redirect "error.asp?mess=" + Server.URLEncode(message)
Response.End
End If
Validated = True
Set rsFaculty = Nothing
End Function
%>
<%
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function SaveFac()%>
<%
On Error Resume Next
SaveFac = False
Set cmdFac = Server.CreateObject("ADODB.Command")
Dim strSQL, gen, tenure, admin, voter, message
If Request.Form("txtGender") <> "No" then 'F
gen = true 'M
else
gen = false
End If
If Request.Form("txtTenure") <> "No" then
tenure = true
else
tenure = false
End If
If Request.Form("txtAdmin") <> "No" then
admin = true
else
admin = false
End If
If Request.Form("txtAVoter") <> "No" then
voter = true
else
voter = false
End If
strSQL = "INSERT INTO Faculty ([USER_ID], [LOGIN_ID], [F_NAME], [L_NAME],"
strSQL = strSQL + " [SEX], [EMAIL], [DIV_ID], [TENURE], [ADMIN_ACCESS], [ACTIVE_VOTER]"
strSQL = strSQL + ") Values ("
strSQL = strSQL + cstr(clng(Request.Form("txtUserID"))) + ","
strSQL = strSQL + "'" + SQLFixTicks(Trim(Request.Form("txtLogin"))) + "',"
strSQL = strSQL + "'" + SQLFixTicks(Trim(Request.Form("txtFName"))) + "',"
strSQL = strSQL + "'" + SQLFixTicks(Trim(Request.Form("txtLName"))) + "',"
strSQL = strSQL + cstr(Cint(gen)) + ","
strSQL = strSQL + "'" + SQLFixTicks(Trim(Request.Form("txtEmail"))) + "',"
strSQL = strSQL + cstr(clng(Request.Form("selDiv"))) + ","
strSQL = strSQL + cstr(Cint(tenure)) + ","
strSQL = strSQL + cstr(Cint(admin)) + ","
strSQL = strSQL + cstr(Cint(voter)) + ")"
dbNVS.Open
cmdFac.ActiveConnection = dbNVS
cmdFac.CommandText = strSQL
dbNVS.BeginTrans
cmdFac.Execute
If Err.Number <> 0 then
message = "A system error occured with the function SaveFac on the x_faculty_add.asp page.
Please click the back button."
dbNVS.RollBack
Response.Clear
Response.Redirect "error.asp?mess=" + Server.URLEncode(message)
Response.End
SaveFac = False
End if
SaveFacPWD(admin)
dbNVS.CommitTrans
dbNVS.Close
Set cmdFac = Nothing
SaveFac = True
End Function
%>
<%
Function SaveFacPWD(admin)%>
<%
On Error Resume Next
SaveFacPWD = False
Dim cmdPWDFac
Set cmdPWDFac = Server.CreateObject("ADODB.Command")
Dim strSQL2, message2, admin2
If Request.Form("txtAdmin") <> "No" then
admin2 = 1
else
admin2 =0
End If
strSQL2 = "INSERT INTO [USERS] ([ID], [USERNAME], [PASSWORD], [ADMIN],[CHANGE_PWD]"
strSQL2 = strSQL2 + ") Values ("
strSQL2 = strSQL2 + cstr(clng(Request.Form("txtUserID"))) + ","
strSQL2 = strSQL2 + "'" + SQLFixTicks(Trim(Request.Form("txtLogin"))) + "',"
strSQL2 = strSQL2 + "'" + SQLFixTicks(Trim(Request.Form("txtUserID"))) + "'," 'set the user_id as the password
strSQL2 = strSQL2 + cstr(Cint(admin)) + ","
strSQL2 = strSQL2 + cstr(Cint(True)) + ")"
dbConn.Open
cmdPWDFac.ActiveConnection = dbConn
cmdPWDFac.CommandText = strSQL2
dbConn.BeginTrans
cmdPWDFac.Execute
If Err.Number <> 0 then
dbConn.RollBack
message2 = "A system error occured with the function SaveFacPWD on the x_faculty_add.asp page.
Please click the back button."
Response.Clear
Response.Redirect "error.asp?mess=" + Server.URLEncode(message2)
Response.End
SaveFacPWD = False
End if
dbConn.CommitTrans
dbConn.Close
Set cmdPWDFac = Nothing
SaveFacPWD = True
End Function
%>