<%@ CodePage=65001 %> <% Const EW_PAGE_ID = "add" Const EW_TABLE_NAME = "Rotator_Photos" %> <% Session.Timeout = 100 %> <% Response.Expires = 0 Response.ExpiresAbsolute = Now() - 1 Response.AddHeader "pragma", "no-cache" Response.AddHeader "cache-control", "private, no-cache, no-store, must-revalidate" %> <% ' Open connection to the database Dim conn Set conn = Server.CreateObject("ADODB.Connection") conn.Open EW_DB_CONNECTION_STRING %> <% Dim Security Set Security = New cAdvancedSecurity %> <% If Not Security.IsLoggedIn() Then Call Security.AutoLogin() If Not Security.IsLoggedIn() Then Call Security.SaveLastUrl() Call Page_Terminate("login.asp") End If %> <% ' Common page loading event (in userfn60.asp) Call Page_Loading() %> <% ' Page load event, used in current page Call Page_Load() %> <% Response.Buffer = True ' Load key values from QueryString Dim bCopy bCopy = True If Request.QueryString("ID").Count > 0 Then Rotator_Photos.ID.QueryStringValue = Request.QueryString("ID") Else bCopy = False End If ' Create form object Dim objForm Set objForm = ew_GetUploadObj() ' Process form if post back If objForm.GetValue("a_add")&"" <> "" Then Rotator_Photos.CurrentAction = objForm.GetValue("a_add") ' Get form action Call GetUploadFiles() ' Get upload files Call LoadFormValues() ' Load form values ' Not post back Else If bCopy Then Rotator_Photos.CurrentAction = "C" ' Copy Record Else Rotator_Photos.CurrentAction = "I" ' Display Blank Record Call LoadDefaultValues() ' Load default values End If End If ' Close form object Set objForm = Nothing ' Perform action based on action code Select Case Rotator_Photos.CurrentAction Case "I" ' Blank record, no action required Case "C" ' Copy an existing record If Not LoadRow() Then ' Load record based on key Session(EW_SESSION_MESSAGE) = "No records found" ' No record found Call Page_Terminate(Rotator_Photos.ReturnUrl) ' Clean up and return End If Case "A" ' Add new record Rotator_Photos.SendEmail = True ' Send email on add success If AddRow() Then ' Add successful Session(EW_SESSION_MESSAGE) = "Add New Record Successful" ' Set up success message Call Page_Terminate(Rotator_Photos.KeyUrl(Rotator_Photos.ReturnUrl, "")) ' Clean up and return Else Call RestoreFormValues() ' Add failed, restore form values End If End Select ' Render row based on row type Rotator_Photos.RowType = EW_ROWTYPE_ADD ' add ' Render add type Call RenderRow() %>

Add to TABLE: Rotator Photos

Go Back

<% If Session(EW_SESSION_MESSAGE) <> "" Then ' Mesasge in Session, display %>

<%= Session(EW_SESSION_MESSAGE) %>

<% Session(EW_SESSION_MESSAGE) = "" ' Clear message in Session End If %>

> > > > > > > ">
Photo Name
Photo
Type
hyperlink

