<%@ CodePage=65001 %> <% Const EW_PAGE_ID = "add" Const EW_TABLE_NAME = "Video_Gallery" %> <% 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 Video_Gallery.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 Video_Gallery.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 Video_Gallery.CurrentAction = "C" ' Copy Record Else Video_Gallery.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 Video_Gallery.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(Video_Gallery.ReturnUrl) ' Clean up and return End If Case "A" ' Add new record Video_Gallery.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(Video_Gallery.KeyUrl(Video_Gallery.ReturnUrl, "")) ' Clean up and return Else Call RestoreFormValues() ' Add failed, restore form values End If End Select ' Render row based on row type Video_Gallery.RowType = EW_ROWTYPE_ADD ' add ' Render add type Call RenderRow() %>

Add to TABLE: Video Gallery

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 %>

>  Add Video Category
Video Category
Category Name
Video Title > > Video Description > Video * > > Created Date > >

<% ' 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 Video_Gallery = 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 Video_Gallery.Video.Upload.UploadFile() Then ' No action required Else Response.Write Video_Gallery.Video.Upload.Message Response.End End If End Function %> <% ' Load default values Function LoadDefaultValues() Video_Gallery.CreatedDate.CurrentValue = Date() End Function %> <% ' Load form values Function LoadFormValues() ' Load from form Video_Gallery.Video_Category.FormValue = objForm.GetValue("x_Video_Category") Video_Gallery.Video_Title.FormValue = objForm.GetValue("x_Video_Title") Video_Gallery.Video_Description.FormValue = objForm.GetValue("x_Video_Description") Video_Gallery.CreatedDate.FormValue = objForm.GetValue("x_CreatedDate") Video_Gallery.CreatedDate.CurrentValue = ew_UnFormatDateTime(Video_Gallery.CreatedDate.CurrentValue, 7) End Function ' Restore form values Function RestoreFormValues() Video_Gallery.Video_Category.CurrentValue = Video_Gallery.Video_Category.FormValue Video_Gallery.Video_Title.CurrentValue = Video_Gallery.Video_Title.FormValue Video_Gallery.Video_Description.CurrentValue = Video_Gallery.Video_Description.FormValue Video_Gallery.CreatedDate.CurrentValue = Video_Gallery.CreatedDate.FormValue Video_Gallery.CreatedDate.CurrentValue = ew_UnFormatDateTime(Video_Gallery.CreatedDate.CurrentValue, 7) End Function %> <% ' Load row based on key values Function LoadRow() Dim rs, sSql, sFilter sFilter = Video_Gallery.SqlKeyFilter If Not IsNumeric(Video_Gallery.ID.CurrentValue) Then LoadRow = False ' Invalid key, exit Exit Function End If sFilter = Replace(sFilter, "@ID@", ew_AdjustSql(Video_Gallery.ID.CurrentValue)) ' Replace key value ' Call Row Selecting event Call Video_Gallery.Row_Selecting(sFilter) ' Load sql based on filter Video_Gallery.CurrentFilter = sFilter sSql = Video_Gallery.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 Video_Gallery.Row_Selected(rs) End If rs.Close Set rs = Nothing End Function ' Load row values from recordset Sub LoadRowValues(rs) Video_Gallery.ID.DbValue = rs("ID") Video_Gallery.Video_Category.DbValue = rs("Video_Category") Video_Gallery.Video_Title.DbValue = rs("Video_Title") Video_Gallery.Video_Description.DbValue = rs("Video_Description") Video_Gallery.Video.Upload.DbValue = rs("Video") Video_Gallery.CreatedDate.DbValue = rs("CreatedDate") End Sub %> <% ' Render row values based on field settings Sub RenderRow() ' Call Row Rendering event Call Video_Gallery.Row_Rendering() ' Common render codes for all row types ' Video_Category Video_Gallery.Video_Category.CellCssStyle = "" Video_Gallery.Video_Category.CellCssClass = "" ' Video_Title Video_Gallery.Video_Title.CellCssStyle = "" Video_Gallery.Video_Title.CellCssClass = "" ' Video_Description Video_Gallery.Video_Description.CellCssStyle = "" Video_Gallery.Video_Description.CellCssClass = "" ' Video Video_Gallery.Video.CellCssStyle = "" Video_Gallery.Video.CellCssClass = "" ' CreatedDate Video_Gallery.CreatedDate.CellCssStyle = "" Video_Gallery.CreatedDate.CellCssClass = "" If Video_Gallery.RowType = EW_ROWTYPE_VIEW Then ' View row ElseIf Video_Gallery.RowType = EW_ROWTYPE_ADD Then ' Add row ' Video_Category Video_Gallery.Video_Category.EditCustomAttributes = "" sSqlWrk = "SELECT [ID], [Category_Name] FROM [Gallery_Category]" sSqlWrk = sSqlWrk & " ORDER BY [Category_Name] Asc" Set rswrk = Server.CreateObject("ADODB.Recordset") rswrk.Open sSqlWrk, conn If Not rswrk.Eof Then arwrk = rswrk.GetRows Else arwrk = "" End If rswrk.Close Set rswrk = Nothing arwrk = ew_AddItemToArray(arwrk, 0, Array("", "Please Select")) Video_Gallery.Video_Category.EditValue = arwrk ' Video_Title Video_Gallery.Video_Title.EditCustomAttributes = "" Video_Gallery.Video_Title.EditValue = ew_HtmlEncode(Video_Gallery.Video_Title.CurrentValue) ' Video_Description Video_Gallery.Video_Description.EditCustomAttributes = "" Video_Gallery.Video_Description.EditValue = Video_Gallery.Video_Description.CurrentValue ' Video Video_Gallery.Video.EditCustomAttributes = "" If Not IsNull(Video_Gallery.Video.Upload.DbValue) Then Video_Gallery.Video.EditValue = Video_Gallery.Video.Upload.DbValue Else Video_Gallery.Video.EditValue = "" End If ' CreatedDate Video_Gallery.CreatedDate.EditCustomAttributes = "" Video_Gallery.CreatedDate.EditValue = ew_FormatDateTime(Video_Gallery.CreatedDate.CurrentValue, 7) ElseIf Video_Gallery.RowType = EW_ROWTYPE_EDIT Then ' Edit row ElseIf Video_Gallery.RowType = EW_ROWTYPE_SEARCH Then ' Search row End If ' Call Row Rendered event Call Video_Gallery.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 = Video_Gallery.SqlKeyFilter If Video_Gallery.ID.CurrentValue = "" Or IsNull(Video_Gallery.ID.CurrentValue) Then bCheckKey = False Else sFilter = Replace(sFilter, "@ID@", ew_AdjustSql(Video_Gallery.ID.CurrentValue)) ' Replace key value End If If Not IsNumeric(Video_Gallery.ID.CurrentValue) Then bCheckKey = False End If If bCheckKey Then Set rsChk = Video_Gallery.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)" Video_Gallery.CurrentFilter = sFilter sSql = Video_Gallery.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 Video_Category Call Video_Gallery.Video_Category.SetDbValue(Video_Gallery.Video_Category.CurrentValue, Null) rs("Video_Category") = Video_Gallery.Video_Category.DbValue ' Field Video_Title Call Video_Gallery.Video_Title.SetDbValue(Video_Gallery.Video_Title.CurrentValue, Null) rs("Video_Title") = Video_Gallery.Video_Title.DbValue ' Field Video_Description Call Video_Gallery.Video_Description.SetDbValue(Video_Gallery.Video_Description.CurrentValue, Null) rs("Video_Description") = Video_Gallery.Video_Description.DbValue ' Field Video Call Video_Gallery.Video.Upload.SaveToSession() ' Save file value to Session Video_Gallery.Video.Upload.DbValue = rs("Video") ' Get original value If IsNull(Video_Gallery.Video.Upload.Value) Then rs("Video") = Null Else rs("Video") = ew_UploadFileNameEx(ew_UploadPathEx(True, "pedro/videos/"), Video_Gallery.Video.Upload.FileName) End If ' Field CreatedDate Call Video_Gallery.CreatedDate.SetDbValue(ew_UnFormatDateTime(Video_Gallery.CreatedDate.CurrentValue, 7), Null) rs("CreatedDate") = Video_Gallery.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 = Video_Gallery.Row_Inserting(rs) If bInsertRow Then ' Field Video If Not IsNull(Video_Gallery.Video.Upload.Value) Then Call ew_SaveFile(ew_UploadPathEx(True, "pedro/videos/"), rs("Video"), Video_Gallery.Video.Upload.Value) ' 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 Video_Gallery.CancelMessage <> "" Then Session(EW_SESSION_MESSAGE) = Video_Gallery.CancelMessage Video_Gallery.CancelMessage = "" Else Session(EW_SESSION_MESSAGE) = "Insert cancelled" End If AddRow = False End If rs.Close Set rs = Nothing If AddRow Then Video_Gallery.ID.DbValue = rsnew("ID") ' Call Row Inserted event Call Video_Gallery.Row_Inserted(rsnew) End If ' Field Video Call Video_Gallery.Video.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" End Sub ' Page Unload event Sub Page_Unload() '***Response.Write "Page Unload" End Sub %>