<% option explicit dim objCon ' ------------------------------------------- fMakeCon Sub fMakeCon dim strConString 'Create and open connection to the database 'strConString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\bmp2k2\bmp2k2.mdb" strConString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=dbBmp;Data Source=12.11.184.33" set objCon = Server.CreateObject("ADODB.Connection") objCon.Open strConString End Sub 'fMakeCon ' --------------------------------------------- fKillCon Sub fKillCon 'Close db connection, kill object objCon.Close set objCon = Nothing End Sub 'fKillCon ' -------------------------------------------- fBadVote function fBadVote dim strRegionString if instr(request.cookies("voter")("region"), request.form("txtRegion")) = 0 then ' User hasn't voted in this region yet, let them through fBadVote = False else ' Voter is trying to stuff the ballot box, shut 'em down fBadVote = true end if end function 'fBadVote ' --------------------------------------------- fCleanForDB Function fCleanForDB(strInPut) If InStr(strInPut, chr(34)) Then strInPut = Replace(strInPut, chr(34), """) End If If InStr(strInPut, chr(39)) Then strInPut = Replace(strInPut, chr(39), "'") End If fCleanForDB = strInPut End Function 'fCleanForDB ' ----------------------------------------------- sSaveUser sub sSaveUser dim strSQL dim strName dim strAddress dim strCity dim strState dim strZip dim strEmail dim strRegion on error resume next strName = fCleanForDB(request.form("txtName")) strAddress = fCleanForDB(request.form("txtAddress")) strCity = fCleanForDB(request.form("txtCity")) strState = fCleanForDB(request.form("txtState")) strZip = fCleanForDB(request.form("txtZip")) strEmail = fCleanForDB(request.form("txtEmail")) strRegion = fCleanForDB(request.form("txtRegion")) strSQL = "" strSQL = strSQL & "INSERT INTO tbl_web_voter " strSQL = strSQL & "(str_name, str_address, str_city, str_state, str_zip, str_email, str_region) " strSQL = strSQL & "VALUES ('" & strName & "', '" & strAddress & "', '" & strCity & "', '" & strState & "', '" & strZip & "', '" & strEmail & "', '" & strRegion & "')" 'Call fMakeCon objCon.execute strSQL 'Call fKillCon end sub 'sSaveUser ' ------------------------------------------- sRecordNational sub sRecordNational dim intCat dim strTCat dim strSCat dim intAct dim strSQL on error resume next 'Call fMakeCon for intCat = 1 to 16 strTCat = "txtNat" & intCat strSCat = "optNat" & intCat if len(request.form(strTCat)) > 0 then 'Record Write-In Vote strSQL = "" strSQL = strSQL & "INSERT INTO tbl_nat_write_in " strSQL = strSQL & "(fk_cat_id, str_act_name) " strSQL = strSQL & "VALUES(" & intCat & ", '" & fCleanForDB(request.form(strTCat)) & "')" objCon.execute strSQL else 'Check for checked vote if request.form(strSCat) <> "" then 'Record Checked Vote strSQL = "" strSQL = strSQL & "UPDATE tbl_band_nat " strSQL = strSQL & "SET int_vote_count = int_vote_count + 1, " strSQL = strSQL & "int_web_vote = int_web_vote + 1 " strSQL = strSQL & "WHERE pk_ent_id = '" & request.form(strSCat) & "'" objCon.execute strSQL end if end if next 'intCat 'Call fKillCon end Sub 'sRecordNational ' ------------------------------------------- sRecordLocal sub sRecordLocal dim intCat dim strTCat dim strSCat dim strOptTable dim strWrInTable dim intAct dim strSQL 'on error resume next ' Select proper region tables to write into select case request.form("txtRegion") case "boston" strOptTable = "tbl_band_bost " strWrInTable = "tbl_bos_write_in " case "portland" strOptTable = "tbl_band_port " strWrInTable = "tbl_port_write_in " case "providence" strOptTable = "tbl_band_prov " strWrInTable = "tbl_prv_write_in " end select for intCat = 1 to 16 strTCat = "txtLoc" & intCat strSCat = "optLoc" & intCat if len(request.form(strTCat)) > 0 then 'Record Write-In Vote strSQL = "" strSQL = strSQL & "INSERT INTO " & strWrInTable strSQL = strSQL & "(fk_cat_id, str_act_name) " strSQL = strSQL & "VALUES(" & intCat & ", '" & fCleanForDB(request.form(strTCat)) & "')" objCon.execute strSQL else 'Check for checked vote if request.form(strSCat) <> "" then 'Record Checked Vote strSQL = "" strSQL = strSQL & "UPDATE " & strOptTable strSQL = strSQL & "SET int_vote_count = int_vote_count + 1, " strSQL = strSQL & "int_web_vote = int_web_vote + 1 " strSQL = strSQL & "WHERE pk_ent_id = '" & request.form(strSCat) & "'" objCon.execute strSQL end if end if next 'intCat end Sub 'sRecordLocal ' ----------------------------------------------------------------------- ' Begin App... if fBadVote then select case request.form("txtRegion") ' User has already voted, send them to appropriate cheater page case "boston" response.redirect "ko_bos.html" case "portland" response.redirect "ko_prt.asp" case "providence" response.redirect "ko_prv.html" end select else ' Record user's votes and submitted information Call fMakeCon Call sRecordNational Call sRecordLocal Call sSaveUser Call fKillCon ' Get voter's region, append it to cookie string dim strRegion strRegion = request.cookies("voter") ("region") strRegion = strRegion & "*" & request.form("txtRegion") & "*" response.cookies("voter") ("region") = strRegion response.cookies("voter").expires = date + 30 'Send user to appropriate thank you page select case request.form("txtRegion") case "boston" response.redirect "ok_bos.html" case "portland" response.redirect "ok_prt.asp" case "providence" response.redirect "ok_prv.html" end select end if %>