<% ' If control is passed here, simply terminate the page without redirect Call Page_Terminate("") ' ----------------------------------------------------------------- ' Subroutine Page_Terminate ' - called when exit page ' - clean up ADO connection and objects ' - if url specified, redirect to url, otherwise end response ' Sub Page_Terminate(url) ' Page unload event, used in current page Call Page_Unload() ' Global page unloaded event (in userfn60.asp) Call Page_Unloaded() conn.Close ' Close Connection Set conn = Nothing Set Security = Nothing Set Rotator_Photos = Nothing ' Go to url if specified If url <> "" Then Response.Clear Response.Redirect url End If ' Terminate response Response.End End Sub ' ' Subroutine Page_Terminate (End) ' ---------------------------------------- %> <% ' Function Get upload files Function GetUploadFiles() ' Get upload data If Rotator_Photos.Photo.Upload.UploadFile() Then ' No action required Else Response.Write Rotator_Photos.Photo.Upload.Message Response.End End If End Function %> <% ' Load default values Function LoadDefaultValues() Rotator_Photos.CreatedDate.CurrentValue = Date() End Function %> <% ' Load form values Function LoadFormValues() ' Load from form Rotator_Photos.Photo_Name.FormValue = objForm.GetValue("x_Photo_Name") Rotator_Photos.zType.FormValue = objForm.GetValue("x_zType") Rotator_Photos.hyperlink.FormValue = objForm.GetValue("x_hyperlink") Rotator_Photos.CreatedDate.FormValue = objForm.GetValue("x_CreatedDate") Rotator_Photos.CreatedDate.CurrentValue = ew_UnFormatDateTime(Rotator_Photos.CreatedDate.CurrentValue, 7) End Function ' Restore form values Function RestoreFormValues() Rotator_Photos.Photo_Name.CurrentValue = Rotator_Photos.Photo_Name.FormValue Rotator_Photos.zType.CurrentValue = Rotator_Photos.zType.FormValue Rotator_Photos.hyperlink.CurrentValue = Rotator_Photos.hyperlink.FormValue Rotator_Photos.CreatedDate.CurrentValue = Rotator_Photos.CreatedDate.FormValue Rotator_Photos.CreatedDate.CurrentValue = ew_UnFormatDateTime(Rotator_Photos.CreatedDate.CurrentValue, 7) End Function %> <% ' Load row based on key values Function LoadRow() Dim rs, sSql, sFilter sFilter = Rotator_Photos.SqlKeyFilter If Not IsNumeric(Rotator_Photos.ID.CurrentValue) Then LoadRow = False ' Invalid key, exit Exit Function End If sFilter = Replace(sFilter, "@ID@", ew_AdjustSql(Rotator_Photos.ID.CurrentValue)) ' Replace key value ' Call Row Selecting event Call Rotator_Photos.Row_Selecting(sFilter) ' Load sql based on filter Rotator_Photos.CurrentFilter = sFilter sSql = Rotator_Photos.SQL Set rs = Server.CreateObject("ADODB.Recordset") rs.Open sSql, conn If rs.Eof Then LoadRow = False Else LoadRow = True rs.MoveFirst Call LoadRowValues(rs) ' Load row values ' Call Row Selected event Call Rotator_Photos.Row_Selected(rs) End If rs.Close Set rs = Nothing End Function ' Load row values from recordset Sub LoadRowValues(rs) Rotator_Photos.ID.DbValue = rs("ID") Rotator_Photos.Photo_Name.DbValue = rs("Photo_Name") Rotator_Photos.Photo.Upload.DbValue = rs("Photo") Rotator_Photos.zType.DbValue = rs("Type") Rotator_Photos.hyperlink.DbValue = rs("hyperlink") Rotator_Photos.CreatedDate.DbValue = rs("CreatedDate") End Sub %> <% ' Render row values based on field settings Sub RenderRow() ' Call Row Rendering event Call Rotator_Photos.Row_Rendering() ' Common render codes for all row types ' Photo_Name Rotator_Photos.Photo_Name.CellCssStyle = "" Rotator_Photos.Photo_Name.CellCssClass = "" ' Photo Rotator_Photos.Photo.CellCssStyle = "" Rotator_Photos.Photo.CellCssClass = "" ' Type Rotator_Photos.zType.CellCssStyle = "" Rotator_Photos.zType.CellCssClass = "" ' hyperlink Rotator_Photos.hyperlink.CellCssStyle = "" Rotator_Photos.hyperlink.CellCssClass = "" ' CreatedDate Rotator_Photos.CreatedDate.CellCssStyle = "" Rotator_Photos.CreatedDate.CellCssClass = "" If Rotator_Photos.RowType = EW_ROWTYPE_VIEW Then ' View row ElseIf Rotator_Photos.RowType = EW_ROWTYPE_ADD Then ' Add row ' Photo_Name Rotator_Photos.Photo_Name.EditCustomAttributes = "" Rotator_Photos.Photo_Name.EditValue = ew_HtmlEncode(Rotator_Photos.Photo_Name.CurrentValue) ' Photo Rotator_Photos.Photo.EditCustomAttributes = "" If Not IsNull(Rotator_Photos.Photo.Upload.DbValue) Then Rotator_Photos.Photo.EditValue = Rotator_Photos.Photo.Upload.DbValue Rotator_Photos.Photo.ImageAlt = "" Else Rotator_Photos.Photo.EditValue = "" End If ' Type Rotator_Photos.zType.EditCustomAttributes = "" Redim arwrk(1, 1) arwrk(0, 0) = "Slides" arwrk(1, 0) = "Slides" arwrk(0, 1) = "Movers" arwrk(1, 1) = "Movers" arwrk = ew_AddItemToArray(arwrk, 0, Array("", "Please Select")) Rotator_Photos.zType.EditValue = arwrk ' hyperlink Rotator_Photos.hyperlink.EditCustomAttributes = "" Rotator_Photos.hyperlink.EditValue = ew_HtmlEncode(Rotator_Photos.hyperlink.CurrentValue) ' CreatedDate Rotator_Photos.CreatedDate.EditCustomAttributes = "" Rotator_Photos.CreatedDate.CurrentValue = ew_FormatDateTime(Date(), 7) ElseIf Rotator_Photos.RowType = EW_ROWTYPE_EDIT Then ' Edit row ElseIf Rotator_Photos.RowType = EW_ROWTYPE_SEARCH Then ' Search row End If ' Call Row Rendered event Call Rotator_Photos.Row_Rendered() End Sub %> <% ' Add record Function AddRow() On Error Resume Next Dim rs, sSql, sFilter Dim rsnew Dim bCheckKey, sSqlChk, sWhereChk, rsChk Dim bInsertRow ' Check for duplicate key bCheckKey = True sFilter = Rotator_Photos.SqlKeyFilter If Rotator_Photos.ID.CurrentValue = "" Or IsNull(Rotator_Photos.ID.CurrentValue) Then bCheckKey = False Else sFilter = Replace(sFilter, "@ID@", ew_AdjustSql(Rotator_Photos.ID.CurrentValue)) ' Replace key value End If If Not IsNumeric(Rotator_Photos.ID.CurrentValue) Then bCheckKey = False End If If bCheckKey Then Set rsChk = Rotator_Photos.LoadRs(sFilter) If Not (rsChk Is Nothing) Then Session(EW_SESSION_MESSAGE) = "Duplicate value for primary key" rsChk.Close Set rsChk = Nothing AddRow = False Exit Function End If End If ' Add new record sFilter = "(0 = 1)" Rotator_Photos.CurrentFilter = sFilter sSql = Rotator_Photos.SQL Set rs = Server.CreateObject("ADODB.Recordset") rs.CursorLocation = EW_CURSORLOCATION rs.Open sSql, conn, 1, 2 rs.AddNew If Err.Number <> 0 Then Session(EW_SESSION_MESSAGE) = Err.Description rs.Close Set rs = Nothing AddRow = False Exit Function End If ' Field Photo_Name Call Rotator_Photos.Photo_Name.SetDbValue(Rotator_Photos.Photo_Name.CurrentValue, Null) rs("Photo_Name") = Rotator_Photos.Photo_Name.DbValue ' Field Photo Call Rotator_Photos.Photo.Upload.SaveToSession() ' Save file value to Session Rotator_Photos.Photo.Upload.DbValue = rs("Photo") ' Get original value If IsNull(Rotator_Photos.Photo.Upload.Value) Then rs("Photo") = Null Else rs("Photo") = ew_UploadFileNameEx(ew_UploadPathEx(True, "RotatorImages/"), Rotator_Photos.Photo.Upload.FileName) End If ' Field Type Call Rotator_Photos.zType.SetDbValue(Rotator_Photos.zType.CurrentValue, Null) rs("Type") = Rotator_Photos.zType.DbValue ' Field hyperlink Call Rotator_Photos.hyperlink.SetDbValue(Rotator_Photos.hyperlink.CurrentValue, Null) rs("hyperlink") = Rotator_Photos.hyperlink.DbValue ' Field CreatedDate Call Rotator_Photos.CreatedDate.SetDbValue(ew_UnFormatDateTime(Rotator_Photos.CreatedDate.CurrentValue, 7), Null) rs("CreatedDate") = Rotator_Photos.CreatedDate.DbValue ' Check recordset update error If Err.Number <> 0 Then Session(EW_SESSION_MESSAGE) = Err.Description rs.Close Set rs = Nothing AddRow = False Exit Function End If ' Call Row Inserting event bInsertRow = Rotator_Photos.Row_Inserting(rs) If bInsertRow Then ' Field Photo If Not IsNull(Rotator_Photos.Photo.Upload.Value) Then Call ew_SaveFile(ew_UploadPathEx(True, "RotatorImages/"), rs("Photo"), Rotator_Photos.Photo.Upload.Value) If Rotator_Photos.Photo.Upload.Action = "2" Or Rotator_Photos.Photo.Upload.Action = "3" Then ' Update/Remove If Rotator_Photos.Photo.Upload.DbValue <> "" Then ew_DeleteFile ew_UploadPathEx(True, "RotatorImages/") & Rotator_Photos.Photo.Upload.DbValue End If ' Clone new rs object Set rsnew = ew_CloneRs(rs) rs.Update If Err.Number <> 0 Then Session(EW_SESSION_MESSAGE) = Err.Description AddRow = False Else AddRow = True End If Else rs.CancelUpdate If Rotator_Photos.CancelMessage <> "" Then Session(EW_SESSION_MESSAGE) = Rotator_Photos.CancelMessage Rotator_Photos.CancelMessage = "" Else Session(EW_SESSION_MESSAGE) = "Insert cancelled" End If AddRow = False End If rs.Close Set rs = Nothing If AddRow Then Rotator_Photos.ID.DbValue = rsnew("ID") ' Call Row Inserted event Call Rotator_Photos.Row_Inserted(rsnew) End If ' Field Photo Call Rotator_Photos.Photo.Upload.RemoveFromSession() ' Remove file value from Session If IsObject(rsnew) Then rsnew.Close Set rsnew = Nothing End If End Function %> <% ' Page Load event Sub Page_Load() '***Response.Write "Page Load" Server.ScriptTimeout=1000 End Sub ' Page Unload event Sub Page_Unload() '***Response.Write "Page Unload" End Sub %>