% 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("nilecruises") Else ewCurSec = GetAnonymousPriv("nilecruises") End If If (ewCurSec And ewAllowAdd) <> ewAllowAdd Then Response.Redirect "nilecruiseslist.asp" %> <% ' Initialize common variables x_NileCruiseID = Null: ox_NileCruiseID = Null: z_NileCruiseID = Null x_NileCruiseLogo = Null: ox_NileCruiseLogo = Null: z_NileCruiseLogo = Null fs_x_NileCruiseLogo = 0: fn_x_NileCruiseLogo = "": ct_x_NileCruiseLogo = "" wd_x_NileCruiseLogo = 0: ht_x_NileCruiseLogo = 0: a_x_NileCruiseLogo = "" x_NileCruiseName = Null: ox_NileCruiseName = Null: z_NileCruiseName = Null x_Photo1 = Null: ox_Photo1 = Null: z_Photo1 = Null fs_x_Photo1 = 0: fn_x_Photo1 = "": ct_x_Photo1 = "" wd_x_Photo1 = 0: ht_x_Photo1 = 0: a_x_Photo1 = "" x_CruiseCategory = Null: ox_CruiseCategory = Null: z_CruiseCategory = Null x_CruiseItinerary = Null: ox_CruiseItinerary = Null: z_CruiseItinerary = Null x_CruiseDescription = Null: ox_CruiseDescription = Null: z_CruiseDescription = Null x_Photo2 = Null: ox_Photo2 = Null: z_Photo2 = Null fs_x_Photo2 = 0: fn_x_Photo2 = "": ct_x_Photo2 = "" wd_x_Photo2 = 0: ht_x_Photo2 = 0: a_x_Photo2 = "" x_Photo3 = Null: ox_Photo3 = Null: z_Photo3 = Null fs_x_Photo3 = 0: fn_x_Photo3 = "": ct_x_Photo3 = "" wd_x_Photo3 = 0: ht_x_Photo3 = 0: a_x_Photo3 = "" x_Photo4 = Null: ox_Photo4 = Null: z_Photo4 = Null fs_x_Photo4 = 0: fn_x_Photo4 = "": ct_x_Photo4 = "" wd_x_Photo4 = 0: ht_x_Photo4 = 0: a_x_Photo4 = "" x_Photo5 = Null: ox_Photo5 = Null: z_Photo5 = Null fs_x_Photo5 = 0: fn_x_Photo5 = "": ct_x_Photo5 = "" wd_x_Photo5 = 0: ht_x_Photo5 = 0: a_x_Photo5 = "" x_Cabinfacilities = Null: ox_Cabinfacilities = Null: z_Cabinfacilities = Null x_Cruisefacilities = Null: ox_Cruisefacilities = Null: z_Cruisefacilities = Null %> <% Response.Buffer = True ' Load key from QueryString bCopy = True x_NileCruiseID = Request.QueryString("NileCruiseID") If x_NileCruiseID = "" Or IsNull(x_NileCruiseID) 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 "nilecruiseslist.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 "nilecruiseslist.asp" Else End If End Select %>
Add to TABLE: nilecruises
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_NileCruiseID = getValue(dict, "x_NileCruiseID") fs_x_NileCruiseLogo = getFileSize(dict, "x_NileCruiseLogo") ' Check the file size If fs_x_NileCruiseLogo > 0 And CLng(EW_Max_File_Size) > 0 Then If fs_x_NileCruiseLogo > 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_NileCruiseLogo = getFileName(dict, "x_NileCruiseLogo") ' Check the file type If Not ewUploadAllowedFileExt(fn_x_NileCruiseLogo) Then Response.Write "File type is not allowed." Response.End End If ct_x_NileCruiseLogo = getFileContentType(dict, "x_NileCruiseLogo") x_NileCruiseLogo = getFileData(dict, "x_NileCruiseLogo") Call ewGetImageDimension(x_NileCruiseLogo, wd_x_NileCruiseLogo, ht_x_NileCruiseLogo) If wd_x_NileCruiseLogo < 0 Or ht_x_NileCruiseLogo < 0 Then wd_x_NileCruiseLogo = getValue(dict, "wd_x_NileCruiseLogo") ht_x_NileCruiseLogo = getValue(dict, "ht_x_NileCruiseLogo") End If a_x_NileCruiseLogo = getValue(dict, "a_x_NileCruiseLogo") x_NileCruiseName = getValue(dict, "x_NileCruiseName") fs_x_Photo1 = getFileSize(dict, "x_Photo1") ' Check the file size If fs_x_Photo1 > 0 And CLng(EW_Max_File_Size) > 0 Then If fs_x_Photo1 > 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_Photo1 = getFileName(dict, "x_Photo1") ' Check the file type If Not ewUploadAllowedFileExt(fn_x_Photo1) Then Response.Write "File type is not allowed." Response.End End If ct_x_Photo1 = getFileContentType(dict, "x_Photo1") x_Photo1 = getFileData(dict, "x_Photo1") Call ewGetImageDimension(x_Photo1, wd_x_Photo1, ht_x_Photo1) If wd_x_Photo1 < 0 Or ht_x_Photo1 < 0 Then wd_x_Photo1 = getValue(dict, "wd_x_Photo1") ht_x_Photo1 = getValue(dict, "ht_x_Photo1") End If a_x_Photo1 = getValue(dict, "a_x_Photo1") x_CruiseCategory = getValue(dict, "x_CruiseCategory") x_CruiseItinerary = getValue(dict, "x_CruiseItinerary") x_CruiseDescription = getValue(dict, "x_CruiseDescription") fs_x_Photo2 = getFileSize(dict, "x_Photo2") ' Check the file size If fs_x_Photo2 > 0 And CLng(EW_Max_File_Size) > 0 Then If fs_x_Photo2 > 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_Photo2 = getFileName(dict, "x_Photo2") ' Check the file type If Not ewUploadAllowedFileExt(fn_x_Photo2) Then Response.Write "File type is not allowed." Response.End End If ct_x_Photo2 = getFileContentType(dict, "x_Photo2") x_Photo2 = getFileData(dict, "x_Photo2") Call ewGetImageDimension(x_Photo2, wd_x_Photo2, ht_x_Photo2) If wd_x_Photo2 < 0 Or ht_x_Photo2 < 0 Then wd_x_Photo2 = getValue(dict, "wd_x_Photo2") ht_x_Photo2 = getValue(dict, "ht_x_Photo2") End If a_x_Photo2 = getValue(dict, "a_x_Photo2") fs_x_Photo3 = getFileSize(dict, "x_Photo3") ' Check the file size If fs_x_Photo3 > 0 And CLng(EW_Max_File_Size) > 0 Then If fs_x_Photo3 > 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_Photo3 = getFileName(dict, "x_Photo3") ' Check the file type If Not ewUploadAllowedFileExt(fn_x_Photo3) Then Response.Write "File type is not allowed." Response.End End If ct_x_Photo3 = getFileContentType(dict, "x_Photo3") x_Photo3 = getFileData(dict, "x_Photo3") Call ewGetImageDimension(x_Photo3, wd_x_Photo3, ht_x_Photo3) If wd_x_Photo3 < 0 Or ht_x_Photo3 < 0 Then wd_x_Photo3 = getValue(dict, "wd_x_Photo3") ht_x_Photo3 = getValue(dict, "ht_x_Photo3") End If a_x_Photo3 = getValue(dict, "a_x_Photo3") fs_x_Photo4 = getFileSize(dict, "x_Photo4") ' Check the file size If fs_x_Photo4 > 0 And CLng(EW_Max_File_Size) > 0 Then If fs_x_Photo4 > 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_Photo4 = getFileName(dict, "x_Photo4") ' Check the file type If Not ewUploadAllowedFileExt(fn_x_Photo4) Then Response.Write "File type is not allowed." Response.End End If ct_x_Photo4 = getFileContentType(dict, "x_Photo4") x_Photo4 = getFileData(dict, "x_Photo4") Call ewGetImageDimension(x_Photo4, wd_x_Photo4, ht_x_Photo4) If wd_x_Photo4 < 0 Or ht_x_Photo4 < 0 Then wd_x_Photo4 = getValue(dict, "wd_x_Photo4") ht_x_Photo4 = getValue(dict, "ht_x_Photo4") End If a_x_Photo4 = getValue(dict, "a_x_Photo4") fs_x_Photo5 = getFileSize(dict, "x_Photo5") ' Check the file size If fs_x_Photo5 > 0 And CLng(EW_Max_File_Size) > 0 Then If fs_x_Photo5 > 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_Photo5 = getFileName(dict, "x_Photo5") ' Check the file type If Not ewUploadAllowedFileExt(fn_x_Photo5) Then Response.Write "File type is not allowed." Response.End End If ct_x_Photo5 = getFileContentType(dict, "x_Photo5") x_Photo5 = getFileData(dict, "x_Photo5") Call ewGetImageDimension(x_Photo5, wd_x_Photo5, ht_x_Photo5) If wd_x_Photo5 < 0 Or ht_x_Photo5 < 0 Then wd_x_Photo5 = getValue(dict, "wd_x_Photo5") ht_x_Photo5 = getValue(dict, "ht_x_Photo5") End If a_x_Photo5 = getValue(dict, "a_x_Photo5") x_Cabinfacilities = getValue(dict, "x_Cabinfacilities") x_Cruisefacilities = getValue(dict, "x_Cruisefacilities") 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_NileCruiseID) Then LoadData = False Exit Function End If sFilter = Replace(sFilter, "@NileCruiseID", AdjustSql(x_NileCruiseID)) ' Replace key value 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_NileCruiseID = rs("NileCruiseID") x_NileCruiseLogo = rs("NileCruiseLogo") x_NileCruiseName = rs("NileCruiseName") x_Photo1 = rs("Photo1") x_CruiseCategory = rs("CruiseCategory") x_CruiseItinerary = rs("CruiseItinerary") x_CruiseDescription = rs("CruiseDescription") x_Photo2 = rs("Photo2") x_Photo3 = rs("Photo3") x_Photo4 = rs("Photo4") x_Photo5 = rs("Photo5") x_Cabinfacilities = rs("Cabinfacilities") x_Cruisefacilities = rs("Cruisefacilities") 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_NileCruiseID = "" Or IsNull(x_NileCruiseID) Then bCheckKey = False Else sFilter = Replace(sFilter, "@NileCruiseID", AdjustSql(x_NileCruiseID)) ' Replace key value End If If Not IsNumeric(x_NileCruiseID) 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 = 3 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 NileCruiseLogo sTmp = x_NileCruiseLogo If Trim(sTmp) = "" Then sTmp = Null If IsNull(sTmp) Then rs("NileCruiseLogo") = Null Else rs("NileCruiseLogo").AppendChunk sTmp End If ' Field NileCruiseName sTmp = Trim(x_NileCruiseName) If Trim(sTmp) = "" Then sTmp = "" rs("NileCruiseName") = sTmp ' Field Photo1 sTmp = x_Photo1 If Trim(sTmp) = "" Then sTmp = Null If IsNull(sTmp) Then rs("Photo1") = Null Else rs("Photo1").AppendChunk sTmp End If ' Field CruiseCategory sTmp = Trim(x_CruiseCategory) If Trim(sTmp) = "" Then sTmp = Null rs("CruiseCategory") = sTmp ' Field CruiseItinerary sTmp = Trim(x_CruiseItinerary) If Trim(sTmp) = "" Then sTmp = Null rs("CruiseItinerary") = sTmp ' Field CruiseDescription sTmp = Trim(x_CruiseDescription) If Trim(sTmp) = "" Then sTmp = Null rs("CruiseDescription") = sTmp ' Field Photo2 sTmp = x_Photo2 If Trim(sTmp) = "" Then sTmp = Null If IsNull(sTmp) Then rs("Photo2") = Null Else rs("Photo2").AppendChunk sTmp End If ' Field Photo3 sTmp = x_Photo3 If Trim(sTmp) = "" Then sTmp = Null If IsNull(sTmp) Then rs("Photo3") = Null Else rs("Photo3").AppendChunk sTmp End If ' Field Photo4 sTmp = x_Photo4 If Trim(sTmp) = "" Then sTmp = Null If IsNull(sTmp) Then rs("Photo4") = Null Else rs("Photo4").AppendChunk sTmp End If ' Field Photo5 sTmp = x_Photo5 If Trim(sTmp) = "" Then sTmp = Null If IsNull(sTmp) Then rs("Photo5") = Null Else rs("Photo5").AppendChunk sTmp End If ' Field Cabinfacilities sTmp = Trim(x_Cabinfacilities) If Trim(sTmp) = "" Then sTmp = Null rs("Cabinfacilities") = sTmp ' Field Cruisefacilities sTmp = Trim(x_Cruisefacilities) If Trim(sTmp) = "" Then sTmp = Null rs("Cruisefacilities") = 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 = "nilecruises" ' Get key value Dim sKey sKey = "" If sKey <> "" Then sKey = sKey & "," sKey = sKey & rsnew.Fields("NileCruiseID") x_NileCruiseID = rsnew.Fields("NileCruiseID") End Sub %>