% Response.Expires = 0 Response.ExpiresAbsolute = Now() - 1 Response.AddHeader "pragma", "no-cache" Response.AddHeader "cache-control", "private, no-cache, no-store, must-revalidate" %> <% If Not IsLoggedIn And Request.Cookies(ewProjectName)("autologin") = "autologin" And Request.Cookies(ewProjectName)("password") <> "" Then Response.Redirect "login.asp" Call LoadUserLevel() If IsLoggedIn Then ewCurSec = CurrentUserLevelPriv("chapter") Else ewCurSec = GetAnonymousPriv("chapter") End If If (ewCurSec And ewAllowAdd) <> ewAllowAdd Then Response.Redirect "chapterlist.asp" If IsLoggedIn And CurrentUserID = "" Then Session(ewSessionMessage) = "You do not have the right permission to view the page" Response.Redirect "login.asp" End If %> <% ' Initialize common variables x_chapter_pkey = Null: ox_chapter_pkey = Null: z_chapter_pkey = Null x_chapter_FFAid = Null: ox_chapter_FFAid = Null: z_chapter_FFAid = Null x_chapter_schoolname = Null: ox_chapter_schoolname = Null: z_chapter_schoolname = Null x_chapter_schooladdress1 = Null: ox_chapter_schooladdress1 = Null: z_chapter_schooladdress1 = Null x_chapter_schooladdress2 = Null: ox_chapter_schooladdress2 = Null: z_chapter_schooladdress2 = Null x_chapter_schooladdress3 = Null: ox_chapter_schooladdress3 = Null: z_chapter_schooladdress3 = Null x_chapter_schoolcity = Null: ox_chapter_schoolcity = Null: z_chapter_schoolcity = Null x_chapter_schoolstate = Null: ox_chapter_schoolstate = Null: z_chapter_schoolstate = Null x_chapter_schoolzipcode = Null: ox_chapter_schoolzipcode = Null: z_chapter_schoolzipcode = Null x_chapter_schoolzipcode4 = Null: ox_chapter_schoolzipcode4 = Null: z_chapter_schoolzipcode4 = Null x_chapter_schooladvisor = Null: ox_chapter_schooladvisor = Null: z_chapter_schooladvisor = Null x_chapter_region = Null: ox_chapter_region = Null: z_chapter_region = Null x_chapter_website = Null: ox_chapter_website = Null: z_chapter_website = Null x_chapter_email = Null: ox_chapter_email = Null: z_chapter_email = Null x_chapter_picture = Null: ox_chapter_picture = Null: z_chapter_picture = Null fs_x_chapter_picture = 0: fn_x_chapter_picture = "": ct_x_chapter_picture = "" wd_x_chapter_picture = 0: ht_x_chapter_picture = 0: a_x_chapter_picture = "" x_chapter_picturename = Null: ox_chapter_picturename = Null: z_chapter_picturename = Null fs_x_chapter_picturename = 0: fn_x_chapter_picturename = "": ct_x_chapter_picturename = "" wd_x_chapter_picturename = 0: ht_x_chapter_picturename = 0: a_x_chapter_picturename = "" x_chapter_picturetype = Null: ox_chapter_picturetype = Null: z_chapter_picturetype = Null x_chapter_theme = Null: ox_chapter_theme = Null: z_chapter_theme = Null x_chapter_bio = Null: ox_chapter_bio = Null: z_chapter_bio = Null x_chapter_links = Null: ox_chapter_links = Null: z_chapter_links = Null x_chapter_officers = Null: ox_chapter_officers = Null: z_chapter_officers = Null x_chapter_advisors = Null: ox_chapter_advisors = Null: z_chapter_advisors = Null x_chapter_courses = Null: ox_chapter_courses = Null: z_chapter_courses = Null x_chapter_news = Null: ox_chapter_news = Null: z_chapter_news = Null x_chapter_events = Null: ox_chapter_events = Null: z_chapter_events = Null x_memberid = Null: ox_memberid = Null: z_memberid = Null %> <% Response.Buffer = True ' Load key from QueryString bCopy = True x_chapter_pkey = Request.QueryString("chapter_pkey") If x_chapter_pkey = "" Or IsNull(x_chapter_pkey) Then bCopy = False End If sAction = "" If Not RequestBlobData() Then If bCopy Then sAction = "C" ' Copy Record Else sAction = "I" ' Display Blank Record End If End If ' Open connection to the database Set conn = Server.CreateObject("ADODB.Connection") conn.Open xDb_Conn_Str Select Case sAction Case "C": ' Get a record to display If Not LoadData() Then ' Load Record based on key Session(ewSessionMessage) = "No records found" conn.Close ' Close Connection Set conn = Nothing Response.Clear Response.Redirect "chapterlist.asp" End If Case "A": ' Add If AddData() Then ' Add New Record Session(ewSessionMessage) = "Add New Record Successful" conn.Close ' Close Connection Set conn = Nothing Response.Clear Response.Redirect "chapterlist.asp" Else End If End Select %>
Add to TABLE: chapter
Back to List
<%= Session(ewSessionMessage) %>
<% Session(ewSessionMessage) = "" ' Clear message End If %> <% conn.Close ' Close Connection Set conn = Nothing %> <% '------------------------------------------------------------------------------- ' Function RequestBlobData ' - Handle mult-part data (for file upload) ' - Variables setup: sAction, field variables, EW_Max_File_Size Function RequestBlobData() Dim rawData, separator, lenSeparator, dict Dim currentPos, inStrByte, tempValue, mValue, value Dim intDict, begPos, endPos Dim nameN, isValid, nameValue, midValue Dim rawStream If Request.TotalBytes > 0 Then Set rawStream = Server.CreateObject("ADODB.Stream") rawStream.Type = 1 'adTypeBinary rawStream.Mode = 3 'adModeReadWrite rawStream.Open rawStream.Write Request.BinaryRead(Request.TotalBytes) rawStream.Position = 0 rawData = rawStream.Read separator = MidB(rawData, 1, InStrB(1, rawData, ChrB(13)) - 1) lenSeparator = LenB(separator) Set dict = Server.CreateObject("Scripting.Dictionary") currentPos = 1 inStrByte = 1 tempValue = "" While inStrByte > 0 inStrByte = InStrB(currentPos, rawData, separator) mValue = inStrByte - currentPos If mValue > 1 Then value = MidB(rawData, currentPos, mValue) Set intDict = Server.CreateObject("Scripting.Dictionary") begPos = 1 + InStrB(1, value, ChrB(34)) endPos = InStrB(begPos + 1, value, ChrB(34)) nameN = MidB(value, begPos, endPos - begPos) isValid = True If InStrB(1, value, stringToByte("Content-Type")) > 1 Then begPos = 1 + InStrB(endPos + 1, value, ChrB(34)) endPos = InStrB(begPos + 1, value, ChrB(34)) If endPos > 0 Then intDict.Add "FileName", ConvertToText(rawStream, currentPos + begPos - 2, endPos - begPos, MidB(value, begPos, endPos - begPos)) begPos = 14 + InStrB(endPos + 1, value, StringToByte("Content-Type:")) endPos = InStrB(begPos, value, ChrB(13)) intDict.Add "ContentType", ConvertToText(rawStream, currentPos + begPos - 2, endPos - begPos, MidB(value, begPos, endPos - begPos)) begPos = endPos + 4 endPos = LenB(value) nameValue = MidB(value, begPos, ((endPos - begPos) - 1)) Else endPos = begPos + 1 isValid = False End If Else nameValue = ConvertToText(rawStream, currentPos + endPos + 3, mValue - endPos - 4, MidB(value, endPos + 5)) End If If isValid = True Then If dict.Exists(byteToString(nameN)) Then Set intDict = dict.Item(byteToString(nameN)) If Right(intDict.Item("Value"), 2) = vbCrLf Then intDict.Item("Value") = Left(intDict.Item("Value"), Len(intDict.Item("Value"))-2) End If intDict.Item("Value") = intDict.Item("Value") & ", " & nameValue Else intDict.Add "Value", nameValue intDict.Add "Name", nameN dict.Add byteToString(nameN), intDict End If End If End If currentPos = lenSeparator + inStrByte Wend rawStream.Close Set rawStream = Nothing ' Get action sAction = getValue(dict, "a_add") EW_Max_File_Size = getValue(dict, "EW_Max_File_Size") x_chapter_pkey = getValue(dict, "x_chapter_pkey") x_chapter_FFAid = getValue(dict, "x_chapter_FFAid") x_chapter_schoolname = getValue(dict, "x_chapter_schoolname") x_chapter_schooladdress1 = getValue(dict, "x_chapter_schooladdress1") x_chapter_schooladdress2 = getValue(dict, "x_chapter_schooladdress2") x_chapter_schooladdress3 = getValue(dict, "x_chapter_schooladdress3") x_chapter_schoolcity = getValue(dict, "x_chapter_schoolcity") x_chapter_schoolstate = getValue(dict, "x_chapter_schoolstate") x_chapter_schoolzipcode = getValue(dict, "x_chapter_schoolzipcode") x_chapter_schoolzipcode4 = getValue(dict, "x_chapter_schoolzipcode4") x_chapter_schooladvisor = getValue(dict, "x_chapter_schooladvisor") x_chapter_region = getValue(dict, "x_chapter_region") x_chapter_website = getValue(dict, "x_chapter_website") x_chapter_email = getValue(dict, "x_chapter_email") fs_x_chapter_picture = getFileSize(dict, "x_chapter_picture") ' Check the file size If fs_x_chapter_picture > 0 And CLng(EW_Max_File_Size) > 0 Then If fs_x_chapter_picture > CLng(EW_Max_File_Size) Then Response.Write Replace("Max. file size (%s bytes) exceeded.", "%s", EW_Max_File_Size) Response.End End If End If fn_x_chapter_picture = getFileName(dict, "x_chapter_picture") ' Check the file type If Not ewUploadAllowedFileExt(fn_x_chapter_picture) Then Response.Write "File type is not allowed." Response.End End If ct_x_chapter_picture = getFileContentType(dict, "x_chapter_picture") x_chapter_picture = getFileData(dict, "x_chapter_picture") Call ewGetImageDimension(x_chapter_picture, wd_x_chapter_picture, ht_x_chapter_picture) If wd_x_chapter_picture < 0 Or ht_x_chapter_picture < 0 Then wd_x_chapter_picture = getValue(dict, "wd_x_chapter_picture") ht_x_chapter_picture = getValue(dict, "ht_x_chapter_picture") End If a_x_chapter_picture = getValue(dict, "a_x_chapter_picture") fs_x_chapter_picturename = getFileSize(dict, "x_chapter_picturename") ' Check the file size If fs_x_chapter_picturename > 0 And CLng(EW_Max_File_Size) > 0 Then If fs_x_chapter_picturename > CLng(EW_Max_File_Size) Then Response.Write Replace("Max. file size (%s bytes) exceeded.", "%s", EW_Max_File_Size) Response.End End If End If fn_x_chapter_picturename = getFileName(dict, "x_chapter_picturename") ' Check the file type If Not ewUploadAllowedFileExt(fn_x_chapter_picturename) Then Response.Write "File type is not allowed." Response.End End If ct_x_chapter_picturename = getFileContentType(dict, "x_chapter_picturename") x_chapter_picturename = getFileData(dict, "x_chapter_picturename") Call ewGetImageDimension(x_chapter_picturename, wd_x_chapter_picturename, ht_x_chapter_picturename) If wd_x_chapter_picturename < 0 Or ht_x_chapter_picturename < 0 Then wd_x_chapter_picturename = getValue(dict, "wd_x_chapter_picturename") ht_x_chapter_picturename = getValue(dict, "ht_x_chapter_picturename") End If a_x_chapter_picturename = getValue(dict, "a_x_chapter_picturename") x_chapter_picturetype = getValue(dict, "x_chapter_picturetype") x_chapter_theme = getValue(dict, "x_chapter_theme") x_chapter_bio = getValue(dict, "x_chapter_bio") x_chapter_links = getValue(dict, "x_chapter_links") x_chapter_officers = getValue(dict, "x_chapter_officers") x_chapter_advisors = getValue(dict, "x_chapter_advisors") x_chapter_courses = getValue(dict, "x_chapter_courses") x_chapter_news = getValue(dict, "x_chapter_news") x_chapter_events = getValue(dict, "x_chapter_events") x_memberid = getValue(dict, "x_memberid") If IsObject(intDict) Then intDict.RemoveAll Set intDict = Nothing End If dict.RemoveAll Set dict = Nothing RequestBlobData = True Else RequestBlobData = False End If End Function %> <% '------------------------------------------------------------------------------- ' Function LoadData ' - Load Data based on Key Value ' - Variables setup: field variables Function LoadData() Dim rs, sSql, sFilter sFilter = ewSqlKeyWhere If Not IsNumeric(x_chapter_pkey) Then LoadData = False Exit Function End If sFilter = Replace(sFilter, "@chapter_pkey", AdjustSql(x_chapter_pkey)) ' Replace key value If CurrentUserID <> "-1" And CurrentUserID <> "" Then ' Non system admin '*** sFilter = sFilter & " AND " & Replace(ewSqlUserIDFilter, "#UserID", AdjustSql(CurrentUserID)) sFilter = sFilter & " AND " & ewSqlUserIDFilter sFilter = Replace(sFilter, "#Key", "[memberid]") sFilter = Replace(sFilter, "#UserID", AdjustSql(CurrentUserID)) End If sSql = ewBuildSql(ewSqlSelect, ewSqlWhere, ewSqlGroupBy, ewSqlHaving, ewSqlOrderBy, sFilter, "") Set rs = Server.CreateObject("ADODB.Recordset") rs.Open sSql, conn If rs.Eof Then LoadData = False Else LoadData = True rs.MoveFirst ' Get the field contents x_chapter_pkey = rs("chapter_pkey") x_chapter_FFAid = rs("chapter_FFAid") x_chapter_schoolname = rs("chapter_schoolname") x_chapter_schooladdress1 = rs("chapter_schooladdress1") x_chapter_schooladdress2 = rs("chapter_schooladdress2") x_chapter_schooladdress3 = rs("chapter_schooladdress3") x_chapter_schoolcity = rs("chapter_schoolcity") x_chapter_schoolstate = rs("chapter_schoolstate") x_chapter_schoolzipcode = rs("chapter_schoolzipcode") x_chapter_schoolzipcode4 = rs("chapter_schoolzipcode4") x_chapter_schooladvisor = rs("chapter_schooladvisor") x_chapter_region = rs("chapter_region") x_chapter_website = rs("chapter_website") x_chapter_email = rs("chapter_email") x_chapter_picture = rs("chapter_picture") x_chapter_picturename = rs("chapter_picturename") x_chapter_picturetype = rs("chapter_picturetype") x_chapter_theme = rs("chapter_theme") x_chapter_bio = rs("chapter_bio") x_chapter_links = rs("chapter_links") x_chapter_officers = rs("chapter_officers") x_chapter_advisors = rs("chapter_advisors") x_chapter_courses = rs("chapter_courses") x_chapter_news = rs("chapter_news") x_chapter_events = rs("chapter_events") x_memberid = rs("memberid") End If rs.Close Set rs = Nothing End Function %> <% '------------------------------------------------------------------------------- ' Function AddData ' - Add Data ' - Variables used: field variables Function AddData() On Error Resume Next Dim rs, sSql, sFilter Dim rsnew Dim bCheckKey, sSqlChk, sWhereChk sFilter = ewSqlKeyWhere ' Check for duplicate key bCheckKey = True If x_chapter_pkey = "" Or IsNull(x_chapter_pkey) Then bCheckKey = False Else sFilter = Replace(sFilter, "@chapter_pkey", AdjustSql(x_chapter_pkey)) ' Replace key value End If If Not IsNumeric(x_chapter_pkey) Then bCheckKey = False End If If bCheckKey Then sSqlChk = ewBuildSql(ewSqlSelect, ewSqlWhere, ewSqlGroupBy, ewSqlHaving, ewSqlOrderBy, sFilter, "") Set rsChk = conn.Execute(sSqlChk) If Err.Number <> 0 Then Session(ewSessionMessage) = Err.Description rsChk.Close Set rsChk = Nothing AddData = False Exit Function ElseIf Not rsChk.Eof Then Session(ewSessionMessage) = "Duplicate value for primary key" rsChk.Close Set rsChk = Nothing AddData = False Exit Function End If rsChk.Close Set rsChk = Nothing End If ' Add New Record sFilter = "(0 = 1)" sSql = ewBuildSql(ewSqlSelect, ewSqlWhere, ewSqlGroupBy, ewSqlHaving, ewSqlOrderBy, sFilter, "") Set rs = Server.CreateObject("ADODB.Recordset") rs.CursorLocation = 2 rs.Open sSql, conn, 1, 2 If Err.Number <> 0 Then Session(ewSessionMessage) = Err.Description rs.Close Set rs = Nothing AddData = False Exit Function End If rs.AddNew ' Field chapter_FFAid sTmp = Trim(x_chapter_FFAid) If Trim(sTmp) = "" Then sTmp = Null rs("chapter_FFAid") = sTmp ' Field chapter_schoolname sTmp = Trim(x_chapter_schoolname) If Trim(sTmp) = "" Then sTmp = Null rs("chapter_schoolname") = sTmp ' Field chapter_schooladdress1 sTmp = Trim(x_chapter_schooladdress1) If Trim(sTmp) = "" Then sTmp = Null rs("chapter_schooladdress1") = sTmp ' Field chapter_schooladdress2 sTmp = Trim(x_chapter_schooladdress2) If Trim(sTmp) = "" Then sTmp = Null rs("chapter_schooladdress2") = sTmp ' Field chapter_schooladdress3 sTmp = Trim(x_chapter_schooladdress3) If Trim(sTmp) = "" Then sTmp = Null rs("chapter_schooladdress3") = sTmp ' Field chapter_schoolcity sTmp = Trim(x_chapter_schoolcity) If Trim(sTmp) = "" Then sTmp = Null rs("chapter_schoolcity") = sTmp ' Field chapter_schoolstate sTmp = Trim(x_chapter_schoolstate) If Trim(sTmp) = "" Then sTmp = Null rs("chapter_schoolstate") = sTmp ' Field chapter_schoolzipcode sTmp = Trim(x_chapter_schoolzipcode) If Trim(sTmp) = "" Then sTmp = Null rs("chapter_schoolzipcode") = sTmp ' Field chapter_schooladvisor sTmp = Trim(x_chapter_schooladvisor) If Trim(sTmp) = "" Then sTmp = Null rs("chapter_schooladvisor") = sTmp ' Field chapter_region sTmp = x_chapter_region If Not IsNumeric(sTmp) Then sTmp = Null Else sTmp = CLng(sTmp) End If rs("chapter_region") = sTmp ' Field chapter_website sTmp = Trim(x_chapter_website) If Trim(sTmp) = "" Then sTmp = Null rs("chapter_website") = sTmp ' Field chapter_email sTmp = Trim(x_chapter_email) If Trim(sTmp) = "" Then sTmp = Null rs("chapter_email") = sTmp ' Field chapter_picture sTmp = x_chapter_picture If Trim(sTmp) = "" Then sTmp = Null If IsNull(sTmp) Then rs("chapter_picture") = Null Else rs("chapter_picture").AppendChunk sTmp End If ' Field chapter_theme sTmp = x_chapter_theme If Not IsNumeric(sTmp) Then sTmp = Null Else sTmp = CLng(sTmp) End If rs("chapter_theme") = sTmp ' Field chapter_bio sTmp = Trim(x_chapter_bio) If Trim(sTmp) = "" Then sTmp = Null rs("chapter_bio") = sTmp ' Field chapter_links sTmp = Trim(x_chapter_links) If Trim(sTmp) = "" Then sTmp = Null rs("chapter_links") = sTmp ' Field chapter_officers sTmp = Trim(x_chapter_officers) If Trim(sTmp) = "" Then sTmp = Null rs("chapter_officers") = sTmp ' Field chapter_advisors sTmp = Trim(x_chapter_advisors) If Trim(sTmp) = "" Then sTmp = Null rs("chapter_advisors") = sTmp ' Field chapter_courses sTmp = Trim(x_chapter_courses) If Trim(sTmp) = "" Then sTmp = Null rs("chapter_courses") = sTmp ' Field chapter_news sTmp = Trim(x_chapter_news) If Trim(sTmp) = "" Then sTmp = Null rs("chapter_news") = sTmp ' Field chapter_events sTmp = Trim(x_chapter_events) If Trim(sTmp) = "" Then sTmp = Null rs("chapter_events") = sTmp ' Field memberid sTmp = x_memberid If Not IsNumeric(sTmp) Then sTmp = Null Else sTmp = CLng(sTmp) End If rs("memberid") = sTmp ' Call recordset inserting event If Recordset_Inserting(rs) Then ' Clone new rs object Set rsnew = CloneRs(rs) rs.Update If Err.Number <> 0 Then Session(ewSessionMessage) = Err.Description AddData = False Else AddData = True End If Else rs.CancelUpdate AddData = False End If rs.Close Set rs = Nothing ' Call recordset inserted event If AddData Then Call Recordset_Inserted(rsnew) End If rsnew.Close Set rsnew = Nothing End Function '------------------------------------------------------------------------------- ' Recordset inserting event Function Recordset_Inserting(rsnew) On Error Resume Next ' Please enter your customized codes here Recordset_Inserting = True End Function '------------------------------------------------------------------------------- ' Recordset inserted event Sub Recordset_Inserted(rsnew) On Error Resume Next Dim table table = "chapter" ' Get key value Dim sKey sKey = "" If sKey <> "" Then sKey = sKey & "," sKey = sKey & rsnew.Fields("chapter_pkey") x_chapter_pkey = rsnew.Fields("chapter_pkey") End Sub %>