%@ Language=VBScript%>
<%Response.Buffer = True%>
<%
set fso = Server.CreateObject("scripting.FileSystemObject")
set myFile = fso.OpenTextFile("C:\diagnostics.txt", 8, Create)
'retrieve info from form
elected = request.form("elected")
runcount = request.form("runcount")
ComID = request.form("ComID")
EType = request.form("EType")
myfile.WriteLine("Num of elected peeps is: " & CStr(elected))
myfile.WriteLine("Num of runcounts is: " & CStr(runcount))
'gets id for an elected member
Set objType= Server.CreateObject("ADODB.Recordset")
GetMemType(objType)
Dim MType 'Member type
MType = objType.fields("TYPE_ID").value
objType.Close
set objType = Nothing
dbNVS.Close
'gets recordset of persons whom terms expires committee
Set objExp= Server.CreateObject("ADODB.Recordset")
GetExpPeople objExp, ComID
Set DictExp = Server.CreateObject("Scripting.Dictionary")
GetExpDict objExp, DictExp
'Gets all keys and items into an array
arrKeys = DictExp.Keys 'User ID
arrItems = DictExp.Items 'Com ID
objExp.close
set objExp = Nothing
dbNVS.Close
'gets the term lenght for the committee
Set objTerm= Server.CreateObject("ADODB.Recordset")
GetTermLength objTerm, ComID
'the following code calculates the new term expiration
Dim NewTerm 'Term Experation Date for new member
length = objTerm.fields("TERM_LENGTH").value
Newdate = DateAdd("yyyy", length, Date)
NewTerm = DatePart("yyyy", Newdate)
objTerm.Close
set ObjTerm = Nothing
dbNVS.Close
ClearVoteTable(ComID)
UpdateApproveStatus(ComID)
'gets recordset of persons voted for in a committee
Set dictVote = Server.CreateObject("Scripting.Dictionary")
GetCommsPeopleIDs dictVote, ComID
lngVoteCount = dictVote.Count
arrVoteKeys = dictVote.Keys 'User ID
arrVoteItems = dictVote.Items 'F_NAME
Dim runoff 'Bool to redirect to edit committee
Dim ElectedCt 'Counts number of updates
Dim RunoffCt 'Counts number of runoffs
UpdateCt = 0
RunoffCt = 0
runoff = false
'Update dbNVS for Elected members
'***********************************************
'Removes all members from the members table whos terms are up
ClearMember(ComID)
For IntLoops = 0 to Elected-1
'myFile.WriteLine(CStr(IntLoops) & " - " & Cstr(arrVoteKeys(IntLoops)))
'Response.Write "Add New User: " + Cstr(arrVoteKeys(IntLoops)) + "
"
ClearElectedResult arrVoteKeys(IntLoops), ComID
' 'Response.Write "Delete old member: " + Cstr(arrKeys(IntLoops)) + "
"
AddMember arrVoteKeys(IntLoops), ComID, NewTerm, Mtype
Next
' Response.Write "
IntLoops: " + Cstr(IntLoops) + "
"
If runcount > 0 Then
runoff = True
If Not EType Then
ClearAllResults(ComID) 'No multiple runoffs
Else
UpdateElectionType(ComID)
End If
'Updates dbNVS for Runoff members
For count = 0 to runcount-1
cnt = IntLoops + Count
'MyFile.WriteLine("Runoff User: " + Cstr(arrVoteKeys(cnt)))
UpdateResults arrVoteKeys(cnt), ComID
Next
cnt = cnt + 1
End If
' Response.Write "
Cnt: " + Cstr(cnt) + "
"
arrCount = lngVoteCount - cnt
For count = 0 to arrCount - 1 'Clears people who are not elected or in a runoff
ClearElectedResult arrVoteKeys(cnt + Count), ComID
' MyFile.WriteLine("OTHER User: " + Cstr(arrVoteKeys(cnt + Count)))
Next
'Response.End
If runoff = True Then
Response.Clear
Response.Redirect"committee_edit.asp?init=0&mode=edit&ComID=" & Cint(ComID)
Response.End
Else
Response.Clear
Response.Redirect "approve_results.asp?init=1"
Response.End
End If
objVote.Close
set objVote = Nothing
Set dbNVS = Nothing
myfile.Close
%>
<%
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' Gets all committee member whose terms are expired
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function GetExpPeople(objExp, ComID)%>
<%
On Error Resume Next
strSQL = "SELECT * FROM [MEMBER] WHERE [COMID] = " & Cint(ComID)
strSQL = strSQL + " AND [TERM] = '" & Cstr(Year(Date())) + "'"
strSQL = strSQL + " ORDER BY [USER_ID] DESC"
dbNVS.Open
objExp.Open strSQL, dbNVS ', adOpenKeyset, adLockOptimistic
If Err.Number <> 0 then
Response.Clear
Response.Redirect "error.asp?mess=A system error occured with the function GetExpPeople.
Please contact the Nominations and Election Committee to resolve this problem.
Please click the back button."
Response.End
End If
End Function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%>
<%
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'Funciton Create a Dictionary For The Voting Results Table
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function GetExpDict(objExp, DictExp)
Dim USER, COMM 'Vars used for storage to get around quotation problems
DO While Not objExp.EOF
USER = objExp.fields("USER_ID").value
COMM = objExp.fields("ComID").value
DictExp.Add USER, COMM
objExp.MoveNext
Loop
End Function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%>
<%
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' Gets term length for a committee
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function GetTermLength(objTerm, ComID)%>
<%
On Error Resume Next
strSQL = "SELECT [TERM_LENGTH] FROM [COMM1] WHERE [ComID] = " & Cint(ComID)
dbNVS.Open
objTerm.Open strSQL, dbNVS ', adOpenKeyset, adLockOptimistic
If Err.Number <> 0 then
Response.Clear
Response.Redirect "error.asp?mess=A system error occured with the function GetTermLength.
Please contact the Nominations and Election Committee to resolve this problem.
Please click the back button."
Response.End
End If
End Function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%>
<%
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' Gets Member Type
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function GetMemType(objType)%>
<%
On Error Resume Next
Dim strSQL
strSQL = "SELECT [TYPE_ID] FROM [MEMBER_TYPE] WHERE [TYPE_NAME] LIKE 'Elected'"
dbNVS.Open
objType.Open strSQL, dbNVS ', adOpenKeyset, adLockOptimistic
If Err.Number <> 0 then
Response.Clear
Response.Redirect "error.asp?mess=A system error occured with the function GetTermLength.
Please contact the Nominations and Election Committee to resolve this problem.
Please click the back button."
Response.End
End If
End Function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%>
<%
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function ClearAllResults(ComID)%>
<%On Error Resume Next
Dim cmdDELETE
Set cmdDELETE = Server.CreateObject("ADODB.command")
Dim strSQL
strSQL = "DELETE FROM [VOTING_RESULTS] WHERE [COMID] = " & Cint(ComID)
dbNVS.Open
cmdDELETE.ActiveConnection = dbNVS
cmdDELETE.CommandText = strSQL
dbNVS.BeginTrans
cmdDELETE.Execute
'Error Handling in a small way...
If Err.Number > 0 then
'something is wrong...don't allow update to database...
dbNVS.RollBack
message = "A system error occured with the function ClearVoteTable." + _
"
Please click the BACK button."
Response.Clear
Response.Redirect "error.asp?mess=" + Server.URLEncode(message)
Response.End
End if
dbNVS.CommitTrans
dbNVS.Close
Set cmdDELETE = Nothing
End Function
%>
<%
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function ClearVoteTable(ComID)%>
<%On Error Resume Next
Dim cmdDELETE
Set cmdDELETE = Server.CreateObject("ADODB.command")
Dim strSQL
strSQL = "DELETE FROM [VOTED] WHERE [COMID] = " & Cint(ComID)
dbNVS.Open
cmdDELETE.ActiveConnection = dbNVS
cmdDELETE.CommandText = strSQL
dbNVS.BeginTrans
cmdDELETE.Execute
'Error Handling in a small way...
If Err.Number > 0 then
'something is wrong...don't allow update to database...
dbNVS.RollBack
message = "A system error occured with the function ClearVoteTable." + _
"
Please click the BACK button."
Response.Clear
Response.Redirect "error.asp?mess=" + Server.URLEncode(message)
Response.End
End if
dbNVS.CommitTrans
dbNVS.Close
Set cmdDELETE = Nothing
End Function
%>
<%
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' This function clears the results of the members who have met the criteria to be
' elected from "VOTING_RESULTS"
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function ClearElectedResult(lngUSER_ID, ComID)
%>
<%On Error Goto 0
Dim cmdDELETE
Set cmdDELETE = Server.CreateObject("ADODB.command")
Dim strSQL
strSQL = "DELETE FROM [VOTING_RESULTS] WHERE [COMID] = " & Cint(ComID)
strSQL = strSQL + " AND [USER_ID] = " & Cstr(lngUSER_ID)
dbNVS.Open
cmdDELETE.ActiveConnection = dbNVS
cmdDELETE.CommandText = strSQL
dbNVS.BeginTrans
cmdDELETE.Execute
'Error Handling in a small way...
If Err.Number > 0 then
'something is wrong...don't allow update to database...
dbNVS.RollBack
message = "A system error occured with the function ClearAllResults." + _
"
Please click the BACK button."
Response.Clear
Response.Redirect "error.asp?mess=" + Server.URLEncode(message)
Response.End
End if
dbNVS.CommitTrans
dbNVS.Close
Set cmdDELETE = Nothing
End Function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%>
<%
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'This Function resets runoff votes to 0
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function UpdateResults(User, ComID)%>
<%On Error Resume Next
UpdateResults = False
Dim strSQL
Dim cmdEDIT
Set cmdEDIT = Server.CreateObject("ADODB.command")
dbNVS.Open
cmdEDIT.ActiveConnection = dbNVS
dbNVS.BeginTrans
strSQL = "UPDATE [VOTING_RESULTS] SET [VOTES] = 0 WHERE"
strSQL = strSQL + " [USER_ID] = " & Cstr(User) & " AND [COMID] = " & Cint(ComID)
cmdEDIT.CommandText = strSQL
cmdEDIT.Execute
'Error Handling in a small way...
If Err.Number > 0 then
'something is wrong...don't allow update to database...
dbNVS.RollBack
message = "A system error occured with the function UpdateResults." + _
"
Please click the BACK button."
'Response.Clear
'Response.Redirect "error.asp?mess=" + Server.URLEncode(message)
'Response.End
End if
dbNVS.CommitTrans
dbNVS.Close
Set cmdEDIT = Nothing
End Function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%>
<%
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'This function add a NEW member to the "MEMBERS" table
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function AddMember(lngUSER_ID, ComID, NewTerm, MType)%>
<%
On Error Goto 0
Dim strSQL
Dim cmdADD
Set cmdADD = Server.CreateObject("ADODB.command")
dbNVS.Open
cmdADD.ActiveConnection = dbNVS
dbNVS.BeginTrans
strSQL = "INSERT INTO [MEMBER] ([USER_ID], [COMID], [TYPE_ID], [TERM])"
strSQL = strSQL + " VALUES (" & Cstr(lngUSER_ID) & ", " & Cint(ComID) & "," & Cint(MType) & ", '" & Cstr(NewTerm) & "')"
cmdADD.CommandText = strSQL
cmdADD.Execute
'Error Handling in a small way...
If Err.Number > 0 then
'something is wrong...don't allow update to database...
dbNVS.RollBack
message = "A system error occured with the function AddMember." + _
"
Please click the BACK button."
Response.Clear
Response.Redirect "error.asp?mess=" + Server.URLEncode(message)
Response.End
End if
dbNVS.CommitTrans
dbNVS.Close
Set cmdADD = Nothing
End Function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%>
<%
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' Updates Election type to runoff
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function UpdateElectionType(ComID)%>
<%On Error Resume Next
Dim strSQL
Dim cmdEDIT
Set cmdEDIT = Server.CreateObject("ADODB.command")
dbNVS.Open
cmdEDIT.ActiveConnection = dbNVS
dbNVS.BeginTrans
strSQL = "UPDATE [COMM1] SET [ELECTION_TYPE] = " & Cstr(Cint(False)) & " WHERE"
strSQL = strSQL + " [COMID] = " & Cint(ComID)
cmdEDIT.CommandText = strSQL
cmdEDIT.Execute
'Error Handling in a small way...
If Err.Number > 0 then
'something is wrong...don't allow update to database...
dbNVS.RollBack
message = "A system error occured with the function UpdateElectionType." + _
"
Please click the BACK button."
Response.Clear
Response.Redirect "error.asp?mess=" + Server.URLEncode(message)
Response.End
End if
dbNVS.CommitTrans
dbNVS.Close
Set cmdEDIT = Nothing
End Function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%>
<%
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' Updates Election Approve Status to True
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function UpdateApproveStatus(ComID)%>
<%On Error Resume Next
Dim strSQL
Dim cmdEDIT
Set cmdEDIT = Server.CreateObject("ADODB.command")
dbNVS.Open
cmdEDIT.ActiveConnection = dbNVS
dbNVS.BeginTrans
strSQL = "UPDATE [COMM1] SET [APPROVE_STATUS] = " & Cstr(Cint(True)) & " WHERE"
strSQL = strSQL + " [COMID] = " & Cint(ComID)
cmdEDIT.CommandText = strSQL
cmdEDIT.Execute
'Error Handling in a small way...
If Err.Number > 0 then
'something is wrong...don't allow update to database...
dbNVS.RollBack
message = "A system error occured with the function UpdateElectionType." + _
"
Please click the BACK button."
Response.Clear
Response.Redirect "error.asp?mess=" + Server.URLEncode(message)
Response.End
End if
dbNVS.CommitTrans
dbNVS.Close
Set cmdEDIT = Nothing
End Function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%>
<%
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' This function clears a member from the "MEMBERS" table each time a new member is added'
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function ClearMember(ComID)%>
<%'On Error Resume Next
'**************************************
'if Not UserID then
' exit Function
'elseif UserID = "" then
' exit Function
'elseif IsNull(UserID) Then
' exit Function
'end if
Dim cmdDELETE
Set cmdDELETE = Server.CreateObject("ADODB.command")
Dim strSQL
strSQL = "DELETE * FROM [MEMBER] WHERE [COMID] = " + CStr(ComID) + " AND [TERM] = """ + Cstr(Year(Date())) + """"
dbNVS.Open
cmdDELETE.ActiveConnection = dbNVS
cmdDELETE.CommandText = strSQL
'dbNVS.BeginTrans
cmdDELETE.Execute
'Error Handling in a small way...
If Err.Number > 0 then
'something is wrong...don't allow update to database...
'dbNVS.RollBack
message = "A system error occured with the function ClearMember." + _
"
Please click the BACK button."
Response.Clear
Response.Redirect "error.asp?mess=" + Server.URLEncode(message)
Response.End
End if
'dbNVS.CommitTrans
dbNVS.Close
Set cmdDELETE = Nothing
End Function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%>